pan-wizard 3.36.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 (314) hide show
  1. package/CHANGELOG.md +3645 -0
  2. package/README.md +36 -48
  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 +1 -2
  8. package/agents/pan-document_code.md +1 -2
  9. package/agents/pan-hardener.md +2 -3
  10. package/agents/pan-integration-checker.md +1 -2
  11. package/agents/pan-knowledge.md +1 -2
  12. package/agents/pan-meta-reviewer.md +3 -3
  13. package/agents/pan-optimizer.md +4 -4
  14. package/agents/pan-phase-researcher.md +79 -488
  15. package/agents/pan-plan-checker.md +12 -2
  16. package/agents/pan-planner.md +10 -6
  17. package/agents/pan-previewer.md +1 -2
  18. package/agents/pan-project-researcher.md +70 -499
  19. package/agents/pan-release.md +1 -1
  20. package/agents/pan-reviewer.md +9 -3
  21. package/agents/pan-roadmapper.md +12 -7
  22. package/agents/pan-verifier.md +7 -2
  23. package/bin/install-lib.cjs +134 -14
  24. package/bin/install.js +59 -12
  25. package/commands/pan/army.md +1 -1
  26. package/commands/pan/autodev.md +76 -0
  27. package/commands/pan/exec-phase.md +3 -4
  28. package/commands/pan/focus-auto.md +14 -7
  29. package/commands/pan/focus-design.md +4 -5
  30. package/commands/pan/focus-docs.md +24 -0
  31. package/commands/pan/learn.md +13 -6
  32. package/commands/pan/milestone-audit.md +8 -1
  33. package/commands/pan/milestone-done.md +10 -5
  34. package/commands/pan/milestone-new.md +2 -2
  35. package/commands/pan/new-project.md +15 -12
  36. package/commands/pan/plan-phase.md +15 -9
  37. package/commands/pan/quick.md +1 -1
  38. package/commands/pan/review-deep.md +11 -5
  39. package/commands/pan/settings.md +6 -0
  40. package/commands/pan/verify-phase.md +6 -2
  41. package/docs/AGENTS.md +917 -0
  42. package/docs/ARCHITECTURE.md +1054 -0
  43. package/docs/CLI-REFERENCE.md +4582 -0
  44. package/docs/COMPARISON.md +116 -0
  45. package/docs/DEVELOPMENT.md +490 -0
  46. package/docs/ECOSYSTEM-REVIEW-2026-06.md +107 -0
  47. package/docs/ECOSYSTEM-REVIEW-2026-08.md +349 -0
  48. package/docs/EXAMPLES.md +584 -0
  49. package/docs/FAQ.md +254 -0
  50. package/docs/FIELD-HARVEST-2026-07.md +88 -0
  51. package/docs/FIELD-REPORT-army-2026-06.md +121 -0
  52. package/docs/HOOKS.md +638 -0
  53. package/docs/IMPROVEMENT-TODO.md +246 -0
  54. package/docs/INTERNALS.md +485 -0
  55. package/docs/MIGRATION-v2-to-v3.md +258 -0
  56. package/docs/SECURITY-HARDENING.md +230 -0
  57. package/docs/SKILLS-ENHANCEMENT-PLAN-V2.md +122 -0
  58. package/docs/SKILLS-FULL-TEXT.md +9685 -0
  59. package/docs/SKILLS-REFERENCE.md +1037 -0
  60. package/docs/TROUBLESHOOTING.md +1084 -0
  61. package/docs/USER-GUIDE.md +1437 -0
  62. package/docs/archive/SKILLS-ENHANCEMENT-PLAN.md +230 -0
  63. package/docs/audits/AUDIT-2026-08-e2e-ROADMAP.md +117 -0
  64. package/docs/audits/AUDIT-2026-08-e2e-VERIFICATION.md +693 -0
  65. package/docs/audits/AUDIT-2026-08-e2e.md +1546 -0
  66. package/docs/audits/OUTSTANDING-2026-08.md +275 -0
  67. package/docs/audits/STABILITY-TEST-2026-08.md +640 -0
  68. package/docs/branding/README-brand-draft.md +119 -0
  69. package/docs/branding/handoff/IMPLEMENTATION.md +205 -0
  70. package/docs/branding/handoff/README-brand-draft.md +119 -0
  71. package/docs/branding/handoff/image-prompts.md +46 -0
  72. package/docs/branding/image-prompts.md +46 -0
  73. package/docs/branding/nano-banana-prompts.txt +60 -0
  74. package/docs/context-monitor.md +13 -0
  75. package/docs/decisions/ADR-0001-strategic-feature-prioritization.md +83 -0
  76. package/docs/decisions/ADR-0002-copilot-cli-runtime.md +71 -0
  77. package/docs/decisions/ADR-0003-smart-execution.md +84 -0
  78. package/docs/decisions/ADR-0004-copilot-cli-interaction.md +89 -0
  79. package/docs/decisions/ADR-0005-command-naming.md +80 -0
  80. package/docs/decisions/ADR-0006-focus-commands.md +101 -0
  81. package/docs/decisions/ADR-0007-ship-v1.md +73 -0
  82. package/docs/decisions/ADR-0008-map-codebase-mermaid-togaf.md +80 -0
  83. package/docs/decisions/ADR-0009-production-deployment-checklist.md +68 -0
  84. package/docs/decisions/ADR-0010-standards-integration.md +79 -0
  85. package/docs/decisions/ADR-0011-help-commands-rewrite.md +64 -0
  86. package/docs/decisions/ADR-0012-contributors-attribution-index.md +42 -0
  87. package/docs/decisions/ADR-0013-strategic-feature-additions.md +53 -0
  88. package/docs/decisions/ADR-0014-internal-cleanup-code-quality.md +53 -0
  89. package/docs/decisions/ADR-0015-focus-auto-runner.md +296 -0
  90. package/docs/decisions/ADR-0016-enhanced-doc-sync.md +54 -0
  91. package/docs/decisions/ADR-0017-enhanced-focus-design.md +69 -0
  92. package/docs/decisions/ADR-0018-user-reality-testing.md +84 -0
  93. package/docs/decisions/ADR-0019-end-to-end-user-acceptance-testing.md +113 -0
  94. package/docs/decisions/ADR-0020-ai-drift-prevention.md +55 -0
  95. package/docs/decisions/ADR-0021-codebase-mapper-v2.md +76 -0
  96. package/docs/decisions/ADR-0022-lifecycle-completeness.md +63 -0
  97. package/docs/decisions/ADR-0023-opus-4-7-adoption.md +89 -0
  98. package/docs/decisions/ADR-0024-spec-b-v2-completion.md +137 -0
  99. package/docs/decisions/ADR-0025-behavioral-guardrails-layer.md +129 -0
  100. package/docs/decisions/ADR-0026-self-improvement-loop.md +171 -0
  101. package/docs/decisions/ADR-0027-doc-code-link-graph.md +164 -0
  102. package/docs/decisions/ADR-0028-unified-agents-skills-target.md +46 -0
  103. package/docs/decisions/ADR-0029-experiment-evaluator.md +76 -0
  104. package/docs/decisions/ADR-0030-planning-concurrency.md +37 -0
  105. package/docs/decisions/ADR-0031-focus-auto-backlog-source.md +47 -0
  106. package/docs/decisions/ADR-0032-squad-model.md +64 -0
  107. package/docs/decisions/ADR-0033-army-campaign.md +40 -0
  108. package/docs/decisions/ADR-0034-scheduled-campaigns.md +57 -0
  109. package/docs/decisions/ADR-0035-army-hud-dashboard.md +40 -0
  110. package/docs/decisions/ADR-0036-agentic-memory-architecture.md +106 -0
  111. package/docs/decisions/ADR-0037-pin-security-agents-to-opus.md +51 -0
  112. package/docs/decisions/ADR-0038-skill-aligned-decomposition.md +41 -0
  113. package/docs/decisions/ADR-0039-worktree-as-project-variant.md +37 -0
  114. package/docs/decisions/ADR-0040-memory-injection-defense.md +55 -0
  115. package/docs/decisions/ADR-0041-mcp-dual-era-bridge.md +47 -0
  116. package/docs/decisions/ADR-0042-design-parity-both-flows.md +45 -0
  117. package/docs/decisions/ADR-0043-addressable-planning-roots.md +56 -0
  118. package/docs/decisions/ADR-0044-bound-the-cached-context.md +104 -0
  119. package/docs/decisions/ADR-0045-agent-plugins-bundle.md +76 -0
  120. package/docs/decisions/ADR-0046-subagent-frontmatter-decisions.md +39 -0
  121. package/docs/decisions/ADR-0047-pan-harness.md +76 -0
  122. package/docs/decisions/ADR-0048-one-core-per-project.md +43 -0
  123. package/docs/decisions/ADR-0049-machine-verdicts-and-findings-ledger.md +116 -0
  124. package/docs/specs/ai_drift_prevention_featureai.md +286 -0
  125. package/docs/specs/codebase_mapper_v2_featureai.md +930 -0
  126. package/docs/specs/command_naming_optimization_featureai.md +930 -0
  127. package/docs/specs/comp_analysis_markdown_v1.md +149 -0
  128. package/docs/specs/continuous_autonomous_execution_featureai.md +304 -0
  129. package/docs/specs/contributors_attribution_index_featureai.md +476 -0
  130. package/docs/specs/copilot_cli_interaction_featureai.md +868 -0
  131. package/docs/specs/copilot_cli_runtime_featureai.md +647 -0
  132. package/docs/specs/custom-skills-assessment.md +461 -0
  133. package/docs/specs/deployment_audit_findings_featureai.md +243 -0
  134. package/docs/specs/doc_code_link_graph_featureai.md +253 -0
  135. package/docs/specs/documentation_alignment_cleanup_featureai.md +69 -0
  136. package/docs/specs/e2e_visual_testing_featureai.md +615 -0
  137. package/docs/specs/end_to_end_user_acceptance_testing_featureai.md +810 -0
  138. package/docs/specs/evidence-loop-plan.md +76 -0
  139. package/docs/specs/evidence_loop_featureai.md +497 -0
  140. package/docs/specs/focus-auto-optimize-category.md +449 -0
  141. package/docs/specs/focus-auto-optimize-superplan.md +188 -0
  142. package/docs/specs/focus_auto_runner_featureai.md +1102 -0
  143. package/docs/specs/focus_design_v2_featureai.md +197 -0
  144. package/docs/specs/focus_sync_v2_featureai.md +202 -0
  145. package/docs/specs/git_integration_overhaul_featureai.md +326 -0
  146. package/docs/specs/glm_zai_provider_featureai.md +200 -0
  147. package/docs/specs/googlecli_adoption_featureai.md +661 -0
  148. package/docs/specs/help_commands_rewrite_featureai.md +860 -0
  149. package/docs/specs/industry_analysis_strategic_additions_featureai.md +231 -0
  150. package/docs/specs/industry_comparison_and_feature_gaps_featureai.md +674 -0
  151. package/docs/specs/internal_cleanup_code_quality_featureai.md +486 -0
  152. package/docs/specs/investigations/README.md +31 -0
  153. package/docs/specs/investigations/digests/2026-09-28.md +47 -0
  154. package/docs/specs/investigations/digests/2026-10-08.md +62 -0
  155. package/docs/specs/investigations/digests/2026-10-10.md +61 -0
  156. package/docs/specs/investigations/features/debugger-red-loop-first.md +55 -0
  157. package/docs/specs/investigations/features/harness-cross-host-behaviour.md +93 -0
  158. package/docs/specs/investigations/features/optimize-apply-regression-gate.md +66 -0
  159. package/docs/specs/investigations/features/reviewer-smell-baseline.md +57 -0
  160. package/docs/specs/investigations/features/trace-failure-capture.md +69 -0
  161. package/docs/specs/lifecycle_completeness_featureai.md +754 -0
  162. package/docs/specs/local-first-ci.md +42 -0
  163. package/docs/specs/map_codebase_mermaid_togaf_featureai.md +805 -0
  164. package/docs/specs/market-delta-2026-09-superplan.md +310 -0
  165. package/docs/specs/market-ideas-2026-09.md +131 -0
  166. package/docs/specs/market-ideas-2026-10.md +428 -0
  167. package/docs/specs/market-ideas-ledger.md +177 -0
  168. package/docs/specs/memory-optimization-2026-10.md +285 -0
  169. package/docs/specs/multi-track-planning-roots.md +143 -0
  170. package/docs/specs/multi_model_routing_featureai.md +687 -0
  171. package/docs/specs/multi_model_routing_superplan.md +197 -0
  172. package/docs/specs/opus_47_existing_enhancements_featureai.md +247 -0
  173. package/docs/specs/opus_47_extended_features_featureai.md +363 -0
  174. package/docs/specs/opus_47_extended_features_v2_featureai.md +397 -0
  175. package/docs/specs/pan_focus_commands_featureai.md +2336 -0
  176. package/docs/specs/pan_zcode_mcp_bridge_featureai.md +120 -0
  177. package/docs/specs/product-excellence-superplan.md +315 -0
  178. package/docs/specs/product_excellence_program_2026_q4_featureai.md +365 -0
  179. package/docs/specs/production_deployment_readiness_featureai.md +433 -0
  180. package/docs/specs/production_readiness_ship_v1_featureai.md +698 -0
  181. package/docs/specs/real_test_enforcement_featureai.md +213 -0
  182. package/docs/specs/reality-check-2026-09-superplan.md +362 -0
  183. package/docs/specs/right-sized-ceremony.md +74 -0
  184. package/docs/specs/roadmap_and_competition_2026_q4_featureai.md +390 -0
  185. package/docs/specs/self_improvement_loop_featureai.md +875 -0
  186. package/docs/specs/skill-aligned-decomposition.md +155 -0
  187. package/docs/specs/standards_integration_featureai.md +833 -0
  188. package/docs/specs/testing-system-redesign-2026-09.md +267 -0
  189. package/docs/specs/user_reality_testing_system_featureai.md +788 -0
  190. package/docs/specs/watch-triggers.json +22 -0
  191. package/docs/specs/workflow-integration-redesign.md +742 -0
  192. package/docs/specs/workflow_state_consistency_featureai.md +183 -0
  193. package/hooks/dist/pan-context-monitor.js +9 -2
  194. package/hooks/dist/pan-cost-logger.js +5 -0
  195. package/hooks/dist/pan-guard.js +28 -5
  196. package/hooks/dist/pan-stop-guard.js +9 -9
  197. package/hooks/dist/pan-trace-logger.js +5 -0
  198. package/package.json +10 -2
  199. package/pan-wizard-core/bin/lib/agents-md.cjs +57 -8
  200. package/pan-wizard-core/bin/lib/autodev-report.cjs +180 -0
  201. package/pan-wizard-core/bin/lib/autodev.cjs +642 -0
  202. package/pan-wizard-core/bin/lib/ci.cjs +143 -0
  203. package/pan-wizard-core/bin/lib/commands.cjs +1 -1
  204. package/pan-wizard-core/bin/lib/config.cjs +31 -2
  205. package/pan-wizard-core/bin/lib/constants.cjs +27 -1
  206. package/pan-wizard-core/bin/lib/core.cjs +22 -10
  207. package/pan-wizard-core/bin/lib/cost.cjs +14 -4
  208. package/pan-wizard-core/bin/lib/cross-family.cjs +164 -0
  209. package/pan-wizard-core/bin/lib/debug-cases.cjs +104 -0
  210. package/pan-wizard-core/bin/lib/failure-class.cjs +81 -0
  211. package/pan-wizard-core/bin/lib/findings.cjs +34 -4
  212. package/pan-wizard-core/bin/lib/focus.cjs +1 -1
  213. package/pan-wizard-core/bin/lib/hosts.cjs +88 -0
  214. package/pan-wizard-core/bin/lib/init.cjs +7 -2
  215. package/pan-wizard-core/bin/lib/knowledge.cjs +2 -0
  216. package/pan-wizard-core/bin/lib/merge.cjs +50 -0
  217. package/pan-wizard-core/bin/lib/mutate.cjs +16 -5
  218. package/pan-wizard-core/bin/lib/next-action.cjs +112 -0
  219. package/pan-wizard-core/bin/lib/optimize.cjs +2 -2
  220. package/pan-wizard-core/bin/lib/phase.cjs +48 -4
  221. package/pan-wizard-core/bin/lib/plan-lint.cjs +150 -1
  222. package/pan-wizard-core/bin/lib/preview.cjs +23 -4
  223. package/pan-wizard-core/bin/lib/requirements-lint.cjs +130 -0
  224. package/pan-wizard-core/bin/lib/research-lint.cjs +150 -3
  225. package/pan-wizard-core/bin/lib/review-deep.cjs +14 -22
  226. package/pan-wizard-core/bin/lib/review-vote.cjs +105 -0
  227. package/pan-wizard-core/bin/lib/runner.cjs +2 -16
  228. package/pan-wizard-core/bin/lib/sizing.cjs +356 -0
  229. package/pan-wizard-core/bin/lib/squads.cjs +1 -1
  230. package/pan-wizard-core/bin/lib/state-write.cjs +247 -0
  231. package/pan-wizard-core/bin/lib/uat.cjs +149 -0
  232. package/pan-wizard-core/bin/lib/verdict.cjs +26 -3
  233. package/pan-wizard-core/bin/lib/verify-plan-set.cjs +30 -1
  234. package/pan-wizard-core/bin/lib/verify-preflight.cjs +2 -2
  235. package/pan-wizard-core/bin/lib/verify-red.cjs +37 -1
  236. package/pan-wizard-core/bin/lib/verify-retro.cjs +3 -2
  237. package/pan-wizard-core/bin/lib/verify.cjs +59 -4
  238. package/pan-wizard-core/bin/lib/worktree.cjs +70 -0
  239. package/pan-wizard-core/bin/pan-tools.cjs +168 -27
  240. package/pan-wizard-core/learnings/universal/autonomous-loop.md +2 -2
  241. package/pan-wizard-core/references/continuation-format.md +3 -3
  242. package/pan-wizard-core/references/guardrails.md +1 -1
  243. package/pan-wizard-core/references/model-profiles.md +2 -3
  244. package/pan-wizard-core/references/questioning.md +24 -0
  245. package/pan-wizard-core/references/ui-brand.md +4 -6
  246. package/pan-wizard-core/references/verdict-contract.md +2 -1
  247. package/pan-wizard-core/templates/config.json +5 -1
  248. package/pan-wizard-core/templates/debug.md +1 -0
  249. package/pan-wizard-core/templates/discovery.md +2 -2
  250. package/pan-wizard-core/templates/requirements.md +9 -0
  251. package/pan-wizard-core/workflows/add-phase.md +4 -6
  252. package/pan-wizard-core/workflows/assumptions.md +19 -1
  253. package/pan-wizard-core/workflows/diagnose-issues.md +2 -0
  254. package/pan-wizard-core/workflows/discuss-phase.md +4 -2
  255. package/pan-wizard-core/workflows/exec-lean.md +69 -0
  256. package/pan-wizard-core/workflows/exec-phase.md +36 -8
  257. package/{commands/pan → pan-wizard-core/workflows}/focus-doc-audit.md +13 -29
  258. package/{commands/pan → pan-wizard-core/workflows}/focus-drift-walking.md +3 -18
  259. package/{commands/pan → pan-wizard-core/workflows}/focus-exec.md +8 -23
  260. package/{commands/pan → pan-wizard-core/workflows}/focus-plan.md +6 -20
  261. package/{commands/pan → pan-wizard-core/workflows}/focus-scan.md +3 -16
  262. package/{commands/pan → pan-wizard-core/workflows}/focus-sync.md +7 -21
  263. package/pan-wizard-core/workflows/health.md +6 -0
  264. package/pan-wizard-core/workflows/help.md +31 -53
  265. package/pan-wizard-core/workflows/insert-phase.md +4 -6
  266. package/pan-wizard-core/workflows/learn.md +3 -3
  267. package/pan-wizard-core/workflows/milestone-audit.md +2 -2
  268. package/pan-wizard-core/workflows/milestone-new.md +38 -95
  269. package/pan-wizard-core/workflows/new-project.md +96 -258
  270. package/pan-wizard-core/workflows/optimize.md +107 -5
  271. package/pan-wizard-core/workflows/phase-tests.md +10 -0
  272. package/pan-wizard-core/workflows/plan-phase.md +86 -43
  273. package/pan-wizard-core/workflows/profile.md +50 -0
  274. package/pan-wizard-core/workflows/progress.md +10 -0
  275. package/pan-wizard-core/workflows/quick.md +34 -43
  276. package/pan-wizard-core/workflows/research-phase.md +118 -40
  277. package/pan-wizard-core/workflows/resume-project.md +18 -2
  278. package/pan-wizard-core/workflows/settings.md +21 -24
  279. package/pan-wizard-core/workflows/todo-check.md +6 -2
  280. package/pan-wizard-core/workflows/transition.md +22 -4
  281. package/pan-wizard-core/workflows/uat-walkthrough.md +90 -0
  282. package/pan-wizard-core/workflows/update.md +1 -1
  283. package/pan-wizard-core/workflows/verify-phase.md +2 -2
  284. package/scripts/build-agent-plugin.js +35 -15
  285. package/scripts/build-plugin.js +10 -1
  286. package/scripts/deprecate-old-versions.js +70 -3
  287. package/scripts/generate-skills-docs.py +1 -1
  288. package/scripts/git-hooks/pre-push +27 -0
  289. package/scripts/install-git-hooks.js +7 -5
  290. package/scripts/install-pre-push.cjs +38 -0
  291. package/scripts/land.cjs +151 -0
  292. package/scripts/local-ci.cjs +501 -0
  293. package/scripts/local-schedule.cjs +277 -0
  294. package/scripts/prompt-lint.cjs +32 -0
  295. package/scripts/prompt-rules.cjs +156 -0
  296. package/scripts/run-tests.cjs +7 -1
  297. package/scripts/test-quality-lint.cjs +3 -3
  298. package/scripts/test-surface.cjs +9 -2
  299. package/agents/pan-research-synthesizer.md +0 -246
  300. package/commands/pan/audit-deployment.md +0 -386
  301. package/commands/pan/dashboard.md +0 -22
  302. package/commands/pan/discord.md +0 -19
  303. package/commands/pan/mcp-bridge.md +0 -143
  304. package/commands/pan/milestone-cleanup.md +0 -19
  305. package/commands/pan/milestone-gaps.md +0 -35
  306. package/commands/pan/optimize.md +0 -115
  307. package/commands/pan/profile.md +0 -76
  308. package/commands/pan/research-phase.md +0 -189
  309. package/pan-wizard-core/bin/lib/bridge.cjs +0 -269
  310. package/pan-wizard-core/templates/research-project/architecture.md +0 -210
  311. package/pan-wizard-core/templates/research-project/features.md +0 -153
  312. package/pan-wizard-core/templates/research-project/pitfalls.md +0 -206
  313. package/pan-wizard-core/templates/research-project/stack.md +0 -126
  314. package/pan-wizard-core/templates/research-project/summary.md +0 -170
