maestro-flow 0.4.16 → 0.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.agents/skills/maestro/SKILL.md +1 -1
  2. package/.agents/skills/maestro-analyze/SKILL.md +5 -0
  3. package/.agents/skills/maestro-blueprint/SKILL.md +5 -0
  4. package/.agents/skills/maestro-brainstorm/SKILL.md +5 -0
  5. package/.agents/skills/maestro-init/SKILL.md +1 -1
  6. package/.agents/skills/maestro-next/SKILL.md +219 -0
  7. package/.agents/skills/maestro-ralph-beta/SKILL.md +893 -0
  8. package/.agy/skills/maestro/SKILL.md +1 -1
  9. package/.agy/skills/maestro-analyze/SKILL.md +5 -0
  10. package/.agy/skills/maestro-blueprint/SKILL.md +5 -0
  11. package/.agy/skills/maestro-brainstorm/SKILL.md +5 -0
  12. package/.agy/skills/maestro-init/SKILL.md +1 -1
  13. package/.agy/skills/maestro-next/SKILL.md +215 -0
  14. package/.agy/skills/maestro-ralph-beta/SKILL.md +889 -0
  15. package/.claude/commands/maestro-analyze.md +5 -0
  16. package/.claude/commands/maestro-blueprint.md +5 -0
  17. package/.claude/commands/maestro-brainstorm.md +5 -0
  18. package/.claude/commands/maestro-init.md +1 -1
  19. package/.claude/commands/maestro-next.md +217 -0
  20. package/.claude/commands/maestro-ralph-beta.md +891 -0
  21. package/.claude/commands/maestro.md +1 -1
  22. package/.codex/skills/learn-decompose/SKILL.md +34 -3
  23. package/.codex/skills/learn-retro/SKILL.md +31 -1
  24. package/.codex/skills/learn-second-opinion/SKILL.md +34 -4
  25. package/.codex/skills/maestro-analyze/SKILL.md +44 -5
  26. package/.codex/skills/maestro-blueprint/SKILL.md +5 -0
  27. package/.codex/skills/maestro-brainstorm/SKILL.md +46 -0
  28. package/.codex/skills/maestro-execute/SKILL.md +61 -5
  29. package/.codex/skills/maestro-milestone-audit/SKILL.md +64 -13
  30. package/.codex/skills/maestro-milestone-complete/SKILL.md +12 -0
  31. package/.codex/skills/maestro-plan/SKILL.md +36 -1
  32. package/.codex/skills/maestro-player/SKILL.md +25 -6
  33. package/.codex/skills/maestro-ralph/SKILL.md +108 -81
  34. package/.codex/skills/maestro-ralph-beta/SKILL.md +891 -0
  35. package/.codex/skills/maestro-ralph-execute/SKILL.md +244 -0
  36. package/.codex/skills/maestro-roadmap/SKILL.md +35 -4
  37. package/.codex/skills/maestro-ui-codify/SKILL.md +38 -10
  38. package/.codex/skills/maestro-verify/SKILL.md +40 -5
  39. package/.codex/skills/manage-codebase-rebuild/SKILL.md +52 -5
  40. package/.codex/skills/manage-issue-discover/SKILL.md +106 -15
  41. package/.codex/skills/quality-auto-test/SKILL.md +70 -16
  42. package/.codex/skills/quality-debug/SKILL.md +139 -28
  43. package/.codex/skills/quality-refactor/SKILL.md +61 -11
  44. package/.codex/skills/quality-review/SKILL.md +45 -9
  45. package/.codex/skills/quality-test/SKILL.md +58 -3
  46. package/.codex/skills/security-audit/SKILL.md +38 -0
  47. package/.codex/skills/spec-map/SKILL.md +65 -8
  48. package/.codex/skills/team-coordinate/SKILL.md +28 -11
  49. package/.codex/skills/team-coordinate/specs/role-catalog.md +20 -0
  50. package/.codex/skills/team-lifecycle-v4/SKILL.md +23 -7
  51. package/.codex/skills/team-lifecycle-v4/instructions/agent-instruction.md +20 -0
  52. package/.codex/skills/team-quality-assurance/SKILL.md +40 -2
  53. package/.codex/skills/team-review/SKILL.md +42 -2
  54. package/.codex/skills/team-tech-debt/SKILL.md +45 -2
  55. package/.codex/skills/team-testing/SKILL.md +42 -2
  56. package/dashboard/dist-server/dashboard/src/server/wiki/search.d.ts +6 -4
  57. package/dashboard/dist-server/dashboard/src/server/wiki/search.js +50 -8
  58. package/dashboard/dist-server/dashboard/src/server/wiki/search.js.map +1 -1
  59. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.d.ts +32 -0
  60. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js +294 -0
  61. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js.map +1 -1
  62. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.d.ts +1 -0
  63. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +35 -1
  64. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  65. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.test.js +235 -0
  66. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.test.js.map +1 -1
  67. package/dist/src/commands/install-backend.d.ts.map +1 -1
  68. package/dist/src/commands/install-backend.js +23 -4
  69. package/dist/src/commands/install-backend.js.map +1 -1
  70. package/dist/src/commands/ralph.d.ts.map +1 -1
  71. package/dist/src/commands/ralph.js +3 -1
  72. package/dist/src/commands/ralph.js.map +1 -1
  73. package/dist/src/ralph/cmd-check.js +1 -1
  74. package/dist/src/ralph/cmd-check.js.map +1 -1
  75. package/dist/src/ralph/cmd-complete.js +1 -1
  76. package/dist/src/ralph/cmd-complete.js.map +1 -1
  77. package/dist/src/ralph/cmd-next.d.ts.map +1 -1
  78. package/dist/src/ralph/cmd-next.js +56 -5
  79. package/dist/src/ralph/cmd-next.js.map +1 -1
  80. package/dist/src/ralph/cmd-session.js +2 -2
  81. package/dist/src/ralph/cmd-session.js.map +1 -1
  82. package/dist/src/ralph/cmd-skills.d.ts +2 -0
  83. package/dist/src/ralph/cmd-skills.d.ts.map +1 -1
  84. package/dist/src/ralph/cmd-skills.js +11 -4
  85. package/dist/src/ralph/cmd-skills.js.map +1 -1
  86. package/dist/src/ralph/skill-scanner.d.ts +7 -2
  87. package/dist/src/ralph/skill-scanner.d.ts.map +1 -1
  88. package/dist/src/ralph/skill-scanner.js +39 -24
  89. package/dist/src/ralph/skill-scanner.js.map +1 -1
  90. package/dist/src/ralph/status-schema.d.ts +2 -0
  91. package/dist/src/ralph/status-schema.d.ts.map +1 -1
  92. package/dist/src/ralph/status-store.d.ts +8 -1
  93. package/dist/src/ralph/status-store.d.ts.map +1 -1
  94. package/dist/src/ralph/status-store.js +12 -2
  95. package/dist/src/ralph/status-store.js.map +1 -1
  96. package/dist/src/tools/store-knowhow.d.ts.map +1 -1
  97. package/dist/src/tools/store-knowhow.js +51 -64
  98. package/dist/src/tools/store-knowhow.js.map +1 -1
  99. package/dist/src/utils/update-notices.js +12 -0
  100. package/dist/src/utils/update-notices.js.map +1 -1
  101. package/package.json +1 -1
  102. package/templates/config.json +21 -33
  103. package/workflows/finish-work.md +119 -0
  104. package/workflows/init.md +11 -11
  105. package/workflows/milestone-complete.md +23 -1
