dsh-context-compression-improved 0.6.0 → 0.6.2
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/package.json +6 -6
- package/packages/selector/lib/client.d.ts +27 -19
- package/packages/selector/lib/client.js +5 -5
- package/packages/selector/lib/pruner.d.ts +7 -0
- package/packages/selector/lib/pruner.js +20 -33
- package/packages/selector/lib/tail-trim.js +3 -6
- package/packages/selector/package.json +1 -1
- package/packages/selector/src/client/CompressionProfileControls.tsx +2 -2
- package/packages/selector/src/client/CompressionProfileSelector.tsx +1 -1
- package/packages/selector/src/client/index.ts +7 -8
- package/packages/selector/src/client/scope-face.ts +21 -0
- package/packages/selector/src/pruner/content.ts +0 -3
- package/packages/selector/src/pruner/session.ts +4 -2
- package/packages/selector/src/pruner.ts +26 -15
- package/packages/selector/src/runtime/measurement.ts +3 -8
- package/packages/selector/src/runtime/retrieve.ts +3 -3
- package/packages/selector/src/runtime/tail-trim.ts +4 -5
- package/packages/selector/tests/code-skeleton.client.spec.ts +93 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +222 -222
- package/packages/selector/tests/helpers/legacy-namespace.ts +31 -31
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
- package/packages/selector/tests/preset-options-write.client.spec.ts +1 -1
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +206 -206
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -3
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -20
- package/packages/selector/tests/settings-seat.client.spec.ts +118 -118
- package/packages/selector/tests/standing-generation.host.spec.ts +704 -704
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/pnpm-workspace.yaml +42 -42
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { join } from 'node:path'
|
|
4
|
-
import { pathToFileURL } from 'node:url'
|
|
5
|
-
import { Context } from '@deepseek-ai/cordis'
|
|
6
|
-
import Group from '@deepseek-ai/cordis-plugin-group'
|
|
7
|
-
import Include from '@deepseek-ai/cordis-plugin-include'
|
|
8
|
-
import { Config } from '../src/index.ts'
|
|
9
|
-
import Loader from '@deepseek-ai/cordis-plugin-loader'
|
|
10
|
-
import AgentRegistry, { type Agent } from '@deepseek-ai/dsh-agent'
|
|
11
|
-
import AgentLoop from '@deepseek-ai/dsh-agent-loop'
|
|
12
|
-
import AgentPresets, { COMPOSITION_FILE } from '@deepseek-ai/dsh-agent-presets'
|
|
13
|
-
import CommandRuntime from '@deepseek-ai/dsh-commands'
|
|
14
|
-
import LlmRuntime from '@deepseek-ai/dsh-llm'
|
|
15
|
-
import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
|
|
16
|
-
import { scopeOf } from '@deepseek-ai/dsh-scope'
|
|
17
|
-
import {
|
|
18
|
-
SettingsProvider,
|
|
19
|
-
type SettingsNamespace,
|
|
20
|
-
} from '@deepseek-ai/dsh-settings'
|
|
21
|
-
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
22
|
-
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
|
|
23
|
-
import TokenMeter from '@deepseek-ai/dsh-token-meter'
|
|
24
|
-
import ToolRuntime from '@deepseek-ai/dsh-tools'
|
|
25
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
26
|
-
import { apply } from '../src/index.ts'
|
|
27
|
-
import { LegacyNamespaceRegistrar } from './helpers/legacy-namespace.ts'
|
|
28
|
-
|
|
29
|
-
// 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
|
|
30
|
-
const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
|
|
31
|
-
|
|
32
|
-
const CORDIS_ORIGINAL = Symbol.for('cordis.original')
|
|
33
|
-
type Traceable = { [CORDIS_ORIGINAL]?: unknown }
|
|
34
|
-
|
|
35
|
-
let ctx: Context | undefined
|
|
36
|
-
let root: string | undefined
|
|
37
|
-
|
|
38
|
-
afterEach(async () => {
|
|
39
|
-
await ctx?.fiber.dispose()
|
|
40
|
-
ctx = undefined
|
|
41
|
-
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
|
42
|
-
root = undefined
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
class MemorySettings extends SettingsProvider {
|
|
46
|
-
readonly writable = true
|
|
47
|
-
|
|
48
|
-
protected load(): Promise<Record<string, unknown>> {
|
|
49
|
-
return Promise.resolve({})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected persist(_ns: SettingsNamespace, _section: Record<string, unknown>): Promise<void> {
|
|
53
|
-
return Promise.resolve()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface CustomSettings {
|
|
58
|
-
profile: string
|
|
59
|
-
custom: {
|
|
60
|
-
history: { trigger: number }
|
|
61
|
-
tailTrim: { enabled: boolean; trigger: number }
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function createPresetRoot(): Promise<string> {
|
|
66
|
-
root = await mkdtemp(join(tmpdir(), 'dsh-selector-loader-e2e-'))
|
|
67
|
-
const marker = join(root, 'marker.mjs')
|
|
68
|
-
await writeFile(marker, 'export function apply() {}\n')
|
|
69
|
-
const source = `- id: source-marker\n name: ${JSON.stringify(marker)}\n`
|
|
70
|
-
for (const id of ['standard', 'custom', 'minimal']) {
|
|
71
|
-
const directory = join(root, id)
|
|
72
|
-
await mkdir(directory)
|
|
73
|
-
await writeFile(join(directory, COMPOSITION_FILE), source)
|
|
74
|
-
}
|
|
75
|
-
return root
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function harness(): Promise<Context> {
|
|
79
|
-
const presets = await createPresetRoot()
|
|
80
|
-
const runtime = new Context()
|
|
81
|
-
runtime.baseUrl = `${pathToFileURL(presets).href}/`
|
|
82
|
-
await runtime.plugin(Loader).await()
|
|
83
|
-
runtime.loader.builtins.include = Include
|
|
84
|
-
runtime.loader.builtins.group = Group
|
|
85
|
-
await runtime.plugin(LlmRuntime).await()
|
|
86
|
-
await runtime.plugin(SessionStore).await()
|
|
87
|
-
await runtime.plugin(SystemPrompt).await()
|
|
88
|
-
await runtime.plugin(ToolRuntime).await()
|
|
89
|
-
await runtime.plugin(AgentRegistry).await()
|
|
90
|
-
await runtime.plugin(AgentLoop).await()
|
|
91
|
-
await runtime.plugin(CommandRuntime).await()
|
|
92
|
-
await runtime.plugin(SessionProjectionRegistry).await()
|
|
93
|
-
await runtime.plugin(TokenMeter).await()
|
|
94
|
-
await runtime.plugin(MemorySettings).await()
|
|
95
|
-
await runtime.plugin(AgentPresets, {
|
|
96
|
-
default: 'standard',
|
|
97
|
-
roots: [{ path: presets, trust: 'system' }],
|
|
98
|
-
includeShippedRoot: false,
|
|
99
|
-
includeUserRoot: false,
|
|
100
|
-
})
|
|
101
|
-
await runtime.plugin({
|
|
102
|
-
apply: (selectorCtx) => {
|
|
103
|
-
apply(selectorCtx, { presetOverlay: true })
|
|
104
|
-
},
|
|
105
|
-
}).await()
|
|
106
|
-
ctx = runtime
|
|
107
|
-
return runtime
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function agentOn(runtime: Context, sessionId: string, preset: string): Promise<Agent> {
|
|
111
|
-
const handle = await runtime.agents.create({
|
|
112
|
-
sessionId: SessionId(sessionId),
|
|
113
|
-
setup: async agentCtx => void await runtime.agentPresets.mount(agentCtx, preset),
|
|
114
|
-
})
|
|
115
|
-
return handle.agent
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function hasCompressionRetrieve(runtime: Context, agent: Agent): boolean {
|
|
119
|
-
return runtime.tools.get('context_compression_retrieve', scopeOf(agent.ctx)) !== undefined
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function hasCompactCommand(runtime: Context, agent: Agent): boolean {
|
|
123
|
-
return runtime.commands.list(agent).some(command => command.name === 'compact')
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function expectCompleteCompressionStack(runtime: Context, agent: Agent): void {
|
|
127
|
-
expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeDefined()
|
|
128
|
-
expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeDefined()
|
|
129
|
-
expect(hasCompressionRetrieve(runtime, agent)).toBe(true)
|
|
130
|
-
expect(hasCompactCommand(runtime, agent)).toBe(true)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function expectNoCompressionStack(runtime: Context, agent: Agent): void {
|
|
134
|
-
expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeUndefined()
|
|
135
|
-
expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeUndefined()
|
|
136
|
-
expect(hasCompressionRetrieve(runtime, agent)).toBe(false)
|
|
137
|
-
expect(hasCompactCommand(runtime, agent)).toBe(false)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
describe('standalone selector Bundle through the real preset Loader', () => {
|
|
141
|
-
it('mounts the complete stack without changing source preset authoring', async () => {
|
|
142
|
-
const runtime = await harness()
|
|
143
|
-
const source = await runtime.agentPresets.resolve('standard')
|
|
144
|
-
const sourceText = await runtime.agentPresets.read('standard')
|
|
145
|
-
|
|
146
|
-
const agent = await agentOn(runtime, 'selector-loader-standard', 'standard')
|
|
147
|
-
|
|
148
|
-
expectCompleteCompressionStack(runtime, agent)
|
|
149
|
-
expect((await runtime.agentPresets.resolve('standard')).path).toBe(source.path)
|
|
150
|
-
expect(await runtime.agentPresets.read('standard')).toBe(sourceText)
|
|
151
|
-
expect(sourceText).not.toContain('tool-result-pruner')
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it('keeps compression across preset changes and excludes only exact Minimal', async () => {
|
|
155
|
-
const runtime = await harness()
|
|
156
|
-
const agent = await agentOn(runtime, 'selector-loader-switch', 'standard')
|
|
157
|
-
expectCompleteCompressionStack(runtime, agent)
|
|
158
|
-
|
|
159
|
-
await runtime.agentPresets.recompose(agent.ctx, 'minimal')
|
|
160
|
-
expectNoCompressionStack(runtime, agent)
|
|
161
|
-
|
|
162
|
-
// `custom` deliberately contains the same source rows as Minimal. Its id,
|
|
163
|
-
// not its copied contents, decides the one documented exception.
|
|
164
|
-
await runtime.agentPresets.recompose(agent.ctx, 'custom')
|
|
165
|
-
expectCompleteCompressionStack(runtime, agent)
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('gives a child the parent\'s exact compression service instances', async () => {
|
|
169
|
-
const runtime = await harness()
|
|
170
|
-
const parent = await agentOn(runtime, 'selector-loader-parent', 'standard')
|
|
171
|
-
const childHandle = await runtime.agents.create({
|
|
172
|
-
sessionId: SessionId('selector-loader-child'),
|
|
173
|
-
setup: childCtx => void runtime.agentPresets.composeFrom(childCtx, parent.ctx),
|
|
174
|
-
})
|
|
175
|
-
const child = childHandle.agent
|
|
176
|
-
|
|
177
|
-
const parentPruner = runtime.agentPresets.serviceFor(parent, 'toolResultPruner')
|
|
178
|
-
const childPruner = runtime.agentPresets.serviceFor(child, 'toolResultPruner')
|
|
179
|
-
const parentCompaction = runtime.agentPresets.serviceFor(parent, 'compaction')
|
|
180
|
-
const childCompaction = runtime.agentPresets.serviceFor(child, 'compaction')
|
|
181
|
-
expect(parentPruner).toBeDefined()
|
|
182
|
-
expect(parentCompaction).toBeDefined()
|
|
183
|
-
expect(Object.is(
|
|
184
|
-
(childPruner as Traceable)[CORDIS_ORIGINAL],
|
|
185
|
-
(parentPruner as Traceable)[CORDIS_ORIGINAL],
|
|
186
|
-
)).toBe(true)
|
|
187
|
-
expect(Object.is(
|
|
188
|
-
(childCompaction as Traceable)[CORDIS_ORIGINAL],
|
|
189
|
-
(parentCompaction as Traceable)[CORDIS_ORIGINAL],
|
|
190
|
-
)).toBe(true)
|
|
191
|
-
expect(hasCompressionRetrieve(runtime, child)).toBe(true)
|
|
192
|
-
expect(hasCompactCommand(runtime, child)).toBe(true)
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
it('carries the daily Custom defaults on the bundle entry config schema', async () => {
|
|
196
|
-
// 0.1.7: there is no plugin-owned settings row publishing defaults — the
|
|
197
|
-
// volatile `settings` field's schema defaults ARE the daily Custom doc the
|
|
198
|
-
// loader resolves into every composition.
|
|
199
|
-
const settings = (Config({ presetOverlay: true }).settings as unknown as {
|
|
200
|
-
get(): CustomSettings
|
|
201
|
-
}).get()
|
|
202
|
-
|
|
203
|
-
expect(settings.custom.history.trigger).toBe(500_000)
|
|
204
|
-
expect(settings.custom.tailTrim).toEqual({ enabled: false, trigger: 700_000 })
|
|
205
|
-
})
|
|
206
|
-
})
|
|
1
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
6
|
+
import Group from '@deepseek-ai/cordis-plugin-group'
|
|
7
|
+
import Include from '@deepseek-ai/cordis-plugin-include'
|
|
8
|
+
import { Config } from '../src/index.ts'
|
|
9
|
+
import Loader from '@deepseek-ai/cordis-plugin-loader'
|
|
10
|
+
import AgentRegistry, { type Agent } from '@deepseek-ai/dsh-agent'
|
|
11
|
+
import AgentLoop from '@deepseek-ai/dsh-agent-loop'
|
|
12
|
+
import AgentPresets, { COMPOSITION_FILE } from '@deepseek-ai/dsh-agent-presets'
|
|
13
|
+
import CommandRuntime from '@deepseek-ai/dsh-commands'
|
|
14
|
+
import LlmRuntime from '@deepseek-ai/dsh-llm'
|
|
15
|
+
import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
|
|
16
|
+
import { scopeOf } from '@deepseek-ai/dsh-scope'
|
|
17
|
+
import {
|
|
18
|
+
SettingsProvider,
|
|
19
|
+
type SettingsNamespace,
|
|
20
|
+
} from '@deepseek-ai/dsh-settings'
|
|
21
|
+
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
22
|
+
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
|
|
23
|
+
import TokenMeter from '@deepseek-ai/dsh-token-meter'
|
|
24
|
+
import ToolRuntime from '@deepseek-ai/dsh-tools'
|
|
25
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
26
|
+
import { apply } from '../src/index.ts'
|
|
27
|
+
import { LegacyNamespaceRegistrar } from './helpers/legacy-namespace.ts'
|
|
28
|
+
|
|
29
|
+
// 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
|
|
30
|
+
const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
|
|
31
|
+
|
|
32
|
+
const CORDIS_ORIGINAL = Symbol.for('cordis.original')
|
|
33
|
+
type Traceable = { [CORDIS_ORIGINAL]?: unknown }
|
|
34
|
+
|
|
35
|
+
let ctx: Context | undefined
|
|
36
|
+
let root: string | undefined
|
|
37
|
+
|
|
38
|
+
afterEach(async () => {
|
|
39
|
+
await ctx?.fiber.dispose()
|
|
40
|
+
ctx = undefined
|
|
41
|
+
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
|
42
|
+
root = undefined
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
class MemorySettings extends SettingsProvider {
|
|
46
|
+
readonly writable = true
|
|
47
|
+
|
|
48
|
+
protected load(): Promise<Record<string, unknown>> {
|
|
49
|
+
return Promise.resolve({})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected persist(_ns: SettingsNamespace, _section: Record<string, unknown>): Promise<void> {
|
|
53
|
+
return Promise.resolve()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface CustomSettings {
|
|
58
|
+
profile: string
|
|
59
|
+
custom: {
|
|
60
|
+
history: { trigger: number }
|
|
61
|
+
tailTrim: { enabled: boolean; trigger: number }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function createPresetRoot(): Promise<string> {
|
|
66
|
+
root = await mkdtemp(join(tmpdir(), 'dsh-selector-loader-e2e-'))
|
|
67
|
+
const marker = join(root, 'marker.mjs')
|
|
68
|
+
await writeFile(marker, 'export function apply() {}\n')
|
|
69
|
+
const source = `- id: source-marker\n name: ${JSON.stringify(marker)}\n`
|
|
70
|
+
for (const id of ['standard', 'custom', 'minimal']) {
|
|
71
|
+
const directory = join(root, id)
|
|
72
|
+
await mkdir(directory)
|
|
73
|
+
await writeFile(join(directory, COMPOSITION_FILE), source)
|
|
74
|
+
}
|
|
75
|
+
return root
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function harness(): Promise<Context> {
|
|
79
|
+
const presets = await createPresetRoot()
|
|
80
|
+
const runtime = new Context()
|
|
81
|
+
runtime.baseUrl = `${pathToFileURL(presets).href}/`
|
|
82
|
+
await runtime.plugin(Loader).await()
|
|
83
|
+
runtime.loader.builtins.include = Include
|
|
84
|
+
runtime.loader.builtins.group = Group
|
|
85
|
+
await runtime.plugin(LlmRuntime).await()
|
|
86
|
+
await runtime.plugin(SessionStore).await()
|
|
87
|
+
await runtime.plugin(SystemPrompt).await()
|
|
88
|
+
await runtime.plugin(ToolRuntime).await()
|
|
89
|
+
await runtime.plugin(AgentRegistry).await()
|
|
90
|
+
await runtime.plugin(AgentLoop).await()
|
|
91
|
+
await runtime.plugin(CommandRuntime).await()
|
|
92
|
+
await runtime.plugin(SessionProjectionRegistry).await()
|
|
93
|
+
await runtime.plugin(TokenMeter).await()
|
|
94
|
+
await runtime.plugin(MemorySettings).await()
|
|
95
|
+
await runtime.plugin(AgentPresets, {
|
|
96
|
+
default: 'standard',
|
|
97
|
+
roots: [{ path: presets, trust: 'system' }],
|
|
98
|
+
includeShippedRoot: false,
|
|
99
|
+
includeUserRoot: false,
|
|
100
|
+
})
|
|
101
|
+
await runtime.plugin({
|
|
102
|
+
apply: (selectorCtx) => {
|
|
103
|
+
apply(selectorCtx, { presetOverlay: true })
|
|
104
|
+
},
|
|
105
|
+
}).await()
|
|
106
|
+
ctx = runtime
|
|
107
|
+
return runtime
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function agentOn(runtime: Context, sessionId: string, preset: string): Promise<Agent> {
|
|
111
|
+
const handle = await runtime.agents.create({
|
|
112
|
+
sessionId: SessionId(sessionId),
|
|
113
|
+
setup: async agentCtx => void await runtime.agentPresets.mount(agentCtx, preset),
|
|
114
|
+
})
|
|
115
|
+
return handle.agent
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function hasCompressionRetrieve(runtime: Context, agent: Agent): boolean {
|
|
119
|
+
return runtime.tools.get('context_compression_retrieve', scopeOf(agent.ctx)) !== undefined
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function hasCompactCommand(runtime: Context, agent: Agent): boolean {
|
|
123
|
+
return runtime.commands.list(agent).some(command => command.name === 'compact')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function expectCompleteCompressionStack(runtime: Context, agent: Agent): void {
|
|
127
|
+
expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeDefined()
|
|
128
|
+
expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeDefined()
|
|
129
|
+
expect(hasCompressionRetrieve(runtime, agent)).toBe(true)
|
|
130
|
+
expect(hasCompactCommand(runtime, agent)).toBe(true)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function expectNoCompressionStack(runtime: Context, agent: Agent): void {
|
|
134
|
+
expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeUndefined()
|
|
135
|
+
expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeUndefined()
|
|
136
|
+
expect(hasCompressionRetrieve(runtime, agent)).toBe(false)
|
|
137
|
+
expect(hasCompactCommand(runtime, agent)).toBe(false)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
describe('standalone selector Bundle through the real preset Loader', () => {
|
|
141
|
+
it('mounts the complete stack without changing source preset authoring', async () => {
|
|
142
|
+
const runtime = await harness()
|
|
143
|
+
const source = await runtime.agentPresets.resolve('standard')
|
|
144
|
+
const sourceText = await runtime.agentPresets.read('standard')
|
|
145
|
+
|
|
146
|
+
const agent = await agentOn(runtime, 'selector-loader-standard', 'standard')
|
|
147
|
+
|
|
148
|
+
expectCompleteCompressionStack(runtime, agent)
|
|
149
|
+
expect((await runtime.agentPresets.resolve('standard')).path).toBe(source.path)
|
|
150
|
+
expect(await runtime.agentPresets.read('standard')).toBe(sourceText)
|
|
151
|
+
expect(sourceText).not.toContain('tool-result-pruner')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('keeps compression across preset changes and excludes only exact Minimal', async () => {
|
|
155
|
+
const runtime = await harness()
|
|
156
|
+
const agent = await agentOn(runtime, 'selector-loader-switch', 'standard')
|
|
157
|
+
expectCompleteCompressionStack(runtime, agent)
|
|
158
|
+
|
|
159
|
+
await runtime.agentPresets.recompose(agent.ctx, 'minimal')
|
|
160
|
+
expectNoCompressionStack(runtime, agent)
|
|
161
|
+
|
|
162
|
+
// `custom` deliberately contains the same source rows as Minimal. Its id,
|
|
163
|
+
// not its copied contents, decides the one documented exception.
|
|
164
|
+
await runtime.agentPresets.recompose(agent.ctx, 'custom')
|
|
165
|
+
expectCompleteCompressionStack(runtime, agent)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('gives a child the parent\'s exact compression service instances', async () => {
|
|
169
|
+
const runtime = await harness()
|
|
170
|
+
const parent = await agentOn(runtime, 'selector-loader-parent', 'standard')
|
|
171
|
+
const childHandle = await runtime.agents.create({
|
|
172
|
+
sessionId: SessionId('selector-loader-child'),
|
|
173
|
+
setup: childCtx => void runtime.agentPresets.composeFrom(childCtx, parent.ctx),
|
|
174
|
+
})
|
|
175
|
+
const child = childHandle.agent
|
|
176
|
+
|
|
177
|
+
const parentPruner = runtime.agentPresets.serviceFor(parent, 'toolResultPruner')
|
|
178
|
+
const childPruner = runtime.agentPresets.serviceFor(child, 'toolResultPruner')
|
|
179
|
+
const parentCompaction = runtime.agentPresets.serviceFor(parent, 'compaction')
|
|
180
|
+
const childCompaction = runtime.agentPresets.serviceFor(child, 'compaction')
|
|
181
|
+
expect(parentPruner).toBeDefined()
|
|
182
|
+
expect(parentCompaction).toBeDefined()
|
|
183
|
+
expect(Object.is(
|
|
184
|
+
(childPruner as Traceable)[CORDIS_ORIGINAL],
|
|
185
|
+
(parentPruner as Traceable)[CORDIS_ORIGINAL],
|
|
186
|
+
)).toBe(true)
|
|
187
|
+
expect(Object.is(
|
|
188
|
+
(childCompaction as Traceable)[CORDIS_ORIGINAL],
|
|
189
|
+
(parentCompaction as Traceable)[CORDIS_ORIGINAL],
|
|
190
|
+
)).toBe(true)
|
|
191
|
+
expect(hasCompressionRetrieve(runtime, child)).toBe(true)
|
|
192
|
+
expect(hasCompactCommand(runtime, child)).toBe(true)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('carries the daily Custom defaults on the bundle entry config schema', async () => {
|
|
196
|
+
// 0.1.7: there is no plugin-owned settings row publishing defaults — the
|
|
197
|
+
// volatile `settings` field's schema defaults ARE the daily Custom doc the
|
|
198
|
+
// loader resolves into every composition.
|
|
199
|
+
const settings = (Config({ presetOverlay: true }).settings as unknown as {
|
|
200
|
+
get(): CustomSettings
|
|
201
|
+
}).get()
|
|
202
|
+
|
|
203
|
+
expect(settings.custom.history.trigger).toBe(500_000)
|
|
204
|
+
expect(settings.custom.tailTrim).toEqual({ enabled: false, trigger: 700_000 })
|
|
205
|
+
})
|
|
206
|
+
})
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
|
|
5
|
-
const root = resolve(import.meta.dirname, '../../..')
|
|
6
|
-
|
|
7
|
-
describe('standalone package contract', () => {
|
|
8
|
-
it('ships one install-facing package with no intra-repo dependency edge', () => {
|
|
9
|
-
const selector = JSON.parse(readFileSync(resolve(root, 'selector/package.json'), 'utf8')) as {
|
|
10
|
-
name: string
|
|
11
|
-
version: string
|
|
12
|
-
dependencies?: Record<string, string>
|
|
13
|
-
peerDependencies?: Record<string, string>
|
|
14
|
-
publishConfig?: { tag?: string }
|
|
15
|
-
}
|
|
16
|
-
expect(selector.name).toBe('dsh-context-compression-improved')
|
|
17
|
-
expect(selector.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
18
|
-
expect(Object.keys(selector.dependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
19
|
-
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
20
|
-
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('@deepseek-ai/dsh-compaction-tool-result-pruner')
|
|
21
|
-
expect(selector.peerDependencies?.['@deepseek-ai/dsh-compaction-basic'])
|
|
22
|
-
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
23
|
-
expect(selector.peerDependencies?.['@deepseek-ai/dsh-command-compact'])
|
|
24
|
-
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
25
|
-
expect(selector.publishConfig?.tag).toBe('latest')
|
|
26
|
-
expect(existsSync(resolve(root, '../runtime/package.json'))).toBe(false)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('makes the repository root the one git install surface', () => {
|
|
30
|
-
const rootManifest = JSON.parse(readFileSync(resolve(root, '../package.json'), 'utf8')) as {
|
|
31
|
-
name: string
|
|
32
|
-
exports?: Record<string, unknown>
|
|
33
|
-
dependencies?: Record<string, string>
|
|
34
|
-
engines?: Record<string, string>
|
|
35
|
-
dsh?: { bundle?: { patch?: string }, client?: { inject?: string[] } }
|
|
36
|
-
}
|
|
37
|
-
expect(rootManifest.name).toBe('dsh-context-compression-improved')
|
|
38
|
-
for (const specifier of ['.', './invariant', './pruner', './client']) {
|
|
39
|
-
expect(rootManifest.exports?.[specifier]).toBeDefined()
|
|
40
|
-
}
|
|
41
|
-
expect(rootManifest.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
42
|
-
expect(rootManifest.dependencies?.['js-yaml']).toBe('^4.3.2')
|
|
43
|
-
expect(rootManifest.dsh?.bundle?.patch).toBe('./packages/selector/cordis.patch.yml')
|
|
44
|
-
expect(rootManifest.dsh?.client?.inject).toEqual([
|
|
45
|
-
'@deepseek-ai/dsh-client-locale',
|
|
46
|
-
'@deepseek-ai/dsh-client-ui-primitives',
|
|
47
|
-
'@deepseek-ai/dsh-client-ui-slots',
|
|
48
|
-
'@deepseek-ai/dsh-client-ui-settings',
|
|
49
|
-
])
|
|
50
|
-
expect(rootManifest.engines?.dsh).toBe('>=0.1.
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('uses the community package in the one Bundle patch', () => {
|
|
54
|
-
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
55
|
-
expect(patch).toContain("name: 'dsh-context-compression-improved'")
|
|
56
|
-
expect(patch).not.toContain('@deepseek-ai/dsh-client-ui-context-compression-selector')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('never ships a retired plugin config key in the Bundle patch', () => {
|
|
60
|
-
// Negative control: the patch is loaded by the host and validated against
|
|
61
|
-
// the plugin's own Config schema, but nothing tied the two together — so
|
|
62
|
-
// the retired review gate's `reviewQueueRoute` survived in this file after
|
|
63
|
-
// the key was removed from the schema, advertising a route that can never
|
|
64
|
-
// register. A retired key must fail here instead of shipping quietly.
|
|
65
|
-
//
|
|
66
|
-
// The pin is on KEY-SETTING lines, not on the whole document: the comments
|
|
67
|
-
// above the rows deliberately name the retired key while explaining why it
|
|
68
|
-
// is gone, and prose must not be mistaken for configuration.
|
|
69
|
-
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
70
|
-
const lines = patch.split('\n')
|
|
71
|
-
for (const retired of ['reviewQueueRoute', 'reviewMode', 'reviewTimeoutTurns', 'reviewHighImpactTokens']) {
|
|
72
|
-
const setsRetired = lines.find(line => new RegExp(`^\\s*${retired}\\s*:`).test(line))
|
|
73
|
-
expect(setsRetired, `${retired} is still set in the Bundle patch`).toBeUndefined()
|
|
74
|
-
}
|
|
75
|
-
// And the live flag the routes row exists for is still wired.
|
|
76
|
-
expect(patch).toContain('estimatorCatalogRoute: true')
|
|
77
|
-
})
|
|
78
|
-
})
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
const root = resolve(import.meta.dirname, '../../..')
|
|
6
|
+
|
|
7
|
+
describe('standalone package contract', () => {
|
|
8
|
+
it('ships one install-facing package with no intra-repo dependency edge', () => {
|
|
9
|
+
const selector = JSON.parse(readFileSync(resolve(root, 'selector/package.json'), 'utf8')) as {
|
|
10
|
+
name: string
|
|
11
|
+
version: string
|
|
12
|
+
dependencies?: Record<string, string>
|
|
13
|
+
peerDependencies?: Record<string, string>
|
|
14
|
+
publishConfig?: { tag?: string }
|
|
15
|
+
}
|
|
16
|
+
expect(selector.name).toBe('dsh-context-compression-improved')
|
|
17
|
+
expect(selector.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
18
|
+
expect(Object.keys(selector.dependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
19
|
+
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
20
|
+
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('@deepseek-ai/dsh-compaction-tool-result-pruner')
|
|
21
|
+
expect(selector.peerDependencies?.['@deepseek-ai/dsh-compaction-basic'])
|
|
22
|
+
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
23
|
+
expect(selector.peerDependencies?.['@deepseek-ai/dsh-command-compact'])
|
|
24
|
+
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
25
|
+
expect(selector.publishConfig?.tag).toBe('latest')
|
|
26
|
+
expect(existsSync(resolve(root, '../runtime/package.json'))).toBe(false)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('makes the repository root the one git install surface', () => {
|
|
30
|
+
const rootManifest = JSON.parse(readFileSync(resolve(root, '../package.json'), 'utf8')) as {
|
|
31
|
+
name: string
|
|
32
|
+
exports?: Record<string, unknown>
|
|
33
|
+
dependencies?: Record<string, string>
|
|
34
|
+
engines?: Record<string, string>
|
|
35
|
+
dsh?: { bundle?: { patch?: string }, client?: { inject?: string[] } }
|
|
36
|
+
}
|
|
37
|
+
expect(rootManifest.name).toBe('dsh-context-compression-improved')
|
|
38
|
+
for (const specifier of ['.', './invariant', './pruner', './client']) {
|
|
39
|
+
expect(rootManifest.exports?.[specifier]).toBeDefined()
|
|
40
|
+
}
|
|
41
|
+
expect(rootManifest.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
42
|
+
expect(rootManifest.dependencies?.['js-yaml']).toBe('^4.3.2')
|
|
43
|
+
expect(rootManifest.dsh?.bundle?.patch).toBe('./packages/selector/cordis.patch.yml')
|
|
44
|
+
expect(rootManifest.dsh?.client?.inject).toEqual([
|
|
45
|
+
'@deepseek-ai/dsh-client-locale',
|
|
46
|
+
'@deepseek-ai/dsh-client-ui-primitives',
|
|
47
|
+
'@deepseek-ai/dsh-client-ui-slots',
|
|
48
|
+
'@deepseek-ai/dsh-client-ui-settings',
|
|
49
|
+
])
|
|
50
|
+
expect(rootManifest.engines?.dsh).toBe('>=0.1.7-rc.1 <0.1.8-0')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('uses the community package in the one Bundle patch', () => {
|
|
54
|
+
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
55
|
+
expect(patch).toContain("name: 'dsh-context-compression-improved'")
|
|
56
|
+
expect(patch).not.toContain('@deepseek-ai/dsh-client-ui-context-compression-selector')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('never ships a retired plugin config key in the Bundle patch', () => {
|
|
60
|
+
// Negative control: the patch is loaded by the host and validated against
|
|
61
|
+
// the plugin's own Config schema, but nothing tied the two together — so
|
|
62
|
+
// the retired review gate's `reviewQueueRoute` survived in this file after
|
|
63
|
+
// the key was removed from the schema, advertising a route that can never
|
|
64
|
+
// register. A retired key must fail here instead of shipping quietly.
|
|
65
|
+
//
|
|
66
|
+
// The pin is on KEY-SETTING lines, not on the whole document: the comments
|
|
67
|
+
// above the rows deliberately name the retired key while explaining why it
|
|
68
|
+
// is gone, and prose must not be mistaken for configuration.
|
|
69
|
+
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
70
|
+
const lines = patch.split('\n')
|
|
71
|
+
for (const retired of ['reviewQueueRoute', 'reviewMode', 'reviewTimeoutTurns', 'reviewHighImpactTokens']) {
|
|
72
|
+
const setsRetired = lines.find(line => new RegExp(`^\\s*${retired}\\s*:`).test(line))
|
|
73
|
+
expect(setsRetired, `${retired} is still set in the Bundle patch`).toBeUndefined()
|
|
74
|
+
}
|
|
75
|
+
// And the live flag the routes row exists for is still wired.
|
|
76
|
+
expect(patch).toContain('estimatorCatalogRoute: true')
|
|
77
|
+
})
|
|
78
|
+
})
|
|
@@ -31,7 +31,7 @@ import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
|
|
|
31
31
|
import TokenMeter from '@deepseek-ai/dsh-token-meter'
|
|
32
32
|
import ToolRuntime from '@deepseek-ai/dsh-tools'
|
|
33
33
|
import * as SelectorHost from '../../src/index.ts'
|
|
34
|
-
import { LegacyNamespaceRegistrar } from '../helpers/legacy-namespace.ts'
|
|
34
|
+
import { LegacyNamespaceRegistrar } from '../helpers/legacy-namespace.ts'
|
|
35
35
|
import ToolResultPruner, {
|
|
36
36
|
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
|
|
37
37
|
} from '../../src/pruner.ts'
|
|
@@ -136,7 +136,7 @@ function appendToolTurn(session: Session, turn: number, text: string): void {
|
|
|
136
136
|
*/
|
|
137
137
|
async function gatedSettings(ctx: Context): Promise<void> {
|
|
138
138
|
await ctx.plugin(TestSettings).await()
|
|
139
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
139
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
140
140
|
await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
|
|
141
141
|
profile: 'tokenpilot-inspired',
|
|
142
142
|
presetOptions: { reviewMode: true, reviewHighImpactTokens: 1 },
|
|
@@ -208,7 +208,7 @@ describe('advice never withholds (retired review gate)', () => {
|
|
|
208
208
|
it('keeps the automatic path identical when no legacy gate key is present', async () => {
|
|
209
209
|
const ctx = await runtimeContext()
|
|
210
210
|
await ctx.plugin(TestSettings).await()
|
|
211
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
211
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
212
212
|
await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
|
|
213
213
|
profile: 'tokenpilot-inspired',
|
|
214
214
|
})
|