diff

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package diff provides shared primitives for parsing and shaping unified git diffs before they are embedded in an AI review prompt. The helpers here are consumed by both the Warden (code review) and Assay stages so the diff size cap, auto-generated file filtering, and changed-file extraction behave identically across stages.

Index

Constants

View Source
const MaxBytes = 250000

MaxBytes limits the diff size passed to a review prompt. Sized to cover real EF Core migration diffs (~138KB observed) with headroom for larger schemas while still keeping the review prompt comfortably within a single-turn budget. Auto-generated files are filtered out before this cap is applied, so most diffs stay well under the limit.

Variables

View Source
var AutoGeneratedPatterns = []string{
	"**/Migrations/*.Designer.cs",
	"**/Migrations/*ModelSnapshot.cs",
}

AutoGeneratedPatterns is the default list of glob patterns (doublestar syntax) for auto-generated files whose diff hunks are dropped before the review. These snapshots mirror the entire model and are not human-reviewable; leaving them in the diff either triggers truncation or leads the reviewer to misread the bulk as unrelated schema changes and reject on scope drift.

Functions

func ChangedFiles

func ChangedFiles(diff string) []string

ChangedFiles extracts the b-side file paths from a unified diff. Returns nil when the diff has no "diff --git" headers. ParseGitPath is reused so renames and a/ b/ paths with spaces behave the same here as in the diff-filter pre-truncation pass.

Uses bufio.Scanner to avoid allocating a full slice of every line in a potentially large diff.

func FilterAutoGenerated

func FilterAutoGenerated(diff string, patterns []string) (string, []string)

FilterAutoGenerated drops git-diff hunks whose file path matches any of the given doublestar glob patterns. Returns the filtered diff and the list of elided file paths (in the order they appeared).

The parser scans for "diff --git " block boundaries using strings.Index so it never materialises a []string of all lines — important for multi-MB diffs that are processed before the truncation cap is applied. When patterns is empty or the input contains no "diff --git" headers, the diff is returned unchanged.

func MatchesAnyPattern

func MatchesAnyPattern(path string, patterns []string) bool

MatchesAnyPattern returns true when path matches any of the doublestar glob patterns. Invalid patterns are skipped silently (they never match) so a bad entry cannot accidentally elide every file.

func ParseGitPath

func ParseGitPath(header string) string

ParseGitPath extracts the b-side file path from a git diff header line of the form "diff --git a/<path> b/<path>". Returns "" if the header cannot be parsed. The b-side path is preferred because it reflects the file's post-change name (renames show the new path).

func Truncate

func Truncate(diff string, maxLen int) string

Truncate limits the diff size to avoid token overflow.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL