From fe07766daeb5b94e87ac7700058cb70768f18cd7 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Sat, 4 Oct 2025 00:20:10 -0700 Subject: [PATCH] clippy --- codex-rs/core/src/codex.rs | 31 ++++++++-------- .../core/src/tools/handlers/apply_patch.rs | 19 +++++----- codex-rs/core/src/tools/handlers/shell.rs | 37 ++++++++++--------- codex-rs/core/src/tools/mod.rs | 32 +++++++++++----- 4 files changed, 68 insertions(+), 51 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 79cd265c93..b9d7bcc6d4 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -2401,6 +2401,7 @@ mod tests { use crate::tasks::SessionTask; use crate::tasks::SessionTaskContext; use crate::tools::ExecResponseFormat; + use crate::tools::HandleExecRequest; use crate::tools::MODEL_FORMAT_HEAD_LINES; use crate::tools::MODEL_FORMAT_MAX_BYTES; use crate::tools::MODEL_FORMAT_MAX_LINES; @@ -3082,16 +3083,16 @@ mod tests { let sub_id = "test-sub".to_string(); let call_id = "test-call".to_string(); - let resp = handle_container_exec_with_params( + let resp = handle_container_exec_with_params(HandleExecRequest { tool_name, params, - &session, - &turn_context, - &mut turn_diff_tracker, + sess: &session, + turn_context: &turn_context, + turn_diff_tracker: &mut turn_diff_tracker, sub_id, call_id, - ExecResponseFormat::LegacyJson, - ) + response_format: ExecResponseFormat::LegacyJson, + }) .await; let Err(FunctionCallError::RespondToModel(output)) = resp else { @@ -3109,16 +3110,16 @@ mod tests { // Force DangerFullAccess to avoid platform sandbox dependencies in tests. turn_context.sandbox_policy = SandboxPolicy::DangerFullAccess; - let resp2 = handle_container_exec_with_params( + let resp2 = handle_container_exec_with_params(HandleExecRequest { tool_name, - params2, - &session, - &turn_context, - &mut turn_diff_tracker, - "test-sub".to_string(), - "test-call-2".to_string(), - ExecResponseFormat::LegacyJson, - ) + params: params2, + sess: &session, + turn_context: &turn_context, + turn_diff_tracker: &mut turn_diff_tracker, + sub_id: "test-sub".to_string(), + call_id: "test-call-2".to_string(), + response_format: ExecResponseFormat::LegacyJson, + }) .await; let output = resp2.expect("expected Ok result"); diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rs index 10221ae0af..05147ba66d 100644 --- a/codex-rs/core/src/tools/handlers/apply_patch.rs +++ b/codex-rs/core/src/tools/handlers/apply_patch.rs @@ -9,6 +9,7 @@ use crate::exec::ExecParams; use crate::function_tool::FunctionCallError; use crate::openai_tools::JsonSchema; use crate::tools::ExecResponseFormat; +use crate::tools::HandleExecRequest; use crate::tools::context::ToolInvocation; use crate::tools::context::ToolOutput; use crate::tools::context::ToolPayload; @@ -77,16 +78,16 @@ impl ToolHandler for ApplyPatchHandler { justification: None, }; - let content = handle_container_exec_with_params( - tool_name.as_str(), - exec_params, - session, - turn, - tracker, - sub_id.to_string(), - call_id.clone(), + let content = handle_container_exec_with_params(HandleExecRequest { + tool_name: tool_name.as_str(), + params: exec_params, + sess: session, + turn_context: turn, + turn_diff_tracker: tracker, + sub_id: sub_id.to_string(), + call_id: call_id.clone(), response_format, - ) + }) .await?; Ok(ToolOutput::Function { diff --git a/codex-rs/core/src/tools/handlers/shell.rs b/codex-rs/core/src/tools/handlers/shell.rs index 1614a267fb..c54cfc0f8d 100644 --- a/codex-rs/core/src/tools/handlers/shell.rs +++ b/codex-rs/core/src/tools/handlers/shell.rs @@ -6,6 +6,7 @@ use crate::exec::ExecParams; use crate::exec_env::create_env; use crate::function_tool::FunctionCallError; use crate::tools::ExecResponseFormat; +use crate::tools::HandleExecRequest; use crate::tools::context::ToolInvocation; use crate::tools::context::ToolOutput; use crate::tools::context::ToolPayload; @@ -73,16 +74,16 @@ impl ToolHandler for ShellHandler { )) })?; let exec_params = Self::to_exec_params(params, turn); - let content = handle_container_exec_with_params( - tool_name.as_str(), - exec_params, - session, - turn, - tracker, - sub_id.to_string(), - call_id.clone(), + let content = handle_container_exec_with_params(HandleExecRequest { + tool_name: tool_name.as_str(), + params: exec_params, + sess: session, + turn_context: turn, + turn_diff_tracker: tracker, + sub_id: sub_id.to_string(), + call_id: call_id.clone(), response_format, - ) + }) .await?; Ok(ToolOutput::Function { content, @@ -91,16 +92,16 @@ impl ToolHandler for ShellHandler { } ToolPayload::LocalShell { params } => { let exec_params = Self::to_exec_params(params, turn); - let content = handle_container_exec_with_params( - tool_name.as_str(), - exec_params, - session, - turn, - tracker, - sub_id.to_string(), - call_id.clone(), + let content = handle_container_exec_with_params(HandleExecRequest { + tool_name: tool_name.as_str(), + params: exec_params, + sess: session, + turn_context: turn, + turn_diff_tracker: tracker, + sub_id: sub_id.to_string(), + call_id: call_id.clone(), response_format, - ) + }) .await?; Ok(ToolOutput::Function { content, diff --git a/codex-rs/core/src/tools/mod.rs b/codex-rs/core/src/tools/mod.rs index c8313ecf30..4b93c4ce9e 100644 --- a/codex-rs/core/src/tools/mod.rs +++ b/codex-rs/core/src/tools/mod.rs @@ -51,16 +51,30 @@ pub(crate) enum ExecResponseFormat { } // TODO(jif) break this down +pub(crate) struct HandleExecRequest<'a> { + pub tool_name: &'a str, + pub params: ExecParams, + pub sess: &'a Session, + pub turn_context: &'a TurnContext, + pub turn_diff_tracker: &'a mut TurnDiffTracker, + pub sub_id: String, + pub call_id: String, + pub response_format: ExecResponseFormat, +} + pub(crate) async fn handle_container_exec_with_params( - tool_name: &str, - params: ExecParams, - sess: &Session, - turn_context: &TurnContext, - turn_diff_tracker: &mut TurnDiffTracker, - sub_id: String, - call_id: String, - response_format: ExecResponseFormat, + request: HandleExecRequest<'_>, ) -> Result { + let HandleExecRequest { + tool_name, + params, + sess, + turn_context, + turn_diff_tracker, + sub_id, + call_id, + response_format, + } = request; let otel_event_manager = turn_context.client.get_otel_event_manager(); if params.with_escalated_permissions.unwrap_or(false) @@ -228,7 +242,7 @@ fn format_unexpected_exec_error(err: CodexErr, response_format: ExecResponseForm } fn format_structured_error(message: &str) -> String { - let lines = vec![ + let lines = [ "Exit code: N/A".to_string(), "Wall time: N/A seconds".to_string(), format!("Error: {message}"),