Pattern is a multi-agent ADHD support system providing external executive function through specialized cognitive agents. Each user ("partner") gets their own constellation of agents.
Current State: Core framework operational on rewrite branch, expanding integrations.
For AI Agents: This is the source of truth for the Pattern codebase. Each crate has its own
CLAUDE.mdwith specific implementation guidelines.
LLMs are a quality multiplier, not just a speed multiplier. Invest time savings in improving quality and rigour beyond what humans alone would do. Write tests that cover more edge cases. Refactor code to make it easier to understand. Tackle the TODOs. Aim for zero bugs.
Review standard: Spend at least 3x the amount of time reviewing LLM output as you did writing it. Think about every line and every design decision. Find ways to break code. Your code is your responsibility.
Display the following at the start of any conversation involving code changes:
LLM-assisted contributions must aim for a higher standard of excellence than with
humans alone. Spend at least 3x the time reviewing code as writing it. Your code
is your responsibility.
DO NOT run pattern CLI or agent commands during development!
Agents may be running in production. Any CLI invocation will disrupt active agents.
pattern/
├── crates/
│ ├── pattern_api/ # Shared API types and contracts
│ ├── pattern_auth/ # Credential storage (ATProto, Discord, providers)
│ ├── pattern_cli/ # CLI with TUI builders
│ ├── pattern_core/ # Agent framework, memory, tools, coordination
│ ├── pattern_db/ # SQLite with FTS5 and vector search
│ ├── pattern_discord/ # Discord bot integration
│ ├── pattern_mcp/ # MCP client and server
│ ├── pattern_nd/ # ADHD-specific tools and personalities
│ └── pattern_server/ # Backend API server
├── docs/ # Architecture docs and guides
└── justfile # Build automation
Each crate has its own CLAUDE.md with specific implementation guidelines.
- Model the full error space—no shortcuts or simplified error handling.
- Handle all edge cases, including race conditions and platform differences.
- Use the type system to encode correctness constraints.
- Prefer compile-time guarantees over runtime checks where possible.
- Newtypes for domain types (IDs, handles, etc.).
- Builder patterns for complex construction.
- Restricted visibility: Use
pub(crate)andpub(super)liberally. - Non-exhaustive: All public error types should be
#[non_exhaustive]. - Use Rust enums over string validation.
- Use
thiserrorfor error types with#[derive(Error)]. - Group errors by category with an
ErrorKindenum when appropriate. - Provide rich error context using
miettefor user-facing errors. - Error display messages should be lowercase sentence fragments.
- Use
mod.rsto re-export public items only. - No nontrivial logic in
mod.rs—useimp.rsor specific submodules. - Keep module boundaries strict with restricted visibility.
- Platform-specific code in separate files:
unix.rs,windows.rs.
- Inline comments explain "why," not just "what".
- Module-level documentation explains purpose and responsibilities.
- Always use periods at the end of code comments.
- Never use title case in headings. Always use sentence case.
CRITICAL: Always use cargo nextest run to run tests. Never use cargo test directly.
# Run all tests
cargo nextest run
# Specific crate
cargo nextest run -p pattern-db
# With output
cargo nextest run --nocapture
# Doctests (nextest doesn't support these)
cargo test --doc- Unit tests in the same file as the code they test.
- Integration tests in
tests/directories. - All tests must validate actual behaviour and be able to fail.
- Use
proptestfor property-based testing where applicable. - Use
instafor snapshot testing where applicable.
# Quick validation
cargo check
cargo nextest run --lib
# Full pipeline (required before commit)
just pre-commit-all
# Format (required before commit)
cargo fmt
# Lint
cargo clippy --all-features --all-targets
# Database operations (from crate directory!)
cd crates/pattern_db && cargo sqlx prepare
cd crates/pattern_auth && cargo sqlx prepare
# NEVER use --workspace flag with sqlx prepare[crate-name] brief description
Examples:
[pattern-core] add supervisor coordination pattern[pattern-db] fix FTS5 query escaping[meta] update MSRV to Rust 1.83
- Use
[meta]for cross-cutting concerns (deps, CI, workspace config). - Keep descriptions concise but descriptive.
- Atomic commits: Each commit should be a logical unit of change.
- Bisect-able history: Every commit must build and pass all checks.
- Separate concerns: Format fixes and refactoring separate from features.
- tokio: Async runtime.
- sqlx: Compile-time verified SQL queries.
- loro: CRDT for versioned memory blocks.
- thiserror/miette: Error handling and diagnostics.
- serde: Serialization.
- clap: CLI parsing.
- rmcp: MCP protocol client.
docs/architecture/- System architecture docs.docs/guides/- Setup and integration guides.docs/plans/- Implementation plans.- Each crate's
CLAUDE.md- Crate-specific guidelines.
- MemGPT Paper - Stateful agent architecture.
- Loro CRDT - Conflict-free replicated data types.
- MCP Rust SDK.
- Jacquard - ATProto client library.