@sienklogic/plan-build-run 2.11.0 → 2.12.1

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 (1222) hide show
  1. package/CHANGELOG.md +1102 -220
  2. package/CLAUDE.md +54 -34
  3. package/LICENSE +2 -1
  4. package/README.md +261 -182
  5. package/agents/pbr-audit.md +266 -0
  6. package/agents/pbr-codebase-mapper.md +236 -0
  7. package/agents/pbr-debugger.md +312 -0
  8. package/agents/pbr-dev-sync.md +220 -0
  9. package/agents/pbr-executor.md +591 -0
  10. package/agents/pbr-general.md +191 -0
  11. package/agents/pbr-integration-checker.md +237 -0
  12. package/agents/pbr-intel-updater.md +296 -0
  13. package/agents/pbr-nyquist-auditor.md +252 -0
  14. package/agents/pbr-plan-checker.md +312 -0
  15. package/agents/pbr-planner.md +539 -0
  16. package/agents/pbr-researcher.md +314 -0
  17. package/agents/pbr-roadmapper.md +346 -0
  18. package/agents/pbr-synthesizer.md +271 -0
  19. package/agents/pbr-ui-checker.md +202 -0
  20. package/agents/pbr-ui-researcher.md +223 -0
  21. package/agents/pbr-verifier.md +495 -0
  22. package/bin/install.js +2752 -0
  23. package/commands/pbr/add-phase.md +75 -0
  24. package/commands/pbr/add-todo.md +8 -0
  25. package/commands/pbr/audit-milestone.md +8 -0
  26. package/commands/pbr/audit.md +5 -0
  27. package/commands/pbr/autonomous.md +5 -0
  28. package/commands/pbr/begin.md +5 -0
  29. package/commands/pbr/build.md +5 -0
  30. package/commands/pbr/check-todos.md +8 -0
  31. package/commands/pbr/complete-milestone.md +8 -0
  32. package/commands/pbr/config.md +5 -0
  33. package/commands/pbr/continue.md +5 -0
  34. package/commands/pbr/dashboard.md +5 -0
  35. package/commands/pbr/debug.md +5 -0
  36. package/commands/pbr/discuss-phase.md +6 -0
  37. package/commands/pbr/discuss.md +5 -0
  38. package/commands/pbr/do.md +5 -0
  39. package/commands/pbr/execute-phase.md +6 -0
  40. package/commands/pbr/explore.md +5 -0
  41. package/commands/pbr/health.md +5 -0
  42. package/commands/pbr/help.md +5 -0
  43. package/commands/pbr/import.md +5 -0
  44. package/commands/pbr/insert-phase.md +65 -0
  45. package/commands/pbr/intel.md +5 -0
  46. package/commands/pbr/join-discord.md +11 -0
  47. package/commands/pbr/list-phase-assumptions.md +69 -0
  48. package/commands/pbr/map-codebase.md +6 -0
  49. package/commands/pbr/milestone.md +5 -0
  50. package/commands/pbr/new-milestone.md +8 -0
  51. package/commands/pbr/new-project.md +6 -0
  52. package/commands/pbr/note.md +5 -0
  53. package/commands/pbr/pause-work.md +5 -0
  54. package/commands/pbr/pause.md +5 -0
  55. package/commands/pbr/plan-milestone-gaps.md +7 -0
  56. package/commands/pbr/plan-phase.md +6 -0
  57. package/commands/pbr/plan.md +5 -0
  58. package/commands/pbr/profile-user.md +5 -0
  59. package/commands/pbr/profile.md +5 -0
  60. package/commands/pbr/progress.md +6 -0
  61. package/commands/pbr/quick.md +5 -0
  62. package/commands/pbr/reapply-patches.md +47 -0
  63. package/commands/pbr/release.md +6 -0
  64. package/commands/pbr/remove-phase.md +66 -0
  65. package/commands/pbr/research-phase.md +59 -0
  66. package/commands/pbr/resume-work.md +5 -0
  67. package/commands/pbr/resume.md +5 -0
  68. package/commands/pbr/review.md +5 -0
  69. package/commands/pbr/scan.md +5 -0
  70. package/commands/pbr/session-report.md +5 -0
  71. package/commands/pbr/set-profile.md +6 -0
  72. package/commands/pbr/settings.md +5 -0
  73. package/commands/pbr/setup.md +5 -0
  74. package/commands/pbr/ship.md +5 -0
  75. package/commands/pbr/status.md +5 -0
  76. package/commands/pbr/statusline.md +5 -0
  77. package/commands/pbr/test.md +5 -0
  78. package/commands/pbr/todo.md +5 -0
  79. package/commands/pbr/ui-phase.md +5 -0
  80. package/commands/pbr/ui-review.md +5 -0
  81. package/commands/pbr/undo.md +5 -0
  82. package/commands/pbr/update.md +37 -0
  83. package/commands/pbr/validate-phase.md +5 -0
  84. package/commands/pbr/verify-work.md +6 -0
  85. package/dashboard/bin/cli.cjs +96 -0
  86. package/dashboard/bin/stop.cjs +129 -0
  87. package/dashboard/eslint.config.js +37 -0
  88. package/dashboard/index.html +20 -0
  89. package/dashboard/package.json +28 -23
  90. package/dashboard/server/index.js +136 -0
  91. package/dashboard/server/lib/frontmatter.js +92 -0
  92. package/dashboard/server/middleware/static.js +35 -0
  93. package/dashboard/server/package.json +16 -0
  94. package/dashboard/server/routes/agents.js +213 -0
  95. package/dashboard/server/routes/config.js +64 -0
  96. package/dashboard/server/routes/health.js +95 -0
  97. package/dashboard/server/routes/memory.js +107 -0
  98. package/dashboard/server/routes/planning.js +234 -0
  99. package/dashboard/server/routes/progress.js +77 -0
  100. package/dashboard/server/routes/projects.js +36 -0
  101. package/dashboard/server/routes/requirements.js +40 -0
  102. package/dashboard/server/routes/roadmap.js +69 -0
  103. package/dashboard/server/routes/status.js +25 -0
  104. package/dashboard/server/routes/telemetry.js +171 -0
  105. package/dashboard/server/services/file-watcher.js +105 -0
  106. package/dashboard/server/services/planning-reader.js +741 -0
  107. package/dashboard/server/test/cli.test.js +34 -0
  108. package/dashboard/server/test/frontmatter.test.js +104 -0
  109. package/dashboard/server/test/isolation.test.js +32 -0
  110. package/dashboard/server/test/planning-reader.test.js +151 -0
  111. package/dashboard/server/test/routes.test.js +91 -0
  112. package/dashboard/server/test/ws.test.js +81 -0
  113. package/dashboard/server/ws.js +96 -0
  114. package/dashboard/src/App.jsx +154 -0
  115. package/dashboard/src/components/charts/BudgetBars.jsx +42 -0
  116. package/dashboard/src/components/charts/ContextRadar.jsx +34 -0
  117. package/dashboard/src/components/charts/PhaseDonut.jsx +66 -0
  118. package/dashboard/src/components/charts/SuccessTrend.jsx +45 -0
  119. package/dashboard/src/components/charts/TokenChart.jsx +55 -0
  120. package/dashboard/src/components/charts/index.js +5 -0
  121. package/dashboard/src/components/config/CfgSection.jsx +93 -0
  122. package/dashboard/src/components/layout/Header.jsx +89 -0
  123. package/dashboard/src/components/layout/ProjectSwitcher.jsx +160 -0
  124. package/dashboard/src/components/layout/Sidebar.jsx +161 -0
  125. package/dashboard/src/components/ui/AutoModeBanner.jsx +138 -0
  126. package/dashboard/src/components/ui/BackButton.jsx +27 -0
  127. package/dashboard/src/components/ui/Badge.jsx +27 -0
  128. package/dashboard/src/components/ui/Card.jsx +23 -0
  129. package/dashboard/src/components/ui/ChartTooltip.jsx +48 -0
  130. package/dashboard/src/components/ui/CheckpointBox.jsx +110 -0
  131. package/dashboard/src/components/ui/CodeBlock.jsx +27 -0
  132. package/dashboard/src/components/ui/ConfidenceBadge.jsx +20 -0
  133. package/dashboard/src/components/ui/ConfirmModal.jsx +161 -0
  134. package/dashboard/src/components/ui/ConnectionBanner.jsx +60 -0
  135. package/dashboard/src/components/ui/ErrorBoundary.jsx +106 -0
  136. package/dashboard/src/components/ui/ErrorBox.jsx +107 -0
  137. package/dashboard/src/components/ui/KeyValue.jsx +33 -0
  138. package/dashboard/src/components/ui/LoadingSkeleton.jsx +84 -0
  139. package/dashboard/src/components/ui/MetricCard.jsx +58 -0
  140. package/dashboard/src/components/ui/NextUpBlock.jsx +92 -0
  141. package/dashboard/src/components/ui/NumberInput.jsx +44 -0
  142. package/dashboard/src/components/ui/PBRBanner.jsx +47 -0
  143. package/dashboard/src/components/ui/PipelineView.jsx +130 -0
  144. package/dashboard/src/components/ui/ProgressBar.jsx +28 -0
  145. package/dashboard/src/components/ui/ProgressDisplay.jsx +47 -0
  146. package/dashboard/src/components/ui/QualityGateBadge.jsx +15 -0
  147. package/dashboard/src/components/ui/SectionTitle.jsx +35 -0
  148. package/dashboard/src/components/ui/SelectInput.jsx +45 -0
  149. package/dashboard/src/components/ui/StatusDot.jsx +51 -0
  150. package/dashboard/src/components/ui/StatusSymbol.jsx +49 -0
  151. package/dashboard/src/components/ui/TabBar.jsx +41 -0
  152. package/dashboard/src/components/ui/TextInput.jsx +42 -0
  153. package/dashboard/src/components/ui/Toast.jsx +117 -0
  154. package/dashboard/src/components/ui/Toggle.jsx +70 -0
  155. package/dashboard/src/components/ui/index.js +29 -0
  156. package/dashboard/src/hooks/useDocumentTitle.js +16 -0
  157. package/dashboard/src/hooks/useFetch.js +50 -0
  158. package/dashboard/src/hooks/useToast.jsx +43 -0
  159. package/dashboard/src/hooks/useWebSocket.js +103 -0
  160. package/dashboard/src/lib/api.js +112 -0
  161. package/dashboard/src/lib/configSchema.js +189 -0
  162. package/dashboard/src/lib/constants.js +18 -0
  163. package/dashboard/src/main.jsx +15 -0
  164. package/dashboard/src/pages/AgentsPage.jsx +191 -0
  165. package/dashboard/src/pages/ConfigPage.jsx +298 -0
  166. package/dashboard/src/pages/HooksPage.jsx +412 -0
  167. package/dashboard/src/pages/LiveFeed.jsx +274 -0
  168. package/dashboard/src/pages/MemoryPage.jsx +107 -0
  169. package/dashboard/src/pages/OnboardingPage.jsx +117 -0
  170. package/dashboard/src/pages/Overview.jsx +360 -0
  171. package/dashboard/src/pages/PhaseDetailView.jsx +216 -0
  172. package/dashboard/src/pages/PlanningPage.jsx +181 -0
  173. package/dashboard/src/pages/ProgressPage.jsx +249 -0
  174. package/dashboard/src/pages/RoadmapPage.jsx +251 -0
  175. package/dashboard/src/pages/Telemetry.jsx +113 -0
  176. package/dashboard/src/pages/planning/DecisionsTab.jsx +153 -0
  177. package/dashboard/src/pages/planning/FilesTab.jsx +420 -0
  178. package/dashboard/src/pages/planning/MilestoneDetail.jsx +319 -0
  179. package/dashboard/src/pages/planning/MilestonesTab.jsx +151 -0
  180. package/dashboard/src/pages/planning/NotesTab.jsx +251 -0
  181. package/dashboard/src/pages/planning/PhasesTab.jsx +218 -0
  182. package/dashboard/src/pages/planning/QuickTab.jsx +50 -0
  183. package/dashboard/src/pages/planning/ResearchTab.jsx +103 -0
  184. package/dashboard/src/pages/planning/TodosTab.jsx +297 -0
  185. package/dashboard/src/theme/ThemeProvider.jsx +38 -0
  186. package/dashboard/src/theme/tokens.js +17 -0
  187. package/dashboard/tests/components/ConfirmModal.test.jsx +179 -0
  188. package/dashboard/tests/components/ConnectionBanner.test.jsx +37 -0
  189. package/dashboard/tests/components/ErrorBoundary.test.jsx +59 -0
  190. package/dashboard/tests/components/LoadingSkeleton.test.jsx +46 -0
  191. package/dashboard/tests/components/ToastContainer.test.jsx +47 -0
  192. package/dashboard/tests/components/Toggle.test.jsx +61 -0
  193. package/dashboard/tests/hooks/useFetch.test.jsx +77 -0
  194. package/dashboard/tests/hooks/useToast.test.jsx +78 -0
  195. package/dashboard/tests/hooks/useWebSocket.test.jsx +128 -0
  196. package/dashboard/tests/pages/ConfigPage.test.jsx +199 -0
  197. package/dashboard/tests/pages/PlanningPage.test.jsx +119 -0
  198. package/dashboard/tests/pages/planning/FilesTab.test.jsx +198 -0
  199. package/dashboard/tests/pages/planning/NotesTab.test.jsx +178 -0
  200. package/dashboard/tests/pages/planning/TodosTab.test.jsx +188 -0
  201. package/dashboard/tests/performance.test.jsx +46 -0
  202. package/dashboard/tests/routes/config.test.js +98 -0
  203. package/dashboard/tests/routes/health.test.js +40 -0
  204. package/dashboard/tests/routes/planning.test.js +112 -0
  205. package/dashboard/tests/routes/roadmap.test.js +91 -0
  206. package/dashboard/tests/routes/status.test.js +131 -0
  207. package/dashboard/tests/server/planning-reader.test.js +153 -0
  208. package/dashboard/tests/setup.js +7 -0
  209. package/dashboard/vite.config.js +41 -0
  210. package/hooks/dist/auto-continue.js +277 -0
  211. package/hooks/dist/block-skill-self-read.js +80 -0
  212. package/hooks/dist/check-agent-state-write.js +63 -0
  213. package/hooks/dist/check-config-change.js +188 -0
  214. package/hooks/dist/check-dangerous-commands.js +185 -0
  215. package/hooks/dist/check-doc-sprawl.js +102 -0
  216. package/hooks/dist/check-phase-boundary.js +191 -0
  217. package/hooks/dist/check-plan-format.js +227 -0
  218. package/hooks/dist/check-roadmap-sync.js +503 -0
  219. package/hooks/dist/check-skill-workflow.js +354 -0
  220. package/hooks/dist/check-state-sync.js +637 -0
  221. package/hooks/dist/check-subagent-output.js +401 -0
  222. package/hooks/dist/check-summary-gate.js +199 -0
  223. package/hooks/dist/context-bridge.js +406 -0
  224. package/hooks/dist/context-budget-check.js +442 -0
  225. package/hooks/dist/context-quality.js +271 -0
  226. package/hooks/dist/enforce-pbr-workflow.js +277 -0
  227. package/hooks/dist/event-handler.js +203 -0
  228. package/hooks/dist/event-logger.js +125 -0
  229. package/hooks/dist/hook-logger.js +112 -0
  230. package/hooks/dist/hook-server-client.js +342 -0
  231. package/hooks/dist/hook-server.js +352 -0
  232. package/hooks/dist/hooks-schema.json +85 -0
  233. package/hooks/dist/hooks.json +309 -0
  234. package/hooks/dist/instructions-loaded.js +107 -0
  235. package/hooks/dist/intel-queue.js +152 -0
  236. package/hooks/dist/intercept-plan-mode.js +50 -0
  237. package/hooks/dist/log-notification.js +125 -0
  238. package/hooks/dist/log-subagent.js +306 -0
  239. package/hooks/dist/log-tool-failure.js +140 -0
  240. package/hooks/dist/milestone-learnings.js +569 -0
  241. package/hooks/dist/pbr-tools.js +5 -0
  242. package/hooks/dist/post-bash-triage.js +152 -0
  243. package/hooks/dist/post-compact.js +135 -0
  244. package/hooks/dist/post-write-dispatch.js +277 -0
  245. package/hooks/dist/post-write-quality.js +208 -0
  246. package/hooks/dist/pre-bash-dispatch.js +158 -0
  247. package/hooks/dist/pre-write-dispatch.js +165 -0
  248. package/hooks/dist/progress-tracker.js +198 -0
  249. package/hooks/dist/prompt-routing.js +209 -0
  250. package/hooks/dist/run-hook.js +144 -0
  251. package/hooks/dist/session-cleanup.js +617 -0
  252. package/hooks/dist/session-tracker.js +124 -0
  253. package/hooks/dist/status-line.js +793 -0
  254. package/hooks/dist/suggest-compact.js +296 -0
  255. package/hooks/dist/sync-context-to-claude.js +100 -0
  256. package/hooks/dist/task-completed.js +206 -0
  257. package/hooks/dist/track-context-budget.js +405 -0
  258. package/hooks/dist/trust-tracker.js +193 -0
  259. package/hooks/dist/validate-commit.js +270 -0
  260. package/hooks/dist/validate-skill-args.js +222 -0
  261. package/hooks/dist/validate-task.js +272 -0
  262. package/hooks/dist/worktree-create.js +144 -0
  263. package/hooks/dist/worktree-remove.js +147 -0
  264. package/package.json +59 -40
  265. package/plan-build-run/bin/config-schema.json +1416 -0
  266. package/plan-build-run/bin/dashboard-launch.cjs +114 -0
  267. package/plan-build-run/bin/event-logger.cjs +92 -0
  268. package/plan-build-run/bin/lib/alternatives.cjs +198 -0
  269. package/plan-build-run/bin/lib/auto-cleanup.cjs +7 -0
  270. package/plan-build-run/bin/lib/build.cjs +717 -0
  271. package/plan-build-run/bin/lib/circuit-state.cjs +133 -0
  272. package/plan-build-run/bin/lib/commands.cjs +482 -0
  273. package/plan-build-run/bin/lib/config.cjs +770 -0
  274. package/plan-build-run/bin/lib/context.cjs +216 -0
  275. package/plan-build-run/bin/lib/contextual-help.cjs +207 -0
  276. package/plan-build-run/bin/lib/core.cjs +1563 -0
  277. package/plan-build-run/bin/lib/decisions.cjs +194 -0
  278. package/plan-build-run/bin/lib/frontmatter.cjs +299 -0
  279. package/plan-build-run/bin/lib/gates/advisories.cjs +129 -0
  280. package/plan-build-run/bin/lib/gates/build-dependency.cjs +115 -0
  281. package/plan-build-run/bin/lib/gates/build-executor.cjs +104 -0
  282. package/plan-build-run/bin/lib/gates/doc-existence.cjs +46 -0
  283. package/plan-build-run/bin/lib/gates/helpers.cjs +93 -0
  284. package/plan-build-run/bin/lib/gates/inline-execution.cjs +185 -0
  285. package/plan-build-run/bin/lib/gates/milestone-complete.cjs +136 -0
  286. package/plan-build-run/bin/lib/gates/milestone-summary.cjs +119 -0
  287. package/plan-build-run/bin/lib/gates/plan-executor.cjs +36 -0
  288. package/plan-build-run/bin/lib/gates/quick-executor.cjs +76 -0
  289. package/plan-build-run/bin/lib/gates/review-planner.cjs +61 -0
  290. package/plan-build-run/bin/lib/gates/review-verifier.cjs +69 -0
  291. package/plan-build-run/bin/lib/graph-cli.cjs +89 -0
  292. package/plan-build-run/bin/lib/graph.cjs +554 -0
  293. package/plan-build-run/bin/lib/health-phase06.cjs +120 -0
  294. package/plan-build-run/bin/lib/health.cjs +133 -0
  295. package/plan-build-run/bin/lib/history.cjs +147 -0
  296. package/plan-build-run/bin/lib/hypothesis-runner.cjs +127 -0
  297. package/plan-build-run/bin/lib/impact-analysis.cjs +319 -0
  298. package/plan-build-run/bin/lib/incidents.cjs +190 -0
  299. package/plan-build-run/bin/lib/init.cjs +367 -0
  300. package/plan-build-run/bin/lib/intel.cjs +653 -0
  301. package/plan-build-run/bin/lib/learnings.cjs +511 -0
  302. package/plan-build-run/bin/lib/local-llm/health.cjs +12 -0
  303. package/plan-build-run/bin/lib/local-llm/index.cjs +89 -0
  304. package/plan-build-run/bin/lib/local-llm/metrics.cjs +20 -0
  305. package/plan-build-run/bin/lib/local-llm/operations/classify-artifact.cjs +4 -0
  306. package/plan-build-run/bin/lib/local-llm/operations/classify-commit.cjs +4 -0
  307. package/plan-build-run/bin/lib/local-llm/operations/classify-error.cjs +4 -0
  308. package/plan-build-run/bin/lib/local-llm/operations/classify-file-intent.cjs +4 -0
  309. package/plan-build-run/bin/lib/local-llm/operations/triage-test-output.cjs +12 -0
  310. package/plan-build-run/bin/lib/local-llm/operations/validate-task.cjs +4 -0
  311. package/plan-build-run/bin/lib/migrate.cjs +298 -0
  312. package/plan-build-run/bin/lib/milestone.cjs +306 -0
  313. package/plan-build-run/bin/lib/negative-knowledge.cjs +194 -0
  314. package/plan-build-run/bin/lib/onboarding-generator.cjs +288 -0
  315. package/plan-build-run/bin/lib/parse-args.cjs +134 -0
  316. package/plan-build-run/bin/lib/patterns.cjs +272 -0
  317. package/plan-build-run/bin/lib/phase.cjs +1021 -0
  318. package/plan-build-run/bin/lib/post-hoc.cjs +160 -0
  319. package/plan-build-run/bin/lib/preview.cjs +174 -0
  320. package/plan-build-run/bin/lib/progress-visualization.cjs +296 -0
  321. package/plan-build-run/bin/lib/quick-init.cjs +131 -0
  322. package/plan-build-run/bin/lib/reference.cjs +234 -0
  323. package/plan-build-run/bin/lib/requirements.cjs +153 -0
  324. package/plan-build-run/bin/lib/reverse-spec.cjs +259 -0
  325. package/plan-build-run/bin/lib/roadmap.cjs +1097 -0
  326. package/plan-build-run/bin/lib/security-scan.cjs +200 -0
  327. package/plan-build-run/bin/lib/skill-section.cjs +98 -0
  328. package/plan-build-run/bin/lib/spec-diff.cjs +209 -0
  329. package/plan-build-run/bin/lib/spec-engine.cjs +189 -0
  330. package/plan-build-run/bin/lib/spot-check.cjs +510 -0
  331. package/plan-build-run/bin/lib/state.cjs +1050 -0
  332. package/plan-build-run/bin/lib/status-render.cjs +527 -0
  333. package/plan-build-run/bin/lib/step-verify.cjs +149 -0
  334. package/plan-build-run/bin/lib/suggest-next.cjs +316 -0
  335. package/plan-build-run/bin/lib/team-composer.cjs +85 -0
  336. package/plan-build-run/bin/lib/team-coordinator.cjs +151 -0
  337. package/plan-build-run/bin/lib/template.cjs +222 -0
  338. package/plan-build-run/bin/lib/templates.cjs +362 -0
  339. package/plan-build-run/bin/lib/test-selection.cjs +163 -0
  340. package/plan-build-run/bin/lib/todo.cjs +300 -0
  341. package/plan-build-run/bin/lib/validation.cjs +187 -0
  342. package/plan-build-run/bin/lib/verify.cjs +1451 -0
  343. package/plan-build-run/bin/pbr-tools.cjs +1877 -0
  344. package/plan-build-run/references/CLAUDE.md +7 -0
  345. package/plan-build-run/references/agent-contracts.md +326 -0
  346. package/plan-build-run/references/agent-teams.md +54 -0
  347. package/plan-build-run/references/behavioral-contexts.md +53 -0
  348. package/plan-build-run/references/checkpoints.md +776 -0
  349. package/plan-build-run/references/config-reference.md +613 -0
  350. package/plan-build-run/references/continuation-format.md +249 -0
  351. package/plan-build-run/references/debugging/CLAUDE.md +7 -0
  352. package/plan-build-run/references/decimal-phase-calculation.md +65 -0
  353. package/plan-build-run/references/git-integration.md +309 -0
  354. package/plan-build-run/references/git-planning-commit.md +38 -0
  355. package/plan-build-run/references/model-profile-resolution.md +34 -0
  356. package/plan-build-run/references/model-profiles.md +182 -0
  357. package/plan-build-run/references/model-selection.md +53 -0
  358. package/plan-build-run/references/phase-argument-parsing.md +61 -0
  359. package/plan-build-run/references/plan-authoring.md +246 -0
  360. package/plan-build-run/references/plan-format.md +351 -0
  361. package/plan-build-run/references/planning-config.md +200 -0
  362. package/plan-build-run/references/questioning.md +162 -0
  363. package/plan-build-run/references/reading-verification.md +127 -0
  364. package/plan-build-run/references/stub-patterns.md +160 -0
  365. package/plan-build-run/references/tdd.md +263 -0
  366. package/plan-build-run/references/ui-brand.md +187 -0
  367. package/plan-build-run/references/verification-overrides.md +38 -0
  368. package/plan-build-run/references/verification-patterns.md +612 -0
  369. package/plan-build-run/references/wave-execution.md +52 -0
  370. package/plan-build-run/skills/audit/SKILL.md +347 -0
  371. package/plan-build-run/skills/autonomous/SKILL.md +460 -0
  372. package/plan-build-run/skills/begin/SKILL.md +926 -0
  373. package/plan-build-run/skills/begin/templates/PROJECT.md.tmpl +33 -0
  374. package/plan-build-run/skills/begin/templates/REQUIREMENTS.md.tmpl +18 -0
  375. package/plan-build-run/skills/begin/templates/STATE.md.tmpl +48 -0
  376. package/plan-build-run/skills/begin/templates/config.json.tmpl +451 -0
  377. package/plan-build-run/skills/begin/templates/project-CONTEXT.md.tmpl +19 -0
  378. package/plan-build-run/skills/begin/templates/researcher-prompt.md.tmpl +47 -0
  379. package/plan-build-run/skills/begin/templates/roadmap-prompt.md.tmpl +49 -0
  380. package/plan-build-run/skills/begin/templates/synthesis-prompt.md.tmpl +44 -0
  381. package/plan-build-run/skills/build/SKILL.md +1655 -0
  382. package/plan-build-run/skills/build/templates/continuation-prompt.md.tmpl +26 -0
  383. package/plan-build-run/skills/build/templates/executor-prompt.md.tmpl +70 -0
  384. package/plan-build-run/skills/build/templates/inline-verifier-prompt.md.tmpl +33 -0
  385. package/plan-build-run/skills/config/SKILL.md +357 -0
  386. package/plan-build-run/skills/continue/SKILL.md +266 -0
  387. package/plan-build-run/skills/dashboard/SKILL.md +12 -0
  388. package/plan-build-run/skills/debug/SKILL.md +573 -0
  389. package/plan-build-run/skills/debug/templates/continuation-prompt.md.tmpl +27 -0
  390. package/plan-build-run/skills/debug/templates/initial-investigation-prompt.md.tmpl +34 -0
  391. package/plan-build-run/skills/discuss/SKILL.md +489 -0
  392. package/plan-build-run/skills/discuss/templates/CONTEXT.md.tmpl +61 -0
  393. package/plan-build-run/skills/discuss/templates/decision-categories.md +9 -0
  394. package/plan-build-run/skills/discuss/templates/project-CONTEXT.md.tmpl +19 -0
  395. package/plan-build-run/skills/do/SKILL.md +165 -0
  396. package/plan-build-run/skills/explore/SKILL.md +449 -0
  397. package/plan-build-run/skills/health/SKILL.md +332 -0
  398. package/plan-build-run/skills/health/templates/check-pattern.md.tmpl +30 -0
  399. package/plan-build-run/skills/health/templates/output-format.md.tmpl +63 -0
  400. package/plan-build-run/skills/help/SKILL.md +236 -0
  401. package/plan-build-run/skills/import/SKILL.md +827 -0
  402. package/plan-build-run/skills/intel/SKILL.md +131 -0
  403. package/plan-build-run/skills/milestone/SKILL.md +825 -0
  404. package/plan-build-run/skills/milestone/templates/audit-output.md.tmpl +76 -0
  405. package/plan-build-run/skills/milestone/templates/complete-output.md.tmpl +32 -0
  406. package/plan-build-run/skills/milestone/templates/edge-cases.md +54 -0
  407. package/plan-build-run/skills/milestone/templates/gaps-output.md.tmpl +25 -0
  408. package/plan-build-run/skills/milestone/templates/integration-checker-prompt.md.tmpl +25 -0
  409. package/plan-build-run/skills/milestone/templates/new-output.md.tmpl +29 -0
  410. package/plan-build-run/skills/milestone/templates/stats-file.md.tmpl +30 -0
  411. package/plan-build-run/skills/note/SKILL.md +221 -0
  412. package/plan-build-run/skills/pause/SKILL.md +259 -0
  413. package/plan-build-run/skills/pause/templates/continue-here.md.tmpl +71 -0
  414. package/plan-build-run/skills/plan/SKILL.md +852 -0
  415. package/plan-build-run/skills/plan/decimal-phase-calc.md +98 -0
  416. package/plan-build-run/skills/plan/templates/checker-prompt.md.tmpl +21 -0
  417. package/plan-build-run/skills/plan/templates/completion-output.md.tmpl +27 -0
  418. package/plan-build-run/skills/plan/templates/gap-closure-prompt.md.tmpl +32 -0
  419. package/plan-build-run/skills/plan/templates/planner-prompt.md.tmpl +38 -0
  420. package/plan-build-run/skills/plan/templates/prompt-partials/phase-project-context.md.tmpl +21 -0
  421. package/plan-build-run/skills/plan/templates/researcher-prompt.md.tmpl +19 -0
  422. package/plan-build-run/skills/plan/templates/revision-prompt.md.tmpl +23 -0
  423. package/plan-build-run/skills/profile/SKILL.md +173 -0
  424. package/plan-build-run/skills/profile-user/SKILL.md +220 -0
  425. package/plan-build-run/skills/quick/SKILL.md +727 -0
  426. package/plan-build-run/skills/release/SKILL.md +206 -0
  427. package/plan-build-run/skills/resume/SKILL.md +499 -0
  428. package/plan-build-run/skills/review/SKILL.md +763 -0
  429. package/plan-build-run/skills/review/templates/debugger-prompt.md.tmpl +60 -0
  430. package/plan-build-run/skills/review/templates/gap-planner-prompt.md.tmpl +40 -0
  431. package/plan-build-run/skills/review/templates/verifier-prompt.md.tmpl +115 -0
  432. package/plan-build-run/skills/scan/SKILL.md +330 -0
  433. package/plan-build-run/skills/scan/templates/mapper-prompt.md.tmpl +201 -0
  434. package/plan-build-run/skills/session-report/SKILL.md +128 -0
  435. package/plan-build-run/skills/setup/SKILL.md +246 -0
  436. package/plan-build-run/skills/shared/agent-type-resolution.md +20 -0
  437. package/plan-build-run/skills/shared/commit-planning-docs.md +43 -0
  438. package/plan-build-run/skills/shared/config-loading.md +102 -0
  439. package/plan-build-run/skills/shared/context-budget.md +105 -0
  440. package/plan-build-run/skills/shared/context-loader-task.md +91 -0
  441. package/plan-build-run/skills/shared/digest-select.md +79 -0
  442. package/plan-build-run/skills/shared/domain-probes.md +125 -0
  443. package/plan-build-run/skills/shared/error-reporting.md +59 -0
  444. package/plan-build-run/skills/shared/gate-prompts.md +390 -0
  445. package/plan-build-run/skills/shared/phase-argument-parsing.md +45 -0
  446. package/plan-build-run/skills/shared/revision-loop.md +81 -0
  447. package/plan-build-run/skills/shared/state-update.md +154 -0
  448. package/plan-build-run/skills/shared/universal-anti-patterns.md +59 -0
  449. package/plan-build-run/skills/ship/SKILL.md +154 -0
  450. package/plan-build-run/skills/status/SKILL.md +520 -0
  451. package/plan-build-run/skills/statusline/SKILL.md +151 -0
  452. package/plan-build-run/skills/test/SKILL.md +254 -0
  453. package/plan-build-run/skills/todo/SKILL.md +285 -0
  454. package/plan-build-run/skills/ui-phase/SKILL.md +177 -0
  455. package/plan-build-run/skills/ui-review/SKILL.md +204 -0
  456. package/plan-build-run/skills/undo/SKILL.md +216 -0
  457. package/plan-build-run/skills/validate-phase/SKILL.md +358 -0
  458. package/plan-build-run/templates/CLAUDE.md +7 -0
  459. package/plan-build-run/templates/DEBUG.md +164 -0
  460. package/plan-build-run/templates/UAT.md +247 -0
  461. package/plan-build-run/templates/VALIDATION.md +76 -0
  462. package/plan-build-run/templates/codebase/architecture.md +255 -0
  463. package/plan-build-run/templates/codebase/concerns.md +310 -0
  464. package/plan-build-run/templates/codebase/conventions.md +307 -0
  465. package/plan-build-run/templates/codebase/integrations.md +280 -0
  466. package/plan-build-run/templates/codebase/stack.md +186 -0
  467. package/plan-build-run/templates/codebase/structure.md +285 -0
  468. package/plan-build-run/templates/codebase/testing.md +480 -0
  469. package/plan-build-run/templates/config.json +37 -0
  470. package/plan-build-run/templates/context.md +297 -0
  471. package/plan-build-run/templates/continue-here.md +78 -0
  472. package/plan-build-run/templates/crud-flow-verification.md +277 -0
  473. package/plan-build-run/templates/debug-subagent-prompt.md +91 -0
  474. package/plan-build-run/templates/deferred-items.md +19 -0
  475. package/plan-build-run/templates/discovery.md +146 -0
  476. package/plan-build-run/templates/milestone-archive.md +123 -0
  477. package/plan-build-run/templates/milestone.md +115 -0
  478. package/plan-build-run/templates/phase-prompt.md +569 -0
  479. package/plan-build-run/templates/planner-subagent-prompt.md +117 -0
  480. package/plan-build-run/templates/project.md +184 -0
  481. package/plan-build-run/templates/requirements.md +231 -0
  482. package/plan-build-run/templates/research-outputs/ARCHITECTURE.md.tmpl +86 -0
  483. package/plan-build-run/templates/research-outputs/FEATURES.md.tmpl +77 -0
  484. package/plan-build-run/templates/research-outputs/PITFALLS.md.tmpl +65 -0
  485. package/plan-build-run/templates/research-outputs/STACK.md.tmpl +80 -0
  486. package/plan-build-run/templates/research-project/ARCHITECTURE.md +204 -0
  487. package/plan-build-run/templates/research-project/FEATURES.md +147 -0
  488. package/plan-build-run/templates/research-project/PITFALLS.md +200 -0
  489. package/plan-build-run/templates/research-project/STACK.md +120 -0
  490. package/plan-build-run/templates/research-project/SUMMARY.md +170 -0
  491. package/plan-build-run/templates/research.md +552 -0
  492. package/plan-build-run/templates/retrospective.md +54 -0
  493. package/plan-build-run/templates/roadmap.md +202 -0
  494. package/plan-build-run/templates/seed.md +16 -0
  495. package/plan-build-run/templates/state.md +176 -0
  496. package/plan-build-run/templates/summary-complex.md +59 -0
  497. package/plan-build-run/templates/summary-minimal.md +41 -0
  498. package/plan-build-run/templates/summary-standard.md +48 -0
  499. package/plan-build-run/templates/summary.md +248 -0
  500. package/plan-build-run/templates/user-setup.md +311 -0
  501. package/plan-build-run/templates/verification-report.md +322 -0
  502. package/plan-build-run/workflows/add-phase.md +111 -0
  503. package/plan-build-run/workflows/add-todo.md +157 -0
  504. package/plan-build-run/workflows/audit-milestone.md +241 -0
  505. package/plan-build-run/workflows/check-todos.md +176 -0
  506. package/plan-build-run/workflows/complete-milestone.md +644 -0
  507. package/plan-build-run/workflows/diagnose-issues.md +219 -0
  508. package/plan-build-run/workflows/discovery-phase.md +289 -0
  509. package/plan-build-run/workflows/discuss-phase.md +429 -0
  510. package/plan-build-run/workflows/execute-phase.md +439 -0
  511. package/plan-build-run/workflows/execute-plan.md +437 -0
  512. package/plan-build-run/workflows/explore.md +150 -0
  513. package/plan-build-run/workflows/help.md +470 -0
  514. package/plan-build-run/workflows/insert-phase.md +129 -0
  515. package/plan-build-run/workflows/list-phase-assumptions.md +178 -0
  516. package/plan-build-run/workflows/map-codebase.md +327 -0
  517. package/plan-build-run/workflows/new-milestone.md +373 -0
  518. package/plan-build-run/workflows/new-project.md +1009 -0
  519. package/plan-build-run/workflows/note.md +90 -0
  520. package/plan-build-run/workflows/pause-work.md +122 -0
  521. package/plan-build-run/workflows/plan-milestone-gaps.md +256 -0
  522. package/plan-build-run/workflows/plan-phase.md +376 -0
  523. package/plan-build-run/workflows/progress.md +431 -0
  524. package/plan-build-run/workflows/quick.md +230 -0
  525. package/plan-build-run/workflows/remove-phase.md +154 -0
  526. package/plan-build-run/workflows/research-phase.md +74 -0
  527. package/plan-build-run/workflows/resume-project.md +306 -0
  528. package/plan-build-run/workflows/set-profile.md +80 -0
  529. package/plan-build-run/workflows/settings.md +145 -0
  530. package/plan-build-run/workflows/transition.md +539 -0
  531. package/plan-build-run/workflows/update.md +212 -0
  532. package/plan-build-run/workflows/verify-phase.md +226 -0
  533. package/plan-build-run/workflows/verify-work.md +465 -0
  534. package/plugins/pbr/.claude-plugin/plugin.json +1 -1
  535. package/plugins/pbr/CLAUDE.md +19 -0
  536. package/plugins/pbr/UI-CONSISTENCY-GAPS.md +1 -1
  537. package/plugins/pbr/agents/audit.md +285 -0
  538. package/plugins/pbr/agents/codebase-mapper.md +110 -18
  539. package/plugins/pbr/agents/debugger.md +231 -29
  540. package/plugins/pbr/agents/dev-sync.md +206 -0
  541. package/plugins/pbr/agents/executor.md +601 -39
  542. package/plugins/pbr/agents/general.md +71 -6
  543. package/plugins/pbr/agents/integration-checker.md +146 -30
  544. package/plugins/pbr/agents/intel-updater.md +333 -0
  545. package/plugins/pbr/agents/nyquist-auditor.md +253 -0
  546. package/plugins/pbr/agents/plan-checker.md +177 -60
  547. package/plugins/pbr/agents/planner.md +404 -42
  548. package/plugins/pbr/agents/researcher.md +239 -36
  549. package/plugins/pbr/agents/roadmapper.md +384 -0
  550. package/plugins/pbr/agents/synthesizer.md +169 -26
  551. package/plugins/pbr/agents/ui-checker.md +203 -0
  552. package/plugins/pbr/agents/ui-researcher.md +224 -0
  553. package/plugins/pbr/agents/verifier.md +452 -48
  554. package/plugins/pbr/commands/add-phase.md +75 -0
  555. package/plugins/pbr/commands/add-todo.md +8 -0
  556. package/plugins/pbr/commands/audit-milestone.md +8 -0
  557. package/plugins/pbr/commands/audit.md +5 -0
  558. package/plugins/pbr/commands/autonomous.md +5 -0
  559. package/plugins/pbr/commands/begin.md +1 -1
  560. package/plugins/pbr/commands/build.md +1 -1
  561. package/plugins/pbr/commands/check-todos.md +8 -0
  562. package/plugins/pbr/commands/complete-milestone.md +8 -0
  563. package/plugins/pbr/commands/config.md +2 -2
  564. package/plugins/pbr/commands/continue.md +1 -1
  565. package/plugins/pbr/commands/dashboard.md +1 -1
  566. package/plugins/pbr/commands/debug.md +1 -1
  567. package/plugins/pbr/commands/discuss-phase.md +6 -0
  568. package/plugins/pbr/commands/discuss.md +1 -1
  569. package/plugins/pbr/commands/do.md +5 -0
  570. package/plugins/pbr/commands/execute-phase.md +6 -0
  571. package/plugins/pbr/commands/explore.md +1 -1
  572. package/plugins/pbr/commands/health.md +1 -1
  573. package/plugins/pbr/commands/help.md +1 -1
  574. package/plugins/pbr/commands/import.md +2 -2
  575. package/plugins/pbr/commands/insert-phase.md +65 -0
  576. package/plugins/pbr/commands/intel.md +5 -0
  577. package/plugins/pbr/commands/join-discord.md +11 -0
  578. package/plugins/pbr/commands/list-phase-assumptions.md +69 -0
  579. package/plugins/pbr/commands/map-codebase.md +6 -0
  580. package/plugins/pbr/commands/milestone.md +1 -1
  581. package/plugins/pbr/commands/new-milestone.md +8 -0
  582. package/plugins/pbr/commands/new-project.md +6 -0
  583. package/plugins/pbr/commands/note.md +1 -1
  584. package/plugins/pbr/commands/pause-work.md +5 -0
  585. package/plugins/pbr/commands/pause.md +1 -1
  586. package/plugins/pbr/commands/plan-milestone-gaps.md +7 -0
  587. package/plugins/pbr/commands/plan-phase.md +6 -0
  588. package/plugins/pbr/commands/plan.md +1 -1
  589. package/plugins/pbr/commands/profile-user.md +5 -0
  590. package/plugins/pbr/commands/profile.md +5 -0
  591. package/plugins/pbr/commands/progress.md +6 -0
  592. package/plugins/pbr/commands/quick.md +2 -2
  593. package/plugins/pbr/commands/reapply-patches.md +47 -0
  594. package/plugins/pbr/commands/release.md +6 -0
  595. package/plugins/pbr/commands/remove-phase.md +66 -0
  596. package/plugins/pbr/commands/research-phase.md +59 -0
  597. package/plugins/pbr/commands/resume-work.md +5 -0
  598. package/plugins/pbr/commands/resume.md +1 -1
  599. package/plugins/pbr/commands/review.md +1 -1
  600. package/plugins/pbr/commands/scan.md +1 -1
  601. package/plugins/pbr/commands/session-report.md +5 -0
  602. package/plugins/pbr/commands/set-profile.md +6 -0
  603. package/plugins/pbr/commands/settings.md +5 -0
  604. package/plugins/pbr/commands/setup.md +2 -2
  605. package/plugins/pbr/commands/ship.md +5 -0
  606. package/plugins/pbr/commands/status.md +1 -1
  607. package/plugins/pbr/commands/statusline.md +1 -1
  608. package/plugins/pbr/commands/test.md +5 -0
  609. package/plugins/pbr/commands/todo.md +2 -2
  610. package/plugins/pbr/commands/ui-phase.md +5 -0
  611. package/plugins/pbr/commands/ui-review.md +5 -0
  612. package/plugins/pbr/commands/undo.md +5 -0
  613. package/plugins/pbr/commands/update.md +37 -0
  614. package/plugins/pbr/commands/validate-phase.md +5 -0
  615. package/plugins/pbr/commands/verify-work.md +6 -0
  616. package/plugins/pbr/dashboard/package-lock.json +6 -0
  617. package/plugins/pbr/hooks/hooks.json +102 -13
  618. package/plugins/pbr/references/agent-contracts.md +37 -8
  619. package/plugins/pbr/references/agent-teams.md +3 -3
  620. package/plugins/pbr/references/archive/checkpoints.md +189 -0
  621. package/plugins/pbr/references/archive/context-quality-tiers.md +45 -0
  622. package/plugins/pbr/references/archive/pbr-rules.md +194 -0
  623. package/plugins/pbr/references/archive/verification-patterns.md +277 -0
  624. package/plugins/pbr/references/config-reference.md +182 -10
  625. package/plugins/pbr/references/continuation-format.md +1 -0
  626. package/plugins/pbr/references/deviation-rules.md +12 -0
  627. package/plugins/pbr/references/git-integration.md +110 -27
  628. package/plugins/pbr/references/hook-ordering.md +89 -0
  629. package/plugins/pbr/references/limitations.md +106 -0
  630. package/plugins/pbr/references/model-profiles.md +90 -7
  631. package/plugins/pbr/references/model-selection.md +1 -1
  632. package/plugins/pbr/references/node-repair.md +48 -0
  633. package/plugins/pbr/references/pbr-tools-cli.md +132 -2
  634. package/plugins/pbr/references/plan-authoring.md +65 -0
  635. package/plugins/pbr/references/plan-format.md +161 -10
  636. package/plugins/pbr/references/pretooluse-jsonl-behavior.md +58 -0
  637. package/plugins/pbr/references/questioning.md +138 -49
  638. package/plugins/pbr/references/reading-verification.md +4 -4
  639. package/plugins/pbr/references/signal-files.md +41 -0
  640. package/plugins/pbr/references/tmux-setup.md +288 -0
  641. package/plugins/pbr/references/ui-brand.md +449 -0
  642. package/plugins/pbr/references/worktree-sparse-checkout.md +86 -0
  643. package/plugins/pbr/scripts/architecture-guard.js +257 -0
  644. package/plugins/pbr/scripts/audit-checks/behavioral-compliance.js +2098 -0
  645. package/plugins/pbr/scripts/audit-checks/error-analysis.js +895 -0
  646. package/plugins/pbr/scripts/audit-checks/feature-verification.js +723 -0
  647. package/plugins/pbr/scripts/audit-checks/index.js +433 -0
  648. package/plugins/pbr/scripts/audit-checks/infrastructure.js +816 -0
  649. package/plugins/pbr/scripts/audit-checks/quality-metrics.js +452 -0
  650. package/plugins/pbr/scripts/audit-checks/session-quality.js +980 -0
  651. package/plugins/pbr/scripts/audit-checks/si-agent-hook-config-checks.js +467 -0
  652. package/plugins/pbr/scripts/audit-checks/si-cross-cutting-checks.js +272 -0
  653. package/plugins/pbr/scripts/audit-checks/si-skill-checks.js +424 -0
  654. package/plugins/pbr/scripts/audit-checks/workflow-compliance.js +1210 -0
  655. package/plugins/pbr/scripts/audit-dimensions.js +552 -0
  656. package/plugins/pbr/scripts/auto-continue.js +211 -32
  657. package/plugins/pbr/scripts/block-skill-self-read.js +85 -0
  658. package/plugins/pbr/scripts/check-agent-state-write.js +74 -0
  659. package/plugins/pbr/scripts/check-config-change.js +188 -0
  660. package/plugins/pbr/scripts/check-cross-plugin-sync.js +93 -0
  661. package/plugins/pbr/scripts/check-dangerous-commands.js +9 -5
  662. package/plugins/pbr/scripts/check-direct-state-write.js +37 -0
  663. package/plugins/pbr/scripts/check-phase-boundary.js +2 -8
  664. package/plugins/pbr/scripts/check-plan-format.js +149 -274
  665. package/plugins/pbr/scripts/check-roadmap-sync.js +175 -10
  666. package/plugins/pbr/scripts/check-skill-workflow.js +38 -34
  667. package/plugins/pbr/scripts/check-state-sync.js +344 -216
  668. package/plugins/pbr/scripts/check-subagent-output.js +297 -256
  669. package/plugins/pbr/scripts/check-summary-gate.js +1 -1
  670. package/plugins/pbr/scripts/config-schema.json +1252 -95
  671. package/plugins/pbr/scripts/context-bridge.js +439 -0
  672. package/plugins/pbr/scripts/context-budget-check.js +89 -9
  673. package/plugins/pbr/scripts/context-quality.js +272 -0
  674. package/plugins/pbr/scripts/enforce-pbr-workflow.js +277 -0
  675. package/plugins/pbr/scripts/event-handler.js +129 -77
  676. package/plugins/pbr/scripts/event-logger.js +61 -26
  677. package/plugins/pbr/scripts/feedback-loop.js +172 -0
  678. package/plugins/pbr/scripts/graph-update.js +199 -0
  679. package/plugins/pbr/scripts/hook-logger.js +76 -35
  680. package/plugins/pbr/scripts/hook-server-client.js +258 -0
  681. package/plugins/pbr/scripts/hook-server.js +334 -0
  682. package/plugins/pbr/scripts/hooks-schema.json +5 -1
  683. package/plugins/pbr/scripts/instructions-loaded.js +107 -0
  684. package/plugins/pbr/scripts/intel-queue.js +152 -0
  685. package/plugins/pbr/scripts/intent-router.cjs +147 -0
  686. package/plugins/pbr/scripts/intercept-plan-mode.js +52 -0
  687. package/plugins/pbr/scripts/lib/alternatives.js +203 -0
  688. package/plugins/pbr/scripts/lib/auto-cleanup.js +221 -0
  689. package/plugins/pbr/scripts/lib/auto-verify.js +103 -0
  690. package/plugins/pbr/scripts/lib/autonomy.js +91 -0
  691. package/plugins/pbr/scripts/lib/build.js +719 -0
  692. package/plugins/pbr/scripts/lib/ci-fix-loop.js +228 -0
  693. package/plugins/pbr/scripts/lib/circuit-state.js +133 -0
  694. package/plugins/pbr/scripts/lib/config.js +901 -0
  695. package/plugins/pbr/scripts/lib/context.js +254 -0
  696. package/plugins/pbr/scripts/lib/convention-detector.js +413 -0
  697. package/plugins/pbr/scripts/lib/core.js +939 -0
  698. package/plugins/pbr/scripts/lib/dashboard-launch.js +170 -0
  699. package/plugins/pbr/scripts/lib/decision-extraction.js +267 -0
  700. package/plugins/pbr/scripts/lib/dependency-break.js +147 -0
  701. package/plugins/pbr/scripts/lib/format-validators.js +947 -0
  702. package/plugins/pbr/scripts/lib/gates/advisories.js +129 -0
  703. package/plugins/pbr/scripts/lib/gates/build-dependency.js +115 -0
  704. package/plugins/pbr/scripts/lib/gates/build-executor.js +104 -0
  705. package/plugins/pbr/scripts/lib/gates/doc-existence.js +46 -0
  706. package/plugins/pbr/scripts/lib/gates/helpers.js +141 -0
  707. package/plugins/pbr/scripts/lib/gates/inline-execution.js +185 -0
  708. package/plugins/pbr/scripts/lib/gates/milestone-complete.js +136 -0
  709. package/plugins/pbr/scripts/lib/gates/milestone-summary.js +119 -0
  710. package/plugins/pbr/scripts/lib/gates/multi-phase-loader.js +147 -0
  711. package/plugins/pbr/scripts/lib/gates/plan-executor.js +36 -0
  712. package/plugins/pbr/scripts/lib/gates/quick-executor.js +76 -0
  713. package/plugins/pbr/scripts/lib/gates/review-planner.js +61 -0
  714. package/plugins/pbr/scripts/lib/gates/review-verifier.js +69 -0
  715. package/plugins/pbr/scripts/lib/gates/rich-agent-context.js +143 -0
  716. package/plugins/pbr/scripts/lib/health-checks.js +215 -0
  717. package/plugins/pbr/scripts/lib/history.js +150 -0
  718. package/plugins/pbr/scripts/lib/init.js +302 -0
  719. package/plugins/pbr/scripts/lib/learnings.js +432 -0
  720. package/plugins/pbr/scripts/lib/migrate.js +169 -0
  721. package/plugins/pbr/scripts/lib/parse-args.js +134 -0
  722. package/plugins/pbr/scripts/lib/pattern-routing.js +55 -0
  723. package/plugins/pbr/scripts/lib/phase.js +935 -0
  724. package/plugins/pbr/scripts/lib/pre-research.js +133 -0
  725. package/plugins/pbr/scripts/lib/preview.js +174 -0
  726. package/plugins/pbr/scripts/lib/quick-init.js +131 -0
  727. package/plugins/pbr/scripts/lib/reference.js +236 -0
  728. package/plugins/pbr/scripts/lib/resolve-root.js +66 -0
  729. package/plugins/pbr/scripts/lib/roadmap.js +784 -0
  730. package/plugins/pbr/scripts/lib/session-briefing.js +879 -0
  731. package/plugins/pbr/scripts/lib/skill-section.js +99 -0
  732. package/plugins/pbr/scripts/lib/smart-next-task.js +225 -0
  733. package/plugins/pbr/scripts/lib/snapshot-manager.js +225 -0
  734. package/plugins/pbr/scripts/lib/spot-check.js +509 -0
  735. package/plugins/pbr/scripts/lib/state.js +565 -0
  736. package/plugins/pbr/scripts/lib/status-render.js +511 -0
  737. package/plugins/pbr/scripts/lib/step-verify.js +149 -0
  738. package/plugins/pbr/scripts/lib/subagent-validators.js +1010 -0
  739. package/plugins/pbr/scripts/lib/suggest-next.js +316 -0
  740. package/plugins/pbr/scripts/lib/tech-debt-scanner.js +116 -0
  741. package/plugins/pbr/scripts/lib/test-cache.js +54 -0
  742. package/plugins/pbr/scripts/lib/todo.js +300 -0
  743. package/plugins/pbr/scripts/lib/trust-gate.js +84 -0
  744. package/plugins/pbr/scripts/local-llm/client.js +237 -0
  745. package/plugins/pbr/scripts/local-llm/health.js +220 -0
  746. package/plugins/pbr/scripts/local-llm/metrics.js +340 -0
  747. package/plugins/pbr/scripts/local-llm/operations/classify-artifact.js +76 -0
  748. package/plugins/pbr/scripts/local-llm/operations/classify-commit.js +137 -0
  749. package/plugins/pbr/scripts/local-llm/operations/classify-error.js +75 -0
  750. package/plugins/pbr/scripts/local-llm/operations/classify-file-intent.js +171 -0
  751. package/plugins/pbr/scripts/local-llm/operations/score-source.js +72 -0
  752. package/plugins/pbr/scripts/local-llm/operations/summarize-context.js +62 -0
  753. package/plugins/pbr/scripts/local-llm/operations/triage-test-output.js +72 -0
  754. package/plugins/pbr/scripts/local-llm/operations/validate-task.js +59 -0
  755. package/plugins/pbr/scripts/local-llm/router.js +101 -0
  756. package/plugins/pbr/scripts/local-llm/shadow.js +60 -0
  757. package/plugins/pbr/scripts/local-llm/threshold-tuner.js +118 -0
  758. package/plugins/pbr/scripts/log-subagent.js +129 -26
  759. package/plugins/pbr/scripts/log-tool-failure.js +58 -5
  760. package/plugins/pbr/scripts/milestone-learnings.js +569 -0
  761. package/plugins/pbr/scripts/package.json +1 -0
  762. package/plugins/pbr/scripts/pbr-tools.js +1361 -1214
  763. package/plugins/pbr/scripts/post-bash-triage.js +163 -0
  764. package/plugins/pbr/scripts/post-compact.js +135 -0
  765. package/plugins/pbr/scripts/post-hoc.js +286 -0
  766. package/plugins/pbr/scripts/post-write-dispatch.js +315 -30
  767. package/plugins/pbr/scripts/post-write-quality.js +3 -3
  768. package/plugins/pbr/scripts/pre-bash-dispatch.js +81 -4
  769. package/plugins/pbr/scripts/pre-write-dispatch.js +76 -20
  770. package/plugins/pbr/scripts/progress-tracker.js +145 -277
  771. package/plugins/pbr/scripts/quick-status.js +179 -0
  772. package/plugins/pbr/scripts/record-incident.js +37 -0
  773. package/plugins/pbr/scripts/risk-classifier.cjs +123 -0
  774. package/plugins/pbr/scripts/run-hook.js +49 -8
  775. package/plugins/pbr/scripts/session-cleanup.js +379 -7
  776. package/plugins/pbr/scripts/session-tracker.js +124 -0
  777. package/plugins/pbr/scripts/status-line.js +540 -27
  778. package/plugins/pbr/scripts/suggest-compact.js +183 -7
  779. package/plugins/pbr/scripts/sync-context-to-claude.js +100 -0
  780. package/plugins/pbr/scripts/task-completed.js +125 -3
  781. package/plugins/pbr/scripts/test/config.test.js +126 -0
  782. package/plugins/pbr/scripts/test/cross-platform.test.js +131 -0
  783. package/plugins/pbr/scripts/test/fixtures/config.json +20 -0
  784. package/plugins/pbr/scripts/test/fixtures/plan.md +54 -0
  785. package/plugins/pbr/scripts/test/fixtures/project.md +30 -0
  786. package/plugins/pbr/scripts/test/fixtures/roadmap.md +55 -0
  787. package/plugins/pbr/scripts/test/fixtures/state.md +60 -0
  788. package/plugins/pbr/scripts/test/fixtures/summary.md +35 -0
  789. package/plugins/pbr/scripts/test/fixtures.test.js +184 -0
  790. package/plugins/pbr/scripts/test/phase.test.js +142 -0
  791. package/plugins/pbr/scripts/test/roadmap.test.js +96 -0
  792. package/plugins/pbr/scripts/test/state.test.js +163 -0
  793. package/plugins/pbr/scripts/track-context-budget.js +323 -88
  794. package/plugins/pbr/scripts/trust-tracker.js +193 -0
  795. package/plugins/pbr/scripts/validate-commit.js +76 -11
  796. package/plugins/pbr/scripts/validate-skill-args.js +18 -14
  797. package/plugins/pbr/scripts/validate-task.js +93 -614
  798. package/plugins/pbr/scripts/worktree-create.js +144 -0
  799. package/plugins/pbr/scripts/worktree-remove.js +147 -0
  800. package/plugins/pbr/skills/audit/SKILL.md +478 -0
  801. package/plugins/pbr/skills/autonomous/SKILL.md +460 -0
  802. package/plugins/pbr/skills/begin/SKILL.md +447 -142
  803. package/plugins/pbr/skills/begin/templates/STATE.md.tmpl +1 -2
  804. package/plugins/pbr/skills/begin/templates/config.json.tmpl +423 -36
  805. package/plugins/pbr/skills/begin/templates/researcher-prompt.md.tmpl +28 -0
  806. package/plugins/pbr/skills/begin/templates/roadmap-prompt.md.tmpl +26 -3
  807. package/plugins/pbr/skills/begin/templates/synthesis-prompt.md.tmpl +33 -5
  808. package/plugins/pbr/skills/build/SKILL.md +1010 -327
  809. package/plugins/pbr/skills/build/templates/continuation-prompt.md.tmpl +26 -0
  810. package/plugins/pbr/skills/build/templates/executor-prompt.md.tmpl +77 -0
  811. package/plugins/pbr/skills/build/templates/inline-verifier-prompt.md.tmpl +33 -0
  812. package/plugins/pbr/skills/config/SKILL.md +108 -9
  813. package/plugins/pbr/skills/continue/SKILL.md +118 -19
  814. package/plugins/pbr/skills/dashboard/SKILL.md +21 -9
  815. package/plugins/pbr/skills/debug/SKILL.md +62 -10
  816. package/plugins/pbr/skills/debug/templates/continuation-prompt.md.tmpl +12 -1
  817. package/plugins/pbr/skills/debug/templates/initial-investigation-prompt.md.tmpl +12 -5
  818. package/plugins/pbr/skills/discuss/SKILL.md +155 -23
  819. package/plugins/pbr/skills/discuss/templates/CONTEXT.md.tmpl +21 -1
  820. package/plugins/pbr/skills/do/SKILL.md +119 -24
  821. package/plugins/pbr/skills/explore/SKILL.md +83 -16
  822. package/plugins/pbr/skills/health/SKILL.md +74 -17
  823. package/plugins/pbr/skills/help/SKILL.md +123 -39
  824. package/plugins/pbr/skills/import/SKILL.md +327 -13
  825. package/plugins/pbr/skills/intel/SKILL.md +131 -0
  826. package/plugins/pbr/skills/milestone/SKILL.md +342 -260
  827. package/plugins/pbr/skills/milestone/templates/audit-output.md.tmpl +76 -0
  828. package/plugins/pbr/skills/milestone/templates/complete-output.md.tmpl +32 -0
  829. package/plugins/pbr/skills/milestone/templates/edge-cases.md +54 -0
  830. package/plugins/pbr/skills/milestone/templates/gaps-output.md.tmpl +25 -0
  831. package/plugins/pbr/skills/milestone/templates/integration-checker-prompt.md.tmpl +25 -0
  832. package/plugins/pbr/skills/milestone/templates/new-output.md.tmpl +29 -0
  833. package/plugins/pbr/skills/note/SKILL.md +10 -2
  834. package/plugins/pbr/skills/pause/SKILL.md +51 -7
  835. package/plugins/pbr/skills/pause/templates/continue-here.md.tmpl +33 -52
  836. package/plugins/pbr/skills/plan/SKILL.md +418 -268
  837. package/plugins/pbr/skills/plan/templates/checker-prompt.md.tmpl +5 -2
  838. package/plugins/pbr/skills/plan/templates/completion-output.md.tmpl +27 -0
  839. package/plugins/pbr/skills/plan/templates/revision-prompt.md.tmpl +21 -5
  840. package/plugins/pbr/skills/profile/SKILL.md +183 -0
  841. package/plugins/pbr/skills/profile-user/SKILL.md +224 -0
  842. package/plugins/pbr/skills/quick/SKILL.md +440 -95
  843. package/plugins/pbr/skills/release/SKILL.md +206 -0
  844. package/plugins/pbr/skills/resume/SKILL.md +122 -27
  845. package/plugins/pbr/skills/review/SKILL.md +219 -154
  846. package/plugins/pbr/skills/review/templates/verifier-prompt.md.tmpl +7 -0
  847. package/plugins/pbr/skills/scan/SKILL.md +36 -12
  848. package/plugins/pbr/skills/scan/templates/mapper-prompt.md.tmpl +1 -1
  849. package/plugins/pbr/skills/session-report/SKILL.md +128 -0
  850. package/plugins/pbr/skills/setup/SKILL.md +149 -202
  851. package/plugins/pbr/skills/shared/agent-context-enrichment.md +21 -0
  852. package/plugins/pbr/skills/shared/agent-type-resolution.md +20 -0
  853. package/plugins/pbr/skills/shared/commit-planning-docs.md +8 -0
  854. package/plugins/pbr/skills/shared/context-budget.md +66 -1
  855. package/plugins/pbr/skills/shared/context-loader-task.md +15 -8
  856. package/plugins/pbr/skills/shared/digest-select.md +2 -2
  857. package/plugins/pbr/skills/shared/domain-probes.md +1 -1
  858. package/plugins/pbr/skills/shared/error-reporting.md +38 -60
  859. package/plugins/pbr/skills/shared/gate-prompts.md +4 -2
  860. package/plugins/pbr/skills/shared/memory-capture.md +48 -0
  861. package/plugins/pbr/skills/shared/phase-argument-parsing.md +4 -4
  862. package/plugins/pbr/skills/shared/revision-loop.md +24 -6
  863. package/plugins/pbr/skills/shared/state-update.md +47 -54
  864. package/plugins/pbr/skills/shared/universal-anti-patterns.md +27 -4
  865. package/plugins/pbr/skills/ship/SKILL.md +154 -0
  866. package/plugins/pbr/skills/status/SKILL.md +201 -53
  867. package/plugins/pbr/skills/test/SKILL.md +254 -0
  868. package/plugins/pbr/skills/todo/SKILL.md +13 -11
  869. package/plugins/pbr/skills/ui-phase/SKILL.md +179 -0
  870. package/plugins/pbr/skills/ui-review/SKILL.md +206 -0
  871. package/plugins/pbr/skills/undo/SKILL.md +218 -0
  872. package/plugins/pbr/skills/validate-phase/SKILL.md +358 -0
  873. package/plugins/pbr/templates/CONTEXT.md.tmpl +45 -20
  874. package/plugins/pbr/templates/DISCOVERY.md.tmpl +29 -0
  875. package/plugins/pbr/templates/HANDOFF.json.tmpl +30 -0
  876. package/plugins/pbr/templates/INTEGRATION-REPORT.md.tmpl +18 -2
  877. package/plugins/pbr/templates/KNOWLEDGE.md.tmpl +39 -0
  878. package/plugins/pbr/templates/MILESTONE-AUDIT.md.tmpl +44 -0
  879. package/plugins/pbr/templates/PROJECT.md.tmpl +126 -0
  880. package/plugins/pbr/templates/REQUIREMENTS.md.tmpl +96 -0
  881. package/plugins/pbr/templates/RETROSPECTIVE.md.tmpl +43 -0
  882. package/plugins/pbr/templates/ROADMAP.md.tmpl +108 -14
  883. package/plugins/pbr/templates/SUMMARY-complex.md.tmpl +133 -0
  884. package/plugins/pbr/templates/SUMMARY-minimal.md.tmpl +55 -0
  885. package/plugins/pbr/templates/SUMMARY.md.tmpl +21 -0
  886. package/plugins/pbr/templates/VERIFICATION-DETAIL.md.tmpl +49 -13
  887. package/plugins/pbr/templates/project-CONTEXT.md.tmpl +59 -0
  888. package/plugins/pbr/templates/research-outputs/ARCHITECTURE.md.tmpl +91 -0
  889. package/plugins/pbr/templates/research-outputs/FEATURES.md.tmpl +64 -0
  890. package/plugins/pbr/templates/research-outputs/PITFALLS.md.tmpl +50 -0
  891. package/plugins/pbr/templates/research-outputs/STACK.md.tmpl +63 -0
  892. package/plugins/pbr/templates/research-outputs/SUMMARY.md.tmpl +98 -0
  893. package/scripts/build-hooks.js +61 -0
  894. package/scripts/check-ci.js +100 -0
  895. package/scripts/clean-changelog.js +362 -0
  896. package/scripts/generate-derivatives.js +581 -0
  897. package/scripts/posttest.js +93 -0
  898. package/scripts/release.js +196 -0
  899. package/scripts/run-tests.cjs +29 -0
  900. package/dashboard/bin/cli.js +0 -25
  901. package/dashboard/public/css/layout.css +0 -472
  902. package/dashboard/public/css/status-colors.css +0 -98
  903. package/dashboard/public/js/htmx-title.js +0 -5
  904. package/dashboard/public/js/sidebar-toggle.js +0 -20
  905. package/dashboard/src/app.js +0 -78
  906. package/dashboard/src/middleware/errorHandler.js +0 -52
  907. package/dashboard/src/middleware/notFoundHandler.js +0 -9
  908. package/dashboard/src/repositories/planning.repository.js +0 -130
  909. package/dashboard/src/routes/events.routes.js +0 -40
  910. package/dashboard/src/routes/index.routes.js +0 -31
  911. package/dashboard/src/routes/pages.routes.js +0 -308
  912. package/dashboard/src/server.js +0 -42
  913. package/dashboard/src/services/dashboard.service.js +0 -309
  914. package/dashboard/src/services/milestone.service.js +0 -154
  915. package/dashboard/src/services/phase.service.js +0 -226
  916. package/dashboard/src/services/project.service.js +0 -57
  917. package/dashboard/src/services/roadmap.service.js +0 -171
  918. package/dashboard/src/services/sse.service.js +0 -58
  919. package/dashboard/src/services/todo.service.js +0 -254
  920. package/dashboard/src/services/watcher.service.js +0 -48
  921. package/dashboard/src/views/coming-soon.ejs +0 -11
  922. package/dashboard/src/views/error.ejs +0 -13
  923. package/dashboard/src/views/index.ejs +0 -5
  924. package/dashboard/src/views/layout.ejs +0 -1
  925. package/dashboard/src/views/milestone-detail.ejs +0 -5
  926. package/dashboard/src/views/milestones.ejs +0 -5
  927. package/dashboard/src/views/partials/dashboard-content.ejs +0 -77
  928. package/dashboard/src/views/partials/footer.ejs +0 -3
  929. package/dashboard/src/views/partials/head.ejs +0 -27
  930. package/dashboard/src/views/partials/header.ejs +0 -12
  931. package/dashboard/src/views/partials/layout-bottom.ejs +0 -15
  932. package/dashboard/src/views/partials/layout-top.ejs +0 -8
  933. package/dashboard/src/views/partials/milestone-detail-content.ejs +0 -19
  934. package/dashboard/src/views/partials/milestones-content.ejs +0 -44
  935. package/dashboard/src/views/partials/phase-content.ejs +0 -189
  936. package/dashboard/src/views/partials/phase-doc-content.ejs +0 -38
  937. package/dashboard/src/views/partials/phases-content.ejs +0 -117
  938. package/dashboard/src/views/partials/roadmap-content.ejs +0 -142
  939. package/dashboard/src/views/partials/sidebar.ejs +0 -46
  940. package/dashboard/src/views/partials/todo-create-content.ejs +0 -53
  941. package/dashboard/src/views/partials/todo-detail-content.ejs +0 -38
  942. package/dashboard/src/views/partials/todos-content.ejs +0 -53
  943. package/dashboard/src/views/phase-detail.ejs +0 -5
  944. package/dashboard/src/views/phase-doc.ejs +0 -5
  945. package/dashboard/src/views/phases.ejs +0 -5
  946. package/dashboard/src/views/roadmap.ejs +0 -5
  947. package/dashboard/src/views/todo-create.ejs +0 -5
  948. package/dashboard/src/views/todo-detail.ejs +0 -5
  949. package/dashboard/src/views/todos.ejs +0 -5
  950. package/plugins/copilot-pbr/CHANGELOG.md +0 -19
  951. package/plugins/copilot-pbr/README.md +0 -129
  952. package/plugins/copilot-pbr/agents/codebase-mapper.agent.md +0 -151
  953. package/plugins/copilot-pbr/agents/debugger.agent.md +0 -172
  954. package/plugins/copilot-pbr/agents/executor.agent.md +0 -267
  955. package/plugins/copilot-pbr/agents/general.agent.md +0 -88
  956. package/plugins/copilot-pbr/agents/integration-checker.agent.md +0 -119
  957. package/plugins/copilot-pbr/agents/plan-checker.agent.md +0 -199
  958. package/plugins/copilot-pbr/agents/planner.agent.md +0 -238
  959. package/plugins/copilot-pbr/agents/researcher.agent.md +0 -186
  960. package/plugins/copilot-pbr/agents/synthesizer.agent.md +0 -126
  961. package/plugins/copilot-pbr/agents/verifier.agent.md +0 -228
  962. package/plugins/copilot-pbr/hooks/hooks.json +0 -144
  963. package/plugins/copilot-pbr/plugin.json +0 -30
  964. package/plugins/copilot-pbr/references/agent-anti-patterns.md +0 -25
  965. package/plugins/copilot-pbr/references/agent-contracts.md +0 -297
  966. package/plugins/copilot-pbr/references/agent-interactions.md +0 -135
  967. package/plugins/copilot-pbr/references/agent-teams.md +0 -55
  968. package/plugins/copilot-pbr/references/checkpoints.md +0 -158
  969. package/plugins/copilot-pbr/references/common-bug-patterns.md +0 -14
  970. package/plugins/copilot-pbr/references/config-reference.md +0 -442
  971. package/plugins/copilot-pbr/references/continuation-format.md +0 -213
  972. package/plugins/copilot-pbr/references/deviation-rules.md +0 -113
  973. package/plugins/copilot-pbr/references/git-integration.md +0 -227
  974. package/plugins/copilot-pbr/references/integration-patterns.md +0 -118
  975. package/plugins/copilot-pbr/references/model-profiles.md +0 -100
  976. package/plugins/copilot-pbr/references/model-selection.md +0 -32
  977. package/plugins/copilot-pbr/references/pbr-rules.md +0 -195
  978. package/plugins/copilot-pbr/references/pbr-tools-cli.md +0 -285
  979. package/plugins/copilot-pbr/references/plan-authoring.md +0 -182
  980. package/plugins/copilot-pbr/references/plan-format.md +0 -288
  981. package/plugins/copilot-pbr/references/planning-config.md +0 -214
  982. package/plugins/copilot-pbr/references/questioning.md +0 -215
  983. package/plugins/copilot-pbr/references/reading-verification.md +0 -128
  984. package/plugins/copilot-pbr/references/stub-patterns.md +0 -161
  985. package/plugins/copilot-pbr/references/subagent-coordination.md +0 -120
  986. package/plugins/copilot-pbr/references/ui-formatting.md +0 -444
  987. package/plugins/copilot-pbr/references/verification-patterns.md +0 -199
  988. package/plugins/copilot-pbr/references/wave-execution.md +0 -96
  989. package/plugins/copilot-pbr/rules/pbr-workflow.mdc +0 -48
  990. package/plugins/copilot-pbr/setup.ps1 +0 -93
  991. package/plugins/copilot-pbr/setup.sh +0 -93
  992. package/plugins/copilot-pbr/skills/begin/SKILL.md +0 -589
  993. package/plugins/copilot-pbr/skills/begin/templates/PROJECT.md.tmpl +0 -34
  994. package/plugins/copilot-pbr/skills/begin/templates/REQUIREMENTS.md.tmpl +0 -19
  995. package/plugins/copilot-pbr/skills/begin/templates/STATE.md.tmpl +0 -50
  996. package/plugins/copilot-pbr/skills/begin/templates/config.json.tmpl +0 -64
  997. package/plugins/copilot-pbr/skills/begin/templates/researcher-prompt.md.tmpl +0 -20
  998. package/plugins/copilot-pbr/skills/begin/templates/roadmap-prompt.md.tmpl +0 -31
  999. package/plugins/copilot-pbr/skills/begin/templates/synthesis-prompt.md.tmpl +0 -17
  1000. package/plugins/copilot-pbr/skills/build/SKILL.md +0 -955
  1001. package/plugins/copilot-pbr/skills/config/SKILL.md +0 -250
  1002. package/plugins/copilot-pbr/skills/continue/SKILL.md +0 -159
  1003. package/plugins/copilot-pbr/skills/dashboard/SKILL.md +0 -43
  1004. package/plugins/copilot-pbr/skills/debug/SKILL.md +0 -508
  1005. package/plugins/copilot-pbr/skills/debug/templates/continuation-prompt.md.tmpl +0 -17
  1006. package/plugins/copilot-pbr/skills/debug/templates/initial-investigation-prompt.md.tmpl +0 -28
  1007. package/plugins/copilot-pbr/skills/discuss/SKILL.md +0 -353
  1008. package/plugins/copilot-pbr/skills/discuss/templates/CONTEXT.md.tmpl +0 -62
  1009. package/plugins/copilot-pbr/skills/discuss/templates/decision-categories.md +0 -10
  1010. package/plugins/copilot-pbr/skills/do/SKILL.md +0 -66
  1011. package/plugins/copilot-pbr/skills/explore/SKILL.md +0 -373
  1012. package/plugins/copilot-pbr/skills/health/SKILL.md +0 -274
  1013. package/plugins/copilot-pbr/skills/health/templates/check-pattern.md.tmpl +0 -31
  1014. package/plugins/copilot-pbr/skills/health/templates/output-format.md.tmpl +0 -64
  1015. package/plugins/copilot-pbr/skills/help/SKILL.md +0 -152
  1016. package/plugins/copilot-pbr/skills/import/SKILL.md +0 -502
  1017. package/plugins/copilot-pbr/skills/milestone/SKILL.md +0 -745
  1018. package/plugins/copilot-pbr/skills/milestone/templates/audit-report.md.tmpl +0 -49
  1019. package/plugins/copilot-pbr/skills/milestone/templates/stats-file.md.tmpl +0 -31
  1020. package/plugins/copilot-pbr/skills/note/SKILL.md +0 -213
  1021. package/plugins/copilot-pbr/skills/pause/SKILL.md +0 -247
  1022. package/plugins/copilot-pbr/skills/pause/templates/continue-here.md.tmpl +0 -72
  1023. package/plugins/copilot-pbr/skills/plan/SKILL.md +0 -662
  1024. package/plugins/copilot-pbr/skills/plan/templates/checker-prompt.md.tmpl +0 -22
  1025. package/plugins/copilot-pbr/skills/plan/templates/gap-closure-prompt.md.tmpl +0 -33
  1026. package/plugins/copilot-pbr/skills/plan/templates/planner-prompt.md.tmpl +0 -39
  1027. package/plugins/copilot-pbr/skills/plan/templates/researcher-prompt.md.tmpl +0 -20
  1028. package/plugins/copilot-pbr/skills/plan/templates/revision-prompt.md.tmpl +0 -24
  1029. package/plugins/copilot-pbr/skills/quick/SKILL.md +0 -376
  1030. package/plugins/copilot-pbr/skills/resume/SKILL.md +0 -399
  1031. package/plugins/copilot-pbr/skills/review/SKILL.md +0 -653
  1032. package/plugins/copilot-pbr/skills/review/templates/debugger-prompt.md.tmpl +0 -61
  1033. package/plugins/copilot-pbr/skills/review/templates/gap-planner-prompt.md.tmpl +0 -41
  1034. package/plugins/copilot-pbr/skills/review/templates/verifier-prompt.md.tmpl +0 -116
  1035. package/plugins/copilot-pbr/skills/scan/SKILL.md +0 -299
  1036. package/plugins/copilot-pbr/skills/scan/templates/mapper-prompt.md.tmpl +0 -202
  1037. package/plugins/copilot-pbr/skills/setup/SKILL.md +0 -296
  1038. package/plugins/copilot-pbr/skills/shared/commit-planning-docs.md +0 -36
  1039. package/plugins/copilot-pbr/skills/shared/config-loading.md +0 -103
  1040. package/plugins/copilot-pbr/skills/shared/context-budget.md +0 -41
  1041. package/plugins/copilot-pbr/skills/shared/context-loader-task.md +0 -87
  1042. package/plugins/copilot-pbr/skills/shared/digest-select.md +0 -80
  1043. package/plugins/copilot-pbr/skills/shared/domain-probes.md +0 -126
  1044. package/plugins/copilot-pbr/skills/shared/error-reporting.md +0 -81
  1045. package/plugins/copilot-pbr/skills/shared/gate-prompts.md +0 -389
  1046. package/plugins/copilot-pbr/skills/shared/phase-argument-parsing.md +0 -46
  1047. package/plugins/copilot-pbr/skills/shared/progress-display.md +0 -53
  1048. package/plugins/copilot-pbr/skills/shared/revision-loop.md +0 -82
  1049. package/plugins/copilot-pbr/skills/shared/state-loading.md +0 -63
  1050. package/plugins/copilot-pbr/skills/shared/state-update.md +0 -162
  1051. package/plugins/copilot-pbr/skills/shared/universal-anti-patterns.md +0 -38
  1052. package/plugins/copilot-pbr/skills/status/SKILL.md +0 -362
  1053. package/plugins/copilot-pbr/skills/statusline/SKILL.md +0 -149
  1054. package/plugins/copilot-pbr/skills/todo/SKILL.md +0 -279
  1055. package/plugins/copilot-pbr/templates/CONTEXT.md.tmpl +0 -53
  1056. package/plugins/copilot-pbr/templates/INTEGRATION-REPORT.md.tmpl +0 -152
  1057. package/plugins/copilot-pbr/templates/RESEARCH-SUMMARY.md.tmpl +0 -98
  1058. package/plugins/copilot-pbr/templates/ROADMAP.md.tmpl +0 -41
  1059. package/plugins/copilot-pbr/templates/SUMMARY.md.tmpl +0 -82
  1060. package/plugins/copilot-pbr/templates/VERIFICATION-DETAIL.md.tmpl +0 -117
  1061. package/plugins/copilot-pbr/templates/codebase/ARCHITECTURE.md.tmpl +0 -98
  1062. package/plugins/copilot-pbr/templates/codebase/CONCERNS.md.tmpl +0 -93
  1063. package/plugins/copilot-pbr/templates/codebase/CONVENTIONS.md.tmpl +0 -104
  1064. package/plugins/copilot-pbr/templates/codebase/INTEGRATIONS.md.tmpl +0 -78
  1065. package/plugins/copilot-pbr/templates/codebase/STACK.md.tmpl +0 -78
  1066. package/plugins/copilot-pbr/templates/codebase/STRUCTURE.md.tmpl +0 -80
  1067. package/plugins/copilot-pbr/templates/codebase/TESTING.md.tmpl +0 -107
  1068. package/plugins/copilot-pbr/templates/continue-here.md.tmpl +0 -74
  1069. package/plugins/copilot-pbr/templates/prompt-partials/phase-project-context.md.tmpl +0 -38
  1070. package/plugins/copilot-pbr/templates/research/ARCHITECTURE.md.tmpl +0 -124
  1071. package/plugins/copilot-pbr/templates/research/STACK.md.tmpl +0 -71
  1072. package/plugins/copilot-pbr/templates/research/SUMMARY.md.tmpl +0 -112
  1073. package/plugins/copilot-pbr/templates/research-outputs/phase-research.md.tmpl +0 -81
  1074. package/plugins/copilot-pbr/templates/research-outputs/project-research.md.tmpl +0 -99
  1075. package/plugins/copilot-pbr/templates/research-outputs/synthesis.md.tmpl +0 -36
  1076. package/plugins/cursor-pbr/.cursor-plugin/plugin.json +0 -32
  1077. package/plugins/cursor-pbr/CHANGELOG.md +0 -15
  1078. package/plugins/cursor-pbr/README.md +0 -118
  1079. package/plugins/cursor-pbr/agents/codebase-mapper.md +0 -150
  1080. package/plugins/cursor-pbr/agents/debugger.md +0 -171
  1081. package/plugins/cursor-pbr/agents/executor.md +0 -266
  1082. package/plugins/cursor-pbr/agents/general.md +0 -87
  1083. package/plugins/cursor-pbr/agents/integration-checker.md +0 -118
  1084. package/plugins/cursor-pbr/agents/plan-checker.md +0 -198
  1085. package/plugins/cursor-pbr/agents/planner.md +0 -237
  1086. package/plugins/cursor-pbr/agents/researcher.md +0 -185
  1087. package/plugins/cursor-pbr/agents/synthesizer.md +0 -125
  1088. package/plugins/cursor-pbr/agents/verifier.md +0 -227
  1089. package/plugins/cursor-pbr/assets/.gitkeep +0 -0
  1090. package/plugins/cursor-pbr/assets/logo.svg +0 -21
  1091. package/plugins/cursor-pbr/hooks/hooks.json +0 -203
  1092. package/plugins/cursor-pbr/references/agent-anti-patterns.md +0 -25
  1093. package/plugins/cursor-pbr/references/agent-contracts.md +0 -297
  1094. package/plugins/cursor-pbr/references/agent-interactions.md +0 -135
  1095. package/plugins/cursor-pbr/references/agent-teams.md +0 -55
  1096. package/plugins/cursor-pbr/references/checkpoints.md +0 -158
  1097. package/plugins/cursor-pbr/references/common-bug-patterns.md +0 -14
  1098. package/plugins/cursor-pbr/references/config-reference.md +0 -442
  1099. package/plugins/cursor-pbr/references/continuation-format.md +0 -213
  1100. package/plugins/cursor-pbr/references/deviation-rules.md +0 -113
  1101. package/plugins/cursor-pbr/references/git-integration.md +0 -227
  1102. package/plugins/cursor-pbr/references/integration-patterns.md +0 -118
  1103. package/plugins/cursor-pbr/references/model-profiles.md +0 -100
  1104. package/plugins/cursor-pbr/references/model-selection.md +0 -32
  1105. package/plugins/cursor-pbr/references/pbr-rules.md +0 -195
  1106. package/plugins/cursor-pbr/references/pbr-tools-cli.md +0 -285
  1107. package/plugins/cursor-pbr/references/plan-authoring.md +0 -182
  1108. package/plugins/cursor-pbr/references/plan-format.md +0 -288
  1109. package/plugins/cursor-pbr/references/planning-config.md +0 -214
  1110. package/plugins/cursor-pbr/references/questioning.md +0 -215
  1111. package/plugins/cursor-pbr/references/reading-verification.md +0 -128
  1112. package/plugins/cursor-pbr/references/stub-patterns.md +0 -161
  1113. package/plugins/cursor-pbr/references/subagent-coordination.md +0 -120
  1114. package/plugins/cursor-pbr/references/ui-formatting.md +0 -444
  1115. package/plugins/cursor-pbr/references/verification-patterns.md +0 -199
  1116. package/plugins/cursor-pbr/references/wave-execution.md +0 -96
  1117. package/plugins/cursor-pbr/rules/pbr-workflow.mdc +0 -48
  1118. package/plugins/cursor-pbr/setup.ps1 +0 -78
  1119. package/plugins/cursor-pbr/setup.sh +0 -83
  1120. package/plugins/cursor-pbr/skills/begin/SKILL.md +0 -589
  1121. package/plugins/cursor-pbr/skills/begin/templates/PROJECT.md.tmpl +0 -34
  1122. package/plugins/cursor-pbr/skills/begin/templates/REQUIREMENTS.md.tmpl +0 -19
  1123. package/plugins/cursor-pbr/skills/begin/templates/STATE.md.tmpl +0 -50
  1124. package/plugins/cursor-pbr/skills/begin/templates/config.json.tmpl +0 -64
  1125. package/plugins/cursor-pbr/skills/begin/templates/researcher-prompt.md.tmpl +0 -20
  1126. package/plugins/cursor-pbr/skills/begin/templates/roadmap-prompt.md.tmpl +0 -31
  1127. package/plugins/cursor-pbr/skills/begin/templates/synthesis-prompt.md.tmpl +0 -17
  1128. package/plugins/cursor-pbr/skills/build/SKILL.md +0 -956
  1129. package/plugins/cursor-pbr/skills/config/SKILL.md +0 -252
  1130. package/plugins/cursor-pbr/skills/continue/SKILL.md +0 -159
  1131. package/plugins/cursor-pbr/skills/dashboard/SKILL.md +0 -44
  1132. package/plugins/cursor-pbr/skills/debug/SKILL.md +0 -512
  1133. package/plugins/cursor-pbr/skills/debug/templates/continuation-prompt.md.tmpl +0 -17
  1134. package/plugins/cursor-pbr/skills/debug/templates/initial-investigation-prompt.md.tmpl +0 -28
  1135. package/plugins/cursor-pbr/skills/discuss/SKILL.md +0 -354
  1136. package/plugins/cursor-pbr/skills/discuss/templates/CONTEXT.md.tmpl +0 -62
  1137. package/plugins/cursor-pbr/skills/discuss/templates/decision-categories.md +0 -10
  1138. package/plugins/cursor-pbr/skills/do/SKILL.md +0 -67
  1139. package/plugins/cursor-pbr/skills/explore/SKILL.md +0 -376
  1140. package/plugins/cursor-pbr/skills/health/SKILL.md +0 -274
  1141. package/plugins/cursor-pbr/skills/health/templates/check-pattern.md.tmpl +0 -31
  1142. package/plugins/cursor-pbr/skills/health/templates/output-format.md.tmpl +0 -64
  1143. package/plugins/cursor-pbr/skills/help/SKILL.md +0 -152
  1144. package/plugins/cursor-pbr/skills/import/SKILL.md +0 -505
  1145. package/plugins/cursor-pbr/skills/milestone/SKILL.md +0 -746
  1146. package/plugins/cursor-pbr/skills/milestone/templates/audit-report.md.tmpl +0 -49
  1147. package/plugins/cursor-pbr/skills/milestone/templates/stats-file.md.tmpl +0 -31
  1148. package/plugins/cursor-pbr/skills/note/SKILL.md +0 -214
  1149. package/plugins/cursor-pbr/skills/pause/SKILL.md +0 -248
  1150. package/plugins/cursor-pbr/skills/pause/templates/continue-here.md.tmpl +0 -72
  1151. package/plugins/cursor-pbr/skills/plan/SKILL.md +0 -663
  1152. package/plugins/cursor-pbr/skills/plan/templates/checker-prompt.md.tmpl +0 -22
  1153. package/plugins/cursor-pbr/skills/plan/templates/gap-closure-prompt.md.tmpl +0 -33
  1154. package/plugins/cursor-pbr/skills/plan/templates/planner-prompt.md.tmpl +0 -39
  1155. package/plugins/cursor-pbr/skills/plan/templates/researcher-prompt.md.tmpl +0 -20
  1156. package/plugins/cursor-pbr/skills/plan/templates/revision-prompt.md.tmpl +0 -24
  1157. package/plugins/cursor-pbr/skills/quick/SKILL.md +0 -376
  1158. package/plugins/cursor-pbr/skills/resume/SKILL.md +0 -399
  1159. package/plugins/cursor-pbr/skills/review/SKILL.md +0 -654
  1160. package/plugins/cursor-pbr/skills/review/templates/debugger-prompt.md.tmpl +0 -61
  1161. package/plugins/cursor-pbr/skills/review/templates/gap-planner-prompt.md.tmpl +0 -41
  1162. package/plugins/cursor-pbr/skills/review/templates/verifier-prompt.md.tmpl +0 -116
  1163. package/plugins/cursor-pbr/skills/scan/SKILL.md +0 -300
  1164. package/plugins/cursor-pbr/skills/scan/templates/mapper-prompt.md.tmpl +0 -202
  1165. package/plugins/cursor-pbr/skills/setup/SKILL.md +0 -296
  1166. package/plugins/cursor-pbr/skills/shared/commit-planning-docs.md +0 -36
  1167. package/plugins/cursor-pbr/skills/shared/config-loading.md +0 -103
  1168. package/plugins/cursor-pbr/skills/shared/context-budget.md +0 -41
  1169. package/plugins/cursor-pbr/skills/shared/context-loader-task.md +0 -87
  1170. package/plugins/cursor-pbr/skills/shared/digest-select.md +0 -80
  1171. package/plugins/cursor-pbr/skills/shared/domain-probes.md +0 -126
  1172. package/plugins/cursor-pbr/skills/shared/error-reporting.md +0 -81
  1173. package/plugins/cursor-pbr/skills/shared/gate-prompts.md +0 -389
  1174. package/plugins/cursor-pbr/skills/shared/phase-argument-parsing.md +0 -46
  1175. package/plugins/cursor-pbr/skills/shared/progress-display.md +0 -53
  1176. package/plugins/cursor-pbr/skills/shared/revision-loop.md +0 -82
  1177. package/plugins/cursor-pbr/skills/shared/state-loading.md +0 -63
  1178. package/plugins/cursor-pbr/skills/shared/state-update.md +0 -162
  1179. package/plugins/cursor-pbr/skills/shared/universal-anti-patterns.md +0 -38
  1180. package/plugins/cursor-pbr/skills/status/SKILL.md +0 -362
  1181. package/plugins/cursor-pbr/skills/statusline/SKILL.md +0 -150
  1182. package/plugins/cursor-pbr/skills/todo/SKILL.md +0 -280
  1183. package/plugins/cursor-pbr/templates/CONTEXT.md.tmpl +0 -53
  1184. package/plugins/cursor-pbr/templates/INTEGRATION-REPORT.md.tmpl +0 -152
  1185. package/plugins/cursor-pbr/templates/RESEARCH-SUMMARY.md.tmpl +0 -98
  1186. package/plugins/cursor-pbr/templates/ROADMAP.md.tmpl +0 -41
  1187. package/plugins/cursor-pbr/templates/SUMMARY.md.tmpl +0 -82
  1188. package/plugins/cursor-pbr/templates/VERIFICATION-DETAIL.md.tmpl +0 -117
  1189. package/plugins/cursor-pbr/templates/codebase/ARCHITECTURE.md.tmpl +0 -98
  1190. package/plugins/cursor-pbr/templates/codebase/CONCERNS.md.tmpl +0 -93
  1191. package/plugins/cursor-pbr/templates/codebase/CONVENTIONS.md.tmpl +0 -104
  1192. package/plugins/cursor-pbr/templates/codebase/INTEGRATIONS.md.tmpl +0 -78
  1193. package/plugins/cursor-pbr/templates/codebase/STACK.md.tmpl +0 -78
  1194. package/plugins/cursor-pbr/templates/codebase/STRUCTURE.md.tmpl +0 -80
  1195. package/plugins/cursor-pbr/templates/codebase/TESTING.md.tmpl +0 -107
  1196. package/plugins/cursor-pbr/templates/continue-here.md.tmpl +0 -74
  1197. package/plugins/cursor-pbr/templates/prompt-partials/phase-project-context.md.tmpl +0 -38
  1198. package/plugins/cursor-pbr/templates/research/ARCHITECTURE.md.tmpl +0 -124
  1199. package/plugins/cursor-pbr/templates/research/STACK.md.tmpl +0 -71
  1200. package/plugins/cursor-pbr/templates/research/SUMMARY.md.tmpl +0 -112
  1201. package/plugins/cursor-pbr/templates/research-outputs/phase-research.md.tmpl +0 -81
  1202. package/plugins/cursor-pbr/templates/research-outputs/project-research.md.tmpl +0 -99
  1203. package/plugins/cursor-pbr/templates/research-outputs/synthesis.md.tmpl +0 -36
  1204. package/plugins/pbr/references/agent-interactions.md +0 -134
  1205. package/plugins/pbr/references/checkpoints.md +0 -157
  1206. package/plugins/pbr/references/pbr-rules.md +0 -194
  1207. package/plugins/pbr/references/planning-config.md +0 -213
  1208. package/plugins/pbr/references/subagent-coordination.md +0 -119
  1209. package/plugins/pbr/references/ui-formatting.md +0 -444
  1210. package/plugins/pbr/references/verification-patterns.md +0 -198
  1211. package/plugins/pbr/scripts/validate-plugin-structure.js +0 -183
  1212. package/plugins/pbr/skills/milestone/templates/audit-report.md.tmpl +0 -48
  1213. package/plugins/pbr/skills/shared/progress-display.md +0 -53
  1214. package/plugins/pbr/skills/shared/state-loading.md +0 -62
  1215. package/plugins/pbr/templates/RESEARCH-SUMMARY.md.tmpl +0 -97
  1216. package/plugins/pbr/templates/research/ARCHITECTURE.md.tmpl +0 -124
  1217. package/plugins/pbr/templates/research/STACK.md.tmpl +0 -71
  1218. package/plugins/pbr/templates/research/SUMMARY.md.tmpl +0 -112
  1219. package/plugins/pbr/templates/research-outputs/phase-research.md.tmpl +0 -81
  1220. package/plugins/pbr/templates/research-outputs/project-research.md.tmpl +0 -99
  1221. package/plugins/pbr/templates/research-outputs/synthesis.md.tmpl +0 -36
  1222. /package/plugins/pbr/references/{agent-anti-patterns.md → archive/agent-anti-patterns.md} +0 -0
