relay-cc 2.0.0

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +428 -0
  3. package/agents/relay-codebase-mapper.md +761 -0
  4. package/agents/relay-debugger.md +1203 -0
  5. package/agents/relay-estimator.md +257 -0
  6. package/agents/relay-executor.md +823 -0
  7. package/agents/relay-plan-checker.md +812 -0
  8. package/agents/relay-planner.md +1418 -0
  9. package/agents/relay-reviewer.md +279 -0
  10. package/agents/relay-ticket-researcher.md +287 -0
  11. package/agents/relay-verifier.md +778 -0
  12. package/bin/install.js +1667 -0
  13. package/commands/relay/add-todo.md +193 -0
  14. package/commands/relay/check-todos.md +200 -0
  15. package/commands/relay/debug.md +169 -0
  16. package/commands/relay/estimate.md +182 -0
  17. package/commands/relay/help.md +328 -0
  18. package/commands/relay/history.md +203 -0
  19. package/commands/relay/map-codebase.md +71 -0
  20. package/commands/relay/pause-work.md +128 -0
  21. package/commands/relay/pr.md +223 -0
  22. package/commands/relay/quick.md +307 -0
  23. package/commands/relay/resume-work.md +40 -0
  24. package/commands/relay/resume.md +181 -0
  25. package/commands/relay/review.md +322 -0
  26. package/commands/relay/rollback.md +248 -0
  27. package/commands/relay/set-profile.md +116 -0
  28. package/commands/relay/settings.md +165 -0
  29. package/commands/relay/setup.md +247 -0
  30. package/commands/relay/status.md +131 -0
  31. package/commands/relay/tickets.md +106 -0
  32. package/commands/relay/update.md +200 -0
  33. package/commands/relay/work.md +398 -0
  34. package/hooks/dist/relay-check-update.js +61 -0
  35. package/hooks/dist/relay-statusline.js +91 -0
  36. package/package.json +47 -0
  37. package/relay/references/checkpoints.md +1078 -0
  38. package/relay/references/continuation-format.md +249 -0
  39. package/relay/references/git-integration.md +209 -0
  40. package/relay/references/model-profiles.md +57 -0
  41. package/relay/references/planning-config.md +189 -0
  42. package/relay/references/questioning.md +141 -0
  43. package/relay/references/tdd.md +263 -0
  44. package/relay/references/ui-brand.md +162 -0
  45. package/relay/references/verification-patterns.md +612 -0
  46. package/relay/templates/DEBUG.md +159 -0
  47. package/relay/templates/UAT.md +247 -0
  48. package/relay/templates/analysis.md +101 -0
  49. package/relay/templates/codebase/architecture.md +255 -0
  50. package/relay/templates/codebase/concerns.md +310 -0
  51. package/relay/templates/codebase/conventions.md +307 -0
  52. package/relay/templates/codebase/integrations.md +280 -0
  53. package/relay/templates/codebase/stack.md +186 -0
  54. package/relay/templates/codebase/structure.md +285 -0
  55. package/relay/templates/codebase/testing.md +480 -0
  56. package/relay/templates/config.json +40 -0
  57. package/relay/templates/context.md +283 -0
  58. package/relay/templates/continue-here.md +78 -0
  59. package/relay/templates/debug-subagent-prompt.md +91 -0
  60. package/relay/templates/estimate.md +108 -0
  61. package/relay/templates/phase-prompt.md +567 -0
  62. package/relay/templates/planner-subagent-prompt.md +117 -0
  63. package/relay/templates/research.md +552 -0
  64. package/relay/templates/state.md +127 -0
  65. package/relay/templates/summary.md +246 -0
  66. package/relay/templates/verification-report.md +322 -0
  67. package/relay/workflows/analyze-ticket.md +42 -0
  68. package/relay/workflows/diagnose-issues.md +231 -0
  69. package/relay/workflows/execute-phase.md +700 -0
  70. package/relay/workflows/execute-plan.md +1851 -0
  71. package/relay/workflows/map-codebase.md +357 -0
  72. package/relay/workflows/resume-project.md +307 -0
  73. package/relay/workflows/sync-ticket.md +58 -0
  74. package/relay/workflows/verify-phase.md +628 -0
  75. package/relay/workflows/verify-ticket.md +596 -0
  76. package/scripts/build-hooks.js +42 -0
