Skip to main content

Module diff

Module diff 

Source
Expand description

Minimal unified-diff parser. Produces the set of line numbers (on the new side of each file) that appear in the diff, so we only anchor inline comments to lines the provider will accept — anchoring outside the diff is rejected (GitHub 422 / Bitbucket 400).

Structs§

HygieneIssue
A deterministic “diff-hygiene” issue: a property of the change set (not the code) worth flagging without an LLM — a binary swept into a commit, an oversized generated file. Reviewer-coverage class D: cheaper, zero-variance, and it cannot hallucinate, so it’s strictly better than asking the model.

Constants§

DEFAULT_VENDORED_DIRS
Path segments that conventionally hold third-party source. Committing code in bulk under one of these is the intended act of vendoring, not a hygiene defect, so class-D checks are suppressed inside them.

Functions§

diff_hygiene
Scan a raw unified diff for deterministic diff-hygiene issues (class D). Targets added files only — the change-set hazards a normal diff view hides. No model, no clone; runs on the raw diff so a file filtered out of the review is still seen.
diff_hygiene_with
diff_hygiene with explicit vendored globs (from .prbot.toml); an empty slice means DEFAULT_VENDORED_DIRS.
diff_line_texts
Map each new-side file path to { line number -> line text } (added or context lines, the leading +/space stripped), for the new version of the file. The content companion to parse_valid_lines, used to confirm a re-anchor by matching a finding to what’s actually on a nearby diff line.
filter_diff_by_globs
Drop per-file sections of a unified diff that don’t pass the include/exclude glob filters — removing lockfiles, generated, vendored, and minified files before the diff is sent to the LLM (saves tokens and noise).
is_vendored
Whether path lies inside vendored third-party code.
pack_diff
Fit diff within max_chars by keeping whole file sections, dropping the lowest-priority files first. Returns (packed_diff, dropped_paths). If the diff already fits, returns it unchanged with an empty dropped list.
pack_diff_bundled
pack_diff that keeps related files together: a source and its test, or i18n siblings, pack as one unit and stay adjacent, instead of being scattered by priority. Falls back to keeping a unit’s highest-priority members when the whole unit can’t fit, so a big source is never dropped just because its test pushed the bundle over budget.
parse_valid_lines
Map each new-side file path to the set of line numbers present in the diff (added or context lines). Removed lines don’t advance the new-side counter.
path_matches_globs
Whether a single path passes the include/exclude glob filters — the per-path equivalent of filter_diff_by_globs, for callers that hold one path rather than a diff (e.g. the /review-file command). Fails open: an invalid glob in either set means “allow” rather than silently blocking the review.
split_diff_sections
Split a unified diff into per-file sections, returning (path, section_text) for each. Sections start at diff --git lines (primary) or, when the diff carries no git headers, at the --- line preceding each +++ marker (or the +++ line itself). This is the same splitting the glob filter and the size packer both build on.