Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(closeout): goldens and exact-argv expectations follow the A1 routing pin; suggestion prose quotes the pinned command; protocol behavior rows; llms rebuilt
garrytan808677b81e5b
diff --git a/docs/protocol/AGENT_OPERATOR_v1.md b/docs/protocol/AGENT_OPERATOR_v1.mdindex adf0a8558a..2b7f6893dd 100644--- a/docs/protocol/AGENT_OPERATOR_v1.md+++ b/docs/protocol/AGENT_OPERATOR_v1.md@@ -956,6 +956,10 @@ old behaviour. The release's CHANGELOG entry carries the same table.| stdin reads | could wait forever on an open, silent pipe | 30 s to the first byte, 60 s idle; `GBRAIN_STDIN_TIMEOUT_MS` overrides | close stdin or pipe the payload || Prompts under an agent process or `CI` | prompted whenever stdin was a terminal | decline unless `GBRAIN_INTERACTIVE=1` | answer through the consent payload instead || `--json` stdout for commands that declare it | could mix human text into stdout or print nothing on failure | exactly one JSON document; other output goes to stderr; a fallback document on a silent non-zero exit | parse stdout as one document |+| Fix commands (`fix.argv`, `command`, `preview_argv`, `verify.argv`, `then`) | a few named the brain and source; most ran against whatever `GBRAIN_BRAIN_ID`, `GBRAIN_SOURCE` or dotfile the shell had | every gbrain fix names `--brain <id>` (and `--source <id>` where the command routes a source), so it acts on the intended brain from any directory | run fixes exactly as given |+| `gbrain doctor --remediation-plan` on a brain with pending migrations | applied the migrations before computing the plan | never migrates; the plan carries a `migrations_pending` notice whose fix applies them | run the notice's fix, or `doctor --remediate` after consent |+| `sources harden` with no id, `migrate` without `--to`, `mcp grant` without a NAME, malformed `backup create/restore` | exit 1 (`sources harden`: `internal_error`) | exit 2, `invalid_params`, with the usage and an example | treat 2 as "fix the command" |+| `gbrain db-repair` under an ambient `GBRAIN_BRAIN_ID` pointing at a mount | refused, ignoring `--brain host` | `--brain host` repairs the host brain | none |## Tool catalog changes (`tools/list_changed`)diff --git a/llms-full.txt b/llms-full.txtindex 0297f28ff5..28d0ee976f 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -3131,9 +3131,13 @@ gbrain returns (`isError: true`, the envelope shown parsed):"gbrain","list","--sort",- "updated"+ "updated",+ "--brain",+ "host",+ "--source",+ "default"],- "command": "gbrain list --sort updated",+ "command": "gbrain list --sort updated --brain host --source default","mcp": {"tool": "list_pages","arguments": {@@ -3184,7 +3188,7 @@ stdout (`--json`):"error": "confirmation_required","code": "confirmation_required","message": "doctor --remediate needs the user's approval before it runs; nothing was changed.",- "suggestion": "Ask the user: Fixing your brain's health will cost about $0.40 in embedding calls. OK to proceed? If they agree, run: gbrain doctor --remediate --max-usd 0.60 --yes",+ "suggestion": "Ask the user: Fixing your brain's health will cost about $0.40 in embedding calls. OK to proceed? If they agree, run: gbrain doctor --remediate --max-usd 0.60 --yes --brain host","effects": ["paid"],@@ -3200,9 +3204,11 @@ stdout (`--json`):"--remediate","--max-usd","0.60",- "--yes"+ "--yes",+ "--brain",+ "host"],- "command": "gbrain doctor --remediate --max-usd 0.60 --yes",+ "command": "gbrain doctor --remediate --max-usd 0.60 --yes --brain host","consent": ["paid"],@@ -3215,7 +3221,9 @@ stdout (`--json`):"gbrain","doctor","--remediation-plan",- "--json"+ "--json",+ "--brain",+ "host"]},"preview": {@@ -3223,9 +3231,11 @@ stdout (`--json`):"gbrain","doctor","--remediation-plan",- "--json"+ "--json",+ "--brain",+ "host"],- "command": "gbrain doctor --remediation-plan --json"+ "command": "gbrain doctor --remediation-plan --json --brain host"},"preapprove_argv": ["gbrain",@@ -3253,15 +3263,15 @@ risk: Spends up to the cap on embedding calls; no data is deleted.consent: paidactor: agentnext: ask_user-if_yes: gbrain doctor --remediate --max-usd 0.60 --yes — To stop asking for runs under a limit the user picks: gbrain config set consent.preapprove.paid.max_usd_per_run '<usd>'-if_no: Nothing runs; nothing was changed. To look first (read-only): gbrain doctor --remediation-plan --json+if_yes: gbrain doctor --remediate --max-usd 0.60 --yes --brain host — To stop asking for runs under a limit the user picks: gbrain config set consent.preapprove.paid.max_usd_per_run '<usd>'+if_no: Nothing runs; nothing was changed. To look first (read-only): gbrain doctor --remediation-plan --json --brain host[SHOW USER]Fixing your brain's health will cost about $0.40 in embedding calls. OK to proceed?[/SHOW USER][/AGENT]```-Nothing ran and the command exited 3. The agent reads `fix.next: ask_user`, relays `user_message` ("Fixing your brain's health will cost about $0.40 in embedding calls. OK to proceed?") and stops. It may offer the read-only preview `gbrain doctor --remediation-plan --json`. Only after the user agrees does it run `gbrain doctor --remediate --max-usd 0.60 --yes`. Passing `--yes` on its own would be a consent violation even though gbrain cannot tell the difference.+Nothing ran and the command exited 3. The agent reads `fix.next: ask_user`, relays `user_message` ("Fixing your brain's health will cost about $0.40 in embedding calls. OK to proceed?") and stops. It may offer the read-only preview `gbrain doctor --remediation-plan --json --brain host`. Only after the user agrees does it run `gbrain doctor --remediate --max-usd 0.60 --yes --brain host`. Passing `--yes` on its own would be a consent violation even though gbrain cannot tell the difference.### 3. An empty recall with a notice: `tell_user_to_run`@@ -3284,12 +3294,12 @@ gbrain returns these content blocks:```text[gbrain notice empty_retrieval kind=info]why: No pages matched. Search ran keyword-only because embeddings are not configured.-fix: gbrain doctor --json+fix: gbrain doctor --json --brain hostnext: tell_user_to_runuser_message: I found no notes on that topic. Your brain searches keywords only right now.```-`content[0]` is still the bare array `[]`; the second block is the notice. The agent does not tell the user "you have no notes on that". It relays `user_message` ("I found no notes on that topic. Your brain searches keywords only right now."). `fix.next` is `tell_user_to_run` because the fix is the user's to run (`gbrain doctor --json`) in their terminal, so the agent offers it rather than running it.+`content[0]` is still the bare array `[]`; the second block is the notice. The agent does not tell the user "you have no notes on that". It relays `user_message` ("I found no notes on that topic. Your brain searches keywords only right now."). `fix.next` is `tell_user_to_run` because the fix is the user's to run (`gbrain doctor --json --brain host`) in their terminal, so the agent offers it rather than running it.### 4. First run on a keyless brain: one decision bundle, `ask_user` (journey)@@ -3665,7 +3675,7 @@ and report it if it repeats.interface RenderedAction {argv?: string[]; // ['gbrain', …]: explicit --brain/--source; positionals after '--'command?: string; // shell-quoted from argv; never hand-built- mcp?: { tool: string; arguments: Record<string, unknown> }; // present only when callable on your connection+ mcp?: { tool: string; arguments: Record<string, unknown> }; // present when callable on your connection (or relayed: see below)consent: Effect[]; // [] means no consent neededactor: 'agent' | 'user' | 'host_admin' | 'provider';next: 'run' | 'ask_user' | 'tell_user_to_run' | 'wait' | 'report';@@ -3681,6 +3691,20 @@ interface RenderedAction {}```+**Explicit routing.** Every `gbrain` argv in a fix (`argv`, `preview_argv`,+`verify.argv`, `then`) names the brain and source the failing call acted on:+`--brain <id>` for commands that open a brain, `--source <id>` for commands that+resolve their source through the ambient chain (shared ops, and CLI commands the+command table marks `routes_source`). gbrain appends them when it renders the+fix, before any bare `--`, and keeps flags the fix already carries. So you can+run the fix later from another directory, or under a different `GBRAIN_BRAIN_ID`,+`GBRAIN_SOURCE`, `.gbrain-mount` or `.gbrain-source`, and it still acts on the+intended brain. Over HTTP only the source id is pinned, and only where a thin+client can send it (an op with a `source_id` scope, or a command the brain+host's operator runs): a mount id is host topology, and a thin client refuses+`--brain`. Paths are stripped as everywhere else. A thin client pins nothing of+its own: it has no local mounts and its remote scopes the source.+`next` is computed when gbrain renders the fix for your connection: from theeffects, the actor, the transport, which tools you can call and the user'spreapprovals. It is never stored, so the same fix can say `run` on the CLI and@@ -3713,14 +3737,18 @@ First matching row wins.| # | Condition | `next` ||---|---|---|-| 1 | no runnable step (no `argv`, no callable `mcp`) | `report`: relay `message`; run `gbrain doctor --json` where you can |+| 1 | no runnable step (no `argv`, no callable `mcp`, and not an MCP-only fix on the CLI) | `report`: relay `message`; run `gbrain doctor --json` where you can || 2 | `actor = provider` | `wait`: retry after the stated delay with the same request identity |-| 3 | `actor` is `user` or `host_admin`, or the fix is CLI-only and you are on MCP | `tell_user_to_run` |+| 3 | `actor` is `user` or `host_admin`, or the fix is CLI-only and you are on MCP, or MCP-only and you are on the CLI | `tell_user_to_run` || 4 | `consent` is non-empty and not covered by a matching preapproval (`destructive` never is) | `ask_user` || 5 | otherwise | `run` |A CLI-only fix rendered for an MCP caller gets actor `user` on stdio and-`host_admin` on HTTP, and `next: tell_user_to_run`.+`host_admin` on HTTP, and `next: tell_user_to_run`. The mirror case: an+MCP-only fix rendered for the CLI (a remote brain's fix on a thin client) keeps+its `mcp` call as data, gets actor `user`, a `user_message` saying to call that+tool over MCP, and `next: tell_user_to_run`; the human line reads+`Fix: call <tool> over MCP with {…}`.### Exclusive fixes and two-step plans@@ -4000,6 +4028,10 @@ old behaviour. The release's CHANGELOG entry carries the same table.| stdin reads | could wait forever on an open, silent pipe | 30 s to the first byte, 60 s idle; `GBRAIN_STDIN_TIMEOUT_MS` overrides | close stdin or pipe the payload || Prompts under an agent process or `CI` | prompted whenever stdin was a terminal | decline unless `GBRAIN_INTERACTIVE=1` | answer through the consent payload instead || `--json` stdout for commands that declare it | could mix human text into stdout or print nothing on failure | exactly one JSON document; other output goes to stderr; a fallback document on a silent non-zero exit | parse stdout as one document |+| Fix commands (`fix.argv`, `command`, `preview_argv`, `verify.argv`, `then`) | a few named the brain and source; most ran against whatever `GBRAIN_BRAIN_ID`, `GBRAIN_SOURCE` or dotfile the shell had | every gbrain fix names `--brain <id>` (and `--source <id>` where the command routes a source), so it acts on the intended brain from any directory | run fixes exactly as given |+| `gbrain doctor --remediation-plan` on a brain with pending migrations | applied the migrations before computing the plan | never migrates; the plan carries a `migrations_pending` notice whose fix applies them | run the notice's fix, or `doctor --remediate` after consent |+| `sources harden` with no id, `migrate` without `--to`, `mcp grant` without a NAME, malformed `backup create/restore` | exit 1 (`sources harden`: `internal_error`) | exit 2, `invalid_params`, with the usage and an example | treat 2 as "fix the command" |+| `gbrain db-repair` under an ambient `GBRAIN_BRAIN_ID` pointing at a mount | refused, ignoring `--brain host` | `--brain host` repairs the host brain | none |## Tool catalog changes (`tools/list_changed`)diff --git a/src/core/agent-output.ts b/src/core/agent-output.tsindex 527280843f..0b19f6e8e0 100644--- a/src/core/agent-output.ts+++ b/src/core/agent-output.ts@@ -353,10 +353,16 @@ export interface EnvelopeParts {retryable?: boolean;}-function appendFixToSuggestion(suggestion: string, fix: RenderedAction | undefined): string {+function appendFixToSuggestion(suggestion: string, fix: RenderedAction | undefined, unpinned?: readonly string[]): string {if (!fix) return suggestion;const step = renderedStep(fix);if (!step || suggestion.includes(step)) return suggestion;+ // Prose that already quotes the fix before its A1 routing pin quotes the pinned command instead (never both).+ const bare = unpinned?.length && !fix.mcp ? shellQuote(unpinned) : undefined;+ if (bare && bare !== step) {+ const quoted = new RegExp(`${bare.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\w/-]|\\s+-)`, 'g');+ if (quoted.test(suggestion)) return suggestion.replace(quoted, () => step);+ }const prose = suggestion.trim();return prose ? `${prose.replace(/[.\s]*$/, '.')} Next: ${step}` : `Next: ${step}`;}@@ -365,7 +371,7 @@ function appendFixToSuggestion(suggestion: string, fix: RenderedAction | undefinexport function buildEnvelope(p: EnvelopeParts, ctx: RenderContext): AgentEnvelope {const entry = codeEntry(p.code);const fix = p.fix ? renderAction(p.fix, ctx) : undefined;- const suggestion = appendFixToSuggestion(p.suggestion ?? entry?.suggestion ?? '', fix);+ const suggestion = appendFixToSuggestion(p.suggestion ?? entry?.suggestion ?? '', fix, p.fix?.argv);const docs = p.docs ?? entry?.docs ?? `docs/guides/error-codes.md#${p.code}`;const notices = p.notices?.length ? orderNotices(p.notices).map(n => renderNotice(n, ctx)) : undefined;return {diff --git a/test/agent-error-surfaces.serial.test.ts b/test/agent-error-surfaces.serial.test.tsindex 2a10e55a22..6c83f572b3 100644--- a/test/agent-error-surfaces.serial.test.ts+++ b/test/agent-error-surfaces.serial.test.ts@@ -177,10 +177,14 @@ afterAll(async () => {interface Expect { error: string; code: string; fixArgv: string[] | null }-/** error, code and fix.argv as the expectation says (fix absent when fixArgv is null). */-function expectSurvives(env: Record<string, any>, want: Expect, where: string): void {+/**+ * error, code and fix.argv as the expectation says (fix absent when fixArgv is null). `pin` is the A1+ * routing the surface renders into the argv (`--brain`/`--source` on the CLI and stdio; only a+ * thin-client-sendable `--source` over HTTP; nothing where no routing is known).+ */+function expectSurvives(env: Record<string, any>, want: Expect, where: string, pin: string[] = []): void {expect({ where, error: env.error, code: env.code, fixArgv: env.fix?.argv ?? null })- .toEqual({ where, error: want.error, code: want.code, fixArgv: want.fixArgv });+ .toEqual({ where, error: want.error, code: want.code, fixArgv: want.fixArgv ? [...want.fixArgv, ...pin] : null });expect(env.contract_version).toBe(1);}@@ -206,8 +210,10 @@ const unpriced = (): unknown => {};const DOCTOR = ['gbrain', 'doctor', '--json'];+const BRAIN_PIN = ['--brain', 'host'];-interface Family { name: string; make(): unknown; want: Expect }+/** `localPin`: what a routed local render (stdio dispatch here) appends to the fix argv. */+interface Family { name: string; make(): unknown; want: Expect; localPin?: string[] }const FAMILIES: Family[] = [{ name: 'StructuredAgentError', make: () => errorFor({ class: 'UsageError', code: 'code_def_requires_symbol', message: 'code-def requires a symbol name', hint: 'gbrain code-def <symbol>' }),@@ -215,23 +221,23 @@ const FAMILIES: Family[] = [{ name: 'GBrainError', make: () => new GBrainError('Invalid engine: "sqlite"', 'Must be "postgres" or "pglite"', 'Pass --engine pglite or --engine postgres'),want: { error: 'config_error', code: 'config_error', fixArgv: null } },{ name: 'PhaseError (legacy object)', make: () => ({ class: 'PhaseError', code: 'storage_error', message: 'disk full during extract' }),- want: { error: 'storage_error', code: 'storage_error', fixArgv: DOCTOR } },+ want: { error: 'storage_error', code: 'storage_error', fixArgv: DOCTOR }, localPin: BRAIN_PIN },{ name: 'AIConfigError', make: () => new AIConfigError('No OpenAI key configured', 'export OPENAI_API_KEY=<key> in the brain host env'),- want: { error: 'unavailable', code: 'unavailable', fixArgv: DOCTOR } },+ want: { error: 'unavailable', code: 'unavailable', fixArgv: DOCTOR }, localPin: BRAIN_PIN },{ name: 'CredentialError', make: () => new CredentialError('access_env_missing', ' (GOOGLE_TOKEN)'),want: { error: 'access_env_missing', code: 'access_env_missing', fixArgv: null } },{ name: 'RemoteMcpError (relayed)', make: () => new RemoteMcpError('network', 'Request to http://127.0.0.1:1/mcp timed out', { kind: 'timeout' }),want: { error: 'timeout', code: 'timeout', fixArgv: ['gbrain', 'remote', 'doctor'] } },{ name: 'GBRAIN_DB_ACCESS', make: () => Object.assign(new Error('connect ECONNREFUSED 127.0.0.1:5432'), { code: 'ECONNREFUSED' }),- want: { error: 'database_error', code: 'database_error', fixArgv: ['gbrain', 'db-repair'] } },+ want: { error: 'database_error', code: 'database_error', fixArgv: ['gbrain', 'db-repair'] }, localPin: BRAIN_PIN },{ name: 'F0 refresh refusal', make: () => catalogueError('refresh_dirty', 'The worktree has uncommitted changes.', 'gbrain sources refresh --source wiki --stash'),- want: { error: 'refresh_dirty', code: 'refresh_dirty', fixArgv: ['gbrain', 'sources', 'refresh', '--source', 'wiki', '--stash'] } },+ want: { error: 'refresh_dirty', code: 'refresh_dirty', fixArgv: ['gbrain', 'sources', 'refresh', '--source', 'wiki', '--stash'] }, localPin: BRAIN_PIN },{ name: 'no_pricing', make: unpriced,- want: { error: 'no_pricing', code: 'no_pricing', fixArgv: ['gbrain', 'pricing', 'set', 'example:unpriced-model-x', '--input', '<usd-per-1M-input-tokens>', '--output', '<usd-per-1M-output-tokens>', '--source', '<pricing-page-url>'] } },+ want: { error: 'no_pricing', code: 'no_pricing', fixArgv: ['gbrain', 'pricing', 'set', 'example:unpriced-model-x', '--input', '<usd-per-1M-input-tokens>', '--output', '<usd-per-1M-output-tokens>', '--source', '<pricing-page-url>'] }, localPin: BRAIN_PIN },{ name: 'SourceTargetError', make: () => new SourceTargetError('Source "h3-no-such-source" not found or is archived. Available active sources: run `gbrain sources list` to see registered sources, or create/restore "h3-no-such-source" before retrying.'),- want: { error: 'unknown_source', code: 'unknown_source', fixArgv: ['gbrain', 'sources', 'list', '--json'] } },+ want: { error: 'unknown_source', code: 'unknown_source', fixArgv: ['gbrain', 'sources', 'list', '--json'] }, localPin: BRAIN_PIN },{ name: 'unknown throw', make: () => new Error('boom opening /home/alice-example/.gbrain/brain.pglite (pid 4242) without OPENAI_API_KEY'),- want: { error: 'internal_error', code: 'internal_error', fixArgv: DOCTOR } },+ want: { error: 'internal_error', code: 'internal_error', fixArgv: DOCTOR }, localPin: BRAIN_PIN },];const OP = 'get_brain_identity';@@ -242,7 +248,7 @@ describe('every error family survives MCP, CLI human, CLI --json and the thin cltest(f.name, async () => {// (1a) shared dispatch on the stdio transport.const stdio = await withOpHandler(OP, throwing(f), () => dispatchToolCall(engineB, OP, {}, { remote: true, transport: 'stdio', sourceId: 'default' })) as ToolResultWire;- expectSurvives(envelopeOf(stdio), f.want, 'mcp stdio dispatch');+ expectSurvives(envelopeOf(stdio), f.want, 'mcp stdio dispatch', f.localPin);// (1b) production serve-http over real HTTP.const http = await withOpHandler(OP, throwing(f), () => callTool(serve.base, adminToken, OP));@@ -286,11 +292,13 @@ describe('every error family survives MCP, CLI human, CLI --json and the thin cldescribe('OperationError (REAL: a missing page) on every surface', () => {const want: Expect = { error: 'page_not_found', code: 'page_not_found', fixArgv: ['gbrain', 'get', MISSING, '--include-deleted'] };+ const localPin = ['--brain', 'host', '--source', 'default'];+ const httpPin = ['--source', 'default'];test('CLI human and --json', async () => {const json = await gbrain(homeA, ['get', MISSING, '--json']);expect(json.exitCode).toBe(1);- expectSurvives(json.json, want, 'cli --json');+ expectSurvives(json.json, want, 'cli --json', localPin);const human = await gbrain(homeA, ['get', MISSING]);expect(human.exitCode).toBe(1);expectHuman(human.stderr, json.json, want);@@ -298,10 +306,10 @@ describe('OperationError (REAL: a missing page) on every surface', () => {test('real stdio serve (SDK client) and serve-http', async () => {const env = await stdioSession(homeA, async c => envelopeOf(await stdioCall(c, 'get_page', { slug: MISSING })));- expectSurvives(env, want, 'stdio serve');+ expectSurvives(env, want, 'stdio serve', localPin);expect(env.fix.mcp).toEqual({ tool: 'get_page', arguments: { slug: MISSING, include_deleted: true } });const http = envelopeOf(await callTool(serve.base, adminToken, 'get_page', { slug: MISSING }));- expectSurvives(http, want, 'serve-http');+ expectSurvives(http, want, 'serve-http', httpPin);}, 120_000);test('real thin-client CLI against a real `gbrain serve --http` (human and --json)', async () => {@@ -330,7 +338,8 @@ describe('OperationError (REAL: a missing page) on every surface', () => {}));const json = await gbrain(homeC, ['get', MISSING, '--json']);expect(json.exitCode).toBe(1);- expectSurvives(json.json, want, 'thin client CLI --json');+ // The server's HTTP render pins the source; the thin client adds no routing of its own.+ expectSurvives(json.json, want, 'thin client CLI --json', httpPin);const human = await gbrain(homeC, ['get', MISSING]);expect(human.exitCode).toBe(1);expectHuman(human.stderr, json.json, want);@@ -347,7 +356,7 @@ describe('REAL CLI triggers for the other families', () => {const r = await gbrain(homeA, ['code-def', '--json']);expect(r.exitCode).toBe(2);expect(r.json.error).toMatchObject({ class: 'UsageError', code: 'code_def_requires_symbol' });- expect(r.json).toMatchObject({ code: 'code_def_requires_symbol', fix: { argv: ['gbrain', 'code-def', '--help'], next: 'run' }, contract_version: 1 });+ expect(r.json).toMatchObject({ code: 'code_def_requires_symbol', fix: { argv: ['gbrain', 'code-def', '--help', '--brain', 'host'], next: 'run' }, contract_version: 1 });}, 90_000);test('GBrainError: mounts add with an invalid engine → config_error (human and --json)', async () => {@@ -363,10 +372,13 @@ describe('REAL CLI triggers for the other families', () => {const want: Expect = { error: 'database_error', code: 'database_error', fixArgv: ['gbrain', 'db-repair'] };const env = { GBRAIN_DATABASE_URL: 'postgresql://h3:[email protected]:1/h3' };const json = await gbrain(homeA, ['get', MISSING, '--json'], env);- expectSurvives(json.json, want, 'cli --json');+ expectSurvives(json.json, want, 'cli --json', BRAIN_PIN);expect(json.json.suggestion).toContain('GBRAIN_DB_ACCESS');expect(json.stdout).not.toContain('h3-secret');- expectHuman((await gbrain(homeA, ['get', MISSING], env)).stderr, json.json, want);+ // Human output is the golden-pinned GBRAIN_DB_ACCESS seam (`… Run: gbrain db-repair`), not the rendered fix line.+ const humanErr = (await gbrain(homeA, ['get', MISSING], env)).stderr;+ expect(humanErr).toContain('Error [database_error]: ');+ expect(humanErr).toContain('Run: gbrain db-repair');}, 90_000);test('F0 refresh refusal: the legacy refusal keys stay and the v1 siblings ride beside them (human and --json)', async () => {@@ -407,12 +419,12 @@ describe('REAL CLI triggers for the other families', () => {const env = { GBRAIN_SOURCE: 'h3-no-such-source' };const json = await gbrain(homeA, ['import', dir, '--no-embed', '--json'], env);expect(json.exitCode).not.toBe(0);- expectSurvives(json.json, want, 'cli --json');+ expectSurvives(json.json, want, 'cli --json', BRAIN_PIN);expect(json.json.class).toBe('caller');expect(json.json.suggestion).not.toContain('Server-side failure');expectHuman((await gbrain(homeA, ['import', dir, '--no-embed'], env)).stderr, json.json, want);const malformed = await gbrain(homeA, ['import', dir, '--no-embed', '--json'], { GBRAIN_SOURCE: 'Not A Source' });- expectSurvives(malformed.json, { ...want, error: 'invalid_source', code: 'invalid_source' }, 'cli --json (malformed id)');+ expectSurvives(malformed.json, { ...want, error: 'invalid_source', code: 'invalid_source' }, 'cli --json (malformed id)', BRAIN_PIN);}, 120_000);test('--brain naming no mount: a suggestion and a mounts-list fix (human and --json)', async () => {@@ -436,7 +448,7 @@ describe('withRelationGuard (REAL: the job table is gone)', () => {const call = await gbrain(homeA, ['call', 'get_job_stats', '{}']);expect(call.exitCode).toBe(1);- expectSurvives(call.json, want, 'gbrain call');+ expectSurvives(call.json, want, 'gbrain call', BRAIN_PIN);expect(call.json.message).toContain('a required table is missing');// The suggestion is rendered from the fix: it quotes the fix command and names no other one.expect(call.json.suggestion).toContain(call.json.fix.command);@@ -445,7 +457,7 @@ describe('withRelationGuard (REAL: the job table is gone)', () => {expect(call.stderr).toContain('Error [unavailable]');const stdio = await stdioSession(homeA, async c => envelopeOf(await stdioCall(c, 'get_job_stats', {})));- expectSurvives(stdio, want, 'stdio serve');+ expectSurvives(stdio, want, 'stdio serve', BRAIN_PIN);await drop(engineB);const http = envelopeOf(await callTool(serve.base, adminToken, 'get_job_stats', {}));diff --git a/test/agent-journey-upgrade.serial.test.ts b/test/agent-journey-upgrade.serial.test.tsindex 0171aa4549..5eca0b99be 100644--- a/test/agent-journey-upgrade.serial.test.ts+++ b/test/agent-journey-upgrade.serial.test.ts@@ -179,7 +179,7 @@ describe('(1) existing scripts after the upgrade', () => {const err = (await run(h, ['call', 'get_page', JSON.stringify({ slug: 'no-such-page' })])).json as Record<string, any>;expect(err).toMatchObject({ error: 'page_not_found', code: 'page_not_found' });expect(typeof err.suggestion).toBe('string');- expect(err.fix?.argv).toEqual(['gbrain', 'get', 'no-such-page', '--include-deleted']);+ expect(err.fix?.argv).toEqual(['gbrain', 'get', 'no-such-page', '--include-deleted', '--brain', 'host', '--source', 'default']);}, 120_000);});diff --git a/test/agent-recovery-consent-journeys.serial.test.ts b/test/agent-recovery-consent-journeys.serial.test.tsindex 05c45d1db8..98a439dff9 100644--- a/test/agent-recovery-consent-journeys.serial.test.ts+++ b/test/agent-recovery-consent-journeys.serial.test.ts@@ -142,7 +142,7 @@ describe('submit_job recovers through the job list, never a resubmit', () => {expect(await jobCount('lint')).toBe(1);expect(env).toMatchObject({ code: 'internal_error', retryable: false });expect(env.suggestion).toContain('inspect state before resubmitting');- expect(env.fix).toMatchObject({ argv: ['gbrain', 'jobs', 'list', '--json'], next: 'run' });+ expect(env.fix).toMatchObject({ argv: ['gbrain', 'jobs', 'list', '--json', '--brain', 'host'], next: 'run' });// Following it: the queued job is visible, so nothing is resubmitted.const listed = await dispatchToolCall(engine, 'list_jobs', {}, { remote: false, sourceId: 'default' }) as ToolResultWire;expect(JSON.parse(listed.content[0]!.text).map((j: { name: string }) => j.name)).toContain('lint');@@ -275,7 +275,7 @@ describe('real CLI: interactivity and approval binding', () => {const before = await dates();const r = await gbrain(approved.fix.argv.slice(1));expect(r.exitCode).not.toBe(0);- expect(r.json).toMatchObject({ code: 'preview_changed', fix: { argv: ['gbrain', 'reindex-frontmatter', '--force', '--dry-run', '--json'], next: 'run' } });+ expect(r.json).toMatchObject({ code: 'preview_changed', fix: { argv: ['gbrain', 'reindex-frontmatter', '--force', '--dry-run', '--json', '--brain', 'host'], next: 'run' } });expect(r.json.message).toContain(approved.plan_hash);expect(await dates()).toBe(before);// The preview the fix names is read-only and shows the plan to ask about next.@@ -286,7 +286,8 @@ describe('real CLI: interactivity and approval binding', () => {};const first = await ask();- expect(first.fix.argv.slice(-3)).toEqual(['--yes', '--expect', first.plan_hash]);+ // The approved command binds the plan (`--yes --expect <hash>`) and, per A1, names the brain.+ expect(first.fix.argv.slice(-5)).toEqual(['--yes', '--expect', first.plan_hash, '--brain', 'host']);// A record the user approved changed (its stored date moved) → re-ask.await sql("UPDATE pages SET effective_date = '1999-01-01', effective_date_source = 'fallback' WHERE slug = 'idea'");diff --git a/test/cli-error-render.serial.test.ts b/test/cli-error-render.serial.test.tsindex 557367c82b..c9b93c0dc7 100644--- a/test/cli-error-render.serial.test.ts+++ b/test/cli-error-render.serial.test.ts@@ -40,7 +40,7 @@ describe('D1 CLI error rendering', () => {const doc = JSON.parse(r.stdout);expect(doc).toMatchObject({ status: 'error', reason: 'invalid_flag', error: 'unknown_flag', code: 'unknown_flag', contract_version: 1 });expect(doc.suggestion).toContain('--limit');- expect(doc.fix).toMatchObject({ argv: ['gbrain', 'search', '--help'], next: 'run' });+ expect(doc.fix).toMatchObject({ argv: ['gbrain', 'search', '--help', '--brain', 'host'], next: 'run' });expect(r.stderr).toContain("unknown flag --limitt for 'gbrain search'");});diff --git a/test/cli-json-commands.serial.test.ts b/test/cli-json-commands.serial.test.tsindex 3b439645c1..d25ddeb8b2 100644--- a/test/cli-json-commands.serial.test.ts+++ b/test/cli-json-commands.serial.test.ts@@ -133,7 +133,7 @@ describe('db-repair --json', () => {expect(r.exitCode).toBe(1);const env = onlyDocument(r);expectEnvelope(env, 'database_error');- expect(env).toMatchObject({ schema_version: 1, reason: 'conn_refused', tier: 'auto', fixed: false, fix: { argv: ['gbrain', 'db-repair', '--yes'] } });+ expect(env).toMatchObject({ schema_version: 1, reason: 'conn_refused', tier: 'auto', fixed: false, fix: { argv: ['gbrain', 'db-repair', '--yes', '--brain', 'host'] } });}, 60_000);test('a PGLite brain: config_error naming pglite-repair; a bad flag combination: invalid_params (exit 2)', async () => {diff --git a/test/e2e/agent-journey-postgres.test.ts b/test/e2e/agent-journey-postgres.test.tsindex 6802d24931..1ecc3a91a8 100644--- a/test/e2e/agent-journey-postgres.test.ts+++ b/test/e2e/agent-journey-postgres.test.ts@@ -326,7 +326,8 @@ describeE2E('H4: Postgres serve readiness keeps the degraded-serve path', () =>const down = expectOneBlockError(await call(s, 'recall', { query: MARKER }), 'recall on a missing database');expect(down).toMatchObject({ error: 'unavailable', code: 'unavailable', reason: 'db_missing', protocol_version: 1 });// A1 surface rule: a CLI-only fix over stdio is the user's to run on this machine (host_admin is HTTP's actor).- expect(down.fix).toMatchObject({ argv: ['gbrain', 'db-repair'], actor: 'user', next: 'tell_user_to_run' });+ // A1: the fix names the served brain explicitly.+ expect(down.fix).toMatchObject({ argv: ['gbrain', 'db-repair', '--brain', 'host'], actor: 'user', next: 'tell_user_to_run' });expect(JSON.stringify(down)).not.toContain(db.url);await db.sql.unsafe(`CREATE DATABASE ${db.name}`);diff --git a/test/e2e/v0_29-mcp-dispatch-pglite.test.ts b/test/e2e/v0_29-mcp-dispatch-pglite.test.tsindex 891d97b902..9b14c773b3 100644--- a/test/e2e/v0_29-mcp-dispatch-pglite.test.ts+++ b/test/e2e/v0_29-mcp-dispatch-pglite.test.ts@@ -132,7 +132,7 @@ describe('v0.29 E2E — dispatchToolCall for the three new ops', () => {// Agent contract v1 (F5): refused at dispatch with the exact CLI command.expect(err.code).toBe('trusted_local_only');expect(err.message.toLowerCase()).toContain('trusted local cli');- expect(err.fix.command).toBe('gbrain transcripts recent');+ expect(err.fix.command).toBe('gbrain transcripts recent --brain host --source default');});test('get_recent_transcripts is denied fail-closed (unknown_tool) when the transport marker is unset', async () => {diff --git a/test/explicit-read-admission-5081.test.ts b/test/explicit-read-admission-5081.test.tsindex ac3f868f12..ebe85517a8 100644--- a/test/explicit-read-admission-5081.test.ts+++ b/test/explicit-read-admission-5081.test.ts@@ -150,7 +150,8 @@ describe('#5081 — explicit reads from a GBRAIN_SOURCE-bound stdio connection',expect(['permission_denied', 'scope_denied']).toContain(body.error);expect(body.suggestion).toBe('This connection is bound to source work (GBRAIN_SOURCE). private is not federated; the brain owner can run '- + '`gbrain sources federate private` on the brain host, or start this connection without GBRAIN_SOURCE.',+ // A1: the quoted command is the rendered fix, so it names the brain.+ + '`gbrain sources federate private --brain host` on the brain host, or start this connection without GBRAIN_SOURCE.',);});}@@ -174,7 +175,7 @@ describe('#5081 — explicit reads from a GBRAIN_SOURCE-bound stdio connection',const { body } = await call(await bound(), 'search', { query: MARKER, source_id: 'iso' });expect(body.error).toBe('permission_denied');expect(body.suggestion).toContain('iso opted out of federation (federated: false)');- expect(body.suggestion).toContain('`gbrain sources federate iso`');+ expect(body.suggestion).toContain('`gbrain sources federate iso --brain host`');});test('unqualified reads stay scalar on the bound source', async () => {@@ -194,7 +195,7 @@ describe('#5081 — explicit reads from a GBRAIN_SOURCE-bound stdio connection',expect(isError).toBe(true);expect(body.suggestion).toBe('This connection is bound to source iso (GBRAIN_SOURCE). iso opted out of federation (federated: false), so it '- + 'reads no other source; the brain owner can run `gbrain sources federate iso` on the brain host, or start this '+ + 'reads no other source; the brain owner can run `gbrain sources federate iso --brain host` on the brain host, or start this '+ 'connection without GBRAIN_SOURCE.',);const own = await call(await bound('iso'), 'search', { query: MARKER, source_id: 'iso' });@@ -209,7 +210,7 @@ describe('#5081 — explicit reads from a GBRAIN_SOURCE-bound stdio connection',const { body } = await call(opts, 'search', { query: MARKER, source_id: 'private' });expect(body.suggestion).toBe('This connection is bound to source work (.gbrain-source). private is not federated; the brain owner can run '- + '`gbrain sources federate private` on the brain host, or start this connection outside the directory pinned by .gbrain-source.',+ + '`gbrain sources federate private --brain host` on the brain host, or start this connection outside the directory pinned by .gbrain-source.',);});});diff --git a/test/fixtures/goldens/cli/engine-free-db-down.json b/test/fixtures/goldens/cli/engine-free-db-down.jsonindex 4ed617ef43..baeeed2016 100644--- a/test/fixtures/goldens/cli/engine-free-db-down.json+++ b/test/fixtures/goldens/cli/engine-free-db-down.json@@ -143,9 +143,9 @@"stderr": [],"stderrFirstLine": null,"stdout": [- "{\"schema_version\":1,\"brain_id\":\"host\",\"reason\":\"conn_refused\",\"tier\":\"auto\",\"marker\":\"GBRAIN_DB_ACCESS conn_refused\",\"diagnosis\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"plan\":[\"bounded reconnect; if the server is down, start it and re-run\"],\"applied\":[],\"fixed\":false,\"remaining\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"error\":\"database_error\",\"code\":\"database_error\",\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"suggestion\":\"Apply the plan: gbrain db-repair --yes\",\"docs\":\"https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#database_error\",\"why\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"fix\":{\"argv\":[\"gbrain\",\"db-repair\",\"--yes\"],\"command\":\"gbrain db-repair --yes\",\"consent\":[],\"actor\":\"agent\",\"next\":\"run\",\"why\":\"Applies the auto tier the plan names (bounded retries, pending migrations, CREATE EXTENSION vector, starting gbrain's own docker container).\",\"requires_exclusive\":false},\"docs_cmd\":[\"gbrain\",\"errors\",\"database_error\"],\"class\":\"server\",\"retryable\":false,\"contract_version\":1}"+ "{\"schema_version\":1,\"brain_id\":\"host\",\"reason\":\"conn_refused\",\"tier\":\"auto\",\"marker\":\"GBRAIN_DB_ACCESS conn_refused\",\"diagnosis\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"plan\":[\"bounded reconnect; if the server is down, start it and re-run\"],\"applied\":[],\"fixed\":false,\"remaining\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"error\":\"database_error\",\"code\":\"database_error\",\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"suggestion\":\"Apply the plan: gbrain db-repair --yes --brain host\",\"docs\":\"https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#database_error\",\"why\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"fix\":{\"argv\":[\"gbrain\",\"db-repair\",\"--yes\",\"--brain\",\"host\"],\"command\":\"gbrain db-repair --yes --brain host\",\"consent\":[],\"actor\":\"agent\",\"next\":\"run\",\"why\":\"Applies the auto tier the plan names (bounded retries, pending migrations, CREATE EXTENSION vector, starting gbrain's own docker container).\",\"requires_exclusive\":false},\"docs_cmd\":[\"gbrain\",\"errors\",\"database_error\"],\"class\":\"server\",\"retryable\":false,\"contract_version\":1}"],- "stdoutFirstLine": "{\"schema_version\":1,\"brain_id\":\"host\",\"reason\":\"conn_refused\",\"tier\":\"auto\",\"marker\":\"GBRAIN_DB_ACCESS conn_refused\",\"diagnosis\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"plan\":[\"bounded reconnect; if the server is down, start it and re-run\"],\"applied\":[],\"fixed\":false,\"remaining\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"error\":\"database_error\",\"code\":\"database_error\",\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"suggestion\":\"Apply the plan: gbrain db-repair --yes\",\"docs\":\"https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#database_error\",\"why\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"fix\":{\"argv\":[\"gbrain\",\"db-repair\",\"--yes\"],\"command\":\"gbrain db-repair --yes\",\"consent\":[],\"actor\":\"agent\",\"next\":\"run\",\"why\":\"Applies the auto tier the plan names (bounded retries, pending migrations, CREATE EXTENSION vector, starting gbrain's own docker container).\",\"requires_exclusive\":false},\"docs_cmd\":[\"gbrain\",\"errors\",\"database_error\"],\"class\":\"server\",\"retryable\":false,\"contract_version\":1}",+ "stdoutFirstLine": "{\"schema_version\":1,\"brain_id\":\"host\",\"reason\":\"conn_refused\",\"tier\":\"auto\",\"marker\":\"GBRAIN_DB_ACCESS conn_refused\",\"diagnosis\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"plan\":[\"bounded reconnect; if the server is down, start it and re-run\"],\"applied\":[],\"fixed\":false,\"remaining\":{\"reason\":\"conn_refused\",\"transient\":true,\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"remediation\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"brainId\":\"host\"},\"error\":\"database_error\",\"code\":\"database_error\",\"message\":\"connect ECONNREFUSED <REDACTED:ipv4>:1\",\"suggestion\":\"Apply the plan: gbrain db-repair --yes --brain host\",\"docs\":\"https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#database_error\",\"why\":\"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port.\",\"fix\":{\"argv\":[\"gbrain\",\"db-repair\",\"--yes\",\"--brain\",\"host\"],\"command\":\"gbrain db-repair --yes --brain host\",\"consent\":[],\"actor\":\"agent\",\"next\":\"run\",\"why\":\"Applies the auto tier the plan names (bounded retries, pending migrations, CREATE EXTENSION vector, starting gbrain's own docker container).\",\"requires_exclusive\":false},\"docs_cmd\":[\"gbrain\",\"errors\",\"database_error\"],\"class\":\"server\",\"retryable\":false,\"contract_version\":1}","url": "config"},{diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.jsonindex bb08ec7e6c..7e6d2344ad 100644--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json@@ -247,7 +247,9 @@"doctor","--only","minions_migration",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."@@ -1112,9 +1114,11 @@"--source","default","--dir",- "<BACKUP_DIR>/default"+ "<BACKUP_DIR>/default",+ "--brain",+ "host"],- "command": "gbrain export --source default --dir '<BACKUP_DIR>/default'",+ "command": "gbrain export --source default --dir '<BACKUP_DIR>/default' --brain host","consent": [],"docs": "https://github.com/garrytan/gbrain/blob/master/docs/operations/backup-check.md","inputs": [@@ -1131,7 +1135,9 @@"doctor","--only","backup_coverage",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Writes a Markdown copy of 'default' (pages and facts) to a directory outside the brain so it survives losing the database."@@ -1465,9 +1471,11 @@"config","set","takes.bootstrap_enabled",- "true"+ "true",+ "--brain",+ "host"],- "command": "gbrain config set takes.bootstrap_enabled true",+ "command": "gbrain config set takes.bootstrap_enabled true --brain host","consent": ["paid"],@@ -1480,7 +1488,9 @@"doctor","--only","takes_count",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Takes (typed claims) are opt-in. Enabling the bootstrap lets maintenance extract them from existing pages with a chat model (about $5 on a typical brain), which feeds calibration."diff --git a/test/fixtures/goldens/doctor/json-pglite-fast.json b/test/fixtures/goldens/doctor/json-pglite-fast.jsonindex d175ebf0db..54c50700d9 100644--- a/test/fixtures/goldens/doctor/json-pglite-fast.json+++ b/test/fixtures/goldens/doctor/json-pglite-fast.json@@ -209,7 +209,9 @@"doctor","--only","minions_migration",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."@@ -314,9 +316,11 @@"argv": ["gbrain","doctor",- "--json"+ "--json",+ "--brain",+ "host"],- "command": "gbrain doctor --json",+ "command": "gbrain doctor --json --brain host","consent": [],"next": "run","requires_exclusive": false,@@ -326,7 +330,9 @@"doctor","--only","connection",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the database checks --fast skipped."@@ -348,9 +354,11 @@"argv": ["gbrain","doctor",- "--json"+ "--json",+ "--brain",+ "host"],- "command": "gbrain doctor --json",+ "command": "gbrain doctor --json --brain host","consent": [],"next": "run","requires_exclusive": false,@@ -360,7 +368,9 @@"doctor","--only","connection",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the database checks --fast skipped."diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.jsonindex e119c234e8..128e2db3c6 100644--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json@@ -250,7 +250,9 @@"doctor","--only","minions_migration",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."@@ -536,7 +538,9 @@"doctor","--only","embeddings",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Embeddings are off, so search is keyword-only, and no configured embedding key fits this brain. Once the key is set this turns on voyage:voyage-4 (1024d) for the PGLite brain at <home>/.gbrain/brain.pglite. Pages, facts and keyword search are kept; existing chunks and facts are queued for vectors, which `gbrain embed --stale` (or the next maintenance cycle) fills."@@ -583,7 +587,9 @@"doctor","--only","embeddings",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Embeddings are off, so search is keyword-only, and no configured embedding key fits this brain. Once the key is set this turns on voyage:voyage-4 (1024d) for the PGLite brain at <home>/.gbrain/brain.pglite. Pages, facts and keyword search are kept; existing chunks and facts are queued for vectors, which `gbrain embed --stale` (or the next maintenance cycle) fills."@@ -1196,9 +1202,11 @@"--source","default","--dir",- "<BACKUP_DIR>/default"+ "<BACKUP_DIR>/default",+ "--brain",+ "host"],- "command": "gbrain export --source default --dir '<BACKUP_DIR>/default'",+ "command": "gbrain export --source default --dir '<BACKUP_DIR>/default' --brain host","consent": [],"docs": "https://github.com/garrytan/gbrain/blob/master/docs/operations/backup-check.md","inputs": [@@ -1215,7 +1223,9 @@"doctor","--only","backup_coverage",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Writes a Markdown copy of 'default' (pages and facts) to a directory outside the brain so it survives losing the database."@@ -1546,7 +1556,9 @@"doctor","--only","embeddings",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Embeddings are off, so search is keyword-only, and no configured embedding key fits this brain. Once the key is set this turns on voyage:voyage-4 (1024d) for the PGLite brain at <home>/.gbrain/brain.pglite. Pages, facts and keyword search are kept; existing chunks and facts are queued for vectors, which `gbrain embed --stale` (or the next maintenance cycle) fills."@@ -1578,9 +1590,11 @@"config","set","takes.bootstrap_enabled",- "true"+ "true",+ "--brain",+ "host"],- "command": "gbrain config set takes.bootstrap_enabled true",+ "command": "gbrain config set takes.bootstrap_enabled true --brain host","consent": ["paid"],@@ -1593,7 +1607,9 @@"doctor","--only","takes_count",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Takes (typed claims) are opt-in. Enabling the bootstrap lets maintenance extract them from existing pages with a chat model (about $5 on a typical brain), which feeds calibration."diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.jsonindex 28c29e0208..f91335cdd0 100644--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json@@ -237,7 +237,9 @@"doctor","--only","minions_migration",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."@@ -527,7 +529,9 @@"doctor","--only","embeddings",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Embeddings are off, so search is keyword-only, and no configured embedding key fits this brain. Once the key is set this turns on voyage:voyage-4 (1024d) for this Postgres brain. Pages, facts and keyword search are kept; existing chunks and facts are queued for vectors, which `gbrain embed --stale` (or the next maintenance cycle) fills."@@ -572,7 +576,9 @@"doctor","--only","embeddings",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Embeddings are off, so search is keyword-only, and no configured embedding key fits this brain. Once the key is set this turns on voyage:voyage-4 (1024d) for this Postgres brain. Pages, facts and keyword search are kept; existing chunks and facts are queued for vectors, which `gbrain embed --stale` (or the next maintenance cycle) fills."@@ -1188,9 +1194,11 @@"--source","default","--dir",- "<BACKUP_DIR>/default"+ "<BACKUP_DIR>/default",+ "--brain",+ "host"],- "command": "gbrain export --source default --dir '<BACKUP_DIR>/default'",+ "command": "gbrain export --source default --dir '<BACKUP_DIR>/default' --brain host","consent": [],"docs": "https://github.com/garrytan/gbrain/blob/master/docs/operations/backup-check.md","inputs": [@@ -1207,7 +1215,9 @@"doctor","--only","backup_coverage",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Writes a Markdown copy of 'default' (pages and facts) to a directory outside the brain so it survives losing the database."@@ -1536,7 +1546,9 @@"doctor","--only","embeddings",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Embeddings are off, so search is keyword-only, and no configured embedding key fits this brain. Once the key is set this turns on voyage:voyage-4 (1024d) for this Postgres brain. Pages, facts and keyword search are kept; existing chunks and facts are queued for vectors, which `gbrain embed --stale` (or the next maintenance cycle) fills."@@ -1568,9 +1580,11 @@"config","set","takes.bootstrap_enabled",- "true"+ "true",+ "--brain",+ "host"],- "command": "gbrain config set takes.bootstrap_enabled true",+ "command": "gbrain config set takes.bootstrap_enabled true --brain host","consent": ["paid"],@@ -1583,7 +1597,9 @@"doctor","--only","takes_count",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Takes (typed claims) are opt-in. Enabling the bootstrap lets maintenance extract them from existing pages with a chat model (about $5 on a typical brain), which feeds calibration."diff --git a/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json b/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.jsonindex 46e30b525a..d06d8ea0ec 100644--- a/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json+++ b/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json@@ -268,9 +268,11 @@"argv": ["gbrain","doctor",- "--json"+ "--json",+ "--brain",+ "host"],- "command": "gbrain doctor --json",+ "command": "gbrain doctor --json --brain host","consent": [],"next": "run","requires_exclusive": false,@@ -280,7 +282,9 @@"doctor","--only","connection",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the database checks --fast skipped."@@ -302,9 +306,11 @@"argv": ["gbrain","doctor",- "--json"+ "--json",+ "--brain",+ "host"],- "command": "gbrain doctor --json",+ "command": "gbrain doctor --json --brain host","consent": [],"next": "run","requires_exclusive": false,@@ -314,7 +320,9 @@"doctor","--only","connection",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Runs the database checks --fast skipped."diff --git a/test/fixtures/goldens/doctor/json-postgres-unreachable.json b/test/fixtures/goldens/doctor/json-postgres-unreachable.jsonindex 214cd3e070..348229e0b3 100644--- a/test/fixtures/goldens/doctor/json-postgres-unreachable.json+++ b/test/fixtures/goldens/doctor/json-postgres-unreachable.json@@ -272,9 +272,11 @@"actor": "agent","argv": ["gbrain",- "db-repair"+ "db-repair",+ "--brain",+ "host"],- "command": "gbrain db-repair",+ "command": "gbrain db-repair --brain host","consent": [],"docs": "https://github.com/garrytan/gbrain/blob/master/docs/ENGINES.md#engine-detection-and-access-repair","next": "run",@@ -285,7 +287,9 @@"doctor","--only","connection",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port. `gbrain db-repair` diagnoses the database URL and access without changing anything (it prints the --yes command for a safe fix)."@@ -306,9 +310,11 @@"actor": "agent","argv": ["gbrain",- "db-repair"+ "db-repair",+ "--brain",+ "host"],- "command": "gbrain db-repair",+ "command": "gbrain db-repair --brain host","consent": [],"docs": "https://github.com/garrytan/gbrain/blob/master/docs/ENGINES.md#engine-detection-and-access-repair","next": "run",@@ -319,7 +325,9 @@"doctor","--only","connection",- "--json"+ "--json",+ "--brain",+ "host"]},"why": "Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port. `gbrain db-repair` diagnoses the database URL and access without changing anything (it prints the --yes command for a safe fix)."diff --git a/test/get-job-stats-op.test.ts b/test/get-job-stats-op.test.tsindex 0492faa9fe..215506b3a6 100644--- a/test/get-job-stats-op.test.ts+++ b/test/get-job-stats-op.test.ts@@ -69,7 +69,14 @@ describe('get_job_stats op', () => {expect(res.isError).toBe(true);const body = parsed(res);expect(body.error).toBe('unavailable');- expect(body.suggestion).toContain('apply-migrations');+ expect(body.reason).toBe('schema_missing');+ expect(body.message).not.toContain('relation "minion_jobs"');+ // The cause (pending migrations or a dropped table) is not knowable here: the fix is the diagnostic+ // doctor read, and the suggestion quotes it instead of naming a different command.+ expect(body.suggestion).toContain('pending schema migrations');+ expect(body.fix.mcp).toEqual({ tool: 'run_doctor', arguments: {} });+ expect(body.suggestion).toContain('Next: run_doctor {}');+ expect(body.suggestion).not.toContain('apply-migrations');});});diff --git a/test/persistence-migration-preservation.test.ts b/test/persistence-migration-preservation.test.tsindex 4e48ec3fdf..15c53a00e8 100644--- a/test/persistence-migration-preservation.test.ts+++ b/test/persistence-migration-preservation.test.ts@@ -74,6 +74,7 @@ test('withdrawals, ownership and compacted cancelled IDs refuse legacy engine miexpect(await compactWriteReceipts(engine)).toBe(1);await expect(assertLegacyEngineMigration(engine)).rejects.toMatchObject({ code: 'writer_coordinator_required' });// Must reject before parsing the target or touching its datastore/config.- await expect(runMigrateEngine(engine, [])).rejects.toMatchObject({ code: 'writer_coordinator_required' });+ // A well-formed invocation (usage mistakes exit 2 before any state check) is still refused on a managed brain.+ await expect(runMigrateEngine(engine, ['--to', 'pglite'])).rejects.toMatchObject({ code: 'writer_coordinator_required' });}});diff --git a/test/thin-client-contract-skew.test.ts b/test/thin-client-contract-skew.test.tsindex 7356d9235a..5876e1ab1e 100644--- a/test/thin-client-contract-skew.test.ts+++ b/test/thin-client-contract-skew.test.ts@@ -49,7 +49,7 @@ describe('new client', () => {const json = new RemoteMcpError('tool_error', 'x', d).toJSON() as Record<string, unknown>;expect(json).toMatchObject({ error: 'unavailable', code: 'unavailable', reason: 'embeddings_disabled', contract_version: 1 });expect(json.notices).toHaveLength(1);- expect(json.fix).toMatchObject({ command: 'gbrain doctor --json' });+ expect(json.fix).toMatchObject({ command: 'gbrain doctor --json --brain host' });});test('× new server: frozen error value and canonical code both survive', () => {@@ -77,7 +77,7 @@ describe('new client', () => {expect(unpackToolResult<unknown[]>(res)).toEqual([]);expect(extractNotices(res)[0]).toMatchObject({ code: 'empty_retrieval', kind: 'info' });const noMeta = { content: res.content };- expect(extractNotices(noMeta)[0]).toMatchObject({ code: 'empty_retrieval', kind: 'info', fix: 'gbrain doctor --json' });+ expect(extractNotices(noMeta)[0]).toMatchObject({ code: 'empty_retrieval', kind: 'info', fix: 'gbrain doctor --json --brain host' });expect(extractNotices(golden('object-result.json')).length).toBe(0);});});