maestro-flow 0.3.46 → 0.3.47

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 (241) hide show
  1. package/.claude/agents/ui-design-agent.md +1 -0
  2. package/.claude/agents/workflow-executor.md +3 -0
  3. package/.claude/commands/learn-decompose.md +91 -146
  4. package/.claude/commands/learn-follow.md +102 -137
  5. package/.claude/commands/learn-investigate.md +102 -167
  6. package/.claude/commands/learn-retro.md +100 -243
  7. package/.claude/commands/learn-second-opinion.md +95 -135
  8. package/.claude/commands/maestro-amend.md +95 -232
  9. package/.claude/commands/maestro-analyze.md +1 -6
  10. package/.claude/commands/maestro-collab.md +104 -265
  11. package/.claude/commands/maestro-composer.md +113 -293
  12. package/.claude/commands/maestro-execute.md +10 -17
  13. package/.claude/commands/maestro-impeccable.md +89 -0
  14. package/.claude/commands/maestro-plan.md +1 -6
  15. package/.claude/commands/maestro-player.md +111 -340
  16. package/.claude/commands/maestro-quick.md +9 -0
  17. package/.claude/commands/maestro-ralph-execute.md +167 -210
  18. package/.claude/commands/maestro-ralph.md +245 -426
  19. package/.claude/commands/maestro-ui-codify.md +13 -0
  20. package/.claude/commands/maestro-ui-craft.md +364 -0
  21. package/.claude/commands/maestro-ui-design.md +12 -1
  22. package/.claude/commands/maestro-verify.md +12 -13
  23. package/.claude/commands/maestro.md +142 -72
  24. package/.claude/commands/manage-knowhow-capture.md +45 -170
  25. package/.claude/commands/quality-auto-test.md +9 -0
  26. package/.claude/commands/quality-debug.md +11 -25
  27. package/.claude/commands/quality-refactor.md +9 -0
  28. package/.claude/commands/quality-review.md +5 -14
  29. package/.claude/commands/spec-add.md +1 -1
  30. package/.claude/commands/spec-load.md +3 -2
  31. package/.claude/skills/maestro-impeccable/SKILL.md +169 -0
  32. package/.codex/skills/learn-decompose/SKILL.md +1 -1
  33. package/.codex/skills/learn-investigate/SKILL.md +2 -1
  34. package/.codex/skills/maestro/SKILL.md +278 -313
  35. package/.codex/skills/maestro-analyze/SKILL.md +126 -417
  36. package/.codex/skills/maestro-brainstorm/SKILL.md +129 -451
  37. package/.codex/skills/maestro-collab/SKILL.md +134 -547
  38. package/.codex/skills/maestro-execute/SKILL.md +3 -1
  39. package/.codex/skills/maestro-impeccable/SKILL.md +112 -0
  40. package/.codex/skills/maestro-plan/SKILL.md +88 -437
  41. package/.codex/skills/maestro-player/SKILL.md +191 -333
  42. package/.codex/skills/maestro-quick/SKILL.md +2 -0
  43. package/.codex/skills/maestro-ralph/SKILL.md +307 -710
  44. package/.codex/skills/maestro-roadmap/SKILL.md +201 -518
  45. package/.codex/skills/maestro-ui-codify/SKILL.md +1 -0
  46. package/.codex/skills/maestro-ui-craft/SKILL.md +341 -0
  47. package/.codex/skills/maestro-ui-design/SKILL.md +10 -0
  48. package/.codex/skills/maestro-verify/SKILL.md +116 -409
  49. package/.codex/skills/quality-auto-test/SKILL.md +145 -443
  50. package/.codex/skills/quality-refactor/SKILL.md +1 -1
  51. package/.codex/skills/quality-test/SKILL.md +229 -517
  52. package/.codex/skills/spec-add/SKILL.md +1 -1
  53. package/README.md +4 -1
  54. package/README.zh-CN.md +3 -1
  55. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.js +3 -0
  56. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.js.map +1 -1
  57. package/dashboard/dist-server/dashboard/src/server/routes/install.js +110 -1
  58. package/dashboard/dist-server/dashboard/src/server/routes/install.js.map +1 -1
  59. package/dashboard/dist-server/dashboard/src/server/routes/settings.js +56 -0
  60. package/dashboard/dist-server/dashboard/src/server/routes/settings.js.map +1 -1
  61. package/dashboard/dist-server/dashboard/src/server/routes/wiki.js +2 -0
  62. package/dashboard/dist-server/dashboard/src/server/routes/wiki.js.map +1 -1
  63. package/dashboard/dist-server/dashboard/src/server/wiki/spec-entry-parser.js +2 -2
  64. package/dashboard/dist-server/dashboard/src/server/wiki/spec-entry-parser.js.map +1 -1
  65. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +2 -0
  66. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  67. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-types.d.ts +3 -1
  68. package/dashboard/dist-server/dashboard/src/shared/constants.d.ts +2 -0
  69. package/dashboard/dist-server/dashboard/src/shared/constants.js +2 -0
  70. package/dashboard/dist-server/dashboard/src/shared/constants.js.map +1 -1
  71. package/dist/src/agents/cli-agent-runner.d.ts.map +1 -1
  72. package/dist/src/agents/cli-agent-runner.js +1 -3
  73. package/dist/src/agents/cli-agent-runner.js.map +1 -1
  74. package/dist/src/agents/cli-history-store.d.ts +5 -0
  75. package/dist/src/agents/cli-history-store.d.ts.map +1 -1
  76. package/dist/src/agents/cli-history-store.js +65 -13
  77. package/dist/src/agents/cli-history-store.js.map +1 -1
  78. package/dist/src/cli.js +13 -0
  79. package/dist/src/cli.js.map +1 -1
  80. package/dist/src/commands/command-help.d.ts +3 -0
  81. package/dist/src/commands/command-help.d.ts.map +1 -0
  82. package/dist/src/commands/command-help.js +60 -0
  83. package/dist/src/commands/command-help.js.map +1 -0
  84. package/dist/src/commands/config.d.ts.map +1 -1
  85. package/dist/src/commands/config.js +17 -0
  86. package/dist/src/commands/config.js.map +1 -1
  87. package/dist/src/commands/delegate.d.ts.map +1 -1
  88. package/dist/src/commands/delegate.js +12 -2
  89. package/dist/src/commands/delegate.js.map +1 -1
  90. package/dist/src/commands/impeccable.d.ts +10 -0
  91. package/dist/src/commands/impeccable.d.ts.map +1 -0
  92. package/dist/src/commands/impeccable.js +181 -0
  93. package/dist/src/commands/impeccable.js.map +1 -0
  94. package/dist/src/commands/spec.js +1 -1
  95. package/dist/src/commands/spec.js.map +1 -1
  96. package/dist/src/commands/wiki.d.ts.map +1 -1
  97. package/dist/src/commands/wiki.js +5 -1
  98. package/dist/src/commands/wiki.js.map +1 -1
  99. package/dist/src/config/cli-tools-config.d.ts.map +1 -1
  100. package/dist/src/config/cli-tools-config.js +10 -7
  101. package/dist/src/config/cli-tools-config.js.map +1 -1
  102. package/dist/src/core/addon-registry.d.ts +31 -0
  103. package/dist/src/core/addon-registry.d.ts.map +1 -0
  104. package/dist/src/core/addon-registry.js +28 -0
  105. package/dist/src/core/addon-registry.js.map +1 -0
  106. package/dist/src/hooks/plugins/spec-injection-plugin.js +2 -0
  107. package/dist/src/hooks/plugins/spec-injection-plugin.js.map +1 -1
  108. package/dist/src/hooks/spec-injector.js +2 -2
  109. package/dist/src/hooks/spec-injector.js.map +1 -1
  110. package/dist/src/index.d.ts +2 -0
  111. package/dist/src/index.d.ts.map +1 -1
  112. package/dist/src/index.js +1 -0
  113. package/dist/src/index.js.map +1 -1
  114. package/dist/src/tools/impeccable/critique-storage.d.ts +28 -0
  115. package/dist/src/tools/impeccable/critique-storage.d.ts.map +1 -0
  116. package/dist/src/tools/impeccable/critique-storage.js +120 -0
  117. package/dist/src/tools/impeccable/critique-storage.js.map +1 -0
  118. package/dist/src/tools/impeccable/design-parser.d.ts +90 -0
  119. package/dist/src/tools/impeccable/design-parser.d.ts.map +1 -0
  120. package/dist/src/tools/impeccable/design-parser.js +696 -0
  121. package/dist/src/tools/impeccable/design-parser.js.map +1 -0
  122. package/dist/src/tools/impeccable/detect-csp.d.ts +6 -0
  123. package/dist/src/tools/impeccable/detect-csp.d.ts.map +1 -0
  124. package/dist/src/tools/impeccable/detect-csp.js +130 -0
  125. package/dist/src/tools/impeccable/detect-csp.js.map +1 -0
  126. package/dist/src/tools/impeccable/is-generated.d.ts +4 -0
  127. package/dist/src/tools/impeccable/is-generated.d.ts.map +1 -0
  128. package/dist/src/tools/impeccable/is-generated.js +56 -0
  129. package/dist/src/tools/impeccable/is-generated.js.map +1 -0
  130. package/dist/src/tools/impeccable/live/accept.d.ts +50 -0
  131. package/dist/src/tools/impeccable/live/accept.d.ts.map +1 -0
  132. package/dist/src/tools/impeccable/live/accept.js +556 -0
  133. package/dist/src/tools/impeccable/live/accept.js.map +1 -0
  134. package/dist/src/tools/impeccable/live/bootstrap.d.ts +2 -0
  135. package/dist/src/tools/impeccable/live/bootstrap.d.ts.map +1 -0
  136. package/dist/src/tools/impeccable/live/bootstrap.js +244 -0
  137. package/dist/src/tools/impeccable/live/bootstrap.js.map +1 -0
  138. package/dist/src/tools/impeccable/live/complete.d.ts +7 -0
  139. package/dist/src/tools/impeccable/live/complete.d.ts.map +1 -0
  140. package/dist/src/tools/impeccable/live/complete.js +67 -0
  141. package/dist/src/tools/impeccable/live/complete.js.map +1 -0
  142. package/dist/src/tools/impeccable/live/completion.d.ts +24 -0
  143. package/dist/src/tools/impeccable/live/completion.d.ts.map +1 -0
  144. package/dist/src/tools/impeccable/live/completion.js +26 -0
  145. package/dist/src/tools/impeccable/live/completion.js.map +1 -0
  146. package/dist/src/tools/impeccable/live/inject.d.ts +41 -0
  147. package/dist/src/tools/impeccable/live/inject.d.ts.map +1 -0
  148. package/dist/src/tools/impeccable/live/inject.js +394 -0
  149. package/dist/src/tools/impeccable/live/inject.js.map +1 -0
  150. package/dist/src/tools/impeccable/live/poll.d.ts +24 -0
  151. package/dist/src/tools/impeccable/live/poll.d.ts.map +1 -0
  152. package/dist/src/tools/impeccable/live/poll.js +180 -0
  153. package/dist/src/tools/impeccable/live/poll.js.map +1 -0
  154. package/dist/src/tools/impeccable/live/resume.d.ts +5 -0
  155. package/dist/src/tools/impeccable/live/resume.d.ts.map +1 -0
  156. package/dist/src/tools/impeccable/live/resume.js +30 -0
  157. package/dist/src/tools/impeccable/live/resume.js.map +1 -0
  158. package/dist/src/tools/impeccable/live/server.d.ts +6 -0
  159. package/dist/src/tools/impeccable/live/server.d.ts.map +1 -0
  160. package/dist/src/tools/impeccable/live/server.js +867 -0
  161. package/dist/src/tools/impeccable/live/server.js.map +1 -0
  162. package/dist/src/tools/impeccable/live/session-store.d.ts +72 -0
  163. package/dist/src/tools/impeccable/live/session-store.d.ts.map +1 -0
  164. package/dist/src/tools/impeccable/live/session-store.js +281 -0
  165. package/dist/src/tools/impeccable/live/session-store.js.map +1 -0
  166. package/dist/src/tools/impeccable/live/static/live-browser-session.js +123 -0
  167. package/dist/src/tools/impeccable/live/static/live-browser.js +4860 -0
  168. package/dist/src/tools/impeccable/live/static/modern-screenshot.umd.js +14 -0
  169. package/dist/src/tools/impeccable/live/status.d.ts +2 -0
  170. package/dist/src/tools/impeccable/live/status.d.ts.map +1 -0
  171. package/dist/src/tools/impeccable/live/status.js +52 -0
  172. package/dist/src/tools/impeccable/live/status.js.map +1 -0
  173. package/dist/src/tools/impeccable/live/wrap.d.ts +33 -0
  174. package/dist/src/tools/impeccable/live/wrap.d.ts.map +1 -0
  175. package/dist/src/tools/impeccable/live/wrap.js +572 -0
  176. package/dist/src/tools/impeccable/live/wrap.js.map +1 -0
  177. package/dist/src/tools/impeccable/load-context.d.ts +13 -0
  178. package/dist/src/tools/impeccable/load-context.d.ts.map +1 -0
  179. package/dist/src/tools/impeccable/load-context.js +79 -0
  180. package/dist/src/tools/impeccable/load-context.js.map +1 -0
  181. package/dist/src/tools/impeccable/paths.d.ts +34 -0
  182. package/dist/src/tools/impeccable/paths.d.ts.map +1 -0
  183. package/dist/src/tools/impeccable/paths.js +102 -0
  184. package/dist/src/tools/impeccable/paths.js.map +1 -0
  185. package/dist/src/tools/spec-entry-parser.d.ts +1 -1
  186. package/dist/src/tools/spec-entry-parser.d.ts.map +1 -1
  187. package/dist/src/tools/spec-entry-parser.js +1 -1
  188. package/dist/src/tools/spec-entry-parser.js.map +1 -1
  189. package/dist/src/tools/spec-init.d.ts.map +1 -1
  190. package/dist/src/tools/spec-init.js +26 -1
  191. package/dist/src/tools/spec-init.js.map +1 -1
  192. package/dist/src/tools/spec-loader.d.ts +1 -1
  193. package/dist/src/tools/spec-loader.d.ts.map +1 -1
  194. package/dist/src/tools/spec-loader.js +2 -0
  195. package/dist/src/tools/spec-loader.js.map +1 -1
  196. package/package.json +2 -2
  197. package/workflows/claude-instructions.md +17 -5
  198. package/workflows/cli-tools-usage.md +10 -3
  199. package/workflows/delegate-usage.md +3 -2
  200. package/workflows/impeccable/adapt.md +190 -0
  201. package/workflows/impeccable/animate.md +175 -0
  202. package/workflows/impeccable/audit.md +133 -0
  203. package/workflows/impeccable/bolder.md +113 -0
  204. package/workflows/impeccable/brand.md +118 -0
  205. package/workflows/impeccable/clarify.md +174 -0
  206. package/workflows/impeccable/codex.md +105 -0
  207. package/workflows/impeccable/cognitive-load.md +106 -0
  208. package/workflows/impeccable/color-and-contrast.md +105 -0
  209. package/workflows/impeccable/colorize.md +154 -0
  210. package/workflows/impeccable/craft.md +123 -0
  211. package/workflows/impeccable/critique.md +261 -0
  212. package/workflows/impeccable/delight.md +302 -0
  213. package/workflows/impeccable/distill.md +111 -0
  214. package/workflows/impeccable/document.md +439 -0
  215. package/workflows/impeccable/extract.md +69 -0
  216. package/workflows/impeccable/harden.md +347 -0
  217. package/workflows/impeccable/heuristics-scoring.md +234 -0
  218. package/workflows/impeccable/interaction-design.md +195 -0
  219. package/workflows/impeccable/layout.md +141 -0
  220. package/workflows/impeccable/live.md +622 -0
  221. package/workflows/impeccable/motion-design.md +109 -0
  222. package/workflows/impeccable/onboard.md +234 -0
  223. package/workflows/impeccable/optimize.md +258 -0
  224. package/workflows/impeccable/overdrive.md +130 -0
  225. package/workflows/impeccable/personas.md +179 -0
  226. package/workflows/impeccable/polish.md +242 -0
  227. package/workflows/impeccable/product.md +62 -0
  228. package/workflows/impeccable/quieter.md +99 -0
  229. package/workflows/impeccable/responsive-design.md +114 -0
  230. package/workflows/impeccable/shape.md +165 -0
  231. package/workflows/impeccable/spatial-design.md +100 -0
  232. package/workflows/impeccable/teach.md +168 -0
  233. package/workflows/impeccable/typeset.md +124 -0
  234. package/workflows/impeccable/typography.md +159 -0
  235. package/workflows/impeccable/ux-writing.md +107 -0
  236. package/workflows/impeccable.md +164 -0
  237. package/workflows/maestro.md +7 -3
  238. package/workflows/skill-authoring.md +265 -0
  239. package/workflows/specs-add.md +3 -2
  240. package/workflows/specs-load.md +2 -1
  241. package/workflows/specs-setup.md +21 -1
