Storage and Memory Architecture โ
TIP
One-liner: CodyMaster gives your AI a durable 5-tier brain that persists across sessions, avoids token overflow, and gets smarter over time.
The 5-Tier Memory Model โ
Every CodyMaster project has five layers of memory, each with a different lifespan and purpose:
| Tier | Name | Storage | Lifespan | Purpose |
|---|---|---|---|---|
| 1 | Sensory | Chat context | This turn | Active files, terminals, current selection |
| 2 | Working | CONTINUITY.md | Session โ next session | Goal, phase, blockers, last actions |
| 3 | Long-term | context.db (SQLite) | Indefinite | Learnings, decisions, BM25-ranked retrieval |
| 4 | Semantic | qmd index | Until re-embed | Full-text + vector search across docs/code |
| 5 | Structural | Skeleton index + CodeGraph | Until re-index | AST, call graphs, 95% token compression |
Tiers 1โ3 are always active. Tiers 4โ5 are opt-in and activated by skills automatically when the project grows large enough.
Global vs Project State โ
Global user data (~/.codymaster/) โ
Shared across all projects, managed by src/data.ts:
~/.codymaster/
โโโ kanban.json โ projects, tasks, activities, deployments, changelog, chain executionsPer-project memory (.cm/) โ
Isolated per repo, never committed to git (add .cm/ to .gitignore):
.cm/
โโโ CONTINUITY.md โ Working memory (Tier 2): goal, phase, blockers, last actions
โโโ config.yaml โ Runtime configuration
โโโ context.db โ SQLite: learnings + decisions with FTS5 index
โโโ context-bus.json โ Real-time output sharing between skills in a chain
โโโ skeleton.md โ L0 codebase index (auto-generated by cm-codeintell)
โโโ token-budget.json โ Token allocation by category
โโโ memory/
โโโ learnings.json โ Legacy flat-file (migrated to SQLite on first run)
โโโ decisions.json โ Legacy flat-file (migrated to SQLite on first run)Storage Backend โ
src/storage-backend.ts defines a StorageBackend interface with 11 methods covering learnings, decisions, skill outputs, and index caching. The backend is swapped via .cm/config.yaml:
# .cm/config.yaml โ default (no changes needed)
storage:
backend: sqliteSQLite backend (default, always recommended) โ
The production backend. Implemented in src/context-db.ts using better-sqlite3:
- WAL mode โ concurrent reads during writes
- FTS5 virtual tables โ BM25-ranked full-text search on learnings and decisions
- Auto-sync triggers โ FTS index stays in sync on every INSERT/DELETE
- Zero external dependencies โ runs in-process, no server required
flowchart LR
A["CLI / MCP Tool"] --> B["StorageBackend\nsrc/storage-backend.ts"]
B --> C["SqliteBackend\nsrc/context-db.ts"]
C --> D["context.db\nFTS5 ยท BM25"]
D --> E["cm_query\ncm_memory_query\nMCP tools"]
style C fill:#2f3640,stroke:#fbc531,color:#fff
style D fill:#353b48,stroke:#fbc531,color:#fffRemoved OpenViking backend โ
Older CodyMaster revisions experimented with an OpenViking-backed implementation. That runtime path has been removed after proving too costly to install and too unreliable for the supported product path.
WARNING
Keep storage.backend: sqlite. If an older project config still says viking, CodyMaster warns and falls back to SQLite automatically.
Search and Retrieval โ
Tier 3 โ SQLite FTS5 (Memory search) โ
Used by cm-continuity and MCP tools to recall relevant learnings and decisions:
Skill: "I need context about the auth module"
โ
cm_query("auth module")
โ
SQLite FTS5 BM25 search โ top-k learnings + decisions sorted by relevance
โ
Agent receives focused context slice (not the entire learnings file)When to use: automatically. Skills call cm_query via MCP without user action.
Tier 4 โ qmd semantic search (Code + doc search) โ
For codebases >200 files or doc sets >50 pages, grep and file reads cause context overflow. qmd provides BM25 + vector search that returns precise snippets instead of full files.
Activated by: cm-deep-search โ triggers automatically when it detects a large project.
Setup: See Semantic Search Guide โ
Tier 5 โ Skeleton Index + CodeGraph (Structural search) โ
For understanding codebases without reading every file:
| Layer | Tool | Cost | Output |
|---|---|---|---|
| L0 | Skeleton index | ~4s, <500 tokens | Directory map, exports, imports |
| L1 | CodeGraph (AST) | ~30s, <2K tokens | Function signatures, class interfaces |
| L2 | Full context | On-demand | Vector embeddings per file |
Activated by: cm-codeintell when you ask "what does this codebase do?" or "how does X work?"
The Context Bus โ
.cm/context-bus.json enables skills in a chain to share outputs without re-deriving state from chat history:
cm-planning writes: { "plan": "...", "phase": "design" }
โ
cm-tdd reads: { "plan": "..." } โ no need to re-explain the plan
โ
cm-code-review reads: { "plan": "...", "test_results": "..." }MCP tools: cm_bus_read, cm_bus_write in src/mcp-context-server.ts.
Token Budget โ
.cm/token-budget.json pre-allocates the 200k context window by category to prevent silent overflow:
engineering: 60k tokens
product: 30k tokens
operations: 20k tokens
growth: 20k tokens
orchestration: 30k tokens
reserved: 40k tokensMCP tool: cm_budget_check โ skills call this before loading large context.
cm:// URI Scheme โ
Skills reference context by URI, not file paths. The URI resolver (src/uri-resolver.ts) maps:
| URI | Resolves to |
|---|---|
cm://memory/learnings | .cm/context.db learnings table |
cm://memory/decisions | .cm/context.db decisions table |
cm://index/l0 | .cm/skeleton.md |
cm://bus/current | .cm/context-bus.json |
cm://skill/cm-tdd | skills/cm-tdd/SKILL.md |
MCP tool: cm_resolve โ loads the right context at the cheapest sufficient depth.
Configuration Reference โ
Full .cm/config.yaml with all options:
storage:
backend: sqlite # supported default; legacy "viking" values fall back to sqlite
memory:
max_learnings: 50 # Trigger Ebbinghaus TTL cleanup above this count
archive_decisions: true
quality:
velocity_tracking: true
code_review_mode: strict # "strict" | "normal"
rarv:
max_retries: 3
self_correction: true
goal_alignment_check: trueSee Also โ
- CodyMaster Brain โ working memory, continuity, context bus
- Semantic Search Guide โ qmd setup, context overflow prevention
- Servers and MCP Runtime โ MCP tools reference
- API Reference โ
cm_query,cm_resolve,cm_budget_check