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.
Design - Cross-vault cards, event-trace exit codes, registry-guard hygiene
Problem
Three follow-ups deferred from the v1.18.0 CodeRabbit review on PR #110, all correctness/hygiene gaps on primary paths:
Cross-vault search drops
disclosure: "cards"results (t_fd411665). In--globalmode a cards-mode search returns nothing. Single-vaultsearch()in cards mode puts hits onoutcome.cardsand leavesoutcome.resultsempty;searchAcrossVaultsonly merges and ranksoutcome.results, so every origin's cards are dropped and the union is empty. Cards mode is the recommended token-cheap first layer, so the gap sits on a primary recall path. The chain-stop also no-ops in cards mode because it gates onresults.A genuine IO error from event-trace surfaces as a usage error (t_27ea0daa).
cmdBrainEventTrace's blanketcatchmaps ANY throw fromresolveLogEventTracestousageError(exit 2). That is correct for the selector checks (--date/--at/--kind) which run before any IO, butreadLogDay -> listLogShardFilescallsreaddirSyncguarded only byexistsSync: an existing-but-unreadable log dir (EACCES) or an EIO is a runtime failure that must be exit 1, not exit 2. The MCP twintoolBrainEventTracehas the identical blanket catch, mapping a runtime IO error toINVALID_PARAMSinstead of an internal error.Registry-guard membership check uses the
inoperator (t_6fbdba4b).auditPreviewBudgetstests exemption withtool.name in PREVIEW_BUDGET_EXEMPTand recomputesObject.keys(...)on every call.inwalks the prototype chain, so a tool whose name collides with anObject.prototypemember (constructor,toString,hasOwnProperty, ...) is falsely reported exempt; the per-callObject.keysis avoidable work.
Scope
src/core/search/cross-vault.ts- makesearchAcrossVaultscards-aware.src/core/brain/event-trace.ts- tag selector-validation errors with a distinct error type.src/cli/brain/verbs/event-trace.ts- route selector errors to exit 2 and runtime errors to exit 1.src/mcp/brain/pack-tools.ts- route the MCP twin's selector errors toINVALID_PARAMSand runtime errors toINTERNAL_ERROR.src/mcp/registry-guard.ts- hoist the exempt-name set once; use own-key membership instead ofin.
Out of scope
- No change to single-vault cards semantics,
expandHitlayers, or the progressive-disclosure grammar. - No change to the continuity store, the log shard format, or selector syntax.
- No new MCP tools, flags, or output fields beyond making
cardsflow through the union (theSearchCard.originfield already exists).
Chosen approach (Variant B - focused per-seam fixes)
Cross-vault cards. Accumulate each origin's
outcome.cardsinto amergedCardsarray, labelled by origin via alabelledCardhelper that mirrors the existinglabelled(setsoriginand anorigin:<label>reason). Detect cards mode fromopts.disclosure === "cards". The chain-stop gate reads the active origin's top score over whichever collection is populated (cards in cards mode, results otherwise). On return: full mode is byte-identical to today (resultscapped, nocards); cards mode returns sorted/cappedcardswithresultsempty, mirroring single-vault semantics. A shared comparator orders by score desc, then origin label, path, chunk id.Event-trace error classification. Introduce
EventTraceSelectorError extends Errorinevent-trace.ts. The three selector checks (validateIsoDatewrap,--atformat,--kindmembership) throw it; nothing on the IO path does. The CLI verb catch returnsusageError(exit 2) forEventTraceSelectorErrorandfail(exit 1) otherwise. The MCP handler returnsINVALID_PARAMSfor the selector error andINTERNAL_ERRORotherwise.Registry-guard hygiene. Precompute
PREVIEW_BUDGET_EXEMPT_NAMES = new Set(Object.keys(PREVIEW_BUDGET_EXEMPT))at module load and use.has()for membership; reuse it for theexemptButUnknownscan. This removes the per-callObject.keysand the prototype-chain false positive in one change.
Design decisions
- One shared selector-error type for both event-trace entry points. The CLI verb and the MCP tool wrap the same resolver and had the same blanket catch; classifying once in the resolver fixes both without duplicating format-validation logic. (Avoids a cheap one-surface-only fix.)
- Cards flow through the existing union, not a parallel function. The read-only invariants, session-focus resolution, and chain-stop policy are identical for cards and full mode; only the collection being merged differs.
SetoverObject.hasOwn. Both fix the prototype gotcha; the hoistedSetadditionally removes the repeatedObject.keysallocation.
File changes
| File | Change |
|---|---|
src/core/search/cross-vault.ts |
cards accumulator + labelledCard + card comparator; cards-mode chain-stop gate and return shape |
src/core/brain/event-trace.ts |
export EventTraceSelectorError; selector checks throw it |
src/cli/brain/verbs/event-trace.ts |
catch routes selector vs runtime to exit 2 vs exit 1 |
src/mcp/brain/pack-tools.ts |
catch routes selector vs runtime to INVALID_PARAMS vs INTERNAL_ERROR |
src/mcp/registry-guard.ts |
hoisted exempt-name Set; .has() membership |
Risks
- Cross-vault return-shape regression. Mitigated: full mode must stay
byte-identical; covered by the existing union tests plus a new cards-mode
test asserting
resultsempty andcardslabelled per origin. - Mis-tagging a runtime error as a selector error (or vice versa). Mitigated
by throwing the typed error ONLY in the three pre-IO checks and asserting an
EACCES/EIO surfaces as exit 1 /
INTERNAL_ERRORin tests. - A real tool legitimately named like a prototype member. None exists today;
the
Setmakes the guard correct if one is ever added.