dsh-context-compression-improved 0.7.0-beta.1 → 0.8.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 (65) hide show
  1. package/CHANGELOG.ja.md +226 -220
  2. package/CHANGELOG.ko.md +220 -214
  3. package/CHANGELOG.md +366 -376
  4. package/CHANGELOG.zh.md +204 -199
  5. package/README.ja.md +85 -85
  6. package/README.ko.md +85 -85
  7. package/README.md +98 -97
  8. package/README.zh.md +85 -86
  9. package/eslint.config.js +30 -76
  10. package/package.json +53 -55
  11. package/packages/selector/dsh.plugin.json +2 -2
  12. package/packages/selector/lib/{intent-gate.js → advisor-state.js} +3 -91
  13. package/packages/selector/lib/client.js +3 -14
  14. package/packages/selector/lib/index.js +1 -92
  15. package/packages/selector/lib/profiles.d.ts +0 -9
  16. package/packages/selector/lib/pruner.d.ts +0 -59
  17. package/packages/selector/lib/pruner.js +7 -410
  18. package/packages/selector/lib/style.css +46 -46
  19. package/packages/selector/package.json +114 -114
  20. package/packages/selector/src/client/decode.ts +2 -6
  21. package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
  22. package/packages/selector/src/index.ts +411 -418
  23. package/packages/selector/src/preset-overlay.ts +0 -3
  24. package/packages/selector/src/profiles.ts +10 -30
  25. package/packages/selector/src/pruner/content.ts +1 -1
  26. package/packages/selector/src/pruner/state.ts +0 -7
  27. package/packages/selector/src/pruner.ts +9 -253
  28. package/packages/selector/src/runtime/audit.ts +0 -17
  29. package/packages/selector/src/runtime/config.ts +11 -36
  30. package/packages/selector/src/runtime/reducers.ts +1 -1
  31. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +1 -46
  32. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -55
  33. package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
  34. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +1 -4
  35. package/packages/selector/src/runtime/types.ts +0 -12
  36. package/packages/selector/tests/auto-compact.client.spec.tsx +213 -214
  37. package/packages/selector/tests/built/client-artifact.spec.ts +59 -61
  38. package/packages/selector/tests/code-skeleton.client.spec.ts +93 -94
  39. package/packages/selector/tests/custom-contract.client.spec.ts +222 -223
  40. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  41. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
  42. package/packages/selector/tests/preset-options-write.client.spec.ts +187 -188
  43. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
  44. package/packages/selector/tests/profiles.client.spec.tsx +434 -436
  45. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  46. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
  47. package/packages/selector/tests/runtime/audit.spec.ts +274 -275
  48. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
  49. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
  50. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2736
  51. package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
  52. package/pnpm-workspace.yaml +66 -66
  53. package/scripts/packed-components-smoke.mjs +0 -2
  54. package/scripts/packed-install-e2e.mjs +5 -7
  55. package/scripts/verify-release.mjs +2 -3
  56. package/tsconfig.tests.json +1 -3
  57. package/vitest.config.ts +0 -14
  58. package/packages/selector/src/runtime/summary-command.ts +0 -133
  59. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  60. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  61. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  62. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  63. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  64. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  65. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
