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.
@@ -164,6 +164,22 @@
164
164
  * standards recommend Recommend standards based on project.md
165
165
  * standards phase-track <phase> Show standards relevant to a phase
166
166
  * standards tools [id] List external scanning tools for standards
167
+ *
168
+ * Circular Optimization Loop:
169
+ * optimize trace init Start a new trace session
170
+ * [--description "..."]
171
+ * optimize trace end Finalize trace session + write summary
172
+ * optimize trace current Show active session ID
173
+ * optimize trace list List all sessions
174
+ * optimize trace log Log a trace event to the active session
175
+ * --type <type> --description "..." [--agent a] [--category c] [--impact i]
176
+ * optimize learn [--session <id>] Analyze session, write analysis JSON
177
+ * optimize apply [--report <path>] Apply safe recommendations from report
178
+ * optimize list List optimization reports
179
+ * optimize stats Cumulative optimization statistics
180
+ *
181
+ * Self-Learn:
182
+ * learn [--session <id>] Alias for optimize learn + invoke pan-optimizer
167
183
  */
168
184
 
169
185
  const fs = require('fs');
@@ -190,6 +206,9 @@ const reviewDeep = require('./lib/review-deep.cjs');
190
206
  const knowledge = require('./lib/knowledge.cjs');
191
207
  const whatif = require('./lib/whatif.cjs');
192
208
  const bridge = require('./lib/bridge.cjs');
209
+ const optimize = require('./lib/optimize.cjs');
210
+ const git = require('./lib/git.cjs');
211
+ const distill = require('./lib/distill.cjs');
193
212
 
