@sienklogic/plan-build-run 2.54.0 → 2.55.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 (127) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/plugins/codex-pbr/agents/audit.md +223 -0
  4. package/plugins/codex-pbr/agents/codebase-mapper.md +196 -0
  5. package/plugins/codex-pbr/agents/debugger.md +245 -0
  6. package/plugins/codex-pbr/agents/dev-sync.md +142 -0
  7. package/plugins/codex-pbr/agents/executor.md +429 -0
  8. package/plugins/codex-pbr/agents/general.md +131 -0
  9. package/plugins/codex-pbr/agents/integration-checker.md +178 -0
  10. package/plugins/codex-pbr/agents/plan-checker.md +253 -0
  11. package/plugins/codex-pbr/agents/planner.md +343 -0
  12. package/plugins/codex-pbr/agents/researcher.md +253 -0
  13. package/plugins/codex-pbr/agents/synthesizer.md +183 -0
  14. package/plugins/codex-pbr/agents/verifier.md +352 -0
  15. package/plugins/codex-pbr/commands/audit.md +5 -0
  16. package/plugins/codex-pbr/commands/begin.md +5 -0
  17. package/plugins/codex-pbr/commands/build.md +5 -0
  18. package/plugins/codex-pbr/commands/config.md +5 -0
  19. package/plugins/codex-pbr/commands/continue.md +5 -0
  20. package/plugins/codex-pbr/commands/dashboard.md +5 -0
  21. package/plugins/codex-pbr/commands/debug.md +5 -0
  22. package/plugins/codex-pbr/commands/discuss.md +5 -0
  23. package/plugins/codex-pbr/commands/do.md +5 -0
  24. package/plugins/codex-pbr/commands/explore.md +5 -0
  25. package/plugins/codex-pbr/commands/health.md +5 -0
  26. package/plugins/codex-pbr/commands/help.md +5 -0
  27. package/plugins/codex-pbr/commands/import.md +5 -0
  28. package/plugins/codex-pbr/commands/milestone.md +5 -0
  29. package/plugins/codex-pbr/commands/note.md +5 -0
  30. package/plugins/codex-pbr/commands/pause.md +5 -0
  31. package/plugins/codex-pbr/commands/plan.md +5 -0
  32. package/plugins/codex-pbr/commands/quick.md +5 -0
  33. package/plugins/codex-pbr/commands/resume.md +5 -0
  34. package/plugins/codex-pbr/commands/review.md +5 -0
  35. package/plugins/codex-pbr/commands/scan.md +5 -0
  36. package/plugins/codex-pbr/commands/setup.md +5 -0
  37. package/plugins/codex-pbr/commands/status.md +5 -0
  38. package/plugins/codex-pbr/commands/statusline.md +5 -0
  39. package/plugins/codex-pbr/commands/test.md +5 -0
  40. package/plugins/codex-pbr/commands/todo.md +5 -0
  41. package/plugins/codex-pbr/commands/undo.md +5 -0
  42. package/plugins/codex-pbr/references/agent-contracts.md +324 -0
  43. package/plugins/codex-pbr/references/agent-teams.md +54 -0
  44. package/plugins/codex-pbr/references/common-bug-patterns.md +13 -0
  45. package/plugins/codex-pbr/references/config-reference.md +552 -0
  46. package/plugins/codex-pbr/references/continuation-format.md +212 -0
  47. package/plugins/codex-pbr/references/deviation-rules.md +112 -0
  48. package/plugins/codex-pbr/references/git-integration.md +256 -0
  49. package/plugins/codex-pbr/references/integration-patterns.md +117 -0
  50. package/plugins/codex-pbr/references/model-profiles.md +99 -0
  51. package/plugins/codex-pbr/references/model-selection.md +31 -0
  52. package/plugins/codex-pbr/references/pbr-tools-cli.md +400 -0
  53. package/plugins/codex-pbr/references/plan-authoring.md +246 -0
  54. package/plugins/codex-pbr/references/plan-format.md +313 -0
  55. package/plugins/codex-pbr/references/questioning.md +235 -0
  56. package/plugins/codex-pbr/references/reading-verification.md +127 -0
  57. package/plugins/codex-pbr/references/signal-files.md +41 -0
  58. package/plugins/codex-pbr/references/stub-patterns.md +160 -0
  59. package/plugins/codex-pbr/references/ui-formatting.md +444 -0
  60. package/plugins/codex-pbr/references/wave-execution.md +95 -0
  61. package/plugins/codex-pbr/skills/audit/SKILL.md +346 -0
  62. package/plugins/codex-pbr/skills/begin/SKILL.md +800 -0
  63. package/plugins/codex-pbr/skills/build/SKILL.md +958 -0
  64. package/plugins/codex-pbr/skills/config/SKILL.md +267 -0
  65. package/plugins/codex-pbr/skills/continue/SKILL.md +172 -0
  66. package/plugins/codex-pbr/skills/dashboard/SKILL.md +44 -0
  67. package/plugins/codex-pbr/skills/debug/SKILL.md +530 -0
  68. package/plugins/codex-pbr/skills/discuss/SKILL.md +355 -0
  69. package/plugins/codex-pbr/skills/do/SKILL.md +68 -0
  70. package/plugins/codex-pbr/skills/explore/SKILL.md +407 -0
  71. package/plugins/codex-pbr/skills/health/SKILL.md +300 -0
  72. package/plugins/codex-pbr/skills/help/SKILL.md +229 -0
  73. package/plugins/codex-pbr/skills/import/SKILL.md +538 -0
  74. package/plugins/codex-pbr/skills/milestone/SKILL.md +620 -0
  75. package/plugins/codex-pbr/skills/note/SKILL.md +215 -0
  76. package/plugins/codex-pbr/skills/pause/SKILL.md +258 -0
  77. package/plugins/codex-pbr/skills/plan/SKILL.md +650 -0
  78. package/plugins/codex-pbr/skills/quick/SKILL.md +417 -0
  79. package/plugins/codex-pbr/skills/resume/SKILL.md +403 -0
  80. package/plugins/codex-pbr/skills/review/SKILL.md +669 -0
  81. package/plugins/codex-pbr/skills/scan/SKILL.md +325 -0
  82. package/plugins/codex-pbr/skills/setup/SKILL.md +169 -0
  83. package/plugins/codex-pbr/skills/shared/commit-planning-docs.md +35 -0
  84. package/plugins/codex-pbr/skills/shared/config-loading.md +102 -0
  85. package/plugins/codex-pbr/skills/shared/context-budget.md +77 -0
  86. package/plugins/codex-pbr/skills/shared/context-loader-task.md +86 -0
  87. package/plugins/codex-pbr/skills/shared/digest-select.md +79 -0
  88. package/plugins/codex-pbr/skills/shared/domain-probes.md +125 -0
  89. package/plugins/codex-pbr/skills/shared/error-reporting.md +59 -0
  90. package/plugins/codex-pbr/skills/shared/gate-prompts.md +388 -0
  91. package/plugins/codex-pbr/skills/shared/phase-argument-parsing.md +45 -0
  92. package/plugins/codex-pbr/skills/shared/revision-loop.md +81 -0
  93. package/plugins/codex-pbr/skills/shared/state-update.md +169 -0
  94. package/plugins/codex-pbr/skills/shared/universal-anti-patterns.md +43 -0
  95. package/plugins/codex-pbr/skills/status/SKILL.md +449 -0
  96. package/plugins/codex-pbr/skills/statusline/SKILL.md +149 -0
  97. package/plugins/codex-pbr/skills/test/SKILL.md +210 -0
  98. package/plugins/codex-pbr/skills/todo/SKILL.md +281 -0
  99. package/plugins/codex-pbr/skills/undo/SKILL.md +172 -0
  100. package/plugins/codex-pbr/templates/CONTEXT.md.tmpl +52 -0
  101. package/plugins/codex-pbr/templates/INTEGRATION-REPORT.md.tmpl +167 -0
  102. package/plugins/codex-pbr/templates/RESEARCH-SUMMARY.md.tmpl +97 -0
  103. package/plugins/codex-pbr/templates/ROADMAP.md.tmpl +47 -0
  104. package/plugins/codex-pbr/templates/SUMMARY-complex.md.tmpl +95 -0
  105. package/plugins/codex-pbr/templates/SUMMARY-minimal.md.tmpl +48 -0
  106. package/plugins/codex-pbr/templates/SUMMARY.md.tmpl +81 -0
  107. package/plugins/codex-pbr/templates/VERIFICATION-DETAIL.md.tmpl +117 -0
  108. package/plugins/codex-pbr/templates/codebase/ARCHITECTURE.md.tmpl +98 -0
  109. package/plugins/codex-pbr/templates/codebase/CONCERNS.md.tmpl +93 -0
  110. package/plugins/codex-pbr/templates/codebase/CONVENTIONS.md.tmpl +104 -0
  111. package/plugins/codex-pbr/templates/codebase/INTEGRATIONS.md.tmpl +78 -0
  112. package/plugins/codex-pbr/templates/codebase/STACK.md.tmpl +78 -0
  113. package/plugins/codex-pbr/templates/codebase/STRUCTURE.md.tmpl +80 -0
  114. package/plugins/codex-pbr/templates/codebase/TESTING.md.tmpl +107 -0
  115. package/plugins/codex-pbr/templates/continue-here.md.tmpl +73 -0
  116. package/plugins/codex-pbr/templates/pr-body.md.tmpl +22 -0
  117. package/plugins/codex-pbr/templates/prompt-partials/phase-project-context.md.tmpl +37 -0
  118. package/plugins/codex-pbr/templates/research/ARCHITECTURE.md.tmpl +124 -0
  119. package/plugins/codex-pbr/templates/research/STACK.md.tmpl +71 -0
  120. package/plugins/codex-pbr/templates/research/SUMMARY.md.tmpl +112 -0
  121. package/plugins/codex-pbr/templates/research-outputs/phase-research.md.tmpl +81 -0
  122. package/plugins/codex-pbr/templates/research-outputs/project-research.md.tmpl +99 -0
  123. package/plugins/codex-pbr/templates/research-outputs/synthesis.md.tmpl +36 -0
  124. package/plugins/copilot-pbr/plugin.json +1 -1
  125. package/plugins/cursor-pbr/.cursor-plugin/plugin.json +1 -1
  126. package/plugins/jules-pbr/AGENTS.md +600 -0
  127. package/plugins/pbr/.claude-plugin/plugin.json +1 -1
