dsh-context-compression-improved 0.11.1 → 0.11.3

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 (311) hide show
  1. package/README.md +15 -110
  2. package/README.zh.md +14 -104
  3. package/THIRD_PARTY_NOTICES.md +25 -7
  4. package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +1 -1
  5. package/{packages/selector/lib → lib}/client.js +27 -10
  6. package/{packages/selector/lib → lib}/index.js +101 -0
  7. package/package.json +125 -112
  8. package/screenshots.json +3 -6
  9. package/.agents/plans/improve/checklist.md +0 -32
  10. package/.agents/plans/improve/findings.md +0 -102
  11. package/.agents/plans/improve/spec.md +0 -53
  12. package/.agents/plans/improve/tasks.md +0 -70
  13. package/.gitattributes +0 -2
  14. package/.githooks/pre-push +0 -37
  15. package/.github/workflows/ci.yml +0 -47
  16. package/CHANGELOG.de.md +0 -580
  17. package/CHANGELOG.es.md +0 -588
  18. package/CHANGELOG.fr.md +0 -576
  19. package/CHANGELOG.it.md +0 -577
  20. package/CHANGELOG.ja.md +0 -261
  21. package/CHANGELOG.ko.md +0 -254
  22. package/CHANGELOG.md +0 -557
  23. package/CHANGELOG.ru.md +0 -554
  24. package/CHANGELOG.zh.md +0 -247
  25. package/CONTRIBUTING.md +0 -22
  26. package/README.de.md +0 -96
  27. package/README.es.md +0 -96
  28. package/README.fr.md +0 -96
  29. package/README.it.md +0 -96
  30. package/README.ja.md +0 -102
  31. package/README.ko.md +0 -102
  32. package/README.ru.md +0 -96
  33. package/SECURITY.md +0 -18
  34. package/assets/board.png +0 -0
  35. package/assets/context.png +0 -0
  36. package/assets/dshfind-card.svg +0 -33
  37. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  38. package/docs/assets/context-compression-selector-settings.png +0 -0
  39. package/docs/compat-0.1.5-report.md +0 -77
  40. package/docs/installation.de.md +0 -104
  41. package/docs/installation.es.md +0 -104
  42. package/docs/installation.fr.md +0 -104
  43. package/docs/installation.it.md +0 -104
  44. package/docs/installation.ja.md +0 -78
  45. package/docs/installation.ko.md +0 -78
  46. package/docs/installation.md +0 -103
  47. package/docs/installation.ru.md +0 -104
  48. package/docs/installation.zh.md +0 -100
  49. package/docs/repair-log.md +0 -657
  50. package/docs/shallow-teaching-preset-template.md +0 -46
  51. package/eslint.config.js +0 -30
  52. package/packages/selector/LICENSE +0 -21
  53. package/packages/selector/README.md +0 -26
  54. package/packages/selector/README.zh.md +0 -24
  55. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  56. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  57. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  58. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  59. package/packages/selector/lib/style.css +0 -350
  60. package/packages/selector/package.json +0 -178
  61. package/packages/selector/screenshots.json +0 -3
  62. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -352
  63. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  64. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
  65. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  66. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  67. package/packages/selector/src/client/bridge-scope.ts +0 -125
  68. package/packages/selector/src/client/decode.ts +0 -68
  69. package/packages/selector/src/client/fab-pos.ts +0 -71
  70. package/packages/selector/src/client/index.ts +0 -438
  71. package/packages/selector/src/client/locales/de.ts +0 -167
  72. package/packages/selector/src/client/locales/es.ts +0 -167
  73. package/packages/selector/src/client/locales/fr.ts +0 -167
  74. package/packages/selector/src/client/locales/it.ts +0 -167
  75. package/packages/selector/src/client/locales/ja.ts +0 -167
  76. package/packages/selector/src/client/locales/ko.ts +0 -167
  77. package/packages/selector/src/client/locales/ru.ts +0 -167
  78. package/packages/selector/src/client/locales.ts +0 -334
  79. package/packages/selector/src/client/monitor-fab.ts +0 -445
  80. package/packages/selector/src/client/preset-options.ts +0 -88
  81. package/packages/selector/src/client/savings-card.tsx +0 -269
  82. package/packages/selector/src/client/scope-face.ts +0 -24
  83. package/packages/selector/src/client/settings-section.tsx +0 -156
  84. package/packages/selector/src/compat/host-generation.ts +0 -96
  85. package/packages/selector/src/compat/llm-messages.ts +0 -50
  86. package/packages/selector/src/compat/settings-lease.ts +0 -108
  87. package/packages/selector/src/compat/tool-result.ts +0 -91
  88. package/packages/selector/src/css-modules.d.ts +0 -6
  89. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  90. package/packages/selector/src/estimator-catalog.ts +0 -104
  91. package/packages/selector/src/index.ts +0 -890
  92. package/packages/selector/src/invariant.ts +0 -113
  93. package/packages/selector/src/preset-overlay.ts +0 -749
  94. package/packages/selector/src/profiles.ts +0 -554
  95. package/packages/selector/src/pruner/content.ts +0 -199
  96. package/packages/selector/src/pruner/session.ts +0 -97
  97. package/packages/selector/src/pruner/state.ts +0 -61
  98. package/packages/selector/src/pruner/tuning.ts +0 -23
  99. package/packages/selector/src/pruner/types.ts +0 -78
  100. package/packages/selector/src/pruner.ts +0 -3222
  101. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  102. package/packages/selector/src/runtime/audit.ts +0 -321
  103. package/packages/selector/src/runtime/config.ts +0 -887
  104. package/packages/selector/src/runtime/custom-policy.ts +0 -300
  105. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  106. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  107. package/packages/selector/src/runtime/display-prefs.ts +0 -98
  108. package/packages/selector/src/runtime/fold-router.ts +0 -143
  109. package/packages/selector/src/runtime/measurement.ts +0 -444
  110. package/packages/selector/src/runtime/monitor.ts +0 -341
  111. package/packages/selector/src/runtime/panel-command.ts +0 -213
  112. package/packages/selector/src/runtime/reducers.ts +0 -1755
  113. package/packages/selector/src/runtime/retrieve.ts +0 -505
  114. package/packages/selector/src/runtime/savings-integral.ts +0 -117
  115. package/packages/selector/src/runtime/savings-projection.ts +0 -229
  116. package/packages/selector/src/runtime/savings-verify.ts +0 -446
  117. package/packages/selector/src/runtime/savings.ts +0 -526
  118. package/packages/selector/src/runtime/sediment-card.ts +0 -126
  119. package/packages/selector/src/runtime/sediment-clock.ts +0 -87
  120. package/packages/selector/src/runtime/sediment-guard.ts +0 -136
  121. package/packages/selector/src/runtime/sediment-publish.ts +0 -144
  122. package/packages/selector/src/runtime/sediment-span.ts +0 -170
  123. package/packages/selector/src/runtime/sediment.ts +0 -209
  124. package/packages/selector/src/runtime/session-events.ts +0 -30
  125. package/packages/selector/src/runtime/session-file-decode.ts +0 -523
  126. package/packages/selector/src/runtime/shallow-tools.ts +0 -342
  127. package/packages/selector/src/runtime/stats-backfill.ts +0 -541
  128. package/packages/selector/src/runtime/stats-db.ts +0 -492
  129. package/packages/selector/src/runtime/stats-schema.ts +0 -123
  130. package/packages/selector/src/runtime/stats-sync.ts +0 -307
  131. package/packages/selector/src/runtime/summary-command.ts +0 -127
  132. package/packages/selector/src/runtime/tail-trim.ts +0 -177
  133. package/packages/selector/src/runtime/token-count.ts +0 -72
  134. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  135. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  136. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  137. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  138. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -82
  139. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  140. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  141. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  142. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  143. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  144. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -129
  145. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  146. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  147. package/packages/selector/src/runtime/tool-names.ts +0 -42
  148. package/packages/selector/src/runtime/toolclass.ts +0 -103
  149. package/packages/selector/src/runtime/triage/masks.ts +0 -128
  150. package/packages/selector/src/runtime/triage/shallow.ts +0 -132
  151. package/packages/selector/src/runtime/triage/signals.ts +0 -167
  152. package/packages/selector/src/runtime/triage/types.ts +0 -125
  153. package/packages/selector/src/runtime/types.ts +0 -396
  154. package/packages/selector/src/runtime/value.ts +0 -48
  155. package/packages/selector/src/settings-bridge.ts +0 -175
  156. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  157. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  158. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  159. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  160. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  161. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  162. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  163. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  164. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  165. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
  166. package/packages/selector/tests/fab-pos.client.spec.ts +0 -47
  167. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
  168. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
  169. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
  170. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
  171. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
  172. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
  173. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
  174. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
  175. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
  176. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
  177. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
  178. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
  179. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
  180. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
  181. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
  182. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  183. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  184. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  185. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  186. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  187. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  188. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  189. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -240
  190. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  191. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  192. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  193. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  194. package/packages/selector/tests/ptc-custom-write.client.spec.ts +0 -86
  195. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
  196. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  197. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  198. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  199. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  200. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  201. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  202. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  203. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  204. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  205. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  206. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  207. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  208. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  209. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
  210. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  211. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  212. package/packages/selector/tests/runtime/fold-router.spec.ts +0 -140
  213. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  214. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  215. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  216. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  217. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  218. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  219. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  220. package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
  221. package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
  222. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  223. package/packages/selector/tests/runtime/ptc-profile.spec.ts +0 -133
  224. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
  225. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  226. package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
  227. package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
  228. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  229. package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
  230. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  231. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  232. package/packages/selector/tests/runtime/sediment-card.spec.ts +0 -111
  233. package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
  234. package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
  235. package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
  236. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
  237. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
  238. package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
  239. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
  240. package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
  241. package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
  242. package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
  243. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  244. package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
  245. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  246. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +0 -135
  247. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  248. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
  249. package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -350
  250. package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
  251. package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
  252. package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
  253. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  254. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  255. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  256. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  257. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  258. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  259. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  260. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -121
  261. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  262. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  263. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  264. package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
  265. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  266. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  267. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  268. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  269. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  270. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  271. package/packages/selector/tsconfig.json +0 -11
  272. package/packages/selector/tsdown.client.config.ts +0 -102
  273. package/packages/selector/tsdown.config.ts +0 -20
  274. package/pnpm-workspace.yaml +0 -76
  275. package/scripts/capture-profile-baseline.mjs +0 -42
  276. package/scripts/cell-browser-e2e.mjs +0 -354
  277. package/scripts/generate-tokenizer-fixtures.py +0 -81
  278. package/scripts/generate-vision-fixtures.py +0 -208
  279. package/scripts/hosts.d.mts +0 -3
  280. package/scripts/hosts.mjs +0 -81
  281. package/scripts/packed-components-smoke.mjs +0 -763
  282. package/scripts/packed-install-e2e.mjs +0 -1346
  283. package/scripts/sediment-latency-report.mjs +0 -63
  284. package/scripts/sync-hosts.mjs +0 -174
  285. package/scripts/toolclass-corpus-replay.mjs +0 -281
  286. package/scripts/verify-release.mjs +0 -343
  287. package/tests/TEST_INVENTORY.md +0 -41
  288. package/tsconfig.base.json +0 -18
  289. package/tsconfig.json +0 -7
  290. package/tsconfig.tests.json +0 -15
  291. package/vitest.built.config.ts +0 -9
  292. package/vitest.config.ts +0 -54
  293. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  294. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  295. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  296. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  297. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  298. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  299. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  300. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  301. /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
  302. /package/{packages/selector/lib → lib}/client.d.ts +0 -0
  303. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  304. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  305. /package/{packages/selector/lib → lib}/invariant.js +0 -0
  306. /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
  307. /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
  308. /package/{packages/selector/lib → lib}/pruner.js +0 -0
  309. /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
  310. /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
  311. /package/{packages/selector/lib → lib}/tool-result.js +0 -0