@@ -14,24 +14,35 @@ allowed-tools:
14
14
  ---
15
15
  <purpose>
16
16
  Closed-loop decision engine for the maestro workflow lifecycle.
17
+ Reads project state → infers position → builds adaptive chain → delegates execution.
17
18
 
18
- Reads project state → infers lifecycle position → builds adaptive command chain → delegates execution.
19
+ Entry points:
20
+ - **`/maestro-ralph "intent"`** — New session: infer → build → execute
21
+ - **`/maestro-ralph continue`** — Resume via maestro-ralph-execute
22
+ - **`/maestro-ralph status`** — Display session progress
19
23
 
20
24
  Three node types:
21
- - **internal**: In-session `Skill()` call (synchronous, lightweight)
22
- - **external**: New Claude Code session via `maestro delegate --to claude` executing `/{skill} {args}` (context-isolated, heavy computation)
25
+ - **internal**: `Skill()` call (synchronous, lightweight)
26
+ - **external**: `maestro delegate --to claude` (context-isolated, heavy computation)
23
27
  - **decision**: Hand back to ralph for re-evaluation (adaptive branching)
24
28
 
25
29
  Key difference from maestro coordinator:
26
- - maestro: static chain → one-time selection → runs all steps sequentially
27
- - ralph: living chain → decision nodes re-evaluate after critical steps → chain grows/shrinks dynamically
30
+ - maestro: static chain → one-time selection → runs all steps
31
+ - ralph: living chain → decision nodes re-evaluate → chain grows/shrinks dynamically
28
32
 
