| name | review-cycle |
| description | Unified multi-dimensional code review with automated fix orchestration. Supports session-based (git changes) and module-based (path patterns) review modes with 7-dimension parallel analysis, iterative deep-dive, and automated fix pipeline. Triggers on "workflow:review-cycle", "workflow:review-session-cycle", "workflow:review-module-cycle", "workflow:review-cycle-fix". |
Review Cycle
Unified multi-dimensional code review orchestrator with dual-mode (session/module) file discovery, 7-dimension parallel analysis, iterative deep-dive on critical findings, and optional automated fix pipeline with intelligent batching and parallel planning.
Architecture Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Review Cycle Orchestrator (SKILL.md) โ
โ โ Pure coordinator: mode detection, phase dispatch, state tracking โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Review Pipeline (Phase 1-5) โ
โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ โ Phase 1 โโ โ Phase 2 โโ โ Phase 3 โโ โ Phase 4 โโ โ Phase 5 โ
โ โDiscoveryโ โParallel โ โAggregateโ โDeep-Diveโ โComplete โ
โ โ Init โ โ Review โ โ โ โ(cond.) โ โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ session| 7 agents severity N agents finalize
โ module รcli-explore calc รcli-explore state
โ โ loop
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
(optional --fix)
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Fix Pipeline (Phase 6-9) โ
โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ โ Phase 6 โโ โ Phase 7 โโ โPhase 7.5 โโ โ Phase 8 โโ โ Phase 9 โ
โ โDiscoveryโ โParallel โ โExport to โ โExecutionโ โComplete โ
โ โBatching โ โPlanning โ โTask JSON โ โOrchestr.โ โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ grouping N agents fix-plan โ M agents aggregate
โ + batch รcli-plan .task/FIX-* รcli-exec + summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Design Principles
- Dual-Mode Review: Session-based (git changes) and module-based (path patterns) share the same review pipeline (Phase 2-5), differing only in file discovery (Phase 1)
- Pure Orchestrator: Execute phases in sequence, parse outputs, pass context between them
- Progressive Phase Loading: Phase docs are read on-demand when that phase executes, not all at once
- Auto-Continue: All phases run autonomously without user intervention between phases
- Subagent Lifecycle: Explicit lifecycle management with spawn_agent โ wait โ close_agent
- Role via agent_type: Subagent roles loaded via TOML
agent_type parameter in spawn_agent (e.g., "cli_explore_agent")
- Optional Fix Pipeline: Phase 6-9 triggered only by explicit
--fix flag or user confirmation after Phase 5
- Content Preservation: All agent prompts, code, schemas preserved verbatim from source commands
Usage
# Review Pipeline (Phase 1-5)
review-cycle <path-pattern> # Module mode
review-cycle [session-id] # Session mode
review-cycle [session-id|path-pattern] [FLAGS] # With flags
# Fix Pipeline (Phase 6-9)
review-cycle --fix <review-dir|export-file> # Fix mode
review-cycle --fix <review-dir> [FLAGS] # Fix with flags
# Flags
--dimensions=dim1,dim2,... Custom dimensions (default: all 7)
--max-iterations=N Max deep-dive iterations (default: 3)
--fix Enter fix pipeline after review or standalone
--resume Resume interrupted fix session
--batch-size=N Findings per planning batch (default: 5, fix mode only)
--export-tasks Export fix-plan findings to .task/FIX-*.json (auto-enabled with --fix)
# Examples
review-cycle src/auth/** # Module: review auth
review-cycle src/auth/**,src/payment/** # Module: multiple paths
review-cycle src/auth/** --dimensions=security,architecture # Module: custom dims
review-cycle WFS-payment-integration # Session: specific
review-cycle # Session: auto-detect
review-cycle --fix ${projectRoot}/.workflow/active/WFS-123/.review/ # Fix: from review dir
review-cycle --fix --resume # Fix: resume session
Mode Detection
function detectMode(args) {
if (args.includes('--fix')) return 'fix';
if (args.match(/\*|\.ts|\.js|\.py|src\/|lib\//)) return 'module';
if (args.match(/^WFS-/) || args.trim() === '') return 'session';
return 'session';
}
| Input Pattern | Detected Mode | Phase Entry |
|---|
src/auth/** | module | Phase 1 (module branch) |
WFS-payment-integration | session | Phase 1 (session branch) |
| (empty) | session | Phase 1 (session branch, auto-detect) |
--fix .review/ | fix | Phase 6 |
--fix --resume | fix | Phase 6 (resume) |
Execution Flow
Input Parsing:
โโ Detect mode (session|module|fix) โ route to appropriate phase entry
Review Pipeline (session or module mode):
Phase 1: Discovery & Initialization
โโ Ref: phases/01-discovery-initialization.md
โโ Session mode: session discovery โ git changed files โ resolve
โโ Module mode: path patterns โ glob expand โ resolve
โโ Common: create session, output dirs, review-state.json, review-progress.json
Phase 2: Parallel Review Coordination
โโ Ref: phases/02-parallel-review.md
โโ Spawn 7 cli-explore-agent instances (Deep Scan mode)
โโ Each produces dimensions/{dimension}.json + reports/{dimension}-analysis.md
โโ Lifecycle: spawn_agent โ batch wait โ close_agent
โโ CLI fallback: Gemini โ Qwen โ Codex
Phase 3: Aggregation
โโ Ref: phases/03-aggregation.md
โโ Load dimension JSONs, calculate severity distribution
โโ Identify cross-cutting concerns (files in 3+ dimensions)
โโ Decision: critical > 0 OR high > 5 OR critical files โ Phase 4
Else โ Phase 5
Phase 4: Iterative Deep-Dive (conditional)
โโ Ref: phases/04-iterative-deep-dive.md
โโ Select critical findings (max 5 per iteration)
โโ Spawn deep-dive agents for root cause analysis
โโ Re-assess severity โ loop back to Phase 3 aggregation
โโ Exit when: no critical findings OR max iterations reached
Phase 5: Review Completion
โโ Ref: phases/05-review-completion.md
โโ Finalize review-state.json + review-progress.json
โโ Prompt user: "Run automated fixes? [Y/n]"
โโ If yes โ Continue to Phase 6
Fix Pipeline (--fix mode or after Phase 5):
Phase 6: Fix Discovery & Batching
โโ Ref: phases/06-fix-discovery-batching.md
โโ Validate export file, create fix session
โโ Intelligent grouping by file+dimension similarity โ batches
Phase 7: Fix Parallel Planning
โโ Ref: phases/07-fix-parallel-planning.md
โโ Spawn N cli-planning-agent instances (โค10 parallel)
โโ Each outputs partial-plan-{batch-id}.json
โโ Lifecycle: spawn_agent โ batch wait โ close_agent
โโ Orchestrator aggregates โ fix-plan.json
Phase 7.5: Export to Task JSON (auto with --fix, or explicit --export-tasks)
โโ Convert fix-plan.json findings โ .task/FIX-{seq}.json
โโ For each finding in fix-plan.json:
โ โโ finding.file โ files[].path (action: "modify")
โ โโ finding.severity โ priority (critical|high|medium|low)
โ โโ finding.fix_description โ description
โ โโ finding.dimension โ scope
โ โโ finding.verification โ convergence.verification
โ โโ finding.changes[] โ convergence.criteria[]
โ โโ finding.fix_steps[] โ implementation[]
โโ Output path: {projectRoot}/.workflow/active/WFS-{id}/.review/.task/FIX-{seq}.json
โโ Each file follows task-schema.json (IDENTITY + CONVERGENCE + FILES required)
โโ source.tool = "review-cycle", source.session_id = WFS-{id}
โ
โโ Generate plan.json (plan-overview-fix-schema) after FIX task export:
โ ```javascript
โ const fixTaskFiles = Glob(`${reviewDir}/.task/FIX-*.json`)
โ const taskIds = fixTaskFiles.map(f => JSON.parse(Read(f)).id).sort()
โ
โ // Guard: skip plan.json if no fix tasks generated
โ if (taskIds.length === 0) {
โ console.warn('No fix tasks generated; skipping plan.json')
โ } else {
โ
โ const planOverview = {
โ summary: `Fix plan from review cycle: ${reviewSummary}`,
โ approach: "Review-driven fix pipeline",
โ task_ids: taskIds,
โ task_count: taskIds.length,
โ complexity: taskIds.length > 5 ? "High" : taskIds.length > 2 ? "Medium" : "Low",
โ fix_context: {
โ root_cause: "Multiple review findings",
โ strategy: "comprehensive_fix",
โ severity: aggregatedFindings.maxSeverity || "Medium", // Derived from max finding severity
โ risk_level: aggregatedFindings.overallRisk || "medium" // Derived from combined risk assessment
โ },
โ test_strategy: {
โ scope: "unit",
โ specific_tests: [],
โ manual_verification: ["Verify all review findings addressed"]
โ },
โ _metadata: {
โ timestamp: getUtc8ISOString(),
โ source: "review-cycle-agent",
โ planning_mode: "agent-based",
โ plan_type: "fix",
โ schema_version: "2.0"
โ }
โ }
โ Write(`${reviewDir}/plan.json`, JSON.stringify(planOverview, null, 2))
โ
โ } // end guard
โ ```
โโ Output path: {reviewDir}/plan.json
Phase 8: Fix Execution
โโ Ref: phases/08-fix-execution.md
โโ Stage-based execution per aggregated timeline
โโ Each group: analyze โ fix โ test โ commit/rollback
โโ Lifecycle: spawn_agent โ wait โ close_agent per group
โโ 100% test pass rate required
Phase 9: Fix Completion
โโ Ref: phases/09-fix-completion.md
โโ Aggregate results โ fix-summary.md
โโ Sync session state: $session-sync -y "Review cycle complete: {findings} findings, {fixed} fixed"
โโ Optional: complete workflow session if all fixes successful
Complete: Review reports + optional fix results
Phase Reference Documents (read on-demand when phase executes):
Core Rules
- Start Immediately: First action is progress tracking initialization, second action is Phase 1 execution
- Mode Detection First: Parse input to determine session/module/fix mode before Phase 1
- Parse Every Output: Extract required data from each phase for next phase
- Auto-Continue: Check progress status to execute next pending phase automatically
- Progressive Phase Loading: Read phase docs ONLY when that phase is about to execute
- DO NOT STOP: Continuous multi-phase workflow until all applicable phases complete
- Conditional Phase 4: Only execute if aggregation triggers iteration (critical > 0 OR high > 5 OR critical files)
- Fix Pipeline Optional: Phase 6-9 only execute with explicit --fix flag or user confirmation
- Explicit Lifecycle: Always close_agent after wait completes to free resources
Data Flow
User Input (path-pattern | session-id | --fix export-file)
โ
[Mode Detection: session | module | fix]
โ
Phase 1: Discovery & Initialization
โ Output: sessionId, reviewId, resolvedFiles, reviewMode, outputDir
โ review-state.json, review-progress.json
Phase 2: Parallel Review Coordination
โ Output: dimensions/*.json, reports/*-analysis.md
Phase 3: Aggregation
โ Output: severityDistribution, criticalFiles, deepDiveFindings
โ Decision: iterate? โ Phase 4 : Phase 5
Phase 4: Iterative Deep-Dive (conditional, loops with Phase 3)
โ Output: iterations/*.json, reports/deep-dive-*.md
โ Loop: re-aggregate โ check criteria โ iterate or exit
Phase 5: Review Completion
โ Output: final review-state.json, review-progress.json
โ Decision: fix? โ Phase 6 : END
Phase 6: Fix Discovery & Batching
โ Output: finding batches (in-memory)
Phase 7: Fix Parallel Planning
โ Output: partial-plan-*.json โ fix-plan.json (aggregated)
Phase 7.5: Export to Task JSON
โ Output: .task/FIX-{seq}.json (per finding, follows task-schema.json)
Phase 8: Fix Execution
โ Output: fix-progress-*.json, git commits
Phase 9: Fix Completion
โ Output: fix-summary.md, fix-history.json
Subagent API Reference
spawn_agent
Create a new subagent with task assignment.
const agentId = spawn_agent({
agent_type: "{agent_type}",
message: `
## TASK ASSIGNMENT
### MANDATORY FIRST STEPS (Agent Execute)
1. Execute: ccw spec load --category "exploration execution"
---
## TASK CONTEXT
${taskContext}
## DELIVERABLES
${deliverables}
`
})
wait_agent
Get results from subagent (only way to retrieve results).
const result = wait_agent({
timeout_ms: 1800000
})
if (result.timed_out) {
followup_task({ target: agentId, message: "STATUS_CHECK: Report current progress, findings so far, and estimated remaining work." })
const status = wait_agent({ timeout_ms: 180000 })
if (status.timed_out) {
followup_task({ target: agentId, message: "FINALIZE: Output all current findings immediately. Time limit reached.", interrupt: true })
const forced = wait_agent({ timeout_ms: 180000 })
if (forced.timed_out) {
close_agent({ target: agentId })
}
}
}
if (result.status[agentId].completed) {
const output = result.status[agentId].completed;
}
followup_task
Assign new work to active subagent (for clarification or follow-up).
followup_task({
target: agentId,
message: `
## CLARIFICATION ANSWERS
${answers}
## NEXT STEP
Continue with analysis generation.
`
})
close_agent
Clean up subagent resources (irreversible).
close_agent({ target: agentId })
Progress Tracking Pattern
Review Pipeline Initialization (before Phase 1):
functions.update_plan([
{ id: "phase-1", title: "Phase 1: Discovery & Initialization", status: "in_progress" },
{ id: "phase-2", title: "Phase 2: Parallel Reviews (7 dimensions)", status: "pending" },
{ id: "phase-3", title: "Phase 3: Aggregation", status: "pending" },
{ id: "phase-4", title: "Phase 4: Deep-dive (conditional)", status: "pending" },
{ id: "phase-5", title: "Phase 5: Review Completion", status: "pending" }
])
Phase Transitions:
- Phase 1 complete:
functions.update_plan([{id: "phase-1", status: "completed"}, {id: "phase-2", status: "in_progress"}])
- Phase 2 complete:
functions.update_plan([{id: "phase-2", status: "completed"}, {id: "phase-3", status: "in_progress"}])
- Phase 3 โ Phase 4 (iteration needed):
functions.update_plan([{id: "phase-3", status: "completed"}, {id: "phase-4", status: "in_progress"}])
- Phase 3 โ Phase 5 (no iteration):
functions.update_plan([{id: "phase-3", status: "completed"}, {id: "phase-4", status: "completed"}, {id: "phase-5", status: "in_progress"}])
- Phase 4 complete:
functions.update_plan([{id: "phase-4", status: "completed"}, {id: "phase-5", status: "in_progress"}])
- Phase 5 complete:
functions.update_plan([{id: "phase-5", status: "completed"}])
During Phase 2 (sub-tasks for each dimension):
โ Security review โ in_progress / completed
โ Architecture review โ in_progress / completed
โ Quality review โ in_progress / completed
... other dimensions
Fix Pipeline (added after Phase 5 if --fix triggered):
functions.update_plan([
{ id: "phase-6", title: "Phase 6: Fix Discovery & Batching", status: "in_progress" },
{ id: "phase-7", title: "Phase 7: Parallel Planning", status: "pending" },
{ id: "phase-7.5", title: "Phase 7.5: Export to Task JSON", status: "pending" },
{ id: "phase-8", title: "Phase 8: Execution", status: "pending" },
{ id: "phase-9", title: "Phase 9: Fix Completion", status: "pending" }
])
Fix Pipeline Transitions:
- Phase 6 complete:
functions.update_plan([{id: "phase-6", status: "completed"}, {id: "phase-7", status: "in_progress"}])
- Phase 7 complete:
functions.update_plan([{id: "phase-7", status: "completed"}, {id: "phase-7.5", status: "in_progress"}])
- Phase 7.5 complete:
functions.update_plan([{id: "phase-7.5", status: "completed"}, {id: "phase-8", status: "in_progress"}])
- Phase 8 complete:
functions.update_plan([{id: "phase-8", status: "completed"}, {id: "phase-9", status: "in_progress"}])
- Phase 9 complete:
functions.update_plan([{id: "phase-9", status: "completed"}])
Error Handling
Review Pipeline Errors
| Phase | Error | Blocking? | Action |
|---|
| Phase 1 | Session not found (session mode) | Yes | Error and exit |
| Phase 1 | No changed files (session mode) | Yes | Error and exit |
| Phase 1 | Invalid path pattern (module mode) | Yes | Error and exit |
| Phase 1 | No files matched (module mode) | Yes | Error and exit |
| Phase 2 | Single dimension fails | No | Log warning, continue other dimensions |
| Phase 2 | All dimensions fail | Yes | Error and exit |
| Phase 3 | Missing dimension JSON | No | Skip in aggregation, log warning |
| Phase 4 | Deep-dive agent fails | No | Skip finding, continue others |
| Phase 4 | Max iterations reached | No | Generate partial report |
Fix Pipeline Errors
| Phase | Error | Blocking? | Action |
|---|
| Phase 6 | Invalid export file | Yes | Abort with error |
| Phase 6 | Empty batches | No | Warn and skip empty |
| Phase 7 | Planning agent timeout | No | Mark batch failed, continue others |
| Phase 7 | All agents fail | Yes | Abort fix session |
| Phase 8 | Test failure after fix | No | Rollback, retry up to max_iterations |
| Phase 8 | Git operations fail | Yes | Abort, preserve state |
| Phase 9 | Aggregation error | No | Generate partial summary |
CLI Fallback Chain
Gemini โ Qwen โ Codex โ degraded mode
Fallback Triggers: HTTP 429/5xx, connection timeout, invalid JSON output, low confidence < 0.4, analysis too brief (< 100 words)
Output File Structure
{projectRoot}/.workflow/active/WFS-{session-id}/.review/
โโโ review-state.json # Orchestrator state machine
โโโ review-progress.json # Real-time progress
โโโ dimensions/ # Per-dimension results (Phase 2)
โ โโโ security.json
โ โโโ architecture.json
โ โโโ quality.json
โ โโโ action-items.json
โ โโโ performance.json
โ โโโ maintainability.json
โ โโโ best-practices.json
โโโ iterations/ # Deep-dive results (Phase 4)
โ โโโ iteration-1-finding-{uuid}.json
โ โโโ iteration-2-finding-{uuid}.json
โโโ reports/ # Human-readable reports
โ โโโ security-analysis.md
โ โโโ security-cli-output.txt
โ โโโ deep-dive-1-{uuid}.md
โ โโโ ...
โโโ .task/ # Task JSON exports (Phase 7.5)
โ โโโ FIX-001.json # Per-finding task (task-schema.json)
โ โโโ FIX-002.json
โ โโโ ...
โโโ plan.json # Plan overview (plan-overview-fix-schema, Phase 7.5)
โโโ fixes/{fix-session-id}/ # Fix results (Phase 6-9)
โโโ partial-plan-*.json
โโโ fix-plan.json
โโโ fix-progress-*.json
โโโ fix-summary.md
โโโ active-fix-session.json
โโโ fix-history.json
Related Commands
View Progress
ccw view
Workflow Pipeline
review-cycle src/auth/**
review-cycle --fix ${projectRoot}/.workflow/active/WFS-{session-id}/.review/
Session Sync
$session-sync -y "Review cycle complete: {findings} findings, {fixed} fixed"