pan-wizard 3.35.0 → 3.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/CHANGELOG.md +3645 -0
  2. package/README.md +46 -52
  3. package/agents/pan-conductor.md +2 -3
  4. package/agents/pan-counterfactual.md +1 -2
  5. package/agents/pan-debugger.md +14 -3
  6. package/agents/pan-design-checker.md +1 -2
  7. package/agents/pan-designer.md +2 -3
  8. package/agents/pan-document_code.md +1 -2
  9. package/agents/pan-executor.md +25 -0
  10. package/agents/pan-hardener.md +4 -3
  11. package/agents/pan-integration-checker.md +1 -2
  12. package/agents/pan-knowledge.md +1 -2
  13. package/agents/pan-meta-reviewer.md +3 -3
  14. package/agents/pan-optimizer.md +4 -4
  15. package/agents/pan-phase-researcher.md +80 -475
  16. package/agents/pan-plan-checker.md +40 -3
  17. package/agents/pan-planner.md +21 -7
  18. package/agents/pan-previewer.md +3 -2
  19. package/agents/pan-project-researcher.md +72 -493
  20. package/agents/pan-release.md +1 -1
  21. package/agents/pan-reviewer.md +14 -3
  22. package/agents/pan-roadmapper.md +12 -7
  23. package/agents/pan-verifier.md +9 -4
  24. package/bin/install-lib.cjs +134 -14
  25. package/bin/install.js +59 -12
  26. package/commands/pan/army.md +1 -1
  27. package/commands/pan/autodev.md +76 -0
  28. package/commands/pan/cost.md +21 -1
  29. package/commands/pan/exec-phase.md +3 -4
  30. package/commands/pan/focus-auto.md +14 -7
  31. package/commands/pan/focus-design.md +4 -5
  32. package/commands/pan/focus-docs.md +24 -0
  33. package/commands/pan/learn.md +13 -6
  34. package/commands/pan/milestone-audit.md +8 -1
  35. package/commands/pan/milestone-done.md +10 -5
  36. package/commands/pan/milestone-new.md +2 -2
  37. package/commands/pan/new-project.md +15 -12
  38. package/commands/pan/plan-phase.md +15 -9
  39. package/commands/pan/preview.md +1 -1
  40. package/commands/pan/quick.md +1 -1
  41. package/commands/pan/review-deep.md +11 -5
  42. package/commands/pan/settings.md +6 -0
  43. package/commands/pan/verify-phase.md +6 -2
  44. package/docs/AGENTS.md +917 -0
  45. package/docs/ARCHITECTURE.md +1054 -0
  46. package/docs/CLI-REFERENCE.md +4582 -0
  47. package/docs/COMPARISON.md +116 -0
  48. package/docs/DEVELOPMENT.md +490 -0
  49. package/docs/ECOSYSTEM-REVIEW-2026-06.md +107 -0
  50. package/docs/ECOSYSTEM-REVIEW-2026-08.md +349 -0
  51. package/docs/EXAMPLES.md +584 -0
  52. package/docs/FAQ.md +254 -0
  53. package/docs/FIELD-HARVEST-2026-07.md +88 -0
  54. package/docs/FIELD-REPORT-army-2026-06.md +121 -0
  55. package/docs/HOOKS.md +638 -0
  56. package/docs/IMPROVEMENT-TODO.md +246 -0
  57. package/docs/INTERNALS.md +485 -0
  58. package/docs/MIGRATION-v2-to-v3.md +258 -0
  59. package/docs/SECURITY-HARDENING.md +230 -0
  60. package/docs/SKILLS-ENHANCEMENT-PLAN-V2.md +122 -0
  61. package/docs/SKILLS-FULL-TEXT.md +9685 -0
  62. package/docs/SKILLS-REFERENCE.md +1037 -0
  63. package/docs/TROUBLESHOOTING.md +1084 -0
  64. package/docs/USER-GUIDE.md +1437 -0
  65. package/docs/archive/SKILLS-ENHANCEMENT-PLAN.md +230 -0
  66. package/docs/audits/AUDIT-2026-08-e2e-ROADMAP.md +117 -0
  67. package/docs/audits/AUDIT-2026-08-e2e-VERIFICATION.md +693 -0
  68. package/docs/audits/AUDIT-2026-08-e2e.md +1546 -0
  69. package/docs/audits/OUTSTANDING-2026-08.md +275 -0
  70. package/docs/audits/STABILITY-TEST-2026-08.md +640 -0
  71. package/docs/branding/README-brand-draft.md +119 -0
  72. package/docs/branding/handoff/IMPLEMENTATION.md +205 -0
  73. package/docs/branding/handoff/README-brand-draft.md +119 -0
  74. package/docs/branding/handoff/image-prompts.md +46 -0
  75. package/docs/branding/image-prompts.md +46 -0
  76. package/docs/branding/nano-banana-prompts.txt +60 -0
  77. package/docs/context-monitor.md +13 -0
  78. package/docs/decisions/ADR-0001-strategic-feature-prioritization.md +83 -0
  79. package/docs/decisions/ADR-0002-copilot-cli-runtime.md +71 -0
  80. package/docs/decisions/ADR-0003-smart-execution.md +84 -0
  81. package/docs/decisions/ADR-0004-copilot-cli-interaction.md +89 -0
  82. package/docs/decisions/ADR-0005-command-naming.md +80 -0
  83. package/docs/decisions/ADR-0006-focus-commands.md +101 -0
  84. package/docs/decisions/ADR-0007-ship-v1.md +73 -0
  85. package/docs/decisions/ADR-0008-map-codebase-mermaid-togaf.md +80 -0
  86. package/docs/decisions/ADR-0009-production-deployment-checklist.md +68 -0
  87. package/docs/decisions/ADR-0010-standards-integration.md +79 -0
  88. package/docs/decisions/ADR-0011-help-commands-rewrite.md +64 -0
  89. package/docs/decisions/ADR-0012-contributors-attribution-index.md +42 -0
  90. package/docs/decisions/ADR-0013-strategic-feature-additions.md +53 -0
  91. package/docs/decisions/ADR-0014-internal-cleanup-code-quality.md +53 -0
  92. package/docs/decisions/ADR-0015-focus-auto-runner.md +296 -0
  93. package/docs/decisions/ADR-0016-enhanced-doc-sync.md +54 -0
  94. package/docs/decisions/ADR-0017-enhanced-focus-design.md +69 -0
  95. package/docs/decisions/ADR-0018-user-reality-testing.md +84 -0
  96. package/docs/decisions/ADR-0019-end-to-end-user-acceptance-testing.md +113 -0
  97. package/docs/decisions/ADR-0020-ai-drift-prevention.md +55 -0
  98. package/docs/decisions/ADR-0021-codebase-mapper-v2.md +76 -0
  99. package/docs/decisions/ADR-0022-lifecycle-completeness.md +63 -0
  100. package/docs/decisions/ADR-0023-opus-4-7-adoption.md +89 -0
  101. package/docs/decisions/ADR-0024-spec-b-v2-completion.md +137 -0
  102. package/docs/decisions/ADR-0025-behavioral-guardrails-layer.md +129 -0
  103. package/docs/decisions/ADR-0026-self-improvement-loop.md +171 -0
  104. package/docs/decisions/ADR-0027-doc-code-link-graph.md +164 -0
  105. package/docs/decisions/ADR-0028-unified-agents-skills-target.md +46 -0
  106. package/docs/decisions/ADR-0029-experiment-evaluator.md +76 -0
  107. package/docs/decisions/ADR-0030-planning-concurrency.md +37 -0
  108. package/docs/decisions/ADR-0031-focus-auto-backlog-source.md +47 -0
  109. package/docs/decisions/ADR-0032-squad-model.md +64 -0
  110. package/docs/decisions/ADR-0033-army-campaign.md +40 -0
  111. package/docs/decisions/ADR-0034-scheduled-campaigns.md +57 -0
  112. package/docs/decisions/ADR-0035-army-hud-dashboard.md +40 -0
  113. package/docs/decisions/ADR-0036-agentic-memory-architecture.md +106 -0
  114. package/docs/decisions/ADR-0037-pin-security-agents-to-opus.md +51 -0
  115. package/docs/decisions/ADR-0038-skill-aligned-decomposition.md +41 -0
  116. package/docs/decisions/ADR-0039-worktree-as-project-variant.md +37 -0
  117. package/docs/decisions/ADR-0040-memory-injection-defense.md +55 -0
  118. package/docs/decisions/ADR-0041-mcp-dual-era-bridge.md +47 -0
  119. package/docs/decisions/ADR-0042-design-parity-both-flows.md +45 -0
  120. package/docs/decisions/ADR-0043-addressable-planning-roots.md +56 -0
  121. package/docs/decisions/ADR-0044-bound-the-cached-context.md +104 -0
  122. package/docs/decisions/ADR-0045-agent-plugins-bundle.md +76 -0
  123. package/docs/decisions/ADR-0046-subagent-frontmatter-decisions.md +39 -0
  124. package/docs/decisions/ADR-0047-pan-harness.md +76 -0
  125. package/docs/decisions/ADR-0048-one-core-per-project.md +43 -0
  126. package/docs/decisions/ADR-0049-machine-verdicts-and-findings-ledger.md +116 -0
  127. package/docs/specs/ai_drift_prevention_featureai.md +286 -0
  128. package/docs/specs/codebase_mapper_v2_featureai.md +930 -0
  129. package/docs/specs/command_naming_optimization_featureai.md +930 -0
  130. package/docs/specs/comp_analysis_markdown_v1.md +149 -0
  131. package/docs/specs/continuous_autonomous_execution_featureai.md +304 -0
  132. package/docs/specs/contributors_attribution_index_featureai.md +476 -0
  133. package/docs/specs/copilot_cli_interaction_featureai.md +868 -0
  134. package/docs/specs/copilot_cli_runtime_featureai.md +647 -0
  135. package/docs/specs/custom-skills-assessment.md +461 -0
  136. package/docs/specs/deployment_audit_findings_featureai.md +243 -0
  137. package/docs/specs/doc_code_link_graph_featureai.md +253 -0
  138. package/docs/specs/documentation_alignment_cleanup_featureai.md +69 -0
  139. package/docs/specs/e2e_visual_testing_featureai.md +615 -0
  140. package/docs/specs/end_to_end_user_acceptance_testing_featureai.md +810 -0
  141. package/docs/specs/evidence-loop-plan.md +76 -0
  142. package/docs/specs/evidence_loop_featureai.md +497 -0
  143. package/docs/specs/focus-auto-optimize-category.md +449 -0
  144. package/docs/specs/focus-auto-optimize-superplan.md +188 -0
  145. package/docs/specs/focus_auto_runner_featureai.md +1102 -0
  146. package/docs/specs/focus_design_v2_featureai.md +197 -0
  147. package/docs/specs/focus_sync_v2_featureai.md +202 -0
  148. package/docs/specs/git_integration_overhaul_featureai.md +326 -0
  149. package/docs/specs/glm_zai_provider_featureai.md +200 -0
  150. package/docs/specs/googlecli_adoption_featureai.md +661 -0
  151. package/docs/specs/help_commands_rewrite_featureai.md +860 -0
  152. package/docs/specs/industry_analysis_strategic_additions_featureai.md +231 -0
  153. package/docs/specs/industry_comparison_and_feature_gaps_featureai.md +674 -0
  154. package/docs/specs/internal_cleanup_code_quality_featureai.md +486 -0
  155. package/docs/specs/investigations/README.md +31 -0
  156. package/docs/specs/investigations/digests/2026-09-28.md +47 -0
  157. package/docs/specs/investigations/digests/2026-10-08.md +62 -0
  158. package/docs/specs/investigations/digests/2026-10-10.md +61 -0
  159. package/docs/specs/investigations/features/debugger-red-loop-first.md +55 -0
  160. package/docs/specs/investigations/features/harness-cross-host-behaviour.md +93 -0
  161. package/docs/specs/investigations/features/optimize-apply-regression-gate.md +66 -0
  162. package/docs/specs/investigations/features/reviewer-smell-baseline.md +57 -0
  163. package/docs/specs/investigations/features/trace-failure-capture.md +69 -0
  164. package/docs/specs/lifecycle_completeness_featureai.md +754 -0
  165. package/docs/specs/local-first-ci.md +42 -0
  166. package/docs/specs/map_codebase_mermaid_togaf_featureai.md +805 -0
  167. package/docs/specs/market-delta-2026-09-superplan.md +310 -0
  168. package/docs/specs/market-ideas-2026-09.md +131 -0
  169. package/docs/specs/market-ideas-2026-10.md +428 -0
  170. package/docs/specs/market-ideas-ledger.md +177 -0
  171. package/docs/specs/memory-optimization-2026-10.md +285 -0
  172. package/docs/specs/multi-track-planning-roots.md +143 -0
  173. package/docs/specs/multi_model_routing_featureai.md +687 -0
  174. package/docs/specs/multi_model_routing_superplan.md +197 -0
  175. package/docs/specs/opus_47_existing_enhancements_featureai.md +247 -0
  176. package/docs/specs/opus_47_extended_features_featureai.md +363 -0
  177. package/docs/specs/opus_47_extended_features_v2_featureai.md +397 -0
  178. package/docs/specs/pan_focus_commands_featureai.md +2336 -0
  179. package/docs/specs/pan_zcode_mcp_bridge_featureai.md +120 -0
  180. package/docs/specs/product-excellence-superplan.md +315 -0
  181. package/docs/specs/product_excellence_program_2026_q4_featureai.md +365 -0
  182. package/docs/specs/production_deployment_readiness_featureai.md +433 -0
  183. package/docs/specs/production_readiness_ship_v1_featureai.md +698 -0
  184. package/docs/specs/real_test_enforcement_featureai.md +213 -0
  185. package/docs/specs/reality-check-2026-09-superplan.md +362 -0
  186. package/docs/specs/right-sized-ceremony.md +74 -0
  187. package/docs/specs/roadmap_and_competition_2026_q4_featureai.md +390 -0
  188. package/docs/specs/self_improvement_loop_featureai.md +875 -0
  189. package/docs/specs/skill-aligned-decomposition.md +155 -0
  190. package/docs/specs/standards_integration_featureai.md +833 -0
  191. package/docs/specs/testing-system-redesign-2026-09.md +267 -0
  192. package/docs/specs/user_reality_testing_system_featureai.md +788 -0
  193. package/docs/specs/watch-triggers.json +22 -0
  194. package/docs/specs/workflow-integration-redesign.md +742 -0
  195. package/docs/specs/workflow_state_consistency_featureai.md +183 -0
  196. package/hooks/dist/pan-context-monitor.js +9 -2
  197. package/hooks/dist/pan-cost-logger.js +5 -0
  198. package/hooks/dist/pan-guard.js +28 -5
  199. package/hooks/dist/pan-stop-guard.js +9 -9
  200. package/hooks/dist/pan-trace-logger.js +5 -0
  201. package/package.json +10 -2
  202. package/pan-wizard-core/bin/lib/agents-md.cjs +57 -8
  203. package/pan-wizard-core/bin/lib/autodev-report.cjs +180 -0
  204. package/pan-wizard-core/bin/lib/autodev.cjs +642 -0
  205. package/pan-wizard-core/bin/lib/ci.cjs +143 -0
  206. package/pan-wizard-core/bin/lib/commands.cjs +1 -1
  207. package/pan-wizard-core/bin/lib/config.cjs +41 -5
  208. package/pan-wizard-core/bin/lib/constants.cjs +27 -1
  209. package/pan-wizard-core/bin/lib/core.cjs +31 -14
  210. package/pan-wizard-core/bin/lib/cost.cjs +160 -4
  211. package/pan-wizard-core/bin/lib/cross-family.cjs +164 -0
  212. package/pan-wizard-core/bin/lib/debug-cases.cjs +104 -0
  213. package/pan-wizard-core/bin/lib/doc-lint.cjs +5 -3
  214. package/pan-wizard-core/bin/lib/failure-class.cjs +81 -0
  215. package/pan-wizard-core/bin/lib/findings.cjs +148 -9
  216. package/pan-wizard-core/bin/lib/focus.cjs +1 -1
  217. package/pan-wizard-core/bin/lib/git.cjs +1 -1
  218. package/pan-wizard-core/bin/lib/hosts.cjs +88 -0
  219. package/pan-wizard-core/bin/lib/init.cjs +7 -2
  220. package/pan-wizard-core/bin/lib/knowledge.cjs +2 -0
  221. package/pan-wizard-core/bin/lib/merge.cjs +50 -0
  222. package/pan-wizard-core/bin/lib/mutate.cjs +268 -0
  223. package/pan-wizard-core/bin/lib/next-action.cjs +112 -0
  224. package/pan-wizard-core/bin/lib/optimize.cjs +2 -2
  225. package/pan-wizard-core/bin/lib/phase-gate.cjs +15 -9
  226. package/pan-wizard-core/bin/lib/phase-remove.cjs +91 -11
  227. package/pan-wizard-core/bin/lib/phase.cjs +85 -13
  228. package/pan-wizard-core/bin/lib/plan-lint.cjs +310 -0
  229. package/pan-wizard-core/bin/lib/preview.cjs +26 -4
  230. package/pan-wizard-core/bin/lib/requirements-lint.cjs +130 -0
  231. package/pan-wizard-core/bin/lib/research-lint.cjs +268 -0
  232. package/pan-wizard-core/bin/lib/review-deep.cjs +14 -22
  233. package/pan-wizard-core/bin/lib/review-vote.cjs +105 -0
  234. package/pan-wizard-core/bin/lib/roadmap.cjs +1 -0
  235. package/pan-wizard-core/bin/lib/runner.cjs +2 -16
  236. package/pan-wizard-core/bin/lib/sizing.cjs +356 -0
  237. package/pan-wizard-core/bin/lib/squads.cjs +1 -1
  238. package/pan-wizard-core/bin/lib/state-write.cjs +247 -0
  239. package/pan-wizard-core/bin/lib/test-gate.cjs +433 -0
  240. package/pan-wizard-core/bin/lib/uat.cjs +149 -0
  241. package/pan-wizard-core/bin/lib/usage.cjs +104 -0
  242. package/pan-wizard-core/bin/lib/verdict.cjs +26 -3
  243. package/pan-wizard-core/bin/lib/verify-plan-set.cjs +30 -1
  244. package/pan-wizard-core/bin/lib/verify-preflight.cjs +2 -2
  245. package/pan-wizard-core/bin/lib/verify-red.cjs +174 -0
  246. package/pan-wizard-core/bin/lib/verify-retro.cjs +3 -2
  247. package/pan-wizard-core/bin/lib/verify-scope.cjs +143 -2
  248. package/pan-wizard-core/bin/lib/verify.cjs +86 -31
  249. package/pan-wizard-core/bin/lib/worktree.cjs +70 -0
  250. package/pan-wizard-core/bin/pan-tools.cjs +257 -28
  251. package/pan-wizard-core/learnings/universal/autonomous-loop.md +2 -2
  252. package/pan-wizard-core/mcp/orchestrator.cjs +4 -1
  253. package/pan-wizard-core/references/continuation-format.md +3 -3
  254. package/pan-wizard-core/references/design-methodology.md +1 -1
  255. package/pan-wizard-core/references/guardrails.md +1 -1
  256. package/pan-wizard-core/references/handoff-decisions.md +1 -1
  257. package/pan-wizard-core/references/model-profiles.md +2 -3
  258. package/pan-wizard-core/references/questioning.md +24 -0
  259. package/pan-wizard-core/references/ui-brand.md +4 -6
  260. package/pan-wizard-core/references/verdict-contract.md +2 -1
  261. package/pan-wizard-core/templates/config.json +10 -2
  262. package/pan-wizard-core/templates/debug.md +1 -0
  263. package/pan-wizard-core/templates/design.md +5 -4
  264. package/pan-wizard-core/templates/discovery.md +2 -2
  265. package/pan-wizard-core/templates/phase-prompt.md +7 -0
  266. package/pan-wizard-core/templates/requirements.md +9 -0
  267. package/pan-wizard-core/templates/research.md +10 -0
  268. package/pan-wizard-core/templates/summary-complex.md +5 -1
  269. package/pan-wizard-core/templates/summary-minimal.md +4 -0
  270. package/pan-wizard-core/templates/summary-standard.md +5 -1
  271. package/pan-wizard-core/templates/summary.md +8 -1
  272. package/pan-wizard-core/workflows/add-phase.md +4 -6
  273. package/pan-wizard-core/workflows/assumptions.md +19 -1
  274. package/pan-wizard-core/workflows/diagnose-issues.md +2 -0
  275. package/pan-wizard-core/workflows/discuss-phase.md +4 -2
  276. package/pan-wizard-core/workflows/exec-lean.md +69 -0
  277. package/pan-wizard-core/workflows/exec-phase.md +79 -15
  278. package/pan-wizard-core/workflows/execute-plan.md +3 -1
  279. package/{commands/pan → pan-wizard-core/workflows}/focus-doc-audit.md +13 -29
  280. package/{commands/pan → pan-wizard-core/workflows}/focus-drift-walking.md +3 -18
  281. package/{commands/pan → pan-wizard-core/workflows}/focus-exec.md +8 -23
  282. package/{commands/pan → pan-wizard-core/workflows}/focus-plan.md +6 -20
  283. package/{commands/pan → pan-wizard-core/workflows}/focus-scan.md +3 -16
  284. package/{commands/pan → pan-wizard-core/workflows}/focus-sync.md +7 -21
  285. package/pan-wizard-core/workflows/health.md +6 -0
  286. package/pan-wizard-core/workflows/help.md +114 -77
  287. package/pan-wizard-core/workflows/insert-phase.md +4 -6
  288. package/pan-wizard-core/workflows/learn.md +3 -3
  289. package/pan-wizard-core/workflows/milestone-audit.md +2 -2
  290. package/pan-wizard-core/workflows/milestone-new.md +38 -95
  291. package/pan-wizard-core/workflows/new-project.md +96 -258
  292. package/pan-wizard-core/workflows/optimize.md +107 -5
  293. package/pan-wizard-core/workflows/phase-tests.md +10 -0
  294. package/pan-wizard-core/workflows/plan-phase.md +106 -45
  295. package/pan-wizard-core/workflows/profile.md +50 -0
  296. package/pan-wizard-core/workflows/progress.md +10 -0
  297. package/pan-wizard-core/workflows/quick.md +34 -43
  298. package/pan-wizard-core/workflows/remove-phase.md +11 -1
  299. package/pan-wizard-core/workflows/research-phase.md +118 -40
  300. package/pan-wizard-core/workflows/resume-project.md +18 -2
  301. package/pan-wizard-core/workflows/settings.md +33 -19
  302. package/pan-wizard-core/workflows/todo-check.md +6 -2
  303. package/pan-wizard-core/workflows/transition.md +22 -4
  304. package/pan-wizard-core/workflows/uat-walkthrough.md +90 -0
  305. package/pan-wizard-core/workflows/update.md +1 -1
  306. package/pan-wizard-core/workflows/verify-phase.md +39 -46
  307. package/scripts/build-agent-plugin.js +35 -15
  308. package/scripts/build-help.cjs +106 -0
  309. package/scripts/build-plugin.js +10 -1
  310. package/scripts/deprecate-old-versions.js +70 -3
  311. package/scripts/generate-skills-docs.py +1 -1
  312. package/scripts/git-hooks/pre-push +27 -0
  313. package/scripts/install-git-hooks.js +7 -5
  314. package/scripts/install-pre-push.cjs +38 -0
  315. package/scripts/land.cjs +151 -0
  316. package/scripts/local-ci.cjs +501 -0
  317. package/scripts/local-schedule.cjs +277 -0
  318. package/scripts/mutation-probe.cjs +7 -80
  319. package/scripts/prompt-lint.cjs +32 -0
  320. package/scripts/prompt-rules.cjs +156 -0
  321. package/scripts/run-tests.cjs +7 -1
  322. package/scripts/test-quality-lint.cjs +3 -3
  323. package/scripts/test-surface.cjs +175 -6
  324. package/agents/pan-research-synthesizer.md +0 -246
  325. package/commands/pan/audit-deployment.md +0 -386
  326. package/commands/pan/dashboard.md +0 -22
  327. package/commands/pan/discord.md +0 -19
  328. package/commands/pan/mcp-bridge.md +0 -143
  329. package/commands/pan/milestone-cleanup.md +0 -19
  330. package/commands/pan/milestone-gaps.md +0 -35
  331. package/commands/pan/optimize.md +0 -115
  332. package/commands/pan/profile.md +0 -76
  333. package/commands/pan/research-phase.md +0 -189
  334. package/pan-wizard-core/bin/lib/bridge.cjs +0 -269
  335. package/pan-wizard-core/templates/research-project/architecture.md +0 -204
  336. package/pan-wizard-core/templates/research-project/features.md +0 -147
  337. package/pan-wizard-core/templates/research-project/pitfalls.md +0 -200
  338. package/pan-wizard-core/templates/research-project/stack.md +0 -120
  339. package/pan-wizard-core/templates/research-project/summary.md +0 -170
