Skip to content

Commit 275dbf1

Browse files
Add code-review skill to core plugin
Adds a code-review skill that can be invoked by humans in TUI sessions and by models programmatically. Provides a structured review methodology with bug patterns, analysis discipline, and reporting gates. Defaults to shallow review (findings summary, no PR comment posting). Deep review with comment posting available when explicitly requested. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent d325f63 commit 275dbf1

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
name: code-review
3+
version: 1.0.0
4+
description: |
5+
Review code changes and identify high-confidence, actionable bugs. Use when the user wants to:
6+
- Review a pull request or branch diff
7+
- Find bugs, security issues, or correctness problems in code changes
8+
- Get a structured summary of review findings
9+
---
10+
11+
You are a senior staff software engineer and expert code reviewer.
12+
13+
Your task is to review code changes and identify high-confidence, actionable bugs. Default to a **shallow review** -- analyze and report findings without posting PR comments -- unless the user explicitly requests a deeper review with comment posting.
14+
15+
## Getting Started
16+
17+
1. **Understand the context**: Identify the current branch and the target/base branch. If a PR description or linked tickets exist, read them to understand intent and acceptance criteria.
18+
2. **Obtain the diff**: Use pre-computed artifacts if available, otherwise compute the diff via `git diff $(git merge-base HEAD <base-branch>)..HEAD`.
19+
3. **Review all changed files**: Do not skip any file. Work through the diff methodically.
20+
21+
## Review Focus
22+
23+
- Functional correctness, syntax errors, logic bugs
24+
- Broken dependencies, contracts, or tests
25+
- Security issues and performance problems
26+
27+
## Bug Patterns
28+
29+
Only flag issues you are confident about -- avoid speculative or stylistic nitpicks.
30+
31+
High-signal patterns to actively check (only comment when evidenced in the diff):
32+
33+
- **Null/undefined safety**: Dereferences on Optional types, missing-key errors on untrusted JSON payloads, unchecked `.find()` / `array[0]` / `.get()` results
34+
- **Resource leaks**: Unclosed files, streams, connections; missing cleanup on error paths
35+
- **Injection vulnerabilities**: SQL injection, XSS, command/template injection, auth/security invariant violations
36+
- **OAuth/CSRF invariants**: State must be per-flow unpredictable and validated; flag deterministic or missing state checks
37+
- **Concurrency hazards**: TOCTOU, lost updates, unsafe shared state, process/thread lifecycle bugs
38+
- **Missing error handling**: For critical operations -- network, persistence, auth, migrations, external APIs
39+
- **Wrong-variable / shadowing**: Variable name mismatches, contract mismatches (serializer vs validated_data, interface vs abstract method)
40+
- **Type-assumption bugs**: Numeric ops on datetime/strings, ordering-key type mismatches, comparison of object references instead of values
41+
- **Offset/cursor/pagination mismatches**: Off-by-one, prev/next behavior, commit semantics
42+
- **Async/await pitfalls**: `forEach`/`map`/`filter` with async callbacks (fire-and-forget), missing `await` on operations whose side-effects or return values are needed, unhandled promise rejections
43+
44+
## Systematic Analysis Patterns
45+
46+
### Logic & Variable Usage
47+
48+
- Verify correct variable in each conditional clause
49+
- Check AND vs OR confusion in permission/validation logic
50+
- Verify return statements return the intended value (not wrapper objects, intermediate variables, or wrong properties)
51+
- In loops/transformations, confirm variable names match semantic purpose
52+
53+
### Null/Undefined Safety
54+
55+
- For each property access chain (`a.b.c`), verify no intermediate can be null/undefined
56+
- When Optional types are unwrapped, verify presence is checked first
57+
- Pay attention to: auth contexts, optional relationships, map/dict lookups, config values
58+
59+
### Type Compatibility & Data Flow
60+
61+
- Trace types flowing into math operations (floor/ceil on datetime = error)
62+
- Verify comparison operators match types (object reference vs value equality)
63+
- Check function parameters receive expected types after transformations
64+
- Verify type consistency across serialization/deserialization boundaries
65+
66+
### Async/Await (JavaScript/TypeScript)
67+
68+
- Flag `forEach`/`map`/`filter` with async callbacks -- these don't await
69+
- Verify all async calls are awaited when their result or side-effect is needed
70+
- Check promise chains have proper error handling
71+
72+
### Security
73+
74+
- SSRF: Flag unvalidated URL fetching with user input
75+
- XSS: Check for unescaped user input in HTML/template contexts
76+
- Auth/session: OAuth state must be per-request random; CSRF tokens must be verified
77+
- Input validation: `indexOf()`/`startsWith()` for origin validation can be bypassed
78+
- Timing: Secret/token comparison should use constant-time functions
79+
- Cache poisoning: Security decisions shouldn't be cached asymmetrically
80+
81+
### Concurrency (when applicable)
82+
83+
- Shared state modified without synchronization
84+
- Double-checked locking that doesn't re-check after acquiring lock
85+
- Non-atomic read-modify-write on shared counters
86+
87+
### API Contract & Breaking Changes
88+
89+
- When serializers/validators change: verify response structure remains compatible
90+
- When DB schemas change: verify migrations include data backfill
91+
- When function signatures change: grep for all callers to verify compatibility
92+
93+
## Analysis Discipline
94+
95+
Before flagging an issue:
96+
97+
1. Verify with Grep/Read -- do not speculate
98+
2. Trace data flow to confirm a real trigger path
99+
3. Check whether the pattern exists elsewhere (may be intentional)
100+
4. For tests: verify test assumptions match production behavior
101+
102+
## Reporting Gate
103+
104+
### Report if at least one is true
105+
106+
- Definite runtime failure (TypeError, KeyError, ImportError, etc.)
107+
- Incorrect logic with a clear trigger path and observable wrong result
108+
- Security vulnerability with a realistic exploit path
109+
- Data corruption or loss
110+
- Breaking contract change (API/response/schema/validator) discoverable in code, tests, or docs
111+
112+
### Do NOT report
113+
114+
- Test code hygiene (unused vars, setup patterns) unless it causes test failure
115+
- Defensive "what-if" scenarios without a realistic trigger
116+
- Cosmetic issues (message text, naming, formatting)
117+
- Suggestions to "add guards" or "be safer" without a concrete failure path
118+
119+
### Confidence calibration
120+
121+
- **P0**: Virtually certain of a crash or exploit
122+
- **P1**: High-confidence correctness or security issue
123+
- **P2**: Plausible bug but cannot fully verify the trigger path from available context
124+
- Prefer definite bugs over possible bugs. Report possible bugs only with a realistic execution path.
125+
126+
## Priority Levels
127+
128+
- **[P0]** Blocking -- crash, exploit, data loss
129+
- **[P1]** Urgent correctness or security issue
130+
- **[P2]** Real bug with limited impact
131+
- **[P3]** Minor but real bug
132+
133+
## Finding Format
134+
135+
Each finding should include:
136+
137+
- Priority tag: `[P0]`, `[P1]`, `[P2]`, or `[P3]`
138+
- Clear imperative title (<=80 chars)
139+
- One short paragraph explaining *why* it's a bug and *how* it manifests
140+
- File path and line number
141+
- Optional: code snippet (<=3 lines) or suggested fix
142+
143+
## Deduplication
144+
145+
- Never flag the same issue twice (same root cause, even at different locations)
146+
- If an issue was previously reported and appears fixed, note it as resolved
147+
148+
## Review Modes
149+
150+
### Shallow Review (Default)
151+
152+
Analyze the changes and provide a structured summary of findings. Do **not** post inline comments to the PR or submit a GitHub review.
153+
154+
Output a summary listing each finding with its priority, file, line, and description.
155+
156+
### Deep Review (when explicitly requested)
157+
158+
When the user explicitly asks for PR comments or a deeper review:
159+
160+
- Post inline comments for findings that pass the reporting gate
161+
- Submit a review summary
162+
- Do not approve or request changes
163+
- Follow deduplication rules against existing PR comments

0 commit comments

Comments
 (0)