mindsystem-cc 3.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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +501 -0
  3. package/agents/ms-codebase-mapper.md +739 -0
  4. package/agents/ms-debugger.md +1184 -0
  5. package/agents/ms-designer.md +414 -0
  6. package/agents/ms-executor.md +760 -0
  7. package/agents/ms-integration-checker.md +423 -0
  8. package/agents/ms-milestone-auditor.md +448 -0
  9. package/agents/ms-mock-generator.md +182 -0
  10. package/agents/ms-plan-checker.md +746 -0
  11. package/agents/ms-research-synthesizer.md +248 -0
  12. package/agents/ms-researcher.md +962 -0
  13. package/agents/ms-roadmapper.md +606 -0
  14. package/agents/ms-verifier.md +779 -0
  15. package/agents/ms-verify-fixer.md +124 -0
  16. package/bin/install.js +296 -0
  17. package/commands/ms/add-phase.md +207 -0
  18. package/commands/ms/add-todo.md +182 -0
  19. package/commands/ms/audit-milestone.md +318 -0
  20. package/commands/ms/check-phase.md +162 -0
  21. package/commands/ms/check-todos.md +217 -0
  22. package/commands/ms/complete-milestone.md +137 -0
  23. package/commands/ms/create-roadmap.md +273 -0
  24. package/commands/ms/debug.md +149 -0
  25. package/commands/ms/define-requirements.md +121 -0
  26. package/commands/ms/design-phase.md +341 -0
  27. package/commands/ms/discuss-milestone.md +48 -0
  28. package/commands/ms/discuss-phase.md +60 -0
  29. package/commands/ms/do-work.md +90 -0
  30. package/commands/ms/execute-phase.md +289 -0
  31. package/commands/ms/help.md +623 -0
  32. package/commands/ms/insert-phase.md +227 -0
  33. package/commands/ms/list-phase-assumptions.md +50 -0
  34. package/commands/ms/map-codebase.md +71 -0
  35. package/commands/ms/new-milestone.md +193 -0
  36. package/commands/ms/new-project.md +338 -0
  37. package/commands/ms/pause-work.md +123 -0
  38. package/commands/ms/plan-milestone-gaps.md +285 -0
  39. package/commands/ms/plan-phase.md +105 -0
  40. package/commands/ms/progress.md +370 -0
  41. package/commands/ms/remove-phase.md +338 -0
  42. package/commands/ms/research-phase.md +175 -0
  43. package/commands/ms/research-project.md +339 -0
  44. package/commands/ms/resume-work.md +40 -0
  45. package/commands/ms/review-design.md +484 -0
  46. package/commands/ms/simplify-flutter.md +193 -0
  47. package/commands/ms/update.md +159 -0
  48. package/commands/ms/verify-work.md +92 -0
  49. package/commands/ms/whats-new.md +124 -0
  50. package/mindsystem/references/checkpoints.md +788 -0
  51. package/mindsystem/references/continuation-format.md +255 -0
  52. package/mindsystem/references/debugging/debugging-mindset.md +11 -0
  53. package/mindsystem/references/debugging/hypothesis-testing.md +11 -0
  54. package/mindsystem/references/debugging/investigation-techniques.md +11 -0
  55. package/mindsystem/references/debugging/verification-patterns.md +11 -0
  56. package/mindsystem/references/debugging/when-to-research.md +11 -0
  57. package/mindsystem/references/git-integration.md +254 -0
  58. package/mindsystem/references/goal-backward.md +286 -0
  59. package/mindsystem/references/mock-patterns.md +294 -0
  60. package/mindsystem/references/plan-format.md +473 -0
  61. package/mindsystem/references/principles.md +73 -0
  62. package/mindsystem/references/questioning.md +140 -0
  63. package/mindsystem/references/research-pitfalls.md +233 -0
  64. package/mindsystem/references/scope-estimation.md +256 -0
  65. package/mindsystem/references/tdd.md +263 -0
  66. package/mindsystem/references/verification-patterns.md +595 -0
  67. package/mindsystem/templates/DEBUG.md +159 -0
  68. package/mindsystem/templates/UAT.md +403 -0
  69. package/mindsystem/templates/adhoc-summary.md +153 -0
  70. package/mindsystem/templates/codebase/architecture.md +255 -0
  71. package/mindsystem/templates/codebase/concerns.md +310 -0
  72. package/mindsystem/templates/codebase/conventions.md +307 -0
  73. package/mindsystem/templates/codebase/integrations.md +280 -0
  74. package/mindsystem/templates/codebase/stack.md +186 -0
  75. package/mindsystem/templates/codebase/structure.md +285 -0
  76. package/mindsystem/templates/codebase/testing.md +480 -0
  77. package/mindsystem/templates/config.json +26 -0
  78. package/mindsystem/templates/context.md +140 -0
  79. package/mindsystem/templates/continue-here.md +78 -0
  80. package/mindsystem/templates/debug-subagent-prompt.md +91 -0
  81. package/mindsystem/templates/design-iteration.md +208 -0
  82. package/mindsystem/templates/design.md +417 -0
  83. package/mindsystem/templates/discovery.md +146 -0
  84. package/mindsystem/templates/milestone-archive.md +123 -0
  85. package/mindsystem/templates/milestone-context.md +93 -0
  86. package/mindsystem/templates/milestone.md +115 -0
  87. package/mindsystem/templates/phase-prompt.md +574 -0
  88. package/mindsystem/templates/project.md +184 -0
  89. package/mindsystem/templates/requirements.md +231 -0
  90. package/mindsystem/templates/research-project/ARCHITECTURE.md +204 -0
  91. package/mindsystem/templates/research-project/FEATURES.md +147 -0
  92. package/mindsystem/templates/research-project/PITFALLS.md +200 -0
  93. package/mindsystem/templates/research-project/STACK.md +120 -0
  94. package/mindsystem/templates/research-project/SUMMARY.md +170 -0
  95. package/mindsystem/templates/research-subagent-prompt.md +92 -0
  96. package/mindsystem/templates/research.md +529 -0
  97. package/mindsystem/templates/roadmap.md +214 -0
  98. package/mindsystem/templates/state.md +224 -0
  99. package/mindsystem/templates/summary.md +269 -0
  100. package/mindsystem/templates/user-setup.md +323 -0
  101. package/mindsystem/templates/verification-report.md +322 -0
  102. package/mindsystem/workflows/complete-milestone.md +759 -0
  103. package/mindsystem/workflows/create-milestone.md +203 -0
  104. package/mindsystem/workflows/debug.md +14 -0
  105. package/mindsystem/workflows/define-requirements.md +330 -0
  106. package/mindsystem/workflows/diagnose-issues.md +241 -0
  107. package/mindsystem/workflows/discovery-phase.md +293 -0
  108. package/mindsystem/workflows/discuss-milestone.md +310 -0
  109. package/mindsystem/workflows/discuss-phase.md +237 -0
  110. package/mindsystem/workflows/do-work.md +359 -0
  111. package/mindsystem/workflows/execute-phase.md +644 -0
  112. package/mindsystem/workflows/execute-plan.md +1828 -0
  113. package/mindsystem/workflows/generate-mocks.md +187 -0
  114. package/mindsystem/workflows/list-phase-assumptions.md +178 -0
  115. package/mindsystem/workflows/map-codebase.md +289 -0
  116. package/mindsystem/workflows/plan-phase.md +876 -0
  117. package/mindsystem/workflows/research-phase.md +17 -0
  118. package/mindsystem/workflows/research-project.md +23 -0
  119. package/mindsystem/workflows/resume-project.md +311 -0
  120. package/mindsystem/workflows/transition.md +564 -0
  121. package/mindsystem/workflows/verify-phase.md +629 -0
  122. package/mindsystem/workflows/verify-work.md +823 -0
  123. package/package.json +32 -0
  124. package/scripts/generate-phase-patch.sh +169 -0
  125. package/scripts/ms-lookup/README.md +112 -0
  126. package/scripts/ms-lookup/ms_lookup/__init__.py +3 -0
  127. package/scripts/ms-lookup/ms_lookup/__main__.py +6 -0
  128. package/scripts/ms-lookup/ms_lookup/backends/__init__.py +6 -0
  129. package/scripts/ms-lookup/ms_lookup/backends/context7.py +219 -0
  130. package/scripts/ms-lookup/ms_lookup/backends/perplexity.py +145 -0
  131. package/scripts/ms-lookup/ms_lookup/cache.py +48 -0
  132. package/scripts/ms-lookup/ms_lookup/cli.py +219 -0
  133. package/scripts/ms-lookup/ms_lookup/config.py +23 -0
  134. package/scripts/ms-lookup/ms_lookup/errors.py +24 -0
  135. package/scripts/ms-lookup/ms_lookup/output.py +49 -0
  136. package/scripts/ms-lookup/ms_lookup/tokens.py +56 -0
  137. package/scripts/ms-lookup/pyproject.toml +17 -0
  138. package/scripts/ms-lookup/uv.lock +207 -0
  139. package/scripts/ms-lookup-wrapper.sh +21 -0
