|
| 1 | +--- |
| 2 | +name: review |
| 3 | +description: Scoped, single-category code review with convergence constraints. Use when performing targeted code review for specific issue types (security, bugs, dead-code, quality, simplify, tests, or diff-only reviews). |
| 4 | +argument-hint: "[security | bugs | dead-code | quality | simplify | tests | diff]" |
| 5 | +disable-model-invocation: true |
| 6 | +allowed-tools: Read, Glob, Grep, Bash(git:*) |
| 7 | +metadata: |
| 8 | + author: cpplain |
| 9 | + version: "1.0" |
| 10 | +--- |
| 11 | + |
| 12 | +# Scoped Code Review with Convergence Constraints |
| 13 | + |
| 14 | +You are performing a **single-category code review** with hard constraints to ensure convergence. This skill exists because iterative whole-codebase reviews create infinite loops: each pass finds issues, fixes add new code, giving the next review fresh surface area. |
| 15 | + |
| 16 | +## Categories |
| 17 | + |
| 18 | +The user invokes this skill with ONE category argument: |
| 19 | + |
| 20 | +| Category | Scope | Key Constraint | |
| 21 | +| ----------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | |
| 22 | +| `security` | Exploitable vulnerabilities with concrete attack vectors | No "defense-in-depth" improvements | |
| 23 | +| `bugs` | Logic errors causing incorrect behavior now | No "could be cleaner" suggestions | |
| 24 | +| `dead-code` | Unreachable code, unused imports/vars/functions | Must verify zero callers via Grep | |
| 25 | +| `quality` | Type errors, resource leaks, broken error recovery | No style, naming, or refactoring | |
| 26 | +| `simplify` | Overly complex, over-abstracted, or over-engineered code | Prefer deletion/inlining; net line count must decrease | |
| 27 | +| `tests` | Test quality and coverage gaps — flaky tests, meaningless assertions, over-mocking, untested critical paths | Improves existing tests; reports gaps but doesn't write new tests | |
| 28 | +| `diff` | Only `+` lines from `git diff HEAD~1` | Ignores pre-existing issues entirely | |
| 29 | + |
| 30 | +**If no argument provided**: Print this category table and stop. Do not perform a review. |
| 31 | + |
| 32 | +**Category argument**: `${0}` |
| 33 | + |
| 34 | +## Hard Constraints (Apply to ALL Categories) |
| 35 | + |
| 36 | +These constraints are **non-negotiable** and apply to every review: |
| 37 | + |
| 38 | +1. **Maximum 7 issues per review** — Report only the 7 most severe issues. If you find more, defer them. |
| 39 | + |
| 40 | +2. **Fixes modify existing code; they do not create new constructs** — If a fix requires adding new functions, classes, constants, or abstractions that did not exist before, it is NOT a fix for this review. Flag it as "Requires human review: [one-sentence explanation]". You have discretion on fix size, but not on fix shape. |
| 41 | + |
| 42 | +3. **No surrounding refactoring** — Fix ONLY the specific issue. Do not clean up nearby code, rename variables, or improve formatting. |
| 43 | + |
| 44 | +4. **Only broken or vulnerable code** — Do not report "improvable" code. If it works correctly, leave it alone. |
| 45 | + |
| 46 | +5. **Stay in category** — A security review cannot report quality issues. A bugs review cannot report dead code. Strictly enforce category boundaries. |
| 47 | + |
| 48 | +6. **No test changes** unless a test is currently broken. Do not modify tests to "improve coverage" or "make them clearer." |
| 49 | + |
| 50 | +## Explicit Anti-Patterns (DO NOT REPORT) |
| 51 | + |
| 52 | +These are explicitly **not issues** for any category: |
| 53 | + |
| 54 | +- "Extract this into a helper function" |
| 55 | +- "Add a constant for this magic number" |
| 56 | +- "Add input validation" (unless it's a current vulnerability) |
| 57 | +- "Improve this error message" |
| 58 | +- "Add type annotations / docstrings" |
| 59 | +- "This could be simplified" (unless category is `simplify`) |
| 60 | +- "Consider using X instead of Y" |
| 61 | +- "Make this more consistent with..." |
| 62 | +- "Add logging here" |
| 63 | +- "This might be confusing to future developers" |
| 64 | + |
| 65 | +If you find yourself wanting to report any of the above, **stop and reconsider**. |
| 66 | + |
| 67 | +## Category-Specific Review Processes |
| 68 | + |
| 69 | +### `security` Review Process |
| 70 | + |
| 71 | +**Goal**: Find exploitable vulnerabilities with concrete attack vectors. |
| 72 | + |
| 73 | +**Step-by-step**: |
| 74 | + |
| 75 | +1. Identify all external input sources (CLI args, file reads, environment variables, API calls) |
| 76 | +2. Trace data flow from external inputs to dangerous operations (command execution, file writes, path construction, eval-like operations) |
| 77 | +3. For each potential issue, construct a concrete exploit scenario |
| 78 | +4. Report ONLY if the exploit is realistic and achievable |
| 79 | + |
| 80 | +**Do NOT report**: |
| 81 | + |
| 82 | +- "Should validate input" without a concrete exploit |
| 83 | +- "Defense-in-depth" improvements |
| 84 | +- Theoretical vulnerabilities with no practical attack vector |
| 85 | +- Missing input sanitization if the input source is already trusted |
| 86 | + |
| 87 | +**Example valid issue**: "User-controlled `--output` flag is passed directly to `open()` without path validation, allowing directory traversal: `--output ../../etc/passwd` writes to arbitrary paths." |
| 88 | + |
| 89 | +**Example invalid issue**: "Should validate that port is in range 1-65535" (not exploitable if the port comes from config file). |
| 90 | + |
| 91 | +### `bugs` Review Process |
| 92 | + |
| 93 | +**Goal**: Find logic errors causing incorrect behavior under realistic inputs. |
| 94 | + |
| 95 | +**Step-by-step**: |
| 96 | + |
| 97 | +1. Verify return types match expected types |
| 98 | +2. Check all code paths reach correct outcomes |
| 99 | +3. Verify exception handling doesn't swallow critical errors |
| 100 | +4. Check loop termination conditions |
| 101 | +5. Verify conditional logic covers all cases |
| 102 | + |
| 103 | +**Do NOT report**: |
| 104 | + |
| 105 | +- "This could be cleaner" |
| 106 | +- "Consider refactoring this" |
| 107 | +- Edge cases that can't occur in practice |
| 108 | +- Style or naming issues |
| 109 | +- Performance problems (unless they cause timeouts/hangs) |
| 110 | + |
| 111 | +**Example valid issue**: "Function returns `None` on error but caller expects boolean, causing `TypeError` at line 45." |
| 112 | + |
| 113 | +**Example invalid issue**: "This function is hard to understand" (not a bug). |
| 114 | + |
| 115 | +### `dead-code` Review Process |
| 116 | + |
| 117 | +**Goal**: Find code that is provably unreachable or unused. |
| 118 | + |
| 119 | +**Step-by-step**: |
| 120 | + |
| 121 | +1. Use Glob to find all source files |
| 122 | +2. For each candidate (unused import, function, class, variable): |
| 123 | + - Use Grep to search the entire codebase for references |
| 124 | + - Check if it's part of a public API (exported, documented) |
| 125 | + - Check if it's a test utility used by multiple tests |
| 126 | +3. Report ONLY if you can prove zero references exist |
| 127 | + |
| 128 | +**Do NOT report**: |
| 129 | + |
| 130 | +- Code that "looks unused" without verification |
| 131 | +- Public APIs (even if unused internally) |
| 132 | +- Test utilities |
| 133 | +- Logging/debugging code |
| 134 | +- Code used conditionally (feature flags, platform-specific) |
| 135 | + |
| 136 | +**Example valid issue**: "Function `_legacy_formatter()` has zero callers in codebase (verified via `Grep`). Can be deleted." |
| 137 | + |
| 138 | +**Example invalid issue**: "Function `export_csv()` is not called" (didn't check if it's a public API). |
| 139 | + |
| 140 | +### `quality` Review Process |
| 141 | + |
| 142 | +**Goal**: Find type errors, resource leaks, and broken error recovery. |
| 143 | + |
| 144 | +**Step-by-step**: |
| 145 | + |
| 146 | +1. Check error handling blocks for correct behavior |
| 147 | +2. Verify resources (files, connections, locks) are properly released |
| 148 | +3. Check type mismatches (string used as int, etc.) |
| 149 | +4. Verify exceptions are caught at appropriate levels |
| 150 | + |
| 151 | +**Do NOT report**: |
| 152 | + |
| 153 | +- Style issues |
| 154 | +- Naming conventions |
| 155 | +- "Could be more Pythonic" |
| 156 | +- Missing docstrings or comments |
| 157 | +- Performance optimizations |
| 158 | + |
| 159 | +**Example valid issue**: "File handle opened at line 23 is never closed if exception occurs at line 27. Use context manager." |
| 160 | + |
| 161 | +**Example invalid issue**: "Variable name `x` is not descriptive" (style, not quality). |
| 162 | + |
| 163 | +### `simplify` Review Process |
| 164 | + |
| 165 | +**Goal**: Find overly complex, over-abstracted, or over-engineered code. Every fix must result in fewer lines than before. |
| 166 | + |
| 167 | +**Step-by-step**: |
| 168 | + |
| 169 | +1. Find abstractions with only one caller (functions, classes, wrappers) |
| 170 | +2. Find constants used exactly once |
| 171 | +3. Find defensive validation for impossible cases (e.g., type checking after isinstance) |
| 172 | +4. Find wrapper functions that add no value |
| 173 | +5. For each issue, verify the simplified version has fewer lines |
| 174 | + |
| 175 | +**Do NOT report**: |
| 176 | + |
| 177 | +- Complexity that serves a purpose (multiple callers, legitimate abstraction) |
| 178 | +- "Could be simplified" without proving line count reduction |
| 179 | +- Abstractions that improve clarity (even if one caller) |
| 180 | + |
| 181 | +**Fix requirement**: The fix must demonstrate NET line reduction. If removing an abstraction requires inlining more code than the abstraction saved, it's not a valid simplification. |
| 182 | + |
| 183 | +**Example valid issue**: "Helper function `_validate_config()` has one caller and just calls two validation functions. Remove it and inline the calls (-5 lines)." |
| 184 | + |
| 185 | +**Example invalid issue**: "Could extract this into a helper" (increases complexity). |
| 186 | + |
| 187 | +### `tests` Review Process |
| 188 | + |
| 189 | +**Goal**: Find test quality issues and coverage gaps. Two distinct parts. |
| 190 | + |
| 191 | +**Part 1: Fix (report as issues with fixes)** |
| 192 | +Step-by-step: |
| 193 | + |
| 194 | +1. Find tests that don't assert anything meaningful (only assert function returns, no validation of correctness) |
| 195 | +2. Find tests that over-mock dependencies so they don't test real behavior |
| 196 | +3. Find tests with timing dependencies (sleeps, brittle timeouts) |
| 197 | +4. Find tests that duplicate other tests exactly |
| 198 | +5. For each issue, provide a fix that modifies the existing test |
| 199 | + |
| 200 | +**Part 2: Coverage Gaps (report as "Coverage gap:" entries)** |
| 201 | +Step-by-step: |
| 202 | + |
| 203 | +1. Identify critical code paths with no test coverage: |
| 204 | + - Error handling branches |
| 205 | + - Security validators |
| 206 | + - Edge cases in parsing/validation |
| 207 | + - Conditional logic branches |
| 208 | +2. Report each gap as: "Coverage gap: [description of what's untested]" |
| 209 | +3. **DO NOT write the new tests** — just flag what's missing |
| 210 | + |
| 211 | +**Do NOT report**: |
| 212 | + |
| 213 | +- "Should add more tests" without specifics |
| 214 | +- Missing tests for trivial getters/setters |
| 215 | +- Coverage of internal implementation details |
| 216 | +- "Could improve test clarity" (not a test quality issue) |
| 217 | + |
| 218 | +**Example valid issue (Part 1)**: "Test `test_parse_config()` only asserts function doesn't raise exception. Add assertions to verify parsed values are correct." |
| 219 | + |
| 220 | +**Example valid coverage gap (Part 2)**: "Coverage gap: `extract_commands()` error handling when shell command has unbalanced quotes is untested." |
| 221 | + |
| 222 | +**Example invalid issue**: "Add more tests for this module" (too vague). |
| 223 | + |
| 224 | +### `diff` Review Process |
| 225 | + |
| 226 | +**Goal**: Review only the lines changed in the most recent commit. |
| 227 | + |
| 228 | +**Step-by-step**: |
| 229 | + |
| 230 | +1. Run `git diff HEAD~1` to get the diff |
| 231 | +2. Extract ONLY lines starting with `+` (additions) |
| 232 | +3. Apply all other review constraints to those lines only |
| 233 | +4. Ignore all pre-existing code, even if it has issues |
| 234 | + |
| 235 | +**Do NOT report**: |
| 236 | + |
| 237 | +- Issues in unchanged code |
| 238 | +- Issues in lines starting with `-` (deletions) |
| 239 | +- Context lines (neither `+` nor `-`) |
| 240 | + |
| 241 | +**Example valid issue**: "Line 45 (added in HEAD): variable `result` is unused after assignment." |
| 242 | + |
| 243 | +**Example invalid issue**: "Line 20 has a security issue" (line 20 wasn't changed in HEAD~1). |
| 244 | + |
| 245 | +## Output Format |
| 246 | + |
| 247 | +Use this exact structure for each issue: |
| 248 | + |
| 249 | +``` |
| 250 | +### Issue N: [Short title] |
| 251 | +**Category**: [category] | **File**: [path:line] | **Severity**: CRITICAL|HIGH|MEDIUM |
| 252 | +
|
| 253 | +**Problem**: [1-2 sentences explaining what's wrong and why it matters] |
| 254 | +
|
| 255 | +**Fix**: [Specific code change OR "Requires human review: [reason]"] |
| 256 | +``` |
| 257 | + |
| 258 | +### Severity Guidelines |
| 259 | + |
| 260 | +- **CRITICAL**: Security exploits, data loss, crashes |
| 261 | +- **HIGH**: Logic errors, resource leaks, broken functionality |
| 262 | +- **MEDIUM**: Dead code, quality issues, test gaps |
| 263 | + |
| 264 | +### Summary Line |
| 265 | + |
| 266 | +After all issues, include: |
| 267 | + |
| 268 | +``` |
| 269 | +--- |
| 270 | +**Summary**: Found [N] issues in [category] review. |
| 271 | +``` |
| 272 | + |
| 273 | +If you found more than 7 issues, add: |
| 274 | + |
| 275 | +``` |
| 276 | +**Note**: [N] additional issues deferred to next pass. |
| 277 | +``` |
| 278 | + |
| 279 | +## Workflow |
| 280 | + |
| 281 | +1. **Validate category argument** — If `${0}` is empty or invalid, print category table and stop. |
| 282 | + |
| 283 | +2. **Scope the review** — If category is `diff`, run `git diff HEAD~1` first to establish scope. |
| 284 | + |
| 285 | +3. **Find issues** — Follow the category-specific process strictly. Use Glob/Grep/Read as needed. |
| 286 | + |
| 287 | +4. **Apply hard constraints** — Filter to top 7, verify fixes don't create new constructs, eliminate anti-patterns. |
| 288 | + |
| 289 | +5. **Format output** — Use structured format for each issue. |
| 290 | + |
| 291 | +6. **Print summary** — Include issue count and deferrals if applicable. |
| 292 | + |
| 293 | +## Convergence Strategy |
| 294 | + |
| 295 | +This skill is designed to enforce convergence: |
| 296 | + |
| 297 | +- **Capped issue count** prevents infinite work |
| 298 | +- **No new constructs** prevents fixes from adding surface area |
| 299 | +- **Category isolation** prevents scope creep |
| 300 | +- **Anti-patterns list** prevents enhancement inflation |
| 301 | +- **Diff mode** enables steady-state reviews of just new changes |
| 302 | + |
| 303 | +After a fix commit, run `/review diff` to verify the fixes didn't introduce new issues. The review should find fewer issues each time, confirming convergence. |
0 commit comments