29
- Session path: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
33
+ Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
30
34
  Mutual invocation with `/maestro-ralph-execute` forms a self-perpetuating work loop.
31
35
  </purpose>
32
36
 
33
37
  <context>
34
- $ARGUMENTS — user intent text, flags, or keywords.
38
+ $ARGUMENTS — intent text, flags, or keywords.
39
+
40
+ **Parse:**
41
+ ```
42
+ -y flag → auto_confirm = true
43
+ .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
44
+ Remaining → intent
45
+ ```
35
46
 
36
47
  **State files:**
37
48
  - `.workflow/state.json` — artifact registry, milestones, phases
@@ -39,137 +50,149 @@ $ARGUMENTS — user intent text, flags, or keywords.
39
50
  - `.workflow/.maestro/ralph-*/status.json` — ralph session state
40
51
  </context>
41
52
 
42
- <execution>
43
-
44
- ## Step 1: Parse & Route
45
-
46
- ```
47
- Parse $ARGUMENTS:
48
- -y flag → auto_confirm = true (skip confirmation, NOT ambiguity resolution)
49
- .md/.txt path → input_doc (supplementary context for downstream commands)
50
- Remaining → intent
51
-
52
- Route:
53
- intent == "status" → handleStatus()
54
- intent == "continue" handleContinue()
55
-
56
- Check running ralph session (.workflow/.maestro/ralph-*/status.json, session status=="running"):
57
- If found AND steps[current_step].type == "decision" AND steps[current_step].status == "running":
58
- Step 3: Decision Evaluation Mode
59
- Else if intent is non-empty:
60
- Step 2: New Session Mode
61
- Else:
62
- AskUserQuestion: "请描述目标,或输入 status/continue"
63
- ```
64
-
65
- ### handleStatus()
66
- ```
67
- Find latest ralph session (by created_at).
68
- Display:
69
- Session: {id}
70
- Status: {status}
71
- Position: {lifecycle_position}
72
- Progress: {completed}/{total} commands
73
- Current: [{current_step}] {steps[current_step].skill} [{type}]
74
-
75
- Commands:
76
- [✓] 0. maestro-analyze 1 [external]
77
- [▸] 1. maestro-plan 1 [internal]
78
- [ ] 2. maestro-execute 1 [external]
79
- ...
80
- End.
81
- ```
82
-
83
- ### handleContinue()
84
- ```
85
- Find latest running ralph session.
86
- If not found → "无运行中的 ralph 会话". End.
87
- Skill({ skill: "maestro-ralph-execute" }). End.
88
- ```
89
-
90
- ---
91
-
92
- ## Step 2: New Session Mode
93
-
94
- ### 2.1: Read project state
95
-
96
- Read `.workflow/state.json` schema:
97
- ```json
98
- {
99
- "current_milestone": "MVP",
100
- "milestones": [{ "id": "M1", "name": "MVP", "status": "active", "phases": [1, 2] }],
101
- "artifacts": [{
102
- "id": "ANL-001", "type": "analyze|plan|execute|verify",
103
- "milestone": "MVP", "phase": 1, "scope": "phase|milestone|adhoc|standalone",
104
- "path": "phases/01-auth-multi-tenant", // relative to .workflow/scratch/
105
- "status": "completed", "depends_on": "PLN-001", "harvested": true
106
- }],
107
- "accumulated_context": { "key_decisions": [], "deferred": [] }
108
- }
109
- ```
110
-
111
- Also check: `.workflow/roadmap.md` existence, `.workflow/scratch/` for result files.
112
-
113
- ### 2.2: Infer lifecycle position
114
-
115
- **Phase 0 Intent-based override:**
116
-
117
- If intent matches brainstorm pattern (contains "brainstorm", "头脑风暴", "探索", "ideate", or "设计思路"), position = `brainstorm` regardless of project state.
53
+ <invariants>
54
+ 1. **Ralph never executes steps** — only creates sessions and evaluates decisions
55
+ 2. **Handoff via Skill("maestro-ralph-execute")** at session creation and after decision evaluation
56
+ 3. **Decision delegates read-only** — `maestro delegate --role analyze --mode analysis`
57
+ 4. **External ≠ CLI call** — external spawns full Claude Code session executing the skill command
58
+ 5. **Delegate sessions non-interactive** — all external skills MUST append `-y` to args inside the prompt
59
+ </invariants>
60
+
61
+ <state_machine>
62
+
63
+ <states>
64
+ S_PARSE_ROUTE — 解析参数、路由入口 PERSIST:
65
+ S_STATUS — 显示 session 进度 PERSIST:
66
+ S_CONTINUE — 恢复执行 PERSIST: —
67
+ S_INFER — state.json、推断生命周期位置 PERSIST: session.lifecycle_position
68
+ S_RESOLVE_PHASE — 解析目标 phase PERSIST: session.phase
69
+ S_BUILD_CHAIN — 构建步骤链 PERSIST: session.steps[]
70
+ S_CREATE_SESSION — status.json PERSIST: session (全量)
71
+ S_CONFIRM — 用户确认 PERSIST:
72
+ S_DISPATCH — 移交 maestro-ralph-execute PERSIST:
73
+ S_DECISION_EVAL — 委托评估质量门 PERSIST:
74
+ S_APPLY_VERDICT — 应用裁决 + 插入命令 PERSIST: session.steps[], session.passed_gates[]
75
+ S_FALLBACK — 请求用户输入 PERSIST: —
76
+ </states>
77
+
78
+ <transitions>
79
+
80
+ S_PARSE_ROUTE:
81
+ → S_STATUS WHEN: intent == "status"
82
+ → S_CONTINUE WHEN: intent == "continue"
83
+ → S_DECISION_EVAL WHEN: running session with decision step in "running" status
84
+ → S_INFER WHEN: intent is non-empty
85
+ → S_FALLBACK WHEN: no intent AND no running session
86
+
87
+ S_STATUS:
88
+ END DO: A_SHOW_STATUS
89
+
90
+ S_CONTINUE:
91
+ → S_DISPATCH WHEN: running session found
92
+ → S_FALLBACK WHEN: no running session DO: display "无运行中的 ralph 会话"
93
+
94
+ S_INFER:
95
+ → S_RESOLVE_PHASE WHEN: position resolved DO: A_INFER_POSITION
96
+ S_FALLBACK WHEN: cannot infer
97
+
98
+ S_RESOLVE_PHASE:
99
+ → S_BUILD_CHAIN WHEN: phase resolved or null DO: A_RESOLVE_PHASE
100
+ → S_FALLBACK WHEN: ambiguous
101
+ GUARD: auto_confirm does NOT skip phase ambiguity
102
+
103
+ S_BUILD_CHAIN:
104
+ → S_CREATE_SESSION DO: A_BUILD_STEPS
105
+
106
+ S_CREATE_SESSION:
107
+ S_CONFIRM WHEN: not auto_confirm DO: A_CREATE_SESSION
108
+ → S_DISPATCH WHEN: auto_confirm DO: A_CREATE_SESSION
109
+
110
+ S_CONFIRM:
111
+ S_DISPATCH WHEN: user selects "Proceed"
112
+ → S_BUILD_CHAIN WHEN: user selects "Edit"
113
+ → END WHEN: user selects "Cancel"
114
+
115
+ S_DISPATCH:
116
+ → END DO: Skill({ skill: "maestro-ralph-execute" })
117
+
118
+ S_DECISION_EVAL:
119
+ → S_APPLY_VERDICT WHEN: quality-gate (post-verify, post-business-test, post-review, post-test)
120
+ DO: A_DELEGATE_EVALUATE
121
+ → S_APPLY_VERDICT WHEN: structural (post-milestone, post-debug-escalate)
122
+ DO: A_STRUCTURAL_EVALUATE
123
+
124
+ S_APPLY_VERDICT:
125
+ → S_DISPATCH WHEN: verdict == "proceed" DO: A_APPLY_PROCEED
126
+ S_DISPATCH WHEN: verdict == "fix" DO: A_APPLY_FIX
127
+ → S_DISPATCH WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE
128
+ S_DISPATCH WHEN: post-milestone + next milestone DO: A_ADVANCE_MILESTONE
129
+ → END WHEN: post-milestone + no next milestone DO: mark completed
130
+ → END WHEN: post-debug-escalate (always STOP) DO: A_PAUSE_ESCALATE
131
+ GUARD: retry_count >= max_retries → force escalate
132
+ GUARD: confidence_score < 60 AND proceed → override to fix
133
+ GUARD: confidence_score > 95 AND fix AND retry > 0 → suggest proceed
134
+ GUARD: auto_confirm → skip user prompt, apply adjusted verdict
135
+ GUARD: not auto_confirm → AskUserQuestion with override options
136
+
137
+ S_FALLBACK:
138
+ → S_PARSE_ROUTE WHEN: user provides input DO: AskUserQuestion
139
+ → END WHEN: user cancels
140
+
141
+ </transitions>
142
+
143
+ <actions>
144
+
145
+ ### A_SHOW_STATUS
146
+
147
+ 1. Find latest ralph session (by created_at)
148
+ 2. Display: Session, Status, Position, Progress, Current step
149
+ 3. List steps: [✓] completed, [▸] current, [ ] pending, [◆] decision
150
+
151
+ ### A_INFER_POSITION
152
+
153
+ **Intent-based override:** brainstorm/头脑风暴/探索/ideate/设计思路 → position = `brainstorm`
154
+
155
+ **Bootstrap detection:**
118
156
 
