pan-wizard 3.4.1 → 3.5.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.
- package/README.md +30 -8
- package/agents/pan-distiller.md +82 -0
- package/agents/pan-optimizer.md +242 -0
- package/bin/install.js +50 -1
- package/commands/pan/focus-auto.md +150 -3
- package/commands/pan/focus-exec.md +11 -0
- package/commands/pan/focus-scan.md +6 -0
- package/commands/pan/git.md +223 -0
- package/commands/pan/learn.md +61 -0
- package/commands/pan/milestone-done.md +9 -0
- package/commands/pan/optimize.md +86 -0
- package/hooks/dist/pan-trace-logger.js +197 -0
- package/package.json +1 -1
- package/pan-wizard-core/bin/lib/commands.cjs +1 -0
- package/pan-wizard-core/bin/lib/constants.cjs +5 -1
- package/pan-wizard-core/bin/lib/distill.cjs +510 -0
- package/pan-wizard-core/bin/lib/focus.cjs +8 -1
- package/pan-wizard-core/bin/lib/git.cjs +407 -0
- package/pan-wizard-core/bin/lib/optimize.cjs +653 -0
- package/pan-wizard-core/bin/pan-tools.cjs +78 -0
- package/pan-wizard-core/workflows/exec-phase.md +97 -0
- package/pan-wizard-core/workflows/learn.md +91 -0
- package/pan-wizard-core/workflows/optimize.md +139 -0
- package/pan-wizard-core/workflows/plan-phase.md +27 -0
- package/pan-wizard-core/workflows/quick.md +7 -0
- package/pan-wizard-core/workflows/verify-phase.md +16 -0
- package/scripts/build-hooks.js +2 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
+
<img src="https://github.com/oharms/PanWizard/raw/main/assets/pan-logo-2000-transparent.svg" alt="PAN Wizard" width="200" />
|
|
4
|
+
|
|
3
5
|
# PAN WIZARD
|
|
4
6
|
|
|
5
7
|
**Project Automation Navigator — A lightweight workflow automation and context engineering system for Claude Code, OpenCode, Gemini CLI, Codex, and Copilot CLI.**
|
|
@@ -20,7 +22,7 @@ npx pan-wizard@latest
|
|
|
20
22
|
|
|
21
23
|
<br>
|
|
22
24
|
|
|
23
|
-

|
|
25
|
+

