maestro-flow 0.4.2 → 0.4.3

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 (80) hide show
  1. package/.claude/commands/maestro-analyze.md +1 -1
  2. package/.claude/commands/maestro-brainstorm.md +1 -1
  3. package/.claude/commands/maestro-collab.md +1 -1
  4. package/.claude/commands/maestro-execute.md +10 -1
  5. package/.claude/commands/maestro-guard.md +101 -0
  6. package/.claude/commands/maestro-impeccable.md +1 -1
  7. package/.claude/commands/maestro-plan.md +15 -2
  8. package/.claude/commands/maestro-ralph-execute.md +9 -2
  9. package/.claude/commands/maestro-ralph.md +8 -1
  10. package/.claude/commands/maestro-verify.md +15 -1
  11. package/.claude/commands/quality-auto-test.md +1 -1
  12. package/.claude/commands/quality-debug.md +1 -1
  13. package/.claude/commands/quality-refactor.md +1 -1
  14. package/.claude/commands/quality-retrospective.md +1 -1
  15. package/.claude/commands/quality-review.md +15 -1
  16. package/.claude/commands/quality-test.md +1 -1
  17. package/.claude/commands/security-audit.md +154 -0
  18. package/.claude/skills/maestro-help/index/catalog.json +2 -0
  19. package/.codex/skills/maestro-analyze/SKILL.md +18 -1
  20. package/.codex/skills/maestro-brainstorm/SKILL.md +17 -4
  21. package/.codex/skills/maestro-collab/SKILL.md +7 -1
  22. package/.codex/skills/maestro-execute/SKILL.md +365 -348
  23. package/.codex/skills/maestro-guard/SKILL.md +97 -0
  24. package/.codex/skills/maestro-impeccable/SKILL.md +1 -1
  25. package/.codex/skills/maestro-plan/SKILL.md +66 -7
  26. package/.codex/skills/maestro-ralph/SKILL.md +1 -1
  27. package/.codex/skills/maestro-verify/SKILL.md +18 -1
  28. package/.codex/skills/quality-auto-test/SKILL.md +13 -3
  29. package/.codex/skills/quality-debug/SKILL.md +362 -346
  30. package/.codex/skills/quality-refactor/SKILL.md +1 -1
  31. package/.codex/skills/quality-retrospective/SKILL.md +292 -292
  32. package/.codex/skills/quality-review/SKILL.md +374 -365
  33. package/.codex/skills/quality-test/SKILL.md +1 -1
  34. package/.codex/skills/security-audit/SKILL.md +154 -0
  35. package/bin/maestro-hook-runner.js +21 -1
  36. package/dashboard/dist-server/src/coordinator/output-parser.js +27 -0
  37. package/dashboard/dist-server/src/coordinator/output-parser.js.map +1 -1
  38. package/dist/src/commands/coordinate.d.ts.map +1 -1
  39. package/dist/src/commands/coordinate.js +2 -0
  40. package/dist/src/commands/coordinate.js.map +1 -1
  41. package/dist/src/commands/hooks.d.ts.map +1 -1
  42. package/dist/src/commands/hooks.js +39 -3
  43. package/dist/src/commands/hooks.js.map +1 -1
  44. package/dist/src/coordinator/output-parser.d.ts.map +1 -1
  45. package/dist/src/coordinator/output-parser.js +27 -0
  46. package/dist/src/coordinator/output-parser.js.map +1 -1
  47. package/dist/src/hooks/delegate-monitor.d.ts +1 -0
  48. package/dist/src/hooks/delegate-monitor.d.ts.map +1 -1
  49. package/dist/src/hooks/delegate-monitor.js +1 -1
  50. package/dist/src/hooks/delegate-monitor.js.map +1 -1
  51. package/dist/src/hooks/guards/workflow-guard.d.ts +15 -0
  52. package/dist/src/hooks/guards/workflow-guard.d.ts.map +1 -1
  53. package/dist/src/hooks/guards/workflow-guard.js +61 -1
  54. package/dist/src/hooks/guards/workflow-guard.js.map +1 -1
  55. package/dist/src/hooks/plugins/decision-log-plugin.d.ts +19 -0
  56. package/dist/src/hooks/plugins/decision-log-plugin.d.ts.map +1 -0
  57. package/dist/src/hooks/plugins/decision-log-plugin.js +28 -0
  58. package/dist/src/hooks/plugins/decision-log-plugin.js.map +1 -0
  59. package/dist/src/hooks/plugins/index.d.ts +2 -0
  60. package/dist/src/hooks/plugins/index.d.ts.map +1 -1
  61. package/dist/src/hooks/plugins/index.js +1 -0
  62. package/dist/src/hooks/plugins/index.js.map +1 -1
  63. package/dist/src/hooks/session-context.d.ts +1 -0
  64. package/dist/src/hooks/session-context.d.ts.map +1 -1
  65. package/dist/src/hooks/session-context.js +1 -1
  66. package/dist/src/hooks/session-context.js.map +1 -1
  67. package/dist/src/hooks/skill-context.d.ts +1 -0
  68. package/dist/src/hooks/skill-context.d.ts.map +1 -1
  69. package/dist/src/hooks/skill-context.js +1 -1
  70. package/dist/src/hooks/skill-context.js.map +1 -1
  71. package/dist/src/hooks/spec-injector.d.ts.map +1 -1
  72. package/dist/src/hooks/spec-injector.js +2 -0
  73. package/dist/src/hooks/spec-injector.js.map +1 -1
  74. package/package.json +1 -1
  75. package/workflows/debug.md +73 -0
  76. package/workflows/execute.md +27 -0
  77. package/workflows/plan.md +11 -0
  78. package/workflows/review.md +33 -1
  79. package/workflows/tdd.md +257 -0
  80. package/workflows/verify.md +57 -0
