maestro-flow 0.4.11 → 0.4.12

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 (166) hide show
  1. package/.agents/agents/cli-explore-agent.md +1 -3
  2. package/.agents/agents/cross-role-reviewer.md +173 -0
  3. package/.agents/agents/role-design-author.md +218 -0
  4. package/.agents/agents/ui-design-agent.md +1 -18
  5. package/.agents/agents/workflow-analyzer.md +1 -1
  6. package/.agents/agents/workflow-external-researcher.md +1 -1
  7. package/.agents/skills/maestro/SKILL.md +61 -27
  8. package/.agents/skills/maestro-analyze/SKILL.md +30 -4
  9. package/.agents/skills/maestro-blueprint/SKILL.md +132 -0
  10. package/.agents/skills/maestro-brainstorm/SKILL.md +119 -103
  11. package/.agents/skills/maestro-help/SKILL.md +48 -14
  12. package/.agents/skills/maestro-help/index/catalog.json +29 -11
  13. package/.agents/skills/maestro-help/phases/01-parse-intent.md +1 -1
  14. package/.agents/skills/maestro-help/phases/02-search-present.md +6 -4
  15. package/.agents/skills/maestro-help/phases/03-workflow-guide.md +60 -33
  16. package/.agents/skills/maestro-init/SKILL.md +3 -3
  17. package/.agents/skills/maestro-milestone-audit/SKILL.md +5 -3
  18. package/.agents/skills/maestro-milestone-complete/SKILL.md +7 -5
  19. package/.agents/skills/maestro-plan/SKILL.md +14 -4
  20. package/.agents/skills/maestro-ralph/SKILL.md +297 -226
  21. package/.agents/skills/maestro-ralph-execute/SKILL.md +81 -67
  22. package/.agents/skills/maestro-roadmap/SKILL.md +42 -81
  23. package/.agents/skills/quality-auto-test/SKILL.md +1 -1
  24. package/.agents/skills/team-lifecycle-v4/roles/analyst/role.md +1 -1
  25. package/.agents/skills/team-lifecycle-v4/roles/reviewer/commands/review-spec.md +2 -2
  26. package/.agents/skills/team-lifecycle-v4/roles/writer/role.md +1 -1
  27. package/.agents/skills/team-lifecycle-v4/templates/architecture.md +3 -3
  28. package/.agents/skills/team-lifecycle-v4/templates/epics.md +2 -2
  29. package/.agents/skills/team-lifecycle-v4/templates/product-brief.md +3 -3
  30. package/.agents/skills/team-lifecycle-v4/templates/requirements.md +2 -2
  31. package/.agy/agents/cli-explore-agent.md +1 -3
  32. package/.agy/agents/cross-role-reviewer.md +170 -0
  33. package/.agy/agents/role-design-author.md +215 -0
  34. package/.agy/agents/ui-design-agent.md +1 -18
  35. package/.agy/agents/workflow-analyzer.md +1 -1
  36. package/.agy/agents/workflow-external-researcher.md +1 -1
  37. package/.agy/skills/maestro/SKILL.md +61 -27
  38. package/.agy/skills/maestro-analyze/SKILL.md +30 -4
  39. package/.agy/skills/maestro-blueprint/SKILL.md +132 -0
  40. package/.agy/skills/maestro-brainstorm/SKILL.md +119 -103
  41. package/.agy/skills/maestro-help/SKILL.md +48 -14
  42. package/.agy/skills/maestro-help/index/catalog.json +29 -11
  43. package/.agy/skills/maestro-help/phases/01-parse-intent.md +1 -1
  44. package/.agy/skills/maestro-help/phases/02-search-present.md +6 -4
  45. package/.agy/skills/maestro-help/phases/03-workflow-guide.md +60 -33
  46. package/.agy/skills/maestro-init/SKILL.md +3 -3
  47. package/.agy/skills/maestro-milestone-audit/SKILL.md +5 -3
  48. package/.agy/skills/maestro-milestone-complete/SKILL.md +7 -5
  49. package/.agy/skills/maestro-plan/SKILL.md +14 -4
  50. package/.agy/skills/maestro-ralph/SKILL.md +297 -226
  51. package/.agy/skills/maestro-ralph-execute/SKILL.md +81 -67
  52. package/.agy/skills/maestro-roadmap/SKILL.md +42 -81
  53. package/.agy/skills/quality-auto-test/SKILL.md +1 -1
  54. package/.agy/skills/team-lifecycle-v4/roles/analyst/role.md +1 -1
  55. package/.agy/skills/team-lifecycle-v4/roles/reviewer/commands/review-spec.md +2 -2
  56. package/.agy/skills/team-lifecycle-v4/roles/writer/role.md +1 -1
  57. package/.agy/skills/team-lifecycle-v4/templates/architecture.md +3 -3
  58. package/.agy/skills/team-lifecycle-v4/templates/epics.md +2 -2
  59. package/.agy/skills/team-lifecycle-v4/templates/product-brief.md +3 -3
  60. package/.agy/skills/team-lifecycle-v4/templates/requirements.md +2 -2
  61. package/.claude/agents/cli-explore-agent.md +1 -3
  62. package/.claude/agents/cross-role-reviewer.md +171 -0
  63. package/.claude/agents/role-design-author.md +216 -0
  64. package/.claude/agents/ui-design-agent.md +1 -18
  65. package/.claude/agents/workflow-analyzer.md +1 -1
  66. package/.claude/agents/workflow-external-researcher.md +1 -1
  67. package/.claude/commands/maestro-analyze.md +30 -4
  68. package/.claude/commands/maestro-blueprint.md +130 -0
  69. package/.claude/commands/maestro-brainstorm.md +132 -116
  70. package/.claude/commands/maestro-init.md +3 -3
  71. package/.claude/commands/maestro-milestone-audit.md +5 -3
  72. package/.claude/commands/maestro-milestone-complete.md +7 -5
  73. package/.claude/commands/maestro-plan.md +14 -4
  74. package/.claude/commands/maestro-ralph-execute.md +81 -67
  75. package/.claude/commands/maestro-ralph.md +297 -226
  76. package/.claude/commands/maestro-roadmap.md +42 -81
  77. package/.claude/commands/maestro.md +61 -27
  78. package/.claude/commands/quality-auto-test.md +1 -1
  79. package/.claude/skills/maestro-help/SKILL.md +48 -14
  80. package/.claude/skills/maestro-help/index/catalog.json +29 -11
  81. package/.claude/skills/maestro-help/phases/01-parse-intent.md +1 -1
  82. package/.claude/skills/maestro-help/phases/02-search-present.md +6 -4
  83. package/.claude/skills/maestro-help/phases/03-workflow-guide.md +60 -33
  84. package/.claude/skills/team-lifecycle-v4/roles/analyst/role.md +1 -1
  85. package/.claude/skills/team-lifecycle-v4/roles/reviewer/commands/review-spec.md +2 -2
  86. package/.claude/skills/team-lifecycle-v4/roles/writer/role.md +1 -1
  87. package/.claude/skills/team-lifecycle-v4/templates/architecture.md +3 -3
  88. package/.claude/skills/team-lifecycle-v4/templates/epics.md +2 -2
  89. package/.claude/skills/team-lifecycle-v4/templates/product-brief.md +3 -3
  90. package/.claude/skills/team-lifecycle-v4/templates/requirements.md +2 -2
  91. package/.codex/skills/maestro/SKILL.md +75 -38
  92. package/.codex/skills/maestro-amend/SKILL.md +157 -0
  93. package/.codex/skills/maestro-analyze/SKILL.md +71 -23
  94. package/.codex/skills/maestro-blueprint/SKILL.md +122 -0
  95. package/.codex/skills/maestro-brainstorm/SKILL.md +135 -45
  96. package/.codex/skills/maestro-composer/SKILL.md +1 -1
  97. package/.codex/skills/maestro-execute/SKILL.md +13 -4
  98. package/.codex/skills/maestro-help/SKILL.md +28 -18
  99. package/.codex/skills/maestro-help/catalog.json +29 -11
  100. package/.codex/skills/maestro-init/SKILL.md +7 -7
  101. package/.codex/skills/maestro-plan/SKILL.md +27 -9
  102. package/.codex/skills/maestro-ralph/SKILL.md +740 -601
  103. package/.codex/skills/maestro-roadmap/SKILL.md +55 -72
  104. package/.codex/skills/maestro-update/SKILL.md +169 -0
  105. package/.codex/skills/maestro-verify/SKILL.md +11 -2
  106. package/.codex/skills/manage-codebase-rebuild/SKILL.md +2 -2
  107. package/.codex/skills/manage-harvest/SKILL.md +10 -2
  108. package/.codex/skills/quality-retrospective/SKILL.md +9 -2
  109. package/.codex/skills/team-lifecycle-v4/roles/analyst/role.md +2 -2
  110. package/.codex/skills/team-lifecycle-v4/roles/reviewer/commands/review-spec.md +2 -2
  111. package/.codex/skills/team-lifecycle-v4/roles/writer/role.md +1 -1
  112. package/.codex/skills/team-lifecycle-v4/templates/architecture.md +3 -3
  113. package/.codex/skills/team-lifecycle-v4/templates/epics.md +2 -2
  114. package/.codex/skills/team-lifecycle-v4/templates/product-brief.md +3 -3
  115. package/.codex/skills/team-lifecycle-v4/templates/requirements.md +2 -2
  116. package/README.md +8 -8
  117. package/README.zh-CN.md +8 -8
  118. package/dashboard/dist-server/dashboard/src/server/routes/settings.js +3 -3
  119. package/dashboard/dist-server/dashboard/src/server/routes/settings.js.map +1 -1
  120. package/dist/src/agents/cli-agent-runner.d.ts.map +1 -1
  121. package/dist/src/agents/cli-agent-runner.js +13 -7
  122. package/dist/src/agents/cli-agent-runner.js.map +1 -1
  123. package/dist/src/commands/spec.d.ts.map +1 -1
  124. package/dist/src/commands/spec.js +8 -1
  125. package/dist/src/commands/spec.js.map +1 -1
  126. package/dist/src/tools/spec-init.d.ts +16 -2
  127. package/dist/src/tools/spec-init.d.ts.map +1 -1
  128. package/dist/src/tools/spec-init.js +58 -187
  129. package/dist/src/tools/spec-init.js.map +1 -1
  130. package/dist/src/tools/spec-loader.d.ts.map +1 -1
  131. package/dist/src/tools/spec-loader.js +16 -16
  132. package/dist/src/tools/spec-loader.js.map +1 -1
  133. package/dist/src/tools/spec-seeds.d.ts +33 -0
  134. package/dist/src/tools/spec-seeds.d.ts.map +1 -0
  135. package/dist/src/tools/spec-seeds.js +200 -0
  136. package/dist/src/tools/spec-seeds.js.map +1 -0
  137. package/dist/src/tools/spec-writer.d.ts.map +1 -1
  138. package/dist/src/tools/spec-writer.js +7 -9
  139. package/dist/src/tools/spec-writer.js.map +1 -1
  140. package/dist/src/utils/update-notices.js +12 -0
  141. package/dist/src/utils/update-notices.js.map +1 -1
  142. package/package.json +1 -1
  143. package/templates/business-test-report.json +1 -1
  144. package/templates/index.json +1 -1
  145. package/templates/roadmap.md +15 -9
  146. package/templates/state.json +18 -17
  147. package/workflows/analyze.md +79 -11
  148. package/workflows/auto-test.md +6 -6
  149. package/workflows/blueprint.md +431 -0
  150. package/workflows/brainstorm.md +603 -496
  151. package/workflows/business-test.md +7 -7
  152. package/workflows/codebase-rebuild.md +4 -4
  153. package/workflows/harvest.md +184 -10
  154. package/workflows/init.md +9 -8
  155. package/workflows/maestro.md +1 -1
  156. package/workflows/milestone-audit.md +12 -4
  157. package/workflows/milestone-complete.md +11 -6
  158. package/workflows/plan.md +88 -22
  159. package/workflows/roadmap-common.md +1 -1
  160. package/workflows/roadmap.md +13 -3
  161. package/workflows/spec-generate.md +24 -13
  162. package/workflows/ui-design.md +2 -2
  163. package/workflows/ui-style.md +1 -1
  164. package/.agents/agents/conceptual-planning-agent.md +0 -247
  165. package/.agy/agents/conceptual-planning-agent.md +0 -244
  166. package/.claude/agents/conceptual-planning-agent.md +0 -245