@@ -1,188 +1,187 @@
1
- // @vitest-environment jsdom
2
-
3
- import { describe, expect, it } from 'vitest'
4
- import { apply } from '../src/client/index.ts'
5
- import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
6
- import type { ContextCompressionSettings } from '../src/profiles.ts'
7
-
8
- /**
9
- * 0.1.7 contract: the compression document rides the entry config as ONE
10
- * volatile whole-object field, so every write commits the full document
11
- * through `configForms.set('settings', doc)`. The sibling-safety that the old
12
- * path-addressed settings service provided is now enforced CLIENT-side:
13
- * `planPresetOptionsOps` is still computed against the current doc and applied
14
- * locally before the commit, so a second field write never erases the first.
15
- */
16
-
17
- interface FormStub {
18
- form: Record<string, unknown>
19
- /** Whole-doc commits the fake Host accepted. */
20
- readonly commits: Record<string, unknown>[]
21
- /** Whole-doc writes the fake Host refused. */
22
- readonly refused: Record<string, unknown>[]
23
- readonly snapshot: () => Record<string, unknown>
24
- }
25
-
26
- function createFormStub(initial: ContextCompressionSettings, commit = true): FormStub {
27
- let revision = 1
28
- let value: Record<string, unknown> = { settings: structuredClone(initial) }
29
- const commits: Record<string, unknown>[] = []
30
- const refused: Record<string, unknown>[] = []
31
- const listeners = new Set<() => void>()
32
- return {
33
- commits,
34
- refused,
35
- snapshot: () => structuredClone(value.settings as Record<string, unknown>),
36
- form: {
37
- getSnapshot: () => ({
38
- status: 'ready' as const,
39
- value: value,
40
- revision,
41
- writable: true,
42
- base: undefined,
43
- user: undefined,
44
- mode: 'host' as const,
45
- }),
46
- subscribe: (listener: () => void) => {
47
- listeners.add(listener)
48
- return () => { listeners.delete(listener) }
49
- },
50
- set: (_field: string, doc: unknown) => {
51
- if (!commit) {
52
- refused.push(doc as Record<string, unknown>)
53
- return Promise.resolve(false)
54
- }
55
- value = { settings: structuredClone(doc) }
56
- revision += 1
57
- commits.push({ settings: structuredClone(doc) })
58
- for (const listener of listeners) listener()
59
- return Promise.resolve(true)
60
- },
61
- unset: () => Promise.resolve(false),
62
- },
63
- }
64
- }
65
-
66
- const DEFAULT_CUSTOM = {
67
- version: 1,
68
- unit: 'tokens',
69
- fresh: { enabled: true, trigger: 4_096, target: 2_048 },
70
- aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
71
- history: {
72
- enabled: true,
73
- trigger: 16_384,
74
- keepRecentTurns: 2,
75
- keepRecent: 16_384,
76
- minReclaim: 8_192,
77
- },
78
- prefixPolicy: 'pressure-break',
79
- } as const satisfies ContextCompressionSettings['custom']
80
-
81
- function bindInjected(
82
- presetOptions: ContextCompressionSettings['presetOptions'],
83
- commit = true,
84
- ): {
85
- injected: CompressionSelectorInjected
86
- stub: FormStub
87
- } {
88
- const settings: ContextCompressionSettings = {
89
- profile: 'tokenpilot-inspired',
90
- custom: structuredClone(DEFAULT_CUSTOM),
91
- autoCompact: { thresholdPercent: 80 },
92
- codeSkeleton: { enabled: false },
93
- intentSummary: { enabled: false },
94
- ...(presetOptions === undefined ? {} : { presetOptions }),
95
- }
96
- const stub = createFormStub(settings, commit)
97
- let options: Record<string, unknown> | undefined
98
- const ctx = {
99
- slots: {
100
- inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => {
101
- const result = factory()
102
- return typeof result === 'function' ? result : () => {}
103
- },
104
- register: (registerOptions: Record<string, unknown>) => {
105
- // The R4 overlay registration rides the same slots service; only the
106
- // settings card carries the inject factory these tests drive.
107
- if (registerOptions.name === 'settings.section') options = registerOptions
108
- return () => {}
109
- },
110
- },
111
- // apply consumes the services through their declarative-inject faces
112
- // (ctx.locale / ctx.configForms), the same shape cordis binds on the host.
113
- locale: { bind: () => (key: string) => key, register: () => {} },
114
- configForms: { get: () => (stub.form as unknown as { getSnapshot(): unknown }) },
115
- }
116
- apply(ctx as never)
117
- if (options === undefined) throw new Error('the settings card never registered')
118
- const factory = options['inject'] as () => CompressionSelectorInjected
119
- return { injected: factory(), stub }
120
- }
121
-
122
- describe('presetOptions writes commit the whole doc through configForms', () => {
123
- it('keeps the estimator channel when a provider is chosen afterwards', async () => {
124
- const { injected, stub } = bindInjected({ estimatorMode: 'host' })
125
- await injected.savePresetOptions({ estimatorProvider: 'local-35b' })
126
- expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'host', estimatorProvider: 'local-35b' })
127
- expect(stub.commits.length).toBe(1)
128
- })
129
-
130
- it('treats a retired review-gate patch as a no-op instead of a write', async () => {
131
- const { injected, stub } = bindInjected({ estimatorMode: 'host' })
132
- // The patch surface no longer carries these keys, and the decoders accept
133
- // them only so a legacy document keeps loading. Cast past the removed type
134
- // so the test pins the RUNTIME behaviour: nothing is written.
135
- await injected.savePresetOptions({
136
- reviewMode: true,
137
- reviewTimeoutTurns: 8,
138
- cacheHitDiscountAlpha: 0.2,
139
- reviewHighImpactTokens: 6000,
140
- } as unknown as Parameters<typeof injected.savePresetOptions>[0])
141
- expect(stub.commits.length).toBe(0)
142
- expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'host' })
143
- })
144
-
145
- it('never loses sibling overrides across whole-doc commits', async () => {
146
- const { injected, stub } = bindInjected({
147
- estimatorMode: 'direct',
148
- estimatorBaseUrl: 'http://192.168.100.242:8200',
149
- dedupeToolResults: false,
150
- readState: false,
151
- })
152
- await injected.savePresetOptions({ estimatorModel: 'Qwen3.6-35B-A3B' })
153
- await injected.savePresetOptions({ estimatorProvider: 'local-35b' })
154
- expect(stub.snapshot()['presetOptions']).toEqual({
155
- estimatorMode: 'direct',
156
- estimatorBaseUrl: 'http://192.168.100.242:8200',
157
- dedupeToolResults: false,
158
- readState: false,
159
- estimatorModel: 'Qwen3.6-35B-A3B',
160
- estimatorProvider: 'local-35b',
161
- })
162
- // Two user actions, two whole-doc commits.
163
- expect(stub.commits.length).toBe(2)
164
- for (const doc of stub.commits) {
165
- // Each commit carries the complete document under the volatile field.
166
- expect(Object.keys(doc)).toEqual(['settings'])
167
- }
168
- })
169
-
170
- it('clears exactly the field a patch names with undefined', async () => {
171
- const { injected, stub } = bindInjected({ estimatorMode: 'direct', estimatorApiKey: 'sk-stored' })
172
- await injected.savePresetOptions({ estimatorApiKey: undefined })
173
- expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'direct' })
174
- })
175
-
176
- it('writes nothing when the patch already matches the stored section', async () => {
177
- const { injected, stub } = bindInjected({ estimatorMode: 'host', estimatorProvider: 'local-35b' })
178
- await injected.savePresetOptions({ estimatorMode: 'host' })
179
- expect(stub.commits.length).toBe(0)
180
- expect(stub.refused.length).toBe(0)
181
- })
182
-
183
- it('reports a save the Host did not commit', async () => {
184
- const { injected } = bindInjected({ estimatorMode: 'host' }, false)
185
- await expect(injected.savePresetOptions({ estimatorProvider: 'local-35b' }))
186
- .rejects.toThrow(/were not saved/)
187
- })
188
- })
1
+ // @vitest-environment jsdom
2
+
3
+ import { describe, expect, it } from 'vitest'
4
+ import { apply } from '../src/client/index.ts'
5
+ import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
6
+ import type { ContextCompressionSettings } from '../src/profiles.ts'
7
+
8
+ /**
9
+ * 0.1.7 contract: the compression document rides the entry config as ONE
10
+ * volatile whole-object field, so every write commits the full document
11
+ * through `configForms.set('settings', doc)`. The sibling-safety that the old
12
+ * path-addressed settings service provided is now enforced CLIENT-side:
13
+ * `planPresetOptionsOps` is still computed against the current doc and applied
14
+ * locally before the commit, so a second field write never erases the first.
15
+ */
16
+
17
+ interface FormStub {
18
+ form: Record<string, unknown>
19
+ /** Whole-doc commits the fake Host accepted. */
20
+ readonly commits: Record<string, unknown>[]
21
+ /** Whole-doc writes the fake Host refused. */
22
+ readonly refused: Record<string, unknown>[]
23
+ readonly snapshot: () => Record<string, unknown>
24
+ }
25
+
26
+ function createFormStub(initial: ContextCompressionSettings, commit = true): FormStub {
27
+ let revision = 1
28
+ let value: Record<string, unknown> = { settings: structuredClone(initial) as unknown as Record<string, unknown> }
29
+ const commits: Record<string, unknown>[] = []
30
+ const refused: Record<string, unknown>[] = []
31
+ const listeners = new Set<() => void>()
32
+ return {
33
+ commits,
34
+ refused,
35
+ snapshot: () => structuredClone(value.settings as Record<string, unknown>),
36
+ form: {
37
+ getSnapshot: () => ({
38
+ status: 'ready' as const,
39
+ value: value as unknown as Record<string, unknown>,
40
+ revision,
41
+ writable: true,
42
+ base: undefined,
43
+ user: undefined,
44
+ mode: 'host' as const,
45
+ }),
46
+ subscribe: (listener: () => void) => {
47
+ listeners.add(listener)
48
+ return () => { listeners.delete(listener) }
49
+ },
50
+ set: (_field: string, doc: unknown) => {
51
+ if (!commit) {
52
+ refused.push(doc as Record<string, unknown>)
53
+ return Promise.resolve(false)
54
+ }
55
+ value = { settings: structuredClone(doc) as unknown as Record<string, unknown> }
56
+ revision += 1
57
+ commits.push({ settings: structuredClone(doc) as unknown as Record<string, unknown> })
58
+ for (const listener of listeners) listener()
59
+ return Promise.resolve(true)
60
+ },
61
+ unset: () => Promise.resolve(false),
62
+ },
63
+ } as FormStub & { form: Record<string, unknown> }
64
+ }
65
+
66
+ const DEFAULT_CUSTOM = {
67
+ version: 1,
68
+ unit: 'tokens',
69
+ fresh: { enabled: true, trigger: 4_096, target: 2_048 },
70
+ aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
71
+ history: {
72
+ enabled: true,
73
+ trigger: 16_384,
74
+ keepRecentTurns: 2,
75
+ keepRecent: 16_384,
76
+ minReclaim: 8_192,
77
+ },
78
+ prefixPolicy: 'pressure-break',
79
+ } as const satisfies ContextCompressionSettings['custom']
80
+
81
+ function bindInjected(
82
+ presetOptions: ContextCompressionSettings['presetOptions'],
83
+ commit = true,
84
+ ): {
85
+ injected: CompressionSelectorInjected
86
+ stub: FormStub
87
+ } {
88
+ const settings: ContextCompressionSettings = {
89
+ profile: 'tokenpilot-inspired',
90
+ custom: structuredClone(DEFAULT_CUSTOM),
91
+ autoCompact: { thresholdPercent: 80 },
92
+ codeSkeleton: { enabled: false },
93
+ ...(presetOptions === undefined ? {} : { presetOptions }),
94
+ }
95
+ const stub = createFormStub(settings, commit)
96
+ let options: Record<string, unknown> | undefined
97
+ const ctx = {
98
+ slots: {
99
+ inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => {
100
+ const result = factory()
101
+ return typeof result === 'function' ? result : () => {}
102
+ },
103
+ register: (registerOptions: Record<string, unknown>) => {
104
+ // The R4 overlay registration rides the same slots service; only the
105
+ // settings card carries the inject factory these tests drive.
106
+ if (registerOptions.name === 'settings.section') options = registerOptions
107
+ return () => {}
108
+ },
109
+ },
110
+ // apply consumes the services through their declarative-inject faces
111
+ // (ctx.locale / ctx.configForms), the same shape cordis binds on the host.
112
+ locale: { bind: () => (key: string) => key, register: () => {} },
113
+ configForms: { get: () => (stub.form as unknown as { getSnapshot(): unknown }) },
114
+ }
115
+ apply(ctx as never)
116
+ if (options === undefined) throw new Error('the settings card never registered')
117
+ const factory = options['inject'] as () => CompressionSelectorInjected
118
+ return { injected: factory(), stub }
119
+ }
120
+
121
+ describe('presetOptions writes commit the whole doc through configForms', () => {
122
+ it('keeps the estimator channel when a provider is chosen afterwards', async () => {
123
+ const { injected, stub } = bindInjected({ estimatorMode: 'host' })
124
+ await injected.savePresetOptions({ estimatorProvider: 'local-35b' })
125
+ expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'host', estimatorProvider: 'local-35b' })
126
+ expect(stub.commits.length).toBe(1)
127
+ })
128
+
129
+ it('treats a retired review-gate patch as a no-op instead of a write', async () => {
130
+ const { injected, stub } = bindInjected({ estimatorMode: 'host' })
131
+ // The patch surface no longer carries these keys, and the decoders accept
132
+ // them only so a legacy document keeps loading. Cast past the removed type
133
+ // so the test pins the RUNTIME behaviour: nothing is written.
134
+ await injected.savePresetOptions({
135
+ reviewMode: true,
136
+ reviewTimeoutTurns: 8,
137
+ cacheHitDiscountAlpha: 0.2,
138
+ reviewHighImpactTokens: 6000,
139
+ } as unknown as Parameters<typeof injected.savePresetOptions>[0])
140
+ expect(stub.commits.length).toBe(0)
141
+ expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'host' })
142
+ })
143
+
144
+ it('never loses sibling overrides across whole-doc commits', async () => {
145
+ const { injected, stub } = bindInjected({
146
+ estimatorMode: 'direct',
147
+ estimatorBaseUrl: 'http://192.168.100.242:8200',
148
+ dedupeToolResults: false,
149
+ readState: false,
150
+ })
151
+ await injected.savePresetOptions({ estimatorModel: 'Qwen3.6-35B-A3B' })
152
+ await injected.savePresetOptions({ estimatorProvider: 'local-35b' })
153
+ expect(stub.snapshot()['presetOptions']).toEqual({
154
+ estimatorMode: 'direct',
155
+ estimatorBaseUrl: 'http://192.168.100.242:8200',
156
+ dedupeToolResults: false,
157
+ readState: false,
158
+ estimatorModel: 'Qwen3.6-35B-A3B',
159
+ estimatorProvider: 'local-35b',
160
+ })
161
+ // Two user actions, two whole-doc commits.
162
+ expect(stub.commits.length).toBe(2)
163
+ for (const doc of stub.commits) {
164
+ // Each commit carries the complete document under the volatile field.
165
+ expect(Object.keys(doc)).toEqual(['settings'])
166
+ }
167
+ })
168
+
169
+ it('clears exactly the field a patch names with undefined', async () => {
170
+ const { injected, stub } = bindInjected({ estimatorMode: 'direct', estimatorApiKey: 'sk-stored' })
171
+ await injected.savePresetOptions({ estimatorApiKey: undefined })
172
+ expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'direct' })
173
+ })
174
+
175
+ it('writes nothing when the patch already matches the stored section', async () => {
176
+ const { injected, stub } = bindInjected({ estimatorMode: 'host', estimatorProvider: 'local-35b' })
177
+ await injected.savePresetOptions({ estimatorMode: 'host' })
178
+ expect(stub.commits.length).toBe(0)
179
+ expect(stub.refused.length).toBe(0)
180
+ })
181
+
182
+ it('reports a save the Host did not commit', async () => {
183
+ const { injected } = bindInjected({ estimatorMode: 'host' }, false)
184
+ await expect(injected.savePresetOptions({ estimatorProvider: 'local-35b' }))
185
+ .rejects.toThrow(/were not saved/)
186
+ })
187
+ })