pan-wizard 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +772 -0
  3. package/agents/pan-debugger.md +1246 -0
  4. package/agents/pan-document_code.md +965 -0
  5. package/agents/pan-executor.md +469 -0
  6. package/agents/pan-integration-checker.md +443 -0
  7. package/agents/pan-phase-researcher.md +572 -0
  8. package/agents/pan-plan-checker.md +763 -0
  9. package/agents/pan-planner.md +1297 -0
  10. package/agents/pan-project-researcher.md +647 -0
  11. package/agents/pan-research-synthesizer.md +239 -0
  12. package/agents/pan-reviewer.md +112 -0
  13. package/agents/pan-roadmapper.md +642 -0
  14. package/agents/pan-verifier.md +672 -0
  15. package/assets/pan-logo-2000-transparent.svg +30 -0
  16. package/assets/pan-logo-2000.svg +43 -0
  17. package/assets/terminal.svg +119 -0
  18. package/bin/install-lib.cjs +616 -0
  19. package/bin/install.js +1936 -0
  20. package/commands/pan/add-phase.md +44 -0
  21. package/commands/pan/assumptions.md +47 -0
  22. package/commands/pan/audit-deployment.md +378 -0
  23. package/commands/pan/debug.md +168 -0
  24. package/commands/pan/discord.md +19 -0
  25. package/commands/pan/discuss-phase.md +84 -0
  26. package/commands/pan/exec-phase.md +45 -0
  27. package/commands/pan/focus-auto.md +323 -0
  28. package/commands/pan/focus-design.md +816 -0
  29. package/commands/pan/focus-exec.md +316 -0
  30. package/commands/pan/focus-plan.md +101 -0
  31. package/commands/pan/focus-scan.md +272 -0
  32. package/commands/pan/focus-sync.md +104 -0
  33. package/commands/pan/health.md +23 -0
  34. package/commands/pan/help.md +23 -0
  35. package/commands/pan/insert-phase.md +33 -0
  36. package/commands/pan/map-codebase.md +72 -0
  37. package/commands/pan/milestone-audit.md +37 -0
  38. package/commands/pan/milestone-cleanup.md +19 -0
  39. package/commands/pan/milestone-done.md +137 -0
  40. package/commands/pan/milestone-gaps.md +35 -0
  41. package/commands/pan/milestone-new.md +45 -0
  42. package/commands/pan/new-project.md +43 -0
  43. package/commands/pan/patches.md +110 -0
  44. package/commands/pan/pause.md +39 -0
  45. package/commands/pan/phase-budget.md +23 -0
  46. package/commands/pan/phase-tests.md +42 -0
  47. package/commands/pan/plan-phase.md +46 -0
  48. package/commands/pan/profile.md +36 -0
  49. package/commands/pan/progress.md +25 -0
  50. package/commands/pan/quick.md +42 -0
  51. package/commands/pan/remove-phase.md +32 -0
  52. package/commands/pan/research-phase.md +190 -0
  53. package/commands/pan/resume.md +41 -0
  54. package/commands/pan/retro.md +33 -0
  55. package/commands/pan/settings.md +37 -0
  56. package/commands/pan/todo-add.md +48 -0
  57. package/commands/pan/todo-check.md +46 -0
  58. package/commands/pan/update.md +38 -0
  59. package/commands/pan/verify-phase.md +39 -0
  60. package/hooks/dist/pan-check-update.js +62 -0
  61. package/hooks/dist/pan-context-monitor.js +122 -0
  62. package/hooks/dist/pan-statusline.js +108 -0
  63. package/package.json +66 -0
  64. package/pan-wizard-core/bin/lib/codebase.cjs +746 -0
  65. package/pan-wizard-core/bin/lib/commands.cjs +1435 -0
  66. package/pan-wizard-core/bin/lib/config.cjs +611 -0
  67. package/pan-wizard-core/bin/lib/constants.cjs +696 -0
  68. package/pan-wizard-core/bin/lib/context-budget.cjs +150 -0
  69. package/pan-wizard-core/bin/lib/core.cjs +650 -0
  70. package/pan-wizard-core/bin/lib/focus.cjs +900 -0
  71. package/pan-wizard-core/bin/lib/frontmatter.cjs +442 -0
  72. package/pan-wizard-core/bin/lib/init.cjs +881 -0
  73. package/pan-wizard-core/bin/lib/milestone.cjs +276 -0
  74. package/pan-wizard-core/bin/lib/phase.cjs +1212 -0
  75. package/pan-wizard-core/bin/lib/roadmap.cjs +470 -0
  76. package/pan-wizard-core/bin/lib/state.cjs +1029 -0
  77. package/pan-wizard-core/bin/lib/template.cjs +314 -0
  78. package/pan-wizard-core/bin/lib/utils.cjs +171 -0
  79. package/pan-wizard-core/bin/lib/verify.cjs +1808 -0
  80. package/pan-wizard-core/bin/pan-tools.cjs +773 -0
  81. package/pan-wizard-core/references/checkpoints.md +776 -0
  82. package/pan-wizard-core/references/continuation-format.md +249 -0
  83. package/pan-wizard-core/references/decimal-phase-calculation.md +65 -0
  84. package/pan-wizard-core/references/git-integration.md +248 -0
  85. package/pan-wizard-core/references/git-planning-commit.md +38 -0
  86. package/pan-wizard-core/references/model-profile-resolution.md +34 -0
  87. package/pan-wizard-core/references/model-profiles.md +111 -0
  88. package/pan-wizard-core/references/phase-argument-parsing.md +61 -0
  89. package/pan-wizard-core/references/planning-config.md +196 -0
  90. package/pan-wizard-core/references/questioning.md +145 -0
  91. package/pan-wizard-core/references/tdd.md +263 -0
  92. package/pan-wizard-core/references/ui-brand.md +160 -0
  93. package/pan-wizard-core/references/verification-patterns.md +612 -0
  94. package/pan-wizard-core/templates/codebase/architecture.md +283 -0
  95. package/pan-wizard-core/templates/codebase/best-practices.md +133 -0
  96. package/pan-wizard-core/templates/codebase/concerns.md +325 -0
  97. package/pan-wizard-core/templates/codebase/conventions.md +307 -0
  98. package/pan-wizard-core/templates/codebase/integrations.md +305 -0
  99. package/pan-wizard-core/templates/codebase/relationships.md +124 -0
  100. package/pan-wizard-core/templates/codebase/stack.md +199 -0
  101. package/pan-wizard-core/templates/codebase/structure.md +298 -0
  102. package/pan-wizard-core/templates/codebase/testing.md +480 -0
  103. package/pan-wizard-core/templates/config.json +37 -0
  104. package/pan-wizard-core/templates/context.md +283 -0
  105. package/pan-wizard-core/templates/continue-here.md +78 -0
  106. package/pan-wizard-core/templates/debug-subagent-prompt.md +91 -0
  107. package/pan-wizard-core/templates/debug.md +164 -0
  108. package/pan-wizard-core/templates/discovery.md +146 -0
  109. package/pan-wizard-core/templates/milestone-archive.md +123 -0
  110. package/pan-wizard-core/templates/milestone.md +115 -0
  111. package/pan-wizard-core/templates/phase-prompt.md +593 -0
  112. package/pan-wizard-core/templates/planner-subagent-prompt.md +117 -0
  113. package/pan-wizard-core/templates/project.md +184 -0
  114. package/pan-wizard-core/templates/requirements.md +231 -0
  115. package/pan-wizard-core/templates/research-project/architecture.md +204 -0
  116. package/pan-wizard-core/templates/research-project/features.md +147 -0
  117. package/pan-wizard-core/templates/research-project/pitfalls.md +200 -0
  118. package/pan-wizard-core/templates/research-project/stack.md +120 -0
  119. package/pan-wizard-core/templates/research-project/summary.md +170 -0
  120. package/pan-wizard-core/templates/research.md +552 -0
  121. package/pan-wizard-core/templates/retrospective.md +54 -0
  122. package/pan-wizard-core/templates/roadmap.md +202 -0
  123. package/pan-wizard-core/templates/standards.md +24 -0
  124. package/pan-wizard-core/templates/state.md +176 -0
  125. package/pan-wizard-core/templates/summary-complex.md +59 -0
  126. package/pan-wizard-core/templates/summary-minimal.md +41 -0
  127. package/pan-wizard-core/templates/summary-standard.md +49 -0
  128. package/pan-wizard-core/templates/summary.md +249 -0
  129. package/pan-wizard-core/templates/uat.md +247 -0
  130. package/pan-wizard-core/templates/user-setup.md +311 -0
  131. package/pan-wizard-core/templates/validation.md +76 -0
  132. package/pan-wizard-core/templates/verification-report.md +322 -0
  133. package/pan-wizard-core/workflows/add-phase.md +111 -0
  134. package/pan-wizard-core/workflows/assumptions.md +178 -0
  135. package/pan-wizard-core/workflows/diagnose-issues.md +219 -0
  136. package/pan-wizard-core/workflows/discuss-phase.md +542 -0
  137. package/pan-wizard-core/workflows/exec-phase.md +572 -0
  138. package/pan-wizard-core/workflows/execute-plan.md +448 -0
  139. package/pan-wizard-core/workflows/health.md +156 -0
  140. package/pan-wizard-core/workflows/help.md +431 -0
  141. package/pan-wizard-core/workflows/insert-phase.md +129 -0
  142. package/pan-wizard-core/workflows/map-codebase.md +401 -0
  143. package/pan-wizard-core/workflows/milestone-audit.md +297 -0
  144. package/pan-wizard-core/workflows/milestone-cleanup.md +152 -0
  145. package/pan-wizard-core/workflows/milestone-gaps.md +274 -0
  146. package/pan-wizard-core/workflows/milestone-new.md +382 -0
  147. package/pan-wizard-core/workflows/new-project.md +1178 -0
  148. package/pan-wizard-core/workflows/pause.md +122 -0
  149. package/pan-wizard-core/workflows/phase-tests.md +388 -0
  150. package/pan-wizard-core/workflows/plan-phase.md +569 -0
  151. package/pan-wizard-core/workflows/profile.md +115 -0
  152. package/pan-wizard-core/workflows/progress.md +381 -0
  153. package/pan-wizard-core/workflows/quick.md +453 -0
  154. package/pan-wizard-core/workflows/remove-phase.md +154 -0
  155. package/pan-wizard-core/workflows/research-phase.md +73 -0
  156. package/pan-wizard-core/workflows/resume-project.md +306 -0
  157. package/pan-wizard-core/workflows/retro.md +121 -0
  158. package/pan-wizard-core/workflows/settings.md +213 -0
  159. package/pan-wizard-core/workflows/todo-add.md +157 -0
  160. package/pan-wizard-core/workflows/todo-check.md +176 -0
  161. package/pan-wizard-core/workflows/transition.md +544 -0
  162. package/pan-wizard-core/workflows/update.md +219 -0
  163. package/pan-wizard-core/workflows/verify-phase.md +301 -0
  164. package/scripts/build-hooks.js +43 -0