119
- Chain for existing project: `brainstorm → roadmap → analyze → ...` (skip init if `.workflow/state.json` exists).
120
-
121
- **Phase 1 Bootstrap detection:**
122
-
123
- | Condition | Position | Chain starts at |
124
- |-----------|----------|-----------------|
125
- | No `.workflow/` + no source files (empty project) | `brainstorm` | brainstorm → init → roadmap → ... |
126
- | No `.workflow/` + has source files (existing code) | `init` | init → roadmap → ... |
127
- | Has `.workflow/` but no `state.json` | `init` | init → roadmap → ... |
128
- | Has `state.json` | → Phase 2 below | — |
129
-
130
- HARD RULE: `input_doc` is supplementary context only. It NEVER substitutes for lifecycle stages.
131
-
132
- **Phase 2 — Artifact-based inference (when state.json exists):**
157
+ | Condition | Position |
158
+ |-----------|----------|
159
+ | No `.workflow/` + no source files | `brainstorm` |
160
+ | No `.workflow/` + has source files | `init` |
161
+ | Has `.workflow/` but no state.json | `init` |
162
+ | Has state.json | → artifact-based inference |
133
163
 
134
- Filter artifacts by `milestone == current_milestone`, group by target phase. Find latest completed artifact type:
164
+ **Artifact-based inference:** Filter by current_milestone + target phase:
135
165
 
