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,486 @@
1
+ # Feature Specification: Internal Cleanup & Code Quality Hardening
2
+
3
+ **Mode:** `--internal` (skip competitive intelligence)
4
+ **Date:** 2026-03-03
5
+ **Status:** Ready for Implementation
6
+
7
+ ---
8
+
9
+ ## Phase 0: Problem Framing
10
+
11
+ ### 0.1 Problem Statement
12
+
13
+ PAN Wizard's 15 core modules (4,770+ LOC), CLI dispatcher (735+ LOC), and installer (2,636 LOC) have accumulated technical debt across 23 development sessions. While the codebase is functionally correct (1,180 tests, 0 failures), a deep audit reveals ~170 issues including: duplicate functions across modules, functions exceeding 50-line complexity budgets, missing argument validation in the dispatcher, inconsistent error handling patterns, dead/unused code, and scattered magic numbers. These issues increase maintenance cost, slow onboarding for contributors, and create surface area for future bugs.
14
+
15
+ ### 0.2 Demand Evidence
16
+
17
+ | Evidence Type | Source | Finding |
18
+ |--------------|--------|---------|
19
+ | Internal audit | 5 parallel scan agents | 170+ issues found across all modules (0 P0, 4 P1, 26 P2, 62 P3, 49 P4, 29 P5) |
20
+ | Memory file | MEMORY.md | 23 sessions of accumulated patterns documented; stability patterns applied iteratively but never holistically |
21
+ | User request | This conversation | User explicitly asked for "internal cleanup and review and optimisations, scan all code and make sure everything is perfect" |
22
+ | Architecture docs | ARCHITECTURE.md | Cognitive complexity budget defined (50 lines, 3 nesting, 4 params) but 12+ functions exceed it |
23
+
24
+ ### 0.3 Scope Definition
25
+
26
+ | In Scope | Out of Scope (and why) |
27
+ |----------|------------------------|
28
+ | Dead code removal | New features (this is cleanup only) |
29
+ | Function complexity reduction (>50 LOC) | Installer refactoring to strategy pattern (too large, separate effort) |
30
+ | Duplicate function consolidation | Test file style unification (test vs it, assert vs assert/strict — cosmetic) |
31
+ | Missing argument validation in dispatcher | Performance optimization of file I/O (already fast enough) |
32
+ | Magic number extraction to constants | Documentation rewrites (already synced in prior session) |
33
+ | Unused import cleanup | |
34
+ | Consistent error handling patterns | |
35
+
36
+ ### 0.4 Success Criteria
37
+
38
+ ```
39
+ SC-1: All 15 core modules have zero functions exceeding 50 lines
40
+ SC-2: Zero duplicate functions across modules (getArchivedPhaseDirs consolidated)
41
+ SC-3: All dispatcher argument access has bounds validation (args[idx+1] checked)
42
+ SC-4: Zero dead code (unused imports, unused exports, unreachable branches)
43
+ SC-5: All magic numbers extracted to constants.cjs
44
+ SC-6: No test regressions — 1180/1180 tests still pass
45
+ SC-7: No new runtime dependencies added
46
+ ```
47
+
48
+ ### 0.5 Cannibalization Check
49
+
50
+ | Existing Command/Agent | Overlap? | Impact |
51
+ |-----------------------|----------|--------|
52
+ | `/pan:health --repair` | Partial | Health checks .planning/ integrity, not code quality — no conflict |
53
+ | `/pan:focus-scan` | None | Scans work items, not code quality |
54
+ | Tests | None | Tests verify behavior, this fixes internals |
55
+
56
+ ### 0.6 Cognitive Load Assessment
57
+
58
+ | Metric | Before | After | Delta |
59
+ |--------|--------|-------|-------|
60
+ | Commands a new user must learn | 41 | 41 | 0 |
61
+ | New concepts introduced | 0 | 0 | 0 |
62
+ | Score | — | — | simplifies (-1) |
63
+
64
+ ---
65
+
66
+ ## Phase 1: Internal Reconnaissance — Audit Results
67
+
68
+ ### 1.1 Consolidated Issue Inventory
69
+
70
+ **Total issues found: ~170 across 5 parallel audits**
71
+
72
+ | Module Group | P1 | P2 | P3 | P4 | P5 | Total |
73
+ |-------------|----|----|----|----|----|----|
74
+ | Core 1-5 (constants, core, utils, frontmatter, config) | 1 | 5 | 8 | 12 | 1 | 27 |
75
+ | Core 6-10 (state, init, phase, roadmap, verify) | 0 | 11 | 28 | 9 | 4 | 52 |
76
+ | Core 11-15 (milestone, commands, template, context-budget, focus) | 0 | 6 | 14 | 16 | 7 | 43 |
77
+ | Dispatcher + Tests | 2 | 6 | 6 | 8 | 4 | 26 |
78
+ | Installer | 1 | 7 | 8 | 5 | 1 | 22 |
79
+ | **TOTAL** | **4** | **35** | **64** | **50** | **17** | **170** |
80
+
81
+ ### 1.2 Top Findings by Category
82
+
83
+ #### A. Dead Code (13 items)
84
+ 1. **core.cjs:216** — `execFileSync` re-imported inside `execGit()` (already at top, line 7)
85
+ 2. **milestone.cjs:7** — `isSummaryFile` imported but never used in module
86
+ 3. **phase.cjs:887** — `phaseName` param in `markPhaseCompleteInRoadmap()` documented as unused
87
+ 4. **phase.cjs:990** — `totalPhases` param in `updateStateAfterPhaseComplete()` documented as unused
88
+ 5. **pan-tools.cjs:662** — `core.cjs` re-required inside focus/design case block
89
+
90
+ #### B. Duplicate Functions (3 items)
91
+ 1. **core.cjs:388 vs utils.cjs:130** — `getArchivedPhaseDirs()` vs `listArchivedPhaseDirs()` are nearly identical (33 vs 38 LOC)
92
+ 2. **config.cjs:372-383 vs 528-534** — Standards section parsing logic duplicated
93
+ 3. **commands.cjs:473-485** — `parseDecisions()` inline instead of module-level like similar helpers
94
+
95
+ #### C. Functions Exceeding 50 Lines (12 items)
96
+ 1. **config.cjs:21-106** — `cmdConfigEnsureSection()` — 86 lines
97
+ 2. **config.cjs:462-554** — `cmdStandardsPhaseTrack()` — 93 lines
98
+ 3. **core.cjs:123-186** — `loadConfig()` — 64 lines
99
+ 4. **commands.cjs:320-446** — `cmdCommit()` — 127 lines
100
+ 5. **commands.cjs:682-754** — `renderHealthReport()` — 73 lines
101
+ 6. **focus.cjs:234-332** — `allocateBudget()` — 99 lines
102
+ 7. **frontmatter.cjs:223-295** — `parseMustHavesBlock()` — 73 lines
103
+ 8. **phase.cjs:536-587** — `renumberDecimalPhases()` — 52 lines
104
+ 9. **phase.cjs:602-667** — `renumberIntegerPhases()` — 66 lines
105
+ 10. **verify.cjs:25-119** — `cmdVerifySummary()` — 95 lines
106
+ 11. **verify.cjs:738-804** — `checkPhaseContents()` — 67 lines
107
+ 12. **verify.cjs:930-996** — `cmdValidateHealth()` — 67 lines
108
+
109
+ #### D. Missing Argument Validation (11 dispatcher locations)
110
+ - pan-tools.cjs lines 225, 303, 330, 332, 355, 437, 455, 467, 478, 497, 621
111
+ - Pattern: `args[1]` or `args[2]` accessed without undefined check before passing to cmd functions
112
+
113
+ #### E. Magic Numbers Not in Constants (15+ items)
114
+ - focus.cjs: budget limits 40/60, ratios 0.6/0.8
115
+ - template.cjs: thresholds 2/3/5/6
116
+ - context-budget.cjs: CHARS_PER_TOKEN = 4
117
+ - commands.cjs: DEFAULT_SENSITIVE_PATTERNS array
118
+ - verify.cjs: health status strings ('broken', 'degraded', 'healthy')
119
+
120
+ #### F. Inconsistent Patterns (20+ items)
121
+ - Error handling: some functions use `error()`, others `output({error: ...})`
122
+ - State mutation: `cmdStateJson()` rebuilds state as a side effect
123
+ - Regex global state: `PHASE_HEADER_RE.lastIndex = 0` reset required in multiple places
124
+ - Flag parsing: 44 separate `indexOf()` calls with no shared helper
125
+
126
+ ### 1.3 Convention Enforcement Checklist
127
+
128
+ - [x] Function naming: `cmd*` for entry points, camelCase for helpers — **CONSISTENT**
129
+ - [x] File reads: try-catch pattern — **CONSISTENT (zero existsSync in core)**
130
+ - [x] File writes: try-catch wrapping — **CONSISTENT**
131
+ - [x] JSON output via `output()` — **CONSISTENT**
132
+ - [x] Errors via `error()` — **MOSTLY CONSISTENT** (some use `output({error:...})`)
133
+ - [x] Paths through `toPosix()` — **CONSISTENT**
134
+ - [x] Module exports at bottom — **CONSISTENT**
135
+ - [x] CommonJS format — **CONSISTENT**
136
+ - [x] Zero runtime deps — **MAINTAINED**
137
+ - [ ] Functions under 50 lines — **12 VIOLATIONS**
138
+ - [ ] Max 3 nesting levels — **~8 VIOLATIONS**
139
+ - [ ] Max 4 parameters — **~5 VIOLATIONS**
140
+
141
+ ---
142
+
143
+ ## Phase 3: Strategic Analysis
144
+
145
+ ### 3.1 Blue Ocean Four Actions Framework
146
+
147
+ | Action | Decisions |
148
+ |--------|-----------|
149
+ | **ELIMINATE** | Duplicate functions (getArchivedPhaseDirs x2), dead imports, unused params, re-required modules |
150
+ | **REDUCE** | Function complexity (12 functions over 50 lines), dispatcher arg parsing duplication (44 indexOf calls), magic numbers scattered across 6 modules |
151
+ | **RAISE** | Code consistency (error handling patterns, argument validation, naming), maintainability (extract helpers, reduce nesting) |
152
+ | **CREATE** | `getArgValue()` dispatcher helper, extracted standards parsing helper, consolidated archive search |
153
+
154
+ ### 3.2 Strategic Moat Analysis
155
+
156
+ | Moat Type | Contribution | Score (0-5) |
157
+ |-----------|-------------|-------------|
158
+ | Context Engineering | No change | 0 |
159
+ | Cross-Platform | Stronger (fewer fragile patterns) | 1 |
160
+ | Developer Experience | No user-facing change | 0 |
161
+ | Zero Dependencies | Maintained | 0 |
162
+ | State Persistence | No change | 0 |
163
+ | Verification Quality | Stronger (fewer internal bugs possible) | 1 |
164
+ | **Maintainability** | **Significantly improved** | **4** |
165
+
166
+ ### 3.3 Strategic Recommendation
167
+
168
+ **Build.** This is pure internal quality improvement with zero user-facing risk. The codebase is functionally sound (1,180 tests prove it) but 12 functions exceed the project's own 50-line complexity budget, 3 functions are duplicated across modules, and the dispatcher has 11 unvalidated argument accesses. Fixing these reduces maintenance cost, makes the codebase more approachable for contributors, and prevents future bugs from accumulating in complex functions. Delivery should be incremental — dead code first, then duplication, then complexity reduction — each independently testable.
169
+
170
+ ---
171
+
172
+ ## Phase 3.5: Architecture Assessment
173
+
174
+ ### 3.5.1 Feature Type: Core Enhancement
175
+ All changes are internal to existing modules. No new commands, agents, workflows, or hooks.
176
+
177
+ ### 3.5.2 Layer Violation Check
178
+ - [x] No new commands calling core directly
179
+ - [x] No new upward dependencies
180
+ - [x] All changes stay within Layer 4 (Core Library) and dispatcher
181
+
182
+ ### 3.5.3 Breaking Change Assessment
183
+ | Question | Answer |
184
+ |----------|--------|
185
+ | Changes any existing command's output schema? | **No** |
186
+ | Changes file formats? | **No** |
187
+ | Changes directory structure? | **No** |
188
+ | Changes installer output? | **No** |
189
+
190
+ **Zero breaking changes. All internal refactoring.**
191
+
192
+ ---
193
+
194
+ ## Phase 4: Design Synthesis
195
+
196
+ ### 4.1 Guide-Level Explanation
197
+
198
+ This is an internal cleanup with no user-facing changes. After completion:
199
+ - The same 41 commands work identically
200
+ - The same 93 CLI subcommands produce identical output
201
+ - The same 1,180 tests pass
202
+ - The codebase is cleaner, more consistent, and easier to maintain
203
+
204
+ ### 4.2 Feature Ladder
205
+
206
+ | Version | Scope | Value | Effort |
207
+ |---------|-------|-------|--------|
208
+ | **v0 (Wave 1)** | Dead code removal + unused imports | Cleaner codebase, smaller surface area | XS (5 pts) |
209
+ | **v1 (Wave 2)** | Duplicate consolidation + magic numbers to constants | Single source of truth | S (10 pts) |
210
+ | **v2 (Wave 3)** | Complexity reduction (extract helpers from 12 functions) | All functions under 50 lines | M (20 pts) |
211
+ | **v3 (Wave 4)** | Dispatcher hardening + pattern consistency | Robust arg validation | S (10 pts) |
212
+
213
+ ---
214
+
215
+ ## Phase 5: Architecture Decision Record
216
+
217
+ See `docs/decisions/ADR-0014-internal-cleanup-code-quality.md`
218
+
219
+ ---
220
+
221
+ ## Phase 6: Error Handling Design
222
+
223
+ ### 6.1 Dispatcher Argument Validation
224
+
225
+ All 11 unvalidated `args[N]` accesses will be protected:
226
+
227
+ **Pattern (before):**
228
+ ```js
229
+ case 'find-phase': {
230
+ phase.cmdFindPhase(cwd, args[1], raw);
231
+ break;
232
+ }
233
+ ```
234
+
235
+ **Pattern (after):**
236
+ ```js
237
+ case 'find-phase': {
238
+ if (!args[1]) { error('find-phase requires a phase number'); }
239
+ phase.cmdFindPhase(cwd, args[1], raw);
240
+ break;
241
+ }
242
+ ```
243
+
244
+ ### 6.2 `getArgValue()` Helper
245
+
246
+ ```js
247
+ function getArgValue(args, flag, defaultVal = null) {
248
+ const idx = args.indexOf(flag);
249
+ if (idx === -1 || idx + 1 >= args.length) return defaultVal;
250
+ return args[idx + 1];
251
+ }
252
+ ```
253
+
254
+ Eliminates 44 inline `indexOf` + `args[idx+1]` patterns.
255
+
256
+ ---
257
+
258
+ ## Phase 7: Security Review
259
+
260
+ ### 7.1 Findings
261
+ - No command injection vulnerabilities (all shell calls use `execFileSync` with array args)
262
+ - No path traversal vulnerabilities (all paths resolved within project root)
263
+ - No sensitive data exposure (output goes through `toPosix()` and never includes absolute paths)
264
+ - The duplicate `execFileSync` import in core.cjs is benign (performance only)
265
+
266
+ ### 7.2 Assessment
267
+ **No security issues found.** The codebase's security posture is strong. The cleanup items are all maintainability concerns, not security risks.
268
+
269
+ ---
270
+
271
+ ## Phase 8: Implementation Roadmap
272
+
273
+ ### Wave 1: Dead Code Removal (XS — 5 pts, MICRO tier)
274
+
275
+ #### Task 1.1: Remove duplicate `execFileSync` import in core.cjs
276
+ - **File:** `pan-wizard-core/bin/lib/core.cjs`
277
+ - **Action:** Remove line 216 `const { execFileSync } = require('child_process');` inside `execGit()` — already imported at line 7
278
+ - **Priority:** P2
279
+ - **Effort:** XS (1 pt)
280
+
281
+ #### Task 1.2: Remove duplicate `core.cjs` require in dispatcher
282
+ - **File:** `pan-wizard-core/bin/pan-tools.cjs`
283
+ - **Action:** Remove line 662 re-require of core.cjs; use top-level import (add `output` to line 168 destructuring)
284
+ - **Priority:** P3
285
+ - **Effort:** XS (1 pt)
286
+
287
+ #### Task 1.3: Remove unused `isSummaryFile` import from milestone.cjs
288
+ - **File:** `pan-wizard-core/bin/lib/milestone.cjs`
289
+ - **Action:** Remove `isSummaryFile` from line 7 destructuring (verify it's truly unused in module first)
290
+ - **Priority:** P5
291
+ - **Effort:** XS (1 pt)
292
+
293
+ #### Task 1.4: Clean up unused function parameters
294
+ - **File:** `pan-wizard-core/bin/lib/phase.cjs`
295
+ - **Action:** Remove or document `phaseName` (line 887) and `totalPhases` (line 990) — if tests pass without them, remove; if callers pass them, keep but prefix with `_`
296
+ - **Priority:** P4
297
+ - **Effort:** XS (1 pt)
298
+
299
+ #### Task 1.5: Remove `classifyItemPriority` from focus.cjs module internals
300
+ - **File:** `pan-wizard-core/bin/lib/focus.cjs`
301
+ - **Action:** Keep export (used by tests), but verify no internal callers — if none, note in comment as test-only export
302
+ - **Priority:** P5
303
+ - **Effort:** XS (1 pt)
304
+
305
+ ---
306
+
307
+ ### Wave 2: Duplication Consolidation + Constants (S — 10 pts, STANDARD tier)
308
+
309
+ #### Task 2.1: Consolidate getArchivedPhaseDirs / listArchivedPhaseDirs
310
+ - **Files:** `core.cjs`, `utils.cjs`, `commands.cjs`, `phase.cjs`
311
+ - **Action:** Keep `getArchivedPhaseDirs()` in core.cjs (it's the canonical location). Remove `listArchivedPhaseDirs()` from utils.cjs. Update any callers of `listArchivedPhaseDirs` to use `getArchivedPhaseDirs`.
312
+ - **Priority:** P2
313
+ - **Effort:** S (2 pts)
314
+
315
+ #### Task 2.2: Extract standards section parsing helper
316
+ - **File:** `pan-wizard-core/bin/lib/config.cjs`
317
+ - **Action:** Extract duplicated checkbox parsing (lines 372-383 and 528-534) into `parseStandardsChecklist(content, standardName)` helper
318
+ - **Priority:** P3
319
+ - **Effort:** S (2 pts)
320
+
321
+ #### Task 2.3: Extract magic numbers to constants.cjs
322
+ - **Files:** `constants.cjs`, `focus.cjs`, `template.cjs`, `context-budget.cjs`, `commands.cjs`, `verify.cjs`
323
+ - **Action:** Extract:
324
+ - `BUDGET_LIMIT_BUGFIX = 40`, `BUDGET_LIMIT_FULL = 60`
325
+ - `STABILITY_RATIO = 0.6`, `FEATURE_RATIO = 0.8`
326
+ - `SIMPLE_TASK_THRESHOLD = 2`, `SIMPLE_FILE_THRESHOLD = 3`, `COMPLEX_TASK_THRESHOLD = 5`, `COMPLEX_FILE_THRESHOLD = 6`
327
+ - `CHARS_PER_TOKEN = 4`
328
+ - `HEALTH_STATUS = { HEALTHY: 'healthy', DEGRADED: 'degraded', BROKEN: 'broken' }`
329
+ - **Priority:** P4
330
+ - **Effort:** M (4 pts)
331
+
332
+ #### Task 2.4: Extract `getArgValue()` helper for dispatcher
333
+ - **File:** `pan-wizard-core/bin/pan-tools.cjs`
334
+ - **Action:** Add `getArgValue(args, flag, defaultVal)` helper at top of file. Replace the most-repeated patterns (start with state/commit/init blocks — ~20 occurrences)
335
+ - **Priority:** P3
336
+ - **Effort:** S (2 pts)
337
+
338
+ ---
339
+
340
+ ### Wave 3: Complexity Reduction (M — 20 pts, STANDARD tier)
341
+
342
+ #### Task 3.1: Split `cmdCommit()` (127 LOC)
343
+ - **File:** `commands.cjs`
344
+ - **Action:** Extract `validateCommitSafety(stagedFiles, config)` and `buildCommitMessage(msg, type, phaseMeta)` helpers. Target: main function under 50 lines.
345
+ - **Priority:** P2
346
+ - **Effort:** M (4 pts)
347
+
348
+ #### Task 3.2: Split `allocateBudget()` (99 LOC)
349
+ - **File:** `focus.cjs`
350
+ - **Action:** Extract mode-specific allocation into `allocateForMode(items, mode, budget)` with per-mode functions. Extract batch dedup to `Set`-based tracking.
351
+ - **Priority:** P2
352
+ - **Effort:** M (4 pts)
353
+
354
+ #### Task 3.3: Split `cmdConfigEnsureSection()` (86 LOC)
355
+ - **File:** `config.cjs`
356
+ - **Action:** Extract `createDefaultConfig(configPath)` and `mergeConfigDefaults(config)` helpers.
357
+ - **Priority:** P3
358
+ - **Effort:** S (2 pts)
359
+
360
+ #### Task 3.4: Split `cmdStandardsPhaseTrack()` (93 LOC)
361
+ - **File:** `config.cjs`
362
+ - **Action:** Extract `scanPlanForStandards(planContent, standards)` helper.
363
+ - **Priority:** P3
364
+ - **Effort:** S (2 pts)
365
+
366
+ #### Task 3.5: Split `cmdVerifySummary()` (95 LOC)
367
+ - **File:** `verify.cjs`
368
+ - **Action:** Extract `verifySummaryFrontmatter(fm)`, `verifySummaryContent(content)`, `verifySummaryCommits(content, cwd)` helpers.
369
+ - **Priority:** P3
370
+ - **Effort:** M (4 pts)
371
+
372
+ #### Task 3.6: Split `renumberIntegerPhases()` (66 LOC)
373
+ - **File:** `phase.cjs`
374
+ - **Action:** Extract sort comparator and rename loop into helpers.
375
+ - **Priority:** P3
376
+ - **Effort:** S (2 pts)
377
+
378
+ #### Task 3.7: Split remaining oversized functions
379
+ - **Files:** `verify.cjs` (checkPhaseContents, cmdValidateHealth), `frontmatter.cjs` (parseMustHavesBlock), `core.cjs` (loadConfig)
380
+ - **Action:** Extract inner loops and validation logic into focused helpers.
381
+ - **Priority:** P4
382
+ - **Effort:** S (2 pts)
383
+
384
+ ---
385
+
386
+ ### Wave 4: Dispatcher Hardening (S — 10 pts, STANDARD tier)
387
+
388
+ #### Task 4.1: Add argument validation to 11 dispatcher cases
389
+ - **File:** `pan-wizard-core/bin/pan-tools.cjs`
390
+ - **Action:** Add `if (!args[N]) { error('command requires <arg>'); }` before each unvalidated `args[N]` access at lines 225, 303, 330, 332, 355, 437, 455, 467, 478, 497, 621.
391
+ - **Priority:** P1
392
+ - **Effort:** S (2 pts)
393
+
394
+ #### Task 4.2: Standardize flag parsing with getArgValue
395
+ - **File:** `pan-wizard-core/bin/pan-tools.cjs`
396
+ - **Action:** Replace remaining `indexOf`+`args[idx+1]` patterns (beyond Task 2.4) with `getArgValue()`.
397
+ - **Priority:** P4
398
+ - **Effort:** S (2 pts)
399
+
400
+ #### Task 4.3: Add new tests for dispatcher argument validation
401
+ - **File:** `tests/commands.test.cjs` (or new `tests/dispatcher.test.cjs`)
402
+ - **Action:** Test each of the 11 cases with missing required args — should return `{error: ...}` not crash.
403
+ - **Priority:** P2
404
+ - **Effort:** M (4 pts)
405
+
406
+ #### Task 4.4: Validate getArgValue bounds in existing flag patterns
407
+ - **File:** `pan-wizard-core/bin/pan-tools.cjs`
408
+ - **Action:** Ensure `getArgValue` returns null when flag is last arg (no value follows). Add test for this.
409
+ - **Priority:** P2
410
+ - **Effort:** S (2 pts)
411
+
412
+ ---
413
+
414
+ ### Dependency Graph
415
+
416
+ ```
417
+ Wave 1 (dead code) → Wave 2 (duplication + constants) → Wave 3 (complexity) → Wave 4 (dispatcher)
418
+ Task 1.1-1.5 Task 2.1-2.4 Task 3.1-3.7 Task 4.1-4.4
419
+ (independent) (2.3 after 1.*) (after 2.*) (4.1 after 2.4)
420
+ ```
421
+
422
+ ### Risk Register
423
+
424
+ | Risk | Probability | Impact | Mitigation |
425
+ |------|------------|--------|------------|
426
+ | Refactored function changes behavior | Low | High | Run full test suite after every extraction |
427
+ | Extracted helper has wrong signature | Low | Medium | Write test for helper before extracting |
428
+ | Removed "dead" code is actually used | Low | High | Grep entire codebase before removing |
429
+ | Constants rename breaks existing test expectations | Low | Medium | Use find-and-replace, run tests |
430
+
431
+ ---
432
+
433
+ ## Phase 9: Test Plan
434
+
435
+ ### 9.1 Test Strategy
436
+ Each wave runs the full test suite (1,180 tests) after completion. No test should change expectations — all changes are behavioral no-ops.
437
+
438
+ ### 9.2 New Tests Required
439
+
440
+ | Wave | New Tests | What They Cover |
441
+ |------|-----------|-----------------|
442
+ | Wave 1 | 0 | Dead code removal — existing tests cover behavior |
443
+ | Wave 2 | 3-5 | `getArgValue()` helper, consolidated `getArchivedPhaseDirs`, `parseStandardsChecklist` |
444
+ | Wave 3 | 5-10 | Each extracted helper function (validateCommitSafety, allocateForMode, etc.) |
445
+ | Wave 4 | 11+ | Missing-arg error paths for each dispatcher case |
446
+
447
+ ### 9.3 Regression Verification
448
+ - [ ] Full suite passes unchanged after each wave
449
+ - [ ] No existing test expectations changed
450
+ - [ ] Test count only increases (new tests for new helpers)
451
+ - [ ] Build hooks compile without error
452
+
453
+ ### 9.4 Assertion Density
454
+ Every new test asserts:
455
+ - Correct return value shape (JSON with expected keys)
456
+ - Correct values for 2+ fields
457
+ - No `error` field on success paths
458
+ - Actionable `error` message on failure paths
459
+
460
+ ---
461
+
462
+ ## Phase 10: Summary
463
+
464
+ ### Problem & Evidence
465
+ PAN Wizard's 15 core modules have accumulated ~170 code quality issues across 23 development sessions. 12 functions exceed the 50-line complexity budget, 3 functions are duplicated across modules, and the dispatcher has 11 unvalidated argument accesses.
466
+
467
+ ### Strategic Assessment
468
+ - **Blue Ocean:** ELIMINATE dead code, REDUCE complexity, RAISE consistency, CREATE shared helpers
469
+ - **Moat Score:** Maintainability +4, Cross-Platform +1, Verification +1
470
+ - **Cognitive Load:** Simplifies (-1) — no new user-facing concepts
471
+ - **Recommendation:** Build. Zero user-facing risk, significant maintenance improvement.
472
+
473
+ ### Implementation Summary
474
+ - **4 waves**, ordered by risk (lowest first)
475
+ - **Wave 1:** Dead code removal (5 tasks, 5 pts, MICRO)
476
+ - **Wave 2:** Duplication + constants (4 tasks, 10 pts, STANDARD)
477
+ - **Wave 3:** Complexity reduction (7 tasks, 20 pts, STANDARD)
478
+ - **Wave 4:** Dispatcher hardening (4 tasks, 10 pts, STANDARD)
479
+ - **Total:** 20 tasks, 45 points, ~19-30 new tests
480
+ - **Zero breaking changes**
481
+
482
+ ### Next Steps
483
+ 1. Run `/pan:focus-plan` with this spec as source
484
+ 2. Execute wave-by-wave with `/pan:focus-exec`
485
+ 3. Run full test suite after each wave
486
+ 4. Commit per wave with descriptive messages
@@ -0,0 +1,31 @@
1
+ # Investigations
2
+
3
+ Output of the `/investigate` dev command (`.claude/commands/investigate.md`): material the maintainer brings — a news
4
+ dump, an article, a paper, a host tool's release notes — triaged against what PAN Wizard already does, with a
5
+ write-up for every ADD or ENHANCE verdict. Nothing here ships; it is the inbox that feeds
6
+ [the ideas ledger](../market-ideas-ledger.md) once the owner files an item.
7
+
8
+ - `digests/` — one per run: the full triage, what PAN already has, what to watch, hand-offs to `/reality-check`.
9
+ - `features/` — one per proposed feature; later runs append to the source trail instead of creating duplicates.
10
+ - `sources/` — the raw input of each run, **gitignored**: this repository is public, so third-party text stays local
11
+ and only the write-ups (in our own words) are tracked.
12
+
13
+ Statuses: PROPOSED → FILED `MI-nnn` (entered in the ledger) or REJECTED (with the reason).
14
+
15
+ ## Digests
16
+
17
+ | Date | Source | Result |
18
+ |---|---|---|
19
+ | [`2026-10-10`](digests/2026-10-10.md) | `mattpocock/skills` repository at `49dd158` | ENHANCE 2 · HAVE 7 · WATCH 1 · SKIP 4 |
20
+ | [`2026-10-08`](digests/2026-10-08.md) | VentureBeat AI Weekly newsletter (pasted), incl. multi-harness RL, SIFT, WikiSkill, Agent Memory Repo, Context Language Models | ENHANCE 1 · HAVE 3 · WATCH 3 · SKIP 7 |
21
+ | [`2026-09-28`](digests/2026-09-28.md) | LLM brief (GrokBot llm-watch), incl. Growing Harness and PaMER papers | ENHANCE 2 · HAVE 2 · WATCH 1 · SKIP 7 |
22
+
23
+ ## Feature write-ups
24
+
25
+ | Feature | Verdict | Priority | Status | Last updated |
26
+ |---|---|---|---|---|
27
+ | [Debugger: a failing command before any hypothesis](features/debugger-red-loop-first.md) | ENHANCE | P2 | FILED `MI-105`, built | `2026-10-10` |
28
+ | [Reviewer: a fixed code-smell baseline](features/reviewer-smell-baseline.md) | ENHANCE | P3 | FILED `MI-106`, built | `2026-10-10` |
29
+ | [Behavioural harness runs on every host CLI](features/harness-cross-host-behaviour.md) | ENHANCE | P2 | FILED `MI-104`, plumbing built | `2026-10-10` |
30
+ | [Failure capture in the trace hook](features/trace-failure-capture.md) | ENHANCE | P2 | FILED `MI-060` (built, ADR-0049) | `2026-09-28` |
31
+ | [Regression gate and rollback for `optimize apply`](features/optimize-apply-regression-gate.md) | ENHANCE | P3 | FILED `MI-061` (revert built; verdict deferred) | `2026-09-28` |
@@ -0,0 +1,47 @@
1
+ # Investigation — 2026-09-28
2
+
3
+ Source: "LLM brief — Mon 28 Sep" (GrokBot llm-watch, AI-generated digest, 7 items) · local copy `sources/2026-09-28.md` (gitignored) · ADD 0 · ENHANCE 2 · HAVE 2 · WATCH 1 · SKIP 7
4
+
5
+ ## Recommendations
6
+ 1. **Failure capture in the trace hook**: ENHANCE, P2, M. The optimise loop's failure signal depends on agents calling `optimize trace log`; they never do, so derive error events from the subagent transcript in the hook. → [write-up](../features/trace-failure-capture.md)
7
+ 2. **Regression gate and rollback for `optimize apply`**: ENHANCE, P3, M. Record applies so they can be reverted, and give an advisory success-first before/after verdict. Its verdict half needs recommendation 1. → [write-up](../features/optimize-apply-regression-gate.md)
8
+
9
+ The brief is mostly open-weight model releases, which PAN does not consume. Its value for PAN is the Growing Harness paper, read through the question of where PAN still leaves routine control to the model.
10
+
11
+ ## Triage
12
+
13
+ | # | Item | Area | Relevance | Verdict | Ledger |
14
+ |---|---|---|---|---|---|
15
+ | 1 | Holo4 open-weight computer-use agents, cost per task vs a frontier model | other (models) | LOW | SKIP: not a model any of PAN's five runtimes defaults to; no rate row without a provider pricing page | MI-023 |
16
+ | 2 | Naive-N0.5-Flash 309B MoE, 1M context, API announced not live | cost/models | LOW | SKIP: no live API, no pricing page | MI-023 |
17
+ | 3 | JEV-27B System-1 decision head sharing one vLLM engine | other (models) | LOW | SKIP: self-hosted serving technique, outside PAN's layer | — |
18
+ | 4 | Julia-1 CPU/ONNX decision encoder for local routing | cost/models | LOW | SKIP: an ONNX model breaks the zero-runtime-dependency rule; PAN routes deterministically (`resolveComplexityTier`) and escalates by outcome | MI-029 |
19
+ | 5a | Growing Harness: optimiser rewrites the agent program from failures | learnings/optimize | MED | SKIP for shipped PAN: no pass/fail oracle for user work, one task family per program, and rewriting installed code in user projects conflicts with keeping planning gates deterministic (ADR-0029's scope fence, Proposed) | — |
20
+ | 5b | Growing Harness principle: recurring control belongs in code, not context | orchestration | MED | HAVE | MI-002 |
21
+ | 5c | Growing Harness: failures recorded by the runtime and localised | learnings/optimize · hooks | HIGH | ENHANCE → rec. 1 | — |
22
+ | 5d | Growing Harness: success-first held-out gate with rollback | learnings/optimize | MED | ENHANCE → rec. 2 | — |
23
+ | 5e | Growing Harness applied to PAN development: harness scenarios as the gate for workflow edits | harness/evals | MED | WATCH | MI-019 |
24
+ | 6a | PaMER: memory-control signals read from pre-action hidden states | context management | LOW | SKIP: needs model hidden states; PAN's runtimes are hosted models and the hosts own compaction | — |
25
+ | 6b | PaMER: compact recent context plus selectively restored evidence | context management | MED | HAVE | MI-036 |
26
+ | 7 | llama.cpp b11205 CUDA SSM scan | other (tooling) | NONE | SKIP: local inference runtime, outside PAN's layer | — |
27
+
28
+ ## HAVE — already covered
29
+ - **5b, control in code**: the MCP `next-action` state machine is a pure function of a state snapshot (`pan-wizard-core/mcp/orchestrator.cjs:121`, SOURCE); native workflow scripts run fan-out control flow as code on Claude Code (MI-002, `3.28.0`); `pan-tools` verbs do the parsing, counting and state updates the workflows would otherwise ask the model for. The paper's small-model result (success held on WebArena-Verified as the model shrank, while the tool-calling baseline collapsed) is outside evidence for keeping workflow prose thin.
30
+ - **6b, recent context plus restored evidence**: `hooks/pan-state-reinject.js` injects the active phase, last step and next action from `.planning/` on the post-compaction `SessionStart` (Claude, Codex) (MI-036, `3.31.0`, SOURCE). PAN restores durable state from disk rather than predicting what to keep, which the paper's second finding supports.
31
+
32
+ ## WATCH
33
+ - **5e, harness as a held-out gate for PAN's own workflow edits.** Keep a fixed scenario set that workflow changes are not tuned against, and refuse a change that lowers its pass rate. Trigger: model-tier scenarios cheap enough to run at `--repeat 3` or more on every workflow change, or a second workflow regression that tier 0 missed. MI-019 (do not soften the harness) stands either way.
34
+
35
+ ## Hand-offs to /reality-check
36
+ None: no item changes a path, config key, event name or file format PAN writes.
37
+
38
+ ## How far to trust the material
39
+ - The brief is an AI-generated secondary digest. Every figure in it is a lead.
40
+ - **Growing Harness** (arXiv:2609.26760 v2, `2026-09-24`): read in full on `2026-09-28` (primary). Evaluation sets are 50 tasks with 95% interval half-widths around ±11–13 points, so several head-to-head wins overlap. The ablations are single runs. Cost figures exclude the offline optimiser. Benchmarks are homogeneous task families, unlike PAN's work.
41
+ - **PaMER** (arXiv:2609.27286 v1, `2026-09-23`): abstract read (primary). It confirms hidden-state signals and the recent-plus-retrieved design on WorkBuddyBench across several backbones. The brief's specific figures (AUROC values, "Recent2 ~26% tokens", "~73% token cut" on a named model) are **not in the abstract** and were not verified.
42
+ - Items 1–4 and 7: not fetched; each is SKIP on PAN-side grounds that hold whatever the release details are.
43
+
44
+ ## Notes
45
+ - No instruction-like text in the material.
46
+ - The brief's "Watch next" list (drafter models, runtime source release, third-party leaderboard runs) concerns model releases outside PAN's layer; not triaged.
47
+ - Recommendation 1 rests partly on the September field telemetry (zero error events recorded across the D-drive projects), which is in project memory and was not re-measured today. Re-measure before building: count `"type":"error"` lines across the field projects' `.planning/optimization/traces/`.
@@ -0,0 +1,62 @@
1
+ # Investigation — 2026-10-08
2
+
3
+ Source: VentureBeat "AI Weekly" newsletter (pasted, 11 items) · local copy `sources/2026-10-08.md` (gitignored) · ADD 0 · ENHANCE 1 · HAVE 3 · WATCH 3 · SKIP 7
4
+
5
+ ## Recommendations
6
+ 1. **Behavioural harness runs on every host CLI**: ENHANCE, P2, L (M for the first host). PAN measures its workflows' behaviour through Claude Code only. Hugging Face's multi-harness study found the same weights scoring 33–62% depending on the host. Give harness model steps a `runtime` and run the portable chain on Codex, Copilot, Gemini and OpenCode, whose CLIs are all on this machine. → [write-up](../features/harness-cross-host-behaviour.md)
7
+
8
+ The newsletter's memory and self-improvement stories land on decisions PAN has already made and measured:
9
+ - **Retired memory injection.** MI-095 retired lesson injection after 16 harness reps showed no effect.
10
+ - **Declined host memory.** MI-010 declined host memory until a cross-runtime format is adopted by a runtime PAN targets.
11
+ - **Human-gated optimiser.** The optimiser loop is human-gated with very few candidates (MI-061).
12
+
13
+ None of the new material overturns those reasons.
14
+
15
+ ## Triage
16
+
17
+ | # | Item | Area | Relevance | Verdict | Ledger |
18
+ |---|---|---|---|---|---|
19
+ | 1 | EmbeddingGemma 2, a 740M multimodal embedding model | other (models) | LOW | SKIP: embeddings mean a vector store and a model dependency; ADR-0036 D4 and MI-101 (files plus grep held up) | MI-101 |
20
+ | 2 | Mistral Large 4, 1.05T MoE, open weights due end of October | cost/models | LOW | SKIP: not a default of any of PAN's five runtimes; no rate row without that (MI-023 rule) | MI-023 |
21
+ | 3 | Amazon Strands Decider 2B, a scoring model for yes/no and choice decisions | cost/models | LOW | SKIP: a local model breaks the zero-runtime-dependency rule; PAN routes deterministically (`resolveComplexityTier`) and escalates on outcome; same reasoning as Julia-1 in the `2026-09-28` digest | MI-029 |
22
+ | 4 | Cohere North 2: agent budgets, rate limits, cross-session memory | peer/competitor | LOW | HAVE (budgets, memory); rate limits do not apply, since PAN makes no model calls of its own | MI-010 |
23
+ | 5 | SIFT: a code-only pairwise judge ranks candidate agents before costly evals | learnings/optimize · harness | MED | WATCH | MI-061 |
24
+ | 6 | Sponsored message (Ernst & Young) | other | NONE | SKIP: advertisement | — |
25
+ | 7 | WikiSkill: traces compiled into a wiki, then into validated skills | learnings/optimize | MED | WATCH | MI-095 |
26
+ | 8a | Hugging Face: the host harness changes measured capability of the same weights | harness/evals | HIGH | ENHANCE → rec. 1 | — |
27
+ | 8b | Hugging Face: RL training through unmodified harnesses via a capture proxy | other | LOW | SKIP: PAN trains no models | — |
28
+ | 9a | Cognition's Agent Memory Repo, an open memory format | peer/competitor · planning state | MED | WATCH: MI-010's trigger not fired | MI-010 |
29
+ | 9b | Cognition's Dreaming: a daily unattended pass that merges, drops and adds memory | learnings/optimize | MED | SKIP: an automatic writer with no approval step; the owner stopped PAN's automatic writers (MI-095, `2026-10-04`) and ADR-0040 treats unattended writes as a poisoning path | MI-095 |
30
+ | 10 | VB Pulse: 2% chose an agent platform for its model | docs/positioning | LOW | HAVE (positioning) | — |
31
+ | 11a | Context Language Models: the model edits a file mirrored into its own live context | orchestration | MED | SKIP: the hosts own the context window; PAN cannot sync an edited transcript into the next call (as with PaMER, `2026-09-28` 6a) | — |
32
+ | 11b | The same paper's principle: let the model manage its own context through a file | orchestration | MED | HAVE | MI-036, MI-097 |
33
+
34
+ ## HAVE — already covered
35
+ - **4, budgets and memory.** Scheduled campaigns carry `daily_budget` with an `enforce_budget` switch that stops a run for the day (`pan-wizard-core/bin/lib/campaign.cjs:81-118`, SOURCE). Every harness model step is refused without `--max-usd` (ADR-0047 D2). PAN's memory is the cited, expiring entries of MI-093 (`memory.cjs:156-179`, SOURCE). Cohere's per-user and per-group rate tiers have no PAN counterpart because the host makes the calls.
36
+ - **10, positioning.** The survey is n=166, self-selected, with no margin of error, so it is secondary by nature. Its top reasons are flexibility across models and tools (22%), production reliability (20%), ease of development (19%) and control over execution (18%). That matches PAN's position as a runtime-neutral layer with deterministic gates, and the August read that the market converged on PAN's thesis. Use it as colour, not as a claim.
37
+ - **11b, model-managed context through a file.**
38
+ - Before the host compacts, the context monitor asks the model to checkpoint its position into `state.md` (`hooks/pan-context-monitor.js:32-40`, `:411-418`, SOURCE).
39
+ - After compaction, the position is re-injected (`hooks/pan-state-reinject.js`, MI-036).
40
+ - PAN's CLAUDE.md block steers the host's summary with compact instructions (`pan-wizard-core/bin/lib/agents-md.cjs:101`, MI-097).
41
+
42
+ The paper's own failure mode supports the line PAN drew: an editable context lets a model plant instructions for itself, which is why PAN keeps the checkpoint to position fields.
43
+
44
+ ## WATCH
45
+ - **5, SIFT.** A judge pays off when there are many candidates to rank. PAN's optimiser applies are rare (one apply run in 14 field projects, MI-061), and a harness A/B compares one or two variants. ADR-0029's scope fence keeps model judges out of lifecycle gates anyway. Trigger: MI-061's (`optimize stats` shows apply runs in three or more projects), or PAN generating several candidate variants per decision. If it fires, note the paper's finding that full files ranked better than diffs as judge input (Spearman 0.68 vs 0.40 over 50 nodes).
46
+ - **7, WikiSkill.** The gains are on math, QA, spreadsheet, office and ALFWorld tasks with small and mid-size models, with skills injected whole into the system prompt. PAN measured lessons on its own coding chain and found no effect (MI-095). It also declined skill preload into agents (ADR-0046 D4). The paper also reports that skills compiled for one model can hurt another (Qwen-4B skills cut Gemini's spreadsheet score from 50.5 to 18.1). That is a caution for anything PAN ships to every model. Trigger: MI-095's (a long-horizon harness run showing an effect), or a harness A/B where a compiled skill changes a fast-tier agent's outcome.
47
+ - **9a, Agent Memory Repo.** Published by Cognition on `2026-10-04`: MIT licence, no version or releases, no named adopter. It installs into other tools as a skill, not as host-native support. MI-010's trigger needs adoption by a runtime PAN targets, so it has not fired; the decline holds. The format is close to PAN's own: a `MEMORY.md` index, files read on demand, and bullet entries with `source` and `added` metadata. It has no expiry, which MI-093's entries do.
48
+
49
+ ## Hand-offs to /reality-check
50
+ None. No item changes a path, config key, event name or file format PAN writes.
51
+
52
+ ## How far to trust the material
53
+ - **The newsletter itself** is secondary. Every item above was checked against its primary source except EmbeddingGemma 2 (search snippets only) and the survey (VentureBeat is its own source). One headline is wrong: Mistral Large 4 has 52B active parameters per Mistral's docs, not 49B. The October 27 weights date appears only in secondary coverage.
54
+ - **Hugging Face multi-harness RL** used one seed per run, no error bars and a single attempt per test cell (250 tasks × 4 harnesses). The authors call the gap between their two RL runs noise. The 29-point spread between harnesses is large next to that, but it comes from one 2.6B model on data-analysis tasks. A frontier model's spread may be smaller, which is why the recommendation is to measure rather than assume.
55
+ - **SIFT** reports one main run plus 3 repeats for its headline, with no confidence intervals. Its strongest judge is stronger than the agent being improved, and two of its cost figures disagree with each other.
56
+ - **WikiSkill** averages 3 runs per result with a paired bootstrap. Its test sets are small (85–280 items) and its validation sets smaller still.
57
+ - **Context Language Models** report no error bars on the main results. Several gains are within plausible run-to-run noise, the FLOPs are theoretical, and the headline 11.4% is relative (about 6 points absolute).
58
+ - **Cognition**: no announcement post was found. The facts come from the spec page, the repository and the Devin docs.
59
+
60
+ ## Notes
61
+ - The material contains no text addressed to the agent. The sponsored message was triaged as an item and nothing more.
62
+ - Version-pinned model names appear above only because this file lives under `docs/specs/`.