dsh-context-compression-improved 0.11.0 → 0.11.2

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 (310) 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} +2 -2
  5. package/{packages/selector/lib → lib}/index.js +101 -0
  6. package/package.json +129 -116
  7. package/screenshots.json +3 -6
  8. package/.agents/plans/improve/checklist.md +0 -32
  9. package/.agents/plans/improve/findings.md +0 -102
  10. package/.agents/plans/improve/spec.md +0 -53
  11. package/.agents/plans/improve/tasks.md +0 -70
  12. package/.gitattributes +0 -2
  13. package/.githooks/pre-push +0 -37
  14. package/.github/workflows/ci.yml +0 -47
  15. package/CHANGELOG.de.md +0 -580
  16. package/CHANGELOG.es.md +0 -588
  17. package/CHANGELOG.fr.md +0 -576
  18. package/CHANGELOG.it.md +0 -577
  19. package/CHANGELOG.ja.md +0 -261
  20. package/CHANGELOG.ko.md +0 -254
  21. package/CHANGELOG.md +0 -557
  22. package/CHANGELOG.ru.md +0 -554
  23. package/CHANGELOG.zh.md +0 -247
  24. package/CONTRIBUTING.md +0 -22
  25. package/README.de.md +0 -96
  26. package/README.es.md +0 -96
  27. package/README.fr.md +0 -96
  28. package/README.it.md +0 -96
  29. package/README.ja.md +0 -102
  30. package/README.ko.md +0 -102
  31. package/README.ru.md +0 -96
  32. package/SECURITY.md +0 -18
  33. package/assets/board.png +0 -0
  34. package/assets/context.png +0 -0
  35. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  36. package/docs/assets/context-compression-selector-settings.png +0 -0
  37. package/docs/compat-0.1.5-report.md +0 -77
  38. package/docs/installation.de.md +0 -104
  39. package/docs/installation.es.md +0 -104
  40. package/docs/installation.fr.md +0 -104
  41. package/docs/installation.it.md +0 -104
  42. package/docs/installation.ja.md +0 -78
  43. package/docs/installation.ko.md +0 -78
  44. package/docs/installation.md +0 -103
  45. package/docs/installation.ru.md +0 -104
  46. package/docs/installation.zh.md +0 -100
  47. package/docs/repair-log.md +0 -657
  48. package/docs/shallow-teaching-preset-template.md +0 -46
  49. package/eslint.config.js +0 -30
  50. package/packages/selector/LICENSE +0 -21
  51. package/packages/selector/README.md +0 -26
  52. package/packages/selector/README.zh.md +0 -24
  53. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  54. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  55. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  56. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  57. package/packages/selector/lib/style.css +0 -350
  58. package/packages/selector/package.json +0 -178
  59. package/packages/selector/screenshots.json +0 -3
  60. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -352
  61. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  62. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
  63. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  64. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  65. package/packages/selector/src/client/bridge-scope.ts +0 -125
  66. package/packages/selector/src/client/decode.ts +0 -68
  67. package/packages/selector/src/client/fab-pos.ts +0 -71
  68. package/packages/selector/src/client/index.ts +0 -438
  69. package/packages/selector/src/client/locales/de.ts +0 -167
  70. package/packages/selector/src/client/locales/es.ts +0 -167
  71. package/packages/selector/src/client/locales/fr.ts +0 -167
  72. package/packages/selector/src/client/locales/it.ts +0 -167
  73. package/packages/selector/src/client/locales/ja.ts +0 -167
  74. package/packages/selector/src/client/locales/ko.ts +0 -167
  75. package/packages/selector/src/client/locales/ru.ts +0 -167
  76. package/packages/selector/src/client/locales.ts +0 -334
  77. package/packages/selector/src/client/monitor-fab.ts +0 -445
  78. package/packages/selector/src/client/preset-options.ts +0 -88
  79. package/packages/selector/src/client/savings-card.tsx +0 -269
  80. package/packages/selector/src/client/scope-face.ts +0 -24
  81. package/packages/selector/src/client/settings-section.tsx +0 -156
  82. package/packages/selector/src/compat/host-generation.ts +0 -96
  83. package/packages/selector/src/compat/llm-messages.ts +0 -50
  84. package/packages/selector/src/compat/settings-lease.ts +0 -108
  85. package/packages/selector/src/compat/tool-result.ts +0 -91
  86. package/packages/selector/src/css-modules.d.ts +0 -6
  87. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  88. package/packages/selector/src/estimator-catalog.ts +0 -104
  89. package/packages/selector/src/index.ts +0 -890
  90. package/packages/selector/src/invariant.ts +0 -113
  91. package/packages/selector/src/preset-overlay.ts +0 -749
  92. package/packages/selector/src/profiles.ts +0 -554
  93. package/packages/selector/src/pruner/content.ts +0 -199
  94. package/packages/selector/src/pruner/session.ts +0 -97
  95. package/packages/selector/src/pruner/state.ts +0 -61
  96. package/packages/selector/src/pruner/tuning.ts +0 -23
  97. package/packages/selector/src/pruner/types.ts +0 -78
  98. package/packages/selector/src/pruner.ts +0 -3222
  99. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  100. package/packages/selector/src/runtime/audit.ts +0 -321
  101. package/packages/selector/src/runtime/config.ts +0 -887
  102. package/packages/selector/src/runtime/custom-policy.ts +0 -300
  103. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  104. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  105. package/packages/selector/src/runtime/display-prefs.ts +0 -98
  106. package/packages/selector/src/runtime/fold-router.ts +0 -143
  107. package/packages/selector/src/runtime/measurement.ts +0 -444
  108. package/packages/selector/src/runtime/monitor.ts +0 -341
  109. package/packages/selector/src/runtime/panel-command.ts +0 -213
  110. package/packages/selector/src/runtime/reducers.ts +0 -1755
  111. package/packages/selector/src/runtime/retrieve.ts +0 -505
  112. package/packages/selector/src/runtime/savings-integral.ts +0 -117
  113. package/packages/selector/src/runtime/savings-projection.ts +0 -229
  114. package/packages/selector/src/runtime/savings-verify.ts +0 -446
  115. package/packages/selector/src/runtime/savings.ts +0 -526
  116. package/packages/selector/src/runtime/sediment-card.ts +0 -126
  117. package/packages/selector/src/runtime/sediment-clock.ts +0 -87
  118. package/packages/selector/src/runtime/sediment-guard.ts +0 -136
  119. package/packages/selector/src/runtime/sediment-publish.ts +0 -144
  120. package/packages/selector/src/runtime/sediment-span.ts +0 -170
  121. package/packages/selector/src/runtime/sediment.ts +0 -209
  122. package/packages/selector/src/runtime/session-events.ts +0 -30
  123. package/packages/selector/src/runtime/session-file-decode.ts +0 -523
  124. package/packages/selector/src/runtime/shallow-tools.ts +0 -342
  125. package/packages/selector/src/runtime/stats-backfill.ts +0 -541
  126. package/packages/selector/src/runtime/stats-db.ts +0 -492
  127. package/packages/selector/src/runtime/stats-schema.ts +0 -123
  128. package/packages/selector/src/runtime/stats-sync.ts +0 -307
  129. package/packages/selector/src/runtime/summary-command.ts +0 -127
  130. package/packages/selector/src/runtime/tail-trim.ts +0 -177
  131. package/packages/selector/src/runtime/token-count.ts +0 -72
  132. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  133. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  134. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  135. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  136. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -82
  137. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  138. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  139. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  140. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  141. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  142. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -129
  143. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  144. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  145. package/packages/selector/src/runtime/tool-names.ts +0 -42
  146. package/packages/selector/src/runtime/toolclass.ts +0 -103
  147. package/packages/selector/src/runtime/triage/masks.ts +0 -128
  148. package/packages/selector/src/runtime/triage/shallow.ts +0 -132
  149. package/packages/selector/src/runtime/triage/signals.ts +0 -167
  150. package/packages/selector/src/runtime/triage/types.ts +0 -125
  151. package/packages/selector/src/runtime/types.ts +0 -396
  152. package/packages/selector/src/runtime/value.ts +0 -48
  153. package/packages/selector/src/settings-bridge.ts +0 -175
  154. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  155. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  156. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  157. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  158. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  159. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  160. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  161. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  162. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  163. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
  164. package/packages/selector/tests/fab-pos.client.spec.ts +0 -47
  165. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
  166. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
  167. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
  168. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
  169. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
  170. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
  171. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
  172. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
  173. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
  174. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
  175. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
  176. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
  177. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
  178. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
  179. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
  180. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  181. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  182. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  183. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  184. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  185. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  186. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  187. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -240
  188. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  189. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  190. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  191. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  192. package/packages/selector/tests/ptc-custom-write.client.spec.ts +0 -86
  193. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
  194. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  195. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  196. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  197. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  198. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  199. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  200. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  201. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  202. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  203. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  204. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  205. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  206. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  207. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
  208. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  209. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  210. package/packages/selector/tests/runtime/fold-router.spec.ts +0 -140
  211. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  212. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  213. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  214. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  215. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  216. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  217. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  218. package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
  219. package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
  220. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  221. package/packages/selector/tests/runtime/ptc-profile.spec.ts +0 -133
  222. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
  223. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  224. package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
  225. package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
  226. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  227. package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
  228. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  229. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  230. package/packages/selector/tests/runtime/sediment-card.spec.ts +0 -111
  231. package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
  232. package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
  233. package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
  234. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
  235. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
  236. package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
  237. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
  238. package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
  239. package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
  240. package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
  241. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  242. package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
  243. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  244. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +0 -135
  245. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  246. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
  247. package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -350
  248. package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
  249. package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
  250. package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
  251. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  252. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  253. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  254. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  255. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  256. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  257. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  258. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -121
  259. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  260. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  261. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  262. package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
  263. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  264. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  265. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  266. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  267. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  268. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  269. package/packages/selector/tsconfig.json +0 -11
  270. package/packages/selector/tsdown.client.config.ts +0 -102
  271. package/packages/selector/tsdown.config.ts +0 -20
  272. package/pnpm-workspace.yaml +0 -76
  273. package/scripts/capture-profile-baseline.mjs +0 -42
  274. package/scripts/cell-browser-e2e.mjs +0 -354
  275. package/scripts/generate-tokenizer-fixtures.py +0 -81
  276. package/scripts/generate-vision-fixtures.py +0 -208
  277. package/scripts/hosts.d.mts +0 -3
  278. package/scripts/hosts.mjs +0 -79
  279. package/scripts/packed-components-smoke.mjs +0 -763
  280. package/scripts/packed-install-e2e.mjs +0 -1346
  281. package/scripts/sediment-latency-report.mjs +0 -63
  282. package/scripts/sync-hosts.mjs +0 -174
  283. package/scripts/toolclass-corpus-replay.mjs +0 -281
  284. package/scripts/verify-release.mjs +0 -343
  285. package/tests/TEST_INVENTORY.md +0 -41
  286. package/tsconfig.base.json +0 -18
  287. package/tsconfig.json +0 -7
  288. package/tsconfig.tests.json +0 -15
  289. package/vitest.built.config.ts +0 -9
  290. package/vitest.config.ts +0 -54
  291. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  292. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  293. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  294. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  295. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  296. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  297. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  298. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  299. /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
  300. /package/{packages/selector/lib → lib}/client.d.ts +0 -0
  301. /package/{packages/selector/lib → lib}/client.js +0 -0
  302. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  303. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  304. /package/{packages/selector/lib → lib}/invariant.js +0 -0
  305. /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
  306. /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
  307. /package/{packages/selector/lib → lib}/pruner.js +0 -0
  308. /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
  309. /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
  310. /package/{packages/selector/lib → lib}/tool-result.js +0 -0
