dsh-context-compression-improved 0.2.3 → 0.2.5
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/.gitattributes +2 -1
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.ja.md +169 -39
- package/CHANGELOG.ko.md +167 -39
- package/CHANGELOG.md +333 -135
- package/CHANGELOG.zh.md +152 -39
- package/CONTRIBUTING.md +22 -22
- package/README.ja.md +85 -104
- package/README.ko.md +85 -103
- package/README.md +94 -112
- package/README.zh.md +85 -101
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.ja.md +78 -76
- package/docs/installation.ko.md +78 -76
- package/docs/installation.md +103 -76
- package/docs/installation.zh.md +100 -76
- package/docs/repair-log.md +657 -582
- package/eslint.config.js +30 -30
- package/package.json +163 -142
- package/packages/selector/README.md +26 -31
- package/packages/selector/README.zh.md +24 -31
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
- package/packages/selector/cordis.patch.yml +27 -19
- package/packages/selector/dsh.plugin.json +2 -2
- package/packages/selector/lib/client.d.ts +320 -228
- package/packages/selector/lib/client.js +3254 -1462
- package/packages/selector/lib/config.js +1713 -842
- package/packages/selector/lib/index.d.ts +46 -38
- package/packages/selector/lib/index.js +1099 -645
- package/packages/selector/lib/invariant.js +70 -70
- package/packages/selector/lib/pruner.d.ts +904 -684
- package/packages/selector/lib/pruner.js +5800 -3807
- package/packages/selector/lib/style.css +88 -46
- package/packages/selector/lib/tail-trim.js +145 -136
- package/packages/selector/package.json +18 -19
- package/packages/selector/screenshots.json +3 -6
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
- package/packages/selector/src/client/EstimatorControls.tsx +277 -281
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +249 -111
- package/packages/selector/src/client/locales/de.ts +141 -0
- package/packages/selector/src/client/locales/es.ts +141 -0
- package/packages/selector/src/client/locales/fr.ts +141 -0
- package/packages/selector/src/client/locales/it.ts +141 -0
- package/packages/selector/src/client/locales/ja.ts +141 -0
- package/packages/selector/src/client/locales/ko.ts +141 -0
- package/packages/selector/src/client/locales/ru.ts +141 -0
- package/packages/selector/src/client/locales.ts +282 -198
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/preset-options.ts +88 -70
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -126
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
- package/packages/selector/src/index.ts +671 -327
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/preset-overlay.ts +60 -1
- package/packages/selector/src/profiles.ts +431 -342
- package/packages/selector/src/pruner/content.ts +18 -5
- package/packages/selector/src/pruner/state.ts +57 -43
- package/packages/selector/src/pruner/types.ts +23 -5
- package/packages/selector/src/pruner.ts +2736 -2144
- package/packages/selector/src/runtime/adaptive-cost.ts +23 -12
- package/packages/selector/src/runtime/audit.ts +303 -215
- package/packages/selector/src/runtime/config.ts +756 -613
- package/packages/selector/src/runtime/measurement.ts +436 -403
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/reducers.ts +1115 -97
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/session-events.ts +30 -17
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +1 -1
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
- 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/tokenpilot/locator.ts +1 -1
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +23 -2
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
- package/packages/selector/src/runtime/toolclass.ts +103 -0
- package/packages/selector/src/runtime/types.ts +365 -309
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
- package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
- package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -243
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +7 -7
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -129
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +14 -3
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
- 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/line-mapping.spec.ts +153 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2531
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +24 -0
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +697 -631
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
- package/pnpm-workspace.yaml +66 -19
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
- package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
- package/scripts/toolclass-corpus-replay.mjs +281 -0
- package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
- package/tests/TEST_INVENTORY.md +41 -42
- package/scripts/capture-profile-baseline.ts +0 -80
- package/tsconfig.scripts.json +0 -13
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
|
@@ -1,88 +1,91 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import type { ClientContext
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// A
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
flipEnabled =
|
|
84
|
-
await expect(actions.saveCodeSkeleton(false)).
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
})
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
+
import type { SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
4
|
+
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
+
import { apply } from '../src/client/index.ts'
|
|
6
|
+
import type {
|
|
7
|
+
CompressionSelectorInjected,
|
|
8
|
+
ContextCompressionSettings,
|
|
9
|
+
} from '../src/client/CompressionProfileSelector.tsx'
|
|
10
|
+
|
|
11
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
12
|
+
IconChevronDownOutline14: () => null,
|
|
13
|
+
Menu: () => null,
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
17
|
+
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
18
|
+
let revision = 3
|
|
19
|
+
let commit = false
|
|
20
|
+
let flipEnabled = false
|
|
21
|
+
let value: ContextCompressionSettings = {
|
|
22
|
+
profile: 'balanced',
|
|
23
|
+
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
24
|
+
autoCompact: { thresholdPercent: 80 },
|
|
25
|
+
codeSkeleton: { enabled: false },
|
|
26
|
+
intentSummary: { enabled: false },
|
|
27
|
+
}
|
|
28
|
+
const snapshot = (): SettingsScopeSnapshot<ContextCompressionSettings> => ({
|
|
29
|
+
status: 'ready',
|
|
30
|
+
value,
|
|
31
|
+
base: undefined,
|
|
32
|
+
user: undefined,
|
|
33
|
+
revision,
|
|
34
|
+
writable: true,
|
|
35
|
+
mode: 'host',
|
|
36
|
+
})
|
|
37
|
+
const scope = {
|
|
38
|
+
getSnapshot: snapshot,
|
|
39
|
+
subscribe: vi.fn(() => () => {}),
|
|
40
|
+
set: vi.fn(async (field: string, next: unknown) => {
|
|
41
|
+
if (!commit) return
|
|
42
|
+
revision += 1
|
|
43
|
+
if (field === 'codeSkeleton' && flipEnabled) {
|
|
44
|
+
const accepted = structuredClone(next as ContextCompressionSettings['codeSkeleton'])
|
|
45
|
+
accepted.enabled = !accepted.enabled
|
|
46
|
+
value = { ...value, codeSkeleton: accepted }
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
value = { ...value, [field]: next }
|
|
50
|
+
}),
|
|
51
|
+
unset: vi.fn(async () => {}),
|
|
52
|
+
}
|
|
53
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
54
|
+
const ctx = {
|
|
55
|
+
effect: (install: () => unknown) => { install() },
|
|
56
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
57
|
+
settingsScope: { bind: vi.fn(() => scope) },
|
|
58
|
+
slots: {
|
|
59
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
60
|
+
register: (registration: { name?: string, inject?: () => CompressionSelectorInjected }) => {
|
|
61
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
62
|
+
if (registration.name === 'settings.section' && typeof registration.inject === 'function') injected = registration.inject
|
|
63
|
+
return () => {}
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
} as unknown as ClientContext
|
|
67
|
+
|
|
68
|
+
apply(ctx)
|
|
69
|
+
const actions = injected?.()
|
|
70
|
+
expect(actions).toBeDefined()
|
|
71
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
72
|
+
|
|
73
|
+
// A silent host drop leaves the revision untouched: the write must reject.
|
|
74
|
+
await expect(actions.saveCodeSkeleton(true)).rejects.toThrow('were not saved')
|
|
75
|
+
|
|
76
|
+
// A committed write resolves and persists the exact section payload.
|
|
77
|
+
commit = true
|
|
78
|
+
await expect(actions.saveCodeSkeleton(true)).resolves.toBeUndefined()
|
|
79
|
+
expect(scope.set).toHaveBeenLastCalledWith('codeSkeleton', { enabled: true })
|
|
80
|
+
expect(value.codeSkeleton).toEqual({ enabled: true })
|
|
81
|
+
|
|
82
|
+
// A host that flips the toggled bit fails the acceptance check.
|
|
83
|
+
flipEnabled = true
|
|
84
|
+
await expect(actions.saveCodeSkeleton(false)).rejects.toThrow('were not saved')
|
|
85
|
+
|
|
86
|
+
flipEnabled = false
|
|
87
|
+
await expect(actions.saveCodeSkeleton(false)).resolves.toBeUndefined()
|
|
88
|
+
expect(scope.set).toHaveBeenLastCalledWith('codeSkeleton', { enabled: false })
|
|
89
|
+
expect(value.codeSkeleton).toEqual({ enabled: false })
|
|
90
|
+
})
|
|
91
|
+
})
|
|
@@ -1,202 +1,205 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import type { ClientContext
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
expect(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
let
|
|
82
|
-
let
|
|
83
|
-
let
|
|
84
|
-
let
|
|
85
|
-
let
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
await expect(actions.select('native')).
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
rewriteCustom =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
dropTailTrim =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
downgradeVersion =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
rewriteReset =
|
|
189
|
-
await expect(actions.resetCustom()).
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
expect(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
})
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
+
import type { SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_CUSTOM_COMPRESSION_POLICY,
|
|
6
|
+
isCustomCompressionPolicy,
|
|
7
|
+
} from '../src/profiles.ts'
|
|
8
|
+
import { apply } from '../src/client/index.ts'
|
|
9
|
+
import { decodeSettings } from '../src/client/decode.ts'
|
|
10
|
+
import type {
|
|
11
|
+
CompressionSelectorInjected,
|
|
12
|
+
ContextCompressionSettings,
|
|
13
|
+
} from '../src/client/CompressionProfileSelector.tsx'
|
|
14
|
+
|
|
15
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
16
|
+
IconChevronDownOutline14: () => null,
|
|
17
|
+
Menu: () => null,
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const CUSTOM = {
|
|
21
|
+
version: 1,
|
|
22
|
+
unit: 'tokens',
|
|
23
|
+
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
24
|
+
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
25
|
+
history: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
trigger: 32_768,
|
|
28
|
+
keepRecentTurns: 2,
|
|
29
|
+
keepRecent: 16_384,
|
|
30
|
+
minReclaim: 8_192,
|
|
31
|
+
},
|
|
32
|
+
prefixPolicy: 'pressure-break',
|
|
33
|
+
} as const satisfies ContextCompressionSettings['custom']
|
|
34
|
+
|
|
35
|
+
describe('context compression browser contract', () => {
|
|
36
|
+
it('accepts legacy v1 and defaults new edits to v3 with TailTrim disabled', () => {
|
|
37
|
+
expect(isCustomCompressionPolicy(CUSTOM)).toBe(true)
|
|
38
|
+
expect(DEFAULT_CUSTOM_COMPRESSION_POLICY).toMatchObject({
|
|
39
|
+
version: 3,
|
|
40
|
+
tailTrim: { enabled: false, trigger: 700_000 },
|
|
41
|
+
})
|
|
42
|
+
expect(isCustomCompressionPolicy(DEFAULT_CUSTOM_COMPRESSION_POLICY)).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('fails the browser narrowing for unknown or invalid Custom fields', () => {
|
|
46
|
+
expect(isCustomCompressionPolicy({
|
|
47
|
+
...structuredClone(CUSTOM),
|
|
48
|
+
tailTrim: { enabled: true },
|
|
49
|
+
})).toBe(false)
|
|
50
|
+
expect(isCustomCompressionPolicy({
|
|
51
|
+
...structuredClone(CUSTOM),
|
|
52
|
+
fresh: { enabled: true, trigger: 100, target: 100 },
|
|
53
|
+
})).toBe(false)
|
|
54
|
+
for (const trigger of [0, -1]) {
|
|
55
|
+
expect(isCustomCompressionPolicy({
|
|
56
|
+
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
57
|
+
tailTrim: { enabled: true, trigger },
|
|
58
|
+
})).toBe(false)
|
|
59
|
+
}
|
|
60
|
+
expect(isCustomCompressionPolicy({
|
|
61
|
+
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
62
|
+
unit: 'context-percent',
|
|
63
|
+
tailTrim: { enabled: true, trigger: 101 },
|
|
64
|
+
})).toBe(false)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('decodes legacy settings to the default threshold and rejects malformed sections', async () => {
|
|
68
|
+
// Legacy documents stored before autoCompact existed inherit 80%.
|
|
69
|
+
const legacy = decodeSettings({ profile: 'balanced', custom: structuredClone(CUSTOM) })
|
|
70
|
+
expect(legacy).toMatchObject({ autoCompact: { thresholdPercent: 80 } })
|
|
71
|
+
// A present-but-invalid threshold fails the whole decode.
|
|
72
|
+
expect(decodeSettings({
|
|
73
|
+
profile: 'balanced',
|
|
74
|
+
custom: structuredClone(CUSTOM),
|
|
75
|
+
autoCompact: { thresholdPercent: 91 },
|
|
76
|
+
})).toBeUndefined()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('reports a recovered no-op write only on the selector boundary', async () => {
|
|
80
|
+
let revision = 7
|
|
81
|
+
let commit = false
|
|
82
|
+
let rewriteCustom = false
|
|
83
|
+
let rewriteReset = false
|
|
84
|
+
let dropTailTrim = false
|
|
85
|
+
let downgradeVersion = false
|
|
86
|
+
let value: ContextCompressionSettings = {
|
|
87
|
+
profile: 'balanced',
|
|
88
|
+
custom: structuredClone(CUSTOM),
|
|
89
|
+
autoCompact: { thresholdPercent: 80 },
|
|
90
|
+
codeSkeleton: { enabled: false },
|
|
91
|
+
intentSummary: { enabled: false },
|
|
92
|
+
}
|
|
93
|
+
const snapshot = (): SettingsScopeSnapshot<ContextCompressionSettings> => ({
|
|
94
|
+
status: 'ready',
|
|
95
|
+
value,
|
|
96
|
+
base: undefined,
|
|
97
|
+
user: undefined,
|
|
98
|
+
revision,
|
|
99
|
+
writable: true,
|
|
100
|
+
mode: 'host',
|
|
101
|
+
})
|
|
102
|
+
const scope = {
|
|
103
|
+
getSnapshot: snapshot,
|
|
104
|
+
subscribe: vi.fn(() => () => {}),
|
|
105
|
+
set: vi.fn(async (field: string, next: unknown) => {
|
|
106
|
+
if (!commit) return
|
|
107
|
+
revision += 1
|
|
108
|
+
if (field === 'custom' && rewriteCustom) {
|
|
109
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
110
|
+
accepted.fresh.trigger += 1
|
|
111
|
+
value = { ...value, custom: accepted }
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
if (field === 'custom' && rewriteReset) {
|
|
115
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
116
|
+
accepted.fresh.trigger += 1
|
|
117
|
+
value = { ...value, custom: accepted }
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (field === 'custom' && dropTailTrim) {
|
|
121
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
122
|
+
if (accepted.version === 3) {
|
|
123
|
+
accepted.tailTrim = { enabled: false, trigger: 700_000 }
|
|
124
|
+
}
|
|
125
|
+
value = { ...value, custom: accepted }
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
if (field === 'custom' && downgradeVersion) {
|
|
129
|
+
value = { ...value, custom: structuredClone(CUSTOM) }
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
value = { ...value, [field]: next }
|
|
133
|
+
}),
|
|
134
|
+
unset: vi.fn(async () => {
|
|
135
|
+
if (!commit) return
|
|
136
|
+
revision += 1
|
|
137
|
+
const custom: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
138
|
+
if (rewriteReset) {
|
|
139
|
+
custom.fresh.trigger = 8_192
|
|
140
|
+
custom.fresh.target = 4_096
|
|
141
|
+
}
|
|
142
|
+
value = { ...value, custom }
|
|
143
|
+
}),
|
|
144
|
+
}
|
|
145
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
146
|
+
const ctx = {
|
|
147
|
+
effect: (install: () => unknown) => { install() },
|
|
148
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
149
|
+
settingsScope: { bind: vi.fn(() => scope) },
|
|
150
|
+
slots: {
|
|
151
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
152
|
+
register: (registration: { name?: string, inject?: () => CompressionSelectorInjected }) => {
|
|
153
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
154
|
+
if (registration.name === 'settings.section' && typeof registration.inject === 'function') injected = registration.inject
|
|
155
|
+
return () => {}
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
} as unknown as ClientContext
|
|
159
|
+
|
|
160
|
+
apply(ctx)
|
|
161
|
+
const actions = injected?.()
|
|
162
|
+
expect(actions).toBeDefined()
|
|
163
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
164
|
+
await expect(actions.select('native')).rejects.toThrow('were not saved')
|
|
165
|
+
|
|
166
|
+
commit = true
|
|
167
|
+
await expect(actions.select('native')).resolves.toBeUndefined()
|
|
168
|
+
expect(value.profile).toBe('native')
|
|
169
|
+
|
|
170
|
+
const requested: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
171
|
+
requested.fresh.trigger = 8_192
|
|
172
|
+
requested.fresh.target = 4_096
|
|
173
|
+
rewriteCustom = true
|
|
174
|
+
await expect(actions.saveCustom(requested)).rejects.toThrow('were not saved')
|
|
175
|
+
|
|
176
|
+
rewriteCustom = false
|
|
177
|
+
const requestedV3 = structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
178
|
+
if (requestedV3.version !== 3) throw new Error('Custom TailTrim persistence fixture requires policy v3')
|
|
179
|
+
requestedV3.tailTrim = { enabled: true, trigger: 49_152 }
|
|
180
|
+
dropTailTrim = true
|
|
181
|
+
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
182
|
+
|
|
183
|
+
dropTailTrim = false
|
|
184
|
+
downgradeVersion = true
|
|
185
|
+
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
186
|
+
|
|
187
|
+
downgradeVersion = false
|
|
188
|
+
rewriteReset = true
|
|
189
|
+
await expect(actions.resetCustom()).rejects.toThrow('were not saved')
|
|
190
|
+
|
|
191
|
+
rewriteReset = false
|
|
192
|
+
await expect(actions.resetCustom()).resolves.toBeUndefined()
|
|
193
|
+
expect(scope.set).toHaveBeenLastCalledWith('custom', DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
194
|
+
expect(scope.unset).not.toHaveBeenCalled()
|
|
195
|
+
|
|
196
|
+
// The Auto Compact threshold shares the same confirm-on-write boundary:
|
|
197
|
+
// committed writes resolve, and a silent host drop rejects.
|
|
198
|
+
commit = false
|
|
199
|
+
await expect(actions.saveAutoCompact(73)).rejects.toThrow('were not saved')
|
|
200
|
+
commit = true
|
|
201
|
+
await expect(actions.saveAutoCompact(73)).resolves.toBeUndefined()
|
|
202
|
+
expect(scope.set).toHaveBeenLastCalledWith('autoCompact', { thresholdPercent: 73 })
|
|
203
|
+
expect(value.autoCompact).toEqual({ thresholdPercent: 73 })
|
|
204
|
+
})
|
|
205
|
+
})
|