@@ -0,0 +1,644 @@
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
+ </required_reading>
12
+
13
+ <process>
14
+
15
+ <step name="load_project_state" priority="first">
16
+ Before any operation, read project state:
17
+
18
+ ```bash
19
+ cat .planning/STATE.md 2>/dev/null
20
+ ```
21
+
22
+ **If file exists:** Parse and internalize:
23
+ - Current position (phase, plan, status)
24
+ - Accumulated decisions (constraints on this execution)
25
+ - Blockers/concerns (things to watch for)
26
+
27
+ **If file missing but .planning/ exists:**
28
+ ```
29
+ STATE.md missing but planning artifacts exist.
30
+ Options:
31
+ 1. Reconstruct from existing artifacts
32
+ 2. Continue without project state (may lose accumulated context)
33
+ ```
34
+
35
+ **If .planning/ doesn't exist:** Error - project not initialized.
36
+ </step>
37
+
38
+ <step name="validate_phase">
39
+ Confirm phase exists and has plans:
40
+
41
+ ```bash
42
+ PHASE_DIR=$(ls -d .planning/phases/${PHASE_ARG}* 2>/dev/null | head -1)
43
+ if [ -z "$PHASE_DIR" ]; then
44
+ echo "ERROR: No phase directory matching '${PHASE_ARG}'"
45
+ exit 1
46
+ fi
47
+
48
+ PLAN_COUNT=$(ls -1 "$PHASE_DIR"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
49
+ if [ "$PLAN_COUNT" -eq 0 ]; then
50
+ echo "ERROR: No plans found in $PHASE_DIR"
51
+ exit 1
52
+ fi
53
+ ```
54
+
55
+ Report: "Found {N} plans in {phase_dir}"
56
+ </step>
57
+
58
+ <step name="discover_plans">
59
+ List all plans and extract metadata:
60
+
61
+ ```bash
62
+ # Get all plans
63
+ ls -1 "$PHASE_DIR"/*-PLAN.md 2>/dev/null | sort
64
+
65
+ # Get completed plans (have SUMMARY.md)
66
+ ls -1 "$PHASE_DIR"/*-SUMMARY.md 2>/dev/null | sort
67
+ ```
68
+
69
+ For each plan, read frontmatter to extract:
70
+ - `wave: N` - Execution wave (pre-computed)
71
+ - `autonomous: true/false` - Whether plan has checkpoints
72
+
73
+ Build plan inventory:
74
+ - Plan path
75
+ - Plan ID (e.g., "03-01")
76
+ - Wave number
77
+ - Autonomous flag
78
+ - Completion status (SUMMARY exists = complete)
79
+
80
+ Skip completed plans. If all complete, report "Phase already executed" and exit.
81
+ </step>
82
+
83
+ <step name="group_by_wave">
84
+ Read `wave` from each plan's frontmatter and group by wave number:
85
+
86
+ ```bash
87
+ # For each plan, extract wave from frontmatter
88
+ for plan in $PHASE_DIR/*-PLAN.md; do
89
+ wave=$(grep "^wave:" "$plan" | cut -d: -f2 | tr -d ' ')
90
+ autonomous=$(grep "^autonomous:" "$plan" | cut -d: -f2 | tr -d ' ')
91
+ echo "$plan:$wave:$autonomous"
92
+ done
93
+ ```
94
+
95
+ **Group plans:**
96
+ ```
97
+ waves = {
98
+ 1: [plan-01, plan-02],
99
+ 2: [plan-03, plan-04],
100
+ 3: [plan-05]
101
+ }
102
+ ```
103
+
104
+ **No dependency analysis needed.** Wave numbers are pre-computed during `/ms:plan-phase`.
105
+
106
+ Report wave structure with context:
107
+ ```
108
+ ## Execution Plan
109
+
110
+ **Phase {X}: {Name}** — {total_plans} plans across {wave_count} waves
111
+
112
+ | Wave | Plans | What it builds |
113
+ |------|-------|----------------|
114
+ | 1 | 01-01, 01-02 | {from plan objectives} |
115
+ | 2 | 01-03 | {from plan objectives} |
116
+ | 3 | 01-04 [checkpoint] | {from plan objectives} |
117
+
118
+ ```
119
+
120
+ The "What it builds" column comes from skimming plan names/objectives. Keep it brief (3-8 words).
121
+ </step>
122
+
123
+ <step name="execute_waves">
124
+ Execute each wave in sequence. Autonomous plans within a wave run in parallel.
125
+
126
+ **For each wave:**
127
+
128
+ 1. **Describe what's being built (BEFORE spawning):**
129
+
130
+ Read each plan's `<objective>` section. Extract what's being built and why it matters.
131
+
132
+ **Output:**
133
+ ```
134
+ ---
135
+
136
+ ## Wave {N}
137
+
138
+ **{Plan ID}: {Plan Name}**
139
+ {2-3 sentences: what this builds, key technical approach, why it matters in context}
140
+
141
+ **{Plan ID}: {Plan Name}** (if parallel)
142
+ {same format}
143
+
144
+ Spawning {count} agent(s)...
145
+
146
+ ---
147
+ ```
148
+
149
+ **Examples:**
150
+ - Bad: "Executing terrain generation plan"
151
+ - Good: "Procedural terrain generator using Perlin noise — creates height maps, biome zones, and collision meshes. Required before vehicle physics can interact with ground."
152
+
153
+ 2. **Spawn all autonomous agents in wave simultaneously:**
154
+
155
+ Use Task tool with multiple parallel calls. Each agent gets prompt from subagent-task-prompt template:
156
+
157
+ ```
158
+ <objective>
159
+ Execute plan {plan_number} of phase {phase_number}-{phase_name}.
160
+
161
+ Commit each task atomically. Create SUMMARY.md. Update STATE.md.
162
+ </objective>
163
+
164
+ <execution_context>
165
+ @~/.claude/mindsystem/workflows/execute-plan.md
166
+ @~/.claude/mindsystem/templates/summary.md
167
+ @~/.claude/mindsystem/references/checkpoints.md
168
+ @~/.claude/mindsystem/references/tdd.md
169
+ </execution_context>
170
+
171
+ <context>
172
+ Plan: @{plan_path}
173
+ Project state: @.planning/STATE.md
174
+ Config: @.planning/config.json (if exists)
175
+ </context>
176
+
177
+ <success_criteria>
178
+ - [ ] All tasks executed
179
+ - [ ] Each task committed individually
180
+ - [ ] SUMMARY.md created in plan directory
181
+ - [ ] STATE.md updated with position and decisions
182
+ </success_criteria>
183
+ ```
184
+
185
+ 2. **Wait for all agents in wave to complete:**
186
+
187
+ Task tool blocks until each agent finishes. All parallel agents return together.
188
+
189
+ 3. **Report completion and what was built:**
190
+
191
+ For each completed agent:
192
+ - Verify SUMMARY.md exists at expected path
193
+ - Read SUMMARY.md to extract what was built
194
+ - Note any issues or deviations
195
+
196
+ **Output:**
197
+ ```
198
+ ---
199
+
200
+ ## Wave {N} Complete
201
+
202
+ **{Plan ID}: {Plan Name}**
203
+ {What was built — from SUMMARY.md deliverables}
204
+ {Notable deviations or discoveries, if any}
205
+
206
+ **{Plan ID}: {Plan Name}** (if parallel)
207
+ {same format}
208
+
209
+ {If more waves: brief note on what this enables for next wave}
210
+
211
+ ---
212
+ ```
213
+
214
+ **Examples:**
215
+ - Bad: "Wave 2 complete. Proceeding to Wave 3."
216
+ - Good: "Terrain system complete — 3 biome types, height-based texturing, physics collision meshes. Vehicle physics (Wave 3) can now reference ground surfaces."
217
+
218
+ 4. **Handle failures:**
219
+
220
+ If any agent in wave fails:
221
+ - Report which plan failed and why
222
+ - Ask user: "Continue with remaining waves?" or "Stop execution?"
223
+ - If continue: proceed to next wave (dependent plans may also fail)
224
+ - If stop: exit with partial completion report
225
+
226
+ 5. **Execute checkpoint plans between waves:**
227
+
228
+ See `<checkpoint_handling>` for details.
229
+
230
+ 6. **Proceed to next wave**
231
+
232
+ </step>
233
+
234
+ <step name="checkpoint_handling">
235
+ Plans with `autonomous: false` require user interaction.
236
+
237
+ **Detection:** Check `autonomous` field in frontmatter.
238
+
239
+ **Execution flow for checkpoint plans:**
240
+
241
+ 1. **Spawn agent for checkpoint plan:**
242
+ ```
243
+ Task(prompt="{subagent-task-prompt}", subagent_type="general-purpose")
244
+ ```
245
+
246
+ 2. **Agent runs until checkpoint:**
247
+ - Executes auto tasks normally
248
+ - Reaches checkpoint task (e.g., `type="checkpoint:human-verify"`) or auth gate
249
+ - Agent returns with structured checkpoint (see checkpoint-return.md template)
250
+
251
+ 3. **Agent return includes (structured format):**
252
+ - Completed Tasks table with commit hashes and files
253
+ - Current task name and blocker
254
+ - Checkpoint type and details for user
255
+ - What's awaited from user
256
+
257
+ 4. **Orchestrator presents checkpoint to user:**
258
+
259
+ Extract and display the "Checkpoint Details" and "Awaiting" sections from agent return:
260
+ ```
261
+ ## Checkpoint: [Type]
262
+
263
+ **Plan:** 03-03 Dashboard Layout
264
+ **Progress:** 2/3 tasks complete
265
+
266
+ [Checkpoint Details section from agent return]
267
+
268
+ [Awaiting section from agent return]
269
+ ```
270
+
271
+ 5. **User responds:**
272
+ - "approved" / "done" → spawn continuation agent
273
+ - Description of issues → spawn continuation agent with feedback
274
+ - Decision selection → spawn continuation agent with choice
275
+
276
+ 6. **Spawn continuation agent (NOT resume):**
277
+
278
+ Use the continuation-prompt.md template:
279
+ ```
280
+ Task(
281
+ prompt=filled_continuation_template,
282
+ subagent_type="general-purpose"
283
+ )
284
+ ```
285
+
286
+ Fill template with:
287
+ - `{completed_tasks_table}`: From agent's checkpoint return
288
+ - `{resume_task_number}`: Current task from checkpoint
289
+ - `{resume_task_name}`: Current task name from checkpoint
290
+ - `{user_response}`: What user provided
291
+ - `{resume_instructions}`: Based on checkpoint type (see continuation-prompt.md)
292
+
293
+ 7. **Continuation agent executes:**
294
+ - Verifies previous commits exist
295
+ - Continues from resume point
296
+ - May hit another checkpoint (repeat from step 4)
297
+ - Or completes plan
298
+
299
+ 8. **Repeat until plan completes or user stops**
300
+
301
+ **Why fresh agent instead of resume:**
302
+ Resume relies on Claude Code's internal serialization which breaks with parallel tool calls.
303
+ Fresh agents with explicit state are more reliable and maintain full context.
304
+
305
+ **Checkpoint in parallel context:**
306
+ If a plan in a parallel wave has a checkpoint:
307
+ - Spawn as normal
308
+ - Agent pauses at checkpoint and returns with structured state
309
+ - Other parallel agents may complete while waiting
310
+ - Present checkpoint to user
311
+ - Spawn continuation agent with user response
312
+ - Wait for all agents to finish before next wave
313
+ </step>
314
+
315
+ <step name="aggregate_results">
316
+ After all waves complete, aggregate results:
317
+
318
+ ```markdown
319
+ ## Phase {X}: {Name} Execution Complete
320
+
321
+ **Waves executed:** {N}
322
+ **Plans completed:** {M} of {total}
323
+
324
+ ### Wave Summary
325
+
326
+ | Wave | Plans | Status |
327
+ |------|-------|--------|
328
+ | 1 | plan-01, plan-02 | ✓ Complete |
329
+ | CP | plan-03 | ✓ Verified |
330
+ | 2 | plan-04 | ✓ Complete |
331
+ | 3 | plan-05 | ✓ Complete |
332
+
333
+ ### Plan Details
334
+
335
+ 1. **03-01**: [one-liner from SUMMARY.md]
336
+ 2. **03-02**: [one-liner from SUMMARY.md]
337
+ ...
338
+
339
+ ### Issues Encountered
340
+ [Aggregate from all SUMMARYs, or "None"]
341
+ ```
342
+ </step>
343
+
344
+ <step name="verify_phase_goal">
345
+ Verify phase achieved its GOAL, not just completed its TASKS.
346
+
347
+ **Spawn verifier:**
348
+
349
+ ```
350
+ Task(
351
+ prompt="Verify phase {phase_number} goal achievement.
352
+
353
+ Phase directory: {phase_dir}
354
+ Phase goal: {goal from ROADMAP.md}
355
+
356
+ Check must_haves against actual codebase. Create VERIFICATION.md.
357
+ Verify what actually exists in the code.",
358
+ subagent_type="ms-verifier"
359
+ )
360
+ ```
361
+
362
+ **Read verification status:**
363
+
364
+ ```bash
365
+ grep "^status:" "$PHASE_DIR"/*-VERIFICATION.md | cut -d: -f2 | tr -d ' '
366
+ ```
367
+
368
+ **Route by status:**
369
+
370
+ | Status | Action |
371
+ |--------|--------|
372
+ | `passed` | Continue to update_roadmap |
373
+ | `human_needed` | Present items to user, get approval or feedback |
374
+ | `gaps_found` | Present gap summary, offer `/ms:plan-phase {phase} --gaps` |
375
+
376
+ **If passed:**
377
+
378
+ Phase goal verified. Proceed to update_roadmap.
379
+
380
+ **If human_needed:**
381
+
382
+ ```markdown
383
+ ## ✓ Phase {X}: {Name} — Human Verification Required
384
+
385
+ All automated checks passed. {N} items need human testing:
386
+
387
+ ### Human Verification Checklist
388
+
389
+ {Extract from VERIFICATION.md human_verification section}
390
+
391
+ ---
392
+
393
+ **After testing:**
394
+ - "approved" → continue to update_roadmap
395
+ - Report issues → will route to gap closure planning
396
+ ```
397
+
398
+ If user approves → continue to update_roadmap.
399
+ If user reports issues → treat as gaps_found.
400
+
401
+ **If gaps_found:**
402
+
403
+ Present gaps and offer next command:
404
+
405
+ ```markdown
406
+ ## ⚠ Phase {X}: {Name} — Gaps Found
407
+
408
+ **Score:** {N}/{M} must-haves verified
409
+ **Report:** {phase_dir}/{phase}-VERIFICATION.md
410
+
411
+ ### What's Missing
412
+
413
+ {Extract gap summaries from VERIFICATION.md gaps section}
414
+
415
+ ---
416
+
417
+ ## ▶ Next Up
418
+
419
+ **Plan gap closure** — create additional plans to complete the phase
420
+
421
+ `/ms:plan-phase {X} --gaps`
422
+
423
+ <sub>`/clear` first → fresh context window</sub>
424
+
425
+ ---
426
+
427
+ **Also available:**
428
+ - `cat {phase_dir}/{phase}-VERIFICATION.md` — see full report
429
+ - `/ms:verify-work {X}` — manual testing before planning
430
+ ```
431
+
432
+ User runs `/ms:plan-phase {X} --gaps` which:
433
+ 1. Reads VERIFICATION.md gaps
434
+ 2. Creates additional plans (04, 05, etc.) to close gaps
435
+ 3. User then runs `/ms:execute-phase {X}` again
436
+ 4. Execute-phase runs incomplete plans (04-05)
437
+ 5. Verifier runs again after new plans complete
438
+
439
+ User stays in control at each decision point.
440
+ </step>
441
+
442
+ <step name="generate_phase_patch">
443
+ Generate a patch file with all implementation changes from this phase.
444
+
445
+ **Run the patch generation script:**
446
+ ```bash
447
+ ~/.claude/mindsystem/scripts/generate-phase-patch.sh ${PHASE_NUMBER}
448
+ ```
449
+
450
+ The script will:
451
+ - Find all commits matching `({PHASE_NUMBER}-` pattern
452
+ - Generate diff from base commit to HEAD
453
+ - Exclude: `.planning`, generated files (Flutter, Next.js, TypeScript), build artifacts
454
+ - Output to `.planning/phases/{phase_dir}/{PHASE_NUMBER}-changes.patch`
455
+ - Skip with message if no phase commits or no implementation changes
456
+
457
+ **Verify patch generation completed:**
458
+ ```bash
459
+ # Check for either: patch file exists OR skip was logged
460
+ PATCH_FILE=$(ls "$PHASE_DIR"/${PHASE_NUMBER}-changes.patch 2>/dev/null)
461
+ if [ -n "$PATCH_FILE" ]; then
462
+ echo "✓ Patch generated: $PATCH_FILE"
463
+ else
464
+ echo "✓ Patch skipped (no implementation changes)"
465
+ fi
466
+ ```
467
+
468
+ **Note:** Patch is NOT committed — left for manual review. User can:
469
+ - Review: `cat .planning/phases/{phase_dir}/{phase}-changes.patch`
470
+ - Apply elsewhere: `git apply {patch_file}`
471
+ - Discard: `rm {patch_file}`
472
+ </step>
473
+
474
+ <step name="update_roadmap">
475
+ Update ROADMAP.md to reflect phase completion:
476
+
477
+ ```bash
478
+ # Mark phase complete
479
+ # Update completion date
480
+ # Update status
481
+ ```
482
+
483
+ Commit phase completion (roadmap, state, verification):
484
+ ```bash
485
+ git add .planning/ROADMAP.md .planning/STATE.md .planning/phases/{phase_dir}/*-VERIFICATION.md
486
+ git add .planning/REQUIREMENTS.md # if updated
487
+ git commit -m "docs(phase-{X}): complete phase execution"
488
+ ```
489
+ </step>
490
+
491
+ <step name="offer_next">
492
+ Present next steps based on milestone status and smart routing.
493
+
494
+ **If more phases remain:**
495
+
496
+ 1. **Parse next phase from ROADMAP.md:**
497
+ ```bash
498
+ # Get next phase details
499
+ grep -A 20 "### Phase ${NEXT_PHASE}:" .planning/ROADMAP.md
500
+ ```
501
+
502
+ Extract: phase name, goal, `**Research**: Likely/Unlikely`, `**Plans**: N plans`
503
+
504
+ 2. **Check for existing context files:**
505
+ ```bash
506
+ CONTEXT_EXISTS=$(ls "$NEXT_PHASE_DIR"/*-CONTEXT.md 2>/dev/null | head -1)
507
+ DESIGN_EXISTS=$(ls "$NEXT_PHASE_DIR"/*-DESIGN.md 2>/dev/null | head -1)
508
+ RESEARCH_EXISTS=$(ls "$NEXT_PHASE_DIR"/*-RESEARCH.md 2>/dev/null | head -1)
509
+ ```
510
+
511
+ 3. **Determine primary suggestion (priority: Discussion > Design > Research > Plan):**
512
+
513
+ **Discussion triggers** (only if no CONTEXT.md exists):
514
+ - User-facing keywords in goal/success criteria: UI, UX, dashboard, form, page, screen, modal, component, layout, design
515
+ - High complexity signals:
516
+ - Plans count >= 3 (from `**Plans**: X plans`)
517
+ - Architecture terms: algorithm, system, architecture, framework
518
+
519
+ **Design triggers** (only if no DESIGN.md exists):
520
+ - UI-heavy keywords: UI, UX, dashboard, form, page, screen, modal, component, layout, design, interface, visual
521
+ - Novel UI work (not just tweaking existing patterns)
522
+
523
+ **Research triggers** (only if no RESEARCH.md exists):
524
+ - `**Research**: Likely` in roadmap phase section
525
+
526
+ **Routing logic:**
527
+ ```
528
+ IF (user-facing keywords OR high-complexity) AND no CONTEXT.md:
529
+ PRIMARY = discuss-phase
530
+ REASON = "{detected signal} — clarify vision first"
531
+ ELSE IF (UI-heavy keywords) AND no DESIGN.md AND CONTEXT.md exists:
532
+ PRIMARY = design-phase
533
+ REASON = "UI-heavy phase — create design specs"
534
+ ELSE IF Research: Likely AND no RESEARCH.md:
535
+ PRIMARY = research-phase
536
+ REASON = "Research: Likely — investigate approach"
537
+ ELSE:
538
+ PRIMARY = plan-phase
539
+ REASON = "Standard patterns — ready to plan"
540
+ ```
541
+
542
+ 4. **Output with reasoning:**
543
+
544
+ ```markdown
545
+ ---
546
+
547
+ ## ▶ Next Up
548
+
549
+ **Phase {X+1}: {Name}** — {Goal}
550
+ *Suggested: {reason}*
551
+
552
+ `/ms:{primary} {X+1}`
553
+
554
+ <sub>`/clear` first → fresh context window</sub>
555
+
556
+ ---
557
+
558
+ **Also available:**
559
+ - `/ms:{alt1} {X+1}` — {alt1_description}
560
+ - `/ms:{alt2} {X+1}` — {alt2_description}
561
+
562
+ ---
563
+ ```
564
+
565
+ **Alternative descriptions:**
566
+ - discuss-phase: "clarify vision and scope"
567
+ - design-phase: "create UI/UX specifications"
568
+ - research-phase: "investigate implementation approach"
569
+ - plan-phase: "create execution plans directly"
570
+
571
+ Only list commands that are NOT the primary suggestion.
572
+
573
+ **If milestone complete:**
574
+ ```markdown
575
+ MILESTONE COMPLETE!
576
+
577
+ All {N} phases executed.
578
+
579
+ `/ms:complete-milestone`
580
+ ```
581
+ </step>
582
+
583
+ </process>
584
+
585
+ <context_efficiency>
586
+ **Why this works:**
587
+
588
+ Orchestrator context usage: ~10-15%
589
+ - Read plan frontmatter (small)
590
+ - Analyze dependencies (logic, no heavy reads)
591
+ - Fill template strings
592
+ - Spawn Task calls
593
+ - Collect results
594
+
595
+ Each subagent: Fresh 200k context
596
+ - Loads full execute-plan workflow
597
+ - Loads templates, references
598
+ - Executes plan with full capacity
599
+ - Creates SUMMARY, commits
600
+
601
+ **No polling.** Task tool blocks until completion. No TaskOutput loops.
602
+
603
+ **No context bleed.** Orchestrator never reads workflow internals. Just paths and results.
604
+ </context_efficiency>
605
+
606
+ <failure_handling>
607
+ **Subagent fails mid-plan:**
608
+ - SUMMARY.md won't exist
609
+ - Orchestrator detects missing SUMMARY
610
+ - Reports failure, asks user how to proceed
611
+
612
+ **Dependency chain breaks:**
613
+ - Wave 1 plan fails
614
+ - Wave 2 plans depending on it will likely fail
615
+ - Orchestrator can still attempt them (user choice)
616
+ - Or skip dependent plans entirely
617
+
618
+ **All agents in wave fail:**
619
+ - Something systemic (git issues, permissions, etc.)
620
+ - Stop execution
621
+ - Report for manual investigation
622
+
623
+ **Checkpoint fails to resolve:**
624
+ - User can't approve or provides repeated issues
625
+ - Ask: "Skip this plan?" or "Abort phase execution?"
626
+ - Record partial progress in STATE.md
627
+ </failure_handling>
628
+
629
+ <resumption>
630
+ **Resuming interrupted execution:**
631
+
632
+ If phase execution was interrupted (context limit, user exit, error):
633
+
634
+ 1. Run `/ms:execute-phase {phase}` again
635
+ 2. discover_plans finds completed SUMMARYs
636
+ 3. Skips completed plans
637
+ 4. Resumes from first incomplete plan
638
+ 5. Continues wave-based execution
639
+
640
+ **STATE.md tracks:**
641
+ - Last completed plan
642
+ - Current wave
643
+ - Any pending checkpoints
644
+ </resumption>