Code Review
Invariant Principles
- Evidence Over Assertion - Every finding needs file:line reference
- Severity Honesty - Critical=security/data loss; Important=correctness; Minor=style
- Context Awareness - Same code may warrant different severity in different contexts
- Respect Time - False positives erode trust; prioritize signal
Inputs
| Input | Required | Description |
|---|---|---|
args |
Yes | Mode flags and targets |
git diff |
Auto | Changed files |
PR data |
If --pr | PR metadata via GitHub |
Outputs
| Output | Type | Description |
|---|---|---|
findings |
List | Issues with severity, file:line |
status |
Enum | PASS/WARN/FAIL or APPROVE/REQUEST_CHANGES |
Mode Router
| Flag | Mode | Command File |
|---|---|---|
--self, -s, (default) |
Pre-PR self-review | (inline below) |
--feedback, -f |
Process received feedback | code-review-feedback |
--give <target> |
Review someone else's code | code-review-give |
--audit [scope] |
Multi-pass deep-dive | (inline below) |
Modifiers: --tarot (roundtable dialogue via code-review-tarot), --pr <num> (PR source)
MCP Tool Integration
| Tool | Purpose |
|---|---|
pr_fetch(num_or_url) |
Fetch PR metadata and diff |
pr_diff(raw_diff) |
Parse diff into FileDiff objects |
pr_match_patterns(files, root) |
Heuristic pre-filtering |
pr_files(pr_result) |
Extract file list |
Principle: MCP tools for read/analyze. gh CLI for write operations (posting reviews, replies).
Fallback: MCP unavailable -> gh CLI -> local diff -> manual paste.
Self Mode (--self)
Workflow:
- Get diff:
git diff $(git merge-base origin/main HEAD)..HEAD - Multi-pass: Logic > Integration > Security > Style
- Generate findings with severity, file:line, description
- Gate: Critical=FAIL, Important=WARN, Minor>
Audit Mode (--audit [scope])
Scopes: (none)=branch changes, file.py, dir/, security, all
Passes: Correctness > Security > Performance > Maintainability > Edge Cases
Output: Executive Summary, findings by category, Risk Assessment (LOW/MEDIUM/HIGH/CRITICAL)
Self-Check
- Correct mode identified
- All findings have file:line
- Severity based on impact, not effort
- Output matches mode spec