@@ -0,0 +1,244 @@
1
+ ---
2
+ name: maestro-ralph-execute
3
+ description: Execute next pending step in ralph session
4
+ argument-hint: "[-y] [session-id]"
5
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep, request_user_input
6
+ ---
7
+ <purpose>
8
+ Single-step executor for ralph (adaptive) and maestro (static) sessions.
9
+ Each invocation: locate session → find next step → resolve args → execute → update → self-invoke next.
10
+
11
+ Mutual invocation with `/maestro-ralph` forms a self-perpetuating work loop.
12
+
13
+ **Session**: `.workflow/.maestro/{session_id}/status.json` — 工作流唯一真源。session_id 格式 `ralph-{YYYYMMDD-HHmmss}`(/maestro-ralph 创建,自适应链)或 `maestro-{YYYYMMDD-HHmmss}`(/maestro 创建,静态链)。两类都由本 skill 推进;省略 `[session-id]` 时取最新 `status=="running"`。Schema 详见 `/maestro-ralph` 的 Session Schema。
14
+ </purpose>
15
+
16
+ <context>
17
+ $ARGUMENTS — optional `-y` flag + optional session ID.
18
+
19
+ **Parse:**
20
+ ```
21
+ -y / --yes → auto = true
22
+ Remaining → session_id (if matches maestro-* or ralph-*)
23
+ ```
24
+ Also read `session.auto_mode` from status.json — if true, treat as `-y`.
25
+
26
+ **Step kinds:**
27
+
28
+ | Kind | Identifier | Execution | Flow after |
29
+ |------|-----------|-----------|------------|
30
+ | decision step | `step.decision` 非空 | `$maestro-ralph` | Execution ends here |
31
+ | 执行 step | `step.decision == null` | `Bash("maestro ralph next")` → 内联按其 stdout 执行 → `Bash("maestro ralph complete N --status ...")` | Self-invoke next |
32
+
33
+ HARD RULES:
34
+ - 执行 step:**统一通过 `maestro ralph next` CLI 加载**。CLI 负责读 command_path(codex SKILL.md)、解析 `<required_reading>` + `<deferred_reading>`、拼接 prompt、写 `step.load.*` + `active_step_index` + `step.status="running"`。不要再在会话里手动 Read + 解析 required_reading
35
+ - decision step:A_EXEC_DECISION 通过 `$maestro-ralph` 直调 handoff 给 ralph 评估(不走 CLI)
36
+ - `command_path` 由 ralph 在 A_BUILD_STEPS 写入 status.json(通过 `maestro ralph skills --platform codex` 预校验;缺失 → ralph next 返回 E006/E007 并拒绝执行)
37
+ - 每个 step 结束必须调用 `maestro ralph complete N --status <S>` 或 `maestro ralph retry N`。STATUS 仅 4 个合法值:`DONE | DONE_WITH_CONCERNS | NEEDS_RETRY | BLOCKED`
38
+ - Platform:`session.platform == "codex"`;ralph next CLI 自动按 platform 解析 SKILL.md(无需额外参数)
39
+ </context>
40
+
41
+ <invariants>
42
+ 1. **执行 = `ralph next` + inline + `ralph complete`** — 调 `maestro ralph next` 拿到 skill 内容,按 stdout 内联执行
43
+ 2. **Required reading 由 CLI 负责** — `ralph next` 自动展开 + 加载 `<required_reading>` 引用的所有文件,缺失 → 退出码 1(E007),不写 active_step_index,不进入执行
44
+ 3. **Deferred reading recorded only** — `<deferred_reading>` 路径由 CLI 记录到 `step.load.deferred_files`,执行阶段按需 Read
45
+ 4. **一致性取代锁** — 同一 session 同时最多一个 step 持 `active_step_index`;CLI 校验失败直接退出码 3,不静默推进
46
+ 5. **Completion 通过 CLI 调用** — 每个 step 末尾调 `maestro ralph complete N --status <S>` 或 `maestro ralph retry N`,由 CLI 写 `completion_*` + 清 `active_step_index`
47
+ 6. **Self-invocation chain** — 持续直到全部 `completion_confirmed` 或 paused
48
+ 7. **status.json 每步骤后由 CLI 原子写盘** — resume-safe
49
+ 8. **STATUS 枚举受限** — 仅 `DONE | DONE_WITH_CONCERNS | NEEDS_RETRY | BLOCKED`
50
+ 9. **Platform binding** — 仅处理 `session.platform == "codex"` 的会话;platform 缺失视为 codex(向前兼容)
51
+ </invariants>
52
+
53
+ <state_machine>
54
+
55
+ <states>
56
+ S_LOCATE — 定位 session + 找下一个 pending step PERSIST: —
57
+ S_RESOLVE_ARGS — 解析占位符 + 丰富参数 PERSIST: step.args (enriched)
58
+ S_EXECUTE — 执行当前 step PERSIST: step.status = "running", session.current_step
59
+ S_POST_EXEC — 标记完成 + 传播上下文 PERSIST: step.completion_*, step.status, session.context
60
+ S_HANDLE_FAIL — 处理失败 PERSIST: step.status, session.status
61
+ S_COMPLETE — 所有 step 完成 PERSIST: session.status = "completed"
62
+ S_FALLBACK — 无 session 可执行 PERSIST: —
63
+ </states>
64
+
65
+ <transitions>
66
+
67
+ S_LOCATE:
68
+ → S_RESOLVE_ARGS WHEN: pending step found DO: A_LOCATE_SESSION
69
+ → S_COMPLETE WHEN: no pending steps
70
+ → S_FALLBACK WHEN: no running session
71
+
72
+ S_RESOLVE_ARGS:
73
+ → S_EXECUTE DO: A_RESOLVE_ARGS
74
+
75
+ S_EXECUTE:
76
+ → END WHEN: step.decision != null DO: A_EXEC_DECISION
77
+ → S_POST_EXEC WHEN: step.decision == null + ralph complete invoked with DONE|DONE_WITH_CONCERNS DO: A_EXEC_STEP
78
+ → S_HANDLE_FAIL WHEN: step.decision == null + ralph next exit≠0 OR ralph complete with NEEDS_RETRY|BLOCKED DO: A_EXEC_STEP
79
+
80
+ S_POST_EXEC:
81
+ → S_LOCATE DO: Bash("maestro ralph complete ...") + $maestro-ralph-execute
82
+ NOTE: CLI 已写完 completion_*, status, active_step_index;无需额外写盘
83
+
84
+ S_HANDLE_FAIL:
85
+ → S_LOCATE WHEN: auto + not retried DO: A_RETRY
86
+ → END WHEN: auto + retried DO: A_PAUSE_SESSION
87
+ → S_LOCATE WHEN: interactive + user selects retry DO: A_RETRY
88
+ → S_LOCATE WHEN: interactive + user selects skip DO: A_SKIP_STEP
89
+ → END WHEN: interactive + user selects abort DO: A_PAUSE_SESSION
90
+
91
+ S_COMPLETE:
92
+ → END DO: A_COMPLETE_SESSION
93
+
94
+ S_FALLBACK:
95
+ → END DO: display "无运行中的会话。使用 /maestro 或 /maestro-ralph 创建。"
96
+
97
+ </transitions>
98
+
99
+ <actions>
100
+
101
+ ### A_LOCATE_SESSION
102
+
103
+ 1. If session_id provided → load `.workflow/.maestro/{session_id}/status.json`
104
+ 2. Else: scan `.workflow/.maestro/*/status.json`, filter `status == "running"`, sort DESC, take first
105
+ 3. Extract: session_id, source, steps[], phase, milestone, intent, auto_mode, context, cli_tool, platform, active_step_index
106
+ 4. **不在此处选 pending step**——pending 选择由 `maestro ralph next` CLI 内部完成;A_LOCATE_SESSION 只确认 session 存在且 running,由 A_EXEC_STEP 调 CLI 推进
107
+
108
+ ### A_RESOLVE_ARGS
109
+
110
+ **Placeholder substitution:**
111
+
112
+ | Placeholder | Source |
113
+ |-------------|--------|
114
+ | `{phase}` | session.phase |
115
+ | `{milestone}` | session.milestone |
116
+ | `{intent}` | session.intent |
117
+ | `{description}` | session.intent (alias) |
118
+ | `{scratch_dir}` | session.context.scratch_dir or latest artifact path |
119
+ | `{plan_dir}` | session.context.plan_dir |
120
+ | `{analysis_dir}` | session.context.analysis_dir |
121
+ | `{issue_id}` | session.context.issue_id |
122
+ | `{milestone_num}` | session.context.milestone_num |
123
+
124
+ **Per-skill enrichment** (when args empty or minimal):
125
+
126
+ | Skill | Required context | Source |
127
+ |-------|-----------------|--------|
128
+ | maestro-brainstorm | topic | `"{intent}"` |
129
+ | maestro-roadmap | description | `"{intent}"` |
130
+ | maestro-analyze | phase or topic | `{phase}` or `"{intent}"` |
131
+ | maestro-plan | phase or --dir | `{phase}`, or `--dir {scratch_dir}` |
132
+ | maestro-execute | phase or --dir | `{phase}`, or `--dir {scratch_dir}` |
133
+ | quality-debug | gap context | Read previous step's error/gap |
134
+ | quality-* | phase | `{phase}` |
135
+
136
+ **Artifact dir resolution for --dir:**
137
+ ```
138
+ Read state.json → filter artifacts by milestone + phase
139
+ plan commands: latest type=="analyze" → --dir .workflow/scratch/{path}
140
+ execute commands: latest type=="plan" → --dir .workflow/scratch/{path}
141
+ ```
142
+
143
+ Write enriched args back to status.json.
144
+
145
+ ### A_EXEC_DECISION
146
+
147
+ 1. Mark step running, write status.json
148
+ 2. Display: `[{index}/{total}] ◆ {step.decision} Retry: {retry}/{max}`
149
+ 3. `$maestro-ralph` — 直调 ralph 评估 + handoff
150
+ 4. 执行在此结束
151
+
152
+ ### A_EXEC_STEP
153
+
154
+ 1. **Load** — `Bash("maestro ralph next")`
155
+ - 退出码 0 → 按 stdout 内联执行
156
+ - 退出码 2 → 交给 S_LOCATE
157
+ - 退出码 3 → active_step_index 已被占用
158
+ - 退出码 1 → pause session
159
+ 2. **Inline execution** — 按 stdout 执行;deferred_reading 按需 Read
160
+ 3. **Complete**:
161
+ - `Bash("maestro ralph complete N --status DONE [--evidence <path>]")`
162
+ - `Bash("maestro ralph complete N --status DONE_WITH_CONCERNS --concerns \"...\"")`
163
+ - `Bash("maestro ralph retry N")`
164
+ - `Bash("maestro ralph complete N --status BLOCKED --reason \"...\"")`
165
+ 4. **Propagate context signals** — 关键信号 (`PHASE: N` / `scratch_dir: path` / `BLP-xxx`) 写入 `status.json.context`
166
+
167
+ 完成后 S_LOCATE 触发 `$maestro-ralph-execute` 直调自调用。
168
+
169
+ ### A_RETRY
170
+
171
+ 1. `Bash("maestro ralph retry N")` — CLI 设 `step.retried = true`, `step.status = "pending"`, `step.completion_confirmed = false`, 清 `active_step_index`
172
+ 2. Display: `[{index}/{total}] ↻ {step.skill} retry`
173
+
174
+ ### A_SKIP_STEP
175
+
176
+ 跳过执行 step — 手动编辑 `status.json`:将该 step `status` 设为 `"skipped"`,`completion_confirmed` 设为 `false`,并清 `active_step_index`(若指向此 step)。
177
+ (不提供 CLI 子命令;跳过是非常规操作,避免自动化误用。)
178
+
179
+ ### A_PAUSE_SESSION
180
+
181
+ 通常由 `ralph complete N --status BLOCKED --reason "..."` 触发,CLI 已写 `session.status = "paused"`。手动 pause 场景下直接编辑 status.json。
182
+ Display: `[{index}/{total}] ✗ {step.skill} 失败,会话已暂停。/maestro-ralph continue 恢复。`
183
+
184
+ ### A_COMPLETE_SESSION
185
+
186
+ 1. 校验:所有 step `completion_confirmed == true`(除 skipped);task_decomposition 存在时校验 `task_decomposition_all_done == true`
187
+ 2. 任一校验失败 → 不标 completed,回 S_LOCATE 或 pause
188
+ 3. `session.status = "completed"`, write status.json
189
+ 4. Display completion report:
190
+ ```
191
+ ============================================================
192
+ SESSION COMPLETE
193
+ ============================================================
194
+ Session: {session_id} [{source}]
195
+ Steps: {completed}/{total} confirmed: {confirmed}/{completed}
196
+
197
+ [✓] 0. maestro-plan 1 [global]
198
+ [✓] 1. maestro-execute 1 [project]
199
+ [✓] 2. maestro-verify 1 [global]
200
+ [✓] 3. ◆ post-verify [decision]
201
+ ...
202
+ ============================================================
203
+ ```
204
+ Icons: `✓` confirmed, `—` skipped, `✗` failed, `◆` decision
205
+
206
+ </actions>
207
+
208
+ </state_machine>
209
+
210
+ <appendix>
211
+
212
+ ### Error Codes
213
+
214
+ | Code | Severity | Description | Recovery |
215
+ |------|----------|-------------|----------|
216
+ | E001 | error | No running session found | Suggest /maestro or /maestro-ralph |
217
+ | E006 | error | command_path missing/unreachable for 执行 step | `ralph next` 拒绝;编辑 status.json 或重 build |
218
+ | E007 | error | required_reading 引用文件缺失 | `ralph next` 拒绝;CLI stderr 列出缺失路径 |
219
+ | E008 | error | `ralph complete` idx ≠ active_step_index | 编辑 status.json 修正一致性 |
220
+ | E009 | error | `ralph complete` step.status ≠ running | 重复 complete 或非法跳跃;编辑 status.json |
221
+ | E010 | error | status.json schema 损坏 | `ralph check` 显示具体损坏字段 |
222
+ | W001 | warning | Step completed with concerns | Log and continue |
223
+ | W005 | warning | active_step_index 指向已 completed step | `ralph next` 自动清理后继续 |
224
+ | W007 | warning | step.skill ≠ SKILL.md frontmatter.name | 提示但不阻塞 |
225
+
226
+ ### Success Criteria
227
+
228
+ - [ ] Session discovery covers maestro-* and ralph-*
229
+ - [ ] `-y` parsed from args 或 session.auto_mode;auto=true 时透传 `-y` 到 skill args
230
+ - [ ] Placeholders resolved;per-skill enrichment 正确
231
+ - [ ] Decision 节点(`step.decision != null`)走 `$maestro-ralph` 直调 handoff(**不调 ralph next CLI**)
232
+ - [ ] 执行 step 通过 `Bash("maestro ralph next")` 加载;CLI 返回拼好的 prompt + completion 协议
233
+ - [ ] required_reading 由 CLI 自动加载并拼入 prompt;缺失 → CLI 退出码 1,pause session
234
+ - [ ] `<deferred_reading>` 由 CLI 记录到 `step.load.deferred_files`,执行阶段按需 Read
235
+ - [ ] 每个 step 末尾必须调 `maestro ralph complete N --status <S>` 或 `maestro ralph retry N`
236
+ - [ ] STATUS 枚举仅 `DONE | DONE_WITH_CONCERNS | NEEDS_RETRY | BLOCKED`
237
+ - [ ] active_step_index 一致性由 CLI 维护;E008/E009 直接退出,不静默推进
238
+ - [ ] step.completion_evidence 通过 `--evidence` 传入并记录
239
+ - [ ] Context signals 由执行 step 显式写回 status.json.context(非 ralph-execute 内嵌扫描)
240
+ - [ ] Auto mode: retry 一次后 pause;interactive 提供 retry/skip/abort
241
+ - [ ] 自调用持续到全部 completion_confirmed 或 paused
242
+ - [ ] 只处理 session.platform == "codex" 的会话
243
+
244
+ </appendix>
@@ -110,19 +110,50 @@ S_AGGREGATE:
110
110
 
