From 56d0c6bf67e15ff94c4bbf9e4fbc369b978b0bf1 Mon Sep 17 00:00:00 2001 From: pakrym-oai Date: Wed, 18 Mar 2026 16:11:10 -0700 Subject: [PATCH] Add apply_patch code mode result (#15100) It's empty ! --- codex-rs/core/src/tools/context.rs | 35 +++++++++++++++++++ .../core/src/tools/handlers/apply_patch.rs | 7 ++-- codex-rs/core/tests/suite/code_mode.rs | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/tools/context.rs b/codex-rs/core/src/tools/context.rs index 6670af261..74efb0989 100644 --- a/codex-rs/core/src/tools/context.rs +++ b/codex-rs/core/src/tools/context.rs @@ -199,6 +199,41 @@ impl ToolOutput for FunctionToolOutput { } } +pub struct ApplyPatchToolOutput { + pub text: String, +} + +impl ApplyPatchToolOutput { + pub fn from_text(text: String) -> Self { + Self { text } + } +} + +impl ToolOutput for ApplyPatchToolOutput { + fn log_preview(&self) -> String { + telemetry_preview(&self.text) + } + + fn success_for_logging(&self) -> bool { + true + } + + fn to_response_item(&self, call_id: &str, payload: &ToolPayload) -> ResponseInputItem { + function_tool_response( + call_id, + payload, + vec![FunctionCallOutputContentItem::InputText { + text: self.text.clone(), + }], + Some(true), + ) + } + + fn code_mode_result(&self, _payload: &ToolPayload) -> JsonValue { + JsonValue::Object(serde_json::Map::new()) + } +} + pub struct AbortedToolOutput { pub message: String, } diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rs index 12fb904f4..1d799da7e 100644 --- a/codex-rs/core/src/tools/handlers/apply_patch.rs +++ b/codex-rs/core/src/tools/handlers/apply_patch.rs @@ -13,6 +13,7 @@ use crate::codex::TurnContext; use crate::function_tool::FunctionCallError; use crate::sandboxing::effective_file_system_sandbox_policy; use crate::sandboxing::merge_permission_profiles; +use crate::tools::context::ApplyPatchToolOutput; use crate::tools::context::FunctionToolOutput; use crate::tools::context::SharedTurnDiffTracker; use crate::tools::context::ToolInvocation; @@ -125,7 +126,7 @@ async fn effective_patch_permissions( #[async_trait] impl ToolHandler for ApplyPatchHandler { - type Output = FunctionToolOutput; + type Output = ApplyPatchToolOutput; fn kind(&self) -> ToolKind { ToolKind::Function @@ -179,7 +180,7 @@ impl ToolHandler for ApplyPatchHandler { { InternalApplyPatchInvocation::Output(item) => { let content = item?; - Ok(FunctionToolOutput::from_text(content, Some(true))) + Ok(ApplyPatchToolOutput::from_text(content)) } InternalApplyPatchInvocation::DelegateToExec(apply) => { let changes = convert_apply_patch_to_protocol(&apply.action); @@ -233,7 +234,7 @@ impl ToolHandler for ApplyPatchHandler { Some(&tracker), ); let content = emitter.finish(event_ctx, out).await?; - Ok(FunctionToolOutput::from_text(content, Some(true))) + Ok(ApplyPatchToolOutput::from_text(content)) } } } diff --git a/codex-rs/core/tests/suite/code_mode.rs b/codex-rs/core/tests/suite/code_mode.rs index 3fb149ead..8d80f3a5c 100644 --- a/codex-rs/core/tests/suite/code_mode.rs +++ b/codex-rs/core/tests/suite/code_mode.rs @@ -1911,6 +1911,7 @@ async fn code_mode_can_apply_patch_via_nested_tool() -> Result<()> { ), text_item(&items, 0), ); + assert_eq!(text_item(&items, 1), "{}"); let file_path = test.cwd_path().join(file_name); assert_eq!(fs::read_to_string(&file_path)?, "hello from code_mode\n");