dsh-context-compression-improved 0.7.0-beta.1 → 0.8.0-beta.1

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 (65) hide show
  1. package/CHANGELOG.ja.md +226 -220
  2. package/CHANGELOG.ko.md +220 -214
  3. package/CHANGELOG.md +366 -376
  4. package/CHANGELOG.zh.md +204 -199
  5. package/README.ja.md +85 -85
  6. package/README.ko.md +85 -85
  7. package/README.md +98 -97
  8. package/README.zh.md +85 -86
  9. package/eslint.config.js +30 -76
  10. package/package.json +53 -55
  11. package/packages/selector/dsh.plugin.json +2 -2
  12. package/packages/selector/lib/{intent-gate.js → advisor-state.js} +3 -91
  13. package/packages/selector/lib/client.js +3 -14
  14. package/packages/selector/lib/index.js +1 -92
  15. package/packages/selector/lib/profiles.d.ts +0 -9
  16. package/packages/selector/lib/pruner.d.ts +0 -59
  17. package/packages/selector/lib/pruner.js +7 -410
  18. package/packages/selector/lib/style.css +46 -46
  19. package/packages/selector/package.json +114 -114
  20. package/packages/selector/src/client/decode.ts +2 -6
  21. package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
  22. package/packages/selector/src/index.ts +411 -418
  23. package/packages/selector/src/preset-overlay.ts +0 -3
  24. package/packages/selector/src/profiles.ts +10 -30
  25. package/packages/selector/src/pruner/content.ts +1 -1
  26. package/packages/selector/src/pruner/state.ts +0 -7
  27. package/packages/selector/src/pruner.ts +9 -253
  28. package/packages/selector/src/runtime/audit.ts +0 -17
  29. package/packages/selector/src/runtime/config.ts +11 -36
  30. package/packages/selector/src/runtime/reducers.ts +1 -1
  31. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +1 -46
  32. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -55
  33. package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
  34. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +1 -4
  35. package/packages/selector/src/runtime/types.ts +0 -12
  36. package/packages/selector/tests/auto-compact.client.spec.tsx +213 -214
  37. package/packages/selector/tests/built/client-artifact.spec.ts +59 -61
  38. package/packages/selector/tests/code-skeleton.client.spec.ts +93 -94
  39. package/packages/selector/tests/custom-contract.client.spec.ts +222 -223
  40. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  41. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
  42. package/packages/selector/tests/preset-options-write.client.spec.ts +187 -188
  43. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
  44. package/packages/selector/tests/profiles.client.spec.tsx +434 -436
  45. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  46. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
  47. package/packages/selector/tests/runtime/audit.spec.ts +274 -275
  48. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
  49. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
  50. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2736
  51. package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
  52. package/pnpm-workspace.yaml +66 -66
  53. package/scripts/packed-components-smoke.mjs +0 -2
  54. package/scripts/packed-install-e2e.mjs +5 -7
  55. package/scripts/verify-release.mjs +2 -3
  56. package/tsconfig.tests.json +1 -3
  57. package/vitest.config.ts +0 -14
  58. package/packages/selector/src/runtime/summary-command.ts +0 -133
  59. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  60. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  61. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  62. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  63. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  64. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  65. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
