claude-flow-novice 2.9.1 → 2.10.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 (349) hide show
  1. package/.claude/agents/cfn-dev-team/CLAUDE.md +1086 -0
  2. package/.claude/agents/cfn-dev-team/README.md +116 -0
  3. package/.claude/agents/cfn-dev-team/architecture/api-designer-persona.md +149 -0
  4. package/.claude/agents/cfn-dev-team/architecture/base-template-generator.md +196 -0
  5. package/.claude/agents/cfn-dev-team/architecture/goal-planner.md +183 -0
  6. package/.claude/agents/cfn-dev-team/architecture/planner.md +182 -0
  7. package/.claude/agents/cfn-dev-team/architecture/system-architect.md +162 -0
  8. package/.claude/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +540 -0
  9. package/.claude/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +20 -14
  10. package/.claude/agents/cfn-dev-team/coordinators/consensus-builder.md +167 -0
  11. package/.claude/agents/cfn-dev-team/dev-ops/devops-engineer.md +148 -0
  12. package/.claude/agents/cfn-dev-team/dev-ops/github-commit-agent.md +118 -0
  13. package/.claude/agents/cfn-dev-team/dev-ops/kubernetes-specialist.md +540 -0
  14. package/.claude/agents/cfn-dev-team/developers/backend-dev.md +20 -0
  15. package/.claude/agents/cfn-dev-team/developers/data/data-engineer.md +585 -0
  16. package/.claude/agents/cfn-dev-team/developers/database/database-architect.md +276 -0
  17. package/.claude/agents/cfn-dev-team/developers/dev-backend-api.md +147 -0
  18. package/.claude/agents/cfn-dev-team/developers/frontend/mobile-dev.md +218 -0
  19. package/.claude/agents/cfn-dev-team/developers/{react-frontend-engineer.md → frontend/react-frontend-engineer.md} +53 -5
  20. package/.claude/agents/cfn-dev-team/developers/frontend/spec-mobile-react-native.md +199 -0
  21. package/.claude/agents/cfn-dev-team/developers/graphql-specialist.md +615 -0
  22. package/.claude/agents/cfn-dev-team/developers/rust-developer.md +174 -0
  23. package/.claude/agents/cfn-dev-team/documentation/README-VALIDATION.md +243 -0
  24. package/.claude/agents/cfn-dev-team/documentation/agent-type-guidelines.md +465 -0
  25. package/.claude/agents/cfn-dev-team/documentation/api-docs.md +103 -0
  26. package/.claude/agents/cfn-dev-team/documentation/docs-api-openapi.md +98 -0
  27. package/.claude/agents/cfn-dev-team/documentation/pseudocode.md +159 -0
  28. package/.claude/agents/cfn-dev-team/documentation/specification.md +157 -0
  29. package/.claude/agents/cfn-dev-team/product-owners/accessibility-advocate-persona.md +109 -0
  30. package/.claude/agents/cfn-dev-team/{coordinators → product-owners}/cto-agent.md +8 -6
  31. package/.claude/agents/cfn-dev-team/product-owners/power-user-persona.md +190 -0
  32. package/.claude/agents/cfn-dev-team/{coordinators → product-owners}/product-owner.md +85 -59
  33. package/.claude/agents/cfn-dev-team/reviewers/quality/analyze-code-quality.md +141 -0
  34. package/.claude/agents/cfn-dev-team/reviewers/quality/code-analyzer.md +200 -0
  35. package/.claude/agents/cfn-dev-team/reviewers/quality/cyclomatic-complexity-reducer.md +321 -0
  36. package/.claude/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +238 -0
  37. package/.claude/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +101 -0
  38. package/.claude/agents/cfn-dev-team/reviewers/quality/quality-metrics.md +375 -0
  39. package/.claude/agents/cfn-dev-team/reviewers/quality/security-specialist.md +193 -0
  40. package/.claude/agents/cfn-dev-team/reviewers/reviewer.md +39 -0
  41. package/.claude/agents/cfn-dev-team/testers/interaction-tester.md +31 -0
  42. package/.claude/agents/cfn-dev-team/testers/load-testing-specialist.md +469 -0
  43. package/.claude/agents/cfn-dev-team/testers/playwright-tester.md +24 -0
  44. package/.claude/agents/cfn-dev-team/testers/tester.md +20 -0
  45. package/.claude/agents/cfn-dev-team/utility/agent-builder.md +151 -0
  46. package/.claude/agents/cfn-dev-team/utility/analyst.md +178 -0
  47. package/.claude/agents/cfn-dev-team/utility/claude-code-expert.md +1043 -0
  48. package/.claude/agents/cfn-dev-team/utility/code-booster.md +139 -0
  49. package/.claude/agents/cfn-dev-team/utility/context-curator.md +99 -0
  50. package/.claude/agents/cfn-dev-team/{developers → utility}/researcher.md +6 -4
  51. package/.claude/commands/cfn/CFN_LOOP_FRONTEND.md +741 -0
  52. package/.claude/commands/cfn/CFN_LOOP_TASK_MODE.md +353 -0
  53. package/.claude/commands/cfn/cfn-loop-frontend.md +555 -0
  54. package/.claude/commands/cfn/cfn-loop.md +168 -7
  55. package/{CFN-CLAUDE.md → .claude/root-claude-distribute/CFN-CLAUDE.md} +23 -3
  56. package/.claude/skills/cfn-ace-system/SKILL.md +364 -0
  57. package/.claude/skills/cfn-ace-system/add-bullet.sh +145 -0
  58. package/.claude/skills/cfn-ace-system/analyze-anti-pattern-effectiveness.sh +56 -0
  59. package/.claude/skills/cfn-ace-system/classify-task.sh +18 -0
  60. package/.claude/skills/cfn-ace-system/export-ace-metrics.sh +48 -0
  61. package/.claude/skills/cfn-ace-system/extract-tags.sh +385 -0
  62. package/.claude/skills/cfn-ace-system/format-negative-context.sh +180 -0
  63. package/.claude/skills/cfn-ace-system/init-indexes.sql +160 -0
  64. package/.claude/skills/cfn-ace-system/invoke-context-curate.sh +192 -0
  65. package/.claude/skills/cfn-ace-system/invoke-context-inject.sh +361 -0
  66. package/.claude/skills/cfn-ace-system/invoke-context-query.sh +139 -0
  67. package/.claude/skills/cfn-ace-system/invoke-context-reflect.sh +343 -0
  68. package/.claude/skills/cfn-ace-system/invoke-context-stats.sh +227 -0
  69. package/.claude/skills/cfn-ace-system/log-merge.sh +67 -0
  70. package/.claude/skills/cfn-ace-system/monitor-injection-performance.sh +138 -0
  71. package/.claude/skills/cfn-ace-system/optimize-injection-pipeline.sh +169 -0
  72. package/.claude/skills/cfn-ace-system/query-anti-patterns.sh +276 -0
  73. package/.claude/skills/cfn-ace-system/query-contexts.sh +150 -0
  74. package/.claude/skills/cfn-ace-system/query-reflections.sh +35 -0
  75. package/.claude/skills/cfn-ace-system/schema/001-create-context-reflections.sql +237 -0
  76. package/.claude/skills/cfn-ace-system/schema/README.md +723 -0
  77. package/.claude/skills/cfn-ace-system/schema/SCHEMA_DESIGN_SUMMARY.md +564 -0
  78. package/.claude/skills/cfn-ace-system/schema/populate-test-data-simple.sh +62 -0
  79. package/.claude/skills/cfn-ace-system/schema/populate-test-data.sh +247 -0
  80. package/.claude/skills/cfn-ace-system/schema/run-migration.sh +231 -0
  81. package/.claude/skills/cfn-ace-system/schema/validate-schema.sql +280 -0
  82. package/.claude/skills/cfn-ace-system/score-relevance-adapter.sh +138 -0
  83. package/.claude/skills/cfn-ace-system/score-relevance.sh +253 -0
  84. package/.claude/skills/cfn-ace-system/sprint-7-lessons.json +46 -0
  85. package/.claude/skills/cfn-ace-system/store-reflection.sh +46 -0
  86. package/.claude/skills/cfn-ace-system/test-ace-skill.sh +312 -0
  87. package/.claude/skills/cfn-ace-system/track-ab-test.sh +42 -0
  88. package/.claude/skills/cfn-ace-system/update-reflection.sh +41 -0
  89. package/.claude/skills/cfn-agent-discovery/SKILL.md +40 -0
  90. package/.claude/skills/cfn-agent-discovery/agents-registry-clean.json +0 -0
  91. package/.claude/skills/cfn-agent-discovery/agents-registry-fixed.json +19 -0
  92. package/.claude/skills/cfn-agent-discovery/agents-registry.json +718 -0
  93. package/.claude/skills/cfn-agent-discovery/discover-agents.py +184 -0
  94. package/.claude/skills/cfn-agent-discovery/discover-agents.sh +87 -0
  95. package/.claude/skills/cfn-agent-discovery/invoke-registry.sh +11 -0
  96. package/.claude/skills/cfn-agent-discovery/temp_script.py +0 -0
  97. package/.claude/skills/cfn-agent-execution/execute-agent.sh +126 -0
  98. package/.claude/skills/cfn-agent-output-processing/SKILL.md +359 -0
  99. package/.claude/skills/cfn-agent-selector/SKILL.md +90 -0
  100. package/.claude/skills/cfn-agent-selector/select-agents.sh +112 -0
  101. package/.claude/skills/cfn-agent-spawning/SKILL.md +135 -0
  102. package/.claude/skills/cfn-agent-spawning/agent-selection-guide.md +814 -0
  103. package/.claude/skills/cfn-agent-spawning/check-dependencies.sh +30 -0
  104. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +263 -0
  105. package/.claude/skills/cfn-agent-spawning/spawn-templates.sh +613 -0
  106. package/.claude/skills/cfn-analytics/description-refinement-guide.md +164 -0
  107. package/.claude/skills/cfn-analytics/log-skill-invocation.js +122 -0
  108. package/.claude/skills/cfn-analytics/run-production-criteria-tests.sh +126 -0
  109. package/.claude/skills/cfn-analytics/skill-analytics-dashboard.js +113 -0
  110. package/.claude/skills/cfn-analytics/skill-invocation-hook.sh +28 -0
  111. package/.claude/skills/cfn-analytics/skill-invocations.sql +58 -0
  112. package/.claude/skills/cfn-analytics/test-corpus.json +32 -0
  113. package/.claude/skills/cfn-analytics/test-data-generator.js +115 -0
  114. package/.claude/skills/cfn-analytics/test-manual-override-rate.js +285 -0
  115. package/.claude/skills/cfn-analytics/validate-skill-selection.js +188 -0
  116. package/.claude/skills/cfn-config-management/SKILL.md +34 -0
  117. package/.claude/skills/cfn-config-management/check-dependencies.sh +56 -0
  118. package/.claude/skills/cfn-config-management/config.json +32 -0
  119. package/.claude/skills/cfn-config-management/manage-config.sh +113 -0
  120. package/.claude/skills/cfn-event-bus/SKILL.md +412 -0
  121. package/.claude/skills/cfn-event-bus/config.json +111 -0
  122. package/.claude/skills/cfn-event-bus/eventbus-wrapper.cjs +69 -0
  123. package/.claude/skills/cfn-event-bus/invoke-event-publish.sh +147 -0
  124. package/.claude/skills/cfn-event-bus/invoke-event-subscribe.sh +171 -0
  125. package/.claude/skills/cfn-event-bus/invoke-lifecycle-track.sh +201 -0
  126. package/.claude/skills/cfn-event-bus/test-event-bus.sh +280 -0
  127. package/.claude/skills/cfn-fleet-manager/SKILL.md +412 -0
  128. package/.claude/skills/cfn-fleet-manager/config.json +60 -0
  129. package/.claude/skills/cfn-fleet-manager/invoke-fleet-allocate.sh +182 -0
  130. package/.claude/skills/cfn-fleet-manager/invoke-fleet-balance.sh +239 -0
  131. package/.claude/skills/cfn-fleet-manager/invoke-fleet-metrics.sh +193 -0
  132. package/.claude/skills/cfn-fleet-manager/invoke-fleet-register.sh +124 -0
  133. package/.claude/skills/cfn-fleet-manager/test-fleet-manager.sh +345 -0
  134. package/.claude/skills/cfn-hook-pipeline/SKILL.md +148 -0
  135. package/.claude/skills/cfn-hook-pipeline/auto-resolve.sh +66 -0
  136. package/.claude/skills/cfn-hook-pipeline/check-dependencies.sh +40 -0
  137. package/.claude/skills/cfn-hook-pipeline/feedback-resolver.sh +452 -0
  138. package/.claude/skills/cfn-hook-pipeline/post-edit-handler.sh +154 -0
  139. package/.claude/skills/cfn-hook-pipeline/security-scan.json +60 -0
  140. package/.claude/skills/cfn-hook-pipeline/security-scanner.sh +121 -0
  141. package/.claude/skills/cfn-hook-pipeline/test-root-warning-resolution.sh +148 -0
  142. package/.claude/skills/cfn-hybrid-routing/SKILL.md +46 -0
  143. package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +52 -0
  144. package/.claude/skills/cfn-hybrid-routing/config.json +26 -0
  145. package/.claude/skills/cfn-hybrid-routing/spawn-worker.sh +44 -0
  146. package/.claude/skills/cfn-loop-orchestration/SKILL.md +299 -0
  147. package/.claude/skills/cfn-loop-orchestration/helpers/auto-tune-timeouts.sh +228 -0
  148. package/.claude/skills/cfn-loop-orchestration/helpers/consensus.sh +84 -0
  149. package/.claude/skills/cfn-loop-orchestration/helpers/context-injection.sh +142 -0
  150. package/.claude/skills/cfn-loop-orchestration/helpers/context-lookup.sh +359 -0
  151. package/.claude/skills/cfn-loop-orchestration/helpers/deliverable-verifier.sh +71 -0
  152. package/.claude/skills/cfn-loop-orchestration/helpers/gate-check.sh +90 -0
  153. package/.claude/skills/cfn-loop-orchestration/helpers/iteration-manager.sh +87 -0
  154. package/.claude/skills/cfn-loop-orchestration/helpers/spawn-agents.sh +271 -0
  155. package/.claude/skills/cfn-loop-orchestration/helpers/timeout-calculator.sh +51 -0
  156. package/.claude/skills/cfn-loop-orchestration/inject-loop-context.sh +41 -0
  157. package/.claude/skills/cfn-loop-orchestration/monitor-execution.sh +156 -0
  158. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +884 -0
  159. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +840 -0
  160. package/.claude/skills/cfn-loop-orchestration/security_utils.sh +99 -0
  161. package/.claude/skills/cfn-loop-orchestration/test-cfn-orchestration.sh +281 -0
  162. package/.claude/skills/cfn-loop-orchestration/test-edge-cases.sh +188 -0
  163. package/.claude/skills/cfn-loop-validation/SKILL.md +353 -0
  164. package/.claude/skills/cfn-loop-validation/check-dependencies.sh +31 -0
  165. package/.claude/skills/cfn-loop-validation/config.json +161 -0
  166. package/.claude/skills/cfn-loop-validation/consensus-calculator.js +477 -0
  167. package/.claude/skills/cfn-loop-validation/evidence-chain.sql +163 -0
  168. package/.claude/skills/cfn-loop-validation/examples/README.md +453 -0
  169. package/.claude/skills/cfn-loop-validation/examples/coordinator-full-cfn-loop.sh +234 -0
  170. package/.claude/skills/cfn-loop-validation/examples/coordinator-loop2-consensus.sh +132 -0
  171. package/.claude/skills/cfn-loop-validation/examples/coordinator-loop3-gate.sh +115 -0
  172. package/.claude/skills/cfn-loop-validation/examples/coordinator-redis-integration.sh +186 -0
  173. package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -0
  174. package/.claude/skills/cfn-loop-validation/validate-iteration.sh +134 -0
  175. package/.claude/skills/cfn-process-lifecycle/SKILL.md +39 -0
  176. package/.claude/skills/cfn-process-lifecycle/check-dependencies.sh +58 -0
  177. package/.claude/skills/cfn-process-lifecycle/config.json +39 -0
  178. package/.claude/skills/cfn-process-lifecycle/process-manager.sh +144 -0
  179. package/.claude/skills/cfn-product-owner-decision/SKILL.md +332 -0
  180. package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +176 -0
  181. package/.claude/skills/cfn-product-owner-decision/parse-decision.sh +66 -0
  182. package/.claude/skills/cfn-product-owner-decision/validate-deliverables.sh +82 -0
  183. package/.claude/skills/cfn-redis-coordination/AGENT_LOGGING.md +280 -0
  184. package/.claude/skills/cfn-redis-coordination/BZPOPMIN_FIX_SUMMARY.md +209 -0
  185. package/.claude/skills/cfn-redis-coordination/HEARTBEAT.md +57 -0
  186. package/.claude/skills/cfn-redis-coordination/HEARTBEAT_MONITORING.md +267 -0
  187. package/.claude/skills/cfn-redis-coordination/LOGGING.md +260 -0
  188. package/.claude/skills/cfn-redis-coordination/SECURITY_REVIEW.md +25 -0
  189. package/.claude/skills/cfn-redis-coordination/SHUTDOWN_HANDLING.md +164 -0
  190. package/.claude/skills/cfn-redis-coordination/SKILL.md +720 -0
  191. package/.claude/skills/cfn-redis-coordination/agent-log.sh +124 -0
  192. package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +75 -0
  193. package/.claude/skills/cfn-redis-coordination/analyze-task-complexity.sh +277 -0
  194. package/.claude/skills/cfn-redis-coordination/cancel-swarm.sh +221 -0
  195. package/.claude/skills/cfn-redis-coordination/cfn-loop-exec.sh +468 -0
  196. package/.claude/skills/cfn-redis-coordination/cfn-loop-relaunch.sh +29 -0
  197. package/.claude/skills/cfn-redis-coordination/check-dependencies.sh +32 -0
  198. package/.claude/skills/cfn-redis-coordination/collect-confidence-scores.sh +179 -0
  199. package/.claude/skills/cfn-redis-coordination/collect-results.sh +75 -0
  200. package/.claude/skills/cfn-redis-coordination/complete-swarm.sh +75 -0
  201. package/.claude/skills/cfn-redis-coordination/config.json +61 -0
  202. package/.claude/skills/cfn-redis-coordination/data/cfn-loop.db +0 -0
  203. package/.claude/skills/cfn-redis-coordination/demos/phase4-wake-queue-test-report.md +82 -0
  204. package/.claude/skills/cfn-redis-coordination/demos/test-bzpopmin-fix.sh +274 -0
  205. package/.claude/skills/cfn-redis-coordination/demos/test-cancel-swarm.sh +276 -0
  206. package/.claude/skills/cfn-redis-coordination/demos/test-dlq.sh +129 -0
  207. package/.claude/skills/cfn-redis-coordination/demos/test-iteration-feedback.sh +320 -0
  208. package/.claude/skills/cfn-redis-coordination/demos/test-orchestrator.sh +249 -0
  209. package/.claude/skills/cfn-redis-coordination/demos/test-priority-wake-phase4-unix.sh +148 -0
  210. package/.claude/skills/cfn-redis-coordination/demos/test-priority-wake-phase4.sh +163 -0
  211. package/.claude/skills/cfn-redis-coordination/demos/test-priority-wake.sh +138 -0
  212. package/.claude/skills/cfn-redis-coordination/demos/test-quick-fix.sh +81 -0
  213. package/.claude/skills/cfn-redis-coordination/demos/test-quorum-absolute.sh +45 -0
  214. package/.claude/skills/cfn-redis-coordination/demos/test-quorum-fallback.sh +68 -0
  215. package/.claude/skills/cfn-redis-coordination/demos/test-quorum-percentage.sh +56 -0
  216. package/.claude/skills/cfn-redis-coordination/demos/test-quorum-with-retry.sh +81 -0
  217. package/.claude/skills/cfn-redis-coordination/demos/test-quorum.sh +57 -0
  218. package/.claude/skills/cfn-redis-coordination/demos/test-shutdown-handling.sh +187 -0
  219. package/.claude/skills/cfn-redis-coordination/demos/test-shutdown.sh +160 -0
  220. package/.claude/skills/cfn-redis-coordination/demos/test-utils-unix.sh +97 -0
  221. package/.claude/skills/cfn-redis-coordination/demos/test-utils.sh +97 -0
  222. package/.claude/skills/cfn-redis-coordination/demos/test-waiting-mode.sh +59 -0
  223. package/.claude/skills/cfn-redis-coordination/examples/README.md +73 -0
  224. package/.claude/skills/cfn-redis-coordination/examples/grafana-dashboard.json +352 -0
  225. package/.claude/skills/cfn-redis-coordination/examples/hierarchical-pattern.sh +127 -0
  226. package/.claude/skills/cfn-redis-coordination/examples/mesh-pattern.sh +171 -0
  227. package/.claude/skills/cfn-redis-coordination/examples/timeout-handling.sh +227 -0
  228. package/.claude/skills/cfn-redis-coordination/examples/waiting-mode-pattern.sh +239 -0
  229. package/.claude/skills/cfn-redis-coordination/execute-product-owner-decision.sh +258 -0
  230. package/.claude/skills/cfn-redis-coordination/get-agent-timeout.sh +177 -0
  231. package/.claude/skills/cfn-redis-coordination/heartbeat-functions.sh +137 -0
  232. package/.claude/skills/cfn-redis-coordination/heartbeat-protocol.md +106 -0
  233. package/.claude/skills/cfn-redis-coordination/heartbeat.sh +126 -0
  234. package/.claude/skills/cfn-redis-coordination/init-swarm.sh +148 -0
  235. package/.claude/skills/cfn-redis-coordination/invoke-redis-pattern.sh +220 -0
  236. package/.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh +283 -0
  237. package/.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh.backup-p7 +423 -0
  238. package/.claude/skills/cfn-redis-coordination/list-active-swarms.sh +147 -0
  239. package/.claude/skills/cfn-redis-coordination/log-event.sh +109 -0
  240. package/.claude/skills/cfn-redis-coordination/metrics-export.sh +674 -0
  241. package/.claude/skills/cfn-redis-coordination/metrics-schema.json +66 -0
  242. package/.claude/skills/cfn-redis-coordination/metrics-storage.md +31 -0
  243. package/.claude/skills/cfn-redis-coordination/monitor-cfn-violations.sh +391 -0
  244. package/.claude/skills/cfn-redis-coordination/monitor-heartbeats.sh +101 -0
  245. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop-v3.sh +141 -0
  246. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh +31 -0
  247. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.backup +38 -0
  248. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.backup-1761167675 +1672 -0
  249. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.backup-p5 +1604 -0
  250. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.backup-phase1 +1550 -0
  251. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.backup-phase2 +1621 -0
  252. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.backup-phase3 +1621 -0
  253. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.bak +0 -0
  254. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.broken +1627 -0
  255. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.corrupted +80 -0
  256. package/.claude/skills/cfn-redis-coordination/orchestrate-cfn-loop.sh.deprecated +1864 -0
  257. package/.claude/skills/cfn-redis-coordination/priority-wake-mechanism.md +75 -0
  258. package/.claude/skills/cfn-redis-coordination/priority_wake.py +134 -0
  259. package/.claude/skills/cfn-redis-coordination/query-dlq.sh +162 -0
  260. package/.claude/skills/cfn-redis-coordination/query-logs.sh +103 -0
  261. package/.claude/skills/cfn-redis-coordination/redis-pattern.sh +619 -0
  262. package/.claude/skills/cfn-redis-coordination/retrieve-context.sh +58 -0
  263. package/.claude/skills/cfn-redis-coordination/select-specialist-agent.sh +371 -0
  264. package/.claude/skills/cfn-redis-coordination/semantic-match-tfidf.py +252 -0
  265. package/.claude/skills/cfn-redis-coordination/send-heartbeat.sh +165 -0
  266. package/.claude/skills/cfn-redis-coordination/signal.sh +38 -0
  267. package/.claude/skills/cfn-redis-coordination/store-context.sh +86 -0
  268. package/.claude/skills/cfn-redis-coordination/store-epic-context.sh +123 -0
  269. package/.claude/skills/cfn-redis-coordination/test-context-injection.sh +354 -0
  270. package/.claude/skills/cfn-redis-coordination/test-timeout-enforcement.sh +513 -0
  271. package/.claude/skills/cfn-redis-coordination/tests/convert-line-endings.sh +15 -0
  272. package/.claude/skills/cfn-redis-coordination/tests/dlq-functionality-test.sh +102 -0
  273. package/.claude/skills/cfn-redis-coordination/tests/edge-cases-test.sh +99 -0
  274. package/.claude/skills/cfn-redis-coordination/tests/integration-test.sh +170 -0
  275. package/.claude/skills/cfn-redis-coordination/tests/retry-mechanism-test.sh +82 -0
  276. package/.claude/skills/cfn-redis-coordination/tests/run-test-suite.sh +92 -0
  277. package/.claude/skills/cfn-redis-coordination/tests/run-tests.sh +4 -0
  278. package/.claude/skills/cfn-redis-coordination/tests/test-heartbeat-monitoring.sh +418 -0
  279. package/.claude/skills/cfn-redis-coordination/tests/test-heartbeat-simple.sh +124 -0
  280. package/.claude/skills/cfn-redis-coordination/tests/test-primitives.sh +166 -0
  281. package/.claude/skills/cfn-redis-coordination/tests/test-utils.sh +54 -0
  282. package/.claude/skills/cfn-redis-coordination/tests/test_coordination_primitives.sh.deprecated +20 -0
  283. package/.claude/skills/cfn-redis-coordination/tests/test_utils.sh +49 -0
  284. package/.claude/skills/cfn-redis-coordination/v2_modularization/core_orchestration.sh +76 -0
  285. package/.claude/skills/cfn-redis-coordination/validate-parameters.sh +492 -0
  286. package/.claude/skills/cfn-sqlite-memory/IMPLEMENTATION_REPORT.md +393 -0
  287. package/.claude/skills/cfn-sqlite-memory/QUICK_REFERENCE.md +204 -0
  288. package/.claude/skills/cfn-sqlite-memory/SKILL.md +415 -0
  289. package/.claude/skills/cfn-sqlite-memory/acl-queries.sql +452 -0
  290. package/.claude/skills/cfn-sqlite-memory/check-dependencies.sh +36 -0
  291. package/.claude/skills/cfn-sqlite-memory/config.json +45 -0
  292. package/.claude/skills/cfn-sqlite-memory/memory-cli.sh +88 -0
  293. package/.claude/skills/cfn-sqlite-memory/test-state-persistence.js +187 -0
  294. package/.claude/skills/cfn-sqlite-memory/ttl-cleanup.sh +274 -0
  295. package/.claude/skills/cfn-test-execution/SKILL.md +128 -0
  296. package/.claude/skills/cfn-test-execution/check-dependencies.sh +36 -0
  297. package/.claude/skills/cfn-test-execution/test-cache-reader.sh +134 -0
  298. package/.claude/skills/cfn-test-execution/test-concurrent-conflicts.sh +115 -0
  299. package/.claude/skills/cfn-test-execution/test-coordinator-pattern.sh +109 -0
  300. package/.claude/skills/cfn-transparency-middleware/Cargo.toml +18 -0
  301. package/.claude/skills/cfn-transparency-middleware/SECURITY.md +41 -0
  302. package/.claude/skills/cfn-transparency-middleware/SKILL.md +91 -0
  303. package/.claude/skills/cfn-transparency-middleware/TEST_RESULTS.md +174 -0
  304. package/.claude/skills/cfn-transparency-middleware/config.json +31 -0
  305. package/.claude/skills/cfn-transparency-middleware/examples/basic-usage.ts +39 -0
  306. package/.claude/skills/cfn-transparency-middleware/examples/batch-processing.ts +52 -0
  307. package/.claude/skills/cfn-transparency-middleware/examples/custom-filtering.ts +61 -0
  308. package/.claude/skills/cfn-transparency-middleware/invoke-transparency-filter.sh +98 -0
  309. package/.claude/skills/cfn-transparency-middleware/invoke-transparency-init.sh +224 -0
  310. package/.claude/skills/cfn-transparency-middleware/invoke-transparency-level.sh +333 -0
  311. package/.claude/skills/cfn-transparency-middleware/invoke-transparency-metrics.sh +345 -0
  312. package/.claude/skills/cfn-transparency-middleware/invoke-transparency-observe.sh +140 -0
  313. package/.claude/skills/cfn-transparency-middleware/invoke-transparency-stop.sh +235 -0
  314. package/.claude/skills/cfn-transparency-middleware/memory_query.rs +85 -0
  315. package/.claude/skills/cfn-transparency-middleware/memory_repository.rs +140 -0
  316. package/.claude/skills/cfn-transparency-middleware/memory_schema.rs +64 -0
  317. package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +29 -0
  318. package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +79 -0
  319. package/.claude/skills/cfn-transparency-middleware/test-e2e.sh +406 -0
  320. package/.claude/skills/cfn-transparency-middleware/test-integration.sh +162 -0
  321. package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +368 -0
  322. package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh.unix +126 -0
  323. package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +93 -0
  324. package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +132 -0
  325. package/.claude/skills/cfn-webapp-testing/SCREENSHOT_NAMING_CONVENTION.md +547 -0
  326. package/.claude/skills/cfn-webapp-testing/SKILL.md +877 -0
  327. package/.claude/skills/cfn-webapp-testing/capture-screenshot.sh +238 -0
  328. package/.claude/skills/cfn-webapp-testing/cfn-loop-integration.sh +265 -0
  329. package/.claude/skills/cfn-webapp-testing/compare-screenshots.sh +199 -0
  330. package/.claude/skills/cfn-webapp-testing/init-storage.sh +150 -0
  331. package/.claude/skills/cfn-webapp-testing/set-baseline.sh +196 -0
  332. package/.claude/skills/cfn-webapp-testing/test-webapp-testing.sh +233 -0
  333. package/README.md +51 -2
  334. package/dist/ace/ace-reflector.js +109 -10
  335. package/dist/ace/ace-reflector.js.map +1 -1
  336. package/dist/cli/agent-executor.js +1 -1
  337. package/dist/cli/agent-executor.js.map +1 -1
  338. package/package.json +43 -7
  339. package/readme/README.md +15 -4
  340. package/scripts/init-project.js +76 -6
  341. package/scripts/run-marketing-tests.sh +43 -0
  342. package/scripts/update_paths.sh +47 -0
  343. package/tools/install-lizard.sh +37 -0
  344. package/tools/simple-complexity.sh +44 -0
  345. package/.claude/agents/cfn-dev-team/developers/coder.md +0 -270
  346. package/.claude/agents/cfn-dev-team/developers/state-architect.md +0 -127
  347. package/.claude/agents/cfn-dev-team/reviewers/code-quality-validator.md +0 -128
  348. /package/.claude/agents/cfn-dev-team/developers/{ui-designer.md → frontend/ui-designer.md} +0 -0
  349. /package/.claude/agents/cfn-dev-team/{coordinators → product-owners}/product-owner-agent.md +0 -0