111
111
  <actions>
112
112
 
113
+ ### Shared Spawn Contract (W1 and W2)
114
+
115
+ Every `spawn_agents_on_csv` call MUST filter `wave==N AND status=="pending"` and use this strict JSON Schema:
116
+
117
+ ```json
118
+ {
119
+ "type": "object",
120
+ "properties": {
121
+ "id": { "type": "string" },
122
+ "result_status": { "type": "string", "enum": ["completed", "failed", "blocked"] },
123
+ "findings": { "type": "string", "maxLength": 500 },
124
+ "output_path": { "type": "string", "description": "W2 only: absolute path of roadmap.md (empty for W1 agents that just return findings)" },
125
+ "error": { "type": "string" }
126
+ },
127
+ "required": ["id", "result_status", "findings"]
128
+ }
129
+ ```
130
+
131
+ Merge: `result_status` → master `status`; copy `findings`, `output_path`, `error`.
132
+
133
+ **Shared termination contract** (embed in every instruction):
134
+ ```
135
+ You MUST call report_agent_job_result EXACTLY ONCE before exiting.
136
+ - Success → result_status=completed (W2: roadmap.md MUST exist on disk)
137
+ - Failure → result_status=failed with error message
138
+ - Blocked → upstream context insufficient → result_status=blocked
139
+ - Timeout → near max_runtime_seconds → result_status=blocked, error="timeout"
140
+ - NEVER continue indefinitely. NEVER exit silently. NEVER omit the call.
141
+ Do NOT write to tasks.csv, wave-*.csv, results.csv. Do NOT call spawn_agents_on_csv (no recursion).
142
+ ```
143
+
113
144
  ### A_SPAWN_WAVE_1
