dsh-context-compression-improved 0.8.0 → 0.9.3

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 (172) 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.de.md +41 -0
  5. package/CHANGELOG.es.md +41 -0
  6. package/CHANGELOG.fr.md +42 -0
  7. package/CHANGELOG.it.md +41 -0
  8. package/CHANGELOG.ja.md +35 -0
  9. package/CHANGELOG.ko.md +34 -0
  10. package/CHANGELOG.md +96 -0
  11. package/CHANGELOG.ru.md +37 -0
  12. package/CHANGELOG.zh.md +32 -0
  13. package/CONTRIBUTING.md +22 -22
  14. package/LICENSE +21 -21
  15. package/README.de.md +7 -9
  16. package/README.es.md +7 -9
  17. package/README.fr.md +7 -9
  18. package/README.it.md +7 -9
  19. package/README.ja.md +6 -2
  20. package/README.ko.md +6 -2
  21. package/README.md +96 -98
  22. package/README.ru.md +7 -9
  23. package/README.zh.md +89 -85
  24. package/SECURITY.md +18 -18
  25. package/THIRD_PARTY_NOTICES.md +14 -14
  26. package/docs/compat-0.1.5-report.md +77 -77
  27. package/docs/installation.de.md +5 -5
  28. package/docs/installation.es.md +5 -5
  29. package/docs/installation.fr.md +5 -5
  30. package/docs/installation.it.md +5 -5
  31. package/docs/installation.ja.md +5 -5
  32. package/docs/installation.ko.md +5 -5
  33. package/docs/installation.md +5 -5
  34. package/docs/installation.ru.md +5 -5
  35. package/docs/installation.zh.md +5 -5
  36. package/docs/repair-log.md +657 -657
  37. package/package.json +24 -22
  38. package/packages/selector/LICENSE +21 -21
  39. package/packages/selector/README.md +26 -26
  40. package/packages/selector/README.zh.md +24 -24
  41. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
  42. package/packages/selector/cordis.patch.yml +27 -27
  43. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
  44. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
  45. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
  46. package/packages/selector/dsh.plugin.json +16 -16
  47. package/packages/selector/lib/client.js +180 -22
  48. package/packages/selector/lib/host-generation.js +62 -0
  49. package/packages/selector/lib/index.js +208 -1
  50. package/packages/selector/lib/invariant.js +1 -1
  51. package/packages/selector/lib/pruner.js +46 -44
  52. package/packages/selector/lib/style.css +53 -53
  53. package/packages/selector/lib/tail-trim.js +73 -4
  54. package/packages/selector/package.json +80 -21
  55. package/packages/selector/screenshots.json +3 -3
  56. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
  57. package/packages/selector/src/client/EstimatorControls.tsx +277 -277
  58. package/packages/selector/src/client/bridge-scope.ts +125 -0
  59. package/packages/selector/src/client/index.ts +122 -36
  60. package/packages/selector/src/client/monitor-fab.ts +0 -2
  61. package/packages/selector/src/client/preset-options.ts +88 -88
  62. package/packages/selector/src/client/scope-face.ts +24 -24
  63. package/packages/selector/src/compat/host-generation.ts +96 -0
  64. package/packages/selector/src/compat/settings-lease.ts +108 -0
  65. package/packages/selector/src/compat/tool-result.ts +91 -0
  66. package/packages/selector/src/css-modules.d.ts +6 -6
  67. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  68. package/packages/selector/src/estimator-catalog.ts +104 -104
  69. package/packages/selector/src/index.ts +8 -0
  70. package/packages/selector/src/invariant.ts +113 -113
  71. package/packages/selector/src/preset-overlay.ts +626 -626
  72. package/packages/selector/src/pruner/content.ts +198 -198
  73. package/packages/selector/src/pruner/session.ts +97 -96
  74. package/packages/selector/src/pruner/tuning.ts +23 -23
  75. package/packages/selector/src/pruner/types.ts +78 -78
  76. package/packages/selector/src/pruner.ts +61 -41
  77. package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
  78. package/packages/selector/src/runtime/custom-policy.ts +278 -278
  79. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
  80. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
  81. package/packages/selector/src/runtime/measurement.ts +444 -431
  82. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  83. package/packages/selector/src/runtime/retrieve.ts +7 -3
  84. package/packages/selector/src/runtime/session-events.ts +30 -30
  85. package/packages/selector/src/runtime/tail-trim.ts +175 -165
  86. package/packages/selector/src/runtime/token-count.ts +72 -72
  87. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
  88. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
  89. package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
  90. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
  91. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  92. package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
  93. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -303
  94. package/packages/selector/src/runtime/toolclass.ts +103 -103
  95. package/packages/selector/src/runtime/value.ts +48 -48
  96. package/packages/selector/src/settings-bridge.ts +175 -0
  97. package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
  98. package/packages/selector/tests/built/client-artifact.spec.ts +6 -9
  99. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
  100. package/packages/selector/tests/code-skeleton.client.spec.ts +98 -94
  101. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
  102. package/packages/selector/tests/custom-contract.client.spec.ts +226 -223
  103. package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
  104. package/packages/selector/tests/estimator-route-registration.host.spec.ts +199 -194
  105. package/packages/selector/tests/helpers/legacy-namespace.ts +35 -35
  106. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  107. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  108. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  109. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  110. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  111. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
  112. package/packages/selector/tests/preset-options-write.client.spec.ts +192 -188
  113. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
  114. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
  115. package/packages/selector/tests/public/package-contract.client.spec.ts +11 -3
  116. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
  117. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
  118. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
  119. package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
  120. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  121. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
  122. package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
  123. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
  124. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  125. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
  126. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
  127. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
  128. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
  129. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
  130. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
  131. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
  132. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
  133. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
  134. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +3 -3
  135. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
  136. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
  137. package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
  138. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
  139. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
  140. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
  141. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
  142. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
  143. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
  144. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
  145. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -116
  146. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
  147. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
  148. package/packages/selector/tests/runtime/value.spec.ts +23 -23
  149. package/packages/selector/tests/settings-seat.client.spec.ts +45 -7
  150. package/packages/selector/tests/standing-generation.host.spec.ts +724 -724
  151. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -269
  152. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
  153. package/packages/selector/tests/support/mock-adapter.ts +37 -37
  154. package/packages/selector/tests/support/ui-primitives.tsx +34 -34
  155. package/packages/selector/tsconfig.json +11 -11
  156. package/packages/selector/tsdown.client.config.ts +102 -102
  157. package/packages/selector/tsdown.config.ts +20 -20
  158. package/scripts/capture-profile-baseline.mjs +42 -42
  159. package/scripts/cell-browser-e2e.mjs +354 -0
  160. package/scripts/generate-tokenizer-fixtures.py +81 -81
  161. package/scripts/generate-vision-fixtures.py +208 -208
  162. package/scripts/hosts.mjs +74 -0
  163. package/scripts/packed-components-smoke.mjs +763 -732
  164. package/scripts/packed-install-e2e.mjs +1330 -1273
  165. package/scripts/sync-hosts.mjs +174 -0
  166. package/scripts/toolclass-corpus-replay.mjs +281 -281
  167. package/scripts/verify-release.mjs +335 -318
  168. package/tsconfig.base.json +18 -18
  169. package/tsconfig.json +7 -7
  170. package/tsconfig.tests.json +15 -15
  171. package/vitest.built.config.ts +9 -9
  172. package/vitest.config.ts +46 -43
