@sienklogic/plan-build-run 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/CLAUDE.md +149 -0
  3. package/LICENSE +21 -0
  4. package/README.md +247 -0
  5. package/dashboard/bin/cli.js +25 -0
  6. package/dashboard/package.json +34 -0
  7. package/dashboard/public/.gitkeep +0 -0
  8. package/dashboard/public/css/layout.css +406 -0
  9. package/dashboard/public/css/status-colors.css +98 -0
  10. package/dashboard/public/js/htmx-title.js +5 -0
  11. package/dashboard/public/js/sidebar-toggle.js +20 -0
  12. package/dashboard/src/app.js +78 -0
  13. package/dashboard/src/middleware/errorHandler.js +52 -0
  14. package/dashboard/src/middleware/notFoundHandler.js +9 -0
  15. package/dashboard/src/repositories/planning.repository.js +128 -0
  16. package/dashboard/src/routes/events.routes.js +40 -0
  17. package/dashboard/src/routes/index.routes.js +31 -0
  18. package/dashboard/src/routes/pages.routes.js +195 -0
  19. package/dashboard/src/server.js +42 -0
  20. package/dashboard/src/services/dashboard.service.js +222 -0
  21. package/dashboard/src/services/phase.service.js +167 -0
  22. package/dashboard/src/services/project.service.js +57 -0
  23. package/dashboard/src/services/roadmap.service.js +171 -0
  24. package/dashboard/src/services/sse.service.js +58 -0
  25. package/dashboard/src/services/todo.service.js +254 -0
  26. package/dashboard/src/services/watcher.service.js +48 -0
  27. package/dashboard/src/views/coming-soon.ejs +11 -0
  28. package/dashboard/src/views/error.ejs +13 -0
  29. package/dashboard/src/views/index.ejs +5 -0
  30. package/dashboard/src/views/layout.ejs +1 -0
  31. package/dashboard/src/views/partials/dashboard-content.ejs +77 -0
  32. package/dashboard/src/views/partials/footer.ejs +3 -0
  33. package/dashboard/src/views/partials/head.ejs +21 -0
  34. package/dashboard/src/views/partials/header.ejs +12 -0
  35. package/dashboard/src/views/partials/layout-bottom.ejs +15 -0
  36. package/dashboard/src/views/partials/layout-top.ejs +8 -0
  37. package/dashboard/src/views/partials/phase-content.ejs +181 -0
  38. package/dashboard/src/views/partials/phases-content.ejs +117 -0
  39. package/dashboard/src/views/partials/roadmap-content.ejs +142 -0
  40. package/dashboard/src/views/partials/sidebar.ejs +38 -0
  41. package/dashboard/src/views/partials/todo-create-content.ejs +53 -0
  42. package/dashboard/src/views/partials/todo-detail-content.ejs +38 -0
  43. package/dashboard/src/views/partials/todos-content.ejs +53 -0
  44. package/dashboard/src/views/phase-detail.ejs +5 -0
  45. package/dashboard/src/views/phases.ejs +5 -0
  46. package/dashboard/src/views/roadmap.ejs +5 -0
  47. package/dashboard/src/views/todo-create.ejs +5 -0
  48. package/dashboard/src/views/todo-detail.ejs +5 -0
  49. package/dashboard/src/views/todos.ejs +5 -0
  50. package/package.json +57 -0
  51. package/plugins/pbr/.claude-plugin/plugin.json +13 -0
  52. package/plugins/pbr/UI-CONSISTENCY-GAPS.md +61 -0
  53. package/plugins/pbr/agents/codebase-mapper.md +271 -0
  54. package/plugins/pbr/agents/debugger.md +281 -0
  55. package/plugins/pbr/agents/executor.md +407 -0
  56. package/plugins/pbr/agents/general.md +164 -0
  57. package/plugins/pbr/agents/integration-checker.md +141 -0
  58. package/plugins/pbr/agents/plan-checker.md +280 -0
  59. package/plugins/pbr/agents/planner.md +358 -0
  60. package/plugins/pbr/agents/researcher.md +363 -0
  61. package/plugins/pbr/agents/synthesizer.md +230 -0
  62. package/plugins/pbr/agents/verifier.md +454 -0
  63. package/plugins/pbr/commands/begin.md +5 -0
  64. package/plugins/pbr/commands/build.md +5 -0
  65. package/plugins/pbr/commands/config.md +5 -0
  66. package/plugins/pbr/commands/continue.md +5 -0
  67. package/plugins/pbr/commands/debug.md +5 -0
  68. package/plugins/pbr/commands/discuss.md +5 -0
  69. package/plugins/pbr/commands/explore.md +5 -0
  70. package/plugins/pbr/commands/health.md +5 -0
  71. package/plugins/pbr/commands/help.md +5 -0
  72. package/plugins/pbr/commands/import.md +5 -0
  73. package/plugins/pbr/commands/milestone.md +5 -0
  74. package/plugins/pbr/commands/note.md +5 -0
  75. package/plugins/pbr/commands/pause.md +5 -0
  76. package/plugins/pbr/commands/plan.md +5 -0
  77. package/plugins/pbr/commands/quick.md +5 -0
  78. package/plugins/pbr/commands/resume.md +5 -0
  79. package/plugins/pbr/commands/review.md +5 -0
  80. package/plugins/pbr/commands/scan.md +5 -0
  81. package/plugins/pbr/commands/setup.md +5 -0
  82. package/plugins/pbr/commands/status.md +5 -0
  83. package/plugins/pbr/commands/todo.md +5 -0
  84. package/plugins/pbr/contexts/dev.md +27 -0
  85. package/plugins/pbr/contexts/research.md +28 -0
  86. package/plugins/pbr/contexts/review.md +36 -0
  87. package/plugins/pbr/hooks/hooks.json +183 -0
  88. package/plugins/pbr/references/agent-anti-patterns.md +24 -0
  89. package/plugins/pbr/references/agent-interactions.md +134 -0
  90. package/plugins/pbr/references/agent-teams.md +54 -0
  91. package/plugins/pbr/references/checkpoints.md +157 -0
  92. package/plugins/pbr/references/common-bug-patterns.md +13 -0
  93. package/plugins/pbr/references/continuation-format.md +212 -0
  94. package/plugins/pbr/references/deviation-rules.md +112 -0
  95. package/plugins/pbr/references/git-integration.md +226 -0
  96. package/plugins/pbr/references/integration-patterns.md +117 -0
  97. package/plugins/pbr/references/model-profiles.md +99 -0
  98. package/plugins/pbr/references/model-selection.md +31 -0
  99. package/plugins/pbr/references/pbr-rules.md +193 -0
  100. package/plugins/pbr/references/plan-authoring.md +181 -0
  101. package/plugins/pbr/references/plan-format.md +283 -0
  102. package/plugins/pbr/references/planning-config.md +213 -0
  103. package/plugins/pbr/references/questioning.md +214 -0
  104. package/plugins/pbr/references/reading-verification.md +127 -0
  105. package/plugins/pbr/references/stub-patterns.md +160 -0
  106. package/plugins/pbr/references/subagent-coordination.md +119 -0
  107. package/plugins/pbr/references/ui-formatting.md +399 -0
  108. package/plugins/pbr/references/verification-patterns.md +198 -0
  109. package/plugins/pbr/references/wave-execution.md +95 -0
  110. package/plugins/pbr/scripts/auto-continue.js +80 -0
  111. package/plugins/pbr/scripts/check-dangerous-commands.js +136 -0
  112. package/plugins/pbr/scripts/check-doc-sprawl.js +102 -0
  113. package/plugins/pbr/scripts/check-phase-boundary.js +196 -0
  114. package/plugins/pbr/scripts/check-plan-format.js +270 -0
  115. package/plugins/pbr/scripts/check-roadmap-sync.js +252 -0
  116. package/plugins/pbr/scripts/check-skill-workflow.js +262 -0
  117. package/plugins/pbr/scripts/check-state-sync.js +476 -0
  118. package/plugins/pbr/scripts/check-subagent-output.js +144 -0
  119. package/plugins/pbr/scripts/config-schema.json +251 -0
  120. package/plugins/pbr/scripts/context-budget-check.js +287 -0
  121. package/plugins/pbr/scripts/event-handler.js +151 -0
  122. package/plugins/pbr/scripts/event-logger.js +92 -0
  123. package/plugins/pbr/scripts/hook-logger.js +76 -0
  124. package/plugins/pbr/scripts/hooks-schema.json +79 -0
  125. package/plugins/pbr/scripts/log-subagent.js +152 -0
  126. package/plugins/pbr/scripts/log-tool-failure.js +88 -0
  127. package/plugins/pbr/scripts/pbr-tools.js +1301 -0
  128. package/plugins/pbr/scripts/post-write-dispatch.js +66 -0
  129. package/plugins/pbr/scripts/post-write-quality.js +207 -0
  130. package/plugins/pbr/scripts/pre-bash-dispatch.js +56 -0
  131. package/plugins/pbr/scripts/pre-write-dispatch.js +62 -0
  132. package/plugins/pbr/scripts/progress-tracker.js +228 -0
  133. package/plugins/pbr/scripts/session-cleanup.js +254 -0
  134. package/plugins/pbr/scripts/status-line.js +285 -0
  135. package/plugins/pbr/scripts/suggest-compact.js +119 -0
  136. package/plugins/pbr/scripts/task-completed.js +45 -0
  137. package/plugins/pbr/scripts/track-context-budget.js +119 -0
  138. package/plugins/pbr/scripts/validate-commit.js +200 -0
  139. package/plugins/pbr/scripts/validate-plugin-structure.js +172 -0
  140. package/plugins/pbr/skills/begin/SKILL.md +545 -0
  141. package/plugins/pbr/skills/begin/templates/PROJECT.md.tmpl +33 -0
  142. package/plugins/pbr/skills/begin/templates/REQUIREMENTS.md.tmpl +18 -0
  143. package/plugins/pbr/skills/begin/templates/STATE.md.tmpl +49 -0
  144. package/plugins/pbr/skills/begin/templates/config.json.tmpl +63 -0
  145. package/plugins/pbr/skills/begin/templates/researcher-prompt.md.tmpl +19 -0
  146. package/plugins/pbr/skills/begin/templates/roadmap-prompt.md.tmpl +30 -0
  147. package/plugins/pbr/skills/begin/templates/synthesis-prompt.md.tmpl +16 -0
  148. package/plugins/pbr/skills/build/SKILL.md +962 -0
  149. package/plugins/pbr/skills/config/SKILL.md +241 -0
  150. package/plugins/pbr/skills/continue/SKILL.md +127 -0
  151. package/plugins/pbr/skills/debug/SKILL.md +489 -0
  152. package/plugins/pbr/skills/debug/templates/continuation-prompt.md.tmpl +16 -0
  153. package/plugins/pbr/skills/debug/templates/initial-investigation-prompt.md.tmpl +27 -0
  154. package/plugins/pbr/skills/discuss/SKILL.md +338 -0
  155. package/plugins/pbr/skills/discuss/templates/CONTEXT.md.tmpl +61 -0
  156. package/plugins/pbr/skills/discuss/templates/decision-categories.md +9 -0
  157. package/plugins/pbr/skills/explore/SKILL.md +362 -0
  158. package/plugins/pbr/skills/health/SKILL.md +186 -0
  159. package/plugins/pbr/skills/health/templates/check-pattern.md.tmpl +30 -0
  160. package/plugins/pbr/skills/health/templates/output-format.md.tmpl +63 -0
  161. package/plugins/pbr/skills/help/SKILL.md +140 -0
  162. package/plugins/pbr/skills/import/SKILL.md +490 -0
  163. package/plugins/pbr/skills/milestone/SKILL.md +673 -0
  164. package/plugins/pbr/skills/milestone/templates/audit-report.md.tmpl +48 -0
  165. package/plugins/pbr/skills/milestone/templates/stats-file.md.tmpl +30 -0
  166. package/plugins/pbr/skills/note/SKILL.md +212 -0
  167. package/plugins/pbr/skills/pause/SKILL.md +235 -0
  168. package/plugins/pbr/skills/pause/templates/continue-here.md.tmpl +71 -0
  169. package/plugins/pbr/skills/plan/SKILL.md +628 -0
  170. package/plugins/pbr/skills/plan/decimal-phase-calc.md +98 -0
  171. package/plugins/pbr/skills/plan/templates/checker-prompt.md.tmpl +21 -0
  172. package/plugins/pbr/skills/plan/templates/gap-closure-prompt.md.tmpl +32 -0
  173. package/plugins/pbr/skills/plan/templates/planner-prompt.md.tmpl +38 -0
  174. package/plugins/pbr/skills/plan/templates/researcher-prompt.md.tmpl +19 -0
  175. package/plugins/pbr/skills/plan/templates/revision-prompt.md.tmpl +23 -0
  176. package/plugins/pbr/skills/quick/SKILL.md +335 -0
  177. package/plugins/pbr/skills/resume/SKILL.md +388 -0
  178. package/plugins/pbr/skills/review/SKILL.md +652 -0
  179. package/plugins/pbr/skills/review/templates/debugger-prompt.md.tmpl +60 -0
  180. package/plugins/pbr/skills/review/templates/gap-planner-prompt.md.tmpl +40 -0
  181. package/plugins/pbr/skills/review/templates/verifier-prompt.md.tmpl +115 -0
  182. package/plugins/pbr/skills/scan/SKILL.md +269 -0
  183. package/plugins/pbr/skills/scan/templates/mapper-prompt.md.tmpl +201 -0
  184. package/plugins/pbr/skills/setup/SKILL.md +227 -0
  185. package/plugins/pbr/skills/shared/commit-planning-docs.md +35 -0
  186. package/plugins/pbr/skills/shared/config-loading.md +102 -0
  187. package/plugins/pbr/skills/shared/context-budget.md +40 -0
  188. package/plugins/pbr/skills/shared/context-loader-task.md +86 -0
  189. package/plugins/pbr/skills/shared/digest-select.md +79 -0
  190. package/plugins/pbr/skills/shared/domain-probes.md +125 -0
  191. package/plugins/pbr/skills/shared/error-reporting.md +79 -0
  192. package/plugins/pbr/skills/shared/gate-prompts.md +388 -0
  193. package/plugins/pbr/skills/shared/phase-argument-parsing.md +45 -0
  194. package/plugins/pbr/skills/shared/progress-display.md +53 -0
  195. package/plugins/pbr/skills/shared/revision-loop.md +81 -0
  196. package/plugins/pbr/skills/shared/state-loading.md +62 -0
  197. package/plugins/pbr/skills/shared/state-update.md +161 -0
  198. package/plugins/pbr/skills/shared/universal-anti-patterns.md +33 -0
  199. package/plugins/pbr/skills/status/SKILL.md +353 -0
  200. package/plugins/pbr/skills/todo/SKILL.md +181 -0
  201. package/plugins/pbr/templates/CONTEXT.md.tmpl +52 -0
  202. package/plugins/pbr/templates/INTEGRATION-REPORT.md.tmpl +151 -0
  203. package/plugins/pbr/templates/RESEARCH-SUMMARY.md.tmpl +97 -0
  204. package/plugins/pbr/templates/ROADMAP.md.tmpl +40 -0
  205. package/plugins/pbr/templates/SUMMARY.md.tmpl +81 -0
  206. package/plugins/pbr/templates/VERIFICATION-DETAIL.md.tmpl +116 -0
  207. package/plugins/pbr/templates/codebase/ARCHITECTURE.md.tmpl +98 -0
  208. package/plugins/pbr/templates/codebase/CONCERNS.md.tmpl +93 -0
  209. package/plugins/pbr/templates/codebase/CONVENTIONS.md.tmpl +104 -0
  210. package/plugins/pbr/templates/codebase/INTEGRATIONS.md.tmpl +78 -0
  211. package/plugins/pbr/templates/codebase/STACK.md.tmpl +78 -0
  212. package/plugins/pbr/templates/codebase/STRUCTURE.md.tmpl +80 -0
  213. package/plugins/pbr/templates/codebase/TESTING.md.tmpl +107 -0
  214. package/plugins/pbr/templates/continue-here.md.tmpl +73 -0
  215. package/plugins/pbr/templates/prompt-partials/phase-project-context.md.tmpl +37 -0
  216. package/plugins/pbr/templates/research/ARCHITECTURE.md.tmpl +124 -0
  217. package/plugins/pbr/templates/research/STACK.md.tmpl +71 -0
  218. package/plugins/pbr/templates/research/SUMMARY.md.tmpl +112 -0
  219. package/plugins/pbr/templates/research-outputs/phase-research.md.tmpl +81 -0
  220. package/plugins/pbr/templates/research-outputs/project-research.md.tmpl +99 -0
  221. package/plugins/pbr/templates/research-outputs/synthesis.md.tmpl +36 -0
