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§
- Hygiene
Issue - 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_hygienewith explicit vendored globs (from.prbot.toml); an empty slice meansDEFAULT_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 toparse_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
pathlies inside vendored third-party code. - pack_
diff - Fit
diffwithinmax_charsby 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_diffthat 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
pathpasses the include/exclude glob filters — the per-path equivalent offilter_diff_by_globs, for callers that hold one path rather than a diff (e.g. the/review-filecommand). 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 atdiff --gitlines (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.