Code Standards π‘ BETA
Code standards are the mandatory patterns in root AGENTS.md: no panics in production, no lint exceptions and files under 450 lines.
Gate map
| Rule | Enforcement |
|---|---|
No unwrap / expect on a production path |
Error-handling ratchet in ci.yml and review |
| Zero clippy warnings | CI clippy baseline |
| File under 450 lines | Review; split proactively at 350 |
| Traceable documentation | botbook_guards.py --check |
| Local fonts, no CDN | Design-system guard in ci.yml |
LLM-Generated Code Policy
Code is generated with LLM assistance, but the standard is the same as for hand-written code: traceable, minimal and free of suppressed warnings.
Core Principle
Fix the cause, not the diagnostic output. A claim or a suppression that cannot be justified in review is deleted.
Important Guidelines
- No
#[allow(...)]attribute. - No
unwrap,expect,panic!,todo!orunimplemented!on a production path. - No unused imports, variables or
_-prefixed unused parameters. - No file over 450 lines; split proactively at 350.
Why No Comments?
Comments that restate code go stale. Keep only the comment that explains a non-obvious mechanism, with a file:line authority where possible.
Development Workflow
Work offline first, batch fixes by file, write once, verify last and never block on a build.
LLM Strategy
Launch background checks, keep analysing while they run, fix all reported problems in one pass per file, then re-launch the checks.
Code Generation Rules
Use Self, derive PartialEq, Eq together, inline format arguments, combine identical match arms and propagate errors with ?.
Rust Style Guide
Formatting and lint gates are the baseline; style beyond them is enforced in review.
Formatting
cargo fmt --check for a non-mutating check.
Linting
cargo clippy --workspace must report zero warnings; fix each finding in code.
Naming Conventions
Names describe responsibility; a module owns one domain.
General Rules
Snake case for functions and modules, upper camel case for types, uppercase for constants.
Self-Documenting Names
Prefer a precise name to a comment that explains what the name should have said.
Code Organization
Split at 350 lines by responsibility: types, handlers, operations, utils and mod.rs re-exports.
Module Structure
A directory module has a mod.rs that re-exports its public items.
Measured Technical Debt
The debt issues (#1368, #1369, #1370) track unwrap/expect, allocations and files over the 450-line ceiling. Counts are measured, not copied into prose.
Import Ordering
Follow cargo fmt; no manual grouping convention is enforced here.
Documentation Strategy
User-facing behaviour goes into BotBook; developer-facing detail goes into a module README and inline comments.
External Documentation Only
A plan is a GitHub issue, not a Markdown file in botbook/.
Where to Document
Documentation describes what the product does today.
Error Handling
Every error path returns Result or handles the error locally with a log; no silent default that hides a failure.
Use Result Types
Prefer ? and ok_or_else to a panic.
Production-path error policy
unwrap, expect, panic!, todo! and unimplemented! are forbidden outside tests.
Custom Error Types
Define a domain error in the owning crate and map it at the boundary.
Testing Standards
Name tests test_, keep them close to the code and avoid ordering dependencies.
Test Naming
A test name states the behaviour it asserts.
Test Organization
Inline #[cfg(test)] modules or the tests/ directory of the owning crate.
Security Standards
Validate input, use SafeCommand, ErrorSanitizer and sql_guard, and require CSRF on state-changing endpoints (root AGENTS.md).
Never Hardcode Secrets
Credentials come from Vault or the environment; secret files live under /tmp.
Validate Input
Sanitise identifiers and validate table names before building a query.
Performance Guidelines
Prefer iterators and avoid owned data in hot paths where a borrow is sufficient; allocations legitimately needed for map keys and cross-thread hand-offs stay.
Use Iterators
Iterator chains keep transformations explicit.
Avoid Unnecessary Allocations
Do not clone to satisfy a borrow checker without understanding why.
LLM Prompt References
Prompts shipped with a bot live in .gbot/ in the bot repository; the work-dir copy is materialized.
Code Review Checklist
- No lint exception added
- No panic on a production path
- No file over 450 lines
- No invented version, flag, endpoint or model name
- Module README or BotBook updated where required
Summary
The standard is enforced by CI gates and by review; a guard that does not exist yet is not cited as available.
Limits
- No
#[allow]to silence a warning; fix the code. - No
_prefix for an unused variable; delete or use it. - No CDN link, ad-hoc colour or inline style in UI or docs.
- No branch change or production swap without explicit approval.