maestro-flow 0.5.43 → 0.5.45

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 (104) hide show
  1. package/.agents/agents/ralph-executor.md +48 -0
  2. package/.agents/skills/maestro-ralph-cli/SKILL.md +21 -16
  3. package/.agents/skills/maestro-ralph-v2/SKILL.md +860 -0
  4. package/.agy/agents/ralph-executor.md +44 -0
  5. package/.agy/skills/maestro-ralph-cli/SKILL.md +21 -16
  6. package/.agy/skills/maestro-ralph-v2/SKILL.md +873 -0
  7. package/.claude/agents/ralph-executor.md +46 -0
  8. package/.claude/commands/maestro-ralph-cli.md +21 -16
  9. package/.claude/commands/maestro-ralph-v2.md +858 -0
  10. package/.codex/skills/maestro-next/SKILL.md +1 -1
  11. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +7 -7
  12. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  13. package/dashboard/dist-server/src/graph/kg/credibility.d.ts +2 -2
  14. package/dashboard/dist-server/src/graph/kg/credibility.js +10 -5
  15. package/dashboard/dist-server/src/graph/kg/credibility.js.map +1 -1
  16. package/dashboard/dist-server/src/graph/kg/db/connection.d.ts +3 -2
  17. package/dashboard/dist-server/src/graph/kg/db/connection.js +28 -16
  18. package/dashboard/dist-server/src/graph/kg/db/connection.js.map +1 -1
  19. package/dashboard/dist-server/src/graph/kg/db/queries.js +4 -4
  20. package/dashboard/dist-server/src/graph/kg/db/queries.js.map +1 -1
  21. package/dashboard/dist-server/src/graph/kg/engine.d.ts +1 -1
  22. package/dashboard/dist-server/src/graph/kg/extraction/knowledge/domain-extractor.d.ts +1 -1
  23. package/dashboard/dist-server/src/graph/kg/extraction/knowledge/domain-extractor.js +8 -4
  24. package/dashboard/dist-server/src/graph/kg/extraction/knowledge/domain-extractor.js.map +1 -1
  25. package/dashboard/dist-server/src/graph/kg/resolution/knowledge-resolver.d.ts +3 -3
  26. package/dashboard/dist-server/src/graph/kg/resolution/knowledge-resolver.js +3 -2
  27. package/dashboard/dist-server/src/graph/kg/resolution/knowledge-resolver.js.map +1 -1
  28. package/dashboard/dist-server/src/graph/kg/surface/hook-injector.js +2 -4
  29. package/dashboard/dist-server/src/graph/kg/surface/hook-injector.js.map +1 -1
  30. package/dashboard/dist-server/src/search/daemon-client.d.ts +3 -25
  31. package/dashboard/dist-server/src/search/daemon-client.js +3 -25
  32. package/dashboard/dist-server/src/search/daemon-client.js.map +1 -1
  33. package/dashboard/dist-server/src/search/daemon-types.d.ts +29 -0
  34. package/dashboard/dist-server/src/search/daemon-types.js +31 -0
  35. package/dashboard/dist-server/src/search/daemon-types.js.map +1 -0
  36. package/dist/src/agents/api-explore/agent-loop.d.ts +1 -1
  37. package/dist/src/agents/api-explore/agent-loop.d.ts.map +1 -1
  38. package/dist/src/agents/api-explore/agent-loop.js +32 -17
  39. package/dist/src/agents/api-explore/agent-loop.js.map +1 -1
  40. package/dist/src/agents/api-explore/prompt-parser.js +5 -5
  41. package/dist/src/agents/api-explore/prompt-parser.js.map +1 -1
  42. package/dist/src/agents/api-explore/runner.d.ts.map +1 -1
  43. package/dist/src/agents/api-explore/runner.js +0 -2
  44. package/dist/src/agents/api-explore/runner.js.map +1 -1
  45. package/dist/src/agents/api-explore/system-prompt.d.ts.map +1 -1
  46. package/dist/src/agents/api-explore/system-prompt.js +30 -22
  47. package/dist/src/agents/api-explore/system-prompt.js.map +1 -1
  48. package/dist/src/agents/api-explore/tools.d.ts +1 -0
  49. package/dist/src/agents/api-explore/tools.d.ts.map +1 -1
  50. package/dist/src/agents/api-explore/tools.js +219 -50
  51. package/dist/src/agents/api-explore/tools.js.map +1 -1
  52. package/dist/src/commands/search.d.ts.map +1 -1
  53. package/dist/src/commands/search.js +10 -4
  54. package/dist/src/commands/search.js.map +1 -1
  55. package/dist/src/commands/update.d.ts.map +1 -1
  56. package/dist/src/commands/update.js +89 -21
  57. package/dist/src/commands/update.js.map +1 -1
  58. package/dist/src/graph/db/connection.d.ts +3 -2
  59. package/dist/src/graph/db/connection.d.ts.map +1 -1
  60. package/dist/src/graph/db/connection.js +28 -16
  61. package/dist/src/graph/db/connection.js.map +1 -1
  62. package/dist/src/graph/db/queries.d.ts.map +1 -1
  63. package/dist/src/graph/db/queries.js.map +1 -1
  64. package/dist/src/graph/kg/credibility.d.ts +2 -2
  65. package/dist/src/graph/kg/credibility.d.ts.map +1 -1
  66. package/dist/src/graph/kg/credibility.js +10 -5
  67. package/dist/src/graph/kg/credibility.js.map +1 -1
  68. package/dist/src/graph/kg/db/connection.d.ts +3 -2
  69. package/dist/src/graph/kg/db/connection.d.ts.map +1 -1
  70. package/dist/src/graph/kg/db/connection.js +28 -16
  71. package/dist/src/graph/kg/db/connection.js.map +1 -1
  72. package/dist/src/graph/kg/db/queries.js +4 -4
  73. package/dist/src/graph/kg/db/queries.js.map +1 -1
  74. package/dist/src/graph/kg/engine.d.ts +1 -1
  75. package/dist/src/graph/kg/engine.d.ts.map +1 -1
  76. package/dist/src/graph/kg/extraction/knowledge/domain-extractor.d.ts +1 -1
  77. package/dist/src/graph/kg/extraction/knowledge/domain-extractor.d.ts.map +1 -1
  78. package/dist/src/graph/kg/extraction/knowledge/domain-extractor.js +8 -4
  79. package/dist/src/graph/kg/extraction/knowledge/domain-extractor.js.map +1 -1
  80. package/dist/src/graph/kg/resolution/knowledge-resolver.d.ts +3 -3
  81. package/dist/src/graph/kg/resolution/knowledge-resolver.d.ts.map +1 -1
  82. package/dist/src/graph/kg/resolution/knowledge-resolver.js +3 -2
  83. package/dist/src/graph/kg/resolution/knowledge-resolver.js.map +1 -1
  84. package/dist/src/graph/kg/surface/hook-injector.d.ts.map +1 -1
  85. package/dist/src/graph/kg/surface/hook-injector.js +2 -4
  86. package/dist/src/graph/kg/surface/hook-injector.js.map +1 -1
  87. package/dist/src/search/daemon-client.d.ts +3 -25
  88. package/dist/src/search/daemon-client.d.ts.map +1 -1
  89. package/dist/src/search/daemon-client.js +3 -25
  90. package/dist/src/search/daemon-client.js.map +1 -1
  91. package/dist/src/search/daemon-types.d.ts +30 -0
  92. package/dist/src/search/daemon-types.d.ts.map +1 -0
  93. package/dist/src/search/daemon-types.js +31 -0
  94. package/dist/src/search/daemon-types.js.map +1 -0
  95. package/dist/src/search/daemon.d.ts +2 -27
  96. package/dist/src/search/daemon.d.ts.map +1 -1
  97. package/dist/src/search/daemon.js +4 -60
  98. package/dist/src/search/daemon.js.map +1 -1
  99. package/dist/src/tools/wiki-search.d.ts.map +1 -1
  100. package/dist/src/tools/wiki-search.js +8 -2
  101. package/dist/src/tools/wiki-search.js.map +1 -1
  102. package/dist/src/utils/update-notices.js +12 -0
  103. package/dist/src/utils/update-notices.js.map +1 -1
  104. package/package.json +1 -3
