fix(cli): trust injected Codex session hook

Codex now requires hook trust before non-managed hooks can run. HAPI relies on the runtime-injected SessionStart hook to receive the Codex thread/session id, so leaving that hook untrusted breaks local Codex startup without manual /hooks review.\n\nGenerate the same trusted_hash Codex derives for the injected SessionStart command and pass it through the runtime hooks.state override. The trust is scoped to the synthetic session-flags hook key and the exact generated command, so user, project, and plugin hooks still go through Codex review normally.\n\nAlso cover the generated config args so future changes keep both the hook declaration and its trust state together.\n\nValidation:\n- bun test cli/src/codex/utils/codexMcpConfig.test.ts\n- bun typecheck
This commit is contained in:
weishu
2026-05-08 19:09:38 +08:00
parent 991b01cd10
commit 2fe1a2ed45
2 changed files with 50 additions and 1 deletions
@@ -103,6 +103,10 @@ describe('codexMcpConfig', () => {
expect(args[1]).toContain('hooks.SessionStart=[');
expect(args[1]).toContain('type = "command"');
expect(args[1]).toContain('hook-forwarder --port 4312 --token secret-token');
expect(args[2]).toBe('-c');
expect(args[3]).toContain('hooks.state={');
expect(args[3]).toContain(':session_start:0:0');
expect(args[3]).toContain('trusted_hash="sha256:');
});
});
});