dsh-context-compression-improved 0.9.7 → 0.9.9-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +15 -98
  3. package/README.zh.md +14 -92
  4. package/THIRD_PARTY_NOTICES.md +32 -14
  5. package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +27 -27
  6. package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +2 -2
  7. package/{packages/selector/lib → lib}/client.d.ts +16 -0
  8. package/{packages/selector/lib → lib}/client.js +393 -116
  9. package/{packages/selector/lib → lib}/index.js +829 -10
  10. package/{packages/selector/lib → lib}/invariant.js +2 -1
  11. package/{packages/selector/lib → lib}/pruner.d.ts +1 -1
  12. package/{packages/selector/lib → lib}/pruner.js +77 -983
  13. package/lib/savings-integral.js +4515 -0
  14. package/{packages/selector/lib → lib}/tail-trim.js +2 -90
  15. package/lib/tool-result.js +150 -0
  16. package/package.json +129 -116
  17. package/screenshots.json +3 -6
  18. package/.gitattributes +0 -2
  19. package/.githooks/pre-push +0 -37
  20. package/.github/workflows/ci.yml +0 -39
  21. package/CHANGELOG.de.md +0 -580
  22. package/CHANGELOG.es.md +0 -588
  23. package/CHANGELOG.fr.md +0 -576
  24. package/CHANGELOG.it.md +0 -577
  25. package/CHANGELOG.ja.md +0 -261
  26. package/CHANGELOG.ko.md +0 -254
  27. package/CHANGELOG.md +0 -532
  28. package/CHANGELOG.ru.md +0 -554
  29. package/CHANGELOG.zh.md +0 -236
  30. package/CONTRIBUTING.md +0 -22
  31. package/README.de.md +0 -96
  32. package/README.es.md +0 -96
  33. package/README.fr.md +0 -96
  34. package/README.it.md +0 -96
  35. package/README.ja.md +0 -102
  36. package/README.ko.md +0 -102
  37. package/README.ru.md +0 -96
  38. package/SECURITY.md +0 -18
  39. package/assets/board.png +0 -0
  40. package/assets/context.png +0 -0
  41. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  42. package/docs/assets/context-compression-selector-settings.png +0 -0
  43. package/docs/compat-0.1.5-report.md +0 -77
  44. package/docs/installation.de.md +0 -104
  45. package/docs/installation.es.md +0 -104
  46. package/docs/installation.fr.md +0 -104
  47. package/docs/installation.it.md +0 -104
  48. package/docs/installation.ja.md +0 -78
  49. package/docs/installation.ko.md +0 -78
  50. package/docs/installation.md +0 -103
  51. package/docs/installation.ru.md +0 -104
  52. package/docs/installation.zh.md +0 -100
  53. package/docs/repair-log.md +0 -657
  54. package/eslint.config.js +0 -30
  55. package/packages/selector/LICENSE +0 -21
  56. package/packages/selector/README.md +0 -26
  57. package/packages/selector/README.zh.md +0 -24
  58. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  59. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  60. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  61. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  62. package/packages/selector/lib/config.js +0 -1777
  63. package/packages/selector/lib/host-generation.js +0 -62
  64. package/packages/selector/lib/style.css +0 -350
  65. package/packages/selector/package.json +0 -174
  66. package/packages/selector/screenshots.json +0 -3
  67. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -293
  68. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  69. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -85
  70. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  71. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  72. package/packages/selector/src/client/bridge-scope.ts +0 -125
  73. package/packages/selector/src/client/decode.ts +0 -57
  74. package/packages/selector/src/client/index.ts +0 -421
  75. package/packages/selector/src/client/locales/de.ts +0 -142
  76. package/packages/selector/src/client/locales/es.ts +0 -142
  77. package/packages/selector/src/client/locales/fr.ts +0 -142
  78. package/packages/selector/src/client/locales/it.ts +0 -142
  79. package/packages/selector/src/client/locales/ja.ts +0 -142
  80. package/packages/selector/src/client/locales/ko.ts +0 -142
  81. package/packages/selector/src/client/locales/ru.ts +0 -142
  82. package/packages/selector/src/client/locales.ts +0 -284
  83. package/packages/selector/src/client/monitor-fab.ts +0 -349
  84. package/packages/selector/src/client/preset-options.ts +0 -88
  85. package/packages/selector/src/client/savings-card.tsx +0 -150
  86. package/packages/selector/src/client/scope-face.ts +0 -24
  87. package/packages/selector/src/client/settings-section.tsx +0 -140
  88. package/packages/selector/src/compat/host-generation.ts +0 -96
  89. package/packages/selector/src/compat/llm-messages.ts +0 -50
  90. package/packages/selector/src/compat/settings-lease.ts +0 -108
  91. package/packages/selector/src/compat/tool-result.ts +0 -91
  92. package/packages/selector/src/css-modules.d.ts +0 -6
  93. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  94. package/packages/selector/src/estimator-catalog.ts +0 -104
  95. package/packages/selector/src/index.ts +0 -655
  96. package/packages/selector/src/invariant.ts +0 -113
  97. package/packages/selector/src/preset-overlay.ts +0 -749
  98. package/packages/selector/src/profiles.ts +0 -431
  99. package/packages/selector/src/pruner/content.ts +0 -198
  100. package/packages/selector/src/pruner/session.ts +0 -97
  101. package/packages/selector/src/pruner/state.ts +0 -61
  102. package/packages/selector/src/pruner/tuning.ts +0 -23
  103. package/packages/selector/src/pruner/types.ts +0 -78
  104. package/packages/selector/src/pruner.ts +0 -2868
  105. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  106. package/packages/selector/src/runtime/audit.ts +0 -303
  107. package/packages/selector/src/runtime/config.ts +0 -756
  108. package/packages/selector/src/runtime/custom-policy.ts +0 -278
  109. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  110. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  111. package/packages/selector/src/runtime/measurement.ts +0 -444
  112. package/packages/selector/src/runtime/monitor.ts +0 -235
  113. package/packages/selector/src/runtime/reducers.ts +0 -1754
  114. package/packages/selector/src/runtime/retrieve.ts +0 -484
  115. package/packages/selector/src/runtime/savings-projection.ts +0 -226
  116. package/packages/selector/src/runtime/savings.ts +0 -417
  117. package/packages/selector/src/runtime/session-events.ts +0 -30
  118. package/packages/selector/src/runtime/summary-command.ts +0 -127
  119. package/packages/selector/src/runtime/tail-trim.ts +0 -176
  120. package/packages/selector/src/runtime/token-count.ts +0 -72
  121. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  122. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  123. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  124. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  125. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -81
  126. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  127. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  128. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  129. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  130. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  131. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -128
  132. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  133. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  134. package/packages/selector/src/runtime/toolclass.ts +0 -103
  135. package/packages/selector/src/runtime/types.ts +0 -365
  136. package/packages/selector/src/runtime/value.ts +0 -48
  137. package/packages/selector/src/settings-bridge.ts +0 -175
  138. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  139. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  140. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  141. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  142. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  143. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  144. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  145. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  146. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  147. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -199
  148. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  149. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  150. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  151. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  152. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  153. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  154. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  155. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -138
  156. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  157. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  158. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  159. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  160. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -86
  161. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  162. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  163. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  164. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  165. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  166. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  167. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  168. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  169. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  170. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  171. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  172. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  173. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  174. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  175. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  176. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  177. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  178. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  179. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  180. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  181. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  182. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  183. package/packages/selector/tests/runtime/monitor.spec.ts +0 -301
  184. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  185. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2782
  186. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  187. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  188. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  189. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  190. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  191. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  192. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  193. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  194. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  195. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  196. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  197. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  198. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  199. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  200. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -119
  201. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  202. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  203. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  204. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  205. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  206. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  207. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  208. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  209. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  210. package/packages/selector/tsconfig.json +0 -11
  211. package/packages/selector/tsdown.client.config.ts +0 -102
  212. package/packages/selector/tsdown.config.ts +0 -20
  213. package/pnpm-workspace.yaml +0 -72
  214. package/scripts/capture-profile-baseline.mjs +0 -42
  215. package/scripts/cell-browser-e2e.mjs +0 -354
  216. package/scripts/generate-tokenizer-fixtures.py +0 -81
  217. package/scripts/generate-vision-fixtures.py +0 -208
  218. package/scripts/hosts.mjs +0 -77
  219. package/scripts/packed-components-smoke.mjs +0 -763
  220. package/scripts/packed-install-e2e.mjs +0 -1346
  221. package/scripts/sync-hosts.mjs +0 -174
  222. package/scripts/toolclass-corpus-replay.mjs +0 -281
  223. package/scripts/verify-release.mjs +0 -335
  224. package/tests/TEST_INVENTORY.md +0 -41
  225. package/tsconfig.base.json +0 -18
  226. package/tsconfig.json +0 -7
  227. package/tsconfig.tests.json +0 -15
  228. package/vitest.built.config.ts +0 -9
  229. package/vitest.config.ts +0 -46
  230. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  231. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  232. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  233. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  234. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  235. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  236. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  237. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  238. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  239. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  240. /package/{packages/selector/lib → lib}/profiles.d.ts +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,57 +0,0 @@
