Skip to main content

Module diff

Module diff 

Source
Expand description

Condensing patches: whole hunks, or none of them.

§Why a truncated diff is worse than no diff

Every other slicer here drops information the model can tell is missing. A diff cut at an arbitrary byte does not: it produces something that parses, reads as complete, and describes a change that was never made. A model shown the first half of a hunk sees a deletion with no corresponding insertion and concludes the code was removed.

So this slicer never cuts a hunk. Everything it does is at hunk granularity or coarser, and what it drops it names.

§The order things are given up

  1. Nothing. If the whole patch fits, it is kept whole.
  2. Context lines. The unchanged lines around each change are the cheapest thing to lose and the least informative — the changed lines are still there, and the file is still named. Trimmed symmetrically, three lines to two to one to none.
  3. Whole hunks, from the end of the patch backwards.

Context goes before hunks because a change with no surrounding context is still a true statement about the patch, whereas a missing hunk is a change the model cannot see at all. Which hunks matter is explicitly out of scope (US-0704), so the order is positional and predictable rather than clever.

§The file list always survives

Even a file whose every hunk was dropped keeps its entry, its status, and its +n/-m counts. That is the difference between “this patch did not touch auth.rs” and “you were not shown what it did to auth.rs” — and a review agent that cannot tell those apart is worse than useless.

§Binary files are summarised, never inlined

A binary patch is megabytes of base85 that no model can read and every model will happily spend a context window on. It becomes one line.

Structs§

DiffSlicer
Condenses unified diffs.
FileDiff
One file’s worth of a patch.
Hunk
One hunk of one file’s diff.

Enums§

FileStatus
What happened to a file.

Constants§

DIFF_SCHEMA
The schema a diff condensate declares.