pan-wizard 2.9.0 → 3.4.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 (69) hide show
  1. package/README.md +8 -8
  2. package/agents/pan-conductor.md +189 -0
  3. package/agents/pan-counterfactual.md +112 -0
  4. package/agents/pan-debugger.md +15 -1
  5. package/agents/pan-document_code.md +21 -0
  6. package/agents/pan-executor.md +16 -0
  7. package/agents/pan-hardener.md +113 -0
  8. package/agents/pan-integration-checker.md +2 -0
  9. package/agents/pan-knowledge.md +81 -0
  10. package/agents/pan-meta-reviewer.md +91 -0
  11. package/agents/pan-plan-checker.md +2 -0
  12. package/agents/pan-previewer.md +98 -0
  13. package/agents/pan-project-researcher.md +4 -4
  14. package/agents/pan-reviewer.md +2 -0
  15. package/agents/pan-verifier.md +2 -0
  16. package/bin/install-lib.cjs +197 -0
  17. package/bin/install.js +1999 -1959
  18. package/commands/pan/assumptions.md +38 -3
  19. package/commands/pan/audit-deployment.md +6 -0
  20. package/commands/pan/cost.md +132 -0
  21. package/commands/pan/debug.md +71 -2
  22. package/commands/pan/exec-phase.md +105 -0
  23. package/commands/pan/focus-auto.md +199 -18
  24. package/commands/pan/focus-design.md +67 -2
  25. package/commands/pan/focus-exec.md +178 -47
  26. package/commands/pan/focus-scan.md +17 -5
  27. package/commands/pan/knowledge.md +129 -0
  28. package/commands/pan/map-codebase.md +47 -6
  29. package/commands/pan/mcp-bridge.md +145 -0
  30. package/commands/pan/milestone-audit.md +23 -0
  31. package/commands/pan/new-project.md +64 -0
  32. package/commands/pan/pause.md +42 -1
  33. package/commands/pan/plan-phase.md +95 -0
  34. package/commands/pan/preview.md +114 -0
  35. package/commands/pan/profile.md +37 -0
  36. package/commands/pan/quick.md +15 -0
  37. package/commands/pan/resume.md +62 -2
  38. package/commands/pan/review-deep.md +128 -0
  39. package/commands/pan/verify-phase.md +53 -0
  40. package/commands/pan/what-if.md +146 -0
  41. package/hooks/dist/pan-cost-logger.js +102 -0
  42. package/hooks/dist/pan-statusline.js +154 -108
  43. package/package.json +1 -1
  44. package/pan-wizard-core/bin/lib/bridge.cjs +269 -0
  45. package/pan-wizard-core/bin/lib/bus.cjs +251 -0
  46. package/pan-wizard-core/bin/lib/codebase.cjs +118 -0
  47. package/pan-wizard-core/bin/lib/constants.cjs +42 -1
  48. package/pan-wizard-core/bin/lib/context-budget.cjs +27 -0
  49. package/pan-wizard-core/bin/lib/core.cjs +91 -6
  50. package/pan-wizard-core/bin/lib/cost.cjs +359 -0
  51. package/pan-wizard-core/bin/lib/focus.cjs +105 -2
  52. package/pan-wizard-core/bin/lib/init.cjs +5 -5
  53. package/pan-wizard-core/bin/lib/knowledge.cjs +331 -0
  54. package/pan-wizard-core/bin/lib/memory.cjs +252 -0
  55. package/pan-wizard-core/bin/lib/phase.cjs +40 -13
  56. package/pan-wizard-core/bin/lib/preview.cjs +480 -0
  57. package/pan-wizard-core/bin/lib/review-deep.cjs +280 -0
  58. package/pan-wizard-core/bin/lib/roadmap.cjs +4 -4
  59. package/pan-wizard-core/bin/lib/state.cjs +2 -2
  60. package/pan-wizard-core/bin/lib/verify.cjs +34 -1
  61. package/pan-wizard-core/bin/lib/whatif.cjs +289 -0
  62. package/pan-wizard-core/bin/pan-tools.cjs +239 -4
  63. package/pan-wizard-core/templates/playbook.md +53 -0
  64. package/pan-wizard-core/templates/preview-report.md +93 -0
  65. package/pan-wizard-core/templates/roadmap.md +24 -24
  66. package/pan-wizard-core/templates/state.md +12 -9
  67. package/pan-wizard-core/workflows/plan-phase.md +1 -1
  68. package/scripts/build-hooks.js +2 -1
  69. package/scripts/generate-skills-docs.py +560 -0
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: pan:mcp-bridge
3
+ group: External tools
4
+ description: Discover available MCP tools and recommend which ones apply to a phase. Discovery-only; auto-invocation deferred.
5
+ argument-hint: "list | recommend <phase> | cache [--servers <json>] [--runtime <name>]"
6
+ allowed-tools:
7
+ - Read
8
+ - Bash
9
+ - Write
10
+ ---
11
+
12
+ <objective>
13
+ Surface Model Context Protocol (MCP) tools visible to the host runtime and recommend which ones might apply to a specific phase plan.
14
+
15
+ Reduced scope from Spec B v1's X-7: **discovery and recommendation only**. Auto-injection of MCP tools into planner context and auto-invocation from executor agents are deliberately deferred (likely Wave 5+ or v3.5). This keeps v3.3 narrow and avoids coupling PAN to Claude Code's MCP schema stability.
16
+ </objective>
17
+
18
+ <execution_context>
19
+ @~/.claude/pan-wizard-core/bin/lib/bridge.cjs
20
+ </execution_context>
21
+
22
+ <subcommands>
23
+
24
+ ### `list`
25
+
26
+ Show cached MCP tools with server grouping and schemas.
27
+
28
+ ```
29
+ /pan:mcp-bridge list
30
+ ```
31
+
32
+ **Output (JSON):**
33
+ ```json
34
+ {
35
+ "cached_at": "2026-04-18T12:34:56Z",
36
+ "runtime": "claude",
37
+ "server_count": 3,
38
+ "tool_count": 12,
39
+ "tools": [
40
+ { "server": "linear", "name": "linear.updateTicket", "description": "...", "schema": {...} },
41
+ ...
42
+ ],
43
+ "source": "cache" | "empty"
44
+ }
45
+ ```
46
+
47
+ When `source: "empty"`, either no MCP servers are configured or the host runtime hasn't populated the cache yet. See the `cache` subcommand for manual seeding.
48
+
49
+ ### `recommend <phase>`
50
+
51
+ Given a phase number, match cached MCP tools against the phase's plan text and return tools ranked by keyword relevance.
52
+
53
+ ```
54
+ /pan:mcp-bridge recommend 7
55
+ /pan:mcp-bridge recommend 12 --max 5 --min-score 2
56
+ ```
57
+
58
+ **Flags:**
59
+ - `--max N` — cap recommendations (default 10)
60
+ - `--min-score N` — minimum keyword hit count (default 1)
61
+
62
+ **Output (JSON):**
63
+ ```json
64
+ {
65
+ "phase": "7",
66
+ "phase_name": "API refactor",
67
+ "runtime": "claude",
68
+ "total_candidates": 12,
69
+ "recommendations": [
70
+ {
71
+ "server": "linear",
72
+ "name": "linear.updateTicket",
73
+ "description": "Update a Linear issue",
74
+ "score": 3,
75
+ "hits": ["linear", "ticket", "update"]
76
+ }
77
+ ]
78
+ }
79
+ ```
80
+
81
+ Scoring is naive keyword frequency with word boundaries — not semantic embeddings. A tool's name and description are tokenized into keywords (≥3 chars); each match in the phase plan text scores 1 point.
82
+
83
+ ### `cache`
84
+
85
+ Write or inspect the MCP tools cache at `.planning/bridge/available-tools.json`.
86
+
87
+ ```
88
+ # Inspect current cache (same as `list` but raw)
89
+ /pan:mcp-bridge cache
90
+
91
+ # Seed cache from scripted discovery (for testing or external pipeline)
92
+ /pan:mcp-bridge cache --runtime claude --servers '[{"name":"linear","tools":[{"name":"linear.updateTicket","description":"Update ticket"}]}]'
93
+ ```
94
+
95
+ Normally the host runtime writes this file. The CLI path exists for test fixtures and external-script integration.
96
+
97
+ </subcommands>
98
+
99
+ <workflow>
100
+
101
+ **New to a project with MCP tools?** Run `/pan:mcp-bridge list` to see what's available. If empty, check the host runtime's MCP config — `.claude/settings.json` for Claude Code, or the runtime's equivalent.
102
+
103
+ **Planning a phase that might touch external systems?** Run `/pan:mcp-bridge recommend <phase>` to get a ranked shortlist. Copy relevant tool names into the phase plan's "External tools" section so the executor knows to invoke them.
104
+
105
+ **Pre-milestone review:** walk through each remaining phase with `/pan:mcp-bridge recommend` to catch "we should have automated this via Linear/Slack/etc." realizations before shipping.
106
+
107
+ </workflow>
108
+
109
+ <caveats>
110
+
111
+ **Discovery is a cache, not a live probe.** The host runtime owns populating `.planning/bridge/available-tools.json`. PAN does not query MCP servers directly — that would require runtime-specific HTTP or IPC integration this command deliberately avoids.
112
+
113
+ **Keyword scoring is crude.** "Postgres" and "PostgreSQL" are different tokens; `postgresql` in a plan won't match a `postgres.query` tool unless the plan also says "postgres." Tune your plan language or expand tool descriptions to improve matches.
114
+
115
+ **Claude Code is the primary target.** MCP is a Claude-first protocol. Other runtimes may have their own tool-discovery mechanisms; the cache schema is intentionally generic so a future Codex/Gemini equivalent could populate the same file.
116
+
117
+ **No automatic invocation.** This command never calls MCP tools. It tells you what's available and what might apply. The actual invocation happens via the host runtime's normal tool-use flow (Claude Code's tool calls, etc.) when the executor agent decides to use a recommended tool.
118
+
119
+ </caveats>
120
+
121
+ <runtime_compatibility>
122
+
123
+ | Runtime | list | recommend | cache |
124
+ |---------|------|-----------|-------|
125
+ | Claude Code | Full | Full | Full (host-populated) |
126
+ | OpenCode | Stub (empty cache returns gracefully) | Stub | CLI write works |
127
+ | Gemini CLI | Stub | Stub | CLI write works |
128
+ | Codex CLI | Stub | Stub | CLI write works |
129
+ | Copilot CLI | Stub | Stub | CLI write works |
130
+
131
+ On non-Claude runtimes, the aggregator and recommendation logic still work — they just report zero tools until something populates the cache.
132
+
133
+ </runtime_compatibility>
134
+
135
+ <future_scope>
136
+
137
+ Explicitly deferred from v3.3 (documented in ADR-0023 / Spec B v2 notes):
138
+
139
+ 1. **Auto-inject recommended tools into planner context** — requires a stable MCP schema contract and a plan-template extension. Candidate for v3.5.
140
+ 2. **Auto-invoke MCP tools from executor agent** — requires permission-gating and per-tool safety review. Candidate for v3.5+.
141
+ 3. **Cross-runtime tool discovery** — generic MCP-like protocol for non-Claude runtimes. No timeline; needs ecosystem signal.
142
+
143
+ Until those land, this command is the minimum viable integration: you see what's there, you get suggestions, you decide manually.
144
+
145
+ </future_scope>
@@ -31,6 +31,29 @@ Glob: .planning/phases/*/*-summary.md
31
31
  Glob: .planning/phases/*/*-verification.md
32
32
  </context>
33
33
 
34
+ <citation_requirement>
35
+ Every coverage judgment in the audit MUST cite evidence from the codebase.
36
+
37
+ **Before writing any requirement as "covered" or "not covered", verify by reading the code.**
38
+
39
+ **Grounding rules:**
40
+ - "Covered" requires: file:line where the requirement is implemented + verification.md or test evidence
41
+ - "Partially covered" requires: file:line showing what exists + specific gap description with expected location
42
+ - "Not covered" requires: grep showing the expected functionality doesn't exist (show the search and empty result)
43
+ - Cross-phase integration claims require: file:line in phase A's output + file:line in phase B's consumer
44
+
45
+ **Anti-pattern:**
46
+ ```
47
+ BAD: "Requirement R3 is covered — the billing module handles this"
48
+ → Which file? Which function? How do you know?
49
+ GOOD: "Requirement R3 is covered — generateInvoice() at src/billing.ts:42 implements line-item
50
+ calculation. Verified in phase-2-verification.md (line 18). Integration: called from
51
+ src/api/orders.ts:156 (phase 3)."
52
+ ```
53
+
54
+ Do not trust summary files at face value. If a verification.md says "all tests pass" but you haven't confirmed the test count, that claim is ungrounded. Spot-check at least 2 verification files by running the actual tests.
55
+ </citation_requirement>
56
+
34
57
  <process>
35
58
  Execute the audit-milestone workflow from @~/.claude/pan-wizard-core/workflows/milestone-audit.md end-to-end.
36
59
  Preserve all workflow gates (scope determination, verification reading, integration check, requirements coverage, routing).
@@ -37,6 +37,70 @@ Initialize a new project through unified flow: questioning → research (optiona
37
37
  @~/.claude/pan-wizard-core/templates/requirements.md
38
38
  </execution_context>
39
39
 
40
+ <progressive_context>
41
+ Load context in layers — do NOT read everything upfront. Each layer builds on the previous.
42
+
43
+ **Layer 1: Manifest (always load first)**
44
+ - package.json / Cargo.toml / pyproject.toml — project identity, deps, scripts
45
+ - .planning/ existence check — is this a fresh start or existing project?
46
+ - README.md first 50 lines — what the project claims to be
47
+
48
+ **Layer 2: Structure (load during questioning)**
49
+ - Directory tree (Glob top-level patterns) — understand project shape
50
+ - Entry points — main files, index files, server files
51
+ - Test infrastructure — test framework, test directory
52
+
53
+ **Layer 3: Hotspots (load during research, if research is enabled)**
54
+ - Most-changed files (git log --name-only) — where active work happens
55
+ - Largest files — complexity centers
56
+ - Import graph roots — most-depended-on modules
57
+
58
+ **Layer 4: Baselines (load only when generating requirements/roadmap)**
59
+ - Test count + pass rate
60
+ - Build status
61
+ - Dependency audit (outdated, vulnerable)
62
+
63
+ **Why layered:** Loading everything at Layer 1 wastes 40-60% of context on information not needed until later. For greenfield projects, Layers 3-4 are empty and should be skipped entirely.
64
+ </progressive_context>
65
+
66
+ <routing_decision_tree>
67
+ Use this decision tree to select the correct path. Evaluate conditions top-to-bottom; take the FIRST match.
68
+
69
+ ```
70
+ IF .planning/ already exists AND contains project.md:
71
+ → WARN: "Project already initialized. Use /pan:resume to continue."
72
+ → STOP (do not overwrite existing project)
73
+
74
+ ELSE IF --auto flag AND @ reference document provided:
75
+ → ASK config questions only (commit_docs, model_profile)
76
+ → SKIP interactive questioning (use the @ document as project context)
77
+ → RUN research automatically
78
+ → GENERATE requirements from research + @ document
79
+ → GENERATE roadmap from requirements
80
+ → No further interaction until complete
81
+
82
+ ELSE IF --auto flag WITHOUT @ reference:
83
+ → ERROR: "--auto requires an @ referenced idea document"
84
+ → STOP
85
+
86
+ ELSE (interactive mode — default):
87
+ → RUN questioning flow (5-area deep questioning)
88
+ → ASK: "Should I research the domain ecosystem?" (Y/N)
89
+ → IF Y: spawn researchers → synthesize → continue
90
+ → IF N: skip research → continue
91
+ → PRESENT requirements for approval
92
+ → PRESENT roadmap for approval
93
+ → COMMIT if commit_docs=true
94
+ ```
95
+
96
+ **Research routing:**
97
+ ```
98
+ IF user says research: spawn pan-project-researcher agents
99
+ IF user declines research: skip directly to requirements generation
100
+ IF codebase already has substantial code: suggest skipping research (existing code IS the context)
101
+ ```
102
+ </routing_decision_tree>
103
+
40
104
  <process>
41
105
  Execute the new-project workflow from @~/.claude/pan-wizard-core/workflows/new-project.md end-to-end.
42
106
  Preserve all workflow gates (validation, approvals, commits, routing).
@@ -27,13 +27,54 @@ Routes to the pause-work workflow which handles:
27
27
  State and phase progress are gathered in-workflow with targeted reads.
28
28
  </context>
29
29
 
30
+ <handoff_schema>
31
+ The `.continue-here.md` file MUST contain ALL of the following sections. Missing sections cause resume failures.
32
+
33
+ ```yaml
34
+ # Required fields for .continue-here.md
35
+ session_id: "{date}-{slug}" # Unique session identifier
36
+ paused_at: "{ISO-8601 timestamp}" # When work was paused
37
+ phase: "{phase number and name}" # Current phase being worked on
38
+ plan: "{plan file path}" # Which plan was active
39
+
40
+ position:
41
+ last_completed_task: "{task ID}" # Last task that was fully done
42
+ next_task: "{task ID}" # What to do next
43
+ wave: "{wave number, if applicable}"
44
+
45
+ progress:
46
+ tasks_done: [{id, title, status}] # All completed tasks this session
47
+ tasks_remaining: [{id, title}] # What's left in the plan
48
+ test_baseline: "{N passing}" # Test count when session started
49
+ test_current: "{N passing}" # Test count at pause time
50
+
51
+ decisions:
52
+ - "{decision made and why}" # Choices that affect remaining work
53
+
54
+ blockers:
55
+ - "{blocker description}" # Anything preventing progress
56
+
57
+ context:
58
+ files_modified: ["{paths}"] # Files changed this session
59
+ key_findings: ["{findings}"] # Non-obvious discoveries
60
+ next_action: "{specific action}" # Exact first step on resume
61
+ ```
62
+
63
+ **Why every field matters:**
64
+ - `position` → resume agent knows WHERE to start (not re-reading the whole plan)
65
+ - `progress` → resume agent knows test baseline (detects regressions vs pre-existing)
66
+ - `decisions` → resume agent won't re-debate settled questions
67
+ - `blockers` → resume agent can flag to user immediately instead of rediscovering
68
+ - `context.next_action` → resume agent's first action is productive, not exploratory
69
+ </handoff_schema>
70
+
30
71
  <process>
31
72
  **Follow the pause-work workflow** from `@~/.claude/pan-wizard-core/workflows/pause.md`.
32
73
 
33
74
  The workflow handles all logic including:
34
75
  1. Phase directory detection
35
76
  2. State gathering with user clarifications
36
- 3. Handoff file writing with timestamp
77
+ 3. Handoff file writing with timestamp — **using the schema from `<handoff_schema>`**
37
78
  4. Git commit
38
79
  5. Confirmation with resume instructions
39
80
  </process>
@@ -40,6 +40,101 @@ Phase number: $ARGUMENTS (optional — auto-detects next unplanned phase if omit
40
40
  Normalize phase input in step 2 before any directory lookups.
41
41
  </context>
42
42
 
43
+ <reflexion_loop>
44
+ During the plan-checker verification iteration:
45
+ 1. Read the plan-checker's critique carefully
46
+ 2. For each identified gap: verify it is a genuine gap by re-reading the relevant requirement
47
+ 3. Do not blindly accept all critiques — some may be false positives from missing context
48
+ 4. Revise the plan to address genuine gaps only
49
+ 5. Maximum 2 revision iterations (plan → check → revise → check → final)
50
+ This prevents over-revision while ensuring real gaps are closed.
51
+ </reflexion_loop>
52
+
53
+ <completion_contract>
54
+ Planning is complete when ALL conditions are met:
55
+ 1. At least one plan.md file created in the phase directory
56
+ 2. Plan-checker passed (or max 2 revision iterations exhausted with final approval)
57
+ 3. Each plan contains: objective, task breakdown with estimates, dependency ordering, and key file links
58
+ 4. Research.md exists (unless --skip-research was used)
59
+ 5. User presented with results and next-step options
60
+
61
+ Planning FAILS if: phase not found in roadmap, or planner agent returns empty/malformed output after retries.
62
+ </completion_contract>
63
+
64
+ <common_mistakes>
65
+ Avoid these planning anti-patterns:
66
+ ```
67
+ BAD: Plan has 25 tasks for a single phase → too granular, executor loses context
68
+ GOOD: 5-8 tasks per plan, each with clear scope and testable outcome
69
+
70
+ BAD: Task says "Implement the feature" with no file links or acceptance criteria
71
+ → Executor guesses at scope, misses edge cases
72
+ GOOD: Task says "Add retry logic to api/client.ts:fetchData() — 3 retries with exponential backoff, tested by tests/client.test.ts"
73
+
74
+ BAD: Plan-checker flags a gap → blindly add a task without re-reading the requirement
75
+ → False positive becomes unnecessary work
76
+ GOOD: Re-read the requirement → confirm the gap is real → then add the task
77
+ ```
78
+ </common_mistakes>
79
+
80
+ <routing_decision_tree>
81
+ Use this decision tree to select the correct path. Evaluate conditions top-to-bottom; take the FIRST match.
82
+
83
+ ```
84
+ IF --gaps flag is set:
85
+ → SKIP research (gap closure uses verification.md instead)
86
+ → READ verification.md for the phase
87
+ → PLAN with gap context
88
+ → VERIFY (unless --skip-verify)
89
+
90
+ ELSE IF --prd <file> flag is set:
91
+ → SKIP discuss-phase entirely
92
+ → PARSE PRD file into context.md
93
+ → SKIP research (PRD provides requirements)
94
+ → PLAN from parsed requirements
95
+ → VERIFY (unless --skip-verify)
96
+
97
+ ELSE IF --skip-research flag is set:
98
+ → SKIP research
99
+ → PLAN directly (must have roadmap context)
100
+ → VERIFY (unless --skip-verify)
101
+
102
+ ELSE IF research.md already exists AND --research NOT set:
103
+ → SKIP research (reuse existing)
104
+ → PLAN using existing research.md
105
+ → VERIFY (unless --skip-verify)
106
+
107
+ ELSE (default path):
108
+ → RUN research (spawn pan-phase-researcher)
109
+ → PLAN from research results
110
+ → VERIFY (unless --skip-verify)
111
+ ```
112
+
113
+ **Verification loop routing:**
114
+ ```
115
+ IF --skip-verify:
116
+ → Present plan, done
117
+
118
+ ELSE:
119
+ → Spawn pan-plan-checker
120
+ → IF checker PASSES: done
121
+ → IF checker finds gaps (iteration 1): revise plan, re-check
122
+ → IF checker finds gaps (iteration 2): final revision, present with caveats
123
+ → Max 2 revision iterations
124
+ ```
125
+ </routing_decision_tree>
126
+
127
+ <cache_priming>
128
+ **Before spawning research + planner agents, prime the prompt cache.** All sub-agents spawned within the next 5 minutes hit cached context instead of re-reading project.md / requirements.md / roadmap.md / state.md / standards.md.
129
+
130
+ Run once per invocation:
131
+ ```
132
+ pan-tools cache prime --summary
133
+ ```
134
+
135
+ Returns `{blocks: [{path, bytes, cache}], total_bytes, sha}`. On Claude Code with Opus 4.7, the host runtime translates these block references into `cache_control: ephemeral`. On non-Claude runtimes or older models this is a no-op — nothing breaks.
136
+ </cache_priming>
137
+
43
138
  <process>
44
139
  Execute the plan-phase workflow from @~/.claude/pan-wizard-core/workflows/plan-phase.md end-to-end.
45
140
  Preserve all workflow gates (validation, research, planning, verification loop, routing).
@@ -0,0 +1,114 @@
1
+ ---
2
+ name: pan:preview
3
+ group: Foresight
4
+ description: Preview what will happen — phase blast radius, phase dependency graph, or milestone ETA
5
+ argument-hint: "phase <N> | phases | milestone"
6
+ allowed-tools:
7
+ - Read
8
+ - Bash
9
+ - Glob
10
+ - Grep
11
+ - Write
12
+ - Task
13
+ ---
14
+
15
+ <objective>
16
+ Read-only foresight. Given a phase, a set of phases, or a milestone, produce a structured forecast: what files get touched, which tests might break, which phases can parallelize, when the milestone will actually finish.
17
+
18
+ Consolidates Spec B v1's architect + simulate + predict-milestone into one entry point with three modes. The data layer (`pan-tools preview …`) extracts structured inputs from `.planning/`; the `pan-previewer` agent analyzes and writes the report. No source code is modified.
19
+ </objective>
20
+
21
+ <execution_context>
22
+ @~/.claude/pan-wizard-core/bin/lib/preview.cjs
23
+ @~/.claude/pan-wizard-core/templates/preview-report.md
24
+ </execution_context>
25
+
26
+ <modes>
27
+
28
+ ### `phase <N>` — Blast radius of one phase
29
+
30
+ ```
31
+ /pan:preview phase 7
32
+ ```
33
+
34
+ **What it does:**
35
+ 1. `pan-tools preview phase <N>` returns `{files_mentioned, test_files_mentioned, risk_signals, risk_score, plans[], status}`.
36
+ 2. Spawn `pan-previewer` with the payload as `<preview_input>`.
37
+ 3. Agent writes `.planning/phases/<N>/preview.md` with files touched / tests at risk / migration steps / risk assessment / bottom line.
38
+
39
+ **Output:** `.planning/phases/<N>/preview.md`
40
+
41
+ ### `phases` — Cross-phase dependency graph
42
+
43
+ ```
44
+ /pan:preview phases
45
+ ```
46
+
47
+ **What it does:**
48
+ 1. `pan-tools preview phases` returns `{phases[], parallel_batches, mermaid, hidden_coupling_count}`.
49
+ 2. Spawn `pan-previewer` with `mode: phases` in the payload.
50
+ 3. Agent writes `.planning/architecture/dependency-graph.md` with mermaid DAG + parallel batches + hidden-coupling flags.
51
+
52
+ **Output:** `.planning/architecture/dependency-graph.md`
53
+
54
+ **Opus 4.7 1M-context bonus:** when the full repo fits in a single agent window, the agent cross-references plan text with actual source imports to catch coupling the frontmatter missed. On smaller-context models, the agent relies on data-layer output alone.
55
+
56
+ ### `milestone` — Completion ETA
57
+
58
+ ```
59
+ /pan:preview milestone
60
+ ```
61
+
62
+ **What it does:**
63
+ 1. `pan-tools preview milestone` returns `{phases_total, completed, remaining, avg_phase_duration_days, eta_date, confidence_pct, bottleneck, sample_size}`.
64
+ 2. Spawn `pan-previewer` with `mode: milestone`.
65
+ 3. Agent writes `.planning/milestones/preview-<today>.md` with ETA + confidence + bottleneck + caveats + bottom line.
66
+
67
+ **Output:** `.planning/milestones/preview-YYYY-MM-DD.md`
68
+
69
+ </modes>
70
+
71
+ <workflow>
72
+
73
+ **Before committing to a phase:** run `/pan:preview phase <N>` to see blast radius. A `risk_score ≥ 7` or a migration signal on auth files should prompt a review before `/pan:exec-phase`.
74
+
75
+ **Before committing to a milestone date externally:** run `/pan:preview milestone`. Look at `confidence_pct` and `sample_size`. If sample is <3, don't promise a date.
76
+
77
+ **Before running phases in parallel:** run `/pan:preview phases`. Parallel batches from the data layer are based on declared `depends_on` only; `hidden_coupling_count > 0` means there are cross-phase references the author should promote to explicit deps before parallelizing.
78
+
79
+ </workflow>
80
+
81
+ <process>
82
+
83
+ For all modes:
84
+
85
+ 1. Run the corresponding `pan-tools preview <mode>` subcommand.
86
+ 2. Parse its JSON output.
87
+ 3. Spawn `pan-previewer` with a prompt that includes:
88
+ - `<preview_input>` block carrying the full JSON payload (mode field set explicitly)
89
+ - `<output_path>` block with the target file path
90
+ - `<files_to_read>` block with any phase context files the agent should load
91
+ 4. Agent writes the report file and returns a short confirmation.
92
+ 5. Echo the output path to the user.
93
+
94
+ The agent does not need workflow context beyond what the data layer provides. Keep spawned-agent prompts lean — the agent's context budget is for reasoning about the structured input, not for loading the whole project.
95
+
96
+ </process>
97
+
98
+ <output_contract>
99
+ The command returns the path to the generated preview document. Never paste the report back into conversation output — the file is the deliverable; reference it by path.
100
+ </output_contract>
101
+
102
+ <runtime_compatibility>
103
+
104
+ | Runtime | phase | phases | milestone |
105
+ |---------|-------|--------|-----------|
106
+ | Claude Code | Full, thinking enabled | Full, 1M-ctx bonus on Opus 4.7 | Full |
107
+ | OpenCode | Full | Data-layer + simple report | Full |
108
+ | Gemini CLI | Full | Data-layer + simple report | Full |
109
+ | Codex CLI | Full | Data-layer + simple report | Full |
110
+ | Copilot CLI | Full | Data-layer + simple report | Full |
111
+
112
+ The data layer (`pan-tools preview …`) works identically on all runtimes. What varies is the quality of the agent's synthesis — Opus 4.7 with thinking catches subtler risks than smaller models.
113
+
114
+ </runtime_compatibility>
@@ -35,3 +35,40 @@ The workflow handles all logic including:
35
35
  5. Cost estimation display (relative cost multiplier per profile)
36
36
  6. Confirmation display
37
37
  </process>
38
+
39
+ <tier_decision_tree>
40
+ **Opus 4.7 capability-aware routing** (since v2.10.0 — E-7). Even within a single profile, PAN picks a tier per-call based on three hints: context estimate, whether the task needs extended thinking, and whether prompt cache is warm.
41
+
42
+ The decision order `resolveModel` applies after the baseline profile pick:
43
+
44
+ ```
45
+ Baseline tier (from MODEL_PROFILES[agent][profile])
46
+
47
+
48
+ ┌─────────────────────────────────────────────┐
49
+ │ context_estimate > 700K tokens? │── yes ──▶ force reasoning (only 1M-ctx tier)
50
+ └─────────────────────────────────────────────┘
51
+ │ no
52
+
53
+ ┌─────────────────────────────────────────────┐
54
+ │ needs_thinking AND tier == fast? │── yes ──▶ upgrade fast → mid
55
+ └─────────────────────────────────────────────┘
56
+ │ no
57
+
58
+ ┌─────────────────────────────────────────────┐
59
+ │ cache_warm AND !needs_thinking │── yes ──▶ downgrade mid → fast
60
+ │ AND context_estimate < 50K AND tier == mid │
61
+ └─────────────────────────────────────────────┘
62
+ │ no
63
+
64
+ Final tier → provider-native model name
65
+ ```
66
+
67
+ **Quick guide:**
68
+ - Heavy verification (plan-checker, verifier, integration-checker, reviewer, debugger): `needs_thinking: true` — baseline upgrades fast→mid.
69
+ - Map-codebase single-shot mode on Opus 4.7: `context_estimate > 700K` — forced to reasoning.
70
+ - Routine exec tasks with project.md cached: `cache_warm + small ctx` — mid gets downgraded to fast for a cost win.
71
+ - All rules are additive to the `quality` / `balanced` / `budget` profile you pick here — profile sets the floor, capability hints adjust upward or downward within that floor's band.
72
+
73
+ **Inspecting routing:** use `pan-tools resolve-model <agent> --metadata '{"context_estimate":900000,"needs_thinking":true}'` to see what tier a given hint set resolves to.
74
+ </tier_decision_tree>
@@ -39,4 +39,19 @@ Context files are resolved inside the workflow (`init quick`) and delegated via
39
39
  <process>
40
40
  Execute the quick workflow from @~/.claude/pan-wizard-core/workflows/quick.md end-to-end.
41
41
  Preserve all workflow gates (validation, task description, planning, execution, state updates, commits).
42
+
43
+ **Scope Containment:**
44
+ Implement only what was asked. Do not refactor surrounding code, add unrelated improvements, or create abstractions for one-time fixes.
45
+
46
+ **State Intent Before Implementing:**
47
+ Before coding, state: "I will modify [files], adding [what], to achieve [goal]."
48
+
49
+ **Pre-Commit Verification Checklist — apply before the final commit:**
50
+ 1. Every modified file was read before editing
51
+ 2. `git diff --stat` contains only files related to the task
52
+ 3. Tests pass (run the project's test suite)
53
+ 4. Commit message accurately describes the verified change
54
+ 5. No secrets or credentials staged
55
+
56
+ If any check fails: fix and re-verify before committing.
42
57
  </process>
@@ -26,6 +26,66 @@ Routes to the resume-project workflow which handles:
26
26
  @~/.claude/pan-wizard-core/workflows/resume-project.md
27
27
  </execution_context>
28
28
 
29
+ <handoff_consumption>
30
+ When a `.continue-here.md` file exists, parse it as structured handoff data before presenting options.
31
+
32
+ **Required extraction (in order):**
33
+ 1. `position.next_task` → This is the FIRST thing to tell the user
34
+ 2. `blockers` → If non-empty, surface BEFORE offering to continue
35
+ 3. `decisions` → Load into context so they are not re-debated
36
+ 4. `progress.test_baseline` + `progress.test_current` → Verify current test count matches `test_current` (detect drift since pause)
37
+ 5. `context.next_action` → Use as the default suggested action
38
+
39
+ **Resume validation:**
40
+ - If `test_current` at resume time differs from stored value → warn user: "Test count changed since pause ({stored} → {current}). Someone else may have committed."
41
+ - If `position.next_task` references a task not in the plan → warn: plan may have been revised since pause
42
+ - If `blockers` exist → present them and ask if resolved before continuing
43
+
44
+ **Anti-pattern:**
45
+ ```
46
+ BAD: Resume reads .continue-here.md, ignores position, re-reads entire plan from scratch
47
+ → Wastes context on already-completed work, may re-implement done tasks
48
+ GOOD: Resume extracts position.next_task, skips completed tasks, starts exactly where paused
49
+ ```
50
+ </handoff_consumption>
51
+
52
+ <routing_decision_tree>
53
+ Use this decision tree to select the correct resumption path. Evaluate top-to-bottom; take the FIRST match.
54
+
55
+ ```
56
+ IF .planning/ does not exist:
57
+ → "No project found. Run /pan:new-project to get started."
58
+ → STOP
59
+
60
+ ELSE IF .continue-here.md exists:
61
+ → PARSE handoff file using <handoff_consumption> protocol
62
+ → PRESENT: position, blockers, next action
63
+ → ROUTE to the command that was paused (exec-phase, plan-phase, etc.)
64
+
65
+ ELSE IF state.md exists AND has status "in_progress":
66
+ → FIND incomplete work: plans without summaries, phases mid-execution
67
+ → IF incomplete phase found:
68
+ → PRESENT phase status + what remains
69
+ → OFFER: continue execution (/pan:exec-phase) or verify (/pan:verify-phase)
70
+ → IF no incomplete work but active milestone:
71
+ → PRESENT milestone progress
72
+ → OFFER: next unplanned phase (/pan:plan-phase) or audit (/pan:milestone-audit)
73
+
74
+ ELSE IF state.md exists AND has status "blocked":
75
+ → PRESENT blockers from state.md
76
+ → OFFER: debug (/pan:debug) or unblock manually
77
+
78
+ ELSE IF state.md exists AND has status "completed":
79
+ → "Current milestone is complete. Run /pan:milestone-done or /pan:milestone-new."
80
+ → STOP
81
+
82
+ ELSE (state.md missing or unreadable):
83
+ → ATTEMPT reconstruction from .planning/ artifacts
84
+ → IF reconstruction succeeds: re-enter tree above
85
+ → IF reconstruction fails: "State is corrupted. Run /pan:new-project or restore from git."
86
+ ```
87
+ </routing_decision_tree>
88
+
29
89
  <process>
30
90
  **Follow the resume-project workflow** from `@~/.claude/pan-wizard-core/workflows/resume-project.md`.
31
91
 
@@ -33,9 +93,9 @@ The workflow handles all resumption logic including:
33
93
 
34
94
  1. Project existence verification
35
95
  2. state.md loading or reconstruction
36
- 3. Checkpoint and incomplete work detection
96
+ 3. Checkpoint and incomplete work detection — **parse using `<handoff_consumption>` protocol**
37
97
  4. Visual status presentation
38
98
  5. Context-aware option offering (checks context.md before suggesting plan vs discuss)
39
- 6. Routing to appropriate next command
99
+ 6. Routing to appropriate next command — **following `<routing_decision_tree>`**
40
100
  7. Session continuity updates
41
101
  </process>