dsh-context-compression-improved 0.8.0-beta.3 → 0.8.0-beta.4
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.
- package/CHANGELOG.md +7 -0
- package/eslint.config.js +30 -30
- package/package.json +163 -163
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +6 -0
- package/packages/selector/lib/client.js +106 -7
- package/packages/selector/lib/index.js +92 -1
- package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
- package/packages/selector/lib/profiles.d.ts +9 -0
- package/packages/selector/lib/pruner.d.ts +59 -0
- package/packages/selector/lib/pruner.js +408 -5
- package/packages/selector/src/client/CompressionProfileControls.tsx +34 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +1 -0
- package/packages/selector/src/client/decode.ts +53 -49
- package/packages/selector/src/client/index.ts +4 -0
- package/packages/selector/src/client/locales/de.ts +5 -0
- package/packages/selector/src/client/locales/es.ts +5 -0
- package/packages/selector/src/client/locales/fr.ts +5 -0
- package/packages/selector/src/client/locales/it.ts +5 -0
- package/packages/selector/src/client/locales/ja.ts +5 -0
- package/packages/selector/src/client/locales/ko.ts +5 -0
- package/packages/selector/src/client/locales/ru.ts +5 -0
- package/packages/selector/src/client/locales.ts +10 -0
- package/packages/selector/src/client/settings-section.tsx +9 -2
- package/packages/selector/src/index.ts +7 -0
- package/packages/selector/src/profiles.ts +414 -394
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner.ts +241 -1
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +731 -706
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/types.ts +358 -346
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -252
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2734 -2731
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +1 -1
- package/scripts/packed-install-e2e.mjs +1 -1
- package/scripts/verify-release.mjs +2 -1
|
@@ -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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
locale
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
expect(stub.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
// so
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
expect(stub.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
await injected.savePresetOptions({
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
expect(stub.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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) 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
|
+
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
|
+
})
|