Skip to content

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.

TypeScript
11.3 KB
Raw Blame

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 (resolveAppendShardId replaces the inline fallback, behaviour unchanged); src/core/brain/continuity/store.ts; src/core/brain/idempotency-ledger.ts; src/core/brain/pref-audit.ts (+ prefAuditPath in paths.ts); src/core/brain/metrics.ts; src/core/brain/lineage/ledger.ts, lineage/verify.ts; src/core/brain/diagnostics.ts + the doctor check that emits sync-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.md ledger table; tests: new tests/core/brain/ledger-shards.test.ts, shard cases added to continuity-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.jsonl and 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.ts and log-shards.write.test.ts pass unmodified; lineage verify reports per shard; the state-surface census and tests/core/state/surfaces.test.ts pass.
  • 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); new src/core/brain/freeze.ts (freezeVault, unfreezeVault, log events freeze / unfreeze); src/core/brain/vault-identity.ts (third parameter lane, freeze check first for the content lane); src/core/brain/paths.ts (brainDirsForWrite(vault, notices?, lane?), frozenMarkerPath); src/core/brain/log.ts (passes WRITE_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 (frozen field); new doctor check src/core/brain/doctor/frozen-check.ts + DIAGNOSTIC_SIGNALS entry vault-frozen (nextCommand: "o2b brain unfreeze"); MCP error boundary in src/mcp/tools.ts (map VaultFrozenError -> structured refusal, append write-refused naming the tool); src/core/brain/destructive-sites.ts (marker removal); src/core/state/surfaces.ts (marker row, 42 -> 43, DECLARED_SURFACE_COUNT in tests/core/architecture/state-surface-census.test.ts:83); new CLI verbs freeze, 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 asserting WRITE_LANE.audit is referenced only from log.ts and freeze-marker.ts/freeze.ts, tests/core/brain/vault-identity*.test.ts extension, CLI test tests/cli/brain-freeze.test.ts, MCP test that brain_create_note on a frozen vault returns the structured refusal and a write-refused event lands in the log, doctor-exit-census passes.
  • Acceptance: with the marker present every guarded content write throws VaultFrozenError naming frozen_at, by, reason and the next command; appendLogEvent still works; o2b brain freeze --reason x writes the marker and one freeze event, unfreeze removes it and writes one unfreeze event; a malformed marker freezes; o2b brain status and brain_status show frozen; o2b brain rollback on 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); new src/core/brain/notes/write-log.ts (listNoteWrites(vault, {agent, device, path, since, until, op}) over readLogDay); src/core/brain/notes/create-note.ts (record after the exclusive write, write_id / audit_reason on the result); src/core/brain/write-batch.ts (update/append commits: hash raw bytes before, store image, write, record; results gain write_id); src/mcp/brain/notes-tools.ts + write-batch-tools.ts (receipts carry write_id); src/core/brain/types.ts (event kind note-write); src/core/brain/agent-source/types.ts + vault-provider.ts (kind note); src/core/brain/destructive-sites.ts (image prune); src/core/state/surfaces.ts (write-images row, count +1); new CLI verb writes (list default with --agent --device --path --since --until --op --json, prune-images [--older-than-days N] [--dry-run]); new MCP tool brain_writes (action: list; plan_revert arrives in Task 5 - declare the enum with both members now and refuse plan_revert by 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 of tests/core/brain/write-batch.test.ts and the create-note suite, agent-source test for kind note, 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-write JSONL line with the fields in the design; the before-image file exists with sha256 = hash_before after an update; a second update to the same content does not write a second image; listNoteWrites filters by agent and path; brain_agent_query lists the note under kind note; a log-append failure (simulated) leaves the note written and the result with write_id: null and an audit_reason; prune-images --dry-run lists and --older-than-days 0 removes.
  • Depends on: none

Task 4: Per-shard hash chain on the Brain log (t_8a7bf39a)

  • Files: src/core/brain/log.ts (renderJsonlLine gains prev + h; the appender computes them from the shard text it already holds under the lock; LOG_CHAIN_FIELDS constant); src/core/brain/log-jsonl.ts (readJsonl ignores the two keys; export a raw-line scanner for the verifier); new src/core/brain/log-chain.ts (logChainHash, verifyLogChain(vault) -> { shards: [{ path, chained, legacy, firstBreak?: { line, reason } }], ok }); new doctor check + DIAGNOSTIC_SIGNALS entry log-chain-broken (nextCommand: "o2b brain log verify"); new CLI verb log with verify [--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 prev links match; editing the middle line's payload makes verify report line 2 hash-mismatch; deleting it reports line 3 prev-mismatch; a file of legacy lines followed by chained lines verifies clean with legacy = N; the doctor emits log-chain-broken only 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 (op revert); CLI writes revert --agent A | --device D [--path P] [--since --until] [--apply <digest>] [--json]; MCP brain_writes action plan_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 A plans one restore to the pre-A bytes and --apply <digest> restores them, takes a note-revert snapshot, and appends a note-write event with op: revert; if B updated in between the plan refuses interleaved; if the note changed after A's last write the plan refuses drift; a note A created is planned delete; 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.md surface count prose near line 201); CHANGELOG.md [1.55.0] + link reference; package.json 1.55.0 + bun run scripts/sync-version.ts; README paragraph; docs/observability.md final 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/python all green on the merged branch.
  • Depends on: Tasks 1-5