dsh-context-compression-improved 0.5.6 → 0.5.7

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 (162) hide show
  1. package/.gitattributes +2 -2
  2. package/.githooks/pre-push +37 -37
  3. package/.github/workflows/ci.yml +39 -39
  4. package/CHANGELOG.ja.md +169 -169
  5. package/CHANGELOG.ko.md +167 -167
  6. package/CHANGELOG.md +314 -304
  7. package/CHANGELOG.zh.md +152 -152
  8. package/CONTRIBUTING.md +22 -22
  9. package/LICENSE +21 -21
  10. package/README.ja.md +85 -85
  11. package/README.ko.md +85 -85
  12. package/README.md +94 -94
  13. package/README.zh.md +85 -85
  14. package/SECURITY.md +18 -18
  15. package/THIRD_PARTY_NOTICES.md +14 -14
  16. package/docs/compat-0.1.5-report.md +77 -77
  17. package/docs/installation.ja.md +78 -78
  18. package/docs/installation.ko.md +78 -78
  19. package/docs/installation.md +103 -103
  20. package/docs/installation.zh.md +100 -100
  21. package/docs/repair-log.md +657 -657
  22. package/eslint.config.js +30 -30
  23. package/package.json +164 -164
  24. package/packages/selector/LICENSE +21 -21
  25. package/packages/selector/README.md +26 -26
  26. package/packages/selector/README.zh.md +24 -24
  27. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
  28. package/packages/selector/cordis.patch.yml +27 -27
  29. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
  30. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
  31. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
  32. package/packages/selector/dsh.plugin.json +16 -16
  33. package/packages/selector/lib/client.js +733 -0
  34. package/packages/selector/lib/style.css +46 -46
  35. package/packages/selector/package.json +114 -114
  36. package/packages/selector/screenshots.json +3 -3
  37. package/packages/selector/src/client/CompressionProfileControls.tsx +226 -226
  38. package/packages/selector/src/client/CompressionProfileSelector.module.css +170 -170
  39. package/packages/selector/src/client/CompressionProfileSelector.tsx +83 -83
  40. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
  41. package/packages/selector/src/client/EstimatorControls.tsx +277 -277
  42. package/packages/selector/src/client/decode.ts +49 -49
  43. package/packages/selector/src/client/index.ts +178 -149
  44. package/packages/selector/src/client/locales/de.ts +98 -0
  45. package/packages/selector/src/client/locales/es.ts +98 -0
  46. package/packages/selector/src/client/locales/fr.ts +98 -0
  47. package/packages/selector/src/client/locales/it.ts +98 -0
  48. package/packages/selector/src/client/locales/ja.ts +98 -0
  49. package/packages/selector/src/client/locales/ko.ts +98 -0
  50. package/packages/selector/src/client/locales/ru.ts +98 -0
  51. package/packages/selector/src/client/locales.ts +196 -196
  52. package/packages/selector/src/client/preset-options.ts +88 -88
  53. package/packages/selector/src/client/settings-section.tsx +124 -124
  54. package/packages/selector/src/css-modules.d.ts +6 -6
  55. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  56. package/packages/selector/src/estimator-catalog.ts +104 -104
  57. package/packages/selector/src/index.ts +463 -463
  58. package/packages/selector/src/invariant.ts +113 -113
  59. package/packages/selector/src/preset-overlay.ts +626 -626
  60. package/packages/selector/src/profiles.ts +394 -394
  61. package/packages/selector/src/pruner/content.ts +201 -201
  62. package/packages/selector/src/pruner/session.ts +94 -94
  63. package/packages/selector/src/pruner/state.ts +50 -50
  64. package/packages/selector/src/pruner/tuning.ts +23 -23
  65. package/packages/selector/src/pruner/types.ts +78 -78
  66. package/packages/selector/src/pruner.ts +2402 -2402
  67. package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
  68. package/packages/selector/src/runtime/audit.ts +286 -286
  69. package/packages/selector/src/runtime/config.ts +706 -706
  70. package/packages/selector/src/runtime/custom-policy.ts +278 -278
  71. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
  72. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
  73. package/packages/selector/src/runtime/measurement.ts +436 -436
  74. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  75. package/packages/selector/src/runtime/retrieve.ts +457 -457
  76. package/packages/selector/src/runtime/session-events.ts +30 -30
  77. package/packages/selector/src/runtime/tail-trim.ts +166 -166
  78. package/packages/selector/src/runtime/token-count.ts +72 -72
  79. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +188 -188
  80. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +149 -149
  81. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
  82. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
  83. package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
  84. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
  85. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  86. package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
  87. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -303
  88. package/packages/selector/src/runtime/toolclass.ts +103 -103
  89. package/packages/selector/src/runtime/types.ts +346 -346
  90. package/packages/selector/src/runtime/value.ts +48 -48
  91. package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
  92. package/packages/selector/tests/auto-compact.client.spec.tsx +213 -213
  93. package/packages/selector/tests/built/client-artifact.spec.ts +59 -59
  94. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
  95. package/packages/selector/tests/code-skeleton.client.spec.ts +90 -90
  96. package/packages/selector/tests/custom-contract.client.spec.ts +204 -204
  97. package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
  98. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  99. package/packages/selector/tests/estimator-route-registration.host.spec.ts +188 -188
  100. package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
  101. package/packages/selector/tests/preset-options-write.client.spec.ts +206 -206
  102. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -201
  103. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
  104. package/packages/selector/tests/profiles.client.spec.tsx +434 -434
  105. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  106. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
  107. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -232
  108. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
  109. package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
  110. package/packages/selector/tests/runtime/audit.spec.ts +274 -274
  111. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  112. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
  113. package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
  114. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
  115. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  116. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
  117. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
  118. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
  119. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
  120. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
  121. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
  122. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
  123. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
  124. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
  125. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2724
  126. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
  127. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
  128. package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
  129. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
  130. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
  131. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
  132. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
  133. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
  134. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
  135. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
  136. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -116
  137. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
  138. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
  139. package/packages/selector/tests/runtime/value.spec.ts +23 -23
  140. package/packages/selector/tests/settings-seat.client.spec.ts +118 -118
  141. package/packages/selector/tests/standing-generation.host.spec.ts +697 -697
  142. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -253
  143. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
  144. package/packages/selector/tests/support/mock-adapter.ts +37 -37
  145. package/packages/selector/tests/support/ui-primitives.tsx +34 -34
  146. package/packages/selector/tsconfig.json +11 -11
  147. package/packages/selector/tsdown.client.config.ts +102 -102
  148. package/packages/selector/tsdown.config.ts +20 -20
  149. package/pnpm-workspace.yaml +66 -66
  150. package/scripts/capture-profile-baseline.mjs +42 -42
  151. package/scripts/generate-tokenizer-fixtures.py +81 -81
  152. package/scripts/generate-vision-fixtures.py +208 -208
  153. package/scripts/packed-components-smoke.mjs +732 -732
  154. package/scripts/packed-install-e2e.mjs +1273 -1273
  155. package/scripts/toolclass-corpus-replay.mjs +281 -281
  156. package/scripts/verify-release.mjs +317 -317
  157. package/tests/TEST_INVENTORY.md +41 -41
  158. package/tsconfig.base.json +18 -18
  159. package/tsconfig.json +7 -7
  160. package/tsconfig.tests.json +15 -15
  161. package/vitest.built.config.ts +9 -9
  162. package/vitest.config.ts +43 -43
