dsh-context-compression-improved 0.7.0-beta.2 → 0.7.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 (46) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/package.json +17 -18
  3. package/packages/selector/dsh.plugin.json +1 -1
  4. package/packages/selector/lib/client.d.ts +44 -0
  5. package/packages/selector/lib/client.js +1007 -13
  6. package/packages/selector/lib/{intent-gate.js → config.js} +799 -136
  7. package/packages/selector/lib/index.d.ts +13 -1
  8. package/packages/selector/lib/index.js +204 -3
  9. package/packages/selector/lib/profiles.d.ts +6 -0
  10. package/packages/selector/lib/pruner.d.ts +6 -0
  11. package/packages/selector/lib/pruner.js +90 -258
  12. package/packages/selector/lib/style.css +42 -0
  13. package/packages/selector/src/client/CompressionProfileControls.tsx +293 -226
  14. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
  15. package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -83
  16. package/packages/selector/src/client/decode.ts +5 -1
  17. package/packages/selector/src/client/index.ts +307 -243
  18. package/packages/selector/src/client/locales/de.ts +43 -0
  19. package/packages/selector/src/client/locales/es.ts +43 -0
  20. package/packages/selector/src/client/locales/fr.ts +43 -0
  21. package/packages/selector/src/client/locales/it.ts +43 -0
  22. package/packages/selector/src/client/locales/ja.ts +43 -0
  23. package/packages/selector/src/client/locales/ko.ts +43 -0
  24. package/packages/selector/src/client/locales/ru.ts +43 -0
  25. package/packages/selector/src/client/locales.ts +282 -196
  26. package/packages/selector/src/client/monitor-fab.ts +336 -0
  27. package/packages/selector/src/client/savings-card.tsx +150 -0
  28. package/packages/selector/src/client/settings-section.tsx +140 -124
  29. package/packages/selector/src/index.ts +207 -5
  30. package/packages/selector/src/profiles.ts +17 -0
  31. package/packages/selector/src/pruner.ts +96 -2
  32. package/packages/selector/src/runtime/config.ts +26 -1
  33. package/packages/selector/src/runtime/monitor.ts +235 -0
  34. package/packages/selector/src/runtime/retrieve.ts +479 -457
  35. package/packages/selector/src/runtime/savings.ts +337 -0
  36. package/packages/selector/src/runtime/types.ts +7 -0
  37. package/packages/selector/tests/code-skeleton.client.spec.ts +2 -2
  38. package/packages/selector/tests/custom-contract.client.spec.ts +2 -2
  39. package/packages/selector/tests/estimator-channel.client.spec.tsx +2 -0
  40. package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
  41. package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
  42. package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
  43. package/packages/selector/tests/runtime/savings.spec.ts +120 -0
  44. package/packages/selector/tests/settings-seat.client.spec.ts +177 -165
  45. package/scripts/packed-install-e2e.mjs +1 -1
  46. package/scripts/verify-release.mjs +1 -1
