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,1828 @@
1
+ <purpose>
2
+ Execute a phase prompt (PLAN.md) and create the outcome summary (SUMMARY.md).
3
+ </purpose>
4
+
5
+ <required_reading>
6
+ Read STATE.md before any operation to load project context.
7
+ </required_reading>
8
+
9
+ <process>
10
+
11
+ <step name="load_project_state" priority="first">
12
+ Before any operation, read project state:
13
+
14
+ ```bash
15
+ cat .planning/STATE.md 2>/dev/null
16
+ ```
17
+
18
+ **If file exists:** Parse and internalize:
19
+
20
+ - Current position (phase, plan, status)
21
+ - Accumulated decisions (constraints on this execution)
22
+ - Blockers/concerns (things to watch for)
23
+ - Brief alignment status
24
+
25
+ **If file missing but .planning/ exists:**
26
+
27
+ ```
28
+ STATE.md missing but planning artifacts exist.
29
+ Options:
30
+ 1. Reconstruct from existing artifacts
31
+ 2. Continue without project state (may lose accumulated context)
32
+ ```
33
+
34
+ **If .planning/ doesn't exist:** Error - project not initialized.
35
+
36
+ This ensures every execution has full project context.
37
+ </step>
38
+
39
+ <step name="identify_plan">
40
+ Find the next plan to execute:
41
+ - Check roadmap for "In progress" phase
42
+ - Find plans in that phase directory
43
+ - Identify first plan without corresponding SUMMARY
44
+
45
+ ```bash
46
+ cat .planning/ROADMAP.md
47
+ # Look for phase with "In progress" status
48
+ # Then find plans in that phase
49
+ ls .planning/phases/XX-name/*-PLAN.md 2>/dev/null | sort
50
+ ls .planning/phases/XX-name/*-SUMMARY.md 2>/dev/null | sort
51
+ ```
52
+
53
+ **Logic:**
54
+
55
+ - If `01-01-PLAN.md` exists but `01-01-SUMMARY.md` doesn't → execute 01-01
56
+ - If `01-01-SUMMARY.md` exists but `01-02-SUMMARY.md` doesn't → execute 01-02
57
+ - Pattern: Find first PLAN file without matching SUMMARY file
58
+
59
+ **Decimal phase handling:**
60
+
61
+ Phase directories can be integer or decimal format:
62
+
63
+ - Integer: `.planning/phases/01-foundation/01-01-PLAN.md`
64
+ - Decimal: `.planning/phases/01.1-hotfix/01.1-01-PLAN.md`
65
+
66
+ Parse phase number from path (handles both formats):
67
+
68
+ ```bash
69
+ # Extract phase number (handles XX or XX.Y format)
70
+ PHASE=$(echo "$PLAN_PATH" | grep -oE '[0-9]+(\.[0-9]+)?-[0-9]+')
71
+ ```
72
+
73
+ SUMMARY naming follows same pattern:
74
+
75
+ - Integer: `01-01-SUMMARY.md`
76
+ - Decimal: `01.1-01-SUMMARY.md`
77
+
78
+ Confirm with user if ambiguous.
79
+
80
+ <config-check>
81
+ ```bash
82
+ cat .planning/config.json 2>/dev/null
83
+ ```
84
+ </config-check>
85
+
86
+ <if mode="yolo">
87
+ ```
88
+ ⚡ Auto-approved: Execute {phase}-{plan}-PLAN.md
89
+ [Plan X of Y for Phase Z]
90
+
91
+ Starting execution...
92
+ ```
93
+
94
+ Proceed directly to parse_segments step.
95
+ </if>
96
+
97
+ <if mode="interactive" OR="custom with gates.execute_next_plan true">
98
+ Present:
99
+
100
+ ```
101
+ Found plan to execute: {phase}-{plan}-PLAN.md
102
+ [Plan X of Y for Phase Z]
103
+
104
+ Proceed with execution?
105
+ ```
106
+
107
+ Wait for confirmation before proceeding.
108
+ </if>
109
+ </step>
110
+
111
+ <step name="record_start_time">
112
+ Record execution start time for performance tracking:
113
+
114
+ ```bash
115
+ PLAN_START_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
116
+ PLAN_START_EPOCH=$(date +%s)
117
+ ```
118
+
119
+ Store in shell variables for duration calculation at completion.
120
+ </step>
121
+
122
+ <step name="parse_segments">
123
+ **Intelligent segmentation: Parse plan into execution segments.**
124
+
125
+ Plans are divided into segments by checkpoints. Each segment is routed to optimal execution context (subagent or main).
126
+
127
+ **1. Check for checkpoints:**
128
+
129
+ ```bash
130
+ # Find all checkpoints and their types
131
+ grep -n "type=\"checkpoint" .planning/phases/XX-name/{phase}-{plan}-PLAN.md
132
+ ```
133
+
134
+ **2. Analyze execution strategy:**
135
+
136
+ **If NO checkpoints found:**
137
+
138
+ - **Fully autonomous plan** - spawn single subagent for entire plan
139
+ - Subagent gets fresh 200k context, executes all tasks, creates SUMMARY, commits
140
+ - Main context: Just orchestration (~5% usage)
141
+
142
+ **If checkpoints found, parse into segments:**
143
+
144
+ Segment = tasks between checkpoints (or start→first checkpoint, or last checkpoint→end)
145
+
146
+ **For each segment, determine routing:**
147
+
148
+ ```
149
+ Segment routing rules:
150
+
151
+ IF segment has no prior checkpoint:
152
+ → SUBAGENT (first segment, nothing to depend on)
153
+
154
+ IF segment follows checkpoint:human-verify:
155
+ → SUBAGENT (verification is just confirmation, doesn't affect next work)
156
+
157
+ IF segment follows checkpoint:decision OR checkpoint:human-action:
158
+ → MAIN CONTEXT (next tasks need the decision/result)
159
+ ```
160
+
161
+ **3. Execution pattern:**
162
+
163
+ **Pattern A: Fully autonomous (no checkpoints)**
164
+
165
+ ```
166
+ Spawn subagent → execute all tasks → SUMMARY → commit → report back
167
+ ```
168
+
169
+ **Pattern B: Segmented with verify-only checkpoints**
170
+
171
+ ```
172
+ Segment 1 (tasks 1-3): Spawn subagent → execute → report back
173
+ Checkpoint 4 (human-verify): Main context → you verify → continue
174
+ Segment 2 (tasks 5-6): Spawn NEW subagent → execute → report back
175
+ Checkpoint 7 (human-verify): Main context → you verify → continue
176
+ Aggregate results → SUMMARY → commit
177
+ ```
178
+
179
+ **Pattern C: Decision-dependent (must stay in main)**
180
+
181
+ ```
182
+ Checkpoint 1 (decision): Main context → you decide → continue in main
183
+ Tasks 2-5: Main context (need decision from checkpoint 1)
184
+ No segmentation benefit - execute entirely in main
185
+ ```
186
+
187
+ **4. Why this works:**
188
+
189
+ **Segmentation benefits:**
190
+
191
+ - Fresh context for each autonomous segment (0% start every time)
192
+ - Main context only for checkpoints (~10-20% total)
193
+ - Can handle 10+ task plans if properly segmented
194
+ - Quality impossible to degrade in autonomous segments
195
+
196
+ **When segmentation provides no benefit:**
197
+
198
+ - Checkpoint is decision/human-action and following tasks depend on outcome
199
+ - Better to execute sequentially in main than break flow
200
+
201
+ **5. Implementation:**
202
+
203
+ **For fully autonomous plans:**
204
+
205
+ ```
206
+ 1. Run init_agent_tracking step first (see step below)
207
+
208
+ 2. Use Task tool with subagent_type="ms-executor":
209
+
210
+ Prompt: "Execute plan at .planning/phases/{phase}-{plan}-PLAN.md
211
+
212
+ This is an autonomous plan (no checkpoints). Execute all tasks, create SUMMARY.md in phase directory, commit with message following plan's commit guidance.
213
+
214
+ Follow all deviation rules and authentication gate protocols from the plan.
215
+
216
+ When complete, report: plan name, tasks completed, SUMMARY path, commit hash."
217
+
218
+ 3. After Task tool returns with agent_id:
219
+
220
+ a. Write agent_id to current-agent-id.txt:
221
+ echo "[agent_id]" > .planning/current-agent-id.txt
222
+
223
+ b. Append spawn entry to agent-history.json:
224
+ {
225
+ "agent_id": "[agent_id from Task response]",
226
+ "task_description": "Execute full plan {phase}-{plan} (autonomous)",
227
+ "phase": "{phase}",
228
+ "plan": "{plan}",
229
+ "segment": null,
230
+ "timestamp": "[ISO timestamp]",
231
+ "status": "spawned",
232
+ "completion_timestamp": null
233
+ }
234
+
235
+ 4. Wait for subagent to complete
236
+
237
+ 5. After subagent completes successfully:
238
+
239
+ a. Update agent-history.json entry:
240
+ - Find entry with matching agent_id
241
+ - Set status: "completed"
242
+ - Set completion_timestamp: "[ISO timestamp]"
243
+
244
+ b. Clear current-agent-id.txt:
245
+ rm .planning/current-agent-id.txt
246
+
247
+ 6. Report completion to user
248
+ ```
249
+
250
+ **For segmented plans (has verify-only checkpoints):**
251
+
252
+ ```
253
+ Execute segment-by-segment:
254
+
255
+ For each autonomous segment:
256
+ Spawn subagent with prompt: "Execute tasks [X-Y] from plan at .planning/phases/{phase}-{plan}-PLAN.md. Read the plan for full context and deviation rules. Do NOT create SUMMARY or commit - just execute these tasks and report results."
257
+
258
+ Wait for subagent completion
259
+
260
+ For each checkpoint:
261
+ Execute in main context
262
+ Wait for user interaction
263
+ Continue to next segment
264
+
265
+ After all segments complete:
266
+ Aggregate all results
267
+ Create SUMMARY.md
268
+ Commit with all changes
269
+ ```
270
+
271
+ **For decision-dependent plans:**
272
+
273
+ ```
274
+ Execute in main context (standard flow below)
275
+ No subagent routing
276
+ Quality maintained through small scope (2-3 tasks per plan)
277
+ ```
278
+
279
+ See step name="segment_execution" for detailed segment execution loop.
280
+ </step>
281
+
282
+ <step name="init_agent_tracking">
283
+ **Initialize agent tracking for subagent resume capability.**
284
+
285
+ Before spawning any subagents, set up tracking infrastructure:
286
+
287
+ **1. Create/verify tracking files:**
288
+
289
+ ```bash
290
+ # Create agent history file if doesn't exist
291
+ if [ ! -f .planning/agent-history.json ]; then
292
+ echo '{"version":"1.0","max_entries":50,"entries":[]}' > .planning/agent-history.json
293
+ fi
294
+
295
+ # Clear any stale current-agent-id (from interrupted sessions)
296
+ # Will be populated when subagent spawns
297
+ rm -f .planning/current-agent-id.txt
298
+ ```
299
+
300
+ **2. Check for interrupted agents (resume detection):**
301
+
302
+ ```bash
303
+ # Check if current-agent-id.txt exists from previous interrupted session
304
+ if [ -f .planning/current-agent-id.txt ]; then
305
+ INTERRUPTED_ID=$(cat .planning/current-agent-id.txt)
306
+ echo "Found interrupted agent: $INTERRUPTED_ID"
307
+ fi
308
+ ```
309
+
310
+ **If interrupted agent found:**
311
+ - The agent ID file exists from a previous session that didn't complete
312
+ - This agent can potentially be resumed using Task tool's `resume` parameter
313
+ - Present to user: "Previous session was interrupted. Resume agent [ID] or start fresh?"
314
+ - If resume: Use Task tool with `resume` parameter set to the interrupted ID
315
+ - If fresh: Clear the file and proceed normally
316
+
317
+ **3. Prune old entries (housekeeping):**
318
+
319
+ If agent-history.json has more than `max_entries`:
320
+ - Remove oldest entries with status "completed"
321
+ - Never remove entries with status "spawned" (may need resume)
322
+ - Keep file under size limit for fast reads
323
+
324
+ **When to run this step:**
325
+ - Pattern A (fully autonomous): Before spawning the single subagent
326
+ - Pattern B (segmented): Before the segment execution loop
327
+ - Pattern C (main context): Skip - no subagents spawned
328
+ </step>
329
+
330
+ <step name="segment_execution">
331
+ **Detailed segment execution loop for segmented plans.**
332
+
333
+ **This step applies ONLY to segmented plans (Pattern B: has checkpoints, but they're verify-only).**
334
+
335
+ For Pattern A (fully autonomous) and Pattern C (decision-dependent), skip this step.
336
+
337
+ **Execution flow:**
338
+
339
+ ````
340
+ 1. Parse plan to identify segments:
341
+ - Read plan file
342
+ - Find checkpoint locations: grep -n "type=\"checkpoint" PLAN.md
343
+ - Identify checkpoint types: grep "type=\"checkpoint" PLAN.md | grep -o 'checkpoint:[^"]*'
344
+ - Build segment map:
345
+ * Segment 1: Start → first checkpoint (tasks 1-X)
346
+ * Checkpoint 1: Type and location
347
+ * Segment 2: After checkpoint 1 → next checkpoint (tasks X+1 to Y)
348
+ * Checkpoint 2: Type and location
349
+ * ... continue for all segments
350
+
351
+ 2. For each segment in order:
352
+
353
+ A. Determine routing (apply rules from parse_segments):
354
+ - No prior checkpoint? → Subagent
355
+ - Prior checkpoint was human-verify? → Subagent
356
+ - Prior checkpoint was decision/human-action? → Main context
357
+
358
+ B. If routing = Subagent:
359
+ ```
360
+ Spawn Task tool with subagent_type="ms-executor":
361
+
362
+ Prompt: "Execute tasks [task numbers/names] from plan at [plan path].
363
+
364
+ **Context:**
365
+ - Read the full plan for objective, context files, and deviation rules
366
+ - You are executing a SEGMENT of this plan (not the full plan)
367
+ - Other segments will be executed separately
368
+
369
+ **Your responsibilities:**
370
+ - Execute only the tasks assigned to you
371
+ - Follow all deviation rules and authentication gate protocols
372
+ - Track deviations for later Summary
373
+ - DO NOT create SUMMARY.md (will be created after all segments complete)
374
+ - DO NOT commit (will be done after all segments complete)
375
+
376
+ **Report back:**
377
+ - Tasks completed
378
+ - Files created/modified
379
+ - Deviations encountered
380
+ - Any issues or blockers"
381
+
382
+ **After Task tool returns with agent_id:**
383
+
384
+ 1. Write agent_id to current-agent-id.txt:
385
+ echo "[agent_id]" > .planning/current-agent-id.txt
386
+
387
+ 2. Append spawn entry to agent-history.json:
388
+ {
389
+ "agent_id": "[agent_id from Task response]",
390
+ "task_description": "Execute tasks [X-Y] from plan {phase}-{plan}",
391
+ "phase": "{phase}",
392
+ "plan": "{plan}",
393
+ "segment": [segment_number],
394
+ "timestamp": "[ISO timestamp]",
395
+ "status": "spawned",
396
+ "completion_timestamp": null
397
+ }
398
+
399
+ Wait for subagent to complete
400
+ Capture results (files changed, deviations, etc.)
401
+
402
+ **After subagent completes successfully:**
403
+
404
+ 1. Update agent-history.json entry:
405
+ - Find entry with matching agent_id
406
+ - Set status: "completed"
407
+ - Set completion_timestamp: "[ISO timestamp]"
408
+
409
+ 2. Clear current-agent-id.txt:
410
+ rm .planning/current-agent-id.txt
411
+
412
+ ```
413
+
414
+ C. If routing = Main context:
415
+ Execute tasks in main using standard execution flow (step name="execute")
416
+ Track results locally
417
+
418
+ D. After segment completes (whether subagent or main):
419
+ Continue to next checkpoint/segment
420
+
421
+ 3. After ALL segments complete:
422
+
423
+ A. Aggregate results from all segments:
424
+ - Collect files created/modified from all segments
425
+ - Collect deviations from all segments
426
+ - Collect decisions from all checkpoints
427
+ - Merge into complete picture
428
+
429
+ B. Create SUMMARY.md:
430
+ - Use aggregated results
431
+ - Document all work from all segments
432
+ - Include deviations from all segments
433
+ - Note which segments were subagented
434
+
435
+ C. Commit:
436
+ - Stage all files from all segments
437
+ - Stage SUMMARY.md
438
+ - Commit with message following plan guidance
439
+ - Include note about segmented execution if relevant
440
+
441
+ D. Report completion
442
+
443
+ **Example execution trace:**
444
+
445
+ ````
446
+
447
+ Plan: 01-02-PLAN.md (8 tasks, 2 verify checkpoints)
448
+
449
+ Parsing segments...
450
+
451
+ - Segment 1: Tasks 1-3 (autonomous)
452
+ - Checkpoint 4: human-verify
453
+ - Segment 2: Tasks 5-6 (autonomous)
454
+ - Checkpoint 7: human-verify
455
+ - Segment 3: Task 8 (autonomous)
456
+
457
+ Routing analysis:
458
+
459
+ - Segment 1: No prior checkpoint → SUBAGENT ✓
460
+ - Checkpoint 4: Verify only → MAIN (required)
461
+ - Segment 2: After verify → SUBAGENT ✓
462
+ - Checkpoint 7: Verify only → MAIN (required)
463
+ - Segment 3: After verify → SUBAGENT ✓
464
+
465
+ Execution:
466
+ [1] Spawning subagent for tasks 1-3...
467
+ → Subagent completes: 3 files modified, 0 deviations
468
+ [2] Executing checkpoint 4 (human-verify)...
469
+ ╔═══════════════════════════════════════════════════════╗
470
+ ║ CHECKPOINT: Verification Required ║
471
+ ╚═══════════════════════════════════════════════════════╝
472
+
473
+ Progress: 3/8 tasks complete
474
+ Task: Verify database schema
475
+
476
+ Built: User and Session tables with relations
477
+
478
+ How to verify:
479
+ 1. Check src/db/schema.ts for correct types
480
+
481
+ ────────────────────────────────────────────────────────
482
+ → YOUR ACTION: Type "approved" or describe issues
483
+ ────────────────────────────────────────────────────────
484
+ User: "approved"
485
+ [3] Spawning subagent for tasks 5-6...
486
+ → Subagent completes: 2 files modified, 1 deviation (added error handling)
487
+ [4] Executing checkpoint 7 (human-verify)...
488
+ User: "approved"
489
+ [5] Spawning subagent for task 8...
490
+ → Subagent completes: 1 file modified, 0 deviations
491
+
492
+ Aggregating results...
493
+
494
+ - Total files: 6 modified
495
+ - Total deviations: 1
496
+ - Segmented execution: 3 subagents, 2 checkpoints
497
+
498
+ Creating SUMMARY.md...
499
+ Committing...
500
+ ✓ Complete
501
+
502
+ ````
503
+
504
+ **Benefits of this pattern:**
505
+ - Main context usage: ~20% (just orchestration + checkpoints)
506
+ - Subagent 1: Fresh 0-30% (tasks 1-3)
507
+ - Subagent 2: Fresh 0-30% (tasks 5-6)
508
+ - Subagent 3: Fresh 0-20% (task 8)
509
+ - All autonomous work: Peak quality
510
+ - Can handle large plans with many tasks if properly segmented
511
+
512
+ **When NOT to use segmentation:**
513
+ - Plan has decision/human-action checkpoints that affect following tasks
514
+ - Following tasks depend on checkpoint outcome
515
+ - Better to execute in main sequentially in those cases
516
+ </step>
517
+
518
+ <step name="load_prompt">
519
+ Read the plan prompt:
520
+ ```bash
521
+ cat .planning/phases/XX-name/{phase}-{plan}-PLAN.md
522
+ ````
523
+
524
+ This IS the execution instructions. Follow it exactly.
525
+
526
+ **If plan references CONTEXT.md:**
527
+ The CONTEXT.md file provides the user's vision for this phase — how they imagine it working, what's essential, and what's out of scope. Honor this context throughout execution.
528
+ </step>
529
+
530
+ <step name="previous_phase_check">
531
+ Before executing, check if previous phase had issues:
532
+
533
+ ```bash
534
+ # Find previous phase summary
535
+ ls .planning/phases/*/SUMMARY.md 2>/dev/null | sort -r | head -2 | tail -1
536
+ ```
537
+
538
+ If previous phase SUMMARY.md has "Issues Encountered" != "None" or "Next Phase Readiness" mentions blockers:
539
+
540
+ Use AskUserQuestion:
541
+
542
+ - header: "Previous Issues"
543
+ - question: "Previous phase had unresolved items: [summary]. How to proceed?"
544
+ - options:
545
+ - "Proceed anyway" - Issues won't block this phase
546
+ - "Address first" - Let's resolve before continuing
547
+ - "Review previous" - Show me the full summary
548
+ </step>
549
+
550
+ <step name="execute">
551
+ Execute each task in the prompt. **Deviations are normal** - handle them automatically using embedded rules below.
552
+
553
+ 1. Read the @context files listed in the prompt
554
+
555
+ 2. For each task:
556
+
557
+ **If `type="auto"`:**
558
+
559
+ **Before executing:** Check if task has `tdd="true"` attribute:
560
+ - If yes: Follow TDD execution flow (see `<tdd_execution>`) - RED → GREEN → REFACTOR cycle with atomic commits per stage
561
+ - If no: Standard implementation
562
+
563
+ - Work toward task completion
564
+ - **If CLI/API returns authentication error:** Handle as authentication gate (see below)
565
+ - **When you discover additional work not in plan:** Apply deviation rules (see below) automatically
566
+ - Continue implementing, applying rules as needed
567
+ - Run the verification
568
+ - Confirm done criteria met
569
+ - **Commit the task** (see `<task_commit>` below)
570
+ - Track task completion and commit hash for Summary documentation
571
+ - Continue to next task
572
+
573
+ **If `type="checkpoint:*"`:**
574
+
575
+ - STOP immediately (do not continue to next task)
576
+ - Execute checkpoint_protocol (see below)
577
+ - Wait for user response
578
+ - Verify if possible (check files, env vars, etc.)
579
+ - Only after user confirmation: continue to next task
580
+
581
+ 3. Run overall verification checks from `<verification>` section
582
+ 4. Confirm all success criteria from `<success_criteria>` section met
583
+ 5. Document all deviations in Summary (automatic - see deviation_documentation below)
584
+ </step>
585
+
586
+ <authentication_gates>
587
+
588
+ ## Handling Authentication Errors During Execution
589
+
590
+ **When you encounter authentication errors during `type="auto"` task execution:**
591
+
592
+ This is NOT a failure. Authentication gates are expected and normal. Handle them dynamically:
593
+
594
+ **Authentication error indicators:**
595
+
596
+ - CLI returns: "Error: Not authenticated", "Not logged in", "Unauthorized", "401", "403"
597
+ - API returns: "Authentication required", "Invalid API key", "Missing credentials"
598
+ - Command fails with: "Please run {tool} login" or "Set {ENV_VAR} environment variable"
599
+
600
+ **Authentication gate protocol:**
601
+
602
+ 1. **Recognize it's an auth gate** - Not a bug, just needs credentials
603
+ 2. **STOP current task execution** - Don't retry repeatedly
604
+ 3. **Create dynamic checkpoint:human-action** - Present it to user immediately
605
+ 4. **Provide exact authentication steps** - CLI commands, where to get keys
606
+ 5. **Wait for user to authenticate** - Let them complete auth flow
607
+ 6. **Verify authentication works** - Test that credentials are valid
608
+ 7. **Retry the original task** - Resume automation where you left off
609
+ 8. **Continue normally** - Don't treat this as an error in Summary
610
+
611
+ **Example: Vercel deployment hits auth error**
612
+
613
+ ```
614
+ Task 3: Deploy to Vercel
615
+ Running: vercel --yes
616
+
617
+ Error: Not authenticated. Please run 'vercel login'
618
+
619
+ [Create checkpoint dynamically]
620
+
621
+ ╔═══════════════════════════════════════════════════════╗
622
+ ║ CHECKPOINT: Action Required ║
623
+ ╚═══════════════════════════════════════════════════════╝
624
+
625
+ Progress: 2/8 tasks complete
626
+ Task: Authenticate Vercel CLI
627
+
628
+ Attempted: vercel --yes
629
+ Error: Not authenticated
630
+
631
+ What you need to do:
632
+ 1. Run: vercel login
633
+ 2. Complete browser authentication
634
+
635
+ I'll verify: vercel whoami returns your account
636
+
637
+ ────────────────────────────────────────────────────────
638
+ → YOUR ACTION: Type "done" when authenticated
639
+ ────────────────────────────────────────────────────────
640
+
641
+ [Wait for user response]
642
+
643
+ [User types "done"]
644
+
645
+ Verifying authentication...
646
+ Running: vercel whoami
647
+ ✓ Authenticated as: user@example.com
648
+
649
+ Retrying deployment...
650
+ Running: vercel --yes
651
+ ✓ Deployed to: https://myapp-abc123.vercel.app
652
+
653
+ Task 3 complete. Continuing to task 4...
654
+ ```
655
+
656
+ **In Summary documentation:**
657
+
658
+ Document authentication gates as normal flow, not deviations:
659
+
660
+ ```markdown
661
+ ## Authentication Gates
662
+
663
+ During execution, I encountered authentication requirements:
664
+
665
+ 1. Task 3: Vercel CLI required authentication
666
+ - Paused for `vercel login`
667
+ - Resumed after authentication
668
+ - Deployed successfully
669
+
670
+ These are normal gates, not errors.
671
+ ```
672
+
673
+ **Key principles:**
674
+
675
+ - Authentication gates are NOT failures or bugs
676
+ - They're expected interaction points during first-time setup
677
+ - Handle them gracefully and continue automation after unblocked
678
+ - Don't mark tasks as "failed" or "incomplete" due to auth gates
679
+ - Document them as normal flow, separate from deviations
680
+ </authentication_gates>
681
+
682
+ <deviation_rules>
683
+
684
+ ## Automatic Deviation Handling
685
+
686
+ **While executing tasks, you WILL discover work not in the plan.** This is normal.
687
+
688
+ Apply these rules automatically. Track all deviations for Summary documentation.
689
+
690
+ ---
691
+
692
+ **RULE 1: Auto-fix bugs**
693
+
694
+ **Trigger:** Code doesn't work as intended (broken behavior, incorrect output, errors)
695
+
696
+ **Action:** Fix immediately, track for Summary
697
+
698
+ **Examples:**
699
+
700
+ - Wrong SQL query returning incorrect data
701
+ - Logic errors (inverted condition, off-by-one, infinite loop)
702
+ - Type errors, null pointer exceptions, undefined references
703
+ - Broken validation (accepts invalid input, rejects valid input)
704
+ - Security vulnerabilities (SQL injection, XSS, CSRF, insecure auth)
705
+ - Race conditions, deadlocks
706
+ - Memory leaks, resource leaks
707
+
708
+ **Process:**
709
+
710
+ 1. Fix the bug inline
711
+ 2. Add/update tests to prevent regression
712
+ 3. Verify fix works
713
+ 4. Continue task
714
+ 5. Track in deviations list: `[Rule 1 - Bug] [description]`
715
+
716
+ **No user permission needed.** Bugs must be fixed for correct operation.
717
+
718
+ ---
719
+
720
+ **RULE 2: Auto-add missing critical functionality**
721
+
722
+ **Trigger:** Code is missing essential features for correctness, security, or basic operation
723
+
724
+ **Action:** Add immediately, track for Summary
725
+
726
+ **Examples:**
727
+
728
+ - Missing error handling (no try/catch, unhandled promise rejections)
729
+ - No input validation (accepts malicious data, type coercion issues)
730
+ - Missing null/undefined checks (crashes on edge cases)
731
+ - No authentication on protected routes
732
+ - Missing authorization checks (users can access others' data)
733
+ - No CSRF protection, missing CORS configuration
734
+ - No rate limiting on public APIs
735
+ - Missing required database indexes (causes timeouts)
736
+ - No logging for errors (can't debug production)
737
+
738
+ **Process:**
739
+
740
+ 1. Add the missing functionality inline
741
+ 2. Add tests for the new functionality
742
+ 3. Verify it works
743
+ 4. Continue task
744
+ 5. Track in deviations list: `[Rule 2 - Missing Critical] [description]`
745
+
746
+ **Critical = required for correct/secure/performant operation**
747
+ **No user permission needed.** These are not "features" - they're requirements for basic correctness.
748
+
749
+ ---
750
+
751
+ **RULE 3: Auto-fix blocking issues**
752
+
753
+ **Trigger:** Something prevents you from completing current task
754
+
755
+ **Action:** Fix immediately to unblock, track for Summary
756
+
757
+ **Examples:**
758
+
759
+ - Missing dependency (package not installed, import fails)
760
+ - Wrong types blocking compilation
761
+ - Broken import paths (file moved, wrong relative path)
762
+ - Missing environment variable (app won't start)
763
+ - Database connection config error
764
+ - Build configuration error (webpack, tsconfig, etc.)
765
+ - Missing file referenced in code
766
+ - Circular dependency blocking module resolution
767
+
768
+ **Process:**
769
+
770
+ 1. Fix the blocking issue
771
+ 2. Verify task can now proceed
772
+ 3. Continue task
773
+ 4. Track in deviations list: `[Rule 3 - Blocking] [description]`
774
+
775
+ **No user permission needed.** Can't complete task without fixing blocker.
776
+
777
+ ---
778
+
779
+ **RULE 4: Ask about architectural changes**
780
+
781
+ **Trigger:** Fix/addition requires significant structural modification
782
+
783
+ **Action:** STOP, present to user, wait for decision
784
+
785
+ **Examples:**
786
+
787
+ - Adding new database table (not just column)
788
+ - Major schema changes (changing primary key, splitting tables)
789
+ - Introducing new service layer or architectural pattern
790
+ - Switching libraries/frameworks (React → Vue, REST → GraphQL)
791
+ - Changing authentication approach (sessions → JWT)
792
+ - Adding new infrastructure (message queue, cache layer, CDN)
793
+ - Changing API contracts (breaking changes to endpoints)
794
+ - Adding new deployment environment
795
+
796
+ **Process:**
797
+
798
+ 1. STOP current task
799
+ 2. Present clearly:
800
+
801
+ ```
802
+ ⚠️ Architectural Decision Needed
803
+
804
+ Current task: [task name]
805
+ Discovery: [what you found that prompted this]
806
+ Proposed change: [architectural modification]
807
+ Why needed: [rationale]
808
+ Impact: [what this affects - APIs, deployment, dependencies, etc.]
809
+ Alternatives: [other approaches, or "none apparent"]
810
+
811
+ Proceed with proposed change? (yes / different approach / defer)
812
+ ```
813
+
814
+ 3. WAIT for user response
815
+ 4. If approved: implement, track as `[Rule 4 - Architectural] [description]`
816
+ 5. If different approach: discuss and implement
817
+ 6. If deferred: note in Summary and continue without change
818
+
819
+ **User decision required.** These changes affect system design.
820
+
821
+ ---
822
+
823
+ **RULE PRIORITY (when multiple could apply):**
824
+
825
+ 1. **If Rule 4 applies** → STOP and ask (architectural decision)
826
+ 2. **If Rules 1-3 apply** → Fix automatically, track for Summary
827
+ 3. **If genuinely unsure which rule** → Apply Rule 4 (ask user)
828
+
829
+ **Edge case guidance:**
830
+
831
+ - "This validation is missing" → Rule 2 (critical for security)
832
+ - "This crashes on null" → Rule 1 (bug)
833
+ - "Need to add table" → Rule 4 (architectural)
834
+ - "Need to add column" → Rule 1 or 2 (depends: fixing bug or adding critical field)
835
+
836
+ **When in doubt:** Ask yourself "Does this affect correctness, security, or ability to complete task?"
837
+
838
+ - YES → Rules 1-3 (fix automatically)
839
+ - MAYBE → Rule 4 (ask user)
840
+
841
+ </deviation_rules>
842
+
843
+ <deviation_documentation>
844
+
845
+ ## Documenting Deviations in Summary
846
+
847
+ After all tasks complete, Summary MUST include deviations section.
848
+
849
+ **If no deviations:**
850
+
851
+ ```markdown
852
+ ## Deviations from Plan
853
+
854
+ None - plan executed exactly as written.
855
+ ```
856
+
857
+ **If deviations occurred:**
858
+
859
+ ```markdown
860
+ ## Deviations from Plan
861
+
862
+ ### Auto-fixed Issues
863
+
864
+ **1. [Rule 1 - Bug] Fixed case-sensitive email uniqueness constraint**
865
+
866
+ - **Found during:** Task 4 (Follow/unfollow API implementation)
867
+ - **Issue:** User.email unique constraint was case-sensitive - Test@example.com and test@example.com were both allowed, causing duplicate accounts
868
+ - **Fix:** Changed to `CREATE UNIQUE INDEX users_email_unique ON users (LOWER(email))`
869
+ - **Files modified:** src/models/User.ts, migrations/003_fix_email_unique.sql
870
+ - **Verification:** Unique constraint test passes - duplicate emails properly rejected
871
+ - **Commit:** abc123f
872
+
873
+ **2. [Rule 2 - Missing Critical] Added JWT expiry validation to auth middleware**
874
+
875
+ - **Found during:** Task 3 (Protected route implementation)
876
+ - **Issue:** Auth middleware wasn't checking token expiry - expired tokens were being accepted
877
+ - **Fix:** Added exp claim validation in middleware, reject with 401 if expired
878
+ - **Files modified:** src/middleware/auth.ts, src/middleware/auth.test.ts
879
+ - **Verification:** Expired token test passes - properly rejects with 401
880
+ - **Commit:** def456g
881
+
882
+ ---
883
+
884
+ **Total deviations:** 4 auto-fixed (1 bug, 1 missing critical, 1 blocking, 1 architectural with approval)
885
+ **Impact on plan:** All auto-fixes necessary for correctness/security/performance. No scope creep.
886
+ ```
887
+
888
+ **This provides complete transparency:**
889
+
890
+ - Every deviation documented
891
+ - Why it was needed
892
+ - What rule applied
893
+ - What was done
894
+ - User can see exactly what happened beyond the plan
895
+
896
+ </deviation_documentation>
897
+
898
+ <tdd_plan_execution>
899
+ ## TDD Plan Execution
900
+
901
+ When executing a plan with `type: tdd` in frontmatter, follow the RED-GREEN-REFACTOR cycle for the single feature defined in the plan.
902
+
903
+ **1. Check test infrastructure (if first TDD plan):**
904
+ If no test framework configured:
905
+ - Detect project type from package.json/requirements.txt/etc.
906
+ - Install minimal test framework (Jest, pytest, Go testing, etc.)
907
+ - Create test config file
908
+ - Verify: run empty test suite
909
+ - This is part of the RED phase, not a separate task
910
+
911
+ **2. RED - Write failing test:**
912
+ - Read `<behavior>` element for test specification
913
+ - Create test file if doesn't exist (follow project conventions)
914
+ - Write test(s) that describe expected behavior
915
+ - Run tests - MUST fail (if passes, test is wrong or feature exists)
916
+ - Commit: `test({phase}-{plan}): add failing test for [feature]`
917
+
918
+ **3. GREEN - Implement to pass:**
919
+ - Read `<implementation>` element for guidance
920
+ - Write minimal code to make test pass
921
+ - Run tests - MUST pass
922
+ - Commit: `feat({phase}-{plan}): implement [feature]`
923
+
924
+ **4. REFACTOR (if needed):**
925
+ - Clean up code if obvious improvements
926
+ - Run tests - MUST still pass
927
+ - Commit only if changes made: `refactor({phase}-{plan}): clean up [feature]`
928
+
929
+ **Commit pattern for TDD plans:**
930
+ Each TDD plan produces 2-3 atomic commits:
931
+ 1. `test({phase}-{plan}): add failing test for X`
932
+ 2. `feat({phase}-{plan}): implement X`
933
+ 3. `refactor({phase}-{plan}): clean up X` (optional)
934
+
935
+ **Error handling:**
936
+ - If test doesn't fail in RED phase: Test is wrong or feature already exists. Investigate before proceeding.
937
+ - If test doesn't pass in GREEN phase: Debug implementation, keep iterating until green.
938
+ - If tests fail in REFACTOR phase: Undo refactor, commit was premature.
939
+
940
+ **Verification:**
941
+ After TDD plan completion, ensure:
942
+ - All tests pass
943
+ - Test coverage for the new behavior exists
944
+ - No unrelated tests broken
945
+
946
+ **Why TDD uses dedicated plans:** TDD requires 2-3 execution cycles (RED → GREEN → REFACTOR), each with file reads, test runs, and potential debugging. This consumes 40-50% of context for a single feature. Dedicated plans ensure full quality throughout the cycle.
947
+
948
+ **Comparison:**
949
+ - Standard plans: Multiple tasks, 1 commit per task, 2-4 commits total
950
+ - TDD plans: Single feature, 2-3 commits for RED/GREEN/REFACTOR cycle
951
+
952
+ See `~/.claude/mindsystem/references/tdd.md` for TDD plan structure.
953
+ </tdd_plan_execution>
954
+
955
+ <task_commit>
956
+ ## Task Commit Protocol
957
+
958
+ After each task completes (verification passed, done criteria met), commit immediately:
959
+
960
+ **1. Identify modified files:**
961
+
962
+ Track files changed during this specific task (not the entire plan):
963
+
964
+ ```bash
965
+ git status --short
966
+ ```
967
+
968
+ **2. Stage only task-related files:**
969
+
970
+ Stage each file individually (NEVER use `git add .` or `git add -A`):
971
+
972
+ ```bash
973
+ # Example - adjust to actual files modified by this task
974
+ git add src/api/auth.ts
975
+ git add src/types/user.ts
976
+ ```
977
+
978
+ **3. Determine commit type:**
979
+
980
+ | Type | When to Use | Example |
981
+ |------|-------------|---------|
982
+ | `feat` | New feature, endpoint, component, functionality | feat(08-02): create user registration endpoint |
983
+ | `fix` | Bug fix, error correction | fix(08-02): correct email validation regex |
984
+ | `test` | Test-only changes (TDD RED phase) | test(08-02): add failing test for password hashing |
985
+ | `refactor` | Code cleanup, no behavior change (TDD REFACTOR phase) | refactor(08-02): extract validation to helper |
986
+ | `perf` | Performance improvement | perf(08-02): add database index for user lookups |
987
+ | `docs` | Documentation changes | docs(08-02): add API endpoint documentation |
988
+ | `style` | Formatting, linting fixes | style(08-02): format auth module |
989
+ | `chore` | Config, tooling, dependencies | chore(08-02): add bcrypt dependency |
990
+
991
+ **4. Craft commit message:**
992
+
993
+ Format: `{type}({phase}-{plan}): {task-name-or-description}`
994
+
995
+ ```bash
996
+ git commit -m "{type}({phase}-{plan}): {concise task description}
997
+
998
+ - {key change 1}
999
+ - {key change 2}
1000
+ - {key change 3}
1001
+ "
1002
+ ```
1003
+
1004
+ **Examples:**
1005
+
1006
+ ```bash
1007
+ # Standard plan task
1008
+ git commit -m "feat(08-02): create user registration endpoint
1009
+
1010
+ - POST /auth/register validates email and password
1011
+ - Checks for duplicate users
1012
+ - Returns JWT token on success
1013
+ "
1014
+
1015
+ # Another standard task
1016
+ git commit -m "fix(08-02): correct email validation regex
1017
+
1018
+ - Fixed regex to accept plus-addressing
1019
+ - Added tests for edge cases
1020
+ "
1021
+ ```
1022
+
1023
+ **Note:** TDD plans have their own commit pattern (test/feat/refactor for RED/GREEN/REFACTOR phases). See `<tdd_plan_execution>` section above.
1024
+
1025
+ **5. Record commit hash:**
1026
+
1027
+ After committing, capture hash for SUMMARY.md:
1028
+
1029
+ ```bash
1030
+ TASK_COMMIT=$(git rev-parse --short HEAD)
1031
+ echo "Task ${TASK_NUM} committed: ${TASK_COMMIT}"
1032
+ ```
1033
+
1034
+ Store in array or list for SUMMARY generation:
1035
+ ```bash
1036
+ TASK_COMMITS+=("Task ${TASK_NUM}: ${TASK_COMMIT}")
1037
+ ```
1038
+
1039
+ **Atomic commit benefits:**
1040
+ - Each task independently revertable
1041
+ - Git bisect finds exact failing task
1042
+ - Git blame traces line to specific task context
1043
+ - Clear history for Claude in future sessions
1044
+ - Better observability for AI-automated workflow
1045
+
1046
+ </task_commit>
1047
+
1048
+ <step name="checkpoint_protocol">
1049
+ When encountering `type="checkpoint:*"`:
1050
+
1051
+ **Critical: Claude automates everything with CLI/API before checkpoints.** Checkpoints are for verification and decisions, not manual work.
1052
+
1053
+ **Display checkpoint clearly:**
1054
+
1055
+ ```
1056
+ ╔═══════════════════════════════════════════════════════╗
1057
+ ║ CHECKPOINT: [Type] ║
1058
+ ╚═══════════════════════════════════════════════════════╝
1059
+
1060
+ Progress: {X}/{Y} tasks complete
1061
+ Task: [task name]
1062
+
1063
+ [Display task-specific content based on type]
1064
+
1065
+ ────────────────────────────────────────────────────────
1066
+ → YOUR ACTION: [Resume signal instruction]
1067
+ ────────────────────────────────────────────────────────
1068
+ ```
1069
+
1070
+ **For checkpoint:human-verify (90% of checkpoints):**
1071
+
1072
+ ```
1073
+ Built: [what was automated - deployed, built, configured]
1074
+
1075
+ How to verify:
1076
+ 1. [Step 1 - exact command/URL]
1077
+ 2. [Step 2 - what to check]
1078
+ 3. [Step 3 - expected behavior]
1079
+
1080
+ ────────────────────────────────────────────────────────
1081
+ → YOUR ACTION: Type "approved" or describe issues
1082
+ ────────────────────────────────────────────────────────
1083
+ ```
1084
+
1085
+ **For checkpoint:decision (9% of checkpoints):**
1086
+
1087
+ ```
1088
+ Decision needed: [decision]
1089
+
1090
+ Context: [why this matters]
1091
+
1092
+ Options:
1093
+ 1. [option-id]: [name]
1094
+ Pros: [pros]
1095
+ Cons: [cons]
1096
+
1097
+ 2. [option-id]: [name]
1098
+ Pros: [pros]
1099
+ Cons: [cons]
1100
+
1101
+ [Resume signal - e.g., "Select: option-id"]
1102
+ ```
1103
+
1104
+ **For checkpoint:human-action (1% - rare, only for truly unavoidable manual steps):**
1105
+
1106
+ ```
1107
+ I automated: [what Claude already did via CLI/API]
1108
+
1109
+ Need your help with: [the ONE thing with no CLI/API - email link, 2FA code]
1110
+
1111
+ Instructions:
1112
+ [Single unavoidable step]
1113
+
1114
+ I'll verify after: [verification]
1115
+
1116
+ [Resume signal - e.g., "Type 'done' when complete"]
1117
+ ```
1118
+
1119
+ **After displaying:** WAIT for user response. Do NOT hallucinate completion. Do NOT continue to next task.
1120
+
1121
+ **After user responds:**
1122
+
1123
+ - Run verification if specified (file exists, env var set, tests pass, etc.)
1124
+ - If verification passes or N/A: continue to next task
1125
+ - If verification fails: inform user, wait for resolution
1126
+
1127
+ See ~/.claude/mindsystem/references/checkpoints.md for complete checkpoint guidance.
1128
+ </step>
1129
+
1130
+ <step name="checkpoint_return_for_orchestrator">
1131
+ **When spawned by an orchestrator (execute-phase or execute-plan command):**
1132
+
1133
+ If you were spawned via Task tool and hit a checkpoint, you cannot directly interact with the user. Instead, RETURN to the orchestrator with structured checkpoint state so it can present to the user and spawn a fresh continuation agent.
1134
+
1135
+ **Return format for checkpoints:**
1136
+
1137
+ **Required in your return:**
1138
+
1139
+ 1. **Completed Tasks table** - Tasks done so far with commit hashes and files created
1140
+ 2. **Current Task** - Which task you're on and what's blocking it
1141
+ 3. **Checkpoint Details** - User-facing content (verification steps, decision options, or action instructions)
1142
+ 4. **Awaiting** - What you need from the user
1143
+
1144
+ **Example return:**
1145
+
1146
+ ```
1147
+ ## CHECKPOINT REACHED
1148
+
1149
+ **Type:** human-action
1150
+ **Plan:** 01-01
1151
+ **Progress:** 1/3 tasks complete
1152
+
1153
+ ### Completed Tasks
1154
+
1155
+ | Task | Name | Commit | Files |
1156
+ |------|------|--------|-------|
1157
+ | 1 | Initialize Next.js 15 project | d6fe73f | package.json, tsconfig.json, app/ |
1158
+
1159
+ ### Current Task
1160
+
1161
+ **Task 2:** Initialize Convex backend
1162
+ **Status:** blocked
1163
+ **Blocked by:** Convex CLI authentication required
1164
+
1165
+ ### Checkpoint Details
1166
+
1167
+ **Automation attempted:**
1168
+ Ran `npx convex dev` to initialize Convex backend
1169
+
1170
+ **Error encountered:**
1171
+ "Error: Not authenticated. Run `npx convex login` first."
1172
+
1173
+ **What you need to do:**
1174
+ 1. Run: `npx convex login`
1175
+ 2. Complete browser authentication
1176
+ 3. Run: `npx convex dev`
1177
+ 4. Create project when prompted
1178
+
1179
+ **I'll verify after:**
1180
+ `cat .env.local | grep CONVEX` returns the Convex URL
1181
+
1182
+ ### Awaiting
1183
+
1184
+ Type "done" when Convex is authenticated and project created.
1185
+ ```
1186
+
1187
+ **After you return:**
1188
+
1189
+ The orchestrator will:
1190
+ 1. Parse your structured return
1191
+ 2. Present checkpoint details to the user
1192
+ 3. Collect user's response
1193
+ 4. Spawn a FRESH continuation agent with your completed tasks state
1194
+
1195
+ You will NOT be resumed. A new agent continues from where you stopped, using your Completed Tasks table to know what's done.
1196
+
1197
+ **How to know if you were spawned:**
1198
+
1199
+ If you're reading this workflow because an orchestrator spawned you, the orchestrator's prompt will include checkpoint return instructions. Follow those instructions when you hit a checkpoint.
1200
+ </step>
1201
+
1202
+ <step name="verification_failure_gate">
1203
+ If any task verification fails:
1204
+
1205
+ STOP. Do not continue to next task.
1206
+
1207
+ Present inline:
1208
+ "Verification failed for Task [X]: [task name]
1209
+
1210
+ Expected: [verification criteria]
1211
+ Actual: [what happened]
1212
+
1213
+ How to proceed?
1214
+
1215
+ 1. Retry - Try the task again
1216
+ 2. Skip - Mark as incomplete, continue
1217
+ 3. Stop - Pause execution, investigate"
1218
+
1219
+ Wait for user decision.
1220
+
1221
+ If user chose "Skip", note it in SUMMARY.md under "Issues Encountered".
1222
+ </step>
1223
+
1224
+ <step name="record_completion_time">
1225
+ Record execution end time and calculate duration:
1226
+
1227
+ ```bash
1228
+ PLAN_END_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
1229
+ PLAN_END_EPOCH=$(date +%s)
1230
+
1231
+ DURATION_SEC=$(( PLAN_END_EPOCH - PLAN_START_EPOCH ))
1232
+ DURATION_MIN=$(( DURATION_SEC / 60 ))
1233
+
1234
+ if [[ $DURATION_MIN -ge 60 ]]; then
1235
+ HRS=$(( DURATION_MIN / 60 ))
1236
+ MIN=$(( DURATION_MIN % 60 ))
1237
+ DURATION="${HRS}h ${MIN}m"
1238
+ else
1239
+ DURATION="${DURATION_MIN} min"
1240
+ fi
1241
+ ```
1242
+
1243
+ Pass timing data to SUMMARY.md creation.
1244
+ </step>
1245
+
1246
+ <step name="generate_user_setup">
1247
+ **Generate USER-SETUP.md if plan has user_setup in frontmatter.**
1248
+
1249
+ Check PLAN.md frontmatter for `user_setup` field:
1250
+
1251
+ ```bash
1252
+ grep -A 50 "^user_setup:" .planning/phases/XX-name/{phase}-{plan}-PLAN.md | head -50
1253
+ ```
1254
+
1255
+ **If user_setup exists and is not empty:**
1256
+
1257
+ Create `.planning/phases/XX-name/{phase}-USER-SETUP.md` using template from `~/.claude/mindsystem/templates/user-setup.md`.
1258
+
1259
+ **Content generation:**
1260
+
1261
+ 1. Parse each service in `user_setup` array
1262
+ 2. For each service, generate sections:
1263
+ - Environment Variables table (from `env_vars`)
1264
+ - Account Setup checklist (from `account_setup`, if present)
1265
+ - Dashboard Configuration steps (from `dashboard_config`, if present)
1266
+ - Local Development notes (from `local_dev`, if present)
1267
+ 3. Add verification section with commands to confirm setup works
1268
+ 4. Set status to "Incomplete"
1269
+
1270
+ **Example output:**
1271
+
1272
+ ```markdown
1273
+ # Phase 10: User Setup Required
1274
+
1275
+ **Generated:** 2025-01-14
1276
+ **Phase:** 10-monetization
1277
+ **Status:** Incomplete
1278
+
1279
+ ## Environment Variables
1280
+
1281
+ | Status | Variable | Source | Add to |
1282
+ |--------|----------|--------|--------|
1283
+ | [ ] | `STRIPE_SECRET_KEY` | Stripe Dashboard → Developers → API keys → Secret key | `.env.local` |
1284
+ | [ ] | `STRIPE_WEBHOOK_SECRET` | Stripe Dashboard → Developers → Webhooks → Signing secret | `.env.local` |
1285
+
1286
+ ## Dashboard Configuration
1287
+
1288
+ - [ ] **Create webhook endpoint**
1289
+ - Location: Stripe Dashboard → Developers → Webhooks → Add endpoint
1290
+ - Details: URL: https://[your-domain]/api/webhooks/stripe, Events: checkout.session.completed
1291
+
1292
+ ## Local Development
1293
+
1294
+ For local testing:
1295
+ \`\`\`bash
1296
+ stripe listen --forward-to localhost:3000/api/webhooks/stripe
1297
+ \`\`\`
1298
+
1299
+ ## Verification
1300
+
1301
+ [Verification commands based on service]
1302
+
1303
+ ---
1304
+ **Once all items complete:** Mark status as "Complete"
1305
+ ```
1306
+
1307
+ **If user_setup is empty or missing:**
1308
+
1309
+ Skip this step - no USER-SETUP.md needed.
1310
+
1311
+ **Track for offer_next:**
1312
+
1313
+ Set `USER_SETUP_CREATED=true` if file was generated, for use in completion messaging.
1314
+ </step>
1315
+
1316
+ <step name="create_summary">
1317
+ Create `{phase}-{plan}-SUMMARY.md` as specified in the prompt's `<output>` section.
1318
+ Use ~/.claude/mindsystem/templates/summary.md for structure.
1319
+
1320
+ **File location:** `.planning/phases/XX-name/{phase}-{plan}-SUMMARY.md`
1321
+
1322
+ **Frontmatter population:**
1323
+
1324
+ Before writing summary content, populate frontmatter fields from execution context:
1325
+
1326
+ 1. **Basic identification:**
1327
+ - phase: From PLAN.md frontmatter
1328
+ - plan: From PLAN.md frontmatter
1329
+ - subsystem: Categorize based on phase focus (auth, payments, ui, api, database, infra, testing, etc.)
1330
+ - tags: Extract tech keywords (libraries, frameworks, tools used)
1331
+
1332
+ 2. **Dependency graph:**
1333
+ - requires: List prior phases this built upon (check PLAN.md context section for referenced prior summaries)
1334
+ - provides: Extract from accomplishments - what was delivered
1335
+ - affects: Infer from phase description/goal what future phases might need this
1336
+
1337
+ 3. **Tech tracking:**
1338
+ - tech-stack.added: New libraries from package.json changes or requirements
1339
+ - tech-stack.patterns: Architectural patterns established (from decisions/accomplishments)
1340
+
1341
+ 4. **File tracking:**
1342
+ - key-files.created: From "Files Created/Modified" section
1343
+ - key-files.modified: From "Files Created/Modified" section
1344
+
1345
+ 5. **Decisions:**
1346
+ - key-decisions: Extract from "Decisions Made" section
1347
+
1348
+ 6. **Metrics:**
1349
+ - duration: From $DURATION variable
1350
+ - completed: From $PLAN_END_TIME (date only, format YYYY-MM-DD)
1351
+
1352
+ Note: If subsystem/affects are unclear, use best judgment based on phase name and accomplishments. Can be refined later.
1353
+
1354
+ **Title format:** `# Phase [X] Plan [Y]: [Name] Summary`
1355
+
1356
+ The one-liner must be SUBSTANTIVE:
1357
+
1358
+ - Good: "JWT auth with refresh rotation using jose library"
1359
+ - Bad: "Authentication implemented"
1360
+
1361
+ **Include performance data:**
1362
+
1363
+ - Duration: `$DURATION`
1364
+ - Started: `$PLAN_START_TIME`
1365
+ - Completed: `$PLAN_END_TIME`
1366
+ - Tasks completed: (count from execution)
1367
+ - Files modified: (count from execution)
1368
+
1369
+ **Next Step section:**
1370
+
1371
+ - If more plans exist in this phase: "Ready for {phase}-{next-plan}-PLAN.md"
1372
+ - If this is the last plan: "Phase complete, ready for transition"
1373
+ </step>
1374
+
1375
+ <step name="update_current_position">
1376
+ Update Current Position section in STATE.md to reflect plan completion.
1377
+
1378
+ **Format:**
1379
+
1380
+ ```markdown
1381
+ Phase: [current] of [total] ([phase name])
1382
+ Plan: [just completed] of [total in phase]
1383
+ Status: [In progress / Phase complete]
1384
+ Last activity: [today] - Completed {phase}-{plan}-PLAN.md
1385
+
1386
+ Progress: [progress bar]
1387
+ ```
1388
+
1389
+ **Calculate progress bar:**
1390
+
1391
+ - Count total plans across all phases (from ROADMAP.md or ROADMAP.md)
1392
+ - Count completed plans (count SUMMARY.md files that exist)
1393
+ - Progress = (completed / total) × 100%
1394
+ - Render: ░ for incomplete, █ for complete
1395
+
1396
+ **Example - completing 02-01-PLAN.md (plan 5 of 10 total):**
1397
+
1398
+ Before:
1399
+
1400
+ ```markdown
1401
+ ## Current Position
1402
+
1403
+ Phase: 2 of 4 (Authentication)
1404
+ Plan: Not started
1405
+ Status: Ready to execute
1406
+ Last activity: 2025-01-18 - Phase 1 complete
1407
+
1408
+ Progress: ██████░░░░ 40%
1409
+ ```
1410
+
1411
+ After:
1412
+
1413
+ ```markdown
1414
+ ## Current Position
1415
+
1416
+ Phase: 2 of 4 (Authentication)
1417
+ Plan: 1 of 2 in current phase
1418
+ Status: In progress
1419
+ Last activity: 2025-01-19 - Completed 02-01-PLAN.md
1420
+
1421
+ Progress: ███████░░░ 50%
1422
+ ```
1423
+
1424
+ **Step complete when:**
1425
+
1426
+ - [ ] Phase number shows current phase (X of total)
1427
+ - [ ] Plan number shows plans complete in current phase (N of total-in-phase)
1428
+ - [ ] Status reflects current state (In progress / Phase complete)
1429
+ - [ ] Last activity shows today's date and the plan just completed
1430
+ - [ ] Progress bar calculated correctly from total completed plans
1431
+ </step>
1432
+
1433
+ <step name="extract_decisions_and_issues">
1434
+ Extract decisions, issues, and concerns from SUMMARY.md into STATE.md accumulated context.
1435
+
1436
+ **Decisions Made:**
1437
+
1438
+ - Read SUMMARY.md "## Decisions Made" section
1439
+ - If content exists (not "None"):
1440
+ - Add each decision to STATE.md Decisions table
1441
+ - Format: `| [phase number] | [decision summary] | [rationale] |`
1442
+
1443
+ **Blockers/Concerns:**
1444
+
1445
+ - Read SUMMARY.md "## Next Phase Readiness" section
1446
+ - If contains blockers or concerns:
1447
+ - Add to STATE.md "Blockers/Concerns Carried Forward"
1448
+ </step>
1449
+
1450
+ <step name="update_session_continuity">
1451
+ Update Session Continuity section in STATE.md to enable resumption in future sessions.
1452
+
1453
+ **Format:**
1454
+
1455
+ ```markdown
1456
+ Last session: [current date and time]
1457
+ Stopped at: Completed {phase}-{plan}-PLAN.md
1458
+ Resume file: [path to .continue-here if exists, else "None"]
1459
+ ```
1460
+
1461
+ **Size constraint note:** Keep STATE.md under 150 lines total.
1462
+ </step>
1463
+
1464
+ <step name="issues_review_gate">
1465
+ Before proceeding, check SUMMARY.md content.
1466
+
1467
+ If "Issues Encountered" is NOT "None":
1468
+
1469
+ <if mode="yolo">
1470
+ ```
1471
+ ⚡ Auto-approved: Issues acknowledgment
1472
+ ⚠️ Note: Issues were encountered during execution:
1473
+ - [Issue 1]
1474
+ - [Issue 2]
1475
+ (Logged - continuing in yolo mode)
1476
+ ```
1477
+
1478
+ Continue without waiting.
1479
+ </if>
1480
+
1481
+ <if mode="interactive" OR="custom with gates.issues_review true">
1482
+ Present issues and wait for acknowledgment before proceeding.
1483
+ </if>
1484
+ </step>
1485
+
1486
+ <step name="update_roadmap">
1487
+ Update the roadmap file:
1488
+
1489
+ ```bash
1490
+ ROADMAP_FILE=".planning/ROADMAP.md"
1491
+ ```
1492
+
1493
+ **If more plans remain in this phase:**
1494
+
1495
+ - Update plan count: "2/3 plans complete"
1496
+ - Keep phase status as "In progress"
1497
+
1498
+ **If this was the last plan in the phase:**
1499
+
1500
+ - Mark phase complete: status → "Complete"
1501
+ - Add completion date
1502
+ </step>
1503
+
1504
+ <step name="git_commit_metadata">
1505
+ Commit execution metadata (SUMMARY + STATE + ROADMAP):
1506
+
1507
+ **Note:** All task code has already been committed during execution (one commit per task).
1508
+ PLAN.md was already committed during plan-phase. This final commit captures execution results only.
1509
+
1510
+ **1. Stage execution artifacts:**
1511
+
1512
+ ```bash
1513
+ git add .planning/phases/XX-name/{phase}-{plan}-SUMMARY.md
1514
+ git add .planning/STATE.md
1515
+ ```
1516
+
1517
+ **2. Stage roadmap:**
1518
+
1519
+ ```bash
1520
+ git add .planning/ROADMAP.md
1521
+ ```
1522
+
1523
+ **3. Verify staging:**
1524
+
1525
+ ```bash
1526
+ git status
1527
+ # Should show only execution artifacts (SUMMARY, STATE, ROADMAP), no code files
1528
+ ```
1529
+
1530
+ **4. Commit metadata:**
1531
+
1532
+ ```bash
1533
+ git commit -m "$(cat <<'EOF'
1534
+ docs({phase}-{plan}): complete [plan-name] plan
1535
+
1536
+ Tasks completed: [N]/[N]
1537
+ - [Task 1 name]
1538
+ - [Task 2 name]
1539
+ - [Task 3 name]
1540
+
1541
+ SUMMARY: .planning/phases/XX-name/{phase}-{plan}-SUMMARY.md
1542
+ EOF
1543
+ )"
1544
+ ```
1545
+
1546
+ **Example:**
1547
+
1548
+ ```bash
1549
+ git commit -m "$(cat <<'EOF'
1550
+ docs(08-02): complete user registration plan
1551
+
1552
+ Tasks completed: 3/3
1553
+ - User registration endpoint
1554
+ - Password hashing with bcrypt
1555
+ - Email confirmation flow
1556
+
1557
+ SUMMARY: .planning/phases/08-user-auth/08-02-registration-SUMMARY.md
1558
+ EOF
1559
+ )"
1560
+ ```
1561
+
1562
+ **Git log after plan execution:**
1563
+
1564
+ ```
1565
+ abc123f docs(08-02): complete user registration plan
1566
+ def456g feat(08-02): add email confirmation flow
1567
+ hij789k feat(08-02): implement password hashing with bcrypt
1568
+ lmn012o feat(08-02): create user registration endpoint
1569
+ ```
1570
+
1571
+ Each task has its own commit, followed by one metadata commit documenting plan completion.
1572
+
1573
+ For commit message conventions, see ~/.claude/mindsystem/references/git-integration.md
1574
+ </step>
1575
+
1576
+ <step name="update_codebase_map">
1577
+ **If .planning/codebase/ exists:**
1578
+
1579
+ Check what changed across all task commits in this plan:
1580
+
1581
+ ```bash
1582
+ # Find first task commit (right after previous plan's docs commit)
1583
+ FIRST_TASK=$(git log --oneline --grep="feat({phase}-{plan}):" --grep="fix({phase}-{plan}):" --grep="test({phase}-{plan}):" --reverse | head -1 | cut -d' ' -f1)
1584
+
1585
+ # Get all changes from first task through now
1586
+ git diff --name-only ${FIRST_TASK}^..HEAD 2>/dev/null
1587
+ ```
1588
+
1589
+ **Update only if structural changes occurred:**
1590
+
1591
+ | Change Detected | Update Action |
1592
+ |-----------------|---------------|
1593
+ | New directory in src/ | STRUCTURE.md: Add to directory layout |
1594
+ | package.json deps changed | STACK.md: Add/remove from dependencies list |
1595
+ | New file pattern (e.g., first .test.ts) | CONVENTIONS.md: Note new pattern |
1596
+ | New external API client | INTEGRATIONS.md: Add service entry with file path |
1597
+ | Config file added/changed | STACK.md: Update configuration section |
1598
+ | File renamed/moved | Update paths in relevant docs |
1599
+
1600
+ **Skip update if only:**
1601
+ - Code changes within existing files
1602
+ - Bug fixes
1603
+ - Content changes (no structural impact)
1604
+
1605
+ **Update format:**
1606
+ Make single targeted edits - add a bullet point, update a path, or remove a stale entry. Don't rewrite sections.
1607
+
1608
+ ```bash
1609
+ git add .planning/codebase/*.md
1610
+ git commit --amend --no-edit # Include in metadata commit
1611
+ ```
1612
+
1613
+ **If .planning/codebase/ doesn't exist:**
1614
+ Skip this step.
1615
+ </step>
1616
+
1617
+ <step name="offer_next">
1618
+ **MANDATORY: Verify remaining work before presenting next steps.**
1619
+
1620
+ Do NOT skip this verification. Do NOT assume phase or milestone completion without checking.
1621
+
1622
+ **Step 0: Check for USER-SETUP.md**
1623
+
1624
+ If `USER_SETUP_CREATED=true` (from generate_user_setup step), always include this warning block at the TOP of completion output:
1625
+
1626
+ ```
1627
+ ⚠️ USER SETUP REQUIRED
1628
+
1629
+ This phase introduced external services requiring manual configuration:
1630
+
1631
+ 📋 .planning/phases/{phase-dir}/{phase}-USER-SETUP.md
1632
+
1633
+ Quick view:
1634
+ - [ ] {ENV_VAR_1}
1635
+ - [ ] {ENV_VAR_2}
1636
+ - [ ] {Dashboard config task}
1637
+
1638
+ Complete this setup for the integration to function.
1639
+ Run `cat .planning/phases/{phase-dir}/{phase}-USER-SETUP.md` for full details.
1640
+
1641
+ ---
1642
+ ```
1643
+
1644
+ This warning appears BEFORE "Plan complete" messaging. User sees setup requirements prominently.
1645
+
1646
+ **Step 1: Count plans and summaries in current phase**
1647
+
1648
+ List files in the phase directory:
1649
+
1650
+ ```bash
1651
+ ls -1 .planning/phases/[current-phase-dir]/*-PLAN.md 2>/dev/null | wc -l
1652
+ ls -1 .planning/phases/[current-phase-dir]/*-SUMMARY.md 2>/dev/null | wc -l
1653
+ ```
1654
+
1655
+ State the counts: "This phase has [X] plans and [Y] summaries."
1656
+
1657
+ **Step 2: Route based on plan completion**
1658
+
1659
+ Compare the counts from Step 1:
1660
+
1661
+ | Condition | Meaning | Action |
1662
+ |-----------|---------|--------|
1663
+ | summaries < plans | More plans remain | Go to **Route A** |
1664
+ | summaries = plans | Phase complete | Go to Step 3 |
1665
+
1666
+ ---
1667
+
1668
+ **Route A: More plans remain in this phase**
1669
+
1670
+ Identify the next unexecuted plan:
1671
+ - Find the first PLAN.md file that has no matching SUMMARY.md
1672
+ - Read its `<objective>` section
1673
+
1674
+ <if mode="yolo">
1675
+ ```
1676
+ Plan {phase}-{plan} complete.
1677
+ Summary: .planning/phases/{phase-dir}/{phase}-{plan}-SUMMARY.md
1678
+
1679
+ {Y} of {X} plans complete for Phase {Z}.
1680
+
1681
+ ⚡ Auto-continuing: Execute next plan ({phase}-{next-plan})
1682
+ ```
1683
+
1684
+ Loop back to identify_plan step automatically.
1685
+ </if>
1686
+
1687
+ <if mode="interactive" OR="custom with gates.execute_next_plan true">
1688
+ ```
1689
+ Plan {phase}-{plan} complete.
1690
+ Summary: .planning/phases/{phase-dir}/{phase}-{plan}-SUMMARY.md
1691
+
1692
+ {Y} of {X} plans complete for Phase {Z}.
1693
+
1694
+ ---
1695
+
1696
+ ## ▶ Next Up
1697
+
1698
+ **Phase {X}: [Phase Name]** — [goal from ROADMAP.md]
1699
+
1700
+ `/ms:execute-phase {phase-number}`
1701
+
1702
+ <sub>`/clear` first → fresh context window</sub>
1703
+
1704
+ ---
1705
+
1706
+ **Also available:**
1707
+ - `/ms:verify-work {phase}` — manual acceptance testing before continuing
1708
+ - Review what was built before continuing
1709
+
1710
+ ---
1711
+ ```
1712
+
1713
+ Wait for user to clear and run next command.
1714
+ </if>
1715
+
1716
+ **STOP here if Route A applies. Do not continue to Step 3.**
1717
+
1718
+ ---
1719
+
1720
+ **Step 3: Check milestone status (only when all plans in phase are complete)**
1721
+
1722
+ Read ROADMAP.md and extract:
1723
+ 1. Current phase number (from the plan just completed)
1724
+ 2. All phase numbers listed in the current milestone section
1725
+
1726
+ To find phases in the current milestone, look for:
1727
+ - Phase headers: lines starting with `### Phase` or `#### Phase`
1728
+ - Phase list items: lines like `- [ ] **Phase X:` or `- [x] **Phase X:`
1729
+
1730
+ Count total phases in the current milestone and identify the highest phase number.
1731
+
1732
+ State: "Current phase is {X}. Milestone has {N} phases (highest: {Y})."
1733
+
1734
+ **Step 4: Route based on milestone status**
1735
+
1736
+ | Condition | Meaning | Action |
1737
+ |-----------|---------|--------|
1738
+ | current phase < highest phase | More phases remain | Go to **Route B** |
1739
+ | current phase = highest phase | Milestone complete | Go to **Route C** |
1740
+
1741
+ ---
1742
+
1743
+ **Route B: Phase complete, more phases remain in milestone**
1744
+
1745
+ Read ROADMAP.md to get the next phase's name and goal.
1746
+
1747
+ ```
1748
+ Plan {phase}-{plan} complete.
1749
+ Summary: .planning/phases/{phase-dir}/{phase}-{plan}-SUMMARY.md
1750
+
1751
+ ## ✓ Phase {Z}: {Phase Name} Complete
1752
+
1753
+ All {Y} plans finished.
1754
+
1755
+ ---
1756
+
1757
+ ## ▶ Next Up
1758
+
1759
+ **Phase {Z+1}: {Next Phase Name}** — {Goal from ROADMAP.md}
1760
+
1761
+ `/ms:plan-phase {Z+1}`
1762
+
1763
+ <sub>`/clear` first → fresh context window</sub>
1764
+
1765
+ ---
1766
+
1767
+ **Also available:**
1768
+ - `/ms:verify-work {Z}` — manual acceptance testing before continuing
1769
+ - `/ms:discuss-phase {Z+1}` — gather context first
1770
+ - `/ms:research-phase {Z+1}` — investigate unknowns
1771
+ - Review phase accomplishments before continuing
1772
+
1773
+ ---
1774
+ ```
1775
+
1776
+ ---
1777
+
1778
+ **Route C: Milestone complete (all phases done)**
1779
+
1780
+ ```
1781
+ 🎉 MILESTONE COMPLETE!
1782
+
1783
+ Plan {phase}-{plan} complete.
1784
+ Summary: .planning/phases/{phase-dir}/{phase}-{plan}-SUMMARY.md
1785
+
1786
+ ## ✓ Phase {Z}: {Phase Name} Complete
1787
+
1788
+ All {Y} plans finished.
1789
+
1790
+ ╔═══════════════════════════════════════════════════════╗
1791
+ ║ All {N} phases complete! Milestone is 100% done. ║
1792
+ ╚═══════════════════════════════════════════════════════╝
1793
+
1794
+ ---
1795
+
1796
+ ## ▶ Next Up
1797
+
1798
+ **Complete Milestone** — archive and prepare for next
1799
+
1800
+ `/ms:complete-milestone`
1801
+
1802
+ <sub>`/clear` first → fresh context window</sub>
1803
+
1804
+ ---
1805
+
1806
+ **Also available:**
1807
+ - `/ms:verify-work` — manual acceptance testing before completing milestone
1808
+ - `/ms:add-phase <description>` — add another phase before completing
1809
+ - Review accomplishments before archiving
1810
+
1811
+ ---
1812
+ ```
1813
+
1814
+ </step>
1815
+
1816
+ </process>
1817
+
1818
+ <success_criteria>
1819
+
1820
+ - All tasks from PLAN.md completed
1821
+ - All verifications pass
1822
+ - USER-SETUP.md generated if user_setup in frontmatter
1823
+ - SUMMARY.md created with substantive content
1824
+ - STATE.md updated (position, decisions, issues, session)
1825
+ - ROADMAP.md updated
1826
+ - If codebase map exists: map updated with execution changes (or skipped if no significant changes)
1827
+ - If USER-SETUP.md created: prominently surfaced in completion output
1828
+ </success_criteria>