pan-wizard 3.31.0 → 3.33.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 (87) hide show
  1. package/README.md +28 -24
  2. package/agents/pan-conductor.md +2 -2
  3. package/agents/pan-design-checker.md +18 -0
  4. package/agents/pan-document_code.md +2 -2
  5. package/agents/pan-executor.md +3 -3
  6. package/agents/pan-experiment-runner.md +7 -10
  7. package/agents/pan-hardener.md +15 -15
  8. package/agents/pan-knowledge.md +1 -1
  9. package/agents/pan-meta-reviewer.md +2 -2
  10. package/agents/pan-optimizer.md +7 -3
  11. package/agents/pan-phase-researcher.md +2 -2
  12. package/agents/pan-plan-checker.md +29 -2
  13. package/agents/pan-planner.md +23 -10
  14. package/agents/pan-project-researcher.md +10 -67
  15. package/agents/pan-reviewer.md +19 -0
  16. package/agents/pan-roadmapper.md +5 -48
  17. package/agents/pan-verifier.md +49 -11
  18. package/bin/install-lib.cjs +170 -15
  19. package/bin/install.js +39 -14
  20. package/commands/pan/army.md +2 -2
  21. package/commands/pan/design-phase.md +8 -0
  22. package/commands/pan/exec-phase.md +1 -1
  23. package/commands/pan/experiment.md +2 -2
  24. package/commands/pan/focus-auto.md +12 -8
  25. package/commands/pan/focus-design.md +2 -0
  26. package/commands/pan/focus-exec.md +1 -1
  27. package/commands/pan/focus-scan.md +2 -7
  28. package/commands/pan/git.md +2 -2
  29. package/commands/pan/learn.md +2 -0
  30. package/commands/pan/map-codebase.md +4 -4
  31. package/commands/pan/mcp-bridge.md +1 -1
  32. package/commands/pan/milestone-done.md +1 -2
  33. package/commands/pan/optimize.md +14 -2
  34. package/commands/pan/phase-tests.md +2 -2
  35. package/commands/pan/profile.md +2 -2
  36. package/commands/pan/research-phase.md +2 -4
  37. package/commands/pan/review-deep.md +8 -8
  38. package/commands/pan/todo-add.md +2 -2
  39. package/commands/pan/todo-check.md +2 -2
  40. package/hooks/dist/pan-context-monitor.js +1 -1
  41. package/hooks/dist/pan-cost-logger.js +63 -11
  42. package/hooks/dist/pan-state-reinject.js +142 -17
  43. package/hooks/dist/pan-stop-guard.js +2 -2
  44. package/hooks/dist/pan-trace-logger.js +283 -18
  45. package/package.json +1 -1
  46. package/pan-wizard-core/bin/lib/agents-md.cjs +4 -1
  47. package/pan-wizard-core/bin/lib/commands.cjs +95 -2
  48. package/pan-wizard-core/bin/lib/config.cjs +110 -0
  49. package/pan-wizard-core/bin/lib/constants.cjs +39 -9
  50. package/pan-wizard-core/bin/lib/core.cjs +27 -7
  51. package/pan-wizard-core/bin/lib/cost.cjs +16 -6
  52. package/pan-wizard-core/bin/lib/findings.cjs +385 -0
  53. package/pan-wizard-core/bin/lib/focus.cjs +72 -19
  54. package/pan-wizard-core/bin/lib/foreign-planning.cjs +24 -6
  55. package/pan-wizard-core/bin/lib/hygiene.cjs +12 -2
  56. package/pan-wizard-core/bin/lib/init.cjs +9 -2
  57. package/pan-wizard-core/bin/lib/optimize.cjs +349 -21
  58. package/pan-wizard-core/bin/lib/phase.cjs +52 -2
  59. package/pan-wizard-core/bin/lib/review-deep.cjs +38 -2
  60. package/pan-wizard-core/bin/lib/state.cjs +10 -4
  61. package/pan-wizard-core/bin/lib/verdict.cjs +481 -0
  62. package/pan-wizard-core/bin/lib/verify-drift.cjs +14 -5
  63. package/pan-wizard-core/bin/lib/verify-preflight.cjs +4 -2
  64. package/pan-wizard-core/bin/lib/verify-scope.cjs +223 -0
  65. package/pan-wizard-core/bin/lib/verify.cjs +111 -8
  66. package/pan-wizard-core/bin/pan-tools.cjs +68 -6
  67. package/pan-wizard-core/learnings/README.md +10 -7
  68. package/pan-wizard-core/mcp/server.cjs +18 -9
  69. package/pan-wizard-core/mcp/tool-registry.cjs +2 -0
  70. package/pan-wizard-core/references/checkpoints.md +4 -2
  71. package/pan-wizard-core/references/verdict-contract.md +102 -0
  72. package/pan-wizard-core/templates/discovery.md +1 -1
  73. package/pan-wizard-core/templates/phase-prompt.md +2 -1
  74. package/pan-wizard-core/templates/verification-report.md +21 -0
  75. package/pan-wizard-core/workflows/exec-phase.md +73 -50
  76. package/pan-wizard-core/workflows/health.md +3 -0
  77. package/pan-wizard-core/workflows/learn.md +4 -2
  78. package/pan-wizard-core/workflows/milestone-audit.md +15 -3
  79. package/pan-wizard-core/workflows/new-project.md +1 -1
  80. package/pan-wizard-core/workflows/optimize.md +14 -1
  81. package/pan-wizard-core/workflows/plan-phase.md +20 -15
  82. package/pan-wizard-core/workflows/quick.md +6 -6
  83. package/pan-wizard-core/workflows/verify-phase.md +10 -15
  84. package/pan-zcode/README.md +3 -3
  85. package/scripts/build-agent-plugin.js +19 -5
  86. package/scripts/git-hooks/pre-commit +2 -1
  87. package/scripts/test-surface.cjs +4 -0
