mirror of
https://github.com/openai/codex.git
synced 2026-10-26 18:38:47 +00:00
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:
committed by
copyberry
parent
9b2ef38f54
commit
cbfd999db7
@@ -56,6 +56,8 @@ pub struct HookEventsToml {
|
||||
pub subagent_stop: Vec<MatcherGroup>,
|
||||
#[serde(rename = "Stop", default)]
|
||||
pub stop: Vec<MatcherGroup>,
|
||||
#[serde(rename = "Interrupt", default)]
|
||||
pub interrupt: Vec<MatcherGroup>,
|
||||
}
|
||||
|
||||
impl HookEventsToml {
|
||||
@@ -72,6 +74,7 @@ impl HookEventsToml {
|
||||
subagent_start,
|
||||
subagent_stop,
|
||||
stop,
|
||||
interrupt,
|
||||
} = self;
|
||||
pre_tool_use.is_empty()
|
||||
&& permission_request.is_empty()
|
||||
@@ -84,6 +87,7 @@ impl HookEventsToml {
|
||||
&& subagent_start.is_empty()
|
||||
&& subagent_stop.is_empty()
|
||||
&& stop.is_empty()
|
||||
&& interrupt.is_empty()
|
||||
}
|
||||
|
||||
pub fn handler_count(&self) -> usize {
|
||||
@@ -99,6 +103,7 @@ impl HookEventsToml {
|
||||
subagent_start,
|
||||
subagent_stop,
|
||||
stop,
|
||||
interrupt,
|
||||
} = self;
|
||||
[
|
||||
pre_tool_use,
|
||||
@@ -112,6 +117,7 @@ impl HookEventsToml {
|
||||
subagent_start,
|
||||
subagent_stop,
|
||||
stop,
|
||||
interrupt,
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
@@ -119,7 +125,7 @@ impl HookEventsToml {
|
||||
.sum()
|
||||
}
|
||||
|
||||
pub fn into_matcher_groups(self) -> [(HookEventName, Vec<MatcherGroup>); 11] {
|
||||
pub fn into_matcher_groups(self) -> [(HookEventName, Vec<MatcherGroup>); 12] {
|
||||
[
|
||||
(HookEventName::PreToolUse, self.pre_tool_use),
|
||||
(HookEventName::PermissionRequest, self.permission_request),
|
||||
@@ -132,6 +138,7 @@ impl HookEventsToml {
|
||||
(HookEventName::SubagentStart, self.subagent_start),
|
||||
(HookEventName::SubagentStop, self.subagent_stop),
|
||||
(HookEventName::Stop, self.stop),
|
||||
(HookEventName::Interrupt, self.interrupt),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +215,7 @@ fn append_hook_events(existing: &mut HookEventsToml, incoming: HookEventsToml) -
|
||||
subagent_start,
|
||||
subagent_stop,
|
||||
stop,
|
||||
interrupt,
|
||||
} = incoming;
|
||||
|
||||
let mut changed = false;
|
||||
@@ -229,6 +230,7 @@ fn append_hook_events(existing: &mut HookEventsToml, incoming: HookEventsToml) -
|
||||
changed |= append_vec(&mut existing.subagent_start, subagent_start);
|
||||
changed |= append_vec(&mut existing.subagent_stop, subagent_stop);
|
||||
changed |= append_vec(&mut existing.stop, stop);
|
||||
changed |= append_vec(&mut existing.interrupt, interrupt);
|
||||
changed
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user