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.
Variant 1: Seam-first, thin shared primitives
- Approach: Add one note-write seam (
src/core/brain/notes/write-seam.ts) that every note mutation passes through: it checks the freeze marker, hashes the target before and after, runs the atomic write, and emits onenote_writelog event throughappendLogEventinsrc/core/brain/log.tswith the pref-audit field shape (agent,hash_before/after,origin_channelstamped server-side atlog.ts:335). Extract only the shard grammar, listing and merge fromsrc/core/brain/log-jsonl.ts:52-62into a smallledger-shards.tsand re-point the five unsharded writers at it; put the per-shardprevchain inside the log appender only; build revert as plan-seal-apply overnote_writeevents with the before-image resolved from a content-addressed image store written by the seam. Landing order: B (shards) β A (seam + event) β C (freeze at the seam) β E (chain in appender + doctor) β D (revert). - Trade-offs:
- Pro: A and C share one chokepoint, and the write-site census (
tests/core/architecture/write-site-census.test.ts) can pin "every note writer routes through the seam" the same way it pins direct-fs exclusions. Internal callers (dream apply, dedup merge, write-session commit inwrite-session/engine.ts:414,write-batch.ts:236) are covered because the seam sits below the MCP layer. - Pro: the shard extraction is mechanical;
continuity/store.ts:98,idempotency-ledger.ts:126,pref-audit.ts,metrics.ts:69andlineage/ledger.tseach swap one path function and one reader loop. The bare file name already means "empty shard id" (log-jsonl.ts:6), so no rename migration is needed, only a doctor lint that reports leftover bare files being appended to by a second device. - Pro: content-addressed before-images (
Brain/.state/write-images/<sha256>) dedupe naturally, and the log event only carries the hash. The snapshot gate (snapshot-gate.ts) coversBrain/top-level entries, so the image store is inside the recovery region. - Pro: revert reuses
sealManifestand thedestination_occupied-style drift refusal fromsrc/core/state/migrate.ts:186,724; the only new semantics are "refuse on drift", the simplest of the three options the task leaves open. - Con: the lineage ledger carries its own
seqand chain plus in-place compaction; sharding it per device means the verifier inlineage/verify.tsmust iterate shards, which is a real change, not a path swap. - Con: the image store grows with every edit until pruned; it needs a retention rule tied to the snapshot policy in
policy.tsor it becomes a second unbounded ledger. - Con: the chain lives in
log.ts, so other ledgers stay unchained. Acceptable per Task E scope, but a second chain later will want the primitive Variant 2 builds now. - Con: new
prevon every log line changes log bytes for every vault. Mitigation: legacy lines withoutprevare treated as chain genesis, and the verifier names themunchained-legacyrather than broken.
- Pro: A and C share one chokepoint, and the write-site census (
- Complexity: medium
- Risk: low
Variant 2: One append-only ledger abstraction carrying shards and chain
- Approach: Build
src/core/brain/ledger/as a typedAppendOnlyLedgerthat owns shard naming, the device id fromresolveDeviceId(), the sync writer lock, sync-conflict exclusion, deterministic merge, and an optional per-shard hash chain. Move Brain/log, continuity, idempotency, pref-audit, metrics and lineage onto it, so Task B and Task E are one change; Task A'snote_writeevent and Task C's freeze refusal event are records on the same log ledger; Task D reads the ledger's typed cursor and stores the before-image inline in the event. Landing order: ledger primitive β migrate six writers β seam + freeze β revert. - Trade-offs:
- Pro: sharding, locking and chaining are written once and every current and future ledger inherits them; the census for "did we miss one" becomes a type check rather than a grep over
src/core/state/surfaces.ts. - Pro: Task E's "which files are chained" question has one answer: any ledger with
chain: true, verified by one doctor check with one finding code. - Con: Brain/log has a markdown twin, a directory-level lock and a byte-exact idempotent append contract (
log.ts:335-380); folding it into a generic ledger risks changing bytes for vaults that enable nothing, which the constraints forbid. - Con: the lineage ledger's compaction, gap sidecar and
seqallocation (lineage/ledger.ts:100-180) do not fit a generic append-only shape without either a leaky escape hatch or a second abstraction. - Con: inline before-images make the log the largest file family in the vault and put note bodies into a file
o2b brain protectand Obsidian expose; redaction rules fromcontinuity/redaction.tswould have to apply to the log too. - Con: file count and review surface exceed the 50-70 file budget once six readers, six writers, their tests, and the pinned state-surface count are all touched in one PR.
- Pro: sharding, locking and chaining are written once and every current and future ledger inherits them; the census for "did we miss one" becomes a type check rather than a grep over
- Complexity: large
- Risk: high
Variant 3: Boundary middleware, core untouched
- Approach: Enforce freeze and emit write events at the MCP and CLI boundary: a
withWriteGuardwrapper overToolDefinitioninsrc/mcp/(next toreach-refusal.ts) and a matching CLI verb decorator, keyed on a tool allow-list of mutating verbs. Shards are done per ledger by copying theLOG_FILE_REgrammar into each writer; the chain goes intolog.ts; revert resolves before-images from the nearest snapshot manifest (manifest.tsdiffManifests) and refuses when none covers the write. Landing order: C β A β B β E β D. - Trade-offs:
- Pro: smallest diff, and the refusal shape is already the house style for boundary refusals (
src/mcp/reach-refusal.ts). - Pro: no change to core write functions, so bit-identical behaviour for unchanged vaults is trivially true.
- Con: the boundary is not the write seam. Dream apply, hygiene, lifecycle, page-dedup merge and the write-session engine mutate
Brain/from inside core and would bypass both the freeze and the event, which is exactly theo2b brain protectfailure the task cites. The census cannot pin a wrapper applied by list. - Con:
hash_beforemust be computed before the core write andhash_afterafter it, but the handler does not know the resolved target path untilresolveNoteTargetruns insidecreateNote; the wrapper ends up re-implementing target resolution or recording the caller's unresolved path. - Con: snapshots are opt-in and pruned, so most revert plans would refuse for lack of a before-image, making Task D mostly a report rather than an apply path.
- Con: five copies of the shard grammar drift the day one changes; the project's own DRY brief forbids this.
- Pro: smallest diff, and the refusal shape is already the house style for boundary refusals (
- Complexity: small
- Risk: high
Recommended: Variant 1
Rationale: The seam is the only position that satisfies both Task A and Task C for the internal writers the tasks explicitly list, and it is the position the existing censuses and the vault-identity guard (vault-identity.ts, "check before any byte") already occupy, so the architecture test can pin it. Extracting just the shard grammar keeps log.ts byte-stable for vaults that change nothing while still putting resolveDeviceId() behind one function, and the content-addressed image store gives Task D a real apply path without either bloating the log or depending on opt-in snapshots. Variant 2 is the right long-term shape but does not fit one wave under the bit-identical constraint, and Variant 3 repeats the bypassed-boundary failure the epic exists to fix.