Level 5: Intelligent Workflows
Complexity: All levels | Artifacts: Full state persistence | Automation: Complete
Level 5 workflows provide the most intelligent automation - automated command chain orchestration with sequential execution and state persistence. They auto-analyze requirements, recommend optimal command chains, and execute end-to-end.
Overview
Included Workflow: ccw-coordinator
Auto-analyze & recommend command chains with sequential execution
Command
/ccw-coordinator "Implement user authentication with OAuth2"
# Or simply
/ccw "Add user authentication"
Core Concept: Minimum Execution Units
Definition: A set of commands that must execute together as an atomic group to achieve a meaningful workflow milestone.
Why This Matters:
- Prevents Incomplete States: Avoid stopping after task generation without execution
- User Experience: User gets complete results, not intermediate artifacts requiring manual follow-up
- Workflow Integrity: Maintains logical coherence of multi-step operations
Minimum Execution Units
Planning + Execution Units
| Unit Name | Commands | Purpose | Output |
|---|---|---|---|
| Quick Implementation | lite-plan -> lite-execute | Lightweight plan and immediate execution | Working code |
| Multi-CLI Planning | multi-cli-plan -> lite-execute | Multi-perspective analysis and execution | Working code |
| Bug Fix | lite-fix -> lite-execute | Quick bug diagnosis and fix execution | Fixed code |
| Full Planning + Execution | plan -> execute | Detailed planning and execution | Working code |
| Verified Planning + Execution | plan -> plan-verify -> execute | Planning with verification and execution | Working code |
| Replanning + Execution | replan -> execute | Update plan and execute changes | Working code |
| TDD Planning + Execution | tdd-plan -> execute | Test-driven development planning and execution | Working code |
| Test Generation + Execution | test-gen -> execute | Generate test suite and execute | Generated tests |
Testing Units
| Unit Name | Commands | Purpose | Output |
|---|---|---|---|
| Test Validation | test-fix-gen -> test-cycle-execute | Generate test tasks and execute test-fix cycle | Tests passed |
Review Units
| Unit Name | Commands | Purpose | Output |
|---|---|---|---|
| Code Review (Session) | review-session-cycle -> review-fix | Complete review cycle and apply fixes | Fixed code |
| Code Review (Module) | review-module-cycle -> review-fix | Module review cycle and apply fixes | Fixed code |
3-Phase Workflow
Phase 1: Analyze Requirements
Parse task description to extract: goal, scope, constraints, complexity, and task type.
function analyzeRequirements(taskDescription) {
return {
goal: extractMainGoal(taskDescription), // e.g., "Implement user registration"
scope: extractScope(taskDescription), // e.g., ["auth", "user_management"]
constraints: extractConstraints(taskDescription), // e.g., ["no breaking changes"]
complexity: determineComplexity(taskDescription), // 'simple' | 'medium' | 'complex'
task_type: detectTaskType(taskDescription) // See task type patterns below
};
}
// Task Type Detection Patterns
function detectTaskType(text) {
// Priority order (first match wins)
if (/fix|bug|error|crash|fail|debug|diagnose/.test(text)) return 'bugfix';
if (/tdd|test-driven|test first/.test(text)) return 'tdd';
if (/test fail|fix test|failing test/.test(text)) return 'test-fix';
if (/generate test|add test/.test(text)) return 'test-gen';
if (/review/.test(text)) return 'review';
if (/explore|brainstorm/.test(text)) return 'brainstorm';
if (/multi-perspective|comparison/.test(text)) return 'multi-cli';
return 'feature'; // Default
}
// Complexity Assessment
function determineComplexity(text) {
let score = 0;
if (/refactor|migrate|architect|system/.test(text)) score += 2;
if (/multiple|across|all|entire/.test(text)) score += 2;
if (/integrate|api|database/.test(text)) score += 1;
if (/security|performance|scale/.test(text)) score += 1;
return score >= 4 ? 'complex' : score >= 2 ? 'medium' : 'simple';
}
Phase 2: Discover Commands & Recommend Chain
Dynamic command chain assembly using port-based matching.
Display to user:
Recommended Command Chain:
Pipeline (visual):
Requirement -> lite-plan -> Plan -> lite-execute -> Code -> test-cycle-execute -> Tests Passed
Commands:
1. /workflow:lite-plan
2. /workflow:lite-execute
3. /workflow:test-cycle-execute
Proceed? [Confirm / Show Details / Adjust / Cancel]
Phase 3: Execute Sequential Command Chain
async function executeCommandChain(chain, analysis) {
const sessionId = `ccw-coord-${Date.now()}`;
const stateDir = `.workflow/.ccw-coordinator/${sessionId}`;
// Initialize state
const state = {
session_id: sessionId,
status: 'running',
created_at: new Date().toISOString(),
analysis: analysis,
command_chain: chain.map((cmd, idx) => ({ ...cmd, index: idx, status: 'pending' })),
execution_results: [],
prompts_used: []
};
// Save initial state
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
for (let i = 0; i < chain.length; i++) {
const cmd = chain[i];
// Assemble prompt
let prompt = formatCommand(cmd, state.execution_results, analysis);
prompt += `\n\nTask: ${analysis.goal}`;
if (state.execution_results.length > 0) {
prompt += '\n\nPrevious results:\n';
state.execution_results.forEach(r => {
if (r.session_id) {
prompt += `- ${r.command}: ${r.session_id}\n`;
}
});
}
// Launch CLI in background
const taskId = Bash(
`ccw cli -p "${escapePrompt(prompt)}" --tool claude --mode write`,
{ run_in_background: true }
).task_id;
// Save checkpoint
state.execution_results.push({
index: i,
command: cmd.command,
status: 'in-progress',
task_id: taskId,
session_id: null,
artifacts: [],
timestamp: new Date().toISOString()
});
// Stop here - wait for hook callback
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
break;
}
state.status = 'waiting';
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
return state;
}
State File Structure
Location: .workflow/.ccw-coordinator/{session_id}/state.json
{
"session_id": "ccw-coord-20250203-143025",
"status": "running|waiting|completed|failed",
"created_at": "2025-02-03T14:30:25Z",
"updated_at": "2025-02-03T14:35:45Z",
"analysis": {
"goal": "Implement user registration",
"scope": ["authentication", "user_management"],
"constraints": ["no breaking changes"],
"complexity": "medium",
"task_type": "feature"
},
"command_chain": [
{
"index": 0,
"command": "/workflow:plan",
"name": "plan",
"status": "completed"
},
{
"index": 1,
"command": "/workflow:execute",
"name": "execute",
"status": "running"
}
],
"execution_results": [
{
"index": 0,
"command": "/workflow:plan",
"status": "completed",
"task_id": "task-001",
"session_id": "WFS-plan-20250203",
"artifacts": ["IMPL_PLAN.md"],
"timestamp": "2025-02-03T14:30:25Z",
"completed_at": "2025-02-03T14:30:45Z"
}
]
}
Complete Lifecycle Decision Flowchart
Use Cases
When to Use
- Complex multi-step workflows
- Uncertain which commands to use
- Desire end-to-end automation
- Need full state tracking and resumability
- Team collaboration with unified execution flow
When NOT to Use
- Simple single-command tasks (use Level 1-4 directly)
- Already know exact commands needed (use Level 1-4 directly)
Relationship with Other Levels
| Level | Manual Degree | CCW Coordinator Role |
|---|---|---|
| Level 1-4 | Manual command selection | Auto-combine these commands |
| Level 5 | Auto command selection | Intelligent orchestrator |
CCW Coordinator uses Level 1-4 internally:
- Analyzes task -> Auto-selects appropriate Level
- Assembles command chain -> Includes Level 1-4 commands
- Executes sequentially -> Follows Minimum Execution Units
Related Workflows
- Level 1: Ultra-Lightweight - Rapid execution
- Level 2: Rapid - Lightweight planning
- Level 3: Standard - Complete planning
- Level 4: Brainstorm - Multi-role exploration
- FAQ - Common questions
Command Reference
See Commands Documentation for:
/ccw-coordinator- Intelligent workflow orchestrator/ccw- Main workflow orchestrator