maestro-flow 0.3.38 → 0.3.40

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 (187) hide show
  1. package/.claude/agents/workflow-analyzer.md +2 -0
  2. package/.claude/agents/workflow-debugger.md +2 -0
  3. package/.claude/agents/workflow-executor.md +2 -0
  4. package/.claude/agents/workflow-integration-checker.md +1 -0
  5. package/.claude/agents/workflow-nyquist-auditor.md +1 -0
  6. package/.claude/agents/workflow-planner.md +2 -0
  7. package/.claude/agents/workflow-reviewer.md +2 -0
  8. package/.claude/agents/workflow-verifier.md +2 -0
  9. package/.claude/commands/learn-decompose.md +176 -176
  10. package/.claude/commands/learn-follow.md +167 -167
  11. package/.claude/commands/learn-investigate.md +221 -221
  12. package/.claude/commands/learn-retro.md +303 -303
  13. package/.claude/commands/learn-second-opinion.md +167 -167
  14. package/.claude/commands/maestro-amend.md +300 -300
  15. package/.claude/commands/maestro-analyze.md +130 -126
  16. package/.claude/commands/maestro-brainstorm.md +104 -100
  17. package/.claude/commands/maestro-composer.md +354 -354
  18. package/.claude/commands/maestro-execute.md +120 -114
  19. package/.claude/commands/maestro-fork.md +86 -86
  20. package/.claude/commands/maestro-init.md +78 -78
  21. package/.claude/commands/maestro-learn.md +140 -140
  22. package/.claude/commands/maestro-link-coordinate.md +1 -1
  23. package/.claude/commands/maestro-merge.md +61 -61
  24. package/.claude/commands/maestro-milestone-release.md +96 -96
  25. package/.claude/commands/maestro-overlay.md +178 -178
  26. package/.claude/commands/maestro-plan.md +154 -138
  27. package/.claude/commands/maestro-player.md +404 -404
  28. package/.claude/commands/maestro-quick.md +56 -56
  29. package/.claude/commands/maestro-ralph-execute.md +7 -18
  30. package/.claude/commands/maestro-ralph.md +48 -12
  31. package/.claude/commands/maestro-roadmap.md +1 -1
  32. package/.claude/commands/maestro-ui-design.md +93 -93
  33. package/.claude/commands/maestro-update.md +176 -176
  34. package/.claude/commands/maestro-verify.md +96 -90
  35. package/.claude/commands/maestro.md +121 -121
  36. package/.claude/commands/manage-codebase-rebuild.md +75 -75
  37. package/.claude/commands/manage-codebase-refresh.md +57 -57
  38. package/.claude/commands/manage-harvest.md +94 -94
  39. package/.claude/commands/manage-issue-discover.md +77 -77
  40. package/.claude/commands/manage-issue.md +73 -73
  41. package/.claude/commands/manage-knowhow-capture.md +193 -193
  42. package/.claude/commands/manage-knowhow.md +77 -77
  43. package/.claude/commands/manage-learn.md +67 -67
  44. package/.claude/commands/manage-status.md +51 -51
  45. package/.claude/commands/manage-wiki.md +62 -62
  46. package/.claude/commands/quality-auto-test.md +5 -1
  47. package/.claude/commands/quality-debug.md +125 -115
  48. package/.claude/commands/quality-refactor.md +55 -55
  49. package/.claude/commands/quality-retrospective.md +78 -78
  50. package/.claude/commands/quality-review.md +114 -108
  51. package/.claude/commands/quality-sync.md +51 -51
  52. package/.claude/commands/quality-test.md +107 -103
  53. package/.claude/commands/spec-add.md +49 -49
  54. package/.claude/commands/spec-load.md +51 -51
  55. package/.claude/commands/spec-remove.md +51 -51
  56. package/.claude/commands/spec-setup.md +51 -51
  57. package/.claude/commands/wiki-connect.md +62 -62
  58. package/.claude/commands/wiki-digest.md +69 -69
  59. package/.codex/skills/learn-decompose/SKILL.md +113 -113
  60. package/.codex/skills/learn-follow/SKILL.md +1 -1
  61. package/.codex/skills/learn-investigate/SKILL.md +83 -83
  62. package/.codex/skills/learn-retro/SKILL.md +83 -83
  63. package/.codex/skills/learn-second-opinion/SKILL.md +86 -86
  64. package/.codex/skills/maestro/SKILL.md +304 -304
  65. package/.codex/skills/maestro-analyze/SKILL.md +11 -3
  66. package/.codex/skills/maestro-brainstorm/SKILL.md +451 -397
  67. package/.codex/skills/maestro-composer/SKILL.md +213 -213
  68. package/.codex/skills/maestro-execute/SKILL.md +346 -318
  69. package/.codex/skills/maestro-fork/SKILL.md +56 -2
  70. package/.codex/skills/maestro-init/SKILL.md +40 -16
  71. package/.codex/skills/maestro-learn/SKILL.md +80 -80
  72. package/.codex/skills/maestro-link-coordinate/SKILL.md +257 -257
  73. package/.codex/skills/maestro-merge/SKILL.md +1 -1
  74. package/.codex/skills/maestro-milestone-audit/SKILL.md +1 -1
  75. package/.codex/skills/maestro-milestone-complete/SKILL.md +40 -9
  76. package/.codex/skills/maestro-milestone-release/SKILL.md +70 -70
  77. package/.codex/skills/maestro-overlay/SKILL.md +1 -1
  78. package/.codex/skills/maestro-plan/SKILL.md +29 -4
  79. package/.codex/skills/maestro-player/SKILL.md +323 -323
  80. package/.codex/skills/maestro-quick/SKILL.md +1 -1
  81. package/.codex/skills/maestro-ralph/SKILL.md +693 -578
  82. package/.codex/skills/maestro-roadmap/SKILL.md +518 -468
  83. package/.codex/skills/maestro-ui-design/SKILL.md +109 -12
  84. package/.codex/skills/maestro-verify/SKILL.md +27 -9
  85. package/.codex/skills/manage-codebase-rebuild/SKILL.md +3 -2
  86. package/.codex/skills/manage-codebase-refresh/SKILL.md +1 -1
  87. package/.codex/skills/manage-harvest/SKILL.md +91 -91
  88. package/.codex/skills/manage-issue/SKILL.md +19 -6
  89. package/.codex/skills/manage-issue-discover/SKILL.md +1 -1
  90. package/.codex/skills/manage-knowhow/SKILL.md +95 -95
  91. package/.codex/skills/manage-knowhow-capture/SKILL.md +110 -110
  92. package/.codex/skills/manage-learn/SKILL.md +1 -1
  93. package/.codex/skills/manage-status/SKILL.md +1 -1
  94. package/.codex/skills/manage-wiki/SKILL.md +55 -55
  95. package/.codex/skills/quality-auto-test/SKILL.md +553 -547
  96. package/.codex/skills/quality-debug/SKILL.md +345 -334
  97. package/.codex/skills/quality-refactor/SKILL.md +1 -1
  98. package/.codex/skills/quality-retrospective/SKILL.md +292 -292
  99. package/.codex/skills/quality-review/SKILL.md +365 -364
  100. package/.codex/skills/quality-sync/SKILL.md +1 -1
  101. package/.codex/skills/quality-test/SKILL.md +507 -498
  102. package/.codex/skills/spec-add/SKILL.md +101 -101
  103. package/.codex/skills/spec-load/SKILL.md +77 -77
  104. package/.codex/skills/spec-map/SKILL.md +1 -1
  105. package/.codex/skills/spec-remove/SKILL.md +69 -69
  106. package/.codex/skills/spec-setup/SKILL.md +1 -1
  107. package/.codex/skills/team-coordinate/SKILL.md +2 -1
  108. package/.codex/skills/team-executor/SKILL.md +116 -115
  109. package/.codex/skills/team-lifecycle-v4/SKILL.md +2 -1
  110. package/.codex/skills/team-lifecycle-v4/instructions/agent-instruction.md +14 -6
  111. package/.codex/skills/team-lifecycle-v4/roles/analyst/role.md +16 -4
  112. package/.codex/skills/team-lifecycle-v4/roles/executor/commands/implement.md +7 -1
  113. package/.codex/skills/team-lifecycle-v4/roles/planner/role.md +16 -4
  114. package/.codex/skills/team-lifecycle-v4/roles/writer/role.md +8 -2
  115. package/.codex/skills/team-quality-assurance/SKILL.md +2 -1
  116. package/.codex/skills/team-quality-assurance/roles/scout/role.md +9 -2
  117. package/.codex/skills/team-review/SKILL.md +2 -1
  118. package/.codex/skills/team-review/roles/reviewer/role.md +10 -1
  119. package/.codex/skills/team-review/roles/scanner/role.md +10 -1
  120. package/.codex/skills/team-tech-debt/SKILL.md +144 -143
  121. package/.codex/skills/team-tech-debt/roles/executor/role.md +9 -5
  122. package/.codex/skills/team-tech-debt/roles/scanner/role.md +10 -0
  123. package/.codex/skills/team-tech-debt/roles/validator/role.md +8 -2
  124. package/.codex/skills/team-testing/SKILL.md +2 -1
  125. package/.codex/skills/team-testing/roles/executor/role.md +8 -2
  126. package/.codex/skills/team-testing/roles/generator/role.md +8 -2
  127. package/.codex/skills/wiki-connect/SKILL.md +73 -73
  128. package/.codex/skills/wiki-digest/SKILL.md +87 -87
  129. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.js +4 -0
  130. package/dashboard/dist-server/dashboard/src/server/agents/claude-code-adapter.js.map +1 -1
  131. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.js +6 -0
  132. package/dashboard/dist-server/dashboard/src/server/agents/codex-cli-adapter.js.map +1 -1
  133. package/dashboard/dist-server/shared/agent-types.d.ts +2 -0
  134. package/dashboard/dist-server/src/agents/cli-agent-runner.d.ts +2 -0
  135. package/dashboard/dist-server/src/agents/cli-agent-runner.js +4 -0
  136. package/dashboard/dist-server/src/agents/cli-agent-runner.js.map +1 -1
  137. package/dashboard/dist-server/src/commands/delegate.d.ts +2 -0
  138. package/dashboard/dist-server/src/commands/delegate.js +18 -0
  139. package/dashboard/dist-server/src/commands/delegate.js.map +1 -1
  140. package/dashboard/dist-server/src/config/cli-tools-config.d.ts +6 -0
  141. package/dashboard/dist-server/src/config/cli-tools-config.js +2 -0
  142. package/dashboard/dist-server/src/config/cli-tools-config.js.map +1 -1
  143. package/dist/shared/agent-types.d.ts +2 -0
  144. package/dist/shared/agent-types.d.ts.map +1 -1
  145. package/dist/src/agents/cli-agent-runner.d.ts +2 -0
  146. package/dist/src/agents/cli-agent-runner.d.ts.map +1 -1
  147. package/dist/src/agents/cli-agent-runner.js +4 -0
  148. package/dist/src/agents/cli-agent-runner.js.map +1 -1
  149. package/dist/src/commands/config.d.ts.map +1 -1
  150. package/dist/src/commands/config.js +29 -1
  151. package/dist/src/commands/config.js.map +1 -1
  152. package/dist/src/commands/delegate.d.ts +2 -0
  153. package/dist/src/commands/delegate.d.ts.map +1 -1
  154. package/dist/src/commands/delegate.js +18 -0
  155. package/dist/src/commands/delegate.js.map +1 -1
  156. package/dist/src/commands/launcher.d.ts.map +1 -1
  157. package/dist/src/commands/launcher.js +27 -4
  158. package/dist/src/commands/launcher.js.map +1 -1
  159. package/dist/src/config/cli-tools-config.d.ts +6 -0
  160. package/dist/src/config/cli-tools-config.d.ts.map +1 -1
  161. package/dist/src/config/cli-tools-config.js +2 -0
  162. package/dist/src/config/cli-tools-config.js.map +1 -1
  163. package/dist/src/core/overlay/applier.d.ts.map +1 -1
  164. package/dist/src/core/overlay/applier.js +65 -5
  165. package/dist/src/core/overlay/applier.js.map +1 -1
  166. package/dist/src/core/overlay/loader.d.ts.map +1 -1
  167. package/dist/src/core/overlay/loader.js +9 -4
  168. package/dist/src/core/overlay/loader.js.map +1 -1
  169. package/dist/src/core/overlay/types.d.ts +2 -0
  170. package/dist/src/core/overlay/types.d.ts.map +1 -1
  171. package/dist/src/core/overlay/types.js +2 -0
  172. package/dist/src/core/overlay/types.js.map +1 -1
  173. package/dist/src/tui/tools-ui/ToolsDashboard.d.ts.map +1 -1
  174. package/dist/src/tui/tools-ui/ToolsDashboard.js +1 -1
  175. package/dist/src/tui/tools-ui/ToolsDashboard.js.map +1 -1
  176. package/dist/src/tui/tools-ui/ToolsOverview.d.ts.map +1 -1
  177. package/dist/src/tui/tools-ui/ToolsOverview.js +51 -4
  178. package/dist/src/tui/tools-ui/ToolsOverview.js.map +1 -1
  179. package/package.json +1 -1
  180. package/shared/agent-types.ts +2 -0
  181. package/workflows/analyze.md +24 -2
  182. package/workflows/auto-test.md +12 -0
  183. package/workflows/brainstorm.md +11 -1
  184. package/workflows/debug.md +13 -4
  185. package/workflows/delegate-protocol.codex.md +65 -0
  186. package/workflows/plan.md +14 -4
  187. package/workflows/test.md +10 -0
