@jaimevalasek/aioson 1.7.2 → 1.9.0

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 (1049) hide show
  1. package/CHANGELOG.md +595 -560
  2. package/CODE_OF_CONDUCT.md +12 -12
  3. package/CONTRIBUTING.md +13 -13
  4. package/LICENSE +661 -661
  5. package/README.md +919 -776
  6. package/bin/aioson.js +4 -4
  7. package/docs/design-previews/aurora-command-ui-website.html +884 -884
  8. package/docs/design-previews/aurora-command-ui.html +682 -682
  9. package/docs/design-previews/bold-editorial-ui-website.html +658 -658
  10. package/docs/design-previews/bold-editorial-ui.html +717 -717
  11. package/docs/design-previews/clean-saas-ui-website.html +1202 -1202
  12. package/docs/design-previews/clean-saas-ui.html +549 -549
  13. package/docs/design-previews/cognitive-core-ui-website.html +1009 -1009
  14. package/docs/design-previews/cognitive-core-ui.html +463 -463
  15. package/docs/design-previews/glassmorphism-ui-website.html +572 -572
  16. package/docs/design-previews/glassmorphism-ui.html +886 -886
  17. package/docs/design-previews/index.html +699 -699
  18. package/docs/design-previews/interface-design-website.html +1187 -1187
  19. package/docs/design-previews/interface-design.html +513 -513
  20. package/docs/design-previews/neo-brutalist-ui-website.html +621 -621
  21. package/docs/design-previews/neo-brutalist-ui.html +797 -797
  22. package/docs/design-previews/premium-command-center-ui-website.html +1217 -1217
  23. package/docs/design-previews/premium-command-center-ui.html +552 -552
  24. package/docs/design-previews/pt.squarespace.com-homepage.html +889 -889
  25. package/docs/design-previews/warm-craft-ui-website.html +684 -684
  26. package/docs/design-previews/warm-craft-ui.html +739 -739
  27. package/docs/en/1-understand/ecosystem-map.md +228 -0
  28. package/docs/en/1-understand/glossary.md +288 -0
  29. package/docs/en/1-understand/what-is-aioson.md +94 -0
  30. package/docs/en/1-understand/why-it-exists.md +106 -0
  31. package/docs/en/2-start/existing-project.md +246 -0
  32. package/docs/en/2-start/first-project.md +307 -0
  33. package/docs/en/2-start/initial-decisions.md +223 -0
  34. package/docs/en/3-recipes/README.md +28 -0
  35. package/docs/en/3-recipes/continuity-between-sessions.md +303 -0
  36. package/docs/en/3-recipes/from-idea-to-prd-via-briefing.md +235 -0
  37. package/docs/en/3-recipes/full-feature-with-sheldon.md +338 -0
  38. package/docs/en/4-agents/README.md +56 -0
  39. package/docs/en/5-reference/README.md +60 -0
  40. package/docs/en/{cli-reference.md → 5-reference/cli-reference.md} +639 -409
  41. package/docs/en/5-reference/i18n.md +52 -0
  42. package/docs/en/{json-schemas.md → 5-reference/json-schemas.md} +41 -41
  43. package/docs/en/{mcp.md → 5-reference/mcp.md} +56 -56
  44. package/docs/en/{parallel.md → 5-reference/parallel.md} +82 -82
  45. package/docs/en/{qa-browser.md → 5-reference/qa-browser.md} +339 -339
  46. package/docs/en/{release-flow.md → 5-reference/release-flow.md} +22 -22
  47. package/docs/en/{release-notes-template.md → 5-reference/release-notes-template.md} +41 -41
  48. package/docs/en/{release.md → 5-reference/release.md} +28 -28
  49. package/docs/en/{schemas → 5-reference/schemas}/agent-prompt.schema.json +17 -17
  50. package/docs/en/{schemas → 5-reference/schemas}/agents.schema.json +32 -32
  51. package/docs/en/{schemas → 5-reference/schemas}/context-validate.schema.json +36 -36
  52. package/docs/en/{schemas → 5-reference/schemas}/doctor.schema.json +89 -89
  53. package/docs/en/{schemas → 5-reference/schemas}/error.schema.json +24 -24
  54. package/docs/en/{schemas → 5-reference/schemas}/i18n-add.schema.json +15 -15
  55. package/docs/en/{schemas → 5-reference/schemas}/index.json +126 -116
  56. package/docs/en/{schemas → 5-reference/schemas}/info.schema.json +39 -39
  57. package/docs/en/{schemas → 5-reference/schemas}/init.schema.json +48 -48
  58. package/docs/en/{schemas → 5-reference/schemas}/install.schema.json +60 -60
  59. package/docs/en/{schemas → 5-reference/schemas}/locale-apply.schema.json +30 -30
  60. package/docs/en/{schemas → 5-reference/schemas}/mcp-doctor.schema.json +95 -95
  61. package/docs/en/{schemas → 5-reference/schemas}/mcp-init.schema.json +122 -122
  62. package/docs/en/{schemas → 5-reference/schemas}/package-test.schema.json +24 -24
  63. package/docs/en/{schemas → 5-reference/schemas}/parallel-assign.schema.json +66 -57
  64. package/docs/en/{schemas → 5-reference/schemas}/parallel-doctor.schema.json +122 -86
  65. package/docs/en/5-reference/schemas/parallel-guard.schema.json +63 -0
  66. package/docs/en/{schemas → 5-reference/schemas}/parallel-init.schema.json +53 -53
  67. package/docs/en/5-reference/schemas/parallel-merge.schema.json +84 -0
  68. package/docs/en/5-reference/schemas/parallel-status.schema.json +184 -0
  69. package/docs/en/{schemas → 5-reference/schemas}/setup-context.schema.json +39 -39
  70. package/docs/en/{schemas → 5-reference/schemas}/smoke.schema.json +23 -23
  71. package/docs/en/{schemas → 5-reference/schemas}/update.schema.json +48 -48
  72. package/docs/en/{schemas → 5-reference/schemas}/workflow-plan.schema.json +30 -30
  73. package/docs/en/{squad-dashboard.md → 5-reference/squad-dashboard.md} +372 -372
  74. package/docs/en/{web3.md → 5-reference/web3.md} +54 -54
  75. package/docs/en/README.md +115 -0
  76. package/docs/en/active-learning-loop/README.md +117 -0
  77. package/docs/en/active-learning-loop/active-learning-loop.md +117 -0
  78. package/docs/en/active-learning-loop/cli-commands.md +320 -0
  79. package/docs/en/active-learning-loop/diagrams.md +225 -0
  80. package/docs/en/active-learning-loop/doctor-checks.md +151 -0
  81. package/docs/en/active-learning-loop/how-to-use.md +313 -0
  82. package/docs/en/active-learning-loop/troubleshooting.md +283 -0
  83. package/docs/en/deyvin-subtask-scout/README.md +109 -0
  84. package/docs/en/deyvin-subtask-scout/cli-commands.md +248 -0
  85. package/docs/en/deyvin-subtask-scout/diagrams.md +124 -0
  86. package/docs/en/deyvin-subtask-scout/how-to-use.md +221 -0
  87. package/docs/en/deyvin-subtask-scout/sub-task-scout.md +115 -0
  88. package/docs/en/deyvin-subtask-scout/troubleshooting.md +184 -0
  89. package/docs/integrations/apps-publish-marketplace.md +94 -0
  90. package/docs/integrations/sdlc-genius-boundary.md +76 -76
  91. package/docs/integrations/sdlc-genius-eval-matrix.md +75 -75
  92. package/docs/integrations/sdlc-genius-install-checklist.md +93 -93
  93. package/docs/integrations/sdlc-genius-review-samples.md +86 -86
  94. package/docs/openclaw-bridge.md +308 -308
  95. package/docs/pt/1-entender/glossario.md +288 -0
  96. package/docs/pt/1-entender/mapa-do-ecossistema.md +228 -0
  97. package/docs/pt/1-entender/o-que-e-aioson.md +94 -0
  98. package/docs/pt/1-entender/por-que-existe.md +107 -0
  99. package/docs/pt/2-comecar/decisoes-iniciais.md +223 -0
  100. package/docs/pt/2-comecar/primeiro-projeto.md +307 -0
  101. package/docs/pt/2-comecar/projeto-existente.md +245 -0
  102. package/docs/pt/3-receitas/README.md +28 -0
  103. package/docs/pt/3-receitas/app-saas-do-zero.md +324 -0
  104. package/docs/pt/3-receitas/auditoria-seguranca.md +254 -0
  105. package/docs/pt/3-receitas/clonar-design-de-site.md +211 -0
  106. package/docs/pt/3-receitas/continuidade-entre-sessoes.md +303 -0
  107. package/docs/pt/3-receitas/da-ideia-ao-prd-via-briefing.md +234 -0
  108. package/docs/pt/3-receitas/feature-completa-com-sheldon.md +338 -0
  109. package/docs/pt/3-receitas/integracao-em-codebase-grande.md +243 -0
  110. package/docs/pt/3-receitas/landing-page.md +281 -0
  111. package/docs/pt/3-receitas/plans-externos-para-product.md +191 -0
  112. package/docs/pt/3-receitas/publicar-no-aioson-com.md +219 -0
  113. package/docs/pt/3-receitas/refatoracao-grande.md +251 -0
  114. package/docs/pt/4-agentes/README.md +65 -0
  115. package/docs/pt/4-agentes/analyst.md +111 -0
  116. package/docs/pt/4-agentes/architect.md +113 -0
  117. package/docs/pt/4-agentes/briefing.md +95 -0
  118. package/docs/pt/4-agentes/committer.md +108 -0
  119. package/docs/pt/4-agentes/copywriter.md +279 -0
  120. package/docs/pt/4-agentes/design-hybrid-forge.md +116 -0
  121. package/docs/pt/4-agentes/dev.md +136 -0
  122. package/docs/pt/4-agentes/deyvin.md +99 -0
  123. package/docs/pt/4-agentes/discover.md +122 -0
  124. package/docs/pt/4-agentes/discovery-design-doc.md +91 -0
  125. package/docs/pt/4-agentes/genome.md +115 -0
  126. package/docs/pt/4-agentes/neo.md +93 -0
  127. package/docs/pt/4-agentes/orache.md +107 -0
  128. package/docs/pt/4-agentes/orchestrator.md +118 -0
  129. package/docs/pt/4-agentes/pentester.md +131 -0
  130. package/docs/pt/4-agentes/pm.md +97 -0
  131. package/docs/pt/4-agentes/product.md +114 -0
  132. package/docs/pt/4-agentes/profiler-enricher.md +93 -0
  133. package/docs/pt/4-agentes/profiler-forge.md +93 -0
  134. package/docs/pt/4-agentes/profiler-researcher.md +98 -0
  135. package/docs/pt/4-agentes/qa.md +124 -0
  136. package/docs/pt/4-agentes/setup.md +104 -0
  137. package/docs/pt/4-agentes/sheldon.md +95 -0
  138. package/docs/pt/4-agentes/site-forge.md +104 -0
  139. package/docs/pt/4-agentes/squad.md +127 -0
  140. package/docs/pt/4-agentes/tester.md +105 -0
  141. package/docs/pt/4-agentes/ux-ui.md +110 -0
  142. package/docs/pt/4-agentes/validator.md +118 -0
  143. package/docs/pt/5-referencia/README.md +88 -0
  144. package/docs/pt/5-referencia/agent-chain-continuity.md +124 -0
  145. package/docs/pt/{agent-sharding.md → 5-referencia/agent-sharding.md} +132 -132
  146. package/docs/pt/5-referencia/aioson-com-store.md +119 -0
  147. package/docs/pt/{automacao-squads.md → 5-referencia/automacao-squads.md} +407 -407
  148. package/docs/pt/{clientes-ai.md → 5-referencia/clientes-ai.md} +300 -286
  149. package/docs/pt/{comandos-cli.md → 5-referencia/comandos-cli.md} +1823 -1634
  150. package/docs/pt/5-referencia/compress-agents.md +304 -0
  151. package/docs/pt/5-referencia/design-docs-governance.md +59 -0
  152. package/docs/pt/{devlog-pipeline.md → 5-referencia/devlog-pipeline.md} +270 -270
  153. package/docs/pt/5-referencia/feature-archive.md +199 -0
  154. package/docs/pt/5-referencia/feature-dossier.md +121 -0
  155. package/docs/pt/{fluxo-artefatos.md → 5-referencia/fluxo-artefatos.md} +179 -178
  156. package/docs/pt/{genome-3.0-spec.md → 5-referencia/genome-4.0-spec.md} +407 -296
  157. package/docs/pt/5-referencia/genome-distribution.md +232 -0
  158. package/docs/pt/{hooks-session-guard.md → 5-referencia/hooks-session-guard.md} +454 -454
  159. package/docs/pt/{inteligencia-adaptativa.md → 5-referencia/inteligencia-adaptativa.md} +324 -324
  160. package/docs/pt/5-referencia/live-sessions.md +144 -0
  161. package/docs/pt/5-referencia/memoria-e-contexto.md +340 -0
  162. package/docs/pt/5-referencia/motor-hardening.md +493 -0
  163. package/docs/pt/{output-strategy-delivery.md → 5-referencia/output-strategy-delivery.md} +655 -655
  164. package/docs/pt/5-referencia/runner-system.md +113 -0
  165. package/docs/pt/{runtime-observability.md → 5-referencia/runtime-observability.md} +76 -76
  166. package/docs/pt/{sandbox.md → 5-referencia/sandbox.md} +125 -125
  167. package/docs/pt/{sdd-automation-scripts.md → 5-referencia/sdd-automation-scripts.md} +559 -557
  168. package/docs/pt/5-referencia/sdd-framework.md +115 -0
  169. package/docs/pt/5-referencia/sdd-planos-e-estrutura.md +321 -0
  170. package/docs/pt/5-referencia/secure-by-default.md +117 -0
  171. package/docs/pt/{skills.md → 5-referencia/skills.md} +275 -267
  172. package/docs/pt/{spec-learnings-pipeline.md → 5-referencia/spec-learnings-pipeline.md} +265 -265
  173. package/docs/pt/{squad-dashboard.md → 5-referencia/squad-dashboard.md} +373 -373
  174. package/docs/pt/{web3.md → 5-referencia/web3.md} +797 -797
  175. package/docs/pt/README.md +111 -116
  176. package/docs/pt/_arquivo/README.md +130 -0
  177. package/docs/pt/{advisor-spec.md → _arquivo/advisor-spec.md} +343 -335
  178. package/docs/pt/{agentes-customizados.md → _arquivo/agentes-customizados.md} +678 -670
  179. package/docs/pt/{busca-de-contexto.md → _arquivo/busca-de-contexto.md} +136 -129
  180. package/docs/pt/{cache-de-contexto.md → _arquivo/cache-de-contexto.md} +163 -156
  181. package/docs/pt/{cenarios.md → _arquivo/cenarios.md} +1282 -1274
  182. package/docs/pt/{design-hybrid-forge.md → _arquivo/design-hybrid-forge.md} +365 -356
  183. package/docs/pt/{deyvin.md → _arquivo/deyvin.md} +123 -115
  184. package/docs/pt/{guia-engineer.md → _arquivo/guia-engineer.md} +234 -226
  185. package/docs/pt/{inicio-rapido.md → _arquivo/inicio-rapido.md} +261 -250
  186. package/docs/pt/{memoria-contexto.md → _arquivo/memoria-contexto.md} +262 -255
  187. package/docs/pt/{monitor-de-contexto.md → _arquivo/monitor-de-contexto.md} +165 -158
  188. package/docs/pt/{profiler-system.md → _arquivo/profiler-system.md} +222 -214
  189. package/docs/pt/{recuperacao-de-sessao.md → _arquivo/recuperacao-de-sessao.md} +134 -125
  190. package/docs/pt/{site-forge.md → _arquivo/site-forge.md} +318 -309
  191. package/docs/pt/{squad-genome.md → _arquivo/squad-genome.md} +793 -783
  192. package/docs/pt/active-learning-loop/README.md +117 -0
  193. package/docs/pt/active-learning-loop/ativo-learning-loop.md +117 -0
  194. package/docs/pt/active-learning-loop/comandos-cli.md +320 -0
  195. package/docs/pt/active-learning-loop/como-usar.md +313 -0
  196. package/docs/pt/active-learning-loop/diagramas.md +225 -0
  197. package/docs/pt/active-learning-loop/doctor-checks.md +151 -0
  198. package/docs/pt/active-learning-loop/troubleshooting.md +283 -0
  199. package/docs/pt/agentes.md +996 -672
  200. package/docs/pt/deyvin-subtask-scout/README.md +109 -0
  201. package/docs/pt/deyvin-subtask-scout/comandos-cli.md +248 -0
  202. package/docs/pt/deyvin-subtask-scout/como-usar.md +221 -0
  203. package/docs/pt/deyvin-subtask-scout/diagramas.md +124 -0
  204. package/docs/pt/deyvin-subtask-scout/sub-task-scout.md +113 -0
  205. package/docs/pt/deyvin-subtask-scout/troubleshooting.md +184 -0
  206. package/docs/pt/living-memory/README.md +81 -0
  207. package/docs/pt/living-memory/autonomy-contract.md +206 -0
  208. package/docs/pt/living-memory/diagramas.md +365 -0
  209. package/docs/pt/living-memory/memoria-viva.md +141 -0
  210. package/docs/pt/living-memory/notificacoes-info.md +142 -0
  211. package/docs/pt/living-memory/reflexao-in-harness.md +218 -0
  212. package/docs/pt/living-memory/troubleshooting.md +286 -0
  213. package/docs/testing/genome-2.0-manual-regression.md +23 -23
  214. package/docs/testing/genome-2.0-matrix.md +36 -36
  215. package/docs/testing/genome-2.0-rollout.md +184 -184
  216. package/package.json +51 -50
  217. package/src/a2a/client.js +165 -165
  218. package/src/a2a/server.js +223 -223
  219. package/src/agent-loader.js +280 -280
  220. package/src/agent-manifests.js +86 -0
  221. package/src/agents.js +92 -72
  222. package/src/autonomy-policy.js +163 -0
  223. package/src/backup-local.js +74 -74
  224. package/src/backup-provider.js +303 -303
  225. package/src/brain-query.js +171 -0
  226. package/src/cli.js +1450 -1099
  227. package/src/commands/agent-audit.js +397 -397
  228. package/src/commands/agent-export-skill.js +229 -229
  229. package/src/commands/agent-loader.js +85 -85
  230. package/src/commands/agents.js +273 -160
  231. package/src/commands/artifact-validate.js +218 -189
  232. package/src/commands/auth.js +298 -0
  233. package/src/commands/backup-local-cmd.js +25 -25
  234. package/src/commands/backup.js +533 -533
  235. package/src/commands/brain-query.js +44 -0
  236. package/src/commands/brief-gen.js +405 -405
  237. package/src/commands/brief-validate.js +65 -65
  238. package/src/commands/briefing.js +344 -0
  239. package/src/commands/classify.js +256 -256
  240. package/src/commands/cloud.js +1767 -1767
  241. package/src/commands/commit-prepare.js +610 -0
  242. package/src/commands/compress-agents.js +416 -0
  243. package/src/commands/config.js +90 -90
  244. package/src/commands/context-cache.js +90 -90
  245. package/src/commands/context-compact.js +49 -49
  246. package/src/commands/context-health.js +187 -175
  247. package/src/commands/context-load.js +219 -0
  248. package/src/commands/context-monitor.js +163 -163
  249. package/src/commands/context-pack.js +45 -45
  250. package/src/commands/context-search.js +66 -66
  251. package/src/commands/context-trim.js +183 -177
  252. package/src/commands/context-validate.js +91 -91
  253. package/src/commands/design-hybrid-options.js +385 -385
  254. package/src/commands/detect-test-runner.js +55 -55
  255. package/src/commands/dev-resume.js +32 -0
  256. package/src/commands/devlog-export-brains.js +27 -27
  257. package/src/commands/devlog-process.js +294 -292
  258. package/src/commands/devlog-watch.js +131 -131
  259. package/src/commands/doctor.js +123 -123
  260. package/src/commands/dossier-add-research.js +114 -0
  261. package/src/commands/dossier-audit.js +222 -0
  262. package/src/commands/dossier.js +423 -0
  263. package/src/commands/feature-archive.js +513 -0
  264. package/src/commands/feature-close.js +554 -165
  265. package/src/commands/gate-approve.js +198 -0
  266. package/src/commands/gate-check.js +247 -228
  267. package/src/commands/genome-doctor.js +489 -41
  268. package/src/commands/genome-migrate.js +49 -49
  269. package/src/commands/git-guard.js +170 -0
  270. package/src/commands/harness.js +307 -0
  271. package/src/commands/health.js +214 -214
  272. package/src/commands/hooks-emit.js +253 -253
  273. package/src/commands/hooks-install.js +347 -347
  274. package/src/commands/i18n-add.js +56 -56
  275. package/src/commands/implementation-plan.js +367 -340
  276. package/src/commands/info.js +41 -41
  277. package/src/commands/init.js +120 -116
  278. package/src/commands/install.js +162 -107
  279. package/src/commands/learning-auto-promote.js +197 -195
  280. package/src/commands/learning-evolve.js +364 -364
  281. package/src/commands/learning-export.js +103 -103
  282. package/src/commands/learning-rollback.js +164 -164
  283. package/src/commands/learning.js +134 -134
  284. package/src/commands/live.js +2101 -1641
  285. package/src/commands/locale-apply.js +54 -51
  286. package/src/commands/locale-diff.js +25 -126
  287. package/src/commands/mcp-doctor.js +407 -406
  288. package/src/commands/mcp-init.js +373 -379
  289. package/src/commands/memory-archive.js +193 -0
  290. package/src/commands/memory-reflect-commit.js +148 -0
  291. package/src/commands/memory-reflect-prepare.js +97 -0
  292. package/src/commands/memory-restore.js +177 -0
  293. package/src/commands/memory-search.js +135 -0
  294. package/src/commands/memory.js +299 -0
  295. package/src/commands/notify.js +68 -0
  296. package/src/commands/package-e2e.js +273 -273
  297. package/src/commands/parallel-assign.js +483 -403
  298. package/src/commands/parallel-doctor.js +850 -437
  299. package/src/commands/parallel-guard.js +241 -0
  300. package/src/commands/parallel-init.js +311 -249
  301. package/src/commands/parallel-merge.js +299 -0
  302. package/src/commands/parallel-status.js +434 -290
  303. package/src/commands/pattern-detect.js +33 -33
  304. package/src/commands/preflight-context.js +30 -30
  305. package/src/commands/preflight.js +267 -208
  306. package/src/commands/pulse-update.js +130 -130
  307. package/src/commands/qa-doctor.js +185 -185
  308. package/src/commands/qa-init.js +166 -161
  309. package/src/commands/qa-report.js +58 -58
  310. package/src/commands/qa-run.js +873 -873
  311. package/src/commands/qa-scan.js +337 -337
  312. package/src/commands/recovery.js +43 -43
  313. package/src/commands/revision.js +235 -0
  314. package/src/commands/runner-daemon.js +274 -274
  315. package/src/commands/runner-plan.js +70 -70
  316. package/src/commands/runner-queue-from-plan.js +166 -166
  317. package/src/commands/runner-queue.js +189 -189
  318. package/src/commands/runner-run.js +129 -129
  319. package/src/commands/runtime.js +2086 -2067
  320. package/src/commands/sandbox.js +37 -37
  321. package/src/commands/scaffold-complete.js +188 -0
  322. package/src/commands/scan-project.js +1371 -1371
  323. package/src/commands/scout-commit.js +163 -0
  324. package/src/commands/scout-prep.js +214 -0
  325. package/src/commands/scout-validate.js +112 -0
  326. package/src/commands/security-audit.js +275 -0
  327. package/src/commands/security-scan.js +376 -0
  328. package/src/commands/self-implement-loop.js +306 -256
  329. package/src/commands/session-guard.js +218 -218
  330. package/src/commands/setup-context.js +699 -698
  331. package/src/commands/setup.js +178 -178
  332. package/src/commands/sizing.js +165 -165
  333. package/src/commands/skill.js +670 -670
  334. package/src/commands/smoke.js +426 -426
  335. package/src/commands/spec-checkpoint.js +177 -177
  336. package/src/commands/spec-status.js +79 -79
  337. package/src/commands/spec-sync.js +190 -190
  338. package/src/commands/spec-tasks.js +288 -288
  339. package/src/commands/squad-agent-create.js +830 -788
  340. package/src/commands/squad-autorun.js +1220 -1220
  341. package/src/commands/squad-bus.js +217 -217
  342. package/src/commands/squad-card.js +149 -149
  343. package/src/commands/squad-daemon.js +343 -343
  344. package/src/commands/squad-dashboard.js +39 -39
  345. package/src/commands/squad-dependency-graph.js +164 -164
  346. package/src/commands/squad-deploy.js +64 -64
  347. package/src/commands/squad-doctor.js +460 -460
  348. package/src/commands/squad-export.js +77 -46
  349. package/src/commands/squad-investigate.js +314 -261
  350. package/src/commands/squad-learning.js +209 -209
  351. package/src/commands/squad-mcp.js +270 -270
  352. package/src/commands/squad-pipeline.js +343 -343
  353. package/src/commands/squad-plan.js +361 -329
  354. package/src/commands/squad-processes.js +56 -56
  355. package/src/commands/squad-recovery.js +42 -42
  356. package/src/commands/squad-repair-genomes.js +39 -39
  357. package/src/commands/squad-review.js +106 -106
  358. package/src/commands/squad-roi.js +291 -291
  359. package/src/commands/squad-scaffold.js +56 -55
  360. package/src/commands/squad-score.js +311 -250
  361. package/src/commands/squad-status.js +481 -460
  362. package/src/commands/squad-tool-register.js +157 -157
  363. package/src/commands/squad-validate.js +438 -347
  364. package/src/commands/squad-webhook.js +160 -160
  365. package/src/commands/squad-worker.js +191 -191
  366. package/src/commands/squad-worktrees.js +75 -75
  367. package/src/commands/state-save.js +122 -122
  368. package/src/commands/store-genome.js +667 -0
  369. package/src/commands/store-skill.js +247 -0
  370. package/src/commands/store-squad.js +431 -0
  371. package/src/commands/store-system.js +392 -0
  372. package/src/commands/sync-agents-preflight.js +176 -0
  373. package/src/commands/test-agents.js +199 -199
  374. package/src/commands/tool-capabilities.js +63 -0
  375. package/src/commands/tool-registry-cmd.js +232 -232
  376. package/src/commands/update.js +64 -64
  377. package/src/commands/verify-gate.js +612 -572
  378. package/src/commands/web-map.js +70 -70
  379. package/src/commands/web-scrape.js +71 -71
  380. package/src/commands/workflow-execute.js +730 -241
  381. package/src/commands/workflow-harden.js +231 -0
  382. package/src/commands/workflow-heal.js +136 -0
  383. package/src/commands/workflow-next.js +1279 -601
  384. package/src/commands/workflow-plan.js +108 -108
  385. package/src/commands/workflow-status.js +440 -250
  386. package/src/commands/workspace.js +144 -0
  387. package/src/constants.js +413 -417
  388. package/src/context-cache.js +159 -159
  389. package/src/context-memory.js +975 -837
  390. package/src/context-parse-reason.js +22 -22
  391. package/src/context-search.js +326 -326
  392. package/src/context-writer.js +197 -196
  393. package/src/context.js +247 -217
  394. package/src/delivery-runner.js +319 -319
  395. package/src/design-variation-catalog.js +503 -503
  396. package/src/detector.js +261 -261
  397. package/src/doctor.js +760 -289
  398. package/src/dossier/codemap-store.js +267 -0
  399. package/src/dossier/dossier-bootstrap.js +222 -0
  400. package/src/dossier/dossier-compact.js +159 -0
  401. package/src/dossier/lock.js +128 -0
  402. package/src/dossier/research-index-store.js +233 -0
  403. package/src/dossier/revision-store.js +313 -0
  404. package/src/dossier/schema.js +162 -0
  405. package/src/dossier/scout-section.js +127 -0
  406. package/src/dossier/store.js +406 -0
  407. package/src/execution-gateway.js +464 -461
  408. package/src/friction-scanner.js +202 -0
  409. package/src/genome-files.js +198 -198
  410. package/src/genome-format.js +442 -442
  411. package/src/genome-schema.js +238 -215
  412. package/src/genomes/bindings.js +281 -281
  413. package/src/genomes.js +500 -467
  414. package/src/handoff-contract.js +417 -0
  415. package/src/handoff-validator.js +45 -0
  416. package/src/harness/circuit-breaker.js +135 -0
  417. package/src/i18n/index.js +103 -103
  418. package/src/i18n/messages/en.js +1541 -1139
  419. package/src/i18n/messages/es.js +1325 -980
  420. package/src/i18n/messages/fr.js +1333 -987
  421. package/src/i18n/messages/pt-BR.js +1561 -1166
  422. package/src/i18n/scaffold.js +64 -64
  423. package/src/install-animation.js +260 -260
  424. package/src/install-profile.js +127 -143
  425. package/src/install-wizard.js +475 -475
  426. package/src/installer-config-merge.js +207 -0
  427. package/src/installer.js +449 -294
  428. package/src/learning-loop-archive.js +595 -0
  429. package/src/learning-loop-doctor.js +217 -0
  430. package/src/learning-loop-engine.js +254 -0
  431. package/src/learning-loop-fts5.js +132 -0
  432. package/src/learning-loop-migration.js +163 -0
  433. package/src/lib/dev-resume.js +140 -0
  434. package/src/lib/dossier-telemetry.js +36 -0
  435. package/src/lib/genomes/compat.js +206 -206
  436. package/src/lib/genomes/migrate.js +90 -90
  437. package/src/lib/git-commit-guard.js +751 -0
  438. package/src/lib/health-check.js +158 -158
  439. package/src/lib/hook-protocol.js +76 -76
  440. package/src/lib/llm-content-sanitizer.js +44 -0
  441. package/src/lib/security/artifact-reader.js +167 -0
  442. package/src/lib/security/exit-codes.js +51 -0
  443. package/src/lib/security/findings-writer.js +176 -0
  444. package/src/lib/security/runtime-events.js +77 -0
  445. package/src/lib/security/secrets-regex.js +115 -0
  446. package/src/lib/squads/genome-repair.js +49 -49
  447. package/src/lib/store/security-scan.js +175 -0
  448. package/src/lib/terminal-checkbox.js +135 -0
  449. package/src/lib/terminal-picker.js +447 -0
  450. package/src/lib/tmux-launcher.js +163 -0
  451. package/src/lib/tool-capabilities.js +102 -0
  452. package/src/lib/webhook-server.js +328 -328
  453. package/src/locales.js +88 -84
  454. package/src/mcp/apps/squad-dashboard/app.js +163 -163
  455. package/src/mcp/apps/squad-dashboard/index.html +261 -261
  456. package/src/mcp/apps/squad-dashboard/mcp-manifest.json +23 -23
  457. package/src/mcp/resources/squad-state.js +130 -130
  458. package/src/mcp-connectors/registry.js +602 -602
  459. package/src/memory-reflect-engine.js +359 -0
  460. package/src/notify-renderer.js +32 -0
  461. package/src/onboarding.js +305 -305
  462. package/src/parallel-workspace.js +756 -0
  463. package/src/parser.js +66 -59
  464. package/src/path-guard.js +47 -0
  465. package/src/permissions-generator.js +400 -0
  466. package/src/preflight-engine.js +654 -443
  467. package/src/prompt-tool.js +20 -20
  468. package/src/qa-html-report.js +472 -472
  469. package/src/recovery-context-session.js +154 -154
  470. package/src/runner/cascade.js +97 -97
  471. package/src/runner/cli-launcher.js +109 -109
  472. package/src/runner/plan-importer.js +63 -63
  473. package/src/runner/queue-store.js +159 -159
  474. package/src/runtime-store.js +2720 -2676
  475. package/src/sandbox.js +194 -177
  476. package/src/self-healing.js +142 -0
  477. package/src/session-handoff.js +295 -77
  478. package/src/squad/agent-teams-adapter.js +270 -264
  479. package/src/squad/brief-validator.js +350 -350
  480. package/src/squad/bus-bridge.js +140 -140
  481. package/src/squad/context-compactor.js +265 -265
  482. package/src/squad/cross-ai-synthesizer.js +250 -250
  483. package/src/squad/external-session.js +180 -180
  484. package/src/squad/hooks-generator.js +196 -196
  485. package/src/squad/inter-squad-events.js +175 -175
  486. package/src/squad/inter-squad.js +74 -74
  487. package/src/squad/intra-bus.js +345 -345
  488. package/src/squad/learning-extractor.js +213 -213
  489. package/src/squad/pattern-detector.js +365 -365
  490. package/src/squad/preflight-context.js +296 -296
  491. package/src/squad/recovery-context.js +372 -372
  492. package/src/squad/reflection.js +365 -365
  493. package/src/squad/squad-scaffold.js +341 -177
  494. package/src/squad/state-manager.js +310 -310
  495. package/src/squad/task-decomposer.js +652 -652
  496. package/src/squad/verify-gate.js +303 -303
  497. package/src/squad/worktree-manager.js +114 -114
  498. package/src/squad-daemon.js +490 -490
  499. package/src/squad-dashboard/api.js +223 -223
  500. package/src/squad-dashboard/attachment-handler.js +93 -93
  501. package/src/squad-dashboard/context-monitor.js +157 -157
  502. package/src/squad-dashboard/execution-logs.js +115 -115
  503. package/src/squad-dashboard/hunk-review.js +209 -209
  504. package/src/squad-dashboard/metrics.js +133 -133
  505. package/src/squad-dashboard/process-monitor.js +125 -125
  506. package/src/squad-dashboard/renderer.js +858 -858
  507. package/src/squad-dashboard/server.js +232 -232
  508. package/src/squad-dashboard/styles.js +525 -525
  509. package/src/squad-dashboard/token-tracker.js +99 -99
  510. package/src/squads/apply-genome.js +21 -21
  511. package/src/squads/genome-binding-service.js +154 -154
  512. package/src/sub-task-engine.js +415 -0
  513. package/src/sub-task-schemas.js +150 -0
  514. package/src/sub-task-state.js +152 -0
  515. package/src/sub-task-telemetry.js +69 -0
  516. package/src/test-briefing.js +226 -0
  517. package/src/tool-executor.js +94 -94
  518. package/src/updater.js +39 -39
  519. package/src/utils.js +49 -46
  520. package/src/version.js +50 -50
  521. package/src/web.js +284 -284
  522. package/src/worker-runner.js +541 -524
  523. package/src/workflow-gates.js +185 -0
  524. package/template/.aioson/advisors/.gitkeep +1 -1
  525. package/template/.aioson/agents/analyst.md +333 -372
  526. package/template/.aioson/agents/architect.md +325 -338
  527. package/template/.aioson/agents/briefing.md +264 -0
  528. package/template/.aioson/agents/committer.md +161 -0
  529. package/template/.aioson/agents/copywriter.md +937 -463
  530. package/template/.aioson/agents/design-hybrid-forge.md +141 -141
  531. package/template/.aioson/agents/dev.md +295 -779
  532. package/template/.aioson/agents/deyvin.md +198 -290
  533. package/template/.aioson/agents/discover.md +235 -0
  534. package/template/.aioson/agents/discovery-design-doc.md +56 -264
  535. package/template/.aioson/agents/genome.md +1904 -314
  536. package/template/.aioson/agents/manifests/analyst.manifest.json +26 -0
  537. package/template/.aioson/agents/manifests/architect.manifest.json +23 -0
  538. package/template/.aioson/agents/manifests/committer.manifest.json +23 -0
  539. package/template/.aioson/agents/manifests/dev.manifest.json +54 -0
  540. package/template/.aioson/agents/manifests/deyvin.manifest.json +41 -0
  541. package/template/.aioson/agents/manifests/orchestrator.manifest.json +30 -0
  542. package/template/.aioson/agents/manifests/pentester.manifest.json +39 -0
  543. package/template/.aioson/agents/manifests/pm.manifest.json +26 -0
  544. package/template/.aioson/agents/manifests/product.manifest.json +23 -0
  545. package/template/.aioson/agents/manifests/qa.manifest.json +41 -0
  546. package/template/.aioson/agents/manifests/setup.manifest.json +20 -0
  547. package/template/.aioson/agents/manifests/ux-ui.manifest.json +24 -0
  548. package/template/.aioson/agents/neo.md +341 -233
  549. package/template/.aioson/agents/orache.md +430 -434
  550. package/template/.aioson/agents/orchestrator.md +274 -364
  551. package/template/.aioson/agents/pair.md +5 -5
  552. package/template/.aioson/agents/pentester.md +289 -0
  553. package/template/.aioson/agents/pm.md +141 -194
  554. package/template/.aioson/agents/product.md +351 -518
  555. package/template/.aioson/agents/profiler-enricher.md +331 -280
  556. package/template/.aioson/agents/profiler-forge.md +212 -202
  557. package/template/.aioson/agents/profiler-researcher.md +282 -259
  558. package/template/.aioson/agents/qa.md +432 -688
  559. package/template/.aioson/agents/setup.md +423 -649
  560. package/template/.aioson/agents/sheldon.md +259 -829
  561. package/template/.aioson/agents/site-forge.md +281 -1753
  562. package/template/.aioson/agents/squad.md +160 -2027
  563. package/template/.aioson/agents/tester.md +536 -463
  564. package/template/.aioson/agents/ux-ui.md +195 -870
  565. package/template/.aioson/agents/validator.md +101 -0
  566. package/template/.aioson/brains/README.md +132 -128
  567. package/template/.aioson/brains/_archived/.gitkeep +0 -0
  568. package/template/.aioson/brains/_index.json +34 -16
  569. package/template/.aioson/brains/dev/patterns.brain.json +79 -0
  570. package/template/.aioson/brains/scripts/query.js +107 -103
  571. package/template/.aioson/brains/sheldon/architecture-decisions.brain.json +79 -0
  572. package/template/.aioson/brains/site-forge/visual-patterns.brain.json +205 -205
  573. package/template/.aioson/config/autonomy-protocol.json +125 -0
  574. package/template/.aioson/config/learning-loop.json +10 -0
  575. package/template/.aioson/config/scout-engine.json +1 -0
  576. package/template/.aioson/config.md +410 -382
  577. package/template/.aioson/constitution.md +36 -33
  578. package/template/.aioson/context/_archived/.gitkeep +0 -0
  579. package/template/.aioson/context/design-doc.md +136 -0
  580. package/template/.aioson/context/project-map.md +57 -0
  581. package/template/.aioson/context/project-pulse.md +34 -34
  582. package/template/.aioson/context/seeds/seed-example.md +27 -27
  583. package/template/.aioson/context/spec.md.template +54 -54
  584. package/template/.aioson/context/user-profile.md +42 -42
  585. package/template/.aioson/design-docs/code-reuse.md +48 -0
  586. package/template/.aioson/design-docs/componentization.md +47 -0
  587. package/template/.aioson/design-docs/file-size.md +52 -0
  588. package/template/.aioson/design-docs/folder-structure.md +51 -0
  589. package/template/.aioson/design-docs/naming.md +54 -0
  590. package/template/.aioson/docs/LAYERS.md +89 -79
  591. package/template/.aioson/docs/README.md +76 -76
  592. package/template/.aioson/docs/autonomy-protocol.md +80 -0
  593. package/template/.aioson/docs/briefing/briefing-craft.md +237 -0
  594. package/template/.aioson/docs/dev/execution-discipline.md +106 -0
  595. package/template/.aioson/docs/dev/stack-conventions.md +83 -0
  596. package/template/.aioson/docs/deyvin/continuity-recovery.md +57 -0
  597. package/template/.aioson/docs/deyvin/debugging-escalation.md +30 -0
  598. package/template/.aioson/docs/deyvin/pair-execution.md +44 -0
  599. package/template/.aioson/docs/deyvin/runtime-handoffs.md +36 -0
  600. package/template/.aioson/docs/example-external-api-context.md +72 -72
  601. package/template/.aioson/docs/pentester/app-playbooks.md +206 -0
  602. package/template/.aioson/docs/pentester/llm-supplychain.md +165 -0
  603. package/template/.aioson/docs/product/conversation-playbook.md +116 -0
  604. package/template/.aioson/docs/product/prd-contract.md +107 -0
  605. package/template/.aioson/docs/product/quality-lens.md +57 -0
  606. package/template/.aioson/docs/product/research-loop.md +65 -0
  607. package/template/.aioson/docs/sheldon/enrichment-paths.md +134 -0
  608. package/template/.aioson/docs/sheldon/harness-contract.md +118 -0
  609. package/template/.aioson/docs/sheldon/quality-lens.md +57 -0
  610. package/template/.aioson/docs/sheldon/research-loop.md +56 -0
  611. package/template/.aioson/docs/sheldon/web-intelligence.md +75 -0
  612. package/template/.aioson/docs/site-forge-build.md +195 -0
  613. package/template/.aioson/docs/site-forge-extraction.md +135 -0
  614. package/template/.aioson/docs/site-forge-qa.md +155 -0
  615. package/template/.aioson/docs/site-forge-recon.md +434 -0
  616. package/template/.aioson/docs/site-forge-transform.md +249 -0
  617. package/template/.aioson/docs/squad/content-output.md +91 -0
  618. package/template/.aioson/docs/squad/creation-flow.md +149 -0
  619. package/template/.aioson/docs/squad/domain-breadth.md +322 -0
  620. package/template/.aioson/docs/squad/domain-classification.md +117 -0
  621. package/template/.aioson/docs/squad/genome-bindings.md +47 -0
  622. package/template/.aioson/docs/squad/package-contract.md +260 -0
  623. package/template/.aioson/docs/squad/quality-lens.md +60 -0
  624. package/template/.aioson/docs/squad/research-loop.md +59 -0
  625. package/template/.aioson/docs/squad/session-operations.md +117 -0
  626. package/template/.aioson/docs/squad/workflow-quality.md +165 -0
  627. package/template/.aioson/docs/tester/coverage-quality.md +351 -0
  628. package/template/.aioson/docs/ux-ui/accessibility-audit.md +55 -0
  629. package/template/.aioson/docs/ux-ui/audit-mode.md +86 -0
  630. package/template/.aioson/docs/ux-ui/component-map.md +35 -0
  631. package/template/.aioson/docs/ux-ui/design-execution.md +111 -0
  632. package/template/.aioson/docs/ux-ui/design-gate.md +27 -0
  633. package/template/.aioson/docs/ux-ui/research-mode.md +39 -0
  634. package/template/.aioson/docs/ux-ui/site-delivery.md +156 -0
  635. package/template/.aioson/docs/ux-ui/token-contract.md +57 -0
  636. package/template/.aioson/genomes/INDEX.md +195 -0
  637. package/template/.aioson/genomes/copywriting/SKILL.md +137 -0
  638. package/template/.aioson/genomes/copywriting/manifest.json +140 -0
  639. package/template/.aioson/genomes/copywriting/references/application-notes.md +145 -0
  640. package/template/.aioson/genomes/copywriting/references/decision-weights.md +45 -0
  641. package/template/.aioson/genomes/copywriting/references/frameworks/5-act-narrative.md +184 -0
  642. package/template/.aioson/genomes/copywriting/references/frameworks/classical-formulas.md +164 -0
  643. package/template/.aioson/genomes/copywriting/references/frameworks/offer-stack.md +195 -0
  644. package/template/.aioson/genomes/copywriting/references/frameworks/one-belief.md +135 -0
  645. package/template/.aioson/genomes/copywriting/references/frameworks/pms-research.md +211 -0
  646. package/template/.aioson/genomes/copywriting/references/frameworks/two-paths-close.md +190 -0
  647. package/template/.aioson/genomes/copywriting/references/heuristics.md +114 -0
  648. package/template/.aioson/genomes/copywriting/references/meta-axioms.md +68 -0
  649. package/template/.aioson/genomes/copywriting/references/methodology.md +115 -0
  650. package/template/.aioson/genomes/copywriting-brunson/SKILL.md +133 -0
  651. package/template/.aioson/genomes/copywriting-brunson/manifest.json +152 -0
  652. package/template/.aioson/genomes/copywriting-brunson/references/application-notes.md +113 -0
  653. package/template/.aioson/genomes/copywriting-brunson/references/decision-weights.md +33 -0
  654. package/template/.aioson/genomes/copywriting-brunson/references/evidence-and-attribution.md +81 -0
  655. package/template/.aioson/genomes/copywriting-brunson/references/frameworks/6-part-structure.md +136 -0
  656. package/template/.aioson/genomes/copywriting-brunson/references/frameworks/origin-story.md +121 -0
  657. package/template/.aioson/genomes/copywriting-brunson/references/frameworks/perfect-webinar-script.md +139 -0
  658. package/template/.aioson/genomes/copywriting-brunson/references/frameworks/persuasive-storytelling-5-structures.md +164 -0
  659. package/template/.aioson/genomes/copywriting-brunson/references/frameworks/value-stack.md +136 -0
  660. package/template/.aioson/genomes/copywriting-brunson/references/frameworks/who-what-why-how.md +110 -0
  661. package/template/.aioson/genomes/copywriting-brunson/references/meta-axioms.md +36 -0
  662. package/template/.aioson/genomes/copywriting-brunson/references/methodology.md +112 -0
  663. package/template/.aioson/git-guard.json +12 -0
  664. package/template/.aioson/mcp/servers.md +23 -24
  665. package/template/.aioson/profiler-reports/.gitkeep +1 -1
  666. package/template/.aioson/rules/README.md +69 -69
  667. package/template/.aioson/rules/_archived/.gitkeep +0 -0
  668. package/template/.aioson/rules/agent-language-policy.md +93 -0
  669. package/template/.aioson/rules/aioson-context-boundary.md +63 -0
  670. package/template/.aioson/rules/canonical-path-contract.md +47 -0
  671. package/template/.aioson/rules/data-format-convention.md +74 -136
  672. package/template/.aioson/rules/disk-first-artifacts.md +44 -0
  673. package/template/.aioson/rules/example-monetary-values.md +30 -30
  674. package/template/.aioson/rules/output-brevity.md +44 -0
  675. package/template/.aioson/rules/prd-section-ownership.md +49 -0
  676. package/template/.aioson/rules/security-baseline.md +139 -0
  677. package/template/.aioson/rules/spec-level-ownership.md +61 -0
  678. package/template/.aioson/rules/squad/README.md +50 -50
  679. package/template/.aioson/rules/squad-driver-pattern.md +81 -0
  680. package/template/.aioson/schemas/content-blueprint.schema.json +30 -30
  681. package/template/.aioson/schemas/genome-meta.schema.json +150 -150
  682. package/template/.aioson/schemas/genome.schema.json +115 -115
  683. package/template/.aioson/schemas/readiness.schema.json +27 -27
  684. package/template/.aioson/schemas/squad-blueprint.schema.json +228 -204
  685. package/template/.aioson/schemas/squad-manifest.schema.json +874 -830
  686. package/template/.aioson/skills/design/aurora-command-ui/SKILL.md +243 -243
  687. package/template/.aioson/skills/design/aurora-command-ui/references/art-direction.md +293 -293
  688. package/template/.aioson/skills/design/aurora-command-ui/references/components.md +827 -827
  689. package/template/.aioson/skills/design/aurora-command-ui/references/dashboards.md +250 -250
  690. package/template/.aioson/skills/design/aurora-command-ui/references/design-tokens.md +585 -585
  691. package/template/.aioson/skills/design/aurora-command-ui/references/motion.md +365 -365
  692. package/template/.aioson/skills/design/aurora-command-ui/references/patterns.md +482 -482
  693. package/template/.aioson/skills/design/aurora-command-ui/references/websites.md +387 -387
  694. package/template/.aioson/skills/design/bold-editorial-ui/SKILL.md +205 -205
  695. package/template/.aioson/skills/design/bold-editorial-ui/references/art-direction.md +338 -338
  696. package/template/.aioson/skills/design/bold-editorial-ui/references/components.md +977 -977
  697. package/template/.aioson/skills/design/bold-editorial-ui/references/dashboards.md +218 -218
  698. package/template/.aioson/skills/design/bold-editorial-ui/references/design-tokens.md +326 -326
  699. package/template/.aioson/skills/design/bold-editorial-ui/references/motion.md +461 -461
  700. package/template/.aioson/skills/design/bold-editorial-ui/references/patterns.md +293 -293
  701. package/template/.aioson/skills/design/bold-editorial-ui/references/websites.md +352 -352
  702. package/template/.aioson/skills/design/clean-saas-ui/SKILL.md +210 -210
  703. package/template/.aioson/skills/design/clean-saas-ui/references/art-direction.md +319 -319
  704. package/template/.aioson/skills/design/clean-saas-ui/references/components.md +365 -365
  705. package/template/.aioson/skills/design/clean-saas-ui/references/dashboards.md +196 -196
  706. package/template/.aioson/skills/design/clean-saas-ui/references/design-tokens.md +244 -244
  707. package/template/.aioson/skills/design/clean-saas-ui/references/motion.md +235 -235
  708. package/template/.aioson/skills/design/clean-saas-ui/references/patterns.md +215 -215
  709. package/template/.aioson/skills/design/clean-saas-ui/references/websites.md +295 -295
  710. package/template/.aioson/skills/design/cognitive-core-ui/SKILL.md +203 -203
  711. package/template/.aioson/skills/design/cognitive-core-ui/references/art-direction.md +339 -339
  712. package/template/.aioson/skills/design/cognitive-core-ui/references/components.md +407 -407
  713. package/template/.aioson/skills/design/cognitive-core-ui/references/dashboards.md +272 -272
  714. package/template/.aioson/skills/design/cognitive-core-ui/references/design-tokens.md +524 -524
  715. package/template/.aioson/skills/design/cognitive-core-ui/references/motion.md +279 -279
  716. package/template/.aioson/skills/design/cognitive-core-ui/references/patterns.md +289 -289
  717. package/template/.aioson/skills/design/cognitive-core-ui/references/websites.md +437 -437
  718. package/template/.aioson/skills/design/glassmorphism-ui/SKILL.md +222 -222
  719. package/template/.aioson/skills/design/glassmorphism-ui/references/art-direction.md +159 -159
  720. package/template/.aioson/skills/design/glassmorphism-ui/references/components.md +498 -498
  721. package/template/.aioson/skills/design/glassmorphism-ui/references/dashboards.md +236 -236
  722. package/template/.aioson/skills/design/glassmorphism-ui/references/design-tokens.md +274 -274
  723. package/template/.aioson/skills/design/glassmorphism-ui/references/motion.md +355 -355
  724. package/template/.aioson/skills/design/glassmorphism-ui/references/patterns.md +198 -198
  725. package/template/.aioson/skills/design/glassmorphism-ui/references/websites.md +307 -307
  726. package/template/.aioson/skills/design/interface-design/SKILL.md +47 -47
  727. package/template/.aioson/skills/design/interface-design/references/components-and-states.md +105 -105
  728. package/template/.aioson/skills/design/interface-design/references/design-directions.md +101 -101
  729. package/template/.aioson/skills/design/interface-design/references/handoff-and-quality.md +71 -71
  730. package/template/.aioson/skills/design/interface-design/references/intent-and-domain.md +74 -74
  731. package/template/.aioson/skills/design/interface-design/references/tokens-and-depth.md +173 -173
  732. package/template/.aioson/skills/design/neo-brutalist-ui/SKILL.md +213 -213
  733. package/template/.aioson/skills/design/neo-brutalist-ui/references/art-direction.md +228 -228
  734. package/template/.aioson/skills/design/neo-brutalist-ui/references/components.md +855 -855
  735. package/template/.aioson/skills/design/neo-brutalist-ui/references/dashboards.md +334 -334
  736. package/template/.aioson/skills/design/neo-brutalist-ui/references/design-tokens.md +342 -342
  737. package/template/.aioson/skills/design/neo-brutalist-ui/references/motion.md +286 -286
  738. package/template/.aioson/skills/design/neo-brutalist-ui/references/patterns.md +458 -458
  739. package/template/.aioson/skills/design/neo-brutalist-ui/references/websites.md +723 -723
  740. package/template/.aioson/skills/design/premium-command-center-ui/SKILL.md +62 -62
  741. package/template/.aioson/skills/design/premium-command-center-ui/references/operations.md +74 -74
  742. package/template/.aioson/skills/design/premium-command-center-ui/references/patterns.md +116 -116
  743. package/template/.aioson/skills/design/premium-command-center-ui/references/validation.md +47 -47
  744. package/template/.aioson/skills/design/premium-command-center-ui/references/visual-system.md +215 -215
  745. package/template/.aioson/skills/design/pt.squarespace.com/.skill-meta.json +31 -31
  746. package/template/.aioson/skills/design/pt.squarespace.com/SKILL.md +66 -66
  747. package/template/.aioson/skills/design/pt.squarespace.com/references/components.md +368 -368
  748. package/template/.aioson/skills/design/pt.squarespace.com/references/design-tokens.md +150 -150
  749. package/template/.aioson/skills/design/pt.squarespace.com/references/motion.md +270 -270
  750. package/template/.aioson/skills/design/pt.squarespace.com/references/patterns.md +189 -189
  751. package/template/.aioson/skills/design/pt.squarespace.com/references/websites.md +165 -165
  752. package/template/.aioson/skills/design/warm-craft-ui/SKILL.md +209 -209
  753. package/template/.aioson/skills/design/warm-craft-ui/references/art-direction.md +324 -324
  754. package/template/.aioson/skills/design/warm-craft-ui/references/components.md +508 -508
  755. package/template/.aioson/skills/design/warm-craft-ui/references/dashboards.md +223 -223
  756. package/template/.aioson/skills/design/warm-craft-ui/references/design-tokens.md +374 -374
  757. package/template/.aioson/skills/design/warm-craft-ui/references/motion.md +356 -356
  758. package/template/.aioson/skills/design/warm-craft-ui/references/patterns.md +288 -288
  759. package/template/.aioson/skills/design/warm-craft-ui/references/websites.md +289 -289
  760. package/template/.aioson/skills/design-system/SKILL.md +92 -92
  761. package/template/.aioson/skills/design-system/components/SKILL.md +274 -274
  762. package/template/.aioson/skills/design-system/dashboards/SKILL.md +184 -184
  763. package/template/.aioson/skills/design-system/foundations/SKILL.md +250 -250
  764. package/template/.aioson/skills/design-system/motion/SKILL.md +197 -197
  765. package/template/.aioson/skills/design-system/patterns/SKILL.md +231 -231
  766. package/template/.aioson/skills/dynamic/README.md +30 -30
  767. package/template/.aioson/skills/dynamic/cardano-docs.md +16 -16
  768. package/template/.aioson/skills/dynamic/ethereum-docs.md +17 -17
  769. package/template/.aioson/skills/dynamic/flux-ui-docs.md +13 -13
  770. package/template/.aioson/skills/dynamic/laravel-docs.md +41 -41
  771. package/template/.aioson/skills/dynamic/npm-packages.md +16 -16
  772. package/template/.aioson/skills/dynamic/solana-docs.md +16 -16
  773. package/template/.aioson/skills/marketing/references/anti-patterns.md +254 -254
  774. package/template/.aioson/skills/marketing/references/cta-matrix.md +361 -0
  775. package/template/.aioson/skills/marketing/references/fascinations.md +192 -192
  776. package/template/.aioson/skills/marketing/references/five-acts.md +248 -248
  777. package/template/.aioson/skills/marketing/references/headline-matrix.md +358 -0
  778. package/template/.aioson/skills/marketing/references/market-intelligence.md +198 -198
  779. package/template/.aioson/skills/marketing/references/offer-structure.md +203 -203
  780. package/template/.aioson/skills/marketing/references/one-belief.md +149 -149
  781. package/template/.aioson/skills/marketing/references/patterns.md +218 -218
  782. package/template/.aioson/skills/marketing/references/platform-constraints.md +337 -0
  783. package/template/.aioson/skills/marketing/references/pms-research.md +193 -193
  784. package/template/.aioson/skills/marketing/vsl-craft.md +385 -385
  785. package/template/.aioson/skills/premium-visual-design/SKILL.md +83 -83
  786. package/template/.aioson/skills/premium-visual-design/components/agent-badge.md +92 -92
  787. package/template/.aioson/skills/premium-visual-design/components/dependency-node.md +102 -102
  788. package/template/.aioson/skills/premium-visual-design/components/mention-autocomplete.md +136 -136
  789. package/template/.aioson/skills/premium-visual-design/components/notification-center.md +136 -136
  790. package/template/.aioson/skills/premium-visual-design/components/review-action-bar.md +188 -188
  791. package/template/.aioson/skills/premium-visual-design/components/team-switcher.md +131 -131
  792. package/template/.aioson/skills/premium-visual-design/patterns/agent-message-thread.md +198 -198
  793. package/template/.aioson/skills/premium-visual-design/patterns/notification-panel.md +275 -275
  794. package/template/.aioson/skills/premium-visual-design/patterns/review-workflow-ui.md +234 -234
  795. package/template/.aioson/skills/premium-visual-design/patterns/task-dependency-graph.md +147 -147
  796. package/template/.aioson/skills/premium-visual-design/tokens/status-extended.md +142 -142
  797. package/template/.aioson/skills/process/aioson-spec-driven/SKILL.md +46 -46
  798. package/template/.aioson/skills/process/aioson-spec-driven/references/analyst.md +30 -30
  799. package/template/.aioson/skills/process/aioson-spec-driven/references/approval-gates.md +109 -109
  800. package/template/.aioson/skills/process/aioson-spec-driven/references/architect.md +23 -23
  801. package/template/.aioson/skills/process/aioson-spec-driven/references/artifact-map.md +44 -44
  802. package/template/.aioson/skills/process/aioson-spec-driven/references/classification-map.md +37 -37
  803. package/template/.aioson/skills/process/aioson-spec-driven/references/dev.md +47 -47
  804. package/template/.aioson/skills/process/aioson-spec-driven/references/deyvin.md +27 -27
  805. package/template/.aioson/skills/process/aioson-spec-driven/references/hardening-lane.md +49 -49
  806. package/template/.aioson/skills/process/aioson-spec-driven/references/maintenance-and-state.md +101 -101
  807. package/template/.aioson/skills/process/aioson-spec-driven/references/pm.md +30 -0
  808. package/template/.aioson/skills/process/aioson-spec-driven/references/product.md +25 -25
  809. package/template/.aioson/skills/process/aioson-spec-driven/references/qa.md +30 -30
  810. package/template/.aioson/skills/process/aioson-spec-driven/references/sheldon.md +25 -25
  811. package/template/.aioson/skills/process/aioson-spec-driven/references/ui-language.md +75 -75
  812. package/template/.aioson/skills/process/design-hybrid-forge/SKILL.md +147 -147
  813. package/template/.aioson/skills/process/design-hybrid-forge/references/crossover-protocol.md +221 -221
  814. package/template/.aioson/skills/process/design-hybrid-forge/references/naming-registry.md +88 -88
  815. package/template/.aioson/skills/process/design-hybrid-forge/references/output-contract.md +306 -306
  816. package/template/.aioson/skills/process/design-hybrid-forge/references/pair-compatibility.md +149 -149
  817. package/template/.aioson/skills/process/design-hybrid-forge/references/quality-gates.md +208 -208
  818. package/template/.aioson/skills/process/design-hybrid-forge/references/variation-library.md +125 -125
  819. package/template/.aioson/skills/process/secure-tdd/SKILL.md +97 -0
  820. package/template/.aioson/skills/process/simplify/SKILL.md +173 -173
  821. package/template/.aioson/skills/references/premium-command-center-ui/master-application-prompt.md +79 -79
  822. package/template/.aioson/skills/references/premium-command-center-ui/operational-ux-playbook.md +253 -253
  823. package/template/.aioson/skills/references/premium-command-center-ui/quality-validation-checklist.md +82 -82
  824. package/template/.aioson/skills/references/premium-command-center-ui/visual-system-and-component-patterns.md +270 -270
  825. package/template/.aioson/skills/squad/SKILL.md +58 -58
  826. package/template/.aioson/skills/squad/formats/catalog.json +15 -15
  827. package/template/.aioson/skills/squad/formats/content/blog-post.md +47 -47
  828. package/template/.aioson/skills/squad/formats/content/newsletter.md +47 -47
  829. package/template/.aioson/skills/squad/formats/creative/podcast-script.md +43 -43
  830. package/template/.aioson/skills/squad/formats/creative/video-script.md +41 -41
  831. package/template/.aioson/skills/squad/formats/social/instagram-feed.md +42 -42
  832. package/template/.aioson/skills/squad/formats/social/linkedin-post.md +42 -42
  833. package/template/.aioson/skills/squad/formats/social/tiktok.md +39 -39
  834. package/template/.aioson/skills/squad/formats/social/twitter-thread.md +39 -39
  835. package/template/.aioson/skills/squad/formats/social/youtube-long.md +47 -47
  836. package/template/.aioson/skills/squad/formats/social/youtube-shorts.md +39 -39
  837. package/template/.aioson/skills/squad/patterns/multi-platform-pattern.md +108 -108
  838. package/template/.aioson/skills/squad/patterns/persona-based-pattern.md +98 -98
  839. package/template/.aioson/skills/squad/patterns/pipeline-pattern.md +106 -106
  840. package/template/.aioson/skills/squad/patterns/review-loop-pattern.md +81 -81
  841. package/template/.aioson/skills/squad/references/checklist-templates.md +122 -122
  842. package/template/.aioson/skills/squad/references/executor-archetypes.md +123 -123
  843. package/template/.aioson/skills/squad/references/workflow-templates.md +169 -169
  844. package/template/.aioson/skills/static/context-budget-guide.md +46 -46
  845. package/template/.aioson/skills/static/debugging-protocol.md +42 -42
  846. package/template/.aioson/skills/static/django-patterns.md +342 -342
  847. package/template/.aioson/skills/static/fastapi-patterns.md +344 -344
  848. package/template/.aioson/skills/static/filament-patterns.md +267 -267
  849. package/template/.aioson/skills/static/flux-ui-components.md +262 -262
  850. package/template/.aioson/skills/static/git-conventions.md +227 -227
  851. package/template/.aioson/skills/static/git-worktrees.md +36 -36
  852. package/template/.aioson/skills/static/harness-sensors.md +74 -74
  853. package/template/.aioson/skills/static/harness-validate/SKILL.md +46 -0
  854. package/template/.aioson/skills/static/jetstream-setup.md +200 -200
  855. package/template/.aioson/skills/static/landing-page-deploy.md +192 -192
  856. package/template/.aioson/skills/static/landing-page-forge.md +730 -730
  857. package/template/.aioson/skills/static/laravel-conventions.md +491 -491
  858. package/template/.aioson/skills/static/multi-agent-patterns.md +43 -43
  859. package/template/.aioson/skills/static/nextjs-patterns.md +321 -321
  860. package/template/.aioson/skills/static/node-express-patterns.md +317 -317
  861. package/template/.aioson/skills/static/node-typescript-patterns.md +282 -282
  862. package/template/.aioson/skills/static/rails-conventions.md +307 -307
  863. package/template/.aioson/skills/static/react-motion-patterns.md +599 -599
  864. package/template/.aioson/skills/static/static-html-patterns/checklists.md +43 -43
  865. package/template/.aioson/skills/static/static-html-patterns/css-tokens.md +609 -609
  866. package/template/.aioson/skills/static/static-html-patterns/motion.md +193 -193
  867. package/template/.aioson/skills/static/static-html-patterns/premium.md +711 -711
  868. package/template/.aioson/skills/static/static-html-patterns/structure.md +209 -209
  869. package/template/.aioson/skills/static/static-html-patterns/utilities.md +190 -190
  870. package/template/.aioson/skills/static/static-html-patterns.md +80 -80
  871. package/template/.aioson/skills/static/tall-stack-patterns.md +286 -286
  872. package/template/.aioson/skills/static/threejs-patterns.md +929 -929
  873. package/template/.aioson/skills/static/ui-ux-modern.md +76 -76
  874. package/template/.aioson/skills/static/web-research-cache.md +115 -112
  875. package/template/.aioson/skills/static/web3-cardano-patterns.md +337 -337
  876. package/template/.aioson/skills/static/web3-ethereum-patterns.md +310 -310
  877. package/template/.aioson/skills/static/web3-security-checklist.md +284 -284
  878. package/template/.aioson/skills/static/web3-solana-patterns.md +324 -324
  879. package/template/.aioson/squads/memory.md +5 -5
  880. package/template/.aioson/tasks/implementation-plan.md +327 -327
  881. package/template/.aioson/tasks/squad-analyze.md +83 -83
  882. package/template/.aioson/tasks/squad-create.md +148 -121
  883. package/template/.aioson/tasks/squad-design.md +206 -158
  884. package/template/.aioson/tasks/squad-execution-plan.md +279 -279
  885. package/template/.aioson/tasks/squad-export.md +20 -20
  886. package/template/.aioson/tasks/squad-extend.md +68 -68
  887. package/template/.aioson/tasks/squad-investigate.md +57 -44
  888. package/template/.aioson/tasks/squad-learning-review.md +44 -44
  889. package/template/.aioson/tasks/squad-output-config.md +177 -177
  890. package/template/.aioson/tasks/squad-pipeline.md +122 -122
  891. package/template/.aioson/tasks/squad-profile.md +48 -48
  892. package/template/.aioson/tasks/squad-refresh.md +236 -0
  893. package/template/.aioson/tasks/squad-repair.md +85 -85
  894. package/template/.aioson/tasks/squad-review.md +61 -61
  895. package/template/.aioson/tasks/squad-task-decompose.md +66 -66
  896. package/template/.aioson/tasks/squad-validate.md +58 -58
  897. package/template/.aioson/templates/reflect-prompts/current-state.md +36 -0
  898. package/template/.aioson/templates/reflect-prompts/how-it-works.md +23 -0
  899. package/template/.aioson/templates/reflect-prompts/what-it-does.md +21 -0
  900. package/template/.aioson/templates/squads/content-basic/template.json +21 -21
  901. package/template/.aioson/templates/squads/digital-marketing-agency/template.json +96 -96
  902. package/template/.aioson/templates/squads/media-channel/template.json +24 -24
  903. package/template/.aioson/templates/squads/research-analysis/template.json +22 -22
  904. package/template/.aioson/templates/squads/software-delivery/template.json +21 -21
  905. package/template/.claude/commands/aioson/agent/analyst.md +5 -5
  906. package/template/.claude/commands/aioson/agent/architect.md +5 -5
  907. package/template/.claude/commands/aioson/agent/briefing.md +5 -0
  908. package/template/.claude/commands/aioson/agent/committer.md +5 -0
  909. package/template/.claude/commands/aioson/agent/copywriter.md +5 -0
  910. package/template/.claude/commands/aioson/agent/design-hybrid-forge.md +5 -5
  911. package/template/.claude/commands/aioson/agent/dev.md +5 -5
  912. package/template/.claude/commands/aioson/agent/deyvin.md +5 -5
  913. package/template/.claude/commands/aioson/agent/discover.md +5 -0
  914. package/template/.claude/commands/aioson/agent/discovery-design-doc.md +5 -5
  915. package/template/.claude/commands/aioson/agent/genome.md +5 -5
  916. package/template/.claude/commands/aioson/agent/neo.md +5 -5
  917. package/template/.claude/commands/aioson/agent/orache.md +5 -5
  918. package/template/.claude/commands/aioson/agent/orchestrator.md +5 -5
  919. package/template/.claude/commands/aioson/agent/pair.md +5 -0
  920. package/template/.claude/commands/aioson/agent/pentester.md +5 -0
  921. package/template/.claude/commands/aioson/agent/pm.md +5 -5
  922. package/template/.claude/commands/aioson/agent/product.md +5 -5
  923. package/template/.claude/commands/aioson/agent/profiler-enricher.md +5 -5
  924. package/template/.claude/commands/aioson/agent/profiler-forge.md +5 -5
  925. package/template/.claude/commands/aioson/agent/profiler-researcher.md +5 -5
  926. package/template/.claude/commands/aioson/agent/qa.md +5 -5
  927. package/template/.claude/commands/aioson/agent/setup.md +5 -5
  928. package/template/.claude/commands/aioson/agent/sheldon.md +5 -5
  929. package/template/.claude/commands/aioson/agent/site-forge.md +5 -5
  930. package/template/.claude/commands/aioson/agent/squad.md +5 -5
  931. package/template/.claude/commands/aioson/agent/tester.md +5 -5
  932. package/template/.claude/commands/aioson/agent/ux-ui.md +5 -5
  933. package/template/.claude/commands/aioson/agent/validator.md +5 -0
  934. package/template/.gemini/GEMINI.md +13 -13
  935. package/template/.gemini/commands/aios-analyst.toml +7 -4
  936. package/template/.gemini/commands/aios-architect.toml +8 -7
  937. package/template/.gemini/commands/aios-committer.toml +7 -0
  938. package/template/.gemini/commands/aios-copywriter.toml +7 -0
  939. package/template/.gemini/commands/aios-cypher.toml +7 -0
  940. package/template/.gemini/commands/aios-dev.toml +9 -8
  941. package/template/.gemini/commands/aios-deyvin.toml +7 -6
  942. package/template/.gemini/commands/aios-discover.toml +6 -0
  943. package/template/.gemini/commands/aios-discovery-design-doc.toml +7 -4
  944. package/template/.gemini/commands/aios-genome.toml +7 -0
  945. package/template/.gemini/commands/aios-neo.toml +6 -4
  946. package/template/.gemini/commands/aios-orache.toml +7 -0
  947. package/template/.gemini/commands/aios-orchestrator.toml +9 -8
  948. package/template/.gemini/commands/aios-pair.toml +7 -6
  949. package/template/.gemini/commands/aios-pm.toml +9 -8
  950. package/template/.gemini/commands/aios-product.toml +6 -4
  951. package/template/.gemini/commands/aios-qa.toml +7 -6
  952. package/template/.gemini/commands/aios-setup.toml +6 -3
  953. package/template/.gemini/commands/aios-sheldon.toml +7 -0
  954. package/template/.gemini/commands/aios-site-forge.toml +7 -0
  955. package/template/.gemini/commands/aios-squad.toml +7 -0
  956. package/template/.gemini/commands/aios-tester.toml +7 -6
  957. package/template/.gemini/commands/aios-ux-ui.toml +9 -8
  958. package/template/.gemini/commands/aios-validator.toml +7 -0
  959. package/template/AGENTS.md +184 -172
  960. package/template/CLAUDE.md +98 -93
  961. package/template/OPENCODE.md +35 -34
  962. package/template/aioson-models.json +40 -40
  963. package/docs/en/i18n.md +0 -52
  964. package/docs/en/schemas/parallel-status.schema.json +0 -94
  965. package/template/.aioson/genomes/copywriting.md +0 -204
  966. package/template/.aioson/locales/en/agents/analyst.md +0 -244
  967. package/template/.aioson/locales/en/agents/architect.md +0 -245
  968. package/template/.aioson/locales/en/agents/dev.md +0 -397
  969. package/template/.aioson/locales/en/agents/deyvin.md +0 -137
  970. package/template/.aioson/locales/en/agents/discovery-design-doc.md +0 -27
  971. package/template/.aioson/locales/en/agents/genome.md +0 -212
  972. package/template/.aioson/locales/en/agents/neo.md +0 -8
  973. package/template/.aioson/locales/en/agents/orache.md +0 -6
  974. package/template/.aioson/locales/en/agents/orchestrator.md +0 -189
  975. package/template/.aioson/locales/en/agents/pair.md +0 -5
  976. package/template/.aioson/locales/en/agents/pm.md +0 -84
  977. package/template/.aioson/locales/en/agents/product.md +0 -378
  978. package/template/.aioson/locales/en/agents/profiler-enricher.md +0 -5
  979. package/template/.aioson/locales/en/agents/profiler-forge.md +0 -5
  980. package/template/.aioson/locales/en/agents/profiler-researcher.md +0 -5
  981. package/template/.aioson/locales/en/agents/qa.md +0 -270
  982. package/template/.aioson/locales/en/agents/setup.md +0 -421
  983. package/template/.aioson/locales/en/agents/sheldon.md +0 -455
  984. package/template/.aioson/locales/en/agents/squad.md +0 -449
  985. package/template/.aioson/locales/en/agents/tester.md +0 -6
  986. package/template/.aioson/locales/en/agents/ux-ui.md +0 -668
  987. package/template/.aioson/locales/es/agents/analyst.md +0 -225
  988. package/template/.aioson/locales/es/agents/architect.md +0 -245
  989. package/template/.aioson/locales/es/agents/dev.md +0 -370
  990. package/template/.aioson/locales/es/agents/deyvin.md +0 -99
  991. package/template/.aioson/locales/es/agents/discovery-design-doc.md +0 -21
  992. package/template/.aioson/locales/es/agents/genome.md +0 -104
  993. package/template/.aioson/locales/es/agents/neo.md +0 -50
  994. package/template/.aioson/locales/es/agents/orache.md +0 -105
  995. package/template/.aioson/locales/es/agents/orchestrator.md +0 -194
  996. package/template/.aioson/locales/es/agents/pair.md +0 -7
  997. package/template/.aioson/locales/es/agents/pm.md +0 -90
  998. package/template/.aioson/locales/es/agents/product.md +0 -372
  999. package/template/.aioson/locales/es/agents/profiler-enricher.md +0 -7
  1000. package/template/.aioson/locales/es/agents/profiler-forge.md +0 -7
  1001. package/template/.aioson/locales/es/agents/profiler-researcher.md +0 -7
  1002. package/template/.aioson/locales/es/agents/qa.md +0 -198
  1003. package/template/.aioson/locales/es/agents/setup.md +0 -405
  1004. package/template/.aioson/locales/es/agents/sheldon.md +0 -309
  1005. package/template/.aioson/locales/es/agents/squad.md +0 -532
  1006. package/template/.aioson/locales/es/agents/tester.md +0 -9
  1007. package/template/.aioson/locales/es/agents/ux-ui.md +0 -212
  1008. package/template/.aioson/locales/fr/agents/analyst.md +0 -225
  1009. package/template/.aioson/locales/fr/agents/architect.md +0 -245
  1010. package/template/.aioson/locales/fr/agents/dev.md +0 -370
  1011. package/template/.aioson/locales/fr/agents/deyvin.md +0 -99
  1012. package/template/.aioson/locales/fr/agents/discovery-design-doc.md +0 -21
  1013. package/template/.aioson/locales/fr/agents/genome.md +0 -104
  1014. package/template/.aioson/locales/fr/agents/neo.md +0 -50
  1015. package/template/.aioson/locales/fr/agents/orache.md +0 -106
  1016. package/template/.aioson/locales/fr/agents/orchestrator.md +0 -194
  1017. package/template/.aioson/locales/fr/agents/pair.md +0 -7
  1018. package/template/.aioson/locales/fr/agents/pm.md +0 -90
  1019. package/template/.aioson/locales/fr/agents/product.md +0 -372
  1020. package/template/.aioson/locales/fr/agents/profiler-enricher.md +0 -7
  1021. package/template/.aioson/locales/fr/agents/profiler-forge.md +0 -7
  1022. package/template/.aioson/locales/fr/agents/profiler-researcher.md +0 -7
  1023. package/template/.aioson/locales/fr/agents/qa.md +0 -198
  1024. package/template/.aioson/locales/fr/agents/setup.md +0 -405
  1025. package/template/.aioson/locales/fr/agents/sheldon.md +0 -309
  1026. package/template/.aioson/locales/fr/agents/squad.md +0 -532
  1027. package/template/.aioson/locales/fr/agents/tester.md +0 -9
  1028. package/template/.aioson/locales/fr/agents/ux-ui.md +0 -212
  1029. package/template/.aioson/locales/pt-BR/agents/analyst.md +0 -319
  1030. package/template/.aioson/locales/pt-BR/agents/architect.md +0 -284
  1031. package/template/.aioson/locales/pt-BR/agents/dev.md +0 -483
  1032. package/template/.aioson/locales/pt-BR/agents/deyvin.md +0 -184
  1033. package/template/.aioson/locales/pt-BR/agents/discovery-design-doc.md +0 -198
  1034. package/template/.aioson/locales/pt-BR/agents/genome.md +0 -297
  1035. package/template/.aioson/locales/pt-BR/agents/neo.md +0 -208
  1036. package/template/.aioson/locales/pt-BR/agents/orache.md +0 -137
  1037. package/template/.aioson/locales/pt-BR/agents/orchestrator.md +0 -324
  1038. package/template/.aioson/locales/pt-BR/agents/pair.md +0 -5
  1039. package/template/.aioson/locales/pt-BR/agents/pm.md +0 -182
  1040. package/template/.aioson/locales/pt-BR/agents/product.md +0 -466
  1041. package/template/.aioson/locales/pt-BR/agents/profiler-enricher.md +0 -5
  1042. package/template/.aioson/locales/pt-BR/agents/profiler-forge.md +0 -5
  1043. package/template/.aioson/locales/pt-BR/agents/profiler-researcher.md +0 -5
  1044. package/template/.aioson/locales/pt-BR/agents/qa.md +0 -300
  1045. package/template/.aioson/locales/pt-BR/agents/setup.md +0 -533
  1046. package/template/.aioson/locales/pt-BR/agents/sheldon.md +0 -323
  1047. package/template/.aioson/locales/pt-BR/agents/squad.md +0 -1330
  1048. package/template/.aioson/locales/pt-BR/agents/tester.md +0 -449
  1049. package/template/.aioson/locales/pt-BR/agents/ux-ui.md +0 -669