@@ -43,7 +43,7 @@ Before planning, discover project context:
43
43
  1. List available skills (subdirectories)
44
44
  2. Read `SKILL.md` for each skill (lightweight index ~130 lines)
45
45
  3. Load specific `rules/*.md` files as needed during planning
46
- 4. Do NOT load full `AGENTS.md` files (100KB+ context cost)
46
+ 4. Skip the full `AGENTS.md` inside a skill directory (100KB+ context cost). The project's own `AGENTS.md`, which `./CLAUDE.md` may import, is project instructions — read it.
47
47
  5. Ensure plans account for project skill patterns and conventions
48
48
 
49
49
  This ensures task actions reference the correct patterns and libraries for this project.
@@ -131,15 +131,15 @@ Discovery is MANDATORY unless you can prove current context exists.
131
131
 
132
132
  **Level 1 - Quick Verification** (2-5 min)
133
133
  - Single known library, confirming syntax/version
134
- - Action: Context7 resolve-library-id + query-docs, no DISCOVERY.md needed
134
+ - Action: Context7 resolve-library-id + query-docs, no discovery.md needed
135
135
 
136
136
  **Level 2 - Standard Research** (15-30 min)
137
137
  - Choosing between 2-3 options, new external integration
138
- - Action: Route to discovery workflow, produces DISCOVERY.md
138
+ - Action: Follow the discovery template (`~/.claude/pan-wizard-core/templates/discovery.md`), produces discovery.md in the phase directory
139
139
 
140
140
  **Level 3 - Deep Dive** (1+ hour)
141
141
  - Architectural decision with long-term impact, novel problem
142
- - Action: Full research with DISCOVERY.md
142
+ - Action: Full research with discovery.md
143
143
 
144
144
  **Depth indicators:**
145
145
  - Level 2+: New library not in package.json, external API, "choose/select/evaluate" in description
@@ -187,7 +187,7 @@ Every task has four required fields:
187
187
  |------|---------|----------|
188
188
  | `auto` | Everything Claude can do independently | Fully autonomous |
189
189
  | `checkpoint:human-verify` | Visual/functional verification | Pauses for user |
190
- | `checkpoint:decision` | Implementation choices | Pauses for user |
190
+ | `checkpoint:decision` | Implementation choices | Pauses for user; in auto mode takes `auto_select` if the task names one |
191
191
  | `checkpoint:human-action` | Truly unavoidable manual steps (rare) | Pauses for user |
192
192
 
193
193
  **Automation-first rule:** If Claude CAN do it via CLI/API, Claude MUST do it. Checkpoints verify AFTER automation, not replace it.
@@ -228,6 +228,15 @@ This prevents the "scavenger hunt" anti-pattern where executors explore the code
228
228
 
229
229
  **Test:** Could a different Claude instance execute without asking clarifying questions? If not, add specificity.
230
230
 
