claude-flow-novice 2.14.36 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/.claude/commands/cfn-loop-cli.md +491 -456
  2. package/.claude/commands/switch-api.md +33 -12
  3. package/.claude/skills/cfn-agent-spawning/get-agent-provider-env.sh +107 -0
  4. package/.claude/skills/cfn-agent-spawning/parse-agent-provider.sh +59 -0
  5. package/.claude/skills/cfn-docker-agent-spawning/spawn-agent.sh +24 -6
  6. package/.claude/skills/cfn-loop-orchestration/helpers/spawn-agents.sh +18 -9
  7. package/.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh +220 -220
  8. package/claude-assets/agents/cfn-dev-team/developers/backend-developer.md +5 -0
  9. package/claude-assets/agents/custom/claude-code-expert.md +151 -2
  10. package/claude-assets/agents/docker-coordinators/cfn-docker-v3-coordinator.md +43 -3
  11. package/claude-assets/commands/cfn-loop-cli.md +491 -456
  12. package/claude-assets/commands/switch-api.md +33 -12
  13. package/claude-assets/skills/cfn-agent-spawning/get-agent-provider-env.sh +107 -0
  14. package/claude-assets/skills/cfn-agent-spawning/parse-agent-provider.sh +59 -0
  15. package/claude-assets/skills/cfn-docker-agent-spawning/spawn-agent.sh +24 -6
  16. package/claude-assets/skills/cfn-error-logging/SKILL.md +339 -0
  17. package/claude-assets/skills/cfn-error-logging/cleanup-error-logs.sh +334 -0
  18. package/claude-assets/skills/cfn-error-logging/integrate-cli.sh +232 -0
  19. package/claude-assets/skills/cfn-error-logging/integrate-docker.sh +294 -0
  20. package/claude-assets/skills/cfn-error-logging/invoke-error-logging.sh +839 -0
  21. package/claude-assets/skills/cfn-error-logging/test-error-logging.sh +475 -0
  22. package/claude-assets/skills/cfn-loop-orchestration/helpers/spawn-agents.sh +18 -9
  23. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +5 -3
  24. package/claude-assets/skills/cfn-redis-coordination/invoke-waiting-mode.sh +220 -220
  25. package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +21 -9
  26. package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +3 -1
  27. package/dist/hello.js +27 -3
  28. package/dist/hello.js.map +1 -1
  29. package/dist/server.js +194 -0
  30. package/dist/server.js.map +1 -0
  31. package/dist/server.test.js +207 -0
  32. package/dist/server.test.js.map +1 -0
  33. package/package.json +2 -1
  34. package/scripts/switch-api.sh +140 -12
