dsh-context-compression-improved 0.5.6 → 0.6.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/package.json +9 -11
- package/packages/selector/lib/advisor-state.js +1 -1
- package/packages/selector/lib/client.d.ts +19 -104
- package/packages/selector/lib/client.js +42 -5
- package/packages/selector/lib/index.d.ts +9 -0
- package/packages/selector/lib/index.js +18 -50
- package/packages/selector/lib/profiles.d.ts +105 -0
- package/packages/selector/lib/pruner.js +3 -2
- package/packages/selector/package.json +21 -21
- package/packages/selector/src/client/index.ts +71 -8
- package/packages/selector/src/index.ts +35 -86
- package/packages/selector/src/pruner.ts +12 -3
- package/packages/selector/src/runtime/config.ts +1 -1
- package/packages/selector/tests/code-skeleton.client.spec.ts +37 -34
- package/packages/selector/tests/custom-contract.client.spec.ts +19 -1
- package/packages/selector/tests/helpers/legacy-namespace.ts +31 -0
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +12 -12
- package/packages/selector/tests/preset-options-write.client.spec.ts +63 -82
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +9 -4
- package/packages/selector/tests/public/package-contract.client.spec.ts +2 -2
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -2
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -17
- package/packages/selector/tests/settings-seat.client.spec.ts +2 -2
- package/packages/selector/tests/standing-generation.host.spec.ts +7 -0
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
|
|
12
12
|
import { decodeSettings } from './decode.ts'
|
|
13
13
|
import { en, zh } from './locales.ts'
|
|
14
|
+
import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
14
15
|
import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -28,19 +29,40 @@ interface SlotsService {
|
|
|
28
29
|
declare module '@deepseek-ai/cordis' {
|
|
29
30
|
interface Context {
|
|
30
31
|
slots: SlotsService
|
|
32
|
+
configForms: ConfigFormsFace
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
// Declare all consumed services (the official client-plugin pattern, and the
|
|
35
37
|
// shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
|
|
36
|
-
// apply until `locale` / `
|
|
38
|
+
// apply until `locale` / `configForms` are provided, so registration can use
|
|
37
39
|
// them directly. Resolving them lazily via ctx.get() instead races the settings
|
|
38
40
|
// client's activation — on a loss the apply early-returned and EVERY settings
|
|
39
|
-
// entry
|
|
40
|
-
|
|
41
|
-
export const inject = ['slots', 'locale', 'settingsScope']
|
|
41
|
+
// entry silently vanished.
|
|
42
|
+
export const inject = ['slots', 'locale', 'configForms']
|
|
42
43
|
const NS = 'context-compression'
|
|
43
44
|
|
|
45
|
+
/** 0.1.7: the profile entry whose config carries the compression settings doc. */
|
|
46
|
+
const ENTRY_ID = 'context-compression-improved-bundle'
|
|
47
|
+
|
|
48
|
+
/** The configForms face this client consumes (structural; 0.1.7 ui-settings). */
|
|
49
|
+
interface ConfigFormsFace {
|
|
50
|
+
get<T>(entryId: string): {
|
|
51
|
+
getSnapshot(): {
|
|
52
|
+
status: 'loading' | 'ready' | 'unavailable'
|
|
53
|
+
value: T | undefined
|
|
54
|
+
revision: number | undefined
|
|
55
|
+
writable: boolean
|
|
56
|
+
base: unknown
|
|
57
|
+
user: unknown
|
|
58
|
+
mode: 'host' | 'memory'
|
|
59
|
+
}
|
|
60
|
+
subscribe(listener: () => void): () => void
|
|
61
|
+
set(field: string, value: unknown): Promise<boolean>
|
|
62
|
+
unset(field: string): Promise<boolean>
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
44
66
|
|
|
45
67
|
function sameCustomPolicy(
|
|
46
68
|
left: ContextCompressionSettings['custom'],
|
|
@@ -68,10 +90,51 @@ function sameCustomPolicy(
|
|
|
68
90
|
export function apply(ctx: ClientContext): void {
|
|
69
91
|
ctx.locale.register(NS, { zh, en })
|
|
70
92
|
const injected = (): CompressionSelectorInjected => {
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
// the
|
|
74
|
-
|
|
93
|
+
// 0.1.7: the compression document rides the selector row's entry config as
|
|
94
|
+
// the volatile `settings` field. The form handle is fetched per factory
|
|
95
|
+
// call on the caller's fiber (same activation rule as the old bind); the
|
|
96
|
+
// wrapper below decodes the stored doc and converts per-field writes into
|
|
97
|
+
// whole-doc commits (a volatile object replaces as one snapshot).
|
|
98
|
+
const form = ctx.configForms.get<Record<string, unknown>>(ENTRY_ID)
|
|
99
|
+
const readDoc = (): ContextCompressionSettings | undefined =>
|
|
100
|
+
decodeSettings(form.getSnapshot().value?.settings)
|
|
101
|
+
const scope: SettingsScope<ContextCompressionSettings> = {
|
|
102
|
+
getSnapshot() {
|
|
103
|
+
const snap = form.getSnapshot()
|
|
104
|
+
return {
|
|
105
|
+
status: snap.status,
|
|
106
|
+
value: readDoc(),
|
|
107
|
+
revision: snap.revision,
|
|
108
|
+
writable: snap.writable,
|
|
109
|
+
base: snap.base,
|
|
110
|
+
user: snap.user,
|
|
111
|
+
mode: snap.mode,
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
subscribe: (listener) => form.subscribe(listener),
|
|
115
|
+
set: async (field, value) => {
|
|
116
|
+
const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
117
|
+
next[field] = value
|
|
118
|
+
await form.set('settings', next)
|
|
119
|
+
},
|
|
120
|
+
unset: async (field) => {
|
|
121
|
+
const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
122
|
+
delete next[field]
|
|
123
|
+
await form.set('settings', next)
|
|
124
|
+
},
|
|
125
|
+
mutate: async (ops) => {
|
|
126
|
+
const doc = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
127
|
+
for (const op of ops) {
|
|
128
|
+
const [head, key] = op.path as [string, string]
|
|
129
|
+
if (head !== 'presetOptions') return
|
|
130
|
+
const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
|
|
131
|
+
if (op.op === 'unset') delete section[key]
|
|
132
|
+
else section[key] = (op as { value?: unknown }).value
|
|
133
|
+
doc.presetOptions = section
|
|
134
|
+
}
|
|
135
|
+
await form.set('settings', doc)
|
|
136
|
+
},
|
|
137
|
+
}
|
|
75
138
|
const writeAndConfirm = async (
|
|
76
139
|
write: () => Promise<void>,
|
|
77
140
|
accepts: (settings: ContextCompressionSettings) => boolean,
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Context } from '@deepseek-ai/cordis'
|
|
4
4
|
import z from '@deepseek-ai/schemastery'
|
|
5
|
-
import {
|
|
6
|
-
type SettingsScope,
|
|
7
|
-
type default as SettingsService,
|
|
8
|
-
} from '@deepseek-ai/dsh-settings'
|
|
9
5
|
import { buildEstimatorCatalog, type EstimatorCatalogDeps } from './estimator-catalog.ts'
|
|
6
|
+
import type { ContextCompressionSettings } from './profiles.ts'
|
|
10
7
|
import {
|
|
11
8
|
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
|
|
12
9
|
ContextCompressionSettingsSchema,
|
|
10
|
+
DEFAULT_CONTEXT_COMPRESSION_SETTINGS,
|
|
13
11
|
} from './runtime/config.ts'
|
|
14
12
|
|
|
15
13
|
import { getAdvisorState } from './runtime/tokenpilot/advisor-state.ts'
|
|
@@ -21,7 +19,6 @@ import { getAdvisorState } from './runtime/tokenpilot/advisor-state.ts'
|
|
|
21
19
|
// package, so the real schema is back and the daily Custom defaults are
|
|
22
20
|
// published again through settings.register(). The namespace value is
|
|
23
21
|
// unchanged ('context-compression').
|
|
24
|
-
const CONTEXT_COMPRESSION_NAMESPACE = CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never
|
|
25
22
|
import {
|
|
26
23
|
decorateAgentPresets,
|
|
27
24
|
resolveCompressionModulePaths,
|
|
@@ -295,31 +292,20 @@ function registerEstimatorCatalogRoute(ctx: Context): void {
|
|
|
295
292
|
log('warn', 'context-compression webServer not active yet — estimator catalog route pending: %s', ESTIMATOR_CATALOG_ROUTES.join(', '))
|
|
296
293
|
}
|
|
297
294
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
scope: SettingsScope<unknown>
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** One selector Host row able to own the registration effect. */
|
|
311
|
-
interface SettingsOwner {
|
|
312
|
-
/** Traceable service proxy binding register() to this row's fiber. */
|
|
313
|
-
readonly settings: SettingsService
|
|
295
|
+
/**
|
|
296
|
+
* Resolve one possibly-volatile field: a live ref on 0.1.7+, a plain value
|
|
297
|
+
* otherwise (0.1.7 hands `.volatile()` fields to `apply()` as live refs).
|
|
298
|
+
*/
|
|
299
|
+
function readVolatileValue<T>(value: T | { get(): T } | undefined): T | undefined {
|
|
300
|
+
if (value !== null && typeof value === 'object' && typeof (value as { get?: unknown }).get === 'function') {
|
|
301
|
+
return (value as { get(): T }).get()
|
|
302
|
+
}
|
|
303
|
+
return value as T | undefined
|
|
314
304
|
}
|
|
315
305
|
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
type SettingsCarrier = SettingsService & {
|
|
322
|
-
[SHARED_SETTINGS]?: SharedSettingsRegistration
|
|
306
|
+
/** The compression settings document carried by this row's composition entry. */
|
|
307
|
+
function readCompressionDoc(config: Config | undefined): ContextCompressionSettings | undefined {
|
|
308
|
+
return readVolatileValue(config?.settings)
|
|
323
309
|
}
|
|
324
310
|
|
|
325
311
|
/** Standalone Bundle behavior; the settings/UI owner remains safe when false. */
|
|
@@ -346,14 +332,25 @@ export interface Config {
|
|
|
346
332
|
* `presetOptions.advisor*` settings keys.
|
|
347
333
|
*/
|
|
348
334
|
advisorReportRoute?: boolean
|
|
335
|
+
/**
|
|
336
|
+
* 0.1.7: the compression settings document as ONE `.volatile()` whole-object
|
|
337
|
+
* field (the old dedicated namespace has no declarative equivalent). The
|
|
338
|
+
* browser selector writes it through `configForms`; the runtime reads the
|
|
339
|
+
* dereferenced value. Loose section schemas keep unknown keys — the strict
|
|
340
|
+
* validation stays in `decodeSettings` (client) and the runtime resolver.
|
|
341
|
+
*/
|
|
342
|
+
settings?: ContextCompressionSettings
|
|
349
343
|
}
|
|
350
344
|
|
|
351
345
|
/** Loader validation for the standalone Bundle opt-in. */
|
|
352
|
-
export const Config
|
|
346
|
+
export const Config = z.object({
|
|
353
347
|
presetOverlay: z.boolean().default(false),
|
|
354
348
|
estimatorCatalogRoute: z.boolean().default(false),
|
|
355
349
|
advisorReportRoute: z.boolean().default(false),
|
|
356
|
-
|
|
350
|
+
// The daily Custom defaults ride the field's schema default so every
|
|
351
|
+
// composition resolves a complete document without a stored user layer.
|
|
352
|
+
settings: z.any().default(DEFAULT_CONTEXT_COMPRESSION_SETTINGS).volatile(),
|
|
353
|
+
}) as unknown as z<Config>
|
|
357
354
|
|
|
358
355
|
/** Register the persisted default read by the currently mounted root pruner. */
|
|
359
356
|
export function apply(ctx: Context, config: Config = {}): void {
|
|
@@ -363,10 +360,6 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
363
360
|
// and quietly did nothing. Report it to a sink the host shows, then re-throw
|
|
364
361
|
// unchanged: behaviour is untouched, only observability is restored.
|
|
365
362
|
try {
|
|
366
|
-
ctx.inject(['settings'], (settingsCtx) => {
|
|
367
|
-
acquireSettingsRegistration(settingsCtx)
|
|
368
|
-
})
|
|
369
|
-
|
|
370
363
|
// The settings card's host-route dropdowns read this route; it lives on the
|
|
371
364
|
// top-level plugin fiber, not inside the isolated `toolResultPruner`
|
|
372
365
|
// service, because the route is host-wide rather than per-pruner-instance.
|
|
@@ -383,7 +376,7 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
383
376
|
{
|
|
384
377
|
modules: resolveCompressionModulePaths(),
|
|
385
378
|
excludedPresetIds: ['minimal'],
|
|
386
|
-
autoCompactThresholdPercent: () => resolveAutoCompactThresholdPercent(presetsCtx),
|
|
379
|
+
autoCompactThresholdPercent: () => resolveAutoCompactThresholdPercent(config, presetsCtx),
|
|
387
380
|
},
|
|
388
381
|
)
|
|
389
382
|
presetsCtx.effect(() => () => installation.dispose(), 'contextCompressionSelector.agentPresets()')
|
|
@@ -399,8 +392,13 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
399
392
|
* values are revalidated here, and any unreadable value falls back to the 80%
|
|
400
393
|
* default rather than blocking preset composition.
|
|
401
394
|
*/
|
|
402
|
-
function resolveAutoCompactThresholdPercent(
|
|
403
|
-
|
|
395
|
+
function resolveAutoCompactThresholdPercent(config: Config | undefined, presetsCtx?: Context): number {
|
|
396
|
+
// 0.1.7: the volatile entry field is authoritative; the legacy per-namespace
|
|
397
|
+
// read stays as a fallback so a host that still serves the old service shape
|
|
398
|
+
// keeps working (test hosts do exactly that).
|
|
399
|
+
const raw = readCompressionDoc(config)
|
|
400
|
+
?? (presetsCtx?.get('settings') as { get?: (ns: never) => unknown } | undefined)
|
|
401
|
+
?.get?.(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never)
|
|
404
402
|
try {
|
|
405
403
|
const record = structuredClone(raw) as Record<string, unknown> | undefined
|
|
406
404
|
const threshold = record?.autoCompact as { thresholdPercent?: number } | undefined
|
|
@@ -411,53 +409,4 @@ function resolveAutoCompactThresholdPercent(presetsCtx: Context): number {
|
|
|
411
409
|
}
|
|
412
410
|
}
|
|
413
411
|
|
|
414
|
-
/**
|
|
415
|
-
* Lease one native settings registration across duplicate Host rows.
|
|
416
|
-
*
|
|
417
|
-
* The lease effect is intentionally registered before settings.register().
|
|
418
|
-
* Cordis disposes effects in reverse order, so the native registration first
|
|
419
|
-
* releases the namespace; this disposer can then transfer it to another live
|
|
420
|
-
* owner without a duplicate-registration window.
|
|
421
|
-
*/
|
|
422
|
-
function acquireSettingsRegistration(ctx: Context): void {
|
|
423
|
-
const settings = ctx.settings as SettingsCarrier
|
|
424
|
-
const owner: SettingsOwner = { settings }
|
|
425
|
-
let shared = settings[SHARED_SETTINGS]
|
|
426
|
-
if (shared === undefined) {
|
|
427
|
-
shared = {
|
|
428
|
-
owners: new Set(),
|
|
429
|
-
registrationOwner: owner,
|
|
430
|
-
scope: undefined as unknown as SettingsScope<unknown>,
|
|
431
|
-
}
|
|
432
|
-
Object.defineProperty(settings, SHARED_SETTINGS, {
|
|
433
|
-
configurable: true,
|
|
434
|
-
enumerable: false,
|
|
435
|
-
writable: false,
|
|
436
|
-
value: shared,
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
shared.owners.add(owner)
|
|
440
|
-
const state = shared
|
|
441
|
-
|
|
442
|
-
ctx.effect(() => () => {
|
|
443
|
-
state.owners.delete(owner)
|
|
444
|
-
if (state.registrationOwner === owner && state.owners.size > 0) {
|
|
445
|
-
const next = state.owners.values().next().value as SettingsOwner
|
|
446
|
-
state.registrationOwner = next
|
|
447
|
-
state.scope = next.settings.register(
|
|
448
|
-
CONTEXT_COMPRESSION_NAMESPACE,
|
|
449
|
-
ContextCompressionSettingsSchema,
|
|
450
|
-
)
|
|
451
|
-
}
|
|
452
|
-
if (state.owners.size === 0 && settings[SHARED_SETTINGS] === state) {
|
|
453
|
-
Reflect.deleteProperty(settings, SHARED_SETTINGS)
|
|
454
|
-
}
|
|
455
|
-
}, 'contextCompressionSelector.settingsLease()')
|
|
456
412
|
|
|
457
|
-
if (state.owners.size === 1) {
|
|
458
|
-
state.scope = settings.register(
|
|
459
|
-
CONTEXT_COMPRESSION_NAMESPACE,
|
|
460
|
-
ContextCompressionSettingsSchema,
|
|
461
|
-
)
|
|
462
|
-
}
|
|
463
|
-
}
|
|
@@ -423,9 +423,18 @@ export class ToolResultPruner extends Service {
|
|
|
423
423
|
private activeSettings(session: Session): ContextCompressionSettings {
|
|
424
424
|
const frozen = this.state.sessionSettings.get(session)
|
|
425
425
|
if (frozen !== undefined) return frozen
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
|
|
426
|
+
// 0.1.7: the compression document rides the selector row's entry config as a
|
|
427
|
+
// `.volatile()` field — read it through the settings service's describe()
|
|
428
|
+
// mirror (keyed by the profile entry id). The legacy per-namespace get stays
|
|
429
|
+
// as a fallback; both are undefined-safe and the caller handles absence.
|
|
430
|
+
const settingsHost = this.ctx.get('settings') as {
|
|
431
|
+
describe?: () => Array<{ ns: unknown; value?: unknown }>
|
|
432
|
+
get?: (ns: never) => unknown
|
|
433
|
+
} | undefined
|
|
434
|
+
const settings = (settingsHost?.describe?.().find(
|
|
435
|
+
(d) => String(d.ns) === 'context-compression-improved-bundle',
|
|
436
|
+
)?.value
|
|
437
|
+
?? settingsHost?.get?.(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never)) as ContextCompressionSettings | undefined
|
|
429
438
|
let resolved: ContextCompressionSettings
|
|
430
439
|
let settingsSource: 'host-settings' | 'plugin-config-fallback' = settings === undefined
|
|
431
440
|
? 'plugin-config-fallback'
|
|
@@ -248,7 +248,7 @@ const isSupportedProfile = (value: unknown): boolean =>
|
|
|
248
248
|
const isUsableCustomDocument = (value: unknown): boolean =>
|
|
249
249
|
isPlainRecord(value)
|
|
250
250
|
|
|
251
|
-
const DEFAULT_CONTEXT_COMPRESSION_SETTINGS: ContextCompressionSettings = {
|
|
251
|
+
export const DEFAULT_CONTEXT_COMPRESSION_SETTINGS: ContextCompressionSettings = {
|
|
252
252
|
profile: 'balanced',
|
|
253
253
|
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
254
254
|
autoCompact: { thresholdPercent: AUTO_COMPACT_THRESHOLD_LIMITS.default },
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
1
3
|
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
-
import type { SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
4
4
|
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
5
|
import { apply } from '../src/client/index.ts'
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
ContextCompressionSettings,
|
|
9
|
-
} from '../src/client/CompressionProfileSelector.tsx'
|
|
6
|
+
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
7
|
+
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
*/
|
|
15
16
|
|
|
16
17
|
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
17
18
|
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
@@ -24,36 +25,37 @@ describe('codeSkeleton confirm-on-write client contract', () => {
|
|
|
24
25
|
autoCompact: { thresholdPercent: 80 },
|
|
25
26
|
codeSkeleton: { enabled: false },
|
|
26
27
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
getSnapshot: snapshot,
|
|
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
38
|
subscribe: vi.fn(() => () => {}),
|
|
39
|
-
set: vi.fn(async (
|
|
40
|
-
if (!commit) return
|
|
39
|
+
set: vi.fn(async (_field: string, next: unknown) => {
|
|
40
|
+
if (!commit) return false
|
|
41
41
|
revision += 1
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const doc = structuredClone(next) as ContextCompressionSettings
|
|
43
|
+
if (flipEnabled) {
|
|
44
|
+
const accepted = structuredClone(doc.codeSkeleton)
|
|
44
45
|
accepted.enabled = !accepted.enabled
|
|
45
|
-
value = { ...
|
|
46
|
-
return
|
|
46
|
+
value = { ...doc, codeSkeleton: accepted }
|
|
47
|
+
return true
|
|
47
48
|
}
|
|
48
|
-
value =
|
|
49
|
+
value = doc
|
|
50
|
+
return true
|
|
49
51
|
}),
|
|
50
|
-
unset: vi.fn(async () =>
|
|
52
|
+
unset: vi.fn(async () => false),
|
|
51
53
|
}
|
|
52
54
|
let injected: (() => CompressionSelectorInjected) | undefined
|
|
53
55
|
const ctx = {
|
|
54
56
|
effect: (install: () => unknown) => { install() },
|
|
55
57
|
locale: { register: vi.fn(() => () => {}) },
|
|
56
|
-
|
|
58
|
+
configForms: { get: vi.fn(() => form) },
|
|
57
59
|
slots: {
|
|
58
60
|
inject: (_slot: string, install: () => unknown) => { install() },
|
|
59
61
|
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
@@ -62,7 +64,7 @@ describe('codeSkeleton confirm-on-write client contract', () => {
|
|
|
62
64
|
return () => {}
|
|
63
65
|
},
|
|
64
66
|
},
|
|
65
|
-
} as unknown as
|
|
67
|
+
} as unknown as Parameters<typeof apply>[0]
|
|
66
68
|
|
|
67
69
|
apply(ctx)
|
|
68
70
|
const actions = injected?.()
|
|
@@ -72,10 +74,11 @@ describe('codeSkeleton confirm-on-write client contract', () => {
|
|
|
72
74
|
// A silent host drop leaves the revision untouched: the write must reject.
|
|
73
75
|
await expect(actions.saveCodeSkeleton(true)).rejects.toThrow('were not saved')
|
|
74
76
|
|
|
75
|
-
// A committed write resolves and persists the exact section payload
|
|
77
|
+
// A committed write resolves and persists the exact section payload under
|
|
78
|
+
// the volatile `settings` field.
|
|
76
79
|
commit = true
|
|
77
80
|
await expect(actions.saveCodeSkeleton(true)).resolves.toBeUndefined()
|
|
78
|
-
expect(
|
|
81
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: true } }))
|
|
79
82
|
expect(value.codeSkeleton).toEqual({ enabled: true })
|
|
80
83
|
|
|
81
84
|
// A host that flips the toggled bit fails the acceptance check.
|
|
@@ -84,7 +87,7 @@ describe('codeSkeleton confirm-on-write client contract', () => {
|
|
|
84
87
|
|
|
85
88
|
flipEnabled = false
|
|
86
89
|
await expect(actions.saveCodeSkeleton(false)).resolves.toBeUndefined()
|
|
87
|
-
expect(
|
|
90
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: false } }))
|
|
88
91
|
expect(value.codeSkeleton).toEqual({ enabled: false })
|
|
89
92
|
})
|
|
90
93
|
})
|
|
@@ -145,7 +145,25 @@ describe('context compression browser contract', () => {
|
|
|
145
145
|
const ctx = {
|
|
146
146
|
effect: (install: () => unknown) => { install() },
|
|
147
147
|
locale: { register: vi.fn(() => () => {}) },
|
|
148
|
-
|
|
148
|
+
// 0.1.7: the plugin commits the whole doc through configForms; the fake
|
|
149
|
+
// routes each changed top-level field back onto the old scope stub so
|
|
150
|
+
// the rewrite/drop semantics below stay observable per field.
|
|
151
|
+
configForms: {
|
|
152
|
+
get: vi.fn(() => ({
|
|
153
|
+
getSnapshot: () => ({ ...snapshot(), value: { settings: value } }),
|
|
154
|
+
subscribe: scope.subscribe,
|
|
155
|
+
set: async (_field: string, doc: unknown) => {
|
|
156
|
+
const next = doc as unknown as Record<string, unknown>
|
|
157
|
+
for (const key of Object.keys(next)) {
|
|
158
|
+
if (JSON.stringify((value as unknown as Record<string, unknown>)[key]) !== JSON.stringify(next[key])) {
|
|
159
|
+
await scope.set(key, (next as Record<string, unknown>)[key])
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return true
|
|
163
|
+
},
|
|
164
|
+
unset: scope.unset,
|
|
165
|
+
})),
|
|
166
|
+
},
|
|
149
167
|
slots: {
|
|
150
168
|
inject: (_slot: string, install: () => unknown) => { install() },
|
|
151
169
|
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-host helper: registers the legacy `context-compression` settings
|
|
3
|
+
* namespace on a 0.1.5-shaped test settings service, so specs can drive the
|
|
4
|
+
* plugin through `settings.update(...)` exactly as they did before the 0.1.7
|
|
5
|
+
* declarative migration. Production code reads the volatile entry field first
|
|
6
|
+
* and falls back to this namespace; on a real 0.1.7 host neither the
|
|
7
|
+
* registration nor this helper exists.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
|
|
11
|
+
ContextCompressionSettingsSchema,
|
|
12
|
+
} from '../../src/runtime/config.ts'
|
|
13
|
+
|
|
14
|
+
export const LegacyNamespaceRegistrar = {
|
|
15
|
+
name: 'context-compression:test/legacy-namespace-registrar',
|
|
16
|
+
async apply(ctx: {
|
|
17
|
+
inject(deps: readonly string[], fn: (s: { settings: { register(ns: never, schema: unknown): unknown } }) => void): void
|
|
18
|
+
}): Promise<void> {
|
|
19
|
+
await new Promise<void>((resolve) => {
|
|
20
|
+
ctx.inject(['settings'], (s) => {
|
|
21
|
+
try {
|
|
22
|
+
s.settings.register(
|
|
23
|
+
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never,
|
|
24
|
+
ContextCompressionSettingsSchema,
|
|
25
|
+
)
|
|
26
|
+
} catch { /* already registered by an earlier row */ }
|
|
27
|
+
resolve()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
11
11
|
import { apply } from '../src/index.ts'
|
|
12
12
|
import type { OverlayableAgentPresets } from '../src/preset-overlay.ts'
|
|
13
|
+
import { LegacyNamespaceRegistrar } from './helpers/legacy-namespace.ts'
|
|
13
14
|
|
|
14
15
|
// 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
|
|
15
16
|
const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
|
|
@@ -73,6 +74,7 @@ describe('context compression selector Host preset integration', () => {
|
|
|
73
74
|
const preset = await sourcePreset()
|
|
74
75
|
ctx = new Context()
|
|
75
76
|
await ctx.plugin(MemorySettings).await()
|
|
77
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
76
78
|
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
77
79
|
|
|
78
80
|
const selector = ctx.plugin({ apply: (child) => {
|
|
@@ -90,7 +92,7 @@ describe('context compression selector Host preset integration', () => {
|
|
|
90
92
|
expect((await service.mount({})).path).toBe(preset.path)
|
|
91
93
|
})
|
|
92
94
|
|
|
93
|
-
it('
|
|
95
|
+
it('0.1.7: duplicate Host rows own independent entry configs — one row\u2019s disposal never disturbs the other', async () => {
|
|
94
96
|
const preset = await sourcePreset()
|
|
95
97
|
ctx = new Context()
|
|
96
98
|
await ctx.plugin(MemorySettings).await()
|
|
@@ -99,39 +101,35 @@ describe('context compression selector Host preset integration', () => {
|
|
|
99
101
|
const builtIn = ctx.plugin({ apply })
|
|
100
102
|
await builtIn.await()
|
|
101
103
|
|
|
102
|
-
const namespace = nsBrand('context-compression')
|
|
103
104
|
const service = ctx.agentPresets as unknown as OverlayableAgentPresets
|
|
104
105
|
expect((await service.mount({})).path).toBe(preset.path)
|
|
105
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
106
|
-
|
|
107
|
-
await ctx.settings.update(namespace, { profile: 'cache-strict' })
|
|
108
|
-
const selectedSettings = structuredClone(ctx.settings.get(namespace))
|
|
109
|
-
expect(selectedSettings).toMatchObject({ profile: 'cache-strict' })
|
|
110
106
|
|
|
107
|
+
// 0.1.7: there is no shared settings registration to lease — each row
|
|
108
|
+
// carries its own compression doc on its entry config, so duplicate rows
|
|
109
|
+
// cannot disturb each other and disposal is purely per row.
|
|
111
110
|
const bundle = ctx.plugin({ apply: (child) => {
|
|
112
|
-
apply(child, { presetOverlay: true })
|
|
111
|
+
apply(child, { presetOverlay: true, settings: { profile: 'cache-strict' } } as never)
|
|
113
112
|
} })
|
|
114
113
|
await bundle.await()
|
|
115
114
|
|
|
116
115
|
const mounted = await service.mount({})
|
|
117
116
|
expect(mounted.path).not.toBe(preset.path)
|
|
118
117
|
expect((await service.recompose({}, 'standard')).path).toBe(mounted.path)
|
|
119
|
-
expect(ctx.settings.get(namespace)).toEqual(selectedSettings)
|
|
120
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
121
118
|
|
|
119
|
+
// Disposing the non-overlay row never touches the overlay row's decoration
|
|
120
|
+
// or its entry config.
|
|
122
121
|
await builtIn.dispose()
|
|
123
122
|
expect((await service.mount({})).path).toBe(mounted.path)
|
|
124
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(1)
|
|
125
123
|
|
|
126
124
|
await bundle.dispose()
|
|
127
125
|
expect((await service.mount({})).path).toBe(preset.path)
|
|
128
|
-
expect(ctx.settings.describe().filter(row => row.ns === namespace)).toHaveLength(0)
|
|
129
126
|
})
|
|
130
127
|
|
|
131
128
|
it('writes the saved Auto Compact threshold into the generated compaction-basic composition', async () => {
|
|
132
129
|
const preset = await sourcePreset()
|
|
133
130
|
ctx = new Context()
|
|
134
131
|
await ctx.plugin(MemorySettings).await()
|
|
132
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
135
133
|
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
136
134
|
// A settings-owning row must register the namespace before the update.
|
|
137
135
|
await ctx.plugin({ apply }).await()
|
|
@@ -161,6 +159,7 @@ describe('context compression selector Host preset integration', () => {
|
|
|
161
159
|
const preset = await sourcePreset()
|
|
162
160
|
ctx = new Context()
|
|
163
161
|
await ctx.plugin(MemorySettings).await()
|
|
162
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
164
163
|
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
165
164
|
|
|
166
165
|
const bundle = ctx.plugin({ apply: (child) => {
|
|
@@ -178,6 +177,7 @@ describe('context compression selector Host preset integration', () => {
|
|
|
178
177
|
const preset = await sourcePreset()
|
|
179
178
|
ctx = new Context()
|
|
180
179
|
await ctx.plugin(MemorySettings).await()
|
|
180
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
181
181
|
await ctx.plugin(FakeAgentPresets, preset).await()
|
|
182
182
|
// A settings-owning row must register the namespace before the update.
|
|
183
183
|
await ctx.plugin({ apply }).await()
|