194
213
  /**
195
214
  * Get the value following a flag in the args array.
@@ -334,6 +353,20 @@ async function main() {
334
353
  break;
335
354
  }
336
355
 
356
+ case 'git': {
357
+ const subcommand = args[1];
358
+ if (!subcommand) { error('git subcommand required. Available: commit, branch, push, status, log, stash, diff, rollback, tag, sync'); }
359
+ git.cmdGit(cwd, subcommand, args.slice(1), raw);
360
+ break;
361
+ }
362
+
363
+ case 'distill': {
364
+ const subcommand = args[1];
365
+ if (!subcommand) { error('distill subcommand required. Available: scan, analyze, report'); }
366
+ distill.cmdDistill(cwd, subcommand, args.slice(1), raw);
367
+ break;
368
+ }
369
+
337
370
  case 'commit': {
338
371
  const amend = args.includes('--amend');
339
372
  const force = args.includes('--force');
@@ -1009,6 +1042,51 @@ async function main() {
1009
1042
  break;
1010
1043
  }
1011
1044
 
1045
+ case 'optimize': {
1046
+ const subcommand = args[1];
1047
+ if (subcommand === 'trace') {
1048
+ const traceSub = args[2];
1049
+ optimize.cmdOptimizeTrace(cwd, traceSub, {
1050
+ sessionId: getArgValue(args, '--session'),
1051
+ description: getArgValue(args, '--description'),
1052
+ command: getArgValue(args, '--command'),
1053
+ phase: getArgValue(args, '--phase'),
1054
+ // trace log opts
1055
+ agent: getArgValue(args, '--agent'),
1056
+ type: getArgValue(args, '--type'),
1057
+ category: getArgValue(args, '--category'),
1058
+ impact: getArgValue(args, '--impact'),
1059
+ description: getArgValue(args, '--description'),
1060
+ correction: getArgValue(args, '--correction'),
1061
+ tokens_wasted: getArgValue(args, '--tokens-wasted') ? Number(getArgValue(args, '--tokens-wasted')) : null,
1062
+ context: (() => { const v = getArgValue(args, '--context'); if (!v) return null; try { return JSON.parse(v); } catch { return null; } })(),
1063
+ }, raw);
1064
+ } else if (subcommand === 'learn') {
1065
+ optimize.cmdOptimizeLearn(cwd, {
1066
+ sessionId: getArgValue(args, '--session'),
1067
+ }, raw);
1068
+ } else if (subcommand === 'apply') {
1069
+ optimize.cmdOptimizeApply(cwd, {
1070
+ reportPath: getArgValue(args, '--report'),
1071
+ }, raw);
1072
+ } else if (subcommand === 'list') {
1073
+ optimize.cmdOptimizeList(cwd, raw);
1074
+ } else if (subcommand === 'stats') {
1075
+ optimize.cmdOptimizeStats(cwd, raw);
1076
+ } else {
1077
+ error('Unknown optimize subcommand. Available: trace, learn, apply, list, stats');
1078
+ }
1079
+ break;
1080
+ }
1081
+
1082
+ case 'learn': {
1083
+ // Convenience alias: pan-tools learn = optimize learn
1084
+ optimize.cmdOptimizeLearn(cwd, {
1085
+ sessionId: getArgValue(args, '--session'),
1086
+ }, raw);
1087
+ break;
1088
+ }
1089
+
1012
1090
  default:
1013
1091
  error(`Unknown command: ${command}. Run pan-tools without arguments to see available commands.`);
1014
1092
  }
@@ -26,6 +26,14 @@ Parse JSON for: `executor_model`, `verifier_model`, `reviewer_model`, `commit_do
26
26
  **If `state_exists` is false but `.planning/` exists:** Offer reconstruct or continue.
27
27
 
28
28
  When `parallelization` is false, plans within a wave execute sequentially.
29
+
30
+ **Circular optimization — start trace session for this exec:**
31
+ ```bash
32
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace init \
33
+ --description "exec-phase ${PHASE_ARG}" \
34
+ --command "exec-phase" \
35
+ --phase "${PHASE_ARG}" 2>/dev/null || true
36
+ ```
29
37
  </step>
30
38
 
31
39
  <step name="handle_branching">
@@ -47,6 +55,33 @@ From init JSON: `phase_dir`, `plan_count`, `incomplete_count`.
47
55
  Report: "Found {plan_count} plans in {phase_dir} ({incomplete_count} incomplete)"
48
56
  </step>
49
57
 
58
+ <step name="load_phase_memory">
59
+ **Load project memory before dispatching executors — prevents re-learning patterns already solved.**
60
+
61
+ ```bash
62
+ ls .planning/memory/*.md 2>/dev/null
63
+ ```
64
+
65
+ If `.planning/memory/` exists and contains `.md` files:
66
+ 1. **Read every file** using the Read tool
67
+ 2. Condense each entry to its rule(s) — 1–3 lines per file
68
+ 3. Store as `MEMORY_RULES` block for injection into executor prompts in execute_waves
69
+ 4. **Log memory priming to trace:**
70
+ ```bash
71
+ MEMORY_COUNT=$(ls .planning/memory/*.md 2>/dev/null | wc -l | tr -d ' ')
72
+ if [ "$MEMORY_COUNT" -gt "0" ]; then
73
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
74
+ --type decision --category memory_primed \
75
+ --description "Loaded ${MEMORY_COUNT} memory entries before Wave 1 dispatch" \
76
+ --agent orchestrator --impact minor \
77
+ --context "{\"memory_count\":${MEMORY_COUNT}}" \
78
+ 2>/dev/null || true
79
+ fi
80
+ ```
81
+
82
+ If no memory files exist: skip (no trace event needed).
83
+ </step>
84
+
50
85
  <step name="discover_and_group_plans">
51
86
  Load plan inventory with wave grouping in one call:
52
87
 
@@ -76,6 +111,11 @@ Execute each wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`
76
111
 
77
112
  **For each wave:**
78
113
 
114
+ 0. **Record wave start time for duration tracking:**
115
+ ```bash
116
+ WAVE_START_MS=$(node -e "console.log(Date.now())")
117
+ ```
118
+
79
119
  1. **Describe what's being built (BEFORE spawning):**
80
120
 
81
121
  Read each plan's `<objective>`. Extract what's being built and why.
@@ -125,6 +165,11 @@ Execute each wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`
125
165
  - .agents/skills/ (Project skills, if exists — list skills, read SKILL.md for each, follow relevant rules during implementation)
126
166
  </files_to_read>
127
167
 
168
+ <project_memory>
169
+ {MEMORY_RULES — insert condensed content of all .planning/memory/*.md files read in load_phase_memory step. If no memory files exist, omit this block entirely.}
170
+ Apply every rule in this block without exception. These are lessons from previous phases that the reviewer has already verified.
171
+ </project_memory>
172
+
128
173
  <success_criteria>
129
174
  - [ ] All tasks executed
130
175
  - [ ] Each task committed individually
@@ -160,6 +205,18 @@ Execute each wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`
160
205
  ---
161
206
  ```
162
207
 
208
+ Log wave completion to trace (include wall-clock duration):
209
+ ```bash
210
+ WAVE_END_MS=$(node -e "console.log(Date.now())")
211
+ WAVE_DURATION_MS=$((WAVE_END_MS - WAVE_START_MS))
212
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
213
+ --type decision --category wave_complete \
214
+ --description "Wave ${WAVE_NUM} complete: ${PLAN_IDS}" \
215
+ --agent pan-executor --impact trivial \
216
+ --context "{\"wave\":${WAVE_NUM},\"plans\":\"${PLAN_IDS}\",\"duration_ms\":${WAVE_DURATION_MS}}" \
217
+ 2>/dev/null || true
218
+ ```
219
+
163
220
  - Bad: "Wave 2 complete. Proceeding to Wave 3."
164
221
  - Good: "Terrain system complete — 3 biome types, height-based texturing, physics collision meshes. Vehicle physics (Wave 3) can now reference ground surfaces."
165
222
 
@@ -342,6 +399,33 @@ Task(
342
399
  ```
343
400
 
344
401
  **If user chooses "Continue anyway":** Proceed to verification. Review findings are informational, not blocking.
402
+
403
+ 4. **Circular optimization — log reviewer corrections to trace bus (W1 fix):**
404
+
405
+ When verdict is `NEEDS_FIXES`, write a `reviewer_correction` event so the optimizer can see the primary quality signal:
406
+ ```bash
407
+ # Extract error count from review output (parse "Errors: N" line)
408
+ REVIEW_ERROR_COUNT=$(echo "$REVIEW_OUTPUT" | grep -E "^- Errors: [0-9]+" | grep -oE "[0-9]+" | head -1)
409
+ REVIEW_ERROR_COUNT=${REVIEW_ERROR_COUNT:-1}
410
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
411
+ --type error --category reviewer_correction \
412
+ --description "Phase ${PHASE_NUMBER} reviewer: NEEDS_FIXES — ${REVIEW_ERROR_COUNT} error(s) found" \
413
+ --agent pan-reviewer --impact major \
414
+ --context "{\"phase\":\"${PHASE_NUMBER}\",\"verdict\":\"NEEDS_FIXES\",\"error_count\":${REVIEW_ERROR_COUNT}}" \
415
+ 2>/dev/null || true
416
+ ```
417
+
418
+ When verdict is `PASS_WITH_WARNINGS`, log a softer signal:
419
+ ```bash
420
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
421
+ --type decision --category reviewer_warnings \
422
+ --description "Phase ${PHASE_NUMBER} reviewer: PASS_WITH_WARNINGS — warnings present" \
423
+ --agent pan-reviewer --impact trivial \
424
+ --context "{\"phase\":\"${PHASE_NUMBER}\",\"verdict\":\"PASS_WITH_WARNINGS\"}" \
425
+ 2>/dev/null || true
426
+ ```
427
+
428
+ When verdict is `PASS`, no trace event needed — clean passes are the expected baseline.
345
429
  </step>
346
430
 
347
431
  <step name="close_parent_artifacts">
@@ -476,6 +560,19 @@ Extract from result: `next_phase`, `next_phase_name`, `is_last_phase`.
476
560
  ```bash
477
561
  node ~/.claude/pan-wizard-core/bin/pan-tools.cjs commit "docs(phase-{X}): complete phase execution" --files .planning/roadmap.md .planning/state.md .planning/requirements.md {phase_dir}/*-verification.md
478
562
  ```
563
+
564
+ **Circular optimization — finalize trace session:**
565
+ ```bash
566
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace end 2>/dev/null || true
567
+ ```
568
+
569
+ Log phase completion event:
570
+ ```bash
571
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
572
+ --type decision --category phase_complete \
573
+ --description "Phase ${PHASE_NUMBER} execution complete (${VERIFICATION_STATUS:-verified})" \
574
+ --agent orchestrator --impact minor 2>/dev/null || true
575
+ ```
479
576
  </step>
480
577
 
481
578
  <step name="offer_next">
@@ -0,0 +1,91 @@
1
+ # Workflow: /pan:learn
2
+
3
+ Analyze the most recent trace session and generate a circular optimization report.
4
+
5
+ ## Prerequisites
6
+
7
+ - A trace session must exist in `.planning/optimization/traces/`
8
+ - If no session exists, instruct the user to start one first:
9
+ ```
10
+ /pan:optimize trace init --description "what you're building"
11
+ [run your build: /pan:exec-phase N or /pan:focus-exec]
12
+ /pan:learn
13
+ ```
14
+
15
+ ## Step 1 — Identify the session
16
+
17
+ Run:
18
+ ```
19
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize trace current
20
+ ```
21
+
22
+ If no active session, run:
23
+ ```
24
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize trace list
25
+ ```
26
+ Use the most recent session unless `--session <id>` was specified.
27
+
28
+ If `--session <id>` was specified, use that session ID.
29
+
30
+ ## Step 2 — Generate local analysis
31
+
32
+ Run:
33
+ ```
34
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize learn [--session <id>]
35
+ ```
36
+
37
+ This produces `.planning/optimization/reports/{session}-analysis.json`.
38
+
39
+ Read the output and note:
40
+ - `summary.errors` — how many error events
41
+ - `summary.gaps` — how many gap events
42
+ - `summary.memory_misses` — how many memory miss events
43
+ - `summary.wasted_tokens` — tokens wasted on redundancies
44
+ - `top_error_patterns` — most frequent error categories
45
+ - `top_memory_misses` — most frequent memory miss topics
46
+
47
+ ## Step 3 — Invoke pan-optimizer agent
48
+
49
+ Spawn the `pan-optimizer` agent with this instruction:
50
+
51
+ > Read the analysis at `.planning/optimization/reports/{session}-analysis.json` and the raw trace at `.planning/optimization/traces/{session}/trace.jsonl`. Also read any existing memory at `.planning/memory/*.md` to understand what's already known. Produce a full optimization report at `.planning/optimization/reports/{session}-opt-report.md` following the format in your agent definition.
52
+
53
+ Wait for the agent to complete. It will write the report to `.planning/optimization/reports/`.
54
+
55
+ ## Step 4 — Present the summary
56
+
57
+ Read `.planning/optimization/reports/{session}-opt-report.md`.
58
+
59
+ Present to the user:
60
+ 1. **Score** — the circular optimization score (0–100)
61
+ 2. **Top 3 findings** — the most impactful recommendations
62
+ 3. **Auto-applicable count** — how many items `/pan:optimize apply` can handle automatically
63
+ 4. **Review required count** — how many prompt/workflow suggestions need human review
64
+ 5. **Next step** — suggest running `/pan:optimize apply` to apply safe optimizations
65
+
66
+ ## Step 5 — Auto-apply (if --apply flag)
67
+
68
+ If the `--apply` flag was passed, immediately run:
69
+ ```
70
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize apply
71
+ ```
72
+
73
+ Show what was applied and what still needs review.
74
+
75
+ ## Step 6 — Update the circular score baseline
76
+
77
+ After applying, tell the user what to watch in the next run:
78
+ - Which memory gaps were filled (will reduce `memory_miss` events)
79
+ - Which error patterns were documented (will reduce repeat errors if agent reads memory)
80
+ - Prompt/workflow changes to consider applying manually
81
+
82
+ ## Edge cases
83
+
84
+ **No events in trace:**
85
+ - Tell the user the trace session is empty. They may need to ensure the `pan-trace-logger` hook is registered in `.claude/settings.json`.
86
+
87
+ **Too few events (< 5):**
88
+ - The optimizer can still run but note the small sample size.
89
+
90
+ **Analysis fails:**
91
+ - Check that `.planning/optimization/traces/{session}/trace.jsonl` exists and is valid JSONL.
@@ -0,0 +1,139 @@
1
+ # Workflow: /pan:optimize
2
+
3
+ Manage the circular optimization loop — apply reports, check stats, control trace sessions.
4
+
5
+ ## Subcommand routing
6
+
7
+ | Subcommand | Action |
8
+ |------------|--------|
9
+ | `apply` | Apply safe recommendations from most recent report |
10
+ | `apply --report <file>` | Apply from a specific report |
11
+ | `list` | List all reports |
12
+ | `stats` | Show cumulative stats |
13
+ | `trace init` | Start a new trace session |
14
+ | `trace end` | Finalize current session |
15
+ | `trace status` | Show active session |
16
+ | `trace list` | List all sessions |
17
+
18
+ ---
19
+
20
+ ## apply
21
+
22
+ ### Step 1 — Identify the report
23
+
24
+ Run:
25
+ ```
26
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize list
27
+ ```
28
+
29
+ Use the most recent `.md` report (the full opt-report, not the `-analysis.json`).
30
+
31
+ If `--report <filename>` was specified, use that file from `.planning/optimization/reports/`.
32
+
33
+ ### Step 2 — Run apply
34
+
35
+ ```
36
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize apply [--report <path>]
37
+ ```
38
+
39
+ ### Step 3 — Present results
40
+
41
+ Show the user:
42
+ - **Applied** — each item that was written (memory entries, notes)
43
+ - **Skipped** — items that already exist or had unknown types
44
+ - **Still needs review** — prompt/workflow suggestions in `suggestions.md`
45
+
46
+ If memory entries were written, tell the user:
47
+ > Memory entries have been added to `.planning/memory/`. They will be loaded on the next agent run, reducing future memory misses for these topics.
48
+
49
+ ### Step 4 — Point to manual review items
50
+
51
+ If `.planning/optimization/suggestions.md` exists, tell the user to review it for:
52
+ - Agent prompt improvements (apply by editing `agents/pan-*.md`)
53
+ - Workflow step additions (apply by editing `pan-wizard-core/workflows/*.md`)
54
+
55
+ ---
56
+
57
+ ## trace init
58
+
59
+ ### Step 1 — Extract description
60
+
61
+ If `--description "..."` was provided, extract it from the args.
62
+
63
+ ### Step 2 — Initialize session
64
+
65
+ ```
66
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize trace init [--description "..."]
67
+ ```
68
+
69
+ Show the user the session ID and confirm that:
70
+ - The hook will automatically log agent completions to this session
71
+ - To log a specific decision/error manually: `pan-tools optimize trace log --type <type> --description "..."`
72
+ - To end the session explicitly: `/pan:optimize trace end`
73
+
74
+ ---
75
+
76
+ ## trace end
77
+
78
+ ```
79
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize trace end
80
+ ```
81
+
82
+ Show: session ID, event count, agent count, type breakdown.
83
+
84
+ ---
85
+
86
+ ## trace status
87
+
88
+ ```
89
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize trace current
90
+ ```
91
+
92
+ If active: show session ID and instruct how to view events.
93
+ If none: tell user to run `/pan:optimize trace init` before their next build.
94
+
95
+ ---
96
+
97
+ ## stats
98
+
99
+ ```
100
+ node .claude/pan-wizard-core/bin/pan-tools.cjs optimize stats
101
+ ```
102
+
103
+ Present as a summary table:
104
+
105
+ ```
106
+ Trace sessions: N
107
+ Optimization reports: N
108
+ Total events traced: N
109
+ Total errors traced: N
110
+ Optimizations applied: N
111
+ Active session: sess_... (or none)
112
+ ```
113
+
114
+ If `total_optimizations_applied` > 0, note:
115
+ > {N} optimizations have been applied across {apply_runs} apply runs. Each applied memory entry reduces future knowledge gaps.
116
+
117
+ ---
118
+
119
+ ## The circular optimization loop explained
120
+
121
+ When explaining the system to users:
122
+
123
+ ```
124
+ Every agent spawn → hook logs completion event
125
+
126
+ .planning/optimization/traces/{session}/trace.jsonl
127
+
128
+ /pan:learn → pan-optimizer reads trace
129
+
130
+ .planning/optimization/reports/{session}-opt-report.md
131
+
132
+ /pan:optimize apply → writes memory entries
133
+
134
+ Next build has better context → fewer errors/gaps
135
+
136
+ (repeat, improving each time)
137
+ ```
138
+
139
+ The key insight: each apply run populates `.planning/memory/` with cached knowledge. Future agent runs load this memory and skip the research/inference that caused gaps. The error rate trends down. The optimization score trends up.
@@ -24,6 +24,13 @@ Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_
24
24
 
25
25
  **If `planning_exists` is false:** Error — run `/pan:new-project` first.
26
26
 
27
+ **Circular optimization — ensure trace session active:**
28
+ ```bash
29
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace init \
30
+ --description "plan-phase ${PHASE}" \
31
+ --command "plan-phase" --phase "${PHASE}" 2>/dev/null || true
32
+ ```
33
+
27
34
  ## 2. Parse and Normalize Arguments
28
35
 
29
36
  Extract from $ARGUMENTS: phase number (integer or decimal like `2.1`), flags (`--research`, `--skip-research`, `--gaps`, `--skip-verify`, `--prd <filepath>`).
@@ -383,7 +390,19 @@ Task(
383
390
  ## 11. Handle Checker Return
384
391
 
385
392
  - **`## VERIFICATION PASSED`:** Display confirmation, proceed to step 13.
393
+ ```bash
394
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
395
+ --type decision --category plan_verified \
396
+ --description "Plan-checker passed for phase ${PHASE_NUMBER}" \
397
+ --agent pan-plan-checker --impact trivial 2>/dev/null || true
398
+ ```
386
399
  - **`## ISSUES FOUND`:** Display issues, check iteration count, proceed to step 12.
400
+ ```bash
401
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
402
+ --type error --category plan_checker_issues \
403
+ --description "Plan-checker found issues in phase ${PHASE_NUMBER} plans" \
404
+ --agent pan-plan-checker --impact minor 2>/dev/null || true
405
+ ```
387
406
 
388
407
  ## 12. Revision Loop (Max 3 Iterations)
389
408
 
@@ -436,6 +455,14 @@ Offer: 1) Force proceed, 2) Provide guidance and retry, 3) Abandon
436
455
 
437
456
  Route to `<offer_next>` OR `auto_advance` depending on flags/config.
438
457
 
458
+ **Circular optimization — log plan creation:**
459
+ ```bash
460
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
461
+ --type decision --category plans_created \
462
+ --description "Plan-phase complete for phase ${PHASE_NUMBER}: ${PLAN_COUNT} plans created" \
463
+ --agent pan-planner --impact minor 2>/dev/null || true
464
+ ```
465
+
439
466
  ## 14. Auto-Advance Check
440
467
 
441
468
  Check for auto-advance trigger:
@@ -52,6 +52,13 @@ Parse JSON for: `planner_model`, `executor_model`, `checker_model`, `verifier_mo
52
52
 
53
53
  Quick tasks can run mid-phase - validation only checks roadmap.md exists, not phase status.
54
54
 
55
+ **Circular optimization — ensure trace session active:**
56
+ ```bash
57
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace init \
58
+ --description "quick: ${DESCRIPTION}" \
59
+ --command "quick" 2>/dev/null || true
60
+ ```
61
+
55
62
  ---
56
63
 
57
64
  **Step 3: Create task directory**
@@ -282,6 +282,22 @@ If gaps_found: list gaps + recommended fix plan names.
282
282
  If human_needed: list items requiring human testing.
283
283
 
284
284
  Orchestrator routes: `passed` → update_roadmap | `gaps_found` → create/execute fixes, re-verify | `human_needed` → present to user.
285
+
286
+ **Circular optimization — log verification outcome:**
287
+ ```bash
288
+ # Map status to impact and event type
289
+ if [ "${STATUS}" = "passed" ]; then
290
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
291
+ --type decision --category verification_passed \
292
+ --description "Phase ${PHASE_NUMBER} verification passed (score: ${SCORE})" \
293
+ --agent pan-verifier --impact minor 2>/dev/null || true
294
+ elif [ "${STATUS}" = "gaps_found" ]; then
295
+ node ~/.claude/pan-wizard-core/bin/pan-tools.cjs optimize trace log \
296
+ --type error --category verification_gaps \
297
+ --description "Phase ${PHASE_NUMBER} verification found gaps (score: ${SCORE})" \
298
+ --agent pan-verifier --impact major 2>/dev/null || true
299
+ fi
300
+ ```
285
301
  </step>
286
302
 
287
303
  </process>
@@ -14,7 +14,8 @@ const HOOKS_TO_COPY = [
14
14
  'pan-check-update.js',
15
15
  'pan-context-monitor.js',
16
16
  'pan-statusline.js',
17
- 'pan-cost-logger.js'
17
+ 'pan-cost-logger.js',
18
+ 'pan-trace-logger.js'
18
19
  ];
19
20
 
20
21
  function build() {