1
- /** Browser-safe settings decoding shared by the client entry and node tests. */
2
-
3
- import {
4
- canonicalizeCustomPolicy,
5
- COMPRESSION_PROFILES,
6
- decodeAutoCompactSettings,
7
- decodeCodeSkeletonSettings,
8
- decodeIntentSummarySettings,
9
- decodeMonitorPanelSettings,
10
- decodePresetOptionsSettings,
11
- isCustomCompressionPolicy,
12
- isPlainRecord,
13
- type CompressionProfile,
14
- type ContextCompressionSettings,
15
- } from '../profiles.ts'
16
-
17
- /**
18
- * Decode one stored context-compression settings document with exactly the
19
- * runtime schema's strictness: a plain object with only `profile`, `custom`,
20
- * `autoCompact`, `codeSkeleton`, and `intentSummary` keys, a supported profile, a valid Custom
21
- * document canonicalized to v3 exactly as the runtime resolver would, a
22
- * strictly-shaped autoCompact section (absent inherits the 80% default), and
23
- * a strictly-shaped codeSkeleton gate (absent inherits off). Anything else
24
- * decodes to `undefined` so the UI reports the document as unreadable instead
25
- * of silently disagreeing with the runtime.
26
- */
27
- export function decodeSettings(value: unknown): ContextCompressionSettings | undefined {
28
- if (!isPlainRecord(value)) return undefined
29
- const keys = Object.keys(value)
30
- if (keys.some(key => key !== 'profile' && key !== 'custom' && key !== 'autoCompact' && key !== 'codeSkeleton' && key !== 'intentSummary' && key !== 'monitorPanel' && key !== 'presetOptions')) {
31
- return undefined
32
- }
33
- const profile = (value as { profile?: unknown }).profile
34
- const custom = (value as { custom?: unknown }).custom
35
- const autoCompact = decodeAutoCompactSettings((value as { autoCompact?: unknown }).autoCompact)
36
- const codeSkeleton = decodeCodeSkeletonSettings((value as { codeSkeleton?: unknown }).codeSkeleton)
37
- const intentSummary = decodeIntentSummarySettings((value as { intentSummary?: unknown }).intentSummary)
38
- const monitorPanel = decodeMonitorPanelSettings((value as { monitorPanel?: unknown }).monitorPanel)
39
- const presetOptions = decodePresetOptionsSettings((value as { presetOptions?: unknown }).presetOptions)
40
- return typeof profile === 'string'
41
- && (COMPRESSION_PROFILES as readonly string[]).includes(profile)
42
- && isCustomCompressionPolicy(custom)
43
- && autoCompact !== undefined
44
- && codeSkeleton !== undefined
45
- && intentSummary !== undefined
46
- && monitorPanel !== undefined
47
- ? {
48
- profile: profile as CompressionProfile,
49
- custom: canonicalizeCustomPolicy(custom),
50
- autoCompact,
51
- codeSkeleton,
52
- intentSummary,
53
- ...monitorPanel === undefined ? {} : { monitorPanel },
54
- ...presetOptions === undefined ? {} : { presetOptions },
55
- }
56
- : undefined
57
- }