pan-wizard 2.9.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.
Files changed (75) hide show
  1. package/README.md +31 -9
  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-distiller.md +82 -0
  6. package/agents/pan-document_code.md +21 -0
  7. package/agents/pan-executor.md +16 -0
  8. package/agents/pan-hardener.md +113 -0
  9. package/agents/pan-integration-checker.md +2 -0
  10. package/agents/pan-knowledge.md +81 -0
  11. package/agents/pan-meta-reviewer.md +91 -0
  12. package/agents/pan-optimizer.md +242 -0
  13. package/agents/pan-plan-checker.md +2 -0
  14. package/agents/pan-previewer.md +98 -0
  15. package/agents/pan-project-researcher.md +4 -4
  16. package/agents/pan-reviewer.md +2 -0
  17. package/agents/pan-verifier.md +2 -0
  18. package/bin/install-lib.cjs +197 -0
  19. package/bin/install.js +2048 -1959
  20. package/commands/pan/cost.md +132 -0
  21. package/commands/pan/exec-phase.md +15 -0
  22. package/commands/pan/focus-auto.md +168 -3
  23. package/commands/pan/focus-exec.md +21 -1
  24. package/commands/pan/focus-scan.md +6 -0
  25. package/commands/pan/git.md +223 -0
  26. package/commands/pan/knowledge.md +129 -0
  27. package/commands/pan/learn.md +61 -0
  28. package/commands/pan/map-codebase.md +15 -0
  29. package/commands/pan/mcp-bridge.md +145 -0
  30. package/commands/pan/milestone-done.md +9 -0
  31. package/commands/pan/optimize.md +86 -0
  32. package/commands/pan/plan-phase.md +11 -0
  33. package/commands/pan/preview.md +114 -0
  34. package/commands/pan/profile.md +37 -0
  35. package/commands/pan/review-deep.md +128 -0
  36. package/commands/pan/verify-phase.md +11 -0
  37. package/commands/pan/what-if.md +146 -0
  38. package/hooks/dist/pan-cost-logger.js +102 -0
  39. package/hooks/dist/pan-statusline.js +154 -108
  40. package/hooks/dist/pan-trace-logger.js +197 -0
  41. package/package.json +1 -1
  42. package/pan-wizard-core/bin/lib/bridge.cjs +269 -0
  43. package/pan-wizard-core/bin/lib/bus.cjs +251 -0
  44. package/pan-wizard-core/bin/lib/codebase.cjs +118 -0
  45. package/pan-wizard-core/bin/lib/commands.cjs +1 -0
  46. package/pan-wizard-core/bin/lib/constants.cjs +44 -1
  47. package/pan-wizard-core/bin/lib/context-budget.cjs +27 -0
  48. package/pan-wizard-core/bin/lib/core.cjs +91 -6
  49. package/pan-wizard-core/bin/lib/cost.cjs +359 -0
  50. package/pan-wizard-core/bin/lib/distill.cjs +510 -0
  51. package/pan-wizard-core/bin/lib/focus.cjs +108 -3
  52. package/pan-wizard-core/bin/lib/git.cjs +407 -0
  53. package/pan-wizard-core/bin/lib/init.cjs +5 -5
  54. package/pan-wizard-core/bin/lib/knowledge.cjs +331 -0
  55. package/pan-wizard-core/bin/lib/memory.cjs +252 -0
  56. package/pan-wizard-core/bin/lib/optimize.cjs +653 -0
  57. package/pan-wizard-core/bin/lib/phase.cjs +40 -13
  58. package/pan-wizard-core/bin/lib/preview.cjs +480 -0
  59. package/pan-wizard-core/bin/lib/review-deep.cjs +280 -0
  60. package/pan-wizard-core/bin/lib/roadmap.cjs +4 -4
  61. package/pan-wizard-core/bin/lib/state.cjs +2 -2
  62. package/pan-wizard-core/bin/lib/verify.cjs +34 -1
  63. package/pan-wizard-core/bin/lib/whatif.cjs +289 -0
  64. package/pan-wizard-core/bin/pan-tools.cjs +317 -4
  65. package/pan-wizard-core/templates/playbook.md +53 -0
  66. package/pan-wizard-core/templates/preview-report.md +93 -0
  67. package/pan-wizard-core/templates/roadmap.md +24 -24
  68. package/pan-wizard-core/templates/state.md +12 -9
  69. package/pan-wizard-core/workflows/exec-phase.md +97 -0
  70. package/pan-wizard-core/workflows/learn.md +91 -0
  71. package/pan-wizard-core/workflows/optimize.md +139 -0
  72. package/pan-wizard-core/workflows/plan-phase.md +28 -1
  73. package/pan-wizard-core/workflows/quick.md +7 -0
  74. package/pan-wizard-core/workflows/verify-phase.md +16 -0
  75. package/scripts/build-hooks.js +3 -1
