claude-flow-novice 2.15.1 → 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 (107) hide show
  1. package/.claude/cfn-extras/agents/google-sheets-specialist.md +614 -0
  2. package/.claude/commands/cfn/create-handoff.md +224 -0
  3. package/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
  4. package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
  5. package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  6. package/.claude/hooks/cfn-post-edit.config.json +44 -44
  7. package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
  8. package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
  9. package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
  10. package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  11. package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  12. package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  13. package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
  14. package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  15. package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  16. package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  17. package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  18. package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  19. package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  20. package/claude-assets/agents/cfn-dev-team/coordinators/handoff-coordinator.md +662 -0
  21. package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +29 -0
  22. package/claude-assets/cfn-extras/agents/google-sheets-specialist.md +614 -0
  23. package/claude-assets/commands/cfn/create-handoff.md +224 -0
  24. package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
  25. package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
  26. package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  27. package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
  28. package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
  29. package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
  30. package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
  31. package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
  32. package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
  33. package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
  34. package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
  35. package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
  36. package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  37. package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
  38. package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
  39. package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  40. package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
  41. package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
  42. package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
  43. package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
  44. package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
  45. package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  46. package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
  47. package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
  48. package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
  49. package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
  50. package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
  51. package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
  52. package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
  53. package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  54. package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  55. package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  56. package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  57. package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  58. package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  59. package/claude-assets/skills/docker-build/SKILL.md +96 -203
  60. package/claude-assets/skills/docker-build/build.sh +73 -73
  61. package/claude-assets/skills/integration/agent-handoff.sh +494 -0
  62. package/claude-assets/skills/integration/file-operations.sh +414 -0
  63. package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
  64. package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
  65. package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
  66. package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
  67. package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
  68. package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
  69. package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
  70. package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
  71. package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
  72. package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
  73. package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
  74. package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
  75. package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
  76. package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
  77. package/dist/agents/agent-loader.js +165 -146
  78. package/dist/agents/agent-loader.js.map +1 -1
  79. package/dist/cli/config-manager.js +91 -109
  80. package/dist/cli/config-manager.js.map +1 -1
  81. package/dist/integration/DatabaseHandoff.js +507 -0
  82. package/dist/integration/DatabaseHandoff.js.map +1 -0
  83. package/dist/integration/StandardAdapter.js +291 -0
  84. package/dist/integration/StandardAdapter.js.map +1 -0
  85. package/dist/lib/agent-output-parser.js +518 -0
  86. package/dist/lib/agent-output-parser.js.map +1 -0
  87. package/dist/lib/agent-output-validator.js +950 -0
  88. package/dist/lib/agent-output-validator.js.map +1 -0
  89. package/dist/lib/artifact-registry.js +443 -0
  90. package/dist/lib/artifact-registry.js.map +1 -0
  91. package/dist/lib/config-validator.js +687 -0
  92. package/dist/lib/config-validator.js.map +1 -0
  93. package/dist/types/agent-output.js +44 -0
  94. package/dist/types/agent-output.js.map +1 -0
  95. package/dist/types/config.js +28 -0
  96. package/dist/types/config.js.map +1 -0
  97. package/package.json +2 -1
  98. package/scripts/artifact-cleanup.sh +392 -0
  99. package/scripts/build-linux.sh +78 -0
  100. package/scripts/deploy-production.sh +355 -355
  101. package/scripts/docker-playwright-fix.sh +311 -311
  102. package/scripts/docker-rebuild-all-agents.sh +127 -127
  103. package/scripts/memory-leak-prevention.sh +305 -305
  104. package/scripts/migrate-artifacts.sh +563 -0
  105. package/scripts/migrate-yaml-to-json.sh +465 -0
  106. package/scripts/run-marketing-tests.sh +42 -42
  107. 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
