Repository navigation
fix(review): precision and new rules from a replay of human-caught defects on public dbt PRs #1739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/review-ac-gaps
Are you sure you want to change the base?
Changes from all commits
bb4be68
c8951a2
b99615d
4535a61
bd4c773
f1be07c
73be80a
c5eb275
1ea34f5
2b1545d
ab6c253
485339a
bb6a1fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * The engine's existence findings, which mean nothing without a schema. | ||
| * Dependency-free so callers can use it without loading the native core binding. | ||
| */ | ||
| const EXISTENCE_CODES = new Set(["E001", "E002"]) | ||
| const EXISTENCE_KINDS = new Set(["TableNotFound", "ColumnNotFound"]) | ||
| export function isExistenceError(err: unknown): boolean { | ||
| const e = err as { code?: unknown; kind?: { type?: unknown } } | null | ||
| return EXISTENCE_CODES.has(String(e?.code)) || EXISTENCE_KINDS.has(String(e?.kind?.type)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,45 @@ const MAX_FILES = 20 | |
| export interface AiReviewFile { | ||
| path: string | ||
| status: string | ||
| /** Model name for a model; the file's base name for any other dbt file. */ | ||
| model: string | ||
| /** dbt role of the file (`model_sql`, `macro`, `schema_yml`, `test`, …); omitted means a model. */ | ||
| kind?: string | ||
| /** Unified diff (added/removed lines) for this file. */ | ||
| diff?: string | ||
| /** dbt-compiled (preferred) or raw SQL for context. */ | ||
| /** Current content: dbt-compiled (preferred) or raw SQL for a model, the file itself otherwise. */ | ||
| sql?: string | ||
| } | ||
|
|
||
| /** Order under the file cap: models first, then the files whose defects reach the most models. */ | ||
| const KIND_ORDER = ["model_sql", "python_model", "macro", "test", "snapshot", "schema_yml", "source_yml", "seed", "project_config"] | ||
| const KIND_LABEL: Record<string, string> = { | ||
| macro: "macro (Jinja; changes every model that calls it)", | ||
| test: "singular data test", | ||
| snapshot: "snapshot", | ||
| schema_yml: "schema yml (tests, contracts, descriptions)", | ||
| source_yml: "sources yml", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The new Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up: low priority, tracked. |
||
| seed: "seed CSV", | ||
| project_config: "project config", | ||
| python_model: "Python model", | ||
| } | ||
| const FENCE: Record<string, string> = { schema_yml: "yaml", source_yml: "yaml", project_config: "yaml", seed: "csv", python_model: "python" } | ||
|
|
||
| function kindRank(kind: string | undefined): number { | ||
| const i = KIND_ORDER.indexOf(kind ?? "model_sql") | ||
| return i < 0 ? KIND_ORDER.length : i | ||
| } | ||
|
|
||
| /** Files the lane sends, in priority order, capped at MAX_FILES. */ | ||
| export function selectAiFiles(files: AiReviewFile[]): AiReviewFile[] { | ||
| return files | ||
| .filter((f) => f.status !== "deleted" && (f.diff || f.sql)) | ||
| .map((f, i) => ({ f, i })) | ||
| .sort((a, b) => kindRank(a.f.kind) - kindRank(b.f.kind) || a.i - b.i) | ||
| .map(({ f }) => f) | ||
| .slice(0, MAX_FILES) | ||
| } | ||
|
|
||
| export interface AiReviewInput { | ||
| files: AiReviewFile[] | ||
| /** Deterministic engine findings — grounding the AI must NOT duplicate. */ | ||
|
|
@@ -85,7 +117,7 @@ function truncate(s: string | undefined, n: number): string { | |
| } | ||
|
|
||
| /** Assemble the user message (mechanical formatting — not IP). */ | ||
| function buildUserMessage(input: AiReviewInput): string { | ||
| export function buildUserMessage(input: AiReviewInput): string { | ||
| const parts: string[] = [] | ||
| if (input.prTitle) parts.push(`PR title: ${truncate(input.prTitle, 200)}`) | ||
| if (input.prBody) parts.push(`PR description:\n${truncate(input.prBody, 1500)}`) | ||
|
|
@@ -101,9 +133,13 @@ function buildUserMessage(input: AiReviewInput): string { | |
|
|
||
| parts.push("\n## CHANGED FILES (review for what the engine missed):") | ||
| for (const f of input.files.slice(0, MAX_FILES)) { | ||
| parts.push(`\n### ${f.path} (${f.status})`) | ||
| const label = f.kind && KIND_LABEL[f.kind] | ||
| parts.push(`\n### ${f.path} (${f.status}${label ? `, ${label}` : ""})`) | ||
| if (f.diff) parts.push("Diff:\n```diff\n" + truncate(f.diff, MAX_DIFF_CHARS) + "\n```") | ||
| if (f.sql) parts.push("Current SQL:\n```sql\n" + truncate(f.sql, MAX_DIFF_CHARS) + "\n```") | ||
| if (f.sql) { | ||
| const isModel = !f.kind || f.kind === "model_sql" | ||
| parts.push(`${isModel ? "Current SQL" : "Current file"}:\n\`\`\`${FENCE[f.kind ?? ""] ?? "sql"}\n` + truncate(f.sql, MAX_DIFF_CHARS) + "\n```") | ||
| } | ||
| } | ||
| parts.push("\nReturn ONLY the JSON array per the output contract.") | ||
| return parts.join("\n") | ||
|
|
@@ -122,8 +158,8 @@ export async function runAiReview(input: AiReviewInput): Promise<AiReviewResult> | |
| findings, | ||
| status: { ...status, durationMs: Date.now() - startedAt }, | ||
| }) | ||
| const files = input.files.filter((f) => f.status !== "deleted" && (f.diff || f.sql)) | ||
| if (!files.length) return done([], { state: "skipped", reason: "no changed model SQL to review" }) | ||
| const files = selectAiFiles(input.files) | ||
| if (!files.length) return done([], { state: "skipped", reason: "no changed dbt files to review" }) | ||
|
|
||
| const controller = new AbortController() | ||
| let timeoutMs = AI_TIMEOUT_BASE_MS | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The AI lane does not see every changed dbt file: deleted files are filtered out, and
analysis/other classified dbt files are never added to its input. Say “eligible non-deleted files in these supported roles” or expand the implementation to cover all changed dbt kinds.Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up: low priority, tracked (wording will note deleted and analysis files are excluded).