Local-first 🧠memory for Hermes Agent that lives in your Obsidian vault and remembers project context. Nightly 😴 dream passes turn repeat corrections into confirmed preferences with measurable confidence. Adapters ship for Claude Code, Codex, and OpenClaw, with an MCP server for anything else.
Who wrote what, and how to take it back - implementation plan
Feature branch: feat/who-wrote-what. TDD per task, one atomic conventional commit per task, bun run fmt + bun run lint green before every commit. Tasks 1-3 are independent and run in parallel in separate worktrees; tasks 4-5 run after them. Task 6 is the reconciliation the orchestrator does on the feature branch.
Registration checklist for a new o2b brain verb (six places): handler src/cli/brain/verbs/<verb>.ts; barrel src/cli/brain/verbs/index.ts; dispatcher import + case in src/cli/brain.ts (the switch stays terminated by default:); src/cli/brain/help-text.ts summary line in BRAIN_HELP AND a VERB_HELP key; src/cli/command-manifest.ts brain group; docs/cli-reference.md. Pinned by tests/cli/manifest-completeness.test.ts and tests/cli/help-surface-parity.test.ts.
Registration checklist for a new MCP tool: ToolDefinition in a domain array (model brain_agent_diff, src/mcp/brain/query-tools.ts:713-751); description <= 300 chars, property descriptions <= 160; previewBudget or a >= 10-char exemption reason in src/mcp/registry-guard.ts PREVIEW_BUDGET_EXEMPT; pins: tests/mcp/mcp.test.ts:765 (113 -> 114), tests/mcp/brain-tools-parity.test.ts FROZEN_BRAIN_TOOL_NAMES, tests/mcp/agent-scope-matrix.test.ts:214 (113 -> 114) plus a SCOPED_SURFACES / PROBE_ENTRIES classification, tests/helpers/tool-probe-catalogue.ts:274-276 (PROBE_ENTRY_COUNT 99, PROBE_RECIPE_COUNT 226, PROBE_TWO_SIDED_COUNT 32 - measured after adding the probe), tests/core/install/tool-ceiling.test.ts:343 (available_tool_count 113 -> 114), docs/mcp.md prose counts. A tool that reads page content needs a src/core/search/visibility-surface-registry.ts row (tests/core/architecture/visibility-surface-census.test.ts:452, MCP_TOOL_POPULATION_SIZE 48).
Tasks
Task 1: Per-device shards for every append-only ledger (t_1814b9bf)
- Files: new
src/core/brain/ledger-shards.ts;src/core/brain/log-jsonl.ts(re-point, keep exports and bytes);src/core/brain/log.ts(resolveAppendShardIdreplaces the inline fallback, behaviour unchanged);src/core/brain/continuity/store.ts;src/core/brain/idempotency-ledger.ts;src/core/brain/pref-audit.ts(+prefAuditPathinpaths.ts);src/core/brain/metrics.ts;src/core/brain/lineage/ledger.ts,lineage/verify.ts;src/core/brain/diagnostics.ts+ the doctor check that emitssync-conflict-log(widen the sweep, keep the code);src/core/state/surfaces.ts(row labels/patterns; count stays 42 unless a new directory appears);docs/observability.mdledger table; tests: newtests/core/brain/ledger-shards.test.ts, shard cases added tocontinuity-store.test.ts,idempotency-ledger.test.ts,pref-audit.test.ts,metrics.test.ts,lineage-ledger-integrity.test.ts, doctor test for a conflict copy under each directory. - Acceptance: each writer with
device_id: "testdev1"in config writes<base>.testdev1.jsonland never the bare file; a reader given a bare file plus two device shards plus a*.sync-conflict-*copy returns the union of the first three in deterministic order and the doctor names the fourth with its directory;log-shards.read.test.tsandlog-shards.write.test.tspass unmodified; lineage verify reports per shard; the state-surface census andtests/core/state/surfaces.test.tspass. - Depends on: none
Task 2: Fleet freeze (t_109fa94d)
- Files: new
src/core/brain/freeze-marker.ts(FROZEN_MARKER_FILE,readFreezeMarker,assertVaultNotFrozen,VaultFrozenError,WRITE_LANE, per-process inode cache); newsrc/core/brain/freeze.ts(freezeVault,unfreezeVault, log eventsfreeze/unfreeze);src/core/brain/vault-identity.ts(third parameterlane, freeze check first for the content lane);src/core/brain/paths.ts(brainDirsForWrite(vault, notices?, lane?),frozenMarkerPath);src/core/brain/log.ts(passesWRITE_LANE.audit);src/core/brain/types.ts(three event kinds);src/core/brain/status.ts+src/cli/brain/verbs/status.ts+src/mcp/brain/health-tools.ts(frozenfield); new doctor checksrc/core/brain/doctor/frozen-check.ts+DIAGNOSTIC_SIGNALSentryvault-frozen(nextCommand: "o2b brain unfreeze"); MCP error boundary insrc/mcp/tools.ts(mapVaultFrozenError-> structured refusal, appendwrite-refusednaming the tool);src/core/brain/destructive-sites.ts(marker removal);src/core/state/surfaces.ts(marker row, 42 -> 43,DECLARED_SURFACE_COUNTintests/core/architecture/state-surface-census.test.ts:83); new CLI verbsfreeze,unfreeze(six places);docs/cli-reference.md,docs/observability.md,docs/mcp.md(refusal shape); tests:tests/core/brain/freeze-marker.test.ts,freeze.test.ts, a lane pin test assertingWRITE_LANE.auditis referenced only fromlog.tsandfreeze-marker.ts/freeze.ts,tests/core/brain/vault-identity*.test.tsextension, CLI testtests/cli/brain-freeze.test.ts, MCP test thatbrain_create_noteon a frozen vault returns the structured refusal and awrite-refusedevent lands in the log,doctor-exit-censuspasses. - Acceptance: with the marker present every guarded content write throws
VaultFrozenErrornamingfrozen_at,by,reasonand the next command;appendLogEventstill works;o2b brain freeze --reason xwrites the marker and onefreezeevent,unfreezeremoves it and writes oneunfreezeevent; a malformed marker freezes;o2b brain statusandbrain_statusshowfrozen;o2b brain rollbackon a frozen vault is refused by name. - Depends on: none
Task 3: Attributable note writes (t_662f4e82)
- Files: new
src/core/brain/notes/write-record.ts(NOTE_WRITE_OP,NOTE_WRITE_NO_PRIOR = "absent",noteWriteId,storeBeforeImage,recordNoteWrite,writeImagePath,WRITE_IMAGE_RETENTION_DAYS,pruneWriteImages); newsrc/core/brain/notes/write-log.ts(listNoteWrites(vault, {agent, device, path, since, until, op})overreadLogDay);src/core/brain/notes/create-note.ts(record after the exclusive write,write_id/audit_reasonon the result);src/core/brain/write-batch.ts(update/append commits: hash raw bytes before, store image, write, record; results gainwrite_id);src/mcp/brain/notes-tools.ts+write-batch-tools.ts(receipts carrywrite_id);src/core/brain/types.ts(event kindnote-write);src/core/brain/agent-source/types.ts+vault-provider.ts(kindnote);src/core/brain/destructive-sites.ts(image prune);src/core/state/surfaces.ts(write-images row, count +1); new CLI verbwrites(listdefault with--agent --device --path --since --until --op --json,prune-images [--older-than-days N] [--dry-run]); new MCP toolbrain_writes(action: list;plan_revertarrives in Task 5 - declare the enum with both members now and refuseplan_revertby name until Task 5 lands, or leave the enum single-valued; pick the first so the pins move once);docs/observability.md,docs/cli-reference.md,docs/mcp.md, README; tests:tests/core/brain/notes/write-record.test.ts,write-log.test.ts, extensions oftests/core/brain/write-batch.test.tsand the create-note suite, agent-source test for kindnote, CLI and MCP tests, write-site census pins (tests/core/architecture/write-site-census.test.ts: new shared-helper rows), destructive-site and state-surface census, MCP pins listed above. - Acceptance: creating, updating and appending a note through MCP and through the kernel each append exactly one
note-writeJSONL line with the fields in the design; the before-image file exists with sha256 =hash_beforeafter an update; a second update to the same content does not write a second image;listNoteWritesfilters by agent and path;brain_agent_querylists the note under kindnote; a log-append failure (simulated) leaves the note written and the result withwrite_id: nulland anaudit_reason;prune-images --dry-runlists and--older-than-days 0removes. - Depends on: none
Task 4: Per-shard hash chain on the Brain log (t_8a7bf39a)
- Files:
src/core/brain/log.ts(renderJsonlLinegainsprev+h; the appender computes them from the shard text it already holds under the lock;LOG_CHAIN_FIELDSconstant);src/core/brain/log-jsonl.ts(readJsonlignores the two keys; export a raw-line scanner for the verifier); newsrc/core/brain/log-chain.ts(logChainHash,verifyLogChain(vault) -> { shards: [{ path, chained, legacy, firstBreak?: { line, reason } }], ok }); new doctor check +DIAGNOSTIC_SIGNALSentrylog-chain-broken(nextCommand: "o2b brain log verify"); new CLI verblogwithverify [--json];docs/observability.md(chain paragraph, markdown twin declared derived); tests:tests/core/brain/log-chain.test.ts(genesis, legacy prefix, edited line, deleted line, appended-by-hand line, two shards independent), existing log tests still pass byte-for-byte on the markdown side, CLI test, doctor-exit census. - Acceptance: three appends produce three lines whose
prevlinks match; editing the middle line's payload makes verify report line 2hash-mismatch; deleting it reports line 3prev-mismatch; a file of legacy lines followed by chained lines verifies clean withlegacy = N; the doctor emitslog-chain-brokenonly on a break. - Depends on: Task 1 (shard listing lives in
ledger-shards.ts)
Task 5: Per-agent revert (t_924129c5)
- Files: new
src/core/brain/notes/revert.ts(planNoteRevert(vault, selector) -> NoteRevertPlan { entries: [{ target, action: restore|delete|refuse, reason?, writes: [write_id], hash_now, hash_to }], digest },applyNoteRevert(vault, digest) -> { snapshot, applied, refused },NOTE_REVERT_REFUSAL = { drift, interleaved, imageMissing });src/core/brain/types.ts(BRAIN_SNAPSHOT_REASON.noteRevert);src/core/brain/notes/write-record.ts(oprevert); CLIwrites revert --agent A | --device D [--path P] [--since --until] [--apply <digest>] [--json]; MCPbrain_writesactionplan_revert(same selector, no apply);docs/cli-reference.md,docs/mcp.md, README; tests:tests/core/brain/notes/revert.test.ts(restore, delete, drift, interleaved, image-missing, digest mismatch, revert-of-revert), CLI test, MCP test, snapshot-reason test. - Acceptance: after agent A updates a note twice and agent B never touches it,
revert --agent Aplans onerestoreto the pre-A bytes and--apply <digest>restores them, takes anote-revertsnapshot, and appends anote-writeevent withop: revert; if B updated in between the plan refusesinterleaved; if the note changed after A's last write the plan refusesdrift; a note A created is planneddelete; applying a stale digest is refused before any byte moves. - Depends on: Task 3
Task 6: Reconciliation, docs, version
- Files: every count pin touched by more than one task (
tests/mcp/*,tests/helpers/tool-probe-catalogue.ts, state-surface and write-site censuses,docs/architecture.mdsurface count prose near line 201);CHANGELOG.md[1.55.0]+ link reference;package.json1.55.0 +bun run scripts/sync-version.ts; README paragraph;docs/observability.mdfinal pass. - Acceptance:
bun run typecheck,bun run lint,bun run fmt:check,bun run test,bun run sync-version:check,python -m unittest discover -s tests/pythonall green on the merged branch. - Depends on: Tasks 1-5