@@ -1,75 +1,75 @@
1
- #!/bin/bash
2
- # Redis Coordination Skill - Agent Emergency Recovery
3
- # Version: 1.0.0
4
- # Last Updated: 2025-10-19
5
-
6
- # Strict error handling
7
- set -euo pipefail
8
-
9
- # Default values
10
- TASK_ID=""
11
- AGENT_ID=""
12
- RECOVERY_MODE="soft" # Options: soft, hard
13
-
14
- # Parse command-line arguments
15
- while [[ $# -gt 0 ]]; do
16
- case "$1" in
17
- --task-id)
18
- TASK_ID="$2"
19
- shift 2
20
- ;;
21
- --agent-id)
22
- AGENT_ID="$2"
23
- shift 2
24
- ;;
25
- --mode)
26
- RECOVERY_MODE="$2"
27
- shift 2
28
- ;;
29
- *)
30
- echo "Unknown parameter: $1"
31
- exit 1
32
- ;;
33
- esac
34
- done
35
-
36
- # Validate required parameters
37
- if [[ -z "$TASK_ID" || -z "$AGENT_ID" ]]; then
38
- echo "Error: task-id and agent-id are required"
39
- exit 1
40
- fi
41
-
42
- # Log recovery attempt
43
- echo "[$(date -u)] Attempting ${RECOVERY_MODE} recovery for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
44
-
45
- # Retrieve agent context before recovery
46
- AGENT_CONTEXT=$(redis-cli get "swarm:${TASK_ID}:${AGENT_ID}:context")
47
-
48
- # Recovery actions based on mode
49
- case "$RECOVERY_MODE" in
50
- "soft")
51
- # Soft recovery: Spawn new agent with previous context
52
- npx claude-flow@alpha spawn "$AGENT_ID" \
53
- --task-id "$TASK_ID" \
54
- --recovery-context "$AGENT_CONTEXT"
55
- ;;
56
- "hard")
57
- # Hard recovery: Full agent replacement
58
- npx claude-flow@alpha spawn "$AGENT_ID" \
59
- --task-id "$TASK_ID" \
60
- --mode replace \
61
- --recovery-context "$AGENT_CONTEXT"
62
- ;;
63
- *)
64
- echo "Invalid recovery mode: ${RECOVERY_MODE}"
65
- exit 1
66
- ;;
67
- esac
68
-
69
- # Update active agents set
70
- redis-cli sadd "swarm:${TASK_ID}:active-agents" "$AGENT_ID"
71
-
72
- # Log recovery completion
73
- echo "[$(date -u)] Recovery completed for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
74
-
1
+ #!/bin/bash
2
+ # Redis Coordination Skill - Agent Emergency Recovery
3
+ # Version: 1.0.0
4
+ # Last Updated: 2025-10-19
5
+
6
+ # Strict error handling
7
+ set -euo pipefail
8
+
9
+ # Default values
10
+ TASK_ID=""
11
+ AGENT_ID=""
12
+ RECOVERY_MODE="soft" # Options: soft, hard
13
+
14
+ # Parse command-line arguments
15
+ while [[ $# -gt 0 ]]; do
16
+ case "$1" in
17
+ --task-id)
18
+ TASK_ID="$2"
19
+ shift 2
20
+ ;;
21
+ --agent-id)
22
+ AGENT_ID="$2"
23
+ shift 2
24
+ ;;
25
+ --mode)
26
+ RECOVERY_MODE="$2"
27
+ shift 2
28
+ ;;
29
+ *)
30
+ echo "Unknown parameter: $1"
31
+ exit 1
32
+ ;;
33
+ esac
34
+ done
35
+
36
+ # Validate required parameters
37
+ if [[ -z "$TASK_ID" || -z "$AGENT_ID" ]]; then
38
+ echo "Error: task-id and agent-id are required"
39
+ exit 1
40
+ fi
41
+
42
+ # Log recovery attempt
43
+ echo "[$(date -u)] Attempting ${RECOVERY_MODE} recovery for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
44
+
45
+ # Retrieve agent context before recovery
46
+ AGENT_CONTEXT=$(redis-cli get "swarm:${TASK_ID}:${AGENT_ID}:context")
47
+
48
+ # Recovery actions based on mode
49
+ case "$RECOVERY_MODE" in
50
+ "soft")
51
+ # Soft recovery: Spawn new agent with previous context
52
+ npx claude-flow@alpha spawn "$AGENT_ID" \
53
+ --task-id "$TASK_ID" \
54
+ --recovery-context "$AGENT_CONTEXT"
55
+ ;;
56
+ "hard")
57
+ # Hard recovery: Full agent replacement
58
+ npx claude-flow@alpha spawn "$AGENT_ID" \
59
+ --task-id "$TASK_ID" \
60
+ --mode replace \
61
+ --recovery-context "$AGENT_CONTEXT"
62
+ ;;
63
+ *)
64
+ echo "Invalid recovery mode: ${RECOVERY_MODE}"
65
+ exit 1
66
+ ;;
67
+ esac
68
+
69
+ # Update active agents set
70
+ redis-cli sadd "swarm:${TASK_ID}:active-agents" "$AGENT_ID"
71
+
72
+ # Log recovery completion
73
+ echo "[$(date -u)] Recovery completed for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
74
+
75
75
  exit 0