Fix write_file compact summary to show actual line/char counts
The write_file compact display was showing 1 line because it was
counting lines in the success message, not the actual written content.
Now parses the tool result (e.g. '✅ wrote 150 lines | 4.2k chars')
to extract and display the correct counts.
Added format_write_file_result() to parse the tool output.
This commit is contained in:
@@ -2204,9 +2204,9 @@ impl<W: UiWriter> Agent<W> {
|
||||
match tool_call.tool.as_str() {
|
||||
"read_file" => Some(streaming::format_read_file_summary(output_len, tool_result.len())),
|
||||
"write_file" => {
|
||||
// Parse the result to get line/char counts
|
||||
// Result format: "✅ +N insertions | -M deletions" or similar
|
||||
Some(streaming::format_write_file_summary(output_len, tool_result.len()))
|
||||
// The tool result already contains the formatted summary
|
||||
// Format: "✅ wrote N lines | M chars"
|
||||
Some(streaming::format_write_file_result(&tool_result))
|
||||
}
|
||||
"str_replace" => {
|
||||
// Parse insertions/deletions from result
|
||||
|
||||
@@ -302,6 +302,23 @@ pub fn format_write_file_summary(line_count: usize, char_count: usize) -> String
|
||||
format!("✏️ {} lines ({} chars)", line_count, char_display)
|
||||
}
|
||||
|
||||
/// Format a write_file result for compact display.
|
||||
/// Parses the tool result which is in format: "✅ wrote N lines | M chars"
|
||||
/// Returns a compact summary like "✏️ N lines (M chars)"
|
||||
pub fn format_write_file_result(tool_result: &str) -> String {
|
||||
// Parse "✅ wrote N lines | M chars" or "✅ wrote N lines | M.Mk chars"
|
||||
if let Some(rest) = tool_result.strip_prefix("✅ wrote ") {
|
||||
// rest is "N lines | M chars" or "N lines | M.Mk chars"
|
||||
if let Some((lines_part, chars_part)) = rest.split_once(" | ") {
|
||||
let lines = lines_part.trim_end_matches(" lines");
|
||||
let chars = chars_part.trim_end_matches(" chars");
|
||||
return format!("✏️ {} lines ({} chars)", lines, chars);
|
||||
}
|
||||
}
|
||||
// Fallback: return the original result if parsing fails
|
||||
tool_result.to_string()
|
||||
}
|
||||
|
||||
/// Format a str_replace result summary.
|
||||
pub fn format_str_replace_summary(insertions: i32, deletions: i32) -> String {
|
||||
if insertions > 0 && deletions > 0 {
|
||||
|
||||
Reference in New Issue
Block a user