Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes (rerun pins the recorded --gbrain-bin; stress weights re-mined for the grown setup suite)

garrytanef19f632ef79
diff --git a/scripts/stress/iteration-weights.json b/scripts/stress/iteration-weights.json
index 6668a022fd..04b6cfc5dc 100644
--- a/scripts/stress/iteration-weights.json
+++ b/scripts/stress/iteration-weights.json
@@ -26,6 +26,8 @@
"test/belief-ledger-weekly-diff.test.ts": 83800,
"test/belief-ledger-weekly-probes.test.ts": 32000,
"test/bootstrap-harness-hook-ownership.test.ts": 100,
+ "test/bootstrap-harness.serial.test.ts": 1300,
+ "test/bootstrap-opencode-door.serial.test.ts": 2800,
"test/brainstorm/save.test.ts": 1800,
"test/capacity-bounded-read-6803.test.ts": 5700,
"test/capture-consent-admission.test.ts": 6700,
@@ -63,7 +65,7 @@
"test/doctor-day-zero.test.ts": 9250,
"test/doctor-early-stop-golden.serial.test.ts": 700,
"test/doctor-frontmatter-holds.test.ts": 12200,
- "test/doctor-harness-smoke.test.ts": 6200,
+ "test/doctor-harness-smoke.test.ts": 12350,
"test/doctor-hot-checks-golden.test.ts": 36550,
"test/doctor-image-embedding-coverage.test.ts": 2500,
"test/doctor-json-golden-latest.test.ts": 100,
@@ -219,7 +221,8 @@
"test/harness-wiring-redaction-6453.test.ts": 550,
"test/held-read-signals.test.ts": 5800,
"test/hold-action-chain-6712.test.ts": 15200,
- "test/hook-launcher-bunfig.test.ts": 1700,
+ "test/hook-command.serial.test.ts": 2300,
+ "test/hook-launcher-bunfig.test.ts": 2200,
"test/import-cancellation.serial.test.ts": 1350,
"test/import-file-result-callback-gbra130.test.ts": 4600,
"test/import-file.test.ts": 1850,
@@ -374,6 +377,7 @@
"test/large-pages/upload-over-ceiling.test.ts": 154600,
"test/large-pages/upload-review.test.ts": 7400,
"test/large-pages/v252-master-reader-compat.test.ts": 8600,
+ "test/launcher-lanes-bunfig.serial.test.ts": 19800,
"test/link-cross-source.test.ts": 6600,
"test/link-preparation-shared-index.test.ts": 8000,
"test/links-attendance-blocked.test.ts": 10400,
@@ -409,6 +413,7 @@
"test/managed-sync-row-parity.test.ts": 11500,
"test/managed-sync-stale-group-head.test.ts": 9000,
"test/managed-synthesis-postprocess.test.ts": 11250,
+ "test/mcp-registration.test.ts": 1050,
"test/mentions-policy-aliases.test.ts": 200,
"test/migrate.test.ts": 10400,
"test/migration-persistence-request-id-index.test.ts": 7400,
@@ -554,6 +559,7 @@
"test/persistence-image-import.serial.test.ts": 4900,
"test/persistence-import-batch.test.ts": 21400,
"test/persistence-index-lock-reclaim-6932.test.ts": 8750,
+ "test/persistence-local-client.test.ts": 800,
"test/persistence-managed-lifecycle.test.ts": 14300,
"test/persistence-managed-sync.test.ts": 188800,
"test/persistence-manifest-git-scope.test.ts": 8200,
@@ -584,6 +590,7 @@
"test/persistence-write-stall.test.ts": 4500,
"test/persistence-writer-fences.test.ts": 3900,
"test/physical-root-birth-tolerance-6501.test.ts": 7500,
+ "test/plugin-turn-hook.test.ts": 10500,
"test/postgres-driver-vendor-6930.test.ts": 100,
"test/postgres-engine-gauge-golden.test.ts": 300,
"test/postgres-rls-scope-inventory.test.ts": 500,
@@ -595,6 +602,7 @@
"test/purge-sync-tombstone-hold-7130.test.ts": 20900,
"test/read-meta-diag.test.ts": 2900,
"test/read-waves-gbra133.test.ts": 2200,
+ "test/readiness.test.ts": 200,
"test/recall-page-fill.test.ts": 14800,
"test/receipt-compaction-newest-sync-gbra130.test.ts": 7200,
"test/receipt-coverage.test.ts": 200,
@@ -639,7 +647,7 @@
"test/serve-http-run-teardown.serial.test.ts": 1400,
"test/serve-sync-handoff.serial.test.ts": 4100,
"test/setup-brain-first.test.ts": 62000,
- "test/setup.test.ts": 356500,
+ "test/setup.test.ts": 432400,
"test/shared-content-freshness.test.ts": 6900,
"test/shared-skills-catalog.test.ts": 17200,
"test/shared-skills-retention-capacity.test.ts": 3800,
diff --git a/src/core/setup/launcher-lanes.ts b/src/core/setup/launcher-lanes.ts
index 17ac73c210..a86067a9cf 100644
--- a/src/core/setup/launcher-lanes.ts
+++ b/src/core/setup/launcher-lanes.ts
@@ -72,11 +72,13 @@ function state(launcher: string | null): { reason: LauncherLaneFinding['reason']
/**
* The `gbrain setup` command that rewrites an install's entries with what its receipt records. Setup keeps the recorded
- * capture and providers decisions on its own; a hooks opt-out and a source pin only come from flags, so the rerun carries them.
+ * capture and providers decisions on its own; a hooks opt-out, a source pin and the recorded binary only come from flags, so the
+ * rerun carries them (a recorded binary that no longer exists falls back to setup's PATH lookup).
*/
-export function setupRerunArgv(harness: 'claude-code' | 'codex', receipt: Pick<ClaudeSetupReceipt, 'name' | 'consent' | 'source_id'>, projectDir?: string): string[] {
+export function setupRerunArgv(harness: 'claude-code' | 'codex', receipt: Pick<ClaudeSetupReceipt, 'name' | 'consent' | 'source_id'> & Partial<Pick<ClaudeSetupReceipt, 'launcher'>>, projectDir?: string): string[] {
return ['gbrain', 'setup', harness, ...(receipt.name === 'gbrain' ? [] : ['--name', receipt.name]), ...(projectDir ? ['--scope', 'project'] : []),
- ...(receipt.consent.wiring_scope.value.hooks === 'none' ? ['--no-hooks'] : []), ...(receipt.source_id ? ['--source', receipt.source_id] : [])];
+ ...(receipt.consent.wiring_scope.value.hooks === 'none' ? ['--no-hooks'] : []), ...(receipt.source_id ? ['--source', receipt.source_id] : []),
+ ...(receipt.launcher?.startsWith('/') && existsSync(receipt.launcher) ? ['--gbrain-bin', receipt.launcher] : [])];
}
function mcpFindings(): LauncherLaneFinding[] {
diff --git a/test/setup.test.ts b/test/setup.test.ts
index 2d9e9eb108..f3141511af 100644
--- a/test/setup.test.ts
+++ b/test/setup.test.ts
@@ -1032,7 +1032,7 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
const lines: string[] = [];
await refreshHookLaunchers((l) => lines.push(l));
expect(lines.join('\n')).toContain("gbrain setup's codex hooks");
- expect(lines.join('\n')).toContain('run gbrain setup codex to rewrite them');
+ expect(lines.join('\n')).toContain(`run gbrain setup codex --gbrain-bin ${b.bin} to rewrite them`);
expect(hookLauncherProblem('codex')).toMatchObject({ lane: 'setup', reason: 'session_cwd' });
});
expect({ hooks: readFileSync(hooksJson(b), 'utf8'), config: readFileSync(codexToml(b), 'utf8') }).toEqual(before);
@@ -1084,7 +1084,7 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
expect(hookLauncherProblem('claude-code')).toBeNull();
const problem = hookLauncherProblems([]);
expect(problem).toMatchObject({ harness: 'claude-code', lane: 'mcp', reason: 'session_cwd', owner: 'setup', setupOwned: true });
- expect(hookLauncherFix(problem!)).toMatchObject({ actor: 'agent', argv: ['gbrain', 'setup', 'claude-code'] });
+ expect(hookLauncherFix(problem!)).toMatchObject({ actor: 'agent', argv: ['gbrain', 'setup', 'claude-code', '--gbrain-bin', b.bin] });
const lines: string[] = [];
await refreshHookLaunchers((l) => lines.push(l));
expect(lines.join('\n')).toContain("gbrain setup's claude-code MCP server and hooks now start gbrain from its own directory");
@@ -1102,7 +1102,7 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
let argv: string[] = [];
await withEnv(env(b), async () => {
argv = hookLauncherFix(hookLauncherProblems([])!).argv!;
- expect(argv).toEqual(['gbrain', 'setup', 'claude-code', '--no-hooks']);
+ expect(argv).toEqual(['gbrain', 'setup', 'claude-code', '--no-hooks', '--gbrain-bin', b.bin]);
});
expect((await setup(b, [...argv.slice(2), '--json'])).exitCode).toBe(0);
expect(readSetupReceipt(receipt(b)).setup!.consent.wiring_scope.value.hooks).toBe('none');
@@ -1137,7 +1137,7 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
await withEnv(env(b), async () => {
const problem = hookLauncherProblem('claude-code');
expect(problem).toMatchObject({ lane: 'setup', receiptPath: receipt(b) });
- expect(hookLauncherFix(problem!)).toMatchObject({ actor: 'agent', argv: ['gbrain', 'setup', 'claude-code'] });
+ expect(hookLauncherFix(problem!)).toMatchObject({ actor: 'agent', argv: ['gbrain', 'setup', 'claude-code', '--gbrain-bin', b.bin] });
});
});
@@ -1147,6 +1147,17 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
expect(setupRerunArgv('claude-code', { name: 'alpha', consent: consent('read-context') as any, source_id: null as any }, '/work/proj')).toEqual(['gbrain', 'setup', 'claude-code', '--name', 'alpha', '--scope', 'project']);
});
+ test('setupRerunArgv pins the binary the install recorded, so a PATH lookup in another directory cannot swap it', () => {
+ const consent = { wiring_scope: { value: { scope: 'user' as const, hooks: 'read-context' as const }, source: 'flag' as const }, capture: { value: 'accepted' as const, source: 'flag' as const }, providers: { value: 'declined' as const, source: 'default' as const } };
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-rerun-bin-'));
+ const bin = join(dir, 'gbrain');
+ writeFileSync(bin, '#!/bin/sh\n');
+ try {
+ expect(setupRerunArgv('claude-code', { name: 'gbrain', consent: consent as any, source_id: null as any, launcher: bin })).toEqual(['gbrain', 'setup', 'claude-code', '--gbrain-bin', bin]);
+ expect(setupRerunArgv('codex', { name: 'gbrain', consent: consent as any, source_id: null as any, launcher: join(dir, 'gone') })).toEqual(['gbrain', 'setup', 'codex']);
+ } finally { rmSync(dir, { recursive: true, force: true }); }
+ });
+
test('codex MCP (#8426): post-upgrade\'s printed rerun keeps a recorded --no-hooks', async () => {
const b = box();
expect((await setup(b, ['codex', '--no-hooks', '--json'])).exitCode).toBe(0);
@@ -1159,7 +1170,7 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
await withEnv(env(b), async () => {
const lines: string[] = [];
await refreshHookLaunchers((l) => lines.push(l));
- expect(lines.join('\n')).toContain('run gbrain setup codex --no-hooks to rewrite them');
+ expect(lines.join('\n')).toContain(`run gbrain setup codex --no-hooks --gbrain-bin ${b.bin} to rewrite them`);
});
});
@@ -1180,7 +1191,7 @@ describe('hooks written before the hook launcher (#8424): the next setup and pos
expect(hookLauncherProblems([])).toMatchObject({ harness: 'codex', lane: 'mcp', reason: 'session_cwd', owner: 'setup' });
const lines: string[] = [];
await refreshHookLaunchers((l) => lines.push(l));
- expect(lines.join('\n')).toContain(`gbrain setup's codex MCP server in ${codexToml(b)} start gbrain in the session's directory; run gbrain setup codex to rewrite them`);
+ expect(lines.join('\n')).toContain(`gbrain setup's codex MCP server in ${codexToml(b)} start gbrain in the session's directory; run gbrain setup codex --gbrain-bin ${b.bin} to rewrite them`);
});
expect({ hooks: readFileSync(hooksJson(b), 'utf8'), config: readFileSync(codexToml(b), 'utf8') }).toEqual(before);
expect((await setup(b, ['codex', '--json'])).exitCode).toBe(0);