dsh-context-compression-improved 0.2.3 → 0.2.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/.gitattributes +2 -1
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.ja.md +169 -39
- package/CHANGELOG.ko.md +167 -39
- package/CHANGELOG.md +333 -135
- package/CHANGELOG.zh.md +152 -39
- package/CONTRIBUTING.md +22 -22
- package/README.ja.md +85 -104
- package/README.ko.md +85 -103
- package/README.md +94 -112
- package/README.zh.md +85 -101
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.ja.md +78 -76
- package/docs/installation.ko.md +78 -76
- package/docs/installation.md +103 -76
- package/docs/installation.zh.md +100 -76
- package/docs/repair-log.md +657 -582
- package/eslint.config.js +30 -30
- package/package.json +163 -142
- package/packages/selector/README.md +26 -31
- package/packages/selector/README.zh.md +24 -31
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
- package/packages/selector/cordis.patch.yml +27 -19
- package/packages/selector/dsh.plugin.json +2 -2
- package/packages/selector/lib/client.d.ts +320 -228
- package/packages/selector/lib/client.js +3254 -1462
- package/packages/selector/lib/config.js +1713 -842
- package/packages/selector/lib/index.d.ts +46 -38
- package/packages/selector/lib/index.js +1099 -645
- package/packages/selector/lib/invariant.js +70 -70
- package/packages/selector/lib/pruner.d.ts +904 -684
- package/packages/selector/lib/pruner.js +5800 -3807
- package/packages/selector/lib/style.css +88 -46
- package/packages/selector/lib/tail-trim.js +145 -136
- package/packages/selector/package.json +18 -19
- package/packages/selector/screenshots.json +3 -6
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
- package/packages/selector/src/client/EstimatorControls.tsx +277 -281
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +249 -111
- package/packages/selector/src/client/locales/de.ts +141 -0
- package/packages/selector/src/client/locales/es.ts +141 -0
- package/packages/selector/src/client/locales/fr.ts +141 -0
- package/packages/selector/src/client/locales/it.ts +141 -0
- package/packages/selector/src/client/locales/ja.ts +141 -0
- package/packages/selector/src/client/locales/ko.ts +141 -0
- package/packages/selector/src/client/locales/ru.ts +141 -0
- package/packages/selector/src/client/locales.ts +282 -198
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/preset-options.ts +88 -70
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -126
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
- package/packages/selector/src/index.ts +671 -327
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/preset-overlay.ts +60 -1
- package/packages/selector/src/profiles.ts +431 -342
- package/packages/selector/src/pruner/content.ts +18 -5
- package/packages/selector/src/pruner/state.ts +57 -43
- package/packages/selector/src/pruner/types.ts +23 -5
- package/packages/selector/src/pruner.ts +2736 -2144
- package/packages/selector/src/runtime/adaptive-cost.ts +23 -12
- package/packages/selector/src/runtime/audit.ts +303 -215
- package/packages/selector/src/runtime/config.ts +756 -613
- package/packages/selector/src/runtime/measurement.ts +436 -403
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/reducers.ts +1115 -97
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/session-events.ts +30 -17
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +1 -1
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
- 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/tokenpilot/locator.ts +1 -1
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +23 -2
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
- package/packages/selector/src/runtime/toolclass.ts +103 -0
- package/packages/selector/src/runtime/types.ts +365 -309
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
- package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
- package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -243
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +7 -7
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -129
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +14 -3
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
- 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/line-mapping.spec.ts +153 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2531
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +24 -0
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +697 -631
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
- package/pnpm-workspace.yaml +66 -19
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
- package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
- package/scripts/toolclass-corpus-replay.mjs +281 -0
- package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
- package/tests/TEST_INVENTORY.md +41 -42
- package/scripts/capture-profile-baseline.ts +0 -80
- package/tsconfig.scripts.json +0 -13
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
|
@@ -1,100 +1,116 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TokenPilot-inspired preset: policy derivation plus the backward-compat
|
|
3
|
-
* golden. The fixture freezes the resolvePolicy output of every pre-existing
|
|
4
|
-
* profile captured BEFORE this preset existed; any byte difference is a
|
|
5
|
-
* compatibility regression, however intentional it feels.
|
|
6
|
-
*/
|
|
7
|
-
import { readFileSync } from 'node:fs'
|
|
8
|
-
import { join } from 'node:path'
|
|
9
|
-
import { describe, expect, it } from 'vitest'
|
|
10
|
-
import {
|
|
11
|
-
parseContextCompressionSettings,
|
|
12
|
-
resolveConfig,
|
|
13
|
-
resolvePolicy,
|
|
14
|
-
} from '../../../src/pruner.ts'
|
|
15
|
-
|
|
16
|
-
const baseline = JSON.parse(readFileSync(
|
|
17
|
-
join(import.meta.dirname, '..', 'fixtures', 'profile-baseline.json'),
|
|
18
|
-
'utf8',
|
|
19
|
-
)) as {
|
|
20
|
-
profiles: Record<string, Record<string, unknown>>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const OLD_PROFILES = ['off', 'native', 'balanced', 'cache-strict', 'savings', 'adaptive', 'custom'] as const
|
|
24
|
-
const OPTION_CASES = [
|
|
25
|
-
{ label: 'defaults', options: {} },
|
|
26
|
-
{ label: 'linkage', options: { contextWindowTokens: 128_000, autoCompactThresholdPercent: 80 } },
|
|
27
|
-
] as const
|
|
28
|
-
|
|
29
|
-
describe('tokenpilot-inspired preset', () => {
|
|
30
|
-
it('keeps every pre-existing profile byte-identical to the pre-preset baseline', () => {
|
|
31
|
-
const config = resolveConfig({})
|
|
32
|
-
for (const profile of OLD_PROFILES) {
|
|
33
|
-
for (const optionCase of OPTION_CASES) {
|
|
34
|
-
const key = optionCase.label
|
|
35
|
-
expect(
|
|
36
|
-
resolvePolicy(config, profile, undefined, optionCase.options),
|
|
37
|
-
`${profile}/${key}`,
|
|
38
|
-
).toStrictEqual(baseline.profiles[profile]?.[key])
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('derives from the balanced baseline and injects the capability matrix', () => {
|
|
44
|
-
const config = resolveConfig({})
|
|
45
|
-
const policy = resolvePolicy(config, 'tokenpilot-inspired')
|
|
46
|
-
expect(policy.profile).toBe('tokenpilot-inspired')
|
|
47
|
-
expect(policy.freshEnabled).toBe(true)
|
|
48
|
-
expect(policy.aggregateEnabled).toBe(true)
|
|
49
|
-
expect(policy.historyMode).toBe('routine')
|
|
50
|
-
expect(policy.freshTriggerTokens).toBe(8_192)
|
|
51
|
-
expect(policy.freshTargetTokens).toBe(3_072)
|
|
52
|
-
expect(policy.aggregateTriggerTokens).toBe(32_768)
|
|
53
|
-
expect(policy.aggregateTargetTokens).toBe(12_288)
|
|
54
|
-
expect(policy.historyTriggerTokens).toBe(500_000)
|
|
55
|
-
expect(policy.historyMinReclaimTokens).toBe(96_000)
|
|
56
|
-
expect(policy.presetOptions).toStrictEqual({
|
|
57
|
-
noNetSavingsGuard: true,
|
|
58
|
-
skipReductionRecovery: true,
|
|
59
|
-
dedupeToolResults: true,
|
|
60
|
-
summaryLocator: true,
|
|
61
|
-
prefixStabilizer: true,
|
|
62
|
-
readState: true,
|
|
63
|
-
estimator: { mode: '' },
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
expect(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
expect(()
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
/**
|
|
2
|
+
* TokenPilot-inspired preset: policy derivation plus the backward-compat
|
|
3
|
+
* golden. The fixture freezes the resolvePolicy output of every pre-existing
|
|
4
|
+
* profile captured BEFORE this preset existed; any byte difference is a
|
|
5
|
+
* compatibility regression, however intentional it feels.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
import { describe, expect, it } from 'vitest'
|
|
10
|
+
import {
|
|
11
|
+
parseContextCompressionSettings,
|
|
12
|
+
resolveConfig,
|
|
13
|
+
resolvePolicy,
|
|
14
|
+
} from '../../../src/pruner.ts'
|
|
15
|
+
|
|
16
|
+
const baseline = JSON.parse(readFileSync(
|
|
17
|
+
join(import.meta.dirname, '..', 'fixtures', 'profile-baseline.json'),
|
|
18
|
+
'utf8',
|
|
19
|
+
)) as {
|
|
20
|
+
profiles: Record<string, Record<string, unknown>>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const OLD_PROFILES = ['off', 'native', 'balanced', 'cache-strict', 'savings', 'adaptive', 'custom'] as const
|
|
24
|
+
const OPTION_CASES = [
|
|
25
|
+
{ label: 'defaults', options: {} },
|
|
26
|
+
{ label: 'linkage', options: { contextWindowTokens: 128_000, autoCompactThresholdPercent: 80 } },
|
|
27
|
+
] as const
|
|
28
|
+
|
|
29
|
+
describe('tokenpilot-inspired preset', () => {
|
|
30
|
+
it('keeps every pre-existing profile byte-identical to the pre-preset baseline', () => {
|
|
31
|
+
const config = resolveConfig({})
|
|
32
|
+
for (const profile of OLD_PROFILES) {
|
|
33
|
+
for (const optionCase of OPTION_CASES) {
|
|
34
|
+
const key = optionCase.label
|
|
35
|
+
expect(
|
|
36
|
+
resolvePolicy(config, profile, undefined, optionCase.options),
|
|
37
|
+
`${profile}/${key}`,
|
|
38
|
+
).toStrictEqual(baseline.profiles[profile]?.[key])
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('derives from the balanced baseline and injects the capability matrix', () => {
|
|
44
|
+
const config = resolveConfig({})
|
|
45
|
+
const policy = resolvePolicy(config, 'tokenpilot-inspired')
|
|
46
|
+
expect(policy.profile).toBe('tokenpilot-inspired')
|
|
47
|
+
expect(policy.freshEnabled).toBe(true)
|
|
48
|
+
expect(policy.aggregateEnabled).toBe(true)
|
|
49
|
+
expect(policy.historyMode).toBe('routine')
|
|
50
|
+
expect(policy.freshTriggerTokens).toBe(8_192)
|
|
51
|
+
expect(policy.freshTargetTokens).toBe(3_072)
|
|
52
|
+
expect(policy.aggregateTriggerTokens).toBe(32_768)
|
|
53
|
+
expect(policy.aggregateTargetTokens).toBe(12_288)
|
|
54
|
+
expect(policy.historyTriggerTokens).toBe(500_000)
|
|
55
|
+
expect(policy.historyMinReclaimTokens).toBe(96_000)
|
|
56
|
+
expect(policy.presetOptions).toStrictEqual({
|
|
57
|
+
noNetSavingsGuard: true,
|
|
58
|
+
skipReductionRecovery: true,
|
|
59
|
+
dedupeToolResults: true,
|
|
60
|
+
summaryLocator: true,
|
|
61
|
+
prefixStabilizer: true,
|
|
62
|
+
readState: true,
|
|
63
|
+
estimator: { mode: '' },
|
|
64
|
+
// Advisory advisor ships off with its documented defaults. The
|
|
65
|
+
// resolved matrix intentionally gains this group so it follows the
|
|
66
|
+
// estimator's resolved-consumption pattern; see
|
|
67
|
+
// .agents/plans/ctx-relevance-advisor/spec.md decision record.
|
|
68
|
+
//
|
|
69
|
+
// The retired review gate's four keys are intentionally absent here:
|
|
70
|
+
// they are still ACCEPTED by the parser for upgrade safety but never
|
|
71
|
+
// reach the resolved policy (a reduction must not be gated).
|
|
72
|
+
advisor: {
|
|
73
|
+
mode: '',
|
|
74
|
+
timeoutMs: 8000,
|
|
75
|
+
refreshTurns: 8,
|
|
76
|
+
scoreThreshold: 0.35,
|
|
77
|
+
sampleLimit: 16,
|
|
78
|
+
minTokens: 250,
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
// Other profiles never carry the capability matrix.
|
|
82
|
+
expect(resolvePolicy(config, 'balanced').presetOptions).toBeUndefined()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('links Auto Compact watermarks like balanced does', () => {
|
|
86
|
+
const config = resolveConfig({})
|
|
87
|
+
const policy = resolvePolicy(config, 'tokenpilot-inspired', undefined, {
|
|
88
|
+
contextWindowTokens: 128_000,
|
|
89
|
+
autoCompactThresholdPercent: 80,
|
|
90
|
+
})
|
|
91
|
+
expect(policy.autoCompactTokens).toBe(102_400)
|
|
92
|
+
expect(policy.microDeadlineTokens).toBe(89_600)
|
|
93
|
+
expect(policy.historyTriggerTokens).toBe(64_000)
|
|
94
|
+
expect(policy.historyMinReclaimTokens).toBe(12_288)
|
|
95
|
+
expect(policy.historyKeepRecentTokens).toBe(8_192)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('accepts persisted presetOptions overrides and rejects unknown keys', () => {
|
|
99
|
+
const base = {
|
|
100
|
+
profile: 'balanced',
|
|
101
|
+
custom: { version: 3, unit: 'tokens', fresh: { enabled: true, trigger: 2, target: 1 }, aggregate: { enabled: false, trigger: 2, target: 1 }, history: { enabled: false, trigger: 2, keepRecentToolCalls: 1, keepRecentTokens: 1, minReclaim: 1 }, prefixPolicy: 'preserve', tailTrim: { enabled: false, trigger: 2 } },
|
|
102
|
+
}
|
|
103
|
+
const doc = {
|
|
104
|
+
...base,
|
|
105
|
+
presetOptions: { dedupeToolResults: false, estimatorMode: 'host' },
|
|
106
|
+
}
|
|
107
|
+
expect((parseContextCompressionSettings(structuredClone(doc)) as { presetOptions?: unknown }).presetOptions).toStrictEqual({
|
|
108
|
+
dedupeToolResults: false,
|
|
109
|
+
estimatorMode: 'host',
|
|
110
|
+
})
|
|
111
|
+
expect(() => parseContextCompressionSettings({
|
|
112
|
+
...base,
|
|
113
|
+
presetOptions: { nope: true },
|
|
114
|
+
})).toThrow()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
@@ -55,4 +55,28 @@ describe('tokenpilot read-state helpers', () => {
|
|
|
55
55
|
expect(clusterOmittedLines('fine', 1)).toBe('1 lines omitted (1 info)')
|
|
56
56
|
expect(clusterOmittedLines('fine', 0)).toBeUndefined()
|
|
57
57
|
})
|
|
58
|
+
|
|
59
|
+
// R8 census: a document's dropped content is described by its section
|
|
60
|
+
// headings, not by an error/warn/info histogram that is always 0/0/N.
|
|
61
|
+
it('lists section headings for document content instead of the info census', () => {
|
|
62
|
+
const doc = [
|
|
63
|
+
'# User Guide',
|
|
64
|
+
'Intro paragraph.',
|
|
65
|
+
'## Installation',
|
|
66
|
+
'Run the installer.',
|
|
67
|
+
'## Configuration',
|
|
68
|
+
'Set the flags.',
|
|
69
|
+
'## Troubleshooting',
|
|
70
|
+
'Check the logs.',
|
|
71
|
+
'## Reference',
|
|
72
|
+
'Appendix material.',
|
|
73
|
+
].join('\n')
|
|
74
|
+
const census = clusterOmittedLines(doc, 40)
|
|
75
|
+
expect(census).toBe(
|
|
76
|
+
'40 lines omitted (sections: User Guide · Installation · Configuration · Troubleshooting · Reference)',
|
|
77
|
+
)
|
|
78
|
+
for (const heading of ['Installation', 'Troubleshooting', 'Reference']) {
|
|
79
|
+
expect(census).toContain(heading)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
58
82
|
})
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { classifyToolSource } from '../../src/runtime/toolclass.ts'
|
|
3
|
+
import { extractCommand, reduceFreshToolResult } from '../../src/runtime/reducers.ts'
|
|
4
|
+
|
|
5
|
+
/** Checklist C1–C15 against the FOUR-class narrowing (tasks v2 G4): web/memory
|
|
6
|
+
* search and research/sql names fall to generic, glob is path-listing, only
|
|
7
|
+
* grep/rg/ripgrep are search, and the content fallback never overrides a
|
|
8
|
+
* whitelist hit. */
|
|
9
|
+
describe('classifyToolSource — name whitelist', () => {
|
|
10
|
+
it('keeps web_search out of search (C1)', () => {
|
|
11
|
+
expect(classifyToolSource('web_search', '')).toBe('generic')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('routes glob to path-listing (C2)', () => {
|
|
15
|
+
expect(classifyToolSource('glob', '')).toBe('path-listing')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('keeps memory/conversation search generic — four classes only (C3, v2)', () => {
|
|
19
|
+
expect(classifyToolSource('memory_search', '')).toBe('generic')
|
|
20
|
+
expect(classifyToolSource('conversation_search', '')).toBe('generic')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('routes grep/rg/ripgrep to search (C4)', () => {
|
|
24
|
+
expect(classifyToolSource('grep', '')).toBe('search')
|
|
25
|
+
expect(classifyToolSource('rg', '')).toBe('search')
|
|
26
|
+
expect(classifyToolSource('ripgrep', '')).toBe('search')
|
|
27
|
+
expect(classifyToolSource('grep_search', '')).toBe('search')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('routes shell/bash/pwsh/terminal to shell-exec (C5)', () => {
|
|
31
|
+
expect(classifyToolSource('shell', '')).toBe('shell')
|
|
32
|
+
expect(classifyToolSource('bash', '')).toBe('shell')
|
|
33
|
+
expect(classifyToolSource('pwsh', '')).toBe('shell')
|
|
34
|
+
expect(classifyToolSource('powershell', '')).toBe('shell')
|
|
35
|
+
expect(classifyToolSource('terminal', '')).toBe('shell')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('routes read/read_file/cat/view/open_file to file-read (C6)', () => {
|
|
39
|
+
expect(classifyToolSource('read', '')).toBe('read')
|
|
40
|
+
expect(classifyToolSource('read_file', '')).toBe('read')
|
|
41
|
+
expect(classifyToolSource('cat', '')).toBe('read')
|
|
42
|
+
expect(classifyToolSource('view', '')).toBe('read')
|
|
43
|
+
expect(classifyToolSource('view_file', '')).toBe('read')
|
|
44
|
+
expect(classifyToolSource('open_file', '')).toBe('read')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('is generic for mutation tools — no file-mutate class in the four-class set (C7, v2)', () => {
|
|
48
|
+
expect(classifyToolSource('write', '')).toBe('generic')
|
|
49
|
+
expect(classifyToolSource('edit', '')).toBe('generic')
|
|
50
|
+
expect(classifyToolSource('apply_patch', '')).toBe('generic')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('returns generic for any name with an mcp token, before content evidence (C8)', () => {
|
|
54
|
+
expect(classifyToolSource('mcp__server__grep', '', 'src/a.ts:1: x')).toBe('generic')
|
|
55
|
+
expect(classifyToolSource('mcp-grep', '', 'src/a.ts:1: x')).toBe('generic')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('never misroutes `research` into a search class (C9)', () => {
|
|
59
|
+
expect(classifyToolSource('research', '')).toBe('generic')
|
|
60
|
+
expect(classifyToolSource('deep_research', '')).toBe('generic')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('never misroutes `execute_sql` into shell-exec (C10)', () => {
|
|
64
|
+
expect(classifyToolSource('execute_sql', '')).toBe('generic')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('matches tokens exactly — no substring bleed (task_11)', () => {
|
|
68
|
+
expect(classifyToolSource('advanced_search', '')).toBe('generic')
|
|
69
|
+
expect(classifyToolSource('free_search_test', '')).toBe('generic')
|
|
70
|
+
expect(classifyToolSource('theme_global', '')).toBe('generic')
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('classifyToolSource — command and content fallback', () => {
|
|
75
|
+
it('routes rg/grep commands to search even from an unknown tool name', () => {
|
|
76
|
+
expect(classifyToolSource('run_tool', 'rg pattern src/')).toBe('search')
|
|
77
|
+
expect(classifyToolSource('run_tool', 'grep -n TODO .')).toBe('search')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('routes find/fd/ls/tree commands to path-listing, not search', () => {
|
|
81
|
+
expect(classifyToolSource('run_tool', 'find . -name "*.ts"')).toBe('path-listing')
|
|
82
|
+
expect(classifyToolSource('run_tool', 'fd config')).toBe('path-listing')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('falls back to search on a path:line:content line (C13)', () => {
|
|
86
|
+
expect(classifyToolSource('unknown_tool', '', 'src/index.ts:12: export const x')).toBe('search')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('does not let prose colons or URLs masquerade as grep output (C13 guard)', () => {
|
|
90
|
+
expect(classifyToolSource('unknown_tool', '', 'Note: 2024 - something happened')).toBe('generic')
|
|
91
|
+
expect(classifyToolSource('unknown_tool', '', 'see https://host.example:8080 - login')).toBe('generic')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('falls back to path-listing when ≥80% of lines are pure paths (C14)', () => {
|
|
95
|
+
const listing = ['src/index.ts', 'src/main.ts', 'src/util.ts', 'README.md'].join('\n')
|
|
96
|
+
expect(classifyToolSource('unknown_tool', '', listing)).toBe('path-listing')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('never overrides a whitelist hit with content evidence (C15)', () => {
|
|
100
|
+
expect(classifyToolSource('bash', '', 'src/index.ts:12: export const x')).toBe('shell')
|
|
101
|
+
expect(classifyToolSource('glob', '', 'src/index.ts:12: export const x')).toBe('path-listing')
|
|
102
|
+
expect(classifyToolSource('read', '', 'src/index.ts')).toBe('read')
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('extractCommand — input key removed (C11/C12)', () => {
|
|
107
|
+
it('returns empty for an input-only payload (C11)', () => {
|
|
108
|
+
expect(extractCommand('{"input":"arbitrary model text"}')).toBe('')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('still reads the command key (C12)', () => {
|
|
112
|
+
expect(extractCommand('{"command":"npm test"}')).toBe('npm test')
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('still reads cmd/script fallbacks', () => {
|
|
116
|
+
expect(extractCommand('{"cmd":"pnpm build"}')).toBe('pnpm build')
|
|
117
|
+
expect(extractCommand('{"script":"ls"}')).toBe('ls')
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
/** End-to-end dispatch guard for the misroute fixes: a `glob` result and an
|
|
122
|
+
* `execute_sql` result must not land on the search reducer even when they
|
|
123
|
+
* exceed every form gate. */
|
|
124
|
+
describe('toolclass dispatch integration', () => {
|
|
125
|
+
const paths = Array.from({ length: 200 }, (_, index) => `pkg/dir${String(index)}/file${String(index)}.ts`)
|
|
126
|
+
const globText = paths.join('\n')
|
|
127
|
+
|
|
128
|
+
it('routes a large glob result away from search-salience (task_11)', () => {
|
|
129
|
+
const output = reduceFreshToolResult({
|
|
130
|
+
toolName: 'glob',
|
|
131
|
+
argumentsText: '{}',
|
|
132
|
+
text: globText,
|
|
133
|
+
budgetChars: 4_000,
|
|
134
|
+
sourceRef: 'session://probe/glob',
|
|
135
|
+
isError: false,
|
|
136
|
+
})
|
|
137
|
+
expect(output).not.toBeNull()
|
|
138
|
+
expect(output!.reducer).not.toBe('search-by-file')
|
|
139
|
+
expect(output!.reducer).not.toBe('search-salience')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('routes a large mcp web_search result away from the search reducer (C1/AD1)', () => {
|
|
143
|
+
const web = Array.from({ length: 60 }, (_, index) =>
|
|
144
|
+
`- [Result ${String(index)}](https://example.com/${String(index)}) — a summary paragraph of the ${String(index)}th hit.`).join('\n')
|
|
145
|
+
const output = reduceFreshToolResult({
|
|
146
|
+
toolName: 'mcp__web__web_search',
|
|
147
|
+
argumentsText: '{}',
|
|
148
|
+
text: web,
|
|
149
|
+
budgetChars: 2_000,
|
|
150
|
+
sourceRef: 'session://probe/web',
|
|
151
|
+
isError: false,
|
|
152
|
+
})
|
|
153
|
+
expect(output).not.toBeNull()
|
|
154
|
+
expect(output!.reducer).not.toBe('search-by-file')
|
|
155
|
+
})
|
|
156
|
+
})
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings-seat contract pin for dsh-context-compression-improved's client.
|
|
3
|
+
*
|
|
4
|
+
* This spec locks WHERE the compression settings panel mounts: exactly ONE
|
|
5
|
+
* seat — the standalone `settings.section` entry (设置 → 上下文压缩) — and
|
|
6
|
+
* explicitly NOT the Plugins-section surfaces, and NOT a `shell.overlay` float
|
|
7
|
+
* (the retired review panel's seat was removed with the gate). History this
|
|
8
|
+
* pins against: the 0.1.5 line first lost every entry (a lazy `ctx.get` of
|
|
9
|
+
* locale/settingsScope raced the settings client and apply bailed), then showed
|
|
10
|
+
* the panel twice (item card + tab on top of the standalone section). Both were
|
|
11
|
+
* fixed by the declarative-inject + single-section shape below. When a future
|
|
12
|
+
* DSH line moves the seat again, migrate src/client/index.ts AND this file
|
|
13
|
+
* together.
|
|
14
|
+
*/
|
|
15
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
16
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
17
|
+
import { apply, inject } from '../src/client/index.ts'
|
|
18
|
+
import { ContextCompressionSettingsSection } from '../src/client/CompressionProfileSelector.tsx'
|
|
19
|
+
|
|
20
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
21
|
+
IconChevronDownOutline14: () => null,
|
|
22
|
+
Menu: () => null,
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
interface CapturedRegistration {
|
|
26
|
+
readonly slot: string
|
|
27
|
+
readonly options: Record<string, unknown>
|
|
28
|
+
readonly component: unknown
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Drive apply against a stub host and capture every slot registration.
|
|
33
|
+
* @param options - `registerThrows` models an older host that does not declare
|
|
34
|
+
* the seat: the slot boundary rejects the registration, exactly the shape the
|
|
35
|
+
* 0.1.2-era hosts had.
|
|
36
|
+
*/
|
|
37
|
+
function collectRegistrations(
|
|
38
|
+
options: { readonly registerThrows?: boolean } = {},
|
|
39
|
+
): { declared: string[]; registrations: CapturedRegistration[] } {
|
|
40
|
+
const declared: string[] = []
|
|
41
|
+
const registrations: CapturedRegistration[] = []
|
|
42
|
+
const ctx = {
|
|
43
|
+
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
44
|
+
settingsScope: { bind: vi.fn(() => ({}) as never) },
|
|
45
|
+
slots: {
|
|
46
|
+
inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
47
|
+
declared.push(slot)
|
|
48
|
+
const result = factory()
|
|
49
|
+
const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
|
|
50
|
+
? (result as Generator<() => void>)
|
|
51
|
+
: [result as () => void]
|
|
52
|
+
for (const step of steps) { void step }
|
|
53
|
+
return () => {}
|
|
54
|
+
},
|
|
55
|
+
register: (record: Record<string, unknown>, component: unknown) => {
|
|
56
|
+
if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
|
|
57
|
+
registrations.push({ slot: String(record['name']), options: record, component })
|
|
58
|
+
return () => {}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
apply(ctx as unknown as ClientContext)
|
|
63
|
+
return { declared, registrations }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('settings-seat contract (standalone settings.section + input-bar session binder)', () => {
|
|
67
|
+
it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
|
|
68
|
+
expect(inject).toEqual(['slots', 'locale', 'settingsScope'])
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('injects exactly two seats: the settings.section panel + the input-bar session binder', () => {
|
|
72
|
+
const { declared, registrations } = collectRegistrations()
|
|
73
|
+
expect(declared).toEqual(['settings.section', 'conversation.input.left'])
|
|
74
|
+
expect(registrations).toHaveLength(2)
|
|
75
|
+
expect(registrations[0]!.slot).toBe('settings.section')
|
|
76
|
+
expect(registrations[1]!.slot).toBe('conversation.input.left')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
|
|
80
|
+
const { declared } = collectRegistrations()
|
|
81
|
+
expect(declared).not.toContain('shell.overlay')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('pins the section identity (id/order/label/locale) and the panel component', () => {
|
|
85
|
+
const { registrations } = collectRegistrations()
|
|
86
|
+
const { options, component } = registrations[0]!
|
|
87
|
+
expect(options['id']).toBe('context-compression')
|
|
88
|
+
expect(options['order']).toBe(17)
|
|
89
|
+
expect(options['locale']).toBe('context-compression')
|
|
90
|
+
expect((options['label'] as () => string)()).toBe('nav')
|
|
91
|
+
expect(typeof options['inject']).toBe('function')
|
|
92
|
+
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
93
|
+
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'saveIntentSummary', 'saveMonitorPanel', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
94
|
+
expect(component).toBe(ContextCompressionSettingsSection)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('pins the input-bar binder: invisible component, inject captures the bare sessionId', () => {
|
|
98
|
+
const { registrations } = collectRegistrations()
|
|
99
|
+
const inputSeat = registrations[1]!
|
|
100
|
+
expect(inputSeat.options['id']).toBe('context-compression-session-bind')
|
|
101
|
+
expect(inputSeat.options['order']).toBe(170)
|
|
102
|
+
expect(typeof inputSeat.options['inject']).toBe('function')
|
|
103
|
+
const face = (inputSeat.options['inject'] as (sessionId: string) => Record<string, unknown>)('sess-42')
|
|
104
|
+
expect(face).toEqual({})
|
|
105
|
+
expect(inputSeat.component).toBeTypeOf('function')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('never adds a Plugins-section card or tab alongside the standalone section', () => {
|
|
109
|
+
const { declared } = collectRegistrations()
|
|
110
|
+
expect(declared).not.toContain('settings.plugins.tab')
|
|
111
|
+
expect(declared).not.toContain('settings.plugin.item')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('survives an older host that does not declare the seat, warning instead of crashing', () => {
|
|
115
|
+
// Cross-version tolerance: a host without this seat rejects the
|
|
116
|
+
// registration at the slot boundary. apply() must swallow that and warn —
|
|
117
|
+
// the historical failure mode was apply() bailing out, which silently took
|
|
118
|
+
// EVERY settings entry down with it.
|
|
119
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
120
|
+
try {
|
|
121
|
+
const { declared } = collectRegistrations({ registerThrows: true })
|
|
122
|
+
// It tried both seats (so the degradation is "loud", not a silent no-op)…
|
|
123
|
+
expect(declared).toEqual(['settings.section', 'conversation.input.left'])
|
|
124
|
+
// …and the rejection never escaped apply().
|
|
125
|
+
expect(warn).toHaveBeenCalled()
|
|
126
|
+
} finally {
|
|
127
|
+
warn.mockRestore()
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
})
|