@@ -0,0 +1,84 @@
1
+ ---
2
+ name: pan:discuss-phase
3
+ group: Phase Lifecycle
4
+ description: Gather phase context through adaptive questioning before planning
5
+ argument-hint: "<phase> [--auto]"
6
+ allowed-tools:
7
+ - Read
8
+ - Write
9
+ - Bash
10
+ - Glob
11
+ - Grep
12
+ - AskUserQuestion
13
+ - Task
14
+ ---
15
+
16
+ <objective>
17
+ Extract implementation decisions that downstream agents need — researcher and planner will use context.md to know what to investigate and what choices are locked.
18
+
19
+ **How it works:**
20
+ 1. Analyze the phase to identify gray areas (UI, UX, behavior, etc.)
21
+ 2. Present gray areas — user selects which to discuss
22
+ 3. Deep-dive each selected area until satisfied
23
+ 4. Create context.md with decisions that guide research and planning
24
+
25
+ **Output:** `{phase_num}-context.md` — decisions clear enough that downstream agents can act without asking the user again
26
+ </objective>
27
+
28
+ <execution_context>
29
+ @~/.claude/pan-wizard-core/workflows/discuss-phase.md
30
+ @~/.claude/pan-wizard-core/templates/context.md
31
+ </execution_context>
32
+
33
+ <context>
34
+ Phase number: $ARGUMENTS (required)
35
+
36
+ Context files are resolved in-workflow using `init phase-op` and roadmap/state tool calls.
37
+ </context>
38
+
39
+ <process>
40
+ 1. Validate phase number (error if missing or not in roadmap)
41
+ 2. Check if context.md exists (offer update/view/skip if yes)
42
+ 3. **Analyze phase** — Identify domain and generate phase-specific gray areas
43
+ 4. **Present gray areas** — Multi-select: which to discuss? (NO skip option)
44
+ 5. **Deep-dive each area** — 4 questions per area, then offer more/next
45
+ 6. **Write context.md** — Sections match areas discussed
46
+ 7. Offer next steps (research or plan)
47
+
48
+ **CRITICAL: Scope guardrail**
49
+ - Phase boundary from roadmap.md is FIXED
50
+ - Discussion clarifies HOW to implement, not WHETHER to add more
51
+ - If user suggests new capabilities: "That's its own phase. I'll note it for later."
52
+ - Capture deferred ideas — don't lose them, don't act on them
53
+
54
+ **Domain-aware gray areas:**
55
+ Gray areas depend on what's being built. Analyze the phase goal:
56
+ - Something users SEE → layout, density, interactions, states
57
+ - Something users CALL → responses, errors, auth, versioning
58
+ - Something users RUN → output format, flags, modes, error handling
59
+ - Something users READ → structure, tone, depth, flow
60
+ - Something being ORGANIZED → criteria, grouping, naming, exceptions
61
+
62
+ Generate 3-4 **phase-specific** gray areas, not generic categories.
63
+
64
+ **Probing depth:**
65
+ - Ask 4 questions per area before checking
66
+ - "More questions about [area], or move to next?"
67
+ - If more → ask 4 more, check again
68
+ - After all areas → "Ready to create context?"
69
+
70
+ **Do NOT ask about (Claude handles these):**
71
+ - Technical implementation
72
+ - Architecture choices
73
+ - Performance concerns
74
+ - Scope expansion
75
+ </process>
76
+
77
+ <success_criteria>
78
+ - Gray areas identified through intelligent analysis
79
+ - User chose which areas to discuss
80
+ - Each selected area explored until satisfied
81
+ - Scope creep redirected to deferred ideas
82
+ - context.md captures decisions, not vague vision
83
+ - User knows next steps
84
+ </success_criteria>
@@ -0,0 +1,45 @@
1
+ ---
2
+ name: pan:exec-phase
3
+ group: Phase Lifecycle
4
+ description: Execute all plans in a phase with wave-based parallelization
5
+ argument-hint: "<phase-number> [--gaps-only] [--skip-tests] [--skip-review] [--fast]"
6
+ allowed-tools:
7
+ - Read
8
+ - Write
9
+ - Edit
10
+ - Glob
11
+ - Grep
12
+ - Bash
13
+ - Task
14
+ - TodoWrite
15
+ - AskUserQuestion
16
+ ---
17
+ <objective>
18
+ Execute all plans in a phase using wave-based parallel execution.
19
+
20
+ Orchestrator stays lean: discover plans, analyze dependencies, group into waves, spawn subagents, collect results. Each subagent loads the full execute-plan context and handles its own plan.
21
+
22
+ Context budget: ~15% orchestrator, 100% fresh per subagent.
23
+ </objective>
24
+
25
+ <execution_context>
26
+ @~/.claude/pan-wizard-core/workflows/exec-phase.md
27
+ @~/.claude/pan-wizard-core/references/ui-brand.md
28
+ </execution_context>
29
+
30
+ <context>
31
+ Phase: $ARGUMENTS
32
+
33
+ **Flags:**
34
+ - `--gaps-only` — Execute only gap closure plans (plans with `gap_closure: true` in frontmatter). Use after verify-work creates fix plans.
35
+ - `--skip-tests` — Skip automatic test generation after execution completes.
36
+ - `--skip-review` — Skip automatic code review after execution completes.
37
+ - `--fast` — Skip both test generation and code review (implies `--skip-tests --skip-review`).
38
+
39
+ Context files are resolved inside the workflow via `pan-tools init execute-phase` and per-subagent `<files_to_read>` blocks.
40
+ </context>
41
+
42
+ <process>
43
+ Execute the execute-phase workflow from @~/.claude/pan-wizard-core/workflows/exec-phase.md end-to-end.
44
+ Preserve all workflow gates (wave execution, checkpoint handling, verification, state updates, routing).
45
+ </process>
@@ -0,0 +1,323 @@
1
+ ---
2
+ name: focus-auto
3
+ group: Focus
4
+ description: Continuous scan-plan-exec loop with purpose-driven categories and 5-layer safety harness
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Edit
9
+ - Bash
10
+ - Grep
11
+ - Glob
12
+ - Agent
13
+ ---
14
+
15
+ # /pan:focus-auto — Continuous Autonomous Improvement Campaigns
16
+
17
+ Run purpose-driven improvement campaigns with a single command. The auto-runner orchestrates scan, plan, and exec cycles automatically with category-scoped scanning, intelligent defaults, and structured stopping.
18
+
19
+ **ADR:** ADR-0015 | **Heritage:** execplan budget + PanMonty categories + focus-exec pipeline
20
+
21
+ ## CRITICAL: Project Scope Boundary
22
+
23
+ This command runs improvement campaigns on the **host project's source code** — NOT on PAN Wizard's own infrastructure.
24
+
25
+ **ALWAYS EXCLUDE these directories from scanning and execution:**
26
+ - `.claude/`, `.github/copilot-instructions.md`, `.opencode/`, `.gemini/`, `.codex/` — PAN runtime directories
27
+ - Any `pan-wizard-core/`, `pan-tools`, agent `.md`, or command `.md` files within PAN runtime directories
28
+
29
+ **These directories are PAN's own tooling installed into the project.** Do not scan PAN files for TODOs, do not report PAN files as lacking coverage, do not modify PAN agents/commands/core as part of a campaign. If a scan finding or batch item targets a PAN infrastructure file — DROP IT.
30
+
31
+ ---
32
+
33
+ ## FIRST ACTION — Category Selection (if no --category argument)
34
+
35
+ If `$ARGUMENTS` does NOT contain `--category`, you MUST ask the user before doing anything else.
36
+
37
+ **Display this text menu and STOP — wait for the user to reply:**
38
+
39
+ ```
40
+ Which category should this auto campaign focus on?
41
+
42
+ 1. **cleanup** — Dead code, unused imports, duplicated logic, magic numbers (P3-P5)
43
+ 2. **stability** — Unguarded file ops, missing error handling, crash risks (P0-P2)
44
+ 3. **tests** — Missing test coverage, low assertion density (P2-P5)
45
+ 4. **features** — Roadmap items, new capabilities (P3-P5)
46
+ 5. **docs** — Stale documentation, missing command descriptions (P5-P6)
47
+ 6. **optimize** — Performance bottlenecks, redundant computation, robustness hardening (P1-P4)
48
+
49
+ Reply with a number (1-6) or category name.
50
+ ```
51
+
52
+ **After the user replies, map their response to a category name:**
53
+ - "1" or "cleanup" → SELECTED_CATEGORY = cleanup
54
+ - "2" or "stability" → SELECTED_CATEGORY = stability
55
+ - "3" or "tests" → SELECTED_CATEGORY = tests
56
+ - "4" or "features" → SELECTED_CATEGORY = features
57
+ - "5" or "docs" → SELECTED_CATEGORY = docs
58
+ - "6" or "optimize" → SELECTED_CATEGORY = optimize
59
+
60
+ **Do NOT proceed past this point without a category. Do NOT guess. Do NOT pick a default. STOP and wait for the user's reply.**
61
+
62
+ ## AUTONOMY RULES (apply AFTER category is selected)
63
+
64
+ - **DO NOT invoke the Skill tool.** All scan, plan, and exec work is done INLINE within this command.
65
+ - **DO NOT stop between phases.** Execute Phase 0 through Phase 3 (or until a safety harness triggers) without pausing.
66
+ - **DO NOT ask the user any more questions.** After category selection, run fully autonomously.
67
+ - **DO NOT show intermediate results.** Only display: the cycle summary line after each cycle, and the campaign summary table at the end.
68
+
69
+ ## Arguments
70
+
71
+ ```
72
+ /pan:focus-auto [--category CAT] [--mode MODE] [--budget N] [--max-cycles N]
73
+ [--total-budget N] [--continue] [--stop] [--status] [--dry-run]
74
+ ```
75
+
76
+ | Flag | Default | Description |
77
+ |------|---------|-------------|
78
+ | `--category` | null (all) | cleanup, tests, stability, features, docs |
79
+ | `--mode` | category-dependent | bugfix, balanced, features, full |
80
+ | `--budget` | category-dependent | Points per cycle (5-100) |
81
+ | `--max-cycles` | 10 | Maximum iterations (1-50) |
82
+ | `--total-budget` | 500 | Cumulative points cap (5-5000) |
83
+ | `--continue` | — | Resume stopped/interrupted run |
84
+ | `--stop` | — | Gracefully stop active run |
85
+ | `--status` | — | Show current campaign progress |
86
+ | `--dry-run` | — | Show plan without executing |
87
+
88
+ ## Category Defaults
89
+
90
+ | Category | Priority Range | Default Mode | Default Budget |
91
+ |----------|---------------|--------------|----------------|
92
+ | cleanup | P3-P5 | balanced | 50 |
93
+ | tests | P2-P5 | balanced | 50 |
94
+ | stability | P0-P2 | bugfix | 40 |
95
+ | features | P3-P5 | features | 50 |
96
+ | docs | P5-P6 | balanced | 30 |
97
+ | optimize | P1-P4 | balanced | 50 |
98
+
99
+ ## Pipeline
100
+
101
+ ### Phase 0: Initialization
102
+
103
+ 1. Parse arguments from `$ARGUMENTS`
104
+ 2. Handle quick operations first:
105
+ - If `--status`: run `pan-tools focus auto --status`, display result, STOP
106
+ - If `--stop`: run `pan-tools focus auto --stop`, display result, STOP
107
+ 3. If `--continue`:
108
+ - Run `pan-tools focus auto --continue` to resume
109
+ - Read the restored state to get category, mode, budget, etc.
110
+ - Skip to Phase 2 (Main Loop)
111
+ 4. If no `--category` was provided, you already displayed the menu in FIRST ACTION above. Use SELECTED_CATEGORY from the user's reply.
112
+ 5. Initialize new run using the category from step 4:
113
+ - Run `pan-tools focus auto --category <SELECTED_CATEGORY> [--mode MODE] [--budget N] [--max-cycles N] [--total-budget N] [--dry-run]`
114
+ - If `--dry-run`: display the plan, STOP
115
+ - Record the run state
116
+
117
+ ### Phase 1: Baseline Capture
118
+
119
+ 1. Run the project's test suite (discover the test command from `package.json` scripts, `Makefile`, or project docs)
120
+ 2. Record baseline test count from the summary line (e.g., "tests 1314")
121
+ 3. If tests fail: ERROR — "Cannot start: N tests failing. Fix tests before running auto campaign."
122
+ 4. Run `git status` to verify clean working tree (warn if dirty, don't block)
123
+ 5. Create safety tag: `git tag -f focus-auto-baseline`
124
+
125
+ ### Phase 2: Main Loop
126
+
127
+ **For each cycle (1 to max_cycles), execute Steps 2.1 through 2.5 without stopping:**
128
+
129
+ #### Step 2.1: Scan (INLINE — do NOT invoke /pan:focus-scan)
130
+
131
+ Perform a deep codebase scan to find actionable work items with evidence.
132
+
133
+ **2.1.1 Read Codebase State**
134
+ - Read project source files via Glob + Read: modules, entry points, key directories
135
+ - Read planning state: `.planning/config.json`, any state/roadmap files that exist
136
+ - Read `package.json` (or equivalent project manifest) for version and entry points
137
+
138
+ **2.1.2 Search for Issues**
139
+ - Grep for `TODO`, `FIXME`, `HACK`, `STUB` in source and test directories
140
+ - Grep for error-prone patterns relevant to the category:
141
+ - **stability:** unguarded `readdirSync`/`readFileSync` without try-catch, `existsSync` calls, `.forEach()` on unverified values, `parseInt` without NaN checks, `.match()` results accessed without null check
142
+ - **cleanup:** dead code, unused imports, duplicated logic, magic numbers
143
+ - **tests:** modules without corresponding test files, low assertion density
144
+ - **features:** roadmap items not yet implemented, README promises without backing code
145
+ - **docs:** stale documentation, missing command descriptions
146
+ - **optimize:** N+1 operations (file I/O / network calls inside loops), redundant re-computation (`JSON.parse`/`stringify` of same data), synchronous blocking in async modules (`readFileSync`/`execSync` alongside async exports), algorithmic complexity (nested `.find()`/`.filter()` in loops creating O(n²)+), unnecessary allocations in hot paths (spread in loops, string concat vs `join()`), regex construction inside loops (should be hoisted), unbounded collection growth (`.push()` without size limits), swallowed errors (`catch {}` / `catch { /* */ }`), suboptimal data structures (array `.includes()` where Set is better), dead assignments, unguarded property access on nullable values (`.length`/`.split()`/`.match()[0]` without null check)
147
+
148
+ **Optimize category: convergent re-scan.** On cycles 2+, cross-reference scan findings against previous cycle completions (`cycles[].items` in auto-run state). Only pick genuinely new items — skip IDs already completed or failed. If the count of new findings drops AND cycle efficiency drops below 30% of the prior cycle's, this signals convergence and the `diminishing_returns` stop condition fires.
149
+ - Use the Agent tool with Explore subagent for thorough analysis if needed
150
+ - Cross-reference findings with any previously completed scan items
151
+
152
+ **2.1.3 Classify Items**
153
+
154
+ | Priority | Focus | Criteria |
155
+ |----------|-------|----------|
156
+ | P0 | CRASH/ERROR | Runtime throws, uncaught exceptions |
157
+ | P1 | WRONG RESULTS | Silent corruption, incorrect output |
158
+ | P2 | TEST GAPS | Missing coverage, low assertion density |
159
+ | P3 | INCOMPLETE | Partially implemented features |
160
+ | P4 | NEW FEATURES | From roadmap, not yet started |
161
+ | P5 | TOOLING | DX improvements, CLI UX |
162
+ | P6 | DOCUMENTATION | Docs sync, reference updates |
163
+
164
+ For P3-P6 items, compute Reality Score: `RS = (UV + TC + RR) / JS`
165
+ - UV = User Value (1-5), TC = Time Criticality (1-5), RR = Risk Reduction (1-5)
166
+ - JS = Job Size: XS=1, S=2, M=3, L=5, XL=8
167
+ - RS >= 3.0 = DO, RS 1.5-2.9 = DEFER, RS < 1.5 = BACKLOG
168
+
169
+ **2.1.4 Filter by Category**
170
+ Only keep items within the run's category priority range (see Category Defaults table). Drop items outside the range. If 0 items match: go to Phase 3 (Campaign End).
171
+
172
+ **2.1.5 Write Scan**
173
+ Write scan results to `.planning/focus/scan-<YYYY-MM-DD>-<category>.md` with:
174
+ - Baseline snapshot table (version, tests, modules)
175
+ - Items grouped by priority tier, each with: ID, title, symptom, root cause, fix guidance, file paths, effort size
176
+ - Summary: item count by priority, total points
177
+
178
+ #### Step 2.2: Plan (INLINE — do NOT invoke /pan:focus-plan)
179
+
180
+ Create a capacity-budgeted batch from the scan items found in Step 2.1.
181
+
182
+ **Capacity Points:** XS=1, S=2, M=4, L=10, XL=20
183
+
184
+ **Allocation by Mode:**
185
+ - `bugfix`: All budget on P0 mandatory, then P1, then P2-P4 smallest-first. No feature work.
186
+ - `balanced`: 60% stability (P0-P2), 40% features (P3-P6)
187
+ - `features`: P0 mandatory, then 80% on P3-P5, 20% on P1-P2 quick wins
188
+ - `full`: All priorities equally weighted, largest-impact-first
189
+
190
+ **Execution Tiers:** XS/S = MICRO, M = STANDARD, L/XL = FULL
191
+ Select items fitting within the cycle's `budget_per_cycle`. Order: MICRO first, then STANDARD, then FULL.
192
+
193
+ Write batch to `.planning/focus/batch-<YYYY-MM-DD>-<category>.json`:
194
+ ```json
195
+ { "date": "...", "mode": "...", "budget": N, "allocated": N,
196
+ "items": [{ "order": N, "id": "...", "title": "...", "priority": "P1",
197
+ "size": "XS", "points": N, "tier": "MICRO", "file": "...", "fix": "..." }],
198
+ "deferred": [{ "id": "...", "title": "...", "reason": "..." }] }
199
+ ```
200
+
201
+ #### Step 2.3: Execute (INLINE — do NOT invoke /pan:focus-exec)
202
+
203
+ Implement each item from the batch created in Step 2.2. Record `tests_before` by running the test suite first.
204
+
205
+ **For each item in execution order:**
206
+
207
+ **MICRO items (XS/S):**
208
+ 1. Read target file(s) — always read before editing
209
+ 2. Implement the fix
210
+ 3. Run the specific test file for the changed module
211
+ 4. Pass = DONE | Fail = one fix attempt, then revert changes, mark FAILED
212
+
213
+ **STANDARD items (M):**
214
+ 1. State understanding: "Item X — Understanding: ..., Files: ..., Confidence: HIGH/MED"
215
+ 2. Read target files + test files
216
+ 3. Implement across necessary files
217
+ 4. Run the project's test suite
218
+ 5. Pass = DONE | Regression = revert all changes for this item, mark FAILED
219
+
220
+ **FULL items (L/XL):**
221
+ 1. State detailed understanding
222
+ 2. Read widely: target, callers, tests, related code
223
+ 3. Design approach before coding
224
+ 4. Implement in logical chunks
225
+ 5. Run the project's build step if applicable
226
+ 6. Run the project's test suite
227
+ 7. Pass = DONE | Fail = investigate (15 min max), then revert, mark FAILED
228
+
229
+ **After all items in the batch:**
230
+ 1. Run full test suite — ALL tests must pass
231
+ 2. Record `tests_after` from the summary line
232
+ 3. If `tests_after < tests_before`: REGRESSION — revert all changes for this cycle, mark all items FAILED
233
+ 4. Update the scan file: mark completed/failed items
234
+ 5. Stage specific changed files (not `git add -A`) and commit with accurate message listing only verified items
235
+ 6. Count: `items_completed`, `items_failed`, `points_used`
236
+
237
+ #### Step 2.4: Record Cycle
238
+
239
+ Run: `pan-tools focus auto --update --items-completed N --items-failed N --points-used N --tests-before N --tests-after N --batch-file <path>`
240
+
241
+ Check the response for stop conditions:
242
+ - `regression`: Tests decreased — STOP IMMEDIATELY
243
+ - `budget_cap`: Cumulative budget exceeded — go to Phase 3
244
+ - `max_cycles`: Maximum iterations reached — go to Phase 3
245
+ - `zero_completed`: No items completed in this cycle — go to Phase 3
246
+ - `diminishing_returns`: Optimize only — cycle efficiency < 30% of previous cycle — go to Phase 3
247
+ - `null`: Continue to next cycle
248
+
249
+ #### Step 2.5: Inter-Cycle Check
250
+
251
+ Display one-line cycle summary: `Cycle N/M | X/Y pts | Z items done | Tests: A -> B`
252
+
253
+ Then continue immediately to the next cycle (back to Step 2.1).
254
+
255
+ ### Phase 3: Campaign End
256
+
257
+ 1. Run `pan-tools focus auto --status` to get final state
258
+ 2. Display campaign summary:
259
+
260
+ ```
261
+ ## Campaign Complete
262
+
263
+ | Metric | Value |
264
+ |--------|-------|
265
+ | Category | <category> |
266
+ | Cycles | N completed |
267
+ | Items completed | X |
268
+ | Items failed | Y |
269
+ | Points used | Z / total_budget |
270
+ | Tests | baseline -> current (delta) |
271
+ | Stop reason | <reason> |
272
+ ```
273
+
274
+ 3. Remove safety tag: `git tag -d focus-auto-baseline 2>/dev/null`
275
+
276
+ ## 5-Layer Safety Harness
277
+
278
+ | Layer | Mechanism | Action |
279
+ |-------|-----------|--------|
280
+ | Per-cycle budget | `--budget N` per cycle | Limits single-cycle damage |
281
+ | Cumulative budget | `--total-budget N` | Prevents runaway spending |
282
+ | Iteration limit | `--max-cycles N` | Hard stop on loop count |
283
+ | Regression circuit breaker | tests_after < tests_before | Immediate stop, status=stopped |
284
+ | Zero-completed guard | 0 items done in a cycle | Stop — further cycles won't help |
285
+
286
+ ## 9 Behavioral Rules
287
+
288
+ 1. **Read Before Write** — Read every file before editing. Understand context, callers, invariants.
289
+ 2. **Root Cause** — Fix the actual defect, not symptoms. Trace the code path.
290
+ 3. **One Change, One Test** — Test after every code change. MICRO: specific test. STANDARD/FULL: full suite.
291
+ 4. **Follow the Plan** — Implement exactly what the batch says. No scope creep.
292
+ 5. **Cross-Platform** — Use platform-agnostic path APIs. Follow the project's module format conventions.
293
+ 6. **Revert Fast** — 5 min limit on debugging a single failure, then revert and mark FAILED.
294
+ 7. **Verify Understanding** — State understanding for M+ items before coding.
295
+ 8. **Preserve Tests** — Never change test expectations to match broken code.
296
+ 9. **Accurate Commits** — Only claim verified items in commit messages. Include actual test counts.
297
+
298
+ ## NEVER DO
299
+
300
+ - Invoke the Skill tool (no `/pan:focus-scan`, `/pan:focus-plan`, `/pan:focus-exec`)
301
+ - Stop or pause between phases (unless a safety harness triggers)
302
+ - Ask the user questions after category selection (Phases 1-3 are fully autonomous)
303
+ - Skip the baseline test capture (Phase 1)
304
+ - Continue after a test regression (circuit breaker is mandatory)
305
+ - Expand scope beyond what the scan found
306
+ - Run more cycles than --max-cycles
307
+ - Spend more points than --total-budget
308
+ - Skip recording cycle results via --update
309
+ - Change test expectations to match broken code
310
+ - Use `git add -A` or `git add .` — stage specific files only
311
+
312
+ ## ALWAYS DO
313
+
314
+ - Execute all phases autonomously from start to finish
315
+ - Capture baseline before first cycle
316
+ - Read every file before editing it
317
+ - Test after every code change
318
+ - Record every cycle via `pan-tools focus auto --update`
319
+ - Stop on ANY safety harness trigger
320
+ - Revert fast when stuck (5 min limit)
321
+ - Display one-line cycle summary between cycles
322
+ - Display campaign summary table at end
323
+ - Commit once per cycle with accurate item list