claude-flow-novice 2.6.0 → 2.8.1

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 (364) hide show
  1. package/.claude/adaptive-context/cfn-v3-reflection.json +21 -0
  2. package/.claude/agents/AGENT_LIFECYCLE.md +495 -0
  3. package/.claude/agents/CLAUDE.md +1002 -995
  4. package/.claude/agents/accessibility-advocate.md +457 -0
  5. package/.claude/agents/agent-principles/README.md +226 -226
  6. package/.claude/agents/agent-principles/agent-type-guidelines.md +10 -0
  7. package/.claude/agents/agent-principles/format-selection.md +10 -0
  8. package/.claude/agents/agent-principles/phase4-template-optimization.md +502 -494
  9. package/.claude/agents/agent-principles/prompt-engineering.md +8 -0
  10. package/.claude/agents/agent-principles/quality-metrics.md +8 -0
  11. package/.claude/agents/analysis/code-analyzer.md +7 -17
  12. package/.claude/agents/analysis/code-review/analyze-code-quality.md +2 -104
  13. package/.claude/agents/analysis/perf-analyzer.md +2 -196
  14. package/.claude/agents/context/context-curator.md +78 -84
  15. package/.claude/agents/context/context-reflector.md +27 -81
  16. package/.claude/agents/coordinators/README.md +42 -0
  17. package/.claude/agents/coordinators/cfn-v3-coordinator.md +440 -0
  18. package/.claude/agents/{product-owner-team → coordinators}/cto-agent.md +154 -187
  19. package/.claude/agents/coordinators/multi-sprint-coordinator.md +50 -0
  20. package/.claude/agents/{product-owner-team → coordinators}/product-owner-agent.md +6 -39
  21. package/.claude/agents/{cfn-loop → coordinators}/product-owner.md +72 -17
  22. package/.claude/agents/core-agents/reviewer.md +114 -135
  23. package/.claude/agents/custom/agent-builder.md +637 -637
  24. package/.claude/agents/developers/README.md +69 -0
  25. package/.claude/agents/developers/backend-dev.md +77 -0
  26. package/.claude/agents/{core-agents → developers}/coder.md +131 -26
  27. package/.claude/agents/developers/react-frontend-engineer.md +121 -0
  28. package/.claude/agents/{frontend → developers}/state-architect.md +1 -0
  29. package/.claude/agents/{frontend → developers}/ui-designer.md +1 -0
  30. package/.claude/agents/development/backend/dev-backend-api.md +0 -29
  31. package/.claude/agents/development/npm-package-specialist.md +355 -347
  32. package/.claude/agents/documentation/api-docs/docs-api-openapi.md +8 -0
  33. package/.claude/agents/documentation/api-docs.md +8 -0
  34. package/.claude/agents/github/github-commit-agent.md +125 -117
  35. package/.claude/agents/goal/goal-planner.md +8 -0
  36. package/.claude/agents/infrastructure/README.md +100 -0
  37. package/.claude/agents/{specialized → infrastructure}/devops-engineer.md +131 -150
  38. package/.claude/agents/planners/README.md +94 -0
  39. package/.claude/agents/{core-agents → planners}/analyst.md +1 -22
  40. package/.claude/agents/{planning-team → planners}/api-designer-persona.md +8 -0
  41. package/.claude/agents/{core-agents → planners}/architect.md +7 -20
  42. package/.claude/agents/{core-agents → planners}/planner.md +0 -21
  43. package/.claude/agents/{planning-team → planners}/security-architect-persona.md +8 -28
  44. package/.claude/agents/{planning-team → planners}/system-architect-persona.md +6 -38
  45. package/.claude/agents/{architecture → planners}/system-architect.md +12 -17
  46. package/.claude/agents/product-owner-team/accessibility-advocate-persona.md +132 -161
  47. package/.claude/agents/product-owner-team/power-user-persona.md +149 -182
  48. package/.claude/agents/retrospective-analyst.md +84 -0
  49. package/.claude/agents/reviewers/README.md +58 -0
  50. package/.claude/agents/{analysis → reviewers}/code-quality-validator.md +8 -17
  51. package/.claude/agents/reviewers/reviewer.md +181 -0
  52. package/.claude/agents/sparc/architecture.md +6 -25
  53. package/.claude/agents/sparc/pseudocode.md +6 -0
  54. package/.claude/agents/sparc/refinement.md +6 -0
  55. package/.claude/agents/sparc/specification.md +1 -0
  56. package/.claude/agents/specialists/README.md +60 -0
  57. package/.claude/agents/{core-agents → specialists}/base-template-generator.md +8 -21
  58. package/.claude/agents/{specialized → specialists}/cli-agent-optimizer.md +1 -1
  59. package/.claude/agents/{specialized → specialists}/code-booster.md +1 -0
  60. package/.claude/agents/{consensus → specialists}/consensus-builder.md +1 -17
  61. package/.claude/agents/{specialized/mobile → specialists}/mobile-dev.md +0 -20
  62. package/.claude/agents/{core-agents → specialists}/performance-benchmarker.md +134 -148
  63. package/.claude/agents/{specialized → specialists}/rust-developer.md +1 -20
  64. package/.claude/agents/{specialized → specialists}/rust-enterprise-developer.md +1 -20
  65. package/.claude/agents/{specialized → specialists}/rust-mvp-developer.md +1 -20
  66. package/.claude/agents/{core-agents → specialists}/security-manager.md +68 -88
  67. package/.claude/agents/{security → specialists}/security-specialist-existing.md +6 -57
  68. package/.claude/agents/{security → specialists}/security-specialist.md +6 -30
  69. package/.claude/agents/{specialized/mobile → specialists}/spec-mobile-react-native.md +2 -21
  70. package/.claude/agents/testers/README.md +94 -0
  71. package/.claude/agents/{testing → testers}/e2e/playwright-agent.md +1 -20
  72. package/.claude/agents/{testing → testers}/interaction-tester.md +1 -20
  73. package/.claude/agents/{testing → testers}/playwright-tester.md +1 -1
  74. package/.claude/agents/testers/tester.md +139 -0
  75. package/.claude/agents/testers/unit/tdd-london-swarm.md +49 -0
  76. package/.claude/agents/testers/validation/production-validator.md +33 -0
  77. package/.claude/agents-ignore/cfn-loop-coordinator.md +157 -0
  78. package/.claude/agents-ignore/cfn-loop-coordinator.md.backup +156 -0
  79. package/.claude/agents-ignore/coordinator.md.backup +182 -0
  80. package/.claude/agents-ignore/cost-savings-cfn-loop-coordinator.md +760 -0
  81. package/.claude/agents-ignore/cost-savings-coordinator.md +173 -0
  82. package/.claude/artifacts/ace-reflections/REFLECT-001-summary.json +39 -0
  83. package/.claude/artifacts/ace-reflections/sprint-7_$(date -u +/"%Y%m%d_%H%M%S/").json" +47 -0
  84. package/.claude/commands/CFN_COORDINATOR_PARAMETERS.md +10 -10
  85. package/.claude/commands/cfn-loop-epic.md +3 -3
  86. package/.claude/commands/cfn-loop-single.md +3 -3
  87. package/.claude/commands/cfn-loop-sprints.md +1 -1
  88. package/.claude/commands/cfn-loop.md +3 -3
  89. package/.claude/commands/cfn-mode.md +20 -0
  90. package/.claude/commands/write-plan.md +104 -0
  91. package/.claude/data/cfn-loop.db +0 -0
  92. package/.claude/data/cfn_loop_logs.db +0 -0
  93. package/.claude/hooks/BACKUP_USAGE.md +243 -0
  94. package/.claude/hooks/post-edit-cfn-retrospective.sh +79 -0
  95. package/.claude/hooks/post-edit.sh +21 -0
  96. package/.claude/hooks/pre-edit-backup.sh +71 -0
  97. package/.claude/hooks/restore-from-backup.sh +37 -0
  98. package/.claude/prompts/cfn-loop-context.md +115 -0
  99. package/.claude/prompts/loop-specific/loop2.md +50 -0
  100. package/.claude/prompts/loop-specific/loop3.md +43 -0
  101. package/.claude/prompts/loop-specific/loop4.md +54 -0
  102. package/.claude/root-claude-distribute/CLAUDE.md +76 -2
  103. package/.claude/skills/ace-system/sprint-7-lessons.json +46 -0
  104. package/.claude/skills/ace-system/store-reflection.sh +33 -136
  105. package/.claude/skills/agent-discovery/SKILL.md +40 -0
  106. package/.claude/skills/agent-discovery/agents-registry-clean.json +0 -0
  107. package/.claude/skills/agent-discovery/agents-registry-fixed.json +19 -0
  108. package/.claude/skills/agent-discovery/agents-registry.json +718 -0
  109. package/.claude/skills/agent-discovery/discover-agents.py +175 -0
  110. package/.claude/skills/agent-discovery/discover-agents.sh +87 -0
  111. package/.claude/skills/agent-discovery/invoke-registry.sh +11 -0
  112. package/.claude/skills/agent-discovery/temp_script.py +0 -0
  113. package/.claude/skills/agent-output-processing/SKILL.md +359 -0
  114. package/.claude/skills/agent-selector/SKILL.md +90 -0
  115. package/.claude/skills/agent-selector/select-agents.sh +96 -0
  116. package/.claude/skills/agent-spawning/agent-selection-guide.md +1 -1
  117. package/.claude/skills/agent-swap/SKILL.md +36 -0
  118. package/.claude/skills/agent-swap/recommend-swap.sh +60 -0
  119. package/.claude/skills/api-validation/test-endpoints.sh +54 -0
  120. package/.claude/skills/automatic-memory-persistence/SKILL.md +73 -0
  121. package/.claude/skills/automatic-memory-persistence/persist-agent-output.sh +49 -0
  122. package/.claude/skills/automatic-memory-persistence/query-agent-history.sh +35 -0
  123. package/.claude/skills/automatic-memory-persistence/test-memory-persistence.sh +235 -0
  124. package/.claude/skills/cfn-loop-orchestration/README.md +41 -0
  125. package/.claude/skills/cfn-loop-orchestration/SKILL.md +299 -0
  126. package/.claude/skills/cfn-loop-orchestration/helpers/auto-tune-timeouts.sh +228 -0
  127. package/.claude/skills/cfn-loop-orchestration/helpers/consensus.sh +84 -0
  128. package/.claude/skills/cfn-loop-orchestration/helpers/deliverable-verifier.sh +71 -0
  129. package/.claude/skills/cfn-loop-orchestration/helpers/gate-check.sh +90 -0
  130. package/.claude/skills/cfn-loop-orchestration/helpers/iteration-manager.sh +87 -0
  131. package/.claude/skills/cfn-loop-orchestration/helpers/timeout-calculator.sh +51 -0
  132. package/.claude/skills/cfn-loop-orchestration/inject-loop-context.sh +41 -0
  133. package/.claude/skills/cfn-loop-orchestration/monitor-execution.sh +156 -0
  134. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +840 -0
  135. package/.claude/skills/cfn-loop-orchestration/security_utils.sh +99 -0
  136. package/.claude/skills/cfn-loop-orchestration/test-cfn-orchestration.sh +281 -0
  137. package/.claude/skills/cfn-loop-orchestration/test-edge-cases.sh +188 -0
  138. package/.claude/skills/cfn-loop-validation/SKILL.md +307 -217
  139. package/.claude/skills/complexity-estimator/SKILL.md +96 -0
  140. package/.claude/skills/complexity-estimator/estimate-complexity.sh +144 -0
  141. package/.claude/skills/context-pruner/SKILL.md +75 -0
  142. package/.claude/skills/context-pruner/prune-context.sh +73 -0
  143. package/.claude/skills/defense-in-depth/SKILL.md +133 -0
  144. package/.claude/skills/dependency-extractor/SKILL.md +35 -0
  145. package/.claude/skills/dependency-extractor/extract-dependencies.sh +66 -0
  146. package/.claude/skills/epic-decomposer/SKILL.md +44 -0
  147. package/.claude/skills/epic-decomposer/decompose-epic.sh +104 -0
  148. package/.claude/skills/improvement-recommender/SKILL.md +33 -0
  149. package/.claude/skills/improvement-recommender/recommend-improvements.sh +92 -0
  150. package/.claude/skills/intervention-detector/SKILL.md +39 -0
  151. package/.claude/skills/intervention-detector/detect-intervention.sh +111 -0
  152. package/.claude/skills/intervention-orchestrator/SKILL.md +43 -0
  153. package/.claude/skills/intervention-orchestrator/execute-intervention.sh +59 -0
  154. package/.claude/skills/loop2-output-processing/SKILL.md +163 -0
  155. package/.claude/skills/loop2-output-processing/execute-and-extract.sh +77 -0
  156. package/.claude/skills/loop2-output-processing/execute-and-extract.sh.backup +36 -0
  157. package/.claude/skills/loop2-output-processing/parse-feedback.sh +147 -0
  158. package/.claude/skills/loop2-output-processing/process-validator-output.sh +275 -0
  159. package/.claude/skills/loop2-output-processing/test-bug27-fix.sh +200 -0
  160. package/.claude/skills/loop2-output-processing/test-loop2-processing.sh +113 -0
  161. package/.claude/skills/loop3-output-processing/AGENT_COMPLETION_PROTOCOL.md +206 -0
  162. package/.claude/skills/loop3-output-processing/SKILL.md +421 -0
  163. package/.claude/skills/loop3-output-processing/calculate-confidence.sh +28 -0
  164. package/.claude/skills/loop3-output-processing/execute-and-extract.sh +85 -0
  165. package/.claude/skills/loop3-output-processing/parse-confidence.sh +31 -0
  166. package/.claude/skills/loop3-output-processing/test-agent-timeout.sh +327 -0
  167. package/.claude/skills/loop3-output-processing/test-loop3-processing.sh +155 -0
  168. package/.claude/skills/loop3-output-processing/verify-deliverables.sh +42 -0
  169. package/.claude/skills/pattern-extraction/SKILL.md +30 -0
  170. package/.claude/skills/pattern-extraction/extract-patterns.sh +80 -0
  171. package/.claude/skills/playbook/SKILL.md +113 -0
  172. package/.claude/skills/playbook/init-playbook.sh +54 -0
  173. package/.claude/skills/playbook/playbook.db +0 -0
  174. package/.claude/skills/playbook/query-playbook.sh +79 -0
  175. package/.claude/skills/playbook/update-playbook.sh +69 -0
  176. package/.claude/skills/playbook-auto-update/SKILL.md +29 -0
  177. package/.claude/skills/playbook-auto-update/auto-update-playbook.sh +86 -0
  178. package/.claude/skills/product-owner-decision/SKILL.md +332 -0
  179. package/.claude/skills/product-owner-decision/execute-decision.sh +176 -0
  180. package/.claude/skills/product-owner-decision/parse-decision.sh +66 -0
  181. package/.claude/skills/product-owner-decision/validate-deliverables.sh +82 -0
  182. package/.claude/skills/redis-coordination/LOGGING.md +260 -0
  183. package/.claude/skills/redis-coordination/README.md +30 -29
  184. package/.claude/skills/redis-coordination/SKILL.md +685 -83
  185. package/.claude/skills/redis-coordination/analyze-task-complexity.sh +277 -0
  186. package/.claude/skills/redis-coordination/cfn-loop-exec.sh +468 -0
  187. package/.claude/skills/redis-coordination/collect-confidence-scores.sh +179 -0
  188. package/.claude/skills/redis-coordination/collect-results.sh +75 -0
  189. package/.claude/skills/redis-coordination/data/cfn-loop.db +0 -0
  190. package/.claude/skills/redis-coordination/{test-orchestrator.sh → demos/test-orchestrator.sh} +25 -0
  191. package/.claude/skills/redis-coordination/execute-product-owner-decision.sh +258 -0
  192. package/.claude/skills/redis-coordination/get-agent-timeout.sh +176 -176
  193. package/.claude/skills/redis-coordination/invoke-waiting-mode.sh +93 -227
  194. package/.claude/skills/redis-coordination/invoke-waiting-mode.sh.backup-p7 +423 -0
  195. package/.claude/skills/redis-coordination/log-event.sh +109 -0
  196. package/.claude/skills/redis-coordination/monitor-cfn-violations.sh +391 -0
  197. package/.claude/skills/redis-coordination/orchestrate-cfn-loop-v3.sh +141 -0
  198. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh +31 -993
  199. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup +38 -0
  200. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup-1761167675 +1672 -0
  201. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup-p5 +1604 -0
  202. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup-phase1 +1550 -0
  203. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup-phase2 +1621 -0
  204. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup-phase3 +1621 -0
  205. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.bak +0 -0
  206. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.broken +1627 -0
  207. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.corrupted +80 -0
  208. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.deprecated +1864 -0
  209. package/.claude/skills/redis-coordination/query-logs.sh +103 -0
  210. package/.claude/skills/redis-coordination/retrieve-context.sh +58 -0
  211. package/.claude/skills/redis-coordination/select-specialist-agent.sh +371 -0
  212. package/.claude/skills/redis-coordination/semantic-match-tfidf.py +252 -0
  213. package/.claude/skills/redis-coordination/send-heartbeat.sh +164 -72
  214. package/.claude/skills/redis-coordination/signal.sh +38 -0
  215. package/.claude/skills/redis-coordination/store-context.sh +86 -0
  216. package/.claude/skills/redis-coordination/test-context-injection.sh +354 -0
  217. package/.claude/skills/redis-coordination/test-timeout-enforcement.sh +513 -0
  218. package/.claude/skills/redis-coordination/tests/convert-line-endings.sh +15 -0
  219. package/.claude/skills/redis-coordination/tests/dlq-functionality-test.sh +101 -101
  220. package/.claude/skills/redis-coordination/tests/edge-cases-test.sh +98 -98
  221. package/.claude/skills/redis-coordination/tests/integration-test.sh +169 -169
  222. package/.claude/skills/redis-coordination/tests/retry-mechanism-test.sh +81 -81
  223. package/.claude/skills/redis-coordination/tests/run-test-suite.sh +91 -91
  224. package/.claude/skills/redis-coordination/tests/run-tests.sh +4 -0
  225. package/.claude/skills/redis-coordination/tests/test-primitives.sh +166 -0
  226. package/.claude/skills/redis-coordination/tests/test-utils.sh +53 -121
  227. package/.claude/skills/redis-coordination/tests/test_coordination_primitives.sh.deprecated +20 -0
  228. package/.claude/skills/redis-coordination/tests/test_utils.sh +49 -0
  229. package/.claude/skills/redis-coordination/v2_modularization/core_orchestration.sh +76 -0
  230. package/.claude/skills/redis-coordination/validate-parameters.sh +492 -0
  231. package/.claude/skills/retrospective-report/SKILL.md +31 -0
  232. package/.claude/skills/retrospective-report/generate-report.sh +101 -0
  233. package/.claude/skills/run-all-skill-tests.sh +124 -0
  234. package/.claude/skills/scope-simplifier/SKILL.md +37 -0
  235. package/.claude/skills/scope-simplifier/simplify-scope.sh +68 -0
  236. package/.claude/skills/simplified-agent-lifecycle/COST_ANALYSIS.md +49 -0
  237. package/.claude/skills/simplified-agent-lifecycle/DESIGN.md +98 -0
  238. package/.claude/skills/simplified-agent-lifecycle/MIGRATION_PLAN.md +74 -0
  239. package/.claude/skills/specialist-injection/SKILL.md +41 -0
  240. package/.claude/skills/specialist-injection/recommend-specialist.sh +57 -0
  241. package/.claude/skills/sprint-execution/SKILL.md +27 -0
  242. package/.claude/skills/sprint-execution/execute-sprint-task.sh +59 -0
  243. package/.claude/skills/sprint-execution/execute-sprint.sh +65 -0
  244. package/.claude/skills/sprint-planner/SKILL.md +37 -0
  245. package/.claude/skills/sprint-planner/plan-sprint.sh +85 -0
  246. package/.claude/skills/standardized-error-handling/SKILL.md +56 -0
  247. package/.claude/skills/standardized-error-handling/capture-agent-error.sh +87 -0
  248. package/.claude/skills/standardized-error-handling/test-error-handling.sh +166 -0
  249. package/.claude/skills/task-classifier/SKILL.md +94 -0
  250. package/.claude/skills/task-classifier/classify-task.sh +115 -0
  251. package/.claude/skills/validation-templates/SKILL.md +47 -0
  252. package/.claude/skills/validation-templates/content.json +38 -0
  253. package/.claude/skills/validation-templates/data.json +38 -0
  254. package/.claude/skills/validation-templates/design.json +38 -0
  255. package/.claude/skills/validation-templates/infrastructure.json +38 -0
  256. package/.claude/skills/validation-templates/research.json +38 -0
  257. package/.claude/skills/validation-templates/software.json +38 -0
  258. package/.claude/skills/webapp-testing/README.md +142 -0
  259. package/.claude/skills/webapp-testing/SCREENSHOT_NAMING_CONVENTION.md +547 -0
  260. package/.claude/skills/webapp-testing/SKILL.md +877 -0
  261. package/.claude/skills/webapp-testing/capture-screenshot.sh +238 -0
  262. package/.claude/skills/webapp-testing/cfn-loop-integration.sh +265 -0
  263. package/.claude/skills/webapp-testing/compare-screenshots.sh +199 -0
  264. package/.claude/skills/webapp-testing/init-storage.sh +150 -0
  265. package/.claude/skills/webapp-testing/set-baseline.sh +196 -0
  266. package/.claude/skills/webapp-testing/test-webapp-testing.sh +233 -0
  267. package/.claude/spawn-pattern-examples.md +3 -3
  268. package/CLAUDE.md +319 -45
  269. package/README.md +598 -251
  270. package/dist/agents/agent-loader.js +146 -165
  271. package/dist/agents/agent-loader.js.map +1 -1
  272. package/dist/cli/agent-command.js +2 -0
  273. package/dist/cli/agent-command.js.map +1 -1
  274. package/dist/cli/agent-definition-parser.js +7 -0
  275. package/dist/cli/agent-definition-parser.js.map +1 -1
  276. package/dist/cli/agent-executor.js +145 -11
  277. package/dist/cli/agent-executor.js.map +1 -1
  278. package/dist/cli/agent-prompt-builder.js +81 -1
  279. package/dist/cli/agent-prompt-builder.js.map +1 -1
  280. package/dist/cli/agent-spawn.js +10 -1
  281. package/dist/cli/agent-spawn.js.map +1 -1
  282. package/dist/cli/anthropic-client.js +192 -13
  283. package/dist/cli/anthropic-client.js.map +1 -1
  284. package/dist/cli/cfn-context.js +150 -0
  285. package/dist/cli/cfn-context.js.map +1 -1
  286. package/dist/cli/cfn-fork.js +159 -0
  287. package/dist/cli/cfn-fork.js.map +1 -0
  288. package/dist/cli/cli-agent-context.js +8 -3
  289. package/dist/cli/cli-agent-context.js.map +1 -1
  290. package/dist/cli/config-manager.js +109 -91
  291. package/dist/cli/config-manager.js.map +1 -1
  292. package/dist/cli/conversation-fork.js +201 -0
  293. package/dist/cli/conversation-fork.js.map +1 -0
  294. package/dist/cli/index.js +4 -0
  295. package/dist/cli/index.js.map +1 -1
  296. package/dist/cli/tool-definitions.js +263 -0
  297. package/dist/cli/tool-definitions.js.map +1 -0
  298. package/dist/cli/tool-executor.js +247 -0
  299. package/dist/cli/tool-executor.js.map +1 -0
  300. package/dist/hello.js +8 -0
  301. package/dist/hello.js.map +1 -0
  302. package/package.json +14 -6
  303. package/scripts/README.md +68 -0
  304. package/scripts/cfn-intervention-example.sh +21 -0
  305. package/scripts/migrate-test-infrastructure.sh +40 -0
  306. package/scripts/validate-test-migration.sh +49 -0
  307. package/scripts/verify-no-secrets.sh +55 -0
  308. package/.claude/agents/architecture/system-architect.md.backup +0 -603
  309. package/.claude/agents/code-booster.md +0 -131
  310. package/.claude/agents/consensus/performance-benchmarker.md +0 -101
  311. package/.claude/agents/consensus/security-manager.md +0 -107
  312. package/.claude/agents/context-curator.md +0 -167
  313. package/.claude/agents/context-reflector.md +0 -65
  314. package/.claude/agents/core-agents/cfn-loop-coordinator.md +0 -134
  315. package/.claude/agents/core-agents/code-quality-validator.md +0 -149
  316. package/.claude/agents/core-agents/context-curator.md +0 -452
  317. package/.claude/agents/core-agents/context-reflector.md +0 -273
  318. package/.claude/agents/core-agents/cost-savings-cfn-loop-coordinator.md +0 -235
  319. package/.claude/agents/core-agents/tester.md +0 -170
  320. package/.claude/agents/development/backend-dev.md +0 -165
  321. package/.claude/agents/devops/devops-engineer.md +0 -148
  322. package/.claude/agents/frontend/interaction-tester.md +0 -139
  323. package/.claude/agents/frontend/react-frontend-engineer.md +0 -9
  324. package/.claude/agents/personas/accessibility-advocate-persona.md +0 -107
  325. package/.claude/agents/testing/production-validator.md +0 -179
  326. package/.claude/agents/testing/tdd-london-swarm.md +0 -209
  327. package/.claude/agents/testing/unit/tdd-london-swarm.md +0 -43
  328. package/.claude/agents/testing/validation/production-validator.md +0 -43
  329. package/.claude/api-configs/config-current-zai-config.env +0 -62
  330. package/.claude/api-configs/config-test-zai-config.env +0 -62
  331. package/.claude/api-configs/env-backups/before-anthropic-20251020-025404.env +0 -62
  332. package/.claude/api-configs/env-backups/before-restore-20251020-025431.env +0 -62
  333. package/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh.backup-1760949407 +0 -933
  334. package/dist/cli/cli-agent-context.test.js +0 -451
  335. package/dist/cli/cli-agent-context.test.js.map +0 -1
  336. package/dist/coordination/fleet-manager.test.js +0 -141
  337. package/dist/coordination/fleet-manager.test.js.map +0 -1
  338. package/dist/middleware/transparency-middleware.test.js +0 -184
  339. package/dist/middleware/transparency-middleware.test.js.map +0 -1
  340. /package/.claude/agents/{core-agents → developers}/researcher.md +0 -0
  341. /package/.claude/agents/{consensus → specialists}/crdt-synchronizer.md +0 -0
  342. /package/.claude/agents/{consensus → specialists}/quorum-manager.md +0 -0
  343. /package/.claude/agents/{consensus → specialists}/raft-manager.md +0 -0
  344. /package/.claude/{agents/core-agents → agents-ignore}/coordinator.md +0 -0
  345. /package/.claude/{agents/core-agents/cost-savings-coordinator.md → agents-ignore/cost-savings-coordinator.md.backup} +0 -0
  346. /package/.claude/skills/redis-coordination/{phase4-wake-queue-test-report.md → demos/phase4-wake-queue-test-report.md} +0 -0
  347. /package/.claude/skills/redis-coordination/{test-bzpopmin-fix.sh → demos/test-bzpopmin-fix.sh} +0 -0
  348. /package/.claude/skills/redis-coordination/{test-cancel-swarm.sh → demos/test-cancel-swarm.sh} +0 -0
  349. /package/.claude/skills/redis-coordination/{test-dlq.sh → demos/test-dlq.sh} +0 -0
  350. /package/.claude/skills/redis-coordination/{test-iteration-feedback.sh → demos/test-iteration-feedback.sh} +0 -0
  351. /package/.claude/skills/redis-coordination/{test-priority-wake-phase4-unix.sh → demos/test-priority-wake-phase4-unix.sh} +0 -0
  352. /package/.claude/skills/redis-coordination/{test-priority-wake-phase4.sh → demos/test-priority-wake-phase4.sh} +0 -0
  353. /package/.claude/skills/redis-coordination/{test-priority-wake.sh → demos/test-priority-wake.sh} +0 -0
  354. /package/.claude/skills/redis-coordination/{test-quick-fix.sh → demos/test-quick-fix.sh} +0 -0
  355. /package/.claude/skills/redis-coordination/{test-quorum-absolute.sh → demos/test-quorum-absolute.sh} +0 -0
  356. /package/.claude/skills/redis-coordination/{test-quorum-fallback.sh → demos/test-quorum-fallback.sh} +0 -0
  357. /package/.claude/skills/redis-coordination/{test-quorum-percentage.sh → demos/test-quorum-percentage.sh} +0 -0
  358. /package/.claude/skills/redis-coordination/{test-quorum-with-retry.sh → demos/test-quorum-with-retry.sh} +0 -0
  359. /package/.claude/skills/redis-coordination/{test-quorum.sh → demos/test-quorum.sh} +0 -0
  360. /package/.claude/skills/redis-coordination/{test-shutdown-handling.sh → demos/test-shutdown-handling.sh} +0 -0
  361. /package/.claude/skills/redis-coordination/{test-shutdown.sh → demos/test-shutdown.sh} +0 -0
  362. /package/.claude/skills/redis-coordination/{test-utils-unix.sh → demos/test-utils-unix.sh} +0 -0
  363. /package/.claude/skills/redis-coordination/{test-utils.sh → demos/test-utils.sh} +0 -0
  364. /package/.claude/skills/redis-coordination/{test-waiting-mode.sh → demos/test-waiting-mode.sh} +0 -0