@@ -3,6 +3,8 @@ name: pan-reviewer
3
3
  description: Read-only code review agent. Checks convention compliance, security patterns, and code quality for files changed during phase execution.
4
4
  tools: Read, Grep, Glob, Bash
5
5
  color: yellow
6
+ thinking: enabled
7
+ thinking_budget: 4000
6
8
  ---
7
9
 
8
10
  <role>
@@ -3,6 +3,8 @@ name: pan-verifier
3
3
  description: Verifies phase goal achievement through goal-backward analysis. Checks codebase delivers what phase promised, not just that tasks completed. Creates verification.md report.
4
4
  tools: Read, Write, Bash, Grep, Glob
5
5
  color: green
6
+ thinking: enabled
7
+ thinking_budget: 6000
6
8
  ---
7
9
 
8
10
  <role>
@@ -570,6 +570,198 @@ function buildHookCommand(configDir, hookName) {
570
570
  return `node "${hooksPath}"`;
571
571
  }
572
572
 
573
+ // ─── Opus 4.7 Skills & Thinking ────────────────────────────────────────────
574
+
575
+ /**
576
+ * Build a Claude Code native skill shim for a PAN command.
577
+ *
578
+ * Claude Code 1.x discovers skills in `.claude/skills/` by frontmatter.
579
+ * PAN's commands live in `.claude/commands/pan/`, so we write a small shim
580
+ * that registers the command as a skill pointing back at the command file.
581
+ *
582
+ * @param {Object} opts
583
+ * @param {string} opts.commandName - e.g. "focus-scan"
584
+ * @param {string} opts.description - Human-readable one-liner (≤120 chars preferred)
585
+ * @param {string} [opts.trigger] - Optional trigger guidance for auto-invocation
586
+ * @returns {string} Skill markdown content
587
+ */
588
+ function buildClaudeSkillShim(opts) {
589
+ if (!opts || typeof opts.commandName !== 'string' || !opts.commandName.trim()) {
590
+ throw new Error('buildClaudeSkillShim: commandName is required');
591
+ }
592
+ const name = opts.commandName.trim();
593
+ const description = (opts.description || '').replace(/\s+/g, ' ').trim();
594
+ const trigger = (opts.trigger || '').replace(/\s+/g, ' ').trim();
595
+
596
+ const frontmatter = [
597
+ '---',
598
+ `name: pan-${name}`,
599
+ `description: ${yamlQuote(description)}`,
600
+ trigger ? `trigger: ${yamlQuote(trigger)}` : null,
601
+ 'source: pan-wizard',
602
+ '---',
603
+ ].filter(Boolean).join('\n');
604
+
605
+ const body = [
606
+ '',
607
+ `# /pan:${name}`,
608
+ '',
609
+ description || `PAN command: ${name}`,
610
+ '',
611
+ `Invokes the command defined at \`.claude/commands/pan/${name}.md\`.`,
612
+ '',
613
+ `To use, run: \`/pan:${name}\``,
614
+ '',
615
+ ].join('\n');
616
+
617
+ return frontmatter + body;
618
+ }
619
+
620
+ /**
621
+ * Translate a thinking directive from the generic PAN frontmatter shape
622
+ * into the runtime-specific syntax (or prose fallback).
623
+ *
624
+ * PAN agents declare: `thinking: enabled` and `thinking_budget: 8000` in
625
+ * frontmatter. Runtimes that support native extended thinking consume those
626
+ * fields directly. Runtimes without native support get a prose preamble
627
+ * that coaches the model to think step-by-step before tool calls.
628
+ *
629
+ * @param {string} runtime - 'claude'|'codex'|'gemini'|'opencode'|'copilot'
630
+ * @param {Object} directive - {enabled: boolean, budget: number}
631
+ * @returns {{frontmatter: Object, preamble: string}} Translated directive.
632
+ * `frontmatter` = fields to add to the agent's YAML header.
633
+ * `preamble` = prose to inject at top of agent prompt.
634
+ */
635
+ function translateThinkingDirective(runtime, directive) {
636
+ const result = { frontmatter: {}, preamble: '' };
637
+ if (!directive || !directive.enabled) return result;
638
+ const budget = Number(directive.budget) > 0 ? Number(directive.budget) : 2000;
639
+
640
+ switch (runtime) {
641
+ case 'claude':
642
+ // Claude Code consumes these natively.
643
+ result.frontmatter = { thinking: 'enabled', thinking_budget: budget };
644
+ return result;
645
+ case 'codex':
646
+ case 'opencode':
647
+ case 'gemini':
648
+ case 'copilot':
649
+ default:
650
+ // Prose fallback — host runtime has no native thinking support.
651
+ result.preamble = `Think through the problem step-by-step before taking any action. Reason about edge cases, hidden dependencies, and likely failure modes. Use up to ~${budget} tokens of internal reasoning. Only after that, call tools or write output.`;
652
+ return result;
653
+ }
654
+ }
655
+
656
+ /**
657
+ * Strip Opus 4.7 `thinking` / `thinking_budget` frontmatter fields from an
658
+ * agent markdown file for runtimes that don't support native extended
659
+ * thinking. When thinking was enabled, inject a prose preamble at the top
660
+ * of the body instructing the model to think step-by-step.
661
+ *
662
+ * Claude runtime is a no-op — those fields stay in frontmatter so the
663
+ * host runtime consumes them.
664
+ *
665
+ * @param {string} content - Full agent .md content
666
+ * @param {string} runtime - 'claude'|'codex'|'gemini'|'opencode'|'copilot'
667
+ * @returns {string} Possibly-rewritten content
668
+ */
669
+ function stripThinkingFrontmatter(content, runtime) {
670
+ if (runtime === 'claude') return content;
671
+ if (typeof content !== 'string' || !content) return content;
672
+
673
+ const { frontmatter, body } = extractFrontmatterAndBody(content);
674
+ if (!frontmatter) return content;
675
+
676
+ const thinkingValue = extractFrontmatterField(frontmatter, 'thinking');
677
+ const budgetValue = extractFrontmatterField(frontmatter, 'thinking_budget');
678
+ if (!thinkingValue && !budgetValue) return content;
679
+
680
+ // Remove the two fields (match on their own lines only).
681
+ let fmBody = frontmatter
682
+ .replace(/^thinking:\s*[^\n]*\n?/gm, '')
683
+ .replace(/^thinking_budget:\s*[^\n]*\n?/gm, '');
684
+
685
+ const rebuilt = `---\n${fmBody.replace(/^---\n|\n---$/g, '')}\n---`;
686
+ let out = rebuilt.replace(/\n\n+/g, '\n\n') + '\n\n';
687
+
688
+ // If thinking was enabled, prepend a prose preamble.
689
+ const enabled = String(thinkingValue || '').toLowerCase().trim() === 'enabled'
690
+ || String(thinkingValue || '').toLowerCase().trim() === 'true';
691
+ if (enabled) {
692
+ const directive = { enabled: true, budget: Number(budgetValue) || 2000 };
693
+ const { preamble } = translateThinkingDirective(runtime, directive);
694
+ if (preamble) {
695
+ out += `<!-- pan:thinking -->\n${preamble}\n<!-- /pan:thinking -->\n\n`;
696
+ }
697
+ }
698
+
699
+ out += body.replace(/^\n+/, '');
700
+ return out;
701
+ }
702
+
703
+ // ─── Opus 4.7 Capability Detection ──────────────────────────────────────────
704
+
705
+ /**
706
+ * Detect model capabilities from a model name string.
707
+ * Used by installer to warn users when their default model lacks features
708
+ * PAN 2.10+ relies on (1M context, extended thinking, prompt caching).
709
+ *
710
+ * @param {string} modelName - e.g. "claude-opus-4-7", "claude-sonnet-4-6", "gpt-5"
711
+ * @returns {{has_1m_ctx: boolean, has_thinking: boolean, has_cache: boolean, tier: string}}
712
+ */
713
+ function detectModelCapabilities(modelName) {
714
+ const result = { has_1m_ctx: false, has_thinking: false, has_cache: false, tier: 'unknown' };
715
+ if (typeof modelName !== 'string' || !modelName) return result;
716
+ const n = modelName.toLowerCase();
717
+
718
+ // Anthropic Claude family
719
+ if (n.includes('opus-4-7') || n.includes('opus-4.7')) {
720
+ return { has_1m_ctx: true, has_thinking: true, has_cache: true, tier: 'reasoning' };
721
+ }
722
+ if (n.includes('opus-4-6') || n.includes('opus-4.6') || n.includes('opus-4')) {
723
+ return { has_1m_ctx: false, has_thinking: true, has_cache: true, tier: 'reasoning' };
724
+ }
725
+ if (n.includes('sonnet-4-6') || n.includes('sonnet-4.6') || n.includes('sonnet-4')) {
726
+ return { has_1m_ctx: false, has_thinking: true, has_cache: true, tier: 'mid' };
727
+ }
728
+ if (n.includes('haiku-4-5') || n.includes('haiku-4.5') || n.includes('haiku-4')) {
729
+ return { has_1m_ctx: false, has_thinking: false, has_cache: true, tier: 'fast' };
730
+ }
731
+ // Older Claude 3.x — no thinking, no 1M context.
732
+ if (n.includes('claude-3')) {
733
+ return { has_1m_ctx: false, has_thinking: false, has_cache: true, tier: n.includes('opus') ? 'reasoning' : (n.includes('haiku') ? 'fast' : 'mid') };
734
+ }
735
+
736
+ // OpenAI GPT-5 family — assume caching + thinking but not 1M ctx.
737
+ if (n.startsWith('gpt-5') || n.includes('o3') || n.includes('o4')) {
738
+ return { has_1m_ctx: false, has_thinking: true, has_cache: true, tier: 'reasoning' };
739
+ }
740
+ if (n.startsWith('gpt-4')) {
741
+ return { has_1m_ctx: false, has_thinking: false, has_cache: true, tier: 'mid' };
742
+ }
743
+
744
+ // Gemini family. Distinguishes Pro / Flash / Flash-Lite and 2.5/3.x.
745
+ // - Pro variants → reasoning tier (thinking available on 2.5+)
746
+ // - Flash → mid tier (thinking on 2.5+)
747
+ // - Flash-Lite → fast tier (no thinking)
748
+ // - 1M context is native on 2.x / 3.x Pro + Flash; Flash-Lite is 1M too on 2.5+.
749
+ if (n.includes('gemini-3') || n.includes('gemini-2') || n.includes('gemini-1.5')) {
750
+ const isFlashLite = n.includes('flash-lite');
751
+ const isFlash = !isFlashLite && n.includes('flash');
752
+ const isPro = !isFlash && !isFlashLite; // default to Pro when neither flash nor flash-lite in name
753
+ const is25orNewer = n.includes('gemini-2.5') || n.includes('gemini-3') || n.includes('-2-5');
754
+ const hasThinking = (is25orNewer || n.includes('thinking')) && !isFlashLite;
755
+ // 1M context: Pro + Flash on 2.x/3.x, Flash-Lite on 2.5+, Gemini 1.5 Pro (but not 1.5 Flash typically).
756
+ const has1m = isPro || isFlash || (isFlashLite && is25orNewer)
757
+ || (n.includes('gemini-1.5-pro') && !isFlash);
758
+ const tier = isFlashLite ? 'fast' : (isFlash ? 'mid' : 'reasoning');
759
+ return { has_1m_ctx: has1m, has_thinking: hasThinking, has_cache: true, tier };
760
+ }
761
+
762
+ return result;
763
+ }
764
+
573
765
  // ─── Exports ────────────────────────────────────────────────────────────────
574
766
 
575
767
  module.exports = {
@@ -613,4 +805,9 @@ module.exports = {
613
805
  processAttribution,
614
806
  // JSONC
615
807
  parseJsonc,
808
+ // Opus 4.7 capabilities
809
+ detectModelCapabilities,
810
+ buildClaudeSkillShim,
811
+ translateThinkingDirective,
812
+ stripThinkingFrontmatter,
616
813
  };