maestro-flow 0.4.16 → 0.4.17

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 (31) hide show
  1. package/.agents/skills/maestro-init/SKILL.md +1 -1
  2. package/.agents/skills/maestro-ralph-beta/SKILL.md +893 -0
  3. package/.agy/skills/maestro-init/SKILL.md +1 -1
  4. package/.agy/skills/maestro-ralph-beta/SKILL.md +889 -0
  5. package/.claude/commands/maestro-init.md +1 -1
  6. package/.claude/commands/maestro-ralph-beta.md +891 -0
  7. package/.codex/skills/maestro-ralph/SKILL.md +93 -73
  8. package/.codex/skills/maestro-ralph-beta/SKILL.md +891 -0
  9. package/.codex/skills/maestro-ralph-execute/SKILL.md +243 -0
  10. package/dist/src/commands/install-backend.d.ts.map +1 -1
  11. package/dist/src/commands/install-backend.js +23 -4
  12. package/dist/src/commands/install-backend.js.map +1 -1
  13. package/dist/src/commands/ralph.d.ts.map +1 -1
  14. package/dist/src/commands/ralph.js +3 -1
  15. package/dist/src/commands/ralph.js.map +1 -1
  16. package/dist/src/ralph/cmd-next.d.ts.map +1 -1
  17. package/dist/src/ralph/cmd-next.js +44 -1
  18. package/dist/src/ralph/cmd-next.js.map +1 -1
  19. package/dist/src/ralph/cmd-skills.d.ts +2 -0
  20. package/dist/src/ralph/cmd-skills.d.ts.map +1 -1
  21. package/dist/src/ralph/cmd-skills.js +11 -4
  22. package/dist/src/ralph/cmd-skills.js.map +1 -1
  23. package/dist/src/ralph/skill-scanner.d.ts +7 -2
  24. package/dist/src/ralph/skill-scanner.d.ts.map +1 -1
  25. package/dist/src/ralph/skill-scanner.js +39 -24
  26. package/dist/src/ralph/skill-scanner.js.map +1 -1
  27. package/dist/src/ralph/status-schema.d.ts +2 -0
  28. package/dist/src/ralph/status-schema.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/templates/config.json +21 -33
  31. package/workflows/init.md +11 -11
