maestro-flow 0.3.8 → 0.3.10

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 (312) hide show
  1. package/.claude/commands/learn-decompose.md +3 -3
  2. package/.claude/commands/learn-follow.md +5 -5
  3. package/.claude/commands/learn-investigate.md +3 -3
  4. package/.claude/commands/learn-retro.md +6 -6
  5. package/.claude/commands/learn-second-opinion.md +3 -3
  6. package/.claude/commands/maestro-analyze.md +166 -99
  7. package/.claude/commands/maestro-brainstorm.md +2 -2
  8. package/.claude/commands/maestro-execute.md +151 -97
  9. package/.claude/commands/maestro-fork.md +111 -0
  10. package/.claude/commands/maestro-init.md +6 -6
  11. package/.claude/commands/maestro-merge.md +77 -0
  12. package/.claude/commands/maestro-milestone-audit.md +72 -60
  13. package/.claude/commands/maestro-milestone-complete.md +67 -59
  14. package/.claude/commands/maestro-milestone-release.md +6 -6
  15. package/.claude/commands/maestro-plan.md +167 -130
  16. package/.claude/commands/maestro-quick.md +4 -4
  17. package/.claude/commands/maestro-roadmap.md +5 -5
  18. package/.claude/commands/maestro-spec-generate.md +5 -5
  19. package/.claude/commands/maestro-ui-design.md +3 -3
  20. package/.claude/commands/maestro-verify.md +106 -87
  21. package/.claude/commands/maestro.md +10 -4
  22. package/.claude/commands/manage-codebase-rebuild.md +4 -4
  23. package/.claude/commands/manage-codebase-refresh.md +1 -1
  24. package/.claude/commands/manage-harvest.md +6 -6
  25. package/.claude/commands/manage-issue-discover.md +2 -2
  26. package/.claude/commands/manage-issue.md +7 -7
  27. package/.claude/commands/manage-learn.md +2 -2
  28. package/.claude/commands/manage-memory-capture.md +4 -4
  29. package/.claude/commands/manage-memory.md +2 -2
  30. package/.claude/commands/manage-status.md +24 -24
  31. package/.claude/commands/quality-business-test.md +5 -5
  32. package/.claude/commands/quality-debug.md +4 -4
  33. package/.claude/commands/quality-integration-test.md +4 -4
  34. package/.claude/commands/quality-refactor.md +3 -3
  35. package/.claude/commands/quality-retrospective.md +2 -2
  36. package/.claude/commands/quality-review.md +4 -4
  37. package/.claude/commands/quality-sync.md +3 -3
  38. package/.claude/commands/quality-test-gen.md +4 -4
  39. package/.claude/commands/quality-test.md +9 -9
  40. package/.claude/commands/spec-add.md +2 -2
  41. package/.claude/commands/spec-load.md +1 -1
  42. package/.claude/commands/spec-setup.md +5 -5
  43. package/.claude/commands/wiki-connect.md +3 -3
  44. package/.claude/commands/wiki-digest.md +4 -4
  45. package/.codex/skills/maestro/SKILL.md +463 -0
  46. package/.codex/skills/maestro-analyze/SKILL.md +79 -20
  47. package/.codex/skills/maestro-chain/SKILL.md +248 -0
  48. package/.codex/skills/maestro-coordinate/SKILL.md +279 -224
  49. package/.codex/skills/maestro-execute/SKILL.md +35 -26
  50. package/.codex/skills/maestro-milestone-audit/SKILL.md +103 -209
  51. package/.codex/skills/maestro-milestone-complete/SKILL.md +149 -158
  52. package/.codex/skills/maestro-plan/SKILL.md +56 -18
  53. package/.codex/skills/maestro-roadmap/SKILL.md +3 -2
  54. package/.codex/skills/team-coordinate/roles/coordinator/commands/monitor.md +2 -2
  55. package/.codex/skills/team-executor/roles/executor/commands/monitor.md +1 -1
  56. package/.codex/skills/team-lifecycle-v4/roles/coordinator/commands/monitor.md +2 -2
  57. package/.codex/skills/team-lifecycle-v4/specs/knowledge-transfer.md +2 -2
  58. package/.codex/skills/team-quality-assurance/roles/coordinator/commands/monitor.md +1 -1
  59. package/.codex/skills/team-review/roles/coordinator/commands/monitor.md +1 -1
  60. package/.codex/skills/team-tech-debt/roles/coordinator/commands/monitor.md +1 -1
  61. package/.codex/skills/team-testing/roles/coordinator/commands/monitor.md +1 -1
  62. package/README.md +26 -21
  63. package/README.zh-CN.md +23 -19
  64. package/bin/maestro-mcp.js +1 -1
  65. package/chains/_intent-map.json +21 -9
  66. package/chains/_router.json +30 -77
  67. package/chains/brainstorm-driven.json +17 -6
  68. package/chains/full-lifecycle.json +22 -23
  69. package/chains/issue-lifecycle.json +13 -13
  70. package/chains/milestone-close.json +20 -7
  71. package/chains/milestone-fork-merge.json +50 -0
  72. package/chains/roadmap-driven.json +17 -6
  73. package/chains/singles/issue-analyze.json +3 -3
  74. package/chains/singles/issue-execute.json +3 -3
  75. package/chains/singles/issue-plan.json +3 -3
  76. package/chains/spec-driven.json +17 -6
  77. package/dashboard/dist/assets/{ArtifactsPage-BmPOu8sO.js → ArtifactsPage-DZNCi6tn.js} +12 -7
  78. package/dashboard/dist/assets/ChatInput-Bvr-FeEq.js +49 -0
  79. package/dashboard/dist/assets/ChatPage-D9zTkJZo.js +22 -0
  80. package/dashboard/dist/assets/CollabPage-B4NAHXS2.js +1 -0
  81. package/dashboard/dist/assets/ExecutionPanel-CFt4LJyq.js +1 -0
  82. package/dashboard/dist/assets/KanbanPage-C8USth6H.js +21 -0
  83. package/dashboard/dist/assets/{MarkdownRenderer-BjZ43aSa.js → MarkdownRenderer-X4af_WNb.js} +1 -1
  84. package/dashboard/dist/assets/McpPage-BKfCVIyU.js +21 -0
  85. package/dashboard/dist/assets/OutputPanel-BlBQFJSW.js +1 -0
  86. package/dashboard/dist/assets/ProblemsPanel-De3DLvoI.js +1 -0
  87. package/dashboard/dist/assets/{RequirementBoardPage-B7yRL0s_.js → RequirementBoardPage-Bf1trzqs.js} +2 -2
  88. package/dashboard/dist/assets/{RequirementPage-D8J_-b6O.js → RequirementPage-Bllxe2XI.js} +10 -5
  89. package/dashboard/dist/assets/{SpecsPage-6lO8v8_C.js → SpecsPage-9lwxKT27.js} +2 -2
  90. package/dashboard/dist/assets/{SupervisorPage-Ds5N378a.js → SupervisorPage-SusdfHFq.js} +1 -1
  91. package/dashboard/dist/assets/{TeamsPage-DrkKr17T.js → TeamsPage-DsuM6OwC.js} +2 -2
  92. package/dashboard/dist/assets/TreeBrowser-Q12qobZs.js +6 -0
  93. package/dashboard/dist/assets/WorkflowPage-D_Fzdy3_.js +6 -0
  94. package/dashboard/dist/assets/{arrow-left-CadP5YgU.js → arrow-left-Bqtb2hle.js} +1 -1
  95. package/dashboard/dist/assets/{check-5xufDzS8.js → check-u6fGOwQO.js} +1 -1
  96. package/dashboard/dist/assets/{chevron-right-CYbpR4ev.js → chevron-right-Csu22t58.js} +1 -1
  97. package/dashboard/dist/assets/{circle-Bm-5Q-Yh.js → circle-CMrkbRNg.js} +1 -1
  98. package/dashboard/dist/assets/{circle-alert-BqcYuT7x.js → circle-alert-c3tH1P4z.js} +1 -1
  99. package/dashboard/dist/assets/{circle-check-big-yyzAFysU.js → circle-check-big-TDSeWstm.js} +1 -1
  100. package/dashboard/dist/assets/{circle-check-DEVzW_lm.js → circle-check-gYxxSYuH.js} +1 -1
  101. package/dashboard/dist/assets/{code-BBdC8Wmw.js → code-CFN2uX9V.js} +1 -1
  102. package/dashboard/dist/assets/{columns-3-CQ9Trztr.js → columns-3-38xIDlzy.js} +1 -1
  103. package/dashboard/dist/assets/{download-DayuF-sn.js → download-DC7KkKyP.js} +1 -1
  104. package/dashboard/dist/assets/{folder-CqXeSKeC.js → folder-CWq_lAnf.js} +1 -1
  105. package/dashboard/dist/assets/index-DWG-WrzT.js +231 -0
  106. package/dashboard/dist/assets/{index-Dru5HYy0.js → index-Do71weNR.js} +1 -1
  107. package/dashboard/dist/assets/index-GUNJodSR.css +1 -0
  108. package/dashboard/dist/assets/{list-DBOD6IUt.js → list-CgIP_2A-.js} +1 -1
  109. package/dashboard/dist/assets/{minus-fQI1Syn2.js → minus-DYoN5UGk.js} +1 -1
  110. package/dashboard/dist/assets/{pen-line-Bkbbngl5.js → pen-line-Bh_WKYHm.js} +1 -1
  111. package/dashboard/dist/assets/{proxy-teW12DdZ.js → proxy-BKxDAKTj.js} +1 -1
  112. package/dashboard/dist/assets/{search-Bq3ygFUW.js → search-SieXnOgr.js} +1 -1
  113. package/dashboard/dist/assets/{shallow-22ZN8sFt.js → shallow-Bme1JY57.js} +1 -1
  114. package/dashboard/dist/assets/{table-BEYtdWc4.js → table-llyEtj-7.js} +1 -1
  115. package/dashboard/dist/assets/terminal-BB3Xfuv5.js +6 -0
  116. package/dashboard/dist/assets/{trash-2-DMqGBgcF.js → trash-2-C8f4vFFM.js} +1 -1
  117. package/dashboard/dist/assets/{zap-9DVkGVtt.js → zap-4uwlzVm0.js} +1 -1
  118. package/dashboard/dist/index.html +2 -2
  119. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.js +8 -4
  120. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.js.map +1 -1
  121. package/dashboard/dist-server/dashboard/src/server/agents/entry-normalizer.d.ts +1 -0
  122. package/dashboard/dist-server/dashboard/src/server/agents/entry-normalizer.js +2 -1
  123. package/dashboard/dist-server/dashboard/src/server/agents/entry-normalizer.js.map +1 -1
  124. package/dashboard/dist-server/dashboard/src/server/agents/stream-json-adapter.js +20 -10
  125. package/dashboard/dist-server/dashboard/src/server/agents/stream-json-adapter.js.map +1 -1
  126. package/dashboard/dist-server/dashboard/src/server/commander/commander-agent.js +2 -2
  127. package/dashboard/dist-server/dashboard/src/server/commander/commander-agent.js.map +1 -1
  128. package/dashboard/dist-server/dashboard/src/server/coordinator/chain-map.js +3 -3
  129. package/dashboard/dist-server/dashboard/src/server/coordinator/chain-map.js.map +1 -1
  130. package/dashboard/dist-server/dashboard/src/server/routes/git.d.ts +2 -0
  131. package/dashboard/dist-server/dashboard/src/server/routes/git.js +79 -0
  132. package/dashboard/dist-server/dashboard/src/server/routes/git.js.map +1 -0
  133. package/dashboard/dist-server/dashboard/src/server/routes/index.js +3 -0
  134. package/dashboard/dist-server/dashboard/src/server/routes/index.js.map +1 -1
  135. package/dashboard/dist-server/dashboard/src/server/routes/issues.js +34 -0
  136. package/dashboard/dist-server/dashboard/src/server/routes/issues.js.map +1 -1
  137. package/dashboard/dist-server/dashboard/src/server/routes/workspace.js +43 -0
  138. package/dashboard/dist-server/dashboard/src/server/routes/workspace.js.map +1 -1
  139. package/dashboard/dist-server/dashboard/src/server/state/state-manager.js +43 -3
  140. package/dashboard/dist-server/dashboard/src/server/state/state-manager.js.map +1 -1
  141. package/dashboard/dist-server/dashboard/src/server/ws/handlers/execution-handler.js +2 -3
  142. package/dashboard/dist-server/dashboard/src/server/ws/handlers/execution-handler.js.map +1 -1
  143. package/dashboard/dist-server/dashboard/src/shared/issue-types.d.ts +5 -0
  144. package/dashboard/dist-server/dashboard/src/shared/issue-types.js.map +1 -1
  145. package/dashboard/dist-server/dashboard/src/shared/normalize-task.d.ts +2 -0
  146. package/dashboard/dist-server/dashboard/src/shared/normalize-task.js +75 -0
  147. package/dashboard/dist-server/dashboard/src/shared/normalize-task.js.map +1 -0
  148. package/dashboard/dist-server/src/hooks/constants.d.ts +90 -12
  149. package/dashboard/dist-server/src/hooks/constants.js +149 -16
  150. package/dashboard/dist-server/src/hooks/constants.js.map +1 -1
  151. package/dashboard/dist-server/src/types/index.d.ts +5 -0
  152. package/dashboard/package.json +59 -59
  153. package/dist/src/cli.js +3 -1
  154. package/dist/src/cli.js.map +1 -1
  155. package/dist/src/commands/collab.d.ts +14 -0
  156. package/dist/src/commands/collab.d.ts.map +1 -0
  157. package/dist/src/commands/{team.js → collab.js} +395 -96
  158. package/dist/src/commands/collab.js.map +1 -0
  159. package/dist/src/commands/hooks.d.ts +5 -1
  160. package/dist/src/commands/hooks.d.ts.map +1 -1
  161. package/dist/src/commands/hooks.js +50 -10
  162. package/dist/src/commands/hooks.js.map +1 -1
  163. package/dist/src/commands/install-ui/InstallConfirm.d.ts +3 -1
  164. package/dist/src/commands/install-ui/InstallConfirm.d.ts.map +1 -1
  165. package/dist/src/commands/install-ui/InstallConfirm.js +3 -1
  166. package/dist/src/commands/install-ui/InstallConfirm.js.map +1 -1
  167. package/dist/src/commands/install-ui/InstallExecution.d.ts.map +1 -1
  168. package/dist/src/commands/install-ui/InstallExecution.js +5 -1
  169. package/dist/src/commands/install-ui/InstallExecution.js.map +1 -1
  170. package/dist/src/commands/install-ui/InstallFlow.d.ts.map +1 -1
  171. package/dist/src/commands/install-ui/InstallFlow.js +7 -3
  172. package/dist/src/commands/install-ui/InstallFlow.js.map +1 -1
  173. package/dist/src/commands/install-ui/StatuslineConfig.d.ts +6 -1
  174. package/dist/src/commands/install-ui/StatuslineConfig.d.ts.map +1 -1
  175. package/dist/src/commands/install-ui/StatuslineConfig.js +27 -5
  176. package/dist/src/commands/install-ui/StatuslineConfig.js.map +1 -1
  177. package/dist/src/commands/msg.d.ts.map +1 -1
  178. package/dist/src/commands/msg.js +4 -3
  179. package/dist/src/commands/msg.js.map +1 -1
  180. package/dist/src/hooks/__tests__/statusline-visual-test.d.ts +7 -0
  181. package/dist/src/hooks/__tests__/statusline-visual-test.d.ts.map +1 -0
  182. package/dist/src/hooks/__tests__/statusline-visual-test.js +236 -0
  183. package/dist/src/hooks/__tests__/statusline-visual-test.js.map +1 -0
  184. package/dist/src/hooks/constants.d.ts +90 -12
  185. package/dist/src/hooks/constants.d.ts.map +1 -1
  186. package/dist/src/hooks/constants.js +149 -16
  187. package/dist/src/hooks/constants.js.map +1 -1
  188. package/dist/src/hooks/guards/index.d.ts +1 -0
  189. package/dist/src/hooks/guards/index.d.ts.map +1 -1
  190. package/dist/src/hooks/guards/index.js +1 -0
  191. package/dist/src/hooks/guards/index.js.map +1 -1
  192. package/dist/src/hooks/guards/preflight-guard.d.ts +29 -0
  193. package/dist/src/hooks/guards/preflight-guard.d.ts.map +1 -0
  194. package/dist/src/hooks/guards/preflight-guard.js +95 -0
  195. package/dist/src/hooks/guards/preflight-guard.js.map +1 -0
  196. package/dist/src/hooks/index.d.ts +1 -0
  197. package/dist/src/hooks/index.d.ts.map +1 -1
  198. package/dist/src/hooks/index.js +1 -0
  199. package/dist/src/hooks/index.js.map +1 -1
  200. package/dist/src/{commands/team.d.ts → hooks/preflight-core.d.ts} +12 -22
  201. package/dist/src/hooks/preflight-core.d.ts.map +1 -0
  202. package/dist/src/hooks/preflight-core.js +86 -0
  203. package/dist/src/hooks/preflight-core.js.map +1 -0
  204. package/dist/src/hooks/statusline.d.ts +8 -17
  205. package/dist/src/hooks/statusline.d.ts.map +1 -1
  206. package/dist/src/hooks/statusline.js +269 -112
  207. package/dist/src/hooks/statusline.js.map +1 -1
  208. package/dist/src/hooks/team-monitor.d.ts.map +1 -1
  209. package/dist/src/hooks/team-monitor.js +16 -0
  210. package/dist/src/hooks/team-monitor.js.map +1 -1
  211. package/dist/src/i18n/locales/en.d.ts.map +1 -1
  212. package/dist/src/i18n/locales/en.js +5 -0
  213. package/dist/src/i18n/locales/en.js.map +1 -1
  214. package/dist/src/i18n/locales/zh.d.ts.map +1 -1
  215. package/dist/src/i18n/locales/zh.js +5 -0
  216. package/dist/src/i18n/locales/zh.js.map +1 -1
  217. package/dist/src/i18n/types.d.ts +5 -0
  218. package/dist/src/i18n/types.d.ts.map +1 -1
  219. package/dist/src/tools/collab-adapter.d.ts +102 -0
  220. package/dist/src/tools/collab-adapter.d.ts.map +1 -0
  221. package/dist/src/tools/collab-adapter.js +458 -0
  222. package/dist/src/tools/collab-adapter.js.map +1 -0
  223. package/dist/src/tools/merge-validator.d.ts +24 -0
  224. package/dist/src/tools/merge-validator.d.ts.map +1 -0
  225. package/dist/src/tools/merge-validator.js +220 -0
  226. package/dist/src/tools/merge-validator.js.map +1 -0
  227. package/dist/src/tools/namespace-guard.d.ts +2 -0
  228. package/dist/src/tools/namespace-guard.d.ts.map +1 -1
  229. package/dist/src/tools/namespace-guard.js +12 -0
  230. package/dist/src/tools/namespace-guard.js.map +1 -1
  231. package/dist/src/tools/phase-gate-evaluator.d.ts +45 -0
  232. package/dist/src/tools/phase-gate-evaluator.d.ts.map +1 -0
  233. package/dist/src/tools/phase-gate-evaluator.js +42 -0
  234. package/dist/src/tools/phase-gate-evaluator.js.map +1 -0
  235. package/dist/src/tools/team-members.d.ts +18 -0
  236. package/dist/src/tools/team-members.d.ts.map +1 -1
  237. package/dist/src/tools/team-members.js +50 -0
  238. package/dist/src/tools/team-members.js.map +1 -1
  239. package/dist/src/tools/team-tasks.d.ts +120 -0
  240. package/dist/src/tools/team-tasks.d.ts.map +1 -0
  241. package/dist/src/tools/team-tasks.js +365 -0
  242. package/dist/src/tools/team-tasks.js.map +1 -0
  243. package/dist/src/tools/transition-recorder.d.ts +3 -0
  244. package/dist/src/tools/transition-recorder.d.ts.map +1 -1
  245. package/dist/src/tools/transition-recorder.js +52 -1
  246. package/dist/src/tools/transition-recorder.js.map +1 -1
  247. package/dist/src/types/index.d.ts +5 -0
  248. package/dist/src/types/index.d.ts.map +1 -1
  249. package/dist/src/utils/get-version.d.ts.map +1 -1
  250. package/dist/src/utils/get-version.js +15 -4
  251. package/dist/src/utils/get-version.js.map +1 -1
  252. package/package.json +1 -1
  253. package/templates/cli/prompts/workflow-skill-conflict-patterns.txt +3 -3
  254. package/templates/cli/prompts/workflow-skill-lessons-learned.txt +3 -3
  255. package/templates/config.json +7 -0
  256. package/templates/search-tools.md +1 -1
  257. package/templates/worktree-scope.json +10 -0
  258. package/templates/worktrees.json +27 -0
  259. package/workflows/analyze.md +86 -36
  260. package/workflows/brainstorm.md +17 -37
  261. package/workflows/cli-tools-usage.md +44 -27
  262. package/workflows/delegate-usage.md +3 -3
  263. package/workflows/execute.md +94 -28
  264. package/workflows/fork.md +309 -0
  265. package/workflows/init.md +10 -1
  266. package/workflows/issue-analyze.md +6 -2
  267. package/workflows/issue-discover.md +4 -4
  268. package/workflows/issue-execute.md +6 -3
  269. package/workflows/issue-plan.md +5 -2
  270. package/workflows/issue.md +66 -7
  271. package/workflows/maestro-coordinate.codex.md +281 -470
  272. package/workflows/maestro-coordinate.md +37 -30
  273. package/workflows/maestro-link-coordinate.md +2 -2
  274. package/workflows/maestro.codex.md +710 -0
  275. package/workflows/maestro.md +62 -46
  276. package/workflows/merge.md +285 -0
  277. package/workflows/milestone-audit.md +89 -70
  278. package/workflows/milestone-complete.md +89 -156
  279. package/workflows/plan.md +122 -17
  280. package/workflows/retrospective.md +4 -4
  281. package/workflows/roadmap.md +11 -3
  282. package/workflows/spec-generate.md +9 -0
  283. package/workflows/status.md +76 -27
  284. package/workflows/ui-design.md +14 -12
  285. package/workflows/verify.md +44 -8
  286. package/.claude/commands/maestro-phase-add.md +0 -63
  287. package/.claude/commands/maestro-phase-transition.md +0 -75
  288. package/.claude/commands/manage-issue-analyze.md +0 -62
  289. package/.claude/commands/manage-issue-execute.md +0 -73
  290. package/.claude/commands/manage-issue-plan.md +0 -62
  291. package/.codex/skills/maestro-phase-add/SKILL.md +0 -154
  292. package/.codex/skills/maestro-phase-transition/SKILL.md +0 -173
  293. package/.codex/skills/manage-issue-analyze/SKILL.md +0 -207
  294. package/.codex/skills/manage-issue-execute/SKILL.md +0 -200
  295. package/.codex/skills/manage-issue-plan/SKILL.md +0 -186
  296. package/chains/singles/phase-add.json +0 -31
  297. package/chains/singles/phase-transition.json +0 -23
  298. package/dashboard/dist/assets/ChatInput-CL8YDfOU.js +0 -67
  299. package/dashboard/dist/assets/ChatPage-CT-ozBK2.js +0 -8
  300. package/dashboard/dist/assets/CollabPage-C0rWMden.js +0 -1
  301. package/dashboard/dist/assets/KanbanPage-C6WbAlwI.js +0 -16
  302. package/dashboard/dist/assets/McpPage-BPIXADQi.js +0 -16
  303. package/dashboard/dist/assets/TreeBrowser-g_QUKemL.js +0 -11
  304. package/dashboard/dist/assets/WorkflowPage-X8aNkDEr.js +0 -6
  305. package/dashboard/dist/assets/git-branch-SqFf4Ru5.js +0 -6
  306. package/dashboard/dist/assets/index-D2Mtyw7I.css +0 -1
  307. package/dashboard/dist/assets/index-nufWop4p.js +0 -231
  308. package/dashboard/dist/assets/wrench-B84-zdLI.js +0 -11
  309. package/dist/src/commands/team.d.ts.map +0 -1
  310. package/dist/src/commands/team.js.map +0 -1
  311. package/workflows/phase-add.md +0 -252
  312. package/workflows/phase-transition.md +0 -399