@@ -0,0 +1,449 @@
1
+ # Feature Spec: `optimize` Category for focus-auto
2
+
3
+ **featureAI output** · Status: DESIGN · Date: 2026-03-18
4
+
5
+ ---
6
+
7
+ ## Phase 0: Problem Framing
8
+
9
+ ### 0.1 Problem Statement
10
+
11
+ PAN Wizard's focus-auto currently covers five categories (cleanup, tests, stability, features, docs) but lacks a dedicated category for **code performance and robustness optimization**. Users who want to systematically improve runtime performance, reduce memory allocations, simplify hot paths, or tighten error handling across a codebase must manually hunt for opportunities or misuse the `cleanup` or `stability` categories, which have different scanning heuristics and priority ranges. A purpose-built `optimize` category would provide targeted scan patterns for performance and robustness issues, and — critically — operate in a **convergent loop** where each cycle re-scans to discover new optimization opportunities revealed by previous changes, stopping only when measurable improvement plateaus.
12
+
13
+ ### 0.2 Scope
14
+
15
+ | In Scope | Out of Scope |
16
+ |----------|-------------|
17
+ | New `optimize` entry in FOCUS_CATEGORIES | Runtime/language-specific profilers |
18
+ | Priority range, default mode, default budget | Benchmark harness infrastructure |
19
+ | Optimization-specific scan heuristics | Breaking API changes for performance |
20
+ | Convergent-loop stop condition (diminishing returns) | Auto-parallelization or concurrency rewrites |
21
+ | Scan pattern catalog for common perf/robustness issues | External dependency upgrades |
22
+ | `optimize` support in all 5 runtimes (command is runtime-agnostic) | GPU/WASM-specific optimizations |
23
+
24
+ ### 0.3 Success Criteria
25
+
26
+ ```
27
+ SC-1: `optimize` is a valid --category value for focus-auto across all 5 runtimes
28
+ SC-2: Existing FOCUS_CATEGORIES consumers (categoryFilter, focusAutoInit, constants) handle `optimize` without regression
29
+ SC-3: Scan step detects ≥8 distinct optimization pattern types
30
+ SC-4: Convergent-loop logic stops when cycle-over-cycle improvement delta < threshold
31
+ SC-5: Unit tests cover: category validation, priority filtering, defaults, diminishing-returns stop condition
32
+ SC-6: Documentation updated (CLI-REFERENCE, focus-auto.md, model-profiles.md category table)
33
+ SC-7: All existing 1649+ tests continue to pass
34
+ ```
35
+
36
+ ### 0.4 User Stories
37
+
38
+ ```
39
+ As a PAN Wizard user, I want to run `pan:focus-auto --category optimize`
40
+ so that my codebase is systematically scanned for performance and robustness
41
+ improvements in iterative cycles, instead of manually grepping for N+1 loops
42
+ and unguarded operations one file at a time.
43
+
44
+ As a PAN Wizard user, I want the optimize campaign to automatically stop
45
+ when further cycles yield diminishing returns, so that I don't waste budget
46
+ on micro-optimizations after the major gains have been captured.
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Phase 1: Internal Reconnaissance
52
+
53
+ ### 1.1 Existing Infrastructure
54
+
55
+ | Component | File | What it does |
56
+ |-----------|------|-------------|
57
+ | FOCUS_CATEGORIES | `constants.cjs:126` | Array of valid category names — **add `optimize` here** |
58
+ | CATEGORY_PRIORITY_RANGE | `constants.cjs:129-135` | Maps category → `{ min, max }` priority indices |
59
+ | CATEGORY_DEFAULTS | `constants.cjs:138-144` | Maps category → `{ mode, budget }` |
60
+ | categoryFilter() | `focus.cjs:~640` | Filters work items by category's priority range |
61
+ | focusAutoInit() | `focus.cjs:~830` | Validates category, reads defaults, creates run state |
62
+ | cmdFocusAuto() | `focus.cjs:~880` | Dispatcher: init/status/stop/update/continue |
63
+ | determineStopReason() | `focus.cjs:~790` | Checks regression/budget/max_cycles/zero_completed |
64
+ | focus-auto.md | `commands/pan/focus-auto.md` | Command definition with scan heuristics per category |
65
+ | focus.test.cjs | `tests/focus.test.cjs` | Unit tests for all focus module exports |
66
+
67
+ ### 1.2 Category Wiring Path
68
+
69
+ Adding a new category requires touching these locations:
70
+
71
+ 1. **`constants.cjs`** — Add `'optimize'` to `FOCUS_CATEGORIES` array
72
+ 2. **`constants.cjs`** — Add `optimize` entry to `CATEGORY_PRIORITY_RANGE`
73
+ 3. **`constants.cjs`** — Add `optimize` entry to `CATEGORY_DEFAULTS`
74
+ 4. **`focus.cjs`** — `determineStopReason()` — add diminishing-returns check
75
+ 5. **`focus-auto.md`** — Add optimize to category menu, scan heuristics, category defaults table
76
+ 6. **`focus.test.cjs`** — Tests for new category filtering, defaults, stop condition
77
+ 7. **Docs** — CLI-REFERENCE.md, USER-GUIDE.md updates
78
+
79
+ ### 1.3 Runtime Compatibility
80
+
81
+ The focus system is **runtime-agnostic**. Categories are string constants consumed by `pan-tools` (CommonJS) and command `.md` files. No runtime-specific handling needed — `optimize` works identically across Claude, Codex, Gemini, OpenCode, and GitHub Copilot.
82
+
83
+ ---
84
+
85
+ ## Phase 2: Competitive Analysis
86
+
87
+ | Tool | Optimization Approach | Strengths | Gaps |
88
+ |------|----------------------|-----------|------|
89
+ | **SonarQube** | Cognitive complexity, code smells, performance hotspots | Deep static analysis, historical trends | No automated fixing, no iterative loop |
90
+ | **ESLint perf rules** | `no-loop-func`, `no-await-in-loop`, `prefer-const` | Fast, integrated in CI | Limited to style rules, no semantic analysis |
91
+ | **Deepsource** | Anti-patterns, algorithmic issues | Multi-language, auto-fix suggestions | Per-file, not project-wide campaigns |
92
+ | **Sourcery (Python)** | Refactor suggestions, complexity reduction | AI-powered, shows before/after | Python-only, no iterative convergence |
93
+ | **Cursor / Copilot refactor** | Single-shot refactoring on selection | Contextual, good for spot fixes | No campaign orchestration, no tracking |
94
+
95
+ **Differentiation opportunity:** None of these tools offer a **convergent iterative loop** — scan, fix, re-scan, fix again — with automatic diminishing-returns detection. PAN Wizard's `optimize` category would be the first to combine project-wide scan heuristics with a tracked budget-limited convergence loop that discovers cascading optimization opportunities.
96
+
97
+ ---
98
+
99
+ ## Phase 3: Design
100
+
101
+ ### 3.1 Category Parameters
102
+
103
+ ```
104
+ Name: optimize
105
+ Priority Range: P1-P4 (min: 1, max: 4)
106
+ Default Mode: balanced
107
+ Default Budget: 50 points per cycle
108
+ ```
109
+
110
+ **Rationale for P1-P4:**
111
+ - P1: Algorithmic disasters (O(n³) where O(n) is possible, unbounded recursion)
112
+ - P2: Significant inefficiencies (N+1 operations, synchronous blocking in async paths, repeated full-collection scans)
113
+ - P3: Moderate improvements (unnecessary allocations, redundant computations, suboptimal data structures)
114
+ - P4: Polish (micro-optimizations, const correctness, minor code tightening)
115
+ - Excludes P0 (those are crashes — `stability` handles them) and P5-P6 (those are tooling/docs)
116
+
117
+ ### 3.2 Optimization Scan Heuristics
118
+
119
+ The `focus-auto.md` command already defines scan heuristics per category in Step 2.1.2. The `optimize` category adds:
120
+
121
+ | ID | Pattern | What to grep/analyze | Priority | Effort |
122
+ |----|---------|---------------------|----------|--------|
123
+ | OPT-01 | **N+1 operations** | Loop containing file I/O, DB query, or network call; `readFileSync`/`readdirSync` inside `for`/`forEach`/`map` | P2 | S-M |
124
+ | OPT-02 | **Redundant re-computation** | Same function called with identical args in the same scope; repeated `JSON.parse`/`JSON.stringify` of the same data | P3 | XS-S |
125
+ | OPT-03 | **Synchronous blocking in async paths** | `readFileSync`/`execSync` in modules that also export async functions | P2 | M |
126
+ | OPT-04 | **Algorithmic complexity** | Nested loops over the same collection (O(n²)+); `.find()` or `.filter()` inside `.map()` or `.forEach()` | P1 | M-L |
127
+ | OPT-05 | **Unnecessary allocations** | Array spread `[...arr]` or `Object.assign({}, obj)` in hot loops; string concatenation in loops instead of `join()` | P3 | XS-S |
128
+ | OPT-06 | **Missing early returns** | Deep nesting (4+ levels) that could be flattened with guard clauses | P4 | XS-S |
129
+ | OPT-07 | **Regex in hot paths** | `new RegExp()` construction inside loops (should be hoisted); repeated `.match()`/`.test()` with the same pattern | P3 | XS |
130
+ | OPT-08 | **Unbounded growth** | Arrays/objects that `.push()` in loops without size limits; `Map`/`Set` that grows without eviction | P2 | S-M |
131
+ | OPT-09 | **Error path robustness** | `catch` blocks that swallow errors silently (`catch {}`/`catch { /* */ }`); missing error propagation | P2 | S |
132
+ | OPT-10 | **Suboptimal data structures** | Repeated `.includes()` on arrays (should be Set); repeated object key lookup patterns that would benefit from Map | P3 | S |
133
+ | OPT-11 | **Dead assignments** | Variables assigned but never read before reassignment or scope exit | P4 | XS |
134
+ | OPT-12 | **Unguarded `.length`/property access** | Accessing `.length`, `.split()`, `.match()[0]` on potentially null/undefined values without null check | P2 | XS-S |
135
+
136
+ ### 3.3 Convergent Loop: Diminishing Returns Detection
137
+
138
+ This is the key differentiator for `optimize`. The existing stop conditions in `determineStopReason()` are:
139
+
140
+ ```
141
+ regression → tests_after < tests_before (immediate stop)
142
+ budget_cap → totals.points_used >= total_budget (stop)
143
+ max_cycles → totals.cycles_completed >= max (stop)
144
+ zero_completed → items_completed === 0 (stop)
145
+ ```
146
+
147
+ **New stop condition: `diminishing_returns`**
148
+
149
+ After each cycle, the auto-runner already records `items_completed` and `points_used`. Define a new metric:
150
+
151
+ ```
152
+ cycle_efficiency = items_completed / points_used
153
+ ```
154
+
155
+ The diminishing-returns check compares the current cycle's efficiency to the previous cycle's:
156
+
157
+ ```
158
+ if (run.cycles.length >= 2) {
159
+ const prev = run.cycles[run.cycles.length - 2];
160
+ const curr = cycle;
161
+ const prevEff = prev.items_completed / (prev.points_used || 1);
162
+ const currEff = curr.items_completed / (curr.points_used || 1);
163
+ if (currEff < prevEff * DIMINISHING_RETURNS_THRESHOLD) {
164
+ return 'diminishing_returns';
165
+ }
166
+ }
167
+ ```
168
+
169
+ **`DIMINISHING_RETURNS_THRESHOLD = 0.3`** — If current cycle efficiency drops below 30% of the previous cycle's, optimization has plateaued. This threshold is aggressive enough to stop wasting budget on micro-gains, but lenient enough to allow 2-3 productive cycles before triggering.
170
+
171
+ **This condition only activates for the `optimize` category.** Other categories use the existing stop conditions only. The check is gated on `run.category === 'optimize'` in `determineStopReason()`.
172
+
173
+ ### 3.4 Circular Re-scan Strategy
174
+
175
+ Standard categories scan once per cycle and may find overlapping items. For `optimize`:
176
+
177
+ 1. **Cycle 1:** Full scan — find all optimization opportunities, prioritize by impact
178
+ 2. **Cycle 2+:** Re-scan from scratch — previous fixes may expose new patterns:
179
+ - Extracting a hot function reveals it's called in a tight loop → OPT-04
180
+ - Removing a redundant parse reveals the remaining one can be cached → OPT-02
181
+ - Flattening nesting reveals a dead assignment → OPT-11
182
+ 3. **Deduplication:** Cross-reference new scan against `cycles[].items` from previous cycles. Skip items with the same `id` that were previously completed or failed. Only pick genuinely new findings.
183
+ 4. **Convergence signal:** When re-scan finds fewer new items than the previous cycle AND efficiency drops below threshold → stop
184
+
185
+ This creates the "circular optimization" the user described: fix → re-scan → discover cascading opportunities → fix → re-scan → until plateau.
186
+
187
+ ### 3.5 Architecture Decision
188
+
189
+ ```
190
+ Modified files:
191
+ pan-wizard-core/bin/lib/constants.cjs — 3 additions (array + 2 objects)
192
+ pan-wizard-core/bin/lib/focus.cjs — ~15 lines (determineStopReason update)
193
+ commands/pan/focus-auto.md — ~30 lines (menu item, scan heuristics, defaults row)
194
+ tests/focus.test.cjs — ~40 lines (new tests)
195
+ docs/CLI-REFERENCE.md — Category table update
196
+ docs/USER-GUIDE.md — Mention in focus section
197
+
198
+ New constants:
199
+ DIMINISHING_RETURNS_THRESHOLD = 0.3 — in constants.cjs
200
+
201
+ No new files needed. No installer changes. No manifest changes.
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Phase 4: Specification
207
+
208
+ ### Files to Modify
209
+
210
+ #### 1. `pan-wizard-core/bin/lib/constants.cjs`
211
+
212
+ **A. Add to FOCUS_CATEGORIES array (line 126):**
213
+ ```js
214
+ const FOCUS_CATEGORIES = ['cleanup', 'tests', 'stability', 'features', 'docs', 'optimize'];
215
+ ```
216
+
217
+ **B. Add to CATEGORY_PRIORITY_RANGE (after line 135):**
218
+ ```js
219
+ optimize: { min: 1, max: 4 }, // P1-P4
220
+ ```
221
+
222
+ **C. Add to CATEGORY_DEFAULTS (after line 144):**
223
+ ```js
224
+ optimize: { mode: 'balanced', budget: 50 },
225
+ ```
226
+
227
+ **D. Add new constant (near other focus constants, ~line 500):**
228
+ ```js
229
+ /** Efficiency drop threshold for optimize category diminishing-returns stop */
230
+ const DIMINISHING_RETURNS_THRESHOLD = 0.3;
231
+ ```
232
+
233
+ **E. Export the new constant** in the module.exports block.
234
+
235
+ #### 2. `pan-wizard-core/bin/lib/focus.cjs`
236
+
237
+ **Update `determineStopReason()`** to add diminishing-returns check:
238
+
239
+ ```js
240
+ function determineStopReason(cycle, run) {
241
+ if (cycle.tests_after < cycle.tests_before) return 'regression';
242
+ if (run.totals.points_used >= run.total_budget) return 'budget_cap';
243
+ if (run.totals.cycles_completed >= run.max_cycles) return 'max_cycles';
244
+ if (cycle.items_completed === 0) return 'zero_completed';
245
+
246
+ // Optimize category: stop when efficiency drops below threshold
247
+ if (run.category === 'optimize' && run.cycles.length >= 2) {
248
+ const prev = run.cycles[run.cycles.length - 2];
249
+ const prevEff = prev.items_completed / (prev.points_used || 1);
250
+ const currEff = cycle.items_completed / (cycle.points_used || 1);
251
+ if (currEff > 0 && currEff < prevEff * DIMINISHING_RETURNS_THRESHOLD) {
252
+ return 'diminishing_returns';
253
+ }
254
+ }
255
+
256
+ return null;
257
+ }
258
+ ```
259
+
260
+ **Note:** Import `DIMINISHING_RETURNS_THRESHOLD` from constants.cjs.
261
+
262
+ #### 3. `commands/pan/focus-auto.md`
263
+
264
+ **A. Add to category menu (FIRST ACTION section):**
265
+ ```
266
+ 6. **optimize** — Performance bottlenecks, redundant computation, robustness hardening (P1-P4)
267
+ ```
268
+ Update: "Reply with a number (1-6) or category name."
269
+
270
+ Add mapping: `"6" or "optimize" → SELECTED_CATEGORY = optimize`
271
+
272
+ **B. Add to Category Defaults table:**
273
+ ```
274
+ | optimize | P1-P4 | balanced | 50 |
275
+ ```
276
+
277
+ **C. Add scan heuristics to Step 2.1.2:**
278
+ ```markdown
279
+ - **optimize:** N+1 operations (file I/O / network calls inside loops), redundant
280
+ re-computation (`JSON.parse`/`stringify` of same data), synchronous blocking in
281
+ async modules, algorithmic complexity (nested `.find()`/`.filter()` in loops),
282
+ unnecessary allocations in hot paths (spread in loops, string concat vs join),
283
+ regex construction inside loops, unbounded collection growth, swallowed errors
284
+ (`catch {}`), suboptimal data structures (array `.includes()` → Set), dead
285
+ assignments, unguarded property access on nullable values
286
+ ```
287
+
288
+ **D. Add convergence note to Step 2.1 (optimize-specific):**
289
+ ```markdown
290
+ **Optimize category: convergent re-scan.** On cycles 2+, cross-reference scan
291
+ findings against previous cycle completions. Only pick genuinely new items. If
292
+ the count of new findings drops below the previous cycle's AND efficiency drops
293
+ below 30% of the prior cycle, this signals convergence.
294
+ ```
295
+
296
+ **E. Add to Phase 3 stop reason table:**
297
+ ```
298
+ | `diminishing_returns` | Optimize only — cycle efficiency < 30% of previous cycle |
299
+ ```
300
+
301
+ #### 4. `tests/focus.test.cjs`
302
+
303
+ Add the following test cases:
304
+
305
+ ```js
306
+ describe('categoryFilter — optimize', () => {
307
+ test('includes P1-P4 items for optimize category', () => {
308
+ const items = [
309
+ { priority: 'P0' }, { priority: 'P1' }, { priority: 'P2' },
310
+ { priority: 'P3' }, { priority: 'P4' }, { priority: 'P5' }, { priority: 'P6' },
311
+ ];
312
+ const result = categoryFilter(items, 'optimize');
313
+ assert.equal(result.length, 4);
314
+ assert.deepEqual(result.map(i => i.priority), ['P1', 'P2', 'P3', 'P4']);
315
+ });
316
+ });
317
+
318
+ describe('CATEGORY_DEFAULTS — optimize', () => {
319
+ test('optimize has balanced mode and 50 budget', () => {
320
+ assert.equal(CATEGORY_DEFAULTS.optimize.mode, 'balanced');
321
+ assert.equal(CATEGORY_DEFAULTS.optimize.budget, 50);
322
+ });
323
+ });
324
+
325
+ describe('CATEGORY_PRIORITY_RANGE — optimize', () => {
326
+ test('optimize range is P1-P4 (indices 1-4)', () => {
327
+ assert.equal(CATEGORY_PRIORITY_RANGE.optimize.min, 1);
328
+ assert.equal(CATEGORY_PRIORITY_RANGE.optimize.max, 4);
329
+ });
330
+ });
331
+
332
+ describe('FOCUS_CATEGORIES includes optimize', () => {
333
+ test('optimize is a valid category', () => {
334
+ assert.ok(FOCUS_CATEGORIES.includes('optimize'));
335
+ });
336
+ });
337
+
338
+ describe('determineStopReason — diminishing returns', () => {
339
+ // (test the updated determineStopReason with optimize category + cycles data)
340
+ test('returns diminishing_returns when efficiency drops below 30%', () => {
341
+ const cycle = { items_completed: 1, points_used: 10, tests_before: 100, tests_after: 101 };
342
+ const run = {
343
+ category: 'optimize',
344
+ total_budget: 500,
345
+ max_cycles: 10,
346
+ totals: { cycles_completed: 2, points_used: 60 },
347
+ cycles: [
348
+ { items_completed: 5, points_used: 10 }, // prev efficiency: 0.5
349
+ cycle, // curr efficiency: 0.1 (< 0.5 * 0.3 = 0.15)
350
+ ],
351
+ };
352
+ // This test will validate the function returns 'diminishing_returns'
353
+ });
354
+
355
+ test('does not trigger diminishing_returns for non-optimize categories', () => {
356
+ const cycle = { items_completed: 1, points_used: 10, tests_before: 100, tests_after: 101 };
357
+ const run = {
358
+ category: 'cleanup',
359
+ total_budget: 500, max_cycles: 10,
360
+ totals: { cycles_completed: 2, points_used: 60 },
361
+ cycles: [
362
+ { items_completed: 5, points_used: 10 },
363
+ cycle,
364
+ ],
365
+ };
366
+ // Should return null, not 'diminishing_returns'
367
+ });
368
+
369
+ test('does not trigger on first cycle (no previous to compare)', () => {
370
+ const cycle = { items_completed: 1, points_used: 10, tests_before: 100, tests_after: 101 };
371
+ const run = {
372
+ category: 'optimize',
373
+ total_budget: 500, max_cycles: 10,
374
+ totals: { cycles_completed: 1, points_used: 10 },
375
+ cycles: [cycle],
376
+ };
377
+ // Should return null — needs 2+ cycles
378
+ });
379
+ });
380
+
381
+ describe('focusAutoInit — optimize category', () => {
382
+ test('accepts optimize as valid category via CLI', () => {
383
+ // Integration: runPanTools(tmpDir, 'focus', 'auto', '--category', 'optimize', '--dry-run')
384
+ // Verify output contains category: 'optimize', mode: 'balanced', budget: 50
385
+ });
386
+ });
387
+ ```
388
+
389
+ **Estimated: ~10 new test cases across 6 describe blocks.**
390
+
391
+ #### 5. Documentation
392
+
393
+ **`docs/CLI-REFERENCE.md`** — Add `optimize` row to focus-auto category table.
394
+
395
+ **`docs/USER-GUIDE.md`** — Mention optimize category in the focus-auto section.
396
+
397
+ ### Implementation Steps
398
+
399
+ ```
400
+ Step 1: constants.cjs — Add 'optimize' to FOCUS_CATEGORIES, CATEGORY_PRIORITY_RANGE,
401
+ CATEGORY_DEFAULTS, and add DIMINISHING_RETURNS_THRESHOLD constant + export
402
+ Step 2: focus.cjs — Import new constant, update determineStopReason() with
403
+ diminishing-returns check gated on category === 'optimize'
404
+ Step 3: focus-auto.md — Add category 6 to menu, defaults table row, scan heuristics,
405
+ convergent re-scan note, stop reason row
406
+ Step 4: focus.test.cjs — Add ~10 tests for category filtering, defaults, priority range,
407
+ diminishing-returns logic, CLI integration
408
+ Step 5: docs/ — Update CLI-REFERENCE.md and USER-GUIDE.md
409
+ Step 6: Run full test suite — verify 0 regressions
410
+ ```
411
+
412
+ ### Runtime Matrix
413
+
414
+ | Runtime | Supported | Notes |
415
+ |---------|-----------|-------|
416
+ | Claude | ✅ | focus-auto.md is runtime-agnostic |
417
+ | Codex | ✅ | Same command file, same constants |
418
+ | Gemini | ✅ | Same command file, same constants |
419
+ | OpenCode | ✅ | Same command file, same constants |
420
+ | GitHub | ✅ | Same command file, same constants |
421
+
422
+ ---
423
+
424
+ ## Phase 5: Risk Assessment
425
+
426
+ | Risk | Impact | Likelihood | Mitigation |
427
+ |------|--------|------------|------------|
428
+ | Existing tests referencing FOCUS_CATEGORIES.length | Medium | Medium | Search for `.length` assertions on FOCUS_CATEGORIES before implementing; update any hardcoded count |
429
+ | Diminishing-returns fires too early (false positive) | Medium | Low | Threshold 0.3 is conservative; only fires after 2+ cycles; only for `optimize` category |
430
+ | Diminishing-returns never fires (false negative) | Low | Low | Existing max_cycles and budget_cap still provide hard stops |
431
+ | Scan heuristics too aggressive (false positives in scan) | Medium | Medium | Heuristics are guidance for the LLM scan step, not automated grep rules — the agent applies judgment |
432
+ | `optimize` overlaps with `cleanup` category | Low | Medium | Priority ranges don't overlap (cleanup: P3-P5 vs optimize: P1-P4); scan heuristics are distinct (cleanup = dead code/imports vs optimize = perf/robustness) |
433
+ | `determineStopReason` order matters — diminishing_returns checked after zero_completed | Low | Low | If items_completed === 0, `zero_completed` fires first (correct: no items means can't compute efficiency) |
434
+ | Breaking change if consumers iterate FOCUS_CATEGORIES with index assumptions | Low | Very Low | FOCUS_CATEGORIES is always consumed by `.includes()` or `.forEach()`, never by index |
435
+
436
+ ### Backward Compatibility
437
+
438
+ - **No breaking changes.** Adding a 6th category to the array is purely additive.
439
+ - Existing campaigns using cleanup/tests/stability/features/docs are unaffected.
440
+ - `determineStopReason` changes are gated on `run.category === 'optimize'` — zero impact on other categories.
441
+ - The new `DIMINISHING_RETURNS_THRESHOLD` constant is only referenced from the one gated code path.
442
+
443
+ ### Estimated Effort
444
+
445
+ - **Constants + focus module:** ~25 lines of code changes
446
+ - **Command .md:** ~30 lines of additions
447
+ - **Tests:** ~80 lines of new tests
448
+ - **Docs:** ~10 lines of table updates
449
+ - **Total: ~145 lines, Size S-M**
@@ -0,0 +1,188 @@
1
+ # PAN Wizard Work Plan — focus-auto `optimize` Category
2
+
3
+ **Generated:** 2026-03-18 · **Source spec:** `docs/specs/focus-auto-optimize-category.md`
4
+
5
+ ---
6
+
7
+ ## Baseline
8
+
9
+ | Metric | Value |
10
+ |--------|-------|
11
+ | Version | 2.8.0 |
12
+ | Tests passing | 1649/1649 |
13
+ | Test files | 46 unit + 25 scenario = 71 |
14
+ | Commands shipped | 40 |
15
+ | Agents shipped | 12 |
16
+ | Core modules | 16 |
17
+ | Focus tests | 128 (37 suites) |
18
+ | Open TODOs in affected files | 0 |
19
+ | Focus categories | 5 (cleanup, tests, stability, features, docs) |
20
+
21
+ ---
22
+
23
+ ## Items
24
+
25
+ | ID | Priority | Size | Title | Files | Status |
26
+ |----|----------|------|-------|-------|--------|
27
+ | 1 | P0 | XS | Add `'optimize'` to FOCUS_CATEGORIES array | `constants.cjs:126` | Remaining |
28
+ | 2 | P0 | XS | Add `optimize` entry to CATEGORY_PRIORITY_RANGE | `constants.cjs:129-135` | Remaining |
29
+ | 3 | P0 | XS | Add `optimize` entry to CATEGORY_DEFAULTS | `constants.cjs:138-144` | Remaining |
30
+ | 4 | P1 | XS | Add DIMINISHING_RETURNS_THRESHOLD constant | `constants.cjs:~502` | Remaining |
31
+ | 5 | P1 | XS | Export DIMINISHING_RETURNS_THRESHOLD | `constants.cjs:~640` (exports block) | Remaining |
32
+ | 6 | P1 | S | Import DIMINISHING_RETURNS_THRESHOLD in focus.cjs | `focus.cjs:14-20` (imports) | Remaining |
33
+ | 7 | P1 | S | Add diminishing-returns check to determineStopReason() | `focus.cjs:779-785` | Remaining |
34
+ | 8 | P1 | XS | Export determineStopReason from focus.cjs | `focus.cjs:862-885` (exports) | Remaining |
35
+ | 9 | P2 | XS | Update existing test: FOCUS_CATEGORIES count 5→6 | `focus.test.cjs:1125-1127` | Remaining |
36
+ | 10 | P2 | XS | Update existing test: FOCUS_CATEGORIES deepStrictEqual array | `focus.test.cjs:1127` | Remaining |
37
+ | 11 | P3 | S | Add test: categoryFilter includes P1-P4 for optimize | `focus.test.cjs` (new block) | Remaining |
38
+ | 12 | P3 | S | Add test: CATEGORY_DEFAULTS.optimize has balanced/50 | `focus.test.cjs` (new block) | Remaining |
39
+ | 13 | P3 | S | Add test: CATEGORY_PRIORITY_RANGE.optimize min=1, max=4 | `focus.test.cjs` (new block) | Remaining |
40
+ | 14 | P3 | S | Add test: diminishing_returns triggers when efficiency < 30% of prev | `focus.test.cjs` (new block) | Remaining |
41
+ | 15 | P3 | S | Add test: diminishing_returns does NOT trigger for non-optimize categories | `focus.test.cjs` (new block) | Remaining |
42
+ | 16 | P3 | XS | Add test: diminishing_returns does NOT trigger on first cycle | `focus.test.cjs` (new block) | Remaining |
43
+ | 17 | P3 | S | Add test: focusAutoInit accepts optimize via CLI --dry-run | `focus.test.cjs` (new block) | Remaining |
44
+ | 18 | P3 | XS | Add test: determineStopReason returns null when efficiency stays high | `focus.test.cjs` (new block) | Remaining |
45
+ | 19 | P5 | S | Add category 6 to focus-auto.md menu + mapping | `focus-auto.md:38-56` | Remaining |
46
+ | 20 | P5 | XS | Add optimize row to focus-auto.md Category Defaults table | `focus-auto.md:~88` | Remaining |
47
+ | 21 | P5 | M | Add optimize scan heuristics to focus-auto.md Step 2.1.2 | `focus-auto.md:~136-145` | Remaining |
48
+ | 22 | P5 | S | Add convergent re-scan note to focus-auto.md optimize section | `focus-auto.md:~150` | Remaining |
49
+ | 23 | P5 | XS | Add diminishing_returns to focus-auto.md stop reason list | `focus-auto.md:~240` | Remaining |
50
+ | 24 | P6 | XS | Update CLI-REFERENCE.md categories line | `CLI-REFERENCE.md:2210` | Remaining |
51
+ | 25 | P6 | XS | Add diminishing_returns stop condition to CLI-REFERENCE.md | `CLI-REFERENCE.md:~2222` | Remaining |
52
+ | 26 | P6 | XS | Update USER-GUIDE.md focus-auto categories mention | `USER-GUIDE.md:332,336` | Remaining |
53
+
54
+ ---
55
+
56
+ ## Points Summary
57
+
58
+ | Priority | Items | Points | Description |
59
+ |----------|-------|--------|-------------|
60
+ | P0 | 3 | 3 | Core constants — feature won't work without these |
61
+ | P1 | 5 | 7 | Convergent-loop logic — key differentiator |
62
+ | P2 | 2 | 2 | Fix breaking tests — must pass before merge |
63
+ | P3 | 8 | 13 | New tests — validate correctness |
64
+ | P5 | 5 | 9 | Command doc — user-facing behavior definition |
65
+ | P6 | 3 | 3 | Reference doc updates |
66
+ | **Total** | **26** | **37** | |
67
+
68
+ ---
69
+
70
+ ## Execution Sessions
71
+
72
+ ### Session 1: Core Infrastructure (P0 + P1 + P2) — 12 points
73
+
74
+ **Goal:** Make `optimize` a valid category with diminishing-returns logic, passing all tests.
75
+
76
+ | Order | ID | Title | Points |
77
+ |-------|-----|-------|--------|
78
+ | 1 | 1 | Add `'optimize'` to FOCUS_CATEGORIES | 1 |
79
+ | 2 | 2 | Add optimize to CATEGORY_PRIORITY_RANGE | 1 |
80
+ | 3 | 3 | Add optimize to CATEGORY_DEFAULTS | 1 |
81
+ | 4 | 4 | Add DIMINISHING_RETURNS_THRESHOLD constant | 1 |
82
+ | 5 | 5 | Export DIMINISHING_RETURNS_THRESHOLD | 1 |
83
+ | 6 | 6 | Import DIMINISHING_RETURNS_THRESHOLD in focus.cjs | 2 |
84
+ | 7 | 7 | Add diminishing-returns check to determineStopReason() | 2 |
85
+ | 8 | 8 | Export determineStopReason from focus.cjs | 1 |
86
+ | 9 | 9 | Fix test: FOCUS_CATEGORIES count 5→6 | 1 |
87
+ | 10 | 10 | Fix test: deepStrictEqual array includes optimize | 1 |
88
+
89
+ **Gate:** `npm test` — all 1649 tests pass (items 9-10 fix the 2 that would break).
90
+
91
+ **Files touched:** `constants.cjs`, `focus.cjs`, `focus.test.cjs`
92
+ **Commit:** `feat: add optimize category to focus-auto with diminishing-returns stop condition`
93
+
94
+ ### Session 2: Test Coverage (P3) — 13 points
95
+
96
+ **Goal:** Full test coverage for the new category and diminishing-returns logic.
97
+
98
+ | Order | ID | Title | Points |
99
+ |-------|-----|-------|--------|
100
+ | 1 | 11 | Test categoryFilter P1-P4 for optimize | 2 |
101
+ | 2 | 12 | Test CATEGORY_DEFAULTS.optimize | 2 |
102
+ | 3 | 13 | Test CATEGORY_PRIORITY_RANGE.optimize | 2 |
103
+ | 4 | 14 | Test diminishing_returns triggers at <30% efficiency | 2 |
104
+ | 5 | 15 | Test diminishing_returns skipped for non-optimize | 2 |
105
+ | 6 | 16 | Test diminishing_returns skipped on first cycle | 1 |
106
+ | 7 | 17 | Test focusAutoInit accepts optimize via CLI | 2 |
107
+ | 8 | 18 | Test determineStopReason null when efficiency high | 1 |
108
+
109
+ **Gate:** `npm test` — 1649 + 8 new = 1657 tests, 0 failures.
110
+
111
+ **Files touched:** `focus.test.cjs`
112
+ **Commit:** `test: add 8 tests for optimize category and diminishing-returns logic`
113
+
114
+ ### Session 3: Command Documentation (P5) — 9 points
115
+
116
+ **Goal:** User-facing focus-auto.md fully documents the optimize category.
117
+
118
+ | Order | ID | Title | Points |
119
+ |-------|-----|-------|--------|
120
+ | 1 | 19 | Add category 6 to interactive menu | 2 |
121
+ | 2 | 20 | Add optimize to Category Defaults table | 1 |
122
+ | 3 | 21 | Add optimize scan heuristics (12 pattern types) | 4 |
123
+ | 4 | 22 | Add convergent re-scan note | 2 |
124
+ | 5 | 23 | Add diminishing_returns to stop reason list | 1 |
125
+
126
+ **Gate:** Visual review — menu shows 6 categories, heuristics list is complete, table has 6 rows.
127
+
128
+ **Files touched:** `focus-auto.md`
129
+ **Commit:** `docs: add optimize category to focus-auto command with scan heuristics and convergence logic`
130
+
131
+ ### Session 4: Reference Documentation (P6) — 3 points
132
+
133
+ **Goal:** All reference docs reflect the new category.
134
+
135
+ | Order | ID | Title | Points |
136
+ |-------|-----|-------|--------|
137
+ | 1 | 24 | Update CLI-REFERENCE.md categories line | 1 |
138
+ | 2 | 25 | Add diminishing_returns to CLI-REFERENCE.md stop conditions | 1 |
139
+ | 3 | 26 | Update USER-GUIDE.md focus category list | 1 |
140
+
141
+ **Gate:** `npm run test:all` — full 1657+ tests pass. Grep for "5 categories" or "cleanup, tests, stability, features, docs" (without optimize) returns 0 stale references.
142
+
143
+ **Files touched:** `CLI-REFERENCE.md`, `USER-GUIDE.md`
144
+ **Commit:** `docs: update CLI reference and user guide with optimize category`
145
+
146
+ ---
147
+
148
+ ## Dependency Graph
149
+
150
+ ```
151
+ Session 1 (constants + focus.cjs + test fixes)
152
+ │
153
+ ├── Session 2 (new tests — depends on Session 1 exports)
154
+ │
155
+ └── Session 3 (command docs — independent of tests but needs category to exist)
156
+ │
157
+ └── Session 4 (ref docs — should match command doc)
158
+ ```
159
+
160
+ Sessions 2 and 3 can run in parallel after Session 1. Session 4 depends on Session 3 (content alignment).
161
+
162
+ ---
163
+
164
+ ## Risk Register
165
+
166
+ | Risk | Impact | Mitigation | Detected By |
167
+ |------|--------|------------|-------------|
168
+ | Test `FOCUS_CATEGORIES.length === 5` breaks | **Blocks merge** | Item 9 — update to 6 | `npm test` in Session 1 gate |
169
+ | Test `deepStrictEqual` array breaks | **Blocks merge** | Item 10 — add optimize to expected array | `npm test` in Session 1 gate |
170
+ | Other tests iterate FOCUS_CATEGORIES by index | Low | Grep confirmed: all uses are `.includes()` or `.forEach()`, never by index | Phase 0 scan |
171
+ | determineStopReason not exported (can't unit test) | Medium | Item 8 — export it | Session 2 import |
172
+ | Diminishing-returns threshold too aggressive | Medium (false stops) | 0.3 is conservative; existing max_cycles/budget_cap still provide hard stops | Integration testing |
173
+ | focus-auto.md menu numbering drift | Low | Item 19 explicitly updates to "1-6" | Visual review |
174
+ | CLAUDE.md test count goes stale | Low | Don't update CLAUDE.md until after final test run confirms count | Session 4 gate |
175
+
176
+ ---
177
+
178
+ ## Success Criteria Checklist
179
+
180
+ | SC | Criterion | Validated By |
181
+ |----|-----------|-------------|
182
+ | SC-1 | `optimize` is a valid --category | Session 1: focusAutoInit + Session 2: CLI test |
183
+ | SC-2 | No regression in existing consumers | Session 1 gate: 1649 tests pass |
184
+ | SC-3 | ≥8 scan pattern types documented | Session 3: 12 patterns in focus-auto.md |
185
+ | SC-4 | Convergent-loop stops on plateau | Session 2: diminishing_returns tests |
186
+ | SC-5 | Unit tests cover all new paths | Session 2: 8 new tests |
187
+ | SC-6 | Documentation updated | Session 3 + 4: focus-auto.md, CLI-REFERENCE, USER-GUIDE |
188
+ | SC-7 | All existing tests pass | Every session gate |