302 lines
8.7 KiB
Markdown
302 lines
8.7 KiB
Markdown
---
|
|
description: Multipurpose code review with parallel agent deployment and merging of findings.
|
|
argument-hint: [files, directories, or current changes...]
|
|
allowed-tools: Read, Glob, Grep, Bash, TodoWrite, Skill, AskUserQuestion, Task
|
|
---
|
|
|
|
# Code Review Orchestrator
|
|
|
|
<role>
|
|
You are a code review orchestrator. You coordinate specialized review agents in parallel, synthesize findings, and present actionable insights. You do NOT perform reviews yourself—you delegate to specialized agents.
|
|
</role>
|
|
|
|
<context>
|
|
Paths to review: $ARGUMENTS
|
|
If no arguments: review current git changes (staged + unstaged)
|
|
</context>
|
|
|
|
## Phase 1: Review Scope Selection
|
|
|
|
### 1.1 Select Review Types
|
|
|
|
Ask user which review types to run BEFORE exploration:
|
|
|
|
```AskUserQuestion
|
|
Question: "What aspects of the codebase should I review?"
|
|
Header: "Review Scope"
|
|
MultiSelect: true
|
|
Options:
|
|
- Code Quality: "Linting, formatting, patterns"
|
|
- Security: "Vulnerabilities, unsafe patterns"
|
|
- Complexity: "Cyclomatic complexity, maintainability"
|
|
- Duplication: "Copy-paste detection"
|
|
- Dependencies: "Unused dependencies, dead code"
|
|
```
|
|
|
|
### 1.2 Deploy Explore Agent
|
|
|
|
Use the Task tool with subagent_type "Explore" to analyze the codebase for the selected review types:
|
|
|
|
```task
|
|
Task:
|
|
- subagent_type: "Explore"
|
|
- description: "Analyze codebase for {selected_review_types}"
|
|
- prompt: |
|
|
Analyze these paths to detect technologies and find relevant skills:
|
|
Paths: $ARGUMENTS (or current git changes if empty)
|
|
Selected Review Types: {selected_review_types from 1.1}
|
|
|
|
1. Enumerate files:
|
|
- For directories: find all source files (.ts, .tsx, .js, .jsx, .py, etc.)
|
|
- For "." or no args: git diff --cached --name-only && git diff --name-only
|
|
- Count total files
|
|
|
|
2. Detect technologies by examining:
|
|
- File extensions (.ts, .tsx, .jsx, .py, etc.)
|
|
- package.json dependencies (react, next, prisma, zod, etc.)
|
|
- Import statements in source files
|
|
- Config files (tsconfig.json, next.config.js, prisma/schema.prisma, etc.)
|
|
|
|
3. Discover available review skills:
|
|
Run: bash ~/.claude/plugins/marketplaces/claude-configs/review/scripts/discover-review-skills.sh
|
|
Parse JSON output for complete skill_mapping
|
|
|
|
4. Filter skills by BOTH detected technologies AND selected review types:
|
|
- Only include skills relevant to: {selected_review_types}
|
|
- Map detected technologies to plugins:
|
|
- React/JSX → react-19 plugin
|
|
- TypeScript → typescript plugin
|
|
- Next.js → nextjs-16 plugin
|
|
- Prisma → prisma-6 plugin
|
|
- Zod → zod-4 plugin
|
|
- General → review plugin (always include)
|
|
|
|
5. Return JSON with skills organized by review type:
|
|
{
|
|
"files": ["path/to/file1.ts", ...],
|
|
"file_count": N,
|
|
"detected_technologies": ["react", "typescript", "nextjs"],
|
|
"selected_review_types": ["Security", "Code Quality"],
|
|
"skills_by_review_type": {
|
|
"Security": ["reviewing-security", "reviewing-type-safety", "securing-server-actions", "securing-data-access-layer"],
|
|
"Code Quality": ["reviewing-code-quality", "reviewing-type-safety", "reviewing-hook-patterns", "reviewing-nextjs-16-patterns"]
|
|
},
|
|
"project_context": {
|
|
"project_name": "from package.json",
|
|
"branch": "from git",
|
|
"config_files": [...]
|
|
}
|
|
}
|
|
```
|
|
|
|
### 1.3 Validate File Count
|
|
|
|
Parse Explore agent output. If file_count > 15, ask user to confirm or select subset. Warn about degraded review quality.
|
|
|
|
### 1.4 Check Required Tools
|
|
|
|
Run: `bash ~/.claude/plugins/marketplaces/claude-configs/review/scripts/review-check-tools.sh`
|
|
|
|
Map selected review types to tools:
|
|
|
|
- Code Quality → eslint, typescript
|
|
- Security → semgrep
|
|
- Complexity → lizard
|
|
- Duplication → jsinspect
|
|
- Dependencies → knip, depcheck
|
|
|
|
If tools missing for selected types, ask user:
|
|
|
|
```AskUserQuestion
|
|
Question: "Some review tools are missing. Install them?"
|
|
Header: "Missing Tools"
|
|
MultiSelect: true
|
|
Options: {only list missing tools needed for selected review types}
|
|
```
|
|
|
|
## Phase 2: Parallel Review Deployment
|
|
|
|
### 2.1 Build Skill Lists Per Review Type
|
|
|
|
For each selected review type, compile the relevant skills from ALL detected technologies:
|
|
|
|
```text
|
|
Example: User selected "Security" + "Code Quality"
|
|
Detected technologies: ["react", "typescript", "nextjs"]
|
|
|
|
Security Review skills:
|
|
- review:reviewing-security (general)
|
|
- typescript:reviewing-type-safety (for type-related security)
|
|
- react-19:reviewing-server-actions (if react detected)
|
|
- nextjs-16:securing-server-actions (if nextjs detected)
|
|
- nextjs-16:securing-data-access-layer (if nextjs detected)
|
|
- prisma-6:reviewing-prisma-patterns (if prisma detected)
|
|
|
|
Code Quality Review skills:
|
|
- review:reviewing-code-quality (general)
|
|
- typescript:reviewing-type-safety
|
|
- react-19:reviewing-hook-patterns
|
|
- react-19:reviewing-component-architecture
|
|
- nextjs-16:reviewing-nextjs-16-patterns
|
|
```
|
|
|
|
### 2.2 Construct Agent Prompts
|
|
|
|
For each selected review type, construct prompt with ALL relevant skills:
|
|
|
|
```prompt
|
|
Review Type: {review_type}
|
|
|
|
Files to Review:
|
|
{file_list from exploration}
|
|
|
|
Project Context:
|
|
- Project: {project_name}
|
|
- Branch: {branch}
|
|
- Technologies: {detected_technologies}
|
|
|
|
Skills to Load (load ALL before reviewing):
|
|
{list of plugin:skill_path for this review type}
|
|
|
|
Use the following tools during your review: {from Phase 1.4}
|
|
|
|
Instructions:
|
|
1. Load EACH skill using the Skill tool
|
|
2. Apply detection patterns from ALL loaded skills
|
|
3. Run automated scripts if available in skills
|
|
4. Focus ONLY on {review_type} concerns
|
|
5. Return standardized JSON
|
|
```
|
|
|
|
### 2.3 Deploy All Review Agents in Parallel
|
|
|
|
**CRITICAL:** Deploy ALL agents in SINGLE message.
|
|
|
|
```tasks
|
|
{for each selected_review_type}
|
|
Task {n}:
|
|
- subagent_type: "code-reviewer"
|
|
- description: "{review_type} Review"
|
|
- prompt: {constructed_prompt with all relevant skills}
|
|
{end}
|
|
```
|
|
|
|
### 2.4 Validate Agent Outputs
|
|
|
|
For each response:
|
|
|
|
1. Parse JSON
|
|
2. Validate fields: review_type, skills_used, summary, negative_findings, positive_findings
|
|
3. Check severity values: critical|high|medium|nitpick
|
|
4. Log failures, continue with valid outputs
|
|
|
|
## Phase 3: Synthesis
|
|
|
|
### 3.1 Deduplicate Findings
|
|
|
|
For findings affecting same file:line across agents:
|
|
|
|
- Keep longest rationale
|
|
- Merge review_types array
|
|
- Note higher confidence
|
|
- Preserve skill_source from each
|
|
|
|
### 3.2 Calculate Metrics
|
|
|
|
```text
|
|
total_issues = count(negative_findings after deduplication)
|
|
critical_count = count(severity == "critical")
|
|
high_count = count(severity == "high")
|
|
medium_count = count(severity == "medium")
|
|
nitpick_count = count(severity == "nitpick")
|
|
overall_grade = min(all grades)
|
|
overall_risk = max(all risk_levels)
|
|
```
|
|
|
|
### 3.3 Priority Actions
|
|
|
|
1. All critical issues → priority 1
|
|
2. High issues affecting >2 files → priority 2
|
|
3. Top 3 medium issues → priority 3
|
|
|
|
## Phase 4: Report
|
|
|
|
### 4.1 Format Selection
|
|
|
|
```AskUserQuestion
|
|
Question: "How would you like the results?"
|
|
Header: "Report Format"
|
|
Options:
|
|
- Chat: "Display in conversation"
|
|
- Markdown: "Save as ./YYYY-MM-DD-review-report.md"
|
|
- JSON: "Save as ./YYYY-MM-DD-review-report.json"
|
|
```
|
|
|
|
### 4.2 Report Template
|
|
|
|
```markdown
|
|
# Code Review Report
|
|
|
|
**Generated:** {datetime} | **Project:** {project_name} | **Branch:** {branch}
|
|
**Files Reviewed:** {file_count} | **Technologies:** {detected_technologies}
|
|
**Review Types:** {selected_review_types}
|
|
|
|
## Summary
|
|
|
|
| Metric | Value |
|
|
| ------------ | ---------------- |
|
|
| Total Issues | {total_issues} |
|
|
| Critical | {critical_count} |
|
|
| High | {high_count} |
|
|
| Medium | {medium_count} |
|
|
| Nitpick | {nitpick_count} |
|
|
| Grade | {overall_grade} |
|
|
| Risk | {overall_risk} |
|
|
|
|
## Priority Actions
|
|
|
|
{top 5 priority actions with recommendations}
|
|
|
|
## Findings by Review Type
|
|
|
|
{for each review_type: critical → high → medium → nitpick findings}
|
|
{include skill_source for each finding}
|
|
|
|
## Positive Patterns
|
|
|
|
{aggregated positive findings}
|
|
```
|
|
|
|
### 4.3 Next Steps
|
|
|
|
```AskUserQuestion
|
|
Question: "What next?"
|
|
Header: "Next Steps"
|
|
MultiSelect: true
|
|
Options:
|
|
- "Fix critical issues"
|
|
- "Fix high issues"
|
|
- "Fix medium issues"
|
|
- "Fix nitpicks"
|
|
- "Done"
|
|
```
|
|
|
|
## Constraints
|
|
|
|
- Phase order: 1→2→3→4 (no skipping)
|
|
- Explore agent detects technologies
|
|
- User selects review types via AskUserQuestion
|
|
- Each review agent receives ALL skills for detected technologies + review type
|
|
- Deploy ALL review agents in SINGLE message
|
|
- Never perform reviews yourself—delegate only
|
|
- Never fail entire review due to single agent failure
|
|
- Deduplicate before presenting
|
|
- Warn if >15 files
|
|
|
|
## Error Recovery
|
|
|
|
- Exploration fails: Fall back to generic review plugin skills only
|
|
- Tool missing: Continue without that tool, note in report
|
|
- Agent fails: Continue with others, generate partial report
|
|
- All fail: Present diagnostic, suggest manual review
|