dsh-context-compression-improved 0.9.7 → 0.9.9-beta.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.
- package/LICENSE +21 -21
- package/README.md +15 -98
- package/README.zh.md +14 -92
- package/THIRD_PARTY_NOTICES.md +32 -14
- package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +27 -27
- package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +2 -2
- package/{packages/selector/lib → lib}/client.d.ts +16 -0
- package/{packages/selector/lib → lib}/client.js +393 -116
- package/{packages/selector/lib → lib}/index.js +829 -10
- package/{packages/selector/lib → lib}/invariant.js +2 -1
- package/{packages/selector/lib → lib}/pruner.d.ts +1 -1
- package/{packages/selector/lib → lib}/pruner.js +77 -983
- package/lib/savings-integral.js +4515 -0
- package/{packages/selector/lib → lib}/tail-trim.js +2 -90
- package/lib/tool-result.js +150 -0
- package/package.json +129 -116
- package/screenshots.json +3 -6
- package/.gitattributes +0 -2
- package/.githooks/pre-push +0 -37
- package/.github/workflows/ci.yml +0 -39
- package/CHANGELOG.de.md +0 -580
- package/CHANGELOG.es.md +0 -588
- package/CHANGELOG.fr.md +0 -576
- package/CHANGELOG.it.md +0 -577
- package/CHANGELOG.ja.md +0 -261
- package/CHANGELOG.ko.md +0 -254
- package/CHANGELOG.md +0 -532
- package/CHANGELOG.ru.md +0 -554
- package/CHANGELOG.zh.md +0 -236
- package/CONTRIBUTING.md +0 -22
- package/README.de.md +0 -96
- package/README.es.md +0 -96
- package/README.fr.md +0 -96
- package/README.it.md +0 -96
- package/README.ja.md +0 -102
- package/README.ko.md +0 -102
- package/README.ru.md +0 -96
- package/SECURITY.md +0 -18
- package/assets/board.png +0 -0
- package/assets/context.png +0 -0
- package/docs/assets/context-compression-selector-profiles.jpg +0 -0
- package/docs/assets/context-compression-selector-settings.png +0 -0
- package/docs/compat-0.1.5-report.md +0 -77
- package/docs/installation.de.md +0 -104
- package/docs/installation.es.md +0 -104
- package/docs/installation.fr.md +0 -104
- package/docs/installation.it.md +0 -104
- package/docs/installation.ja.md +0 -78
- package/docs/installation.ko.md +0 -78
- package/docs/installation.md +0 -103
- package/docs/installation.ru.md +0 -104
- package/docs/installation.zh.md +0 -100
- package/docs/repair-log.md +0 -657
- package/eslint.config.js +0 -30
- package/packages/selector/LICENSE +0 -21
- package/packages/selector/README.md +0 -26
- package/packages/selector/README.zh.md +0 -24
- package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
- package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
- package/packages/selector/lib/config.js +0 -1777
- package/packages/selector/lib/host-generation.js +0 -62
- package/packages/selector/lib/style.css +0 -350
- package/packages/selector/package.json +0 -174
- package/packages/selector/screenshots.json +0 -3
- package/packages/selector/src/client/CompressionProfileControls.tsx +0 -293
- package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
- package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -85
- package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
- package/packages/selector/src/client/EstimatorControls.tsx +0 -277
- package/packages/selector/src/client/bridge-scope.ts +0 -125
- package/packages/selector/src/client/decode.ts +0 -57
- package/packages/selector/src/client/index.ts +0 -421
- package/packages/selector/src/client/locales/de.ts +0 -142
- package/packages/selector/src/client/locales/es.ts +0 -142
- package/packages/selector/src/client/locales/fr.ts +0 -142
- package/packages/selector/src/client/locales/it.ts +0 -142
- package/packages/selector/src/client/locales/ja.ts +0 -142
- package/packages/selector/src/client/locales/ko.ts +0 -142
- package/packages/selector/src/client/locales/ru.ts +0 -142
- package/packages/selector/src/client/locales.ts +0 -284
- package/packages/selector/src/client/monitor-fab.ts +0 -349
- package/packages/selector/src/client/preset-options.ts +0 -88
- package/packages/selector/src/client/savings-card.tsx +0 -150
- package/packages/selector/src/client/scope-face.ts +0 -24
- package/packages/selector/src/client/settings-section.tsx +0 -140
- package/packages/selector/src/compat/host-generation.ts +0 -96
- package/packages/selector/src/compat/llm-messages.ts +0 -50
- package/packages/selector/src/compat/settings-lease.ts +0 -108
- package/packages/selector/src/compat/tool-result.ts +0 -91
- package/packages/selector/src/css-modules.d.ts +0 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
- package/packages/selector/src/estimator-catalog.ts +0 -104
- package/packages/selector/src/index.ts +0 -655
- package/packages/selector/src/invariant.ts +0 -113
- package/packages/selector/src/preset-overlay.ts +0 -749
- package/packages/selector/src/profiles.ts +0 -431
- package/packages/selector/src/pruner/content.ts +0 -198
- package/packages/selector/src/pruner/session.ts +0 -97
- package/packages/selector/src/pruner/state.ts +0 -61
- package/packages/selector/src/pruner/tuning.ts +0 -23
- package/packages/selector/src/pruner/types.ts +0 -78
- package/packages/selector/src/pruner.ts +0 -2868
- package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
- package/packages/selector/src/runtime/audit.ts +0 -303
- package/packages/selector/src/runtime/config.ts +0 -756
- package/packages/selector/src/runtime/custom-policy.ts +0 -278
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
- package/packages/selector/src/runtime/measurement.ts +0 -444
- package/packages/selector/src/runtime/monitor.ts +0 -235
- package/packages/selector/src/runtime/reducers.ts +0 -1754
- package/packages/selector/src/runtime/retrieve.ts +0 -484
- package/packages/selector/src/runtime/savings-projection.ts +0 -226
- package/packages/selector/src/runtime/savings.ts +0 -417
- package/packages/selector/src/runtime/session-events.ts +0 -30
- package/packages/selector/src/runtime/summary-command.ts +0 -127
- package/packages/selector/src/runtime/tail-trim.ts +0 -176
- package/packages/selector/src/runtime/token-count.ts +0 -72
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -81
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
- 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/src/runtime/tokenpilot/locator.ts +0 -128
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
- package/packages/selector/src/runtime/toolclass.ts +0 -103
- package/packages/selector/src/runtime/types.ts +0 -365
- package/packages/selector/src/runtime/value.ts +0 -48
- package/packages/selector/src/settings-bridge.ts +0 -175
- package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
- package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
- package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
- package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
- package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
- package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
- package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -199
- package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
- package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +0 -138
- package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
- package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
- package/packages/selector/tests/profiles.client.spec.tsx +0 -436
- package/packages/selector/tests/public/package-contract.client.spec.ts +0 -86
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
- package/packages/selector/tests/runtime/audit.spec.ts +0 -275
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
- package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
- 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/jsonl-reducer.spec.ts +0 -79
- package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
- package/packages/selector/tests/runtime/monitor.spec.ts +0 -301
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2782
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
- package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
- package/packages/selector/tests/runtime/savings.spec.ts +0 -139
- package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
- package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
- package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
- package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -119
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
- package/packages/selector/tests/runtime/value.spec.ts +0 -23
- package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
- package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
- package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
- package/packages/selector/tests/support/mock-adapter.ts +0 -37
- package/packages/selector/tests/support/ui-primitives.tsx +0 -34
- package/packages/selector/tsconfig.json +0 -11
- package/packages/selector/tsdown.client.config.ts +0 -102
- package/packages/selector/tsdown.config.ts +0 -20
- package/pnpm-workspace.yaml +0 -72
- package/scripts/capture-profile-baseline.mjs +0 -42
- package/scripts/cell-browser-e2e.mjs +0 -354
- package/scripts/generate-tokenizer-fixtures.py +0 -81
- package/scripts/generate-vision-fixtures.py +0 -208
- package/scripts/hosts.mjs +0 -77
- package/scripts/packed-components-smoke.mjs +0 -763
- package/scripts/packed-install-e2e.mjs +0 -1346
- package/scripts/sync-hosts.mjs +0 -174
- package/scripts/toolclass-corpus-replay.mjs +0 -281
- package/scripts/verify-release.mjs +0 -335
- package/tests/TEST_INVENTORY.md +0 -41
- package/tsconfig.base.json +0 -18
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -15
- package/vitest.built.config.ts +0 -9
- package/vitest.config.ts +0 -46
- /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{packages/selector/lib → lib}/index.d.ts +0 -0
- /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
- /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
import { apply } from '../src/client/index.ts'
|
|
5
|
-
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
6
|
-
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 0.1.7 contract: the compression document rides the entry config as ONE
|
|
10
|
-
* volatile whole-object field, so every write commits the full document
|
|
11
|
-
* through `configForms.set('settings', doc)`. The sibling-safety that the old
|
|
12
|
-
* path-addressed settings service provided is now enforced CLIENT-side:
|
|
13
|
-
* `planPresetOptionsOps` is still computed against the current doc and applied
|
|
14
|
-
* locally before the commit, so a second field write never erases the first.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
interface FormStub {
|
|
18
|
-
form: Record<string, unknown>
|
|
19
|
-
/** Whole-doc commits the fake Host accepted. */
|
|
20
|
-
readonly commits: Record<string, unknown>[]
|
|
21
|
-
/** Whole-doc writes the fake Host refused. */
|
|
22
|
-
readonly refused: Record<string, unknown>[]
|
|
23
|
-
readonly snapshot: () => Record<string, unknown>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function createFormStub(initial: ContextCompressionSettings, commit = true): FormStub {
|
|
27
|
-
let revision = 1
|
|
28
|
-
let value: Record<string, unknown> = { settings: structuredClone(initial) as unknown as Record<string, unknown> }
|
|
29
|
-
const commits: Record<string, unknown>[] = []
|
|
30
|
-
const refused: Record<string, unknown>[] = []
|
|
31
|
-
const listeners = new Set<() => void>()
|
|
32
|
-
return {
|
|
33
|
-
commits,
|
|
34
|
-
refused,
|
|
35
|
-
snapshot: () => structuredClone(value.settings as Record<string, unknown>),
|
|
36
|
-
form: {
|
|
37
|
-
getSnapshot: () => ({
|
|
38
|
-
status: 'ready' as const,
|
|
39
|
-
value: value as unknown as Record<string, unknown>,
|
|
40
|
-
revision,
|
|
41
|
-
writable: true,
|
|
42
|
-
base: undefined,
|
|
43
|
-
user: undefined,
|
|
44
|
-
mode: 'host' as const,
|
|
45
|
-
}),
|
|
46
|
-
subscribe: (listener: () => void) => {
|
|
47
|
-
listeners.add(listener)
|
|
48
|
-
return () => { listeners.delete(listener) }
|
|
49
|
-
},
|
|
50
|
-
set: (_field: string, doc: unknown) => {
|
|
51
|
-
if (!commit) {
|
|
52
|
-
refused.push(doc as Record<string, unknown>)
|
|
53
|
-
return Promise.resolve(false)
|
|
54
|
-
}
|
|
55
|
-
value = { settings: structuredClone(doc) as unknown as Record<string, unknown> }
|
|
56
|
-
revision += 1
|
|
57
|
-
commits.push({ settings: structuredClone(doc) as unknown as Record<string, unknown> })
|
|
58
|
-
for (const listener of listeners) listener()
|
|
59
|
-
return Promise.resolve(true)
|
|
60
|
-
},
|
|
61
|
-
unset: () => Promise.resolve(false),
|
|
62
|
-
},
|
|
63
|
-
} as FormStub & { form: Record<string, unknown> }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const DEFAULT_CUSTOM = {
|
|
67
|
-
version: 1,
|
|
68
|
-
unit: 'tokens',
|
|
69
|
-
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
70
|
-
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
71
|
-
history: {
|
|
72
|
-
enabled: true,
|
|
73
|
-
trigger: 16_384,
|
|
74
|
-
keepRecentTurns: 2,
|
|
75
|
-
keepRecent: 16_384,
|
|
76
|
-
minReclaim: 8_192,
|
|
77
|
-
},
|
|
78
|
-
prefixPolicy: 'pressure-break',
|
|
79
|
-
} as const satisfies ContextCompressionSettings['custom']
|
|
80
|
-
|
|
81
|
-
function bindInjected(
|
|
82
|
-
presetOptions: ContextCompressionSettings['presetOptions'],
|
|
83
|
-
commit = true,
|
|
84
|
-
): {
|
|
85
|
-
injected: CompressionSelectorInjected
|
|
86
|
-
stub: FormStub
|
|
87
|
-
} {
|
|
88
|
-
const settings: ContextCompressionSettings = {
|
|
89
|
-
profile: 'tokenpilot-inspired',
|
|
90
|
-
custom: structuredClone(DEFAULT_CUSTOM),
|
|
91
|
-
autoCompact: { thresholdPercent: 80 },
|
|
92
|
-
codeSkeleton: { enabled: false },
|
|
93
|
-
intentSummary: { enabled: false },
|
|
94
|
-
...(presetOptions === undefined ? {} : { presetOptions }),
|
|
95
|
-
}
|
|
96
|
-
const stub = createFormStub(settings, commit)
|
|
97
|
-
let options: Record<string, unknown> | undefined
|
|
98
|
-
const ctx = {
|
|
99
|
-
slots: {
|
|
100
|
-
inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
101
|
-
const result = factory()
|
|
102
|
-
return typeof result === 'function' ? result : () => {}
|
|
103
|
-
},
|
|
104
|
-
register: (registerOptions: Record<string, unknown>) => {
|
|
105
|
-
// The R4 overlay registration rides the same slots service; only the
|
|
106
|
-
// settings card carries the inject factory these tests drive.
|
|
107
|
-
if (registerOptions.name === 'settings.section') options = registerOptions
|
|
108
|
-
return () => {}
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
// apply consumes the services through their declarative-inject faces
|
|
112
|
-
// (ctx.locale / ctx.configForms), the same shape cordis binds on the host.
|
|
113
|
-
locale: { bind: () => (key: string) => key, register: () => {} },
|
|
114
|
-
configForms: { get: () => (stub.form as unknown as { getSnapshot(): unknown }) },
|
|
115
|
-
// Scoped sub-inject seam: host resolves configForms and fires the arm
|
|
116
|
-
inject: (services: string[], cb: (service: unknown) => void) => {
|
|
117
|
-
if (services.includes('configForms')) cb(ctx.configForms)
|
|
118
|
-
},
|
|
119
|
-
}
|
|
120
|
-
apply(ctx as never)
|
|
121
|
-
if (options === undefined) throw new Error('the settings card never registered')
|
|
122
|
-
const factory = options['inject'] as () => CompressionSelectorInjected
|
|
123
|
-
return { injected: factory(), stub }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
describe('presetOptions writes commit the whole doc through configForms', () => {
|
|
127
|
-
it('keeps the estimator channel when a provider is chosen afterwards', async () => {
|
|
128
|
-
const { injected, stub } = bindInjected({ estimatorMode: 'host' })
|
|
129
|
-
await injected.savePresetOptions({ estimatorProvider: 'local-35b' })
|
|
130
|
-
expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'host', estimatorProvider: 'local-35b' })
|
|
131
|
-
expect(stub.commits.length).toBe(1)
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('treats a retired review-gate patch as a no-op instead of a write', async () => {
|
|
135
|
-
const { injected, stub } = bindInjected({ estimatorMode: 'host' })
|
|
136
|
-
// The patch surface no longer carries these keys, and the decoders accept
|
|
137
|
-
// them only so a legacy document keeps loading. Cast past the removed type
|
|
138
|
-
// so the test pins the RUNTIME behaviour: nothing is written.
|
|
139
|
-
await injected.savePresetOptions({
|
|
140
|
-
reviewMode: true,
|
|
141
|
-
reviewTimeoutTurns: 8,
|
|
142
|
-
cacheHitDiscountAlpha: 0.2,
|
|
143
|
-
reviewHighImpactTokens: 6000,
|
|
144
|
-
} as unknown as Parameters<typeof injected.savePresetOptions>[0])
|
|
145
|
-
expect(stub.commits.length).toBe(0)
|
|
146
|
-
expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'host' })
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('never loses sibling overrides across whole-doc commits', async () => {
|
|
150
|
-
const { injected, stub } = bindInjected({
|
|
151
|
-
estimatorMode: 'direct',
|
|
152
|
-
estimatorBaseUrl: 'http://192.168.100.242:8200',
|
|
153
|
-
dedupeToolResults: false,
|
|
154
|
-
readState: false,
|
|
155
|
-
})
|
|
156
|
-
await injected.savePresetOptions({ estimatorModel: 'Qwen3.6-35B-A3B' })
|
|
157
|
-
await injected.savePresetOptions({ estimatorProvider: 'local-35b' })
|
|
158
|
-
expect(stub.snapshot()['presetOptions']).toEqual({
|
|
159
|
-
estimatorMode: 'direct',
|
|
160
|
-
estimatorBaseUrl: 'http://192.168.100.242:8200',
|
|
161
|
-
dedupeToolResults: false,
|
|
162
|
-
readState: false,
|
|
163
|
-
estimatorModel: 'Qwen3.6-35B-A3B',
|
|
164
|
-
estimatorProvider: 'local-35b',
|
|
165
|
-
})
|
|
166
|
-
// Two user actions, two whole-doc commits.
|
|
167
|
-
expect(stub.commits.length).toBe(2)
|
|
168
|
-
for (const doc of stub.commits) {
|
|
169
|
-
// Each commit carries the complete document under the volatile field.
|
|
170
|
-
expect(Object.keys(doc)).toEqual(['settings'])
|
|
171
|
-
}
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('clears exactly the field a patch names with undefined', async () => {
|
|
175
|
-
const { injected, stub } = bindInjected({ estimatorMode: 'direct', estimatorApiKey: 'sk-stored' })
|
|
176
|
-
await injected.savePresetOptions({ estimatorApiKey: undefined })
|
|
177
|
-
expect(stub.snapshot()['presetOptions']).toEqual({ estimatorMode: 'direct' })
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
it('writes nothing when the patch already matches the stored section', async () => {
|
|
181
|
-
const { injected, stub } = bindInjected({ estimatorMode: 'host', estimatorProvider: 'local-35b' })
|
|
182
|
-
await injected.savePresetOptions({ estimatorMode: 'host' })
|
|
183
|
-
expect(stub.commits.length).toBe(0)
|
|
184
|
-
expect(stub.refused.length).toBe(0)
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('reports a save the Host did not commit', async () => {
|
|
188
|
-
const { injected } = bindInjected({ estimatorMode: 'host' }, false)
|
|
189
|
-
await expect(injected.savePresetOptions({ estimatorProvider: 'local-35b' }))
|
|
190
|
-
.rejects.toThrow(/were not saved/)
|
|
191
|
-
})
|
|
192
|
-
})
|
|
@@ -1,200 +0,0 @@
|
|
|
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 { type SettingsNamespace } from '@deepseek-ai/dsh-settings'
|
|
18
|
-
import { LegacySettingsProvider } from './helpers/legacy-settings/index.ts'
|
|
19
|
-
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
20
|
-
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
|
|
21
|
-
import TokenMeter from '@deepseek-ai/dsh-token-meter'
|
|
22
|
-
import ToolRuntime from '@deepseek-ai/dsh-tools'
|
|
23
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
24
|
-
import { apply } from '../src/index.ts'
|
|
25
|
-
|
|
26
|
-
const CORDIS_ORIGINAL = Symbol.for('cordis.original')
|
|
27
|
-
type Traceable = { [CORDIS_ORIGINAL]?: unknown }
|
|
28
|
-
|
|
29
|
-
let ctx: Context | undefined
|
|
30
|
-
let root: string | undefined
|
|
31
|
-
|
|
32
|
-
afterEach(async () => {
|
|
33
|
-
await ctx?.fiber.dispose()
|
|
34
|
-
ctx = undefined
|
|
35
|
-
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
|
36
|
-
root = undefined
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
class MemorySettings extends LegacySettingsProvider {
|
|
40
|
-
readonly writable = true
|
|
41
|
-
|
|
42
|
-
protected load(): Promise<Record<string, unknown>> {
|
|
43
|
-
return Promise.resolve({})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
protected persist(_ns: SettingsNamespace, _section: Record<string, unknown>): Promise<void> {
|
|
47
|
-
return Promise.resolve()
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface CustomSettings {
|
|
52
|
-
profile: string
|
|
53
|
-
custom: {
|
|
54
|
-
history: { trigger: number }
|
|
55
|
-
tailTrim: { enabled: boolean; trigger: number }
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function createPresetRoot(): Promise<string> {
|
|
60
|
-
root = await mkdtemp(join(tmpdir(), 'dsh-selector-loader-e2e-'))
|
|
61
|
-
const marker = join(root, 'marker.mjs')
|
|
62
|
-
await writeFile(marker, 'export function apply() {}\n')
|
|
63
|
-
const source = `- id: source-marker\n name: ${JSON.stringify(marker)}\n`
|
|
64
|
-
for (const id of ['standard', 'custom', 'minimal']) {
|
|
65
|
-
const directory = join(root, id)
|
|
66
|
-
await mkdir(directory)
|
|
67
|
-
await writeFile(join(directory, COMPOSITION_FILE), source)
|
|
68
|
-
}
|
|
69
|
-
return root
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function harness(): Promise<Context> {
|
|
73
|
-
const presets = await createPresetRoot()
|
|
74
|
-
const runtime = new Context()
|
|
75
|
-
runtime.baseUrl = `${pathToFileURL(presets).href}/`
|
|
76
|
-
await runtime.plugin(Loader).await()
|
|
77
|
-
runtime.loader.builtins.include = Include
|
|
78
|
-
runtime.loader.builtins.group = Group
|
|
79
|
-
await runtime.plugin(LlmRuntime).await()
|
|
80
|
-
await runtime.plugin(SessionStore).await()
|
|
81
|
-
await runtime.plugin(SystemPrompt).await()
|
|
82
|
-
await runtime.plugin(ToolRuntime).await()
|
|
83
|
-
await runtime.plugin(AgentRegistry).await()
|
|
84
|
-
await runtime.plugin(AgentLoop).await()
|
|
85
|
-
await runtime.plugin(CommandRuntime).await()
|
|
86
|
-
await runtime.plugin(SessionProjectionRegistry).await()
|
|
87
|
-
await runtime.plugin(TokenMeter).await()
|
|
88
|
-
await runtime.plugin(MemorySettings).await()
|
|
89
|
-
await runtime.plugin(AgentPresets, {
|
|
90
|
-
default: 'standard',
|
|
91
|
-
roots: [{ path: presets, trust: 'system' }],
|
|
92
|
-
includeShippedRoot: false,
|
|
93
|
-
includeUserRoot: false,
|
|
94
|
-
})
|
|
95
|
-
await runtime.plugin({
|
|
96
|
-
apply: (selectorCtx) => {
|
|
97
|
-
apply(selectorCtx, { presetOverlay: true })
|
|
98
|
-
},
|
|
99
|
-
}).await()
|
|
100
|
-
ctx = runtime
|
|
101
|
-
return runtime
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function agentOn(runtime: Context, sessionId: string, preset: string): Promise<Agent> {
|
|
105
|
-
const handle = await runtime.agents.create({
|
|
106
|
-
sessionId: SessionId(sessionId),
|
|
107
|
-
setup: async agentCtx => void await runtime.agentPresets.mount(agentCtx, preset),
|
|
108
|
-
})
|
|
109
|
-
return handle.agent
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function hasCompressionRetrieve(runtime: Context, agent: Agent): boolean {
|
|
113
|
-
return runtime.tools.get('context_compression_retrieve', scopeOf(agent.ctx)) !== undefined
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function hasCompactCommand(runtime: Context, agent: Agent): boolean {
|
|
117
|
-
return runtime.commands.list(agent).some(command => command.name === 'compact')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function expectCompleteCompressionStack(runtime: Context, agent: Agent): void {
|
|
121
|
-
expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeDefined()
|
|
122
|
-
expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeDefined()
|
|
123
|
-
expect(hasCompressionRetrieve(runtime, agent)).toBe(true)
|
|
124
|
-
expect(hasCompactCommand(runtime, agent)).toBe(true)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function expectNoCompressionStack(runtime: Context, agent: Agent): void {
|
|
128
|
-
expect(runtime.agentPresets.serviceFor(agent, 'toolResultPruner')).toBeUndefined()
|
|
129
|
-
expect(runtime.agentPresets.serviceFor(agent, 'compaction')).toBeUndefined()
|
|
130
|
-
expect(hasCompressionRetrieve(runtime, agent)).toBe(false)
|
|
131
|
-
expect(hasCompactCommand(runtime, agent)).toBe(false)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
describe('standalone selector Bundle through the real preset Loader', () => {
|
|
135
|
-
it('mounts the complete stack without changing source preset authoring', async () => {
|
|
136
|
-
const runtime = await harness()
|
|
137
|
-
const source = await runtime.agentPresets.resolve('standard')
|
|
138
|
-
const sourceText = await runtime.agentPresets.read('standard')
|
|
139
|
-
|
|
140
|
-
const agent = await agentOn(runtime, 'selector-loader-standard', 'standard')
|
|
141
|
-
|
|
142
|
-
expectCompleteCompressionStack(runtime, agent)
|
|
143
|
-
expect((await runtime.agentPresets.resolve('standard')).path).toBe(source.path)
|
|
144
|
-
expect(await runtime.agentPresets.read('standard')).toBe(sourceText)
|
|
145
|
-
expect(sourceText).not.toContain('tool-result-pruner')
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('keeps compression across preset changes and excludes only exact Minimal', async () => {
|
|
149
|
-
const runtime = await harness()
|
|
150
|
-
const agent = await agentOn(runtime, 'selector-loader-switch', 'standard')
|
|
151
|
-
expectCompleteCompressionStack(runtime, agent)
|
|
152
|
-
|
|
153
|
-
await runtime.agentPresets.recompose(agent.ctx, 'minimal')
|
|
154
|
-
expectNoCompressionStack(runtime, agent)
|
|
155
|
-
|
|
156
|
-
// `custom` deliberately contains the same source rows as Minimal. Its id,
|
|
157
|
-
// not its copied contents, decides the one documented exception.
|
|
158
|
-
await runtime.agentPresets.recompose(agent.ctx, 'custom')
|
|
159
|
-
expectCompleteCompressionStack(runtime, agent)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('gives a child the parent\'s exact compression service instances', async () => {
|
|
163
|
-
const runtime = await harness()
|
|
164
|
-
const parent = await agentOn(runtime, 'selector-loader-parent', 'standard')
|
|
165
|
-
const childHandle = await runtime.agents.create({
|
|
166
|
-
sessionId: SessionId('selector-loader-child'),
|
|
167
|
-
setup: childCtx => void runtime.agentPresets.composeFrom(childCtx, parent.ctx),
|
|
168
|
-
})
|
|
169
|
-
const child = childHandle.agent
|
|
170
|
-
|
|
171
|
-
const parentPruner = runtime.agentPresets.serviceFor(parent, 'toolResultPruner')
|
|
172
|
-
const childPruner = runtime.agentPresets.serviceFor(child, 'toolResultPruner')
|
|
173
|
-
const parentCompaction = runtime.agentPresets.serviceFor(parent, 'compaction')
|
|
174
|
-
const childCompaction = runtime.agentPresets.serviceFor(child, 'compaction')
|
|
175
|
-
expect(parentPruner).toBeDefined()
|
|
176
|
-
expect(parentCompaction).toBeDefined()
|
|
177
|
-
expect(Object.is(
|
|
178
|
-
(childPruner as Traceable)[CORDIS_ORIGINAL],
|
|
179
|
-
(parentPruner as Traceable)[CORDIS_ORIGINAL],
|
|
180
|
-
)).toBe(true)
|
|
181
|
-
expect(Object.is(
|
|
182
|
-
(childCompaction as Traceable)[CORDIS_ORIGINAL],
|
|
183
|
-
(parentCompaction as Traceable)[CORDIS_ORIGINAL],
|
|
184
|
-
)).toBe(true)
|
|
185
|
-
expect(hasCompressionRetrieve(runtime, child)).toBe(true)
|
|
186
|
-
expect(hasCompactCommand(runtime, child)).toBe(true)
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
it('carries the daily Custom defaults on the bundle entry config schema', async () => {
|
|
190
|
-
// 0.1.7: there is no plugin-owned settings row publishing defaults — the
|
|
191
|
-
// volatile `settings` field's schema defaults ARE the daily Custom doc the
|
|
192
|
-
// loader resolves into every composition.
|
|
193
|
-
const settings = (Config({ presetOverlay: true }).settings as unknown as {
|
|
194
|
-
get(): CustomSettings
|
|
195
|
-
}).get()
|
|
196
|
-
|
|
197
|
-
expect(settings.custom.history.trigger).toBe(500_000)
|
|
198
|
-
expect(settings.custom.tailTrim).toEqual({ enabled: false, trigger: 700_000 })
|
|
199
|
-
})
|
|
200
|
-
})
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { access, mkdir, mkdtemp, readFile, readdir, rm, stat, utimes, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { dirname, join } from 'node:path'
|
|
4
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
|
-
import { load } from 'js-yaml'
|
|
6
|
-
import type { AgentPreset } from '@deepseek-ai/dsh-agent-presets'
|
|
7
|
-
import {
|
|
8
|
-
decorateAgentPresets,
|
|
9
|
-
type CompressionModulePaths,
|
|
10
|
-
type OverlayableAgentPresets,
|
|
11
|
-
type PresetOverlayMetadataIo,
|
|
12
|
-
} from '../src/preset-overlay.ts'
|
|
13
|
-
|
|
14
|
-
const MODULES: CompressionModulePaths = {
|
|
15
|
-
compactionBasic: '/opt/context-selector/compaction-basic.js',
|
|
16
|
-
commandCompact: '/opt/context-selector/command-compact.js',
|
|
17
|
-
toolResultPruner: '/opt/context-selector/tool-result-pruner.js',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const roots: string[] = []
|
|
21
|
-
|
|
22
|
-
afterEach(async () => {
|
|
23
|
-
await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true, force: true })))
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
async function fixture(): Promise<{
|
|
27
|
-
root: string
|
|
28
|
-
standard: AgentPreset
|
|
29
|
-
minimal: AgentPreset
|
|
30
|
-
}> {
|
|
31
|
-
const root = await mkdtemp(join(tmpdir(), 'dsh-selector-overlay-test-'))
|
|
32
|
-
roots.push(root)
|
|
33
|
-
const standardPath = join(root, 'standard', 'agent.cordis.yml')
|
|
34
|
-
const minimalPath = join(root, 'minimal', 'agent.cordis.yml')
|
|
35
|
-
await mkdir(dirname(standardPath), { recursive: true })
|
|
36
|
-
await mkdir(dirname(minimalPath), { recursive: true })
|
|
37
|
-
await writeFile(standardPath, [
|
|
38
|
-
'- id: persona',
|
|
39
|
-
" name: '/opt/preset/persona.js'",
|
|
40
|
-
'- id: tool-context-retrieve',
|
|
41
|
-
" name: '@deepseek-ai/dsh-tool-context-retrieve'",
|
|
42
|
-
'- id: compaction',
|
|
43
|
-
' name: cordis:group',
|
|
44
|
-
' group: true',
|
|
45
|
-
' isolate:',
|
|
46
|
-
' compaction: true',
|
|
47
|
-
' toolResultPruner: true',
|
|
48
|
-
' config:',
|
|
49
|
-
' - id: compaction-basic',
|
|
50
|
-
" name: '@deepseek-ai/dsh-compaction-basic'",
|
|
51
|
-
' - id: command-compact',
|
|
52
|
-
" name: '@deepseek-ai/dsh-command-compact'",
|
|
53
|
-
' - id: tool-result-pruner',
|
|
54
|
-
" name: '@deepseek-ai/dsh-compaction-tool-result-pruner'",
|
|
55
|
-
'',
|
|
56
|
-
].join('\n'))
|
|
57
|
-
await writeFile(minimalPath, "- id: persona\n name: '/opt/preset/minimal.js'\n")
|
|
58
|
-
return {
|
|
59
|
-
root,
|
|
60
|
-
standard: { id: 'standard', trust: 'system', path: standardPath },
|
|
61
|
-
minimal: { id: 'minimal', trust: 'system', path: minimalPath },
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
class FakeAgentPresets implements OverlayableAgentPresets {
|
|
66
|
-
constructor(private readonly presets: ReadonlyMap<string, AgentPreset>) {}
|
|
67
|
-
|
|
68
|
-
async resolve(id = 'standard'): Promise<AgentPreset> {
|
|
69
|
-
const preset = this.presets.get(id)
|
|
70
|
-
if (preset === undefined) throw new Error(`unknown preset: ${id}`)
|
|
71
|
-
return preset
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async mount(_agentCtx: unknown, id?: string): Promise<AgentPreset> {
|
|
75
|
-
return await this.resolve(id)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async recompose(_agentCtx: unknown, id: string): Promise<AgentPreset> {
|
|
79
|
-
return await this.resolve(id)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async standingKeyFor(id?: string): Promise<string> {
|
|
83
|
-
return (await this.resolve(id)).path
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async read(id: string): Promise<string> {
|
|
87
|
-
return await readFile((await this.resolve(id)).path, 'utf8')
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function rowsAt(text: string): Array<Record<string, unknown>> {
|
|
92
|
-
const rows = load(text)
|
|
93
|
-
if (!Array.isArray(rows)) throw new TypeError('expected entry list')
|
|
94
|
-
return rows as Array<Record<string, unknown>>
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function flatten(rows: Array<Record<string, unknown>>): Array<Record<string, unknown>> {
|
|
98
|
-
return rows.flatMap((row) => {
|
|
99
|
-
const nested = row.group === true && Array.isArray(row.config)
|
|
100
|
-
? flatten(row.config as Array<Record<string, unknown>>)
|
|
101
|
-
: []
|
|
102
|
-
return [row, ...nested]
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
describe('plugin-owned preset overlay decorator', () => {
|
|
107
|
-
it('enhances only composition operations while authoring sees the source preset', async () => {
|
|
108
|
-
const { root, standard, minimal } = await fixture()
|
|
109
|
-
const presets = new FakeAgentPresets(new Map([
|
|
110
|
-
['standard', standard],
|
|
111
|
-
['minimal', minimal],
|
|
112
|
-
]))
|
|
113
|
-
const installation = decorateAgentPresets(presets, {
|
|
114
|
-
modules: MODULES,
|
|
115
|
-
excludedPresetIds: ['minimal'],
|
|
116
|
-
tempParent: root,
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
expect((await presets.resolve('standard')).path).toBe(standard.path)
|
|
120
|
-
expect(await presets.read('standard')).toBe(await readFile(standard.path, 'utf8'))
|
|
121
|
-
|
|
122
|
-
const mounted = await presets.mount({}, 'standard')
|
|
123
|
-
expect(mounted.path).not.toBe(standard.path)
|
|
124
|
-
expect((await presets.recompose({}, 'standard')).path).toBe(mounted.path)
|
|
125
|
-
expect(await presets.standingKeyFor('standard')).toBe(mounted.path)
|
|
126
|
-
expect((await presets.mount({}, 'minimal')).path).toBe(minimal.path)
|
|
127
|
-
expect((await presets.resolve('standard')).path).toBe(standard.path)
|
|
128
|
-
|
|
129
|
-
const all = flatten(rowsAt(await readFile(mounted.path, 'utf8')))
|
|
130
|
-
expect(all.filter(row => row.id === 'tool-context-retrieve')).toHaveLength(1)
|
|
131
|
-
expect(all.filter(row => row.id === 'compaction')).toHaveLength(1)
|
|
132
|
-
expect(all.filter(row => row.id === 'compaction-basic')).toHaveLength(1)
|
|
133
|
-
expect(all.filter(row => row.id === 'command-compact')).toHaveLength(1)
|
|
134
|
-
expect(all.filter(row => row.id === 'tool-result-pruner')).toHaveLength(1)
|
|
135
|
-
expect(all.find(row => row.id === 'tool-context-retrieve')?.name)
|
|
136
|
-
.toBe('@deepseek-ai/dsh-tool-context-retrieve')
|
|
137
|
-
expect(all.find(row => row.id === 'tool-result-pruner')?.name).toBe(MODULES.toolResultPruner)
|
|
138
|
-
|
|
139
|
-
await installation.dispose()
|
|
140
|
-
expect((await presets.mount({}, 'standard')).path).toBe(standard.path)
|
|
141
|
-
await expect(access(dirname(mounted.path))).rejects.toThrow()
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('keeps direct concurrent resolve outside the operation-local overlay', async () => {
|
|
145
|
-
const { root, standard } = await fixture()
|
|
146
|
-
const presets = new FakeAgentPresets(new Map([['standard', standard]]))
|
|
147
|
-
const installation = decorateAgentPresets(presets, { modules: MODULES, tempParent: root })
|
|
148
|
-
|
|
149
|
-
const [mounted, resolved] = await Promise.all([
|
|
150
|
-
presets.mount({}, 'standard'),
|
|
151
|
-
presets.resolve('standard'),
|
|
152
|
-
])
|
|
153
|
-
|
|
154
|
-
expect(mounted.path).not.toBe(standard.path)
|
|
155
|
-
expect(resolved.path).toBe(standard.path)
|
|
156
|
-
await installation.dispose()
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
it('uses owner-only files and starts a new generation after source content changes', async () => {
|
|
160
|
-
const { root, standard } = await fixture()
|
|
161
|
-
const presets = new FakeAgentPresets(new Map([['standard', standard]]))
|
|
162
|
-
const installation = decorateAgentPresets(presets, { modules: MODULES, tempParent: root })
|
|
163
|
-
|
|
164
|
-
const first = await presets.mount({}, 'standard')
|
|
165
|
-
const same = await presets.mount({}, 'standard')
|
|
166
|
-
expect(same.path).toBe(first.path)
|
|
167
|
-
// Windows (NTFS) ignores POSIX permission bits: mode stays 0o666.
|
|
168
|
-
if (process.platform !== 'win32') {
|
|
169
|
-
expect((await stat(dirname(first.path))).mode & 0o777).toBe(0o700)
|
|
170
|
-
expect((await stat(first.path)).mode & 0o777).toBe(0o600)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
await writeFile(standard.path, `${await readFile(standard.path, 'utf8')}\n- id: later\n name: '/opt/preset/later.js'\n`)
|
|
174
|
-
const changed = await presets.mount({}, 'standard')
|
|
175
|
-
expect(changed.path).not.toBe(first.path)
|
|
176
|
-
expect(await readFile(changed.path, 'utf8')).toContain('id: later')
|
|
177
|
-
|
|
178
|
-
await installation.dispose()
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('shares one decoration across duplicate Bundle and built-in loads', async () => {
|
|
182
|
-
const { root, standard } = await fixture()
|
|
183
|
-
const presets = new FakeAgentPresets(new Map([['standard', standard]]))
|
|
184
|
-
const first = decorateAgentPresets(presets, { modules: MODULES, tempParent: root })
|
|
185
|
-
const second = decorateAgentPresets(presets, { modules: MODULES, tempParent: root })
|
|
186
|
-
|
|
187
|
-
const mounted = await presets.mount({}, 'standard')
|
|
188
|
-
const all = flatten(rowsAt(await readFile(mounted.path, 'utf8')))
|
|
189
|
-
expect(all.filter(row => row.id === 'compaction')).toHaveLength(1)
|
|
190
|
-
expect(all.filter(row => row.id === 'tool-result-pruner')).toHaveLength(1)
|
|
191
|
-
|
|
192
|
-
await first.dispose()
|
|
193
|
-
expect((await presets.mount({}, 'standard')).path).toBe(mounted.path)
|
|
194
|
-
|
|
195
|
-
await second.dispose()
|
|
196
|
-
expect((await presets.mount({}, 'standard')).path).toBe(standard.path)
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
it('does not share one decoration across different metadata policies', async () => {
|
|
200
|
-
const { root, standard } = await fixture()
|
|
201
|
-
const presets = new FakeAgentPresets(new Map([['standard', standard]]))
|
|
202
|
-
const metadataIo = (): PresetOverlayMetadataIo => ({
|
|
203
|
-
async setTimes(path, stamp) {
|
|
204
|
-
await utimes(path, stamp, stamp)
|
|
205
|
-
},
|
|
206
|
-
async read(path) {
|
|
207
|
-
const observed = await stat(path)
|
|
208
|
-
return { mtimeMs: observed.mtimeMs, size: observed.size }
|
|
209
|
-
},
|
|
210
|
-
})
|
|
211
|
-
const first = decorateAgentPresets(presets, {
|
|
212
|
-
modules: MODULES,
|
|
213
|
-
tempParent: root,
|
|
214
|
-
metadataIo: metadataIo(),
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
expect(() => decorateAgentPresets(presets, {
|
|
218
|
-
modules: MODULES,
|
|
219
|
-
tempParent: root,
|
|
220
|
-
metadataIo: metadataIo(),
|
|
221
|
-
})).toThrow(/different compression overlay/u)
|
|
222
|
-
|
|
223
|
-
await first.dispose()
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('removes staging files when metadata preparation fails before publish', async () => {
|
|
227
|
-
const { root, standard } = await fixture()
|
|
228
|
-
const presets = new FakeAgentPresets(new Map([['standard', standard]]))
|
|
229
|
-
const installation = decorateAgentPresets(presets, {
|
|
230
|
-
modules: MODULES,
|
|
231
|
-
tempParent: root,
|
|
232
|
-
metadataIo: {
|
|
233
|
-
setTimes: () => Promise.reject(new Error('synthetic metadata failure')),
|
|
234
|
-
read: () => Promise.reject(new Error('metadata read must not run')),
|
|
235
|
-
},
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
await expect(presets.mount({}, 'standard')).rejects.toThrow(/synthetic metadata failure/u)
|
|
239
|
-
const generatedDirectories = (await readdir(root, { withFileTypes: true }))
|
|
240
|
-
.filter(entry => entry.isDirectory() && entry.name.startsWith('dsh-context-compression-presets-'))
|
|
241
|
-
expect(generatedDirectories).toHaveLength(1)
|
|
242
|
-
expect(await readdir(join(root, generatedDirectories[0]!.name))).toEqual([])
|
|
243
|
-
|
|
244
|
-
await installation.dispose()
|
|
245
|
-
})
|
|
246
|
-
})
|