@@ -1,1220 +1,1220 @@
1
- 'use strict';
2
-
3
- /**
4
- * aioson squad:autorun — Autonomous squad execution
5
- *
6
- * Given a high-level goal, this command:
7
- * 1. Decomposes the goal into a task plan (heuristic or structured)
8
- * 2. Activates the intra-squad bus for real-time communication
9
- * 3. Runs each task through the worker-runner with optional reflection
10
- * 4. Coordinator monitors the bus for blocks or feedback
11
- * 5. Reports the final session summary
12
- *
13
- * Phase 1 additions:
14
- * - Gap Closure Loop: failed tasks are retried up to 3x with failure context
15
- * - Budget Gating: halts before a task if session token budget is exceeded
16
- * - Heartbeat Protocol: posts bus heartbeat every 30s during long tasks
17
- * - Anti-Analysis-Loop Guard: warns executor if N+ status without result
18
- * - Squad STATE.md: cross-session memory updated at start/end
19
- *
20
- * Usage:
21
- * aioson squad:autorun . --squad=content-team --goal="Create 3 podcast episodes"
22
- * aioson squad:autorun . --squad=content-team --goal="..." --reflect --bus --mode=structured
23
- * aioson squad:autorun . --squad=content-team --plan=SESSION_ID (resume from saved plan)
24
- * aioson squad:autorun . --squad=content-team --plan=SESSION_ID --dry-run
25
- *
26
- * Flags:
27
- * --goal High-level objective (required unless --plan is given)
28
- * --reflect Run reflection after each task (default: false)
29
- * --bus Enable intra-bus for inter-executor communication (default: true)
30
- * --mode Decomposition mode: heuristic (default) | structured
31
- * --plan Resume from existing session plan (session ID)
32
- * --dry-run Show plan without executing
33
- * --sequential Force sequential execution even for independent tasks (default: false)
34
- * --timeout Per-task timeout in seconds (default: 120)
35
- * --max-retries Gap closure max retry attempts (default: 3)
36
- * --no-gap-closure Disable automatic retry on task failure
37
- */
38
-
39
- const fs = require('node:fs/promises');
40
- const path = require('node:path');
41
- const { randomUUID } = require('node:crypto');
42
- const {
43
- decompose,
44
- getReadyTasks,
45
- isPlanComplete,
46
- updateTaskStatus,
47
- loadPlan,
48
- formatPlan
49
- } = require('../squad/task-decomposer');
50
- const bus = require('../squad/intra-bus');
51
- const { reflect, formatReport } = require('../squad/reflection');
52
- const { runWorker, listWorkers } = require('../worker-runner');
53
- const stateManager = require('../squad/state-manager');
54
- const { getUnresolvedBlocks } = require('../squad/intra-bus');
55
- const interSquadEvents = require('../squad/inter-squad-events');
56
- const { runHook, HOOK_DENY } = require('../lib/hook-protocol');
57
- const { extractLearnings, persistAgentMemory } = require('../squad/learning-extractor');
58
- const { validateBrief, autoFixBrief } = require('../squad/brief-validator');
59
- const { resolveEngine, translateToTeamConfig, writeTeamConfig } = require('../squad/agent-teams-adapter');
60
-
61
- const STATUS_ICON = {
62
- pending: '○',
63
- in_progress: '●',
64
- completed: '✓',
65
- failed: '✗',
66
- escalated: '⚠',
67
- skipped: '–'
68
- };
69
-
70
- function icon(status) {
71
- return STATUS_ICON[status] || '?';
72
- }
73
-
74
- function nowIso() { return new Date().toISOString(); }
75
-
76
- function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }
77
-
78
- // ─── Budget helpers ───────────────────────────────────────────────────────────
79
-
80
- /**
81
- * Load token budget from squad manifest (optional field).
82
- * Returns Infinity if not configured.
83
- */
84
- async function loadBudget(projectDir, squadSlug) {
85
- const manifestPath = path.join(
86
- projectDir, '.aioson', 'squads', squadSlug, 'squad.manifest.json'
87
- );
88
- try {
89
- const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
90
- const budget = manifest.budget || {};
91
- return {
92
- maxTokensPerSession: budget.max_tokens_per_session || Infinity,
93
- maxTokensPerTask: budget.max_tokens_per_task || Infinity,
94
- actionOnExceed: budget.action_on_exceed || 'pause'
95
- };
96
- } catch {
97
- return { maxTokensPerSession: Infinity, maxTokensPerTask: Infinity, actionOnExceed: 'pause' };
98
- }
99
- }
100
-
101
- /**
102
- * Estimate tokens a task will consume (heuristic: chars/4 + overhead).
103
- */
104
- function estimateTaskTokens(task) {
105
- const descLen = (task.description || '').length;
106
- const criteriaLen = (task.acceptance_criteria || []).join(' ').length;
107
- return Math.ceil((descLen + criteriaLen) / 4) + 500; // 500 base overhead
108
- }
109
-
110
- // ─── Heartbeat wrapper ────────────────────────────────────────────────────────
111
-
112
- /**
113
- * Run a task with heartbeat pulses on the bus every 30s.
114
- * Clears the interval on task completion/failure regardless.
115
- */
116
- async function runTaskWithHeartbeat(projectDir, squadSlug, task, sessionId, options, runFn) {
117
- const { enableBus } = options;
118
- const startMs = Date.now();
119
-
120
- let hbInterval = null;
121
- if (enableBus) {
122
- hbInterval = setInterval(async () => {
123
- const elapsed = Math.round((Date.now() - startMs) / 1000);
124
- await bus.post(projectDir, squadSlug, sessionId, {
125
- from: 'coordinator',
126
- to: '*',
127
- type: 'heartbeat',
128
- content: `${task.title} — ${elapsed}s elapsed`,
129
- metadata: { task_id: task.id, elapsed_s: elapsed }
130
- }).catch(() => {});
131
- }, 30_000);
132
- }
133
-
134
- try {
135
- return await runFn();
136
- } finally {
137
- if (hbInterval) clearInterval(hbInterval);
138
- }
139
- }
140
-
141
- // ─── Anti-analysis-loop guard ─────────────────────────────────────────────────
142
-
143
- /**
144
- * Check if an executor appears to be in an analysis loop.
145
- * Posts a coordinator feedback message if the threshold is exceeded.
146
- */
147
- async function checkAntiLoop(projectDir, squadSlug, sessionId, task, enableBus, threshold = 8) {
148
- if (!enableBus || !task.executor) return;
149
-
150
- const messages = await bus.read(projectDir, squadSlug, sessionId).catch(() => []);
151
- if (bus.isAnalysisLoop(messages, task.executor, threshold)) {
152
- await bus.post(projectDir, squadSlug, sessionId, {
153
- from: 'coordinator',
154
- to: task.executor,
155
- type: 'feedback',
156
- content: `Analysis loop detected for "${task.title}". You have posted ${threshold}+ status updates without a result. Stop analyzing — produce concrete output now, or post a "block" message explaining why you cannot proceed.`,
157
- metadata: { task_id: task.id, anti_loop: true }
158
- }).catch(() => {});
159
- }
160
- }
161
-
162
- // ─── Core task runner ─────────────────────────────────────────────────────────
163
-
164
- /**
165
- * Run a single task (no retry logic here — handled by gap closure wrapper).
166
- */
167
- async function runTask(projectDir, squadSlug, task, sessionId, options, logger) {
168
- const { enableBus, enableReflect, timeoutMs } = options;
169
- const taskCtx = {
170
- projectDir,
171
- squadSlug,
172
- executorSlug: task.executor || 'unknown',
173
- taskTitle: task.title,
174
- iteration: task._attempt || 1
175
- };
176
-
177
- // Post status to bus
178
- if (enableBus) {
179
- await bus.post(projectDir, squadSlug, sessionId, {
180
- from: task.executor || 'coordinator',
181
- to: '*',
182
- type: 'status',
183
- content: `Starting: ${task.title}${task._attempt > 1 ? ` (retry ${task._attempt})` : ''}`,
184
- metadata: { task_id: task.id, attempt: task._attempt || 1 }
185
- }).catch(() => {});
186
- }
187
-
188
- await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'in_progress');
189
-
190
- // Build worker input with fresh context pointers (2.2: paths, not inline content)
191
- const workerInput = {
192
- task_id: task.id,
193
- title: task.title,
194
- description: task.description,
195
- acceptance_criteria: task.acceptance_criteria,
196
- read_first_hints: task.read_first_hints || [], // executor reads these, not coordinator
197
- must_haves: task.must_haves || null,
198
- session_id: sessionId,
199
- bus_enabled: enableBus,
200
- ...(task._failure_context ? { failure_context: task._failure_context, attempt: task._attempt } : {})
201
- };
202
-
203
- let workerResult = null;
204
- let taskOutput = null;
205
- let workerRan = false;
206
-
207
- const workers = await listWorkers(projectDir, squadSlug);
208
- const workerConfig = workers.find(
209
- (w) => w.slug === task.executor || w.slug === task.id
210
- );
211
-
212
- if (workerConfig) {
213
- workerRan = true;
214
- workerResult = await runWorker(projectDir, squadSlug, workerConfig.slug, workerInput, {
215
- timeoutMs,
216
- triggerType: 'autorun'
217
- });
218
- taskOutput = workerResult.ok
219
- ? JSON.stringify(workerResult.output || '')
220
- : `Worker failed: ${workerResult.error}`;
221
- } else {
222
- taskOutput = `[no-worker-script] Task "${task.title}" assigned to executor "${task.executor}". Run manually or scaffold a worker with: aioson squad:worker --squad=${squadSlug} create --slug=${task.executor}`;
223
- workerResult = { ok: true, output: { message: taskOutput }, noScript: true };
224
- }
225
-
226
- // Anti-analysis-loop check after task runs
227
- await checkAntiLoop(projectDir, squadSlug, sessionId, task, enableBus);
228
-
229
- // Reflection pass — pass full task object so verify-gate can check must_haves
230
- let reflectionResult = null;
231
- if (enableReflect && taskOutput && workerResult.ok) {
232
- reflectionResult = await reflect(taskOutput, {
233
- ...taskCtx,
234
- iteration: task._attempt || 1,
235
- task // enables must_haves verification
236
- });
237
-
238
- if (enableBus) {
239
- await bus.post(projectDir, squadSlug, sessionId, {
240
- from: task.executor || 'coordinator',
241
- to: '*',
242
- type: 'feedback',
243
- content: formatReport(reflectionResult, task.executor),
244
- metadata: { task_id: task.id, verdict: reflectionResult.verdict }
245
- }).catch(() => {});
246
- }
247
- }
248
-
249
- // Determine final status
250
- let finalStatus;
251
- if (!workerResult.ok) {
252
- finalStatus = 'failed';
253
- } else if (reflectionResult && reflectionResult.verdict === 'ESCALATE') {
254
- finalStatus = 'escalated';
255
- } else {
256
- finalStatus = 'completed';
257
- }
258
-
259
- await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, finalStatus, {
260
- worker_ran: workerRan,
261
- output_summary: String(taskOutput || '').slice(0, 500),
262
- reflection: reflectionResult
263
- ? { verdict: reflectionResult.verdict, score: reflectionResult.score }
264
- : null,
265
- completed_at: nowIso()
266
- });
267
-
268
- if (enableBus) {
269
- await bus.post(projectDir, squadSlug, sessionId, {
270
- from: task.executor || 'coordinator',
271
- to: '*',
272
- type: 'result',
273
- content: `${icon(finalStatus)} ${task.title} → ${finalStatus.toUpperCase()}${reflectionResult ? ` (reflection: ${reflectionResult.verdict})` : ''}`,
274
- metadata: { task_id: task.id, status: finalStatus }
275
- }).catch(() => {});
276
- }
277
-
278
- return { task, finalStatus, workerResult, reflectionResult };
279
- }
280
-
281
- // ─── Inter-squad dependency validation ───────────────────────────────────────
282
-
283
- /**
284
- * Validate inter-squad dependencies declared in manifest.depends_on.
285
- * Returns { satisfied: boolean, unmet: Array<{squad, event}> }
286
- */
287
- async function validateInterSquadDependencies(projectDir, manifest) {
288
- const deps = manifest.depends_on || [];
289
- if (deps.length === 0) return { satisfied: true, unmet: [] };
290
-
291
- const unmet = [];
292
- for (const dep of deps) {
293
- if (!dep.event) continue;
294
- try {
295
- const events = await interSquadEvents.consume(projectDir, {
296
- toSquad: manifest.slug,
297
- subscriptions: [dep.event]
298
- });
299
- if (events.length === 0) {
300
- unmet.push({ squad: dep.squad || '(unknown)', event: dep.event });
301
- }
302
- } catch {
303
- unmet.push({ squad: dep.squad || '(unknown)', event: dep.event });
304
- }
305
- }
306
-
307
- return { satisfied: unmet.length === 0, unmet };
308
- }
309
-
310
- // ─── Bus coordinator intelligence ────────────────────────────────────────────
311
-
312
- // ── Block classification helpers ─────────────────────────────────────────────
313
-
314
- function extractKeyName(content) {
315
- const m = content.match(/([A-Z_]{3,}_(?:KEY|TOKEN|SECRET|ID))/i);
316
- return m ? m[1].toUpperCase() : 'API key';
317
- }
318
-
319
- function extractMissingPath(content) {
320
- const m = content.match(/(?:file|path|found)[:\s]+([./\w-]+\.\w+)/i);
321
- return m ? m[1] : 'unknown file';
322
- }
323
-
324
- function extractDependencyId(content) {
325
- const m = content.match(/task[- _](\d{2})/i);
326
- return m ? `task-${m[1]}` : null;
327
- }
328
-
329
- function classifyBlock(content) {
330
- const c = String(content || '').toLowerCase();
331
- if (/api\s*key|credential|secret|token\b|\.env/.test(c)) return 'api_key';
332
- if (/file\s*not\s*found|no such file|enoent|missing file/.test(c)) return 'file_missing';
333
- if (/permission\s*denied|access\s*denied|forbidden|403/.test(c)) return 'permission';
334
- if (/timed?\s*out|etimedout|deadline|exceeded/.test(c)) return 'timeout';
335
- if (/depends\s*on|waiting\s*for|requires\s*task|blocked\s*by/.test(c)) return 'dependency';
336
- return 'generic';
337
- }
338
-
339
- /**
340
- * Strategy map: each strategy returns an { action, message, metadata } object.
341
- */
342
- const BLOCK_STRATEGIES = {
343
- api_key: (block, _ctx) => ({
344
- action: 'human-gate',
345
- message: `API key/credential required: ${extractKeyName(block.content)}. Add to .env and restart the session.`,
346
- metadata: { resolution: 'human_escalation', key_hint: extractKeyName(block.content) }
347
- }),
348
-
349
- file_missing: (block, ctx) => {
350
- const missingFile = extractMissingPath(block.content);
351
- const prevResults = (ctx.recentResults || []).filter((r) => r.includes('.') || r.includes('/'));
352
- const hint = prevResults.length > 0
353
- ? `Check if a previous task created it. Recent results: ${prevResults.slice(0, 2).join(' | ')}`
354
- : `Verify the file path and that the producing task ran successfully.`;
355
- return {
356
- action: 'retry-with-context',
357
- message: `File not found: ${missingFile}. ${hint}`,
358
- metadata: { resolution: 'context_hint', missing_file: missingFile }
359
- };
360
- },
361
-
362
- dependency: (block, _ctx) => {
363
- const depId = extractDependencyId(block.content);
364
- return {
365
- action: 'wait-and-retry',
366
- message: depId
367
- ? `Waiting for ${depId} to complete before proceeding.`
368
- : `Dependency not satisfied. Wait for upstream tasks to complete.`,
369
- metadata: { resolution: 'dependency_wait', dep_id: depId }
370
- };
371
- },
372
-
373
- permission: (_block, _ctx) => ({
374
- action: 'human-gate',
375
- message: 'Permission denied — this operation requires manual intervention or elevated access.',
376
- metadata: { resolution: 'human_escalation' }
377
- }),
378
-
379
- timeout: (_block, _ctx) => ({
380
- action: 'abort-and-escalate',
381
- message: 'Task exceeded its timeout. It may need to be decomposed into smaller steps.',
382
- metadata: { resolution: 'escalate_decompose' }
383
- }),
384
-
385
- generic: (block, ctx) => {
386
- const recentCtx = (ctx.recentResults || []).join('\n');
387
- return {
388
- action: 'coordinator-hint',
389
- message: `Coordinator attempting to resolve block. Try proceeding with available information.${recentCtx ? `\nContext from other executors:\n${recentCtx}` : ''}`,
390
- metadata: { resolution: 'coordinator_hint' }
391
- };
392
- }
393
- };
394
-
395
- /**
396
- * After each wave, inspect the bus for unresolved block messages and
397
- * attempt automatic resolution using the strategy pattern.
398
- *
399
- * Block types: api_key, file_missing, dependency, permission, timeout, generic
400
- * Actions: human-gate, retry-with-context, wait-and-retry, abort-and-escalate, coordinator-hint
401
- */
402
- async function handleBusBlocks(projectDir, squadSlug, sessionId, logger) {
403
- const allMessages = await bus.read(projectDir, squadSlug, sessionId).catch(() => []);
404
- const unresolved = getUnresolvedBlocks(allMessages);
405
-
406
- if (unresolved.length === 0) return;
407
-
408
- const recentResultMessages = allMessages
409
- .filter((m) => m.type === 'result')
410
- .slice(-3)
411
- .map((m) => `${m.from}: ${String(m.content || '').slice(0, 100)}`);
412
-
413
- for (const block of unresolved) {
414
- const blockType = classifyBlock(block.content);
415
- const strategy = BLOCK_STRATEGIES[blockType] || BLOCK_STRATEGIES.generic;
416
- const resolution = strategy(block, { recentResults: recentResultMessages });
417
-
418
- if (resolution.action === 'human-gate' || resolution.action === 'abort-and-escalate') {
419
- logger.log(` ⚠ Block [${blockType}] requires human attention: "${String(block.content || '').slice(0, 80)}"`);
420
- }
421
-
422
- await bus.post(projectDir, squadSlug, sessionId, {
423
- from: 'coordinator',
424
- to: block.from,
425
- type: 'resolution',
426
- content: resolution.message,
427
- metadata: { block_id: block.id, block_type: blockType, ...resolution.metadata }
428
- }).catch(() => {});
429
- }
430
- }
431
-
432
- // ─── Gap Closure Loop ─────────────────────────────────────────────────────────
433
-
434
- /**
435
- * Run a task with automatic retry on failure (gap closure).
436
- *
437
- * On failure:
438
- * 1. Capture the error as failure context
439
- * 2. Re-run the task with the failure context injected into workerInput
440
- * 3. Repeat up to maxRetries times
441
- * 4. If still failing after maxRetries: escalate
442
- *
443
- * ESCALATE results are NOT retried — they require coordinator/human attention.
444
- */
445
- async function runTaskWithGapClosure(
446
- projectDir, squadSlug, task, sessionId, options, logger,
447
- maxRetries = 3
448
- ) {
449
- const { enableBus } = options;
450
- let currentTask = { ...task, _attempt: 1 };
451
- let lastError = null;
452
-
453
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
454
- currentTask = { ...currentTask, _attempt: attempt };
455
-
456
- // Announce gap closure retry on bus (only from attempt 2 onwards)
457
- if (attempt > 1 && enableBus) {
458
- await bus.post(projectDir, squadSlug, sessionId, {
459
- from: 'coordinator',
460
- to: task.executor || '*',
461
- type: 'gap_closure_attempt',
462
- content: `Retrying "${task.title}" (attempt ${attempt}/${maxRetries}). Previous failure: ${lastError}`,
463
- metadata: { task_id: task.id, attempt, prev_error: lastError }
464
- }).catch(() => {});
465
- }
466
-
467
- // Run with heartbeat
468
- const result = await runTaskWithHeartbeat(
469
- projectDir, squadSlug, task, sessionId, options,
470
- () => runTask(projectDir, squadSlug, currentTask, sessionId, options, logger)
471
- );
472
-
473
- if (result.finalStatus === 'completed') {
474
- if (attempt > 1) {
475
- logger.log(` ↩ Gap closed after ${attempt} attempt(s)`);
476
- }
477
- return result;
478
- }
479
-
480
- // Don't retry escalated tasks — they need human/coordinator attention
481
- if (result.finalStatus === 'escalated') {
482
- return result;
483
- }
484
-
485
- // Capture failure context for next attempt
486
- lastError = result.workerResult?.error || `task failed on attempt ${attempt}`;
487
- currentTask = {
488
- ...currentTask,
489
- _failure_context: lastError
490
- };
491
-
492
- if (attempt < maxRetries) {
493
- logger.log(` ↩ Gap closure attempt ${attempt}/${maxRetries} failed — retrying with context`);
494
- }
495
- }
496
-
497
- // Exhausted retries — escalate
498
- logger.log(` ✗ Gap closure exhausted (${maxRetries} attempts) — escalating`);
499
-
500
- await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'escalated', {
501
- gap_closure_exhausted: true,
502
- last_error: lastError,
503
- completed_at: nowIso()
504
- });
505
-
506
- if (enableBus) {
507
- await bus.post(projectDir, squadSlug, sessionId, {
508
- from: 'coordinator',
509
- to: '*',
510
- type: 'block',
511
- content: `Task "${task.title}" escalated after ${maxRetries} gap closure attempts. Last error: ${lastError}`,
512
- metadata: { task_id: task.id, gap_closure_exhausted: true, attempts: maxRetries }
513
- }).catch(() => {});
514
- }
515
-
516
- return {
517
- task,
518
- finalStatus: 'escalated',
519
- workerResult: { ok: false, error: lastError, gap_closure_exhausted: true },
520
- reflectionResult: null
521
- };
522
- }
523
-
524
- // ─── Sampling-and-Voting (Plan 81 §Sprint 4) ────────────────────────────────
525
-
526
- /**
527
- * Synthesize votes from multiple worker instances.
528
- * Returns { consensus, winningOutput, allVotes }.
529
- *
530
- * Consensus is the fraction of instances that agree on the same status.
531
- * For completed tasks, compares output similarity via a simple hash.
532
- */
533
- function synthesizeVotes(votes) {
534
- const statusCounts = {};
535
- for (const v of votes) {
536
- const s = v.finalStatus || 'unknown';
537
- statusCounts[s] = (statusCounts[s] || 0) + 1;
538
- }
539
-
540
- let bestStatus = 'unknown';
541
- let bestCount = 0;
542
- for (const [s, count] of Object.entries(statusCounts)) {
543
- if (count > bestCount) { bestStatus = s; bestCount = count; }
544
- }
545
-
546
- const consensus = bestCount / votes.length;
547
- const winningVotes = votes.filter((v) => v.finalStatus === bestStatus);
548
-
549
- return {
550
- consensus,
551
- bestStatus,
552
- winningOutput: winningVotes[0],
553
- allVotes: votes.map((v) => ({
554
- finalStatus: v.finalStatus,
555
- outputSummary: String(v.workerResult?.output || '').slice(0, 200)
556
- }))
557
- };
558
- }
559
-
560
- /**
561
- * Run a task with sampling-and-voting for critical decisions.
562
- *
563
- * Spawns N instances of the same task in parallel, then synthesizes votes.
564
- * If consensus < threshold, escalates to human-gate.
565
- *
566
- * @param {object} task — task with voting config: { instances, threshold }
567
- * @param {number} instances — number of parallel instances (default: 3)
568
- * @param {number} threshold — minimum consensus fraction (default: 0.66)
569
- */
570
- async function runTaskWithVoting(
571
- projectDir, squadSlug, task, sessionId, options, logger,
572
- instances = 3, threshold = 0.66
573
- ) {
574
- const { enableBus } = options;
575
-
576
- if (enableBus) {
577
- await bus.post(projectDir, squadSlug, sessionId, {
578
- from: 'coordinator',
579
- to: '*',
580
- type: 'status',
581
- content: `Sampling-and-Voting: running ${instances} instances of "${task.title}"`,
582
- metadata: { task_id: task.id, voting: true, instances }
583
- }).catch(() => {});
584
- }
585
-
586
- // Spawn N instances in parallel
587
- const instancePromises = [];
588
- for (let i = 1; i <= instances; i++) {
589
- const instanceTask = { ...task, _attempt: 1, _voting_instance: i };
590
- instancePromises.push(
591
- runTaskWithHeartbeat(
592
- projectDir, squadSlug, instanceTask, sessionId, options,
593
- () => runTask(projectDir, squadSlug, instanceTask, sessionId, options, logger)
594
- ).catch((err) => ({
595
- task: instanceTask,
596
- finalStatus: 'failed',
597
- workerResult: { ok: false, error: err.message },
598
- reflectionResult: null
599
- }))
600
- );
601
- }
602
-
603
- const votes = await Promise.all(instancePromises);
604
- const result = synthesizeVotes(votes);
605
-
606
- if (enableBus) {
607
- await bus.post(projectDir, squadSlug, sessionId, {
608
- from: 'coordinator',
609
- to: '*',
610
- type: 'feedback',
611
- content: `Voting result for "${task.title}": consensus=${(result.consensus * 100).toFixed(0)}% status=${result.bestStatus} (${instances} instances)`,
612
- metadata: { task_id: task.id, consensus: result.consensus, bestStatus: result.bestStatus }
613
- }).catch(() => {});
614
- }
615
-
616
- // If consensus below threshold, escalate
617
- if (result.consensus < threshold) {
618
- logger.log(` ⚠ Voting: consensus ${(result.consensus * 100).toFixed(0)}% < ${(threshold * 100).toFixed(0)}% threshold — escalating`);
619
-
620
- await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'escalated', {
621
- voting: { consensus: result.consensus, threshold, allVotes: result.allVotes },
622
- completed_at: nowIso()
623
- });
624
-
625
- if (enableBus) {
626
- await bus.post(projectDir, squadSlug, sessionId, {
627
- from: 'coordinator',
628
- to: '*',
629
- type: 'block',
630
- content: `Task "${task.title}" — voting consensus too low (${(result.consensus * 100).toFixed(0)}%). Requires human review.`,
631
- metadata: { task_id: task.id, voting_escalated: true }
632
- }).catch(() => {});
633
- }
634
-
635
- return {
636
- task,
637
- finalStatus: 'escalated',
638
- workerResult: { ok: false, error: 'voting_consensus_below_threshold', voting: result },
639
- reflectionResult: null
640
- };
641
- }
642
-
643
- // Use the winning vote as the result
644
- return result.winningOutput;
645
- }
646
-
647
- // ─── Evaluator-Optimizer Loop (Plan 82 §ITEM 4) ──────────────────────────────
648
-
649
- /**
650
- * Run a task through an evaluator-optimizer loop (dev→qa→dev...):
651
- * 1. Generator phase: run the task as the implementer
652
- * 2. Evaluator phase: run a review task against criteria (fresh context)
653
- * 3. If PASS → done. If FAIL → inject structured feedback → repeat
654
- * 4. Max iterations before escalating to human
655
- *
656
- * The key: the evaluator receives only the artifact, not the generator's reasoning.
657
- * This prevents confirmation bias (same principle as verify-gate).
658
- */
659
- async function runWithEvalOptimize(
660
- projectDir, squadSlug, task, sessionId, options, logger,
661
- maxIterations = 3
662
- ) {
663
- const { enableBus } = options;
664
- let lastFeedback = null;
665
- let lastResult = null;
666
-
667
- if (enableBus) {
668
- await bus.post(projectDir, squadSlug, sessionId, {
669
- from: 'coordinator',
670
- to: '*',
671
- type: 'status',
672
- content: `Evaluator-Optimizer: starting loop for "${task.title}" (max ${maxIterations} iterations)`,
673
- metadata: { task_id: task.id, eval_optimize: true, max_iterations: maxIterations }
674
- }).catch(() => {});
675
- }
676
-
677
- for (let iteration = 1; iteration <= maxIterations; iteration++) {
678
- // ── Generator phase ──────────────────────────────────────────────────────
679
- const generatorTask = {
680
- ...task,
681
- _attempt: iteration,
682
- ...(lastFeedback ? { _eval_feedback: lastFeedback, _eval_iteration: iteration } : {})
683
- };
684
-
685
- lastResult = await runTaskWithHeartbeat(
686
- projectDir, squadSlug, generatorTask, sessionId, options,
687
- () => runTask(projectDir, squadSlug, generatorTask, sessionId, options, logger)
688
- );
689
-
690
- if (lastResult.finalStatus !== 'completed') {
691
- logger.log(` ↳ Eval-Optimize iteration ${iteration}: generator failed — escalating`);
692
- return lastResult;
693
- }
694
-
695
- // ── Evaluator phase ──────────────────────────────────────────────────────
696
- const reviewTask = {
697
- id: `${task.id}-review-${iteration}`,
698
- title: `Review: ${task.title} (iteration ${iteration})`,
699
- description: [
700
- `Evaluate the output of task "${task.title}".`,
701
- ``,
702
- `Criteria to check (ALL must pass):`,
703
- ...(task.review_criteria || []).map((c) => `- ${c}`),
704
- ``,
705
- `Output PASS if all criteria are met.`,
706
- `Output FAIL with structured feedback: specific file:line references, exact criterion violated, minimum change to pass.`,
707
- ``,
708
- `Do NOT consider how the implementer reasoned — evaluate only the artifact.`
709
- ].join('\n'),
710
- executor: task.reviewer || 'qa',
711
- acceptance_criteria: ['Output either PASS or FAIL with structured feedback'],
712
- _eval_artifact: lastResult.workerResult?.output || null
713
- };
714
-
715
- const evalResult = await runTaskWithHeartbeat(
716
- projectDir, squadSlug, reviewTask, sessionId, options,
717
- () => runTask(projectDir, squadSlug, reviewTask, sessionId, options, logger)
718
- );
719
-
720
- const evalOutput = String(evalResult.workerResult?.output || '');
721
- const passed = /\bPASS\b/i.test(evalOutput) && !/\bFAIL\b/i.test(evalOutput);
722
-
723
- if (enableBus) {
724
- await bus.post(projectDir, squadSlug, sessionId, {
725
- from: 'coordinator',
726
- to: '*',
727
- type: 'feedback',
728
- content: `Eval-Optimize iteration ${iteration}/${maxIterations}: ${passed ? 'PASS' : 'FAIL'} — ${evalOutput.slice(0, 120)}`,
729
- metadata: { task_id: task.id, iteration, verdict: passed ? 'PASS' : 'FAIL' }
730
- }).catch(() => {});
731
- }
732
-
733
- if (passed) {
734
- logger.log(` ↳ Eval-Optimize PASS at iteration ${iteration}`);
735
- await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'completed', {
736
- eval_optimize: { iterations: iteration, verdict: 'PASS' },
737
- completed_at: nowIso()
738
- });
739
- return lastResult;
740
- }
741
-
742
- lastFeedback = evalOutput.slice(0, 1000);
743
- logger.log(` ↳ Eval-Optimize FAIL at iteration ${iteration} — applying feedback`);
744
- }
745
-
746
- // Max iterations reached — escalate
747
- logger.log(` ✗ Eval-Optimize: ${maxIterations} iterations exhausted — escalating`);
748
-
749
- await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'escalated', {
750
- eval_optimize: { iterations: maxIterations, verdict: 'FAIL', last_feedback: lastFeedback },
751
- completed_at: nowIso()
752
- });
753
-
754
- if (enableBus) {
755
- await bus.post(projectDir, squadSlug, sessionId, {
756
- from: 'coordinator',
757
- to: '*',
758
- type: 'block',
759
- content: `Task "${task.title}" — eval-optimize loop exhausted (${maxIterations} iterations). Requires human review.`,
760
- metadata: { task_id: task.id, eval_optimize_exhausted: true }
761
- }).catch(() => {});
762
- }
763
-
764
- return {
765
- task,
766
- finalStatus: 'escalated',
767
- workerResult: { ok: false, error: 'eval_optimize_exhausted', last_feedback: lastFeedback },
768
- reflectionResult: null
769
- };
770
- }
771
-
772
- // ─── Main command ─────────────────────────────────────────────────────────────
773
-
774
- async function runSquadAutorun({ args, options = {}, logger }) {
775
- const targetDir = path.resolve(process.cwd(), args[0] || '.');
776
- const squadSlug = String(options.squad || options.s || '').trim();
777
-
778
- if (!squadSlug) {
779
- logger.error('Error: --squad is required');
780
- return { ok: false, error: 'missing_squad' };
781
- }
782
-
783
- const dryRun = Boolean(options['dry-run'] || options.dryRun);
784
- const enableBus = options.bus !== false && options.bus !== 'false';
785
- const enableReflect = Boolean(options.reflect);
786
- const sequential = Boolean(options.sequential);
787
- const mode = String(options.mode || 'heuristic').trim();
788
- const timeoutMs = (options.timeout ? Number(options.timeout) : 120) * 1000;
789
- const existingPlanId = String(options.plan || '').trim();
790
- const enableGapClosure = options['no-gap-closure'] !== true && options['no-gap-closure'] !== 'true';
791
- const maxRetries = Math.min(Math.max(Number(options['max-retries'] || 3), 1), 5);
792
- const requestedEngine = String(options.engine || 'legacy').trim();
793
- const ignoreDeps = Boolean(options['ignore-deps'] || options.ignoreDeps);
794
- const waitDeps = Boolean(options['wait-deps'] || options.waitDeps);
795
- const waitDepsTimeoutMs = (options['wait-deps-timeout'] ? Number(options['wait-deps-timeout']) : 60) * 1000;
796
-
797
- // ── Resolve execution engine (Plan 81 §1.1) ──────────────────────────────
798
- const engineResult = resolveEngine(requestedEngine);
799
- if (engineResult.fallback) {
800
- logger.log(`⚠ ${engineResult.reason} — falling back to legacy engine`);
801
- }
802
-
803
- // ── Load token budget ──────────────────────────────────────────────────────
804
- const budget = await loadBudget(targetDir, squadSlug);
805
- let sessionTokensUsed = 0;
806
- let budgetExceeded = false;
807
-
808
- // ── Load or create plan ────────────────────────────────────────────────────
809
- let plan;
810
- let sessionId;
811
-
812
- if (existingPlanId) {
813
- plan = await loadPlan(targetDir, squadSlug, existingPlanId);
814
- if (!plan) {
815
- logger.error(`Plan not found: session "${existingPlanId}" for squad "${squadSlug}"`);
816
- return { ok: false, error: 'plan_not_found' };
817
- }
818
- sessionId = existingPlanId;
819
- logger.log(`Resuming plan [${sessionId}] — ${plan.tasks.length} tasks`);
820
- } else {
821
- const goal = String(options.goal || '').trim();
822
- if (!goal) {
823
- logger.error('Error: --goal is required (or --plan to resume an existing plan)');
824
- return { ok: false, error: 'missing_goal' };
825
- }
826
-
827
- sessionId = randomUUID();
828
- logger.log(`Decomposing goal for squad "${squadSlug}" [${mode}]...`);
829
- plan = await decompose(targetDir, squadSlug, goal, { sessionId, mode, save: !dryRun });
830
- logger.log(`Plan ready: ${plan.tasks.length} tasks across ${Object.keys(plan.parallel_groups).length} parallel group(s)`);
831
- }
832
-
833
- // ── Show plan ──────────────────────────────────────────────────────────────
834
- if (options.json) {
835
- if (dryRun) return { ok: true, dryRun: true, plan };
836
- } else {
837
- logger.log('');
838
- logger.log(formatPlan(plan));
839
- logger.log('');
840
- }
841
-
842
- if (dryRun) {
843
- logger.log('[dry-run] Plan shown above. No tasks executed.');
844
- return { ok: true, dryRun: true, plan };
845
- }
846
-
847
- // ── Handle structured mode ─────────────────────────────────────────────────
848
- if (mode === 'structured' && plan.structured_prompt) {
849
- const promptPath = path.join(
850
- targetDir, '.aioson', 'squads', squadSlug, 'sessions', sessionId, 'decompose-prompt.md'
851
- );
852
- const promptContent = [
853
- '---',
854
- `session_id: ${sessionId}`,
855
- `squad: ${squadSlug}`,
856
- `created_at: ${plan.created_at}`,
857
- '---',
858
- '',
859
- plan.structured_prompt,
860
- '',
861
- '> After the agent fills in the JSON above, run:',
862
- `> aioson squad:autorun . --squad=${squadSlug} --plan=${sessionId}`
863
- ].join('\n');
864
-
865
- const { ensureDir } = require('../utils');
866
- await ensureDir(path.dirname(promptPath));
867
- await fs.writeFile(promptPath, promptContent, 'utf8');
868
-
869
- logger.log(`[structured] Decomposition prompt saved to: ${path.relative(targetDir, promptPath)}`);
870
- logger.log('Activate your agent to fill in the plan, then resume with:');
871
- logger.log(` aioson squad:autorun . --squad=${squadSlug} --plan=${sessionId}`);
872
- return { ok: true, mode: 'structured', sessionId, promptPath: path.relative(targetDir, promptPath), plan };
873
- }
874
-
875
- // ── Load squad manifest (for inter-squad config and hooks) ─────────────────
876
- let squadManifest = {};
877
- try {
878
- const manifestPath = path.join(targetDir, '.aioson', 'squads', squadSlug, 'squad.manifest.json');
879
- squadManifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
880
- } catch { /* manifest is optional */ }
881
-
882
- // ── Inter-squad dependency validation ─────────────────────────────────────
883
- if (!ignoreDeps && (squadManifest.depends_on || []).length > 0) {
884
- const depResult = await validateInterSquadDependencies(targetDir, squadManifest);
885
- if (!depResult.satisfied) {
886
- const depList = depResult.unmet.map((d) => `${d.squad}/${d.event}`).join(', ');
887
- if (waitDeps) {
888
- logger.log(`⏳ Waiting for inter-squad events: ${depList}`);
889
- const deadline = Date.now() + waitDepsTimeoutMs;
890
- let resolved = false;
891
- while (Date.now() < deadline) {
892
- await sleep(3000);
893
- const retry = await validateInterSquadDependencies(targetDir, squadManifest);
894
- if (retry.satisfied) { resolved = true; break; }
895
- }
896
- if (!resolved) {
897
- logger.error(`✗ Dependencies still unmet after ${waitDepsTimeoutMs / 1000}s: ${depList}`);
898
- return { ok: false, error: 'unmet_dependencies', unmet: depResult.unmet };
899
- }
900
- logger.log(' ✓ Dependencies satisfied');
901
- } else {
902
- logger.warn(`⚠ Unmet inter-squad dependencies: ${depList}`);
903
- logger.warn(' Use --ignore-deps to run anyway, or --wait-deps to poll until satisfied');
904
- return { ok: false, error: 'unmet_dependencies', unmet: depResult.unmet };
905
- }
906
- }
907
- }
908
-
909
- // ── 3.3 Hook Exit Code Protocol — pre_run hook ─────────────────────────────
910
- const preRunHook = squadManifest.hooks?.pre_run;
911
- if (preRunHook) {
912
- logger.log(`Running pre_run hook: ${preRunHook.slice(0, 60)}${preRunHook.length > 60 ? '...' : ''}`);
913
- const hookResult = runHook(preRunHook, {
914
- squad: squadSlug,
915
- session_id: sessionId,
916
- goal: plan.goal,
917
- project_dir: targetDir
918
- });
919
- if (hookResult.denied) {
920
- logger.error(`✗ Pre-run hook denied execution${hookResult.stderr ? ': ' + hookResult.stderr : ''}`);
921
- return { ok: false, error: 'hook_denied', hook: preRunHook, reason: hookResult.stderr };
922
- }
923
- if (hookResult.warn) {
924
- logger.log(` ⚠ Pre-run hook exited ${hookResult.exitCode} (non-fatal)${hookResult.stderr ? ': ' + hookResult.stderr : ''}`);
925
- } else {
926
- logger.log(' ✓ Pre-run hook passed');
927
- }
928
- }
929
-
930
- // ── 3.1 Inter-Squad Event Streaming — consume pending events ───────────────
931
- const subscriptions = [
932
- ...(squadManifest.subscriptions || []),
933
- ...(squadManifest.depends_on || []).map((d) => d.event).filter(Boolean)
934
- ];
935
- let incomingEvents = [];
936
- if (subscriptions.length > 0) {
937
- incomingEvents = await interSquadEvents
938
- .consume(targetDir, { toSquad: squadSlug, subscriptions })
939
- .catch(() => []);
940
- if (incomingEvents.length > 0) {
941
- logger.log(`Inter-squad events received: ${incomingEvents.length}`);
942
- for (const ev of incomingEvents) {
943
- logger.log(` ← [${ev.fromSquad}] ${ev.event}${ev.payload ? ' · ' + JSON.stringify(ev.payload).slice(0, 80) : ''}`);
944
- }
945
- logger.log('');
946
- }
947
- }
948
-
949
- // Inject incoming events into the plan goal context so executors are aware
950
- if (incomingEvents.length > 0 && plan.tasks.length > 0) {
951
- const firstTask = plan.tasks[0];
952
- const eventSummary = incomingEvents
953
- .map((e) => `[${e.fromSquad}] ${e.event}: ${JSON.stringify(e.payload || {})}`)
954
- .join('\n');
955
- firstTask._inter_squad_events = eventSummary;
956
- }
957
-
958
- // ── Record session start in STATE.md ───────────────────────────────────────
959
- await stateManager.recordSessionStart(targetDir, squadSlug, sessionId, plan.goal).catch(() => {});
960
-
961
- // ── Agent Teams engine path (Plan 81 §1.1) ────────────────────────────────
962
- if (engineResult.engine === 'agent-teams') {
963
- logger.log(`Engine: agent-teams (Claude Code ${engineResult.version})`);
964
- const teamConfig = translateToTeamConfig(targetDir, squadManifest, plan, {
965
- budget, enableBus
966
- });
967
- const configPath = await writeTeamConfig(targetDir, squadSlug, teamConfig);
968
- logger.log(`Team config: ${path.relative(targetDir, configPath)}`);
969
- logger.log(`Teammates: ${teamConfig.teammates.map((t) => t.name).join(', ')}`);
970
- logger.log(`Tasks: ${teamConfig.tasks.length}`);
971
- logger.log('');
972
- logger.log('Agent Teams execution is configured. Use:');
973
- logger.log(` claude --team ${path.relative(targetDir, configPath)}`);
974
- logger.log('');
975
-
976
- await stateManager.recordSessionEnd(targetDir, squadSlug, sessionId, []).catch(() => {});
977
-
978
- return {
979
- ok: true,
980
- engine: 'agent-teams',
981
- session_id: sessionId,
982
- squad: squadSlug,
983
- configPath: path.relative(targetDir, configPath),
984
- teamConfig
985
- };
986
- }
987
-
988
- // ── Execute tasks (legacy engine) ─────────────────────────────────────────
989
- logger.log(`Starting execution — session [${sessionId}]`);
990
- if (enableBus) logger.log('Intra-squad bus: enabled');
991
- if (enableReflect) logger.log('Reflection: enabled');
992
- if (enableGapClosure) logger.log(`Gap closure: enabled (max ${maxRetries} retries)`);
993
- if (budget.maxTokensPerSession !== Infinity) {
994
- logger.log(`Budget: ${budget.maxTokensPerSession.toLocaleString()} tokens/session`);
995
- }
996
- logger.log('');
997
-
998
- const results = [];
999
- let completedCount = 0;
1000
- let failedCount = 0;
1001
- let escalatedCount = 0;
1002
- const startedAt = Date.now();
1003
-
1004
- const runOptions = { enableBus, enableReflect, timeoutMs };
1005
-
1006
- // Run in parallel group waves (or sequentially if --sequential)
1007
- const groups = Object.keys(plan.parallel_groups).map(Number).sort((a, b) => a - b);
1008
-
1009
- for (const group of groups) {
1010
- if (budgetExceeded) {
1011
- logger.log(`⚠ Session budget exceeded (${sessionTokensUsed.toLocaleString()} tokens used). Stopping.`);
1012
- break;
1013
- }
1014
-
1015
- const groupTaskIds = plan.parallel_groups[group];
1016
- const groupTasks = groupTaskIds
1017
- .map((id) => plan.tasks.find((t) => t.id === id))
1018
- .filter((t) => t && t.status === 'pending');
1019
-
1020
- if (groupTasks.length === 0) continue;
1021
-
1022
- logger.log(`── Group ${group} (${groupTasks.length} task${groupTasks.length > 1 ? 's' : ''})${groupTasks.length > 1 && !sequential ? ' — running in parallel' : ''}`);
1023
-
1024
- // ── Budget gate: check before running this group ────────────────────────
1025
- const groupEstimatedTokens = groupTasks.reduce((sum, t) => sum + estimateTaskTokens(t), 0);
1026
- if (sessionTokensUsed + groupEstimatedTokens > budget.maxTokensPerSession) {
1027
- logger.log(` ⚠ Budget gate: estimated ${(sessionTokensUsed + groupEstimatedTokens).toLocaleString()} tokens would exceed session limit of ${budget.maxTokensPerSession.toLocaleString()}.`);
1028
- if (budget.actionOnExceed === 'abort') {
1029
- logger.log(' Budget action: abort — stopping execution.');
1030
- budgetExceeded = true;
1031
- break;
1032
- }
1033
- // Default: 'pause' — warn and continue (user can see in summary)
1034
- logger.log(' Budget action: pause — marking remaining tasks as skipped.');
1035
- for (const task of groupTasks) {
1036
- await updateTaskStatus(targetDir, squadSlug, sessionId, task.id, 'skipped', {
1037
- skip_reason: 'budget_exceeded',
1038
- estimated_tokens: estimateTaskTokens(task)
1039
- });
1040
- }
1041
- budgetExceeded = true;
1042
- break;
1043
- }
1044
-
1045
- // ── Run tasks in this group ────────────────────────────────────────────
1046
- const runTask_ = async (task) => {
1047
- // Brief validation guard (Plan 80 §1): validate brief before spawn
1048
- if (task.brief_path) {
1049
- const briefResult = await validateBrief(task.brief_path, targetDir);
1050
- if (!briefResult.ready) {
1051
- // Auto-fix simple fields (out_of_scope only)
1052
- if (briefResult.issues.length === 1 && briefResult.issues[0].field === 'out_of_scope') {
1053
- await autoFixBrief(task.brief_path, targetDir);
1054
- logger.log(` ↩ Auto-fixed brief for ${task.id} (out_of_scope)`);
1055
- } else {
1056
- if (enableBus) {
1057
- await bus.post(targetDir, squadSlug, sessionId, {
1058
- from: 'coordinator', to: '*', type: 'block',
1059
- content: `Brief NOT READY for ${task.id}: ${briefResult.issues.map((i) => i.message).join(', ')}`,
1060
- metadata: { task_id: task.id, brief_validation: briefResult }
1061
- }).catch(() => {});
1062
- }
1063
- logger.log(` ⚠ ${task.id}: brief NOT READY (${briefResult.issues.length} issues) — skipping`);
1064
- await updateTaskStatus(targetDir, squadSlug, sessionId, task.id, 'skipped', {
1065
- skip_reason: 'brief_not_ready', issues: briefResult.issues
1066
- });
1067
- return { task, finalStatus: 'skipped', workerResult: null, reflectionResult: null };
1068
- }
1069
- }
1070
- }
1071
-
1072
- logger.log(` ${icon('in_progress')} ${task.id}: ${task.title}`);
1073
-
1074
- // Sampling-and-Voting path (Plan 81 §Sprint 4)
1075
- if (task.voting) {
1076
- const votingInstances = task.voting.instances || 3;
1077
- const votingThreshold = task.voting.threshold || 0.66;
1078
- logger.log(` ↳ Voting: ${votingInstances} instances, threshold ${(votingThreshold * 100).toFixed(0)}%`);
1079
- const runner = runTaskWithVoting(
1080
- targetDir, squadSlug, task, sessionId, runOptions, logger,
1081
- votingInstances, votingThreshold
1082
- );
1083
- return runner.then((r) => {
1084
- logger.log(` ${icon(r.finalStatus)} ${task.id}: ${r.finalStatus.toUpperCase()}`);
1085
- return r;
1086
- });
1087
- }
1088
-
1089
- // Evaluator-Optimizer path (Plan 82 §ITEM 4)
1090
- if (task.review_loop) {
1091
- const maxReviewIter = task.max_review_iterations || 3;
1092
- logger.log(` ↳ Eval-Optimize: max ${maxReviewIter} iterations, reviewer=${task.reviewer || 'qa'}`);
1093
- return runWithEvalOptimize(
1094
- targetDir, squadSlug, task, sessionId, runOptions, logger, maxReviewIter
1095
- ).then((r) => {
1096
- logger.log(` ${icon(r.finalStatus)} ${task.id}: ${r.finalStatus.toUpperCase()}`);
1097
- return r;
1098
- });
1099
- }
1100
-
1101
- const runner = enableGapClosure
1102
- ? runTaskWithGapClosure(targetDir, squadSlug, task, sessionId, runOptions, logger, maxRetries)
1103
- : runTaskWithHeartbeat(targetDir, squadSlug, task, sessionId, runOptions,
1104
- () => runTask(targetDir, squadSlug, task, sessionId, runOptions, logger));
1105
- return runner.then((r) => {
1106
- logger.log(` ${icon(r.finalStatus)} ${task.id}: ${r.finalStatus.toUpperCase()}`);
1107
- return r;
1108
- });
1109
- };
1110
-
1111
- let groupResults;
1112
- if (sequential || groupTasks.length === 1) {
1113
- groupResults = [];
1114
- for (const task of groupTasks) {
1115
- groupResults.push(await runTask_(task));
1116
- }
1117
- } else {
1118
- groupResults = await Promise.all(groupTasks.map(runTask_));
1119
- }
1120
-
1121
- results.push(...groupResults);
1122
-
1123
- // Accumulate token usage estimate for budget tracking
1124
- for (const r of groupResults) {
1125
- sessionTokensUsed += estimateTaskTokens(r.task);
1126
- if (r.finalStatus === 'completed') completedCount++;
1127
- else if (r.finalStatus === 'failed') failedCount++;
1128
- else if (r.finalStatus === 'escalated') escalatedCount++;
1129
- }
1130
-
1131
- // Bus coordinator: resolve any unresolved blocks after this wave
1132
- if (enableBus) {
1133
- await handleBusBlocks(targetDir, squadSlug, sessionId, logger).catch(() => {});
1134
- }
1135
-
1136
- // Short pause between waves to allow bus writes to flush
1137
- if (groups.length > 1) await sleep(100);
1138
- }
1139
-
1140
- // ── Record session end in STATE.md ─────────────────────────────────────────
1141
- await stateManager.recordSessionEnd(targetDir, squadSlug, sessionId, results).catch(() => {});
1142
-
1143
- // ── 5.1 Automatic Learning Extraction ─────────────────────────────────────
1144
- if (completedCount > 0 || escalatedCount > 0) {
1145
- const allBusMessages = enableBus
1146
- ? await bus.read(targetDir, squadSlug, sessionId).catch(() => [])
1147
- : [];
1148
- const allReflections = results
1149
- .filter((r) => r.reflectionResult)
1150
- .map((r) => r.reflectionResult);
1151
-
1152
- const learnings = await extractLearnings(targetDir, squadSlug, sessionId, {
1153
- busMessages: allBusMessages,
1154
- taskResults: results,
1155
- reflectionReports: allReflections
1156
- }).catch(() => []);
1157
-
1158
- if (learnings.length > 0) {
1159
- // Persist learnings to per-agent memory files (Plan 81 §Sprint 4)
1160
- await persistAgentMemory(targetDir, squadSlug, learnings, results).catch(() => {});
1161
- // Will be shown in the summary section below
1162
- results._extractedLearnings = learnings.length;
1163
- }
1164
- }
1165
-
1166
- // ── Session summary ────────────────────────────────────────────────────────
1167
- const elapsed = Math.round((Date.now() - startedAt) / 1000);
1168
- const busSummary = enableBus
1169
- ? await bus.summary(targetDir, squadSlug, sessionId).catch(() => null)
1170
- : null;
1171
-
1172
- const summary = {
1173
- ok: failedCount === 0 && escalatedCount === 0,
1174
- session_id: sessionId,
1175
- squad: squadSlug,
1176
- goal: plan.goal,
1177
- elapsed_s: elapsed,
1178
- budget_used: sessionTokensUsed,
1179
- budget_limit: budget.maxTokensPerSession,
1180
- tasks: {
1181
- total: plan.tasks.length,
1182
- completed: completedCount,
1183
- failed: failedCount,
1184
- escalated: escalatedCount
1185
- },
1186
- bus: busSummary
1187
- ? { total_messages: busSummary.total, blocks: busSummary.blocks.length }
1188
- : null
1189
- };
1190
-
1191
- if (options.json) return summary;
1192
-
1193
- logger.log('');
1194
- logger.log('── Autorun complete ─────────────────────────────────────────');
1195
- logger.log(`Session: ${sessionId}`);
1196
- logger.log(`Elapsed: ${elapsed}s`);
1197
- logger.log(`Tasks: ${completedCount}/${plan.tasks.length} completed ${failedCount > 0 ? `| ${failedCount} failed` : ''} ${escalatedCount > 0 ? `| ${escalatedCount} escalated` : ''}`);
1198
- if (budget.maxTokensPerSession !== Infinity) {
1199
- logger.log(`Tokens: ~${sessionTokensUsed.toLocaleString()} used / ${budget.maxTokensPerSession.toLocaleString()} budget`);
1200
- }
1201
- if (busSummary && busSummary.total > 0) {
1202
- logger.log(`Bus: ${busSummary.total} messages${busSummary.blocks.length > 0 ? ` | ⚠ ${busSummary.blocks.length} block(s)` : ''}`);
1203
- }
1204
- if (escalatedCount > 0) {
1205
- logger.log('');
1206
- logger.log('⚠ Escalated tasks require coordinator attention:');
1207
- for (const r of results.filter((r) => r.finalStatus === 'escalated')) {
1208
- const exhausted = r.workerResult?.gap_closure_exhausted ? ' (gap closure exhausted)' : '';
1209
- logger.log(` ${r.task.id}: ${r.task.title}${exhausted}`);
1210
- }
1211
- }
1212
- logger.log('');
1213
- logger.log(`Plan: .aioson/squads/${squadSlug}/sessions/${sessionId}/plan.json`);
1214
- logger.log(`State: .aioson/squads/${squadSlug}/STATE.md`);
1215
- if (enableBus) logger.log(`Bus: .aioson/squads/${squadSlug}/sessions/${sessionId}/bus.jsonl`);
1216
-
1217
- return summary;
1218
- }
1219
-
1220
- module.exports = { runSquadAutorun };
1
+ 'use strict';
2
+
3
+ /**
4
+ * aioson squad:autorun — Autonomous squad execution
5
+ *
6
+ * Given a high-level goal, this command:
7
+ * 1. Decomposes the goal into a task plan (heuristic or structured)
8
+ * 2. Activates the intra-squad bus for real-time communication
9
+ * 3. Runs each task through the worker-runner with optional reflection
10
+ * 4. Coordinator monitors the bus for blocks or feedback
11
+ * 5. Reports the final session summary
12
+ *
13
+ * Phase 1 additions:
14
+ * - Gap Closure Loop: failed tasks are retried up to 3x with failure context
15
+ * - Budget Gating: halts before a task if session token budget is exceeded
16
+ * - Heartbeat Protocol: posts bus heartbeat every 30s during long tasks
17
+ * - Anti-Analysis-Loop Guard: warns executor if N+ status without result
18
+ * - Squad STATE.md: cross-session memory updated at start/end
19
+ *
20
+ * Usage:
21
+ * aioson squad:autorun . --squad=content-team --goal="Create 3 podcast episodes"
22
+ * aioson squad:autorun . --squad=content-team --goal="..." --reflect --bus --mode=structured
23
+ * aioson squad:autorun . --squad=content-team --plan=SESSION_ID (resume from saved plan)
24
+ * aioson squad:autorun . --squad=content-team --plan=SESSION_ID --dry-run
25
+ *
26
+ * Flags:
27
+ * --goal High-level objective (required unless --plan is given)
28
+ * --reflect Run reflection after each task (default: false)
29
+ * --bus Enable intra-bus for inter-executor communication (default: true)
30
+ * --mode Decomposition mode: heuristic (default) | structured
31
+ * --plan Resume from existing session plan (session ID)
32
+ * --dry-run Show plan without executing
33
+ * --sequential Force sequential execution even for independent tasks (default: false)
34
+ * --timeout Per-task timeout in seconds (default: 120)
35
+ * --max-retries Gap closure max retry attempts (default: 3)
36
+ * --no-gap-closure Disable automatic retry on task failure
37
+ */
38
+
39
+ const fs = require('node:fs/promises');
40
+ const path = require('node:path');
41
+ const { randomUUID } = require('node:crypto');
42
+ const {
43
+ decompose,
44
+ getReadyTasks,
45
+ isPlanComplete,
46
+ updateTaskStatus,
47
+ loadPlan,
48
+ formatPlan
49
+ } = require('../squad/task-decomposer');
50
+ const bus = require('../squad/intra-bus');
51
+ const { reflect, formatReport } = require('../squad/reflection');
52
+ const { runWorker, listWorkers } = require('../worker-runner');
53
+ const stateManager = require('../squad/state-manager');
54
+ const { getUnresolvedBlocks } = require('../squad/intra-bus');
55
+ const interSquadEvents = require('../squad/inter-squad-events');
56
+ const { runHook, HOOK_DENY } = require('../lib/hook-protocol');
57
+ const { extractLearnings, persistAgentMemory } = require('../squad/learning-extractor');
58
+ const { validateBrief, autoFixBrief } = require('../squad/brief-validator');
59
+ const { resolveEngine, translateToTeamConfig, writeTeamConfig } = require('../squad/agent-teams-adapter');
60
+
61
+ const STATUS_ICON = {
62
+ pending: '○',
63
+ in_progress: '●',
64
+ completed: '✓',
65
+ failed: '✗',
66
+ escalated: '⚠',
67
+ skipped: '–'
68
+ };
69
+
70
+ function icon(status) {
71
+ return STATUS_ICON[status] || '?';
72
+ }
73
+
74
+ function nowIso() { return new Date().toISOString(); }
75
+
76
+ function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }
77
+
78
+ // ─── Budget helpers ───────────────────────────────────────────────────────────
79
+
80
+ /**
81
+ * Load token budget from squad manifest (optional field).
82
+ * Returns Infinity if not configured.
83
+ */
84
+ async function loadBudget(projectDir, squadSlug) {
85
+ const manifestPath = path.join(
86
+ projectDir, '.aioson', 'squads', squadSlug, 'squad.manifest.json'
87
+ );
88
+ try {
89
+ const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
90
+ const budget = manifest.budget || {};
91
+ return {
92
+ maxTokensPerSession: budget.max_tokens_per_session || Infinity,
93
+ maxTokensPerTask: budget.max_tokens_per_task || Infinity,
94
+ actionOnExceed: budget.action_on_exceed || 'pause'
95
+ };
96
+ } catch {
97
+ return { maxTokensPerSession: Infinity, maxTokensPerTask: Infinity, actionOnExceed: 'pause' };
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Estimate tokens a task will consume (heuristic: chars/4 + overhead).
103
+ */
104
+ function estimateTaskTokens(task) {
105
+ const descLen = (task.description || '').length;
106
+ const criteriaLen = (task.acceptance_criteria || []).join(' ').length;
107
+ return Math.ceil((descLen + criteriaLen) / 4) + 500; // 500 base overhead
108
+ }
109
+
110
+ // ─── Heartbeat wrapper ────────────────────────────────────────────────────────
111
+
112
+ /**
113
+ * Run a task with heartbeat pulses on the bus every 30s.
114
+ * Clears the interval on task completion/failure regardless.
115
+ */
116
+ async function runTaskWithHeartbeat(projectDir, squadSlug, task, sessionId, options, runFn) {
117
+ const { enableBus } = options;
118
+ const startMs = Date.now();
119
+
120
+ let hbInterval = null;
121
+ if (enableBus) {
122
+ hbInterval = setInterval(async () => {
123
+ const elapsed = Math.round((Date.now() - startMs) / 1000);
124
+ await bus.post(projectDir, squadSlug, sessionId, {
125
+ from: 'coordinator',
126
+ to: '*',
127
+ type: 'heartbeat',
128
+ content: `${task.title} — ${elapsed}s elapsed`,
129
+ metadata: { task_id: task.id, elapsed_s: elapsed }
130
+ }).catch(() => {});
131
+ }, 30_000);
132
+ }
133
+
134
+ try {
135
+ return await runFn();
136
+ } finally {
137
+ if (hbInterval) clearInterval(hbInterval);
138
+ }
139
+ }
140
+
141
+ // ─── Anti-analysis-loop guard ─────────────────────────────────────────────────
142
+
143
+ /**
144
+ * Check if an executor appears to be in an analysis loop.
145
+ * Posts a coordinator feedback message if the threshold is exceeded.
146
+ */
147
+ async function checkAntiLoop(projectDir, squadSlug, sessionId, task, enableBus, threshold = 8) {
148
+ if (!enableBus || !task.executor) return;
149
+
150
+ const messages = await bus.read(projectDir, squadSlug, sessionId).catch(() => []);
151
+ if (bus.isAnalysisLoop(messages, task.executor, threshold)) {
152
+ await bus.post(projectDir, squadSlug, sessionId, {
153
+ from: 'coordinator',
154
+ to: task.executor,
155
+ type: 'feedback',
156
+ content: `Analysis loop detected for "${task.title}". You have posted ${threshold}+ status updates without a result. Stop analyzing — produce concrete output now, or post a "block" message explaining why you cannot proceed.`,
157
+ metadata: { task_id: task.id, anti_loop: true }
158
+ }).catch(() => {});
159
+ }
160
+ }
161
+
162
+ // ─── Core task runner ─────────────────────────────────────────────────────────
163
+
164
+ /**
165
+ * Run a single task (no retry logic here — handled by gap closure wrapper).
166
+ */
167
+ async function runTask(projectDir, squadSlug, task, sessionId, options, logger) {
168
+ const { enableBus, enableReflect, timeoutMs } = options;
169
+ const taskCtx = {
170
+ projectDir,
171
+ squadSlug,
172
+ executorSlug: task.executor || 'unknown',
173
+ taskTitle: task.title,
174
+ iteration: task._attempt || 1
175
+ };
176
+
177
+ // Post status to bus
178
+ if (enableBus) {
179
+ await bus.post(projectDir, squadSlug, sessionId, {
180
+ from: task.executor || 'coordinator',
181
+ to: '*',
182
+ type: 'status',
183
+ content: `Starting: ${task.title}${task._attempt > 1 ? ` (retry ${task._attempt})` : ''}`,
184
+ metadata: { task_id: task.id, attempt: task._attempt || 1 }
185
+ }).catch(() => {});
186
+ }
187
+
188
+ await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'in_progress');
189
+
190
+ // Build worker input with fresh context pointers (2.2: paths, not inline content)
191
+ const workerInput = {
192
+ task_id: task.id,
193
+ title: task.title,
194
+ description: task.description,
195
+ acceptance_criteria: task.acceptance_criteria,
196
+ read_first_hints: task.read_first_hints || [], // executor reads these, not coordinator
197
+ must_haves: task.must_haves || null,
198
+ session_id: sessionId,
199
+ bus_enabled: enableBus,
200
+ ...(task._failure_context ? { failure_context: task._failure_context, attempt: task._attempt } : {})
201
+ };
202
+
203
+ let workerResult = null;
204
+ let taskOutput = null;
205
+ let workerRan = false;
206
+
207
+ const workers = await listWorkers(projectDir, squadSlug);
208
+ const workerConfig = workers.find(
209
+ (w) => w.slug === task.executor || w.slug === task.id
210
+ );
211
+
212
+ if (workerConfig) {
213
+ workerRan = true;
214
+ workerResult = await runWorker(projectDir, squadSlug, workerConfig.slug, workerInput, {
215
+ timeoutMs,
216
+ triggerType: 'autorun'
217
+ });
218
+ taskOutput = workerResult.ok
219
+ ? JSON.stringify(workerResult.output || '')
220
+ : `Worker failed: ${workerResult.error}`;
221
+ } else {
222
+ taskOutput = `[no-worker-script] Task "${task.title}" assigned to executor "${task.executor}". Run manually or scaffold a worker with: aioson squad:worker --squad=${squadSlug} create --slug=${task.executor}`;
223
+ workerResult = { ok: true, output: { message: taskOutput }, noScript: true };
224
+ }
225
+
226
+ // Anti-analysis-loop check after task runs
227
+ await checkAntiLoop(projectDir, squadSlug, sessionId, task, enableBus);
228
+
229
+ // Reflection pass — pass full task object so verify-gate can check must_haves
230
+ let reflectionResult = null;
231
+ if (enableReflect && taskOutput && workerResult.ok) {
232
+ reflectionResult = await reflect(taskOutput, {
233
+ ...taskCtx,
234
+ iteration: task._attempt || 1,
235
+ task // enables must_haves verification
236
+ });
237
+
238
+ if (enableBus) {
239
+ await bus.post(projectDir, squadSlug, sessionId, {
240
+ from: task.executor || 'coordinator',
241
+ to: '*',
242
+ type: 'feedback',
243
+ content: formatReport(reflectionResult, task.executor),
244
+ metadata: { task_id: task.id, verdict: reflectionResult.verdict }
245
+ }).catch(() => {});
246
+ }
247
+ }
248
+
249
+ // Determine final status
250
+ let finalStatus;
251
+ if (!workerResult.ok) {
252
+ finalStatus = 'failed';
253
+ } else if (reflectionResult && reflectionResult.verdict === 'ESCALATE') {
254
+ finalStatus = 'escalated';
255
+ } else {
256
+ finalStatus = 'completed';
257
+ }
258
+
259
+ await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, finalStatus, {
260
+ worker_ran: workerRan,
261
+ output_summary: String(taskOutput || '').slice(0, 500),
262
+ reflection: reflectionResult
263
+ ? { verdict: reflectionResult.verdict, score: reflectionResult.score }
264
+ : null,
265
+ completed_at: nowIso()
266
+ });
267
+
268
+ if (enableBus) {
269
+ await bus.post(projectDir, squadSlug, sessionId, {
270
+ from: task.executor || 'coordinator',
271
+ to: '*',
272
+ type: 'result',
273
+ content: `${icon(finalStatus)} ${task.title} → ${finalStatus.toUpperCase()}${reflectionResult ? ` (reflection: ${reflectionResult.verdict})` : ''}`,
274
+ metadata: { task_id: task.id, status: finalStatus }
275
+ }).catch(() => {});
276
+ }
277
+
278
+ return { task, finalStatus, workerResult, reflectionResult };
279
+ }
280
+
281
+ // ─── Inter-squad dependency validation ───────────────────────────────────────
282
+
283
+ /**
284
+ * Validate inter-squad dependencies declared in manifest.depends_on.
285
+ * Returns { satisfied: boolean, unmet: Array<{squad, event}> }
286
+ */
287
+ async function validateInterSquadDependencies(projectDir, manifest) {
288
+ const deps = manifest.depends_on || [];
289
+ if (deps.length === 0) return { satisfied: true, unmet: [] };
290
+
291
+ const unmet = [];
292
+ for (const dep of deps) {
293
+ if (!dep.event) continue;
294
+ try {
295
+ const events = await interSquadEvents.consume(projectDir, {
296
+ toSquad: manifest.slug,
297
+ subscriptions: [dep.event]
298
+ });
299
+ if (events.length === 0) {
300
+ unmet.push({ squad: dep.squad || '(unknown)', event: dep.event });
301
+ }
302
+ } catch {
303
+ unmet.push({ squad: dep.squad || '(unknown)', event: dep.event });
304
+ }
305
+ }
306
+
307
+ return { satisfied: unmet.length === 0, unmet };
308
+ }
309
+
310
+ // ─── Bus coordinator intelligence ────────────────────────────────────────────
311
+
312
+ // ── Block classification helpers ─────────────────────────────────────────────
313
+
314
+ function extractKeyName(content) {
315
+ const m = content.match(/([A-Z_]{3,}_(?:KEY|TOKEN|SECRET|ID))/i);
316
+ return m ? m[1].toUpperCase() : 'API key';
317
+ }
318
+
319
+ function extractMissingPath(content) {
320
+ const m = content.match(/(?:file|path|found)[:\s]+([./\w-]+\.\w+)/i);
321
+ return m ? m[1] : 'unknown file';
322
+ }
323
+
324
+ function extractDependencyId(content) {
325
+ const m = content.match(/task[- _](\d{2})/i);
326
+ return m ? `task-${m[1]}` : null;
327
+ }
328
+
329
+ function classifyBlock(content) {
330
+ const c = String(content || '').toLowerCase();
331
+ if (/api\s*key|credential|secret|token\b|\.env/.test(c)) return 'api_key';
332
+ if (/file\s*not\s*found|no such file|enoent|missing file/.test(c)) return 'file_missing';
333
+ if (/permission\s*denied|access\s*denied|forbidden|403/.test(c)) return 'permission';
334
+ if (/timed?\s*out|etimedout|deadline|exceeded/.test(c)) return 'timeout';
335
+ if (/depends\s*on|waiting\s*for|requires\s*task|blocked\s*by/.test(c)) return 'dependency';
336
+ return 'generic';
337
+ }
338
+
339
+ /**
340
+ * Strategy map: each strategy returns an { action, message, metadata } object.
341
+ */
342
+ const BLOCK_STRATEGIES = {
343
+ api_key: (block, _ctx) => ({
344
+ action: 'human-gate',
345
+ message: `API key/credential required: ${extractKeyName(block.content)}. Add to .env and restart the session.`,
346
+ metadata: { resolution: 'human_escalation', key_hint: extractKeyName(block.content) }
347
+ }),
348
+
349
+ file_missing: (block, ctx) => {
350
+ const missingFile = extractMissingPath(block.content);
351
+ const prevResults = (ctx.recentResults || []).filter((r) => r.includes('.') || r.includes('/'));
352
+ const hint = prevResults.length > 0
353
+ ? `Check if a previous task created it. Recent results: ${prevResults.slice(0, 2).join(' | ')}`
354
+ : `Verify the file path and that the producing task ran successfully.`;
355
+ return {
356
+ action: 'retry-with-context',
357
+ message: `File not found: ${missingFile}. ${hint}`,
358
+ metadata: { resolution: 'context_hint', missing_file: missingFile }
359
+ };
360
+ },
361
+
362
+ dependency: (block, _ctx) => {
363
+ const depId = extractDependencyId(block.content);
364
+ return {
365
+ action: 'wait-and-retry',
366
+ message: depId
367
+ ? `Waiting for ${depId} to complete before proceeding.`
368
+ : `Dependency not satisfied. Wait for upstream tasks to complete.`,
369
+ metadata: { resolution: 'dependency_wait', dep_id: depId }
370
+ };
371
+ },
372
+
373
+ permission: (_block, _ctx) => ({
374
+ action: 'human-gate',
375
+ message: 'Permission denied — this operation requires manual intervention or elevated access.',
376
+ metadata: { resolution: 'human_escalation' }
377
+ }),
378
+
379
+ timeout: (_block, _ctx) => ({
380
+ action: 'abort-and-escalate',
381
+ message: 'Task exceeded its timeout. It may need to be decomposed into smaller steps.',
382
+ metadata: { resolution: 'escalate_decompose' }
383
+ }),
384
+
385
+ generic: (block, ctx) => {
386
+ const recentCtx = (ctx.recentResults || []).join('\n');
387
+ return {
388
+ action: 'coordinator-hint',
389
+ message: `Coordinator attempting to resolve block. Try proceeding with available information.${recentCtx ? `\nContext from other executors:\n${recentCtx}` : ''}`,
390
+ metadata: { resolution: 'coordinator_hint' }
391
+ };
392
+ }
393
+ };
394
+
395
+ /**
396
+ * After each wave, inspect the bus for unresolved block messages and
397
+ * attempt automatic resolution using the strategy pattern.
398
+ *
399
+ * Block types: api_key, file_missing, dependency, permission, timeout, generic
400
+ * Actions: human-gate, retry-with-context, wait-and-retry, abort-and-escalate, coordinator-hint
401
+ */
402
+ async function handleBusBlocks(projectDir, squadSlug, sessionId, logger) {
403
+ const allMessages = await bus.read(projectDir, squadSlug, sessionId).catch(() => []);
404
+ const unresolved = getUnresolvedBlocks(allMessages);
405
+
406
+ if (unresolved.length === 0) return;
407
+
408
+ const recentResultMessages = allMessages
409
+ .filter((m) => m.type === 'result')
410
+ .slice(-3)
411
+ .map((m) => `${m.from}: ${String(m.content || '').slice(0, 100)}`);
412
+
413
+ for (const block of unresolved) {
414
+ const blockType = classifyBlock(block.content);
415
+ const strategy = BLOCK_STRATEGIES[blockType] || BLOCK_STRATEGIES.generic;
416
+ const resolution = strategy(block, { recentResults: recentResultMessages });
417
+
418
+ if (resolution.action === 'human-gate' || resolution.action === 'abort-and-escalate') {
419
+ logger.log(` ⚠ Block [${blockType}] requires human attention: "${String(block.content || '').slice(0, 80)}"`);
420
+ }
421
+
422
+ await bus.post(projectDir, squadSlug, sessionId, {
423
+ from: 'coordinator',
424
+ to: block.from,
425
+ type: 'resolution',
426
+ content: resolution.message,
427
+ metadata: { block_id: block.id, block_type: blockType, ...resolution.metadata }
428
+ }).catch(() => {});
429
+ }
430
+ }
431
+
432
+ // ─── Gap Closure Loop ─────────────────────────────────────────────────────────
433
+
434
+ /**
435
+ * Run a task with automatic retry on failure (gap closure).
436
+ *
437
+ * On failure:
438
+ * 1. Capture the error as failure context
439
+ * 2. Re-run the task with the failure context injected into workerInput
440
+ * 3. Repeat up to maxRetries times
441
+ * 4. If still failing after maxRetries: escalate
442
+ *
443
+ * ESCALATE results are NOT retried — they require coordinator/human attention.
444
+ */
445
+ async function runTaskWithGapClosure(
446
+ projectDir, squadSlug, task, sessionId, options, logger,
447
+ maxRetries = 3
448
+ ) {
449
+ const { enableBus } = options;
450
+ let currentTask = { ...task, _attempt: 1 };
451
+ let lastError = null;
452
+
453
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
454
+ currentTask = { ...currentTask, _attempt: attempt };
455
+
456
+ // Announce gap closure retry on bus (only from attempt 2 onwards)
457
+ if (attempt > 1 && enableBus) {
458
+ await bus.post(projectDir, squadSlug, sessionId, {
459
+ from: 'coordinator',
460
+ to: task.executor || '*',
461
+ type: 'gap_closure_attempt',
462
+ content: `Retrying "${task.title}" (attempt ${attempt}/${maxRetries}). Previous failure: ${lastError}`,
463
+ metadata: { task_id: task.id, attempt, prev_error: lastError }
464
+ }).catch(() => {});
465
+ }
466
+
467
+ // Run with heartbeat
468
+ const result = await runTaskWithHeartbeat(
469
+ projectDir, squadSlug, task, sessionId, options,
470
+ () => runTask(projectDir, squadSlug, currentTask, sessionId, options, logger)
471
+ );
472
+
473
+ if (result.finalStatus === 'completed') {
474
+ if (attempt > 1) {
475
+ logger.log(` ↩ Gap closed after ${attempt} attempt(s)`);
476
+ }
477
+ return result;
478
+ }
479
+
480
+ // Don't retry escalated tasks — they need human/coordinator attention
481
+ if (result.finalStatus === 'escalated') {
482
+ return result;
483
+ }
484
+
485
+ // Capture failure context for next attempt
486
+ lastError = result.workerResult?.error || `task failed on attempt ${attempt}`;
487
+ currentTask = {
488
+ ...currentTask,
489
+ _failure_context: lastError
490
+ };
491
+
492
+ if (attempt < maxRetries) {
493
+ logger.log(` ↩ Gap closure attempt ${attempt}/${maxRetries} failed — retrying with context`);
494
+ }
495
+ }
496
+
497
+ // Exhausted retries — escalate
498
+ logger.log(` ✗ Gap closure exhausted (${maxRetries} attempts) — escalating`);
499
+
500
+ await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'escalated', {
501
+ gap_closure_exhausted: true,
502
+ last_error: lastError,
503
+ completed_at: nowIso()
504
+ });
505
+
506
+ if (enableBus) {
507
+ await bus.post(projectDir, squadSlug, sessionId, {
508
+ from: 'coordinator',
509
+ to: '*',
510
+ type: 'block',
511
+ content: `Task "${task.title}" escalated after ${maxRetries} gap closure attempts. Last error: ${lastError}`,
512
+ metadata: { task_id: task.id, gap_closure_exhausted: true, attempts: maxRetries }
513
+ }).catch(() => {});
514
+ }
515
+
516
+ return {
517
+ task,
518
+ finalStatus: 'escalated',
519
+ workerResult: { ok: false, error: lastError, gap_closure_exhausted: true },
520
+ reflectionResult: null
521
+ };
522
+ }
523
+
524
+ // ─── Sampling-and-Voting (Plan 81 §Sprint 4) ────────────────────────────────
525
+
526
+ /**
527
+ * Synthesize votes from multiple worker instances.
528
+ * Returns { consensus, winningOutput, allVotes }.
529
+ *
530
+ * Consensus is the fraction of instances that agree on the same status.
531
+ * For completed tasks, compares output similarity via a simple hash.
532
+ */
533
+ function synthesizeVotes(votes) {
534
+ const statusCounts = {};
535
+ for (const v of votes) {
536
+ const s = v.finalStatus || 'unknown';
537
+ statusCounts[s] = (statusCounts[s] || 0) + 1;
538
+ }
539
+
540
+ let bestStatus = 'unknown';
541
+ let bestCount = 0;
542
+ for (const [s, count] of Object.entries(statusCounts)) {
543
+ if (count > bestCount) { bestStatus = s; bestCount = count; }
544
+ }
545
+
546
+ const consensus = bestCount / votes.length;
547
+ const winningVotes = votes.filter((v) => v.finalStatus === bestStatus);
548
+
549
+ return {
550
+ consensus,
551
+ bestStatus,
552
+ winningOutput: winningVotes[0],
553
+ allVotes: votes.map((v) => ({
554
+ finalStatus: v.finalStatus,
555
+ outputSummary: String(v.workerResult?.output || '').slice(0, 200)
556
+ }))
557
+ };
558
+ }
559
+
560
+ /**
561
+ * Run a task with sampling-and-voting for critical decisions.
562
+ *
563
+ * Spawns N instances of the same task in parallel, then synthesizes votes.
564
+ * If consensus < threshold, escalates to human-gate.
565
+ *
566
+ * @param {object} task — task with voting config: { instances, threshold }
567
+ * @param {number} instances — number of parallel instances (default: 3)
568
+ * @param {number} threshold — minimum consensus fraction (default: 0.66)
569
+ */
570
+ async function runTaskWithVoting(
571
+ projectDir, squadSlug, task, sessionId, options, logger,
572
+ instances = 3, threshold = 0.66
573
+ ) {
574
+ const { enableBus } = options;
575
+
576
+ if (enableBus) {
577
+ await bus.post(projectDir, squadSlug, sessionId, {
578
+ from: 'coordinator',
579
+ to: '*',
580
+ type: 'status',
581
+ content: `Sampling-and-Voting: running ${instances} instances of "${task.title}"`,
582
+ metadata: { task_id: task.id, voting: true, instances }
583
+ }).catch(() => {});
584
+ }
585
+
586
+ // Spawn N instances in parallel
587
+ const instancePromises = [];
588
+ for (let i = 1; i <= instances; i++) {
589
+ const instanceTask = { ...task, _attempt: 1, _voting_instance: i };
590
+ instancePromises.push(
591
+ runTaskWithHeartbeat(
592
+ projectDir, squadSlug, instanceTask, sessionId, options,
593
+ () => runTask(projectDir, squadSlug, instanceTask, sessionId, options, logger)
594
+ ).catch((err) => ({
595
+ task: instanceTask,
596
+ finalStatus: 'failed',
597
+ workerResult: { ok: false, error: err.message },
598
+ reflectionResult: null
599
+ }))
600
+ );
601
+ }
602
+
603
+ const votes = await Promise.all(instancePromises);
604
+ const result = synthesizeVotes(votes);
605
+
606
+ if (enableBus) {
607
+ await bus.post(projectDir, squadSlug, sessionId, {
608
+ from: 'coordinator',
609
+ to: '*',
610
+ type: 'feedback',
611
+ content: `Voting result for "${task.title}": consensus=${(result.consensus * 100).toFixed(0)}% status=${result.bestStatus} (${instances} instances)`,
612
+ metadata: { task_id: task.id, consensus: result.consensus, bestStatus: result.bestStatus }
613
+ }).catch(() => {});
614
+ }
615
+
616
+ // If consensus below threshold, escalate
617
+ if (result.consensus < threshold) {
618
+ logger.log(` ⚠ Voting: consensus ${(result.consensus * 100).toFixed(0)}% < ${(threshold * 100).toFixed(0)}% threshold — escalating`);
619
+
620
+ await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'escalated', {
621
+ voting: { consensus: result.consensus, threshold, allVotes: result.allVotes },
622
+ completed_at: nowIso()
623
+ });
624
+
625
+ if (enableBus) {
626
+ await bus.post(projectDir, squadSlug, sessionId, {
627
+ from: 'coordinator',
628
+ to: '*',
629
+ type: 'block',
630
+ content: `Task "${task.title}" — voting consensus too low (${(result.consensus * 100).toFixed(0)}%). Requires human review.`,
631
+ metadata: { task_id: task.id, voting_escalated: true }
632
+ }).catch(() => {});
633
+ }
634
+
635
+ return {
636
+ task,
637
+ finalStatus: 'escalated',
638
+ workerResult: { ok: false, error: 'voting_consensus_below_threshold', voting: result },
639
+ reflectionResult: null
640
+ };
641
+ }
642
+
643
+ // Use the winning vote as the result
644
+ return result.winningOutput;
645
+ }
646
+
647
+ // ─── Evaluator-Optimizer Loop (Plan 82 §ITEM 4) ──────────────────────────────
648
+
649
+ /**
650
+ * Run a task through an evaluator-optimizer loop (dev→qa→dev...):
651
+ * 1. Generator phase: run the task as the implementer
652
+ * 2. Evaluator phase: run a review task against criteria (fresh context)
653
+ * 3. If PASS → done. If FAIL → inject structured feedback → repeat
654
+ * 4. Max iterations before escalating to human
655
+ *
656
+ * The key: the evaluator receives only the artifact, not the generator's reasoning.
657
+ * This prevents confirmation bias (same principle as verify-gate).
658
+ */
659
+ async function runWithEvalOptimize(
660
+ projectDir, squadSlug, task, sessionId, options, logger,
661
+ maxIterations = 3
662
+ ) {
663
+ const { enableBus } = options;
664
+ let lastFeedback = null;
665
+ let lastResult = null;
666
+
667
+ if (enableBus) {
668
+ await bus.post(projectDir, squadSlug, sessionId, {
669
+ from: 'coordinator',
670
+ to: '*',
671
+ type: 'status',
672
+ content: `Evaluator-Optimizer: starting loop for "${task.title}" (max ${maxIterations} iterations)`,
673
+ metadata: { task_id: task.id, eval_optimize: true, max_iterations: maxIterations }
674
+ }).catch(() => {});
675
+ }
676
+
677
+ for (let iteration = 1; iteration <= maxIterations; iteration++) {
678
+ // ── Generator phase ──────────────────────────────────────────────────────
679
+ const generatorTask = {
680
+ ...task,
681
+ _attempt: iteration,
682
+ ...(lastFeedback ? { _eval_feedback: lastFeedback, _eval_iteration: iteration } : {})
683
+ };
684
+
685
+ lastResult = await runTaskWithHeartbeat(
686
+ projectDir, squadSlug, generatorTask, sessionId, options,
687
+ () => runTask(projectDir, squadSlug, generatorTask, sessionId, options, logger)
688
+ );
689
+
690
+ if (lastResult.finalStatus !== 'completed') {
691
+ logger.log(` ↳ Eval-Optimize iteration ${iteration}: generator failed — escalating`);
692
+ return lastResult;
693
+ }
694
+
695
+ // ── Evaluator phase ──────────────────────────────────────────────────────
696
+ const reviewTask = {
697
+ id: `${task.id}-review-${iteration}`,
698
+ title: `Review: ${task.title} (iteration ${iteration})`,
699
+ description: [
700
+ `Evaluate the output of task "${task.title}".`,
701
+ ``,
702
+ `Criteria to check (ALL must pass):`,
703
+ ...(task.review_criteria || []).map((c) => `- ${c}`),
704
+ ``,
705
+ `Output PASS if all criteria are met.`,
706
+ `Output FAIL with structured feedback: specific file:line references, exact criterion violated, minimum change to pass.`,
707
+ ``,
708
+ `Do NOT consider how the implementer reasoned — evaluate only the artifact.`
709
+ ].join('\n'),
710
+ executor: task.reviewer || 'qa',
711
+ acceptance_criteria: ['Output either PASS or FAIL with structured feedback'],
712
+ _eval_artifact: lastResult.workerResult?.output || null
713
+ };
714
+
715
+ const evalResult = await runTaskWithHeartbeat(
716
+ projectDir, squadSlug, reviewTask, sessionId, options,
717
+ () => runTask(projectDir, squadSlug, reviewTask, sessionId, options, logger)
718
+ );
719
+
720
+ const evalOutput = String(evalResult.workerResult?.output || '');
721
+ const passed = /\bPASS\b/i.test(evalOutput) && !/\bFAIL\b/i.test(evalOutput);
722
+
723
+ if (enableBus) {
724
+ await bus.post(projectDir, squadSlug, sessionId, {
725
+ from: 'coordinator',
726
+ to: '*',
727
+ type: 'feedback',
728
+ content: `Eval-Optimize iteration ${iteration}/${maxIterations}: ${passed ? 'PASS' : 'FAIL'} — ${evalOutput.slice(0, 120)}`,
729
+ metadata: { task_id: task.id, iteration, verdict: passed ? 'PASS' : 'FAIL' }
730
+ }).catch(() => {});
731
+ }
732
+
733
+ if (passed) {
734
+ logger.log(` ↳ Eval-Optimize PASS at iteration ${iteration}`);
735
+ await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'completed', {
736
+ eval_optimize: { iterations: iteration, verdict: 'PASS' },
737
+ completed_at: nowIso()
738
+ });
739
+ return lastResult;
740
+ }
741
+
742
+ lastFeedback = evalOutput.slice(0, 1000);
743
+ logger.log(` ↳ Eval-Optimize FAIL at iteration ${iteration} — applying feedback`);
744
+ }
745
+
746
+ // Max iterations reached — escalate
747
+ logger.log(` ✗ Eval-Optimize: ${maxIterations} iterations exhausted — escalating`);
748
+
749
+ await updateTaskStatus(projectDir, squadSlug, sessionId, task.id, 'escalated', {
750
+ eval_optimize: { iterations: maxIterations, verdict: 'FAIL', last_feedback: lastFeedback },
751
+ completed_at: nowIso()
752
+ });
753
+
754
+ if (enableBus) {
755
+ await bus.post(projectDir, squadSlug, sessionId, {
756
+ from: 'coordinator',
757
+ to: '*',
758
+ type: 'block',
759
+ content: `Task "${task.title}" — eval-optimize loop exhausted (${maxIterations} iterations). Requires human review.`,
760
+ metadata: { task_id: task.id, eval_optimize_exhausted: true }
761
+ }).catch(() => {});
762
+ }
763
+
764
+ return {
765
+ task,
766
+ finalStatus: 'escalated',
767
+ workerResult: { ok: false, error: 'eval_optimize_exhausted', last_feedback: lastFeedback },
768
+ reflectionResult: null
769
+ };
770
+ }
771
+
772
+ // ─── Main command ─────────────────────────────────────────────────────────────
773
+
774
+ async function runSquadAutorun({ args, options = {}, logger }) {
775
+ const targetDir = path.resolve(process.cwd(), args[0] || '.');
776
+ const squadSlug = String(options.squad || options.s || '').trim();
777
+
778
+ if (!squadSlug) {
779
+ logger.error('Error: --squad is required');
780
+ return { ok: false, error: 'missing_squad' };
781
+ }
782
+
783
+ const dryRun = Boolean(options['dry-run'] || options.dryRun);
784
+ const enableBus = options.bus !== false && options.bus !== 'false';
785
+ const enableReflect = Boolean(options.reflect);
786
+ const sequential = Boolean(options.sequential);
787
+ const mode = String(options.mode || 'heuristic').trim();
788
+ const timeoutMs = (options.timeout ? Number(options.timeout) : 120) * 1000;
789
+ const existingPlanId = String(options.plan || '').trim();
790
+ const enableGapClosure = options['no-gap-closure'] !== true && options['no-gap-closure'] !== 'true';
791
+ const maxRetries = Math.min(Math.max(Number(options['max-retries'] || 3), 1), 5);
792
+ const requestedEngine = String(options.engine || 'legacy').trim();
793
+ const ignoreDeps = Boolean(options['ignore-deps'] || options.ignoreDeps);
794
+ const waitDeps = Boolean(options['wait-deps'] || options.waitDeps);
795
+ const waitDepsTimeoutMs = (options['wait-deps-timeout'] ? Number(options['wait-deps-timeout']) : 60) * 1000;
796
+
797
+ // ── Resolve execution engine (Plan 81 §1.1) ──────────────────────────────
798
+ const engineResult = resolveEngine(requestedEngine);
799
+ if (engineResult.fallback) {
800
+ logger.log(`⚠ ${engineResult.reason} — falling back to legacy engine`);
801
+ }
802
+
803
+ // ── Load token budget ──────────────────────────────────────────────────────
804
+ const budget = await loadBudget(targetDir, squadSlug);
805
+ let sessionTokensUsed = 0;
806
+ let budgetExceeded = false;
807
+
808
+ // ── Load or create plan ────────────────────────────────────────────────────
809
+ let plan;
810
+ let sessionId;
811
+
812
+ if (existingPlanId) {
813
+ plan = await loadPlan(targetDir, squadSlug, existingPlanId);
814
+ if (!plan) {
815
+ logger.error(`Plan not found: session "${existingPlanId}" for squad "${squadSlug}"`);
816
+ return { ok: false, error: 'plan_not_found' };
817
+ }
818
+ sessionId = existingPlanId;
819
+ logger.log(`Resuming plan [${sessionId}] — ${plan.tasks.length} tasks`);
820
+ } else {
821
+ const goal = String(options.goal || '').trim();
822
+ if (!goal) {
823
+ logger.error('Error: --goal is required (or --plan to resume an existing plan)');
824
+ return { ok: false, error: 'missing_goal' };
825
+ }
826
+
827
+ sessionId = randomUUID();
828
+ logger.log(`Decomposing goal for squad "${squadSlug}" [${mode}]...`);
829
+ plan = await decompose(targetDir, squadSlug, goal, { sessionId, mode, save: !dryRun });
830
+ logger.log(`Plan ready: ${plan.tasks.length} tasks across ${Object.keys(plan.parallel_groups).length} parallel group(s)`);
831
+ }
832
+
833
+ // ── Show plan ──────────────────────────────────────────────────────────────
834
+ if (options.json) {
835
+ if (dryRun) return { ok: true, dryRun: true, plan };
836
+ } else {
837
+ logger.log('');
838
+ logger.log(formatPlan(plan));
839
+ logger.log('');
840
+ }
841
+
842
+ if (dryRun) {
843
+ logger.log('[dry-run] Plan shown above. No tasks executed.');
844
+ return { ok: true, dryRun: true, plan };
845
+ }
846
+
847
+ // ── Handle structured mode ─────────────────────────────────────────────────
848
+ if (mode === 'structured' && plan.structured_prompt) {
849
+ const promptPath = path.join(
850
+ targetDir, '.aioson', 'squads', squadSlug, 'sessions', sessionId, 'decompose-prompt.md'
851
+ );
852
+ const promptContent = [
853
+ '---',
854
+ `session_id: ${sessionId}`,
855
+ `squad: ${squadSlug}`,
856
+ `created_at: ${plan.created_at}`,
857
+ '---',
858
+ '',
859
+ plan.structured_prompt,
860
+ '',
861
+ '> After the agent fills in the JSON above, run:',
862
+ `> aioson squad:autorun . --squad=${squadSlug} --plan=${sessionId}`
863
+ ].join('\n');
864
+
865
+ const { ensureDir } = require('../utils');
866
+ await ensureDir(path.dirname(promptPath));
867
+ await fs.writeFile(promptPath, promptContent, 'utf8');
868
+
869
+ logger.log(`[structured] Decomposition prompt saved to: ${path.relative(targetDir, promptPath)}`);
870
+ logger.log('Activate your agent to fill in the plan, then resume with:');
871
+ logger.log(` aioson squad:autorun . --squad=${squadSlug} --plan=${sessionId}`);
872
+ return { ok: true, mode: 'structured', sessionId, promptPath: path.relative(targetDir, promptPath), plan };
873
+ }
874
+
875
+ // ── Load squad manifest (for inter-squad config and hooks) ─────────────────
876
+ let squadManifest = {};
877
+ try {
878
+ const manifestPath = path.join(targetDir, '.aioson', 'squads', squadSlug, 'squad.manifest.json');
879
+ squadManifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
880
+ } catch { /* manifest is optional */ }
881
+
882
+ // ── Inter-squad dependency validation ─────────────────────────────────────
883
+ if (!ignoreDeps && (squadManifest.depends_on || []).length > 0) {
884
+ const depResult = await validateInterSquadDependencies(targetDir, squadManifest);
885
+ if (!depResult.satisfied) {
886
+ const depList = depResult.unmet.map((d) => `${d.squad}/${d.event}`).join(', ');
887
+ if (waitDeps) {
888
+ logger.log(`⏳ Waiting for inter-squad events: ${depList}`);
889
+ const deadline = Date.now() + waitDepsTimeoutMs;
890
+ let resolved = false;
891
+ while (Date.now() < deadline) {
892
+ await sleep(3000);
893
+ const retry = await validateInterSquadDependencies(targetDir, squadManifest);
894
+ if (retry.satisfied) { resolved = true; break; }
895
+ }
896
+ if (!resolved) {
897
+ logger.error(`✗ Dependencies still unmet after ${waitDepsTimeoutMs / 1000}s: ${depList}`);
898
+ return { ok: false, error: 'unmet_dependencies', unmet: depResult.unmet };
899
+ }
900
+ logger.log(' ✓ Dependencies satisfied');
901
+ } else {
902
+ logger.warn(`⚠ Unmet inter-squad dependencies: ${depList}`);
903
+ logger.warn(' Use --ignore-deps to run anyway, or --wait-deps to poll until satisfied');
904
+ return { ok: false, error: 'unmet_dependencies', unmet: depResult.unmet };
905
+ }
906
+ }
907
+ }
908
+
909
+ // ── 3.3 Hook Exit Code Protocol — pre_run hook ─────────────────────────────
910
+ const preRunHook = squadManifest.hooks?.pre_run;
911
+ if (preRunHook) {
912
+ logger.log(`Running pre_run hook: ${preRunHook.slice(0, 60)}${preRunHook.length > 60 ? '...' : ''}`);
913
+ const hookResult = runHook(preRunHook, {
914
+ squad: squadSlug,
915
+ session_id: sessionId,
916
+ goal: plan.goal,
917
+ project_dir: targetDir
918
+ });
919
+ if (hookResult.denied) {
920
+ logger.error(`✗ Pre-run hook denied execution${hookResult.stderr ? ': ' + hookResult.stderr : ''}`);
921
+ return { ok: false, error: 'hook_denied', hook: preRunHook, reason: hookResult.stderr };
922
+ }
923
+ if (hookResult.warn) {
924
+ logger.log(` ⚠ Pre-run hook exited ${hookResult.exitCode} (non-fatal)${hookResult.stderr ? ': ' + hookResult.stderr : ''}`);
925
+ } else {
926
+ logger.log(' ✓ Pre-run hook passed');
927
+ }
928
+ }
929
+
930
+ // ── 3.1 Inter-Squad Event Streaming — consume pending events ───────────────
931
+ const subscriptions = [
932
+ ...(squadManifest.subscriptions || []),
933
+ ...(squadManifest.depends_on || []).map((d) => d.event).filter(Boolean)
934
+ ];
935
+ let incomingEvents = [];
936
+ if (subscriptions.length > 0) {
937
+ incomingEvents = await interSquadEvents
938
+ .consume(targetDir, { toSquad: squadSlug, subscriptions })
939
+ .catch(() => []);
940
+ if (incomingEvents.length > 0) {
941
+ logger.log(`Inter-squad events received: ${incomingEvents.length}`);
942
+ for (const ev of incomingEvents) {
943
+ logger.log(` ← [${ev.fromSquad}] ${ev.event}${ev.payload ? ' · ' + JSON.stringify(ev.payload).slice(0, 80) : ''}`);
944
+ }
945
+ logger.log('');
946
+ }
947
+ }
948
+
949
+ // Inject incoming events into the plan goal context so executors are aware
950
+ if (incomingEvents.length > 0 && plan.tasks.length > 0) {
951
+ const firstTask = plan.tasks[0];
952
+ const eventSummary = incomingEvents
953
+ .map((e) => `[${e.fromSquad}] ${e.event}: ${JSON.stringify(e.payload || {})}`)
954
+ .join('\n');
955
+ firstTask._inter_squad_events = eventSummary;
956
+ }
957
+
958
+ // ── Record session start in STATE.md ───────────────────────────────────────
959
+ await stateManager.recordSessionStart(targetDir, squadSlug, sessionId, plan.goal).catch(() => {});
960
+
961
+ // ── Agent Teams engine path (Plan 81 §1.1) ────────────────────────────────
962
+ if (engineResult.engine === 'agent-teams') {
963
+ logger.log(`Engine: agent-teams (Claude Code ${engineResult.version})`);
964
+ const teamConfig = translateToTeamConfig(targetDir, squadManifest, plan, {
965
+ budget, enableBus
966
+ });
967
+ const configPath = await writeTeamConfig(targetDir, squadSlug, teamConfig);
968
+ logger.log(`Team config: ${path.relative(targetDir, configPath)}`);
969
+ logger.log(`Teammates: ${teamConfig.teammates.map((t) => t.name).join(', ')}`);
970
+ logger.log(`Tasks: ${teamConfig.tasks.length}`);
971
+ logger.log('');
972
+ logger.log('Agent Teams execution is configured. Use:');
973
+ logger.log(` claude --team ${path.relative(targetDir, configPath)}`);
974
+ logger.log('');
975
+
976
+ await stateManager.recordSessionEnd(targetDir, squadSlug, sessionId, []).catch(() => {});
977
+
978
+ return {
979
+ ok: true,
980
+ engine: 'agent-teams',
981
+ session_id: sessionId,
982
+ squad: squadSlug,
983
+ configPath: path.relative(targetDir, configPath),
984
+ teamConfig
985
+ };
986
+ }
987
+
988
+ // ── Execute tasks (legacy engine) ─────────────────────────────────────────
989
+ logger.log(`Starting execution — session [${sessionId}]`);
990
+ if (enableBus) logger.log('Intra-squad bus: enabled');
991
+ if (enableReflect) logger.log('Reflection: enabled');
992
+ if (enableGapClosure) logger.log(`Gap closure: enabled (max ${maxRetries} retries)`);
993
+ if (budget.maxTokensPerSession !== Infinity) {
994
+ logger.log(`Budget: ${budget.maxTokensPerSession.toLocaleString()} tokens/session`);
995
+ }
996
+ logger.log('');
997
+
998
+ const results = [];
999
+ let completedCount = 0;
1000
+ let failedCount = 0;
1001
+ let escalatedCount = 0;
1002
+ const startedAt = Date.now();
1003
+
1004
+ const runOptions = { enableBus, enableReflect, timeoutMs };
1005
+
1006
+ // Run in parallel group waves (or sequentially if --sequential)
1007
+ const groups = Object.keys(plan.parallel_groups).map(Number).sort((a, b) => a - b);
1008
+
1009
+ for (const group of groups) {
1010
+ if (budgetExceeded) {
1011
+ logger.log(`⚠ Session budget exceeded (${sessionTokensUsed.toLocaleString()} tokens used). Stopping.`);
1012
+ break;
1013
+ }
1014
+
1015
+ const groupTaskIds = plan.parallel_groups[group];
1016
+ const groupTasks = groupTaskIds
1017
+ .map((id) => plan.tasks.find((t) => t.id === id))
1018
+ .filter((t) => t && t.status === 'pending');
1019
+
1020
+ if (groupTasks.length === 0) continue;
1021
+
1022
+ logger.log(`── Group ${group} (${groupTasks.length} task${groupTasks.length > 1 ? 's' : ''})${groupTasks.length > 1 && !sequential ? ' — running in parallel' : ''}`);
1023
+
1024
+ // ── Budget gate: check before running this group ────────────────────────
1025
+ const groupEstimatedTokens = groupTasks.reduce((sum, t) => sum + estimateTaskTokens(t), 0);
1026
+ if (sessionTokensUsed + groupEstimatedTokens > budget.maxTokensPerSession) {
1027
+ logger.log(` ⚠ Budget gate: estimated ${(sessionTokensUsed + groupEstimatedTokens).toLocaleString()} tokens would exceed session limit of ${budget.maxTokensPerSession.toLocaleString()}.`);
1028
+ if (budget.actionOnExceed === 'abort') {
1029
+ logger.log(' Budget action: abort — stopping execution.');
1030
+ budgetExceeded = true;
1031
+ break;
1032
+ }
1033
+ // Default: 'pause' — warn and continue (user can see in summary)
1034
+ logger.log(' Budget action: pause — marking remaining tasks as skipped.');
1035
+ for (const task of groupTasks) {
1036
+ await updateTaskStatus(targetDir, squadSlug, sessionId, task.id, 'skipped', {
1037
+ skip_reason: 'budget_exceeded',
1038
+ estimated_tokens: estimateTaskTokens(task)
1039
+ });
1040
+ }
1041
+ budgetExceeded = true;
1042
+ break;
1043
+ }
1044
+
1045
+ // ── Run tasks in this group ────────────────────────────────────────────
1046
+ const runTask_ = async (task) => {
1047
+ // Brief validation guard (Plan 80 §1): validate brief before spawn
1048
+ if (task.brief_path) {
1049
+ const briefResult = await validateBrief(task.brief_path, targetDir);
1050
+ if (!briefResult.ready) {
1051
+ // Auto-fix simple fields (out_of_scope only)
1052
+ if (briefResult.issues.length === 1 && briefResult.issues[0].field === 'out_of_scope') {
1053
+ await autoFixBrief(task.brief_path, targetDir);
1054
+ logger.log(` ↩ Auto-fixed brief for ${task.id} (out_of_scope)`);
1055
+ } else {
1056
+ if (enableBus) {
1057
+ await bus.post(targetDir, squadSlug, sessionId, {
1058
+ from: 'coordinator', to: '*', type: 'block',
1059
+ content: `Brief NOT READY for ${task.id}: ${briefResult.issues.map((i) => i.message).join(', ')}`,
1060
+ metadata: { task_id: task.id, brief_validation: briefResult }
1061
+ }).catch(() => {});
1062
+ }
1063
+ logger.log(` ⚠ ${task.id}: brief NOT READY (${briefResult.issues.length} issues) — skipping`);
1064
+ await updateTaskStatus(targetDir, squadSlug, sessionId, task.id, 'skipped', {
1065
+ skip_reason: 'brief_not_ready', issues: briefResult.issues
1066
+ });
1067
+ return { task, finalStatus: 'skipped', workerResult: null, reflectionResult: null };
1068
+ }
1069
+ }
1070
+ }
1071
+
1072
+ logger.log(` ${icon('in_progress')} ${task.id}: ${task.title}`);
1073
+
1074
+ // Sampling-and-Voting path (Plan 81 §Sprint 4)
1075
+ if (task.voting) {
1076
+ const votingInstances = task.voting.instances || 3;
1077
+ const votingThreshold = task.voting.threshold || 0.66;
1078
+ logger.log(` ↳ Voting: ${votingInstances} instances, threshold ${(votingThreshold * 100).toFixed(0)}%`);
1079
+ const runner = runTaskWithVoting(
1080
+ targetDir, squadSlug, task, sessionId, runOptions, logger,
1081
+ votingInstances, votingThreshold
1082
+ );
1083
+ return runner.then((r) => {
1084
+ logger.log(` ${icon(r.finalStatus)} ${task.id}: ${r.finalStatus.toUpperCase()}`);
1085
+ return r;
1086
+ });
1087
+ }
1088
+
1089
+ // Evaluator-Optimizer path (Plan 82 §ITEM 4)
1090
+ if (task.review_loop) {
1091
+ const maxReviewIter = task.max_review_iterations || 3;
1092
+ logger.log(` ↳ Eval-Optimize: max ${maxReviewIter} iterations, reviewer=${task.reviewer || 'qa'}`);
1093
+ return runWithEvalOptimize(
1094
+ targetDir, squadSlug, task, sessionId, runOptions, logger, maxReviewIter
1095
+ ).then((r) => {
1096
+ logger.log(` ${icon(r.finalStatus)} ${task.id}: ${r.finalStatus.toUpperCase()}`);
1097
+ return r;
1098
+ });
1099
+ }
1100
+
1101
+ const runner = enableGapClosure
1102
+ ? runTaskWithGapClosure(targetDir, squadSlug, task, sessionId, runOptions, logger, maxRetries)
1103
+ : runTaskWithHeartbeat(targetDir, squadSlug, task, sessionId, runOptions,
1104
+ () => runTask(targetDir, squadSlug, task, sessionId, runOptions, logger));
1105
+ return runner.then((r) => {
1106
+ logger.log(` ${icon(r.finalStatus)} ${task.id}: ${r.finalStatus.toUpperCase()}`);
1107
+ return r;
1108
+ });
1109
+ };
1110
+
1111
+ let groupResults;
1112
+ if (sequential || groupTasks.length === 1) {
1113
+ groupResults = [];
1114
+ for (const task of groupTasks) {
1115
+ groupResults.push(await runTask_(task));
1116
+ }
1117
+ } else {
1118
+ groupResults = await Promise.all(groupTasks.map(runTask_));
1119
+ }
1120
+
1121
+ results.push(...groupResults);
1122
+
1123
+ // Accumulate token usage estimate for budget tracking
1124
+ for (const r of groupResults) {
1125
+ sessionTokensUsed += estimateTaskTokens(r.task);
1126
+ if (r.finalStatus === 'completed') completedCount++;
1127
+ else if (r.finalStatus === 'failed') failedCount++;
1128
+ else if (r.finalStatus === 'escalated') escalatedCount++;
1129
+ }
1130
+
1131
+ // Bus coordinator: resolve any unresolved blocks after this wave
1132
+ if (enableBus) {
1133
+ await handleBusBlocks(targetDir, squadSlug, sessionId, logger).catch(() => {});
1134
+ }
1135
+
1136
+ // Short pause between waves to allow bus writes to flush
1137
+ if (groups.length > 1) await sleep(100);
1138
+ }
1139
+
1140
+ // ── Record session end in STATE.md ─────────────────────────────────────────
1141
+ await stateManager.recordSessionEnd(targetDir, squadSlug, sessionId, results).catch(() => {});
1142
+
1143
+ // ── 5.1 Automatic Learning Extraction ─────────────────────────────────────
1144
+ if (completedCount > 0 || escalatedCount > 0) {
1145
+ const allBusMessages = enableBus
1146
+ ? await bus.read(targetDir, squadSlug, sessionId).catch(() => [])
1147
+ : [];
1148
+ const allReflections = results
1149
+ .filter((r) => r.reflectionResult)
1150
+ .map((r) => r.reflectionResult);
1151
+
1152
+ const learnings = await extractLearnings(targetDir, squadSlug, sessionId, {
1153
+ busMessages: allBusMessages,
1154
+ taskResults: results,
1155
+ reflectionReports: allReflections
1156
+ }).catch(() => []);
1157
+
1158
+ if (learnings.length > 0) {
1159
+ // Persist learnings to per-agent memory files (Plan 81 §Sprint 4)
1160
+ await persistAgentMemory(targetDir, squadSlug, learnings, results).catch(() => {});
1161
+ // Will be shown in the summary section below
1162
+ results._extractedLearnings = learnings.length;
1163
+ }
1164
+ }
1165
+
1166
+ // ── Session summary ────────────────────────────────────────────────────────
1167
+ const elapsed = Math.round((Date.now() - startedAt) / 1000);
1168
+ const busSummary = enableBus
1169
+ ? await bus.summary(targetDir, squadSlug, sessionId).catch(() => null)
1170
+ : null;
1171
+
1172
+ const summary = {
1173
+ ok: failedCount === 0 && escalatedCount === 0,
1174
+ session_id: sessionId,
1175
+ squad: squadSlug,
1176
+ goal: plan.goal,
1177
+ elapsed_s: elapsed,
1178
+ budget_used: sessionTokensUsed,
1179
+ budget_limit: budget.maxTokensPerSession,
1180
+ tasks: {
1181
+ total: plan.tasks.length,
1182
+ completed: completedCount,
1183
+ failed: failedCount,
1184
+ escalated: escalatedCount
1185
+ },
1186
+ bus: busSummary
1187
+ ? { total_messages: busSummary.total, blocks: busSummary.blocks.length }
1188
+ : null
1189
+ };
1190
+
1191
+ if (options.json) return summary;
1192
+
1193
+ logger.log('');
1194
+ logger.log('── Autorun complete ─────────────────────────────────────────');
1195
+ logger.log(`Session: ${sessionId}`);
1196
+ logger.log(`Elapsed: ${elapsed}s`);
1197
+ logger.log(`Tasks: ${completedCount}/${plan.tasks.length} completed ${failedCount > 0 ? `| ${failedCount} failed` : ''} ${escalatedCount > 0 ? `| ${escalatedCount} escalated` : ''}`);
1198
+ if (budget.maxTokensPerSession !== Infinity) {
1199
+ logger.log(`Tokens: ~${sessionTokensUsed.toLocaleString()} used / ${budget.maxTokensPerSession.toLocaleString()} budget`);
1200
+ }
1201
+ if (busSummary && busSummary.total > 0) {
1202
+ logger.log(`Bus: ${busSummary.total} messages${busSummary.blocks.length > 0 ? ` | ⚠ ${busSummary.blocks.length} block(s)` : ''}`);
1203
+ }
1204
+ if (escalatedCount > 0) {
1205
+ logger.log('');
1206
+ logger.log('⚠ Escalated tasks require coordinator attention:');
1207
+ for (const r of results.filter((r) => r.finalStatus === 'escalated')) {
1208
+ const exhausted = r.workerResult?.gap_closure_exhausted ? ' (gap closure exhausted)' : '';
1209
+ logger.log(` ${r.task.id}: ${r.task.title}${exhausted}`);
1210
+ }
1211
+ }
1212
+ logger.log('');
1213
+ logger.log(`Plan: .aioson/squads/${squadSlug}/sessions/${sessionId}/plan.json`);
1214
+ logger.log(`State: .aioson/squads/${squadSlug}/STATE.md`);
1215
+ if (enableBus) logger.log(`Bus: .aioson/squads/${squadSlug}/sessions/${sessionId}/bus.jsonl`);
1216
+
1217
+ return summary;
1218
+ }
1219
+
1220
+ module.exports = { runSquadAutorun };