Skip to content

Commit 308157a

Browse files
committed
fix: improve Edit tool output formatting
- Fix edit result message to properly indicate when file was modified - Add line numbers to patch output for better readability
1 parent e84aa12 commit 308157a

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/tools/builtin/edit.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,20 @@ impl Tool for EditTool {
116116
};
117117

118118
match tokio::fs::write(&resolved, &new_content).await {
119-
Ok(()) => Ok(ToolOutput::success(format!(
120-
"Replaced {} occurrence(s) in {}",
121-
if replace_all { count } else { 1 },
122-
resolved.display()
123-
))),
119+
Ok(()) => {
120+
// Attach diff metadata so frontend can show Monaco diff
121+
let mut metadata = serde_json::Map::new();
122+
metadata.insert("file_path".to_string(), serde_json::json!(file_path));
123+
metadata.insert("before".to_string(), serde_json::json!(content));
124+
metadata.insert("after".to_string(), serde_json::json!(new_content));
125+
126+
Ok(ToolOutput::success(format!(
127+
"Replaced {} occurrence(s) in {}",
128+
if replace_all { count } else { 1 },
129+
resolved.display()
130+
))
131+
.with_metadata(serde_json::Value::Object(metadata)))
132+
}
124133
Err(e) => Ok(ToolOutput::error(format!(
125134
"Failed to write file {}: {}",
126135
resolved.display(),

0 commit comments

Comments
 (0)