dsh-context-compression-improved 0.2.4 → 0.2.5
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/.gitattributes +2 -1
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +8 -8
- package/CHANGELOG.ja.md +169 -39
- package/CHANGELOG.ko.md +167 -39
- package/CHANGELOG.md +212 -16
- package/CHANGELOG.zh.md +152 -39
- package/CONTRIBUTING.md +22 -22
- package/README.ja.md +85 -104
- package/README.ko.md +85 -103
- package/README.md +1 -19
- package/README.zh.md +85 -101
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.ja.md +78 -76
- package/docs/installation.ko.md +78 -76
- package/docs/installation.md +103 -76
- package/docs/installation.zh.md +100 -76
- package/docs/repair-log.md +657 -582
- package/eslint.config.js +30 -30
- package/package.json +75 -54
- package/packages/selector/README.md +7 -12
- package/packages/selector/README.zh.md +6 -13
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
- package/packages/selector/cordis.patch.yml +27 -19
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +97 -5
- package/packages/selector/lib/client.js +1884 -92
- package/packages/selector/lib/config.js +863 -6
- package/packages/selector/lib/index.d.ts +29 -21
- package/packages/selector/lib/index.js +424 -18
- package/packages/selector/lib/invariant.js +4 -4
- package/packages/selector/lib/pruner.d.ts +179 -4
- package/packages/selector/lib/pruner.js +1406 -371
- package/packages/selector/lib/style.css +42 -0
- package/packages/selector/lib/tail-trim.js +13 -4
- package/packages/selector/package.json +18 -27
- package/packages/selector/screenshots.json +3 -6
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
- package/packages/selector/src/client/EstimatorControls.tsx +277 -281
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +200 -62
- package/packages/selector/src/client/locales/de.ts +141 -0
- package/packages/selector/src/client/locales/es.ts +141 -0
- package/packages/selector/src/client/locales/fr.ts +141 -0
- package/packages/selector/src/client/locales/it.ts +141 -0
- package/packages/selector/src/client/locales/ja.ts +141 -0
- package/packages/selector/src/client/locales/ko.ts +141 -0
- package/packages/selector/src/client/locales/ru.ts +141 -0
- package/packages/selector/src/client/locales.ts +282 -198
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/preset-options.ts +88 -70
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -126
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
- package/packages/selector/src/index.ts +671 -327
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/profiles.ts +431 -342
- package/packages/selector/src/pruner/state.ts +57 -43
- package/packages/selector/src/pruner.ts +2736 -2154
- package/packages/selector/src/runtime/audit.ts +303 -231
- package/packages/selector/src/runtime/config.ts +756 -642
- package/packages/selector/src/runtime/measurement.ts +436 -432
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/session-events.ts +30 -17
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
- 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/tokenpilot/sidechannel.ts +303 -275
- package/packages/selector/src/runtime/types.ts +365 -325
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
- package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
- package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
- package/packages/selector/tests/preset-overlay.host.spec.ts +8 -18
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -172
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- 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/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2702
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
- package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +142 -87
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
- package/pnpm-workspace.yaml +66 -19
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
- package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
- package/scripts/toolclass-corpus-replay.mjs +281 -273
- package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
- package/tests/TEST_INVENTORY.md +41 -42
- package/scripts/capture-profile-baseline.ts +0 -80
- package/tsconfig.scripts.json +0 -13
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
|
@@ -1,713 +1,732 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
) {
|
|
113
|
-
|
|
114
|
-
session.append('
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
session
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
&&
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
boundaryCtx.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
{
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
})
|
|
458
|
-
visionText.append('
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
assert(estimatedImageCount
|
|
551
|
-
`packed vision image
|
|
552
|
-
assert(estimatedImageCount.
|
|
553
|
-
`packed vision
|
|
554
|
-
assert(
|
|
555
|
-
`packed vision
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
assert(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
await ctx
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
await ctx.settings.update(namespace, { custom:
|
|
631
|
-
frozenA.
|
|
632
|
-
appendToolTurn(frozenA
|
|
633
|
-
assert(ctx.toolResultPruner.pruneSession(frozenA, {
|
|
634
|
-
stage: 'fresh', freshTurn:
|
|
635
|
-
}).pruned.length === 1, '
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
&&
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
&&
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
stage:
|
|
704
|
-
reducer:
|
|
705
|
-
tokensBefore:
|
|
706
|
-
tokensAfter:
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
1
|
+
import { realpath } from 'node:fs/promises'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, sep } from 'node:path'
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
5
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
6
|
+
import { agentEvents } from '@deepseek-ai/dsh-agent'
|
|
7
|
+
import AgentLoop from '@deepseek-ai/dsh-agent-loop'
|
|
8
|
+
import { mountAgentLoopTestDependencies } from '@deepseek-ai/dsh-agent-loop-testkit'
|
|
9
|
+
import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic'
|
|
10
|
+
import LlmRuntime, {
|
|
11
|
+
ToolCallId as CallId,
|
|
12
|
+
createMessage,
|
|
13
|
+
createUserMessage,
|
|
14
|
+
createToolResultMessage,
|
|
15
|
+
LlmAdapter,
|
|
16
|
+
} from '@deepseek-ai/dsh-llm'
|
|
17
|
+
import SessionStore, { Session, SessionId, canonicalHeader } from '@deepseek-ai/dsh-session'
|
|
18
|
+
import { SettingsProvider } from '@deepseek-ai/dsh-settings'
|
|
19
|
+
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
20
|
+
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
|
|
21
|
+
import TokenMeter from '@deepseek-ai/dsh-token-meter'
|
|
22
|
+
import ToolRuntime from '@deepseek-ai/dsh-tools'
|
|
23
|
+
|
|
24
|
+
const MODEL = 'deepseek-v4-flash'
|
|
25
|
+
const AUDIT_PREFIX = 'context-compression audit '
|
|
26
|
+
const consumerRoot = await realpath(dirname(fileURLToPath(import.meta.url)))
|
|
27
|
+
const consumerRequire = createRequire(import.meta.url)
|
|
28
|
+
const selectorPackage = consumerRequire.resolve('dsh-context-compression-improved/package.json')
|
|
29
|
+
const selectorRequire = createRequire(selectorPackage)
|
|
30
|
+
const prunerEntry = selectorRequire.resolve('dsh-context-compression-improved/pruner')
|
|
31
|
+
const SelectorHost = await import(pathToFileURL(consumerRequire.resolve('dsh-context-compression-improved')).href)
|
|
32
|
+
const Runtime = await import(pathToFileURL(prunerEntry).href)
|
|
33
|
+
|
|
34
|
+
const assert = (condition, message) => {
|
|
35
|
+
if (!condition) throw new Error(`packed component smoke: ${message}`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (const path of [selectorPackage, prunerEntry]) {
|
|
39
|
+
const resolved = await realpath(path)
|
|
40
|
+
assert(resolved.startsWith(`${consumerRoot}${sep}node_modules${sep}`),
|
|
41
|
+
`product module resolved outside the packed consumer: ${resolved}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class MemorySettings extends SettingsProvider {
|
|
45
|
+
writable = true
|
|
46
|
+
stored = {}
|
|
47
|
+
|
|
48
|
+
load() {
|
|
49
|
+
return Promise.resolve(structuredClone(this.stored))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
persist(namespace, section) {
|
|
53
|
+
this.stored[namespace] = structuredClone(section)
|
|
54
|
+
return Promise.resolve()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class NativeSummaryAdapter extends LlmAdapter {
|
|
59
|
+
constructor(responses, contextWindow) {
|
|
60
|
+
super()
|
|
61
|
+
this.responses = [...responses]
|
|
62
|
+
this.contextWindow = contextWindow
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
resolveModel(provider, model) {
|
|
66
|
+
return Promise.resolve({
|
|
67
|
+
provider,
|
|
68
|
+
id: model,
|
|
69
|
+
name: model,
|
|
70
|
+
context: { contextWindow: this.contextWindow },
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async * stream(options) {
|
|
75
|
+
options.signal?.throwIfAborted()
|
|
76
|
+
const text = this.responses.shift()
|
|
77
|
+
if (text === undefined) throw new Error('NativeSummaryAdapter response script exhausted')
|
|
78
|
+
yield { type: 'block-start', index: 0, blockType: 'text' }
|
|
79
|
+
yield { type: 'text-delta', index: 0, text }
|
|
80
|
+
yield { type: 'block-end', index: 0, block: { type: 'text', text } }
|
|
81
|
+
yield { type: 'usage', usage: { inputTokens: 10, outputTokens: text.length } }
|
|
82
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function captureAudit(ctx) {
|
|
87
|
+
const records = []
|
|
88
|
+
Object.defineProperty(ctx.logger, 'info', {
|
|
89
|
+
configurable: true,
|
|
90
|
+
value(message) {
|
|
91
|
+
const line = String(message)
|
|
92
|
+
if (line.startsWith(AUDIT_PREFIX)) records.push(JSON.parse(line.slice(AUDIT_PREFIX.length)))
|
|
93
|
+
return ctx.logger
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
return records
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function appendToolTurn(session, turn, text, closeTurn, userText, provider = 'deepseek', model = MODEL) {
|
|
100
|
+
const callId = CallId(`packed-call-${String(turn)}`)
|
|
101
|
+
session.append('turn/start', { turn })
|
|
102
|
+
if (session.requestHeader() === undefined) {
|
|
103
|
+
session.append('request/header', {
|
|
104
|
+
reason: 'initial',
|
|
105
|
+
header: canonicalHeader({ config: { provider, model } }),
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
if (userText !== undefined) {
|
|
109
|
+
session.append('user/message', createUserMessage({
|
|
110
|
+
content: [{ type: 'text', text: userText }],
|
|
111
|
+
source: { kind: 'user' },
|
|
112
|
+
}), { surfaceOp: 'append' })
|
|
113
|
+
}
|
|
114
|
+
session.append('step/start', { turn, step: 1 })
|
|
115
|
+
const assistant = session.append('assistant/message', {
|
|
116
|
+
stream: [],
|
|
117
|
+
turn,
|
|
118
|
+
step: 1,
|
|
119
|
+
message: createMessage({
|
|
120
|
+
role: 'assistant',
|
|
121
|
+
content: [{ type: 'tool-call', id: callId, name: 'bash', arguments: '{}' }],
|
|
122
|
+
source: { kind: 'model', provider, model },
|
|
123
|
+
}),
|
|
124
|
+
}, { surfaceOp: 'append' })
|
|
125
|
+
session.append('tool/call', { turn, step: 1, callId, name: 'bash', arguments: '{}' })
|
|
126
|
+
const result = session.append('tool/result', {
|
|
127
|
+
turn,
|
|
128
|
+
step: 1,
|
|
129
|
+
message: createToolResultMessage({
|
|
130
|
+
callId,
|
|
131
|
+
content: [{ type: 'text', text }],
|
|
132
|
+
isError: false,
|
|
133
|
+
}),
|
|
134
|
+
}, { surfaceOp: 'append' })
|
|
135
|
+
session.append('step/end', { turn, step: 1 })
|
|
136
|
+
if (closeTurn) session.append('turn/end', { turn, reason: { kind: 'completed' } })
|
|
137
|
+
return { assistantSeq: assistant.seq, resultSeq: result.seq }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function appendToolBatchTurn(session, turn, texts, closeTurn, userText) {
|
|
141
|
+
const calls = texts.map((_, index) => ({
|
|
142
|
+
id: CallId(`packed-call-${String(turn)}-${String(index + 1)}`),
|
|
143
|
+
name: 'bash',
|
|
144
|
+
}))
|
|
145
|
+
session.append('turn/start', { turn })
|
|
146
|
+
if (session.requestHeader() === undefined) {
|
|
147
|
+
session.append('request/header', {
|
|
148
|
+
reason: 'initial',
|
|
149
|
+
header: canonicalHeader({ config: { provider: 'deepseek', model: MODEL } }),
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
if (userText !== undefined) {
|
|
153
|
+
session.append('user/message', createUserMessage({
|
|
154
|
+
content: [{ type: 'text', text: userText }],
|
|
155
|
+
source: { kind: 'user' },
|
|
156
|
+
}), { surfaceOp: 'append' })
|
|
157
|
+
}
|
|
158
|
+
session.append('step/start', { turn, step: 1 })
|
|
159
|
+
session.append('assistant/message', {
|
|
160
|
+
stream: [],
|
|
161
|
+
turn,
|
|
162
|
+
step: 1,
|
|
163
|
+
message: createMessage({
|
|
164
|
+
role: 'assistant',
|
|
165
|
+
content: calls.map(call => ({
|
|
166
|
+
type: 'tool-call', id: call.id, name: call.name, arguments: '{}',
|
|
167
|
+
})),
|
|
168
|
+
source: { kind: 'model', provider: 'deepseek', model: MODEL },
|
|
169
|
+
}),
|
|
170
|
+
}, { surfaceOp: 'append' })
|
|
171
|
+
for (const [index, call] of calls.entries()) {
|
|
172
|
+
session.append('tool/call', {
|
|
173
|
+
turn, step: 1, callId: call.id, name: call.name, arguments: '{}',
|
|
174
|
+
})
|
|
175
|
+
session.append('tool/result', {
|
|
176
|
+
turn,
|
|
177
|
+
step: 1,
|
|
178
|
+
message: createToolResultMessage({
|
|
179
|
+
callId: call.id,
|
|
180
|
+
content: [{ type: 'text', text: texts[index] ?? '' }],
|
|
181
|
+
isError: false,
|
|
182
|
+
}),
|
|
183
|
+
}, { surfaceOp: 'append' })
|
|
184
|
+
}
|
|
185
|
+
session.append('step/end', { turn, step: 1 })
|
|
186
|
+
if (closeTurn) session.append('turn/end', { turn, reason: { kind: 'completed' } })
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function stubAgent(ctx, session) {
|
|
190
|
+
return {
|
|
191
|
+
id: session.id,
|
|
192
|
+
options: {},
|
|
193
|
+
session,
|
|
194
|
+
// 0.1.5 moved the durable Inbox behind the loop driver; the pruner only
|
|
195
|
+
// reads id/session, so an inert face is enough for the stub.
|
|
196
|
+
inbox: undefined,
|
|
197
|
+
status: 'idle',
|
|
198
|
+
ctx,
|
|
199
|
+
send() {},
|
|
200
|
+
followup() {},
|
|
201
|
+
steer: () => ({ outcome: Promise.resolve({ status: 'rejected' }) }),
|
|
202
|
+
inject() {},
|
|
203
|
+
cancel() {},
|
|
204
|
+
runMaintenance: task => task(new AbortController().signal),
|
|
205
|
+
whenIdle: () => Promise.resolve(),
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const ctx = new Context()
|
|
210
|
+
try {
|
|
211
|
+
await ctx.plugin(MemorySettings).await()
|
|
212
|
+
await ctx.plugin(SelectorHost).await()
|
|
213
|
+
await ctx.plugin(LlmRuntime).await()
|
|
214
|
+
await ctx.plugin(SessionStore).await()
|
|
215
|
+
await ctx.plugin(SystemPrompt).await()
|
|
216
|
+
await ctx.plugin(ToolRuntime).await()
|
|
217
|
+
await ctx.plugin(SessionProjectionRegistry).await()
|
|
218
|
+
await ctx.plugin(TokenMeter).await()
|
|
219
|
+
const audit = captureAudit(ctx)
|
|
220
|
+
|
|
221
|
+
const policy = structuredClone(Runtime.DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
222
|
+
assert(policy.version === 3, 'TailTrim requires the public Custom v3 policy')
|
|
223
|
+
policy.fresh = { enabled: true, trigger: 512, target: 256 }
|
|
224
|
+
policy.aggregate = { enabled: true, trigger: 1_000, target: 400 }
|
|
225
|
+
policy.history = {
|
|
226
|
+
enabled: true,
|
|
227
|
+
// Strict required-reclaim: the batch must pull tool tokens back under the
|
|
228
|
+
// trigger, so it sits above the large protected tail and placeholder
|
|
229
|
+
// residue while remaining below the session's tool-result total.
|
|
230
|
+
trigger: 7_800,
|
|
231
|
+
keepRecentToolCalls: 0,
|
|
232
|
+
keepRecentTokens: 1,
|
|
233
|
+
minReclaim: 1,
|
|
234
|
+
}
|
|
235
|
+
policy.prefixPolicy = 'pressure-break'
|
|
236
|
+
policy.tailTrim = { enabled: true, trigger: 8 }
|
|
237
|
+
const namespace = Runtime.CONTEXT_COMPRESSION_SETTINGS_NAMESPACE
|
|
238
|
+
await ctx.settings.update(namespace, { profile: 'custom', custom: policy })
|
|
239
|
+
await ctx.plugin(Runtime.default, {
|
|
240
|
+
profile: 'native',
|
|
241
|
+
nativeTriggerTokens: 100,
|
|
242
|
+
nativeTargetTokens: 64,
|
|
243
|
+
headChars: 8,
|
|
244
|
+
tailChars: 8,
|
|
245
|
+
}).await()
|
|
246
|
+
|
|
247
|
+
const session = Session.create(SessionId('packed-components-full-pipeline'))
|
|
248
|
+
appendToolTurn(session, 1, 'packed Fresh '.repeat(600), false, 'run packed Fresh')
|
|
249
|
+
ctx.toolResultPruner.pruneSession(session, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
|
|
250
|
+
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
|
251
|
+
appendToolBatchTurn(
|
|
252
|
+
session,
|
|
253
|
+
2,
|
|
254
|
+
Array.from({ length: 30 }, (_, index) => `packed Aggregate ${String(index)} `.repeat(20)),
|
|
255
|
+
false,
|
|
256
|
+
'run packed Aggregate',
|
|
257
|
+
)
|
|
258
|
+
ctx.toolResultPruner.pruneSession(session, { stage: 'fresh', freshTurn: 2, freshStep: 1 })
|
|
259
|
+
session.append('turn/end', { turn: 2, reason: { kind: 'completed' } })
|
|
260
|
+
appendToolTurn(session, 3, 'packed History '.repeat(600), true, 'run packed History')
|
|
261
|
+
appendToolTurn(session, 4, 'packed recent protected working-set context '.repeat(1000), true, 'retain packed recent context')
|
|
262
|
+
session.append('turn/start', { turn: 5 })
|
|
263
|
+
ctx.toolResultPruner.pruneSession(session, { stage: 'pressure' })
|
|
264
|
+
|
|
265
|
+
const tail = audit.find(record => record.kind === 'rewrite' && record.component === 'tail-trim')
|
|
266
|
+
assert(tail !== undefined, 'TailTrim did not commit from installed Runtime')
|
|
267
|
+
const ref = `session://${String(session.id)}/tailtrim/${String(tail.manifestSeq)}`
|
|
268
|
+
const recovered = await ctx.tools.execute({
|
|
269
|
+
name: 'context_compression_retrieve',
|
|
270
|
+
arguments: { ref, max_lines: 20 },
|
|
271
|
+
callId: CallId('packed-tailtrim-retrieve'),
|
|
272
|
+
signal: new AbortController().signal,
|
|
273
|
+
agent: stubAgent(ctx, session),
|
|
274
|
+
})
|
|
275
|
+
assert(recovered.isError === false, 'installed TailTrim recovery returned an error')
|
|
276
|
+
const recoveredText = recovered.content
|
|
277
|
+
.map(block => block.type === 'text' ? block.text : '')
|
|
278
|
+
.join('\n')
|
|
279
|
+
assert(recoveredText.includes('kind: tailtrim-group'),
|
|
280
|
+
'installed TailTrim recovery did not return a TailTrim group')
|
|
281
|
+
const tailSourcePayloads = tail.sourceSeqs
|
|
282
|
+
.map(seq => session.snapshotEvents()[seq])
|
|
283
|
+
.filter(event => event !== undefined)
|
|
284
|
+
.map(event => JSON.stringify(event))
|
|
285
|
+
const recoveredMarker = [
|
|
286
|
+
'packed Fresh',
|
|
287
|
+
'packed Aggregate',
|
|
288
|
+
'packed History',
|
|
289
|
+
'packed recent working set',
|
|
290
|
+
].find(marker => tailSourcePayloads.some(payload => payload.includes(marker)))
|
|
291
|
+
assert(recoveredMarker !== undefined,
|
|
292
|
+
'installed TailTrim audit did not identify an original source payload marker')
|
|
293
|
+
assert(recoveredText.includes(recoveredMarker),
|
|
294
|
+
'installed TailTrim recovery did not contain the audited original source payload')
|
|
295
|
+
|
|
296
|
+
const capacityPolicy = structuredClone(policy)
|
|
297
|
+
capacityPolicy.fresh.enabled = false
|
|
298
|
+
capacityPolicy.aggregate.enabled = false
|
|
299
|
+
capacityPolicy.history = {
|
|
300
|
+
enabled: true,
|
|
301
|
+
trigger: 400,
|
|
302
|
+
keepRecentToolCalls: 0,
|
|
303
|
+
keepRecentTokens: 1,
|
|
304
|
+
minReclaim: 1,
|
|
305
|
+
}
|
|
306
|
+
capacityPolicy.prefixPolicy = 'preserve'
|
|
307
|
+
capacityPolicy.tailTrim.enabled = false
|
|
308
|
+
await ctx.settings.update(namespace, { profile: 'custom', custom: capacityPolicy })
|
|
309
|
+
|
|
310
|
+
const inactiveCapacity = Session.create(SessionId('packed-history-capacity-inactive'))
|
|
311
|
+
appendToolTurn(inactiveCapacity, 1, 'packed capacity inactive '.repeat(600), true)
|
|
312
|
+
appendToolTurn(inactiveCapacity, 2, 'packed newest protected result', true)
|
|
313
|
+
inactiveCapacity.append('request/context', {
|
|
314
|
+
provider: 'deepseek',
|
|
315
|
+
model: MODEL,
|
|
316
|
+
contextWindow: 1_000_000,
|
|
317
|
+
})
|
|
318
|
+
inactiveCapacity.append('turn/start', { turn: 3 })
|
|
319
|
+
ctx.toolResultPruner.pruneSession(inactiveCapacity, { stage: 'pressure' })
|
|
320
|
+
const inactiveCapacityAudit = audit.find(record => record.kind === 'component-evaluation'
|
|
321
|
+
&& record.sessionId === String(inactiveCapacity.id)
|
|
322
|
+
&& record.component === 'history')
|
|
323
|
+
assert(inactiveCapacityAudit?.status === 'skipped'
|
|
324
|
+
&& inactiveCapacityAudit.reason === 'below-micro-deadline'
|
|
325
|
+
&& inactiveCapacityAudit.historyMode === 'capacity-pressure',
|
|
326
|
+
'installed History did not prove the inactive capacity-pressure gate')
|
|
327
|
+
|
|
328
|
+
const activeCapacity = Session.create(SessionId('packed-history-capacity-active'))
|
|
329
|
+
appendToolTurn(activeCapacity, 1, 'packed capacity active '.repeat(600), true)
|
|
330
|
+
appendToolTurn(activeCapacity, 2, 'packed newest protected result', true)
|
|
331
|
+
const activeCapacityWindow = Math.floor(ctx.tokenMeter.measure(activeCapacity).totalTokens / 0.75)
|
|
332
|
+
activeCapacity.append('request/context', {
|
|
333
|
+
provider: 'deepseek',
|
|
334
|
+
model: MODEL,
|
|
335
|
+
contextWindow: activeCapacityWindow,
|
|
336
|
+
})
|
|
337
|
+
activeCapacity.append('turn/start', { turn: 3 })
|
|
338
|
+
ctx.toolResultPruner.pruneSession(activeCapacity, { stage: 'pressure' })
|
|
339
|
+
const capacityRewrite = audit.find(record => record.kind === 'rewrite'
|
|
340
|
+
&& record.sessionId === String(activeCapacity.id)
|
|
341
|
+
&& record.component === 'history')
|
|
342
|
+
assert(capacityRewrite?.historyMode === 'capacity-pressure'
|
|
343
|
+
&& capacityRewrite.stage === 'pressure'
|
|
344
|
+
&& typeof capacityRewrite.reducer === 'string'
|
|
345
|
+
&& Number.isSafeInteger(capacityRewrite.tokensBefore)
|
|
346
|
+
&& Number.isSafeInteger(capacityRewrite.tokensAfter)
|
|
347
|
+
&& capacityRewrite.tokensBefore > capacityRewrite.tokensAfter,
|
|
348
|
+
'installed History did not commit exact capacity-pressure evidence')
|
|
349
|
+
|
|
350
|
+
const boundaryCtx = new Context()
|
|
351
|
+
try {
|
|
352
|
+
await mountAgentLoopTestDependencies(boundaryCtx)
|
|
353
|
+
await boundaryCtx.plugin(AgentLoop, { agents: [] }).await()
|
|
354
|
+
await boundaryCtx.plugin(TokenMeter).await()
|
|
355
|
+
const boundaryAudit = captureAudit(boundaryCtx)
|
|
356
|
+
boundaryCtx.llm.registerAdapter(
|
|
357
|
+
['deepseek'],
|
|
358
|
+
new NativeSummaryAdapter(['packed Cache Strict pressure pass complete'], 100),
|
|
359
|
+
)
|
|
360
|
+
await boundaryCtx.plugin(Runtime.default, {
|
|
361
|
+
profile: 'cache-strict',
|
|
362
|
+
freshTriggerTokens: 100_000,
|
|
363
|
+
freshTargetTokens: 90_000,
|
|
364
|
+
aggregateTriggerTokens: 100_000,
|
|
365
|
+
aggregateTargetTokens: 90_000,
|
|
366
|
+
historyTriggerTokens: 400,
|
|
367
|
+
historyKeepRecentToolCalls: 0,
|
|
368
|
+
historyKeepRecentTokens: 1,
|
|
369
|
+
historyMinReclaimTokens: 1,
|
|
370
|
+
}).await()
|
|
371
|
+
const boundaryAgent = await boundaryCtx.agentLoop.create(
|
|
372
|
+
SessionId('packed-history-capacity-request-boundary'),
|
|
373
|
+
{ provider: 'deepseek', model: MODEL },
|
|
374
|
+
)
|
|
375
|
+
const boundarySession = boundaryAgent.session
|
|
376
|
+
appendToolTurn(boundarySession, 1, 'packed old capacity-pressure evidence '.repeat(600), true)
|
|
377
|
+
appendToolTurn(boundarySession, 2, 'packed newest protected result', true)
|
|
378
|
+
const boundaryTotal = boundaryCtx.tokenMeter.measure(boundarySession).totalTokens
|
|
379
|
+
boundarySession.append('request/context', {
|
|
380
|
+
provider: 'deepseek',
|
|
381
|
+
model: MODEL,
|
|
382
|
+
// Just under the frozen 80% deadline D = 0.7 * window so the gate is
|
|
383
|
+
// active while the strict reclaim target stays reachable.
|
|
384
|
+
contextWindow: Math.floor(boundaryTotal / 0.72),
|
|
385
|
+
})
|
|
386
|
+
boundaryAgent.followup(createUserMessage({
|
|
387
|
+
content: [{ type: 'text', text: 'run packed Cache Strict pressure pass' }],
|
|
388
|
+
source: { kind: 'user' },
|
|
389
|
+
}))
|
|
390
|
+
await boundaryAgent.whenIdle()
|
|
391
|
+
const boundaryRewrite = boundaryAudit.find(record => record.kind === 'rewrite'
|
|
392
|
+
&& record.sessionId === String(boundarySession.id)
|
|
393
|
+
&& record.component === 'history')
|
|
394
|
+
assert(boundaryRewrite?.stage === 'pressure'
|
|
395
|
+
&& boundaryRewrite.historyMode === 'capacity-pressure'
|
|
396
|
+
&& boundaryRewrite.tokensBefore > boundaryRewrite.tokensAfter,
|
|
397
|
+
'installed Cache Strict did not schedule History from the real request boundary')
|
|
398
|
+
} finally {
|
|
399
|
+
await boundaryCtx.fiber.dispose()
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Packed vision-session gate: the installed runtime must actually resolve
|
|
403
|
+
// the deepseek-v4-flash-vision-exp route, count text exactly with the
|
|
404
|
+
// separately bundled vision tokenizer, estimate image surfaces, and keep
|
|
405
|
+
// image-bearing results outside exact rewrite proofs.
|
|
406
|
+
const VISION_MODEL = 'deepseek-v4-flash-vision-exp'
|
|
407
|
+
const VISION_TOKENIZER_REPOSITORY = 'deepseek-ai/DeepSeek-V4-Flash-Vision-Exp'
|
|
408
|
+
const VISION_TOKENIZER_REVISION = '6821d6ad3681a4b137b066b76094fa82ebd0a380'
|
|
409
|
+
const imageBlock = (width, height) => ({
|
|
410
|
+
type: 'image',
|
|
411
|
+
attachment: {
|
|
412
|
+
attachmentId: `packed-image-${String(width)}x${String(height)}`,
|
|
413
|
+
mediaType: 'image/png',
|
|
414
|
+
bytes: 1_024,
|
|
415
|
+
width,
|
|
416
|
+
height,
|
|
417
|
+
},
|
|
418
|
+
})
|
|
419
|
+
const visionCtx = new Context()
|
|
420
|
+
try {
|
|
421
|
+
await visionCtx.plugin(MemorySettings).await()
|
|
422
|
+
await visionCtx.plugin(SelectorHost).await()
|
|
423
|
+
await visionCtx.plugin(LlmRuntime).await()
|
|
424
|
+
await visionCtx.plugin(SessionStore).await()
|
|
425
|
+
await visionCtx.plugin(SystemPrompt).await()
|
|
426
|
+
await visionCtx.plugin(ToolRuntime).await()
|
|
427
|
+
await visionCtx.plugin(SessionProjectionRegistry).await()
|
|
428
|
+
await visionCtx.plugin(TokenMeter).await()
|
|
429
|
+
const visionAudit = captureAudit(visionCtx)
|
|
430
|
+
await visionCtx.plugin(Runtime.default, {
|
|
431
|
+
profile: 'balanced',
|
|
432
|
+
freshTriggerTokens: 1_000_000,
|
|
433
|
+
freshTargetTokens: 900_000,
|
|
434
|
+
aggregateTriggerTokens: 100,
|
|
435
|
+
aggregateTargetTokens: 64,
|
|
436
|
+
historyTriggerTokens: 600,
|
|
437
|
+
historyKeepRecentToolCalls: 0,
|
|
438
|
+
historyKeepRecentTokens: 1,
|
|
439
|
+
historyMinReclaimTokens: 1,
|
|
440
|
+
}).await()
|
|
441
|
+
|
|
442
|
+
// (a) A user image plus pure-text tool results: the text rewrites must be
|
|
443
|
+
// exact and carry the vision tokenizer's repository/revision.
|
|
444
|
+
const visionText = Session.create(SessionId('packed-vision-text-session'))
|
|
445
|
+
visionText.append('turn/start', { turn: 1 })
|
|
446
|
+
visionText.append('request/header', {
|
|
447
|
+
reason: 'initial',
|
|
448
|
+
header: canonicalHeader({ config: { provider: 'deepseek', model: VISION_MODEL } }),
|
|
449
|
+
})
|
|
450
|
+
visionText.append('user/message', createUserMessage({
|
|
451
|
+
content: [
|
|
452
|
+
imageBlock(640, 480),
|
|
453
|
+
{ type: 'text', text: 'describe the attachment and run the tools' },
|
|
454
|
+
],
|
|
455
|
+
source: { kind: 'user' },
|
|
456
|
+
}), { surfaceOp: 'append' })
|
|
457
|
+
visionText.append('step/start', { turn: 1, step: 1 })
|
|
458
|
+
visionText.append('assistant/message', {
|
|
459
|
+
turn: 1,
|
|
460
|
+
step: 1,
|
|
461
|
+
message: createMessage({
|
|
462
|
+
role: 'assistant',
|
|
463
|
+
content: [{ type: 'tool-call', id: CallId('packed-vision-call-1'), name: 'bash', arguments: '{}' }],
|
|
464
|
+
source: { kind: 'model', provider: 'deepseek', model: VISION_MODEL },
|
|
465
|
+
}),
|
|
466
|
+
}, { surfaceOp: 'append' })
|
|
467
|
+
visionText.append('tool/call', { turn: 1, step: 1, callId: CallId('packed-vision-call-1'), name: 'bash', arguments: '{}' })
|
|
468
|
+
visionText.append('tool/result', {
|
|
469
|
+
turn: 1,
|
|
470
|
+
step: 1,
|
|
471
|
+
message: createToolResultMessage({
|
|
472
|
+
callId: CallId('packed-vision-call-1'),
|
|
473
|
+
content: [{ type: 'text', text: 'packed vision fresh evidence '.repeat(1_000) }],
|
|
474
|
+
isError: false,
|
|
475
|
+
}),
|
|
476
|
+
}, { surfaceOp: 'append' })
|
|
477
|
+
visionText.append('step/end', { turn: 1, step: 1 })
|
|
478
|
+
visionText.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
|
479
|
+
appendToolTurn(visionText, 2, 'packed vision history evidence '.repeat(300), true, undefined, 'deepseek', VISION_MODEL)
|
|
480
|
+
appendToolTurn(visionText, 3, 'packed recent protected result', true, undefined, 'deepseek', VISION_MODEL)
|
|
481
|
+
visionText.append('turn/start', { turn: 4 })
|
|
482
|
+
const visionFresh = visionCtx.toolResultPruner.pruneSession(visionText, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
|
|
483
|
+
const visionPressure = visionCtx.toolResultPruner.pruneSession(visionText, { stage: 'pressure' })
|
|
484
|
+
assert(visionFresh.pruned.length === 1 && visionPressure.pruned.length >= 1,
|
|
485
|
+
'packed vision text session did not rewrite pure-text results')
|
|
486
|
+
const visionRewrites = visionAudit
|
|
487
|
+
.filter(record => record.kind === 'rewrite' && record.sessionId === String(visionText.id))
|
|
488
|
+
assert(visionRewrites.length >= 2, 'packed vision text session lacks aggregate and history rewrites')
|
|
489
|
+
for (const record of visionRewrites) {
|
|
490
|
+
assert(record.tokenizerId === VISION_TOKENIZER_REPOSITORY
|
|
491
|
+
&& record.tokenizerRevision === VISION_TOKENIZER_REVISION,
|
|
492
|
+
`packed vision rewrite used tokenizer ${String(record.tokenizerId)}@${String(record.tokenizerRevision)}`)
|
|
493
|
+
}
|
|
494
|
+
assert(visionRewrites.some(record => record.component === 'aggregate')
|
|
495
|
+
&& visionRewrites.some(record => record.component === 'history'),
|
|
496
|
+
'packed vision text session lacks an aggregate/history component rewrite')
|
|
497
|
+
|
|
498
|
+
// (b) An image-bearing tool result: its surface may be estimated, but every
|
|
499
|
+
// rewrite path still requires exact counts. The original event is untouched
|
|
500
|
+
// and the audits say why no rewrite was authorized.
|
|
501
|
+
const visionImage = Session.create(SessionId('packed-vision-image-tool-result'))
|
|
502
|
+
visionImage.append('turn/start', { turn: 1 })
|
|
503
|
+
visionImage.append('request/header', {
|
|
504
|
+
reason: 'initial',
|
|
505
|
+
header: canonicalHeader({ config: { provider: 'deepseek', model: VISION_MODEL } }),
|
|
506
|
+
})
|
|
507
|
+
const estimatedUserImage = visionImage.append('user/message', createUserMessage({
|
|
508
|
+
content: [imageBlock(800, 600)],
|
|
509
|
+
source: { kind: 'user' },
|
|
510
|
+
}), { surfaceOp: 'append' })
|
|
511
|
+
visionImage.append('step/start', { turn: 1, step: 1 })
|
|
512
|
+
visionImage.append('assistant/message', {
|
|
513
|
+
turn: 1,
|
|
514
|
+
step: 1,
|
|
515
|
+
message: createMessage({
|
|
516
|
+
role: 'assistant',
|
|
517
|
+
content: [{ type: 'tool-call', id: CallId('packed-vision-image-call'), name: 'screenshot', arguments: '{}' }],
|
|
518
|
+
source: { kind: 'model', provider: 'deepseek', model: VISION_MODEL },
|
|
519
|
+
}),
|
|
520
|
+
}, { surfaceOp: 'append' })
|
|
521
|
+
visionImage.append('tool/call', { turn: 1, step: 1, callId: CallId('packed-vision-image-call'), name: 'screenshot', arguments: '{}' })
|
|
522
|
+
const imageResult = visionImage.append('tool/result', {
|
|
523
|
+
turn: 1,
|
|
524
|
+
step: 1,
|
|
525
|
+
message: createToolResultMessage({
|
|
526
|
+
callId: CallId('packed-vision-image-call'),
|
|
527
|
+
content: [
|
|
528
|
+
{ type: 'text', text: 'packed screenshot captured' },
|
|
529
|
+
imageBlock(800, 600),
|
|
530
|
+
],
|
|
531
|
+
isError: false,
|
|
532
|
+
}),
|
|
533
|
+
}, { surfaceOp: 'append' })
|
|
534
|
+
visionImage.append('step/end', { turn: 1, step: 1 })
|
|
535
|
+
visionImage.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
|
536
|
+
visionImage.append('turn/start', { turn: 2 })
|
|
537
|
+
const imageFresh = visionCtx.toolResultPruner.pruneSession(visionImage, { stage: 'fresh', freshTurn: 1, freshStep: 1 })
|
|
538
|
+
const imagePressure = visionCtx.toolResultPruner.pruneSession(visionImage, { stage: 'pressure' })
|
|
539
|
+
assert(imageFresh.pruned.length === 0 && imagePressure.pruned.length === 0,
|
|
540
|
+
'packed vision image-bearing result was rewritten lossily')
|
|
541
|
+
const imageMeasurement = Runtime.measureForCompaction(visionCtx, visionImage)
|
|
542
|
+
const estimatedImageCount = imageMeasurement.measuredNodes
|
|
543
|
+
.find(node => node.seq === estimatedUserImage.seq)?.count
|
|
544
|
+
assert(estimatedImageCount?.kind === 'tokenizer-estimate',
|
|
545
|
+
`packed vision image surface is ${String(estimatedImageCount?.kind)}, expected tokenizer-estimate`)
|
|
546
|
+
assert(estimatedImageCount.tokens === 340,
|
|
547
|
+
`packed vision 800x600 estimate is ${String(estimatedImageCount.tokens)}, expected 340`)
|
|
548
|
+
assert(estimatedImageCount.upperBoundTokens === 384,
|
|
549
|
+
`packed vision image upper bound is ${String(estimatedImageCount.upperBoundTokens)}, expected 384`)
|
|
550
|
+
assert(estimatedImageCount.estimatorId === `${VISION_TOKENIZER_REPOSITORY}/image-token-estimate`,
|
|
551
|
+
`packed vision image estimator id is ${String(estimatedImageCount.estimatorId)}`)
|
|
552
|
+
assert(estimatedImageCount.estimatorRevision === `${VISION_TOKENIZER_REVISION}:v1`,
|
|
553
|
+
`packed vision image estimator revision is ${String(estimatedImageCount.estimatorRevision)}`)
|
|
554
|
+
assert(imageMeasurement.currentSurface.kind === 'tokenizer-estimate',
|
|
555
|
+
`packed vision current surface is ${imageMeasurement.currentSurface.kind}, expected tokenizer-estimate`)
|
|
556
|
+
// Tool-result events carry one envelope block whose nested content holds
|
|
557
|
+
// the original [text, image] blocks; the durable attachment reference must
|
|
558
|
+
// still be there verbatim.
|
|
559
|
+
const originalImage = visionImage.snapshotEvents()[imageResult.seq]
|
|
560
|
+
assert(originalImage?.type === 'tool/result'
|
|
561
|
+
&& JSON.stringify(originalImage).includes('packed-image-800x600')
|
|
562
|
+
&& JSON.stringify(originalImage).includes('"type":"image"'),
|
|
563
|
+
'packed vision image-bearing result is no longer intact on the surface')
|
|
564
|
+
// The character basis retired the `exact-tokenizer-unavailable` skip: a
|
|
565
|
+
// History planning skip can no longer refuse for a missing exact count (see
|
|
566
|
+
// the HistoryPlanOutcome note in src/pruner/types.ts). A vision session
|
|
567
|
+
// without the exact tokenizer is therefore judged on characters and its
|
|
568
|
+
// skip carries a real reason (observed: fresh/aggregate `at-or-below-
|
|
569
|
+
// trigger`, history `below-profile-trigger`) — assert that observable
|
|
570
|
+
// contract instead of the removed literal.
|
|
571
|
+
for (const component of ['fresh', 'history']) {
|
|
572
|
+
const record = visionAudit.find(entry => entry.kind === 'component-evaluation'
|
|
573
|
+
&& entry.sessionId === String(visionImage.id)
|
|
574
|
+
&& entry.component === component)
|
|
575
|
+
assert(record !== undefined,
|
|
576
|
+
`packed vision image session lacks the ${component} component-evaluation audit`)
|
|
577
|
+
assert(record.status === 'skipped',
|
|
578
|
+
`packed vision ${component} status is ${String(record.status)}, expected skipped`)
|
|
579
|
+
assert(record.measurementKind === 'characters',
|
|
580
|
+
`packed vision ${component} was decided on ${String(record.measurementKind)}, expected characters`)
|
|
581
|
+
assert(typeof record.reason === 'string' && record.reason.length > 0,
|
|
582
|
+
`packed vision ${component} skip carries no diagnostic reason`)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
console.info(`PACKED_VISION_E2E ${JSON.stringify({
|
|
586
|
+
model: VISION_MODEL,
|
|
587
|
+
tokenizer: { repository: VISION_TOKENIZER_REPOSITORY, revision: VISION_TOKENIZER_REVISION },
|
|
588
|
+
textSession: 'exact-rewrites-with-vision-tokenizer',
|
|
589
|
+
imageSession: {
|
|
590
|
+
measurement: estimatedImageCount,
|
|
591
|
+
currentSurfaceKind: imageMeasurement.currentSurface.kind,
|
|
592
|
+
exactRewriteIneligible: true,
|
|
593
|
+
originalIntact: true,
|
|
594
|
+
},
|
|
595
|
+
})}`)
|
|
596
|
+
} finally {
|
|
597
|
+
await visionCtx.fiber.dispose()
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const beforeNative = ctx.tokenMeter.measure(session).totalTokens
|
|
601
|
+
assert(beforeNative > 2, 'installed pipeline has no Native pressure')
|
|
602
|
+
ctx.llm.registerAdapter(['deepseek'], new NativeSummaryAdapter(['packed native summary'], beforeNative))
|
|
603
|
+
void new BasicCompactionEngine(ctx, {
|
|
604
|
+
auto: true,
|
|
605
|
+
thresholdRatio: 0.5,
|
|
606
|
+
retainTokens: 0,
|
|
607
|
+
maxTokens: 100,
|
|
608
|
+
compactionRetries: 0,
|
|
609
|
+
})
|
|
610
|
+
const decision = await agentEvents(ctx, stubAgent(ctx, session)).waterfall(
|
|
611
|
+
'agent/pre-step',
|
|
612
|
+
{ messages: [], turn: 5, step: 1, signal: new AbortController().signal },
|
|
613
|
+
() => Promise.resolve({ kind: 'enter', messages: [] }),
|
|
614
|
+
)
|
|
615
|
+
assert(decision.kind === 'enter', 'Native pre-step did not return enter')
|
|
616
|
+
assert(session.snapshotEvents().some(event => event.type === 'compaction/summary'),
|
|
617
|
+
'official BasicCompactionEngine did not commit Native summary')
|
|
618
|
+
|
|
619
|
+
await ctx.settings.update(namespace, { profile: 'native' })
|
|
620
|
+
const nativeSession = Session.create(SessionId('packed-native-tool-result'))
|
|
621
|
+
appendToolTurn(nativeSession, 1, 'packed native tool result '.repeat(800), false)
|
|
622
|
+
const nativeResult = ctx.toolResultPruner.pruneSession(nativeSession, { stage: 'pressure' })
|
|
623
|
+
assert(nativeResult.pruned.length === 1, 'installed Native tool-result profile did not rewrite')
|
|
624
|
+
|
|
625
|
+
const firstFrozen = structuredClone(policy)
|
|
626
|
+
firstFrozen.fresh = { enabled: true, trigger: 512, target: 256 }
|
|
627
|
+
firstFrozen.aggregate.enabled = false
|
|
628
|
+
firstFrozen.history.enabled = false
|
|
629
|
+
firstFrozen.tailTrim.enabled = false
|
|
630
|
+
await ctx.settings.update(namespace, { profile: 'custom', custom: firstFrozen })
|
|
631
|
+
const frozenA = Session.create(SessionId('packed-policy-freeze-a'))
|
|
632
|
+
appendToolTurn(frozenA, 1, 'packed frozen first '.repeat(800), false)
|
|
633
|
+
assert(ctx.toolResultPruner.pruneSession(frozenA, {
|
|
634
|
+
stage: 'fresh', freshTurn: 1, freshStep: 1,
|
|
635
|
+
}).pruned.length === 1, 'first frozen policy did not run Fresh')
|
|
636
|
+
const edited = structuredClone(firstFrozen)
|
|
637
|
+
edited.fresh.enabled = false
|
|
638
|
+
edited.history.trigger += 123
|
|
639
|
+
await ctx.settings.update(namespace, { custom: edited })
|
|
640
|
+
frozenA.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
|
641
|
+
appendToolTurn(frozenA, 2, 'packed frozen second '.repeat(800), false)
|
|
642
|
+
assert(ctx.toolResultPruner.pruneSession(frozenA, {
|
|
643
|
+
stage: 'fresh', freshTurn: 2, freshStep: 1,
|
|
644
|
+
}).pruned.length === 1, 'observed Session did not retain its complete frozen policy')
|
|
645
|
+
const frozenB = Session.create(SessionId('packed-policy-freeze-b'))
|
|
646
|
+
appendToolTurn(frozenB, 1, 'packed new disabled Fresh '.repeat(800), false)
|
|
647
|
+
assert(ctx.toolResultPruner.pruneSession(frozenB, {
|
|
648
|
+
stage: 'fresh', freshTurn: 1, freshStep: 1,
|
|
649
|
+
}).pruned.length === 0, 'new Session did not adopt the edited complete policy')
|
|
650
|
+
|
|
651
|
+
const rewrites = audit.filter(record => record.kind === 'rewrite')
|
|
652
|
+
const firstIndex = component => audit.findIndex(record => record.kind === 'rewrite'
|
|
653
|
+
&& record.sessionId === String(session.id) && record.component === component)
|
|
654
|
+
for (const component of ['fresh', 'aggregate', 'history', 'tail-trim']) {
|
|
655
|
+
assert(firstIndex(component) >= 0, `installed pipeline lacks ${component} rewrite`)
|
|
656
|
+
}
|
|
657
|
+
const routineHistory = rewrites.find(record => record.sessionId === String(session.id)
|
|
658
|
+
&& record.component === 'history')
|
|
659
|
+
assert(routineHistory?.historyMode === 'routine',
|
|
660
|
+
'installed full pipeline did not identify routine History')
|
|
661
|
+
assert(firstIndex('fresh') < firstIndex('aggregate')
|
|
662
|
+
&& firstIndex('aggregate') < firstIndex('history')
|
|
663
|
+
&& firstIndex('history') < firstIndex('tail-trim'),
|
|
664
|
+
'installed component rewrite order is wrong')
|
|
665
|
+
const pipelineRewrites = rewrites.filter(record => record.sessionId === String(session.id))
|
|
666
|
+
// The character basis decides on Unicode code points, so a committed rewrite
|
|
667
|
+
// may report an unchanged token figure while still reclaiming characters
|
|
668
|
+
// (observed once here: history `historical-tool-result-aging` landed at
|
|
669
|
+
// 129 -> 129 with tokensRemoved 0). The rewrite audit carries no character
|
|
670
|
+
// field yet, so assert what the basis can actually guarantee: integer
|
|
671
|
+
// accounting, a consistent removal figure, and never an increase. A strict
|
|
672
|
+
// token decrease would re-encode the retired exact-token authority — see the
|
|
673
|
+
// measurementBasis note in src/runtime/audit.ts.
|
|
674
|
+
assert(pipelineRewrites.every(record => Number.isSafeInteger(record.tokensBefore)
|
|
675
|
+
&& Number.isSafeInteger(record.tokensAfter)
|
|
676
|
+
&& record.tokensBefore >= record.tokensAfter
|
|
677
|
+
&& record.tokensRemoved === record.tokensBefore - record.tokensAfter),
|
|
678
|
+
'installed rewrite token accounting is inconsistent or increasing')
|
|
679
|
+
assert(audit.some(record => record.kind === 'native-auto-compact'
|
|
680
|
+
&& record.sessionId === String(session.id)),
|
|
681
|
+
'installed Runtime did not audit official Native summary')
|
|
682
|
+
assert(rewrites.some(record => record.component === 'native-tool-result'
|
|
683
|
+
&& record.sessionId === String(nativeSession.id)),
|
|
684
|
+
'installed Runtime lacks Native tool-result audit')
|
|
685
|
+
const frozenAuditA = audit.find(record => record.kind === 'policy-frozen'
|
|
686
|
+
&& record.sessionId === String(frozenA.id))
|
|
687
|
+
const frozenAuditB = audit.find(record => record.kind === 'policy-frozen'
|
|
688
|
+
&& record.sessionId === String(frozenB.id))
|
|
689
|
+
assert(frozenAuditA?.settings?.custom?.fresh?.enabled === true,
|
|
690
|
+
'first installed policy-frozen record lacks original complete settings')
|
|
691
|
+
assert(frozenAuditB?.settings?.custom?.fresh?.enabled === false,
|
|
692
|
+
'new installed policy-frozen record lacks edited complete settings')
|
|
693
|
+
|
|
694
|
+
console.info(`PACKED_COMPONENTS_E2E ${JSON.stringify({
|
|
695
|
+
productImports: 'consumer-node_modules',
|
|
696
|
+
components: ['fresh', 'aggregate', 'history', 'tail-trim', 'native-tool-result'],
|
|
697
|
+
coreNative: 'compaction/summary',
|
|
698
|
+
tailTrimRecovery: 'original-group-recovered',
|
|
699
|
+
policyFreeze: 'old-session-retained-new-session-adopted',
|
|
700
|
+
exactTokenEvidence: 'before-greater-than-after',
|
|
701
|
+
historyModes: {
|
|
702
|
+
routine: {
|
|
703
|
+
stage: routineHistory.stage,
|
|
704
|
+
reducer: routineHistory.reducer,
|
|
705
|
+
tokensBefore: routineHistory.tokensBefore,
|
|
706
|
+
tokensAfter: routineHistory.tokensAfter,
|
|
707
|
+
},
|
|
708
|
+
capacityPressure: {
|
|
709
|
+
inactiveReason: inactiveCapacityAudit.reason,
|
|
710
|
+
stage: capacityRewrite.stage,
|
|
711
|
+
reducer: capacityRewrite.reducer,
|
|
712
|
+
tokensBefore: capacityRewrite.tokensBefore,
|
|
713
|
+
tokensAfter: capacityRewrite.tokensAfter,
|
|
714
|
+
},
|
|
715
|
+
capacityPressureRequestBoundary: 'scheduled-history-rewrite',
|
|
716
|
+
},
|
|
717
|
+
rewriteEvidence: ['fresh', 'aggregate', 'history', 'tail-trim'].map(component => {
|
|
718
|
+
const record = pipelineRewrites.find(candidate => candidate.component === component)
|
|
719
|
+
assert(record !== undefined, `installed Runtime lacks ${component} rewrite evidence`)
|
|
720
|
+
return {
|
|
721
|
+
component: record.component,
|
|
722
|
+
stage: record.stage,
|
|
723
|
+
reducer: record.reducer,
|
|
724
|
+
tokensBefore: record.tokensBefore,
|
|
725
|
+
tokensAfter: record.tokensAfter,
|
|
726
|
+
}
|
|
727
|
+
}),
|
|
728
|
+
customEvents: session.snapshotEvents().some(event => event.type === 'compaction/group-trim') ? 'present' : 'absent',
|
|
729
|
+
})}`)
|
|
730
|
+
} finally {
|
|
731
|
+
await ctx.fiber.dispose()
|
|
732
|
+
}
|