maestro-flow 0.5.3 → 0.5.31

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 (259) hide show
  1. package/.agents/skills/learn-follow/SKILL.md +114 -114
  2. package/.agents/skills/learn-investigate/SKILL.md +138 -139
  3. package/.agents/skills/learn-second-opinion/SKILL.md +105 -109
  4. package/.agents/skills/maestro/SKILL.md +2 -10
  5. package/.agents/skills/maestro-amend/SKILL.md +152 -152
  6. package/.agents/skills/maestro-analyze/SKILL.md +201 -252
  7. package/.agents/skills/maestro-blueprint/SKILL.md +175 -190
  8. package/.agents/skills/maestro-brainstorm/SKILL.md +196 -200
  9. package/.agents/skills/maestro-collab/SKILL.md +159 -159
  10. package/.agents/skills/maestro-companion/SKILL.md +517 -517
  11. package/.agents/skills/maestro-composer/SKILL.md +173 -164
  12. package/.agents/skills/maestro-execute/SKILL.md +169 -170
  13. package/.agents/skills/maestro-fork/SKILL.md +97 -96
  14. package/.agents/skills/maestro-grill/SKILL.md +161 -162
  15. package/.agents/skills/maestro-guard/SKILL.md +93 -92
  16. package/.agents/skills/maestro-impeccable/SKILL.md +296 -253
  17. package/.agents/skills/maestro-init/SKILL.md +117 -118
  18. package/.agents/skills/maestro-merge/SKILL.md +73 -66
  19. package/.agents/skills/maestro-milestone-audit/SKILL.md +4 -10
  20. package/.agents/skills/maestro-milestone-complete/SKILL.md +6 -7
  21. package/.agents/skills/maestro-milestone-release/SKILL.md +122 -131
  22. package/.agents/skills/maestro-next/SKILL.md +241 -245
  23. package/.agents/skills/maestro-overlay/SKILL.md +176 -166
  24. package/.agents/skills/maestro-plan/SKILL.md +211 -197
  25. package/.agents/skills/maestro-player/SKILL.md +167 -167
  26. package/.agents/skills/maestro-quick/SKILL.md +69 -63
  27. package/.agents/skills/maestro-ralph/SKILL.md +2 -36
  28. package/.agents/skills/maestro-ralph-beta/SKILL.md +861 -872
  29. package/.agents/skills/maestro-ralph-execute/SKILL.md +234 -234
  30. package/.agents/skills/maestro-roadmap/SKILL.md +159 -172
  31. package/.agents/skills/maestro-swarm-workflow/SKILL.md +229 -250
  32. package/.agents/skills/maestro-tools-execute/SKILL.md +108 -103
  33. package/.agents/skills/maestro-tools-register/SKILL.md +148 -143
  34. package/.agents/skills/maestro-ui-codify/SKILL.md +103 -86
  35. package/.agents/skills/maestro-universal-workflow/SKILL.md +534 -547
  36. package/.agents/skills/maestro-update/SKILL.md +109 -106
  37. package/.agents/skills/manage-codebase-rebuild/SKILL.md +73 -71
  38. package/.agents/skills/manage-harvest/SKILL.md +83 -81
  39. package/.agents/skills/manage-issue/SKILL.md +59 -60
  40. package/.agents/skills/manage-issue-discover/SKILL.md +70 -68
  41. package/.agents/skills/manage-kg-extractors/SKILL.md +130 -0
  42. package/.agents/skills/manage-knowhow/SKILL.md +70 -66
  43. package/.agents/skills/manage-knowhow-capture/SKILL.md +79 -69
  44. package/.agents/skills/manage-knowledge-audit/SKILL.md +91 -74
  45. package/.agents/skills/manage-status/SKILL.md +52 -42
  46. package/.agents/skills/manage-wiki/SKILL.md +69 -58
  47. package/.agents/skills/odyssey-debug/SKILL.md +445 -459
  48. package/.agents/skills/odyssey-improve/SKILL.md +477 -491
  49. package/.agents/skills/odyssey-planex/SKILL.md +576 -587
  50. package/.agents/skills/odyssey-review-test-fix/SKILL.md +400 -413
  51. package/.agents/skills/odyssey-ui/SKILL.md +431 -448
  52. package/.agents/skills/quality-auto-test/SKILL.md +140 -123
  53. package/.agents/skills/quality-debug/SKILL.md +145 -106
  54. package/.agents/skills/quality-refactor/SKILL.md +91 -53
  55. package/.agents/skills/quality-retrospective/SKILL.md +109 -63
  56. package/.agents/skills/quality-review/SKILL.md +141 -114
  57. package/.agents/skills/quality-sync/SKILL.md +74 -38
  58. package/.agents/skills/quality-test/SKILL.md +133 -103
  59. package/.agents/skills/security-audit/SKILL.md +217 -166
  60. package/.agents/skills/spec-add/SKILL.md +66 -59
  61. package/.agents/skills/spec-load/SKILL.md +68 -68
  62. package/.agents/skills/spec-remove/SKILL.md +42 -42
  63. package/.agents/skills/spec-setup/SKILL.md +38 -41
  64. package/.agy/skills/learn-follow/SKILL.md +114 -114
  65. package/.agy/skills/learn-investigate/SKILL.md +138 -139
  66. package/.agy/skills/learn-second-opinion/SKILL.md +105 -109
  67. package/.agy/skills/maestro/SKILL.md +2 -10
  68. package/.agy/skills/maestro-amend/SKILL.md +152 -152
  69. package/.agy/skills/maestro-analyze/SKILL.md +201 -252
  70. package/.agy/skills/maestro-blueprint/SKILL.md +175 -190
  71. package/.agy/skills/maestro-brainstorm/SKILL.md +196 -200
  72. package/.agy/skills/maestro-collab/SKILL.md +159 -159
  73. package/.agy/skills/maestro-companion/SKILL.md +517 -517
  74. package/.agy/skills/maestro-composer/SKILL.md +173 -164
  75. package/.agy/skills/maestro-execute/SKILL.md +169 -170
  76. package/.agy/skills/maestro-fork/SKILL.md +97 -96
  77. package/.agy/skills/maestro-grill/SKILL.md +161 -162
  78. package/.agy/skills/maestro-guard/SKILL.md +93 -92
  79. package/.agy/skills/maestro-impeccable/SKILL.md +296 -253
  80. package/.agy/skills/maestro-init/SKILL.md +117 -118
  81. package/.agy/skills/maestro-merge/SKILL.md +73 -66
  82. package/.agy/skills/maestro-milestone-audit/SKILL.md +4 -10
  83. package/.agy/skills/maestro-milestone-complete/SKILL.md +6 -7
  84. package/.agy/skills/maestro-milestone-release/SKILL.md +122 -131
  85. package/.agy/skills/maestro-next/SKILL.md +241 -245
  86. package/.agy/skills/maestro-overlay/SKILL.md +176 -166
  87. package/.agy/skills/maestro-plan/SKILL.md +211 -197
  88. package/.agy/skills/maestro-player/SKILL.md +167 -167
  89. package/.agy/skills/maestro-quick/SKILL.md +69 -63
  90. package/.agy/skills/maestro-ralph/SKILL.md +2 -36
  91. package/.agy/skills/maestro-ralph-beta/SKILL.md +861 -872
  92. package/.agy/skills/maestro-ralph-execute/SKILL.md +234 -234
  93. package/.agy/skills/maestro-roadmap/SKILL.md +159 -172
  94. package/.agy/skills/maestro-swarm-workflow/SKILL.md +229 -250
  95. package/.agy/skills/maestro-tools-execute/SKILL.md +108 -103
  96. package/.agy/skills/maestro-tools-register/SKILL.md +148 -143
  97. package/.agy/skills/maestro-ui-codify/SKILL.md +103 -86
  98. package/.agy/skills/maestro-universal-workflow/SKILL.md +534 -547
  99. package/.agy/skills/maestro-update/SKILL.md +109 -106
  100. package/.agy/skills/manage-codebase-rebuild/SKILL.md +73 -71
  101. package/.agy/skills/manage-harvest/SKILL.md +83 -81
  102. package/.agy/skills/manage-issue/SKILL.md +59 -60
  103. package/.agy/skills/manage-issue-discover/SKILL.md +70 -68
  104. package/.agy/skills/manage-kg-extractors/SKILL.md +130 -0
  105. package/.agy/skills/manage-knowhow/SKILL.md +70 -66
  106. package/.agy/skills/manage-knowhow-capture/SKILL.md +79 -69
  107. package/.agy/skills/manage-knowledge-audit/SKILL.md +91 -74
  108. package/.agy/skills/manage-status/SKILL.md +52 -42
  109. package/.agy/skills/manage-wiki/SKILL.md +69 -58
  110. package/.agy/skills/odyssey-debug/SKILL.md +445 -459
  111. package/.agy/skills/odyssey-improve/SKILL.md +477 -491
  112. package/.agy/skills/odyssey-planex/SKILL.md +576 -587
  113. package/.agy/skills/odyssey-review-test-fix/SKILL.md +400 -413
  114. package/.agy/skills/odyssey-ui/SKILL.md +431 -448
  115. package/.agy/skills/quality-auto-test/SKILL.md +140 -123
  116. package/.agy/skills/quality-debug/SKILL.md +145 -106
  117. package/.agy/skills/quality-refactor/SKILL.md +91 -53
  118. package/.agy/skills/quality-retrospective/SKILL.md +109 -63
  119. package/.agy/skills/quality-review/SKILL.md +141 -114
  120. package/.agy/skills/quality-sync/SKILL.md +74 -38
  121. package/.agy/skills/quality-test/SKILL.md +133 -103
  122. package/.agy/skills/security-audit/SKILL.md +217 -166
  123. package/.agy/skills/spec-add/SKILL.md +66 -59
  124. package/.agy/skills/spec-load/SKILL.md +68 -68
  125. package/.agy/skills/spec-remove/SKILL.md +42 -42
  126. package/.agy/skills/spec-setup/SKILL.md +38 -41
  127. package/.claude/commands/learn-follow.md +127 -127
  128. package/.claude/commands/learn-investigate.md +151 -152
  129. package/.claude/commands/learn-second-opinion.md +118 -122
  130. package/.claude/commands/maestro-amend.md +164 -164
  131. package/.claude/commands/maestro-analyze.md +215 -266
  132. package/.claude/commands/maestro-blueprint.md +189 -204
  133. package/.claude/commands/maestro-brainstorm.md +209 -213
  134. package/.claude/commands/maestro-collab.md +172 -172
  135. package/.claude/commands/maestro-companion.md +531 -531
  136. package/.claude/commands/maestro-composer.md +188 -179
  137. package/.claude/commands/maestro-execute.md +183 -184
  138. package/.claude/commands/maestro-fork.md +111 -110
  139. package/.claude/commands/maestro-grill.md +175 -176
  140. package/.claude/commands/maestro-guard.md +103 -102
  141. package/.claude/commands/maestro-impeccable.md +311 -268
  142. package/.claude/commands/maestro-init.md +130 -131
  143. package/.claude/commands/maestro-merge.md +87 -80
  144. package/.claude/commands/maestro-milestone-audit.md +4 -10
  145. package/.claude/commands/maestro-milestone-complete.md +6 -7
  146. package/.claude/commands/maestro-milestone-release.md +136 -145
  147. package/.claude/commands/maestro-next.md +253 -257
  148. package/.claude/commands/maestro-overlay.md +188 -178
  149. package/.claude/commands/maestro-plan.md +225 -211
  150. package/.claude/commands/maestro-player.md +182 -182
  151. package/.claude/commands/maestro-quick.md +83 -77
  152. package/.claude/commands/maestro-ralph-beta.md +875 -886
  153. package/.claude/commands/maestro-ralph-execute.md +247 -247
  154. package/.claude/commands/maestro-ralph.md +2 -36
  155. package/.claude/commands/maestro-roadmap.md +173 -186
  156. package/.claude/commands/maestro-swarm-workflow.md +243 -264
  157. package/.claude/commands/maestro-tools-execute.md +122 -117
  158. package/.claude/commands/maestro-tools-register.md +162 -157
  159. package/.claude/commands/maestro-ui-codify.md +117 -100
  160. package/.claude/commands/maestro-universal-workflow.md +548 -561
  161. package/.claude/commands/maestro-update.md +122 -119
  162. package/.claude/commands/maestro.md +2 -10
  163. package/.claude/commands/manage-codebase-rebuild.md +87 -85
  164. package/.claude/commands/manage-harvest.md +97 -95
  165. package/.claude/commands/manage-issue-discover.md +83 -81
  166. package/.claude/commands/manage-issue.md +72 -73
  167. package/.claude/commands/manage-kg-extractors.md +128 -0
  168. package/.claude/commands/manage-knowhow-capture.md +92 -82
  169. package/.claude/commands/manage-knowhow.md +83 -79
  170. package/.claude/commands/manage-knowledge-audit.md +105 -88
  171. package/.claude/commands/manage-status.md +62 -52
  172. package/.claude/commands/manage-wiki.md +82 -71
  173. package/.claude/commands/odyssey-debug.md +459 -473
  174. package/.claude/commands/odyssey-improve.md +491 -505
  175. package/.claude/commands/odyssey-planex.md +590 -601
  176. package/.claude/commands/odyssey-review-test-fix.md +414 -427
  177. package/.claude/commands/odyssey-ui.md +445 -462
  178. package/.claude/commands/quality-auto-test.md +153 -136
  179. package/.claude/commands/quality-debug.md +159 -120
  180. package/.claude/commands/quality-refactor.md +105 -67
  181. package/.claude/commands/quality-retrospective.md +123 -77
  182. package/.claude/commands/quality-review.md +155 -128
  183. package/.claude/commands/quality-sync.md +88 -52
  184. package/.claude/commands/quality-test.md +147 -117
  185. package/.claude/commands/security-audit.md +230 -179
  186. package/.claude/commands/spec-add.md +77 -70
  187. package/.claude/commands/spec-load.md +78 -78
  188. package/.claude/commands/spec-remove.md +55 -55
  189. package/.claude/commands/spec-setup.md +49 -52
  190. package/dist/src/cli.js +1 -1
  191. package/dist/src/cli.js.map +1 -1
  192. package/dist/src/commands/kg.d.ts.map +1 -1
  193. package/dist/src/commands/kg.js +11 -5
  194. package/dist/src/commands/kg.js.map +1 -1
  195. package/dist/src/graph/kg/extraction/code/code-extractor.d.ts +2 -0
  196. package/dist/src/graph/kg/extraction/code/code-extractor.d.ts.map +1 -1
  197. package/dist/src/graph/kg/extraction/code/code-extractor.js +32 -3
  198. package/dist/src/graph/kg/extraction/code/code-extractor.js.map +1 -1
  199. package/dist/src/graph/kg/extraction/code/plugin-engine.d.ts +35 -0
  200. package/dist/src/graph/kg/extraction/code/plugin-engine.d.ts.map +1 -0
  201. package/dist/src/graph/kg/extraction/code/plugin-engine.js +573 -0
  202. package/dist/src/graph/kg/extraction/code/plugin-engine.js.map +1 -0
  203. package/dist/src/graph/kg/extraction/code/plugin-types.d.ts +95 -0
  204. package/dist/src/graph/kg/extraction/code/plugin-types.d.ts.map +1 -0
  205. package/dist/src/graph/kg/extraction/code/plugin-types.js +5 -0
  206. package/dist/src/graph/kg/extraction/code/plugin-types.js.map +1 -0
  207. package/dist/src/graph/kg/extraction/orchestrator.d.ts.map +1 -1
  208. package/dist/src/graph/kg/extraction/orchestrator.js +17 -5
  209. package/dist/src/graph/kg/extraction/orchestrator.js.map +1 -1
  210. package/dist/src/graph/kg/schema.sql +16 -11
  211. package/dist/src/graph/kg/surface/cli.d.ts.map +1 -1
  212. package/dist/src/graph/kg/surface/cli.js +153 -56
  213. package/dist/src/graph/kg/surface/cli.js.map +1 -1
  214. package/dist/src/hooks/workspace.d.ts +4 -2
  215. package/dist/src/hooks/workspace.d.ts.map +1 -1
  216. package/dist/src/hooks/workspace.js +6 -2
  217. package/dist/src/hooks/workspace.js.map +1 -1
  218. package/package.json +91 -91
  219. package/workflows/analyze.md +25 -49
  220. package/workflows/auto-test.md +699 -699
  221. package/workflows/blueprint.md +403 -431
  222. package/workflows/brainstorm.md +54 -195
  223. package/workflows/business-test.md +570 -570
  224. package/workflows/claude-instructions.md +23 -51
  225. package/workflows/codex-instructions.md +27 -77
  226. package/workflows/coding-philosophy.md +69 -69
  227. package/workflows/command-authoring.md +823 -823
  228. package/workflows/debug.md +43 -98
  229. package/workflows/delegate-usage.md +39 -241
  230. package/workflows/execute.md +4 -53
  231. package/workflows/grill.md +12 -56
  232. package/workflows/harvest.md +22 -68
  233. package/workflows/init.md +148 -148
  234. package/workflows/instruction-authoring-guide.md +97 -0
  235. package/workflows/issue-execute.md +110 -110
  236. package/workflows/issue-gaps-analyze.codex.md +260 -260
  237. package/workflows/issue-gaps-analyze.md +216 -216
  238. package/workflows/issue-plan.md +110 -110
  239. package/workflows/issue.md +338 -346
  240. package/workflows/knowhow.md +0 -32
  241. package/workflows/learn.md +277 -277
  242. package/workflows/maestro-chain-execute.md +20 -20
  243. package/workflows/refactor.md +22 -44
  244. package/workflows/retrospective.md +16 -65
  245. package/workflows/review.md +446 -486
  246. package/workflows/roadmap.md +35 -132
  247. package/workflows/skill-authoring.md +265 -265
  248. package/workflows/spec-generate.md +470 -470
  249. package/workflows/specs-remove.md +104 -104
  250. package/workflows/sync.md +11 -41
  251. package/workflows/test-gen.md +226 -226
  252. package/workflows/test.md +385 -475
  253. package/workflows/ui-design.md +391 -391
  254. package/workflows/ui-style.md +199 -199
  255. package/workflows/wiki-connect.md +151 -151
  256. package/workflows/wiki-digest.md +178 -178
  257. package/workflows/wiki-manage.md +109 -109
  258. package/workflows/cli-tools-usage.md +0 -252
  259. package/workflows/delegate-protocol.codex.md +0 -65
