dsh-context-compression-improved 0.9.5 → 0.9.8

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 (141) hide show
  1. package/.gitattributes +2 -2
  2. package/.githooks/pre-push +37 -37
  3. package/CHANGELOG.md +4 -0
  4. package/CONTRIBUTING.md +22 -22
  5. package/LICENSE +21 -21
  6. package/README.de.md +3 -3
  7. package/README.es.md +3 -3
  8. package/README.fr.md +3 -3
  9. package/README.it.md +3 -3
  10. package/README.ja.md +16 -3
  11. package/README.ko.md +16 -3
  12. package/README.md +16 -3
  13. package/README.ru.md +3 -3
  14. package/README.zh.md +16 -3
  15. package/SECURITY.md +18 -18
  16. package/THIRD_PARTY_NOTICES.md +14 -14
  17. package/assets/board.png +0 -0
  18. package/assets/context.png +0 -0
  19. package/docs/compat-0.1.5-report.md +77 -77
  20. package/docs/installation.de.md +2 -2
  21. package/docs/installation.es.md +2 -2
  22. package/docs/installation.fr.md +2 -2
  23. package/docs/installation.it.md +2 -2
  24. package/docs/installation.ja.md +2 -2
  25. package/docs/installation.ko.md +2 -2
  26. package/docs/installation.md +2 -2
  27. package/docs/installation.ru.md +2 -2
  28. package/docs/installation.zh.md +2 -2
  29. package/docs/repair-log.md +657 -657
  30. package/package.json +7 -6
  31. package/packages/selector/LICENSE +21 -21
  32. package/packages/selector/README.md +26 -26
  33. package/packages/selector/README.zh.md +24 -24
  34. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
  35. package/packages/selector/cordis.patch.yml +27 -27
  36. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
  37. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
  38. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
  39. package/packages/selector/dsh.plugin.json +2 -2
  40. package/packages/selector/lib/index.js +25 -0
  41. package/packages/selector/lib/pruner.d.ts +1 -1
  42. package/packages/selector/lib/pruner.js +1 -2
  43. package/packages/selector/lib/style.css +53 -53
  44. package/packages/selector/lib/tail-trim.js +25 -2
  45. package/packages/selector/package.json +22 -21
  46. package/packages/selector/screenshots.json +3 -3
  47. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
  48. package/packages/selector/src/client/EstimatorControls.tsx +277 -277
  49. package/packages/selector/src/client/preset-options.ts +88 -88
  50. package/packages/selector/src/client/scope-face.ts +24 -24
  51. package/packages/selector/src/compat/llm-messages.ts +50 -0
  52. package/packages/selector/src/css-modules.d.ts +6 -6
  53. package/packages/selector/src/estimator-catalog.ts +104 -104
  54. package/packages/selector/src/index.ts +27 -0
  55. package/packages/selector/src/invariant.ts +113 -113
  56. package/packages/selector/src/pruner/tuning.ts +23 -23
  57. package/packages/selector/src/pruner/types.ts +78 -78
  58. package/packages/selector/src/pruner.ts +5 -1
  59. package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
  60. package/packages/selector/src/runtime/audit.ts +303 -303
  61. package/packages/selector/src/runtime/custom-policy.ts +278 -278
  62. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
  63. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
  64. package/packages/selector/src/runtime/session-events.ts +30 -30
  65. package/packages/selector/src/runtime/tail-trim.ts +2 -1
  66. package/packages/selector/src/runtime/token-count.ts +72 -72
  67. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -233
  68. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -204
  69. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
  70. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
  71. package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
  72. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
  73. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -53
  74. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -65
  75. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -125
  76. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -37
  77. package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
  78. package/packages/selector/src/runtime/toolclass.ts +103 -103
  79. package/packages/selector/src/runtime/value.ts +48 -48
  80. package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
  81. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
  82. package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
  83. package/packages/selector/tests/helpers/legacy-namespace.ts +35 -35
  84. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  85. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  86. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  87. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  88. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  89. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
  90. package/packages/selector/tests/public/package-contract.client.spec.ts +4 -4
  91. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
  92. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
  93. package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
  94. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
  95. package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
  96. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
  97. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
  98. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
  99. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
  100. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
  101. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
  102. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
  103. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
  104. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -62
  105. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -156
  106. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
  107. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
  108. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
  109. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
  110. package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
  111. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
  112. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -154
  113. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
  114. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
  115. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
  116. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
  117. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
  118. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
  119. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
  120. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
  121. package/packages/selector/tests/runtime/value.spec.ts +23 -23
  122. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -269
  123. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
  124. package/packages/selector/tests/support/mock-adapter.ts +37 -37
  125. package/packages/selector/tests/support/ui-primitives.tsx +34 -34
  126. package/packages/selector/tsconfig.json +11 -11
  127. package/packages/selector/tsdown.client.config.ts +102 -102
  128. package/packages/selector/tsdown.config.ts +20 -20
  129. package/pnpm-workspace.yaml +6 -0
  130. package/screenshots.json +6 -0
  131. package/scripts/capture-profile-baseline.mjs +42 -42
  132. package/scripts/generate-tokenizer-fixtures.py +81 -81
  133. package/scripts/generate-vision-fixtures.py +208 -208
  134. package/scripts/hosts.mjs +6 -2
  135. package/scripts/packed-install-e2e.mjs +19 -3
  136. package/scripts/sync-hosts.mjs +2 -2
  137. package/scripts/toolclass-corpus-replay.mjs +281 -281
  138. package/scripts/verify-release.mjs +6 -6
  139. package/tsconfig.base.json +18 -18
  140. package/tsconfig.json +7 -7
  141. package/vitest.built.config.ts +9 -9
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "dsh-context-compression-improved",
3
- "version": "0.9.5",
3
+ "version": "0.9.8",
4
4
  "publishConfig": {
5
+ "registry": "https://registry.npmjs.org",
5
6
  "tag": "latest"
6
7
  },