@@ -0,0 +1,884 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ # CFN Loop Orchestration - Main Coordinator
5
+ # Version: 1.1.0 (Security Enhanced)
6
+ #
7
+ # Orchestrates the Complete Fail Never (CFN) Loop workflow using modular
8
+ # helper scripts, Redis Coordination primitives, and enhanced security.
9
+ #
10
+ # Usage:
11
+ # ./orchestrate.sh --task-id <id> \
12
+ # --mode <mvp|standard|enterprise> \
13
+ # --loop3-agents <agent1,agent2,...> \
14
+ # --loop2-agents <agent1,agent2,...> \
15
+ # --product-owner <agent-id> \
16
+ # [--max-iterations <n>] \
17
+ # [--epic-context <json>] \
18
+ # [--phase-context <json>] \
19
+ # [--success-criteria <json>]
20
+ ##############################################################################
21
+
22
+ set -euo pipefail
23
+
24
+ # Load security utilities
25
+ # shellcheck source=./security_utils.sh
26
+ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/security_utils.sh"
27
+
28
+ # Determine script directory
29
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
30
+ HELPERS_DIR="$SCRIPT_DIR/helpers"
31
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" && REDIS_COORD_SKILL="$PROJECT_ROOT/.claude/skills/cfn-redis-coordination"
32
+
33
+ # Configuration
34
+ TASK_ID=""
35
+ MODE="standard"
36
+ LOOP3_AGENTS=""
37
+ LOOP2_AGENTS=""
38
+ PRODUCT_OWNER=""
39
+ MAX_ITERATIONS=10
40
+ MIN_QUORUM_LOOP3="0.66"
41
+ MIN_QUORUM_LOOP2="0.66"
42
+ EPIC_CONTEXT=""
43
+ PHASE_CONTEXT=""
44
+ SUCCESS_CRITERIA=""
45
+ EXPECTED_FILES=""
46
+ PHASE_ID=""
47
+
48
+ # Mode-specific thresholds
49
+ declare -A GATE_THRESHOLD=(
50
+ [mvp]=0.70
51
+ [standard]=0.75
52
+ [enterprise]=0.75
53
+ )
54
+
55
+ declare -A CONSENSUS_THRESHOLD=(
56
+ [mvp]=0.80
57
+ [standard]=0.90
58
+ [enterprise]=0.95
59
+ )
60
+
61
+ # Execution tracking
62
+ START_TIME=$(date +%s)
63
+ ITERATIONS_COMPLETED=0
64
+ FINAL_DECISION=""
65
+ LOOP3_FINAL_CONFIDENCE=0.0
66
+ LOOP2_FINAL_CONSENSUS=0.0
67
+ DELIVERABLES_VERIFIED=false
68
+
69
+ ##############################################################################
70
+ # Argument Parsing
71
+ ##############################################################################
72
+ while [[ $# -gt 0 ]]; do
73
+ case $1 in
74
+ --task-id)
75
+ if [[ $# -lt 2 ]]; then
76
+ echo "Error: --task-id requires a value"
77
+ exit 1
78
+ fi
79
+ TASK_ID=$(sanitize_input "$2") || { echo "Invalid task ID"; exit 1; }
80
+ shift 2
81
+ ;;
82
+ --mode)
83
+ if [[ $# -lt 2 ]]; then
84
+ echo "Error: --mode requires a value"
85
+ exit 1
86
+ fi
87
+ MODE="$2"
88
+ # Whitelist allowed modes
89
+ if [[ ! "$MODE" =~ ^(mvp|standard|enterprise)$ ]]; then
90
+ echo "Invalid mode. Must be mvp, standard, or enterprise."
91
+ exit 1
92
+ fi
93
+ shift 2
94
+ ;;
95
+ --loop3-agents)
96
+ if [[ $# -lt 2 ]]; then
97
+ echo "Error: --loop3-agents requires a value"
98
+ exit 1
99
+ fi
100
+ validate_agent_list "$2" || { echo "Invalid Loop 3 agent list"; exit 1; }
101
+ LOOP3_AGENTS="$2"
102
+ shift 2
103
+ ;;
104
+ --loop2-agents)
105
+ if [[ $# -lt 2 ]]; then
106
+ echo "Error: --loop2-agents requires a value"
107
+ exit 1
108
+ fi
109
+ validate_agent_list "$2" || { echo "Invalid Loop 2 agent list"; exit 1; }
110
+ LOOP2_AGENTS="$2"
111
+ shift 2
112
+ ;;
113
+ --product-owner)
114
+ if [[ $# -lt 2 ]]; then
115
+ echo "Error: --product-owner requires a value"
116
+ exit 1
117
+ fi
118
+ PRODUCT_OWNER=$(sanitize_input "$2") || { echo "Invalid product owner"; exit 1; }
119
+ shift 2
120
+ ;;
121
+ --max-iterations)
122
+ if [[ $# -lt 2 ]]; then
123
+ echo "Error: --max-iterations requires a value"
124
+ exit 1
125
+ fi
126
+ # Validate max iterations is a positive integer
127
+ if [[ ! "$2" =~ ^[1-9][0-9]*$ ]]; then
128
+ echo "Max iterations must be a positive integer"
129
+ exit 1
130
+ fi
131
+ MAX_ITERATIONS="$2"
132
+ shift 2
133
+ ;;
134
+ --min-quorum-loop3)
135
+ if [[ $# -lt 2 ]]; then
136
+ echo "Error: --min-quorum-loop3 requires a value"
137
+ exit 1
138
+ fi
139
+ # Validate quorum is a valid decimal between 0 and 1
140
+ if [[ ! "$2" =~ ^0\.[0-9]+$ ]] || (( $(echo "$2 > 1" | bc -l) )); then
141
+ echo "Invalid Loop 3 quorum. Must be between 0 and 1."
142
+ exit 1
143
+ fi
144
+ MIN_QUORUM_LOOP3="$2"
145
+ shift 2
146
+ ;;
147
+ --min-quorum-loop2)
148
+ if [[ $# -lt 2 ]]; then
149
+ echo "Error: --min-quorum-loop2 requires a value"
150
+ exit 1
151
+ fi
152
+ # Validate quorum is a valid decimal between 0 and 1
153
+ if [[ ! "$2" =~ ^0\.[0-9]+$ ]] || (( $(echo "$2 > 1" | bc -l) )); then
154
+ echo "Invalid Loop 2 quorum. Must be between 0 and 1."
155
+ exit 1
156
+ fi
157
+ MIN_QUORUM_LOOP2="$2"
158
+ shift 2
159
+ ;;
160
+ --epic-context)
161
+ if [[ $# -lt 2 ]]; then
162
+ echo "Error: --epic-context requires a value"
163
+ exit 1
164
+ fi
165
+ validate_json_context "$2" || { echo "Invalid epic context JSON"; exit 1; }
166
+ EPIC_CONTEXT="$2"
167
+ shift 2
168
+ ;;
169
+ --phase-context)
170
+ if [[ $# -lt 2 ]]; then
171
+ echo "Error: --phase-context requires a value"
172
+ exit 1
173
+ fi
174
+ validate_json_context "$2" || { echo "Invalid phase context JSON"; exit 1; }
175
+ PHASE_CONTEXT="$2"
176
+ shift 2
177
+ ;;
178
+ --success-criteria)
179
+ if [[ $# -lt 2 ]]; then
180
+ echo "Error: --success-criteria requires a value"
181
+ exit 1
182
+ fi
183
+ validate_json_context "$2" || { echo "Invalid success criteria JSON"; exit 1; }
184
+ SUCCESS_CRITERIA="$2"
185
+ shift 2
186
+ ;;
187
+ --expected-files)
188
+ if [[ $# -lt 2 ]]; then
189
+ echo "Error: --expected-files requires a value"
190
+ exit 1
191
+ fi
192
+ # Optional: validate each expected file name if not empty
193
+ if [ -n "$2" ]; then
194
+ IFS=',' read -ra FILES <<< "$2"
195
+ for file in "${FILES[@]}"; do
196
+ sanitize_input "$file" 256 || { echo "Invalid expected filename: $file"; exit 1; }
197
+ done
198
+ fi
199
+ EXPECTED_FILES="$2"
200
+ shift 2
201
+ ;;
202
+ --phase-id)
203
+ if [[ $# -lt 2 ]]; then
204
+ echo "Error: --phase-id requires a value"
205
+ exit 1
206
+ fi
207
+ PHASE_ID=$(sanitize_input "$2") || { echo "Invalid phase ID"; exit 1; }
208
+ shift 2
209
+ ;;
210
+ *)
211
+ echo "Error: Unknown option: '$1'"
212
+ echo ""
213
+ echo "Usage: $0 [OPTIONS]"
214
+ echo ""
215
+ echo "Required options:"
216
+ echo " --task-id <id> Unique task identifier"
217
+ echo " --loop3-agents <agents> Comma-separated list of Loop 3 agents"
218
+ echo " --loop2-agents <agents> Comma-separated list of Loop 2 agents"
219
+ echo " --product-owner <agent> Product owner agent ID"
220
+ echo ""
221
+ echo "Optional options:"
222
+ echo " --mode <mode> CFN mode: mvp, standard, enterprise (default: standard)"
223
+ echo " --max-iterations <n> Maximum iterations (default: 10)"
224
+ echo " --min-quorum-loop3 <n> Loop 3 quorum threshold (default: 0.66)"
225
+ echo " --min-quorum-loop2 <n> Loop 2 quorum threshold (default: 0.66)"
226
+ echo " --epic-context <json> Epic context JSON"
227
+ echo " --phase-context <json> Phase context JSON"
228
+ echo " --success-criteria <json> Success criteria JSON"
229
+ echo " --expected-files <files> Comma-separated expected deliverables"
230
+ echo " --phase-id <id> Phase identifier for timeout calculation"
231
+ exit 1
232
+ ;;
233
+ esac
234
+ done
235
+
236
+ # Validation
237
+ if [ -z "$TASK_ID" ] || [ -z "$LOOP3_AGENTS" ] || [ -z "$LOOP2_AGENTS" ] || [ -z "$PRODUCT_OWNER" ]; then
238
+ echo "Error: Required parameters missing"
239
+ echo "Usage: $0 --task-id <id> --mode <mode> --loop3-agents <agents> --loop2-agents <agents> --product-owner <agent>"
240
+ exit 1
241
+ fi
242
+
243
+ # Get thresholds for mode
244
+ # Add additional mode validation with safe fallback
245
+ case "$MODE" in
246
+ mvp)
247
+ GATE=${GATE_THRESHOLD[mvp]:-0.70}
248
+ CONSENSUS=${CONSENSUS_THRESHOLD[mvp]:-0.80}
249
+ ;;
250
+ standard)
251
+ GATE=${GATE_THRESHOLD[standard]:-0.75}
252
+ CONSENSUS=${CONSENSUS_THRESHOLD[standard]:-0.90}
253
+ ;;
254
+ enterprise)
255
+ GATE=${GATE_THRESHOLD[enterprise]:-0.85}
256
+ CONSENSUS=${CONSENSUS_THRESHOLD[enterprise]:-0.95}
257
+ ;;
258
+ *)
259
+ echo "Invalid mode: $MODE"
260
+ exit 1
261
+ ;;
262
+ esac
263
+
264
+ # Calculate timeout
265
+ TIMEOUT=$("$HELPERS_DIR/timeout-calculator.sh" --phase-id "${PHASE_ID:-unknown}")
266
+
267
+ echo "=============================================="
268
+ echo "CFN Loop Orchestration v1.0.0"
269
+ echo "=============================================="
270
+ echo "Task ID: $TASK_ID"
271
+ echo "Mode: $MODE"
272
+ echo "Gate Threshold: $GATE"
273
+ echo "Consensus Threshold: $CONSENSUS"
274
+ echo "Max Iterations: $MAX_ITERATIONS"
275
+ echo "Timeout: ${TIMEOUT}s"
276
+ echo "=============================================="
277
+ echo ""
278
+
279
+ ##############################################################################
280
+ # Helper Functions
281
+ ##############################################################################
282
+
283
+ function store_context() {
284
+ local task_id="$1"
285
+
286
+ # Store epic context if provided using Redis coordination primitive
287
+ if [ -n "$EPIC_CONTEXT" ]; then
288
+ "$REDIS_COORD_SKILL/store-context.sh" \
289
+ --task-id "$task_id" \
290
+ --key "epic-context" \
291
+ --value "$EPIC_CONTEXT" \
292
+ --namespace "swarm" >/dev/null
293
+ echo "Stored epic context"
294
+ fi
295
+
296
+ # Store phase context if provided using Redis coordination primitive
297
+ if [ -n "$PHASE_CONTEXT" ]; then
298
+ "$REDIS_COORD_SKILL/store-context.sh" \
299
+ --task-id "$task_id" \
300
+ --key "phase-context" \
301
+ --value "$PHASE_CONTEXT" \
302
+ --namespace "swarm" >/dev/null
303
+ echo "Stored phase context"
304
+ fi
305
+
306
+ # Store success criteria if provided using Redis coordination primitive
307
+ if [ -n "$SUCCESS_CRITERIA" ]; then
308
+ "$REDIS_COORD_SKILL/store-context.sh" \
309
+ --task-id "$task_id" \
310
+ --key "success-criteria" \
311
+ --value "$SUCCESS_CRITERIA" \
312
+ --namespace "swarm" >/dev/null
313
+ echo "Stored success criteria"
314
+ fi
315
+
316
+ echo ""
317
+ }
318
+
319
+ build_agent_context() {
320
+ local iteration="$1"
321
+ local agent_type="$2"
322
+ local feedback="$3"
323
+ local loop_type="${4:-}" # NEW: loop3, loop2, or loop4 (optional)
324
+
325
+ # Extract from SUCCESS_CRITERIA JSON
326
+ local task_desc="CFN Loop implementation"
327
+ local deliverables=$(echo "$SUCCESS_CRITERIA" | jq -r '.deliverables // [] | join(", ")' 2>/dev/null || echo "")
328
+ local acceptance=$(echo "$SUCCESS_CRITERIA" | jq -r '.acceptanceCriteria // [] | join(", ")' 2>/dev/null || echo "")
329
+
330
+ # Build base context
331
+ local context="Task: $task_desc | Deliverables: $deliverables | Acceptance: $acceptance | Iteration: $iteration"
332
+
333
+ if [[ -n "$feedback" ]]; then
334
+ context="$context | Feedback: $feedback"
335
+ fi
336
+
337
+ # Inject CFN Loop context if injection script exists and loop_type provided
338
+ if [[ -n "$loop_type" ]] && [[ -x "$SCRIPT_DIR/inject-loop-context.sh" ]]; then
339
+ context=$("$SCRIPT_DIR/inject-loop-context.sh" "$loop_type" "$context" 2>/dev/null || echo "$context")
340
+ fi
341
+
342
+ echo "$context"
343
+ }
344
+
345
+ function spawn_loop3_agents() {
346
+ local task_id="$1"
347
+ local iteration="$2"
348
+ local agents="$3"
349
+
350
+ echo "[Loop 3] Spawning implementer agents (iteration $iteration)..."
351
+
352
+ # Convert comma-separated agents to array
353
+ IFS=',' read -ra AGENT_ARRAY <<< "$agents"
354
+
355
+ # Track agent instance counts for unique ID generation
356
+ declare -A AGENT_INSTANCE_COUNTS
357
+
358
+ # Spawn each agent via CLI
359
+ for agent_type in "${AGENT_ARRAY[@]}"; do
360
+ # Generate unique agent ID (agent-type-iteration-instance)
361
+ AGENT_INSTANCE_COUNTS["$agent_type"]=$((${AGENT_INSTANCE_COUNTS["$agent_type"]:-0} + 1))
362
+ INSTANCE_NUM="${AGENT_INSTANCE_COUNTS["$agent_type"]}"
363
+ UNIQUE_AGENT_ID="${agent_type}-${iteration}-${INSTANCE_NUM}"
364
+
365
+ echo " Spawning: $agent_type (ID: $UNIQUE_AGENT_ID)"
366
+
367
+ # Validate agent input
368
+ local safe_agent_type safe_task_id safe_agent_id
369
+ safe_agent_type=$(sanitize_input "$agent_type") || continue
370
+ safe_task_id=$(sanitize_input "$task_id") || continue
371
+ safe_agent_id=$(sanitize_input "$UNIQUE_AGENT_ID") || continue
372
+
373
+ # Spawn agent in background with explicit agent ID
374
+ npx claude-flow-novice agent "$safe_agent_type" \
375
+ --task-id "$safe_task_id" \
376
+ --agent-id "$safe_agent_id" \
377
+ --iteration "$iteration" \
378
+ --context "$(build_agent_context "$iteration" "$safe_agent_type" "" "loop3")" &
379
+
380
+ # Store PID for monitoring using unique agent ID
381
+ AGENT_PID=$!
382
+ "$REDIS_COORD_SKILL/store-context.sh" \
383
+ --task-id "$task_id" \
384
+ --key "${UNIQUE_AGENT_ID}:pid" \
385
+ --value "{\"pid\": $AGENT_PID}" \
386
+ --namespace "swarm" >/dev/null
387
+
388
+ # Store agent ID mapping for later retrieval using Redis SADD for set storage
389
+ redis-cli SADD "swarm:${task_id}:loop3:agent_ids:iteration${iteration}" "$UNIQUE_AGENT_ID" >/dev/null
390
+ done
391
+
392
+ echo "[Loop 3] All agents spawned"
393
+ echo ""
394
+ }
395
+
396
+ function wait_for_agents() {
397
+ local task_id="$1"
398
+ local agents="$2"
399
+ local timeout="$3"
400
+ local iteration="${4:-1}"
401
+
402
+ echo "Waiting for agents to complete (timeout: ${timeout}s)..."
403
+
404
+ # Retrieve actual agent IDs from Redis (stored during spawn using SADD)
405
+ local stored_ids
406
+ stored_ids=$(redis-cli SMEMBERS "swarm:${task_id}:loop3:agent_ids:iteration${iteration}" 2>/dev/null | tr '\n' ',' | sed 's/,$//')
407
+
408
+ # If stored IDs exist, use them; otherwise fallback to generating from agent types
409
+ local -a AGENT_IDS
410
+ if [ -n "$stored_ids" ]; then
411
+ IFS=',' read -ra AGENT_IDS <<< "$stored_ids"
412
+ echo " Retrieved ${#AGENT_IDS[@]} agent IDs from Redis"
413
+ else
414
+ # Fallback: Convert agent types to IDs (legacy compatibility)
415
+ echo " Warning: No stored agent IDs, using agent types as fallback"
416
+ IFS=',' read -ra AGENT_TYPES <<< "$agents"
417
+
418
+ # Track instance counts to match spawn behavior
419
+ declare -A AGENT_INSTANCE_COUNTS
420
+ for agent_type in "${AGENT_TYPES[@]}"; do
421
+ AGENT_INSTANCE_COUNTS["$agent_type"]=$((${AGENT_INSTANCE_COUNTS["$agent_type"]:-0} + 1))
422
+ INSTANCE_NUM="${AGENT_INSTANCE_COUNTS["$agent_type"]}"
423
+ AGENT_IDS+=("${agent_type}-${iteration}-${INSTANCE_NUM}")
424
+ done
425
+ fi
426
+
427
+ # Parallel BLPOP implementation with shared timeout
428
+ # Track start time for global timeout calculation
429
+ local start_time=$(date +%s)
430
+
431
+ # Spawn parallel BLPOP processes for each agent
432
+ local pids=()
433
+ local temp_files=()
434
+
435
+ for unique_agent_id in "${AGENT_IDS[@]}"; do
436
+ # Create temporary file for this agent's result
437
+ local temp_file="/tmp/cfn-wait-${task_id}-${unique_agent_id}-$$.tmp"
438
+ temp_files+=("$temp_file")
439
+
440
+ echo " Waiting for: $unique_agent_id"
441
+
442
+ # Spawn BLPOP in background, write result to temp file
443
+ (
444
+ local result
445
+ if redis-cli blpop "swarm:${task_id}:${unique_agent_id}:done" "$timeout" >/dev/null 2>&1; then
446
+ echo "success" > "$temp_file"
447
+ else
448
+ echo "timeout" > "$temp_file"
449
+ fi
450
+ exit 0
451
+ ) &
452
+
453
+ pids+=($!)
454
+ done
455
+
456
+ # Wait for all parallel BLPOP processes to complete
457
+ # This ensures timeout is global (60s total), not per-agent (60s * N)
458
+ for pid in "${pids[@]}"; do
459
+ wait "$pid" 2>/dev/null || true
460
+ done
461
+
462
+ # Calculate actual elapsed time
463
+ local end_time=$(date +%s)
464
+ local elapsed=$((end_time - start_time))
465
+
466
+ # Check results and report status
467
+ local completed=0
468
+ local timed_out=0
469
+
470
+ for i in "${!AGENT_IDS[@]}"; do
471
+ local unique_agent_id="${AGENT_IDS[$i]}"
472
+ local temp_file="${temp_files[$i]}"
473
+
474
+ if [ -f "$temp_file" ]; then
475
+ local result=$(cat "$temp_file")
476
+ if [ "$result" = "success" ]; then
477
+ ((completed++))
478
+ echo " ✅ $unique_agent_id completed"
479
+ else
480
+ ((timed_out++))
481
+ echo " ⚠️ $unique_agent_id did not complete within timeout"
482
+ fi
483
+ rm -f "$temp_file"
484
+ else
485
+ ((timed_out++))
486
+ echo " ❌ $unique_agent_id result file missing"
487
+ fi
488
+ done
489
+
490
+ echo "Agents completed: $completed/${#AGENT_IDS[@]} (elapsed: ${elapsed}s)"
491
+ echo ""
492
+ }
493
+
494
+ function wait_for_loop2_agents() {
495
+ local task_id="$1"
496
+ local agents="$2"
497
+ local timeout="$3"
498
+ local iteration="${4:-1}"
499
+
500
+ echo "Waiting for Loop 2 validators to complete (timeout: ${timeout}s)..."
501
+
502
+ # Retrieve actual agent IDs from Redis (stored during spawn using SADD)
503
+ local stored_ids
504
+ stored_ids=$(redis-cli SMEMBERS "swarm:${task_id}:loop2:agent_ids:iteration${iteration}" 2>/dev/null | tr '\n' ',' | sed 's/,$//')
505
+
506
+ # If stored IDs exist, use them; otherwise fallback to generating from agent types
507
+ local -a VALIDATOR_IDS
508
+ if [ -n "$stored_ids" ]; then
509
+ IFS=',' read -ra VALIDATOR_IDS <<< "$stored_ids"
510
+ echo " Retrieved ${#VALIDATOR_IDS[@]} validator IDs from Redis"
511
+ else
512
+ # Fallback: Convert agent types to IDs (legacy compatibility)
513
+ echo " Warning: No stored validator IDs, using agent types as fallback"
514
+ IFS=',' read -ra AGENT_TYPES <<< "$agents"
515
+
516
+ # Track instance counts to match spawn behavior
517
+ declare -A AGENT_INSTANCE_COUNTS
518
+ for agent_type in "${AGENT_TYPES[@]}"; do
519
+ AGENT_INSTANCE_COUNTS["$agent_type"]=$((${AGENT_INSTANCE_COUNTS["$agent_type"]:-0} + 1))
520
+ INSTANCE_NUM="${AGENT_INSTANCE_COUNTS["$agent_type"]}"
521
+ VALIDATOR_IDS+=("${agent_type}-${iteration}-${INSTANCE_NUM}")
522
+ done
523
+ fi
524
+
525
+ # Parallel BLPOP implementation
526
+ local start_time=$(date +%s)
527
+ local pids=()
528
+ local temp_files=()
529
+
530
+ for unique_validator_id in "${VALIDATOR_IDS[@]}"; do
531
+ local temp_file="/tmp/cfn-wait-${task_id}-${unique_validator_id}-$$.tmp"
532
+ temp_files+=("$temp_file")
533
+
534
+ echo " Waiting for: $unique_validator_id"
535
+
536
+ # Spawn BLPOP in background
537
+ (
538
+ if redis-cli blpop "swarm:${task_id}:${unique_validator_id}:done" "$timeout" >/dev/null 2>&1; then
539
+ echo "success" > "$temp_file"
540
+ else
541
+ echo "timeout" > "$temp_file"
542
+ fi
543
+ exit 0
544
+ ) &
545
+
546
+ pids+=($!)
547
+ done
548
+
549
+ # Wait for all processes
550
+ for pid in "${pids[@]}"; do
551
+ wait "$pid" 2>/dev/null || true
552
+ done
553
+
554
+ # Check results
555
+ local end_time=$(date +%s)
556
+ local elapsed=$((end_time - start_time))
557
+ local completed=0
558
+ local timed_out=0
559
+
560
+ for i in "${!VALIDATOR_IDS[@]}"; do
561
+ local unique_validator_id="${VALIDATOR_IDS[$i]}"
562
+ local temp_file="${temp_files[$i]}"
563
+
564
+ if [ -f "$temp_file" ]; then
565
+ local result=$(cat "$temp_file")
566
+ if [ "$result" = "success" ]; then
567
+ ((completed++))
568
+ echo " ✅ $unique_validator_id completed"
569
+ else
570
+ ((timed_out++))
571
+ echo " ⚠️ $unique_validator_id did not complete within timeout"
572
+ fi
573
+ rm -f "$temp_file"
574
+ else
575
+ ((timed_out++))
576
+ echo " ❌ $unique_validator_id result file missing"
577
+ fi
578
+ done
579
+
580
+ echo "Validators completed: $completed/${#VALIDATOR_IDS[@]} (elapsed: ${elapsed}s)"
581
+ echo ""
582
+ }
583
+
584
+ function spawn_loop2_agents() {
585
+ local task_id="$1"
586
+ local iteration="$2"
587
+ local agents="$3"
588
+
589
+ echo "[Loop 2] Spawning validator agents (iteration $iteration)..."
590
+
591
+ # Convert comma-separated agents to array
592
+ IFS=',' read -ra AGENT_ARRAY <<< "$agents"
593
+
594
+ # Track agent instance counts for unique ID generation
595
+ declare -A AGENT_INSTANCE_COUNTS
596
+
597
+ # Spawn each agent via CLI
598
+ for agent_type in "${AGENT_ARRAY[@]}"; do
599
+ # Generate unique agent ID (agent-type-iteration-instance)
600
+ AGENT_INSTANCE_COUNTS["$agent_type"]=$((${AGENT_INSTANCE_COUNTS["$agent_type"]:-0} + 1))
601
+ INSTANCE_NUM="${AGENT_INSTANCE_COUNTS["$agent_type"]}"
602
+ UNIQUE_VALIDATOR_ID="${agent_type}-${iteration}-${INSTANCE_NUM}"
603
+
604
+ echo " Spawning: $agent_type (ID: $UNIQUE_VALIDATOR_ID)"
605
+
606
+ # Spawn agent in background with explicit agent ID
607
+ npx claude-flow-novice agent "$agent_type" \
608
+ --task-id "$task_id" \
609
+ --agent-id "$UNIQUE_VALIDATOR_ID" \
610
+ --iteration "$iteration" \
611
+ --context "$(build_agent_context "$iteration" "$agent_type" "" "loop2")" &
612
+
613
+ # Store PID for monitoring using unique agent ID
614
+ AGENT_PID=$!
615
+ "$REDIS_COORD_SKILL/store-context.sh" \
616
+ --task-id "$task_id" \
617
+ --key "${UNIQUE_VALIDATOR_ID}:pid" \
618
+ --value "{\"pid\": $AGENT_PID}" \
619
+ --namespace "swarm" >/dev/null
620
+
621
+ # Store agent ID mapping for later retrieval using Redis SADD for set storage
622
+ redis-cli SADD "swarm:${task_id}:loop2:agent_ids:iteration${iteration}" "$UNIQUE_VALIDATOR_ID" >/dev/null
623
+ done
624
+
625
+ echo "[Loop 2] All agents spawned"
626
+ echo ""
627
+ }
628
+
629
+ function spawn_product_owner() {
630
+ local task_id="$1"
631
+ local iteration="$2"
632
+
633
+ echo "[Product Owner] Spawning decision agent..."
634
+
635
+ # BLOCKER #2 FIX: Match execute-decision.sh actual parameters
636
+ # Required: --task-id, --agent-id, --consensus, --threshold, --iteration, --max-iterations
637
+ local decision_output
638
+ decision_output=$("$SCRIPT_DIR/.claude/skills/cfn-cfn-product-owner-decision/execute-decision.sh" \
639
+ --task-id "$task_id" \
640
+ --agent-id "$PRODUCT_OWNER" \
641
+ --consensus "$LOOP2_FINAL_CONSENSUS" \
642
+ --threshold "$CONSENSUS" \
643
+ --iteration "$iteration" \
644
+ --max-iterations "$MAX_ITERATIONS")
645
+
646
+ # Parse decision from output
647
+ if echo "$decision_output" | grep -q "PROCEED"; then
648
+ FINAL_DECISION="PROCEED"
649
+ elif echo "$decision_output" | grep -q "ITERATE"; then
650
+ FINAL_DECISION="ITERATE"
651
+ elif echo "$decision_output" | grep -q "ABORT"; then
652
+ FINAL_DECISION="ABORT"
653
+ else
654
+ echo "Warning: Could not parse Product Owner decision, defaulting to ITERATE"
655
+ FINAL_DECISION="ITERATE"
656
+ fi
657
+
658
+ echo "[Product Owner] Decision: $FINAL_DECISION"
659
+ echo ""
660
+ }
661
+
662
+ function output_result() {
663
+ local status="$1"
664
+ local end_time=$(date +%s)
665
+ local execution_time=$((end_time - START_TIME))
666
+
667
+ echo "=============================================="
668
+ echo "CFN Loop Execution Complete"
669
+ echo "=============================================="
670
+ echo "Status: $status"
671
+ echo "Iterations: $ITERATIONS_COMPLETED"
672
+ echo "Final Decision: $FINAL_DECISION"
673
+ echo "Loop 3 Confidence: $LOOP3_FINAL_CONFIDENCE"
674
+ echo "Loop 2 Consensus: $LOOP2_FINAL_CONSENSUS"
675
+ echo "Deliverables Verified: $DELIVERABLES_VERIFIED"
676
+ echo "Execution Time: ${execution_time}s"
677
+ echo "=============================================="
678
+
679
+ # Output structured JSON result
680
+ cat <<EOF
681
+ {
682
+ "status": "$status",
683
+ "iterations_completed": $ITERATIONS_COMPLETED,
684
+ "final_decision": "$FINAL_DECISION",
685
+ "loop3_confidence": $LOOP3_FINAL_CONFIDENCE,
686
+ "loop2_consensus": $LOOP2_FINAL_CONSENSUS,
687
+ "deliverables_verified": $DELIVERABLES_VERIFIED,
688
+ "execution_time_seconds": $execution_time
689
+ }
690
+ EOF
691
+ }
692
+
693
+ ##############################################################################
694
+ # Main CFN Loop
695
+ ##############################################################################
696
+
697
+ # Store context in Redis
698
+ store_context "$TASK_ID"
699
+
700
+ # Iteration loop
701
+ for ((ITERATION=1; ITERATION<=MAX_ITERATIONS; ITERATION++)); do
702
+ echo ""
703
+ echo "=========================================="
704
+ echo "Iteration $ITERATION / $MAX_ITERATIONS"
705
+ echo "=========================================="
706
+ echo ""
707
+
708
+ ITERATIONS_COMPLETED=$ITERATION
709
+
710
+ # Step 1: Spawn Loop 3 agents (implementers)
711
+ spawn_loop3_agents "$TASK_ID" "$ITERATION" "$LOOP3_AGENTS"
712
+
713
+ # Step 2: Wait for Loop 3 completion
714
+ wait_for_agents "$TASK_ID" "$LOOP3_AGENTS" "$TIMEOUT" "$ITERATION"
715
+
716
+ # Step 3: Verify deliverables (prevent "consensus on vapor")
717
+ if [ -n "$EXPECTED_FILES" ] || [ -n "$EPIC_CONTEXT" ]; then
718
+ # Extract task type from epic context for keyword detection
719
+ TASK_TYPE=""
720
+ if [ -n "$EPIC_CONTEXT" ]; then
721
+ TASK_TYPE=$(echo "$EPIC_CONTEXT" | jq -r '.epicGoal // ""' 2>/dev/null || echo "")
722
+ fi
723
+
724
+ if "$HELPERS_DIR/deliverable-verifier.sh" \
725
+ --expected-files "${EXPECTED_FILES:-}" \
726
+ --task-type "${TASK_TYPE:-}"; then
727
+ DELIVERABLES_VERIFIED=true
728
+ else
729
+ echo "❌ Deliverable verification failed - forcing Loop 3 iteration"
730
+ # Use iteration manager to wake Loop 3 agents with explicit feedback
731
+ "$HELPERS_DIR/iteration-manager.sh" \
732
+ --task-id "$TASK_ID" \
733
+ --iteration "$((ITERATION + 1))" \
734
+ --agents "$LOOP3_AGENTS" \
735
+ --feedback-source "swarm:${TASK_ID}:feedback"
736
+ continue
737
+ fi
738
+ fi
739
+
740
+ # Step 4: Gate check (Loop 3 self-validation)
741
+ # Retrieve actual Loop 3 agent IDs for validation
742
+ LOOP3_IDS=$(redis-cli SMEMBERS "swarm:${TASK_ID}:loop3:agent_ids:iteration${ITERATION}" 2>/dev/null | tr '\n' ',' | sed 's/,$//')
743
+
744
+ if [ -z "$LOOP3_IDS" ]; then
745
+ echo "⚠️ WARNING: No Loop 3 agent IDs found in Redis, using agent types as fallback"
746
+ LOOP3_IDS="$LOOP3_AGENTS"
747
+ fi
748
+
749
+ if "$HELPERS_DIR/gate-check.sh" \
750
+ --task-id "$TASK_ID" \
751
+ --agents "$LOOP3_IDS" \
752
+ --threshold "$GATE" \
753
+ --min-quorum "$MIN_QUORUM_LOOP3"; then
754
+ # Gate passed - store confidence
755
+ LOOP3_FINAL_CONFIDENCE=$("$REDIS_COORD_SKILL/invoke-waiting-mode.sh" collect \
756
+ --task-id "$TASK_ID" \
757
+ --agent-ids "$LOOP3_IDS" \
758
+ --min-quorum "$MIN_QUORUM_LOOP3")
759
+ else
760
+ # Gate failed - iterate Loop 3
761
+ echo "❌ Gate check failed - iterating Loop 3"
762
+ "$HELPERS_DIR/iteration-manager.sh" \
763
+ --task-id "$TASK_ID" \
764
+ --iteration "$((ITERATION + 1))" \
765
+ --agents "$LOOP3_AGENTS" \
766
+ --feedback-source "swarm:${TASK_ID}:feedback"
767
+ continue
768
+ fi
769
+
770
+ # Step 5: Spawn Loop 2 agents (validators)
771
+ spawn_loop2_agents "$TASK_ID" "$ITERATION" "$LOOP2_AGENTS"
772
+
773
+ # Step 6: Wait for Loop 2 completion
774
+ wait_for_loop2_agents "$TASK_ID" "$LOOP2_AGENTS" "$TIMEOUT" "$ITERATION"
775
+
776
+ # Step 7: Consensus check (Loop 2 validation)
777
+ # Retrieve actual Loop 2 agent IDs for validation
778
+ LOOP2_IDS=$(redis-cli SMEMBERS "swarm:${TASK_ID}:loop2:agent_ids:iteration${ITERATION}" 2>/dev/null | tr '\n' ',' | sed 's/,$//')
779
+
780
+ if [ -z "$LOOP2_IDS" ]; then
781
+ echo "⚠️ WARNING: No Loop 2 agent IDs found in Redis, using agent types as fallback"
782
+ LOOP2_IDS="$LOOP2_AGENTS"
783
+ fi
784
+
785
+ if "$HELPERS_DIR/consensus.sh" \
786
+ --task-id "$TASK_ID" \
787
+ --agents "$LOOP2_IDS" \
788
+ --threshold "$CONSENSUS" \
789
+ --min-quorum "$MIN_QUORUM_LOOP2"; then
790
+ # Consensus reached - store score
791
+ LOOP2_FINAL_CONSENSUS=$("$REDIS_COORD_SKILL/invoke-waiting-mode.sh" collect \
792
+ --task-id "$TASK_ID" \
793
+ --agent-ids "$LOOP2_IDS" \
794
+ --min-quorum "$MIN_QUORUM_LOOP2")
795
+ else
796
+ # Consensus failed - iterate all agents
797
+ echo "❌ Consensus check failed - iterating all agents"
798
+ "$HELPERS_DIR/iteration-manager.sh" \
799
+ --task-id "$TASK_ID" \
800
+ --iteration "$((ITERATION + 1))" \
801
+ --agents "$LOOP3_AGENTS,$LOOP2_AGENTS" \
802
+ --feedback-source "swarm:${TASK_ID}:feedback"
803
+ continue
804
+ fi
805
+
806
+ # Step 8: Product Owner Decision
807
+ spawn_product_owner "$TASK_ID" "$ITERATION"
808
+
809
+ # Step 9: Execute decision
810
+ case "$FINAL_DECISION" in
811
+ PROCEED)
812
+ # Launch ACE reflection in background (Loop 5)
813
+ echo "[Loop 5] Launching reflection in background..."
814
+
815
+ # Ensure log directory exists
816
+ mkdir -p "$PROJECT_ROOT/.artifacts/logs"
817
+
818
+ # Build reflection context from CFN Loop execution
819
+ REFLECTION_CONTEXT=$(cat <<EOF
820
+ {
821
+ "task_id": "$TASK_ID",
822
+ "task_type": "cfn_loop",
823
+ "mode": "$MODE",
824
+ "iterations_completed": $ITERATIONS_COMPLETED,
825
+ "loop3_agents": "$LOOP3_AGENTS",
826
+ "loop2_agents": "$LOOP2_AGENTS",
827
+ "loop3_confidence": $LOOP3_FINAL_CONFIDENCE,
828
+ "loop2_consensus": $LOOP2_FINAL_CONSENSUS,
829
+ "gate_threshold": $GATE,
830
+ "consensus_threshold": $CONSENSUS,
831
+ "deliverables_verified": $DELIVERABLES_VERIFIED,
832
+ "epic_context": $EPIC_CONTEXT,
833
+ "phase_context": $PHASE_CONTEXT,
834
+ "success_criteria": $SUCCESS_CRITERIA
835
+ }
836
+ EOF
837
+ )
838
+
839
+ # Launch reflection in background (non-blocking)
840
+ (
841
+ "$PROJECT_ROOT/.claude/skills/cfn-ace-system/invoke-context-reflect.sh" \
842
+ --context "$REFLECTION_CONTEXT" \
843
+ --output "/tmp/reflection-${TASK_ID}.json" 2>&1 | \
844
+ tee -a "$PROJECT_ROOT/.artifacts/logs/ace-reflection-${TASK_ID}.log"
845
+
846
+ # Log completion
847
+ echo "[$(date -Iseconds)] Reflection complete for task $TASK_ID" >> \
848
+ "$PROJECT_ROOT/.artifacts/logs/ace-reflection-${TASK_ID}.log"
849
+ ) &
850
+
851
+ REFLECTION_PID=$!
852
+ echo "[Loop 5] Reflection launched (PID: $REFLECTION_PID)"
853
+ echo ""
854
+
855
+ # Continue with output (don't wait for reflection)
856
+ output_result "success"
857
+ exit 0
858
+ ;;
859
+ ABORT)
860
+ output_result "aborted"
861
+ exit 1
862
+ ;;
863
+ ITERATE)
864
+ if [ $ITERATION -ge $MAX_ITERATIONS ]; then
865
+ echo "❌ Max iterations reached"
866
+ output_result "failed"
867
+ exit 1
868
+ fi
869
+
870
+ echo "🔄 Product Owner requested iteration"
871
+ "$HELPERS_DIR/iteration-manager.sh" \
872
+ --task-id "$TASK_ID" \
873
+ --iteration "$((ITERATION + 1))" \
874
+ --agents "$LOOP3_AGENTS,$LOOP2_AGENTS" \
875
+ --feedback-source "swarm:${TASK_ID}:feedback"
876
+ continue
877
+ ;;
878
+ esac
879
+ done
880
+
881
+ # Max iterations reached without success
882
+ echo "❌ Max iterations ($MAX_ITERATIONS) reached without PROCEED decision"
883
+ output_result "failed"
884
+ exit 1