@@ -0,0 +1,1102 @@
1
+ # featureAI: Focus Auto-Runner — Continuous Categorized Execution Pipeline
2
+
3
+ > **Generated**: 2026-03-03 (v2 — deep rewrite incorporating budget heritage + ADR quality bar)
4
+ > **Mode**: `--full` (all 10 phases)
5
+ > **Feature**: `/pan:focus-auto` — Continuous scan→plan→exec loop with purpose-driven campaigns
6
+ > **ADR**: ADR-0015
7
+ > **Predecessors**: execplan.md (capacity budget), superplan.md (scan/priority), panmonty_protocol.md (change categories, loop exhaustion)
8
+
9
+ ---
10
+
11
+ ## Phase 0: Problem Framing & Demand Validation
12
+
13
+ ### 0.1 Problem Statement
14
+
15
+ PAN Wizard's focus system — born from the execplan/superplan lineage (sessions 1-16) and reified in the focus commands (session 17, ADR-0006) — requires **three manual invocations per improvement cycle**: `/pan:focus-scan` → `/pan:focus-plan` → `/pan:focus-exec`. Each cycle takes 20-60 minutes of AI time and produces 15-50 points of verified work. For the sustained multi-cycle campaigns that produce transformative codebase improvement (sessions 24-25 together cleaned 44 items across 65 files), the human must manually bridge each cycle: reviewing the scan, confirming the plan, monitoring execution, then repeating.
16
+
17
+ This matters NOW because: (a) the focus system has proven its value over 6 consecutive sessions, establishing that iterative refinement delivers compound quality gains, (b) competitors are converging on continuous execution (Cursor Background Agents, GitHub Copilot Coding Agent, Aider --watch-files), and (c) PAN's unique budget + priority + category infrastructure — which no competitor has — is the perfect foundation for intelligent autonomous looping.
18
+
19
+ The cost of NOT building this: Users plateau at 1-2 manual cycles per session instead of running the 5-10 cycle campaigns that transform codebase quality. The manual overhead also prevents off-hours execution — a developer can't say "clean up the test suite overnight" without this feature.
20
+
21
+ ### 0.2 Demand Evidence
22
+
23
+ | Evidence Type | Source | Finding |
24
+ |--------------|--------|---------|
25
+ | **User-stated explicit request** | This conversation | "design auto flow, new one that can perform continuously from scan-plan-exec-scan... etc, with categories of what it scans for, like cleanups for example and then categorizes them" |
26
+ | **Internal usage pattern (quantified)** | Sessions 24-25 (2026-03-03) | Two back-to-back manual cycles in a single day: session 24 (20 items, 45 pts, 1180→1190 tests) + session 25 (24 items, 50 pts, 1190→1169 tests). Total: 44 items, 95 pts across 2 manual cycles |
27
+ | **Internal usage pattern (historical)** | Sessions 1-12 | The execplan/superplan pipeline was manually invoked 12+ times across 12 sessions, accumulating 363→674 tests. Each session required manual plan loading + capacity budgeting |
28
+ | **Competitor convergence** | Cursor, Copilot, Aider | Cursor ships cloud Background Agents (2M PRs/month). GitHub Copilot Coding Agent runs on issue assignment. Aider has --watch-files event-driven mode. Industry moving toward autonomous execution |
29
+ | **PanMonty heritage** | panmonty_protocol.md | PanMonty already defines 5 change categories (DOCS_ONLY, TESTS_ONLY, LIB_CHANGE, HOOK_CHANGE, FULL_FEATURE) and a loop exhaustion guard (3rd Phase 7 entry → ask user). This proves the concept of categorized looping is architecturally native to PAN |
30
+
31
+ **Demand status**: STRONG — direct user request + quantified internal usage across 25 sessions + competitive convergence + architectural heritage.
32
+
33
+ ### 0.3 Scope Definition
34
+
35
+ | In Scope | Out of Scope (and why) |
36
+ |----------|------------------------|
37
+ | Continuous scan→plan→exec loop orchestration | Cloud/remote execution (PAN is local-first, zero-dep — no Docker, no GitHub Actions) |
38
+ | 5 purpose categories (cleanup, tests, stability, features, docs) | User-defined custom categories (5 predefined covers 95% of real usage in sessions 1-25; extensibility adds config complexity for negligible value) |
39
+ | Category-scoped scanning with priority-range filtering | Real-time file watching (Aider's --watch-files approach; batch execution is PAN's paradigm, not event-driven) |
40
+ | Triple safety net: per-cycle budget + cumulative budget + max cycles | Multi-branch parallel execution (requires git worktree orchestration; session-bound is simpler and safer) |
41
+ | Circuit breaker on test regression (inherits PanMonty's loop exhaustion pattern) | External task sources like Jira/GitHub Issues (PAN reads .planning/ only; external integration is a separate feature) |
42
+ | Run state persistence in auto-run.json for cross-session resumability | AI model selection per category (model profile is a separate concern, handled by /pan:profile) |
43
+ | `pan-tools focus auto` core subcommand extending focus.cjs | New core module (focus.cjs is the right home; no module proliferation) |
44
+ | Inherits ALL 9 behavioral rules from focus-exec within each cycle | Modifying the 9 behavioral rules (these are battle-tested across 6+ sessions) |
45
+ | Inherits the capacity budget system from execplan/focus-plan | New budget system (the XS=1/S=2/M=4/L=10/XL=20 system is proven across 25 sessions) |
46
+
47
+ ### 0.4 Success Criteria (Measurable)
48
+
49
+ ```
50
+ SC-1: User starts a multi-cycle campaign with one command: `/pan:focus-auto --category cleanup`
51
+ SC-2: Each cycle produces a verifiable batch with before/after test counts (inherits focus-exec Stage 4)
52
+ SC-3: Loop stops automatically on ANY of: budget exhausted, no items remain, test regression, max cycles, zero completed items in a cycle
53
+ SC-4: Category filter reduces scan results by >= 40% vs unfiltered scan (measured: cleanup items are ~30% of total in sessions 24-25)
54
+ SC-5: Progress persists to .planning/focus/auto-run.json — can resume with --continue across sessions
55
+ SC-6: Zero regressions in existing 1169 tests
56
+ SC-7: Works across all 5 runtimes (Claude Code, OpenCode, Gemini CLI, Codex, Copilot CLI)
57
+ SC-8: pan-tools focus auto completes in < 300ms (state management only; scan/plan/exec are separate invocations)
58
+ SC-9: Raw mode (--raw) produces a human-readable campaign dashboard for non-JSON consumers
59
+ ```
60
+
61
+ ### 0.5 User Stories
62
+
63
+ ```
64
+ As a developer who just ran 2 manual cleanup cycles back-to-back (like sessions 24-25),
65
+ I want to say "/pan:focus-auto --category cleanup --max-cycles 5",
66
+ so that the AI handles the scan→plan→exec cycling automatically while I review the results,
67
+ instead of manually invoking 3 commands per cycle (15 total invocations for 5 cycles).
68
+
69
+ As a developer maintaining a large codebase with 1169+ tests,
70
+ I want purpose-driven campaigns where "--category tests" only touches test files
71
+ and "--category stability" only touches error handling and validation,
72
+ so that each campaign has a clear, reviewable scope and doesn't mix unrelated changes,
73
+ instead of getting a mixed bag where cleanup items, feature items, and test items
74
+ are interleaved in ways that make commit review harder.
75
+
76
+ As a developer running improvement campaigns during focused work blocks,
77
+ I want the auto-runner to stop safely on test regression (circuit breaker),
78
+ stop on budget exhaustion (cumulative cap), and persist progress for --continue later,
79
+ so that I can trust the auto-runner to maintain codebase integrity autonomously,
80
+ instead of babysitting each cycle and worrying about runaway execution.
81
+
82
+ As a developer using PAN Wizard across different AI runtimes,
83
+ I want the auto-runner to work identically whether I invoke it from Claude Code,
84
+ OpenCode, Gemini CLI, Codex, or Copilot CLI,
85
+ so that my campaign workflow doesn't change when I switch tools,
86
+ instead of learning runtime-specific continuous execution patterns.
87
+ ```
88
+
89
+ ### 0.6 Cannibalization Check
90
+
91
+ | Existing Command/Agent | Overlap? | Impact |
92
+ |-----------------------|----------|--------|
93
+ | `/pan:focus-scan` | Partial — auto calls scan internally per cycle | No migration. Auto-runner USES scan. Scan remains independently invocable. |
94
+ | `/pan:focus-plan` | Partial — auto calls plan internally per cycle | No migration. Auto-runner USES plan with category-filtered items. Plan remains independently invocable. |
95
+ | `/pan:focus-exec` | Partial — auto calls exec internally per cycle | No migration. Auto-runner USES exec for the 6-stage pipeline. Exec remains independently invocable. |
96
+ | `/pan:focus-sync` | None — sync is called within exec's Stage 5 | N/A |
97
+ | `/pan:focus-design` | None — design is standalone investigation | N/A |
98
+ | `/pan:exec-phase` | None — different abstraction (roadmap phases vs focus items) | N/A |
99
+ | `/pan:panmonty` (PanMonty protocol) | Conceptual — PanMonty has change categories + loop exhaustion | Auto-runner adopts PanMonty's category concept but operates at focus-batch granularity, not individual-item granularity. PanMonty is for manual feature implementation; auto-runner is for automated quality campaigns. |
100
+ | `execplan.md` (legacy) | Historical — execplan's budget system is now in focus-exec | execplan is superseded by focus-exec. Auto-runner extends focus-exec, not execplan. |
101
+ | `superplan.md` (legacy) | Historical — superplan's scan system is now in focus-scan | superplan is superseded by focus-scan. Auto-runner extends focus-scan, not superplan. |
102
+
103
+ **Verdict**: No full overlap. The auto-runner is a NEW orchestration layer that composes existing focus commands into an automated loop. All existing commands remain independently usable. The conceptual heritage from PanMonty (categories) and execplan/superplan (budget) validates the approach rather than duplicating it.
104
+
105
+ ### 0.7 Cognitive Load Assessment
106
+
107
+ | Metric | Before | After | Delta |
108
+ |--------|--------|-------|-------|
109
+ | Focus commands | 5 (scan, plan, exec, sync, design) | 6 (+auto) | +1 command |
110
+ | New concepts | 0 | 2 (categories, auto-loop) | +2 concepts |
111
+ | Manual invocations for 5-cycle campaign | 15 (3 per cycle × 5) | 1 | -14 invocations |
112
+ | Score | — | — | **-1 (net simplification)** |
113
+
114
+ **Justification**: While auto introduces +1 command and +2 concepts, it ELIMINATES 14 manual invocations for the most common power-user workflow (multi-cycle campaigns). The category concept is already familiar from PanMonty's change categories. Net effect: **simplification** for the target audience (users who run 2+ cycles).
115
+
116
+ ---
117
+
118
+ ## Phase 1: Internal Reconnaissance
119
+
120
+ ### 1.1 Existing Capabilities Inventory
121
+
122
+ | Capability | Status | Location | Relevance to Auto-Runner |
123
+ |------------|--------|----------|--------------------------|
124
+ | Work item collection (phases, todos, patterns) | Production (session 17+) | focus.cjs:collectWorkItems | **Core dependency** — needs category post-filter |
125
+ | Priority classification (P0-P6) | Production (session 17+) | focus.cjs:classifyItemPriority | **Reuse unchanged** — categories map to priority ranges |
126
+ | Reality Score computation (RS formula) | Production (session 17+) | focus.cjs:computeRealityScore | **Reuse unchanged** — RS filtering within categories |
127
+ | Budget allocation (4 modes) | Production (session 17+) | focus.cjs:allocateBudget | **Reuse unchanged** — mode selection per category |
128
+ | Multi-pass allocation (stability/feature split) | Production (session 17+) | focus.cjs:allocatePass | **Reuse unchanged** — passes constrained by category priority range |
129
+ | Tier classification (MICRO/STANDARD/FULL) | Production (session 17+) | focus.cjs:classifyTier | **Reuse unchanged** — tier pacing within each cycle |
130
+ | Batch file persistence (JSON) | Production (session 17+) | focus.cjs:cmdFocusPlan | **Reuse unchanged** — each cycle produces a batch file |
131
+ | Latest batch reader | Production (session 17+) | focus.cjs:readLatestBatch | **Reuse unchanged** — exec reads batch per cycle |
132
+ | Doc staleness detection | Production (session 17+) | focus.cjs:checkDocStaleness | **Reuse unchanged** — sync within exec's Stage 5 |
133
+ | Error pattern reading | Production (session 14+) | commands.cjs:readErrorPatterns | **Reuse unchanged** — patterns are scan input source |
134
+ | Session history append | Production (session 14+) | commands.cjs:appendSessionSummary | **New usage** — append per-campaign summary |
135
+ | Rollback snapshots | Production (session 14+) | commands.cjs:cmdRollbackSnapshot | **Reuse unchanged** — snapshot per cycle |
136
+ | PanMonty change categories | Production (session 1+) | panmonty_protocol.md | **Heritage** — 5 categories (DOCS/TESTS/LIB/HOOK/FULL) inform auto-runner's 5 categories |
137
+ | PanMonty loop exhaustion | Production (session 1+) | panmonty_protocol.md Phase 7 | **Heritage** — 3rd Phase 7 entry asks user. Auto-runner adapts: zero-completed-items triggers stop |
138
+ | execplan capacity budget | Superseded by focus-exec | execplan.md | **Heritage** — XS=1/S=2/M=4/L=10/XL=20 system carried forward unchanged |
139
+ | execplan 9 behavioral rules | Superseded by focus-exec | execplan.md/focus-exec.md | **Heritage** — all 9 rules inherited by auto-runner cycles |
140
+ | Verbose logging | Production (session 18+) | core.cjs:verbose() | **Reuse** — per-cycle verbose output for diagnostics |
141
+ | Safe file read | Production (all sessions) | core.cjs:safeReadFile() | **Reuse** — auto-run.json reading |
142
+ | Path normalization | Production (all sessions) | core.cjs:toPosix() | **Reuse** — all paths in output |
143
+ | Config loading | Production (all sessions) | config.cjs:loadConfig() | **New usage** — load auto-runner defaults from config.json |
144
+
145
+ ### 1.2 Budget System Heritage Map
146
+
147
+ The auto-runner's budget system traces a clear lineage:
148
+
149
+ ```
150
+ execplan.md (v1, session 1-12)
151
+ ├── Capacity Budget: XS=1, S=2, M=4, L=10, XL=20
152
+ ├── 4 Modes: bugfix/balanced/features/full
153
+ ├── 6-Stage Pipeline
154
+ ├── 9 Behavioral Rules
155
+ └── Test cadence by tier: MICRO(batch 3)/STANDARD(each)/FULL(build+each)
156
+ │
157
+ ↓
158
+ superplan.md (v1-v18, session 1-20)
159
+ ├── Priority Framework: P0-P6
160
+ ├── Effort Estimation: XS-XL
161
+ ├── Reality Score: RS = (UV + TC + RR) / JS
162
+ └── Scan Assembly: items grouped by priority
163
+ │
164
+ ↓
165
+ focus-scan/plan/exec (v1, session 17, ADR-0006)
166
+ ├── Unified in focus.cjs module (559 LOC)
167
+ ├── JSON batch files (.planning/focus/batch-*.json)
168
+ ├── Constants in constants.cjs (EFFORT_POINTS, FOCUS_MODES, etc.)
169
+ ├── allocateBudget() with multi-pass algorithm
170
+ └── 73 tests in focus.test.cjs
171
+ │
172
+ ↓
173
+ panmonty_protocol.md (parallel track, session 1+)
174
+ ├── 5 Change Categories: DOCS_ONLY/TESTS_ONLY/LIB_CHANGE/HOOK_CHANGE/FULL_FEATURE
175
+ ├── Loop Exhaustion Guard: 3rd Phase 7 entry → ask user
176
+ ├── Batch Planning: size all items → assign tier → sequence
177
+ └── Quick Mode: auto-detect XS/S DOCS/TESTS → skip full workflow
178
+ │
179
+ ↓
180
+ focus-auto (THIS FEATURE)
181
+ ├── Inherits: budget system, 4 modes, 6-stage pipeline, 9 rules, tier cadence
182
+ ├── Inherits: P0-P6 priorities, RS scoring, effort estimation
183
+ ├── Inherits: JSON batch files, allocateBudget(), constants
184
+ ├── Adapts: PanMonty categories → 5 purpose categories with priority-range mapping
185
+ ├── Adapts: PanMonty loop exhaustion → circuit breaker + zero-completed stop
186
+ └── Creates: continuous loop, run state persistence, campaign-level tracking
187
+ ```
188
+
189
+ ### 1.3 Convention Enforcement Checklist
190
+
191
+ - [x] Function naming: `cmdFocusAuto()` follows `cmd` prefix pattern (see cmdFocusScan, cmdFocusPlan, etc.)
192
+ - [x] File reads: safe read via `safeReadFile()` or try-catch with null return
193
+ - [x] File writes: wrapped in try-catch (see writeStateMd pattern in state.cjs)
194
+ - [x] JSON output: via `output(obj, raw, rawMessage)` — never console.log
195
+ - [x] Errors: via `error(msg)` — never console.error or throw
196
+ - [x] Paths: via `toPosix(path)` — never raw path.join in output fields
197
+ - [x] Exports: at bottom of focus.cjs via `module.exports = { ... }`
198
+ - [x] Subcommand routing: `auto` case in focus switch block in pan-tools.cjs
199
+ - [x] Module format: CommonJS (.cjs, require()/module.exports)
200
+ - [x] Zero runtime deps: Node.js built-ins only (fs, path, child_process)
201
+ - [x] getArgValue: use `getArgValue(args, flag, default)` for flag parsing (session 24 pattern)
202
+
203
+ ### 1.4 Dependency & Integration Map
204
+
205
+ ```
206
+ [focus auto]
207
+ ├── depends on: focus.cjs — collectWorkItems, allocateBudget, classifyTier,
208
+ │ computeRealityScore, sortByPriority, readLatestBatch
209
+ ├── depends on: constants.cjs — PRIORITY_LEVELS, EFFORT_POINTS, FOCUS_MODES,
210
+ │ FOCUS_TIERS, FOCUS_DIR, new AUTO_RUN_FILE,
211
+ │ new FOCUS_CATEGORIES, new DEFAULT_MAX_CYCLES,
212
+ │ new DEFAULT_TOTAL_BUDGET
213
+ ├── depends on: core.cjs — output, error, safeReadFile, toPosix, verbose
214
+ ├── depends on: utils.cjs — planningPath
215
+ ├── extends: focus subcommand group (adds 'auto' alongside scan/plan/exec/sync/design)
216
+ ├── informed by: panmonty_protocol.md — change categories, loop exhaustion guard
217
+ ├── informed by: execplan.md — capacity budget, 6-stage pipeline, 9 behavioral rules
218
+ ├── conflicts with: nothing (purely additive — no existing functions modified)
219
+ └── enables: overnight campaigns, CI integration, scheduled quality runs, --continue resumability
220
+ ```
221
+
222
+ **require() chain**: `pan-tools.cjs` → `focus.cjs` (cmdFocusAuto) → `constants.cjs` + `core.cjs` + `utils.cjs`. No new modules. No circular dependencies (verified: focus.cjs has no reverse dependency on pan-tools.cjs).
223
+
224
+ ---
225
+
226
+ ## Phase 2: Competitive Intelligence
227
+
228
+ ### 2.1 Deep-Dive Summary (8 Tools Researched)
229
+
230
+ Full competitive research in: [continuous_autonomous_execution_featureai.md](continuous_autonomous_execution_featureai.md)
231
+
232
+ | Tool | Continuous Mode | Categories | Budget | Loop Control | Safety |
233
+ |------|----------------|------------|--------|-------------|--------|
234
+ | **Aider** | --watch-files (event) | None | None | User bash loop | --dry-run, --auto-test |
235
+ | **Cursor** | Background Agents (cloud) | None (Bugbot is 1 specialized agent) | Opaque credits | Run until done/fail | Plan mode, branch isolation |
236
+ | **Cline** | YOLO mode | None | None (removed v3.35) | None | Action-type permissions (can disable all) |
237
+ | **Windsurf** | Turbo Mode | None | Per-session | Debug loop (try→test→retry) | Memories system, rules |
238
+ | **GitHub Copilot** | Coding Agent (cloud, issue-triggered) | GitHub labels (implicit) | Per-issue | PR completion | Branch isolation, Actions CI |
239
+ | **Claude Code** | Headless -p, Agent SDK | None | --max-turns N | Session end | Permission modes |
240
+ | **Devin** | Compound agent (Planner/Coder/Critic) | None | Per-task | Checkpoint iteration | Sandboxed environment |
241
+ | **OpenAI Codex** | Per-task cloud sandbox | None | Per-task | Task completion | System-level sandbox |
242
+
243
+ ### 2.2 Five Whitespace Opportunities
244
+
245
+ 1. **Categorized work queue** — No tool has a structured, user-visible work queue with purpose-driven categories. GitHub Copilot uses labels but as implicit routing, not as a scoping mechanism.
246
+ 2. **Budget-aware continuous execution** — No tool has per-cycle or cumulative budget caps. Cursor depletes credits opaquely. Cline removed its only safeguard.
247
+ 3. **Priority-driven automatic selection** — No tool auto-selects work by priority × effort × reality score. Every competitor treats work items as equal.
248
+ 4. **Structured progress persistence** — Most tools rely on git commits as only state. PAN's `.planning/` directory with structured JSON provides machine-readable progress that survives across sessions and runtimes.
249
+ 5. **Cross-runtime orchestration** — Every tool is siloed to one runtime. PAN's 5-runtime command .md architecture means the auto-runner works identically across Claude Code, OpenCode, Gemini CLI, Codex, and Copilot CLI.
250
+
251
+ ### 2.3 Heritage Advantage: PanMonty Categories → Focus Categories
252
+
253
+ PAN is uniquely positioned because the category concept is **already architecturally native**:
254
+
255
+ | PanMonty Category | Detected By | Focus Auto Category | Priority Range | Mode Hint |
256
+ |-------------------|-------------|---------------------|----------------|-----------|
257
+ | DOCS_ONLY | Only `.md` files touched | **docs** | P5-P6 | balanced |
258
+ | TESTS_ONLY | Only `tests/` files touched | **tests** | P2-P5 | balanced |
259
+ | LIB_CHANGE | `pan-wizard-core/bin/lib/*.cjs` files | **stability** or **cleanup** | P0-P3 | bugfix/balanced |
260
+ | HOOK_CHANGE | `hooks/src/*.js` files | **features** | P3-P5 | features |
261
+ | FULL_FEATURE | Cross-cutting changes | *(no direct mapping — auto-runner is for iterative refinement, not new features)* | P3-P5 | features |
262
+
263
+ This means the category concept has been **validated in production** (PanMonty has been used since session 1) — we're not inventing a new concept, we're elevating a proven one.
264
+
265
+ ---
266
+
267
+ ## Phase 3: Strategic Analysis
268
+
269
+ ### 3.1 Blue Ocean Four Actions Framework
270
+
271
+ | Action | Question | Decisions |
272
+ |--------|----------|-----------|
273
+ | **ELIMINATE** | What should we drop? | Complex configuration taxonomies. No YAML config for categories. No daemon/service mode. No cloud execution. No real-time file watching. No user-extensible category definitions (5 is enough). |
274
+ | **REDUCE** | What should be reduced? | Manual invocations per campaign: 15 → 1. Cognitive load of remembering scan→plan→exec sequence. Decision fatigue about mode/budget per cycle (category implies sensible defaults). Human attention required between cycles (from constant to zero, with circuit breaker safety). |
275
+ | **RAISE** | What should be raised? | Campaign visibility: structured per-cycle stats, cumulative progress dashboard. Safety guarantees: triple safety net + circuit breaker + PanMonty-derived loop exhaustion guard. Resumability: cross-session --continue with full state restore. Test quality assurance: regression detection between cycles, not just within. |
276
+ | **CREATE** | What should we create? | **Purpose-driven campaigns** — not "run stuff continuously" but "run a cleanup campaign" with domain-scoped scanning, appropriate mode defaults, and meaningful stopping conditions. **Campaign-level analytics** — total items, points, test delta across all cycles. **Intelligent default escalation** — category→mode→priority-range→budget chain eliminates manual flag selection. |
277
+
278
+ ### 3.2 Wardley Evolution Assessment
279
+
280
+ ```
281
+ Genesis ──────── Custom-Built ──────── Product ──────── Commodity
282
+ ▲ ▲
283
+ │ │
284
+ Categorized work Continuous execution
285
+ queues (PAN only) (Cursor/Copilot/Aider)
286
+ │
287
+ │
288
+ Budget-aware execution
289
+ (PAN only, proven 25 sessions)
290
+ ```
291
+
292
+ - **Continuous execution**: Moving from Custom-Built → Product. Cursor, Copilot, Aider all have some form. Becoming table-stakes within 12 months.
293
+ - **Categorized work queues**: Still in Genesis. PAN is the only tool exploring this. First-mover advantage with 18+ months before competitors could replicate (they'd need to build the entire scan→plan→exec infrastructure first).
294
+ - **Budget-aware execution**: Custom-Built, unique to PAN. The XS/S/M/L/XL point system with 4 modes has been proven across 25 sessions. No competitor has attempted this.
295
+ - **2-3 year forecast**: Continuous execution becomes commodity. Categorization and budget awareness become the differentiators for enterprise adoption. PAN should own this space NOW.
296
+
297
+ ### 3.3 Strategic Moat Analysis
298
+
299
+ | Moat Type | Contribution | Score (0-5) |
300
+ |-----------|-------------|-------------|
301
+ | **Context Engineering** | Categories reduce scan noise by 40-70% per campaign, improving AI focus and item quality | 5 |
302
+ | **Cross-Platform** | Auto-runner works across 5 runtimes via command .md — no competitor has cross-runtime continuous execution | 5 |
303
+ | **Developer Experience** | Single command replaces 15 invocations for a 5-cycle campaign — transformative workflow reduction | 5 |
304
+ | **Zero Dependencies** | Pure Node.js, file-based state, no daemon, no database, no cloud, no Docker | 5 |
305
+ | **State Persistence** | auto-run.json tracks per-cycle stats with --continue resumability — survives session boundaries | 5 |
306
+ | **Verification Quality** | Triple safety net (per-cycle + cumulative + max-cycles) + regression circuit breaker + zero-completed-items guard (from PanMonty loop exhaustion) | 5 |
307
+ | **Budget Heritage** | 25 sessions of proven budget system (execplan → focus-exec), 4 allocation modes, RS scoring — no competitor has this depth | 5 |
308
+ | **Total** | | **35/35** |
309
+
310
+ ### 3.4 Strategic Recommendation
311
+
312
+ **BUILD — IMMEDIATELY.** This is the most strategically differentiated feature PAN can ship. The auto-runner sits at the intersection of THREE unique capabilities that no competitor has: (1) categorized work queues, (2) budget-aware execution with 25 sessions of proven point-system heritage, and (3) cross-runtime portability. Our unique angle: **purpose-driven campaigns** — "run a cleanup campaign" or "run a test hardening campaign" as a single-command experience, with each category carrying sensible defaults for mode, priority range, and budget. We should explicitly NOT copy Cursor's opaque cloud execution (PAN is transparent and local), Cline's safety-free YOLO mode (PAN's circuit breaker is a feature, not a constraint), or Aider's "user writes the bash loop" approach (PAN provides the orchestration). The strategic timing is NOW — we have the infrastructure (focus-scan/plan/exec), the heritage (execplan/superplan/PanMonty), and the demand (user request + 25 sessions of manual cycling).
313
+
314
+ ---
315
+
316
+ ## Phase 3.5: Architecture & Implementation Pattern Assessment
317
+
318
+ ### 3.5.1 Feature Type Classification
319
+
320
+ | Component | Type | Template |
321
+ |-----------|------|----------|
322
+ | `cmdFocusAuto()` in focus.cjs | Core Enhancement | Add to existing module |
323
+ | `categoryFilter()` in focus.cjs | Core Enhancement | New exported helper |
324
+ | `readAutoRun()` / `writeAutoRun()` in focus.cjs | Core Enhancement | New persistence helpers |
325
+ | `focus auto` dispatch in pan-tools.cjs | Dispatcher Addition | New case in focus switch |
326
+ | Constants (FOCUS_CATEGORIES, etc.) | Constants Addition | Add to constants.cjs |
327
+ | `focus-auto.md` command file | New Workflow | New command .md |
328
+ | Config defaults for auto section | Config Enhancement | Add section to loadConfig |
329
+
330
+ ### 3.5.2 Layer Violation Check
331
+
332
+ - [x] Command file (.md) does NOT call core modules directly — invokes `pan-tools focus auto` via CLI
333
+ - [x] focus.cjs returns data objects — does NOT import agent files or command .md files
334
+ - [x] `cmdFocusAuto()` calls `output()` only as a cmd* entry point — helper functions return data
335
+ - [x] No upward dependencies — focus.cjs does NOT require pan-tools.cjs (verified in Phase 1.4)
336
+ - [x] `categoryFilter()` is a pure function — takes items + category, returns filtered items
337
+ - [x] `readAutoRun()` / `writeAutoRun()` follow the `readJsonFile()` / `safeReadFile()` patterns
338
+
339
+ ### 3.5.3 Output Contract Design (Contract-First)
340
+
341
+ **`pan-tools focus auto` — Initialize a new run:**
342
+ ```json
343
+ {
344
+ "run_id": "string — auto-YYYY-MM-DD-N (N = run number for that day)",
345
+ "status": "string — initialized",
346
+ "category": "string|null — cleanup|tests|stability|features|docs|null(all)",
347
+ "mode": "string — bugfix|balanced|features|full",
348
+ "budget_per_cycle": "number — points per cycle (5-100)",
349
+ "max_cycles": "number — maximum iterations (1-50)",
350
+ "total_budget": "number — cumulative points cap (5-5000)",
351
+ "priority_range": "[string, string] — [min_priority, max_priority] derived from category",
352
+ "cycles_completed": 0,
353
+ "total_items_completed": 0,
354
+ "total_points_used": 0,
355
+ "tests_baseline": "number|null — filled by workflow after npm test",
356
+ "run_file": "string — posix path to .planning/focus/auto-run.json"
357
+ }
358
+ ```
359
+
360
+ **`pan-tools focus auto --status` — Check progress:**
361
+ ```json
362
+ {
363
+ "run_id": "string",
364
+ "status": "string — initialized|in_progress|completed|stopped|failed",
365
+ "category": "string|null",
366
+ "cycles_completed": "number",
367
+ "total_items_completed": "number",
368
+ "total_points_used": "number",
369
+ "budget_remaining": "number — total_budget - total_points_used",
370
+ "cycles_remaining": "number — max_cycles - cycles_completed",
371
+ "tests_baseline": "number",
372
+ "tests_current": "number",
373
+ "tests_delta": "number — tests_current - tests_baseline",
374
+ "stop_reason": "string|null — exhausted|no_items|regression|max_cycles|budget_cap|zero_completed|user_stop",
375
+ "last_cycle": "object|null — { cycle, items_completed, items_failed, points_used, tests_before, tests_after, batch_file }"
376
+ }
377
+ ```
378
+
379
+ **`pan-tools focus auto --update` — Record cycle results (called by workflow after each cycle):**
380
+ ```json
381
+ {
382
+ "run_id": "string",
383
+ "status": "string — in_progress|completed|stopped",
384
+ "cycle_recorded": "number — which cycle was just recorded",
385
+ "total_items_completed": "number — updated cumulative",
386
+ "total_points_used": "number — updated cumulative",
387
+ "stop_reason": "string|null"
388
+ }
389
+ ```
390
+
391
+ **`pan-tools focus auto --stop` — Graceful stop:**
392
+ ```json
393
+ {
394
+ "run_id": "string",
395
+ "status": "stopped",
396
+ "stop_reason": "user_stop",
397
+ "cycles_completed": "number",
398
+ "total_items_completed": "number"
399
+ }
400
+ ```
401
+
402
+ **Contract rules verified:**
403
+ - [x] camelCase field names (run_id uses underscore for consistency with existing batch format)
404
+ - [x] No collisions with scan/plan/exec output fields
405
+ - [x] Error shape: `{"error": "descriptive message"}` — consistent with all 91 subcommands
406
+ - [x] Paths via toPosix() — relative to project root
407
+ - [x] Output < 2KB typical
408
+
409
+ ### 3.5.4 State Transition Modeling
410
+
411
+ | Current State | Action | New State | Error If Invalid |
412
+ |--------------|--------|-----------|-----------------|
413
+ | No auto-run.json | `focus auto --category cleanup` | initialized | — |
414
+ | No auto-run.json | `focus auto --continue` | — | `"No auto-run in progress. Start with: focus auto --category <name>"` |
415
+ | No auto-run.json | `focus auto --status` | — | `"No auto-run found. Start with: focus auto --category <name>"` |
416
+ | initialized | Workflow starts cycle 1 (--update with cycle data) | in_progress | — |
417
+ | in_progress | Cycle completes, items remain, budget available | in_progress | — |
418
+ | in_progress | Scan finds 0 items matching category | completed (no_items) | — |
419
+ | in_progress | total_points_used >= total_budget | completed (budget_cap) | — |
420
+ | in_progress | cycles_completed >= max_cycles | completed (max_cycles) | — |
421
+ | in_progress | tests_after < tests_before for any cycle | stopped (regression) | — |
422
+ | in_progress | Cycle completes with 0 items completed (PanMonty loop exhaustion) | stopped (zero_completed) | — |
423
+ | in_progress | `focus auto --stop` | stopped (user_stop) | — |
424
+ | in_progress | `focus auto --category X` (new run attempt) | — | `"Auto-run already in progress. Use --stop to end it, or --continue to resume."` |
425
+ | completed | `focus auto --category X` | initialized (new run, old archived) | — |
426
+ | stopped | `focus auto --continue` | in_progress (resumes) | — |
427
+ | stopped | `focus auto --category X` | initialized (new run, old archived) | — |
428
+
429
+ ### 3.5.5 Breaking Change Assessment
430
+
431
+ | Question | Answer |
432
+ |----------|--------|
433
+ | Changes any existing command's output schema? | **No** — all existing focus subcommands unchanged |
434
+ | Changes file formats? | **No** — new auto-run.json is additive; batch-*.json format unchanged |
435
+ | Changes directory structure? | **No** — auto-run.json goes in existing .planning/focus/ |
436
+ | Changes installer output? | **No** — no installer changes needed |
437
+
438
+ **No migration strategy needed.** This is purely additive.
439
+
440
+ ### 3.5.6 Composability Analysis
441
+
442
+ | Interaction | Works? | How |
443
+ |-------------|--------|-----|
444
+ | Output feeds another command | Yes | `focus auto --status` JSON feeds CI/CD status checks |
445
+ | Callable from an agent | Yes | `pan-tools focus auto --category cleanup --max-cycles 3` |
446
+ | Usable in a hook pipeline | Yes | Post-commit hook could trigger `focus auto --status` to check if campaign is running |
447
+ | Works in --raw mode | Yes | Human-readable campaign dashboard: "Cycle 3/5 \| 47/200 pts \| 12 items \| +3 tests" |
448
+ | Composable with existing focus commands | Yes | `focus scan --lean` still works independently; auto-runner calls it internally |
449
+
450
+ ### 3.5.7 Performance Budget
451
+
452
+ | Operation | Cost | Notes |
453
+ |-----------|------|-------|
454
+ | Read auto-run.json (1 × ~5ms) | ~5ms | safeReadFile + JSON.parse |
455
+ | Read config.json (1 × ~5ms) | ~5ms | loadConfig for auto defaults |
456
+ | Validate args (computation) | ~1ms | Enum checks, range checks |
457
+ | Write auto-run.json (1 × ~5ms) | ~5ms | JSON.stringify + writeFileSync |
458
+ | toPosix computation | ~1ms | Path normalization |
459
+ | **Total (cmdFocusAuto)** | **< 20ms** | Well under 500ms budget |
460
+
461
+ Note: Scan/plan/exec are separate CLI invocations (~200ms/~50ms/~100ms respectively), invoked by the workflow .md — NOT by cmdFocusAuto().
462
+
463
+ ### 3.5.8 Cross-Platform Considerations
464
+
465
+ | Platform | Consideration | Mitigation |
466
+ |----------|---------------|------------|
467
+ | Windows | Path separators in auto-run.json | All paths via toPosix() before storage |
468
+ | Windows | CRLF in JSON | JSON.stringify produces LF; consistent |
469
+ | Windows | 260-char path limit | auto-run.json path is ~40 chars — well within |
470
+ | Mac/Linux | Case-sensitive filesystem | All filenames lowercase (session 22 convention) |
471
+ | All | fs.mkdirSync for focus dir | recursive:true (already used in cmdFocusPlan) |
472
+ | All 5 runtimes | Command .md compatibility | Standard frontmatter + allowed_tools format |
473
+
474
+ ---
475
+
476
+ ## Phase 4: Design Synthesis
477
+
478
+ ### 4.1 Guide-Level Explanation (User-Facing)
479
+
480
+ **Focus Auto-Runner** lets you run purpose-driven improvement campaigns with a single command. Instead of manually cycling through scan→plan→exec (15 invocations for a 5-cycle campaign), the auto-runner orchestrates the loop automatically with category-scoped scanning and intelligent stopping.
481
+
482
+ **Example 1: Cleanup Campaign**
483
+ ```
484
+ /pan:focus-auto --category cleanup
485
+ ```
486
+ Scans for cleanup items only (dead code, naming inconsistencies, empty catch blocks, unnecessary aliases, duplication). Plans a budget-constrained batch. Executes with full verification. Loops until no cleanup items remain or defaults are hit (10 cycles max, 500 pts cumulative). Progress saved to `.planning/focus/auto-run.json`.
487
+
488
+ **Example 2: Test Hardening with Limits**
489
+ ```
490
+ /pan:focus-auto --category tests --max-cycles 3 --budget 40
491
+ ```
492
+ Runs up to 3 cycles of test improvements (duplicate tests, tautology assertions, missing coverage, weak assertions, inconsistent patterns). Spends at most 40 points per cycle, 120 points cumulative.
493
+
494
+ **Example 3: Stability Sweep**
495
+ ```
496
+ /pan:focus-auto --category stability --mode bugfix
497
+ ```
498
+ Scans for P0-P2 stability items only (regex bugs, error handling inconsistencies, missing validation, TOCTOU races). Uses bugfix mode (40 pts/cycle, P0→P1→P2 priority order). Stops on regression.
499
+
500
+ **Example 4: Full Sweep (All Categories)**
501
+ ```
502
+ /pan:focus-auto --max-cycles 5 --total-budget 200
503
+ ```
504
+ Runs up to 5 cycles across ALL work categories with a cumulative 200-point budget cap. No category filter — picks highest-priority items regardless of type.
505
+
506
+ **Example 5: Resume After Interruption**
507
+ ```
508
+ /pan:focus-auto --continue
509
+ ```
510
+ Resumes the most recent auto-run from where it left off. Reads progress from auto-run.json. Picks up at the next cycle.
511
+
512
+ **Example 6: Check Progress**
513
+ ```
514
+ /pan:focus-auto --status
515
+ ```
516
+ Shows: `Cycle 3/10 | 87/500 pts | 19 items completed | Tests: 1169 → 1175 (+6) | Category: cleanup`
517
+
518
+ **What it does NOT do:**
519
+ - Does NOT run in the background as a daemon — runs in your current AI session
520
+ - Does NOT create branches or PRs — commits to your current branch per cycle
521
+ - Does NOT skip verification — every cycle runs the full test suite
522
+ - Does NOT modify the 9 behavioral rules — each cycle follows focus-exec exactly
523
+ - Does NOT replace manual focus commands — scan/plan/exec remain independently usable
524
+
525
+ **Error messages you'd see:**
526
+ - `"Category must be one of: cleanup, tests, stability, features, docs"` — invalid category
527
+ - `"Auto-run already in progress. Use --stop to end it, or --continue to resume."` — concurrent run guard
528
+ - `"No auto-run in progress. Start with: focus auto --category <name>"` — --continue with no run
529
+ - `"Cannot start: N tests failing. Fix tests before running auto campaign."` — failing baseline
530
+
531
+ ### 4.2 Reference-Level Explanation (Technical)
532
+
533
+ #### 4.2.1 Command Interface
534
+
535
+ ```
536
+ pan-tools focus auto [--category CAT] [--mode MODE] [--budget N] [--max-cycles N]
537
+ [--total-budget N] [--continue] [--stop] [--status] [--dry-run]
538
+ ```
539
+
540
+ | Flag | Type | Default | Validation |
541
+ |------|------|---------|------------|
542
+ | `--category` | enum | null (all) | Must be: cleanup, tests, stability, features, docs |
543
+ | `--mode` | enum | category-dependent | Must be: bugfix, balanced, features, full |
544
+ | `--budget` | int | 50 | Range: 5-100 |
545
+ | `--max-cycles` | int | 10 | Range: 1-50 |
546
+ | `--total-budget` | int | 500 | Range: 5-5000 |
547
+ | `--continue` | flag | false | Requires existing in_progress or stopped run |
548
+ | `--stop` | flag | false | Requires existing in_progress run |
549
+ | `--status` | flag | false | Returns current run state or error if none |
550
+ | `--dry-run` | flag | false | Shows what would run without executing |
551
+
552
+ #### 4.2.2 Category → Default Mapping (Intelligent Defaults)
553
+
554
+ Each category carries **sensible defaults** so the user doesn't need to specify mode/budget/priority:
555
+
556
+ | Category | Priority Range | Default Mode | Default Budget | Rationale |
557
+ |----------|---------------|--------------|----------------|-----------|
558
+ | `cleanup` | P3-P5 | balanced | 50 | Cleanup is safe, medium-priority internal improvement |
559
+ | `tests` | P2-P5 | balanced | 50 | Test work spans quality (P2) to tooling (P5) |
560
+ | `stability` | P0-P2 | bugfix | 40 | Stability is highest-priority, use conservative budget |
561
+ | `features` | P3-P5 | features | 50 | Features need the features-mode 80/20 allocation |
562
+ | `docs` | P5-P6 | balanced | 30 | Doc work is low-risk, low-priority, small budget |
563
+ | *(all)* | P0-P6 | balanced | 50 | No filter, standard balanced allocation |
564
+
565
+ Explicit flags override category defaults: `--category stability --mode full --budget 60` uses those values, not the stability defaults.
566
+
567
+ #### 4.2.3 Category Filter Implementation
568
+
569
+ The category filter is a **post-filter on collectWorkItems()** — not a separate scan. This reuses 100% of the existing scan infrastructure:
570
+
571
+ ```javascript
572
+ function categoryFilter(items, category) {
573
+ if (!category) return items; // null = no filter
574
+ const range = CATEGORY_PRIORITY_RANGE[category]; // e.g., { min: 3, max: 5 } for cleanup
575
+ return items.filter(item => {
576
+ const idx = PRIORITY_LEVELS.indexOf(item.priority);
577
+ return idx >= range.min && idx <= range.max;
578
+ });
579
+ }
580
+ ```
581
+
582
+ Where `CATEGORY_PRIORITY_RANGE` maps:
583
+ ```javascript
584
+ const CATEGORY_PRIORITY_RANGE = {
585
+ cleanup: { min: 3, max: 5 }, // P3-P5
586
+ tests: { min: 2, max: 5 }, // P2-P5
587
+ stability: { min: 0, max: 2 }, // P0-P2
588
+ features: { min: 3, max: 5 }, // P3-P5
589
+ docs: { min: 5, max: 6 }, // P5-P6
590
+ };
591
+ ```
592
+
593
+ #### 4.2.4 auto-run.json Schema
594
+
595
+ ```json
596
+ {
597
+ "run_id": "auto-2026-03-03-1",
598
+ "status": "in_progress",
599
+ "category": "cleanup",
600
+ "mode": "balanced",
601
+ "budget_per_cycle": 50,
602
+ "max_cycles": 10,
603
+ "total_budget": 500,
604
+ "priority_range": { "min": 3, "max": 5 },
605
+ "tests_baseline": 1169,
606
+ "cycles": [
607
+ {
608
+ "cycle": 1,
609
+ "items_completed": 12,
610
+ "items_failed": 1,
611
+ "points_used": 38,
612
+ "tests_before": 1169,
613
+ "tests_after": 1165,
614
+ "batch_file": ".planning/focus/batch-2026-03-03.json",
615
+ "timestamp": "2026-03-03T14:30:00Z"
616
+ }
617
+ ],
618
+ "totals": {
619
+ "cycles_completed": 1,
620
+ "items_completed": 12,
621
+ "items_failed": 1,
622
+ "points_used": 38,
623
+ "tests_current": 1165
624
+ },
625
+ "stop_reason": null
626
+ }
627
+ ```
628
+
629
+ ### 4.3 Design Decisions
630
+
631
+ | Decision | Adopted From | Rationale | What We Did NOT Copy (and Why) |
632
+ |----------|-------------|-----------|-------------------------------|
633
+ | 5 predefined categories | PanMonty's 5 change categories | Proven concept, covers 95% of real usage, zero configuration | Did NOT copy Cursor's implicit categorization (labels are external, not workflow-native) |
634
+ | Post-filter on existing scan | PAN's collectWorkItems() | Reuses 100% of scan infrastructure, no duplication | Did NOT create per-category scanners (would require 5 separate scan implementations) |
635
+ | Category → default mapping chain | Blue Ocean: REDUCE decision fatigue | `--category cleanup` carries sensible mode/budget/priority defaults | Did NOT require all flags for every invocation (competitors require explicit config) |
636
+ | Workflow orchestrates loop, core manages state | Anthropic's two-phase pattern + ADR-0006 | Core returns data, workflow makes AI decisions | Did NOT put loop in core (workflow needs AI tool access: Read, Bash, git) |
637
+ | Circuit breaker on test regression | PanMonty Phase 7 loop exhaustion guard | 3rd loop entry pattern adapted: any test drop = immediate stop | Did NOT copy Cline's safety-free YOLO mode (user trust requires verification) |
638
+ | Zero-completed-items guard | PanMonty Phase 7 loop exhaustion | If a cycle completes with 0 items done, further cycles won't help | Did NOT allow infinite empty cycles (would waste context without progress) |
639
+ | Per-cycle commits (inherited from focus-exec) | execplan.md 6-stage pipeline | Each cycle is atomic; failure in cycle N doesn't lose cycles 1..N-1 | Did NOT use single final commit (losing all work on late failure) |
640
+ | JSON file for run state | PAN's batch-*.json pattern | Consistent persistence, human-readable, machine-parseable | Did NOT use SQLite (zero-dep constraint), did NOT use state.md (different lifecycle) |
641
+ | Triple safety net | Novel (no competitor) | Per-cycle budget + cumulative budget + max cycles | Did NOT rely on single limit (insufficient for autonomous execution) |
642
+ | auto-run.json in .planning/focus/ | Existing focus directory convention | Co-located with batch-*.json and scan-*.md | Did NOT create new directory (.planning/auto/ would be unnecessary) |
643
+
644
+ ### 4.4 Drawbacks & Alternatives
645
+
646
+ | Decision Point | Chosen | Alternative | Why Not | Drawback of Chosen |
647
+ |----------------|--------|------------|---------|-------------------|
648
+ | 5 fixed categories | Predefined enum | User-defined via config.json | Config complexity, testing surface, low marginal value | Can't add "security" or "performance" categories without code change |
649
+ | Loop in workflow .md | AI orchestrates | Core module runs loop | Core can't invoke git, npm test, AI decisions, file edits | Depends on AI following instructions (mitigated: 9 behavioral rules are battle-tested) |
650
+ | Single auto-run.json | One run at a time | Multiple concurrent runs | Complexity, merge conflicts, git state confusion | Can't run "cleanup" and "tests" simultaneously |
651
+ | Per-cycle commits | Commit after each cycle | Single commit at end | Losing cycles 1..N-1 on failure in cycle N | More commits in git history (mitigated: each commit is self-describing) |
652
+ | No daemon mode | Session-bound execution | Background daemon | Zero-dep constraint, cross-platform daemon complexity | Can't run truly unattended overnight (user must keep session open) |
653
+ | Category as priority-range filter | Post-filter on full scan | Separate scan logic per category | 5x scan code, maintenance burden, inconsistency risk | Categories may include items the user considers "wrong category" (mitigated: priority ranges are based on 25 sessions of real data) |
654
+
655
+ ### 4.5 Feature Ladder (Incremental Delivery)
656
+
657
+ | Version | Scope | Value Delivered | Effort |
658
+ |---------|-------|----------------|--------|
659
+ | **v0 (MVP)** | `cmdFocusAuto()` with init/status/stop/update subcommands + `categoryFilter()` + constants + dispatcher routing + `focus-auto.md` command file | Single-command campaigns with categories, defaults, and run state persistence. Covers SC-1, SC-4, SC-5, SC-7. | M (4 pts) |
660
+ | **v1 (Complete)** | `--continue` resume logic + `--dry-run` preview + `--total-budget` cumulative cap + regression circuit breaker + zero-completed guard + per-cycle stats + campaign summary output | Full production auto-runner with all safety features and diagnostics. Covers SC-2, SC-3, SC-6, SC-8, SC-9. | M (4 pts) |
661
+ | **v2 (Enhanced)** | Config.json `auto` section for persistent defaults + campaign history archiving (past runs in .planning/focus/auto-history/) + aggregate campaign analytics + `focus auto --history` to show past campaigns | Best-in-class campaign management with historical tracking. | L (10 pts) |
662
+
663
+ ### 4.6 Adoption Analysis
664
+
665
+ | Question | Answer |
666
+ |----------|--------|
667
+ | How does the user discover this feature? | Natural progression: after running scan→plan→exec 2+ times, user wants automation. `/pan:help` lists focus-auto. README documents campaign workflow. The command name "auto" is intuitive given "scan", "plan", "exec" are already known. |
668
+ | What's the learning curve? | Minimal — if you know focus-exec, auto is "do it in a loop". One new flag (`--category`) is the key concept. Category names are self-documenting: cleanup, tests, stability, features, docs. |
669
+ | Does it require changing existing workflows? | No. Manual scan→plan→exec continues to work independently. Auto-runner is additive. Users who don't want continuous execution lose nothing. |
670
+ | What's the "aha moment"? | Running `/pan:focus-auto --category cleanup --max-cycles 5` and watching 50+ cleanup items get resolved across 5 cycles with per-cycle commits, test verification, and a final campaign summary — all from one command. The dashboard showing "Cycle 5/5 \| 47 items \| 142 pts \| Tests: 1169→1175 (+6)" makes the value tangible. |
671
+ | What's the "power user moment"? | Discovering that `--category stability --mode bugfix` automatically restricts to P0-P2 items with conservative 40pt budget — no manual flag tuning needed. Category→defaults chain eliminates 80% of flag decisions. |
672
+
673
+ ---
674
+
675
+ ## Phase 5: Architecture Decision Record
676
+
677
+ *See separate file: [ADR-0015-focus-auto-runner.md](../decisions/ADR-0015-focus-auto-runner.md)*
678
+
679
+ ---
680
+
681
+ ## Phase 6: Error Handling & Diagnostics Design
682
+
683
+ ### 6.1 Failure Mode Analysis
684
+
685
+ | Failure Mode | Category | Detection Pattern | Recovery | User Sees |
686
+ |-------------|----------|-------------------|----------|-----------|
687
+ | Tests failing at start | Precondition | npm test fails in workflow | Refuse to start, show failure count | `"Cannot start: N tests failing. Fix tests before running auto campaign."` |
688
+ | Invalid category name | User error | Enum validation in cmdFocusAuto | JSON error with valid options | `"Category must be one of: cleanup, tests, stability, features, docs"` |
689
+ | Budget out of range | User error | Range check (5-100) | JSON error with bounds | `"Budget must be between 5 and 100"` |
690
+ | Max cycles out of range | User error | Range check (1-50) | JSON error with bounds | `"Max cycles must be between 1 and 50"` |
691
+ | Concurrent run attempt | User error | auto-run.json status === 'in_progress' | JSON error with hint | `"Auto-run already in progress. Use --stop to end it, or --continue to resume."` |
692
+ | --continue with no active run | User error | No auto-run.json or status is 'completed' | JSON error with hint | `"No auto-run in progress. Start with: focus auto --category <name>"` |
693
+ | Scan finds 0 items matching category | Normal completion | collectWorkItems → categoryFilter returns [] | Complete with no_items reason | `"No items found for category 'cleanup'. Campaign complete."` |
694
+ | Budget exhausted (cumulative) | Normal completion | total_points_used >= total_budget | Complete current cycle, stop | `"Total budget cap (500 pts) reached after 4 cycles."` |
695
+ | Max cycles reached | Normal completion | cycles_completed >= max_cycles | Stop cleanly | `"Maximum 10 cycles completed. 47 items across 10 cycles."` |
696
+ | Test regression detected | Safety trigger | tests_after < tests_before in any cycle | CIRCUIT BREAKER — stop immediately, preserve state | `"REGRESSION: tests dropped from 1169 to 1165 in cycle 3. Auto-run stopped. Review last cycle."` |
697
+ | Zero completed items in cycle | Loop exhaustion (PanMonty heritage) | Cycle produces 0 completed items | Stop — further cycles won't help | `"Cycle 4 completed 0 items. Stopping — remaining items may need manual review."` |
698
+ | auto-run.json corrupted | Data corruption | JSON.parse fails or required fields missing | Error with recovery hint | `"auto-run.json is corrupted. Delete it and restart with: focus auto --category <name>"` |
699
+ | .planning/ missing | Precondition | planningPath(cwd) not accessible | Error with hint | `".planning directory not found. Run pan-tools init first."` |
700
+ | Disk full on write | Environment | try-catch on writeFileSync | Graceful error, preserve in-memory state | `"Failed to write auto-run.json: ENOSPC. Run completed cycles are preserved in git commits."` |
701
+ | Batch creation fails mid-cycle | Internal | cmdFocusPlan returns error | Log warning, stop run | `"Cycle 3 failed: batch creation error. Run --continue to retry."` |
702
+
703
+ ### 6.2 Diagnostic Support
704
+
705
+ | Diagnostic | How | When |
706
+ |------------|-----|------|
707
+ | `--raw` flag | Human-readable campaign dashboard (one-line summary) | Interactive monitoring |
708
+ | `--status` flag | Full progress JSON with per-cycle breakdown | Mid-campaign check |
709
+ | `--dry-run` flag | Show category defaults, predicted scan scope, but don't execute | Pre-flight check |
710
+ | `--verbose` (inherited) | Per-cycle verbose logging via core.cjs:verbose() | Troubleshooting |
711
+ | auto-run.json | Machine-readable run state with full cycle history | Post-mortem analysis |
712
+ | Per-cycle batch-*.json files | Preserved by focus-plan, one per cycle | Per-cycle item review |
713
+ | Git commits per cycle | Each cycle produces a verifiable commit | Per-cycle code review |
714
+ | stderr via error() | Error details to stderr | Failures |
715
+
716
+ ---
717
+
718
+ ## Phase 7: Security & Threat Model
719
+
720
+ ### 7.1 Asset & Attack Surface Inventory
721
+
722
+ | Asset | Accessed How | Trust Level |
723
+ |-------|-------------|-------------|
724
+ | auto-run.json | Read + Write by cmdFocusAuto | System-generated (PAN creates, PAN reads) |
725
+ | batch-*.json | Read only (created by focus plan) | System-generated |
726
+ | scan-*.md | Read only (created by focus scan) | System-generated |
727
+ | config.json | Read only (loadConfig) | User-editable but PAN-managed |
728
+ | .planning/focus/ directory | Read + Write | PAN-managed subdirectory |
729
+
730
+ | Input Vector | Source | Validation Required |
731
+ |-------------|--------|-------------------|
732
+ | --category flag | User-typed | Strict enum: 5 values + null. No partial matching, no regex. |
733
+ | --budget flag | User-typed | parseInt → range check 5-100. NaN → error. |
734
+ | --max-cycles flag | User-typed | parseInt → range check 1-50. NaN → error. |
735
+ | --total-budget flag | User-typed | parseInt → range check 5-5000. NaN → error. |
736
+ | --mode flag | User-typed | Strict enum: 4 values. From existing FOCUS_MODES constant. |
737
+ | auto-run.json content | Disk (PAN-generated) | JSON.parse in try-catch. Validate: run_id (string), status (enum), cycles (array). |
738
+
739
+ ### 7.2 Path Safety Protocol
740
+
741
+ The auto-runner only reads/writes within `.planning/focus/`. All paths constructed via:
742
+ ```javascript
743
+ path.join(planningPath(cwd), FOCUS_DIR, AUTO_RUN_FILE)
744
+ ```
745
+ No user-supplied path arguments. No path traversal possible. Standard `planningPath(cwd)` + constant filename.
746
+
747
+ ### 7.3 Output Sanitization
748
+
749
+ - [x] No absolute filesystem paths — all paths via toPosix() relative to project root
750
+ - [x] No environment variable values in output
751
+ - [x] No stack traces in error messages — only actionable error text with recovery hints
752
+ - [x] No internal function names in errors — user sees "auto-run.json is corrupted" not "JSON.parse failed at readAutoRun:14"
753
+
754
+ ### 7.4 Content Validation
755
+
756
+ - auto-run.json: `JSON.parse()` in try-catch. Validate required fields: `run_id` (string), `status` (enum of 5 values), `cycles` (array). Missing/malformed → return null, error with recovery hint.
757
+ - batch-*.json: Already validated by existing `readLatestBatch()` (returns null on malformation)
758
+ - config.json: Already validated by existing `loadConfig()` (returns defaults on failure)
759
+ - No `eval()`, no `Function()`, no template string injection
760
+
761
+ ### 7.5 Privilege Scope Declaration
762
+
763
+ ```
764
+ Reads from: .planning/focus/ (auto-run.json, batch-*.json, scan-*.md)
765
+ .planning/ (state.md, config.json, roadmap.md, patterns.md, todos/)
766
+ Writes to: .planning/focus/auto-run.json ONLY
767
+ (batch-*.json written by focus plan, not by auto)
768
+ Executes shell: No (git, npm test are delegated to workflow .md, not core)
769
+ Reads outside project: No
770
+ Accesses network: No
771
+ ```
772
+
773
+ ---
774
+
775
+ ## Phase 8: Implementation Roadmap
776
+
777
+ ### 8.1 Command .md Definition (DRAFT)
778
+
779
+ ```markdown
780
+ ---
781
+ command: focus-auto
782
+ group: Focus
783
+ description: Continuous categorized execution — automated scan-plan-exec loop
784
+ allowed_tools: Read, Write, Edit, Bash, Grep, Glob, Agent
785
+ ---
786
+
787
+ # /pan:focus-auto — Continuous Categorized Execution Pipeline
788
+
789
+ Run purpose-driven improvement campaigns with automated scan-plan-exec cycling.
790
+
791
+ ## Quick Start
792
+ /pan:focus-auto --category cleanup # cleanup campaign
793
+ /pan:focus-auto --category tests --max-cycles 3 # test hardening, 3 cycles
794
+ /pan:focus-auto --category stability --mode bugfix # stability sweep
795
+ /pan:focus-auto --continue # resume interrupted run
796
+ /pan:focus-auto --status # check progress
797
+
798
+ ## Flags
799
+ --category CAT Scope: cleanup, tests, stability, features, docs (default: all)
800
+ --mode MODE Allocation: bugfix, balanced, features, full (default: category-dependent)
801
+ --budget N Points per cycle, 5-100 (default: category-dependent)
802
+ --max-cycles N Maximum iterations, 1-50 (default: 10)
803
+ --total-budget N Cumulative points cap, 5-5000 (default: 500)
804
+ --continue Resume interrupted run
805
+ --stop Gracefully stop current run
806
+ --status Show progress dashboard
807
+ --dry-run Preview without executing
808
+
809
+ ## Category Definitions
810
+ | Category | Scans For | Priority | Default Mode | Default Budget |
811
+ |-----------|------------------------------------------------------------------------|----------|-------------|----------------|
812
+ | cleanup | Dead code, naming, aliases, inline requires, empty catches, duplication| P3-P5 | balanced | 50 pts |
813
+ | tests | Duplicate tests, tautologies, missing coverage, weak assertions | P2-P5 | balanced | 50 pts |
814
+ | stability | Regex bugs, error handling, missing validation, TOCTOU, unsafe ops | P0-P2 | bugfix | 40 pts |
815
+ | features | Incomplete commands, missing flags, roadmap TODOs | P3-P5 | features | 50 pts |
816
+ | docs | Stale counts, missing docs, outdated references | P5-P6 | balanced | 30 pts |
817
+
818
+ ## Auto-Run Loop Protocol
819
+
820
+ ### Initialization
821
+ 1. Run `pan-tools focus auto [flags]` to create run state
822
+ 2. Record test baseline with `npm test` — if tests fail, STOP
823
+ 3. Create rollback snapshot (git tag)
824
+
825
+ ### Loop (repeat until stopping condition)
826
+ For each cycle N:
827
+ 1. **SCAN**: `/pan:focus-scan` — collect all items, apply category filter
828
+ 2. **CHECK**: If 0 items match category → stop (no_items)
829
+ 3. **PLAN**: `/pan:focus-plan --mode MODE --budget N` — create batch from filtered items
830
+ 4. **CHECK**: If total_points_used + allocated > total_budget → stop (budget_cap)
831
+ 5. **EXEC**: `/pan:focus-exec` — full 6-stage pipeline (all 9 behavioral rules apply)
832
+ 6. **VERIFY**: Compare tests_after vs tests_before — if regression → CIRCUIT BREAKER STOP
833
+ 7. **CHECK**: If 0 items completed in this cycle → stop (zero_completed)
834
+ 8. **UPDATE**: `pan-tools focus auto --update` with cycle results
835
+ 9. **CHECK**: If cycles_completed >= max_cycles → stop (max_cycles)
836
+ 10. **CONTINUE**: Loop to next cycle
837
+
838
+ ### Stopping Conditions (ANY triggers stop)
839
+ | Condition | Detection | Reason |
840
+ |------------------------|----------------------------------------------|-----------------|
841
+ | No items found | Category filter returns 0 items | no_items |
842
+ | Budget exhausted | total_points_used >= total_budget | budget_cap |
843
+ | Max cycles reached | cycles_completed >= max_cycles | max_cycles |
844
+ | Test regression | tests_after < tests_before in ANY cycle | regression |
845
+ | Zero items completed | Cycle completed but 0 items done | zero_completed |
846
+ | User stop | /pan:focus-auto --stop | user_stop |
847
+
848
+ ### Completion
849
+ 1. Write final auto-run.json with all cycle stats
850
+ 2. Output campaign summary dashboard
851
+
852
+ ## AI Behavioral Rules (extends focus-exec)
853
+ 1. ALL 9 focus-exec rules apply within each cycle
854
+ 2. Between cycles: ALWAYS check ALL stopping conditions
855
+ 3. NEVER skip verification between cycles
856
+ 4. Category scope MUST be maintained — do not fix items outside the category
857
+ 5. If scan returns items but plan allocates 0 (budget mismatch), stop
858
+ 6. Each cycle MUST produce a git commit (per focus-exec Stage 6)
859
+ ```
860
+
861
+ ### 8.2 Implementation Tasks (Ordered)
862
+
863
+ #### Task 1: Add auto-runner constants to constants.cjs
864
+ **Files**: [constants.cjs](../../pan-wizard-core/bin/lib/constants.cjs)
865
+ **Changes**: Add `FOCUS_CATEGORIES` (array of 5 strings), `CATEGORY_PRIORITY_RANGE` (object mapping category→{min,max}), `CATEGORY_DEFAULTS` (object mapping category→{mode,budget}), `AUTO_RUN_FILE` ('auto-run.json'), `DEFAULT_MAX_CYCLES` (10), `DEFAULT_TOTAL_BUDGET` (500)
866
+ **Test**: `npm test -- --test-name-pattern constants`
867
+ **Estimate**: XS (1 pt)
868
+ **Priority**: P3
869
+
870
+ #### Task 2: Add categoryFilter() to focus.cjs
871
+ **Files**: [focus.cjs](../../pan-wizard-core/bin/lib/focus.cjs)
872
+ **Changes**: Add `categoryFilter(items, category)` pure function. Import `CATEGORY_PRIORITY_RANGE` from constants. Export it for testing.
873
+ **Test**: `npm test -- --test-name-pattern focus`
874
+ **Estimate**: XS (1 pt)
875
+ **Priority**: P3
876
+
877
+ #### Task 3: Add readAutoRun() / writeAutoRun() to focus.cjs
878
+ **Files**: [focus.cjs](../../pan-wizard-core/bin/lib/focus.cjs)
879
+ **Changes**: Add `readAutoRun(cwd)` (reads and validates .planning/focus/auto-run.json, returns parsed JSON or null) and `writeAutoRun(cwd, data)` (writes auto-run.json with try-catch, returns {written: true} or {error}). Both use planningPath + FOCUS_DIR + AUTO_RUN_FILE.
880
+ **Test**: `npm test -- --test-name-pattern focus`
881
+ **Estimate**: S (2 pts)
882
+ **Priority**: P3
883
+
884
+ #### Task 4: Add cmdFocusAuto() to focus.cjs
885
+ **Files**: [focus.cjs](../../pan-wizard-core/bin/lib/focus.cjs)
886
+ **Changes**: Add `cmdFocusAuto(cwd, raw, ...args)` function handling subcommands: init (default), --status, --stop, --continue, --update. Uses getArgValue for flag parsing. Validates category enum, budget range, max-cycles range. Creates/reads/updates auto-run.json via readAutoRun/writeAutoRun. Export it.
887
+ **Test**: `npm test -- --test-name-pattern focus`
888
+ **Estimate**: M (4 pts)
889
+ **Priority**: P3
890
+
891
+ #### Task 5: Add dispatcher routing for 'auto'
892
+ **Files**: [pan-tools.cjs](../../pan-wizard-core/bin/pan-tools.cjs)
893
+ **Changes**: Add `} else if (subcommand === 'auto') { focus.cmdFocusAuto(cwd, raw, ...args.slice(2)); }` to the focus switch block. Update the error message to include 'auto' in the Available list.
894
+ **Test**: `npm test -- --test-name-pattern dispatcher`
895
+ **Estimate**: XS (1 pt)
896
+ **Priority**: P3
897
+
898
+ #### Task 6: Write focus-auto.md command file
899
+ **Files**: `.claude/commands/pan/focus-auto.md` (new)
900
+ **Changes**: Create the full command file (from 8.1 draft above). Include frontmatter, category table, loop protocol, stopping conditions, behavioral rules.
901
+ **Test**: Manual invocation test
902
+ **Estimate**: S (2 pts)
903
+ **Priority**: P3
904
+
905
+ #### Task 7: Add unit + integration tests
906
+ **Files**: [focus.test.cjs](../../tests/focus.test.cjs)
907
+ **Changes**: Add test suites for: categoryFilter (7 tests: one per category + null + empty), readAutoRun/writeAutoRun (4 tests: round-trip, missing, malformed, missing dir), cmdFocusAuto init (3 tests: valid, invalid category, concurrent guard), cmdFocusAuto --status (2 tests: with/without run), cmdFocusAuto --stop (2 tests: active/no run), cmdFocusAuto --update (2 tests: valid cycle, no run), cmdFocusAuto --continue (2 tests: stopped run, no run). Total: ~22 new tests.
908
+ **Test**: `npm test -- --test-name-pattern focus`
909
+ **Estimate**: M (4 pts)
910
+ **Priority**: P2
911
+
912
+ #### Task 8: Add config.json auto section defaults
913
+ **Files**: [config.cjs](../../pan-wizard-core/bin/lib/config.cjs)
914
+ **Changes**: Add `auto` section to loadConfig with keys: default_category (null), default_max_cycles (10), default_total_budget (500). Follow existing pattern of explicit section return + catch fallback.
915
+ **Test**: `npm test -- --test-name-pattern config`
916
+ **Estimate**: XS (1 pt)
917
+ **Priority**: P5
918
+
919
+ #### Task 9: Doc sync (README, CLI-REF, CHANGELOG, USER-GUIDE)
920
+ **Files**: README.md, docs/CLI-REFERENCE.md, CHANGELOG.md, docs/USER-GUIDE.md
921
+ **Changes**: Add focus auto command documentation, category table, campaign workflow examples. Update command count from 41 to 42 (or 91 to 92 subcommands).
922
+ **Test**: `/pan:focus-sync --all`
923
+ **Estimate**: S (2 pts)
924
+ **Priority**: P6
925
+
926
+ ### 8.3 Dependency Graph
927
+
928
+ ```
929
+ Task 1 (constants) ──┬──→ Task 2 (categoryFilter) ──→ Task 4 (cmdFocusAuto) ──→ Task 5 (dispatcher)
930
+ │ │ │
931
+ └──→ Task 3 (read/writeAutoRun) ────────┘ │
932
+ │ ↓
933
+ ├──→ Task 7 (tests) Task 6 (command .md)
934
+ │ │
935
+ └──→ Task 8 (config) Task 9 (docs)
936
+ ```
937
+
938
+ **Critical path**: Task 1 → Task 2 → Task 4 → Task 5 (dispatcher wiring unlocks CLI testing)
939
+ **Total**: 9 tasks, **18 points** (1+1+2+4+1+2+4+1+2)
940
+ **Estimated effort**: 2 focus-exec cycles at balanced mode
941
+
942
+ ### 8.4 Risk Register
943
+
944
+ | Risk | Probability | Impact | Mitigation |
945
+ |------|------------|--------|------------|
946
+ | AI doesn't follow loop instructions | Medium | High — too many/few cycles | Max-cycles hard limit (default 10), circuit breaker, zero-completed guard |
947
+ | Category filter too broad | Low | Medium — includes irrelevant items | Priority ranges derived from 25 sessions of real data |
948
+ | Category filter too narrow | Low | Medium — misses relevant items | User can omit --category for unfiltered mode |
949
+ | auto-run.json corruption mid-write | Low | Medium — lost progress | try-catch + per-cycle git commits preserve all completed work |
950
+ | Concurrent runs from different sessions | Low | Medium — race condition | Concurrent guard: check status === 'in_progress' before init |
951
+ | Runaway execution | Very Low | High — unwanted changes | Triple safety net: per-cycle budget + total budget + max cycles + regression circuit breaker + zero-completed guard = 5 independent stopping mechanisms |
952
+ | Category defaults don't match user expectations | Low | Low — user overrides with flags | Explicit flags always override category defaults; docs clearly show defaults |
953
+
954
+ ### 8.5 Cognitive Complexity Budget
955
+
956
+ | Function | Lines | Nesting | Params | Status |
957
+ |----------|-------|---------|--------|--------|
958
+ | `categoryFilter()` | ~10 | 1 | 2 | Within budget |
959
+ | `readAutoRun()` | ~12 | 2 | 1 | Within budget |
960
+ | `writeAutoRun()` | ~10 | 2 | 2 | Within budget |
961
+ | `cmdFocusAuto()` | ~45 | 3 | 3 | At budget (standard cmd* pattern) |
962
+ | Total new code | ~77 | — | — | Modest addition to 559-line module |
963
+
964
+ ---
965
+
966
+ ## Phase 9: Test Plan
967
+
968
+ ### 9.1 Test Pyramid
969
+
970
+ | Level | Pattern | Count | What It Catches |
971
+ |-------|---------|-------|-----------------|
972
+ | **Unit** | categoryFilter, readAutoRun, writeAutoRun, arg parsing, defaults | 14+ | Logic bugs, category boundaries, state serialization, enum validation |
973
+ | **Integration** | `pan-tools focus auto` CLI with real filesystem | 8+ | Wiring bugs, arg parsing, JSON output, file persistence, concurrent guard |
974
+ | **E2E** | Multi-command auto-run lifecycle | 3+ | State transitions, stopping conditions, cycle recording |
975
+ | **Total** | | **25+** | |
976
+
977
+ ### 9.2 Unit Tests (14 minimum)
978
+
979
+ ```
980
+ categoryFilter:
981
+ 1. cleanup category returns only P3-P5 items
982
+ 2. tests category returns only P2-P5 items
983
+ 3. stability category returns only P0-P2 items
984
+ 4. features category returns only P3-P5 items
985
+ 5. docs category returns only P5-P6 items
986
+ 6. null category returns all items (no filter)
987
+ 7. empty items array returns empty array
988
+
989
+ readAutoRun / writeAutoRun:
990
+ 8. writes and reads back valid run state (round-trip)
991
+ 9. readAutoRun returns null for missing file
992
+ 10. readAutoRun returns null for malformed JSON
993
+ 11. readAutoRun returns null when .planning/focus/ doesn't exist
994
+ 12. writeAutoRun creates focus dir if missing (mkdirSync recursive)
995
+
996
+ cmdFocusAuto defaults:
997
+ 13. --category cleanup sets mode=balanced, budget=50, priority P3-P5
998
+ 14. --category stability sets mode=bugfix, budget=40, priority P0-P2
999
+ ```
1000
+
1001
+ ### 9.3 Integration Tests (8 minimum)
1002
+
1003
+ ```
1004
+ focus auto init:
1005
+ 1. creates auto-run.json with correct fields (run_id, status=initialized, category, etc.)
1006
+ 2. returns initialized status JSON
1007
+ 3. rejects invalid category name with error
1008
+ 4. rejects when auto-run already in_progress (concurrent guard)
1009
+
1010
+ focus auto --status:
1011
+ 5. returns run progress from auto-run.json
1012
+ 6. returns error when no active run
1013
+
1014
+ focus auto --stop:
1015
+ 7. updates status to stopped, stop_reason=user_stop
1016
+
1017
+ focus auto --continue:
1018
+ 8. loads existing stopped run and returns in_progress status
1019
+ ```
1020
+
1021
+ ### 9.4 E2E Tests (3 minimum)
1022
+
1023
+ ```
1024
+ 1. init → update with cycle data → status shows cycle recorded → update with completion → status shows completed
1025
+ 2. init with --max-cycles 1 → update with 1 cycle → auto shows max_cycles stop reason
1026
+ 3. init → stop → continue → status shows in_progress (full lifecycle)
1027
+ ```
1028
+
1029
+ ### 9.5 Assertion Density Requirements
1030
+
1031
+ Every test asserts AT MINIMUM:
1032
+ - **Success tests**: (a) `result.success === true`, (b) `output` has expected shape (2+ field checks), (c) no `error` field in parsed output
1033
+ - **Error tests**: (a) `output.error` is a string with actionable message, (b) no auto-run.json corruption (check file wasn't partially written), (c) exit code is 1
1034
+
1035
+ ### 9.6 Boundary Value Analysis
1036
+
1037
+ - [x] Empty project (no .planning/) → error with init hint
1038
+ - [x] Minimal project (empty .planning/focus/) → creates auto-run.json successfully
1039
+ - [x] Budget = 5 (minimum) → only picks XS items
1040
+ - [x] Budget = 100 (maximum) → respects limit
1041
+ - [x] Max cycles = 1 → exactly 1 cycle
1042
+ - [x] Total budget = 5 → may stop mid-first-cycle
1043
+ - [x] Malformed auto-run.json → error with recovery hint, no crash
1044
+ - [x] --continue with completed run → error
1045
+ - [x] --continue with stopped run → success (resumes)
1046
+ - [x] Concurrent init attempt (status=in_progress) → error with hint
1047
+ - [x] All 5 categories individually tested for correct priority filtering
1048
+ - [x] null category (no --category flag) → all items, no filtering
1049
+
1050
+ ### 9.7 Regression Verification
1051
+
1052
+ - [x] Full suite passes: `npm test` (1169 tests, 0 failures)
1053
+ - [x] focus.test.cjs existing 73 tests still pass
1054
+ - [x] constants.test.cjs existing tests still pass
1055
+ - [x] config.test.cjs existing tests still pass
1056
+ - [x] dispatcher.test.cjs existing tests still pass
1057
+ - [x] No existing test expectations changed
1058
+
1059
+ ---
1060
+
1061
+ ## Phase 10: Output Artifacts
1062
+
1063
+ ### 10.1 Specification Document
1064
+ Saved to: `docs/specs/focus_auto_runner_featureai.md` (this file, v2 deep rewrite)
1065
+
1066
+ ### 10.2 ADR
1067
+ Saved to: `docs/decisions/ADR-0015-focus-auto-runner.md` (v2 deep rewrite)
1068
+
1069
+ ### 10.3 Competitive Research
1070
+ Preserved at: `docs/specs/continuous_autonomous_execution_featureai.md` (8-tool analysis)
1071
+
1072
+ ### 10.4 Report Summary
1073
+
1074
+ **Problem & Evidence**: Manual 3-command cycling limits improvement campaigns. Quantified: sessions 24-25 ran 44 items across 2 manual cycles in one day. 5 evidence sources (user request, internal usage ×2, competitor convergence, PanMonty heritage).
1075
+
1076
+ **Strategic Assessment**:
1077
+ - Blue Ocean: CREATE purpose-driven campaigns with category→defaults chain (first in industry). ELIMINATE manual cycling overhead (15 invocations → 1). REDUCE decision fatigue (category carries mode/budget/priority defaults).
1078
+ - Wardley: Continuous execution → Product (table-stakes). Categorization → Genesis (first-mover). Budget awareness → Custom-Built (unique to PAN).
1079
+ - Moat Score: **35/35** — maximum across all 7 dimensions
1080
+ - Cognitive Load: **-1 (net simplification)** despite +1 command and +2 concepts
1081
+ - Recommendation: **BUILD IMMEDIATELY** — strongest strategic alignment of any proposed feature
1082
+
1083
+ **Design Summary**: Workflow-orchestrated continuous loop with core state management. 5 purpose categories (cleanup, tests, stability, features, docs) with category→default mapping chain. Triple safety net + regression circuit breaker + zero-completed guard (5 independent stopping mechanisms). Inherits ALL infrastructure: budget system (execplan heritage, 25 sessions proven), 9 behavioral rules, 6-stage pipeline, 4 allocation modes, P0-P6 priorities, RS scoring. No new modules.
1084
+
1085
+ **Heritage Chain**: execplan.md → superplan.md → focus-scan/plan/exec (ADR-0006) → PanMonty categories → **focus-auto** (this feature)
1086
+
1087
+ **Feature Ladder**:
1088
+ | Version | Effort | Value |
1089
+ |---------|--------|-------|
1090
+ | v0 (MVP) | M (4 pts) | Core function + category filter + command .md + dispatcher |
1091
+ | v1 (Complete) | M (4 pts) | --continue, --stop, --status, --dry-run, circuit breaker, all guards |
1092
+ | v2 (Enhanced) | L (10 pts) | Config defaults, campaign history, aggregate analytics |
1093
+
1094
+ **Implementation**: 9 tasks, 18 total points, 2 estimated focus-exec cycles. Critical path: constants → categoryFilter → cmdFocusAuto → dispatcher.
1095
+
1096
+ **Test Plan**: 25+ tests (14 unit, 8 integration, 3 E2E). Assertion density enforced. Boundary analysis covers all 5 categories, all edge cases.
1097
+
1098
+ **Security**: Minimal surface — reads/writes .planning/focus/ only. No shell execution from core. No user-supplied paths. Strict enum validation on all inputs. 6 validated fields in auto-run.json schema.
1099
+
1100
+ **Adoption**: "aha moment" = watching 50+ items resolved across 5 automated cycles. Power-user moment = discovering category→defaults chain eliminates manual flag tuning.
1101
+
1102
+ **Next Steps**: Implement v0+v1 via 2 focus-exec cycles, estimated 18 points across 9 tasks.