dsh-context-compression-improved 0.6.5 → 0.7.0-beta.2

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.
Files changed (70) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -211
  3. package/CHANGELOG.ko.md +211 -205
  4. package/CHANGELOG.md +392 -350
  5. package/CHANGELOG.zh.md +196 -190
  6. package/README.md +97 -96
  7. package/README.zh.md +86 -85
  8. package/eslint.config.js +76 -30
  9. package/package.json +3 -1
  10. package/packages/selector/dsh.plugin.json +1 -1
  11. package/packages/selector/lib/client.js +747 -3
  12. package/packages/selector/lib/index.js +92 -1
  13. package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
  14. package/packages/selector/lib/profiles.d.ts +9 -0
  15. package/packages/selector/lib/pruner.d.ts +59 -0
  16. package/packages/selector/lib/pruner.js +410 -8
  17. package/packages/selector/src/client/decode.ts +53 -49
  18. package/packages/selector/src/client/index.ts +30 -0
  19. package/packages/selector/src/client/locales/de.ts +98 -0
  20. package/packages/selector/src/client/locales/es.ts +98 -0
  21. package/packages/selector/src/client/locales/fr.ts +98 -0
  22. package/packages/selector/src/client/locales/it.ts +98 -0
  23. package/packages/selector/src/client/locales/ja.ts +98 -0
  24. package/packages/selector/src/client/locales/ko.ts +98 -0
  25. package/packages/selector/src/client/locales/ru.ts +98 -0
  26. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  27. package/packages/selector/src/index.ts +418 -411
  28. package/packages/selector/src/preset-overlay.ts +629 -626
  29. package/packages/selector/src/profiles.ts +414 -394
  30. package/packages/selector/src/pruner/content.ts +198 -198
  31. package/packages/selector/src/pruner/state.ts +57 -50
  32. package/packages/selector/src/pruner.ts +2665 -2421
  33. package/packages/selector/src/runtime/audit.ts +303 -286
  34. package/packages/selector/src/runtime/config.ts +731 -706
  35. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  36. package/packages/selector/src/runtime/summary-command.ts +133 -0
  37. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
  38. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
  39. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  40. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  41. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  42. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  43. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  44. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -303
  45. package/packages/selector/src/runtime/types.ts +358 -346
  46. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
  47. package/packages/selector/tests/built/client-artifact.spec.ts +61 -59
  48. package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
  49. package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
  50. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  51. package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
  52. package/packages/selector/tests/profiles.client.spec.tsx +436 -434
  53. package/packages/selector/tests/runtime/audit.spec.ts +275 -274
  54. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  55. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  56. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  57. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  58. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +5 -0
  59. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  60. package/packages/selector/tests/standing-generation.host.spec.ts +15 -35
  61. package/scripts/packed-components-smoke.mjs +734 -732
  62. package/scripts/packed-install-e2e.mjs +1275 -1273
  63. package/scripts/verify-release.mjs +318 -317
  64. package/tests/TEST_INVENTORY.md +41 -41
  65. package/tsconfig.tests.json +17 -15
  66. package/vitest.config.ts +57 -43
  67. package/.agents-stash-064.patch +0 -39
  68. package/_dsh_devdeps.json +0 -50
  69. package/_verify064/package/package.json +0 -162
  70. package/_verify064/package/packages/selector/src/client/index.ts +0 -232
