botserver/PROMPT.md

528 lines
14 KiB
Markdown
Raw Normal View History

2025-12-12 23:20:42 -03:00
# botserver Development Prompt Guide
**Version:** 6.1.0
2025-12-12 23:20:42 -03:00
**Purpose:** Consolidated LLM context for botserver development
---
2025-12-21 23:40:43 -03:00
## ZERO TOLERANCE POLICY
**This project has the strictest code quality requirements possible:**
```toml
[lints.clippy]
all = "warn"
pedantic = "warn"
nursery = "warn"
cargo = "warn"
unwrap_used = "warn"
expect_used = "warn"
panic = "warn"
todo = "warn"
```
2025-12-21 23:40:43 -03:00
**EVERY SINGLE WARNING MUST BE FIXED. NO EXCEPTIONS.**
2025-12-21 23:40:43 -03:00
---
2025-12-21 23:40:43 -03:00
## ABSOLUTE PROHIBITIONS
2025-12-21 23:40:43 -03:00
```
❌ NEVER use #![allow()] or #[allow()] in source code to silence warnings
❌ NEVER use _ prefix for unused variables - USE the variable (add logging)
2025-12-21 23:40:43 -03:00
❌ NEVER use .unwrap() - use ? or proper error handling
❌ NEVER use .expect() - use ? or proper error handling
❌ NEVER use panic!() or unreachable!() - handle all cases
❌ NEVER use todo!() or unimplemented!() - write real code
❌ NEVER leave unused imports - DELETE them
❌ NEVER leave dead code - USE IT (add logging, make public, add fallback methods)
❌ NEVER delete unused struct fields - USE them in logging or make them public
2025-12-21 23:40:43 -03:00
❌ NEVER use approximate constants (3.14159) - use std::f64::consts::PI
❌ NEVER silence clippy in code - FIX THE CODE or configure in Cargo.toml
❌ NEVER use CDN links - all assets must be local
2025-12-23 15:52:35 -03:00
❌ NEVER run cargo check or cargo clippy - USE ONLY the diagnostics tool
❌ NEVER add comments - code must be self-documenting via types and naming
❌ NEVER add file header comments (//! or /*!) - no module docs
❌ NEVER add function doc comments (///) - types are the documentation
❌ NEVER add ASCII art or banners in code
❌ NEVER add TODO/FIXME/HACK comments - fix it or delete it
2025-12-21 23:40:43 -03:00
```
---
2025-12-21 23:40:43 -03:00
## CARGO.TOML LINT EXCEPTIONS
2025-12-21 23:40:43 -03:00
When a clippy lint has **technical false positives** that cannot be fixed in code,
disable it in `Cargo.toml` with a comment explaining why:
2025-12-21 23:40:43 -03:00
```toml
[lints.clippy]
# Disabled: has false positives for functions with mut self, heap types (Vec, String)
missing_const_for_fn = "allow"
# Disabled: Tauri commands require owned types (Window) that cannot be passed by reference
needless_pass_by_value = "allow"
# Disabled: transitive dependencies we cannot control
multiple_crate_versions = "allow"
```
2025-12-21 23:40:43 -03:00
**Approved exceptions:**
- `missing_const_for_fn` - false positives for `mut self`, heap types
- `needless_pass_by_value` - Tauri/framework requirements
- `multiple_crate_versions` - transitive dependencies
- `future_not_send` - when async traits require non-Send futures
2025-12-21 23:40:43 -03:00
---
2025-12-21 23:40:43 -03:00
## MANDATORY CODE PATTERNS
2025-12-21 23:40:43 -03:00
### Error Handling - Use `?` Operator
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
let value = something.unwrap();
let value = something.expect("msg");
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
let value = something?;
let value = something.ok_or_else(|| Error::NotFound)?;
```
2025-12-21 23:40:43 -03:00
### Option Handling - Use Combinators
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
if let Some(x) = opt {
x
} else {
default
}
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
opt.unwrap_or(default)
opt.unwrap_or_else(|| compute_default())
opt.map_or(default, |x| transform(x))
```
2025-12-21 23:40:43 -03:00
### Match Arms - Must Be Different
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG - identical arms
match x {
A => do_thing(),
B => do_thing(),
C => other(),
}
2025-12-21 23:40:43 -03:00
// ✅ CORRECT - combine identical arms
match x {
A | B => do_thing(),
C => other(),
}
```
2025-12-21 23:40:43 -03:00
### Self Usage in Impl Blocks
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
impl MyStruct {
fn new() -> MyStruct { MyStruct { } }
}
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
impl MyStruct {
fn new() -> Self { Self { } }
}
```
2025-12-21 23:40:43 -03:00
### Format Strings - Inline Variables
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
format!("Hello {}", name)
log::info!("Processing {}", id);
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
format!("Hello {name}")
log::info!("Processing {id}");
```
2025-12-21 23:40:43 -03:00
### Display vs ToString
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
impl ToString for MyType {
fn to_string(&self) -> String { }
}
// ✅ CORRECT
impl std::fmt::Display for MyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { }
}
```
2025-12-21 23:40:43 -03:00
### Derive Eq with PartialEq
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
#[derive(PartialEq)]
struct MyStruct { }
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
#[derive(PartialEq, Eq)]
struct MyStruct { }
```
### Must Use Attributes
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG - pure function without #[must_use]
pub fn calculate() -> i32 { }
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
#[must_use]
pub fn calculate() -> i32 { }
```
2025-12-23 15:52:35 -03:00
### Zero Comments Policy
```rust
// ❌ WRONG - any comments
/// Returns the user's full name
fn get_full_name(&self) -> String { }
// Validate input before processing
fn process(data: &str) { }
//! This module handles user authentication
// ✅ CORRECT - self-documenting code, no comments
fn full_name(&self) -> String { }
fn process_validated_input(data: &str) { }
```
**Why zero comments:**
- Rust's type system documents intent (Result, Option, traits)
- Comments become stale when code changes
- LLMs can infer intent from well-structured code
- Good naming > comments
- Types are the documentation
2025-12-21 23:40:43 -03:00
### Const Functions
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG - could be const but isn't
pub fn default_value() -> i32 { 42 }
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
pub const fn default_value() -> i32 { 42 }
```
2025-12-21 23:40:43 -03:00
### Pass by Reference
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG - needless pass by value
fn process(data: String) { println!("{data}"); }
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
fn process(data: &str) { println!("{data}"); }
```
2025-12-21 23:40:43 -03:00
### Clone Only When Needed
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG - redundant clone
let x = value.clone();
use_value(&x);
2025-12-21 23:40:43 -03:00
// ✅ CORRECT
use_value(&value);
```
2025-12-21 23:40:43 -03:00
### Mathematical Constants
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG
let pi = 3.14159;
let e = 2.71828;
// ✅ CORRECT
use std::f64::consts::{PI, E};
let pi = PI;
let e = E;
```
2025-12-21 23:40:43 -03:00
### Async Functions
2025-12-21 23:40:43 -03:00
```rust
// ❌ WRONG - async without await
async fn process() { sync_operation(); }
// ✅ CORRECT - remove async if no await needed
fn process() { sync_operation(); }
```
---
2025-12-21 23:40:43 -03:00
## Build Rules
2025-12-21 23:40:43 -03:00
```bash
# Development - ALWAYS debug build
cargo build
cargo check
# NEVER use release unless deploying
# cargo build --release # NO!
```
---
2025-12-21 23:40:43 -03:00
## Version Management
2025-12-21 23:40:43 -03:00
**Version is 6.1.0 - NEVER CHANGE without explicit approval**
2025-12-21 23:40:43 -03:00
---
2025-12-21 23:40:43 -03:00
## Database Standards
2025-12-21 23:40:43 -03:00
**TABLES AND INDEXES ONLY:**
2025-12-21 23:40:43 -03:00
```
✅ CREATE TABLE IF NOT EXISTS
✅ CREATE INDEX IF NOT EXISTS
✅ Inline constraints
❌ CREATE VIEW
❌ CREATE TRIGGER
❌ CREATE FUNCTION
❌ Stored Procedures
```
**JSON Columns:** Use TEXT with `_json` suffix, not JSONB
---
## Code Generation Rules
```
- KISS, NO TALK, SECURED ENTERPRISE GRADE THREAD SAFE CODE ONLY
2025-12-21 23:40:43 -03:00
- Use rustc 1.90.0+
- No placeholders, no explanations, no comments
- All code must be complete, professional, production-ready
- REMOVE ALL COMMENTS FROM GENERATED CODE
- Always include full updated code files - never partial
- Only return files that have actual changes
2025-12-21 23:40:43 -03:00
- Return 0 warnings - FIX ALL CLIPPY WARNINGS
- NO DEAD CODE - implement real functionality
```
2025-12-21 23:40:43 -03:00
---
## Documentation Rules
```
2025-12-21 23:40:43 -03:00
- Rust code examples ONLY in docs/reference/architecture.md
- All other docs: BASIC, bash, JSON, SQL, YAML only
- Keep only README.md and PROMPT.md at project root level
```
2025-12-21 23:40:43 -03:00
---
## Frontend Rules
```
- Use HTMX to minimize JavaScript - delegate logic to Rust server
- NO external CDN - all JS/CSS must be local in vendor/ folders
- Server-side rendering with Askama templates returning HTML
- Endpoints return HTML fragments, not JSON (for HTMX)
```
---
2025-12-21 23:40:43 -03:00
## Rust Patterns
```rust
2025-12-21 23:40:43 -03:00
// Random number generation
let mut rng = rand::rng();
2025-12-21 23:40:43 -03:00
// Database - ONLY diesel, never sqlx
use diesel::prelude::*;
2025-12-21 23:40:43 -03:00
// Config from AppConfig - no hardcoded values
let url = config.drive.endpoint.clone();
2025-12-21 23:40:43 -03:00
// Logging - all-in-one-line, unique messages, inline vars
info!("Processing request id={id} user={user_id}");
```
---
2025-12-21 23:40:43 -03:00
## Dependencies
```
2025-12-21 23:40:43 -03:00
- Use diesel - remove any sqlx references
- After adding to Cargo.toml: cargo audit must show 0 vulnerabilities
- If audit fails, find alternative library
- Minimize redundancy - check existing libs before adding
```
---
2025-12-21 23:40:43 -03:00
## Key Files
```
2025-12-21 23:40:43 -03:00
src/main.rs # Entry point
src/lib.rs # Module exports
src/basic/ # BASIC language keywords
src/core/ # Core functionality
src/shared/state.rs # AppState definition
src/shared/utils.rs # Utility functions
src/shared/models.rs # Database models
```
---
## Dependencies (Key Libraries)
| Library | Version | Purpose |
|---------|---------|---------|
| axum | 0.7.5 | Web framework |
2025-12-21 23:40:43 -03:00
| diesel | 2.1 | PostgreSQL ORM |
| tokio | 1.41 | Async runtime |
| rhai | git | BASIC scripting |
| reqwest | 0.12 | HTTP client |
| serde | 1.0 | Serialization |
| askama | 0.12 | HTML Templates |
---
## Efficient Warning Fix Strategy
**IDE DIAGNOSTICS ARE THE SOURCE OF TRUTH** - Never run `cargo clippy` manually.
When fixing clippy warnings in files:
1. **TRUST DIAGNOSTICS** - Use `diagnostics()` tool, not cargo commands
2. **READ FULL FILE** - Use `read_file` with line ranges to get complete file content
3. **FIX ALL WARNINGS** - Apply all fixes in memory before writing
4. **OVERWRITE FILE** - Use `edit_file` with `mode: "overwrite"` to replace entire file
5. **BATCH FILES** - Get diagnostics for multiple files, fix in parallel
6. **RE-CHECK** - Call `diagnostics(path)` after edits to verify fixes
This is FASTER than incremental edits. Never make single-warning fixes.
```
// Workflow:
1. diagnostics() - get project overview (files with warning counts)
2. diagnostics(path) - get specific warnings with line numbers
3. read_file(path, start, end) - read full file in chunks
4. edit_file(path, mode="overwrite") - write fixed version
5. diagnostics(path) - verify warnings are fixed
6. Repeat for next file
```
**IMPORTANT:** Diagnostics may be stale after edits. Re-read the file or call diagnostics again to refresh.
---
## Current Warning Status (Session 11)
### ✅ ACHIEVED: 0 CLIPPY WARNINGS
All clippy warnings have been fixed. The codebase now passes `cargo clippy` with 0 warnings.
### Files Fixed This Session:
- `auto_task/mod.rs` - Renamed auto_task.rs to task_types.rs to fix module_inception
- `auto_task/task_types.rs` - Module rename (was auto_task.rs)
- `auto_task/app_logs.rs` - Changed `Lazy` to `LazyLock` from std
- `auto_task/ask_later.rs` - Removed redundant clones
- `auto_task/autotask_api.rs` - Fixed let...else patterns, updated imports
- `auto_task/designer_ai.rs` - Removed unused async/self, fixed format_push_string with writeln!
- `auto_task/intent_classifier.rs` - Removed unused async/self, removed doc comments, fixed if_not_else
- `basic/keywords/app_server.rs` - Removed unused async, fixed case-sensitive extension check
- `basic/keywords/db_api.rs` - Fixed let...else patterns
- `basic/keywords/table_access.rs` - Fixed let...else, matches!, Option<&T>
- `basic/keywords/table_definition.rs` - Combined identical match arms
- `core/kb/website_crawler_service.rs` - Fixed non-binding let on future with drop()
- `designer/mod.rs` - Fixed format_push_string, unwrap_or_else, Path::extension()
### Common Fix Patterns Applied:
- `manual_let_else`: `let x = match opt { Some(v) => v, None => return }``let Some(x) = opt else { return }`
- `redundant_clone`: Remove `.clone()` on last usage of variable
- `format_push_string`: `s.push_str(&format!(...))``use std::fmt::Write; let _ = writeln!(s, ...)`
- `unnecessary_debug_formatting`: `{:?}` on PathBuf → `{path.display()}`
- `if_not_else`: `if !x { a } else { b }``if x { b } else { a }`
- `match_same_arms`: Combine identical arms with `|` or remove redundant arms
- `or_fun_call`: `.unwrap_or(fn())``.unwrap_or_else(fn)` or `.unwrap_or_else(|_| ...)`
- `unused_self`: Convert to associated function with `Self::method()` calls
- `unused_async`: Remove `async` from functions that don't use `.await`
- `module_inception`: Rename module file if it has same name as parent (e.g., `auto_task/auto_task.rs``auto_task/task_types.rs`)
- `non_std_lazy_statics`: Replace `once_cell::sync::Lazy` with `std::sync::LazyLock`
- `single_char_add_str`: `push_str("\n")``push('\n')`
- `case_sensitive_file_extension_comparisons`: Use `Path::extension()` instead of `ends_with(".ext")`
- `equatable_if_let`: `if let Some(true) = x``if matches!(x, Some(true))`
- `useless_format`: Don't use `format!()` for static strings, use string literal directly
- `Option<&T>`: Change `fn f(x: &Option<T>)``fn f(x: Option<&T>)` and call with `x.as_ref()`
- `non_binding_let`: `let _ = future;``drop(future);` for futures
- `doc_markdown`: Remove doc comments (zero comments policy) or use backticks for code references
---
## Remember
2025-12-21 23:40:43 -03:00
- **ZERO WARNINGS** - Every clippy warning must be fixed
2025-12-23 15:52:35 -03:00
- **ZERO COMMENTS** - No comments, no doc comments, no file headers, no ASCII art
2025-12-21 23:40:43 -03:00
- **NO ALLOW IN CODE** - Never use #[allow()] in source files
- **CARGO.TOML EXCEPTIONS OK** - Disable lints with false positives in Cargo.toml with comment
- **NO DEAD CODE** - Delete unused code, never prefix with _
- **NO UNWRAP/EXPECT** - Use ? operator or proper error handling
- **NO APPROXIMATE CONSTANTS** - Use std::f64::consts
- **INLINE FORMAT ARGS** - format!("{name}") not format!("{}", name)
- **USE SELF** - In impl blocks, use Self not the type name
- **DERIVE EQ** - Always derive Eq with PartialEq
- **DISPLAY NOT TOSTRING** - Implement Display, not ToString
- **USE DIAGNOSTICS** - Use IDE diagnostics tool, never call cargo clippy directly
- **PASS BY REF** - Don't clone unnecessarily
- **CONST FN** - Make functions const when possible
- **MUST USE** - Add #[must_use] to pure functions
- **diesel**: No sqlx references
- **Sessions**: Always retrieve by ID when present
- **Config**: Never hardcode values, use AppConfig
- **Bootstrap**: Never suggest manual installation
2025-12-21 23:40:43 -03:00
- **Version**: Always 6.1.0 - do not change
- **Migrations**: TABLES AND INDEXES ONLY
- **JSON**: Use TEXT columns with `_json` suffix
- **Session Continuation**: When running out of context, create detailed summary: (1) what was done, (2) what remains, (3) specific files and line numbers, (4) exact next steps.
---
## Monitor Keywords (ON EMAIL, ON CHANGE)
2025-12-21 23:40:43 -03:00
### ON EMAIL
```basic
ON EMAIL "support@company.com"
email = GET LAST "email_received_events"
2025-12-21 23:40:43 -03:00
TALK "New email from " + email.from_address
END ON
```
2025-12-21 23:40:43 -03:00
### ON CHANGE
```basic
2025-12-21 23:40:43 -03:00
ON CHANGE "gdrive://myaccount/folder"
files = GET LAST "folder_change_events"
FOR EACH file IN files
TALK "File changed: " + file.name
NEXT
END ON
```
2025-12-21 23:40:43 -03:00
**TriggerKind Enum:**
- Scheduled = 0
- TableUpdate = 1
- TableInsert = 2
- TableDelete = 3
- Webhook = 4
- EmailReceived = 5
- FolderChange = 6