claude-flow-novice 2.15.2 → 2.15.3

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 (98) hide show
  1. package/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
  2. package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
  3. package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  4. package/.claude/hooks/cfn-post-edit.config.json +44 -44
  5. package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
  6. package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
  7. package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
  8. package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  9. package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  10. package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  11. package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
  12. package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  13. package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  14. package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  15. package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  16. package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  17. package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  18. package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
  19. package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
  20. package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  21. package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
  22. package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
  23. package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
  24. package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
  25. package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
  26. package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
  27. package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
  28. package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
  29. package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
  30. package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  31. package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
  32. package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
  33. package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  34. package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
  35. package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
  36. package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
  37. package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
  38. package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
  39. package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  40. package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
  41. package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
  42. package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
  43. package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
  44. package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
  45. package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
  46. package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
  47. package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  48. package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  49. package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  50. package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  51. package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  52. package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  53. package/claude-assets/skills/docker-build/SKILL.md +96 -203
  54. package/claude-assets/skills/docker-build/build.sh +73 -73
  55. package/claude-assets/skills/integration/agent-handoff.sh +494 -0
  56. package/claude-assets/skills/integration/file-operations.sh +414 -0
  57. package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
  58. package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
  59. package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
  60. package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
  61. package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
  62. package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
  63. package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
  64. package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
  65. package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
  66. package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
  67. package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
  68. package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
  69. package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
  70. package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
  71. package/dist/cli/config-manager.js +91 -109
  72. package/dist/cli/config-manager.js.map +1 -1
  73. package/dist/integration/DatabaseHandoff.js +507 -0
  74. package/dist/integration/DatabaseHandoff.js.map +1 -0
  75. package/dist/integration/StandardAdapter.js +291 -0
  76. package/dist/integration/StandardAdapter.js.map +1 -0
  77. package/dist/lib/agent-output-parser.js +518 -0
  78. package/dist/lib/agent-output-parser.js.map +1 -0
  79. package/dist/lib/agent-output-validator.js +950 -0
  80. package/dist/lib/agent-output-validator.js.map +1 -0
  81. package/dist/lib/artifact-registry.js +443 -0
  82. package/dist/lib/artifact-registry.js.map +1 -0
  83. package/dist/lib/config-validator.js +687 -0
  84. package/dist/lib/config-validator.js.map +1 -0
  85. package/dist/types/agent-output.js +44 -0
  86. package/dist/types/agent-output.js.map +1 -0
  87. package/dist/types/config.js +28 -0
  88. package/dist/types/config.js.map +1 -0
  89. package/package.json +2 -1
  90. package/scripts/artifact-cleanup.sh +392 -0
  91. package/scripts/deploy-production.sh +355 -355
  92. package/scripts/docker-playwright-fix.sh +311 -311
  93. package/scripts/docker-rebuild-all-agents.sh +127 -127
  94. package/scripts/memory-leak-prevention.sh +305 -305
  95. package/scripts/migrate-artifacts.sh +563 -0
  96. package/scripts/migrate-yaml-to-json.sh +465 -0
  97. package/scripts/run-marketing-tests.sh +42 -42
  98. package/scripts/update_paths.sh +46 -46
