dsh-context-compression-improved 0.10.0 → 0.10.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 (262) hide show
  1. package/README.md +15 -110
  2. package/README.zh.md +14 -104
  3. package/THIRD_PARTY_NOTICES.md +25 -7
  4. package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +2 -2
  5. package/{packages/selector/lib → lib}/client.js +73 -12
  6. package/package.json +129 -116
  7. package/screenshots.json +3 -6
  8. package/.agents/plans/improve/checklist.md +0 -32
  9. package/.agents/plans/improve/findings.md +0 -102
  10. package/.agents/plans/improve/spec.md +0 -53
  11. package/.agents/plans/improve/tasks.md +0 -70
  12. package/.gitattributes +0 -2
  13. package/.githooks/pre-push +0 -37
  14. package/.github/workflows/ci.yml +0 -39
  15. package/CHANGELOG.de.md +0 -580
  16. package/CHANGELOG.es.md +0 -588
  17. package/CHANGELOG.fr.md +0 -576
  18. package/CHANGELOG.it.md +0 -577
  19. package/CHANGELOG.ja.md +0 -261
  20. package/CHANGELOG.ko.md +0 -254
  21. package/CHANGELOG.md +0 -544
  22. package/CHANGELOG.ru.md +0 -554
  23. package/CHANGELOG.zh.md +0 -238
  24. package/CONTRIBUTING.md +0 -22
  25. package/README.de.md +0 -96
  26. package/README.es.md +0 -96
  27. package/README.fr.md +0 -96
  28. package/README.it.md +0 -96
  29. package/README.ja.md +0 -102
  30. package/README.ko.md +0 -102
  31. package/README.ru.md +0 -96
  32. package/SECURITY.md +0 -18
  33. package/assets/board.png +0 -0
  34. package/assets/context.png +0 -0
  35. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  36. package/docs/assets/context-compression-selector-settings.png +0 -0
  37. package/docs/compat-0.1.5-report.md +0 -77
  38. package/docs/installation.de.md +0 -104
  39. package/docs/installation.es.md +0 -104
  40. package/docs/installation.fr.md +0 -104
  41. package/docs/installation.it.md +0 -104
  42. package/docs/installation.ja.md +0 -78
  43. package/docs/installation.ko.md +0 -78
  44. package/docs/installation.md +0 -103
  45. package/docs/installation.ru.md +0 -104
  46. package/docs/installation.zh.md +0 -100
  47. package/docs/repair-log.md +0 -657
  48. package/eslint.config.js +0 -30
  49. package/packages/selector/LICENSE +0 -21
  50. package/packages/selector/README.md +0 -26
  51. package/packages/selector/README.zh.md +0 -24
  52. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  53. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  54. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  55. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  56. package/packages/selector/lib/style.css +0 -350
  57. package/packages/selector/package.json +0 -178
  58. package/packages/selector/screenshots.json +0 -3
  59. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -293
  60. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  61. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -85
  62. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  63. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  64. package/packages/selector/src/client/bridge-scope.ts +0 -125
  65. package/packages/selector/src/client/decode.ts +0 -57
  66. package/packages/selector/src/client/index.ts +0 -424
  67. package/packages/selector/src/client/locales/de.ts +0 -158
  68. package/packages/selector/src/client/locales/es.ts +0 -158
  69. package/packages/selector/src/client/locales/fr.ts +0 -158
  70. package/packages/selector/src/client/locales/it.ts +0 -158
  71. package/packages/selector/src/client/locales/ja.ts +0 -158
  72. package/packages/selector/src/client/locales/ko.ts +0 -158
  73. package/packages/selector/src/client/locales/ru.ts +0 -158
  74. package/packages/selector/src/client/locales.ts +0 -316
  75. package/packages/selector/src/client/monitor-fab.ts +0 -419
  76. package/packages/selector/src/client/preset-options.ts +0 -88
  77. package/packages/selector/src/client/savings-card.tsx +0 -269
  78. package/packages/selector/src/client/scope-face.ts +0 -24
  79. package/packages/selector/src/client/settings-section.tsx +0 -140
  80. package/packages/selector/src/compat/host-generation.ts +0 -96
  81. package/packages/selector/src/compat/llm-messages.ts +0 -50
  82. package/packages/selector/src/compat/settings-lease.ts +0 -108
  83. package/packages/selector/src/compat/tool-result.ts +0 -91
  84. package/packages/selector/src/css-modules.d.ts +0 -6
  85. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  86. package/packages/selector/src/estimator-catalog.ts +0 -104
  87. package/packages/selector/src/index.ts +0 -890
  88. package/packages/selector/src/invariant.ts +0 -113
  89. package/packages/selector/src/preset-overlay.ts +0 -749
  90. package/packages/selector/src/profiles.ts +0 -431
  91. package/packages/selector/src/pruner/content.ts +0 -198
  92. package/packages/selector/src/pruner/session.ts +0 -97
  93. package/packages/selector/src/pruner/state.ts +0 -61
  94. package/packages/selector/src/pruner/tuning.ts +0 -23
  95. package/packages/selector/src/pruner/types.ts +0 -78
  96. package/packages/selector/src/pruner.ts +0 -2914
  97. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  98. package/packages/selector/src/runtime/audit.ts +0 -320
  99. package/packages/selector/src/runtime/config.ts +0 -756
  100. package/packages/selector/src/runtime/custom-policy.ts +0 -278
  101. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  102. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  103. package/packages/selector/src/runtime/display-prefs.ts +0 -98
  104. package/packages/selector/src/runtime/measurement.ts +0 -444
  105. package/packages/selector/src/runtime/monitor.ts +0 -310
  106. package/packages/selector/src/runtime/panel-command.ts +0 -213
  107. package/packages/selector/src/runtime/reducers.ts +0 -1754
  108. package/packages/selector/src/runtime/retrieve.ts +0 -503
  109. package/packages/selector/src/runtime/savings-integral.ts +0 -117
  110. package/packages/selector/src/runtime/savings-projection.ts +0 -229
  111. package/packages/selector/src/runtime/savings-verify.ts +0 -446
  112. package/packages/selector/src/runtime/savings.ts +0 -526
  113. package/packages/selector/src/runtime/session-events.ts +0 -30
  114. package/packages/selector/src/runtime/session-file-decode.ts +0 -523
  115. package/packages/selector/src/runtime/stats-backfill.ts +0 -541
  116. package/packages/selector/src/runtime/stats-db.ts +0 -492
  117. package/packages/selector/src/runtime/stats-schema.ts +0 -123
  118. package/packages/selector/src/runtime/stats-sync.ts +0 -307
  119. package/packages/selector/src/runtime/summary-command.ts +0 -127
  120. package/packages/selector/src/runtime/tail-trim.ts +0 -176
  121. package/packages/selector/src/runtime/token-count.ts +0 -72
  122. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  123. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  124. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  125. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  126. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -81
  127. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  128. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  129. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  130. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  131. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  132. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -128
  133. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  134. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  135. package/packages/selector/src/runtime/toolclass.ts +0 -103
  136. package/packages/selector/src/runtime/types.ts +0 -365
  137. package/packages/selector/src/runtime/value.ts +0 -48
  138. package/packages/selector/src/settings-bridge.ts +0 -175
  139. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  140. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  141. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  142. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  143. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  144. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  145. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  146. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  147. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  148. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
  149. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  150. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  151. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  152. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  153. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  154. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  155. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  156. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -220
  157. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  158. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  159. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  160. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  161. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -86
  162. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  163. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  164. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  165. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  166. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  167. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  168. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  169. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  170. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  171. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  172. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  173. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  174. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  175. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
  176. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  177. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  178. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  179. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  180. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  181. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  182. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  183. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  184. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  185. package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
  186. package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
  187. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  188. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2781
  189. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  190. package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
  191. package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
  192. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  193. package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
  194. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  195. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  196. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  197. package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
  198. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  199. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  200. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
  201. package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -348
  202. package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
  203. package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
  204. package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
  205. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  206. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  207. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  208. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  209. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  210. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  211. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  212. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -119
  213. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  214. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  215. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  216. package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
  217. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  218. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  219. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  220. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  221. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  222. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  223. package/packages/selector/tsconfig.json +0 -11
  224. package/packages/selector/tsdown.client.config.ts +0 -102
  225. package/packages/selector/tsdown.config.ts +0 -20
  226. package/pnpm-workspace.yaml +0 -76
  227. package/scripts/capture-profile-baseline.mjs +0 -42
  228. package/scripts/cell-browser-e2e.mjs +0 -354
  229. package/scripts/generate-tokenizer-fixtures.py +0 -81
  230. package/scripts/generate-vision-fixtures.py +0 -208
  231. package/scripts/hosts.mjs +0 -78
  232. package/scripts/packed-components-smoke.mjs +0 -763
  233. package/scripts/packed-install-e2e.mjs +0 -1346
  234. package/scripts/sync-hosts.mjs +0 -174
  235. package/scripts/toolclass-corpus-replay.mjs +0 -281
  236. package/scripts/verify-release.mjs +0 -338
  237. package/tests/TEST_INVENTORY.md +0 -41
  238. package/tsconfig.base.json +0 -18
  239. package/tsconfig.json +0 -7
  240. package/tsconfig.tests.json +0 -15
  241. package/vitest.built.config.ts +0 -9
  242. package/vitest.config.ts +0 -54
  243. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  244. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  245. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  246. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  247. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  248. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  249. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  250. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  251. /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
  252. /package/{packages/selector/lib → lib}/client.d.ts +0 -0
  253. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  254. /package/{packages/selector/lib → lib}/index.js +0 -0
  255. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  256. /package/{packages/selector/lib → lib}/invariant.js +0 -0
  257. /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
  258. /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
  259. /package/{packages/selector/lib → lib}/pruner.js +0 -0
  260. /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
  261. /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
  262. /package/{packages/selector/lib → lib}/tool-result.js +0 -0