@@ -1,204 +1,204 @@
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 { type SettingsNamespace } from '@deepseek-ai/dsh-settings'
7
- import { LegacySettingsProvider } from './helpers/legacy-settings/index.ts'
8
- import { afterEach, describe, expect, it } from 'vitest'
9
- import { apply } from '../src/index.ts'
10
- import type { OverlayableAgentPresets } from '../src/preset-overlay.ts'
11
- import { LegacyNamespaceRegistrar } from './helpers/legacy-namespace.ts'
12
-
13
- // 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
14
- const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
15
-
16
- let root: string | undefined
17
- let ctx: Context | undefined
18
-
19
- afterEach(async () => {
20
- await ctx?.fiber.dispose()
21
- ctx = undefined
22
- if (root !== undefined) await rm(root, { recursive: true, force: true })
23
- root = undefined
24
- })
25
-
26
- class MemorySettings extends LegacySettingsProvider {
27
- readonly writable = true
28
- private readonly stored: Record<string, unknown> = {}
29
-
30
- protected load(): Promise<Record<string, unknown>> {
31
- return Promise.resolve(structuredClone(this.stored))
32
- }
33
-
34
- protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
35
- this.stored[ns] = structuredClone(section)
36
- return Promise.resolve()
37
- }
38
- }
39
-
40
- class FakeAgentPresets extends Service implements OverlayableAgentPresets {
41
- constructor(ctx: Context, readonly preset: AgentPreset) {
42
- super(ctx, 'agentPresets')
43
- }
44
-
45
- async resolve(): Promise<AgentPreset> {
46
- return this.preset
47
- }
48
-
49
- async mount(_agentCtx: unknown): Promise<AgentPreset> {
50
- return await this.resolve()
51
- }
52
-
53
- async recompose(_agentCtx: unknown, _id: string): Promise<AgentPreset> {
54
- return await this.resolve()
55
- }
56
-
57
- async standingKeyFor(): Promise<string> {
58
- return (await this.resolve()).path
59
- }
60
- }
61
-
62
- async function sourcePreset(): Promise<AgentPreset> {
63
- root = await mkdtemp(join(tmpdir(), 'dsh-selector-host-overlay-'))
64
- const path = join(root, 'standard', 'agent.cordis.yml')
65
- await mkdir(dirname(path), { recursive: true })
66
- await writeFile(path, "- id: persona\n name: '/opt/preset/persona.js'\n")
67
- return { id: 'standard', trust: 'system', path }
68
- }
69
-
70
- describe('context compression selector Host preset integration', () => {
71
- it('decorates native composition only for the lifetime of the selector fiber', async () => {
72
- const preset = await sourcePreset()
73
- ctx = new Context()
74
- await ctx.plugin(MemorySettings).await()
75
- await ctx.plugin(LegacyNamespaceRegistrar).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('0.1.7: duplicate Host rows own independent entry configs — one row\u2019s disposal never disturbs the other', 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 service = ctx.agentPresets as unknown as OverlayableAgentPresets
103
- expect((await service.mount({})).path).toBe(preset.path)
104
-
105
- // 0.1.7: there is no shared settings registration to lease — each row
106
- // carries its own compression doc on its entry config, so duplicate rows
107
- // cannot disturb each other and disposal is purely per row.
108
- const bundle = ctx.plugin({ apply: (child) => {
109
- apply(child, { presetOverlay: true, settings: { profile: 'cache-strict' } } as never)
110
- } })
111
- await bundle.await()
112
-
113
- const mounted = await service.mount({})
114
- expect(mounted.path).not.toBe(preset.path)
115
- expect((await service.recompose({}, 'standard')).path).toBe(mounted.path)
116
-
117
- // Disposing the non-overlay row never touches the overlay row's decoration
118
- // or its entry config.
119
- await builtIn.dispose()
120
- expect((await service.mount({})).path).toBe(mounted.path)
121
-
122
- await bundle.dispose()
123
- expect((await service.mount({})).path).toBe(preset.path)
124
- })
125
-
126
- it('writes the saved Auto Compact threshold into the generated compaction-basic composition', async () => {
127
- const preset = await sourcePreset()
128
- ctx = new Context()
129
- await ctx.plugin(MemorySettings).await()
130
- await ctx.plugin(LegacyNamespaceRegistrar).await()
131
- await ctx.plugin(FakeAgentPresets, preset).await()
132
- // A settings-owning row must register the namespace before the update.
133
- await ctx.plugin({ apply }).await()
134
- const namespace = nsBrand('context-compression')
135
- await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
136
-
137
- const bundle = ctx.plugin({ apply: (child) => {
138
- apply(child, { presetOverlay: true })
139
- } })
140
- await bundle.await()
141
-
142
- const service = ctx.agentPresets as unknown as OverlayableAgentPresets
143
- const mounted = await service.mount({})
144
- const rendered = await readFile(mounted.path, 'utf8')
145
- expect(rendered).toContain('id: compaction-basic')
146
- expect(rendered).toContain('thresholdRatio: 0.73')
147
- // First-release retention stays pinned at 0.16 next to the threshold.
148
- expect(rendered).toContain('retainRatio: 0.16')
149
- // The SAME read feeds the runtime deployment config, so one generation
150
- // cannot split Auto Compact and micro compact across two thresholds.
151
- expect(rendered).toContain('id: tool-result-pruner')
152
- expect(rendered).toContain('autoCompactThresholdPercent: 73')
153
- await bundle.dispose()
154
- })
155
-
156
- it('defaults the generated threshold to 0.8 and keeps it absent from settings until saved', async () => {
157
- const preset = await sourcePreset()
158
- ctx = new Context()
159
- await ctx.plugin(MemorySettings).await()
160
- await ctx.plugin(LegacyNamespaceRegistrar).await()
161
- await ctx.plugin(FakeAgentPresets, preset).await()
162
-
163
- const bundle = ctx.plugin({ apply: (child) => {
164
- apply(child, { presetOverlay: true })
165
- } })
166
- await bundle.await()
167
-
168
- const service = ctx.agentPresets as unknown as OverlayableAgentPresets
169
- const rendered = await readFile((await service.mount({})).path, 'utf8')
170
- expect(rendered).toContain('thresholdRatio: 0.8')
171
- await bundle.dispose()
172
- })
173
-
174
- it('moves the standing composition generation when an equal-length threshold changes', async () => {
175
- const preset = await sourcePreset()
176
- ctx = new Context()
177
- await ctx.plugin(MemorySettings).await()
178
- await ctx.plugin(LegacyNamespaceRegistrar).await()
179
- await ctx.plugin(FakeAgentPresets, preset).await()
180
- // A settings-owning row must register the namespace before the update.
181
- await ctx.plugin({ apply }).await()
182
- const namespace = nsBrand('context-compression')
183
- await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 70 } })
184
-
185
- const bundle = ctx.plugin({ apply: (child) => {
186
- apply(child, { presetOverlay: true })
187
- } })
188
- await bundle.await()
189
-
190
- const service = ctx.agentPresets as unknown as OverlayableAgentPresets
191
- const first = await service.mount({})
192
- expect(await readFile(first.path, 'utf8')).toContain('thresholdRatio: 0.7')
193
- expect(await service.standingKeyFor()).toBe(first.path)
194
-
195
- // Same character length, different content: the generated identity and
196
- // standing composition generation must both move to the new threshold.
197
- await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 80 } })
198
- const second = await service.mount({})
199
- expect(second.path).not.toBe(first.path)
200
- expect(await readFile(second.path, 'utf8')).toContain('thresholdRatio: 0.8')
201
- expect(await service.standingKeyFor()).toBe(second.path)
202
- await bundle.dispose()
203
- })
204
- })
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 { type SettingsNamespace } from '@deepseek-ai/dsh-settings'
7
+ import { LegacySettingsProvider } from './helpers/legacy-settings/index.ts'
8
+ import { afterEach, describe, expect, it } from 'vitest'
9
+ import { apply } from '../src/index.ts'
10
+ import type { OverlayableAgentPresets } from '../src/preset-overlay.ts'
11
+ import { LegacyNamespaceRegistrar } from './helpers/legacy-namespace.ts'
12
+
13
+ // 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
14
+ const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
15
+
16
+ let root: string | undefined
17
+ let ctx: Context | undefined
18
+
19
+ afterEach(async () => {
20
+ await ctx?.fiber.dispose()
21
+ ctx = undefined
22
+ if (root !== undefined) await rm(root, { recursive: true, force: true })
23
+ root = undefined
24
+ })
25
+
26
+ class MemorySettings extends LegacySettingsProvider {
27
+ readonly writable = true
28
+ private readonly stored: Record<string, unknown> = {}
29
+
30
+ protected load(): Promise<Record<string, unknown>> {
31
+ return Promise.resolve(structuredClone(this.stored))
32
+ }
33
+
34
+ protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
35
+ this.stored[ns] = structuredClone(section)
36
+ return Promise.resolve()
37
+ }
38
+ }
39
+
40
+ class FakeAgentPresets extends Service implements OverlayableAgentPresets {
41
+ constructor(ctx: Context, readonly preset: AgentPreset) {
42
+ super(ctx, 'agentPresets')
43
+ }
44
+
45
+ async resolve(): Promise<AgentPreset> {
46
+ return this.preset
47
+ }
48
+
49
+ async mount(_agentCtx: unknown): Promise<AgentPreset> {
50
+ return await this.resolve()
51
+ }
52
+
53
+ async recompose(_agentCtx: unknown, _id: string): Promise<AgentPreset> {
54
+ return await this.resolve()
55
+ }
56
+
57
+ async standingKeyFor(): Promise<string> {
58
+ return (await this.resolve()).path
59
+ }
60
+ }
61
+
62
+ async function sourcePreset(): Promise<AgentPreset> {
63
+ root = await mkdtemp(join(tmpdir(), 'dsh-selector-host-overlay-'))
64
+ const path = join(root, 'standard', 'agent.cordis.yml')
65
+ await mkdir(dirname(path), { recursive: true })
66
+ await writeFile(path, "- id: persona\n name: '/opt/preset/persona.js'\n")
67
+ return { id: 'standard', trust: 'system', path }
68
+ }
69
+
70
+ describe('context compression selector Host preset integration', () => {
71
+ it('decorates native composition only for the lifetime of the selector fiber', async () => {
72
+ const preset = await sourcePreset()
73
+ ctx = new Context()
74
+ await ctx.plugin(MemorySettings).await()
75
+ await ctx.plugin(LegacyNamespaceRegistrar).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('0.1.7: duplicate Host rows own independent entry configs — one row\u2019s disposal never disturbs the other', 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 service = ctx.agentPresets as unknown as OverlayableAgentPresets
103
+ expect((await service.mount({})).path).toBe(preset.path)
104
+
105
+ // 0.1.7: there is no shared settings registration to lease — each row
106
+ // carries its own compression doc on its entry config, so duplicate rows
107
+ // cannot disturb each other and disposal is purely per row.
108
+ const bundle = ctx.plugin({ apply: (child) => {
109
+ apply(child, { presetOverlay: true, settings: { profile: 'cache-strict' } } as never)
110
+ } })
111
+ await bundle.await()
112
+
113
+ const mounted = await service.mount({})
114
+ expect(mounted.path).not.toBe(preset.path)
115
+ expect((await service.recompose({}, 'standard')).path).toBe(mounted.path)
116
+
117
+ // Disposing the non-overlay row never touches the overlay row's decoration
118
+ // or its entry config.
119
+ await builtIn.dispose()
120
+ expect((await service.mount({})).path).toBe(mounted.path)
121
+
122
+ await bundle.dispose()
123
+ expect((await service.mount({})).path).toBe(preset.path)
124
+ })
125
+
126
+ it('writes the saved Auto Compact threshold into the generated compaction-basic composition', async () => {
127
+ const preset = await sourcePreset()
128
+ ctx = new Context()
129
+ await ctx.plugin(MemorySettings).await()
130
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
131
+ await ctx.plugin(FakeAgentPresets, preset).await()
132
+ // A settings-owning row must register the namespace before the update.
133
+ await ctx.plugin({ apply }).await()
134
+ const namespace = nsBrand('context-compression')
135
+ await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
136
+
137
+ const bundle = ctx.plugin({ apply: (child) => {
138
+ apply(child, { presetOverlay: true })
139
+ } })
140
+ await bundle.await()
141
+
142
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
143
+ const mounted = await service.mount({})
144
+ const rendered = await readFile(mounted.path, 'utf8')
145
+ expect(rendered).toContain('id: compaction-basic')
146
+ expect(rendered).toContain('thresholdRatio: 0.73')
147
+ // First-release retention stays pinned at 0.16 next to the threshold.
148
+ expect(rendered).toContain('retainRatio: 0.16')
149
+ // The SAME read feeds the runtime deployment config, so one generation
150
+ // cannot split Auto Compact and micro compact across two thresholds.
151
+ expect(rendered).toContain('id: tool-result-pruner')
152
+ expect(rendered).toContain('autoCompactThresholdPercent: 73')
153
+ await bundle.dispose()
154
+ })
155
+
156
+ it('defaults the generated threshold to 0.8 and keeps it absent from settings until saved', async () => {
157
+ const preset = await sourcePreset()
158
+ ctx = new Context()
159
+ await ctx.plugin(MemorySettings).await()
160
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
161
+ await ctx.plugin(FakeAgentPresets, preset).await()
162
+
163
+ const bundle = ctx.plugin({ apply: (child) => {
164
+ apply(child, { presetOverlay: true })
165
+ } })
166
+ await bundle.await()
167
+
168
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
169
+ const rendered = await readFile((await service.mount({})).path, 'utf8')
170
+ expect(rendered).toContain('thresholdRatio: 0.8')
171
+ await bundle.dispose()
172
+ })
173
+
174
+ it('moves the standing composition generation when an equal-length threshold changes', async () => {
175
+ const preset = await sourcePreset()
176
+ ctx = new Context()
177
+ await ctx.plugin(MemorySettings).await()
178
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
179
+ await ctx.plugin(FakeAgentPresets, preset).await()
180
+ // A settings-owning row must register the namespace before the update.
181
+ await ctx.plugin({ apply }).await()
182
+ const namespace = nsBrand('context-compression')
183
+ await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 70 } })
184
+
185
+ const bundle = ctx.plugin({ apply: (child) => {
186
+ apply(child, { presetOverlay: true })
187
+ } })
188
+ await bundle.await()
189
+
190
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
191
+ const first = await service.mount({})
192
+ expect(await readFile(first.path, 'utf8')).toContain('thresholdRatio: 0.7')
193
+ expect(await service.standingKeyFor()).toBe(first.path)
194
+
195
+ // Same character length, different content: the generated identity and
196
+ // standing composition generation must both move to the new threshold.
197
+ await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 80 } })
198
+ const second = await service.mount({})
199
+ expect(second.path).not.toBe(first.path)
200
+ expect(await readFile(second.path, 'utf8')).toContain('thresholdRatio: 0.8')
201
+ expect(await service.standingKeyFor()).toBe(second.path)
202
+ await bundle.dispose()
203
+ })
204
+ })