dsh-context-compression-improved 0.1.1 → 0.2.1

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 (148) hide show
  1. package/.gitattributes +1 -0
  2. package/.github/workflows/ci.yml +39 -0
  3. package/CHANGELOG.ja.md +39 -0
  4. package/CHANGELOG.ko.md +39 -0
  5. package/CHANGELOG.md +135 -0
  6. package/CHANGELOG.zh.md +39 -0
  7. package/CONTRIBUTING.md +22 -0
  8. package/README.ja.md +104 -0
  9. package/README.ko.md +103 -0
  10. package/README.md +89 -12
  11. package/README.zh.md +87 -12
  12. package/SECURITY.md +18 -0
  13. package/THIRD_PARTY_NOTICES.md +7 -31
  14. package/docs/installation.ja.md +76 -0
  15. package/docs/installation.ko.md +76 -0
  16. package/docs/installation.md +76 -0
  17. package/docs/installation.zh.md +76 -0
  18. package/docs/repair-log.md +582 -0
  19. package/eslint.config.js +30 -0
  20. package/package.json +85 -82
  21. package/packages/selector/LICENSE +21 -0
  22. package/packages/selector/README.md +26 -0
  23. package/packages/selector/README.zh.md +26 -0
  24. package/packages/selector/THIRD_PARTY_NOTICES.md +38 -0
  25. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -0
  26. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -0
  27. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -0
  28. package/packages/selector/lib/style.css +308 -0
  29. package/packages/selector/package.json +115 -0
  30. package/{screenshots.json → packages/selector/screenshots.json} +6 -6
  31. package/packages/selector/src/client/CompressionProfileControls.tsx +229 -0
  32. package/packages/selector/src/client/CompressionProfileSelector.module.css +170 -0
  33. package/packages/selector/src/client/CompressionProfileSelector.tsx +79 -0
  34. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -0
  35. package/packages/selector/src/client/EstimatorControls.tsx +281 -0
  36. package/packages/selector/src/client/decode.ts +49 -0
  37. package/packages/selector/src/client/index.ts +111 -0
  38. package/packages/selector/src/client/locales.ts +198 -0
  39. package/packages/selector/src/client/preset-options.ts +70 -0
  40. package/packages/selector/src/client/settings-section.tsx +126 -0
  41. package/packages/selector/src/css-modules.d.ts +6 -0
  42. package/packages/selector/src/deepseek-v4-tokenizer.ts +210 -0
  43. package/packages/selector/src/estimator-catalog.ts +104 -0
  44. package/packages/selector/src/index.ts +327 -0
  45. package/packages/selector/src/invariant.ts +113 -0
  46. package/packages/selector/src/preset-overlay.ts +567 -0
  47. package/packages/selector/src/profiles.ts +342 -0
  48. package/packages/selector/src/pruner/content.ts +188 -0
  49. package/packages/selector/src/pruner/session.ts +94 -0
  50. package/packages/selector/src/pruner/state.ts +43 -0
  51. package/packages/selector/src/pruner/tuning.ts +23 -0
  52. package/packages/selector/src/pruner/types.ts +60 -0
  53. package/packages/selector/src/pruner.ts +2144 -0
  54. package/packages/selector/src/runtime/adaptive-cost.ts +194 -0
  55. package/packages/selector/src/runtime/audit.ts +215 -0
  56. package/packages/selector/src/runtime/config.ts +613 -0
  57. package/packages/selector/src/runtime/custom-policy.ts +278 -0
  58. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -0
  59. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -0
  60. package/packages/selector/src/runtime/measurement.ts +403 -0
  61. package/packages/selector/src/runtime/reducers.ts +656 -0
  62. package/packages/selector/src/runtime/retrieve.ts +457 -0
  63. package/packages/selector/src/runtime/session-events.ts +17 -0
  64. package/packages/selector/src/runtime/tail-trim.ts +166 -0
  65. package/packages/selector/src/runtime/token-count.ts +72 -0
  66. package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -0
  67. package/packages/selector/src/runtime/tokenpilot/estimator.ts +183 -0
  68. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -0
  69. package/packages/selector/src/runtime/tokenpilot/read-state.ts +77 -0
  70. package/packages/selector/src/runtime/types.ts +309 -0
  71. package/packages/selector/src/runtime/value.ts +48 -0
  72. package/packages/selector/tests/auto-compact.client.spec.tsx +226 -0
  73. package/packages/selector/tests/built/client-artifact.spec.ts +51 -0
  74. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -0
  75. package/packages/selector/tests/code-skeleton.client.spec.ts +88 -0
  76. package/packages/selector/tests/custom-contract.client.spec.ts +202 -0
  77. package/packages/selector/tests/estimator-catalog.spec.ts +70 -0
  78. package/packages/selector/tests/estimator-channel.client.spec.tsx +247 -0
  79. package/packages/selector/tests/estimator-route-registration.host.spec.ts +176 -0
  80. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -0
  81. package/packages/selector/tests/preset-options-write.client.spec.ts +181 -0
  82. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +196 -0
  83. package/packages/selector/tests/preset-overlay.host.spec.ts +243 -0
  84. package/packages/selector/tests/profiles.client.spec.tsx +434 -0
  85. package/packages/selector/tests/public/package-contract.client.spec.ts +33 -0
  86. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -0
  87. package/packages/selector/tests/runtime/audit.spec.ts +129 -0
  88. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -0
  89. package/packages/selector/tests/runtime/code-skeleton.spec.ts +141 -0
  90. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -0
  91. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -0
  92. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -0
  93. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -0
  94. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -0
  95. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -0
  96. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2531 -0
  97. package/packages/selector/tests/runtime/session-events.spec.ts +27 -0
  98. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -0
  99. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -0
  100. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +56 -0
  101. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -0
  102. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +100 -0
  103. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +58 -0
  104. package/packages/selector/tests/runtime/value.spec.ts +23 -0
  105. package/packages/selector/tests/standing-generation.host.spec.ts +631 -0
  106. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +250 -0
  107. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -0
  108. package/packages/selector/tests/support/mock-adapter.ts +37 -0
  109. package/packages/selector/tests/support/ui-primitives.tsx +34 -0
  110. package/packages/selector/tsconfig.json +11 -0
  111. package/packages/selector/tsdown.client.config.ts +102 -0
  112. package/packages/selector/tsdown.config.ts +20 -0
  113. package/pnpm-workspace.yaml +19 -0
  114. package/scripts/capture-profile-baseline.ts +80 -0
  115. package/scripts/generate-tokenizer-fixtures.py +81 -0
  116. package/scripts/generate-vision-fixtures.py +208 -0
  117. package/scripts/packed-components-smoke.ts +713 -0
  118. package/scripts/packed-install-e2e.ts +1072 -0
  119. package/scripts/verify-release.ts +300 -0
  120. package/tests/TEST_INVENTORY.md +42 -0
  121. package/tsconfig.base.json +18 -0
  122. package/tsconfig.json +7 -0
  123. package/tsconfig.scripts.json +13 -0
  124. package/tsconfig.tests.json +15 -0
  125. package/vitest.built.config.ts +9 -0
  126. package/vitest.config.ts +43 -0
  127. /package/{assets → packages/selector/assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  128. /package/{assets → packages/selector/assets}/deepseek-v4/manifest.json +0 -0
  129. /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer.json +0 -0
  130. /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer_config.json +0 -0
  131. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  132. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  133. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  134. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  135. /package/{assets → packages/selector/assets}/screenshots/context-compression-selector-profiles.jpg +0 -0
  136. /package/{assets → packages/selector/assets}/screenshots/context-compression-selector-settings.png +0 -0
  137. /package/{cordis.patch.yml → packages/selector/cordis.patch.yml} +0 -0
  138. /package/{dsh.plugin.json → packages/selector/dsh.plugin.json} +0 -0
  139. /package/{lib → packages/selector/lib}/client.d.ts +0 -0
  140. /package/{lib → packages/selector/lib}/client.js +0 -0
  141. /package/{lib → packages/selector/lib}/config.js +0 -0
  142. /package/{lib → packages/selector/lib}/index.d.ts +0 -0
  143. /package/{lib → packages/selector/lib}/index.js +0 -0
  144. /package/{lib → packages/selector/lib}/invariant.d.ts +0 -0
  145. /package/{lib → packages/selector/lib}/invariant.js +0 -0
  146. /package/{lib → packages/selector/lib}/pruner.d.ts +0 -0
  147. /package/{lib → packages/selector/lib}/pruner.js +0 -0
  148. /package/{lib → packages/selector/lib}/tail-trim.js +0 -0
package/README.md CHANGED
@@ -1,26 +1,103 @@
1
1
  # dsh-context-compression-improved
2
2
 
3
- The installable Product Bundle for the unofficial community DeepSeek Harness context-compression selector.
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**.
4
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.
5
+ [中文说明](README.zh.md) · [日本語](README.ja.md) · [한국어](README.ko.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
+ ## What it is
18
+
19
+ 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:
20
+
21
+ - **Fresh** pre-compresses a newly oversized tool-result segment before the model receives it.
22
+ - **Aggregate** pre-compresses fresh material again when it still grows beyond its budget.
23
+ - **History / micro-compact** replaces eligible old tool results while preserving recent working context.
24
+ - **TailTrim** is an optional Custom-only tail reduction path.
25
+ - **Native** preserves the Harness-style head/middle/tail trimming as one explicit profile.
26
+ - **Code skeleton (new, orthogonal gate)** — see below.
27
+
28
+ Every decision is recorded: stage, reducer, trigger, skip reason, and exact token counts where available.
29
+
30
+ ## Code skeleton gate (new)
31
+
32
+ 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.
33
+
34
+ Properties:
35
+
36
+ - **Orthogonal**: independent of the selected profile (`balanced`, `savings`, `cache-strict`, `adaptive`, `custom`, `off`, `native`). All profiles get the gate.
37
+ - **Off by default**: `codeSkeleton: { enabled: false }` until you turn it on.
38
+ - **Measurement-gated**: requires the exact DeepSeek tokenizer; without it the plugin fails open.
39
+ - **Session-frozen**: like all selector settings, changes affect newly observed sessions only.
40
+ - **Strictly parsed**: `codeSkeleton` must be exactly `{ enabled: boolean }`; malformed values throw on the runtime side and show as unreadable in the browser UI.
41
+
42
+ ### Provenance, and whose numbers these are
43
+
44
+ The skeletonization approach is borrowed from **[Headroom](https://github.com/headroomlabs-ai/headroom)**
45
+ (Apache-2.0) — a context-compression layer for AI agents that routes JSON, source code and prose
46
+ through separate compressors (`SmartCrusher` for JSON, `CodeCompressor` for code), with its
47
+ skeleton transform living in `crates/headroom-core/src/transforms/live_zone.rs` and
48
+ `smart_crusher/planning.rs`.
49
+
50
+ **The reduction figures are Headroom's, not this plugin's.** Headroom's published claim, verbatim:
51
+
52
+ > 20% fewer tokens for coding agents, **60–95% fewer tokens for JSON**, same answers.
53
+
54
+ The headline — **up to 95% fewer tokens** — comes from that sentence: JSON payloads, measured by
55
+ Headroom's own compressors on Headroom's own benchmarks. That is the same source this gate draws
56
+ its mechanism from. This repository ships **no benchmark of its own**, so it claims **no reduction
57
+ percentage of its own**; read the measurements at the source.
58
+
59
+ ## Settings UI
60
+
61
+ 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.
62
+
63
+ ![Context Compression Selector settings UI](packages/selector/assets/screenshots/context-compression-selector-settings.png)
64
+
65
+ ## Install
66
+
67
+ Build and install from source (this fork is not yet published to npm; the internal package names intentionally stay upstream's):
6
68
 
7
69
  ```sh
8
- dsh plugin --profile web add dsh-context-compression-improved@latest
9
- dsh --profile web --dump-config
70
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
71
+ cd dsh-context-compression-improved
72
+ pnpm install --frozen-lockfile
73
+ pnpm build
10
74
  ```
11
75
 
12
- This one command installs the Bundle and its pinned `@huggingface/tokenizers` dependency; there is no separate runtime package. The Bundle contributes Host settings, the Web UI, and a reversible preset overlay. All presets except the exact built-in `minimal` id receive the compression stack; switching non-Minimal presets preserves the saved selector settings. Minimal pauses plugin compression without deleting the setting.
76
+ 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).
13
77
 
14
- ## What it provides
78
+ ## Development
15
79
 
16
- It provides deterministic Fresh, Aggregate, History, Native tool-result, and Custom TailTrim compression; a plugin-owned `context_compression_retrieve` recovery tool; structured audit records; and a pinned offline DeepSeek V4 tokenizer. It uses only public DeepSeek Harness APIs and supports both `0.1.1-rc.2` and `0.1.2-alpha.5`; it does not patch Harness core.
80
+ ```sh
81
+ pnpm install --frozen-lockfile
82
+ pnpm lint # ESLint baseline (also enforced in CI)
83
+ pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
84
+ pnpm test # full vitest suite
85
+ pnpm test:watch # TDD loop: write the failing regression first, then make it pass
86
+ pnpm build
87
+ pnpm verify:release
88
+ ```
17
89
 
18
- Lossy rewrites require exact same-revision counts before and after replacement. Verified model ids are `deepseek-v4-flash`, `deepseek-v4-pro`, and `deepseek-v4-flash-vision-exp`. Vision text counting uses the separately pinned `deepseek-ai/DeepSeek-V4-Flash-Vision-Exp` tokenizer. Vision images use the official image-processor arithmetic validated against official golden fixtures and are reported as `tokenizer-estimate`: the four alignment residues over valid intrinsic dimensions are collapsed to their midpoint, with 384 tokens retained as the per-image upper bound; malformed or unevaluable dimensions use a fixed 256-token fallback. The estimate is not exact because the absolute prompt position and the adapter's final image projection are not publicly observable. Image-bearing tool-result candidates remain exact-ineligible and intact; unknown models, unavailable tokenizer assets, unsafe tool groups, and incomplete text measurements still fail open.
90
+ 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).
19
91
 
20
- Audit log records use the prefix `context-compression audit ` and distinguish policy snapshots, skipped/disabled components, committed rewrites, fail-open errors, and observed core `compaction/summary` events. No audit record contains prompt or tool-result content.
92
+ ## Compatibility
21
93
 
22
- The first `policy-frozen` record carries the complete settings/deployment snapshot. It is emitted through the Harness logger, so its retention follows the configured log sink; standard prune/replacement Session events remain the durable proof of committed rewrites. This package does not hard-code a private path below `~/.dsh`.
94
+ - Verified against DeepSeek Harness `dsh-v0.1.1-rc.2` using public plugin and profile APIs only; compatible with the official `dsh-v0.1.2-alpha.5` release.
95
+ - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
96
+ - 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.
23
97
 
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.
98
+ ## Credits and license
25
99
 
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. Tokenizer provenance and checksums are in `assets/deepseek-v4/manifest.json` and `assets/deepseek-v4-vision-exp/manifest.json`, summarized in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). This package is not affiliated with or endorsed by DeepSeek.
100
+ - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
101
+ - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
102
+ - Code-skeleton mechanism: [Headroom](https://github.com/headroomlabs-ai/headroom) (Apache-2.0) — see "Provenance, and whose numbers these are" above.
103
+ - MIT — see [LICENSE](LICENSE) (upstream copyright notice retained) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for bundled tokenizer provenance.
package/README.zh.md CHANGED
@@ -1,26 +1,101 @@
1
1
  # dsh-context-compression-improved
2
2
 
3
- 这是可直接安装的非官方社区 DeepSeek Harness 上下文压缩选择器 Product Bundle。
3
+ > [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) 的改进版 fork——面向 DeepSeek Harness 的可审计工具结果上下文压缩选择器,新增正交的**代码骨架压缩门**。
4
4
 
5
- **0.1.0 更新:**已加入 DeepSeek V4 Flash 视觉模型的官方 tokenizer;用户可选择模型驱动 Auto Compact 的触发阈值;标准 Profile 的水位与压缩参数会随该选择联动。
5
+ [English](README.md) · [日本語](README.ja.md) · [한국어](README.ko.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
+ ## 它是什么
18
+
19
+ 长时运行的 agent 任务会积累大量工具输出。本社区插件在不修改 DeepSeek Harness 核心的前提下,提供可选、可审计的工具结果上下文压缩策略:
20
+
21
+ - **Fresh**:在模型收到之前,预压缩新近超限的工具结果段。
22
+ - **Aggregate**:当 Fresh 压缩后仍超出预算时再次预压缩。
23
+ - **History / micro-compact**:在保护近期工作上下文的前提下替换符合条件的旧工具结果。
24
+ - **TailTrim**:仅在 Custom 下可选的尾窗收缩路径。
25
+ - **Native**:把 Harness 原生头/中/尾裁剪保留为一个显式 Profile。
26
+ - **代码骨架(新增,正交门)**——见下节。
27
+
28
+ 每个决策都会留痕:阶段、reducer、触发原因、跳过原因,以及可得时的精确 token 数。
29
+
30
+ ## 代码骨架门(新增)
31
+
32
+ 开启后,超大**源码类新工具结果**(例如大型 `read_file`)会先尝试骨架化压缩:保留导入与类型/函数/类声明,省略函数体并加占位标记,被省略函数体内的错误行予以保留。若骨架无法生成或无法通过验证,则回退到原有的头部裁剪——这道门不会让上下文变得更差。
33
+
34
+ 特性:
35
+
36
+ - **正交**:独立于所选 Profile(`balanced`、`savings`、`cache-strict`、`adaptive`、`custom`、`off`、`native`),所有 Profile 都能拿到这道门。
37
+ - **默认关闭**:`codeSkeleton: { enabled: false }`,需要显式开启。
38
+ - **测量前置**:需要精确 DeepSeek tokenizer;不可用时 fail-open。
39
+ - **会话冻结**:与所有选择器设置一致,修改只影响新观察的会话。
40
+ - **严格解析**:`codeSkeleton` 必须恰好是 `{ enabled: boolean }`;畸形输入在运行时侧抛错、浏览器侧显示不可读。
41
+
42
+ ### 出处,以及这些数字是谁的
43
+
44
+ 骨架化思路借鉴自 **[Headroom](https://github.com/headroomlabs-ai/headroom)**(Apache-2.0)——
45
+ 一个面向 AI Agent 的上下文压缩层,把 JSON、源码与散文分别交给不同压缩器(JSON 走
46
+ `SmartCrusher`,代码走 `CodeCompressor`),其骨架化变换位于
47
+ `crates/headroom-core/src/transforms/live_zone.rs` 与 `smart_crusher/planning.rs`。
48
+
49
+ **降幅数字是 Headroom 的,不是本插件的。** Headroom 公开的官方口径原文如下:
50
+
51
+ > 20% fewer tokens for coding agents, **60–95% fewer tokens for JSON**, same answers.
52
+
53
+ 其中 **最高降 95%** 即出自这一句:口径为 JSON 载荷,由 Headroom 自家压缩器在其自家基准上测得,
54
+ 也正是本门机制的同源出处。本仓库**不含任何自己的 benchmark**,因此**不自称任何降幅百分比**;
55
+ 要数字,请到源头读。
56
+
57
+ ## 设置界面
58
+
59
+ 在同一设置区内选择压缩 Profile、调整 Auto Compact 触发水位,并开关代码骨架压缩。开关即改即存,刷新后显示已保存状态。
60
+
61
+ ![Context Compression Selector 设置界面](packages/selector/assets/screenshots/context-compression-selector-settings.png)
62
+
63
+ ## 安装
64
+
65
+ 从源码构建并安装(本 fork 尚未发布 npm 包;内部包名有意保持与上游一致):
6
66
 
7
67
  ```sh
8
- dsh plugin --profile web add dsh-context-compression-improved@latest
9
- dsh --profile web --dump-config
68
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
69
+ cd dsh-context-compression-improved
70
+ pnpm install --frozen-lockfile
71
+ pnpm build
10
72
  ```
11
73
 
12
- 这一条命令会安装 Bundle 及其固定版本的 `@huggingface/tokenizers` 依赖,不再需要单独的 runtime 包。Bundle 提供 Host 设置、Web UI 和可逆的 preset overlay。除 id 精确等于内置 `minimal` 的 preset 外,其他 preset 都会获得压缩能力;非 Minimal preset 之间切换时已保存设置保持不变。Minimal 只暂停插件压缩,不删除设置。
74
+ 随后打包 selector 包并安装到某个 Harness Profile——完整步骤(含验证与卸载)见[安装教程](docs/installation.zh.md)。
13
75
 
14
- ## 本包能力
76
+ ## 开发
15
77
 
16
- 本包提供确定性的 Fresh、Aggregate、History、Native 工具结果与 Custom TailTrim 压缩,插件自有的 `context_compression_retrieve` 恢复工具,结构化审计记录,以及固定版本的离线 DeepSeek V4 tokenizer。它只使用 DeepSeek Harness 的公开 API,兼容 `0.1.1-rc.2` 与 `0.1.2-alpha.5`,不修改 Harness 核心。
78
+ ```sh
79
+ pnpm install --frozen-lockfile
80
+ pnpm lint # ESLint 基线(CI 同步强制)
81
+ pnpm typecheck # runtime + selector + tests tsc,含 bundle 步
82
+ pnpm test # vitest 全量
83
+ pnpm test:watch # TDD 环路:先写失败的回归用例,再让它通过
84
+ pnpm build
85
+ pnpm verify:release
86
+ ```
17
87
 
18
- 有损改写要求 replacement 前后取得同 revision 的 exact count。明确验证过的模型 id 为 `deepseek-v4-flash`、`deepseek-v4-pro` 与 `deepseek-v4-flash-vision-exp`。视觉模型的文本计数使用独立固定的 `deepseek-ai/DeepSeek-V4-Flash-Vision-Exp` tokenizer。图像 token 使用由官方 golden fixtures 逐项验证的官方图像处理算术,并以 `tokenizer-estimate` 上报:有效 intrinsic 尺寸的四种对齐位置取中值,每张图片保留 384 token 上限;尺寸畸形或无法计算时固定计为 256 token。由于绝对 prompt 位置与 adapter 最终图片投影不可公开观测,该数值不标记为 exact。含图片的工具结果候选仍不具备 exact 资格并保持原样;未知模型、tokenizer 资产不可用、不安全工具组或文本计量不完整时继续 fail-open。
88
+ 贡献遵循上游纪律:先写失败的回归用例;所有生产改动收敛在本仓库内;对“已触发”“已启用但跳过”“fail-open”分别给出证据。见 [CONTRIBUTING.md](CONTRIBUTING.md)
19
89
 
20
- 审计日志以 `context-compression audit ` 开头,区分策略快照、组件关闭/跳过、已提交 rewrite、fail-open 错误和已观察到的核心 `compaction/summary`。审计记录不包含 prompt 或工具结果正文。
90
+ ## 兼容性
21
91
 
22
- 首次 `policy-frozen` 会携带完整 settings/deployment 快照。它通过 Harness logger 输出,因此保留期限由部署的日志 sink 决定;标准 prune/replacement Session event 仍是已提交 rewrite 的持久证据。本包不会在 `~/.dsh` 下硬编码私有路径。
92
+ - 仅使用公开的插件与 Profile API,针对 DeepSeek Harness `dsh-v0.1.1-rc.2` 验证;兼容官方 `dsh-v0.1.2-alpha.5` 版本。
93
+ - 需要 Node `^22.19.0 || >=24` 与 pnpm `11.7.0`。
94
+ - 插件只使用 Harness 公开扩展 API,不修改 Harness 核心代码。非官方社区项目,与 DeepSeek 无隶属或背书关系。
23
95
 
24
- 已验证兼容:DeepSeek Harness `dsh-v0.1.1-rc.2` 与 `dsh-v0.1.2-alpha.5`,Node `^22.19.0 || >=24`。不需要修改 Harness 核心。
96
+ ## 致谢与许可
25
97
 
26
- Profile、默认值、审计证据、Adaptive/cache 限制、升级/卸载与安全说明见[完整 README](https://github.com/WilliamShi666/dsh-context-compression-improved#readme)。Tokenizer 来源与校验和在 `assets/deepseek-v4/manifest.json`、`assets/deepseek-v4-vision-exp/manifest.json`,并汇总于 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。本包与 DeepSeek 无隶属或背书关系。
98
+ - 上游项目与全部既有工作:[WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector),作者 WilliamShi666(MIT)。
99
+ - fork 新增内容(代码骨架门、工具链、多语文档):drscrewdriver。
100
+ - 代码骨架机制来源:[Headroom](https://github.com/headroomlabs-ai/headroom)(Apache-2.0)——见上文「出处,以及这些数字是谁的」。
101
+ - MIT——见 [LICENSE](LICENSE)(保留上游版权声明);内置 tokenizer 来源见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
package/SECURITY.md ADDED
@@ -0,0 +1,18 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ During the initial release, only the newest published Beta or stable version is supported. Compatibility is limited to the Harness versions listed in the README.
6
+
7
+ ## Reporting a vulnerability
8
+
9
+ Please use GitHub's private **Report a vulnerability** flow for this repository. Do not open a public issue containing secrets, exploit details, private Session data, prompts, tool results, or user paths.
10
+
11
+ Include the affected plugin version, Harness version, minimal reproduction, impact, and whether the issue can alter Session surface/recovery behavior. We will acknowledge a valid report as soon as practical, investigate privately, and publish a coordinated fix and advisory when appropriate.
12
+
13
+ ## Security posture
14
+
15
+ - The Bundle does not require credentials of its own.
16
+ - Compression and recovery are same-Session operations; audit records omit model-visible content.
17
+ - Unknown models, tokenizer integrity failures, malformed policies, unsafe tool groups, and incomplete exact measurements fail open.
18
+ - NPM tarballs use explicit file allowlists and do not ship source maps, user logs, Sessions, or local configuration.
@@ -1,38 +1,14 @@
1
1
  # Third-party notices
2
2
 
3
- Portions of this package are adapted from the MIT-licensed DeepSeek Harness, verified against `dsh-v0.1.1-rc.2` (`b150a551b8d465e31e418e1b2eaf5e79bbb7d28e`).
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`.
4
4
 
5
- ## DeepSeek Harness MIT notice
5
+ The runtime package distributes tokenizer assets from these pinned official repositories, both under the MIT license:
6
6
 
7
- Copyright (c) 2026 DeepSeek
7
+ - [deepseek-ai/DeepSeek-V4-Pro](https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro) at revision `0e1a0e5e52aea73055f50fef6f2423db370265b6`, recorded in `packages/runtime/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/runtime/assets/deepseek-v4-vision-exp/manifest.json`. The vision model is served by this distinct tokenizer, never as an alias of the text tokenizer.
8
9
 
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:
10
+ Exact file sizes and SHA-256 values are recorded in each directory's `manifest.json`; the upstream license text ships beside the assets.
15
11
 
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
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.
18
13
 
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 also distributes `tokenizer.json` and `tokenizer_config.json` from these pinned official repositories, both under the MIT license:
28
-
29
- - `deepseek-ai/DeepSeek-V4-Pro` revision `0e1a0e5e52aea73055f50fef6f2423db370265b6` (serves `deepseek-v4-flash` and `deepseek-v4-pro`), in `assets/deepseek-v4/`.
30
- - `deepseek-ai/DeepSeek-V4-Flash-Vision-Exp` revision `6821d6ad3681a4b137b066b76094fa82ebd0a380` (serves `deepseek-v4-flash-vision-exp`), in `assets/deepseek-v4-vision-exp/`. This tokenizer is a distinct artifact, not an alias of the V4 Pro tokenizer.
31
-
32
- The exact provenance and SHA-256 values are in each directory's `manifest.json`; the upstream license text ships beside the assets. The vision image-token arithmetic is a port of the repository's `inference/image_processor.py` at the same pinned revision.
33
-
34
- This package depends on `@huggingface/tokenizers` 0.1.3 under Apache-2.0. Its NPM package carries the dependency license text.
35
-
36
- 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.
37
-
38
- This is an unofficial community package and is not endorsed by DeepSeek.
14
+ The names DeepSeek and DeepSeek Harness identify upstream projects only. They do not imply affiliation or endorsement.
@@ -0,0 +1,76 @@
1
+ # dsh-context-compression-improved をインストールする
2
+
3
+ > [English](installation.md) · [中文](installation.zh.md) · [日本語](installation.ja.md) · [한국어](installation.ko.md)
4
+
5
+ このガイドでは、ソースからフォークをインストールします。このフォークはアップストリームに対して名前が変更されており(`dsh-context-compression-selector` → `dsh-context-compression-improved`)、まだ npm に公開されていません。ソースおよびセッションログに現れる `dsh-context-compression-improved-runtime` は凍結された来歴ラベルであり、パッケージ依存ではありません。実行時の依存は `@huggingface/tokenizers` と `js-yaml` のみです。
6
+
7
+ ## 前提条件
8
+
9
+ - Node `^22.19.0 || >=24` と pnpm `11.7.0`(`corepack enable` で `packageManager` の固定バージョンが使われます)。
10
+ - `0.1.1-rc.2` peer 範囲に互換する DeepSeek Harness(公式 `dsh-v0.1.2-alpha.5` リリースに対して検証済み)。
11
+ - DeepSeek V4 モデルルート(`deepseek-v4-flash`、`deepseek-v4-pro`、`deepseek-v4-flash-vision-exp`)。コードスケルトンゲートを含む非可逆圧縮には同梱の正確なトークナイザーが必要で、その他のルートは fail-open で元のツール結果を保持します。
12
+ - Git。
13
+
14
+ ## 1. ソースからビルド
15
+
16
+ ```sh
17
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
18
+ cd dsh-context-compression-improved
19
+ pnpm install --frozen-lockfile
20
+ pnpm build
21
+ ```
22
+
23
+ `pnpm build` はすべてのパッケージの両方のライブラリ成果物をバンドルします(`tsdown`)。インストール前にフルスイートを実行したい場合は `pnpm test` を実行してください。
24
+
25
+ ## 2. Bundle エントリーパッケージを pack
26
+
27
+ selector パッケージが唯一の Bundle エントリーで、ランタイムはその正確なバージョン依存として付いてきます:
28
+
29
+ ```sh
30
+ cd packages/selector
31
+ pnpm pack
32
+ # → dsh-context-compression-improved-0.1.0.tgz
33
+ cd ../..
34
+ ```
35
+
36
+ `pnpm pack` は `prepack` フック経由でバンドルを実行するため、tarball は常にチェックアウト内容と一致します。
37
+
38
+ ## 3. Harness プロファイルに追加
39
+
40
+ selector パッケージは Harness Bundle マニフェストフィールド `dsh.bundle.patch` を宣言しているため、`dsh plugin add` が標準のアウトオブツリー Bundle インストール経路になります:
41
+
42
+ ```sh
43
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
44
+ dsh --profile web --dump-config
45
+ ```
46
+
47
+ インストール後、対象プロファイルを再起動してください。設定ダンプに selector Bundle が有効として表示されるはずです。selector と runtime の 2 パッケージを別々にインストール・接続**しないでください**——runtime は自動的にインストールされます。
48
+
49
+ ## 4. コードスケルトンゲートを有効にする
50
+
51
+ DeepSeek Harness の設定 → **Context compression selector** を開きます:
52
+
53
+ 1. 圧縮プロファイルを選択します(ゲートはすべてのプロファイルに対して直交します)。
54
+ 2. 必要に応じて Auto Compact トリガーレベルを調整します(50–90%、デフォルト 80%)。
55
+ 3. **Code skeleton compression** を **On** にします。トグルは変更時に保存されます。
56
+
57
+ 他のセレクター設定と同様、値はセッションが最初に観測した時点で凍結されます——ゲートは新しく観測されたセッションにのみ影響し、実行中のタスクには適用されません。
58
+
59
+ ## 5. 更新と削除
60
+
61
+ ```sh
62
+ # 更新:pull、再ビルド、再 pack、新しい tarball を再追加
63
+ git pull && pnpm install --frozen-lockfile && pnpm build
64
+ cd packages/selector && pnpm pack && cd ../..
65
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
66
+
67
+ # 削除
68
+ dsh plugin --profile web remove dsh-context-compression-improved
69
+ ```
70
+
71
+ ## トラブルシューティング
72
+
73
+ - **ダンプに Bundle が有効と表示されない**:プロファイルを再起動し、selector エントリーパッケージ(runtime ではなく)を追加したこと、Harness のバージョンが互換 peer 範囲内であることを確認してください。
74
+ - **ツール結果が一切スケルトン圧縮されない**:ゲートはデフォルトでオフです。トグルを確認してください。圧縮は、正確なトークナイザーのモデルルート上の、新規かつ超大規模なソースコード系ツール結果にのみ適用され、すべてのスキップは理由付きで監査記録に残ります。
75
+ - **トグルが読み取り不能と表示される**:保存済みの `codeSkeleton` セクションが厳格なブラウザーデコードに失敗しています(正確に `{ enabled: boolean }` である必要があります)。不正なセクションを削除すればデフォルトに戻ります。
76
+ - **更新手順が失敗する**:プラグインは npm パッケージのセマンティクスに従います。お使いの Harness ビルドが tarball 間のアップグレードを拒否する場合は、まず古いバージョンを削除してください。
@@ -0,0 +1,76 @@
1
+ # dsh-context-compression-improved 설치하기
2
+
3
+ > [English](installation.md) · [中文](installation.zh.md) · [日本語](installation.ja.md) · [한국어](installation.ko.md)
4
+
5
+ 이 가이드는 포크를 소스에서 설치하는 방법을 다룹니다. 이 포크는 업스트림에 대해 이름이 변경되었으며(`dsh-context-compression-selector` → `dsh-context-compression-improved`), 아직 npm에 게시되지 않았습니다. 소스와 세션 로그에 나타나는 `dsh-context-compression-improved-runtime`은 동결된 프로버넌스 라벨이며 패키지 의존성이 아닙니다. 런타임 의존성은 `@huggingface/tokenizers`와 `js-yaml`뿐입니다.
6
+
7
+ ## 사전 요구 사항
8
+
9
+ - Node `^22.19.0 || >=24` 및 pnpm `11.7.0`(`corepack enable`은 `packageManager`의 고정 버전을 사용합니다).
10
+ - `0.1.1-rc.2` peer 범위와 호환되는 DeepSeek Harness(공식 `dsh-v0.1.2-alpha.5` 릴리스에서 검증).
11
+ - DeepSeek V4 모델 경로(`deepseek-v4-flash`, `deepseek-v4-pro`, `deepseek-v4-flash-vision-exp`). 코드 스켈레톤 게이트를 포함한 손실 압축은 번들된 정확한 토크나이저가 필요하며, 그 외의 경로는 fail-open으로 원본 도구 결과를 유지합니다.
12
+ - Git.
13
+
14
+ ## 1. 소스에서 빌드
15
+
16
+ ```sh
17
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
18
+ cd dsh-context-compression-improved
19
+ pnpm install --frozen-lockfile
20
+ pnpm build
21
+ ```
22
+
23
+ `pnpm build`는 모든 패키지의 두 라이브러리 산출물을 번들합니다(`tsdown`). 설치 전에 전체 테스트 스위트를 실행하려면 `pnpm test`를 먼저 실행하세요.
24
+
25
+ ## 2. Bundle 엔트리 패키지를 pack
26
+
27
+ 셀렉터 패키지가 유일한 Bundle 엔트리이며, 런타임은 정확한 버전 의존성으로 함께 따라옵니다:
28
+
29
+ ```sh
30
+ cd packages/selector
31
+ pnpm pack
32
+ # → dsh-context-compression-improved-0.1.0.tgz
33
+ cd ../..
34
+ ```
35
+
36
+ `pnpm pack`은 `prepack` 훅을 통해 번들을 실행하므로, tarball은 항상 체크아웃 내용과 일치합니다.
37
+
38
+ ## 3. Harness 프로파일에 추가
39
+
40
+ 셀렉터 패키지는 Harness Bundle 매니페스트 필드 `dsh.bundle.patch`를 선언하므로, `dsh plugin add`가 표준적인 out-of-tree Bundle 설치 경로입니다:
41
+
42
+ ```sh
43
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
44
+ dsh --profile web --dump-config
45
+ ```
46
+
47
+ 설치 후 해당 프로파일을 재시작하세요. 설정 덤프에 셀렉터 Bundle이 활성 상태로 표시되어야 합니다. 셀렉터와 런타임 패키지를 따로 설치하거나 연결하지 **마세요** — 런타임은 자동으로 설치됩니다.
48
+
49
+ ## 4. 코드 스켈레톤 게이트 켜기
50
+
51
+ DeepSeek Harness 설정 → **Context compression selector**를 엽니다:
52
+
53
+ 1. 압축 프로파일을 선택합니다(게이트는 모든 프로파일에 대해 직교합니다).
54
+ 2. 필요하면 Auto Compact 트리거 레벨을 조정합니다(50–90%, 기본값 80%).
55
+ 3. **Code skeleton compression**을 **On**으로 설정합니다. 토글은 변경 시 저장됩니다.
56
+
57
+ 다른 셀렉터 설정과 마찬가지로 값은 세션이 처음 관찰하는 시점에 고정됩니다 — 게이트는 새로 관찰된 세션에만 적용되며, 실행 중인 작업에는 적용되지 않습니다.
58
+
59
+ ## 5. 업데이트 및 제거
60
+
61
+ ```sh
62
+ # 업데이트: pull, 재빌드, 재 pack, 새 tarball을 다시 추가
63
+ git pull && pnpm install --frozen-lockfile && pnpm build
64
+ cd packages/selector && pnpm pack && cd ../..
65
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
66
+
67
+ # 제거
68
+ dsh plugin --profile web remove dsh-context-compression-improved
69
+ ```
70
+
71
+ ## 문제 해결
72
+
73
+ - **덤프에 Bundle이 활성으로 표시되지 않음**: 프로파일을 재시작하고, 셀렉터 엔트리 패키지(런타임이 아닌)를 추가했는지, Harness 버전이 호환 peer 범위 내인지 확인하세요.
74
+ - **도구 결과가 한 번도 스켈레톤 압축되지 않음**: 게이트는 기본값이 off입니다. 토글을 확인하세요. 압축은 정확한 토크나이저 모델 경로에서 새로 들어온 초대형 소스코드 도구 결과에만 적용되며, 모든 건너뜀은 사유와 함께 감사 기록에 남습니다.
75
+ - **토글이 읽을 수 없음으로 표시됨**: 저장된 `codeSkeleton` 섹션이 엄격한 브라우저 디코드에 실패했습니다(정확히 `{ enabled: boolean }`이어야 함). 잘못된 섹션을 제거하면 기본값으로 돌아갑니다.
76
+ - **업데이트 단계 실패**: 플러그인은 npm 패키지 의미론을 따릅니다. 사용 중인 Harness 빌드가 tarball 간 업그레이드를 거부하면 먼저 이전 버전을 제거하세요.
@@ -0,0 +1,76 @@
1
+ # Installing dsh-context-compression-improved
2
+
3
+ > [English](installation.md) · [中文](installation.zh.md) · [日本語](installation.ja.md) · [한국어](installation.ko.md)
4
+
5
+ This guide installs the fork from source. The fork is renamed relative to upstream (`dsh-context-compression-selector` → `dsh-context-compression-improved`) and is not yet published to npm. The literal `dsh-context-compression-improved-runtime` that appears in the source and in durable session logs is a frozen provenance label, not a package dependency — the runtime dependencies are `@huggingface/tokenizers` and `js-yaml`.
6
+
7
+ ## Prerequisites
8
+
9
+ - Node `^22.19.0 || >=24` and pnpm `11.7.0` (`corepack enable` picks the pinned version from `packageManager`).
10
+ - A DeepSeek Harness installation compatible with the `0.1.1-rc.2` peer range (verified against the official `dsh-v0.1.2-alpha.5` release).
11
+ - A DeepSeek V4 model route (`deepseek-v4-flash`, `deepseek-v4-pro`, or `deepseek-v4-flash-vision-exp`). Lossy compression — including the code-skeleton gate — requires the exact bundled tokenizer; other routes fail open and keep original tool results.
12
+ - Git.
13
+
14
+ ## 1. Build from source
15
+
16
+ ```sh
17
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
18
+ cd dsh-context-compression-improved
19
+ pnpm install --frozen-lockfile
20
+ pnpm build
21
+ ```
22
+
23
+ `pnpm build` bundles both library faces of every package (`tsdown`). Run `pnpm test` first if you want the full suite on your machine before installing.
24
+
25
+ ## 2. Pack the Bundle entry package
26
+
27
+ The selector package is the single Bundle entry; the runtime comes along as its exact-version dependency:
28
+
29
+ ```sh
30
+ cd packages/selector
31
+ pnpm pack
32
+ # → dsh-context-compression-improved-0.1.0.tgz
33
+ cd ../..
34
+ ```
35
+
36
+ `pnpm pack` runs the bundle through the `prepack` hook, so the tarball always matches your checkout.
37
+
38
+ ## 3. Add it to a Harness profile
39
+
40
+ The selector package declares the Harness Bundle manifest field `dsh.bundle.patch`, so `dsh plugin add` is the standard out-of-tree Bundle installation path:
41
+
42
+ ```sh
43
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
44
+ dsh --profile web --dump-config
45
+ ```
46
+
47
+ Restart the selected profile after installation. The config dump should list the selector Bundle as active. Do **not** install or wire the selector and runtime packages separately — the runtime is installed automatically.
48
+
49
+ ## 4. Turn on the code-skeleton gate
50
+
51
+ Open DeepSeek Harness settings → **Context compression selector**:
52
+
53
+ 1. Pick a compression profile (the gate is orthogonal to all of them).
54
+ 2. Optionally adjust the Auto Compact trigger level (50–90%, default 80%).
55
+ 3. Set **Code skeleton compression** to **On**. The toggle saves on change.
56
+
57
+ Like all selector settings, the value is frozen when a session first observes it — the gate affects newly observed sessions, never a task that is already running.
58
+
59
+ ## 5. Update or remove
60
+
61
+ ```sh
62
+ # update: pull, rebuild, repack, and add the new tarball again
63
+ git pull && pnpm install --frozen-lockfile && pnpm build
64
+ cd packages/selector && pnpm pack && cd ../..
65
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
66
+
67
+ # remove
68
+ dsh plugin --profile web remove dsh-context-compression-improved
69
+ ```
70
+
71
+ ## Troubleshooting
72
+
73
+ - **Bundle not active in the dump**: restart the profile; confirm you added the selector entry package (not the runtime) and that the Harness version is in the compatible peer range.
74
+ - **Tool results are never skeleton-compressed**: the gate is off by default; check the toggle. Compression only applies to fresh, oversized source-code tool results on exact-tokenizer model routes, and every skip is recorded with a reason in the audit trail.
75
+ - **The toggle shows as unreadable**: the stored `codeSkeleton` section failed the strict browser decode (it must be exactly `{ enabled: boolean }`). Removing the malformed section restores defaults.
76
+ - **Updating fails on the upgrade step**: the plugin follows npm package semantics; remove the old version first if a tarball-to-tarball upgrade is refused by your Harness build.
@@ -0,0 +1,76 @@
1
+ # 安装 dsh-context-compression-improved
2
+
3
+ > [English](installation.md) · [中文](installation.zh.md) · [日本語](installation.ja.md) · [한국어](installation.ko.md)
4
+
5
+ 本教程从源码安装本 fork。本 fork 相对上游已重命名(`dsh-context-compression-selector` → `dsh-context-compression-improved`),且尚未发布 npm 包。源码与会话日志中出现的 `dsh-context-compression-improved-runtime` 是冻结的溯源标识,并非包依赖——运行时依赖只有 `@huggingface/tokenizers` 和 `js-yaml`。
6
+
7
+ ## 前置条件
8
+
9
+ - Node `^22.19.0 || >=24` 与 pnpm `11.7.0`(`corepack enable` 会按 `packageManager` 字段使用固定版本)。
10
+ - 兼容 `0.1.1-rc.2` peer 范围的 DeepSeek Harness(已针对官方 `dsh-v0.1.2-alpha.5` 验证)。
11
+ - DeepSeek V4 模型路由(`deepseek-v4-flash`、`deepseek-v4-pro` 或 `deepseek-v4-flash-vision-exp`)。有损压缩——包括代码骨架门——依赖内置的精确 tokenizer;其他路由 fail-open 并保留原始工具结果。
12
+ - Git。
13
+
14
+ ## 1. 从源码构建
15
+
16
+ ```sh
17
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
18
+ cd dsh-context-compression-improved
19
+ pnpm install --frozen-lockfile
20
+ pnpm build
21
+ ```
22
+
23
+ `pnpm build` 会打包所有包的两套产物(`tsdown`)。如需在安装前先跑全量测试,可执行 `pnpm test`。
24
+
25
+ ## 2. 打包 Bundle 入口包
26
+
27
+ selector 包是唯一的 Bundle 入口;runtime 作为其精确版本依赖自动随行:
28
+
29
+ ```sh
30
+ cd packages/selector
31
+ pnpm pack
32
+ # → dsh-context-compression-improved-0.1.0.tgz
33
+ cd ../..
34
+ ```
35
+
36
+ `pnpm pack` 会通过 `prepack` 钩子执行打包,因此 tarball 始终与你的检出内容一致。
37
+
38
+ ## 3. 安装到 Harness Profile
39
+
40
+ selector 包声明了 Harness Bundle manifest 字段 `dsh.bundle.patch`,因此 `dsh plugin add` 是标准的树外 Bundle 安装方式:
41
+
42
+ ```sh
43
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
44
+ dsh --profile web --dump-config
45
+ ```
46
+
47
+ 安装后重启对应 Profile。配置导出中应显示 selector Bundle 已激活。**不要**分别安装或手动连接 selector 与 runtime 两个包——runtime 会自动安装。
48
+
49
+ ## 4. 打开代码骨架门
50
+
51
+ 打开 DeepSeek Harness 设置 → **上下文压缩选择器**:
52
+
53
+ 1. 选择一个压缩 Profile(这道门与所有 Profile 正交)。
54
+ 2. 按需调整 Auto Compact 触发水位(50–90%,默认 80%)。
55
+ 3. 将**代码骨架压缩**设为**开**。开关即改即存。
56
+
57
+ 与所有选择器设置一致,取值在会话首次观察时冻结——这道门只影响新观察的会话,不会改变正在运行的任务。
58
+
59
+ ## 5. 更新或卸载
60
+
61
+ ```sh
62
+ # 更新:拉取、重建、重新打包、再次添加新 tarball
63
+ git pull && pnpm install --frozen-lockfile && pnpm build
64
+ cd packages/selector && pnpm pack && cd ../..
65
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
66
+
67
+ # 卸载
68
+ dsh plugin --profile web remove dsh-context-compression-improved
69
+ ```
70
+
71
+ ## 故障排除
72
+
73
+ - **配置导出中 Bundle 未激活**:重启 Profile;确认添加的是 selector 入口包(而非 runtime),且 Harness 版本在兼容的 peer 范围内。
74
+ - **工具结果从未被骨架化压缩**:该门默认关闭,请检查开关。压缩只作用于精确 tokenizer 路由上新鲜、超大、源码类的工具结果,且每次跳过都会在审计记录中留有原因。
75
+ - **开关显示为不可读**:已存的 `codeSkeleton` 段未通过严格的浏览器解码(必须恰好是 `{ enabled: boolean }`)。删除畸形段即可恢复默认。
76
+ - **升级步骤失败**:插件遵循 npm 包语义;如果你的 Harness 构建拒绝 tarball 到 tarball 的升级,请先移除旧版本再安装。