pan-wizard 3.4.1 → 3.5.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.
- 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
|
@@ -58,8 +58,10 @@ Which category should this auto campaign focus on?
|
|
|
58
58
|
5. **docs** — Stale documentation, missing command descriptions (P5-P6)
|
|
59
59
|
6. **optimize** — Performance bottlenecks, redundant computation, robustness hardening (P1-P4)
|
|
60
60
|
7. **prompts** — Execute micro-prompt documents sequentially, or generate them from specs (P0-P6)
|
|
61
|
+
8. **security** — OWASP Top 10 violations, STRIDE threats, auth/injection/crypto hardening (P0-P2)
|
|
62
|
+
9. **distill** — AI code-bloat: phantom try/catch, unused imports, repeated blocks, premature abstraction, god functions (P1-P5)
|
|
61
63
|
|
|
62
|
-
Reply with a number (1-
|
|
64
|
+
Reply with a number (1-9) or category name.
|
|
63
65
|
```
|
|
64
66
|
|
|
65
67
|
**After the user replies, map their response to a category name:**
|
|
@@ -70,6 +72,8 @@ Reply with a number (1-7) or category name.
|
|
|
70
72
|
- "5" or "docs" → SELECTED_CATEGORY = docs
|
|
71
73
|
- "6" or "optimize" → SELECTED_CATEGORY = optimize
|
|
72
74
|
- "7" or "prompts" → SELECTED_CATEGORY = prompts
|
|
75
|
+
- "8" or "security" → SELECTED_CATEGORY = security
|
|
76
|
+
- "9" or "distill" → SELECTED_CATEGORY = distill
|
|
73
77
|
|
|
74
78
|
Wait for the user's reply before proceeding. Do not guess or pick a default category.
|
|
75
79
|
|
|
@@ -85,11 +89,12 @@ Wait for the user's reply before proceeding. Do not guess or pick a default cate
|
|
|
85
89
|
```
|
|
86
90
|
/pan:focus-auto [--category CAT] [--mode MODE] [--budget N] [--max-cycles N]
|
|
87
91
|
[--total-budget N] [--continue] [--stop] [--status] [--dry-run]
|
|
92
|
+
[--deep-review]
|
|
88
93
|
```
|
|
89
94
|
|
|
90
95
|
| Flag | Default | Description |
|
|
91
96
|
|------|---------|-------------|
|
|
92
|
-
| `--category` | null (all) | cleanup, tests, stability, features, docs, optimize, prompts |
|
|
97
|
+
| `--category` | null (all) | cleanup, tests, stability, features, docs, optimize, prompts, security, distill |
|
|
93
98
|
| `--mode` | category-dependent | bugfix, balanced, features, full |
|
|
94
99
|
| `--budget` | category-dependent | Points per cycle (5-100) |
|
|
95
100
|
| `--max-cycles` | 10 | Maximum iterations (1-50) |
|
|
@@ -98,6 +103,7 @@ Wait for the user's reply before proceeding. Do not guess or pick a default cate
|
|
|
98
103
|
| `--stop` | — | Gracefully stop active run |
|
|
99
104
|
| `--status` | — | Show current campaign progress |
|
|
100
105
|
| `--dry-run` | — | Show plan without executing |
|
|
106
|
+
| `--deep-review` | off | After every exec cycle, run inline OWASP security check on changed files. Verdict `block` or `review_required` stops the campaign (6th safety harness). Works with all categories. |
|
|
101
107
|
|
|
102
108
|
## Category Defaults
|
|
103
109
|
|
|
@@ -110,6 +116,7 @@ Wait for the user's reply before proceeding. Do not guess or pick a default cate
|
|
|
110
116
|
| docs | P5-P6 | balanced | 30 |
|
|
111
117
|
| optimize | P1-P4 | balanced | 50 |
|
|
112
118
|
| prompts | P0-P6 | balanced | 100 |
|
|
119
|
+
| security | P0-P2 | bugfix | 40 |
|
|
113
120
|
|
|
114
121
|
## Pipeline
|
|
115
122
|
|
|
@@ -173,6 +180,11 @@ Perform a deep codebase scan to find actionable work items with evidence.
|
|
|
173
180
|
- **features:** roadmap items not yet implemented, README promises without backing code
|
|
174
181
|
- **docs:** stale documentation, missing command descriptions
|
|
175
182
|
- **optimize:** N+1 operations (file I/O / network calls inside loops), redundant re-computation (`JSON.parse`/`stringify` of same data), synchronous blocking in async modules (`readFileSync`/`execSync` alongside async exports), algorithmic complexity (nested `.find()`/`.filter()` in loops creating O(n²)+), unnecessary allocations in hot paths (spread in loops, string concat vs `join()`), regex construction inside loops (should be hoisted), unbounded collection growth (`.push()` without size limits), swallowed errors (`catch {}` / `catch { /* */ }`), suboptimal data structures (array `.includes()` where Set is better), dead assignments, unguarded property access on nullable values (`.length`/`.split()`/`.match()[0]` without null check)
|
|
183
|
+
- **security:** Three-pass approach:
|
|
184
|
+
- **Pass 1 — Injection & crypto (inline grep):** Scan source files for `eval(`, `execSync`, `exec(`, string concatenation in SQL patterns (`` `SELECT...${`` / `"SELECT..."+`), `md5(`/`sha1(`/`createHash('md5'`/`createHash('sha1'`, hardcoded secrets (`password\s*=\s*['"]`, `api_key\s*=\s*['"]`, `secret\s*=\s*['"`), `Math.random()` used for security purposes.
|
|
185
|
+
- **Pass 2 — Auth & access control (inline grep):** Routes without auth middleware (look for `router.get/post/put/delete` without preceding `app.use(...auth...)`), `req.params.id` used directly without ownership check, `JSON.parse(` on `req.body` without schema validation, CORS `origin: '*'` or `Access-Control-Allow-Origin: *`, verbose errors that expose stack traces (`res.json({ stack:`).
|
|
186
|
+
- **Pass 3 — Semantic depth (Agent tool, optional):** For M/L items where grep found a suspicious pattern but fix guidance needs code-path tracing, use the Agent tool with Explore subagent to read the specific file and confirm exploitability before including in the batch.
|
|
187
|
+
- **Classification:** Map findings to priorities: OWASP critical/exploit-ready → P0, High/auth-bypass → P1, Medium/defense-in-depth → P2. Drop LOW/INFO — they don't meet the P0-P2 filter.
|
|
176
188
|
- **prompts:** Two operational modes — detect which applies:
|
|
177
189
|
- **Execute mode:** Find micro-prompt documents (`.md` files containing ordered prompt blocks, e.g., `## Prompt 1`, `## Prompt 2`, or numbered checklist items `- [ ] Prompt: ...`). Look in `.planning/`, project root, and `docs/` for files matching patterns: `*prompts*`, `*micro-prompt*`, `*prompt-plan*`, `*prompt-sequence*`. Each unchecked/incomplete prompt block is one work item.
|
|
178
190
|
- **Generate mode:** Find specification documents (files matching `*spec*`, `*prd*`, `*requirements*`, `*feature*` in `.planning/`, `docs/specs/`, project root) that do NOT already have a corresponding micro-prompt document. Each spec needing decomposition is one work item.
|
|
@@ -271,6 +283,32 @@ A failed item never blocks subsequent items.
|
|
|
271
283
|
5. Stage specific changed files (not `git add -A`) and commit with accurate message listing only verified items
|
|
272
284
|
6. Count: `items_completed`, `items_failed`, `points_used`
|
|
273
285
|
|
|
286
|
+
**If `--deep-review` flag is active (run after commit, before recording cycle):**
|
|
287
|
+
|
|
288
|
+
Get changed files from this cycle's commit:
|
|
289
|
+
```bash
|
|
290
|
+
CHANGED=$(git diff HEAD~1 --name-only 2>/dev/null | grep -E '\.(js|ts|jsx|tsx|py|go|rb|java|php)$')
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Run inline OWASP security check on changed files only:
|
|
294
|
+
- Grep each changed file for critical patterns:
|
|
295
|
+
- Injection: `eval(`, `execSync(`, SQL string concat (`` `SELECT...${`` ), `child_process.exec(`
|
|
296
|
+
- Crypto: `createHash('md5'`, `createHash('sha1'`, `Math.random()` near auth/token/secret context
|
|
297
|
+
- Auth bypass: routes with no auth guard added, `req.params` used as DB key without ownership check
|
|
298
|
+
- Secrets: `password\s*=\s*['"]`, `apiKey\s*=\s*['"]`, `token\s*=\s*['"]` assigned to a literal value
|
|
299
|
+
- Score findings by severity: critical (exploit-ready) → BLOCK; high (auth/injection surface) → WARN; medium/low → LOG
|
|
300
|
+
|
|
301
|
+
**Handle deep-review verdict:**
|
|
302
|
+
|
|
303
|
+
| Severity found | Verdict | Action |
|
|
304
|
+
|---------------|---------|--------|
|
|
305
|
+
| Critical pattern in changed file | `block` | STOP campaign — do NOT record cycle, revert last commit, present finding to user |
|
|
306
|
+
| High pattern in changed file | `review_required` | STOP campaign — record cycle as completed, flag finding, recommend manual review |
|
|
307
|
+
| Medium/low only | `ok_with_minor` | Continue — append findings to `.planning/focus/security-log-<date>.md` |
|
|
308
|
+
| No patterns | `ok` | Continue silently |
|
|
309
|
+
|
|
310
|
+
Write all non-ok findings to `.planning/focus/security-log-<date>.md` with file:line references.
|
|
311
|
+
|
|
274
312
|
#### Step 2.4: Record Cycle
|
|
275
313
|
|
|
276
314
|
Run: `pan-tools focus auto --update --items-completed N --items-failed N --points-used N --tests-before N --tests-after N --batch-file <path>`
|
|
@@ -282,6 +320,8 @@ Check the response for stop conditions:
|
|
|
282
320
|
- `zero_completed`: No items completed in this cycle — go to Phase 3
|
|
283
321
|
- `diminishing_returns`: Optimize only — cycle efficiency < 30% of previous cycle — go to Phase 3
|
|
284
322
|
- `prompts_complete`: Prompts only — all prompts in document executed — go to Phase 3
|
|
323
|
+
- `security_complete`: Security only — scan found no HIGH/CRITICAL items remaining — go to Phase 3
|
|
324
|
+
- `deep_review_block`: `--deep-review` only — critical pattern detected in changed files — go to Phase 3 with warning
|
|
285
325
|
- `null`: Continue to next cycle
|
|
286
326
|
|
|
287
327
|
#### Step 2.5: Inter-Cycle Context Management
|
|
@@ -341,7 +381,7 @@ Then continue immediately to the next cycle (back to Step 2.1).
|
|
|
341
381
|
|
|
342
382
|
3. Remove safety tag: `git tag -d focus-auto-baseline 2>/dev/null`
|
|
343
383
|
|
|
344
|
-
##
|
|
384
|
+
## 6-Layer Safety Harness
|
|
345
385
|
|
|
346
386
|
| Layer | Mechanism | Action |
|
|
347
387
|
|-------|-----------|--------|
|
|
@@ -350,6 +390,7 @@ Then continue immediately to the next cycle (back to Step 2.1).
|
|
|
350
390
|
| Iteration limit | `--max-cycles N` | Hard stop on loop count |
|
|
351
391
|
| Regression circuit breaker | tests_after < tests_before | Immediate stop, status=stopped |
|
|
352
392
|
| Zero-completed guard | 0 items done in a cycle | Stop — further cycles won't help |
|
|
393
|
+
| Security gate (`--deep-review`) | Critical/high OWASP pattern in changed files | Revert last commit (critical) or flag for manual review (high), stop campaign |
|
|
353
394
|
|
|
354
395
|
## 9 Behavioral Rules
|
|
355
396
|
|
|
@@ -448,6 +489,112 @@ When a specification document is found that doesn't have a matching micro-prompt
|
|
|
448
489
|
|
|
449
490
|
**After generation:** The document is written and committed. The next cycle will detect it in execute mode and begin executing prompts sequentially.
|
|
450
491
|
|
|
492
|
+
## Security Category — Execution Details
|
|
493
|
+
|
|
494
|
+
The security category scans for OWASP Top 10 (2025) violations and STRIDE threats, then fixes them cycle by cycle until the scan returns zero HIGH/CRITICAL findings.
|
|
495
|
+
|
|
496
|
+
### Scan approach (Step 2.1)
|
|
497
|
+
|
|
498
|
+
Three passes per cycle:
|
|
499
|
+
|
|
500
|
+
**Pass 1 — Fast grep scan (always runs):**
|
|
501
|
+
|
|
502
|
+
| OWASP | Grep pattern | Priority |
|
|
503
|
+
|-------|-------------|---------|
|
|
504
|
+
| A03 Injection | `eval(`, `execSync(`, `` `SELECT.*\${ ``, `child_process.exec(` | P0 |
|
|
505
|
+
| A02 Crypto | `createHash\(['"]md5\|sha1`, `Math\.random\(\)` near auth/token | P0 |
|
|
506
|
+
| A01 Access | Route without auth middleware, IDOR (raw `req.params.id` to DB) | P1 |
|
|
507
|
+
| A05 Misconfig | `origin:\s*['"]?\*`, `Access-Control-Allow-Origin: \*`, stack in response | P1 |
|
|
508
|
+
| A07 Auth | No session expiry, credentials in URL params | P1 |
|
|
509
|
+
| A04 Design | Missing rate-limit on auth/payment endpoints | P2 |
|
|
510
|
+
| A09 Logging | Security events (`login`, `payment`, `admin`) with no log call nearby | P2 |
|
|
511
|
+
|
|
512
|
+
**Pass 2 — Structural check (always runs):**
|
|
513
|
+
- Read route files and check: does every mutating endpoint (POST/PUT/PATCH/DELETE) have auth middleware before the handler?
|
|
514
|
+
- Check for hardcoded secrets: grep for `['"][A-Za-z0-9_]{20,}['"]` assigned to variables named `key`/`token`/`secret`/`password`/`apiKey`
|
|
515
|
+
- Check for prototype pollution risk: `Object.assign(req.body)` or spread from untrusted input into a stored object
|
|
516
|
+
|
|
517
|
+
**Pass 3 — Semantic depth (Agent tool, for M/L items only):**
|
|
518
|
+
When a pattern match needs code-path confirmation, spawn an Explore subagent:
|
|
519
|
+
> "Read [file]. Confirm whether [line N] is reachable from an unauthenticated request path and whether the input is sanitized before use."
|
|
520
|
+
|
|
521
|
+
Use the confirmation to decide whether to include the item at P0/P1 or drop it as a false positive.
|
|
522
|
+
|
|
523
|
+
### Item classification
|
|
524
|
+
|
|
525
|
+
| Hardener severity | Focus priority | Example |
|
|
526
|
+
|------------------|----------------|---------|
|
|
527
|
+
| Critical | P0 | `eval(req.body.code)` — direct RCE |
|
|
528
|
+
| High | P1 | Auth bypass on admin route |
|
|
529
|
+
| Medium | P2 | Rate-limiting absent on login |
|
|
530
|
+
| Low / Info | DROP | Missing security header on non-sensitive route |
|
|
531
|
+
|
|
532
|
+
### Execution (Step 2.3)
|
|
533
|
+
|
|
534
|
+
Treat each security item as a STANDARD or FULL item regardless of effort estimate:
|
|
535
|
+
|
|
536
|
+
1. **State threat:** "This is [OWASP category]. The exploit path is: [attacker does X → Y → data/system compromised]."
|
|
537
|
+
2. **Read the file** — confirm the pattern is real, not a false positive
|
|
538
|
+
3. **Implement the fix** — use established patterns (parameterized queries, allowlists, bcrypt, rate-limit middleware)
|
|
539
|
+
4. **Write or update the test** — every security fix MUST have a test that proves the vulnerability is closed (e.g., send the malicious payload, assert 400/403 not 200)
|
|
540
|
+
5. **Run full test suite** — regression check before marking DONE
|
|
541
|
+
|
|
542
|
+
### Stop condition
|
|
543
|
+
|
|
544
|
+
`security_complete` fires when the scan finds zero P0/P1 items. P2 items (medium) may remain — they won't stop the campaign unless `zero_completed` fires (no items at all).
|
|
545
|
+
|
|
546
|
+
A security campaign that ends with `security_complete` means: no critical or high OWASP violations found in the scanned files. Medium/low items can be addressed in subsequent targeted passes or documented as accepted risk.
|
|
547
|
+
|
|
548
|
+
---
|
|
549
|
+
|
|
550
|
+
## Distill Category — Execution Details
|
|
551
|
+
|
|
552
|
+
The `distill` category targets **AI-generated code bloat** with a 5-pass pipeline based on the SOTA agentic-refactoring architecture (deterministic-first, LLM-on-narrow-spans).
|
|
553
|
+
|
|
554
|
+
### Pipeline
|
|
555
|
+
|
|
556
|
+
| Pass | What | Cost | Tier output |
|
|
557
|
+
|------|------|------|-------------|
|
|
558
|
+
| 1 | **Deterministic patterns** — phantom try/catch, unused imports, magic numbers, long functions, wide param lists | Free | safe / review |
|
|
559
|
+
| 2 | **AST-style analysis** — single-instance factories, deep nesting | Free | review |
|
|
560
|
+
| 3 | **Cross-file graph** — repeated 5+ line blocks, unreferenced exports | Free | review |
|
|
561
|
+
| 4 | **LLM judgment** — pan-distiller agent receives ONLY flagged spans (max 50 lines context per finding); validates pattern, refines tier, proposes minimal rewrite | LLM tokens | safe / review / risky |
|
|
562
|
+
| 5 | **Cross-session memory** — compares findings to `.planning/memory/distill-patterns.md`; flags **regressed** patterns ("we already fixed this") | Free | metadata |
|
|
563
|
+
|
|
564
|
+
### Safety Tiers
|
|
565
|
+
|
|
566
|
+
| Tier | Rule | Action |
|
|
567
|
+
|------|------|--------|
|
|
568
|
+
| `safe` | Deterministic, behavior-preserving (e.g., remove unused import) | Auto-applied |
|
|
569
|
+
| `review_required` | Behavior preserved under invariants but human should verify | Surfaced to user |
|
|
570
|
+
| `risky` | Cross-file impact or might surface latent bugs | Never auto-applied |
|
|
571
|
+
|
|
572
|
+
A finding's confidence below 0.85 is automatically downgraded to `review_required` regardless of original tier.
|
|
573
|
+
|
|
574
|
+
### Bloat Budget
|
|
575
|
+
|
|
576
|
+
After each cycle, distill computes:
|
|
577
|
+
- **touched_loc** — total LOC modified in cycle
|
|
578
|
+
- **removable_loc** — sum of `loc_saved` across findings
|
|
579
|
+
- **essential_loc** — touched_loc − removable_loc
|
|
580
|
+
- **bloat ratio** — touched_loc / essential_loc
|
|
581
|
+
|
|
582
|
+
Default threshold: **2.0x**. If a cycle's ratio exceeds threshold, the bloat budget gate flags it for review.
|
|
583
|
+
|
|
584
|
+
### Stop condition
|
|
585
|
+
|
|
586
|
+
`distill_complete` fires when the scan finds zero bloat findings. The codebase is fully distilled for the patterns the deterministic + AST + graph passes detect.
|
|
587
|
+
|
|
588
|
+
### CLI
|
|
589
|
+
|
|
590
|
+
```bash
|
|
591
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs distill scan
|
|
592
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs distill analyze [--touched-loc N] [--bloat-threshold X]
|
|
593
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs distill report
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
`scan` returns findings. `analyze` adds bloat budget + regressed pattern detection. `report` writes findings to `.planning/memory/distill-patterns.md` for the next session.
|
|
597
|
+
|
|
451
598
|
<failure_pattern_capture>
|
|
452
599
|
When the same failure pattern appears in 2+ items within a campaign, capture it for future runs.
|
|
453
600
|
|
|
@@ -213,6 +213,12 @@ This catches emergent interactions: 5 "add try-catch" fixes might reveal the mod
|
|
|
213
213
|
4. **Prime prompt cache** — `pan-tools cache prime --summary` (once; all sub-agents in the next 5 min hit cached context)
|
|
214
214
|
5. **Report** — Output session start summary
|
|
215
215
|
|
|
216
|
+
**Circular optimization — init trace:**
|
|
217
|
+
```bash
|
|
218
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace init \
|
|
219
|
+
--description "focus-exec session" --command "focus-exec" 2>/dev/null || true
|
|
220
|
+
```
|
|
221
|
+
|
|
216
222
|
**Record baseline:**
|
|
217
223
|
```
|
|
218
224
|
baseline_version: <from package.json>
|
|
@@ -395,6 +401,11 @@ Unless `--no-commit`:
|
|
|
395
401
|
- Record session summary (items completed, tests before/after, budget used)
|
|
396
402
|
- Append error patterns if any failures occurred
|
|
397
403
|
|
|
404
|
+
### 6.3.5 Circular optimization — end trace
|
|
405
|
+
```bash
|
|
406
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace end 2>/dev/null || true
|
|
407
|
+
```
|
|
408
|
+
|
|
398
409
|
### 6.4 Final Report
|
|
399
410
|
|
|
400
411
|
```markdown
|
|
@@ -58,6 +58,12 @@ When `/pan:focus-scan` is invoked, execute all phases without stopping. Do not a
|
|
|
58
58
|
|
|
59
59
|
## Phase 0: Orientation & Baseline Snapshot
|
|
60
60
|
|
|
61
|
+
**Circular optimization — init trace:**
|
|
62
|
+
```bash
|
|
63
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace init \
|
|
64
|
+
--description "focus-scan" --command "focus-scan" 2>/dev/null || true
|
|
65
|
+
```
|
|
66
|
+
|
|
61
67
|
### 0.1 Read Current State
|
|
62
68
|
Read these files to establish baseline:
|
|
63
69
|
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pan:git
|
|
3
|
+
group: Git Workflow
|
|
4
|
+
description: Safe, phase-aware git workflow commands — commit, branch, push, status, log, stash, diff, rollback, tag, sync
|
|
5
|
+
argument-hint: "<subcommand> [options]"
|
|
6
|
+
allowed-tools:
|
|
7
|
+
- Read
|
|
8
|
+
- Write
|
|
9
|
+
- Edit
|
|
10
|
+
- Glob
|
|
11
|
+
- Grep
|
|
12
|
+
- Bash
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<objective>
|
|
16
|
+
Phase-aware git workflow with safety guardrails built in. Every subcommand that modifies history runs safety checks. Rollback uses PAN snapshot tags created by exec-phase.
|
|
17
|
+
|
|
18
|
+
Works with any git repository — PAN installation not required.
|
|
19
|
+
</objective>
|
|
20
|
+
|
|
21
|
+
<subcommands>
|
|
22
|
+
|
|
23
|
+
## Subcommands
|
|
24
|
+
|
|
25
|
+
| Subcommand | Usage | What it does |
|
|
26
|
+
|------------|-------|--------------|
|
|
27
|
+
| `commit` | `git commit --type feat --message "add X"` | Safe commit: checks deleted files + secrets, conventional type prefix |
|
|
28
|
+
| `branch` | `git branch create --phase 3` | Create / switch / list / delete branches; phase-aware naming |
|
|
29
|
+
| `push` | `git push [--remote origin] [--branch main]` | Push with remote validation; requires `--force` for force-push |
|
|
30
|
+
| `status` | `git status` | Branch + staged/unstaged/untracked counts |
|
|
31
|
+
| `log` | `git log [--count 20]` | Formatted history, default 10 entries |
|
|
32
|
+
| `stash` | `git stash save --name "WIP auth"` | Named stash save / pop / list / drop |
|
|
33
|
+
| `diff` | `git diff [--staged] [--file path]` | Diff with line counts |
|
|
34
|
+
| `rollback` | `git rollback [--tag pan-rollback-X] [--dry-run]` | Reset to PAN snapshot tag |
|
|
35
|
+
| `tag` | `git tag list [--pattern v*]` | List / create / delete tags |
|
|
36
|
+
| `sync` | `git sync [--rebase]` | Fetch + pull from origin |
|
|
37
|
+
|
|
38
|
+
</subcommands>
|
|
39
|
+
|
|
40
|
+
<workflow>
|
|
41
|
+
|
|
42
|
+
## Execution
|
|
43
|
+
|
|
44
|
+
Run the appropriate subcommand via pan-tools:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git <subcommand> [opts]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or invoke directly in conversation: `/pan:git <subcommand> [opts]`
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### commit — Safe Commit
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git commit \
|
|
58
|
+
--type feat --message "implement user auth"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Options:**
|
|
62
|
+
- `--type` — `feat | fix | docs | test | refactor | chore`
|
|
63
|
+
- `--message` — Commit message body
|
|
64
|
+
- `--all` — Stage all changes before committing
|
|
65
|
+
- `--files f1 f2` — Stage specific files
|
|
66
|
+
- `--amend` — Amend last commit (no message needed)
|
|
67
|
+
- `--force` — Bypass deleted-file and sensitive-file blocks
|
|
68
|
+
|
|
69
|
+
**Safety checks run automatically:**
|
|
70
|
+
|
|
71
|
+
| Check | Blocks on | Override |
|
|
72
|
+
|-------|-----------|---------|
|
|
73
|
+
| Deleted files | Staged deletions found | `--force` |
|
|
74
|
+
| Sensitive files | `.env`, `.pem`, `.key`, `secret`, `password`, `token` | `--force` |
|
|
75
|
+
|
|
76
|
+
**Output:** `{committed, hash, type, safety_checks}`
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### branch — Branch Management
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Phase-aware branch (names as pan/phase-3)
|
|
84
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch create --phase 3
|
|
85
|
+
|
|
86
|
+
# Custom name
|
|
87
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch create --name feature/auth
|
|
88
|
+
|
|
89
|
+
# Switch
|
|
90
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch switch --name main
|
|
91
|
+
|
|
92
|
+
# List all branches
|
|
93
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch list
|
|
94
|
+
|
|
95
|
+
# Delete (safe — merged only)
|
|
96
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch delete --name feature/old
|
|
97
|
+
|
|
98
|
+
# Delete unmerged (force)
|
|
99
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch delete --name feature/old --force
|
|
100
|
+
|
|
101
|
+
# Current branch
|
|
102
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git branch current
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Phase naming convention:** `pan/phase-{N}` — matches `phase_branch_template` in `.planning/config.json`
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### push — Safe Push
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git push
|
|
113
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git push --remote upstream --branch main
|
|
114
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git push --force # requires explicit flag
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Output:** `{pushed, remote, branch, force}`
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### status — Phase-Aware Status
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git status
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Output:** `{branch, clean, staged_count, unstaged_count, untracked_count, files}`
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
### log — Commit History
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git log --count 20
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Output:** `{commits: [{hash, message}], total}`
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### stash — Named Stash
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Save
|
|
145
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git stash save --name "WIP: auth refactor"
|
|
146
|
+
|
|
147
|
+
# List all stashes
|
|
148
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git stash list
|
|
149
|
+
|
|
150
|
+
# Pop latest
|
|
151
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git stash pop
|
|
152
|
+
|
|
153
|
+
# Pop by index
|
|
154
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git stash pop --index 1
|
|
155
|
+
|
|
156
|
+
# Drop
|
|
157
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git stash drop --index 0
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### diff — Staged/Unstaged Diff
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git diff
|
|
166
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git diff --staged
|
|
167
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git diff --staged --file src/api.js
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Output:** `{diff, lines_added, lines_removed, files_changed}`
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### rollback — Revert to PAN Snapshot
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Rollback to latest PAN snapshot tag (requires clean working tree)
|
|
178
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git rollback
|
|
179
|
+
|
|
180
|
+
# Preview — does NOT reset, shows what would happen
|
|
181
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git rollback --dry-run
|
|
182
|
+
|
|
183
|
+
# Rollback to specific tag
|
|
184
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git rollback --tag pan-rollback-03-1714000000
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Rollback workflow:**
|
|
188
|
+
1. Lists all `pan-rollback-*` tags (created by exec-phase before wave execution)
|
|
189
|
+
2. Verifies working tree is clean (blocks on dirty tree unless `--dry-run`)
|
|
190
|
+
3. Runs `git reset --hard <tag>`
|
|
191
|
+
|
|
192
|
+
**Output:** `{rolled_back, tag, hash, dry_run}`
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### tag — Tag Management
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git tag list
|
|
200
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git tag list --pattern "v*"
|
|
201
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git tag create --name v3.6.0 --message "Release 3.6.0"
|
|
202
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git tag delete --name v3.6.0-rc1
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Output:** `{tags, count}` / `{created, tag}` / `{deleted, tag}`
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### sync — Pull from Upstream
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git sync
|
|
213
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git sync --rebase
|
|
214
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs git sync --remote upstream --branch main
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Output:** `{synced, remote, branch, rebase, commits_received}`
|
|
218
|
+
|
|
219
|
+
</workflow>
|
|
220
|
+
|
|
221
|
+
<runtime_note>
|
|
222
|
+
All subcommands work with any git repository regardless of whether PAN is installed or `.planning/` exists. The only requirement is a valid git repo (`git init` or cloned).
|
|
223
|
+
</runtime_note>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# /pan:learn
|
|
2
|
+
|
|
3
|
+
Analyze the most recent trace session and generate an optimization report.
|
|
4
|
+
|
|
5
|
+
**Usage:**
|
|
6
|
+
```
|
|
7
|
+
/pan:learn
|
|
8
|
+
/pan:learn --session <session-id>
|
|
9
|
+
/pan:learn --apply
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
**Flags:**
|
|
13
|
+
- `--session <id>` — analyze a specific session instead of the most recent
|
|
14
|
+
- `--apply` — automatically apply safe optimizations after generating the report (equivalent to running `/pan:optimize apply` immediately after)
|
|
15
|
+
|
|
16
|
+
**What it does:**
|
|
17
|
+
|
|
18
|
+
1. Reads trace events from `.planning/optimization/traces/{session}/trace.jsonl`
|
|
19
|
+
2. Performs local analysis (error/gap/redundancy patterns, agent stats)
|
|
20
|
+
3. Writes `.planning/optimization/reports/{session}-analysis.json`
|
|
21
|
+
4. Invokes `pan-optimizer` agent to produce `.planning/optimization/reports/{session}-opt-report.md`
|
|
22
|
+
5. If `--apply` flag: immediately runs `/pan:optimize apply` on the new report
|
|
23
|
+
6. Prints the optimization summary
|
|
24
|
+
|
|
25
|
+
**When to run:**
|
|
26
|
+
- After any `/pan:exec-phase` or `/pan:focus-exec` that had a trace session active
|
|
27
|
+
- After a full build cycle to capture all decisions and errors
|
|
28
|
+
- On demand to understand what PAN did and how to make it smarter
|
|
29
|
+
|
|
30
|
+
**What it learns from:**
|
|
31
|
+
- Tool failures and correction loops (error events)
|
|
32
|
+
- Topics the model had to infer without context (gap events)
|
|
33
|
+
- Repeated research on the same topic (redundancy events)
|
|
34
|
+
- Memory cache misses (memory_miss events)
|
|
35
|
+
- Unexpected outcomes (surprise events)
|
|
36
|
+
|
|
37
|
+
**Output:**
|
|
38
|
+
|
|
39
|
+
The optimization report in `.planning/optimization/reports/` contains:
|
|
40
|
+
- Ranked error patterns with fix recommendations
|
|
41
|
+
- Memory gap findings with ready-to-apply memory entry content
|
|
42
|
+
- Redundancy analysis with token waste estimates
|
|
43
|
+
- Prompt improvement suggestions (require human review before applying)
|
|
44
|
+
- Workflow gap suggestions (require human review)
|
|
45
|
+
- An `## Auto-Apply Actions` JSON block for `/pan:optimize apply`
|
|
46
|
+
- A circular optimization score (0–100)
|
|
47
|
+
|
|
48
|
+
**Example:**
|
|
49
|
+
```
|
|
50
|
+
/pan:learn
|
|
51
|
+
→ Session sess_20260421T180000: 47 events (8 errors, 12 gaps, 3 redundancies)
|
|
52
|
+
→ Report: .planning/optimization/reports/sess_20260421T180000-opt-report.md
|
|
53
|
+
→ Optimization score: 72/100
|
|
54
|
+
→ Top finding: M1 — Express middleware order missing from memory (5 misses)
|
|
55
|
+
→ Auto-applicable: 3 memory entries
|
|
56
|
+
→ Needs review: 2 prompt improvements, 1 workflow gap
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**See also:** `/pan:optimize`, `/pan:exec-phase`
|
|
60
|
+
|
|
61
|
+
Follow the workflow at `.claude/workflows/learn.md` (or `pan-wizard-core/workflows/learn.md`).
|
|
@@ -111,6 +111,15 @@ Output: Milestone archived (roadmap + requirements), project.md evolved, git tag
|
|
|
111
111
|
8. **Offer next steps:**
|
|
112
112
|
- `/pan:milestone-new` — start next milestone (questioning → research → requirements → roadmap)
|
|
113
113
|
|
|
114
|
+
9. **Circular optimization — summarize what was learned this milestone:**
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace end 2>/dev/null || true
|
|
118
|
+
node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize learn 2>/dev/null || true
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Present the optimization summary to the user and suggest `/pan:optimize apply` to write memory entries.
|
|
122
|
+
|
|
114
123
|
</process>
|
|
115
124
|
|
|
116
125
|
<success_criteria>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# /pan:optimize
|
|
2
|
+
|
|
3
|
+
Manage the circular optimization loop: apply recommendations, view stats, list reports.
|
|
4
|
+
|
|
5
|
+
**Usage:**
|
|
6
|
+
```
|
|
7
|
+
/pan:optimize apply
|
|
8
|
+
/pan:optimize apply --report <filename>
|
|
9
|
+
/pan:optimize list
|
|
10
|
+
/pan:optimize stats
|
|
11
|
+
/pan:optimize trace init [--description "what you're building"]
|
|
12
|
+
/pan:optimize trace end
|
|
13
|
+
/pan:optimize trace status
|
|
14
|
+
/pan:optimize trace list
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Subcommands:**
|
|
18
|
+
|
|
19
|
+
### apply
|
|
20
|
+
Apply safe optimizations from the most recent (or specified) optimization report.
|
|
21
|
+
|
|
22
|
+
Auto-applied automatically:
|
|
23
|
+
- New memory entries (`.planning/memory/*.md`) — skipped if file already exists
|
|
24
|
+
- Suggestions appended to `.planning/optimization/suggestions.md`
|
|
25
|
+
- Config notes appended to `.planning/optimization/config-suggestions.md`
|
|
26
|
+
|
|
27
|
+
Requires human review (never auto-applied):
|
|
28
|
+
- Agent prompt changes
|
|
29
|
+
- Workflow step additions
|
|
30
|
+
- Structural changes to commands
|
|
31
|
+
|
|
32
|
+
After applying, the report lists what was applied and what still needs review.
|
|
33
|
+
|
|
34
|
+
### list
|
|
35
|
+
List all optimization reports in `.planning/optimization/reports/`, most recent first.
|
|
36
|
+
|
|
37
|
+
### stats
|
|
38
|
+
Show cumulative optimization statistics:
|
|
39
|
+
- Total trace sessions run
|
|
40
|
+
- Total events traced
|
|
41
|
+
- Total errors/gaps/redundancies seen
|
|
42
|
+
- Total optimizations applied across all runs
|
|
43
|
+
- Current active trace session (if any)
|
|
44
|
+
|
|
45
|
+
### trace init
|
|
46
|
+
Start a new trace session before running a build. The hook fires automatically on SubagentStop, but calling `trace init` first lets you attach a description to the session.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
/pan:optimize trace init --description "building express web server"
|
|
50
|
+
/pan:exec-phase 1
|
|
51
|
+
/pan:learn
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### trace end
|
|
55
|
+
Finalize the current trace session (writes summary stats to session.json).
|
|
56
|
+
|
|
57
|
+
### trace status
|
|
58
|
+
Show the active trace session ID and event count.
|
|
59
|
+
|
|
60
|
+
### trace list
|
|
61
|
+
List all trace sessions, most recent first.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
**The circular loop:**
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
┌─────────────────────────────────────────────────────┐
|
|
69
|
+
│ │
|
|
70
|
+
│ /pan:optimize trace init │
|
|
71
|
+
│ ↓ │
|
|
72
|
+
│ /pan:exec-phase N ← agents run, hook traces │
|
|
73
|
+
│ ↓ │
|
|
74
|
+
│ /pan:learn ← analyze + report │
|
|
75
|
+
│ ↓ │
|
|
76
|
+
│ /pan:optimize apply ← write memory entries │
|
|
77
|
+
│ ↓ │
|
|
78
|
+
│ Next run is smarter ← memory populated │
|
|
79
|
+
│ ↑ │
|
|
80
|
+
│ └──────────────────────────────────────────┘
|
|
81
|
+
└─────────────────────────────────────────────────────┘
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Each iteration improves the model's context: fewer memory misses, fewer repeated errors, better decisions.
|
|
85
|
+
|
|
86
|
+
**See also:** `/pan:learn`, `/pan:exec-phase`
|