Documentation
¶
Overview ¶
Package diff parses unified diffs into a structured DiffFile model and maps (file, post-image line) pairs back to added, modified, context, or out-of-hunk locations.
Parsing delegates to sourcegraph/go-diff (ADR 0006); this package adds classification, line-position bookkeeping, and the validator-facing Index.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiffFile ¶
DiffFile is one changed file extracted from a unified diff.
Path holds the post-change path (per the schema: findings address files by their post-change path). OldPath is set when Kind is a rename variant.
type FileKind ¶
type FileKind int
FileKind classifies a changed file for prompt construction. The provider adapter uses this to decide what reaches the model.
const ( // FileText is a text file with reviewable hunks. Include in prompt. FileText FileKind = iota // FileRenameWithHunks was renamed and also modified. Include under // the post-rename path; preserve the old path as metadata. FileRenameWithHunks // FilePureRename was renamed without content changes. Metadata only. FilePureRename // FileDelete was deleted. Metadata only by default; the v1 schema does // not accept deleted-line comments. FileDelete // FileBinary is a binary file change. Metadata only; unsupported by // the model prompt. FileBinary // FileModeOnly changed file mode without content changes. Metadata only. FileModeOnly )
func (FileKind) IncludeInPrompt ¶
IncludeInPrompt reports whether this file's hunks should reach the model. Mirrors the classification rule in docs/provider-adapters.md § Diff Edge Cases.
type Hunk ¶
Hunk is one contiguous block of changes within a file, corresponding to a `@@ -a,b +c,d @@` section of the unified diff.
Lines are kept in source order; each carries its post-image line number (zero for deleted lines, which have no post-image position).
type HunkLine ¶
type HunkLine struct {
Side LineSide
NewLine int // post-image line number; zero when Side == LineDeleted
Content string // line content, without the leading +/-/space marker
}
HunkLine is one line within a hunk.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index answers (file, post-image line) → LineClassification queries against a parsed set of DiffFiles. The validator uses it to enforce the v1 schema invariant that findings target only added or modified lines.
func NewIndex ¶
NewIndex builds an Index from a parsed diff. Files whose Kind excludes them from the prompt (binary, mode-only, pure-rename, delete) are kept in the index so callers can still distinguish "not in diff" from "in diff but unaddressable"; this distinction matters in M3 when reporting why a finding was quarantined.
type LineClassification ¶
type LineClassification int
LineClassification labels what a post-image line number resolves to in a changed file. The validator uses this to enforce the v1 finding schema invariant: only added/modified lines are valid finding targets.
const ( // LineAdded is a brand-new line introduced by the diff (a "+" line in // a hunk where the deleted counterpart, if any, is absent). LineAdded LineClassification = iota // LineModified is an added line that replaces a deleted line in the // same hunk position. Distinguished from LineAdded so the TUI can // render edit highlights differently in M4. LineModified // LineContext is an unchanged context line shown for surrounding // readability. The v1 finding schema disallows context-line comments, // so the validator quarantines findings landing here. LineContext // LineOutsideHunk is a line number that falls outside every hunk in // the file. The schema disallows comments here; quarantine. LineOutsideHunk // LineFileNotFound is returned when the file isn't part of the diff // at all, or has a kind that excludes it from prompting. LineFileNotFound )