maestro-flow 0.4.17 → 0.4.19

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 (165) 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-next/SKILL.md +254 -0
  6. package/.agents/skills/team-swarm/SKILL.md +180 -0
  7. package/.agents/skills/team-swarm/roles/analyst/role.md +187 -0
  8. package/.agents/skills/team-swarm/roles/ant/role.md +169 -0
  9. package/.agents/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  10. package/.agents/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  11. package/.agents/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  12. package/.agents/skills/team-swarm/roles/coordinator/role.md +211 -0
  13. package/.agents/skills/team-swarm/roles/scorer/role.md +157 -0
  14. package/.agents/skills/team-swarm/scripts/aco.py +473 -0
  15. package/.agents/skills/team-swarm/scripts/pheromone.py +144 -0
  16. package/.agents/skills/team-swarm/scripts/scoring.py +92 -0
  17. package/.agents/skills/team-swarm/scripts/test_aco.py +475 -0
  18. package/.agents/skills/team-swarm/specs/ant-output-schema.md +119 -0
  19. package/.agents/skills/team-swarm/specs/convergence-criteria.md +106 -0
  20. package/.agents/skills/team-swarm/specs/pheromone-schema.md +123 -0
  21. package/.agents/skills/team-swarm/specs/swarm-config-template.json +71 -0
  22. package/.agents/skills/team-swarm/specs/swarm-protocol.md +117 -0
  23. package/.agy/skills/maestro/SKILL.md +1 -1
  24. package/.agy/skills/maestro-analyze/SKILL.md +5 -0
  25. package/.agy/skills/maestro-blueprint/SKILL.md +5 -0
  26. package/.agy/skills/maestro-brainstorm/SKILL.md +5 -0
  27. package/.agy/skills/maestro-next/SKILL.md +250 -0
  28. package/.agy/skills/team-swarm/SKILL.md +176 -0
  29. package/.agy/skills/team-swarm/roles/analyst/role.md +183 -0
  30. package/.agy/skills/team-swarm/roles/ant/role.md +165 -0
  31. package/.agy/skills/team-swarm/roles/coordinator/commands/converge.md +134 -0
  32. package/.agy/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  33. package/.agy/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
  34. package/.agy/skills/team-swarm/roles/coordinator/role.md +209 -0
  35. package/.agy/skills/team-swarm/roles/scorer/role.md +153 -0
  36. package/.agy/skills/team-swarm/scripts/aco.py +473 -0
  37. package/.agy/skills/team-swarm/scripts/pheromone.py +144 -0
  38. package/.agy/skills/team-swarm/scripts/scoring.py +92 -0
  39. package/.agy/skills/team-swarm/scripts/test_aco.py +475 -0
  40. package/.agy/skills/team-swarm/specs/ant-output-schema.md +119 -0
  41. package/.agy/skills/team-swarm/specs/convergence-criteria.md +106 -0
  42. package/.agy/skills/team-swarm/specs/pheromone-schema.md +123 -0
  43. package/.agy/skills/team-swarm/specs/swarm-config-template.json +71 -0
  44. package/.agy/skills/team-swarm/specs/swarm-protocol.md +117 -0
  45. package/.claude/commands/maestro-analyze.md +5 -0
  46. package/.claude/commands/maestro-blueprint.md +5 -0
  47. package/.claude/commands/maestro-brainstorm.md +5 -0
  48. package/.claude/commands/maestro-next.md +252 -0
  49. package/.claude/commands/maestro.md +1 -1
  50. package/.claude/skills/team-swarm/SKILL.md +178 -0
  51. package/.claude/skills/team-swarm/roles/analyst/role.md +185 -0
  52. package/.claude/skills/team-swarm/roles/ant/role.md +167 -0
  53. package/.claude/skills/team-swarm/roles/coordinator/commands/converge.md +146 -0
  54. package/.claude/skills/team-swarm/roles/coordinator/commands/init-swarm.md +136 -0
  55. package/.claude/skills/team-swarm/roles/coordinator/commands/iterate.md +232 -0
  56. package/.claude/skills/team-swarm/roles/coordinator/role.md +209 -0
  57. package/.claude/skills/team-swarm/roles/scorer/role.md +155 -0
  58. package/.claude/skills/team-swarm/scripts/aco.py +473 -0
  59. package/.claude/skills/team-swarm/scripts/pheromone.py +144 -0
  60. package/.claude/skills/team-swarm/scripts/scoring.py +92 -0
  61. package/.claude/skills/team-swarm/scripts/test_aco.py +475 -0
  62. package/.claude/skills/team-swarm/specs/ant-output-schema.md +119 -0
  63. package/.claude/skills/team-swarm/specs/convergence-criteria.md +106 -0
  64. package/.claude/skills/team-swarm/specs/pheromone-schema.md +123 -0
  65. package/.claude/skills/team-swarm/specs/swarm-config-template.json +71 -0
  66. package/.claude/skills/team-swarm/specs/swarm-protocol.md +117 -0
  67. package/.codex/skills/learn-decompose/SKILL.md +34 -3
  68. package/.codex/skills/learn-retro/SKILL.md +31 -1
  69. package/.codex/skills/learn-second-opinion/SKILL.md +34 -4
  70. package/.codex/skills/maestro-analyze/SKILL.md +44 -5
  71. package/.codex/skills/maestro-blueprint/SKILL.md +5 -0
  72. package/.codex/skills/maestro-brainstorm/SKILL.md +46 -0
  73. package/.codex/skills/maestro-execute/SKILL.md +61 -5
  74. package/.codex/skills/maestro-milestone-audit/SKILL.md +64 -13
  75. package/.codex/skills/maestro-milestone-complete/SKILL.md +12 -0
  76. package/.codex/skills/maestro-next/SKILL.md +297 -0
  77. package/.codex/skills/maestro-plan/SKILL.md +36 -1
  78. package/.codex/skills/maestro-player/SKILL.md +25 -6
  79. package/.codex/skills/maestro-ralph/SKILL.md +17 -10
  80. package/.codex/skills/maestro-ralph-execute/SKILL.md +2 -1
  81. package/.codex/skills/maestro-roadmap/SKILL.md +35 -4
  82. package/.codex/skills/maestro-ui-codify/SKILL.md +38 -10
  83. package/.codex/skills/maestro-verify/SKILL.md +40 -5
  84. package/.codex/skills/manage-codebase-rebuild/SKILL.md +52 -5
  85. package/.codex/skills/manage-issue-discover/SKILL.md +106 -15
  86. package/.codex/skills/quality-auto-test/SKILL.md +70 -16
  87. package/.codex/skills/quality-debug/SKILL.md +139 -28
  88. package/.codex/skills/quality-refactor/SKILL.md +61 -11
  89. package/.codex/skills/quality-review/SKILL.md +45 -9
  90. package/.codex/skills/quality-test/SKILL.md +58 -3
  91. package/.codex/skills/security-audit/SKILL.md +38 -0
  92. package/.codex/skills/spec-map/SKILL.md +65 -8
  93. package/.codex/skills/team-coordinate/SKILL.md +28 -11
  94. package/.codex/skills/team-coordinate/specs/role-catalog.md +20 -0
  95. package/.codex/skills/team-lifecycle-v4/SKILL.md +23 -7
  96. package/.codex/skills/team-lifecycle-v4/instructions/agent-instruction.md +20 -0
  97. package/.codex/skills/team-quality-assurance/SKILL.md +40 -2
  98. package/.codex/skills/team-review/SKILL.md +42 -2
  99. package/.codex/skills/team-tech-debt/SKILL.md +45 -2
  100. package/.codex/skills/team-testing/SKILL.md +42 -2
  101. package/dashboard/dist-server/dashboard/src/server/wiki/search.d.ts +6 -4
  102. package/dashboard/dist-server/dashboard/src/server/wiki/search.js +50 -8
  103. package/dashboard/dist-server/dashboard/src/server/wiki/search.js.map +1 -1
  104. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.d.ts +32 -0
  105. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js +294 -0
  106. package/dashboard/dist-server/dashboard/src/server/wiki/virtual-wiki-adapters.js.map +1 -1
  107. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.d.ts +1 -0
  108. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js +35 -1
  109. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.js.map +1 -1
  110. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.test.js +235 -0
  111. package/dashboard/dist-server/dashboard/src/server/wiki/wiki-indexer.test.js.map +1 -1
  112. package/dist/src/commands/install.js +5 -1
  113. package/dist/src/commands/install.js.map +1 -1
  114. package/dist/src/i18n/locales/en.d.ts.map +1 -1
  115. package/dist/src/i18n/locales/en.js +9 -0
  116. package/dist/src/i18n/locales/en.js.map +1 -1
  117. package/dist/src/i18n/locales/zh.d.ts.map +1 -1
  118. package/dist/src/i18n/locales/zh.js +9 -0
  119. package/dist/src/i18n/locales/zh.js.map +1 -1
  120. package/dist/src/i18n/types.d.ts +3 -0
  121. package/dist/src/i18n/types.d.ts.map +1 -1
  122. package/dist/src/ralph/cmd-check.js +1 -1
  123. package/dist/src/ralph/cmd-check.js.map +1 -1
  124. package/dist/src/ralph/cmd-complete.js +1 -1
  125. package/dist/src/ralph/cmd-complete.js.map +1 -1
  126. package/dist/src/ralph/cmd-next.d.ts.map +1 -1
  127. package/dist/src/ralph/cmd-next.js +12 -4
  128. package/dist/src/ralph/cmd-next.js.map +1 -1
  129. package/dist/src/ralph/cmd-session.js +2 -2
  130. package/dist/src/ralph/cmd-session.js.map +1 -1
  131. package/dist/src/ralph/status-store.d.ts +8 -1
  132. package/dist/src/ralph/status-store.d.ts.map +1 -1
  133. package/dist/src/ralph/status-store.js +12 -2
  134. package/dist/src/ralph/status-store.js.map +1 -1
  135. package/dist/src/tools/store-knowhow.d.ts.map +1 -1
  136. package/dist/src/tools/store-knowhow.js +51 -64
  137. package/dist/src/tools/store-knowhow.js.map +1 -1
  138. package/dist/src/tui/install-ui/HooksConfig.d.ts +5 -1
  139. package/dist/src/tui/install-ui/HooksConfig.d.ts.map +1 -1
  140. package/dist/src/tui/install-ui/HooksConfig.js +5 -3
  141. package/dist/src/tui/install-ui/HooksConfig.js.map +1 -1
  142. package/dist/src/tui/install-ui/InstallConfirm.d.ts +2 -0
  143. package/dist/src/tui/install-ui/InstallConfirm.d.ts.map +1 -1
  144. package/dist/src/tui/install-ui/InstallConfirm.js +1 -1
  145. package/dist/src/tui/install-ui/InstallConfirm.js.map +1 -1
  146. package/dist/src/tui/install-ui/InstallExecution.d.ts +1 -0
  147. package/dist/src/tui/install-ui/InstallExecution.d.ts.map +1 -1
  148. package/dist/src/tui/install-ui/InstallExecution.js +26 -3
  149. package/dist/src/tui/install-ui/InstallExecution.js.map +1 -1
  150. package/dist/src/tui/install-ui/InstallFlow.d.ts +1 -1
  151. package/dist/src/tui/install-ui/InstallFlow.d.ts.map +1 -1
  152. package/dist/src/tui/install-ui/InstallFlow.js +76 -16
  153. package/dist/src/tui/install-ui/InstallFlow.js.map +1 -1
  154. package/dist/src/tui/install-ui/InstallHub.d.ts +2 -0
  155. package/dist/src/tui/install-ui/InstallHub.d.ts.map +1 -1
  156. package/dist/src/tui/install-ui/InstallHub.js +8 -0
  157. package/dist/src/tui/install-ui/InstallHub.js.map +1 -1
  158. package/dist/src/tui/install-ui/InstallResult.d.ts.map +1 -1
  159. package/dist/src/tui/install-ui/InstallResult.js +1 -1
  160. package/dist/src/tui/install-ui/InstallResult.js.map +1 -1
  161. package/dist/src/utils/update-notices.js +23 -0
  162. package/dist/src/utils/update-notices.js.map +1 -1
  163. package/package.json +1 -1
  164. package/workflows/finish-work.md +119 -0
  165. package/workflows/milestone-complete.md +23 -1
