dsh-context-compression-improved 0.5.5 → 0.5.7
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 -2
- package/.githooks/pre-push +37 -37
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.ja.md +169 -169
- package/CHANGELOG.ko.md +167 -167
- package/CHANGELOG.md +314 -304
- package/CHANGELOG.zh.md +152 -152
- package/CONTRIBUTING.md +22 -22
- package/LICENSE +21 -21
- package/README.ja.md +85 -85
- package/README.ko.md +85 -85
- package/README.md +94 -85
- package/README.zh.md +85 -85
- package/SECURITY.md +18 -18
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -77
- package/docs/installation.ja.md +78 -78
- package/docs/installation.ko.md +78 -78
- package/docs/installation.md +103 -103
- package/docs/installation.zh.md +100 -100
- package/docs/repair-log.md +657 -657
- package/eslint.config.js +30 -30
- package/package.json +164 -160
- package/packages/selector/LICENSE +21 -21
- package/packages/selector/README.md +26 -21
- package/packages/selector/README.zh.md +24 -19
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
- package/packages/selector/cordis.patch.yml +27 -27
- package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.js +733 -0
- package/packages/selector/lib/style.css +46 -46
- package/packages/selector/package.json +114 -114
- package/packages/selector/screenshots.json +3 -3
- package/packages/selector/src/client/CompressionProfileControls.tsx +226 -226
- package/packages/selector/src/client/CompressionProfileSelector.module.css +170 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +83 -83
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
- package/packages/selector/src/client/EstimatorControls.tsx +277 -277
- package/packages/selector/src/client/decode.ts +49 -49
- package/packages/selector/src/client/index.ts +178 -149
- package/packages/selector/src/client/locales/de.ts +98 -0
- package/packages/selector/src/client/locales/es.ts +98 -0
- package/packages/selector/src/client/locales/fr.ts +98 -0
- package/packages/selector/src/client/locales/it.ts +98 -0
- package/packages/selector/src/client/locales/ja.ts +98 -0
- package/packages/selector/src/client/locales/ko.ts +98 -0
- package/packages/selector/src/client/locales/ru.ts +98 -0
- package/packages/selector/src/client/locales.ts +196 -196
- package/packages/selector/src/client/preset-options.ts +88 -88
- package/packages/selector/src/client/settings-section.tsx +124 -124
- package/packages/selector/src/css-modules.d.ts +6 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
- package/packages/selector/src/estimator-catalog.ts +104 -104
- package/packages/selector/src/index.ts +463 -463
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/preset-overlay.ts +626 -626
- package/packages/selector/src/profiles.ts +394 -394
- package/packages/selector/src/pruner/content.ts +201 -201
- package/packages/selector/src/pruner/session.ts +94 -94
- package/packages/selector/src/pruner/state.ts +50 -50
- package/packages/selector/src/pruner/tuning.ts +23 -23
- package/packages/selector/src/pruner/types.ts +78 -78
- package/packages/selector/src/pruner.ts +2402 -2402
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
- package/packages/selector/src/runtime/audit.ts +286 -286
- package/packages/selector/src/runtime/config.ts +706 -706
- package/packages/selector/src/runtime/custom-policy.ts +278 -278
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
- package/packages/selector/src/runtime/measurement.ts +436 -436
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/retrieve.ts +457 -457
- package/packages/selector/src/runtime/session-events.ts +30 -30
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/token-count.ts +72 -72
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +188 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +149 -149
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
- package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -303
- package/packages/selector/src/runtime/toolclass.ts +103 -103
- package/packages/selector/src/runtime/types.ts +346 -346
- package/packages/selector/src/runtime/value.ts +48 -48
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
- package/packages/selector/tests/auto-compact.client.spec.tsx +213 -213
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -59
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +90 -90
- package/packages/selector/tests/custom-contract.client.spec.ts +204 -204
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
- package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +188 -188
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
- package/packages/selector/tests/preset-options-write.client.spec.ts +206 -206
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -201
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
- package/packages/selector/tests/profiles.client.spec.tsx +434 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -232
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
- package/packages/selector/tests/runtime/audit.spec.ts +274 -274
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
- package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2724
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -116
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
- package/packages/selector/tests/runtime/value.spec.ts +23 -23
- package/packages/selector/tests/settings-seat.client.spec.ts +118 -118
- package/packages/selector/tests/standing-generation.host.spec.ts +697 -697
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -253
- package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
- package/packages/selector/tests/support/mock-adapter.ts +37 -37
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/packages/selector/tsconfig.json +11 -11
- package/packages/selector/tsdown.client.config.ts +102 -102
- package/packages/selector/tsdown.config.ts +20 -20
- package/pnpm-workspace.yaml +66 -66
- package/scripts/capture-profile-baseline.mjs +42 -42
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/packed-components-smoke.mjs +732 -732
- package/scripts/packed-install-e2e.mjs +1273 -1273
- package/scripts/toolclass-corpus-replay.mjs +281 -281
- package/scripts/verify-release.mjs +317 -317
- package/tests/TEST_INVENTORY.md +41 -41
- package/tsconfig.base.json +18 -18
- package/tsconfig.json +7 -7
- package/tsconfig.tests.json +15 -15
- package/vitest.built.config.ts +9 -9
- package/vitest.config.ts +43 -43
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { dirname, join } from 'node:path'
|
|
4
|
-
import { Context, Service } from '@deepseek-ai/cordis'
|
|
5
|
-
import type { AgentPreset } from '@deepseek-ai/dsh-agent-presets'
|
|
6
|
-
import {
|
|
7
|
-
SettingsProvider,
|
|
8
|
-
type SettingsNamespace,
|
|
9
|
-
} from '@deepseek-ai/dsh-settings'
|
|
10
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
11
|
-
import { apply } from '../src/index.ts'
|
|
12
|
-
import type { OverlayableAgentPresets } from '../src/preset-overlay.ts'
|
|
13
|
-
|
|
14
|
-
// 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
|
|
15
|
-
const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
|
|
16
|
-
|
|
17
|
-
let root: string | undefined
|
|
18
|
-
let ctx: Context | undefined
|
|
19
|
-
|
|
20
|
-
afterEach(async () => {
|
|
21
|
-
await ctx?.fiber.dispose()
|
|
22
|
-
ctx = undefined
|
|
23
|
-
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
|
24
|
-
root = undefined
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
class MemorySettings extends SettingsProvider {
|
|
28
|
-
readonly writable = true
|
|
29
|
-
private readonly stored: Record<string, unknown> = {}
|
|
30
|
-
|
|
31
|
-
protected load(): Promise<Record<string, unknown>> {
|
|
32
|
-
return Promise.resolve(structuredClone(this.stored))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
|
|
36
|
-
this.stored[ns] = structuredClone(section)
|
|
37
|
-
return Promise.resolve()
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class FakeAgentPresets extends Service implements OverlayableAgentPresets {
|
|
42
|
-
constructor(ctx: Context, readonly preset: AgentPreset) {
|
|
43
|
-
super(ctx, 'agentPresets')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async resolve(): Promise<AgentPreset> {
|
|
47
|
-
return this.preset
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async mount(_agentCtx: unknown): Promise<AgentPreset> {
|
|
51
|
-
return await this.resolve()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async recompose(_agentCtx: unknown, _id: string): Promise<AgentPreset> {
|
|
55
|
-
return await this.resolve()
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async standingKeyFor(): Promise<string> {
|
|
59
|
-
return (await this.resolve()).path
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function sourcePreset(): Promise<AgentPreset> {
|
|
64
|
-
root = await mkdtemp(join(tmpdir(), 'dsh-selector-host-overlay-'))
|
|
65
|
-
const path = join(root, 'standard', 'agent.cordis.yml')
|
|
66
|
-
await mkdir(dirname(path), { recursive: true })
|
|
67
|
-
await writeFile(path, "- id: persona\n name: '/opt/preset/persona.js'\n")
|
|
68
|
-
return { id: 'standard', trust: 'system', path }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe('context compression selector Host preset integration', () => {
|
|
72
|
-
it('decorates native composition only for the lifetime of the selector fiber', async () => {
|
|
73
|
-
const preset = await sourcePreset()
|
|
74
|
-
ctx = new Context()
|
|
75
|
-
await ctx.plugin(MemorySettings).await()
|
|
76
|
-
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
77
|
-
|
|
78
|
-
const selector = ctx.plugin({ apply: (child) => {
|
|
79
|
-
apply(child, { presetOverlay: true })
|
|
80
|
-
} })
|
|
81
|
-
await selector.await()
|
|
82
|
-
|
|
83
|
-
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
84
|
-
const mounted = await service.mount({})
|
|
85
|
-
expect(mounted.path).not.toBe(preset.path)
|
|
86
|
-
expect(await readFile(mounted.path, 'utf8')).toContain('id: tool-result-pruner')
|
|
87
|
-
expect((await service.resolve()).path).toBe(preset.path)
|
|
88
|
-
|
|
89
|
-
await selector.dispose()
|
|
90
|
-
expect((await service.mount({})).path).toBe(preset.path)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('keeps settings and overlay alive across duplicate Host row disposal', async () => {
|
|
94
|
-
const preset = await sourcePreset()
|
|
95
|
-
ctx = new Context()
|
|
96
|
-
await ctx.plugin(MemorySettings).await()
|
|
97
|
-
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
98
|
-
|
|
99
|
-
const builtIn = ctx.plugin({ apply })
|
|
100
|
-
await builtIn.await()
|
|
101
|
-
|
|
102
|
-
const namespace = nsBrand('context-compression')
|
|
103
|
-
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
104
|
-
expect((await service.mount({})).path).toBe(preset.path)
|
|
105
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
106
|
-
|
|
107
|
-
await ctx.settings.update(namespace, { profile: 'cache-strict' })
|
|
108
|
-
const selectedSettings = structuredClone(ctx.settings.get(namespace))
|
|
109
|
-
expect(selectedSettings).toMatchObject({ profile: 'cache-strict' })
|
|
110
|
-
|
|
111
|
-
const bundle = ctx.plugin({ apply: (child) => {
|
|
112
|
-
apply(child, { presetOverlay: true })
|
|
113
|
-
} })
|
|
114
|
-
await bundle.await()
|
|
115
|
-
|
|
116
|
-
const mounted = await service.mount({})
|
|
117
|
-
expect(mounted.path).not.toBe(preset.path)
|
|
118
|
-
expect((await service.recompose({}, 'standard')).path).toBe(mounted.path)
|
|
119
|
-
expect(ctx.settings.get(namespace)).toEqual(selectedSettings)
|
|
120
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
121
|
-
|
|
122
|
-
await builtIn.dispose()
|
|
123
|
-
expect((await service.mount({})).path).toBe(mounted.path)
|
|
124
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
125
|
-
|
|
126
|
-
await bundle.dispose()
|
|
127
|
-
expect((await service.mount({})).path).toBe(preset.path)
|
|
128
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(0)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('writes the saved Auto Compact threshold into the generated compaction-basic composition', async () => {
|
|
132
|
-
const preset = await sourcePreset()
|
|
133
|
-
ctx = new Context()
|
|
134
|
-
await ctx.plugin(MemorySettings).await()
|
|
135
|
-
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
136
|
-
// A settings-owning row must register the namespace before the update.
|
|
137
|
-
await ctx.plugin({ apply }).await()
|
|
138
|
-
const namespace = nsBrand('context-compression')
|
|
139
|
-
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
|
|
140
|
-
|
|
141
|
-
const bundle = ctx.plugin({ apply: (child) => {
|
|
142
|
-
apply(child, { presetOverlay: true })
|
|
143
|
-
} })
|
|
144
|
-
await bundle.await()
|
|
145
|
-
|
|
146
|
-
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
147
|
-
const mounted = await service.mount({})
|
|
148
|
-
const rendered = await readFile(mounted.path, 'utf8')
|
|
149
|
-
expect(rendered).toContain('id: compaction-basic')
|
|
150
|
-
expect(rendered).toContain('thresholdRatio: 0.73')
|
|
151
|
-
// First-release retention stays pinned at 0.16 next to the threshold.
|
|
152
|
-
expect(rendered).toContain('retainRatio: 0.16')
|
|
153
|
-
// The SAME read feeds the runtime deployment config, so one generation
|
|
154
|
-
// cannot split Auto Compact and micro compact across two thresholds.
|
|
155
|
-
expect(rendered).toContain('id: tool-result-pruner')
|
|
156
|
-
expect(rendered).toContain('autoCompactThresholdPercent: 73')
|
|
157
|
-
await bundle.dispose()
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
it('defaults the generated threshold to 0.8 and keeps it absent from settings until saved', async () => {
|
|
161
|
-
const preset = await sourcePreset()
|
|
162
|
-
ctx = new Context()
|
|
163
|
-
await ctx.plugin(MemorySettings).await()
|
|
164
|
-
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
165
|
-
|
|
166
|
-
const bundle = ctx.plugin({ apply: (child) => {
|
|
167
|
-
apply(child, { presetOverlay: true })
|
|
168
|
-
} })
|
|
169
|
-
await bundle.await()
|
|
170
|
-
|
|
171
|
-
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
172
|
-
const rendered = await readFile((await service.mount({})).path, 'utf8')
|
|
173
|
-
expect(rendered).toContain('thresholdRatio: 0.8')
|
|
174
|
-
await bundle.dispose()
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('moves the standing composition generation when an equal-length threshold changes', async () => {
|
|
178
|
-
const preset = await sourcePreset()
|
|
179
|
-
ctx = new Context()
|
|
180
|
-
await ctx.plugin(MemorySettings).await()
|
|
181
|
-
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
182
|
-
// A settings-owning row must register the namespace before the update.
|
|
183
|
-
await ctx.plugin({ apply }).await()
|
|
184
|
-
const namespace = nsBrand('context-compression')
|
|
185
|
-
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 70 } })
|
|
186
|
-
|
|
187
|
-
const bundle = ctx.plugin({ apply: (child) => {
|
|
188
|
-
apply(child, { presetOverlay: true })
|
|
189
|
-
} })
|
|
190
|
-
await bundle.await()
|
|
191
|
-
|
|
192
|
-
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
193
|
-
const first = await service.mount({})
|
|
194
|
-
expect(await readFile(first.path, 'utf8')).toContain('thresholdRatio: 0.7')
|
|
195
|
-
expect(await service.standingKeyFor()).toBe(first.path)
|
|
196
|
-
|
|
197
|
-
// Same character length, different content: the generated identity and
|
|
198
|
-
// standing composition generation must both move to the new threshold.
|
|
199
|
-
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 80 } })
|
|
200
|
-
const second = await service.mount({})
|
|
201
|
-
expect(second.path).not.toBe(first.path)
|
|
202
|
-
expect(await readFile(second.path, 'utf8')).toContain('thresholdRatio: 0.8')
|
|
203
|
-
expect(await service.standingKeyFor()).toBe(second.path)
|
|
204
|
-
await bundle.dispose()
|
|
205
|
-
})
|
|
206
|
-
})
|
|
1
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { Context, Service } from '@deepseek-ai/cordis'
|
|
5
|
+
import type { AgentPreset } from '@deepseek-ai/dsh-agent-presets'
|
|
6
|
+
import {
|
|
7
|
+
SettingsProvider,
|
|
8
|
+
type SettingsNamespace,
|
|
9
|
+
} from '@deepseek-ai/dsh-settings'
|
|
10
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
11
|
+
import { apply } from '../src/index.ts'
|
|
12
|
+
import type { OverlayableAgentPresets } from '../src/preset-overlay.ts'
|
|
13
|
+
|
|
14
|
+
// 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
|
|
15
|
+
const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
|
|
16
|
+
|
|
17
|
+
let root: string | undefined
|
|
18
|
+
let ctx: Context | undefined
|
|
19
|
+
|
|
20
|
+
afterEach(async () => {
|
|
21
|
+
await ctx?.fiber.dispose()
|
|
22
|
+
ctx = undefined
|
|
23
|
+
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
|
24
|
+
root = undefined
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
class MemorySettings extends SettingsProvider {
|
|
28
|
+
readonly writable = true
|
|
29
|
+
private readonly stored: Record<string, unknown> = {}
|
|
30
|
+
|
|
31
|
+
protected load(): Promise<Record<string, unknown>> {
|
|
32
|
+
return Promise.resolve(structuredClone(this.stored))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
|
|
36
|
+
this.stored[ns] = structuredClone(section)
|
|
37
|
+
return Promise.resolve()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class FakeAgentPresets extends Service implements OverlayableAgentPresets {
|
|
42
|
+
constructor(ctx: Context, readonly preset: AgentPreset) {
|
|
43
|
+
super(ctx, 'agentPresets')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async resolve(): Promise<AgentPreset> {
|
|
47
|
+
return this.preset
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async mount(_agentCtx: unknown): Promise<AgentPreset> {
|
|
51
|
+
return await this.resolve()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async recompose(_agentCtx: unknown, _id: string): Promise<AgentPreset> {
|
|
55
|
+
return await this.resolve()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async standingKeyFor(): Promise<string> {
|
|
59
|
+
return (await this.resolve()).path
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function sourcePreset(): Promise<AgentPreset> {
|
|
64
|
+
root = await mkdtemp(join(tmpdir(), 'dsh-selector-host-overlay-'))
|
|
65
|
+
const path = join(root, 'standard', 'agent.cordis.yml')
|
|
66
|
+
await mkdir(dirname(path), { recursive: true })
|
|
67
|
+
await writeFile(path, "- id: persona\n name: '/opt/preset/persona.js'\n")
|
|
68
|
+
return { id: 'standard', trust: 'system', path }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe('context compression selector Host preset integration', () => {
|
|
72
|
+
it('decorates native composition only for the lifetime of the selector fiber', async () => {
|
|
73
|
+
const preset = await sourcePreset()
|
|
74
|
+
ctx = new Context()
|
|
75
|
+
await ctx.plugin(MemorySettings).await()
|
|
76
|
+
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
77
|
+
|
|
78
|
+
const selector = ctx.plugin({ apply: (child) => {
|
|
79
|
+
apply(child, { presetOverlay: true })
|
|
80
|
+
} })
|
|
81
|
+
await selector.await()
|
|
82
|
+
|
|
83
|
+
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
84
|
+
const mounted = await service.mount({})
|
|
85
|
+
expect(mounted.path).not.toBe(preset.path)
|
|
86
|
+
expect(await readFile(mounted.path, 'utf8')).toContain('id: tool-result-pruner')
|
|
87
|
+
expect((await service.resolve()).path).toBe(preset.path)
|
|
88
|
+
|
|
89
|
+
await selector.dispose()
|
|
90
|
+
expect((await service.mount({})).path).toBe(preset.path)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('keeps settings and overlay alive across duplicate Host row disposal', async () => {
|
|
94
|
+
const preset = await sourcePreset()
|
|
95
|
+
ctx = new Context()
|
|
96
|
+
await ctx.plugin(MemorySettings).await()
|
|
97
|
+
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
98
|
+
|
|
99
|
+
const builtIn = ctx.plugin({ apply })
|
|
100
|
+
await builtIn.await()
|
|
101
|
+
|
|
102
|
+
const namespace = nsBrand('context-compression')
|
|
103
|
+
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
104
|
+
expect((await service.mount({})).path).toBe(preset.path)
|
|
105
|
+
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
106
|
+
|
|
107
|
+
await ctx.settings.update(namespace, { profile: 'cache-strict' })
|
|
108
|
+
const selectedSettings = structuredClone(ctx.settings.get(namespace))
|
|
109
|
+
expect(selectedSettings).toMatchObject({ profile: 'cache-strict' })
|
|
110
|
+
|
|
111
|
+
const bundle = ctx.plugin({ apply: (child) => {
|
|
112
|
+
apply(child, { presetOverlay: true })
|
|
113
|
+
} })
|
|
114
|
+
await bundle.await()
|
|
115
|
+
|
|
116
|
+
const mounted = await service.mount({})
|
|
117
|
+
expect(mounted.path).not.toBe(preset.path)
|
|
118
|
+
expect((await service.recompose({}, 'standard')).path).toBe(mounted.path)
|
|
119
|
+
expect(ctx.settings.get(namespace)).toEqual(selectedSettings)
|
|
120
|
+
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
121
|
+
|
|
122
|
+
await builtIn.dispose()
|
|
123
|
+
expect((await service.mount({})).path).toBe(mounted.path)
|
|
124
|
+
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
125
|
+
|
|
126
|
+
await bundle.dispose()
|
|
127
|
+
expect((await service.mount({})).path).toBe(preset.path)
|
|
128
|
+
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(0)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('writes the saved Auto Compact threshold into the generated compaction-basic composition', async () => {
|
|
132
|
+
const preset = await sourcePreset()
|
|
133
|
+
ctx = new Context()
|
|
134
|
+
await ctx.plugin(MemorySettings).await()
|
|
135
|
+
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
136
|
+
// A settings-owning row must register the namespace before the update.
|
|
137
|
+
await ctx.plugin({ apply }).await()
|
|
138
|
+
const namespace = nsBrand('context-compression')
|
|
139
|
+
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
|
|
140
|
+
|
|
141
|
+
const bundle = ctx.plugin({ apply: (child) => {
|
|
142
|
+
apply(child, { presetOverlay: true })
|
|
143
|
+
} })
|
|
144
|
+
await bundle.await()
|
|
145
|
+
|
|
146
|
+
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
147
|
+
const mounted = await service.mount({})
|
|
148
|
+
const rendered = await readFile(mounted.path, 'utf8')
|
|
149
|
+
expect(rendered).toContain('id: compaction-basic')
|
|
150
|
+
expect(rendered).toContain('thresholdRatio: 0.73')
|
|
151
|
+
// First-release retention stays pinned at 0.16 next to the threshold.
|
|
152
|
+
expect(rendered).toContain('retainRatio: 0.16')
|
|
153
|
+
// The SAME read feeds the runtime deployment config, so one generation
|
|
154
|
+
// cannot split Auto Compact and micro compact across two thresholds.
|
|
155
|
+
expect(rendered).toContain('id: tool-result-pruner')
|
|
156
|
+
expect(rendered).toContain('autoCompactThresholdPercent: 73')
|
|
157
|
+
await bundle.dispose()
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('defaults the generated threshold to 0.8 and keeps it absent from settings until saved', async () => {
|
|
161
|
+
const preset = await sourcePreset()
|
|
162
|
+
ctx = new Context()
|
|
163
|
+
await ctx.plugin(MemorySettings).await()
|
|
164
|
+
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
165
|
+
|
|
166
|
+
const bundle = ctx.plugin({ apply: (child) => {
|
|
167
|
+
apply(child, { presetOverlay: true })
|
|
168
|
+
} })
|
|
169
|
+
await bundle.await()
|
|
170
|
+
|
|
171
|
+
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
172
|
+
const rendered = await readFile((await service.mount({})).path, 'utf8')
|
|
173
|
+
expect(rendered).toContain('thresholdRatio: 0.8')
|
|
174
|
+
await bundle.dispose()
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('moves the standing composition generation when an equal-length threshold changes', async () => {
|
|
178
|
+
const preset = await sourcePreset()
|
|
179
|
+
ctx = new Context()
|
|
180
|
+
await ctx.plugin(MemorySettings).await()
|
|
181
|
+
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
182
|
+
// A settings-owning row must register the namespace before the update.
|
|
183
|
+
await ctx.plugin({ apply }).await()
|
|
184
|
+
const namespace = nsBrand('context-compression')
|
|
185
|
+
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 70 } })
|
|
186
|
+
|
|
187
|
+
const bundle = ctx.plugin({ apply: (child) => {
|
|
188
|
+
apply(child, { presetOverlay: true })
|
|
189
|
+
} })
|
|
190
|
+
await bundle.await()
|
|
191
|
+
|
|
192
|
+
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
193
|
+
const first = await service.mount({})
|
|
194
|
+
expect(await readFile(first.path, 'utf8')).toContain('thresholdRatio: 0.7')
|
|
195
|
+
expect(await service.standingKeyFor()).toBe(first.path)
|
|
196
|
+
|
|
197
|
+
// Same character length, different content: the generated identity and
|
|
198
|
+
// standing composition generation must both move to the new threshold.
|
|
199
|
+
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 80 } })
|
|
200
|
+
const second = await service.mount({})
|
|
201
|
+
expect(second.path).not.toBe(first.path)
|
|
202
|
+
expect(await readFile(second.path, 'utf8')).toContain('thresholdRatio: 0.8')
|
|
203
|
+
expect(await service.standingKeyFor()).toBe(second.path)
|
|
204
|
+
await bundle.dispose()
|
|
205
|
+
})
|
|
206
|
+
})
|