dsh-context-compression-improved 0.5.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/README.md +10 -1
  2. package/package.json +162 -160
  3. package/packages/selector/README.md +6 -1
  4. package/packages/selector/README.zh.md +6 -1
  5. package/packages/selector/lib/advisor-state.js +1 -1
  6. package/packages/selector/lib/client.d.ts +19 -104
  7. package/packages/selector/lib/client.js +42 -5
  8. package/packages/selector/lib/index.d.ts +9 -0
  9. package/packages/selector/lib/index.js +18 -50
  10. package/packages/selector/lib/profiles.d.ts +105 -0
  11. package/packages/selector/lib/pruner.js +3 -2
  12. package/packages/selector/package.json +114 -114
  13. package/packages/selector/src/client/index.ts +71 -8
  14. package/packages/selector/src/index.ts +35 -86
  15. package/packages/selector/src/pruner.ts +12 -3
  16. package/packages/selector/src/runtime/config.ts +1 -1
  17. package/packages/selector/tests/code-skeleton.client.spec.ts +93 -90
  18. package/packages/selector/tests/custom-contract.client.spec.ts +19 -1
  19. package/packages/selector/tests/helpers/legacy-namespace.ts +31 -0
  20. package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
  21. package/packages/selector/tests/preset-options-write.client.spec.ts +63 -82
  22. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +206 -201
  23. package/packages/selector/tests/public/package-contract.client.spec.ts +2 -2
  24. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -2
  25. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -17
  26. package/packages/selector/tests/settings-seat.client.spec.ts +2 -2
  27. package/packages/selector/tests/standing-generation.host.spec.ts +704 -697
