Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
docs(search): name the per-brain expansion off switch; pin it with CLI-path tests
time-attack6794d814acc6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6eb1308c66..e486de26ae 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,15 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**You can turn query expansion off for a whole brain with one command: `gbrain config set search.expansion false` (docs and tests only, no behavior change).** The setting already worked: `gbrain query` over the CLI, MCP and `gbrain serve --http` all skip the expansion LLM call when a call leaves `expand` unset, and an explicit `--expand` / `expand: true` still expands. It was just not written down where people look. On a 300-question LongMemEval run, expansion added about 1.8 s per query with no measurable quality gain. The init mode picker, the search-modes guide and the install guide now name the command, and say that the brain host sets it (a thin client can't) on gbrain v0.60.188.0 or later.++### Itemized changes++- **Docs** (`src/core/search/mode-advice.ts`, `docs/guides/search-modes.md`, `INSTALL_FOR_AGENTS.md`): the per-brain off switch, how to undo it (`gbrain config unset search.expansion`), and who can set it on a hosted brain.+- **Tests** (`test/search/operation-expansion-contract.serial.test.ts`): `gbrain config set search.expansion false` followed by CLI-parsed `query` calls: unset expands in `tokenmax`, `false` does not, `false` plus `--expand` does, and unsetting the key restores expansion. `recall` never expands, even with `search.expansion=true`.+## [0.60.231.0] - 2026-10-14**Reading a large page no longer pulls the whole page into a response: `get_page` returns an outline and a window, and every remote window is cut from the privacy-sanitized view of the page (large pages Wave A, part 1).** Before, `get_page` of a 100 MB page built a 204 MB JSON-RPC frame. That is over the MCP SDK's 10 MiB stdio limit and far over the 25k tokens a harness accepts. Evidence delivery also read the whole body for every conversation hit: 2 s and +622 MB per hit at 100 MB. Now an MCP client that is not the thin client gets the full body up to the inline threshold, and above it an outline plus the first window with the exact call to read on. Windows, outlines and short leads all slice one projection with withdrawals applied, takes/facts fences stripped and credentials projected. A partial response never fills `compiled_truth`, `timeline` or `content`, so a read followed by a write cannot shrink a page by accident. Another guard backs this up: a remote `put_page` that would cut a large page to under half refuses unless `allow_shrink: true`. Pages up to today's ingest limits read as before through the local CLI and the thin client. The ceiling increase and searchability of large pages come in the next Wave A PR.diff --git a/INSTALL_FOR_AGENTS.md b/INSTALL_FOR_AGENTS.mdindex c552c38c0b..a5131b0a9c 100644--- a/INSTALL_FOR_AGENTS.md+++ b/INSTALL_FOR_AGENTS.md@@ -292,7 +292,8 @@ Estimated downstream input cost of the retrieved payload @ 10K queries/mo:>> Expansion follows the mode for `gbrain query` only: on in `tokenmax`, off in> `balanced` and `conservative`; `--expand` (`expand: true` over MCP) forces it-> and `--no-expand` (`expand: false`) skips it. `gbrain search` and the memory+> and `--no-expand` (`expand: false`) skips it. `gbrain config set search.expansion false`+> turns the default off for the brain in any mode. `gbrain search` and the memory> verbs never expand. See [search modes](docs/guides/search-modes.md) for the> current contract.>diff --git a/docs/guides/search-modes.md b/docs/guides/search-modes.mdindex 1d0cf83852..adf4b798c9 100644--- a/docs/guides/search-modes.md+++ b/docs/guides/search-modes.md@@ -52,6 +52,16 @@ verbs and the eval harnesses pin expansion per call, so `search` neverexpands, even with `search.expansion=true`. `gbrain search modes` reports theresolved row.+To turn expansion off for one brain without changing its mode, run+`gbrain config set search.expansion false` on the brain host. Every `query`+call that leaves `expand` unset then skips it: the CLI, MCP over stdio and+`gbrain serve --http` all resolve the same row. A call that passes+`--expand` / `expand: true` still expands. `gbrain config unset search.expansion`+returns to the mode default. The key is per brain and lives in its database,+so a thin client (`gbrain init --mcp-only`) can't set it; whoever runs the+brain host sets it, and the host needs gbrain v0.60.188.0 or later, because+`query` ignored `search.expansion` before that release.+Keyless retrieval takes the keyword-only path before expansion; configuredembedding and expansion providers are prerequisites. Image-only retrieval alsoskips expansion. Check response metadata `expansion_applied` for actualdiff --git a/llms-full.txt b/llms-full.txtindex 9d6654018a..d23fa44c0c 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -2855,7 +2855,8 @@ Estimated downstream input cost of the retrieved payload @ 10K queries/mo:>> Expansion follows the mode for `gbrain query` only: on in `tokenmax`, off in> `balanced` and `conservative`; `--expand` (`expand: true` over MCP) forces it-> and `--no-expand` (`expand: false`) skips it. `gbrain search` and the memory+> and `--no-expand` (`expand: false`) skips it. `gbrain config set search.expansion false`+> turns the default off for the brain in any mode. `gbrain search` and the memory> verbs never expand. See [search modes](docs/guides/search-modes.md) for the> current contract.>diff --git a/src/core/search/mode-advice.ts b/src/core/search/mode-advice.tsindex 076efa71d1..763c0c30e2 100644--- a/src/core/search/mode-advice.ts+++ b/src/core/search/mode-advice.ts@@ -86,7 +86,8 @@ export function costMatrixSentence(): string {/** How `query` and `search` expand, stated once. */export const QUERY_EXPANSION_LINE ='`gbrain query` expands only when the mode says so (off in conservative and balanced, on in tokenmax); ' +- '--expand forces it and --no-expand skips it. `gbrain search` never expands. An expansion is one call to the ' ++ '--expand forces it and --no-expand skips it. `gbrain config set search.expansion false` turns the default off for ' ++ 'the brain in any mode (true turns it on; an explicit --expand still wins). `gbrain search` never expands. An expansion is one call to the ' +'configured chat model, a separate provider charge; keyless brains never expand.';/** The picker's reason for each recommendation branch. */diff --git a/test/init-mode-picker.test.ts b/test/init-mode-picker.test.tsindex 0a4b5176e7..0be03b2407 100644--- a/test/init-mode-picker.test.ts+++ b/test/init-mode-picker.test.ts@@ -217,6 +217,7 @@ describe('cost matrix: newest models, priced from model-pricing', () => {const flat = MODE_PICKER_MENU.replace(/\s+/g, ' ');expect(flat).toContain('`gbrain query` expands only when the mode says so');expect(flat).toContain('`gbrain search` never expands');+ expect(flat).toContain('`gbrain config set search.expansion false` turns the default off for the brain');expect(flat).not.toMatch(/in every mode/);expect(MODE_PICKER_MENU).toContain('semantic result caching is temporarily disabled');expect(MODE_PICKER_MENU).toContain('gbrain search tune');diff --git a/test/search/operation-expansion-contract.serial.test.ts b/test/search/operation-expansion-contract.serial.test.tsindex 1371944223..c3cf006c9e 100644--- a/test/search/operation-expansion-contract.serial.test.ts+++ b/test/search/operation-expansion-contract.serial.test.ts@@ -19,6 +19,8 @@ import { _exports_for_test as searchCommand } from '../../src/commands/search.tsimport { buildTuneRecommendations } from '../../src/core/search/tune-recommendations.ts';import { configureGateway, resetGateway, __setEmbedTransportForTests } from '../../src/core/ai/gateway.ts';import { installFixtureChunks } from '../helpers/page-projection.ts';+import { parseOpArgs } from '../../src/cli/main.ts';+import { runConfig } from '../../src/commands/config.ts';const DIMS = 1536;const embedTransport = (async (p: { values: string[] }) => ({@@ -127,6 +129,53 @@ describe('query expansion follows the search mode', () => {}});+describe('per-brain off switch: `gbrain config set search.expansion false`', () => {+ async function runQueryCli(argv: string[], probe: ReturnType<typeof spyHybrid>): Promise<number> {+ const before = probe.expanderCalls.length;+ await operationsByName.query.handler(makeCtx({}), parseOpArgs(operationsByName.query, argv));+ return probe.expanderCalls.length - before;+ }++ test('unset expands in tokenmax, false stops it, an explicit --expand still wins, unset again restores it', async () => {+ await resetSearchConfig('tokenmax', undefined);+ const probe = spyHybrid(q => [q, `${q} alternate phrasing`]);+ const log = spyOn(console, 'log').mockImplementation(() => {});+ try {+ expect(parseOpArgs(operationsByName.query, ['Zirconiumneedle retrieval'])).not.toHaveProperty('expand');+ expect(await runQueryCli(['Zirconiumneedle retrieval'], probe)).toBe(1);++ await runConfig(engine, ['set', 'search.expansion', 'false']);+ expect(await engine.getConfig('search.expansion')).toBe('false');+ expect((await buildModesReport(engine)).resolved.expansion).toMatchObject({ value: false, source: 'override' });+ expect(await runQueryCli(['Zirconiumneedle retrieval'], probe)).toBe(0);+ expect(await runQueryCli(['Zirconiumneedle retrieval', '--expand'], probe)).toBe(1);+ expect(await runQueryCli(['Zirconiumneedle retrieval', '--no-expand'], probe)).toBe(0);++ await runConfig(engine, ['unset', 'search.expansion']);+ expect(await runQueryCli(['Zirconiumneedle retrieval'], probe)).toBe(1);+ } finally {+ log.mockRestore();+ probe.restore();+ }+ });++ test('recall never expands, even with search.expansion=true', async () => {+ await resetSearchConfig('tokenmax', 'true');+ const probe = spyHybrid(q => [q, `${q} alternate phrasing`]);+ try {+ await operationsByName.recall.handler(makeCtx({}), { query: 'Zirconiumneedle retrieval' });+ expect(probe.options.length).toBeGreaterThan(0);+ for (const opts of probe.options) {+ expect(opts?.expansion).toBe(false);+ expect(opts?.expandFn).toBeUndefined();+ }+ expect(probe.expanderCalls).toEqual([]);+ } finally {+ probe.restore();+ }+ });+});+describe('CRAG escalation reads what the first pass did', () => {test('callerExpanded is expansion_applied, not the requested flag', async () => {await resetSearchConfig('balanced', undefined);