maestro-flow 0.4.16 → 0.4.18

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