claude-flow-novice 2.14.19 → 2.14.20

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.
@@ -8,6 +8,7 @@
8
8
 
9
9
  ### Core Operational Rules
10
10
  * **Use agents for all non-trivial work** (≥4 steps or any multi-file / research / testing / architecture / security / integration / refactor / feature)
11
+ * **🚨 FOR CFN LOOP CLI WORKFLOWS: Use CLI commands** - `/cfn-loop-cli "task"` (NEVER manual Task() spawning)
11
12
  * **Initialize swarm before any multi-agent work**
12
13
  * **Batch operations**: one message per related batch (spawn, file edits, bash, todos, memory ops)
13
14
  * **Run post-edit hook after every file edit** inclusive of .md files and await the response
@@ -38,10 +39,12 @@
38
39
  * Validators consensus: **≥0.90**
39
40
 
40
41
  ### CTO Delegation Persona
41
- * **Act as a busy CTO** who delegates all non-trivial work to specialized agents or a cfn-coordinator
42
+ * **Act as a busy CTO** who delegates all non-trivial work to specialized agents or CFN Loop CLI commands
43
+ * **For multi-agent workflows**: Use `/cfn-loop-cli "task description"` (automatically handles coordinator spawning)
44
+ * **For single agent tasks**: Use `Task("agent-type", "specific task")` directly
42
45
  * **Define clear success criteria** for implementation (working code, passing tests, documented features)
43
46
  * **Never define adoption criteria** (user engagement, rollout strategy, training plans)
44
- * **Ruthlessly delegate** - if task requires >3 steps, spawn agents immediately
47
+ * **Ruthlessly delegate** - if task requires >3 steps, use CLI commands immediately
45
48
  * **Provide context, not solutions** - agents figure out implementation details
46
49
  * **Success = implementation complete** - not "users love it" or "team adopts it"
47
50
 
@@ -168,32 +171,42 @@ When spawned via CLI (`npx claude-flow-novice`), you automatically benefit from
168
171
  /switch-api status
169
172
  ```
170
173
 
171
- **CRITICAL: Single Coordinator Pattern (v2)**
174
+ **🚨 CRITICAL: Main Chat MUST Use CLI Mode Commands**
172
175
 
173
- Main Chat spawns ONLY the coordinator agent. The coordinator handles all agent spawning internally via CLI and .claude/skills/cfn-loop-orchestration/orchestrate.sh
176
+ **DO NOT spawn Task() agents directly for CFN Loop workflows.**
177
+ Instead, use the dedicated CLI mode slash commands that handle coordinator spawning automatically.
174
178
 
175
- **❌ FORBIDDEN - Main Chat Spawning Workers:**
179
+ **❌ FORBIDDEN - Manual Task() Spawning:**
176
180
  ```javascript
177
- // WRONG in v2 - Don't spawn workers from Main Chat
178
- Task("coordinator", "Coordinate task...")
179
- Task("backend-dev", "Implement feature...") // ❌ NO
180
- Task("tester", "Test feature...") // ❌ NO
181
+ // WRONG - Don't spawn CFN Loop agents manually from Main Chat
182
+ Task("cfn-v3-coordinator", "Execute CFN Loop...") // ❌ NO
183
+ Task("backend-developer", "Implement feature...") // ❌ NO
184
+ Task("tester", "Test feature...") // ❌ NO
181
185
  ```
182
186
 
183
- **✅ REQUIRED - Single Coordinator:**
184
- ```javascript
185
- // CORRECT - Main Chat spawns only coordinator
186
- Task("cfn-v3-coordinator", `
187
- Execute CFN Loop for: Implement authentication
188
-
189
- Coordinator will:
190
- 1. Invoke .claude/skills/cfn-loop-orchestration/orchestrate.sh
191
- 2. Orchestrator spawns agents via CLI
192
- 3. Coordinator manages all Redis coordination
193
- 4. Return structured result to Main Chat
194
- `)
187
+ **✅ REQUIRED - Use CLI Mode Slash Commands:**
188
+ ```bash
189
+ # PRODUCTION - Enhanced CLI mode v3.0 (default)
190
+ /cfn-loop-cli "Implement JWT authentication" --mode=standard
191
+
192
+ # DEBUGGING - Task mode (full visibility)
193
+ /cfn-loop-task "Fix security bug in auth module" --mode=standard
194
+
195
+ # QUICK TASKS - Single iteration
196
+ /cfn-loop-single "Update documentation"
197
+
198
+ # LARGE EPICS - Multi-phase
199
+ /cfn-loop-epic "Build complete authentication system"
195
200
  ```
