dsh-context-compression-improved 0.6.4 → 0.7.0-beta.1

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 (75) hide show
  1. package/CHANGELOG.ja.md +51 -0
  2. package/CHANGELOG.ko.md +47 -0
  3. package/CHANGELOG.md +72 -0
  4. package/CHANGELOG.zh.md +47 -0
  5. package/README.ja.md +2 -2
  6. package/README.ko.md +2 -2
  7. package/README.md +6 -3
  8. package/README.zh.md +3 -2
  9. package/eslint.config.js +76 -30
  10. package/package.json +164 -162
  11. package/packages/selector/dsh.plugin.json +16 -16
  12. package/packages/selector/lib/client.js +16 -4
  13. package/packages/selector/lib/index.js +92 -1
  14. package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
  15. package/packages/selector/lib/profiles.d.ts +9 -0
  16. package/packages/selector/lib/pruner.d.ts +59 -0
  17. package/packages/selector/lib/pruner.js +410 -8
  18. package/packages/selector/package.json +114 -114
  19. package/packages/selector/src/client/decode.ts +6 -2
  20. package/packages/selector/src/client/index.ts +213 -232
  21. package/packages/selector/src/client/scope-face.ts +24 -24
  22. package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
  23. package/packages/selector/src/index.ts +418 -412
  24. package/packages/selector/src/preset-overlay.ts +3 -0
  25. package/packages/selector/src/profiles.ts +30 -10
  26. package/packages/selector/src/pruner/content.ts +1 -1
  27. package/packages/selector/src/pruner/state.ts +7 -0
  28. package/packages/selector/src/pruner.ts +253 -10
  29. package/packages/selector/src/runtime/audit.ts +17 -0
  30. package/packages/selector/src/runtime/config.ts +36 -11
  31. package/packages/selector/src/runtime/reducers.ts +1 -1
  32. package/packages/selector/src/runtime/summary-command.ts +133 -0
  33. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +46 -1
  34. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +55 -0
  35. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  36. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  37. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  38. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  39. package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
  40. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +4 -1
  41. package/packages/selector/src/runtime/types.ts +12 -0
  42. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
  43. package/packages/selector/tests/built/client-artifact.spec.ts +2 -0
  44. package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
  45. package/packages/selector/tests/custom-contract.client.spec.ts +3 -2
  46. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  47. package/packages/selector/tests/helpers/legacy-namespace.ts +8 -4
  48. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
  49. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
  50. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
  51. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
  52. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
  53. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -206
  54. package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
  55. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -206
  56. package/packages/selector/tests/profiles.client.spec.tsx +436 -434
  57. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  58. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -233
  59. package/packages/selector/tests/runtime/audit.spec.ts +275 -274
  60. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
  61. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
  62. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  63. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  64. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2736 -2727
  65. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  66. package/packages/selector/tests/settings-seat.client.spec.ts +165 -165
  67. package/packages/selector/tests/standing-generation.host.spec.ts +704 -704
  68. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +18 -2
  69. package/packages/selector/tests/support/ui-primitives.tsx +34 -34
  70. package/pnpm-workspace.yaml +1 -1
  71. package/scripts/packed-components-smoke.mjs +2 -0
  72. package/scripts/packed-install-e2e.mjs +1275 -1273
  73. package/scripts/verify-release.mjs +318 -317
  74. package/tsconfig.tests.json +3 -1
  75. package/vitest.config.ts +14 -0