@@ -0,0 +1,889 @@
1
+ ---
2
+ name: maestro-ralph-beta
3
+ description: Self-running loop controller for adaptive maestro workflow — build, tick, decide in one skill
4
+ argument-hint: <intent> [-y] | continue | status
5
+ allowed-tools:
6
+ - ask_question
7
+ - grep_search
8
+ - replace_file_content
9
+ - run_command
10
+ - view_file
11
+ - write_to_file
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 claude --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-verify, 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 | `verify` |
301
+ | phase 已存在 + 最新 artifact = verify | → refine from result files |
302
+
303
+ **Refine from verify results:**
304
+
305
+ | Condition | Position |
306
+ |-----------|----------|
307
+ | verification.json: passed==false or gaps[] | `verify-failed` |
308
+ | passed==true, no review.json | `business-test` |
309
+ | review.json: verdict=="BLOCK" | `review-failed` |
310
+ | review.json: verdict!="BLOCK" | `test` |
311
+ | uat.md: all passed | `milestone-audit` |
312
+ | uat.md: has failures | `test-failed` |
313
+
314
+ ### A_RESOLVE_SCOPE_VERDICT
315
+
316
+ 仅当 `lifecycle_position ∈ {analyze-macro, roadmap, plan}` 且存在最新 analyze artifact 时执行。
317
+
318
+ 1. 定位最新 macro analyze artifact(`type=="analyze"` 且 `scope=="macro"`,按 created_at DESC)→ `session.analyze_macro_id = ANL-xxx`
319
+ 2. 读 `{artifact_path}/conclusions.json` 的 `scope_verdict` 字段(`large | medium | small`)
320
+ 3. 写入 `session.scope_verdict`;缺失 → `unknown`
321
+ 4. 路由建议:
322
+
323
+ | scope_verdict | 链路 |
324
+ |---------------|------|
325
+ | `large` | analyze-macro → roadmap → analyze → plan → execute → ... |
326
+ | `medium` / `small` | analyze-macro → plan --from analyze:{ANL_ID} → execute → ... |
327
+ | `unknown` | 默认 large;post-analyze-scope 节点再纠正 |
328
+
329
+ ### A_DETERMINE_QUALITY_MODE
330
+
331
+ 读 `session.quality_mode_override`(CLI `--quality`),无则按规则推断:
332
+
333
+ | Condition | Mode | Pipeline (verify 之后) |
334
+ |-----------|------|-------------------------|
335
+ | Has `specs/REQ-*.md` + 当前 phase 业务范围明确 | `full` | business-test → review → test-gen → test |
336
+ | Default | `standard` | review → test-gen (当 coverage<80%) → test |
337
+ | `--quality quick` | `quick` | review --tier quick |
338
+
339
+ 写入 `session.quality_mode`。
340
+
341
+ ### A_DETERMINE_PLANNING_MODE
342
+
343
+ **Auto-resolve rules (按优先级):**
344
+
345
+ | Condition | Mode |
346
+ |-----------|------|
347
+ | lifecycle_position ∈ {brainstorm, init, roadmap} | `independent` |
348
+ | `phase_is_new == true` | `independent` |
349
+ | intent 显式指定 phase 编号(如 "phase 2"、"P3") | `independent` |
350
+ | milestone 仅含 1 个 phase | `independent` |
351
+ | milestone 含多个 phase + `auto_confirm` | `unified` |
352
+ | milestone 含多个 phase + 非 `auto_confirm` | → ask_question |
353
+
354
+ **ask_question** (仅当 milestone 含 ≥2 phase 且非 auto_confirm):
355
+
356
+ ```
357
+ question: "当前里程碑含 {N} 个 phase,选择规划模式?"
358
+ options:
359
+ - label: "统一规划 (Recommended)"
360
+ description: "一次性分析+规划整个里程碑所有 phase,analyze/plan 走里程碑级,适合 phase 间关联紧密"
361
+ - label: "独立规划"
362
+ description: "逐个 phase 走完整生命周期(analyze→plan→execute→verify→...),适合 phase 间独立性高"
363
+ ```
364
+
365
+ 写入 `session.planning_mode`(`"unified"` 或 `"independent"`)。
366
+
367
+ ### A_DECOMPOSE_TASKS
368
+
369
+ **1. Classify intent breadth:**
370
+
371
+ | Pattern | Breadth | Clarify? |
372
+ |---------|---------|----------|
373
+ | 重构/全面/重写/重做/整体/迁移 · overhaul/migrate/rewrite/revamp | broad | MUST (ignores auto_confirm) |
374
+ | named single file/function/bug, "fix X", "add Y to Z" | narrow | skip — auto-derive |
375
+ | otherwise | medium | clarify unless auto_confirm |
376
+
377
+ **2. Clarify boundary** (broad/medium) — `ask_question`, ≤3 rounds, options pre-filled from intent + a quick Glob/Grep scan of the target module:
378
+
379
+ | Round | Question | Drives |
380
+ |-------|----------|--------|
381
+ | Scope | 哪些目录/文件/层在范围内?明确排除什么? | boundary_contract.in_scope / out_of_scope |
382
+ | Constraints | 必须向后兼容?公共 API 冻结?行为/性能预算?测试门槛? | boundary_contract.constraints + execution_criteria |
383
+ | Done | 什么可观测结果算"完成"?(如:测试全绿 + 行为零变更 + X 指标) | boundary_contract.definition_of_done |
384
+
385
+ narrow → derive defaults from intent + codebase, skip questions.
386
+
387
+ **3. Derive `execution_criteria`**: backward-compat、scope-freeze、test/coverage bar、fix-don't-hide、incremental commit。
388
+
389
+ **4. Derive `task_decomposition`** (子目标清单 — outcome-oriented, NOT lifecycle stages). Each entry:
390
+ ```json
391
+ { "id": "G1", "goal": "<deliverable>", "boundary": "<in/out note>",
392
+ "done_when": "<objectively checkable condition>",
393
+ "evidence": "verification.json|review.json|uat.md|<test path>",
394
+ "lifecycle": ["analyze","execute","verify"], "status": "pending" }
395
+ ```
396
+ `done_when` 必须客观可验证,且引用 ralph 已产出的 artifact;`lifecycle` 字段映射到产出 evidence 的生命周期 stage。
397
+
398
+ **5. Persist**: `boundary_contract`, `execution_criteria`, `task_decomposition`。每个 sub-goal 初始化 `status: "pending"` + `completion_confirmed: false`。
399
+
400
+ **6. Stage** the Goal Prompt (Appendix) for A_CREATE_SESSION to emit.
401
+
402
+ ### A_BUILD_STEPS
403
+
404
+ 从 `session.lifecycle_position` 生成 steps 到 `milestone-complete`。
405
+
406
+ | Stage | Skill (independent) | Skill (unified) | Decision after | quality_mode |
407
+ |-------|---------------------|-----------------|----------------|--------------|
408
+ | brainstorm | `maestro-brainstorm "{intent}"` | *(same)* | — | all |
409
+ | blueprint | `maestro-blueprint "{intent}"` | *(same)* | — | all |
410
+ | init | `maestro-init` | *(same)* | — | all |
411
+ | analyze-macro | `maestro-analyze "{intent}"` | *(same)* | `post-analyze-scope` | all |
412
+ | roadmap | `maestro-roadmap --from analyze:{analyze_macro_id}` | *(same)* | — | all |
413
+ | analyze | `maestro-analyze {phase}` | `maestro-analyze` | — | all |
414
+ | 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 |
415
+ | execute | `maestro-execute {phase}` | `maestro-execute` | — | all |
416
+ | verify | `maestro-verify {phase}` | `maestro-verify` | `post-verify` | 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(verify/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 claude --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.json → filter 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-verify | 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` / `verify` 同 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. maestro-verify 1 [global]
719
+ [✓] 3. ◆ post-verify [decision]
720
+ ...
721
+ ============================================================
722
+ ```
723
+ Icons: `✓` confirmed, `—` skipped, `✗` failed, `◆` decision
724
+
725
+ </actions>
726
+
727
+ </state_machine>
728
+
729
+ <appendix>
730
+
731
+ ### Session Schema
732
+
733
+ ```json
734
+ {
735
+ "session_id": "ralph-{YYYYMMDD-HHmmss}",
736
+ "source": "ralph", "status": "running",
737
+ "ralph_protocol_version": "2",
738
+ "active_step_index": null,
739
+ "intent": "", "lifecycle_position": "",
740
+ "phase": null, "phase_is_new": false,
741
+ "milestone": "", // D-007 反查结果
742
+ "auto_mode": false,
743
+ "quality_mode": "standard", // "full" | "standard" | "quick"
744
+ "planning_mode": "independent", // "unified" | "independent"
745
+ "scope_verdict": null, // "large" | "medium" | "small" | "unknown" | null
746
+ "analyze_macro_id": null, // "ANL-xxx"
747
+ "blueprint_id": null, // "BLP-xxx"
748
+ "cli_tool": "claude", "passed_gates": [],
749
+ "consec_exit2_count": 0,
750
+
751
+ "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
752
+ "analysis_dir": null, "brainstorm_dir": null, "blueprint_dir": null },
753
+ "steps": [{
754
+ "index": 0,
755
+ "skill": "", // 执行 step 有值;decision 节点为空字符串/null
756
+ "args": "",
757
+ "stage": "", // brainstorm|blueprint|init|analyze-macro|roadmap|analyze|plan|execute|verify|...
758
+ "scope": null, // "phase"|"standalone"|"milestone"|null(plan 等需要)
759
+ "decision": null, // null = 执行 step;非 null = decision step (值为 gate 名)
760
+ "retry_count": 0, // decision step
761
+ "max_retries": 2, // decision step
762
+ "command_scope": "global|project|missing|null",
763
+ "command_path": "<absolute path> | null",
764
+ "milestone_id": null, // 仅含 {phase} 占位符的 step
765
+ "source_artifact_ref": null, // "analyze:ANL-xxx" | "blueprint:BLP-xxx" | null
766
+ "status": "pending|running|completed|skipped|failed",
767
+ "goal_ref": null,
768
+ "completion_confirmed": false,
769
+ "completion_status": null,
770
+ "completion_evidence": null,
771
+ "completed_at": null,
772
+ "deferred_reads": [],
773
+ "load": null // { loaded_at, required_files[], deferred_files[], resolve_version }
774
+ }],
775
+ "current_step": 0,
776
+
777
+ "boundary_contract": {
778
+ "in_scope": [], "out_of_scope": [], "constraints": [], "definition_of_done": ""
779
+ },
780
+ "execution_criteria": [],
781
+ "task_decomposition": [
782
+ { "id": "G1", "goal": "", "boundary": "", "done_when": "",
783
+ "evidence": "", "lifecycle": [], "status": "pending|done",
784
+ "completion_confirmed": false, "completed_at": null }
785
+ ],
786
+ "task_decomposition_all_done": false
787
+ }
788
+ ```
789
+
790
+ ### Fix-Loop Templates
791
+
792
+ 插入的执行 step 按 A_BUILD_STEPS 规则 9 解析 `command_path` + `command_scope`;`decision:*` 条目为 decision 节点。
793
+
794
+ **post-verify:**
795
+ ```
796
+ quality-debug "{gap_summary}"
797
+ maestro-plan --gaps {phase}
798
+ maestro-execute {phase}
799
+ maestro-verify {phase}
800
+ decision:post-verify {retry+1}
801
+ ```
802
+
803
+ **post-business-test:**
804
+ ```
805
+ quality-debug --from-business-test "{gap_summary}"
806
+ maestro-plan --gaps {phase}
807
+ maestro-execute {phase}
808
+ maestro-verify {phase}
809
+ decision:post-verify {retry: 0}
810
+ quality-auto-test {phase}
811
+ decision:post-business-test {retry+1}
812
+ ```
813
+
814
+ **post-review:**
815
+ ```
816
+ quality-debug "{gap_summary}"
817
+ maestro-plan --gaps {phase}
818
+ maestro-execute {phase}
819
+ quality-review {phase}
820
+ decision:post-review {retry+1}
821
+ ```
822
+
823
+ **post-test:**
824
+ ```
825
+ quality-debug --from-uat "{gap_summary}"
826
+ maestro-plan --gaps {phase}
827
+ maestro-execute {phase}
828
+ maestro-verify {phase}
829
+ decision:post-verify {retry: 0}
830
+ quality-auto-test {phase}
831
+ decision:post-business-test {retry: 0}
832
+ quality-review {phase}
833
+ decision:post-review {retry: 0}
834
+ quality-auto-test {phase}
835
+ quality-test {phase}
836
+ decision:post-test {retry+1}
837
+ ```
838
+
839
+ **post-goal-audit:** (per unmet sub-goal group)
840
+ ```
841
+ # for each unmet sub-goal G{n}, scoped to target_phase:
842
+ maestro-plan --gaps {target_phase} "G{n}: {gap}" [goal_ref: G{n}]
843
+ maestro-execute {target_phase} [goal_ref: G{n}]
844
+ maestro-verify {target_phase} [goal_ref: G{n}]
845
+ # after all unmet groups inserted:
846
+ decision:post-goal-audit {retry+1}
847
+ ```
848
+
849
+ ### Goal Prompt Template
850
+
851
+ decomposition 产出后,链路概览之后逐字显示:
852
+
853
+ ```
854
+ 📋 任务分解完成。可随时复制以下 /goal 设定终止条件:
855
+
856
+ /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。
857
+ ```
858
+
859
+ ### Error Codes
860
+
861
+ | Code | Severity | Description | Recovery |
862
+ |------|----------|-------------|----------|
863
+ | E001 | error | No intent and no running session | Prompt for intent |
864
+ | E002 | error | Cannot infer lifecycle position | Show raw state, ask |
865
+ | E003 | error | Artifact dir not found for decision | Show glob, ask |
866
+ | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
867
+ | E005 | error | Delegate execution failed | Fallback: "fix" |
868
+ | E006 | error | command_scope == "missing" for one or more steps | List missing skills, abort build |
869
+ | E007 | error | required_reading 引用文件缺失 | `ralph next` 拒绝;CLI stderr 列出缺失路径 |
870
+ | E008 | error | `ralph complete` idx ≠ active_step_index | 编辑 status.json 修正一致性 |
871
+ | E009 | error | `ralph complete` step.status ≠ running | 重复 complete 或非法跳跃;编辑 status.json |
872
+ | E010 | error | status.json schema 损坏 OR A_EXEC_STEP exit=2 熔断(连续 ≥2 次空转) | `ralph check` 显示损坏字段;熔断需人工核对 next_pending_step 与 router 路由是否一致 |
873
+ | W001 | warning | Decision expanded chain | Auto-handled |
874
+ | W002 | warning | Max retries, escalating | Auto-handled |
875
+ | W003 | warning | Multiple running sessions | Use latest, warn |
876
+ | W004 | warning | Low delegate confidence | Show warning |
877
+ | W005 | warning | active_step_index 指向已 completed step | `ralph next` 自动清理后继续 |
878
+ | W007 | warning | step.skill ≠ command .md frontmatter.name | 提示但不阻塞 |
879
+
880
+ ### Success Criteria
881
+
882
+ - [ ] Tick 末尾自调用 `Skill("maestro-ralph-beta")`,直到全部 `completion_confirmed` 或 paused
883
+ - [ ] 同一 session 同时仅一个 step 持 `active_step_index`;切换前必经 release
884
+ - [ ] Decision step 全程不调 `maestro ralph next` / `complete`,由 maestro-ralph-beta 内联评估并 release
885
+ - [ ] `task_decomposition` 存在时,chain 含 `decision:post-goal-audit`,且最终 `task_decomposition_all_done == true` 才允许 S_COMPLETE
886
+ - [ ] Chain 以 `milestone-complete` 结尾;A_APPLY_* 修改 steps[] 后均 reindex
887
+ - [ ] 连续 2 次 `ralph next` exit=2 → E010 pause(防 router 错路由空转)
888
+
889
+ </appendix>