136
- | State | Position |
137
- |-------|----------|
138
- | No milestones[] or no roadmap.md | `roadmap` |
139
- | No artifacts for target phase | `analyze` |
140
- | Latest type == "analyze" | `plan` |
141
- | Latest type == "plan" | `execute` |
142
- | Latest type == "execute" | `verify` |
143
- | Latest type == "verify" | → Refine by result files below |
166
+ | Latest artifact type | Position |
167
+ |---------------------|----------|
168
+ | no milestones or no roadmap.md | `roadmap` |
169
+ | none for phase | `analyze` |
170
+ | analyze | `plan` |
171
+ | plan | `execute` |
172
+ | execute | `verify` |
173
+ | verify | → refine from result files |
144
174
 
145
- **Refine from verify results** (read `{artifact_dir}/` files):
175
+ **Refine from verify results:**
146
176
 
147
177
  | Condition | Position |
148
178
  |-----------|----------|
149
- | verification.json: `passed==false` or `gaps[]` non-empty | `verify-failed` |
150
- | verification.json: `passed==true`, no review.json | `business-test` |
151
- | review.json: `verdict=="BLOCK"` | `review-failed` |
152
- | review.json: `verdict!="BLOCK"` | `test` |
179
+ | verification.json: passed==false or gaps[] | `verify-failed` |
180
+ | passed==true, no review.json | `business-test` |
181
+ | review.json: verdict=="BLOCK" | `review-failed` |
182
+ | review.json: verdict!="BLOCK" | `test` |
153
183
  | uat.md: all passed | `milestone-audit` |
154
184
  | uat.md: has failures | `test-failed` |
155
185
 
156
- ### 2.3: Resolve phase number
157
-
158
- Priority order:
159
- 1. Regex from intent: `phase\s*(\d+)` or bare number
160
- 2. Latest in-progress artifact's phase field
161
- 3. First incomplete phase in current milestone's `phases[]`
162
- 4. `null` if position is brainstorm/init/roadmap (deferred to post-roadmap)
163
- 5. AskUserQuestion if ambiguous (auto_confirm does NOT skip this)
186
+ ### A_RESOLVE_PHASE
164
187
 
165
- ### 2.4: Build command sequence
188
+ Priority: 1) regex from intent 2) latest artifact's phase 3) first incomplete phase 4) null if brainstorm/init/roadmap 5) AskUserQuestion if ambiguous
166
189
 
167
- Generate steps from `lifecycle_position` to target (default: `milestone-complete`).
190
+ ### A_BUILD_STEPS
168
191
 
169
- **Lifecycle stages reference:**
192
+ Generate steps from lifecycle_position to milestone-complete:
170
193
 
171
- | Stage | Skill command | Type | Decision after |
172
- |-------|--------------|------|----------------|
194
+ | Stage | Skill | Type | Decision after |
195
+ |-------|-------|------|----------------|
173
196
  | brainstorm | `maestro-brainstorm "{intent}"` | external | — |
174
197
  | init | `maestro-init` | internal | — |
175
198
  | roadmap | `maestro-roadmap "{intent}"` | internal | — |
