Skip to main content

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 NameCommandsPurposeOutput
Quick Implementationlite-plan -> lite-executeLightweight plan and immediate executionWorking code
Multi-CLI Planningmulti-cli-plan -> lite-executeMulti-perspective analysis and executionWorking code
Bug Fixlite-fix -> lite-executeQuick bug diagnosis and fix executionFixed code
Full Planning + Executionplan -> executeDetailed planning and executionWorking code
Verified Planning + Executionplan -> plan-verify -> executePlanning with verification and executionWorking code
Replanning + Executionreplan -> executeUpdate plan and execute changesWorking code
TDD Planning + Executiontdd-plan -> executeTest-driven development planning and executionWorking code
Test Generation + Executiontest-gen -> executeGenerate test suite and executeGenerated tests

Testing Units

Unit NameCommandsPurposeOutput
Test Validationtest-fix-gen -> test-cycle-executeGenerate test tasks and execute test-fix cycleTests passed

Review Units

Unit NameCommandsPurposeOutput
Code Review (Session)review-session-cycle -> review-fixComplete review cycle and apply fixesFixed code
Code Review (Module)review-module-cycle -> review-fixModule review cycle and apply fixesFixed 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

LevelManual DegreeCCW Coordinator Role
Level 1-4Manual command selectionAuto-combine these commands
Level 5Auto command selectionIntelligent 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

Command Reference

See Commands Documentation for:

  • /ccw-coordinator - Intelligent workflow orchestrator
  • /ccw - Main workflow orchestrator