@@ -23,12 +23,12 @@ Entry points:
23
23
  - **`/maestro-ralph continue`** — Resume via maestro-ralph-execute
24
24
  - **`/maestro-ralph status`** — Display session progress
25
25
 
26
- Initial decomposition (S_DECOMPOSE): broad intents (重构/全面/迁移/重写) are boundary-clarified via ≤3 questions, producing 执行准则 + 子目标清单 written into status.json, plus a `goal-checklist.md` (a rendered view of status.json) and a copy-paste `/goal` prompt for the user to bind.
26
+ Initial decomposition (S_DECOMPOSE): boundary-clarified via ≤3 questions for broad intents (重构/全面/迁移/重写). 写入 status.json `boundary_contract` / `execution_criteria` / `task_decomposition`,附 `/goal` prompt
27
27
 
28
- Three node types:
29
- - **internal**: `invoke_skill()` call (synchronous, lightweight)
30
- - **external**: `maestro delegate --to claude` (context-isolated, heavy computation)
31
- - **decision**: Hand back to ralph for re-evaluation (adaptive branching)
28
+ Node types:
29
+ - **internal** (default): ralph-execute `read_file({command_path})` 命令 .md,按内容内联执行
30
+ - **decision**: ralph 评估
31
+ - **external**: 仅在显式声明时使用(`maestro delegate --to claude`)
32
32
 
33
33
  Key difference from maestro coordinator:
34
34
  - maestro: static chain → one-time selection → runs all steps
@@ -37,23 +37,19 @@ Key difference from maestro coordinator:
37
37
  Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
38
38
  Mutual invocation with `/maestro-ralph-execute` forms a self-perpetuating work loop.
39
39
 
40
- ### 执行方式 / Execution Flow
40
+ ### Execution Flow
41
41
 
42
42
  ```
43
43
  /maestro-ralph "intent" ─▶ ralph infer → decompose → build chain
44
- writes status.json (truth)
45
- renders goal-checklist.md (view)
44
+ resolves command_path per step
45
+ writes status.json
46
46
  │ emits /goal prompt
47
47
 
48
- ralph-execute ◀─┐ runs next step:
49
- │ │ internal → invoke_skill()
50
- │ │ external delegate (STOP→callback)
51
- │ │ decision invoke_skill("maestro-ralph")
52
- └─────────┘ updates status.json + re-renders checklist
53
- loop until done | paused
48
+ ralph-execute ◀─┐ internal read_file(command_path) inline
49
+ │ │ decision → invoke_skill("maestro-ralph")
50
+ └─────────┘ writes step.completion_confirmed
51
+ loop until all completion_confirmed | paused
54
52
  ```
55
-
56
- `status.json` 是唯一真源;checklist 是渲染视图。决策节点是链路生长点(`post-goal-audit` 插入按子目标的 mini-loop;`post-verify/review/test` 插入修复 loop)。评估只走 ralph,执行只走 ralph-execute,两者不互相替代。
57
53
  </purpose>
58
54
 
59
55
  <context>
@@ -76,10 +72,13 @@ Remaining → intent
76
72
  1. **Ralph never executes steps** — only creates sessions and evaluates decisions
77
73
  2. **Handoff via invoke_skill("maestro-ralph-execute")** — at session creation and after decision evaluation
78
74
  3. **Decision delegates read-only** — `maestro delegate --role analyze --mode analysis`
79
- 4. **External CLI call** — external spawns full Claude Code session executing the skill command
80
- 5. **Delegate sessions non-interactive** all external skills MUST append `-y` to args inside the prompt
81
- 6. **Decomposition is outcome-oriented**sub-goals are deliverables/done-criteria, NEVER lifecycle-stage duplicates (analyze/plan/...). `/goal` binding is user-driven; ralph only emits the prompt
82
- 7. **task_decomposition drives DYNAMIC step growth, not a frozen plan** sub-goals are the convergence spec; `status.json.steps[]` remains the living chain. The `post-goal-audit` decision node re-checks the checklist and **dynamically inserts scoped execution steps** for every unmet sub-goal (same insert+reindex+retry mechanism as fix-loops). Decomposition never replaces ralph's adaptive branching — it feeds it. New fields are also additive/optional (absent → decomposition off, old behavior); never remove/rename existing fields
75
+ 4. **Default type = internal** — `external` 仅显式标注时出现,build 不默认生成
76
+ 5. **status.json 是唯一真源**不生成 markdown 清单或侧文件
77
+ 6. **每个 step 必须 `completion_confirmed: true`** 基于 `--- COMPLETION STATUS ---` `STATUS: DONE`;缺失则视为未完成
78
+ 7. **command_path A_BUILD_STEPS 解析**全局优先 `~/.claude/commands/{name}.md`,fallback 项目 `.claude/commands/{name}.md`,写入 status.json
79
+ 8. **Decomposition is outcome-oriented** — sub-goals 为可观测交付,禁止 lifecycle 复刻;`/goal` 用户绑定,ralph 只发提示词
80
+ 9. **planning_mode governs arg granularity** — `unified` → skill args 无 `{phase}`;`independent` → 含 `{phase}`
81
+ 10. **task_decomposition 驱动 steps[] 动态生长** — `post-goal-audit` 按 unmet 子目标插入 scoped mini-loop;字段可选/累加,既有字段不删不改
83
82
  </invariants>
84
83
 
85
84
  <state_machine>
@@ -88,9 +87,11 @@ Remaining → intent
88
87
  S_PARSE_ROUTE — 解析参数、路由入口 PERSIST: —
89
88
  S_STATUS — 显示 session 进度 PERSIST: —
90
89
  S_CONTINUE — 恢复执行 PERSIST: —
91
- S_RESOLVE_PHASE — 解析目标 phase + 标记 phase_is_new PERSIST: session.phase, session.phase_is_new
90
+ S_RESOLVE_PHASE — 解析 phase + phase_is_new + D-007 milestone PERSIST: session.phase, session.phase_is_new, session.milestone
92
91
  S_INFER — 基于已解析 phase 推断 lifecycle_position PERSIST: session.lifecycle_position