114
145
 
115
- Filter wave==1 -> write wave-1.csv -> `spawn_agents_on_csv`.
146
+ Filter `wave==1 AND status=="pending"` -> write wave-1.csv -> spawn.
116
147
 
117
- **Agents**: scope analysis (feature inventory + priority), risk analysis (unknowns + mitigations), dependency analysis (dependency graph + critical path).
148
+ **Agents**: scope analysis (feature inventory + priority), risk analysis (unknowns + mitigations), dependency analysis (dependency graph + critical path). Read-only.
118
149
 
119
150
  Merge results -> master tasks.csv.
120
151
 
121
152
  ### A_SPAWN_WAVE_2
122
153
 
123
- Build prev_context from wave 1. Inject strategy + `--phases` constraint. Spawn.
154
+ Filter `wave==2 AND status=="pending"`. Build prev_context from wave 1. Inject strategy + `--phases` constraint. Spawn.
124
155
 
125
- Assembly agent produces roadmap.md with Milestone > Phase hierarchy (goal, depends-on, requirements, success criteria), scope decisions.
156
+ Assembly agent produces roadmap.md with Milestone > Phase hierarchy (goal, depends-on, requirements, success criteria), scope decisions. Verifies roadmap.md on disk before reporting completed.
126
157
 
127
158
  **Strategy selection** via uncertainty assessment (5 factors):