@@ -1,199 +0,0 @@
1
- /**
2
- * Pure content-analysis functions extracted from ToolResultPruner.
3
- *
4
- * Every function here has ZERO `this` dependency — they receive all inputs
5
- * as explicit arguments. Grouped by natural cohesion (content blocks →
6
- * token counting → recovery helpers).
7
- *
8
- * @module dsh-context-compression-improved/pruner/content
9
- */
10
-
11
- import type { ContentBlock } from '@deepseek-ai/dsh-llm'
12
- import { RUNTIME_TOOL_NAMES } from '../runtime/tool-names.ts'
13
- import type {
14
- CompactionTokenView,
15
- ProviderMeasurementKey,
16
- TokenCount,
17
- } from '../runtime/measurement.ts'
18
- import { countExactCanonicalTextFields } from '../runtime/token-count.ts'
19
- import { codePointLength, PRUNE_MARKER } from '../runtime/config.ts'
20
- import type { PrunedEntry, PruneResult } from '../runtime/types.ts'
21
- import { RICH_BLOCK_PRESSURE_COST } from './tuning.ts'
22
-
23
- // ── Content-block predicates ────────────────────────────────────────────
24
-
25
- function onlyTextBlock(blocks: readonly ContentBlock[]): Extract<ContentBlock, { type: 'text' }> | null {
26
- return blocks.length === 1 && blocks[0]?.type === 'text' ? blocks[0] : null
27
- }
28
-
29
- function onlyTextBlocks(blocks: readonly ContentBlock[]): readonly Extract<ContentBlock, { type: 'text' }>[] | null {
30
- return blocks.every((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')
31
- ? blocks
32
- : null
33
- }
34
-
35
- // ── Token counting ──────────────────────────────────────────────────────
36
-
37
- function countToolContent(blocks: readonly ContentBlock[], view: CompactionTokenView): TokenCount {
38
- const text = onlyTextBlocks(blocks)
39
- if (text === null) return unavailableCount('tool result contains unsupported rich content')
40
- return countExactCanonicalTextFields(
41
- text.map(block => block.text),
42
- candidate => view.countCanonicalText(candidate),
43
- 'tool result replacement',
44
- )
45
- }
46
-
47
- function exactTokens(count: TokenCount): number | undefined {
48
- return count.kind === 'exact-tokenizer' ? count.tokens : undefined
49
- }
50
-
51
- // ── Provider measurement key comparison ─────────────────────────────────
52
-
53
- function sameProviderMeasurementKey(
54
- left: Readonly<ProviderMeasurementKey>,
55
- right: Readonly<ProviderMeasurementKey>,
56
- ): boolean {
57
- return left.provider === right.provider
58
- && left.baseUrlClass === right.baseUrlClass
59
- && left.apiRoute === right.apiRoute
60
- && left.modelId === right.modelId
61
- && left.requestTemplateRevision === right.requestTemplateRevision
62
- && left.tokenizerRevision === right.tokenizerRevision
63
- && left.modality === right.modality
64
- }
65
-
66
- // ── Token helpers ───────────────────────────────────────────────────────
67
-
68
- function unavailableCount(reason: string): TokenCount {
69
- return Object.freeze({ kind: 'unavailable', reason })
70
- }
71
-
72
- // ── Recovery markers ────────────────────────────────────────────────────
73
-
74
- function recoveryMarker(sourceRef: string, label: string, startLine?: number): string {
75
- const hint = startLine === undefined
76
- ? `use ${RUNTIME_TOOL_NAMES.RETRIEVE} with a query or narrow start_line/max_lines if needed (avoid re-reading the whole result)`
77
- : `retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${sourceRef}","start_line":${String(startLine)},"max_lines":80})`
78
- return `\n\n[... ${label}; source=${sourceRef}; ${hint} ...]\n\n`
79
- }
80
-
81
- // ── Content measurement ─────────────────────────────────────────────────
82
-
83
- /**
84
- * Measure text content in Unicode code points; non-text blocks cost zero.
85
- * @param blocks - tool-result content to measure.
86
- * @returns total Unicode code points across text blocks.
87
- */
88
- function measureContent(blocks: readonly ContentBlock[]): number {
89
- let chars = 0
90
- for (const block of blocks) {
91
- if (block.type === 'text') chars += codePointLength(block.text)
92
- }
93
- return chars
94
- }
95
-
96
- function pressureCost(blocks: readonly ContentBlock[]): number {
97
- let cost = 0
98
- for (const block of blocks) {
99
- switch (block.type) {
100
- case 'text':
101
- case 'reasoning':
102
- cost += codePointLength(block.text)
103
- break
104
- case 'tool-call':
105
- cost += RICH_BLOCK_PRESSURE_COST
106
- + codePointLength(block.name)
107
- + codePointLength(block.arguments)
108
- break
109
- default: {
110
- // ContentBlockMap is merge-extensible. Unknown model-visible blocks
111
- // scale with their durable JSON payload instead of receiving a fixed
112
- // token that a large provider block could bypass.
113
- const serialized = JSON.stringify(block)
114
- cost += Math.max(RICH_BLOCK_PRESSURE_COST, codePointLength(serialized))
115
- }
116
- }
117
- }
118
- return cost
119
- }
120
-
121
- // ── Native content pruning ──────────────────────────────────────────────
122
-
123
- function nativePruneContent(
124
- blocks: readonly ContentBlock[],
125
- thresholdChars: number,
126
- headChars: number,
127
- tailChars: number,
128
- marker: string | ((startLine: number) => string) = PRUNE_MARKER,
129
- ): ContentBlock[] | null {
130
- const totalChars = measureContent(blocks)
131
- if (totalChars <= thresholdChars) return null
132
- const markerChars = codePointLength(typeof marker === 'function' ? marker(1) : marker)
133
- const safeHead = Math.max(0, Math.min(headChars, thresholdChars - markerChars))
134
- const safeTail = Math.max(0, Math.min(tailChars, thresholdChars - markerChars - safeHead))
135
- const removedStart = safeHead
136
- const removedEnd = totalChars - safeTail
137
- const pruned: ContentBlock[] = []
138
- let consumed = 0
139
- let markerInserted = false
140
- // '\n' count in the RAW event text before the current block (retrieve scans
141
- // the original event; blocks are joined with '\n'). Line numbers therefore
142
- // never depend on what the pruning removed.
143
- let newlinesBefore = 0
144
- for (const block of blocks) {
145
- if (block.type !== 'text') {
146
- pruned.push(block)
147
- newlinesBefore += 1
148
- continue
149
- }
150
- const points = Array.from(block.text)
151
- const blockStart = consumed
152
- const blockEnd = blockStart + points.length
153
- const headEnd = Math.min(points.length, Math.max(0, removedStart - blockStart))
154
- const tailStart = Math.min(points.length, Math.max(0, removedEnd - blockStart))
155
- const intersectsRemoved = blockStart < removedEnd && blockEnd > removedStart
156
- // The elided region starts on the event line after the retained head.
157
- const headText = points.slice(0, headEnd).join('')
158
- const insertion = intersectsRemoved && !markerInserted && typeof marker === 'function'
159
- ? marker(1 + newlinesBefore + headText.split('\n').length - 1)
160
- : intersectsRemoved && !markerInserted ? marker : ''
161
- if (insertion !== '') markerInserted = true
162
- const text = points.slice(0, headEnd).join('') + insertion + points.slice(tailStart).join('')
163
- if (text !== '') pruned.push({ ...block, text })
164
- newlinesBefore += block.text.split('\n').length - 1 + 1
165
- consumed = blockEnd
166
- }
167
- if (!markerInserted) return null
168
- const charsAfter = measureContent(pruned)
169
- return charsAfter <= thresholdChars && charsAfter < totalChars ? pruned : null
170
- }
171
-
172
- // ── Result aggregation ──────────────────────────────────────────────────
173
-
174
- function summarize(entries: readonly PrunedEntry[]): PruneResult {
175
- return {
176
- pruned: entries,
177
- charsRemoved: entries.reduce((sum, entry) => sum + entry.charsBefore - entry.charsAfter, 0),
178
- tokensRemoved: entries.reduce((sum, entry) => sum + entry.tokensBefore - entry.tokensAfter, 0),
179
- }
180
- }
181
-
182
- function emptyResult(): PruneResult {
183
- return { pruned: [], charsRemoved: 0, tokensRemoved: 0 }
184
- }
185
-
186
- export {
187
- onlyTextBlock,
188
- onlyTextBlocks,
189
- countToolContent,
190
- exactTokens,
191
- sameProviderMeasurementKey,
192
- unavailableCount,
193
- recoveryMarker,
194
- summarize,
195
- emptyResult,
196
- measureContent,
197
- pressureCost,
198
- nativePruneContent,
199
- }
@@ -1,97 +0,0 @@
1
- /**
2
- * Pure session-scanning functions extracted from ToolResultPruner.
3
- *
4
- * Every function here has ZERO `this` dependency — they receive all inputs
5
- * as explicit arguments and only read session events.
6
- *
7
- * @module dsh-context-compression-improved/pruner/session
8
- */
9
-
10
- import type { Session } from '@deepseek-ai/dsh-session'
11
- import { sessionEvents } from '../runtime/session-events.ts'
12
- import { deepSeekV4TokenizerForModel } from '../deepseek-v4-tokenizer.ts'
13
- import { viewToolResult } from '../compat/tool-result.ts'
14
- import type { SnapshotCandidate, PlannedReplacement, HistoryPlanOutcome } from './types.ts'
15
-
16
- /** Check whether the session currently has an open (unterminated) turn. */
17
- function hasOpenTurn(session: Session): boolean {
18
- let open = false
19
- for (const event of sessionEvents(session)) {
20
- if (event.type === 'turn/start') open = true
21
- else if (event.type === 'turn/end') open = false
22
- }
23
- return open
24
- }
25
-
26
- /** Walk the tool-result source chain to find the root result seq. */
27
- function rootToolResultSeq(session: Session, seq: number): number {
28
- const events = sessionEvents(session)
29
- let current = seq
30
- const seen = new Set<number>()
31
- while (!seen.has(current)) {
32
- seen.add(current)
33
- const event = events[current]
34
- if (event?.type !== 'tool/result' || typeof event.surfaceOp !== 'object') return current
35
- const previous = event.sourceEventSeqs?.[0]
36
- if (previous === undefined) return current
37
- current = previous
38
- }
39
- return seq
40
- }
41
-
42
- /** Build a session:// event reference string for a given seq. */
43
- function sourceRef(session: Session, seq: number): string {
44
- return `session://${session.id}/event/${String(seq)}`
45
- }
46
-
47
- /** Find the latest completed step number for a given turn. */
48
- function latestCompletedToolStep(session: Session, turn: number): number | undefined {
49
- let latest: number | undefined
50
- for (const event of sessionEvents(session)) {
51
- if (event.type === 'step/end' && event.data.turn === turn) latest = event.data.step
52
- }
53
- return latest
54
- }
55
-
56
- /** Routed provider/model when the durable request header names one route. */
57
- function routeAuditFact(session: Session): { provider: string, model: string } | undefined {
58
- const header = session.requestHeader()?.config
59
- if (header === undefined || header.provider.length === 0 || header.model.length === 0) return undefined
60
- return { provider: header.provider, model: header.model }
61
- }
62
-
63
- /** Bundled tokenizer identity for one route, when the route is eligible. */
64
- function tokenizerAuditFact(route: { provider: string, model: string }): { tokenizer: { repository: string, revision: string } } {
65
- // Reuse the measurement eligibility boundary: a DeepSeek model id routed
66
- // through another provider never used the bundled tokenizer.
67
- const eligible = route.provider === 'deepseek' || route.provider === 'deepseek-official'
68
- const identity = eligible ? deepSeekV4TokenizerForModel(route.model)?.countText('') : undefined
69
- if (identity?.kind === 'exact-tokenizer') {
70
- return { tokenizer: { repository: identity.tokenizerId, revision: identity.tokenizerRevision } }
71
- }
72
- return { tokenizer: { repository: 'unavailable', revision: 'unavailable' } }
73
- }
74
-
75
- /** Check whether a snapshot candidate represents an error result. */
76
- function isError(candidate: SnapshotCandidate): boolean {
77
- // 0.1.7-rc.2: tool results are first-class `tool`-role messages — `isError`
78
- // moved from the result block onto the message itself. The generation-
79
- // gated triple view resolves the axis (legacy envelope: the wrapper block).
80
- return viewToolResult(candidate.event.data.message).isError || candidate.event.data.error !== undefined
81
- }
82
-
83
- /** Wrap a plan list into a HistoryPlanOutcome. */
84
- function historyOutcome(plans: readonly PlannedReplacement[]): HistoryPlanOutcome {
85
- return { kind: 'planned', plans: [...plans] }
86
- }
87
-
88
- export {
89
- hasOpenTurn,
90
- rootToolResultSeq,
91
- sourceRef,
92
- latestCompletedToolStep,
93
- routeAuditFact,
94
- tokenizerAuditFact,
95
- isError,
96
- historyOutcome,
97
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Consolidated per-session mutable state for {@link ToolResultPruner}.
3
- *
4
- * Every field is a WeakMap keyed by Session, keeping the service
5
- * stateless across sessions and safe under GC.
6
- */
7
-
8
- import type { Session } from '@deepseek-ai/dsh-session'
9
- import type { DedupeTable } from '../runtime/tokenpilot/dedup.ts'
10
- import type { EstimatorFailures } from '../runtime/tokenpilot/estimator.ts'
11
- import type { SideChannel } from '../runtime/tokenpilot/sidechannel.ts'
12
- import type { PendingIntentFold } from '../runtime/tokenpilot/intent-fold.ts'
13
- import type {
14
- ContextCompressionSettings,
15
- ResolvedConfig,
16
- } from '../runtime/types.ts'
17
-
18
- /** Mutable per-session state bag used inside {@link ToolResultPruner}. */
19
- export interface PrunerState {
20
- /** Resolved immutable deployment configuration. */
21
- readonly config: ResolvedConfig
22
-
23
- /** Complete canonical setting document frozen when each Session first reaches this root service. */
24
- readonly sessionSettings: WeakMap<Session, ContextCompressionSettings>
25
- /** Original result seqs whose first-exposure KEEP/REDUCE decision has committed. */
26
- readonly firstExposure: WeakMap<Session, Set<number>>
27
- /** Result seqs permanently exempt from further reduction (recovery outputs and registered equivalents). */
28
- readonly recoveryExemptions: WeakMap<Session, Set<number>>
29
- /** Per-session canonical-content hash index backing tokenpilot-inspired dedupe. */
30
- readonly dedupeTables: WeakMap<Session, DedupeTable>
31
- /** Advisory estimator verdicts consumed by the read-state classification. */
32
- readonly estimatorVerdicts: WeakMap<Session, Map<number, boolean>>
33
- /** Per-session estimator failure backoff state. */
34
- readonly estimatorFailures: WeakMap<Session, EstimatorFailures>
35
- /** Runtime prerequisite warnings deduplicated per Session and failure key. */
36
- readonly warnedFailures: WeakMap<Session, Set<string>>
37
- /** Last Adaptive postflight attempt emitted per Session; keeps diagnostics bounded and independent. */
38
- readonly postflightDiagnostics: WeakMap<Session, string>
39
- /** Current pre-step chain identity, shared by this producer and downstream compaction-basic. */
40
- readonly activeRequestBoundaries: WeakMap<Session, object>
41
- /** Boundary identity that already attempted one fully preflighted TailTrim publication. */
42
- readonly tailTrimBoundaryAttempts: WeakMap<Session, object>
43
- /** Last effective policy audit key emitted for each Session. */
44
- readonly policyResolutionAudits: WeakMap<Session, string>
45
- /** Last observed turn index per Session: the monotonic clock for advisory records. */
46
- readonly turnClocks: WeakMap<Session, number>
47
- /** Estimator-reported remaining turns Ŝ per Session; advisory only. */
48
- readonly estimatorRemainingTurns: WeakMap<Session, number>
49
- /** Per-session advisor side channel, constructed once with the advisor overrides. */
50
- readonly advisorChannels: WeakMap<Session, SideChannel>
51
- /** Per-session intent-summary writer channel, constructed once with the estimator channel mode. */
52
- readonly intentChannels: WeakMap<Session, SideChannel>
53
- /** Sessions whose savings ledger has been seeded from the session-log projection. */
54
- readonly projectedSavings: WeakSet<Session>
55
- /** Staged intent fold awaiting the next pressure round (at most one per session). */
56
- readonly pendingIntentFolds: WeakMap<Session, PendingIntentFold>
57
- /** Landed intent-fold seqs: fold-once, never reconsidered by any later stage. */
58
- readonly intentFoldedSeqs: WeakMap<Session, Set<number>>
59
- /** Live-surface tokens when the last intent fold landed (growth-gate baseline). */
60
- readonly intentBaselines: WeakMap<Session, number>
61
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Tuning constants and pure helper functions for the context-compression pruner.
3
- *
4
- * These are stateless, session-independent, and safe to import from any
5
- * pruner sub-module without creating circular dependencies.
6
- */
7
-
8
- /** Line-feed character used as the canonical newline separator. */
9
- export const BS = String.fromCharCode(10)
10
-
11
- /** Count the lines present in the original but absent from the replacement. */
12
- export function countOmittedLines(original: string, replacement: string): number | undefined {
13
- const originalLines = original.split(BS).length
14
- const replacementLines = replacement.split(BS).length
15
- const omitted = originalLines - replacementLines
16
- return omitted > 0 ? omitted : undefined
17
- }
18
-
19
- /** Minimum token-equivalent cost charged for every rich content block. */
20
- export const RICH_BLOCK_PRESSURE_COST = 256
21
-
22
- /** Routed-context utilization required before capacity-pressure History may age sent history. */
23
- export const CAPACITY_PRESSURE_RATIO = 0.7
@@ -1,78 +0,0 @@
1
- /**
2
- * Pruner-internal type definitions.
3
- *
4
- * These types are private to the pruner module tree and are NOT re-exported
5
- * through the package's public API.
6
- */
7
-
8
- import type { ContentBlock } from '@deepseek-ai/dsh-llm'
9
- import type { SessionEvent } from '@deepseek-ai/dsh-session'
10
- import type { TokenCount } from '../runtime/measurement.ts'
11
- import type { CompressionAuditComponent } from '../runtime/audit.ts'
12
- import type { HistoryMode, PruneStage } from '../runtime/types.ts'
13
-
14
- export interface ToolCallInfo {
15
- readonly name: string
16
- readonly arguments: string
17
- }
18
-
19
- export interface SnapshotCandidate {
20
- readonly seq: number
21
- readonly event: SessionEvent<'tool/result'>
22
- readonly call: ToolCallInfo
23
- /** Authoritative same-revision exact canonical content count (telemetry only). */
24
- readonly count: TokenCount
25
- /** Same-revision legacy heuristic price used only by bounded projections. */
26
- readonly shadowedHeuristicTokenCount: number
27
- /**
28
- * Authoritative decision metric: character pressure in Unicode code points.
29
- * Every eligibility and acceptance gate decides on this number so the plugin
30
- * never depends on the routed model id owning a bundled exact tokenizer;
31
- * `count` is retained as diagnostic telemetry only.
32
- */
33
- readonly characterPressure: number
34
- }
35
-
36
- export interface PlannedReplacement {
37
- readonly candidate: SnapshotCandidate
38
- readonly content: ContentBlock[]
39
- readonly sourceSeq: number
40
- readonly reducer: string
41
- readonly stage: PruneStage
42
- readonly component: CompressionAuditComponent
43
- readonly historyMode?: HistoryMode
44
- readonly charsBefore: number
45
- readonly charsAfter: number
46
- readonly tokensBefore: number
47
- readonly tokensAfter: number
48
- /**
49
- * Which measurement produced this plan's decision: 'exact-tokenizer' when
50
- * both sides of the reduction carry one bundled tokenizer identity,
51
- * 'characters' when the proof ran on code points alone.
52
- */
53
- readonly measurementBasis: 'exact-tokenizer' | 'characters'
54
- readonly tokenizerId: string
55
- readonly tokenizerRevision: string
56
- /**
57
- * Original-event lines the reducer elided (task_4c/G7 telemetry, from
58
- * `ReducerOutput.elidedLines`). Rides the rewrite AUDIT record only — it is
59
- * never printed into replacement content.
60
- */
61
- readonly elidedLines?: number
62
- }
63
-
64
- /**
65
- * Discriminated History planning outcome: every skip path carries its own
66
- * reason instead of collapsing into one merged "no eligible minimum reclaim"
67
- * audit, so operators can tell a protected working set from an unreachable
68
- * reclaim target. The former 'exact-tokenizer-unavailable' member is gone:
69
- * planning decides on the character basis and can no longer refuse for a
70
- * missing exact count.
71
- */
72
- export type HistoryPlanOutcome =
73
- | { readonly kind: 'planned', readonly plans: PlannedReplacement[] }
74
- | { readonly kind: 'below-profile-trigger' }
75
- | { readonly kind: 'no-safe-candidates' }
76
- | { readonly kind: 'protected-working-set' }
77
- | { readonly kind: 'insufficient-reclaim', readonly reclaim: number, readonly required: number }
78
- | { readonly kind: 'cannot-reach-deadline-target', readonly reclaim: number, readonly required: number }