Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(security): bootstrap and harness capture lanes and the plugin hook start gbrain through a launcher; hook git probes skip core.fsmonitor behind the receipt gate (#8428, #8427)

garrytan9cd878428c60
diff --git a/src/commands/bootstrap.ts b/src/commands/bootstrap.ts
index 5b15dbf651..d4df8df890 100644
--- a/src/commands/bootstrap.ts
+++ b/src/commands/bootstrap.ts
@@ -1572,7 +1572,7 @@ async function runHooks(
try {
r = cloudCarrier
? writeCommittedClaudeHooks(ws, { env: hookEnv })
- : writeClaudeHooks(ws, { gbrainBin, env: hookEnv });
+ : writeClaudeHooks(ws, { gbrainBin, hookLauncher: ensureHookLauncher(hookLauncherPath()), env: hookEnv });
} catch (e) {
// Fail-closed on an unparseable settings file (either carrier): MCP
// (step 1) still landed; record that, surface the fix, and exit
@@ -1609,7 +1609,12 @@ async function runHooks(
// command carries NO GBRAIN_SOURCE — hooks.json is machine-global, a
// baked source would stamp every codex session on this machine with
// this repo's source; session-end resolves from the payload instead.
- const r = writeCodexHooks({ gbrainBin });
+ let r: ReturnType<typeof writeCodexHooks>;
+ try {
+ r = writeCodexHooks({ gbrainBin, hookLauncher: ensureHookLauncher(hookLauncherPath()) });
+ } catch (e) {
+ r = { ok: false, hooksPath: '', configPath: '', notes: [(e as Error).message] };
+ }
if (r.ok) {
hooksWritten = true;
console.log(
diff --git a/src/commands/hook.ts b/src/commands/hook.ts
index 316330f46e..66a35743dd 100644
--- a/src/commands/hook.ts
+++ b/src/commands/hook.ts
@@ -738,7 +738,8 @@ function tryExecAsync(bin: string, args: string[], timeoutMs = HOOK_GIT_TIMEOUT_
try {
execFile(
bin,
- args,
+ // #8427: a checkout's .git/config core.fsmonitor names a command that `git status` runs; a hook probe never runs it.
+ bin === 'git' ? ['-c', 'core.fsmonitor=false', ...args] : args,
{ timeout: timeoutMs, maxBuffer: 4 * 1024 * 1024, env: gitChildEnv() },
(err, stdout) => resolve(err ? null : stdout.toString().trim()),
);
@@ -750,13 +751,26 @@ function tryExecAsync(bin: string, args: string[], timeoutMs = HOOK_GIT_TIMEOUT_
/**
* Resolve the bootstrap workspace root for a hook event: the git toplevel of
- * `ws`, gated on an `initialized` agent.json manifest at that root. The gate
+ * `ws`, which must be the install receipt's workspace_dir (checked before any
+ * git runs, #8427) and hold an `initialized` agent.json manifest. The gate
* is the security boundary — `gbrain hook <event>` run in an arbitrary repo
* must never commit or push it. Shared by session-start and session-end.
*/
async function resolveBootstrapWorkspaceRoot(ws: string): Promise<string | null> {
+ // #8427: the install receipt names the one workspace gbrain bootstrapped. A session anywhere else runs no git at all,
+ // since the checkout itself can supply an initialized agent.json and a .git/config whose settings git would act on.
+ let workspace: string;
+ try {
+ const receipt = readReceipt(resolveGbrainHome());
+ if (!receipt?.workspace_dir) return null;
+ workspace = realpathOrResolve(receipt.workspace_dir);
+ } catch {
+ return null;
+ }
+ const at = realpathOrResolve(ws);
+ if (at !== workspace && !at.startsWith(workspace.endsWith('/') ? workspace : `${workspace}/`)) return null;
const root = await tryExecAsync('git', ['-C', ws, 'rev-parse', '--show-toplevel']);
- if (!root) return null;
+ if (!root || realpathOrResolve(root) !== workspace) return null;
const manifest = readManifest(root);
if (manifest.state !== 'initialized') return null; // not a bootstrap workspace
return root;
diff --git a/src/core/bootstrap/codex-hooks.ts b/src/core/bootstrap/codex-hooks.ts
index c0e2b7fc16..260bfc2785 100644
--- a/src/core/bootstrap/codex-hooks.ts
+++ b/src/core/bootstrap/codex-hooks.ts
@@ -188,6 +188,8 @@ export interface WriteCodexHooksResult {
*/
export function writeCodexHooks(opts: {
gbrainBin: string;
+ /** The trusted-directory launcher the capture starts gbrain through (src/core/setup/hook-launcher.ts), never the session's directory (#8428). */
+ hookLauncher?: string;
hooksPath?: string;
configPath?: string;
}): WriteCodexHooksResult {
@@ -209,7 +211,7 @@ export function writeCodexHooks(opts: {
}
const hooks = (doc.hooks && typeof doc.hooks === 'object' && !Array.isArray(doc.hooks) ? doc.hooks : {}) as NonNullable<HooksJson['hooks']>;
const sessionEnd = Array.isArray(hooks[SESSION_END_EVENT]) ? hooks[SESSION_END_EVENT]! : [];
- const command = buildCodexSessionEndCommand(opts.gbrainBin);
+ const command = buildCodexSessionEndCommand(opts.gbrainBin, opts.hookLauncher);
const ourGroup = { hooks: [{ type: 'command', command, timeout: SESSION_END_TIMEOUT_SEC }] };
// Fresh install appends LAST; a re-run replaces our group IN PLACE — a
// strip-then-append would shift every foreign group sitting after ours
diff --git a/src/core/bootstrap/harness.ts b/src/core/bootstrap/harness.ts
index 6a72b4bbf3..c4361cf2a7 100644
--- a/src/core/bootstrap/harness.ts
+++ b/src/core/bootstrap/harness.ts
@@ -93,6 +93,7 @@ import {
} from './format.ts';
import { atomicWriteTextFile } from './atomic-write.ts';
import { removeCodexHooks, writeCodexHooks } from './codex-hooks.ts';
+import { ensureHookLauncher, hookLauncherPath } from '../setup/hook-launcher.ts';
import {
removeCodexHttpServerBlock,
writeCodexHttpServerBlock,
@@ -1456,6 +1457,7 @@ export async function applyHarness(flags: HarnessFlags, rawDeps: HarnessDeps): P
}
const r = writeClaudeHooksAt(settingsPath, {
gbrainBin: bin,
+ hookLauncher: ensureHookLauncher(hookLauncherPath()),
env,
events: hookEvents,
marker: GBRAIN_HARNESS_MARKER_VALUE,
@@ -1581,7 +1583,7 @@ export async function applyHarness(flags: HarnessFlags, rawDeps: HarnessDeps): P
} else {
// Paths derive from THIS TARGET's config.toml (CODEX_HOME-resolved
// upstream, test-injectable) — never the ambient global default.
- const hr = writeCodexHooks({ gbrainBin: hooksBin, configPath: t.path!, hooksPath: join(dirname(t.path!), 'hooks.json') });
+ const hr = writeCodexHooks({ gbrainBin: hooksBin, hookLauncher: ensureHookLauncher(hookLauncherPath()), configPath: t.path!, hooksPath: join(dirname(t.path!), 'hooks.json') });
if (hr.ok) d.log(`Codex SessionEnd hook wired: ${hr.hooksPath} + trust entry in ${hr.configPath}.`);
else for (const note of hr.notes) d.logError(note);
}
diff --git a/src/core/bootstrap/hooks.ts b/src/core/bootstrap/hooks.ts
index 34a479edb9..ad1c6a9974 100644
--- a/src/core/bootstrap/hooks.ts
+++ b/src/core/bootstrap/hooks.ts
@@ -31,6 +31,7 @@ import { atomicWriteTextFile } from './atomic-write.ts';
import { normalizeSeatLabel } from '../context/seat.ts';
import { detectExecutionEnvironment } from '../execution-env.ts';
import { stdioServeArgv } from '../mcp-registration.ts';
+import { isHookLauncherPath } from '../setup/hook-launcher.ts';
import type { McpSurface } from '../../mcp/surface.ts';
import type { HarnessReceipt, HarnessTarget } from './format.ts';
import {
@@ -303,7 +304,7 @@ export function classifyHarnessHook(
const sub = (CLAUDE_HOOK_SUBCOMMAND as Record<string, string | undefined>)[event];
if (!sub || !/(?:^|[\s'])GBRAIN_HOOK_LANE=harness(?=[\s']|$)/.test(e.command) || !/\shook(?:\s|$)/.test(e.command)) return null;
const parsed = parseClaudeHookCommand(e.command);
- if (!parsed || parsed.launcher !== undefined || parsed.env.GBRAIN_HOOK_LANE !== 'harness' || parsed.subcommand !== sub) {
+ if (!parsed || (parsed.launcher !== undefined && !isHookLauncherPath(parsed.launcher)) || parsed.env.GBRAIN_HOOK_LANE !== 'harness' || parsed.subcommand !== sub) {
return { ownership: 'unowned', why: `not the exact \`hook ${sub}\` command gbrain writes (edited or extended)` };
}
if (identity === 'any') return { ownership: 'command', why: 'harness hook command shape' };
diff --git a/src/core/setup/hook-launcher.ts b/src/core/setup/hook-launcher.ts
index b5259d60ed..f087a0e41b 100644
--- a/src/core/setup/hook-launcher.ts
+++ b/src/core/setup/hook-launcher.ts
@@ -131,10 +131,14 @@ export function shellWords(command: string): string[] | null {
return words;
}
+/** An absolute path shaped like a hook launcher (<config dir>/hook-launcher/gbrain-hook). */
+export function isHookLauncherPath(path: string): boolean {
+ return path.startsWith('/') && path.endsWith(`/${HOOK_LAUNCHER_DIR}/${HOOK_LAUNCHER_NAME}`);
+}
+
/** The launcher a hook command runs gbrain through, or null for a command that starts gbrain in the session directory. */
export function hookLauncherInCommand(command: string): string | null {
- const suffix = `/${HOOK_LAUNCHER_DIR}/${HOOK_LAUNCHER_NAME}`;
- return shellWords(command)?.find((w) => w.startsWith('/') && w.endsWith(suffix)) ?? null;
+ return shellWords(command)?.find(isHookLauncherPath) ?? null;
}
export { HOOK_CWD_ENV, captureHookSessionCwd, hookSessionCwd } from '../session-cwd.ts';
diff --git a/test/hook-command.serial.test.ts b/test/hook-command.serial.test.ts
index 4e74354a53..5bdb1e4793 100644
--- a/test/hook-command.serial.test.ts
+++ b/test/hook-command.serial.test.ts
@@ -1197,6 +1197,23 @@ function markRepoPhaseComplete(repo: string): void {
} as RepoReceipt);
}
+/** #8427: the bootstrap install receipt names this workspace, as bootstrap writes it when it wires the hooks, before any repo phase. */
+function markBootstrapped(repo: string): void {
+ const toplevel = execFileSync('git', ['-C', repo, 'rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim();
+ mkdirSync(join(home(), 'bootstrap'), { recursive: true });
+ writeReceipt(home(), {
+ receipt_version: 1,
+ workspace_dir: toplevel,
+ source_id: 'workspace',
+ agent_name: 'test-agent',
+ created_at: '2026-01-01T00:00:00.000Z',
+ created_by: 'test',
+ brain_created_by_bootstrap: false,
+ created_paths: [],
+ registrations: [],
+ } as RepoReceipt);
+}
+
describe('bootstrap push gate [G4]', () => {
test('git repo + dirty tree + NO agent.json: session-start and session-end never spawn a push, repo untouched', async () => {
const repo = join(tmp, 'plain-repo');
@@ -1291,6 +1308,7 @@ describe('bootstrap push gate [G4]', () => {
initGitRepoWithDirtyTree(repo);
writeFileSync(join(repo, 'agent.json'), JSON.stringify(INITIALIZED_MANIFEST, null, 2) + '\n');
// NB: no markRepoPhaseComplete — the repo phase has not run yet.
+ markBootstrapped(repo);
const spawned: string[] = [];
const out = collectStdout();
await runHook(['session-start'], {
@@ -1307,6 +1325,7 @@ describe('bootstrap push gate [G4]', () => {
const repo = join(tmp, 'boot-repo-pending-end');
initGitRepoWithDirtyTree(repo);
writeFileSync(join(repo, 'agent.json'), JSON.stringify(INITIALIZED_MANIFEST, null, 2) + '\n');
+ markBootstrapped(repo);
const spawned: string[] = [];
await runHook(['session-end'], {
write: () => {},
@@ -1337,6 +1356,7 @@ function bootRepo(name: string, opts: { repoPhase?: boolean; clean?: boolean } =
initGitRepoWithDirtyTree(repo);
writeFileSync(join(repo, 'agent.json'), JSON.stringify(INITIALIZED_MANIFEST, null, 2) + '\n');
if (opts.repoPhase !== false) markRepoPhaseComplete(repo);
+ else markBootstrapped(repo);
if (opts.clean) {
execFileSync('git', ['-C', repo, 'add', '-A'], { stdio: 'ignore' });
execFileSync('git', ['-C', repo, '-c', 'user.email=t@t', '-c', 'user.name=t', 'commit', '-qm', 'init'], { stdio: 'ignore' });
@@ -1516,8 +1536,9 @@ describe('stop-hook per-turn push [D3]', () => {
await runHook(['stop'], stopIo(a, spawned));
expect(spawned).toHaveLength(1);
await runHook(['stop'], stopIo(b, spawned));
- expect(spawned).toHaveLength(1); // b defers (no receipt binding) — and does NOT clobber a's state
- expect((await lastHeartbeat())?.reason).toBe('push_deferred_repo_pending');
+ expect(spawned).toHaveLength(1); // b is not the receipt's workspace — and does NOT clobber a's state
+ // #8427: a workspace the receipt does not name is not gbrain's, so no git runs there at all.
+ expect((await lastHeartbeat())?.reason).toBe('push_skipped_not_bootstrap');
await runHook(['stop'], stopIo(a, spawned));
expect(spawned).toHaveLength(1); // a still debounced — b's activity didn't reset a
expect((await lastHeartbeat())?.reason).toBe('push_debounced');
diff --git a/test/mcp-registration.test.ts b/test/mcp-registration.test.ts
index 49ad8c186f..04899e724b 100644
--- a/test/mcp-registration.test.ts
+++ b/test/mcp-registration.test.ts
@@ -15,6 +15,7 @@ import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { PLUGIN_SURFACE, REGISTRATION_ADVERTISE, REGISTRATION_SURFACE, registeredAdvertise, registeredSurface, registrationAdvertise, stdioServeArgv } from '../src/core/mcp-registration.ts';
import { harnessWiringEntry } from '../src/core/readiness.ts';
+import { hookLauncherPath } from '../src/core/setup/hook-launcher.ts';
import { registerClaudeMcp, registerCodexMcp } from '../src/core/bootstrap/hooks.ts';
import { resolveSurfaceWithSource } from '../src/mcp/surface.ts';
@@ -65,14 +66,16 @@ describe('REGISTRATION_SURFACE and stdioServeArgv', () => {
describe('every stdio registration path builds from REGISTRATION_SURFACE', () => {
test('readiness harness_wiring: Claude Code and Codex pin the surface; opencode runs bootstrap hooks', () => {
- expect(wiring('claude-code')?.argv).toEqual(['claude', 'mcp', 'add', 'gbrain', '--', ...stdioServeArgv(BIN, REGISTRATION_SURFACE, REGISTRATION_ADVERTISE)]);
- expect(wiring('codex')?.argv).toEqual(['codex', 'mcp', 'add', 'gbrain', '--', ...stdioServeArgv(BIN, REGISTRATION_SURFACE, REGISTRATION_ADVERTISE)]);
+ // #8426: Claude Code and Codex register through gbrain setup, which puts serve behind the hook launcher.
+ expect(wiring('claude-code')?.argv).toEqual(['gbrain', 'setup', 'claude-code', '--no-hooks', '--no-instructions', '--gbrain-bin', BIN]);
+ expect(wiring('codex')?.argv).toEqual(['gbrain', 'setup', 'codex', '--no-hooks', '--no-instructions', '--gbrain-bin', BIN]);
expect(wiring('opencode')?.argv).toEqual(['gbrain', 'bootstrap', 'hooks', '--harness', 'opencode', '--no-hooks']);
- expect(wiring('claude-code')?.why).toContain(`${BIN} serve --surface starter --advertise verbs`);
+ expect(wiring('claude-code')?.why).toContain(`${hookLauncherPath()} ${stdioServeArgv(BIN, REGISTRATION_SURFACE, REGISTRATION_ADVERTISE).join(' ')}`);
});
test('init --surface reaches the readiness fix (the quickstart line and the first-run harness decision read it)', () => {
- expect(wiring('claude-code', 'starter')?.argv).toEqual(['claude', 'mcp', 'add', 'gbrain', '--', BIN, 'serve', '--surface', 'starter']);
+ expect(wiring('claude-code', 'starter')?.argv).toEqual(['gbrain', 'setup', 'claude-code', '--no-hooks', '--no-instructions', '--gbrain-bin', BIN, '--surface', 'starter']);
+ expect(wiring('claude-code', 'starter')?.why).toContain(`${BIN} serve --surface starter`);
expect(wiring('opencode', 'verbs')?.argv).toEqual(['gbrain', 'bootstrap', 'hooks', '--harness', 'opencode', '--no-hooks', '--surface', 'verbs']);
const missing = harnessWiringEntry({ transport: 'cli', harnesses: [], lockOwner: null, gbrainBin: BIN }).fix;
expect(missing?.why).toContain('serve --surface starter --advertise verbs');
diff --git a/test/readiness.test.ts b/test/readiness.test.ts
index a79b21f25c..c430022619 100644
--- a/test/readiness.test.ts
+++ b/test/readiness.test.ts
@@ -168,13 +168,14 @@ describe('harness_wiring by state', () => {
const BIN = '/opt/gbrain/bin/gbrain';
const owner = (transport: 'stdio' | 'http', is_self = false): LockOwner => ({ pid: 4242, transport, is_self });
- test('one harness, no serve: harness-native stdio registration with the absolute binary, --surface starter and --advertise verbs', () => {
+ test('one harness, no serve: gbrain setup registers the absolute binary behind the hook launcher, --surface starter and --advertise verbs', () => {
const claude = harnessWiringEntry({ transport: 'cli', harnesses: ['claude-code'], lockOwner: null, gbrainBin: BIN });
- expect(claude.fix?.argv).toEqual(['claude', 'mcp', 'add', 'gbrain', '--', BIN, 'serve', '--surface', 'starter', '--advertise', 'verbs']);
+ expect(claude.fix?.argv).toEqual(['gbrain', 'setup', 'claude-code', '--no-hooks', '--no-instructions', '--gbrain-bin', BIN]);
+ expect(claude.fix?.why).toContain(`/hook-launcher/gbrain-hook ${BIN} serve --surface starter --advertise verbs`);
expect(claude.fix?.consent).toEqual(['persistent_install']);
expect(claude.fix?.why).toContain('~/.claude.json');
expect(harnessWiringEntry({ transport: 'cli', harnesses: ['codex'], lockOwner: null, gbrainBin: BIN }).fix?.argv)
- .toEqual(['codex', 'mcp', 'add', 'gbrain', '--', BIN, 'serve', '--surface', 'starter', '--advertise', 'verbs']);
+ .toEqual(['gbrain', 'setup', 'codex', '--no-hooks', '--no-instructions', '--gbrain-bin', BIN]);
expect(harnessWiringEntry({ transport: 'cli', harnesses: ['opencode'], lockOwner: null, gbrainBin: BIN }).fix?.argv)
.toEqual(['gbrain', 'bootstrap', 'hooks', '--harness', 'opencode', '--no-hooks']);
});
diff --git a/test/setup.test.ts b/test/setup.test.ts
index 3fa9f057a0..cf33c3f1d3 100644
--- a/test/setup.test.ts
+++ b/test/setup.test.ts
@@ -42,6 +42,8 @@ const roots: string[] = [];
afterAll(() => { for (const r of roots) rmSync(r, { recursive: true, force: true }); });
interface Box { root: string; home: string; gbrainHome: string; bin: string }
+/** The hook launcher setup registers serve behind (#8426). */
+const launcher = (b: Box) => join(b.gbrainHome, '.gbrain', 'hook-launcher', 'gbrain-hook');
function box(): Box {
const root = mkdtempSync(join(tmpdir(), 'gbrain-setup-'));
@@ -88,7 +90,7 @@ describe('gbrain setup claude-code: install lifecycle', () => {
expect(first.doc.consent.providers).toMatchObject({ value: 'declined', source: 'default' });
expect(readJson(join(b.gbrainHome, '.gbrain', 'config.json')).embedding_disabled).toBe(true);
const entry = readJson(claudeJson(b)).mcpServers.gbrain;
- expect(entry).toEqual({ type: 'stdio', command: b.bin, args: ['serve', '--surface', 'starter', '--advertise', 'verbs'], env: { GBRAIN_HOME: b.gbrainHome } });
+ expect(entry).toEqual({ type: 'stdio', command: launcher(b), args: [b.bin, 'serve', '--surface', 'starter', '--advertise', 'verbs'], env: { GBRAIN_HOME: b.gbrainHome } });
expect(Object.keys(readJson(settings(b)).hooks).sort()).toEqual(['SessionStart', 'UserPromptSubmit']);
expect(readJson(receipt(b)).status).toBe('installed');
const [bundle] = first.doc.notices;
@@ -107,10 +109,10 @@ describe('gbrain setup claude-code: install lifecycle', () => {
test('starter is the default surface; --surface full is the opt-in, and a re-run keeps the surface already registered', async () => {
const b = box();
expect((await setup(b, ['claude-code', '--surface', 'full', '--json'])).exitCode).toBe(0);
- expect(readJson(claudeJson(b)).mcpServers.gbrain.args).toEqual(['serve', '--surface', 'full']);
+ expect(readJson(claudeJson(b)).mcpServers.gbrain.args).toEqual([b.bin, 'serve', '--surface', 'full']);
const rerun = await setup(b, ['claude-code', '--json']);
expect(rerun.exitCode).toBe(0);
- expect(readJson(claudeJson(b)).mcpServers.gbrain.args).toEqual(['serve', '--surface', 'full']);
+ expect(readJson(claudeJson(b)).mcpServers.gbrain.args).toEqual([b.bin, 'serve', '--surface', 'full']);
expect(rerun.doc.steps.map((s: any) => s.action)).toEqual(['keep', 'keep', 'keep']);
});
@@ -239,7 +241,7 @@ describe('gbrain setup claude-code: install lifecycle', () => {
expect(readFileSync(claudeJson(b), 'utf8')).toBe(foreignCfg);
expect(existsSync(settings(b))).toBe(false);
- const same = { type: 'stdio', command: b.bin, args: ['serve', '--surface', 'starter'], env: { GBRAIN_HOME: b.gbrainHome } };
+ const same = { type: 'stdio', command: launcher(b), args: [b.bin, 'serve', '--surface', 'starter'], env: { GBRAIN_HOME: b.gbrainHome } };
writeFileSync(claudeJson(b), JSON.stringify({ mcpServers: { gbrain: same } }));
const adopted = await setup(b, ['claude-code', '--json']);
expect(adopted.exitCode).toBe(0);
@@ -326,7 +328,7 @@ describe('gbrain setup claude-code: target first', () => {
const first = await setup(b, ['claude-code', '--surface', 'full', '--json']);
expect(first.exitCode).toBe(0);
expect(first.doc.target.advertise).toBeUndefined();
- const listedFull = { type: 'stdio', command: b.bin, args: ['serve', '--surface', 'full'], env: { GBRAIN_HOME: b.gbrainHome } };
+ const listedFull = { type: 'stdio', command: launcher(b), args: [b.bin, 'serve', '--surface', 'full'], env: { GBRAIN_HOME: b.gbrainHome } };
expect(readJson(claudeJson(b)).mcpServers.gbrain).toEqual(listedFull);
const again = await setup(b, ['claude-code', '--json']);
expect(again.exitCode).toBe(0);
@@ -554,7 +556,7 @@ describe('gbrain setup codex: install lifecycle', () => {
expect(first.doc.capability).toMatchObject({ harness: 'codex', setup: 'supported', push: 'native-verified', read_events: ['SessionStart', 'UserPromptSubmit'] });
expect(first.doc.consent.capture).toMatchObject({ value: 'declined', source: 'default' });
expect(readJson(join(b.gbrainHome, '.gbrain', 'config.json')).embedding_disabled).toBe(true);
- expect(toml(b).mcp_servers.gbrain).toEqual({ command: b.bin, args: ['serve', '--surface', 'starter', '--advertise', 'verbs'], env: { GBRAIN_HOME: b.gbrainHome } });
+ expect(toml(b).mcp_servers.gbrain).toEqual({ command: launcher(b), args: [b.bin, 'serve', '--surface', 'starter', '--advertise', 'verbs'], env: { GBRAIN_HOME: b.gbrainHome } });
expect(Object.keys(readJson(hooksJson(b)).hooks).sort()).toEqual(['SessionStart', 'UserPromptSubmit']);
expect(groups(b, 'UserPromptSubmit')).toEqual([{ hooks: [{ type: 'command', timeout: 15,
command: `env GBRAIN_HOOK_LANE=setup GBRAIN_HOME=${b.gbrainHome} ${b.gbrainHome}/.gbrain/hook-launcher/gbrain-hook ${b.bin} hook user-prompt --harness codex` }] }]);
@@ -721,7 +723,7 @@ describe('gbrain setup codex: install lifecycle', () => {
expect(readFileSync(codexToml(b), 'utf8')).toBe(foreign);
expect(existsSync(hooksJson(b))).toBe(false);
- const same = `[mcp_servers.gbrain]\ncommand = ${JSON.stringify(b.bin)}\nargs = ["serve", "--surface", "starter"]\nenv = { GBRAIN_HOME = ${JSON.stringify(b.gbrainHome)} }\n`;
+ const same = `[mcp_servers.gbrain]\ncommand = ${JSON.stringify(launcher(b))}\nargs = [${JSON.stringify(b.bin)}, "serve", "--surface", "starter"]\nenv = { GBRAIN_HOME = ${JSON.stringify(b.gbrainHome)} }\n`;
writeFileSync(codexToml(b), same);
expect((await setup(b, ['codex'])).exitCode).toBe(0);
expect(readJson(codexReceipt(b)).mcp_adopted).toBe(true);