128
159
  | Factor | Low | Medium | High |
@@ -260,7 +260,35 @@ Write `tasks.csv` to `${sessionFolder}/tasks.csv`.
260
260
 
261
261
  ### Step 4: Wave Execution
262
262
 
263
- Execute waves sequentially via `spawn_agents_on_csv`.
263
+ Execute waves sequentially via `spawn_agents_on_csv`. All four waves share the same `output_schema` shape (below) — only `instruction` differs.
264
+
265
+ **Shared output_schema** (strict JSON Schema):
266
+
267
+ ```javascript
268
+ const UI_CODIFY_OUTPUT_SCHEMA = {
269
+ type: "object",
270
+ properties: {
271
+ id: { type: "string" },
272
+ result_status: { type: "string", enum: ["completed", "failed"] },
273
+ findings: { type: "string", maxLength: 500 },
274
+ output_path: { type: "string", description: "Absolute path of the file/dir produced by this worker (empty if failed)" },
275
+ error: { type: "string" }
276
+ },
277
+ required: ["id", "result_status", "findings"]
278
+ }
279
+ ```
280
+
281
+ **Shared termination contract** (embed in every `instruction` below):
282
+
283
+ ```
284
+ TERMINATION CONTRACT (mandatory — NO worker may end without calling report_agent_job_result):
285
+ - Success → result_status=completed, output_path set to the absolute path of the artifact you wrote
286
+ - Failure → unrecoverable error → result_status=failed, output_path=""
287
+ - Timeout → near max_runtime_seconds, finalize current write if safe → otherwise report failed with error="timeout"
288
+ - NEVER continue indefinitely. NEVER exit silently. NEVER omit the call.
289
+ - Do NOT write to tasks.csv, wave-*.csv, results.csv (orchestrator owns those).
290
+ - Do NOT call spawn_agents_on_csv (no recursion).
291
+ ```
264
292
 
