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,269 +0,0 @@
1
- /**
2
- * 节省统计卡片(设置分节内,只读):存量(本进程口径) + 累计(按 N 次 call) +
3
- * 省钱估计三行并存(T26),会话账本服务端分页(T24 数据面),持久化徽标与降级
4
- * 标注,显示偏好经载荷 displayPrefs 实时拾取(T32,/ccip 的落点)。
5
- * 数据源 = `/api/.../savings`(存量)与 `/api/.../savings/sessions`(分页面板),
6
- * 5s 自调度轮询,失败静默——统计卡片永不打扰设置页主功能。
7
- *
8
- * @module dsh-context-compression-improved/client/savings-card
9
- */
10
- import { useEffect, useRef, useState } from 'react'
11
- import css from './CompressionProfileSelector.module.css'
12
- import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
13
-
14
- const SAVINGS_ROUTE = '/api/dsh-context-compression-improved/savings'
15
- const SESSIONS_ROUTE = '/api/dsh-context-compression-improved/savings/sessions'
16
- const PAGE_SIZE = 20
17
-
18
- interface BasisPair { exact: number; estimated: number }
19
- interface IntegralTotals { netExact: number; netEstimated: number; cachedInput: number; uncachedInput: number; calls: number }
20
- interface DisplayPrefs {
21
- rows: { stock: boolean; total: boolean; money: boolean }
22
- mode: 'full' | 'compact'
23
- focusSessionId: string | null
24
- }
25
-
26
- interface SavingsSnapshot {
27
- ok?: boolean
28
- startedAt: string
29
- sessions: number
30
- gross: BasisPair
31
- offsets: BasisPair
32
- net: BasisPair
33
- perComponent: Array<{ component: string; tokens: number; basis: string; kind: string }>
34
- recentOffsets: Array<{ component: string; tokens: number; basis: string; at: string; note?: string }>
35
- usage?: { requests: number; inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; cacheHitRate: number | null }
36
- perSession?: Array<{ sessionId: string; net: BasisPair; requests: number; cacheHitRate: number | null }>
37
- pricing?: { currency: string; actualCost?: string; estimatedSavedCost?: string }
38
- }
39
-
40
- interface SessionsPayload {
41
- ok?: boolean
42
- persisted: { persisted: true; driver: string } | { persisted: false; reason: string }
43
- displayPrefs: DisplayPrefs
44
- total: number
45
- offset: number
46
- limit: number
47
- integralTotal: IntegralTotals
48
- integralMoney?: { decimal: string; currency: string }
49
- sessions: Array<{
50
- sessionId: string
51
- net: BasisPair
52
- integral: IntegralTotals
53
- money?: { decimal: string; currency: string }
54
- source: string
55
- liveStock?: BasisPair
56
- }>
57
- liveOnly: Array<{ sessionId: string; net: BasisPair; requests: number; cacheHitRate: number | null }>
58
- }
59
-
60
- export interface SavingsCardProps {
61
- /** locale 文案函数(与设置分节同一 translator,键受字典类型约束)。 */
62
- t: CompressionProfileSelectorProps['t']
63
- }
64
-
65
- function fmt(n: number): string {
66
- return n.toLocaleString('en-US')
67
- }
68
-
69
- /** 节省统计卡片:存量/累计双口径 + 会话账本分页;口径分列永不混算。 */
70
- export function SavingsCard({ t }: SavingsCardProps) {
71
- const [snap, setSnap] = useState<SavingsSnapshot | null>(null)
72
- const [panel, setPanel] = useState<SessionsPayload | null>(null)
73
- const [offset, setOffset] = useState(0)
74
- const offsetRef = useRef(0)
75
- offsetRef.current = offset
76
- const stopped = useRef(false)
77
- useEffect(() => {
78
- stopped.current = false
79
- const tick = async (): Promise<void> => {
80
- try {
81
- const response = await fetch(SAVINGS_ROUTE, { headers: { 'cache-control': 'no-cache' } })
82
- if (response.ok) {
83
- const data = (await response.json()) as SavingsSnapshot
84
- if (data?.startedAt !== undefined && !stopped.current) setSnap(data)
85
- }
86
- } catch {
87
- /* 路由未注册/网络不可用:静默 */
88
- }
89
- try {
90
- const response = await fetch(`${SESSIONS_ROUTE}?offset=${String(offsetRef.current)}&limit=${String(PAGE_SIZE)}`, { headers: { 'cache-control': 'no-cache' } })
91
- if (response.ok) {
92
- const data = (await response.json()) as SessionsPayload
93
- if (data?.ok === true && !stopped.current) setPanel(data)
94
- }
95
- } catch {
96
- /* 分页面板缺席(老版本宿主):静默,存量口径照常显示 */
97
- }
98
- if (!stopped.current) setTimeout(tick, 5000)
99
- }
100
- void tick()
101
- return () => {
102
- stopped.current = true
103
- }
104
- }, [offset])
105
-
106
- const prefs = panel?.displayPrefs
107
- const stockVisible = prefs?.rows.stock !== false
108
- const totalVisible = prefs?.rows.total !== false
109
- const moneyVisible = prefs?.rows.money !== false
110
- const compact = prefs?.mode === 'compact'
111
- const focus = prefs?.focusSessionId ?? null
112
- const persisted = panel?.persisted?.persisted === true
113
-
114
- const integral = panel?.integralTotal
115
- const stockEmpty = snap === null || (snap.gross.exact + snap.gross.estimated === 0)
116
- const integralEmpty = integral === undefined || integral.calls === 0
117
- // 桩数据/部分载荷可能缺数组字段:统一兜底,账本判据与渲染共用同一视图。
118
- const panelSessions = panel?.sessions ?? []
119
- const panelLiveOnly = panel?.liveOnly ?? []
120
- // 本会话存量/累计为零时若账本已有回填数据,仍要落全卡渲染——早退会把
121
- // 会话账本一起吞掉(存量空 ≠ 无历史节省)。
122
- const ledgerReady = panelSessions.length > 0 || panelLiveOnly.length > 1
123
- if (stockEmpty && integralEmpty && !ledgerReady) {
124
- return <div className={css.pricing}>{t('savings.empty')}</div>
125
- }
126
- const hasExact = snap !== null && (snap.gross.exact > 0 || snap.offsets.exact > 0)
127
- const hasEstimated = snap !== null && (snap.gross.estimated > 0 || snap.offsets.estimated > 0)
128
- const netTone = snap !== null && (snap.net.exact + snap.net.estimated) >= 0 ? css.savingsNetPositive : css.savingsNetNegative
129
- return (
130
- <div className={`${css.savingsCard}`} data-testid="savings-card">
131
- <div className={css.savingsRow}>
132
- <span>{t('savings.title')}</span>
133
- {panel === null ? null : (
134
- <span className={css.savingsMuted} data-testid="savings-persisted">
135
- {persisted ? `✓ ${t('savings.persisted')}` : `⚠ ${t('savings.degraded')}`}
136
- </span>
137
- )}
138
- </div>
139
- {stockVisible && snap !== null ? (
140
- <>
141
- {hasExact ? (
142
- <div className={`${css.savingsRow} ${netTone}`} data-testid="savings-stock-exact">
143
- <span>{t('savings.netExact')}</span>
144
- <strong>{fmt(snap.net.exact)}</strong>
145
- </div>
146
- ) : null}
147
- {hasEstimated ? (
148
- <div className={css.savingsRow} data-testid="savings-stock-estimated">
149
- <span>{t('savings.netEstimated')}</span>
150
- <strong>{fmt(snap.net.estimated)}</strong>
151
- </div>
152
- ) : null}
153
- {!compact ? (
154
- <>
155
- <div className={css.savingsRow}>
156
- <span className={css.savingsMuted}>{t('savings.gross')}</span>
157
- <span className={css.savingsMuted}>
158
- {hasExact ? `✓ ${fmt(snap.gross.exact)}` : ''}{hasExact && hasEstimated ? ' · ' : ''}{hasEstimated ? `≈ ${fmt(snap.gross.estimated)}` : ''}
159
- </span>
160
- </div>
161
- <div className={css.savingsRow}>
162
- <span className={css.savingsMuted}>{t('savings.offsets')}</span>
163
- <span className={css.savingsMuted}>
164
- {hasExact ? `−${fmt(snap.offsets.exact)}` : ''}{hasExact && hasEstimated ? ' · ' : ''}{hasEstimated ? `−${fmt(snap.offsets.estimated)}` : ''}
165
- </span>
166
- </div>
167
- </>
168
- ) : null}
169
- </>
170
- ) : null}
171
- {totalVisible && integral !== undefined && integral.calls > 0 ? (
172
- <div className={css.savingsRow} data-testid="savings-cumulative">
173
- <span>{t('savings.cumulative').replace('N', fmt(integral.calls))}</span>
174
- <strong>
175
- {integral.netExact !== 0 ? fmt(integral.netExact) : ''}{integral.netExact !== 0 && integral.netEstimated !== 0 ? ' · ' : ''}{integral.netEstimated !== 0 ? `≈ ${fmt(integral.netEstimated)}` : ''}
176
- </strong>
177
- </div>
178
- ) : null}
179
- {moneyVisible && panel?.integralMoney !== undefined ? (
180
- <div className={css.savingsRow} data-testid="savings-money">
181
- <span className={css.savingsMuted}>{t('savings.money')}</span>
182
- <span className={css.savingsMuted}>{panel.integralMoney.currency} {panel.integralMoney.decimal}</span>
183
- </div>
184
- ) : null}
185
- {stockVisible && snap !== null && !compact && snap.usage !== undefined && snap.usage.requests > 0 ? (
186
- <>
187
- <div className={css.savingsRow}>
188
- <span className={css.savingsMuted}>{t('savings.requests')}</span>
189
- <span className={css.savingsMuted}>{fmt(snap.usage.requests)}</span>
190
- </div>
191
- <div className={css.savingsRow}>
192
- <span className={css.savingsMuted}>{t('savings.cacheHit')}</span>
193
- <span className={css.savingsMuted}>
194
- {snap.usage.cacheHitRate === null ? '–' : `${Math.round(snap.usage.cacheHitRate * 100)}%`}
195
- </span>
196
- </div>
197
- {snap.pricing?.actualCost !== undefined ? (
198
- <div className={css.savingsRow}>
199
- <span className={css.savingsMuted}>{t('savings.actualCost')}</span>
200
- <span className={css.savingsMuted}>{snap.pricing.currency} {snap.pricing.actualCost}</span>
201
- </div>
202
- ) : null}
203
- {snap.pricing?.estimatedSavedCost !== undefined ? (
204
- <div className={css.savingsRow}>
205
- <span className={css.savingsMuted}>{t('savings.savedMoney')}</span>
206
- <span className={css.savingsMuted}>{snap.pricing.currency} {snap.pricing.estimatedSavedCost}</span>
207
- </div>
208
- ) : null}
209
- </>
210
- ) : null}
211
- {ledgerReady ? (
212
- <div className={css.savingsBreakdown} data-testid="savings-session-list">
213
- <div className={css.savingsRow}>
214
- <span className={css.savingsMuted}>{t('savings.sessions')}{panel !== null && panel.total > 0 ? ` (${fmt(panel.total)})` : ''}</span>
215
- <span className={css.savingsMuted}>
216
- {panel !== null && (panel.total > panelSessions.length || panel.offset > 0) ? (
217
- <>
218
- <a
219
- href="#"
220
- data-testid="savings-page-prev"
221
- onClick={(event) => { event.preventDefault(); setOffset(value => Math.max(0, value - PAGE_SIZE)) }}
222
- >{t('savings.pagePrev')}</a>
223
- {' · '}
224
- </>
225
- ) : null}
226
- {panel !== null && panel.offset + panelSessions.length < panel.total ? (
227
- <a
228
- href="#"
229
- data-testid="savings-page-next"
230
- onClick={(event) => { event.preventDefault(); setOffset(value => value + PAGE_SIZE) }}
231
- >{t('savings.pageNext')}</a>
232
- ) : null}
233
- </span>
234
- </div>
235
- {panelSessions.slice(0, 8).map(row => (
236
- <div key={row.sessionId} className={css.savingsRow}>
237
- <span className={css.savingsMuted}>
238
- {row.sessionId === focus ? `◎ ${t('savings.focus')} · ` : ''}{row.sessionId.slice(0, 8)}… · {fmt(row.integral.calls)} calls
239
- </span>
240
- <span className={css.savingsMuted}>
241
- {fmt(row.net.exact)}{row.money !== undefined ? ` · ${row.money.currency} ${row.money.decimal}` : ''}
242
- </span>
243
- </div>
244
- ))}
245
- {panelLiveOnly.slice(0, 3).map(row => (
246
- <div key={row.sessionId} className={css.savingsRow}>
247
- <span className={css.savingsMuted}>{row.sessionId.slice(0, 8)}… · {t('savings.netEstimated')}</span>
248
- <span className={css.savingsMuted}>{fmt(row.net.exact + row.net.estimated)}</span>
249
- </div>
250
- ))}
251
- </div>
252
- ) : null}
253
- {stockVisible && snap !== null && !compact && snap.perComponent.length > 0 ? (
254
- <div className={css.savingsBreakdown}>
255
- {snap.perComponent.slice(0, 6).map((row) => (
256
- <div key={`${row.kind}:${row.component}:${row.basis}`} className={css.savingsRow}>
257
- <span className={css.savingsMuted}>
258
- {row.kind === 'offset' ? '−' : '+'} {row.component}
259
- <small> ({row.basis === 'exact-tokenizer' ? t('savings.basisExact') : t('savings.basisEstimated')})</small>
260
- </span>
261
- <span className={css.savingsMuted}>{fmt(row.tokens)}</span>
262
- </div>
263
- ))}
264
- </div>
265
- ) : null}
266
- <div className={css.savingsNote}>{t('savings.basisNote')}</div>
267
- </div>
268
- )
269
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * 0.1.7-rc.2 stopped exporting `SettingsScope` from
3
- * `@deepseek-ai/dsh-client-ui-settings/client`; the structural face the
4
- * selector consumes lives here instead (getSnapshot shape mirrors the 0.1.7
5
- * `ConfigFormSnapshot` minus the parts the components never read).
6
- */
7
- /** The projected snapshot shape (identity-stable between changes — React #185). */
8
- export interface ScopeSnapshot<T> {
9
- status: 'loading' | 'ready' | 'unavailable'
10
- value: T | undefined
11
- revision: number | undefined
12
- writable: boolean
13
- base: unknown
14
- user: unknown
15
- mode: 'host' | 'memory'
16
- }
17
-
18
- export interface SettingsScope<T> {
19
- getSnapshot(): ScopeSnapshot<T>
20
- subscribe(listener: () => void): () => void
21
- set(field: string, value: unknown): Promise<boolean>
22
- unset(field: string): Promise<boolean>
23
- mutate?(ops: readonly { path: readonly string[]; op: string; value?: unknown }[]): Promise<boolean>
24
- }
@@ -1,156 +0,0 @@
1
- /**
2
- * Full-page Settings surface backed by the same durable selector state.
3
- *
4
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
- *
6
- * @module dsh-context-compression-improved/client/settings-section
7
- */
8
-
9
- import { useEffect, useState } from 'react'
10
- import css from './CompressionProfileSelector.module.css'
11
- import {
12
- AUTO_COMPACT_THRESHOLD_LIMITS,
13
- COMPRESSION_PROFILES,
14
- type CompressionProfile,
15
- type CustomCompressionPolicyV3,
16
- } from '../profiles.ts'
17
- import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
18
- import { AutoCompactThresholdControls, CodeSkeletonControls, SedimentControls, IntentSummaryControls, MonitorPanelControls } from './CompressionProfileControls.tsx'
19
- import { EstimatorControls, EstimatorInactiveNotice } from './EstimatorControls.tsx'
20
- import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
21
- import { SavingsCard } from './savings-card'
22
-
23
- /** Full-page Settings surface backed by the same durable selector state. */
24
- export function ContextCompressionSettingsSection(props: CompressionProfileSelectorProps) {
25
- return <SettingsCompressionProfileControls {...props} />
26
- }
27
-
28
- export function SettingsCompressionProfileControls({
29
- useCompression, select, saveCustom, resetCustom, savePtcCustom, resetPtcCustom, saveAutoCompact, saveCodeSkeleton, saveSediment, saveIntentSummary, saveMonitorPanel,
30
- savePresetOptions, t,
31
- }: CompressionProfileSelectorProps) {
32
- const state = useCompression(snapshot => snapshot)
33
- // Harness 0.1.5 dropped browser-side agentPreset from session summaries, so
34
- // the old Minimal-preset gate has no data source; the selector stays enabled.
35
- const selectorAvailable = true
36
- const [saving, setSaving] = useState(false)
37
- const [saveError, setSaveError] = useState<string | null>(null)
38
- const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
39
- const [ptcDraft, setPtcDraft] = useState<CustomCompressionPolicyV3 | null>(null)
40
- const current = state.value?.profile ?? 'balanced'
41
- useEffect(() => {
42
- const custom = state.value?.custom
43
- setDraft((current === 'custom' || current === 'tokenpilot-inspired') && custom !== undefined ? editableCustom(custom) : null)
44
- }, [current, state.value?.custom])
45
- useEffect(() => {
46
- const ptcCustom = state.value?.ptcCustom
47
- setPtcDraft(current === 'ptc' && ptcCustom !== undefined ? editableCustom(ptcCustom) : null)
48
- }, [current, state.value?.ptcCustom])
49
- if (state.status === 'unavailable') return null
50
-
51
- const busy = state.status === 'loading' || saving
52
- const selectProfile = (profile: CompressionProfile): void => {
53
- if (!selectorAvailable || !state.writable || profile === current) return
54
- setSaveError(null)
55
- setSaving(true)
56
- void select(profile).then(
57
- () => { setSaving(false) },
58
- (error: unknown) => {
59
- setSaving(false)
60
- setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
61
- },
62
- )
63
- }
64
- const settle = (operation: () => Promise<void>): void => {
65
- setSaveError(null)
66
- setSaving(true)
67
- void operation().then(
68
- () => { setSaving(false) },
69
- (error: unknown) => {
70
- setSaving(false)
71
- setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
72
- },
73
- )
74
- }
75
-
76
- return (
77
- <section className={css.settingsSection}>
78
- <h2 className={css.settingsTitle}>{t('settings.title')}</h2>
79
- <p className={css.settingsDescription}>{t('settings.description')}</p>
80
- {selectorAvailable ? (
81
- <div className={css.profileGrid} aria-label={t('label')}>
82
- {COMPRESSION_PROFILES.map((profile) => {
83
- const selected = profile === current
84
- return (
85
- <button key={profile} type="button" className={css.profileCard} aria-pressed={selected}
86
- disabled={busy || !state.writable} onClick={() => { selectProfile(profile) }}>
87
- <span className={css.profileCardTop}>
88
- <span className={css.profileCardTitle}>{t(`profile.${profile}`)}</span>
89
- {selected ? <span className={css.profileCurrent}>{t('profile.current')}</span> : null}
90
- </span>
91
- <span className={css.profileCardDetail}>{t(`detail.${profile}`)}</span>
92
- </button>
93
- )
94
- })}
95
- </div>
96
- ) : <div className={css.unavailable} role="status">{t('status.minimalUnavailable')}</div>}
97
- <AutoCompactThresholdControls
98
- value={state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default}
99
- disabled={busy || !state.writable || !selectorAvailable}
100
- save={saveAutoCompact}
101
- settle={settle}
102
- t={t}
103
- />
104
- <CodeSkeletonControls
105
- value={state.value?.codeSkeleton?.enabled ?? false}
106
- disabled={busy || !state.writable || !selectorAvailable}
107
- save={saveCodeSkeleton}
108
- settle={settle}
109
- t={t}
110
- />
111
- <SedimentControls
112
- value={state.value?.sediment?.enabled ?? false}
113
- disabled={busy || !state.writable || !selectorAvailable}
114
- save={saveSediment}
115
- settle={settle}
116
- t={t}
117
- />
118
- <IntentSummaryControls
119
- value={state.value?.intentSummary?.enabled ?? false}
120
- disabled={busy || !state.writable || !selectorAvailable}
121
- save={saveIntentSummary}
122
- settle={settle}
123
- t={t}
124
- />
125
- <MonitorPanelControls
126
- value={state.value?.monitorPanel?.enabled ?? false}
127
- disabled={busy || !state.writable || !selectorAvailable}
128
- save={saveMonitorPanel}
129
- settle={settle}
130
- t={t}
131
- />
132
- {current !== 'tokenpilot-inspired' ? (
133
- <EstimatorInactiveNotice profile={t(`profile.${current}`)} t={t} />
134
- ) : (
135
- <EstimatorControls
136
- options={state.value?.presetOptions ?? {}}
137
- disabled={busy || !state.writable || !selectorAvailable}
138
- save={savePresetOptions}
139
- settle={settle}
140
- t={t}
141
- />
142
- )}
143
- <SavingsCard t={t} />
144
- <div className={css.pricing}>{t('pricing.disclosure')}</div>
145
- {current !== 'custom' && current !== 'tokenpilot-inspired' || draft === null || !selectorAvailable ? null : (
146
- <CustomPolicyEditor value={draft} disabled={busy || !state.writable} setValue={setDraft}
147
- save={() => saveCustom(structuredClone(draft))} reset={resetCustom} settle={settle} t={t} />
148
- )}
149
- {current !== 'ptc' || ptcDraft === null || !selectorAvailable ? null : (
150
- <CustomPolicyEditor value={ptcDraft} disabled={busy || !state.writable} setValue={setPtcDraft}
151
- save={() => savePtcCustom(structuredClone(ptcDraft))} reset={resetPtcCustom} settle={settle} t={t} />
152
- )}
153
- {saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
154
- </section>
155
- )
156
- }
@@ -1,96 +0,0 @@
1
- /**
2
- * Host generation probe — the ONE narrow-waist version read in the server
3
- * plane. Capability-based, never reads plugin-local node_modules (family
4
- * rule, enum-peer INDEX §C): a settings service that still exposes
5
- * `register` is a pre-0.1.7 host (0.1.0–0.1.5 lines, dsh-settings pack
6
- * evidence); from 0.1.7-rc.1 the service drops register entirely (probe
7
- * roundtrip: methods all undefined) and settings live in the loader-managed
8
- * entry config.
9
- *
10
- * Client-side code must NOT use this module: per audit P1-9 the client picks
11
- * its data path by which scoped sub-inject resolves (configForms arm = Gen D
12
- * upgrade; bridge transport is the default that works everywhere).
13
- */
14
-
15
- export type HostGeneration = 'legacy' | 'modern'
16
-
17
- let cached: HostGeneration | undefined
18
-
19
- /**
20
- * Pure classifier from a RESOLVED settings service face. A service that still
21
- * exposes `register` is a pre-0.1.7 host (0.1.0–0.1.5 lines, dsh-settings pack
22
- * evidence — verified on the real 0.1.0-rc.2 host: `register(ns, schema,
23
- * options)` at dsh-settings/lib/index.js:311); from 0.1.7-rc.1 the service
24
- * drops register entirely and settings live in the loader-managed entry
25
- * config.
26
- */
27
- export function classifySettingsFace(settings: unknown): HostGeneration {
28
- return typeof (settings as { register?: unknown } | null)?.register === 'function' ? 'legacy' : 'modern'
29
- }
30
-
31
- /**
32
- * Probe the host generation from the settings service face.
33
- *
34
- * A verdict is only CACHED from a resolved service object. Rows compose
35
- * before host services on every line (measured: the wire-time probe on a real
36
- * 0.1.0-rc.2 cell saw no settings service yet and the old code cached
37
- * 'modern' forever — the legacy lease arm went dead on the exact line it was
38
- * built for). While the service is absent the answer is a provisional
39
- * 'modern' and deliberately uncached, so the definitive
40
- * `noteResolvedSettingsService` evidence can still flip it.
41
- */
42
- export function detectHostGeneration(ctx: { get(name: string): unknown }): HostGeneration {
43
- if (cached !== undefined) return cached
44
- let settings: unknown
45
- try {
46
- settings = ctx.get('settings')
47
- } catch {
48
- return 'modern'
49
- }
50
- if (settings === null || typeof settings !== 'object') return 'modern'
51
- cached = classifySettingsFace(settings)
52
- return cached
53
- }
54
-
55
- /**
56
- * Definitive verdict from the resolved service (evidence observed, not
57
- * guessed): the settings inject callback calls this once the service has
58
- * actually composed. Always (re)writes the cache — a provisional earlier
59
- * verdict must not survive real evidence.
60
- */
61
- export function noteResolvedSettingsService(settings: unknown): HostGeneration {
62
- cached = classifySettingsFace(settings)
63
- return cached
64
- }
65
-
66
- /**
67
- * Server-plane snapshot for code paths that hold no ctx (the tool-result
68
- * adapters). The bridge's inject callback has already noted the resolved
69
- * service by the time any session message flows, so this reads real evidence
70
- * on every line; without it the only safe answer is the provisional default.
71
- */
72
- export function hostGenerationSnapshot(): HostGeneration {
73
- return cached ?? 'modern'
74
- }
75
-
76
- /** Test seam: reset the cached probe (unit tests only). */
77
- export function resetHostGenerationCache(): void {
78
- cached = undefined
79
- }
80
-
81
- /**
82
- * Diagnostics sink by generation: measured on the 0.1.2 host the cordis
83
- * logger prints nothing in the `dsh web` terminal, so legacy lines report
84
- * through console; modern hosts keep the service logger.
85
- */
86
- export interface CompatLog {
87
- (message: string, ...rest: unknown[]): void
88
- }
89
-
90
- export function compatLog(ctx: { get(name: string): unknown; logger?: Record<'info' | 'warn', (...rest: unknown[]) => void> }, level: 'info' | 'warn' = 'info'): CompatLog {
91
- if (detectHostGeneration(ctx) === 'legacy') {
92
- return (message, ...rest) => console[level](`[dsh-context-compression-improved] ${message}`, ...rest)
93
- }
94
- const sink = ctx.logger?.[level]?.bind(ctx.logger) ?? ((...rest: unknown[]) => console[level](...rest))
95
- return (message, ...rest) => sink(`[dsh-context-compression-improved] ${message}`, ...rest)
96
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Local stand-ins for the two `@deepseek-ai/dsh-llm` message factories the
3
- * pruner and TailTrim hot paths need. The package is an OPTIONAL peer — the
4
- * official-clone profile in the packed-install e2e (and any host line that
5
- * stops shipping it into a plugin's module graph) does not resolve it, and a
6
- * static value import then crashes the whole plugin at module-load time with
7
- * ERR_MODULE_NOT_FOUND. This mirrors the 0.9.3 pruner soft-import decision:
8
- * the semantics are deliberately tiny and stable (deep clone → brand a fresh
9
- * id → deep freeze), so the plugin carries its own copy instead of importing
10
- * the host's.
11
- */
12
- import type { UserMessage } from '@deepseek-ai/dsh-llm'
13
-
14
- /** Recursive `Object.freeze` over own enumerable properties (arrays included). */
15
- function deepFreeze<T>(value: T): T {
16
- if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
17
- Object.freeze(value)
18
- for (const nested of Object.values(value as Record<string, unknown>)) {
19
- deepFreeze(nested)
20
- }
21
- }
22
- return value
23
- }
24
-
25
- /**
26
- * Detach and deep-freeze a message whose identity already exists — the host
27
- * factory is `deepFreeze(structuredClone(message))`, byte-for-byte.
28
- */
29
- export function freezeMessage<T>(message: T): T {
30
- return deepFreeze(structuredClone(message))
31
- }
32
-
33
- /**
34
- * Create one identified user-role message and freeze it before publication —
35
- * the host factory spreads the input, stamps `role: 'user'` and a fresh UUID
36
- * id, clones and freezes. The signature mirrors the host's generic form so
37
- * call sites keep their excess-property discipline; `id`/`role` stay
38
- * unconstructible via the `never` guards, exactly like the host's d.ts.
39
- */
40
- type NewUserMessage = Omit<UserMessage, 'id' | 'role'>
41
-
42
- export function createUserMessage<T extends NewUserMessage>(
43
- input: T & { readonly id?: never, readonly role?: never },
44
- ): UserMessage {
45
- return deepFreeze(structuredClone({
46
- ...input,
47
- role: 'user' as const,
48
- id: crypto.randomUUID(),
49
- })) as unknown as UserMessage
50
- }