@@ -1,201 +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 Loader from '@deepseek-ai/cordis-plugin-loader'
9
- import AgentRegistry, { type Agent } from '@deepseek-ai/dsh-agent'
10
- import AgentLoop from '@deepseek-ai/dsh-agent-loop'
11
- import AgentPresets, { COMPOSITION_FILE } from '@deepseek-ai/dsh-agent-presets'
12
- import CommandRuntime from '@deepseek-ai/dsh-commands'
13
- import LlmRuntime from '@deepseek-ai/dsh-llm'
14
- import SessionStore, { SessionId } from '@deepseek-ai/dsh-session'
15
- import { scopeOf } from '@deepseek-ai/dsh-scope'
16
- import {
17
- SettingsProvider,
18
- type SettingsNamespace,
19
- } from '@deepseek-ai/dsh-settings'
20
- import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
21
- import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
22
- import TokenMeter from '@deepseek-ai/dsh-token-meter'
23
- import ToolRuntime from '@deepseek-ai/dsh-tools'
24
- import { afterEach, describe, expect, it } from 'vitest'
25
- import { apply } from '../src/index.ts'
26
-
27
- // 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
28
- const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
29
-
30
- const CORDIS_ORIGINAL = Symbol.for('cordis.original')
31
- type Traceable = { [CORDIS_ORIGINAL]?: unknown }
32
-
33
- let ctx: Context | undefined
34
- let root: string | undefined
35
-
36
- afterEach(async () => {
37
- await ctx?.fiber.dispose()
38
- ctx = undefined
39
- if (root !== undefined) await rm(root, { recursive: true, force: true })
40
- root = undefined
41
- })
42
-
43
- class MemorySettings extends SettingsProvider {
44
- readonly writable = true
45
-
46
- protected load(): Promise<Record<string, unknown>> {
47
- return Promise.resolve({})
48
- }
49
-
50
- protected persist(_ns: SettingsNamespace, _section: Record<string, unknown>): Promise<void> {
51
- return Promise.resolve()
52
- }
53
- }
54
-
55
- interface CustomSettings {
56
- profile: string
57
- custom: {
58
- history: { trigger: number }
59
- tailTrim: { enabled: boolean; trigger: number }
60
- }
61
- }
62
-
63
- async function createPresetRoot(): Promise<string> {
64
- root = await mkdtemp(join(tmpdir(), 'dsh-selector-loader-e2e-'))
65
- const marker = join(root, 'marker.mjs')
66
- await writeFile(marker, 'export function apply() {}\n')
67
- const source = `- id: source-marker\n name: ${JSON.stringify(marker)}\n`
68
- for (const id of ['standard', 'custom', 'minimal']) {
69
- const directory = join(root, id)
70
- await mkdir(directory)
71
- await writeFile(join(directory, COMPOSITION_FILE), source)
72
- }
73
- return root
74
- }
75
-
76
- async function harness(): Promise<Context> {
77
- const presets = await createPresetRoot()
78
- const runtime = new Context()
79
- runtime.baseUrl = `${pathToFileURL(presets).href}/`
80
- await runtime.plugin(Loader).await()
81
- runtime.loader.builtins.include = Include
82
- runtime.loader.builtins.group = Group
83
- await runtime.plugin(LlmRuntime).await()
84
- await runtime.plugin(SessionStore).await()
85
- await runtime.plugin(SystemPrompt).await()
86
- await runtime.plugin(ToolRuntime).await()
87
- await runtime.plugin(AgentRegistry).await()
88
- await runtime.plugin(AgentLoop).await()
89
- await runtime.plugin(CommandRuntime).await()
90
- await runtime.plugin(SessionProjectionRegistry).await()
91
- await runtime.plugin(TokenMeter).await()
92
- await runtime.plugin(MemorySettings).await()
93
- await runtime.plugin(AgentPresets, {
94
- default: 'standard',
95
- roots: [{ path: presets, trust: 'system' }],
96
- includeShippedRoot: false,
97
- includeUserRoot: false,
98
- })
99
- await runtime.plugin({
100
- apply: (selectorCtx) => {
101
- apply(selectorCtx, { presetOverlay: true })
102
- },
103
- }).await()
104
- ctx = runtime
105
- return runtime
106
- }
107
-
108
- async function agentOn(runtime: Context, sessionId: string, preset: string): Promise<Agent> {
109
- const handle = await runtime.agents.create({
110
- sessionId: SessionId(sessionId),
111
- setup: async agentCtx => void await runtime.agentPresets.mount(agentCtx, preset),
112
- })
113
- return handle.agent
114
- }
115
-
116
- function hasCompressionRetrieve(runtime: Context, agent: Agent): boolean {
117
- return runtime.tools.get('context_compression_retrieve', scopeOf(agent.ctx)) !== undefined
118
- }
119
-
120
- function hasCompactCommand(runtime: Context, agent: Agent): boolean {
121
- return runtime.commands.list(agent).some(command => command.name === 'compact')
122
- }
123
-
124
- function expectCompleteCompressionStack(runtime: Context, agent: Agent): void {
125
- expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeDefined()
126
- expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeDefined()
127
- expect(hasCompressionRetrieve(runtime, agent)).toBe(true)
128
- expect(hasCompactCommand(runtime, agent)).toBe(true)
129
- }
130
-
131
- function expectNoCompressionStack(runtime: Context, agent: Agent): void {
132
- expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeUndefined()
133
- expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeUndefined()
134
- expect(hasCompressionRetrieve(runtime, agent)).toBe(false)
135
- expect(hasCompactCommand(runtime, agent)).toBe(false)
136
- }
137
-
138
- describe('standalone selector Bundle through the real preset Loader', () => {
139
- it('mounts the complete stack without changing source preset authoring', async () => {
140
- const runtime = await harness()
141
- const source = await runtime.agentPresets.resolve('standard')
142
- const sourceText = await runtime.agentPresets.read('standard')
143
-
144
- const agent = await agentOn(runtime, 'selector-loader-standard', 'standard')
145
-
146
- expectCompleteCompressionStack(runtime, agent)
147
- expect((await runtime.agentPresets.resolve('standard')).path).toBe(source.path)
148
- expect(await runtime.agentPresets.read('standard')).toBe(sourceText)
149
- expect(sourceText).not.toContain('tool-result-pruner')
150
- })
151
-
152
- it('keeps compression across preset changes and excludes only exact Minimal', async () => {
153
- const runtime = await harness()
154
- const agent = await agentOn(runtime, 'selector-loader-switch', 'standard')
155
- expectCompleteCompressionStack(runtime, agent)
156
-
157
- await runtime.agentPresets.recompose(agent.ctx, 'minimal')
158
- expectNoCompressionStack(runtime, agent)
159
-
160
- // `custom` deliberately contains the same source rows as Minimal. Its id,
161
- // not its copied contents, decides the one documented exception.
162
- await runtime.agentPresets.recompose(agent.ctx, 'custom')
163
- expectCompleteCompressionStack(runtime, agent)
164
- })
165
-
166
- it('gives a child the parent\'s exact compression service instances', async () => {
167
- const runtime = await harness()
168
- const parent = await agentOn(runtime, 'selector-loader-parent', 'standard')
169
- const childHandle = await runtime.agents.create({
170
- sessionId: SessionId('selector-loader-child'),
171
- setup: childCtx => void runtime.agentPresets.composeFrom(childCtx, parent.ctx),
172
- })
173
- const child = childHandle.agent
174
-
175
- const parentPruner = runtime.agentPresets.serviceFor(parent, 'toolResultPruner')
176
- const childPruner = runtime.agentPresets.serviceFor(child, 'toolResultPruner')
177
- const parentCompaction = runtime.agentPresets.serviceFor(parent, 'compaction')
178
- const childCompaction = runtime.agentPresets.serviceFor(child, 'compaction')
179
- expect(parentPruner).toBeDefined()
180
- expect(parentCompaction).toBeDefined()
181
- expect(Object.is(
182
- (childPruner as Traceable)[CORDIS_ORIGINAL],
183
- (parentPruner as Traceable)[CORDIS_ORIGINAL],
184
- )).toBe(true)
185
- expect(Object.is(
186
- (childCompaction as Traceable)[CORDIS_ORIGINAL],
187
- (parentCompaction as Traceable)[CORDIS_ORIGINAL],
188
- )).toBe(true)
189
- expect(hasCompressionRetrieve(runtime, child)).toBe(true)
190
- expect(hasCompactCommand(runtime, child)).toBe(true)
191
- })
192
-
193
- it('publishes the daily Custom defaults from the plugin-owned settings row', async () => {
194
- const runtime = await harness()
195
- const namespace = nsBrand('context-compression')
196
- const settings = runtime.settings.get(namespace) as CustomSettings
197
-
198
- expect(settings.custom.history.trigger).toBe(500_000)
199
- expect(settings.custom.tailTrim).toEqual({ enabled: false, trigger: 700_000 })
200
- })
201
- })
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
+ })
@@ -19,9 +19,9 @@ describe('standalone package contract', () => {
19
19
  expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
20
20
  expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('@deepseek-ai/dsh-compaction-tool-result-pruner')
21
21
  expect(selector.peerDependencies?.['@deepseek-ai/dsh-compaction-basic'])
22
- .toBe('>=0.1.5-rc.2 <0.2.0-0')
22
+ .toBe('>=0.1.7-rc.1 <0.2.0-0')
23
23
  expect(selector.peerDependencies?.['@deepseek-ai/dsh-command-compact'])
24
- .toBe('>=0.1.5-rc.2 <0.2.0-0')
24
+ .toBe('>=0.1.7-rc.1 <0.2.0-0')
25
25
  expect(selector.publishConfig?.tag).toBe('latest')
26
26
  expect(existsSync(resolve(root, '../runtime/package.json'))).toBe(false)
27
27
  })