@@ -1,6 +1,6 @@
1
- # Workflow: maestro-coordinate (Codex Edition)
1
+ # Workflow: Maestro-coordinate (Codex CLI-Delegate Edition)
2
2
 
3
- Codex team-agent version of `maestro-coordinate`. Replaces `maestro cli` background execution + hook callbacks with synchronous `spawn_agent / wait / close_agent`. Each chain step assembles a prompt containing the skill invocation (`$skill-name args`) and spawns one agent; the analysis step spawns a second agent inline. All async state-machine concerns are eliminated.
3
+ Autonomous CLI coordinator for Codex. Classifies intent, selects command chain, executes each step via `codex delegate` with template-driven prompts and async state machine. After each step, gemini evaluates output quality and generates optimization hints for subsequent steps.
4
4
 
5
5
  > Referenced by: `~/.codex/skills/maestro-coordinate/SKILL.md`
6
6
 
@@ -10,58 +10,57 @@ Codex team-agent version of `maestro-coordinate`. Replaces `maestro cli` backgro
10
10
 
11
11
  ```javascript
12
12
  const args = $ARGUMENTS.trim();
13
- const AUTO_YES = new RegExp('\\b(-y|--yes)\\b').test(args);
14
- const RESUME = new RegExp('\\b(-c|--continue)\\b').test(args);
15
- const DRY_RUN = new RegExp('\\b--dry-run\\b').test(args);
16
- const forceChain = args.match(new RegExp('--chain\\s+(\\S+)'))?.[1] ?? null;
13
+ const autoYes = /\b(-y|--yes)\b/.test(args);
14
+ const resumeMode = /\b(-c|--continue)\b/.test(args);
15
+ const dryRun = /\b--dry-run\b/.test(args);
16
+ const forcedChain = args.match(/--chain\s+(\S+)/)?.[1] || null;
17
+ const cliTool = args.match(/--tool\s+(\S+)/)?.[1] || 'codex';
17
18
  const intent = args
18
- .replace(new RegExp('\\b(-y|--yes|-c|--continue|--dry-run)\\b', 'g'), '')
19
- .replace(new RegExp('--(chain)\\s+\\S+', 'g'), '')
19
+ .replace(/\b(-y|--yes|-c|--continue|--dry-run)\b/g, '')
20
+ .replace(/--(chain|tool)\s+\S+/g, '')
20
21
  .trim();
21
22
  ```
