Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
129469a
feat(review): give the AI finder the repo's review instructions from …
RaghwendraSingh Nov 24, 2026
de2c6b0
fix(review): one comment for a convention broken the same way on seve…
RaghwendraSingh Nov 24, 2026
e7245fd
fix(review): team conventions fail loudly on git errors and read ever…
RaghwendraSingh Nov 25, 2026
f6d334a
fix(review): convention grouping keeps distinct same-file findings; r…
RaghwendraSingh Nov 25, 2026
61f83ad
fix(review): convention grouping keeps folded findings in the envelope
RaghwendraSingh Nov 27, 2026
aa82045
fix(review): harden the team-conventions loader
RaghwendraSingh Nov 27, 2026
4db0ce7
fix(review): the verifier reads base-branch convention text; the mult…
RaghwendraSingh Nov 27, 2026
6a0b0dc
fix(review): conventions docs and comments match the behaviour
RaghwendraSingh Nov 27, 2026
c39a276
fix(review): folded convention findings survive a long lead body and …
RaghwendraSingh Nov 27, 2026
09cd3ba
fix(review): redact tokens and passwords in team convention text
RaghwendraSingh Nov 27, 2026
0a8a6fb
fix(review): one `git ls-tree` for the convention loader's files and …
RaghwendraSingh Nov 27, 2026
862d6d5
fix(review): redact convention text with high-precision patterns only
RaghwendraSingh Nov 27, 2026
6e765d6
fix(review): fold convention findings only into a lead this run posts…
RaghwendraSingh Nov 27, 2026
4c7806f
fix(review): a new convention lead does not re-list findings already …
RaghwendraSingh Nov 27, 2026
4d8021c
fix(review): a folded finding must be inline-eligible itself; summary…
RaghwendraSingh Nov 27, 2026
a114a86
fix(review): a Cursor globs list survives a blank or comment line; gi…
RaghwendraSingh Nov 27, 2026
4515069
fix(review): summary grouping ignores the lead's same-applies sentence
RaghwendraSingh Nov 27, 2026
c6d68f1
fix(review): a Cursor globs list at column 0 is read when the frontma…
RaghwendraSingh Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/docs/usage/dbt-pr-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ ai: true # the advisory AI lane; false turns it off. Or an
# otherFiles: true # other/analysis files inside the project (.sql/.yml/.yaml)
# pythonFiles: true # changed Python files, inside or outside the project
# verify: true # the dbt-grounded verifier over the AI comments
# conventions: true # repo review instructions from the base branch (see below)
dataDiff: # OFF by default — see "Data-diff in CI" below
enabled: false
warehouse: "" # connection name; empty = default connection
Expand Down Expand Up @@ -652,6 +653,22 @@ across 12 dialects all plan; anything still unrecognized stays *undecidable*, ne
when neither resolves to a work tree. The error names the work tree it found;
note that a home directory that is itself a git repository (dotfiles kept in
git) is such a work tree, so files anywhere under it are refused.
The repo's own review instructions go with each call, read from the base branch
so a PR cannot change them: `.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, so a dbt project's own `.altimate/review.md` next to its
`.altimate/review.yml` applies to it), `.cursor/rules/*.mdc` (rules with `globs`
or `alwaysApply`; manual rules with neither are skipped), `.cursorrules`,
`.github/copilot-instructions.md`, `.coderabbit.yaml` `path_instructions` and
`tone_instructions`, and the dbt/SQL/test sections of `CONTRIBUTING.md`, most
specific first, up to 3,000 characters per call (`ai.conventions: false` or
`ALTIMATE_REVIEW_CONVENTIONS=0` turns this off). A file that is a symlink at the
base commit is skipped, and so is any instruction file that holds a private key
or a service-account key: it is never sent to the model. In the other files,
provider tokens (GitHub `ghp_…`, Slack `xox…`, OpenAI `sk-…`), AWS key ids, passwords in URLs and
secret-named settings whose value looks like a credential are redacted; ordinary
text such as `env_var('DBT_PASSWORD')` examples is left as written. The verifier reads a
convention file's base-branch text, not the PR's edit of it.
4. **Rubric → verdict.** Findings map to a verdict by a versioned rubric (data,
not prompt): any blocking-category `critical` → `REQUEST_CHANGES`; ≥3 warnings
→ risk pattern → `REQUEST_CHANGES`; only suggestions → `COMMENT`; nothing →
Expand Down
8 changes: 5 additions & 3 deletions packages/opencode/src/altimate/review/ai-replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// again. Ids are the stored ones; benchmark labels are keyed by them.
// Fidelity is approximate: discarded findings come back with bodies clamped to
// 600 characters, and kept ones after the orchestrator's anchoring/cleaning.
import { SAME_APPLIES_RE } from "./conventions"
import { readFile } from "node:fs/promises"
import z from "zod"
import { Provider } from "@/provider/provider"
Expand Down Expand Up @@ -151,13 +152,14 @@ export function replayFindings(raw: unknown): ReplayedLane {
/** A kept finding close to how the generator returned it: no verification record, body suffix,
* tier, origin, or the orchestrator's `preExisting` / `evidenceLine` (re-derived on the next run). */
function unverify(f: Finding): Finding {
const { tier: _tier, origin: _origin, preExisting: _pre, evidenceLine: _line, ...rest } = f
const { tier: _tier, origin: _origin, preExisting: _pre, evidenceLine: _line, groupedInto: _grouped, ...rest } = f
// Convention grouping runs again on replay (after the verifier): drop the lead's list of the other files.
let body = f.body.replace(SAME_APPLIES_RE, "")
const prior = f.evidence?.result
if (!prior || typeof prior !== "object") return rest
if (!prior || typeof prior !== "object") return { ...rest, body }
const { verification, ...result } = prior as Record<string, unknown> & {
verification?: { rule?: string; evidence?: string }
}
let body = f.body
const suffix = verification?.rule === "verified" && verification.evidence ? `\n\nVerified: ${verification.evidence}` : ""
if (suffix && body.endsWith(suffix)) body = body.slice(0, -suffix.length)
return { ...rest, body, evidence: { tool: "ai-review", result } }
Expand Down
29 changes: 26 additions & 3 deletions packages/opencode/src/altimate/review/ai-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CARD_BATCH_MAX_CHARS } from "./ai-context-card"
import { type AiSwitches, switchOn } from "./ai-switches"
import { AI_OTHER_FILES_QUOTA, AI_OTHER_KINDS } from "./ai-other-files"
import { AI_PYTHON_FILES_QUOTA, AI_PYTHON_KIND } from "./ai-python-files"
import { type Convention, type ConventionRecord, conventionRecords, groupConventionFindings, renderConventions } from "./conventions"

