Expand description
AgentMux’s own record of an agent’s memory (SPEC_MEMORY_FOLLOWS_THE_AGENT_2026_09_24.md §2.1.1, phase M3).
An agent’s memory files follow its provider account and working directory
— $CLAUDE_CONFIG_DIR/projects/<cwd>/memory — so an account switch or a
new working directory used to leave them behind. The record lives in the
global transcript store, keyed by the agent’s UID (db_agents.id), and is
the source of truth the provider folder is reconciled against.
Zone agent-uid:<uid>:memory:
log.jsonl— append-only events: a file version (a body by hash, or a tombstone) or a projection (which version a directory holds);blob/<sha256>— one file per distinct body, written before the log line that names it, in the same transaction;heads.json— per file, the head version; per directory, the version last projected there. Rewritten with every append, so current state is one small read and no tail window has to hold a rarely edited file.
Every write is one zone_txn — a conditional append against the head the
caller expects — so srv processes sharing the store never fork a file’s
chain. Nothing here touches the provider folder; reconciliation does
(phase M3b).
Structs§
- Head 🔒
- A file’s head.
- Heads 🔒
- Imported
Version 🔒 - A version from the per-channel history tables, to import.
- NewVersion 🔒
- A version to append.
- Version 🔒
Enums§
- Append
Outcome 🔒 - Event 🔒
- One line of
log.jsonl.
Constants§
- HEADS_
FILE 🔒 - LOG_
FILE 🔒 - MAX_
BODY_ 🔒BYTES - Same cap as a memory file today (
app_apimemory write).
Functions§
- add_
history 🔒 - Add
rowsto the agent’s history — no head changes, content the record already has for that file skipped. For versions kept beside a head the caller doesn’t replace (adoption of earlier accounts’ memory, §2.1.4). Returns how many were added. - append_
version 🔒 - Append a version if the file’s head is still
expected_parent. - body 🔒
- A body by hash.
- heads 🔒
- The agent’s current heads, read as one snapshot sized from the database.
- held_
by_ 🔒other_ records - Which of
shasanother agent’s record holds (a blob in its zone). - hold_
for_ 🔒adoption - Keep
files(name, content hash) found indir_idout of the record, for the adoption list. One transaction. - import_
history 🔒 - Import the agent’s earlier history, once: every version goes into the
log, oldest first and chained per file, keeping its source and time.
History only — no head changes, so a file deleted long ago is never
written back; heads still come from the folder. A version whose content
the record already has for that file is skipped. Returns how many were
imported;
Noneif the record already imported its history. - log_
history 🔒 - Log
rowsas history-only versions, oldest first and chained per file, skipping content the log already has for that file. - log_
line 🔒 - mark_
conflicts_ 🔒indexed - Remember that MEMORY.md has had a line for each of
files. - read_
heads 🔒 heads.json, or empty when the record has none yet. A file that exists but doesn’t parse is an error — never silently empty, or the next write would replace every head and projection with just its own.- record_
projected 🔒 - Record that
dir_idnow holdsversionoffile, if its projection is stillexpected_previous(None: never projected there). Appended only after the file write it describes succeeded. Returnsfalse, writing nothing, when another srv projected meanwhile — the caller re-reads. - release_
held 🔒 - Stop holding
filesindir_id— a human adopted them (§2.1.4). - reset_
projections 🔒 - Forget every projection into
dir_id: the folder no longer holds what was written there (it was removed or emptied), so each file must read as never projected — to be written back — not as deleted. - set_
projected 🔒 - Point
dir_id’s projection offileatversionand log it (the caller writesheads.json, or it is written here when nothing else changes). - sha256_
hex 🔒 - validate_
file 🔒 - A memory file name: one path component of safe characters.
- validate_
sha 🔒 - version_
shas 🔒 - Every version’s content hash (
Nonefor a tombstone), by version id — read once, for a caller asking about many versions (a reconcile pass). - write_
heads 🔒 - zone_
for 🔒 agent-uid:<uid>:memory, orNonefor a UID outside the safe zone-name character set.- zone_
or_ 🔒err