92
+ S_RESOLVE_SCOPE — 读 macro analyze conclusions.scope_verdict PERSIST: session.scope_verdict, session.analyze_macro_id
93
93
  S_QUALITY_MODE — 决定质量管线模式 PERSIST: session.quality_mode
94
+ S_PLANNING_MODE — 决定统一/独立规划模式 PERSIST: session.planning_mode
94
95
  S_DECOMPOSE — 边界澄清、写执行准则+子目标清单 PERSIST: session.boundary_contract, .execution_criteria, .task_decomposition
95
96
  S_BUILD_CHAIN — 构建步骤链 PERSIST: session.steps[]
96
97
  S_CREATE_SESSION — 写 status.json PERSIST: session (全量)
@@ -123,17 +124,25 @@ S_RESOLVE_PHASE:
123
124
  GUARD: auto_confirm does NOT skip phase ambiguity
124
125
 
125
126
  S_INFER:
126
- S_QUALITY_MODE WHEN: position resolved DO: A_INFER_POSITION
127
+ S_RESOLVE_SCOPE WHEN: position resolved DO: A_INFER_POSITION
127
128
  → S_FALLBACK WHEN: cannot infer
128
129
 
130
+ S_RESOLVE_SCOPE:
131
+ → S_QUALITY_MODE DO: A_RESOLVE_SCOPE_VERDICT
132
+ GUARD: position ∈ {brainstorm, blueprint, init} → skip (scope_verdict = null)
133
+
129
134
  S_QUALITY_MODE:
130
- S_DECOMPOSE DO: A_DETERMINE_QUALITY_MODE
135
+ S_PLANNING_MODE DO: A_DETERMINE_QUALITY_MODE
136
+
137
+ S_PLANNING_MODE:
138
+ → S_DECOMPOSE DO: A_DETERMINE_PLANNING_MODE
139
+ GUARD: lifecycle_position ∈ {brainstorm, blueprint, init, analyze-macro, roadmap} → skip (force independent)
131
140
 
132
141
  S_DECOMPOSE:
133
142
  → S_BUILD_CHAIN DO: A_DECOMPOSE_TASKS
134
- GUARD: broad intent (重构/全面/重写/迁移/overhaul/migrate/rewrite) → MUST clarify boundary even if auto_confirm
135
- GUARD: narrow intent (single file/function/bug) → auto-derive, skip questions
136
- GUARD: position ∈ {brainstorm, init} → skip decomposition (no concrete target yet)
143
+ GUARD: broad intent → MUST clarify boundary even if auto_confirm
144
+ GUARD: narrow intent → auto-derive, skip questions
145
+ GUARD: position ∈ {brainstorm, blueprint, init} → skip decomposition
137
146
 
138
147
  S_BUILD_CHAIN:
139
148
  → S_CREATE_SESSION DO: A_BUILD_STEPS
@@ -155,6 +164,8 @@ S_DECISION_EVAL:
155
164
  DO: A_DELEGATE_EVALUATE
156
165
  → S_APPLY_VERDICT WHEN: goal-gate (post-goal-audit)
157
166
  DO: A_GOAL_AUDIT_EVALUATE
167
+ → S_APPLY_VERDICT WHEN: scope-gate (post-analyze-scope)
168
+ DO: A_SCOPE_EVALUATE
158
169
  → S_APPLY_VERDICT WHEN: structural (post-milestone, post-debug-escalate)
159
170
  DO: A_STRUCTURAL_EVALUATE
160
171
 
@@ -162,10 +173,12 @@ S_APPLY_VERDICT:
162
173
  → S_DISPATCH WHEN: verdict == "proceed" DO: A_APPLY_PROCEED
163
174
  → S_DISPATCH WHEN: post-goal-audit + unmet sub-goals DO: A_APPLY_GOAL_FIX
164
175
  → S_DISPATCH WHEN: post-goal-audit + all sub-goals met DO: A_APPLY_GOAL_DONE
176
+ → S_DISPATCH WHEN: post-analyze-scope DO: A_APPLY_SCOPE_VERDICT
165
177
  → S_DISPATCH WHEN: verdict == "fix" DO: A_APPLY_FIX
166
178
  → S_DISPATCH WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE
167
- → S_DISPATCH WHEN: post-milestone + next milestone DO: A_ADVANCE_MILESTONE
168
- → END WHEN: post-milestone + no next milestone DO: mark completed
179
+ → S_DISPATCH WHEN: post-milestone + standard + next milestone DO: A_ADVANCE_MILESTONE
180
+ → END WHEN: post-milestone + standard + no next milestone DO: mark completed
181
+ → END WHEN: post-milestone + adhoc DO: mark completed (adhoc self-contained)
169
182
  → END WHEN: post-debug-escalate (always STOP) DO: A_PAUSE_ESCALATE
170
183
  GUARD: retry_count >= max_retries → force escalate
171
184
  GUARD: confidence_score < 60 AND proceed → override to fix
@@ -185,41 +198,53 @@ S_FALLBACK:
185
198
 
186
199
  1. Find latest ralph session (by created_at)
187
200
  2. Display: Session, Status, Position, Progress, Current step
188
- 3. List steps: [✓] completed, [▸] current, [ ] pending, [◆] decision
189
- 4. If `task_decomposition` present (graceful skip if absent backward compat):
201
+ 3. List steps: [✓] completion_confirmed, [▸] current, [ ] pending, [◆] decision;附 `command_scope`(global/project) + `command_path`
202
+ 4. If `task_decomposition` present (absent skip):
190
203
  ```
191
204
  Sub-goals ({done}/{total}) source: {session_dir}/status.json#/task_decomposition
192
- [x] G1 done_when={done_when} evidence={evidence}
193
- [ ] G2 done_when={done_when} evidence={evidence} ◀ unmet
194
- ...
195
- Checklist view: {session_dir}/goal-checklist.md (regenerated from status.json)
205
+ [x] G1 done_when={done_when} evidence={evidence} confirmed={completion_confirmed}
206
+ [ ] G2 done_when={done_when} evidence={evidence} confirmed=false ◀ unmet
196
207
  ```
197
- Reads state directly from `status.json.task_decomposition[*].status` — checklist is just a view, status.json wins on conflict.
198
208
 
199
209
  ### A_RESOLVE_PHASE
200
210
 
201
- **前置于 A_INFER_POSITION**——position 推断需要先知道 target phase 是否在 state.json 中已存在。
211
+ 前置于 A_INFER_POSITION。产出 `phase` + `phase_is_new` + `milestone`(D-007 反查)三元组。
202
212
 
203
- **Priority (产出 `phase` + `phase_is_new` 二元组):**
213
+ **Priority:**
204
214
 
205
215
  | Step | 行为 | phase_is_new |
206
216
  |------|------|--------------|
207
- | 1 | intent 匹配 `phase\s*(\d+)` 正则 → 取 state.json 中对应 phase | false |
208
- | 2 | intent 派生短语(如 "docs-site-redesign", "auth-refactor")→ 在 state.json.milestones[*].phases / artifacts[*].path 中查找 | false (匹配) / true (无匹配) |
217
+ | 1 | intent 匹配 `phase\s*(\d+)` → 取 state.json 对应 phase | false |
218
+ | 2 | intent 派生短语 `state.json.milestones[*].phase_slugs` / `artifacts[*].path` 查找 | false (匹配) / true (无匹配) |
209
219
  | 3 | 未派生 → 取最新 in-progress artifact 的 phase | false |
210
220
  | 4 | 仍无 → state.json 首个 incomplete phase | false |
211
- | 5 | position 将是 brainstorm/init/roadmap → phase = null | n/a |
212
- | 6 | 仍模糊 → `ask_user`(新 phase / 已存在 phase 二选一) | 由用户回答确定 |
221
+ | 5 | position 将是 brainstorm/blueprint/init/roadmap/analyze-macro → phase = null | n/a |
222
+ | 6 | 仍模糊 → `ask_user` | 由用户回答确定 |
223
+
224
+ **D-007 Phase→Milestone 反查**(数字 phase 已解析时):
225
+ ```
226
+ resolve_milestone(phase_number):
227
+ for ms in state.json.milestones:
228
+ if str(phase_number) in ms.phase_slugs: return ms.id
229
+ return state.json.current_milestone # fallback
230
+ ```
231
+ 写入 `session.milestone`;禁止直接使用 `current_milestone` 当做 phase 所属 milestone。
213
232
 
214
- **写入 session**: `phase`(字符串或 null)+ `phase_is_new`(bool)。`phase_is_new=true` 表示当前 milestone 下需要为这个 phase 创建全套生命周期(A_INFER_POSITION 据此强制起始位置)。
233
+ **写入 session**: `phase`, `phase_is_new`, `milestone`。
215
234
 
216
235
  **新派生 phase 时 milestone 处理**:
217
- - state.json 当前 milestone 仍 active → 沿用当前 milestone,仅新增 phase
218
- - intent 同时派生了新 milestone 名(如 "M1-visual-replication")→ 写入 session 但**仅作标签**;state.json.milestones 由后续 `maestro-roadmap` / `maestro-milestone-release` 真实创建。session 层面禁止虚构 milestone 直接改 state.json
236
+ - state.json 当前 milestone 仍 active → 沿用,新增 phase
237
+ - intent 派生新 milestone 写入 session 仅作标签;`state.json.milestones` `maestro-roadmap` / `maestro-milestone-release` 创建
219
238
 
