feat(review): give the AI finder the repo's review instructions from the base branch

RA
5d ago
+2081-33

Issue for this PR

Part of #1792

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Stacked on feat/review-finder-defects. The second of three PRs that bring the AI lane to the measured configuration.

What changed

  • conventions.ts reads the repo's own review instructions from the base commit, so a PR cannot change the rules it is reviewed under. It reads:
    • .altimate/review.md (or .altimate/REVIEW.md), REVIEW.md, AGENTS.md, CLAUDE.md and .claude/CLAUDE.md, at the root and in each directory above a file the review covers (the project's changed files and the outside-project Python files its AI lane may take), so a dbt project's own .altimate/review.md applies to it
    • .cursor/rules/*.mdc (by glob or alwaysApply; manual rules with neither are skipped; frontmatter parsed as YAML, with a line reader for Cursor's unquoted globs) and .cursorrules
    • .github/copilot-instructions.md
    • .coderabbit.yaml path_instructions and the document-level tone_instructions (reviews.tone_instructions as a fallback)
    • the dbt/SQL/test sections of CONTRIBUTING.md
  • Base-commit reads fail loudly. A path absent at the base commit is skipped; a git failure reading or listing that commit fails the review, as the base-policy read of the same commit does, instead of passing for "no conventions". The base tree is listed once (git ls-tree -r -z), so unusual rule file names load, and only paths it holds are read, at most 8 git show calls at a time. Symlinks at the base commit are skipped (git would return the target's name).
  • Credential screen. An instruction file that holds a private key or a service-account key (holdsCredentials, the screen every other AI-lane input goes through) is skipped before it is parsed, so it never reaches the model. In the others, credentials are redacted with high-precision patterns only: provider-prefixed tokens, AWS key ids, URL userinfo with a password, and secret-named settings whose value looks like a credential. Ordinary guidance (env_var('DBT_PASSWORD') examples, "basic tests", md5 examples) is left as written.
  • A TEAM CONVENTIONS section in each finder call. It holds the conventions that apply to that call's files, most specific first, within 3,000 characters for the whole section, heading included. The finder names the convention's path in the comment body. The core 0.9 output has no cites field yet; once core 0.10 adds it, it applies here.
  • One comment per convention. AI findings that name the same convention for the same issue (same category, same title without the file's own names) on several files get one inline comment on a lead, picked by severity, then path and line, which lists the others. The folded findings stay in the envelope (groupedInto: <lead id>, with their own lines, for SARIF, audit and replay); the renderer shows them through the lead, whose comment carries their markers, but only when this run posts the lead inline: a lead over the inline budget, or a summary rendered without inline comments (CLI, agent tool, the 422 fallback), lists each folded finding on its own. Once the lead is on the PR, a finding newly folded into it is posted on its own, and a finding already on the PR is never folded again (so a lead picked anew on a later push does not re-list it). The lead's "same applies" line names only the findings actually folded. The list of folded files is added after the body clamp, so a long lead body cannot cut it; a repeat-merged comment keeps groupedInto only when all its members share it, and findings folded into a merged lead follow it to the merged id. Only one finding per other file is folded in; further findings on the same file may be distinct issues and stay. Replay mode (ALTIMATE_REVIEW_AI_REPLAY) records and groups the same way.
  • Verifier evidence. The verifier's read_file serves a convention file's base-branch text, so a PR's edit to a CLAUDE.md cannot be used to refute a finding based on the base convention.
  • Switch: conventions, on by default with the AI lane. ai.conventions: false or ALTIMATE_REVIEW_CONVENTIONS=0 turns it off. When off, nothing is loaded and the finder's messages are byte-identical to before.
  • Envelope: ai.conventions[] records path, source, scope, globs and size, but not the text; under --all-projects it is the union over the projects. ai.input[].conventions is set on the first file of each call that carried any.
  • Overlap with #1774. This becomes the only reader of repo instructions: it covers every file #1774's loadRepoInstructions reads. When #1774 is rebased onto this PR, that commit can be dropped.

Results

The measured configuration included conventions together with the other two PRs. AI and rule comments were counted together.

  • On 46 public dbt PRs: 526 real bugs against CodeRabbit's 437, with 10% wrong comments against 14%.
  • On 90 fresh public dbt PRs, counting distinct real bugs on the PRs each bot also reviewed:
    • us 125, CodeRabbit 93
    • us 227, Copilot 76
    • us 189, Cursor Bugbot 56

Conventions were not measured on their own.

The measured build deleted folded convention findings, searched for scoped files above every PR path (now only above the files the review covers), cut a long convention to the whole call budget (now half while others follow), and had no credential screen or symlink skip. Those changes can change which conventions a call carries on some PRs; the measurement was not rerun.

How did you verify your code works?

  • bun test test/altimate/review (packages/opencode): 1092 pass, 0 fail.
  • bun run typecheck (packages/opencode, tsgo --noEmit): clean.
  • New tests cover:
    • the loader: parsing, scoping and budget, and reading from the base commit over git
    • off identity under the plain, coverage and focused input modes
    • per-call placement and the envelope record
    • grouping of the same convention across files, keeping distinct same-file findings, and in replay mode
    • git failures rejecting rather than dropping conventions; a non-ASCII rule name over git
    • reviewPullRequest end to end under the AI dry run: a base-branch CLAUDE.md is used and the PR's edit to it is ignored

Cost side effects

  • No new model calls, warehouse queries or cloud resources.
  • When the AI lane is on and the repo has review instructions, each finder call carries at most 3,000 extra characters of conventions (about 750 input tokens).
  • Reading the files is one git ls-tree listing and a git show per instruction file that exists at the base commit, at most 8 at a time.
  • ai.conventions: false or ALTIMATE_REVIEW_CONVENTIONS=0 turns it off.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

šŸ¤– Generated with Claude Code