Skip to main content

chunk_diff

Function chunk_diff 

Source
pub fn chunk_diff(diff: &str, max_tokens: usize) -> String
Expand description

Performs multi-level diff chunking for large diffs.

This function implements a three-tier approach to chunking:

  1. File-level merging: Greedily combine entire file diffs until token limit
  2. Hunk-level splitting: If a single file is too large, split by hunks
  3. Line-level splitting: For extremely large hunks, split by lines

§Arguments

  • diff - The full git diff string
  • max_tokens - Maximum tokens allowed per chunk (prompt overhead will be subtracted)

§Returns

A single string containing the chunked diff, with separators between chunks