@@ -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。
@@ -1,46 +1,46 @@
1
- # Parent and child agent cache-prefix audit
2
-
3
- ## Scope
4
-
5
- This reference characterizes when DeepSeek Harness parent and child requests can present an identical prompt prefix to DeepSeek's automatic context cache. It does not add an explicit cache key, cache breakpoint, cache identifier, or client-side KV cache.
6
-
7
- The selector plugin owns settings registration and UI only. It has no hook into agent request construction, subagent session creation, or LLM serialization, so this work must not add runtime request behavior to the plugin or modify Harness core.
8
-
9
- ## Three separate questions
10
-
11
- Context inheritance asks whether a child session receives parent session events. A fork copies the parent event prefix through the last completed turn; a spawn starts without parent messages. The child metadata records the parent session and, for a fork, the seed length.
12
-
13
- Harness cache control asks whether Harness supplies a DeepSeek cache key or breakpoint across requests or sessions. The DeepSeek adapter serializes ordinary Chat Completions input and reads official usage fields; it supplies no explicit cache control.
14
-
15
- Server cache reuse asks whether byte-identical request prefixes can hit DeepSeek's automatic context cache. This is best-effort server behavior and is confirmed only when official response usage reports a positive `prompt_cache_hit_tokens` value. Latency and price are not evidence.
16
-
17
- ## Reuse characterization
18
-
19
- The test-only audit representation is versioned and canonical. Object keys are sorted recursively, while arrays retain their model-visible order. A SHA-256 fingerprint is computed over UTF-8 JSON containing the provider, model, system prompt, tool schemas, and inherited messages.
20
-
21
- A child is reusable only when it is a fork, declares parent-context inheritance, and its provider, model, system prompt, tools, and inherited messages equal the parent's stable envelope. Spawn mode, a changed persona or system prompt, changed tool schema or order, changed provider or model route, and changed history are rejected. The audit never repairs or concatenates mismatched contexts.
22
-
23
- The characterization does not guarantee that two independently assembled HTTP bodies have the same byte prefix: JSON property order and the child-only continuation still belong to the DeepSeek adapter. The live test captures the actual immutable agent-loop request options and compares the stable inherited envelope before allowing a cache-reuse claim.
24
-
25
- ## Safe evidence record
26
-
27
- An evidence event may contain only the audit version, prefix fingerprint, estimated shared-prefix tokens, parent and child session identifiers, mode, eligibility or reason, cache-read tokens, cache-miss tokens, observed prompt tokens, and confirmation status. It must not contain prompts, messages, tool arguments or results, tool schemas, permissions, environment values, credentials, or secrets.
28
-
29
- Usage is internally consistent only when `cacheReadTokens + cacheMissTokens` equals the observed prompt-token total. A positive cache-read count confirms a natural cache hit for that request. Missing or zero cache-read usage yields `unconfirmed`, never a claimed miss caused by Harness.
30
-
31
- ## TDD acceptance criteria
32
-
33
- The RED test imports an absent test-support module and defines the required behavior before implementation. The GREEN implementation remains under `tests/support` and exports no product runtime API.
34
-
35
- - Fork accepts an identical completed-turn prefix and produces the same fingerprint for parent and child views.
36
- - Spawn is ineligible because it does not inherit parent messages.
37
- - Persona, tool schema or order, provider, model, and history mismatches are ineligible.
38
- - Safe evidence records contain only the allowlisted fields and never contain representative secret or tool-result content.
39
- - Usage projection accepts hit plus miss equaling the prompt total and rejects inconsistent totals.
40
- - The existing selector runtime source remains unchanged, so disabling or omitting the plugin cannot affect agent requests.
41
- - A key-gated host-side live DeepSeek E2E test uses an isolated in-memory context and task-local `DSH_HOME`; it reports only sanitized usage evidence.
42
- - Existing fork, spawn, request-reconstruction, DeepSeek usage-projection, selector-plugin tests, the full build, and `git diff --check` pass.
43
-
44
- ## Operational boundaries
45
-
46
- Tests do not connect to the active web profile, start or restart a Harness service, deploy code, or write session logs outside the isolated test environment. The test-only implementation adds no product runtime API and does not alter active profile settings or service state.
1
+ # Parent and child agent cache-prefix audit
2
+
3
+ ## Scope
4
+
5
+ This reference characterizes when DeepSeek Harness parent and child requests can present an identical prompt prefix to DeepSeek's automatic context cache. It does not add an explicit cache key, cache breakpoint, cache identifier, or client-side KV cache.
6
+
7
+ The selector plugin owns settings registration and UI only. It has no hook into agent request construction, subagent session creation, or LLM serialization, so this work must not add runtime request behavior to the plugin or modify Harness core.
8
+
9
+ ## Three separate questions
10
+
11
+ Context inheritance asks whether a child session receives parent session events. A fork copies the parent event prefix through the last completed turn; a spawn starts without parent messages. The child metadata records the parent session and, for a fork, the seed length.
12
+
13
+ Harness cache control asks whether Harness supplies a DeepSeek cache key or breakpoint across requests or sessions. The DeepSeek adapter serializes ordinary Chat Completions input and reads official usage fields; it supplies no explicit cache control.
14
+
15
+ Server cache reuse asks whether byte-identical request prefixes can hit DeepSeek's automatic context cache. This is best-effort server behavior and is confirmed only when official response usage reports a positive `prompt_cache_hit_tokens` value. Latency and price are not evidence.
16
+
17
+ ## Reuse characterization
18
+
19
+ The test-only audit representation is versioned and canonical. Object keys are sorted recursively, while arrays retain their model-visible order. A SHA-256 fingerprint is computed over UTF-8 JSON containing the provider, model, system prompt, tool schemas, and inherited messages.
20
+
21
+ A child is reusable only when it is a fork, declares parent-context inheritance, and its provider, model, system prompt, tools, and inherited messages equal the parent's stable envelope. Spawn mode, a changed persona or system prompt, changed tool schema or order, changed provider or model route, and changed history are rejected. The audit never repairs or concatenates mismatched contexts.
22
+
23
+ The characterization does not guarantee that two independently assembled HTTP bodies have the same byte prefix: JSON property order and the child-only continuation still belong to the DeepSeek adapter. The live test captures the actual immutable agent-loop request options and compares the stable inherited envelope before allowing a cache-reuse claim.
24
+
25
+ ## Safe evidence record
26
+
27
+ An evidence event may contain only the audit version, prefix fingerprint, estimated shared-prefix tokens, parent and child session identifiers, mode, eligibility or reason, cache-read tokens, cache-miss tokens, observed prompt tokens, and confirmation status. It must not contain prompts, messages, tool arguments or results, tool schemas, permissions, environment values, credentials, or secrets.
28
+
29
+ Usage is internally consistent only when `cacheReadTokens + cacheMissTokens` equals the observed prompt-token total. A positive cache-read count confirms a natural cache hit for that request. Missing or zero cache-read usage yields `unconfirmed`, never a claimed miss caused by Harness.
30
+
31
+ ## TDD acceptance criteria
32
+
33
+ The RED test imports an absent test-support module and defines the required behavior before implementation. The GREEN implementation remains under `tests/support` and exports no product runtime API.
34
+
35
+ - Fork accepts an identical completed-turn prefix and produces the same fingerprint for parent and child views.
36
+ - Spawn is ineligible because it does not inherit parent messages.
37
+ - Persona, tool schema or order, provider, model, and history mismatches are ineligible.
38
+ - Safe evidence records contain only the allowlisted fields and never contain representative secret or tool-result content.
39
+ - Usage projection accepts hit plus miss equaling the prompt total and rejects inconsistent totals.
40
+ - The existing selector runtime source remains unchanged, so disabling or omitting the plugin cannot affect agent requests.
41
+ - A key-gated host-side live DeepSeek E2E test uses an isolated in-memory context and task-local `DSH_HOME`; it reports only sanitized usage evidence.
42
+ - Existing fork, spawn, request-reconstruction, DeepSeek usage-projection, selector-plugin tests, the full build, and `git diff --check` pass.
43
+
44
+ ## Operational boundaries
45
+
46
+ Tests do not connect to the active web profile, start or restart a Harness service, deploy code, or write session logs outside the isolated test environment. The test-only implementation adds no product runtime API and does not alter active profile settings or service state.
@@ -1,16 +1,16 @@
1
- {
2
- "id": "dsh-external/dsh-context-compression-improved",
3
- "version": "0.8.0",
4
- "main": "./lib/index.js",
5
- "description": "Auditable tool-result context-compression selector with code-skeleton gate for DeepSeek Harness",
6
- "engines": {
7
- "dsh": ">=0.2.0-rc.1 <0.2.1-0"
8
- },
9
- "contributes": {
10
- "tools": [],
11
- "skills": []
12
- },
13
- "client": {
14
- "main": "./lib/client.js"
15
- }
16
- }
1
+ {
2
+ "id": "dsh-external/dsh-context-compression-improved",
3
+ "version": "0.9.2",
4
+ "main": "./lib/index.js",
5
+ "description": "Auditable tool-result context-compression selector with code-skeleton gate for DeepSeek Harness",
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"
8
+ },
9
+ "contributes": {
10
+ "tools": [],
11
+ "skills": []
12
+ },
13
+ "client": {
14
+ "main": "./lib/client.js"
15
+ }
16
+ }
@@ -4,8 +4,8 @@ window.__ModuleLoader__.load({
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
- let react_jsx_runtime = require("react/jsx-runtime");
8
7
  let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
9
  require("@deepseek-ai/dsh-client-ui-primitives");
10
10
  //#region src/profiles.ts
11
11
  /** Public context-compression choices shared by the Host schema and browser selector. */
@@ -3093,12 +3093,120 @@ window.__ModuleLoader__.load({
3093
3093
  });
3094
3094
  }
3095
3095
  //#endregion
3096
+ //#region src/client/bridge-scope.ts
3097
+ const SETTINGS_ROUTE = "/api/dsh-context-compression-improved/settings";
3098
+ const POLL_MS = 4e3;
3099
+ function createBridgeScope() {
3100
+ let snapshot = {
3101
+ status: "loading",
3102
+ value: void 0,
3103
+ revision: void 0,
3104
+ writable: true,
3105
+ base: void 0,
3106
+ user: void 0,
3107
+ mode: "host"
3108
+ };
3109
+ const listeners = /* @__PURE__ */ new Set();
3110
+ let pollTimer;
3111
+ const emit = () => {
3112
+ for (const listener of listeners) listener();
3113
+ };
3114
+ const applyDoc = (doc, revision) => {
3115
+ const value = decodeSettings(doc);
3116
+ const next = {
3117
+ status: value === void 0 ? "unavailable" : "ready",
3118
+ value,
3119
+ revision,
3120
+ writable: true,
3121
+ base: void 0,
3122
+ user: void 0,
3123
+ mode: "host"
3124
+ };
3125
+ if (JSON.stringify(next) !== JSON.stringify(snapshot)) {
3126
+ snapshot = next;
3127
+ emit();
3128
+ }
3129
+ };
3130
+ async function refresh() {
3131
+ try {
3132
+ const response = await fetch(SETTINGS_ROUTE, { headers: { "cache-control": "no-cache" } });
3133
+ if (!response.ok) throw new Error(`settings bridge ${response.status}`);
3134
+ const body = await response.json();
3135
+ applyDoc(body.doc, body.revision ?? void 0);
3136
+ } catch {
3137
+ if (snapshot.status !== "unavailable") {
3138
+ snapshot = {
3139
+ ...snapshot,
3140
+ status: "unavailable"
3141
+ };
3142
+ emit();
3143
+ }
3144
+ }
3145
+ }
3146
+ async function writeDoc(next) {
3147
+ const response = await fetch(SETTINGS_ROUTE, {
3148
+ method: "POST",
3149
+ headers: { "content-type": "application/json" },
3150
+ body: JSON.stringify({ doc: next })
3151
+ });
3152
+ if (!response.ok) return false;
3153
+ const body = await response.json();
3154
+ if (body.ok !== true) return false;
3155
+ applyDoc(body.doc ?? next, (snapshot.revision ?? 0) + 1);
3156
+ return true;
3157
+ }
3158
+ const cloneDoc = () => {
3159
+ const value = snapshot.value;
3160
+ return value === void 0 ? {} : structuredClone(value);
3161
+ };
3162
+ return {
3163
+ getSnapshot: () => snapshot,
3164
+ subscribe: (listener) => {
3165
+ listeners.add(listener);
3166
+ if (listeners.size === 1) {
3167
+ refresh();
3168
+ pollTimer = setInterval(() => {
3169
+ refresh();
3170
+ }, POLL_MS);
3171
+ }
3172
+ return () => {
3173
+ listeners.delete(listener);
3174
+ if (listeners.size === 0 && pollTimer !== void 0) {
3175
+ clearInterval(pollTimer);
3176
+ pollTimer = void 0;
3177
+ }
3178
+ };
3179
+ },
3180
+ set: async (field, value) => {
3181
+ const next = cloneDoc();
3182
+ next[field] = value;
3183
+ return writeDoc(next);
3184
+ },
3185
+ unset: async (field) => {
3186
+ const next = cloneDoc();
3187
+ delete next[field];
3188
+ return writeDoc(next);
3189
+ },
3190
+ mutate: async (ops) => {
3191
+ const doc = cloneDoc();
3192
+ for (const op of ops) {
3193
+ const [head, key] = op.path;
3194
+ if (head !== "presetOptions") return false;
3195
+ const section = { ...doc.presetOptions ?? {} };
3196
+ if (op.op === "unset") delete section[key];
3197
+ else section[key] = op.value;
3198
+ doc.presetOptions = section;
3199
+ }
3200
+ return writeDoc(doc);
3201
+ },
3202
+ refresh: () => {
3203
+ refresh();
3204
+ }
3205
+ };
3206
+ }
3207
+ //#endregion
3096
3208
  //#region src/client/index.ts
3097
- const inject = [
3098
- "slots",
3099
- "locale",
3100
- "configForms"
3101
- ];
3209
+ const inject = ["slots", "locale"];
3102
3210
  const NS = "context-compression";
3103
3211
  /** 0.1.7: the profile entry whose config carries the compression settings doc. */
3104
3212
  const ENTRY_ID = "context-compression-improved-bundle";
@@ -3159,13 +3267,11 @@ window.__ModuleLoader__.load({
3159
3267
  console.warn(`[dsh-context-compression-improved] locale "${language.id}" registration failed:`, error);
3160
3268
  }
3161
3269
  const tNav = ctx.locale?.bind?.(NS) ?? ((key) => key);
3162
- let readMonitorPanelEnabled = () => {
3163
- try {
3164
- return decodeSettings(ctx.configForms.get(ENTRY_ID).getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false;
3165
- } catch {
3166
- return false;
3167
- }
3168
- };
3270
+ let configFormsHandle;
3271
+ /** Last monitorPanel.enabled seen through whichever scope is current (FAB 读数缓存). */
3272
+ let monitorPanelEnabledCache = false;
3273
+ /** 浮动监控面板(FAB): body 级幂等单例。enabled 读数走双臂 scope 的投影缓存。 */
3274
+ let readMonitorPanelEnabled = () => monitorPanelEnabledCache;
3169
3275
  let latestSessionId;
3170
3276
  try {
3171
3277
  initMonitorFab({
@@ -3190,10 +3296,23 @@ window.__ModuleLoader__.load({
3190
3296
  } catch (error) {
3191
3297
  console.warn("[dsh-context-compression-improved] 监控浮动球挂载失败(不影响设置分节):", error);
3192
3298
  }
3193
- const injected = () => {
3194
- const form = ctx.configForms.get(ENTRY_ID);
3299
+ const bridgeScope = createBridgeScope();
3300
+ bridgeScope.refresh();
3301
+ const bridgeReadEnabled = () => decodeSettings(bridgeScope.getSnapshot().value)?.monitorPanel?.enabled ?? false;
3302
+ readMonitorPanelEnabled = () => configFormsHandle === void 0 ? bridgeReadEnabled() : monitorPanelEnabledCache;
3303
+ try {
3304
+ ctx.inject(["configForms"], (configFormsArg) => {
3305
+ const svc = configFormsArg?.configForms;
3306
+ const face = svc !== void 0 && svc !== null ? svc : configFormsArg;
3307
+ configFormsHandle = typeof face?.get === "function" ? face : void 0;
3308
+ });
3309
+ } catch (error) {
3310
+ console.warn("[dsh-context-compression-improved] configForms 臂挂载失败(桥面继续服务):", error);
3311
+ }
3312
+ /** configForms 原生 scope(0.1.7+):volatile entry 字段权威写路径。 */
3313
+ const scopeFromConfigForms = (service) => {
3314
+ const form = service.get(ENTRY_ID);
3195
3315
  const readDoc = () => decodeSettings(form.getSnapshot().value?.settings);
3196
- readMonitorPanelEnabled = () => decodeSettings(form.getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false;
3197
3316
  let projectedSource;
3198
3317
  let projected = {
3199
3318
  status: "loading",
@@ -3204,21 +3323,22 @@ window.__ModuleLoader__.load({
3204
3323
  user: void 0,
3205
3324
  mode: "host"
3206
3325
  };
3207
- const scope = {
3326
+ return {
3208
3327
  getSnapshot() {
3209
3328
  const snap = form.getSnapshot();
3210
3329
  if (snap !== projectedSource) {
3211
3330
  projectedSource = snap;
3212
3331
  projected = {
3213
- status: snap.status,
3332
+ status: snap.status ?? "loading",
3214
3333
  value: decodeSettings(snap.value?.settings),
3215
- revision: snap.revision,
3216
- writable: snap.writable,
3334
+ revision: snap.revision ?? void 0,
3335
+ writable: snap.writable ?? false,
3217
3336
  base: snap.base,
3218
3337
  user: snap.user,
3219
- mode: snap.mode
3338
+ mode: snap.mode ?? "host"
3220
3339
  };
3221
3340
  }
3341
+ monitorPanelEnabledCache = projected.value?.monitorPanel?.enabled ?? false;
3222
3342
  return projected;
3223
3343
  },
3224
3344
  subscribe: (listener) => form.subscribe(listener),
@@ -3245,6 +3365,14 @@ window.__ModuleLoader__.load({
3245
3365
  return form.set("settings", doc);
3246
3366
  }
3247
3367
  };
3368
+ };
3369
+ const injected = () => {
3370
+ let scope = bridgeScope;
3371
+ if (configFormsHandle !== void 0) try {
3372
+ scope = scopeFromConfigForms(configFormsHandle);
3373
+ } catch (error) {
3374
+ console.warn("[dsh-context-compression-improved] configForms scope 构建失败(回落桥面):", error);
3375
+ }
3248
3376
  const writeAndConfirm = async (write, accepts) => {
3249
3377
  const beforeRevision = scope.getSnapshot().revision;
3250
3378
  await write();
@@ -3267,6 +3395,27 @@ window.__ModuleLoader__.load({
3267
3395
  }
3268
3396
  };
3269
3397
  };
3398
+ const sectionViaAdapter = (props) => {
3399
+ const inj = injected();
3400
+ const scope = inj.hooks?.compression;
3401
+ const useCompression = (selector) => {
3402
+ if (!scope) return selector({
3403
+ status: "loading",
3404
+ value: void 0,
3405
+ revision: void 0,
3406
+ writable: false,
3407
+ base: void 0,
3408
+ user: void 0,
3409
+ mode: "memory"
3410
+ });
3411
+ return (0, react.useSyncExternalStore)(scope.subscribe, () => selector(scope.getSnapshot()));
3412
+ };
3413
+ return (0, react.createElement)(ContextCompressionSettingsSection, {
3414
+ ...inj,
3415
+ ...props,
3416
+ useCompression
3417
+ });
3418
+ };
3270
3419
  try {
3271
3420
  ctx.slots.inject("settings.section", () => ctx.slots.register({
3272
3421
  name: "settings.section",
@@ -3277,7 +3426,7 @@ window.__ModuleLoader__.load({
3277
3426
  inject: injected
3278
3427
  }, ContextCompressionSettingsSection));
3279
3428
  } catch (error) {
3280
- console.warn("[dsh-context-compression-improved] settings.section 注册失败(新宿主已收编):", error);
3429
+ console.warn("[dsh-context-compression-improved] settings.section 注册失败(宿主无该槽,静默缺席):", error);
3281
3430
  }
3282
3431
  try {
3283
3432
  ctx.slots.inject("conversation.input.left", () => ctx.slots.register({
@@ -3292,6 +3441,15 @@ window.__ModuleLoader__.load({
3292
3441
  } catch (error) {
3293
3442
  console.warn("[dsh-context-compression-improved] conversation.input.left 注册失败(旧宿主无该槽,浮动面板保持聚合口径):", error);
3294
3443
  }
3444
+ try {
3445
+ ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
3446
+ name: "plugins.bundle.config",
3447
+ key: "dsh-context-compression-improved",
3448
+ locale: NS
3449
+ }, sectionViaAdapter));
3450
+ } catch (error) {
3451
+ console.warn("[dsh-context-compression-improved] plugins.bundle.config 注册失败(旧宿主无该槽,静默缺席):", error);
3452
+ }
3295
3453
  }
3296
3454
  //#endregion
3297
3455
  exports.apply = apply;
@@ -0,0 +1,62 @@
1
+ //#region src/compat/host-generation.ts
2
+ let cached;
3
+ /**
4
+ * Pure classifier from a RESOLVED settings service face. A service that still
5
+ * exposes `register` is a pre-0.1.7 host (0.1.0–0.1.5 lines, dsh-settings pack
6
+ * evidence — verified on the real 0.1.0-rc.2 host: `register(ns, schema,
7
+ * options)` at dsh-settings/lib/index.js:311); from 0.1.7-rc.1 the service
8
+ * drops register entirely and settings live in the loader-managed entry
9
+ * config.
10
+ */
11
+ function classifySettingsFace(settings) {
12
+ return typeof settings?.register === "function" ? "legacy" : "modern";
13
+ }
14
+ /**
15
+ * Probe the host generation from the settings service face.
16
+ *
17
+ * A verdict is only CACHED from a resolved service object. Rows compose
18
+ * before host services on every line (measured: the wire-time probe on a real
19
+ * 0.1.0-rc.2 cell saw no settings service yet and the old code cached
20
+ * 'modern' forever — the legacy lease arm went dead on the exact line it was
21
+ * built for). While the service is absent the answer is a provisional
22
+ * 'modern' and deliberately uncached, so the definitive
23
+ * `noteResolvedSettingsService` evidence can still flip it.
24
+ */
25
+ function detectHostGeneration(ctx) {
26
+ if (cached !== void 0) return cached;
27
+ let settings;
28
+ try {
29
+ settings = ctx.get("settings");
30
+ } catch {
31
+ return "modern";
32
+ }
33
+ if (settings === null || typeof settings !== "object") return "modern";
34
+ cached = classifySettingsFace(settings);
35
+ return cached;
36
+ }
37
+ /**
38
+ * Definitive verdict from the resolved service (evidence observed, not
39
+ * guessed): the settings inject callback calls this once the service has
40
+ * actually composed. Always (re)writes the cache — a provisional earlier
41
+ * verdict must not survive real evidence.
42
+ */
43
+ function noteResolvedSettingsService(settings) {
44
+ cached = classifySettingsFace(settings);
45
+ return cached;
46
+ }
47
+ /**
48
+ * Server-plane snapshot for code paths that hold no ctx (the tool-result
49
+ * adapters). The bridge's inject callback has already noted the resolved
50
+ * service by the time any session message flows, so this reads real evidence
51
+ * on every line; without it the only safe answer is the provisional default.
52
+ */
53
+ function hostGenerationSnapshot() {
54
+ return cached ?? "modern";
55
+ }
56
+ function compatLog(ctx, level = "info") {
57
+ if (detectHostGeneration(ctx) === "legacy") return (message, ...rest) => console[level](`[dsh-context-compression-improved] ${message}`, ...rest);
58
+ const sink = ctx.logger?.[level]?.bind(ctx.logger) ?? ((...rest) => console[level](...rest));
59
+ return (message, ...rest) => sink(`[dsh-context-compression-improved] ${message}`, ...rest);
60
+ }
61
+ //#endregion
62
+ export { noteResolvedSettingsService as i, detectHostGeneration as n, hostGenerationSnapshot as r, compatLog as t };