Skip to content

Commit f99e3c9

Browse files
authored
Merge pull request #53 from cahaseler/52-add-comprehensive-code-review-feature-to-cc-track
feat: complete TASK_054 - Add Comprehensive Code Review Feature to cc-track
2 parents d303d9e + 8e552f3 commit f99e3c9

File tree

16 files changed

+1686
-89
lines changed

16 files changed

+1686
-89
lines changed

.claude/backlog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
## Items
1414

1515
<!-- Items will be added below -->
16-
- [2025-09-11] code review command that invokes long running code review agent, optionally using claude cli or codex cli
1716
- [2025-09-11] investigate consistent issues with pre-compaction hook when invoked on manual compaction (Known Claude Code bug: https://github.com/anthropics/claude-code/issues/7530)
1817
- Add automatic file header summaries for all TypeScript files. Each file should start with a block comment containing a one-sentence ai-written summary plus an auto-generated `@exports` list of functions/classes with line numbers. Use the TypeScript compiler API in a Node script to parse ASTs, extract exports, and update headers. Wire it into a pre-commit or post-edit hook so the `@exports` section stays current without manual edits. This makes files self-describing in the first 20 lines for AI tools and repo navigation.
1918
- extract prompts into dedicated config file sections (or their own files? to allow for users to more easily customize them) (may not be practical depending on how dynamically we're building them)
2019
- [2025-09-15] improve task creation with multi-turn claude code sdk invocation in the current working directory instructing claude to investigate any open questions and provide explicit detailed answers in the task file. Also see if we can return a message instructing claude to read this new task file after it's created.
20+
- [2025-09-15] block attempts to add stupid comments with the preToolUse hook

.claude/plans/054.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Plan: 054
2+
3+
Captured: 2025-09-15T12:58:39.440Z
4+
5+
# Plan: Add Comprehensive Code Review Feature to cc-track
6+
7+
## Overview
8+
Add an optional code review feature that runs after validation passes in the prepare-completion phase. When enabled, it will launch a Claude Code SDK agent to perform comprehensive code review and write analysis to `code-reviews/TASK_XXX_[DATE].md`.
9+
10+
## Implementation Steps
11+
12+
### 1. Add Configuration Option
13+
- Add `code_review` section to track.config.json under `features`
14+
- Include only `enabled` flag (default: false)
15+
- Hard-code timeout to 10 minutes (600000ms) and max_turns to 30 in implementation
16+
17+
### 2. Create Code Review Function in ClaudeSDK
18+
- Add `performCodeReview()` function to `src/lib/claude-sdk.ts`
19+
- Parameters: taskId, taskTitle, taskRequirements, gitDiff, projectRoot
20+
- Use Claude SDK with Sonnet model, 10-minute timeout, 30 turns max
21+
- Grant Read, Grep, Glob permissions plus Write/Edit to code-reviews/ directory only
22+
- Return structured review result with markdown content
23+
24+
### 3. Integrate into prepare-completion Command
25+
- After validation passes, check if code_review is enabled in config
26+
- **Check if a review file already exists for this task** (glob for `code-reviews/TASK_XXX_*.md`)
27+
- If review exists, skip the code review and inform user that review already exists
28+
- If no review exists:
29+
- Gather required data: task requirements from task file, git diff from merge base, task ID and title
30+
- Call performCodeReview() function
31+
- Ensure code-reviews/ directory exists
32+
- Write output to `code-reviews/TASK_XXX_[DATE].md`
33+
- Show summary to user with path to review file
34+
35+
### 4. Review File Format
36+
The review file will include:
37+
- Task summary (ID, title, branch)
38+
- Requirements alignment check
39+
- Security assessment
40+
- Code quality analysis
41+
- Performance considerations
42+
- Architectural concerns
43+
- Improvement suggestions
44+
- Overall verdict
45+
46+
### 5. Implementation Details
47+
- Use existing ClaudeSDK patterns with query() function
48+
- Configure with cwd: projectRoot for proper context
49+
- Stream results to capture complete analysis
50+
- Handle timeouts gracefully with partial results
51+
- Use the same dependency injection pattern as other hooks/commands
52+
- **One review per task** - presence of any `TASK_XXX_*.md` file skips review generation
53+
54+
### 6. Testing
55+
- Add tests to prepare-completion.test.ts that mock the ClaudeSDK performCodeReview function
56+
- Test both enabled and disabled code review scenarios
57+
- **Test skipping review when file already exists**
58+
- Test file creation and error handling
59+
- Follow existing test patterns with mock creation functions
60+
61+
## Benefits
62+
- Automated comprehensive code review before task completion
63+
- Consistent review quality and format
64+
- Documentation of code quality decisions
65+
- Security and performance issue detection
66+
- Learning from review patterns over time
67+
- **Idempotent** - can run prepare-completion multiple times without duplicate reviews
68+
69+
## Non-Goals
70+
- This won't block task completion (advisory only)
71+
- Won't modify code automatically
72+
- Won't replace human review for PRs

.claude/tasks/TASK_054.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Add Comprehensive Code Review Feature to cc-track
2+
3+
**Purpose:** Add an optional code review feature that runs after validation passes in the prepare-completion phase, launching a Claude Code SDK agent to perform comprehensive code review and write analysis to code-reviews directory.
4+
5+
**Status:** completed
6+
**Started:** 2025-09-15 08:58
7+
**Task ID:** 054
8+
9+
## Requirements
10+
- [ ] Add `code_review` section to track.config.json under `features` with `enabled` flag (default: false)
11+
- [ ] Create `performCodeReview()` function in `src/lib/claude-sdk.ts`
12+
- [ ] Configure function with taskId, taskTitle, taskRequirements, gitDiff, projectRoot parameters
13+
- [ ] Use Claude SDK with Sonnet model, 10-minute timeout, 30 turns max
14+
- [ ] Grant Read, Grep, Glob permissions plus Write/Edit to code-reviews/ directory only
15+
- [ ] Return structured review result with markdown content
16+
- [ ] Integrate into prepare-completion command after validation passes
17+
- [ ] Check if review file already exists for task (glob for `code-reviews/TASK_XXX_*.md`)
18+
- [ ] Skip review if file already exists and inform user
19+
- [ ] If no review exists, gather task requirements, git diff, task ID and title
20+
- [ ] Ensure code-reviews/ directory exists before writing
21+
- [ ] Write output to `code-reviews/TASK_XXX_[DATE].md` format
22+
- [ ] Show summary to user with path to review file
23+
- [ ] Include task summary, requirements alignment, security assessment, code quality analysis, performance considerations, architectural concerns, improvement suggestions, and overall verdict in review file
24+
- [ ] Add tests to prepare-completion.test.ts that mock the ClaudeSDK performCodeReview function
25+
- [ ] Test both enabled and disabled code review scenarios
26+
- [ ] Test skipping review when file already exists
27+
- [ ] Test file creation and error handling
28+
29+
## Success Criteria
30+
- Code review feature can be enabled/disabled via configuration
31+
- When enabled and no existing review exists, comprehensive code review is generated after validation passes
32+
- Review files are written to code-reviews/ directory with proper naming convention
33+
- Existing reviews are detected and skip duplicate generation
34+
- Feature is fully tested with appropriate mocks
35+
- User receives clear feedback about review generation or skipping
36+
37+
## Technical Approach
38+
- Extend existing ClaudeSDK patterns with new performCodeReview function
39+
- Use dependency injection pattern consistent with other commands
40+
- Configure agent with restricted permissions for security
41+
- Implement idempotent behavior by checking for existing review files
42+
- Follow existing test patterns with mock creation functions
43+
44+
## Recent Progress
45+
- Researched existing codebase structure and patterns for implementing code review feature
46+
- Analyzed validation library (src/lib/validation.ts) to understand current validation flow
47+
- Examined existing code-reviews directory and file naming conventions (TASK_XXX_[DATE].md format)
48+
- Investigated track.config.json structure and configuration patterns
49+
- Reviewed Claude SDK usage patterns in claude-sdk.ts for consistent implementation
50+
- Analyzed prepare-completion command structure and integration points
51+
- Clarified requirements: hardcode 10-minute timeout and 30 turns max (not configurable)
52+
- Implemented performCodeReview() function in claude-sdk.ts with all required parameters
53+
- Added code_review configuration to track.config.json with enabled flag (default: false)
54+
- Integrated code review into prepare-completion command after validation passes
55+
- Implemented idempotent behavior - skips if review file already exists
56+
- Added comprehensive test suite covering all scenarios (enabled/disabled, existing reviews, errors)
57+
- Fixed test to expect full task content instead of just requirements section
58+
- Successfully ran automated code review on own implementation - all requirements met
59+
- Updated Biome configuration to treat all warnings as errors for stricter validation
60+
61+
## Current Focus
62+
63+
Task completed on 2025-09-15
64+
65+
## Open Questions & Blockers
66+
None - task successfully completed with comprehensive code review feature fully operational
67+
68+
## Next Steps
69+
1. Examine current track.config.json structure and config types
70+
2. Add code_review configuration section with proper TypeScript types
71+
3. Create performCodeReview function in claude-sdk.ts
72+
4. Integrate review logic into prepare-completion command
73+
74+
<!-- github_issue: 52 -->
75+
<!-- github_url: https://github.com/cahaseler/cc-track/issues/52 -->
76+
<!-- issue_branch: 52-add-comprehensive-code-review-feature-to-cc-track -->

.claude/track.config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"description": "Block edits on protected branches to enforce feature branch workflow",
7676
"protected_branches": ["main", "master"],
7777
"allow_gitignored": true
78+
},
79+
"code_review": {
80+
"enabled": true,
81+
"description": "Run comprehensive code review using Claude SDK before task completion"
7882
}
7983
},
8084
"logging": {

0 commit comments

Comments
 (0)