@@ -1,241 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { codePointLength } from '../../src/runtime/config.ts'
3
- import {
4
- documentSectionSummaries,
5
- reduceFreshToolResult,
6
- searchNodeSummaries,
7
- type ReducerInput,
8
- } from '../../src/runtime/reducers.ts'
9
- import {
10
- buildRankUserPrompt,
11
- mergeRanking,
12
- parseRanking,
13
- rankNodes,
14
- sideChannelGate,
15
- type RankedNode,
16
- } from '../../src/runtime/tokenpilot/sidechannel.ts'
17
-
18
- const SOURCE_REF = 'session://s1/event/9'
19
-
20
- function input(text: string, budgetChars = 4_000): ReducerInput {
21
- return {
22
- toolName: 'grep_search',
23
- argumentsText: '{"pattern":"config"}',
24
- text,
25
- budgetChars,
26
- sourceRef: SOURCE_REF,
27
- isError: false,
28
- }
29
- }
30
-
31
- function stubChannel(answer: string | undefined, calls: { count: number }): Pick<{ ask: unknown }, never> & {
32
- ask: (request: { system: string, user: string, signal: AbortSignal }) => Promise<string | undefined>
33
- askAudited: (request: { system: string, user: string, signal: AbortSignal }) => Promise<{ text?: string, audit: { ok: boolean, latencyMs: number } }>
34
- identity: () => string | undefined
35
- } {
36
- return {
37
- async ask(request) {
38
- calls.count += 1
39
- void request
40
- return answer
41
- },
42
- async askAudited(request) {
43
- const text = await this.ask(request)
44
- return { ...(text === undefined ? {} : { text }), audit: { ok: text !== undefined, latencyMs: 1 } }
45
- },
46
- identity: () => 'stub',
47
- }
48
- }
49
-
50
- describe('rank parsing and merging (TS4)', () => {
51
- it('keeps only valid identifiers in returned order', () => {
52
- const ranked = parseRanking('b.ts, junk, a.ts, b.ts', new Set(['a.ts', 'b.ts']))
53
- expect(ranked).toEqual(['b.ts', 'a.ts'])
54
- })
55
- it('resolves undefined for empty or garbage answers (fail-open)', () => {
56
- expect(parseRanking(undefined, new Set(['a.ts']))).toBeUndefined()
57
- expect(parseRanking(' ', new Set(['a.ts']))).toBeUndefined()
58
- expect(parseRanking('I cannot rank these files', new Set(['a.ts']))).toBeUndefined()
59
- })
60
- it('appends unmentioned nodes in their original order (existence intact)', () => {
61
- const nodes = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]
62
- expect(mergeRanking(nodes, ['c'])).toEqual([{ id: 'c' }, { id: 'a' }, { id: 'b' }])
63
- expect(mergeRanking(nodes, undefined)).toEqual(nodes)
64
- })
65
- })
66
-
67
- describe('cost gate (R-10)', () => {
68
- it('does not call when everything fits or there is a single node', () => {
69
- expect(sideChannelGate(true, 500)).toBe(false)
70
- expect(sideChannelGate(false, 1)).toBe(false)
71
- expect(sideChannelGate(false, 2)).toBe(true)
72
- })
73
- })
74
-
75
- describe('node summaries (SC8: samples ride with identifiers)', () => {
76
- it('search summaries carry path, count, and one content line', () => {
77
- const text = ['a.ts:1: alpha config', 'a.ts:2: beta', 'b.ts:7: gamma'].join('\n')
78
- const nodes = searchNodeSummaries(text)
79
- expect(nodes).toHaveLength(2)
80
- const a = nodes.find(node => node.id === 'a.ts')!
81
- expect(a.count).toBe(2)
82
- expect(a.sample).toContain('alpha config')
83
- })
84
- it('document summaries carry heading, mass, and the first content line (not only titles)', () => {
85
- const text = [
86
- '# Guide',
87
- 'Intro sentence everyone should read.',
88
- '## Configuration',
89
- ...Array.from({ length: 20 }, (_, i) => `config line ${String(i)}`),
90
- ].join('\n')
91
- const sections = documentSectionSummaries(text)
92
- expect(sections).toHaveLength(2)
93
- const config = sections.find(section => section.id === 'Configuration')!
94
- expect(config.level).toBe(2)
95
- expect(config.chars).toBeGreaterThan(100)
96
- expect(config.sample).toContain('config line 0')
97
- })
98
- it('the rank prompt embeds query, reasoning, and samples (AD11 intent carrier)', () => {
99
- const nodes: RankedNode[] = [{ id: 'a.ts', detail: '2 hits', sample: 'alpha config line' }]
100
- const prompt = buildRankUserPrompt(nodes, 'find loading config', 'the user wants the config loader')
101
- expect(prompt).toContain('query: find loading config')
102
- expect(prompt).toContain('reasoning: the user wants the config loader')
103
- expect(prompt).toContain('a.ts | 2 hits | alpha config line')
104
- })
105
- })
106
-
107
- describe('S1a ranked search fold', () => {
108
- const rows = [
109
- ...Array.from({ length: 40 }, (_, i) => `fat.ts:${String(i + 1)}: fat row ${String(i)}`),
110
- ...Array.from({ length: 40 }, (_, i) => `star.ts:${String(i + 1)}: star row ${String(i)}`),
111
- ]
112
-
113
- it('ranked file fills L2 first while L1 stays complete (existence lossless)', () => {
114
- const tight = input(rows.join('\n'), 1_500)
115
- const mechanical = reduceFreshToolResult(tight)!
116
- const ranked = reduceFreshToolResult(tight, { files: ['star.ts'] })!
117
- expect(ranked.reducer).toBe('search-by-file')
118
- // L1 locator sets survive untouched for both files.
119
- const locatorOf = (text: string, path: string): string | undefined =>
120
- text.split('\n').find(line => line.startsWith(`## ${path}`))
121
- for (const text of [mechanical.text, ranked.text]) {
122
- expect(locatorOf(text, 'fat.ts')!.match(/L\d+/gu)).toHaveLength(40)
123
- expect(locatorOf(text, 'star.ts')!.match(/L\d+/gu)).toHaveLength(40)
124
- }
125
- // Ranking only changes which rows the quota shows first.
126
- const countRows = (text: string, path: string): number =>
127
- text.split('\n').filter(line => line.startsWith(`${path}:`)).length
128
- expect(countRows(ranked.text, 'star.ts')).toBeGreaterThanOrEqual(countRows(mechanical.text, 'star.ts'))
129
- })
130
-
131
- it('counter-proof: no ranking reproduces the mechanical output byte-for-byte', () => {
132
- const tight = input(rows.join('\n'), 1_500)
133
- const mechanical = reduceFreshToolResult(tight)!.text
134
- expect(reduceFreshToolResult(tight, {})!.text).toBe(mechanical)
135
- expect(reduceFreshToolResult(tight, { files: [] })!.text).toBe(mechanical)
136
- })
137
-
138
- it('an LM ranking with unknown paths changes nothing', () => {
139
- const tight = input(rows.join('\n'), 1_500)
140
- const mechanical = reduceFreshToolResult(tight)!.text
141
- expect(reduceFreshToolResult(tight, { files: ['nope.ts'] })!.text).toBe(mechanical)
142
- })
143
- })
144
-
145
- describe('S1b ranked document fold', () => {
146
- function doc(): string {
147
- const parts: string[] = ['# Guide', 'Intro line.']
148
- for (const [name, size] of [['Small', 6] as const, ['Target Section', 40] as const, ['Appendix', 30] as const]) {
149
- parts.push(`## ${name}`)
150
- parts.push(...Array.from({ length: size }, (_, i) => `${name} body line ${String(i)} with ordinary prose.`))
151
- }
152
- return parts.join('\n')
153
- }
154
-
155
- function docInput(budget: number): ReducerInput {
156
- return { ...input(doc(), budget), toolName: 'mcp_fetch' }
157
- }
158
-
159
- it('selected section keeps full content; unselected keep heading plus first line', () => {
160
- const budget = 4_000
161
- const ranked = reduceFreshToolResult(docInput(budget), { sections: ['Target Section'] })
162
- expect(ranked).not.toBeNull()
163
- expect(ranked!.reducer).toBe('doc-skeleton')
164
- const text = ranked!.text
165
- // All headings survive (existence is never the channel's to remove).
166
- for (const heading of ['Guide', 'Small', 'Target Section', 'Appendix']) {
167
- expect(text).toContain(heading)
168
- }
169
- // Selected: full content fits. Unselected: first line only.
170
- expect(text).toContain('Target Section body line 39')
171
- expect(text).not.toContain('Appendix body line 29')
172
- expect(text).toContain('Appendix body line 0')
173
- expect(codePointLength(text)).toBeLessThanOrEqual(budget)
174
- })
175
-
176
- it('fills the ranked section partially when the budget cannot hold it whole', () => {
177
- const tight = reduceFreshToolResult(docInput(1_600), { sections: ['Target Section'] })!
178
- expect(codePointLength(tight.text)).toBeLessThanOrEqual(1_600)
179
- // More than the first-line floor of the ranked section survives.
180
- expect(tight.text.split('\n').filter(line => line.startsWith('Target Section body line')).length).toBeGreaterThan(1)
181
- // Unselected sections still show their first line (mechanical floor).
182
- expect(tight.text).toContain('Appendix body line 0')
183
- })
184
-
185
- it('counter-proof: no ranking reproduces the mechanical skeleton byte-for-byte', () => {
186
- const budget = 1_600
187
- const mechanical = reduceFreshToolResult(docInput(budget))!.text
188
- expect(reduceFreshToolResult(docInput(budget), { sections: [] })!.text).toBe(mechanical)
189
- })
190
- })
191
-
192
- describe('S1 orchestrator', () => {
193
- it('makes exactly ONE call and applies the ranking', async () => {
194
- const calls = { count: 0 }
195
- const channel = stubChannel('b.ts, a.ts', calls)
196
- const outcome = await rankNodes(
197
- [
198
- { id: 'a.ts', detail: '3 hits', sample: 'alpha' },
199
- { id: 'b.ts', detail: '9 hits', sample: 'beta' },
200
- ],
201
- new Set(['a.ts', 'b.ts']),
202
- 'find the loader',
203
- 'wants config loading',
204
- channel,
205
- AbortSignal.timeout(1_000),
206
- )
207
- expect(calls.count).toBe(1)
208
- expect(outcome.ranking).toEqual(['b.ts', 'a.ts'])
209
- expect(outcome.audit.ok).toBe(true)
210
- })
211
- it('falls back with an audit record when the channel returns nothing', async () => {
212
- const calls = { count: 0 }
213
- const outcome = await rankNodes(
214
- [
215
- { id: 'a.ts', detail: '3 hits', sample: 'alpha' },
216
- { id: 'b.ts', detail: '9 hits', sample: 'beta' },
217
- ],
218
- new Set(['a.ts', 'b.ts']),
219
- 'find the loader',
220
- undefined,
221
- stubChannel(undefined, calls),
222
- AbortSignal.timeout(1_000),
223
- )
224
- expect(outcome.ranking).toBeUndefined()
225
- expect(outcome.audit.ok).toBe(false)
226
- expect(outcome.audit.reason).toContain('falling back')
227
- })
228
- it('gate stays closed for a single node or an empty query (zero calls)', async () => {
229
- const calls = { count: 0 }
230
- const outcome = await rankNodes(
231
- [{ id: 'a.ts', detail: '3 hits', sample: 'alpha' }],
232
- new Set(['a.ts']),
233
- 'find the loader',
234
- undefined,
235
- stubChannel('a.ts', calls),
236
- AbortSignal.timeout(1_000),
237
- )
238
- expect(calls.count).toBe(0)
239
- expect(outcome.ranking).toBeUndefined()
240
- })
241
- })
@@ -1,167 +0,0 @@
1
- /**
2
- * T21:回填调度器规格——路由首命中一次性闸、dispose 低频节流、pause/resume、
3
- * 分块扫盘(游标跨 chunk 推进 + wrap 归零)、无 store 空转、重放幂等。
4
- *
5
- * 调度器是模块级单例:每个用例 vi.resetModules + 动态 import 取全新状态,
6
- * 同一动态链里的 stats-db 单例也随注册表一起刷新。DSH_HOME 指向临时目录,
7
- * 绝不触碰真实 `~/.dsh`。
8
- */
9
- import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from 'node:fs'
10
- import { tmpdir } from 'node:os'
11
- import { join } from 'node:path'
12
- import zlib from 'node:zlib'
13
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
14
- import { generationLogFilename } from '../../src/runtime/session-file-decode.ts'
15
-
16
- const dirs: string[] = []
17
- const envBackup: Record<string, string | undefined> = {}
18
- // 最近一次动态注册表的 stats-db:afterEach 关句柄后再删目录(Windows EBUSY)。
19
- let lastStatsDb: typeof import('../../src/runtime/stats-db.ts') | undefined
20
-
21
- function tempDir(tag: string): string {
22
- const dir = mkdtempSync(join(tmpdir(), `cci-sched-${tag}-`))
23
- dirs.push(dir)
24
- return dir
25
- }
26
-
27
- /** 写一个可解码的 v4 会话目录(header + 一条带压缩替换与 usage 的事件流)。 */
28
- function writeSessionDir(dshHome: string, sessionId: string): void {
29
- const dir = join(dshHome, 'sessions', 'proj', sessionId)
30
- const header = JSON.stringify({ type: 'session', version: 4, id: sessionId, createdAt: 1, cwd: 'proj' })
31
- const rows = [
32
- JSON.stringify({ seq: 0, type: 'user/message', time: 1000, data: { message: { content: [{ type: 'text', text: 'go' }] } } }),
33
- JSON.stringify({ seq: 1, type: 'tool/result', time: 1001, data: { message: { content: [{ type: 'text', text: 'R'.repeat(400) }] } } }),
34
- JSON.stringify({ seq: 2, type: 'tool/result', time: 1002, surfaceOp: { op: 'replace', startSeq: 1, endSeq: 1 }, data: { message: { content: [{ type: 'text', text: 'S'.repeat(100) }] } } }),
35
- JSON.stringify({ seq: 3, type: 'assistant/message', time: 1003, data: { message: { content: [] }, usage: { inputTokens: 100, outputTokens: 10, cacheReadTokens: 50 } } }),
36
- ]
37
- const bytes = zlib.zstdCompressSync(Buffer.from([header, ...rows, ''].join('\n'), 'utf8'))
38
- mkdirSync(dir, { recursive: true })
39
- writeFileSync(join(dir, generationLogFilename(4, 'zstd')), bytes)
40
- }
41
-
42
- /** 全新模块注册表:scheduler 与 stats-db 单例一起重置。 */
43
- async function freshModules() {
44
- vi.resetModules()
45
- const backfill = await import('../../src/runtime/stats-backfill.ts')
46
- const statsDb = await import('../../src/runtime/stats-db.ts')
47
- lastStatsDb = statsDb
48
- return { backfill, statsDb }
49
- }
50
-
51
- async function settle(backfill: typeof import('../../src/runtime/stats-backfill.ts')): Promise<void> {
52
- await vi.waitFor(() => {
53
- expect(backfill.getStatsBackfillStatus().running).toBe(false)
54
- })
55
- }
56
-
57
- beforeEach(() => {
58
- envBackup['DSH_HOME'] = process.env['DSH_HOME']
59
- })
60
-
61
- afterEach(() => {
62
- process.env['DSH_HOME'] = envBackup['DSH_HOME']
63
- lastStatsDb?.closeStatsStore()
64
- for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
65
- })
66
-
67
- describe('回填调度器(T21)', () => {
68
- it('路由首命中触发一轮;重复命中被一次性闸吸收', async () => {
69
- const home = tempDir('route')
70
- process.env['DSH_HOME'] = home
71
- writeSessionDir(home, 'sess-route-1')
72
- writeSessionDir(home, 'sess-route-2')
73
- const { backfill, statsDb } = await freshModules()
74
- const store = await statsDb.ensureStatsStore(join(tempDir('route-db'), 'stats.sqlite'))
75
- expect(store).not.toBeNull()
76
-
77
- backfill.kickStatsBackfillOnRouteHit()
78
- await settle(backfill)
79
- expect(backfill.getStatsBackfillStatus().runs).toBe(1)
80
- expect(backfill.getStatsBackfillStatus().lastSummary?.sessions).toBe(2)
81
-
82
- backfill.kickStatsBackfillOnRouteHit()
83
- await settle(backfill)
84
- expect(backfill.getStatsBackfillStatus().runs).toBe(1)
85
- })
86
-
87
- it('前台活跃压缩 → 回填让路(busy 期间零推进),旗标释放后完成', async () => {
88
- const home = tempDir('livebusy')
89
- process.env['DSH_HOME'] = home
90
- writeSessionDir(home, 'sess-livebusy')
91
- const { backfill, statsDb } = await freshModules()
92
- const statsSync = await import('../../src/runtime/stats-sync.ts')
93
- const store = await statsDb.ensureStatsStore(join(tempDir('livebusy-db'), 'stats.sqlite'))
94
- expect(store).not.toBeNull()
95
-
96
- statsSync.setStatsLivePathBusy(true)
97
- const passPromise = backfill.runStatsBackfillPass({ dshHome: home })
98
- // busy 窗口内 pass 已启动(running)但让路零推进
99
- await new Promise(resolve => setTimeout(resolve, 200))
100
- expect(backfill.getStatsBackfillStatus().running).toBe(true)
101
- expect(backfill.getStatsBackfillStatus().runs).toBe(0)
102
- statsSync.setStatsLivePathBusy(false)
103
- await vi.waitFor(() => {
104
- expect(backfill.getStatsBackfillStatus().running).toBe(false)
105
- }, { timeout: 5000 })
106
- expect(backfill.getStatsBackfillStatus().runs).toBe(1)
107
- expect(backfill.getStatsBackfillStatus().lastSummary?.sessions).toBe(1)
108
- await expect(passPromise).resolves.toMatchObject({ sessions: 1 })
109
- })
110
-
111
- it('分块扫盘:chunk 游标跨 chunk 推进、wrap 归零后重放零新增', async () => {
112
- const home = tempDir('chunk')
113
- process.env['DSH_HOME'] = home
114
- for (const id of ['sess-c-1', 'sess-c-2', 'sess-c-3']) writeSessionDir(home, id)
115
- const { backfill, statsDb } = await freshModules()
116
- const store = await statsDb.ensureStatsStore(join(tempDir('chunk-db'), 'stats.sqlite'))
117
- expect(store).not.toBeNull()
118
-
119
- // chunkSize=2 → 3 会话分两 chunk;claims 全部落库
120
- const first = await backfill.runStatsBackfillPass({ maxSessionsPerBackend: 2 })
121
- expect(first?.backend).toBe('files')
122
- expect(first?.sessions).toBe(3)
123
- expect(first!.claimsAdded).toBeGreaterThan(0)
124
-
125
- // 第二轮:全水位命中 → 零新增零处理(幂等重放锚点)
126
- const second = await backfill.runStatsBackfillPass({ maxSessionsPerBackend: 2 })
127
- expect(second?.sessions).toBe(0)
128
- expect(second?.claimsAdded).toBe(0)
129
- })
130
-
131
- it('pause 空转、resume 恢复;dispose kick 10 分钟节流', async () => {
132
- const home = tempDir('pause')
133
- process.env['DSH_HOME'] = home
134
- writeSessionDir(home, 'sess-pause-1')
135
- const { backfill, statsDb } = await freshModules()
136
- await statsDb.ensureStatsStore(join(tempDir('pause-db'), 'stats.sqlite'))
137
-
138
- backfill.pauseStatsBackfill()
139
- expect(await backfill.runStatsBackfillPass()).toBeUndefined()
140
- backfill.kickStatsBackfillOnDispose()
141
- await settle(backfill)
142
- expect(backfill.getStatsBackfillStatus().runs).toBe(0)
143
-
144
- backfill.resumeStatsBackfill()
145
- backfill.kickStatsBackfillOnDispose()
146
- await settle(backfill)
147
- expect(backfill.getStatsBackfillStatus().runs).toBe(1)
148
-
149
- // 节流窗口内第二次 dispose kick 不再跑
150
- backfill.kickStatsBackfillOnDispose()
151
- await settle(backfill)
152
- expect(backfill.getStatsBackfillStatus().runs).toBe(1)
153
- })
154
-
155
- it('无 store(未开/无驱动)时 kick 与直接 pass 全部空转', async () => {
156
- const home = tempDir('nostore')
157
- process.env['DSH_HOME'] = home
158
- writeSessionDir(home, 'sess-nostore-1')
159
- const { backfill } = await freshModules()
160
-
161
- expect(await backfill.runStatsBackfillPass()).toBeUndefined()
162
- backfill.kickStatsBackfillOnRouteHit()
163
- await settle(backfill)
164
- expect(backfill.getStatsBackfillStatus().runs).toBe(0)
165
- expect(backfill.getStatsBackfillStatus().lastSummary).toBeUndefined()
166
- })
167
- })