@@ -1,165 +1,177 @@
1
- /**
2
- * Settings-seat contract pin for dsh-context-compression-improved's client.
3
- *
4
- * This spec locks WHERE the compression settings panel mounts: exactly ONE
5
- * seat — the standalone `settings.section` entry (设置 → 上下文压缩) — and
6
- * explicitly NOT the Plugins-section surfaces, and NOT a `shell.overlay` float
7
- * (the retired review panel's seat was removed with the gate). History this
8
- * pins against: the 0.1.5 line first lost every entry (a lazy `ctx.get` of
9
- * locale/settingsScope raced the settings client and apply bailed), then showed
10
- * the panel twice (item card + tab on top of the standalone section). Both were
11
- * fixed by the declarative-inject + single-section shape below. When a future
12
- * DSH line moves the seat again, migrate src/client/index.ts AND this file
13
- * together.
14
- */
15
- import { describe, expect, it, vi } from 'vitest'
16
- import type { Context as ClientContext } from '@deepseek-ai/cordis'
17
- import { apply, inject } from '../src/client/index.ts'
18
- import { ContextCompressionSettingsSection } from '../src/client/CompressionProfileSelector.tsx'
19
- import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
20
-
21
- vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
22
- IconChevronDownOutlineMedium: () => null,
23
- Menu: () => null,
24
- }))
25
-
26
- interface CapturedRegistration {
27
- readonly slot: string
28
- readonly options: Record<string, unknown>
29
- readonly component: unknown
30
- }
31
-
32
- /**
33
- * Drive apply against a stub host and capture every slot registration.
34
- * @param options - `registerThrows` models an older host that does not declare
35
- * the seat: the slot boundary rejects the registration, exactly the shape the
36
- * 0.1.2-era hosts had.
37
- */
38
- function collectRegistrations(
39
- options: { readonly registerThrows?: boolean } = {},
40
- ): { declared: string[]; registrations: CapturedRegistration[] } {
41
- const declared: string[] = []
42
- const registrations: CapturedRegistration[] = []
43
- const ctx = {
44
- locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
45
- configForms: { get: vi.fn(() => ({}) as never) },
46
- slots: {
47
- inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
48
- declared.push(slot)
49
- const result = factory()
50
- const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
51
- ? (result as Generator<() => void>)
52
- : [result as () => void]
53
- for (const step of steps) { void step }
54
- return () => {}
55
- },
56
- register: (record: Record<string, unknown>, component: unknown) => {
57
- if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
58
- registrations.push({ slot: String(record['name']), options: record, component })
59
- return () => {}
60
- },
61
- },
62
- }
63
- apply(ctx as unknown as ClientContext)
64
- return { declared, registrations }
65
- }
66
-
67
- describe('settings-seat contract (standalone settings.section only)', () => {
68
- it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
69
- expect(inject).toEqual(['slots', 'locale', 'configForms'])
70
- })
71
-
72
- it('injects exactly the settings.section seat and nothing else', () => {
73
- const { declared, registrations } = collectRegistrations()
74
- expect(declared).toEqual(['settings.section'])
75
- expect(registrations).toHaveLength(1)
76
- expect(registrations[0]!.slot).toBe('settings.section')
77
- })
78
-
79
- it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
80
- const { declared } = collectRegistrations()
81
- expect(declared).not.toContain('shell.overlay')
82
- })
83
-
84
- it('pins the section identity (id/order/label/locale) and the panel component', () => {
85
- const { registrations } = collectRegistrations()
86
- const { options, component } = registrations[0]!
87
- expect(options['id']).toBe('context-compression')
88
- expect(options['order']).toBe(17)
89
- expect(options['locale']).toBe('context-compression')
90
- expect((options['label'] as () => string)()).toBe('nav')
91
- expect(typeof options['inject']).toBe('function')
92
- const face = (options['inject'] as () => Record<string, unknown>)()
93
- expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePresetOptions', 'select', 'resetCustom'].sort())
94
- expect(component).toBe(ContextCompressionSettingsSection)
95
- })
96
-
97
- it('never adds a Plugins-section card or tab alongside the standalone section', () => {
98
- const { declared } = collectRegistrations()
99
- expect(declared).not.toContain('settings.plugins.tab')
100
- expect(declared).not.toContain('settings.plugin.item')
101
- })
102
-
103
- it('projects an identity-stable snapshot between form changes (React #185 regression)', () => {
104
- // The 0.1.7 adapter wraps configForms into the legacy scope shape. Its
105
- // getSnapshot MUST return the same object reference until the underlying
106
- // form snapshot changes: a fresh literal per call re-renders
107
- // useSyncExternalStore forever — "Minified React error #185" (maximum
108
- // update depth exceeded), and the slot boundary abdicates the whole
109
- // settings.section on the production host.
110
- let source = {
111
- status: 'ready' as const,
112
- value: { settings: { profile: 'balanced', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } },
113
- revision: 1, writable: true, base: undefined, user: undefined, mode: 'host' as const,
114
- }
115
- const listeners: (() => void)[] = []
116
- const ctx = {
117
- locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
118
- configForms: { get: () => ({
119
- getSnapshot: () => source,
120
- subscribe: (listener: () => void) => { listeners.push(listener); return () => {} },
121
- set: async () => true,
122
- }) },
123
- slots: {
124
- inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => { void factory() },
125
- register: (record: Record<string, unknown>) => {
126
- registrations.push({ slot: String(record['name']), options: record, component: null })
127
- return () => {}
128
- },
129
- },
130
- }
131
- const registrations: CapturedRegistration[] = []
132
- apply(ctx as unknown as ClientContext)
133
- const face = (registrations[0]!.options['inject'] as () => { hooks: { compression: { getSnapshot(): unknown; subscribe(l: () => void): () => void } } })()
134
- const scope = face.hooks.compression
135
-
136
- const first = scope.getSnapshot()
137
- expect(scope.getSnapshot()).toBe(first)
138
- // value decodes through the whole strict validator
139
- expect(first && typeof first === 'object' && 'value' in first && (first as { value?: { profile?: string } }).value?.profile).toBe('balanced')
140
-
141
- // Host accepts a change → NEW form snapshot object → projection recomputes
142
- source = { ...source, revision: 2, value: { settings: { profile: 'off', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } } }
143
- for (const listener of listeners) listener()
144
- const second = scope.getSnapshot()
145
- expect(second).not.toBe(first)
146
- expect(second && typeof second === 'object' && 'value' in second && (second as { value?: { profile?: string } }).value?.profile).toBe('off')
147
- })
148
-
149
- it('survives an older host that does not declare the seat, warning instead of crashing', () => {
150
- // Cross-version tolerance: a host without this seat rejects the
151
- // registration at the slot boundary. apply() must swallow that and warn —
152
- // the historical failure mode was apply() bailing out, which silently took
153
- // EVERY settings entry down with it.
154
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
155
- try {
156
- const { declared } = collectRegistrations({ registerThrows: true })
157
- // It tried the seat (so the degradation is "loud", not a silent no-op)…
158
- expect(declared).toEqual(['settings.section'])
159
- // …and the rejection never escaped apply().
160
- expect(warn).toHaveBeenCalled()
161
- } finally {
162
- warn.mockRestore()
163
- }
164
- })
165
- })
1
+ /**
2
+ * Settings-seat contract pin for dsh-context-compression-improved's client.
3
+ *
4
+ * This spec locks WHERE the compression settings panel mounts: exactly ONE
5
+ * seat — the standalone `settings.section` entry (设置 → 上下文压缩) — and
6
+ * explicitly NOT the Plugins-section surfaces, and NOT a `shell.overlay` float
7
+ * (the retired review panel's seat was removed with the gate). History this
8
+ * pins against: the 0.1.5 line first lost every entry (a lazy `ctx.get` of
9
+ * locale/settingsScope raced the settings client and apply bailed), then showed
10
+ * the panel twice (item card + tab on top of the standalone section). Both were
11
+ * fixed by the declarative-inject + single-section shape below. When a future
12
+ * DSH line moves the seat again, migrate src/client/index.ts AND this file
13
+ * together.
14
+ */
15
+ import { describe, expect, it, vi } from 'vitest'
16
+ import type { Context as ClientContext } from '@deepseek-ai/cordis'
17
+ import { apply, inject } from '../src/client/index.ts'
18
+ import { ContextCompressionSettingsSection } from '../src/client/CompressionProfileSelector.tsx'
19
+ import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
20
+
21
+ vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
22
+ IconChevronDownOutlineMedium: () => null,
23
+ Menu: () => null,
24
+ }))
25
+
26
+ interface CapturedRegistration {
27
+ readonly slot: string
28
+ readonly options: Record<string, unknown>
29
+ readonly component: unknown
30
+ }
31
+
32
+ /**
33
+ * Drive apply against a stub host and capture every slot registration.
34
+ * @param options - `registerThrows` models an older host that does not declare
35
+ * the seat: the slot boundary rejects the registration, exactly the shape the
36
+ * 0.1.2-era hosts had.
37
+ */
38
+ function collectRegistrations(
39
+ options: { readonly registerThrows?: boolean } = {},
40
+ ): { declared: string[]; registrations: CapturedRegistration[] } {
41
+ const declared: string[] = []
42
+ const registrations: CapturedRegistration[] = []
43
+ const ctx = {
44
+ locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
45
+ configForms: { get: vi.fn(() => ({}) as never) },
46
+ slots: {
47
+ inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
48
+ declared.push(slot)
49
+ const result = factory()
50
+ const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
51
+ ? (result as Generator<() => void>)
52
+ : [result as () => void]
53
+ for (const step of steps) { void step }
54
+ return () => {}
55
+ },
56
+ register: (record: Record<string, unknown>, component: unknown) => {
57
+ if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
58
+ registrations.push({ slot: String(record['name']), options: record, component })
59
+ return () => {}
60
+ },
61
+ },
62
+ }
63
+ apply(ctx as unknown as ClientContext)
64
+ return { declared, registrations }
65
+ }
66
+
67
+ describe('settings-seat contract (standalone settings.section + input-bar session binder)', () => {
68
+ it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
69
+ expect(inject).toEqual(['slots', 'locale', 'configForms'])
70
+ })
71
+
72
+ it('injects exactly two seats: the settings.section panel + the input-bar session binder', () => {
73
+ const { declared, registrations } = collectRegistrations()
74
+ expect(declared).toEqual(['settings.section', 'conversation.input.left'])
75
+ expect(registrations).toHaveLength(2)
76
+ expect(registrations[0]!.slot).toBe('settings.section')
77
+ expect(registrations[1]!.slot).toBe('conversation.input.left')
78
+ })
79
+
80
+ it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
81
+ const { declared } = collectRegistrations()
82
+ expect(declared).not.toContain('shell.overlay')
83
+ })
84
+
85
+ it('pins the section identity (id/order/label/locale) and the panel component', () => {
86
+ const { registrations } = collectRegistrations()
87
+ const { options, component } = registrations[0]!
88
+ expect(options['id']).toBe('context-compression')
89
+ expect(options['order']).toBe(17)
90
+ expect(options['locale']).toBe('context-compression')
91
+ expect((options['label'] as () => string)()).toBe('nav')
92
+ expect(typeof options['inject']).toBe('function')
93
+ const face = (options['inject'] as () => Record<string, unknown>)()
94
+ expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'saveIntentSummary', 'saveMonitorPanel', 'savePresetOptions', 'select', 'resetCustom'].sort())
95
+ expect(component).toBe(ContextCompressionSettingsSection)
96
+ })
97
+
98
+ it('pins the input-bar binder: invisible component, inject captures the bare sessionId', () => {
99
+ const { registrations } = collectRegistrations()
100
+ const inputSeat = registrations[1]!
101
+ expect(inputSeat.options['id']).toBe('context-compression-session-bind')
102
+ expect(inputSeat.options['order']).toBe(170)
103
+ expect(typeof inputSeat.options['inject']).toBe('function')
104
+ const face = (inputSeat.options['inject'] as (sessionId: string) => Record<string, unknown>)('sess-42')
105
+ expect(face).toEqual({})
106
+ expect(inputSeat.component).toBeTypeOf('function')
107
+ })
108
+
109
+ it('never adds a Plugins-section card or tab alongside the standalone section', () => {
110
+ const { declared } = collectRegistrations()
111
+ expect(declared).not.toContain('settings.plugins.tab')
112
+ expect(declared).not.toContain('settings.plugin.item')
113
+ })
114
+
115
+ it('projects an identity-stable snapshot between form changes (React #185 regression)', () => {
116
+ // The 0.1.7 adapter wraps configForms into the legacy scope shape. Its
117
+ // getSnapshot MUST return the same object reference until the underlying
118
+ // form snapshot changes: a fresh literal per call re-renders
119
+ // useSyncExternalStore forever — "Minified React error #185" (maximum
120
+ // update depth exceeded), and the slot boundary abdicates the whole
121
+ // settings.section on the production host.
122
+ let source = {
123
+ status: 'ready' as const,
124
+ value: { settings: { profile: 'balanced', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } },
125
+ revision: 1, writable: true, base: undefined, user: undefined, mode: 'host' as const,
126
+ }
127
+ const listeners: (() => void)[] = []
128
+ const ctx = {
129
+ locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
130
+ configForms: { get: () => ({
131
+ getSnapshot: () => source,
132
+ subscribe: (listener: () => void) => { listeners.push(listener); return () => {} },
133
+ set: async () => true,
134
+ }) },
135
+ slots: {
136
+ inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => { void factory() },
137
+ register: (record: Record<string, unknown>) => {
138
+ registrations.push({ slot: String(record['name']), options: record, component: null })
139
+ return () => {}
140
+ },
141
+ },
142
+ }
143
+ const registrations: CapturedRegistration[] = []
144
+ apply(ctx as unknown as ClientContext)
145
+ const face = (registrations[0]!.options['inject'] as () => { hooks: { compression: { getSnapshot(): unknown; subscribe(l: () => void): () => void } } })()
146
+ const scope = face.hooks.compression
147
+
148
+ const first = scope.getSnapshot()
149
+ expect(scope.getSnapshot()).toBe(first)
150
+ // value decodes through the whole strict validator
151
+ expect(first && typeof first === 'object' && 'value' in first && (first as { value?: { profile?: string } }).value?.profile).toBe('balanced')
152
+
153
+ // Host accepts a change → NEW form snapshot object → projection recomputes
154
+ source = { ...source, revision: 2, value: { settings: { profile: 'off', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } } }
155
+ for (const listener of listeners) listener()
156
+ const second = scope.getSnapshot()
157
+ expect(second).not.toBe(first)
158
+ expect(second && typeof second === 'object' && 'value' in second && (second as { value?: { profile?: string } }).value?.profile).toBe('off')
159
+ })
160
+
161
+ it('survives an older host that does not declare the seat, warning instead of crashing', () => {
162
+ // Cross-version tolerance: a host without this seat rejects the
163
+ // registration at the slot boundary. apply() must swallow that and warn —
164
+ // the historical failure mode was apply() bailing out, which silently took
165
+ // EVERY settings entry down with it.
166
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
167
+ try {
168
+ const { declared } = collectRegistrations({ registerThrows: true })
169
+ // It tried both seats (so the degradation is "loud", not a silent no-op)…
170
+ expect(declared).toEqual(['settings.section', 'conversation.input.left'])
171
+ // …and the rejection never escaped apply().
172
+ expect(warn).toHaveBeenCalled()
173
+ } finally {
174
+ warn.mockRestore()
175
+ }
176
+ })
177
+ })
@@ -416,7 +416,7 @@ async function runOfficialCloneCliSmoke(referenceRoot, registry, upgradeFrom, ca
416
416
  * ui-slot packages) the web bundler supplies, and that stack is verified
417
417
  * from the built client libraries below.
418
418
  */
419
- const HOST_PLANE_ENTRIES = ['index.js', 'pruner.js', 'advisor-state.js', 'tail-trim.js', 'invariant.js']
419
+ const HOST_PLANE_ENTRIES = ['index.js', 'pruner.js', 'config.js', 'tail-trim.js', 'invariant.js']
420
420
 
421
421
  /**
422
422
  * Bare package names the installed package's host-plane runtime files import.
@@ -49,7 +49,7 @@ const INSTALLATION_PROVIDED_RUNTIME = new Set([
49
49
  // stack (`react`, the ui-slot packages); its requires are reviewed from the
50
50
  // built artifact further down instead.
51
51
  const HOST_PLANE_ENTRIES = [
52
- 'lib/intent-gate.js',
52
+ 'lib/config.js',
53
53
  'lib/index.js',
54
54
  'lib/invariant.js',
55
55
  'lib/pruner.js',