22
23
 
23
- **Resume mode**: If `RESUME`:
24
- 1. Glob `.workflow/.maestro-coordinate/coord-*/state.json`, sort desc by name, load latest
25
- 2. Set `current_step` to index of first step where `status === "pending"`
24
+ **If resumeMode:**
25
+ 1. Find latest `state.json` in `.workflow/.maestro-coordinate/`
26
+ 2. Load state → set `current_step` to first non-completed step
26
27
  3. Jump to **Step 6**
27
28
 
28
29
  ---
29
30
 
30
31
  ## Step 2: Read Project State
31
32
 
32
- ```javascript
33
- const stateFile = '.workflow/state.json';
34
- let projectState = { initialized: false };
35
-
36
- if (fileExists(stateFile)) {
37
- const raw = JSON.parse(Read(stateFile));
38
- projectState = {
39
- initialized: true,
40
- current_phase: raw.current_phase,
41
- phase_slug: raw.phase_slug,
42
- phase_status: raw.phase_status, // pending|exploring|planning|executing|verifying|testing|completed|blocked
43
- phase_artifacts: raw.phase_artifacts ?? {},
44
- execution: raw.execution ?? { tasks_completed: 0, tasks_total: 0 },
45
- verification_status: raw.verification_status ?? 'pending',
46
- review_verdict: raw.review_verdict ?? null,
47
- uat_status: raw.uat_status ?? 'pending',
48
- phases_total: raw.phases_total ?? 0,
49
- phases_completed: raw.phases_completed ?? 0,
50
- has_blockers: raw.has_blockers ?? false,
51
- accumulated_context: raw.accumulated_context ?? null
52
- };
53
- }
33
+ ```bash
34
+ test -f .workflow/state.json && echo "exists" || echo "missing"
35
+ ```
36
+
37
+ **If exists:** Read `.workflow/state.json` + `.workflow/roadmap.md` + current phase `index.json`:
54
38
 
55
- if (!projectState.initialized && !intent) throw new Error('E001: No project state and no intent. Run $maestro-init first.');
39
+ ```javascript
40
+ const projectState = {
41
+ initialized: true,
42
+ current_milestone: /* from state.json */,
43
+ latest_artifact: /* last artifact in artifacts[] */,
44
+ milestone_progress: '...', // derived from artifact registry
45
+ phase_artifacts: { brainstorm: false, analysis: false, context: false, plan: false, verification: false, uat: false },
46
+ execution: { tasks_completed: 0, tasks_total: 0 },
47
+ verification_status: 'pending',
48
+ review_verdict: null, // PASS|WARN|BLOCK|null
49
+ uat_status: 'pending',
50
+ phases_total: 0, phases_completed: 0,
51
+ has_blockers: false, accumulated_context: null
52
+ };
56
53
  ```
57
54
 
55
+ **If missing:** `projectState = { initialized: false }`. If intent also empty → **Error E001**.
56
+
58
57
  ---
59
58
 
60
59
  ## Step 3: Classify Intent & Select Chain
61
60
 
62
61
  ### 3a: Exact-match keywords (fast path)
63
62
 
64
- If `forceChain` is set validate against chainMap and jump to **3c**.
63
+ If `forcedChain` is set, validate and jump to **3c**.
65
64
 
66
65
  ```javascript