package/README.md CHANGED
@@ -1,121 +1,26 @@
1
1
  # dsh-context-compression-improved
2
2
 
3
- > An improved fork of [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) — an auditable tool-result context-compression selector for DeepSeek Harness — adding an orthogonal **code-skeleton compression gate**.
3
+ The installable Product Bundle for the unofficial community DeepSeek Harness context-compression selector.
4
4
 
5
- [中文说明](README.zh.md) · [日本語](README.ja.md) · [한국어](README.ko.md) · [Français](README.fr.md) · [Deutsch](README.de.md) · [Italiano](README.it.md) · [Русский](README.ru.md) · [Español](README.es.md) · [Changelog](CHANGELOG.md) · [Installation guide](docs/installation.md)
6
-
7
- > [!NOTE]
8
- > **What this fork adds on top of upstream 0.1.0:**
9
- >
10
- > - An orthogonal **code-skeleton compression gate** (`codeSkeleton.enabled`, default off): the first exposure of an oversized fresh source-code tool result can keep a skeleton of imports and declarations — bodies elided, error lines kept — before the regular reducers run.
11
- > - A settings toggle for that gate in the same selector settings section, independent of every compression profile.
12
- > - An ESLint baseline wired into CI, a `test:watch` TDD loop, and documentation in English, Simplified Chinese, Japanese, and Korean.
13
-
14
- > [!IMPORTANT]
15
- > This project supports **DeepSeek models only**. Lossless measurement and lossy compression depend on the bundled official DeepSeek tokenizers (`deepseek-v4-flash`, `deepseek-v4-pro`, `deepseek-v4-flash-vision-exp`). Everything else fails open and keeps original tool results. See the [upstream README](https://github.com/WilliamShi666/dsh-context-compression-selector#model-support-and-safety) for the full safety model.
16
-
17
- > [!TIP]
18
- > **Recommended: connect DeepSeek with your own API key via a custom Responses API endpoint.** Prefer a custom OpenAI-compatible endpoint (`/v1/responses`) over the official-account Messages API route: it does not go through the Anthropic-style message serialization, so requests never trip message-format issues or `tool_use`/`tool_result` pairing validation (the official route's resume-replay 400s cannot be repaired from the plugin side), and you can switch endpoint nodes over time and keep existing sessions running.
19
-
20
- <!-- host-compat:begin — generated by scripts/sync-hosts.mjs from scripts/hosts.mjs; DO NOT EDIT -->
21
- - **Supported DSH hosts:** `0.1.0-rc.2` `0.1.0-rc.3` `0.1.0-rc.6` `0.1.0-rc.7` `0.1.0-rc.8` `0.1.1-rc.1` `0.1.1-rc.2` `0.1.2-rc.1` `0.1.5-rc.1` `0.1.5-rc.2` `0.1.5-rc.3` `0.1.7-rc.1` `0.1.7-rc.2` `0.2.0-rc.1` `0.2.0-rc.2` `0.2.1-rc.1` `0.2.1-rc.2` `0.2.1-rc.3` (18 rc releases across lines 0.1.0 / 0.1.1 / 0.1.2 / 0.1.5 / 0.1.7 / 0.2.0 / 0.2.1)
22
- <!-- host-compat:end -->
23
-
24
- ## What it is
25
-
26
- Long-running agent tasks accumulate a large amount of tool output. This community plugin adds selectable, auditable policies for reducing that tool-result context without modifying DeepSeek Harness core:
27
-
28
- - **Fresh** pre-compresses a newly oversized tool-result segment before the model receives it.
29
- - **Aggregate** pre-compresses fresh material again when it still grows beyond its budget.
30
- - **History / micro-compact** replaces eligible old tool results while preserving recent working context.
31
- - **TailTrim** is an optional Custom-only tail reduction path.
32
- - **Native** preserves the Harness-style head/middle/tail trimming as one explicit profile.
33
- - **Code skeleton (new, orthogonal gate)** — see below.
34
-
35
- Every decision is recorded: stage, reducer, trigger, skip reason, and exact token counts where available.
36
-
37
- ## Code skeleton gate (new)
38
-
39
- When the gate is enabled, an oversized **fresh source-code tool result** (for example a large `read_file`) first tries a skeleton reduction: imports and type/function/class declarations are kept, function bodies are elided with a marker, and error lines inside elided bodies are preserved. If the skeleton cannot be produced or verified, the result falls back to the original head pruning — the gate can never make context worse.
40
-
41
- Properties:
42
-
43
- - **Orthogonal**: independent of the selected profile (`balanced`, `savings`, `cache-strict`, `adaptive`, `custom`, `off`, `native`). All profiles get the gate.
44
- - **Off by default**: `codeSkeleton: { enabled: false }` until you turn it on.
45
- - **Measurement-gated**: requires the exact DeepSeek tokenizer; without it the plugin fails open.
46
- - **Session-frozen**: like all selector settings, changes affect newly observed sessions only.
47
- - **Strictly parsed**: `codeSkeleton` must be exactly `{ enabled: boolean }`; malformed values throw on the runtime side and show as unreadable in the browser UI.
48
-
49
- ## Settings UI
50
-
51
- Choose a compression profile, set the Auto Compact trigger level, and toggle code-skeleton compression in the same settings section. The toggle saves on change and shows the saved state on reload.
52
-
53
- ![Context Compression Selector settings UI](docs/assets/context-compression-selector-settings.png)
54
-
55
- ## Monitoring UI
56
-
57
- While compression runs, the plugin gives you a live view of what it saves: a **compression monitor** panel — net/gross savings, offsets, context usage, cache-hit rate, cost estimate, and the turn-tail intent-summary state, with a per-session resume/disable override right in the panel — next to the session's context trend chart.
58
-
59
- ![Compression monitor panel](assets/board.png)
60
-
61
- Context trend for a session under compression: per-step / per-turn token composition with a timing overlay; the scissors mark where reductions landed.
62
-
63
- ![Context trend chart](assets/context.png)
64
-
65
- ## Stats semantics and persistence
66
-
67
- Savings are reported in three distinct semantics — never merged:
68
-
69
- - **Stock (currently active)** — net savings still in effect on the live surface; it rises and falls as compressed content moves in and out.
70
- - **Cumulative (across N calls)** — the stock sampled at every request boundary and summed; answers "how much was saved historically" and survives host restarts.
71
- - **Money saved** — cumulative weighted by cache hit/miss at official list prices (deepseek-official official routes only; other routes show the token figure).
72
-
73
- Stats persist in SQLite (`~/.dsh/storages/dsh-context-compression/stats.sqlite`) across host restarts; a missing driver or write failure degrades visibly (panel badge, in-memory fallback). Historical sessions are backfilled from on-disk behavior records (host `sessionQuery` service preferred, read-only session-log parsing as fallback — session files are never written). Records contain counts, sequence numbers, session identifiers, and enum component names only; original text and free-form text never enter the database. Delete the file to reset stats completely.
74
-
75
- The `/ccip` command drives the panel in real time: `rows stock|total|money on|off`, `mode compact|full`, `session <id|latest|off>`, `flush`, `backfill pause|resume|status`.
76
-
77
- ## Install
78
-
79
- **Recommended: install from npm.** One version covers every supported Harness line — `latest` carries the full 17-rc enum (0.1.0-rc.2 → 0.2.1-rc.2); the runtime picks per-line code paths on its own.
5
+ **0.1.0 highlights:** DeepSeek V4 Flash Vision's official tokenizer is included; users can choose the model-driven Auto Compact threshold; standard profile watermarks and compression parameters follow that choice.
80
6
 
81
7
  ```sh
82
- dsh plugin --profile web add dsh-context-compression-improved@latest
83
- dsh --profile web --dump-config
84
- ```
85
-
86
- From source (alternative — the internal package names intentionally stay upstream's):
87
-
88
8
  ```sh
89
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
90
- cd dsh-context-compression-improved
91
- pnpm install --frozen-lockfile
92
- pnpm build
9
+ dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
10
+ # DSH 0.1.2 line:
11
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
12
+ dsh --profile web --dump-config
93
13
  ```
94
-
95
- Then pack the selector package and add it to a Harness profile — the full walkthrough, including verification and uninstall steps, is in the [installation guide](docs/installation.md).
96
-
97
- ## Development
98
-
99
- ```sh
100
- pnpm install --frozen-lockfile
101
- pnpm lint # ESLint baseline (also enforced in CI)
102
- pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
103
- pnpm test # full vitest suite
104
- pnpm test:watch # TDD loop: write the failing regression first, then make it pass
105
- pnpm build
106
- pnpm verify:release
14
+ dsh --profile web --dump-config
107
15
  ```
108
16
 
109
- Contributions follow the upstream discipline: add the failing regression first, keep every production change inside this repository, and explain “triggered”, “enabled but skipped”, and fail-open evidence separately. See [CONTRIBUTING.md](CONTRIBUTING.md).
110
-
111
- ## Compatibility
112
-
113
- - Built and tested against the official DeepSeek Harness releases; peers declare the full supported-hosts enum (`0.1.0-rc.2` → `0.2.1-rc.2`, seven lines) and the plugin uses public plugin and profile APIs only. The supported list is generated into the managed block above by `scripts/sync-hosts.mjs` from `scripts/hosts.mjs`.
114
- - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
115
- - The plugin uses only public Harness extension APIs and does not modify Harness core code. Unofficial community project, not affiliated with or endorsed by DeepSeek.
17
+ This one command installs the single `dsh-context-compression-improved` package: the compression
18
+ runtime, the Host settings, the Web UI and the reversible preset overlay all ship in it.
19
+ The Bundle contributes Host settings, the Web UI, and a reversible preset overlay. All presets
20
+ except the exact built-in `minimal` id receive the compression stack; switching non-Minimal
21
+ presets preserves the saved selector settings. Minimal pauses plugin compression without
22
+ deleting the setting.
116
23
 
117
- ## Credits and license
24
+ Verified compatibility: DeepSeek Harness `dsh-v0.1.1-rc.2` and `dsh-v0.1.2-alpha.5`, Node `^22.19.0 || >=24`. No Harness core patch is required.
118
25
 
119
- - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
120
- - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
121
- - MIT — see [LICENSE](LICENSE) (upstream copyright notice retained) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for bundled tokenizer provenance.
26
+ See the [full README](https://github.com/WilliamShi666/dsh-context-compression-improved#readme) for profiles, defaults, audit evidence, Adaptive/cache limitations, upgrade/removal, and security guidance. This package is not affiliated with or endorsed by DeepSeek.
package/README.zh.md CHANGED
@@ -1,114 +1,24 @@
1
1
  # dsh-context-compression-improved
2
2
 
3
- > [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) 的改进版 fork——面向 DeepSeek Harness 的可审计工具结果上下文压缩选择器,新增正交的**代码骨架压缩门*。
3
+ 这是可直接安装的非官方社区 DeepSeek Harness 上下文压缩选择器 Product Bundle。
4
4
 
5
- [English](README.md) · [日本語](README.ja.md) · [한국어](README.ko.md) · [Français](README.fr.md) · [Deutsch](README.de.md) · [Italiano](README.it.md) · [Русский](README.ru.md) · [Español](README.es.md) · [更新日志](CHANGELOG.zh.md) · [安装教程](docs/installation.zh.md)
6
-
7
- > [!NOTE]
8
- > **本fork 在上游 0.1.0 之上新增:*
9
- >
10
- > - 正交的**代码骨架压缩门**(`codeSkeleton.enabled`,默认关闭):超大源码类工具结果首次曝光时,可先保留导入与声明的骨架——省略函数体并保留错误行——再进入常规 reducer。
11
- > - 同一选择器设置区内新增该门的开关,独立于所有压缩 Profile。
12
- > - 接入 CI 的 ESLint 基线、`test:watch` TDD 环路,以及英/中日韩四语文档。
13
-
14
- > [!IMPORTANT]
15
- > 本项目仅支持 **DeepSeek 模型**。无损测量与有损压缩依赖内置的 DeepSeek 官方 tokenizer(`deepseek-v4-flash`、`deepseek-v4-pro`、`deepseek-v4-flash-vision-exp`)。其余模型一律 fail-open 并保留原始工具结果。完整安全模型见[上游 README](https://github.com/WilliamShi666/dsh-context-compression-selector#model-support-and-safety)。
16
-
17
- > [!TIP]
18
- > **推荐接入方式:用 API key 以自定义 Responses API 连接 DeepSeek。** 建议走自定义 OpenAI 兼容端点(`/v1/responses`)而不是官方账号的 Messages API 路由:前者不经过 Anthropic 风格的消息序列化,不会因为 message 格式而出现问题,可避开 `tool_use`/`tool_result` 配对校验限制(官方路由 resume-replay 时的 400 插件侧无法修复);也便于按时间切换节点后接续会话。
19
-
20
- <!-- host-compat:begin — generated by scripts/sync-hosts.mjs from scripts/hosts.mjs; DO NOT EDIT -->
21
- - **支持的 DSH 宿主:** `0.1.0-rc.2` `0.1.0-rc.3` `0.1.0-rc.6` `0.1.0-rc.7` `0.1.0-rc.8` `0.1.1-rc.1` `0.1.1-rc.2` `0.1.2-rc.1` `0.1.5-rc.1` `0.1.5-rc.2` `0.1.5-rc.3` `0.1.7-rc.1` `0.1.7-rc.2` `0.2.0-rc.1` `0.2.0-rc.2` `0.2.1-rc.1` `0.2.1-rc.2` `0.2.1-rc.3`(覆盖 0.1.0 / 0.1.1 / 0.1.2 / 0.1.5 / 0.1.7 / 0.2.0 / 0.2.1 七条线共 18 个 rc)
22
- <!-- host-compat:end -->
23
-
24
- ## 它是什么
25
-
26
- 长时运行的 agent 任务会积累大量工具输出。本社区插件在不修改 DeepSeek Harness 核心的前提下,提供可选、可审计的工具结果上下文压缩策略:
27
-
28
- - **Fresh**:在模型收到之前,预压缩新近超限的工具结果段。
29
- - **Aggregate**:当 Fresh 压缩后仍超出预算时再次预压缩。
30
- - **History / micro-compact**:在保护近期工作上下文的前提下替换符合条件的旧工具结果。
31
- - **TailTrim**:仅在 Custom 下可选的尾窗收缩路径。
32
- - **Native**:把 Harness 原生头中尾裁剪保留为一个显式 Profile。
33
- - **代码骨架(新增,正交门)**——见下节。
34
-
35
- 每个决策都会留痕:阶段、reducer、触发原因、跳过原因,以及可得时的精确 token 数。
36
-
37
- ## 代码骨架门(新增)
38
-
39
- 开启后,超大**源码类新工具结果**(例如大型 `read_file`)会先尝试骨架化压缩:保留导入与类型/函数/类声明,省略函数体并加占位标记,被省略函数体内的错误行予以保留。若骨架无法生成或无法通过验证,则回退到原有的头部裁剪——这道门不会让上下文变得更差。
40
-
41
- 特性:
42
-
43
- - **正交**:独立于所选 Profile(`balanced`、`savings`、`cache-strict`、`adaptive`、`custom`、`off`、`native`),所有 Profile 都能拿到这道门。
44
- - **默认关闭**:`codeSkeleton: { enabled: false }`,需要显式开启。
45
- - **测量前置**:需要精确 DeepSeek tokenizer;不可用时 fail-open。
46
- - **会话冻结**:与所有选择器设置一致,修改只影响新观察的会话。
47
- - **严格解析**:`codeSkeleton` 必须恰好是 `{ enabled: boolean }`;畸形输入在运行时侧抛错、浏览器侧显示不可读。
48
-
49
- ## 设置界面
50
-
51
- 在同一设置区内选择压缩 Profile、调整 Auto Compact 触发水位,并开关代码骨架压缩。开关即改即存,刷新后显示已保存状态。
52
-
53
- ![Context Compression Selector 设置界面](docs/assets/context-compression-selector-settings.png)
54
-
55
- ## 监控界面
56
-
57
- 压缩运行时,插件提供节省量的实时视图:**压缩监控**悬浮面板——净节省/毛节省/抵消/上下文占用/缓存命中率/成本估算/回合末意图摘要状态,面板内可直接对当前会话恢复或停用——以及会话的上下文趋势图。
58
-
59
- ![压缩监控面板](assets/board.png)
60
-
61
- 压缩会话的上下文趋势:逐步骤/轮次的 token 组成与耗时叠加,剪刀标记指示裁剪/折叠落点。
62
-
63
- ![上下文趋势图](assets/context.png)
64
-
65
- ## 统计口径与持久化
66
-
67
- 节省统计分三个口径,语义不同、互不替代:
68
-
69
- - **存量(当前生效)**——当前上下文面上仍在生效的净节省,随压缩内容进出面而涨落;
70
- - **累计(按 N 次 call)**——每个请求边界对存量的采样求和,回答"历史上总共省了多少",跨宿主重启保留;
71
- - **省钱估计**——累计按缓存命中/未命中分权折算官方牌价(仅 deepseek-official 官方路由可解,其余只显示 token 口径)。
72
-
73
- 统计经 SQLite 持久化(`~/.dsh/storages/dsh-context-compression/stats.sqlite`),跨宿主重启保留;驱动缺席或写失败时可见降级(面板标注,统计退回内存口径)。历史会话可从磁盘行为记录回填统计(宿主 sessionQuery 服务优先,缺席时只读解析会话日志,绝不写会话文件)。记录只含计数/序号/会话标识与组件枚举名,原文与自由文本绝不入库;删除该文件即可完全重置统计。
74
-
75
- `/ccip` 命令提供面板实时控制:`rows stock|total|money on|off`(行开关)、`mode compact|full`、`session <id|latest|off>`(聚焦会话)、`flush`(强制落库)、`backfill pause|resume|status`(回填开关)。
76
-
77
- ## 安装
78
-
79
- 从源码构建并安装 —— 本 fork 亦已发布到 npm,包名为 `dsh-context-compression-improved`(单版本覆盖全部支持线:`latest` 携带 17 个 rc 的完整枚举 0.1.0-rc.2 → 0.2.1-rc.2,分线代码路径由运行时自行选择);内部包名有意保持与上游一致:
5
+ **0.1.0 更新:**已加入 DeepSeek V4 Flash 视觉模型的官方 tokenizer;用户可选择模型驱动 Auto Compact 的触发阈值;标准 Profile 的水位与压缩参数会随该选择联动。
80
6
 
81
7
  ```sh
82
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
83
- cd dsh-context-compression-improved
84
- pnpm install --frozen-lockfile
85
- pnpm build
86
- ```
87
-
88
- 随后打包 selector 包并安装到某个 Harness Profile——完整步骤(含验证与卸载)见[安装教程](docs/installation.zh.md)。
89
-
90
- ## 开发
91
-
92
8
  ```sh
93
- pnpm install --frozen-lockfile
94
- pnpm lint # ESLint 基线(CI 同步强制)
95
- pnpm typecheck # runtime + selector + tests tsc,含 bundle 步
96
- pnpm test # vitest 全量
97
- pnpm test:watch # TDD 环路:先写失败的回归用例,再让它通过
98
- pnpm build
99
- pnpm verify:release
9
+ dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
10
+ # DSH 0.1.2 line:
11
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
12
+ dsh --profile web --dump-config
13
+ ```
14
+ dsh --profile web --dump-config
100
15
  ```
101
16
 
102
- 贡献遵循上游纪律:先写失败的回归用例;所有生产改动收敛在本仓库内;对“已触发”“已启用但跳过”“fail-open”分别给出证据。见 [CONTRIBUTING.md](CONTRIBUTING.md)。
103
-
104
- ## 兼容性
105
-
106
- - 基于官方 DeepSeek Harness 发布版构建并测试;peers 声明完整支持清单枚举(`0.1.0-rc.2` → `0.2.1-rc.2` 七条线),仅使用公开的插件与 Profile API。支持清单由 `scripts/sync-hosts.mjs` 从 `scripts/hosts.mjs` 生成到上方管理块。
107
- - 需要 Node `^22.19.0 || >=24` 与 pnpm `11.7.0`。
108
- - 插件只使用 Harness 公开扩展 API,不修改 Harness 核心代码。非官方社区项目,与 DeepSeek 无隶属或背书关系。
17
+ 这一条命令安装单一的 `dsh-context-compression-improved` 包:压缩运行时、Host 设置、Web UI
18
+ 与可逆 preset overlay 全部包含在其中。除 id 精确等于内置 `minimal` 的 preset 外,
19
+ 其他 preset 都会获得压缩能力;非 Minimal preset 之间切换时已保存设置保持不变。
20
+ Minimal 只暂停插件压缩,不删除设置。
109
21
 
110
- ## 致谢与许可
22
+ 已验证兼容 DeepSeek Harness `dsh-v0.1.1-rc.2` 与 `dsh-v0.1.2-alpha.5`,Node `^22.19.0 || >=24`。不需要修改 Harness 核心。
111
23
 
112
- - 上游项目与全部既有工作:[WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector),作者 WilliamShi666(MIT)。
113
- - fork 新增内容(代码骨架门、工具链、多语文档):drscrewdriver。
114
- - MIT——见 [LICENSE](LICENSE)(保留上游版权声明);内置 tokenizer 来源见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
24
+ Profile、默认值、审计证据、Adaptive/cache 限制、升级/卸载与安全说明见[完整 README](https://github.com/WilliamShi666/dsh-context-compression-improved#readme)。本包与 DeepSeek 无隶属或背书关系。
@@ -1,14 +1,32 @@
1
1
  # Third-party notices
2
2
 
3
- This community project contains code adapted from the MIT-licensed [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness), verified against tag `dsh-v0.1.1-rc.2`, commit `b150a551b8d465e31e418e1b2eaf5e79bbb7d28e`.
3
+ Portions of this package are adapted from the MIT-licensed DeepSeek Harness, verified against `dsh-v0.1.1-rc.2` (`b150a551b8d465e31e418e1b2eaf5e79bbb7d28e`).
4
4
 
5
- The runtime package distributes tokenizer assets from these pinned official repositories, both under the MIT license:
5
+ ## DeepSeek Harness MIT notice
6
6
 
7
- - [deepseek-ai/DeepSeek-V4-Pro](https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro) at revision `0e1a0e5e52aea73055f50fef6f2423db370265b6`, recorded in `packages/selector/assets/deepseek-v4/manifest.json`.
8
- - [deepseek-ai/DeepSeek-V4-Flash-Vision-Exp](https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-Vision-Exp) at revision `6821d6ad3681a4b137b066b76094fa82ebd0a380`, recorded in `packages/selector/assets/deepseek-v4-vision-exp/manifest.json`. The vision model is served by this distinct tokenizer, never as an alias of the text tokenizer.
7
+ Copyright (c) 2026 DeepSeek
9
8
 
10
- Exact file sizes and SHA-256 values are recorded in each directory's `manifest.json`; the upstream license text ships beside the assets.
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
11
15
 
12
- The install-time production dependency closure also contains `@huggingface/tokenizers` (Apache-2.0), `js-yaml` (MIT), and its `argparse` dependency (Python-2.0). Each dependency ships its own license text in its NPM package.
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
13
18
 
14
- The names DeepSeek and DeepSeek Harness identify upstream projects only. They do not imply affiliation or endorsement.
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ This package carries the official DeepSeek tokenizer assets, with their exact license and
28
+ provenance manifests, under `assets/`.
29
+
30
+ This package depends on `js-yaml` under MIT; its production dependency `argparse` is licensed under Python-2.0. Their NPM packages carry the dependency license texts.
31
+
32
+ This is an unofficial community package and is not endorsed by DeepSeek.
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-context-compression-improved",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "main": "./lib/index.js",
5
5
  "description": "Auditable tool-result context-compression selector with code-skeleton gate for DeepSeek Harness",
6
6
  "engines": {
7
- "dsh": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3"
7
+ "dsh": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4"
8
8
  },
9
9
  "contributes": {
10
10
  "tools": [],
@@ -1587,6 +1587,56 @@ window.__ModuleLoader__.load({
1587
1587
  } : void 0;
1588
1588
  }
1589
1589
  //#endregion
1590
+ //#region src/client/fab-pos.ts
1591
+ const clamp01 = (v) => Math.max(0, Math.min(1, v));
1592
+ const isFin = (v) => typeof v === "number" && Number.isFinite(v);
1593
+ /** 除法结果的归一化兜底:±Infinity 夹到 1/0,NaN 视为无效。 */
1594
+ const divClamp = (px, vpSize) => {
1595
+ const q = px / vpSize;
1596
+ if (q === Infinity) return 1;
1597
+ if (q === -Infinity) return 0;
1598
+ if (!Number.isFinite(q)) return null;
1599
+ return clamp01(q);
1600
+ };
1601
+ /**
1602
+ * 读入 localStorage 存量形状并归一为比例态:
1603
+ * - {fx,fy} 均有限 → 夹回 [0,1] 直用;
1604
+ * - 否则 {x,y} 均有限(旧像素格式)→ 按当前视口除法换算(±Infinity 夹 1/0,NaN 拒);
1605
+ * - 其余(非对象/数组/字段缺失/脏值)→ null,由调用方走默认位。
1606
+ */
1607
+ function normalizeStored(raw, vp) {
1608
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
1609
+ const r = raw;
1610
+ if (isFin(r.fx) && isFin(r.fy)) return {
1611
+ fx: clamp01(r.fx),
1612
+ fy: clamp01(r.fy)
1613
+ };
1614
+ if (!isFin(r.x) || !isFin(r.y)) return null;
1615
+ const fx = divClamp(r.x, vp.vw);
1616
+ const fy = divClamp(r.y, vp.vh);
1617
+ if (fx === null || fy === null) return null;
1618
+ return {
1619
+ fx,
1620
+ fy
1621
+ };
1622
+ }
1623
+ /** 像素 → 比例,4 位小数舍入;像素本身可为 clamp 后越内值(先夹再存)。 */
1624
+ function toRatio(pos, vp) {
1625
+ const fx = divClamp(pos.x, vp.vw);
1626
+ const fy = divClamp(pos.y, vp.vh);
1627
+ return {
1628
+ fx: fx === null ? 0 : fx,
1629
+ fy: fy === null ? 0 : fy
1630
+ };
1631
+ }
1632
+ /** 比例 → 像素(不做 clamp——落位后由接线层既有 clamp 收边)。 */
1633
+ function fromRatio(r, vp) {
1634
+ return {
1635
+ x: Math.round(clamp01(r.fx) * vp.vw),
1636
+ y: Math.round(clamp01(r.fy) * vp.vh)
1637
+ };
1638
+ }
1639
+ //#endregion
1590
1640
  //#region src/client/monitor-fab.ts
1591
1641
  /**
1592
1642
  * 压缩监控浮动球 + 面板(task: cci-monitor-fab;骨架整编自 pm 撤下的
@@ -1685,27 +1735,38 @@ window.__ModuleLoader__.load({
1685
1735
  <div class="recent" data-recent></div>
1686
1736
  `;
1687
1737
  document.body.append(fab, panel);
1688
- let pos;
1738
+ const vpFab = () => ({
1739
+ vw: window.innerWidth,
1740
+ vh: window.innerHeight,
1741
+ w: 42,
1742
+ h: 42
1743
+ });
1744
+ let ratio;
1689
1745
  try {
1690
- pos = JSON.parse(localStorage.getItem(POS_KEY) ?? "null") ?? {
1691
- x: Math.max(8, window.innerWidth - 66),
1692
- y: Math.max(8, Math.round(window.innerHeight * .6))
1693
- };
1746
+ ratio = normalizeStored(JSON.parse(localStorage.getItem(POS_KEY) ?? "null"), vpFab());
1694
1747
  } catch {
1695
- pos = {
1696
- x: Math.max(8, window.innerWidth - 66),
1697
- y: Math.max(8, Math.round(window.innerHeight * .6))
1698
- };
1748
+ ratio = null;
1699
1749
  }
1750
+ let pos = ratio !== null ? fromRatio(ratio, vpFab()) : {
1751
+ x: Math.max(8, window.innerWidth - 66),
1752
+ y: Math.max(8, Math.round(window.innerHeight * .6))
1753
+ };
1700
1754
  const clamp = (p) => ({
1701
1755
  x: Math.max(8, Math.min(window.innerWidth - 50, p.x)),
1702
1756
  y: Math.max(8, Math.min(window.innerHeight - 50, p.y))
1703
1757
  });
1704
- const place = () => {
1758
+ /** 像素态直接落位: clamp → 镜像回 ratio → 写 style(拖拽帧专用,不回推 ratio)。 */
1759
+ const paint = () => {
1705
1760
  pos = clamp(pos);
1761
+ ratio = toRatio(pos, vpFab());
1706
1762
  fab.style.left = `${pos.x}px`;
1707
1763
  fab.style.top = `${pos.y}px`;
1708
1764
  };
1765
+ /** 从存储比例全量重推导(init + resize): 角落随视口缩放跟随,再夹回屏内。 */
1766
+ const place = () => {
1767
+ if (ratio !== null) pos = fromRatio(ratio, vpFab());
1768
+ paint();
1769
+ };
1709
1770
  place();
1710
1771
  window.addEventListener("resize", place);
1711
1772
  const makeDrag = (el, key) => {
@@ -1740,12 +1801,12 @@ window.__ModuleLoader__.load({
1740
1801
  });
1741
1802
  if (Math.abs(next.x - pos.x) > 2 || Math.abs(next.y - pos.y) > 2) moved = true;
1742
1803
  pos = key === "fab" ? next : pos;
1743
- if (key === "fab") place();
1804
+ if (key === "fab") paint();
1744
1805
  });
1745
1806
  el.addEventListener("pointerup", () => {
1746
1807
  active = false;
1747
1808
  if (moved && key === "fab") try {
1748
- localStorage.setItem(POS_KEY, JSON.stringify(pos));
1809
+ localStorage.setItem(POS_KEY, JSON.stringify(ratio ?? toRatio(pos, vpFab())));
1749
1810
  } catch {}
1750
1811
  });
1751
1812
  el.addEventListener("pointercancel", () => {