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
@@ -1,187 +1,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
- })
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
+ })