rustbrain
CLI for a Rust-native second brain — local Markdown + SQLite knowledge graph for humans and AI agents.
Write ordinary notes (docs/**/*.md, Obsidian-style WikiLinks). Index Rust code with Tree-Sitter. Search with FTS5. Expand the graph. Pack agent context under a token budget. All offline, project-scoped, Git-friendly.
docs/*.md + src/**/*.rs + CHANGELOG.md + Cargo.toml deps
│ │ │ │
▼ ▼ ▼ ▼
WikiLinks tree-sitter hub: changelog docs.rs notes
frontmatter symbols
└──────────────┬──────────────┴────────────────┘
▼
.brain/db.sqlite ← source of truth
│
▼
.brain/graph.mmap ← CSR neighborhood cache
│
▼
query · context · graph · doctor · agents
Library API: rustbrain-core
Full flag book: docs/CLI.md
Repo: github.com/shan-alexander/rustbrain
Why rustbrain?
| Benefit | What you get |
|---|---|
| Agent-ready | context packs ranked notes + graph neighbors under a token budget (Markdown or XML) |
| Truth in Git | Notes are plain Markdown; .brain/ is a disposable index (gitignore it) |
| Code ↔ docs | symbol:Foo from notes; [[docs/adr/…]] in rustdoc → bidirectional edges |
| Rust ecosystem | Indexes CHANGELOG.md, harvests docs.rs URLs from Cargo.toml on setup |
| No cloud required | Local SQLite FTS5 + optional CSR mmap; no LLM inventiveness in the engine |
| HITL planning | plan notes with status densify (backlog → blocked); optional ROADMAP/BACKLOG hubs |
Install
# pin: cargo install rustbrain --version 0.3.20 --locked
# ensure the binary is on PATH
Requirements: Rust 1.80+, a C toolchain (bundled SQLite + tree-sitter).
License: MIT OR Apache-2.0.
Getting started (5 minutes)
1. One-shot setup (recommended)
This will:
- Create
.brain/db.sqlite - Scaffold
docs/(goals, ADRs, analysis, plans, …) - Write root
AGENTS.md+docs/AGENTS.md(agent protocol) - Harvest README →
docs/goals/from-readme.md(if present) - Harvest Cargo.toml deps → docs.rs notes under
docs/references/crates/ - Optional AST module map
- Sync (index) + doctor
Skip pieces when you need to:
2. Capture knowledge
# Preferred: type + title only → scaffold → edit the printed path → sync
# edit docs/adr/use-local-sqlite.md (Status / Context / Decision / Consequences)
# edit checkboxes / status: backlog | in_progress | qa | done | cancelled | blocked
3. Search & orient (agents and humans)
4. Everyday loop
# After editing docs or code:
# Soft-link orphans / normalize WikiLinks when needed:
# Live re-index while editing:
Command reference (overview)
| Command | Purpose |
|---|---|
setup |
One-shot init + bootstrap + sync + doctor |
init |
Create empty .brain/db.sqlite only |
bootstrap |
Docs tree, AGENTS, ignore, README harvest, crate docs, module map |
sync |
Index Markdown / Canvas / Rust; bake graph.mmap |
doctor |
Health + optional --orphans / --json / --strict |
note new |
Typed scaffold under docs/ (--type + --title) |
query |
Ranked FTS (--scores, --type, --with-symbols, --all-workspaces) |
context |
Agent pack: seeds + hops + excerpts (-m budget, -F markdown|xml) |
graph |
Neighborhood ASCII/JSON or workspace stats |
links |
Pending list; --auto soft edges; --apply rewrites; --discover AC |
watch |
Debounced live re-index |
export / import |
Portable .brainbundle |
Full flags and nuances: docs/CLI.md.
Note types (quick map)
| Type | Default dir | Use for |
|---|---|---|
goal |
docs/goals/ |
Aims / non-goals |
adr |
docs/adr/ |
Decisions you committed to |
analysis |
docs/analysis/ |
Dated investigations (benches, options) |
plan |
docs/plans/ |
Roadmaps, backlogs, tasklists (status densified on sync) |
changelog |
root hub / docs/changelogs/ |
Ship history (prefer root CHANGELOG.md) |
concept |
docs/concepts/ |
Timeless “what is X” |
edge_case |
docs/edge_cases/ |
Traps and platform quirks |
reference |
docs/concepts/ or generated crates |
External crates / APIs |
Root hubs (when files exist):
| File | Node id | Type |
|---|---|---|
README.md |
readme |
goal |
CHANGELOG.md |
changelog |
changelog |
ROADMAP.md |
roadmap |
plan |
BACKLOG.md |
backlog |
plan |
Plan status tokens (after sync): status:backlog, status:in_progress, status:qa, status:done, status:cancelled, status:blocked.
Agent protocol (HITL)
After setup, agents should treat AGENTS.md / docs/AGENTS.md as the project mandate:
- Orient with
rustbrain context "…"before large refactors - Search with
query/graphinstead of inventing history - Capture with
note newscaffolds + WikiLinks /symbol: syncafter doc or code changes- Never invent ADR history or changelog entries
Customize the cookbook:
# or commit AGENTS.template.md / .rustbrain/AGENTS.template.md
# or export RUSTBRAIN_AGENTS_TEMPLATE=/path/to/template.md
Linking notes and code
node_type: adr
tags: [storage]
Decision: keep the brain in-process.
See [[docs/concepts/fts5]] and symbol:Database::open.
/// Primary store. Decision: [[docs/adr/use-local-sqlite]].
On sync:
- Note → code:
anchors - Code rustdoc → note:
doc_links
Portability
# copy file to another machine / repo
Exit codes
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Error, or doctor --strict with unhealthy / pending links |
Library usage
Embed the same engine in tools and agents via rustbrain-core:
[]
= "0.3"
See that crate’s README for full Rust API examples (Brain, query_ranked, context_for_prompt_with, …).
License
MIT OR Apache-2.0