Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(search): keep the starter tool list's headroom and core-search-2.md under its cap next to the operability wave (list_pages 'Default 50'; condensed key-files entries)
garrytan36656930baed
diff --git a/docs/architecture/key-files/core-search-2.md b/docs/architecture/key-files/core-search-2.mdindex 578e3992f5..3bbcea4f87 100644--- a/docs/architecture/key-files/core-search-2.md+++ b/docs/architecture/key-files/core-search-2.md@@ -33,9 +33,9 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/core/link-ranking-policy.ts` — the link-type ranking participation policy: `NON_RANKING_LINK_TYPES` (`amends`), `linkTypeRanks`, and `rankingLinkSql(alias)`, the inlined predicate every link-counting ranking reader applies (read-enrichment backlinks, adjacency, fanout, chain hops and degree; enrich inbound order; entity-resolution connection count; generated-page demotion; entity anchoring). Reference reads (graph ops, cards, `backlink_count`, referrers) keep these edges. Tests: `test/amends-link.test.ts` (+ Postgres twin), one invariance row per consumer.- `src/core/search/provenance-demotion.ts` — `applyGeneratedDemotion(engine, list, query, scope)`, called first in `applyIdentityBoosts` (hybrid/request.ts) on the fused path and both keyword-only paths, so it runs before reranking and before the pool is cut. Rows whose page carries a gbrain-owned marker (frontmatter `dream_generated: true`, type `extract_receipt`) get `provenance: 'generated'`; such a row is multiplied by `GENERATED_FACTOR` (0.5, stamped `generated_demotion`) only when the query names an entity (`resolveQueryEntity`), the page links to it by a ranking link type, and a non-generated row in the pool is the entity page or links to it. `recordsCorrection` (frontmatter `supersedes`/`corrects`, a facts-fence row with `valid_until`) exempts corrections. `search.demote_generated=false` keeps scores. Tests: `test/search-provenance-demotion.test.ts`.-- `src/core/search/frontmatter-where.ts` + `src/core/ops/where-param.ts` — the `where` frontmatter equality filter on `search`, `query` and `list_pages` (#7159; CLI `--where key=value`, repeat for AND, `key=a,b` for any-of, parsed in `cli/op-param-values.ts`). `parseFrontmatterWhere` caps keys (8, `[A-Za-z_][A-Za-z0-9_-]{0,63}`), values (32 per key, 256 chars) and rejects nested values as `invalid_params`. Each value becomes OR'd `p.frontmatter @> $n::text::jsonb` containments (scalar, one-element list, and the number/boolean a string spells), keys ANDed, so the GIN index `idx_pages_frontmatter` serves it; keys and values travel only inside bound JSON. The clause is pushed into every SQL leg (keyword, title, vector, CJK, `listPages`), a filtered call skips the hybrid cache, and `keepFrontmatterMatches` re-checks the finished rows for arms outside those legs (exact lookup, alias fan-out, facts). Visibility, source and private filters are unchanged. Tests: `test/search-frontmatter-where.test.ts`, `test/e2e/search-frontmatter-where-parity.test.ts`.-- `src/core/search/filter-hint.ts` — the one `search_filter_hint` info notice (deduped per session) a first-page `search`/`query` gets when it looks like it wanted a filter: the query names a page type the caller can see and under 80% of the top rows are that type (`types`), names a time (`since`/`until`; `search` points at `query`), or 90% of at least 8 top rows are one type it did not name. Never changes results, never throws. Test: `test/search-frontmatter-where.test.ts`.-- `src/core/search/search-cost.ts` — per-request model-call cost (`_meta.retrieval.cost`, #7158). `withSearchCost` wraps the `search`/`query` handlers (`metered` in ops/search.ts) and observes every `invokeAI` inside the request through `withAIInvocationMeter` (AsyncLocalStorage, so concurrent requests stay apart; `hasAIInvocationObservers` is true under a meter so unguarded SDK calls are seen too). Refused calls are not counted; USD from `usageCostUsd`; `gateway.expand` invocations get their own `expansion` line. Test: `test/search-cost.serial.test.ts`.+- `src/core/search/frontmatter-where.ts` + `src/core/ops/where-param.ts` — the `where` frontmatter equality filter on `search`, `query`, `list_pages` (#7159; CLI `--where key=value`). Bounded keys and values, else `invalid_params`; each value is a bound `p.frontmatter @> $n::text::jsonb` test (GIN-served), pushed into every SQL leg; a filtered call skips the hybrid cache and `keepFrontmatterMatches` re-checks the other arms. Tests: `test/search-frontmatter-where.test.ts`, its e2e parity file.+- `src/core/search/filter-hint.ts` — one `search_filter_hint` info notice per session when a first-page `search`/`query` names a type or time it did not filter on, or one type fills its top rows. Never changes results.+- `src/core/search/search-cost.ts` — `_meta.retrieval.cost` (#7158): `withSearchCost` meters every `invokeAI` in the request via `withAIInvocationMeter` (AsyncLocalStorage); refused calls are not counted; `gateway.expand` gets an `expansion` line. Test: `test/search-cost.serial.test.ts`.- `src/core/search/stage-timings.ts` — per-request search stage timings. The `search`/`query` handlers create one `SearchTimings` and thread it into every hybrid call of the request (`HybridSearchOpts._timings`, `HybridRequest.timer`; absent = `UNTIMED`, a pass-through). `stage(name, work)` books critical-path blocked wall-clock time: one current stage at a time, a nested stage takes the clock and hands it back, so a fan-out or escalation hybrid call is booked once under its own stages, and retries accumulate. `overlap(label, promise)` times concurrent work (the keyword and title arms) into `overlapped_ms` without adding it to a stage. `branch()` returns a timer for stages run alongside the critical path (hybrid's vector side: modality, expansion, embed, vector arms); until `join(branch, promise)` its stage time goes to `overlapped_ms` under the stage name, and from the join the wait is booked to the branch's current stage (the stage key appears in `stages_ms` even at 0). `snapshot()` reads `total_ms` from its own monotonic start, apportions integer `stages_ms` + `other_ms` to sum to it exactly (`other_ms >= 0`); `searchOutput` takes it after the returned rows are assembled and emits it as `_meta.retrieval.timings` (never in content blocks); `formatTimingsSummary` is the `--explain` line. Stages: setup, lexical, relational, expansion, embed, vector, fuse, post_fusion, rerank, alias_fanout, anchoring, facts_arm, response. The gate (every bench query: `0 <= total - sum(stages) <= 10%`) is the `timings` phase of `scripts/bench-refactor-wave-1.ts`. Pinned by `test/search/stage-timings.test.ts` and `test/search/stage-timings-ops.test.ts`.- `src/core/search/sql-ranking.ts` — Pure SQL string builders. `buildSourceFactorCase(slugColumn, boostMap, detail)` emits a CASE with longest-prefix-match wins (returns literal `'1.0'` when `detail === 'high'` for temporal-bypass parity with COMPILED_TRUTH_BOOST). `buildHardExcludeClause(slugColumn, prefixes)` emits `NOT (col LIKE 'p1%' OR col LIKE 'p2%')` — OR-chain wrapped in NOT, NOT `NOT LIKE ALL/ANY` (those quantifiers don't express set-exclusion). LIKE meta-character escape covers all three of `%`, `_`, AND `\` (backslash is Postgres LIKE's default escape char). Single-quote doubling on SQL string literals so injection-style inputs are inert text. `buildBestPerPagePoolCte(...)` is the shared per-page max-pool CTE both engines' `searchVector` inject — instead of returning the single best chunk per page from an inner `ORDER BY embedding <=> vec LIMIT N` (which lets a page lose to a neighbor on ONE weak chunk while its strong chunk sits just below the inner cut), the CTE pools the BEST chunk score per `(source_id, slug)` composite key so a page surfaces on its strongest evidence; composite key (not bare slug) keeps multi-source brains correct; single source of truth so the two engines can't drift.diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.tsindex 6f6e7fb410..dbd4d3817f 100644--- a/src/core/operation-manifest.generated.ts+++ b/src/core/operation-manifest.generated.ts@@ -512,7 +512,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = ["name": "list_pages","idempotent": true,"outputRedaction": "retrieval",- "description": "List pages by type, slug_prefix, frontmatter where; what did I touch this week: sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row.",+ "description": "List pages by type, slug_prefix, frontmatter where; what did I touch this week: sort=updated_desc. Default 50; truncated: continue with updated_after + updated_after_slug from the last row.","params": {"type": {"type": "string",diff --git a/src/core/operations-descriptions.ts b/src/core/operations-descriptions.tsindex 1a98b4c440..4d7440e105 100644--- a/src/core/operations-descriptions.ts+++ b/src/core/operations-descriptions.ts@@ -46,7 +46,7 @@ export const GET_RECENT_TRANSCRIPTS_DESCRIPTION =// ──────────────────────────────────────────────────────────────────────────────export const LIST_PAGES_DESCRIPTION =- "List pages by type, slug_prefix, frontmatter where; what did I touch this week: sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row.";+ "List pages by type, slug_prefix, frontmatter where; what did I touch this week: sort=updated_desc. Default 50; truncated: continue with updated_after + updated_after_slug from the last row.";export const QUERY_DESCRIPTION ="Hybrid search for concept/landscape questions and people/companies/projects by topic; expand adds multi-query expansion (expansion recovers synonyms). Still top-K; return_unit: sections or conversations. Lists: list_pages. Exact tokens: `search` is cheaper (no LLM call). Personal: get_recent_salience, find_anomalies; transcripts: `gbrain transcripts recent`. Do NOT assume 'crazy' means impressive (often difficult or emotionally charged). Needs an embedding key (else keyword-only); expansion needs a chat key. Fact rows: use follow_up. fields: \"full\" adds diagnostics.";diff --git a/test/fixtures/goldens/cli/tools-json.json b/test/fixtures/goldens/cli/tools-json.jsonindex 7893e87019..aba819566a 100644--- a/test/fixtures/goldens/cli/tools-json.json+++ b/test/fixtures/goldens/cli/tools-json.json@@ -2,8 +2,8 @@"golden": {"exitCode": 0,"stderr": "",- "stdoutBytes": 253499,- "stdoutSha256": "6fe1f75ed4ba8cf69bd122d187764d1d0eb6b49a79a3b716dc6d0dc853600a0a",+ "stdoutBytes": 253494,+ "stdoutSha256": "34ed4b9439a06d3e5f295ed1de62199f73772a1a955da6c255a4c58a1d0f4ac0","toolNames": ["remember","entity",@@ -718,7 +718,7 @@"scope": "write"},{- "description": "List pages by type, slug_prefix, frontmatter where; what did I touch this week: sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row.",+ "description": "List pages by type, slug_prefix, frontmatter where; what did I touch this week: sort=updated_desc. Default 50; truncated: continue with updated_after + updated_after_slug from the last row.","idempotent": true,"local_only": false,"mutating": false,