@@ -184,275 +207,131 @@ Generate steps from `lifecycle_position` to target (default: `milestone-complete
184
207
  | milestone-audit | `maestro-milestone-audit` | internal | — |
185
208
  | milestone-complete | `maestro-milestone-complete` | internal | `post-milestone` |
186
209
 
187
- **Type rationale:**
188
- - `internal` = in-session `Skill()` call, needs user interaction or is lightweight (plan, verify, quality-*, milestone-*)
189
- - `external` = new Claude Code session via `maestro delegate --to claude` executing `/{skill} {args}`, context-isolated heavy computation (analyze, execute, brainstorm)
190
-
191
- IMPORTANT: `external` ≠ single CLI tool call. It spawns a full Claude Code session that executes the skill command — the delegate session has complete skill access.
192
-
193
- HARD RULE: Delegate sessions are non-interactive. All skills executed via delegate MUST always append `-y` **to the skill's args inside the prompt** (not as a `maestro delegate` CLI argument). This is enforced by ralph-execute in Step 5c — ralph does not preset flags in steps.
194
-
195
- **Build rules:**
196
- 1. Start from inferred position, skip completed stages
197
- 2. After each decision-triggering stage, insert a decision node with `{ decision, retry_count: 0, max_retries: 2 }`
198
- 3. Args use placeholders resolved at execution time by ralph-execute:
199
- - `{phase}` → session.phase
200
- - `{intent}` → session.intent
201
- - `{scratch_dir}` → latest artifact path
202
- 4. Phase-independent commands (brainstorm, roadmap, init) use `"{intent}"` as args
203
- 5. Commands needing prior output (analyze→plan, plan→execute) have args resolved via artifact lookup at execution time by ralph-execute
204
-
205
- **Example — from "plan" position:**
206
- ```json
207
- [
208
- { "index": 0, "type": "internal", "skill": "maestro-plan", "args": "{phase}" },
209
- { "index": 1, "type": "external", "skill": "maestro-execute", "args": "{phase}" },
210
- { "index": 2, "type": "internal", "skill": "maestro-verify", "args": "{phase}" },
211
- { "index": 3, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-verify\",\"retry_count\":0,\"max_retries\":2}" },
212
- { "index": 4, "type": "internal", "skill": "quality-auto-test", "args": "{phase}" },
213
- { "index": 5, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-business-test\",\"retry_count\":0,\"max_retries\":2}" },
214
- { "index": 6, "type": "internal", "skill": "quality-review", "args": "{phase}" },
215
- { "index": 7, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-review\",\"retry_count\":0,\"max_retries\":2}" },
216
- { "index": 8, "type": "internal", "skill": "quality-auto-test", "args": "{phase}" },
217
- { "index": 9, "type": "internal", "skill": "quality-test", "args": "{phase}" },
218
- { "index": 10, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-test\",\"retry_count\":0,\"max_retries\":2}" },
219
- { "index": 11, "type": "internal", "skill": "maestro-milestone-audit", "args": "" },
220
- { "index": 12, "type": "internal", "skill": "maestro-milestone-complete", "args": "" },
221
- { "index": 13, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-milestone\"}" }
222
- ]
223
- ```
224
-
225
- ### 2.5: Create session
226
-
227
- ```json
228
- {
229
- "session_id": "ralph-{YYYYMMDD-HHmmss}",
230
- "source": "ralph",
231
- "created_at": "{ISO}", "updated_at": "{ISO}",
232
- "intent": "{user_intent}",
233
- "status": "running",
234
- "chain_name": "ralph-lifecycle",
235
- "task_type": "lifecycle",
236
- "lifecycle_position": "{position}",
237
- "target": "milestone-complete",
238
- "phase": null | N,
239
- "milestone": "{M}",
240
- "auto_mode": auto_confirm,
241
- "cli_tool": "claude",
242
- "quality_mode": "standard",
243
- "passed_gates": [],
244
- "context": {
245
- "issue_id": null, "milestone_num": null, "spec_session_id": null,
246
- "scratch_dir": null, "plan_dir": null, "analysis_dir": null, "brainstorm_dir": null
247
- },
248
- "steps": [...],
249
- "waves": [],
250
- "current_step": 0
251
- }
252
- ```
253
-
254
- Write to `.workflow/.maestro/{session_id}/status.json`.
255
-
256
- ### 2.6: Display plan + confirm
257
-
258
- ```
259
- ============================================================
260
- RALPH DECISION
261
- ============================================================
262
- Position: {lifecycle_position} (Phase {N}, {milestone})
263
- Target: {target}
264
- Commands: {total} steps ({decision_count} decision points)
265
-
266
- [ ] 0. maestro-plan 1 [internal]
267
- [ ] 1. maestro-execute 1 [external]
268
- [ ] 2. maestro-verify 1 [internal]
269
- [ ] 3. ◆ post-verify [decision]
270
- ...
271
- ============================================================
272
- ```
273
-
274
- - If auto_confirm (`-y`): proceed directly
275
- - Else: AskUserQuestion → Proceed / Edit / Cancel
210
+ Type rationale: `internal` = Skill(), lightweight/interactive; `external` = delegate --to claude, context-isolated heavy computation
276
211
 
277
- ### 2.7: Launch execution
212
+ Build rules: start from position, skip completed, insert decision nodes with `{ retry_count: 0, max_retries: 2 }`, args use placeholders resolved at execution time by ralph-execute
278
213
 
279
- HARD RULE: Ralph's job ends at session creation. Do NOT execute steps, read project files for execution, or update step statuses directly.
214
+ ### A_CREATE_SESSION
280
215
 
281
- ```
282
- Skill({ skill: "maestro-ralph-execute" })
283
- End.
284
- ```
216
+ 1. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json` (see Appendix: Session Schema)
217
+ 2. Display chain overview with step list
285
218
 
286
- ---
219
+ ### A_DELEGATE_EVALUATE
287
220
 
288
- ## Step 3: Decision Evaluation Mode
221
+ 1. Resolve artifact dir: `.workflow/scratch/{artifact.path}/` with fallback glob
222
+ 2. Parse decision metadata: `{ decision, retry_count, max_retries }`
223
+ 3. Map result files:
224
+ | Decision | Files |
225
+ |----------|-------|
226
+ | post-verify | verification.json |
227
+ | post-business-test | .tests/auto-test/report.json |
228
+ | post-review | review.json |
229
+ | post-test | uat.md, .tests/test-results.json |
230
+ 4. Check artifact for confidence section → include as signal
231
+ 5. Execute delegate (run_in_background, STOP, wait for callback):
232
+ ```
233
+ maestro delegate "PURPOSE: 评估 {decision} 质量门结果
234
+ TASK: 读取结果 | 分析状态 | 评估严重性 | 给出建议
235
+ EXPECTED: ---VERDICT--- STATUS/REASON/GAP_SUMMARY/CONFIDENCE(high|medium|low)/CONFIDENCE_SCORE(0-100)/WEAKEST_DIMENSION ---END---
236
+ CONSTRAINTS: 只评估 | 置信度<60% 倾向 fix | retry {n}/{max} 达上限必须 escalate"
237
+ --role analyze --mode analysis
238
+ ```
239
+ 6. On callback: parse verdict; if parse fails → fallback STATUS="fix"
240
+ 7. Confidence adjustment: <60 + proceed → fix; >95 + fix + retry>0 → suggest proceed
289
241
 
290
- Triggered when ralph-execute encounters a decision node and hands back to ralph.
242
+ ### A_STRUCTURAL_EVALUATE
291
243
 
292
- ### 3.1: Load session + resolve artifact dir
244
+ **post-milestone:** Read state.json next milestone? insert lifecycle steps / complete
245
+ **post-debug-escalate:** Always STOP → set paused, display "请人工介入"
293
246
 
294
- Read session status.json. Identify decision node at `steps[current_step]`.
247
+ ### A_APPLY_PROCEED
295
248
 
296
- **Artifact dir resolution:**
297
- ```
298
- Read .workflow/state.json
299
- Filter: milestone == session.milestone, phase == session.phase
300
- Sort: created_at DESC
249
+ 1. Mark decision completed, write status.json
250
+ 2. Display: ◆ Decision: {type} → proceed ({reason})
301
251
 
302
- artifact_dir = .workflow/scratch/{artifact.path}/
252
+ ### A_APPLY_FIX
303
253
 
304
- Fallback if path not found:
305
- glob .workflow/scratch/*-P{phase}-*/ sorted by date DESC, take first
306
- ```
254
+ 1. Insert fix-loop commands after current step (see Appendix: Fix-Loop Templates)
255
+ 2. Reindex steps, increment retry_count, write status.json
256
+ 3. Display: ◆ Decision: {type} → fix, +{N} commands inserted
307
257
 
308
- ### 3.2: Parse decision metadata
258
+ ### A_APPLY_ESCALATE
309
259
 
310
- ```
311
- meta = JSON.parse(decision_node.args)
312
- // { decision: "post-verify", retry_count: 0, max_retries: 2 }
313
- ```
314
-
315
- ### 3.3: Delegate evaluation
316
-
317
- For quality-gate decisions (post-verify, post-business-test, post-review, post-test), delegate analysis to external CLI. For structural decisions (post-milestone, post-debug-escalate), evaluate directly.
260
+ 1. Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`
261
+ 2. Increment retry_count, reindex, write status.json
318
262
 
319
- **Structural decisions → Step 3.5 (direct evaluation)**
320
- **Quality-gate decisions → delegate below:**
263
+ ### A_ADVANCE_MILESTONE
321
264
 
322
- NOTE: This delegate uses `--mode analysis` (read-only) — the CLI tool won't trigger interactive prompts, so no extra `-y` needed. If this ever changes to write-mode delegate, ensure the target skill appends `-y`.
265
+ 1. Update session: milestone, phase, reset passed_gates
266
+ 2. Insert full lifecycle steps for next milestone
267
+ 3. Reindex, write status.json
323
268
 
324
- **Result file mapping** (for delegate CONTEXT):
269
+ ### A_PAUSE_ESCALATE
325
270
 
326
- | Decision type | Files to include |
327
- |---------------|-----------------|
328
- | post-verify | `{artifact_dir}/verification.json` |
329
- | post-business-test | `{artifact_dir}/.tests/auto-test/report.json` |
330
- | post-review | `{artifact_dir}/review.json` |
331
- | post-test | `{artifact_dir}/uat.md`, `{artifact_dir}/.tests/test-results.json` |
271
+ 1. Set session status = "paused", write status.json
272
+ 2. Display: ◆ 已达最大重试次数,debug 已执行。请人工介入。
273
+ 3. Display: /maestro-ralph continue 恢复
332
274
 
333
- **Confidence-aware evaluation**:
275
+ </actions>
334
276
 
335
- Before delegating, check if artifact contains a confidence section (added by downstream commands):
336
- - `verification.json` → `confidence.overall` (from maestro-verify)
337
- - `report.json` → `confidence.overall` (from quality-auto-test)
338
- - `review.json` → may contain dimension confidence (from quality-review)
339
- - `uat.md` → confidence summary section (from quality-test)
277
+ </state_machine>
340
278
 
341
- If confidence data found, include in delegate prompt as additional signal:
342
- ```
343
- 已有置信度评估: 整体 {overall}%, 最弱维度: {weakest} ({score}%)
344
- ```
279
+ <appendix>
345
280
 
346
- **Confidence-based verdict bias**: When artifact confidence is available:
347
- - confidence < 60% → bias toward "fix" even if surface status looks clean (hidden quality gaps)
348
- - confidence 60-95% → use delegate verdict as-is
349
- - confidence > 95% → bias toward "proceed" (strong evidence of quality)
281
+ ### Session Schema
350
282
 
351
- ```
352
- Bash({
353
- command: `maestro delegate "PURPOSE: 评估 ${meta.decision} 质量门结果,判断是否通过
354
- TASK: 读取结果文件 | 分析通过/失败状态 | 评估问题严重性 | 检查置信度评分 | 给出下一步建议
355
- MODE: analysis
356
- CONTEXT: @${result_files}
357
- EXPECTED: 严格按以下格式输出:
358
- ---VERDICT---
359
- STATUS: proceed | fix | escalate
360
- REASON: 一句话解释
361
- GAP_SUMMARY: 具体问题描述(仅 fix/escalate 时填写,用于传递给 quality-debug)
362
- CONFIDENCE: high | medium | low
363
- CONFIDENCE_SCORE: 0-100(从结果文件中读取置信度分数,无则估算)
364
- WEAKEST_DIMENSION: 最弱维度名称
365
- ---END---
366
- CONSTRAINTS: 只评估不修改 | STATUS 三选一 | 置信度 < 60% 倾向 fix | 如果 retry ${meta.retry_count}/${meta.max_retries} 已达上限且仍有问题则必须 escalate" --role analyze --mode analysis`,
367
- run_in_background: true
368
- })
369
- STOP — wait for callback.
283
+ ```json
284
+ {
285
+ "session_id": "ralph-{YYYYMMDD-HHmmss}",
286
+ "source": "ralph", "status": "running",
287
+ "intent": "", "lifecycle_position": "",
288
+ "phase": null, "milestone": "",
289
+ "auto_mode": false, "quality_mode": "standard",
290
+ "cli_tool": "claude", "passed_gates": [],
291
+ "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
292
+ "analysis_dir": null, "brainstorm_dir": null },
293
+ "steps": [{ "index": 0, "type": "internal|external|decision",
294
+ "skill": "", "args": "", "status": "pending" }],
295
+ "waves": [], "current_step": 0
296
+ }
370
297
  ```
371
298
 
372
- ### 3.4: Parse verdict + apply
299
+ ### Fix-Loop Templates
373
300
 
374
- **On callback:** retrieve output via `maestro delegate output <exec_id>`.
375
-
376
- Parse structured response:
377
- ```
378
- Extract between ---VERDICT--- and ---END---:
379
- verdict.status = "proceed" | "fix" | "escalate"
380
- verdict.reason = string
381
- verdict.gap_summary = string (context for quality-debug)
382
- verdict.confidence = "high" | "medium" | "low"
383
- verdict.confidence_score = 0-100 (numeric, from artifact or estimated)
384
- verdict.weakest_dimension = string (weakest confidence dimension)
385
-
386
- If parse fails → fallback: treat as "fix" with generic gap_summary
387
-
388
- Confidence-based verdict adjustment (after parse, before apply):
389
- If verdict.confidence_score < 60 AND verdict.status == "proceed":
390
- → Override to "fix", reason += " (置信度不足: {score}%,{weakest_dimension} 需加强)"
391
- If verdict.confidence_score > 95 AND verdict.status == "fix" AND retry_count > 0:
392
- → Suggest "proceed" override, reason += " (置信度充分: {score}%,建议通过)"
393
- ```
394
-
395
- **Apply verdict:**
396
-
397
- | Mode | Behavior |
398
- |------|----------|
399
- | `-y` (auto_confirm) | Follow verdict directly — no user confirmation |
400
- | Interactive + confidence == "high" | Display recommendation, AskUserQuestion: "按建议执行 / 覆盖 / 取消" |
401
- | Interactive + confidence != "high" | Display recommendation with warning, AskUserQuestion: "按建议执行 / 覆盖 / 取消" |
402
-
403
- User override options (interactive only):
404
- - **按建议执行** → apply verdict as-is
405
- - **覆盖 proceed** → force proceed regardless of verdict
406
- - **覆盖 fix** → force fix loop
407
- - **取消** → pause session, End.
408
-
409
- **Verdict → action mapping:**
410
-
411
- | Verdict | Action |
412
- |---------|--------|
413
- | `proceed` | No insertion, continue to next step |
414
- | `fix` | Insert fix-loop commands (see 3.4a) |
415
- | `escalate` | Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]` |
416
-
417
- ### 3.4a: Fix-loop templates (by decision type)
418
-
419
- When verdict == "fix", insert pre-defined fix-loop based on decision type.
420
- The delegate's `gap_summary` is passed as context to `quality-debug`.
421
-
422
- #### post-verify fix-loop
301
+ **post-verify:**
423
302
  ```
