mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Treat bundled cleanup hooks as built-ins (#42110)
## What changed - Centralize the allowlist for bundled MCP cleanup hooks and use it for both local and executor-discovered plugins, including `unified-computer-use` cleanup through `cua_repl`. - Mark matching cleanup hooks as trusted built-ins so they run without saved hook trust and remain active when regular hooks or their per-hook state are disabled. Plugin enablement and managed-only policy still apply. - Hide built-in cleanup hooks from hook listings and lifecycle notifications while retaining their metrics. Keep the built-in classification out of serialized protocol data. ## Testing - Cover allowlist boundaries, trust and enablement behavior, inline and file-based hook declarations, MCP success and error responses, hook listing, lifecycle notifications, metrics, and protocol serialization. GitOrigin-RevId: f93b7bc99f4ed9694f529def8ec383b45f31430e
This commit is contained in:
@@ -57,6 +57,8 @@ pub(crate) struct CommandShell {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct ConfiguredHandler {
|
||||
/// Internally admitted cleanup hook, enabled independently of per-hook state.
|
||||
pub builtin: bool,
|
||||
pub event_name: codex_protocol::protocol::HookEventName,
|
||||
pub matcher: Option<String>,
|
||||
pub timeout_sec: u64,
|
||||
@@ -195,6 +197,8 @@ pub enum HookListEntryHandler {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct HookListEntry {
|
||||
/// Builtin hooks remain available internally but are omitted from the public hooks list.
|
||||
pub builtin: bool,
|
||||
pub key: String,
|
||||
pub event_name: HookEventName,
|
||||
pub handler: HookListEntryHandler,
|
||||
@@ -231,7 +235,7 @@ impl ClaudeHooksEngine {
|
||||
command_runtime: CommandHookRuntime,
|
||||
mcp_executor: Arc<dyn HookMcpExecutor>,
|
||||
) -> Self {
|
||||
if !enabled {
|
||||
if !enabled && plugin_hook_sources.is_empty() {
|
||||
return Self {
|
||||
handlers: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
@@ -242,12 +246,18 @@ impl ClaudeHooksEngine {
|
||||
}
|
||||
|
||||
let _ = schema_loader::generated_hook_schemas();
|
||||
let discovered = discovery::discover_handlers(
|
||||
let mut discovered = discovery::discover_handlers(
|
||||
config_layer_stack,
|
||||
plugin_hook_sources,
|
||||
plugin_hook_load_warnings,
|
||||
bypass_hook_trust,
|
||||
);
|
||||
if !enabled {
|
||||
discovered.handlers.retain(|handler| handler.builtin);
|
||||
// Disabled ordinary hooks must not emit warnings or reject session startup.
|
||||
discovered.warnings.clear();
|
||||
discovered.required_load_errors.clear();
|
||||
}
|
||||
Self {
|
||||
handlers: discovered.handlers,
|
||||
warnings: discovered.warnings,
|
||||
@@ -308,6 +318,7 @@ impl ClaudeHooksEngine {
|
||||
continue;
|
||||
}
|
||||
self.handlers.push(ConfiguredHandler {
|
||||
builtin: true,
|
||||
event_name,
|
||||
matcher: None,
|
||||
timeout_sec: timeout_sec.unwrap_or(5).max(1),
|
||||
|
||||
Reference in New Issue
Block a user