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.
Implementation plan β Recall precision, coverage & provenance hardening
Branch: feat/recall-precision-provenance. Cards are driven ONE AT A TIME on this shared branch.
Each worker MUST git pull / build on the commits previously-driven in-scope cards already landed,
and must not duplicate or conflict with sibling tasks. Follow TDD: write the failing test first.
Combined design: docs/brainstorm/recall-precision-provenance/design.md.
Drive order: D7 β D1 β D2 β D3 β D4 β D5.
D7 β t_122b2cbc β Expose chunker minTokens as per-vault config
Note: maxTokens and overlapTokens are ALREADY operator-tunable
(indexer.ts:263-265 passes config.chunkSize/config.chunkOverlap; resolveSearchConfig reads
search_chunk_size/search_chunk_overlap config + env with validation). D7 narrows to exposing
the only missing knob: the chunk-packing floor minTokens (DEFAULT_MIN_TOKENS). The default
MUST equal the existing constant so chunk hashes are unchanged when no config is set (Syncthing-peer
determinism contract).
Files
src/core/search/index.tsβ addminTokenstoDEFAULTS(== existingDEFAULT_MIN_TOKENS), resolve it fromsearch_chunk_min_tokensconfig +OPEN_SECOND_BRAIN_SEARCH_CHUNK_MIN_TOKENSenv viaparseInteger, with validation (0 <= minTokens < chunkSize), add toResolvedSearchConfigreturn shape.src/core/search/types.tsβ addreadonly chunkMinTokens: number;toResolvedSearchConfig.src/core/search/indexer.ts:263-265β threadminTokens: config.chunkMinTokensinto the existingchunkMarkdown(...)call (alongside the already-presentmaxTokens/overlapTokens).tests/core/search/config.test.tsβ new/extended cases.
Acceptance (passing test)
A test in tests/core/search/config.test.ts that:
- Resolves config with
search_chunk_min_tokensset and assertschunkMinTokenscarries through; - Asserts the DEFAULT (no config) yields a value equal to
chunker.DEFAULT_MIN_TOKENS(import the constant) so chunk hashes are byte-identical to pre-change β the bit-identity guard; - Asserts validation rejects
minTokens >= chunkSize.
Depends on
None. Orthogonal. (Driven first.)
D1 β t_8da11868 β Context traces attached to logged events (provenance join)
A read-only correlation-join reader. Given a log event's correlation IDs, resolve the attached
context_receipt / recall_telemetry / generation_report via the existing continuity
read-model (read-model.ts, which already lifts session_id/turn_id/handoff fields to
first-class join keys). Missing records return empty, never throw (fail-open). Surfaced as
brain_context_trace (MCP) + o2b brain context-trace (CLI).
Files
src/core/brain/provenance/context-trace.ts(new) β pure join functionresolveContextTrace(vault, correlation)returning a frozen shape{ logEvent, receipts, recallTelemetry, generationReports }. Join on the read-model's lifted first-class fields (session_id,turn_id,handoffRef,timestamp,agent,sourceRefs). No new writes.src/core/brain/log.tsβ add a small read helper to load a single log event row by its JSONL sidecar id/timestamp if a join-by-id is needed (read-only; do not touchappendLogEvent).src/mcp/brain/recall-tools.tsβ addbrain_context_traceop (input: correlation fields or a log event id; output: the joined trace). Fail-open: missing β empty arrays.src/cli/brain.tsβ addcontext-tracesubcommand.tests/core/brain/context-trace.test.ts(new).
Acceptance (passing test)
A test in tests/core/brain/context-trace.test.ts over a fixture vault with a log event and
matching + non-matching continuity records that asserts:
- Given a log event's
session_id+turn_id, the reader returns exactly the matchingcontext_receipt/recall_telemetry/generation_report; - A log event with NO matching records returns empty arrays (not an error) β the fail-open guard;
- A partial-match (only
recall_telemetrypresent) returns that one and empty for the rest.
Depends on
None. Orthogonal.
D2 β t_0b83c97b β Read-time virtual line numbering (Lstart-Lend pointers)
Pure read-time functions + a LinePointer type (introduced here, reused by D5). Deterministic
1-based numbering from file start; bytes on disk never mutated.
Files
src/core/search/line-citation.ts(new) βLinePointer { path, lineStart, lineEnd }, purerenderWithLineNumbers(text, startLine?),extractLineRange(text, lineStart, lineEnd),parseLinePointer(str)/formatLinePointer(ptr)forpath:Lstart-Lendform.src/core/search/evidence-pack.tsβ addlineStart/lineEndtoEvidenceRecord(additive;buildEvidencePackcarries them over fromBrainSearchResult.startLine/endLine, which it already receives). Render aLinePointerfor eachEvidenceRecordwhen line-citation is requested. NOTE:EvidenceRecorddoes not currently carry line spans β the source values live onBrainSearchResult(types.ts:84-85) and thechunkstable (schema.ts:42-43); threading them in here is the additive change D2 makes.src/core/brain/session-recall.tsβ plumb theLstart-Lendform into the snippet/citation path (snippet()at ~510) as an alternative to char-offset.tests/core/search/line-citation.test.ts(new).
Acceptance (passing test)
A test in tests/core/search/line-citation.test.ts that:
renderWithLineNumbersapplies[N]markers 1-based and is a pure function (same input β same output, never mutates the input string);extractLineRange(text, 55, 72)returns exactly lines 55-72 inclusive;parseLinePointer("note.md:L55-L72")round-trips throughformatLinePointer;- Re-running render on an unchanged file yields identical numbering (idempotent β the "pointers never invalidate" invariant).
Depends on
None (introduces the LinePointer type D5 will import).
D3 β t_468190f5 β Generalize progressive disclosure to all recall
Compact-card β expand β raw-transcript disclosure for the general search, mirroring
searchSessionRecall/expandSessionRecall. Reuse the existing store read for layer 2/3, NOT a new
index. Default behavior stays full-content (bit-identical); disclosure: 'cards' opts in. The
existing query-lane expand flag stays distinct.
Files
src/core/search/types.tsβ add adisclosureoption ('full' | 'cards', default'full') and a compactSearchCardresult shape (path, title, score, reasons, snippet, pointer) for layer 1.src/core/search/search.tsβ whendisclosure === 'cards', return compact cards (layer 1); add anexpandHit(vault, hitId)returning layer 2 (fuller note) and a layer-3 raw chunk read via the existing store, reusingexpandSessionRecall's paginated-cursor pattern.src/cli/search.tsβ add--disclosure cardsflag + asearch expandsubcommand.src/mcp/brain/recall-tools.tsβ adddisclosurefield tobrain_search+ abrain_search_expandop.tests/core/search/disclosure.test.ts(new).
Acceptance (passing test)
A test in tests/core/search/disclosure.test.ts that:
disclosure: 'cards'returns compact cards (no full content) for layer 1;expandHiton a card returns the fuller note (layer 2) and the raw chunk (layer 3);- Default (no
disclosure) is bit-identical to pre-change output β the bit-identity guard; - The layer-2/3 expand reuses the existing store read (assert no new index file is created).
Depends on
D2 (renders LinePointer citations in the compact cards / expanded note).
D4 β t_23c1b929 β Normalized-confidence chain-stop for cross-vault recall
After each origin completes, if the top result's NORMALIZED [0,1] score >= threshold (default 0.8),
skip remaining origins and record which were skipped. Gates on normalized confidence, never raw
score. Distinct from the retrieve-or-not surfacing-gate and from query-cache. Default-off
(chainStopEnabled) β bit-identical.
Files
src/core/search/types.tsβ addchainStopEnabled: booleanandchainStopScore: numbertoResolvedRecallConfig; add achainStop?field to the cross-vault outcome recording{ triggered: true, stoppedAfter: <label>, skipped: [<labels>] }.src/core/search/index.tsβ resolvechain_stop_enabled(config + env, default false) andchain_stop_score(default 0.8) with[0,1]range validation.src/core/search/cross-vault.tsβ in the per-origin loop, after pushing results, ifchainStopEnabled && merged.length && topNormalizedScore >= chainStopScore, break and recordskipped= remaining origin labels. Top score is the normalized resultscore(already [0,1]).tests/core/search/cross-vault.test.tsβ new cases.
Acceptance (passing test)
A test in tests/core/search/cross-vault.test.ts with a multi-origin fixture that:
- With
chainStopEnabledon and the first origin's top normalized score >= 0.8, later origins are NOT searched andchainStop.skippedlists them; - A high RAW score on a tiny-corpus origin that yields a low NORMALIZED score does NOT trigger the stop (the normalized-not-raw guard);
chainStopEnabledoff (default) runs all origins, bit-identical to today, andchainStopis absent β the bit-identity guard.
Depends on
None for logic; drives before D5 so D5 builds on a settled search.ts/cross-vault.ts seam.
D5 β t_8eb5ca32 β Coverage-driven targeted self-correcting recall on partial misses
After the first evidence-pack pass, if uncoveredRareTerms is non-empty AND results exist (partial
miss, coverage below COMPLETENESS_COMPLETE_THRESHOLD), run exactly ONE targeted follow-up pass:
derive queries from the uncovered rare terms via existing query-expansion.ts/synonyms.ts,
re-query, merge. Distinct from the existing zero-candidate broadened-OR secondPass. Deterministic
trigger, no LLM, capped at one pass. Default-off (coverageRetryEnabled) β bit-identical. Reuses
D2's LinePointer to cite newly-found evidence.
Files
src/core/search/types.tsβ addcoverageRetryEnabled: booleantoResolvedRecallConfig; add acoverageRetry?field toSearchOutcomerecording{ triggered: true, uncoveredTerms: [...], added: <n> }.src/core/search/index.tsβ resolvecoverage_retry_enabled(config + env, default false).src/core/search/search.tsβ after the existing zero-candidatesecondPassblock, add a distinct branch: whenevidencePack && coverageRetryEnabled && results.length > 0 && evidencePack.uncoveredRareTerms?.length, build ONE targeted query from the uncovered rare terms viaderiveExpansionTerms/tokenizeForExpansion, re-query (runFtsQueryDetailed), merge any new hits, update the evidence pack, recordcoverageRetry. Hard cap: one pass. NOTE:deriveExpansionTermslives insynonyms.ts(notquery-expansion.ts);tokenizeForExpansionis also insynonyms.ts.query-expansion.tsimports it for internal use only (no re-export), so import both helpers directly fromsynonyms.ts.tests/core/search/coverage-retry.test.ts(new).
Acceptance (passing test)
A test in tests/core/search/coverage-retry.test.ts over a fixture vault where the first pass
returns results but leaves a rare term uncovered that:
- With
coverageRetryEnabledon, the targeted follow-up re-queries for the uncovered rare term and merges newly-found evidence, recordingcoverageRetry.triggeredwith the uncovered terms; - The retry runs exactly ONCE (a second uncovered term after the retry does not trigger a third pass) β the cap guard;
coverageRetryEnabledoff (default) is bit-identical to today andcoverageRetryis absent β the bit-identity guard;- A ZERO-candidate first pass still uses the existing
secondPass(not this path) β the distinctness guard.
Depends on
D2 (LinePointer import for citing new evidence) and D4 (settled search.ts seam to extend).