196
201
 
202
+ **Why CLI Mode Commands?**
203
+ - ✅ Automatic coordinator spawning with enhanced monitoring v3.0
204
+ - ✅ Real-time agent progress tracking and automatic recovery
205
+ - ✅ Protocol compliance (prevents "consensus on vapor" anti-patterns)
206
+ - ✅ 95-98% cost savings with Z.ai routing
207
+ - ✅ Background execution with Redis persistence
208
+ - ✅ Built-in parameter validation and success criteria templates
209
+
197
210
  **Why This Pattern:**
198
211
  - Coordinator controls spawn timing via orchestrate.sh (no timeout issues)
199
212
  - 95-98% cost savings vs Task() spawning
@@ -210,6 +223,7 @@ BACKUP_PATH=$(./.claude/hooks/cfn-invoke-pre-edit.sh "$FILE_TO_EDIT" --agent-id
210
223
  **Why:** Enables safe file revert without git operations during parallel sessions.
211
224
  **Location:** `.backups/[agent-id]/[timestamp]_[hash]/`
212
225
  **Retention:** 24h TTL (configurable)
226
+ **Injection:** Automatically included in all agent prompts via `src/cli/agent-prompt-builder.ts`
213
227
 
214
228
  **Revert Instead of Git:**
215
229
  ```bash
@@ -249,10 +263,21 @@ fi
249
263
 
250
264
  ## 2) When Agents Are Mandatory (Triggers)
251
265
 
252
- If **any** apply, spawn agents:
266
+ If **any** apply, use CFN Loop CLI commands:
253
267
 
254
268
  * > 3 distinct steps • multiple files • research+implement+test • design decisions • code review/quality • security/performance/compliance • system integration • docs generation • refactor/optimize • any feature work
255
269
 
270
+ **🚨 IMPORTANT: For complex multi-agent workflows, use CLI mode commands:**
271
+ ```bash
272
+ # Production with enhanced monitoring v3.0
273
+ /cfn-loop-cli "Complex task description" --mode=standard
274
+
275
+ # Debugging with full visibility
276
+ /cfn-loop-task "Complex task description" --mode=standard
277
+ ```
278
+
279
+ **Do NOT manually spawn Task() agents for CFN Loop workflows - the CLI commands handle coordination automatically.**
280
+
256
281
  ### Skill Selection Criteria
257
282
  **Mandatory Skill Spawning Triggers:**
258
283
  - Complex tasks (>3 steps)
@@ -273,16 +298,26 @@ npx claude-flow-novice swarm "Task Description" \
273
298
 
274
299
  ### Single Agent vs Coordinator
275
300
 
276
- **Use Single Agent:**
301
+ **Use Single Agent (Task() directly):**
277
302
  * 1 specialized task (coding, reviewing, testing)
278
303
  * No dependencies on other agents
279
304
  * Straightforward execution
305
+ * Simple, isolated work
280
306
 
281
- **Use Coordinator:**
307
+ **Use Coordinator (CLI Commands):**
282
308
  * Multiple agents needed (2+)
283
309
  * Sequential dependencies (Loop 3 → Loop 2 → Product Owner)
284
310
  * Iteration/consensus required
285
- * CFN Loop workflows
311
+ * **ALL CFN Loop workflows**
312
+
313
+ **🚨 FOR CFN LOOP WORKFLOWS: Always use CLI commands - never manual Task() spawning**
314
+ ```bash
315
+ # Multi-agent workflows (coordinator handles everything)
316
+ /cfn-loop-cli "Build authentication system" --mode=standard
317
+
318
+ # Single agent tasks (direct Task() is fine)
319
+ Task("reviewer", "Review this specific file")
320
+ ```
286
321
 
287
322
  ## 3) Coordination Patterns
288
323
 
@@ -312,40 +347,48 @@ Refer to `.claude/skills/cfn-redis-coordination/SKILL.md` for:
312
347
 
313
348
  ### CFN Loop Orchestration Pattern
314
349
 
315
- **CLI Mode (Production):**
316
- Main Chat spawns cfn-v3-coordinator → Coordinator spawns workers via CLI → Workers exit after reporting confidence
350
+ **CLI Mode (Production) - Enhanced v3.0:**
351
+ Main Chat spawns cfn-v3-coordinator → Enhanced orchestrator with monitoring → Workers via CLI with progress tracking Automatic recovery from stuck agents
317
352
 
318
353
  **Task Mode (Debugging):**
319
354
  Main Chat spawns all agents directly via Task() → No coordinator → Full visibility
320
355
 
321
- **Orchestrator:**
356
+ **Enhanced Orchestrator v3.0:**
322
357
  ```bash
323
358
  ./.claude/skills/cfn-loop-orchestration/orchestrate.sh
324
359
  ```
325
- - Spawns Loop 3 agents (implementers)
326
- - Collects confidence scores
327
- - Gate check: spawn Loop 2 if ≥threshold
328
- - Spawns Loop 2 agents (validators)
329
- - Collects consensus
360
+ - **Enhanced Monitoring**: Real-time agent progress tracking with stuck detection
361
+ - **Automatic Recovery**: Dead process cleanup and agent restart capabilities
362
+ - **Protocol Compliance**: Prevents "consensus on vapor" anti-patterns
363
+ - **Enhanced Spawning**: Context validation and broadcast message injection
364
+ - **Progress Visibility**: Detailed progress reports with timestamps
365
+ - Spawns Loop 3 agents with protocol enforcement
366
+ - Enhanced waiting with progress tracking and recovery
367
+ - Collects confidence scores with metadata validation
368
+ - Gate check: spawn Loop 2 if ≥threshold (with health verification)
369
+ - Spawns Loop 2 agents (validators) with monitoring
370
+ - Collects consensus with stuck agent detection
330
371
  - Spawns Product Owner for decision
331
- - Manages iterations based on PROCEED/ITERATE/ABORT
372
+ - Manages iterations based on PROCEED/ITERATE/ABORT with timeout handling
332
373
 
333
374
  **Agent Completion Protocol (Mode-Specific):**
334
375
 
335
- **CLI Mode** (spawned via `npx claude-flow-novice agent-spawn`):
376
+ **CLI Mode v3.0** (spawned via `npx claude-flow-novice agent-spawn`):
336
377
  ```bash
337
- # 1. Complete work
338
- # 2. Signal done
378
+ # 1. Complete work with enhanced context
379
+ # 2. Automatic context validation (prevents "consensus on vapor")
380
+ # 3. Signal completion
339
381
  redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
340
382
 
341
- # 3. Report confidence and exit
342
- ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh report \
383
+ # 4. Report confidence with metadata
384
+ ./.claude/skills/cfn-redis-coordination/report-completion.sh \
343
385
  --task-id "$TASK_ID" \
344
386
  --agent-id "$AGENT_ID" \
345
387
  --confidence 0.85 \
346
- --iteration 1
388
+ --iteration 1 \
389
+ --result '{"deliverables_created": ["file.ts"], "status": "complete"}'
347
390
 
348
- # Agent exits cleanly (no waiting mode)
391
+ # 5. Agent exits cleanly (orchestrator monitors via enhanced waiting)
349
392
  ```
350
393
 
351
394
  **Task Mode** (spawned via Task() tool in Main Chat):
@@ -356,6 +399,12 @@ redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
356
399
  # NO explicit completion protocol needed
357
400
  ```
358
401
 
402
+ **Enhanced Agent Protocol Requirements:**
403
+ - ✅ **Mandatory completion signaling**: `report-completion.sh` call required
404
+ - ✅ **Context awareness**: Broadcast messages automatically injected
405
+ - ✅ **Metadata tracking**: Agent status and process PID monitored
406
+ - ✅ **Health checking**: Process health validated during execution
407
+
359
408
  **Orchestration Flow (CORRECTED - Self-Validation Pattern):**
360
409
  1. Loop 3 agents complete work and report confidence
361
410
  2. **Gate Check:** Loop 3 self-validation scores checked
@@ -686,4 +735,28 @@ Out of Scope:
686
735
  - **Confidence:** 0.91
687
736
  - **Priority:** 8
688
737
  - **Insight**: Decompose complex systems into independent skills (20 skills in CFN v3: task-classifier, playbook, validation-templates, etc.). Enables reuse, testing isolation, and incremental enhancement.
689
- - **Tags**: modularity, skills, architecture, reusability
738
+ - **Tags**: modularity, skills, architecture, reusability
739
+ ## Sprint 10 Adaptive Context Lessons (Phase X - Defensive Programming)
740
+
741
+ ### Defensive Programming Patterns
742
+
743
+ #### PATTERN-025: Comprehensive File Validation
744
+ - **Context**: Defensive File Handling
745
+ - **Insight**: Implement comprehensive file validation techniques that go beyond basic existence checks. Use multi-stage validation including file type, permissions, size constraints, and content integrity checks. Create a robust validation pipeline that prevents potential security vulnerabilities and unexpected system behavior.
746
+ - **Tags**: file-handling, defensive-programming, validation, security, system-integrity
747
+ - **Confidence**: 0.92
748
+ - **Priority**: 9/10
749
+
750
+ #### PATTERN-026: Shell Strict Mode
751
+ - **Context**: Bash Script Reliability
752
+ - **Insight**: Enable shell strict mode using `set -euo pipefail` to create more robust and predictable shell scripts. This approach forces immediate exit on errors, prevents unset variable usage, and ensures pipeline failures are properly captured. Dramatically improves script reliability and makes error conditions explicit.
753
+ - **Tags**: bash, shell-scripting, error-handling, defensive-programming, reliability
754
+ - **Confidence**: 0.90
755
+ - **Priority**: 9/10
756
+
757
+ #### PATTERN-028: Process Group Management
758
+ - **Context**: Background Process Handling
759
+ - **Insight**: Implement comprehensive process group management techniques to ensure clean termination and resource cleanup. Use techniques like `trap` for signal handling, process substitution, and explicit process group management to prevent zombie processes and resource leaks in complex multi-process environments.
760
+ - **Tags**: process-management, bash, background-processes, resource-cleanup, defensive-programming
761
+ - **Confidence**: 0.86
762
+ - **Priority**: 8/10
@@ -317,23 +317,78 @@ function store_context() {
317
317
  }
318
318
 
319
319
  build_agent_context() {
320
- local iteration="$1"
321
- local agent_type="$2"
322
- local feedback="$3"
323
- local loop_type="${4:-}" # NEW: loop3, loop2, or loop4 (optional)
320
+ local task_id="$1"
321
+ local iteration="$2"
322
+ local agent_type="$3"
323
+ local feedback="$4"
324
+ local loop_type="${5:-}" # NEW: loop3, loop2, or loop4 (optional)
324
325
 
325
- # Extract from SUCCESS_CRITERIA JSON
326
+ # Initialize context variables
326
327
  local task_desc="CFN Loop implementation"
327
- local deliverables=$(echo "$SUCCESS_CRITERIA" | jq -r '.deliverables // [] | join(", ")' 2>/dev/null || echo "")
328
- local acceptance=$(echo "$SUCCESS_CRITERIA" | jq -r '.acceptanceCriteria // [] | join(", ")' 2>/dev/null || echo "")
328
+ local deliverables=""
329
+ local acceptance=""
330
+ local epic_context=""
331
+ local phase_context=""
332
+ local target_files=""
333
+
334
+ # Try to retrieve complete context from Redis
335
+ if command -v "$REDIS_COORD_SKILL/get-context.sh" >/dev/null 2>&1; then
336
+ if redis_context=$("$REDIS_COORD_SKILL/get-context.sh" --task-id "$task_id" --namespace "swarm" 2>/dev/null); then
337
+ echo "📥 Retrieved Redis context for task: $task_id" >&2
338
+
339
+ # Extract fields from Redis context
340
+ task_desc=$(echo "$redis_context" | jq -r '.["epic-context"] // .epic_context // "CFN Loop implementation"' 2>/dev/null || echo "CFN Loop implementation")
341
+ deliverables=$(echo "$redis_context" | jq -r '.deliverables // [] | if type == "array" then join(", ") else . end' 2>/dev/null || echo "")
342
+ acceptance=$(echo "$redis_context" | jq -r '.acceptanceCriteria // .["acceptance-criteria"] // [] | if type == "array" then join(", ") else . end' 2>/dev/null || echo "")
343
+ epic_context=$(echo "$redis_context" | jq -r '.["epic-context"] // ""' 2>/dev/null || echo "")
344
+ phase_context=$(echo "$redis_context" | jq -r '.["phase-context"] // ""' 2>/dev/null || echo "")
345
+ target_files=$(echo "$redis_context" | jq -r '.["target-files"] // ""' 2>/dev/null || echo "")
346
+
347
+ echo "📋 Redis context extracted - Task: $task_desc" >&2
348
+ else
349
+ echo "⚠️ Failed to retrieve Redis context, using local SUCCESS_CRITERIA" >&2
350
+ fi
351
+ else
352
+ echo "⚠️ get-context.sh not found, using local SUCCESS_CRITERIA" >&2
353
+ fi
354
+
355
+ # Fallback to local SUCCESS_CRITERIA if Redis retrieval failed or incomplete
356
+ if [ -z "$deliverables" ] && [ -n "$SUCCESS_CRITERIA" ]; then
357
+ deliverables=$(echo "$SUCCESS_CRITERIA" | jq -r '.deliverables // [] | join(", ")' 2>/dev/null || echo "")
358
+ acceptance=$(echo "$SUCCESS_CRITERIA" | jq -r '.acceptanceCriteria // [] | join(", ")' 2>/dev/null || echo "")
359
+ echo "🔄 Using local SUCCESS_CRITERIA as fallback" >&2
360
+ fi
329
361
 
330
- # Build base context
331
- local context="Task: $task_desc | Deliverables: $deliverables | Acceptance: $acceptance | Iteration: $iteration"
362
+ # Build comprehensive context string
363
+ local context="Task: $task_desc"
364
+
365
+ if [ -n "$deliverables" ]; then
366
+ context="$context | Deliverables: $deliverables"
367
+ fi
368
+
369
+ if [ -n "$acceptance" ]; then
370
+ context="$context | Acceptance Criteria: $acceptance"
371
+ fi
372
+
373
+ if [ -n "$target_files" ]; then
374
+ context="$context | Target Files: $target_files"
375
+ fi
376
+
377
+ context="$context | Iteration: $iteration"
332
378
 
333
379
  if [[ -n "$feedback" ]]; then
334
380
  context="$context | Feedback: $feedback"
335
381
  fi
336
382
 
383
+ # Add epic/phase context if available
384
+ if [ -n "$epic_context" ]; then
385
+ context="$context | Epic: $epic_context"
386
+ fi
387
+
388
+ if [ -n "$phase_context" ]; then
389
+ context="$context | Phase: $phase_context"
390
+ fi
391
+
337
392
  # Inject CFN Loop context if injection script exists and loop_type provided
338
393
  if [[ -n "$loop_type" ]] && [[ -x "$SCRIPT_DIR/inject-loop-context.sh" ]]; then
339
394
  context=$("$SCRIPT_DIR/inject-loop-context.sh" "$loop_type" "$context" 2>/dev/null || echo "$context")
@@ -375,7 +430,7 @@ function spawn_loop3_agents() {
375
430
  --task-id "$safe_task_id" \
376
431
  --agent-id "$safe_agent_id" \
377
432
  --iteration "$iteration" \
378
- --context "$(build_agent_context "$iteration" "$safe_agent_type" "" "loop3")" &
433
+ --context "$(build_agent_context "$safe_task_id" "$iteration" "$safe_agent_type" "" "loop3")" &
379
434
 
380
435
  # Store PID for monitoring using unique agent ID
381
436
  AGENT_PID=$!
@@ -608,7 +663,7 @@ function spawn_loop2_agents() {
608
663
  --task-id "$task_id" \
609
664
  --agent-id "$UNIQUE_VALIDATOR_ID" \
610
665
  --iteration "$iteration" \
611
- --context "$(build_agent_context "$iteration" "$agent_type" "" "loop2")" &
666
+ --context "$(build_agent_context "$task_id" "$iteration" "$agent_type" "" "loop2")" &
612
667
 
613
668
  # Store PID for monitoring using unique agent ID
614
669
  AGENT_PID=$!