@@ -1,993 +1,31 @@
1
- #!/usr/bin/env bash
2
-
3
- ##############################################################################
4
- # CFN Loop Orchestration v2.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
- # [--min-quorum-loop3 <n|n%|0.n>] \
15
- # [--min-quorum-loop2 <n|n%|0.n>]
16
- #
17
- # CFN Loop Structure (CORRECTED):
18
- # Loop 3 (Primary Swarm - Self Validation)
19
- # ↓
20
- # IF Loop 3 self-validation gate FAILS → RELAUNCH Loop 3 (skip Loop 2)
21
- # IF Loop 3 self-validation gate PASSES → Proceed to Loop 2
22
- # ↓
23
- # Loop 2 (Consensus Validators)
24
- # ↓
25
- # Product Owner Decision
26
- #
27
- # Dependency Enforcement:
28
- # - Loop 3 agents self-validate via confidence scores
29
- # - Gate check determines if Loop 2 validators should be engaged
30
- # - Loop 2 agents WAIT for gate pass signal before starting work
31
- # - Product Owner BLOCKS until all Loop 2 agents signal completion
32
- # - Uses Redis BLPOP for zero-token waiting
33
- #
34
- # Quorum Configuration:
35
- # - Absolute: --min-quorum-loop3 3 (requires exactly 3 agents)
36
- # - Percentage: --min-quorum-loop3 85% (requires 85% of agents)
37
- # - Decimal: --min-quorum-loop3 0.66 (requires 66% of agents)
38
- # - Default: 0.66 (2/3 majority) if not specified
39
- #
40
- # Agent Requirements:
41
- # Loop 3 (Implementers):
42
- # 1. Complete work
43
- # 2. Signal done: redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
44
- # 3. Report confidence: invoke-waiting-mode.sh report --confidence <0.0-1.0>
45
- # 4. Enter waiting: invoke-waiting-mode.sh enter (for potential iteration)
46
- #
47
- # Loop 2 (Validators):
48
- # 1. WAIT for gate pass: redis-cli blpop "swarm:${TASK_ID}:gate-passed" 0
49
- # 2. Retrieve Loop 3 results for review
50
- # 3. Perform validation
51
- # 4. Signal done: redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
52
- # 5. Report consensus: invoke-waiting-mode.sh report --confidence <0.0-1.0>
53
- # 6. Enter waiting: invoke-waiting-mode.sh enter (for potential iteration)
54
- ##############################################################################
55
-
56
- set -euo pipefail
57
-
58
- # Configuration
59
- TASK_ID=""
60
- MODE="standard"
61
- LOOP3_AGENTS=""
62
- LOOP2_AGENTS=""
63
- PRODUCT_OWNER=""
64
- MAX_ITERATIONS=10
65
- TIMEOUT=3600 # 1 hour timeout for agent completion
66
- RETRY_COUNT=3
67
- RETRY_DELAY=5000 # Base delay in milliseconds
68
- MIN_QUORUM_LOOP3="" # Minimum agents required for Loop 3 (absolute or percentage)
69
- MIN_QUORUM_LOOP2="" # Minimum agents required for Loop 2 (absolute or percentage)
70
- ORCHESTRATOR_PID=$$
71
- SHUTDOWN_MONITOR_PID=""
72
- SHUTDOWN_REQUESTED=0
73
- LOOP3_HEARTBEAT_MONITOR_PID=""
74
- LOOP2_HEARTBEAT_MONITOR_PID=""
75
-
76
- # Thresholds by mode
77
- declare -A GATE_THRESHOLD=(
78
- [mvp]=0.70
79
- [standard]=0.75
80
- [enterprise]=0.75
81
- )
82
-
83
- declare -A CONSENSUS_THRESHOLD=(
84
- [mvp]=0.80
85
- [standard]=0.90
86
- [enterprise]=0.95
87
- )
88
-
89
- # Parse arguments
90
- while [[ $# -gt 0 ]]; do
91
- case $1 in
92
- --task-id)
93
- TASK_ID="$2"
94
- shift 2
95
- ;;
96
- --mode)
97
- MODE="$2"
98
- shift 2
99
- ;;
100
- --loop3-agents)
101
- LOOP3_AGENTS="$2"
102
- shift 2
103
- ;;
104
- --loop2-agents)
105
- LOOP2_AGENTS="$2"
106
- shift 2
107
- ;;
108
- --product-owner)
109
- PRODUCT_OWNER="$2"
110
- shift 2
111
- ;;
112
- --max-iterations)
113
- MAX_ITERATIONS="$2"
114
- shift 2
115
- ;;
116
- --retry-count)
117
- RETRY_COUNT="$2"
118
- shift 2
119
- ;;
120
- --retry-delay)
121
- RETRY_DELAY="$2"
122
- shift 2
123
- ;;
124
- --timeout)
125
- TIMEOUT="$2"
126
- shift 2
127
- ;;
128
- --min-quorum-loop3)
129
- MIN_QUORUM_LOOP3="$2"
130
- shift 2
131
- ;;
132
- --min-quorum-loop2)
133
- MIN_QUORUM_LOOP2="$2"
134
- shift 2
135
- ;;
136
- *)
137
- echo "Unknown option: $1"
138
- exit 1
139
- ;;
140
- esac
141
- done
142
-
143
- # Validation
144
- if [ -z "$TASK_ID" ] || [ -z "$LOOP3_AGENTS" ] || [ -z "$LOOP2_AGENTS" ] || [ -z "$PRODUCT_OWNER" ]; then
145
- echo "Error: Required parameters missing"
146
- echo "Usage: $0 --task-id <id> --mode <mode> --loop3-agents <agents> --loop2-agents <agents> --product-owner <agent>"
147
- exit 1
148
- fi
149
-
150
- GATE=${GATE_THRESHOLD[$MODE]}
151
- CONSENSUS=${CONSENSUS_THRESHOLD[$MODE]}
152
-
153
- # Set default quorum values if not specified (66% = 2/3 majority)
154
- MIN_QUORUM_LOOP3=${MIN_QUORUM_LOOP3:-0.66}
155
- MIN_QUORUM_LOOP2=${MIN_QUORUM_LOOP2:-0.66}
156
-
157
- ##############################################################################
158
- # Shutdown Handling Functions
159
- ##############################################################################
160
- function cleanup_and_exit() {
161
- local exit_code="${1:-130}"
162
- local reason="${2:-user_interrupt}"
163
-
164
- # Set shutdown flag to stop any ongoing operations
165
- SHUTDOWN_REQUESTED=1
166
-
167
- echo ""
168
- echo "=============================================="
169
- echo "🛑 Orchestrator shutting down gracefully..."
170
- echo "=============================================="
171
- echo "Reason: $reason"
172
- echo "Exit Code: $exit_code"
173
-
174
- # Kill shutdown monitor if running
175
- if [ -n "$SHUTDOWN_MONITOR_PID" ] && kill -0 "$SHUTDOWN_MONITOR_PID" 2>/dev/null; then
176
- kill "$SHUTDOWN_MONITOR_PID" 2>/dev/null || true
177
- wait "$SHUTDOWN_MONITOR_PID" 2>/dev/null || true
178
- fi
179
-
180
- # Stop heartbeat monitors if running
181
- if [ -n "${LOOP3_HEARTBEAT_MONITOR_PID:-}" ]; then
182
- echo "Stopping Loop 3 heartbeat monitor..."
183
- stop_heartbeat_monitor "$TASK_ID" "loop3" "$LOOP3_HEARTBEAT_MONITOR_PID"
184
- fi
185
- if [ -n "${LOOP2_HEARTBEAT_MONITOR_PID:-}" ]; then
186
- echo "Stopping Loop 2 heartbeat monitor..."
187
- stop_heartbeat_monitor "$TASK_ID" "loop2" "$LOOP2_HEARTBEAT_MONITOR_PID"
188
- fi
189
-
190
- # Mark swarm as cancelled if initialized
191
- if [ -n "$TASK_ID" ] && [ -n "${SWARM_ID:-}" ]; then
192
- echo "Marking swarm as cancelled..."
193
- ./.claude/skills/redis-coordination/complete-swarm.sh \
194
- --swarm-id "$SWARM_ID" \
195
- --final-metric "status=cancelled" \
196
- --final-metric "shutdown_reason=$reason" 2>/dev/null || echo " ⚠️ Failed to mark swarm as cancelled"
197
- fi
198
-
199
- # Clean up Redis keys
200
- if [ -n "$TASK_ID" ]; then
201
- echo "Cleaning up Redis keys..."
202
- local keys_deleted=$(redis-cli --scan --pattern "swarm:${TASK_ID}:*" | xargs -r redis-cli DEL 2>/dev/null || echo "0")
203
- echo " Deleted $keys_deleted Redis keys"
204
- fi
205
-
206
- # Clean up heartbeat monitor marker files
207
- rm -f /tmp/heartbeat-monitor-${TASK_ID}-*.active 2>/dev/null || true
208
-
209
- echo "=============================================="
210
- echo "Shutdown complete"
211
- echo "=============================================="
212
-
213
- exit "$exit_code"
214
- }
215
-
216
- # Trap SIGTERM and SIGINT for graceful shutdown
217
- trap 'echo "[TRAP] Caught SIGINT" >&2; cleanup_and_exit 130 "SIGINT_received"' SIGINT
218
- trap 'echo "[TRAP] Caught SIGTERM" >&2; cleanup_and_exit 143 "SIGTERM_received"' SIGTERM
219
-
220
- ##############################################################################
221
- # Start Shutdown Monitor (Background Process)
222
- ##############################################################################
223
- function start_shutdown_monitor() {
224
- local task_id="$1"
225
-
226
- (
227
- # Block on shutdown channel (zero-token waiting)
228
- SHUTDOWN_KEY="swarm:${task_id}:shutdown"
229
- SHUTDOWN_RESULT=$(redis-cli BLPOP "$SHUTDOWN_KEY" 0 2>/dev/null || echo "")
230
-
231
- if [ -n "$SHUTDOWN_RESULT" ]; then
232
- # Extract shutdown payload (format: key value)
233
- SHUTDOWN_PAYLOAD=$(echo "$SHUTDOWN_RESULT" | tail -1)
234
- REASON=$(echo "$SHUTDOWN_PAYLOAD" | jq -r '.reason // "external_shutdown"' 2>/dev/null || echo "external_shutdown")
235
-
236
- echo ""
237
- echo "🛑 Shutdown signal received from Redis channel: $REASON"
238
- echo " Sending SIGTERM to orchestrator PID: $ORCHESTRATOR_PID"
239
-
240
- # Send SIGTERM to main orchestrator process
241
- if kill -TERM "$ORCHESTRATOR_PID" 2>/dev/null; then
242
- echo " ✅ SIGTERM sent successfully"
243
- else
244
- echo " ❌ Failed to send SIGTERM (process may have already exited)"
245
- exit 0
246
- fi
247
- fi
248
- ) &
249
-
250
- SHUTDOWN_MONITOR_PID=$!
251
- echo "Shutdown monitor started (PID: $SHUTDOWN_MONITOR_PID)"
252
- }
253
-
254
- ##############################################################################
255
- # Quorum Calculation Function
256
- ##############################################################################
257
- function calculate_quorum() {
258
- local quorum_spec="$1"
259
- local total_agents="$2"
260
-
261
- # If no quorum specified, require all agents
262
- if [ -z "$quorum_spec" ]; then
263
- echo "$total_agents"
264
- return 0
265
- fi
266
-
267
- # Check if percentage format (e.g., "85%")
268
- if [[ "$quorum_spec" =~ %$ ]]; then
269
- # Extract percentage value (remove % suffix)
270
- local pct="${quorum_spec%\%}"
271
- # Calculate: ceil(total_agents * pct / 100)
272
- echo "scale=0; ($total_agents * $pct + 50) / 100" | bc
273
- # Check if decimal (0.0-1.0), treat as fraction
274
- elif [[ "$quorum_spec" =~ ^0?\.[0-9]+$ ]]; then
275
- # Calculate: ceil(total_agents * fraction)
276
- echo "scale=0; ($quorum_spec * $total_agents + 0.5) / 1" | bc
277
- else
278
- # Absolute number - validate it doesn't exceed total
279
- if [ "$quorum_spec" -gt "$total_agents" ]; then
280
- echo "Error: Quorum ($quorum_spec) exceeds total agents ($total_agents)" >&2
281
- return 1
282
- fi
283
- echo "$quorum_spec"
284
- fi
285
- }
286
-
287
- ##############################################################################
288
- # Dead Letter Queue (DLQ) Functions
289
- ##############################################################################
290
- function write_to_dlq() {
291
- local agent="$1"
292
- local reason="$2"
293
- local retry_count="$3"
294
-
295
- DLQ_KEY="swarm:${TASK_ID}:dlq:${agent}"
296
- DLQ_ENTRY=$(jq -n \
297
- --arg reason "$reason" \
298
- --arg retries "$retry_count" \
299
- --arg ts "$(date +%s)" \
300
- '{reason: $reason, retry_count: ($retries | tonumber), timestamp: ($ts | tonumber)}')
301
-
302
- echo "$DLQ_ENTRY" | redis-cli -x LPUSH "$DLQ_KEY" >/dev/null
303
- redis-cli EXPIRE "$DLQ_KEY" 604800 >/dev/null # 7 days TTL
304
-
305
- echo " ❌ $agent → DLQ (reason: $reason, retries: $retry_count)"
306
- }
307
-
308
- ##############################################################################
309
- # Exponential Backoff Retry Function
310
- ##############################################################################
311
- function retry_with_backoff() {
312
- local agent="$1"
313
- local attempt="$2"
314
- local max_retries="$3"
315
- local base_delay="$4"
316
-
317
- # Check for shutdown before sleeping
318
- if [ "$SHUTDOWN_REQUESTED" -eq 1 ]; then
319
- echo " [SHUTDOWN] Skipping backoff delay for $agent" >&2
320
- return 0
321
- fi
322
-
323
- # Exponential backoff: delay = base_delay * (2 ^ attempt)
324
- local delay=$(echo "$base_delay * (2 ^ $attempt)" | bc)
325
- local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
326
-
327
- echo " [$timestamp] [Retry $attempt/$max_retries] Waiting ${delay}ms before retry for $agent..."
328
-
329
- # Use interruptible sleep - sleep in small increments and check for shutdown
330
- local delay_sec=$(echo "scale=3; $delay / 1000" | bc)
331
- local elapsed=0
332
- while (( $(echo "$elapsed < $delay_sec" | bc -l) )); do
333
- # Sleep for 0.5s increments (or remaining time if less)
334
- local remaining=$(echo "$delay_sec - $elapsed" | bc)
335
- local sleep_time=$(echo "if ($remaining < 0.5) $remaining else 0.5" | bc)
336
-
337
- sleep "$sleep_time" &
338
- wait $! 2>/dev/null || return 0 # If wait is interrupted (SIGTERM), return immediately
339
-
340
- elapsed=$(echo "$elapsed + $sleep_time" | bc)
341
-
342
- # Check for shutdown after each sleep increment
343
- if [ "$SHUTDOWN_REQUESTED" -eq 1 ]; then
344
- echo " [SHUTDOWN] Interrupted backoff delay for $agent" >&2
345
- return 0
346
- fi
347
- done
348
- }
349
-
350
- ##############################################################################
351
- # Heartbeat Monitoring Functions
352
- ##############################################################################
353
- declare -A MISSED_HEARTBEATS # Track missed heartbeats per agent
354
-
355
- function check_agent_heartbeat() {
356
- local agent="$1"
357
- local task_id="$2"
358
-
359
- HB_KEY="swarm:${task_id}:${agent}:heartbeat"
360
- HB_DATA=$(redis-cli GET "$HB_KEY" 2>/dev/null || echo "")
361
-
362
- if [ -z "$HB_DATA" ] || [ "$HB_DATA" = "(nil)" ]; then
363
- return 1 # Dead
364
- else
365
- return 0 # Alive
366
- fi
367
- }
368
-
369
- function check_heartbeats_loop() {
370
- local task_id="$1"
371
- local loop_name="$2"
372
- shift 2
373
- local agents=("$@")
374
-
375
- for AGENT in "${agents[@]}"; do
376
- # Skip agents already marked as failed
377
- if [[ " ${LOOP3_FAILED_AGENTS[@]} ${LOOP2_FAILED_AGENTS[@]} " =~ " ${AGENT} " ]]; then
378
- continue
379
- fi
380
-
381
- if ! check_agent_heartbeat "$AGENT" "$task_id"; then
382
- MISSED_HEARTBEATS["$AGENT"]=$((${MISSED_HEARTBEATS["$AGENT"]:-0} + 1))
383
-
384
- if [ ${MISSED_HEARTBEATS["$AGENT"]} -ge 2 ]; then
385
- local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
386
- echo " [$timestamp] [$loop_name] ⚠️ $AGENT appears hung (no heartbeat for 60s)" >&2
387
-
388
- # Determine which loop this agent belongs to and check quorum
389
- if [[ " ${LOOP3_AGENTS} " =~ " ${AGENT} " ]]; then
390
- REMAINING=$((${#LOOP3_COMPLETED_AGENTS[@]}))
391
- REQUIRED=$(calculate_quorum "$MIN_QUORUM_LOOP3" "$LOOP3_TOTAL")
392
- elif [[ " ${LOOP2_AGENTS} " =~ " ${AGENT} " ]]; then
393
- # Safety check: LOOP2_COMPLETED_AGENTS may not be initialized during Loop 3
394
- if [ -z "${LOOP2_COMPLETED_AGENTS+x}" ]; then
395
- continue
396
- fi
397
- REMAINING=$((${#LOOP2_COMPLETED_AGENTS[@]}))
398
- REQUIRED=$(calculate_quorum "$MIN_QUORUM_LOOP2" "$LOOP2_TOTAL")
399
- else
400
- continue
401
- fi
402
-
403
- if [ $REMAINING -ge $REQUIRED ]; then
404
- echo " [$timestamp] [$loop_name] ℹ️ Continuing with quorum (${REMAINING}/${REQUIRED} agents)" >&2
405
- else
406
- echo " [$timestamp] [$loop_name] ⚠️ Cannot meet quorum without $AGENT (${REMAINING}/${REQUIRED})" >&2
407
- fi
408
- fi
409
- else
410
- MISSED_HEARTBEATS["$AGENT"]=0 # Reset counter
411
- fi
412
- done
413
- }
414
-
415
- function start_heartbeat_monitor() {
416
- local task_id="$1"
417
- local loop_name="$2"
418
- shift 2
419
- local agents=("$@")
420
-
421
- # Create marker file for this monitor
422
- local monitor_marker="/tmp/heartbeat-monitor-${task_id}-${loop_name}.active"
423
- touch "$monitor_marker"
424
-
425
- (
426
- while [ -f "$monitor_marker" ]; do
427
- # Check for shutdown
428
- if [ "$SHUTDOWN_REQUESTED" -eq 1 ]; then
429
- break
430
- fi
431
-
432
- check_heartbeats_loop "$task_id" "$loop_name" "${agents[@]}"
433
- sleep 30
434
- done
435
- ) &
436
-
437
- echo "$!" # Return PID
438
- }
439
-
440
- function stop_heartbeat_monitor() {
441
- local task_id="$1"
442
- local loop_name="$2"
443
- local monitor_pid="$3"
444
-
445
- # Remove marker file to stop the monitor loop
446
- rm -f "/tmp/heartbeat-monitor-${task_id}-${loop_name}.active"
447
-
448
- # Kill monitor process if still running
449
- if [ -n "$monitor_pid" ] && kill -0 "$monitor_pid" 2>/dev/null; then
450
- kill "$monitor_pid" 2>/dev/null || true
451
- wait "$monitor_pid" 2>/dev/null || true
452
- fi
453
- }
454
-
455
- ##############################################################################
456
- # Get Agent-Specific Timeout
457
- ##############################################################################
458
- function get_agent_timeout() {
459
- local agent="$1"
460
- local task_id="$2"
461
-
462
- # Use get-agent-timeout.sh helper script
463
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
464
- AGENT_TIMEOUT=$("$SCRIPT_DIR/get-agent-timeout.sh" --task-id "$task_id" --agent-id "$agent" 2>/dev/null || echo "$TIMEOUT")
465
-
466
- echo "$AGENT_TIMEOUT"
467
- }
468
-
469
- ##############################################################################
470
- # BLPOP with Retry Logic
471
- ##############################################################################
472
- function blpop_with_retry() {
473
- local agent="$1"
474
- local done_key="$2"
475
- local timeout="$3"
476
- local retry_count="$4"
477
- local retry_delay="$5"
478
-
479
- for ATTEMPT in $(seq 1 $retry_count); do
480
- # Check for shutdown before attempting BLPOP
481
- if [ "$SHUTDOWN_REQUESTED" -eq 1 ]; then
482
- echo " [SHUTDOWN] Aborting BLPOP for $agent" >&2
483
- return 1
484
- fi
485
-
486
- # Use Redis's native BLPOP timeout instead of shell timeout command
487
- # This allows SIGTERM to properly interrupt the process
488
- RESULT=$(redis-cli blpop "$done_key" "$timeout" 2>/dev/null || echo "")
489
-
490
- if [ -n "$RESULT" ]; then
491
- echo "$RESULT"
492
- return 0 # Success
493
- fi
494
-
495
- # Check for shutdown after BLPOP timeout
496
- if [ "$SHUTDOWN_REQUESTED" -eq 1 ]; then
497
- echo " [SHUTDOWN] Aborting retry for $agent" >&2
498
- return 1
499
- fi
500
-
501
- # Log retry attempt (to stderr so it's visible during command substitution)
502
- local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
503
- echo " [$timestamp] ⚠️ BLPOP attempt $ATTEMPT/$retry_count failed for $agent" >&2
504
-
505
- if [ $ATTEMPT -lt $retry_count ]; then
506
- # METRICS: Increment retry counter
507
- redis-cli INCR "swarm:${TASK_ID}:metrics:retry_count" >/dev/null
508
-
509
- retry_with_backoff "$agent" "$ATTEMPT" "$retry_count" "$retry_delay" >&2
510
- else
511
- # Final failure - write to DLQ
512
- echo " [$timestamp] ❌ FINAL FAILURE: $agent after $retry_count attempts" >&2
513
- write_to_dlq "$agent" "timeout_after_retries" "$retry_count"
514
- return 1
515
- fi
516
- done
517
-
518
- return 1
519
- }
520
-
521
- echo "=== CFN Loop Orchestration ==="
522
- echo "Task ID: $TASK_ID"
523
- echo "Mode: $MODE (Gate: $GATE, Consensus: $CONSENSUS)"
524
- echo "Max Iterations: $MAX_ITERATIONS"
525
- echo ""
526
-
527
- # Initialize swarm using general Redis coordination primitive
528
- SWARM_ID="swarm-${TASK_ID}"
529
- ALL_AGENTS="${LOOP3_AGENTS},${LOOP2_AGENTS},${PRODUCT_OWNER}"
530
-
531
- # Build CFN-specific metadata
532
- CFN_METADATA=$(cat <<EOF
533
- {
534
- "mode": "$MODE",
535
- "loop3_agents": "$LOOP3_AGENTS",
536
- "loop2_agents": "$LOOP2_AGENTS",
537
- "product_owner": "$PRODUCT_OWNER",
538
- "workflow_type": "cfn_loop"
539
- }
540
- EOF
541
- )
542
-
543
- # Use general init-swarm primitive
544
- ./.claude/skills/redis-coordination/init-swarm.sh \
545
- --swarm-id "$SWARM_ID" \
546
- --agents "$ALL_AGENTS" \
547
- --task-id "$TASK_ID" \
548
- --topology "hierarchical" \
549
- --metadata "$CFN_METADATA" > /dev/null
550
-
551
- # Start shutdown monitor in background
552
- start_shutdown_monitor "$TASK_ID"
553
-
554
- echo ""
555
-
556
- # Iteration loop
557
- for ITERATION in $(seq 1 $MAX_ITERATIONS); do
558
- echo "=== Iteration $ITERATION/$MAX_ITERATIONS ==="
559
-
560
- # METRICS: Iteration start timestamp
561
- ITERATION_START=$(date +%s%N | cut -b1-13) # milliseconds
562
- redis-cli LPUSH "swarm:${TASK_ID}:metrics:iteration_start" "$ITERATION_START" >/dev/null
563
-
564
- # Step 1: Spawn Loop 3 agents via CLI
565
- echo "[Loop 3] Spawning implementers via CLI..."
566
- IFS=',' read -ra AGENTS <<< "$LOOP3_AGENTS"
567
-
568
- for AGENT in "${AGENTS[@]}"; do
569
- echo " Spawning: npx cfn-spawn agent $AGENT --task-id $TASK_ID --iteration $ITERATION"
570
-
571
- # Spawn agent in background via CLI (using cfn-spawn pattern)
572
- npx cfn-spawn agent "$AGENT" \
573
- --task-id "$TASK_ID" \
574
- --iteration "$ITERATION" \
575
- --context "Loop 3 implementation" \
576
- --mode "$MODE" &
577
-
578
- AGENT_PID=$!
579
- echo " ✅ Spawned $AGENT (PID: $AGENT_PID)"
580
- done
581
-
582
- echo ""
583
-
584
- # Step 2: Wait for Loop 3 agents to complete
585
- echo "[Loop 3] Waiting for implementers to complete..."
586
-
587
- LOOP3_TOTAL=${#AGENTS[@]}
588
- LOOP3_REQUIRED=$(calculate_quorum "$MIN_QUORUM_LOOP3" "$LOOP3_TOTAL")
589
- LOOP3_COMPLETED_AGENTS=()
590
- LOOP3_FAILED_AGENTS=()
591
-
592
- echo "[Loop 3] Quorum: $LOOP3_REQUIRED/$LOOP3_TOTAL agents required"
593
-
594
- # Start Loop 3 heartbeat monitor
595
- echo "[Loop 3] Starting heartbeat monitor (checking every 30s)..."
596
- LOOP3_HEARTBEAT_MONITOR_PID=$(start_heartbeat_monitor "$TASK_ID" "loop3" "${AGENTS[@]}")
597
-
598
- for AGENT in "${AGENTS[@]}"; do
599
- DONE_KEY="swarm:${TASK_ID}:${AGENT}:done"
600
-
601
- # Get agent-specific timeout
602
- AGENT_TIMEOUT=$(get_agent_timeout "$AGENT" "$TASK_ID")
603
- echo " Waiting for $AGENT (timeout: ${AGENT_TIMEOUT}s)..."
604
-
605
- # METRICS: Agent latency start
606
- AGENT_START=$(date +%s%N | cut -b1-13)
607
-
608
- # BLPOP with retry logic using agent-specific timeout
609
- if RESULT=$(blpop_with_retry "$AGENT" "$DONE_KEY" "$AGENT_TIMEOUT" "$RETRY_COUNT" "$RETRY_DELAY"); then
610
- # METRICS: Agent latency end
611
- AGENT_END=$(date +%s%N | cut -b1-13)
612
- LATENCY=$((AGENT_END - AGENT_START))
613
-
614
- # Store latency metric with agent label and loop context
615
- METRIC=$(jq -nc \
616
- --arg agent "$AGENT" \
617
- --arg latency "$LATENCY" \
618
- --arg loop "loop3" \
619
- --arg iteration "$ITERATION" \
620
- '{agent: $agent, latency_ms: ($latency | tonumber), loop: $loop, iteration: ($iteration | tonumber)}')
621
- echo "$METRIC" | redis-cli -x LPUSH "swarm:${TASK_ID}:metrics:agent_latency" >/dev/null
622
-
623
- echo " ✅ $AGENT complete (${LATENCY}ms)"
624
- LOOP3_COMPLETED_AGENTS+=("$AGENT")
625
- else
626
- echo " ❌ $AGENT failed after $RETRY_COUNT retry attempts"
627
- LOOP3_FAILED_AGENTS+=("$AGENT")
628
-
629
- # METRICS: Increment timeout counter
630
- redis-cli INCR "swarm:${TASK_ID}:metrics:timeout_count" >/dev/null
631
- fi
632
- done
633
-
634
- # Stop Loop 3 heartbeat monitor
635
- echo "[Loop 3] Stopping heartbeat monitor..."
636
- stop_heartbeat_monitor "$TASK_ID" "loop3" "$LOOP3_HEARTBEAT_MONITOR_PID"
637
- LOOP3_HEARTBEAT_MONITOR_PID=""
638
-
639
- # Validate quorum
640
- if [ ${#LOOP3_COMPLETED_AGENTS[@]} -ge "$LOOP3_REQUIRED" ]; then
641
- echo "[Loop 3] ✅ Quorum met: ${#LOOP3_COMPLETED_AGENTS[@]}/$LOOP3_REQUIRED agents completed"
642
- if [ ${#LOOP3_FAILED_AGENTS[@]} -gt 0 ]; then
643
- echo "[Loop 3] ⚠️ Failed agents (continuing with quorum): ${LOOP3_FAILED_AGENTS[*]}"
644
-
645
- # METRICS: Increment quorum fallback counter
646
- redis-cli INCR "swarm:${TASK_ID}:metrics:quorum_fallback" >/dev/null
647
- fi
648
- else
649
- echo "[Loop 3] ❌ Quorum FAILED: ${#LOOP3_COMPLETED_AGENTS[@]} < $LOOP3_REQUIRED"
650
- echo "[Loop 3] Failed agents: ${LOOP3_FAILED_AGENTS[*]}"
651
- exit 1
652
- fi
653
- echo ""
654
-
655
- # Step 2: Collect Loop 3 confidence scores (only from completed agents)
656
- echo "[Loop 3] Collecting confidence scores from ${#LOOP3_COMPLETED_AGENTS[@]} agents..."
657
- LOOP3_COMPLETED_IDS=$(IFS=','; echo "${LOOP3_COMPLETED_AGENTS[*]}")
658
- LOOP3_CONSENSUS=$(./.claude/skills/redis-coordination/invoke-waiting-mode.sh collect \
659
- --task-id "$TASK_ID" \
660
- --agent-ids "$LOOP3_COMPLETED_IDS" | tail -1)
661
-
662
- echo "[Loop 3] Average confidence: $LOOP3_CONSENSUS (from ${#LOOP3_COMPLETED_AGENTS[@]}/${LOOP3_TOTAL} agents)"
663
-
664
- # METRICS: Store Loop 3 consensus score
665
- LOOP3_METRIC=$(jq -nc \
666
- --arg consensus "$LOOP3_CONSENSUS" \
667
- --arg iteration "$ITERATION" \
668
- '{consensus: ($consensus | tonumber), iteration: ($iteration | tonumber)}')
669
- echo "$LOOP3_METRIC" | redis-cli -x LPUSH "swarm:${TASK_ID}:metrics:loop3_consensus" >/dev/null
670
-
671
- # Gate check
672
- if (( $(echo "$LOOP3_CONSENSUS < $GATE" | bc -l) )); then
673
- echo "❌ Gate FAILED ($LOOP3_CONSENSUS < $GATE)"
674
- echo "Decision: RELAUNCH iteration $((ITERATION + 1))"
675
-
676
- # METRICS: Increment gate failure counter
677
- redis-cli INCR "swarm:${TASK_ID}:metrics:gate_failures" >/dev/null
678
-
679
- # Wake Loop 3 agents for next iteration with MEDIUM priority (priority=30)
680
- IFS=',' read -ra AGENTS <<< "$LOOP3_AGENTS"
681
- for AGENT in "${AGENTS[@]}"; do
682
- ./.claude/skills/redis-coordination/invoke-waiting-mode.sh wake \
683
- --task-id "$TASK_ID" \
684
- --agent-id "$AGENT" \
685
- --priority 30 \
686
- --reason "gate_failed" \
687
- --iteration $((ITERATION + 1)) \
688
- --feedback "Improve confidence from $LOOP3_CONSENSUS to >$GATE"
689
- done
690
-
691
- continue # Next iteration
692
- fi
693
-
694
- echo "✅ Gate PASSED ($LOOP3_CONSENSUS >= $GATE)"
695
- echo ""
696
-
697
- # Signal Loop 2 validators that gate has passed (they can start work)
698
- GATE_PASS_KEY="swarm:${TASK_ID}:gate-passed"
699
- redis-cli lpush "$GATE_PASS_KEY" "{\"iteration\": $ITERATION, \"loop3_confidence\": $LOOP3_CONSENSUS}" > /dev/null
700
- echo "[Loop 3] Gate pass signal sent to Loop 2 validators"
701
- echo ""
702
-
703
- # Step 3: Spawn Loop 2 validators via CLI
704
- echo "[Loop 2] Spawning validators via CLI..."
705
- IFS=',' read -ra VALIDATORS <<< "$LOOP2_AGENTS"
706
-
707
- for VALIDATOR in "${VALIDATORS[@]}"; do
708
- echo " Spawning: npx cfn-spawn agent $VALIDATOR --task-id $TASK_ID --iteration $ITERATION"
709
-
710
- # Spawn validator in background via CLI (using cfn-spawn pattern)
711
- npx cfn-spawn agent "$VALIDATOR" \
712
- --task-id "$TASK_ID" \
713
- --iteration "$ITERATION" \
714
- --context "Loop 2 validation" \
715
- --mode "$MODE" &
716
-
717
- VALIDATOR_PID=$!
718
- echo " ✅ Spawned $VALIDATOR (PID: $VALIDATOR_PID)"
719
- done
720
-
721
- echo ""
722
-
723
- # Step 4: Wait for Loop 2 validators to complete
724
- echo "[Loop 2] Waiting for validators to complete..."
725
-
726
- LOOP2_TOTAL=${#VALIDATORS[@]}
727
- LOOP2_REQUIRED=$(calculate_quorum "$MIN_QUORUM_LOOP2" "$LOOP2_TOTAL")
728
- LOOP2_COMPLETED_AGENTS=()
729
- LOOP2_FAILED_AGENTS=()
730
-
731
- echo "[Loop 2] Quorum: $LOOP2_REQUIRED/$LOOP2_TOTAL agents required"
732
-
733
- # Start Loop 2 heartbeat monitor
734
- echo "[Loop 2] Starting heartbeat monitor (checking every 30s)..."
735
- LOOP2_HEARTBEAT_MONITOR_PID=$(start_heartbeat_monitor "$TASK_ID" "loop2" "${VALIDATORS[@]}")
736
-
737
- for VALIDATOR in "${VALIDATORS[@]}"; do
738
- DONE_KEY="swarm:${TASK_ID}:${VALIDATOR}:done"
739
-
740
- # Get agent-specific timeout
741
- AGENT_TIMEOUT=$(get_agent_timeout "$VALIDATOR" "$TASK_ID")
742
- echo " Waiting for $VALIDATOR (timeout: ${AGENT_TIMEOUT}s)..."
743
-
744
- # METRICS: Agent latency start
745
- AGENT_START=$(date +%s%N | cut -b1-13)
746
-
747
- # BLPOP with retry logic using agent-specific timeout
748
- if RESULT=$(blpop_with_retry "$VALIDATOR" "$DONE_KEY" "$AGENT_TIMEOUT" "$RETRY_COUNT" "$RETRY_DELAY"); then
749
- # METRICS: Agent latency end
750
- AGENT_END=$(date +%s%N | cut -b1-13)
751
- LATENCY=$((AGENT_END - AGENT_START))
752
-
753
- # Store latency metric with agent label and loop context
754
- METRIC=$(jq -nc \
755
- --arg agent "$VALIDATOR" \
756
- --arg latency "$LATENCY" \
757
- --arg loop "loop2" \
758
- --arg iteration "$ITERATION" \
759
- '{agent: $agent, latency_ms: ($latency | tonumber), loop: $loop, iteration: ($iteration | tonumber)}')
760
- echo "$METRIC" | redis-cli -x LPUSH "swarm:${TASK_ID}:metrics:agent_latency" >/dev/null
761
-
762
- echo " ✅ $VALIDATOR complete (${LATENCY}ms)"
763
- LOOP2_COMPLETED_AGENTS+=("$VALIDATOR")
764
- else
765
- echo " ❌ $VALIDATOR failed after $RETRY_COUNT retry attempts"
766
- LOOP2_FAILED_AGENTS+=("$VALIDATOR")
767
-
768
- # METRICS: Increment timeout counter
769
- redis-cli INCR "swarm:${TASK_ID}:metrics:timeout_count" >/dev/null
770
- fi
771
- done
772
-
773
- # Stop Loop 2 heartbeat monitor
774
- echo "[Loop 2] Stopping heartbeat monitor..."
775
- stop_heartbeat_monitor "$TASK_ID" "loop2" "$LOOP2_HEARTBEAT_MONITOR_PID"
776
- LOOP2_HEARTBEAT_MONITOR_PID=""
777
-
778
- # Validate quorum
779
- if [ ${#LOOP2_COMPLETED_AGENTS[@]} -ge "$LOOP2_REQUIRED" ]; then
780
- echo "[Loop 2] ✅ Quorum met: ${#LOOP2_COMPLETED_AGENTS[@]}/$LOOP2_REQUIRED agents completed"
781
- if [ ${#LOOP2_FAILED_AGENTS[@]} -gt 0 ]; then
782
- echo "[Loop 2] ⚠️ Failed agents (continuing with quorum): ${LOOP2_FAILED_AGENTS[*]}"
783
-
784
- # METRICS: Increment quorum fallback counter
785
- redis-cli INCR "swarm:${TASK_ID}:metrics:quorum_fallback" >/dev/null
786
- fi
787
- else
788
- echo "[Loop 2] ❌ Quorum FAILED: ${#LOOP2_COMPLETED_AGENTS[@]} < $LOOP2_REQUIRED"
789
- echo "[Loop 2] Failed agents: ${LOOP2_FAILED_AGENTS[*]}"
790
- exit 1
791
- fi
792
- echo ""
793
-
794
- # Step 4: Collect Loop 2 consensus scores and feedback (only from completed agents)
795
- echo "[Loop 2] Collecting consensus scores from ${#LOOP2_COMPLETED_AGENTS[@]} agents..."
796
- LOOP2_COMPLETED_IDS=$(IFS=','; echo "${LOOP2_COMPLETED_AGENTS[*]}")
797
-
798
- # Capture full output to extract both consensus and feedback
799
- COLLECT_OUTPUT=$(./.claude/skills/redis-coordination/invoke-waiting-mode.sh collect \
800
- --task-id "$TASK_ID" \
801
- --agent-ids "$LOOP2_COMPLETED_IDS")
802
-
803
- LOOP2_CONSENSUS=$(echo "$COLLECT_OUTPUT" | tail -1)
804
-
805
- # Extract aggregated feedback from collect output
806
- LOOP2_FEEDBACK=""
807
- if echo "$COLLECT_OUTPUT" | grep -q "Aggregated Feedback"; then
808
- LOOP2_FEEDBACK=$(echo "$COLLECT_OUTPUT" | sed -n '/Aggregated Feedback/,/Consensus:/p' | grep '^\s*-' | sed 's/^\s*-\s*//' | paste -sd ',' -)
809
- fi
810
-
811
- echo "[Loop 2] Average consensus: $LOOP2_CONSENSUS (from ${#LOOP2_COMPLETED_AGENTS[@]}/${LOOP2_TOTAL} agents)"
812
-
813
- # METRICS: Store Loop 2 consensus score
814
- LOOP2_METRIC=$(jq -nc \
815
- --arg consensus "$LOOP2_CONSENSUS" \
816
- --arg iteration "$ITERATION" \
817
- '{consensus: ($consensus | tonumber), iteration: ($iteration | tonumber)}')
818
- echo "$LOOP2_METRIC" | redis-cli -x LPUSH "swarm:${TASK_ID}:metrics:loop2_consensus" >/dev/null
819
-
820
- # SPRINT 3 - Phase 2: Store iteration results for all agents
821
- echo "[Coordinator] Storing iteration results for history..."
822
- IFS=',' read -ra ALL_AGENTS_ARRAY <<< "$LOOP3_AGENTS,$LOOP2_AGENTS"
823
- for AGENT in "${ALL_AGENTS_ARRAY[@]}"; do
824
- # Get agent's confidence score
825
- AGENT_CONFIDENCE=$(redis-cli get "swarm:${TASK_ID}:${AGENT}:confidence:iteration-${ITERATION}" || echo "0")
826
- if [ "$AGENT_CONFIDENCE" = "(nil)" ]; then
827
- AGENT_CONFIDENCE="0"
828
- fi
829
-
830
- # Get agent's result/output (try multiple possible keys)
831
- AGENT_RESULT=$(redis-cli get "swarm:${TASK_ID}:${AGENT}:output" || echo "")
832
- if [ "$AGENT_RESULT" = "(nil)" ] || [ -z "$AGENT_RESULT" ]; then
833
- AGENT_RESULT="Completed iteration $ITERATION"
834
- fi
835
-
836
- # Store result with metadata
837
- RESULT_DATA=$(jq -nc \
838
- --arg result "$AGENT_RESULT" \
839
- --arg confidence "$AGENT_CONFIDENCE" \
840
- --arg iteration "$ITERATION" \
841
- --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
842
- '{result: $result, confidence: ($confidence | tonumber), iteration: ($iteration | tonumber), timestamp: $timestamp}')
843
-
844
- echo "$RESULT_DATA" | redis-cli -x setex "swarm:${TASK_ID}:${AGENT}:result:iteration-${ITERATION}" 86400 >/dev/null
845
-
846
- # Store feedback if available (from Loop 2 validators)
847
- if [ -n "$LOOP2_FEEDBACK" ]; then
848
- FEEDBACK_DATA=$(jq -nc \
849
- --arg feedback "$LOOP2_FEEDBACK" \
850
- --arg iteration "$ITERATION" \
851
- --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
852
- '{feedback: $feedback, iteration: ($iteration | tonumber), timestamp: $timestamp}')
853
- echo "$FEEDBACK_DATA" | redis-cli -x setex "swarm:${TASK_ID}:${AGENT}:feedback:iteration-${ITERATION}" 86400 >/dev/null
854
- fi
855
- done
856
- echo "[Coordinator] Iteration results stored for ${#ALL_AGENTS_ARRAY[@]} agents"
857
-
858
- # Consensus check
859
- if (( $(echo "$LOOP2_CONSENSUS >= $CONSENSUS" | bc -l) )); then
860
- echo "✅ CONSENSUS REACHED ($LOOP2_CONSENSUS >= $CONSENSUS)"
861
- echo ""
862
-
863
- # Wake Product Owner with CRITICAL priority (priority=5)
864
- echo "[Coordinator] Waking Product Owner with CRITICAL priority..."
865
- ./.claude/skills/redis-coordination/invoke-waiting-mode.sh wake \
866
- --task-id "$TASK_ID" \
867
- --agent-id "$PRODUCT_OWNER" \
868
- --priority 5 \
869
- --reason "consensus_ready" \
870
- --iteration "$ITERATION" \
871
- --feedback "Loop 2 consensus: $LOOP2_CONSENSUS"
872
-
873
- # Wait for Product Owner decision
874
- echo "[Product Owner] Waiting for GOAP decision..."
875
- DECISION_KEY="swarm:${TASK_ID}:${PRODUCT_OWNER}:decision"
876
-
877
- # Get agent-specific timeout for Product Owner
878
- PO_TIMEOUT=$(get_agent_timeout "$PRODUCT_OWNER" "$TASK_ID")
879
- echo "[Product Owner] Using timeout: ${PO_TIMEOUT}s"
880
-
881
- # BLPOP with retry logic for decision using agent-specific timeout
882
- if ! DECISION_RESULT=$(blpop_with_retry "$PRODUCT_OWNER" "$DECISION_KEY" "$PO_TIMEOUT" "$RETRY_COUNT" "$RETRY_DELAY"); then
883
- echo "❌ ERROR: Product Owner failed after $RETRY_COUNT retry attempts"
884
- exit 1
885
- fi
886
-
887
- # Extract decision from BLPOP result (format: key value)
888
- DECISION=$(echo "$DECISION_RESULT" | tail -1)
889
-
890
- DECISION_TYPE=$(echo "$DECISION" | jq -r '.decision')
891
-
892
- echo "[Product Owner] Decision: $DECISION_TYPE"
893
-
894
- if [ "$DECISION_TYPE" = "PROCEED" ]; then
895
- echo ""
896
- echo "🎉 CFN Loop Complete!"
897
- echo "Final Consensus: $LOOP2_CONSENSUS (Iteration $ITERATION)"
898
-
899
- # METRICS: Iteration end timestamp and duration
900
- ITERATION_END=$(date +%s%N | cut -b1-13)
901
- ITERATION_DURATION=$((ITERATION_END - ITERATION_START))
902
-
903
- # Store final iteration duration metric
904
- DURATION_METRIC=$(jq -nc \
905
- --arg duration "$ITERATION_DURATION" \
906
- --arg iteration "$ITERATION" \
907
- '{duration_ms: ($duration | tonumber), iteration: ($iteration | tonumber)}')
908
- echo "$DURATION_METRIC" | redis-cli -x LPUSH "swarm:${TASK_ID}:metrics:iteration_duration" >/dev/null
909
-
910
- # Wake all agents with completion signal - CRITICAL priority (priority=5)
911
- echo "[Coordinator] Waking all agents with CRITICAL priority for completion..."
912
- IFS=',' read -ra ALL_AGENTS <<< "$LOOP3_AGENTS,$LOOP2_AGENTS"
913
- for AGENT in "${ALL_AGENTS[@]}"; do
914
- ./.claude/skills/redis-coordination/invoke-waiting-mode.sh wake \
915
- --task-id "$TASK_ID" \
916
- --agent-id "$AGENT" \
917
- --priority 5 \
918
- --reason "cfn_complete" \
919
- --iteration "$ITERATION"
920
- done
921
-
922
- # Use general complete-swarm primitive
923
- ./.claude/skills/redis-coordination/complete-swarm.sh \
924
- --swarm-id "$SWARM_ID" \
925
- --final-metric "final_consensus=$LOOP2_CONSENSUS" \
926
- --final-metric "total_iterations=$ITERATION" > /dev/null
927
-
928
- exit 0
929
- fi
930
-
931
- else
932
- echo "⚠️ CONSENSUS NOT REACHED ($LOOP2_CONSENSUS < $CONSENSUS)"
933
- echo "Decision: RELAUNCH iteration $((ITERATION + 1))"
934
- echo ""
935
- fi
936
-
937
- # METRICS: Iteration end timestamp and duration (for relaunch scenario)
938
- ITERATION_END=$(date +%s%N | cut -b1-13)
939
- ITERATION_DURATION=$((ITERATION_END - ITERATION_START))
940
-
941
- # Store iteration duration metric
942
- DURATION_METRIC=$(jq -nc \
943
- --arg duration "$ITERATION_DURATION" \
944
- --arg iteration "$ITERATION" \
945
- '{duration_ms: ($duration | tonumber), iteration: ($iteration | tonumber)}')
946
- echo "$DURATION_METRIC" | redis-cli -x LPUSH "swarm:${TASK_ID}:metrics:iteration_duration" >/dev/null
947
-
948
- # Relaunch next iteration
949
- if [ $ITERATION -eq $MAX_ITERATIONS ]; then
950
- echo "❌ Maximum iterations ($MAX_ITERATIONS) reached without consensus"
951
- exit 1
952
- fi
953
-
954
- # Wake agents for next iteration with role-based priorities and specific feedback
955
- echo "[Coordinator] Waking agents for iteration $((ITERATION + 1)) with priorities and feedback..."
956
-
957
- # Build feedback message for Loop 3 implementers
958
- LOOP3_FEEDBACK="Improve consensus from $LOOP2_CONSENSUS to >=$CONSENSUS"
959
- if [ -n "$LOOP2_FEEDBACK" ]; then
960
- # Include specific validator feedback
961
- LOOP3_FEEDBACK="$LOOP3_FEEDBACK,$LOOP2_FEEDBACK"
962
- echo "[Coordinator] Passing validator feedback to Loop 3: $(echo "$LOOP2_FEEDBACK" | tr ',' '\n' | wc -l) items"
963
- fi
964
-
965
- # Wake Loop 3 implementers with MEDIUM priority (priority=30)
966
- IFS=',' read -ra LOOP3_ARRAY <<< "$LOOP3_AGENTS"
967
- for AGENT in "${LOOP3_ARRAY[@]}"; do
968
- ./.claude/skills/redis-coordination/invoke-waiting-mode.sh wake \
969
- --task-id "$TASK_ID" \
970
- --agent-id "$AGENT" \
971
- --priority 30 \
972
- --reason "cfn_loop_iteration" \
973
- --iteration $((ITERATION + 1)) \
974
- --feedback "$LOOP3_FEEDBACK"
975
- done
976
-
977
- # Wake Loop 2 validators with HIGH priority (priority=10)
978
- IFS=',' read -ra LOOP2_ARRAY <<< "$LOOP2_AGENTS"
979
- for AGENT in "${LOOP2_ARRAY[@]}"; do
980
- ./.claude/skills/redis-coordination/invoke-waiting-mode.sh wake \
981
- --task-id "$TASK_ID" \
982
- --agent-id "$AGENT" \
983
- --priority 10 \
984
- --reason "cfn_loop_iteration" \
985
- --iteration $((ITERATION + 1)) \
986
- --feedback "Re-validate iteration $((ITERATION + 1)) work against threshold >=$CONSENSUS"
987
- done
988
-
989
- echo ""
990
- done
991
-
992
- echo "❌ CFN Loop failed after $MAX_ITERATIONS iterations"
993
- exit 1
1
+ #!/bin/bash
2
+
3
+ echo "=========================================="
4
+ echo "⚠️ DEPRECATED: orchestrate-cfn-loop.sh"
5
+ echo "=========================================="
6
+ echo ""
7
+ echo "This orchestrator has been replaced by the modular CFN v3 version."
8
+ echo ""
9
+ echo "New Location:"
10
+ echo " ./.claude/skills/cfn-loop-orchestration/orchestrate.sh"
11
+ echo ""
12
+ echo "Key Improvements in v3:"
13
+ echo " - 78% code reduction (70KB → 26KB)"
14
+ echo " - Modular helper scripts"
15
+ echo " - Stateless context injection"
16
+ echo " - Better agent ID tracking"
17
+ echo " - No BLPOP hangs"
18
+ echo ""
19
+ echo "Migration:"
20
+ echo " Replace: orchestrate-cfn-loop.sh"
21
+ echo " With: cfn-loop-orchestration/orchestrate.sh"
22
+ echo ""
23
+ echo "Same parameters supported (backward compatible)"
24
+ echo ""
25
+ echo "=========================================="
26
+ echo ""
27
+ echo "Forwarding to new orchestrator..."
28
+ echo ""
29
+
30
+ # Forward to new version
31
+ exec "$(dirname "$0")/../cfn-loop-orchestration/orchestrate.sh" "$@"