@@ -88,6 +88,7 @@ describe('context compression browser contract', () => {
88
88
  custom: structuredClone(CUSTOM),
89
89
  autoCompact: { thresholdPercent: 80 },
90
90
  codeSkeleton: { enabled: false },
91
+ intentSummary: { enabled: false },
91
92
  }
92
93
  const snapshot = (): ScopeSnapshot<ContextCompressionSettings> => ({
93
94
  status: 'ready',
@@ -153,10 +154,10 @@ describe('context compression browser contract', () => {
153
154
  getSnapshot: () => ({ ...snapshot(), value: { settings: value } }),
154
155
  subscribe: scope.subscribe,
155
156
  set: async (_field: string, doc: unknown) => {
156
- const next = doc as unknown as Record<string, unknown>
157
+ const next = doc as Record<string, unknown>
157
158
  for (const key of Object.keys(next)) {
158
159
  if (JSON.stringify((value as unknown as Record<string, unknown>)[key]) !== JSON.stringify(next[key])) {
159
- await scope.set(key, (next as Record<string, unknown>)[key])
160
+ await scope.set(key, (next)[key])
160
161
  }
161
162
  }
162
163
  return true
@@ -1,252 +1,252 @@
1
- // @vitest-environment jsdom
2
-
3
- import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
- import { useSyncExternalStore } from 'react'
5
- import { afterEach, describe, expect, it, vi } from 'vitest'
6
- import {
7
- ContextCompressionSettingsSection,
8
- type CompressionProfileSelectorProps,
9
- type ContextCompressionSettings,
10
- } from '../src/client/CompressionProfileSelector.tsx'
11
- import { en } from '../src/client/locales.ts'
12
-
13
- afterEach(() => {
14
- cleanup()
15
- vi.unstubAllGlobals()
16
- })
17
-
18
- interface SettingsScopeSnapshot<T> {
19
- status: 'loading' | 'ready' | 'unavailable'
20
- value: T | undefined
21
- base: T | undefined
22
- user: T | undefined
23
- revision: number | undefined
24
- writable: boolean
25
- mode: 'host' | 'memory'
26
- }
27
-
28
- interface SnapshotStore<T> {
29
- readonly getSnapshot: () => T
30
- readonly subscribe: (listener: () => void) => () => void
31
- }
32
-
33
- function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
34
- const snapshot = structuredClone(initial)
35
- const listeners = new Set<() => void>()
36
- return {
37
- getSnapshot: () => snapshot,
38
- subscribe(listener) {
39
- listeners.add(listener)
40
- return () => { listeners.delete(listener) }
41
- },
42
- }
43
- }
44
-
45
- function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
46
- return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
47
- return useSyncExternalStore(
48
- store.subscribe,
49
- () => selector(store.getSnapshot()),
50
- () => selector(store.getSnapshot()),
51
- )
52
- }
53
- }
54
-
55
- const DEFAULT_CUSTOM = {
56
- version: 1,
57
- unit: 'tokens',
58
- fresh: { enabled: true, trigger: 4_096, target: 2_048 },
59
- aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
60
- history: {
61
- enabled: true,
62
- trigger: 32_768,
63
- keepRecentTurns: 2,
64
- keepRecent: 16_384,
65
- minReclaim: 8_192,
66
- },
67
- prefixPolicy: 'pressure-break',
68
- } as const satisfies ContextCompressionSettings['custom']
69
-
70
- const t = (key: string) => en[key as keyof typeof en] ?? key
71
-
72
- const PROVIDER_LABEL = 'Provider'
73
- const CHANNEL_LABEL = 'Channel'
74
- const MODEL_LABEL = 'Model'
75
- const API_KEY_LABEL = 'API key (write-only, never echoed)'
76
- const BASE_URL_LABEL = 'Endpoint base URL (/v1)'
77
-
78
- const CATALOG = {
79
- ok: true,
80
- providers: [
81
- {
82
- id: 'local-35b',
83
- name: 'local-35b',
84
- models: [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen3.6-35B-A3B' }, { id: 'Qwen38-27B', name: 'Qwen38-27B' }],
85
- },
86
- { id: 'deepseek-official', name: 'DeepSeek', models: [{ id: 'deepseek-flash', name: 'DeepSeek-V41-Flash' }] },
87
- ],
88
- selection: { provider: 'deepseek-official', model: 'deepseek-flash' },
89
- }
90
-
91
- function mountEstimator(
92
- presetOptions: ContextCompressionSettings['presetOptions'],
93
- options: { readonly catalog?: unknown, readonly profile?: ContextCompressionSettings['profile'] } = {},
94
- ) {
95
- const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
96
- status: 'ready',
97
- value: {
98
- profile: options.profile ?? 'tokenpilot-inspired',
99
- custom: structuredClone(DEFAULT_CUSTOM),
100
- autoCompact: { thresholdPercent: 80 },
101
- codeSkeleton: { enabled: false },
102
- presetOptions: presetOptions ?? {},
103
- },
104
- base: undefined,
105
- user: undefined,
106
- revision: 0,
107
- writable: true,
108
- mode: 'host',
109
- })
110
- const savePresetOptions = vi.fn(() => Promise.resolve())
111
- if (options.catalog !== undefined) {
112
- vi.stubGlobal('fetch', vi.fn(() => Promise.resolve({
113
- ok: true,
114
- json: () => Promise.resolve(options.catalog),
115
- })))
116
- }
117
- render(<ContextCompressionSettingsSection {...({
118
- useCompression: bindSnapshotSelector(state),
119
- select: vi.fn(() => Promise.resolve()),
120
- saveCustom: vi.fn(() => Promise.resolve()),
121
- resetCustom: vi.fn(() => Promise.resolve()),
122
- saveAutoCompact: vi.fn(() => Promise.resolve()),
123
- saveCodeSkeleton: vi.fn(() => Promise.resolve()),
124
- savePresetOptions,
125
- t,
126
- } as unknown as CompressionProfileSelectorProps)} />)
127
- return { savePresetOptions }
128
- }
129
-
130
- describe('estimator channel card', () => {
131
- it('host mode fills comboboxes from the catalog, keeps custom typing, and asks for no API key', async () => {
132
- const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' }, { catalog: CATALOG })
133
-
134
- // Provider/model are always comboboxes (dsh-perm-gate receiver pattern):
135
- // a catalog pick fills the field, and the same input accepts a custom id.
136
- const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
137
- const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
138
- await waitFor(() => {
139
- const providerOptions = document.querySelectorAll('#estimator-provider-options option')
140
- expect([...providerOptions].map(option => (option as HTMLOptionElement).value))
141
- .toEqual(['local-35b', 'deepseek-official'])
142
- expect(provider.getAttribute('list')).toBe('estimator-provider-options')
143
- expect(model.getAttribute('list')).toBe('estimator-model-options')
144
- })
145
- expect(screen.getByText(/Effective route: deepseek-official \/ deepseek-flash/)).not.toBeNull()
146
- expect(screen.getByText(/no API key is needed/)).not.toBeNull()
147
-
148
- // No credential input and no base-URL field on this channel.
149
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
150
- expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
151
- expect(document.querySelectorAll('input[type="password"]').length).toBe(0)
152
-
153
- // A datalist pick fires change without blur: it commits immediately.
154
- fireEvent.change(provider, { target: { value: 'local-35b' } })
155
- await waitFor(() => {
156
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'local-35b' })
157
- })
158
- // Free typing only commits on blur, so mid-edit keystrokes never save.
159
- fireEvent.change(provider, { target: { value: 'my-custom-group' } })
160
- expect(savePresetOptions).not.toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
161
- fireEvent.blur(provider)
162
- await waitFor(() => {
163
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
164
- })
165
- })
166
-
167
- it('offers the catalog models of the chosen provider and commits one', async () => {
168
- const { savePresetOptions } = mountEstimator(
169
- { estimatorMode: 'host', estimatorProvider: 'local-35b' },
170
- { catalog: CATALOG },
171
- )
172
- // Query before the catalog lands: once the datalist has options, the
173
- // label's textContent includes them and getByLabelText's exact match
174
- // would no longer see a bare "Model".
175
- const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
176
- expect(model.value).toBe('')
177
- await waitFor(() => {
178
- const modelOptions = document.querySelectorAll('#estimator-model-options option')
179
- expect([...modelOptions].map(option => (option as HTMLOptionElement).value))
180
- .toEqual(['Qwen3.6-35B-A3B', 'Qwen38-27B'])
181
- })
182
- expect(screen.getByText(/Effective route: local-35b/)).not.toBeNull()
183
-
184
- fireEvent.change(model, { target: { value: 'Qwen38-27B' } })
185
- await waitFor(() => {
186
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorModel: 'Qwen38-27B' })
187
- })
188
- })
189
-
190
- it('still accepts custom names — without a credential field — when no catalog is served', async () => {
191
- vi.stubGlobal('fetch', vi.fn(() => Promise.reject(new Error('no route'))))
192
- const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' })
193
-
194
- const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
195
- // The model field stays present and editable without a served catalog.
196
- expect(screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)).toBeTruthy()
197
- expect(document.querySelectorAll('#estimator-provider-options option').length).toBe(0)
198
- expect(document.querySelectorAll('#estimator-model-options option').length).toBe(0)
199
- fireEvent.change(provider, { target: { value: 'manual-group' } })
200
- fireEvent.blur(provider)
201
- await waitFor(() => {
202
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'manual-group' })
203
- })
204
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
205
- expect(screen.getByText(/no API key is needed/)).not.toBeNull()
206
- expect(screen.getByText(/not determined yet/)).not.toBeNull()
207
- })
208
-
209
- it('keeps the endpoint and key fields on the direct channel alone', () => {
210
- mountEstimator({ estimatorMode: 'direct' })
211
-
212
- expect(screen.getByLabelText(BASE_URL_LABEL)).not.toBeNull()
213
- expect(screen.getByLabelText(MODEL_LABEL).tagName).toBe('INPUT')
214
- expect(screen.getByLabelText(API_KEY_LABEL)).not.toBeNull()
215
- expect(document.querySelectorAll('input[type="password"]').length).toBe(1)
216
- expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
217
- expect(screen.queryByText(/no API key is needed/)).toBeNull()
218
- })
219
-
220
- it('renders no channel controls while the estimator is off', () => {
221
- mountEstimator({})
222
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
223
- expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
224
- expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
225
- })
226
-
227
- // Regression guard for the first real-machine report: the card used to render
228
- // nothing at all off tokenpilot-inspired, which reads as a missing feature.
229
- it('keeps the estimator section, and names the unlocking profile, off tokenpilot-inspired', () => {
230
- mountEstimator({}, { profile: 'balanced' })
231
-
232
- // The heading and its stable anchor survive, so the panel is still findable
233
- // where the reader last saw it.
234
- expect(document.getElementById('context-compression-estimator-title')?.textContent)
235
- .toBe('Estimator (optional)')
236
- // The notice names the current profile and the profile that unlocks the card.
237
- const notice = screen.getByText(/ships only with the TokenPilot-inspired profile/)
238
- expect(notice.textContent).toContain('“Balanced”')
239
- expect(notice.textContent).toContain('Select TokenPilot-inspired')
240
- // Gating semantics are unchanged: no channel control exists here.
241
- expect(screen.queryByLabelText(CHANNEL_LABEL)).toBeNull()
242
- expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
243
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
244
- expect(document.querySelectorAll('input[list]').length).toBe(0)
245
- })
246
-
247
- it('drops the inactive notice once tokenpilot-inspired owns the selector', () => {
248
- mountEstimator({})
249
- expect(screen.queryByText(/ships only with the TokenPilot-inspired profile/)).toBeNull()
250
- expect(screen.getByLabelText(CHANNEL_LABEL)).not.toBeNull()
251
- })
252
- })
1
+ // @vitest-environment jsdom
2
+
3
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+ import { useSyncExternalStore } from 'react'
5
+ import { afterEach, describe, expect, it, vi } from 'vitest'
6
+ import {
7
+ ContextCompressionSettingsSection,
8
+ type ContextCompressionSettings,
9
+ } from '../src/client/CompressionProfileSelector.tsx'
10
+ import { en } from '../src/client/locales.ts'
11
+
12
+ afterEach(() => {
13
+ cleanup()
14
+ vi.unstubAllGlobals()
15
+ })
16
+
17
+ interface SettingsScopeSnapshot<T> {
18
+ status: 'loading' | 'ready' | 'unavailable'
19
+ value: T | undefined
20
+ base: T | undefined
21
+ user: T | undefined
22
+ revision: number | undefined
23
+ writable: boolean
24
+ mode: 'host' | 'memory'
25
+ }
26
+
27
+ interface SnapshotStore<T> {
28
+ readonly getSnapshot: () => T
29
+ readonly subscribe: (listener: () => void) => () => void
30
+ }
31
+
32
+ function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
33
+ const snapshot = structuredClone(initial)
34
+ const listeners = new Set<() => void>()
35
+ return {
36
+ getSnapshot: () => snapshot,
37
+ subscribe(listener) {
38
+ listeners.add(listener)
39
+ return () => { listeners.delete(listener) }
40
+ },
41
+ }
42
+ }
43
+
44
+ function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
45
+ return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
46
+ return useSyncExternalStore(
47
+ store.subscribe,
48
+ () => selector(store.getSnapshot()),
49
+ () => selector(store.getSnapshot()),
50
+ )
51
+ }
52
+ }
53
+
54
+ const DEFAULT_CUSTOM = {
55
+ version: 1,
56
+ unit: 'tokens',
57
+ fresh: { enabled: true, trigger: 4_096, target: 2_048 },
58
+ aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
59
+ history: {
60
+ enabled: true,
61
+ trigger: 32_768,
62
+ keepRecentTurns: 2,
63
+ keepRecent: 16_384,
64
+ minReclaim: 8_192,
65
+ },
66
+ prefixPolicy: 'pressure-break',
67
+ } as const satisfies ContextCompressionSettings['custom']
68
+
69
+ const t = (key: string) => en[key as keyof typeof en] ?? key
70
+
71
+ const PROVIDER_LABEL = 'Provider'
72
+ const CHANNEL_LABEL = 'Channel'
73
+ const MODEL_LABEL = 'Model'
74
+ const API_KEY_LABEL = 'API key (write-only, never echoed)'
75
+ const BASE_URL_LABEL = 'Endpoint base URL (/v1)'
76
+
77
+ const CATALOG = {
78
+ ok: true,
79
+ providers: [
80
+ {
81
+ id: 'local-35b',
82
+ name: 'local-35b',
83
+ models: [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen3.6-35B-A3B' }, { id: 'Qwen38-27B', name: 'Qwen38-27B' }],
84
+ },
85
+ { id: 'deepseek-official', name: 'DeepSeek', models: [{ id: 'deepseek-flash', name: 'DeepSeek-V41-Flash' }] },
86
+ ],
87
+ selection: { provider: 'deepseek-official', model: 'deepseek-flash' },
88
+ }
89
+
90
+ function mountEstimator(
91
+ presetOptions: ContextCompressionSettings['presetOptions'],
92
+ options: { readonly catalog?: unknown, readonly profile?: ContextCompressionSettings['profile'] } = {},
93
+ ) {
94
+ const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
95
+ status: 'ready',
96
+ value: {
97
+ profile: options.profile ?? 'tokenpilot-inspired',
98
+ custom: structuredClone(DEFAULT_CUSTOM),
99
+ autoCompact: { thresholdPercent: 80 },
100
+ codeSkeleton: { enabled: false },
101
+ intentSummary: { enabled: false },
102
+ presetOptions: presetOptions ?? {},
103
+ },
104
+ base: undefined,
105
+ user: undefined,
106
+ revision: 0,
107
+ writable: true,
108
+ mode: 'host',
109
+ })
110
+ const savePresetOptions = vi.fn(() => Promise.resolve())
111
+ if (options.catalog !== undefined) {
112
+ vi.stubGlobal('fetch', vi.fn(() => Promise.resolve({
113
+ ok: true,
114
+ json: () => Promise.resolve(options.catalog),
115
+ })))
116
+ }
117
+ render(<ContextCompressionSettingsSection {...({
118
+ useCompression: bindSnapshotSelector(state),
119
+ select: vi.fn(() => Promise.resolve()),
120
+ saveCustom: vi.fn(() => Promise.resolve()),
121
+ resetCustom: vi.fn(() => Promise.resolve()),
122
+ saveAutoCompact: vi.fn(() => Promise.resolve()),
123
+ saveCodeSkeleton: vi.fn(() => Promise.resolve()),
124
+ savePresetOptions,
125
+ t,
126
+ })} />)
127
+ return { savePresetOptions }
128
+ }
129
+
130
+ describe('estimator channel card', () => {
131
+ it('host mode fills comboboxes from the catalog, keeps custom typing, and asks for no API key', async () => {
132
+ const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' }, { catalog: CATALOG })
133
+
134
+ // Provider/model are always comboboxes (dsh-perm-gate receiver pattern):
135
+ // a catalog pick fills the field, and the same input accepts a custom id.
136
+ const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
137
+ const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
138
+ await waitFor(() => {
139
+ const providerOptions = document.querySelectorAll('#estimator-provider-options option')
140
+ expect([...providerOptions].map(option => (option as HTMLOptionElement).value))
141
+ .toEqual(['local-35b', 'deepseek-official'])
142
+ expect(provider.getAttribute('list')).toBe('estimator-provider-options')
143
+ expect(model.getAttribute('list')).toBe('estimator-model-options')
144
+ })
145
+ expect(screen.getByText(/Effective route: deepseek-official \/ deepseek-flash/)).not.toBeNull()
146
+ expect(screen.getByText(/no API key is needed/)).not.toBeNull()
147
+
148
+ // No credential input and no base-URL field on this channel.
149
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
150
+ expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
151
+ expect(document.querySelectorAll('input[type="password"]').length).toBe(0)
152
+
153
+ // A datalist pick fires change without blur: it commits immediately.
154
+ fireEvent.change(provider, { target: { value: 'local-35b' } })
155
+ await waitFor(() => {
156
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'local-35b' })
157
+ })
158
+ // Free typing only commits on blur, so mid-edit keystrokes never save.
159
+ fireEvent.change(provider, { target: { value: 'my-custom-group' } })
160
+ expect(savePresetOptions).not.toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
161
+ fireEvent.blur(provider)
162
+ await waitFor(() => {
163
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
164
+ })
165
+ })
166
+
167
+ it('offers the catalog models of the chosen provider and commits one', async () => {
168
+ const { savePresetOptions } = mountEstimator(
169
+ { estimatorMode: 'host', estimatorProvider: 'local-35b' },
170
+ { catalog: CATALOG },
171
+ )
172
+ // Query before the catalog lands: once the datalist has options, the
173
+ // label's textContent includes them and getByLabelText's exact match
174
+ // would no longer see a bare "Model".
175
+ const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
176
+ expect(model.value).toBe('')
177
+ await waitFor(() => {
178
+ const modelOptions = document.querySelectorAll('#estimator-model-options option')
179
+ expect([...modelOptions].map(option => (option as HTMLOptionElement).value))
180
+ .toEqual(['Qwen3.6-35B-A3B', 'Qwen38-27B'])
181
+ })
182
+ expect(screen.getByText(/Effective route: local-35b/)).not.toBeNull()
183
+
184
+ fireEvent.change(model, { target: { value: 'Qwen38-27B' } })
185
+ await waitFor(() => {
186
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorModel: 'Qwen38-27B' })
187
+ })
188
+ })
189
+
190
+ it('still accepts custom names — without a credential field — when no catalog is served', async () => {
191
+ vi.stubGlobal('fetch', vi.fn(() => Promise.reject(new Error('no route'))))
192
+ const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' })
193
+
194
+ const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
195
+ // The model field stays present and editable without a served catalog.
196
+ expect(screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)).toBeTruthy()
197
+ expect(document.querySelectorAll('#estimator-provider-options option').length).toBe(0)
198
+ expect(document.querySelectorAll('#estimator-model-options option').length).toBe(0)
199
+ fireEvent.change(provider, { target: { value: 'manual-group' } })
200
+ fireEvent.blur(provider)
201
+ await waitFor(() => {
202
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'manual-group' })
203
+ })
204
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
205
+ expect(screen.getByText(/no API key is needed/)).not.toBeNull()
206
+ expect(screen.getByText(/not determined yet/)).not.toBeNull()
207
+ })
208
+
209
+ it('keeps the endpoint and key fields on the direct channel alone', () => {
210
+ mountEstimator({ estimatorMode: 'direct' })
211
+
212
+ expect(screen.getByLabelText(BASE_URL_LABEL)).not.toBeNull()
213
+ expect(screen.getByLabelText(MODEL_LABEL).tagName).toBe('INPUT')
214
+ expect(screen.getByLabelText(API_KEY_LABEL)).not.toBeNull()
215
+ expect(document.querySelectorAll('input[type="password"]').length).toBe(1)
216
+ expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
217
+ expect(screen.queryByText(/no API key is needed/)).toBeNull()
218
+ })
219
+
220
+ it('renders no channel controls while the estimator is off', () => {
221
+ mountEstimator({})
222
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
223
+ expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
224
+ expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
225
+ })
226
+
227
+ // Regression guard for the first real-machine report: the card used to render
228
+ // nothing at all off tokenpilot-inspired, which reads as a missing feature.
229
+ it('keeps the estimator section, and names the unlocking profile, off tokenpilot-inspired', () => {
230
+ mountEstimator({}, { profile: 'balanced' })
231
+
232
+ // The heading and its stable anchor survive, so the panel is still findable
233
+ // where the reader last saw it.
234
+ expect(document.getElementById('context-compression-estimator-title')?.textContent)
235
+ .toBe('Estimator (optional)')
236
+ // The notice names the current profile and the profile that unlocks the card.
237
+ const notice = screen.getByText(/ships only with the TokenPilot-inspired profile/)
238
+ expect(notice.textContent).toContain('“Balanced”')
239
+ expect(notice.textContent).toContain('Select TokenPilot-inspired')
240
+ // Gating semantics are unchanged: no channel control exists here.
241
+ expect(screen.queryByLabelText(CHANNEL_LABEL)).toBeNull()
242
+ expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
243
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
244
+ expect(document.querySelectorAll('input[list]').length).toBe(0)
245
+ })
246
+
247
+ it('drops the inactive notice once tokenpilot-inspired owns the selector', () => {
248
+ mountEstimator({})
249
+ expect(screen.queryByText(/ships only with the TokenPilot-inspired profile/)).toBeNull()
250
+ expect(screen.getByLabelText(CHANNEL_LABEL)).not.toBeNull()
251
+ })
252
+ })
@@ -6,6 +6,7 @@
6
6
  * and falls back to this namespace; on a real 0.1.7 host neither the
