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
35 changes: 35 additions & 0 deletions codex-rs/core/src/tools/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
7 changes: 4 additions & 3 deletions codex-rs/core/src/tools/handlers/apply_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions codex-rs/core/tests/suite/code_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,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");
Expand Down
Loading