67
66
  const exactMatch = {
@@ -83,7 +82,7 @@ Instead of regex, extract a structured intent tuple using LLM semantic understan
83
82
  ```json
84
83
  {
85
84
  "action": "<create|fix|analyze|plan|execute|verify|review|test|debug|refactor|explore|manage|transition|continue|sync|learn|retrospect>",
86
- "object": "<feature|bug|issue|code|test|spec|phase|milestone|doc|performance|security|ui|memory|codebase|team|config>",
85
+ "object": "<feature|bug|issue|code|test|spec|phase|milestone|doc|performance|security|ui|memory|codebase|config>",
87
86
  "scope": "<module/file/area or null>",
88
87
  "issue_id": "<ISS-XXXXXXXX-NNN if mentioned, else null>",
89
88
  "phase_ref": "<integer if mentioned, else null>",
@@ -108,7 +107,7 @@ function routeIntent(intent, projectState) {
108
107
  // Action × Object matrix
109
108
  const matrix = {
110
109
  'fix': { 'bug': 'debug', 'issue': 'issue', 'code': 'debug', 'performance': 'debug', 'security': 'debug', '_default': 'debug' },
111
- 'create': { 'feature': 'quick', 'issue': 'issue', 'test': 'test_gen', 'spec': 'spec_generate', 'ui': 'ui_design', 'config': 'init', 'phase': 'phase_add', '_default': 'quick' },
110
+ 'create': { 'feature': 'quick', 'issue': 'issue', 'test': 'test_gen', 'spec': 'spec_generate', 'ui': 'ui_design', 'config': 'init', 'phase': 'roadmap', '_default': 'quick' },
112
111
  'analyze': { 'bug': 'analyze', 'issue': 'issue_analyze', 'code': 'analyze', 'codebase': 'spec_map', '_default': 'analyze' },
113
112
  'explore': { 'issue': 'issue_discover', 'feature': 'brainstorm', 'ui': 'ui_design', '_default': 'brainstorm' },
114
113
  'plan': { 'issue': 'issue_plan', 'spec': 'spec_generate', '_default': 'plan' },
@@ -118,82 +117,63 @@ function routeIntent(intent, projectState) {
118
117
  'test': { '_default': 'test' },
119
118
  'debug': { '_default': 'debug' },
120
119
  'refactor': { '_default': 'refactor' },
121
- 'manage': { 'issue': 'issue', 'milestone': 'milestone_audit', 'phase': 'phase_transition', 'memory': 'memory', 'doc': 'sync', 'codebase': 'codebase_refresh', 'team': 'team_coordinate', '_default': 'status' },
122
- 'transition':{ 'phase': 'phase_transition', 'milestone': 'milestone_complete', '_default': 'phase_transition' },
120
+ 'manage': { 'issue': 'issue', 'milestone': 'milestone_audit', 'phase': 'milestone_close', 'memory': 'memory', 'doc': 'sync', 'codebase': 'codebase_refresh', '_default': 'status' },
121
+ 'transition':{ 'phase': 'milestone_close', 'milestone': 'milestone_complete', '_default': 'milestone_close' },
123
122
  'continue': { '_default': 'state_continue' },
124
123
  'sync': { '_default': 'sync' },
125
124
  'learn': { '_default': 'learn' },
126
125
  'retrospect':{ '_default': 'retrospective' },
127
126
  };
128
127
 
129
- // Team skill detection
130
- if (object === 'team') {
131
- const teamRoutes = { 'review': 'team_review', 'test': 'team_test', 'debug': 'team_qa', 'refactor': 'team_tech_debt', 'execute': 'team_lifecycle', '_default': 'team_coordinate' };
132
- return teamRoutes[action] || 'team_coordinate';
133
- }
134
-
135
128
  const actionMap = matrix[action] || matrix['fix'];
136
129
  return actionMap[object] || actionMap['_default'] || 'quick';
137
130
  }
138
131
  ```
139
132
 
140
- **Clarity scoring**: 3 = action+object+scope, 2 = action+object, 1 = action only, 0 = empty.
141
- If `clarity < 2` and not `AUTO_YES`: call `functions.request_user_input` with one focused question (max 2 rounds).
133
+ Compute clarity (3=action+object+scope, 2=action+object, 1=action only, 0=empty).
134
+ If clarity < 2 and not autoYes: clarify via AskUserQuestion (max 2 rounds).
142
135
 
143
- ### 3b: State-based routing (when `taskType === 'state_continue'`)
136
+ ### 3b: State-based routing (task_type == `state_continue`)
144
137
 
145
138
  ```javascript
146
139
  function detectNextAction(s) {
147
140
  if (!s.initialized) return { chain: 'init', steps: [{ cmd: 'maestro-init' }] };
148
141
  const ps = s.phase_status, art = s.phase_artifacts, exec = s.execution;
149
142
 
143
+ // Post-milestone: no roadmap, has accumulated context
150
144
  if (s.phases_total === 0 && !fileExists('.workflow/roadmap.md') && s.accumulated_context)
151
145
  return { chain: 'next-milestone', steps: [{ cmd: 'maestro-roadmap', args: '"{description}"' }] };
152
146
  if (s.phases_total === 0)
153
- return { chain: 'brainstorm-driven', steps: [
154
- { cmd: 'maestro-brainstorm', args: '"{description}"' },
155
- { cmd: 'maestro-plan', args: '{phase}' },
156
- { cmd: 'maestro-execute', args: '{phase}' },
157
- { cmd: 'maestro-verify', args: '{phase}' }
158
- ]};
147
+ return { chain: 'brainstorm-driven', steps: [{ cmd: 'maestro-brainstorm', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }] };
159
148
 
160
149
  if (ps === 'pending') {
161
- if (art.context) return { chain: 'plan', steps: [{ cmd: 'maestro-plan', args: '{phase}' }] };
162
- return { chain: 'analyze', steps: [{ cmd: 'maestro-analyze', args: '{phase}' }] };
150
+ if (art.context) return { chain: 'plan', steps: [{ cmd: 'maestro-plan', args: '{phase}' }] };
151
+ return { chain: 'analyze', steps: [{ cmd: 'maestro-analyze', args: '{phase}' }] };
163
152
  }
164
153
  if (ps === 'exploring' || ps === 'planning') {
165
- if (art.plan) return { chain: 'execute-verify', steps: [
166
- { cmd: 'maestro-execute', args: '{phase}' },
167
- { cmd: 'maestro-verify', args: '{phase}' }
168
- ]};
154
+ if (art.plan) return { chain: 'execute-verify', steps: [{ cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }] };
169
155
  return { chain: 'plan', steps: [{ cmd: 'maestro-plan', args: '{phase}' }] };
170
156
  }
171
157
  if (ps === 'executing') {
172
- if (exec.tasks_completed >= exec.tasks_total && exec.tasks_total > 0)
173
- return { chain: 'verify', steps: [{ cmd: 'maestro-verify', args: '{phase}' }] };
158
+ if (exec.tasks_completed >= exec.tasks_total && exec.tasks_total > 0) return { chain: 'verify', steps: [{ cmd: 'maestro-verify', args: '{phase}' }] };
174
159
  return { chain: 'execute', steps: [{ cmd: 'maestro-execute', args: '{phase}' }] };
175
160
  }
176
161
  if (ps === 'verifying') {
177
162
  if (s.verification_status === 'passed') {
178
- if (!s.review_verdict) return { chain: 'review', steps: [{ cmd: 'quality-review', args: '{phase}' }] };
179
- if (s.uat_status === 'pending') return { chain: 'test', steps: [{ cmd: 'quality-test', args: '{phase}' }] };
180
- if (s.uat_status === 'passed') return { chain: 'phase-transition', steps: [{ cmd: 'maestro-phase-transition' }] };
163
+ if (!s.review_verdict) return { chain: 'review', steps: [{ cmd: 'quality-review', args: '{phase}' }] };
164
+ if (s.uat_status === 'pending') return { chain: 'test', steps: [{ cmd: 'quality-test', args: '{phase}' }] };
165
+ if (s.uat_status === 'passed') return { chain: 'milestone-close', steps: [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }] };
181
166
  return { chain: 'debug', steps: [{ cmd: 'quality-debug', args: '--from-uat {phase}' }] };
182
167
  }
183
- return { chain: 'quality-loop-partial', steps: [
184
- { cmd: 'maestro-plan', args: '{phase} --gaps' },
185
- { cmd: 'maestro-execute', args: '{phase}' },
186
- { cmd: 'maestro-verify', args: '{phase}' }
187
- ]};
168
+ return { chain: 'quality-loop-partial', steps: [{ cmd: 'maestro-plan', args: '{phase} --gaps' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }] };
188
169
  }
189
170
  if (ps === 'testing') {
190
- if (s.uat_status === 'passed') return { chain: 'phase-transition', steps: [{ cmd: 'maestro-phase-transition' }] };
171
+ if (s.uat_status === 'passed') return { chain: 'milestone-close', steps: [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }] };
191
172
  return { chain: 'debug', steps: [{ cmd: 'quality-debug', args: '--from-uat {phase}' }] };
192
173
  }
193
174
  if (ps === 'completed') {
194
- if (s.phases_completed >= s.phases_total)
195
- return { chain: 'milestone-close', steps: [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }] };
196
- return { chain: 'phase-transition', steps: [{ cmd: 'maestro-phase-transition' }] };
175
+ if (s.phases_completed >= s.phases_total) return { chain: 'milestone-close', steps: [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }] };
176
+ return { chain: 'milestone-close', steps: [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }] };
197
177
  }
198
178
  if (ps === 'blocked') return { chain: 'debug', steps: [{ cmd: 'quality-debug' }] };
199
179
  return { chain: 'status', steps: [{ cmd: 'manage-status' }] };
@@ -204,264 +184,157 @@ function detectNextAction(s) {
204
184
 
205
185
  ```javascript
206
186
  const chainMap = {
207
- // ── Single-step ──────────────────────────────────────────────────────────
187
+ // Single-step
208
188
  'status': [{ cmd: 'manage-status' }],
209
189
  'init': [{ cmd: 'maestro-init' }],
210
- 'analyze': [{ cmd: 'maestro-analyze', args: '{phase}' }],
211
- 'ui_design': [{ cmd: 'maestro-ui-design', args: '{phase}' }],
212
- 'plan': [{ cmd: 'maestro-plan', args: '{phase}' }],
213
- 'execute': [{ cmd: 'maestro-execute', args: '{phase}' }],
214
- 'verify': [{ cmd: 'maestro-verify', args: '{phase}' }],
215
- 'test_gen': [{ cmd: 'quality-test-gen', args: '{phase}' }],
216
- 'test': [{ cmd: 'quality-test', args: '{phase}' }],
217
- 'debug': [{ cmd: 'quality-debug', args: '"{description}"' }],
218
- 'integration_test': [{ cmd: 'quality-integration-test',args: '{phase}' }],
219
- 'refactor': [{ cmd: 'quality-refactor', args: '"{description}"' }],
220
- 'review': [{ cmd: 'quality-review', args: '{phase}' }],
221
- 'retrospective': [{ cmd: 'quality-retrospective', args: '{phase}' }],
222
- 'learn': [{ cmd: 'manage-learn', args: '"{description}"' }],
223
- 'sync': [{ cmd: 'quality-sync', args: '{phase}' }],
224
- 'phase_transition': [{ cmd: 'maestro-phase-transition' }],
225
- 'phase_add': [{ cmd: 'maestro-phase-add', args: '"{description}"' }],
190
+ 'analyze': [{ cmd: 'maestro-analyze', args: '{phase}' }],
191
+ 'ui_design': [{ cmd: 'maestro-ui-design', args: '{phase}' }],
192
+ 'plan': [{ cmd: 'maestro-plan', args: '{phase}' }],
193
+ 'execute': [{ cmd: 'maestro-execute', args: '{phase}' }],
194
+ 'verify': [{ cmd: 'maestro-verify', args: '{phase}' }],
195
+ 'test_gen': [{ cmd: 'quality-test-gen', args: '{phase}' }],
196
+ 'test': [{ cmd: 'quality-test', args: '{phase}' }],
197
+ 'debug': [{ cmd: 'quality-debug', args: '"{description}"' }],
198
+ 'integration_test': [{ cmd: 'quality-integration-test', args: '{phase}' }],
199
+ 'refactor': [{ cmd: 'quality-refactor', args: '"{description}"' }],
200
+ 'review': [{ cmd: 'quality-review', args: '{phase}' }],
201
+ 'retrospective': [{ cmd: 'quality-retrospective', args: '{phase}' }],
202
+ 'learn': [{ cmd: 'manage-learn', args: '"{description}"' }],
203
+ 'sync': [{ cmd: 'quality-sync', args: '{phase}' }],
204
+ 'milestone_close': [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }],
205
+ 'roadmap': [{ cmd: 'maestro-roadmap', args: '"{description}"' }],
226
206
  'milestone_audit': [{ cmd: 'maestro-milestone-audit' }],
227
207
  'milestone_complete': [{ cmd: 'maestro-milestone-complete' }],
228
208
  'codebase_rebuild': [{ cmd: 'manage-codebase-rebuild' }],
229
209
  'codebase_refresh': [{ cmd: 'manage-codebase-refresh' }],
230
210
  'spec_setup': [{ cmd: 'spec-setup' }],
231
- 'spec_add': [{ cmd: 'spec-add', args: '"{description}"' }],
232
- 'spec_load': [{ cmd: 'spec-load', args: '"{description}"' }],
211
+ 'spec_add': [{ cmd: 'spec-add', args: '"{description}"' }],
212
+ 'spec_load': [{ cmd: 'spec-load', args: '"{description}"' }],
233
213
  'spec_map': [{ cmd: 'manage-codebase-rebuild' }],
234
- 'memory_capture': [{ cmd: 'manage-memory-capture', args: '"{description}"' }],
235
- 'memory': [{ cmd: 'manage-memory', args: '"{description}"' }],
236
- 'issue': [{ cmd: 'manage-issue', args: '"{description}"' }],
237
- 'issue_discover': [{ cmd: 'manage-issue-discover', args: '"{description}"' }],
238
- 'issue_analyze': [{ cmd: 'manage-issue-analyze', args: '"{description}"' }],
239
- 'issue_plan': [{ cmd: 'manage-issue-plan', args: '"{description}"' }],
240
- 'issue_execute': [{ cmd: 'manage-issue-execute', args: '"{description}"' }],
241
- 'quick': [{ cmd: 'maestro-quick', args: '"{description}"' }],
242
- 'team_lifecycle': [{ cmd: 'team-lifecycle-v4', args: '"{description}"' }],
243
- 'team_coordinate': [{ cmd: 'team-coordinate', args: '"{description}"' }],
244
- 'team_qa': [{ cmd: 'team-quality-assurance', args: '"{description}"' }],
245
- 'team_test': [{ cmd: 'team-testing', args: '"{description}"' }],
246
- 'team_review': [{ cmd: 'team-review', args: '"{description}"' }],
247
- 'team_tech_debt': [{ cmd: 'team-tech-debt', args: '"{description}"' }],
248
-
249
- // ── Multi-step chains ────────────────────────────────────────────────────
250
- 'spec-driven': [
251
- { cmd: 'maestro-init' },
252
- { cmd: 'maestro-spec-generate', args: '"{description}"' },
253
- { cmd: 'maestro-plan', args: '{phase}' },
254
- { cmd: 'maestro-execute', args: '{phase}' },
255
- { cmd: 'maestro-verify', args: '{phase}' }
256
- ],
257
- 'brainstorm-driven': [
258
- { cmd: 'maestro-brainstorm', args: '"{description}"' },
259
- { cmd: 'maestro-plan', args: '{phase}' },
260
- { cmd: 'maestro-execute', args: '{phase}' },
261
- { cmd: 'maestro-verify', args: '{phase}' }
262
- ],
263
- 'ui-design-driven': [
264
- { cmd: 'maestro-ui-design', args: '{phase}' },
265
- { cmd: 'maestro-plan', args: '{phase}' },
266
- { cmd: 'maestro-execute', args: '{phase}' },
267
- { cmd: 'maestro-verify', args: '{phase}' }
268
- ],
269
- 'full-lifecycle': [
270
- { cmd: 'maestro-plan', args: '{phase}' },
271
- { cmd: 'maestro-execute', args: '{phase}' },
272
- { cmd: 'maestro-verify', args: '{phase}' },
273
- { cmd: 'quality-review', args: '{phase}' },
274
- { cmd: 'quality-test', args: '{phase}' },
275
- { cmd: 'maestro-phase-transition' }
276
- ],
277
- 'execute-verify': [
278
- { cmd: 'maestro-execute', args: '{phase}' },
279
- { cmd: 'maestro-verify', args: '{phase}' }
280
- ],
281
- 'quality-loop': [
282
- { cmd: 'maestro-verify', args: '{phase}' },
283
- { cmd: 'quality-review', args: '{phase}' },
284
- { cmd: 'quality-test', args: '{phase}' },
285
- { cmd: 'quality-debug', args: '--from-uat {phase}' },
286
- { cmd: 'maestro-plan', args: '{phase} --gaps' },
287
- { cmd: 'maestro-execute', args: '{phase}' }
288
- ],
289
- 'milestone-close': [
290
- { cmd: 'maestro-milestone-audit' },
291
- { cmd: 'maestro-milestone-complete' }
292
- ],
293
- 'roadmap-driven': [
294
- { cmd: 'maestro-init' },
295
- { cmd: 'maestro-roadmap', args: '"{description}"' },
296
- { cmd: 'maestro-plan', args: '{phase}' },
297
- { cmd: 'maestro-execute', args: '{phase}' },
298
- { cmd: 'maestro-verify', args: '{phase}' }
299
- ],
300
- 'next-milestone': [
301
- { cmd: 'maestro-roadmap', args: '"{description}"' },
302
- { cmd: 'maestro-plan', args: '{phase}' },
303
- { cmd: 'maestro-execute', args: '{phase}' },
304
- { cmd: 'maestro-verify', args: '{phase}' }
305
- ],
306
- 'analyze-plan-execute': [
307
- { cmd: 'maestro-analyze', args: '"{description}" -q' },
308
- { cmd: 'maestro-plan', args: '--dir {scratch_dir}' },
309
- { cmd: 'maestro-execute', args: '--dir {scratch_dir}' }
310
- ],
311
-
312
- // ── SKILL.md simplified aliases (--chain <name> shortcuts) ───────────────
313
- 'feature': [
314
- { cmd: 'maestro-plan', args: '{phase}' },
315
- { cmd: 'maestro-execute', args: '{phase}' },
316
- { cmd: 'maestro-verify', args: '{phase}' }
317
- ],
318
- 'quality-fix': [
319
- { cmd: 'manage-issue-analyze', args: '"{description}"' },
320
- { cmd: 'manage-issue-execute', args: '"{description}"' },
321
- { cmd: 'maestro-verify', args: '{phase}' }
322
- ],
323
- 'deploy': [
324
- { cmd: 'maestro-verify', args: '{phase}' },
325
- { cmd: 'maestro-execute', args: '{phase}' }
326
- ],
327
-
328
- // ── Issue lifecycle chains (with quality gates) ────────────────────────────
329
- 'issue-full': [
330
- { cmd: 'manage-issue-analyze', args: '{issue_id}' },
331
- { cmd: 'manage-issue-plan', args: '{issue_id}' },
332
- { cmd: 'manage-issue-execute', args: '{issue_id}' },
333
- { cmd: 'quality-review', args: '--scope {affected_files}' },
334
- { cmd: 'manage-issue', args: 'close {issue_id} --resolution fixed' }
335
- ],
336
- 'issue-quick': [
337
- { cmd: 'manage-issue-plan', args: '{issue_id}' },
338
- { cmd: 'manage-issue-execute', args: '{issue_id}' },
339
- { cmd: 'manage-issue', args: 'close {issue_id} --resolution fixed' }
340
- ],
214
+ 'memory_capture': [{ cmd: 'manage-memory-capture', args: '"{description}"' }],
215
+ 'memory': [{ cmd: 'manage-memory', args: '"{description}"' }],
216
+ 'issue': [{ cmd: 'manage-issue', args: '"{description}"' }],
217
+ 'issue_discover': [{ cmd: 'manage-issue-discover', args: '"{description}"' }],
218
+ 'issue_analyze': [{ cmd: 'maestro-analyze', args: '--gaps "{description}"' }],
219
+ 'issue_plan': [{ cmd: 'maestro-plan', args: '--gaps' }],
220
+ 'issue_execute': [{ cmd: 'maestro-execute', args: '' }],
221
+ 'quick': [{ cmd: 'maestro-quick', args: '"{description}"' }],
222
+ 'fork': [{ cmd: 'maestro-fork', args: '-m {milestone_num}' }],
223
+ 'merge': [{ cmd: 'maestro-merge', args: '-m {milestone_num}' }],
224
+ // Multi-step chains
225
+ 'spec-driven': [{ cmd: 'maestro-init' }, { cmd: 'maestro-spec-generate', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }],
226
+ 'brainstorm-driven': [{ cmd: 'maestro-brainstorm', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }],
227
+ 'ui-design-driven': [{ cmd: 'maestro-ui-design', args: '{phase}' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }],
228
+ 'full-lifecycle': [{ cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }, { cmd: 'quality-review', args: '{phase}' }, { cmd: 'quality-test', args: '{phase}' }, { cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }],
229
+ 'execute-verify': [{ cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }],
230
+ 'quality-loop': [{ cmd: 'maestro-verify', args: '{phase}' }, { cmd: 'quality-review', args: '{phase}' }, { cmd: 'quality-test', args: '{phase}' }, { cmd: 'quality-debug', args: '--from-uat {phase}' }, { cmd: 'maestro-plan', args: '{phase} --gaps' }, { cmd: 'maestro-execute', args: '{phase}' }],
231
+ 'milestone-close': [{ cmd: 'maestro-milestone-audit' }, { cmd: 'maestro-milestone-complete' }],
232
+ 'roadmap-driven': [{ cmd: 'maestro-init' }, { cmd: 'maestro-roadmap', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }],
233
+ 'next-milestone': [{ cmd: 'maestro-roadmap', args: '"{description}"' }, { cmd: 'maestro-plan', args: '{phase}' }, { cmd: 'maestro-execute', args: '{phase}' }, { cmd: 'maestro-verify', args: '{phase}' }],
234
+ 'analyze-plan-execute': [{ cmd: 'maestro-analyze', args: '"{description}" -q' }, { cmd: 'maestro-plan', args: '--dir {scratch_dir}' }, { cmd: 'maestro-execute', args: '--dir {scratch_dir}' }],
235
+ // Issue lifecycle chains (with quality gates)
236
+ 'issue-full': [{ cmd: 'maestro-analyze', args: '--gaps {issue_id}' }, { cmd: 'maestro-plan', args: '--gaps' }, { cmd: 'maestro-execute', args: '' }, { cmd: 'quality-review', args: '--scope {affected_files}' }, { cmd: 'manage-issue', args: 'close {issue_id} --resolution fixed' }],
237
+ 'issue-quick': [{ cmd: 'maestro-plan', args: '--gaps' }, { cmd: 'maestro-execute', args: '' }, { cmd: 'manage-issue', args: 'close {issue_id} --resolution fixed' }],
341
238
  };