@@ -10,875 +10,864 @@ allowed-tools:
10
10
  - view_file
11
11
  - write_to_file
12
12
  ---
13
- <purpose>
14
- Closed-loop runner for the maestro workflow lifecycle.
15
- Single skill every invocation routes by session state, executes one tick, and self-invokes `Skill("maestro-ralph-beta")` until all `completion_confirmed` or paused.
16
-
17
- Entry points:
18
- - **`/maestro-ralph-beta "intent"`** — New session: infer → decompose → build → tick
19
- - **`/maestro-ralph-beta continue`** Resume: locate session tick
20
- - **`/maestro-ralph-beta status`** — Display session progress
21
-
22
- Tick kinds:
23
- - **执行 step** (`step.decision == null`): `maestro ralph next` inline `maestro ralph complete` → self-invoke
24
- - **decision step** (`step.decision != null`): inline evaluate apply verdict → self-invoke
25
-
26
- Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
27
- </purpose>
28
-
29
- <context>
30
- $ARGUMENTS — intent text, flags, or keywords.
31
-
32
- **Parse:**
33
- ```
34
- -y flag → auto_confirm = true
35
- .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
36
- "status" → status mode
37
- "continue" resume mode
38
- Remaining → intent (new session)
39
- ```
40
-
41
- **State files:**
42
- - `.workflow/state.json`artifact registry, milestones, phases
43
- - `.workflow/roadmap.md` — milestone/phase structure
44
- - `.workflow/.maestro/ralph-*/status.json` ralph session state
45
- </context>
46
-
47
- <invariants>
48
- 1. **Self-invocation = `Skill("maestro-ralph-beta")`**每次 tick 末尾强制自调用;除非 router 命中终止条件
49
- 2. **status.json 是唯一真源;写入权限分层**:
50
- - **Step 级字段**(`step.completion_*`, `step.status` 执行 step running↔completed, `step.load.*`, `step.retried`,以及执行 step 的 `active_step_index` 占用/释放)→ 由 `maestro ralph next/complete/retry` CLI 写入
51
- - **会话级结构**(`session.status`, `passed_gates`, `steps[]` 增删/reindex, `task_decomposition[*]`, `boundary_contract`, `context.*`, `scope_verdict`, `consec_exit2_count`, decision step 的 `status`/`retry_count`/`active_step_index` 占用与释放)→ 由 maestro-ralph-beta 写入
52
- 3. **执行 step 通过 `maestro ralph next` 加载** — CLI 解析 frontmatter + `<required_reading>` + `<deferred_reading>`、读 required 全文、拼 prompt、写 `step.load.*` + `active_step_index` + `step.status="running"`
53
- 4. **decision step 内联评估** — 不 handoff、不调 ralph next;按 `step.decision` 分派 A_DECISION_*
54
- 5. **每个 step 必须 `completion_confirmed: true`** — 由 `maestro ralph complete N --status DONE|DONE_WITH_CONCERNS` 写入;STATUS 仅 `DONE | DONE_WITH_CONCERNS | NEEDS_RETRY | BLOCKED`
55
- 6. **command_path A_BUILD_STEPS 解析** — 通过 `maestro ralph skills --platform agy --json --quiet` 预校验(project 覆盖 global,只扫描 `.claude/commands/`);未命中标 `command_scope = "missing"`
56
- 7. **required reading CLI 加载** — 缺失 → 退出码 1(E007)→ pause session;ralph build 阶段不读 .md 内容
57
- 8. **active_step_index 一致性由 CLI 维护** — 同一 session 同时最多一个 step 持有;E008/E009 直接退出
58
- 9. **Decomposition is outcome-oriented** — sub-goals 为可观测交付,禁止 lifecycle 复刻;`/goal` 由用户输入
59
- 10. **planning_mode governs arg granularity** — `unified` → skill args 无 `{phase}`;`independent` → 含 `{phase}`
60
- 11. **task_decomposition 驱动 steps[] 动态生长** — `post-goal-audit` 按 unmet 子目标插入 scoped mini-loop;字段累加,既有字段不删不改
61
- </invariants>
62
-
63
- <router>
64
-
65
- 每次进入 skill 先执行 router,按顺序匹配,先命中先用。术语:
66
- - **active session** = `.workflow/.maestro/ralph-*/status.json` 中 `status ∈ {running, paused}` 的最新会话
67
- - **live session** = active session `status == "running"`
68
- - **active_step** = `session.steps[session.active_step_index]`
69
-
70
- ```
71
- 1. intent == "status" → S_STATUS END
72
- 2. intent == "continue" AND active session exists A_RESUME_SESSION S_TICK_LOCATE
73
- 3. intent non-empty AND intent ∉ {"continue","status"} AND active session exists
74
- → S_FALLBACK → END
75
- display "已有 active session {id};先 /maestro-ralph-beta continue 续跑或显式 abandon"
76
- 4. live session AND active_step.status == "running" AND active_step.decision != null
77
- → S_TICK_LOCATE → S_TICK_DECISION
78
- 5. live session AND has pending step → S_TICK_LOCATE
79
- 6. live session AND all completion_confirmed → S_COMPLETE → END
80
- 7. active session AND session.status == "paused" AND no intent → S_FALLBACK → END
81
- display "Session {id} paused;输入 /maestro-ralph-beta continue 显式恢复"
82
- 8. no active session AND intent non-empty → S_BUILD_PHASE
83
- 9. no active session AND no intent → S_FALLBACK → END
84
- ```
85
-
86
- </router>
87
-
88
- <state_machine>
89
-
90
- <states>
91
- # Build phase (one-time per session)
92
- S_RESOLVE_PHASE 解析 phase + phase_is_new + D-007 milestone PERSIST: session.phase, session.phase_is_new, session.milestone
93
- S_INFER 推断 lifecycle_position PERSIST: session.lifecycle_position
94
- S_RESOLVE_SCOPE macro analyze conclusions.scope_verdict PERSIST: session.scope_verdict, session.analyze_macro_id
95
- S_QUALITY_MODE 决定质量管线模式 PERSIST: session.quality_mode
96
- S_PLANNING_MODE 决定统一/独立规划模式 PERSIST: session.planning_mode
97
- S_DECOMPOSE — 边界澄清、写执行准则+子目标清单 PERSIST: session.boundary_contract, .execution_criteria, .task_decomposition
98
- S_BUILD_CHAIN — 构建步骤链 PERSIST: session.steps[]
99
- S_CREATE_SESSION status.json PERSIST: session (全量)
100
- S_CONFIRM 用户确认 PERSIST:
101
-
102
- # Tick phase (per step)
103
- S_TICK_LOCATE — 定位 session + 找 active step PERSIST: —
104
- S_TICK — 分派执行 step 或 decision step PERSIST: step.status, active_step_index
105
- S_TICK_EXEC — 执行 step:ralph next → inline → ralph complete PERSIST: via CLI
106
- S_TICK_DECISION — decision step:内联评估 + 应用裁决 PERSIST: session.steps[], passed_gates, decisions.ndjson
107
- S_HANDLE_FAIL — 处理执行失败 PERSIST: step.status, session.status
108
-
109
- # Terminal
110
- S_STATUS — 显示 session 进度 PERSIST: —
111
- S_COMPLETE — 收尾 PERSIST: session.status = "completed"
112
- S_FALLBACK — 引导用户输入或退出 PERSIST:
113
- </states>
114
-
115
- <transitions>
116
-
117
- # === Build phase ===
118
-
119
- S_BUILD_PHASE (entry):
120
- → S_RESOLVE_PHASE
121
-
122
- S_RESOLVE_PHASE:
123
- → S_INFER WHEN: phase resolved or null DO: A_RESOLVE_PHASE
124
- → S_FALLBACK WHEN: ambiguous
125
- GUARD: auto_confirm does NOT skip phase ambiguity
126
-
127
- S_INFER:
128
- S_RESOLVE_SCOPE WHEN: position resolved DO: A_INFER_POSITION
129
- S_FALLBACK WHEN: cannot infer
130
-
131
- S_RESOLVE_SCOPE:
132
- S_QUALITY_MODE DO: A_RESOLVE_SCOPE_VERDICT
133
- GUARD: position {brainstorm, blueprint, init} skip (scope_verdict = null)
134
-
135
- S_QUALITY_MODE:
136
- → S_PLANNING_MODE DO: A_DETERMINE_QUALITY_MODE
137
-
138
- S_PLANNING_MODE:
139
- → S_DECOMPOSE DO: A_DETERMINE_PLANNING_MODE
140
- GUARD: lifecycle_position ∈ {brainstorm, blueprint, init, analyze-macro, roadmap} → skip (force independent)
141
-
142
- S_DECOMPOSE:
143
- → S_BUILD_CHAIN DO: A_DECOMPOSE_TASKS
144
- GUARD: broad intent → MUST clarify boundary even if auto_confirm
145
- GUARD: narrow intent auto-derive, skip questions
146
- GUARD: position {brainstorm, blueprint, init} → skip decomposition
147
-
148
- S_BUILD_CHAIN:
149
- S_CREATE_SESSION DO: A_BUILD_STEPS
150
-
151
- S_CREATE_SESSION:
152
- S_CONFIRM WHEN: not auto_confirm DO: A_CREATE_SESSION
153
- S_TICK_LOCATE WHEN: auto_confirm DO: A_CREATE_SESSION + Skill("maestro-ralph-beta")
154
-
155
- S_CONFIRM:
156
- → S_TICK_LOCATE WHEN: user selects "Proceed" DO: Skill("maestro-ralph-beta")
157
- S_BUILD_CHAIN WHEN: user selects "Edit"
158
- END WHEN: user selects "Cancel"
159
-
160
- # === Tick phase ===
161
-
162
- S_TICK_LOCATE: Entry: A_LOCATE_SESSION
163
- S_TICK WHEN: next_pending_step != null
164
- S_COMPLETE WHEN: next_pending_step == null
165
- → S_FALLBACK WHEN: no active session
166
-
167
- S_TICK:
168
- → S_TICK_DECISION WHEN: next_pending_step.decision != null DO: A_CLAIM_DECISION
169
- S_TICK_EXEC WHEN: next_pending_step.decision == null DO: A_RESOLVE_ARGS
170
-
171
- S_TICK_EXEC: Entry: A_EXEC_STEP
172
- → S_TICK_LOCATE WHEN: ralph complete with DONE|DONE_WITH_CONCERNS DO: Skill("maestro-ralph-beta")
173
- S_TICK_LOCATE WHEN: ralph next exit == 2 DO: Skill("maestro-ralph-beta")
174
- → S_HANDLE_FAIL WHEN: ralph next exit == 1 OR exit >= 3
175
- → S_HANDLE_FAIL WHEN: ralph complete with NEEDS_RETRY|BLOCKED
176
-
177
- S_TICK_DECISION: (gate 名取自 `step.decision`)
178
- S_TICK_APPLY WHEN: quality-gate (post-execute, post-business-test, post-review, post-test)
179
- DO: A_DELEGATE_EVALUATE
180
- S_TICK_APPLY WHEN: goal-gate (post-goal-audit)
181
- DO: A_GOAL_AUDIT_EVALUATE
182
- S_TICK_APPLY WHEN: scope-gate (post-analyze-scope)
183
- DO: A_SCOPE_EVALUATE
184
- S_TICK_APPLY WHEN: structural (post-milestone, post-debug-escalate)
185
- DO: A_STRUCTURAL_EVALUATE
186
-
187
- S_TICK_APPLY:
188
- → S_TICK_LOCATE WHEN: verdict == "proceed" DO: A_APPLY_PROCEED + Skill("maestro-ralph-beta")
189
- → S_TICK_LOCATE WHEN: post-goal-audit + unmet sub-goals DO: A_APPLY_GOAL_FIX + Skill("maestro-ralph-beta")
190
- → S_TICK_LOCATE WHEN: post-goal-audit + all sub-goals met DO: A_APPLY_GOAL_DONE + Skill("maestro-ralph-beta")
191
- S_TICK_LOCATE WHEN: post-analyze-scope DO: A_APPLY_SCOPE_VERDICT + Skill("maestro-ralph-beta")
192
- → S_TICK_LOCATE WHEN: verdict == "fix" DO: A_APPLY_FIX + Skill("maestro-ralph-beta")
193
- → S_TICK_LOCATE WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE + Skill("maestro-ralph-beta")
194
- → S_TICK_LOCATE WHEN: post-milestone + standard + next milestone DO: A_ADVANCE_MILESTONE + Skill("maestro-ralph-beta")
195
- → END WHEN: post-milestone + standard + no next milestone DO: mark completed
196
- END WHEN: post-milestone + adhoc DO: mark completed (adhoc self-contained)
197
- END WHEN: post-debug-escalate (always STOP) DO: A_PAUSE_ESCALATE
198
- GUARD: retry_count >= max_retries force escalate
199
- GUARD: confidence_score < 60 AND proceed → override to fix
200
- GUARD: confidence_score > 95 AND fix AND retry > 0 → suggest proceed
201
- GUARD: auto_confirm → skip user prompt, apply adjusted verdict
202
- GUARD: not auto_confirm → ask_question with override options
203
-
204
- S_HANDLE_FAIL:
205
- → S_TICK_LOCATE WHEN: auto + not retried DO: A_RETRY + Skill("maestro-ralph-beta")
206
- → END WHEN: auto + retried DO: A_PAUSE_SESSION
207
- → S_TICK_LOCATE WHEN: interactive + user selects retry DO: A_RETRY + Skill("maestro-ralph-beta")
208
- → S_TICK_LOCATE WHEN: interactive + user selects skip DO: A_SKIP_STEP + Skill("maestro-ralph-beta")
209
- END WHEN: interactive + user selects abort DO: A_PAUSE_SESSION
210
-
211
- # === Terminal ===
212
-
213
- S_STATUS:
214
- → END DO: A_SHOW_STATUS
215
-
216
- S_COMPLETE:
217
- END DO: A_COMPLETE_SESSION
218
-
219
- S_FALLBACK:
220
- S_BUILD_PHASE WHEN: user provides intent (no active session) DO: ask_question
221
- S_TICK_LOCATE WHEN: user selects "continue active session" DO: A_RESUME_SESSION + Skill("maestro-ralph-beta")
222
- END WHEN: user cancels OR no active session for resume
223
-
224
- </transitions>
225
-
226
- <actions>
227
-
228
- ### A_SHOW_STATUS
229
-
230
- 1. Find latest ralph session (by created_at)
231
- 2. Display: Session, Status, Position, Progress, Current step
232
- 3. List steps: [✓] completion_confirmed, [▸] current, [ ] pending, [◆] decision(`step.decision` 非空);执行 step 附 `command_scope`(global/project) + `command_path`
233
- 4. If `task_decomposition` present (absent → skip):
234
- ```
235
- Sub-goals ({done}/{total}) source: {session_dir}/status.json#/task_decomposition
236
- [x] G1 done_when={done_when} evidence={evidence} confirmed={completion_confirmed}
237
- [ ] G2 done_when={done_when} evidence={evidence} confirmed=false ◀ unmet
238
- ```
239
-
240
- ### A_RESOLVE_PHASE
241
-
242
- 产出 `phase` + `phase_is_new` + `milestone`(D-007 反查)。
243
-
244
- **Priority:**
245
-
246
- | Step | 行为 | phase_is_new |
247
- |------|------|--------------|
248
- | 1 | intent 匹配 `phase\s*(\d+)` 取 state.json 对应 phase | false |
249
- | 2 | intent 派生短语 → 在 `state.json.milestones[*].phase_slugs` / `artifacts[*].path` 查找 | false (匹配) / true (无匹配) |
250
- | 3 | 未派生 → 取最新 in-progress artifact 的 phase | false |
251
- | 4 | 仍无 → state.json 首个 incomplete phase | false |
252
- | 5 | position 将是 brainstorm/blueprint/init/roadmap/analyze-macro → phase = null | n/a |
253
- | 6 | 仍模糊 `ask_question` | 由用户回答确定 |
254
-
255
- **D-007 Phase→Milestone 反查**(数字 phase 已解析时):
256
- ```
257
- resolve_milestone(phase_number):
258
- for ms in state.json.milestones:
259
- if str(phase_number) in ms.phase_slugs: return ms.id
260
- return state.json.current_milestone # fallback
261
- ```
262
- 写入 `session.milestone`。
263
-
264
- **写入 session**: `phase`, `phase_is_new`, `milestone`。
265
-
266
- **新派生 phase milestone 处理**:
267
- - state.json 当前 milestone active 沿用,新增 phase
268
- - intent 派生新 milestone 名 → 写入 session 仅作标签;`state.json.milestones` 由 `maestro-roadmap` / `maestro-milestone-release` 创建
269
-
270
- ### A_INFER_POSITION
271
-
272
- **Intent-based overrides** (按顺序匹配,先命中先用):
273
-
274
- | Pattern | Position |
275
- |---------|----------|
276
- | brainstorm / 头脑风暴 / 探索 / ideate / 设计思路 | `brainstorm` |
277
- | blueprint / 规格 / 正式文档 / spec-generate / 7-phase | `blueprint` |
278
- | broad/medium intent 无数字 phase (重构/全面/重写/迁移/新功能 X) | `analyze-macro` |
279
-
280
- **Bootstrap detection:**
281
-
282
- | Condition | Position |
283
- |-----------|----------|
284
- | No `.workflow/` + no source files | `brainstorm` |
285
- | No `.workflow/` + has source files | `init` |
286
- | Has `.workflow/` but no state.json | `init` |
287
- | Has state.json | phase-aware artifact inference |
288
-
289
- **Phase-aware artifact inference**(基于 `session.phase` + `session.phase_is_new`,artifact `session.phase` 过滤):
290
-
291
- | Condition | Position |
292
- |-----------|----------|
293
- | `phase_is_new == true` | `analyze` |
294
- | no milestones AND no roadmap.md AND has analyze macro artifact | `roadmap` |
295
- | no milestones AND no roadmap.md AND no analyze artifact | `analyze-macro` |
296
- | `phase == null` | n/a |
297
- | phase 已存在 + 无任何 artifact | `analyze` |
298
- | phase 已存在 + 最新 artifact = analyze | `plan` |
299
- | phase 已存在 + 最新 artifact = plan | `execute` |
300
- | phase 已存在 + 最新 artifact = execute | refine from post-execute results |
301
-
302
- **Refine from post-execute results:**
303
-
304
- execute artifact 的 scratch dir 中检查结果文件(verification.json 由 execute 内置 gate 产出):
305
-
306
- | Condition | Position |
307
- |-----------|----------|
308
- | verification.json passed==false gaps[] | `execute` (触发 post-execute fix loop) |
309
- | passed==true, no review.json | `business-test` |
310
- | review.json: verdict=="BLOCK" | `review-failed` |
311
- | review.json: verdict!="BLOCK" | `test` |
312
- | uat.md: all passed | `milestone-audit` |
313
- | uat.md: has failures | `test-failed` |
314
-
315
- ### A_RESOLVE_SCOPE_VERDICT
316
-
317
- 仅当 `lifecycle_position {analyze-macro, roadmap, plan}` 且存在最新 analyze artifact 时执行。
318
-
319
- 1. 定位最新 macro analyze artifact(`type=="analyze"` 且 `scope=="macro"`,按 created_at DESC)→ `session.analyze_macro_id = ANL-xxx`
320
- 2. 读 `{artifact_path}/conclusions.json` 的 `scope_verdict` 字段(`large | medium | small`)
321
- 3. 写入 `session.scope_verdict`;缺失 → `unknown`
322
- 4. 路由建议:
323
-
324
- | scope_verdict | 链路 |
325
- |---------------|------|
326
- | `large` | analyze-macroroadmap analyzeplan → execute → ... |
327
- | `medium` / `small` | analyze-macro → plan --from analyze:{ANL_ID} → execute → ... |
328
- | `unknown` | 默认 large;post-analyze-scope 节点再纠正 |
329
-
330
- ### A_DETERMINE_QUALITY_MODE
331
-
332
- 读 `session.quality_mode_override`(CLI `--quality`),无则按规则推断:
333
-
334
- | Condition | Mode | Pipeline (execute 之后) |
335
- |-----------|------|-------------------------|
336
- | Has `specs/REQ-*.md` + 当前 phase 业务范围明确 | `full` | business-test → review → test-gen → test |
337
- | Default | `standard` | review test-gen (当 coverage<80%) → test |
338
- | `--quality quick` | `quick` | review --tier quick |
339
-
340
- 写入 `session.quality_mode`。
341
-
342
- ### A_DETERMINE_PLANNING_MODE
343
-
344
- **Auto-resolve rules (按优先级):**
345
-
346
- | Condition | Mode |
347
- |-----------|------|
348
- | lifecycle_position ∈ {brainstorm, init, roadmap} | `independent` |
349
- | `phase_is_new == true` | `independent` |
350
- | intent 显式指定 phase 编号(如 "phase 2"、"P3") | `independent` |
351
- | milestone 仅含 1 个 phase | `independent` |
352
- | milestone 含多个 phase + `auto_confirm` | `unified` |
353
- | milestone 含多个 phase + 非 `auto_confirm` | → ask_question |
354
-
355
- **ask_question** (仅当 milestone 含 ≥2 phase 且非 auto_confirm):
356
-
357
- ```
358
- question: "当前里程碑含 {N} 个 phase,选择规划模式?"
359
- options:
360
- - label: "统一规划 (Recommended)"
361
- description: "一次性分析+规划整个里程碑所有 phase,analyze/plan 走里程碑级,适合 phase 间关联紧密"
362
- - label: "独立规划"
363
- description: "逐个 phase 走完整生命周期(analyze→plan→execute→...),适合 phase 间独立性高"
364
- ```
365
-
366
- 写入 `session.planning_mode`(`"unified"` 或 `"independent"`)。
367
-
368
- ### A_DECOMPOSE_TASKS
369
-
370
- **1. Classify intent breadth:**
371
-
372
- | Pattern | Breadth | Clarify? |
373
- |---------|---------|----------|
374
- | 重构/全面/重写/重做/整体/迁移 · overhaul/migrate/rewrite/revamp | broad | MUST (ignores auto_confirm) |
375
- | named single file/function/bug, "fix X", "add Y to Z" | narrow | skip — auto-derive |
376
- | otherwise | medium | clarify unless auto_confirm |
377
-
378
- **2. Clarify boundary** (broad/medium) — `ask_question`, ≤3 rounds, options pre-filled from intent + a quick Glob/Grep scan of the target module:
379
-
380
- | Round | Question | Drives |
381
- |-------|----------|--------|
382
- | Scope | 哪些目录/文件/层在范围内?明确排除什么? | boundary_contract.in_scope / out_of_scope |
383
- | Constraints | 必须向后兼容?公共 API 冻结?行为/性能预算?测试门槛? | boundary_contract.constraints + execution_criteria |
384
- | Done | 什么可观测结果算"完成"?(如:测试全绿 + 行为零变更 + X 指标) | boundary_contract.definition_of_done |
385
-
386
- narrow derive defaults from intent + codebase, skip questions.
387
-
388
- **3. Derive `execution_criteria`**: backward-compat、scope-freeze、test/coverage bar、fix-don't-hide、incremental commit。
389
-
390
- **4. Derive `task_decomposition`** (子目标清单 outcome-oriented, NOT lifecycle stages). Each entry:
391
- ```json
392
- { "id": "G1", "goal": "<deliverable>", "boundary": "<in/out note>",
393
- "done_when": "<objectively checkable condition>",
394
- "evidence": "verification.json|review.json|uat.md|<test path>",
395
- "lifecycle": ["analyze","execute"], "status": "pending" }
396
- ```
397
- `done_when` 必须客观可验证,且引用 ralph 已产出的 artifact;`lifecycle` 字段映射到产出 evidence 的生命周期 stage。
398
-
399
- **5. Persist**: `boundary_contract`, `execution_criteria`, `task_decomposition`。每个 sub-goal 初始化 `status: "pending"` + `completion_confirmed: false`。
400
-
401
- **6. Stage** the Goal Prompt (Appendix) for A_CREATE_SESSION to emit.
402
-
403
- ### A_BUILD_STEPS
404
-
405
- `session.lifecycle_position` 生成 steps `milestone-complete`。
406
-
407
- | Stage | Skill (independent) | Skill (unified) | Decision after | quality_mode |
408
- |-------|---------------------|-----------------|----------------|--------------|
409
- | brainstorm | `maestro-brainstorm "{intent}"` | *(same)* | | all |
410
- | blueprint | `maestro-blueprint "{intent}"` | *(same)* | — | all |
411
- | init | `maestro-init` | *(same)* | | all |
412
- | analyze-macro | `maestro-analyze "{intent}"` | *(same)* | `post-analyze-scope` | all |
413
- | roadmap | `maestro-roadmap --from analyze:{analyze_macro_id}` | *(same)* | — | all |
414
- | analyze | `maestro-analyze {phase}` | `maestro-analyze` | — | all |
415
- | plan | `maestro-plan {phase}` *(scope=phase)* / `maestro-plan --from analyze:{analyze_macro_id}` *(scope=standalone)* / `maestro-plan --from blueprint:{blueprint_id}` *(scope=standalone)* | `maestro-plan` | — | all |
416
- | execute | `maestro-execute {phase}` | `maestro-execute` | `post-execute` | all |
417
- | business-test | `quality-auto-test {phase}` | `quality-auto-test` | `post-business-test` | full only |
418
- | review | `quality-review {phase}` | `quality-review` | `post-review` | all (quick: append `--tier quick`) |
419
- | test-gen | `quality-auto-test {phase}` | `quality-auto-test` | — | full / standard if coverage<80% |
420
- | test | `quality-test {phase}` | `quality-test` | `post-test` | full, standard |
421
- | milestone-audit | `maestro-milestone-audit` | *(same)* | — | all |
422
- | goal-audit | *(decision-only)* | *(same)* | `post-goal-audit` | all (only if decomposed) |
423
- | milestone-complete | `maestro-milestone-complete` | *(same)* | `post-milestone` | all |
424
-
425
- **Build rules (按顺序应用):**
426
-
427
- 0. **planning_mode 选列**:`unified` Skill (unified) 列;`independent` Skill (independent)
428
- 1. **起点**:从 `session.lifecycle_position` 开始
429
- 2. **跳过已完成**:跳过当前 milestone+phase 下已有 completed artifact stage(按 `session.phase` 过滤);unified milestone 过滤
430
- 3. **quality_mode 过滤**:按 `session.quality_mode` 排除不匹配 stage
431
- 4. **决策节点**:每个 Decision after 非空的 stage 之后插入 `{ decision: "<gate>", retry_count: 0, max_retries: 2, command_scope: null, command_path: null }`
432
- 5. **goal-audit 插入**:`task_decomposition` 存在时,在最后一个 evidence-producing stage(execute/review/test)之后、`milestone-complete` 之前插入 `decision:post-goal-audit`
433
- 6. **终点硬约束**:chain `milestone-complete` 结尾
434
- 7. **goal_ref 传播**:`task_decomposition` 存在时,每个 step `step.stage g.lifecycle` 匹配 `step.goal_ref = g.id`(多匹配取字典序最小);decision 节点不打 goal_ref
435
- 8. **占位符**:independent 保留 `{phase}` `{intent}`;unified 不带 `{phase}`
436
- 9. **command_path 解析**(执行 step):
437
- - skill = args 前的第一个 token
438
- - `run_command("maestro ralph skills --platform agy --json --quiet")` 拉取 global + project(project 覆盖 global),匹配 skill 名:
439
- - 命中 `command_scope = "global" | "project"`,`command_path = <绝对路径>`
440
- - 未命中 `command_scope = "missing"`, `command_path = null` → A_CREATE_SESSION raise E006
441
- 10. **每个 step 初始化** `completion_confirmed: false`, `completion_status: null`, `completion_evidence: null`, `deferred_reads: []`, `load: null`
442
- 11. **scope_verdict gating**(仅当 chain 起点 = `analyze-macro`):
443
- - `scope_verdict ∈ {medium, small}` → 跳过 `roadmap` + `analyze` 两 stage;`plan` 选 standalone 列(`--from analyze:{analyze_macro_id}`),不带 `{phase}`
444
- - `scope_verdict == large` → 保留 `roadmap` + `analyze`;`plan` 选 phase 列(`{phase}`)
445
- - `scope_verdict == unknown` 默认 large 路径;由 `post-analyze-scope` 决策节点在 macro analyze 完成后纠正(A_APPLY_SCOPE_VERDICT)
446
- 12. **--from 自动注入**:
447
- - `analyze_macro_id` 存在且当前 step `roadmap` args 改为 `--from analyze:{analyze_macro_id}`
448
- - `analyze_macro_id` 存在且 `scope_verdict {medium, small}` 且当前 step 是 `plan` → args 改为 `--from analyze:{analyze_macro_id}`
449
- - `blueprint_id` 存在 → 当前 step 是 `plan` → args 改为 `--from blueprint:{blueprint_id}`(优先级低于 phase 数字参数)
450
- - 写入 `step.source_artifact_ref` 以便审计
451
- 13. **Milestone-ref**:含 `{phase}` 占位符的 step → `step.milestone_id = session.milestone`
452
- 14. **动态插入步骤**(A_APPLY_*)同样应用规则 7-13
453
-
454
- ### A_CREATE_SESSION
455
-
456
- 1. 校验所有 step `command_scope != "missing"`;否则 raise E006 + 列出缺失 skill
457
- 2. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
458
- 3. Display chain overview:每步显示 `{index}. {skill} [{command_scope}]`
459
- 4. `task_decomposition` 存在 → display Goal Prompt block,继续进入 tick
460
-
461
- ### A_LOCATE_SESSION
462
-
463
- 1. If session_id provided load `.workflow/.maestro/{session_id}/status.json`
464
- 2. Else: scan `.workflow/.maestro/*/status.json`, filter `status {"running","paused"}`, sort DESC by created_at, take first
465
- 3. Extract: session_id, source, steps[], phase, milestone, intent, auto_mode, context, cli_tool, active_step_index, status
466
- 4. 预探测 `next_pending_step`(瞬态,不持久化):
467
- - 若 `active_step_index != null` 且 `steps[active_step_index].status == "running"` → `steps[active_step_index]`
468
- - 否则 `steps[]` 中 `status == "pending"` 的最小 index
469
- - 都无 → `null`
470
-
471
- ### A_RESUME_SESSION
472
-
473
- 1. A_LOCATE_SESSION 加载 active session
474
- 2. 清理 active_step_index:若 `active_step_index != null` 且 `steps[active_step_index].status ∈ {"completed","skipped","failed"}` → `active_step_index = null`;其余保留
475
- 3. If `session.status == "paused"` → `session.status = "running"`
476
- 4. `session.consec_exit2_count = 0`
477
- 5. Display: `↻ Resume {session_id}`
478
-
479
- ### A_CLAIM_DECISION
480
-
481
- 1. 校验 `session.active_step_index {null, next_pending_step.index}`,否则 raise E008
482
- 2. `session.active_step_index = next_pending_step.index`
483
- 3. `steps[next_pending_step.index].status = "running"`
484
- 4. Display: `[{index}/{total}] {step.decision} Retry: {retry}/{max}`
485
-
486
- ### A_RESOLVE_ARGS
487
-
488
- **Placeholder substitution:**
489
-
490
- | Placeholder | Source |
491
- |-------------|--------|
492
- | `{phase}` | session.phase |
493
- | `{milestone}` | session.milestone |
494
- | `{intent}` | session.intent |
495
- | `{description}` | session.intent (alias) |
496
- | `{scratch_dir}` | session.context.scratch_dir or latest artifact path |
497
- | `{plan_dir}` | session.context.plan_dir |
498
- | `{analysis_dir}` | session.context.analysis_dir |
499
- | `{issue_id}` | session.context.issue_id |
500
- | `{milestone_num}` | session.context.milestone_num |
501
-
502
- **Per-skill enrichment** (when args empty or minimal):
503
-
504
- | Skill | Required context | Source |
505
- |-------|-----------------|--------|
506
- | maestro-brainstorm | topic | `"{intent}"` |
507
- | maestro-roadmap | description | `"{intent}"` |
508
- | maestro-analyze | phase or topic | `{phase}` or `"{intent}"` |
509
- | maestro-plan | phase or --dir | `{phase}`, or `--dir {scratch_dir}` |
510
- | maestro-execute | phase or --dir | `{phase}`, or `--dir {scratch_dir}` |
511
- | quality-debug | gap context | Read previous step's error/gap |
512
- | quality-* | phase | `{phase}` |
513
-
514
- **Artifact dir resolution for --dir:**
515
- ```
516
- Read state.jsonfilter artifacts by milestone + phase
517
- plan commands: latest type=="analyze"--dir .workflow/scratch/{path}
518
- execute commands: latest type=="plan"--dir .workflow/scratch/{path}
519
- ```
520
-
521
- Write enriched args back to status.json.
522
-
523
- ### A_EXEC_STEP
524
-
525
- 1. **Load** — `run_command("maestro ralph next")`
526
- - exit 0 → `session.consec_exit2_count = 0`,按 stdout 内联执行(进入步骤 2)
527
- - exit 2 → `session.consec_exit2_count += 1`;≥ 2 时抛 E010 → S_HANDLE_FAIL;否则 → S_TICK_LOCATE
528
- - exit 1 → E007 → S_HANDLE_FAIL
529
- - exit 3 E008 S_HANDLE_FAIL
530
- 2. **Inline execution** stdout 执行;deferred_reading 按需 Read
531
- 3. **Complete**:
532
- - `run_command("maestro ralph complete N --status DONE [--evidence <path>]")`
533
- - `run_command("maestro ralph complete N --status DONE_WITH_CONCERNS --concerns \"...\"")`
534
- - `run_command("maestro ralph retry N")`
535
- - `run_command("maestro ralph complete N --status BLOCKED --reason \"...\"")`
536
- 4. **Propagate context signals** — `PHASE: N` / `scratch_dir: path` / `BLP-xxx` 写入 `status.json.context`
537
-
538
- ### A_DELEGATE_EVALUATE
539
-
540
- 1. Resolve artifact dir: `.workflow/scratch/{artifact.path}/` with fallback glob
541
- 2. Parse decision metadata: `{ decision, retry_count, max_retries }`
542
- 3. Map result files:
543
- | Decision | Files |
544
- |----------|-------|
545
- | post-execute | verification.json |
546
- | post-business-test | .tests/auto-test/report.json |
547
- | post-review | review.json |
548
- | post-test | uat.md, .tests/test-results.json |
549
- 4. Check artifact for confidence section → include as signal
550
- 5. Execute delegate (run_in_background, STOP, wait for callback):
551
- ```
552
- maestro delegate "PURPOSE: 评估 {decision} 质量门结果
553
- TASK: 读取结果 | 分析状态 | 评估严重性 | 给出建议
554
- EXPECTED: ---VERDICT--- STATUS/REASON/GAP_SUMMARY/CONFIDENCE(high|medium|low)/CONFIDENCE_SCORE(0-100)/WEAKEST_DIMENSION ---END---
555
- CONSTRAINTS: 只评估 | 置信度<60% 倾向 fix | retry {n}/{max} 达上限必须 escalate"
556
- --role analyze --mode analysis
557
- ```
558
- 6. On callback: parse verdict; if parse fails → fallback STATUS="fix"
559
- 7. Confidence adjustment: <60 + proceed → fix; >95 + fix + retry>0 → suggest proceed
560
- 8. **Decision log**: Append to `{session_dir}/decisions.ndjson`:
561
- ```json
562
- { "id": "DEC-{timestamp}", "timestamp": "{ISO}", "source": "ralph",
563
- "node_id": "{step.decision}", "type": "quality-gate",
564
- "verdict": "{adjusted_verdict}", "confidence_score": {N},
565
- "close_call": {N>=50 && N<=70}, "summary": "{REASON}" }
566
- ```
567
-
568
- ### A_STRUCTURAL_EVALUATE
569
-
570
- **post-milestone:**
571
- 1. Read state.json取已完成 milestone 对象
572
- 2. `milestone_obj.type` (default `"standard"`)
573
- 3. `type == "standard"`:next milestone 存在 → insert lifecycle steps;否则 → END
574
- 4. `type == "adhoc"`:END,`current_milestone = null`
575
-
576
- **post-debug-escalate:** STOP paused,display "请人工介入"
577
-
578
- ### A_SCOPE_EVALUATE
579
-
580
- `post-analyze-scope` 触发。
581
-
582
- 1. 定位刚完成的 macro analyze artifact → `analyze_macro_id`, `conclusions_path = {artifact_path}/conclusions.json`
583
- 2. 读取 `conclusions.scope_verdict`(`large | medium | small`),缺失 → `unknown`
584
- 3. 写入 `session.scope_verdict` + `session.analyze_macro_id`
585
- 4. Append `{session_dir}/decisions.ndjson`:
586
- ```json
587
- { "id": "DEC-{timestamp}", "type": "scope-gate",
588
- "source": "ralph", "node_id": "post-analyze-scope",
589
- "verdict": "{scope_verdict}", "analyze_macro_id": "{ANL_ID}" }
590
- ```
591
- 5. → A_APPLY_SCOPE_VERDICT
592
-
593
- ### A_GOAL_AUDIT_EVALUATE
594
-
595
- 仅当 `task_decomposition` 存在。
596
-
597
- 1. Read `session.task_decomposition`
598
- 2. For each sub-goal `status != "done"`:resolve `evidence` artifact
599
- 3. Delegate read-only audit (run_in_background, STOP, wait):
600
- ```
601
- maestro delegate "PURPOSE: 审计未完成子目标,判定 met / unmet
602
- TASK:
603
- 1. 读取 status.json.task_decomposition 中 status!=done 的子目标
604
- 2. 打开 evidence 产物,对照 done_when 严格判定
605
- 3. 输出 met / unmet,unmet 给出 gap + target_phase
606
- CONTEXT:
607
- status.json = {session_dir}/status.json
608
- evidence = {evidence artifacts}
609
- execution_criteria = {execution_criteria}
610
- boundary_contract = {boundary_contract}
611
- EXPECTED:
612
- ---VERDICT---
613
- STATUS=all_met|has_unmet
614
- UNMET=[{id:G2,gap:'...',target_phase:execute}, ...]
615
- CONFIDENCE_SCORE=0-100
616
- ---END---
617
- CONSTRAINTS:
618
- - 只评估,不修改文件
619
- - 严格按 done_when 判定;evidence 缺失 unmet
620
- - 不得建议超出 boundary_contract 的修改
621
- "
622
- --role analyze --mode analysis
623
- ```
624
- 4. On callback: 对每个 met 子目标,set `task_decomposition[i].status="done"` + `completion_confirmed=true` + `completed_at=now`
625
- 5. Append `{session_dir}/decisions.ndjson` with `"type": "goal-gate"`, `unmet_count`, `unmet_ids`
626
- 6. Verdict: `all_met` A_APPLY_GOAL_DONE; `has_unmet` A_APPLY_GOAL_FIX
627
- GUARD: retry_count >= max_retries AND still unmet → A_APPLY_ESCALATE
628
-
629
- > **A_APPLY_\* release 协议**(所有 A_APPLY_* 末尾统一应用):
630
- > - 完成分支(proceed / goal-done / scope applied / structural advanced):`step.status = "completed"`, `step.completion_confirmed = true`, `session.active_step_index = null`
631
- > - 重评分支(fix / escalate / goal-fix):`step.status = "pending"`, `step.completion_confirmed = false`, `session.active_step_index = null`, `step.retry_count += 1`
632
-
633
- ### A_APPLY_PROCEED
634
-
635
- 1. release 协议 — 完成分支
636
- 2. Append decisions.ndjson with verdict
637
- 3. Display: Decision: {type} → proceed ({reason})
638
-
639
- ### A_APPLY_FIX
640
-
641
- 1. Insert fix-loop commands after current step (Appendix: Fix-Loop Templates)
642
- 2. release 协议 — 重评分支;reindex steps
643
- 3. Display: ◆ Decision: {type} → fix, +{N} commands inserted
644
-
645
- ### A_APPLY_ESCALATE
646
-
647
- 1. Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`
648
- 2. release 协议 重评分支;reindex
649
-
650
- ### A_APPLY_SCOPE_VERDICT
651
-
652
- 由 `post-analyze-scope` 触发。
653
-
654
- 1. 读 `session.scope_verdict`
655
- 2. `large`:为后续 `roadmap` step 注入 `--from analyze:{analyze_macro_id}`;后续 `plan` step phase 列
656
- 3. `medium` / `small`:
657
- - 删除 `goal-audit` 之前未完成的 `roadmap` + `analyze` (phase) step
658
- - 下一个未完成的 `plan` step `maestro-plan --from analyze:{analyze_macro_id}`,去掉 `{phase}`,`source_artifact_ref = analyze:{analyze_macro_id}`
659
- - 后续 `execute` 等沿用同一 standalone scope
660
- 4. `unknown`:非 auto_confirm → ask_question 二选一(large / medium-small);auto_confirm → 默认 large
661
- 5. release 协议 — 完成分支;reindex
662
- 6. Display: Scope verdict: {verdict} {kept|collapsed to standalone via analyze:{ANL_ID}}
663
-
664
- ### A_APPLY_GOAL_FIX
665
-
666
- 1. 对每个 unmet 子目标 `G{n}`(按 `target_phase` 分组去重):在 `goal-audit` 节点前插入 scoped mini-loop(Appendix: post-goal-audit),每条 step `goal_ref: "G{n}"`
667
- 2. 追加 `decision:post-goal-audit {retry+1}`
668
- 3. release 协议 重评分支;reindex
669
- 4. Display: Goal audit: {k} unmet → +{N} steps inserted (G{ids}), retry {r}/{max}
670
-
671
- ### A_APPLY_GOAL_DONE
672
-
673
- 1. 每个 `task_decomposition[*]` → `status="done"`, `completion_confirmed=true`, `completed_at=now`;顶层 `task_decomposition_all_done=true`
674
- 2. release 协议 完成分支;proceed to `milestone-complete`
675
- 3. Display: Goal audit: all met ✓
676
-
677
- ### A_ADVANCE_MILESTONE
678
-
679
- 1. Update session: milestone, phase, reset passed_gates
680
- 2. Insert full lifecycle steps for next milestone
681
- 3. release 协议 — 完成分支;reindex
682
-
683
- ### A_RETRY
684
-
685
- 1. `run_command("maestro ralph retry N")`
686
- 2. Display: `[{index}/{total}] ↻ {step.skill} retry`
687
-
688
- ### A_SKIP_STEP
689
-
690
- 手动编辑 status.json:`step.status = "skipped"`, `step.completion_confirmed = false`,若 `active_step_index == step.index` 则置 null。
691
-
692
- ### A_PAUSE_SESSION
693
-
694
- `session.status = "paused"` (CLI 通过 `ralph complete N --status BLOCKED` 自动写;手动场景直接编辑)
695
- Display: `[{index}/{total}] {step.skill} 失败,会话已暂停。/maestro-ralph-beta continue 恢复。`
696
-
697
- ### A_PAUSE_ESCALATE
698
-
699
- 1. `session.status = "paused"`
700
- 2. Display: ◆ 已达最大重试次数,debug 已执行。请人工介入。
701
- 3. Display: /maestro-ralph-beta continue 恢复
702
-
703
- ### A_COMPLETE_SESSION
704
-
705
- 1. 校验:所有 step `completion_confirmed == true`(除 skipped);task_decomposition 存在时校验 `task_decomposition_all_done == true`
706
- 2. 任一校验失败 → 不标 completed,回 S_TICK_LOCATE 或 pause
707
- 3. `session.status = "completed"`, write status.json
708
- 4. Display completion report:
709
- ```
710
- ============================================================
711
- SESSION COMPLETE
712
- ============================================================
713
- Session: {session_id} [{source}]
714
- Steps: {completed}/{total} confirmed: {confirmed}/{completed}
715
-
716
- [✓] 0. maestro-plan 1 [global]
717
- [✓] 1. maestro-execute 1 [project]
718
- [✓] 2. ◆ post-execute [decision]
719
- ...
720
- ============================================================
721
- ```
722
- Icons: `✓` confirmed, `—` skipped, `✗` failed, `◆` decision
723
-
724
- </actions>
725
-
726
- </state_machine>
727
-
728
- <appendix>
729
-
730
- ### Session Schema
731
-
732
- ```json
733
- {
734
- "session_id": "ralph-{YYYYMMDD-HHmmss}",
735
- "source": "ralph", "status": "running",
736
- "ralph_protocol_version": "2",
737
- "active_step_index": null,
738
- "intent": "", "lifecycle_position": "",
739
- "phase": null, "phase_is_new": false,
740
- "milestone": "", // D-007 反查结果
741
- "auto_mode": false,
742
- "quality_mode": "standard", // "full" | "standard" | "quick"
743
- "planning_mode": "independent", // "unified" | "independent"
744
- "scope_verdict": null, // "large" | "medium" | "small" | "unknown" | null
745
- "analyze_macro_id": null, // "ANL-xxx"
746
- "blueprint_id": null, // "BLP-xxx"
747
- "cli_tool": "claude", "passed_gates": [],
748
- "consec_exit2_count": 0,
749
-
750
- "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
751
- "analysis_dir": null, "brainstorm_dir": null, "blueprint_dir": null },
752
- "steps": [{
753
- "index": 0,
754
- "skill": "", // 执行 step 有值;decision 节点为空字符串/null
755
- "args": "",
756
- "stage": "", // brainstorm|blueprint|init|analyze-macro|roadmap|analyze|plan|execute|...
757
- "scope": null, // "phase"|"standalone"|"milestone"|null(plan 等需要)
758
- "decision": null, // null = 执行 step;非 null = decision step (值为 gate 名)
759
- "retry_count": 0, // decision step
760
- "max_retries": 2, // decision step
761
- "command_scope": "global|project|missing|null",
762
- "command_path": "<absolute path> | null",
763
- "milestone_id": null, // 仅含 {phase} 占位符的 step
764
- "source_artifact_ref": null, // "analyze:ANL-xxx" | "blueprint:BLP-xxx" | null
765
- "status": "pending|running|completed|skipped|failed",
766
- "goal_ref": null,
767
- "completion_confirmed": false,
768
- "completion_status": null,
769
- "completion_evidence": null,
770
- "completed_at": null,
771
- "deferred_reads": [],
772
- "load": null // { loaded_at, required_files[], deferred_files[], resolve_version }
773
- }],
774
- "current_step": 0,
775
-
776
- "boundary_contract": {
777
- "in_scope": [], "out_of_scope": [], "constraints": [], "definition_of_done": ""
778
- },
779
- "execution_criteria": [],
780
- "task_decomposition": [
781
- { "id": "G1", "goal": "", "boundary": "", "done_when": "",
782
- "evidence": "", "lifecycle": [], "status": "pending|done",
783
- "completion_confirmed": false, "completed_at": null }
784
- ],
785
- "task_decomposition_all_done": false
786
- }
787
- ```
788
-
789
- ### Fix-Loop Templates
790
-
791
- 插入的执行 step 按 A_BUILD_STEPS 规则 9 解析 `command_path` + `command_scope`;`decision:*` 条目为 decision 节点。
792
-
793
- **post-execute:**
794
- ```
795
- quality-debug "{gap_summary}"
796
- maestro-plan --gaps {phase}
797
- maestro-execute {phase}
798
- decision:post-execute {retry+1}
799
- ```
800
-
801
- **post-business-test:**
802
- ```
803
- quality-debug --from-business-test "{gap_summary}"
804
- maestro-plan --gaps {phase}
805
- maestro-execute {phase}
806
- decision:post-execute {retry: 0}
807
- quality-auto-test {phase}
808
- decision:post-business-test {retry+1}
809
- ```
810
-
811
- **post-review:**
812
- ```
813
- quality-debug "{gap_summary}"
814
- maestro-plan --gaps {phase}
815
- maestro-execute {phase}
816
- quality-review {phase}
817
- decision:post-review {retry+1}
818
- ```
819
-
820
- **post-test:**
821
- ```
822
- quality-debug --from-uat "{gap_summary}"
823
- maestro-plan --gaps {phase}
824
- maestro-execute {phase}
825
- decision:post-execute {retry: 0}
826
- quality-auto-test {phase}
827
- decision:post-business-test {retry: 0}
828
- quality-review {phase}
829
- decision:post-review {retry: 0}
830
- quality-auto-test {phase}
831
- quality-test {phase}
832
- decision:post-test {retry+1}
833
- ```
834
-
835
- **post-goal-audit:** (per unmet sub-goal group)
836
- ```
837
- # for each unmet sub-goal G{n}, scoped to target_phase:
838
- maestro-plan --gaps {target_phase} "G{n}: {gap}" [goal_ref: G{n}]
839
- maestro-execute {target_phase} [goal_ref: G{n}]
840
- # after all unmet groups inserted:
841
- decision:post-goal-audit {retry+1}
842
- ```
843
-
844
- ### Goal Prompt Template
845
-
846
- decomposition 产出后,链路概览之后逐字显示:
847
-
848
- ```
849
- 📋 任务分解完成。可随时复制以下 /goal 设定终止条件:
850
-
851
- /goal 直到 {session_dir}/status.json task_decomposition[*] steps[*] 全部 completion_confirmed=true 才停。每轮以 status.json 为唯一行动手册,通过 /maestro-ralph-beta 推进 tick;decision 节点由 ralph 内联评估。禁止手动执行 skill 或修改 boundary_contract.out_of_scope。
852
- ```
853
-
854
- ### Error Codes
855
-
856
- | Code | Severity | Description | Recovery |
857
- |------|----------|-------------|----------|
858
- | E001 | error | No intent and no running session | Prompt for intent |
859
- | E002 | error | Cannot infer lifecycle position | Show raw state, ask |
860
- | E003 | error | Artifact dir not found for decision | Show glob, ask |
861
- | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
862
- | E005 | error | Delegate execution failed | Fallback: "fix" |
863
- | E006 | error | command_scope == "missing" for one or more steps | List missing skills, abort build |
864
- | E007 | error | required_reading 引用文件缺失 | `ralph next` 拒绝;CLI stderr 列出缺失路径 |
865
- | E008 | error | `ralph complete` idx ≠ active_step_index | 编辑 status.json 修正一致性 |
866
- | E009 | error | `ralph complete` step.status ≠ running | 重复 complete 或非法跳跃;编辑 status.json |
867
- | E010 | error | status.json schema 损坏 OR A_EXEC_STEP exit=2 熔断(连续 ≥2 次空转) | `ralph check` 显示损坏字段;熔断需人工核对 next_pending_step 与 router 路由是否一致 |
868
- | W001 | warning | Decision expanded chain | Auto-handled |
869
- | W002 | warning | Max retries, escalating | Auto-handled |
870
- | W003 | warning | Multiple running sessions | Use latest, warn |
871
- | W004 | warning | Low delegate confidence | Show warning |
872
- | W005 | warning | active_step_index 指向已 completed step | `ralph next` 自动清理后继续 |
873
- | W007 | warning | step.skill ≠ command .md frontmatter.name | 提示但不阻塞 |
874
-
875
- ### Success Criteria
876
-
877
- - [ ] Tick 末尾自调用 `Skill("maestro-ralph-beta")`,直到全部 `completion_confirmed` 或 paused
878
- - [ ] 同一 session 同时仅一个 step 持 `active_step_index`;切换前必经 release
879
- - [ ] Decision step 全程不调 `maestro ralph next` / `complete`,由 maestro-ralph-beta 内联评估并 release
880
- - [ ] `task_decomposition` 存在时,chain 含 `decision:post-goal-audit`,且最终 `task_decomposition_all_done == true` 才允许 S_COMPLETE
881
- - [ ] Chain 以 `milestone-complete` 结尾;A_APPLY_* 修改 steps[] 后均 reindex
882
- - [ ] 连续 2 次 `ralph next` exit=2 → E010 pause(防 router 错路由空转)
883
-
884
- </appendix>
13
+ <purpose>
14
+ Self-running closed-loop: routes by session state, executes one tick, self-invokes until done or paused.
15
+ Single skill handles build + execute + decision evaluation. Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`.
16
+ </purpose>
17
+
18
+ <context>
19
+ $ARGUMENTSintent text, flags, or keywords.
20
+
21
+ **Parse:**
22
+ ```
23
+ -y flag auto_confirm = true
24
+ .md/.txt path input_doc (supplementary context only, NEVER substitutes lifecycle stages)
25
+ "status" → status mode
26
+ "continue" → resume mode
27
+ Remaining → intent (new session)
28
+ ```
29
+
30
+ **State files:**
31
+ - `.workflow/state.json` — artifact registry, milestones, phases
32
+ - `.workflow/roadmap.md` — milestone/phase structure
33
+ - `.workflow/.maestro/ralph-*/status.json` — ralph session state
34
+ </context>
35
+
36
+ <invariants>
37
+ 1. **Self-invocation = `Skill("maestro-ralph-beta")`** 每次 tick 末尾强制自调用;除非 router 命中终止条件
38
+ 2. **status.json 是唯一真源;写入权限分层**:
39
+ - **Step 级字段**(`step.completion_*`, `step.status` 执行 step running↔completed, `step.load.*`, `step.retried`,以及执行 step 的 `active_step_index` 占用/释放)→ 由 `maestro ralph next/complete/retry` CLI 写入
40
+ - **会话级结构**(`session.status`, `passed_gates`, `steps[]` 增删/reindex, `task_decomposition[*]`, `boundary_contract`, `context.*`, `scope_verdict`, `consec_exit2_count`, decision step 的 `status`/`retry_count`/`active_step_index` 占用与释放)→ 由 maestro-ralph-beta 写入
41
+ 3. **执行 step 通过 `maestro ralph next` 加载** — CLI 解析 frontmatter + `<required_reading>` + `<deferred_reading>`、读 required 全文、拼 prompt、写 `step.load.*` + `active_step_index` + `step.status="running"`
42
+ 4. **decision step 内联评估** handoff、不调 ralph next;按 `step.decision` 分派 A_DECISION_*
43
+ 5. **每个 step 必须 `completion_confirmed: true`** `maestro ralph complete N --status DONE|DONE_WITH_CONCERNS` 写入;STATUS 仅 `DONE | DONE_WITH_CONCERNS | NEEDS_RETRY | BLOCKED`
44
+ 6. **command_path 在 A_BUILD_STEPS 解析** — 通过 `maestro ralph skills --platform agy --json --quiet` 预校验(project 覆盖 global,只扫描 `.claude/commands/`);未命中标 `command_scope = "missing"`
45
+ 7. **required reading 由 CLI 加载** — 缺失 → 退出码 1(E007)→ pause session;ralph build 阶段不读 .md 内容
46
+ 8. **active_step_index 一致性由 CLI 维护** — 同一 session 同时最多一个 step 持有;E008/E009 直接退出
47
+ 9. **Decomposition is outcome-oriented** — sub-goals 为可观测交付,禁止 lifecycle 复刻;`/goal` 由用户输入
48
+ 10. **planning_mode governs arg granularity** `unified` skill args 无 `{phase}`;`independent` → 含 `{phase}`
49
+ 11. **task_decomposition 驱动 steps[] 动态生长** — `post-goal-audit` 按 unmet 子目标插入 scoped mini-loop;字段累加,既有字段不删不改
50
+ </invariants>
51
+
52
+ <router>
53
+
54
+ 每次进入 skill 先执行 router,按顺序匹配,先命中先用。术语:
55
+ - **active session** = `.workflow/.maestro/ralph-*/status.json` `status {running, paused}` 的最新会话
56
+ - **live session** = active session `status == "running"`
57
+ - **active_step** = `session.steps[session.active_step_index]`
58
+
59
+ ```
60
+ 1. intent == "status" → S_STATUS → END
61
+ 2. intent == "continue" AND active session exists → A_RESUME_SESSION → S_TICK_LOCATE
62
+ 3. intent non-empty AND intent ∉ {"continue","status"} AND active session exists
63
+ → S_FALLBACK → END
64
+ display "已有 active session {id};先 /maestro-ralph-beta continue 续跑或显式 abandon"
65
+ 4. live session AND active_step.status == "running" AND active_step.decision != null
66
+ S_TICK_LOCATE S_TICK_DECISION
67
+ 5. live session AND has pending step → S_TICK_LOCATE
68
+ 6. live session AND all completion_confirmed → S_COMPLETE → END
69
+ 7. active session AND session.status == "paused" AND no intent → S_FALLBACK → END
70
+ display "Session {id} paused;输入 /maestro-ralph-beta continue 显式恢复"
71
+ 8. no active session AND intent non-empty S_BUILD_PHASE
72
+ 9. no active session AND no intent S_FALLBACK END
73
+ ```
74
+
75
+ </router>
76
+
77
+ <state_machine>
78
+
79
+ <states>
80
+ # Build phase (one-time per session)
81
+ S_RESOLVE_PHASE 解析 phase + phase_is_new + D-007 milestone PERSIST: session.phase, session.phase_is_new, session.milestone
82
+ S_INFER — 推断 lifecycle_position PERSIST: session.lifecycle_position
83
+ S_RESOLVE_SCOPE — macro analyze conclusions.scope_verdict PERSIST: session.scope_verdict, session.analyze_macro_id
84
+ S_QUALITY_MODE — 决定质量管线模式 PERSIST: session.quality_mode
85
+ S_PLANNING_MODE — 决定统一/独立规划模式 PERSIST: session.planning_mode
86
+ S_DECOMPOSE — 边界澄清、写执行准则+子目标清单 PERSIST: session.boundary_contract, .execution_criteria, .task_decomposition
87
+ S_BUILD_CHAIN — 构建步骤链 PERSIST: session.steps[]
88
+ S_CREATE_SESSION — 写 status.json PERSIST: session (全量)
89
+ S_CONFIRM — 用户确认 PERSIST: —
90
+
91
+ # Tick phase (per step)
92
+ S_TICK_LOCATE 定位 session + active step PERSIST:
93
+ S_TICK 分派执行 step 或 decision step PERSIST: step.status, active_step_index
94
+ S_TICK_EXEC 执行 step:ralph next → inline → ralph complete PERSIST: via CLI
95
+ S_TICK_DECISION decision step:内联评估 + 应用裁决 PERSIST: session.steps[], passed_gates, decisions.ndjson
96
+ S_HANDLE_FAIL 处理执行失败 PERSIST: step.status, session.status
97
+
98
+ # Terminal
99
+ S_STATUS 显示 session 进度 PERSIST:
100
+ S_COMPLETE 收尾 PERSIST: session.status = "completed"
101
+ S_FALLBACK — 引导用户输入或退出 PERSIST: —
102
+ </states>
103
+
104
+ <transitions>
105
+
106
+ # === Build phase ===
107
+
108
+ S_BUILD_PHASE (entry):
109
+ S_RESOLVE_PHASE
110
+
111
+ S_RESOLVE_PHASE:
112
+ S_INFER WHEN: phase resolved or null DO: A_RESOLVE_PHASE
113
+ → S_FALLBACK WHEN: ambiguous
114
+ GUARD: auto_confirm does NOT skip phase ambiguity
115
+
116
+ S_INFER:
117
+ S_RESOLVE_SCOPE WHEN: position resolved DO: A_INFER_POSITION
118
+ → S_FALLBACK WHEN: cannot infer
119
+
120
+ S_RESOLVE_SCOPE:
121
+ → S_QUALITY_MODE DO: A_RESOLVE_SCOPE_VERDICT
122
+ GUARD: position ∈ {brainstorm, blueprint, init} → skip (scope_verdict = null)
123
+
124
+ S_QUALITY_MODE:
125
+ S_PLANNING_MODE DO: A_DETERMINE_QUALITY_MODE
126
+
127
+ S_PLANNING_MODE:
128
+ S_DECOMPOSE DO: A_DETERMINE_PLANNING_MODE
129
+ GUARD: lifecycle_position ∈ {brainstorm, blueprint, init, analyze-macro, roadmap} skip (force independent)
130
+
131
+ S_DECOMPOSE:
132
+ S_BUILD_CHAIN DO: A_DECOMPOSE_TASKS
133
+ GUARD: broad intent MUST clarify boundary even if auto_confirm
134
+ GUARD: narrow intent → auto-derive, skip questions
135
+ GUARD: position ∈ {brainstorm, blueprint, init} → skip decomposition
136
+
137
+ S_BUILD_CHAIN:
138
+ → S_CREATE_SESSION DO: A_BUILD_STEPS
139
+
140
+ S_CREATE_SESSION:
141
+ → S_CONFIRM WHEN: not auto_confirm DO: A_CREATE_SESSION
142
+ → S_TICK_LOCATE WHEN: auto_confirm DO: A_CREATE_SESSION + Skill("maestro-ralph-beta")
143
+
144
+ S_CONFIRM:
145
+ → S_TICK_LOCATE WHEN: user selects "Proceed" DO: Skill("maestro-ralph-beta")
146
+ → S_BUILD_CHAIN WHEN: user selects "Edit"
147
+ → END WHEN: user selects "Cancel"
148
+
149
+ # === Tick phase ===
150
+
151
+ S_TICK_LOCATE: Entry: A_LOCATE_SESSION
152
+ S_TICK WHEN: next_pending_step != null
153
+ S_COMPLETE WHEN: next_pending_step == null
154
+ → S_FALLBACK WHEN: no active session
155
+
156
+ S_TICK:
157
+ S_TICK_DECISION WHEN: next_pending_step.decision != null DO: A_CLAIM_DECISION
158
+ S_TICK_EXEC WHEN: next_pending_step.decision == null DO: A_RESOLVE_ARGS
159
+
160
+ S_TICK_EXEC: Entry: A_EXEC_STEP
161
+ → S_TICK_LOCATE WHEN: ralph complete with DONE|DONE_WITH_CONCERNS DO: Skill("maestro-ralph-beta")
162
+ S_TICK_LOCATE WHEN: ralph next exit == 2 DO: Skill("maestro-ralph-beta")
163
+ S_HANDLE_FAIL WHEN: ralph next exit == 1 OR exit >= 3
164
+ S_HANDLE_FAIL WHEN: ralph complete with NEEDS_RETRY|BLOCKED
165
+
166
+ S_TICK_DECISION: (gate 名取自 `step.decision`)
167
+ → S_TICK_APPLY WHEN: quality-gate (post-execute, post-business-test, post-review, post-test)
168
+ DO: A_DELEGATE_EVALUATE
169
+ S_TICK_APPLY WHEN: goal-gate (post-goal-audit)
170
+ DO: A_GOAL_AUDIT_EVALUATE
171
+ S_TICK_APPLY WHEN: scope-gate (post-analyze-scope)
172
+ DO: A_SCOPE_EVALUATE
173
+ S_TICK_APPLY WHEN: structural (post-milestone, post-debug-escalate)
174
+ DO: A_STRUCTURAL_EVALUATE
175
+
176
+ S_TICK_APPLY:
177
+ → S_TICK_LOCATE WHEN: verdict == "proceed" DO: A_APPLY_PROCEED + Skill("maestro-ralph-beta")
178
+ S_TICK_LOCATE WHEN: post-goal-audit + unmet sub-goals DO: A_APPLY_GOAL_FIX + Skill("maestro-ralph-beta")
179
+ → S_TICK_LOCATE WHEN: post-goal-audit + all sub-goals met DO: A_APPLY_GOAL_DONE + Skill("maestro-ralph-beta")
180
+ S_TICK_LOCATE WHEN: post-analyze-scope DO: A_APPLY_SCOPE_VERDICT + Skill("maestro-ralph-beta")
181
+ → S_TICK_LOCATE WHEN: verdict == "fix" DO: A_APPLY_FIX + Skill("maestro-ralph-beta")
182
+ S_TICK_LOCATE WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE + Skill("maestro-ralph-beta")
183
+ → S_TICK_LOCATE WHEN: post-milestone + standard + next milestone DO: A_ADVANCE_MILESTONE + Skill("maestro-ralph-beta")
184
+ END WHEN: post-milestone + standard + no next milestone DO: mark completed
185
+ → END WHEN: post-milestone + adhoc DO: mark completed (adhoc self-contained)
186
+ → END WHEN: post-debug-escalate (always STOP) DO: A_PAUSE_ESCALATE
187
+ GUARD: retry_count >= max_retries → force escalate
188
+ GUARD: confidence_score < 60 AND proceed override to fix
189
+ GUARD: confidence_score > 95 AND fix AND retry > 0 → suggest proceed
190
+ GUARD: auto_confirm skip user prompt, apply adjusted verdict
191
+ GUARD: not auto_confirm ask_question with override options
192
+
193
+ S_HANDLE_FAIL:
194
+ → S_TICK_LOCATE WHEN: auto + not retried DO: A_RETRY + Skill("maestro-ralph-beta")
195
+ → END WHEN: auto + retried DO: A_PAUSE_SESSION
196
+ S_TICK_LOCATE WHEN: interactive + user selects retry DO: A_RETRY + Skill("maestro-ralph-beta")
197
+ S_TICK_LOCATE WHEN: interactive + user selects skip DO: A_SKIP_STEP + Skill("maestro-ralph-beta")
198
+ → END WHEN: interactive + user selects abort DO: A_PAUSE_SESSION
199
+
200
+ # === Terminal ===
201
+
202
+ S_STATUS:
203
+ → END DO: A_SHOW_STATUS
204
+
205
+ S_COMPLETE:
206
+ → END DO: A_COMPLETE_SESSION
207
+
208
+ S_FALLBACK:
209
+ S_BUILD_PHASE WHEN: user provides intent (no active session) DO: ask_question
210
+ → S_TICK_LOCATE WHEN: user selects "continue active session" DO: A_RESUME_SESSION + Skill("maestro-ralph-beta")
211
+ END WHEN: user cancels OR no active session for resume
212
+
213
+ </transitions>
214
+
215
+ <actions>
216
+
217
+ ### A_SHOW_STATUS
218
+
219
+ 1. Find latest ralph session (by created_at)
220
+ 2. Display: Session, Status, Position, Progress, Current step
221
+ 3. List steps: [✓] completion_confirmed, [▸] current, [ ] pending, [◆] decision(`step.decision` 非空);执行 step 附 `command_scope`(global/project) + `command_path`
222
+ 4. If `task_decomposition` present (absent skip):
223
+ ```
224
+ Sub-goals ({done}/{total}) source: {session_dir}/status.json#/task_decomposition
225
+ [x] G1 done_when={done_when} evidence={evidence} confirmed={completion_confirmed}
226
+ [ ] G2 done_when={done_when} evidence={evidence} confirmed=false ◀ unmet
227
+ ```
228
+
229
+ ### A_RESOLVE_PHASE
230
+
231
+ 产出 `phase` + `phase_is_new` + `milestone`(D-007 反查)。
232
+
233
+ **Priority:**
234
+
235
+ | Step | 行为 | phase_is_new |
236
+ |------|------|--------------|
237
+ | 1 | intent 匹配 `phase\s*(\d+)` → 取 state.json 对应 phase | false |
238
+ | 2 | intent 派生短语 → 在 `state.json.milestones[*].phase_slugs` / `artifacts[*].path` 查找 | false (匹配) / true (无匹配) |
239
+ | 3 | 未派生 → 取最新 in-progress artifact 的 phase | false |
240
+ | 4 | 仍无 → state.json 首个 incomplete phase | false |
241
+ | 5 | position 将是 brainstorm/blueprint/init/roadmap/analyze-macro → phase = null | n/a |
242
+ | 6 | 仍模糊 → `ask_question` | 由用户回答确定 |
243
+
244
+ **D-007 Phase→Milestone 反查**(数字 phase 已解析时):
245
+ ```
246
+ resolve_milestone(phase_number):
247
+ for ms in state.json.milestones:
248
+ if str(phase_number) in ms.phase_slugs: return ms.id
249
+ return state.json.current_milestone # fallback
250
+ ```
251
+ 写入 `session.milestone`。
252
+
253
+ **写入 session**: `phase`, `phase_is_new`, `milestone`。
254
+
255
+ **新派生 phase milestone 处理**:
256
+ - state.json 当前 milestone 仍 active → 沿用,新增 phase
257
+ - intent 派生新 milestone 名 → 写入 session 仅作标签;`state.json.milestones` 由 `maestro-roadmap` / `maestro-milestone-release` 创建
258
+
259
+ ### A_INFER_POSITION
260
+
261
+ **Intent-based overrides** (按顺序匹配,先命中先用):
262
+
263
+ | Pattern | Position |
264
+ |---------|----------|
265
+ | brainstorm / 头脑风暴 / 探索 / ideate / 设计思路 | `brainstorm` |
266
+ | blueprint / 规格 / 正式文档 / spec-generate / 7-phase | `blueprint` |
267
+ | broad/medium intent 无数字 phase (重构/全面/重写/迁移/新功能 X) | `analyze-macro` |
268
+
269
+ **Bootstrap detection:**
270
+
271
+ | Condition | Position |
272
+ |-----------|----------|
273
+ | No `.workflow/` + no source files | `brainstorm` |
274
+ | No `.workflow/` + has source files | `init` |
275
+ | Has `.workflow/` but no state.json | `init` |
276
+ | Has state.json | phase-aware artifact inference |
277
+
278
+ **Phase-aware artifact inference**(基于 `session.phase` + `session.phase_is_new`,artifact `session.phase` 过滤):
279
+
280
+ | Condition | Position |
281
+ |-----------|----------|
282
+ | `phase_is_new == true` | `analyze` |
283
+ | no milestones AND no roadmap.md AND has analyze macro artifact | `roadmap` |
284
+ | no milestones AND no roadmap.md AND no analyze artifact | `analyze-macro` |
285
+ | `phase == null` | n/a |
286
+ | phase 已存在 + 无任何 artifact | `analyze` |
287
+ | phase 已存在 + 最新 artifact = analyze | `plan` |
288
+ | phase 已存在 + 最新 artifact = plan | `execute` |
289
+ | phase 已存在 + 最新 artifact = execute | → refine from post-execute results |
290
+
291
+ **Refine from post-execute results:**
292
+
293
+ execute artifact scratch dir 中检查结果文件(verification.json 由 execute 内置 gate 产出):
294
+
295
+ | Condition | Position |
296
+ |-----------|----------|
297
+ | verification.json passed==false gaps[] | `execute` (触发 post-execute fix loop) |
298
+ | passed==true, no review.json | `business-test` |
299
+ | review.json: verdict=="BLOCK" | `review-failed` |
300
+ | review.json: verdict!="BLOCK" | `test` |
301
+ | uat.md: all passed | `milestone-audit` |
302
+ | uat.md: has failures | `test-failed` |
303
+
304
+ ### A_RESOLVE_SCOPE_VERDICT
305
+
306
+ 仅当 `lifecycle_position {analyze-macro, roadmap, plan}` 且存在最新 analyze artifact 时执行。
307
+
308
+ 1. 定位最新 macro analyze artifact(`type=="analyze"` `scope=="macro"`,按 created_at DESC)→ `session.analyze_macro_id = ANL-xxx`
309
+ 2. `{artifact_path}/conclusions.json` `scope_verdict` 字段(`large | medium | small`)
310
+ 3. 写入 `session.scope_verdict`;缺失 `unknown`
311
+ 4. 路由建议:
312
+
313
+ | scope_verdict | 链路 |
314
+ |---------------|------|
315
+ | `large` | analyze-macro → roadmap → analyze → plan → execute → ... |
316
+ | `medium` / `small` | analyze-macro → plan --from analyze:{ANL_ID} → execute → ... |
317
+ | `unknown` | 默认 large;post-analyze-scope 节点再纠正 |
318
+
319
+ ### A_DETERMINE_QUALITY_MODE
320
+
321
+ `session.quality_mode_override`(CLI `--quality`),无则按规则推断:
322
+
323
+ | Condition | Mode | Pipeline (execute 之后) |
324
+ |-----------|------|-------------------------|
325
+ | Has `specs/REQ-*.md` + 当前 phase 业务范围明确 | `full` | business-test → review → test-gen → test |
326
+ | Default | `standard` | reviewtest-gen (当 coverage<80%)test |
327
+ | `--quality quick` | `quick` | review --tier quick |
328
+
329
+ 写入 `session.quality_mode`。
330
+
331
+ ### A_DETERMINE_PLANNING_MODE
332
+
333
+ **Auto-resolve rules (按优先级):**
334
+
335
+ | Condition | Mode |
336
+ |-----------|------|
337
+ | lifecycle_position {brainstorm, init, roadmap} | `independent` |
338
+ | `phase_is_new == true` | `independent` |
339
+ | intent 显式指定 phase 编号(如 "phase 2"、"P3") | `independent` |
340
+ | milestone 仅含 1 个 phase | `independent` |
341
+ | milestone 含多个 phase + `auto_confirm` | `unified` |
342
+ | milestone 含多个 phase + 非 `auto_confirm` | → ask_question |
343
+
344
+ **ask_question** (仅当 milestone 含 ≥2 phase 且非 auto_confirm):
345
+
346
+ ```
347
+ question: "当前里程碑含 {N} 个 phase,选择规划模式?"
348
+ options:
349
+ - label: "统一规划 (Recommended)"
350
+ description: "一次性分析+规划整个里程碑所有 phase,analyze/plan 走里程碑级,适合 phase 间关联紧密"
351
+ - label: "独立规划"
352
+ description: "逐个 phase 走完整生命周期(analyze→plan→execute→...),适合 phase 间独立性高"
353
+ ```
354
+
355
+ 写入 `session.planning_mode`(`"unified"` `"independent"`)。
356
+
357
+ ### A_DECOMPOSE_TASKS
358
+
359
+ **1. Classify intent breadth:**
360
+
361
+ | Pattern | Breadth | Clarify? |
362
+ |---------|---------|----------|
363
+ | 重构/全面/重写/重做/整体/迁移 · overhaul/migrate/rewrite/revamp | broad | MUST (ignores auto_confirm) |
364
+ | named single file/function/bug, "fix X", "add Y to Z" | narrow | skip — auto-derive |
365
+ | otherwise | medium | clarify unless auto_confirm |
366
+
367
+ **2. Clarify boundary** (broad/medium) — `ask_question`, ≤3 rounds, options pre-filled from intent + a quick Glob/Grep scan of the target module:
368
+
369
+ | Round | Question | Drives |
370
+ |-------|----------|--------|
371
+ | Scope | 哪些目录/文件/层在范围内?明确排除什么? | boundary_contract.in_scope / out_of_scope |
372
+ | Constraints | 必须向后兼容?公共 API 冻结?行为/性能预算?测试门槛? | boundary_contract.constraints + execution_criteria |
373
+ | Done | 什么可观测结果算"完成"?(如:测试全绿 + 行为零变更 + X 指标) | boundary_contract.definition_of_done |
374
+
375
+ narrow derive defaults from intent + codebase, skip questions.
376
+
377
+ **3. Derive `execution_criteria`**: backward-compat、scope-freeze、test/coverage bar、fix-don't-hide、incremental commit。
378
+
379
+ **4. Derive `task_decomposition`** (子目标清单 — outcome-oriented, NOT lifecycle stages). Each entry:
380
+ ```json
381
+ { "id": "G1", "goal": "<deliverable>", "boundary": "<in/out note>",
382
+ "done_when": "<objectively checkable condition>",
383
+ "evidence": "verification.json|review.json|uat.md|<test path>",
384
+ "lifecycle": ["analyze","execute"], "status": "pending" }
385
+ ```
386
+ `done_when` 必须客观可验证,且引用 ralph 已产出的 artifact;`lifecycle` 字段映射到产出 evidence 的生命周期 stage。
387
+
388
+ **5. Persist**: `boundary_contract`, `execution_criteria`, `task_decomposition`。每个 sub-goal 初始化 `status: "pending"` + `completion_confirmed: false`。
389
+
390
+ **6. Stage** the Goal Prompt (Appendix) for A_CREATE_SESSION to emit.
391
+
392
+ ### A_BUILD_STEPS
393
+
394
+ `session.lifecycle_position` 生成 steps 到 `milestone-complete`。
395
+
396
+ | Stage | Skill (independent) | Skill (unified) | Decision after | quality_mode |
397
+ |-------|---------------------|-----------------|----------------|--------------|
398
+ | brainstorm | `maestro-brainstorm "{intent}"` | *(same)* | — | all |
399
+ | blueprint | `maestro-blueprint "{intent}"` | *(same)* | | all |
400
+ | init | `maestro-init` | *(same)* | — | all |
401
+ | analyze-macro | `maestro-analyze "{intent}"` | *(same)* | `post-analyze-scope` | all |
402
+ | roadmap | `maestro-roadmap --from analyze:{analyze_macro_id}` | *(same)* | — | all |
403
+ | analyze | `maestro-analyze {phase}` | `maestro-analyze` | — | all |
404
+ | plan | `maestro-plan {phase}` *(scope=phase)* / `maestro-plan --from analyze:{analyze_macro_id}` *(scope=standalone)* / `maestro-plan --from blueprint:{blueprint_id}` *(scope=standalone)* | `maestro-plan` | — | all |
405
+ | execute | `maestro-execute {phase}` | `maestro-execute` | `post-execute` | all |
406
+ | business-test | `quality-auto-test {phase}` | `quality-auto-test` | `post-business-test` | full only |
407
+ | review | `quality-review {phase}` | `quality-review` | `post-review` | all (quick: append `--tier quick`) |
408
+ | test-gen | `quality-auto-test {phase}` | `quality-auto-test` | — | full / standard if coverage<80% |
409
+ | test | `quality-test {phase}` | `quality-test` | `post-test` | full, standard |
410
+ | milestone-audit | `maestro-milestone-audit` | *(same)* | — | all |
411
+ | goal-audit | *(decision-only)* | *(same)* | `post-goal-audit` | all (only if decomposed) |
412
+ | milestone-complete | `maestro-milestone-complete` | *(same)* | `post-milestone` | all |
413
+
414
+ **Build rules (按顺序应用):**
415
+
416
+ 0. **planning_mode 选列**:`unified` Skill (unified) 列;`independent` Skill (independent)
417
+ 1. **起点**:从 `session.lifecycle_position` 开始
418
+ 2. **跳过已完成**:跳过当前 milestone+phase 下已有 completed artifact stage(按 `session.phase` 过滤);unified milestone 过滤
419
+ 3. **quality_mode 过滤**:按 `session.quality_mode` 排除不匹配 stage
420
+ 4. **决策节点**:每个 Decision after 非空的 stage 之后插入 `{ decision: "<gate>", retry_count: 0, max_retries: 2, command_scope: null, command_path: null }`
421
+ 5. **goal-audit 插入**:`task_decomposition` 存在时,在最后一个 evidence-producing stage(execute/review/test)之后、`milestone-complete` 之前插入 `decision:post-goal-audit`
422
+ 6. **终点硬约束**:chain `milestone-complete` 结尾
423
+ 7. **goal_ref 传播**:`task_decomposition` 存在时,每个 step `step.stage ∈ g.lifecycle` 匹配 `step.goal_ref = g.id`(多匹配取字典序最小);decision 节点不打 goal_ref
424
+ 8. **占位符**:independent 保留 `{phase}` `{intent}`;unified 不带 `{phase}`
425
+ 9. **command_path 解析**(执行 step):
426
+ - skill 名 = args 前的第一个 token
427
+ - `run_command("maestro ralph skills --platform agy --json --quiet")` 拉取 global + project(project 覆盖 global),匹配 skill 名:
428
+ - 命中 `command_scope = "global" | "project"`,`command_path = <绝对路径>`
429
+ - 未命中 `command_scope = "missing"`, `command_path = null` A_CREATE_SESSION raise E006
430
+ 10. **每个 step 初始化** `completion_confirmed: false`, `completion_status: null`, `completion_evidence: null`, `deferred_reads: []`, `load: null`
431
+ 11. **scope_verdict gating**(仅当 chain 起点 = `analyze-macro`):
432
+ - `scope_verdict {medium, small}` → 跳过 `roadmap` + `analyze` 两 stage;`plan` standalone 列(`--from analyze:{analyze_macro_id}`),不带 `{phase}`
433
+ - `scope_verdict == large` → 保留 `roadmap` + `analyze`;`plan` 选 phase 列(`{phase}`)
434
+ - `scope_verdict == unknown` 默认 large 路径;由 `post-analyze-scope` 决策节点在 macro analyze 完成后纠正(A_APPLY_SCOPE_VERDICT)
435
+ 12. **--from 自动注入**:
436
+ - `analyze_macro_id` 存在且当前 step 是 `roadmap` → args 改为 `--from analyze:{analyze_macro_id}`
437
+ - `analyze_macro_id` 存在且 `scope_verdict ∈ {medium, small}` 且当前 step 是 `plan` → args 改为 `--from analyze:{analyze_macro_id}`
438
+ - `blueprint_id` 存在 当前 step `plan` args 改为 `--from blueprint:{blueprint_id}`(优先级低于 phase 数字参数)
439
+ - 写入 `step.source_artifact_ref` 以便审计
440
+ 13. **Milestone-ref**:含 `{phase}` 占位符的 step `step.milestone_id = session.milestone`
441
+ 14. **动态插入步骤**(A_APPLY_*)同样应用规则 7-13
442
+
443
+ ### A_CREATE_SESSION
444
+
445
+ 1. 校验所有 step `command_scope != "missing"`;否则 raise E006 + 列出缺失 skill
446
+ 2. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
447
+ 3. Display chain overview:每步显示 `{index}. {skill} [{command_scope}]`
448
+ 4. `task_decomposition` 存在 display Goal Prompt block,继续进入 tick
449
+
450
+ ### A_LOCATE_SESSION
451
+
452
+ 1. If session_id provided → load `.workflow/.maestro/{session_id}/status.json`
453
+ 2. Else: scan `.workflow/.maestro/*/status.json`, filter `status ∈ {"running","paused"}`, sort DESC by created_at, take first
454
+ 3. Extract: session_id, source, steps[], phase, milestone, intent, auto_mode, context, cli_tool, active_step_index, status
455
+ 4. 预探测 `next_pending_step`(瞬态,不持久化):
456
+ - `active_step_index != null` `steps[active_step_index].status == "running"` `steps[active_step_index]`
457
+ - 否则 `steps[]` 中 `status == "pending"` 的最小 index
458
+ - 都无 `null`
459
+
460
+ ### A_RESUME_SESSION
461
+
462
+ 1. A_LOCATE_SESSION 加载 active session
463
+ 2. 清理 active_step_index:若 `active_step_index != null` 且 `steps[active_step_index].status ∈ {"completed","skipped","failed"}` → `active_step_index = null`;其余保留
464
+ 3. If `session.status == "paused"` `session.status = "running"`
465
+ 4. `session.consec_exit2_count = 0`
466
+ 5. Display: `↻ Resume {session_id}`
467
+
468
+ ### A_CLAIM_DECISION
469
+
470
+ 1. 校验 `session.active_step_index ∈ {null, next_pending_step.index}`,否则 raise E008
471
+ 2. `session.active_step_index = next_pending_step.index`
472
+ 3. `steps[next_pending_step.index].status = "running"`
473
+ 4. Display: `[{index}/{total}] {step.decision} Retry: {retry}/{max}`
474
+
475
+ ### A_RESOLVE_ARGS
476
+
477
+ **Placeholder substitution:**
478
+
479
+ | Placeholder | Source |
480
+ |-------------|--------|
481
+ | `{phase}` | session.phase |
482
+ | `{milestone}` | session.milestone |
483
+ | `{intent}` | session.intent |
484
+ | `{description}` | session.intent (alias) |
485
+ | `{scratch_dir}` | session.context.scratch_dir or latest artifact path |
486
+ | `{plan_dir}` | session.context.plan_dir |
487
+ | `{analysis_dir}` | session.context.analysis_dir |
488
+ | `{issue_id}` | session.context.issue_id |
489
+ | `{milestone_num}` | session.context.milestone_num |
490
+
491
+ **Per-skill enrichment** (when args empty or minimal):
492
+
493
+ | Skill | Required context | Source |
494
+ |-------|-----------------|--------|
495
+ | maestro-brainstorm | topic | `"{intent}"` |
496
+ | maestro-roadmap | description | `"{intent}"` |
497
+ | maestro-analyze | phase or topic | `{phase}` or `"{intent}"` |
498
+ | maestro-plan | phase or --dir | `{phase}`, or `--dir {scratch_dir}` |
499
+ | maestro-execute | phase or --dir | `{phase}`, or `--dir {scratch_dir}` |
500
+ | quality-debug | gap context | Read previous step's error/gap |
501
+ | quality-* | phase | `{phase}` |
502
+
503
+ **Artifact dir resolution for --dir:**
504
+ ```
505
+ Read state.json → filter artifacts by milestone + phase
506
+ plan commands: latest type=="analyze" --dir .workflow/scratch/{path}
507
+ execute commands: latest type=="plan" --dir .workflow/scratch/{path}
508
+ ```
509
+
510
+ Write enriched args back to status.json.
511
+
512
+ ### A_EXEC_STEP
513
+
514
+ 1. **Load** `run_command("maestro ralph next")`
515
+ - exit 0 → `session.consec_exit2_count = 0`,按 stdout 内联执行(进入步骤 2)
516
+ - exit 2 `session.consec_exit2_count += 1`;≥ 2 时抛 E010 → S_HANDLE_FAIL;否则 → S_TICK_LOCATE
517
+ - exit 1 E007 S_HANDLE_FAIL
518
+ - exit 3E008 → S_HANDLE_FAIL
519
+ 2. **Inline execution** — 按 stdout 执行;deferred_reading 按需 Read
520
+ 3. **Complete**:
521
+ - `run_command("maestro ralph complete N --status DONE [--evidence <path>]")`
522
+ - `run_command("maestro ralph complete N --status DONE_WITH_CONCERNS --concerns \"...\"")`
523
+ - `run_command("maestro ralph retry N")`
524
+ - `run_command("maestro ralph complete N --status BLOCKED --reason \"...\"")`
525
+ 4. **Propagate context signals** — `PHASE: N` / `scratch_dir: path` / `BLP-xxx` 写入 `status.json.context`
526
+
527
+ ### A_DELEGATE_EVALUATE
528
+
529
+ 1. Resolve artifact dir: `.workflow/scratch/{artifact.path}/` with fallback glob
530
+ 2. Parse decision metadata: `{ decision, retry_count, max_retries }`
531
+ 3. Map result files:
532
+ | Decision | Files |
533
+ |----------|-------|
534
+ | post-execute | verification.json |
535
+ | post-business-test | .tests/auto-test/report.json |
536
+ | post-review | review.json |
537
+ | post-test | uat.md, .tests/test-results.json |
538
+ 4. Check artifact for confidence section → include as signal
539
+ 5. Execute delegate (run_in_background, STOP, wait for callback):
540
+ ```
541
+ maestro delegate "PURPOSE: 评估 {decision} 质量门结果
542
+ TASK: 读取结果 | 分析状态 | 评估严重性 | 给出建议
543
+ EXPECTED: ---VERDICT--- STATUS/REASON/GAP_SUMMARY/CONFIDENCE(high|medium|low)/CONFIDENCE_SCORE(0-100)/WEAKEST_DIMENSION ---END---
544
+ CONSTRAINTS: 只评估 | 置信度<60% 倾向 fix | retry {n}/{max} 达上限必须 escalate"
545
+ --role analyze --mode analysis
546
+ ```
547
+ 6. On callback: parse verdict; if parse fails → fallback STATUS="fix"
548
+ 7. Confidence adjustment: <60 + proceed → fix; >95 + fix + retry>0 → suggest proceed
549
+ 8. **Decision log**: Append to `{session_dir}/decisions.ndjson`:
550
+ ```json
551
+ { "id": "DEC-{timestamp}", "timestamp": "{ISO}", "source": "ralph",
552
+ "node_id": "{step.decision}", "type": "quality-gate",
553
+ "verdict": "{adjusted_verdict}", "confidence_score": {N},
554
+ "close_call": {N>=50 && N<=70}, "summary": "{REASON}" }
555
+ ```
556
+
557
+ ### A_STRUCTURAL_EVALUATE
558
+
559
+ **post-milestone:**
560
+ 1. Read state.json 取已完成 milestone 对象
561
+ 2. `milestone_obj.type` (default `"standard"`)
562
+ 3. `type == "standard"`:next milestone 存在 → insert lifecycle steps;否则 → END
563
+ 4. `type == "adhoc"`:END,`current_milestone = null`
564
+
565
+ **post-debug-escalate:** STOP paused,display "请人工介入"
566
+
567
+ ### A_SCOPE_EVALUATE
568
+
569
+ 由 `post-analyze-scope` 触发。
570
+
571
+ 1. 定位刚完成的 macro analyze artifact `analyze_macro_id`, `conclusions_path = {artifact_path}/conclusions.json`
572
+ 2. 读取 `conclusions.scope_verdict`(`large | medium | small`),缺失 → `unknown`
573
+ 3. 写入 `session.scope_verdict` + `session.analyze_macro_id`
574
+ 4. Append `{session_dir}/decisions.ndjson`:
575
+ ```json
576
+ { "id": "DEC-{timestamp}", "type": "scope-gate",
577
+ "source": "ralph", "node_id": "post-analyze-scope",
578
+ "verdict": "{scope_verdict}", "analyze_macro_id": "{ANL_ID}" }
579
+ ```
580
+ 5. A_APPLY_SCOPE_VERDICT
581
+
582
+ ### A_GOAL_AUDIT_EVALUATE
583
+
584
+ 仅当 `task_decomposition` 存在。
585
+
586
+ 1. Read `session.task_decomposition`
587
+ 2. For each sub-goal `status != "done"`:resolve `evidence` artifact
588
+ 3. Delegate read-only audit (run_in_background, STOP, wait):
589
+ ```
590
+ maestro delegate "PURPOSE: 审计未完成子目标,判定 met / unmet
591
+ TASK:
592
+ 1. 读取 status.json.task_decomposition 中 status!=done 的子目标
593
+ 2. 打开 evidence 产物,对照 done_when 严格判定
594
+ 3. 输出 met / unmet,unmet 给出 gap + target_phase
595
+ CONTEXT:
596
+ status.json = {session_dir}/status.json
597
+ evidence = {evidence artifacts}
598
+ execution_criteria = {execution_criteria}
599
+ boundary_contract = {boundary_contract}
600
+ EXPECTED:
601
+ ---VERDICT---
602
+ STATUS=all_met|has_unmet
603
+ UNMET=[{id:G2,gap:'...',target_phase:execute}, ...]
604
+ CONFIDENCE_SCORE=0-100
605
+ ---END---
606
+ CONSTRAINTS:
607
+ - 只评估,不修改文件
608
+ - 严格按 done_when 判定;evidence 缺失 → unmet
609
+ - 不得建议超出 boundary_contract 的修改
610
+ "
611
+ --role analyze --mode analysis
612
+ ```
613
+ 4. On callback: 对每个 met 子目标,set `task_decomposition[i].status="done"` + `completion_confirmed=true` + `completed_at=now`
614
+ 5. Append `{session_dir}/decisions.ndjson` with `"type": "goal-gate"`, `unmet_count`, `unmet_ids`
615
+ 6. Verdict: `all_met` → A_APPLY_GOAL_DONE; `has_unmet` → A_APPLY_GOAL_FIX
616
+ GUARD: retry_count >= max_retries AND still unmet → A_APPLY_ESCALATE
617
+
618
+ > **A_APPLY_\* release 协议**(所有 A_APPLY_* 末尾统一应用):
619
+ > - 完成分支(proceed / goal-done / scope applied / structural advanced):`step.status = "completed"`, `step.completion_confirmed = true`, `session.active_step_index = null`
620
+ > - 重评分支(fix / escalate / goal-fix):`step.status = "pending"`, `step.completion_confirmed = false`, `session.active_step_index = null`, `step.retry_count += 1`
621
+
622
+ ### A_APPLY_PROCEED
623
+
624
+ 1. release 协议 完成分支
625
+ 2. Append decisions.ndjson with verdict
626
+ 3. Display: Decision: {type}proceed ({reason})
627
+
628
+ ### A_APPLY_FIX
629
+
630
+ 1. Insert fix-loop commands after current step (Appendix: Fix-Loop Templates)
631
+ 2. release 协议 重评分支;reindex steps
632
+ 3. Display: ◆ Decision: {type} → fix, +{N} commands inserted
633
+
634
+ ### A_APPLY_ESCALATE
635
+
636
+ 1. Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`
637
+ 2. release 协议 重评分支;reindex
638
+
639
+ ### A_APPLY_SCOPE_VERDICT
640
+
641
+ `post-analyze-scope` 触发。
642
+
643
+ 1. `session.scope_verdict`
644
+ 2. `large`:为后续 `roadmap` step 注入 `--from analyze:{analyze_macro_id}`;后续 `plan` step 选 phase 列
645
+ 3. `medium` / `small`:
646
+ - 删除 `goal-audit` 之前未完成的 `roadmap` + `analyze` (phase) step
647
+ - 下一个未完成的 `plan` step → `maestro-plan --from analyze:{analyze_macro_id}`,去掉 `{phase}`,`source_artifact_ref = analyze:{analyze_macro_id}`
648
+ - 后续 `execute` 等沿用同一 standalone scope
649
+ 4. `unknown`:非 auto_confirm → ask_question 二选一(large / medium-small);auto_confirm → 默认 large
650
+ 5. release 协议 — 完成分支;reindex
651
+ 6. Display: ◆ Scope verdict: {verdict} → {kept|collapsed to standalone via analyze:{ANL_ID}}
652
+
653
+ ### A_APPLY_GOAL_FIX
654
+
655
+ 1. 对每个 unmet 子目标 `G{n}`(按 `target_phase` 分组去重):在 `goal-audit` 节点前插入 scoped mini-loop(Appendix: post-goal-audit),每条 step `goal_ref: "G{n}"`
656
+ 2. 追加 `decision:post-goal-audit {retry+1}`
657
+ 3. release 协议 重评分支;reindex
658
+ 4. Display: Goal audit: {k} unmet → +{N} steps inserted (G{ids}), retry {r}/{max}
659
+
660
+ ### A_APPLY_GOAL_DONE
661
+
662
+ 1. 每个 `task_decomposition[*]``status="done"`, `completion_confirmed=true`, `completed_at=now`;顶层 `task_decomposition_all_done=true`
663
+ 2. release 协议 — 完成分支;proceed to `milestone-complete`
664
+ 3. Display: ◆ Goal audit: all met ✓
665
+
666
+ ### A_ADVANCE_MILESTONE
667
+
668
+ 1. Update session: milestone, phase, reset passed_gates
669
+ 2. Insert full lifecycle steps for next milestone
670
+ 3. release 协议 — 完成分支;reindex
671
+
672
+ ### A_RETRY
673
+
674
+ 1. `run_command("maestro ralph retry N")`
675
+ 2. Display: `[{index}/{total}] {step.skill} retry`
676
+
677
+ ### A_SKIP_STEP
678
+
679
+ 手动编辑 status.json:`step.status = "skipped"`, `step.completion_confirmed = false`,若 `active_step_index == step.index` 则置 null。
680
+
681
+ ### A_PAUSE_SESSION
682
+
683
+ `session.status = "paused"` (CLI 通过 `ralph complete N --status BLOCKED` 自动写;手动场景直接编辑)
684
+ Display: `[{index}/{total}] ✗ {step.skill} 失败,会话已暂停。/maestro-ralph-beta continue 恢复。`
685
+
686
+ ### A_PAUSE_ESCALATE
687
+
688
+ 1. `session.status = "paused"`
689
+ 2. Display: ◆ 已达最大重试次数,debug 已执行。请人工介入。
690
+ 3. Display: /maestro-ralph-beta continue 恢复
691
+
692
+ ### A_COMPLETE_SESSION
693
+
694
+ 1. 校验:所有 step `completion_confirmed == true`(除 skipped);task_decomposition 存在时校验 `task_decomposition_all_done == true`
695
+ 2. 任一校验失败 不标 completed,回 S_TICK_LOCATE 或 pause
696
+ 3. `session.status = "completed"`, write status.json
697
+ 4. Display completion report:
698
+ ```
699
+ ============================================================
700
+ SESSION COMPLETE
701
+ ============================================================
702
+ Session: {session_id} [{source}]
703
+ Steps: {completed}/{total} confirmed: {confirmed}/{completed}
704
+
705
+ [✓] 0. maestro-plan 1 [global]
706
+ [✓] 1. maestro-execute 1 [project]
707
+ [✓] 2. post-execute [decision]
708
+ ...
709
+ ============================================================
710
+ ```
711
+ Icons: `✓` confirmed, `—` skipped, `✗` failed, `◆` decision
712
+
713
+ </actions>
714
+
715
+ </state_machine>
716
+
717
+ <appendix>
718
+
719
+ ### Session Schema
720
+
721
+ ```json
722
+ {
723
+ "session_id": "ralph-{YYYYMMDD-HHmmss}",
724
+ "source": "ralph", "status": "running",
725
+ "ralph_protocol_version": "2",
726
+ "active_step_index": null,
727
+ "intent": "", "lifecycle_position": "",
728
+ "phase": null, "phase_is_new": false,
729
+ "milestone": "", // D-007 反查结果
730
+ "auto_mode": false,
731
+ "quality_mode": "standard", // "full" | "standard" | "quick"
732
+ "planning_mode": "independent", // "unified" | "independent"
733
+ "scope_verdict": null, // "large" | "medium" | "small" | "unknown" | null
734
+ "analyze_macro_id": null, // "ANL-xxx"
735
+ "blueprint_id": null, // "BLP-xxx"
736
+ "cli_tool": "claude", "passed_gates": [],
737
+ "consec_exit2_count": 0,
738
+
739
+ "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
740
+ "analysis_dir": null, "brainstorm_dir": null, "blueprint_dir": null },
741
+ "steps": [{
742
+ "index": 0,
743
+ "skill": "", // 执行 step 有值;decision 节点为空字符串/null
744
+ "args": "",
745
+ "stage": "", // brainstorm|blueprint|init|analyze-macro|roadmap|analyze|plan|execute|...
746
+ "scope": null, // "phase"|"standalone"|"milestone"|null(plan 等需要)
747
+ "decision": null, // null = 执行 step;非 null = decision step (值为 gate 名)
748
+ "retry_count": 0, // decision step
749
+ "max_retries": 2, // decision step
750
+ "command_scope": "global|project|missing|null",
751
+ "command_path": "<absolute path> | null",
752
+ "milestone_id": null, // 仅含 {phase} 占位符的 step
753
+ "source_artifact_ref": null, // "analyze:ANL-xxx" | "blueprint:BLP-xxx" | null
754
+ "status": "pending|running|completed|skipped|failed",
755
+ "goal_ref": null,
756
+ "completion_confirmed": false,
757
+ "completion_status": null,
758
+ "completion_evidence": null,
759
+ "completed_at": null,
760
+ "deferred_reads": [],
761
+ "load": null // { loaded_at, required_files[], deferred_files[], resolve_version }
762
+ }],
763
+ "current_step": 0,
764
+
765
+ "boundary_contract": {
766
+ "in_scope": [], "out_of_scope": [], "constraints": [], "definition_of_done": ""
767
+ },
768
+ "execution_criteria": [],
769
+ "task_decomposition": [
770
+ { "id": "G1", "goal": "", "boundary": "", "done_when": "",
771
+ "evidence": "", "lifecycle": [], "status": "pending|done",
772
+ "completion_confirmed": false, "completed_at": null }
773
+ ],
774
+ "task_decomposition_all_done": false
775
+ }
776
+ ```
777
+
778
+ ### Fix-Loop Templates
779
+
780
+ 插入的执行 step 按 A_BUILD_STEPS 规则 9 解析 `command_path` + `command_scope`;`decision:*` 条目为 decision 节点。
781
+
782
+ **post-execute:**
783
+ ```
784
+ quality-debug "{gap_summary}"
785
+ maestro-plan --gaps {phase}
786
+ maestro-execute {phase}
787
+ decision:post-execute {retry+1}
788
+ ```
789
+
790
+ **post-business-test:**
791
+ ```
792
+ quality-debug --from-business-test "{gap_summary}"
793
+ maestro-plan --gaps {phase}
794
+ maestro-execute {phase}
795
+ decision:post-execute {retry: 0}
796
+ quality-auto-test {phase}
797
+ decision:post-business-test {retry+1}
798
+ ```
799
+
800
+ **post-review:**
801
+ ```
802
+ quality-debug "{gap_summary}"
803
+ maestro-plan --gaps {phase}
804
+ maestro-execute {phase}
805
+ quality-review {phase}
806
+ decision:post-review {retry+1}
807
+ ```
808
+
809
+ **post-test:**
810
+ ```
811
+ quality-debug --from-uat "{gap_summary}"
812
+ maestro-plan --gaps {phase}
813
+ maestro-execute {phase}
814
+ decision:post-execute {retry: 0}
815
+ quality-auto-test {phase}
816
+ decision:post-business-test {retry: 0}
817
+ quality-review {phase}
818
+ decision:post-review {retry: 0}
819
+ quality-auto-test {phase}
820
+ quality-test {phase}
821
+ decision:post-test {retry+1}
822
+ ```
823
+
824
+ **post-goal-audit:** (per unmet sub-goal group)
825
+ ```
826
+ # for each unmet sub-goal G{n}, scoped to target_phase:
827
+ maestro-plan --gaps {target_phase} "G{n}: {gap}" [goal_ref: G{n}]
828
+ maestro-execute {target_phase} [goal_ref: G{n}]
829
+ # after all unmet groups inserted:
830
+ decision:post-goal-audit {retry+1}
831
+ ```
832
+
833
+ ### Goal Prompt Template
834
+
835
+ decomposition 产出后,链路概览之后逐字显示:
836
+
837
+ ```
838
+ 📋 任务分解完成。可随时复制以下 /goal 设定终止条件:
839
+
840
+ /goal 直到 {session_dir}/status.json task_decomposition[*] 与 steps[*] 全部 completion_confirmed=true 才停。每轮以 status.json 为唯一行动手册,通过 /maestro-ralph-beta 推进 tick;decision 节点由 ralph 内联评估。禁止手动执行 skill 或修改 boundary_contract.out_of_scope。
841
+ ```
842
+
843
+ ### Error Codes
844
+
845
+ | Code | Severity | Description | Recovery |
846
+ |------|----------|-------------|----------|
847
+ | E001 | error | No intent and no running session | Prompt for intent |
848
+ | E002 | error | Cannot infer lifecycle position | Show raw state, ask |
849
+ | E003 | error | Artifact dir not found for decision | Show glob, ask |
850
+ | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
851
+ | E005 | error | Delegate execution failed | Fallback: "fix" |
852
+ | E006 | error | command_scope == "missing" for one or more steps | List missing skills, abort build |
853
+ | E007 | error | required_reading 引用文件缺失 | `ralph next` 拒绝;CLI stderr 列出缺失路径 |
854
+ | E008 | error | `ralph complete` idx ≠ active_step_index | 编辑 status.json 修正一致性 |
855
+ | E009 | error | `ralph complete` step.status ≠ running | 重复 complete 或非法跳跃;编辑 status.json |
856
+ | E010 | error | status.json schema 损坏 OR A_EXEC_STEP exit=2 熔断(连续 ≥2 次空转) | `ralph check` 显示损坏字段;熔断需人工核对 next_pending_step 与 router 路由是否一致 |
857
+ | W001 | warning | Decision expanded chain | Auto-handled |
858
+ | W002 | warning | Max retries, escalating | Auto-handled |
859
+ | W003 | warning | Multiple running sessions | Use latest, warn |
860
+ | W004 | warning | Low delegate confidence | Show warning |
861
+ | W005 | warning | active_step_index 指向已 completed step | `ralph next` 自动清理后继续 |
862
+ | W007 | warning | step.skill command .md frontmatter.name | 提示但不阻塞 |
863
+
864
+ ### Success Criteria
865
+
866
+ - [ ] Tick 末尾自调用 `Skill("maestro-ralph-beta")`,直到全部 `completion_confirmed` paused
867
+ - [ ] 同一 session 同时仅一个 step `active_step_index`;切换前必经 release
868
+ - [ ] Decision step 全程不调 `maestro ralph next` / `complete`,由 maestro-ralph-beta 内联评估并 release
869
+ - [ ] `task_decomposition` 存在时,chain `decision:post-goal-audit`,且最终 `task_decomposition_all_done == true` 才允许 S_COMPLETE
870
+ - [ ] Chain `milestone-complete` 结尾;A_APPLY_* 修改 steps[] 后均 reindex
871
+ - [ ] 连续 2 `ralph next` exit=2 E010 pause(防 router 错路由空转)
872
+
873
+ </appendix>