265
293
  #### Wave 1: File Discovery (Barrier)
266
294
 
@@ -270,15 +298,15 @@ Filter `wave == 1 && status == pending` from master CSV. Write `wave-1.csv`.
270
298
  spawn_agents_on_csv({
271
299
  csv_path: `${sessionFolder}/wave-1.csv`,
272
300
  id_column: "id",
273
- instruction: `You are scanning a source directory for design-relevant files. Read the 'description' column for full instructions. Use Glob to find files, Read to sample content. Write file inventory JSON to the specified path. Report findings as a concise summary.`,
301
+ instruction: `You are scanning a source directory for design-relevant files. Read the 'description' column for full instructions. Use Glob to find files, Read to sample content. Write file inventory JSON to the specified path. Report findings as a concise summary.\n\n${SHARED_TERMINATION_CONTRACT}`,
274
302
  max_concurrency: 1,
275
303
  max_runtime_seconds: 1800,
276
304
  output_csv_path: `${sessionFolder}/wave-1-results.csv`,
277
- output_schema: { id, result_status: ["completed"|"failed"], findings, output_path, error }
305
+ output_schema: UI_CODIFY_OUTPUT_SCHEMA
278
306
  })
279
307
  ```
280
308
 
281
- Merge wave-1-results.csv into master `tasks.csv`: map `result_status` -> master `status` column, then delete `wave-1.csv` and `wave-1-results.csv`.
309
+ Merge wave-1-results.csv into master `tasks.csv`: map `result_status` -> master `status` column; copy `findings`, `output_path`, `error`. Delete `wave-1.csv` and `wave-1-results.csv`.
282
310
 
283
311
  #### Wave 2: Parallel Extraction (3 agents)
284
312
 
@@ -288,11 +316,11 @@ Filter `wave == 2 && status == pending`. Build `prev_context` from wave 1 findin
288
316
  spawn_agents_on_csv({
289
317
  csv_path: `${sessionFolder}/wave-2.csv`,
290
318
  id_column: "id",
291
- instruction: `You are extracting design tokens from source code. Read the 'description' column for your specific extraction task. Use prev_context for file inventory from discovery phase. Read source files, extract tokens, write output JSON to the specified path.`,
319
+ instruction: `You are extracting design tokens from source code. Read the 'description' column for your specific extraction task. Use prev_context for file inventory from discovery phase. Read source files, extract tokens, write output JSON to the specified path.\n\n${SHARED_TERMINATION_CONTRACT}`,
292
320
  max_concurrency: 3,
293
321
  max_runtime_seconds: 3600,
294
322
  output_csv_path: `${sessionFolder}/wave-2-results.csv`,
295
- output_schema: { id, result_status: ["completed"|"failed"], findings, output_path, error }
323
+ output_schema: UI_CODIFY_OUTPUT_SCHEMA
296
324
  })
297
325
  ```
298
326
 
@@ -308,11 +336,11 @@ Filter `wave == 3 && status == pending`. Build `prev_context` from wave 2 findin
308
336
  spawn_agents_on_csv({
309
337
  csv_path: `${sessionFolder}/wave-3.csv`,
310
338
  id_column: "id",
311
- instruction: `You are generating a reference design package. Read the 'description' column for full instructions. Copy token files, generate preview.html and preview.css. Report package contents in findings.`,
339
+ instruction: `You are generating a reference design package. Read the 'description' column for full instructions. Copy token files, generate preview.html and preview.css. Report package contents in findings.\n\n${SHARED_TERMINATION_CONTRACT}`,
312
340
  max_concurrency: 1,
313
341
  max_runtime_seconds: 1800,
314
342
  output_csv_path: `${sessionFolder}/wave-3-results.csv`,
315
- output_schema: { id, result_status: ["completed"|"failed"], findings, output_path, error }
343
+ output_schema: UI_CODIFY_OUTPUT_SCHEMA
316
344
  })
