pan-wizard 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +772 -0
  3. package/agents/pan-debugger.md +1246 -0
  4. package/agents/pan-document_code.md +965 -0
  5. package/agents/pan-executor.md +469 -0
  6. package/agents/pan-integration-checker.md +443 -0
  7. package/agents/pan-phase-researcher.md +572 -0
  8. package/agents/pan-plan-checker.md +763 -0
  9. package/agents/pan-planner.md +1297 -0
  10. package/agents/pan-project-researcher.md +647 -0
  11. package/agents/pan-research-synthesizer.md +239 -0
  12. package/agents/pan-reviewer.md +112 -0
  13. package/agents/pan-roadmapper.md +642 -0
  14. package/agents/pan-verifier.md +672 -0
  15. package/assets/pan-logo-2000-transparent.svg +30 -0
  16. package/assets/pan-logo-2000.svg +43 -0
  17. package/assets/terminal.svg +119 -0
  18. package/bin/install-lib.cjs +616 -0
  19. package/bin/install.js +1936 -0
  20. package/commands/pan/add-phase.md +44 -0
  21. package/commands/pan/assumptions.md +47 -0
  22. package/commands/pan/audit-deployment.md +378 -0
  23. package/commands/pan/debug.md +168 -0
  24. package/commands/pan/discord.md +19 -0
  25. package/commands/pan/discuss-phase.md +84 -0
  26. package/commands/pan/exec-phase.md +45 -0
  27. package/commands/pan/focus-auto.md +323 -0
  28. package/commands/pan/focus-design.md +816 -0
  29. package/commands/pan/focus-exec.md +316 -0
  30. package/commands/pan/focus-plan.md +101 -0
  31. package/commands/pan/focus-scan.md +272 -0
  32. package/commands/pan/focus-sync.md +104 -0
  33. package/commands/pan/health.md +23 -0
  34. package/commands/pan/help.md +23 -0
  35. package/commands/pan/insert-phase.md +33 -0
  36. package/commands/pan/map-codebase.md +72 -0
  37. package/commands/pan/milestone-audit.md +37 -0
  38. package/commands/pan/milestone-cleanup.md +19 -0
  39. package/commands/pan/milestone-done.md +137 -0
  40. package/commands/pan/milestone-gaps.md +35 -0
  41. package/commands/pan/milestone-new.md +45 -0
  42. package/commands/pan/new-project.md +43 -0
  43. package/commands/pan/patches.md +110 -0
  44. package/commands/pan/pause.md +39 -0
  45. package/commands/pan/phase-budget.md +23 -0
  46. package/commands/pan/phase-tests.md +42 -0
  47. package/commands/pan/plan-phase.md +46 -0
  48. package/commands/pan/profile.md +36 -0
  49. package/commands/pan/progress.md +25 -0
  50. package/commands/pan/quick.md +42 -0
  51. package/commands/pan/remove-phase.md +32 -0
  52. package/commands/pan/research-phase.md +190 -0
  53. package/commands/pan/resume.md +41 -0
  54. package/commands/pan/retro.md +33 -0
  55. package/commands/pan/settings.md +37 -0
  56. package/commands/pan/todo-add.md +48 -0
  57. package/commands/pan/todo-check.md +46 -0
  58. package/commands/pan/update.md +38 -0
  59. package/commands/pan/verify-phase.md +39 -0
  60. package/hooks/dist/pan-check-update.js +62 -0
  61. package/hooks/dist/pan-context-monitor.js +122 -0
  62. package/hooks/dist/pan-statusline.js +108 -0
  63. package/package.json +66 -0
  64. package/pan-wizard-core/bin/lib/codebase.cjs +746 -0
  65. package/pan-wizard-core/bin/lib/commands.cjs +1435 -0
  66. package/pan-wizard-core/bin/lib/config.cjs +611 -0
  67. package/pan-wizard-core/bin/lib/constants.cjs +696 -0
  68. package/pan-wizard-core/bin/lib/context-budget.cjs +150 -0
  69. package/pan-wizard-core/bin/lib/core.cjs +650 -0
  70. package/pan-wizard-core/bin/lib/focus.cjs +900 -0
  71. package/pan-wizard-core/bin/lib/frontmatter.cjs +442 -0
  72. package/pan-wizard-core/bin/lib/init.cjs +881 -0
  73. package/pan-wizard-core/bin/lib/milestone.cjs +276 -0
  74. package/pan-wizard-core/bin/lib/phase.cjs +1212 -0
  75. package/pan-wizard-core/bin/lib/roadmap.cjs +470 -0
  76. package/pan-wizard-core/bin/lib/state.cjs +1029 -0
  77. package/pan-wizard-core/bin/lib/template.cjs +314 -0
  78. package/pan-wizard-core/bin/lib/utils.cjs +171 -0
  79. package/pan-wizard-core/bin/lib/verify.cjs +1808 -0
  80. package/pan-wizard-core/bin/pan-tools.cjs +773 -0
  81. package/pan-wizard-core/references/checkpoints.md +776 -0
  82. package/pan-wizard-core/references/continuation-format.md +249 -0
  83. package/pan-wizard-core/references/decimal-phase-calculation.md +65 -0
  84. package/pan-wizard-core/references/git-integration.md +248 -0
  85. package/pan-wizard-core/references/git-planning-commit.md +38 -0
  86. package/pan-wizard-core/references/model-profile-resolution.md +34 -0
  87. package/pan-wizard-core/references/model-profiles.md +111 -0
  88. package/pan-wizard-core/references/phase-argument-parsing.md +61 -0
  89. package/pan-wizard-core/references/planning-config.md +196 -0
  90. package/pan-wizard-core/references/questioning.md +145 -0
  91. package/pan-wizard-core/references/tdd.md +263 -0
  92. package/pan-wizard-core/references/ui-brand.md +160 -0
  93. package/pan-wizard-core/references/verification-patterns.md +612 -0
  94. package/pan-wizard-core/templates/codebase/architecture.md +283 -0
  95. package/pan-wizard-core/templates/codebase/best-practices.md +133 -0
  96. package/pan-wizard-core/templates/codebase/concerns.md +325 -0
  97. package/pan-wizard-core/templates/codebase/conventions.md +307 -0
  98. package/pan-wizard-core/templates/codebase/integrations.md +305 -0
  99. package/pan-wizard-core/templates/codebase/relationships.md +124 -0
  100. package/pan-wizard-core/templates/codebase/stack.md +199 -0
  101. package/pan-wizard-core/templates/codebase/structure.md +298 -0
  102. package/pan-wizard-core/templates/codebase/testing.md +480 -0
  103. package/pan-wizard-core/templates/config.json +37 -0
  104. package/pan-wizard-core/templates/context.md +283 -0
  105. package/pan-wizard-core/templates/continue-here.md +78 -0
  106. package/pan-wizard-core/templates/debug-subagent-prompt.md +91 -0
  107. package/pan-wizard-core/templates/debug.md +164 -0
  108. package/pan-wizard-core/templates/discovery.md +146 -0
  109. package/pan-wizard-core/templates/milestone-archive.md +123 -0
  110. package/pan-wizard-core/templates/milestone.md +115 -0
  111. package/pan-wizard-core/templates/phase-prompt.md +593 -0
  112. package/pan-wizard-core/templates/planner-subagent-prompt.md +117 -0
  113. package/pan-wizard-core/templates/project.md +184 -0
  114. package/pan-wizard-core/templates/requirements.md +231 -0
  115. package/pan-wizard-core/templates/research-project/architecture.md +204 -0
  116. package/pan-wizard-core/templates/research-project/features.md +147 -0
  117. package/pan-wizard-core/templates/research-project/pitfalls.md +200 -0
  118. package/pan-wizard-core/templates/research-project/stack.md +120 -0
  119. package/pan-wizard-core/templates/research-project/summary.md +170 -0
  120. package/pan-wizard-core/templates/research.md +552 -0
  121. package/pan-wizard-core/templates/retrospective.md +54 -0
  122. package/pan-wizard-core/templates/roadmap.md +202 -0
  123. package/pan-wizard-core/templates/standards.md +24 -0
  124. package/pan-wizard-core/templates/state.md +176 -0
  125. package/pan-wizard-core/templates/summary-complex.md +59 -0
  126. package/pan-wizard-core/templates/summary-minimal.md +41 -0
  127. package/pan-wizard-core/templates/summary-standard.md +49 -0
  128. package/pan-wizard-core/templates/summary.md +249 -0
  129. package/pan-wizard-core/templates/uat.md +247 -0
  130. package/pan-wizard-core/templates/user-setup.md +311 -0
  131. package/pan-wizard-core/templates/validation.md +76 -0
  132. package/pan-wizard-core/templates/verification-report.md +322 -0
  133. package/pan-wizard-core/workflows/add-phase.md +111 -0
  134. package/pan-wizard-core/workflows/assumptions.md +178 -0
  135. package/pan-wizard-core/workflows/diagnose-issues.md +219 -0
  136. package/pan-wizard-core/workflows/discuss-phase.md +542 -0
  137. package/pan-wizard-core/workflows/exec-phase.md +572 -0
  138. package/pan-wizard-core/workflows/execute-plan.md +448 -0
  139. package/pan-wizard-core/workflows/health.md +156 -0
  140. package/pan-wizard-core/workflows/help.md +431 -0
  141. package/pan-wizard-core/workflows/insert-phase.md +129 -0
  142. package/pan-wizard-core/workflows/map-codebase.md +401 -0
  143. package/pan-wizard-core/workflows/milestone-audit.md +297 -0
  144. package/pan-wizard-core/workflows/milestone-cleanup.md +152 -0
  145. package/pan-wizard-core/workflows/milestone-gaps.md +274 -0
  146. package/pan-wizard-core/workflows/milestone-new.md +382 -0
  147. package/pan-wizard-core/workflows/new-project.md +1178 -0
  148. package/pan-wizard-core/workflows/pause.md +122 -0
  149. package/pan-wizard-core/workflows/phase-tests.md +388 -0
  150. package/pan-wizard-core/workflows/plan-phase.md +569 -0
  151. package/pan-wizard-core/workflows/profile.md +115 -0
  152. package/pan-wizard-core/workflows/progress.md +381 -0
  153. package/pan-wizard-core/workflows/quick.md +453 -0
  154. package/pan-wizard-core/workflows/remove-phase.md +154 -0
  155. package/pan-wizard-core/workflows/research-phase.md +73 -0
  156. package/pan-wizard-core/workflows/resume-project.md +306 -0
  157. package/pan-wizard-core/workflows/retro.md +121 -0
  158. package/pan-wizard-core/workflows/settings.md +213 -0
  159. package/pan-wizard-core/workflows/todo-add.md +157 -0
  160. package/pan-wizard-core/workflows/todo-check.md +176 -0
  161. package/pan-wizard-core/workflows/transition.md +544 -0
  162. package/pan-wizard-core/workflows/update.md +219 -0
  163. package/pan-wizard-core/workflows/verify-phase.md +301 -0
  164. package/scripts/build-hooks.js +43 -0
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Context Budget — Estimate context utilization and quality for current phase
3
+ *
4
+ * Reads state.md, phase plans, and config to produce a context health report.
5
+ * Makes PAN's context rot prevention visible and measurable.
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const { output, error, safeReadFile, loadConfig, findPhaseInternal, toPosix } = require('./core.cjs');
11
+ const { planningPath, phasesPath, fileAccessible } = require('./utils.cjs');
12
+ const { STATE_FILE, ROADMAP_FILE, PROJECT_FILE, isPlanFile, isSummaryFile, CHARS_PER_TOKEN, CONTEXT_WINDOW, WARNING_THRESHOLD, CRITICAL_THRESHOLD } = require('./constants.cjs');
13
+
14
+ /**
15
+ * Estimate token count from text content.
16
+ * @param {string} text - Text content
17
+ * @returns {number} Estimated token count
18
+ */
19
+ function estimateTokens(text) {
20
+ if (!text) return 0;
21
+ return Math.ceil(text.length / CHARS_PER_TOKEN);
22
+ }
23
+
24
+ /**
25
+ * Compute context budget for the current project state.
26
+ * @param {string} cwd - Project root directory
27
+ * @param {boolean} raw - If true, output human-readable string
28
+ */
29
+ function cmdContextBudget(cwd, raw) {
30
+ const planDir = planningPath(cwd);
31
+ if (!fileAccessible(planDir)) {
32
+ return output({ error: '.planning/ directory not found', hint: 'Run /pan:new-project to initialize' }, raw,
33
+ 'Error: .planning/ directory not found\nHint: Run /pan:new-project to initialize');
34
+ }
35
+
36
+ const config = loadConfig(cwd);
37
+
38
+ // Read core files and estimate tokens
39
+ const stateContent = safeReadFile(path.join(planDir, STATE_FILE));
40
+ const roadmapContent = safeReadFile(path.join(planDir, ROADMAP_FILE));
41
+ const projectContent = safeReadFile(path.join(planDir, PROJECT_FILE));
42
+
43
+ const stateTokens = estimateTokens(stateContent);
44
+ const roadmapTokens = estimateTokens(roadmapContent);
45
+ const projectTokens = estimateTokens(projectContent);
46
+
47
+ // Find current phase and estimate plan tokens
48
+ let currentPhase = null;
49
+ let planTokens = 0;
50
+ let planCount = 0;
51
+ let incompletePlanCount = 0;
52
+ let phaseDir = null;
53
+
54
+ if (stateContent) {
55
+ const phaseMatch = stateContent.match(/\*\*Current Phase:\*\*\s*(\S+)/);
56
+ if (phaseMatch) {
57
+ currentPhase = phaseMatch[1];
58
+ const phaseInfo = findPhaseInternal(cwd, currentPhase);
59
+ if (phaseInfo && phaseInfo.found) {
60
+ phaseDir = phaseInfo.directory;
61
+ planCount = phaseInfo.plans.length;
62
+ incompletePlanCount = phaseInfo.incomplete_plans.length;
63
+
64
+ // Estimate plan tokens
65
+ const fullPhasePath = path.join(cwd, phaseInfo.directory);
66
+ for (const planFile of phaseInfo.plans) {
67
+ const planContent = safeReadFile(path.join(fullPhasePath, planFile));
68
+ planTokens += estimateTokens(planContent);
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ // Calculate totals
75
+ const contextTokens = stateTokens + roadmapTokens + projectTokens;
76
+ const totalTokens = contextTokens + planTokens;
77
+ const utilization = totalTokens / CONTEXT_WINDOW;
78
+
79
+ // Determine status
80
+ let status = 'healthy';
81
+ if (!currentPhase) {
82
+ status = 'idle';
83
+ } else if (utilization >= CRITICAL_THRESHOLD) {
84
+ status = 'critical';
85
+ } else if (utilization >= WARNING_THRESHOLD) {
86
+ status = 'warning';
87
+ }
88
+
89
+ // Generate recommendation
90
+ let recommendation;
91
+ if (status === 'idle') {
92
+ recommendation = 'No active phase. Run /pan:plan-phase to start.';
93
+ } else if (status === 'critical') {
94
+ recommendation = 'Context budget near limit. Consider splitting this phase into smaller phases.';
95
+ } else if (status === 'warning') {
96
+ recommendation = 'Context usage is elevated. Monitor quality during execution.';
97
+ } else {
98
+ const remainingTokens = CONTEXT_WINDOW - totalTokens;
99
+ const avgPlanTokens = planCount > 0 ? Math.ceil(planTokens / planCount) : 5000;
100
+ const additionalPlans = avgPlanTokens > 0 ? Math.floor(remainingTokens / avgPlanTokens) : 0;
101
+ recommendation = `Within budget. ~${additionalPlans} more plans could fit before degradation.`;
102
+ }
103
+
104
+ const result = {
105
+ status,
106
+ currentPhase: currentPhase || null,
107
+ phaseDirectory: phaseDir ? toPosix(phaseDir) : null,
108
+ plans: planCount,
109
+ incompletePlans: incompletePlanCount,
110
+ modelProfile: config.model_profile,
111
+ tokens: {
112
+ project: projectTokens,
113
+ roadmap: roadmapTokens,
114
+ state: stateTokens,
115
+ plans: planTokens,
116
+ total: totalTokens,
117
+ },
118
+ contextWindow: CONTEXT_WINDOW,
119
+ budgetUtilization: Math.round(utilization * 1000) / 1000,
120
+ recommendation,
121
+ };
122
+
123
+ if (raw) {
124
+ const lines = [
125
+ `Context Budget: ${status.toUpperCase()}`,
126
+ ``,
127
+ `Current Phase: ${currentPhase || 'none'}`,
128
+ `Model Profile: ${config.model_profile}`,
129
+ `Plans: ${planCount} total, ${incompletePlanCount} incomplete`,
130
+ ``,
131
+ `Token Estimates:`,
132
+ ` project.md: ${projectTokens.toLocaleString()}`,
133
+ ` roadmap.md: ${roadmapTokens.toLocaleString()}`,
134
+ ` state.md: ${stateTokens.toLocaleString()}`,
135
+ ` Phase Plans: ${planTokens.toLocaleString()}`,
136
+ ` Total: ${totalTokens.toLocaleString()} / ${CONTEXT_WINDOW.toLocaleString()}`,
137
+ ``,
138
+ `Utilization: ${(utilization * 100).toFixed(1)}%`,
139
+ `${recommendation}`,
140
+ ];
141
+ return output(result, true, lines.join('\n'));
142
+ }
143
+
144
+ return output(result, false);
145
+ }
146
+
147
+ module.exports = {
148
+ cmdContextBudget,
149
+ estimateTokens,
150
+ };