@@ -1,348 +1,365 @@
1
- ---
2
- name: maestro-execute
3
- description: Execute plan with parallel waves and atomic commits
4
- argument-hint: "[-y|--yes] [-c|--concurrency N] [--continue] \"<phase> [--auto-commit] [--method agent|cli] [--dir <path>]\""
5
- allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, request_user_input
6
- ---
7
-
8
- <purpose>
9
- Wave-based parallel task execution using `spawn_agents_on_csv`. Reads plan.json to build a CSV where waves are pre-computed from the plan. Each wave runs tasks in parallel, with cross-wave context propagation via `prev_context`. This is the core execution engine of the maestro pipeline.
10
-
11
- **Core workflow**: Load Plan -> Build CSV from Tasks -> Wave-by-Wave Parallel Execution -> Aggregate Results
12
-
13
- **Topology**: Custom (waves inherited from plan.json -- no Kahn's algorithm needed)
14
-
15
- ```
16
- +---------------------------------------------------------------------------+
17
- | TASK EXECUTION CSV WAVE WORKFLOW |
18
- +---------------------------------------------------------------------------+
19
- | |
20
- | Phase 1: Plan Resolution -> CSV |
21
- | +-- Resolve phase directory (or --dir path) |
22
- | +-- Read plan.json + .task/TASK-*.json definitions |
23
- | +-- Detect completed tasks (breakpoint resume) |
24
- | +-- Build tasks.csv with one row per pending task |
25
- | +-- Waves inherited from plan.json (pre-computed) |
26
- | +-- Load project specs for executor context |
27
- | +-- User validates task breakdown (skip if -y) |
28
- | |
29
- | Phase 2: Wave Execution Engine |
30
- | +-- For each wave (sequential): |
31
- | | +-- Wave N: Task Execution (parallel within wave) |
32
- | | | +-- Each agent implements one task |
33
- | | | +-- Agent reads task definition + convergence criteria |
34
- | | | +-- Agent creates/modifies files per task.files |
35
- | | | +-- Agent verifies convergence.criteria (max 3 fix attempts) |
36
- | | | +-- Agent writes .summaries/TASK-{NNN}-summary.md |
37
- | | | +-- Atomic commit if --auto-commit |
38
- | | | +-- Discoveries shared via board (patterns, blockers) |
39
- | | +-- Merge wave results into master tasks.csv |
40
- | | +-- Build prev_context for next wave from completed findings |
41
- | | +-- If blocked tasks: prompt user (skip if -y: auto-continue) |
42
- | +-- discoveries.ndjson shared across all waves (append-only) |
43
- | |
44
- | Phase 3: Results Aggregation |
45
- | +-- Export results.csv |
46
- | +-- Update .task/TASK-*.json statuses |
47
- | +-- Update index.json execution progress |
48
- | +-- Update state.json project progress |
49
- | +-- Generate context.md with execution report |
50
- | +-- Auto-sync codebase docs (if configured) |
51
- | +-- Display summary with next steps |
52
- | |
53
- +---------------------------------------------------------------------------+
54
- ```
55
-
56
- </purpose>
57
-
58
- <context>
59
- ```bash
60
- $maestro-execute "3"
61
- $maestro-execute -c 4 "3 --auto-commit"
62
- $maestro-execute -y "3 --method cli"
63
- $maestro-execute "3 --dir .workflow/scratch/quick-fix"
64
- $maestro-execute --continue "20260318-execute-P3-phase3"
65
- ```
66
-
67
- **Flags**:
68
- - `-y, --yes`: Skip all confirmations (auto mode)
69
- - `-c, --concurrency N`: Max concurrent agents within each wave (default: 5)
70
- - `--continue`: Resume existing session
71
-
72
- **Inner flags** (passed inside quotes):
73
- - `--auto-commit`: Atomic git commit after each task completion
74
- - `--method agent|cli`: Override execution method (default: from config.json)
75
- - `--dir <path>`: Use arbitrary directory instead of phase resolution (scratch mode)
76
-
77
- When `--yes` or `-y`: Auto-confirm task breakdown, skip blocked-task prompts, auto-continue through all waves.
78
-
79
- **Output Directory**: `.workflow/.csv-wave/{session-id}/`
80
- **Core Output**: `tasks.csv` (master state) + `results.csv` (final) + `discoveries.ndjson` (shared exploration) + `context.md` (human-readable report)
81
- </context>
82
-
83
- <csv_schema>
84
-
85
- ### tasks.csv (Master State)
86
-
87
- ```csv
88
- id,title,description,scope,convergence_criteria,hints,execution_directives,deps,context_from,wave,status,findings,files_modified,tests_passed,error
89
- "TASK-001","Setup auth module","Create authentication module with JWT token generation and verification. Export verifyToken and generateToken functions.","src/auth/","auth.ts contains export function verifyToken(; auth.ts contains export function generateToken(","Reference existing middleware pattern in src/middleware/auth.ts","npm test -- --grep auth","","","1","","","","",""
90
- "TASK-002","Create user model","Define User interface and database schema with email, passwordHash, role fields. Use existing Result type pattern.","src/models/","user.ts contains export interface User; user.ts contains email: string","See src/models/session.ts for existing model pattern","npm test -- --grep user","","","1","","","","",""
91
- "TASK-003","Auth middleware","Create Express middleware that validates JWT from Authorization header. Use verifyToken from auth module. Return 401 on invalid token.","src/middleware/","auth-middleware.ts contains export function authMiddleware(; auth-middleware.ts contains verifyToken","Follows existing middleware pattern in src/middleware/logging.ts","npm test -- --grep middleware","TASK-001","TASK-001","2","","","","",""
92
- "TASK-004","Login endpoint","Implement POST /api/login endpoint. Validate credentials against user model, return JWT on success. Use generateToken from auth module.","src/routes/","login.ts contains router.post('/api/login'; login.ts contains generateToken(","Wire into existing Express app in src/app.ts","curl -X POST localhost:3000/api/login","TASK-001;TASK-002","TASK-001;TASK-002","2","","","","",""
93
- "TASK-005","Integration tests","Write integration tests for full auth flow: register, login, access protected route, token refresh.","tests/","tests/auth.test.ts exists; npm test exits with code 0","Use existing test setup in tests/setup.ts","npm test","TASK-003;TASK-004","TASK-003;TASK-004","3","","","","",""
94
- ```
95
-
96
- **Columns**:
97
-
98
- | Column | Phase | Description |
99
- |--------|-------|-------------|
100
- | `id` | Input | Task ID (TASK-NNN format, from plan.json) |
101
- | `title` | Input | Short task title from task definition |
102
- | `description` | Input | Full task description from TASK-*.json |
103
- | `scope` | Input | Target file/directory glob from task.files |
104
- | `convergence_criteria` | Input | Grep-verifiable completion criteria (semicolon-separated) |
105
- | `hints` | Input | Implementation hints + reference files from task definition |
106
- | `execution_directives` | Input | Verification commands to run after implementation |
107
- | `deps` | Input | Semicolon-separated dependency task IDs |
108
- | `context_from` | Input | Semicolon-separated task IDs whose findings this task needs |
109
- | `wave` | Computed | Wave number from plan.json wave assignment |
110
- | `status` | Output | `pending` -> `completed` / `failed` / `blocked` / `skipped` |
111
- | `findings` | Output | Implementation notes and observations (max 500 chars) |
112
- | `files_modified` | Output | Semicolon-separated list of created/modified files |
113
- | `tests_passed` | Output | Test pass/fail status from execution_directives |
114
- | `error` | Output | Error message if failed or blocked |
115
-
116
- ### Per-Wave CSV (Temporary)
117
-
118
- Each wave generates `wave-{N}.csv` with extra `prev_context` column populated from predecessor task findings.
119
-
120
- ### Output Artifacts
121
-
122
- | File | Purpose | Lifecycle |
123
- |------|---------|-----------|
124
- | `tasks.csv` | Master state -- all tasks with status/findings | Updated after each wave |
125
- | `wave-{N}.csv` | Per-wave input (temporary) | Created before wave, deleted after |
126
- | `wave-{N}-results.csv` | Per-wave output | Created by spawn_agents_on_csv |
127
- | `results.csv` | Final export of all task results | Created in Phase 3 |
128
- | `discoveries.ndjson` | Shared exploration board | Append-only, carries across waves |
129
- | `context.md` | Human-readable execution report | Created in Phase 3 |
130
-
131
- ### Session Structure
132
-
133
- ```
134
- .workflow/.csv-wave/{YYYYMMDD}-execute-P{N}-{slug}/
135
- +-- tasks.csv
136
- +-- results.csv
137
- +-- discoveries.ndjson
138
- +-- context.md
139
- +-- config.json
140
- +-- wave-{N}.csv (temporary)
141
- +-- wave-{N}-results.csv (temporary)
142
- ```
143
- </csv_schema>
144
-
145
- <invariants>
146
- 1. **Start Immediately**: First action is session initialization, then Phase 1
147
- 2. **Wave Order is Sacred**: Never execute wave N+1 before wave N completes and results are merged
148
- 3. **CSV is Source of Truth**: Master tasks.csv holds all execution state
149
- 4. **Context Propagation**: prev_context built from master CSV findings, not from memory
150
- 5. **Discovery Board is Append-Only**: Never clear, modify, or recreate discoveries.ndjson
151
- 6. **Cascading Skip on Failure**: If a task fails/blocks, all dependent tasks are skipped
152
- 7. **Cleanup Temp Files**: Remove wave-{N}.csv after results are merged
153
- 8. **Max 3 Fix Attempts**: Per task, auto-fix convergence failures up to 3 times, then mark blocked
154
- 9. **Breakpoint Resume**: Always detect completed tasks and skip them on re-run
155
- 10. **DO NOT STOP**: Continuous execution until all waves complete or user explicitly stops
156
- </invariants>
157
-
158
- <execution>
159
-
160
- ### Session Initialization
161
-
162
- ```
163
- Parse from $ARGUMENTS:
164
- AUTO_YES ← --yes | -y
165
- continueMode ← --continue
166
- maxConcurrency ← --concurrency | -c N (default: 5)
167
- autoCommit ← --auto-commit
168
- executionMethod ← --method agent|cli (default: from config.json)
169
- scratchDir ← --dir <path> (default: null)
170
- phaseArg ← remaining text after flag removal
171
-
172
- Derive:
173
- dateStrUTC+8 YYYYMMDD
174
- sessionId scratchDir ? "{dateStr}-execute-scratch" : "{dateStr}-execute-P{phaseArg}-{phaseSlug}"
175
- sessionFolder".workflow/.csv-wave/{sessionId}"
176
-
177
- mkdir -p {sessionFolder}
178
- ```
179
-
180
- ### Pre-flight: Team Conflict Check
181
-
182
- Before any task execution, run:
183
- ```
184
- Bash("maestro collab preflight --phase <phase-number>")
185
- ```
186
- If exit code is 1, present warnings and ask whether to proceed.
187
-
188
- ### Phase 1: Plan Resolution -> CSV
189
-
190
- **Objective**: Resolve phase, load plan + task definitions, detect resume point, generate tasks.csv.
191
-
192
- **Decomposition Rules**:
193
-
194
- 1. **Plan resolution** (per scratch-milestone-architecture):
195
-
196
- | Input | Resolution |
197
- |-------|------------|
198
- | `--dir <path>` | Use path directly (scratch plan dir) |
199
- | No args | Find all pending plans for current milestone from state.json.artifacts[] |
200
- | Number (e.g., `3`) | Find pending plans for phase N from state.json.artifacts[] |
201
-
202
- For multi-plan: execute sequentially. Each plan is a full CSV session.
203
-
204
- 2. **Load plan**: Read `{PLAN_DIR}/plan.json` for wave structure and task assignments
205
-
206
- 3. **Detect completed tasks (breakpoint resume)**: Read `.task/TASK-{NNN}.json` for each task; exclude completed ones from CSV. Log resume count.
207
-
208
- 4. **Build tasks.csv**: For each pending task per wave, read `.task/TASK-{NNN}.json` and extract: title, description, scope (from files), convergence.criteria, hints, execution_directives. Set `deps` from task dependency, `context_from` = deps, `wave` from plan.json.
209
-
210
- 5. **Load project specs + tools**: Run `maestro spec load --category coding` to load coding conventions, architecture constraints, AND discoverable knowhow tools (passed to all agents)
211
-
212
- 6. **Load UI specs (conditional)**: If any task involves frontend/UI work (task scope/description contains component, page, style, layout, CSS, HTML, frontend; or focus_paths in `src/components/`, `src/pages/`, `src/styles/`, `src/ui/`), also run `maestro spec load --category ui` and include in agent context.
213
-
214
- 7. **Load codebase + wiki context** (optional, passed to all agents):
215
- - If `.workflow/codebase/ARCHITECTURE.md` exists: read and include as `codebase_context` in agent instructions
216
- - Run `maestro wiki search "<phase keywords>" --json 2>/dev/null`; if results: include top 5 entries as `wiki_context`
217
- - Both are optional proceed without if unavailable
218
-
219
- 7. **User validation**: Display task/wave breakdown. Skip if AUTO_YES.
220
-
221
- ### Phase 2: Wave Execution Engine
222
-
223
- **Objective**: Execute tasks wave-by-wave via spawn_agents_on_csv with cross-wave context propagation.
224
-
225
- #### Per-Wave Execution Loop
226
-
227
- For each wave N in ascending order:
228
-
229
- 1. Extract wave N pending rows from master `tasks.csv` (skip wave if none)
230
- 2. Build `prev_context` per task from completed predecessor findings
231
- 3. Write `wave-{N}.csv` with `prev_context` column, then execute:
232
-
233
- ```javascript
234
- spawn_agents_on_csv({
235
- csv_path: `${sessionFolder}/wave-${N}.csv`,
236
- id_column: "id",
237
- instruction: buildExecutorInstruction(sessionFolder, phaseDir, autoCommit, specsContent), // agent: ~/.codex/agents/workflow-executor.toml
238
- max_concurrency: maxConcurrency, max_runtime_seconds: 3600,
239
- output_csv_path: `${sessionFolder}/wave-${N}-results.csv`,
240
- output_schema: { id, status: [completed|failed|blocked], findings, files_modified, tests_passed, error }
241
- })
242
- ```
243
-
244
- 4. Merge results into master `tasks.csv`, delete `wave-{N}.csv`
245
-
246
- #### Blocked Task Handling
247
-
248
- After each wave: if blocked tasks exist, prompt user to continue or stop (AUTO_YES: auto-continue). Skip tasks whose deps are blocked/failed.
249
-
250
- #### Cascading Skip
251
-
252
- Blocked/failed tasks cascade: mark all downstream dependents as `skipped` with error "Dependency {dep_id} blocked/failed".
253
-
254
- ### Phase 3: Results Aggregation
255
-
256
- **Objective**: Update all state files and generate execution report.
257
-
258
- 1. Export final `tasks.csv` as `results.csv`
259
-
260
- 2. **Update task files**: Write each task's status from CSV back to `.task/{id}.json`
261
-
262
- 3. **Issue status sync**: For tasks with `issue_id`, update `.workflow/issues/issues.jsonl`:
263
- - All task_refs completed -> `issue.status = "resolved"`; any failed -> `"in_progress"`
264
- - Append history entry: `{ action: "executed", at: <ISO>, by: "maestro-execute", summary: "TASK-{NNN} {status}" }`
265
-
266
- 4. **Register EXC artifact in state.json**: Find matching plan artifact, create `{ id: "EXC-{next_id}", type: "execute", milestone, phase, scope, path, status: "completed", depends_on: plan_artifact.id, harvested: false, created_at, completed_at }`
267
-
268
- 5. **Extract incremental specs**: Read `.summaries/`, use `maestro spec add` CLI:
269
- - Learnings/pitfalls → `maestro spec add learning "<title>" "<content>" --keywords ... --source execute:{PLAN_DIR}`
270
- - Design rationale `maestro spec add coding "<title>" "<content>" --keywords ...`
271
- - Root cause/workaround → `maestro spec add debug "<title>" "<content>" --keywords ...`
272
- Mark artifact `harvested: true`
273
-
274
- 6. **Post-task Knowledge Inquiry**: After each task completes, evaluate inquiry triggers:
275
-
276
- - **Execution deviation**: If task summary mentions approach change, dependency swap, or plan deviation:
277
- Prompt: "TASK-{NNN} deviated from the plan. Record as architecture constraint?"
278
- On confirm: `maestro spec add arch "<decision>" "<rationale>" --keywords ... --source execute:{PLAN_DIR}`
279
-
280
- - **Retry success**: If task required >=2 retries before completion:
281
- → Prompt: "TASK-{NNN} succeeded after {N} retries. Document this fix pattern?"
282
- On confirm: `maestro spec add debug "<pattern>" "<content>" --keywords ... --source execute:{PLAN_DIR}`
283
-
284
- - **Implicit knowledge**: If task summary contains design rationale ("chose X because", "rejected Y due to"):
285
- Prompt: "Design decision detected. Record as a learning?"
286
- On confirm: `maestro spec add learning "<decision>" "<rationale>" --keywords ... --source execute:{PLAN_DIR}`
287
-
288
- Use `request_user_input` for prompts:
289
- ```json
290
- { "questions": [{ "id": "knowledge-capture", "header": "Knowledge Capture", "question": "...", "options": [{ "label": "Yes", "description": "Record to specs" }, { "label": "Skip", "description": "Continue without recording" }] }] }
291
- ```
292
-
293
- 7. **Generate context.md**: Execution report with summary (tasks/blocked/waves/auto-commit), per-wave result table (task, status, files, tests), blocked tasks, discovery board summary, next steps.
294
-
295
- 8. **Auto-sync** (if config.json.codebase.auto_sync_after_execute == true): detect changed files, trigger codebase doc update.
296
-
297
- 9. **Display completion report**: Phase, completed/blocked counts, wave progress, paths to `.summaries/` and `.task/`, next step suggestions (`maestro-verify`, `manage-status`).
298
-
299
- ### Shared Discovery Board Protocol
300
-
301
- #### Standard Discovery Types
302
-
303
- | Type | Dedup Key | Data Schema | Description |
304
- |------|-----------|-------------|-------------|
305
- | `code_pattern` | `data.name` | `{name, file, description}` | Reusable code pattern found during implementation |
306
- | `integration_point` | `data.file` | `{file, description, exports[]}` | Module connection point discovered |
307
- | `convention` | singleton | `{naming, imports, formatting}` | Project coding conventions observed |
308
- | `blocker` | `data.issue` | `{issue, severity, impact}` | Blocking issue encountered |
309
- | `tech_stack` | singleton | `{framework, language, tools[]}` | Technology stack detail confirmed |
310
- | `test_command` | `data.command` | `{command, scope, result}` | Working test command discovered |
311
-
312
- #### Protocol
313
-
314
- Read `discoveries.ndjson` before implementation. Append-only: dedup by type+key before writing, never modify/delete.
315
-
316
- ```bash
317
- echo '{"ts":"<ISO>","worker":"TASK-001","type":"code_pattern","data":{"name":"Result type","file":"src/types/result.ts","description":"All functions return Result<T,E> for error handling"}}' >> {session_folder}/discoveries.ndjson
318
- ```
319
- </execution>
320
-
321
- <error_codes>
322
-
323
- | Error | Resolution |
324
- |-------|------------|
325
- | Phase directory not found | Abort with error: "Phase {N} not found" |
326
- | plan.json not found | Abort with error: "No plan found -- run plan first" |
327
- | No pending tasks (all completed) | Abort with info: "All tasks already completed" |
328
- | Task file (.task/TASK-*.json) missing | Skip task, log error, mark as failed |
329
- | Agent spawn fails | Retry once, then mark task as blocked with checkpoint |
330
- | Convergence criteria not met after 3 attempts | Mark task as blocked, write checkpoint |
331
- | Git commit fails (--auto-commit) | Log warning, continue (task still marked completed) |
332
- | All tasks in wave blocked | Stop execution, report blocked wave |
333
- | CSV parse error | Validate format, show line number |
334
- | discoveries.ndjson corrupt | Ignore malformed lines, continue |
335
- | Continue mode: no session found | List available sessions |
336
- </error_codes>
337
-
338
- <success_criteria>
339
- - [ ] Session folder created with valid tasks.csv
340
- - [ ] All waves executed in order with cross-wave context propagation
341
- - [ ] Completed tasks have .summaries/TASK-{NNN}-summary.md
342
- - [ ] .task/TASK-*.json statuses updated to match execution results
343
- - [ ] state.json updated with EXC artifact
344
- - [ ] context.md produced with execution report
345
- - [ ] Blocked tasks have checkpoint info for resume
346
- - [ ] Cascading skip applied for dependent tasks
347
- - [ ] discoveries.ndjson append-only throughout
348
- </success_criteria>
1
+ ---
2
+ name: maestro-execute
3
+ description: Use when a confirmed plan is ready for implementation
4
+ argument-hint: "[-y|--yes] [-c|--concurrency N] [--continue] \"<phase> [--auto-commit] [--method agent|cli] [--dir <path>]\""
5
+ allowed-tools: spawn_agents_on_csv, Read, Write, Edit, Bash, Glob, Grep, request_user_input
6
+ ---
7
+
8
+ <purpose>
9
+ Wave-based parallel task execution using `spawn_agents_on_csv`. Reads plan.json to build a CSV where waves are pre-computed from the plan. Each wave runs tasks in parallel, with cross-wave context propagation via `prev_context`. This is the core execution engine of the maestro pipeline.
10
+
11
+ **Core workflow**: Load Plan -> Build CSV from Tasks -> Wave-by-Wave Parallel Execution -> Aggregate Results
12
+
13
+ ## Iron Law
14
+
15
+ **VERIFY EACH TASK OUTPUT BEFORE MARKING COMPLETE.** Every task needs convergence criteria checks — no task may be marked "completed" based on agent self-report alone.
16
+
17
+ ## Red Flags These Thoughts Mean STOP
18
+ - "The agent said it's done, so it must be done" / "I'll batch-verify all tasks at the end"
19
+ - "This task is too simple to need verification" / "Let me mark it complete and fix later"
20
+ All mean: **run convergence criteria check NOW**.
21
+
22
+ **Topology**: Custom (waves inherited from plan.json -- no Kahn's algorithm needed)
23
+
24
+ ```
25
+ +---------------------------------------------------------------------------+
26
+ | TASK EXECUTION CSV WAVE WORKFLOW |
27
+ +---------------------------------------------------------------------------+
28
+ | |
29
+ | Phase 1: Plan Resolution -> CSV |
30
+ | +-- Resolve phase directory (or --dir path) |
31
+ | +-- Read plan.json + .task/TASK-*.json definitions |
32
+ | +-- Detect completed tasks (breakpoint resume) |
33
+ | +-- Build tasks.csv with one row per pending task |
34
+ | +-- Waves inherited from plan.json (pre-computed) |
35
+ | +-- Load project specs for executor context |
36
+ | +-- User validates task breakdown (skip if -y) |
37
+ | |
38
+ | Phase 2: Wave Execution Engine |
39
+ | +-- For each wave (sequential): |
40
+ | | +-- Wave N: Task Execution (parallel within wave) |
41
+ | | | +-- Each agent implements one task |
42
+ | | | +-- Agent reads task definition + convergence criteria |
43
+ | | | +-- Agent creates/modifies files per task.files |
44
+ | | | +-- Agent verifies convergence.criteria (max 3 fix attempts) |
45
+ | | | +-- Agent writes .summaries/TASK-{NNN}-summary.md |
46
+ | | | +-- Atomic commit if --auto-commit |
47
+ | | | +-- Discoveries shared via board (patterns, blockers) |
48
+ | | +-- Merge wave results into master tasks.csv |
49
+ | | +-- Build prev_context for next wave from completed findings |
50
+ | | +-- If blocked tasks: prompt user (skip if -y: auto-continue) |
51
+ | +-- discoveries.ndjson shared across all waves (append-only) |
52
+ | |
53
+ | Phase 3: Results Aggregation |
54
+ | +-- Export results.csv |
55
+ | +-- Update .task/TASK-*.json statuses |
56
+ | +-- Update index.json execution progress |
57
+ | +-- Update state.json project progress |
58
+ | +-- Generate context.md with execution report |
59
+ | +-- Auto-sync codebase docs (if configured) |
60
+ | +-- Display summary with next steps |
61
+ | |
62
+ +---------------------------------------------------------------------------+
63
+ ```
64
+
65
+ </purpose>
66
+
67
+ <context>
68
+ ```bash
69
+ $maestro-execute "3"
70
+ $maestro-execute -c 4 "3 --auto-commit"
71
+ $maestro-execute -y "3 --method cli"
72
+ $maestro-execute "3 --dir .workflow/scratch/quick-fix"
73
+ $maestro-execute --continue "20260318-execute-P3-phase3"
74
+ ```
75
+
76
+ **Flags**:
77
+ - `-y, --yes`: Skip all confirmations (auto mode)
78
+ - `-c, --concurrency N`: Max concurrent agents within each wave (default: 5)
79
+ - `--continue`: Resume existing session
80
+
81
+ **Inner flags** (passed inside quotes):
82
+ - `--auto-commit`: Atomic git commit after each task completion
83
+ - `--method agent|cli`: Override execution method (default: from config.json)
84
+ - `--dir <path>`: Use arbitrary directory instead of phase resolution (scratch mode)
85
+
86
+ When `--yes` or `-y`: Auto-confirm task breakdown, skip blocked-task prompts, auto-continue through all waves.
87
+
88
+ **Output Directory**: `.workflow/.csv-wave/{session-id}/`
89
+ **Core Output**: `tasks.csv` (master state) + `results.csv` (final) + `discoveries.ndjson` (shared exploration) + `context.md` (human-readable report)
90
+ </context>
91
+
92
+ <csv_schema>
93
+
94
+ ### tasks.csv (Master State)
95
+
96
+ ```csv
97
+ id,title,description,scope,convergence_criteria,hints,execution_directives,deps,context_from,wave,status,findings,files_modified,tests_passed,error
98
+ "TASK-001","Setup auth module","Create authentication module with JWT token generation and verification. Export verifyToken and generateToken functions.","src/auth/","auth.ts contains export function verifyToken(; auth.ts contains export function generateToken(","Reference existing middleware pattern in src/middleware/auth.ts","npm test -- --grep auth","","","1","","","","",""
99
+ "TASK-002","Create user model","Define User interface and database schema with email, passwordHash, role fields. Use existing Result type pattern.","src/models/","user.ts contains export interface User; user.ts contains email: string","See src/models/session.ts for existing model pattern","npm test -- --grep user","","","1","","","","",""
100
+ "TASK-003","Auth middleware","Create Express middleware that validates JWT from Authorization header. Use verifyToken from auth module. Return 401 on invalid token.","src/middleware/","auth-middleware.ts contains export function authMiddleware(; auth-middleware.ts contains verifyToken","Follows existing middleware pattern in src/middleware/logging.ts","npm test -- --grep middleware","TASK-001","TASK-001","2","","","","",""
101
+ "TASK-004","Login endpoint","Implement POST /api/login endpoint. Validate credentials against user model, return JWT on success. Use generateToken from auth module.","src/routes/","login.ts contains router.post('/api/login'; login.ts contains generateToken(","Wire into existing Express app in src/app.ts","curl -X POST localhost:3000/api/login","TASK-001;TASK-002","TASK-001;TASK-002","2","","","","",""
102
+ "TASK-005","Integration tests","Write integration tests for full auth flow: register, login, access protected route, token refresh.","tests/","tests/auth.test.ts exists; npm test exits with code 0","Use existing test setup in tests/setup.ts","npm test","TASK-003;TASK-004","TASK-003;TASK-004","3","","","","",""
103
+ ```
104
+
105
+ **Columns**:
106
+
107
+ | Column | Phase | Description |
108
+ |--------|-------|-------------|
109
+ | `id` | Input | Task ID (TASK-NNN format, from plan.json) |
110
+ | `title` | Input | Short task title from task definition |
111
+ | `description` | Input | Full task description from TASK-*.json |
112
+ | `scope` | Input | Target file/directory glob from task.files |
113
+ | `convergence_criteria` | Input | Grep-verifiable completion criteria (semicolon-separated) |
114
+ | `hints` | Input | Implementation hints + reference files from task definition |
115
+ | `execution_directives` | Input | Verification commands to run after implementation |
116
+ | `deps` | Input | Semicolon-separated dependency task IDs |
117
+ | `context_from` | Input | Semicolon-separated task IDs whose findings this task needs |
118
+ | `wave` | Computed | Wave number from plan.json wave assignment |
119
+ | `status` | Output | `pending` -> `completed` / `failed` / `blocked` / `skipped` |
120
+ | `findings` | Output | Implementation notes and observations (max 500 chars) |
121
+ | `files_modified` | Output | Semicolon-separated list of created/modified files |
122
+ | `tests_passed` | Output | Test pass/fail status from execution_directives |
123
+ | `error` | Output | Error message if failed or blocked |
124
+
125
+ ### Per-Wave CSV (Temporary)
126
+
127
+ Each wave generates `wave-{N}.csv` with extra `prev_context` column populated from predecessor task findings.
128
+
129
+ ### Output Artifacts
130
+
131
+ | File | Purpose | Lifecycle |
132
+ |------|---------|-----------|
133
+ | `tasks.csv` | Master state -- all tasks with status/findings | Updated after each wave |
134
+ | `wave-{N}.csv` | Per-wave input (temporary) | Created before wave, deleted after |
135
+ | `wave-{N}-results.csv` | Per-wave output | Created by spawn_agents_on_csv |
136
+ | `results.csv` | Final export of all task results | Created in Phase 3 |
137
+ | `discoveries.ndjson` | Shared exploration board | Append-only, carries across waves |
138
+ | `context.md` | Human-readable execution report | Created in Phase 3 |
139
+
140
+ ### Session Structure
141
+
142
+ ```
143
+ .workflow/.csv-wave/{YYYYMMDD}-execute-P{N}-{slug}/
144
+ +-- tasks.csv
145
+ +-- results.csv
146
+ +-- discoveries.ndjson
147
+ +-- context.md
148
+ +-- config.json
149
+ +-- wave-{N}.csv (temporary)
150
+ +-- wave-{N}-results.csv (temporary)
151
+ ```
152
+ </csv_schema>
153
+
154
+ <invariants>
155
+ 1. **Start Immediately**: First action is session initialization, then Phase 1
156
+ 2. **Wave Order is Sacred**: Never execute wave N+1 before wave N completes and results are merged
157
+ 3. **CSV is Source of Truth**: Master tasks.csv holds all execution state
158
+ 4. **Context Propagation**: prev_context built from master CSV findings, not from memory
159
+ 5. **Discovery Board is Append-Only**: Never clear, modify, or recreate discoveries.ndjson
160
+ 6. **Cascading Skip on Failure**: If a task fails/blocks, all dependent tasks are skipped
161
+ 7. **Cleanup Temp Files**: Remove wave-{N}.csv after results are merged
162
+ 8. **Max 3 Fix Attempts**: Per task, auto-fix convergence failures up to 3 times, then mark blocked
163
+ 9. **Breakpoint Resume**: Always detect completed tasks and skip them on re-run
164
+ 10. **DO NOT STOP**: Continuous execution until all waves complete or user explicitly stops
165
+ </invariants>
166
+
167
+ <execution>
168
+
169
+ ### Session Initialization
170
+
171
+ ```
172
+ Parse from $ARGUMENTS:
173
+ AUTO_YES--yes | -y
174
+ continueMode --continue
175
+ maxConcurrency--concurrency | -c N (default: 5)
176
+ autoCommit ← --auto-commit
177
+ executionMethod --method agent|cli (default: from config.json)
178
+ scratchDir ← --dir <path> (default: null)
179
+ phaseArg ← remaining text after flag removal
180
+
181
+ Derive:
182
+ dateStr ← UTC+8 YYYYMMDD
183
+ sessionId ← scratchDir ? "{dateStr}-execute-scratch" : "{dateStr}-execute-P{phaseArg}-{phaseSlug}"
184
+ sessionFolder ← ".workflow/.csv-wave/{sessionId}"
185
+
186
+ mkdir -p {sessionFolder}
187
+ ```
188
+
189
+ ### Pre-flight: Team Conflict Check
190
+
191
+ Before any task execution, run:
192
+ ```
193
+ Bash("maestro collab preflight --phase <phase-number>")
194
+ ```
195
+ If exit code is 1, present warnings and ask whether to proceed.
196
+
197
+ ### Phase 1: Plan Resolution -> CSV
198
+
199
+ **Objective**: Resolve phase, load plan + task definitions, detect resume point, generate tasks.csv.
200
+
201
+ **Decomposition Rules**:
202
+
203
+ 1. **Plan resolution** (per scratch-milestone-architecture):
204
+
205
+ | Input | Resolution |
206
+ |-------|------------|
207
+ | `--dir <path>` | Use path directly (scratch plan dir) |
208
+ | No args | Find all pending plans for current milestone from state.json.artifacts[] |
209
+ | Number (e.g., `3`) | Find pending plans for phase N from state.json.artifacts[] |
210
+
211
+ For multi-plan: execute sequentially. Each plan is a full CSV session.
212
+
213
+ 2. **Load plan**: Read `{PLAN_DIR}/plan.json` for wave structure and task assignments
214
+
215
+ 3. **Detect completed tasks (breakpoint resume)**: Read `.task/TASK-{NNN}.json` for each task; exclude completed ones from CSV. Log resume count.
216
+
217
+ 4. **Build tasks.csv**: For each pending task per wave, read `.task/TASK-{NNN}.json` and extract: title, description, scope (from files), convergence.criteria, hints, execution_directives. Set `deps` from task dependency, `context_from` = deps, `wave` from plan.json.
218
+
219
+ 5. **Load project specs + tools**: Run `maestro spec load --category coding` to load coding conventions, architecture constraints, AND discoverable knowhow tools (passed to all agents)
220
+
221
+ 6. **Load UI specs (conditional)**: If any task involves frontend/UI work (task scope/description contains component, page, style, layout, CSS, HTML, frontend; or focus_paths in `src/components/`, `src/pages/`, `src/styles/`, `src/ui/`), also run `maestro spec load --category ui` and include in agent context.
222
+
223
+ 7. **Load codebase + wiki context** (optional, passed to all agents):
224
+ - If `.workflow/codebase/ARCHITECTURE.md` exists: read and include as `codebase_context` in agent instructions
225
+ - Run `maestro wiki search "<phase keywords>" --json 2>/dev/null`; if results: include top 5 entries as `wiki_context`
226
+ - Both are optional — proceed without if unavailable
227
+
228
+ 7. **User validation**: Display task/wave breakdown. Skip if AUTO_YES.
229
+
230
+ 8. **TDD plan detection**: If `plan.json.tdd_mode == true`, enable TDD execution enforcement:
231
+ - RED tasks (meta.tdd_phase=red): after completion, verify test exists AND fails. If test passes mark BLOCKED "Test passes before implementation — wrong test".
232
+ - GREEN tasks (meta.tdd_phase=green): after completion, verify ALL tests pass. If RED test still fails → mark BLOCKED.
233
+ - REFACTOR tasks (meta.tdd_phase=refactor): after completion, verify ALL tests still pass. If any fails → undo, mark BLOCKED.
234
+
235
+ ### Phase 2: Wave Execution Engine
236
+
237
+ **Objective**: Execute tasks wave-by-wave via spawn_agents_on_csv with cross-wave context propagation.
238
+
239
+ #### Per-Wave Execution Loop
240
+
241
+ For each wave N in ascending order:
242
+
243
+ 1. Extract wave N pending rows from master `tasks.csv` (skip wave if none)
244
+ 2. Build `prev_context` per task from completed predecessor findings
245
+ 3. Write `wave-{N}.csv` with `prev_context` column, then execute:
246
+
247
+ ```javascript
248
+ spawn_agents_on_csv({
249
+ csv_path: `${sessionFolder}/wave-${N}.csv`,
250
+ id_column: "id",
251
+ instruction: buildExecutorInstruction(sessionFolder, phaseDir, autoCommit, specsContent), // agent: ~/.codex/agents/workflow-executor.toml
252
+ max_concurrency: maxConcurrency, max_runtime_seconds: 3600,
253
+ output_csv_path: `${sessionFolder}/wave-${N}-results.csv`,
254
+ output_schema: { id, status: [completed|failed|blocked], findings, files_modified, tests_passed, error }
255
+ })
256
+ ```
257
+
258
+ 4. Merge results into master `tasks.csv`, delete `wave-{N}.csv`
259
+
260
+ #### Blocked Task Handling
261
+
262
+ After each wave: if blocked tasks exist, prompt user to continue or stop (AUTO_YES: auto-continue). Skip tasks whose deps are blocked/failed.
263
+
264
+ #### Cascading Skip
265
+
266
+ Blocked/failed tasks cascade: mark all downstream dependents as `skipped` with error "Dependency {dep_id} blocked/failed".
267
+
268
+ ### Phase 3: Results Aggregation
269
+
270
+ **Objective**: Update all state files and generate execution report.
271
+
272
+ 1. Export final `tasks.csv` as `results.csv`
273
+
274
+ 2. **Update task files**: Write each task's status from CSV back to `.task/{id}.json`
275
+
276
+ 3. **Issue status sync**: For tasks with `issue_id`, update `.workflow/issues/issues.jsonl`:
277
+ - All task_refs completed -> `issue.status = "resolved"`; any failed -> `"in_progress"`
278
+ - Append history entry: `{ action: "executed", at: <ISO>, by: "maestro-execute", summary: "TASK-{NNN} {status}" }`
279
+
280
+ 4. **Register EXC artifact in state.json**: Find matching plan artifact, create `{ id: "EXC-{next_id}", type: "execute", milestone, phase, scope, path, status: "completed", depends_on: plan_artifact.id, harvested: false, created_at, completed_at }`
281
+
282
+ 5. **Extract incremental specs**: Read `.summaries/`, use `maestro spec add` CLI:
283
+ - Learnings/pitfalls → `maestro spec add learning "<title>" "<content>" --keywords ... --source execute:{PLAN_DIR}`
284
+ - Design rationale `maestro spec add coding "<title>" "<content>" --keywords ...`
285
+ - Root cause/workaround `maestro spec add debug "<title>" "<content>" --keywords ...`
286
+ Mark artifact `harvested: true`
287
+
288
+ 6. **Post-task Knowledge Inquiry**: After each task completes, evaluate inquiry triggers:
289
+
290
+ - **Execution deviation**: If task summary mentions approach change, dependency swap, or plan deviation:
291
+ → Prompt: "TASK-{NNN} deviated from the plan. Record as architecture constraint?"
292
+ → On confirm: `maestro spec add arch "<decision>" "<rationale>" --keywords ... --source execute:{PLAN_DIR}`
293
+
294
+ - **Retry success**: If task required >=2 retries before completion:
295
+ Prompt: "TASK-{NNN} succeeded after {N} retries. Document this fix pattern?"
296
+ → On confirm: `maestro spec add debug "<pattern>" "<content>" --keywords ... --source execute:{PLAN_DIR}`
297
+
298
+ - **Implicit knowledge**: If task summary contains design rationale ("chose X because", "rejected Y due to"):
299
+ Prompt: "Design decision detected. Record as a learning?"
300
+ → On confirm: `maestro spec add learning "<decision>" "<rationale>" --keywords ... --source execute:{PLAN_DIR}`
301
+
302
+ Use `request_user_input` for prompts:
303
+ ```json
304
+ { "questions": [{ "id": "knowledge-capture", "header": "Knowledge Capture", "question": "...", "options": [{ "label": "Yes", "description": "Record to specs" }, { "label": "Skip", "description": "Continue without recording" }] }] }
305
+ ```
306
+
307
+ 7. **Generate context.md**: Execution report with summary (tasks/blocked/waves/auto-commit), per-wave result table (task, status, files, tests), blocked tasks, discovery board summary, next steps.
308
+
309
+ 8. **Auto-sync** (if config.json.codebase.auto_sync_after_execute == true): detect changed files, trigger codebase doc update.
310
+
311
+ 9. **Display completion report**: Phase, completed/blocked counts, wave progress, paths to `.summaries/` and `.task/`, next step suggestions (`maestro-verify`, `manage-status`).
312
+
313
+ ### Shared Discovery Board Protocol
314
+
315
+ #### Standard Discovery Types
316
+
317
+ | Type | Dedup Key | Data Schema | Description |
318
+ |------|-----------|-------------|-------------|
319
+ | `code_pattern` | `data.name` | `{name, file, description}` | Reusable code pattern found during implementation |
320
+ | `integration_point` | `data.file` | `{file, description, exports[]}` | Module connection point discovered |
321
+ | `convention` | singleton | `{naming, imports, formatting}` | Project coding conventions observed |
322
+ | `blocker` | `data.issue` | `{issue, severity, impact}` | Blocking issue encountered |
323
+ | `tech_stack` | singleton | `{framework, language, tools[]}` | Technology stack detail confirmed |
324
+ | `test_command` | `data.command` | `{command, scope, result}` | Working test command discovered |
325
+
326
+ #### Protocol
327
+
328
+ Read `discoveries.ndjson` before implementation. Append-only: dedup by type+key before writing, never modify/delete.
329
+
330
+ ```bash
331
+ echo '{"ts":"<ISO>","worker":"TASK-001","type":"code_pattern","data":{"name":"Result type","file":"src/types/result.ts","description":"All functions return Result<T,E> for error handling"}}' >> {session_folder}/discoveries.ndjson
332
+ ```
333
+ </execution>
334
+
335
+ <error_codes>
336
+
337
+ | Error | Resolution |
338
+ |-------|------------|
339
+ | Phase directory not found | Abort with error: "Phase {N} not found" |
340
+ | plan.json not found | Abort with error: "No plan found -- run plan first" |
341
+ | No pending tasks (all completed) | Abort with info: "All tasks already completed" |
342
+ | Task file (.task/TASK-*.json) missing | Skip task, log error, mark as failed |
343
+ | Agent spawn fails | Retry once, then mark task as blocked with checkpoint |
344
+ | Convergence criteria not met after 3 attempts | Mark task as blocked, write checkpoint |
345
+ | Git commit fails (--auto-commit) | Log warning, continue (task still marked completed) |
346
+ | All tasks in wave blocked | Stop execution, report blocked wave |
347
+ | CSV parse error | Validate format, show line number |
348
+ | discoveries.ndjson corrupt | Ignore malformed lines, continue |
349
+ | Continue mode: no session found | List available sessions |
350
+ </error_codes>
351
+
352
+ <success_criteria>
353
+ - [ ] Session folder created with valid tasks.csv
354
+ - [ ] All waves executed in order with cross-wave context propagation
355
+ - [ ] Completed tasks have .summaries/TASK-{NNN}-summary.md
356
+ - [ ] .task/TASK-*.json statuses updated to match execution results
357
+ - [ ] state.json updated with EXC artifact
358
+ - [ ] Issue status synced for tasks with issue_id (all completed → resolved, any failed → in_progress)
359
+ - [ ] Incremental specs extracted from summaries (learnings, design rationale, root causes)
360
+ - [ ] Post-task knowledge inquiry triggered when applicable (deviation, retry>=2, design rationale)
361
+ - [ ] context.md produced with execution report
362
+ - [ ] Blocked tasks have checkpoint info for resume
363
+ - [ ] Cascading skip applied for dependent tasks
364
+ - [ ] discoveries.ndjson append-only throughout
365
+ </success_criteria>