317
345
  ```
318
346
 
@@ -326,11 +354,11 @@ Filter `wave == 4 && status == pending`. Build `prev_context` from wave 3 findin
326
354
  spawn_agents_on_csv({
327
355
  csv_path: `${sessionFolder}/wave-4.csv`,
328
356
  id_column: "id",
329
- instruction: `You are building knowledge assets from a design package. Read the 'description' column for full instructions. Build manifest, write knowhow files, create spec entries, refresh wiki index, cleanup temp files. Report asset counts in findings.`,
357
+ instruction: `You are building knowledge assets from a design package. Read the 'description' column for full instructions. Build manifest, write knowhow files, create spec entries, refresh wiki index, cleanup temp files. Report asset counts in findings.\n\n${SHARED_TERMINATION_CONTRACT}`,
330
358
  max_concurrency: 1,
331
359
  max_runtime_seconds: 1800,
332
360
  output_csv_path: `${sessionFolder}/wave-4-results.csv`,
333
- output_schema: { id, result_status: ["completed"|"failed"], findings, output_path, error }
361
+ output_schema: UI_CODIFY_OUTPUT_SCHEMA
334
362
  })
335
363
  ```
336
364
 
@@ -128,23 +128,58 @@ S_AGGREGATE:
128
128
 
129
129
  <actions>
130
130
 
131
+ ### Shared Spawn Contract (W1, W2, W3)
132
+
133
+ Every `spawn_agents_on_csv` call MUST filter `wave==N AND status=="pending"` from master tasks.csv and use the strict JSON Schema below.
134
+
135
+ **output_schema**:
136
+
137
+ ```json
138
+ {
139
+ "type": "object",
140
+ "properties": {
141
+ "id": { "type": "string" },
142
+ "result_status": { "type": "string", "enum": ["completed", "failed", "blocked"] },
143
+ "verdict": { "type": "string", "description": "Per-agent verdict (e.g., VERIFIED/FAILED/UNCERTAIN, SUBSTANTIVE/STUB, WIRED/ORPHANED/NOT_WIRED, COVERED/PARTIAL/MISSING)" },
144
+ "findings": { "type": "string", "maxLength": 500 },
145
+ "gaps_found": { "type": "string", "description": "Semicolon-separated gaps with severity + fix direction" },
146
+ "error": { "type": "string" }
147
+ },
148
+ "required": ["id", "result_status", "findings", "verdict"]
149
+ }
150
+ ```
151
+
152
+ Merge: `result_status` → master `status`; copy `verdict`, `findings`, `gaps_found`, `error`.
153
+
154
+ **Shared termination contract** (embed in every instruction):
155
+ ```
156
+ You MUST call report_agent_job_result EXACTLY ONCE before exiting.
157
+ - Success → result_status=completed with concrete verdict
158
+ - Failure → result_status=failed with error message
159
+ - Blocked → upstream missing (W2/W3 cannot proceed) → result_status=blocked
160
+ - Timeout → near max_runtime_seconds → result_status=blocked, error="timeout"
161
+ - NEVER continue indefinitely. NEVER exit silently. NEVER omit the call.
162
+ - Read-only verification. Do NOT modify source files.
163
+ Do NOT write to tasks.csv, wave-*.csv, results.csv, verification.json. Do NOT call spawn_agents_on_csv (no recursion).
164
+ ```
165
+
131
166
  ### A_SPAWN_WAVE_1
132
167
 
133
- Filter wave==1 -> write wave-1.csv -> spawn.
168
+ Filter `wave==1 AND status=="pending"` -> write wave-1.csv -> spawn.
134
169
 
135
- **Truth check agent**: Identify supporting artifacts, check existence + substance + wiring indicators. Status: VERIFIED / FAILED / UNCERTAIN. Report gaps with severity + fix direction.
170
+ **Truth check agent**: Identify supporting artifacts, check existence + substance + wiring indicators. verdict: VERIFIED / FAILED / UNCERTAIN. Report gaps with severity + fix direction.
136
171
  **Artifact existence agent**: Check file on disk. Missing = gap (severity=critical). Exists = note size + structure for wave 2.
137
172
 
138
173
  ### A_SPAWN_WAVE_2
139
174
 
140
- Filter wave==2, skip if existence failed for that artifact. Build prev_context from wave 1 -> spawn.
175
+ Filter `wave==2 AND status=="pending"`, skip if existence failed for that artifact. Build prev_context from wave 1 -> spawn.
141
176
 
142
177
  **Substance agent**: <10 lines real logic or placeholder markers = STUB. Otherwise SUBSTANTIVE.
143
- **Wiring agent**: Grep for import + actual usage beyond imports. Status: WIRED / ORPHANED / NOT_WIRED.
178
+ **Wiring agent**: Grep for import + actual usage beyond imports. verdict: WIRED / ORPHANED / NOT_WIRED.
144
179
 
145
180
  ### A_SPAWN_WAVE_3
