dsh-context-compression-improved 0.8.0-beta.3 → 0.8.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/eslint.config.js +30 -30
- package/package.json +163 -163
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +28 -0
- package/packages/selector/lib/client.js +631 -7
- package/packages/selector/lib/{advisor-state.js → config.js} +170 -65
- package/packages/selector/lib/index.d.ts +13 -1
- package/packages/selector/lib/index.js +306 -50
- package/packages/selector/lib/profiles.d.ts +15 -0
- package/packages/selector/lib/pruner.d.ts +65 -0
- package/packages/selector/lib/pruner.js +408 -5
- package/packages/selector/src/client/CompressionProfileControls.tsx +67 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +2 -0
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +41 -0
- package/packages/selector/src/client/locales/de.ts +26 -0
- package/packages/selector/src/client/locales/es.ts +26 -0
- package/packages/selector/src/client/locales/fr.ts +26 -0
- package/packages/selector/src/client/locales/it.ts +26 -0
- package/packages/selector/src/client/locales/ja.ts +26 -0
- package/packages/selector/src/client/locales/ko.ts +26 -0
- package/packages/selector/src/client/locales/ru.ts +26 -0
- package/packages/selector/src/client/locales.ts +52 -0
- package/packages/selector/src/client/monitor-fab.ts +307 -0
- package/packages/selector/src/client/settings-section.tsx +16 -2
- package/packages/selector/src/index.ts +133 -60
- package/packages/selector/src/profiles.ts +431 -394
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner.ts +241 -1
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +756 -706
- package/packages/selector/src/runtime/monitor.ts +149 -0
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/types.ts +365 -346
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -252
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +8 -6
- package/packages/selector/tests/monitor-fab.client.spec.ts +117 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +236 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2734 -2731
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +1 -1
- package/scripts/packed-install-e2e.mjs +1 -1
- package/scripts/verify-release.mjs +2 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_CONTEXT_COMPRESSION_SETTINGS,
|
|
4
|
+
parseContextCompressionSettings,
|
|
5
|
+
} from '../../src/runtime/config.ts'
|
|
6
|
+
import {
|
|
7
|
+
getLastIntentFold,
|
|
8
|
+
getObservedIntentEnabled,
|
|
9
|
+
getSummaryOverride,
|
|
10
|
+
recordIntentFold,
|
|
11
|
+
setSummaryOverride,
|
|
12
|
+
observeIntentEnabled,
|
|
13
|
+
} from '../../src/runtime/tokenpilot/advisor-state.ts'
|
|
14
|
+
import {
|
|
15
|
+
parseSummaryCommandArgs,
|
|
16
|
+
registerSummaryCommand,
|
|
17
|
+
} from '../../src/runtime/summary-command.ts'
|
|
18
|
+
|
|
19
|
+
describe('intentSummary settings parsing', () => {
|
|
20
|
+
it('defaults to lossless off', () => {
|
|
21
|
+
expect(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.intentSummary).toEqual({ enabled: false })
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('absent section inherits the default', () => {
|
|
25
|
+
const parsed = parseContextCompressionSettings({
|
|
26
|
+
profile: 'balanced',
|
|
27
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
28
|
+
autoCompact: { thresholdPercent: 80 },
|
|
29
|
+
codeSkeleton: { enabled: false },
|
|
30
|
+
})
|
|
31
|
+
expect(parsed.intentSummary).toEqual({ enabled: false })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('accepts exactly { enabled: boolean }', () => {
|
|
35
|
+
const parsed = parseContextCompressionSettings({
|
|
36
|
+
profile: 'balanced',
|
|
37
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
38
|
+
intentSummary: { enabled: true },
|
|
39
|
+
})
|
|
40
|
+
expect(parsed.intentSummary).toEqual({ enabled: true })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('rejects extra keys (present-but-invalid is never silently defaulted)', () => {
|
|
44
|
+
expect(() => parseContextCompressionSettings({
|
|
45
|
+
profile: 'balanced',
|
|
46
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
47
|
+
intentSummary: { enabled: true, gate: 1 },
|
|
48
|
+
})).toThrow(/expected exactly "enabled"/)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('rejects non-boolean enabled', () => {
|
|
52
|
+
expect(() => parseContextCompressionSettings({
|
|
53
|
+
profile: 'balanced',
|
|
54
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
55
|
+
intentSummary: { enabled: 'yes' },
|
|
56
|
+
})).toThrow(/intentSummary\.enabled must be a boolean/)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('rejects non-object section', () => {
|
|
60
|
+
expect(() => parseContextCompressionSettings({
|
|
61
|
+
profile: 'balanced',
|
|
62
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
63
|
+
intentSummary: true,
|
|
64
|
+
})).toThrow(/intentSummary must be a plain object/)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('session-scoped summary override state', () => {
|
|
69
|
+
it('round-trips and clears per session id, isolated across sessions', () => {
|
|
70
|
+
expect(getSummaryOverride('s1')).toBeUndefined()
|
|
71
|
+
setSummaryOverride('s1', 'off')
|
|
72
|
+
setSummaryOverride('s2', 'on')
|
|
73
|
+
expect(getSummaryOverride('s1')).toBe('off')
|
|
74
|
+
expect(getSummaryOverride('s2')).toBe('on')
|
|
75
|
+
setSummaryOverride('s1', undefined)
|
|
76
|
+
expect(getSummaryOverride('s1')).toBeUndefined()
|
|
77
|
+
expect(getSummaryOverride('s2')).toBe('on')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('observed enabled flag round-trips independently', () => {
|
|
81
|
+
expect(getObservedIntentEnabled('sx')).toBeUndefined()
|
|
82
|
+
observeIntentEnabled('sx', true)
|
|
83
|
+
expect(getObservedIntentEnabled('sx')).toBe(true)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('last fold record is newest-wins per session', () => {
|
|
87
|
+
expect(getLastIntentFold('sy')).toBeUndefined()
|
|
88
|
+
recordIntentFold('sy', { turn: 3, startSeq: 10, endSeq: 20, liveTokensBefore: 100_000, at: 1 })
|
|
89
|
+
recordIntentFold('sy', { turn: 5, startSeq: 30, endSeq: 40, liveTokensBefore: 150_000, at: 2 })
|
|
90
|
+
expect(getLastIntentFold('sy')).toMatchObject({ turn: 5, startSeq: 30 })
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
describe('/ctx-summary command surface', () => {
|
|
95
|
+
it('parses exactly off|on|status (case-insensitive, trimmed)', () => {
|
|
96
|
+
expect(parseSummaryCommandArgs(' off ')).toBe('off')
|
|
97
|
+
expect(parseSummaryCommandArgs('ON')).toBe('on')
|
|
98
|
+
expect(parseSummaryCommandArgs('Status')).toBe('status')
|
|
99
|
+
expect(parseSummaryCommandArgs('')).toBeUndefined()
|
|
100
|
+
expect(parseSummaryCommandArgs('now')).toBeUndefined()
|
|
101
|
+
expect(parseSummaryCommandArgs('off extra')).toBeUndefined()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('handler sets and clears the override for the invocation session', async () => {
|
|
105
|
+
let registered: { name: string, handler: (invocation: { agent?: unknown, rawInput?: unknown }) => Promise<{ kind: string, text: string }> } | undefined
|
|
106
|
+
const commands = { register: (definition: unknown): void => { registered = definition as typeof registered } }
|
|
107
|
+
const ctx = {
|
|
108
|
+
inject: (deps: readonly string[], callback: (injected: Record<string, unknown>) => void): void => {
|
|
109
|
+
if (deps.includes('commands')) callback({ commands })
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
registerSummaryCommand(ctx as never)
|
|
113
|
+
await vi.waitFor(() => expect(registered).toBeDefined())
|
|
114
|
+
expect(registered?.name).toBe('ctx-summary')
|
|
115
|
+
|
|
116
|
+
const agent = { session: { id: 'sess-1' } }
|
|
117
|
+
const off = await registered!.handler({ agent, rawInput: 'off' })
|
|
118
|
+
expect(off.kind).toBe('success')
|
|
119
|
+
expect(getSummaryOverride('sess-1')).toBe('off')
|
|
120
|
+
|
|
121
|
+
const on = await registered!.handler({ agent, rawInput: 'on' })
|
|
122
|
+
expect(on.kind).toBe('success')
|
|
123
|
+
expect(getSummaryOverride('sess-1')).toBe('on')
|
|
124
|
+
|
|
125
|
+
const bad = await registered!.handler({ agent, rawInput: 'wat' })
|
|
126
|
+
expect(bad.kind).toBe('error')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('status reports override, gate and last fold', async () => {
|
|
130
|
+
let registered: { handler: (invocation: { agent?: unknown, rawInput?: unknown }) => Promise<{ kind: string, text: string }> } | undefined
|
|
131
|
+
const commands = { register: (definition: unknown): void => { registered = definition as typeof registered } }
|
|
132
|
+
registerSummaryCommand({
|
|
133
|
+
inject: (_deps: readonly string[], callback: (injected: Record<string, unknown>) => void) => callback({ commands }),
|
|
134
|
+
} as never)
|
|
135
|
+
await vi.waitFor(() => expect(registered).toBeDefined())
|
|
136
|
+
recordIntentFold('sess-9', { turn: 7, startSeq: 5, endSeq: 9, liveTokensBefore: 120_000, at: 42 })
|
|
137
|
+
const out = await registered!.handler({ agent: { session: { id: 'sess-9' } }, rawInput: 'status' })
|
|
138
|
+
expect(out.kind).toBe('success')
|
|
139
|
+
expect(out.text).toContain('override: default')
|
|
140
|
+
expect(out.text).toContain('seq 5..9')
|
|
141
|
+
expect(out.text).toContain('45% of window')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('stays quiet when the commands service never mounts', () => {
|
|
145
|
+
const ctx = {
|
|
146
|
+
inject: (deps: readonly string[], callback: (injected: Record<string, unknown>) => void) => {
|
|
147
|
+
// cordis semantics: the callback never runs when a dependency is absent.
|
|
148
|
+
void deps
|
|
149
|
+
void callback
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
expect(() => registerSummaryCommand(ctx as never)).not.toThrow()
|
|
153
|
+
})
|
|
154
|
+
})
|
|
@@ -90,7 +90,7 @@ describe('settings-seat contract (standalone settings.section only)', () => {
|
|
|
90
90
|
expect((options['label'] as () => string)()).toBe('nav')
|
|
91
91
|
expect(typeof options['inject']).toBe('function')
|
|
92
92
|
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
93
|
-
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
93
|
+
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'saveIntentSummary', 'saveMonitorPanel', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
94
94
|
expect(component).toBe(ContextCompressionSettingsSection)
|
|
95
95
|
})
|
|
96
96
|
|
|
@@ -416,7 +416,7 @@ async function runOfficialCloneCliSmoke(referenceRoot, registry, upgradeFrom, ca
|
|
|
416
416
|
* ui-slot packages) the web bundler supplies, and that stack is verified
|
|
417
417
|
* from the built client libraries below.
|
|
418
418
|
*/
|
|
419
|
-
const HOST_PLANE_ENTRIES = ['index.js', 'pruner.js', '
|
|
419
|
+
const HOST_PLANE_ENTRIES = ['index.js', 'pruner.js', 'config.js', 'tail-trim.js', 'invariant.js']
|
|
420
420
|
|
|
421
421
|
/**
|
|
422
422
|
* Bare package names the installed package's host-plane runtime files import.
|
|
@@ -39,6 +39,7 @@ if (rootPackage.dsh?.bundle?.patch !== './packages/selector/cordis.patch.yml') {
|
|
|
39
39
|
const INSTALLATION_PROVIDED_RUNTIME = new Set([
|
|
40
40
|
'@deepseek-ai/cordis',
|
|
41
41
|
'@deepseek-ai/cordis-plugin-include',
|
|
42
|
+
'@deepseek-ai/dsh-commands',
|
|
42
43
|
'@deepseek-ai/dsh-llm',
|
|
43
44
|
'@deepseek-ai/dsh-session',
|
|
44
45
|
'@deepseek-ai/dsh-settings',
|
|
@@ -48,7 +49,7 @@ const INSTALLATION_PROVIDED_RUNTIME = new Set([
|
|
|
48
49
|
// stack (`react`, the ui-slot packages); its requires are reviewed from the
|
|
49
50
|
// built artifact further down instead.
|
|
50
51
|
const HOST_PLANE_ENTRIES = [
|
|
51
|
-
'lib/
|
|
52
|
+
'lib/config.js',
|
|
52
53
|
'lib/index.js',
|
|
53
54
|
'lib/invariant.js',
|
|
54
55
|
'lib/pruner.js',
|