Files
kandev/apps/backend/config/workflows/pr-review.yml
T

121 lines
5.4 KiB
YAML

id: pr-review
name: PR Review
description: >-
Track pull requests through review. PRs wait in queue, get reviewed
by the agent, then marked as done.
steps:
- id: waiting
name: Waiting
position: 0
color: bg-neutral-400
is_start_step: true
allow_manual_move: true
events:
on_turn_start:
- type: move_to_next
- id: review
name: Review
position: 1
color: bg-yellow-500
show_in_command_panel: true
allow_manual_move: true
prompt: |
Review the changes in this pull request.
{{task_prompt}}
HARD RULE — READ THIS FIRST
You are reviewing the PR's DIFF, not the repository. Findings are only valid on lines that were ADDED or MODIFIED in this PR. Unchanged lines in changed files, and any code in files the PR did not touch, are OFF-LIMITS even if they contain real bugs. If you cannot point to the exact added/modified line in the PR diff that triggers a finding, discard the finding.
STEP 0: CREATE A TASK LIST
Before anything else, create a task list tracking the substeps below (use your todo/task tracking tool if available). Mark each task in_progress when you begin it and completed when you finish. Do not skip ahead — each step feeds the next.
STEP 1: GET THE PR DIFF AND ENUMERATE CHANGED LINES
- Extract the PR number from the task description (e.g. from the GitHub URL).
- Run: gh pr view <number> --json headRefName,baseRefName,title,body to confirm branch, base, and intent.
- Run: gh pr diff <number> to fetch the canonical PR diff (this is what GitHub shows reviewers).
- For each file in the diff, list the changed hunks as (file, start_line-end_line) for the NEW side (added/modified lines only — ignore removed-only lines and unchanged context lines).
- Write this "changed-lines map" down at the top of your review notes. Every finding you later report must cite a (file, line) pair that falls inside this map.
STEP 2: READ FOR CONTEXT, NOT FOR FINDINGS
Context reading is allowed only to understand whether a changed line is correct. It is never a source of findings.
- Open each changed file and read the surrounding function / block so you understand what the added lines do.
- Navigate to callers, interfaces, or tests only if needed to judge a changed line.
- Do NOT scan unchanged code looking for issues. Do NOT review files outside the diff.
STEP 3: REVIEW THE CHANGED LINES
Walk through the changed-lines map hunk by hunk. For each hunk, consider these layers (skip layers that don't apply):
Security (blockers if found):
- No secrets, tokens, or credentials in code
- Input validation at system boundaries (user input, API handlers, external data)
- No SQL injection, XSS, command injection, or path traversal
- Auth and authorization checks on new endpoints
Logic & correctness:
- Edge cases handled (empty input, nil/null, zero, max values)
- Error paths covered and not silently swallowed
- Race conditions in concurrent code
Performance:
- No N+1 queries (loop with individual DB calls)
- No memory leaks (unclosed connections, streams, listeners)
- Algorithm complexity appropriate for the data scale
Architecture:
- New abstractions justified — no over-engineering
- Concerns cleanly separated (single responsibility)
Code quality:
- No dead code, unused imports, or commented-out code
- No speculative code (unused flags, one-off abstractions with single call site)
- Deep nesting (>3 levels) — suggest early returns
AI slop detection:
- Comments that restate code or narrate obvious steps
- Unnecessary try/catch that swallow errors or return silent defaults
- as any / as unknown casts to dodge type errors instead of fixing types
- Redundant validation where inputs are already parsed/typed
STEP 4: SELF-CHECK EVERY FINDING BEFORE REPORTING
For each candidate finding, do this check. Drop the finding if any answer is "no":
1. Is the cited (file, line) inside the changed-lines map from STEP 1?
2. Can you quote the exact added/modified line from the PR diff that triggers it? (Include that quoted line in your notes.)
3. Is the issue caused by this PR, not pre-existing?
4. Are you >=80% confident it's a real issue?
STEP 5: OUTPUT
For each finding: file:line - description, why it matters, how to fix it, and the quoted diff line.
Use these sections (omit empty ones):
BLOCKER (must fix before merge — security, data loss, broken logic):
- file:line - description
SUGGESTION (recommended, doesn't block — performance, architecture, missing tests):
- file:line - description
End with a verdict: Ready to merge / Ready with suggestions / Blocked
NOT A FINDING (never report these):
- Any line not in the changed-lines map — even if it's a real bug
- Pre-existing code patterns that this PR didn't introduce or change
- Things linters, typecheckers, or CI catch (imports, types, formatting)
- Intentional functionality changes directly related to the PR's purpose
- Issues explicitly suppressed in code (lint-ignore, nolint comments)
events:
on_enter:
- type: auto_start_agent
- id: done
name: Done
position: 2
color: bg-green-500
allow_manual_move: true