424
303
  quality-debug "{gap_summary}"
425
304
  maestro-plan --gaps {phase}
426
- maestro-execute {phase} [external]
305
+ maestro-execute {phase} [external]
427
306
  maestro-verify {phase}
428
- decision:post-verify {retry_count + 1}
307
+ decision:post-verify {retry+1}
429
308
  ```
430
309
 
431
- #### post-business-test fix-loop
310
+ **post-business-test:**
432
311
  ```
433
312
  quality-debug --from-business-test "{gap_summary}"
434
313
  maestro-plan --gaps {phase}
435
- maestro-execute {phase} [external]
314
+ maestro-execute {phase} [external]
436
315
  maestro-verify {phase}
437
316
  decision:post-verify {retry: 0}
438
317
  quality-auto-test {phase}
439
- decision:post-business-test {retry_count + 1}
318
+ decision:post-business-test {retry+1}
440
319
  ```
441
320
 
442
- #### post-review fix-loop
321
+ **post-review:**
443
322
  ```
444
323
  quality-debug "{gap_summary}"
445
324
  maestro-plan --gaps {phase}
446
- maestro-execute {phase} [external]
325
+ maestro-execute {phase} [external]
447
326
  quality-review {phase}
448
- decision:post-review {retry_count + 1}
327
+ decision:post-review {retry+1}
449
328
  ```
450
329
 
451
- #### post-test fix-loop
330
+ **post-test:**
452
331
  ```
