Memory System
Primary files:
src/memory-paths.tssrc/memory-maintenance.tssrc/memory-retrieval.tssrc/memory-search.tssrc/memory-action-gateway.ts- transcript FTS in
src/db.ts
Canonical Files
Per group:
MEMORY.md(canonical durable memory)memory/*.md(additional memory notes)SOUL.md(identity/policy context, not compaction log store)
Main group workspace:
- by default
~/nanomounted as/workspace/group
Non-main groups:
groups/<group-folder>/...
Global memory:
groups/global/MEMORY.mdandgroups/global/memory/*.md
Migration Rules
On startup:
- legacy
CLAUDE.md->SOUL.mdmigration when needed - compaction sections (
## Session Compaction ...) are moved fromSOUL.mdintoMEMORY.md
Compaction append target:
appendCompactionSummaryToMemory(groupFolder, summary, timestamp)
Retrieval-Gated Injection
buildMemoryContext({groupFolder, prompt}):
- load chunks from group + global memory docs
- tokenize prompt tail (chat-log aware stripping)
- score chunks lexically
- choose top
MEMORY_TOP_KwithinMEMORY_CONTEXT_CHAR_BUDGET - inject into container input as
memoryContext
If retrieval is disabled, host sends no injected memory snippets.
Transcript Episodic Memory (SQLite FTS)
db.ts creates messages_fts virtual table with triggers syncing messages rows.
Search path:
searchMessagesByFts(chatJids, query, limit)- used by
searchTranscriptMemoryinmemory-search.ts
Ranking:
- transcript scores transform from FTS
bm25rank to normalized positive score.
Memory Search API
executeMemoryAction supports:
memory_get: read allowed memory filememory_search: merge document + session hits and rank
Cross-group rules:
- non-main cannot request another group folder
- main may request explicit
groupFolder
Path guard:
- allowed paths only:
MEMORY.md/memory.mdmemory/<name>.md
- traversal blocked by workspace-relative resolution checks
/compact Command Behavior
In src/index.ts:
- runs dedicated compaction prompt via model
- stores summary markdown in
MEMORY.md - sets
nextRunNoContinue=trueso next session starts fresh
Return text includes compaction request id and preview snippet.