Expand description
Durable semantic memory (v0.10.0).
Plain-Markdown, agent-managed long-term memory: one fact per file with
YAML frontmatter (name, description, scope, created, tags) and a
body. Three scopes, all machine-local except shared:
- global
<data_dir>/memory/(all projects) - project-private
<data_dir>/projects/<key>/memory/(default; not committed) - project-shared
<git-root>/.mermaid/memory/(opt-in; committed)
Retrieval is an always-loaded auto-derived INDEX (name + description + path
per file, grouped by scope) plus on-demand reads of the full files via the
normal read_file tool. The index is generated from the files, so it can
never drift from them. No database, no vectors, no embeddings.
This module owns the on-disk format, scope resolution, index generation, load/refresh, and the write/delete primitives the memory tool and slash commands build on.
Structs§
- Loaded
Memory - Snapshot of all loaded memory across scopes plus the rendered index block.
- Memory
Entry - One memory file’s index entry. Deliberately holds no body — the full fact
is read on demand via
read_fileonpath, keeping the always-loaded snapshot small.
Enums§
- Memory
Reload Outcome - Outcome of a per-turn
refresh(), for optional status reporting. - Memory
Scope - Where a memory lives. The directory is authoritative; the frontmatter
scopefield is advisory/portable metadata so a hand-moved file is still classified by its location.
Functions§
- delete_
memory - Delete a memory by name or file-stem id. Returns the deleted path, or
Noneif no match. - dir_for
- Resolve the on-disk directory for a scope at
cwd, if available. - entries_
with_ bodies - Load every memory’s index entry paired with its full body text, across all scopes. Consolidation needs the bodies to judge duplicates/staleness.
- find
- Find a memory by name or file-stem id across all scopes.
- find_
git_ root - Walk UP from
startto the nearest directory containing a.gitentry (file or dir, so worktrees resolve), orNoneif not inside a repo. - load
- Load all memory for
cwdinto a snapshot, orNonewhen disabled or empty. - memory_
roots - The memory roots for
cwd, in injection order (global → private → shared). Shared is omitted whencwdisn’t in a git repo. Returns an empty vec only if the machine data dir can’t be resolved. - refresh
- Per-turn refresh: re-scan the roots (cheap — a few
read_dirs + stats) and report whether anything changed sincecurrent. Picks up the agent’s own mid-session writes and hand edits with no filesystem watcher. - slugify
- kebab-case slug for a memory name → filename stem.
- write_
memory - Write a memory at the resolved directory for
scope/cwd. - write_
to_ dir - Write a memory into
dir(created if needed). Returns the file path. Testable core ofwrite_memory.