From 76b19d889ee06271c223e212571e04f242c3c043 Mon Sep 17 00:00:00 2001 From: Chris Buetti Date: Thu, 26 Mar 2026 16:44:58 +0100 Subject: [PATCH] Limit diff output to 55,000 characters Limit the diff output to 55,000 characters and add a message indicating truncation. --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4f11f36..776c7b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,6 +110,21 @@ async fn main() -> Result<(), ()> { .stdout; let output = str::from_utf8(&output).unwrap(); + // 16,385 token context minus 2,000 for completion and ~500 for system/function overhead. + // At ~4 chars/token, that's roughly 55,000 chars of diff we can safely include. + const MAX_DIFF_CHARS: usize = 55_000; + let output = if output.len() > MAX_DIFF_CHARS { + let truncated = &output[..output[..MAX_DIFF_CHARS].rfind('\n').unwrap_or(MAX_DIFF_CHARS)]; + format!( + "{}\n\n[diff truncated — {}/{} bytes shown]", + truncated, + truncated.len(), + output.len() + ) + } else { + output.to_string() + }; + if !cli.dry_run { info!("Loading Data..."); }