@@ -31,6 +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
35
  import ToolResultPruner, {
35
36
  CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
36
37
  } from '../../src/pruner.ts'
@@ -135,7 +136,7 @@ function appendToolTurn(session: Session, turn: number, text: string): void {
135
136
  */
136
137
  async function gatedSettings(ctx: Context): Promise<void> {
137
138
  await ctx.plugin(TestSettings).await()
138
- await ctx.plugin(SelectorHost).await()
139
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
139
140
  await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
140
141
  profile: 'tokenpilot-inspired',
141
142
  presetOptions: { reviewMode: true, reviewHighImpactTokens: 1 },
@@ -207,7 +208,7 @@ describe('advice never withholds (retired review gate)', () => {
207
208
  it('keeps the automatic path identical when no legacy gate key is present', async () => {
208
209
  const ctx = await runtimeContext()
209
210
  await ctx.plugin(TestSettings).await()
210
- await ctx.plugin(SelectorHost).await()
211
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
211
212
  await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
212
213
  profile: 'tokenpilot-inspired',
213
214
  })
@@ -36,6 +36,7 @@ import ToolRuntime from '@deepseek-ai/dsh-tools'
36
36
  import { CompactionId } from '@deepseek-ai/dsh-compaction'
37
37
  import InvariantRegistry from '@deepseek-ai/dsh-invariants'
38
38
  import * as SelectorHost from '../../../src/index.ts'
39
+ import { LegacyNamespaceRegistrar } from '../../helpers/legacy-namespace.ts'
39
40
  import * as RuntimeInvariant from '../../../src/invariant.ts'
40
41
  import { sessionEvents } from '../../../src/runtime/session-events.ts'
41
42
  import ToolResultPruner, {
@@ -424,7 +425,7 @@ describe('standalone runtime on published Harness APIs', () => {
424
425
  // replacement → audit record) without ever touching the replacement text.
425
426
  const ctx = await runtimeContext()
426
427
  await ctx.plugin(TestSettings).await()
427
- await ctx.plugin(SelectorHost).await()
428
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
428
429
  await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
429
430
  profile: 'balanced',
430
431
  codeSkeleton: { enabled: true },
@@ -589,7 +590,7 @@ describe('standalone runtime on published Harness APIs', () => {
589
590
  it('moves the capacity-pressure gate with the frozen Auto Compact threshold', async () => {
590
591
  const ctx = await runtimeContext()
591
592
  await ctx.plugin(TestSettings).await()
592
- await ctx.plugin(SelectorHost).await()
593
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
593
594
  const audit = captureAudit(ctx)
594
595
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
595
596
 
@@ -625,7 +626,7 @@ describe('standalone runtime on published Harness APIs', () => {
625
626
  it('ages History earlier when the frozen Auto Compact threshold is low', async () => {
626
627
  const ctx = await runtimeContext()
627
628
  await ctx.plugin(TestSettings).await()
628
- await ctx.plugin(SelectorHost).await()
629
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
629
630
  const audit = captureAudit(ctx)
630
631
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
631
632
 
@@ -659,7 +660,7 @@ describe('standalone runtime on published Harness APIs', () => {
659
660
  it('freezes the generation-owned threshold over later global settings changes', async () => {
660
661
  const ctx = await runtimeContext()
661
662
  await ctx.plugin(TestSettings).await()
662
- await ctx.plugin(SelectorHost).await()
663
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
663
664
  const audit = captureAudit(ctx)
664
665
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
665
666
  // The preset overlay captured 70% into this generation's deployment
@@ -695,7 +696,7 @@ describe('standalone runtime on published Harness APIs', () => {
695
696
  it('fails open to a lossless frozen policy when stored settings are malformed', async () => {
696
697
  const ctx = await runtimeContext()
697
698
  await ctx.plugin(TestSettings).await()
698
- await ctx.plugin(SelectorHost).await()
699
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
699
700
  const audit = captureAudit(ctx)
700
701
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
701
702
  // A hand-edited store can surface a document the schema rejects (unknown
@@ -745,7 +746,7 @@ describe('standalone runtime on published Harness APIs', () => {
745
746
  ])('fails open to a lossless frozen policy when the stored document carries %s', async (label, malformed) => {
746
747
  const ctx = await runtimeContext()
747
748
  await ctx.plugin(TestSettings).await()
748
- await ctx.plugin(SelectorHost).await()
749
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
749
750
  const audit = captureAudit(ctx)
750
751
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
751
752
  // Schemastery `.default(...)` would silently replace these present-but-null
@@ -782,7 +783,7 @@ describe('standalone runtime on published Harness APIs', () => {
782
783
 
783
784
  const ctx = await runtimeContext()
784
785
  await ctx.plugin(TestSettings).await()
785
- await ctx.plugin(SelectorHost).await()
786
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
786
787
  const audit = captureAudit(ctx)
787
788
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
788
789
  const malformed = {
@@ -882,7 +883,7 @@ describe('standalone runtime on published Harness APIs', () => {
882
883
  it('audits the Auto Compact coordination block on policy resolution', async () => {
883
884
  const ctx = await runtimeContext()
884
885
  await ctx.plugin(TestSettings).await()
885
- await ctx.plugin(SelectorHost).await()
886
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
886
887
  const audit = captureAudit(ctx)
887
888
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
888
889
  await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
@@ -919,6 +920,7 @@ describe('standalone runtime on published Harness APIs', () => {
919
920
  const overrideCtx = await runtimeContext()
920
921
  await overrideCtx.plugin(TestSettings).await()
921
922
  await overrideCtx.plugin(SelectorHost).await()
923
+ await overrideCtx.plugin(LegacyNamespaceRegistrar).await()
922
924
  const overrideAudit = captureAudit(overrideCtx)
923
925
  await overrideCtx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
924
926
  await overrideCtx.plugin(ToolResultPruner, {
@@ -944,6 +946,7 @@ describe('standalone runtime on published Harness APIs', () => {
944
946
  const mixedCtx = await runtimeContext()
945
947
  await mixedCtx.plugin(TestSettings).await()
946
948
  await mixedCtx.plugin(SelectorHost).await()
949
+ await mixedCtx.plugin(LegacyNamespaceRegistrar).await()
947
950
  const mixedAudit = captureAudit(mixedCtx)
948
951
  await mixedCtx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
949
952
  await mixedCtx.plugin(ToolResultPruner, {
@@ -979,7 +982,7 @@ describe('standalone runtime on published Harness APIs', () => {
979
982
  it('freezes the Auto Compact threshold per Session and applies new values only to new Sessions', async () => {
980
983
  const ctx = await runtimeContext()
981
984
  await ctx.plugin(TestSettings).await()
982
- await ctx.plugin(SelectorHost).await()
985
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
983
986
  const audit = captureAudit(ctx)
984
987
  const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
985
988
  await ctx.plugin(ToolResultPruner, { profile: 'balanced' }).await()
@@ -1503,7 +1506,7 @@ describe('standalone runtime on published Harness APIs', () => {
1503
1506
  it('still commits unlinked Custom History batches at the minimum reclaim', async () => {
1504
1507
  const ctx = await runtimeContext()
1505
1508
  await ctx.plugin(TestSettings).await()
1506
- await ctx.plugin(SelectorHost).await()
1509
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
1507
1510
  const audit = captureAudit(ctx)
1508
1511
  // A protected token tail larger than the trigger leaves the linked-style
1509
1512
  // whole-excess demand unreachable; Custom stays manual and must still
@@ -1689,7 +1692,7 @@ describe('standalone runtime on published Harness APIs', () => {
1689
1692
  const ctx = new Context()
1690
1693
  activeContexts.push(ctx)
1691
1694
  await ctx.plugin(TestSettings).await()
1692
- await ctx.plugin(SelectorHost).await()
1695
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
1693
1696
  await ctx.plugin(SessionStore).await()
1694
1697
  await ctx.plugin(SystemPrompt).await()
1695
1698
  await ctx.plugin(ToolRuntime).await()
@@ -1751,7 +1754,7 @@ describe('standalone runtime on published Harness APIs', () => {
1751
1754
  const ctx = new Context()
1752
1755
  activeContexts.push(ctx)
1753
1756
  await ctx.plugin(TestSettings).await()
1754
- await ctx.plugin(SelectorHost).await()
1757
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
1755
1758
  await ctx.plugin(SessionStore).await()
1756
1759
  await ctx.plugin(SystemPrompt).await()
1757
1760
  await ctx.plugin(ToolRuntime).await()
@@ -1848,7 +1851,7 @@ describe('standalone runtime on published Harness APIs', () => {
1848
1851
  const ctx = new Context()
1849
1852
  activeContexts.push(ctx)
1850
1853
  await ctx.plugin(TestSettings).await()
1851
- await ctx.plugin(SelectorHost).await()
1854
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
1852
1855
  await ctx.plugin(SessionStore).await()
1853
1856
  await ctx.plugin(SystemPrompt).await()
1854
1857
  await ctx.plugin(ToolRuntime).await()
@@ -1941,7 +1944,7 @@ describe('standalone runtime on published Harness APIs', () => {
1941
1944
  const ctx = new Context()
1942
1945
  activeContexts.push(ctx)
1943
1946
  await ctx.plugin(TestSettings).await()
1944
- await ctx.plugin(SelectorHost).await()
1947
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
1945
1948
  await ctx.plugin(SessionStore).await()
1946
1949
  await ctx.plugin(InvariantRegistry).await()
1947
1950
  await ctx.plugin(RuntimeInvariant).await()
@@ -2121,7 +2124,7 @@ describe('standalone runtime on published Harness APIs', () => {
2121
2124
  const ctx = new Context()
2122
2125
  activeContexts.push(ctx)
2123
2126
  await ctx.plugin(TestSettings).await()
2124
- await ctx.plugin(SelectorHost).await()
2127
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
2125
2128
  await ctx.plugin(LlmRuntime).await()
2126
2129
  await ctx.plugin(SessionStore).await()
2127
2130
  await ctx.plugin(SystemPrompt).await()
@@ -2568,7 +2571,7 @@ describe('standalone runtime on published Harness APIs', () => {
2568
2571
  it('never TailTrims a tool group whose results carry images', async () => {
2569
2572
  const ctx = await runtimeContext()
2570
2573
  await ctx.plugin(TestSettings).await()
2571
- await ctx.plugin(SelectorHost).await()
2574
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
2572
2575
  const audit = captureAudit(ctx)
2573
2576
  await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
2574
2577
  profile: 'custom',
@@ -2660,7 +2663,7 @@ describe('character basis / model-id independence', () => {
2660
2663
  async function characterBasisContext(): Promise<Context> {
2661
2664
  const ctx = await runtimeContext()
2662
2665
  await ctx.plugin(TestSettings).await()
2663
- await ctx.plugin(SelectorHost).await()
2666
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
2664
2667
  await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
2665
2668
  profile: 'balanced',
2666
2669
  codeSkeleton: { enabled: true },