Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
docs(key-files): one hub-dampening bullet (fold the multi-hop planner's twin)
garrytan617ee152e60d
diff --git a/docs/architecture/key-files/core-search-2.md b/docs/architecture/key-files/core-search-2.mdindex e5f51e466b..2ad105b669 100644--- a/docs/architecture/key-files/core-search-2.md+++ b/docs/architecture/key-files/core-search-2.md@@ -4,7 +4,7 @@Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.- `src/core/search/explain-target.ts` — `explain_target` diagnosis. A `TargetTrace` (HybridSearchOpts.explainTarget) records the target page's presence and 1-based rank at each pipeline stage: every arm instance (`arm:<label>`, plus `arm:keyword_raw`/`arm:title_raw` before relaxed-row demotion), `fused`, `deduped`, `reranked`, `return_pool`, `limit_slice`, `token_budget`. `diagnoseTrace` returns one state (`retrieved` / `dropped` / `reinjected` / `not_retrieved` / `not_recorded`) naming the first stage that lost the page; boost stages are never reported as drops (they only re-order). `probeTarget` + `diagnoseProbe` run one read under the caller's read policy and separate not-indexed / stale projection / unsealed safe chunks / ambiguous slug; an unreadable page and an absent page return the same `target_not_found_or_not_visible`. Every diagnosis carries an Action-contract fix the `search`/`query` ops emit as a notice. Pinned by `test/search/explain.test.ts`.-- `src/core/search/hub-dampening.ts` — degree-aware weight for graph-derived lifts: `hubWeight(n, H) = 1/(1+((n-1)/H)^2)` (H = the half degree; `off` → 1), `dampenBoost` (scales a factor's excess over 1.0; never touches demotions), `normalizeHubDampening` (the ONE parse contract for `search.hub_dampening` and the per-call seam). `runPostFusionStages` fetches one caller-scoped degree map (`readBacklinkCounts`) shared by the backlink stage and graph signals; a failed read fails open with `meta.hub_dampening.errored`. Default `off` in every bundle until a held-out verdict; knobs-hash part `hd=` only when a half degree is set. Pinned by `test/search/hub-dampening.test.ts`.+- `src/core/search/hub-dampening.ts` — degree-aware weight for graph-derived lifts: `hubWeight(n, H) = 1/(1+((n-1)/H)^2)` (H = the half degree; `off` → 1), `dampenBoost` (scales a factor's excess over 1.0; never touches demotions), `normalizeHubDampening` (the ONE parse contract for `search.hub_dampening` and the per-call seam). Callers pass the caller-visible degree; the multi-hop chain executor (`relational-chain.ts`) uses `hubWeight` for typed-link hops. `runPostFusionStages` fetches one caller-scoped degree map (`readBacklinkCounts`) shared by the backlink stage and graph signals; a failed read fails open with `meta.hub_dampening.errored`. Default `off` in every bundle until a held-out verdict; knobs-hash part `hd=` only when a half degree is set. Pinned by `test/search/hub-dampening.test.ts`.- `src/core/search/evidence-delivery.ts` — the `return_unit` evidence assembler (default `auto`: conversation pages by type or `chat/`/`conversations/` slug come back whole under `search.return_budget_conversation` (24,000), every other hit is its unchanged chunk; `effectivePlan` skips the stage when an implied `auto` sees no conversation hit, so that path and `chunk` stay byte-identical). `resolveEvidencePlan` validates `return_unit` / `return_window` (invalid_params naming the allowed values and an example), reads `search.return_unit` / `think.return_unit`, `search.return_window`, `search.return_budget_default` (6,000), `search.return_budget_conversation` (24,000) and clamps remote budgets to `search.return_budget_max_remote` (32,000, reported). Snippet precedence: explicit `snippet_chars` > explicit `return_unit` > subagent default cap > config unit. `deliverEvidence` groups hits by page_id (one block per page at its best rank), makes ONE `engine.getChunkWindows` call (re-authorizes every page; unauthorized pages are dropped, never served from hit text), builds the page text from the stored body sanitized whole and passed through `credentialSafeProjection` before slicing (`pageEvidenceText`: compiled truth + serializer timeline sentinel + timeline; frontmatter excluded; private-key spans become newline-padded `<REDACTED:private_key_pem>` tokens, the same text the chunkers cut from), locates the hit chunks in it (`locateChunks`: exact, then whitespace-insensitive, since the chunker trims and folds whitespace), cuts `window` / `section` (ATX headings outside code fences, or conversation rounds detected structurally, never by page type) / `page` / `auto` (fenced-code hits are placed by their code minus the chunker's synthesized header), counts tokens as the sum of per-line cl100k counts, reserves each page's matching span before enriching by rank, caps blocks at 60,000 characters, redacts secrets before final accounting, and returns NEW rows with `delivered` plus a `delivery` meta. Fetch failure/timeout (5 s) falls back to the hit chunk only for live hits. `assembleEvidenceForHits` / op `assemble_evidence` deliver the exact evidence `query` returns for a frozen `(source_id, slug, chunk_id)` list; `evidenceFingerprint` hashes it (gbrain-evals E1/E3 parity). Normative spec: `docs/evidence-delivery.md`. Tests: `test/evidence-delivery.test.ts`, `test/evidence-delivery-golden.test.ts`, `test/e2e/evidence-delivery-leak.test.ts`, `test/e2e/evidence-delivery-parity.test.ts`; bench `scripts/bench-evidence-delivery.ts`.- `src/core/search/chunk-windows.ts` — request/response shapes and the row mapper for `BrainEngine.getChunkWindows`. The SQL lives once in `src/core/engine-sql/chunks.ts` (`getChunkWindows`): page rows (authorization + seal + max chunk index + raw body columns) and chunk rows (inside the requested chunk_index ranges, text modality, requested chunk sources, row cap) come back in one UNION so the row cap never hides a page's authorization; the predicate is the search legs' (source scope, deleted, current text projection, archived source, quarantine, private pages, safe chunks). Postgres runs it inside the scoped read transaction.@@ -38,7 +38,6 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/core/search/relational-plan.ts` — `parseRelationalPlan`: deterministic planner for questions chaining 2-3 typed relationships (bounded lexer, fixed lexicon of verb / passive / agent-noun / outgoing-noun forms, one anchor span, anchor-outward hop order with the main-clause verb outermost, type coherence, head-noun constraint). Returns `plan` / `not_applicable` (fewer than two relationships) / `unsupported` with a reason (coordination, negation, time, counting, quotes, multiple entities, incoherent types). `isRelationalQuery(query, plannerOn)` is the relational test for ranking decisions; planner off it equals `parseRelationalQuery`. Pinned by `test/relational-plan.test.ts`.-- `src/core/search/hub-dampening.ts` — `hubWeight(degree, H)` = 1 / (1 + ((max(n,1) − 1) / H)²), `'off'` → 1; `dampenBoost`, `normalizeHubDampening`. Pure; callers pass the caller-visible degree.- `src/core/search/relational-recall.ts` — the relational recall arm: `parseRelationalQuery` → seed resolution per in-scope source (federated set, scalar source, or every non-archived source for an unscoped caller; a literal `__all__` resolves no seeds, fail-closed) → `relationalFanout` → hydrate, fail-open. Seeds resolve through `resolveEntitySlugWithSource` and a `fallback_slugify` result is dropped (confidence gate D3). The entity resolver never returns meetings, so for an incoming `attended` relation (`Who attended <meeting>?`) a live `meeting` or `event` page whose title is exactly the seed phrase (case-insensitive, unique in the source) is the seed; other relations never seed from titles. Pinned by `test/relational-recall.test.ts`, `test/relational-recall-scope-sources.test.ts` and `test/pack-relation-direction-engine.test.ts`. With `planner` on (`search.relational_planner`, on in balanced/tokenmax), a 2-3 relationship question (`parseRelationalPlan`) runs `runRelationalChain` first: answers then evidence pages, each with a `relational` field; nothing found → the one-hop path; refused → no arm (`meta.plan`). With `orientOneHop` (`search.relational_orient_onehop`, off in every bundle) typed one-hop walks add neighbors reached through links written on the other page. `answerRows` limits the pin and evidence slot to answers. Pinned by `test/relational-recall.test.ts`.