From 1b051aad9472c6d277a928b5d5043ca367dbc5f7 Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Mon, 12 Jan 2026 20:32:54 +0530 Subject: [PATCH] Fix write_file compact summary to show actual line/char counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- crates/g3-core/src/lib.rs | 6 +++--- crates/g3-core/src/streaming.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/g3-core/src/lib.rs b/crates/g3-core/src/lib.rs index 1615211..9451bec 100644 --- a/crates/g3-core/src/lib.rs +++ b/crates/g3-core/src/lib.rs @@ -2204,9 +2204,9 @@ impl Agent { 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 diff --git a/crates/g3-core/src/streaming.rs b/crates/g3-core/src/streaming.rs index 3b03a33..72bd0e6 100644 --- a/crates/g3-core/src/streaming.rs +++ b/crates/g3-core/src/streaming.rs @@ -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 {