From 77fd3134c3f8466c83a3f693e8b90ac612f9ccf4 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 8 Mar 2026 01:16:11 -0500 Subject: [PATCH] Use format_lines_numbered in format_patch_error to avoid duplicating line numbering logic Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/arc-agent/src/v4a_patch.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/arc-agent/src/v4a_patch.rs b/crates/arc-agent/src/v4a_patch.rs index a192c8f82..a2276009d 100644 --- a/crates/arc-agent/src/v4a_patch.rs +++ b/crates/arc-agent/src/v4a_patch.rs @@ -1,4 +1,4 @@ -use crate::sandbox::Sandbox; +use crate::sandbox::{format_lines_numbered, Sandbox}; use crate::tool_registry::RegisteredTool; use crate::truncation::{truncate_output, TruncationMode}; use arc_llm::types::ToolDefinition; @@ -244,12 +244,7 @@ fn apply_hunks(content: &str, hunks: &[Hunk]) -> Result { } fn format_patch_error(error: &str, path: &str, content: &str) -> String { - let numbered: String = content - .lines() - .enumerate() - .map(|(i, line)| format!("{}|{}", i + 1, line)) - .collect::>() - .join("\n"); + let numbered = format_lines_numbered(content, None, None); let truncated = truncate_output(&numbered, 9_000, TruncationMode::HeadTail); format!("{error}\n\nCurrent contents of {path}:\n{truncated}") } @@ -670,9 +665,9 @@ mod tests { ); assert!(result.contains("Could not find context line in file: 'fn missing()'")); assert!(result.contains("Current contents of src/lib.rs:")); - assert!(result.contains("1|fn hello() {")); - assert!(result.contains("2| println!(\"hi\");")); - assert!(result.contains("3|}")); + assert!(result.contains("1 | fn hello() {")); + assert!(result.contains("2 | println!(\"hi\");")); + assert!(result.contains("3 | }")); } #[test] @@ -709,6 +704,6 @@ mod tests { let err = apply_patch_operations(&ops, &env).await.unwrap_err(); assert!(err.contains("Could not find context line")); assert!(err.contains("Current contents of src/game.py:")); - assert!(err.contains("1|def real_fn():")); + assert!(err.contains("1 | def real_fn():")); } }