342
239
 
343
- // Aliases: task type → named chain
240
+ // Aliases: task type → named multi-step chain
344
241
  const taskToChain = {
345
- 'spec_generate': 'spec-driven',
346
- 'brainstorm': 'brainstorm-driven',
347
- 'issue_execute': 'issue-full', // issue execute always gets review gate
242
+ 'spec_generate': 'spec-driven',
243
+ 'brainstorm': 'brainstorm-driven',
244
+ 'issue_execute': 'issue-full', // issue execute always gets review gate
348
245
  };
349
246
  ```
350
247
 
351
248
  **Resolution order:**
352
- 1. `forceChain` → `chainMap[forceChain]` (E002 if not found)
249
+ 1. `forcedChain` → `chainMap[forcedChain]`
353
250
  2. `state_continue` → `detectNextAction(projectState)`
354
251
  3. `taskToChain[taskType]` → named chain
355
252
  4. `chainMap[taskType]` → direct lookup
356
253
 
357
- ### 3d: Resolve phase, description, and issue ID
254
+ ### 3d: Resolve phase number and issue ID
358
255
 
359
256
  ```javascript
360
257
  function resolvePhase() {
361
258
  // From structured extraction
362
259
  if (intentAnalysis.phase_ref) return intentAnalysis.phase_ref;
363
260
  // Fallback regex
364
- const m = intent.match(new RegExp('^(\\d+)$')) ?? intent.match(new RegExp('phase\\s*(\\d+)', 'i'));
365
- if (m) return m[1] ?? m[2];
366
- if (projectState.initialized) return projectState.current_phase;
261
+ const m = intent.match(/phase\s*(\d+)|^(\d+)$/);
262
+ if (m) return m[1] || m[2];
263
+ // With scratch-based architecture, commands default to milestone-wide when no phase specified
367
264
  return null;
368
265
  }