@@ -1,232 +0,0 @@
1
- import type {} from '@deepseek-ai/dsh-client-locale/client'
2
- import type { Context as ClientContext } from '@deepseek-ai/cordis'
3
- import type {} from '@deepseek-ai/dsh-client-ui-session/client'
4
- import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
5
- import type {} from '@deepseek-ai/dsh-client-ui-workspace/client'
6
- import {
7
- isCustomCompressionPolicy,
8
- ContextCompressionSettingsSection,
9
- type CompressionSelectorInjected, type ContextCompressionSettings,
10
- } from './CompressionProfileSelector.tsx'
11
- import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
12
- import { decodeSettings } from './decode.ts'
13
- import { en, zh } from './locales.ts'
14
- import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
15
- import type { ScopeSnapshot, SettingsScope } from './scope-face.ts'
16
-
17
- /**
18
- * Harness 0.1.5 mounts the web core's `slots` service on the client context
19
- * but no longer ships a public type for it; declare the face this plugin
20
- * consumes (same shape dsh-thinking-levels and dsh-prime-memory rely on).
21
- * `inject` factories may be sync (return a disposer) or generator (yield the
22
- * registration); slot options are validated at runtime per slot kind, which
23
- * lets one entry supply both `id` (Desktop, list) and `key` (CLI, keyed).
24
- */
25
- interface SlotsService {
26
- inject(slot: string, register: () => (() => void) | Generator<() => void>): () => void
27
- register(options: Record<string, unknown>, component: unknown): () => void
28
- }
29
- declare module '@deepseek-ai/cordis' {
30
- interface Context {
31
- slots: SlotsService
32
- }
33
- }
34
-
35
- // Declare all consumed services (the official client-plugin pattern, and the
36
- // shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
37
- // apply until `locale` / `configForms` are provided, so registration can use
38
- // them directly. Resolving them lazily via ctx.get() instead races the settings
39
- // client's activation — on a loss the apply early-returned and EVERY settings
40
- // entry silently vanished.
41
- export const inject = ['slots', 'locale', 'configForms']
42
- const NS = 'context-compression'
43
-
44
- /** 0.1.7: the profile entry whose config carries the compression settings doc. */
45
- const ENTRY_ID = 'context-compression-improved-bundle'
46
-
47
- /** The configForms face this client consumes (structural; 0.1.7 ui-settings). */
48
- interface ConfigFormsFace {
49
- get<T>(entryId: string): {
50
- getSnapshot(): {
51
- status: 'loading' | 'ready' | 'unavailable'
52
- value: T | undefined
53
- revision: number | undefined
54
- writable: boolean
55
- base: unknown
56
- user: unknown
57
- mode: 'host' | 'memory'
58
- }
59
- subscribe(listener: () => void): () => void
60
- set(field: string, value: unknown): Promise<boolean>
61
- unset(field: string): Promise<boolean>
62
- }
63
- }
64
-
65
-
66
- function sameCustomPolicy(
67
- left: ContextCompressionSettings['custom'],
68
- right: ContextCompressionSettings['custom'],
69
- ): boolean {
70
- if (left.version !== 3 || right.version !== 3) return false
71
- return left.version === right.version
72
- && left.unit === right.unit
73
- && left.prefixPolicy === right.prefixPolicy
74
- && left.fresh.enabled === right.fresh.enabled
75
- && left.fresh.trigger === right.fresh.trigger
76
- && left.fresh.target === right.fresh.target
77
- && left.aggregate.enabled === right.aggregate.enabled
78
- && left.aggregate.trigger === right.aggregate.trigger
79
- && left.aggregate.target === right.aggregate.target
80
- && left.history.enabled === right.history.enabled
81
- && left.history.trigger === right.history.trigger
82
- && left.history.keepRecentToolCalls === right.history.keepRecentToolCalls
83
- && left.history.keepRecentTokens === right.history.keepRecentTokens
84
- && left.history.minReclaim === right.history.minReclaim
85
- && left.tailTrim.enabled === right.tailTrim.enabled
86
- && left.tailTrim.trigger === right.tailTrim.trigger
87
- }
88
-
89
- export function apply(ctx: ClientContext): void {
90
- ctx.locale.register(NS, { zh, en })
91
- // Section label translator, captured EAGERLY: the settings shell evaluates
92
- // `label()` during its own render; a lazy ctx.locale accessor inside the
93
- // thunk would throw there if `locale` ever left this module's inject list
94
- // (the search-index 0.5.3 family-tab incident). bind() returns a live
95
- // binder, so locale switches are still followed.
96
- const localeSvc = ctx.locale as { bind?: (n: string) => (key: string) => string } | undefined
97
- const tNav = localeSvc?.bind?.(NS) ?? ((key: string) => key)
98
- const injected = (): CompressionSelectorInjected => {
99
- // 0.1.7: the compression document rides the selector row's entry config as
100
- // the volatile `settings` field. The form handle is fetched per factory
101
- // call on the caller's fiber (same activation rule as the old bind); the
102
- // wrapper below decodes the stored doc and converts per-field writes into
103
- // whole-doc commits (a volatile object replaces as one snapshot).
104
- const form = ctx.configForms.get<Record<string, unknown>>(ENTRY_ID)
105
- const readDoc = (): ContextCompressionSettings | undefined =>
106
- decodeSettings(form.getSnapshot().value?.settings)
107
- // useSyncExternalStore requires a getSnapshot that returns a STABLE
108
- // reference between changes — a fresh object per call is React error #185
109
- // (maximum update depth exceeded). Cache the projection keyed on the form
110
- // snapshot's identity: ConfigFormSnapshot is documented stable until the
111
- // next accepted change.
112
- let projectedSource: object | undefined
113
- let projected: ScopeSnapshot<ContextCompressionSettings> = {
114
- status: 'loading', value: undefined, revision: undefined,
115
- writable: false, base: undefined, user: undefined, mode: 'host',
116
- }
117
- const scope: SettingsScope<ContextCompressionSettings> = {
118
- getSnapshot() {
119
- const snap = form.getSnapshot()
120
- if (snap !== projectedSource) {
121
- projectedSource = snap
122
- projected = {
123
- status: snap.status,
124
- value: decodeSettings(snap.value?.settings),
125
- revision: snap.revision,
126
- writable: snap.writable,
127
- base: snap.base,
128
- user: snap.user,
129
- mode: snap.mode,
130
- }
131
- }
132
- return projected
133
- },
134
- subscribe: (listener) => form.subscribe(listener),
135
- set: async (field, value) => {
136
- const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
137
- next[field] = value
138
- return form.set('settings', next)
139
- },
140
- unset: async (field) => {
141
- const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
142
- delete next[field]
143
- return form.set('settings', next)
144
- },
145
- mutate: async (ops) => {
146
- const doc = { ...(readDoc() ?? {}) } as Record<string, unknown>
147
- for (const op of ops) {
148
- const [head, key] = op.path as [string, string]
149
- if (head !== 'presetOptions') return false
150
- const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
151
- if (op.op === 'unset') delete section[key]
152
- else section[key] = (op as { value?: unknown }).value
153
- doc.presetOptions = section
154
- }
155
- return form.set('settings', doc)
156
- },
157
- }
158
- const writeAndConfirm = async (
159
- write: () => Promise<unknown>,
160
- accepts: (settings: ContextCompressionSettings) => boolean,
161
- ): Promise<void> => {
162
- const beforeRevision = scope.getSnapshot().revision
163
- await write()
164
- const after = scope.getSnapshot()
165
- if (
166
- after.status !== 'ready'
167
- || after.value === undefined
168
- || after.revision === beforeRevision
169
- || !accepts(after.value)
170
- ) {
171
- throw new Error('Context compression settings were not saved.')
172
- }
173
- }
174
- return {
175
- hooks: { compression: scope },
176
- select: profile => writeAndConfirm(
177
- () => scope.set('profile', profile),
178
- settings => settings.profile === profile,
179
- ),
180
- saveCustom: custom => writeAndConfirm(
181
- () => scope.set('custom', custom),
182
- settings => isCustomCompressionPolicy(settings.custom)
183
- && sameCustomPolicy(settings.custom, custom),
184
- ),
185
- resetCustom: () => writeAndConfirm(
186
- () => scope.set('custom', structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)),
187
- settings => isCustomCompressionPolicy(settings.custom)
188
- && sameCustomPolicy(settings.custom, DEFAULT_CUSTOM_COMPRESSION_POLICY),
189
- ),
190
- saveAutoCompact: thresholdPercent => writeAndConfirm(
191
- () => scope.set('autoCompact', { thresholdPercent }),
192
- settings => settings.autoCompact.thresholdPercent === thresholdPercent,
193
- ),
194
- saveCodeSkeleton: enabled => writeAndConfirm(
195
- () => scope.set('codeSkeleton', { enabled }),
196
- settings => settings.codeSkeleton.enabled === enabled,
197
- ),
198
- savePresetOptions: options => {
199
- // Path-addressed so one field write cannot delete its siblings: the
200
- // previous whole-section set erased estimatorMode (and every other
201
- // override) whenever the user touched a second field.
202
- const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
203
- if (ops.length === 0) return Promise.resolve()
204
- return writeAndConfirm(
205
- () => scope.mutate?.(ops) ?? Promise.resolve(false),
206
- settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
207
- )
208
- },
209
- }
210
- }
211
- // 设置 → 上下文压缩 直挂分节(0.1.1 契约;0.1.5 官方分节也注册在此,未声明槽
212
- // 的注册会在激活期抛错,故 try/catch 守卫 —— 同 dsh-prime-memory 的双槽冗余)。
213
- // 只挂这一处:再注册 `settings.plugins.tab` / `settings.plugin.item` 会在
214
- // 设置里同时出现独立分节和插件卡片,重复展示同一张面板。
215
- try {
216
- ctx.slots.inject('settings.section', () => ctx.slots.register({
217
- name: 'settings.section',
218
- id: 'context-compression',
219
- order: 17,
220
- label: () => tNav('nav'),
221
- locale: NS,
222
- inject: injected,
223
- }, ContextCompressionSettingsSection))
224
- } catch (error) {
225
- console.warn('[dsh-context-compression-improved] settings.section 注册失败(新宿主已收编):', error)
226
- }
227
- }
228
-
229
- export type {
230
- CompressionProfile, CompressionProfileSelectorProps, CompressionSelectorInjected,
231
- ContextCompressionSettings,
232
- } from './CompressionProfileSelector.tsx'