@@ -0,0 +1,1877 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * PBR Tools -- CLI dispatcher for Plan-Build-Run workflow operations
5
+ *
6
+ * Thin dispatcher that imports from lib/ modules. All core logic lives in:
7
+ * lib/core.cjs -- Foundation utilities (parsers, file ops, constants)
8
+ * lib/config.cjs -- Config loading, validation, depth profiles
9
+ * lib/state.cjs -- STATE.md operations (load, update, patch, advance)
10
+ * lib/roadmap.cjs -- ROADMAP.md operations (parse, update status/plans)
11
+ * lib/phase.cjs -- Phase operations (add, remove, list, info, plan-index)
12
+ * lib/init.cjs -- Compound init commands (execute-phase, plan-phase, etc.)
13
+ * lib/history.cjs -- History operations (append, load)
14
+ * lib/todo.cjs -- Todo operations (list, get, add, done)
15
+ * lib/build.cjs -- Build pipeline (staleness, gates, checkpoints, seeds, CI)
16
+ * lib/learnings.cjs -- Learning ingestion, query, threshold checks
17
+ * lib/local-llm/ -- Local LLM operations (health, classify, score, summarize)
18
+ * lib/verify.cjs -- Verification suite + consistency/health validation
19
+ * lib/frontmatter.cjs -- Frontmatter CRUD
20
+ * lib/commands.cjs -- Standalone utility commands (commit, scaffold, etc.)
21
+ * lib/template.cjs -- Template selection and fill
22
+ * lib/milestone.cjs -- Milestone and requirements lifecycle
23
+ *
24
+ * Skills/agents call this via:
25
+ * node pbr-tools.cjs <command> [args] [--raw] [--cwd <path>]
26
+ *
27
+ * Environment: PBR_PROJECT_ROOT -- Override project root directory
28
+ *
29
+ * Commands:
30
+ *
31
+ * STATE OPERATIONS:
32
+ * state load Full project state as JSON
33
+ * state check-progress Recalculate progress from filesystem
34
+ * state update <field> <value> Atomically update a STATE.md field
35
+ * state get [section] Get STATE.md content or section
36
+ * state json Output STATE.md frontmatter as JSON
37
+ * state patch --field val ... Batch update STATE.md fields
38
+ * state advance-plan Increment plan counter
39
+ * state record-metric --phase N Record execution metrics
40
+ * --plan M --duration Xmin [--tasks N] [--files N]
41
+ * state update-progress Recalculate progress bar
42
+ * state add-decision --summary "..." Add decision to STATE.md
43
+ * [--phase N] [--rationale "..."] [--summary-file path] [--rationale-file path]
44
+ * state add-blocker --text "..." Add blocker
45
+ * state resolve-blocker --text "..." Remove blocker
46
+ * state record-session --stopped-at "..." [--resume-file path]
47
+ * state record-activity <description> Record activity in STATE.md
48
+ * state phase-complete <N> Mark phase complete in STATE.md
49
+ * state rederive Re-derive state from filesystem, fix drift
50
+ * state reconcile Reconcile STATE.md with ROADMAP.md phase counts
51
+ * state-bundle <phase> Full state bundle for a phase
52
+ * state-snapshot Structured parse of STATE.md
53
+ *
54
+ * CONFIG OPERATIONS:
55
+ * config validate Validate config.json against schema
56
+ * config load-defaults Load user defaults from home dir
57
+ * config save-defaults Save current config as user defaults
58
+ * config resolve-depth [dir] Resolve depth profile from config
59
+ * config get <key> Get a config value by dotted key
60
+ * config set <key> <value> Set a config value
61
+ * config-ensure-section Initialize .planning/config.json
62
+ * config-get <key> Legacy alias for config get
63
+ * config-set <key> <value> Legacy alias for config set
64
+ *
65
+ * PHASE OPERATIONS:
66
+ * phase add <slug> [--after N] [--goal "..."] [--depends-on N]
67
+ * phase remove <N> Remove an empty phase directory
68
+ * phase list List all phase directories with status
69
+ * phase complete <N> Mark phase done, advance STATE.md
70
+ * phase insert <N> <slug> [--goal "..."] [--depends-on N]
71
+ * phase info <N> Comprehensive single-phase status
72
+ * phase commits-for <N> Read phase manifest, output commits JSON
73
+ * phase first-last-commit <N> Output first/last commit hashes
74
+ * phase next-decimal <phase> Calculate next decimal phase number
75
+ * phases list [--type T] [--phase N] [--include-archived]
76
+ * phase-info <N> Alias for phase info
77
+ * phase-plan-index <phase> Index plans with waves and status
78
+ * find-phase <phase> Find phase directory by number
79
+ * plan-index <phase> Plan inventory for a phase
80
+ * must-haves <phase> Collect all must-haves from phase plans
81
+ *
82
+ * ROADMAP OPERATIONS:
83
+ * roadmap get-phase <phase> Extract phase section from ROADMAP.md
84
+ * roadmap analyze Full roadmap parse with disk status
85
+ * roadmap update-plan-progress <N> Update progress table row from disk
86
+ * roadmap update-status <N> <status> Update phase status in ROADMAP.md
87
+ * roadmap update-plans <N> <c> <t> Update phase plans in ROADMAP.md
88
+ * roadmap append-phase <slug> ... Append new phase to roadmap
89
+ * roadmap remove-phase <N> Remove phase from roadmap
90
+ * roadmap insert-phase <N> <slug> Insert phase into roadmap
91
+ *
92
+ * INIT (COMPOUND COMMANDS):
93
+ * init execute-phase <phase> All context for execute-phase workflow
94
+ * init plan-phase <phase> All context for plan-phase workflow
95
+ * init new-project All context for new-project workflow
96
+ * init new-milestone All context for new-milestone workflow
97
+ * init quick <description> All context for quick workflow
98
+ * init resume All context for resume-project workflow
99
+ * init verify-work <phase> All context for verify-work workflow
100
+ * init phase-op <phase> Generic phase operation context
101
+ * init todos [area] All context for todo workflows
102
+ * init milestone-op All context for milestone operations
103
+ * init map-codebase All context for map-codebase workflow
104
+ * init progress All context for progress workflow
105
+ *
106
+ * TODO OPERATIONS:
107
+ * todo list [--theme T] [--status S] List todos as JSON
108
+ * todo get <NNN> Get a specific todo by number
109
+ * todo add <title> [--priority P] [--theme T] [--source S]
110
+ * todo done <NNN> Mark a todo as complete
111
+ *
112
+ * HISTORY:
113
+ * history append <type> <title> [body] Append record to STATE.md History
114
+ * history load Load history records as JSON
115
+ * history-digest Aggregate all SUMMARY.md data
116
+ *
117
+ * LEARNINGS:
118
+ * learnings ingest <json-file> Ingest a learning entry
119
+ * learnings query [--tags X] [--min-confidence Y] [--stack S] [--type T]
120
+ * learnings check-thresholds Check deferral trigger conditions
121
+ * learnings copy-global <path> <proj> Copy cross_project LEARNINGS.md to ~/.claude/pbr-knowledge/
122
+ * learnings query-global [--tags X] [--project P] Query global knowledge files
123
+ * learnings aggregate [--project P] [--type T] [--top N]
124
+ *
125
+ * PATTERNS (Phase 16: Cross-project pattern library):
126
+ * patterns extract <json-file> Extract pattern into ~/.claude/patterns/
127
+ * patterns query [--tags X,Y] [--type T] [--stack S] [--min-confidence N]
128
+ * patterns list List all stored patterns
129
+ *
130
+ * TEMPLATES (Phase 16: Spec templates):
131
+ * templates list List built-in + user templates
132
+ * templates instantiate <name> [--param key=value ...]
133
+ *
134
+ * NEGATIVE KNOWLEDGE:
135
+ * negative-knowledge record --title "..." --category <cat> --files "a,b" --what-tried "..." --why-failed "..."
136
+ * negative-knowledge query --files "path1,path2"
137
+ * negative-knowledge list [--category X] [--phase Y] [--status Z]
138
+ *
139
+ * INCIDENTS:
140
+ * incidents record --source hook --type block --issue "..." [--severity warning] [--session-id S] [--context '{}'] [--auto-fixed] [--resolution "..."] [--duration-ms N]
141
+ * incidents list [--limit N]
142
+ * incidents query [--type T] [--severity S] [--source X] [--last Nd] [--session-id ID]
143
+ * incidents summary
144
+ *
145
+ * INTEL OPERATIONS:
146
+ * intel query <term> Search intel files for a term
147
+ * intel update Trigger intel refresh (prints agent instructions)
148
+ * intel status Show staleness info for intel files
149
+ * intel diff Show changes since last full refresh
150
+ * intel snapshot Save refresh snapshot (.last-refresh.json)
151
+ * intel validate Validate all intel files for correctness
152
+ * intel extract-exports <filepath> Extract exports from a JS/CJS file
153
+ * intel patch-meta <filepath> Patch _meta.updated_at to current timestamp
154
+ *
155
+ * BUILD PIPELINE:
156
+ * staleness-check <phase-slug> Check if phase plans are stale
157
+ * summary-gate <phase-slug> <plan-id> Verify SUMMARY.md for a plan
158
+ * checkpoint init <slug> [--plans ids] Initialize checkpoint manifest
159
+ * checkpoint update <slug> --wave N --resolved id [--sha hash]
160
+ * seeds match <slug> <phase-number> Find matching seed files
161
+ * ci-poll <run-id> [--timeout <secs>] Poll CI run status
162
+ * rollback <manifest-path> Rollback from manifest
163
+ * build-preview <phase-slug> Preview what build would do
164
+ *
165
+ * LLM OPERATIONS:
166
+ * llm health Check local LLM availability
167
+ * llm status Show LLM config status
168
+ * llm classify <PLAN|SUMMARY> <file> Classify artifact via LLM
169
+ * llm score-source <url> <file> Score a source via LLM
170
+ * llm classify-error <file> [agent] Classify error via LLM
171
+ * llm summarize <file> [max-words] Summarize context via LLM
172
+ * llm metrics [--session <ISO>] LLM usage metrics
173
+ * llm adjust-thresholds Suggest threshold adjustments
174
+ *
175
+ * SESSION:
176
+ * session get <key> [--session-id <id>]
177
+ * session set <key> <value> [--session-id <id>]
178
+ * session clear [key] [--session-id <id>]
179
+ * session dump [--session-id <id>]
180
+ *
181
+ * CLAIMS:
182
+ * claim acquire <slug> --session-id <id> --skill <name>
183
+ * claim release <slug> --session-id <id>
184
+ * claim list
185
+ *
186
+ * VERIFICATION:
187
+ * verify plan-structure <file> Check PLAN.md structure + tasks
188
+ * verify phase-completeness <phase> Check all plans have summaries
189
+ * verify references <file> Check @-refs + paths resolve
190
+ * verify commits <h1> [h2] ... Batch verify commit hashes
191
+ * verify artifacts <plan-file> Check must_haves.artifacts
192
+ * verify key-links <plan-file> Check must_haves.key_links
193
+ * verify-summary <path> Verify a SUMMARY.md file
194
+ * validate consistency Check phase/roadmap sync
195
+ * validate health [--repair] Check .planning/ integrity
196
+ * validate-project Comprehensive integrity check
197
+ *
198
+ * FRONTMATTER:
199
+ * frontmatter get <file> [--field k]
200
+ * frontmatter set <file> --field k --value v
201
+ * frontmatter merge <file> --data '{json}'
202
+ * frontmatter validate <file> --schema plan|summary|verification
203
+ * frontmatter <filepath> Parse frontmatter (reference compat)
204
+ *
205
+ * TEMPLATES:
206
+ * template select <plan-path> Select template type for a plan
207
+ * template fill summary|plan|verification --phase N [options]
208
+ *
209
+ * MILESTONES:
210
+ * milestone complete <version> [--name <name>] [--archive-phases]
211
+ * milestone stats <version> Milestone statistics
212
+ * milestone-stats <version> Alias for milestone stats
213
+ *
214
+ * REQUIREMENTS:
215
+ * requirements mark-complete <ids> Mark requirement IDs as complete
216
+ * requirements update-status Update REQ-ID checkboxes (--req-ids, --status done|reset)
217
+ * requirements mark-phase Mark phase requirements (--phase-dir <path>)
218
+ * requirements status Get all requirement statuses as JSON
219
+ *
220
+ * SCAFFOLDING:
221
+ * scaffold context|uat|verification|phase-dir --phase <N> [--name <name>]
222
+ *
223
+ * UTILITY:
224
+ * resolve-model <agent-type> Get model for agent based on profile
225
+ * generate-slug <text> Convert text to URL-safe slug
226
+ * slug-generate <text> Alias for generate-slug
227
+ * quick init <description> Create quick task directory + PLAN.md
228
+ * current-timestamp [format] Get timestamp (full|date|filename)
229
+ * verify-path-exists <path> Check file/directory existence
230
+ * summary-extract <path> [--fields] Extract structured data from SUMMARY.md
231
+ * websearch <query> [--limit N] [--freshness day|week|month]
232
+ * progress [json|table|bar] Render progress in various formats
233
+ * commit <message> [--files f1 f2] Commit planning docs
234
+ * suggest-next Deterministic routing recommendation
235
+ *
236
+ * REFERENCE & SKILLS:
237
+ * reference <name> [--section heading] [--list]
238
+ * skill-section <skill> <section>
239
+ * skill-section --list <skill>
240
+ * step-verify <skill> <step> <checklist-json>
241
+ * context-triage [--agents-done N] [--plans-total N] [--step NAME]
242
+ * suggest-alternatives phase-not-found|missing-prereq|config-invalid [args]
243
+ * spot-check <phaseSlug> <planId>
244
+ *
245
+ * SPEC (PHASE 11 SPEC-DRIVEN DEVELOPMENT):
246
+ * spec parse <plan-file> Parse PLAN.md into structured JSON
247
+ * spec diff <file-a> <file-b> Semantic diff between two PLAN.md versions
248
+ * spec reverse <file...> Generate spec from source files
249
+ * spec impact <file...> Predict impact of changed files
250
+ * [--format json|markdown] Output format (default: json)
251
+ * [--project-root <path>] Project root for impact analysis
252
+ *
253
+ * MIGRATION & EVENTS:
254
+ * migrate [--dry-run] [--force] Run schema migrations
255
+ * event <category> <event> [details] Log an event
256
+ * tmux detect Detect tmux environment
257
+ *
258
+ * HELP:
259
+ * help Show this help message
260
+ */
261
+
262
+ const fs = require('fs');
263
+ const path = require('path');
264
+
265
+ // ─── Module-level planningDir with MSYS path bridging ─────────────────────────
266
+
267
+ let cwd = process.env.PBR_PROJECT_ROOT || process.cwd();
268
+ const msysMatch = cwd.match(/^\/([a-zA-Z])\/(.*)/);
269
+ if (msysMatch) cwd = msysMatch[1] + ':' + path.sep + msysMatch[2].replace(/\//g, path.sep);
270
+ let planningDir = path.join(cwd, '.planning');
271
+
272
+ // ─── Lazy module loaders ──────────────────────────────────────────────────────
273
+ // Each module is loaded on first use to minimize startup time
274
+
275
+ let _core, _config, _state, _phase, _roadmap, _init;
276
+ let _history, _todo, _learnings, _spotCheck, _build, _llm;
277
+ let _verify, _frontmatter, _commands, _template, _milestone;
278
+ let _reference, _skillSection, _stepVerify, _preview, _context;
279
+ let _alternatives, _migrate, _circuitState, _intel, _statusRender, _suggestNext, _parseArgs;
280
+ let _decisions;
281
+ let _negativeKnowledge;
282
+ let _patterns;
283
+ let _templates;
284
+ let _incidents;
285
+
286
+ function getCore() { if (!_core) _core = require('./lib/core.cjs'); return _core; }
287
+ function getConfig() { if (!_config) _config = require('./lib/config.cjs'); return _config; }
288
+ function getState() { if (!_state) _state = require('./lib/state.cjs'); return _state; }
289
+ function getPhase() { if (!_phase) _phase = require('./lib/phase.cjs'); return _phase; }
290
+ function getRoadmap() { if (!_roadmap) _roadmap = require('./lib/roadmap.cjs'); return _roadmap; }
291
+ function getInit() { if (!_init) _init = require('./lib/init.cjs'); return _init; }
292
+ function getHistory() { if (!_history) _history = require('./lib/history.cjs'); return _history; }
293
+ function getTodo() { if (!_todo) _todo = require('./lib/todo.cjs'); return _todo; }
294
+ function getLearnings() { if (!_learnings) _learnings = require('./lib/learnings.cjs'); return _learnings; }
295
+ function getSpotCheck() { if (!_spotCheck) _spotCheck = require('./lib/spot-check.cjs'); return _spotCheck; }
296
+ function getBuild() { if (!_build) _build = require('./lib/build.cjs'); return _build; }
297
+ function getLlm() { if (!_llm) _llm = require('./lib/local-llm/index.cjs'); return _llm; }
298
+ function getVerify() { if (!_verify) _verify = require('./lib/verify.cjs'); return _verify; }
299
+ function getFrontmatter() { if (!_frontmatter) _frontmatter = require('./lib/frontmatter.cjs'); return _frontmatter; }
300
+ function getCommands() { if (!_commands) _commands = require('./lib/commands.cjs'); return _commands; }
301
+ function getTemplate() { if (!_template) _template = require('./lib/template.cjs'); return _template; }
302
+ function getMilestone() { if (!_milestone) _milestone = require('./lib/milestone.cjs'); return _milestone; }
303
+ function getReference() { if (!_reference) _reference = require('./lib/reference.cjs'); return _reference; }
304
+ function getSkillSection() { if (!_skillSection) _skillSection = require('./lib/skill-section.cjs'); return _skillSection; }
305
+ function getStepVerify() { if (!_stepVerify) _stepVerify = require('./lib/step-verify.cjs'); return _stepVerify; }
306
+ function getPreview() { if (!_preview) _preview = require('./lib/preview.cjs'); return _preview; }
307
+ function getContext() { if (!_context) _context = require('./lib/context.cjs'); return _context; }
308
+ function getAlternatives() { if (!_alternatives) _alternatives = require('./lib/alternatives.cjs'); return _alternatives; }
309
+ function getMigrate() { if (!_migrate) _migrate = require('./lib/migrate.cjs'); return _migrate; }
310
+ function getIntel() { if (!_intel) _intel = require('./lib/intel.cjs'); return _intel; }
311
+ function getStatusRender() { if (!_statusRender) _statusRender = require('./lib/status-render.cjs'); return _statusRender; }
312
+ function getSuggestNext() { if (!_suggestNext) _suggestNext = require('./lib/suggest-next.cjs'); return _suggestNext; }
313
+ function getParseArgs() { if (!_parseArgs) _parseArgs = require('./lib/parse-args.cjs'); return _parseArgs; }
314
+ function getDecisions() { if (!_decisions) _decisions = require('./lib/decisions.cjs'); return _decisions; }
315
+ function getNegativeKnowledge() { if (!_negativeKnowledge) _negativeKnowledge = require('./lib/negative-knowledge.cjs'); return _negativeKnowledge; }
316
+ function getPatterns() { if (!_patterns) _patterns = require('./lib/patterns.cjs'); return _patterns; }
317
+ function getTemplates() { if (!_templates) _templates = require('./lib/templates.cjs'); return _templates; }
318
+ function getIncidents() { if (!_incidents) _incidents = require('./lib/incidents.cjs'); return _incidents; }
319
+
320
+ // ─── Helper: resolve plugin root ──────────────────────────────────────────────
321
+
322
+ function resolvePluginRoot() {
323
+ const pluginRoot = process.env.PBR_PLUGIN_ROOT || path.resolve(__dirname, '..');
324
+ let root = pluginRoot;
325
+ const m = root.match(/^\/([a-zA-Z])\/(.*)/);
326
+ if (m) root = m[1] + ':' + path.sep + m[2].replace(/\//g, path.sep);
327
+ return root;
328
+ }
329
+
330
+ // ─── Wrapper functions (bridge planningDir to lib pure functions) ──────────────
331
+
332
+ function configLoad(dir) { return getConfig().configLoad(dir || planningDir); }
333
+ function configValidate(preloaded) { return getConfig().configValidate(preloaded, planningDir); }
334
+
335
+ function stateLoad() { return getState().stateLoad(planningDir); }
336
+ function stateCheckProgress() { return getState().stateCheckProgress(planningDir); }
337
+ function stateUpdate(field, value) { return getState().stateUpdate(field, value, planningDir); }
338
+ function statePatch(jsonStr) { return getState().statePatch(jsonStr, planningDir); }
339
+ function stateAdvancePlan() { return getState().stateAdvancePlan(planningDir); }
340
+ function stateRecordMetric(metricArgs) { return getState().stateRecordMetric(metricArgs, planningDir); }
341
+ function stateRecordActivity(desc) { return getState().stateRecordActivity(desc, planningDir); }
342
+ function stateUpdateProgress() { return getState().stateUpdateProgress(planningDir); }
343
+ function stateGetStatus() { return getState().stateGetStatus(planningDir); }
344
+ function stateSnapshot() { return getState().stateSnapshot(planningDir); }
345
+
346
+ function roadmapAnalyze() { return getRoadmap().roadmapAnalyze(planningDir); }
347
+ function roadmapUpdateStatus(p, s) { return getRoadmap().roadmapUpdateStatus(p, s, planningDir); }
348
+ function roadmapUpdatePlans(p, c, t) { return getRoadmap().roadmapUpdatePlans(p, c, t, planningDir); }
349
+ function roadmapUpdatePlanProgress(p) { return getRoadmap().roadmapUpdatePlanProgress(p, planningDir); }
350
+ function roadmapGetPhase(p) { return getRoadmap().roadmapGetPhase(p, planningDir); }
351
+ function roadmapAppendPhase(slug, opts) { return getRoadmap().roadmapAppendPhase(slug, planningDir, opts); }
352
+ function roadmapRemovePhase(p) { return getRoadmap().roadmapRemovePhase(p, planningDir); }
353
+ function roadmapInsertPhase(pos, slug, opts) { return getRoadmap().roadmapInsertPhase(pos, slug, planningDir, opts); }
354
+
355
+ function phaseFrontmatter(fp) { return getPhase().frontmatter(fp); }
356
+ function phasePlanIndex(p) { return getPhase().phasePlanIndex(p, planningDir); }
357
+ function phaseMustHaves(p) { return getPhase().phaseMustHaves(p, planningDir); }
358
+ function phaseInfo(p) { return getPhase().phaseInfo(p, planningDir); }
359
+ function phaseAdd(slug, after, opts) { return getPhase().phaseAdd(slug, after, planningDir, opts); }
360
+ function phaseRemove(p) { return getPhase().phaseRemove(p, planningDir); }
361
+ function phaseList() { return getPhase().phaseList(planningDir); }
362
+ function phaseComplete(p) { return getPhase().phaseComplete(p, planningDir); }
363
+ function phaseInsert(pos, slug, opts) { return getPhase().phaseInsert(pos, slug, planningDir, opts); }
364
+ function phaseCommitsFor(p) { return getPhase().phaseCommitsFor(p, planningDir); }
365
+ function phaseFirstLastCommit(p) { return getPhase().phaseFirstLastCommit(p, planningDir); }
366
+ function milestoneStats(v) { return getPhase().milestoneStats(v, planningDir); }
367
+
368
+ function initExecutePhase(p, dir, model) { return getInit().initExecutePhase(p, dir || planningDir, model); }
369
+ function initPlanPhase(p, dir, model) { return getInit().initPlanPhase(p, dir || planningDir, model); }
370
+ function initQuick(desc) { return getInit().initQuick(desc, planningDir); }
371
+ function initVerifyWork(p, dir, model) { return getInit().initVerifyWork(p, dir || planningDir, model); }
372
+ function initResume() { return getInit().initResume(planningDir); }
373
+ function initProgress() { return getInit().initProgress(planningDir); }
374
+ function initStateBundle(p) { return getInit().initStateBundle(p, planningDir); }
375
+
376
+ function historyAppend(entry, dir) { return getHistory().historyAppend(entry, dir || planningDir); }
377
+ function historyLoad(dir) { return getHistory().historyLoad(dir || planningDir); }
378
+
379
+ function todoList(opts) { return getTodo().todoList(planningDir, opts); }
380
+ function todoGet(num) { return getTodo().todoGet(planningDir, num); }
381
+ function todoAdd(title, opts) { return getTodo().todoAdd(planningDir, title, opts); }
382
+ function todoDone(num) { return getTodo().todoDone(planningDir, num); }
383
+
384
+ function decisionsRecord(opts) { return getDecisions().recordDecision(planningDir, opts); }
385
+ function decisionsList(filters) { return getDecisions().listDecisions(planningDir, filters); }
386
+
387
+ function spotCheck(phaseSlug, planId) { return getSpotCheck().spotCheck(planningDir, phaseSlug, planId); }
388
+ function verifySpotCheck(type, dirPath) { return getSpotCheck().verifySpotCheck(type, dirPath); }
389
+
390
+ function stalenessCheck(slug) { return getBuild().stalenessCheck(slug, planningDir); }
391
+ function summaryGate(slug, planId) { return getBuild().summaryGate(slug, planId, planningDir); }
392
+ function checkpointInit(slug, plans) { return getBuild().checkpointInit(slug, plans, planningDir); }
393
+ function checkpointUpdate(slug, opts) { return getBuild().checkpointUpdate(slug, opts, planningDir); }
394
+ function seedsMatch(slug, num) { return getBuild().seedsMatch(slug, num, planningDir); }
395
+ function ciPoll(runId, timeout) { return getBuild().ciPoll(runId, timeout, planningDir); }
396
+ function rollbackPlan(manifest) { return getBuild().rollback(manifest, planningDir); }
397
+
398
+ function referenceGet(name, opts) {
399
+ return getReference().referenceGet(name, opts, resolvePluginRoot());
400
+ }
401
+
402
+ function skillSectionGet(skill, query) {
403
+ return getSkillSection().skillSection(skill, query, resolvePluginRoot());
404
+ }
405
+
406
+ function listSkillHeadings(skill) {
407
+ const root = resolvePluginRoot();
408
+ const available = getSkillSection().listAvailableSkills(root);
409
+ const skillPath = path.join(root, 'skills', skill, 'SKILL.md');
410
+ if (!fs.existsSync(skillPath)) {
411
+ return { error: `Skill not found: ${skill}`, available };
412
+ }
413
+ const content = fs.readFileSync(skillPath, 'utf8');
414
+ return { skill, headings: getReference().listHeadings(content) };
415
+ }
416
+
417
+ function contextTriage(opts) {
418
+ return getContext().contextTriage(opts, planningDir);
419
+ }
420
+
421
+ // ─── validateProject (cross-cutting) ──────────────────────────────────────────
422
+
423
+ function validateProject() {
424
+ const core = getCore();
425
+ const checks = [];
426
+ const errors = [];
427
+ const warnings = [];
428
+
429
+ if (!fs.existsSync(planningDir)) {
430
+ return { valid: false, errors: ['.planning/ directory not found'], warnings: [], checks: ['directory_exists: FAIL'] };
431
+ }
432
+ checks.push('directory_exists: PASS');
433
+
434
+ const config = configLoad();
435
+ if (!config) {
436
+ errors.push('config.json missing or invalid JSON');
437
+ checks.push('config_valid: FAIL');
438
+ } else {
439
+ const configResult = configValidate(config);
440
+ if (!configResult.valid) errors.push(...configResult.errors.map(e => 'config: ' + e));
441
+ warnings.push(...(configResult.warnings || []).map(w => 'config: ' + w));
442
+ checks.push('config_valid: ' + (configResult.valid ? 'PASS' : 'FAIL'));
443
+ }
444
+
445
+ const statePath = path.join(planningDir, 'STATE.md');
446
+ if (!fs.existsSync(statePath)) {
447
+ errors.push('STATE.md not found');
448
+ checks.push('state_exists: FAIL');
449
+ } else {
450
+ try {
451
+ const stateContent = fs.readFileSync(statePath, 'utf8');
452
+ const fm = core.parseYamlFrontmatter(stateContent);
453
+ if (!fm || !fm.current_phase) {
454
+ warnings.push('STATE.md frontmatter missing current_phase');
455
+ checks.push('state_frontmatter: WARN');
456
+ } else {
457
+ checks.push('state_frontmatter: PASS');
458
+ }
459
+ } catch (e) {
460
+ errors.push('STATE.md unreadable: ' + e.message);
461
+ checks.push('state_readable: FAIL');
462
+ }
463
+ }
464
+
465
+ const roadmapPath = path.join(planningDir, 'ROADMAP.md');
466
+ if (!fs.existsSync(roadmapPath)) {
467
+ warnings.push('ROADMAP.md not found (may be a new project)');
468
+ checks.push('roadmap_exists: WARN');
469
+ } else {
470
+ checks.push('roadmap_exists: PASS');
471
+ }
472
+
473
+ return { valid: errors.length === 0, errors, warnings, checks };
474
+ }
475
+
476
+ // ─── Spec Operations (Phase 11) ───────────────────────────────────────────────
477
+
478
+ /**
479
+ * Handle spec subcommands: parse, diff, reverse, impact.
480
+ * @param {string[]} args - raw CLI args (args[0] is 'spec', args[1] is subcommand)
481
+ * @param {string} pDir - planningDir
482
+ * @param {string} projectRoot - cwd
483
+ * @param {Function} outputFn - output function
484
+ * @param {Function} errorFn - error function
485
+ */
486
+
487
+ // ─── Incident flag parsers ──────────────────────────────────────────────────
488
+
489
+ function parseIncidentFlags(flagArgs) {
490
+ const entry = {};
491
+ for (let i = 0; i < flagArgs.length; i++) {
492
+ if (flagArgs[i] === '--source') entry.source = flagArgs[++i];
493
+ else if (flagArgs[i] === '--type') entry.type = flagArgs[++i];
494
+ else if (flagArgs[i] === '--severity') entry.severity = flagArgs[++i];
495
+ else if (flagArgs[i] === '--issue') entry.issue = flagArgs[++i];
496
+ else if (flagArgs[i] === '--session-id') entry.session_id = flagArgs[++i];
497
+ else if (flagArgs[i] === '--auto-fixed') entry.auto_fixed = true;
498
+ else if (flagArgs[i] === '--resolution') entry.resolution = flagArgs[++i];
499
+ else if (flagArgs[i] === '--duration-ms') entry.duration_ms = parseInt(flagArgs[++i], 10);
500
+ else if (flagArgs[i] === '--context') {
501
+ try { entry.context = JSON.parse(flagArgs[++i]); } catch (_e) { /* skip */ }
502
+ }
503
+ }
504
+ return entry;
505
+ }
506
+
507
+ function parseQueryFlags(flagArgs) {
508
+ const filter = {};
509
+ for (let i = 0; i < flagArgs.length; i++) {
510
+ if (flagArgs[i] === '--type') filter.type = flagArgs[++i];
511
+ else if (flagArgs[i] === '--severity') filter.severity = flagArgs[++i];
512
+ else if (flagArgs[i] === '--source') filter.source = flagArgs[++i];
513
+ else if (flagArgs[i] === '--session-id') filter.session_id = flagArgs[++i];
514
+ else if (flagArgs[i] === '--last') filter.last = flagArgs[++i];
515
+ }
516
+ return filter;
517
+ }
518
+
519
+ function handleSpec(args, pDir, projectRoot, outputFn, errorFn) {
520
+ const subcommand = args[1];
521
+
522
+ // Parse common flags
523
+ const formatIdx = args.indexOf('--format');
524
+ const format = formatIdx !== -1 ? args[formatIdx + 1] : 'json';
525
+ const projectRootIdx = args.indexOf('--project-root');
526
+ const effectiveRoot = projectRootIdx !== -1 ? args[projectRootIdx + 1] : projectRoot;
527
+
528
+ // Load config for feature toggle checks
529
+ let config = {};
530
+ try {
531
+ const configPath = path.join(pDir, 'config.json');
532
+ if (fs.existsSync(configPath)) {
533
+ config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
534
+ }
535
+ } catch (_e) {
536
+ // Config unreadable — use defaults
537
+ }
538
+ const features = config.features || {};
539
+
540
+ // Audit log helper
541
+ function writeAuditLog(cmd, featureName, status, fileCount) {
542
+ try {
543
+ const logDir = path.join(pDir, 'logs');
544
+ if (fs.existsSync(logDir)) {
545
+ const logFile = path.join(logDir, 'spec-engine.jsonl');
546
+ const entry = JSON.stringify({
547
+ ts: new Date().toISOString(),
548
+ cmd: `spec.${cmd}`,
549
+ feature: featureName,
550
+ status,
551
+ files: fileCount || 0,
552
+ });
553
+ fs.appendFileSync(logFile, entry + '\n', 'utf-8');
554
+ }
555
+ } catch (_e) {
556
+ // No-op if log dir missing or unwritable
557
+ }
558
+ }
559
+
560
+ if (!subcommand || subcommand === '--help' || subcommand === 'help') {
561
+ const usageText = [
562
+ 'Usage: spec <subcommand> [args] [--format json|markdown]',
563
+ '',
564
+ 'Subcommands:',
565
+ ' parse <plan-file> Parse PLAN.md into structured JSON',
566
+ ' diff <file-a> <file-b> Semantic diff between two PLAN.md versions',
567
+ ' reverse <file...> Generate spec from source files',
568
+ ' impact <file...> Predict impact of changed files',
569
+ '',
570
+ 'Flags:',
571
+ ' --format json|markdown Output format (default: json)',
572
+ ' --project-root <path> Project root for impact analysis',
573
+ ].join('\n');
574
+ outputFn(null, true, usageText);
575
+ return;
576
+ }
577
+
578
+ if (subcommand === 'parse') {
579
+ const planFile = args[2];
580
+ if (!planFile) { errorFn('Usage: spec parse <plan-file>'); return; }
581
+ const { parsePlanToSpec } = require('./lib/spec-engine.cjs');
582
+ let content;
583
+ try {
584
+ content = fs.readFileSync(planFile, 'utf-8');
585
+ } catch (e) {
586
+ errorFn(`Cannot read file: ${planFile}: ${e.message}`);
587
+ return;
588
+ }
589
+ const spec = parsePlanToSpec(content);
590
+ writeAuditLog('parse', 'machine_executable_plans', 'ok', 1);
591
+ outputFn({ frontmatter: spec.frontmatter, tasks: spec.tasks });
592
+ return;
593
+ }
594
+
595
+ if (subcommand === 'diff') {
596
+ if (features.spec_diffing === false) {
597
+ outputFn({ error: 'Feature disabled. Enable features.spec_diffing in config.json' });
598
+ return;
599
+ }
600
+ const fileA = args[2];
601
+ const fileB = args[3];
602
+ if (!fileA || !fileB) { errorFn('Usage: spec diff <file-a> <file-b>'); return; }
603
+ const { diffPlanFiles, formatDiff } = require('./lib/spec-diff.cjs');
604
+ let contentA, contentB;
605
+ try {
606
+ contentA = fs.readFileSync(fileA, 'utf-8');
607
+ contentB = fs.readFileSync(fileB, 'utf-8');
608
+ } catch (e) {
609
+ errorFn(`Cannot read file: ${e.message}`);
610
+ return;
611
+ }
612
+ const diff = diffPlanFiles(contentA, contentB);
613
+ writeAuditLog('diff', 'spec_diffing', 'ok', 2);
614
+ if (format === 'markdown') {
615
+ outputFn(null, true, formatDiff(diff, 'markdown'));
616
+ } else {
617
+ outputFn(diff);
618
+ }
619
+ return;
620
+ }
621
+
622
+ if (subcommand === 'reverse') {
623
+ if (features.reverse_spec === false) {
624
+ outputFn({ error: 'Feature disabled. Enable features.reverse_spec in config.json' });
625
+ return;
626
+ }
627
+ const files = [];
628
+ for (let i = 2; i < args.length; i++) {
629
+ if (!args[i].startsWith('--')) files.push(args[i]);
630
+ }
631
+ if (files.length === 0) { errorFn('Usage: spec reverse <file...>'); return; }
632
+ const { generateReverseSpec } = require('./lib/reverse-spec.cjs');
633
+ const { serializeSpec } = require('./lib/spec-engine.cjs');
634
+ const spec = generateReverseSpec(files, { readFile: (p) => fs.readFileSync(p, 'utf-8') });
635
+ writeAuditLog('reverse', 'reverse_spec', 'ok', files.length);
636
+ if (format === 'markdown') {
637
+ outputFn(null, true, serializeSpec(spec));
638
+ } else {
639
+ outputFn(spec);
640
+ }
641
+ return;
642
+ }
643
+
644
+ if (subcommand === 'impact') {
645
+ if (features.predictive_impact === false) {
646
+ outputFn({ error: 'Feature disabled. Enable features.predictive_impact in config.json' });
647
+ return;
648
+ }
649
+ const files = [];
650
+ for (let i = 2; i < args.length; i++) {
651
+ if (!args[i].startsWith('--') && args[i - 1] !== '--project-root') files.push(args[i]);
652
+ }
653
+ if (files.length === 0) { errorFn('Usage: spec impact <file...>'); return; }
654
+ const { analyzeImpact } = require('./lib/impact-analysis.cjs');
655
+ const report = analyzeImpact(files, effectiveRoot);
656
+ writeAuditLog('impact', 'predictive_impact', 'ok', files.length);
657
+ outputFn(report);
658
+ return;
659
+ }
660
+
661
+ errorFn(`Unknown spec subcommand: ${subcommand}\nAvailable: parse, diff, reverse, impact`);
662
+ }
663
+
664
+ // ─── CLI entry point ──────────────────────────────────────────────────────────
665
+
666
+ async function main() {
667
+ const args = process.argv.slice(2);
668
+ const { output, error } = getCore();
669
+
670
+ // --cwd override
671
+ const cwdEqArg = args.find(arg => arg.startsWith('--cwd='));
672
+ const cwdIdx = args.indexOf('--cwd');
673
+ if (cwdEqArg) {
674
+ const value = cwdEqArg.slice('--cwd='.length).trim();
675
+ if (!value) error('Missing value for --cwd');
676
+ args.splice(args.indexOf(cwdEqArg), 1);
677
+ cwd = path.resolve(value);
678
+ planningDir = path.join(cwd, '.planning');
679
+ } else if (cwdIdx !== -1) {
680
+ const value = args[cwdIdx + 1];
681
+ if (!value || value.startsWith('--')) error('Missing value for --cwd');
682
+ args.splice(cwdIdx, 2);
683
+ cwd = path.resolve(value);
684
+ planningDir = path.join(cwd, '.planning');
685
+ }
686
+
687
+ if (!fs.existsSync(cwd) || !fs.statSync(cwd).isDirectory()) {
688
+ error(`Invalid --cwd: ${cwd}`);
689
+ }
690
+
691
+ // --raw flag
692
+ const rawIndex = args.indexOf('--raw');
693
+ const raw = rawIndex !== -1;
694
+ if (rawIndex !== -1) args.splice(rawIndex, 1);
695
+
696
+ const command = args[0];
697
+ const subcommand = args[1];
698
+
699
+ if (!command || command === 'help') {
700
+ // Print help from the header comment
701
+ const selfContent = fs.readFileSync(__filename, 'utf8');
702
+ const commentEnd = selfContent.indexOf(' */');
703
+ const helpText = selfContent
704
+ .slice(selfContent.indexOf('/**') + 3, commentEnd)
705
+ .split('\n')
706
+ .map(l => l.replace(/^\s*\*\s?/, ''))
707
+ .join('\n')
708
+ .trim();
709
+ if (raw) {
710
+ process.stdout.write(helpText + '\n');
711
+ } else {
712
+ output({ help: helpText }, false, helpText);
713
+ }
714
+ return;
715
+ }
716
+
717
+ try {
718
+ // ─── State Operations ─────────────────────────────────────────────────────
719
+ if (command === 'state' && subcommand === 'load') {
720
+ output(stateLoad());
721
+ } else if (command === 'state' && subcommand === 'check-progress') {
722
+ output(stateCheckProgress());
723
+ } else if (command === 'state' && subcommand === 'update') {
724
+ const field = args[2];
725
+ const value = args[3];
726
+ if (!field || value === undefined) error('Usage: pbr-tools.cjs state update <field> <value>');
727
+ output(stateUpdate(field, value));
728
+ } else if (command === 'state' && subcommand === 'json') {
729
+ // GSD compat: cmdStateJson
730
+ getState().cmdStateJson(cwd, raw);
731
+ } else if (command === 'state' && subcommand === 'get') {
732
+ // GSD compat: cmdStateGet
733
+ getState().cmdStateGet(cwd, args[2], raw);
734
+ } else if (command === 'state' && subcommand === 'patch') {
735
+ // Support both reference (JSON string) and GSD (--key val pairs) patterns
736
+ if (args[2] && !args[2].startsWith('--')) {
737
+ // Reference pattern: state patch '{"key": "val"}'
738
+ output(statePatch(args[2]));
739
+ } else {
740
+ // GSD pattern: state patch --key val --key2 val2
741
+ const patches = {};
742
+ for (let i = 2; i < args.length; i += 2) {
743
+ const key = args[i].replace(/^--/, '');
744
+ const value = args[i + 1];
745
+ if (key && value !== undefined) patches[key] = value;
746
+ }
747
+ getState().cmdStatePatch(cwd, patches, raw);
748
+ }
749
+ } else if (command === 'state' && subcommand === 'advance-plan') {
750
+ output(stateAdvancePlan());
751
+ } else if (command === 'state' && subcommand === 'record-metric') {
752
+ // Support both reference (positional) and GSD (--flag) patterns
753
+ const phaseIdx = args.indexOf('--phase');
754
+ if (phaseIdx !== -1) {
755
+ // GSD pattern with --flags
756
+ const planIdx = args.indexOf('--plan');
757
+ const durationIdx = args.indexOf('--duration');
758
+ const tasksIdx = args.indexOf('--tasks');
759
+ const filesIdx = args.indexOf('--files');
760
+ getState().cmdStateRecordMetric(cwd, {
761
+ phase: phaseIdx !== -1 ? args[phaseIdx + 1] : null,
762
+ plan: planIdx !== -1 ? args[planIdx + 1] : null,
763
+ duration: durationIdx !== -1 ? args[durationIdx + 1] : null,
764
+ tasks: tasksIdx !== -1 ? args[tasksIdx + 1] : null,
765
+ files: filesIdx !== -1 ? args[filesIdx + 1] : null,
766
+ }, raw);
767
+ } else {
768
+ // Reference pattern: positional args
769
+ output(stateRecordMetric(args.slice(2)));
770
+ }
771
+ } else if (command === 'state' && subcommand === 'record-activity') {
772
+ const description = args.slice(2).join(' ');
773
+ if (!description) error('Usage: pbr-tools.cjs state record-activity <description>');
774
+ output(stateRecordActivity(description));
775
+ } else if (command === 'state' && subcommand === 'update-progress') {
776
+ output(stateUpdateProgress());
777
+ } else if (command === 'state' && subcommand === 'phase-complete') {
778
+ const p = args[2];
779
+ if (!p) error('Usage: pbr-tools.cjs state phase-complete <phase>');
780
+ output(getState().statePhaseComplete(Number(p), planningDir));
781
+ } else if (command === 'state' && subcommand === 'rederive') {
782
+ output(getState().stateRederive(planningDir));
783
+ } else if (command === 'state' && subcommand === 'reconcile') {
784
+ const result = getState().stateReconcile(planningDir);
785
+ if (result.changes.length > 0) {
786
+ console.log('Reconciled STATE.md:');
787
+ result.changes.forEach(c => console.log(' ' + c));
788
+ } else {
789
+ console.log('STATE.md is consistent with ROADMAP.md — no changes needed.');
790
+ }
791
+ if (result.phantoms.length > 0) {
792
+ console.log('Phantom ROADMAP phases (no directory on disk):');
793
+ result.phantoms.forEach(p => console.log(' ' + p));
794
+ console.log('Review and remove manually if no longer needed.');
795
+ }
796
+ if (raw) output(result);
797
+ } else if (command === 'state' && subcommand === 'add-decision') {
798
+ // GSD pattern: --summary "text" --phase N
799
+ const phaseIdx = args.indexOf('--phase');
800
+ const summaryIdx = args.indexOf('--summary');
801
+ const summaryFileIdx = args.indexOf('--summary-file');
802
+ const rationaleIdx = args.indexOf('--rationale');
803
+ const rationaleFileIdx = args.indexOf('--rationale-file');
804
+ getState().cmdStateAddDecision(cwd, {
805
+ phase: phaseIdx !== -1 ? args[phaseIdx + 1] : null,
806
+ summary: summaryIdx !== -1 ? args[summaryIdx + 1] : null,
807
+ summary_file: summaryFileIdx !== -1 ? args[summaryFileIdx + 1] : null,
808
+ rationale: rationaleIdx !== -1 ? args[rationaleIdx + 1] : '',
809
+ rationale_file: rationaleFileIdx !== -1 ? args[rationaleFileIdx + 1] : null,
810
+ }, raw);
811
+ } else if (command === 'state' && subcommand === 'add-blocker') {
812
+ const textIdx = args.indexOf('--text');
813
+ const textFileIdx = args.indexOf('--text-file');
814
+ getState().cmdStateAddBlocker(cwd, {
815
+ text: textIdx !== -1 ? args[textIdx + 1] : null,
816
+ text_file: textFileIdx !== -1 ? args[textFileIdx + 1] : null,
817
+ }, raw);
818
+ } else if (command === 'state' && subcommand === 'resolve-blocker') {
819
+ const textIdx = args.indexOf('--text');
820
+ getState().cmdStateResolveBlocker(cwd, textIdx !== -1 ? args[textIdx + 1] : null, raw);
821
+ } else if (command === 'state' && subcommand === 'record-session') {
822
+ const stoppedIdx = args.indexOf('--stopped-at');
823
+ const resumeIdx = args.indexOf('--resume-file');
824
+ getState().cmdStateRecordSession(cwd, {
825
+ stopped_at: stoppedIdx !== -1 ? args[stoppedIdx + 1] : null,
826
+ resume_file: resumeIdx !== -1 ? args[resumeIdx + 1] : 'None',
827
+ }, raw);
828
+ } else if (command === 'state' && !subcommand) {
829
+ // Bare "state" = state load
830
+ output(stateLoad());
831
+
832
+ // ─── State-bundle and state-snapshot (top-level aliases) ────────────────
833
+ } else if (command === 'state-bundle') {
834
+ const phaseNum = args[1];
835
+ if (!phaseNum) error('Usage: pbr-tools.cjs state-bundle <phase-number>');
836
+ output(initStateBundle(phaseNum));
837
+ } else if (command === 'state-snapshot') {
838
+ getState().cmdStateSnapshot(cwd, raw);
839
+
840
+ // ─── Config Operations ────────────────────────────────────────────────────
841
+ } else if (command === 'config' && subcommand === 'validate') {
842
+ output(configValidate());
843
+ } else if (command === 'config' && subcommand === 'load-defaults') {
844
+ const defaults = getConfig().loadUserDefaults();
845
+ output(defaults || { exists: false, path: getConfig().USER_DEFAULTS_PATH });
846
+ } else if (command === 'config' && subcommand === 'save-defaults') {
847
+ const cfg = configLoad();
848
+ if (!cfg) error('No config.json found. Run /pbr:setup first.');
849
+ output(getConfig().saveUserDefaults(cfg));
850
+ } else if (command === 'config' && subcommand === 'resolve-depth') {
851
+ const dir = args[2] || undefined;
852
+ const cfg = configLoad(dir);
853
+ output(getConfig().configResolveDepth(cfg));
854
+ } else if (command === 'config' && subcommand === 'get') {
855
+ getConfig().cmdConfigGet(cwd, args[2], raw);
856
+ } else if (command === 'config' && subcommand === 'set') {
857
+ getConfig().cmdConfigSet(cwd, args[2], args[3], raw);
858
+ } else if (command === 'config' && subcommand === 'ensure-section') {
859
+ getConfig().cmdConfigEnsureSection(cwd, raw);
860
+ } else if (command === 'config-ensure-section') {
861
+ getConfig().cmdConfigEnsureSection(cwd, raw);
862
+ } else if (command === 'config-set') {
863
+ getConfig().cmdConfigSet(cwd, args[1], args[2], raw);
864
+ } else if (command === 'config-get') {
865
+ getConfig().cmdConfigGet(cwd, args[1], raw);
866
+
867
+ // ─── Phase Operations ─────────────────────────────────────────────────────
868
+ } else if (command === 'phase' && subcommand === 'add') {
869
+ const slug = args[2];
870
+ if (!slug) error('Usage: phase add <slug> [--after N] [--goal "..."] [--depends-on N]');
871
+ const afterIdx = args.indexOf('--after');
872
+ const afterPhase = afterIdx !== -1 ? args[afterIdx + 1] : null;
873
+ const goalIdx = args.indexOf('--goal');
874
+ const goal = goalIdx !== -1 ? args[goalIdx + 1] : null;
875
+ const depIdx = args.indexOf('--depends-on');
876
+ const dependsOn = depIdx !== -1 ? args[depIdx + 1] : null;
877
+ const opts = {};
878
+ if (goal) opts.goal = goal;
879
+ if (dependsOn) opts.dependsOn = dependsOn;
880
+ output(phaseAdd(slug, afterPhase, Object.keys(opts).length > 0 ? opts : undefined));
881
+ } else if (command === 'phase' && subcommand === 'remove') {
882
+ const p = args[2];
883
+ if (!p) error('Usage: phase remove <N>');
884
+ output(phaseRemove(p));
885
+ } else if (command === 'phase' && subcommand === 'list') {
886
+ output(phaseList());
887
+ } else if (command === 'phase' && subcommand === 'complete') {
888
+ const p = args[2];
889
+ if (!p) error('Usage: phase complete <N>');
890
+ output(phaseComplete(p));
891
+ } else if (command === 'phase' && subcommand === 'insert') {
892
+ const position = args[2];
893
+ const slug = args[3];
894
+ if (!position || !slug) error('Usage: phase insert <N> <slug> [--goal "..."] [--depends-on N]');
895
+ const goalIdx = args.indexOf('--goal');
896
+ const goal = goalIdx !== -1 ? args[goalIdx + 1] : null;
897
+ const depIdx = args.indexOf('--depends-on');
898
+ const dependsOn = depIdx !== -1 ? args[depIdx + 1] : null;
899
+ const opts = {};
900
+ if (goal) opts.goal = goal;
901
+ if (dependsOn) opts.dependsOn = dependsOn;
902
+ output(phaseInsert(parseInt(position, 10), slug, Object.keys(opts).length > 0 ? opts : undefined));
903
+ } else if (command === 'phase' && subcommand === 'info') {
904
+ const p = args[2];
905
+ if (!p) error('Usage: phase info <N>');
906
+ output(phaseInfo(p));
907
+ } else if (command === 'phase' && subcommand === 'commits-for') {
908
+ const p = args[2];
909
+ if (!p) error('Usage: phase commits-for <N>');
910
+ output(phaseCommitsFor(p));
911
+ } else if (command === 'phase' && subcommand === 'first-last-commit') {
912
+ const p = args[2];
913
+ if (!p) error('Usage: phase first-last-commit <N>');
914
+ output(phaseFirstLastCommit(p));
915
+ } else if (command === 'phase' && subcommand === 'next-decimal') {
916
+ // GSD compat
917
+ getPhase().cmdPhaseNextDecimal
918
+ ? getPhase().cmdPhaseNextDecimal(cwd, args[2], raw)
919
+ : output(getPhase().phaseNextDecimal ? getPhase().phaseNextDecimal(args[2], planningDir) : { error: 'not implemented' });
920
+ } else if (command === 'phases' && subcommand === 'list') {
921
+ // GSD compat: phases list with options
922
+ const typeIndex = args.indexOf('--type');
923
+ const phaseIndex = args.indexOf('--phase');
924
+ const options = {
925
+ type: typeIndex !== -1 ? args[typeIndex + 1] : null,
926
+ phase: phaseIndex !== -1 ? args[phaseIndex + 1] : null,
927
+ includeArchived: args.includes('--include-archived'),
928
+ };
929
+ getPhase().cmdPhasesList
930
+ ? getPhase().cmdPhasesList(cwd, options, raw)
931
+ : output(phaseList());
932
+ } else if (command === 'phase-info') {
933
+ const p = args[1];
934
+ if (!p) error('Usage: pbr-tools.cjs phase-info <N>');
935
+ output(phaseInfo(p));
936
+ } else if (command === 'phase-plan-index') {
937
+ const p = args[1];
938
+ if (!p) error('Usage: pbr-tools.cjs phase-plan-index <phase>');
939
+ getPhase().cmdPhasePlanIndex
940
+ ? getPhase().cmdPhasePlanIndex(cwd, p, raw)
941
+ : output(phasePlanIndex(p));
942
+ } else if (command === 'find-phase') {
943
+ getPhase().cmdFindPhase
944
+ ? getPhase().cmdFindPhase(cwd, args[1], raw)
945
+ : output(getCore().findPhaseInternal(cwd, args[1]));
946
+ } else if (command === 'plan-index') {
947
+ const p = args[1];
948
+ if (!p) error('Usage: pbr-tools.cjs plan-index <phase>');
949
+ output(phasePlanIndex(p));
950
+ } else if (command === 'must-haves') {
951
+ const p = args[1];
952
+ if (!p) error('Usage: pbr-tools.cjs must-haves <phase>');
953
+ output(phaseMustHaves(p));
954
+
955
+ // ─── Roadmap Operations ───────────────────────────────────────────────────
956
+ } else if (command === 'roadmap' && subcommand === 'get-phase') {
957
+ const p = args[2];
958
+ if (!p) error('Usage: roadmap get-phase <phase>');
959
+ output(roadmapGetPhase(p));
960
+ } else if (command === 'roadmap' && subcommand === 'analyze') {
961
+ output(roadmapAnalyze());
962
+ } else if (command === 'roadmap' && subcommand === 'update-plan-progress') {
963
+ const p = args[2];
964
+ if (!p) error('Usage: roadmap update-plan-progress <phase>');
965
+ output(roadmapUpdatePlanProgress(p));
966
+ } else if (command === 'roadmap' && subcommand === 'update-status') {
967
+ const p = args[2];
968
+ const s = args[3];
969
+ if (!p || !s) error('Usage: roadmap update-status <phase> <status>');
970
+ output(roadmapUpdateStatus(p, s));
971
+ } else if (command === 'roadmap' && subcommand === 'update-plans') {
972
+ const p = args[2];
973
+ const c = args[3];
974
+ const t = args[4];
975
+ if (!p || c === undefined || t === undefined) error('Usage: roadmap update-plans <phase> <complete> <total>');
976
+ output(roadmapUpdatePlans(p, c, t));
977
+ } else if (command === 'roadmap' && subcommand === 'append-phase') {
978
+ const slug = args[2];
979
+ if (!slug) error('Usage: roadmap append-phase <slug> [options]');
980
+ output(roadmapAppendPhase(slug));
981
+ } else if (command === 'roadmap' && subcommand === 'remove-phase') {
982
+ const p = args[2];
983
+ if (!p) error('Usage: roadmap remove-phase <N>');
984
+ output(roadmapRemovePhase(p));
985
+ } else if (command === 'roadmap' && subcommand === 'insert-phase') {
986
+ const pos = args[2];
987
+ const slug = args[3];
988
+ if (!pos || !slug) error('Usage: roadmap insert-phase <N> <slug>');
989
+ output(roadmapInsertPhase(parseInt(pos, 10), slug));
990
+
991
+ // ─── Init (Compound Commands) ─────────────────────────────────────────────
992
+ } else if (command === 'init' && subcommand === 'execute-phase') {
993
+ const p = args[2];
994
+ if (!p) error('Usage: pbr-tools.cjs init execute-phase <phase>');
995
+ output(initExecutePhase(p));
996
+ } else if (command === 'init' && subcommand === 'plan-phase') {
997
+ const p = args[2];
998
+ if (!p) error('Usage: pbr-tools.cjs init plan-phase <phase>');
999
+ output(initPlanPhase(p));
1000
+ } else if (command === 'init' && subcommand === 'new-project') {
1001
+ getInit().cmdInitNewProject
1002
+ ? getInit().cmdInitNewProject(cwd, raw)
1003
+ : output({ error: 'init new-project not available in reference mode' });
1004
+ } else if (command === 'init' && subcommand === 'new-milestone') {
1005
+ getInit().cmdInitNewMilestone
1006
+ ? getInit().cmdInitNewMilestone(cwd, raw)
1007
+ : output({ error: 'init new-milestone not available in reference mode' });
1008
+ } else if (command === 'init' && subcommand === 'quick') {
1009
+ const desc = args.slice(2).join(' ') || '';
1010
+ output(initQuick(desc));
1011
+ } else if (command === 'init' && subcommand === 'resume') {
1012
+ output(initResume());
1013
+ } else if (command === 'init' && subcommand === 'verify-work') {
1014
+ const p = args[2];
1015
+ if (!p) error('Usage: pbr-tools.cjs init verify-work <phase>');
1016
+ output(initVerifyWork(p));
1017
+ } else if (command === 'init' && subcommand === 'phase-op') {
1018
+ getInit().cmdInitPhaseOp
1019
+ ? getInit().cmdInitPhaseOp(cwd, args[2], raw)
1020
+ : output(phaseInfo(args[2]));
1021
+ } else if (command === 'init' && subcommand === 'todos') {
1022
+ getInit().cmdInitTodos
1023
+ ? getInit().cmdInitTodos(cwd, args[2], raw)
1024
+ : output(todoList({}));
1025
+ } else if (command === 'init' && subcommand === 'milestone-op') {
1026
+ getInit().cmdInitMilestoneOp
1027
+ ? getInit().cmdInitMilestoneOp(cwd, raw)
1028
+ : output({ error: 'init milestone-op not available' });
1029
+ } else if (command === 'init' && subcommand === 'map-codebase') {
1030
+ getInit().cmdInitMapCodebase
1031
+ ? getInit().cmdInitMapCodebase(cwd, raw)
1032
+ : output({ error: 'init map-codebase not available' });
1033
+ } else if (command === 'init' && subcommand === 'progress') {
1034
+ output(initProgress());
1035
+ } else if (command === 'init') {
1036
+ error(`Unknown init workflow: ${subcommand}\nAvailable: execute-phase, plan-phase, new-project, new-milestone, quick, resume, verify-work, phase-op, todos, milestone-op, map-codebase, progress`);
1037
+
1038
+ // ─── Todo Operations ──────────────────────────────────────────────────────
1039
+ } else if (command === 'todo' && subcommand === 'list') {
1040
+ const opts = {};
1041
+ const themeIdx = args.indexOf('--theme');
1042
+ if (themeIdx !== -1 && args[themeIdx + 1]) opts.theme = args[themeIdx + 1];
1043
+ const statusIdx = args.indexOf('--status');
1044
+ if (statusIdx !== -1 && args[statusIdx + 1]) opts.status = args[statusIdx + 1];
1045
+ output(todoList(opts));
1046
+ } else if (command === 'todo' && subcommand === 'get') {
1047
+ const num = args[2];
1048
+ if (!num) error('Usage: pbr-tools.cjs todo get <NNN>');
1049
+ output(todoGet(num));
1050
+ } else if (command === 'todo' && subcommand === 'add') {
1051
+ const titleParts = [];
1052
+ const opts = {};
1053
+ for (let i = 2; i < args.length; i++) {
1054
+ if (args[i] === '--priority' && args[i + 1]) { opts.priority = args[++i]; }
1055
+ else if (args[i] === '--theme' && args[i + 1]) { opts.theme = args[++i]; }
1056
+ else if (args[i] === '--source' && args[i + 1]) { opts.source = args[++i]; }
1057
+ else { titleParts.push(args[i]); }
1058
+ }
1059
+ const title = titleParts.join(' ');
1060
+ if (!title) error('Usage: pbr-tools.cjs todo add <title> [--priority P1|P2|P3] [--theme <theme>]');
1061
+ output(todoAdd(title, opts));
1062
+ } else if (command === 'todo' && subcommand === 'done') {
1063
+ const num = args[2];
1064
+ if (!num) error('Usage: pbr-tools.cjs todo done <NNN>');
1065
+ output(todoDone(num));
1066
+
1067
+ // ─── History ──────────────────────────────────────────────────────────────
1068
+ } else if (command === 'history' && subcommand === 'append') {
1069
+ const type = args[2];
1070
+ const title = args[3];
1071
+ const body = args[4] || '';
1072
+ if (!type || !title) error('Usage: pbr-tools.cjs history append <type> <title> [body]');
1073
+ output(historyAppend({ type, title, body }));
1074
+ } else if (command === 'history' && subcommand === 'load') {
1075
+ output(historyLoad());
1076
+ } else if (command === 'history-digest') {
1077
+ getCommands().cmdHistoryDigest(cwd, raw);
1078
+
1079
+ // ─── Learnings ────────────────────────────────────────────────────────────
1080
+ } else if (command === 'learnings' && subcommand === 'ingest') {
1081
+ const jsonFile = args[2];
1082
+ if (!jsonFile) error('Usage: learnings ingest <json-file>');
1083
+ const rawContent = fs.readFileSync(jsonFile, 'utf8');
1084
+ const entry = JSON.parse(rawContent);
1085
+ output(getLearnings().learningsIngest(entry));
1086
+ } else if (command === 'learnings' && subcommand === 'query') {
1087
+ const filters = {};
1088
+ for (let i = 2; i < args.length; i++) {
1089
+ if (args[i] === '--tags' && args[i + 1]) { filters.tags = args[++i].split(',').map(t => t.trim()); }
1090
+ else if (args[i] === '--min-confidence' && args[i + 1]) { filters.minConfidence = args[++i]; }
1091
+ else if (args[i] === '--stack' && args[i + 1]) { filters.stack = args[++i]; }
1092
+ else if (args[i] === '--type' && args[i + 1]) { filters.type = args[++i]; }
1093
+ }
1094
+ output(getLearnings().learningsQuery(filters));
1095
+ } else if (command === 'learnings' && subcommand === 'check-thresholds') {
1096
+ output(getLearnings().checkDeferralThresholds());
1097
+ } else if (command === 'learnings' && subcommand === 'aggregate') {
1098
+ const filters = {};
1099
+ for (let i = 2; i < args.length; i++) {
1100
+ if (args[i] === '--project' && args[i + 1]) { filters.project = args[++i]; }
1101
+ else if (args[i] === '--type' && args[i + 1]) { filters.type = args[++i]; }
1102
+ else if (args[i] === '--top' && args[i + 1]) { filters.topN = parseInt(args[++i], 10); }
1103
+ }
1104
+ const cfg = (() => { try { return require('./lib/config.cjs').configLoad(planningDir) || {}; } catch (_) { return {}; } })();
1105
+ output(getLearnings().learningsAggregate(filters, { configFeatures: cfg.features || {} }), raw);
1106
+ } else if (command === 'learnings' && subcommand === 'copy-global') {
1107
+ const filePath = args[2];
1108
+ const projectName = args[3];
1109
+ if (!filePath || !projectName) error('Usage: learnings copy-global <learnings-md-path> <project-name>');
1110
+ output(getLearnings().copyToGlobal(filePath, projectName));
1111
+ } else if (command === 'learnings' && subcommand === 'query-global') {
1112
+ const filters = {};
1113
+ for (let i = 2; i < args.length; i++) {
1114
+ if (args[i] === '--tags' && args[i + 1]) { filters.tags = args[++i].split(',').map(t => t.trim()); }
1115
+ else if (args[i] === '--project' && args[i + 1]) { filters.project = args[++i]; }
1116
+ }
1117
+ output(getLearnings().queryGlobal(filters));
1118
+
1119
+ // ─── Intel ──────────────────────────────────────────────────────────────────
1120
+ } else if (command === 'intel' && subcommand === 'query') {
1121
+ const term = args[2];
1122
+ if (!term) error('Usage: intel query <term>');
1123
+ output(getIntel().intelQuery(term, planningDir));
1124
+ } else if (command === 'intel' && subcommand === 'update') {
1125
+ output(getIntel().intelUpdate(planningDir));
1126
+ } else if (command === 'intel' && subcommand === 'status') {
1127
+ output(getIntel().intelStatus(planningDir));
1128
+ } else if (command === 'intel' && subcommand === 'diff') {
1129
+ output(getIntel().intelDiff(planningDir));
1130
+ } else if (command === 'intel' && subcommand === 'snapshot') {
1131
+ output(getIntel().intelSnapshot(planningDir));
1132
+ } else if (command === 'intel' && subcommand === 'validate') {
1133
+ output(getIntel().intelValidate(planningDir));
1134
+ } else if (command === 'intel' && subcommand === 'extract-exports') {
1135
+ const filePath = args[2];
1136
+ if (!filePath) error('Usage: intel extract-exports <filepath>');
1137
+ output(getIntel().intelExtractExports(filePath));
1138
+ } else if (command === 'intel' && subcommand === 'patch-meta') {
1139
+ const filePath = args[2];
1140
+ if (!filePath) error('Usage: intel patch-meta <filepath>');
1141
+ output(getIntel().intelPatchMeta(filePath));
1142
+
1143
+ // ─── Build Pipeline ───────────────────────────────────────────────────────
1144
+ } else if (command === 'staleness-check') {
1145
+ const slug = args[1];
1146
+ if (!slug) error('Usage: staleness-check <phase-slug>');
1147
+ output(stalenessCheck(slug));
1148
+ } else if (command === 'summary-gate') {
1149
+ const slug = args[1];
1150
+ const planId = args[2];
1151
+ if (!slug || !planId) error('Usage: summary-gate <phase-slug> <plan-id>');
1152
+ output(summaryGate(slug, planId));
1153
+ } else if (command === 'checkpoint' && subcommand === 'init') {
1154
+ const slug = args[2];
1155
+ const plans = args[3] || '';
1156
+ output(checkpointInit(slug, plans));
1157
+ } else if (command === 'checkpoint' && subcommand === 'update') {
1158
+ const slug = args[2];
1159
+ const waveIdx = args.indexOf('--wave');
1160
+ const wave = waveIdx !== -1 ? parseInt(args[waveIdx + 1], 10) : 1;
1161
+ const resolvedIdx = args.indexOf('--resolved');
1162
+ const resolved = resolvedIdx !== -1 ? args[resolvedIdx + 1] : '';
1163
+ const shaIdx = args.indexOf('--sha');
1164
+ const sha = shaIdx !== -1 ? args[shaIdx + 1] : '';
1165
+ output(checkpointUpdate(slug, { wave, resolved, sha }));
1166
+ } else if (command === 'seeds' && subcommand === 'match') {
1167
+ const slug = args[2];
1168
+ const num = args[3];
1169
+ if (!slug) error('Usage: seeds match <phase-slug> <phase-number>');
1170
+ output(seedsMatch(slug, num));
1171
+ } else if (command === 'ci-poll') {
1172
+ const runId = args[1];
1173
+ const timeoutIdx = args.indexOf('--timeout');
1174
+ const timeoutSecs = timeoutIdx !== -1 ? parseInt(args[timeoutIdx + 1], 10) : 300;
1175
+ if (!runId) error('Usage: pbr-tools.cjs ci-poll <run-id> [--timeout <seconds>]');
1176
+ output(ciPoll(runId, timeoutSecs));
1177
+ } else if (command === 'rollback') {
1178
+ const manifestPath = args[1];
1179
+ if (!manifestPath) error('Usage: pbr-tools.cjs rollback <manifest-path>');
1180
+ output(rollbackPlan(manifestPath));
1181
+ } else if (command === 'build-preview') {
1182
+ const phaseSlug = args[1];
1183
+ if (!phaseSlug) error('Usage: pbr-tools.cjs build-preview <phase-slug>');
1184
+ const result = getPreview().buildPreview(phaseSlug, {}, planningDir, resolvePluginRoot());
1185
+ if (result && result.error) { output(result); process.exit(1); }
1186
+ output(result);
1187
+
1188
+ // ─── LLM Operations ──────────────────────────────────────────────────────
1189
+ } else if (command === 'llm' && subcommand === 'health') {
1190
+ output(getLlm().llmHealth(planningDir));
1191
+ } else if (command === 'llm' && subcommand === 'status') {
1192
+ output(getLlm().llmStatus(planningDir));
1193
+ } else if (command === 'llm' && subcommand === 'classify') {
1194
+ const fileType = args[2];
1195
+ const filePath = args[3];
1196
+ if (!fileType || !filePath) error('Usage: pbr-tools.cjs llm classify <PLAN|SUMMARY> <filepath>');
1197
+ output(await getLlm().llmClassify(planningDir, fileType, filePath));
1198
+ } else if (command === 'llm' && subcommand === 'score-source') {
1199
+ const sourceUrl = args[2];
1200
+ const filePath = args[3];
1201
+ if (!sourceUrl || !filePath) error('Usage: pbr-tools.cjs llm score-source <url> <file-path>');
1202
+ output(await getLlm().llmScoreSource(planningDir, sourceUrl, filePath));
1203
+ } else if (command === 'llm' && subcommand === 'classify-error') {
1204
+ const filePath = args[2];
1205
+ const agentType = args[3] || 'unknown';
1206
+ if (!filePath) error('Usage: pbr-tools.cjs llm classify-error <file-path> [agent-type]');
1207
+ output(await getLlm().llmClassifyError(planningDir, filePath, agentType));
1208
+ } else if (command === 'llm' && subcommand === 'summarize') {
1209
+ const filePath = args[2];
1210
+ const maxWords = args[3] ? parseInt(args[3], 10) : undefined;
1211
+ if (!filePath) error('Usage: pbr-tools.cjs llm summarize <file-path> [max-words]');
1212
+ output(await getLlm().llmSummarize(planningDir, filePath, maxWords));
1213
+ } else if (command === 'llm' && subcommand === 'metrics') {
1214
+ output(getLlm().llmMetrics(planningDir, args.slice(2)));
1215
+ } else if (command === 'llm' && subcommand === 'adjust-thresholds') {
1216
+ output(getLlm().llmAdjustThresholds(planningDir));
1217
+
1218
+ // ─── Session ──────────────────────────────────────────────────────────────
1219
+ } else if (command === 'session') {
1220
+ const core = getCore();
1221
+ const sub = args[1];
1222
+ const sessionIdIdx = args.indexOf('--session-id');
1223
+ const sessionId = sessionIdIdx !== -1 ? args[sessionIdIdx + 1] : null;
1224
+ const positional = sessionIdIdx !== -1
1225
+ ? args.filter((_a, i) => i !== sessionIdIdx && i !== sessionIdIdx + 1)
1226
+ : args;
1227
+ const key = positional[2];
1228
+ const value = positional[3];
1229
+ const dir = planningDir;
1230
+ if (sub === 'get') {
1231
+ if (!key) error('Usage: pbr-tools.cjs session get <key> [--session-id <id>]');
1232
+ if (!core.SESSION_ALLOWED_KEYS.includes(key)) error(`Unknown session key: ${key}. Allowed: ${core.SESSION_ALLOWED_KEYS.join(', ')}`);
1233
+ const data = core.sessionLoad(dir, sessionId);
1234
+ const val = Object.prototype.hasOwnProperty.call(data, key) ? data[key] : null;
1235
+ output({ key, value: val });
1236
+ } else if (sub === 'set') {
1237
+ if (!key || value === undefined) error('Usage: pbr-tools.cjs session set <key> <value> [--session-id <id>]');
1238
+ if (!core.SESSION_ALLOWED_KEYS.includes(key)) error(`Unknown session key: ${key}. Allowed: ${core.SESSION_ALLOWED_KEYS.join(', ')}`);
1239
+ let coerced = value;
1240
+ if (/^\d+$/.test(value)) coerced = parseInt(value, 10);
1241
+ else if (value === 'null') coerced = null;
1242
+ const result = core.sessionSave(dir, { [key]: coerced }, sessionId);
1243
+ if (!result.success) error(result.error || 'Failed to save session');
1244
+ output({ ok: true });
1245
+ } else if (sub === 'clear') {
1246
+ if (key) {
1247
+ if (!core.SESSION_ALLOWED_KEYS.includes(key)) error(`Unknown session key: ${key}. Allowed: ${core.SESSION_ALLOWED_KEYS.join(', ')}`);
1248
+ const result = core.sessionSave(dir, { [key]: null }, sessionId);
1249
+ if (!result.success) error(result.error || 'Failed to clear session key');
1250
+ } else {
1251
+ const sessionPath = sessionId
1252
+ ? core.resolveSessionPath(dir, '.session.json', sessionId)
1253
+ : path.join(dir, '.session.json');
1254
+ try { if (fs.existsSync(sessionPath)) fs.unlinkSync(sessionPath); } catch (e) { error(e.message); }
1255
+ }
1256
+ output({ ok: true });
1257
+ } else if (sub === 'dump') {
1258
+ const data = core.sessionLoad(dir, sessionId);
1259
+ output(data);
1260
+ } else {
1261
+ error('Usage: pbr-tools.cjs session get|set|clear|dump <key> [value] [--session-id <id>]');
1262
+ }
1263
+
1264
+ // ─── Claims ───────────────────────────────────────────────────────────────
1265
+ } else if (command === 'claim' && subcommand === 'acquire') {
1266
+ const phaseSlug = args[2];
1267
+ const sidIdx = args.indexOf('--session-id');
1268
+ const sessionId = sidIdx !== -1 ? args[sidIdx + 1] : null;
1269
+ const skillIdx = args.indexOf('--skill');
1270
+ const skill = skillIdx !== -1 ? args[skillIdx + 1] : 'unknown';
1271
+ if (!phaseSlug || !sessionId) error('Usage: pbr-tools.cjs claim acquire <phase-slug> --session-id <id> --skill <name>');
1272
+ const phaseDir = path.join(planningDir, 'phases', phaseSlug);
1273
+ if (!fs.existsSync(phaseDir)) { output({ error: `Phase directory not found: ${phaseSlug}` }); return; }
1274
+ output(getCore().acquireClaim(planningDir, phaseDir, sessionId, skill));
1275
+ } else if (command === 'claim' && subcommand === 'release') {
1276
+ const phaseSlug = args[2];
1277
+ const sidIdx = args.indexOf('--session-id');
1278
+ const sessionId = sidIdx !== -1 ? args[sidIdx + 1] : null;
1279
+ if (!phaseSlug || !sessionId) error('Usage: pbr-tools.cjs claim release <phase-slug> --session-id <id>');
1280
+ const phaseDir = path.join(planningDir, 'phases', phaseSlug);
1281
+ if (!fs.existsSync(phaseDir)) { output({ error: `Phase directory not found: ${phaseSlug}` }); return; }
1282
+ output(getCore().releaseClaim(planningDir, phaseDir, sessionId));
1283
+ } else if (command === 'claim' && subcommand === 'list') {
1284
+ output(getCore().listClaims(planningDir));
1285
+
1286
+ // ─── Verification ─────────────────────────────────────────────────────────
1287
+ } else if (command === 'verify' && subcommand === 'plan-structure') {
1288
+ getVerify().cmdVerifyPlanStructure(cwd, args[2], raw);
1289
+ } else if (command === 'verify' && subcommand === 'phase-completeness') {
1290
+ getVerify().cmdVerifyPhaseCompleteness(cwd, args[2], raw);
1291
+ } else if (command === 'verify' && subcommand === 'references') {
1292
+ getVerify().cmdVerifyReferences(cwd, args[2], raw);
1293
+ } else if (command === 'verify' && subcommand === 'commits') {
1294
+ getVerify().cmdVerifyCommits(cwd, args.slice(2), raw);
1295
+ } else if (command === 'verify' && subcommand === 'artifacts') {
1296
+ getVerify().cmdVerifyArtifacts(cwd, args[2], raw);
1297
+ } else if (command === 'verify' && subcommand === 'key-links') {
1298
+ getVerify().cmdVerifyKeyLinks(cwd, args[2], raw);
1299
+ } else if (command === 'verify' && subcommand === 'spot-check') {
1300
+ const scType = args[2];
1301
+ const scPath = args[3];
1302
+ if (!scType || !scPath) { error('Usage: verify spot-check <type> <path> (types: plan, summary, verification, quick)'); }
1303
+ const result = verifySpotCheck(scType, scPath);
1304
+ if (result.error) { process.stdout.write(JSON.stringify(result, null, 2) + '\n'); process.exit(1); }
1305
+ output(result, raw, result.passed ? 'passed' : 'failed');
1306
+ } else if (command === 'verify-summary') {
1307
+ const summaryPath = args[1];
1308
+ const countIndex = args.indexOf('--check-count');
1309
+ const checkCount = countIndex !== -1 ? parseInt(args[countIndex + 1], 10) : 2;
1310
+ getVerify().cmdVerifySummary(cwd, summaryPath, checkCount, raw);
1311
+ } else if (command === 'validate' && subcommand === 'consistency') {
1312
+ getVerify().cmdValidateConsistency(cwd, raw);
1313
+ } else if (command === 'validate' && subcommand === 'health') {
1314
+ const repairFlag = args.includes('--repair');
1315
+ getVerify().cmdValidateHealth(cwd, { repair: repairFlag }, raw);
1316
+ } else if (command === 'validate-project') {
1317
+ output(validateProject());
1318
+
1319
+ // ─── Trust Gate ───────────────────────────────────────────────────────────
1320
+ } else if (command === 'trust-gate') {
1321
+ const phaseNum = args[1] || '';
1322
+ const { resolveVerificationDepth } = require(path.join(__dirname, '..', '..', 'plugins', 'pbr', 'scripts', 'lib', 'trust-gate'));
1323
+ const config = getConfig().configLoad(planningDir);
1324
+ const depth = resolveVerificationDepth(planningDir, config);
1325
+ output({ depth, phase: phaseNum });
1326
+
1327
+ // ─── Frontmatter ──────────────────────────────────────────────────────────
1328
+ } else if (command === 'frontmatter' && subcommand === 'get') {
1329
+ const file = args[2];
1330
+ const fieldIdx = args.indexOf('--field');
1331
+ getFrontmatter().cmdFrontmatterGet(cwd, file, fieldIdx !== -1 ? args[fieldIdx + 1] : null, raw);
1332
+ } else if (command === 'frontmatter' && subcommand === 'set') {
1333
+ const file = args[2];
1334
+ const fieldIdx = args.indexOf('--field');
1335
+ const valueIdx = args.indexOf('--value');
1336
+ getFrontmatter().cmdFrontmatterSet(cwd, file, fieldIdx !== -1 ? args[fieldIdx + 1] : null, valueIdx !== -1 ? args[valueIdx + 1] : undefined, raw);
1337
+ } else if (command === 'frontmatter' && subcommand === 'merge') {
1338
+ const file = args[2];
1339
+ const dataIdx = args.indexOf('--data');
1340
+ getFrontmatter().cmdFrontmatterMerge(cwd, file, dataIdx !== -1 ? args[dataIdx + 1] : null, raw);
1341
+ } else if (command === 'frontmatter' && subcommand === 'validate') {
1342
+ const file = args[2];
1343
+ const schemaIdx = args.indexOf('--schema');
1344
+ getFrontmatter().cmdFrontmatterValidate(cwd, file, schemaIdx !== -1 ? args[schemaIdx + 1] : null, raw);
1345
+ } else if (command === 'frontmatter' && subcommand && !['get', 'set', 'merge', 'validate'].includes(subcommand)) {
1346
+ // Reference compat: frontmatter <filepath> (parse frontmatter from file)
1347
+ output(phaseFrontmatter(subcommand));
1348
+
1349
+ // ─── Templates ────────────────────────────────────────────────────────────
1350
+ } else if (command === 'template' && subcommand === 'select') {
1351
+ getTemplate().cmdTemplateSelect(cwd, args[2], raw);
1352
+ } else if (command === 'template' && subcommand === 'fill') {
1353
+ const templateType = args[2];
1354
+ const phaseIdx = args.indexOf('--phase');
1355
+ const planIdx = args.indexOf('--plan');
1356
+ const nameIdx = args.indexOf('--name');
1357
+ const typeIdx = args.indexOf('--type');
1358
+ const waveIdx = args.indexOf('--wave');
1359
+ const fieldsIdx = args.indexOf('--fields');
1360
+ getTemplate().cmdTemplateFill(cwd, templateType, {
1361
+ phase: phaseIdx !== -1 ? args[phaseIdx + 1] : null,
1362
+ plan: planIdx !== -1 ? args[planIdx + 1] : null,
1363
+ name: nameIdx !== -1 ? args[nameIdx + 1] : null,
1364
+ type: typeIdx !== -1 ? args[typeIdx + 1] : 'execute',
1365
+ wave: waveIdx !== -1 ? args[waveIdx + 1] : '1',
1366
+ fields: fieldsIdx !== -1 ? JSON.parse(args[fieldsIdx + 1]) : {},
1367
+ }, raw);
1368
+
1369
+ // ─── Milestones ───────────────────────────────────────────────────────────
1370
+ } else if (command === 'milestone' && subcommand === 'complete') {
1371
+ const nameIndex = args.indexOf('--name');
1372
+ const archivePhases = args.includes('--archive-phases');
1373
+ let milestoneName = null;
1374
+ if (nameIndex !== -1) {
1375
+ const nameArgs = [];
1376
+ for (let i = nameIndex + 1; i < args.length; i++) {
1377
+ if (args[i].startsWith('--')) break;
1378
+ nameArgs.push(args[i]);
1379
+ }
1380
+ milestoneName = nameArgs.join(' ') || null;
1381
+ }
1382
+ getMilestone().cmdMilestoneComplete(cwd, args[2], { name: milestoneName, archivePhases }, raw);
1383
+ } else if (command === 'milestone' && subcommand === 'stats') {
1384
+ const version = args[2];
1385
+ if (!version) error('Usage: milestone stats <version>');
1386
+ output(milestoneStats(version));
1387
+ } else if (command === 'milestone-stats') {
1388
+ const version = args[1];
1389
+ if (!version) error('Usage: pbr-tools.cjs milestone-stats <version>');
1390
+ output(milestoneStats(version));
1391
+
1392
+ // ─── Requirements ─────────────────────────────────────────────────────────
1393
+ } else if (command === 'requirements' && subcommand === 'mark-complete') {
1394
+ getMilestone().cmdRequirementsMarkComplete(cwd, args.slice(2), raw);
1395
+
1396
+ } else if (command === 'requirements' && subcommand === 'update-status') {
1397
+ const reqMod = require('./lib/requirements.cjs');
1398
+ const reqIdsIdx = args.indexOf('--req-ids');
1399
+ const statusIdx = args.indexOf('--status');
1400
+ if (reqIdsIdx === -1 || statusIdx === -1) {
1401
+ error('Usage: requirements update-status --req-ids REQ-01,REQ-02 --status done|reset');
1402
+ }
1403
+ const reqIds = args[reqIdsIdx + 1].split(',').map(s => s.trim()).filter(Boolean);
1404
+ const reqStatus = args[statusIdx + 1];
1405
+ if (!['done', 'reset'].includes(reqStatus)) error('--status must be "done" or "reset"');
1406
+ const result = reqMod.updateRequirementStatus(planningDir, reqIds, reqStatus);
1407
+ output(result, raw, `${result.updated} updated, ${result.skipped} skipped`);
1408
+
1409
+ } else if (command === 'requirements' && subcommand === 'mark-phase') {
1410
+ const reqMod = require('./lib/requirements.cjs');
1411
+ const phaseDirIdx = args.indexOf('--phase-dir');
1412
+ if (phaseDirIdx === -1) error('Usage: requirements mark-phase --phase-dir <path>');
1413
+ const targetPhaseDir = args[phaseDirIdx + 1];
1414
+ const config = configLoad();
1415
+ if (config && config.features && config.features.living_requirements === false) {
1416
+ output({ skipped: true, reason: 'features.living_requirements is disabled' }, raw, 'living requirements disabled');
1417
+ } else {
1418
+ const result = reqMod.markPhaseRequirements(planningDir, targetPhaseDir);
1419
+ output(result, raw, result.skipped_reason || `${result.updated} requirements marked`);
1420
+ }
1421
+
1422
+ } else if (command === 'requirements' && subcommand === 'status') {
1423
+ const reqMod = require('./lib/requirements.cjs');
1424
+ const statusMap = reqMod.getRequirementStatus(planningDir);
1425
+ const obj = {};
1426
+ for (const [k, v] of statusMap) { obj[k] = v; }
1427
+ output(obj, raw, `${statusMap.size} requirements found`);
1428
+
1429
+ // ─── Scaffolding ──────────────────────────────────────────────────────────
1430
+ } else if (command === 'scaffold') {
1431
+ const scaffoldType = args[1];
1432
+ const phaseIndex = args.indexOf('--phase');
1433
+ const nameIndex = args.indexOf('--name');
1434
+ const scaffoldOptions = {
1435
+ phase: phaseIndex !== -1 ? args[phaseIndex + 1] : null,
1436
+ name: nameIndex !== -1 ? args.slice(nameIndex + 1).join(' ') : null,
1437
+ };
1438
+ getCommands().cmdScaffold(cwd, scaffoldType, scaffoldOptions, raw);
1439
+
1440
+ // ─── Utility Commands ─────────────────────────────────────────────────────
1441
+ } else if (command === 'resolve-model') {
1442
+ getCommands().cmdResolveModel(cwd, args[1], raw);
1443
+ } else if (command === 'generate-slug' || command === 'slug-generate') {
1444
+ getCommands().cmdGenerateSlug(args[1], raw);
1445
+
1446
+ // ─── Quick Task Operations ─────────────────────────────────────────────────
1447
+ } else if (command === 'quick' && subcommand === 'init') {
1448
+ const desc = args.slice(2).join(' ') || '';
1449
+ const quickInitMod = require('./lib/quick-init.cjs');
1450
+ output(quickInitMod.quickInit(desc, planningDir));
1451
+
1452
+ } else if (command === 'current-timestamp') {
1453
+ getCommands().cmdCurrentTimestamp(args[1] || 'full', raw);
1454
+ } else if (command === 'verify-path-exists') {
1455
+ getCommands().cmdVerifyPathExists(cwd, args[1], raw);
1456
+ } else if (command === 'summary-extract') {
1457
+ const summaryPath = args[1];
1458
+ const fieldsIndex = args.indexOf('--fields');
1459
+ const fields = fieldsIndex !== -1 ? args[fieldsIndex + 1].split(',') : null;
1460
+ getCommands().cmdSummaryExtract(cwd, summaryPath, fields, raw);
1461
+ } else if (command === 'websearch') {
1462
+ const query = args[1];
1463
+ const limitIdx = args.indexOf('--limit');
1464
+ const freshnessIdx = args.indexOf('--freshness');
1465
+ await getCommands().cmdWebsearch(query, {
1466
+ limit: limitIdx !== -1 ? parseInt(args[limitIdx + 1], 10) : 10,
1467
+ freshness: freshnessIdx !== -1 ? args[freshnessIdx + 1] : null,
1468
+ }, raw);
1469
+ } else if (command === 'progress') {
1470
+ // If a sub-format is specified (table, bar), use the legacy render
1471
+ const fmt = args[1];
1472
+ if (fmt && ['table', 'bar', 'json'].includes(fmt)) {
1473
+ getCommands().cmdProgressRender(cwd, fmt, raw);
1474
+ } else {
1475
+ // DX progress data: phase dependency graph + agent activity
1476
+ const progressViz = require('./lib/progress-visualization.cjs');
1477
+ output(progressViz.getProgressData(planningDir, configLoad(planningDir)));
1478
+ }
1479
+
1480
+ // ─── Contextual Help ──────────────────────────────────────────────────────
1481
+ } else if (command === 'help-context') {
1482
+ const ctxHelp = require('./lib/contextual-help.cjs');
1483
+ output(ctxHelp.getContextualHelp(planningDir, configLoad(planningDir)));
1484
+
1485
+ // ─── Onboarding Guide ─────────────────────────────────────────────────────
1486
+ } else if (command === 'onboard') {
1487
+ const onboard = require('./lib/onboarding-generator.cjs');
1488
+ const result = onboard.generateOnboardingGuide(planningDir, configLoad(planningDir));
1489
+ if (raw) {
1490
+ output(result);
1491
+ } else {
1492
+ // Output the markdown field for human-readable usage
1493
+ process.stdout.write(result.markdown || '');
1494
+ }
1495
+
1496
+ } else if (command === 'commit') {
1497
+ const amend = args.includes('--amend');
1498
+ const filesIndex = args.indexOf('--files');
1499
+ const endIndex = filesIndex !== -1 ? filesIndex : args.length;
1500
+ const messageArgs = args.slice(1, endIndex).filter(a => !a.startsWith('--'));
1501
+ const message = messageArgs.join(' ') || undefined;
1502
+ const files = filesIndex !== -1 ? args.slice(filesIndex + 1).filter(a => !a.startsWith('--')) : [];
1503
+ getCommands().cmdCommit(cwd, message, files, raw, amend);
1504
+
1505
+ // ─── Reference & Skills ───────────────────────────────────────────────────
1506
+ } else if (command === 'reference') {
1507
+ const name = args[1];
1508
+ if (!name) error('Usage: pbr-tools.cjs reference <name> [--section <heading>] [--list]');
1509
+ const listFlag = args.includes('--list');
1510
+ const sectionIdx = args.indexOf('--section');
1511
+ const section = sectionIdx !== -1 ? args.slice(sectionIdx + 1).join(' ') : null;
1512
+ output(referenceGet(name, { section, list: listFlag }));
1513
+ } else if (command === 'skill-section') {
1514
+ if (args[1] === '--list') {
1515
+ const skillName = args[2];
1516
+ if (!skillName) error('Usage: pbr-tools.cjs skill-section --list <skill>');
1517
+ const listResult = listSkillHeadings(skillName);
1518
+ output(listResult);
1519
+ if (listResult.error) process.exit(1);
1520
+ } else {
1521
+ const skillName = args[1];
1522
+ const sectionQuery = args.slice(2).join(' ');
1523
+ if (!skillName || !sectionQuery) error('Usage: pbr-tools.cjs skill-section <skill> <section>');
1524
+ const secResult = skillSectionGet(skillName, sectionQuery);
1525
+ output(secResult);
1526
+ if (secResult.error) process.exit(1);
1527
+ }
1528
+ } else if (command === 'step-verify') {
1529
+ const skill = args[1];
1530
+ const step = args[2];
1531
+ const checklistStr = args[3] || '[]';
1532
+ let checklist;
1533
+ try { checklist = JSON.parse(checklistStr); } catch (_e) { output({ error: 'Invalid checklist JSON' }); process.exit(1); return; }
1534
+ const svContext = {
1535
+ planningDir,
1536
+ phaseSlug: process.env.PBR_PHASE_SLUG || '',
1537
+ planId: process.env.PBR_PLAN_ID || ''
1538
+ };
1539
+ const svResult = getStepVerify().stepVerify(skill, step, checklist, svContext);
1540
+ output(svResult);
1541
+ if (svResult.error || svResult.all_passed === false) process.exit(1);
1542
+ } else if (command === 'context-triage') {
1543
+ const opts = {};
1544
+ const agentsIdx = args.indexOf('--agents-done');
1545
+ if (agentsIdx !== -1) opts.agentsDone = parseInt(args[agentsIdx + 1], 10);
1546
+ const plansIdx = args.indexOf('--plans-total');
1547
+ if (plansIdx !== -1) opts.plansTotal = parseInt(args[plansIdx + 1], 10);
1548
+ const stepIdx = args.indexOf('--step');
1549
+ if (stepIdx !== -1) opts.currentStep = args[stepIdx + 1];
1550
+ output(contextTriage(opts));
1551
+ } else if (command === 'suggest-alternatives') {
1552
+ const errorType = args[1];
1553
+ const alt = getAlternatives();
1554
+ if (errorType === 'phase-not-found') {
1555
+ output(alt.phaseAlternatives(args[2] || '', planningDir));
1556
+ } else if (errorType === 'missing-prereq') {
1557
+ output(alt.prerequisiteAlternatives(args[2] || '', planningDir));
1558
+ } else if (errorType === 'config-invalid') {
1559
+ output(alt.configAlternatives(args[2] || '', args[3] || '', planningDir));
1560
+ } else {
1561
+ output({ error: 'Unknown error type. Valid: phase-not-found, missing-prereq, config-invalid' });
1562
+ process.exit(1);
1563
+ }
1564
+ } else if (command === 'spot-check') {
1565
+ const phaseSlug = args[1];
1566
+ const planId = args[2];
1567
+ if (!phaseSlug || !planId) error('Usage: spot-check <phaseSlug> <planId>');
1568
+ output(spotCheck(phaseSlug, planId));
1569
+
1570
+ // ─── Migration & Events ───────────────────────────────────────────────────
1571
+ } else if (command === 'migrate') {
1572
+ const dryRun = args.includes('--dry-run');
1573
+ const force = args.includes('--force');
1574
+ const result = await getMigrate().applyMigrations(planningDir, { dryRun, force });
1575
+ output(result);
1576
+ } else if (command === 'event') {
1577
+ const category = args[1];
1578
+ const eventName = args[2];
1579
+ let details = {};
1580
+ if (args[3]) {
1581
+ try { details = JSON.parse(args[3]); } catch (_e) { details = { raw: args[3] }; }
1582
+ }
1583
+ if (!category || !eventName) error('Usage: pbr-tools.cjs event <category> <event> [JSON-details]');
1584
+ const { logEvent } = require('./event-logger.cjs');
1585
+ logEvent(category, eventName, details);
1586
+ output({ logged: true, category, event: eventName });
1587
+ } else if (command === 'tmux' && subcommand === 'detect') {
1588
+ const tmuxEnv = process.env.TMUX || '';
1589
+ const result = {
1590
+ in_tmux: !!tmuxEnv,
1591
+ pane: process.env.TMUX_PANE || null,
1592
+ session: null
1593
+ };
1594
+ if (tmuxEnv) {
1595
+ const parts = tmuxEnv.split(',');
1596
+ if (parts.length >= 1) result.session = parts[0].split('/').pop() || null;
1597
+ }
1598
+ output(result);
1599
+
1600
+ // ─── List-todos (legacy alias) ────────────────────────────────────────────
1601
+ } else if (command === 'list-todos') {
1602
+ // Legacy GSD command -- forward to todo list
1603
+ output(todoList({ theme: args[1] || undefined }));
1604
+
1605
+ // ─── Status Render ────────────────────────────────────────────────────────
1606
+ } else if (command === 'status' && subcommand === 'render') {
1607
+ output(getStatusRender().statusRender(planningDir));
1608
+
1609
+ // ─── Suggest Next ──────────────────────────────────────────────────────────
1610
+ } else if (command === 'suggest-next') {
1611
+ output(getSuggestNext().suggestNext(planningDir));
1612
+
1613
+ // ─── Dashboard ─────────────────────────────────────────────────────────────
1614
+ } else if (command === 'dashboard') {
1615
+ const { spawn } = require('child_process');
1616
+ const dashboardDir = path.join(__dirname, '..', '..', 'dashboard', 'server');
1617
+ const dashboardIndex = path.join(dashboardDir, 'index.js');
1618
+
1619
+ if (!fs.existsSync(dashboardIndex)) {
1620
+ error(`Dashboard server not found at ${dashboardDir}. Ensure dashboard/server/ exists.`);
1621
+ }
1622
+
1623
+ // Check if node_modules exist in dashboard/server
1624
+ if (!fs.existsSync(path.join(dashboardDir, 'node_modules'))) {
1625
+ process.stderr.write('Installing dashboard dependencies...\n');
1626
+ const install = require('child_process').execSync('npm install', {
1627
+ cwd: dashboardDir,
1628
+ stdio: 'inherit'
1629
+ });
1630
+ }
1631
+
1632
+ const port = subcommand || process.env.PBR_DASHBOARD_PORT || '3141';
1633
+
1634
+ if (args[1] === 'stop') {
1635
+ // Find and kill existing dashboard process
1636
+ try {
1637
+ const pid = fs.readFileSync(path.join(cwd, '.planning', '.dashboard-pid'), 'utf8').trim();
1638
+ process.kill(Number(pid), 'SIGTERM');
1639
+ fs.unlinkSync(path.join(cwd, '.planning', '.dashboard-pid'));
1640
+ process.stderr.write(`Dashboard stopped (PID ${pid})\n`);
1641
+ output({ stopped: true, pid: Number(pid) });
1642
+ } catch {
1643
+ process.stderr.write('No running dashboard found.\n');
1644
+ output({ stopped: false });
1645
+ }
1646
+ } else {
1647
+ // Start dashboard server
1648
+ const child = spawn(process.execPath, [dashboardIndex], {
1649
+ cwd: cwd,
1650
+ env: { ...process.env, PBR_DASHBOARD_PORT: port },
1651
+ stdio: 'inherit',
1652
+ detached: false,
1653
+ });
1654
+
1655
+ // Write PID for stop command
1656
+ const pidDir = path.join(cwd, '.planning');
1657
+ if (fs.existsSync(pidDir)) {
1658
+ fs.writeFileSync(path.join(pidDir, '.dashboard-pid'), String(child.pid));
1659
+ }
1660
+
1661
+ child.on('error', (err) => {
1662
+ process.stderr.write(`Dashboard failed to start: ${err.message}\n`);
1663
+ process.exit(1);
1664
+ });
1665
+
1666
+ // Keep parent alive while dashboard runs
1667
+ child.on('exit', (code) => {
1668
+ const pidFile = path.join(cwd, '.planning', '.dashboard-pid');
1669
+ try { fs.unlinkSync(pidFile); } catch {}
1670
+ process.exit(code || 0);
1671
+ });
1672
+
1673
+ // Forward SIGINT/SIGTERM to child
1674
+ process.on('SIGINT', () => child.kill('SIGINT'));
1675
+ process.on('SIGTERM', () => child.kill('SIGTERM'));
1676
+
1677
+ // Prevent main() from exiting
1678
+ return new Promise(() => {});
1679
+ }
1680
+
1681
+ // ─── Parse Args ────────────────────────────────────────────────────────────
1682
+ } else if (command === 'parse-args') {
1683
+ const type = args[1];
1684
+ const rawInput = args.slice(2).join(' ');
1685
+ if (!type) error('Usage: pbr-tools.cjs parse-args <type> <args>\nTypes: plan, quick');
1686
+ output(getParseArgs().parseArgs(type, rawInput));
1687
+
1688
+ // ─── Status Fingerprint ──────────────────────────────────────────────────
1689
+ } else if (command === 'status' && subcommand === 'fingerprint') {
1690
+ const crypto = require('crypto');
1691
+ const files = {};
1692
+ let combinedContent = '';
1693
+ for (const name of ['STATE.md', 'ROADMAP.md']) {
1694
+ const filePath = path.join(planningDir, name);
1695
+ try {
1696
+ const content = fs.readFileSync(filePath, 'utf8');
1697
+ const stat = fs.statSync(filePath);
1698
+ const hash = crypto.createHash('sha256').update(content).digest('hex').slice(0, 8);
1699
+ files[name] = {
1700
+ hash,
1701
+ mtime: stat.mtime.toISOString(),
1702
+ lines: content.split('\n').length
1703
+ };
1704
+ combinedContent += content;
1705
+ } catch {
1706
+ files[name] = { hash: null, mtime: null, lines: 0 };
1707
+ }
1708
+ }
1709
+ const fingerprint = combinedContent
1710
+ ? crypto.createHash('sha256').update(combinedContent).digest('hex').slice(0, 8)
1711
+ : null;
1712
+ // Count phase directories
1713
+ let phaseDirs = 0;
1714
+ const phasesDir = path.join(planningDir, 'phases');
1715
+ try {
1716
+ const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
1717
+ phaseDirs = entries.filter(e => e.isDirectory()).length;
1718
+ } catch { /* no phases dir */ }
1719
+ output({
1720
+ fingerprint,
1721
+ files,
1722
+ phase_dirs: phaseDirs,
1723
+ timestamp: new Date().toISOString()
1724
+ });
1725
+
1726
+ // ─── Decisions Operations ───────────────────────────────────────────────
1727
+ } else if (command === 'decisions' && subcommand === 'record') {
1728
+ const opts = {};
1729
+ for (let i = 2; i < args.length; i++) {
1730
+ if (args[i] === '--decision' && args[i + 1]) { opts.decision = args[++i]; }
1731
+ else if (args[i] === '--rationale' && args[i + 1]) { opts.rationale = args[++i]; }
1732
+ else if (args[i] === '--context' && args[i + 1]) { opts.context = args[++i]; }
1733
+ else if (args[i] === '--agent' && args[i + 1]) { opts.agent = args[++i]; }
1734
+ else if (args[i] === '--phase' && args[i + 1]) { opts.phase = args[++i]; }
1735
+ else if (args[i] === '--tags' && args[i + 1]) { opts.tags = args[++i].split(',').map(t => t.trim()); }
1736
+ else if (args[i] === '--alternatives' && args[i + 1]) { opts.alternatives = args[++i].split(',').map(a => a.trim()); }
1737
+ else if (args[i] === '--consequences' && args[i + 1]) { opts.consequences = args[++i]; }
1738
+ }
1739
+ if (!opts.decision) error('Usage: decisions record --decision "..." --rationale "..." [--context "..."] [--agent name] [--phase NN] [--tags t1,t2] [--alternatives a1,a2] [--consequences "..."]');
1740
+ output(decisionsRecord(opts));
1741
+ } else if (command === 'decisions' && subcommand === 'list') {
1742
+ const filters = {};
1743
+ const statusIdx = args.indexOf('--status');
1744
+ if (statusIdx !== -1 && args[statusIdx + 1]) filters.status = args[statusIdx + 1];
1745
+ const phaseIdx = args.indexOf('--phase');
1746
+ if (phaseIdx !== -1 && args[phaseIdx + 1]) filters.phase = args[phaseIdx + 1];
1747
+ const tagIdx = args.indexOf('--tag');
1748
+ if (tagIdx !== -1 && args[tagIdx + 1]) filters.tag = args[tagIdx + 1];
1749
+ output(decisionsList(Object.keys(filters).length > 0 ? filters : undefined));
1750
+ } else if (command === 'decisions') {
1751
+ error(`Unknown decisions subcommand: ${subcommand}\nAvailable: record, list`);
1752
+
1753
+ // ─── Negative Knowledge ────────────────────────────────────────────────────
1754
+ } else if (command === 'negative-knowledge' && subcommand === 'record') {
1755
+ const nkArgs = {};
1756
+ for (let i = 2; i < args.length; i++) {
1757
+ if (args[i] === '--title' && args[i + 1]) { nkArgs.title = args[++i]; }
1758
+ else if (args[i] === '--category' && args[i + 1]) { nkArgs.category = args[++i]; }
1759
+ else if (args[i] === '--files' && args[i + 1]) { nkArgs.filesInvolved = args[++i].split(',').map(f => f.trim()); }
1760
+ else if (args[i] === '--what-tried' && args[i + 1]) { nkArgs.whatTried = args[++i]; }
1761
+ else if (args[i] === '--why-failed' && args[i + 1]) { nkArgs.whyFailed = args[++i]; }
1762
+ else if (args[i] === '--what-worked' && args[i + 1]) { nkArgs.whatWorked = args[++i]; }
1763
+ else if (args[i] === '--phase' && args[i + 1]) { nkArgs.phase = args[++i]; }
1764
+ }
1765
+ if (!nkArgs.title || !nkArgs.category) error('Usage: negative-knowledge record --title "..." --category <cat> --files "a,b" --what-tried "..." --why-failed "..."');
1766
+ const result = getNegativeKnowledge().recordFailure(planningDir, nkArgs);
1767
+ output(result);
1768
+ } else if (command === 'negative-knowledge' && subcommand === 'query') {
1769
+ let files = [];
1770
+ for (let i = 2; i < args.length; i++) {
1771
+ if (args[i] === '--files' && args[i + 1]) { files = args[++i].split(',').map(f => f.trim()); }
1772
+ }
1773
+ if (files.length === 0) error('Usage: negative-knowledge query --files "path1,path2"');
1774
+ output(getNegativeKnowledge().queryByFiles(planningDir, files));
1775
+ } else if (command === 'negative-knowledge' && subcommand === 'list') {
1776
+ const filters = {};
1777
+ for (let i = 2; i < args.length; i++) {
1778
+ if (args[i] === '--category' && args[i + 1]) { filters.category = args[++i]; }
1779
+ else if (args[i] === '--phase' && args[i + 1]) { filters.phase = args[++i]; }
1780
+ else if (args[i] === '--status' && args[i + 1]) { filters.status = args[++i]; }
1781
+ }
1782
+ output(getNegativeKnowledge().listFailures(planningDir, filters));
1783
+ } else if (command === 'negative-knowledge') {
1784
+ error(`Unknown negative-knowledge subcommand: ${subcommand}\nAvailable: record, query, list`);
1785
+
1786
+ // ─── Patterns Operations (Phase 16: Cross-project pattern library) ────────
1787
+ } else if (command === 'patterns' && subcommand === 'extract') {
1788
+ const jsonFile = args[2];
1789
+ if (!jsonFile) error('Usage: patterns extract <json-file>');
1790
+ const entry = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
1791
+ const cfg = (() => { try { return require('./lib/config.cjs').configLoad(planningDir) || {}; } catch (_) { return {}; } })();
1792
+ output(getPatterns().patternExtract(entry, { configFeatures: cfg.features || {} }), raw);
1793
+ } else if (command === 'patterns' && subcommand === 'query') {
1794
+ const filters = {};
1795
+ for (let i = 2; i < args.length; i++) {
1796
+ if (args[i] === '--tags' && args[i + 1]) { filters.tags = args[++i].split(',').map(t => t.trim()); }
1797
+ else if (args[i] === '--type' && args[i + 1]) { filters.type = args[++i]; }
1798
+ else if (args[i] === '--stack' && args[i + 1]) { filters.stack = args[++i]; }
1799
+ else if (args[i] === '--min-confidence' && args[i + 1]) { filters.minConfidence = parseFloat(args[++i]); }
1800
+ }
1801
+ const cfg = (() => { try { return require('./lib/config.cjs').configLoad(planningDir) || {}; } catch (_) { return {}; } })();
1802
+ output(getPatterns().patternQuery(filters, { configFeatures: cfg.features || {} }), raw);
1803
+ } else if (command === 'patterns' && subcommand === 'list') {
1804
+ const cfg = (() => { try { return require('./lib/config.cjs').configLoad(planningDir) || {}; } catch (_) { return {}; } })();
1805
+ output(getPatterns().patternList({ configFeatures: cfg.features || {} }), raw);
1806
+ } else if (command === 'patterns') {
1807
+ error(`Unknown patterns subcommand: ${subcommand}\nAvailable: extract, query, list`);
1808
+
1809
+ // ─── Templates Operations (Phase 16: Spec templates) ─────────────────────
1810
+ } else if (command === 'templates' && subcommand === 'list') {
1811
+ const cfg = (() => { try { return require('./lib/config.cjs').configLoad(planningDir) || {}; } catch (_) { return {}; } })();
1812
+ output(getTemplates().templateList({ configFeatures: cfg.features || {} }), raw);
1813
+ } else if (command === 'templates' && subcommand === 'instantiate') {
1814
+ const templateName = args[2];
1815
+ if (!templateName) error('Usage: templates instantiate <name> [--param key=value ...]');
1816
+ const params = {};
1817
+ for (let i = 3; i < args.length; i++) {
1818
+ if (args[i] === '--param' && args[i + 1]) {
1819
+ const kv = args[++i];
1820
+ const eqIdx = kv.indexOf('=');
1821
+ if (eqIdx !== -1) {
1822
+ params[kv.slice(0, eqIdx)] = kv.slice(eqIdx + 1);
1823
+ }
1824
+ }
1825
+ }
1826
+ const cfg = (() => { try { return require('./lib/config.cjs').configLoad(planningDir) || {}; } catch (_) { return {}; } })();
1827
+ output(getTemplates().templateInstantiate(templateName, params, { configFeatures: cfg.features || {} }), raw);
1828
+ } else if (command === 'templates') {
1829
+ error(`Unknown templates subcommand: ${subcommand}\nAvailable: list, instantiate`);
1830
+
1831
+ // ─── Graph Operations ─────────────────────────────────────────────────────
1832
+ } else if (command === 'graph') {
1833
+ const graphCli = require('./lib/graph-cli.cjs');
1834
+ graphCli.handleGraphCommand(subcommand, args, planningDir, cwd, output, error);
1835
+
1836
+ // ─── Spec Operations (Phase 11: Spec-Driven Development) ─────────────────
1837
+ } else if (command === 'spec') {
1838
+ handleSpec(args, planningDir, cwd, output, error);
1839
+
1840
+ // ─── Incident Journal ────────────────────────────────────────────────────
1841
+ } else if (command === 'incidents') {
1842
+ const incidents = getIncidents();
1843
+ const sub = subcommand;
1844
+ const planningDirOpts = { planningDir, cwd };
1845
+
1846
+ if (sub === 'record') {
1847
+ const entry = parseIncidentFlags(args.slice(2));
1848
+ const written = incidents.record(entry, planningDirOpts);
1849
+ output(written || { recorded: false }, raw);
1850
+ } else if (sub === 'list') {
1851
+ const limitIdx = args.indexOf('--limit');
1852
+ const limit = limitIdx >= 0 ? parseInt(args[limitIdx + 1], 10) : 50;
1853
+ output(incidents.list({ ...planningDirOpts, limit }), raw);
1854
+ } else if (sub === 'query') {
1855
+ const filter = parseQueryFlags(args.slice(2));
1856
+ output(incidents.query(filter, planningDirOpts), raw);
1857
+ } else if (sub === 'summary') {
1858
+ output(incidents.summary(planningDirOpts), raw);
1859
+ } else {
1860
+ error('Unknown incidents subcommand. Use: record|list|query|summary');
1861
+ }
1862
+
1863
+ // ─── Unknown Command ──────────────────────────────────────────────────────
1864
+ } else {
1865
+ const allCommands = 'state load|check-progress|update|get|json|patch|advance-plan|record-metric|record-activity|update-progress|add-decision|add-blocker|resolve-blocker|record-session, state-bundle, state-snapshot, config validate|load-defaults|save-defaults|resolve-depth|get|set|ensure-section, phase add|remove|list|complete|insert|info|commits-for|first-last-commit|next-decimal, phases list, phase-info, phase-plan-index, find-phase, plan-index, must-haves, roadmap get-phase|analyze|update-plan-progress|update-status|update-plans|append-phase|remove-phase|insert-phase, init execute-phase|plan-phase|new-project|new-milestone|quick|resume|verify-work|phase-op|todos|milestone-op|map-codebase|progress, todo list|get|add|done, decisions record|list, negative-knowledge record|query|list, history append|load, history-digest, learnings ingest|query|check-thresholds|aggregate, patterns extract|query|list, templates list|instantiate, incidents record|list|query|summary, intel query|update|status|diff, staleness-check, summary-gate, checkpoint init|update, seeds match, ci-poll, rollback, build-preview, llm health|status|classify|score-source|classify-error|summarize|metrics|adjust-thresholds, session get|set|clear|dump, claim acquire|release|list, verify plan-structure|phase-completeness|references|commits|artifacts|key-links, verify-summary, validate consistency|health, validate-project, frontmatter get|set|merge|validate, template select|fill, milestone complete|stats, milestone-stats, requirements mark-complete, scaffold, resolve-model, generate-slug|slug-generate, quick init, current-timestamp, verify-path-exists, summary-extract, websearch, progress, commit, reference, skill-section, step-verify, context-triage, suggest-alternatives, spot-check, status render|fingerprint, parse-args plan|quick, migrate, event, dashboard [port|stop], tmux detect, help';
1866
+ error(`Unknown command: ${args.join(' ')}\nCommands: ${allCommands}`);
1867
+ }
1868
+ } catch (e) {
1869
+ getCore().error(e.message);
1870
+ }
1871
+ }
1872
+
1873
+ if (require.main === module || process.argv[1] === __filename) {
1874
+ main().catch(err => { process.stderr.write(err.message + '\n'); process.exit(1); });
1875
+ }
1876
+
1877
+ module.exports = { main };