369
266
 
370
267
  function resolveIssueId() {
371
268
  if (intentAnalysis.issue_id) return intentAnalysis.issue_id;
372
- const m = intent.match(new RegExp('ISS-[\\w]+-\\d+', 'i'));
269
+ const m = intent.match(/ISS-[\w]+-\d+/i);
373
270
  return m ? m[0] : null;
374
271
  }
375
-
376
- const resolvedPhase = resolvePhase();
377
- const resolvedIssueId = resolveIssueId();
378
- const context = {
379
- current_phase: resolvedPhase,
380
- user_intent: intent,
381
- issue_id: resolvedIssueId,
382
- spec_session_id: null,
383
- scratch_dir: null
384
- };
385
272
  ```
386
273
 
274
+ When executing issue chains, replace `{issue_id}` in step args with the resolved issue ID.
275
+
387
276
  ---
388
277
 
389
278
  ## Step 4: Confirm
390
279
 
391
- **If `DRY_RUN`**: Display chain and exit.
280
+ **If `dryRun`:** Display chain and exit.
392
281
 
393
282
  ```
394
- MAESTRO-COORDINATE: {chain_name} (dry run)
395
- 1. ${step.cmd} {step.args}
396
- 2. ${step.cmd} {step.args}
397
-
283
+ MAESTRO-COORDINATE: {chain_name} (dry run)
284
+ 1. [{cmd}] {args}
285
+ 2. [{cmd}] {args}
398
286
  ```
399
287
 
400
- **If not `AUTO_YES`**: Ask user via `functions.request_user_input`:
401
- - Execute all steps
402
- - Execute from step N
403
- - Cancel
288
+ **If not autoYes:** AskUserQuestion Execute / Execute from step N / Cancel.
404
289
 
405
290
  ---
406
291
 
407
292
  ## Step 5: Setup Session
408
293
 
409
294
  ```javascript
410
- const ts = new Date().toISOString().replaceAll('-', '').replaceAll(':', '').replaceAll('T', '').slice(0, 15);
411
- const sessionId = `coord-${ts}`;
295
+ const sessionId = `coord-${new Date().toISOString().replace(/[-:T]/g, '').slice(0, 15)}`;
412
296
  const sessionDir = `.workflow/.maestro-coordinate/${sessionId}`;
413
297
  Bash(`mkdir -p "${sessionDir}"`);
414
298
 
415
299
  const state = {
416
- session_id: sessionId,
417
- status: 'running',
300
+ session_id: sessionId, status: 'running',
418
301
  created_at: new Date().toISOString(),
419
- intent,
420
- task_type: taskType,
421
- chain_name: chainName,
422
- auto_yes: AUTO_YES,
423
- phase: resolvedPhase,
302
+ intent, task_type: taskType, chain_name: chainName,
303
+ tool: cliTool, auto_mode: autoYes, phase: resolvedPhase,
424
304
  current_step: 0,
425
- step_analyses: [], // analysis results per step (for hints chaining)
305
+ gemini_session_id: null,
306
+ step_analyses: [],
426
307
  steps: chain.map((s, i) => ({
427
- index: i,
428
- cmd: s.cmd,
429
- args: s.args ?? '',
430
- status: 'pending',
431
- findings: null,
432
- quality_score: null,
433
- hints_for_next: null
308
+ index: i, cmd: s.cmd, args: s.args || '',
309
+ status: 'pending', exec_id: null, analysis: null
434
310
  }))
435
311
  };
436
312
  Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
313
+
314
+ const context = { resolved_phase: resolvedPhase, user_intent: intent, issue_id: resolvedIssueId, spec_session_id: null };
437
315
  ```
438
316
 
439
317
  ---
440
318
 
441
- ## Step 6: Execute Step via spawn_agent
319
+ ## Step 6: Execute Step via codex delegate
442
320
 
443
321
  ### 6a: Assemble args
444
322
 
445
323
  ```javascript
446
324
  const AUTO_FLAG_MAP = {
447
- 'maestro-analyze': '-y',
448
- 'maestro-brainstorm': '-y',
449
- 'maestro-ui-design': '-y',
450
- 'maestro-plan': '--auto',
451
- 'maestro-spec-generate': '-y',
452
- 'quality-test': '--auto-fix',
453
- 'quality-retrospective': '--auto-yes',
325
+ 'maestro-analyze': '-y', 'maestro-brainstorm': '-y', 'maestro-ui-design': '-y',
326
+ 'maestro-plan': '--auto', 'maestro-spec-generate': '-y', 'quality-test': '--auto-fix',
327
+ 'quality-retrospective': '--auto-yes',
454
328
  };
455
329
 
