Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,30 @@ describe("ProviderActivityProjection", () => {
]);
});

it("names the hook that failed", () => {
const activities = projectRuntimeEventToActivities({
type: "hook.completed",
eventId: EventId.make("evt-hook-completed"),
provider: ProviderDriverKind.make("codex"),
threadId: ThreadId.make("thread-1"),
createdAt: "2026-06-01T12:00:00.000Z",
payload: {
hookId: "hook-1",
hookEvent: "sessionStart",
outcome: "error",
stderr: "node: command not found",
},
} satisfies ProviderRuntimeEvent);

expect(activities).toEqual([
expect.objectContaining({
kind: "hook.completed",
tone: "error",
summary: "SessionStart hook failed",
}),
]);
});

it("suppresses routine MCP startup status updates", () => {
for (const status of ["starting", "ready", "connected", "cancelled"]) {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,19 +1014,25 @@ export function projectRuntimeEventToActivities(

case "hook.completed": {
const detail = event.payload.output ?? event.payload.stdout ?? event.payload.stderr;
// Codex names events in camelCase ("sessionStart"); hook configs and
// Claude use "SessionStart".
const hook = event.payload.hookEvent
? `${event.payload.hookEvent.charAt(0).toUpperCase()}${event.payload.hookEvent.slice(1)} hook`
: "Hook";
return [
baseActivity(event, {
id: event.eventId,
tone: event.payload.outcome === "error" ? "error" : "tool",
kind: "hook.completed",
summary:
event.payload.outcome === "success"
? "Hook completed"
? `${hook} completed`
: event.payload.outcome === "cancelled"
? "Hook cancelled"
: "Hook failed",
? `${hook} cancelled`
: `${hook} failed`,
payload: {
hookId: event.payload.hookId,
...(event.payload.hookEvent ? { hookEvent: event.payload.hookEvent } : {}),
outcome: event.payload.outcome,
status: event.payload.outcome === "success" ? "completed" : "failed",
...(detail ? { detail: truncateBlock(detail) } : {}),
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/provider/Layers/ClaudeAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7074,12 +7074,14 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
},
});
return;
case "hook_response":
case "hook_response": {
const hookEvent = nonEmptyString(message.hook_event);
yield* offerRuntimeEvent({
...base,
type: "hook.completed",
payload: {
hookId: message.hook_id,
...(hookEvent ? { hookEvent } : {}),
outcome: message.outcome,
output: message.output,
stdout: message.stdout,
Expand All @@ -7088,6 +7090,7 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
},
});
return;
}
case "background_tasks_changed": {
// This is a level signal with replace semantics. Forward the complete
// set so orchestration can set the pending count absolutely; do not
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/provider/Layers/CodexAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,7 @@ export function mapToRuntimeEvents(
type: "hook.completed",
payload: {
hookId: payload.run.id,
hookEvent: payload.run.eventName,
outcome: hookOutcomeFromStatus(payload.run.status),
...(output ? { output } : {}),
...(payload.run.statusMessage ? { stderr: payload.run.statusMessage } : {}),
Expand Down
45 changes: 45 additions & 0 deletions apps/web/src/session-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,51 @@ describe("deriveWorkLogEntries", () => {
expect(entries).toEqual([]);
});

it("shows a hook only when it fails", () => {
const hook = (id: string, outcome: "success" | "error") => [
makeActivity({
id: `${id}-started`,
createdAt: "2026-02-23T00:00:01.000Z",
kind: "hook.started",
summary: "SessionStart hook started",
tone: "tool",
payload: { hookId: id, hookName: "SessionStart:startup", hookEvent: "SessionStart" },
}),
makeActivity({
id: `${id}-progress`,
createdAt: "2026-02-23T00:00:02.000Z",
kind: "hook.progress",
summary: "Hook output",
tone: "warning",
payload: { hookId: id, status: "inProgress", stderr: "warming up" },
}),
makeActivity({
id: `${id}-completed`,
createdAt: "2026-02-23T00:00:03.000Z",
kind: "hook.completed",
summary: outcome === "success" ? "SessionStart hook completed" : "SessionStart hook failed",
tone: outcome === "success" ? "tool" : "error",
payload: {
hookId: id,
hookEvent: "SessionStart",
outcome,
status: outcome === "success" ? "completed" : "failed",
...(outcome === "error" ? { detail: "node: command not found" } : {}),
},
}),
];

expect(deriveWorkLogEntries(hook("hook-ok", "success"))).toEqual([]);
expect(deriveWorkLogEntries(hook("hook-bad", "error"))).toEqual([
expect.objectContaining({
id: "hook-bad-completed",
label: "SessionStart hook failed",
tone: "error",
detail: "node: command not found",
}),
]);
});

it("omits task.started but shows task.progress and task.completed", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/session-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3184,6 +3184,7 @@ export function deriveWorkLogEntries(
// plugin settings unless an actual tool call or provider turn is blocked.
.filter((activity) => activity.kind !== "mcp.status.updated")
.filter((activity) => activity.kind !== "mcp.oauth.completed")
.filter((activity) => !isQuietHookActivity(activity))
.filter((activity) => activity.kind !== "prompt-suggestion.updated")
.filter((activity) => !isToolHeartbeatActivity(activity))
.filter(
Expand Down Expand Up @@ -3221,6 +3222,17 @@ export function deriveWorkLogEntries(
);
}

/** A hook that worked is plugin housekeeping (a plugin's note at session
* start, a formatter after each edit), so only one that failed or was
* cancelled gets a row: its completion, which names the hook and says why.
* Its start and output stay quiet even while it runs. */
function isQuietHookActivity(activity: OrchestrationThreadActivity): boolean {
if (activity.kind === "hook.started" || activity.kind === "hook.progress") {
return true;
}
return activity.kind === "hook.completed" && asRecord(activity.payload)?.outcome === "success";
}

/** A provider's connection retries matter only while they last: once the
* provider answers again in that turn (a thought, a tool call, a usage
* update), they drop out. Retries nothing followed stay, as one line. */
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/providerRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ export type HookProgressPayload = typeof HookProgressPayload.Type;

const HookCompletedPayload = Schema.Struct({
hookId: TrimmedNonEmptyStringSchema,
/** The hook's trigger (SessionStart, PreToolUse...), so a failure can say which hook failed. */
hookEvent: Schema.optional(TrimmedNonEmptyStringSchema),
outcome: Schema.Literals(["success", "error", "cancelled"]),
output: Schema.optional(Schema.String),
stdout: Schema.optional(Schema.String),
Expand Down
Loading