@@ -0,0 +1,860 @@
1
+ ---
2
+ name: maestro-ralph-v2
3
+ description: Adaptive lifecycle orchestrator — compose, dispatch ralph-executor agent, evaluate decision, loop
4
+ argument-hint: "<intent> [-y] [--amend [change]] [--roadmap] | status | continue"
5
+ allowed-tools:
6
+ - read_file
7
+ - write_file
8
+ - edit_file
9
+ - shell
10
+ - find_files
11
+ - search
12
+ - invoke_skill
13
+ - ask_user
14
+ - delegate_subagent
15
+ ---
16
+ <!-- Open-standard mirror generated by scripts/build-agents-standard.mjs — do not edit; re-run after editing .claude/ source. -->
17
+
18
+ <purpose>
19
+ Adaptive lifecycle orchestrator: locate step → resolve args → load context → dispatch delegate_subagent(ralph-executor) per step (agent 调 `ralph next` + 执行) → extract signals → drift check → ralph complete → evaluate decision → next step → loop.
20
+
21
+ Session: `.workflow/.maestro/ralph-v2-{YYYYMMDD-HHmmss}/status.json`
22
+ </purpose>
23
+
24
+ <deferred_reading>
25
+ - [ralph-amend-goal.md](~/.maestro/workflows/ralph-amend-goal.md) — read when `--amend` flag active for goal amendment flow
26
+ </deferred_reading>
27
+
28
+ <context>
29
+ $ARGUMENTS — intent text, flags, or keywords.
30
+
31
+ **Parse:**
32
+ ```
33
+ -y flag → auto_confirm = true
34
+ --roadmap → wants_roadmap = true
35
+ --amend / -a → amend_mode = true
36
+ .md/.txt path → input_doc
37
+ status|continue → route keyword
38
+ Remaining → intent (amend_mode 时为 change_request)
39
+ ```
40
+
41
+ **State files**:
42
+ - `.workflow/state.json` — artifact registry
43
+ - `.workflow/.maestro/ralph-v2-*/status.json` — session state
44
+ </context>
45
+
46
+ <invariants>
47
+ 1. **Ralph-v2 owns the full loop** — locate step → resolve args → load context → dispatch agent → extract signals → drift → complete,全部在本命令内完成
48
+ 2. **One agent per step** — 每个执行 step 派发一个 executor agent,agent 执行完返回,主流程解析结果后决定下一步
49
+ 3. **Agent is a thin wrapper** — executor agent 调 `ralph next` 获取 skill prompt 并执行,返回输出;arg resolution、context loading、signal extraction、drift analysis、ralph complete 均由主流程完成
50
+ 4. **Synchronous dispatch** — delegate_subagent() 调用是同步的(等待返回),不需要 STOP/callback 模式
51
+ 5. **主流程调 `ralph complete`** — 每个 step 完成后由主流程调 `maestro ralph complete`,非 agent 上报
52
+ 6. **Decision evaluation inline** — decision 节点不 handoff,通过 `delegate_subagent()` 启动分析 Agent 在本循环内评估
53
+ 7. **No CLI delegation** — 本命令不使用 `maestro delegate`;执行和评估均通过 delegate_subagent() 完成
54
+ 8. **Decision delegates read-only** — 评估 Agent 通过 prompt 中的 CONSTRAINTS 约束为只读
55
+ 9. **执行 step 通过 `maestro ralph next` CLI 加载并内联执行**(由 execute Agent 完成)
56
+ 10. **status.json 是唯一真源** — 不生成 markdown 清单或侧文件
57
+ 11. **每个 step 必须 `completion_confirmed: true`** — 由 `maestro ralph complete N --status DONE`(或 DONE_WITH_CONCERNS)写入;CLI 是唯一合法写入路径
58
+ 12. **command_path 在 A_BUILD_STEPS 解析** — 通过 `maestro ralph skills --platform agent --json --quiet` 预校验
59
+ 13. **执行 step 加载契约** — 由 `maestro ralph next` CLI 在执行期完成
60
+ 14. **Decomposition is outcome-oriented** — sub-goals 为可观测交付,禁止 lifecycle 复刻
61
+ 15. **planning_mode governs arg granularity** — `unified` → skill args 无 `{phase}`;`independent` → 含 `{phase}`
62
+ 16. **task_decomposition 驱动 steps[] 动态生长** — `post-goal-audit` 按 unmet 子目标插入 scoped mini-loop
63
+ 17. **Invariant violation = BLOCK** — 违反上述任一 invariant 即阻断当前操作
64
+ 18. **Evaluate fallback 必须标记** — 评估 Agent 解析 verdict 失败时 fallback 为 "fix",MUST 在 decisions.ndjson 记录 `"parse_failed": true, "confidence_score": 0`
65
+ 19. **auto_confirm 单一来源** — `auto_confirm` 仅由用户 `-y` 标志设定
66
+ 20. **分解契约单一所有者** — `boundary_contract` / `task_decomposition` 由 session 创建者拥有
67
+ 21. **控制权优先级(范式治理)** — FSM 独占 session 生命周期 + step 排序 + retry/fix/escalate + cross-step decision 节点
68
+ </invariants>
69
+
70
+ <state_machine>
71
+
72
+ Chain-building states + 执行循环 states:
73
+
74
+ <states>
75
+ S_PARSE_ROUTE — 解析参数、路由入口
76
+ S_STATUS — 显示 session 进度
77
+ S_CONTINUE — 恢复执行
78
+ S_RESOLVE_PHASE — 解析 phase + phase_is_new + milestone PERSIST: session.phase, session.phase_is_new, session.milestone
79
+ S_INFER — 推断 lifecycle_position PERSIST: session.lifecycle_position, session.wants_roadmap
80
+ S_RESOLVE_SCOPE — 读 macro analyze conclusions.scope_verdict PERSIST: session.scope_verdict, session.analyze_macro_id
81
+ S_QUALITY_MODE — 决定质量管线模式 PERSIST: session.quality_mode
82
+ S_PLANNING_MODE — 决定统一/独立规划模式 PERSIST: session.planning_mode
83
+ S_DECOMPOSE — 边界澄清 + 执行准则 + 子目标清单 PERSIST: session.boundary_contract, .execution_criteria, .task_decomposition
84
+ S_BUILD_CHAIN — 构建步骤链(build rules 0-14) PERSIST: session.steps[]
85
+ S_CREATE_SESSION — 写 status.json PERSIST: session (全量)
86
+ S_CONFIRM — 用户确认
87
+
88
+ S_STEP_LOCATE — 找下一个 pending step PERSIST: —
89
+ S_STEP_RESOLVE — 解析占位符 + 丰富参数 PERSIST: step.args (enriched)
90
+ S_STEP_DISPATCH — 组装上下文 + 派发 executor agent 执行单步 PERSIST: step.agent_exec_name, step.status = "running"
91
+ S_STEP_ANALYZE — 提取信号 + 组装 completion 参数 PERSIST: —
92
+ S_STEP_DRIFT — 产物 vs 目标偏离分析 PERSIST: step.drift_score
93
+ S_STEP_COMPLETE — 调 `ralph complete` 上报 PERSIST: step.completion_*
94
+ S_DECISION_EVAL — 启动分析 Agent 评估质量门 PERSIST: —
95
+ S_APPLY_VERDICT — 应用裁决 PERSIST: session.steps[]
96
+ S_SESSION_DONE — 所有 step 完成 PERSIST: session.status
97
+ S_HANDLE_FAIL — 处理失败 PERSIST: step.status
98
+ S_AMEND_GOAL — 修改 running session 目标 PERSIST: session.task_decomposition, .boundary_contract, .goal_changelog, .steps[]
99
+ S_FALLBACK — 请求用户输入 PERSIST: —
100
+ </states>
101
+
102
+ <transitions>
103
+
104
+ S_PARSE_ROUTE:
105
+ → S_STATUS WHEN: intent == "status"
106
+ → S_CONTINUE WHEN: intent == "continue"
107
+ → S_AMEND_GOAL WHEN: amend_mode == true AND running session exists
108
+ → S_FALLBACK WHEN: amend_mode == true AND no running session
109
+ → S_DECISION_EVAL WHEN: running session with decision step in "running" status
110
+ → S_RESOLVE_PHASE WHEN: intent is non-empty
111
+ → S_FALLBACK WHEN: no intent AND no running session
112
+
113
+ S_STATUS:
114
+ → END DO: A_SHOW_STATUS
115
+
116
+ S_CONTINUE:
117
+ → S_STEP_LOCATE WHEN: running session found
118
+ → S_FALLBACK WHEN: no running session
119
+
120
+ S_AMEND_GOAL:
121
+ → S_STEP_LOCATE WHEN: change applied + user confirmed DO: A_AMEND_GOAL
122
+ → END WHEN: user cancels
123
+ GUARD: RISK_LEVEL=high → auto_confirm 无效
124
+
125
+ S_CREATE_SESSION:
126
+ → S_CONFIRM WHEN: not auto_confirm
127
+ → S_STEP_LOCATE WHEN: auto_confirm
128
+
129
+ S_CONFIRM:
130
+ → S_STEP_LOCATE WHEN: user confirms
131
+ → S_BUILD_CHAIN WHEN: user edits
132
+ → END WHEN: user cancels
133
+
134
+ S_STEP_LOCATE:
135
+ → S_STEP_RESOLVE WHEN: pending execution step found (step.decision == null)
136
+ → S_DECISION_EVAL WHEN: pending decision step found (step.decision != null)
137
+ → S_SESSION_DONE WHEN: no pending steps (all completed/skipped)
138
+ → S_HANDLE_FAIL WHEN: has failed step and no pending
139
+ → S_FALLBACK WHEN: no running session
140
+
141
+ S_STEP_RESOLVE:
142
+ → S_STEP_DISPATCH DO: A_STEP_RESOLVE_ARGS
143
+
144
+ S_STEP_DISPATCH:
145
+ → S_STEP_ANALYZE WHEN: agent returned output DO: A_STEP_DISPATCH
146
+ → S_HANDLE_FAIL WHEN: agent returned error/null DO: A_STEP_DISPATCH
147
+
148
+ S_STEP_ANALYZE:
149
+ → S_STEP_DRIFT WHEN: STATUS == DONE|DONE_WITH_CONCERNS DO: A_STEP_EXTRACT
150
+ → S_HANDLE_FAIL WHEN: STATUS == NEEDS_RETRY|BLOCKED DO: A_STEP_EXTRACT
151
+
152
+ S_STEP_DRIFT:
153
+ → S_STEP_COMPLETE WHEN: ALIGNED|MINOR_DRIFT DO: A_STEP_DRIFT_ANALYZE
154
+ → S_STEP_DISPATCH WHEN: MAJOR_DRIFT + not retried DO: A_STEP_DRIFT_ANALYZE (ralph retry + re-execute)
155
+ → S_STEP_COMPLETE WHEN: MAJOR_DRIFT + retried DO: A_STEP_DRIFT_ANALYZE (DONE_WITH_CONCERNS)
156
+
157
+ S_STEP_COMPLETE:
158
+ → S_STEP_LOCATE DO: A_STEP_COMPLETE (loop to next step)
159
+
160
+ S_DECISION_EVAL: (decision 节点 == `step.decision` 非空)
161
+ → S_APPLY_VERDICT WHEN: quality-gate (post-execute, post-business-test, post-review, post-test, post-frontend-verify)
162
+ DO: A_AGENT_EVALUATE
163
+ → S_APPLY_VERDICT WHEN: goal-gate (post-goal-audit)
164
+ DO: A_AGENT_GOAL_AUDIT
165
+ → S_APPLY_VERDICT WHEN: scope-gate (post-analyze-scope)
166
+ DO: A_SCOPE_EVALUATE
167
+ → S_APPLY_VERDICT WHEN: reground-gate (post-reground)
168
+ DO: A_AGENT_REGROUND
169
+ → S_APPLY_VERDICT WHEN: structural (post-milestone, post-debug-escalate)
170
+ DO: A_STRUCTURAL_EVALUATE
171
+
172
+ S_APPLY_VERDICT:
173
+ → S_STEP_LOCATE WHEN: verdict == "proceed" DO: A_APPLY_PROCEED
174
+ → S_STEP_LOCATE WHEN: post-goal-audit + has_unmet DO: A_APPLY_GOAL_FIX
175
+ → S_STEP_LOCATE WHEN: post-goal-audit + all_met + INTENT_ALIGNED=true DO: A_APPLY_GOAL_DONE
176
+ → END WHEN: post-goal-audit + all_met + INTENT_ALIGNED=false DO: A_REGROUND_HALT
177
+ → S_STEP_LOCATE WHEN: post-analyze-scope DO: A_APPLY_SCOPE_VERDICT
178
+ → S_STEP_LOCATE WHEN: verdict == "fix" DO: A_APPLY_FIX
179
+ → S_STEP_LOCATE WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE
180
+ → S_STEP_LOCATE WHEN: post-milestone + standard + next milestone DO: A_ADVANCE_MILESTONE
181
+ → END WHEN: post-milestone + standard + no next milestone
182
+ → END WHEN: post-milestone + adhoc DO: mark completed (set current_milestone = null)
183
+ → END WHEN: post-debug-escalate DO: A_PAUSE_ESCALATE
184
+ → END WHEN: post-reground + drifted + confidence >= 60 DO: A_REGROUND_HALT
185
+ → S_STEP_LOCATE WHEN: post-reground + aligned DO: A_APPLY_PROCEED
186
+ → S_STEP_LOCATE WHEN: post-reground + drifted + confidence < 60 DO: A_APPLY_PROCEED (标 LOW CONFIDENCE)
187
+ GUARD: retry_count >= max_retries → force escalate
188
+ GUARD: confidence_score < 60 AND proceed → override to fix
189
+ GUARD: confidence_score > 95 AND fix AND retry > 0 → suggest proceed
190
+ GUARD: auto_confirm → skip user prompt, apply adjusted verdict
191
+ GUARD: not auto_confirm → ask_user with override options
192
+ GUARD: post-reground + drifted + confidence >= 60 → A_REGROUND_HALT(auto_confirm 不跳过)
193
+
194
+ S_HANDLE_FAIL:
195
+ → S_STEP_LOCATE WHEN: auto + not retried DO: A_RETRY
196
+ → END WHEN: auto + retried DO: A_PAUSE_SESSION
197
+ → S_STEP_LOCATE WHEN: interactive + retry
198
+ → S_STEP_LOCATE WHEN: interactive + skip
199
+ → END WHEN: interactive + abort
200
+
201
+ S_SESSION_DONE:
202
+ → END DO: A_COMPLETE_SESSION
203
+
204
+ </transitions>
205
+
206
+ <actions>
207
+
208
+ ### A_CREATE_SESSION
209
+ 1. `session_id` format: `ralph-v2-{YYYYMMDD-HHmmss}`
210
+ 2. Additional fields: `execution_mode: "agent"`,无 `cli_tool` 字段
211
+ 3. Each step: `agent_exec_name: null`(执行 Agent 名称标识)
212
+ 4. Step mode/role/rule assigned per stage (see Stage Mapping table)
213
+
214
+ ### A_STEP_RESOLVE_ARGS
215
+
216
+ 解析占位符 + 丰富参数。在 `ralph next` 之前执行。
217
+
218
+ **1. Placeholder substitution:**
219
+
220
+ | Placeholder | Source |
221
+ |-------------|--------|
222
+ | `{phase}` | session.phase |
223
+ | `{milestone}` | session.milestone |
224
+ | `{intent}` | session.intent |
225
+ | `{description}` | session.intent (alias) |
226
+ | `{scratch_dir}` | session.context.scratch_dir or latest artifact path |
227
+ | `{plan_dir}` | session.context.plan_dir |
228
+ | `{analysis_dir}` | session.context.analysis_dir |
229
+ | `{issue_id}` | session.context.issue_id |
230
+ | `{milestone_num}` | session.context.milestone_num |
231
+
232
+ **2. Per-skill enrichment** (when args empty or minimal):
233
+
234
+ | Skill | Required context | Source |
235
+ |-------|-----------------|--------|
236
+ | maestro-brainstorm | topic | `"{intent}"` |
237
+ | maestro-roadmap | description | `"{intent}"` |
238
+ | maestro-analyze | phase or topic | `{phase}` or `"{intent}"` |
239
+ | maestro-plan | phase, --from, or --dir | see --from auto-injection below |
240
+ | maestro-execute | phase or --dir | see --from auto-injection below |
241
+ | quality-debug | gap context | Read previous step's error/gap |
242
+ | quality-* | phase | `{phase}` |
243
+
244
+ **3. --from auto-injection (phase-level artifact chaining):**
245
+
246
+ ```
247
+ Read state.json.artifacts(含 milestone_history 内归档 artifacts)
248
+ → filter by milestone={session.milestone} + phase={session.phase} + status=="completed"
249
+
250
+ plan step(含 {phase} 占位符,args 无 --from 且无 --dir):
251
+ 1. 查同 phase+milestone 最新 completed type=="analyze" artifact → id = ANL-xxx
252
+ 2. 命中 → args 追加 --from analyze:{id}
253
+ 3. 写 step.source_artifact_ref = "analyze:{id}"
254
+
255
+ execute step(含 {phase} 占位符,args 无 --dir):
256
+ 1. 查同 phase+milestone 最新 completed type=="plan" artifact → id = PLN-xxx, path = scratch/...
257
+ 2. 命中 → args 追加 --dir .workflow/scratch/{path}
258
+ 3. 写 step.source_artifact_ref = "plan:{id}"
259
+ ```
260
+
261
+ 兜底:查询无结果 → 不注入,由命令自身 discovery 逻辑处理。已有 `--from` 或 `--dir` 的 step 不覆盖。
262
+
263
+ **4. Goal context injection:**
264
+
265
+ 当 `step.goal_ref` 非空且 `session.task_decomposition` 存在时:
266
+ ```
267
+ goal = session.task_decomposition.find(g => g.id == step.goal_ref)
268
+ if goal:
269
+ goal_snippet = { id: goal.id, goal: goal.goal, done_when: goal.done_when,
270
+ boundary: goal.boundary, evidence: goal.evidence }
271
+ → 传递给 A_STEP_DISPATCH 注入 agent prompt
272
+ ```
273
+
274
+ **5. Write** enriched args + source_artifact_ref back to status.json.
275
+
276
+ ### A_STEP_DISPATCH
277
+
278
+ 加载前序产出 + 组装上下文 + 派发 executor agent 执行单步。Agent 内部调 `maestro ralph next` 获取 skill prompt 并执行。
279
+
280
+ **1. Load previous step context:**
281
+
282
+ - 读前一 completed step 的 `completion_summary` + `completion_caveats` + `completion_decisions` + `completion_deferred`
283
+ - 按 `session.context` 中的路径逐个 Read,提取与当前 step 相关的内容:
284
+
285
+ | 当前 stage | 加载什么 | Source |
286
+ |-----------|---------|--------|
287
+ | plan | analysis conclusions + scope_verdict | `{context.analysis_dir}/conclusions.json` |
288
+ | execute | task list + wave assignments | `{context.plan_dir}/TASK-*.json` |
289
+ | review | changed files + verification results | `{context.scratch_dir}/verification.json` |
290
+ | test | review findings | `review.json` |
291
+ | debug | error traces + failing test details | 前一 step 的 `completion_evidence` |
292
+ | brainstorm | grill report | `{context.grill_id}` report |
293
+
294
+ - Explore if needed — 产物指向代码位置但缺少上下文 → `maestro explore` 补充(仅 execute/debug/test 且有文件路径引用时)
295
+ - Accumulated signals — 遍历 ALL completed steps → 聚合 caveats + deferred
296
+
297
+ **2. Goal context pre-injection:**
298
+
299
+ - GUARD: `ralph_protocol_version >= "2"` → skip(session_anchor 已含 goal context)
300
+ - WHEN `ralph_protocol_version < "2"` 或缺失 AND `step.goal_ref` 非空 → 组装 `<goal_context>` 块注入 prompt:
301
+ ```
302
+ <goal_context>
303
+ Sub-goal: {goal.id} — {goal.goal}
304
+ Done when: {goal.done_when}
305
+ Boundary: {goal.boundary}
306
+ Evidence target: {goal.evidence}
307
+ Execution criteria: {session.execution_criteria joined by '; '}
308
+ </goal_context>
309
+ ```
310
+
311
+ **3. Resolve agent name:** `{stage_prefix}-{session_id_short}-{HHmmss}`
312
+
313
+ | Stage | Prefix |
314
+ |-------|--------|
315
+ | grill | `grl` |
316
+ | brainstorm | `brn` |
317
+ | analyze-macro | `anm` |
318
+ | analyze | `ana` |
319
+ | plan | `pln` |
320
+ | execute | `exe` |
321
+ | review | `rev` |
322
+ | test | `tst` |
323
+ | debug | `dbg` |
324
+ | Other | `run` |
325
+
326
+ **4. Dispatch:**
327
+
328
+ ```
329
+ delegate_subagent({
330
+ subagent_type: "ralph-executor",
331
+ name: "{resolved_agent_name}",
332
+ description: "执行 step {index}: {step.skill}",
333
+ prompt: `Session: {session_id}
334
+
335
+ {goal_context 块,仅 protocol < 2 时}
336
+
337
+ {loaded_step_context}
338
+ `
339
+ })
340
+ ```
341
+
342
+ Agent 内部调 `maestro ralph next --session {session_id}` 获取 skill prompt 并执行。
343
+
344
+ 5. Write `step.agent_exec_name` to status.json
345
+ 6. Display: `[{index}/{total}] ⟶ {step.skill} → Agent:{name}`
346
+ 7. Agent 同步返回 → `agent_output` = 返回文本;返回 null → STATUS=BLOCKED
347
+
348
+ ### A_STEP_EXTRACT
349
+
350
+ 从 agent 返回的执行输出中提取结构化信号,用于 completion 参数组装。
351
+
352
+ **1. Stage-specific signal extraction:**
353
+
354
+ | Stage | 提取什么 | 写入字段 |
355
+ |-------|---------|---------|
356
+ | analyze | `conclusions.json` scope_verdict + key_findings | `--summary`, context.analysis_dir |
357
+ | plan | TASK-*.json 数量 + 主要模块 + 波次 | `--summary`, context.plan_dir |
358
+ | execute | 修改文件数 + verification passed/failed | `--summary`, `--evidence`, context.scratch_dir |
359
+ | review | verdict + findings 数量 + severity | `--summary`, `--decisions` |
360
+ | test | pass/fail 统计 | `--summary`, `--evidence` |
361
+ | debug | root cause + 修复内容 | `--summary`, `--decisions` |
362
+ | grill | 核心质疑点数量 | `--summary`, `--caveats`, context.grill_id |
363
+ | brainstorm | 候选方案数 + 推荐方案 | `--summary`, `--decisions`, context.brainstorm_dir |
364
+
365
+ **2. Artifact scanning** — Use Glob 查找执行期间新增/修改的产物:
366
+
367
+ | Pattern | Signal |
368
+ |---------|--------|
369
+ | `conclusions.json` | `analysis_dir` |
370
+ | `TASK-*.json` | `plan_dir` |
371
+ | `verification.json` | `scratch_dir` |
372
+ | `review.json` | review stage |
373
+ | `test-results.json`, `uat.md` | test stage |
374
+ | `grill-report.md` | `grill_id` |
375
+ | `.brainstorming/*` | `brainstorm_dir` |
376
+
377
+ **3. Output text signal extraction** — 从执行输出文本中提取:
378
+
379
+ | Signal pattern | 写入 |
380
+ |----------------|------|
381
+ | `ANL-xxx` (artifact ID) | `session.analyze_macro_id` |
382
+ | `PLN-xxx` (artifact ID) | `context.plan_dir` |
383
+ | `BLP-xxx` (artifact ID) | `session.blueprint_id` |
384
+ | `scratch_dir:` 或 `.workflow/scratch/` 路径 | `context.scratch_dir` |
385
+ | `plan_dir:` 路径 | `context.plan_dir` |
386
+ | `PHASE: N` | `session.context.phase` |
387
+
388
+ **4. STATUS determination:**
389
+
390
+ | 条件 | STATUS |
391
+ |------|--------|
392
+ | Skill 正常完成 + 有产物 | `DONE` |
393
+ | 完成但有 warnings/concerns | `DONE_WITH_CONCERNS` |
394
+ | 执行出错但可重试(临时错误、网络问题) | `NEEDS_RETRY` |
395
+ | 执行出错且无法重试(schema 错误、command_path 不可达) | `BLOCKED` |
396
+ | Agent 返回 null(崩溃/超时) | `BLOCKED` |
397
+
398
+ **5. Compose completion params:**
399
+
400
+ | Param | 规则 | 组装方法 |
401
+ |-------|------|---------|
402
+ | `--summary` | MUST。动词开头,≤100 字 | `"<动词><做了什么>,<量化结果>"` |
403
+ | `--decisions` | SHOULD。每条一个架构/技术决策 | 从执行中做出的非显而易见的选择 |
404
+ | `--caveats` | SHOULD。后续 step 须知 | 发现但不属于本步解决的问题 |
405
+ | `--deferred` | SHOULD。推迟工作项 | 被主动推迟的项 |
406
+ | `--evidence` | SHOULD。验证产物路径 | 指向验证结果文件 |
407
+ | `--concerns` | COND。仅 DONE_WITH_CONCERNS 时 | CAVEATS 内容同时映射为 --concerns |
408
+
409
+ ### A_STEP_DRIFT_ANALYZE
410
+
411
+ 产物 vs 目标偏离分析。A_STEP_EXTRACT 后、A_STEP_COMPLETE 前执行。
412
+
413
+ **1. 收集对照基准:**
414
+
415
+ | 基准来源 | 取值 |
416
+ |---------|------|
417
+ | `step.goal_ref` → goal.done_when | 子目标完成条件 |
418
+ | `session.boundary_contract.definition_of_done` | 全局验收标准 |
419
+ | `session.execution_criteria` | 执行准则 |
420
+ | `session.intent` | 原始意图 |
421
+
422
+ **2. 对比评分:**
423
+
424
+ | 维度 | 检查 |
425
+ |------|------|
426
+ | 覆盖度 | 产物是否覆盖 goal.done_when 每个条件 |
427
+ | 方向性 | decisions 是否与 intent/boundary 一致 |
428
+ | 完整性 | 预期产物类型是否齐全 |
429
+
430
+ **drift_score:**
431
+ - `ALIGNED` — 全部维度通过
432
+ - `MINOR_DRIFT` — 小缺口,不影响后续
433
+ - `MAJOR_DRIFT` — 方向性偏离或关键产物缺失
434
+
435
+ **3. 修正动作:**
436
+
437
+ | drift_score | 动作 |
438
+ |-------------|------|
439
+ | ALIGNED | 正常进入 S_STEP_COMPLETE |
440
+ | MINOR_DRIFT | 偏离项追加到 caveats,正常 complete |
441
+ | MAJOR_DRIFT + 未重试 | `shell("maestro ralph retry {index}")` → 回到 S_STEP_DISPATCH 重执行(drift_correction 作修正上下文注入 prompt) |
442
+ | MAJOR_DRIFT + 已重试 | 以 DONE_WITH_CONCERNS complete |
443
+
444
+ **4. 写入:** `step.drift_score`, `step.drift_correction`
445
+
446
+ ### A_STEP_COMPLETE
447
+
448
+ 调 `ralph complete` 上报 + 传播上下文信号 + 循环。
449
+
450
+ 1. 使用 A_STEP_EXTRACT 组装的参数调用 `ralph complete`:
451
+ ```
452
+ shell("maestro ralph complete {index} --status DONE --summary \"{SUMMARY}\" [--evidence ...] [--decisions ...] [--caveats ...] [--deferred ...]")
453
+ ```
454
+ DONE_WITH_CONCERNS 时 caveats 同时映射 `--concerns`。BLOCKED 时用 `--reason`。
455
+
456
+ 2. **Context signals propagation** — 将关键信号写入 `status.json.context`:
457
+
458
+ | Signal | 写入字段 |
459
+ |--------|---------|
460
+ | `analysis_dir` | `context.analysis_dir` |
461
+ | `plan_dir` | `context.plan_dir` |
462
+ | `scratch_dir` | `context.scratch_dir` |
463
+ | `grill_id` | `context.grill_id` |
464
+ | `brainstorm_dir` | `context.brainstorm_dir` |
465
+ | `blueprint_dir` | `context.blueprint_dir` |
466
+ | `ANL-xxx` | `session.analyze_macro_id` |
467
+ | `BLP-xxx` | `session.blueprint_id` |
468
+ | `phase` | `session.context.phase` |
469
+
470
+ 3. Display: `[{index}/{total}] ✓ {step.skill} → {SUMMARY}`
471
+ 4. Loop back to S_STEP_LOCATE
472
+
473
+ ### A_AGENT_EVALUATE
474
+
475
+ 通过 Agent 在本循环内评估质量门。
476
+
477
+ 1. Resolve artifact dir: `.workflow/scratch/{artifact.path}/` with fallback glob
478
+ 2. Parse decision metadata: `{ decision, retry_count, max_retries }`
479
+ 3. Map result files:
480
+
481
+ | Decision | Files |
482
+ |----------|-------|
483
+ | post-execute | verification.json |
484
+ | post-business-test | .tests/auto-test/report.json |
485
+ | post-review | review.json |
486
+ | post-test | uat.md, .tests/test-results.json |
487
+ | post-frontend-verify | e2e-results.json |
488
+
489
+ 4. Dispatch evaluation Agent:
490
+ ```
491
+ delegate_subagent({
492
+ name: "eval-{decision}-{timestamp}",
493
+ description: "评估 {decision} 质量门",
494
+ prompt: "PURPOSE: 评估 {decision} 质量门结果
495
+ TASK: 读取以下结果文件 | 分析状态 | 评估严重性 | 给出建议
496
+ FILES: {result_file_paths}
497
+ SESSION: {session_dir}/status.json
498
+ EXPECTED: 输出以下格式:
499
+ ---VERDICT---
500
+ STATUS: PASS|FAIL|PARTIAL|BLOCKED
501
+ REASON: <一句话原因>
502
+ GAP_SUMMARY: <差距摘要>
503
+ CONFIDENCE: high|medium|low
504
+ CONFIDENCE_SCORE: 0-100
505
+ WEAKEST_DIMENSION: <最弱维度>
506
+ ---END---
507
+ CONSTRAINTS: 只评估不修改文件 | 置信度<60%倾向 fix | retry {n}/{max} 达上限必须 escalate"
508
+ })
509
+ ```
510
+ 5. On return: parse `---VERDICT---` block — STATUS must match strict enum `PASS|FAIL|PARTIAL|BLOCKED`; parse failure → fallback STATUS="fix", `parse_failed: true`, `confidence_score: 0` (invariant 18)
511
+ 6. Confidence adjustment: <60 + proceed → fix; >95 + fix + retry>0 → suggest proceed
512
+ 7. **Decision log**: Append to `{session_dir}/decisions.ndjson`:
513
+ ```json
514
+ { "id": "DEC-{timestamp}", "timestamp": "{ISO}", "source": "ralph-v2",
515
+ "node_id": "{step.decision}", "type": "quality-gate",
516
+ "verdict": "{adjusted_verdict}", "confidence_score": {N},
517
+ "parse_failed": false,
518
+ "close_call": {N>=50 && N<=70}, "summary": "{REASON}" }
519
+ ```
520
+
521
+ ### A_AGENT_GOAL_AUDIT
522
+
523
+ 通过 Agent 审计子目标完成情况。
524
+
525
+ 1. Read `session.task_decomposition` from status.json
526
+ 2. Dispatch audit Agent:
527
+ ```
528
+ delegate_subagent({
529
+ name: "goal-audit-{timestamp}",
530
+ description: "审计子目标完成情况",
531
+ prompt: "PURPOSE: 审计未完成子目标,判定 met / unmet
532
+ TASK:
533
+ 1. 读取 {session_dir}/status.json 中 task_decomposition 的 status!=done 子目标
534
+ 2. 打开 evidence 产物,对照 done_when 严格判定
535
+ 3. 输出 met / unmet,unmet 给出 gap + target_phase
536
+ 4. 对照 intent + definition_of_done 判定意图保真
537
+ CONTEXT:
538
+ status.json = {session_dir}/status.json
539
+ intent = {session.intent}
540
+ definition_of_done = {boundary_contract.definition_of_done}
541
+ execution_criteria = {execution_criteria}
542
+ boundary_contract = {boundary_contract}
543
+ EXPECTED:
544
+ ---VERDICT---
545
+ STATUS: all_met|has_unmet
546
+ INTENT_ALIGNED: true|false
547
+ UNMET: [{id:G2,gap:'...',target_phase:execute}, ...]
548
+ CONFIDENCE_SCORE: 0-100
549
+ ---END---
550
+ CONSTRAINTS: 只评估不修改文件 | 严格按 done_when 判定 | evidence 缺失→unmet"
551
+ })
552
+ ```
553
+ 3. On return: parse verdict, update task_decomposition status
554
+ 4. Append `{session_dir}/decisions.ndjson`:`{ "type": "goal-gate", "unmet_count": N, "unmet_ids": [...] }`
555
+ 5. Verdict routing: `all_met` + `INTENT_ALIGNED=true` → A_APPLY_GOAL_DONE;`all_met` + `INTENT_ALIGNED=false` → A_REGROUND_HALT;`has_unmet` → A_APPLY_GOAL_FIX
556
+ GUARD: retry_count >= max_retries AND still unmet → A_APPLY_ESCALATE
557
+
558
+ ### A_AGENT_REGROUND
559
+
560
+ 通过 Agent 执行意图保真检查。
561
+
562
+ 1. Read status.json:intent, boundary_contract, completed steps, done goals
563
+ 2. Dispatch reground Agent:
564
+ ```
565
+ delegate_subagent({
566
+ name: "reground-{timestamp}",
567
+ description: "意图保真检查",
568
+ prompt: "PURPOSE: 意图保真检查 — 对照 intent 验证累积执行是否漂移
569
+ TASK:
570
+ 1. 读取 intent + boundary_contract.definition_of_done
571
+ 2. 读取已完成 steps 的 completion_evidence + 已 done 子目标
572
+ 3. 判定累积产出是否仍服务 intent
573
+ 4. 输出 aligned / drifted + drift_description + corrective_action
574
+ CONTEXT:
575
+ status.json = {session_dir}/status.json
576
+ intent = {session.intent}
577
+ definition_of_done = {boundary_contract.definition_of_done}
578
+ in_scope = {boundary_contract.in_scope}
579
+ out_of_scope = {boundary_contract.out_of_scope}
580
+ goal_changelog = {session.goal_changelog ?? []}
581
+ EXPECTED:
582
+ ---VERDICT---
583
+ STATUS: aligned|drifted
584
+ DRIFT_DESCRIPTION: <空或具体描述>
585
+ CORRECTIVE_ACTION: <空或建议>
586
+ CONFIDENCE_SCORE: 0-100
587
+ ---END---
588
+ CONSTRAINTS: 只评估不修改文件 | aligned 阈值≥80% | 单个 step 触碰 out_of_scope→直接 drifted"
589
+ })
590
+ ```
591
+ 3. On return: parse verdict
592
+ 4. Append `{session_dir}/decisions.ndjson`
593
+ 5. Verdict routing:aligned → A_APPLY_PROCEED;drifted + confidence >= 60 → A_REGROUND_HALT;drifted + confidence < 60 → A_APPLY_PROCEED (LOW CONFIDENCE)
594
+
595
+ ### A_SCOPE_EVALUATE
596
+
597
+ 仅由 `post-analyze-scope` 决策节点触发。
598
+
599
+ 1. 定位刚完成的 macro analyze artifact → `analyze_macro_id`, `conclusions_path`
600
+ 2. 读取 `conclusions.scope_verdict`(`large | medium | small`),缺失 → `unknown`
601
+ 3. 写入 `session.scope_verdict` + `session.analyze_macro_id`
602
+ 4. Append `{session_dir}/decisions.ndjson`:`{ "type": "scope-gate", "source": "ralph-v2", "verdict": "{scope_verdict}", "analyze_macro_id": "{ANL_ID}" }`
603
+
604
+ ### A_STRUCTURAL_EVALUATE
605
+
606
+ **post-milestone:**
607
+ 1. Read state.json → resolve milestone type(default `"standard"`)
608
+ 2. Standard milestone:next milestone exists → insert lifecycle steps / complete
609
+ 3. Adhoc milestone(`type == "adhoc"`):always END,set `current_milestone = null`
610
+
611
+ **post-debug-escalate:** always → A_PAUSE_ESCALATE
612
+
613
+ ### A_SHOW_STATUS
614
+
615
+ 1. Find latest `ralph-v2-*` session(by created_at)
616
+ 2. Display: Session, Status, Position, Progress, Current step
617
+ 3. List steps: [✓] confirmed, [▸] current, [ ] pending, [◆] decision;执行 step 附 `command_scope` + `command_path`
618
+ 4. If `task_decomposition` present → 显示 sub-goals 进度(done/total)
619
+
620
+ ### A_APPLY_PROCEED / A_APPLY_FIX / A_APPLY_ESCALATE
621
+
622
+ - **A_APPLY_PROCEED**: Mark decision completed, write status.json
623
+ - **A_APPLY_FIX**: Insert fix-loop steps after current step(见 Fix-Loop Templates),reindex,increment retry_count
624
+ - **A_APPLY_ESCALATE**: Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`,reindex
625
+
626
+ ### A_APPLY_SCOPE_VERDICT
627
+
628
+ 依据 `session.scope_verdict` + `session.wants_roadmap` 重塑下游链路:
629
+
630
+ 1. 路径 A(`large` 且 `wants_roadmap`):保持 roadmap+analyze,`plan` 选 phase 列
631
+ 2. 路径 B(`medium`/`small`,或 `large` 非 `wants_roadmap`):删除未完成的 `roadmap` + `analyze` step,`plan` 改为 `--from analyze:{ANL_ID}`
632
+ 3. 路径 C(`unknown`):非 auto_confirm → ask_user;auto_confirm → 默认路径 B
633
+ 4. Reindex steps,标 decision completed
634
+
635
+ ### A_APPLY_GOAL_FIX / A_APPLY_GOAL_DONE
636
+
637
+ - **A_APPLY_GOAL_FIX**: 对每个 unmet 子目标插入 scoped mini-loop(plan --gaps + execute),`goal_ref` 标注,重新追加 `decision:post-goal-audit {retry+1}`
638
+ - **A_APPLY_GOAL_DONE**: set `task_decomposition[*].status="done"`, `completion_confirmed=true`, `task_decomposition_all_done=true`
639
+
640
+ ### A_ADVANCE_MILESTONE
641
+
642
+ 1. Update session: milestone, phase, reset passed_gates
643
+ 2. Insert full lifecycle steps for next milestone
644
+ 3. Reindex, write status.json
645
+
646
+ ### A_REGROUND_HALT / A_PAUSE_ESCALATE
647
+
648
+ - **A_REGROUND_HALT**: set `session.status = "paused"`,display drift warning + 恢复选项。auto_confirm 不跳过
649
+ - **A_PAUSE_ESCALATE**: set session paused,display "请人工介入",suggest continue
650
+
651
+ ### A_AMEND_GOAL
652
+
653
+ 运行中 session 的目标热修改。详细流程由 `<deferred_reading>` 加载 `ralph-amend-goal.md`。
654
+
655
+ | Phase | 行为 | 产出 |
656
+ |-------|------|------|
657
+ | 1. 快照 | 读 `task_decomposition` + `boundary_contract` + 已完成 steps 的 `completion_summary` | Display: 目标列表 + 进度 |
658
+ | 2. 解析 | `change_request` 非空 → 直接用;为空 → ask_user(修改/新增/移除/调整边界) | `change_type` + `change_request` |
659
+ | 3. Mini Grill | Agent 评估影响 | RISK_LEVEL + AFFECTED_GOALS + INVALIDATED_STEPS + NEW_GAPS |
660
+ | 4. 确认 | ask_user:应用并继续 / 仅改目标 / 取消 | 用户选择 |
661
+ | 5. 应用 | 归档旧目标(`superseded`)→ 写入新目标(`origin: CHG-xxx`)→ 重建链路 → write status.json | re-dispatch |
662
+
663
+ **Phase 3 Agent prompt:**
664
+ ```
665
+ delegate_subagent({
666
+ name: "amend-grill-{timestamp}",
667
+ description: "Amend impact analysis",
668
+ prompt: "PURPOSE: 评估目标修改对 running session 的影响
669
+ TASK:
670
+ 1. 读取 {session_dir}/status.json 的 task_decomposition + boundary_contract + 已完成 steps
671
+ 2. 分析 change_request 对既有目标/步骤的影响
672
+ 3. 判定 RISK_LEVEL (low/medium/high)
673
+ 4. 列出 AFFECTED_GOALS / INVALIDATED_STEPS / NEW_GAPS
674
+ CONTEXT:
675
+ change_request = {change_request}
676
+ change_type = {change_type}
677
+ session = {session_dir}/status.json
678
+ EXPECTED:
679
+ ---AMEND-VERDICT---
680
+ RISK_LEVEL: low|medium|high
681
+ AFFECTED_GOALS: [G1, G2, ...]
682
+ INVALIDATED_STEPS: [step indices]
683
+ NEW_GAPS: [gap descriptions]
684
+ RECOMMENDATION: <建议>
685
+ ---END---
686
+ CONSTRAINTS: 只评估不修改文件"
687
+ })
688
+ ```
689
+
690
+ GUARD: `RISK_LEVEL == high` → ask_user 不跳过(auto_confirm 无效)
691
+ GUARD: 已完成(`status: "done"`)的目标不可 supersede(skip + warn)
692
+ 旧目标标 `superseded`(`superseded_by` + `superseded_at`),新目标标 `origin: "CHG-xxx"`。`goal_changelog` 含完整 `before/after` + `impact_assessment`。
693
+
694
+ ### A_RETRY / A_PAUSE_SESSION / A_COMPLETE_SESSION
695
+
696
+ - **A_RETRY**: `shell("maestro ralph retry {index}")` — CLI 设 `step.retried = true`, `step.status = "pending"`, 清 `active_step_index`
697
+ - **A_PAUSE_SESSION**: `ralph complete N --status BLOCKED --reason "..."` — CLI 写 `session.status = "paused"`
698
+ - **A_COMPLETE_SESSION**: 校验所有 step `completion_confirmed == true` + `task_decomposition_all_done == true`(若存在),通过后写 `session.status = "completed"`
699
+
700
+ </actions>
701
+
702
+ </state_machine>
703
+
704
+ <appendix>
705
+
706
+ ### Stage Mapping
707
+
708
+ 执行 Agent 始终拥有完整工具集(read + write),由 skill 自身约束行为。Decision 评估 Agent 通过 prompt 中的 CONSTRAINTS 约束为只读。
709
+
710
+ | Stage | invoke_skill(independent) | invoke_skill(unified) | Decision after | quality_mode |
711
+ |-------|---------------------|-----------------|----------------|--------------|
712
+ | grill | `maestro-grill "{intent}"` | *(same)* | — | all |
713
+ | brainstorm | `maestro-brainstorm "{intent}"` | *(same)* | — | all |
714
+ | blueprint | `maestro-blueprint "{intent}"` | *(same)* | — | all |
715
+ | init | `maestro-init` | *(same)* | — | all |
716
+ | spec-setup | `spec-setup` | *(same)* | — | all |
717
+ | analyze-macro | `maestro-analyze "{intent}"` | *(same)* | `post-analyze-scope` | all |
718
+ | roadmap | `maestro-roadmap --from analyze:{id}` | *(same)* | — | all |
719
+ | analyze | `maestro-analyze {phase}` | `maestro-analyze` | — | all |
720
+ | plan | `maestro-plan {phase}` | `maestro-plan` | — | all |
721
+ | execute | `maestro-execute {phase}` | `maestro-execute` | `post-execute` | all |
722
+ | business-test | `quality-auto-test {phase}` | `quality-auto-test` | `post-business-test` | full only |
723
+ | review | `quality-review {phase}` | `quality-review` | `post-review` | all |
724
+ | test-gen | `quality-auto-test {phase}` | `quality-auto-test` | — | full / standard |
725
+ | test | `quality-test {phase}` | `quality-test` | `post-test` | full, standard |
726
+ | frontend-verify | `quality-test {phase} --frontend-verify` | `quality-test --frontend-verify` | `post-frontend-verify` | all (UI only) |
727
+ | milestone-audit | `maestro-milestone-audit` | *(same)* | — | all |
728
+ | goal-audit | *(decision-only)* | *(same)* | `post-goal-audit` | all |
729
+ | milestone-complete | `maestro-milestone-complete` | *(same)* | `post-milestone` | all |
730
+
731
+ Build rules 0-14 全部适用,包括 spec-setup 预检(rule 0.5)、grill auto_confirm 透传(rule 3.5)、frontend-verify UI 门控(rule 3.6)、re-grounding 插入(rule 5.5)等。
732
+
733
+ ### Session Schema
734
+
735
+ ```json
736
+ {
737
+ "session_id": "ralph-v2-{YYYYMMDD-HHmmss}",
738
+ "source": "ralph", "status": "running",
739
+ "execution_mode": "agent",
740
+ "ralph_protocol_version": "2",
741
+ "active_step_index": null,
742
+ "active_agent_name": null,
743
+ "intent": "", "lifecycle_position": "",
744
+ "phase": null, "phase_is_new": false,
745
+ "milestone": "",
746
+ "auto_mode": false,
747
+ "decomposition_owner": "ralph",
748
+
749
+ "quality_mode": "standard",
750
+ "planning_mode": "independent",
751
+ "scope_verdict": null,
752
+ "wants_roadmap": false,
753
+ "analyze_macro_id": null,
754
+ "blueprint_id": null,
755
+ "passed_gates": [],
756
+ "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
757
+ "analysis_dir": null, "brainstorm_dir": null, "blueprint_dir": null },
758
+ "steps": [{
759
+ "index": 0,
760
+ "skill": "",
761
+ "args": "",
762
+ "stage": "",
763
+ "scope": null,
764
+ "decision": null,
765
+ "retry_count": 0,
766
+ "max_retries": 2,
767
+ "command_scope": "global|project|missing|null",
768
+ "command_path": "<absolute path> | null",
769
+ "milestone_id": null,
770
+ "source_artifact_ref": null,
771
+ "status": "pending|running|completed|skipped|failed",
772
+ "goal_ref": null,
773
+ "completion_confirmed": false,
774
+ "completion_status": null,
775
+ "completion_evidence": null,
776
+ "completion_summary": null,
777
+ "completion_decisions": null,
778
+ "completion_caveats": null,
779
+ "completion_deferred": null,
780
+ "completed_at": null,
781
+ "deferred_reads": [],
782
+ "load": null,
783
+ "agent_exec_name": null,
784
+ "artifacts_produced": [],
785
+ "drift_score": null,
786
+ "drift_correction": null
787
+ }],
788
+ "waves": [], "current_step": 0,
789
+
790
+ "boundary_contract": {
791
+ "in_scope": [], "out_of_scope": [], "constraints": [], "definition_of_done": ""
792
+ },
793
+ "execution_criteria": [],
794
+ "task_decomposition": [
795
+ { "id": "G1", "goal": "", "boundary": "", "done_when": "",
796
+ "evidence": "", "lifecycle": [], "status": "pending|done|superseded",
797
+ "completion_confirmed": false, "completed_at": null,
798
+ "superseded_by": null, "superseded_at": null, "origin": null }
799
+ ],
800
+ "task_decomposition_all_done": false,
801
+
802
+ "goal_changelog": [
803
+ { "id": "CHG-001", "timestamp": "{ISO}",
804
+ "change_type": "modify|add|remove|boundary",
805
+ "reason": "",
806
+ "impact_assessment": { "risk_level": "low|medium|high",
807
+ "invalidated_steps": [], "new_steps_inserted": 0 },
808
+ "before": { "goals": [{"id":"G1","goal":"...","done_when":"..."}] },
809
+ "after": { "goals": [{"id":"G1v2","goal":"...","done_when":"..."}] } }
810
+ ]
811
+ }
812
+ ```
813
+
814
+ ### Fix-Loop Templates
815
+
816
+ 6 套 fix-loop templates(post-execute / post-business-test / post-review / post-test / post-frontend-verify / post-goal-audit)。插入的 step 通过 A_STEP_DISPATCH 派发 executor agent 逐步执行,由主流程调 `ralph complete` 上报。
817
+
818
+ ### Error Codes
819
+
820
+ E001–E006, W001–W004 适用。Agent 新增:
821
+
822
+ | Code | Severity | Description | Recovery |
823
+ |------|----------|-------------|----------|
824
+ | E014 | error | Agent execution failed (Agent returned null) | Retry once, then BLOCKED |
825
+ | E016 | error | Evaluation Agent verdict parse failed | Fallback fix + parse_failed: true |
826
+
827
+ ### Success Criteria
828
+
829
+ - [ ] ralph-v2 owns full step loop: locate → resolve → dispatch → extract → drift → complete → next
830
+ - [ ] One agent per step — `delegate_subagent({ subagent_type: "ralph-executor" })` 每步派发一个
831
+ - [ ] Agent 内调 `maestro ralph next` 获取 skill prompt 并执行,返回执行输出
832
+ - [ ] 主流程调 `maestro ralph complete` 上报(非 agent 上报)
833
+ - [ ] 主流程负责 arg resolution、context loading、signal extraction、drift analysis
834
+ - [ ] Agent 返回执行输出文本,主流程从中提取信号和状态
835
+ - [ ] Agent 崩溃(返回 null)→ STATUS=BLOCKED,转 S_HANDLE_FAIL
836
+ - [ ] 无 STOP/callback 模式 — delegate_subagent() 同步等待返回
837
+ - [ ] Decision evaluation 通过 delegate_subagent() 同步完成
838
+ - [ ] Verdict 解析保持 `---VERDICT---` 格式,parse 失败 → fallback fix + parse_failed: true
839
+ - [ ] decisions.ndjson 追加:source 字段为 `"ralph-v2"`
840
+ - [ ] Session schema: `execution_mode: "agent"`,`agent_exec_name`(执行 Agent 名称标识),含 `artifacts_produced`
841
+ - [ ] Chain building(S_RESOLVE_PHASE through S_BUILD_CHAIN)自包含执行
842
+ - [ ] A_STEP_DISPATCH 含前序产出加载(滑动窗口 5 step + accumulated signals + stage-specific artifacts)
843
+ - [ ] Agent name 含 stage prefix(grl/brn/anm/ana/pln/exe/rev/tst/dbg)
844
+ - [ ] `--summary` 在 DONE/DONE_WITH_CONCERNS 时为 MUST(动词开头,≤100 字)
845
+ - [ ] CAVEATS 在 DONE_WITH_CONCERNS 时同时映射 --concerns
846
+ - [ ] A_STEP_EXTRACT 从 agent 输出提取 artifact IDs、path signals、phase signals
847
+ - [ ] A_STEP_DRIFT_ANALYZE:ALIGNED/MINOR_DRIFT → complete;MAJOR_DRIFT+未重试 → retry;MAJOR_DRIFT+已重试 → DONE_WITH_CONCERNS
848
+ - [ ] A_STEP_COMPLETE 将 context signals 写入 status.json.context
849
+ - [ ] A_AMEND_GOAL:完整 5 步流程 + deferred_reading ralph-amend-goal.md + Agent mini grill 含完整 prompt
850
+ - [ ] 旧目标标 superseded(superseded_by + superseded_at),新目标 origin: "CHG-xxx"
851
+ - [ ] goal_changelog 含完整 before/after + impact_assessment
852
+ - [ ] blueprint_id session 字段支持 --from blueprint:{BLP_ID} 路径
853
+ - [ ] spec-setup 预检(build rule 0.5)
854
+ - [ ] post-milestone adhoc 分支:mark completed + set current_milestone = null
855
+ - [ ] post-reground + drifted + confidence < 60 → A_APPLY_PROCEED (LOW CONFIDENCE)
856
+ - [ ] Fix-loop 插入的 step 通过 A_STEP_DISPATCH 逐步执行
857
+ - [ ] re-grounding 3-step 插入规则(build rule 5.5)不变
858
+ - [ ] A_REGROUND_HALT 漂移熔断(auto_confirm 不跳过)不变
859
+
860
+ </appendix>