146
181
 
147
- Filter wave==3. Mark skipped per --skip-antipattern / --skip-tests. Build prev_context from waves 1+2 -> spawn.
182
+ Filter `wave==3 AND status=="pending"`. Mark skipped per --skip-antipattern / --skip-tests. Build prev_context from waves 1+2 -> spawn.
148
183
 
149
184
  **Anti-pattern agent**: Extract modified files from summaries. Scan for TODO/FIXME/XXX/HACK, placeholder, empty returns, disabled tests. Categorize: Blocker / Warning / Info.
150
185
  **Nyquist agent**: Detect test framework, map requirements to test files, classify COVERED / PARTIAL / MISSING. Run coverage if available.
@@ -210,17 +210,17 @@ Filter master `tasks.csv` for `wave == 1 AND status == pending` → write `wave-
210
210
  spawn_agents_on_csv({
211
211
  csv_path: `${sessionFolder}/wave-1.csv`,
212
212
  id_column: "id",
213
- instruction: buildRebuildInstruction(sessionFolder, sourceDirs), // agent: ~/.codex/agents/workflow-codebase-mapper.toml
213
+ instruction: REBUILD_INSTRUCTION, // see "Rebuild Worker Contract" below
214
214
  max_concurrency: maxConcurrency,
215
215
  max_runtime_seconds: 3600,
216
216
  output_csv_path: `${sessionFolder}/wave-1-results.csv`,
217
217
  output_schema: {
218
218
  type: "object",
219
219
  properties: {
220
- id: { type: "string" },
221
- result_status: { type: "string", enum: ["completed", "failed"] },
222
- result_findings: { type: "string" },
223
- error: { type: "string" }
220
+ id: { type: "string" },
221
+ result_status: { type: "string", enum: ["completed", "failed"] },
222
+ result_findings: { type: "string", description: "For task 1-3: JSON payload to merge into doc-index.json. For task 4-5: list of files written" },
223
+ error: { type: "string" }
224
224
  },
225
225
  required: ["id", "result_status", "result_findings"]
226
226
  }
@@ -229,6 +229,53 @@ spawn_agents_on_csv({
229
229
 
230
230
  Merge `wave-1-results.csv` into master `tasks.csv`: map `result_status` -> master `status`, `result_findings` -> master `findings`, copy `error` as-is. After merge, delete temporary files (`wave-1.csv` and `wave-1-results.csv`).
231
231
 
232
+ #### Rebuild Worker Contract (REBUILD_INSTRUCTION)
233
+
234
+ ```
235
+ You are a codebase doc generator for ONE task (Component Scanner / Feature Mapper / Requirement Linker / Tech Registry Writer / Feature Map Writer). Your contract depends on your task id — read description carefully.
236
+
237
+ DUAL CONTRACT (per task id):
238
+ Tasks 1-3 (Scanner/Mapper/Linker) → RETURN data via result_findings (JSON payload). Do NOT write files.
239
+ Tasks 4-5 (Writers) → MUST WRITE files via the Write tool. Verify each via Glob. Return file count + absolute paths via result_findings.
240
+
241
+ REQUIRED STEPS:
242
+ 1. Scan codebase per description and focus_area
243
+ 2. For tasks 1-3: assemble JSON payload matching the documented section schema (components / features / requirements)
244
+ 3. For tasks 4-5: render markdown documents and write them to disk; verify every intended file exists via Glob; if any file missing → result_status=failed
245
+ 4. Append discoveries to {sessionFolder}/discoveries.ndjson if reusable
246
+ 5. Call report_agent_job_result EXACTLY ONCE
247
+
248
+ TERMINATION CONTRACT (mandatory — NO worker may end without calling report_agent_job_result):
249
+ - Success → result_status=completed
250
+ - Failure → unrecoverable error / write verification fails → result_status=failed
251
+ - Timeout → near max_runtime_seconds, finish current write/scan if safe, then report failed with error="timeout (partial)"
252
+ - NEVER skip report_agent_job_result.
253
+
254
+ CONTRACT VIOLATION GUARD:
255
+ - Tasks 4-5 returning markdown content in result_findings instead of writing files → MUST self-report failed (orchestrator cannot assemble docs from text).
256
+ - Tasks 1-3 writing files to .workflow/codebase/ → MUST self-report failed (orchestrator owns assembly).
257
+
258
+ OUTPUT (must match output_schema):
259
+ Tasks 1-3:
260
+ {
261
+ "id": "<your row id>",
262
+ "result_status": "completed" | "failed",
263
+ "result_findings": "<JSON payload to merge into doc-index.json section>",
264
+ "error": "<message if failed, else empty>"
265
+ }
266
+ Tasks 4-5:
267
+ {
268
+ "id": "<your row id>",
269
+ "result_status": "completed" | "failed",
270
+ "result_findings": "<count + semicolon-separated absolute paths of files written>",
271
+ "error": "<message if failed, else empty>"
272
+ }
273
+
274
+ CONSTRAINTS:
275
+ - Do NOT write to tasks.csv, wave-*.csv, results.csv, doc-index.json (orchestrator assembles in Phase 3).
276
+ - Do NOT call spawn_agents_on_csv (no recursion).
277
+ ```
278
+
232
279
  ### Phase 3: Results -> .workflow/codebase/
233
280
 
234
281
  **Objective**: Assemble doc-index.json from agent findings, validate, update state.