220
239
  ### A_INFER_POSITION
221
240
 
222
- **Intent-based override:** brainstorm/头脑风暴/探索/ideate/设计思路 → position = `brainstorm`
241
+ **Intent-based overrides** (按顺序匹配,先命中先用):
242
+
243
+ | Pattern | Position |
244
+ |---------|----------|
245
+ | brainstorm / 头脑风暴 / 探索 / ideate / 设计思路 | `brainstorm` |
246
+ | blueprint / 规格 / 正式文档 / spec-generate / 7-phase | `blueprint` |
247
+ | broad/medium intent 无数字 phase (重构/全面/重写/迁移/新功能 X) | `analyze-macro` |
223
248
 
224
249
  **Bootstrap detection:**
225
250
 
@@ -234,16 +259,32 @@ S_FALLBACK:
234
259
 
235
260
  | Condition | Position |
236
261
  |-----------|----------|
237
- | `phase_is_new == true` (intent 派生的新 phase, state.json 中无) | **`analyze`** (强制从头起) |
238
- | no milestones or no roadmap.md | `roadmap` |
239
- | `phase == null` (brainstorm/init/roadmap 已由 override 决定) | n/a |
262
+ | `phase_is_new == true` ( phase) | `analyze` |
263
+ | no milestones AND no roadmap.md AND has analyze macro artifact | `roadmap` |
264
+ | no milestones AND no roadmap.md AND no analyze artifact | `analyze-macro` |
265
+ | `phase == null` (brainstorm/blueprint/init/roadmap/analyze-macro override 已定) | n/a |
240
266
  | phase 已存在 + 无任何 artifact | `analyze` |
241
267
  | phase 已存在 + 最新 artifact = analyze | `plan` |
242
268
  | phase 已存在 + 最新 artifact = plan | `execute` |
243
269
  | phase 已存在 + 最新 artifact = execute | `verify` |
244
270
  | phase 已存在 + 最新 artifact = verify | → refine from result files |
245
271
 
246
- **关键不变量**:artifact 过滤必须用 `session.phase`(A_RESOLVE_PHASE 已写入),而不是 state.json.current_phase。当 `phase_is_new` 时跳过过滤直接走 `analyze`,避免错用其他 phase 的 artifact 推断。
272
+ **关键不变量**:artifact 过滤按 `session.phase`,不读 `state.json.current_phase`。`phase_is_new` 直接 `analyze`。
273
+
274
+ ### A_RESOLVE_SCOPE_VERDICT
275
+
276
+ 仅当 `lifecycle_position ∈ {analyze-macro, roadmap, plan}` 且存在最新 analyze artifact 时执行。
277
+
278
+ 1. 定位最新 macro analyze artifact(`type=="analyze"` 且 `scope=="macro"`,按 created_at DESC)→ 记 `session.analyze_macro_id = ANL-xxx`
279
+ 2. 读 `{artifact_path}/conclusions.json` 的 `scope_verdict` 字段(`large | medium | small`)
280
+ 3. 写入 `session.scope_verdict`;缺失时设 `unknown`
281
+ 4. 路由建议(A_BUILD_STEPS 据此决定是否插入 roadmap、plan 是否走 `--from`):
282
+
283
+ | scope_verdict | 链路 |
284
+ |---------------|------|
285
+ | `large` | analyze-macro → roadmap → analyze → plan → execute → ... |
286
+ | `medium` / `small` | analyze-macro → plan --from analyze:{ANL_ID} → execute → ...(跳过 roadmap + analyze-phase) |
287
+ | `unknown` | 默认走 large 路径,post-analyze-scope 决策节点再纠正 |
247
288
 
248
289
  **Refine from verify results:**
249
290
 
@@ -268,9 +309,37 @@ S_FALLBACK:
268
309
 
269
310
  写入 `session.quality_mode`。A_BUILD_STEPS 据此过滤 stage(见下)。
270
311
 
312
+ ### A_DETERMINE_PLANNING_MODE
313
+
314
+ 决定里程碑的规划粒度:一次性规划整个里程碑(统一)还是逐 phase 走完整生命周期(独立)。
315
+
316
+ **Auto-resolve rules (按优先级):**
317
+
318
+ | Condition | Mode | Reason |
319
+ |-----------|------|--------|
320
+ | lifecycle_position ∈ {brainstorm, init, roadmap} | `independent` | 前期阶段不涉及多 phase 规划 |
321
+ | `phase_is_new == true` | `independent` | 新 phase 尚无里程碑上下文 |
322
+ | intent 显式指定 phase 编号(如 "phase 2"、"P3") | `independent` | 用户明确针对单个 phase |
323
+ | milestone 仅含 1 个 phase(读 state.json) | `independent` | 统一无意义 |
324
+ | milestone 含多个 phase + `auto_confirm` | `unified` | 自动模式倾向高效 |
325
+ | milestone 含多个 phase + 非 `auto_confirm` | → ask_user | 征询用户选择 |
326
+
327
+ **ask_user** (仅当 milestone 含 ≥2 phase 且非 auto_confirm):
328
+
329
+ ```
330
+ question: "当前里程碑含 {N} 个 phase,选择规划模式?"
331
+ options:
332
+ - label: "统一规划 (Recommended)"
333
+ description: "一次性分析+规划整个里程碑所有 phase,analyze/plan 走里程碑级,适合 phase 间关联紧密"
334
+ - label: "独立规划"
335
+ description: "逐个 phase 走完整生命周期(analyze→plan→execute→verify→...),适合 phase 间独立性高"
336
+ ```
337
+
338
+ 写入 `session.planning_mode`(`"unified"` 或 `"independent"`)。`A_BUILD_STEPS` 据此决定 skill args 是否携带 `{phase}` 占位符。
339
+
271
340
  ### A_DECOMPOSE_TASKS
272
341
 
273
- Build the boundary contract + outcome sub-goal checklist that `/goal` will track. Runs once at session creation, before chain build. All output is **additive** to status.json.
342
+ Runs once before chain build; additive to status.json.
274
343
 
275
344
  **1. Classify intent breadth:**
276
345
 
@@ -290,7 +359,7 @@ Build the boundary contract + outcome sub-goal checklist that `/goal` will track
290
359
 
291
360
  narrow → derive defaults from intent + codebase, skip questions.
292
361
 
293
- **3. Derive `execution_criteria`** (执行准则 — 3-6 short imperative rules every step obeys): backward-compat stance, scope-freeze ("只改请求范围"), test/coverage bar, fix-don't-hide, incremental commit. Each verify/review/test gate later checks against these.
362
+ **3. Derive `execution_criteria`**: backward-compatscope-freezetest/coverage barfix-don't-hideincremental commit
294
363
 
295
364
  **4. Derive `task_decomposition`** (子目标清单 — outcome-oriented, NOT lifecycle stages). Each entry:
296
365
  ```json
@@ -299,60 +368,70 @@ narrow → derive defaults from intent + codebase, skip questions.
299
368
  "evidence": "verification.json|review.json|uat.md|<test path>",
300
369
  "lifecycle": ["analyze","execute","verify"], "status": "pending" }
301
370
  ```
302
- **Cleverness rule**: `done_when` MUST be objectively verifiable and SHOULD reference an artifact ralph already produces, so the `/goal` Stop hook can re-verify after context compaction. Map each sub-goal to the lifecycle phase(s) that will produce its evidence this is how the checklist "adapts to ralph": the existing pipeline becomes the machinery that satisfies the goals.
371
+ `done_when` 必须客观可验证,且引用 ralph 已产出的 artifact;`lifecycle` 字段映射到产出 evidence 的生命周期 stage。
303
372
 
304
- **5. Persist** (additive) into session for A_CREATE_SESSION to write: `boundary_contract`, `execution_criteria`, `task_decomposition`. Absent feature (skipped) write none; downstream treats as "decomposition off".
373
+ **5. Persist** (additive): `boundary_contract`, `execution_criteria`, `task_decomposition`。每个 sub-goal `status: "pending"` + `completion_confirmed: false`。
305
374
 
306
- **6. Stage** the Goal Checklist + Goal Prompt (Appendix) for A_CREATE_SESSION to emit.
375
+ **6. Stage** the Goal Prompt (Appendix) for A_CREATE_SESSION to emit.
307
376
 
308
377
  ### A_BUILD_STEPS
309
378
 