@@ -1,252 +1,252 @@
1
- #!/usr/bin/env bash
2
-
3
- ##############################################################################
4
- # CFN Loop Orchestration v1.0.0
5
- # Manages multi-loop CFN execution with dependency tracking and consensus
6
- #
7
- # Usage:
8
- # ./orchestrate-cfn-loop.sh --task-id <id> \
9
- # --mode <mvp|standard|enterprise> \
10
- # --loop3-agents <agent1,agent2,...> \
11
- # --loop2-agents <agent1,agent2,...> \
12
- # --product-owner <agent-id> \
13
- # [--max-iterations <n>]
14
- #
15
- # CFN Loop Structure:
16
- # Loop 3 (Primary Swarm) → Loop 2 (Consensus) → Product Owner Decision
17
- #
18
- # Dependency Enforcement:
19
- # - Loop 2 agents BLOCK until all Loop 3 agents signal completion
20
- # - Product Owner BLOCKS until all Loop 2 agents signal completion
21
- # - Uses Redis BLPOP for zero-token waiting
22
- ##############################################################################
23
-
24
- set -euo pipefail
25
-
26
- # Configuration
27
- TASK_ID=""
28
- MODE="standard"
29
- LOOP3_AGENTS=""
30
- LOOP2_AGENTS=""
31
- PRODUCT_OWNER=""
32
- MAX_ITERATIONS=10
33
- TIMEOUT=3600 # 1 hour timeout for agent completion
34
-
35
- # Thresholds by mode
36
- declare -A GATE_THRESHOLD=(
37
- [mvp]=0.70
38
- [standard]=0.75
39
- [enterprise]=0.75
40
- )
41
-
42
- declare -A CONSENSUS_THRESHOLD=(
43
- [mvp]=0.80
44
- [standard]=0.90
45
- [enterprise]=0.95
46
- )
47
-
48
- # Parse arguments
49
- while [[ $# -gt 0 ]]; do
50
- case $1 in
51
- --task-id)
52
- TASK_ID="$2"
53
- shift 2
54
- ;;
55
- --mode)
56
- MODE="$2"
57
- shift 2
58
- ;;
59
- --loop3-agents)
60
- LOOP3_AGENTS="$2"
61
- shift 2
62
- ;;
63
- --loop2-agents)
64
- LOOP2_AGENTS="$2"
65
- shift 2
66
- ;;
67
- --product-owner)
68
- PRODUCT_OWNER="$2"
69
- shift 2
70
- ;;
71
- --max-iterations)
72
- MAX_ITERATIONS="$2"
73
- shift 2
74
- ;;
75
- *)
76
- echo "Unknown option: $1"
77
- exit 1
78
- ;;
79
- esac
80
- done
81
-
82
- # Validation
83
- if [ -z "$TASK_ID" ] || [ -z "$LOOP3_AGENTS" ] || [ -z "$LOOP2_AGENTS" ] || [ -z "$PRODUCT_OWNER" ]; then
84
- echo "Error: Required parameters missing"
85
- echo "Usage: $0 --task-id <id> --mode <mode> --loop3-agents <agents> --loop2-agents <agents> --product-owner <agent>"
86
- exit 1
87
- fi
88
-
89
- GATE=${GATE_THRESHOLD[$MODE]}
90
- CONSENSUS=${CONSENSUS_THRESHOLD[$MODE]}
91
-
92
- echo "=== CFN Loop Orchestration ==="
93
- echo "Task ID: $TASK_ID"
94
- echo "Mode: $MODE (Gate: $GATE, Consensus: $CONSENSUS)"
95
- echo "Max Iterations: $MAX_ITERATIONS"
96
- echo ""
97
-
98
- # Iteration loop
99
- for ITERATION in $(seq 1 $MAX_ITERATIONS); do
100
- echo "=== Iteration $ITERATION/$MAX_ITERATIONS ==="
101
-
102
- # Step 1: Wait for Loop 3 agents to complete
103
- echo "[Loop 3] Waiting for implementers to complete..."
104
- IFS=',' read -ra AGENTS <<< "$LOOP3_AGENTS"
105
-
106
- for AGENT in "${AGENTS[@]}"; do
107
- DONE_KEY="swarm:${TASK_ID}:${AGENT}:done"
108
- echo " Waiting for $AGENT..."
109
-
110
- # BLPOP with timeout (blocks until agent signals done)
111
- RESULT=$(timeout $TIMEOUT redis-cli blpop "$DONE_KEY" 0 2>/dev/null || echo "")
112
-
113
- if [ -z "$RESULT" ]; then
114
- echo " ❌ ERROR: $AGENT timeout after ${TIMEOUT}s"
115
- exit 1
116
- fi
117
-
118
- echo " ✅ $AGENT complete"
119
- done
120
-
121
- echo "[Loop 3] All implementers complete!"
122
- echo ""
123
-
124
- # Step 2: Collect Loop 3 confidence scores
125
- echo "[Loop 3] Collecting confidence scores..."
126
- LOOP3_CONSENSUS=$(./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh collect \
127
- --task-id "$TASK_ID" \
128
- --agent-ids "$LOOP3_AGENTS" | tail -1)
129
-
130
- echo "[Loop 3] Average confidence: $LOOP3_CONSENSUS"
131
-
132
- # Gate check
133
- if (( $(echo "$LOOP3_CONSENSUS < $GATE" | bc -l) )); then
134
- echo "❌ Gate FAILED ($LOOP3_CONSENSUS < $GATE)"
135
- echo "Decision: RELAUNCH iteration $((ITERATION + 1))"
136
-
137
- # Wake Loop 3 agents for next iteration
138
- IFS=',' read -ra AGENTS <<< "$LOOP3_AGENTS"
139
- for AGENT in "${AGENTS[@]}"; do
140
- ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh wake \
141
- --task-id "$TASK_ID" \
142
- --agent-id "$AGENT" \
143
- --reason "gate_failed" \
144
- --iteration $((ITERATION + 1)) \
145
- --feedback "Improve confidence from $LOOP3_CONSENSUS to >$GATE"
146
- done
147
-
148
- continue # Next iteration
149
- fi
150
-
151
- echo "✅ Gate PASSED ($LOOP3_CONSENSUS >= $GATE)"
152
- echo ""
153
-
154
- # Step 3: Wait for Loop 2 validators to complete
155
- echo "[Loop 2] Waiting for validators to complete..."
156
- IFS=',' read -ra VALIDATORS <<< "$LOOP2_AGENTS"
157
-
158
- for VALIDATOR in "${VALIDATORS[@]}"; do
159
- DONE_KEY="swarm:${TASK_ID}:${VALIDATOR}:done"
160
- echo " Waiting for $VALIDATOR..."
161
-
162
- RESULT=$(timeout $TIMEOUT redis-cli blpop "$DONE_KEY" 0 2>/dev/null || echo "")
163
-
164
- if [ -z "$RESULT" ]; then
165
- echo " ❌ ERROR: $VALIDATOR timeout after ${TIMEOUT}s"
166
- exit 1
167
- fi
168
-
169
- echo " ✅ $VALIDATOR complete"
170
- done
171
-
172
- echo "[Loop 2] All validators complete!"
173
- echo ""
174
-
175
- # Step 4: Collect Loop 2 consensus scores
176
- echo "[Loop 2] Collecting consensus scores..."
177
- LOOP2_CONSENSUS=$(./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh collect \
178
- --task-id "$TASK_ID" \
179
- --agent-ids "$LOOP2_AGENTS" | tail -1)
180
-
181
- echo "[Loop 2] Average consensus: $LOOP2_CONSENSUS"
182
-
183
- # Consensus check
184
- if (( $(echo "$LOOP2_CONSENSUS >= $CONSENSUS" | bc -l) )); then
185
- echo "✅ CONSENSUS REACHED ($LOOP2_CONSENSUS >= $CONSENSUS)"
186
- echo ""
187
-
188
- # Signal Product Owner that consensus is ready
189
- DECISION_KEY="swarm:${TASK_ID}:${PRODUCT_OWNER}:consensus-ready"
190
- redis-cli lpush "$DECISION_KEY" "{\"iteration\": $ITERATION, \"consensus\": $LOOP2_CONSENSUS}" > /dev/null
191
-
192
- # Wait for Product Owner decision
193
- echo "[Product Owner] Waiting for GOAP decision..."
194
- DECISION_KEY="swarm:${TASK_ID}:${PRODUCT_OWNER}:decision"
195
- DECISION=$(timeout $TIMEOUT redis-cli blpop "$DECISION_KEY" 0 2>/dev/null | tail -1)
196
-
197
- if [ -z "$DECISION" ]; then
198
- echo "❌ ERROR: Product Owner timeout"
199
- exit 1
200
- fi
201
-
202
- DECISION_TYPE=$(echo "$DECISION" | jq -r '.decision')
203
-
204
- echo "[Product Owner] Decision: $DECISION_TYPE"
205
-
206
- if [ "$DECISION_TYPE" = "PROCEED" ]; then
207
- echo ""
208
- echo "🎉 CFN Loop Complete!"
209
- echo "Final Consensus: $LOOP2_CONSENSUS (Iteration $ITERATION)"
210
-
211
- # Wake all agents with completion signal
212
- IFS=',' read -ra ALL_AGENTS <<< "$LOOP3_AGENTS,$LOOP2_AGENTS"
213
- for AGENT in "${ALL_AGENTS[@]}"; do
214
- ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh wake \
215
- --task-id "$TASK_ID" \
216
- --agent-id "$AGENT" \
217
- --reason "cfn_complete" \
218
- --iteration "$ITERATION"
219
- done
220
-
221
- exit 0
222
- fi
223
-
224
- else
225
- echo "⚠️ CONSENSUS NOT REACHED ($LOOP2_CONSENSUS < $CONSENSUS)"
226
- echo "Decision: RELAUNCH iteration $((ITERATION + 1))"
227
- echo ""
228
- fi
229
-
230
- # Relaunch next iteration
231
- if [ $ITERATION -eq $MAX_ITERATIONS ]; then
232
- echo "❌ Maximum iterations ($MAX_ITERATIONS) reached without consensus"
233
- exit 1
234
- fi
235
-
236
- # Wake all agents for next iteration
237
- echo "[Coordinator] Waking agents for iteration $((ITERATION + 1))..."
238
- IFS=',' read -ra ALL_AGENTS <<< "$LOOP3_AGENTS,$LOOP2_AGENTS"
239
- for AGENT in "${ALL_AGENTS[@]}"; do
240
- ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh wake \
241
- --task-id "$TASK_ID" \
242
- --agent-id "$AGENT" \
243
- --reason "cfn_loop_iteration" \
244
- --iteration $((ITERATION + 1)) \
245
- --feedback "Improve consensus from $LOOP2_CONSENSUS to >=$CONSENSUS"
246
- done
247
-
248
- echo ""
249
- done
250
-
251
- echo "❌ CFN Loop failed after $MAX_ITERATIONS iterations"
252
- exit 1
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ # CFN Loop Orchestration v1.0.0
5
+ # Manages multi-loop CFN execution with dependency tracking and consensus
6
+ #
7
+ # Usage:
8
+ # ./orchestrate-cfn-loop.sh --task-id <id> \
9
+ # --mode <mvp|standard|enterprise> \
10
+ # --loop3-agents <agent1,agent2,...> \
11
+ # --loop2-agents <agent1,agent2,...> \
12
+ # --product-owner <agent-id> \
13
+ # [--max-iterations <n>]
14
+ #
15
+ # CFN Loop Structure:
16
+ # Loop 3 (Primary Swarm) → Loop 2 (Consensus) → Product Owner Decision
17
+ #
18
+ # Dependency Enforcement:
19
+ # - Loop 2 agents BLOCK until all Loop 3 agents signal completion
20
+ # - Product Owner BLOCKS until all Loop 2 agents signal completion
21
+ # - Uses Redis BLPOP for zero-token waiting
22
+ ##############################################################################
23
+
24
+ set -euo pipefail
25
+
26
+ # Configuration
27
+ TASK_ID=""
28
+ MODE="standard"
29
+ LOOP3_AGENTS=""
30
+ LOOP2_AGENTS=""
31
+ PRODUCT_OWNER=""
32
+ MAX_ITERATIONS=10
33
+ TIMEOUT=3600 # 1 hour timeout for agent completion
34
+
35
+ # Thresholds by mode
36
+ declare -A GATE_THRESHOLD=(
37
+ [mvp]=0.70
38
+ [standard]=0.75
39
+ [enterprise]=0.75
40
+ )
41
+
42
+ declare -A CONSENSUS_THRESHOLD=(
43
+ [mvp]=0.80
44
+ [standard]=0.90
45
+ [enterprise]=0.95
46
+ )
47
+
48
+ # Parse arguments
49
+ while [[ $# -gt 0 ]]; do
50
+ case $1 in
51
+ --task-id)
52
+ TASK_ID="$2"
53
+ shift 2
54
+ ;;
55
+ --mode)
56
+ MODE="$2"
57
+ shift 2
58
+ ;;
59
+ --loop3-agents)
60
+ LOOP3_AGENTS="$2"
61
+ shift 2
62
+ ;;
63
+ --loop2-agents)
64
+ LOOP2_AGENTS="$2"
65
+ shift 2
66
+ ;;
67
+ --product-owner)
68
+ PRODUCT_OWNER="$2"
69
+ shift 2
70
+ ;;
71
+ --max-iterations)
72
+ MAX_ITERATIONS="$2"
73
+ shift 2
74
+ ;;
75
+ *)
76
+ echo "Unknown option: $1"
77
+ exit 1
78
+ ;;
79
+ esac
80
+ done
81
+
82
+ # Validation
83
+ if [ -z "$TASK_ID" ] || [ -z "$LOOP3_AGENTS" ] || [ -z "$LOOP2_AGENTS" ] || [ -z "$PRODUCT_OWNER" ]; then
84
+ echo "Error: Required parameters missing"
85
+ echo "Usage: $0 --task-id <id> --mode <mode> --loop3-agents <agents> --loop2-agents <agents> --product-owner <agent>"
86
+ exit 1
87
+ fi
88
+
89
+ GATE=${GATE_THRESHOLD[$MODE]}
90
+ CONSENSUS=${CONSENSUS_THRESHOLD[$MODE]}
91
+
92
+ echo "=== CFN Loop Orchestration ==="
93
+ echo "Task ID: $TASK_ID"
94
+ echo "Mode: $MODE (Gate: $GATE, Consensus: $CONSENSUS)"
95
+ echo "Max Iterations: $MAX_ITERATIONS"
96
+ echo ""
97
+
98
+ # Iteration loop
99
+ for ITERATION in $(seq 1 $MAX_ITERATIONS); do
100
+ echo "=== Iteration $ITERATION/$MAX_ITERATIONS ==="
101
+
102
+ # Step 1: Wait for Loop 3 agents to complete
103
+ echo "[Loop 3] Waiting for implementers to complete..."
104
+ IFS=',' read -ra AGENTS <<< "$LOOP3_AGENTS"
105
+
106
+ for AGENT in "${AGENTS[@]}"; do
107
+ DONE_KEY="swarm:${TASK_ID}:${AGENT}:done"
108
+ echo " Waiting for $AGENT..."
109
+
110
+ # BLPOP with timeout (blocks until agent signals done)
111
+ RESULT=$(timeout $TIMEOUT redis-cli blpop "$DONE_KEY" 0 2>/dev/null || echo "")
112
+
113
+ if [ -z "$RESULT" ]; then
114
+ echo " ❌ ERROR: $AGENT timeout after ${TIMEOUT}s"
115
+ exit 1
116
+ fi
117
+
118
+ echo " ✅ $AGENT complete"
119
+ done
120
+
121
+ echo "[Loop 3] All implementers complete!"
122
+ echo ""
123
+
124
+ # Step 2: Collect Loop 3 confidence scores
125
+ echo "[Loop 3] Collecting confidence scores..."
126
+ LOOP3_CONSENSUS=$(./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh collect \
127
+ --task-id "$TASK_ID" \
128
+ --agent-ids "$LOOP3_AGENTS" | tail -1)
129
+
130
+ echo "[Loop 3] Average confidence: $LOOP3_CONSENSUS"
131
+
132
+ # Gate check
133
+ if (( $(echo "$LOOP3_CONSENSUS < $GATE" | bc -l) )); then
134
+ echo "❌ Gate FAILED ($LOOP3_CONSENSUS < $GATE)"
135
+ echo "Decision: RELAUNCH iteration $((ITERATION + 1))"
136
+
137
+ # Wake Loop 3 agents for next iteration
138
+ IFS=',' read -ra AGENTS <<< "$LOOP3_AGENTS"
139
+ for AGENT in "${AGENTS[@]}"; do
140
+ ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh wake \
141
+ --task-id "$TASK_ID" \
142
+ --agent-id "$AGENT" \
143
+ --reason "gate_failed" \
144
+ --iteration $((ITERATION + 1)) \
145
+ --feedback "Improve confidence from $LOOP3_CONSENSUS to >$GATE"
146
+ done
147
+
148
+ continue # Next iteration
149
+ fi
150
+
151
+ echo "✅ Gate PASSED ($LOOP3_CONSENSUS >= $GATE)"
152
+ echo ""
153
+
154
+ # Step 3: Wait for Loop 2 validators to complete
155
+ echo "[Loop 2] Waiting for validators to complete..."
156
+ IFS=',' read -ra VALIDATORS <<< "$LOOP2_AGENTS"
157
+
158
+ for VALIDATOR in "${VALIDATORS[@]}"; do
159
+ DONE_KEY="swarm:${TASK_ID}:${VALIDATOR}:done"
160
+ echo " Waiting for $VALIDATOR..."
161
+
162
+ RESULT=$(timeout $TIMEOUT redis-cli blpop "$DONE_KEY" 0 2>/dev/null || echo "")
163
+
164
+ if [ -z "$RESULT" ]; then
165
+ echo " ❌ ERROR: $VALIDATOR timeout after ${TIMEOUT}s"
166
+ exit 1
167
+ fi
168
+
169
+ echo " ✅ $VALIDATOR complete"
170
+ done
171
+
172
+ echo "[Loop 2] All validators complete!"
173
+ echo ""
174
+
175
+ # Step 4: Collect Loop 2 consensus scores
176
+ echo "[Loop 2] Collecting consensus scores..."
177
+ LOOP2_CONSENSUS=$(./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh collect \
178
+ --task-id "$TASK_ID" \
179
+ --agent-ids "$LOOP2_AGENTS" | tail -1)
180
+
181
+ echo "[Loop 2] Average consensus: $LOOP2_CONSENSUS"
182
+
183
+ # Consensus check
184
+ if (( $(echo "$LOOP2_CONSENSUS >= $CONSENSUS" | bc -l) )); then
185
+ echo "✅ CONSENSUS REACHED ($LOOP2_CONSENSUS >= $CONSENSUS)"
186
+ echo ""
187
+
188
+ # Signal Product Owner that consensus is ready
189
+ DECISION_KEY="swarm:${TASK_ID}:${PRODUCT_OWNER}:consensus-ready"
190
+ redis-cli lpush "$DECISION_KEY" "{\"iteration\": $ITERATION, \"consensus\": $LOOP2_CONSENSUS}" > /dev/null
191
+
192
+ # Wait for Product Owner decision
193
+ echo "[Product Owner] Waiting for GOAP decision..."
194
+ DECISION_KEY="swarm:${TASK_ID}:${PRODUCT_OWNER}:decision"
195
+ DECISION=$(timeout $TIMEOUT redis-cli blpop "$DECISION_KEY" 0 2>/dev/null | tail -1)
196
+
197
+ if [ -z "$DECISION" ]; then
198
+ echo "❌ ERROR: Product Owner timeout"
199
+ exit 1
200
+ fi
201
+
202
+ DECISION_TYPE=$(echo "$DECISION" | jq -r '.decision')
203
+
204
+ echo "[Product Owner] Decision: $DECISION_TYPE"
205
+
206
+ if [ "$DECISION_TYPE" = "PROCEED" ]; then
207
+ echo ""
208
+ echo "🎉 CFN Loop Complete!"
209
+ echo "Final Consensus: $LOOP2_CONSENSUS (Iteration $ITERATION)"
210
+
211
+ # Wake all agents with completion signal
212
+ IFS=',' read -ra ALL_AGENTS <<< "$LOOP3_AGENTS,$LOOP2_AGENTS"
213
+ for AGENT in "${ALL_AGENTS[@]}"; do
214
+ ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh wake \
215
+ --task-id "$TASK_ID" \
216
+ --agent-id "$AGENT" \
217
+ --reason "cfn_complete" \
218
+ --iteration "$ITERATION"
219
+ done
220
+
221
+ exit 0
222
+ fi
223
+
224
+ else
225
+ echo "⚠️ CONSENSUS NOT REACHED ($LOOP2_CONSENSUS < $CONSENSUS)"
226
+ echo "Decision: RELAUNCH iteration $((ITERATION + 1))"
227
+ echo ""
228
+ fi
229
+
230
+ # Relaunch next iteration
231
+ if [ $ITERATION -eq $MAX_ITERATIONS ]; then
232
+ echo "❌ Maximum iterations ($MAX_ITERATIONS) reached without consensus"
233
+ exit 1
234
+ fi
235
+
236
+ # Wake all agents for next iteration
237
+ echo "[Coordinator] Waking agents for iteration $((ITERATION + 1))..."
238
+ IFS=',' read -ra ALL_AGENTS <<< "$LOOP3_AGENTS,$LOOP2_AGENTS"
239
+ for AGENT in "${ALL_AGENTS[@]}"; do
240
+ ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh wake \
241
+ --task-id "$TASK_ID" \
242
+ --agent-id "$AGENT" \
243
+ --reason "cfn_loop_iteration" \
244
+ --iteration $((ITERATION + 1)) \
245
+ --feedback "Improve consensus from $LOOP2_CONSENSUS to >=$CONSENSUS"
246
+ done
247
+
248
+ echo ""
249
+ done
250
+
251
+ echo "❌ CFN Loop failed after $MAX_ITERATIONS iterations"
252
+ exit 1