@@ -0,0 +1,650 @@
1
+ ---
2
+ name: plan
3
+ description: "Create a detailed plan for a phase. Research, plan, and verify before building."
4
+ ---
5
+
6
+ **STOP — DO NOT READ THIS FILE. You are already reading it. This prompt was injected into your context by Claude Code's plugin system. Using the Read tool on this SKILL.md file wastes ~7,600 tokens. Begin executing Step 1 immediately.**
7
+
8
+ # $pbr-plan — Phase Planning
9
+
10
+ You are the orchestrator for `$pbr-plan`. This skill creates detailed, executable plans for a specific phase. Plans are the bridge between the roadmap and actual code — they must be specific enough for an executor agent to follow mechanically. Your job is to stay lean, delegate heavy work to Task() agents, 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 subagent output — read only plan frontmatter for summaries
18
+ - **Delegate** all research and planning work to agents — the orchestrator routes, it doesn't plan
19
+
20
+ ## Step 0 — Immediate Output
21
+
22
+ **Before ANY tool calls**, display this banner:
23
+
24
+ ```
25
+ ╔══════════════════════════════════════════════════════════════╗
26
+ ║ PLAN-BUILD-RUN ► PLANNING PHASE {N} ║
27
+ ╚══════════════════════════════════════════════════════════════╝
28
+ ```
29
+
30
+ Where `{N}` is the phase number from `$ARGUMENTS`. Then proceed to Step 1.
31
+
32
+ ## Prerequisites
33
+
34
+ - `.planning/config.json` exists (run `$pbr-begin` first)
35
+ - `.planning/ROADMAP.md` exists with at least one phase
36
+ - `.planning/REQUIREMENTS.md` exists
37
+
38
+ ---
39
+
40
+ ## Argument Parsing
41
+
42
+ Parse `$ARGUMENTS` according to `skills/shared/phase-argument-parsing.md`.
43
+
44
+ ### Standard Invocation
45
+
46
+ `$pbr-plan <N>` — Plan phase N
47
+
48
+ Parse the phase number and optional flags:
49
+
50
+ | Argument | Meaning |
51
+ |----------|---------|
52
+ | `3` | Plan phase 3 |
53
+ | `3 --skip-research` | Plan phase 3, skip research step |
54
+ | `3 --assumptions` | Surface assumptions before planning phase 3 |
55
+ | `3 --gaps` | Create gap-closure plans for phase 3 (from VERIFICATION.md) |
56
+ | `3 --teams` | Plan phase 3 using specialist agent teams |
57
+ | (no number) | Use current phase from STATE.md |
58
+ | `3 --preview` | Preview what planning would produce for phase 3 without spawning agents |
59
+
60
+ ### Subcommands
61
+
62
+ | Subcommand | Meaning |
63
+ |------------|---------|
64
+ | `add` | Append a new phase to the end of the roadmap |
65
+ | `insert <N>` | Insert a new phase at position N (uses decimal numbering) |
66
+ | `remove <N>` | Remove phase N from the roadmap |
67
+
68
+ ### Freeform Text Guard — CRITICAL
69
+
70
+ **STOP. Before ANY context loading or Step 1 work**, you MUST check whether `$ARGUMENTS` looks like freeform text rather than a valid invocation. This check is non-negotiable. Valid patterns are:
71
+
72
+ - Empty (no arguments)
73
+ - A phase number: integer (`3`, `03`) or decimal (`3.1`)
74
+ - A subcommand: `add`, `insert <N>`, `remove <N>`
75
+ - A phase number followed by flags: `3 --skip-research`, `3 --assumptions`, `3 --gaps`, `3 --teams`
76
+ - The word `check` (legacy alias)
77
+
78
+ If `$ARGUMENTS` does NOT match any of these patterns — i.e., it contains freeform words that are not a recognized subcommand or flag — then **stop execution** and respond:
79
+
80
+ ```
81
+ `$pbr-plan` expects a phase number or subcommand.
82
+
83
+ Usage:
84
+ $pbr-plan <N> Plan phase N
85
+ $pbr-plan <N> --gaps Create gap-closure plans
86
+ $pbr-plan add Add a new phase
87
+ $pbr-plan insert <N> Insert a phase at position N
88
+ $pbr-plan remove <N> Remove phase N
89
+ ```
90
+
91
+ Then suggest the appropriate skill based on the text content:
92
+
93
+ | If the text looks like... | Suggest |
94
+ |---------------------------|---------|
95
+ | A task, idea, or feature request | `$pbr-todo` to capture it, or `$pbr-explore` to investigate |
96
+ | A bug or debugging request | `$pbr-debug` to investigate the issue |
97
+ | A review or quality concern | `$pbr-review` to assess existing work |
98
+ | Anything else | `$pbr-explore` for open-ended work |
99
+
100
+ Do NOT proceed with planning. The user needs to use the correct skill.
101
+
102
+ **Self-check**: If you reach Step 1 without having matched a valid argument pattern above, you have a bug. Stop immediately and show the usage block.
103
+
104
+ ---
105
+
106
+ ## Orchestration Flow: Standard Planning
107
+
108
+ Execute these steps in order for standard `$pbr-plan <N>` invocations.
109
+
110
+ ---
111
+
112
+ ### Step 1: Parse and Validate (inline)
113
+
114
+ Reference: `skills/shared/config-loading.md` for the tooling shortcut (`state load`, `plan-index`, `phase-info`) and config field reference.
115
+
116
+ 1. Parse `$ARGUMENTS` for phase number and flags
117
+ 2. Read `.planning/config.json` for settings (see config-loading.md for field reference)
118
+ **CRITICAL (hook-enforced): Write .active-skill NOW.** Write the text "plan" to `.planning/.active-skill` using the Write tool.
119
+ 3. Resolve depth profile: run `node ${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.
120
+ 4. Validate:
121
+ - Phase exists in ROADMAP.md
122
+ - Phase directory exists at `.planning/phases/{NN}-{slug}/`
123
+ - Phase does not already have PLAN.md files (unless user confirms re-planning)
124
+ 5. If no phase number given, read current phase from `.planning/STATE.md`
125
+ 6. **CONTEXT.md existence check**: If the phase is non-trivial (has 2+ requirements or success criteria), check whether a CONTEXT.md exists at EITHER `.planning/CONTEXT.md` (project-level) OR `.planning/phases/{NN}-{slug}/CONTEXT.md` (phase-level). If NEITHER exists, warn: "Phase {N} has no CONTEXT.md. Consider running `$pbr-discuss {N}` first to capture your preferences. Continue anyway?" If user says no, stop. If yes, continue. If at least one exists, proceed without warning.
126
+
127
+ #### --preview mode
128
+
129
+ If `--preview` is present in `$ARGUMENTS`:
130
+
131
+ 1. Detect the `--preview` flag and extract the phase number.
132
+ 2. Render the following dry-run banner:
133
+
134
+ ```
135
+ ╔══════════════════════════════════════════════════════════════╗
136
+ ║ DRY RUN — $pbr-plan {N} --preview ║
137
+ ║ No researchers or planners will be spawned ║
138
+ ╚══════════════════════════════════════════════════════════════╝
139
+ ```
140
+
141
+ 3. Show the 5 steps that would occur:
142
+
143
+ 1. Parse ROADMAP.md for phase {N} goal, dependencies, and requirements
144
+ 2. Spawn researcher agents to investigate codebase and gather context
145
+ 3. Spawn planner agent to write PLAN files based on research
146
+ 4. Run plan-checker to validate structure and completeness
147
+ 5. Present plans for your approval before building
148
+
149
+ 4. Show estimated agent spawns: ~2-4 agents (1-2 researchers + 1 planner + 1 plan-checker)
150
+ 5. Show output location: `.planning/phases/{NN}-{slug}/PLAN-NN.md`
151
+
152
+ 6. **STOP** — do not proceed to Step 2.
153
+
154
+ ---
155
+
156
+ **If phase already has plans:**
157
+ - Use AskUserQuestion (pattern: yes-no from `skills/shared/gate-prompts.md`):
158
+ question: "Phase {N} already has plans. Re-plan from scratch?"
159
+ header: "Re-plan?"
160
+ options:
161
+ - label: "Yes" description: "Delete existing plans and create new ones"
162
+ - label: "No" description: "Keep existing plans unchanged"
163
+ - If "Yes": delete existing PLAN.md files in the phase directory
164
+ - If "No" or "Other": stop
165
+
166
+ ---
167
+
168
+ ### Step 2: Load Context (inline)
169
+
170
+ **Init-first pattern**: When spawning agents, pass the output of `node plugins/pbr/scripts/pbr-tools.js init plan-phase {N}` as context rather than having the agent read multiple files separately. This reduces file reads and prevents context-loading failures.
171
+
172
+ Read context file PATHS and metadata. Build lean context bundles for subagent prompts — include paths and one-line descriptions, NOT full file bodies. Agents have the Read tool and will pull file contents on-demand.
173
+
174
+ ```
175
+ 1. Read .planning/ROADMAP.md — extract current phase goal, dependencies, requirements
176
+ 2. Read .planning/REQUIREMENTS.md — extract requirements mapped to this phase
177
+ 3. Read .planning/CONTEXT.md (if exists) — extract only the `## Decision Summary` section (everything from `## Decision Summary` to the next `##` heading). If no Decision Summary section exists (legacy CONTEXT.md), fall back to extracting the full `## Decisions (LOCKED...)` and `## Deferred Ideas` sections.
178
+ 4. Read .planning/phases/{NN}-{slug}/CONTEXT.md (if exists) — extract only the `## Decision Summary` section. Fall back to full locked decisions + deferred sections if no Decision Summary exists.
179
+ 5. Read .planning/config.json — extract feature flags, depth, model settings
180
+ 6. List prior SUMMARY.md file paths and extract frontmatter metadata only (status, provides, key_files). Do NOT read full SUMMARY bodies — agents pull these on-demand via Read tool.
181
+ 7. Read .planning/research/SUMMARY.md (if exists) — extract research findings
182
+ ```
183
+
184
+ **Digest-select depth for prior SUMMARYs (Step 6):**
185
+
186
+ Reference: `skills/shared/digest-select.md` for the full depth rules and examples. In short: direct dependencies get frontmatter + key decisions, transitive get frontmatter only, 2+ back get skipped.
187
+
188
+ Collect all of this into a context bundle that will be passed to agents.
189
+
190
+ ---
191
+
192
+ ### Step 3: Assumption Surfacing (inline, if `--assumptions` flag)
193
+
194
+ **IMPORTANT**: This step is FREE (no agents). It happens entirely inline.
195
+
196
+ Before spawning any agents, present 4 assumptions to the user — one each for: approach (how the phase will be implemented), key technology, architecture, and scope boundary. For each, ask the user to confirm or correct. Record corrections as new CONTEXT.md locked decisions. After all assumptions are confirmed/corrected, continue to Step 4.
197
+
198
+ ---
199
+
200
+ ### Step 4: Phase Research (delegated, conditional)
201
+
202
+ **Skip this step if ANY of these are true:**
203
+ - `--skip-research` flag is set
204
+ - `--gaps` flag is set
205
+ - Depth profile has `features.research_phase: false`
206
+
207
+ To check: run `node ${PLUGIN_ROOT}/scripts/pbr-tools.js config resolve-depth` and read `profile["features.research_phase"]`. This replaces checking `features.research_phase` and `depth` separately -- the depth profile already incorporates both.
208
+
209
+ **Conditional research (standard/balanced mode):** When the profile has `features.research_phase: true`, also check whether `.planning/codebase/` or `.planning/research/` already contains relevant context for this phase. If substantial context exists (>3 files in codebase/ or a RESEARCH.md mentioning this phase's technologies), skip research and note: "Skipping research -- existing context found in {directory}." This implements the balanced mode's "conditional research" behavior.
210
+
211
+ **If research is needed:**
212
+
213
+ Display to the user: `◐ Spawning researcher...`
214
+
215
+ Spawn a researcher Task():
216
+
217
+ ```
218
+ Task({
219
+ subagent_type: "pbr:researcher",
220
+ prompt: <phase research prompt>
221
+ })
222
+
223
+ NOTE: The pbr:researcher subagent type auto-loads the agent definition. Do NOT inline it.
224
+ ```
225
+
226
+ **Path resolution**: Before constructing the agent prompt, resolve `${PLUGIN_ROOT}` to its absolute path. Do not pass the variable literally in prompts — Task() contexts may not expand it. Use the resolved absolute path for any pbr-tools.js or template references included in the prompt.
227
+
228
+ #### Phase Research Prompt Template
229
+
230
+ Read `skills/plan/templates/researcher-prompt.md.tmpl` and use it as the prompt template for spawning the researcher agent. Fill in the placeholders with phase-specific context:
231
+ - `{NN}` - phase number (zero-padded)
232
+ - `{phase name}` - phase name from roadmap
233
+ - `{goal from roadmap}` - phase goal statement
234
+ - `{REQ-IDs mapped to this phase}` - requirement IDs
235
+ - `{dependencies from roadmap}` - dependency list
236
+ - Fill `<project_context>` and `<prior_work>` blocks per the shared partial (`templates/prompt-partials/phase-project-context.md.tmpl`): Decision Summary for context, manifest table for prior work
237
+
238
+ **Prepend this block to the researcher prompt before sending:**
239
+ ```
240
+ <files_to_read>
241
+ CRITICAL (no hook): Read these files BEFORE any other action:
242
+ 1. .planning/ROADMAP.md — phase goals, dependencies, and structure
243
+ 2. .planning/REQUIREMENTS.md — scoped requirements for this phase (if exists)
244
+ </files_to_read>
245
+ ```
246
+
247
+ Wait for the researcher to complete before proceeding.
248
+
249
+ After the researcher completes, check the Task() output for a completion marker:
250
+ - If `## RESEARCH COMPLETE` is present: proceed to planner
251
+ - If `## RESEARCH BLOCKED` is present: warn the user that research could not complete, ask if they want to proceed with limited context or stop
252
+ - If neither marker is present: warn that researcher may not have completed successfully, but proceed
253
+
254
+ ---
255
+
256
+ ### Step 4.5: Pre-Planner Briefing (delegated)
257
+
258
+ **CRITICAL (no hook): Run pre-planner briefing before spawning the planner. Do NOT skip this step.**
259
+
260
+ Consolidate seed scanning and deferred idea surfacing into a single lightweight Task():
261
+
262
+ ```
263
+ Task({
264
+ subagent_type: "pbr:general",
265
+ model: "haiku",
266
+ prompt: "Pre-planner briefing for Phase {NN} ({phase-slug}).
267
+
268
+ 1. SEED SCANNING:
269
+ Run: `node ${PLUGIN_ROOT}/scripts/pbr-tools.js seeds match {phase-slug} {phase-number}`
270
+ If `matched` is non-empty, output a ## Seeds section listing each seed name, description, and content.
271
+ If empty, output: ## Seeds\nNo matching seeds found.
272
+
273
+ 2. DEFERRED IDEAS:
274
+ Read `.planning/CONTEXT.md`. If it has a section containing 'deferred' or 'ideas' (case-insensitive),
275
+ extract items that mention Phase {NN} or keywords matching the phase slug.
276
+ If relevant items found, output a ## Deferred Ideas section listing them.
277
+ If none found, output: ## Deferred Ideas\nNo relevant deferred items.
278
+
279
+ Output format: Return both sections as markdown. End with ## BRIEFING COMPLETE."
280
+ })
281
+ ```
282
+
283
+ After the Task() completes:
284
+ - If `## Seeds` section contains matches:
285
+ - If `gates.confirm_seeds` is `true` in config: present them to the user via AskUserQuestion (pattern: yes-no-pick from `skills/shared/gate-prompts.md`):
286
+ question: "Include these {N} seeds in planning?"
287
+ header: "Seeds?"
288
+ options:
289
+ - label: "Yes, all" description: "Include all {N} matching seeds"
290
+ - label: "Let me pick" description: "Choose which seeds to include"
291
+ - label: "No" description: "Proceed without seeds"
292
+ - If "Yes, all": include seed content in planner context
293
+ - If "Let me pick": present individual seeds for selection
294
+ - If "No": proceed without seeds
295
+ - If `gates.confirm_seeds` is `false` (default): automatically include all matching seeds in planner context without prompting. Log: "Including {N} seeds automatically (gates.confirm_seeds=false)."
296
+
297
+ - If `## Deferred Ideas` section has items:
298
+ - If `gates.confirm_deferred` is `true` in config: present via AskUserQuestion (pattern: yes-no from `skills/shared/gate-prompts.md`):
299
+ question: "Include these deferred ideas in planning context?"
300
+ - If "Yes": append to planner context under `Deferred ideas to consider:`
301
+ - If "No": proceed without changes
302
+ - If `gates.confirm_deferred` is `false` (default): automatically append deferred ideas to planner context without prompting. Log: "Including deferred ideas automatically (gates.confirm_deferred=false)."
303
+
304
+ - If both sections are empty: proceed silently to Step 5 (no AskUserQuestion needed)
305
+
306
+ ---
307
+
308
+ ### Step 5: Planning (delegated)
309
+
310
+ #### Team Mode (--teams)
311
+
312
+ If `--teams` flag is set OR `config.parallelization.use_teams` is true, spawn 3 parallel planner agents (architect, security, test) then a synthesizer to merge their outputs. See `references/agent-teams.md` for agent role definitions, output paths (`.planning/phases/{NN}-{slug}/team/`), and prompt content for each role.
313
+
314
+ If `--teams` is NOT set and `config.parallelization.use_teams` is false or unset, proceed with the single-planner flow below.
315
+
316
+ #### Single-Planner Flow (default)
317
+
318
+ **Learnings injection (opt-in):** Check for planning and estimation learnings before spawning the planner:
319
+
320
+ ```bash
321
+ node {resolved_plugin_root}/scripts/pbr-tools.js learnings query --tags "estimation,planning,process" 2>/dev/null
322
+ ```
323
+
324
+ If non-empty JSON array returned:
325
+
326
+ - Write to temp file and note as `{learnings_temp_path}`:
327
+
328
+ ```bash
329
+ node {resolved_plugin_root}/scripts/pbr-tools.js learnings query --tags "estimation,planning,process" > /tmp/pbr-learnings-$$.md
330
+ ```
331
+
332
+ - Add as an additional `files_to_read` item in the planner prompt below
333
+
334
+ If no learnings or command fails: omit.
335
+
336
+ Display to the user: `◐ Spawning planner...`
337
+
338
+ Spawn the planner Task() with all context inlined:
339
+
340
+ ```
341
+ Task({
342
+ subagent_type: "pbr:planner",
343
+ prompt: <planning prompt>
344
+ })
345
+
346
+ NOTE: The pbr:planner subagent type auto-loads the agent definition.
347
+
348
+ After planner completes, check for completion markers: `## PLANNING COMPLETE`, `## PLANNING FAILED`, or `## PLANNING INCONCLUSIVE`. Route accordingly. Do NOT inline it.
349
+ ```
350
+
351
+ **Path resolution**: Before constructing the agent prompt, resolve `${PLUGIN_ROOT}` to its absolute path. Do not pass the variable literally in prompts — Task() contexts may not expand it. Use the resolved absolute path for any pbr-tools.js or template references included in the prompt.
352
+
353
+ #### Planning Prompt Template
354
+
355
+ Read `skills/plan/templates/planner-prompt.md.tmpl` and use it as the prompt template for spawning the planner agent. Fill in all placeholder blocks with phase-specific context:
356
+
357
+ - `<phase_context>` - phase number, directory, goal, requirements, dependencies, success criteria
358
+ - `<project_context>` - locked decisions, user constraints, deferred ideas, phase-specific decisions
359
+ - `<prior_work>` - manifest table of preceding phase SUMMARY.md file paths with status and one-line exports (NOT full bodies)
360
+ - `<research>` - file path to RESEARCH.md if it exists (NOT inlined content)
361
+ - `<config>` - max tasks, parallelization, TDD mode from config.json
362
+ - `<planning_instructions>` - phase-specific planning rules and output path
363
+
364
+ **Prepend this block to the planner prompt before sending:**
365
+
366
+ ```
367
+ <files_to_read>
368
+ CRITICAL (no hook): Read these files BEFORE any other action:
369
+ 1. .planning/CONTEXT.md — locked decisions and constraints (if exists)
370
+ 2. .planning/ROADMAP.md — phase goals, dependencies, and structure
371
+ 3. .planning/phases/{NN}-{slug}/RESEARCH.md — research findings (if exists)
372
+ {if learnings_temp_path exists}4. {learnings_temp_path} — cross-project learnings (estimation and planning patterns from past PBR projects){/if}
373
+ </files_to_read>
374
+ ```
375
+
376
+ If `{learnings_temp_path}` was produced in the learnings injection step above, replace `{if...}{/if}` with the actual line. If no learnings were found, omit item 4 entirely.
377
+
378
+ Wait for the planner to complete.
379
+
380
+ After the planner returns, read the plan files it created to extract counts. Display a completion summary:
381
+
382
+ ```
383
+ ✓ Planner created {N} plan(s) across {M} wave(s)
384
+ ```
385
+
386
+ Where `{N}` is the number of PLAN.md files written and `{M}` is the number of distinct wave values across those plans (from frontmatter).
387
+
388
+ ### Step 5b: Spot-Check Planner Output
389
+
390
+ CRITICAL (no hook): Verify planner output before proceeding.
391
+
392
+ 1. **PLAN files exist**: Check `.planning/phases/{NN}-{slug}/PLAN-*.md` files exist on disk
393
+ 2. **Valid frontmatter**: Read first 20 lines of each PLAN file — verify `depends_on`, `files_modified`, `must_haves` fields present
394
+ 3. **Task structure**: Verify at least one `<task>` block exists in each plan file
395
+ 4. **Plan count matches**: Number of PLAN files matches what the planner reported
396
+
397
+ If ANY spot-check fails, present the user with options: **Retry** / **Continue anyway** / **Abort**
398
+
399
+ ---
400
+
401
+ ### Step 6: Plan Validation (delegated, conditional)
402
+
403
+ **Skip this step if:**
404
+ - Depth profile has `features.plan_checking: false`
405
+
406
+ To check: use the resolved depth profile from Step 1. The profile consolidates the depth setting and any user overrides into a single boolean.
407
+
408
+ **If validation is enabled:**
409
+
410
+ Display to the user: `◐ Spawning plan checker...`
411
+
412
+ Spawn the plan checker Task():
413
+
414
+ ```
415
+ Task({
416
+ subagent_type: "pbr:plan-checker",
417
+ prompt: <checker prompt>
418
+ })
419
+
420
+ NOTE: The pbr:plan-checker subagent type auto-loads the agent definition. Do NOT inline it.
421
+ ```
422
+
423
+ **Path resolution**: Before constructing the agent prompt, resolve `${PLUGIN_ROOT}` to its absolute path. Do not pass the variable literally in prompts — Task() contexts may not expand it. Use the resolved absolute path for any pbr-tools.js or template references included in the prompt.
424
+
425
+ #### Checker Prompt Template
426
+
427
+ Read `skills/plan/templates/checker-prompt.md.tmpl` and use it as the prompt template for spawning the plan checker agent. Fill in the placeholders:
428
+ - `<plans_to_check>` - manifest table of PLAN.md file paths (checker reads each via Read tool)
429
+ - `<phase_context>` - phase goal and requirement IDs
430
+ - `<context>` - file paths to project-level and phase-level CONTEXT.md files (checker reads via Read tool)
431
+
432
+ **Prepend this block to the checker prompt before sending:**
433
+ ```
434
+ <files_to_read>
435
+ CRITICAL (no hook): Read these files BEFORE any other action:
436
+ 1. .planning/phases/{NN}-{slug}/PLAN-*.md — plan files to validate
437
+ 2. .planning/CONTEXT.md — locked decisions to check against (if exists)
438
+ </files_to_read>
439
+ ```
440
+
441
+ **Process checker results:**
442
+
443
+ After the plan checker returns, display its result:
444
+
445
+ - If `VERIFICATION PASSED`: display `✓ Plan checker: all plans passed` and proceed to Step 8
446
+ - If issues found: display `⚠ Plan checker found {N} issue(s) — entering revision loop` and proceed to Step 7
447
+
448
+ ---
449
+
450
+ ### Step 7: Revision Loop (max 3 iterations)
451
+
452
+ Reference: `skills/shared/revision-loop.md` for the full Check-Revise-Escalate pattern.
453
+
454
+ Follow the revision loop pattern with:
455
+ - **Producer**: planner (re-spawned with `skills/plan/templates/revision-prompt.md.tmpl`)
456
+ - **Checker**: plan-checker (back to Step 6)
457
+ - **Escalation**: present issues to user, offer "Proceed anyway" or "Adjust approach" (re-enter Step 5)
458
+
459
+ ---
460
+
461
+ ### Step 8: User Approval (inline, conditional)
462
+
463
+ **Skip if:**
464
+ - `gates.confirm_plan` is `false` in config
465
+ - `mode` is `autonomous` in config
466
+
467
+ **If approval is needed:**
468
+
469
+ Present a summary of all plans to the user. For each plan include: plan name, wave, task count, must-haves, files_modified. For each task include the task name. Add a wave execution order summary (Wave 1: Plan 01, 02 (parallel), Wave 2: Plan 03, etc.).
470
+
471
+ Use AskUserQuestion (pattern: approve-revise-abort from `skills/shared/gate-prompts.md`):
472
+ question: "Approve these {count} plans for Phase {N}?"
473
+ header: "Approve?"
474
+ options:
475
+ - label: "Approve" description: "Proceed to build phase"
476
+ - label: "Request changes" description: "Discuss adjustments before proceeding"
477
+ - label: "Abort" description: "Cancel planning for this phase"
478
+
479
+ **If user selects 'Request changes' or 'Other':**
480
+ - Discuss what needs to change
481
+ - Re-enter Step 5 with updated context/constraints
482
+ - Or make small inline edits to plan files directly
483
+
484
+ **If user selects 'Approve':**
485
+ - **CONTEXT.md compliance reporting**: If `.planning/CONTEXT.md` exists, compare all locked decisions against the generated plans. Print: "CONTEXT.md compliance: {M}/{N} locked decisions mapped to tasks" where M = locked decisions that are reflected in at least one task, N = total locked decisions. If any locked decisions are unmapped, list them as warnings.
486
+ - **Dependency fingerprinting**: For each dependency phase (phases that this phase depends on, per ROADMAP.md):
487
+ 1. Find all SUMMARY.md files in the dependency phase directory
488
+ 2. Compute a fingerprint string for each: `"len:{bytes}-mod:{mtime}"` and add as a `dependency_fingerprints` map in each plan's YAML frontmatter — this allows the build skill to detect stale plans if dependencies were rebuilt.
489
+ - **Update ROADMAP.md Progress table** (REQUIRED — do this BEFORE updating STATE.md):
490
+
491
+ **Tooling shortcut**: Use the CLI for atomic updates:
492
+ ```bash
493
+ node ${PLUGIN_ROOT}/scripts/pbr-tools.js roadmap update-plans {phase} 0 {N}
494
+ node ${PLUGIN_ROOT}/scripts/pbr-tools.js roadmap update-status {phase} planned
495
+ node ${PLUGIN_ROOT}/scripts/pbr-tools.js state update status planned
496
+ node ${PLUGIN_ROOT}/scripts/pbr-tools.js state update last_activity now
497
+ ```
498
+
499
+ 1. Open `.planning/ROADMAP.md`
500
+ 2. Find the `## Progress` table
501
+ 3. Locate the row matching this phase number
502
+ 4. Update the `Plans Complete` column to `0/{N}` where N = number of plan files just created
503
+ 5. Update the `Status` column to `planned`
504
+ 6. Save the file — do NOT skip this step
505
+ - Update STATE.md via CLI **(CRITICAL (no hook) — update BOTH frontmatter AND body)**: set `status: "planned"`, `plans_total`, `last_command` in frontmatter AND update `Status:`, `Plan:` lines in body `## Current Position`
506
+
507
+ **Tooling shortcut**: `node ${PLUGIN_ROOT}/scripts/pbr-tools.js state patch '{"status":"planned","last_command":"$pbr-plan {N}"}'`
508
+ - **If `features.auto_advance` is `true` AND `mode` is `autonomous`:** Chain directly to build: `Skill({ skill: "pbr:build", args: "{N}" })`. This continues the build→review→plan→build cycle automatically.
509
+ - **Otherwise:** Suggest next action: `$pbr-build {N}`
510
+
511
+ ---
512
+
513
+ ## Orchestration Flow: Subcommands
514
+
515
+ ### Subcommand: `add`
516
+
517
+ **CRITICAL (hook-enforced): Write .active-skill NOW.** Write the text "plan" to `.planning/.active-skill` using the Write tool.
518
+
519
+ 1. Read `.planning/ROADMAP.md`
520
+ 2. Calculate next phase number (last phase + 1)
521
+ 3. Ask user: "What's the goal for this new phase?"
522
+ 4. Ask user: "What requirements does it address?" (show available unassigned REQ-IDs)
523
+ 5. Ask user: "What phases does it depend on?"
524
+ 6. Append phase to ROADMAP.md
525
+ 7. Create phase directory: `.planning/phases/{NN}-{slug}/`
526
+ 8. Update STATE.md if needed
527
+ 9. Suggest: `$pbr-plan {N}` to plan the new phase
528
+ 10. Delete `.planning/.active-skill` if it exists.
529
+
530
+ ### Subcommand: `insert <N>`
531
+
532
+ Reference: `skills/plan/decimal-phase-calc.md` for decimal numbering rules.
533
+
534
+ **CRITICAL (hook-enforced): Write .active-skill NOW.** Write the text "plan" to `.planning/.active-skill` using the Write tool.
535
+
536
+ 1. Read `.planning/ROADMAP.md`
537
+ 2. Calculate decimal phase number:
538
+ - If inserting at position 3: becomes 3.1
539
+ - If 3.1 already exists: becomes 3.2
540
+ - Etc. (see decimal-phase-calc.md)
541
+ 3. Ask user for phase goal, requirements, dependencies
542
+ 4. Insert phase into ROADMAP.md at the correct position
543
+ 5. Create phase directory: `.planning/phases/{NN.M}-{slug}/`
544
+ 6. Update dependencies of subsequent phases if affected
545
+ 7. Suggest: `$pbr-plan {N.M}` to plan the new phase
546
+ 8. Delete `.planning/.active-skill` if it exists.
547
+
548
+ ### Subcommand: `remove <N>`
549
+
550
+ 1. Read `.planning/ROADMAP.md`
551
+ 2. Validate:
552
+ - Phase must exist
553
+ - Phase must be in `pending` or `not started` status (cannot remove completed/in-progress phases)
554
+ - No other phases depend on this phase (or user confirms breaking dependencies)
555
+ 3. **CRITICAL (hook-enforced): Write .active-skill NOW.** Write the text "plan" to `.planning/.active-skill` using the Write tool.
556
+ 4. Confirm with user: "Remove Phase {N}: {name}? This will delete the phase directory and renumber subsequent phases."
557
+ 5. If confirmed:
558
+ - Delete `.planning/phases/{NN}-{slug}/` directory
559
+ - Remove phase from ROADMAP.md
560
+ - Renumber subsequent phases (N+1 becomes N, etc.)
561
+ - Update all `depends_on` references in ROADMAP.md
562
+ - Update STATE.md if needed
563
+ 6. Delete `.planning/.active-skill` if it exists.
564
+
565
+ ---
566
+
567
+ ## Orchestration Flow: Gap Closure (`--gaps`)
568
+
569
+ When invoked with `--gaps`:
570
+
571
+ 1. Read `.planning/phases/{NN}-{slug}/VERIFICATION.md`
572
+ - If no VERIFICATION.md exists: tell user "No verification report found. Run `$pbr-review {N}` first."
573
+ 2. Extract all gaps from the verification report
574
+ 3. Spawn planner Task() in Gap Closure mode:
575
+
576
+ Read `skills/plan/templates/gap-closure-prompt.md.tmpl` and use it as the prompt template for the gap closure planner. Fill in the placeholders:
577
+ - `<verification_report>` - inline the FULL VERIFICATION.md content
578
+ - `<existing_plans>` - inline all existing PLAN.md files for the phase
579
+ - `<gap_closure_instructions>` - specify output path and gap_closure frontmatter flag
580
+
581
+ 4. After gap-closure plans are created:
582
+ - Run plan checker (if enabled)
583
+ - Present to user for approval
584
+ - Suggest: `$pbr-build {N} --gaps-only`
585
+
586
+ ---
587
+
588
+ ## Error Handling
589
+
590
+ ### Phase not found
591
+ If the specified phase doesn't exist in ROADMAP.md, use conversational recovery:
592
+
593
+ 1. Run: `node ${PLUGIN_ROOT}/scripts/pbr-tools.js suggest-alternatives phase-not-found {slug}`
594
+ 2. Parse the JSON response to get `available` phases and `suggestions` (closest matches).
595
+ 3. Display: "Phase '{slug}' not found. Did you mean one of these?"
596
+ - List `suggestions` (if any) as numbered options.
597
+ - Offer "Show all phases" to list `available`.
598
+ 4. Use AskUserQuestion (pattern: yes-no-pick from `skills/shared/gate-prompts.md`) to let the user pick a phase or abort.
599
+ - If user picks a valid phase slug: re-run with that slug.
600
+ - If user chooses to abort: stop cleanly with a friendly message.
601
+
602
+ ### Missing prerequisites
603
+ If REQUIREMENTS.md or ROADMAP.md don't exist, use conversational recovery:
604
+
605
+ 1. Run: `node ${PLUGIN_ROOT}/scripts/pbr-tools.js suggest-alternatives missing-prereq {phase}`
606
+ 2. Parse the JSON response to get `existing_summaries`, `missing_summaries`, and `suggested_action`.
607
+ 3. Display what is already complete and what is missing.
608
+ 4. Use AskUserQuestion to offer: "Run $pbr-build {prerequisite-phase} first, or continue anyway?"
609
+ - If user chooses to continue: proceed with planning (note missing prereqs in plan frontmatter).
610
+ - If user chooses to build first: stop and display the suggested build command.
611
+
612
+ ### Research agent fails
613
+ If the researcher Task() fails, display:
614
+ ```
615
+ ⚠ Research agent failed. Planning without phase-specific research.
616
+ This may result in less accurate plans.
617
+ ```
618
+ Continue to the planning step.
619
+
620
+ ### Planner agent fails
621
+ If the planner Task() fails, display a branded error box — see `skills/shared/error-reporting.md`, pattern: Planner agent failure.
622
+
623
+ ### Checker loops forever
624
+ After 3 revision iterations without passing, display a branded error box — see `skills/shared/error-reporting.md`, pattern: Checker loops.
625
+ Present remaining issues and ask user to decide: proceed or intervene.
626
+
627
+ ---
628
+
629
+ ## Files Created/Modified by $pbr-plan
630
+
631
+ | File | Purpose | When |
632
+ |------|---------|------|
633
+ | `.planning/phases/{NN}-{slug}/RESEARCH.md` | Phase-specific research | Step 4 |
634
+ | `.planning/phases/{NN}-{slug}/PLAN-{NN}.md` | Executable plan files | Step 5 |
635
+ | `.planning/CONTEXT.md` | Updated with assumptions | Step 3 (--assumptions) |
636
+ | `.planning/ROADMAP.md` | Plans Complete + Status → `planned`; updated for add/insert/remove | Step 8, Subcommands |
637
+ | `.planning/STATE.md` | Updated with plan status | Step 8 |
638
+
639
+ ---
640
+
641
+ ## Cleanup
642
+
643
+ Delete `.planning/.active-skill` if it exists. This must happen on all paths (success, partial, and failure) before reporting results.
644
+
645
+ ## Completion
646
+
647
+ After planning completes, present:
648
+
649
+ Use the branded stage banner and next-up block from `skills/plan/templates/completion-output.md.tmpl`.
650
+ Fill in: `{N}` (phase number), `{phase-name}`, `{plan_count}`, `{plan_list_lines}` (one line per plan with wave and task count), `{wave_table_lines}` (one line per wave).