maestro-flow 0.4.7 → 0.4.9

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 (136) hide show
  1. package/.claude/commands/maestro-ralph.md +548 -377
  2. package/.claude/commands/maestro.md +220 -191
  3. package/.codex/skills/maestro/SKILL.md +495 -462
  4. package/.codex/skills/maestro-ralph/SKILL.md +491 -339
  5. package/dashboard/dist/assets/{ArtifactsPage-CVh0Z2I2.js → ArtifactsPage-BLvAqQlQ.js} +1 -1
  6. package/dashboard/dist/assets/{ChatInput-CBI3qHQQ.js → ChatInput-DU9YGZKX.js} +1 -1
  7. package/dashboard/dist/assets/{ChatPage-BjJ9CYox.js → ChatPage-DYHfheXC.js} +1 -1
  8. package/dashboard/dist/assets/{CollabPage-CprGGO9y.js → CollabPage-CSlmvEa-.js} +1 -1
  9. package/dashboard/dist/assets/{ExecutionPanel-CClxD7cH.js → ExecutionPanel-RYWf0dYC.js} +1 -1
  10. package/dashboard/dist/assets/{KanbanPage-copqjdPg.js → KanbanPage-N55Iv0-X.js} +1 -1
  11. package/dashboard/dist/assets/{MaestroCoordinatePage-CioZjQ9N.js → MaestroCoordinatePage-BxwZ6yy5.js} +1 -1
  12. package/dashboard/dist/assets/{MarkdownRenderer-CtUhoxCT.js → MarkdownRenderer-ZGtOY7Ti.js} +1 -1
  13. package/dashboard/dist/assets/{McpPage-BcPPcJpr.js → McpPage-Im6s4pGR.js} +1 -1
  14. package/dashboard/dist/assets/{MeetingRoomPage-BgmAKxU-.js → MeetingRoomPage-CxHRn1xx.js} +1 -1
  15. package/dashboard/dist/assets/{OutputPanel-DgT3gMyp.js → OutputPanel-DaL8c1i5.js} +1 -1
  16. package/dashboard/dist/assets/{ProblemsPanel-BmG7rxoG.js → ProblemsPanel-BQTd5812.js} +1 -1
  17. package/dashboard/dist/assets/{RequirementBoardPage-k8YoeQ0r.js → RequirementBoardPage-22y9u1qh.js} +1 -1
  18. package/dashboard/dist/assets/{RequirementPage-Da2354px.js → RequirementPage-_mO743Xm.js} +1 -1
  19. package/dashboard/dist/assets/{RoomsPage-BtqDiYaU.js → RoomsPage-CExTbOGr.js} +1 -1
  20. package/dashboard/dist/assets/{SpecsPage-ByPVH_M3.js → SpecsPage-gr4KX51-.js} +1 -1
  21. package/dashboard/dist/assets/{TeamsPage-sFDLN30L.js → TeamsPage-BxEXLb5g.js} +1 -1
  22. package/dashboard/dist/assets/{TreeBrowser-oEx8YJXV.js → TreeBrowser-CVtPF5C9.js} +1 -1
  23. package/dashboard/dist/assets/{WorkflowPage-JrX7CVHh.js → WorkflowPage-BoN18Lhs.js} +1 -1
  24. package/dashboard/dist/assets/{arrow-left-DYvgSdIH.js → arrow-left-C5ROg97G.js} +1 -1
  25. package/dashboard/dist/assets/{check-jcgYBWVR.js → check-Bs8PM0tQ.js} +1 -1
  26. package/dashboard/dist/assets/{chevron-right-DvZ5sMOg.js → chevron-right-SmErd_1F.js} +1 -1
  27. package/dashboard/dist/assets/{circle-DYT-zoRZ.js → circle-CjpslL_D.js} +1 -1
  28. package/dashboard/dist/assets/{circle-alert-Bfbv3gt4.js → circle-alert-CuzAg2fd.js} +1 -1
  29. package/dashboard/dist/assets/{circle-check-D82WnpbI.js → circle-check-BIkDU5D5.js} +1 -1
  30. package/dashboard/dist/assets/{circle-check-big-CPVD1GKF.js → circle-check-big-CYctV8bK.js} +1 -1
  31. package/dashboard/dist/assets/{code-B3bKFGI4.js → code-DoB7rfxt.js} +1 -1
  32. package/dashboard/dist/assets/{columns-3-BeMAQCix.js → columns-3-Ch5KIyRa.js} +1 -1
  33. package/dashboard/dist/assets/{download-BCtpoWYB.js → download-DadtG2Nr.js} +1 -1
  34. package/dashboard/dist/assets/{folder-CTj6SNNu.js → folder-B8ODoZfb.js} +1 -1
  35. package/dashboard/dist/assets/{index-BxR_3IbJ.js → index-BL4h1OKY.js} +1 -1
  36. package/dashboard/dist/assets/{index-DpcPd-UG.js → index-DQIlX2w_.js} +4 -4
  37. package/dashboard/dist/assets/{index-CWBJLu42.js → index-DaFwSmVJ.js} +10 -10
  38. package/dashboard/dist/assets/{list-BMv8pIQn.js → list-CI-XIPZh.js} +1 -1
  39. package/dashboard/dist/assets/{loader-DdM4VOgF.js → loader-DpdMoQvh.js} +1 -1
  40. package/dashboard/dist/assets/{minus-D15s2E__.js → minus-BVbfXGrC.js} +1 -1
  41. package/dashboard/dist/assets/{pen-line-DO6o4xWz.js → pen-line-CR8GaHt-.js} +1 -1
  42. package/dashboard/dist/assets/{pencil-qGxg9jOe.js → pencil-I7GE0y29.js} +1 -1
  43. package/dashboard/dist/assets/{proxy-DOffTzwA.js → proxy-CcYyZZWI.js} +1 -1
  44. package/dashboard/dist/assets/{refresh-cw-C9UNdLCy.js → refresh-cw-BG9V_T4R.js} +1 -1
  45. package/dashboard/dist/assets/{rows-2-CifAA5SL.js → rows-2-DP6NjQFk.js} +1 -1
  46. package/dashboard/dist/assets/{search-pe7pU1YN.js → search-b78eLlw2.js} +1 -1
  47. package/dashboard/dist/assets/{shallow-r7YynQYA.js → shallow-CJEesgtu.js} +1 -1
  48. package/dashboard/dist/assets/{table-Bh772iIw.js → table-B_lk-a1d.js} +1 -1
  49. package/dashboard/dist/assets/{team-types-C_HqX2p2.js → team-types-Se7f9LfJ.js} +1 -1
  50. package/dashboard/dist/assets/{terminal-EpmtGBlw.js → terminal-DXx4tvzq.js} +1 -1
  51. package/dashboard/dist/assets/{trash-2-Xen46iNQ.js → trash-2-CVh9mnRj.js} +1 -1
  52. package/dashboard/dist/assets/{users-BLueDPxF.js → users-Da9zGME5.js} +1 -1
  53. package/dashboard/dist/assets/{zap-DsQCPF61.js → zap-C0zaC7gJ.js} +1 -1
  54. package/dashboard/dist/index.html +1 -1
  55. package/dashboard/dist-server/dashboard/src/server/agents/adapter-factory.js +4 -0
  56. package/dashboard/dist-server/dashboard/src/server/agents/adapter-factory.js.map +1 -1
  57. package/dashboard/dist-server/dashboard/src/server/agents/agy-adapter.d.ts +39 -0
  58. package/dashboard/dist-server/dashboard/src/server/agents/agy-adapter.js +423 -0
  59. package/dashboard/dist-server/dashboard/src/server/agents/agy-adapter.js.map +1 -0
  60. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.js +25 -33
  61. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.js.map +1 -1
  62. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.test.js +9 -3
  63. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.test.js.map +1 -1
  64. package/dashboard/dist-server/dashboard/src/server/agents/codex-app-server-adapter.js +5 -2
  65. package/dashboard/dist-server/dashboard/src/server/agents/codex-app-server-adapter.js.map +1 -1
  66. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.d.ts +6 -0
  67. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.js +129 -8
  68. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.js.map +1 -1
  69. package/dashboard/dist-server/dashboard/src/server/agents/gemini-a2a-adapter.js +6 -3
  70. package/dashboard/dist-server/dashboard/src/server/agents/gemini-a2a-adapter.js.map +1 -1
  71. package/dashboard/dist-server/dashboard/src/server/agents/gemini-a2a-adapter.test.js +7 -1
  72. package/dashboard/dist-server/dashboard/src/server/agents/gemini-a2a-adapter.test.js.map +1 -1
  73. package/dashboard/dist-server/dashboard/src/server/agents/opencode-adapter.d.ts +2 -0
  74. package/dashboard/dist-server/dashboard/src/server/agents/opencode-adapter.js +40 -15
  75. package/dashboard/dist-server/dashboard/src/server/agents/opencode-adapter.js.map +1 -1
  76. package/dashboard/dist-server/dashboard/src/server/agents/process-tree-kill.d.ts +1 -0
  77. package/dashboard/dist-server/dashboard/src/server/agents/process-tree-kill.js +59 -0
  78. package/dashboard/dist-server/dashboard/src/server/agents/process-tree-kill.js.map +1 -0
  79. package/dashboard/dist-server/dashboard/src/server/agents/process-tree-kill.test.d.ts +1 -0
  80. package/dashboard/dist-server/dashboard/src/server/agents/process-tree-kill.test.js +78 -0
  81. package/dashboard/dist-server/dashboard/src/server/agents/process-tree-kill.test.js.map +1 -0
  82. package/dashboard/dist-server/dashboard/src/server/agents/stale-handler.d.ts +25 -0
  83. package/dashboard/dist-server/dashboard/src/server/agents/stale-handler.js +40 -0
  84. package/dashboard/dist-server/dashboard/src/server/agents/stale-handler.js.map +1 -0
  85. package/dashboard/dist-server/dashboard/src/server/agents/stale-handler.test.d.ts +1 -0
  86. package/dashboard/dist-server/dashboard/src/server/agents/stale-handler.test.js +89 -0
  87. package/dashboard/dist-server/dashboard/src/server/agents/stale-handler.test.js.map +1 -0
  88. package/dashboard/dist-server/dashboard/src/server/agents/stream-json-adapter.js +19 -8
  89. package/dashboard/dist-server/dashboard/src/server/agents/stream-json-adapter.js.map +1 -1
  90. package/dashboard/dist-server/dashboard/src/server/agents/stream-monitor.d.ts +6 -0
  91. package/dashboard/dist-server/dashboard/src/server/agents/stream-monitor.js +7 -1
  92. package/dashboard/dist-server/dashboard/src/server/agents/stream-monitor.js.map +1 -1
  93. package/dashboard/dist-server/dashboard/src/server/agents/stream-monitor.test.d.ts +1 -0
  94. package/dashboard/dist-server/dashboard/src/server/agents/stream-monitor.test.js +46 -0
  95. package/dashboard/dist-server/dashboard/src/server/agents/stream-monitor.test.js.map +1 -0
  96. package/dashboard/dist-server/dashboard/src/shared/constants.js +2 -0
  97. package/dashboard/dist-server/dashboard/src/shared/constants.js.map +1 -1
  98. package/dashboard/dist-server/shared/agent-types.d.ts +7 -1
  99. package/dist/shared/agent-types.d.ts +7 -1
  100. package/dist/shared/agent-types.d.ts.map +1 -1
  101. package/dist/src/agents/cli-agent-runner.d.ts +3 -0
  102. package/dist/src/agents/cli-agent-runner.d.ts.map +1 -1
  103. package/dist/src/agents/cli-agent-runner.js +4 -0
  104. package/dist/src/agents/cli-agent-runner.js.map +1 -1
  105. package/dist/src/commands/delegate.d.ts +2 -0
  106. package/dist/src/commands/delegate.d.ts.map +1 -1
  107. package/dist/src/commands/delegate.js +18 -0
  108. package/dist/src/commands/delegate.js.map +1 -1
  109. package/dist/src/commands/hooks.d.ts +64 -0
  110. package/dist/src/commands/hooks.d.ts.map +1 -1
  111. package/dist/src/commands/hooks.js +107 -0
  112. package/dist/src/commands/hooks.js.map +1 -1
  113. package/dist/src/commands/install.d.ts.map +1 -1
  114. package/dist/src/commands/install.js +17 -3
  115. package/dist/src/commands/install.js.map +1 -1
  116. package/dist/src/commands/update.d.ts.map +1 -1
  117. package/dist/src/commands/update.js +53 -0
  118. package/dist/src/commands/update.js.map +1 -1
  119. package/dist/src/config/cli-tools-config.d.ts +22 -5
  120. package/dist/src/config/cli-tools-config.d.ts.map +1 -1
  121. package/dist/src/config/cli-tools-config.js +77 -32
  122. package/dist/src/config/cli-tools-config.js.map +1 -1
  123. package/dist/src/config/cli-tools-defaults.json +2 -1
  124. package/dist/src/core/component-defs.d.ts.map +1 -1
  125. package/dist/src/core/component-defs.js +53 -0
  126. package/dist/src/core/component-defs.js.map +1 -1
  127. package/dist/src/tui/install-ui/InstallExecution.d.ts.map +1 -1
  128. package/dist/src/tui/install-ui/InstallExecution.js +5 -3
  129. package/dist/src/tui/install-ui/InstallExecution.js.map +1 -1
  130. package/dist/src/utils/update-notices.d.ts +62 -0
  131. package/dist/src/utils/update-notices.d.ts.map +1 -0
  132. package/dist/src/utils/update-notices.js +178 -0
  133. package/dist/src/utils/update-notices.js.map +1 -0
  134. package/package.json +82 -82
  135. package/shared/agent-types.ts +237 -231
  136. package/workflows/agy-instructions.md +124 -0