310
- Generate steps from `session.lifecycle_position` to `milestone-complete`(终点硬约束)。
311
-
312
- | Stage | Skill | Type | Decision after | quality_mode |
313
- |-------|-------|------|----------------|--------------|
314
- | brainstorm | `maestro-brainstorm "{intent}"` | external | — | all |
315
- | init | `maestro-init` | internal | — | all |
316
- | roadmap | `maestro-roadmap "{intent}"` | internal | — | all |
317
- | analyze | `maestro-analyze {phase}` | external | | all |
318
- | plan | `maestro-plan {phase}` | internal | — | all |
319
- | execute | `maestro-execute {phase}` | external | — | all |
320
- | verify | `maestro-verify {phase}` | internal | `post-verify` | all |
321
- | business-test | `quality-auto-test {phase}` | internal | `post-business-test` | **full only** |
322
- | review | `quality-review {phase}` | internal | `post-review` | all (quick: append `--tier quick`) |
323
- | test-gen | `quality-auto-test {phase}` | internal | | full / standard if coverage<80% |
324
- | test | `quality-test {phase}` | internal | `post-test` | full, standard |
325
- | milestone-audit | `maestro-milestone-audit` | internal | — | all |
326
- | goal-audit | *(decision-only, no skill)* | decision | `post-goal-audit` | all (only if decomposed) |
327
- | milestone-complete | `maestro-milestone-complete` | internal | `post-milestone` | all (chain 终点) |
328
-
329
- Type rationale: `internal` = invoke_skill(), lightweight/interactive; `external` = delegate --to claude, context-isolated heavy computation
379
+ Generate steps from `session.lifecycle_position` to `milestone-complete`.
380
+
381
+ | Stage | invoke_skill(independent) | invoke_skill(unified) | Type | Decision after | quality_mode |
382
+ |-------|---------------------|-----------------|------|----------------|--------------|
383
+ | brainstorm | `maestro-brainstorm "{intent}"` | *(same)* | internal | — | all |
384
+ | blueprint | `maestro-blueprint "{intent}"` | *(same)* | internal | — | all |
385
+ | init | `maestro-init` | *(same)* | internal | — | all |
386
+ | analyze-macro | `maestro-analyze "{intent}"` | *(same)* | internal | `post-analyze-scope` | all |
387
+ | roadmap | `maestro-roadmap --from analyze:{analyze_macro_id}` | *(same)* | internal | — | all |
388
+ | analyze | `maestro-analyze {phase}` | `maestro-analyze` | internal | — | all |
389
+ | 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` | internal | — | all |
390
+ | execute | `maestro-execute {phase}` | `maestro-execute` | internal | | all |
391
+ | verify | `maestro-verify {phase}` | `maestro-verify` | internal | `post-verify` | all |
392
+ | business-test | `quality-auto-test {phase}` | `quality-auto-test` | internal | `post-business-test` | full only |
393
+ | review | `quality-review {phase}` | `quality-review` | internal | `post-review` | all (quick: append `--tier quick`) |
394
+ | test-gen | `quality-auto-test {phase}` | `quality-auto-test` | internal | — | full / standard if coverage<80% |
395
+ | test | `quality-test {phase}` | `quality-test` | internal | `post-test` | full, standard |
396
+ | milestone-audit | `maestro-milestone-audit` | *(same)* | internal | | all |
397
+ | goal-audit | *(decision-only)* | *(same)* | decision | `post-goal-audit` | all (only if decomposed) |
398
+ | milestone-complete | `maestro-milestone-complete` | *(same)* | internal | `post-milestone` | all |
330
399
 
331
400
  **Build rules (按顺序应用):**
332
401
 
333
- 1. **起点**:从 `session.lifecycle_position` 开始;不读 `state.json.current_phase`
334
- 2. **跳过已完成**:跳过当前 milestone+phase 下已有 completed artifact 的 stage(artifact 过滤同样按 `session.phase`,不按 state.json 当前 phase)
335
- 3. **quality_mode 过滤**:按 `session.quality_mode` 排除上表 `quality_mode` 列不包含该模式的 stage(如 standard 不跑 business-test、quick 不跑 test-gen/test)
402
+ 0. **planning_mode 选列**:`unified` → invoke_skill(unified) 列;`independent` invoke_skill(independent) 列
403
+ 1. **起点**:从 `session.lifecycle_position` 开始
404
+ 2. **跳过已完成**:跳过当前 milestone+phase 下已有 completed artifact stage(按 `session.phase` 过滤);unified milestone 过滤
405
+ 3. **quality_mode 过滤**:按 `session.quality_mode` 排除不匹配 stage
336
406
  4. **决策节点**:每个 Decision after 非空的 stage 之后插入 `{ type: "decision", decision: "<gate>", retry_count: 0, max_retries: 2 }`
337
- 5. **goal-audit 插入**:当且仅当 `task_decomposition` 存在 → 在最后一个 evidence-producing stage(verify/review/test)之后、`milestone-complete` 之前插入 `decision:post-goal-audit`
338
- 6. **终点硬约束**:chain 必须以 `milestone-complete` 步骤结尾(除非 `lifecycle_position` 已是 `milestone-complete` 之后的状态)。生成器在收尾时不论 quality_mode 都必须 append 该 step
339
- 7. **初始 goal_ref 传播**:若 `task_decomposition` 存在,遍历每个新建 step
340
- - 计算 `step.stage`(如 execute/verify/review)
341
- - 对每个 `g ∈ task_decomposition`:若 `step.stage g.lifecycle` `step.goal_ref = g.id`
342
- - 多 G 匹配 → id 字典序最小者;保证 verify/review 等共用 lifecycle 的 step 也有可追溯标签
343
- - decision 节点不打 goal_ref(goal-audit 自身除外,它的 verdict 直接修改 task_decomposition)
344
- 8. **占位符**:args 用 `{phase}` `{intent}` 等,由 ralph-execute 在执行时解析
345
- 9. **动态插入**:`post-goal-audit` 触发 A_APPLY_GOAL_FIX 时插入的步骤同样按规则 7 `goal_ref`(追溯到触发它的子目标 G{n})
407
+ 5. **goal-audit 插入**:`task_decomposition` 存在时,在最后一个 evidence-producing stage(verify/review/test)之后、`milestone-complete` 之前插入 `decision:post-goal-audit`
408
+ 6. **终点硬约束**:chain `milestone-complete` 结尾
409
+ 7. **goal_ref 传播**:`task_decomposition` 存在时,每个 step 按 `step.stage ∈ g.lifecycle` 匹配 `step.goal_ref = g.id`(多匹配取字典序最小);decision 节点不打 goal_ref
410
+ 8. **占位符**:independent 保留 `{phase}` `{intent}`;unified 不带 `{phase}`
411
+ 9. **command_path 解析**(每个非 decision step):
412
+ - 取 skill 名(args 前的第一个 token)
413
+ - 全局优先:`~/.claude/commands/{name}.md` 存在 `command_scope = "global"`
414
+ - Fallback:`.claude/commands/{name}.md` 存在 → `command_scope = "project"`
415
+ - 两者都缺 `command_scope = "missing"`, `command_path = null`,A_CREATE_SESSION 报错 E006
416
+ 10. **每个 step 初始化** `completion_confirmed: false`, `completion_status: null`, `completion_evidence: null`
417
+ 11. **scope_verdict gating**(仅当 chain 起点 = `analyze-macro`):
418
+ - `scope_verdict ∈ {medium, small}` → 跳过 `roadmap` + `analyze` 两 stage;`plan` 选 standalone 列(`--from analyze:{analyze_macro_id}`),不带 `{phase}`
419
+ - `scope_verdict == large` → 保留 `roadmap` + `analyze`;`plan` 选 phase 列(`{phase}`)
420
+ - `scope_verdict == unknown` → 默认 large 路径;由 `post-analyze-scope` 决策节点在 macro analyze 完成后纠正(A_APPLY_SCOPE_VERDICT)
421
+ 12. **--from 自动注入**:
422
+ - `analyze_macro_id` 存在且当前 step 是 `roadmap` → args 改为 `--from analyze:{analyze_macro_id}`
423
+ - `analyze_macro_id` 存在且 `scope_verdict ∈ {medium, small}` 且当前 step 是 `plan` → args 改为 `--from analyze:{analyze_macro_id}`
424
+ - `blueprint_id` 存在 → 当前 step 是 `plan` → args 改为 `--from blueprint:{blueprint_id}`(优先级低于 phase 数字参数)
425
+ - 写入 `step.source_artifact_ref` 以便审计
426
+ 13. **D-007 Milestone-ref 标注**:每个含 `{phase}` 占位符的 step → `step.milestone_id = session.milestone`(由 A_RESOLVE_PHASE 反查得出),禁止读 `current_milestone`
427
+ 14. **动态插入步骤**(A_APPLY_*)同样应用规则 7-13
346
428
 
347
429
  ### A_CREATE_SESSION
348
430
 
349
- 1. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json` (Appendix: Session Schema) decomposition fields included only if produced (additive)
350
- 2. If `task_decomposition` present:
351
- - Set `session.goal_checklist_path = "{session_dir}/goal-checklist.md"` in status.json
352
- - **Render** checklist from status.json (Appendix: Goal Checklist Template + Sync Rule). This is a one-way projection — status.json drives content; the file is never hand-edited
353
- - Stable filename within session (so `/goal` condition string survives context compaction)
354
- 3. Display chain overview with step list
355
- 4. If `task_decomposition` present: display the **Goal Prompt block** (Appendix: Goal Prompt Template) — the copy-paste `/goal …` line binds status.json + checklist as a Stop-hook target
431
+ 1. Validate: 所有 step `command_scope != "missing"`;否则 raise E006 + 列出缺失 skill
432
+ 2. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json` (Appendix: Session Schema)
433
+ 3. Display chain overview:每步显示 `{index}. {skill} [{type}] [{command_scope}]`
434
+ 4. If `task_decomposition` present: display the **Goal Prompt block** (Appendix: Goal Prompt Template)
356
435
 
357
436
  ### A_DELEGATE_EVALUATE
358
437
 
@@ -386,45 +465,64 @@ Type rationale: `internal` = invoke_skill(), lightweight/interactive; `external`
386
465
 
387
466
  ### A_STRUCTURAL_EVALUATE
388
467
 
389
- **post-milestone:** Read state.json → next milestone? → insert lifecycle steps / complete
468
+ **post-milestone:**
469
+ 1. Read state.json → resolve completed milestone object
470
+ 2. Determine milestone type: `milestone_obj.type` (default `"standard"` if missing)
471
+ 3. **Standard milestone** (`type != "adhoc"`): next milestone exists? → insert lifecycle steps / complete
472
+ 4. **Adhoc milestone** (`type == "adhoc"`): always END — adhoc milestones are self-contained, no successor to advance to. Set `current_milestone = null`.
473
+
390
474
  **post-debug-escalate:** Always STOP → set paused, display "请人工介入"
391
475
 
476
+ ### A_SCOPE_EVALUATE
477
+
478
+ 仅由 `post-analyze-scope` 决策节点触发;macro analyze 完成后读 `conclusions.json.scope_verdict` 决定下游链路。
479
+
480
+ 1. 定位刚完成的 macro analyze artifact → `analyze_macro_id`, `conclusions_path = {artifact_path}/conclusions.json`
481
+ 2. 读取 `conclusions.scope_verdict`(`large | medium | small`),缺失 → `unknown`
482
+ 3. 写入 `session.scope_verdict` + `session.analyze_macro_id`
483
+ 4. Append `{session_dir}/decisions.ndjson`:
484
+ ```json
485
+ { "id": "DEC-{timestamp}", "type": "scope-gate",
486
+ "source": "ralph", "node_id": "post-analyze-scope",
487
+ "verdict": "{scope_verdict}", "analyze_macro_id": "{ANL_ID}" }
488
+ ```
489
+ 5. → A_APPLY_SCOPE_VERDICT
490
+
392
491
  ### A_GOAL_AUDIT_EVALUATE
393
492
 
394
- Re-checks sub-goals against `status.json` (source of truth) and decides whether `steps[]` must dynamically grow. Only runs when `task_decomposition` present.
493
+ Runs only when `task_decomposition` present.
395
494
 
396
- 1. Read `session.task_decomposition` from status.json (NOT from checklist — checklist is just a view)
397
- 2. For each sub-goal `status != "done"`: resolve its `evidence` artifact (verification.json / review.json / uat.md / test path) under the current phase scratch dir
495
+ 1. Read `session.task_decomposition` from status.json
496
+ 2. For each sub-goal `status != "done"`: resolve `evidence` artifact under current phase scratch dir
398
497
  3. Delegate read-only audit (run_in_background, STOP, wait):
399
498
  ```