7
8
  "type": "module",
@@ -53,7 +54,7 @@
53
54
  "packageManager": "pnpm@11.7.0",
54
55
  "engines": {
55
56
  "node": "^22.19.0 || >=24.0.0",
56
- "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"
57
+ "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"
57
58
  },
58
59
  "scripts": {
59
60
  "build": "pnpm -r --if-present run bundle",
@@ -71,10 +72,10 @@
71
72
  "pack:dry-run": "pnpm -r --if-present run pack:dry-run"
72
73
  },
73
74
  "peerDependencies": {
74
- "@deepseek-ai/dsh-client-locale": "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",
75
- "@deepseek-ai/dsh-client-ui-primitives": "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",
76
- "@deepseek-ai/dsh-client-ui-settings": "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",
77
- "@deepseek-ai/dsh-client-ui-slots": "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"
75
+ "@deepseek-ai/dsh-client-locale": "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",
76
+ "@deepseek-ai/dsh-client-ui-primitives": "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",
77
+ "@deepseek-ai/dsh-client-ui-settings": "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",
78
+ "@deepseek-ai/dsh-client-ui-slots": "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"
78
79
  },
79
80
  "peerDependenciesMeta": {
80
81
  "@deepseek-ai/dsh-client-locale": {
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 WilliamShi666
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WilliamShi666
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,26 +1,26 @@
1
- # dsh-context-compression-improved
2
-
3
- The installable Product Bundle for the unofficial community DeepSeek Harness context-compression selector.
4
-
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.
6
-
7
- ```sh
8
- ```sh
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
15
- ```
16
-
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.
23
-
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.
25
-
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.
1
+ # dsh-context-compression-improved
2
+
3
+ The installable Product Bundle for the unofficial community DeepSeek Harness context-compression selector.
4
+
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.
6
+
7
+ ```sh
8
+ ```sh
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
15
+ ```
16
+
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.
23
+
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.
25
+
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.
@@ -1,24 +1,24 @@
1
- # dsh-context-compression-improved
2
-
3
- 这是可直接安装的非官方社区 DeepSeek Harness 上下文压缩选择器 Product Bundle。
4
-
5
- **0.1.0 更新:**已加入 DeepSeek V4 Flash 视觉模型的官方 tokenizer;用户可选择模型驱动 Auto Compact 的触发阈值;标准 Profile 的水位与压缩参数会随该选择联动。
6
-
7
- ```sh
8
- ```sh
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
15
- ```
16
-
17
- 这一条命令安装单一的 `dsh-context-compression-improved` 包:压缩运行时、Host 设置、Web UI
18
- 与可逆 preset overlay 全部包含在其中。除 id 精确等于内置 `minimal` 的 preset 外,
19
- 其他 preset 都会获得压缩能力;非 Minimal preset 之间切换时已保存设置保持不变。
20
- Minimal 只暂停插件压缩,不删除设置。
21
-
22
- 已验证兼容 DeepSeek Harness `dsh-v0.1.1-rc.2` 与 `dsh-v0.1.2-alpha.5`,Node `^22.19.0 || >=24`。不需要修改 Harness 核心。
23
-
24
- Profile、默认值、审计证据、Adaptive/cache 限制、升级/卸载与安全说明见[完整 README](https://github.com/WilliamShi666/dsh-context-compression-improved#readme)。本包与 DeepSeek 无隶属或背书关系。
1
+ # dsh-context-compression-improved
2
+
3
+ 这是可直接安装的非官方社区 DeepSeek Harness 上下文压缩选择器 Product Bundle。
4
+
5
+ **0.1.0 更新:**已加入 DeepSeek V4 Flash 视觉模型的官方 tokenizer;用户可选择模型驱动 Auto Compact 的触发阈值;标准 Profile 的水位与压缩参数会随该选择联动。
6
+
7
+ ```sh
8
+ ```sh
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
15
+ ```
16
+
17
+ 这一条命令安装单一的 `dsh-context-compression-improved` 包:压缩运行时、Host 设置、Web UI
18
+ 与可逆 preset overlay 全部包含在其中。除 id 精确等于内置 `minimal` 的 preset 外,
19
+ 其他 preset 都会获得压缩能力;非 Minimal preset 之间切换时已保存设置保持不变。
20
+ Minimal 只暂停插件压缩,不删除设置。
21
+
22
+ 已验证兼容 DeepSeek Harness `dsh-v0.1.1-rc.2` 与 `dsh-v0.1.2-alpha.5`,Node `^22.19.0 || >=24`。不需要修改 Harness 核心。
23
+
24
+ Profile、默认值、审计证据、Adaptive/cache 限制、升级/卸载与安全说明见[完整 README](https://github.com/WilliamShi666/dsh-context-compression-improved#readme)。本包与 DeepSeek 无隶属或背书关系。
@@ -1,32 +1,32 @@
1
- # Third-party notices
2
-
3
- Portions of this package are adapted from the MIT-licensed DeepSeek Harness, verified against `dsh-v0.1.1-rc.2` (`b150a551b8d465e31e418e1b2eaf5e79bbb7d28e`).
4
-
5
- ## DeepSeek Harness MIT notice
6
-
7
- Copyright (c) 2026 DeepSeek
8
-
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:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
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
+ # Third-party notices
2
+
3
+ Portions of this package are adapted from the MIT-licensed DeepSeek Harness, verified against `dsh-v0.1.1-rc.2` (`b150a551b8d465e31e418e1b2eaf5e79bbb7d28e`).
4
+
5
+ ## DeepSeek Harness MIT notice
6
+
7
+ Copyright (c) 2026 DeepSeek
8
+
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:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
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,27 +1,27 @@
1
- # Standalone Profile Bundle entry. The same package may already be present in a
2
- # Harness distribution; its Host implementation reference-counts the preset
3
- # decoration so the two rows never install two compression stacks.
4
- - insert:
5
- - id: context-compression-improved-bundle
6
- name: 'dsh-context-compression-improved'
7
- config:
8
- presetOverlay: true
9
- # The HTTP routes ride their own row so the compression stack stays loadable
10
- # on profiles that have no host web server. Measured on the host source:
11
- # `dsh-host-webserver.register` performs no authorization check and
12
- # `ctx.get(name)` only asks whether the providing fiber is active, so this
13
- # `inject` is belt-and-braces — the row is simply absent instead of
14
- # announcing a pending route on a webServer-less profile. The two-channel
15
- # registration inside the plugin covers both arrival orders on its own.
16
- #
17
- # `estimatorCatalogRoute` is the only flag this row sets. The retired
18
- # review gate's `reviewQueueRoute` used to live here; that key no longer
19
- # exists in the plugin's Config schema (a reduction must never block
20
- # automatic processing), so setting it would advertise a route that can
21
- # never register.
22
- - id: context-compression-improved-estimator-catalog
23
- name: 'dsh-context-compression-improved'
24
- inject:
25
- - webServer
26
- config:
27
- estimatorCatalogRoute: true
1
+ # Standalone Profile Bundle entry. The same package may already be present in a
2
+ # Harness distribution; its Host implementation reference-counts the preset
3
+ # decoration so the two rows never install two compression stacks.
4
+ - insert:
5
+ - id: context-compression-improved-bundle
6
+ name: 'dsh-context-compression-improved'
7
+ config:
8
+ presetOverlay: true
9
+ # The HTTP routes ride their own row so the compression stack stays loadable
10
+ # on profiles that have no host web server. Measured on the host source:
11
+ # `dsh-host-webserver.register` performs no authorization check and
12
+ # `ctx.get(name)` only asks whether the providing fiber is active, so this
13
+ # `inject` is belt-and-braces — the row is simply absent instead of
14
+ # announcing a pending route on a webServer-less profile. The two-channel
15
+ # registration inside the plugin covers both arrival orders on its own.
16
+ #
17
+ # `estimatorCatalogRoute` is the only flag this row sets. The retired
18
+ # review gate's `reviewQueueRoute` used to live here; that key no longer
19
+ # exists in the plugin's Config schema (a reduction must never block
20
+ # automatic processing), so setting it would advertise a route that can
21
+ # never register.
22
+ - id: context-compression-improved-estimator-catalog
23
+ name: 'dsh-context-compression-improved'
24
+ inject:
25
+ - webServer
26
+ config:
27
+ estimatorCatalogRoute: true
@@ -1,112 +1,112 @@
1
- # History / microcompact:按 agent 工具调用保护近期工作集
2
-
3
- 状态:提案,尚未实现
4
-
5
- ## 目标与边界
6
-
7
- 将插件的 History / microcompact 从“保护最近若干个 Harness turn 加一个 token 尾窗”改为“超过该 Profile 的 History 触发阈值后,保护最近 10 次已完成的 agent 工具调用”。这是一项面向所有插件 Profile 的策略变更,不是只为 Balanced 调整。
8
-
9
- 所有实现只修改本仓库的 runtime、selector UI、配置、审计、测试和 npm Bundle。不得修改 DeepSeek Harness 核心、会话事件格式、内置压缩器、provider 或 DSH UI。插件继续只消费现有公开的 `tool/call`、`tool/result` 和 Session surface API。
10
-
11
- 此前发现的 `deepseek-official` tokenizer route alias 是独立的插件内兼容性修复:需回填到本仓库的 `measurement.ts` 并测试,但不属于本 History 策略改动。
12
-
13
- ## 现有问题
14
-
15
- 当前 History 用外层 `turn` 保护近期内容。一个 turn 通常是一次用户消息驱动的 agent 处理周期,不是一次工具调用:一次“探索代码库”的用户请求可以在同一 turn 内产生几十个 Bash、Read、Grep 或 Web 调用。这样它们会被整体保护,即使其中大部分已经很旧;反过来,连续输入几条没有工具输出的用户消息也会推进保护窗口。
16
-
17
- 用户消息不是 History 的可替换对象,保护它们的外层 turn 对 History 没有实际约束意义。现有的 `historyKeepRecentTokens` 也会让“近期保护”取决于个别结果的大小,而不是 agent 最近实际使用过的工具交互数量。
18
-
19
- ## 统一语义
20
-
21
- ### 触发条件不变
22
-
23
- 每个 Profile 仍使用自己的 History gate、`historyTriggerTokens` 和 `historyMinReclaimTokens`。当且仅当:
24
-
25
- 1. 运行到了插件的 `pressure` 阶段;
26
- 2. Profile 的 History gate 允许执行;
27
- 3. 所有活动工具结果的精确 token 总数严格大于该 Profile 的 `historyTriggerTokens`;
28
-
29
- History 才会规划 microcompact。Fresh、Aggregate、Native 和 TailTrim 的各自 trigger/reducer 不因这条规则而变。
30
-
31
- ### 两部分近期工作集
32
-
33
- 一条可计数记录是一个仍在活动 surface 中、能按 `callId` 与 agent 发出的 `tool/call` 配对的 `tool/result`。计数顺序使用该调用在活动会话 surface 中的原始发生顺序,不能使用外层 turn,也不能使用之后压缩替换事件的 seq。
34
-
35
- - 精确保护最新 10 条已完成调用;不足 10 条时全部保护。
36
- - 用户消息、assistant 文本、`turn/start`、`turn/end`、`step/start`、`step/end` 都不计数,也不因它们的数量改变选择结果。
37
- - 尚未产生 `tool/result` 的未完成调用不占槽位,也不是压缩候选。
38
- - `context_compression_retrieve` 也算一次 agent 工具调用并占一个槽位,以保证“最后十次调用完全不动”的字面语义;但它本身继续永远不可被 History 重写。
39
- - 已经是 History 占位符的结果继续占槽位,但不能再次被 History 重写。
40
-
41
- 在调用数量保护之外,保留一个 `64000` token 的工具结果尾窗。从最新活动 `tool/result` 向较早结果逐条累计精确 token;每一条先加入保护集、再判断累计值是否已达到或超过 `64000`。因此,刚好使累计值跨过 `64000` 的那一条也受保护。这个尾窗同样不包含用户消息或 assistant 文本。
42
-
43
- 最终保护集是“最近 10 次调用保护集”和“最近 `64000` token 工具结果尾窗”的并集。排除它后,History 由旧到新选择安全结果,沿用现有可恢复占位符/富结果 reducer。达到 `max(historyMinReclaimTokens, totalTokens - historyTriggerTokens)` 后停止;若最终无法达到最小回收量,则整个 History 批次不提交。精确 tokenizer 不可用、结果形态不安全或 recovery tool 缺失时继续 fail-open。
44
-
45
- 删除 `historyKeepRecentTurns`,保留并将标准 Profile 的 `historyKeepRecentTokens` 统一为 `64000`。近期工作集因此同时保证最近工具交互数量和最近工具结果的内容规模。
46
-
47
- ## 各 Profile 的计划与初始参数
48
-
49
- 首版只替换“保护集的计算方法”,保留现有各 Profile 的触发和回收数值。这样可以先验证工作集语义,而不把“何时触发”“保留什么”“一次回收多少”三个变量同时改变。下表中的“建议首版”是待实现值;“后续调参”只有在带真实工具输出的可重复测试证明需要时才进行。
50
-
51
- | Profile | 当前/建议 History gate | 首版 trigger / 最小回收 | 近期保护 | 后续调参方向 |
52
- | --- | --- | --- | --- | --- |
53
- | `off` | disabled | 不触发 | 10 次调用 + `64000` token;无运行效果 | 无;保持关闭。 |
54
- | `native` | disabled | 不触发;Native 头-中-尾裁剪仍独立 | 10 次调用 + `64000` token;无运行效果 | 无;不得把 History 偷偷加入 Native。 |
55
- | `balanced` | `routine` | `500000 / 96000` tokens,保持不变 | 最近 10 次调用 + `64000` token 尾窗 | 作为基线。若保护集导致频繁无法达到 96k 回收,再只评估提高 trigger 或降低 min-reclaim 之一。 |
56
- | `cache-strict` | `capacity-pressure` | `600000 / 128000` tokens,保持不变;路由上下文利用率至少 `70%` | 最近 10 次调用 + `64000` token 尾窗 | 不降低 trigger;它以稳定已发送前缀为优先。只在已确认容量压力时改写。 |
57
- | `savings` | `routine` | `400000 / 128000` tokens | 最近 10 次调用 + `64000` token 尾窗 | 将 trigger 从 `450000` 提前到 `400000`,以更早回收旧工具结果;首版保留 `128000` 最小回收量,避免用一次很小的前缀改写交换缓存损失。 |
58
- | `adaptive` | `adaptive`,容量压力可覆盖 | `500000 / 96000` tokens,保持不变 | 最近 10 次调用 + `64000` token 尾窗 | 先让现有成本判断评估新的候选批次;没有连续官方 usage/价格证据时不调低门槛。 |
59
- | `custom` | `enabled + prefixPolicy` 决定 routine 或 capacity-pressure | 保留用户的 trigger/min-reclaim | 默认 10 次调用 + `64000` token 尾窗 | Custom v3 允许用户显式改两个保护值;默认/重置值为 10 与 `64000`。 |
60
-
61
- TailTrim 不属于 History / microcompact,但它目前复用 History 的近期保护 helper。为避免同一 helper 同时拥有两套语义,TailTrim 也使用同一个“最近 N 次工具调用 + token 尾窗”保护集;它的独立 trigger、完整工具组条件和 reducer 不变。
62
-
63
- ## 参数与配置改动
64
-
65
- 近期保护参数为:
66
-
67
- ```ts
68
- historyKeepRecentToolCalls: number
69
- historyKeepRecentTokens: number
70
- ```
71
-
72
- 前者是非负安全整数;标准 Profile 都解析为 `10`,它不是 token 数,不受 `tokens` / `context-percent` 单位切换影响。后者保留现有 token 尾窗语义,标准 Profile 都解析为 `64000`。即使 `off`、`native` 的 History 被禁用,解析后的策略结构仍完整一致。
73
-
74
- Custom 升为版本 3:
75
-
76
- ```ts
77
- history: {
78
- enabled: boolean
79
- trigger: number
80
- keepRecentToolCalls: number
81
- keepRecentTokens: number
82
- minReclaim: number
83
- }
84
- ```
85
-
86
- Custom 编辑器显示“保护近期工具调用数”和“保护近期工具结果尾窗”,默认值分别为 10 与 `64000`。保留 Custom 的可编辑性:标准 Profile 固定这些默认值,只有明确选择 Custom 的用户可以改变它们。若产品决定“Custom 也必须固定为这些值”,可在实现前删去两个输入框;其余算法不受影响。
87
-
88
- 已有 Custom v1/v2 设置继续可读:插件将它们规范化为 v3,将 `keepRecentToolCalls` 设为 10,并将用户原有的 `keepRecent` 原样迁移为 `keepRecentTokens`。下一次用户保存 Custom 时写回 v3。部署配置中使用已删除的 `historyKeepRecentTurns` 则在插件加载时明确报错,提示改用 `historyKeepRecentToolCalls`;`historyKeepRecentTokens` 继续受支持。
89
-
90
- ## 审计与可观测性
91
-
92
- `policy-frozen` 和 `policy-resolved` 记录新字段。History rewrite 仍记录 `component: "history"`、`stage: "pressure"`、History mode、reducer、精确 token 前后值和回收量。
93
-
94
- 为解释选择器结果,History 审计增加有限元数据:配置的保护调用数、尾窗 token 预算、活动已完成调用总数、实际受保护结果数。不得记录工具文本、工具参数、用户消息、call id 或 prompt。无需新增 DSH Session event 或修改 DSH 核心审计 schema。
95
-
96
- ## 验证计划
97
-
98
- 每个 History-enabled Profile 至少覆盖一次独立测试;不得只用 Balanced 证明实现。
99
-
100
- 1. 一个用户 turn 内连续完成至少 16 次调用并越过 trigger:最近 10 次总计约 `30000` token,继续向前累计到 `64000` token 的第 11 至第 15 次也不变;第 16 次(从最新向旧数)成为可选候选。
101
- 2. 将同一批调用切分到任意多个用户 turn:受保护和可压缩集合完全相同;只添加用户消息的 turn 不改变结果。
102
- 3. 包含并行调用、错误结果、富结果、已替换占位符和 `context_compression_retrieve`,验证计数顺序与不可重写规则。
103
- 4. `off` 和 `native` 即使工具输出很大也不执行 History;Native 仍按自己的逻辑运行。
104
- 5. Balanced、Savings 的 routine gate 在各自 trigger 之上执行;Cache Strict 只有确认容量压力时执行;Adaptive 在成本证据不足时跳过、容量压力时仍可执行;Custom 同时覆盖 routine 与 capacity-pressure。
105
- 6. 十条或更少调用、未达到 `64000` token 尾窗但所有调用都仍在尾窗内、精确 tokenizer 不可用、无安全候选或达不到最小回收量时,History 只留下可解释的跳过审计,不产生部分重写。
106
- 7. Custom v1/v2 规范化、v3 校验、浏览器输入、中文/英文文案、运行时公共测试、packed smoke、构建和 clean-install 发布验证均使用新字段。
107
-
108
- ## 风险与取舍
109
-
110
- 最近十条结果或 `64000` token 尾窗可能很大,导致旧结果不足以回收最小 token 数;此时跳过是对工作集保证的正确结果,而不是压缩器失效。Savings 的更激进候选参数必须先用同一任务的 token、缓存和结果可用性数据验证。
111
-
112
- 这会改变旧 Custom 文档的实际保留行为。将其统一为 10 次调用是可预测的迁移,但不等价于任何旧 turn/token 数。发布说明必须明确指出 Custom v3 和该语义变化。
1
+ # History / microcompact:按 agent 工具调用保护近期工作集
2
+
3
+ 状态:提案,尚未实现
4
+
5
+ ## 目标与边界
6
+
7
+ 将插件的 History / microcompact 从“保护最近若干个 Harness turn 加一个 token 尾窗”改为“超过该 Profile 的 History 触发阈值后,保护最近 10 次已完成的 agent 工具调用”。这是一项面向所有插件 Profile 的策略变更,不是只为 Balanced 调整。
8
+
9
+ 所有实现只修改本仓库的 runtime、selector UI、配置、审计、测试和 npm Bundle。不得修改 DeepSeek Harness 核心、会话事件格式、内置压缩器、provider 或 DSH UI。插件继续只消费现有公开的 `tool/call`、`tool/result` 和 Session surface API。
10
+
11
+ 此前发现的 `deepseek-official` tokenizer route alias 是独立的插件内兼容性修复:需回填到本仓库的 `measurement.ts` 并测试,但不属于本 History 策略改动。
12
+
13
+ ## 现有问题
14
+
15
+ 当前 History 用外层 `turn` 保护近期内容。一个 turn 通常是一次用户消息驱动的 agent 处理周期,不是一次工具调用:一次“探索代码库”的用户请求可以在同一 turn 内产生几十个 Bash、Read、Grep 或 Web 调用。这样它们会被整体保护,即使其中大部分已经很旧;反过来,连续输入几条没有工具输出的用户消息也会推进保护窗口。
16
+
17
+ 用户消息不是 History 的可替换对象,保护它们的外层 turn 对 History 没有实际约束意义。现有的 `historyKeepRecentTokens` 也会让“近期保护”取决于个别结果的大小,而不是 agent 最近实际使用过的工具交互数量。
18
+
19
+ ## 统一语义
20
+
21
+ ### 触发条件不变
22
+
23
+ 每个 Profile 仍使用自己的 History gate、`historyTriggerTokens` 和 `historyMinReclaimTokens`。当且仅当:
24
+
25
+ 1. 运行到了插件的 `pressure` 阶段;
26
+ 2. Profile 的 History gate 允许执行;
27
+ 3. 所有活动工具结果的精确 token 总数严格大于该 Profile 的 `historyTriggerTokens`;
28
+
29
+ History 才会规划 microcompact。Fresh、Aggregate、Native 和 TailTrim 的各自 trigger/reducer 不因这条规则而变。
30
+
31
+ ### 两部分近期工作集
32
+
33
+ 一条可计数记录是一个仍在活动 surface 中、能按 `callId` 与 agent 发出的 `tool/call` 配对的 `tool/result`。计数顺序使用该调用在活动会话 surface 中的原始发生顺序,不能使用外层 turn,也不能使用之后压缩替换事件的 seq。
34
+
35
+ - 精确保护最新 10 条已完成调用;不足 10 条时全部保护。
36
+ - 用户消息、assistant 文本、`turn/start`、`turn/end`、`step/start`、`step/end` 都不计数,也不因它们的数量改变选择结果。
37
+ - 尚未产生 `tool/result` 的未完成调用不占槽位,也不是压缩候选。
38
+ - `context_compression_retrieve` 也算一次 agent 工具调用并占一个槽位,以保证“最后十次调用完全不动”的字面语义;但它本身继续永远不可被 History 重写。
39
+ - 已经是 History 占位符的结果继续占槽位,但不能再次被 History 重写。
40
+
41
+ 在调用数量保护之外,保留一个 `64000` token 的工具结果尾窗。从最新活动 `tool/result` 向较早结果逐条累计精确 token;每一条先加入保护集、再判断累计值是否已达到或超过 `64000`。因此,刚好使累计值跨过 `64000` 的那一条也受保护。这个尾窗同样不包含用户消息或 assistant 文本。
42
+
43
+ 最终保护集是“最近 10 次调用保护集”和“最近 `64000` token 工具结果尾窗”的并集。排除它后,History 由旧到新选择安全结果,沿用现有可恢复占位符/富结果 reducer。达到 `max(historyMinReclaimTokens, totalTokens - historyTriggerTokens)` 后停止;若最终无法达到最小回收量,则整个 History 批次不提交。精确 tokenizer 不可用、结果形态不安全或 recovery tool 缺失时继续 fail-open。
44
+
45
+ 删除 `historyKeepRecentTurns`,保留并将标准 Profile 的 `historyKeepRecentTokens` 统一为 `64000`。近期工作集因此同时保证最近工具交互数量和最近工具结果的内容规模。
46
+
47
+ ## 各 Profile 的计划与初始参数
48
+
49
+ 首版只替换“保护集的计算方法”,保留现有各 Profile 的触发和回收数值。这样可以先验证工作集语义,而不把“何时触发”“保留什么”“一次回收多少”三个变量同时改变。下表中的“建议首版”是待实现值;“后续调参”只有在带真实工具输出的可重复测试证明需要时才进行。
50
+
51
+ | Profile | 当前/建议 History gate | 首版 trigger / 最小回收 | 近期保护 | 后续调参方向 |
52
+ | --- | --- | --- | --- | --- |
53
+ | `off` | disabled | 不触发 | 10 次调用 + `64000` token;无运行效果 | 无;保持关闭。 |
54
+ | `native` | disabled | 不触发;Native 头-中-尾裁剪仍独立 | 10 次调用 + `64000` token;无运行效果 | 无;不得把 History 偷偷加入 Native。 |
55
+ | `balanced` | `routine` | `500000 / 96000` tokens,保持不变 | 最近 10 次调用 + `64000` token 尾窗 | 作为基线。若保护集导致频繁无法达到 96k 回收,再只评估提高 trigger 或降低 min-reclaim 之一。 |
56
+ | `cache-strict` | `capacity-pressure` | `600000 / 128000` tokens,保持不变;路由上下文利用率至少 `70%` | 最近 10 次调用 + `64000` token 尾窗 | 不降低 trigger;它以稳定已发送前缀为优先。只在已确认容量压力时改写。 |
57
+ | `savings` | `routine` | `400000 / 128000` tokens | 最近 10 次调用 + `64000` token 尾窗 | 将 trigger 从 `450000` 提前到 `400000`,以更早回收旧工具结果;首版保留 `128000` 最小回收量,避免用一次很小的前缀改写交换缓存损失。 |
58
+ | `adaptive` | `adaptive`,容量压力可覆盖 | `500000 / 96000` tokens,保持不变 | 最近 10 次调用 + `64000` token 尾窗 | 先让现有成本判断评估新的候选批次;没有连续官方 usage/价格证据时不调低门槛。 |
59
+ | `custom` | `enabled + prefixPolicy` 决定 routine 或 capacity-pressure | 保留用户的 trigger/min-reclaim | 默认 10 次调用 + `64000` token 尾窗 | Custom v3 允许用户显式改两个保护值;默认/重置值为 10 与 `64000`。 |
60
+
61
+ TailTrim 不属于 History / microcompact,但它目前复用 History 的近期保护 helper。为避免同一 helper 同时拥有两套语义,TailTrim 也使用同一个“最近 N 次工具调用 + token 尾窗”保护集;它的独立 trigger、完整工具组条件和 reducer 不变。
62
+
63
+ ## 参数与配置改动
64
+
65
+ 近期保护参数为:
66
+
67
+ ```ts
68
+ historyKeepRecentToolCalls: number
69
+ historyKeepRecentTokens: number
70
+ ```
71
+
72
+ 前者是非负安全整数;标准 Profile 都解析为 `10`,它不是 token 数,不受 `tokens` / `context-percent` 单位切换影响。后者保留现有 token 尾窗语义,标准 Profile 都解析为 `64000`。即使 `off`、`native` 的 History 被禁用,解析后的策略结构仍完整一致。
73
+
74
+ Custom 升为版本 3:
75
+
76
+ ```ts
77
+ history: {
78
+ enabled: boolean
79
+ trigger: number
80
+ keepRecentToolCalls: number
81
+ keepRecentTokens: number
82
+ minReclaim: number
83
+ }
84
+ ```
85
+
86
+ Custom 编辑器显示“保护近期工具调用数”和“保护近期工具结果尾窗”,默认值分别为 10 与 `64000`。保留 Custom 的可编辑性:标准 Profile 固定这些默认值,只有明确选择 Custom 的用户可以改变它们。若产品决定“Custom 也必须固定为这些值”,可在实现前删去两个输入框;其余算法不受影响。
87
+
88
+ 已有 Custom v1/v2 设置继续可读:插件将它们规范化为 v3,将 `keepRecentToolCalls` 设为 10,并将用户原有的 `keepRecent` 原样迁移为 `keepRecentTokens`。下一次用户保存 Custom 时写回 v3。部署配置中使用已删除的 `historyKeepRecentTurns` 则在插件加载时明确报错,提示改用 `historyKeepRecentToolCalls`;`historyKeepRecentTokens` 继续受支持。
89
+
90
+ ## 审计与可观测性
91
+
92
+ `policy-frozen` 和 `policy-resolved` 记录新字段。History rewrite 仍记录 `component: "history"`、`stage: "pressure"`、History mode、reducer、精确 token 前后值和回收量。
93
+
94
+ 为解释选择器结果,History 审计增加有限元数据:配置的保护调用数、尾窗 token 预算、活动已完成调用总数、实际受保护结果数。不得记录工具文本、工具参数、用户消息、call id 或 prompt。无需新增 DSH Session event 或修改 DSH 核心审计 schema。
95
+
96
+ ## 验证计划
97
+
98
+ 每个 History-enabled Profile 至少覆盖一次独立测试;不得只用 Balanced 证明实现。
99
+
100
+ 1. 一个用户 turn 内连续完成至少 16 次调用并越过 trigger:最近 10 次总计约 `30000` token,继续向前累计到 `64000` token 的第 11 至第 15 次也不变;第 16 次(从最新向旧数)成为可选候选。
101
+ 2. 将同一批调用切分到任意多个用户 turn:受保护和可压缩集合完全相同;只添加用户消息的 turn 不改变结果。
102
+ 3. 包含并行调用、错误结果、富结果、已替换占位符和 `context_compression_retrieve`,验证计数顺序与不可重写规则。
103
+ 4. `off` 和 `native` 即使工具输出很大也不执行 History;Native 仍按自己的逻辑运行。
104
+ 5. Balanced、Savings 的 routine gate 在各自 trigger 之上执行;Cache Strict 只有确认容量压力时执行;Adaptive 在成本证据不足时跳过、容量压力时仍可执行;Custom 同时覆盖 routine 与 capacity-pressure。
105
+ 6. 十条或更少调用、未达到 `64000` token 尾窗但所有调用都仍在尾窗内、精确 tokenizer 不可用、无安全候选或达不到最小回收量时,History 只留下可解释的跳过审计,不产生部分重写。
106
+ 7. Custom v1/v2 规范化、v3 校验、浏览器输入、中文/英文文案、运行时公共测试、packed smoke、构建和 clean-install 发布验证均使用新字段。
107
+
108
+ ## 风险与取舍
109
+
110
+ 最近十条结果或 `64000` token 尾窗可能很大,导致旧结果不足以回收最小 token 数;此时跳过是对工作集保证的正确结果,而不是压缩器失效。Savings 的更激进候选参数必须先用同一任务的 token、缓存和结果可用性数据验证。
111
+
112
+ 这会改变旧 Custom 文档的实际保留行为。将其统一为 10 次调用是可预测的迁移,但不等价于任何旧 turn/token 数。发布说明必须明确指出 Custom v3 和该语义变化。
@@ -1,34 +1,34 @@
1
- # 原生工具结果压缩接管规格
2
-
3
- ## 范围
4
-
5
- 本规格只约束选择器 Bundle 的工具结果压缩。不得修改 DeepSeek Harness 核心、内置 pruner、会话事件格式或 DSH UI。
6
-
7
- ## 机制
8
-
9
- 适用的 Harness preset 在插件的可逆 overlay 中移除 `@deepseek-ai/dsh-compaction-tool-result-pruner`,并以选择器 runtime 的同名 `toolResultPruner` 服务替换它。Harness 的 compaction-basic 继续调用这个公开服务;选择器据冻结的 Profile 决定允许哪一种 reducer。因此同一 Session 不会同时运行核心头尾裁剪和选择器 reducer。
10
-
11
- ## Profile 规则
12
-
13
- | Profile | 选择器原生风格头—中间—尾 reducer | 其他选择器路径 |
14
- | --- | --- | --- |
15
- | `native` | 允许 | Fresh、Aggregate、History、TailTrim 均关闭 |
16
- | `balanced` | 禁止 | 按 Balanced policy 运行 |
17
- | `cache-strict` | 禁止 | 按 Cache Strict policy 运行 |
18
- | `savings` | 禁止 | 按 Savings policy 运行 |
19
- | `adaptive` | 禁止 | 按 Adaptive policy 运行 |
20
- | `custom` | 禁止 | 只运行 Custom 明确启用的路径 |
21
- | `off` | 禁止 | 不运行选择器工具结果压缩 |
22
-
23
- 这里的“禁止”同时排除两条路径:overlay 已移除核心 `@deepseek-ai/dsh-compaction-tool-result-pruner`,解析后的 `nativeToolResultEnabled` 也为 `false`。因此不会生成 `component: "native-tool-result"` 的选择器 rewrite。`native-auto-compact` 是 Harness/模型独立机制,不受本规格控制。
24
-
25
- ## 会话冻结
26
-
27
- 选择器首次观察 Session 时冻结 Profile 与 Custom 文档。之后修改全局设置只能影响新 Session,不能让已经采用 Balanced、Savings、Cache Strict、Adaptive 或 Custom 的 Session 在中途重新启用头—中间—尾裁剪。
28
-
29
- ## 验收
30
-
31
- 1. `resolvePolicy()` 对 `balanced`、`cache-strict`、`savings`、`adaptive`、`custom` 返回 `nativeToolResultEnabled: false`,对 `native` 返回 `true`。
32
- 2. 插件 runtime 的 pressure pass 仅在 `nativeToolResultEnabled` 为 `true` 时计划 `native-tool-result` rewrite。
33
- 3. preset overlay 测试证明生成 composition 中没有核心 pruner,只有选择器 runtime 的同名服务。
34
- 4. 所有源代码改动限定在本仓库;不修改 Harness worktree。
1
+ # 原生工具结果压缩接管规格
2
+
3
+ ## 范围
4
+
5
+ 本规格只约束选择器 Bundle 的工具结果压缩。不得修改 DeepSeek Harness 核心、内置 pruner、会话事件格式或 DSH UI。
6
+
7
+ ## 机制
8
+
9
+ 适用的 Harness preset 在插件的可逆 overlay 中移除 `@deepseek-ai/dsh-compaction-tool-result-pruner`,并以选择器 runtime 的同名 `toolResultPruner` 服务替换它。Harness 的 compaction-basic 继续调用这个公开服务;选择器据冻结的 Profile 决定允许哪一种 reducer。因此同一 Session 不会同时运行核心头尾裁剪和选择器 reducer。
10
+
11
+ ## Profile 规则
12
+
13
+ | Profile | 选择器原生风格头—中间—尾 reducer | 其他选择器路径 |
14
+ | --- | --- | --- |
15
+ | `native` | 允许 | Fresh、Aggregate、History、TailTrim 均关闭 |
16
+ | `balanced` | 禁止 | 按 Balanced policy 运行 |
17
+ | `cache-strict` | 禁止 | 按 Cache Strict policy 运行 |
18
+ | `savings` | 禁止 | 按 Savings policy 运行 |
19
+ | `adaptive` | 禁止 | 按 Adaptive policy 运行 |
20
+ | `custom` | 禁止 | 只运行 Custom 明确启用的路径 |
21
+ | `off` | 禁止 | 不运行选择器工具结果压缩 |
22
+
23
+ 这里的“禁止”同时排除两条路径:overlay 已移除核心 `@deepseek-ai/dsh-compaction-tool-result-pruner`,解析后的 `nativeToolResultEnabled` 也为 `false`。因此不会生成 `component: "native-tool-result"` 的选择器 rewrite。`native-auto-compact` 是 Harness/模型独立机制,不受本规格控制。
24
+
25
+ ## 会话冻结
26
+
27
+ 选择器首次观察 Session 时冻结 Profile 与 Custom 文档。之后修改全局设置只能影响新 Session,不能让已经采用 Balanced、Savings、Cache Strict、Adaptive 或 Custom 的 Session 在中途重新启用头—中间—尾裁剪。
28
+
29
+ ## 验收
30
+
31
+ 1. `resolvePolicy()` 对 `balanced`、`cache-strict`、`savings`、`adaptive`、`custom` 返回 `nativeToolResultEnabled: false`,对 `native` 返回 `true`。
32
+ 2. 插件 runtime 的 pressure pass 仅在 `nativeToolResultEnabled` 为 `true` 时计划 `native-tool-result` rewrite。
33
+ 3. preset overlay 测试证明生成 composition 中没有核心 pruner,只有选择器 runtime 的同名服务。
34
+ 4. 所有源代码改动限定在本仓库;不修改 Harness worktree。