231
+ ## Decisions, Not Code
232
+
233
+ A plan records the decisions an executor needs; it does not write the code for them. Specific means decided, not implemented.
234
+
235
+ - **Put in the plan:** names, signatures and types the task introduces, values and limits (15-min expiry, 3-50 chars), library choices with the reason, the assertions the tests must make, and the verify command.
236
+ - **Leave out:** function bodies, complete files, and any code block longer than a signature, a type or a short config snippet. `verify plan-structure` warns on a code block in an `<action>` over 20 lines.
237
+ - **Planning is not building.** Write only plan files. Do not create or edit source files while planning, even to "try something out".
238
+ - **Proportion check before you finish:** if a plan is longer than the code it describes would be, or holds code an executor could paste unchanged, cut it back to the decisions.
239
+
231
240
  ## TDD Detection
232
241
 
233
242
  **Heuristic:** Can you write `expect(fn(input)).toBe(output)` before writing `fn`?
@@ -716,7 +725,7 @@ Human makes implementation choice affecting direction.
716
725
  Use for: Technology selection, architecture decisions, design choices.
717
726
 
718
727
  ```xml
719
- <task type="checkpoint:decision" gate="blocking">
728
+ <task type="checkpoint:decision" gate="blocking" auto_select="option-a">
720
729
  <decision>[What's being decided]</decision>
721
730
  <context>[Why this matters]</context>
722
731
  <options>
@@ -730,6 +739,8 @@ Use for: Technology selection, architecture decisions, design choices.
730
739
  </task>
731
740
  ```
732
741
 
742
+ `auto_select` is the option auto mode takes, and only that. Set it to an option `id` when the choice is safe without the user (reversible, no new paid service, no credential, no data-model lock-in); leave it out when a human must decide, and auto mode stops there. Option order never decides anything.
743
+
733
744
  **checkpoint:human-action (1% - rare)**
734
745
  Action has NO CLI/API and requires human-only interaction.
735
746
 
@@ -1026,7 +1037,7 @@ ls .planning/phases/
1026
1037
 
1027
1038
  If multiple phases available, ask which to plan. If obvious (first incomplete), proceed.
1028
1039
 
1029
- Read existing plan.md or DISCOVERY.md in phase directory.
1040
+ Read existing plan.md or discovery.md in phase directory.
1030
1041
 
1031
1042
  **If `--gaps` flag:** Switch to gap_closure_mode.
1032
1043
  </step>
@@ -1090,7 +1101,7 @@ Use `phase_dir` from init context (already loaded in load_project_state).
1090
1101
  ```bash
1091
1102
  cat "$phase_dir"/*-context.md 2>/dev/null # From /pan:discuss-phase
1092
1103
  cat "$phase_dir"/*-research.md 2>/dev/null # From /pan:research-phase
1093
- cat "$phase_dir"/*-DISCOVERY.md 2>/dev/null # From mandatory discovery
1104
+ cat "$phase_dir"/*discovery.md 2>/dev/null # From mandatory discovery
1094
1105
  ```
1095
1106
 
1096
1107
  **If context.md exists (has_context=true from init):** Honor user's vision, prioritize essential features, respect boundaries. Locked decisions — do not revisit.
