dino-spec 13.6.1 → 14.0.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 (203) hide show
  1. package/README.md +82 -5
  2. package/dist/commands/hud.d.ts +1 -8
  3. package/dist/commands/hud.d.ts.map +1 -1
  4. package/dist/commands/hud.js +4 -18
  5. package/dist/commands/hud.js.map +1 -1
  6. package/dist/core/config/feature-flags.d.ts +25 -1
  7. package/dist/core/config/feature-flags.d.ts.map +1 -1
  8. package/dist/core/config/feature-flags.js +7 -1
  9. package/dist/core/config/feature-flags.js.map +1 -1
  10. package/dist/core/context/__tests__/budget-thresholds.test.d.ts +5 -0
  11. package/dist/core/context/__tests__/budget-thresholds.test.d.ts.map +1 -0
  12. package/dist/core/context/__tests__/budget-thresholds.test.js +223 -0
  13. package/dist/core/context/__tests__/budget-thresholds.test.js.map +1 -0
  14. package/dist/core/context/__tests__/compaction-engine.test.d.ts +5 -0
  15. package/dist/core/context/__tests__/compaction-engine.test.d.ts.map +1 -0
  16. package/dist/core/context/__tests__/compaction-engine.test.js +474 -0
  17. package/dist/core/context/__tests__/compaction-engine.test.js.map +1 -0
  18. package/dist/core/context/__tests__/output-persistence.test.d.ts +5 -0
  19. package/dist/core/context/__tests__/output-persistence.test.d.ts.map +1 -0
  20. package/dist/core/context/__tests__/output-persistence.test.js +246 -0
  21. package/dist/core/context/__tests__/output-persistence.test.js.map +1 -0
  22. package/dist/core/context/auto-injection-engine.d.ts +10 -1
  23. package/dist/core/context/auto-injection-engine.d.ts.map +1 -1
  24. package/dist/core/context/auto-injection-engine.js +45 -2
  25. package/dist/core/context/auto-injection-engine.js.map +1 -1
  26. package/dist/core/context/budget-thresholds.d.ts +167 -0
  27. package/dist/core/context/budget-thresholds.d.ts.map +1 -0
  28. package/dist/core/context/budget-thresholds.js +234 -0
  29. package/dist/core/context/budget-thresholds.js.map +1 -0
  30. package/dist/core/context/compaction-engine.d.ts +193 -0
  31. package/dist/core/context/compaction-engine.d.ts.map +1 -0
  32. package/dist/core/context/compaction-engine.js +376 -0
  33. package/dist/core/context/compaction-engine.js.map +1 -0
  34. package/dist/core/context/context-health.d.ts +27 -2
  35. package/dist/core/context/context-health.d.ts.map +1 -1
  36. package/dist/core/context/context-health.js +98 -12
  37. package/dist/core/context/context-health.js.map +1 -1
  38. package/dist/core/context/focus-resource-loader.d.ts +143 -0
  39. package/dist/core/context/focus-resource-loader.d.ts.map +1 -0
  40. package/dist/core/context/focus-resource-loader.js +305 -0
  41. package/dist/core/context/focus-resource-loader.js.map +1 -0
  42. package/dist/core/context/index.d.ts +10 -5
  43. package/dist/core/context/index.d.ts.map +1 -1
  44. package/dist/core/context/index.js +40 -5
  45. package/dist/core/context/index.js.map +1 -1
  46. package/dist/core/context/lazy-loader.d.ts +44 -1
  47. package/dist/core/context/lazy-loader.d.ts.map +1 -1
  48. package/dist/core/context/lazy-loader.js +59 -1
  49. package/dist/core/context/lazy-loader.js.map +1 -1
  50. package/dist/core/context/output-persistence.d.ts +142 -0
  51. package/dist/core/context/output-persistence.d.ts.map +1 -0
  52. package/dist/core/context/output-persistence.js +242 -0
  53. package/dist/core/context/output-persistence.js.map +1 -0
  54. package/dist/core/context-repl/__tests__/repl-environment.test.d.ts +7 -0
  55. package/dist/core/context-repl/__tests__/repl-environment.test.d.ts.map +1 -0
  56. package/dist/core/context-repl/__tests__/repl-environment.test.js +335 -0
  57. package/dist/core/context-repl/__tests__/repl-environment.test.js.map +1 -0
  58. package/dist/core/context-repl/context-window-monitor.d.ts +181 -0
  59. package/dist/core/context-repl/context-window-monitor.d.ts.map +1 -0
  60. package/dist/core/context-repl/context-window-monitor.js +309 -0
  61. package/dist/core/context-repl/context-window-monitor.js.map +1 -0
  62. package/dist/core/context-repl/index.d.ts +8 -3
  63. package/dist/core/context-repl/index.d.ts.map +1 -1
  64. package/dist/core/context-repl/index.js +11 -3
  65. package/dist/core/context-repl/index.js.map +1 -1
  66. package/dist/core/context-repl/repl-environment.d.ts +66 -0
  67. package/dist/core/context-repl/repl-environment.d.ts.map +1 -0
  68. package/dist/core/context-repl/repl-environment.js +795 -0
  69. package/dist/core/context-repl/repl-environment.js.map +1 -0
  70. package/dist/core/context-repl/types.d.ts +277 -1
  71. package/dist/core/context-repl/types.d.ts.map +1 -1
  72. package/dist/core/context-repl/types.js +52 -1
  73. package/dist/core/context-repl/types.js.map +1 -1
  74. package/dist/core/environment/__tests__/pre-verify.test.d.ts +5 -0
  75. package/dist/core/environment/__tests__/pre-verify.test.d.ts.map +1 -0
  76. package/dist/core/environment/__tests__/pre-verify.test.js +343 -0
  77. package/dist/core/environment/__tests__/pre-verify.test.js.map +1 -0
  78. package/dist/core/environment/index.d.ts +8 -0
  79. package/dist/core/environment/index.d.ts.map +1 -0
  80. package/dist/core/environment/index.js +7 -0
  81. package/dist/core/environment/index.js.map +1 -0
  82. package/dist/core/environment/pre-verify.d.ts +63 -0
  83. package/dist/core/environment/pre-verify.d.ts.map +1 -0
  84. package/dist/core/environment/pre-verify.js +221 -0
  85. package/dist/core/environment/pre-verify.js.map +1 -0
  86. package/dist/core/environment/types.d.ts +37 -0
  87. package/dist/core/environment/types.d.ts.map +1 -0
  88. package/dist/core/environment/types.js +5 -0
  89. package/dist/core/environment/types.js.map +1 -0
  90. package/dist/core/generator/claude-md.js +1 -1
  91. package/dist/core/intelligence/context-budget.d.ts +10 -5
  92. package/dist/core/intelligence/context-budget.d.ts.map +1 -1
  93. package/dist/core/intelligence/context-budget.js +12 -5
  94. package/dist/core/intelligence/context-budget.js.map +1 -1
  95. package/dist/core/provider/storage.d.ts.map +1 -1
  96. package/dist/core/provider/storage.js +1 -2
  97. package/dist/core/provider/storage.js.map +1 -1
  98. package/dist/hooks/post-edit.js +73 -0
  99. package/dist/hooks/post-edit.js.map +1 -1
  100. package/dist/hooks/session-start.js +115 -0
  101. package/dist/hooks/session-start.js.map +1 -1
  102. package/dist/hooks/types.js +1 -1
  103. package/dist/hooks/user-prompt-submit.js +100 -0
  104. package/dist/hooks/user-prompt-submit.js.map +1 -1
  105. package/dist/hud/config.d.ts +3 -28
  106. package/dist/hud/config.d.ts.map +1 -1
  107. package/dist/hud/config.js +8 -60
  108. package/dist/hud/config.js.map +1 -1
  109. package/dist/hud/index.d.ts.map +1 -1
  110. package/dist/hud/index.js +0 -1
  111. package/dist/hud/index.js.map +1 -1
  112. package/dist/hud/render/budget-bar.d.ts +0 -2
  113. package/dist/hud/render/budget-bar.d.ts.map +1 -1
  114. package/dist/hud/render/budget-bar.js +5 -8
  115. package/dist/hud/render/budget-bar.js.map +1 -1
  116. package/dist/hud/stdin.d.ts +0 -3
  117. package/dist/hud/stdin.d.ts.map +1 -1
  118. package/dist/hud/stdin.js +2 -29
  119. package/dist/hud/stdin.js.map +1 -1
  120. package/dist/hud/types.d.ts +0 -2
  121. package/dist/hud/types.d.ts.map +1 -1
  122. package/dist/mcp/__tests__/dynamic-updates.test.d.ts +5 -0
  123. package/dist/mcp/__tests__/dynamic-updates.test.d.ts.map +1 -0
  124. package/dist/mcp/__tests__/dynamic-updates.test.js +314 -0
  125. package/dist/mcp/__tests__/dynamic-updates.test.js.map +1 -0
  126. package/dist/mcp/dynamic-updates.d.ts +167 -0
  127. package/dist/mcp/dynamic-updates.d.ts.map +1 -0
  128. package/dist/mcp/dynamic-updates.js +313 -0
  129. package/dist/mcp/dynamic-updates.js.map +1 -0
  130. package/dist/mcp/focus-filter.d.ts +74 -0
  131. package/dist/mcp/focus-filter.d.ts.map +1 -0
  132. package/dist/mcp/focus-filter.js +229 -0
  133. package/dist/mcp/focus-filter.js.map +1 -0
  134. package/dist/mcp/index.d.ts +4 -2
  135. package/dist/mcp/index.d.ts.map +1 -1
  136. package/dist/mcp/index.js +5 -2
  137. package/dist/mcp/index.js.map +1 -1
  138. package/dist/mcp/registry.d.ts +4 -4
  139. package/dist/mcp/registry.d.ts.map +1 -1
  140. package/dist/mcp/registry.js +16 -16
  141. package/dist/mcp/registry.js.map +1 -1
  142. package/dist/mcp/server.d.ts +2 -1
  143. package/dist/mcp/server.d.ts.map +1 -1
  144. package/dist/mcp/server.js +12 -3
  145. package/dist/mcp/server.js.map +1 -1
  146. package/dist/mcp/tool-tiers.d.ts.map +1 -1
  147. package/dist/mcp/tool-tiers.js +5 -0
  148. package/dist/mcp/tool-tiers.js.map +1 -1
  149. package/dist/mcp/tools/__tests__/environment.test.d.ts +5 -0
  150. package/dist/mcp/tools/__tests__/environment.test.d.ts.map +1 -0
  151. package/dist/mcp/tools/__tests__/environment.test.js +219 -0
  152. package/dist/mcp/tools/__tests__/environment.test.js.map +1 -0
  153. package/dist/mcp/tools/auto-inject.d.ts +36 -0
  154. package/dist/mcp/tools/auto-inject.d.ts.map +1 -0
  155. package/dist/mcp/tools/auto-inject.js +143 -0
  156. package/dist/mcp/tools/auto-inject.js.map +1 -0
  157. package/dist/mcp/tools/auto-unload.d.ts +29 -0
  158. package/dist/mcp/tools/auto-unload.d.ts.map +1 -0
  159. package/dist/mcp/tools/auto-unload.js +151 -0
  160. package/dist/mcp/tools/auto-unload.js.map +1 -0
  161. package/dist/mcp/tools/context-repl.d.ts +48 -0
  162. package/dist/mcp/tools/context-repl.d.ts.map +1 -0
  163. package/dist/mcp/tools/context-repl.js +290 -0
  164. package/dist/mcp/tools/context-repl.js.map +1 -0
  165. package/dist/mcp/tools/environment.d.ts +27 -0
  166. package/dist/mcp/tools/environment.d.ts.map +1 -0
  167. package/dist/mcp/tools/environment.js +97 -0
  168. package/dist/mcp/tools/environment.js.map +1 -0
  169. package/dist/mcp/tools/health.d.ts +29 -0
  170. package/dist/mcp/tools/health.d.ts.map +1 -0
  171. package/dist/mcp/tools/health.js +171 -0
  172. package/dist/mcp/tools/health.js.map +1 -0
  173. package/dist/mcp/tools/index.d.ts +9 -2
  174. package/dist/mcp/tools/index.d.ts.map +1 -1
  175. package/dist/mcp/tools/index.js +37 -2
  176. package/dist/mcp/tools/index.js.map +1 -1
  177. package/dist/mcp/tools/output-persistence.d.ts +44 -0
  178. package/dist/mcp/tools/output-persistence.d.ts.map +1 -0
  179. package/dist/mcp/tools/output-persistence.js +208 -0
  180. package/dist/mcp/tools/output-persistence.js.map +1 -0
  181. package/dist/mcp-server.d.ts +2 -1
  182. package/dist/mcp-server.d.ts.map +1 -1
  183. package/dist/mcp-server.js +36 -7
  184. package/dist/mcp-server.js.map +1 -1
  185. package/dist/rules/index.js +2 -2
  186. package/dist/utils/exec.js +2 -2
  187. package/dist/utils/exec.js.map +1 -1
  188. package/dist/utils/gitignore.d.ts.map +1 -1
  189. package/dist/utils/gitignore.js +5 -0
  190. package/dist/utils/gitignore.js.map +1 -1
  191. package/package.json +76 -77
  192. package/dist/hud/config-tui.d.ts +0 -25
  193. package/dist/hud/config-tui.d.ts.map +0 -1
  194. package/dist/hud/config-tui.js +0 -199
  195. package/dist/hud/config-tui.js.map +0 -1
  196. package/dist/hud/models.d.ts +0 -58
  197. package/dist/hud/models.d.ts.map +0 -1
  198. package/dist/hud/models.js +0 -124
  199. package/dist/hud/models.js.map +0 -1
  200. package/dist/hud/token-estimator.d.ts +0 -79
  201. package/dist/hud/token-estimator.d.ts.map +0 -1
  202. package/dist/hud/token-estimator.js +0 -126
  203. package/dist/hud/token-estimator.js.map +0 -1
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Budget Thresholds - v14.0.0
3
+ *
4
+ * Configurable context budget thresholds with safety margins.
5
+ * Optimized for Claude 4.5's extended context window (200K tokens).
6
+ *
7
+ * Key improvements over v13.x:
8
+ * - Raised thresholds from 80/90/95% to 85/95/98%
9
+ * - Safety margin calculation for reliable headroom
10
+ * - Config-driven thresholds via .dino/config.json
11
+ * - Backwards compatible with existing budget tracking
12
+ *
13
+ * Reference: Anthropic context engineering best practices
14
+ */
15
+ import { loadConfig } from '../config/feature-flags.js';
16
+ /**
17
+ * Default budget thresholds (v14.0.0)
18
+ *
19
+ * These thresholds are optimized for safe context utilization
20
+ * while maximizing available token budget.
21
+ */
22
+ export const OPTIMIZED_BUDGET_THRESHOLDS = {
23
+ /** Start monitoring - context filling up */
24
+ WARNING: 0.85, // was 0.80
25
+ /** High usage - recommend compaction */
26
+ HIGH: 0.95, // was 0.90
27
+ /** Critical - force compaction recommendation */
28
+ CRITICAL: 0.98, // was 0.95
29
+ };
30
+ /**
31
+ * Legacy thresholds for backwards compatibility
32
+ */
33
+ export const LEGACY_BUDGET_THRESHOLDS = {
34
+ WARNING: 0.80,
35
+ HIGH: 0.90,
36
+ CRITICAL: 0.95,
37
+ };
38
+ /**
39
+ * Default safety margin in tokens
40
+ *
41
+ * Reserved buffer to prevent context overflow.
42
+ * Provides headroom for system messages and unexpected content.
43
+ */
44
+ export const DEFAULT_SAFETY_MARGIN = 2000;
45
+ /**
46
+ * Default threshold configuration
47
+ */
48
+ export const DEFAULT_THRESHOLD_CONFIG = {
49
+ warning: OPTIMIZED_BUDGET_THRESHOLDS.WARNING,
50
+ high: OPTIMIZED_BUDGET_THRESHOLDS.HIGH,
51
+ critical: OPTIMIZED_BUDGET_THRESHOLDS.CRITICAL,
52
+ safetyMargin: DEFAULT_SAFETY_MARGIN,
53
+ };
54
+ /**
55
+ * Get threshold level from usage percentage
56
+ *
57
+ * @param usage - Current token usage
58
+ * @param limit - Context limit in tokens
59
+ * @param config - Threshold configuration (optional)
60
+ * @returns ThresholdLevel
61
+ */
62
+ export function getThresholdLevel(usage, limit, config = DEFAULT_THRESHOLD_CONFIG) {
63
+ const percentage = usage / limit;
64
+ if (percentage >= config.critical) {
65
+ return 'critical';
66
+ }
67
+ if (percentage >= config.high) {
68
+ return 'high';
69
+ }
70
+ if (percentage >= config.warning) {
71
+ return 'warning';
72
+ }
73
+ return 'safe';
74
+ }
75
+ /**
76
+ * Calculate threshold result with safety margin
77
+ *
78
+ * @param usage - Current token usage
79
+ * @param limit - Context limit in tokens
80
+ * @param config - Threshold configuration (optional)
81
+ * @returns ThresholdResult with remaining capacity
82
+ */
83
+ export function calculateThresholdResult(usage, limit, config = DEFAULT_THRESHOLD_CONFIG) {
84
+ const level = getThresholdLevel(usage, limit, config);
85
+ const remaining = Math.max(0, limit - usage);
86
+ const safeRemaining = Math.max(0, remaining - config.safetyMargin);
87
+ const percentage = Math.round((usage / limit) * 100);
88
+ return {
89
+ level,
90
+ remaining,
91
+ safeRemaining,
92
+ percentage,
93
+ shouldCompact: level === 'high' || level === 'critical',
94
+ forceCompact: level === 'critical',
95
+ };
96
+ }
97
+ /**
98
+ * Load threshold configuration from config.json
99
+ *
100
+ * Configuration can be customized via .dino/config.json:
101
+ * ```json
102
+ * {
103
+ * "custom": {
104
+ * "budgetThresholds": {
105
+ * "warning": 0.85,
106
+ * "high": 0.95,
107
+ * "critical": 0.98,
108
+ * "safetyMargin": 2000
109
+ * }
110
+ * }
111
+ * }
112
+ * ```
113
+ *
114
+ * Falls back to optimized thresholds if not configured.
115
+ *
116
+ * @param projectDir - Project directory
117
+ * @returns ThresholdConfig
118
+ */
119
+ export async function loadThresholdConfig(projectDir = process.cwd()) {
120
+ try {
121
+ const config = await loadConfig(projectDir);
122
+ const customThresholds = config.custom?.budgetThresholds;
123
+ if (customThresholds) {
124
+ return {
125
+ warning: customThresholds.warning ?? DEFAULT_THRESHOLD_CONFIG.warning,
126
+ high: customThresholds.high ?? DEFAULT_THRESHOLD_CONFIG.high,
127
+ critical: customThresholds.critical ?? DEFAULT_THRESHOLD_CONFIG.critical,
128
+ safetyMargin: customThresholds.safetyMargin ?? DEFAULT_THRESHOLD_CONFIG.safetyMargin,
129
+ };
130
+ }
131
+ }
132
+ catch {
133
+ // Fall back to defaults on any error
134
+ }
135
+ return DEFAULT_THRESHOLD_CONFIG;
136
+ }
137
+ /**
138
+ * Check if using legacy thresholds
139
+ *
140
+ * Returns true if config has legacy threshold values.
141
+ * Useful for migration warnings.
142
+ *
143
+ * @param config - Threshold configuration
144
+ * @returns boolean
145
+ */
146
+ export function isLegacyThresholds(config) {
147
+ return (config.warning === LEGACY_BUDGET_THRESHOLDS.WARNING &&
148
+ config.high === LEGACY_BUDGET_THRESHOLDS.HIGH &&
149
+ config.critical === LEGACY_BUDGET_THRESHOLDS.CRITICAL);
150
+ }
151
+ /**
152
+ * Get recommendations for threshold level
153
+ *
154
+ * @param level - Current threshold level
155
+ * @returns Array of recommended actions
156
+ */
157
+ export function getThresholdRecommendations(level) {
158
+ switch (level) {
159
+ case 'critical':
160
+ return [
161
+ 'CRITICAL: Context at 98%+. Immediate compaction required.',
162
+ 'Run: dino compact --force',
163
+ 'Or start a new conversation with /dino.handoff',
164
+ 'Consider using /dino.fossil to archive completed work.',
165
+ ];
166
+ case 'high':
167
+ return [
168
+ 'HIGH: Context at 95%+. Compaction recommended.',
169
+ 'Run: dino compact',
170
+ 'Avoid loading large files. Use targeted searches.',
171
+ 'Checkpoint progress for potential handoff.',
172
+ ];
173
+ case 'warning':
174
+ return [
175
+ 'WARNING: Context at 85%+. Monitor usage.',
176
+ 'Prefer grep/glob over full file reads.',
177
+ 'Consider deferring non-essential file reads.',
178
+ ];
179
+ case 'safe':
180
+ default:
181
+ return [];
182
+ }
183
+ }
184
+ /**
185
+ * Format threshold result for display
186
+ *
187
+ * @param result - Threshold result
188
+ * @returns Formatted string
189
+ */
190
+ export function formatThresholdResult(result) {
191
+ const indicator = result.level === 'critical' ? '[!!!]'
192
+ : result.level === 'high' ? '[!!]'
193
+ : result.level === 'warning' ? '[!]'
194
+ : '[OK]';
195
+ const lines = [];
196
+ lines.push(`## Budget Status ${indicator}`);
197
+ lines.push('');
198
+ lines.push(`**Level:** ${result.level.toUpperCase()} (${result.percentage}% used)`);
199
+ lines.push(`**Remaining:** ${Math.round(result.remaining / 1000)}K tokens`);
200
+ lines.push(`**Safe Remaining:** ${Math.round(result.safeRemaining / 1000)}K tokens`);
201
+ const recommendations = getThresholdRecommendations(result.level);
202
+ if (recommendations.length > 0) {
203
+ lines.push('');
204
+ lines.push('### Recommendations:');
205
+ recommendations.forEach((rec) => lines.push(`- ${rec}`));
206
+ }
207
+ return lines.join('\n');
208
+ }
209
+ /**
210
+ * Calculate safe capacity at a threshold
211
+ *
212
+ * Returns the amount of tokens that can be safely used
213
+ * before hitting the specified threshold.
214
+ *
215
+ * @param limit - Context limit in tokens
216
+ * @param threshold - Threshold percentage (0-1)
217
+ * @param safetyMargin - Safety margin in tokens
218
+ * @returns Safe capacity in tokens
219
+ */
220
+ export function calculateSafeCapacity(limit, threshold, safetyMargin = DEFAULT_SAFETY_MARGIN) {
221
+ return Math.max(0, Math.floor(limit * threshold) - safetyMargin);
222
+ }
223
+ /**
224
+ * Get effective limit accounting for safety margin
225
+ *
226
+ * @param limit - Context limit in tokens
227
+ * @param config - Threshold configuration
228
+ * @returns Effective limit with safety margin applied
229
+ */
230
+ export function getEffectiveLimit(limit, config = DEFAULT_THRESHOLD_CONFIG) {
231
+ // Use high threshold as the practical limit
232
+ return calculateSafeCapacity(limit, config.high, config.safetyMargin);
233
+ }
234
+ //# sourceMappingURL=budget-thresholds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budget-thresholds.js","sourceRoot":"","sources":["../../../src/core/context/budget-thresholds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,4CAA4C;IAC5C,OAAO,EAAE,IAAI,EAAE,WAAW;IAC1B,wCAAwC;IACxC,IAAI,EAAE,IAAI,EAAE,WAAW;IACvB,iDAAiD;IACjD,QAAQ,EAAE,IAAI,EAAE,WAAW;CACnB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,IAAI;CACN,CAAC;AAEX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAuC1C;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,OAAO,EA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,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,SAAiB,EACjB,eAAuB,qBAAqB;IAE5C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,YAAY,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,SAA0B,wBAAwB;IAElD,4CAA4C;IAC5C,OAAO,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Auto Compaction Engine - v14.0.0
3
+ *
4
+ * Automatic context compaction that triggers when context usage
5
+ * exceeds configurable thresholds. Extracts decisions, blockers,
6
+ * and progress to structured format for persistence.
7
+ *
8
+ * Features:
9
+ * - Configurable auto-compact threshold (default: 75%)
10
+ * - Integration with ContextBudgetTracker
11
+ * - Structured JSON output preserving decisions/learnings
12
+ * - CLI command support: dino compact --auto
13
+ *
14
+ * Reference: Anthropic context engineering best practices
15
+ */
16
+ import { type CompactionResult, type SessionSection } from '../intelligence/session-compactor.js';
17
+ /**
18
+ * Decision extracted from session
19
+ */
20
+ export interface ExtractedDecision {
21
+ /** Decision text */
22
+ text: string;
23
+ /** Topic/area the decision relates to */
24
+ topic: string;
25
+ /** What was chosen */
26
+ choice: string;
27
+ /** Why it was chosen */
28
+ rationale?: string;
29
+ /** When the decision was made */
30
+ timestamp?: string;
31
+ /** Type of decision */
32
+ type: 'decision' | 'choice' | 'approach';
33
+ }
34
+ /**
35
+ * Blocker extracted from session
36
+ */
37
+ export interface ExtractedBlocker {
38
+ /** Blocker text */
39
+ text: string;
40
+ /** When the blocker was added */
41
+ addedAt?: string;
42
+ /** Current status */
43
+ status: 'active' | 'resolved';
44
+ }
45
+ /**
46
+ * Progress entry extracted from session
47
+ */
48
+ export interface ExtractedProgress {
49
+ /** Progress signal text */
50
+ text: string;
51
+ /** Signal type */
52
+ type: string;
53
+ /** When it occurred */
54
+ timestamp: string;
55
+ }
56
+ /**
57
+ * Structured compaction output
58
+ */
59
+ export interface StructuredCompaction {
60
+ /** Extracted decisions */
61
+ decisions: ExtractedDecision[];
62
+ /** Extracted blockers */
63
+ blockers: ExtractedBlocker[];
64
+ /** Extracted progress signals */
65
+ progress: ExtractedProgress[];
66
+ /** When compaction occurred */
67
+ timestamp: string;
68
+ /** Session identifier */
69
+ sessionId: string;
70
+ /** Original token count */
71
+ originalTokens: number;
72
+ /** Tokens recovered by compaction */
73
+ tokensRecovered: number;
74
+ }
75
+ /**
76
+ * Compaction engine result
77
+ */
78
+ export interface CompactionEngineResult {
79
+ /** Whether compaction was triggered */
80
+ triggered: boolean;
81
+ /** Whether compaction was executed */
82
+ executed: boolean;
83
+ /** Reason for trigger or skip */
84
+ reason: string;
85
+ /** Structured compaction data (if executed) */
86
+ structuredOutput?: StructuredCompaction;
87
+ /** Compaction result from session-compactor (if executed) */
88
+ compactionResult?: CompactionResult;
89
+ /** Output file path (if persisted) */
90
+ outputPath?: string;
91
+ /** Current context usage percentage */
92
+ usagePercent: number;
93
+ /** Current token count */
94
+ currentTokens: number;
95
+ /** Effective limit */
96
+ limit: number;
97
+ }
98
+ /**
99
+ * Compaction engine options
100
+ */
101
+ export interface CompactionEngineOptions {
102
+ /** Threshold for auto-compaction (0-1, default: 0.75) */
103
+ threshold?: number;
104
+ /** Token limit to use */
105
+ limit?: number;
106
+ /** Force compaction regardless of threshold */
107
+ force?: boolean;
108
+ /** Project directory */
109
+ projectDir?: string;
110
+ /** Whether to persist structured output */
111
+ persistOutput?: boolean;
112
+ /** Custom session ID */
113
+ sessionId?: string;
114
+ /** Skip actual compaction (dry run) */
115
+ dryRun?: boolean;
116
+ }
117
+ /**
118
+ * Default auto-compact threshold (75%)
119
+ * Lower than warning threshold to provide headroom
120
+ */
121
+ export declare const AUTO_COMPACT_THRESHOLD = 0.75;
122
+ /**
123
+ * Directory for compacted outputs
124
+ */
125
+ export declare const COMPACT_OUTPUT_DIR = ".dino/compacted";
126
+ /**
127
+ * Feature flag for auto-compaction
128
+ */
129
+ export declare const AUTO_COMPACT_FEATURE_FLAG = "enableAutoCompaction";
130
+ /**
131
+ * Check if auto-compaction should trigger
132
+ *
133
+ * @param currentTokens Current token count
134
+ * @param limit Token limit
135
+ * @param threshold Threshold percentage (0-1)
136
+ * @returns Whether compaction should trigger
137
+ */
138
+ export declare function shouldAutoCompact(currentTokens: number, limit?: number, threshold?: number): boolean;
139
+ /**
140
+ * Calculate usage percentage
141
+ */
142
+ export declare function getUsagePercent(currentTokens: number, limit: number): number;
143
+ /**
144
+ * Extract structured decisions from session sections
145
+ */
146
+ export declare function extractDecisions(sections: SessionSection[]): ExtractedDecision[];
147
+ /**
148
+ * Extract structured blockers from session sections
149
+ */
150
+ export declare function extractBlockers(sections: SessionSection[]): ExtractedBlocker[];
151
+ /**
152
+ * Extract structured progress from session sections
153
+ */
154
+ export declare function extractProgress(sections: SessionSection[]): ExtractedProgress[];
155
+ /**
156
+ * Generate session ID from timestamp
157
+ */
158
+ export declare function generateSessionId(): string;
159
+ /**
160
+ * Create structured compaction output
161
+ */
162
+ export declare function createStructuredCompaction(sections: SessionSection[], originalTokens: number, tokensRecovered: number, sessionId?: string): StructuredCompaction;
163
+ /**
164
+ * Persist structured compaction to disk
165
+ */
166
+ export declare function persistStructuredCompaction(compaction: StructuredCompaction, projectDir?: string): Promise<string>;
167
+ /**
168
+ * List persisted compactions
169
+ */
170
+ export declare function listCompactions(projectDir?: string): Promise<StructuredCompaction[]>;
171
+ /**
172
+ * Run auto-compaction engine
173
+ *
174
+ * This is the main entry point for the compaction engine.
175
+ * It checks if compaction should trigger based on current context usage
176
+ * and executes compaction with structured output if needed.
177
+ */
178
+ export declare function runAutoCompaction(options?: CompactionEngineOptions): Promise<CompactionEngineResult>;
179
+ /**
180
+ * Format compaction engine result for display
181
+ */
182
+ export declare function formatCompactionEngineResult(result: CompactionEngineResult): string;
183
+ /**
184
+ * Get compaction engine statistics
185
+ */
186
+ export declare function getCompactionEngineStats(projectDir?: string): Promise<{
187
+ compactionCount: number;
188
+ totalTokensRecovered: number;
189
+ totalDecisionsExtracted: number;
190
+ totalBlockersExtracted: number;
191
+ latestCompaction: string | null;
192
+ }>;
193
+ //# sourceMappingURL=compaction-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-engine.d.ts","sourceRoot":"","sources":["../../../src/core/context/compaction-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAOL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,sCAAsC,CAAC;AAU9C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,IAAI,EAAE,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B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