dsh-context-compression-improved 0.8.0-beta.3 → 0.8.0-beta.4
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/CHANGELOG.md +7 -0
- package/eslint.config.js +30 -30
- package/package.json +163 -163
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +6 -0
- package/packages/selector/lib/client.js +106 -7
- package/packages/selector/lib/index.js +92 -1
- package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
- package/packages/selector/lib/profiles.d.ts +9 -0
- package/packages/selector/lib/pruner.d.ts +59 -0
- package/packages/selector/lib/pruner.js +408 -5
- package/packages/selector/src/client/CompressionProfileControls.tsx +34 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +1 -0
- package/packages/selector/src/client/decode.ts +53 -49
- package/packages/selector/src/client/index.ts +4 -0
- package/packages/selector/src/client/locales/de.ts +5 -0
- package/packages/selector/src/client/locales/es.ts +5 -0
- package/packages/selector/src/client/locales/fr.ts +5 -0
- package/packages/selector/src/client/locales/it.ts +5 -0
- package/packages/selector/src/client/locales/ja.ts +5 -0
- package/packages/selector/src/client/locales/ko.ts +5 -0
- package/packages/selector/src/client/locales/ru.ts +5 -0
- package/packages/selector/src/client/locales.ts +10 -0
- package/packages/selector/src/client/settings-section.tsx +9 -2
- package/packages/selector/src/index.ts +7 -0
- package/packages/selector/src/profiles.ts +414 -394
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner.ts +241 -1
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +731 -706
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/types.ts +358 -346
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -252
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2734 -2731
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +1 -1
- package/scripts/packed-install-e2e.mjs +1 -1
- package/scripts/verify-release.mjs +2 -1
|
@@ -1,346 +1,358 @@
|
|
|
1
|
-
import type { ToolCallId as CallId } from '@deepseek-ai/dsh-llm'
|
|
2
|
-
|
|
3
|
-
/** User-facing mixed strategy profile. */
|
|
4
|
-
export const COMPRESSION_PROFILES = [
|
|
5
|
-
'off',
|
|
6
|
-
'native',
|
|
7
|
-
'balanced',
|
|
8
|
-
'cache-strict',
|
|
9
|
-
'savings',
|
|
10
|
-
'adaptive',
|
|
11
|
-
'tokenpilot-inspired',
|
|
12
|
-
'custom',
|
|
13
|
-
] as const
|
|
14
|
-
|
|
15
|
-
/** Public compression strategy selected for one Session. */
|
|
16
|
-
export type CompressionProfile = typeof COMPRESSION_PROFILES[number]
|
|
17
|
-
|
|
18
|
-
/** When historical tool results may be aged for one Session policy. */
|
|
19
|
-
export type HistoryMode = 'disabled' | 'routine' | 'capacity-pressure' | 'adaptive'
|
|
20
|
-
|
|
21
|
-
/** Canonical unit stored by one versioned Custom policy. */
|
|
22
|
-
export type CustomCompressionUnit = 'tokens' | 'context-percent'
|
|
23
|
-
|
|
24
|
-
/** Whether routine History may rewrite a previously sent Harness prefix. */
|
|
25
|
-
export type CustomPrefixPolicy = 'preserve' | 'pressure-break'
|
|
26
|
-
|
|
27
|
-
/** One independently selectable Custom Fresh or Aggregate stage. */
|
|
28
|
-
export interface CustomCompressionBudget {
|
|
29
|
-
enabled: boolean
|
|
30
|
-
trigger: number
|
|
31
|
-
target: number
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Legacy Custom History gate and turn/token working-set protection. */
|
|
35
|
-
export interface LegacyCustomHistoryPolicy {
|
|
36
|
-
enabled: boolean
|
|
37
|
-
trigger: number
|
|
38
|
-
keepRecentTurns: number
|
|
39
|
-
keepRecent: number
|
|
40
|
-
minReclaim: number
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Custom History gate and recent tool-call/token working-set protection. */
|
|
44
|
-
export interface CustomHistoryPolicy {
|
|
45
|
-
enabled: boolean
|
|
46
|
-
trigger: number
|
|
47
|
-
keepRecentToolCalls: number
|
|
48
|
-
keepRecentTokens: number
|
|
49
|
-
minReclaim: number
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Custom-only experimental TailTrim gate. */
|
|
53
|
-
export interface CustomTailTrimPolicy {
|
|
54
|
-
enabled: boolean
|
|
55
|
-
trigger: number
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** TokenPilot-inspired preset sub-capability switches (only injected for `tokenpilot-inspired`). */
|
|
59
|
-
export interface PresetOptions {
|
|
60
|
-
/** Reject replacements whose text is not smaller than the original (G1). */
|
|
61
|
-
readonly noNetSavingsGuard: boolean
|
|
62
|
-
/** Permanently exempt recovery content from further reduction (G2). */
|
|
63
|
-
readonly skipReductionRecovery: boolean
|
|
64
|
-
/** Replace byte-identical repeated tool results with first-occurrence pointers (A1). */
|
|
65
|
-
readonly dedupeToolResults: boolean
|
|
66
|
-
/** Append Exact Sources locator blocks after Auto Compact completes (A2). */
|
|
67
|
-
readonly summaryLocator: boolean
|
|
68
|
-
/** Volatile-line demotion, deterministic tool ordering, and prefix fingerprint audit (S1/S2). */
|
|
69
|
-
readonly prefixStabilizer: boolean
|
|
70
|
-
/** Fresh/superseded read-state classification with clustered omission markers (R2/R3). */
|
|
71
|
-
readonly readState: boolean
|
|
72
|
-
/** Optional estimator channel; `''` keeps every estimator consumer on rule-only fallbacks (E1/E2). */
|
|
73
|
-
readonly estimator: { readonly mode: '' | 'host' | 'direct' }
|
|
74
|
-
/**
|
|
75
|
-
* Advisory relevance advisor: statistics and suggestions only — every output
|
|
76
|
-
* (summaries, scores, decay, recertification) is observational and must never
|
|
77
|
-
* suppress, delay, or rewrite any reduction that would land. `''` (the
|
|
78
|
-
* default) keeps the advisor fully off.
|
|
79
|
-
*/
|
|
80
|
-
readonly advisor: {
|
|
81
|
-
readonly mode: '' | 'host' | 'direct'
|
|
82
|
-
readonly timeoutMs: number
|
|
83
|
-
readonly refreshTurns: number
|
|
84
|
-
readonly scoreThreshold: number
|
|
85
|
-
readonly sampleLimit: number
|
|
86
|
-
readonly minTokens: number
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Common user-authored Custom stages shared by persisted policy versions. */
|
|
91
|
-
interface CustomCompressionPolicyFields<HistoryPolicy> {
|
|
92
|
-
unit: CustomCompressionUnit
|
|
93
|
-
fresh: CustomCompressionBudget
|
|
94
|
-
aggregate: CustomCompressionBudget
|
|
95
|
-
history: HistoryPolicy
|
|
96
|
-
prefixPolicy: CustomPrefixPolicy
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Legacy R4 Custom policy, accepted without migration. */
|
|
100
|
-
export interface CustomCompressionPolicyV1 extends CustomCompressionPolicyFields<LegacyCustomHistoryPolicy> {
|
|
101
|
-
version: 1
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** R5 Custom policy with an explicit default-off TailTrim stage. */
|
|
105
|
-
export interface CustomCompressionPolicyV2 extends CustomCompressionPolicyFields<LegacyCustomHistoryPolicy> {
|
|
106
|
-
version: 2
|
|
107
|
-
tailTrim: CustomTailTrimPolicy
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Custom policy with tool-call working-set protection. */
|
|
111
|
-
export interface CustomCompressionPolicyV3 extends CustomCompressionPolicyFields<CustomHistoryPolicy> {
|
|
112
|
-
version: 3
|
|
113
|
-
tailTrim: CustomTailTrimPolicy
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Strict persisted Custom policy union. */
|
|
117
|
-
export type CustomCompressionPolicy = CustomCompressionPolicyV1 | CustomCompressionPolicyV2 | CustomCompressionPolicyV3
|
|
118
|
-
|
|
119
|
-
/** User-tunable Auto Compact coordination preferences. */
|
|
120
|
-
export interface AutoCompactSettings {
|
|
121
|
-
/** Routed-context percentage that triggers model-driven Auto Compact. */
|
|
122
|
-
thresholdPercent: number
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Orthogonal evidence-based code-skeleton reducer gate. Independent of every
|
|
127
|
-
* profile: when enabled, fresh oversized source-code results may take the
|
|
128
|
-
* `hypa-code-skeleton` reducer before the head/tail fallbacks.
|
|
129
|
-
*/
|
|
130
|
-
export interface CodeSkeletonSettings {
|
|
131
|
-
enabled: boolean
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
readonly
|
|
151
|
-
readonly
|
|
152
|
-
readonly
|
|
153
|
-
readonly
|
|
154
|
-
readonly
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
readonly
|
|
161
|
-
readonly
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
readonly
|
|
240
|
-
|
|
241
|
-
readonly
|
|
242
|
-
readonly
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
readonly
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
readonly
|
|
255
|
-
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*/
|
|
260
|
-
readonly
|
|
261
|
-
/**
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
readonly
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
readonly
|
|
288
|
-
|
|
289
|
-
readonly
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
readonly
|
|
295
|
-
|
|
296
|
-
readonly
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
export interface
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
readonly
|
|
330
|
-
/**
|
|
331
|
-
readonly
|
|
332
|
-
/**
|
|
333
|
-
readonly
|
|
334
|
-
/**
|
|
335
|
-
readonly
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
readonly
|
|
342
|
-
/**
|
|
343
|
-
readonly
|
|
344
|
-
/** Authoritative exact canonical content tokens
|
|
345
|
-
readonly
|
|
346
|
-
|
|
1
|
+
import type { ToolCallId as CallId } from '@deepseek-ai/dsh-llm'
|
|
2
|
+
|
|
3
|
+
/** User-facing mixed strategy profile. */
|
|
4
|
+
export const COMPRESSION_PROFILES = [
|
|
5
|
+
'off',
|
|
6
|
+
'native',
|
|
7
|
+
'balanced',
|
|
8
|
+
'cache-strict',
|
|
9
|
+
'savings',
|
|
10
|
+
'adaptive',
|
|
11
|
+
'tokenpilot-inspired',
|
|
12
|
+
'custom',
|
|
13
|
+
] as const
|
|
14
|
+
|
|
15
|
+
/** Public compression strategy selected for one Session. */
|
|
16
|
+
export type CompressionProfile = typeof COMPRESSION_PROFILES[number]
|
|
17
|
+
|
|
18
|
+
/** When historical tool results may be aged for one Session policy. */
|
|
19
|
+
export type HistoryMode = 'disabled' | 'routine' | 'capacity-pressure' | 'adaptive'
|
|
20
|
+
|
|
21
|
+
/** Canonical unit stored by one versioned Custom policy. */
|
|
22
|
+
export type CustomCompressionUnit = 'tokens' | 'context-percent'
|
|
23
|
+
|
|
24
|
+
/** Whether routine History may rewrite a previously sent Harness prefix. */
|
|
25
|
+
export type CustomPrefixPolicy = 'preserve' | 'pressure-break'
|
|
26
|
+
|
|
27
|
+
/** One independently selectable Custom Fresh or Aggregate stage. */
|
|
28
|
+
export interface CustomCompressionBudget {
|
|
29
|
+
enabled: boolean
|
|
30
|
+
trigger: number
|
|
31
|
+
target: number
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Legacy Custom History gate and turn/token working-set protection. */
|
|
35
|
+
export interface LegacyCustomHistoryPolicy {
|
|
36
|
+
enabled: boolean
|
|
37
|
+
trigger: number
|
|
38
|
+
keepRecentTurns: number
|
|
39
|
+
keepRecent: number
|
|
40
|
+
minReclaim: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Custom History gate and recent tool-call/token working-set protection. */
|
|
44
|
+
export interface CustomHistoryPolicy {
|
|
45
|
+
enabled: boolean
|
|
46
|
+
trigger: number
|
|
47
|
+
keepRecentToolCalls: number
|
|
48
|
+
keepRecentTokens: number
|
|
49
|
+
minReclaim: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Custom-only experimental TailTrim gate. */
|
|
53
|
+
export interface CustomTailTrimPolicy {
|
|
54
|
+
enabled: boolean
|
|
55
|
+
trigger: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** TokenPilot-inspired preset sub-capability switches (only injected for `tokenpilot-inspired`). */
|
|
59
|
+
export interface PresetOptions {
|
|
60
|
+
/** Reject replacements whose text is not smaller than the original (G1). */
|
|
61
|
+
readonly noNetSavingsGuard: boolean
|
|
62
|
+
/** Permanently exempt recovery content from further reduction (G2). */
|
|
63
|
+
readonly skipReductionRecovery: boolean
|
|
64
|
+
/** Replace byte-identical repeated tool results with first-occurrence pointers (A1). */
|
|
65
|
+
readonly dedupeToolResults: boolean
|
|
66
|
+
/** Append Exact Sources locator blocks after Auto Compact completes (A2). */
|
|
67
|
+
readonly summaryLocator: boolean
|
|
68
|
+
/** Volatile-line demotion, deterministic tool ordering, and prefix fingerprint audit (S1/S2). */
|
|
69
|
+
readonly prefixStabilizer: boolean
|
|
70
|
+
/** Fresh/superseded read-state classification with clustered omission markers (R2/R3). */
|
|
71
|
+
readonly readState: boolean
|
|
72
|
+
/** Optional estimator channel; `''` keeps every estimator consumer on rule-only fallbacks (E1/E2). */
|
|
73
|
+
readonly estimator: { readonly mode: '' | 'host' | 'direct' }
|
|
74
|
+
/**
|
|
75
|
+
* Advisory relevance advisor: statistics and suggestions only — every output
|
|
76
|
+
* (summaries, scores, decay, recertification) is observational and must never
|
|
77
|
+
* suppress, delay, or rewrite any reduction that would land. `''` (the
|
|
78
|
+
* default) keeps the advisor fully off.
|
|
79
|
+
*/
|
|
80
|
+
readonly advisor: {
|
|
81
|
+
readonly mode: '' | 'host' | 'direct'
|
|
82
|
+
readonly timeoutMs: number
|
|
83
|
+
readonly refreshTurns: number
|
|
84
|
+
readonly scoreThreshold: number
|
|
85
|
+
readonly sampleLimit: number
|
|
86
|
+
readonly minTokens: number
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Common user-authored Custom stages shared by persisted policy versions. */
|
|
91
|
+
interface CustomCompressionPolicyFields<HistoryPolicy> {
|
|
92
|
+
unit: CustomCompressionUnit
|
|
93
|
+
fresh: CustomCompressionBudget
|
|
94
|
+
aggregate: CustomCompressionBudget
|
|
95
|
+
history: HistoryPolicy
|
|
96
|
+
prefixPolicy: CustomPrefixPolicy
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Legacy R4 Custom policy, accepted without migration. */
|
|
100
|
+
export interface CustomCompressionPolicyV1 extends CustomCompressionPolicyFields<LegacyCustomHistoryPolicy> {
|
|
101
|
+
version: 1
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** R5 Custom policy with an explicit default-off TailTrim stage. */
|
|
105
|
+
export interface CustomCompressionPolicyV2 extends CustomCompressionPolicyFields<LegacyCustomHistoryPolicy> {
|
|
106
|
+
version: 2
|
|
107
|
+
tailTrim: CustomTailTrimPolicy
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Custom policy with tool-call working-set protection. */
|
|
111
|
+
export interface CustomCompressionPolicyV3 extends CustomCompressionPolicyFields<CustomHistoryPolicy> {
|
|
112
|
+
version: 3
|
|
113
|
+
tailTrim: CustomTailTrimPolicy
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Strict persisted Custom policy union. */
|
|
117
|
+
export type CustomCompressionPolicy = CustomCompressionPolicyV1 | CustomCompressionPolicyV2 | CustomCompressionPolicyV3
|
|
118
|
+
|
|
119
|
+
/** User-tunable Auto Compact coordination preferences. */
|
|
120
|
+
export interface AutoCompactSettings {
|
|
121
|
+
/** Routed-context percentage that triggers model-driven Auto Compact. */
|
|
122
|
+
thresholdPercent: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Orthogonal evidence-based code-skeleton reducer gate. Independent of every
|
|
127
|
+
* profile: when enabled, fresh oversized source-code results may take the
|
|
128
|
+
* `hypa-code-skeleton` reducer before the head/tail fallbacks.
|
|
129
|
+
*/
|
|
130
|
+
export interface CodeSkeletonSettings {
|
|
131
|
+
enabled: boolean
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Orthogonal turn-tail intent-summary gate. Independent of every profile:
|
|
136
|
+
* when enabled, the turn-boundary growth gate may fold consumed-increment
|
|
137
|
+
* tool results into an LLM-written intent block (skeleton + verbatim error
|
|
138
|
+
* lines are kept; the model only ever writes the summary segment).
|
|
139
|
+
*/
|
|
140
|
+
export interface IntentSummarySettings {
|
|
141
|
+
enabled: boolean
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Persisted sub-capability overrides for the `tokenpilot-inspired` preset.
|
|
146
|
+
* Absent fields inherit the preset defaults; the section is only meaningful
|
|
147
|
+
* while the resolved profile is `tokenpilot-inspired`.
|
|
148
|
+
*/
|
|
149
|
+
export interface PresetOptionsSettings {
|
|
150
|
+
readonly dedupeToolResults?: boolean
|
|
151
|
+
readonly summaryLocator?: boolean
|
|
152
|
+
readonly prefixStabilizer?: boolean
|
|
153
|
+
readonly readState?: boolean
|
|
154
|
+
readonly estimatorMode?: '' | 'host' | 'direct'
|
|
155
|
+
/**
|
|
156
|
+
* Estimator endpoint fields. Persisted-settings only: they never enter the
|
|
157
|
+
* frozen CompressionPolicy, which is emitted verbatim by policy-resolved
|
|
158
|
+
* audits, so the API key cannot leak into logs.
|
|
159
|
+
*/
|
|
160
|
+
readonly estimatorProvider?: string
|
|
161
|
+
readonly estimatorModel?: string
|
|
162
|
+
readonly estimatorBaseUrl?: string
|
|
163
|
+
readonly estimatorApiKey?: string
|
|
164
|
+
readonly estimatorTimeoutMs?: number
|
|
165
|
+
/** Advisory advisor channel; `''` (the default) keeps the advisor off. */
|
|
166
|
+
readonly advisorMode?: '' | 'host' | 'direct'
|
|
167
|
+
readonly advisorTimeoutMs?: number
|
|
168
|
+
readonly advisorRefreshTurns?: number
|
|
169
|
+
readonly advisorScoreThreshold?: number
|
|
170
|
+
readonly advisorSampleLimit?: number
|
|
171
|
+
readonly advisorMinTokens?: number
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Durable global preference exposed through `ctx.settings`. */
|
|
175
|
+
export interface ContextCompressionSettings {
|
|
176
|
+
/** Default strategy snapped when a Session first reaches the pruner. */
|
|
177
|
+
profile: CompressionProfile
|
|
178
|
+
/** Versioned Custom policy snapped with `profile` for a newly observed Session. */
|
|
179
|
+
custom: CustomCompressionPolicy
|
|
180
|
+
/** Auto Compact trigger preference snapped with `profile` for a newly observed Session. */
|
|
181
|
+
autoCompact: AutoCompactSettings
|
|
182
|
+
/** Code-skeleton reducer gate snapped independently of `profile`. */
|
|
183
|
+
codeSkeleton: CodeSkeletonSettings
|
|
184
|
+
/** Turn-tail intent-summary gate snapped independently of `profile`. */
|
|
185
|
+
intentSummary: IntentSummarySettings
|
|
186
|
+
/** Optional tokenpilot-inspired sub-capability overrides; absent inherits preset defaults. */
|
|
187
|
+
presetOptions?: PresetOptionsSettings
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Token-gated policy with character fields limited to reducer candidate shape. */
|
|
191
|
+
export interface ToolResultPruneConfig {
|
|
192
|
+
/** Composition fallback when Host settings are unavailable. Defaults to `balanced`. */
|
|
193
|
+
profile?: CompressionProfile
|
|
194
|
+
/** Native fallback leading Unicode code points. Defaults to `4096`. */
|
|
195
|
+
headChars?: number
|
|
196
|
+
/** Native fallback trailing Unicode code points. Defaults to `1024`. */
|
|
197
|
+
tailChars?: number
|
|
198
|
+
/** Native original-content token trigger. Profile default when omitted. */
|
|
199
|
+
nativeTriggerTokens?: number
|
|
200
|
+
/** Native replacement token target. Profile default when omitted. */
|
|
201
|
+
nativeTargetTokens?: number
|
|
202
|
+
/** Fresh-result exact-token trigger. Profile default when omitted. */
|
|
203
|
+
freshTriggerTokens?: number
|
|
204
|
+
/** Maximum fresh-result exact-token replacement size. Profile default when omitted. */
|
|
205
|
+
freshTargetTokens?: number
|
|
206
|
+
/** Combined completed-step token pressure that starts aggregate reduction. */
|
|
207
|
+
aggregateTriggerTokens?: number
|
|
208
|
+
/** Aggregate token target after completed-step pressure exceeds its trigger. */
|
|
209
|
+
aggregateTargetTokens?: number
|
|
210
|
+
/** Total live tool-result tokens that permit historical aging. Profile default when omitted. */
|
|
211
|
+
historyTriggerTokens?: number
|
|
212
|
+
/** Recent completed agent tool calls protected from historical aging. Profile default when omitted. */
|
|
213
|
+
historyKeepRecentToolCalls?: number
|
|
214
|
+
/** Recent tool-result token tail protected in addition to tool calls. Profile default when omitted. */
|
|
215
|
+
historyKeepRecentTokens?: number
|
|
216
|
+
/** Minimum reclaim required before historical aging is worth a cache break. Profile default when omitted. */
|
|
217
|
+
historyMinReclaimTokens?: number
|
|
218
|
+
/**
|
|
219
|
+
* Read-class input cap in characters. Invariant (startup-asserted in
|
|
220
|
+
* `resolvePolicy`): when set it must exceed `freshTriggerTokens × 4.0` —
|
|
221
|
+
* the conservative chars/token upper bound — otherwise the cap sits below
|
|
222
|
+
* the fresh trigger and silently silences the fresh path for every read
|
|
223
|
+
* result. Unset profiles (host cap 50k–59.5k chars observed) stay untouched.
|
|
224
|
+
*/
|
|
225
|
+
readInputCapChars?: number
|
|
226
|
+
/**
|
|
227
|
+
* Auto Compact threshold percent frozen into this deployment by the preset
|
|
228
|
+
* overlay generation (50–90 integer). When present it supersedes the live
|
|
229
|
+
* Host setting so one generation never splits Auto Compact and micro
|
|
230
|
+
* compact across two thresholds.
|
|
231
|
+
*/
|
|
232
|
+
autoCompactThresholdPercent?: number
|
|
233
|
+
/** Optional tokenpilot-inspired sub-capability overrides (deploy-level). */
|
|
234
|
+
presetOptions?: PresetOptionsSettings
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Resolved per-profile behavior. */
|
|
238
|
+
export interface CompressionPolicy {
|
|
239
|
+
readonly profile: CompressionProfile
|
|
240
|
+
/** Whether this Session may use the selector's native-style head/middle/tail reducer. */
|
|
241
|
+
readonly nativeToolResultEnabled: boolean
|
|
242
|
+
readonly freshEnabled: boolean
|
|
243
|
+
readonly aggregateEnabled: boolean
|
|
244
|
+
readonly historyMode: HistoryMode
|
|
245
|
+
readonly nativeTriggerTokens: number
|
|
246
|
+
readonly nativeTargetTokens: number
|
|
247
|
+
readonly freshTriggerTokens: number
|
|
248
|
+
readonly freshTargetTokens: number
|
|
249
|
+
readonly aggregateTriggerTokens: number
|
|
250
|
+
readonly aggregateTargetTokens: number
|
|
251
|
+
readonly historyTriggerTokens: number
|
|
252
|
+
readonly historyKeepRecentToolCalls: number
|
|
253
|
+
readonly historyKeepRecentTokens: number
|
|
254
|
+
readonly historyMinReclaimTokens: number
|
|
255
|
+
/**
|
|
256
|
+
* Read-class input cap in characters when configured; absent otherwise.
|
|
257
|
+
* Startup-asserted to exceed `freshTriggerTokens × 4.0` so it can never
|
|
258
|
+
* silently silence the fresh path (G2 invariant).
|
|
259
|
+
*/
|
|
260
|
+
readonly readInputCapChars?: number
|
|
261
|
+
/**
|
|
262
|
+
* Auto Compact token watermark `A = floor(C × a)` when the standard-profile
|
|
263
|
+
* History linkage resolved for this Session; absent for Custom, Off, Native,
|
|
264
|
+
* or unresolved routed capacity.
|
|
265
|
+
*/
|
|
266
|
+
readonly autoCompactTokens?: number
|
|
267
|
+
/**
|
|
268
|
+
* Micro-compact last-chance watermark `D = floor(A × 0.875)`. Absent when
|
|
269
|
+
* {@link autoCompactTokens} is absent; capacity-pressure gates fall back to
|
|
270
|
+
* the fixed 0.7 routed-context ratio in that case.
|
|
271
|
+
*/
|
|
272
|
+
readonly microDeadlineTokens?: number
|
|
273
|
+
/** Present for Custom v3; standard profiles and legacy Custom policies carry no TailTrim policy. */
|
|
274
|
+
readonly tailTrim?: {
|
|
275
|
+
readonly enabled: boolean
|
|
276
|
+
readonly triggerTokens: number
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* TokenPilot-inspired sub-capability switches. Present only for the
|
|
280
|
+
* `tokenpilot-inspired` preset; every other profile stays byte-identical.
|
|
281
|
+
*/
|
|
282
|
+
readonly presetOptions?: PresetOptions
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Validated, detached, deeply immutable configuration. */
|
|
286
|
+
export interface ResolvedConfig {
|
|
287
|
+
readonly profile: CompressionProfile
|
|
288
|
+
readonly headChars: number
|
|
289
|
+
readonly tailChars: number
|
|
290
|
+
readonly nativeTriggerTokens?: number
|
|
291
|
+
readonly nativeTargetTokens?: number
|
|
292
|
+
readonly freshTriggerTokens?: number
|
|
293
|
+
readonly freshTargetTokens?: number
|
|
294
|
+
readonly aggregateTriggerTokens?: number
|
|
295
|
+
readonly aggregateTargetTokens?: number
|
|
296
|
+
readonly historyTriggerTokens?: number
|
|
297
|
+
readonly historyKeepRecentToolCalls?: number
|
|
298
|
+
readonly historyKeepRecentTokens?: number
|
|
299
|
+
readonly historyMinReclaimTokens?: number
|
|
300
|
+
/** Read-class input cap in characters when configured; absent otherwise. */
|
|
301
|
+
readonly readInputCapChars?: number
|
|
302
|
+
/**
|
|
303
|
+
* Auto Compact threshold percent frozen into this deployment by the preset
|
|
304
|
+
* overlay generation (50-90 integer). Supersedes the live Host setting.
|
|
305
|
+
*/
|
|
306
|
+
readonly autoCompactThresholdPercent?: number
|
|
307
|
+
/** Optional tokenpilot-inspired sub-capability overrides resolved from the deployment config. */
|
|
308
|
+
readonly presetOptions?: PresetOptionsSettings
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Why a pruning pass runs. */
|
|
312
|
+
export type PruneStage = 'fresh' | 'pressure'
|
|
313
|
+
|
|
314
|
+
/** Optional control over one pruning pass. */
|
|
315
|
+
export interface PruneSessionOptions {
|
|
316
|
+
/** `fresh` only reduces never-before-seen oversized results; `pressure` may age older results too. */
|
|
317
|
+
stage?: PruneStage
|
|
318
|
+
/** Routed model context capacity used only to resolve a context-percent Custom snapshot. */
|
|
319
|
+
contextWindowTokens?: number
|
|
320
|
+
/** Proposed turn at the pre-step boundary. Used with `freshStep` to freeze keep/reduce decisions. */
|
|
321
|
+
freshTurn?: number
|
|
322
|
+
/** The immediately preceding completed step whose tool results have not yet entered a model request. */
|
|
323
|
+
freshStep?: number
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Cited source event and size accounting for one landed surface replacement. */
|
|
327
|
+
export interface PrunedEntry {
|
|
328
|
+
/** Current surface event shadowed by this replacement. */
|
|
329
|
+
readonly originalSeq: number
|
|
330
|
+
/** Root full-fidelity source event used in the recovery reference. */
|
|
331
|
+
readonly sourceSeq: number
|
|
332
|
+
/** Newly appended compressed tool-result event. */
|
|
333
|
+
readonly replacementSeq: number
|
|
334
|
+
/** Tool call shared by the original and replacement. */
|
|
335
|
+
readonly callId: CallId
|
|
336
|
+
/** Reducer or aging strategy that produced the replacement. */
|
|
337
|
+
readonly reducer: string
|
|
338
|
+
/** Pass stage that landed the replacement. */
|
|
339
|
+
readonly stage: PruneStage
|
|
340
|
+
/** Original deterministic pressure cost. */
|
|
341
|
+
readonly charsBefore: number
|
|
342
|
+
/** Replacement deterministic pressure cost. */
|
|
343
|
+
readonly charsAfter: number
|
|
344
|
+
/** Authoritative exact canonical content tokens before replacement. */
|
|
345
|
+
readonly tokensBefore: number
|
|
346
|
+
/** Authoritative exact canonical content tokens after replacement. */
|
|
347
|
+
readonly tokensAfter: number
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Aggregate outcome of one stable-surface pruning pass. */
|
|
351
|
+
export interface PruneResult {
|
|
352
|
+
/** Replacements in landing order. */
|
|
353
|
+
readonly pruned: readonly PrunedEntry[]
|
|
354
|
+
/** Total deterministic pressure cost removed across replacements. */
|
|
355
|
+
readonly charsRemoved: number
|
|
356
|
+
/** Authoritative exact canonical content tokens removed. */
|
|
357
|
+
readonly tokensRemoved: number
|
|
358
|
+
}
|