@@ -1,49 +1,49 @@
1
- /** Browser-safe settings decoding shared by the client entry and node tests. */
2
-
3
- import {
4
- canonicalizeCustomPolicy,
5
- COMPRESSION_PROFILES,
6
- decodeAutoCompactSettings,
7
- decodeCodeSkeletonSettings,
8
- decodePresetOptionsSettings,
9
- isCustomCompressionPolicy,
10
- isPlainRecord,
11
- type CompressionProfile,
12
- type ContextCompressionSettings,
13
- } from '../profiles.ts'
14
-
15
- /**
16
- * Decode one stored context-compression settings document with exactly the
17
- * runtime schema's strictness: a plain object with only `profile`, `custom`,
18
- * `autoCompact`, and `codeSkeleton` keys, a supported profile, a valid Custom
19
- * document canonicalized to v3 exactly as the runtime resolver would, a
20
- * strictly-shaped autoCompact section (absent inherits the 80% default), and
21
- * a strictly-shaped codeSkeleton gate (absent inherits off). Anything else
22
- * decodes to `undefined` so the UI reports the document as unreadable instead
23
- * of silently disagreeing with the runtime.
24
- */
25
- export function decodeSettings(value: unknown): ContextCompressionSettings | undefined {
26
- if (!isPlainRecord(value)) return undefined
27
- const keys = Object.keys(value)
28
- if (keys.some(key => key !== 'profile' && key !== 'custom' && key !== 'autoCompact' && key !== 'codeSkeleton' && key !== 'presetOptions')) {
29
- return undefined
30
- }
31
- const profile = (value as { profile?: unknown }).profile
32
- const custom = (value as { custom?: unknown }).custom
33
- const autoCompact = decodeAutoCompactSettings((value as { autoCompact?: unknown }).autoCompact)
34
- const codeSkeleton = decodeCodeSkeletonSettings((value as { codeSkeleton?: unknown }).codeSkeleton)
35
- const presetOptions = decodePresetOptionsSettings((value as { presetOptions?: unknown }).presetOptions)
36
- return typeof profile === 'string'
37
- && (COMPRESSION_PROFILES as readonly string[]).includes(profile)
38
- && isCustomCompressionPolicy(custom)
39
- && autoCompact !== undefined
40
- && codeSkeleton !== undefined
41
- ? {
42
- profile: profile as CompressionProfile,
43
- custom: canonicalizeCustomPolicy(custom),
44
- autoCompact,
45
- codeSkeleton,
46
- ...presetOptions === undefined ? {} : { presetOptions },
47
- }
48
- : undefined
49
- }
1
+ /** Browser-safe settings decoding shared by the client entry and node tests. */
2
+
3
+ import {
4
+ canonicalizeCustomPolicy,
5
+ COMPRESSION_PROFILES,
6
+ decodeAutoCompactSettings,
7
+ decodeCodeSkeletonSettings,
8
+ decodePresetOptionsSettings,
9
+ isCustomCompressionPolicy,
10
+ isPlainRecord,
11
+ type CompressionProfile,
12
+ type ContextCompressionSettings,
13
+ } from '../profiles.ts'
14
+
15
+ /**
16
+ * Decode one stored context-compression settings document with exactly the
17
+ * runtime schema's strictness: a plain object with only `profile`, `custom`,
18
+ * `autoCompact`, and `codeSkeleton` keys, a supported profile, a valid Custom
19
+ * document canonicalized to v3 exactly as the runtime resolver would, a
20
+ * strictly-shaped autoCompact section (absent inherits the 80% default), and
21
+ * a strictly-shaped codeSkeleton gate (absent inherits off). Anything else
22
+ * decodes to `undefined` so the UI reports the document as unreadable instead
23
+ * of silently disagreeing with the runtime.
24
+ */
25
+ export function decodeSettings(value: unknown): ContextCompressionSettings | undefined {
26
+ if (!isPlainRecord(value)) return undefined
27
+ const keys = Object.keys(value)
28
+ if (keys.some(key => key !== 'profile' && key !== 'custom' && key !== 'autoCompact' && key !== 'codeSkeleton' && key !== 'presetOptions')) {
29
+ return undefined
30
+ }
31
+ const profile = (value as { profile?: unknown }).profile
32
+ const custom = (value as { custom?: unknown }).custom
33
+ const autoCompact = decodeAutoCompactSettings((value as { autoCompact?: unknown }).autoCompact)
34
+ const codeSkeleton = decodeCodeSkeletonSettings((value as { codeSkeleton?: unknown }).codeSkeleton)
35
+ const presetOptions = decodePresetOptionsSettings((value as { presetOptions?: unknown }).presetOptions)
36
+ return typeof profile === 'string'
37
+ && (COMPRESSION_PROFILES as readonly string[]).includes(profile)
38
+ && isCustomCompressionPolicy(custom)
39
+ && autoCompact !== undefined
40
+ && codeSkeleton !== undefined
41
+ ? {
42
+ profile: profile as CompressionProfile,
43
+ custom: canonicalizeCustomPolicy(custom),
44
+ autoCompact,
45
+ codeSkeleton,
46
+ ...presetOptions === undefined ? {} : { presetOptions },
47
+ }
48
+ : undefined
49
+ }
@@ -1,149 +1,178 @@
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
-
16
- /**
17
- * Harness 0.1.5 mounts the web core's `slots` service on the client context
18
- * but no longer ships a public type for it; declare the face this plugin
19
- * consumes (same shape dsh-thinking-levels and dsh-prime-memory rely on).
20
- * `inject` factories may be sync (return a disposer) or generator (yield the
21
- * registration); slot options are validated at runtime per slot kind, which
22
- * lets one entry supply both `id` (Desktop, list) and `key` (CLI, keyed).
23
- */
24
- interface SlotsService {
25
- inject(slot: string, register: () => (() => void) | Generator<() => void>): () => void
26
- register(options: Record<string, unknown>, component: unknown): () => void
27
- }
28
- declare module '@deepseek-ai/cordis' {
29
- interface Context {
30
- slots: SlotsService
31
- }
32
- }
33
-
34
- // Declare all consumed services (the official client-plugin pattern, and the
35
- // shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
36
- // apply until `locale` / `settingsScope` are provided, so registration can use
37
- // them directly. Resolving them lazily via ctx.get() instead races the settings
38
- // client's activation — on a loss the apply early-returned and EVERY settings
39
- // entry (the standalone section, the plugins-tab card, the item card) silently
40
- // vanished.
41
- export const inject = ['slots', 'locale', 'settingsScope']
42
- const NS = 'context-compression'
43
-
44
-
45
- function sameCustomPolicy(
46
- left: ContextCompressionSettings['custom'],
47
- right: ContextCompressionSettings['custom'],
48
- ): boolean {
49
- if (left.version !== 3 || right.version !== 3) return false
50
- return left.version === right.version
51
- && left.unit === right.unit
52
- && left.prefixPolicy === right.prefixPolicy
53
- && left.fresh.enabled === right.fresh.enabled
54
- && left.fresh.trigger === right.fresh.trigger
55
- && left.fresh.target === right.fresh.target
56
- && left.aggregate.enabled === right.aggregate.enabled
57
- && left.aggregate.trigger === right.aggregate.trigger
58
- && left.aggregate.target === right.aggregate.target
59
- && left.history.enabled === right.history.enabled
60
- && left.history.trigger === right.history.trigger
61
- && left.history.keepRecentToolCalls === right.history.keepRecentToolCalls
62
- && left.history.keepRecentTokens === right.history.keepRecentTokens
63
- && left.history.minReclaim === right.history.minReclaim
64
- && left.tailTrim.enabled === right.tailTrim.enabled
65
- && left.tailTrim.trigger === right.tailTrim.trigger
66
- }
67
-
68
- export function apply(ctx: ClientContext): void {
69
- ctx.locale.register(NS, { zh, en })
70
- const injected = (): CompressionSelectorInjected => {
71
- // Bind per factory call on the caller's fiber (0.1.5: activation must
72
- // never block on the settings transport; the scope disposer belongs to
73
- // the calling registration's lifecycle).
74
- const scope = ctx.settingsScope.bind<ContextCompressionSettings>({ namespace: NS, decode: decodeSettings })
75
- const writeAndConfirm = async (
76
- write: () => Promise<void>,
77
- accepts: (settings: ContextCompressionSettings) => boolean,
78
- ): Promise<void> => {
79
- const beforeRevision = scope.getSnapshot().revision
80
- await write()
81
- const after = scope.getSnapshot()
82
- if (
83
- after.status !== 'ready'
84
- || after.value === undefined
85
- || after.revision === beforeRevision
86
- || !accepts(after.value)
87
- ) {
88
- throw new Error('Context compression settings were not saved.')
89
- }
90
- }
91
- return {
92
- hooks: { compression: scope },
93
- select: profile => writeAndConfirm(
94
- () => scope.set('profile', profile),
95
- settings => settings.profile === profile,
96
- ),
97
- saveCustom: custom => writeAndConfirm(
98
- () => scope.set('custom', custom),
99
- settings => isCustomCompressionPolicy(settings.custom)
100
- && sameCustomPolicy(settings.custom, custom),
101
- ),
102
- resetCustom: () => writeAndConfirm(
103
- () => scope.set('custom', structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)),
104
- settings => isCustomCompressionPolicy(settings.custom)
105
- && sameCustomPolicy(settings.custom, DEFAULT_CUSTOM_COMPRESSION_POLICY),
106
- ),
107
- saveAutoCompact: thresholdPercent => writeAndConfirm(
108
- () => scope.set('autoCompact', { thresholdPercent }),
109
- settings => settings.autoCompact.thresholdPercent === thresholdPercent,
110
- ),
111
- saveCodeSkeleton: enabled => writeAndConfirm(
112
- () => scope.set('codeSkeleton', { enabled }),
113
- settings => settings.codeSkeleton.enabled === enabled,
114
- ),
115
- savePresetOptions: options => {
116
- // Path-addressed so one field write cannot delete its siblings: the
117
- // previous whole-section set erased estimatorMode (and every other
118
- // override) whenever the user touched a second field.
119
- const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
120
- if (ops.length === 0) return Promise.resolve()
121
- return writeAndConfirm(
122
- () => scope.mutate(ops),
123
- settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
124
- )
125
- },
126
- }
127
- }
128
- // 设置 → 上下文压缩 直挂分节(0.1.1 契约;0.1.5 官方分节也注册在此,未声明槽
129
- // 的注册会在激活期抛错,故 try/catch 守卫 —— 同 dsh-prime-memory 的双槽冗余)。
130
- // 只挂这一处:再注册 `settings.plugins.tab` / `settings.plugin.item` 会在
131
- // 设置里同时出现独立分节和插件卡片,重复展示同一张面板。
132
- try {
133
- ctx.slots.inject('settings.section', () => ctx.slots.register({
134
- name: 'settings.section',
135
- id: 'context-compression',
136
- order: 17,
137
- label: () => ctx.locale.bind(NS)('nav'),
138
- locale: NS,
139
- inject: injected,
140
- }, ContextCompressionSettingsSection))
141
- } catch (error) {
142
- console.warn('[dsh-context-compression-improved] settings.section 注册失败(新宿主已收编):', error)
143
- }
144
- }
145
-
146
- export type {
147
- CompressionProfile, CompressionProfileSelectorProps, CompressionSelectorInjected,
148
- ContextCompressionSettings,
149
- } from './CompressionProfileSelector.tsx'
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 { de } from './locales/de.ts'
15
+ import { es } from './locales/es.ts'
16
+ import { fr } from './locales/fr.ts'
17
+ import { it } from './locales/it.ts'
18
+ import { ja } from './locales/ja.ts'
19
+ import { ko } from './locales/ko.ts'
20
+ import { ru } from './locales/ru.ts'
21
+ import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
22
+
23
+ /**
24
+ * Harness 0.1.5 mounts the web core's `slots` service on the client context
25
+ * but no longer ships a public type for it; declare the face this plugin
26
+ * consumes (same shape dsh-thinking-levels and dsh-prime-memory rely on).
27
+ * `inject` factories may be sync (return a disposer) or generator (yield the
28
+ * registration); slot options are validated at runtime per slot kind, which
29
+ * lets one entry supply both `id` (Desktop, list) and `key` (CLI, keyed).
30
+ */
31
+ interface SlotsService {
32
+ inject(slot: string, register: () => (() => void) | Generator<() => void>): () => void
33
+ register(options: Record<string, unknown>, component: unknown): () => void
34
+ }
35
+ declare module '@deepseek-ai/cordis' {
36
+ interface Context {
37
+ slots: SlotsService
38
+ }
39
+ }
40
+
41
+ // Declare all consumed services (the official client-plugin pattern, and the
42
+ // shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
43
+ // apply until `locale` / `settingsScope` are provided, so registration can use
44
+ // them directly. Resolving them lazily via ctx.get() instead races the settings
45
+ // client's activation — on a loss the apply early-returned and EVERY settings
46
+ // entry (the standalone section, the plugins-tab card, the item card) silently
47
+ // vanished.
48
+ export const inject = ['slots', 'locale', 'settingsScope']
49
+ const NS = 'context-compression'
50
+
51
+
52
+ function sameCustomPolicy(
53
+ left: ContextCompressionSettings['custom'],
54
+ right: ContextCompressionSettings['custom'],
55
+ ): boolean {
56
+ if (left.version !== 3 || right.version !== 3) return false
57
+ return left.version === right.version
58
+ && left.unit === right.unit
59
+ && left.prefixPolicy === right.prefixPolicy
60
+ && left.fresh.enabled === right.fresh.enabled
61
+ && left.fresh.trigger === right.fresh.trigger
62
+ && left.fresh.target === right.fresh.target
63
+ && left.aggregate.enabled === right.aggregate.enabled
64
+ && left.aggregate.trigger === right.aggregate.trigger
65
+ && left.aggregate.target === right.aggregate.target
66
+ && left.history.enabled === right.history.enabled
67
+ && left.history.trigger === right.history.trigger
68
+ && left.history.keepRecentToolCalls === right.history.keepRecentToolCalls
69
+ && left.history.keepRecentTokens === right.history.keepRecentTokens
70
+ && left.history.minReclaim === right.history.minReclaim
71
+ && left.tailTrim.enabled === right.tailTrim.enabled
72
+ && left.tailTrim.trigger === right.tailTrim.trigger
73
+ }
74
+
75
+ export function apply(ctx: ClientContext): void {
76
+ ctx.locale.register(NS, { zh, en })
77
+ // de/es/fr/it/ja/ko/ru are not host built-ins (`BuiltInLocaleId` is zh|en), so
78
+ // their dictionaries ride the single-locale untyped register overload, and each
79
+ // needs an `addLanguage` definition to become selectable. Labels are
80
+ // self-described in their own language; the fallback chain ends at English.
81
+ // One occupied locale must not sink activation, hence the per-language guard.
82
+ const languages = [
83
+ { id: 'de', label: 'Deutsch', dict: de },
84
+ { id: 'es', label: 'Español', dict: es },
85
+ { id: 'fr', label: 'Français', dict: fr },
86
+ { id: 'it', label: 'Italiano', dict: it },
87
+ { id: 'ja', label: '日本語', dict: ja },
88
+ { id: 'ko', label: '한국어', dict: ko },
89
+ { id: 'ru', label: 'Русский', dict: ru },
90
+ ] as const
91
+ for (const language of languages) {
92
+ try {
93
+ ctx.locale.register(NS, language.id, language.dict)
94
+ ctx.locale.addLanguage({ id: language.id, label: language.label, fallback: 'en' })
95
+ } catch (error) {
96
+ console.warn(`[dsh-context-compression-improved] locale "${language.id}" registration failed:`, error)
97
+ }
98
+ }
99
+ const injected = (): CompressionSelectorInjected => {
100
+ // Bind per factory call on the caller's fiber (0.1.5: activation must
101
+ // never block on the settings transport; the scope disposer belongs to
102
+ // the calling registration's lifecycle).
103
+ const scope = ctx.settingsScope.bind<ContextCompressionSettings>({ namespace: NS, decode: decodeSettings })
104
+ const writeAndConfirm = async (
105
+ write: () => Promise<void>,
106
+ accepts: (settings: ContextCompressionSettings) => boolean,
107
+ ): Promise<void> => {
108
+ const beforeRevision = scope.getSnapshot().revision
109
+ await write()
110
+ const after = scope.getSnapshot()
111
+ if (
112
+ after.status !== 'ready'
113
+ || after.value === undefined
114
+ || after.revision === beforeRevision
115
+ || !accepts(after.value)
116
+ ) {
117
+ throw new Error('Context compression settings were not saved.')
118
+ }
119
+ }
120
+ return {
121
+ hooks: { compression: scope },
122
+ select: profile => writeAndConfirm(
123
+ () => scope.set('profile', profile),
124
+ settings => settings.profile === profile,
125
+ ),
126
+ saveCustom: custom => writeAndConfirm(
127
+ () => scope.set('custom', custom),
128
+ settings => isCustomCompressionPolicy(settings.custom)
129
+ && sameCustomPolicy(settings.custom, custom),
130
+ ),
131
+ resetCustom: () => writeAndConfirm(
132
+ () => scope.set('custom', structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)),
133
+ settings => isCustomCompressionPolicy(settings.custom)
134
+ && sameCustomPolicy(settings.custom, DEFAULT_CUSTOM_COMPRESSION_POLICY),
135
+ ),
136
+ saveAutoCompact: thresholdPercent => writeAndConfirm(
137
+ () => scope.set('autoCompact', { thresholdPercent }),
138
+ settings => settings.autoCompact.thresholdPercent === thresholdPercent,
139
+ ),
140
+ saveCodeSkeleton: enabled => writeAndConfirm(
141
+ () => scope.set('codeSkeleton', { enabled }),
142
+ settings => settings.codeSkeleton.enabled === enabled,
143
+ ),
144
+ savePresetOptions: options => {
145
+ // Path-addressed so one field write cannot delete its siblings: the
146
+ // previous whole-section set erased estimatorMode (and every other
147
+ // override) whenever the user touched a second field.
148
+ const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
149
+ if (ops.length === 0) return Promise.resolve()
150
+ return writeAndConfirm(
151
+ () => scope.mutate(ops),
152
+ settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
153
+ )
154
+ },
155
+ }
156
+ }
157
+ // 设置 → 上下文压缩 直挂分节(0.1.1 契约;0.1.5 官方分节也注册在此,未声明槽
158
+ // 的注册会在激活期抛错,故 try/catch 守卫 —— 同 dsh-prime-memory 的双槽冗余)。
159
+ // 只挂这一处:再注册 `settings.plugins.tab` / `settings.plugin.item` 会在
160
+ // 设置里同时出现独立分节和插件卡片,重复展示同一张面板。
161
+ try {
162
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
163
+ name: 'settings.section',
164
+ id: 'context-compression',
165
+ order: 17,
166
+ label: () => ctx.locale.bind(NS)('nav'),
167
+ locale: NS,
168
+ inject: injected,
169
+ }, ContextCompressionSettingsSection))
170
+ } catch (error) {
171
+ console.warn('[dsh-context-compression-improved] settings.section 注册失败(新宿主已收编):', error)
172
+ }
173
+ }
174
+
175
+ export type {
176
+ CompressionProfile, CompressionProfileSelectorProps, CompressionSelectorInjected,
177
+ ContextCompressionSettings,
178
+ } from './CompressionProfileSelector.tsx'
@@ -0,0 +1,98 @@
1
+ import type { ContextCompressionLocaleKey } from '../locales.ts'
2
+
3
+ /** German copy matching every simplified Chinese selector key. */
4
+ export const de = {
5
+ 'nav': 'Kontextkomprimierung wählen',
6
+ 'settings.title': 'Kontextkomprimierung wählen',
7
+ 'settings.description': 'Wählen Sie ein Komprimierungsprofil für die aktuelle Sitzung und konfigurieren Sie dessen Parameter.',
8
+ 'label': 'Kontextkomprimierung',
9
+ 'status.loading': 'Wird geladen',
10
+ 'status.unavailable': 'Nicht verfügbar',
11
+ 'status.presetUnavailable': 'Das Preset dieser Sitzung bietet keine Kontextkomprimierung, oder die Verfügbarkeit ist noch nicht bestätigt.',
12
+ 'status.minimalUnavailable': 'Der Minimalmodus lädt für diese Sitzung keine Kontextkomprimierung. Die Auswahl ist aus und das native Harness-Verhalten gilt. Wechseln Sie zu Standard, PTC / Coding, Kreativ oder zu einem kompatiblen eigenen Preset, um sie zu konfigurieren.',
13
+ 'status.saveFailed': 'Speichern fehlgeschlagen. Bitte erneut versuchen.',
14
+ 'pricing.disclosure': 'Offizielle DeepSeek-Preise, geprüft am 2026-08-25. Spitzenzeiten Mo–Fr 09:00–12:00 und 14:00–18:00 (Asia/Shanghai), sonst Nebenzeiten. Anfragen über eine Grenze hinweg verwenden eine Kostenspanne.',
15
+ 'profile.balanced': 'Ausbalanciert',
16
+ 'profile.cache-strict': 'Cache Strict (Präfixschutz)',
17
+ 'profile.savings': 'Sparen',
18
+ 'profile.adaptive': 'Adaptiv (kostenbewusst)',
19
+ 'profile.tokenpilot-inspired': 'TokenPilot-inspiriert',
20
+ 'estimator.title': 'Schätzer (optional)',
21
+ 'estimator.description': 'Ein kleines Hilfsmodell schätzt ohne Beispiele, ob alte Datei-Lesevorgänge wahrscheinlich noch referenziert werden; nur beratend für das Altern des Verlaufs. Ohne Konfiguration oder bei Fehlern greift reines Regelverhalten.',
22
+ 'estimator.mode': 'Kanal',
23
+ 'estimator.mode.off': 'Aus (nur Regeln)',
24
+ 'estimator.mode.host': 'Host-Modell (nutzt konfigurierte Anbieter)',
25
+ 'estimator.mode.direct': 'Direkter OpenAI-kompatibler Endpunkt',
26
+ 'estimator.inactive': 'Der Schätzer gehört nur zum Profil „TokenPilot-inspiriert“: dessen Preset-Optionen (Deduplizierungszeiger, Zusammenfassungsanker, Lesestatus-Semantik und der Schätzer-Kanal) werden nie in ein anderes Profil übernommen, daher hat das aktuelle Profil „{profile}“ keinen Schätzer-Kanal. Wählen Sie „TokenPilot-inspiriert“, dann erhält dieser Bereich eine Kanalwahl — konfigurierte Anbieter nutzen (Host-Modell) oder ein direkter OpenAI-kompatibler Endpunkt.',
27
+ 'estimator.provider': 'Anbieter',
28
+ 'estimator.provider.placeholder': 'Leer folgt dem Standardmodell der Sitzung; aus der Liste wählen oder eigene ID eingeben',
29
+ 'estimator.model.placeholder': 'Leer folgt dem Standardmodell der Sitzung; aus der Liste wählen oder eigene ID eingeben',
30
+ 'estimator.hostReuse': 'Der Host-Kanal nutzt die in DSH bereits konfigurierten Anbieter und Zugangsdaten — kein API-Schlüssel nötig, und hier wird keiner akzeptiert.',
31
+ 'estimator.hostRoute': 'Aktuelle Route: {route}.',
32
+ 'estimator.hostUnresolved': 'noch unbestimmt (wählen Sie ein Standardmodell in den DSH-Einstellungen oder geben Sie hier Anbieter und Modell an)',
33
+ 'estimator.baseUrl': 'Basis-URL des Endpunkts (/v1)',
34
+ 'estimator.model': 'Modell',
35
+ 'estimator.apiKey': 'API-Schlüssel (nur schreiben, nie angezeigt)',
36
+ 'estimator.apiKey.placeholder': 'Endpunkt-Schlüssel eingeben; Speichern beim Verlassen des Felds',
37
+ 'estimator.apiKey.set': 'Gesetzt · neuen Wert eingeben, um ihn zu überschreiben',
38
+ 'estimator.apiKey.clear': 'Löschen',
39
+ 'estimator.apiKey.overwrite': 'Ein Geheimnis ist gespeichert; neuen Wert eingeben und das Feld verlassen, um ihn zu überschreiben.',
40
+ 'detail.tokenpilot-inspired': 'Auf Ausbalanciert aufsetzend: Deduplizierungszeiger, Wiederherstellungs-Freistellung, Zusammenfassungsanker, Präfixstabilisierung und Lesestatus-Semantik; der Schätzer braucht einen separat konfigurierten Endpunkt',
41
+ 'profile.custom': 'Eigene / Experimentell',
42
+ 'profile.native': 'Native Referenz',
43
+ 'profile.off': 'Plugin aus',
44
+ 'profile.current': 'Aktuelles Profil',
45
+ 'detail.balanced': 'Reduziert frische Tool-Ergebnisse deterministisch; altert alte Ergebnisse bei hohem Füllstand',
46
+ 'detail.cache-strict': 'Altert den gesendeten Verlauf nur bei bestätigter Kapazitätslast; Anbieter-Cache-Treffer bleiben Best-Effort',
47
+ 'detail.savings': 'Nutzt kleinere Ziele und altert alte Tool-Ergebnisse früher; günstigere Anfragen sind nicht garantiert',
48
+ 'detail.adaptive': 'Nutzt Fresh/Aggregate von Ausbalanciert; altert den Verlauf nur, wenn benachbarte offizielle Nutzung und aktuelle offizielle Preise eine klare Ersparnis belegen',
49
+ 'detail.custom': 'Wählen Sie umgesetzte Stufen und gemessene Schwellenwerte für neue Sitzungen',
50
+ 'detail.native': 'Nutzt nur die native Kopf-/Schwanz-Kürzung von Harness',
51
+ 'detail.off': 'Deaktiviert die deterministische Auswahl; natives Auto-Compact bleibt separat konfiguriert',
52
+ 'autoCompact.title': 'Auto-Compact-Auslöseschwelle',
53
+ 'autoCompact.description': 'Das modellgetriebene Auto Compact löst aus, sobald die Anfrage-Auslastung diese Schwelle überschreitet. History-Auslöser des Standardprofils, Mindest-Freigabe und das neue Ende folgen der Schwelle; Änderungen wirken nur auf neue Sitzungen.',
54
+ 'autoCompact.inputLabel': 'Auto-Compact-Schwelle (%)',
55
+ 'autoCompact.sliderLabel': 'Schieberegler für die Auto-Compact-Schwelle',
56
+ 'autoCompact.quick': 'Schnellwerte',
57
+ 'autoCompact.riskLow': 'Unter dem empfohlenen Bereich: früheres Auslösen erhöht Zusammenfassungsaufrufe und Präfix-Neuaufbauten.',
58
+ 'autoCompact.riskHigh': 'Über dem empfohlenen Bereich: die Kontextkapazität teilen sich Anfragen und Ausgabe, späteres Auslösen verkleinert den Spielraum für einzelne große Ausgaben, Reasoning und Tool-Schemata.',
59
+ 'autoCompact.invalid': 'Die Auto-Compact-Schwelle muss eine ganze Zahl zwischen 50 und 90 sein.',
60
+ 'autoCompact.save': 'Auto-Compact-Schwelle speichern',
61
+ 'autoCompact.summaryHint': 'Auto-Compact-Schwelle: {percent} %. In den Einstellungen änderbar.',
62
+ 'codeSkeleton.title': 'Code-Skelettkomprimierung (opt-in)',
63
+ 'codeSkeleton.description': 'Unabhängiger Schalter, losgelöst von den Profilen oben. Aktiviert versucht ein überdimensioniertes frisches Quellcode-Tool-Ergebnis zuerst ein Skelett, das Imports und Deklarationen hält (Rümpfe ausgelassen, Fehlerzeilen behalten), und fällt bei Scheitern auf die ursprüngliche Kopf-Kürzung zurück. Erfordert den exakten Tokenizer; wirkt nur auf neue Sitzungen.',
64
+ 'codeSkeleton.enabled': 'Code-Skelettkomprimierung',
65
+ 'codeSkeleton.enabled.on': 'Ein',
66
+ 'codeSkeleton.enabled.off': 'Aus (Standard)',
67
+ 'custom.title': 'Eigene Strategie',
68
+ 'custom.settingsHint': 'Detaillierte Parameter unter Einstellungen > Kontextkomprimierung wählen bearbeiten.',
69
+ 'custom.sessionScope': 'Gespeicherte Änderungen greifen, wenn die aktuelle Compression-Runtime eine Sitzung zum ersten Mal beobachtet. Eine von dieser Runtime bereits beobachtete Sitzung behält ihre eingefrorene Strategie.',
70
+ 'custom.measurement': 'Zuerst der exakte DeepSeek-Tokenizer; sonst Tokenizer-Schätzung mit Kalibrierung als Rückfallebene. Nie chars/4. Die Cache-Zuordnung bleibt unbekannt.',
71
+ 'custom.unit': 'Kanonische Einheit',
72
+ 'custom.unit.tokens': 'Token',
73
+ 'custom.unit.contextPercent': 'Kontextprozent',
74
+ 'custom.enabled': 'Aktiviert',
75
+ 'custom.enabled.on': 'Ein',
76
+ 'custom.enabled.off': 'Aus',
77
+ 'custom.fresh.enabled': 'Fresh aktivieren',
78
+ 'custom.fresh.trigger': 'Fresh-Auslöser',
79
+ 'custom.fresh.target': 'Fresh-Ziel',
80
+ 'custom.aggregate.enabled': 'Aggregate aktivieren',
81
+ 'custom.aggregate.trigger': 'Aggregate-Auslöser',
82
+ 'custom.aggregate.target': 'Aggregate-Ziel',
83
+ 'custom.history.enabled': 'History aktivieren',
84
+ 'custom.history.trigger': 'History-Auslöser',
85
+ 'custom.history.keepRecentToolCalls': 'Geschützte letzte Tool-Aufrufe',
86
+ 'custom.history.keepRecentTokens': 'Geschütztes neues Ende der Tool-Ergebnisse',
87
+ 'custom.history.minReclaim': 'Mindest-Freigabe',
88
+ 'custom.prefixPolicy': 'Richtlinie für gesendete Präfixe',
89
+ 'custom.prefixPolicy.preserve': 'Bewahren bis Kapazitätsdruck',
90
+ 'custom.prefixPolicy.pressureBreak': 'Reguläres Verlaufsaltern erlauben',
91
+ 'custom.experimental': 'Experimentell: diese Regler gehören nur zum eigenen Profil und kommen nie in Standardprofile.',
92
+ 'custom.tailTrim.enabled': 'TailTrim aktivieren (experimentell)',
93
+ 'custom.tailTrim.trigger': 'TailTrim-Auslöser',
94
+ 'custom.tailTrim.warning': 'TailTrim erfordert den exakten Tokenizer und ersetzt höchstens eine vollständige, abgeschlossene, fehlerfreie Gruppe nur aus Tools durch eine wiederherstellbare Referenz. Es teilt sich mit History die geschützten letzten Tool-Aufrufe, das geschützte neue Ende der Tool-Ergebnisse und die Mindest-Freigabe. Es schreibt ein gesendetes Präfix um und kann Cache-Treffer verringern.',
95
+ 'custom.save': 'Eigene Strategie speichern',
96
+ 'custom.reset': 'Eigene Strategie zurücksetzen',
97
+ 'custom.invalid': 'Werte der eigenen Strategie sind ungültig.',
98
+ } satisfies Record<ContextCompressionLocaleKey, string>