Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codex-rs/core/src/session/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8770,7 +8770,7 @@ async fn rejects_escalated_permissions_when_policy_not_on_request() {
let tool_name = "shell";
let call_id = "test-call".to_string();

let handler = ShellHandler;
let handler = ShellHandler::default();
let resp = handler
.handle(ToolInvocation {
session: Arc::clone(&session),
Expand Down Expand Up @@ -8845,7 +8845,7 @@ async fn unified_exec_rejects_escalated_permissions_when_policy_not_on_request()
let turn_context = Arc::new(turn_context_raw);
let tracker = Arc::new(tokio::sync::Mutex::new(TurnDiffTracker::new()));

let handler = ExecCommandHandler;
let handler = ExecCommandHandler::default();
let resp = handler
.handle(ToolInvocation {
session: Arc::clone(&session),
Expand Down
8 changes: 4 additions & 4 deletions codex-rs/core/src/session/tests/guardian_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async fn guardian_allows_shell_additional_permissions_requests_past_policy_valid
arg0: None,
};

let handler = ShellHandler;
let handler = ShellHandler::default();
let resp = handler
.handle(ToolInvocation {
session: Arc::clone(&session),
Expand Down Expand Up @@ -437,7 +437,7 @@ async fn strict_auto_review_turn_grant_forces_guardian_for_shell_policy_skip() {
let session = Arc::new(session);
let turn_context = Arc::new(turn_context_raw);

let handler = ShellHandler;
let handler = ShellHandler::default();
let command = if cfg!(windows) {
vec![
"cmd.exe".to_string(),
Expand Down Expand Up @@ -498,7 +498,7 @@ async fn guardian_allows_unified_exec_additional_permissions_requests_past_polic
let turn_context = Arc::new(turn_context_raw);
let tracker = Arc::new(tokio::sync::Mutex::new(TurnDiffTracker::new()));

let handler = ExecCommandHandler;
let handler = ExecCommandHandler::default();
let resp = handler
.handle(ToolInvocation {
session: Arc::clone(&session),
Expand Down Expand Up @@ -615,7 +615,7 @@ async fn shell_handler_allows_sticky_turn_permissions_without_inline_request_per
let session = Arc::new(session);
let turn_context = Arc::new(turn_context_raw);

let handler = ShellHandler;
let handler = ShellHandler::default();
let resp = handler
.handle(ToolInvocation {
session: Arc::clone(&session),
Expand Down
13 changes: 12 additions & 1 deletion codex-rs/core/src/tools/code_mode/execute_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ use crate::tools::context::ToolPayload;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::ExecContext;
use super::PUBLIC_TOOL_NAME;
use super::build_enabled_tools;
use super::handle_runtime_response;
use super::is_exec_tool_name;

pub struct CodeModeExecuteHandler;
pub struct CodeModeExecuteHandler {
spec: ToolSpec,
}

impl CodeModeExecuteHandler {
pub(crate) fn new(spec: ToolSpec) -> Self {
Self { spec }
}

async fn execute(
&self,
session: std::sync::Arc<crate::session::session::Session>,
Expand Down Expand Up @@ -83,6 +90,10 @@ impl ToolHandler for CodeModeExecuteHandler {
ToolName::plain(PUBLIC_TOOL_NAME)
}

fn spec(&self) -> Option<ToolSpec> {
Some(self.spec.clone())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/core/src/tools/code_mode/wait_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use crate::tools::context::ToolPayload;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::DEFAULT_WAIT_YIELD_TIME_MS;
use super::ExecContext;
use super::WAIT_TOOL_NAME;
use super::handle_runtime_response;
use super::wait_spec::create_wait_tool;

pub struct CodeModeWaitHandler;

Expand Down Expand Up @@ -46,6 +48,10 @@ impl ToolHandler for CodeModeWaitHandler {
ToolName::plain(WAIT_TOOL_NAME)
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_wait_tool())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::function_tool::FunctionCallError;
use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::agent_jobs_spec::create_report_agent_job_result_tool;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::*;

Expand All @@ -17,6 +19,10 @@ impl ToolHandler for ReportAgentJobResultHandler {
ToolName::plain("report_agent_job_result")
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_report_agent_job_result_tool())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::function_tool::FunctionCallError;
use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::agent_jobs_spec::create_spawn_agents_on_csv_tool;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::*;

Expand All @@ -17,6 +19,10 @@ impl ToolHandler for SpawnAgentsOnCsvHandler {
ToolName::plain("spawn_agents_on_csv")
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_spawn_agents_on_csv_tool())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
31 changes: 30 additions & 1 deletion codex-rs/core/src/tools/handlers/apply_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::tools::events::ToolEmitter;
use crate::tools::events::ToolEventCtx;
use crate::tools::handlers::apply_granted_turn_permissions;
use crate::tools::handlers::apply_patch_spec::ApplyPatchToolArgs;
use crate::tools::handlers::apply_patch_spec::create_apply_patch_freeform_tool;
use crate::tools::handlers::apply_patch_spec::create_apply_patch_json_tool;
use crate::tools::handlers::parse_arguments;
use crate::tools::hook_names::HookToolName;
use crate::tools::orchestrator::ToolOrchestrator;
Expand All @@ -41,18 +43,38 @@ use codex_exec_server::ExecutorFileSystem;
use codex_features::Feature;
use codex_protocol::models::AdditionalPermissionProfile;
use codex_protocol::models::FileSystemPermissions;
use codex_protocol::openai_models::ApplyPatchToolType;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::FileChange;
use codex_protocol::protocol::PatchApplyUpdatedEvent;
use codex_sandboxing::policy_transforms::effective_file_system_sandbox_policy;
use codex_sandboxing::policy_transforms::merge_permission_profiles;
use codex_sandboxing::policy_transforms::normalize_additional_permissions;
use codex_tools::ToolName;
use codex_tools::ToolSpec;
use codex_utils_absolute_path::AbsolutePathBuf;

const APPLY_PATCH_ARGUMENT_DIFF_BUFFER_INTERVAL: Duration = Duration::from_millis(500);

pub struct ApplyPatchHandler;
pub struct ApplyPatchHandler {
options: ApplyPatchToolType,
}

impl Default for ApplyPatchHandler {
fn default() -> Self {
Self {
options: ApplyPatchToolType::Freeform,
}
}
}

impl ApplyPatchHandler {
pub(crate) fn new(apply_patch_tool_type: ApplyPatchToolType) -> Self {
Self {
options: apply_patch_tool_type,
}
}
}

#[derive(Default)]
struct ApplyPatchArgumentDiffConsumer {
Expand Down Expand Up @@ -297,6 +319,13 @@ impl ToolHandler for ApplyPatchHandler {
ToolName::plain("apply_patch")
}

fn spec(&self) -> Option<ToolSpec> {
Some(match self.options {
ApplyPatchToolType::Freeform => create_apply_patch_freeform_tool(),
ApplyPatchToolType::Function => create_apply_patch_json_tool(),
})
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
6 changes: 3 additions & 3 deletions codex-rs/core/src/tools/handlers/apply_patch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn pre_tool_use_payload_uses_json_patch_input() {
arguments: json!({ "input": patch }).to_string(),
};
let invocation = invocation_for_payload(payload).await;
let handler = ApplyPatchHandler;
let handler = ApplyPatchHandler::default();

assert_eq!(
handler.pre_tool_use_payload(&invocation),
Expand All @@ -67,7 +67,7 @@ async fn pre_tool_use_payload_uses_freeform_patch_input() {
input: patch.to_string(),
};
let invocation = invocation_for_payload(payload).await;
let handler = ApplyPatchHandler;
let handler = ApplyPatchHandler::default();

assert_eq!(
handler.pre_tool_use_payload(&invocation),
Expand All @@ -86,7 +86,7 @@ async fn post_tool_use_payload_uses_patch_input_and_tool_output() {
};
let invocation = invocation_for_payload(payload).await;
let output = ApplyPatchToolOutput::from_text("Success. Updated files.".to_string());
let handler = ApplyPatchHandler;
let handler = ApplyPatchHandler::default();

assert_eq!(
handler.post_tool_use_payload(&invocation, &output),
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/core/src/tools/handlers/goal/create_goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::goal_spec::CREATE_GOAL_TOOL_NAME;
use crate::tools::handlers::goal_spec::create_create_goal_tool;
use crate::tools::handlers::parse_arguments;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::CompletionBudgetReport;
use super::CreateGoalArgs;
Expand All @@ -23,6 +25,10 @@ impl ToolHandler for CreateGoalHandler {
ToolName::plain(CREATE_GOAL_TOOL_NAME)
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_create_goal_tool())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/core/src/tools/handlers/goal/get_goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::goal_spec::GET_GOAL_TOOL_NAME;
use crate::tools::handlers::goal_spec::create_get_goal_tool;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::CompletionBudgetReport;
use super::format_goal_error;
Expand All @@ -20,6 +22,10 @@ impl ToolHandler for GetGoalHandler {
ToolName::plain(GET_GOAL_TOOL_NAME)
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_get_goal_tool())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/core/src/tools/handlers/goal/update_goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::goal_spec::UPDATE_GOAL_TOOL_NAME;
use crate::tools::handlers::goal_spec::create_update_goal_tool;
use crate::tools::handlers::parse_arguments;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_protocol::protocol::ThreadGoalStatus;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use super::CompletionBudgetReport;
use super::UpdateGoalArgs;
Expand All @@ -25,6 +27,10 @@ impl ToolHandler for UpdateGoalHandler {
ToolName::plain(UPDATE_GOAL_TOOL_NAME)
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_update_goal_tool())
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use crate::function_tool::FunctionCallError;
use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::mcp_resource_spec::create_list_mcp_resource_templates_tool;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_protocol::models::function_call_output_content_items_to_text;
use codex_protocol::protocol::McpInvocation;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use rmcp::model::PaginatedRequestParams;

Expand All @@ -31,6 +33,14 @@ impl ToolHandler for ListMcpResourceTemplatesHandler {
ToolName::plain("list_mcp_resource_templates")
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_list_mcp_resource_templates_tool())
}

fn supports_parallel_tool_calls(&self) -> bool {
true
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use crate::function_tool::FunctionCallError;
use crate::tools::context::FunctionToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::handlers::mcp_resource_spec::create_list_mcp_resources_tool;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
use codex_protocol::models::function_call_output_content_items_to_text;
use codex_protocol::protocol::McpInvocation;
use codex_tools::ToolName;
use codex_tools::ToolSpec;

use rmcp::model::PaginatedRequestParams;

Expand All @@ -31,6 +33,14 @@ impl ToolHandler for ListMcpResourcesHandler {
ToolName::plain("list_mcp_resources")
}

fn spec(&self) -> Option<ToolSpec> {
Some(create_list_mcp_resources_tool())
}

fn supports_parallel_tool_calls(&self) -> bool {
true
}

fn kind(&self) -> ToolKind {
ToolKind::Function
}
Expand Down
Loading
Loading