@@ -0,0 +1,962 @@
1
+ ---
2
+ name: build
3
+ description: "Execute all plans in a phase. Spawns agents to build in parallel, commits atomically."
4
+ allowed-tools: Read, Write, Edit, Bash, Glob, Grep, Task, AskUserQuestion
5
+ argument-hint: "<phase-number> [--gaps-only] [--team]"
6
+ ---
7
+
8
+ # /pbr:build — Phase Execution
9
+
10
+ You are the orchestrator for `/pbr:build`. This skill executes all plans in a phase by spawning executor agents. Plans are grouped by wave and executed in order — independent plans run in parallel, dependent plans wait. Your job is to stay lean, delegate ALL building work to Task() subagents, and keep the user's main context window clean.
11
+
12
+ ## Context Budget
13
+
14
+ Reference: `skills/shared/context-budget.md` for the universal orchestrator rules.
15
+
16
+ Additionally for this skill:
17
+ - **Minimize** reading executor output — read only SUMMARY.md frontmatter, not full content
18
+ - **Delegate** all building work to executor subagents — the orchestrator routes, it doesn't build
19
+
20
+ ## Prerequisites
21
+
22
+ - `.planning/config.json` exists
23
+ - Phase has been planned: `.planning/phases/{NN}-{slug}/` contains PLAN.md files
24
+ - Prior phase dependencies are completed (check SUMMARY.md files)
25
+
26
+ ---
27
+
28
+ ## Argument Parsing
29
+
30
+ Parse `$ARGUMENTS` according to `skills/shared/phase-argument-parsing.md`.
31
+
32
+ | Argument | Meaning |
33
+ |----------|---------|
34
+ | `3` | Build phase 3 |
35
+ | `3 --gaps-only` | Build only gap-closure plans in phase 3 |
36
+ | `3 --team` | Use Agent Teams for complex inter-agent coordination |
37
+ | (no number) | Use current phase from STATE.md |
38
+
39
+ ---
40
+
41
+ ## Orchestration Flow
42
+
43
+ Execute these steps in order.
44
+
45
+ ---
46
+
47
+ ### Step 1: Parse and Validate (inline)
48
+
49
+ Reference: `skills/shared/config-loading.md` for the tooling shortcut and config field reference.
50
+
51
+ 1. Parse `$ARGUMENTS` for phase number and flags
52
+ 2. Read `.planning/config.json` for parallelization, model, and gate settings (see config-loading.md for field reference)
53
+ 3. Resolve depth profile: run `node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js config resolve-depth` to get the effective feature/gate settings for the current depth. Store the result for use in later gating decisions.
54
+ 4. Write `.planning/.active-skill` with the content `build` (registers with workflow enforcement hook)
55
+ 4. Validate:
56
+ - Phase directory exists at `.planning/phases/{NN}-{slug}/`
57
+ - PLAN.md files exist in the directory
58
+ - Prior phase dependencies are met (check for SUMMARY.md files in dependency phases)
59
+ 4. If no phase number given, read current phase from `.planning/STATE.md`
60
+ - `config.models.complexity_map` — adaptive model mapping (default: `{ simple: "haiku", medium: "sonnet", complex: "inherit" }`)
61
+ 5. If `gates.confirm_execute` is true: use AskUserQuestion (pattern: yes-no from `skills/shared/gate-prompts.md`):
62
+ question: "Ready to build Phase {N}? This will execute {count} plans."
63
+ header: "Build?"
64
+ options:
65
+ - label: "Yes" description: "Start building Phase {N}"
66
+ - label: "No" description: "Cancel — review plans first"
67
+ If "No" or "Other": stop and suggest `/pbr:plan {N}` to review plans
68
+ 6. If `git.branching_strategy` is `phase`: create and switch to branch `plan-build-run/phase-{NN}-{name}` before any build work begins
69
+ 7. Record the current HEAD commit SHA: `git rev-parse HEAD` — store as `pre_build_commit` for use in Step 8-pre-c (codebase map update)
70
+
71
+ **Staleness check (dependency fingerprints):**
72
+ After validating prerequisites, check plan staleness:
73
+ 1. Read each PLAN.md file's `dependency_fingerprints` field (if present)
74
+ 2. For each fingerprinted dependency, check the current SUMMARY.md file (length + modification time)
75
+ 3. If any fingerprint doesn't match: the dependency phase was re-built after this plan was created
76
+ 4. Use AskUserQuestion (pattern: stale-continue from `skills/shared/gate-prompts.md`):
77
+ question: "Plan {plan_id} may be stale — dependency phase {M} was re-built after this plan was created."
78
+ header: "Stale"
79
+ options:
80
+ - label: "Continue anyway" description: "Proceed with existing plans (may still be valid)"
81
+ - label: "Re-plan" description: "Stop and re-plan with `/pbr:plan {N}` (recommended)"
82
+ If "Re-plan" or "Other": stop and suggest `/pbr:plan {N}`
83
+ If "Continue anyway": proceed with existing plans
84
+ 7. If plans have no `dependency_fingerprints` field: skip this check (backward compatible)
85
+
86
+ **Validation errors — use branded error boxes:**
87
+
88
+ If no plans found:
89
+ ```
90
+ ╔══════════════════════════════════════════════════════════════╗
91
+ ║ ERROR ║
92
+ ╚══════════════════════════════════════════════════════════════╝
93
+
94
+ Phase {N} has no plans.
95
+
96
+ **To fix:** Run `/pbr:plan {N}` first.
97
+ ```
98
+
99
+ If dependencies incomplete:
100
+ ```
101
+ ╔══════════════════════════════════════════════════════════════╗
102
+ ║ ERROR ║
103
+ ╚══════════════════════════════════════════════════════════════╝
104
+
105
+ Phase {N} depends on Phase {M}, which is not complete.
106
+
107
+ **To fix:** Build Phase {M} first with `/pbr:build {M}`.
108
+ ```
109
+
110
+ ---
111
+
112
+ ### Step 2: Load Config (inline)
113
+
114
+ Read configuration values needed for execution. See `skills/shared/config-loading.md` for the full field reference; build uses: `parallelization.*`, `features.goal_verification`, `features.inline_verify`, `features.atomic_commits`, `features.auto_continue`, `features.auto_advance`, `planning.commit_docs`, `git.commit_format`, `git.branching_strategy`.
115
+
116
+ ---
117
+
118
+ ### Step 3: Discover Plans (inline)
119
+
120
+ **Tooling shortcut**: Instead of manually parsing each PLAN.md frontmatter, run:
121
+ ```bash
122
+ node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js plan-index <phase>
123
+ ```
124
+ This returns a JSON object with `plans` (array with plan_id, wave, depends_on, autonomous, must_haves_count per plan) and `waves` (grouped by wave). Falls back to manual parsing if unavailable.
125
+
126
+ 1. List all files matching `.planning/phases/{NN}-{slug}/*-PLAN.md`
127
+ 2. If `--gaps-only` flag: filter to only plans with `gap_closure: true` in frontmatter
128
+ 3. Read each plan file's YAML frontmatter to extract:
129
+ - Plan ID
130
+ - Wave number
131
+ - Dependencies (depends_on)
132
+ - Whether autonomous
133
+ 4. Sort plans by plan number
134
+
135
+ **If no plans match filters:**
136
+ - With `--gaps-only`: "No gap-closure plans found. Run `/pbr:plan {N} --gaps` first."
137
+ - Without filter: "No plans found in phase directory."
138
+
139
+ ---
140
+
141
+ ### Step 4: Check for Prior Work (inline)
142
+
143
+ Check for existing SUMMARY.md files from previous runs (crash recovery):
144
+
145
+ 1. List all `SUMMARY-*.md` files in the phase directory
146
+ 2. For each SUMMARY, read its status:
147
+ - `completed`: Skip this plan (already done)
148
+ - `partial`: Present to user — retry or skip?
149
+ - `failed`: Present to user — retry or skip?
150
+ - `checkpoint`: Resume from checkpoint (see Step 6e)
151
+ 3. Build the skip list of plans to exclude
152
+
153
+ **If all plans already have completed SUMMARYs:**
154
+ Use AskUserQuestion (pattern: yes-no from `skills/shared/gate-prompts.md`):
155
+ question: "Phase {N} has already been built. All plans have completed SUMMARYs. Re-build from scratch?"
156
+ header: "Re-build?"
157
+ options:
158
+ - label: "Yes" description: "Delete existing SUMMARYs and re-execute all plans"
159
+ - label: "No" description: "Keep existing build — review instead"
160
+ - If "Yes": delete SUMMARY files and proceed
161
+ - If "No" or "Other": suggest `/pbr:review {N}`
162
+
163
+ ---
164
+
165
+ ### Step 5: Extract Waves (inline)
166
+
167
+ Group plans by wave number from their frontmatter. See `references/wave-execution.md` for the full wave execution model (parallelization, git lock handling, checkpoint manifests).
168
+
169
+ Validate wave consistency:
170
+ - Wave 1 plans must have `depends_on: []`
171
+ - Wave 2+ plans must depend only on plans from earlier waves
172
+ - No plan depends on a plan in the same wave (would need to be sequential)
173
+
174
+ ---
175
+
176
+ ### Step 5b: Write Checkpoint Manifest (inline)
177
+
178
+ Before entering the wave loop, write `.planning/phases/{NN}-{slug}/.checkpoint-manifest.json`:
179
+
180
+ ```json
181
+ {
182
+ "plans": ["02-01", "02-02", "02-03"],
183
+ "checkpoints_resolved": [],
184
+ "checkpoints_pending": [],
185
+ "wave": 1,
186
+ "deferred": [],
187
+ "commit_log": [],
188
+ "last_good_commit": null
189
+ }
190
+ ```
191
+
192
+ This file tracks execution progress for crash recovery and rollback. On resume after compaction, read this manifest to determine where execution left off and which plans still need work.
193
+
194
+ Update the manifest after each wave completes:
195
+ - Move completed plan IDs into `checkpoints_resolved`
196
+ - Advance the `wave` counter
197
+ - Record commit SHAs in `commit_log` (array of `{ plan, sha, timestamp }` objects)
198
+ - Update `last_good_commit` to the SHA of the last successfully verified commit
199
+ - Append any deferred items collected from executor SUMMARYs
200
+
201
+ ---
202
+
203
+ ### Step 6: Wave Loop (core execution)
204
+
205
+ **Crash recovery check:** Before entering the wave loop, check if `.checkpoint-manifest.json` already exists with completed plans from a prior run. If it does, reconstruct the skip list from its `checkpoints_resolved` array. This handles the case where the orchestrator's context was compacted or the session was interrupted mid-build.
206
+
207
+ **Orphaned progress file check:** Also scan the phase directory for `.PROGRESS-*` files. These indicate an executor that crashed mid-task. For each orphaned progress file:
208
+ 1. Read it to find the `plan_id`, `last_completed_task`, and `total_tasks`
209
+ 2. If the plan is NOT in `checkpoints_resolved` (not yet complete), inform the user:
210
+ ```
211
+ Detected interrupted execution for plan {plan_id}: {last_completed_task}/{total_tasks} tasks completed.
212
+ ```
213
+ 3. The executor will automatically resume from the progress file when spawned — no special action needed from the orchestrator.
214
+ 4. If the plan IS in `checkpoints_resolved`, the progress file is stale — delete it.
215
+
216
+ For each wave, in order (Wave 1, then Wave 2, etc.):
217
+
218
+ #### 6a. Spawn Executors
219
+
220
+ For each plan in the current wave (excluding skipped plans):
221
+
222
+ **Present plan narrative before spawning:**
223
+
224
+ Display to the user before spawning:
225
+
226
+ ```
227
+ ◐ Spawning {N} executor(s) for Wave {W}...
228
+ ```
229
+
230
+ Then present a brief narrative for each plan to give the user context on what's about to happen:
231
+
232
+ ```
233
+ Wave {W} — {N} plan(s):
234
+
235
+ Plan {id}: {plan name}
236
+ {2-3 sentence description: what this plan builds, the technical approach, and why it matters.
237
+ Derive this from the plan's must_haves and first task's <action> summary.}
238
+
239
+ Plan {id}: {plan name}
240
+ {2-3 sentence description}
241
+ ```
242
+
243
+ This is a read-only presentation step — extract descriptions from plan frontmatter `must_haves.truths` and the plan's task names. Do not read full task bodies for this; keep it lightweight.
244
+
245
+ **State fragment rule:** Executors MUST NOT modify STATE.md directly. The build skill orchestrator is the sole STATE.md writer during execution. Executors report results via SUMMARY.md only; the orchestrator reads those summaries and updates STATE.md itself.
246
+
247
+ **Model Selection (Adaptive)**:
248
+ Before spawning the executor for each plan, determine the model:
249
+ 1. Read the plan's task elements for `complexity` and `model` attributes
250
+ 2. If ANY task has an explicit `model` attribute, use the most capable model among them (inherit > sonnet > haiku)
251
+ 3. Otherwise, use the HIGHEST complexity among the plan's tasks to select the model:
252
+ - Look up `config.models.complexity_map.{complexity}` (defaults: simple->haiku, medium->sonnet, complex->inherit)
253
+ 4. If `config.models.executor` is set (non-null), it overrides adaptive selection entirely — use that model for all executors
254
+ 5. Pass the selected model to the Task() spawn
255
+
256
+ Reference: `references/model-selection.md` for full details.
257
+
258
+ 1. Extract the `## Summary` section from the PLAN.md (everything after the `## Summary` heading to end of file). If no ## Summary section exists (legacy plans), fall back to reading the full PLAN.md content. Note: The orchestrator reads the full PLAN.md once for narrative extraction AND summary extraction; only the ## Summary portion is inlined into the executor prompt. The full PLAN.md stays on disk for the executor to Read.
259
+ 2. Read `.planning/CONTEXT.md` (if exists)
260
+ 3. Read `.planning/STATE.md`
261
+ 4. Read prior SUMMARY.md files from the same phase (completed plans in earlier waves)
262
+ 5. Read `.planning/config.json`
263
+
264
+ Construct the executor prompt:
265
+
266
+ ```
267
+ You are the executor agent. Execute the following plan.
268
+
269
+ <plan_summary>
270
+ [Inline only the ## Summary section from PLAN.md]
271
+ </plan_summary>
272
+
273
+ <plan_file>
274
+ .planning/phases/{NN}-{slug}/{plan_id}-PLAN.md
275
+ </plan_file>
276
+
277
+ <project_context>
278
+ Project root: {absolute path to project root}
279
+ Platform: {win32|linux|darwin}
280
+
281
+ Config:
282
+ commit_format: {commit_format from config}
283
+ tdd_mode: {tdd_mode from config}
284
+ atomic_commits: {atomic_commits from config}
285
+
286
+ Available context files (read via Read tool as needed):
287
+ - Config: {absolute path to config.json}
288
+ - State: {absolute path to STATE.md}
289
+ {If CONTEXT.md exists:}
290
+ - Project context (locked decisions): {absolute path to CONTEXT.md}
291
+ </project_context>
292
+
293
+ <prior_work>
294
+ Completed plans in this phase:
295
+ | Plan | Status | Commits | Summary File |
296
+ |------|--------|---------|-------------|
297
+ | {plan_id} | complete | {hash1}, {hash2} | {absolute path to SUMMARY.md} |
298
+
299
+ Read any SUMMARY file via Read tool if you need details on what prior plans produced.
300
+ </prior_work>
301
+
302
+ Execute all tasks in the plan sequentially. For each task:
303
+ 0. Read the full plan file from the path in <plan_file> to get task details
304
+ 1. Execute the <action> steps
305
+ 2. Run the <verify> commands
306
+ 3. Create an atomic commit with format: {commit_format}
307
+ 4. Record the commit hash
308
+
309
+ After all tasks complete:
310
+ 1. Write SUMMARY.md to .planning/phases/{NN}-{slug}/SUMMARY-{plan_id}.md
311
+ 2. Run self-check (verify files exist, commits exist, verify commands still pass)
312
+ 3. Return your SUMMARY.md content as your final response
313
+
314
+ If you hit a checkpoint task, STOP and return the checkpoint response format immediately.
315
+ ```
316
+
317
+ **Spawn strategy based on config:**
318
+
319
+ - If `parallelization.enabled: true` AND multiple plans in this wave:
320
+ - Spawn up to `max_concurrent_agents` Task() calls in parallel
321
+ - Each Task() call is independent
322
+ - Use `run_in_background: true` for each executor
323
+ - While waiting, display progress to the user:
324
+ - After spawning: "Wave {W}: launched {N} executors in parallel: {list of plan names}"
325
+ - Periodically (~30s): check `TaskOutput` with `block: false` and report status
326
+ - When each completes: "Plan {id} complete ({duration})"
327
+ - When all complete: "Wave {W} finished. {passed}/{total} plans succeeded."
328
+
329
+ - If `parallelization.enabled: false` OR single plan in wave:
330
+ - Spawn Task() calls sequentially, one at a time
331
+
332
+ ```
333
+ Task({
334
+ subagent_type: "pbr:executor",
335
+ prompt: <executor prompt constructed above>
336
+ })
337
+
338
+ NOTE: The pbr:executor subagent type auto-loads the agent definition. Do NOT inline it.
339
+ ```
340
+
341
+ #### 6b. Wait for Wave Completion
342
+
343
+ Block until all executor Task() calls for this wave complete.
344
+
345
+ #### 6c. Read Results
346
+
347
+ For each completed executor:
348
+
349
+ 1. Check if SUMMARY.md was written to the expected location
350
+ 2. Read the SUMMARY.md frontmatter (not the full body — keep context lean)
351
+ 3. Extract status: `completed` | `partial` | `checkpoint` | `failed`
352
+ 4. Record commit hashes, files created, deviations
353
+ 5. **Update checkpoint manifest `commit_log`**: For each completed plan, append `{ plan: "{plan_id}", sha: "{commit_hash}", timestamp: "{ISO date}" }` to the `commit_log` array. Update `last_good_commit` to the last commit SHA from this wave.
354
+
355
+ **Spot-check executor claims:**
356
+
357
+ After reading each SUMMARY, perform a lightweight verification:
358
+ - Pick 2-3 files from the SUMMARY's `key_files` list and verify they exist (`ls`)
359
+ - Run `git log --oneline -n {commit_count}` and confirm the count matches the claimed commits
360
+ - For each spot-checked file, verify it has >10 lines (`wc -l`): warn if trivially small
361
+ - For each spot-checked file, search for TODO/FIXME/placeholder/stub markers: warn if found
362
+ - Check SUMMARY.md frontmatter for `self_check_failures`: if present, warn the user:
363
+ "Plan {id} reported self-check failures: {list failures}. Inspect before continuing?"
364
+ - If ANY spot-check fails, warn the user before proceeding to the next wave:
365
+ "Spot-check failed for plan {id}: {detail}. Inspect before continuing?"
366
+
367
+ **Read executor deviations:**
368
+
369
+ After all executors in the wave complete, read all SUMMARY frontmatter and:
370
+ - Collect `deferred` items into a running list (append to `.checkpoint-manifest.json` deferred array)
371
+ - Flag any deviation-rule-4 (architectural) stops — these require user attention
372
+ - Present a brief wave summary to the user:
373
+ "Wave {W} complete. {N} plans done. {D} deferred ideas logged. {A} architectural issues."
374
+
375
+ Build a wave results table:
376
+
377
+ ```
378
+ Wave {W} Results:
379
+ | Plan | Status | Tasks | Commits | Deviations |
380
+ |------|--------|-------|---------|------------|
381
+ | {id} | complete | 3/3 | abc, def, ghi | 0 |
382
+ | {id} | complete | 2/2 | jkl, mno | 1 |
383
+ ```
384
+
385
+ #### 6c-ii. Inline Per-Task Verification (conditional)
386
+
387
+ **Skip if** the depth profile has `features.inline_verify: false`.
388
+
389
+ To check: use the resolved depth profile. Only `comprehensive` mode enables inline verification by default.
390
+
391
+ When inline verification is enabled, each completed plan gets a targeted verification pass before the orchestrator proceeds to the next wave. This catches issues early — before dependent plans build on a broken foundation.
392
+
393
+ For each plan that completed successfully in this wave:
394
+
395
+ 1. Read the plan's SUMMARY.md to get `key_files` (the files this plan created/modified)
396
+ 2. Display to the user: `◐ Spawning inline verifier for plan {plan_id}...`
397
+
398
+ Spawn a lightweight verifier:
399
+
400
+ ```
401
+ Task({
402
+ subagent_type: "pbr:verifier",
403
+ model: "haiku",
404
+ prompt: "Targeted inline verification for plan {plan_id}.
405
+
406
+ Verify ONLY these files: {comma-separated key_files list}
407
+
408
+ For each file, check three layers:
409
+ 1. Existence — does the file exist?
410
+ 2. Substantiveness — is it more than a stub? (>10 lines, no TODO/FIXME placeholders)
411
+ 3. Wiring — is it imported/used by at least one other file?
412
+
413
+ Report PASS or FAIL with a one-line reason per file.
414
+ Write nothing to disk — just return your results as text."
415
+ })
416
+ ```
417
+
418
+ 3. If verifier reports FAIL for any file:
419
+ - Present the failure to the user: "Inline verify failed for plan {plan_id}: {details}"
420
+ - Re-spawn the executor for just the failed items: include only the failing file context in the prompt
421
+ - If the retry also fails: proceed but flag in the wave results table (don't block indefinitely)
422
+ 4. If verifier reports all PASS: continue to next wave
423
+
424
+ **Note:** This adds latency (~10-20s per plan for the haiku verifier). It's opt-in via `features.inline_verify: true` for projects where early detection outweighs speed.
425
+
426
+ ---
427
+
428
+ #### 6d. Handle Failures
429
+
430
+ If any executor returned `failed` or `partial`:
431
+
432
+ **Handoff bug check (false-failure detection):**
433
+
434
+ Before presenting failure options, check whether the executor actually completed its work despite reporting failure (known Claude Code platform bug where handoff reports failure but work is done):
435
+
436
+ 1. Check if SUMMARY.md exists at the expected path for this plan
437
+ 2. If SUMMARY.md exists:
438
+ a. Read its frontmatter `status` field
439
+ b. If `status: complete` AND frontmatter has `commits` entries:
440
+ - Run the same spot-checks from Step 6c (file existence, commit count)
441
+ - If spot-checks pass: treat this plan as **success**, not failure
442
+ - Tell user: "Plan {id} reported failure but SUMMARY.md shows completed work. Spot-checks passed — treating as success."
443
+ - Skip the failure flow for this plan
444
+ c. If `status: partial` or spot-checks fail: proceed with normal failure handling below
445
+
446
+ Present failure details to the user:
447
+ ```
448
+ Plan {id} {status}:
449
+ Task {N}: {name} - FAILED
450
+ Error: {verify output or error message}
451
+
452
+ Deviations attempted: {count}
453
+ Last verify output: {output}
454
+ ```
455
+
456
+ Use AskUserQuestion (pattern: multi-option-failure from `skills/shared/gate-prompts.md`):
457
+ question: "Plan {id} failed at task {N} ({name}). How should we proceed?"
458
+ header: "Failed"
459
+ options:
460
+ - label: "Retry" description: "Re-spawn the executor for this plan"
461
+ - label: "Skip" description: "Mark as skipped, continue to next wave"
462
+ - label: "Rollback" description: "Undo commits from this plan, revert to last good state"
463
+ - label: "Abort" description: "Stop the entire build"
464
+
465
+ **If user selects 'Retry':**
466
+ - Re-spawn executor Task() with the same prompt
467
+ - If retry also fails: ask user again (max 2 retries total)
468
+
469
+ **If user selects 'Skip':**
470
+ - Note the skip in results
471
+ - Check if any plans in later waves depend on the skipped plan
472
+ - If yes: warn user that those plans will also need to be skipped or adjusted
473
+
474
+ **If user selects 'Rollback':**
475
+ - Read `last_good_commit` from `.checkpoint-manifest.json`
476
+ - If `last_good_commit` exists:
477
+ - Show the user: "Rolling back to commit {sha} (last verified good state). This will soft-reset {N} commits."
478
+ - Run: `git reset --soft {last_good_commit}`
479
+ - Delete the failed plan's SUMMARY.md file if it was created
480
+ - Update the checkpoint manifest: remove the failed plan from `checkpoints_resolved`
481
+ - Continue to next wave or stop based on user preference
482
+ - If no `last_good_commit`: warn "No rollback point available (this was the first plan). Use abort instead."
483
+
484
+ **If user selects 'Abort':**
485
+ - Update STATE.md with current progress
486
+ - Present what was completed before the abort
487
+ - Suggest: "Fix the issue and run `/pbr:build {N}` to resume (completed plans will be skipped)"
488
+
489
+ #### 6e. Handle Checkpoints
490
+
491
+ If any executor returned `checkpoint`:
492
+
493
+ 1. Read the checkpoint details from the executor's response
494
+ 2. Present the checkpoint to the user:
495
+
496
+ ```
497
+ Checkpoint in Plan {id}, Task {N}: {checkpoint type}
498
+
499
+ {checkpoint details — what was built, what is needed}
500
+
501
+ {For decision type: present options}
502
+ {For human-action type: present steps}
503
+ {For human-verify type: present what to verify}
504
+ ```
505
+
506
+ 3. Wait for user response
507
+ 4. Spawn a FRESH continuation executor:
508
+
509
+ Reference: `references/continuation-format.md` for the continuation protocol.
510
+
511
+ ```
512
+ You are the executor agent. Continue executing a plan from a checkpoint.
513
+
514
+ <plan_summary>
515
+ [Inline only the ## Summary section from PLAN.md]
516
+ </plan_summary>
517
+
518
+ <plan_file>
519
+ .planning/phases/{NN}-{slug}/{plan_id}-PLAN.md
520
+ </plan_file>
521
+
522
+ <completed_tasks>
523
+ | Task | Commit | Status |
524
+ |------|--------|--------|
525
+ | {task_name} | {hash} | complete |
526
+ | {task_name} | {hash} | complete |
527
+ | {checkpoint_task} | — | checkpoint |
528
+ </completed_tasks>
529
+
530
+ <checkpoint_resolution>
531
+ User response to checkpoint: {user's response}
532
+ Resume at: Task {N+1} (or re-execute checkpoint task with user's answer)
533
+ </checkpoint_resolution>
534
+
535
+ <project_context>
536
+ {Same lean context as original spawn — config key-values + file paths, not inlined bodies}
537
+ </project_context>
538
+
539
+ Continue execution from the checkpoint. Skip completed tasks. Process the checkpoint resolution, then continue with remaining tasks. Write SUMMARY.md when done.
540
+ ```
541
+
542
+ #### 6f. Update STATE.md
543
+
544
+ After each wave completes (all plans in the wave are done, skipped, or aborted):
545
+
546
+ **SUMMARY gate — verify before updating STATE.md:**
547
+
548
+ Before writing any STATE.md update, verify these three gates for every plan in the wave:
549
+ 1. SUMMARY file exists at the expected path
550
+ 2. SUMMARY file is not empty (file size > 0)
551
+ 3. SUMMARY file has a valid title and YAML frontmatter (contains `---` delimiters and a `status:` field)
552
+
553
+ Block the STATE.md update until ALL gates pass. If any gate fails:
554
+ - Warn user: "SUMMARY gate failed for plan {id}: {which gate}. Cannot update STATE.md."
555
+ - Ask user to retry the executor or manually inspect the SUMMARY file
556
+
557
+ Once gates pass, update `.planning/STATE.md`:
558
+
559
+ **Tooling shortcut**: Use the CLI for atomic STATE.md updates instead of manual read-modify-write:
560
+ ```bash
561
+ node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js state update plans_complete {N}
562
+ node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js state update status building
563
+ node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js state update last_activity now
564
+ ```
565
+
566
+ - Current plan progress: "{completed}/{total} in current phase"
567
+ - Last activity timestamp
568
+ - Progress bar percentage
569
+ - Any new decisions from executor deviations
570
+
571
+ **STATE.md size limit:** Follow the size limit enforcement rules in `skills/shared/state-update.md` (150 lines max — collapse completed phases, remove duplicated decisions, trim old sessions).
572
+
573
+ ---
574
+
575
+ ### Step 7: Phase Verification (delegated, conditional)
576
+
577
+ **Event-driven auto-verify signal:** Check if `.planning/.auto-verify` exists (written by `event-handler.js` SubagentStop hook). If the signal file exists, read it and delete it (one-shot). The signal confirms that auto-verification was triggered — proceed with verification even if the build just finished.
578
+
579
+ **Skip if:**
580
+ - Build was aborted
581
+ - Depth profile has `features.goal_verification: false`
582
+ - Depth is `quick` AND the total task count across all plans in this phase is fewer than 3
583
+
584
+ To check: run `node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js config resolve-depth` and read `profile["features.goal_verification"]`. For the task-count check in quick mode, sum the task counts from all PLAN.md frontmatter `must_haves` (already available from Step 3 plan discovery).
585
+
586
+ This implements budget mode's "skip verifier for < 3 tasks" rule: small phases in quick mode don't need a full verification pass.
587
+
588
+ **If skipping because `features.goal_verification` is `false`:**
589
+ Note for Step 8f completion summary: append "Note: Automatic verification was skipped (goal_verification: false). Run `/pbr:review {N}` to verify what was built."
590
+
591
+ **If verification is enabled:**
592
+
593
+ Display to the user: `◐ Spawning verifier...`
594
+
595
+ Spawn a verifier Task():
596
+
597
+ ```
598
+ Task({
599
+ subagent_type: "pbr:verifier",
600
+ prompt: <verifier prompt>
601
+ })
602
+
603
+ NOTE: The pbr:verifier subagent type auto-loads the agent definition. Do NOT inline it.
604
+ ```
605
+
606
+ #### Verifier Prompt Template
607
+
608
+ ```
609
+ You are the verifier agent. Verify that phase {N} meets its goals.
610
+
611
+ <verification_approach>
612
+ For each must-have from the phase's plans, perform a three-layer check:
613
+
614
+ Layer 1 — Existence: Does the artifact exist? (ls, grep for exports)
615
+ Layer 2 — Substantiveness: Is it more than a stub? (wc -l, grep for implementation)
616
+ Layer 3 — Wiring: Is it connected to the rest of the system? (grep for imports/usage)
617
+
618
+ See references/verification-patterns.md for detailed patterns.
619
+ </verification_approach>
620
+
621
+ <phase_plans>
622
+ [For each PLAN.md in the phase: inline the must_haves section from frontmatter]
623
+ </phase_plans>
624
+
625
+ <build_results>
626
+ Build summaries for verification (read full content via Read tool):
627
+
628
+ | Plan | Summary File | Status |
629
+ |------|-------------|--------|
630
+ {For each SUMMARY.md in the phase:}
631
+ | {plan_id} | {absolute path to SUMMARY.md} | {status from frontmatter} |
632
+
633
+ Read each SUMMARY file to check what was actually built against the must-haves.
634
+ </build_results>
635
+
636
+ <instructions>
637
+ 1. For each must-have truth: run existence, substantiveness, and wiring checks
638
+ 2. For each must-have artifact: verify the file exists and has real content
639
+ 3. For each must-have key_link: verify the connection is made
640
+
641
+ Write your verification report to .planning/phases/{NN}-{slug}/VERIFICATION.md
642
+
643
+ Format:
644
+ ---
645
+ status: "passed" | "gaps_found" | "human_needed"
646
+ phase: "{NN}-{slug}"
647
+ checked_at: "{date}"
648
+ must_haves_checked: {count}
649
+ must_haves_passed: {count}
650
+ must_haves_failed: {count}
651
+ ---
652
+
653
+ # Phase Verification: {phase name}
654
+
655
+ ## Results
656
+
657
+ | Must-Have | Layer 1 | Layer 2 | Layer 3 | Status |
658
+ |-----------|---------|---------|---------|--------|
659
+ | {truth} | PASS | PASS | PASS | PASSED |
660
+ | {truth} | PASS | FAIL | — | GAP |
661
+
662
+ ## Gaps Found
663
+ {For each gap: what's missing, which layer failed, suggested fix}
664
+
665
+ ## Passed
666
+ {For each pass: what was verified, how}
667
+ </instructions>
668
+
669
+ Use the Write tool to create VERIFICATION.md. Use Bash to run verification commands.
670
+ ```
671
+
672
+ ---
673
+
674
+ ### Step 8: Finalize (inline)
675
+
676
+ After all waves complete and optional verification runs:
677
+
678
+ **8-pre. Re-verify after gap closure (conditional):**
679
+
680
+ If `--gaps-only` flag was used AND `features.goal_verification` is `true`:
681
+
682
+ 1. Delete the existing `VERIFICATION.md` (it reflects pre-gap-closure state)
683
+ 2. Re-run the verifier using the same Step 7 process — this produces a fresh `VERIFICATION.md` that accounts for the gap-closure work
684
+ 3. Read the new verification status for use in determining `final_status` below
685
+
686
+ This ensures that `/pbr:review` after a `--gaps-only` build sees the updated verification state, not stale gaps from before the fix.
687
+
688
+ **8-pre-b. Determine final status based on verification:**
689
+ - If verification ran and status is `passed`: final_status = "built"
690
+ - If verification ran and status is `gaps_found`: final_status = "built*" (built with unverified gaps)
691
+ - If verification was skipped: final_status = "built (unverified)"
692
+ - If build was partial: final_status = "partial"
693
+
694
+ **8-pre-c. Codebase map incremental update (conditional):**
695
+
696
+ Only run if ALL of these are true:
697
+ - `.planning/codebase/` directory exists (project was previously scanned with `/pbr:scan`)
698
+ - Build was not aborted
699
+ - `git diff --name-only {pre_build_commit}..HEAD` shows >5 files changed OR `package.json`/`requirements.txt`/`go.mod`/`Cargo.toml` was modified
700
+
701
+ If triggered:
702
+ 1. Record the pre-build commit SHA at the start of Step 1 (before any executors run) for comparison
703
+ 2. Run `git diff --name-only {pre_build_commit}..HEAD` to get the list of changed files
704
+ 3. Display to the user: `◐ Spawning codebase mapper (incremental update)...`
705
+
706
+ Spawn a lightweight mapper Task():
707
+ ```
708
+ Task({
709
+ subagent_type: "pbr:codebase-mapper",
710
+ model: "haiku",
711
+ prompt: "Incremental codebase map update. These files changed during the Phase {N} build:\n{diff file list}\n\nRead the existing .planning/codebase/ documents. Update ONLY the sections affected by these changes. Do NOT rewrite entire documents — make targeted updates. If a new dependency was added, update STACK.md. If new directories/modules were created, update STRUCTURE.md. If new patterns were introduced, update CONVENTIONS.md. Write updated files to .planning/codebase/."
712
+ })
713
+ ```
714
+ 4. Do NOT block on this — use `run_in_background: true` and continue to Step 8a. Report completion in Step 8f if it finishes in time.
715
+
716
+ **8a. Update ROADMAP.md Progress table** (REQUIRED — do this BEFORE updating STATE.md):
717
+
718
+ **Tooling shortcut**: Use the CLI for atomic ROADMAP.md table updates instead of manual editing:
719
+ ```bash
720
+ node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js roadmap update-plans {phase} {completed} {total}
721
+ node ${CLAUDE_PLUGIN_ROOT}/scripts/pbr-tools.js roadmap update-status {phase} {final_status}
722
+ ```
723
+ These return `{ success, old_status, new_status }` or `{ success, old_plans, new_plans }`. Falls back to manual editing if unavailable.
724
+
725
+ 1. Open `.planning/ROADMAP.md`
726
+ 2. Find the `## Progress` table
727
+ 3. Locate the row matching this phase number
728
+ 4. Update the `Plans Complete` column to `{completed}/{total}` (e.g., `2/2` if all plans built successfully)
729
+ 5. Update the `Status` column to the final_status determined in Step 8-pre
730
+ 6. Save the file — do NOT skip this step
731
+
732
+ **8b. Update STATE.md:**
733
+ - Phase status: {final_status from Step 8-pre}
734
+ - Plan completion count
735
+ - Last activity timestamp
736
+ - Progress bar
737
+
738
+ **8c. Commit planning docs (if configured):**
739
+ Reference: `skills/shared/commit-planning-docs.md` for the standard commit pattern.
740
+ If `planning.commit_docs` is `true`:
741
+ - Stage SUMMARY.md files and VERIFICATION.md
742
+ - Commit: `docs({phase}): add build summaries and verification`
743
+
744
+ **8d. Handle git branching:**
745
+ If `git.branching_strategy` is `phase`:
746
+ - All work was done on the phase branch (created in Step 1)
747
+ - Squash merge to main: `git checkout main && git merge --squash plan-build-run/phase-{NN}-{name}`
748
+ - Use AskUserQuestion (pattern: yes-no from `skills/shared/gate-prompts.md`):
749
+ question: "Phase {N} complete on branch `plan-build-run/phase-{NN}-{name}`. Squash merge to main?"
750
+ header: "Merge?"
751
+ options:
752
+ - label: "Yes, merge" description: "Squash merge to main and delete the phase branch"
753
+ - label: "No, keep" description: "Leave the branch as-is for manual review"
754
+ - If "Yes, merge": complete the merge and delete the phase branch
755
+ - If "No, keep" or "Other": leave the branch as-is and inform the user
756
+
757
+ **8e. Auto-advance / auto-continue (conditional):**
758
+
759
+ **If `features.auto_advance` is `true` AND `mode` is `autonomous`:**
760
+ Chain to the next skill directly within this session. This eliminates manual phase cycling.
761
+
762
+ | Build Result | Next Action | How |
763
+ |-------------|-------------|-----|
764
+ | Verification passed, more phases | Plan next phase | `Skill({ skill: "dev:plan", args: "{N+1}" })` |
765
+ | Verification skipped | Run review | `Skill({ skill: "dev:review", args: "{N}" })` |
766
+ | Verification gaps found | **HARD STOP** — present gaps to user | Do NOT auto-advance past failures |
767
+ | Last phase complete | **HARD STOP** — milestone boundary | Suggest `/pbr:milestone audit` |
768
+ | Build errors occurred | **HARD STOP** — errors need human review | Do NOT auto-advance past errors |
769
+
770
+ After invoking the chained skill, it runs within the same session. When it completes, the chained skill may itself chain further (review→plan, plan→build) if auto_advance remains true. This creates the full cycle: build→review→plan→build→...
771
+
772
+ **Else if `features.auto_continue` is `true`:**
773
+ Write `.planning/.auto-next` containing the next logical command (e.g., `/pbr:plan {N+1}` or `/pbr:review {N}`)
774
+ - This file signals to the user or to wrapper scripts that the next step is ready
775
+
776
+ **8f. Present completion summary:**
777
+
778
+ Use the branded output templates from `references/ui-formatting.md`. Route based on status:
779
+
780
+ | Status | Template |
781
+ |--------|----------|
782
+ | `passed` + more phases | "Phase Complete" template |
783
+ | `passed` + last phase | "Milestone Complete" template |
784
+ | `gaps_found` | "Gaps Found" template |
785
+
786
+ Before the branded banner, include the results table:
787
+
788
+ ```
789
+ Results:
790
+ | Plan | Status | Tasks | Commits |
791
+ |------|--------|-------|---------|
792
+ | {id} | complete | 3/3 | 3 |
793
+ | {id} | complete | 2/2 | 2 |
794
+
795
+ {If verification ran:}
796
+ Verification: {PASSED | GAPS_FOUND}
797
+ {count} must-haves checked, {count} passed, {count} gaps
798
+
799
+ Total commits: {count}
800
+ Total files created: {count}
801
+ Total files modified: {count}
802
+ Deviations: {count}
803
+ ```
804
+
805
+ Then present the appropriate branded banner:
806
+
807
+ **If `passed` + more phases:**
808
+ ```
809
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
810
+ PLAN-BUILD-RUN ► PHASE {N} COMPLETE ✓
811
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
812
+
813
+ **Phase {N}: {Name}**
814
+
815
+ {X} plans executed
816
+ Goal verified ✓
817
+
818
+ ───────────────────────────────────────────────────────────────
819
+
820
+ ## ▶ Next Up
821
+
822
+ **Phase {N+1}: {Name}** — {Goal from ROADMAP.md}
823
+
824
+ `/pbr:plan {N+1}`
825
+
826
+ <sub>`/clear` first → fresh context window</sub>
827
+
828
+ ───────────────────────────────────────────────────────────────
829
+
830
+ **Also available:**
831
+ - `/pbr:review {N}` — manual acceptance testing before continuing
832
+ - `/pbr:status` — see full project status
833
+
834
+ ───────────────────────────────────────────────────────────────
835
+ ```
836
+
837
+ **If `passed` + last phase:**
838
+ ```
839
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
840
+ PLAN-BUILD-RUN ► MILESTONE COMPLETE 🎉
841
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
842
+
843
+ {N} phases completed
844
+ All phase goals verified ✓
845
+
846
+ ───────────────────────────────────────────────────────────────
847
+
848
+ ## ▶ Next Up
849
+
850
+ **Audit milestone** — verify requirements, cross-phase integration, E2E flows
851
+
852
+ `/pbr:milestone audit`
853
+
854
+ <sub>`/clear` first → fresh context window</sub>
855
+
856
+ ───────────────────────────────────────────────────────────────
857
+
858
+ **Also available:**
859
+ - `/pbr:review` — manual acceptance testing
860
+ - `/pbr:milestone complete` — skip audit, archive directly
861
+
862
+ ───────────────────────────────────────────────────────────────
863
+ ```
864
+
865
+ **If `gaps_found`:**
866
+ ```
867
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
868
+ PLAN-BUILD-RUN ► PHASE {N} GAPS FOUND ⚠
869
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
870
+
871
+ **Phase {N}: {Name}**
872
+
873
+ Score: {X}/{Y} must-haves verified
874
+ Report: .planning/phases/{phase_dir}/VERIFICATION.md
875
+
876
+ ### What's Missing
877
+
878
+ {Extract gap summaries from VERIFICATION.md}
879
+
880
+ ───────────────────────────────────────────────────────────────
881
+
882
+ ## ▶ Next Up
883
+
884
+ **Plan gap closure** — create additional plans to complete the phase
885
+
886
+ `/pbr:plan {N} --gaps`
887
+
888
+ <sub>`/clear` first → fresh context window</sub>
889
+
890
+ ───────────────────────────────────────────────────────────────
891
+
892
+ **Also available:**
893
+ - `cat .planning/phases/{phase_dir}/VERIFICATION.md` — see full report
894
+ - `/pbr:review {N}` — manual testing before planning
895
+
896
+ ───────────────────────────────────────────────────────────────
897
+ ```
898
+
899
+ **8g. Display USER-SETUP.md (conditional):**
900
+
901
+ Check if `.planning/phases/{NN}-{slug}/USER-SETUP.md` exists. If it does:
902
+
903
+ ```
904
+ Setup Required:
905
+ This phase introduced external setup requirements. See the details below
906
+ or read .planning/phases/{NN}-{slug}/USER-SETUP.md directly.
907
+
908
+ {Read and display the USER-SETUP.md content — it's typically short}
909
+ ```
910
+
911
+ This ensures the user sees setup requirements prominently instead of buried in SUMMARY files.
912
+
913
+ ---
914
+
915
+ ## Error Handling
916
+
917
+ ### Executor agent timeout
918
+ If a Task() doesn't return within a reasonable time, display:
919
+ ```
920
+ ╔══════════════════════════════════════════════════════════════╗
921
+ ║ ERROR ║
922
+ ╚══════════════════════════════════════════════════════════════╝
923
+
924
+ Executor agent timed out for Plan {id}.
925
+
926
+ **To fix:** Check `.planning/phases/{NN}-{slug}/` for partial SUMMARY.md, then retry or skip.
927
+ ```
928
+ Treat as `partial` status. Present to user: retry or skip.
929
+
930
+ For commit conventions and git workflow details, see `references/git-integration.md`.
931
+
932
+ ### Git lock conflicts
933
+ If multiple parallel executors create git lock conflicts:
934
+ - The executor agent handles retries internally (see executor agent definition)
935
+ - If lock conflicts persist, display: `⚠ Git lock conflicts detected with parallel execution. Consider reducing max_concurrent_agents to 1.`
936
+
937
+ ### Executor produces unexpected files
938
+ If SUMMARY.md shows files not listed in the plan's `files_modified`:
939
+ - Note the discrepancy in the wave results
940
+ - Do not fail — the executor's deviation rules may have required additional files
941
+ - Flag for review: "Plan {id} modified files not in the plan: {list}"
942
+
943
+ ### Build on wrong branch
944
+ If `git.branching_strategy` is `phase` but we're not on the phase branch:
945
+ - Create the phase branch: `git checkout -b plan-build-run/phase-{NN}-{name}`
946
+ - Proceed with build on the new branch
947
+
948
+ ---
949
+
950
+ ## Files Created/Modified by /pbr:build
951
+
952
+ | File | Purpose | When |
953
+ |------|---------|------|
954
+ | `.planning/phases/{NN}-{slug}/.checkpoint-manifest.json` | Execution progress for crash recovery | Step 5b, updated each wave |
955
+ | `.planning/phases/{NN}-{slug}/SUMMARY-{plan_id}.md` | Per-plan build summary | Step 6 (each executor) |
956
+ | `.planning/phases/{NN}-{slug}/USER-SETUP.md` | External setup requirements | Step 6 (executor, if needed) |
957
+ | `.planning/phases/{NN}-{slug}/VERIFICATION.md` | Phase verification report | Step 7 |
958
+ | `.planning/codebase/*.md` | Incremental codebase map updates | Step 8-pre-c (if codebase/ exists) |
959
+ | `.planning/ROADMAP.md` | Plans Complete + Status → `built` or `partial` | Step 8a |
960
+ | `.planning/STATE.md` | Updated progress | Steps 6f, 8b |
961
+ | `.planning/.auto-next` | Next command signal (if auto_continue enabled) | Step 8e |
962
+ | Project source files | Actual code | Step 6 (executors) |