456
330
  function assembleArgs(step) {
457
- let a = (step.args ?? '')
458
- .replaceAll('{phase}', context.current_phase ?? '')
459
- .replaceAll('{description}', context.user_intent ?? '')
460
- .replaceAll('{issue_id}', context.issue_id ?? '')
461
- .replaceAll('{spec_session_id}', context.spec_session_id ?? '')
462
- .replaceAll('{scratch_dir}', context.scratch_dir ?? '');
463
-
464
- if (AUTO_YES) {
331
+ let a = (step.args || '')
332
+ .replace(/\{phase\}/g, context.resolved_phase || '') // empty = milestone-wide default
333
+ .replace(/\{description\}/g, context.user_intent || '')
334
+ .replace(/\{issue_id\}/g, context.issue_id || '')
335
+ .replace(/\{spec_session_id\}/g, context.spec_session_id || '')
336
+ .replace(/\{scratch_dir\}/g, context.scratch_dir || '');
337
+ if (state.auto_mode) {
465
338
  const flag = AUTO_FLAG_MAP[step.cmd];
466
339
  if (flag && !a.includes(flag)) a = a ? `${a} ${flag}` : flag;
467
340
  }
@@ -469,233 +342,179 @@ function assembleArgs(step) {
469
342
  }
470
343
  ```
471
344
 
472
- ### 6b: Build analysis hints from previous step
473
-
474
- ```javascript
475
- function buildAnalysisHints(stepIdx) {
476
- const prev = state.step_analyses.find(a => a.step_index === stepIdx - 1);
477
- if (!prev?.next_step_hints) return '';
478
- const h = prev.next_step_hints;
479
- const parts = [];
480
- if (h.prompt_additions) parts.push(h.prompt_additions);
481
- if (h.cautions?.length) parts.push('Cautions: ' + h.cautions.join('; '));
482
- if (h.context_to_carry) parts.push('Context from prior step: ' + h.context_to_carry);
483
- return parts.join('\n');
484
- }
485
- ```
345
+ ### 6b: Build prompt from template
486
346
 
487
- ### 6c: Assemble step prompt (replaces coordinate-step.txt template)
488
-
489
- The prompt embeds the skill invocation so the agent knows exactly what to call:
347
+ Read `~/.maestro/templates/cli/prompts/coordinate-step.txt`, fill placeholders.
348
+ If previous step has analysis hints, inject them as `{{ANALYSIS_HINTS}}`.
490
349
 
491
350
  ```javascript
492
- function buildStepPrompt(step, stepIdx, assembledArgs, analysisHints) {
493
- const skillCall = assembledArgs
494
- ? `$${step.cmd} ${assembledArgs}`
495
- : `$${step.cmd}`;
496
-
497
- return `## TASK ASSIGNMENT
498
-
499
- ### MANDATORY FIRST STEPS
500
- 1. Read: ~/.codex/agents/universal-executor.md
501
- 2. Read: ~/.codex/skills/${step.cmd}/SKILL.md
502
-
503
- ---
351
+ function escapeForShell(str) { return "'" + str.replace(/'/g, "'\\''") + "'"; }
504
352
 
505
- **Coordinate Step ${stepIdx + 1}/${state.steps.length}: ${step.cmd}**
506
- Chain: ${state.chain_name}
507
- Intent: ${state.intent}
508
-
509
- ## Skill Invocation
510
- Execute this skill to complete your task:
511
-
512
- ${skillCall}
513
-
514
- Follow the Implementation section of the skill file you loaded in step 2.
515
- ${AUTO_YES ? 'Auto mode: skip all confirmation prompts within the skill.' : ''}
353
+ const assembledArgs = assembleArgs(step);
354
+ const template = Read('~/.maestro/templates/cli/prompts/coordinate-step.txt');
516
355
 
517
- ${analysisHints ? `## Analysis Hints from Previous Step\n${analysisHints}\n` : ''}
518
- ## Output (required — last JSON block in your response)
519
- \`\`\`json
520
- {
521
- "status": "completed",
522
- "quality_score": <0-100>,
523
- "step_summary": "<what was accomplished — max 500 chars>",
524
- "phase_detected": <number or null>,
525
- "spec_session_id": "<if a spec session was created, else null>",
526
- "scratch_dir": "<if a scratch dir was created, else null>",
527
- "hints_for_next": "<specific guidance for the next chain step, or null>"
356
+ // Build analysis hints from previous step's gemini evaluation
357
+ let analysisHints = '';
358
+ const prevAnalysis = (state.step_analyses || []).find(a => a.step_index === state.current_step - 1);
359
+ if (prevAnalysis?.next_step_hints) {
360
+ const h = prevAnalysis.next_step_hints;
361
+ const parts = [];
362
+ if (h.prompt_additions) parts.push(h.prompt_additions);
363
+ if (h.cautions?.length) parts.push('Cautions: ' + h.cautions.join('; '));
364
+ if (h.context_to_carry) parts.push('Context from prior step: ' + h.context_to_carry);
365
+ if (parts.length) analysisHints = parts.join('\n');
528
366
  }
529
- \`\`\`
530
367
 
531
- Session artifacts: ${sessionDir}/`;
532
- }
368
+ const prompt = template
369
+ .replace('{{COMMAND}}', `/${step.cmd}`)
370
+ .replace('{{ARGS}}', assembledArgs)
371
+ .replace('{{STEP_N}}', `${state.current_step + 1}/${state.steps.length}`)
372
+ .replace('{{AUTO_DIRECTIVE}}', state.auto_mode ? 'Auto-confirm all prompts. No interactive questions.' : '')
373
+ .replace('{{CHAIN_NAME}}', state.chain_name)
374
+ .replace('{{ANALYSIS_HINTS}}', analysisHints);
533
375
  ```
534
376
 
535
- ### 6d: Spawn, wait, close
377
+ ### 6c: Launch via codex delegate
536
378
 
537
- ```javascript
538
- const step = state.steps[state.current_step];
539
- const assembledArgs = assembleArgs(step);
540
- const analysisHints = buildAnalysisHints(state.current_step);
541
- const stepPrompt = buildStepPrompt(step, state.current_step, assembledArgs, analysisHints);
379
+ ```
380
+ ------------------------------------------------------------
381
+ STEP {i+1}/{total}: {step.cmd} | Tool: {cliTool}
382
+ ------------------------------------------------------------
383
+ ```
542
384
 
543
- step.status = 'running';
544
- step.started_at = new Date().toISOString();
385
+ ```javascript
386
+ state.steps[state.current_step].status = 'running';
387
+ state.steps[state.current_step].started_at = new Date().toISOString();
545
388
  Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
546
389
 
547
- const stepAgent = spawn_agent({ message: stepPrompt });
548
-
549
- let result = wait({ ids: [stepAgent], timeout_ms: 600000 });
550
- if (result.timed_out) {
551
- send_input({ id: stepAgent, message: "Please finalize and output your results JSON now." });
552
- result = wait({ ids: [stepAgent], timeout_ms: 120000 });
553
- }
554
-
555
- const rawOutput = result.status[stepAgent].completed ?? '';
556
- close_agent({ id: stepAgent });
557
-
558
- // Save raw output for analysis
559
- Write(`${sessionDir}/step-${state.current_step + 1}-output.txt`, rawOutput);
390
+ Bash({
391
+ command: `codex delegate ${escapeForShell(prompt)} --to ${state.tool} --mode write`,
392
+ run_in_background: true, timeout: 600000
393
+ });
394
+ // STOP wait for hook callback
560
395
  ```
561
396
 
562
397
  ---
563
398
 
564
- ## Step 7: Post-Step Processing
565
-
566
- ### 7a: Parse output and propagate context
399
+ ## Step 7: Post-Step Callback
567
400
 
568
401
  ```javascript
569
- const output = parseLastJSON(rawOutput) ?? {
570
- status: result.timed_out ? 'failed' : 'completed',
571
- quality_score: null,
572
- step_summary: rawOutput.slice(-500),
573
- phase_detected: null,
574
- spec_session_id: null,
575
- scratch_dir: null,
576
- hints_for_next: null
577
- };
578
-
579
- // Propagate context to subsequent steps
580
- if (output.phase_detected) context.current_phase = output.phase_detected;
581
- if (output.spec_session_id) context.spec_session_id = output.spec_session_id;
582
- if (output.scratch_dir) context.scratch_dir = output.scratch_dir;
583
-
584
- // Determine step outcome
585
- const stepFailed = output.status === 'failed' || result.timed_out;
586
-
587
- if (stepFailed && AUTO_YES && !step.retried) {
588
- // One auto-retry
589
- step.retried = true;
590
- Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
591
- // → back to Step 6d with same step
592
- } else if (stepFailed && !AUTO_YES) {
593
- // Ask: Retry / Skip / Abort
594
- const choice = functions.request_user_input({
595
- id: 'step-failure',
596
- items: [{ type: 'text', text: `Step ${state.current_step + 1} (${step.cmd}) failed. Retry / Skip / Abort?` }]
597
- });
598
- if (choice === 'Retry') { /* → back to Step 6d */ }
599
- if (choice === 'Abort') {
600
- state.status = 'aborted';
601
- Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
602
- return; // exit
603
- }
604
- // Skip: fall through
605
- step.status = 'skipped';
606
- } else if (stepFailed) {
402
+ const stepIdx = state.current_step;
403
+ const step = state.steps[stepIdx];
404
+ const output = /* callback output */;
405
+
406
+ // Capture exec_id from stderr [CODEX_EXEC_ID=xxx]
407
+ step.exec_id = /* from callback */;
408
+ step.completed_at = new Date().toISOString();
409
+
410
+ // Context propagation
411
+ const phaseMatch = output.match(/PHASE:\s*(\d+)/m);
412
+ if (phaseMatch) context.resolved_phase = phaseMatch[1];
413
+ const specMatch = output.match(/SPEC-[\w-]+/);
414
+ if (specMatch) context.spec_session_id = specMatch[0];
415
+ const scratchMatch = output.match(/scratch_dir:\s*(.+)/m);
416
+ if (scratchMatch) context.scratch_dir = scratchMatch[1].trim();
417
+
418
+ // Success/failure
419
+ const failed = /^STATUS:\s*FAILURE/m.test(output);
420
+ if (!failed) {
421
+ step.status = 'completed';
422
+ } else if (state.auto_mode) {
423
+ if (!step.retried) { step.retried = true; /* re-execute Step 6c */ return; }
607
424
  step.status = 'skipped';
608
425
  } else {
609
- step.status = 'completed';
426
+ // AskUserQuestion: Retry / Skip / Abort
427
+ // On Abort: state.status = 'aborted', save, exit
610
428
  }
611
429
 
612
- step.findings = output.step_summary;
613
- step.quality_score = output.quality_score;
614
- step.hints_for_next= output.hints_for_next;
615
- step.completed_at = new Date().toISOString();
430
+ // Save output for analysis
431
+ Write(`${sessionDir}/step-${stepIdx + 1}-output.txt`, output);
616
432
  Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
617
- ```
618
-
619
- ### 7b: Analyze step output (inline analysis agent)
620
433
 
621
- Skip if: step failed/skipped **or** chain has only one step.
622
-
623
- ```javascript
434
+ // → Step 7b: Gemini analysis (skip if step failed/skipped or single-step chain)
624
435
  if (step.status === 'completed' && state.steps.length > 1) {
625
- const nextStep = state.steps[state.current_step + 1] ?? null;
626
- const priorAnalysesSummary = state.step_analyses
627
- .map(a => `- Step ${a.step_index + 1} (${a.cmd}): score=${a.quality_score}, issues=${a.issues?.length ?? 0}`)
628
- .join('\n');
629
-
630
- const analysisPrompt = `## TASK ASSIGNMENT
631
-
632
- ### MANDATORY FIRST STEPS
633
- 1. Read: ~/.codex/agents/cli-explore-agent.md
436
+ // Step 7b
437
+ } else {
438
+ // Skip analysis, advance directly
439
+ state.current_step = stepIdx + 1;
440
+ Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
441
+ if (state.current_step < state.steps.length) { /* → Step 6 */ }
442
+ else { /* → Step 8 */ }
443
+ }
444
+ ```
634
445
 
635
446
  ---
636
447
 
637
- Goal: Evaluate execution quality of coordinate step and generate optimization hints for the next step.
638
-
639
- Step: $${step.cmd} (step ${state.current_step + 1}/${state.steps.length})
640
- Chain: ${state.chain_name} | Intent: ${state.intent}
448
+ ## Step 7b: Analyze Step Output (via gemini)
641
449
 
642
- Step output (last 200 lines):
643
- ${rawOutput.split('\n').slice(-200).join('\n')}
450
+ After each step completes, call gemini to evaluate execution quality and generate optimization hints for subsequent steps.
644
451
 
645
- ${priorAnalysesSummary ? `Prior step analyses:\n${priorAnalysesSummary}\n` : ''}
646
- Next step: ${nextStep ? `$${nextStep.cmd} ${assembleArgs(nextStep)}` : 'None (last step)'}
647
-
648
- ## Output (strict JSON)
649
- \`\`\`json
452
+ ```javascript
453
+ const stepIdx = state.current_step;
454
+ const step = state.steps[stepIdx];
455
+ const output = Read(`${sessionDir}/step-${stepIdx + 1}-output.txt`);
456
+ const nextStep = stepIdx < state.steps.length - 1 ? state.steps[stepIdx + 1] : null;
457
+
458
+ // Build analysis prompt
459
+ const priorAnalyses = (state.step_analyses || [])
460
+ .map(a => `- Step ${a.step_index + 1} (${a.cmd}): score=${a.quality_score}, issues=${a.issues?.length || 0}`)
461
+ .join('\n');
462
+
463
+ const analysisPrompt = `PURPOSE: Evaluate execution quality of coordinate step "${step.cmd}" (${stepIdx + 1}/${state.steps.length}) and generate optimization hints for the next step.
464
+ CHAIN: ${state.chain_name} | Intent: ${state.intent}
465
+ COMMAND: /${step.cmd} ${step.args || ''}
466
+ STEP OUTPUT (last 200 lines):
467
+ ${output.split('\n').slice(-200).join('\n')}
468
+ ${priorAnalyses ? `PRIOR STEP ANALYSES:\n${priorAnalyses}` : ''}
469
+ ${nextStep ? `NEXT STEP: /${nextStep.cmd} ${nextStep.args || ''}` : 'NEXT STEP: None (last step)'}
470
+ EXPECTED OUTPUT (strict JSON):
650
471
  {
651
472
  "quality_score": <0-100>,
652
- "execution_assessment": {
653
- "success": <bool>,
654
- "completeness": "full|partial|minimal",
655
- "key_outputs": [],
656
- "missing_outputs": []
657
- },
473
+ "execution_assessment": { "success": <bool>, "completeness": "<full|partial|minimal>", "key_outputs": [], "missing_outputs": [] },
658
474
  "issues": [{ "severity": "critical|high|medium|low", "description": "" }],
659
475
  "next_step_hints": {
660
476
  "prompt_additions": "<extra context or constraints to inject into next step prompt>",
661
477
  "cautions": ["<things next step should watch out for>"],
662
- "context_to_carry": "<key facts from this step that next step needs>"
478
+ "context_to_carry": "<key facts from this step's output that next step needs>"
663
479
  },
664
480
  "step_summary": ""
665
- }
666
- \`\`\``;
481
+ }`;
667
482
 
668
- const analysisAgent = spawn_agent({ message: analysisPrompt });
669
- let aResult = wait({ ids: [analysisAgent], timeout_ms: 300000 });
670
- if (aResult.timed_out) {
671
- send_input({ id: analysisAgent, message: "Finalize and output analysis JSON now." });
672
- aResult = wait({ ids: [analysisAgent], timeout_ms: 60000 });
673
- }
674
- close_agent({ id: analysisAgent });
675
-
676
- const analysis = parseLastJSON(aResult.status[analysisAgent].completed ?? '') ?? {};
677
- state.step_analyses.push({
678
- step_index: state.current_step,
679
- cmd: step.cmd,
680
- quality_score: analysis.quality_score,
681
- issues: analysis.issues,
682
- next_step_hints: analysis.next_step_hints,
683
- summary: analysis.step_summary
684
- });
685
- step.quality_score = analysis.quality_score ?? step.quality_score;
686
- Write(`${sessionDir}/step-${state.current_step + 1}-analysis.json`, JSON.stringify(analysis, null, 2));
687
- Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
688
- }
483
+ let delegateCmd = `codex delegate ${escapeForShell(analysisPrompt)} --to gemini --mode analysis --rule analysis-review-code-quality`;
484
+ if (state.gemini_session_id) delegateCmd += ` --resume ${state.gemini_session_id}`;
485
+ Bash({ command: delegateCmd, run_in_background: true, timeout: 300000 });
486
+ // STOP wait for hook callback
689
487
  ```
