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,216 +0,0 @@
1
- /**
2
- * CustomPolicyEditor: full custom compression policy editor with StageFields.
3
- *
4
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
- *
6
- * @module dsh-context-compression-improved/client/CustomPolicyEditor
7
- */
8
-
9
- import type { ContextCompressionLocaleKey } from './locales.ts'
10
- import css from './CompressionProfileSelector.module.css'
11
- import {
12
- isCustomCompressionPolicy,
13
- type CustomCompressionBudget,
14
- type CustomCompressionPolicy,
15
- type CustomCompressionPolicyV3,
16
- type CustomHistoryPolicy,
17
- } from '../profiles.ts'
18
-
19
- interface CustomPolicyEditorProps {
20
- value: CustomCompressionPolicyV3
21
- disabled: boolean
22
- setValue: (value: CustomCompressionPolicyV3) => void
23
- save: () => Promise<void>
24
- reset: () => Promise<void>
25
- settle: (operation: () => Promise<void>) => void
26
- t: (key: ContextCompressionLocaleKey) => string
27
- }
28
-
29
- export function CustomPolicyEditor({ value, disabled, setValue, save, reset, settle, t }: CustomPolicyEditorProps) {
30
- const valid = isCustomCompressionPolicy(value)
31
- const unitStep = value.unit === 'tokens' ? 1 : 0.01
32
- const unitMax = value.unit === 'tokens' ? undefined : 100
33
- const unitBounds = unitMax === undefined ? {} : { max: unitMax }
34
- const setBudget = (
35
- stage: 'fresh' | 'aggregate',
36
- patch: Partial<CustomCompressionBudget>,
37
- ): void => {
38
- setValue({ ...value, [stage]: { ...value[stage], ...patch } })
39
- }
40
- const setHistory = (patch: Partial<CustomHistoryPolicy>): void => {
41
- setValue({ ...value, history: { ...value.history, ...patch } })
42
- }
43
- return (
44
- <section className={css.custom} aria-labelledby="context-compression-custom-title">
45
- <h3 id="context-compression-custom-title" className={css.customTitle}>{t('custom.title')}</h3>
46
- <p className={css.customNote}>{t('custom.sessionScope')}</p>
47
- <p className={css.customNote}>{t('custom.measurement')}</p>
48
- <label className={css.field}>
49
- <span>{t('custom.unit')}</span>
50
- <select
51
- value={value.unit}
52
- disabled={disabled}
53
- onChange={(event) => {
54
- setValue({
55
- ...value,
56
- unit: event.currentTarget.value as CustomCompressionPolicy['unit'],
57
- })
58
- }}
59
- >
60
- <option value="tokens">{t('custom.unit.tokens')}</option>
61
- <option value="context-percent">{t('custom.unit.contextPercent')}</option>
62
- </select>
63
- </label>
64
- <StageFields
65
- t={t}
66
- title={t('custom.fresh.enabled')}
67
- enabled={value.fresh.enabled}
68
- disabled={disabled}
69
- onEnabled={(enabled) => { setBudget('fresh', { enabled }) }}
70
- fields={[
71
- { label: t('custom.fresh.trigger'), value: value.fresh.trigger, set: (trigger) => { setBudget('fresh', { trigger }) }, ...unitBounds },
72
- { label: t('custom.fresh.target'), value: value.fresh.target, set: (target) => { setBudget('fresh', { target }) }, ...unitBounds },
73
- ]}
74
- step={unitStep}
75
- />
76
- <StageFields
77
- t={t}
78
- title={t('custom.aggregate.enabled')}
79
- enabled={value.aggregate.enabled}
80
- disabled={disabled}
81
- onEnabled={(enabled) => { setBudget('aggregate', { enabled }) }}
82
- fields={[
83
- { label: t('custom.aggregate.trigger'), value: value.aggregate.trigger, set: (trigger) => { setBudget('aggregate', { trigger }) }, ...unitBounds },
84
- { label: t('custom.aggregate.target'), value: value.aggregate.target, set: (target) => { setBudget('aggregate', { target }) }, ...unitBounds },
85
- ]}
86
- step={unitStep}
87
- />
88
- <StageFields
89
- t={t}
90
- title={t('custom.history.enabled')}
91
- enabled={value.history.enabled}
92
- disabled={disabled}
93
- onEnabled={(enabled) => { setHistory({ enabled }) }}
94
- fields={[
95
- { label: t('custom.history.trigger'), value: value.history.trigger, set: (trigger) => { setHistory({ trigger }) }, ...unitBounds },
96
- { label: t('custom.history.keepRecentToolCalls'), value: value.history.keepRecentToolCalls, set: (keepRecentToolCalls) => { setHistory({ keepRecentToolCalls }) }, integer: true, allowZero: true },
97
- { label: t('custom.history.keepRecentTokens'), value: value.history.keepRecentTokens, set: (keepRecentTokens) => { setHistory({ keepRecentTokens }) }, allowZero: true, ...unitBounds },
98
- { label: t('custom.history.minReclaim'), value: value.history.minReclaim, set: (minReclaim) => { setHistory({ minReclaim }) }, ...unitBounds },
99
- ]}
100
- step={unitStep}
101
- fieldsEnabled={value.history.enabled || value.tailTrim.enabled}
102
- />
103
- <label className={css.field}>
104
- <span>{t('custom.prefixPolicy')}</span>
105
- <select
106
- value={value.prefixPolicy}
107
- disabled={disabled || !value.history.enabled}
108
- onChange={(event) => {
109
- setValue({
110
- ...value,
111
- prefixPolicy: event.currentTarget.value as CustomCompressionPolicy['prefixPolicy'],
112
- })
113
- }}
114
- >
115
- <option value="preserve">{t('custom.prefixPolicy.preserve')}</option>
116
- <option value="pressure-break">{t('custom.prefixPolicy.pressureBreak')}</option>
117
- </select>
118
- </label>
119
- <div className={css.customNote}>{t('custom.experimental')}</div>
120
- <StageFields
121
- t={t}
122
- title={t('custom.tailTrim.enabled')}
123
- enabled={value.tailTrim.enabled}
124
- disabled={disabled}
125
- onEnabled={(enabled) => {
126
- setValue({ ...value, tailTrim: { ...value.tailTrim, enabled } })
127
- }}
128
- fields={[{
129
- label: t('custom.tailTrim.trigger'),
130
- value: value.tailTrim.trigger,
131
- set: (trigger) => {
132
- setValue({ ...value, tailTrim: { ...value.tailTrim, trigger } })
133
- },
134
- ...unitBounds,
135
- }]}
136
- step={unitStep}
137
- />
138
- <p className={css.customNote}>{t('custom.tailTrim.warning')}</p>
139
- {valid ? null : <div className={css.error} role="alert">{t('custom.invalid')}</div>}
140
- <div className={css.actions}>
141
- <button type="button" disabled={disabled || !valid} onClick={() => { settle(save) }}>{t('custom.save')}</button>
142
- <button type="button" disabled={disabled} onClick={() => { settle(reset) }}>{t('custom.reset')}</button>
143
- </div>
144
- </section>
145
- )
146
- }
147
-
148
- interface StageNumberField {
149
- label: string
150
- value: number
151
- set: (value: number) => void
152
- integer?: boolean
153
- allowZero?: boolean
154
- max?: number
155
- }
156
-
157
- export function StageFields({ title, enabled, disabled, onEnabled, fields, step, fieldsEnabled = enabled, t }: {
158
- title: string
159
- enabled: boolean
160
- disabled: boolean
161
- onEnabled: (enabled: boolean) => void
162
- fields: readonly StageNumberField[]
163
- step: number
164
- fieldsEnabled?: boolean
165
- t: (key: ContextCompressionLocaleKey) => string
166
- }) {
167
- return (
168
- <fieldset className={css.stage} disabled={disabled}>
169
- <legend>{title}</legend>
170
- <label className={css.field}>
171
- <span>{t('custom.enabled')}</span>
172
- <select aria-label={title} value={enabled ? 'on' : 'off'}
173
- onChange={(event) => { onEnabled(event.currentTarget.value === 'on') }}>
174
- <option value="on">{t('custom.enabled.on')}</option>
175
- <option value="off">{t('custom.enabled.off')}</option>
176
- </select>
177
- </label>
178
- <div className={css.fieldGrid}>
179
- {fields.map(field => (
180
- <label className={css.field} key={field.label}>
181
- <span>{field.label}</span>
182
- <input
183
- type="number"
184
- value={field.value}
185
- min={field.allowZero === true ? 0 : field.integer === true ? 1 : step}
186
- max={field.max}
187
- step={field.integer === true ? 1 : step}
188
- disabled={!fieldsEnabled || disabled}
189
- onChange={(event) => { field.set(Number(event.currentTarget.value)) }}
190
- />
191
- </label>
192
- ))}
193
- </div>
194
- </fieldset>
195
- )
196
- }
197
-
198
- /** Convert a legacy custom policy to V3 format. */
199
- export function editableCustom(value: CustomCompressionPolicy): CustomCompressionPolicyV3 {
200
- if (value.version === 3) return structuredClone(value)
201
- return {
202
- version: 3,
203
- unit: value.unit,
204
- fresh: structuredClone(value.fresh),
205
- aggregate: structuredClone(value.aggregate),
206
- history: {
207
- enabled: value.history.enabled,
208
- trigger: value.history.trigger,
209
- keepRecentToolCalls: 10,
210
- keepRecentTokens: value.history.keepRecent,
211
- minReclaim: value.history.minReclaim,
212
- },
213
- prefixPolicy: value.prefixPolicy,
214
- tailTrim: value.version === 1 ? { enabled: false, trigger: 700_000 } : structuredClone(value.tailTrim),
215
- }
216
- }
@@ -1,277 +0,0 @@
1
- /**
2
- * TokenPilot-inspired estimator channel card components.
3
- *
4
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
- *
6
- * @module dsh-context-compression-improved/client/EstimatorControls
7
- */
8
-
9
- import { useEffect, useState } from 'react'
10
- import type { ContextCompressionLocaleKey } from './locales.ts'
11
- import type { PresetOptionsPatch } from './preset-options.ts'
12
- import type { PresetOptionsSettings } from '../profiles.ts'
13
- import css from './CompressionProfileSelector.module.css'
14
-
15
- interface EstimatorControlsProps {
16
- options: PresetOptionsSettings
17
- disabled: boolean
18
- save: (options: PresetOptionsPatch) => Promise<void>
19
- settle: (operation: () => Promise<void>) => void
20
- t: (key: ContextCompressionLocaleKey) => string
21
- }
22
-
23
- interface EstimatorInactiveNoticeProps {
24
- /** Already-localized label of the profile that currently owns the selector. */
25
- profile: string
26
- t: (key: ContextCompressionLocaleKey) => string
27
- }
28
-
29
- /**
30
- * The estimator card is gated on the tokenpilot-inspired profile, because
31
- * `presetOptions` is merged into that profile alone. A card that merely
32
- * disappears reads as a missing feature — the first real-machine report was
33
- * exactly that — so keep the heading and its anchor id in place and spend them
34
- * on the reason plus the profile that unlocks the card. The gate itself is
35
- * unchanged: no estimator control exists outside tokenpilot-inspired.
36
- *
37
- * Exported from the estimator card's own module so the gated card and its
38
- * explanation cannot drift apart.
39
- */
40
- export function EstimatorInactiveNotice({ profile, t }: EstimatorInactiveNoticeProps) {
41
- return (
42
- <section className={css.autoCompact} aria-labelledby="context-compression-estimator-title">
43
- <h3 id="context-compression-estimator-title" className={css.autoCompactTitle}>{t('estimator.title')}</h3>
44
- <p className={css.customNote}>{t('estimator.inactive').replace('{profile}', profile)}</p>
45
- </section>
46
- )
47
- }
48
-
49
- interface CatalogModelEntry { readonly id: string, readonly name: string }
50
- interface CatalogProviderEntry { readonly id: string, readonly name: string, readonly models: readonly CatalogModelEntry[], readonly error?: string }
51
- interface EstimatorCatalogBody {
52
- readonly ok?: boolean
53
- readonly providers?: readonly CatalogProviderEntry[]
54
- readonly selection?: { readonly provider: string, readonly model: string }
55
- }
56
-
57
- const ESTIMATOR_CATALOG_ROUTE = '/api/dsh-context-compression-improved/estimator-catalog'
58
-
59
- /**
60
- * TokenPilot-inspired estimator channel card. Shown only while the
61
- * tokenpilot-inspired profile is selected, and split by channel:
62
- *
63
- * - `host` reuses the providers and credentials the user already configured in
64
- * DSH through the Harness `llm` service, so this card names a provider and a
65
- * model and accepts NO API key — the key field belongs to the direct channel
66
- * alone.
67
- * - `direct` talks to a native OpenAI-compatible endpoint, which is the only
68
- * channel that carries its own base URL and write-only key.
69
- *
70
- * The whole card is advisory: an unconfigured or failing endpoint keeps every
71
- * consumer on its rule-only fallback.
72
- */
73
- export function EstimatorControls({ options, disabled, save, settle, t }: EstimatorControlsProps) {
74
- const [keyDraft, setKeyDraft] = useState('')
75
- const [baseUrl, setBaseUrl] = useState(options.estimatorBaseUrl ?? '')
76
- const [model, setModel] = useState(options.estimatorModel ?? '')
77
- const [provider, setProvider] = useState(options.estimatorProvider ?? '')
78
- const mode = options.estimatorMode ?? ''
79
- // Host-mode dropdown source: the live provider/model-group catalog served by
80
- // the Bundle entry's estimator-catalog route (dsh-perm-gate receiver
81
- // pattern). The provider/model fields are always comboboxes: an empty
82
- // catalog (route missing / llm service absent) simply offers no suggestions
83
- // while custom typing keeps working, so nothing breaks on hosts without the
84
- // webServer.
85
- const [catalog, setCatalog] = useState<EstimatorCatalogBody | undefined>()
86
- useEffect(() => {
87
- if (mode !== 'host') return
88
- let alive = true
89
- // The catalog route answers once the host webServer/llm services are up;
90
- // poll briefly so the dropdowns fill without reopening the panel.
91
- let attempts = 0
92
- const load = async (): Promise<EstimatorCatalogBody | undefined> => {
93
- try {
94
- const response = await fetch(ESTIMATOR_CATALOG_ROUTE, { headers: { 'cache-control': 'no-cache' } })
95
- return response.ok ? (await response.json()) as EstimatorCatalogBody : undefined
96
- } catch {
97
- return undefined
98
- }
99
- }
100
- const tick = (): void => {
101
- attempts += 1
102
- void load().then((body) => {
103
- if (!alive) return
104
- if (body !== undefined && (body.providers?.length ?? 0) > 0) {
105
- setCatalog(body)
106
- return
107
- }
108
- if (attempts < 10) setTimeout(tick, 3_000)
109
- })
110
- }
111
- tick()
112
- return () => { alive = false }
113
- }, [mode])
114
- const hostProviders = catalog?.providers ?? []
115
- // Model suggestions follow the provider draft exactly like dsh-perm-gate's
116
- // receiver card: an empty provider lists every group's models, a chosen
117
- // provider narrows to its own. The provider error (if any) rides along in
118
- // the option label so a broken group is visible without blocking typing.
119
- const providerDraft = provider
120
- const hostModels = hostProviders
121
- .filter(entry => providerDraft === '' || entry.id === providerDraft)
122
- .flatMap(entry => entry.models.map(model => ({ ...model, provider: entry.id })))
123
- const hostProvider = hostProviders.find(entry => entry.id === providerDraft)
124
- ?? hostProviders.find(entry => entry.id === (options.estimatorProvider ?? ''))
125
- const hasKey = (options.estimatorApiKey ?? '') !== ''
126
- const commit = (patch: PresetOptionsPatch) => {
127
- settle(() => save(patch))
128
- }
129
- // What the host channel would actually call right now: an explicit override
130
- // wins, otherwise the session default the catalog reports. Naming the
131
- // resolved route is the whole point of this channel — the user re-enters
132
- // nothing the Harness already knows.
133
- const overrideProvider = options.estimatorProvider ?? ''
134
- const overrideModel = options.estimatorModel ?? ''
135
- const effectiveProvider = overrideProvider !== '' ? overrideProvider : catalog?.selection?.provider ?? ''
136
- const effectiveModel = overrideModel !== '' ? overrideModel : catalog?.selection?.model ?? ''
137
- const effectiveRoute = effectiveProvider !== '' && effectiveModel !== ''
138
- ? `${effectiveProvider} / ${effectiveModel}`
139
- : t('estimator.hostUnresolved')
140
- return (
141
- <section className={css.autoCompact} aria-labelledby="context-compression-estimator-title">
142
- <h3 id="context-compression-estimator-title" className={css.autoCompactTitle}>{t('estimator.title')}</h3>
143
- <p className={css.customNote}>{t('estimator.description')}</p>
144
- <label className={css.field}>
145
- <span>{t('estimator.mode')}</span>
146
- <select
147
- value={mode}
148
- disabled={disabled}
149
- onChange={(event) => { settle(() => save({ estimatorMode: event.currentTarget.value as '' | 'host' | 'direct' })) }}
150
- >
151
- <option value="">{t('estimator.mode.off')}</option>
152
- <option value="host">{t('estimator.mode.host')}</option>
153
- <option value="direct">{t('estimator.mode.direct')}</option>
154
- </select>
155
- </label>
156
- {mode === '' ? null : mode === 'host' ? (
157
- <>
158
- <label className={css.field}>
159
- <span>{t('estimator.provider')}</span>
160
- <input
161
- type="text"
162
- list="estimator-provider-options"
163
- value={provider}
164
- disabled={disabled}
165
- placeholder={t('estimator.provider.placeholder')}
166
- onChange={(event) => {
167
- const next = event.currentTarget.value
168
- setProvider(next)
169
- // Picking from the datalist fires change without blur: commit
170
- // an exact catalog hit immediately; free typing waits for blur
171
- // so mid-edit keystrokes never disable the panel.
172
- if (next !== '' && hostProviders.some(entry => entry.id === next)) {
173
- commit({ estimatorProvider: next })
174
- }
175
- }}
176
- onBlur={() => { if (provider !== (options.estimatorProvider ?? '')) commit({ estimatorProvider: provider }) }}
177
- />
178
- </label>
179
- {/* Datalists ride outside the labels on purpose: option text inside a
180
- label would leak into its accessible name. */}
181
- <datalist id="estimator-provider-options">
182
- {hostProviders.map(entry => (
183
- <option key={entry.id} value={entry.id}>
184
- {entry.name === '' ? entry.id : entry.name}{entry.error === undefined ? '' : ` (${entry.error})`}
185
- </option>
186
- ))}
187
- </datalist>
188
- <label className={css.field}>
189
- <span>{t('estimator.model')}</span>
190
- <input
191
- type="text"
192
- list="estimator-model-options"
193
- value={model}
194
- disabled={disabled}
195
- placeholder={t('estimator.model.placeholder')}
196
- onChange={(event) => {
197
- const next = event.currentTarget.value
198
- setModel(next)
199
- if (next !== '' && hostModels.some(entry => entry.id === next)) {
200
- commit({ estimatorModel: next })
201
- }
202
- }}
203
- onBlur={() => { if (model !== (options.estimatorModel ?? '')) commit({ estimatorModel: model }) }}
204
- />
205
- </label>
206
- <datalist id="estimator-model-options">
207
- {hostModels.map(entry => (
208
- <option key={`${entry.provider}\0${entry.id}`} value={entry.id}>{entry.name}</option>
209
- ))}
210
- </datalist>
211
- {hostProvider?.error === undefined ? null : (
212
- <p className={css.customNote}>{String(hostProvider.error)}</p>
213
- )}
214
- <p className={css.customNote}>{t('estimator.hostReuse')}</p>
215
- <p className={css.customNote}>{t('estimator.hostRoute').replace('{route}', effectiveRoute)}</p>
216
- </>
217
- ) : (
218
- <>
219
- <label className={css.field}>
220
- <span>{t('estimator.baseUrl')}</span>
221
- <input
222
- type="text"
223
- value={baseUrl}
224
- disabled={disabled}
225
- placeholder="https://127.0.0.1:8000/v1"
226
- onChange={(event) => { setBaseUrl(event.currentTarget.value) }}
227
- onBlur={() => { if (baseUrl !== (options.estimatorBaseUrl ?? '')) commit({ estimatorBaseUrl: baseUrl }) }}
228
- />
229
- </label>
230
- <label className={css.field}>
231
- <span>{t('estimator.model')}</span>
232
- <input
233
- type="text"
234
- value={model}
235
- disabled={disabled}
236
- onChange={(event) => { setModel(event.currentTarget.value) }}
237
- onBlur={() => { if (model !== (options.estimatorModel ?? '')) commit({ estimatorModel: model }) }}
238
- />
239
- </label>
240
- <label className={css.field}>
241
- <span>{t('estimator.apiKey')}</span>
242
- <div style={{ display: 'flex', gap: '6px' }}>
243
- <input
244
- type="password"
245
- autoComplete="off"
246
- spellCheck={false}
247
- value={keyDraft}
248
- disabled={disabled}
249
- placeholder={hasKey ? t('estimator.apiKey.set') : t('estimator.apiKey.placeholder')}
250
- onChange={(event) => { setKeyDraft(event.currentTarget.value) }}
251
- onBlur={() => {
252
- const next = keyDraft.trim()
253
- if (next === '') return
254
- settle(() => save({ estimatorApiKey: next }))
255
- setKeyDraft('')
256
- }}
257
- onKeyDown={(event) => {
258
- if (event.key === 'Enter') event.currentTarget.blur()
259
- }}
260
- />
261
- {hasKey ? (
262
- <button
263
- type="button"
264
- disabled={disabled}
265
- onClick={() => { settle(() => save({ estimatorApiKey: undefined })) }}
266
- >
267
- {t('estimator.apiKey.clear')}
268
- </button>
269
- ) : null}
270
- </div>
271
- {hasKey ? <span className={css.customNote}>{t('estimator.apiKey.overwrite')}</span> : null}
272
- </label>
273
- </>
274
- )}
275
- </section>
276
- )
277
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * Bridge-backed settings scope — the default data plane on legacy hosts
3
- * (0.1.0–0.1.5), where the client `settingsScope.bind` face never becomes
4
- * ready (Gate 0: status "unavailable", writes rejected) and configForms does
5
- * not exist. Speaks HTTP to the settings bridge route (settings-bridge.ts)
6
- * and implements the same `SettingsScope` face the configForms scope builds,
7
- * so the selector components stay generation-agnostic.
8
- *
9
- * Detection-free by design (audit P1-9): no property probing, no timeouts —
10
- * the bridge works on every line, and on 0.1.7+ the configForms scoped
11
- * sub-inject resolves and replaces this scope with the native one.
12
- */
13
- import type { ScopeSnapshot, SettingsScope } from './scope-face.ts'
14
- import { decodeSettings } from './decode.ts'
15
- import type { ContextCompressionSettings } from './CompressionProfileSelector.tsx'
16
-
17
- const SETTINGS_ROUTE = '/api/dsh-context-compression-improved/settings'
18
- const POLL_MS = 4000
19
-
20
- export interface BridgeScope extends SettingsScope<ContextCompressionSettings> {
21
- /** Kick an immediate refresh (called once at apply). */
22
- refresh(): void
23
- }
24
-
25
- export function createBridgeScope(): BridgeScope {
26
- let snapshot: ScopeSnapshot<ContextCompressionSettings> = {
27
- status: 'loading', value: undefined, revision: undefined,
28
- writable: true, base: undefined, user: undefined, mode: 'host',
29
- }
30
- const listeners = new Set<() => void>()
31
- let pollTimer: ReturnType<typeof setInterval> | undefined
32
-
33
- const emit = () => { for (const listener of listeners) listener() }
34
-
35
- const applyDoc = (doc: unknown, revision: number | undefined): void => {
36
- const value = decodeSettings(doc)
37
- const next: ScopeSnapshot<ContextCompressionSettings> = {
38
- status: value === undefined ? 'unavailable' : 'ready',
39
- value,
40
- revision,
41
- writable: true,
42
- base: undefined,
43
- user: undefined,
44
- mode: 'host',
45
- }
46
- if (JSON.stringify(next) !== JSON.stringify(snapshot)) {
47
- snapshot = next
48
- emit()
49
- }
50
- }
51
-
52
- async function refresh(): Promise<void> {
53
- try {
54
- const response = await fetch(SETTINGS_ROUTE, { headers: { 'cache-control': 'no-cache' } })
55
- if (!response.ok) throw new Error(`settings bridge ${response.status}`)
56
- const body = await response.json() as { doc?: unknown; revision?: number | null }
57
- applyDoc(body.doc, body.revision ?? undefined)
58
- } catch {
59
- if (snapshot.status !== 'unavailable') {
60
- snapshot = { ...snapshot, status: 'unavailable' }
61
- emit()
62
- }
63
- }
64
- }
65
-
66
- async function writeDoc(next: ContextCompressionSettings): Promise<boolean> {
67
- const response = await fetch(SETTINGS_ROUTE, {
68
- method: 'POST',
69
- headers: { 'content-type': 'application/json' },
70
- body: JSON.stringify({ doc: next }),
71
- })
72
- if (!response.ok) return false
73
- const body = await response.json() as { ok?: boolean; doc?: unknown }
74
- if (body.ok !== true) return false
75
- applyDoc(body.doc ?? next, (snapshot.revision ?? 0) + 1)
76
- return true
77
- }
78
-
79
- const cloneDoc = (): ContextCompressionSettings => {
80
- const value = snapshot.value
81
- return (value === undefined ? {} : structuredClone(value)) as ContextCompressionSettings
82
- }
83
-
84
- const scope: BridgeScope = {
85
- getSnapshot: () => snapshot,
86
- subscribe: (listener) => {
87
- listeners.add(listener)
88
- if (listeners.size === 1) {
89
- void refresh()
90
- pollTimer = setInterval(() => { void refresh() }, POLL_MS)
91
- }
92
- return () => {
93
- listeners.delete(listener)
94
- if (listeners.size === 0 && pollTimer !== undefined) {
95
- clearInterval(pollTimer)
96
- pollTimer = undefined
97
- }
98
- }
99
- },
100
- set: async (field, value) => {
101
- const next = cloneDoc() as unknown as Record<string, unknown>
102
- next[field] = value
103
- return writeDoc(next as unknown as ContextCompressionSettings)
104
- },
105
- unset: async (field) => {
106
- const next = cloneDoc() as unknown as Record<string, unknown>
107
- delete next[field]
108
- return writeDoc(next as unknown as ContextCompressionSettings)
109
- },
110
- mutate: async (ops) => {
111
- const doc = cloneDoc() as unknown as Record<string, unknown>
112
- for (const op of ops) {
113
- const [head, key] = op.path as [string, string]
114
- if (head !== 'presetOptions') return false
115
- const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
116
- if (op.op === 'unset') delete section[key]
117
- else section[key] = (op as { value?: unknown }).value
118
- doc.presetOptions = section
119
- }
120
- return writeDoc(doc as unknown as ContextCompressionSettings)
121
- },
122
- refresh: () => { void refresh() },
123
- }
124
- return scope
125
- }
@@ -1,68 +0,0 @@
1
- /** Browser-safe settings decoding shared by the client entry and node tests. */
2
-
3
- import {
4
- canonicalizeCustomPolicy,
5
- COMPRESSION_PROFILES,
6
- DEFAULT_PTC_COMPRESSION_POLICY,
7
- decodeAutoCompactSettings,
8
- decodeCodeSkeletonSettings,
9
- decodeIntentSummarySettings,
10
- decodeMonitorPanelSettings,
11
- decodePresetOptionsSettings,
12
- decodeSedimentSettings,
13
- isCustomCompressionPolicy,
14
- isPlainRecord,
15
- type CompressionProfile,
16
- type ContextCompressionSettings,
17
- } from '../profiles.ts'
18
-
19
- /**
20
- * Decode one stored context-compression settings document with exactly the
21
- * runtime schema's strictness: a plain object with only `profile`, `custom`,
22
- * `autoCompact`, `codeSkeleton`, and `intentSummary` keys, a supported profile, a valid Custom
23
- * document canonicalized to v3 exactly as the runtime resolver would, a
24
- * strictly-shaped autoCompact section (absent inherits the 80% default), and
25
- * a strictly-shaped codeSkeleton gate (absent inherits off). Anything else
26
- * decodes to `undefined` so the UI reports the document as unreadable instead
27
- * of silently disagreeing with the runtime.
28
- */
29
- export function decodeSettings(value: unknown): ContextCompressionSettings | undefined {
30
- if (!isPlainRecord(value)) return undefined
31
- const keys = Object.keys(value)
32
- if (keys.some(key => key !== 'profile' && key !== 'custom' && key !== 'ptcCustom' && key !== 'autoCompact' && key !== 'codeSkeleton' && key !== 'intentSummary' && key !== 'monitorPanel' && key !== 'sediment' && key !== 'presetOptions')) {
33
- return undefined
34
- }
35
- const profile = (value as { profile?: unknown }).profile
36
- const custom = (value as { custom?: unknown }).custom
37
- const ptcCustomRaw = (value as { ptcCustom?: unknown }).ptcCustom
38
- const ptcCustom = ptcCustomRaw === undefined
39
- ? DEFAULT_PTC_COMPRESSION_POLICY
40
- : isCustomCompressionPolicy(ptcCustomRaw) ? canonicalizeCustomPolicy(ptcCustomRaw) : undefined
41
- const autoCompact = decodeAutoCompactSettings((value as { autoCompact?: unknown }).autoCompact)
42
- const codeSkeleton = decodeCodeSkeletonSettings((value as { codeSkeleton?: unknown }).codeSkeleton)
43
- const intentSummary = decodeIntentSummarySettings((value as { intentSummary?: unknown }).intentSummary)
44
- const monitorPanel = decodeMonitorPanelSettings((value as { monitorPanel?: unknown }).monitorPanel)
45
- const sediment = decodeSedimentSettings((value as { sediment?: unknown }).sediment)
46
- const presetOptions = decodePresetOptionsSettings((value as { presetOptions?: unknown }).presetOptions)
47
- return typeof profile === 'string'
48
- && (COMPRESSION_PROFILES as readonly string[]).includes(profile)
49
- && isCustomCompressionPolicy(custom)
50
- && ptcCustom !== undefined
51
- && autoCompact !== undefined
52
- && codeSkeleton !== undefined
53
- && intentSummary !== undefined
54
- && monitorPanel !== undefined
55
- && sediment !== undefined
56
- ? {
57
- profile: profile as CompressionProfile,
58
- custom: canonicalizeCustomPolicy(custom),
59
- ptcCustom,
60
- autoCompact,
61
- codeSkeleton,
62
- intentSummary,
63
- ...monitorPanel === undefined ? {} : { monitorPanel },
64
- sediment,
65
- ...presetOptions === undefined ? {} : { presetOptions },
66
- }
67
- : undefined
68
- }