400
- maestro delegate "PURPOSE: 审计未完成子目标,判定哪些已达成、哪些仍需补步骤
499
+ maestro delegate "PURPOSE: 审计未完成子目标,判定 met / unmet
401
500
  TASK:
402
- 1. 读取 status.json.task_decomposition 中每个 status!=done 的子目标
403
- 2. 打开其 evidence 产物,对照 done_when 严格判定
404
- 3. 输出 met / unmet 分类,unmet 给出差距 + 应回补的 target_phase
501
+ 1. 读取 status.json.task_decomposition status!=done 的子目标
502
+ 2. 打开 evidence 产物,对照 done_when 严格判定
503
+ 3. 输出 met / unmetunmet 给出 gap + target_phase
405
504
  CONTEXT:
406
505
  status.json = {session_dir}/status.json
407
- checklist = {goal_checklist_path} (人类可读视图,仅供参考)
408
506
  evidence = {evidence artifacts}
409
- 执行准则 = {execution_criteria}
410
- 边界契约 = {boundary_contract}
411
- EXPECTED (单行 verdict 块,严格遵循):
507
+ execution_criteria = {execution_criteria}
508
+ boundary_contract = {boundary_contract}
509
+ EXPECTED:
412
510
  ---VERDICT---
413
511
  STATUS=all_met|has_unmet
414
- UNMET=[{id:G2,gap:'...',target_phase:execute}, ...] # 空数组当 STATUS=all_met
512
+ UNMET=[{id:G2,gap:'...',target_phase:execute}, ...]
415
513
  CONFIDENCE_SCORE=0-100
416
514
  ---END---
417
515
  CONSTRAINTS:
418
- - 只评估,不修改任何文件
419
- - 严格按 done_when 判定;evidence 缺失 → 视为 unmet
516
+ - 只评估,不修改文件
517
+ - 严格按 done_when 判定;evidence 缺失 → unmet
420
518
  - 不得建议超出 boundary_contract 的修改
421
519
  "
422
520
  --role analyze --mode analysis
423
521
  ```
424
- 4. On callback: parse UNMET list. **status.json is the write target** — for each met sub-goal: `task_decomposition[i].status="done"` + `task_decomposition[i].completed_at=now`. Then regenerate checklist view from status.json (see Sync Rule in Appendix).
425
- 5. **Decision log**: append to `{session_dir}/decisions.ndjson` with `"type": "goal-gate"`, `unmet_count`, `unmet_ids`
522
+ 4. On callback: 对每个 met 子目标,set `task_decomposition[i].status="done"` + `completion_confirmed=true` + `completed_at=now`
523
+ 5. Append `{session_dir}/decisions.ndjson` with `"type": "goal-gate"`, `unmet_count`, `unmet_ids`
426
524
  6. Verdict: `all_met` → A_APPLY_GOAL_DONE; `has_unmet` → A_APPLY_GOAL_FIX
427
- GUARD: retry_count >= max_retries AND still unmet → A_APPLY_ESCALATE (insert quality-debug, hand to human)
525
+ GUARD: retry_count >= max_retries AND still unmet → A_APPLY_ESCALATE
428
526
 
429
527
  ### A_APPLY_PROCEED
430
528
 
@@ -442,22 +540,33 @@ Re-checks sub-goals against `status.json` (source of truth) and decides whether
442
540
  1. Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`
443
541
  2. Increment retry_count, reindex, write status.json
444
542
 
445
- ### A_APPLY_GOAL_FIX
543
+ ### A_APPLY_SCOPE_VERDICT
446
544
 
447
- **This is the dynamic step-growth core.** For every unmet sub-goal, inject scoped execution steps so `steps[]` grows toward convergence:
545
+ `post-analyze-scope` 触发,依据 `session.scope_verdict` 重塑下游链路。
448
546
 
449
- 1. For each `unmet` sub-goal `G{n}` (grouped by `target_phase` to avoid duplicate runs):
450
- insert before the `goal-audit` node a scoped mini-loop (see Appendix: Fix-Loop Templates → post-goal-audit), each inserted step tagged `goal_ref: "G{n}"`
451
- 2. Re-append a fresh `decision:post-goal-audit {retry+1}` after the inserted steps (re-loops until all met or max retries)
452
- 3. Reindex steps, increment retry_count, write status.json (steps[] now larger — the JSON "grew")
453
- 4. Display: Goal audit: {k} sub-goals unmet → +{N} steps inserted (G{ids}), retry {r}/{max}
547
+ 1. `session.scope_verdict`
548
+ 2. 路径 A(`large`):保持当前链;为后续 `roadmap` step 注入 `--from analyze:{analyze_macro_id}`;为后续 `plan` step phase 列;继续推进
549
+ 3. 路径 B(`medium` / `small`):
550
+ - 删除 `goal-audit` 之前所有未完成的 `roadmap` + `analyze` (phase) step
551
+ - 把下一个未完成的 `plan` step 改为 `maestro-plan --from analyze:{analyze_macro_id}`,去掉 `{phase}`,`source_artifact_ref = analyze:{analyze_macro_id}`
552
+ - 后续 `execute` / `verify` 等沿用同一 standalone scope(不带 `{phase}`,由 plan 写出的 task 列表驱动)
553
+ 4. 路径 C(`unknown`):
554
+ - 非 auto_confirm → ask_user 二选一(large / medium-small);auto_confirm → 默认 large
555
+ 5. Reindex steps,标 decision completed,write status.json
556
+ 6. Display: ◆ Scope verdict: {verdict} → {kept|collapsed to standalone via analyze:{ANL_ID}}
557
+
558
+ ### A_APPLY_GOAL_FIX
559
+
560
+ 1. 对每个 unmet 子目标 `G{n}`(按 `target_phase` 分组去重):在 `goal-audit` 节点前插入 scoped mini-loop(见 Appendix: Fix-Loop Templates → post-goal-audit),每条插入 step `goal_ref: "G{n}"`,按 A_BUILD_STEPS 规则 9 解析 `command_path`
561
+ 2. 重新追加 `decision:post-goal-audit {retry+1}`
562
+ 3. Reindex steps, increment retry_count, write status.json
563
+ 4. Display: ◆ Goal audit: {k} unmet → +{N} steps inserted (G{ids}), retry {r}/{max}
454
564
 
455
565
  ### A_APPLY_GOAL_DONE
456
566
 
