mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
## What changed - Add discovery and listing APIs for environment-owned required hooks, with command and MCP execution routed to the owning environment. - Use each environment's working directory in hook input, withhold controller transcript paths, and prevent environment hooks from granting permission requests. - Resolve `command_windows` against the environment's platform and, when hooks are enabled, reject unloadable required hooks before accepting environment configurations at startup or readiness. ## Testing Add regression coverage for invalid managed hook matchers at startup and readiness, successful readiness after correction, and per-hook working directory and transcript path scoping for `SubagentStop`. GitOrigin-RevId: 1ac0ab3778ba608c72e5917fcbaebcc1d454887f
140 lines
4.7 KiB
Rust
140 lines
4.7 KiB
Rust
mod config_rules;
|
|
mod context;
|
|
mod declarations;
|
|
mod engine;
|
|
mod environment;
|
|
pub(crate) mod events;
|
|
mod legacy_notify;
|
|
mod mcp;
|
|
pub use environment::EnvironmentHookOutput;
|
|
pub use environment::EnvironmentHookSource;
|
|
pub use environment::HookEnvironmentExecutor;
|
|
mod output_spill;
|
|
mod registry;
|
|
mod schema;
|
|
mod types;
|
|
|
|
use codex_protocol::protocol::HookEventName;
|
|
|
|
pub use config_rules::hook_states_from_stack;
|
|
pub use declarations::PluginHookDeclaration;
|
|
pub use declarations::plugin_hook_declarations;
|
|
pub use engine::HookListEntry;
|
|
pub use engine::HookListEntryHandler;
|
|
pub use engine::discovery::validate_environment_hooks;
|
|
pub use engine::dispatcher::hook_execution_mode_label;
|
|
pub use engine::dispatcher::hook_handler_type_label;
|
|
pub use events::common::SubagentHookContext;
|
|
/// Hook event names as they appear in hooks JSON and config files.
|
|
pub const HOOK_EVENT_NAMES: [&str; 14] = [
|
|
"PreModelRequest",
|
|
"PostModelRequest",
|
|
"PreToolUse",
|
|
"PermissionRequest",
|
|
"PostToolUse",
|
|
"PreCompact",
|
|
"PostCompact",
|
|
"SessionStart",
|
|
"SessionEnd",
|
|
"UserPromptSubmit",
|
|
"SubagentStart",
|
|
"SubagentStop",
|
|
"Stop",
|
|
"Interrupt",
|
|
];
|
|
|
|
/// Hook event names whose matcher fields are meaningful during dispatch.
|
|
///
|
|
/// Other events can appear in hooks JSON, but Codex ignores their matcher
|
|
/// fields because those events do not dispatch against a tool, compaction
|
|
/// trigger, session-start source, or session-end reason.
|
|
pub const HOOK_EVENT_NAMES_WITH_MATCHERS: [&str; 9] = [
|
|
"PreToolUse",
|
|
"PermissionRequest",
|
|
"PostToolUse",
|
|
"PreCompact",
|
|
"PostCompact",
|
|
"SessionStart",
|
|
"SessionEnd",
|
|
"SubagentStart",
|
|
"SubagentStop",
|
|
];
|
|
|
|
pub use context::HookContext;
|
|
pub use events::compact::PostCompactRequest;
|
|
pub use events::compact::PreCompactOutcome;
|
|
pub use events::compact::PreCompactRequest;
|
|
pub use events::compact::StatelessHookOutcome;
|
|
pub use events::interrupt::InterruptOutcome;
|
|
pub use events::interrupt::InterruptRequest;
|
|
pub use events::permission_request::PermissionRequestDecision;
|
|
pub use events::permission_request::PermissionRequestOutcome;
|
|
pub use events::permission_request::PermissionRequestRequest;
|
|
pub use events::post_tool_use::PostToolUseOutcome;
|
|
pub use events::post_tool_use::PostToolUseRequest;
|
|
pub use events::pre_tool_use::PreToolUseOutcome;
|
|
pub use events::pre_tool_use::PreToolUseRequest;
|
|
pub use events::session_end::SessionEndOutcome;
|
|
pub use events::session_end::SessionEndRequest;
|
|
pub use events::session_start::SessionStartOutcome;
|
|
pub use events::session_start::SessionStartRequest;
|
|
pub use events::session_start::SessionStartSource;
|
|
pub use events::session_start::StartHookTarget;
|
|
pub use events::stop::StopHookTarget;
|
|
pub use events::stop::StopOutcome;
|
|
pub use events::stop::StopRequest;
|
|
pub use events::user_prompt_submit::UserPromptSubmitOutcome;
|
|
pub use events::user_prompt_submit::UserPromptSubmitRequest;
|
|
pub use legacy_notify::legacy_notify_json;
|
|
pub use mcp::HookMcpCall;
|
|
pub use mcp::HookMcpExecutor;
|
|
pub use mcp::HookMcpOutput;
|
|
pub use registry::HookListOutcome;
|
|
pub use registry::Hooks;
|
|
pub use registry::HooksConfig;
|
|
pub use registry::list_hooks;
|
|
pub use schema::write_schema_fixtures;
|
|
pub use types::Hook;
|
|
pub use types::HookEvent;
|
|
pub use types::HookEventAfterAgent;
|
|
pub use types::HookPayload;
|
|
pub use types::HookResponse;
|
|
pub use types::HookResult;
|
|
|
|
/// Returns the hook event label used in persisted hook-state keys.
|
|
pub fn hook_event_key_label(event_name: HookEventName) -> &'static str {
|
|
match event_name {
|
|
HookEventName::PreToolUse => "pre_tool_use",
|
|
HookEventName::PermissionRequest => "permission_request",
|
|
HookEventName::PostToolUse => "post_tool_use",
|
|
HookEventName::PreCompact => "pre_compact",
|
|
HookEventName::PostCompact => "post_compact",
|
|
HookEventName::PreModelRequest => "pre_model_request",
|
|
HookEventName::PostModelRequest => "post_model_request",
|
|
HookEventName::SessionStart => "session_start",
|
|
HookEventName::SessionEnd => "session_end",
|
|
HookEventName::UserPromptSubmit => "user_prompt_submit",
|
|
HookEventName::SubagentStart => "subagent_start",
|
|
HookEventName::SubagentStop => "subagent_stop",
|
|
HookEventName::Stop => "stop",
|
|
HookEventName::Interrupt => "interrupt",
|
|
}
|
|
}
|
|
|
|
/// Builds the persisted config-state key for one discovered hook handler.
|
|
pub fn hook_key(
|
|
key_source: &str,
|
|
event_name: HookEventName,
|
|
group_index: usize,
|
|
handler_index: usize,
|
|
) -> String {
|
|
format!(
|
|
"{key_source}:{}:{group_index}:{handler_index}",
|
|
hook_event_key_label(event_name)
|
|
)
|
|
}
|
|
|
|
pub use events::model_request::ModelRequestHookEvent;
|
|
pub use events::model_request::ModelRequestHookInput;
|
|
pub use events::model_request::ModelRequestStatus;
|