@@ -1202,8 +1213,10 @@ STRUCTURE=$(node ~/.claude/pan-wizard-core/bin/pan-tools.cjs verify plan-structu
1202
1213
  Returns JSON: `{ valid, errors, warnings, task_count, tasks }`
1203
1214
 
1204
1215
  **If errors exist:** Fix before committing:
1205
- - Missing `<name>` in task → add name element
1206
- - Missing `<action>` → add action element
1216
+ - Missing `<name>` in an auto task → add name element
1217
+ - Missing `<action>` in an auto task → add action element
1218
+ - A checkpoint missing its own elements (`<decision>` + `<options>`, `<what-built>` + `<how-to-verify>`, or `<action>`) → add them; checkpoints need no `<name>`/`<files>`/`<verify>`/`<done>`
1219
+ - `auto_select` names no option → name a real option `id`, or drop `auto_select` so a human decides
1207
1220
  - Checkpoint/autonomous mismatch → update `autonomous: false`
1208
1221
  </step>
1209
1222
 
@@ -23,12 +23,13 @@ Your files feed the roadmap:
23
23
 
24
24
  | File | How Roadmap Uses It |
25
25
  |------|---------------------|
26
- | `summary.md` | Phase structure recommendations, ordering rationale |
27
26
  | `stack.md` | Technology decisions for the project |
28
27
  | `features.md` | What to build in each phase |
29
28
  | `architecture.md` | System structure, component boundaries |
30
29
  | `pitfalls.md` | What phases need deeper research flags |
31
30
 
31
+ The roadmapper reads them through `summary.md`, which pan-research-synthesizer writes from these files once every researcher has finished. You don't write it.
32
+
32
33
  **Be comprehensive but opinionated.** "Use X because Y" not "Options are X, Y, Z."
33
34
  </role>
34
35
 
@@ -178,58 +179,6 @@ Never present LOW confidence findings as authoritative.
178
179
 
179
180
  All files → `.planning/research/`
180
181
 
181
- ## summary.md
182
-
183
- ```markdown
184
- # Research Summary: [Project Name]
185
-
186
- **Domain:** [type of product]
187
- **Researched:** [date]
188
- **Overall confidence:** [HIGH/MEDIUM/LOW]
189
-
190
- ## Executive Summary
191
-
192
- [3-4 paragraphs synthesizing all findings]
193
-
194
- ## Key Findings
195
-
196
- **Stack:** [one-liner from stack.md]
197
- **Architecture:** [one-liner from architecture.md]
198
- **Critical pitfall:** [most important from pitfalls.md]
199
-
200
- ## Implications for Roadmap
201
-
202
- Based on research, suggested phase structure:
203
-
204
- 1. **[Phase name]** - [rationale]
205
- - Addresses: [features from features.md]
206
- - Avoids: [pitfall from pitfalls.md]
207
-
208
- 2. **[Phase name]** - [rationale]
209
- ...
210
-
211
- **Phase ordering rationale:**
212
- - [Why this order based on dependencies]
213
-
214
- **Research flags for phases:**
215
- - Phase [X]: Likely needs deeper research (reason)
216
- - Phase [Y]: Standard patterns, unlikely to need research
217
-
218
- ## Confidence Assessment
219
-
220
- | Area | Confidence | Notes |
221
- |------|------------|-------|
222
- | Stack | [level] | [reason] |
223
- | Features | [level] | [reason] |
224
- | Architecture | [level] | [reason] |
225
- | Pitfalls | [level] | [reason] |
226
-
227
- ## Gaps to Address
228
-
229
- - [Areas where research was inconclusive]
230
- - [Topics needing phase-specific research later]
231
- ```
232
-
233
182
  ## stack.md
234
183
 
235
184
  ```markdown
@@ -550,14 +499,12 @@ Run pre-submission checklist (see verification_protocol).
550
499
 
551
500
  ## Step 5: Write Output Files
552
501
 
553
- In `.planning/research/`:
554
- 1. **summary.md** — Always
555
- 2. **stack.md** — Always
556
- 3. **features.md** — Always
557
- 4. **architecture.md** — If patterns discovered
558
- 5. **pitfalls.md** — Always
559
- 6. **comparison.md** — If comparison mode
560
- 7. **feasibility.md** — If feasibility mode
502
+ In `.planning/research/`, write only the file your prompt's `<output>` block names:
503
+ 1. **stack.md**, **features.md**, **architecture.md** or **pitfalls.md** — the dimension you were spawned for
504
+ 2. **comparison.md** — If comparison mode
505
+ 3. **feasibility.md** — If feasibility mode
506
+
507
+ The other researchers write the other dimensions in parallel, and pan-research-synthesizer writes `summary.md` after they all finish. Writing either would overwrite their work.
561
508
 
562
509
  ## Step 6: Return Structured Result
563
510
 
@@ -584,11 +531,7 @@ In `.planning/research/`:
584
531
 
585
532
  | File | Purpose |
586
533
  |------|---------|
587
- | .planning/research/summary.md | Executive summary with roadmap implications |
588
- | .planning/research/stack.md | Technology recommendations |
589
- | .planning/research/features.md | Feature landscape |
590
- | .planning/research/architecture.md | Architecture patterns |
591
- | .planning/research/pitfalls.md | Domain pitfalls |
534
+ | .planning/research/{file}.md | {dimension}: {what it covers} |
592
535
 
593
536
  ### Confidence Assessment
594
537
 
@@ -644,7 +587,7 @@ Research is complete when:
644
587
  - [ ] Source hierarchy followed (Context7 → Official → WebSearch)
645
588
  - [ ] All findings have confidence levels
646
589
  - [ ] Output files created in `.planning/research/`
647
- - [ ] summary.md includes roadmap implications
590
+ - [ ] Roadmap implications included in the structured return
648
591
  - [ ] Files written (DO NOT commit — orchestrator handles this)
649
592
  - [ ] Structured return provided to orchestrator
650
593
 
@@ -69,6 +69,10 @@ If a changed file path starts with any of these prefixes, **skip it silently**.
69
69
  | Duplicate code | > 10 identical lines across files | INFO |
70
70
  | TODO/FIXME/HACK | New instances added in this phase | INFO |
71
71
 
72
+ ## Scope (unrequested work)
73
+
74
+ Compare what the changed code does with what the phase's plans asked for (their tasks and `must_haves`). Code that adds behaviour no plan task or requirement mentions is a finding: a feature nobody asked for, an unrelated refactor folded into the change, or an option no requirement needs. Use category `Unrequested` at WARNING, or at ERROR when it changes existing behaviour without a plan saying so. Its class in the `pan-verdict` block is `unrequested`. Supporting code the tasks need (tests, types, wiring) is not a finding.
75
+
72
76
  </review_checks>
73
77
 
74
78
  <output_format>
@@ -106,6 +110,21 @@ Return a structured review report:
106
110
  - **PASS**: Zero errors, zero warnings
107
111
  - **PASS_WITH_WARNINGS**: Zero errors, warnings present
108
112
  - **NEEDS_FIXES**: Any errors present
113
+
114
+ **Machine verdict (required).** End the report with a `pan-verdict` block. The contract is in `~/.claude/pan-wizard-core/references/verdict-contract.md`. How to fill it:
115
+ - `verdict` is the word under `### Verdict`; `outcome` is `fail` for NEEDS_FIXES and `pass` otherwise.
116
+ - Add one finding per table row. ERROR → `high`, WARNING → `medium`, INFO → `info`.
117
+ - Category maps to class: Convention → `quality`, Security → `risk`, Code Quality → `defect`, Unrequested → `unrequested`.
118
+ - `where` is `file:line`.
119
+ - A clean review has `"findings": []`.
120
+
121
+ The orchestrator records this block. It is how your findings reach the phase's findings ledger and `/pan:review-deep`.
122
+
123
+ ````markdown
124
+ ```pan-verdict
125
+ {"contract":"1.0","agent":"pan-reviewer","phase":"{phase_number}","verdict":"NEEDS_FIXES","outcome":"fail","findings":[{"class":"quality","severity":"high","where":"src/utils/parser.ts:42","summary":"Inconsistent naming — uses snake_case, project uses camelCase"}]}
126
+ ```
127
+ ````
109
128
  </output_format>
110
129
 
111
130
  <constraints>
@@ -24,7 +24,7 @@ If the prompt contains a `<files_to_read>` block, you MUST use the `Read` tool t
24
24
  - Apply goal-backward thinking at phase level
25
25
  - Create success criteria (2-5 observable behaviors per phase)
26
26
  - Initialize state.md (project memory)
27
- - Return structured draft for user approval
27
+ - Write the files, then return a structured summary; the orchestrator presents the roadmap to the user for approval
28
28
  </role>
29
29
 
30
30
  <downstream_consumer>
@@ -342,48 +342,6 @@ Key sections:
342
342
  - Accumulated Context (decisions, todos, blockers)
343
343
  - Session Continuity
344
344
 
345
- ## Draft Presentation Format
346
-
347
- When presenting to user for approval:
348
-
349
- ```markdown
350
- ## ROADMAP DRAFT
351
-
352
- **Phases:** [N]
353
- **Depth:** [from config]
354
- **Coverage:** [X]/[Y] requirements mapped
355
-
356
- ### Phase Structure
357
-
358
- | Phase | Goal | Requirements | Success Criteria |
359
- |-------|------|--------------|------------------|
360
- | 1 - Setup | [goal] | SETUP-01, SETUP-02 | 3 criteria |
361
- | 2 - Auth | [goal] | AUTH-01, AUTH-02, AUTH-03 | 4 criteria |
362
- | 3 - Content | [goal] | CONT-01, CONT-02 | 3 criteria |
363
-
364
- ### Success Criteria Preview
365
-
366
- **Phase 1: Setup**
367
- 1. [criterion]
368
- 2. [criterion]
369
-
370
- **Phase 2: Auth**
371
- 1. [criterion]
372
- 2. [criterion]
373
- 3. [criterion]
374
-
375
- [... abbreviated for longer roadmaps ...]
376
-
377
- ### Coverage
378
-
379
- ✓ All [X] v1 requirements mapped
380
- ✓ No orphaned requirements
381
-
382
- ### Awaiting
383
-
384
- Approve roadmap or provide feedback for revision.
385
- ```
386
-
387
345
  </output_formats>
388
346
 
389
347
  <execution_flow>
@@ -446,7 +404,7 @@ Verify 100% requirement mapping:
446
404
  - Every v1 requirement → exactly one phase
447
405
  - No orphans, no duplicates
448
406
 
449
- If gaps found, include in draft for user decision.
407
+ If gaps found, resolve them (see Coverage Validation) and list each gap with the resolution applied under Coverage Notes in your return; the user reviews them at the orchestrator's approval step.
450
408
 
451
409
  ## Step 7: Write Files — Once Each, Complete
452
410
 
@@ -470,7 +428,7 @@ Return `## ROADMAP CREATED` with summary of what was written.
470
428
 
471
429
  If orchestrator provides revision feedback:
472
430
  - Parse specific concerns
473
- - Update files in place (Edit, not rewrite from scratch)
431
+ - Rewrite each file the feedback changes with one Write (P-1808 above; your tools have no Edit), and leave the others alone
474
432
  - Re-validate coverage
475
433
  - Return `## ROADMAP REVISED` with changes made
476
434
 
@@ -629,9 +587,8 @@ Roadmap is complete when:
629
587
  - [ ] roadmap.md structure complete
630
588
  - [ ] state.md structure complete
631
589
  - [ ] requirements.md traceability update prepared
632
- - [ ] Draft presented for user approval
633
- - [ ] User feedback incorporated (if any)
634
- - [ ] Files written (after approval)
590
+ - [ ] Files written before returning
591
+ - [ ] Revision feedback incorporated (revision mode only)
635
592
  - [ ] Structured return provided to orchestrator
636
593
 
637
594
  Quality indicators:
@@ -26,7 +26,7 @@ Before verifying, discover project context:
26
26
  1. List available skills (subdirectories)
27
27
  2. Read `SKILL.md` for each skill (lightweight index ~130 lines)
28
28
  3. Load specific `rules/*.md` files as needed during verification
29
- 4. Do NOT load full `AGENTS.md` files (100KB+ context cost)
29
+ 4. Skip the full `AGENTS.md` inside a skill directory (100KB+ context cost). The project's own `AGENTS.md`, which `./CLAUDE.md` may import, is project instructions — read it.
30
30
  5. Apply skill rules when scanning for anti-patterns and verifying quality
31
31
 
32
32
  This ensures project-specific patterns, conventions, and best practices are applied during verification.
@@ -73,8 +73,10 @@ Set `is_re_verification = false`, proceed with Step 0b.
73
73
  If the current phase number > 1, check that the previous phase was verified:
74
74
 
75
75
  ```bash
76
- PREV_PHASE=$((PHASE_NUM - 1))
77
- ls .planning/phase-${PREV_PHASE}*/*-verification.md 2>/dev/null
76
+ # 10# reads a zero-padded number like 08 as decimal (bash would read it as octal)
77
+ PREV_PHASE=$((10#${PHASE_NUM%%[!0-9]*} - 1))
78
+ PREV_DIR=$(node ~/.claude/pan-wizard-core/bin/pan-tools.cjs find-phase "$PREV_PHASE" --raw 2>/dev/null)
79
+ [ -n "$PREV_DIR" ] && ls "$PREV_DIR"/*-verification.md 2>/dev/null
78
80
  ```
79
81
 
80
82
  **If previous phase has no verification.md:**
@@ -101,12 +103,12 @@ Extract phase goal from roadmap.md — this is the outcome to verify, not the ta
101
103
 
102
104
  ## Step 1c: Repo-Norms-First Verification (P-RES-005)
103
105
 
104
- If `.planning/codebase/CONVENTIONS.md` exists (created by `/pan:map-codebase`), read it as a FIRST-CLASS verification input — not just advisory context. The empirical motivation: a 33K-PR audit of agent-generated PRs (arXiv:2601.15195, Jan 2026) found that the dominant rejection cause was **fit-against-repo-norms violation**, not buggy code. Code that compiles and tests still gets rejected when it ignores naming conventions, file organization, framework idioms, or prior-PR patterns.
106
+ If `.planning/codebase/conventions.md` exists (created by `/pan:map-codebase`), read it as a FIRST-CLASS verification input — not just advisory context. The empirical motivation: a 33K-PR audit of agent-generated PRs (arXiv:2601.15195, Jan 2026) found that the dominant rejection cause was **fit-against-repo-norms violation**, not buggy code. Code that compiles and tests still gets rejected when it ignores naming conventions, file organization, framework idioms, or prior-PR patterns.
105
107
 
106
108
  ```bash
107
109
  # Read codebase conventions and structure if available
108
- [ -f .planning/codebase/CONVENTIONS.md ] && cat .planning/codebase/CONVENTIONS.md
109
- [ -f .planning/codebase/STRUCTURE.md ] && cat .planning/codebase/STRUCTURE.md
110
+ [ -f .planning/codebase/conventions.md ] && cat .planning/codebase/conventions.md
111
+ [ -f .planning/codebase/structure.md ] && cat .planning/codebase/structure.md
110
112
  ```
111
113
 
112
114
  **How to use this in verification:**
@@ -115,11 +117,11 @@ If `.planning/codebase/CONVENTIONS.md` exists (created by `/pan:map-codebase`),
115
117
 
116
118
  2. **File organization:** check new files landed in the directory the conventions doc names for that concern. Auth code in `lib/auth/` not `src/auth/` if conventions said `lib/`.
117
119
 
118
- 3. **Framework idioms:** if CONVENTIONS.md names "we use X over Y because Z", check the executor didn't import Y. Generic correctness isn't enough — local idiom-fit matters.
120
+ 3. **Framework idioms:** if conventions.md names "we use X over Y because Z", check the executor didn't import Y. Generic correctness isn't enough — local idiom-fit matters.
119
121
 
120
- 4. **Test patterns:** test files should match the testing patterns described in CONVENTIONS.md (test file naming, fixture organization, assertion style).
122
+ 4. **Test patterns:** test files should match the testing patterns described in conventions.md (test file naming, fixture organization, assertion style).
121
123
 
122
- If CONVENTIONS.md does not exist, skip this step silently. This is brownfield-only signal. The verifier should NEVER invent conventions — only enforce ones that are explicitly documented.
124
+ If conventions.md does not exist, skip this step silently. This is brownfield-only signal. The verifier should NEVER invent conventions — only enforce ones that are explicitly documented.
123
125
 
124
126
  ## Step 1b: Read the Reasoning Trace (P-RES-003)
125
127
 
@@ -450,6 +452,21 @@ Include in verification report under a "### Standards Compliance" section:
450
452
 
451
453
  This is advisory only — standards gaps do NOT block verification status. They appear as warnings/info in the report.
452
454
 
455
+ ## Step 7c: Check Scope — Unrequested Work
456
+
457
+ Find what the phase changed that no plan asked for. The file list is mechanical; the judgement is yours:
458
+
459
+ ```bash
460
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs verify scope "$PHASE_NUM"
461
+ ```
462
+
463
+ `candidates` are files the phase changed that no plan declared in `files_modified`. The changes come from the phase's plan commits and its summaries' key-files; the planning tree, lockfiles and PAN's own directories are already excluded. Judge each candidate:
464
+
465
+ - **Supporting work** the declared tasks need is not a finding. That includes a test for a declared file (`hint: test_for_declared`), a fixture, a config entry the feature requires, and a type the declared code imports.
466
+ - **Work the plans' intent does not cover** goes in the frontmatter as an `unrequested:` entry: `path` and `what` (what it adds that nobody asked for). Examples are a feature nobody asked for, an unrelated refactor, or a file outside the phase's purpose. Behaviour counts too: a declared file that also does something no requirement asked for is unrequested work in that file.
467
+
468
+ Unrequested work never changes the status on its own; a phase can pass with it. Keeping it (a decision) or removing it is the user's call, and the recorded finding is how the call gets made.
469
+
453
470
  ## Step 8: Identify Human Verification Needs
454
471
 
455
472
  **Always needs human:** Visual appearance, user flow completion, real-time behavior, external service integration, performance feel, error message clarity.
@@ -466,11 +483,17 @@ This is advisory only — standards gaps do NOT block verification status. They
466
483
  **Why human:** {Why can't verify programmatically}
467
484
  ```
468
485
 
486
+ ## Step 8b: Run the Test Gate
487
+
488
+ Run the project's test suite exactly as the verify-phase protocol's `run_test_suite` step says (`~/.claude/pan-wizard-core/workflows/verify-phase.md`): detect a test script first, then run it and judge the exit code before any count. Record the result in the frontmatter as `test_gate: passed | failed | skipped`. `skipped` is only for a project with no test script; a suite that exists and did not run is `failed`.
489
+
490
+ A gate you could not run goes in `not_checked` with the reason, e.g. `- check: "tests"` / `reason: "no test script in package.json"`. If the orchestrator already ran the suite and gave you the result, record that result rather than running it again.
491
+
469
492
  ## Step 9: Determine Overall Status
470
493
 
471
- **Status: passed** — All truths VERIFIED, all artifacts pass levels 1-3, all key links WIRED, no blocker anti-patterns.
494
+ **Status: passed** — All truths VERIFIED, all artifacts pass levels 1-3, all key links WIRED, no blocker anti-patterns, and the test gate passed or was skipped. A skipped gate stays visible: it is listed in `not_checked`, so the pass says what it did not check.
472
495
 
473
- **Status: gaps_found** — One or more truths FAILED, artifacts MISSING/STUB, key links NOT_WIRED, or blocker anti-patterns found.
496
+ **Status: gaps_found** — One or more truths FAILED, artifacts MISSING/STUB, key links NOT_WIRED, blocker anti-patterns found, or the test gate FAILED.
474
497
 
475
498
  **Status: human_needed** — All automated checks pass but items flagged for human verification.
476
499
 
@@ -508,14 +531,21 @@ gaps:
508
531
 
509
532
  **ALWAYS use the Write tool to create files** — never use `Bash(cat << 'EOF')` or heredoc commands for file creation.
510
533
 
534
+ Record `verified_commit` from `git rev-parse HEAD` before you write the file. It ties the verdict to the code you checked: `pan-tools verify stale <phase>` and `pan-tools progress` compare the phase's files against it, and a file changed since then marks this verification stale.
535
+
511
536
  Create `.planning/phases/{phase_dir}/{phase_num}-verification.md`:
512
537
 
513
538
  ```markdown
514
539
  ---
515
540
  phase: XX-name
516
541
  verified: YYYY-MM-DDTHH:MM:SSZ
542
+ verified_commit: <sha> # `git rev-parse HEAD` before you write this file: the code you verified
517
543
  status: passed | gaps_found | human_needed
518
544
  score: N/M must-haves verified
545
+ test_gate: passed | failed | skipped # Step 8b
546
+ not_checked: # Only for checks that could not run — never count them as passed
547
+ - check: "tests"
548
+ reason: "no test script in package.json"
519
549
  re_verification: # Only if previous verification.md existed
520
550
  previous_status: gaps_found
521
551
  previous_score: 2/5
@@ -536,6 +566,9 @@ human_verification: # Only if status: human_needed
536
566
  - test: "What to do"
537
567
  expected: "What should happen"
538
568
  why_human: "Why can't verify programmatically"
569
+ unrequested: # Only if Step 7c found work no plan asked for
570
+ - path: "src/path/to/file.tsx"
571
+ what: "What it adds that no plan or requirement asked for"
539
572
  ---
540
573
 
541
574
  # Phase {X}: {Name} Verification Report
@@ -581,6 +614,10 @@ human_verification: # Only if status: human_needed
581
614
 
582
615
  {Items needing human testing — detailed format for user}
583
616
 
617
+ ### Unrequested Work
618
+
619
+ {Files or behaviour no plan asked for (Step 7c), each with what it adds — or "None: every change traces to a plan."}
620
+
584
621
  ### Gaps Summary
585
622
 
586
623
  {Narrative summary of what's missing and why}
@@ -706,6 +743,7 @@ return <div>No messages</div> // Always shows "no messages"
706
743
  - [ ] Requirements coverage assessed (if applicable)
707
744
  - [ ] Anti-patterns scanned and categorized
708
745
  - [ ] Human verification items identified
746
+ - [ ] Scope checked with `verify scope`; unrequested work recorded in `unrequested:`
709
747
  - [ ] Overall status determined
710
748
  - [ ] Gaps structured in YAML frontmatter (if gaps_found)
711
749
  - [ ] Re-verification metadata included (if previous existed)