453
332
  quality-debug --from-uat "{gap_summary}"
454
333
  maestro-plan --gaps {phase}
455
- maestro-execute {phase} [external]
334
+ maestro-execute {phase} [external]
456
335
  maestro-verify {phase}
457
336
  decision:post-verify {retry: 0}
458
337
  quality-auto-test {phase}
@@ -461,91 +340,31 @@ quality-review {phase}
461
340
  decision:post-review {retry: 0}
462
341
  quality-auto-test {phase}
463
342
  quality-test {phase}
464
- decision:post-test {retry_count + 1}
465
- ```
466
-
467
- ### 3.5: Structural decisions (direct evaluation)
468
-
469
- These don't need delegate analysis — evaluated directly by ralph.
470
-
471
- #### post-milestone
472
-
343
+ decision:post-test {retry+1}
473
344
  ```
474
- Read .workflow/state.json — check for next milestone (status "pending" or "active")
475
345
 
476
- If next milestone found:
477
- Update session: milestone = next_m.name, phase = first_phase
478
- Insert full lifecycle for next milestone (analyze through milestone-complete + decision nodes)
479
- Display: ◆ post-milestone: {completed} done → advancing to {next_m.name} Phase {first_phase}
346
+ ### Error Codes
480
347
 
481
- If no next milestone:
482
- Proceed — session completes naturally
483
- Display: ◆ post-milestone: all milestones complete!
484
- ```
485
-
486
- #### post-debug-escalate
487
-
488
- Terminal escalation — max retries exceeded after debug.
489
-
490
- ```
491
- Set session status = "paused"
492
- Display: ◆ 已达最大重试次数,debug 已执行。请人工介入检查结果。
493
- Display: 使用 /maestro-ralph continue 在处理后恢复
494
- End.
495
- ```
496
-
497
- ### 3.6: Insert commands + update session
498
-
499
- ```
500
- Insert new_commands at position (current_step + 1)
501
- Reindex all steps: step.index = array position
502
- Mark current decision node: status = "completed", completed_at = now
503
- Write status.json
504
-
505
- Display: ◆ Decision: {type} → {verdict.status} ({verdict.reason}), +{N} commands inserted
506
- ```
507
-
508
- ### 3.7: Resume execution
509
-
510
- ```
511
- Skill({ skill: "maestro-ralph-execute" })
512
- End.
513
- ```
514
-
515
- </execution>
516
-
517
- <error_codes>
518
348
  | Code | Severity | Description | Recovery |
519
349
  |------|----------|-------------|----------|
520
350
  | E001 | error | No intent and no running session | Prompt for intent |
521
- | E002 | error | Cannot infer lifecycle position | Show raw state, ask user |
522
- | E003 | error | Artifact dir not found for decision evaluation | Show glob results, ask user |
523
- | E004 | error | Delegate verdict parse failed | Fallback: treat as "fix" |
524
- | E005 | error | Delegate execution failed | Fallback: treat as "fix" with generic summary |
525
- | W001 | warning | Decision node expanded chain | Auto-handled, log expansion |
526
- | W002 | warning | Max retries reached, escalating | Auto-handled |
527
- | W003 | warning | Multiple running sessions found | Use latest, warn user |
528
- | W004 | warning | Delegate confidence == "low" | Show warning in interactive mode |
529
- </error_codes>
530
-
531
- <success_criteria>
532
- - [ ] state.json parsed with correct schema (type, path, scope, milestone, artifacts[])
533
- - [ ] Lifecycle position inferred from bootstrap state + artifact chain + result files
534
- - [ ] Artifact dir resolved: `.workflow/scratch/{artifact.path}/` with fallback glob
535
- - [ ] Full quality pipeline generated: verify → business-test → review → test-gen → test
536
- - [ ] Decision nodes inserted after: post-verify, post-business-test, post-review, post-test, post-milestone
537
- - [ ] Quality-gate decisions delegated via `maestro delegate --role analyze --mode analysis`
538
- - [ ] Delegate verdict parsed: STATUS / REASON / GAP_SUMMARY / CONFIDENCE / CONFIDENCE_SCORE / WEAKEST_DIMENSION
539
- - [ ] Confidence-based verdict adjustment applied (< 60% bias fix, > 95% bias proceed)
540
- - [ ] Artifact confidence sections read when available (verification.json, report.json, uat.md)
541
- - [ ] `-y` mode: auto-follow adjusted verdict without user confirmation
542
- - [ ] Interactive mode: display recommendation with confidence score + AskUserQuestion with override options
543
- - [ ] Delegate failure fallback: treat as "fix" verdict
544
- - [ ] gap_summary from delegate passed to quality-debug as context
545
- - [ ] Fix-loop templates applied per decision type with retry_count increment
546
- - [ ] retry_count tracked per decision, max_retries enforced, escalation to post-debug-escalate
547
- - [ ] Structural decisions (post-milestone, post-debug-escalate) evaluated directly without delegate
548
- - [ ] Command insertion + reindex preserves step integrity
351
+ | E002 | error | Cannot infer lifecycle position | Show raw state, ask |
352
+ | E003 | error | Artifact dir not found for decision | Show glob, ask |
353
+ | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
354
+ | E005 | error | Delegate execution failed | Fallback: "fix" |
355
+ | W001 | warning | Decision expanded chain | Auto-handled |
356
+ | W002 | warning | Max retries, escalating | Auto-handled |
357
+ | W003 | warning | Multiple running sessions | Use latest, warn |
358
+ | W004 | warning | Low delegate confidence | Show warning |
359
+
360
+ ### Success Criteria
361
+
362
+ - [ ] State parsed, position inferred from bootstrap + artifacts + result files
363
+ - [ ] Quality pipeline generated: verify business-test review test-gen test
364
+ - [ ] Decision nodes delegate-evaluated via maestro delegate --role analyze
365
+ - [ ] Verdict parsed with confidence adjustment
366
+ - [ ] Fix-loop templates applied with retry tracking
549
367
  - [ ] Ralph never executes steps — only creates sessions and evaluates decisions
550
- - [ ] Handoff to maestro-ralph-execute via Skill() at session creation and after decision evaluation
551
- </success_criteria>
368
+ - [ ] Handoff to maestro-ralph-execute via Skill() at creation and after decisions
369
+
370
+ </appendix>