Skip to content

Commit 1724bdb

Browse files
committed
feat: add /speckit.review command β€” staff-level code review
Add a new core command for thorough, staff-engineer-level code review of implementation changes with 5 review passes: 1. Correctness & Logic 2. Security 3. Performance & Scalability 4. Spec Compliance & Architecture 5. Test Quality Generates structured review report with severity levels (Blocker/Warning/Suggestion) and verdicts (APPROVED / APPROVED WITH CONDITIONS / CHANGES REQUIRED). Inspired by GStack's /review command.
1 parent 3899dcc commit 1724bdb

File tree

2 files changed

+251
-0
lines changed

2 files changed

+251
-0
lines changed

β€Žtemplates/commands/review.mdβ€Ž

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
description: Perform a staff-level code review of implementation changes, focused on correctness, security, performance, and spec compliance.
3+
scripts:
4+
sh: scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks
5+
ps: scripts/powershell/check-prerequisites.ps1 -Json -RequireTasks -IncludeTasks
6+
---
7+
8+
## User Input
9+
10+
```text
11+
$ARGUMENTS
12+
```
13+
14+
You **MUST** consider the user input before proceeding (if not empty).
15+
16+
## Pre-Execution Checks
17+
18+
**Check for extension hooks (before review)**:
19+
- Check if `.specify/extensions.yml` exists in the project root.
20+
- If it exists, read it and look for entries under the `hooks.before_review` key
21+
- If the YAML cannot be parsed or is invalid, skip hook checking silently and continue normally
22+
- Filter out hooks where `enabled` is explicitly `false`. Treat hooks without an `enabled` field as enabled by default.
23+
- For each remaining hook, do **not** attempt to interpret or evaluate hook `condition` expressions:
24+
- If the hook has no `condition` field, or it is null/empty, treat the hook as executable
25+
- If the hook defines a non-empty `condition`, skip the hook and leave condition evaluation to the HookExecutor implementation
26+
- For each executable hook, output the following based on its `optional` flag:
27+
- **Optional hook** (`optional: true`):
28+
```
29+
## Extension Hooks
30+
31+
**Optional Pre-Hook**: {extension}
32+
Command: `/{command}`
33+
Description: {description}
34+
35+
Prompt: {prompt}
36+
To execute: `/{command}`
37+
```
38+
- **Mandatory hook** (`optional: false`):
39+
```
40+
## Extension Hooks
41+
42+
**Automatic Pre-Hook**: {extension}
43+
Executing: `/{command}`
44+
EXECUTE_COMMAND: {command}
45+
46+
Wait for the result of the hook command before proceeding to the Outline.
47+
```
48+
- If no hooks are registered or `.specify/extensions.yml` does not exist, skip silently
49+
50+
## Goal
51+
52+
Conduct a thorough, staff-engineer-level code review of all changes made during the implementation phase. This review acts as a quality gate before shipping, catching bugs, security issues, performance regressions, and deviations from the specification. The review is **read-only** β€” it produces a structured report but does NOT modify code.
53+
54+
## Operating Constraints
55+
56+
**STRICTLY READ-ONLY**: Do **not** modify any source files. Output a structured review report to the reviews directory. If critical issues are found, recommend specific fixes but do NOT apply them.
57+
58+
**Constitution Authority**: The project constitution (`/memory/constitution.md`) defines non-negotiable quality standards. Any violation is automatically a πŸ”΄ Blocker.
59+
60+
## Outline
61+
62+
1. Run `{SCRIPT}` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\''m Groot' (or double-quote if possible: "I'm Groot").
63+
64+
2. **Gather Review Context**:
65+
- **REQUIRED**: Read `spec.md` for functional requirements and acceptance criteria
66+
- **REQUIRED**: Read `plan.md` for architecture decisions and technical constraints
67+
- **REQUIRED**: Read `tasks.md` for the full task list and implementation scope
68+
- **IF EXISTS**: Read `/memory/constitution.md` for quality standards and principles
69+
- **IF EXISTS**: Read any existing review reports in FEATURE_DIR/reviews/ for context
70+
71+
3. **Identify Changes to Review**:
72+
- Run `git diff main --stat` (or appropriate base branch) to identify all changed files
73+
- If no git diff is available, use the file paths referenced in `tasks.md` as the review scope
74+
- Group changes by category: source code, tests, configuration, documentation
75+
- Prioritize review order: security-sensitive files β†’ core logic β†’ API surfaces β†’ tests β†’ config β†’ docs
76+
77+
4. **Review Pass 1 β€” Correctness & Logic**:
78+
- Verify each implementation matches its corresponding requirement in `spec.md`
79+
- Check for off-by-one errors, null/undefined handling, boundary conditions
80+
- Validate error handling: are errors caught, logged, and surfaced appropriately?
81+
- Check for race conditions in concurrent/async code
82+
- Verify data validation at trust boundaries (user input, API responses, file reads)
83+
- Ensure state management is consistent (no orphaned state, proper cleanup)
84+
85+
5. **Review Pass 2 β€” Security**:
86+
- Check for injection vulnerabilities (SQL, XSS, command injection, path traversal)
87+
- Verify authentication and authorization checks on all protected endpoints
88+
- Look for hardcoded secrets, credentials, or API keys
89+
- Validate input sanitization and output encoding
90+
- Check for insecure dependencies or known vulnerability patterns
91+
- Verify CORS, CSP, and other security header configurations
92+
- Check for sensitive data exposure in logs, error messages, or responses
93+
94+
6. **Review Pass 3 β€” Performance & Scalability**:
95+
- Identify N+1 query patterns or unnecessary database calls
96+
- Check for unbounded loops, missing pagination, or large in-memory collections
97+
- Look for blocking operations in async contexts
98+
- Verify caching strategies are appropriate and cache invalidation is correct
99+
- Check for resource leaks (file handles, connections, event listeners)
100+
- Validate that performance-critical paths noted in `plan.md` are optimized
101+
102+
7. **Review Pass 4 β€” Spec Compliance & Architecture**:
103+
- Cross-reference each functional requirement (FR-###) against implementation
104+
- Verify architecture decisions from `plan.md` are followed (patterns, layers, boundaries)
105+
- Check API contracts match specification (request/response shapes, status codes)
106+
- Validate that acceptance criteria from user stories are testable and tested
107+
- Flag any implemented functionality NOT in the spec (scope creep)
108+
- Flag any spec requirements NOT implemented (missing coverage)
109+
110+
8. **Review Pass 5 β€” Test Quality**:
111+
- Verify test coverage for critical paths and edge cases
112+
- Check test assertions are meaningful (not just "doesn't throw")
113+
- Validate test isolation (no shared mutable state between tests)
114+
- Verify mock/stub usage is appropriate and doesn't hide real bugs
115+
- Check that acceptance criteria have corresponding test cases
116+
- Flag untested error paths and boundary conditions
117+
118+
9. **Severity Classification**:
119+
Apply the following severity levels to each finding:
120+
121+
- πŸ”΄ **Blocker**: Security vulnerability, data corruption risk, crashes, constitution violation, missing core functionality. **Must fix before shipping.**
122+
- 🟑 **Warning**: Performance issue, incomplete error handling, missing edge case coverage, test gap, architectural deviation. **Should fix before shipping.**
123+
- 🟒 **Suggestion**: Code clarity improvement, refactoring opportunity, documentation gap, minor style inconsistency. **Nice to fix but non-blocking.**
124+
125+
10. **Generate Review Report**:
126+
Create the review report at `FEATURE_DIR/reviews/review-{timestamp}.md` using the review report template. The report must include:
127+
128+
- **Executive Summary**: Overall assessment (APPROVED / APPROVED WITH CONDITIONS / CHANGES REQUIRED)
129+
- **Findings Table**: All findings with ID, severity, file, line(s), description, recommendation
130+
- **Spec Coverage Matrix**: Requirements vs implementation status
131+
- **Test Coverage Assessment**: Coverage gaps relative to acceptance criteria
132+
- **Metrics**: Total findings by severity, files reviewed, spec coverage percentage
133+
- **Recommended Actions**: Prioritized list of fixes, grouped by severity
134+
135+
11. **Provide Verdict**:
136+
Based on findings, provide one of:
137+
- βœ… **APPROVED**: No blockers, minimal warnings. Safe to proceed to `/speckit.ship`
138+
- ⚠️ **APPROVED WITH CONDITIONS**: No blockers, but warnings should be addressed. List conditions.
139+
- ❌ **CHANGES REQUIRED**: Blockers found. Must fix and re-review before shipping. List blocking items.
140+
141+
## Post-Review Actions
142+
143+
Suggest next steps based on verdict:
144+
- If APPROVED: "Run `/speckit.ship` to prepare the release"
145+
- If APPROVED WITH CONDITIONS: "Address warnings, then run `/speckit.ship`"
146+
- If CHANGES REQUIRED: "Fix blocker issues, then run `/speckit.review` again"
147+
148+
**Check for extension hooks (after review)**:
149+
- Check if `.specify/extensions.yml` exists in the project root.
150+
- If it exists, read it and look for entries under the `hooks.after_review` key
151+
- If the YAML cannot be parsed or is invalid, skip hook checking silently and continue normally
152+
- Filter out hooks where `enabled` is explicitly `false`. Treat hooks without an `enabled` field as enabled by default.
153+
- For each remaining hook, do **not** attempt to interpret or evaluate hook `condition` expressions:
154+
- If the hook has no `condition` field, or it is null/empty, treat the hook as executable
155+
- If the hook defines a non-empty `condition`, skip the hook and leave condition evaluation to the HookExecutor implementation
156+
- For each executable hook, output the following based on its `optional` flag:
157+
- **Optional hook** (`optional: true`):
158+
```
159+
## Extension Hooks
160+
161+
**Optional Hook**: {extension}
162+
Command: `/{command}`
163+
Description: {description}
164+
165+
Prompt: {prompt}
166+
To execute: `/{command}`
167+
```
168+
- **Mandatory hook** (`optional: false`):
169+
```
170+
## Extension Hooks
171+
172+
**Automatic Hook**: {extension}
173+
Executing: `/{command}`
174+
EXECUTE_COMMAND: {command}
175+
```
176+
- If no hooks are registered or `.specify/extensions.yml` does not exist, skip silently

β€Žtemplates/review-template.mdβ€Ž

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Code Review Report: [FEATURE NAME]
2+
3+
**Reviewer**: AI Agent (Staff Engineer Perspective)
4+
**Date**: [DATE]
5+
**Feature**: [Link to spec.md]
6+
**Branch**: [Feature branch name]
7+
**Verdict**: [βœ… APPROVED / ⚠️ APPROVED WITH CONDITIONS / ❌ CHANGES REQUIRED]
8+
9+
---
10+
11+
## Executive Summary
12+
13+
[One-paragraph overall assessment of the implementation quality, key strengths, and primary concerns.]
14+
15+
---
16+
17+
## Review Findings
18+
19+
| ID | Severity | File | Line(s) | Category | Finding | Recommendation |
20+
|----|----------|------|---------|----------|---------|----------------|
21+
| R001 | πŸ”΄ Blocker | [file] | [lines] | [category] | [description] | [fix suggestion] |
22+
| R002 | 🟑 Warning | [file] | [lines] | [category] | [description] | [fix suggestion] |
23+
| R003 | 🟒 Suggestion | [file] | [lines] | [category] | [description] | [fix suggestion] |
24+
25+
**Categories**: Correctness, Security, Performance, Spec Compliance, Error Handling, Test Quality, Architecture
26+
27+
---
28+
29+
## Spec Coverage Matrix
30+
31+
| Requirement | Status | Implementation Notes |
32+
|-------------|--------|---------------------|
33+
| FR-001: [requirement] | βœ… Implemented | [notes] |
34+
| FR-002: [requirement] | ⚠️ Partial | [what's missing] |
35+
| FR-003: [requirement] | ❌ Missing | [recommendation] |
36+
37+
**Coverage**: [X]/[Y] requirements implemented ([Z]%)
38+
39+
---
40+
41+
## Test Coverage Assessment
42+
43+
| Area | Tests Exist? | Coverage | Gaps |
44+
|------|-------------|----------|------|
45+
| [Module/Feature] | βœ…/❌ | [%] | [untested paths] |
46+
47+
---
48+
49+
## Metrics Summary
50+
51+
| Metric | Value |
52+
|--------|-------|
53+
| Files reviewed | [count] |
54+
| πŸ”΄ Blockers | [count] |
55+
| 🟑 Warnings | [count] |
56+
| 🟒 Suggestions | [count] |
57+
| Spec coverage | [%] |
58+
| Test coverage | [%] |
59+
60+
---
61+
62+
## Recommended Actions
63+
64+
### Must Fix (Blockers)
65+
1. [Action item with specific file and fix description]
66+
67+
### Should Fix (Warnings)
68+
1. [Action item]
69+
70+
### Nice to Fix (Suggestions)
71+
1. [Action item]
72+
73+
---
74+
75+
*Generated by `/speckit.review` β€” Staff-level code review for spec-driven development.*

0 commit comments

Comments
Β (0)