457
- 1. Write status.json (source of truth): set every `task_decomposition[*].status="done"`, `completed_at=now`, plus top-level `task_decomposition_all_done=true`
458
- 2. Regenerate `goal-checklist.md` from status.json (Sync Rule in Appendix) — all boxes flip to `[x]`, sentinel `ALL_GOALS_DONE` appended at file end
459
- 3. Mark goal-audit decision completed; proceed to `milestone-complete`
460
- 4. Display: ◆ Goal audit: 全部子目标达成 ✓ — status.json + checklist 已同步 ALL_GOALS_DONE
567
+ 1. status.json: set 每个 `task_decomposition[*].status="done"`, `completion_confirmed=true`, `completed_at=now`,顶层 `task_decomposition_all_done=true`
568
+ 2. Mark goal-audit decision completed;proceed to `milestone-complete`
569
+ 3. Display: Goal audit: all met
461
570
 
462
571
  ### A_ADVANCE_MILESTONE
463
572
 
@@ -484,18 +593,38 @@ Re-checks sub-goals against `status.json` (source of truth) and decides whether
484
593
  "session_id": "ralph-{YYYYMMDD-HHmmss}",
485
594
  "source": "ralph", "status": "running",
486
595
  "intent": "", "lifecycle_position": "",
487
- "phase": null, "phase_is_new": false, "milestone": "",
596
+ "phase": null, "phase_is_new": false,
597
+ "milestone": "", // D-007 反查结果,禁止读 current_milestone
488
598
  "auto_mode": false,
489
- "quality_mode": "standard", // "full" | "standard" | "quick" — 由 A_DETERMINE_QUALITY_MODE 写入
599
+ "quality_mode": "standard", // "full" | "standard" | "quick"
600
+ "planning_mode": "independent", // "unified" | "independent"
601
+ "scope_verdict": null, // "large" | "medium" | "small" | "unknown" | null
602
+ "analyze_macro_id": null, // "ANL-xxx" 来自最新 macro analyze
603
+ "blueprint_id": null, // "BLP-xxx" 若存在
490
604
  "cli_tool": "claude", "passed_gates": [],
491
605
  "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
492
- "analysis_dir": null, "brainstorm_dir": null },
493
- "steps": [{ "index": 0, "type": "internal|external|decision",
494
- "skill": "", "args": "", "status": "pending",
495
- "goal_ref": null }],
606
+ "analysis_dir": null, "brainstorm_dir": null, "blueprint_dir": null },
607
+ "steps": [{
608
+ "index": 0,
609
+ "type": "internal|external|decision",
610
+ "skill": "",
611
+ "args": "",
612
+ "stage": "", // brainstorm|blueprint|init|analyze-macro|roadmap|analyze|plan|execute|verify|...
613
+ "scope": null, // "phase"|"standalone"|"milestone"|null(plan 等需要)
614
+ "command_scope": "global|project|missing|null",
615
+ "command_path": "~/.claude/commands/{name}.md | .claude/commands/{name}.md | null",
616
+ "milestone_id": null, // D-007 反查注入;仅含 {phase} 占位符的 step 有
617
+ "source_artifact_ref": null, // "analyze:ANL-xxx" | "blueprint:BLP-xxx" | null
618
+ "status": "pending|running|completed|skipped|failed",
619
+ "goal_ref": null,
620
+ "completion_confirmed": false,
621
+ "completion_status": null,
622
+ "completion_evidence": null,
623
+ "completed_at": null
624
+ }],
496
625
  "waves": [], "current_step": 0,
497
626
 
498
- "_comment": "↓ OPTIONAL additive decomposition block (v0.4.8+). Absentno decomposition; readers MUST tolerate missing keys. Never remove/rename above fields.",
627
+ // Optional decomposition block (additive; absent → decomposition off)
499
628
  "boundary_contract": {
500
629
  "in_scope": [], "out_of_scope": [], "constraints": [], "definition_of_done": ""
501
630
  },
@@ -503,25 +632,23 @@ Re-checks sub-goals against `status.json` (source of truth) and decides whether
503
632
  "task_decomposition": [
504
633
  { "id": "G1", "goal": "", "boundary": "", "done_when": "",
505
634
  "evidence": "", "lifecycle": [], "status": "pending|done",
506
- "completed_at": null }
635
+ "completion_confirmed": false, "completed_at": null }
507
636
  ],
508
- "task_decomposition_all_done": false,
509
- "goal_checklist_path": "",
510
- "goal_checklist_synced_at": null
637
+ "task_decomposition_all_done": false
511
638
  }
512
639
  ```
513
640
 
514
- **扩展约定**:
515
- - Schema 加字段 = 可选(缺省 = 旧行为);不删/不改既有字段名。
516
- - `steps[]` 是活数组:`post-goal-audit` 与 `post-verify/review/test` 等决策节点按需追加+重排,子目标收敛即停。`goal_ref`(可选)回溯每条动态插入步骤所属子目标。
641
+ 新增字段可选,缺省=旧行为;既有字段名不删不改。
517
642
 
518
643
  ### Fix-Loop Templates
519
644
 
645
+ 所有插入 step 默认 `type: "internal"`,按 A_BUILD_STEPS 规则 9 解析 `command_path` + `command_scope`。
646
+
520
647
  **post-verify:**
521
648
  ```
522
649
  quality-debug "{gap_summary}"
523
650
  maestro-plan --gaps {phase}
524
- maestro-execute {phase} [external]
651
+ maestro-execute {phase}
525
652
  maestro-verify {phase}
526
653
  decision:post-verify {retry+1}
527
654
  ```
@@ -530,7 +657,7 @@ decision:post-verify {retry+1}
530
657
  ```
531
658
  quality-debug --from-business-test "{gap_summary}"
532
659
  maestro-plan --gaps {phase}
533
- maestro-execute {phase} [external]
660
+ maestro-execute {phase}
534
661
  maestro-verify {phase}
535
662
  decision:post-verify {retry: 0}
536
663
  quality-auto-test {phase}
@@ -541,7 +668,7 @@ decision:post-business-test {retry+1}
541
668
  ```
542
669
  quality-debug "{gap_summary}"
543
670
  maestro-plan --gaps {phase}
544
- maestro-execute {phase} [external]
671
+ maestro-execute {phase}
545
672
  quality-review {phase}
546
673
  decision:post-review {retry+1}
547
674
  ```
@@ -550,7 +677,7 @@ decision:post-review {retry+1}
550
677
  ```
551
678
  quality-debug --from-uat "{gap_summary}"
552
679
  maestro-plan --gaps {phase}
553
- maestro-execute {phase} [external]
680
+ maestro-execute {phase}
554
681
  maestro-verify {phase}
555
682
  decision:post-verify {retry: 0}
556
683
  quality-auto-test {phase}
@@ -562,73 +689,15 @@ quality-test {phase}
562
689
  decision:post-test {retry+1}
563
690
  ```
564
691
 
565
- **post-goal-audit:** (per unmet sub-goal group — this is what dynamically grows `steps[]`)
692
+ **post-goal-audit:** (per unmet sub-goal group)
566
693
  ```
567
- # for each unmet sub-goal G{n}, scoped to its target_phase:
694
+ # for each unmet sub-goal G{n}, scoped to target_phase:
568
695
  maestro-plan --gaps {target_phase} "G{n}: {gap}" [goal_ref: G{n}]
569
- maestro-execute {target_phase} [external] [goal_ref: G{n}]
570
- maestro-verify {target_phase} [goal_ref: G{n}]
571
- # after all unmet groups inserted, re-loop the audit:
696
+ maestro-execute {target_phase} [goal_ref: G{n}]
697
+ maestro-verify {target_phase} [goal_ref: G{n}]
698
+ # after all unmet groups inserted:
572
699
  decision:post-goal-audit {retry+1}
573
700
  ```
574
- Notes: only unmet sub-goals' phases are re-run (no full-pipeline replay); inserted steps carry `goal_ref` for traceability; loop exits when audit returns `all_met` (→ A_APPLY_GOAL_DONE) or retry hits max (→ escalate to human). This keeps growth bounded.
575
-
576
- ### Goal Checklist Template (status.json projection)
577
-
578
- `{session_dir}/goal-checklist.md` 是 `status.json` 的只读投影:不要手改,永远从 JSON 重渲染。文件名在 session 内稳定,`/goal` 条件字符串跨上下文压缩仍可用。
579
-
580
- ```markdown
581
- # Ralph Goal Checklist — {session_id}
582
- <!-- AUTO-GENERATED from status.json. Source: ../status.json#/task_decomposition -->
583
-
584
- > Intent : {intent}
585
- > Source : `{session_dir}/status.json` (authoritative)
586
- > Last sync : {ISO} Phase: {phase} Milestone: {milestone}
587
-
588
- ## Resume / 恢复入口
589
- **不要直接执行 skill,调用入口:**
590
- ```
591
- /maestro-ralph continue
592
- ```
593
- ralph 评估下一步门控,ralph-execute 跑实际步骤。Stop hook 触发时也走这条路径。
594
-
595
- ## 执行准则 / Execution Criteria
596
- <!-- status.json#/execution_criteria -->
597
- - {criterion 1}
598
- - {criterion 2}
599
-
600
- ## 边界契约 / Boundary Contract
601
- <!-- status.json#/boundary_contract -->
602
- - In scope : {in_scope}
603
- - Out of scope : {out_of_scope}
604
- - Constraints : {constraints}
605
- - Definition of Done : {definition_of_done}
606
-
607
- ## 子目标 / Sub-goals ({done}/{total})
608
- <!-- status.json#/task_decomposition -->
609
- - [ ] G1 — {goal}
610
- done_when : {done_when}
611
- evidence : {evidence}
612
- lifecycle : {lifecycle}
613
- <!-- ref: status.json#/task_decomposition/0 status=pending -->
614
- - [x] G2 — {goal}
615
- done_when : {done_when}
616
- evidence : {evidence}
617
- <!-- ref: status.json#/task_decomposition/1 status=done completed_at={ISO} -->
618
- - [ ] G3 — ...
619
-
620
- <!-- A_APPLY_GOAL_DONE 在全部 status=done 时在文件末尾追加 ALL_GOALS_DONE -->
621
- ```
622
-
623
- ### Sync Rule (status.json ↔ goal-checklist.md)
624
-
625
- 单向投影;status.json 为真源;冲突时直接重渲染,不合并。
626
-
627
- 1. 只有 ralph / ralph-execute 写 `task_decomposition[*].status`;markdown 不可写入状态。
628
- 2. `task_decomposition` / `execution_criteria` / `boundary_contract` 任一变化 → 立即重渲染 checklist。
629
- 3. 全部 `status="done"` → 在文件末追加 `ALL_GOALS_DONE` 哨兵行。
630
- 4. 检测到 checklist 缺失或与 JSON 漂移 → 直接重渲染覆盖;视 markdown 为可丢弃产物。
631
- 5. ralph-execute(可选、向后兼容):完成 `lifecycle` 覆盖某子目标的 step 后,校验 evidence;满足则置 `status="done"` + 重渲染。无 `task_decomposition` 字段 → 不动作。
632
701
 
