dsh-context-compression-improved 0.7.0-beta.1 → 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 (83) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -220
  3. package/CHANGELOG.ko.md +211 -214
  4. package/CHANGELOG.md +401 -376
  5. package/CHANGELOG.zh.md +196 -199
  6. package/README.md +97 -97
  7. package/README.zh.md +86 -86
  8. package/package.json +1 -1
  9. package/packages/selector/dsh.plugin.json +1 -1
  10. package/packages/selector/lib/client.d.ts +44 -0
  11. package/packages/selector/lib/client.js +1733 -6
  12. package/packages/selector/lib/{intent-gate.js → config.js} +799 -136
  13. package/packages/selector/lib/index.d.ts +13 -1
  14. package/packages/selector/lib/index.js +204 -3
  15. package/packages/selector/lib/profiles.d.ts +6 -0
  16. package/packages/selector/lib/pruner.d.ts +6 -0
  17. package/packages/selector/lib/pruner.js +90 -258
  18. package/packages/selector/lib/style.css +88 -46
  19. package/packages/selector/src/client/CompressionProfileControls.tsx +293 -226
  20. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
  21. package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -83
  22. package/packages/selector/src/client/decode.ts +57 -53
  23. package/packages/selector/src/client/index.ts +307 -213
  24. package/packages/selector/src/client/locales/de.ts +141 -0
  25. package/packages/selector/src/client/locales/es.ts +141 -0
  26. package/packages/selector/src/client/locales/fr.ts +141 -0
  27. package/packages/selector/src/client/locales/it.ts +141 -0
  28. package/packages/selector/src/client/locales/ja.ts +141 -0
  29. package/packages/selector/src/client/locales/ko.ts +141 -0
  30. package/packages/selector/src/client/locales/ru.ts +141 -0
  31. package/packages/selector/src/client/locales.ts +282 -196
  32. package/packages/selector/src/client/monitor-fab.ts +336 -0
  33. package/packages/selector/src/client/savings-card.tsx +150 -0
  34. package/packages/selector/src/client/settings-section.tsx +140 -124
  35. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  36. package/packages/selector/src/index.ts +207 -5
  37. package/packages/selector/src/preset-overlay.ts +629 -629
  38. package/packages/selector/src/profiles.ts +431 -414
  39. package/packages/selector/src/pruner/content.ts +198 -198
  40. package/packages/selector/src/pruner/state.ts +57 -57
  41. package/packages/selector/src/pruner.ts +2759 -2665
  42. package/packages/selector/src/runtime/audit.ts +303 -303
  43. package/packages/selector/src/runtime/config.ts +756 -731
  44. package/packages/selector/src/runtime/monitor.ts +235 -0
  45. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  46. package/packages/selector/src/runtime/retrieve.ts +479 -457
  47. package/packages/selector/src/runtime/savings.ts +337 -0
  48. package/packages/selector/src/runtime/summary-command.ts +133 -133
  49. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -233
  50. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -204
  51. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -53
  52. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -65
  53. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -125
  54. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -37
  55. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  56. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -306
  57. package/packages/selector/src/runtime/types.ts +365 -358
  58. package/packages/selector/tests/built/client-artifact.spec.ts +61 -61
  59. package/packages/selector/tests/code-skeleton.client.spec.ts +2 -2
  60. package/packages/selector/tests/custom-contract.client.spec.ts +2 -2
  61. package/packages/selector/tests/estimator-channel.client.spec.tsx +2 -0
  62. package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
  63. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  64. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  65. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  66. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  67. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  68. package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
  69. package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
  70. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  71. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  72. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -62
  73. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -156
  74. package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
  75. package/packages/selector/tests/runtime/savings.spec.ts +120 -0
  76. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -154
  77. package/packages/selector/tests/settings-seat.client.spec.ts +177 -165
  78. package/scripts/packed-components-smoke.mjs +734 -734
  79. package/scripts/packed-install-e2e.mjs +1 -1
  80. package/scripts/verify-release.mjs +1 -1
  81. package/tests/TEST_INVENTORY.md +41 -41
  82. package/tsconfig.tests.json +17 -17
  83. package/vitest.config.ts +57 -57
@@ -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
+ })