@@ -137,17 +137,17 @@ S_COMPLETE:
137
137
 
138
138
  1. **Checkpoint**: handle inline — save snapshot, update context.last_checkpoint, mark completed. If auto_continue==false: AskUserQuestion (Continue/Pause/Abort).
139
139
 
140
- 2. **Skill nodes**: resolve runtime references → write wave-{N}.csv → spawn:
140
+ 2. **Skill nodes**: resolve runtime references → write wave-{N}.csv (only rows with status == "pending") → spawn:
141
141
  ```
142
142
  spawn_agents_on_csv({
143
143
  csv_path: "wave-{N}.csv", id_column: "id",
144
144
  instruction: SUB_AGENT_INSTRUCTION,
145
- max_workers: waveSteps.length, max_runtime_seconds: 3600,
145
+ max_concurrency: waveSteps.length, max_runtime_seconds: 3600,
146
146
  output_csv_path: "wave-{N}-results.csv", output_schema: RESULT_SCHEMA
147
147
  })
148
148
  ```
149
149
 
150
- 3. Read results → update step status/findings/artifacts
150
+ 3. Read results → map `result_status` → master step `status`; copy `summary` into findings and `artifacts` into the step artifact list
151
151
  4. **Barrier analysis**: read artifacts, update context per barrier table
