diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index fe154ed8cd..7cf994baac 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::collections::HashMap; use std::fmt::Debug; use std::path::PathBuf; use std::sync::Arc; @@ -75,7 +74,6 @@ use crate::protocol::EventMsg; use crate::protocol::ExecApprovalRequestEvent; use crate::protocol::ExecCommandBeginEvent; use crate::protocol::ExecCommandEndEvent; -use crate::protocol::FileChange; use crate::protocol::InputItem; use crate::protocol::ListCustomPromptsResponseEvent; use crate::protocol::Op; @@ -1089,23 +1087,6 @@ impl Drop for Session { } } -#[derive(Clone, Debug)] -pub(crate) struct ExecCommandContext { - pub(crate) sub_id: String, - pub(crate) call_id: String, - pub(crate) command_for_display: Vec, - pub(crate) cwd: PathBuf, - pub(crate) apply_patch: Option, - pub(crate) tool_name: String, - pub(crate) otel_event_manager: OtelEventManager, -} - -#[derive(Clone, Debug)] -pub(crate) struct ApplyPatchCommandContext { - pub(crate) user_explicitly_approved_this_action: bool, - pub(crate) changes: HashMap, -} - async fn submission_loop( sess: Arc, turn_context: TurnContext, @@ -2365,6 +2346,8 @@ pub(crate) async fn exit_review_mode( use crate::executor::errors::ExecError; use crate::executor::linkers::PreparedExec; +use crate::tools::context::ApplyPatchCommandContext; +use crate::tools::context::ExecCommandContext; #[cfg(test)] pub(crate) use tests::make_session_and_context; diff --git a/codex-rs/core/src/executor/mod.rs b/codex-rs/core/src/executor/mod.rs index a5a305c604..97d7b29294 100644 --- a/codex-rs/core/src/executor/mod.rs +++ b/codex-rs/core/src/executor/mod.rs @@ -10,11 +10,11 @@ pub(crate) use runner::ExecutorConfig; pub(crate) use runner::normalize_exec_result; pub(crate) mod linkers { - use crate::codex::ExecCommandContext; use crate::exec::ExecParams; use crate::exec::StdoutStream; use crate::executor::backends::ExecutionMode; use crate::executor::runner::ExecutionRequest; + use crate::tools::context::ExecCommandContext; pub struct PreparedExec { pub(crate) context: ExecCommandContext, diff --git a/codex-rs/core/src/executor/runner.rs b/codex-rs/core/src/executor/runner.rs index ede9ed49e7..db67276177 100644 --- a/codex-rs/core/src/executor/runner.rs +++ b/codex-rs/core/src/executor/runner.rs @@ -6,7 +6,6 @@ use std::time::Duration; use super::backends::ExecutionMode; use super::backends::backend_for_mode; use super::cache::ApprovalCache; -use crate::codex::ExecCommandContext; use crate::codex::Session; use crate::error::CodexErr; use crate::error::SandboxErr; @@ -24,6 +23,7 @@ use crate::protocol::AskForApproval; use crate::protocol::ReviewDecision; use crate::protocol::SandboxPolicy; use crate::shell; +use crate::tools::context::ExecCommandContext; use codex_otel::otel_event_manager::ToolDecisionSource; #[derive(Clone, Debug)] diff --git a/codex-rs/core/src/tools/context.rs b/codex-rs/core/src/tools/context.rs index 08c78fb9f5..bb43231730 100644 --- a/codex-rs/core/src/tools/context.rs +++ b/codex-rs/core/src/tools/context.rs @@ -1,3 +1,6 @@ +use crate::codex::Session; +use crate::codex::TurnContext; +use crate::turn_diff_tracker::TurnDiffTracker; use codex_otel::otel_event_manager::OtelEventManager; use codex_protocol::models::FunctionCallOutputPayload; use codex_protocol::models::ResponseInputItem; @@ -8,10 +11,6 @@ use std::borrow::Cow; use std::collections::HashMap; use std::path::PathBuf; -use crate::codex::Session; -use crate::codex::TurnContext; -use crate::turn_diff_tracker::TurnDiffTracker; - pub struct ToolInvocation<'a> { pub session: &'a Session, pub turn: &'a TurnContext, @@ -98,7 +97,7 @@ pub(crate) struct ExecCommandContext { pub(crate) call_id: String, pub(crate) command_for_display: Vec, pub(crate) cwd: PathBuf, - pub(crate) apply_patch: Option, + pub(crate) apply_patch: Option, pub(crate) tool_name: String, pub(crate) otel_event_manager: OtelEventManager, } diff --git a/codex-rs/core/src/tools/mod.rs b/codex-rs/core/src/tools/mod.rs index 9497633eb9..4d9cd26b2e 100644 --- a/codex-rs/core/src/tools/mod.rs +++ b/codex-rs/core/src/tools/mod.rs @@ -8,8 +8,6 @@ use crate::apply_patch; use crate::apply_patch::ApplyPatchExec; use crate::apply_patch::InternalApplyPatchInvocation; use crate::apply_patch::convert_apply_patch_to_protocol; -use crate::codex::ApplyPatchCommandContext; -use crate::codex::ExecCommandContext; use crate::codex::Session; use crate::codex::TurnContext; use crate::error::CodexErr; @@ -21,6 +19,8 @@ use crate::executor::ExecutionMode; use crate::executor::errors::ExecError; use crate::executor::linkers::PreparedExec; use crate::function_tool::FunctionCallError; +use crate::tools::context::ApplyPatchCommandContext; +use crate::tools::context::ExecCommandContext; use crate::turn_diff_tracker::TurnDiffTracker; use codex_apply_patch::MaybeApplyPatchVerified; use codex_apply_patch::maybe_parse_apply_patch_verified; diff --git a/codex-rs/core/src/tools/registry.rs b/codex-rs/core/src/tools/registry.rs index a0e0cf5fd7..23e712b34c 100644 --- a/codex-rs/core/src/tools/registry.rs +++ b/codex-rs/core/src/tools/registry.rs @@ -13,18 +13,12 @@ use crate::tools::context::ToolPayload; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum ToolKind { Function, - Custom, - LocalShell, UnifiedExec, Mcp, } #[async_trait] pub trait ToolHandler: Send + Sync { - fn spec(&self) -> Option<&crate::tools::spec::ResponsesApiTool> { - None - } - fn kind(&self) -> ToolKind; fn matches_kind(&self, payload: &ToolPayload) -> bool { @@ -32,8 +26,6 @@ pub trait ToolHandler: Send + Sync { (self.kind(), payload), (ToolKind::Function, ToolPayload::Function { .. }) | (ToolKind::Function, ToolPayload::UnifiedExec { .. }) - | (ToolKind::Custom, ToolPayload::Custom { .. }) - | (ToolKind::LocalShell, ToolPayload::LocalShell { .. }) | (ToolKind::UnifiedExec, ToolPayload::UnifiedExec { .. }) | (ToolKind::Mcp, ToolPayload::Mcp { .. }) ) @@ -64,10 +56,6 @@ impl ToolRegistry { // } // } - pub fn iter_handlers(&self) -> impl Iterator)> { - self.handlers.iter() - } - pub async fn dispatch<'a>( &self, invocation: ToolInvocation<'a>, @@ -97,7 +85,9 @@ impl ToolRegistry { match handler.handle(invocation).await { Ok(output) => { let preview = output.log_preview(); - let mut guard = output_cell.lock().expect("mutex poisoned"); + let mut guard = output_cell + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); *guard = Some(output); Ok(preview) } @@ -109,7 +99,9 @@ impl ToolRegistry { match result { Ok(_) => { - let mut guard = output_cell.lock().expect("mutex poisoned"); + let mut guard = output_cell + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); let output = guard.take().ok_or_else(|| { FunctionCallError::RespondToModel("tool produced no output".to_string()) })?; @@ -160,14 +152,6 @@ impl ToolRegistryBuilder { // } // } - pub fn extend(&mut self, other: ToolRegistryBuilder) { - for (name, handler) in other.handlers { - if self.handlers.insert(name.clone(), handler).is_some() { - warn!("overwriting handler for tool {name}"); - } - } - } - pub fn build(self) -> ToolRegistry { ToolRegistry::new(self.handlers) } diff --git a/codex-rs/core/src/tools/router.rs b/codex-rs/core/src/tools/router.rs index 403f5a5c78..56d04fd62c 100644 --- a/codex-rs/core/src/tools/router.rs +++ b/codex-rs/core/src/tools/router.rs @@ -37,10 +37,6 @@ impl Router { Self { registry, specs } } - pub fn new(registry: ToolRegistry, specs: Vec) -> Self { - Self { registry, specs } - } - pub fn specs(&self) -> &[ToolSpec] { &self.specs }