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.
Honest Query Embed and Safe Upgrades - variants
The variants come from the primary consultant (claude -p, exit 0, 3 variants; cli-output/claude.md). The prompt is cli-output/prompt.md. The fallback consultant was not run, because the primary returned three parseable variants.
Consultant output (verbatim)
Variant 1: Provider choke point
- Approach: Move every query-embed rule into the embedding provider layer:
embed(texts, { kind, reach })performs the reach-and-price gate, the window truncation (it already knows the prefix it prepends) and the extra-body merge, sobelief-semantic.tsdrops its inline check andrunSemanticPhaseonly threadstransportReachthrough. Compare-before-write lands as a newexpectBeforeoption onatomicWriteFileSyncinfs-atomic.tswith a tri-state expectation (absent, or exact bytes), andapplyUpgradepasses each row'sbeforethrough it. - Trade-offs:
- Pro: literally one place; impossible to add a query surface that bypasses the rule.
- Pro: truncation sees the real prefix and model window, no mirrored estimate needed.
- Con: the provider also serves index-side passage embeds, so the gate must be keyed on
kindand reach must be invented for the indexer; cost policy and transport reach leak into a transport adapter. - Con: refusal surfaces as a provider error that
semantic-phasemust map back onto its explicit/implicit arms andbrain_context_packontoEMBEDDING_COST_UNPRICED, so the typed-code mapping is duplicated anyway. - Con:
query_tokensdisclosure andtruncatedflag have to travel back up through a result shape change onembed().
- Complexity: large
- Risk: medium
Variant 2: Query-embed gateway module plus drift-checked writes
- Approach: Add one module (
src/core/search/embeddings/query-embed.ts) exportingprepareQueryEmbed({ query, reach, model, config })that returns either a typed refusal (EMBEDDING_COST_UNPRICED) or a prepared input (text,truncated,estimatedTokensusing the ceiling estimator minus aqueryPrefixSentByProvidertwin of the passage-prefix helper; no declared window means no truncation).belief-semantic.tsandrunSemanticPhaseboth call it, withsearch()threadingtransportReachintorunSemanticLane; the explicit arm throws, the implicit arm records the existingRETRIEVAL_DEGRADATIONmember, andbrain_recall_feedbackinherits the behaviour unchanged. Extra body is one flat keyembedding_request_extraholding a JSON object string with env twin, validated against aRESERVED_EMBEDDING_BODY_KEYSconst, excluded from index identity.applyUpgrade(vault, plan?)accepts the plan the caller already showed, snapshots, then writes each row through a newexpectBeforeoption onatomicWriteFileSync(tri-state:nullfor absent) and raisesBrainUpgradeErrorUPGRADE_DRIFTnaming the files whose bytes moved. - Trade-offs:
- Pro: one rule in one named module, but the module stays query-specific so the indexer is untouched.
- Pro: refusal codes, truncation disclosure and reach resolution are computed once and returned as data, so the two call sites only differ in how they surface them.
- Pro:
expectBeforeis a reusable compare-and-swap primitive that mirrorswritePreferenceTxnexpectRevision and can be reused by other managed writers later. - Con:
before: ""must becomebefore: string | nullin plan rows, a type change across planner, CLI renderer and self-heal worker. - Con:
embedding_request_extraas a JSON string in flat YAML is a new value shape for the hand parser and its error message must name the key.
- Complexity: medium
- Risk: low
Variant 3: Policy resolved at the entry points, plan-digest guarded upgrade
- Approach:
search()andbrain_context_packeach build a resolvedQueryEmbedPolicyvalue (reach, price known, window or null) and pass it down;runSemanticPhaseandbelief-semantic.tsconsume it through a small pureapplyQueryBudget(policy, query)insearch/query-budget.ts. Extra body fields use a flat prefix conventionembedding_body_<field>: valuewith env twins, each scalar passed through as typed YAML, reserved names refused.applyUpgrade(vault, sealedDigest)keeps re-planning but seals the plan (digest over every row's path andbefore) like note revert, and refuses withUPGRADE_PLAN_DRIFTwhen the fresh plan's digest disagrees with the one the CLI or self-heal worker computed. - Trade-offs:
- Pro: smallest diff on the semantic lane; hooks and MCP callers need no change since reach resolution already happens in
search(). - Pro: prefix keys fit the existing flat config vocabulary without a new value shape.
- Con: the policy is assembled in two places, so the "one rule" is enforced by convention, not by a single function, and a new entry point can forget it.
- Con: a plan digest guards the window between show-and-apply but not the window between re-plan and write, so a hand edit landing during the tar+zstd snapshot is still overwritten.
- Con: prefix keys cannot express nested or array values, and the hand parser's unknown-key validation must learn a wildcard.
- Pro: smallest diff on the semantic lane; hooks and MCP callers need no change since reach resolution already happens in
- Complexity: small
- Risk: medium
Recommended: Variant 2
Rationale: The task's spine is "one rule on every surface", and only a query-specific gateway module makes that rule a single function both callers must go through without dragging cost policy into the provider adapter that also serves indexing. Its expectBefore write primitive closes the actual drift window at the moment of the write, which Variant 3's plan digest does not, and it follows the repo's existing expectRevision and sealed-digest precedents. The one JSON-object config key keeps the extra body expressive without a new wildcard key family in the hand-written YAML parser, and keeping it out of the index identity matches the v1.72.0 pricing precedent.
Orchestrator decision
Variant 2 is accepted, as the consultant recommended, with three overrides. The full rationale is in design.md, "Chosen approach".
- Key name. The key is
embedding_extra_body, notembedding_request_extra. It matches the card and theextra_bodyname operators already know from OpenAI client libraries. - An operator-declared input window (
embedding_input_window_tokens). Without it, query truncation would reach only the six curated preset models. This mirrors how v1.72.0 let the operator declare a price for an uncurated model. Absent means unknown, and unknown means no cut. - A drift pre-flight before the snapshot, in addition to the per-write
expectBefore. A run that is already stale is refused with nothing written and no snapshot taken.
Variant 1 is rejected because it puts cost and reach policy inside the provider adapter that also serves indexing, and it still duplicates the typed-code mapping at both callers. Variant 3 is rejected because "one rule" would rest on each entry point remembering to build the policy. Its plan digest also leaves the read-to-write window during the snapshot open, which is the exact window the follow-up is about.
Spec review (phase 1) found two things. First, defaultRecallRetriever drops the search trail, so a gated lane at the hooks would be silent. A task now carries the codes to the local audit line. Second, plugins/hermes/_schemas.py vendors no brain_recall_feedback response shape, so it is not touched.