633
702
  ### Goal Prompt Template
634
703
 
@@ -637,12 +706,12 @@ ralph 评估下一步门控,ralph-execute 跑实际步骤。Stop hook 触发
637
706
  ```
638
707
  📋 任务分解完成。复制下面一行设定目标,会话在子目标全部达成前不停:
639
708
 
640
- /goal 目标达成条件: {session_dir}/status.json 中 task_decomposition[*].status 全部为 "done"(等价: {session_dir}/goal-checklist.md 末尾含 ALL_GOALS_DONE)。未达成时: 阅读 {session_dir}/goal-checklist.md 取得"执行准则/边界契约/子目标"作为行动手册, 然后调用 /maestro-ralph continue 推进下一步; 严禁手动执行 skill 或越界修改 status.json.boundary_contract.out_of_scope。
709
+ /goal 目标达成条件: {session_dir}/status.json 中 task_decomposition[*].status == "done" 且 task_decomposition[*].completion_confirmed == true steps[*].completion_confirmed == true。未达成时:阅读 {session_dir}/status.json 取得 execution_criteria / boundary_contract / task_decomposition / steps 作为行动手册,调用 /maestro-ralph continue 推进;严禁手动执行 skill 或越界修改 status.json.boundary_contract.out_of_scope。
641
710
 
642
711
  随后运行 /maestro-ralph continue 立即开始执行。
643
712
  ```
644
713
 
645
- `/goal` 是 harness 命令,仅用户能输入;ralph 只能输出此提示词。判据以 status.json 为权威,哨兵为等价信号,避免视图漂移误判。
714
+ `/goal` 由用户输入;ralph 只输出此提示词。判据以 status.json 为权威。
646
715
 
647
716
  ### Error Codes
648
717
 
@@ -653,6 +722,7 @@ ralph 评估下一步门控,ralph-execute 跑实际步骤。Stop hook 触发
653
722
  | E003 | error | Artifact dir not found for decision | Show glob, ask |
654
723
  | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
655
724
  | E005 | error | Delegate execution failed | Fallback: "fix" |
725
+ | E006 | error | command_scope == "missing" for one or more steps | List missing skills, abort build |
656
726
  | W001 | warning | Decision expanded chain | Auto-handled |
657
727
  | W002 | warning | Max retries, escalating | Auto-handled |
658
728
  | W003 | warning | Multiple running sessions | Use latest, warn |
@@ -660,26 +730,27 @@ ralph 评估下一步门控,ralph-execute 跑实际步骤。Stop hook 触发
660
730
 
661
731
  ### Success Criteria
662
732
 
663
- - [ ] Phase 先于 position 解析(S_RESOLVE_PHASE → S_INFER → S_QUALITY_MODE);phase_is_new 标记写入 session
664
- - [ ] phase_is_new=true lifecycle_position 强制为 `analyze`(禁止用其他 phase 的 artifact 推断)
665
- - [ ] artifact 过滤始终按 session.phase(不读 state.json.current_phase)
666
- - [ ] quality_mode 显式由 A_DETERMINE_QUALITY_MODE 决定(full/standard/quick),过滤 build steps
667
- - [ ] State parsed, position inferred from bootstrap + artifacts + result files
668
- - [ ] Decomposition runs as initial step; broad intent boundary-clarified via ≤3 questions (ignores auto_confirm); narrow auto-derives
669
- - [ ] status.json enriched additively with boundary_contract + execution_criteria + task_decomposition; absent fields = old behavior preserved
670
- - [ ] status.json is single source of truth; goal-checklist.md is a regenerated projection (Sync Rule), never hand-edited
671
- - [ ] goal-checklist.md carries explicit `status.json#/task_decomposition[i]` JSON-pointer refs per entry + last-sync timestamp
672
- - [ ] Mutations to task_decomposition trigger checklist re-render; ALL_GOALS_DONE sentinel appended only when all entries status=done
673
- - [ ] Goal Prompt names status.json as the authoritative judgement source, with ALL_GOALS_DONE sentinel as equivalent signal
674
- - [ ] post-goal-audit decision node inserted before milestone-complete (only when decomposed)
675
- - [ ] Unmet sub-goals DYNAMICALLY grow steps[] via scoped per-goal mini-loops (goal_ref tagged), looping until all_met or max retries → escalate
676
- - [ ] Quality pipeline quality_mode 生成(full=全管线 / standard=skip business-test / quick=仅 review --tier quick)
677
- - [ ] Chain 末端硬约束:必须以 `milestone-complete` 结尾(goal-audit decision 紧前)
678
- - [ ] 初始构建按 task_decomposition[*].lifecycle 给每个 step 打 goal_ref(verify/review 等共用 lifecycle 的 step 也有标签)
679
- - [ ] Decision nodes delegate-evaluated via maestro delegate --role analyze
680
- - [ ] Verdict parsed with confidence adjustment
681
- - [ ] Fix-loop templates applied with retry tracking
682
- - [ ] Ralph never executes steps — only creates sessions and evaluates decisions
683
- - [ ] Handoff to maestro-ralph-execute via invoke_skill() at creation and after decisions
733
+ - [ ] Phase 先于 position 解析;phase_is_new 标记写入 session
734
+ - [ ] D-007 反查:phase 数字 `session.milestone`,禁止读 current_milestone;写入 step.milestone_id
735
+ - [ ] phase_is_new=true lifecycle_position 强制 `analyze`
736
+ - [ ] Intent overrides 识别 brainstorm / blueprint / analyze-macro
737
+ - [ ] A_RESOLVE_SCOPE_VERDICT macro analyze conclusions.scope_verdict,写入 session.scope_verdict + analyze_macro_id
738
+ - [ ] 链路起点 = analyze-macro 时:large→roadmap+analyze+plan(phase);medium/small→直跳 plan --from analyze:{ANL_ID}(跳过 roadmap+analyze)
739
+ - [ ] post-analyze-scope decision 节点在 macro analyze 之后插入;A_SCOPE_EVALUATE/A_APPLY_SCOPE_VERDICT 重塑链路
740
+ - [ ] plan step args 支持三路径:`{phase}` / `--from analyze:{ANL_ID}` / `--from blueprint:{BLP_ID}`,写入 step.source_artifact_ref
741
+ - [ ] roadmap step args 自动注入 `--from analyze:{analyze_macro_id}`(若存在)
742
+ - [ ] artifact 过滤按 session.phase;unified milestone
743
+ - [ ] quality_mode A_DETERMINE_QUALITY_MODE 决定,过滤 build steps
744
+ - [ ] Decomposition: broad intent ≤3 question clarify;narrow auto-derive
745
+ - [ ] status.json 唯一真源:boundary_contract + execution_criteria + task_decomposition;无外部清单
746
+ - [ ] 每个 step 默认 `type: "internal"`,含 `command_scope` + `command_path`(全局优先 fallback 项目)
747
+ - [ ] 每个 step `completion_confirmed` + `completion_status` + `completion_evidence`(初始 false/null)
748
+ - [ ] 每个 sub-goal `completion_confirmed`(初始 false)
749
+ - [ ] post-goal-audit decision 仅在 decomposed 时插入,位于 milestone-complete 之前
750
+ - [ ] Unmet sub-goals 动态 grow steps[](goal_ref tagged);max retries → escalate
751
+ - [ ] planning_mode 显式决定;unified=无 `{phase}`, independent=带 `{phase}`
752
+ - [ ] Chain 必须以 `milestone-complete` 结尾
753
+ - [ ] Decision nodes maestro delegate --role analyze 评估
754
+ - [ ] Ralph 不执行 step,只 evaluate;invoke_skill("maestro-ralph-execute") handoff
684
755
 
685
756
  </appendix>