Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(search): no cost meta without a model call; where and slug_prefix listed on the full MCP surface only, within the starter schema budget
garrytan7676ca24bd86
diff --git a/docs/TOOL_CATALOG.md b/docs/TOOL_CATALOG.mdindex f999fc141d..b584c40c36 100644--- a/docs/TOOL_CATALOG.md+++ b/docs/TOOL_CATALOG.md@@ -184,7 +184,7 @@ Every non-localOnly operation on the MCP surface: 157 tools across 25 areas. **S| `get_versions` | Page version history, newest snapshot first: metadata only (id, snapshot_at, title, type, tags, frontmatter) for the newest 20 versions by default. | read | | || `get_write_request` | Your write's receipt by request_id (after write_pending or a lost reply). | write | yes | || `list_page_purges` | Owner-only (`gbrain pages purges list`). | admin | | |-| `list_pages` | List pages with filters. | read | yes | |+| `list_pages` | List pages; filters incl. | read | yes | || `list_write_conflicts` | Pages whose writes keep ending in a source_changed conflict, grouped by slug. | read | | || `list_write_requests` | Your write receipts in one source, newest first (for a lost request_id). | write | yes | || `put_page` | Complete content REPLACES the whole page: read get_page include_content:true; its revision is expected_revision. | write | yes | |diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.tsindex a7f0ab0d16..9e543c8552 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 with filters. For 'what's recent / what did I touch this week' use sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row. Filters: type, tag, slug_prefix, updated_after, where (frontmatter fields); sort: updated_desc, updated_asc, created_desc, slug.",+ "description": "List pages; filters incl. slug_prefix, where (frontmatter). Recent / this week: sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row.","params": {"type": {"type": "string",@@ -554,11 +554,13 @@ export const OPERATION_MANIFEST: OperationMeta[] = [},"slug_prefix": {"type": "string",- "description": "Slugs starting with this literal text, e.g. 'deals/' (% and _ match themselves)."+ "description": "Literal slug prefix, e.g. 'deals/'.",+ "fullSurfaceOnly": true},"where": {"type": "object","cliKeyValue": true,+ "fullSurfaceOnly": true,"description": "Frontmatter equality, e.g. {status: \"active\"}; a list matches any."},"source_id": {@@ -1234,7 +1236,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = ["name": "search","idempotent": true,"outputRedaction": "retrieval",- "description": "Cheap hybrid search, no LLM expansion, top 20: exact tokens, names, field values. NOT proof of coverage; match: \"keyword\" pages every keyword match and takes OR across quoted names or codes (\"A\" OR \"B\" OR …): one call lists every page matching any. Name lists: entity names. Concepts/landscape or people/companies/projects by topic: `query`; lists: list_pages; personal: get_recent_salience. return_unit: sections or conversations. Filters: types, where (frontmatter fields); dates: `query`. fields: \"full\" adds diagnostics.",+ "description": "Cheap hybrid search, no LLM expansion, top 20: exact tokens, names, field values. NOT proof of coverage; match: \"keyword\" pages every keyword match and takes OR across quoted names or codes (\"A\" OR \"B\" OR …): one call lists every page matching any. Name lists: entity names. Concepts/landscape or people/companies/projects by topic: `query`; lists: list_pages; personal: get_recent_salience. return_unit: sections or conversations. fields: \"full\" adds diagnostics.","params": {"query": {"type": "string",@@ -1279,6 +1281,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = ["where": {"type": "object","cliKeyValue": true,+ "fullSurfaceOnly": true,"description": "Frontmatter equality, e.g. {status: \"active\"}; a list matches any."},"snippet_chars": {@@ -1358,7 +1361,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = ["name": "query","idempotent": true,"outputRedaction": "retrieval",- "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. Filters: types, since/until, where (frontmatter fields). fields: \"full\" adds diagnostics.",+ "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.","params": {"query": {"type": "string",@@ -1391,6 +1394,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = ["where": {"type": "object","cliKeyValue": true,+ "fullSurfaceOnly": true,"description": "Frontmatter equality, e.g. {status: \"active\"}; a list matches any."},"snippet_chars": {diff --git a/src/core/operations-descriptions.ts b/src/core/operations-descriptions.tsindex f8fc02985a..c8e5cfb417 100644--- a/src/core/operations-descriptions.ts+++ b/src/core/operations-descriptions.ts@@ -46,13 +46,13 @@ export const GET_RECENT_TRANSCRIPTS_DESCRIPTION =// ──────────────────────────────────────────────────────────────────────────────export const LIST_PAGES_DESCRIPTION =- "List pages with filters. For 'what's recent / what did I touch this week' use sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row. Filters: type, tag, slug_prefix, updated_after, where (frontmatter fields); sort: updated_desc, updated_asc, created_desc, slug.";+ "List pages; filters incl. slug_prefix, where (frontmatter). Recent / this week: sort=updated_desc. Default 50 rows; 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. Filters: types, since/until, where (frontmatter fields). fields: \"full\" adds diagnostics.";+ "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.";export const SEARCH_DESCRIPTION =- "Cheap hybrid search, no LLM expansion, top 20: exact tokens, names, field values. NOT proof of coverage; match: \"keyword\" pages every keyword match and takes OR across quoted names or codes (\"A\" OR \"B\" OR …): one call lists every page matching any. Name lists: entity names. Concepts/landscape or people/companies/projects by topic: `query`; lists: list_pages; personal: get_recent_salience. return_unit: sections or conversations. Filters: types, where (frontmatter fields); dates: `query`. fields: \"full\" adds diagnostics.";+ "Cheap hybrid search, no LLM expansion, top 20: exact tokens, names, field values. NOT proof of coverage; match: \"keyword\" pages every keyword match and takes OR across quoted names or codes (\"A\" OR \"B\" OR …): one call lists every page matching any. Name lists: entity names. Concepts/landscape or people/companies/projects by topic: `query`; lists: list_pages; personal: get_recent_salience. return_unit: sections or conversations. fields: \"full\" adds diagnostics.";/** `search`'s `match` param (Cat 40 Hard F2). */export const SEARCH_MATCH_DESCRIPTION = 'keyword: every match, paged.';diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.tsindex 1c62cc3468..1d5b583934 100644--- a/src/core/ops/pages.ts+++ b/src/core/ops/pages.ts@@ -519,7 +519,7 @@ const list_pages: Operation = {enum: [...LIST_PAGES_SORT_VALUES],},include_deleted: { type: 'boolean', description: 'Include soft-deleted pages.' },- slug_prefix: { type: 'string', description: "Slugs starting with this literal text, e.g. 'deals/' (% and _ match themselves)." },+ slug_prefix: { type: 'string', description: "Literal slug prefix, e.g. 'deals/'.", fullSurfaceOnly: true },where: WHERE_PARAM,// #4400 — list_pages had no source-scoping param at all: unlike// search/query it silently ignored any caller-supplied source and alwaysdiff --git a/src/core/ops/search.ts b/src/core/ops/search.tsindex e324177c20..0411332436 100644--- a/src/core/ops/search.ts+++ b/src/core/ops/search.ts@@ -126,7 +126,7 @@ function searchOutput(ctx: OperationContext, p: Record<string, unknown>, resultsconst emit = (output: { meta: Record<string, unknown> }, returned: SearchResult[]) => {recordRecallOutcome(returned);const cost = searchCostSnapshot();- ctx.emitResponseMeta?.('retrieval', { ...output.meta, timings: timings.snapshot(), ...(cost ? { cost } : {}) });+ ctx.emitResponseMeta?.('retrieval', { ...output.meta, timings: timings.snapshot(), ...(cost?.calls ? { cost } : {}) });return returned;};if (!evidence) {diff --git a/src/core/ops/where-param.ts b/src/core/ops/where-param.tsindex 1548c6c6d0..7f18755863 100644--- a/src/core/ops/where-param.ts+++ b/src/core/ops/where-param.ts@@ -7,7 +7,7 @@ import type { OperationContext, ParamDef } from './contract.ts';import { invalidParam } from './op-fix.ts';import { FrontmatterWhereError, WHERE_EXAMPLE, parseFrontmatterWhere, type FrontmatterWhere } from '../search/frontmatter-where.ts';-export const WHERE_PARAM: ParamDef = { type: 'object', cliKeyValue: true, description: 'Frontmatter equality, e.g. {status: "active"}; a list matches any.' };+export const WHERE_PARAM: ParamDef = { type: 'object', cliKeyValue: true, fullSurfaceOnly: true, description: 'Frontmatter equality, e.g. {status: "active"}; a list matches any.' };/** The validated filter, or undefined when absent; a bad key or value is invalid_params. */export function whereOpParam(ctx: Pick<OperationContext, 'remote' | 'transport'>, tool: string, raw: unknown): FrontmatterWhere | undefined {diff --git a/test/fixtures/goldens/cli/help-and-errors.json b/test/fixtures/goldens/cli/help-and-errors.jsonindex 4c1d0ffeef..7020b2f2f0 100644--- a/test/fixtures/goldens/cli/help-and-errors.json+++ b/test/fixtures/goldens/cli/help-and-errors.json@@ -718,7 +718,7 @@"stdout": ["Usage: gbrain query <query> [options]","",- "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. Filters: types, since/until, where (frontmatter fields). fields: \"full\" adds diagnostics.",+ "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.","","Options:"," <query> Question or topic (required unless image).",diff --git a/test/fixtures/goldens/cli/tools-json.json b/test/fixtures/goldens/cli/tools-json.jsonindex 5357374d14..6f0f3dd3ac 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": 253788,- "stdoutSha256": "aced261f1a8bf90d1fc1c3d32e7cf472997f3bfafba85d9c7a6890c639b7a5fa",+ "stdoutBytes": 253499,+ "stdoutSha256": "3d0b213b3db1c260314abd46136c79a5ddd0e2b34e6a62bcb6b97cd9d7b89493","toolNames": ["remember","entity",@@ -718,7 +718,7 @@"scope": "write"},{- "description": "List pages with filters. For 'what's recent / what did I touch this week' use sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row. Filters: type, tag, slug_prefix, updated_after, where (frontmatter fields); sort: updated_desc, updated_asc, created_desc, slug.",+ "description": "List pages; filters incl. slug_prefix, where (frontmatter). Recent / this week: sort=updated_desc. Default 50 rows; truncated: continue with updated_after + updated_after_slug from the last row.","idempotent": true,"local_only": false,"mutating": false,@@ -752,7 +752,7 @@"type": "number"},"slug_prefix": {- "description": "Slugs starting with this literal text, e.g. 'deals/' (% and _ match themselves).",+ "description": "Literal slug prefix, e.g. 'deals/'.","type": "string"},"sort": {@@ -1576,7 +1576,7 @@"scope": "write"},{- "description": "Cheap hybrid search, no LLM expansion, top 20: exact tokens, names, field values. NOT proof of coverage; match: \"keyword\" pages every keyword match and takes OR across quoted names or codes (\"A\" OR \"B\" OR …): one call lists every page matching any. Name lists: entity names. Concepts/landscape or people/companies/projects by topic: `query`; lists: list_pages; personal: get_recent_salience. return_unit: sections or conversations. Filters: types, where (frontmatter fields); dates: `query`. fields: \"full\" adds diagnostics.",+ "description": "Cheap hybrid search, no LLM expansion, top 20: exact tokens, names, field values. NOT proof of coverage; match: \"keyword\" pages every keyword match and takes OR across quoted names or codes (\"A\" OR \"B\" OR …): one call lists every page matching any. Name lists: entity names. Concepts/landscape or people/companies/projects by topic: `query`; lists: list_pages; personal: get_recent_salience. return_unit: sections or conversations. fields: \"full\" adds diagnostics.","idempotent": true,"local_only": false,"mutating": false,@@ -1716,7 +1716,7 @@"scope": "read"},{- "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. Filters: types, since/until, where (frontmatter fields). fields: \"full\" adds diagnostics.",+ "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.","idempotent": true,"local_only": false,"mutating": false,diff --git a/test/search-cost.serial.test.ts b/test/search-cost.serial.test.tsindex 0e20619a40..9970125393 100644--- a/test/search-cost.serial.test.ts+++ b/test/search-cost.serial.test.ts@@ -69,7 +69,7 @@ describe('search/query cost meta (#7158)', () => {keyless();const { rows, retrieval } = await callSearch(engine, { query: 'widget pricing' }, false);expect(rows.length).toBeGreaterThan(0);- expect(retrieval.cost).toEqual({ calls: 0, estimated_usd: 0 });+ expect(retrieval.cost).toBeUndefined();const timings = retrieval.timings as { total_ms: number; stages_ms: Record<string, number> };expect(timings.total_ms).toBeGreaterThanOrEqual(0);expect(timings.stages_ms.lexical).toBeGreaterThanOrEqual(0);@@ -110,7 +110,7 @@ describe('search/query cost meta (#7158)', () => {callSearch(engine, { query: 'widget', match: 'keyword' }, false),callQuery({ query: 'widget pricing', expand: false }),]);- expect(keyword.retrieval.cost).toEqual({ calls: 0, estimated_usd: 0 });+ expect(keyword.retrieval.cost).toBeUndefined();expect((hybrid.cost as Record<string, any>).rerank.calls).toBe(1);});});