Add hooks for interrupted turns (#40511)

## What changed

- Add an `Interrupt` hook event that runs for an active top-level turn before its
  interrupted abort event is emitted.
- Flush the turn transcript before invoking the hook and provide the session,
  turn, transcript, working directory, model, and permission mode in its input.
- Support command and MCP handlers, including asynchronous commands, with a
  one-second default timeout and a three-second maximum.
- Expose the event through hook configuration, managed requirements, app-server
  notifications, generated schemas, analytics, and the TUI hook views.

## Testing

- Cover handler discovery, timeout normalization, output parsing, protocol
  compatibility, TUI rendering, and interrupt execution ordering.

GitOrigin-RevId: 163fa7c098d94ac2775f6d137f8e916f8ea9b6eb
This commit is contained in:
Andrei Eternal authored and copyberry committed 2026-08-25 01:27:18 +00:00
1 parent 9b2ef38f54
commit cbfd999db7
49 files changed
+1393 -48

No files matched your search

@@ -779,6 +779,7 @@ fn event_label(event_name: HookEventName) -> &'static str {
HookEventName::SubagentStart => "SubagentStart",
HookEventName::SubagentStop => "SubagentStop",
HookEventName::Stop => "Stop",
HookEventName::Interrupt => "Interrupt",
}
}
@@ -795,6 +796,7 @@ fn event_description(event_name: HookEventName) -> &'static str {
HookEventName::SubagentStart => "When a subagent is created",
HookEventName::SubagentStop => "Right before a subagent ends its turn",
HookEventName::Stop => "Right before Codex ends its turn",
HookEventName::Interrupt => "Right before an interrupted turn is aborted",
}
}
@@ -18,5 +18,6 @@ expression: "render_lines(&view, 112)"
SubagentStart 0 0 When a subagent is created
SubagentStop 0 0 Right before a subagent ends its turn
Stop 0 0 Right before Codex ends its turn
Interrupt 0 0 Right before an interrupted turn is aborted
Press enter to view hooks; esc to close
@@ -22,5 +22,6 @@ expression: "render_lines(&view, 112)"
SubagentStart 0 0 When a subagent is created
SubagentStop 0 0 Right before a subagent ends its turn
Stop 0 0 Right before Codex ends its turn
Interrupt 0 0 Right before an interrupted turn is aborted
Press enter to view hooks; esc to close
@@ -20,5 +20,6 @@ expression: "render_lines(&view, 112)"
SubagentStart 0 0 0 When a subagent is created
SubagentStop 0 0 0 Right before a subagent ends its turn
Stop 0 0 0 Right before Codex ends its turn
Interrupt 0 0 0 Right before an interrupted turn is aborted
Press t to trust all; enter to review hooks; esc to close