@@ -1,457 +1,492 @@
1
- ---
2
- description: "Execute CFN Loop in CLI mode (production, cost-optimized, 95-98% savings)"
3
- argument-hint: "<task description> [--mode=mvp|standard|enterprise] [--max-iterations=n]"
4
- allowed-tools: ["Task", "TodoWrite", "Read", "Bash"]
5
- ---
6
-
7
- # CFN Loop CLI Mode - Production Execution
8
-
9
- Execute CFN Loop using CLI spawning for maximum cost savings (95-98% vs Task tool).
10
-
11
- 🚨 **CLI MODE: Production, Cost-Optimized, Background Execution**
12
-
13
- **Task**: $ARGUMENTS
14
-
15
- ## What is CLI Mode?
16
-
17
- **CLI Mode Architecture v3.0 (Enhanced):**
18
- - Main Chat processes **slash command** then spawns coordinator agent via CLI with background=true
19
- - Coordinator spawns **all workers via CLI** with background=true for cost optimization
20
- - All CLI agents use **Z.ai custom routing** (when enabled)
21
- - **Real-time monitoring** with automatic recovery from stuck agents
22
- - Background execution with **Redis monitoring** and progress visibility
23
- - **Enhanced features**: Process health checking, context validation, broadcast protocol
24
-
25
-
26
- ## Prerequisites
27
-
28
- **Enable Z.ai Custom Routing (One-Time Setup):**
29
- ```bash
30
- /switch-api zai
31
- ```
32
-
33
- **Verify Status:**
34
- ```bash
35
- /switch-api status
36
- # Expected: Main Chat=Anthropic, Task=Anthropic, CLI=Z.ai
37
- ```
38
-
39
- ## Command Options
40
-
41
- **Usage Examples:**
42
- ```
43
- # Standard mode (recommended)
44
- /cfn-loop-cli "Implement JWT authentication"
45
-
46
- # MVP mode (fast, lower quality gates)
47
- /cfn-loop-cli "Build prototype feature" --mode=mvp
48
-
49
- # Enterprise mode (high quality, more validators)
50
- /cfn-loop-cli "Production security feature" --mode=enterprise --max-iterations=15
51
- ```
52
-
53
- **Options:**
54
- - `--mode=<mvp|standard|enterprise>`: Quality mode (default: standard)
55
- - `--max-iterations=<n>`: Max iterations per loop (default: 10)
56
-
57
- ## Mode Comparison
58
-
59
- | Mode | Gate | Consensus | Iterations | Validators | Use Case |
60
- |------|------|-----------|------------|------------|----------|
61
- | MVP | ≥0.70 | ≥0.80 | 5 | 2 | Prototypes, proof-of-concept |
62
- | Standard | ≥0.75 | ≥0.90 | 10 | 3-4 | Production features |
63
- | Enterprise | ≥0.85 | ≥0.95 | 15 | 5 | Security, compliance, critical systems |
64
-
65
- ## How CLI Mode Works
66
-
67
- 1. **Main Chat** invokes `/cfn-loop-cli` slash command
68
- 2. **SlashCommand tool** processes command and returns execution instructions to Main Chat
69
- 3. **Main Chat** spawns `cfn-v3-coordinator` agent via bash with background=true
70
- 4. **Coordinator** orchestrates the entire CFN Loop workflow in the background
71
- 5. **Coordinator** spawns **Loop 3 workers via CLI** with background=true
72
- 6. **Loop 3** agents implement the solution and validate against quality gates
73
- 7. **Coordinator** spawns **Loop 2 workers via CLI** for validation
74
- 8. **Product Owner** makes the final decision on deliverables
75
- 9. **Background execution** with Redis coordination for scalability
76
-
77
- **CLI Architecture Pattern:**
78
- - Main Chat → SlashCommand (processing) → Main Chat spawns coordinator via bash
79
- ```bash
80
- npx claude-flow-novice agent cfn-v3-coordinator \
81
- --task-id "cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}" \
82
- --context "TASK_DESCRIPTION='Fix core infrastructure
83
- dependencies' MODE='standard' MAX_ITERATIONS=10" \
84
- --timeout 300 \
85
- --background=true
86
- ```
87
- - All agents spawned via CLI by coordinator with Z.ai routing and background execution
88
- - Background execution enables monitoring and recovery capabilities
89
-
90
- ## Main Chat Monitoring Instructions
91
-
92
- **After spawning the coordinator, Main Chat should:**
93
-
94
- ### 1. Immediate Verification (First 30 seconds)
95
- ```bash
96
- # Verify coordinator spawned successfully
97
- TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
98
- pgrep -f "cfn-v3-coordinator" && echo "✅ Coordinator running" || echo "❌ Coordinator failed"
99
-
100
- # Check Redis context was created
101
- redis-cli EXISTS "cfn_loop:task:$TASK_ID:context" && echo "✅ Context stored" || echo "❌ No context"
102
- ```
103
-
104
- ### 2. Progress Monitoring (Every 2-5 minutes for long tasks)
105
- ```bash
106
- # Check iteration progress and confidence scores
107
- redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep -E "(iteration|confidence|status)"
108
-
109
- # Monitor agent completion status
110
- redis-cli LRANGE "swarm:${TASK_ID}:agent:status" 0 -1
111
-
112
- # Quick health check
113
- redis-cli HGET "cfn_loop:task:$TASK_ID:health" "coordinator"
114
- ```
115
-
116
- ### 3. Web Portal Monitoring (Recommended for >10 minute tasks)
117
- ```bash
118
- # Start monitoring dashboard
119
- npm run portal:start
120
-
121
- # Access real-time progress at http://localhost:3000
122
- # - Live agent status dashboard
123
- # - Iteration progress visualization
124
- # - Confidence score trends
125
- # - Error rate monitoring
126
- ```
127
-
128
- ### 4. Background Execution Monitoring Pattern
129
- ```bash
130
- # For long-running tasks, use this monitoring pattern:
131
- sleep 300 # Wait 5 minutes
132
- redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep status
133
-
134
- # If still running, continue monitoring
135
- if [ $? -eq 0 ]; then
136
- echo "Task in progress, monitoring..."
137
- sleep 300 # Wait another 5 minutes
138
- redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep status
139
- fi
140
- ```
141
-
142
- ### 5. Troubleshooting If Coordinator Fails
143
- ```bash
144
- # Investigate missing coordinator
145
- ./.claude/skills/cfn-loop-orchestration/investigate-missing-coordinator.sh "$TASK_ID"
146
-
147
- # Check for process issues
148
- ps aux | grep "claude-flow-novice agent" | grep -v grep
149
-
150
- # Verify Redis connectivity
151
- redis-cli PING
152
- ```
153
-
154
- ## CLI Mode Benefits
155
-
156
- **Performance:**
157
- - Scales linearly with iterations (Task mode scales exponentially)
158
- - Background execution without timeout limitations
159
- - Parallel agent spawning for improved throughput
160
-
161
- **Production Features v3.0:**
162
- - Background execution (no timeout issues)
163
- - Redis state persistence (crash recovery)
164
- - Zero-token waiting (BLPOP blocks without API calls)
165
- - Web portal visibility (http://localhost:3000)
166
- - **Enhanced monitoring**: Real-time agent progress tracking
167
- - **Automatic recovery**: Dead process cleanup and agent restart
168
- - **Protocol compliance**: Prevents "consensus on vapor" anti-patterns
169
- - **Progress visibility**: Detailed reports with timestamps and health status
170
-
171
- **Performance:**
172
- - Parallel agent spawning (no sequential bottleneck)
173
- - Instant wake-up (<100ms latency)
174
- - Scalable (10+ agents, indefinite cycles)
175
-
176
- ## Troubleshooting
177
-
178
- **Custom routing not working:**
179
- ```bash
180
- /switch-api status # Check current provider
181
- /switch-api zai # Enable Z.ai routing
182
- ```
183
-
184
- **Coordinator timeout:**
185
- - Expected for long tasks (>10 min)
186
- - Check web portal for progress: http://localhost:3000
187
- - Query Redis: `redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"`
188
-
189
- **No deliverables created:**
190
- - Orchestrator validates deliverables before PROCEED
191
- - Will force ITERATE if git diff shows zero changes
192
- - Check coordinator output for validation failures
193
-
194
- **Web Portal Access:**
195
- - Monitor real-time agent progress at http://localhost:3000
196
- - View detailed execution logs and health status
197
- - Track iteration progress and confidence scores
198
-
199
- ## Enhanced Monitoring v3.0
200
-
201
- CLI mode includes comprehensive monitoring capabilities for production workflows:
202
-
203
- ### Real-Time Progress Tracking
204
- - **Agent Status**: Monitor individual agent health and progress
205
- - **Iteration Progress**: Track confidence scores and gate validation
206
- - **Resource Usage**: CPU, memory, and Redis connection monitoring
207
- - **Error Detection**: Automatic identification of stuck or failed agents
208
-
209
- ### Monitoring Commands
210
-
211
- **Check Task Status:**
212
- ```bash
213
- # View complete task context and progress
214
- redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"
215
-
216
- # Monitor agent completion status
217
- redis-cli LRANGE "swarm:${TASK_ID}:agent:status" 0 -1
218
- ```
219
-
220
- **Agent Health Monitoring:**
221
- ```bash
222
- # Check if coordinator is running
223
- pgrep -f "cfn-v3-coordinator" && echo "Coordinator alive" || echo "Coordinator missing"
224
-
225
- # Monitor active agent processes
226
- ps aux | grep "claude-flow-novice agent" | grep -v grep
227
-
228
- # Check Redis connectivity
229
- redis-cli PING
230
- ```
231
-
232
- **Progress Monitoring:**
233
- ```bash
234
- # Real-time agent completion monitoring
235
- watch -n 5 'redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep -E "(iteration|confidence|status)"'
236
-
237
- # Monitor agent signals
238
- redis-cli PUBLISH "swarm:${TASK_ID}:monitor" "status_check"
239
- ```
240
-
241
- ### Automatic Recovery Features
242
-
243
- **Dead Process Detection:**
244
- - Automatically detects and reports stuck agents
245
- - Process health checking with configurable timeouts
246
- - Automatic cleanup of orphaned Redis connections
247
-
248
- **Agent Restart Capability:**
249
- - Coordinator can restart failed agents automatically
250
- - Context preservation across agent restarts
251
- - Iteration state recovery from Redis persistence
252
-
253
- **Error Recovery Patterns:**
254
- - Timeout detection and agent termination
255
- - Context validation before spawning replacements
256
- - Graceful degradation with partial agent sets
257
-
258
- ### Monitoring Dashboard Features
259
-
260
- **Web Portal (http://localhost:3000):**
261
- - Live agent status dashboard
262
- - Iteration progress visualization
263
- - Confidence score trends
264
- - Error rate monitoring
265
- - Resource usage graphs
266
-
267
- **CLI Monitoring Tools:**
268
- - `cfn-portal` - Start/stop monitoring dashboard
269
- - `cfn-context` - Query task context and status
270
- - `cfn-metrics` - View performance analytics
271
- - `cfn-redis` - Direct Redis inspection tools
272
-
273
- ### Troubleshooting Monitoring Issues
274
-
275
- **Missing Coordinator:**
276
- ```bash
277
- # Investigate coordinator failure
278
- ./.claude/skills/cfn-loop-orchestration/investigate-missing-coordinator.sh "$TASK_ID"
279
-
280
- # Check for namespace mismatches
281
- redis-cli KEYS "cfn_loop:*" | head -10
282
- ```
283
-
284
- **Stuck Agents:**
285
- ```bash
286
- # Force cleanup of stuck agents
287
- ./.claude/skills/cfn-loop-orchestration/cleanup-stuck-agents.sh "$TASK_ID"
288
-
289
- # Monitor agent timeouts
290
- redis-cli HGET "cfn_loop:task:$TASK_ID:timeouts" "agent_timeouts"
291
- ```
292
-
293
- **Redis Connection Issues:**
294
- ```bash
295
- # Test Redis connectivity
296
- redis-cli -n 0 PING
297
-
298
- # Check Redis memory usage
299
- redis-cli INFO memory | grep used_memory_human
300
-
301
- # Monitor Redis keyspace
302
- redis-cli DBSIZE
303
- ```
304
-
305
- ## Usage Examples
306
-
307
- **Simple API Development:**
308
- ```
309
- /cfn-loop-cli "Build REST API with user authentication"
310
- ```
311
-
312
- **Complex Feature with High Quality Requirements:**
313
- ```
314
- /cfn-loop-cli "Implement payment processing with PCI compliance" --mode=enterprise --max-iterations=15
315
- ```
316
-
317
- **Quick Prototype:**
318
- ```
319
- /cfn-loop-cli "Build MVP landing page" --mode=mvp
320
- ```
321
-
322
- **Infrastructure Deployment:**
323
- ```
324
- /cfn-loop-cli "Set up CI/CD pipeline for microservices"
325
- ```
326
-
327
- ## Related Commands
328
-
329
- - **Task Mode**: `/cfn-loop-task` (debugging, full visibility)
330
- - **Frontend**: `/cfn-loop-frontend` (visual iteration workflow)
331
- - **Documentation**: `/cfn-loop-document` (generate docs)
332
-
333
- ## Related Documentation
334
-
335
- - Task Mode Guide: `.claude/commands/cfn/CFN_LOOP_TASK_MODE.md`
336
- - Coordinator Parameters: `.claude/commands/cfn/CFN_COORDINATOR_PARAMETERS.md`
337
- - Redis Coordination: `.claude/skills/cfn-redis-coordination/SKILL.md`
338
- - Orchestration: `.claude/skills/cfn-loop-orchestration/SKILL.md`
339
-
340
- ---
341
-
342
- ## 🚨 EXECUTION INSTRUCTIONS (Internal Use)
343
-
344
- **Main Chat: Slash command processing followed by CLI coordinator spawning:**
345
-
346
- The SlashCommand tool processes the command and returns execution instructions. Main Chat then spawns the coordinator agent using CLI with background=true for monitoring capabilities.
347
-
348
- **Coordinator Spawning Pattern:**
349
-
350
- ```bash
351
- # Generate unique task ID
352
- TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
353
-
354
- # Extract task description and mode from slash command
355
- TASK_DESCRIPTION="$ARGUMENTS"
356
- MODE="${mode:-standard}"
357
- MAX_ITERATIONS="${maxIterations:-10}"
358
-
359
- # Spawn coordinator via CLI (background execution)
360
- npx claude-flow-novice agent cfn-v3-coordinator \
361
- --task-id "$TASK_ID" \
362
- --context "TASK_DESCRIPTION='$TASK_DESCRIPTION' MODE='$MODE' MAX_ITERATIONS=$MAX_ITERATIONS" \
363
- --timeout 300 \
364
- --background=true
365
- ```
366
-
367
- **Main Chat Execution Command:**
368
-
369
- ```bash
370
- # Main Chat should execute this command after processing slash command
371
- npx claude-flow-novice agent cfn-v3-coordinator \
372
- --task-id "cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}" \
373
- --context "TASK_DESCRIPTION='Fix core infrastructure dependencies - lucide-wrappers.tsx LucideIcon React 18 compatibility, resolve module export errors in types/, establish proper import path resolution' MODE='standard' MAX_ITERATIONS=10" \
374
- --timeout 300 \
375
- --background=true
376
- ```
377
-
378
- **Internal Coordinator Pattern (what the coordinator does):**
379
-
380
- ```bash
381
- # Generate unique task ID
382
- TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
383
-
384
- # Extract task description and mode from slash command arguments
385
- TASK_DESCRIPTION="parsed from $ARGUMENTS"
386
- MODE="${mode:-standard}"
387
- MAX_ITERATIONS="${maxIterations:-10}"
388
-
389
- # Determine appropriate agents based on task complexity
390
- TASK_COMPLEXITY="standard" # auto-detect or pass from command
391
- case "$TASK_COMPLEXITY" in
392
- "simple")
393
- LOOP3_AGENTS="backend-dev,researcher"
394
- LOOP2_AGENTS="reviewer,tester"
395
- ;;
396
- "standard")
397
- LOOP3_AGENTS="backend-dev,researcher,devops"
398
- LOOP2_AGENTS="reviewer,tester,architect,security-specialist"
399
- ;;
400
- "complex")
401
- LOOP3_AGENTS="backend-dev,researcher,devops,rust-developer"
402
- LOOP2_AGENTS="reviewer,tester,architect,security-specialist,code-analyzer"
403
- ;;
404
- esac
405
-
406
- # Coordinator spawns CLI workers (background execution)
407
- npx claude-flow-novice agent "$LOOP3_AGENT" \
408
- --task-id "$TASK_ID" \
409
- --agent-id "$AGENT_ID" \
410
- --context "Complete deliverables and acceptance criteria" \
411
- --timeout 300 \
412
- --background=true
413
-
414
- # Monitor progress (required for background tasks)
415
- # redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"
416
- ```
417
-
418
- **Critical Background Execution Instructions:**
419
-
420
- 1. **Always use `--background=true`** for CLI mode to enable:
421
- - Non-blocking coordinator execution
422
- - Real-time monitoring capabilities
423
- - Redis state persistence
424
- - Automatic recovery features
425
-
426
- 2. **Background execution means:**
427
- - Coordinator runs independently of Main Chat
428
- - Main Chat can monitor progress via Redis queries
429
- - Long-running tasks won't timeout due to Bash tool limitations
430
- - Web portal can track agent progress in real-time
431
-
432
- 3. **Without `--background=true`:**
433
- - Coordinator blocks Main Chat execution
434
- - No monitoring capabilities
435
- - Timeouts after 10 minutes (Bash tool limit)
436
- - No recovery or persistence features
437
-
438
- **Why This Pattern:**
439
- - ✅ Coordinator via CLI with background=true for monitoring capabilities
440
- - ✅ All agents via CLI for maximum cost optimization (95-98% savings)
441
- - Background execution with enhanced monitoring
442
- - Z.ai routing automatically applied to all CLI agents
443
- - Redis coordination for agent communication
444
- - Enhanced monitoring and recovery capabilities
445
- - Clean separation: Main Chat → SlashCommand (processing) → Main Chat spawns CLI(coordinator) → CLI Workers
446
- - Production-ready with real-time progress tracking
447
- - ✅ No timeout limitations with `--background=true`
448
-
449
- **Enhanced Monitoring Benefits:**
450
- - Real-time agent progress tracking via Redis
451
- - Automatic recovery from stuck agents
452
- - Web portal visibility (http://localhost:3000)
453
- - Process health checking and cleanup
454
- - Context validation and preservation
455
- - Performance metrics and analytics
456
-
1
+ ---
2
+ description: "Execute CFN Loop in CLI mode (production, cost-optimized, 95-98% savings)"
3
+ argument-hint: "<task description> [--mode=mvp|standard|enterprise] [--max-iterations=n]"
4
+ allowed-tools: ["Task", "TodoWrite", "Read", "Bash"]
5
+ ---
6
+
7
+ # CFN Loop CLI Mode - Production Execution
8
+
9
+ 🚨 **IMPORTANT: This slash command MUST auto-execute the coordinator spawn via Bash tool.**
10
+
11
+ **DO NOT just show instructions. EXECUTE the bash command immediately after reading this.**
12
+
13
+ ---
14
+
15
+ ## Execution Instructions (AUTO-EXECUTE)
16
+
17
+ **Step 1: Parse Arguments**
18
+ ```
19
+ TASK_DESCRIPTION: $ARGUMENTS (extract task, remove flags)
20
+ MODE: Parse from --mode flag or default to "standard"
21
+ MAX_ITERATIONS: Parse from --max-iterations flag or default to 10
22
+ ```
23
+
24
+ **Step 2: Generate Task ID**
25
+ ```bash
26
+ TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
27
+ ```
28
+
29
+ **Step 3: Spawn Coordinator (REQUIRED - Execute this command now via Bash tool)**
30
+ ```bash
31
+ npx claude-flow-novice agent cfn-v3-coordinator \
32
+ --task-id "$TASK_ID" \
33
+ --context "TASK_DESCRIPTION='$TASK_DESCRIPTION' MODE='$MODE' MAX_ITERATIONS=$MAX_ITERATIONS" \
34
+ --timeout 300 \
35
+ --background=true
36
+ ```
37
+
38
+ **Step 4: Inform User**
39
+ After spawning coordinator, tell user:
40
+ - ✅ CFN Loop coordinator spawned with task ID: $TASK_ID
41
+ - 📊 Monitor progress: `redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"`
42
+ - 🌐 Web dashboard: http://localhost:3000
43
+
44
+ ---
45
+
46
+ ## Background Information (DO NOT show this to user unless they ask)
47
+
48
+ **Task**: $ARGUMENTS
49
+
50
+ ## What is CLI Mode?
51
+
52
+ **CLI Mode Architecture v3.0 (Enhanced):**
53
+ - Main Chat processes **slash command** then spawns coordinator agent via CLI with background=true
54
+ - Coordinator spawns **all workers via CLI** with background=true for cost optimization
55
+ - All CLI agents use **Z.ai custom routing** (when enabled)
56
+ - **Real-time monitoring** with automatic recovery from stuck agents
57
+ - Background execution with **Redis monitoring** and progress visibility
58
+ - **Enhanced features**: Process health checking, context validation, broadcast protocol
59
+
60
+
61
+ ## Prerequisites
62
+
63
+ **Enable Z.ai Custom Routing (One-Time Setup):**
64
+ ```bash
65
+ /switch-api zai
66
+ ```
67
+
68
+ **Verify Status:**
69
+ ```bash
70
+ /switch-api status
71
+ # Expected: Main Chat=Anthropic, Task=Anthropic, CLI=Z.ai
72
+ ```
73
+
74
+ ## Command Options
75
+
76
+ **Usage Examples:**
77
+ ```
78
+ # Standard mode (recommended)
79
+ /cfn-loop-cli "Implement JWT authentication"
80
+
81
+ # MVP mode (fast, lower quality gates)
82
+ /cfn-loop-cli "Build prototype feature" --mode=mvp
83
+
84
+ # Enterprise mode (high quality, more validators)
85
+ /cfn-loop-cli "Production security feature" --mode=enterprise --max-iterations=15
86
+ ```
87
+
88
+ **Options:**
89
+ - `--mode=<mvp|standard|enterprise>`: Quality mode (default: standard)
90
+ - `--max-iterations=<n>`: Max iterations per loop (default: 10)
91
+
92
+ ## Mode Comparison
93
+
94
+ | Mode | Gate | Consensus | Iterations | Validators | Use Case |
95
+ |------|------|-----------|------------|------------|----------|
96
+ | MVP | ≥0.70 | ≥0.80 | 5 | 2 | Prototypes, proof-of-concept |
97
+ | Standard | ≥0.75 | ≥0.90 | 10 | 3-4 | Production features |
98
+ | Enterprise | ≥0.85 | ≥0.95 | 15 | 5 | Security, compliance, critical systems |
99
+
100
+ ## How CLI Mode Works
101
+
102
+ 1. **Main Chat** invokes `/cfn-loop-cli` slash command
103
+ 2. **SlashCommand tool** processes command and returns execution instructions to Main Chat
104
+ 3. **Main Chat** spawns `cfn-v3-coordinator` agent via bash with background=true
105
+ 4. **Coordinator** orchestrates the entire CFN Loop workflow in the background
106
+ 5. **Coordinator** spawns **Loop 3 workers via CLI** with background=true
107
+ 6. **Loop 3** agents implement the solution and validate against quality gates
108
+ 7. **Coordinator** spawns **Loop 2 workers via CLI** for validation
109
+ 8. **Product Owner** makes the final decision on deliverables
110
+ 9. **Background execution** with Redis coordination for scalability
111
+
112
+ **CLI Architecture Pattern:**
113
+ - Main Chat → SlashCommand (processing) → Main Chat spawns coordinator via bash
114
+ ```bash
115
+ npx claude-flow-novice agent cfn-v3-coordinator \
116
+ --task-id "cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}" \
117
+ --context "TASK_DESCRIPTION='Fix core infrastructure
118
+ dependencies' MODE='standard' MAX_ITERATIONS=10" \
119
+ --timeout 300 \
120
+ --background=true
121
+ ```
122
+ - All agents spawned via CLI by coordinator with Z.ai routing and background execution
123
+ - Background execution enables monitoring and recovery capabilities
124
+
125
+ ## Main Chat Monitoring Instructions
126
+
127
+ **After spawning the coordinator, Main Chat should:**
128
+
129
+ ### 1. Immediate Verification (First 30 seconds)
130
+ ```bash
131
+ # Verify coordinator spawned successfully
132
+ TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
133
+ pgrep -f "cfn-v3-coordinator" && echo "✅ Coordinator running" || echo "❌ Coordinator failed"
134
+
135
+ # Check Redis context was created
136
+ redis-cli EXISTS "cfn_loop:task:$TASK_ID:context" && echo " Context stored" || echo "❌ No context"
137
+ ```
138
+
139
+ ### 2. Progress Monitoring (Every 2-5 minutes for long tasks)
140
+ ```bash
141
+ # Check iteration progress and confidence scores
142
+ redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep -E "(iteration|confidence|status)"
143
+
144
+ # Monitor agent completion status
145
+ redis-cli LRANGE "swarm:${TASK_ID}:agent:status" 0 -1
146
+
147
+ # Quick health check
148
+ redis-cli HGET "cfn_loop:task:$TASK_ID:health" "coordinator"
149
+ ```
150
+
151
+ ### 3. Web Portal Monitoring (Recommended for >10 minute tasks)
152
+ ```bash
153
+ # Start monitoring dashboard
154
+ npm run portal:start
155
+
156
+ # Access real-time progress at http://localhost:3000
157
+ # - Live agent status dashboard
158
+ # - Iteration progress visualization
159
+ # - Confidence score trends
160
+ # - Error rate monitoring
161
+ ```
162
+
163
+ ### 4. Background Execution Monitoring Pattern
164
+ ```bash
165
+ # For long-running tasks, use this monitoring pattern:
166
+ sleep 300 # Wait 5 minutes
167
+ redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep status
168
+
169
+ # If still running, continue monitoring
170
+ if [ $? -eq 0 ]; then
171
+ echo "Task in progress, monitoring..."
172
+ sleep 300 # Wait another 5 minutes
173
+ redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep status
174
+ fi
175
+ ```
176
+
177
+ ### 5. Troubleshooting If Coordinator Fails
178
+ ```bash
179
+ # Investigate missing coordinator
180
+ ./.claude/skills/cfn-loop-orchestration/investigate-missing-coordinator.sh "$TASK_ID"
181
+
182
+ # Check for process issues
183
+ ps aux | grep "claude-flow-novice agent" | grep -v grep
184
+
185
+ # Verify Redis connectivity
186
+ redis-cli PING
187
+ ```
188
+
189
+ ## CLI Mode Benefits
190
+
191
+ **Performance:**
192
+ - Scales linearly with iterations (Task mode scales exponentially)
193
+ - Background execution without timeout limitations
194
+ - Parallel agent spawning for improved throughput
195
+
196
+ **Production Features v3.0:**
197
+ - Background execution (no timeout issues)
198
+ - Redis state persistence (crash recovery)
199
+ - Zero-token waiting (BLPOP blocks without API calls)
200
+ - Web portal visibility (http://localhost:3000)
201
+ - **Enhanced monitoring**: Real-time agent progress tracking
202
+ - **Automatic recovery**: Dead process cleanup and agent restart
203
+ - **Protocol compliance**: Prevents "consensus on vapor" anti-patterns
204
+ - **Progress visibility**: Detailed reports with timestamps and health status
205
+
206
+ **Performance:**
207
+ - Parallel agent spawning (no sequential bottleneck)
208
+ - Instant wake-up (<100ms latency)
209
+ - Scalable (10+ agents, indefinite cycles)
210
+
211
+ ## Troubleshooting
212
+
213
+ **Custom routing not working:**
214
+ ```bash
215
+ /switch-api status # Check current provider
216
+ /switch-api zai # Enable Z.ai routing
217
+ ```
218
+
219
+ **Coordinator timeout:**
220
+ - Expected for long tasks (>10 min)
221
+ - Check web portal for progress: http://localhost:3000
222
+ - Query Redis: `redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"`
223
+
224
+ **No deliverables created:**
225
+ - Orchestrator validates deliverables before PROCEED
226
+ - Will force ITERATE if git diff shows zero changes
227
+ - Check coordinator output for validation failures
228
+
229
+ **Web Portal Access:**
230
+ - Monitor real-time agent progress at http://localhost:3000
231
+ - View detailed execution logs and health status
232
+ - Track iteration progress and confidence scores
233
+
234
+ ## Enhanced Monitoring v3.0
235
+
236
+ CLI mode includes comprehensive monitoring capabilities for production workflows:
237
+
238
+ ### Real-Time Progress Tracking
239
+ - **Agent Status**: Monitor individual agent health and progress
240
+ - **Iteration Progress**: Track confidence scores and gate validation
241
+ - **Resource Usage**: CPU, memory, and Redis connection monitoring
242
+ - **Error Detection**: Automatic identification of stuck or failed agents
243
+
244
+ ### Monitoring Commands
245
+
246
+ **Check Task Status:**
247
+ ```bash
248
+ # View complete task context and progress
249
+ redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"
250
+
251
+ # Monitor agent completion status
252
+ redis-cli LRANGE "swarm:${TASK_ID}:agent:status" 0 -1
253
+ ```
254
+
255
+ **Agent Health Monitoring:**
256
+ ```bash
257
+ # Check if coordinator is running
258
+ pgrep -f "cfn-v3-coordinator" && echo "Coordinator alive" || echo "Coordinator missing"
259
+
260
+ # Monitor active agent processes
261
+ ps aux | grep "claude-flow-novice agent" | grep -v grep
262
+
263
+ # Check Redis connectivity
264
+ redis-cli PING
265
+ ```
266
+
267
+ **Progress Monitoring:**
268
+ ```bash
269
+ # Real-time agent completion monitoring
270
+ watch -n 5 'redis-cli HGETALL "cfn_loop:task:$TASK_ID:context" | grep -E "(iteration|confidence|status)"'
271
+
272
+ # Monitor agent signals
273
+ redis-cli PUBLISH "swarm:${TASK_ID}:monitor" "status_check"
274
+ ```
275
+
276
+ ### Automatic Recovery Features
277
+
278
+ **Dead Process Detection:**
279
+ - Automatically detects and reports stuck agents
280
+ - Process health checking with configurable timeouts
281
+ - Automatic cleanup of orphaned Redis connections
282
+
283
+ **Agent Restart Capability:**
284
+ - Coordinator can restart failed agents automatically
285
+ - Context preservation across agent restarts
286
+ - Iteration state recovery from Redis persistence
287
+
288
+ **Error Recovery Patterns:**
289
+ - Timeout detection and agent termination
290
+ - Context validation before spawning replacements
291
+ - Graceful degradation with partial agent sets
292
+
293
+ ### Monitoring Dashboard Features
294
+
295
+ **Web Portal (http://localhost:3000):**
296
+ - Live agent status dashboard
297
+ - Iteration progress visualization
298
+ - Confidence score trends
299
+ - Error rate monitoring
300
+ - Resource usage graphs
301
+
302
+ **CLI Monitoring Tools:**
303
+ - `cfn-portal` - Start/stop monitoring dashboard
304
+ - `cfn-context` - Query task context and status
305
+ - `cfn-metrics` - View performance analytics
306
+ - `cfn-redis` - Direct Redis inspection tools
307
+
308
+ ### Troubleshooting Monitoring Issues
309
+
310
+ **Missing Coordinator:**
311
+ ```bash
312
+ # Investigate coordinator failure
313
+ ./.claude/skills/cfn-loop-orchestration/investigate-missing-coordinator.sh "$TASK_ID"
314
+
315
+ # Check for namespace mismatches
316
+ redis-cli KEYS "cfn_loop:*" | head -10
317
+ ```
318
+
319
+ **Stuck Agents:**
320
+ ```bash
321
+ # Force cleanup of stuck agents
322
+ ./.claude/skills/cfn-loop-orchestration/cleanup-stuck-agents.sh "$TASK_ID"
323
+
324
+ # Monitor agent timeouts
325
+ redis-cli HGET "cfn_loop:task:$TASK_ID:timeouts" "agent_timeouts"
326
+ ```
327
+
328
+ **Redis Connection Issues:**
329
+ ```bash
330
+ # Test Redis connectivity
331
+ redis-cli -n 0 PING
332
+
333
+ # Check Redis memory usage
334
+ redis-cli INFO memory | grep used_memory_human
335
+
336
+ # Monitor Redis keyspace
337
+ redis-cli DBSIZE
338
+ ```
339
+
340
+ ## Usage Examples
341
+
342
+ **Simple API Development:**
343
+ ```
344
+ /cfn-loop-cli "Build REST API with user authentication"
345
+ ```
346
+
347
+ **Complex Feature with High Quality Requirements:**
348
+ ```
349
+ /cfn-loop-cli "Implement payment processing with PCI compliance" --mode=enterprise --max-iterations=15
350
+ ```
351
+
352
+ **Quick Prototype:**
353
+ ```
354
+ /cfn-loop-cli "Build MVP landing page" --mode=mvp
355
+ ```
356
+
357
+ **Infrastructure Deployment:**
358
+ ```
359
+ /cfn-loop-cli "Set up CI/CD pipeline for microservices"
360
+ ```
361
+
362
+ ## Related Commands
363
+
364
+ - **Task Mode**: `/cfn-loop-task` (debugging, full visibility)
365
+ - **Frontend**: `/cfn-loop-frontend` (visual iteration workflow)
366
+ - **Documentation**: `/cfn-loop-document` (generate docs)
367
+
368
+ ## Related Documentation
369
+
370
+ - Task Mode Guide: `.claude/commands/cfn/CFN_LOOP_TASK_MODE.md`
371
+ - Coordinator Parameters: `.claude/commands/cfn/CFN_COORDINATOR_PARAMETERS.md`
372
+ - Redis Coordination: `.claude/skills/cfn-redis-coordination/SKILL.md`
373
+ - Orchestration: `.claude/skills/cfn-loop-orchestration/SKILL.md`
374
+
375
+ ---
376
+
377
+ ## 🚨 EXECUTION INSTRUCTIONS (Internal Use)
378
+
379
+ **Main Chat: Slash command processing followed by CLI coordinator spawning:**
380
+
381
+ The SlashCommand tool processes the command and returns execution instructions. Main Chat then spawns the coordinator agent using CLI with background=true for monitoring capabilities.
382
+
383
+ **Coordinator Spawning Pattern:**
384
+
385
+ ```bash
386
+ # Generate unique task ID
387
+ TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
388
+
389
+ # Extract task description and mode from slash command
390
+ TASK_DESCRIPTION="$ARGUMENTS"
391
+ MODE="${mode:-standard}"
392
+ MAX_ITERATIONS="${maxIterations:-10}"
393
+
394
+ # Spawn coordinator via CLI (background execution)
395
+ npx claude-flow-novice agent cfn-v3-coordinator \
396
+ --task-id "$TASK_ID" \
397
+ --context "TASK_DESCRIPTION='$TASK_DESCRIPTION' MODE='$MODE' MAX_ITERATIONS=$MAX_ITERATIONS" \
398
+ --timeout 300 \
399
+ --background=true
400
+ ```
401
+
402
+ **Main Chat Execution Command:**
403
+
404
+ ```bash
405
+ # Main Chat should execute this command after processing slash command
406
+ npx claude-flow-novice agent cfn-v3-coordinator \
407
+ --task-id "cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}" \
408
+ --context "TASK_DESCRIPTION='Fix core infrastructure dependencies - lucide-wrappers.tsx LucideIcon React 18 compatibility, resolve module export errors in types/, establish proper import path resolution' MODE='standard' MAX_ITERATIONS=10" \
409
+ --timeout 300 \
410
+ --background=true
411
+ ```
412
+
413
+ **Internal Coordinator Pattern (what the coordinator does):**
414
+
415
+ ```bash
416
+ # Generate unique task ID
417
+ TASK_ID="cfn-cli-$(date +%s%N | tail -c 7)-${RANDOM}"
418
+
419
+ # Extract task description and mode from slash command arguments
420
+ TASK_DESCRIPTION="parsed from $ARGUMENTS"
421
+ MODE="${mode:-standard}"
422
+ MAX_ITERATIONS="${maxIterations:-10}"
423
+
424
+ # Determine appropriate agents based on task complexity
425
+ TASK_COMPLEXITY="standard" # auto-detect or pass from command
426
+ case "$TASK_COMPLEXITY" in
427
+ "simple")
428
+ LOOP3_AGENTS="backend-dev,researcher"
429
+ LOOP2_AGENTS="reviewer,tester"
430
+ ;;
431
+ "standard")
432
+ LOOP3_AGENTS="backend-dev,researcher,devops"
433
+ LOOP2_AGENTS="reviewer,tester,architect,security-specialist"
434
+ ;;
435
+ "complex")
436
+ LOOP3_AGENTS="backend-dev,researcher,devops,rust-developer"
437
+ LOOP2_AGENTS="reviewer,tester,architect,security-specialist,code-analyzer"
438
+ ;;
439
+ esac
440
+
441
+ # Coordinator spawns CLI workers (background execution)
442
+ npx claude-flow-novice agent "$LOOP3_AGENT" \
443
+ --task-id "$TASK_ID" \
444
+ --agent-id "$AGENT_ID" \
445
+ --context "Complete deliverables and acceptance criteria" \
446
+ --timeout 300 \
447
+ --background=true
448
+
449
+ # Monitor progress (required for background tasks)
450
+ # redis-cli HGETALL "cfn_loop:task:$TASK_ID:context"
451
+ ```
452
+
453
+ **Critical Background Execution Instructions:**
454
+
455
+ 1. **Always use `--background=true`** for CLI mode to enable:
456
+ - Non-blocking coordinator execution
457
+ - Real-time monitoring capabilities
458
+ - Redis state persistence
459
+ - Automatic recovery features
460
+
461
+ 2. **Background execution means:**
462
+ - Coordinator runs independently of Main Chat
463
+ - Main Chat can monitor progress via Redis queries
464
+ - Long-running tasks won't timeout due to Bash tool limitations
465
+ - Web portal can track agent progress in real-time
466
+
467
+ 3. **Without `--background=true`:**
468
+ - Coordinator blocks Main Chat execution
469
+ - No monitoring capabilities
470
+ - Timeouts after 10 minutes (Bash tool limit)
471
+ - No recovery or persistence features
472
+
473
+ **Why This Pattern:**
474
+ - ✅ Coordinator via CLI with background=true for monitoring capabilities
475
+ - ✅ All agents via CLI for maximum cost optimization (95-98% savings)
476
+ - ✅ Background execution with enhanced monitoring
477
+ - ✅ Z.ai routing automatically applied to all CLI agents
478
+ - ✅ Redis coordination for agent communication
479
+ - ✅ Enhanced monitoring and recovery capabilities
480
+ - ✅ Clean separation: Main Chat → SlashCommand (processing) → Main Chat spawns CLI(coordinator) → CLI Workers
481
+ - ✅ Production-ready with real-time progress tracking
482
+ - ✅ No timeout limitations with `--background=true`
483
+
484
+ **Enhanced Monitoring Benefits:**
485
+ - Real-time agent progress tracking via Redis
486
+ - Automatic recovery from stuck agents
487
+ - Web portal visibility (http://localhost:3000)
488
+ - Process health checking and cleanup
489
+ - Context validation and preservation
490
+ - Performance metrics and analytics
491
+
457
492
  **Version:** 3.1.0 (2025-11-05) - Removed cost information, added Main Chat monitoring instructions, clarified background execution requirements