Move read_file metadata to end of output

Change read_file output format so the "🔍 N lines read" appears as
the last line after the file content, not before it. This keeps the
output cleaner with just one metadata line at the end.
This commit is contained in:
Dhanji R. Prasanna
2026-01-11 19:56:23 +05:30
parent ed1c31dd70
commit da63e79a13

View File

@@ -104,11 +104,8 @@ pub async fn execute_read_file<W: UiWriter>(
let fallback_content = &content[fallback_start..]; let fallback_content = &content[fallback_start..];
let line_count = fallback_content.lines().count(); let line_count = fallback_content.lines().count();
return Ok(format!( return Ok(format!(
"⚠️ Start position {} exceeds file length {}. Reading last {} chars instead.\n\ "{}\n🔍 {} lines read (start {} exceeded length {}, showing last {} chars)",
🔍 {} lines read (chars {}-{}):\n{}", fallback_content, line_count, user_start, total_file_len, total_file_len - fallback_start
user_start, total_file_len,
total_file_len - fallback_start,
line_count, fallback_start, total_file_len, fallback_content
)); ));
} }
@@ -164,18 +161,16 @@ pub async fn execute_read_file<W: UiWriter>(
// Token-aware truncation header // Token-aware truncation header
let context_pct = (ctx.context_used_tokens as f32 / ctx.context_total_tokens as f32 * 100.0) as u32; let context_pct = (ctx.context_used_tokens as f32 / ctx.context_total_tokens as f32 * 100.0) as u32;
Ok(format!( Ok(format!(
"⚠️ TRUNCATED: chars {}-{} of {} (exceeds 20% context, at {}%)\n\ "{}\n🔍 {} lines read (truncated, chars {}-{} of {}, context {}%)",
🔍 {} lines read:\n{}", partial_content, line_count, start_boundary, end_boundary, total_file_len, context_pct
start_boundary, end_boundary, total_file_len, context_pct,
line_count, partial_content
)) ))
} else if start_char.is_some() || end_char.is_some() { } else if start_char.is_some() || end_char.is_some() {
Ok(format!( Ok(format!(
"🔍 {} lines read (chars {}-{}):\n{}", "{}\n🔍 {} lines read (chars {}-{})",
line_count, start_boundary, end_boundary, partial_content partial_content, line_count, start_boundary, end_boundary
)) ))
} else { } else {
Ok(format!("🔍 {} lines read:\n{}", line_count, content)) Ok(format!("{}\n🔍 {} lines read", content, line_count))
} }
} }
Err(e) => Ok(format!("❌ Failed to read file '{}': {}", path_str, e)), Err(e) => Ok(format!("❌ Failed to read file '{}': {}", path_str, e)),