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.
- package/CHANGELOG.ja.md +226 -220
- package/CHANGELOG.ko.md +220 -214
- package/CHANGELOG.md +366 -376
- package/CHANGELOG.zh.md +204 -199
- package/README.ja.md +85 -85
- package/README.ko.md +85 -85
- package/README.md +98 -97
- package/README.zh.md +85 -86
- package/eslint.config.js +30 -76
- package/package.json +53 -55
- package/packages/selector/dsh.plugin.json +2 -2
- package/packages/selector/lib/{intent-gate.js → advisor-state.js} +3 -91
- package/packages/selector/lib/client.js +3 -14
- package/packages/selector/lib/index.js +1 -92
- package/packages/selector/lib/profiles.d.ts +0 -9
- package/packages/selector/lib/pruner.d.ts +0 -59
- package/packages/selector/lib/pruner.js +7 -410
- package/packages/selector/lib/style.css +46 -46
- package/packages/selector/package.json +114 -114
- package/packages/selector/src/client/decode.ts +2 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
- package/packages/selector/src/index.ts +411 -418
- package/packages/selector/src/preset-overlay.ts +0 -3
- package/packages/selector/src/profiles.ts +10 -30
- package/packages/selector/src/pruner/content.ts +1 -1
- package/packages/selector/src/pruner/state.ts +0 -7
- package/packages/selector/src/pruner.ts +9 -253
- package/packages/selector/src/runtime/audit.ts +0 -17
- package/packages/selector/src/runtime/config.ts +11 -36
- package/packages/selector/src/runtime/reducers.ts +1 -1
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +1 -46
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -55
- package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +1 -4
- package/packages/selector/src/runtime/types.ts +0 -12
- package/packages/selector/tests/auto-compact.client.spec.tsx +213 -214
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -61
- package/packages/selector/tests/code-skeleton.client.spec.ts +93 -94
- package/packages/selector/tests/custom-contract.client.spec.ts +222 -223
- package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
- package/packages/selector/tests/preset-options-write.client.spec.ts +187 -188
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
- package/packages/selector/tests/profiles.client.spec.tsx +434 -436
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
- package/packages/selector/tests/runtime/audit.spec.ts +274 -275
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2736
- package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
- package/pnpm-workspace.yaml +66 -66
- package/scripts/packed-components-smoke.mjs +0 -2
- package/scripts/packed-install-e2e.mjs +5 -7
- package/scripts/verify-release.mjs +2 -3
- package/tsconfig.tests.json +1 -3
- package/vitest.config.ts +0 -14
- package/packages/selector/src/runtime/summary-command.ts +0 -133
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
- package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
- package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
- package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
3
|
-
import * as React from 'react'
|
|
4
|
-
import * as jsxRuntime from 'react/jsx-runtime'
|
|
5
|
-
import { describe, expect, it } from 'vitest'
|
|
6
|
-
|
|
7
|
-
const artifact = resolve(import.meta.dirname, '../../lib/client.js')
|
|
8
|
-
|
|
9
|
-
describe('built Harness client artifact', () => {
|
|
10
|
-
it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
|
|
11
|
-
const code = readFileSync(artifact, 'utf8')
|
|
12
|
-
let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
|
|
13
|
-
const moduleLoader = {
|
|
14
|
-
load(value: typeof registration) {
|
|
15
|
-
registration = value
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
expect(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect(
|
|
57
|
-
expect(code).not.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
61
|
-
})
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import * as jsxRuntime from 'react/jsx-runtime'
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
|
|
7
|
+
const artifact = resolve(import.meta.dirname, '../../lib/client.js')
|
|
8
|
+
|
|
9
|
+
describe('built Harness client artifact', () => {
|
|
10
|
+
it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
|
|
11
|
+
const code = readFileSync(artifact, 'utf8')
|
|
12
|
+
let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
|
|
13
|
+
const moduleLoader = {
|
|
14
|
+
load(value: typeof registration) {
|
|
15
|
+
registration = value
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
|
|
19
|
+
|
|
20
|
+
expect(() => Function(code)()).not.toThrow()
|
|
21
|
+
expect(registration?.id).toBe('dsh-context-compression-improved')
|
|
22
|
+
|
|
23
|
+
const modules = new Map<string, unknown>([
|
|
24
|
+
['react', React],
|
|
25
|
+
['react/jsx-runtime', jsxRuntime],
|
|
26
|
+
// The current selector only keeps this official package as a side-effect
|
|
27
|
+
// external. A minimal public-module stub proves the artifact asks the
|
|
28
|
+
// Harness loader for it without importing the package's raw CSS in Node.
|
|
29
|
+
['@deepseek-ai/dsh-client-ui-primitives', {}],
|
|
30
|
+
])
|
|
31
|
+
const exported = registration?.factory((id) => {
|
|
32
|
+
if (!modules.has(id)) throw new Error(`unexpected client dependency: ${id}`)
|
|
33
|
+
return modules.get(id)
|
|
34
|
+
}) as { apply?: unknown, inject?: unknown }
|
|
35
|
+
|
|
36
|
+
expect(exported.apply).toBeTypeOf('function')
|
|
37
|
+
// Declare every consumed service: cordis holds apply until each one is
|
|
38
|
+
// provided, which is the official client-plugin pattern on this 0.1.5 host
|
|
39
|
+
// line (dsh-thinking-levels does the same). The earlier lazy alternative —
|
|
40
|
+
// resolving `locale` / `configForms` through ctx.get() inside apply —
|
|
41
|
+
// raced the settings client's activation; on a loss the apply
|
|
42
|
+
// early-returned and EVERY settings entry (the standalone section, the
|
|
43
|
+
// plugins-tab card, the item card) silently vanished. See the rationale
|
|
44
|
+
// recorded in src/client/index.ts.
|
|
45
|
+
expect(exported.inject).toEqual(['slots', 'locale', 'configForms'])
|
|
46
|
+
const style = document.querySelector<HTMLStyleElement>(
|
|
47
|
+
'style[data-plugin-css="dsh-context-compression-improved/CompressionProfileSelector.module.css"]',
|
|
48
|
+
)
|
|
49
|
+
expect(style?.dataset.plugin).toBe('dsh-context-compression-improved')
|
|
50
|
+
expect(style?.textContent).toContain('profileGrid')
|
|
51
|
+
expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
|
|
52
|
+
|
|
53
|
+
registration?.factory((id) => modules.get(id))
|
|
54
|
+
expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
|
|
55
|
+
expect(code).not.toMatch(/^\s*(?:import|export)\s/mu)
|
|
56
|
+
expect(code).not.toMatch(/(?:\/home\/|[A-Za-z]:\\Users\\)/u)
|
|
57
|
+
expect(code).not.toContain('sourceMappingURL')
|
|
58
|
+
})
|
|
59
|
+
})
|
|
@@ -1,94 +1,93 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
-
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
-
import { apply } from '../src/client/index.ts'
|
|
6
|
-
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
7
|
-
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 0.1.7 contract: `codeSkeleton` rides the entry config as part of the volatile
|
|
11
|
-
* `settings` whole-object field. Every write commits the full doc through
|
|
12
|
-
* `configForms.set('settings', doc)`; the confirm-on-write semantics are
|
|
13
|
-
* unchanged — a host that silently drops (or flips) the section fails the
|
|
14
|
-
* acceptance check on the post-commit snapshot.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
18
|
-
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
19
|
-
let revision = 3
|
|
20
|
-
let commit = false
|
|
21
|
-
let flipEnabled = false
|
|
22
|
-
let value: ContextCompressionSettings = {
|
|
23
|
-
profile: 'balanced',
|
|
24
|
-
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
25
|
-
autoCompact: { thresholdPercent: 80 },
|
|
26
|
-
codeSkeleton: { enabled: false },
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
expect(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
+
import { apply } from '../src/client/index.ts'
|
|
6
|
+
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
7
|
+
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 0.1.7 contract: `codeSkeleton` rides the entry config as part of the volatile
|
|
11
|
+
* `settings` whole-object field. Every write commits the full doc through
|
|
12
|
+
* `configForms.set('settings', doc)`; the confirm-on-write semantics are
|
|
13
|
+
* unchanged — a host that silently drops (or flips) the section fails the
|
|
14
|
+
* acceptance check on the post-commit snapshot.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
18
|
+
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
19
|
+
let revision = 3
|
|
20
|
+
let commit = false
|
|
21
|
+
let flipEnabled = false
|
|
22
|
+
let value: ContextCompressionSettings = {
|
|
23
|
+
profile: 'balanced',
|
|
24
|
+
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
25
|
+
autoCompact: { thresholdPercent: 80 },
|
|
26
|
+
codeSkeleton: { enabled: false },
|
|
27
|
+
}
|
|
28
|
+
const form = {
|
|
29
|
+
getSnapshot: vi.fn(() => ({
|
|
30
|
+
status: 'ready' as const,
|
|
31
|
+
value: { settings: value },
|
|
32
|
+
base: undefined,
|
|
33
|
+
user: undefined,
|
|
34
|
+
revision,
|
|
35
|
+
writable: true,
|
|
36
|
+
mode: 'host' as const,
|
|
37
|
+
})),
|
|
38
|
+
subscribe: vi.fn(() => () => {}),
|
|
39
|
+
set: vi.fn(async (_field: string, next: unknown) => {
|
|
40
|
+
if (!commit) return false
|
|
41
|
+
revision += 1
|
|
42
|
+
const doc = structuredClone(next) as ContextCompressionSettings
|
|
43
|
+
if (flipEnabled) {
|
|
44
|
+
const accepted = structuredClone(doc.codeSkeleton)
|
|
45
|
+
accepted.enabled = !accepted.enabled
|
|
46
|
+
value = { ...doc, codeSkeleton: accepted }
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
value = doc
|
|
50
|
+
return true
|
|
51
|
+
}),
|
|
52
|
+
unset: vi.fn(async () => false),
|
|
53
|
+
}
|
|
54
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
55
|
+
const ctx = {
|
|
56
|
+
effect: (install: () => unknown) => { install() },
|
|
57
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
58
|
+
configForms: { get: vi.fn(() => form) },
|
|
59
|
+
slots: {
|
|
60
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
61
|
+
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
62
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
63
|
+
if (typeof registration.inject === 'function') injected = registration.inject
|
|
64
|
+
return () => {}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
} as unknown as Parameters<typeof apply>[0]
|
|
68
|
+
|
|
69
|
+
apply(ctx)
|
|
70
|
+
const actions = injected?.()
|
|
71
|
+
expect(actions).toBeDefined()
|
|
72
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
73
|
+
|
|
74
|
+
// A silent host drop leaves the revision untouched: the write must reject.
|
|
75
|
+
await expect(actions.saveCodeSkeleton(true)).rejects.toThrow('were not saved')
|
|
76
|
+
|
|
77
|
+
// A committed write resolves and persists the exact section payload under
|
|
78
|
+
// the volatile `settings` field.
|
|
79
|
+
commit = true
|
|
80
|
+
await expect(actions.saveCodeSkeleton(true)).resolves.toBeUndefined()
|
|
81
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: true } }))
|
|
82
|
+
expect(value.codeSkeleton).toEqual({ enabled: true })
|
|
83
|
+
|
|
84
|
+
// A host that flips the toggled bit fails the acceptance check.
|
|
85
|
+
flipEnabled = true
|
|
86
|
+
await expect(actions.saveCodeSkeleton(false)).rejects.toThrow('were not saved')
|
|
87
|
+
|
|
88
|
+
flipEnabled = false
|
|
89
|
+
await expect(actions.saveCodeSkeleton(false)).resolves.toBeUndefined()
|
|
90
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: false } }))
|
|
91
|
+
expect(value.codeSkeleton).toEqual({ enabled: false })
|
|
92
|
+
})
|
|
93
|
+
})
|