@@ -1,377 +1,548 @@
1
- ---
2
- name: maestro-ralph
3
- description: Use when the optimal command sequence is unclear and needs automated state-based determination
4
- argument-hint: "<intent> [-y] | status | continue"
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 decision engine for the maestro workflow lifecycle.
17
- Reads project state → infers position → builds adaptive chain → delegates execution.
18
-
19
- Entry points:
20
- - **`/maestro-ralph "intent"`** — New session: infer → build → execute
21
- - **`/maestro-ralph continue`** — Resume via maestro-ralph-execute
22
- - **`/maestro-ralph status`** — Display session progress
23
-
24
- Three node types:
25
- - **internal**: `Skill()` call (synchronous, lightweight)
26
- - **external**: `maestro delegate --to claude` (context-isolated, heavy computation)
27
- - **decision**: Hand back to ralph for re-evaluation (adaptive branching)
28
-
29
- Key difference from maestro coordinator:
30
- - maestro: static chain → one-time selection → runs all steps
31
- - ralph: living chain → decision nodes re-evaluate → chain grows/shrinks dynamically
32
-
33
- Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
34
- Mutual invocation with `/maestro-ralph-execute` forms a self-perpetuating work loop.
35
- </purpose>
36
-
37
- <context>
38
- $ARGUMENTS — intent text, flags, or keywords.
39
-
40
- **Parse:**
41
- ```
42
- -y flag → auto_confirm = true
43
- .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
44
- Remaining intent
45
- ```
46
-
47
- **State files:**
48
- - `.workflow/state.json` — artifact registry, milestones, phases
49
- - `.workflow/roadmap.md` — milestone/phase structure
50
- - `.workflow/.maestro/ralph-*/status.json` — ralph session state
51
- </context>
52
-
53
- <invariants>
54
- 1. **Ralph never executes steps** — only creates sessions and evaluates decisions
55
- 2. **Handoff via Skill("maestro-ralph-execute")** — at session creation and after decision evaluation
56
- 3. **Decision delegates read-only** — `maestro delegate --role analyze --mode analysis`
57
- 4. **External CLI call** — external spawns full Claude Code session executing the skill command
58
- 5. **Delegate sessions non-interactive** — all external skills MUST append `-y` to args inside the prompt
59
- </invariants>
60
-
61
- <state_machine>
62
-
63
- <states>
64
- S_PARSE_ROUTE — 解析参数、路由入口 PERSIST: —
65
- S_STATUS — 显示 session 进度 PERSIST: —
66
- S_CONTINUE — 恢复执行 PERSIST: —
67
- S_INFER — 读 state.json、推断生命周期位置 PERSIST: session.lifecycle_position
68
- S_RESOLVE_PHASE 解析目标 phase PERSIST: session.phase
69
- S_BUILD_CHAIN 构建步骤链 PERSIST: session.steps[]
70
- S_CREATE_SESSION 写 status.json PERSIST: session (全量)
71
- S_CONFIRM 用户确认 PERSIST:
72
- S_DISPATCH 移交 maestro-ralph-execute PERSIST:
73
- S_DECISION_EVAL 委托评估质量门 PERSIST:
74
- S_APPLY_VERDICT 应用裁决 + 插入命令 PERSIST: session.steps[], session.passed_gates[]
75
- S_FALLBACK 请求用户输入 PERSIST:
76
- </states>
77
-
78
- <transitions>
79
-
80
- S_PARSE_ROUTE:
81
- → S_STATUS WHEN: intent == "status"
82
- → S_CONTINUE WHEN: intent == "continue"
83
- → S_DECISION_EVAL WHEN: running session with decision step in "running" status
84
- → S_INFER WHEN: intent is non-empty
85
- → S_FALLBACK WHEN: no intent AND no running session
86
-
87
- S_STATUS:
88
- END DO: A_SHOW_STATUS
89
-
90
- S_CONTINUE:
91
- → S_DISPATCH WHEN: running session found
92
- → S_FALLBACK WHEN: no running session DO: display "无运行中的 ralph 会话"
93
-
94
- S_INFER:
95
- → S_RESOLVE_PHASE WHEN: position resolved DO: A_INFER_POSITION
96
- S_FALLBACK WHEN: cannot infer
97
-
98
- S_RESOLVE_PHASE:
99
- → S_BUILD_CHAIN WHEN: phase resolved or null DO: A_RESOLVE_PHASE
100
- S_FALLBACK WHEN: ambiguous
101
- GUARD: auto_confirm does NOT skip phase ambiguity
102
-
103
- S_BUILD_CHAIN:
104
- S_CREATE_SESSION DO: A_BUILD_STEPS
105
-
106
- S_CREATE_SESSION:
107
- → S_CONFIRM WHEN: not auto_confirm DO: A_CREATE_SESSION
108
- → S_DISPATCH WHEN: auto_confirm DO: A_CREATE_SESSION
109
-
110
- S_CONFIRM:
111
- S_DISPATCH WHEN: user selects "Proceed"
112
- S_BUILD_CHAIN WHEN: user selects "Edit"
113
- → END WHEN: user selects "Cancel"
114
-
115
- S_DISPATCH:
116
- → END DO: Skill({ skill: "maestro-ralph-execute" })
117
-
118
- S_DECISION_EVAL:
119
- S_APPLY_VERDICT WHEN: quality-gate (post-verify, post-business-test, post-review, post-test)
120
- DO: A_DELEGATE_EVALUATE
121
- → S_APPLY_VERDICT WHEN: structural (post-milestone, post-debug-escalate)
122
- DO: A_STRUCTURAL_EVALUATE
123
-
124
- S_APPLY_VERDICT:
125
- → S_DISPATCH WHEN: verdict == "proceed" DO: A_APPLY_PROCEED
126
- S_DISPATCH WHEN: verdict == "fix" DO: A_APPLY_FIX
127
- S_DISPATCH WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE
128
- → S_DISPATCH WHEN: post-milestone + next milestone DO: A_ADVANCE_MILESTONE
129
- → END WHEN: post-milestone + no next milestone DO: mark completed
130
- END WHEN: post-debug-escalate (always STOP) DO: A_PAUSE_ESCALATE
131
- GUARD: retry_count >= max_retries → force escalate
132
- GUARD: confidence_score < 60 AND proceed → override to fix
133
- GUARD: confidence_score > 95 AND fix AND retry > 0 → suggest proceed
134
- GUARD: auto_confirm skip user prompt, apply adjusted verdict
135
- GUARD: not auto_confirm → AskUserQuestion with override options
136
-
137
- S_FALLBACK:
138
- S_PARSE_ROUTE WHEN: user provides input DO: AskUserQuestion
139
- END WHEN: user cancels
140
-
141
- </transitions>
142
-
143
- <actions>
144
-
145
- ### A_SHOW_STATUS
146
-
147
- 1. Find latest ralph session (by created_at)
148
- 2. Display: Session, Status, Position, Progress, Current step
149
- 3. List steps: [✓] completed, [▸] current, [ ] pending, [◆] decision
150
-
151
- ### A_INFER_POSITION
152
-
153
- **Intent-based override:** brainstorm/头脑风暴/探索/ideate/设计思路 position = `brainstorm`
154
-
155
- **Bootstrap detection:**
156
-
157
- | Condition | Position |
158
- |-----------|----------|
159
- | No `.workflow/` + no source files | `brainstorm` |
160
- | No `.workflow/` + has source files | `init` |
161
- | Has `.workflow/` but no state.json | `init` |
162
- | Has state.json | artifact-based inference |
163
-
164
- **Artifact-based inference:** Filter by current_milestone + target phase:
165
-
166
- | Latest artifact type | Position |
167
- |---------------------|----------|
168
- | no milestones or no roadmap.md | `roadmap` |
169
- | none for phase | `analyze` |
170
- | analyze | `plan` |
171
- | plan | `execute` |
172
- | execute | `verify` |
173
- | verify | refine from result files |
174
-
175
- **Refine from verify results:**
176
-
177
- | Condition | Position |
178
- |-----------|----------|
179
- | verification.json: passed==false or gaps[] | `verify-failed` |
180
- | passed==true, no review.json | `business-test` |
181
- | review.json: verdict=="BLOCK" | `review-failed` |
182
- | review.json: verdict!="BLOCK" | `test` |
183
- | uat.md: all passed | `milestone-audit` |
184
- | uat.md: has failures | `test-failed` |
185
-
186
- ### A_RESOLVE_PHASE
187
-
188
- Priority: 1) regex from intent 2) latest artifact's phase 3) first incomplete phase 4) null if brainstorm/init/roadmap 5) AskUserQuestion if ambiguous
189
-
190
- ### A_BUILD_STEPS
191
-
192
- Generate steps from lifecycle_position to milestone-complete:
193
-
194
- | Stage | Skill | Type | Decision after |
195
- |-------|-------|------|----------------|
196
- | brainstorm | `maestro-brainstorm "{intent}"` | external | — |
197
- | init | `maestro-init` | internal | — |
198
- | roadmap | `maestro-roadmap "{intent}"` | internal | — |
199
- | analyze | `maestro-analyze {phase}` | external | — |
200
- | plan | `maestro-plan {phase}` | internal | — |
201
- | execute | `maestro-execute {phase}` | external | — |
202
- | verify | `maestro-verify {phase}` | internal | `post-verify` |
203
- | business-test | `quality-auto-test {phase}` | internal | `post-business-test` |
204
- | review | `quality-review {phase}` | internal | `post-review` |
205
- | test-gen | `quality-auto-test {phase}` | internal | — |
206
- | test | `quality-test {phase}` | internal | `post-test` |
207
- | milestone-audit | `maestro-milestone-audit` | internal | — |
208
- | milestone-complete | `maestro-milestone-complete` | internal | `post-milestone` |
209
-
210
- Type rationale: `internal` = Skill(), lightweight/interactive; `external` = delegate --to claude, context-isolated heavy computation
211
-
212
- Build rules: start from position, skip completed, insert decision nodes with `{ retry_count: 0, max_retries: 2 }`, args use placeholders resolved at execution time by ralph-execute
213
-
214
- ### A_CREATE_SESSION
215
-
216
- 1. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json` (see Appendix: Session Schema)
217
- 2. Display chain overview with step list
218
-
219
- ### A_DELEGATE_EVALUATE
220
-
221
- 1. Resolve artifact dir: `.workflow/scratch/{artifact.path}/` with fallback glob
222
- 2. Parse decision metadata: `{ decision, retry_count, max_retries }`
223
- 3. Map result files:
224
- | Decision | Files |
225
- |----------|-------|
226
- | post-verify | verification.json |
227
- | post-business-test | .tests/auto-test/report.json |
228
- | post-review | review.json |
229
- | post-test | uat.md, .tests/test-results.json |
230
- 4. Check artifact for confidence section include as signal
231
- 5. Execute delegate (run_in_background, STOP, wait for callback):
232
- ```
233
- maestro delegate "PURPOSE: 评估 {decision} 质量门结果
234
- TASK: 读取结果 | 分析状态 | 评估严重性 | 给出建议
235
- EXPECTED: ---VERDICT--- STATUS/REASON/GAP_SUMMARY/CONFIDENCE(high|medium|low)/CONFIDENCE_SCORE(0-100)/WEAKEST_DIMENSION ---END---
236
- CONSTRAINTS: 只评估 | 置信度<60% 倾向 fix | retry {n}/{max} 达上限必须 escalate"
237
- --role analyze --mode analysis
238
- ```
239
- 6. On callback: parse verdict; if parse failsfallback STATUS="fix"
240
- 7. Confidence adjustment: <60 + proceed → fix; >95 + fix + retry>0 → suggest proceed
241
- 8. **Decision log**: Append to `{session_dir}/decisions.ndjson`:
242
- ```json
243
- { "id": "DEC-{timestamp}", "timestamp": "{ISO}", "source": "ralph",
244
- "node_id": "{step.decision}", "type": "quality-gate",
245
- "verdict": "{adjusted_verdict}", "confidence_score": {N},
246
- "close_call": {N>=50 && N<=70}, "summary": "{REASON}" }
247
- ```
248
-
249
- ### A_STRUCTURAL_EVALUATE
250
-
251
- **post-milestone:** Read state.json next milestone? insert lifecycle steps / complete
252
- **post-debug-escalate:** Always STOP set paused, display "请人工介入"
253
-
254
- ### A_APPLY_PROCEED
255
-
256
- 1. Mark decision completed, write status.json
257
- 2. Display: Decision: {type} proceed ({reason})
258
-
259
- ### A_APPLY_FIX
260
-
261
- 1. Insert fix-loop commands after current step (see Appendix: Fix-Loop Templates)
262
- 2. Reindex steps, increment retry_count, write status.json
263
- 3. Display: ◆ Decision: {type} → fix, +{N} commands inserted
264
-
265
- ### A_APPLY_ESCALATE
266
-
267
- 1. Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`
268
- 2. Increment retry_count, reindex, write status.json
269
-
270
- ### A_ADVANCE_MILESTONE
271
-
272
- 1. Update session: milestone, phase, reset passed_gates
273
- 2. Insert full lifecycle steps for next milestone
274
- 3. Reindex, write status.json
275
-
276
- ### A_PAUSE_ESCALATE
277
-
278
- 1. Set session status = "paused", write status.json
279
- 2. Display: 已达最大重试次数,debug 已执行。请人工介入。
280
- 3. Display: /maestro-ralph continue 恢复
281
-
282
- </actions>
283
-
284
- </state_machine>
285
-
286
- <appendix>
287
-
288
- ### Session Schema
289
-
290
- ```json
291
- {
292
- "session_id": "ralph-{YYYYMMDD-HHmmss}",
293
- "source": "ralph", "status": "running",
294
- "intent": "", "lifecycle_position": "",
295
- "phase": null, "milestone": "",
296
- "auto_mode": false, "quality_mode": "standard",
297
- "cli_tool": "claude", "passed_gates": [],
298
- "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
299
- "analysis_dir": null, "brainstorm_dir": null },
300
- "steps": [{ "index": 0, "type": "internal|external|decision",
301
- "skill": "", "args": "", "status": "pending" }],
302
- "waves": [], "current_step": 0
303
- }
304
- ```
305
-
306
- ### Fix-Loop Templates
307
-
308
- **post-verify:**
309
- ```
310
- quality-debug "{gap_summary}"
311
- maestro-plan --gaps {phase}
312
- maestro-execute {phase} [external]
313
- maestro-verify {phase}
314
- decision:post-verify {retry+1}
315
- ```
316
-
317
- **post-business-test:**
318
- ```
319
- quality-debug --from-business-test "{gap_summary}"
320
- maestro-plan --gaps {phase}
321
- maestro-execute {phase} [external]
322
- maestro-verify {phase}
323
- decision:post-verify {retry: 0}
324
- quality-auto-test {phase}
325
- decision:post-business-test {retry+1}
326
- ```
327
-
328
- **post-review:**
329
- ```
330
- quality-debug "{gap_summary}"
331
- maestro-plan --gaps {phase}
332
- maestro-execute {phase} [external]
333
- quality-review {phase}
334
- decision:post-review {retry+1}
335
- ```
336
-
337
- **post-test:**
338
- ```
339
- quality-debug --from-uat "{gap_summary}"
340
- maestro-plan --gaps {phase}
341
- maestro-execute {phase} [external]
342
- maestro-verify {phase}
343
- decision:post-verify {retry: 0}
344
- quality-auto-test {phase}
345
- decision:post-business-test {retry: 0}
346
- quality-review {phase}
347
- decision:post-review {retry: 0}
348
- quality-auto-test {phase}
349
- quality-test {phase}
350
- decision:post-test {retry+1}
351
- ```
352
-
353
- ### Error Codes
354
-
355
- | Code | Severity | Description | Recovery |
356
- |------|----------|-------------|----------|
357
- | E001 | error | No intent and no running session | Prompt for intent |
358
- | E002 | error | Cannot infer lifecycle position | Show raw state, ask |
359
- | E003 | error | Artifact dir not found for decision | Show glob, ask |
360
- | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
361
- | E005 | error | Delegate execution failed | Fallback: "fix" |
362
- | W001 | warning | Decision expanded chain | Auto-handled |
363
- | W002 | warning | Max retries, escalating | Auto-handled |
364
- | W003 | warning | Multiple running sessions | Use latest, warn |
365
- | W004 | warning | Low delegate confidence | Show warning |
366
-
367
- ### Success Criteria
368
-
369
- - [ ] State parsed, position inferred from bootstrap + artifacts + result files
370
- - [ ] Quality pipeline generated: verify → business-test → review → test-gen → test
371
- - [ ] Decision nodes delegate-evaluated via maestro delegate --role analyze
372
- - [ ] Verdict parsed with confidence adjustment
373
- - [ ] Fix-loop templates applied with retry tracking
374
- - [ ] Ralph never executes steps — only creates sessions and evaluates decisions
375
- - [ ] Handoff to maestro-ralph-execute via Skill() at creation and after decisions
376
-
377
- </appendix>
1
+ ---
2
+ name: maestro-ralph
3
+ description: Use when the optimal command sequence is unclear and needs automated state-based determination
4
+ argument-hint: "<intent> [-y] | status | continue"
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 decision engine for the maestro workflow lifecycle.
17
+ Reads project state → infers position → builds adaptive chain → delegates execution.
18
+
19
+ Entry points:
20
+ - **`/maestro-ralph "intent"`** — New session: infer → decompose → build → execute
21
+ - **`/maestro-ralph continue`** — Resume via maestro-ralph-execute
22
+ - **`/maestro-ralph status`** — Display session progress
23
+
24
+ Initial decomposition (S_DECOMPOSE): broad intents (重构/全面/迁移/重写) are boundary-clarified via ≤3 questions, producing 执行准则 + 子目标清单 written into status.json, plus a `goal-checklist.md` and a copy-paste `/goal` prompt for the user to bind.
25
+
26
+ Three node types:
27
+ - **internal**: `Skill()` call (synchronous, lightweight)
28
+ - **external**: `maestro delegate --to claude` (context-isolated, heavy computation)
29
+ - **decision**: Hand back to ralph for re-evaluation (adaptive branching)
30
+
31
+ Key difference from maestro coordinator:
32
+ - maestro: static chain → one-time selection → runs all steps
33
+ - ralph: living chain → decision nodes re-evaluate → chain grows/shrinks dynamically
34
+
35
+ Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`
36
+ Mutual invocation with `/maestro-ralph-execute` forms a self-perpetuating work loop.
37
+ </purpose>
38
+
39
+ <context>
40
+ $ARGUMENTS — intent text, flags, or keywords.
41
+
42
+ **Parse:**
43
+ ```
44
+ -y flag auto_confirm = true
45
+ .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
46
+ Remaining → intent
47
+ ```
48
+
49
+ **State files:**
50
+ - `.workflow/state.json` — artifact registry, milestones, phases
51
+ - `.workflow/roadmap.md` — milestone/phase structure
52
+ - `.workflow/.maestro/ralph-*/status.json` — ralph session state
53
+ </context>
54
+
55
+ <invariants>
56
+ 1. **Ralph never executes steps** — only creates sessions and evaluates decisions
57
+ 2. **Handoff via Skill("maestro-ralph-execute")** — at session creation and after decision evaluation
58
+ 3. **Decision delegates read-only** — `maestro delegate --role analyze --mode analysis`
59
+ 4. **External ≠ CLI call** — external spawns full Claude Code session executing the skill command
60
+ 5. **Delegate sessions non-interactive** — all external skills MUST append `-y` to args inside the prompt
61
+ 6. **Decomposition is outcome-oriented** — sub-goals are deliverables/done-criteria, NEVER lifecycle-stage duplicates (analyze/plan/...). `/goal` binding is user-driven; ralph only emits the prompt
62
+ 7. **task_decomposition drives DYNAMIC step growth, not a frozen plan** — sub-goals are the convergence spec; `status.json.steps[]` remains the living chain. The `post-goal-audit` decision node re-checks the checklist and **dynamically inserts scoped execution steps** for every unmet sub-goal (same insert+reindex+retry mechanism as fix-loops). Decomposition never replaces ralph's adaptive branching — it feeds it. New fields are also additive/optional (absent → decomposition off, old behavior); never remove/rename existing fields
63
+ </invariants>
64
+
65
+ <state_machine>
66
+
67
+ <states>
68
+ S_PARSE_ROUTE 解析参数、路由入口 PERSIST:
69
+ S_STATUS 显示 session 进度 PERSIST:
70
+ S_CONTINUE 恢复执行 PERSIST:
71
+ S_INFER 读 state.json、推断生命周期位置 PERSIST: session.lifecycle_position
72
+ S_RESOLVE_PHASE 解析目标 phase PERSIST: session.phase
73
+ S_DECOMPOSE 边界澄清、写执行准则+子目标清单 PERSIST: session.boundary_contract, .execution_criteria, .task_decomposition
74
+ S_BUILD_CHAIN 构建步骤链 PERSIST: session.steps[]
75
+ S_CREATE_SESSION 写 status.json PERSIST: session (全量)
76
+ S_CONFIRM — 用户确认 PERSIST: —
77
+ S_DISPATCH — 移交 maestro-ralph-execute PERSIST: —
78
+ S_DECISION_EVAL — 委托评估质量门 PERSIST: —
79
+ S_APPLY_VERDICT — 应用裁决 + 插入命令 PERSIST: session.steps[], session.passed_gates[]
80
+ S_FALLBACK — 请求用户输入 PERSIST:
81
+ </states>
82
+
83
+ <transitions>
84
+
85
+ S_PARSE_ROUTE:
86
+ → S_STATUS WHEN: intent == "status"
87
+ → S_CONTINUE WHEN: intent == "continue"
88
+ S_DECISION_EVAL WHEN: running session with decision step in "running" status
89
+ → S_INFER WHEN: intent is non-empty
90
+ → S_FALLBACK WHEN: no intent AND no running session
91
+
92
+ S_STATUS:
93
+ → END DO: A_SHOW_STATUS
94
+
95
+ S_CONTINUE:
96
+ S_DISPATCH WHEN: running session found
97
+ → S_FALLBACK WHEN: no running session DO: display "无运行中的 ralph 会话"
98
+
99
+ S_INFER:
100
+ S_RESOLVE_PHASE WHEN: position resolved DO: A_INFER_POSITION
101
+ → S_FALLBACK WHEN: cannot infer
102
+
103
+ S_RESOLVE_PHASE:
104
+ S_DECOMPOSE WHEN: phase resolved or null DO: A_RESOLVE_PHASE
105
+ → S_FALLBACK WHEN: ambiguous
106
+ GUARD: auto_confirm does NOT skip phase ambiguity
107
+
108
+ S_DECOMPOSE:
109
+ → S_BUILD_CHAIN DO: A_DECOMPOSE_TASKS
110
+ GUARD: broad intent (重构/全面/重写/迁移/overhaul/migrate/rewrite) → MUST clarify boundary even if auto_confirm
111
+ GUARD: narrow intent (single file/function/bug) auto-derive, skip questions
112
+ GUARD: position ∈ {brainstorm, init} skip decomposition (no concrete target yet)
113
+
114
+ S_BUILD_CHAIN:
115
+ → S_CREATE_SESSION DO: A_BUILD_STEPS
116
+
117
+ S_CREATE_SESSION:
118
+ → S_CONFIRM WHEN: not auto_confirm DO: A_CREATE_SESSION
119
+ S_DISPATCH WHEN: auto_confirm DO: A_CREATE_SESSION
120
+
121
+ S_CONFIRM:
122
+ → S_DISPATCH WHEN: user selects "Proceed"
123
+ → S_BUILD_CHAIN WHEN: user selects "Edit"
124
+ → END WHEN: user selects "Cancel"
125
+
126
+ S_DISPATCH:
127
+ END DO: Skill({ skill: "maestro-ralph-execute" })
128
+
129
+ S_DECISION_EVAL:
130
+ S_APPLY_VERDICT WHEN: quality-gate (post-verify, post-business-test, post-review, post-test)
131
+ DO: A_DELEGATE_EVALUATE
132
+ S_APPLY_VERDICT WHEN: goal-gate (post-goal-audit)
133
+ DO: A_GOAL_AUDIT_EVALUATE
134
+ S_APPLY_VERDICT WHEN: structural (post-milestone, post-debug-escalate)
135
+ DO: A_STRUCTURAL_EVALUATE
136
+
137
+ S_APPLY_VERDICT:
138
+ S_DISPATCH WHEN: verdict == "proceed" DO: A_APPLY_PROCEED
139
+ S_DISPATCH WHEN: post-goal-audit + unmet sub-goals DO: A_APPLY_GOAL_FIX
140
+ → S_DISPATCH WHEN: post-goal-audit + all sub-goals met DO: A_APPLY_GOAL_DONE
141
+ → S_DISPATCH WHEN: verdict == "fix" DO: A_APPLY_FIX
142
+ → S_DISPATCH WHEN: verdict == "escalate" DO: A_APPLY_ESCALATE
143
+ → S_DISPATCH WHEN: post-milestone + next milestone DO: A_ADVANCE_MILESTONE
144
+ → END WHEN: post-milestone + no next milestone DO: mark completed
145
+ END WHEN: post-debug-escalate (always STOP) DO: A_PAUSE_ESCALATE
146
+ GUARD: retry_count >= max_retries → force escalate
147
+ GUARD: confidence_score < 60 AND proceed → override to fix
148
+ GUARD: confidence_score > 95 AND fix AND retry > 0 → suggest proceed
149
+ GUARD: auto_confirm skip user prompt, apply adjusted verdict
150
+ GUARD: not auto_confirm → AskUserQuestion with override options
151
+
152
+ S_FALLBACK:
153
+ S_PARSE_ROUTE WHEN: user provides input DO: AskUserQuestion
154
+ → END WHEN: user cancels
155
+
156
+ </transitions>
157
+
158
+ <actions>
159
+
160
+ ### A_SHOW_STATUS
161
+
162
+ 1. Find latest ralph session (by created_at)
163
+ 2. Display: Session, Status, Position, Progress, Current step
164
+ 3. List steps: [✓] completed, [▸] current, [ ] pending, [◆] decision
165
+ 4. If `task_decomposition` present: show `Sub-goals: {done}/{total}` and any unmet G-ids (graceful skip if field absent — backward compat)
166
+
167
+ ### A_INFER_POSITION
168
+
169
+ **Intent-based override:** brainstorm/头脑风暴/探索/ideate/设计思路 position = `brainstorm`
170
+
171
+ **Bootstrap detection:**
172
+
173
+ | Condition | Position |
174
+ |-----------|----------|
175
+ | No `.workflow/` + no source files | `brainstorm` |
176
+ | No `.workflow/` + has source files | `init` |
177
+ | Has `.workflow/` but no state.json | `init` |
178
+ | Has state.json | → artifact-based inference |
179
+
180
+ **Artifact-based inference:** Filter by current_milestone + target phase:
181
+
182
+ | Latest artifact type | Position |
183
+ |---------------------|----------|
184
+ | no milestones or no roadmap.md | `roadmap` |
185
+ | none for phase | `analyze` |
186
+ | analyze | `plan` |
187
+ | plan | `execute` |
188
+ | execute | `verify` |
189
+ | verify | → refine from result files |
190
+
191
+ **Refine from verify results:**
192
+
193
+ | Condition | Position |
194
+ |-----------|----------|
195
+ | verification.json: passed==false or gaps[] | `verify-failed` |
196
+ | passed==true, no review.json | `business-test` |
197
+ | review.json: verdict=="BLOCK" | `review-failed` |
198
+ | review.json: verdict!="BLOCK" | `test` |
199
+ | uat.md: all passed | `milestone-audit` |
200
+ | uat.md: has failures | `test-failed` |
201
+
202
+ ### A_RESOLVE_PHASE
203
+
204
+ Priority: 1) regex from intent 2) latest artifact's phase 3) first incomplete phase 4) null if brainstorm/init/roadmap 5) AskUserQuestion if ambiguous
205
+
206
+ ### A_DECOMPOSE_TASKS
207
+
208
+ Build the boundary contract + outcome sub-goal checklist that `/goal` will track. Runs once at session creation, before chain build. All output is **additive** to status.json.
209
+
210
+ **1. Classify intent breadth:**
211
+
212
+ | Pattern | Breadth | Clarify? |
213
+ |---------|---------|----------|
214
+ | 重构/全面/重写/重做/整体/迁移 · overhaul/migrate/rewrite/revamp | broad | MUST (ignores auto_confirm) |
215
+ | named single file/function/bug, "fix X", "add Y to Z" | narrow | skip — auto-derive |
216
+ | otherwise | medium | clarify unless auto_confirm |
217
+
218
+ **2. Clarify boundary** (broad/medium) — `AskUserQuestion`, ≤3 rounds, options pre-filled from intent + a quick Glob/Grep scan of the target module:
219
+
220
+ | Round | Question | Drives |
221
+ |-------|----------|--------|
222
+ | Scope | 哪些目录/文件/层在范围内?明确排除什么? | boundary_contract.in_scope / out_of_scope |
223
+ | Constraints | 必须向后兼容?公共 API 冻结?行为/性能预算?测试门槛? | boundary_contract.constraints + execution_criteria |
224
+ | Done | 什么可观测结果算"完成"?(如:测试全绿 + 行为零变更 + X 指标) | boundary_contract.definition_of_done |
225
+
226
+ narrow derive defaults from intent + codebase, skip questions.
227
+
228
+ **3. Derive `execution_criteria`** (执行准则 — 3-6 short imperative rules every step obeys): backward-compat stance, scope-freeze ("只改请求范围"), test/coverage bar, fix-don't-hide, incremental commit. Each verify/review/test gate later checks against these.
229
+
230
+ **4. Derive `task_decomposition`** (子目标清单 outcome-oriented, NOT lifecycle stages). Each entry:
231
+ ```json
232
+ { "id": "G1", "goal": "<deliverable>", "boundary": "<in/out note>",
233
+ "done_when": "<objectively checkable condition>",
234
+ "evidence": "verification.json|review.json|uat.md|<test path>",
235
+ "lifecycle": ["analyze","execute","verify"], "status": "pending" }
236
+ ```
237
+ **Cleverness rule**: `done_when` MUST be objectively verifiable and SHOULD reference an artifact ralph already produces, so the `/goal` Stop hook can re-verify after context compaction. Map each sub-goal to the lifecycle phase(s) that will produce its evidence — this is how the checklist "adapts to ralph": the existing pipeline becomes the machinery that satisfies the goals.
238
+
239
+ **5. Persist** (additive) into session for A_CREATE_SESSION to write: `boundary_contract`, `execution_criteria`, `task_decomposition`. Absent feature (skipped) write none; downstream treats as "decomposition off".
240
+
241
+ **6. Stage** the Goal Checklist + Goal Prompt (Appendix) for A_CREATE_SESSION to emit.
242
+
243
+ ### A_BUILD_STEPS
244
+
245
+ Generate steps from lifecycle_position to milestone-complete:
246
+
247
+ | Stage | Skill | Type | Decision after |
248
+ |-------|-------|------|----------------|
249
+ | brainstorm | `maestro-brainstorm "{intent}"` | external | — |
250
+ | init | `maestro-init` | internal | — |
251
+ | roadmap | `maestro-roadmap "{intent}"` | internal | |
252
+ | analyze | `maestro-analyze {phase}` | external | |
253
+ | plan | `maestro-plan {phase}` | internal | — |
254
+ | execute | `maestro-execute {phase}` | external | — |
255
+ | verify | `maestro-verify {phase}` | internal | `post-verify` |
256
+ | business-test | `quality-auto-test {phase}` | internal | `post-business-test` |
257
+ | review | `quality-review {phase}` | internal | `post-review` |
258
+ | test-gen | `quality-auto-test {phase}` | internal | — |
259
+ | test | `quality-test {phase}` | internal | `post-test` |
260
+ | milestone-audit | `maestro-milestone-audit` | internal | — |
261
+ | goal-audit | *(decision-only, no skill)* | decision | `post-goal-audit` |
262
+ | milestone-complete | `maestro-milestone-complete` | internal | `post-milestone` |
263
+
264
+ `goal-audit` row is inserted **only when `task_decomposition` present**, immediately before `milestone-complete`. It is a pure decision node (no skill step) — its job is to re-check the goal-checklist and **dynamically grow `steps[]`** for unmet sub-goals.
265
+
266
+ Type rationale: `internal` = Skill(), lightweight/interactive; `external` = delegate --to claude, context-isolated heavy computation
267
+
268
+ Build rules: start from position, skip completed, insert decision nodes with `{ retry_count: 0, max_retries: 2 }`, args use placeholders resolved at execution time by ralph-execute. Steps dynamically inserted by `post-goal-audit` carry optional `goal_ref: "G{n}"` tracing which sub-goal they serve.
269
+
270
+ ### A_CREATE_SESSION
271
+
272
+ 1. Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json` (see Appendix: Session Schema) include decomposition fields only if produced (additive)
273
+ 2. If `task_decomposition` present: write `{session_dir}/goal-checklist.md` (see Appendix: Goal Checklist Template) — stable within session, referenced verbatim by `/goal`
274
+ 3. Display chain overview with step list
275
+ 4. If `task_decomposition` present: display the **Goal Prompt block** (Appendix: Goal Prompt Template) — the copy-paste `/goal …` line binding the checklist as a Stop-hook target
276
+
277
+ ### A_DELEGATE_EVALUATE
278
+
279
+ 1. Resolve artifact dir: `.workflow/scratch/{artifact.path}/` with fallback glob
280
+ 2. Parse decision metadata: `{ decision, retry_count, max_retries }`
281
+ 3. Map result files:
282
+ | Decision | Files |
283
+ |----------|-------|
284
+ | post-verify | verification.json |
285
+ | post-business-test | .tests/auto-test/report.json |
286
+ | post-review | review.json |
287
+ | post-test | uat.md, .tests/test-results.json |
288
+ 4. Check artifact for confidence section → include as signal
289
+ 5. Execute delegate (run_in_background, STOP, wait for callback):
290
+ ```
291
+ maestro delegate "PURPOSE: 评估 {decision} 质量门结果
292
+ TASK: 读取结果 | 分析状态 | 评估严重性 | 给出建议
293
+ EXPECTED: ---VERDICT--- STATUS/REASON/GAP_SUMMARY/CONFIDENCE(high|medium|low)/CONFIDENCE_SCORE(0-100)/WEAKEST_DIMENSION ---END---
294
+ CONSTRAINTS: 只评估 | 置信度<60% 倾向 fix | retry {n}/{max} 达上限必须 escalate"
295
+ --role analyze --mode analysis
296
+ ```
297
+ 6. On callback: parse verdict; if parse fails → fallback STATUS="fix"
298
+ 7. Confidence adjustment: <60 + proceed fix; >95 + fix + retry>0 → suggest proceed
299
+ 8. **Decision log**: Append to `{session_dir}/decisions.ndjson`:
300
+ ```json
301
+ { "id": "DEC-{timestamp}", "timestamp": "{ISO}", "source": "ralph",
302
+ "node_id": "{step.decision}", "type": "quality-gate",
303
+ "verdict": "{adjusted_verdict}", "confidence_score": {N},
304
+ "close_call": {N>=50 && N<=70}, "summary": "{REASON}" }
305
+ ```
306
+
307
+ ### A_STRUCTURAL_EVALUATE
308
+
309
+ **post-milestone:** Read state.json → next milestone? → insert lifecycle steps / complete
310
+ **post-debug-escalate:** Always STOP → set paused, display "请人工介入"
311
+
312
+ ### A_GOAL_AUDIT_EVALUATE
313
+
314
+ Re-checks the goal-checklist and decides whether `steps[]` must dynamically grow. Only runs when `task_decomposition` present.
315
+
316
+ 1. Read `session.task_decomposition` + `goal_checklist_path`
317
+ 2. For each sub-goal `status != "done"`: resolve its `evidence` artifact (verification.json / review.json / uat.md / test path) under the current phase scratch dir
318
+ 3. Delegate read-only audit (run_in_background, STOP, wait):
319
+ ```
320
+ maestro delegate "PURPOSE: 审计子目标达成情况,决定是否需要补充执行步骤
321
+ TASK: 逐个读取每个未完成子目标的 evidence 产物 | 对照 done_when 判定 met/unmet | 给出每个 unmet 子目标的差距
322
+ CONTEXT: @{goal_checklist_path} @{evidence artifacts} | 执行准则: {execution_criteria} | 边界: {boundary_contract}
323
+ EXPECTED: ---VERDICT--- STATUS(all_met|has_unmet) / UNMET=[{id:G2,gap:'...',target_phase:execute}] / CONFIDENCE_SCORE(0-100) ---END---
324
+ CONSTRAINTS: 只评估不修改 | 严格按 done_when 判定 | 不得超出 boundary_contract"
325
+ --role analyze --mode analysis
326
+ ```
327
+ 4. On callback: parse UNMET list. For each met sub-goal → set `task_decomposition[i].status="done"` + flip `[ ]→[x]` in goal-checklist.md
328
+ 5. **Decision log**: append to `{session_dir}/decisions.ndjson` with `"type": "goal-gate"`, `unmet_count`, `unmet_ids`
329
+ 6. Verdict: `all_met` → A_APPLY_GOAL_DONE; `has_unmet` → A_APPLY_GOAL_FIX
330
+ GUARD: retry_count >= max_retries AND still unmet → A_APPLY_ESCALATE (insert quality-debug, hand to human)
331
+
332
+ ### A_APPLY_PROCEED
333
+
334
+ 1. Mark decision completed, write status.json
335
+ 2. Display: ◆ Decision: {type} → proceed ({reason})
336
+
337
+ ### A_APPLY_FIX
338
+
339
+ 1. Insert fix-loop commands after current step (see Appendix: Fix-Loop Templates)
340
+ 2. Reindex steps, increment retry_count, write status.json
341
+ 3. Display: ◆ Decision: {type} → fix, +{N} commands inserted
342
+
343
+ ### A_APPLY_ESCALATE
344
+
345
+ 1. Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]`
346
+ 2. Increment retry_count, reindex, write status.json
347
+
348
+ ### A_APPLY_GOAL_FIX
349
+
350
+ **This is the dynamic step-growth core.** For every unmet sub-goal, inject scoped execution steps so `steps[]` grows toward convergence:
351
+
352
+ 1. For each `unmet` sub-goal `G{n}` (grouped by `target_phase` to avoid duplicate runs):
353
+ insert before the `goal-audit` node a scoped mini-loop (see Appendix: Fix-Loop Templates → post-goal-audit), each inserted step tagged `goal_ref: "G{n}"`
354
+ 2. Re-append a fresh `decision:post-goal-audit {retry+1}` after the inserted steps (re-loops until all met or max retries)
355
+ 3. Reindex steps, increment retry_count, write status.json (steps[] now larger — the JSON "grew")
356
+ 4. Display: ◆ Goal audit: {k} sub-goals unmet → +{N} steps inserted (G{ids}), retry {r}/{max}
357
+
358
+ ### A_APPLY_GOAL_DONE
359
+
360
+ 1. Set all `task_decomposition[*].status="done"`, write status.json
361
+ 2. Append `ALL_GOALS_DONE` sentinel line to goal-checklist.md (satisfies the user's `/goal` Stop hook)
362
+ 3. Mark goal-audit decision completed; proceed to `milestone-complete`
363
+ 4. Display: Goal audit: 全部子目标达成 checklist 已写入 ALL_GOALS_DONE
364
+
365
+ ### A_ADVANCE_MILESTONE
366
+
367
+ 1. Update session: milestone, phase, reset passed_gates
368
+ 2. Insert full lifecycle steps for next milestone
369
+ 3. Reindex, write status.json
370
+
371
+ ### A_PAUSE_ESCALATE
372
+
373
+ 1. Set session status = "paused", write status.json
374
+ 2. Display: 已达最大重试次数,debug 已执行。请人工介入。
375
+ 3. Display: /maestro-ralph continue 恢复
376
+
377
+ </actions>
378
+
379
+ </state_machine>
380
+
381
+ <appendix>
382
+
383
+ ### Session Schema
384
+
385
+ ```json
386
+ {
387
+ "session_id": "ralph-{YYYYMMDD-HHmmss}",
388
+ "source": "ralph", "status": "running",
389
+ "intent": "", "lifecycle_position": "",
390
+ "phase": null, "milestone": "",
391
+ "auto_mode": false, "quality_mode": "standard",
392
+ "cli_tool": "claude", "passed_gates": [],
393
+ "context": { "issue_id": null, "scratch_dir": null, "plan_dir": null,
394
+ "analysis_dir": null, "brainstorm_dir": null },
395
+ "steps": [{ "index": 0, "type": "internal|external|decision",
396
+ "skill": "", "args": "", "status": "pending",
397
+ "goal_ref": null }],
398
+ "waves": [], "current_step": 0,
399
+
400
+ "_comment": "↓ OPTIONAL additive decomposition block (v0.4.8+). Absent → no decomposition; readers MUST tolerate missing keys. Never remove/rename above fields.",
401
+ "boundary_contract": {
402
+ "in_scope": [], "out_of_scope": [], "constraints": [], "definition_of_done": ""
403
+ },
404
+ "execution_criteria": [],
405
+ "task_decomposition": [
406
+ { "id": "G1", "goal": "", "boundary": "", "done_when": "",
407
+ "evidence": "", "lifecycle": [], "status": "pending|done" }
408
+ ],
409
+ "goal_checklist_path": ""
410
+ }
411
+ ```
412
+
413
+ > **Extensibility contract (two dimensions)**:
414
+ > 1. **Schema-additive** — decomposition block fields are optional; absence = old behavior.
415
+ > 2. **Step-dynamic** — `steps[]` is a *living array*: `post-goal-audit` (and existing fix/escalate/milestone decisions) **append/reindex steps at runtime** until sub-goals converge. The JSON "extends" primarily by growing `steps[]`, not by freezing a plan. `goal_ref` (optional, default null) traces dynamically-added steps back to the sub-goal that spawned them.
416
+
417
+ ### Fix-Loop Templates
418
+
419
+ **post-verify:**
420
+ ```
421
+ quality-debug "{gap_summary}"
422
+ maestro-plan --gaps {phase}
423
+ maestro-execute {phase} [external]
424
+ maestro-verify {phase}
425
+ decision:post-verify {retry+1}
426
+ ```
427
+
428
+ **post-business-test:**
429
+ ```
430
+ quality-debug --from-business-test "{gap_summary}"
431
+ maestro-plan --gaps {phase}
432
+ maestro-execute {phase} [external]
433
+ maestro-verify {phase}
434
+ decision:post-verify {retry: 0}
435
+ quality-auto-test {phase}
436
+ decision:post-business-test {retry+1}
437
+ ```
438
+
439
+ **post-review:**
440
+ ```
441
+ quality-debug "{gap_summary}"
442
+ maestro-plan --gaps {phase}
443
+ maestro-execute {phase} [external]
444
+ quality-review {phase}
445
+ decision:post-review {retry+1}
446
+ ```
447
+
448
+ **post-test:**
449
+ ```
450
+ quality-debug --from-uat "{gap_summary}"
451
+ maestro-plan --gaps {phase}
452
+ maestro-execute {phase} [external]
453
+ maestro-verify {phase}
454
+ decision:post-verify {retry: 0}
455
+ quality-auto-test {phase}
456
+ decision:post-business-test {retry: 0}
457
+ quality-review {phase}
458
+ decision:post-review {retry: 0}
459
+ quality-auto-test {phase}
460
+ quality-test {phase}
461
+ decision:post-test {retry+1}
462
+ ```
463
+
464
+ **post-goal-audit:** (per unmet sub-goal group — this is what dynamically grows `steps[]`)
465
+ ```
466
+ # for each unmet sub-goal G{n}, scoped to its target_phase:
467
+ maestro-plan --gaps {target_phase} "G{n}: {gap}" [goal_ref: G{n}]
468
+ maestro-execute {target_phase} [external] [goal_ref: G{n}]
469
+ maestro-verify {target_phase} [goal_ref: G{n}]
470
+ # after all unmet groups inserted, re-loop the audit:
471
+ decision:post-goal-audit {retry+1}
472
+ ```
473
+ Notes: only unmet sub-goals' phases are re-run (no full-pipeline replay); inserted steps carry `goal_ref` for traceability; loop exits when audit returns `all_met` (→ A_APPLY_GOAL_DONE) or retry hits max (→ escalate to human). This keeps growth bounded.
474
+
475
+ ### Goal Checklist Template
476
+
477
+ Written to `{session_dir}/goal-checklist.md`. Stable within the session; never renamed (so the `/goal` condition string stays valid across context compaction).
478
+
479
+ ```markdown
480
+ # Ralph Goal Checklist — {session_id}
481
+ > Intent: {intent}
482
+
483
+ ## 执行准则 / Execution Criteria
484
+ - {criterion 1}
485
+ - {criterion 2}
486
+
487
+ ## 边界契约 / Boundary Contract
488
+ - In scope: {in_scope}
489
+ - Out of scope: {out_of_scope}
490
+ - Constraints: {constraints}
491
+ - Definition of Done: {definition_of_done}
492
+
493
+ ## 子目标 / Sub-goals
494
+ - [ ] G1: {goal} — done when: {done_when} (evidence: {evidence})
495
+ - [ ] G2: {goal} — done when: {done_when} (evidence: {evidence})
496
+ - [ ] G3: ...
497
+
498
+ <!-- ralph-execute flips [ ]→[x] when a sub-goal's evidence artifact confirms done;
499
+ appends the line `ALL_GOALS_DONE` once every box is [x]. -->
500
+ ```
501
+
502
+ `maestro-ralph-execute` responsibility (additive, optional): after a step whose `lifecycle` covers a sub-goal, re-check that sub-goal's `evidence` artifact; if satisfied, set `task_decomposition[i].status="done"` in status.json AND flip its checkbox in goal-checklist.md. When all done → append `ALL_GOALS_DONE`. If decomposition fields absent → do nothing (old behavior).
503
+
504
+ ### Goal Prompt Template
505
+
506
+ Displayed verbatim after the chain overview (only when decomposition produced):
507
+
508
+ ```
509
+ 📋 任务分解完成。可选(推荐):复制下面一行设定目标,让会话在所有子目标达成前不停:
510
+
511
+ /goal 当 {session_dir}/goal-checklist.md 中所有子目标复选框均为 [x] 且文件含 ALL_GOALS_DONE 哨兵时目标达成;否则依据文件内"执行准则"继续推进未完成子目标,不得超出边界契约范围
512
+
513
+ 然后运行 /maestro-ralph continue 开始执行。
514
+ ```
515
+
516
+ > `/goal` 是 harness 命令、仅用户可输入 — ralph 只输出此提示词,不能自行注册。这与 status.json 的可扩展约定一致:绑定是用户侧、可选的增量能力。
517
+
518
+ ### Error Codes
519
+
520
+ | Code | Severity | Description | Recovery |
521
+ |------|----------|-------------|----------|
522
+ | E001 | error | No intent and no running session | Prompt for intent |
523
+ | E002 | error | Cannot infer lifecycle position | Show raw state, ask |
524
+ | E003 | error | Artifact dir not found for decision | Show glob, ask |
525
+ | E004 | error | Delegate verdict parse failed | Fallback: "fix" |
526
+ | E005 | error | Delegate execution failed | Fallback: "fix" |
527
+ | W001 | warning | Decision expanded chain | Auto-handled |
528
+ | W002 | warning | Max retries, escalating | Auto-handled |
529
+ | W003 | warning | Multiple running sessions | Use latest, warn |
530
+ | W004 | warning | Low delegate confidence | Show warning |
531
+
532
+ ### Success Criteria
533
+
534
+ - [ ] State parsed, position inferred from bootstrap + artifacts + result files
535
+ - [ ] Decomposition runs as initial step; broad intent boundary-clarified via ≤3 questions (ignores auto_confirm); narrow auto-derives
536
+ - [ ] status.json enriched additively with boundary_contract + execution_criteria + task_decomposition; absent fields = old behavior preserved
537
+ - [ ] goal-checklist.md generated with verifiable done_when mapped to ralph evidence + ALL_GOALS_DONE sentinel
538
+ - [ ] Goal Prompt emitted for user to bind via /goal
539
+ - [ ] post-goal-audit decision node inserted before milestone-complete (only when decomposed)
540
+ - [ ] Unmet sub-goals DYNAMICALLY grow steps[] via scoped per-goal mini-loops (goal_ref tagged), looping until all_met or max retries → escalate
541
+ - [ ] Quality pipeline generated: verify → business-test → review → test-gen → test
542
+ - [ ] Decision nodes delegate-evaluated via maestro delegate --role analyze
543
+ - [ ] Verdict parsed with confidence adjustment
544
+ - [ ] Fix-loop templates applied with retry tracking
545
+ - [ ] Ralph never executes steps — only creates sessions and evaluates decisions
546
+ - [ ] Handoff to maestro-ralph-execute via Skill() at creation and after decisions
547
+
548
+ </appendix>