|
|
24
26
|
|
|
25
27
|
<br>
|
|
26
28
|
|
|
@@ -47,12 +49,12 @@ PAN is the context engineering layer that makes Claude Code reliable. It breaks
|
|
|
47
49
|
└─────────────────────┬───────────────────────────────────────┘
|
|
48
50
|
│ invokes
|
|
49
51
|
┌─────────────────────▼───────────────────────────────────────┐
|
|
50
|
-
│ COMMANDS (
|
|
52
|
+
│ COMMANDS (51 .md files + 4 CLI operations) │
|
|
51
53
|
│ Thin orchestrators that spawn agents and route results │
|
|
52
54
|
└─────────────────────┬───────────────────────────────────────┘
|
|
53
55
|
│ spawns
|
|
54
56
|
┌─────────────────────▼───────────────────────────────────────┐
|
|
55
|
-
│ AGENTS (
|
|
57
|
+
│ AGENTS (20 specialized) │
|
|
56
58
|
│ planner · executor · verifier · researcher · debugger ... │
|
|
57
59
|
│ Each runs in fresh 200K context window │
|
|
58
60
|
└─────────────────────┬───────────────────────────────────────┘
|
|
@@ -149,9 +151,9 @@ node bin/install.js --claude --local
|
|
|
149
151
|
Installs to `./.claude/` for testing modifications before contributing.
|
|
150
152
|
|
|
151
153
|
```bash
|
|
152
|
-
npm test # ~
|
|
154
|
+
npm test # ~2302 unit tests (61 files)
|
|
153
155
|
npm run test:scenarios # ~265 scenario tests (30 files)
|
|
154
|
-
npm run test:all # All
|
|
156
|
+
npm run test:all # All 2567 tests (91 files)
|
|
155
157
|
```
|
|
156
158
|
|
|
157
159
|
</details>
|
|
@@ -481,7 +483,7 @@ You're never locked in. The system adapts.
|
|
|
481
483
|
| | PAN Wizard | Cursor / Windsurf | Aider / Cline | GitHub Copilot |
|
|
482
484
|
|---|---|---|---|---|
|
|
483
485
|
| **Context rot prevention** | Phase-scoped fresh 200K windows | No — context degrades over time | No (Cline: condensing) | No |
|
|
484
|
-
| **Multi-agent** |
|
|
486
|
+
| **Multi-agent** | 20 specialized agents, parallel waves | Up to 8 parallel (Cursor 2.0) | Single agent | Specialized sub-agents |
|
|
485
487
|
| **Plan → Verify loop** | Research → plan → verify with iteration | Agent generates plan | Plan mode (Cline) | Plan step |
|
|
486
488
|
| **Post-execution verification** | Auto verifier + human UAT | Iterative error-fix | Manual test runs | Auto-fix loop |
|
|
487
489
|
| **Session persistence** | state.md + pause/resume + handoff | Notepad / Memories | None / Task history | None |
|
|
@@ -583,6 +585,26 @@ PAN is not a replacement for your IDE or AI agent — it's the orchestration lay
|
|
|
583
585
|
| `/pan:focus-drift-walking` | Walk project tree, detect doc-code drift, score severity, auto-repair |
|
|
584
586
|
| `/pan:focus-doc-audit` | Multi-dimensional document audit with 8-dimension quality scoring |
|
|
585
587
|
|
|
588
|
+
### Spec B v2 (v3.0–v3.4)
|
|
589
|
+
|
|
590
|
+
| Command | What it does |
|
|
591
|
+
|---------|--------------|
|
|
592
|
+
| `/pan:cost` | Token usage + estimated cost across PAN invocations (json/table/chart) |
|
|
593
|
+
| `/pan:preview <phase\|phases\|milestone>` | Read-only foresight: blast radius, dependency graph, milestone ETA |
|
|
594
|
+
| `/pan:review-deep <phase>` | Security audit (OWASP + STRIDE) + cross-check by meta-reviewer |
|
|
595
|
+
| `/pan:knowledge {ask\|discuss\|playbook}` | Grounded Q&A, multi-turn discussion, or aggregate memory into playbook |
|
|
596
|
+
| `/pan:what-if <phase> "scenario"` | Counterfactual phase replay in isolated git worktree |
|
|
597
|
+
| `/pan:mcp-bridge {list\|recommend\|cache}` | Discover MCP tools and recommend per-phase relevance |
|
|
598
|
+
|
|
599
|
+
### Optimization & Git (v3.5)
|
|
600
|
+
|
|
601
|
+
| Command | What it does |
|
|
602
|
+
|---------|--------------|
|
|
603
|
+
| `/pan:learn` | Analyze trace events, generate optimization report with auto-apply block |
|
|
604
|
+
| `/pan:optimize {apply\|list\|stats\|trace}` | Apply optimizer recommendations, list reports, view stats, manage trace sessions |
|
|
605
|
+
| `/pan:git <subcommand>` | Phase-aware git workflow: commit/branch/push/status/log/stash/diff/rollback/tag/sync |
|
|
606
|
+
| `/pan:audit-deployment` | Audit a PAN installation for integrity (manifest verification, drift detection) |
|
|
607
|
+
|
|
586
608
|
<sup>¹ Contributed by reddit user OracleGreyBeard</sup>
|
|
587
609
|
|
|
588
610
|
---
|
|
@@ -750,8 +772,8 @@ This removes all PAN commands, agents, hooks, and settings while preserving your
|
|
|
750
772
|
| [Architecture](docs/ARCHITECTURE.md) | Contributors | 5-layer system design, data flow, module graph |
|
|
751
773
|
| [Development Guide](docs/DEVELOPMENT.md) | Contributors | Setup, how to add commands/agents/tests, cross-platform pitfalls |
|
|
752
774
|
| [CLI Reference](docs/CLI-REFERENCE.md) | Contributors | Every pan-tools.cjs subcommand with args, flags, and JSON output |
|
|
753
|
-
| [Agent System](docs/AGENTS.md) | Contributors |
|
|
754
|
-
| [Hook System](docs/HOOKS.md) | Contributors |
|
|
775
|
+
| [Agent System](docs/AGENTS.md) | Contributors | 20 agents, lifecycle, model profiles, collaboration patterns |
|
|
776
|
+
| [Hook System](docs/HOOKS.md) | Contributors | 5 built-in hooks, bridge file architecture, custom hook development |
|
|
755
777
|
| [Internals](docs/INTERNALS.md) | Power Users | Checkpoint system, TDD, verification patterns, model profiles |
|
|
756
778
|
| [Troubleshooting](docs/TROUBLESHOOTING.md) | Users | Deep-dive diagnostics for execution, state, git, and verification issues |
|
|
757
779
|
| [Contributing](CONTRIBUTING.md) | Contributors | Project structure, code style, PR process |
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pan-distiller
|
|
3
|
+
description: AI code-bloat detection and rewrite agent. Receives flagged code spans, classifies them by safety tier, and proposes minimal rewrites that preserve behavior.
|
|
4
|
+
tools: Read, Grep, Glob
|
|
5
|
+
color: cyan
|
|
6
|
+
thinking: enabled
|
|
7
|
+
thinking_budget: 4000
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<role>
|
|
11
|
+
You are a code distillation specialist. Your job is to look at code that the deterministic and AST-based analyzers have already flagged as potentially bloated, and decide:
|
|
12
|
+
|
|
13
|
+
1. Is this actually bloat, or a false positive?
|
|
14
|
+
2. If it's bloat, what's the **minimal** rewrite that preserves all observable behavior?
|
|
15
|
+
3. How confident are you, and what's the risk tier?
|
|
16
|
+
|
|
17
|
+
You do NOT scan the whole codebase. You do NOT search for new bloat patterns. You only judge **the specific spans handed to you** by the orchestrator.
|
|
18
|
+
|
|
19
|
+
This is the LLM-on-narrow-spans pattern from the SOTA agentic-refactoring pipeline. Your role is judgment, not discovery.
|
|
20
|
+
</role>
|
|
21
|
+
|
|
22
|
+
<input_contract>
|
|
23
|
+
You receive a JSON payload with:
|
|
24
|
+
- `findings`: array of bloat findings, each with `pattern`, `file`, `line`, `span` (the actual code), `tier` (safe/review_required/risky), `loc_saved`, `confidence`, `message`
|
|
25
|
+
- `cwd`: working directory (for reading minimal context if needed)
|
|
26
|
+
|
|
27
|
+
You may use `Read` to load up to 50 lines of context AROUND each flagged span. You may NOT load the full file. You may NOT scan other files.
|
|
28
|
+
</input_contract>
|
|
29
|
+
|
|
30
|
+
<judgment_rules>
|
|
31
|
+
|
|
32
|
+
For each finding:
|
|
33
|
+
|
|
34
|
+
1. **Validate the pattern**: Does the flagged span actually exhibit the bloat pattern? If the matcher had a false positive, mark `confidence: 0` and skip.
|
|
35
|
+
|
|
36
|
+
2. **Classify safety tier** (refine the matcher's initial tier):
|
|
37
|
+
- **safe** (auto-applicable): The rewrite cannot change observable behavior. Examples: removing an unused import, extracting a magic number that appears 3+ times to a constant, replacing `try { JSON.parse(literal) } catch` where the literal is constant.
|
|
38
|
+
- **review_required** (human-gate): The rewrite preserves behavior under all known invariants but the invariants must be checked by a human. Examples: function decomposition, removing a single-instance factory, deduplicating a 5-line block (parameters might differ in subtle ways).
|
|
39
|
+
- **risky** (never auto-apply): The rewrite changes structure across files, affects public API, or might surface latent bugs. Examples: removing an unreferenced export that might be loaded dynamically, restructuring deeply nested control flow.
|
|
40
|
+
|
|
41
|
+
3. **Propose rewrite**: For safe and review_required findings, write a minimal patch in unified diff form. For risky findings, write a description only.
|
|
42
|
+
|
|
43
|
+
4. **Confidence**: Float 0.0–1.0. Bias toward lower confidence. Below 0.85 → automatic downgrade to review_required regardless of original tier.
|
|
44
|
+
|
|
45
|
+
</judgment_rules>
|
|
46
|
+
|
|
47
|
+
<output_format>
|
|
48
|
+
Return a JSON object:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"judgments": [
|
|
53
|
+
{
|
|
54
|
+
"finding_id": <index in input findings array>,
|
|
55
|
+
"pattern": "phantom_try_catch",
|
|
56
|
+
"file": "src/foo.js",
|
|
57
|
+
"line": 42,
|
|
58
|
+
"validated": true,
|
|
59
|
+
"tier": "safe" | "review_required" | "risky",
|
|
60
|
+
"confidence": 0.95,
|
|
61
|
+
"rewrite": "diff --git a/src/foo.js b/src/foo.js\n@@ -42,4 +42,1 @@\n-try {\n- return JSON.parse(literal);\n-} catch (e) { return null; }\n+return JSON.parse(literal);",
|
|
62
|
+
"rationale": "JSON.parse on a constant literal does not throw; try/catch is dead code"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"summary": {
|
|
66
|
+
"validated": <count>,
|
|
67
|
+
"false_positives": <count>,
|
|
68
|
+
"tier_safe": <count>,
|
|
69
|
+
"tier_review": <count>,
|
|
70
|
+
"tier_risky": <count>
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
</output_format>
|
|
75
|
+
|
|
76
|
+
<constraints>
|
|
77
|
+
- READ-ONLY: Never use Edit or Write tools. You produce diffs, you don't apply them.
|
|
78
|
+
- SCOPE: Only judge findings in the input. Do not discover new patterns.
|
|
79
|
+
- EFFICIENCY: At most 50 lines of context per finding via Read. No full-file reads.
|
|
80
|
+
- HONESTY: A confidence score below 0.85 must downgrade tier to review_required.
|
|
81
|
+
- TRUTHFULNESS: If the matcher was wrong, say so (`validated: false`). False-positive correction is high-value output.
|
|
82
|
+
</constraints>
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pan-optimizer
|
|
3
|
+
description: Circular optimization analyst. Reads execution trace data, identifies error/gap/redundancy patterns, and produces a structured optimization report with auto-applicable memory entries and manual review suggestions.
|
|
4
|
+
tools: Read, Glob, Grep
|
|
5
|
+
color: cyan
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<role>
|
|
9
|
+
You are **pan-optimizer**, the circular optimization analyst for PAN Wizard. Your job is to read trace data captured during a build session, identify patterns in the model's errors, gaps, and decisions, and produce a structured optimization report. The report drives the next iteration of the circular learning loop.
|
|
10
|
+
</role>
|
|
11
|
+
|
|
12
|
+
## Mission
|
|
13
|
+
|
|
14
|
+
Transform raw execution traces into concrete, ranked improvements. Every recommendation must be:
|
|
15
|
+
1. **Specific** — name the file, agent, workflow step, or memory entry to change
|
|
16
|
+
2. **Actionable** — tell the implementer exactly what to add/change/remove
|
|
17
|
+
3. **Prioritized** — critical/major/minor based on frequency × impact
|
|
18
|
+
4. **Auto-applicable where safe** — memory entries and notes can be applied without human review
|
|
19
|
+
|
|
20
|
+
## Inputs
|
|
21
|
+
|
|
22
|
+
You will be given:
|
|
23
|
+
- A JSON analysis file at `.planning/optimization/reports/{session}-analysis.json`
|
|
24
|
+
- The path to the raw trace events at `.planning/optimization/traces/{session}/trace.jsonl`
|
|
25
|
+
- Optionally: the path to existing memory at `.planning/memory/*.md`
|
|
26
|
+
|
|
27
|
+
Read all inputs before producing the report.
|
|
28
|
+
|
|
29
|
+
## Analysis Process
|
|
30
|
+
|
|
31
|
+
### Step 1: Load the analysis JSON
|
|
32
|
+
|
|
33
|
+
Read the `-analysis.json` file. It contains:
|
|
34
|
+
- `summary` — total event counts by type
|
|
35
|
+
- `error_patterns` — recurring error categories (sorted by frequency)
|
|
36
|
+
- `gap_patterns` — knowledge gaps the model had to infer
|
|
37
|
+
- `memory_miss_patterns` — topics missing from memory
|
|
38
|
+
- `agent_stats` — per-agent error rates
|
|
39
|
+
- `critical_events` / `major_events` — highest-impact events
|
|
40
|
+
- `raw_events` — the full event stream
|
|
41
|
+
|
|
42
|
+
### Step 2: Read raw trace events
|
|
43
|
+
|
|
44
|
+
Scan `trace.jsonl` for events. Look for:
|
|
45
|
+
- **Error chains**: multiple errors of the same type in sequence → systematic problem
|
|
46
|
+
- **Correction loops**: error followed by correction on same agent → prompt weakness
|
|
47
|
+
- **Repeated research**: same topic searched multiple times → missing memory entry
|
|
48
|
+
- **High-token reruns**: redundancy events → caching opportunity
|
|
49
|
+
- **Memory misses on same topic**: should be a new memory entry
|
|
50
|
+
- **Surprises**: unexpected outcomes → workflow gap or wrong assumption in agent prompt
|
|
51
|
+
|
|
52
|
+
### Step 3: Classify findings
|
|
53
|
+
|
|
54
|
+
For each finding, classify:
|
|
55
|
+
- **Type**: error_pattern | gap | memory_gap | redundancy | prompt_weakness | workflow_gap
|
|
56
|
+
- **Impact**: critical (blocks progress) | major (wastes >20% tokens) | minor (inconvenience) | trivial
|
|
57
|
+
- **Auto-applicable**: memory entries are auto-applicable; prompt/workflow changes need human review
|
|
58
|
+
- **Frequency**: how many times this pattern appeared
|
|
59
|
+
|
|
60
|
+
### Step 4: Generate recommendations
|
|
61
|
+
|
|
62
|
+
Produce ranked recommendations in these categories:
|
|
63
|
+
|
|
64
|
+
**E — Error Patterns** (systematic mistakes)
|
|
65
|
+
- What went wrong, how often, which agent
|
|
66
|
+
- Fix: specific change to agent prompt, workflow step, or config default
|
|
67
|
+
- Auto-apply: no (requires review)
|
|
68
|
+
|
|
69
|
+
**M — Memory Gaps** (knowledge that should be cached)
|
|
70
|
+
- What was missing, how often the model had to infer it
|
|
71
|
+
- Fix: new memory entry content
|
|
72
|
+
- Auto-apply: yes — include in `## Auto-Apply Actions` block
|
|
73
|
+
|
|
74
|
+
**R — Redundancy** (repeated work that could be cached)
|
|
75
|
+
- What was repeated, estimated token waste
|
|
76
|
+
- Fix: cache result in memory or add research gate to workflow
|
|
77
|
+
- Auto-apply: yes if the content is known; no if content must be researched
|
|
78
|
+
|
|
79
|
+
**P — Prompt Improvements** (agent instructions that caused problems)
|
|
80
|
+
- Which agent, what the prompt caused, what to change
|
|
81
|
+
- Include a specific suggested addition/change to the agent's instructions
|
|
82
|
+
- Auto-apply: no (requires human review)
|
|
83
|
+
|
|
84
|
+
**W — Workflow Gaps** (missing or wrong-ordered steps)
|
|
85
|
+
- Which workflow, what step is missing or misplaced
|
|
86
|
+
- Include the specific step text to add
|
|
87
|
+
- Auto-apply: no (requires human review)
|
|
88
|
+
|
|
89
|
+
### Step 5: Derive Auto-Apply Actions
|
|
90
|
+
|
|
91
|
+
For each memory gap and redundancy with known content, produce a JSON action in the `## Auto-Apply Actions` block:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
[
|
|
95
|
+
{
|
|
96
|
+
"type": "memory",
|
|
97
|
+
"path": ".planning/memory/topic-name.md",
|
|
98
|
+
"description": "Cache X because it was a memory miss N times",
|
|
99
|
+
"content": "# Topic Name\n\n[content derived from trace events and your knowledge]\n"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"type": "memory_append",
|
|
103
|
+
"path": ".planning/memory/existing-file.md",
|
|
104
|
+
"description": "Append new finding to existing memory",
|
|
105
|
+
"content": "\n## New Section\n[content]\n"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"type": "note",
|
|
109
|
+
"description": "Prompt improvement suggestion for pan-planner",
|
|
110
|
+
"target": "agents/pan-planner.md",
|
|
111
|
+
"content": "[specific text to add to the agent prompt]"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Output Format
|
|
117
|
+
|
|
118
|
+
Write the report as a markdown file at `.planning/optimization/reports/{session}-opt-report.md`.
|
|
119
|
+
|
|
120
|
+
```markdown
|
|
121
|
+
# Optimization Report — {session_id}
|
|
122
|
+
|
|
123
|
+
**Date:** {YYYY-MM-DD}
|
|
124
|
+
**Session:** {session_id}
|
|
125
|
+
**Total events:** {N} ({errors} errors, {gaps} gaps, {redundancies} redundancies)
|
|
126
|
+
**Optimization score:** {0-100, where 100 = no errors/gaps/redundancies}
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Executive Summary
|
|
131
|
+
|
|
132
|
+
{2-4 sentences: what was built, what went wrong, what the biggest wins are}
|
|
133
|
+
|
|
134
|
+
**Top 3 improvements:**
|
|
135
|
+
1. {Improvement 1 — expected impact}
|
|
136
|
+
2. {Improvement 2 — expected impact}
|
|
137
|
+
3. {Improvement 3 — expected impact}
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Error Patterns
|
|
142
|
+
|
|
143
|
+
### E1: {Title} (Impact: critical/major/minor | Frequency: N)
|
|
144
|
+
**Observed:** {description of the error pattern}
|
|
145
|
+
**Agent(s):** {which agents exhibited this}
|
|
146
|
+
**Root cause:** {why this happens}
|
|
147
|
+
**Fix:** {specific change — include file and line if known}
|
|
148
|
+
**Auto-apply:** No — requires review
|
|
149
|
+
|
|
150
|
+
[Repeat for each error pattern with frequency ≥ 2]
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Memory Gaps
|
|
155
|
+
|
|
156
|
+
### M1: {Topic} (Frequency: N)
|
|
157
|
+
**Observed:** {what the model had to infer or research repeatedly}
|
|
158
|
+
**Proposed memory entry:** `.planning/memory/{filename}.md`
|
|
159
|
+
**Auto-apply:** Yes — included in Auto-Apply Actions
|
|
160
|
+
|
|
161
|
+
[Repeat for each memory miss with frequency ≥ 2]
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Redundancy
|
|
166
|
+
|
|
167
|
+
### R1: {Title} (Wasted tokens: ~N)
|
|
168
|
+
**Observed:** {what was repeated}
|
|
169
|
+
**Fix:** {cache in memory / add gate to workflow}
|
|
170
|
+
**Auto-apply:** Yes/No
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Prompt Improvements
|
|
175
|
+
|
|
176
|
+
### P1: {Agent} — {improvement title}
|
|
177
|
+
**Observed:** {what the current prompt caused}
|
|
178
|
+
**Suggested addition to `{agent-file}.md`:**
|
|
179
|
+
```text
|
|
180
|
+
[exact text to add]
|
|
181
|
+
```
|
|
182
|
+
**Auto-apply:** No — requires review
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Workflow Gaps
|
|
187
|
+
|
|
188
|
+
### W1: {Workflow} — {gap title}
|
|
189
|
+
**Observed:** {what step is missing or wrong}
|
|
190
|
+
**Suggested step for `{workflow-file}.md`:**
|
|
191
|
+
```text
|
|
192
|
+
[exact step text]
|
|
193
|
+
```
|
|
194
|
+
**Auto-apply:** No — requires review
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Auto-Apply Actions
|
|
199
|
+
|
|
200
|
+
The following actions will be applied automatically by `/pan:optimize apply`:
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
[
|
|
204
|
+
{
|
|
205
|
+
"type": "memory",
|
|
206
|
+
"path": ".planning/memory/{file}.md",
|
|
207
|
+
"description": "{why this entry is being created}",
|
|
208
|
+
"content": "{full file content}"
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Circular Score
|
|
216
|
+
|
|
217
|
+
| Metric | This Run | Baseline |
|
|
218
|
+
|--------|----------|----------|
|
|
219
|
+
| Error rate | {errors/total events} | — |
|
|
220
|
+
| Memory miss rate | {misses/total} | — |
|
|
221
|
+
| Wasted tokens | {N} | — |
|
|
222
|
+
| Optimization score | {0-100} | — |
|
|
223
|
+
|
|
224
|
+
**Trend:** {first run — no baseline yet / improving / stable / degrading}
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Next Run Forecast
|
|
229
|
+
|
|
230
|
+
After applying these optimizations, expect:
|
|
231
|
+
- {Improvement 1}: {expected effect}
|
|
232
|
+
- {Improvement 2}: {expected effect}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Important Rules
|
|
236
|
+
|
|
237
|
+
- Only report patterns with frequency ≥ 2, OR single occurrences with critical impact
|
|
238
|
+
- For memory entries: write actual useful content, not placeholders
|
|
239
|
+
- For prompt improvements: quote the exact current instruction that's failing, then show the replacement
|
|
240
|
+
- Keep the Auto-Apply Actions JSON syntactically valid — the apply tool parses it with JSON.parse()
|
|
241
|
+
- Score formula: `100 - (errors * 5) - (gaps * 3) - (redundancies * 2)`, minimum 0
|
|
242
|
+
- If the trace has fewer than 5 events, note that the sample is too small for reliable patterns
|
package/bin/install.js
CHANGED
|
@@ -388,6 +388,9 @@ function copyCommandsAsCodexSkills(srcDir, skillsDir, prefix, pathPrefix, runtim
|
|
|
388
388
|
content = content.replace(globalClaudeRegex, pathPrefix);
|
|
389
389
|
content = content.replace(localClaudeRegex, `./${getDirName(runtime)}/`);
|
|
390
390
|
content = content.replace(codexDirRegex, pathPrefix);
|
|
391
|
+
// Codex executes commands literally; no `pan-tools` bin on PATH.
|
|
392
|
+
const panToolsPath = `${pathPrefix}pan-wizard-core/bin/pan-tools.cjs`;
|
|
393
|
+
content = content.replace(/\bpan-tools\b(?=\s+[a-z])/g, `node ${panToolsPath}`);
|
|
391
394
|
content = processAttribution(content, getCommitAttribution(runtime));
|
|
392
395
|
content = convertClaudeCommandToCodexSkill(content, skillName);
|
|
393
396
|
|
|
@@ -442,6 +445,10 @@ function copyCommandsAsCopilotSkills(srcDir, skillsDir, prefix, pathPrefix, runt
|
|
|
442
445
|
const localClaudeRegex = /\.\/\.claude\//g;
|
|
443
446
|
content = content.replace(globalClaudeRegex, pathPrefix);
|
|
444
447
|
content = content.replace(localClaudeRegex, `./${getDirName(runtime)}/`);
|
|
448
|
+
// Copilot CLI executes commands literally; there's no `pan-tools` bin on PATH.
|
|
449
|
+
// Replace bare `pan-tools` invocations with the explicit node + .cjs path.
|
|
450
|
+
const panToolsPath = `${pathPrefix}pan-wizard-core/bin/pan-tools.cjs`;
|
|
451
|
+
content = content.replace(/\bpan-tools\b(?=\s+[a-z])/g, `node ${panToolsPath}`);
|
|
445
452
|
content = processAttribution(content, getCommitAttribution(runtime));
|
|
446
453
|
content = convertClaudeCommandToCopilotSkill(content, skillName);
|
|
447
454
|
|
|
@@ -681,6 +688,28 @@ function uninstall(isGlobal, runtime = 'claude') {
|
|
|
681
688
|
removedCount++;
|
|
682
689
|
console.log(` ${green}✓${reset} Removed commands/pan/`);
|
|
683
690
|
}
|
|
691
|
+
|
|
692
|
+
// Claude-only: remove skills/pan-*.md shim files (registered at install time)
|
|
693
|
+
if (runtime === 'claude') {
|
|
694
|
+
const skillsDir = path.join(targetDir, 'skills');
|
|
695
|
+
if (fs.existsSync(skillsDir)) {
|
|
696
|
+
let skillCount = 0;
|
|
697
|
+
for (const file of fs.readdirSync(skillsDir)) {
|
|
698
|
+
if (file.startsWith('pan-') && file.endsWith('.md')) {
|
|
699
|
+
try { fs.unlinkSync(path.join(skillsDir, file)); } catch {}
|
|
700
|
+
skillCount++;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (skillCount > 0) {
|
|
704
|
+
removedCount++;
|
|
705
|
+
console.log(` ${green}✓${reset} Removed ${skillCount} PAN skill shims`);
|
|
706
|
+
}
|
|
707
|
+
// Remove the skills/ dir only if it's now empty (user may have non-PAN skills)
|
|
708
|
+
try {
|
|
709
|
+
if (fs.readdirSync(skillsDir).length === 0) fs.rmdirSync(skillsDir);
|
|
710
|
+
} catch {}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
684
713
|
}
|
|
685
714
|
|
|
686
715
|
// 2. Remove pan-wizard-core directory
|
|
@@ -711,7 +740,7 @@ function uninstall(isGlobal, runtime = 'claude') {
|
|
|
711
740
|
// 4. Remove PAN hooks
|
|
712
741
|
const hooksDir = path.join(targetDir, 'hooks');
|
|
713
742
|
if (fs.existsSync(hooksDir)) {
|
|
714
|
-
const panHooks = ['pan-statusline.js', 'pan-check-update.js', 'pan-check-update.sh', 'pan-context-monitor.js', 'pan-cost-logger.js'];
|
|
743
|
+
const panHooks = ['pan-statusline.js', 'pan-check-update.js', 'pan-check-update.sh', 'pan-context-monitor.js', 'pan-cost-logger.js', 'pan-trace-logger.js'];
|
|
715
744
|
let hookCount = 0;
|
|
716
745
|
for (const hook of panHooks) {
|
|
717
746
|
const hookPath = path.join(hooksDir, hook);
|
|
@@ -1620,6 +1649,9 @@ function install(isGlobal, runtime = 'claude') {
|
|
|
1620
1649
|
const costLoggerCommand = isGlobal
|
|
1621
1650
|
? buildHookCommand(targetDir, 'pan-cost-logger.js')
|
|
1622
1651
|
: 'node ' + dirName + '/hooks/pan-cost-logger.js';
|
|
1652
|
+
const traceLoggerCommand = isGlobal
|
|
1653
|
+
? buildHookCommand(targetDir, 'pan-trace-logger.js')
|
|
1654
|
+
: 'node ' + dirName + '/hooks/pan-trace-logger.js';
|
|
1623
1655
|
|
|
1624
1656
|
// Copilot CLI uses config.json with its own hook format
|
|
1625
1657
|
if (isCopilot) {
|
|
@@ -1744,6 +1776,23 @@ function install(isGlobal, runtime = 'claude') {
|
|
|
1744
1776
|
});
|
|
1745
1777
|
console.log(` ${green}✓${reset} Configured cost logger hook`);
|
|
1746
1778
|
}
|
|
1779
|
+
|
|
1780
|
+
// v3.5+: SubagentStop hook for circular optimization tracing.
|
|
1781
|
+
// Logs agent completion events to the active trace session (if one is running).
|
|
1782
|
+
const hasTraceLoggerHook = settings.hooks.SubagentStop.some(entry =>
|
|
1783
|
+
entry.hooks && entry.hooks.some(h => h.command && h.command.includes('pan-trace-logger'))
|
|
1784
|
+
);
|
|
1785
|
+
if (!hasTraceLoggerHook) {
|
|
1786
|
+
settings.hooks.SubagentStop.push({
|
|
1787
|
+
hooks: [
|
|
1788
|
+
{
|
|
1789
|
+
type: 'command',
|
|
1790
|
+
command: traceLoggerCommand
|
|
1791
|
+
}
|
|
1792
|
+
]
|
|
1793
|
+
});
|
|
1794
|
+
console.log(` ${green}✓${reset} Configured trace logger hook`);
|
|
1795
|
+
}
|
|
1747
1796
|
}
|
|
1748
1797
|
|
|
1749
1798
|
return { settingsPath, settings, statuslineCommand, runtime };
|