@@ -1,578 +1,693 @@
1
- ---
2
- name: maestro-ralph
3
- description: Closed-loop lifecycle decision engine read state, infer position, build adaptive chain, execute via CSV waves, delegate-evaluate at decision nodes
4
- argument-hint: "\"intent\" [-y] | status | continue | execute"
5
- allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
6
- ---
7
-
8
- <purpose>
9
- Closed-loop decision engine for the maestro workflow lifecycle.
10
- Coordinator assembles fully-resolved skill calls → spawns via `spawn_agents_on_csv` →
11
- delegates evaluation at decision nodes → dynamically expands/shrinks chain.
12
-
13
- Entry points:
14
- - **`$maestro-ralph "intent"`** — New session: read state → infer → build → execute
15
- - **`$maestro-ralph execute`** / **`continue`** — Resume: run next wave(s) until decision or completion
16
- - **`$maestro-ralph status`** — Display session progress
17
-
18
- Two node types:
19
- - **external**: Executed via `spawn_agents_on_csv`. Barrier steps solo; non-barriers parallel.
20
- - **decision**: Delegate evaluation via `maestro delegate --role analyze`, then expand/proceed/escalate.
21
-
22
- Key difference from maestro coordinator:
23
- - maestro: static chain → run all waves
24
- - ralph: living chain → decision nodes delegate-evaluate → chain adapts dynamically
25
-
26
- Session at `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`.
27
- </purpose>
28
-
29
- <context>
30
- $ARGUMENTS — intent text or keywords.
31
-
32
- **Routing:**
33
- ```
34
- "status" → handleStatus(). End.
35
- "execute" | "continue"→ Phase 2 (Wave Execution).
36
- otherwise → Phase 1 (New Session).
37
- ```
38
-
39
- **Flags:**
40
- - `-y` / `--yes` `session.auto_mode = true`
41
- - Skip confirmation prompts
42
- - Decision nodes: auto-follow delegate verdict (no STOP), except post-debug-escalate
43
- - Failures: retry once then skip
44
-
45
- **`-y` downstream propagation** (appended to skill_call in CSV):
46
-
47
- | Skill | Flag | Effect |
48
- |-------|------|--------|
49
- | maestro-init | `-y` | 跳过交互提问 |
50
- | maestro-analyze | `-y` | 跳过 scoping 交互 |
51
- | maestro-brainstorm | `-y` | 跳过交互提问 |
52
- | maestro-roadmap | `-y` | 跳过交互选择 |
53
- | maestro-plan | `-y` | 跳过确认和澄清 |
54
- | maestro-execute | `-y` | 跳过确认,blocked 自动继续 |
55
- | quality-auto-test | `-y` | 跳过计划确认 |
56
- | quality-test | `-y --auto-fix` | 自动触发 gap-fix loop |
57
- | maestro-milestone-complete | `-y` | 跳过 knowledge promotion 交互 |
58
-
59
- 未列出的命令无 auto flag,原样执行。
60
- </context>
61
-
62
- <invariants>
63
- 1. **ALL external steps via spawn_agents_on_csv** — coordinator NEVER executes skill logic directly
64
- 2. **Coordinator = prompt assembler** — classify → enrich args → build CSV → spawn → read results → assemble next
65
- 3. **Decision nodes delegate-evaluate** — use `maestro delegate --role analyze` for quality-gate assessment; structural decisions (post-milestone, post-debug-escalate) evaluated directly
66
- 4. **Decision STOP behavior** — default: STOP after evaluation; `-y` mode: auto-continue (except post-debug-escalate always STOPs)
67
- 5. **Barrier = solo wave** — analyze, plan, execute, brainstorm, roadmap always run alone
68
- 6. **Non-barriers can parallel** — consecutive non-barrier, non-decision external steps grouped into one wave
69
- 7. **Wave-by-wave** — never start wave N+1 before wave N results are read
70
- 8. **Coordinator owns context** — sub-agents never read prior results; coordinator assembles full skill_call
71
- 9. **Abort on failure** — `-y`: retry once then skip; non-`-y`: mark remaining skipped → pause
72
- 10. **Quality mode governs steps** — full/standard/quick determines which quality stages are included
73
- 11. **passed_gates skip** — already-passed gates not re-run in retry loops (unless code changed)
74
- </invariants>
75
-
76
- <execution>
77
-
78
- ## Phase 1: New Session
79
-
80
- ### 1.1: Read project state
81
-
82
- Read `.workflow/state.json` schema:
83
- ```json
84
- {
85
- "current_milestone": "MVP",
86
- "milestones": [{ "id": "M1", "name": "MVP", "status": "active", "phases": [1, 2] }],
87
- "artifacts": [{
88
- "id": "ANL-001", "type": "analyze|plan|execute|verify",
89
- "milestone": "MVP", "phase": 1, "scope": "phase|milestone|adhoc|standalone",
90
- "path": "phases/01-auth-multi-tenant", // relative to .workflow/scratch/
91
- "status": "completed", "depends_on": "PLN-001", "harvested": true
92
- }],
93
- "accumulated_context": { "key_decisions": [], "deferred": [] }
94
- }
95
- ```
96
-
97
- ### 1.2: Infer lifecycle position
98
-
99
- **Bootstrap detection:**
100
-
101
- | Condition | Position | Chain starts at |
102
- |-----------|----------|-----------------|
103
- | No `.workflow/` + no source files | `brainstorm` | brainstorm init → roadmap → ... |
104
- | No `.workflow/` + has source files | `init` | initroadmap... |
105
- | Has `.workflow/` but no state.json | `init` | init roadmap ... |
106
- | Has state.json | Artifact-based inference below |
107
-
108
- **Artifact-based inference:**
109
-
110
- Filter by `milestone == current_milestone`, target phase. Find latest completed artifact type:
111
-
112
- | State | Position |
113
- |-------|----------|
114
- | No milestones[] or no roadmap.md | `roadmap` |
115
- | No artifacts for target phase | `analyze` |
116
- | Latest == "analyze" | `plan` |
117
- | Latest == "plan" | `execute` |
118
- | Latest == "execute" | `verify` |
119
- | Latest == "verify" | → Refine by result files |
120
-
121
- **Refine from verify results** (read `{artifact_dir}/`):
122
-
123
- | Condition | Position |
124
- |-----------|----------|
125
- | verification.json: `passed==false` or `gaps[]` non-empty | `verify-failed` |
126
- | verification.json: `passed==true`, no review.json | `post-verify` |
127
- | review.json: `verdict=="BLOCK"` | `review-failed` |
128
- | review.json: `verdict!="BLOCK"` | `test` |
129
- | uat.md: all passed | `milestone-audit` |
130
- | uat.md: has failures | `test-failed` |
131
-
132
- **resolve_artifact_dir(artifact):**
133
- ```
134
- Full path = .workflow/scratch/{artifact.path}/
135
- Fallback: glob .workflow/scratch/*-P{phase}-*/ sorted by date DESC, take first
136
- ```
137
-
138
- ### 1.3: Determine quality mode
139
-
140
- **Auto-inference (can be overridden by user to any mode):**
141
-
142
- | Condition | Mode | Pipeline |
143
- |-----------|------|----------|
144
- | Has requirements/REQ-*.md + phase scope | `full` | verify → business-test → review → test-gen → test |
145
- | Default | `standard` | verify → review → test (test-gen conditional on coverage < 80%) |
146
- | User explicit `--quality quick` | `quick` | verify → review --tier quick |
147
-
148
- User can specify `--quality full|standard|quick` to override auto-inference.
149
-
150
- ### 1.4: Build command sequence
151
-
152
- **Lifecycle stages:**
153
-
154
- | Stage | Skill | Barrier | Decision after | Condition |
155
- |-------|-------|---------|----------------|-----------|
156
- | brainstorm | `maestro-brainstorm "{intent}"` | yes | | 0→1 only |
157
- | init | `maestro-init` | no | — | always |
158
- | roadmap | `maestro-roadmap "{intent}"` | yes | — | always |
159
- | analyze | `maestro-analyze {phase}` | yes | — | always |
160
- | plan | `maestro-plan {phase}` | yes | | always |
161
- | execute | `maestro-execute {phase}` | yes | — | always |
162
- | verify | `maestro-verify {phase}` | no | `post-verify` | always |
163
- | business-test | `quality-auto-test {phase}` | no | `post-biz-test` | full only |
164
- | review | `quality-review {phase}` | no | `post-review` | always (quick: +`--tier quick`) |
165
- | test-gen | `quality-auto-test {phase}` | no | | full; standard if coverage < 80% |
166
- | test | `quality-test {phase}` | no | `post-test` | full/standard |
167
- | milestone-audit | `maestro-milestone-audit` | no | — | always |
168
- | milestone-complete | `maestro-milestone-complete` | no | `post-milestone` | always |
169
-
170
- **Build rules:**
171
- 1. Start from inferred position, skip completed stages
172
- 2. Filter by quality_mode (remove inapplicable stages)
173
- 3. After each decision-triggering stage, insert decision node: `{ decision, retry_count: 0, max_retries: 2 }`
174
- 4. Conditional steps (test-gen in standard) use: `{ "condition": "check_coverage", "threshold": 80 }`
175
- 5. Args use placeholders resolved at wave build time by coordinator
176
-
177
- ### 1.5: Create session
178
-
179
- Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`:
180
- ```json
181
- {
182
- "session_id": "ralph-{YYYYMMDD-HHmmss}",
183
- "source": "ralph",
184
- "created_at": "ISO", "updated_at": "ISO",
185
- "intent": "{user_intent}",
186
- "status": "running",
187
- "chain_name": "ralph-lifecycle",
188
- "lifecycle_position": "{position}",
189
- "target": "milestone-complete",
190
- "phase": null | N,
191
- "milestone": null | "{M}",
192
- "auto_mode": false,
193
- "quality_mode": "standard",
194
- "passed_gates": [],
195
- "context": {
196
- "issue_id": null, "milestone_num": null, "spec_session_id": null,
197
- "scratch_dir": null, "plan_dir": null, "analysis_dir": null, "brainstorm_dir": null
198
- },
199
- "steps": [...],
200
- "waves": [],
201
- "current_step": 0
202
- }
203
- ```
204
-
205
- ### 1.6: Initialize plan + confirm
206
-
207
- ```
208
- functions.update_plan({
209
- explanation: "Ralph lifecycle: {position} → milestone-complete",
210
- plan: steps.map(step => ({ step: stepLabel(step), status: "pending" }))
211
- })
212
- ```
213
-
214
- Display:
215
- ```
216
- ============================================================
217
- RALPH DECISION ENGINE
218
- ============================================================
219
- Position: {position} (Phase {N}, {milestone})
220
- Target: milestone-complete
221
- Quality: {quality_mode}
222
- Steps: {total} ({decision_count} decision points)
223
-
224
- [ ] 0. maestro-plan {phase} [barrier]
225
- [ ] 1. maestro-execute {phase} [barrier]
226
- [ ] 2. maestro-verify {phase} [external]
227
- [ ] 3. post-verify [decision]
228
- ...
229
- ============================================================
230
- ```
231
-
232
- - If `-y`: proceed directly
233
- - Else: AskUserQuestion Proceed / Cancel / Change quality mode
234
-
235
- Fall through to Phase 2.
236
-
237
- ---
238
-
239
- ## Phase 2: Wave Execution Loop
240
-
241
- ### 2.1: Load session + find next step
242
-
243
- Read status.json. Rebuild `update_plan` from step statuses.
244
- Find first pending step.
245
-
246
- - If decision node Step 2.2 (Delegate Evaluation)
247
- - If external node Step 2.3 (Wave Execution)
248
- - If no pending Phase 3 (Completion)
249
-
250
- ### 2.2: Delegate Evaluation (decision nodes)
251
-
252
- **Route by decision type:**
253
- - Quality-gate decisions (post-verify, post-biz-test, post-review, post-test) → delegate analysis
254
- - Structural decisions (post-milestone, post-debug-escalate) → direct evaluation
255
-
256
- #### 2.2a: Delegate quality-gate assessment
257
-
258
- Read decision metadata: `{ decision, retry_count, max_retries }`
259
-
260
- **Result file mapping:**
261
-
262
- | Decision | Files to include |
263
- |----------|-----------------|
264
- | post-verify | `{artifact_dir}/verification.json` |
265
- | post-biz-test | `{artifact_dir}/business-test-results.json` |
266
- | post-review | `{artifact_dir}/review.json` |
267
- | post-test | `{artifact_dir}/uat.md`, `{artifact_dir}/.tests/test-results.json` |
268
-
269
- ```
270
- Bash({
271
- command: `maestro delegate "PURPOSE: 评估 ${meta.decision} 质量门结果
272
- TASK: 读取结果文件 | 分析通过/失败 | 评估严重性 | 给出建议
273
- MODE: analysis
274
- CONTEXT: @${result_files}
275
- EXPECTED: 严格按格式输出:
276
- ---VERDICT---
277
- STATUS: proceed | fix | escalate
278
- REASON: 一句话解释
279
- GAP_SUMMARY: 问题描述(fix/escalate 时填写)
280
- CONFIDENCE: high | medium | low
281
- ---END---
282
- CONSTRAINTS: 只评估 | STATUS 三选一 | retry ${meta.retry_count}/${meta.max_retries} 达上限必须 escalate" --role analyze --mode analysis`,
283
- run_in_background: true
284
- })
285
- STOP — wait for callback.
286
- ```
287
-
288
- **Parse verdict** (on callback):
289
- ```
290
- Extract STATUS / REASON / GAP_SUMMARY / CONFIDENCE from output.
291
- If parse fails → fallback: STATUS = "fix", GAP_SUMMARY = generic
292
- ```
293
-
294
- **Apply verdict:**
295
-
296
- | Mode | Behavior |
297
- |------|----------|
298
- | `-y` (auto_mode) | Follow verdict directly, no user prompt |
299
- | Interactive | Display recommendation, AskUserQuestion: "按建议执行 / 覆盖 / 取消" |
300
-
301
- **Verdict action:**
302
-
303
- | Verdict | Action |
304
- |---------|--------|
305
- | `proceed` | Add gate to passed_gates, continue |
306
- | `fix` | Clear passed_gates (code will change), insert fix-loop |
307
- | `escalate` | Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]` |
308
-
309
- #### 2.2b: Fix-loop templates
310
-
311
- The delegate's `gap_summary` is passed as context to `quality-debug`.
312
-
313
- **post-verify fix-loop:**
314
- ```
315
- quality-debug "{gap_summary}"
316
- maestro-plan --gaps {phase} [barrier]
317
- maestro-execute {phase} [barrier]
318
- maestro-verify {phase}
319
- decision:post-verify {retry+1}
320
- ```
321
-
322
- **post-biz-test fix-loop (full mode):**
323
- ```
324
- quality-debug --from-business-test "{gap_summary}"
325
- maestro-plan --gaps {phase} [barrier]
326
- maestro-execute {phase} [barrier]
327
- maestro-verify {phase}
328
- decision:post-verify {retry: 0}
329
- quality-auto-test {phase}
330
- decision:post-biz-test {retry+1}
331
- ```
332
-
333
- **post-review fix-loop:**
334
- ```
335
- quality-debug "{gap_summary}"
336
- maestro-plan --gaps {phase} [barrier]
337
- maestro-execute {phase} [barrier]
338
- quality-review {phase}
339
- decision:post-review {retry+1}
340
- ```
341
-
342
- **post-test fix-loop:**
343
- ```
344
- quality-debug --from-uat "{gap_summary}"
345
- maestro-plan --gaps {phase} [barrier]
346
- maestro-execute {phase} [barrier]
347
- maestro-verify {phase}
348
- decision:post-verify {retry: 0}
349
- quality-test {phase}
350
- decision:post-test {retry+1}
351
- ```
352
-
353
- #### 2.2c: Structural decisions (direct evaluation)
354
-
355
- **post-milestone:**
356
- ```
357
- Read .workflow/state.json check next milestone (status "pending"/"active")
358
- If found: update session (milestone, phase, reset passed_gates), re-infer quality_mode,
359
- insert lifecycle via buildSteps() for next milestone
360
- If none: proceed — session completes naturally
361
- ```
362
-
363
- **post-debug-escalate:**
364
- ```
365
- Set session status = "paused"
366
- Display: 已达最大重试次数,debug 已执行。请人工介入检查结果。
367
- STOP (always, regardless of -y)
368
- ```
369
-
370
- #### 2.2d: Finalize decision
371
-
372
- ```
373
- Mark decision step "completed"
374
- Reindex steps if commands inserted
375
- Write status.json
376
- Sync update_plan
377
-
378
- Display: Decision: {type} {verdict.status} ({verdict.reason})
379
-
380
- STOP behavior:
381
- post-debug-escalate always STOP
382
- auto_mode == true → no STOP, continue to 2.3
383
- auto_mode == false → STOP. Display: ⏸ 使用 $maestro-ralph execute 继续
384
- ```
385
-
386
- ### 2.3: Build and Execute Wave
387
-
388
- **Loop while pending non-decision steps exist:**
389
-
390
- **1. buildNextWave:**
391
- - Conditional step → evaluate condition, skip if not met:
392
- - `check_coverage`: read `{artifact_dir}/validation.json`, if `coverage >= threshold` → skip test-gen; else → include
393
- - If validation.json not found include (assume coverage insufficient)
394
- - Barrier step solo wave (single row CSV)
395
- - Non-barrier collect consecutive non-barrier, non-decision steps (multi-row CSV)
396
- - Stop at first decision node
397
-
398
- **2. buildSkillCall(step, session)** — assemble fully-resolved command:
399
-
400
- Placeholder resolution:
401
- ```
402
- {phase} → session.phase
403
- {intent} session.intent
404
- {scratch_dir} → latest artifact path
405
- {plan_dir} session.context.plan_dir
406
- {analysis_dir} session.context.analysis_dir
407
- ```
408
-
409
- Per-skill enrichment:
410
- | Skill | Enrichment |
411
- |-------|-----------|
412
- | maestro-brainstorm | args empty → `"{intent}"` |
413
- | maestro-roadmap | args empty `"{intent}"` |
414
- | maestro-analyze | args empty → `{phase}` |
415
- | maestro-plan | resolve latest analyze artifact → `--dir .workflow/scratch/{path}` |
416
- | maestro-execute | resolve latest plan artifact → `--dir .workflow/scratch/{path}` |
417
- | quality-debug | append gap_summary or `--from-uat`/`--from-business-test` |
418
- | quality-* / maestro-verify / milestone-* | args empty → `{phase}` or empty |
419
-
420
- Auto flag: append from propagation table if `auto_mode == true`.
421
-
422
- Result: `$<skill-name> <enriched-args> [auto-flag]`
423
-
424
- **3. Write wave CSV:** `{sessionDir}/wave-{N}.csv`
425
-
426
- **4. Update plan** (mark wave steps in_progress)
427
-
428
- **5. Spawn:**
429
- ```
430
- spawn_agents_on_csv({
431
- csv_path: "{sessionDir}/wave-{N}.csv",
432
- id_column: "id",
433
- instruction: WAVE_INSTRUCTION,
434
- max_workers: <wave_size>,
435
- max_runtime_seconds: 3600,
436
- output_csv_path: "{sessionDir}/wave-{N}-results.csv",
437
- output_schema: RESULT_SCHEMA
438
- })
439
- ```
440
-
441
- **6. Read results** — update step statuses from results CSV
442
-
443
- **7. Barrier context update:**
444
-
445
- | Barrier | Read | Update |
446
- |---------|------|--------|
447
- | maestro-analyze | context.md, state.json | context.analysis_dir |
448
- | maestro-plan | plan.json | context.plan_dir |
449
- | maestro-execute | results | context.exec_status |
450
- | maestro-brainstorm | .brainstorming/ | context.brainstorm_dir |
451
- | maestro-roadmap | specs/ | context.spec_session_id |
452
-
453
- **8. Persist** — write status.json + sync update_plan
454
-
455
- **9. Failure check:**
456
- - `-y`: retry once, then skip and continue
457
- - Non-`-y`: mark remaining skipped → pause → STOP
458
-
459
- **10. Next step check:**
460
- - Decision node + auto_mode → loop to 2.2
461
- - Decision node + non-auto STOP
462
- - External node → loop to step 1
463
-
464
- ---
465
-
466
- ## Phase 3: Completion
467
-
468
- ```
469
- status.status = "completed"
470
- status.updated_at = now
471
- Write status.json
472
-
473
- functions.update_plan({
474
- explanation: "Ralph lifecycle complete",
475
- plan: steps.map(step => ({ step: stepLabel(step), status: "completed" }))
476
- })
477
- ```
478
-
479
- Display:
480
- ```
481
- ============================================================
482
- RALPH COMPLETE
483
- ============================================================
484
- Session: {session_id}
485
- Quality: {quality_mode}
486
- Phase: {phase} {milestone}
487
- Waves: {wave_count} executed
488
- Steps: {completed}/{total} ({skipped} skipped)
489
-
490
- [✓] 0. maestro-plan 1 [W1]
491
- [✓] 1. maestro-execute 1 [W2]
492
- [✓] 2. maestro-verify 1 [W3]
493
- [✓] 3. ◆ post-verify → proceed [decision]
494
- [~] 4. quality-auto-test 1 [skipped: standard mode]
495
- [✓] 5. quality-review 1 [W4]
496
- ...
497
- ============================================================
498
- ```
499
-
500
- </execution>
501
-
502
- <csv_schema>
503
- ### wave-{N}.csv
504
-
505
- Coordinator 已完成 arg 组装 + auto flag 附加:
506
-
507
- ```csv
508
- id,skill_call,topic
509
- "3","$maestro-verify 1","Ralph step 3/14: verify phase 1"
510
- "4","$quality-review 1 --tier quick","Ralph step 4/14: review phase 1"
511
- ```
512
-
513
- Rules:
514
- - `skill_call`: complete `$<skill> <args> [auto-flag]` from `buildSkillCall()`
515
- - `topic`: human-readable step description
516
- - Non-barrier external + non-decision multi-row (parallel)
517
- - Barrier external single-row (solo)
518
- - Decision nodes NEVER appear in CSV — processed by coordinator directly
519
-
520
- ### Sub-Agent Instruction
521
-
522
- ```
523
- 你是 CSV job agent。
524
-
525
- 执行技能调用:{skill_call}
526
- 任务说明:{topic}
527
-
528
- 限制:
529
- - 不要修改 .workflow/.maestro/ 下的 status 文件
530
- - skill 内部有自己的 session 管理,按 skill SKILL.md 执行
531
-
532
- 完成后调用 `report_agent_job_result`,返回:
533
- {"status":"completed|failed","skill_call":"{skill_call}","summary":"一句话结果","artifacts":"产物路径","error":"失败原因"}
534
- ```
535
-
536
- ### Result Schema
537
-
538
- `{ status, skill_call, summary, artifacts, error }` — all string
539
- </csv_schema>
540
-
541
- <error_codes>
542
- | Code | Severity | Description | Recovery |
543
- |------|----------|-------------|----------|
544
- | E001 | error | No intent and no running session | Prompt for intent |
545
- | E002 | error | Cannot infer lifecycle position | Show raw state, ask user |
546
- | E003 | error | Artifact dir not found for decision | Show glob results, ask user |
547
- | E004 | error | Delegate verdict parse failed | Fallback: treat as "fix" |
548
- | E005 | error | Delegate execution failed | Fallback: treat as "fix" with generic summary |
549
- | E006 | error | Wave timeout (max_runtime_seconds) | Mark step failed, pause |
550
- | E007 | error | No session found for execute/continue | Suggest $maestro-ralph "intent" |
551
- | W001 | warning | Decision node expanded chain | Auto-handled, log expansion |
552
- | W002 | warning | Max retries reached, escalating | Auto-handled |
553
- | W003 | warning | Multiple running sessions found | Use latest, warn user |
554
- | W004 | warning | Delegate confidence == "low" | Show warning in interactive mode |
555
- </error_codes>
556
-
557
- <success_criteria>
558
- - [ ] state.json parsed with actual schema (type, path, scope, milestone, depends_on)
559
- - [ ] Lifecycle position inferred from bootstrap + artifact chain + result files
560
- - [ ] Artifact dir resolved via resolve_artifact_dir() with fallback glob
561
- - [ ] Quality mode (full/standard/quick) correctly inferred and governs step generation
562
- - [ ] Conditional steps evaluated at decision time (coverage threshold)
563
- - [ ] buildSkillCall() completes arg enrichment + auto flag, CSV contains full commands
564
- - [ ] Quality-gate decisions delegate-evaluated via `maestro delegate --role analyze`
565
- - [ ] Delegate verdict parsed: STATUS / REASON / GAP_SUMMARY / CONFIDENCE
566
- - [ ] `-y` mode: auto-follow delegate verdict, no STOP (except post-debug-escalate)
567
- - [ ] Interactive mode: display recommendation + AskUserQuestion with override
568
- - [ ] Delegate failure fallback: treat as "fix" verdict
569
- - [ ] passed_gates[] tracks passed quality gates, skips re-runs in retry loops
570
- - [ ] passed_gates cleared when code changes (fix-loop inserts execute step)
571
- - [ ] Fix-loop templates correctly use gap_summary from delegate
572
- - [ ] retry_count tracked per decision, max_retries enforced → escalation
573
- - [ ] ALL external steps via spawn_agents_on_csv — coordinator never executes directly
574
- - [ ] Barrier steps solo wave, non-barriers parallel
575
- - [ ] functions.update_plan() initialized in 1.6, synced per wave, finalized in Phase 3
576
- - [ ] status.json persisted after every wave and decision
577
- - [ ] Command insertion + reindex preserves step integrity
578
- </success_criteria>
1
+ ---
2
+ name: maestro-ralph
3
+ description: Adaptive lifecycle engine -- infer state, build command chain
4
+ argument-hint: "\"intent\" [-y] | status | continue | execute"
5
+ allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, request_user_input
6
+ ---
7
+
8
+ <purpose>
9
+ Closed-loop decision engine for the maestro workflow lifecycle.
10
+ Coordinator assembles fully-resolved skill calls → spawns via `spawn_agents_on_csv` →
11
+ delegates evaluation at decision nodes → dynamically expands/shrinks chain.
12
+
13
+ Entry points:
14
+ - **`$maestro-ralph "intent"`** — New session: read state → infer → build → execute
15
+ - **`$maestro-ralph execute`** / **`continue`** — Resume: run next wave(s) until decision or completion
16
+ - **`$maestro-ralph status`** — Display session progress
17
+
18
+ Two node types:
19
+ - **external**: Executed via `spawn_agents_on_csv`. Barrier steps solo; non-barriers parallel.
20
+ - **decision**: Delegate evaluation via `maestro delegate --role analyze`, then expand/proceed/escalate.
21
+
22
+ Key difference from maestro coordinator:
23
+ - maestro: static chain → run all waves
24
+ - ralph: living chain → decision nodes delegate-evaluate → chain adapts dynamically
25
+
26
+ Session at `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`.
27
+ </purpose>
28
+
29
+ <context>
30
+ $ARGUMENTS — intent text, flags, or keywords.
31
+
32
+ **State files:**
33
+ - `.workflow/state.json` — artifact registry, milestones, phases
34
+ - `.workflow/roadmap.md` — milestone/phase structure
35
+ - `.workflow/.maestro/ralph-*/status.json` ralph session state
36
+
37
+ **Parse & Route:**
38
+ ```
39
+ Parse $ARGUMENTS:
40
+ -y / --yes → auto_mode = true
41
+ .md/.txt path input_doc (supplementary context for downstream commands)
42
+ Remaining → intent
43
+
44
+ Route:
45
+ intent == "status" → handleStatus(). End.
46
+ intent == "execute" | "continue" → Phase 2 (Wave Execution).
47
+
48
+ Check running ralph session (.workflow/.maestro/ralph-*/status.json, status=="running"):
49
+ If found AND steps[current_step].type == "decision" AND steps[current_step].status == "running":
50
+ Phase 2, Step 2.2 (Delegate Evaluation resume mid-decision)
51
+ Else if intent is non-empty:
52
+ Phase 1 (New Session)
53
+ Else:
54
+ request_user_input: "请描述目标,或输入 status/continue/execute"
55
+ ```
56
+
57
+ HARD RULE: `input_doc` is supplementary context only. It NEVER substitutes for lifecycle stages.
58
+
59
+ ### handleStatus()
60
+ ```
61
+ Find latest ralph session (by created_at).
62
+ Display:
63
+ Session: {id}
64
+ Status: {status}
65
+ Position: {lifecycle_position}
66
+ Quality: {quality_mode}
67
+ Progress: {completed}/{total} steps ({decision_count} decisions)
68
+ Current: [{current_step}] {steps[current_step].skill} [{type}]
69
+
70
+ Steps:
71
+ [✓] 0. maestro-analyze 1 [W1, barrier]
72
+ [▸] 1. maestro-plan 1 [barrier]
73
+ [ ] 2. maestro-execute 1 [barrier]
74
+ [ ] 3. ◆ post-verify [decision]
75
+ ...
76
+ End.
77
+ ```
78
+
79
+ **Flags:**
80
+ - `-y` / `--yes` → `session.auto_mode = true`
81
+ - Skip confirmation prompts
82
+ - Decision nodes: auto-follow delegate verdict (no STOP), except post-debug-escalate
83
+ - Failures: retry once then pause
84
+
85
+ **`-y` downstream propagation** (appended to skill_call in CSV):
86
+
87
+ | Skill | Flag | Effect |
88
+ |-------|------|--------|
89
+ | maestro-init | `-y` | 跳过交互提问 |
90
+ | maestro-analyze | `-y` | 跳过 scoping 交互 |
91
+ | maestro-brainstorm | `-y` | 跳过交互提问 |
92
+ | maestro-roadmap | `-y` | 跳过交互选择 |
93
+ | maestro-plan | `-y` | 跳过确认和澄清 |
94
+ | maestro-execute | `-y` | 跳过确认,blocked 自动继续 |
95
+ | quality-auto-test | `-y` | 跳过计划确认 |
96
+ | quality-test | `-y --auto-fix` | 自动触发 gap-fix loop |
97
+ | maestro-milestone-complete | `-y` | 跳过 knowledge promotion 交互 |
98
+
99
+ 未列出的命令无 auto flag,原样执行。
100
+ </context>
101
+
102
+ <invariants>
103
+ 1. **ALL external steps via spawn_agents_on_csv** coordinator NEVER executes skill logic directly
104
+ 2. **Coordinator = prompt assembler** classify enrich args build CSV spawnread results → assemble next
105
+ 3. **Decision nodes delegate-evaluate** use `maestro delegate --role analyze` for quality-gate assessment; structural decisions (post-milestone, post-debug-escalate) evaluated directly
106
+ 4. **Decision STOP behavior** default: STOP after evaluation; `-y` mode: auto-continue (except post-debug-escalate always STOPs)
107
+ 5. **Barrier = solo wave** — analyze, plan, execute, brainstorm, roadmap always run alone
108
+ 6. **Non-barriers can parallel** — consecutive non-barrier, non-decision external steps grouped into one wave
109
+ 7. **Wave-by-wave** — never start wave N+1 before wave N results are read
110
+ 8. **Coordinator owns context** sub-agents never read prior results; coordinator assembles full skill_call
111
+ 9. **Abort on failure** — `-y`: retry once then pause; non-`-y`: mark remaining skipped → pause
112
+ 10. **Quality mode governs steps** — full/standard/quick determines which quality stages are included
113
+ 11. **passed_gates skip** — already-passed gates not re-run in retry loops (unless code changed)
114
+ </invariants>
115
+
116
+ <execution>
117
+
118
+ ## Phase 1: New Session
119
+
120
+ ### 1.1: Read project state
121
+
122
+ Read `.workflow/state.json` schema:
123
+ ```json
124
+ {
125
+ "current_milestone": "MVP",
126
+ "milestones": [{ "id": "M1", "name": "MVP", "status": "active", "phases": [1, 2] }],
127
+ "artifacts": [{
128
+ "id": "ANL-001", "type": "analyze|plan|execute|verify",
129
+ "milestone": "MVP", "phase": 1, "scope": "phase|milestone|adhoc|standalone",
130
+ "path": "phases/01-auth-multi-tenant", // relative to .workflow/scratch/
131
+ "status": "completed", "depends_on": "PLN-001", "harvested": true
132
+ }],
133
+ "accumulated_context": { "key_decisions": [], "deferred": [] }
134
+ }
135
+ ```
136
+
137
+ ### 1.2: Infer lifecycle position
138
+
139
+ **Intent-based override:**
140
+
141
+ If intent matches brainstorm pattern (contains "brainstorm", "头脑风暴", "探索", "ideate", or "设计思路"), position = `brainstorm` regardless of project state.
142
+
143
+ Chain for existing project: `brainstorm → roadmap → analyze → ...` (skip init if `.workflow/state.json` exists).
144
+
145
+ **Bootstrap detection:**
146
+
147
+ | Condition | Position | Chain starts at |
148
+ |-----------|----------|-----------------|
149
+ | No `.workflow/` + no source files | `brainstorm` | brainstorm → init → roadmap → ... |
150
+ | No `.workflow/` + has source files | `init` | init → roadmap → ... |
151
+ | Has `.workflow/` but no state.json | `init` | init → roadmap → ... |
152
+ | Has state.json | → Artifact-based inference below |
153
+
154
+ **Artifact-based inference:**
155
+
156
+ Filter by `milestone == current_milestone`, target phase. Find latest completed artifact type:
157
+
158
+ | State | Position |
159
+ |-------|----------|
160
+ | No milestones[] or no roadmap.md | `roadmap` |
161
+ | No artifacts for target phase | `analyze` |
162
+ | Latest == "analyze" | `plan` |
163
+ | Latest == "plan" | `execute` |
164
+ | Latest == "execute" | `verify` |
165
+ | Latest == "verify" | Refine by result files |
166
+
167
+ **Refine from verify results** (read `{artifact_dir}/`):
168
+
169
+ | Condition | Position |
170
+ |-----------|----------|
171
+ | verification.json: `passed==false` or `gaps[]` non-empty | `verify-failed` |
172
+ | verification.json: `passed==true`, no review.json, has `.tests/auto-test/report.json` | `review` |
173
+ | verification.json: `passed==true`, no review.json, no `.tests/auto-test/report.json` | `business-test` (full) / `review` (standard/quick) |
174
+ | review.json: `verdict=="BLOCK"` | `review-failed` |
175
+ | review.json: `verdict!="BLOCK"` | `test` |
176
+ | uat.md: all passed | `milestone-audit` |
177
+ | uat.md: has failures | `test-failed` |
178
+
179
+ **resolve_artifact_dir(artifact):**
180
+ ```
181
+ Full path = .workflow/scratch/{artifact.path}/
182
+ Fallback: glob .workflow/scratch/*-P{phase}-*/ sorted by date DESC, take first
183
+ ```
184
+
185
+ ### 1.3: Resolve phase number
186
+
187
+ Priority order:
188
+ 1. Regex from intent: `phase\s*(\d+)` or bare number
189
+ 2. Latest in-progress artifact's phase field
190
+ 3. First incomplete phase in current milestone's `phases[]`
191
+ 4. `null` if position is brainstorm/init/roadmap (deferred to post-roadmap)
192
+ 5. request_user_input if ambiguous (auto_mode does NOT skip this)
193
+
194
+ ### 1.4: Determine quality mode
195
+
196
+ **Auto-inference (can be overridden by user to any mode):**
197
+
198
+ | Condition | Mode | Pipeline |
199
+ |-----------|------|----------|
200
+ | Has requirements/REQ-*.md + phase scope | `full` | verify → business-test → review → test-gen → test |
201
+ | Default | `standard` | verify → review → test (test-gen conditional on coverage < 80%) |
202
+ | User explicit `--quality quick` | `quick` | verify → review --tier quick |
203
+
204
+ User can specify `--quality full|standard|quick` to override auto-inference.
205
+
206
+ ### 1.5: Build command sequence
207
+
208
+ **Lifecycle stages:**
209
+
210
+ | Stage | Skill | Barrier | Decision after | Condition |
211
+ |-------|-------|---------|----------------|-----------|
212
+ | brainstorm | `maestro-brainstorm "{intent}"` | yes | — | intent-override or 0→1 bootstrap |
213
+ | init | `maestro-init` | no | — | always |
214
+ | roadmap | `maestro-roadmap "{intent}"` | yes | — | always |
215
+ | analyze | `maestro-analyze {phase}` | yes | — | always |
216
+ | plan | `maestro-plan {phase}` | yes | — | always |
217
+ | execute | `maestro-execute {phase}` | yes | — | always |
218
+ | verify | `maestro-verify {phase}` | no | `post-verify` | always |
219
+ | business-test | `quality-auto-test {phase}` | no | `post-business-test` | full only |
220
+ | review | `quality-review {phase}` | no | `post-review` | always (quick: +`--tier quick`) |
221
+ | test-gen | `quality-auto-test {phase}` | no | — | full; standard if coverage < 80% |
222
+ | test | `quality-test {phase}` | no | `post-test` | full/standard |
223
+ | milestone-audit | `maestro-milestone-audit` | no | — | always |
224
+ | milestone-complete | `maestro-milestone-complete` | no | `post-milestone` | always |
225
+
226
+ **Build rules:**
227
+ 1. Start from inferred position, skip completed stages
228
+ 2. Filter by quality_mode (remove inapplicable stages)
229
+ 3. After each decision-triggering stage, insert decision node: `{ decision, retry_count: 0, max_retries: 2 }`
230
+ 4. Conditional steps (test-gen in standard) use: `{ "condition": "check_coverage", "threshold": 80 }`
231
+ 5. Phase-independent commands (brainstorm, roadmap, init) use `"{intent}"` as args
232
+ 6. Commands needing prior output (analyze→plan, plan→execute) have args resolved via artifact lookup at wave build time by coordinator (see buildSkillCall enrichment table in 2.3)
233
+ 7. Args use placeholders resolved at wave build time by coordinator
234
+
235
+ **Example from "plan" position, standard quality mode:**
236
+ ```json
237
+ [
238
+ { "index": 0, "type": "external", "skill": "maestro-plan", "args": "{phase}", "barrier": true },
239
+ { "index": 1, "type": "external", "skill": "maestro-execute", "args": "{phase}", "barrier": true },
240
+ { "index": 2, "type": "external", "skill": "maestro-verify", "args": "{phase}" },
241
+ { "index": 3, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-verify\",\"retry_count\":0,\"max_retries\":2}" },
242
+ { "index": 4, "type": "external", "skill": "quality-review", "args": "{phase}" },
243
+ { "index": 5, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-review\",\"retry_count\":0,\"max_retries\":2}" },
244
+ { "index": 6, "type": "external", "skill": "quality-auto-test", "args": "{phase}", "condition": "check_coverage" },
245
+ { "index": 7, "type": "external", "skill": "quality-test", "args": "{phase}" },
246
+ { "index": 8, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-test\",\"retry_count\":0,\"max_retries\":2}" },
247
+ { "index": 9, "type": "external", "skill": "maestro-milestone-audit", "args": "" },
248
+ { "index": 10, "type": "external", "skill": "maestro-milestone-complete", "args": "" },
249
+ { "index": 11, "type": "decision", "skill": "maestro-ralph", "args": "{\"decision\":\"post-milestone\"}" }
250
+ ]
251
+ ```
252
+
253
+ ### 1.6: Create session
254
+
255
+ Write `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`:
256
+ ```json
257
+ {
258
+ "session_id": "ralph-{YYYYMMDD-HHmmss}",
259
+ "source": "ralph",
260
+ "created_at": "ISO", "updated_at": "ISO",
261
+ "intent": "{user_intent}",
262
+ "status": "running",
263
+ "chain_name": "ralph-lifecycle",
264
+ "task_type": "lifecycle",
265
+ "lifecycle_position": "{position}",
266
+ "target": "milestone-complete",
267
+ "phase": null | N,
268
+ "milestone": null | "{M}",
269
+ "auto_mode": false,
270
+ "quality_mode": "standard",
271
+ "passed_gates": [],
272
+ "context": {
273
+ "issue_id": null, "milestone_num": null, "spec_session_id": null,
274
+ "scratch_dir": null, "plan_dir": null, "analysis_dir": null, "brainstorm_dir": null
275
+ },
276
+ "steps": [...],
277
+ "waves": [],
278
+ "current_step": 0
279
+ }
280
+ ```
281
+
282
+ ### 1.7: Initialize plan + confirm
283
+
284
+ ```
285
+ functions.update_plan({
286
+ explanation: "Ralph lifecycle: {position} → milestone-complete",
287
+ plan: steps.map(step => ({ step: stepLabel(step), status: "pending" }))
288
+ })
289
+ ```
290
+
291
+ Display:
292
+ ```
293
+ ============================================================
294
+ RALPH DECISION ENGINE
295
+ ============================================================
296
+ Position: {position} (Phase {N}, {milestone})
297
+ Target: milestone-complete
298
+ Quality: {quality_mode}
299
+ Steps: {total} ({decision_count} decision points)
300
+
301
+ [ ] 0. maestro-plan {phase} [barrier]
302
+ [ ] 1. maestro-execute {phase} [barrier]
303
+ [ ] 2. maestro-verify {phase} [external]
304
+ [ ] 3. ◆ post-verify [decision]
305
+ ...
306
+ ============================================================
307
+ ```
308
+
309
+ - If `-y`: proceed directly
310
+ - Else: request_user_input → Proceed / Edit / Cancel / Change quality mode
311
+
312
+ Fall through to Phase 2.
313
+
314
+ ---
315
+
316
+ ## Phase 2: Wave Execution Loop
317
+
318
+ ### 2.1: Load session + find next step
319
+
320
+ Read status.json. Rebuild `update_plan` from step statuses.
321
+ Find first pending step.
322
+
323
+ - If decision node → Step 2.2 (Delegate Evaluation)
324
+ - If external node → Step 2.3 (Wave Execution)
325
+ - If no pending → Phase 3 (Completion)
326
+
327
+ ### 2.2: Delegate Evaluation (decision nodes)
328
+
329
+ **Route by decision type:**
330
+ - Quality-gate decisions (post-verify, post-business-test, post-review, post-test) → delegate analysis
331
+ - Structural decisions (post-milestone, post-debug-escalate) → direct evaluation
332
+
333
+ #### 2.2a: Delegate quality-gate assessment
334
+
335
+ Read decision metadata: `{ decision, retry_count, max_retries }`
336
+
337
+ **Result file mapping:**
338
+
339
+ | Decision | Files to include |
340
+ |----------|-----------------|
341
+ | post-verify | `{artifact_dir}/verification.json` |
342
+ | post-business-test | `{artifact_dir}/.tests/auto-test/report.json` |
343
+ | post-review | `{artifact_dir}/review.json` |
344
+ | post-test | `{artifact_dir}/uat.md`, `{artifact_dir}/.tests/test-results.json` |
345
+
346
+ ```
347
+ exec_command({
348
+ cmd: `maestro delegate "PURPOSE: 评估 ${meta.decision} 质量门结果
349
+ TASK: 读取结果文件 | 分析通过/失败 | 评估严重性 | 给出建议
350
+ MODE: analysis
351
+ CONTEXT: @${result_files}
352
+ EXPECTED: 严格按格式输出:
353
+ ---VERDICT---
354
+ STATUS: proceed | fix | escalate
355
+ REASON: 一句话解释
356
+ GAP_SUMMARY: 问题描述(fix/escalate 时填写)
357
+ CONFIDENCE: high | medium | low
358
+ CONFIDENCE_SCORE: 0-100(从结果文件中读取置信度分数,无则估算)
359
+ WEAKEST_DIMENSION: 最弱维度名称
360
+ ---END---
361
+ CONSTRAINTS: 只评估 | STATUS 三选一 | 置信度 < 60% 倾向 fix | retry ${meta.retry_count}/${meta.max_retries} 达上限必须 escalate" --role analyze --mode analysis`,
362
+ yield_time_ms: 30000,
363
+ max_output_tokens: 6000
364
+ })
365
+ // ⚠️ If session_id returned → poll write_stdin until completion (see @~/.maestro/workflows/delegate-protocol.codex.md)
366
+ // NEVER skip — verdict is required for decision routing
367
+ ```
368
+
369
+ **Parse verdict** (on callback):
370
+ ```
371
+ Extract STATUS / REASON / GAP_SUMMARY / CONFIDENCE / CONFIDENCE_SCORE / WEAKEST_DIMENSION from output.
372
+ If parse fails → fallback: STATUS = "fix", GAP_SUMMARY = generic
373
+
374
+ Confidence-based verdict adjustment (after parse, before apply):
375
+ If CONFIDENCE_SCORE < 60 AND STATUS == "proceed":
376
+ Override to "fix", REASON += " (置信度不足: {score}%,{weakest} 需加强)"
377
+ If CONFIDENCE_SCORE > 95 AND STATUS == "fix" AND retry_count > 0:
378
+ Suggest "proceed" override, REASON += " (置信度充分: {score}%,建议通过)"
379
+ ```
380
+
381
+ **Confidence-aware evaluation**: Before delegating, check if artifact contains confidence section (added by downstream commands). If found, include `已有置信度评估: 整体 {overall}%, 最弱维度: {weakest} ({score}%)` in delegate prompt as additional signal.
382
+
383
+ **Apply verdict:**
384
+
385
+ | Mode | Behavior |
386
+ |------|----------|
387
+ | `-y` (auto_mode) | Follow adjusted verdict directly, no user prompt |
388
+ | Interactive + confidence_score >= 80 | Display recommendation with confidence, prompt user |
389
+ | Interactive + confidence_score < 80 | Display recommendation **with confidence warning**, prompt user |
390
+
391
+ Interactive prompt (via `request_user_input`):
392
+ ```json
393
+ { "questions": [{ "id": "decision_override", "header": "◆ {meta.decision} 评估结果", "question": "STATUS: {verdict.status}\nREASON: {verdict.reason}\n\n选择操作:", "options": [
394
+ { "label": "按建议执行 (Recommended)", "description": "执行 {verdict.status} 操作" },
395
+ { "label": "覆盖 proceed", "description": "忽略问题,强制通过" },
396
+ { "label": "覆盖 fix", "description": "强制进入修复循环" },
397
+ { "label": "取消", "description": "暂停会话,手动处理" }
398
+ ]}] }
399
+ ```
400
+
401
+ **Verdict → action:**
402
+
403
+ | Verdict | Action |
404
+ |---------|--------|
405
+ | `proceed` | Add gate to passed_gates, continue |
406
+ | `fix` | Clear passed_gates (code will change), insert fix-loop |
407
+ | `escalate` | Insert `[quality-debug "{gap_summary}", decision:post-debug-escalate]` |
408
+
409
+ #### 2.2b: Fix-loop templates
410
+
411
+ The delegate's `gap_summary` is passed as context to `quality-debug`.
412
+
413
+ **passed_gates reset**: Every fix-loop inserts `maestro-execute` (code changes), so `passed_gates` is cleared at insertion time (see 2.2a verdict action). Downstream decision nodes restart with `retry: 0` to re-validate against modified code. Only the triggering decision's own `retry_count` increments.
414
+
415
+ **post-verify fix-loop:**
416
+ Reset: `passed_gates = []` (code changed via execute)
417
+ ```
418
+ quality-debug "{gap_summary}"
419
+ maestro-plan --gaps {phase} [barrier]
420
+ maestro-execute {phase} [barrier]
421
+ maestro-verify {phase}
422
+ decision:post-verify {retry+1}
423
+ ```
424
+
425
+ **post-business-test fix-loop (full mode):**
426
+ Reset: `passed_gates = []` (code changed via execute); post-verify restarts at retry: 0
427
+ ```
428
+ quality-debug --from-business-test "{gap_summary}"
429
+ maestro-plan --gaps {phase} [barrier]
430
+ maestro-execute {phase} [barrier]
431
+ maestro-verify {phase}
432
+ decision:post-verify {retry: 0}
433
+ quality-auto-test {phase}
434
+ decision:post-business-test {retry+1}
435
+ ```
436
+
437
+ **post-review fix-loop:**
438
+ Reset: `passed_gates = []` (code changed via execute); post-verify restarts at retry: 0
439
+ ```
440
+ quality-debug "{gap_summary}"
441
+ maestro-plan --gaps {phase} [barrier]
442
+ maestro-execute {phase} [barrier]
443
+ maestro-verify {phase}
444
+ decision:post-verify {retry: 0}
445
+ quality-review {phase}
446
+ decision:post-review {retry+1}
447
+ ```
448
+
449
+ **post-test fix-loop:**
450
+ Reset: `passed_gates = []` (code changed via execute); all downstream decisions restart at retry: 0
451
+ ```
452
+ quality-debug --from-uat "{gap_summary}"
453
+ maestro-plan --gaps {phase} [barrier]
454
+ maestro-execute {phase} [barrier]
455
+ maestro-verify {phase}
456
+ decision:post-verify {retry: 0}
457
+ quality-auto-test {phase} # full mode only
458
+ decision:post-business-test {retry: 0} # full mode only
459
+ quality-review {phase}
460
+ decision:post-review {retry: 0}
461
+ quality-auto-test {phase} # full mode; standard if coverage < 80%
462
+ quality-test {phase}
463
+ decision:post-test {retry+1}
464
+ ```
465
+
466
+ #### 2.2c: Structural decisions (direct evaluation)
467
+
468
+ **post-milestone:**
469
+ ```
470
+ Read .workflow/state.json check next milestone (status "pending"/"active")
471
+ If found: update session (milestone, phase, reset passed_gates), re-infer quality_mode,
472
+ insert lifecycle via buildSteps() for next milestone
473
+ If none: proceed — session completes naturally
474
+ ```
475
+
476
+ **post-debug-escalate:**
477
+ ```
478
+ Set session status = "paused"
479
+ Display: ◆ 已达最大重试次数,debug 已执行。请人工介入检查结果。
480
+ STOP (always, regardless of -y)
481
+ ```
482
+
483
+ #### 2.2d: Finalize decision
484
+
485
+ ```
486
+ Mark decision step "completed"
487
+ Reindex steps if commands inserted
488
+ Write status.json
489
+ Sync update_plan
490
+
491
+ Display: ◆ Decision: {type} → {verdict.status} ({verdict.reason})
492
+
493
+ STOP behavior:
494
+ post-debug-escalate always STOP
495
+ auto_mode == true → no STOP, continue to 2.3
496
+ auto_mode == false → STOP. Display: ⏸ 使用 $maestro-ralph execute 继续
497
+ ```
498
+
499
+ ### 2.3: Build and Execute Wave
500
+
501
+ **Loop while pending non-decision steps exist:**
502
+
503
+ **1. buildNextWave:**
504
+ - Conditional step → evaluate condition, skip if not met:
505
+ - `check_coverage`: read `{artifact_dir}/validation.json`, if `coverage >= threshold` → skip test-gen; else → include
506
+ - If validation.json not found → include (assume coverage insufficient)
507
+ - Barrier step → solo wave (single row CSV)
508
+ - Non-barrier → collect consecutive non-barrier, non-decision steps (multi-row CSV)
509
+ - Stop at first decision node
510
+
511
+ **2. buildSkillCall(step, session)** — assemble fully-resolved command:
512
+
513
+ Placeholder resolution:
514
+ ```
515
+ {phase} session.phase
516
+ {intent}session.intent
517
+ {scratch_dir} latest artifact path
518
+ {plan_dir} session.context.plan_dir
519
+ {analysis_dir} → session.context.analysis_dir
520
+ ```
521
+
522
+ Per-skill enrichment:
523
+ | Skill | Enrichment |
524
+ |-------|-----------|
525
+ | maestro-brainstorm | args empty → `"{intent}"` |
526
+ | maestro-roadmap | args empty → `"{intent}"` |
527
+ | maestro-analyze | args empty → `{phase}` |
528
+ | maestro-plan | resolve latest analyze artifact → `--dir .workflow/scratch/{path}` |
529
+ | maestro-execute | resolve latest plan artifact → `--dir .workflow/scratch/{path}` |
530
+ | quality-debug | append gap_summary or `--from-uat`/`--from-business-test` |
531
+ | quality-* / maestro-verify / milestone-* | args empty → `{phase}` or empty |
532
+
533
+ Auto flag: append from propagation table if `auto_mode == true`.
534
+
535
+ Result: `$<skill-name> <enriched-args> [auto-flag]`
536
+
537
+ **3. Write wave CSV:** `{sessionDir}/wave-{N}.csv`
538
+
539
+ **4. Update plan** (mark wave steps in_progress)
540
+
541
+ **5. Spawn:**
542
+ ```
543
+ spawn_agents_on_csv({
544
+ csv_path: "{sessionDir}/wave-{N}.csv",
545
+ id_column: "id",
546
+ instruction: WAVE_INSTRUCTION,
547
+ max_workers: <wave_size>,
548
+ max_runtime_seconds: 3600,
549
+ output_csv_path: "{sessionDir}/wave-{N}-results.csv",
550
+ output_schema: RESULT_SCHEMA
551
+ })
552
+ ```
553
+
554
+ **6. Read results** update step statuses from results CSV
555
+
556
+ **7. Barrier context update:**
557
+
558
+ | Barrier | Read | Update |
559
+ |---------|------|--------|
560
+ | maestro-analyze | context.md, state.json | context.analysis_dir |
561
+ | maestro-plan | plan.json | context.plan_dir |
562
+ | maestro-execute | results | context.exec_status |
563
+ | maestro-brainstorm | .brainstorming/ | context.brainstorm_dir |
564
+ | maestro-roadmap | specs/ | context.spec_session_id |
565
+
566
+ **8. Persist** write status.json + sync update_plan
567
+
568
+ **9. Failure check:**
569
+ - `-y`: retry once, then pause (await manual intervention)
570
+ - Non-`-y`: mark remaining skipped pause STOP
571
+
572
+ **10. Next step check:**
573
+ - Decision node + auto_mode loop to 2.2
574
+ - Decision node + non-auto → STOP
575
+ - External node loop to step 1
576
+
577
+ ---
578
+
579
+ ## Phase 3: Completion
580
+
581
+ ```
582
+ status.status = "completed"
583
+ status.updated_at = now
584
+ Write status.json
585
+
586
+ functions.update_plan({
587
+ explanation: "Ralph lifecycle complete",
588
+ plan: steps.map(step => ({ step: stepLabel(step), status: "completed" }))
589
+ })
590
+ ```
591
+
592
+ Display:
593
+ ```
594
+ ============================================================
595
+ RALPH COMPLETE
596
+ ============================================================
597
+ Session: {session_id}
598
+ Quality: {quality_mode}
599
+ Phase: {phase} → {milestone}
600
+ Waves: {wave_count} executed
601
+ Steps: {completed}/{total} ({skipped} skipped)
602
+
603
+ [✓] 0. maestro-plan 1 [W1]
604
+ [✓] 1. maestro-execute 1 [W2]
605
+ [✓] 2. maestro-verify 1 [W3]
606
+ [✓] 3. ◆ post-verify → proceed [decision]
607
+ [~] 4. quality-auto-test 1 [skipped: standard mode]
608
+ [✓] 5. quality-review 1 [W4]
609
+ ...
610
+ ============================================================
611
+ ```
612
+
613
+ </execution>
614
+
615
+ <csv_schema>
616
+ ### wave-{N}.csv
617
+
618
+ Coordinator 已完成 arg 组装 + auto flag 附加:
619
+
620
+ ```csv
621
+ id,skill_call,topic
622
+ "3","$maestro-verify 1","Ralph step 3/14: verify phase 1"
623
+ "4","$quality-review 1 --tier quick","Ralph step 4/14: review phase 1"
624
+ ```
625
+
626
+ Rules:
627
+ - `skill_call`: complete `$<skill> <args> [auto-flag]` from `buildSkillCall()`
628
+ - `topic`: human-readable step description
629
+ - Non-barrier external + non-decision → multi-row (parallel)
630
+ - Barrier external → single-row (solo)
631
+ - Decision nodes NEVER appear in CSV — processed by coordinator directly
632
+
633
+ ### Sub-Agent Instruction
634
+
635
+ ```
636
+ 你是 CSV job 子 agent。
637
+
638
+ 执行技能调用:{skill_call}
639
+ 任务说明:{topic}
640
+
641
+ 限制:
642
+ - 不要修改 .workflow/.maestro/ 下的 status 文件
643
+ - skill 内部有自己的 session 管理,按 skill SKILL.md 执行
644
+
645
+ 完成后调用 `report_agent_job_result`,返回:
646
+ {"status":"completed|failed","skill_call":"{skill_call}","summary":"一句话结果","artifacts":"产物路径","error":"失败原因"}
647
+ ```
648
+
649
+ ### Result Schema
650
+
651
+ `{ status, skill_call, summary, artifacts, error }` — all string
652
+ </csv_schema>
653
+
654
+ <error_codes>
655
+ | Code | Severity | Description | Recovery |
656
+ |------|----------|-------------|----------|
657
+ | E001 | error | No intent and no running session | Prompt for intent |
658
+ | E002 | error | Cannot infer lifecycle position | Show raw state, ask user |
659
+ | E003 | error | Artifact dir not found for decision | Show glob results, ask user |
660
+ | E004 | error | Delegate verdict parse failed | Fallback: treat as "fix" |
661
+ | E005 | error | Delegate execution failed | Fallback: treat as "fix" with generic summary |
662
+ | E006 | error | Wave timeout (max_runtime_seconds) | Mark step failed, pause |
663
+ | E007 | error | No session found for execute/continue | Suggest $maestro-ralph "intent" |
664
+ | W001 | warning | Decision node expanded chain | Auto-handled, log expansion |
665
+ | W002 | warning | Max retries reached, escalating | Auto-handled |
666
+ | W003 | warning | Multiple running sessions found | Use latest, warn user |
667
+ | W004 | warning | Delegate confidence == "low" | Show warning in interactive mode |
668
+ </error_codes>
669
+
670
+ <success_criteria>
671
+ - [ ] state.json parsed with actual schema (type, path, scope, milestone, depends_on)
672
+ - [ ] Lifecycle position inferred from bootstrap + artifact chain + result files
673
+ - [ ] Artifact dir resolved via resolve_artifact_dir() with fallback glob
674
+ - [ ] Quality mode (full/standard/quick) correctly inferred and governs step generation
675
+ - [ ] Conditional steps evaluated at decision time (coverage threshold)
676
+ - [ ] buildSkillCall() completes arg enrichment + auto flag, CSV contains full commands
677
+ - [ ] Quality-gate decisions delegate-evaluated via `maestro delegate --role analyze`
678
+ - [ ] Delegate verdict parsed: STATUS / REASON / GAP_SUMMARY / CONFIDENCE / CONFIDENCE_SCORE / WEAKEST_DIMENSION
679
+ - [ ] Confidence-based verdict adjustment applied (< 60% bias fix, > 95% bias proceed)
680
+ - [ ] Artifact confidence sections read when available as additional signal
681
+ - [ ] `-y` mode: auto-follow adjusted verdict, no STOP (except post-debug-escalate)
682
+ - [ ] Interactive mode: display recommendation with confidence score + request_user_input with override
683
+ - [ ] Delegate failure fallback: treat as "fix" verdict
684
+ - [ ] passed_gates[] tracks passed quality gates, skips re-runs in retry loops
685
+ - [ ] passed_gates cleared when code changes (fix-loop inserts execute step)
686
+ - [ ] Fix-loop templates correctly use gap_summary from delegate
687
+ - [ ] retry_count tracked per decision, max_retries enforced → escalation
688
+ - [ ] ALL external steps via spawn_agents_on_csv — coordinator never executes directly
689
+ - [ ] Barrier steps solo wave, non-barriers parallel
690
+ - [ ] functions.update_plan() initialized in 1.7, synced per wave, finalized in Phase 3
691
+ - [ ] status.json persisted after every wave and decision
692
+ - [ ] Command insertion + reindex preserves step integrity
693
+ </success_criteria>