Documentation
¶
Overview ¶
Package diff computes a line-level diff between two versions of a file and renders it as a unified diff, with added/removed line counts. It is a pure, dependency-free leaf package: the writer tools use it to preview a pending change (the new content a write_file / edit_file / multi_edit would produce) without touching disk, so a front-end can show an approval card or a changed-files panel before the call runs.
The line diff uses Myers' O(ND) algorithm — the same shortest-edit-script approach git uses — so the hunks read the way a developer expects rather than a naive longest-common-subsequence walk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Path string `json:"path"`
Kind Kind `json:"kind"`
OldText string `json:"old_text"`
NewText string `json:"new_text"`
Added int `json:"added"` // lines present in new but not old
Removed int `json:"removed"` // lines present in old but not new
Diff string `json:"diff"` // unified diff; "" when Binary
Binary bool `json:"binary"`
}
Change is a previewed (not-yet-applied) edit to one file: the before/after text, the unified diff between them, and the line tallies a UI shows as "+N / -M". Binary is set when either side looks non-textual, in which case Diff is left empty (a byte-diff would be noise).