dsh-context-compression-improved 0.11.4 → 0.13.0

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 (330) hide show
  1. package/.agents/plans/improve/checklist.md +32 -0
  2. package/.agents/plans/improve/findings.md +102 -0
  3. package/.agents/plans/improve/spec.md +53 -0
  4. package/.agents/plans/improve/tasks.md +70 -0
  5. package/.gitattributes +2 -0
  6. package/.githooks/pre-push +37 -0
  7. package/.github/workflows/ci.yml +47 -0
  8. package/CHANGELOG.de.md +580 -0
  9. package/CHANGELOG.es.md +588 -0
  10. package/CHANGELOG.fr.md +576 -0
  11. package/CHANGELOG.it.md +577 -0
  12. package/CHANGELOG.ja.md +261 -0
  13. package/CHANGELOG.ko.md +254 -0
  14. package/CHANGELOG.md +582 -0
  15. package/CHANGELOG.pt.md +167 -0
  16. package/CHANGELOG.ru.md +554 -0
  17. package/CHANGELOG.zh.md +247 -0
  18. package/CONTRIBUTING.md +22 -0
  19. package/README.de.md +96 -0
  20. package/README.es.md +96 -0
  21. package/README.fr.md +96 -0
  22. package/README.it.md +96 -0
  23. package/README.ja.md +102 -0
  24. package/README.ko.md +102 -0
  25. package/README.md +121 -15
  26. package/README.pt.md +96 -0
  27. package/README.ru.md +96 -0
  28. package/README.zh.md +104 -14
  29. package/SECURITY.md +18 -0
  30. package/THIRD_PARTY_NOTICES.md +7 -25
  31. package/assets/board.png +0 -0
  32. package/assets/context.png +0 -0
  33. package/assets/dshfind-card.svg +33 -0
  34. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  35. package/docs/assets/context-compression-selector-settings.png +0 -0
  36. package/docs/compat-0.1.5-report.md +77 -0
  37. package/docs/installation.de.md +104 -0
  38. package/docs/installation.es.md +104 -0
  39. package/docs/installation.fr.md +104 -0
  40. package/docs/installation.it.md +104 -0
  41. package/docs/installation.ja.md +78 -0
  42. package/docs/installation.ko.md +78 -0
  43. package/docs/installation.md +103 -0
  44. package/docs/installation.ru.md +104 -0
  45. package/docs/installation.zh.md +100 -0
  46. package/docs/repair-log.md +657 -0
  47. package/docs/shallow-teaching-preset-template.md +46 -0
  48. package/eslint.config.js +30 -0
  49. package/package.json +112 -127
  50. package/packages/selector/LICENSE +21 -0
  51. package/packages/selector/README.md +26 -0
  52. package/packages/selector/README.zh.md +24 -0
  53. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -0
  54. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -0
  55. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -0
  56. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -0
  57. package/{dsh.plugin.json → packages/selector/dsh.plugin.json} +2 -2
  58. package/{lib → packages/selector/lib}/client.js +400 -0
  59. package/packages/selector/lib/style.css +350 -0
  60. package/packages/selector/package.json +180 -0
  61. package/packages/selector/screenshots.json +3 -0
  62. package/packages/selector/src/client/CompressionProfileControls.tsx +352 -0
  63. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -0
  64. package/packages/selector/src/client/CompressionProfileSelector.tsx +89 -0
  65. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -0
  66. package/packages/selector/src/client/EstimatorControls.tsx +277 -0
  67. package/packages/selector/src/client/bridge-scope.ts +125 -0
  68. package/packages/selector/src/client/decode.ts +68 -0
  69. package/packages/selector/src/client/fab-pos.ts +71 -0
  70. package/packages/selector/src/client/guide-steps.ts +50 -0
  71. package/packages/selector/src/client/guide.tsx +368 -0
  72. package/packages/selector/src/client/index.ts +456 -0
  73. package/packages/selector/src/client/locales/de.ts +167 -0
  74. package/packages/selector/src/client/locales/es.ts +167 -0
  75. package/packages/selector/src/client/locales/fr.ts +167 -0
  76. package/packages/selector/src/client/locales/it.ts +167 -0
  77. package/packages/selector/src/client/locales/ja.ts +167 -0
  78. package/packages/selector/src/client/locales/ko.ts +167 -0
  79. package/packages/selector/src/client/locales/pt.ts +167 -0
  80. package/packages/selector/src/client/locales/ru.ts +167 -0
  81. package/packages/selector/src/client/locales.ts +334 -0
  82. package/packages/selector/src/client/monitor-fab.ts +445 -0
  83. package/packages/selector/src/client/preset-options.ts +88 -0
  84. package/packages/selector/src/client/savings-card.tsx +269 -0
  85. package/packages/selector/src/client/scope-face.ts +24 -0
  86. package/packages/selector/src/client/settings-section.tsx +171 -0
  87. package/packages/selector/src/compat/host-generation.ts +96 -0
  88. package/packages/selector/src/compat/llm-messages.ts +50 -0
  89. package/packages/selector/src/compat/settings-lease.ts +108 -0
  90. package/packages/selector/src/compat/tool-result.ts +91 -0
  91. package/packages/selector/src/css-modules.d.ts +6 -0
  92. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -0
  93. package/packages/selector/src/estimator-catalog.ts +104 -0
  94. package/packages/selector/src/index.ts +909 -0
  95. package/packages/selector/src/invariant.ts +113 -0
  96. package/packages/selector/src/preset-overlay.ts +749 -0
  97. package/packages/selector/src/profiles.ts +554 -0
  98. package/packages/selector/src/pruner/content.ts +199 -0
  99. package/packages/selector/src/pruner/session.ts +97 -0
  100. package/packages/selector/src/pruner/state.ts +61 -0
  101. package/packages/selector/src/pruner/tuning.ts +23 -0
  102. package/packages/selector/src/pruner/types.ts +78 -0
  103. package/packages/selector/src/pruner.ts +3222 -0
  104. package/packages/selector/src/runtime/adaptive-cost.ts +205 -0
  105. package/packages/selector/src/runtime/audit.ts +321 -0
  106. package/packages/selector/src/runtime/config.ts +887 -0
  107. package/packages/selector/src/runtime/custom-policy.ts +300 -0
  108. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -0
  109. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -0
  110. package/packages/selector/src/runtime/display-prefs.ts +98 -0
  111. package/packages/selector/src/runtime/fold-router.ts +143 -0
  112. package/packages/selector/src/runtime/measurement.ts +444 -0
  113. package/packages/selector/src/runtime/monitor.ts +341 -0
  114. package/packages/selector/src/runtime/panel-command.ts +213 -0
  115. package/packages/selector/src/runtime/reducers.ts +1755 -0
  116. package/packages/selector/src/runtime/retrieve.ts +505 -0
  117. package/packages/selector/src/runtime/savings-integral.ts +117 -0
  118. package/packages/selector/src/runtime/savings-projection.ts +229 -0
  119. package/packages/selector/src/runtime/savings-verify.ts +446 -0
  120. package/packages/selector/src/runtime/savings.ts +526 -0
  121. package/packages/selector/src/runtime/sediment-card.ts +126 -0
  122. package/packages/selector/src/runtime/sediment-clock.ts +87 -0
  123. package/packages/selector/src/runtime/sediment-guard.ts +136 -0
  124. package/packages/selector/src/runtime/sediment-publish.ts +144 -0
  125. package/packages/selector/src/runtime/sediment-span.ts +170 -0
  126. package/packages/selector/src/runtime/sediment.ts +209 -0
  127. package/packages/selector/src/runtime/session-events.ts +30 -0
  128. package/packages/selector/src/runtime/session-file-decode.ts +523 -0
  129. package/packages/selector/src/runtime/shallow-tools.ts +342 -0
  130. package/packages/selector/src/runtime/stats-backfill.ts +541 -0
  131. package/packages/selector/src/runtime/stats-db.ts +492 -0
  132. package/packages/selector/src/runtime/stats-schema.ts +123 -0
  133. package/packages/selector/src/runtime/stats-sync.ts +307 -0
  134. package/packages/selector/src/runtime/summary-command.ts +127 -0
  135. package/packages/selector/src/runtime/tail-trim.ts +177 -0
  136. package/packages/selector/src/runtime/token-count.ts +72 -0
  137. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
  138. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
  139. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
  140. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
  141. package/packages/selector/src/runtime/tokenpilot/dedup.ts +82 -0
  142. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -0
  143. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  144. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  145. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  146. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  147. package/packages/selector/src/runtime/tokenpilot/locator.ts +129 -0
  148. package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -0
  149. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
  150. package/packages/selector/src/runtime/tool-names.ts +42 -0
  151. package/packages/selector/src/runtime/toolclass.ts +103 -0
  152. package/packages/selector/src/runtime/triage/masks.ts +128 -0
  153. package/packages/selector/src/runtime/triage/shallow.ts +132 -0
  154. package/packages/selector/src/runtime/triage/signals.ts +167 -0
  155. package/packages/selector/src/runtime/triage/types.ts +125 -0
  156. package/packages/selector/src/runtime/types.ts +396 -0
  157. package/packages/selector/src/runtime/value.ts +48 -0
  158. package/packages/selector/src/settings-bridge.ts +175 -0
  159. package/packages/selector/src/tui-command.ts +99 -0
  160. package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
  161. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -0
  162. package/packages/selector/tests/built/client-artifact.spec.ts +56 -0
  163. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -0
  164. package/packages/selector/tests/code-skeleton.client.spec.ts +98 -0
  165. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
  166. package/packages/selector/tests/custom-contract.client.spec.ts +226 -0
  167. package/packages/selector/tests/estimator-catalog.spec.ts +70 -0
  168. package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -0
  169. package/packages/selector/tests/estimator-route-registration.host.spec.ts +202 -0
  170. package/packages/selector/tests/fab-pos.client.spec.ts +47 -0
  171. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +231 -0
  172. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +236 -0
  173. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +220 -0
  174. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +140 -0
  175. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +117 -0
  176. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +67 -0
  177. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +119 -0
  178. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +119 -0
  179. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +131 -0
  180. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +196 -0
  181. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +71 -0
  182. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +126 -0
  183. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +86 -0
  184. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +50 -0
  185. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +102 -0
  186. package/packages/selector/tests/helpers/legacy-namespace.ts +35 -0
  187. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
  188. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
  189. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
  190. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
  191. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
  192. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -0
  193. package/packages/selector/tests/monitor-fab.client.spec.ts +240 -0
  194. package/packages/selector/tests/preset-options-write.client.spec.ts +192 -0
  195. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -0
  196. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -0
  197. package/packages/selector/tests/profiles.client.spec.tsx +436 -0
  198. package/packages/selector/tests/ptc-custom-write.client.spec.ts +86 -0
  199. package/packages/selector/tests/public/package-contract.client.spec.ts +91 -0
  200. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -0
  201. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -0
  202. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
  203. package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
  204. package/packages/selector/tests/runtime/audit.spec.ts +275 -0
  205. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -0
  206. package/packages/selector/tests/runtime/behavior-lock-profiles.spec.ts +128 -0
  207. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
  208. package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -0
  209. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -0
  210. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -0
  211. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -0
  212. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
  213. package/packages/selector/tests/runtime/fallback-diversity.spec.ts +75 -0
  214. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -0
  215. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +46 -0
  216. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -0
  217. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -0
  218. package/packages/selector/tests/runtime/fold-router.spec.ts +140 -0
  219. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
  220. package/packages/selector/tests/runtime/fresh-gate.spec.ts +43 -0
  221. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
  222. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  223. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  224. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +79 -0
  225. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
  226. package/packages/selector/tests/runtime/monitor.spec.ts +354 -0
  227. package/packages/selector/tests/runtime/panel-command.spec.ts +101 -0
  228. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
  229. package/packages/selector/tests/runtime/ptc-profile.spec.ts +133 -0
  230. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2795 -0
  231. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
  232. package/packages/selector/tests/runtime/savings-accounting.spec.ts +291 -0
  233. package/packages/selector/tests/runtime/savings-integral.spec.ts +169 -0
  234. package/packages/selector/tests/runtime/savings-projection.spec.ts +89 -0
  235. package/packages/selector/tests/runtime/savings-verify.spec.ts +226 -0
  236. package/packages/selector/tests/runtime/savings.spec.ts +139 -0
  237. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
  238. package/packages/selector/tests/runtime/sediment-card.spec.ts +111 -0
  239. package/packages/selector/tests/runtime/sediment-config.spec.ts +56 -0
  240. package/packages/selector/tests/runtime/sediment-guard.spec.ts +71 -0
  241. package/packages/selector/tests/runtime/sediment-masks.spec.ts +95 -0
  242. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +166 -0
  243. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +65 -0
  244. package/packages/selector/tests/runtime/sediment-publish.spec.ts +142 -0
  245. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +158 -0
  246. package/packages/selector/tests/runtime/sediment-settings.spec.ts +73 -0
  247. package/packages/selector/tests/runtime/sediment-signals.spec.ts +124 -0
  248. package/packages/selector/tests/runtime/sediment-span.spec.ts +92 -0
  249. package/packages/selector/tests/runtime/session-events.spec.ts +27 -0
  250. package/packages/selector/tests/runtime/session-file-decode.spec.ts +281 -0
  251. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +58 -0
  252. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +135 -0
  253. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
  254. package/packages/selector/tests/runtime/source-kind-audit.spec.ts +79 -0
  255. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +167 -0
  256. package/packages/selector/tests/runtime/stats-backfill.spec.ts +350 -0
  257. package/packages/selector/tests/runtime/stats-db.spec.ts +361 -0
  258. package/packages/selector/tests/runtime/stats-privacy.spec.ts +55 -0
  259. package/packages/selector/tests/runtime/stats-sync.spec.ts +278 -0
  260. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  261. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
  262. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -0
  263. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
  264. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -0
  265. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -0
  266. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -0
  267. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +121 -0
  268. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -0
  269. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
  270. package/packages/selector/tests/runtime/value.spec.ts +23 -0
  271. package/packages/selector/tests/savings-sessions.client.spec.tsx +140 -0
  272. package/packages/selector/tests/settings-seat.client.spec.ts +215 -0
  273. package/packages/selector/tests/standing-generation.host.spec.ts +729 -0
  274. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -0
  275. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -0
  276. package/packages/selector/tests/support/mock-adapter.ts +37 -0
  277. package/packages/selector/tests/support/ui-primitives.tsx +34 -0
  278. package/packages/selector/tsconfig.json +11 -0
  279. package/packages/selector/tsdown.client.config.ts +102 -0
  280. package/packages/selector/tsdown.config.ts +20 -0
  281. package/pnpm-workspace.yaml +76 -0
  282. package/screenshots.json +6 -3
  283. package/scripts/capture-profile-baseline.mjs +42 -0
  284. package/scripts/cell-browser-e2e.mjs +354 -0
  285. package/scripts/generate-tokenizer-fixtures.py +81 -0
  286. package/scripts/generate-vision-fixtures.py +208 -0
  287. package/scripts/hosts.d.mts +3 -0
  288. package/scripts/hosts.mjs +81 -0
  289. package/scripts/packed-components-smoke.mjs +763 -0
  290. package/scripts/packed-install-e2e.mjs +1346 -0
  291. package/scripts/sediment-latency-report.mjs +63 -0
  292. package/scripts/sync-hosts.mjs +176 -0
  293. package/scripts/toolclass-corpus-replay.mjs +281 -0
  294. package/scripts/verify-release.mjs +342 -0
  295. package/tests/TEST_INVENTORY.md +41 -0
  296. package/tsconfig.base.json +18 -0
  297. package/tsconfig.json +7 -0
  298. package/tsconfig.tests.json +15 -0
  299. package/vitest.built.config.ts +9 -0
  300. package/vitest.config.ts +54 -0
  301. /package/{assets → packages/selector/assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  302. /package/{assets → packages/selector/assets}/deepseek-v4/manifest.json +0 -0
  303. /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer.json +0 -0
  304. /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer_config.json +0 -0
  305. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  306. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  307. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  308. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  309. /package/{cordis.patch.yml → packages/selector/cordis.patch.yml} +0 -0
  310. /package/{lib → packages/selector/lib}/client.d.ts +0 -0
  311. /package/{lib → packages/selector/lib}/index.d.ts +0 -0
  312. /package/{lib → packages/selector/lib}/index.js +0 -0
  313. /package/{lib → packages/selector/lib}/invariant.d.ts +0 -0
  314. /package/{lib → packages/selector/lib}/invariant.js +0 -0
  315. /package/{lib → packages/selector/lib}/profiles.d.ts +0 -0
  316. /package/{lib → packages/selector/lib}/pruner.d.ts +0 -0
  317. /package/{lib → packages/selector/lib}/pruner.js +0 -0
  318. /package/{lib → packages/selector/lib}/savings-integral.js +0 -0
  319. /package/{lib → packages/selector/lib}/tail-trim.js +0 -0
  320. /package/{lib → packages/selector/lib}/tool-result.js +0 -0
  321. /package/{locale → packages/selector/locale}/de.json +0 -0
  322. /package/{locale → packages/selector/locale}/en.json +0 -0
  323. /package/{locale → packages/selector/locale}/es.json +0 -0
  324. /package/{locale → packages/selector/locale}/fr.json +0 -0
  325. /package/{locale → packages/selector/locale}/it.json +0 -0
  326. /package/{locale → packages/selector/locale}/ja.json +0 -0
  327. /package/{locale → packages/selector/locale}/ko.json +0 -0
  328. /package/{locale → packages/selector/locale}/pt.json +0 -0
  329. /package/{locale → packages/selector/locale}/ru.json +0 -0
  330. /package/{locale → packages/selector/locale}/zh.json +0 -0
@@ -0,0 +1,241 @@
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
+ })
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Source-kind audit: all message publications use plugin-specific source kind.
3
+ *
4
+ * Plan: cci-longterm-refactor v0.13.1 (F16 — source.kind audit)
5
+ *
6
+ * Verifies the invariant: every createUserMessage call within this plugin
7
+ * carries source.kind === 'dsh-context-compression' (modern hosts) or
8
+ * source.kind === 'plugin' with plugin === 'dsh-context-compression-improved'
9
+ * (legacy hosts). Messages must NEVER use kind: 'user' — dsh-ops #1040 lesson:
10
+ * host treats kind:'user' as a real user bubble, polluting chat history.
11
+ *
12
+ * @module dsh-context-compression-improved/tests/runtime/source-kind-audit
13
+ */
14
+ import { describe, expect, it } from 'vitest'
15
+ import { compressionMessageSource } from '../../src/compat/tool-result.ts'
16
+ import { createUserMessage } from '../../src/compat/llm-messages.ts'
17
+
18
+ describe('F16: compressionMessageSource returns plugin-specific kind', () => {
19
+ it('modern host: kind is dsh-context-compression', () => {
20
+ // Default (no generation arg) should be modern
21
+ const source = compressionMessageSource('modern')
22
+ expect(source).toEqual({ kind: 'dsh-context-compression' })
23
+ })
24
+
25
+ it('legacy host: kind is plugin with correct plugin id', () => {
26
+ const source = compressionMessageSource('legacy')
27
+ expect(source).toEqual({
28
+ kind: 'plugin',
29
+ plugin: 'dsh-context-compression-improved',
30
+ })
31
+ })
32
+
33
+ it('neither path returns kind: "user"', () => {
34
+ const modern = compressionMessageSource('modern')
35
+ const legacy = compressionMessageSource('legacy')
36
+ expect(modern.kind).not.toBe('user')
37
+ expect(legacy.kind).not.toBe('user')
38
+ })
39
+ })
40
+
41
+ describe('F16: createUserMessage preserves source.kind from input', () => {
42
+ it('message carries the plugin-specific source through creation', () => {
43
+ const content = [{ type: 'text' as const, text: 'test skeleton footer' }]
44
+ const source = compressionMessageSource('modern')
45
+ const message = createUserMessage({
46
+ content,
47
+ source: source as { kind: 'dsh-context-compression' },
48
+ })
49
+ expect(message.role).toBe('user') // role is always 'user' for message type
50
+ expect((message as any).source.kind).toBe('dsh-context-compression')
51
+ expect((message as any).source.kind).not.toBe('user')
52
+ })
53
+
54
+ it('legacy source also passes through', () => {
55
+ const content = [{ type: 'text' as const, text: 'test tail-trim stub' }]
56
+ const source = compressionMessageSource('legacy')
57
+ const message = createUserMessage({
58
+ content,
59
+ source: source as any,
60
+ })
61
+ expect((message as any).source.kind).toBe('plugin')
62
+ expect((message as any).source.plugin).toBe('dsh-context-compression-improved')
63
+ })
64
+ })
65
+
66
+ describe('F16: static audit — no hard-coded kind:"user" in src', () => {
67
+ it('compressionMessageSource is the single source of truth for message sources', () => {
68
+ // This test is a structural invariant check:
69
+ // If anyone adds a new createUserMessage() call with a raw literal
70
+ // like `source: { kind: 'user' }`, the TypeScript type system should
71
+ // reject it (MessageSourceMap has no 'user' key registered by this plugin).
72
+ // The compressionMessageSource() factory is the ONLY sanctioned way.
73
+ //
74
+ // Note: Full grep-based enforcement is the ESLint rule (task_13.1.2).
75
+ // This test just validates the factory function itself is correct.
76
+ const source = compressionMessageSource()
77
+ expect(['dsh-context-compression', 'plugin']).toContain(source.kind)
78
+ })
79
+ })
@@ -0,0 +1,167 @@
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
+ })