Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(security): readiness never reruns an existing gbrain setup install with --no-hooks (adversarial review, #8426)
garrytan949985404dd6
diff --git a/src/core/readiness.ts b/src/core/readiness.tsindex 9926f0294a..fdd937b852 100644--- a/src/core/readiness.ts+++ b/src/core/readiness.ts@@ -28,6 +28,7 @@ import type { McpSurface } from '../mcp/surface.ts';import { REGISTRATION_SURFACE, registrationAdvertise, stdioServeArgv } from './mcp-registration.ts';import { gbrainPath } from './config.ts';import { hookLauncherPath } from './setup/hook-launcher.ts';+import { localSetupRecords } from './setup/local-receipts.ts';import type { BrainEngine } from './engine.ts';import { redactForTransport, type Action, type ActionInput, type Effect, type Transport } from './agent-output.ts';import { detectCapabilities } from './capability.ts';@@ -415,6 +416,12 @@ const SURFACE_GLOSS: Record<McpSurface, string> = {function stdioRegistration(h: ReadinessHarness, bin: string, chosen?: McpSurface): Action {const surface = chosen ?? REGISTRATION_SURFACE;const advertise = registrationAdvertise({ userChoseSurface: chosen !== undefined });+ // A setup install's hooks decision lives in its receipt; a --no-hooks rerun would turn its hooks off, so doctor names the rerun instead.+ if (h !== 'opencode' && localSetupRecords().some((r) => r.harness === h && r.status === 'installed' && r.scope !== 'project')) {+ return { argv: ['gbrain', 'doctor', '--only', 'harness_wiring', '--json'], consent: [], actor: 'agent', requires_exclusive: false,+ why: `gbrain setup already registered gbrain for ${HARNESS_LABEL[h]}; doctor checks that entry and names the setup rerun that keeps its recorded hooks and source decisions.`,+ verify: VERIFY('harness_wiring'), docs: MEMORY_VERBS_INSTALL };+ }// Each harness starts a user-scope stdio server in the session's directory, so its writer registers serve behind gbrain's launcher (#8426, #8435).const serve = [hookLauncherPath(), ...stdioServeArgv(bin, surface, advertise)];const argv = h === 'opencode' ? ['gbrain', 'bootstrap', 'hooks', '--harness', 'opencode', '--no-hooks', ...(chosen ? ['--surface', chosen] : [])]diff --git a/test/readiness.test.ts b/test/readiness.test.tsindex 4873cb3b3e..2cd4510812 100644--- a/test/readiness.test.ts+++ b/test/readiness.test.ts@@ -19,6 +19,9 @@ import { renderAction, cliRenderContext, type Action } from '../src/core/agent-oimport { listRecipes } from '../src/core/ai/recipes/index.ts';import type { GBrainConfig } from '../src/core/config.ts';import { withEnv } from './helpers/with-env.ts';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';const PROVIDER_ENVS = [...new Set(listRecipes().flatMap(r => r.auth_env?.required ?? []))];@@ -168,6 +171,19 @@ 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('an existing gbrain setup install is never rerun with --no-hooks: readiness points at doctor, which names the rerun that keeps its decisions', async () => {+ const home = mkdtempSync(join(tmpdir(), 'gbrain-readiness-setup-'));+ try {+ await withEnv({ HOME: home, GBRAIN_HOME: home, CLAUDE_CONFIG_DIR: undefined, CODEX_HOME: undefined }, async () => {+ writeFileSync(join(home, '.gbrain-connection-claude-code-gbrain.json'), JSON.stringify({ connection: 'local-stdio', setup_receipt_version: 1, gbrain_home: join(home, '.gbrain'), harness: 'claude-code', name: 'gbrain', status: 'installed', scope: 'user' }));+ const claude = harnessWiringEntry({ transport: 'cli', harnesses: ['claude-code'], lockOwner: null, gbrainBin: BIN });+ expect(claude.fix).toMatchObject({ argv: ['gbrain', 'doctor', '--only', 'harness_wiring', '--json'], consent: [], actor: 'agent' });+ expect(harnessWiringEntry({ transport: 'cli', harnesses: ['codex'], lockOwner: null, gbrainBin: BIN }).fix?.argv)+ .toEqual(['gbrain', 'setup', 'codex', '--no-hooks', '--gbrain-bin', BIN]);+ });+ } finally { rmSync(home, { recursive: true, force: true }); }+ });+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(['gbrain', 'setup', 'claude-code', '--no-hooks', '--gbrain-bin', BIN]);