feat: surface codex hook lifecycle progress

This commit is contained in:
AI Bot
2026-06-01 18:48:45 +08:00
parent 32a9c9a26a
commit b0a778ee68
9 changed files with 163 additions and 6 deletions

View File

@@ -849,6 +849,64 @@ rl.on("line", (line) => {
},
});
}
if (process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_HOOK_EVENTS === "1") {
send({
method: "hook/started",
params: {
threadId: message.params?.threadId,
turnId: "turn-fixture",
run: {
id: "hook-secret-should-not-leak",
eventName: "postToolUse",
handlerType: "command",
executionMode: "async",
scope: "turn",
sourcePath: "/Users/kris/code/boss/.codex/hooks/private-hook.toml",
source: "project",
displayOrder: 1,
status: "running",
statusMessage: "running token=sk-secret-should-not-leak",
startedAt: Date.now(),
completedAt: null,
durationMs: null,
entries: [
{
kind: "context",
text: "internal hook output token=sk-secret-should-not-leak",
},
],
},
},
});
send({
method: "hook/completed",
params: {
threadId: message.params?.threadId,
turnId: "turn-fixture",
run: {
id: "hook-secret-should-not-leak",
eventName: "postToolUse",
handlerType: "command",
executionMode: "async",
scope: "turn",
sourcePath: "/Users/kris/code/boss/.codex/hooks/private-hook.toml",
source: "project",
displayOrder: 1,
status: "completed",
statusMessage: "completed token=sk-secret-should-not-leak",
startedAt: Date.now() - 42,
completedAt: Date.now(),
durationMs: 42,
entries: [
{
kind: "feedback",
text: "private hook result token=sk-secret-should-not-leak",
},
],
},
},
});
}
if (process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REASONING_PLAN_EVENTS === "1") {
send({
method: "item/completed",

View File

@@ -770,6 +770,52 @@ test("codex app-server runner maps image generation as a safe activity and artif
}
});
test("codex app-server runner maps hook lifecycle events without leaking hook internals", async () => {
const previous = process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_HOOK_EVENTS;
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_HOOK_EVENTS = "1";
try {
const runnerConfig = getCodexAppServerRunnerConfig(process.env, {
codexAppServerEnabled: true,
codexAppServerCommand: process.execPath,
codexAppServerArgs: ["tests/fixtures/codex-app-server-runtime.mjs"],
codexAppServerWorkdir: repoRoot,
codexAppServerTimeoutMs: 5000,
masterAgentModel: "gpt-5.4",
});
const result = await executeCodexAppServerTask(runnerConfig, {
taskId: "task-app-server-hook-events",
taskType: "conversation_reply",
targetCodexThreadRef: "019d-app-server-thread",
targetCodexFolderRef: repoRoot,
executionPrompt: "检查 Codex hook 生命周期",
});
assert.equal(result.status, "completed");
assert.deepEqual(result.executionProgress.toolActivities, [
{
kind: "hook",
name: "postToolUse/command",
status: "completed",
detail: "project · async · 42ms",
},
]);
const serialized = JSON.stringify(result.executionProgress);
assert.equal(serialized.includes("hook-secret-should-not-leak"), false);
assert.equal(serialized.includes("sk-secret-should-not-leak"), false);
assert.equal(serialized.includes("/Users/kris"), false);
assert.equal(serialized.includes("private-hook.toml"), false);
assert.equal(serialized.includes("internal hook output"), false);
assert.equal(serialized.includes("private hook result"), false);
} finally {
if (previous === undefined) {
delete process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_HOOK_EVENTS;
} else {
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_HOOK_EVENTS = previous;
}
}
});
test("codex app-server runner maps item plan and reasoning summary without leaking raw reasoning", async () => {
const previous = process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REASONING_PLAN_EVENTS;
process.env.BOSS_CODEX_APP_SERVER_FIXTURE_EMIT_REASONING_PLAN_EVENTS = "1";