@@ -0,0 +1,700 @@
1
+ <purpose>
2
+ Execute all plans in a phase using wave-based parallel execution. Orchestrator stays lean by delegating plan execution to subagents.
3
+ </purpose>
4
+
5
+ <core_principle>
6
+ The orchestrator's job is coordination, not execution. Each subagent loads the full execute-plan context itself. Orchestrator discovers plans, analyzes dependencies, groups into waves, spawns agents, handles checkpoints, collects results.
7
+ </core_principle>
8
+
9
+ <required_reading>
10
+ Read STATE.md before any operation to load project context.
11
+ Read config.json for planning behavior settings.
12
+ </required_reading>
13
+
14
+ <process>
15
+
16
+ <step name="resolve_model_profile" priority="first">
17
+ Read model profile for agent spawning:
18
+
19
+ ```bash
20
+ MODEL_PROFILE=$(cat .relay/config.json 2>/dev/null | grep -o '"model_profile"[[:space:]]*:[[:space:]]*"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"' || echo "balanced")
21
+ ```
22
+
23
+ Default to "balanced" if not set.
24
+
25
+ **Model lookup table:**
26
+
27
+ | Agent | quality | balanced | budget |
28
+ |-------|---------|----------|--------|
29
+ | relay-executor | opus | sonnet | sonnet |
30
+ | relay-verifier | sonnet | sonnet | haiku |
31
+ | general-purpose | — | — | — |
32
+
33
+ Store resolved models for use in Task calls below.
34
+ </step>
35
+
36
+ <step name="load_project_state">
37
+ Before any operation, read project state:
38
+
39
+ ```bash
40
+ cat .relay/STATE.md 2>/dev/null
41
+ ```
42
+
43
+ **If file exists:** Parse and internalize:
44
+ - Current position (phase, plan, status)
45
+ - Accumulated decisions (constraints on this execution)
46
+ - Blockers/concerns (things to watch for)
47
+
48
+ **If file missing but .relay/ exists:**
49
+ ```
50
+ STATE.md missing but planning artifacts exist.
51
+ Options:
52
+ 1. Reconstruct from existing artifacts
53
+ 2. Continue without project state (may lose accumulated context)
54
+ ```
55
+
56
+ **If .relay/ doesn't exist:** Error - project not initialized.
57
+
58
+ **Load planning config:**
59
+
60
+ ```bash
61
+ # Check if planning docs should be committed (default: true)
62
+ COMMIT_PLANNING_DOCS=$(cat .relay/config.json 2>/dev/null | grep -o '"commit_docs"[[:space:]]*:[[:space:]]*[^,}]*' | grep -o 'true\|false' || echo "true")
63
+ # Auto-detect gitignored (overrides config)
64
+ git check-ignore -q .relay 2>/dev/null && COMMIT_PLANNING_DOCS=false
65
+ ```
66
+
67
+ Store `COMMIT_PLANNING_DOCS` for use in git operations.
68
+
69
+ **Load parallelization config:**
70
+
71
+ ```bash
72
+ # Check if parallelization is enabled (default: true)
73
+ PARALLELIZATION=$(cat .relay/config.json 2>/dev/null | grep -o '"parallelization"[[:space:]]*:[[:space:]]*[^,}]*' | grep -o 'true\|false' || echo "true")
74
+ ```
75
+
76
+ Store `PARALLELIZATION` for use in wave execution step. When `false`, plans within a wave execute sequentially instead of in parallel.
77
+
78
+ **Load git branching config:**
79
+
80
+ ```bash
81
+ # Get branching strategy (default: none)
82
+ BRANCHING_STRATEGY=$(cat .relay/config.json 2>/dev/null | grep -o '"branching_strategy"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*:.*"\([^"]*\)"/\1/' || echo "none")
83
+
84
+ # Get templates
85
+ PHASE_BRANCH_TEMPLATE=$(cat .relay/config.json 2>/dev/null | grep -o '"phase_branch_template"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*:.*"\([^"]*\)"/\1/' || echo "relay/phase-{phase}-{slug}")
86
+ MILESTONE_BRANCH_TEMPLATE=$(cat .relay/config.json 2>/dev/null | grep -o '"milestone_branch_template"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*:.*"\([^"]*\)"/\1/' || echo "relay/{milestone}-{slug}")
87
+ ```
88
+
89
+ Store `BRANCHING_STRATEGY` and templates for use in branch creation step.
90
+ </step>
91
+
92
+ <step name="handle_branching">
93
+ Create or switch to appropriate branch based on branching strategy.
94
+
95
+ **Skip if strategy is "none":**
96
+
97
+ ```bash
98
+ if [ "$BRANCHING_STRATEGY" = "none" ]; then
99
+ # No branching, continue on current branch
100
+ exit 0
101
+ fi
102
+ ```
103
+
104
+ **For "phase" strategy — create phase branch:**
105
+
106
+ ```bash
107
+ if [ "$BRANCHING_STRATEGY" = "phase" ]; then
108
+ # Get phase name from directory (e.g., "03-authentication" → "authentication")
109
+ PHASE_NAME=$(basename "$PHASE_DIR" | sed 's/^[0-9]*-//')
110
+
111
+ # Create slug from phase name
112
+ PHASE_SLUG=$(echo "$PHASE_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
113
+
114
+ # Apply template
115
+ BRANCH_NAME=$(echo "$PHASE_BRANCH_TEMPLATE" | sed "s/{phase}/$PADDED_PHASE/g" | sed "s/{slug}/$PHASE_SLUG/g")
116
+
117
+ # Create or switch to branch
118
+ git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
119
+
120
+ echo "Branch: $BRANCH_NAME (phase branching)"
121
+ fi
122
+ ```
123
+
124
+ **For "milestone" strategy — create/switch to milestone branch:**
125
+
126
+ ```bash
127
+ if [ "$BRANCHING_STRATEGY" = "milestone" ]; then
128
+ # Get current milestone info from ROADMAP.md
129
+ MILESTONE_VERSION=$(grep -oE 'v[0-9]+\.[0-9]+' .relay/ROADMAP.md | head -1 || echo "v1.0")
130
+ MILESTONE_NAME=$(grep -A1 "## .*$MILESTONE_VERSION" .relay/ROADMAP.md | tail -1 | sed 's/.*- //' | cut -d'(' -f1 | tr -d ' ' || echo "milestone")
131
+
132
+ # Create slug
133
+ MILESTONE_SLUG=$(echo "$MILESTONE_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
134
+
135
+ # Apply template
136
+ BRANCH_NAME=$(echo "$MILESTONE_BRANCH_TEMPLATE" | sed "s/{milestone}/$MILESTONE_VERSION/g" | sed "s/{slug}/$MILESTONE_SLUG/g")
137
+
138
+ # Create or switch to branch (same branch for all phases in milestone)
139
+ git checkout -b "$BRANCH_NAME" 2>/dev/null || git checkout "$BRANCH_NAME"
140
+
141
+ echo "Branch: $BRANCH_NAME (milestone branching)"
142
+ fi
143
+ ```
144
+
145
+ **Report branch status:**
146
+
147
+ ```
148
+ Branching: {strategy} → {branch_name}
149
+ ```
150
+
151
+ **Note:** All subsequent plan commits go to this branch. User handles merging based on their workflow.
152
+ </step>
153
+
154
+ <step name="validate_phase">
155
+ Confirm phase exists and has plans:
156
+
157
+ ```bash
158
+ # Match both zero-padded (05-*) and unpadded (5-*) folders
159
+ PADDED_PHASE=$(printf "%02d" ${PHASE_ARG} 2>/dev/null || echo "${PHASE_ARG}")
160
+ PHASE_DIR=$(ls -d .relay/tickets/${PADDED_PHASE}-* .relay/tickets/${PHASE_ARG}-* 2>/dev/null | head -1)
161
+ if [ -z "$PHASE_DIR" ]; then
162
+ echo "ERROR: No phase directory matching '${PHASE_ARG}'"
163
+ exit 1
164
+ fi
165
+
166
+ PLAN_COUNT=$(ls -1 "$PHASE_DIR"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
167
+ if [ "$PLAN_COUNT" -eq 0 ]; then
168
+ echo "ERROR: No plans found in $PHASE_DIR"
169
+ exit 1
170
+ fi
171
+ ```
172
+
173
+ Report: "Found {N} plans in {phase_dir}"
174
+ </step>
175
+
176
+ <step name="discover_plans">
177
+ List all plans and extract metadata:
178
+
179
+ ```bash
180
+ # Get all plans
181
+ ls -1 "$PHASE_DIR"/*-PLAN.md 2>/dev/null | sort
182
+
183
+ # Get completed plans (have SUMMARY.md)
184
+ ls -1 "$PHASE_DIR"/*-SUMMARY.md 2>/dev/null | sort
185
+ ```
186
+
187
+ For each plan, read frontmatter to extract:
188
+ - `wave: N` - Execution wave (pre-computed)
189
+ - `autonomous: true/false` - Whether plan has checkpoints
190
+ - `gap_closure: true/false` - Whether plan closes gaps from verification/UAT
191
+
192
+ Build plan inventory:
193
+ - Plan path
194
+ - Plan ID (e.g., "03-01")
195
+ - Wave number
196
+ - Autonomous flag
197
+ - Gap closure flag
198
+ - Completion status (SUMMARY exists = complete)
199
+
200
+ **Filtering:**
201
+ - Skip completed plans (have SUMMARY.md)
202
+ - If `--gaps-only` flag: also skip plans where `gap_closure` is not `true`
203
+
204
+ If all plans filtered out, report "No matching incomplete plans" and exit.
205
+ </step>
206
+
207
+ <step name="group_by_wave">
208
+ Read `wave` from each plan's frontmatter and group by wave number:
209
+
210
+ ```bash
211
+ # For each plan, extract wave from frontmatter
212
+ for plan in $PHASE_DIR/*-PLAN.md; do
213
+ wave=$(grep "^wave:" "$plan" | cut -d: -f2 | tr -d ' ')
214
+ autonomous=$(grep "^autonomous:" "$plan" | cut -d: -f2 | tr -d ' ')
215
+ echo "$plan:$wave:$autonomous"
216
+ done
217
+ ```
218
+
219
+ **Group plans:**
220
+ ```
221
+ waves = {
222
+ 1: [plan-01, plan-02],
223
+ 2: [plan-03, plan-04],
224
+ 3: [plan-05]
225
+ }
226
+ ```
227
+
228
+ **No dependency analysis needed.** Wave numbers are pre-computed during `/relay:plan-phase`.
229
+
230
+ Report wave structure with context:
231
+ ```
232
+ ## Execution Plan
233
+
234
+ **Phase {X}: {Name}** — {total_plans} plans across {wave_count} waves
235
+
236
+ | Wave | Plans | What it builds |
237
+ |------|-------|----------------|
238
+ | 1 | 01-01, 01-02 | {from plan objectives} |
239
+ | 2 | 01-03 | {from plan objectives} |
240
+ | 3 | 01-04 [checkpoint] | {from plan objectives} |
241
+
242
+ ```
243
+
244
+ The "What it builds" column comes from skimming plan names/objectives. Keep it brief (3-8 words).
245
+ </step>
246
+
247
+ <step name="execute_waves">
248
+ Execute each wave in sequence. Autonomous plans within a wave run in parallel **only if `PARALLELIZATION=true`**.
249
+
250
+ **If `PARALLELIZATION=false`:** Execute plans within each wave sequentially (one at a time). This prevents side effects from concurrent operations like tests, linting, and code generation.
251
+
252
+ **For each wave:**
253
+
254
+ 1. **Describe what's being built (BEFORE spawning):**
255
+
256
+ Read each plan's `<objective>` section. Extract what's being built and why it matters.
257
+
258
+ **Output:**
259
+ ```
260
+ ---
261
+
262
+ ## Wave {N}
263
+
264
+ **{Plan ID}: {Plan Name}**
265
+ {2-3 sentences: what this builds, key technical approach, why it matters in context}
266
+
267
+ **{Plan ID}: {Plan Name}** (if parallel)
268
+ {same format}
269
+
270
+ Spawning {count} agent(s)...
271
+
272
+ ---
273
+ ```
274
+
275
+ **Examples:**
276
+ - Bad: "Executing terrain generation plan"
277
+ - Good: "Procedural terrain generator using Perlin noise — creates height maps, biome zones, and collision meshes. Required before vehicle physics can interact with ground."
278
+
279
+ 2. **Read files and spawn agents:**
280
+
281
+ Before spawning, read file contents. The `@` syntax does not work across Task() boundaries - content must be inlined.
282
+
283
+ ```bash
284
+ # Read each plan in the wave
285
+ PLAN_CONTENT=$(cat "{plan_path}")
286
+ STATE_CONTENT=$(cat .relay/STATE.md)
287
+ CONFIG_CONTENT=$(cat .relay/config.json 2>/dev/null)
288
+ ```
289
+
290
+ **If `PARALLELIZATION=true` (default):** Use Task tool with multiple parallel calls.
291
+
292
+ **If `PARALLELIZATION=false`:** Spawn agents one at a time, waiting for each to complete before starting the next. This ensures no concurrent file modifications or build operations.
293
+
294
+ Each agent gets prompt with inlined content:
295
+
296
+ ```
297
+ <objective>
298
+ Execute plan {plan_number} of phase {phase_number}-{phase_name}.
299
+
300
+ Commit each task atomically. Create SUMMARY.md. Update STATE.md.
301
+ </objective>
302
+
303
+ <execution_context>
304
+ @~/.claude/relay/workflows/execute-plan.md
305
+ @~/.claude/relay/templates/summary.md
306
+ @~/.claude/relay/references/checkpoints.md
307
+ @~/.claude/relay/references/tdd.md
308
+ </execution_context>
309
+
310
+ <context>
311
+ Plan:
312
+ {plan_content}
313
+
314
+ Project state:
315
+ {state_content}
316
+
317
+ Config (if exists):
318
+ {config_content}
319
+ </context>
320
+
321
+ <success_criteria>
322
+ - [ ] All tasks executed
323
+ - [ ] Each task committed individually
324
+ - [ ] SUMMARY.md created in plan directory
325
+ - [ ] STATE.md updated with position and decisions
326
+ </success_criteria>
327
+ ```
328
+
329
+ 2. **Wait for all agents in wave to complete:**
330
+
331
+ Task tool blocks until each agent finishes. All parallel agents return together.
332
+
333
+ 3. **Report completion and what was built:**
334
+
335
+ For each completed agent:
336
+ - Verify SUMMARY.md exists at expected path
337
+ - Read SUMMARY.md to extract what was built
338
+ - Note any issues or deviations
339
+
340
+ **Spot-check claims before trusting SUMMARY:**
341
+
342
+ For each completed plan's SUMMARY.md:
343
+ - Pick the first 2 files from `key-files.created` frontmatter — verify they exist on disk with `[ -f ]`
344
+ - Check `git log --oneline --all --grep="{phase}-{plan}"` returns at least 1 commit
345
+ - Check SUMMARY.md for `## Self-Check: FAILED` marker
346
+
347
+ If ANY spot-check fails:
348
+ - Do NOT proceed silently
349
+ - Report which plan failed verification and what was missing
350
+ - Route to failure handler (step 4): ask user "Retry plan?" or "Continue with remaining waves?"
351
+
352
+ If spot-checks pass: proceed normally.
353
+
354
+ **Output:**
355
+ ```
356
+ ---
357
+
358
+ ## Wave {N} Complete
359
+
360
+ **{Plan ID}: {Plan Name}**
361
+ {What was built — from SUMMARY.md deliverables}
362
+ {Notable deviations or discoveries, if any}
363
+
364
+ **{Plan ID}: {Plan Name}** (if parallel)
365
+ {same format}
366
+
367
+ {If more waves: brief note on what this enables for next wave}
368
+
369
+ ---
370
+ ```
371
+
372
+ **Examples:**
373
+ - Bad: "Wave 2 complete. Proceeding to Wave 3."
374
+ - Good: "Terrain system complete — 3 biome types, height-based texturing, physics collision meshes. Vehicle physics (Wave 3) can now reference ground surfaces."
375
+
376
+ 4. **Handle failures:**
377
+
378
+ If any agent in wave fails:
379
+ - Report which plan failed and why
380
+ - Ask user: "Continue with remaining waves?" or "Stop execution?"
381
+ - If continue: proceed to next wave (dependent plans may also fail)
382
+ - If stop: exit with partial completion report
383
+
384
+ 5. **Execute checkpoint plans between waves:**
385
+
386
+ See `<checkpoint_handling>` for details.
387
+
388
+ 6. **Proceed to next wave**
389
+
390
+ </step>
391
+
392
+ <step name="checkpoint_handling">
393
+ Plans with `autonomous: false` require user interaction.
394
+
395
+ **Detection:** Check `autonomous` field in frontmatter.
396
+
397
+ **Execution flow for checkpoint plans:**
398
+
399
+ 1. **Spawn agent for checkpoint plan:**
400
+ ```
401
+ Task(prompt="{subagent-task-prompt}", subagent_type="relay-executor", model="{executor_model}")
402
+ ```
403
+
404
+ 2. **Agent runs until checkpoint:**
405
+ - Executes auto tasks normally
406
+ - Reaches checkpoint task (e.g., `type="checkpoint:human-verify"`) or auth gate
407
+ - Agent returns with structured checkpoint (see checkpoint-return.md template)
408
+
409
+ 3. **Agent return includes (structured format):**
410
+ - Completed Tasks table with commit hashes and files
411
+ - Current task name and blocker
412
+ - Checkpoint type and details for user
413
+ - What's awaited from user
414
+
415
+ 4. **Orchestrator presents checkpoint to user:**
416
+
417
+ Extract and display the "Checkpoint Details" and "Awaiting" sections from agent return:
418
+ ```
419
+ ## Checkpoint: [Type]
420
+
421
+ **Plan:** 03-03 Dashboard Layout
422
+ **Progress:** 2/3 tasks complete
423
+
424
+ [Checkpoint Details section from agent return]
425
+
426
+ [Awaiting section from agent return]
427
+ ```
428
+
429
+ 5. **User responds:**
430
+ - "approved" / "done" → spawn continuation agent
431
+ - Description of issues → spawn continuation agent with feedback
432
+ - Decision selection → spawn continuation agent with choice
433
+
434
+ 6. **Spawn continuation agent (NOT resume):**
435
+
436
+ Use the continuation-prompt.md template:
437
+ ```
438
+ Task(
439
+ prompt=filled_continuation_template,
440
+ subagent_type="relay-executor",
441
+ model="{executor_model}"
442
+ )
443
+ ```
444
+
445
+ Fill template with:
446
+ - `{completed_tasks_table}`: From agent's checkpoint return
447
+ - `{resume_task_number}`: Current task from checkpoint
448
+ - `{resume_task_name}`: Current task name from checkpoint
449
+ - `{user_response}`: What user provided
450
+ - `{resume_instructions}`: Based on checkpoint type (see continuation-prompt.md)
451
+
452
+ 7. **Continuation agent executes:**
453
+ - Verifies previous commits exist
454
+ - Continues from resume point
455
+ - May hit another checkpoint (repeat from step 4)
456
+ - Or completes plan
457
+
458
+ 8. **Repeat until plan completes or user stops**
459
+
460
+ **Why fresh agent instead of resume:**
461
+ Resume relies on Claude Code's internal serialization which breaks with parallel tool calls.
462
+ Fresh agents with explicit state are more reliable and maintain full context.
463
+
464
+ **Checkpoint in parallel context:**
465
+ If a plan in a parallel wave has a checkpoint:
466
+ - Spawn as normal
467
+ - Agent pauses at checkpoint and returns with structured state
468
+ - Other parallel agents may complete while waiting
469
+ - Present checkpoint to user
470
+ - Spawn continuation agent with user response
471
+ - Wait for all agents to finish before next wave
472
+ </step>
473
+
474
+ <step name="aggregate_results">
475
+ After all waves complete, aggregate results:
476
+
477
+ ```markdown
478
+ ## Phase {X}: {Name} Execution Complete
479
+
480
+ **Waves executed:** {N}
481
+ **Plans completed:** {M} of {total}
482
+
483
+ ### Wave Summary
484
+
485
+ | Wave | Plans | Status |
486
+ |------|-------|--------|
487
+ | 1 | plan-01, plan-02 | ✓ Complete |
488
+ | CP | plan-03 | ✓ Verified |
489
+ | 2 | plan-04 | ✓ Complete |
490
+ | 3 | plan-05 | ✓ Complete |
491
+
492
+ ### Plan Details
493
+
494
+ 1. **03-01**: [one-liner from SUMMARY.md]
495
+ 2. **03-02**: [one-liner from SUMMARY.md]
496
+ ...
497
+
498
+ ### Issues Encountered
499
+ [Aggregate from all SUMMARYs, or "None"]
500
+ ```
501
+ </step>
502
+
503
+ <step name="verify_phase_goal">
504
+ Verify phase achieved its GOAL, not just completed its TASKS.
505
+
506
+ **Spawn verifier:**
507
+
508
+ ```
509
+ Task(
510
+ prompt="Verify phase {phase_number} goal achievement.
511
+
512
+ Phase directory: {phase_dir}
513
+ Phase goal: {goal from ROADMAP.md}
514
+
515
+ Check must_haves against actual codebase. Create VERIFICATION.md.
516
+ Verify what actually exists in the code.",
517
+ subagent_type="relay-verifier",
518
+ model="{verifier_model}"
519
+ )
520
+ ```
521
+
522
+ **Read verification status:**
523
+
524
+ ```bash
525
+ grep "^status:" "$PHASE_DIR"/*-VERIFICATION.md | cut -d: -f2 | tr -d ' '
526
+ ```
527
+
528
+ **Route by status:**
529
+
530
+ | Status | Action |
531
+ |--------|--------|
532
+ | `passed` | Continue to update_roadmap |
533
+ | `human_needed` | Present items to user, get approval or feedback |
534
+ | `gaps_found` | Present gap summary, offer `/relay:plan-phase {phase} --gaps` |
535
+
536
+ **If passed:**
537
+
538
+ Phase goal verified. Proceed to update_roadmap.
539
+
540
+ **If human_needed:**
541
+
542
+ ```markdown
543
+ ## ✓ Phase {X}: {Name} — Human Verification Required
544
+
545
+ All automated checks passed. {N} items need human testing:
546
+
547
+ ### Human Verification Checklist
548
+
549
+ {Extract from VERIFICATION.md human_verification section}
550
+
551
+ ---
552
+
553
+ **After testing:**
554
+ - "approved" → continue to update_roadmap
555
+ - Report issues → will route to gap closure planning
556
+ ```
557
+
558
+ If user approves → continue to update_roadmap.
559
+ If user reports issues → treat as gaps_found.
560
+
561
+ **If gaps_found:**
562
+
563
+ Present gaps and offer next command:
564
+
565
+ ```markdown
566
+ ## ⚠ Phase {X}: {Name} — Gaps Found
567
+
568
+ **Score:** {N}/{M} must-haves verified
569
+ **Report:** {phase_dir}/{phase}-VERIFICATION.md
570
+
571
+ ### What's Missing
572
+
573
+ {Extract gap summaries from VERIFICATION.md gaps section}
574
+
575
+ ---
576
+
577
+ ## ▶ Next Up
578
+
579
+ **Plan gap closure** — create additional plans to complete the phase
580
+
581
+ `/relay:plan-phase {X} --gaps`
582
+
583
+ <sub>`/clear` first → fresh context window</sub>
584
+
585
+ ---
586
+
587
+ **Also available:**
588
+ - `cat {phase_dir}/{phase}-VERIFICATION.md` — see full report
589
+ - `/relay:verify-work {X}` — manual testing before planning
590
+ ```
591
+
592
+ User runs `/relay:plan-phase {X} --gaps` which:
593
+ 1. Reads VERIFICATION.md gaps
594
+ 2. Creates additional plans (04, 05, etc.) with `gap_closure: true` to close gaps
595
+ 3. User then runs `/relay:execute-phase {X} --gaps-only`
596
+ 4. Execute-phase runs only gap closure plans (04-05)
597
+ 5. Verifier runs again after new plans complete
598
+
599
+ User stays in control at each decision point.
600
+ </step>
601
+
602
+ <step name="update_roadmap">
603
+ Update ROADMAP.md to reflect phase completion:
604
+
605
+ ```bash
606
+ # Mark phase complete
607
+ # Update completion date
608
+ # Update status
609
+ ```
610
+
611
+ **Check planning config:**
612
+
613
+ If `COMMIT_PLANNING_DOCS=false` (set in load_project_state):
614
+ - Skip all git operations for .relay/ files
615
+ - Planning docs exist locally but are gitignored
616
+ - Log: "Skipping planning docs commit (commit_docs: false)"
617
+ - Proceed to offer_next step
618
+
619
+ If `COMMIT_PLANNING_DOCS=true` (default):
620
+ - Continue with git operations below
621
+
622
+ Commit phase completion (roadmap, state, verification):
623
+ ```bash
624
+ git add .relay/ROADMAP.md .relay/STATE.md .relay/tickets/{phase_dir}/*-VERIFICATION.md
625
+ git add .relay/REQUIREMENTS.md # if updated
626
+ git commit -m "docs(phase-{X}): complete phase execution"
627
+ ```
628
+ </step>
629
+
630
+ <step name="offer_next">
631
+ Present next steps based on milestone status:
632
+
633
+ **If more phases remain:**
634
+ ```
635
+ ## Next Up
636
+
637
+ **Phase {X+1}: {Name}** — {Goal}
638
+
639
+ `/relay:plan-phase {X+1}`
640
+
641
+ <sub>`/clear` first for fresh context</sub>
642
+ ```
643
+
644
+ **If milestone complete:**
645
+ ```
646
+ MILESTONE COMPLETE!
647
+
648
+ All {N} phases executed.
649
+
650
+ `/relay:complete-milestone`
651
+ ```
652
+ </step>
653
+
654
+ </process>
655
+
656
+ <context_efficiency>
657
+ Orchestrator: ~10-15% context (frontmatter, spawning, results).
658
+ Subagents: Fresh 200k each (full workflow + execution).
659
+ No polling (Task blocks). No context bleed.
660
+ </context_efficiency>
661
+
662
+ <failure_handling>
663
+ **Subagent fails mid-plan:**
664
+ - SUMMARY.md won't exist
665
+ - Orchestrator detects missing SUMMARY
666
+ - Reports failure, asks user how to proceed
667
+
668
+ **Dependency chain breaks:**
669
+ - Wave 1 plan fails
670
+ - Wave 2 plans depending on it will likely fail
671
+ - Orchestrator can still attempt them (user choice)
672
+ - Or skip dependent plans entirely
673
+
674
+ **All agents in wave fail:**
675
+ - Something systemic (git issues, permissions, etc.)
676
+ - Stop execution
677
+ - Report for manual investigation
678
+
679
+ **Checkpoint fails to resolve:**
680
+ - User can't approve or provides repeated issues
681
+ - Ask: "Skip this plan?" or "Abort phase execution?"
682
+ - Record partial progress in STATE.md
683
+ </failure_handling>
684
+
685
+ <resumption>
686
+ **Resuming interrupted execution:**
687
+
688
+ If phase execution was interrupted (context limit, user exit, error):
689
+
690
+ 1. Run `/relay:execute-phase {phase}` again
691
+ 2. discover_plans finds completed SUMMARYs
692
+ 3. Skips completed plans
693
+ 4. Resumes from first incomplete plan
694
+ 5. Continues wave-based execution
695
+
696
+ **STATE.md tracks:**
697
+ - Last completed plan
698
+ - Current wave
699
+ - Any pending checkpoints
700
+ </resumption>