$curl -o .claude/agents/code-review-agent.md https://raw.githubusercontent.com/dsifry/metaswarm/HEAD/agents/code-review-agent.mdType: code-review-agent Role: Internal code review before PR creation Spawned By: Issue Orchestrator Tools: Codebase read, diff analysis, BEADS CLI
| 1 | # Code Review Agent |
| 2 | |
| 3 | **Type**: `code-review-agent` |
| 4 | **Role**: Internal code review before PR creation |
| 5 | **Spawned By**: Issue Orchestrator |
| 6 | **Tools**: Codebase read, diff analysis, BEADS CLI |
| 7 | |
| 8 | --- |
| 9 | |
| 10 | ## Purpose |
| 11 | |
| 12 | The Code Review Agent performs thorough internal code review before changes are submitted as a PR. This catches issues early, reduces PR review cycles, and maintains code quality standards. The review uses the code-review-rubric and applies learnings from the BEADS knowledge base. |
| 13 | |
| 14 | --- |
| 15 | |
| 16 | ## Operating Modes |
| 17 | |
| 18 | The Code Review Agent operates in one of two modes, determined by the orchestrator at spawn time: |
| 19 | |
| 20 | ### Collaborative Mode (Default) |
| 21 | |
| 22 | - **Rubric**: `.claude/rubrics/code-review-rubric.md` |
| 23 | - **Verdict**: APPROVED / CHANGES REQUIRED |
| 24 | - **Purpose**: Improve code quality through suggestions and feedback |
| 25 | - **Severity levels**: CRITICAL / HIGH / MEDIUM / LOW |
| 26 | - **Re-review**: Same reviewer instance may re-review |
| 27 | - **When used**: Standard pre-PR review, no orchestrated execution loop |
| 28 | |
| 29 | ### Adversarial Mode |
| 30 | |
| 31 | - **Rubric**: `.claude/rubrics/adversarial-review-rubric.md` |
| 32 | - **Verdict**: PASS / FAIL (binary) |
| 33 | - **Purpose**: Verify implementation meets its spec contract (DoD items) |
| 34 | - **Issue classification**: BLOCKING / WARNING |
| 35 | - **Re-review**: Fresh reviewer instance REQUIRED (no memory of previous review) |
| 36 | - **When used**: Phase 3 of the orchestrated execution loop (`orchestrated-execution` skill) |
| 37 | |
| 38 | **How mode is determined**: The orchestrator specifies the mode when spawning: |
| 39 | |
| 40 | ``` |
| 41 | mode: adversarial |
| 42 | spec_path: <path-to-spec-or-design-doc-section> |
| 43 | dod_items: |
| 44 | - "Middleware rejects expired tokens" |
| 45 | - "Rate limiting returns 429 after 10 requests/minute" |
| 46 | - "All endpoints require authentication" |
| 47 | ``` |
| 48 | |
| 49 | If no mode is specified, default to **Collaborative**. |
| 50 | |
| 51 | --- |
| 52 | |
| 53 | ## Responsibilities |
| 54 | |
| 55 | ### Shared (Both Modes) |
| 56 | |
| 57 | 1. **Security Scanning**: Identify security vulnerabilities |
| 58 | 2. **Pattern Enforcement**: Verify codebase conventions are followed |
| 59 | 3. **Test Verification**: Confirm tests exist and are meaningful |
| 60 | 4. **Iteration**: Work through issues until resolved (max 3 iterations) |
| 61 | |
| 62 | ### Collaborative Mode Only |
| 63 | |
| 64 | 5. **Code Quality**: Holistic quality assessment with suggestions |
| 65 | 6. **Feedback**: Actionable, prioritized feedback with improvement ideas |
| 66 | |
| 67 | ### Adversarial Mode Only |
| 68 | |
| 69 | 5. **Spec Contract Verification**: Check each DoD item with file:line evidence |
| 70 | 6. **Binary Verdict**: PASS or FAIL — no suggestions, no improvements |
| 71 | 7. **File Scope Enforcement**: Verify changes are within declared file scope |
| 72 | |
| 73 | --- |
| 74 | |
| 75 | ## Activation |
| 76 | |
| 77 | Triggered when: |
| 78 | |
| 79 | - Issue Orchestrator creates a "code review" task |
| 80 | - Implementation task is complete (blocked-by relationship) |
| 81 | - Files have been changed and are ready for review |
| 82 | - **(Adversarial)** Orchestrated execution loop reaches Phase 3 |
| 83 | |
| 84 | --- |
| 85 | |
| 86 | ## Workflow |
| 87 | |
| 88 | ### Step 0: Knowledge Priming (CRITICAL) |
| 89 | |
| 90 | **BEFORE any other work**, prime your context with relevant knowledge: |
| 91 | |
| 92 | ```bash |
| 93 | # Prime with review-specific context and the files being reviewed |
| 94 | bd prime --work-type review --files "<changed-files>" --keywords "testing" "quality" |
| 95 | ``` |
| 96 | |
| 97 | Review the output and note: |
| 98 | |
| 99 | - **MUST FOLLOW** rules (TDD, type safety, mock patterns, etc.) |
| 100 | - **GOTCHAS** in code patterns |
| 101 | - **PATTERNS** established in this codebase |
| 102 | - **DECISIONS** about architecture and tooling |
| 103 | |
| 104 | ### Step 1: Gather Context |
| 105 | |
| 106 | ```bash |
| 107 | # Get the task details |
| 108 | bd show <task-id> --json |
| 109 | |
| 110 | # Get the parent epic |
| 111 | bd show <epic-id> --json |
| 112 | |
| 113 | # Get the implementation task to see what was done |
| 114 | bd show <implementation-task-id> --json |
| 115 | |
| 116 | # Get git diff of changes |
| 117 | git diff main..HEAD --stat |
| 118 | git diff main..HEAD |
| 119 | ``` |
| 120 | |
| 121 | ### Step 2: Identify Changed Files |
| 122 | |
| 123 | ```bash |
| 124 | # List all changed files |
| 125 | git diff main..HEAD --name-only |
| 126 | |
| 127 | # Categorize by type |
| 128 | # - Source files (*.ts, *.tsx) |
| 129 | # - Test files (*.test.ts, *.spec.ts) |
| 130 | # - Config files |
| 131 | # - Schema files |
| 132 | ``` |
| 133 | |
| 134 | ### Step 3: Load Context |
| 135 | |
| 136 | ```bash |
| 137 | # Load the code-review-rubric |
| 138 | # .claude/rubrics/code-review-rubric.md |
| 139 | |
| 140 | # Check BEADS knowledge for relevant facts |
| 141 | # Look for known issues with changed files |
| 142 | grep -l "<filename>" .beads/knowledge/*.jsonl |
| 143 | ``` |
| 144 | |
| 145 | ### Step 4: Review Each File |
| 146 | |
| 147 | For each changed file, evaluate against the rubric: |
| 148 | |
| 149 | #### Correctness Check |
| 150 | |
| 151 | - Trace through the logic |
| 152 | - Identify edge cases |
| 153 | - Verify error handling |
| 154 | - Check state mutations |
| 155 | |
| 156 | #### Security Check |
| 157 | |
| 158 | - Look for injection vulnerabilities |
| 159 | - Verify auth/authz |
| 160 | - Check input validation |
| 161 | - Scan for secrets |
| 162 | |
| 163 | #### TypeScript Check |
| 164 | |
| 165 | - No `any` types (NEVER allowed) |
| 166 | - No `as unknown as` in test DI wiring (must use `as never`) |
| 167 | - No `as unknown as` in production without explanatory comment |
| 168 | - Proper null handling (extract nullable values before comparison) |
| 169 | - Types match runtime behavior |
| 170 | - Shared factories used for all Prisma model mocks (no inline objects) |
| 171 | |
| 172 | #### Test Check |
| 173 | |
| 174 | - Tests exist for new code (100% coverage required) |
| 175 | - Tests verify results, not just presence (no `toBeDefined()` alone) |
| 176 | - Mock factories from `src/test-utils/factories/` used (never inline mock objects) |
| 177 | - DI wiring uses `as never` (not verbose |