const log = Log.create({ service: "ai-review" })

Expand Down Expand Up @@ -750,6 +751,8 @@ export interface AiReviewInput {
checkedPaths?: string[]
/** The review's repository (`--cwd`): files named by env variables must be outside it. */
reviewDir?: string
/** Team conventions from the base branch (`conventions` switch); each call carries those for its files. */
conventions?: Convention[]
}

/** What happened in the advisory lane, reported on the envelope and in the comment. */
Expand Down Expand Up @@ -782,6 +785,8 @@ export interface AiLaneStatus {
unsent?: string[]
/** Files sent only in calls that failed while others answered (state `ok`): not reviewed by the lane. */
failedFiles?: string[]
/** The team conventions loaded from the base branch (no text), when any were given. */
conventions?: ConventionRecord[]
}
/** One file as sent to the model. */
export interface AiInputRecord {
Expand All @@ -797,6 +802,8 @@ export interface AiInputRecord {
card: boolean
/** Index of the call that carried the file; set only under focused batching. */
batch?: number
/** Convention paths the call carried; set on the first file of each call that carried any. */
conventions?: string[]
}
/** Token counts as `Session.getUsage` reports them: `input` excludes cached
* tokens, `inputTotal` includes them. */
Expand Down Expand Up @@ -889,6 +896,9 @@ function buildBatchMessage(
} else {
parts.push("\n## GROUNDING — the engine produced no findings.")
}
// The team conventions that apply to this call's files, within the per-call conventions budget.
const conventions = input.conventions?.length ? renderConventions(input.conventions, input.files.map((f) => f.path)) : undefined
if (conventions?.text) parts.push(conventions.text)

parts.push("\n## CHANGED FILES (review for what the engine missed):")
let cardChars = 0
Expand All @@ -908,6 +918,7 @@ function buildBatchMessage(
...(focus ? { batch: focus.batch } : {}),
})
}
if (conventions?.paths.length && records.length) records[0].conventions = conventions.paths
if (focus?.others.length) {
parts.push(
"\n## OTHER FILES CHANGED IN THIS PR (reviewed in separate calls; do not comment on them):",
Expand Down Expand Up @@ -997,13 +1008,15 @@ export async function runAiReview(input: AiReviewInput): Promise<AiReviewResult>
const plan = planAiInput(input)
const { files, budget } = plan
const dryRun = aiDryRunEnabled()
// Recorded under coverage, focused batching, context cards or dry run (all on by default).
// Recorded under coverage, focused batching, context cards or dry run (all on by default);
// `conventions` whenever the base has instruction files (the `conventions` switch, on by default).
// Files only the AI lane reads are listed by the coverage ledger, unless a deterministic lane checked them.
const checked = new Set(input.checkedPaths ?? [])
const unsent = plan.unsent.filter((f) => !AI_ONLY_KINDS.has(f.kind ?? "") || checked.has(f.path)).map((f) => f.path)
const recorded: Pick<AiLaneStatus, "input" | "unsent"> = {
const recorded: Pick<AiLaneStatus, "input" | "unsent" | "conventions"> = {
...(budget.coverage || dryRun || plan.focused || plan.input.some((r) => r.card) ? { input: plan.input } : {}),
...(budget.coverage && unsent.length ? { unsent } : {}),
...(input.conventions?.length ? { conventions: conventionRecords(input.conventions) } : {}),
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: Multi-project merge drops ai.conventions from other lanes

    ...(input.conventions?.length ? { conventions: conventionRecords(input.conventions) } : {}),

mergeAi (multi-project.ts) spreads one selected lane (ok ?? first) and aggregates input, but not conventions. When projects have different conventions settings and the selected lane has them disabled, the merged envelope has input[].conventions references but no ai.conventions. With the same setting everywhere, the records are normally identical, because every project gets the whole PR's paths.

Suggested fix: union the convention records across lanes in mergeAi.

Raised by: Codex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fixed in 09c023fdd4. mergeAi takes the union of ai.conventions across lanes, deduplicated. This matters more now that each project loads only the conventions above its own files. Test: mergeProjectEnvelopes unions ai.conventions across projects.

}
const done = (findings: Finding[], status: Omit<AiLaneStatus, "durationMs">): AiReviewResult => ({
findings,
Expand All @@ -1012,7 +1025,15 @@ export async function runAiReview(input: AiReviewInput): Promise<AiReviewResult>
if (!files.length && (dryRun || !replay)) return done([], { state: "skipped", reason: "no changed dbt files to review" })
// Dry run wins over replay: a replayed envelope would still reach the verifier, a model call.
if (dryRun) return done([], { state: "skipped", reason: "dry run (ALTIMATE_REVIEW_AI_DRYRUN=1): no model call" })
if (replay) return runAiReplay(input, replay)
if (replay) {
// The replayed findings get the same convention record and grouping as a live run.
const r = await runAiReplay(input, replay)
if (!input.conventions?.length) return r
return {
findings: groupConventionFindings(r.findings, input.conventions),
status: { ...r.status, conventions: conventionRecords(input.conventions) },
}
}

let modelLabel: string | undefined
try {
Expand Down Expand Up @@ -1065,6 +1086,8 @@ export async function runAiReview(input: AiReviewInput): Promise<AiReviewResult>
findings = v.findings
verifier = v.status
}
// One comment for one convention broken the same way on several files.
if (input.conventions?.length) findings = groupConventionFindings(findings, input.conventions)
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
return done(findings, {
state: "ok",
model: modelLabel,
Expand Down
8 changes: 5 additions & 3 deletions packages/opencode/src/altimate/review/ai-switches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// env variable, as before, so an unset variable means off there.
import type { ReviewConfig } from "./config"

export type AiSwitchName = "coverage" | "contextCard" | "focused" | "otherFiles" | "pythonFiles" | "verify"
export type AiSwitchName = "coverage" | "contextCard" | "focused" | "otherFiles" | "pythonFiles" | "verify" | "conventions"

export type AiSwitches = Record<AiSwitchName, boolean>

Expand All @@ -20,12 +20,13 @@ export const AI_SWITCH_ENV: Record<AiSwitchName, string> = {
otherFiles: "ALTIMATE_REVIEW_AI_OTHER_FILES",
pythonFiles: "ALTIMATE_REVIEW_AI_PYTHON_FILES",
verify: "ALTIMATE_REVIEW_AI_VERIFY",
conventions: "ALTIMATE_REVIEW_CONVENTIONS",
}

/**
* Product defaults when neither env nor config sets a switch: the configuration measured
* together (wider input, related files batched, context cards, the verifier). Each one is
* opt-out with `ai: { <switch>: false }` or its env variable set to `0`.
* together (wider input, related files batched, context cards, the verifier, the team
* conventions). Each one is opt-out with `ai: { <switch>: false }` or its env variable set to `0`.
*/
export const AI_SWITCH_DEFAULTS: AiSwitches = {
coverage: true,
Expand All @@ -34,6 +35,7 @@ export const AI_SWITCH_DEFAULTS: AiSwitches = {
otherFiles: true,
pythonFiles: true,
verify: true,
conventions: true,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
}

type Env = Record<string, string | undefined>
Expand Down
9 changes: 8 additions & 1 deletion packages/opencode/src/altimate/review/ai-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export interface AiVerifyEvidence {
addedLines: Map<string, Set<number>>
/** Every file the PR changes, repo-relative, including tests and CI outside the dbt project. */
prFiles?: string[]
/** The team conventions the finder was given, by path: their base-commit text. `read_file`
* serves this text for a convention path, so a PR's edit cannot refute a base convention. */
conventions?: Map<string, string>
}

export type Decision = "keep" | "discard" | "summary"
Expand Down Expand Up @@ -824,6 +827,7 @@ export function verifierTools(
...graph.parents.map((p) => p.path),
...graph.downstream.map((d) => d.path),
...(ev.prFiles ?? []),
...(ev.conventions?.keys() ?? []),
]),
].filter((p) => !isCredentialPath(p))
/** A requested path inside the review scope, as the repo-relative path to read; a project-relative path resolves too. */
Expand All @@ -843,7 +847,7 @@ export function verifierTools(

return {
read_file: {
description: "Up to 200 numbered lines of any file the PR changes (tests and CI included), a dbt parent or direct child.",
description: "Up to 200 numbered lines of a changed file (tests, CI too), a dbt parent or child, or a team convention (base text).",
input: z.object({
path: z.string(),
side,
Expand All @@ -853,6 +857,9 @@ export function verifierTools(
async run({ path, side, start, end }) {
const p = resolve(path)
if (!p) return scope
const convention = ev.conventions?.get(p)
if (convention !== undefined)
return `(team convention, base-branch text)\n${numberedSlice(convention, start as number, end as number) ?? ""}`
return (
(await ev.readFile(p, (side as "old" | "new") ?? "new", start as number, end as number)) ??
NA(`${p} does not exist on that side`)
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/altimate/review/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const ReviewConfig = z.object({
pythonFiles: z.boolean().optional(),
/** The dbt-grounded verifier over the AI findings. */
verify: z.boolean().optional(),
/** Repo review instructions (AGENTS.md, CLAUDE.md, REVIEW.md, Cursor/CodeRabbit/Copilot rules, CONTRIBUTING.md) from the base branch. */
conventions: z.boolean().optional(),
}),
])
.default(true),
Expand Down
Loading
Loading