690
488
 
691
- ### 7c: Advance
489
+ ### Step 7c: Post-Analyze Callback
692
490
 
693
491
  ```javascript
694
- state.current_step += 1;
492
+ const analysisResult = /* parsed JSON from callback output */;
493
+
494
+ // Capture gemini session ID for resume chain
495
+ state.gemini_session_id = /* from callback stderr [CODEX_EXEC_ID=xxx] */;
496
+
497
+ // Store analysis
498
+ if (!state.step_analyses) state.step_analyses = [];
499
+ state.step_analyses.push({
500
+ step_index: stepIdx, cmd: step.cmd,
501
+ quality_score: analysisResult.quality_score,
502
+ issues: analysisResult.issues,
503
+ next_step_hints: analysisResult.next_step_hints,
504
+ summary: analysisResult.step_summary
505
+ });
506
+ step.analysis = {
507
+ quality_score: analysisResult.quality_score,
508
+ issue_count: (analysisResult.issues || []).length
509
+ };
510
+ Write(`${sessionDir}/step-${stepIdx + 1}-analysis.json`, JSON.stringify(analysisResult, null, 2));
511
+
512
+ // Advance
513
+ state.current_step = stepIdx + 1;
695
514
  Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
696
515
 
697
516
  if (state.current_step < state.steps.length) {
698
- // → back to Step 6
517
+ // → Back to Step 6
699
518
  } else {
700
519
  // → Step 8
701
520
  }
@@ -706,34 +525,26 @@ if (state.current_step < state.steps.length) {
706
525
  ## Step 8: Completion Report
707
526
 
708
527
  ```javascript
709
- const done = state.steps.filter(s => s.status === 'completed').length;
710
- const skipped = state.steps.filter(s => s.status === 'skipped').length;
711
- const avgScore = state.step_analyses.length
712
- ? Math.round(state.step_analyses.reduce((s, a) => s + (a.quality_score ?? 0), 0) / state.step_analyses.length)
713
- : null;
714
-
528
+ const done = state.steps.filter(s => s.status === 'completed').length;
715
529
  state.status = state.steps.some(s => s.status === 'failed') ? 'completed_with_errors' : 'completed';
716
530
  state.completed_at = new Date().toISOString();
717
531
  Write(`${sessionDir}/state.json`, JSON.stringify(state, null, 2));
718
532
  ```
719
533
 
720
- Display:
721
534
  ```
722
535
  ============================================================
723
536
  MAESTRO-COORDINATE COMPLETE
724
537
  ============================================================
725
- Session: {session_id}
726
- Chain: {chain_name} ({done}/{total} steps)
538
+ Session: {session_id}
539
+ Chain: {chain_name} ({done}/{total})
540
+ Tool: {cliTool}
727
541
 
728
542
  Steps:
729
- [✓] 1. {cmd} — completed (quality: {score}/100)
730
- [✓] 2. {cmd} — completed (quality: {score}/100)
731
- [⚠] 3. {cmd} — skipped
732
-
733
- Avg Quality: {avgScore}/100
734
- Artifacts: .workflow/.maestro-coordinate/{session_id}/
543
+ [✓] 1. maestro-plan — completed (quality: 85/100)
544
+ [✓] 2. maestro-execute — completed (quality: 78/100)
735
545
 
736
- Resume: $maestro-coordinate --continue
546
+ Avg Quality: {avg_score}/100
547
+ Next: $Maestro-coordinate --continue
737
548
  ============================================================
738
549
  ```
739
550
 
@@ -741,15 +552,15 @@ Display:
741
552
 
742
553
  ## Core Rules
743
554
 
744
- 1. **Semantic routing**: LLM-native structured extraction (`action × object`) replaces regex; disambiguates "问题" by context
745
- 2. **Sequential**: Advance `current_step` only after the current step agent is **closed** and state written
746
- 3. **Skill in prompt**: Every step agent's message MUST contain `$skill-name args` this is the skill invocation
747
- 4. **MANDATORY FIRST STEPS**: Step agents read `universal-executor.md` + the target `SKILL.md`; analysis agents read `cli-explore-agent.md`
748
- 5. **Context propagation**: Parse `phase_detected`, `spec_session_id`, `scratch_dir`, `issue_id` from each step's output JSON; feed into next step's `assembleArgs`
749
- 6. **Quality gates**: Issue chains auto-include review; `issue-full` is default for issue execution
750
- 7. **Analysis hints chain**: `step_analyses[N].next_step_hints` `buildAnalysisHints(N+1)` injected into step N+1's prompt
751
- 8. **Timeout handling**: One `send_input` urge, then close agent regardless
752
- 9. **Auto-retry**: One silent retry if `AUTO_YES` and step fails; no retry in interactive mode
753
- 10. **State.json is source of truth**: Write after every state change; `--continue` reads it to resume
754
- 11. **Dry-run is read-only**: Display chain and exit no agents spawned
755
- 12. **Analysis skip conditions**: Single-step chains and failed/skipped steps skip the analysis agent
555
+ 1. **Semantic routing** LLM-native structured extraction (`action × object`) replaces regex; disambiguates "问题" by context
556
+ 2. **STOP after each `codex delegate` call** background execution, wait for hook callback
557
+ 3. **State machine** advance via `current_step`, no sync loops for async operations
558
+ 4. **Template-driven** all steps use `coordinate-step.txt`, no per-command prompt assembly
559
+ 5. **Context propagation** parse PHASE / spec session ID / scratch_dir / issue_id from each step output, feed to next step
560
+ 6. **Quality gates** issue chains auto-include review; `issue-full` is default for issue execution
561
+ 7. **Tool fallback** if `codex delegate` fails: retry with same tool once, then try `gemini` → `qwen`
562
+ 8. **Auto-confirm injection** `{{AUTO_DIRECTIVE}}` in template prevents blocking during background execution
563
+ 9. **Resumable** `-c` reads `state.json`, jumps to first pending step
564
+ 10. **Gemini analysis after each step** evaluate output quality via `codex delegate --to gemini --mode analysis`, chained via `--resume`. Analysis generates `next_step_hints` injected into next step's prompt as `{{ANALYSIS_HINTS}}`
565
+ 11. **Session capture** after each gemini callback, capture exec_id `gemini_session_id` for resume chain
566
+ 12. **Analysis skip conditions** skip gemini analysis for: failed/skipped steps, single-step chains