Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes, fix-check round (#8424)
garrytanfaf81564ab2b
diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 5ce7f13a08..4fd4df68d1 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -4365,7 +4365,11 @@ directory in `GBRAIN_HOOK_CWD` and runs gbrain from its own directory. TheRun `fix.argv` (`gbrain setup <harness>` for setup's hooks,`gbrain setup <harness> --instructions-only` for the turn-rule hook);`gbrain post-upgrade` moves every user-scope hook it can find. A project-scope-install is refreshed from its project directory. Check with+install is refreshed from its project directory. A setup hook you edited after+setup wrote it (`edited: true`) is never rewritten, so the fix is a+`user_message`: remove or rewrite that entry, then run setup. When the check+already carried another warning with its own fix, that code and fix stay, and+the launcher fix is in `details.hook_launcher_fix`. Check with`gbrain doctor --only harness_wiring`.## Connection noticesdiff --git a/src/commands/doctor/checks/harness-wiring.ts b/src/commands/doctor/checks/harness-wiring.tsindex 11e0a6f491..7966216762 100644--- a/src/commands/doctor/checks/harness-wiring.ts+++ b/src/commands/doctor/checks/harness-wiring.ts@@ -523,7 +523,7 @@ export function hookLauncherFix(p: HookLauncherProblem): Action {const why = "Rewrites gbrain's hooks to start gbrain from its own launcher directory, so a repository's bunfig.toml or .env never runs when a session opens there. `gbrain post-upgrade` refreshes the user-scope hooks too.";const verify = doctorVerify(NAME);if (p.reason === 'foreign') return { consent: [], actor: 'user', requires_exclusive: false, verify, why, user_message: `${p.detail}. Remove that file (gbrain did not write it), then run: ${argv.join(' ')}` };- if (p.edited) return { consent: [], actor: 'user', requires_exclusive: false, verify, why, user_message: `${p.detail}. Remove or rewrite that entry in ${p.source} (setup never overwrites an edit), then run: ${argv.join(' ')}` };+ if (p.edited) return { consent: [], actor: 'user', requires_exclusive: false, verify, why, user_message: `${p.detail}. Remove or rewrite that entry in ${p.source} (setup never overwrites an edit), then ${project ? `from ${project}, ` : ''}run: ${argv.join(' ')}` };if (project) return { consent: [], actor: 'user', requires_exclusive: false, verify, why, user_message: `gbrain's hooks for ${project} start gbrain in the session's directory. From ${project}, run: ${argv.join(' ')}` };return { argv, consent: ['persistent_install'], actor: 'agent', requires_exclusive: false, verify, why };}diff --git a/src/core/setup/hook-launcher-refresh.ts b/src/core/setup/hook-launcher-refresh.tsindex 24ceaf809a..e8402cef89 100644--- a/src/core/setup/hook-launcher-refresh.ts+++ b/src/core/setup/hook-launcher-refresh.ts@@ -90,9 +90,9 @@ async function refreshSetup(log: (line: string) => void): Promise<void> {sourceId: receipt.source_id, surface: receipt.surface, advertise: receipt.advertise ?? null, events: Object.keys({ ...receipt.hooks.owned, ...receipt.hooks.pending }) as ClaudeHookEvent[] };if (!receipt.mcp_plugin && inspectClaudeSetup(plan).mcp.state !== 'current') { log(`Hook launcher: gbrain's claude-code hooks start gbrain in the session's directory; run ${rerun} to rewrite them.`); continue; }const applied = await applyClaudeSetup(plan, receipt.consent, { pluginOwner: receipt.mcp_plugin ?? null, brainCreated: false });- const edited = new Set(Object.values(applied.edited));- const kept = Object.keys(applied.edited);- log(claudeHookEntries(paths.settingsPath).some((e) => edited.has(hookEntryHash(e) ?? '') && needsLauncher(e.command as string))+ const left = new Set(claudeHookEntries(paths.settingsPath).filter((e) => needsLauncher(e.command as string)).map((e) => hookEntryHash(e) ?? ''));+ const kept = Object.entries(applied.edited).filter(([, hash]) => left.has(hash)).map(([event]) => event);+ log(kept.length > 0? `Hook launcher: gbrain setup's claude-code ${kept.join(', ')} hook in ${paths.settingsPath} was edited after setup wrote it, so it is kept as is and still starts gbrain in the session's directory; remove or rewrite it, then run ${rerun}.`: `Hook launcher: gbrain setup's claude-code hooks in ${paths.settingsPath} now start gbrain from its own directory.`);} else if (record.harness === 'codex') {@@ -105,9 +105,9 @@ async function refreshSetup(log: (line: string) => void): Promise<void> {sourceId: receipt.source_id, surface: receipt.surface, advertise: receipt.advertise ?? null, events: Object.keys({ ...receipt.hooks.owned, ...receipt.hooks.pending }) as CodexSetupEvent[] };if (!receipt.mcp_plugin && inspectCodexSetup(plan).mcp.state !== 'current') { log(`Hook launcher: gbrain's codex hooks start gbrain in the session's directory; run ${rerun} to rewrite them.`); continue; }const applied = await applyCodexSetup(plan, receipt.consent, { pluginOwner: receipt.mcp_plugin ?? null, brainCreated: false });- const edited = new Set(Object.values(applied.receipt.hooks.edited));- const kept = applied.preserved.filter((p) => p.kind === 'hook' && p.reason === 'edited').map((p) => p.event);- log(codexHookCensus(paths.hooksPath).some((g) => edited.has(g.hash) && g.commands.some(needsLauncher))+ const left = new Set(codexHookCensus(paths.hooksPath).filter((g) => g.commands.some(needsLauncher)).map((g) => g.hash));+ const kept = Object.entries(applied.receipt.hooks.edited).filter(([, hash]) => left.has(hash)).map(([event]) => event);+ log(kept.length > 0? `Hook launcher: gbrain setup's codex ${kept.join(', ')} hook in ${paths.hooksPath} was edited after setup wrote it, so it is kept as is and still starts gbrain in the session's directory; remove or rewrite it, then run ${rerun}.`: `Hook launcher: gbrain setup's codex hooks in ${paths.hooksPath} now start gbrain from its own directory.`);}diff --git a/src/core/setup/turn-hook-check.ts b/src/core/setup/turn-hook-check.tsindex 81d200f77d..aa0a8d8a64 100644--- a/src/core/setup/turn-hook-check.ts+++ b/src/core/setup/turn-hook-check.ts@@ -182,14 +182,12 @@ export function hookLauncherProblem(harness: 'claude-code' | 'codex', opts: { pr}for (const f of found) {const launcher = hookLauncherInCommand(f.command);- const edited = f.edited ? { edited: true } : {};- const kept = f.edited ? '; it was edited after setup wrote it, so setup keeps it as is' : '';if (!launcher) {- return { harness, lane: f.lane, source: f.source, reason: 'session_cwd', ...edited,- detail: `gbrain's ${f.lane} hook in ${f.source} starts gbrain in the session's directory, so Bun loads that directory's bunfig.toml and .env before gbrain runs${kept}` };+ return { harness, lane: f.lane, source: f.source, reason: 'session_cwd', ...(f.edited ? { edited: true } : {}),+ detail: `gbrain's ${f.lane} hook in ${f.source} starts gbrain in the session's directory, so Bun loads that directory's bunfig.toml and .env before gbrain runs${f.edited ? '; it was edited after setup wrote it, so setup keeps it as is' : ''}` };}const s = hookLauncherState(launcher);- if (s.state !== 'current') return { harness, lane: f.lane, source: f.source, reason: s.state, ...edited, detail: `gbrain's ${f.lane} hook in ${f.source} runs through ${launcher}, but ${s.detail}${kept}` };+ if (s.state !== 'current') return { harness, lane: f.lane, source: f.source, reason: s.state, detail: `gbrain's ${f.lane} hook in ${f.source} runs through ${launcher}, but ${s.detail}` };}return null;}diff --git a/test/hook-launcher-bunfig.test.ts b/test/hook-launcher-bunfig.test.tsindex 8386dbadb9..e1b1fde849 100644--- a/test/hook-launcher-bunfig.test.ts+++ b/test/hook-launcher-bunfig.test.ts@@ -253,6 +253,7 @@ describe('doctor: the hook_session_cwd fix and how it joins the harness_wiring cconst edited = hookLauncherFix(problem(b, { edited: true }));expect(edited.actor).toBe('user');expect(edited.user_message).toContain('Remove or rewrite that entry');+ expect(hookLauncherFix(problem(b, { edited: true, source: join(project, '.claude', 'settings.local.json') })).user_message).toContain(`then from ${project}, run: gbrain setup claude-code --scope project`);});});