7
7
  * registration nor this helper exists.
8
8
  */
9
+ import type { Context } from '@deepseek-ai/cordis'
9
10
  import {
10
11
  CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
11
12
  ContextCompressionSettingsSchema,
@@ -13,13 +14,16 @@ import {
13
14
 
14
15
  export const LegacyNamespaceRegistrar = {
15
16
  name: 'context-compression:test/legacy-namespace-registrar',
16
- async apply(ctx: {
17
- inject(deps: readonly string[], fn: (s: { settings: { register(ns: never, schema: unknown): unknown } }) => void): void
18
- }): Promise<void> {
17
+ async apply(ctx: Context): Promise<void> {
19
18
  await new Promise<void>((resolve) => {
20
19
  ctx.inject(['settings'], (s) => {
21
20
  try {
22
- s.settings.register(
21
+ // The test host mounts a vendored 0.1.5-shaped provider whose
22
+ // static type is the 0.1.7 Context augmentation (`SettingsForms`);
23
+ // narrow to the legacy registry surface at the seam.
24
+ ;(s.settings as unknown as {
25
+ register(ns: never, schema: unknown): unknown
26
+ }).register(
23
27
  CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never,
24
28
  ContextCompressionSettingsSchema,
25
29
  )
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Legacy test-host settings seam.
3
+ *
4
+ * Vendored verbatim from `@deepseek-ai/dsh-settings@0.1.5-rc.2`
5
+ * (`lib/types/index.js` + `lib/types/redact.js`, with the
6
+ * `@deepseek-ai/dsh-util-values@0.1.5-rc.2` helpers inlined as
7
+ * `./legacy/util-values.js`): the 0.1.7 host replaced the
8
+ * namespace-registry provider with declarative `SettingsForms`, while the
9
+ * plugin keeps the legacy `ctx.settings.get(ns)` read as a host-shape
10
+ * fallback (see src/index.ts). The host specs mount a provider subclassing
11
+ * this base to exercise exactly that fallback against the real 0.1.7
12
+ * baseline. Type declarations: `./legacy/provider.d.ts`.
13
+ */
14
+ export { SettingsProvider as LegacySettingsProvider } from './legacy/provider.js'
15
+
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Narrow type surface for the vendored 0.1.5 `SettingsProvider` (legacy test-host seam).
3
+ *
4
+ * The 0.1.7 `@deepseek-ai/dsh-settings` host replaced the namespace-registry
5
+ * provider with the declarative `SettingsForms` projector, but the plugin
6
+ * deliberately keeps the legacy `ctx.settings.get(ns)` read as a fallback
7
+ * "so a host that still serves the old service shape keeps working (test
8
+ * hosts do exactly that)" (src/index.ts). The host specs drive that fallback
9
+ * through this vendored base class — the verbatim 0.1.5-rc.2 implementation,
10
+ * not a behavioral re-implementation.
11
+ *
12
+ * Only the members the specs and the production fallback actually touch are
13
+ * declared; the full 0.1.5 surface exists at runtime in provider.js.
14
+ */
15
+ import { Service } from '@deepseek-ai/cordis'
16
+
17
+ export declare abstract class SettingsProvider extends Service {
18
+ /** Register as the `settings` service of `ctx` (implementation: `super(ctx, 'settings')`). */
19
+ constructor(ctx: Context)
20
+ /** Whether {@linkcode LegacySettingsProvider.update} may persist through this provider. */
21
+ abstract readonly writable: boolean
22
+ /** Load the provider's raw document (namespace → raw section) once at init. */
23
+ protected abstract load(): Promise<Record<string, unknown>>
24
+ /** Durably store one namespace's merged user section. */
25
+ protected abstract persist(ns: string, section: Record<string, unknown>): Promise<void>
26
+ /** Register a namespace schema; duplicate registration fails loud. */
27
+ register(ns: string, schema: unknown, options?: unknown): unknown
28
+ /** Read one registered namespace's resolved value (undefined while unregistered). */
29
+ get(ns: string): unknown
30
+ /** Merge a patch into one registered namespace's user layer, validate, persist. */
31
+ update(ns: string, patch: object, expectedRevision?: number): Promise<void>
32
+ /** Replace one registered namespace's user section wholesale, validate, persist. */
33
+ replace(ns: string, section: object, expectedRevision?: number): Promise<void>
34
+ /** Apply path-addressed edits to one registered namespace's user section. */
35
+ mutate(ns: string, ops: readonly unknown[], expectedRevision?: number): Promise<void>
36
+ /** Describe every registered namespace for configuration surfaces. */
37
+ describe(options?: { redactSecrets?: boolean }): unknown[]
38
+ /** Non-file providers expose no open-document affordance. */
39
+ get documentPath(): string | undefined
40
+ prepareDocument(): Promise<string | undefined>
41
+ }