152
152
  5. Append wave record to state.waves[], persist state.json
153
153
 
@@ -158,14 +158,33 @@ spawn_agents_on_csv({
158
158
  先原样执行技能调用:{skill_call}
159
159
  然后基于结果完成任务说明:{topic}
160
160
  限制:不要修改 .workflow/.maestro/ 下的 state 文件
161
- 最后调用 report_agent_job_result,返回 JSON:
162
- {"status":"completed|failed","skill_call":"...","summary":"一句话","artifacts":"路径或空","error":"原因或空"}
161
+ 最后必须调用 report_agent_job_result(无论成功/失败/超时都必须上报)。
162
+
163
+ TERMINATION CONTRACT(强制):
164
+ - 成功:result_status = completed,summary 描述产出
165
+ - 失败:result_status = failed,error 写明原因
166
+ - 超时:临近 max_runtime_seconds 时立即上报 result_status = failed,error = "timeout"
167
+ - 禁止:无限循环、静默退出、跳过 report_agent_job_result
168
+
169
+ OUTPUT(必须匹配 output_schema):
170
+ {"id":"<row id>","result_status":"completed|failed","skill_call":"...","summary":"一句话","artifacts":"路径或空","error":"原因或空"}
163
171
  ```
164
172
 
165
173
  ### RESULT_SCHEMA
166
174
 
167
175
  ```json
168
- { "status": "completed|failed", "skill_call": "", "summary": "", "artifacts": "", "error": "" }
176
+ {
177
+ "type": "object",
178
+ "properties": {
179
+ "id": { "type": "string" },
180
+ "result_status": { "type": "string", "enum": ["completed", "failed"] },
181
+ "skill_call": { "type": "string" },
182
+ "summary": { "type": "string", "maxLength": 500 },
183
+ "artifacts": { "type": "string" },
184
+ "error": { "type": "string" }
185
+ },
186
+ "required": ["id", "result_status", "summary"]
187
+ }
169
188
  ```
170
189
 
171
190
  </actions>
@@ -1,17 +1,22 @@
1
1
  ---
2
2
  name: maestro-ralph
3
3
  description: Use when the optimal command sequence is unclear and needs automated state-based determination
4
- argument-hint: "<intent> [-y] | status | continue"
4
+ argument-hint: "<intent> [-y] | status [session-id] | continue [session-id]"
5
5
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, request_user_input
6
6
  ---
7
7
  <purpose>
8
8
  Closed-loop decision engine for the maestro workflow lifecycle.
9
9
  Reads project state → infers position → builds adaptive chain → delegates execution.
10
10
 
11
- Entry points:
12
- - **`/maestro-ralph "intent"`** — New session: infer → decompose → build → emit /goal prompt(如有 decomposition)→ dispatch ralph-execute
13
- - **`/maestro-ralph continue`** Wrapper; dispatches to ralph-execute(首选直接 `/maestro-ralph-execute` 推进 step)
14
- - **`/maestro-ralph status`** — Display session progress
11
+ ### Session
12
+
13
+ `.workflow/.maestro/{session_id}/status.json`工作流唯一真源(schema `<appendix>`)。session_id 格式:`ralph-{YYYYMMDD-HHmmss}`(本 skill 创建,自适应链)或 `maestro-{YYYYMMDD-HHmmss}`(`/maestro` coordinator 创建,静态链)。两类都由 `/maestro-ralph-execute` 推进。session-id 省略时取最新 `status=="running"`。
14
+
15
+ ### Entry points
16
+
17
+ - **`/maestro-ralph "intent"`** — 新建 session:infer → decompose → build → emit /goal prompt(如有 decomposition)→ dispatch ralph-execute
18
+ - **`/maestro-ralph continue [session-id]`** — 恢复执行;省略=最新 running(首选直接 `/maestro-ralph-execute [session-id]`)
19
+ - **`/maestro-ralph status [session-id]`** — 显示进度;省略=最新 ralph session
15
20
 
16
21
  > 推进规则:**step 推进由 `/maestro-ralph-execute` 负责**;ralph 仅在 build / decision 评估时介入。decision 节点由 ralph-execute 自动 `$maestro-ralph` 直调 handoff,无需用户手动切换。
17
22
 
@@ -48,9 +53,10 @@ $ARGUMENTS — intent text, flags, or keywords.
48
53
 
49
54
  **Parse:**
50
55
  ```
51
- -y flag → auto_confirm = true
52
- .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
53
- Remaining → intent
56
+ -y flag → auto_confirm = true
57
+ .md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
58
+ status|continue + session-idintent ∈ {status,continue} 且后续 token 匹配 ralph-*|maestro-* → target_session_id
59
+ Remaining → intent
54
60
  ```
55
61
 
56
62
  **State files:**
@@ -108,7 +114,8 @@ S_STATUS:
108
114
  → END DO: A_SHOW_STATUS
109
115
 
110
116
  S_CONTINUE:
111
- → S_DISPATCH WHEN: running session found
117
+ → S_DISPATCH WHEN: target_session_id provided AND session exists
118
+ → S_DISPATCH WHEN: running session found (no target_session_id → latest running)
112
119
  → S_FALLBACK WHEN: no running session DO: display "无运行中的 ralph 会话"
113
120
 
114
121
  S_RESOLVE_PHASE:
@@ -189,7 +196,7 @@ S_FALLBACK:
189
196
 
190
197
  ### A_SHOW_STATUS
191
198
 
192
- 1. Find latest ralph session (by created_at)
199
+ 1. `target_session_id` 提供 → 直接加载 `.workflow/.maestro/{target_session_id}/status.json`;否则取最新 ralph sessionby created_at
193
200
  2. Display: Session, Status, Position, Progress, Current step
194
201
  3. List steps: [✓] completion_confirmed, [▸] current, [ ] pending, [◆] decision(`step.decision` 非空);执行 step 附 `command_scope`(global/project) + `command_path`
195
202
  4. If `task_decomposition` present (absent → skip):
@@ -9,7 +9,8 @@ Single-step executor for ralph (adaptive) and maestro (static) sessions.
9
9
  Each invocation: locate session → find next step → resolve args → execute → update → self-invoke next.
10
10
 
11
11
  Mutual invocation with `/maestro-ralph` forms a self-perpetuating work loop.
12
- Session: `.workflow/.maestro/*/status.json`
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。
13
14
  </purpose>
14
15
 
15
16
  <context>
@@ -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.
@@ -247,31 +247,63 @@ Initialize `discovery-state.json`:
247
247
  spawn_agents_on_csv({
248
248
  csv_path: `${sessionFolder}/wave-1.csv`,
249
249
  id_column: "id",
250
- instruction: buildDiscoverInstruction(sessionFolder, discoveryDir, mode),
250
+ instruction: DISCOVER_PERSPECTIVE_INSTRUCTION, // see "Perspective Worker Contract" below
251
251
  max_concurrency: maxConcurrency,
252
252
  max_runtime_seconds: 3600,
253
253
  output_csv_path: `${sessionFolder}/wave-1-results.csv`,
254
- output_schema: { // required: id, result_status, findings
255
- id: "string", result_status: "completed|failed",
256
- findings: "string", issues_found: "string",
257
- severity_distribution: "string", error: "string"
254
+ output_schema: {
255
+ type: "object",
256
+ properties: {
257
+ id: { type: "string" },
258
+ result_status: { type: "string", enum: ["completed", "failed"] },
259
+ findings: { type: "string", maxLength: 500 },
260
+ issues_found: { type: "string", description: "JSON array string" },
261
+ severity_distribution: { type: "string", description: "JSON object string {critical, high, medium, low}" },
262
+ error: { type: "string" }
263
+ },
264
+ required: ["id", "result_status", "findings"]
258
265
  }
259
266
  })
260
267
  ```
261
268
 
262
- 6. Merge `wave-1-results.csv` into master `tasks.csv` (map `result_status` -> master `status` column)
269
+ 6. Merge `wave-1-results.csv` into master `tasks.csv` (map `result_status` -> master `status` column; copy `findings`, `issues_found`, `severity_distribution`, `error`)
263
270
  7. Save per-perspective findings to `{discoveryDir}/{perspective}-findings.json`
264
271
  8. Update `discovery-state.json` with completed perspectives
265
272
  9. Delete temporary files: `wave-1.csv` and `wave-1-results.csv`
266
273
 
267
- **Perspective scan agent protocol**:
268
- - Scan all source files matching scope_glob
269
- - Identify concrete issues with file:line references
270
- - Rate each finding: critical / high / medium / low
271
- - Provide brief fix direction for each finding
272
- - Report affected_components[]
273
- - Share cross-cutting discoveries via discovery board
274
- - Output issues_found as JSON array + severity_distribution as JSON object
274
+ #### Perspective Worker Contract (DISCOVER_PERSPECTIVE_INSTRUCTION)
275
+
276
+ ```
277
+ You are a perspective scanner for ONE dimension. Your perspective, scope_glob, and description come from your CSV row.
278
+
279
+ REQUIRED STEPS:
280
+ 1. Read shared discoveries: {sessionFolder}/discoveries.ndjson (may be empty)
281
+ 2. Scan all files matching scope_glob using Read/Grep/Glob (read-only)
282
+ 3. For each finding: capture title, severity (critical|high|medium|low), description, file:line location, fix_direction, affected_components[]
283
+ 4. Append cross-cutting patterns to discoveries.ndjson (dedup by type+key)
284
+ 5. Call report_agent_job_result EXACTLY ONCE
285
+
286
+ TERMINATION CONTRACT (mandatory — NO worker may end without calling report_agent_job_result):
287
+ - Success path → result_status=completed (issues_found may be empty array if nothing found)
288
+ - Timeout path → near max_runtime_seconds, STOP and report completed with partial issues_found (do NOT report failed for timeout — partial work is valuable)
289
+ - Failure path → unrecoverable error (cannot read scope, parse failure) → result_status=failed with error message
290
+ - NEVER continue indefinitely. NEVER exit silently. NEVER omit the call.
291
+
292
+ OUTPUT (return via report_agent_job_result; must match output_schema):
293
+ {
294
+ "id": "<your row id>",
295
+ "result_status": "completed" | "failed",
296
+ "findings": "<one-sentence summary, max 500 chars>",
297
+ "issues_found": "<JSON array string: [{\"title\":\"...\",\"severity\":\"...\",\"description\":\"...\",\"location\":\"file:line\",\"fix_direction\":\"...\",\"affected_components\":[...]}]>",
298
+ "severity_distribution": "<JSON object string: {\"critical\":N,\"high\":N,\"medium\":N,\"low\":N}>",
299
+ "error": "<message if failed, else empty>"
300
+ }
301
+
302
+ CONSTRAINTS:
303
+ - Every finding MUST have a concrete file:line reference. No speculative issues.
304
+ - Do NOT write to tasks.csv, wave-*.csv, results.csv, or issues.jsonl (orchestrator owns those).
305
+ - Do NOT call spawn_agents_on_csv (no recursion).
306
+ ```
275
307
 
276
308
  #### Wave 2: Dedup + Issue Creation (Single Agent)
277
309
 
@@ -285,10 +317,69 @@ spawn_agents_on_csv({
285
317
  ...
286
318
  ```
287
319
  5. Write `wave-2.csv` with `prev_context` column
288
- 6. Execute `spawn_agents_on_csv` for dedup agent
320
+ 6. Execute:
321
+
322
+ ```javascript
323
+ spawn_agents_on_csv({
324
+ csv_path: `${sessionFolder}/wave-2.csv`,
325
+ id_column: "id",
326
+ instruction: DEDUP_INSTRUCTION, // see "Dedup Worker Contract" below
327
+ max_concurrency: 1,
328
+ max_runtime_seconds: 1800,
329
+ output_csv_path: `${sessionFolder}/wave-2-results.csv`,
330
+ output_schema: {
331
+ type: "object",
332
+ properties: {
333
+ id: { type: "string" },
334
+ result_status: { type: "string", enum: ["completed", "failed"] },
335
+ findings: { type: "string", maxLength: 500 },
336
+ issues_found: { type: "string", description: "JSON array of deduplicated issues with ISS-* IDs" },
337
+ severity_distribution: { type: "string" },
338
+ error: { type: "string" }
339
+ },
340
+ required: ["id", "result_status", "findings"]
341
+ }
342
+ })
343
+ ```
344
+
289
345
  7. Merge results into master `tasks.csv` (map `result_status` -> master `status` column)
290
346
  8. Delete temporary files: `wave-2.csv` and `wave-2-results.csv`
291
347
 
348
+ #### Dedup Worker Contract (DEDUP_INSTRUCTION)
349
+
350
+ ```
351
+ You are the dedup + issue creation worker. Your prev_context contains all wave-1 perspective findings.
352
+
353
+ REQUIRED STEPS:
354
+ 1. Parse prev_context — extract every issues_found JSON from upstream rows
355
+ 2. Deduplicate: group by file path, compare descriptions (>80% overlap or same file:line → keep higher severity)
356
+ 3. Assign collision-safe ID per unique issue: ISS-YYYYMMDD-NNN
357
+ 4. Build full issue record (severity→priority: critical→1/high→2/medium→3/low→4; source="discover"; tags=[perspective])
358
+ 5. Append deduplicated records to .workflow/issues/issues.jsonl AND {discoveryDir}/discovery-issues.jsonl
359
+ 6. Call report_agent_job_result EXACTLY ONCE
360
+
361
+ TERMINATION CONTRACT (mandatory):
362
+ - Success → result_status=completed with issues_found = final deduped JSON array
363
+ - Timeout → near max_runtime_seconds, persist partial dedup, report completed with note in findings
364
+ - Failure → file write error, parse error → result_status=failed
365
+ - NEVER skip report_agent_job_result.
366
+
367
+ OUTPUT (must match output_schema):
368
+ {
369
+ "id": "<your row id>",
370
+ "result_status": "completed" | "failed",
371
+ "findings": "<pre-dedup count → post-dedup count summary>",
372
+ "issues_found": "<JSON array of final deduplicated issues>",
373
+ "severity_distribution": "<JSON object: {critical, high, medium, low}>",
374
+ "error": "<message if failed, else empty>"
375
+ }
376
+
377
+ CONSTRAINTS:
378
+ - Append-only writes to issues.jsonl. Never overwrite existing records.
379
+ - Every record MUST include source: "discover".
380
+ - Do NOT call spawn_agents_on_csv (no recursion).
381
+ ```
382
+
292
383
  **Dedup agent protocol**:
293
384
  - Merge all perspective findings from prev_context into single list
294
385
  - Deduplicate: group by file path, compare descriptions (>80% overlap or same file:line → keep higher severity)