Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Add apply_patch code mode result (#15100)

pakrym-oai56d0c6bf67e1
diff --git a/codex-rs/core/src/tools/context.rs b/codex-rs/core/src/tools/context.rs
index 6670af2613..74efb0989b 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 12fb904f4d..1d799da7e7 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 3fb149eadf..8d80f3a5cc 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");