dsh-context-compression-improved 0.7.0-beta.1 → 0.7.0

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 (83) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -220
  3. package/CHANGELOG.ko.md +211 -214
  4. package/CHANGELOG.md +401 -376
  5. package/CHANGELOG.zh.md +196 -199
  6. package/README.md +97 -97
  7. package/README.zh.md +86 -86
  8. package/package.json +1 -1
  9. package/packages/selector/dsh.plugin.json +1 -1
  10. package/packages/selector/lib/client.d.ts +44 -0
  11. package/packages/selector/lib/client.js +1733 -6
  12. package/packages/selector/lib/{intent-gate.js → config.js} +799 -136
  13. package/packages/selector/lib/index.d.ts +13 -1
  14. package/packages/selector/lib/index.js +204 -3
  15. package/packages/selector/lib/profiles.d.ts +6 -0
  16. package/packages/selector/lib/pruner.d.ts +6 -0
  17. package/packages/selector/lib/pruner.js +90 -258
  18. package/packages/selector/lib/style.css +88 -46
  19. package/packages/selector/src/client/CompressionProfileControls.tsx +293 -226
  20. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
  21. package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -83
  22. package/packages/selector/src/client/decode.ts +57 -53
  23. package/packages/selector/src/client/index.ts +307 -213
  24. package/packages/selector/src/client/locales/de.ts +141 -0
  25. package/packages/selector/src/client/locales/es.ts +141 -0
  26. package/packages/selector/src/client/locales/fr.ts +141 -0
  27. package/packages/selector/src/client/locales/it.ts +141 -0
  28. package/packages/selector/src/client/locales/ja.ts +141 -0
  29. package/packages/selector/src/client/locales/ko.ts +141 -0
  30. package/packages/selector/src/client/locales/ru.ts +141 -0
  31. package/packages/selector/src/client/locales.ts +282 -196
  32. package/packages/selector/src/client/monitor-fab.ts +336 -0
  33. package/packages/selector/src/client/savings-card.tsx +150 -0
  34. package/packages/selector/src/client/settings-section.tsx +140 -124
  35. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  36. package/packages/selector/src/index.ts +207 -5
  37. package/packages/selector/src/preset-overlay.ts +629 -629
  38. package/packages/selector/src/profiles.ts +431 -414
  39. package/packages/selector/src/pruner/content.ts +198 -198
  40. package/packages/selector/src/pruner/state.ts +57 -57
  41. package/packages/selector/src/pruner.ts +2759 -2665
  42. package/packages/selector/src/runtime/audit.ts +303 -303
  43. package/packages/selector/src/runtime/config.ts +756 -731
  44. package/packages/selector/src/runtime/monitor.ts +235 -0
  45. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  46. package/packages/selector/src/runtime/retrieve.ts +479 -457
  47. package/packages/selector/src/runtime/savings.ts +337 -0
  48. package/packages/selector/src/runtime/summary-command.ts +133 -133
  49. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -233
  50. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -204
  51. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -53
  52. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -65
  53. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -125
  54. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -37
  55. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  56. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -306
  57. package/packages/selector/src/runtime/types.ts +365 -358
  58. package/packages/selector/tests/built/client-artifact.spec.ts +61 -61
  59. package/packages/selector/tests/code-skeleton.client.spec.ts +2 -2
  60. package/packages/selector/tests/custom-contract.client.spec.ts +2 -2
  61. package/packages/selector/tests/estimator-channel.client.spec.tsx +2 -0
  62. package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
  63. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  64. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  65. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  66. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  67. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  68. package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
  69. package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
  70. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  71. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  72. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -62
  73. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -156
  74. package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
  75. package/packages/selector/tests/runtime/savings.spec.ts +120 -0
  76. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -154
  77. package/packages/selector/tests/settings-seat.client.spec.ts +177 -165
  78. package/scripts/packed-components-smoke.mjs +734 -734
  79. package/scripts/packed-install-e2e.mjs +1 -1
  80. package/scripts/verify-release.mjs +1 -1
  81. package/tests/TEST_INVENTORY.md +41 -41
  82. package/tsconfig.tests.json +17 -17
  83. package/vitest.config.ts +57 -57
package/README.md CHANGED
@@ -1,97 +1,97 @@
1
- # dsh-context-compression-improved
2
-
3
- > An improved fork of [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) — an auditable tool-result context-compression selector for DeepSeek Harness — adding an orthogonal **code-skeleton compression gate**.
4
-
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
- > - A **turn-tail intent summary** (`intentSummary.enabled`, default off): when the growth gate passes (>45% of the window, >50K tokens grown since the last fold), consumed-increment tool results are masked to semantic-role records (read-class → one-line target/scale records; write-class keep skeleton + verbatim error lines), one LLM writer call produces the summary segment, and the fold lands on the next pressure round as per-candidate blocks with seq provenance. Fold-once, fail-open, with retention-ratio and call-cost audits. Session-scoped `/ctx-summary off|on|status` pauses/resumes it without touching settings.
11
- > - 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.
12
- > - A settings toggle for that gate in the same selector settings section, independent of every compression profile.
13
- > - An ESLint baseline wired into CI, a `test:watch` TDD loop, and documentation in English, Simplified Chinese, Japanese, and Korean.
14
-
15
- > [!IMPORTANT]
16
- > 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.
17
-
18
- ## What it is
19
-
20
- 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:
21
-
22
- - **Fresh** pre-compresses a newly oversized tool-result segment before the model receives it.
23
- - **Aggregate** pre-compresses fresh material again when it still grows beyond its budget.
24
- - **History / micro-compact** replaces eligible old tool results while preserving recent working context.
25
- - **TailTrim** is an optional Custom-only tail reduction path.
26
- - **Native** preserves the Harness-style head/middle/tail trimming as one explicit profile.
27
- - **Code skeleton (new, orthogonal gate)** — see below.
28
-
29
- Every decision is recorded: stage, reducer, trigger, skip reason, and exact token counts where available.
30
-
31
- ## Code skeleton gate (new)
32
-
33
- 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.
34
-
35
- Properties:
36
-
37
- - **Orthogonal**: independent of the selected profile (`balanced`, `savings`, `cache-strict`, `adaptive`, `custom`, `off`, `native`). All profiles get the gate.
38
- - **Off by default**: `codeSkeleton: { enabled: false }` until you turn it on.
39
- - **Measurement-gated**: requires the exact DeepSeek tokenizer; without it the plugin fails open.
40
- - **Session-frozen**: like all selector settings, changes affect newly observed sessions only.
41
- - **Strictly parsed**: `codeSkeleton` must be exactly `{ enabled: boolean }`; malformed values throw on the runtime side and show as unreadable in the browser UI.
42
-
43
- ## Settings UI
44
-
45
- 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.
46
-
47
- ![Context Compression Selector settings UI](docs/assets/context-compression-selector-settings.png)
48
-
49
- ## Install
50
-
51
- **Recommended: install from npm.** One dist-tag per Harness line — `dsh-0.1.7` for the 0.1.7 line (this branch), `dsh-0.1.5` for the 0.1.5 line, `dsh-0.1.2` for the 0.1.2 line.
52
-
53
- ```sh
54
- dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.7
55
- # DSH 0.1.5 line:
56
- # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
57
- # DSH 0.1.2 line:
58
- # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
59
- dsh --profile web --dump-config
60
- ```
61
-
62
- From source (alternative — the internal package names intentionally stay upstream's):
63
-
64
- ```sh
65
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
66
- cd dsh-context-compression-improved
67
- pnpm install --frozen-lockfile
68
- pnpm build
69
- ```
70
-
71
- 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).
72
-
73
- ## Development
74
-
75
- ```sh
76
- pnpm install --frozen-lockfile
77
- pnpm lint # ESLint baseline (also enforced in CI)
78
- pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
79
- pnpm test # full vitest suite
80
- pnpm test:watch # TDD loop: write the failing regression first, then make it pass
81
- pnpm build
82
- pnpm verify:release
83
- ```
84
-
85
- 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).
86
-
87
- ## Compatibility
88
-
89
- - Built and tested against the official DeepSeek Harness `dsh-v0.1.7-rc.2` release; peers declare `>=0.1.7-rc.1 <0.2.0-0` and the plugin uses public plugin and profile APIs only. Earlier lines remain served from their own dist-tags (`dsh-0.1.5`, `dsh-0.1.2`).
90
- - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
91
- - 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.
92
-
93
- ## Credits and license
94
-
95
- - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
96
- - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
97
- - MIT — see [LICENSE](LICENSE) (upstream copyright notice retained) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for bundled tokenizer provenance.
1
+ # dsh-context-compression-improved
2
+
3
+ > An improved fork of [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) — an auditable tool-result context-compression selector for DeepSeek Harness — adding an orthogonal **code-skeleton compression gate**.
4
+
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
+ > - A **turn-tail intent summary** (`intentSummary.enabled`, default off): when the growth gate passes (>45% of the window, >50K tokens grown since the last fold), consumed-increment tool results are masked to semantic-role records (read-class → one-line target/scale records; write-class keep skeleton + verbatim error lines), one LLM writer call produces the summary segment, and the fold lands on the next pressure round as per-candidate blocks with seq provenance. Fold-once, fail-open, with retention-ratio and call-cost audits. Session-scoped `/ctx-summary off|on|status` pauses/resumes it without touching settings.
11
+ > - 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.
12
+ > - A settings toggle for that gate in the same selector settings section, independent of every compression profile.
13
+ > - An ESLint baseline wired into CI, a `test:watch` TDD loop, and documentation in English, Simplified Chinese, Japanese, and Korean.
14
+
15
+ > [!IMPORTANT]
16
+ > 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.
17
+
18
+ ## What it is
19
+
20
+ 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:
21
+
22
+ - **Fresh** pre-compresses a newly oversized tool-result segment before the model receives it.
23
+ - **Aggregate** pre-compresses fresh material again when it still grows beyond its budget.
24
+ - **History / micro-compact** replaces eligible old tool results while preserving recent working context.
25
+ - **TailTrim** is an optional Custom-only tail reduction path.
26
+ - **Native** preserves the Harness-style head/middle/tail trimming as one explicit profile.
27
+ - **Code skeleton (new, orthogonal gate)** — see below.
28
+
29
+ Every decision is recorded: stage, reducer, trigger, skip reason, and exact token counts where available.
30
+
31
+ ## Code skeleton gate (new)
32
+
33
+ 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.
34
+
35
+ Properties:
36
+
37
+ - **Orthogonal**: independent of the selected profile (`balanced`, `savings`, `cache-strict`, `adaptive`, `custom`, `off`, `native`). All profiles get the gate.
38
+ - **Off by default**: `codeSkeleton: { enabled: false }` until you turn it on.
39
+ - **Measurement-gated**: requires the exact DeepSeek tokenizer; without it the plugin fails open.
40
+ - **Session-frozen**: like all selector settings, changes affect newly observed sessions only.
41
+ - **Strictly parsed**: `codeSkeleton` must be exactly `{ enabled: boolean }`; malformed values throw on the runtime side and show as unreadable in the browser UI.
42
+
43
+ ## Settings UI
44
+
45
+ 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.
46
+
47
+ ![Context Compression Selector settings UI](docs/assets/context-compression-selector-settings.png)
48
+
49
+ ## Install
50
+
51
+ **Recommended: install from npm.** One dist-tag per Harness line — `dsh-0.1.7` for the 0.1.7 line (this branch), `dsh-0.1.5` for the 0.1.5 line, `dsh-0.1.2` for the 0.1.2 line.
52
+
53
+ ```sh
54
+ dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.7
55
+ # DSH 0.1.5 line:
56
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
57
+ # DSH 0.1.2 line:
58
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
59
+ dsh --profile web --dump-config
60
+ ```
61
+
62
+ From source (alternative — the internal package names intentionally stay upstream's):
63
+
64
+ ```sh
65
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
66
+ cd dsh-context-compression-improved
67
+ pnpm install --frozen-lockfile
68
+ pnpm build
69
+ ```
70
+
71
+ 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).
72
+
73
+ ## Development
74
+
75
+ ```sh
76
+ pnpm install --frozen-lockfile
77
+ pnpm lint # ESLint baseline (also enforced in CI)
78
+ pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
79
+ pnpm test # full vitest suite
80
+ pnpm test:watch # TDD loop: write the failing regression first, then make it pass
81
+ pnpm build
82
+ pnpm verify:release
83
+ ```
84
+
85
+ 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).
86
+
87
+ ## Compatibility
88
+
89
+ - Built and tested against the official DeepSeek Harness `dsh-v0.1.7-rc.2` release; peers declare `>=0.1.7-rc.1 <0.2.0-0` and the plugin uses public plugin and profile APIs only. Earlier lines remain served from their own dist-tags (`dsh-0.1.5`, `dsh-0.1.2`).
90
+ - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
91
+ - 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.
92
+
93
+ ## Credits and license
94
+
95
+ - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
96
+ - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
97
+ - 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,86 +1,86 @@
1
- # dsh-context-compression-improved
2
-
3
- > [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) 的改进版 fork——面向 DeepSeek Harness 的可审计工具结果上下文压缩选择器,新增正交的**代码骨架压缩门*。
4
-
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
- > - **回合末意图摘要**(`intentSummary.enabled`,默认关闭):增长门控通过(>窗口 45% 且距上次折叠增长 >50K token)后,把"已消费增量"按语义角色 mask——读类工具结果压成单行目标/规模记录,写类保留骨架与逐字错误行——一次 LLM 写手调用产出摘要段,下一压力回合落地为带 seq 溯源的逐候选块。fold-once、fail-open,审计含保持率与调用成本。会话内 `/ctx-summary off|on|status` 可临时暂停/恢复,不动设置。
11
- > - 正交的**代码骨架压缩门**(`codeSkeleton.enabled`,默认关闭):超大源码类工具结果首次曝光时,可先保留导入与声明的骨架——省略函数体并保留错误行——再进入常规 reducer。
12
- > - 同一选择器设置区内新增该门的开关,独立于所有压缩 Profile。
13
- > - 接入 CI 的 ESLint 基线、`test:watch` TDD 环路,以及英/中日韩四语文档。
14
-
15
- > [!IMPORTANT]
16
- > 本项目仅支持 **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)。
17
-
18
- ## 它是什么
19
-
20
- 长时运行的 agent 任务会积累大量工具输出。本社区插件在不修改 DeepSeek Harness 核心的前提下,提供可选、可审计的工具结果上下文压缩策略:
21
-
22
- - **Fresh**:在模型收到之前,预压缩新近超限的工具结果段。
23
- - **Aggregate**:当 Fresh 压缩后仍超出预算时再次预压缩。
24
- - **History / micro-compact**:在保护近期工作上下文的前提下替换符合条件的旧工具结果。
25
- - **TailTrim**:仅在 Custom 下可选的尾窗收缩路径。
26
- - **Native**:把 Harness 原生头中尾裁剪保留为一个显式 Profile。
27
- - **代码骨架(新增,正交门)**——见下节。
28
-
29
- 每个决策都会留痕:阶段、reducer、触发原因、跳过原因,以及可得时的精确 token 数。
30
-
31
- ## 代码骨架门(新增)
32
-
33
- 开启后,超大**源码类新工具结果**(例如大型 `read_file`)会先尝试骨架化压缩:保留导入与类型/函数/类声明,省略函数体并加占位标记,被省略函数体内的错误行予以保留。若骨架无法生成或无法通过验证,则回退到原有的头部裁剪——这道门不会让上下文变得更差。
34
-
35
- 特性:
36
-
37
- - **正交**:独立于所选 Profile(`balanced`、`savings`、`cache-strict`、`adaptive`、`custom`、`off`、`native`),所有 Profile 都能拿到这道门。
38
- - **默认关闭**:`codeSkeleton: { enabled: false }`,需要显式开启。
39
- - **测量前置**:需要精确 DeepSeek tokenizer;不可用时 fail-open。
40
- - **会话冻结**:与所有选择器设置一致,修改只影响新观察的会话。
41
- - **严格解析**:`codeSkeleton` 必须恰好是 `{ enabled: boolean }`;畸形输入在运行时侧抛错、浏览器侧显示不可读。
42
-
43
- ## 设置界面
44
-
45
- 在同一设置区内选择压缩 Profile、调整 Auto Compact 触发水位,并开关代码骨架压缩。开关即改即存,刷新后显示已保存状态。
46
-
47
- ![Context Compression Selector 设置界面](docs/assets/context-compression-selector-settings.png)
48
-
49
- ## 安装
50
-
51
- 从源码构建并安装 —— 本 fork 亦已发布到 npm,包名为 `dsh-context-compression-improved`(0.1.7 线使用 dist-tag `dsh-0.1.7`,0.1.5 线使用 `dsh-0.1.5`);内部包名有意保持与上游一致:
52
-
53
- ```sh
54
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
55
- cd dsh-context-compression-improved
56
- pnpm install --frozen-lockfile
57
- pnpm build
58
- ```
59
-
60
- 随后打包 selector 包并安装到某个 Harness Profile——完整步骤(含验证与卸载)见[安装教程](docs/installation.zh.md)。
61
-
62
- ## 开发
63
-
64
- ```sh
65
- pnpm install --frozen-lockfile
66
- pnpm lint # ESLint 基线(CI 同步强制)
67
- pnpm typecheck # runtime + selector + tests tsc,含 bundle 步
68
- pnpm test # vitest 全量
69
- pnpm test:watch # TDD 环路:先写失败的回归用例,再让它通过
70
- pnpm build
71
- pnpm verify:release
72
- ```
73
-
74
- 贡献遵循上游纪律:先写失败的回归用例;所有生产改动收敛在本仓库内;对“已触发”“已启用但跳过”“fail-open”分别给出证据。见 [CONTRIBUTING.md](CONTRIBUTING.md)。
75
-
76
- ## 兼容性
77
-
78
- - 基于官方 DeepSeek Harness `dsh-v0.1.7-rc.2` 发布版构建并测试;peers 声明 `>=0.1.7-rc.1 <0.2.0-0`,仅使用公开的插件与 Profile API。更早的 Harness 线由各自的 dist-tag(`dsh-0.1.5`、`dsh-0.1.2`)继续服务。
79
- - 需要 Node `^22.19.0 || >=24` 与 pnpm `11.7.0`。
80
- - 插件只使用 Harness 公开扩展 API,不修改 Harness 核心代码。非官方社区项目,与 DeepSeek 无隶属或背书关系。
81
-
82
- ## 致谢与许可
83
-
84
- - 上游项目与全部既有工作:[WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector),作者 WilliamShi666(MIT)。
85
- - fork 新增内容(代码骨架门、工具链、多语文档):drscrewdriver。
86
- - MIT——见 [LICENSE](LICENSE)(保留上游版权声明);内置 tokenizer 来源见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
1
+ # dsh-context-compression-improved
2
+
3
+ > [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) 的改进版 fork——面向 DeepSeek Harness 的可审计工具结果上下文压缩选择器,新增正交的**代码骨架压缩门*。
4
+
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
+ > - **回合末意图摘要**(`intentSummary.enabled`,默认关闭):增长门控通过(>窗口 45% 且距上次折叠增长 >50K token)后,把"已消费增量"按语义角色 mask——读类工具结果压成单行目标/规模记录,写类保留骨架与逐字错误行——一次 LLM 写手调用产出摘要段,下一压力回合落地为带 seq 溯源的逐候选块。fold-once、fail-open,审计含保持率与调用成本。会话内 `/ctx-summary off|on|status` 可临时暂停/恢复,不动设置。
11
+ > - 正交的**代码骨架压缩门**(`codeSkeleton.enabled`,默认关闭):超大源码类工具结果首次曝光时,可先保留导入与声明的骨架——省略函数体并保留错误行——再进入常规 reducer。
12
+ > - 同一选择器设置区内新增该门的开关,独立于所有压缩 Profile。
13
+ > - 接入 CI 的 ESLint 基线、`test:watch` TDD 环路,以及英/中日韩四语文档。
14
+
15
+ > [!IMPORTANT]
16
+ > 本项目仅支持 **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)。
17
+
18
+ ## 它是什么
19
+
20
+ 长时运行的 agent 任务会积累大量工具输出。本社区插件在不修改 DeepSeek Harness 核心的前提下,提供可选、可审计的工具结果上下文压缩策略:
21
+
22
+ - **Fresh**:在模型收到之前,预压缩新近超限的工具结果段。
23
+ - **Aggregate**:当 Fresh 压缩后仍超出预算时再次预压缩。
24
+ - **History / micro-compact**:在保护近期工作上下文的前提下替换符合条件的旧工具结果。
25
+ - **TailTrim**:仅在 Custom 下可选的尾窗收缩路径。
26
+ - **Native**:把 Harness 原生头中尾裁剪保留为一个显式 Profile。
27
+ - **代码骨架(新增,正交门)**——见下节。
28
+
29
+ 每个决策都会留痕:阶段、reducer、触发原因、跳过原因,以及可得时的精确 token 数。
30
+
31
+ ## 代码骨架门(新增)
32
+
33
+ 开启后,超大**源码类新工具结果**(例如大型 `read_file`)会先尝试骨架化压缩:保留导入与类型/函数/类声明,省略函数体并加占位标记,被省略函数体内的错误行予以保留。若骨架无法生成或无法通过验证,则回退到原有的头部裁剪——这道门不会让上下文变得更差。
34
+
35
+ 特性:
36
+
37
+ - **正交**:独立于所选 Profile(`balanced`、`savings`、`cache-strict`、`adaptive`、`custom`、`off`、`native`),所有 Profile 都能拿到这道门。
38
+ - **默认关闭**:`codeSkeleton: { enabled: false }`,需要显式开启。
39
+ - **测量前置**:需要精确 DeepSeek tokenizer;不可用时 fail-open。
40
+ - **会话冻结**:与所有选择器设置一致,修改只影响新观察的会话。
41
+ - **严格解析**:`codeSkeleton` 必须恰好是 `{ enabled: boolean }`;畸形输入在运行时侧抛错、浏览器侧显示不可读。
42
+
43
+ ## 设置界面
44
+
45
+ 在同一设置区内选择压缩 Profile、调整 Auto Compact 触发水位,并开关代码骨架压缩。开关即改即存,刷新后显示已保存状态。
46
+
47
+ ![Context Compression Selector 设置界面](docs/assets/context-compression-selector-settings.png)
48
+
49
+ ## 安装
50
+
51
+ 从源码构建并安装 —— 本 fork 亦已发布到 npm,包名为 `dsh-context-compression-improved`(0.1.7 线使用 dist-tag `dsh-0.1.7`,0.1.5 线使用 `dsh-0.1.5`);内部包名有意保持与上游一致:
52
+
53
+ ```sh
54
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
55
+ cd dsh-context-compression-improved
56
+ pnpm install --frozen-lockfile
57
+ pnpm build
58
+ ```
59
+
60
+ 随后打包 selector 包并安装到某个 Harness Profile——完整步骤(含验证与卸载)见[安装教程](docs/installation.zh.md)。
61
+
62
+ ## 开发
63
+
64
+ ```sh
65
+ pnpm install --frozen-lockfile
66
+ pnpm lint # ESLint 基线(CI 同步强制)
67
+ pnpm typecheck # runtime + selector + tests tsc,含 bundle 步
68
+ pnpm test # vitest 全量
69
+ pnpm test:watch # TDD 环路:先写失败的回归用例,再让它通过
70
+ pnpm build
71
+ pnpm verify:release
72
+ ```
73
+
74
+ 贡献遵循上游纪律:先写失败的回归用例;所有生产改动收敛在本仓库内;对“已触发”“已启用但跳过”“fail-open”分别给出证据。见 [CONTRIBUTING.md](CONTRIBUTING.md)。
75
+
76
+ ## 兼容性
77
+
78
+ - 基于官方 DeepSeek Harness `dsh-v0.1.7-rc.2` 发布版构建并测试;peers 声明 `>=0.1.7-rc.1 <0.2.0-0`,仅使用公开的插件与 Profile API。更早的 Harness 线由各自的 dist-tag(`dsh-0.1.5`、`dsh-0.1.2`)继续服务。
79
+ - 需要 Node `^22.19.0 || >=24` 与 pnpm `11.7.0`。
80
+ - 插件只使用 Harness 公开扩展 API,不修改 Harness 核心代码。非官方社区项目,与 DeepSeek 无隶属或背书关系。
81
+
82
+ ## 致谢与许可
83
+
84
+ - 上游项目与全部既有工作:[WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector),作者 WilliamShi666(MIT)。
85
+ - fork 新增内容(代码骨架门、工具链、多语文档):drscrewdriver。
86
+ - MIT——见 [LICENSE](LICENSE)(保留上游版权声明);内置 tokenizer 来源见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-context-compression-improved",
3
- "version": "0.7.0-beta.1",
3
+ "version": "0.7.0",
4
4
  "publishConfig": {
5
5
  "tag": "dsh-0.1.7"
6
6
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-context-compression-improved",
3
- "version": "0.7.0-beta.1",
3
+ "version": "0.7.0",
4
4
  "main": "./lib/index.js",
5
5
  "description": "Auditable tool-result context-compression selector with code-skeleton gate for DeepSeek Harness",
6
6
  "engines": {
@@ -71,6 +71,34 @@ declare const zh: {
71
71
  'codeSkeleton.enabled': string;
72
72
  'codeSkeleton.enabled.on': string;
73
73
  'codeSkeleton.enabled.off': string;
74
+ 'intentSummary.title': string;
75
+ 'intentSummary.description': string;
76
+ 'intentSummary.enabled': string;
77
+ 'intentSummary.enabled.on': string;
78
+ 'intentSummary.enabled.off': string;
79
+ 'monitor.fab.title': string;
80
+ 'monitor.panel.title': string;
81
+ 'monitor.panel.net': string;
82
+ 'monitor.panel.gross': string;
83
+ 'monitor.panel.offsets': string;
84
+ 'monitor.panel.context': string;
85
+ 'monitor.panel.suggest': string;
86
+ 'monitor.panel.cacheHit': string;
87
+ 'monitor.panel.cost': string;
88
+ 'monitor.panel.intent': string;
89
+ 'monitor.panel.overrideHint': string;
90
+ 'monitor.panel.resume': string;
91
+ 'monitor.panel.disable': string;
92
+ 'monitor.panel.stateOn': string;
93
+ 'monitor.panel.stateOff': string;
94
+ 'monitor.panel.gateUnknown': string;
95
+ 'monitor.panel.lastFold': string;
96
+ 'monitor.panel.stale': string;
97
+ 'monitorPanel.title': string;
98
+ 'monitorPanel.description': string;
99
+ 'monitorPanel.enabled': string;
100
+ 'monitorPanel.enabled.on': string;
101
+ 'monitorPanel.enabled.off': string;
74
102
  'custom.title': string;
75
103
  'custom.settingsHint': string;
76
104
  'custom.sessionScope': string;
@@ -102,6 +130,20 @@ declare const zh: {
102
130
  'custom.save': string;
103
131
  'custom.reset': string;
104
132
  'custom.invalid': string;
133
+ 'savings.title': string;
134
+ 'savings.netExact': string;
135
+ 'savings.netEstimated': string;
136
+ 'savings.gross': string;
137
+ 'savings.offsets': string;
138
+ 'savings.empty': string;
139
+ 'savings.basisExact': string;
140
+ 'savings.basisEstimated': string;
141
+ 'savings.basisNote': string;
142
+ 'savings.requests': string;
143
+ 'savings.cacheHit': string;
144
+ 'savings.actualCost': string;
145
+ 'savings.savedMoney': string;
146
+ 'savings.perSession': string;
105
147
  };
106
148
  /** Locale keys that every context-compression selector dictionary must provide. */
107
149
  type ContextCompressionLocaleKey = keyof typeof zh;
@@ -145,6 +187,8 @@ interface CompressionSelectorInjected {
145
187
  resetCustom: () => Promise<void>;
146
188
  saveAutoCompact: (thresholdPercent: number) => Promise<void>;
147
189
  saveCodeSkeleton: (enabled: boolean) => Promise<void>;
190
+ saveIntentSummary: (enabled: boolean) => Promise<void>;
191
+ saveMonitorPanel: (enabled: boolean) => Promise<void>;
148
192
  /** Patch of `presetOptions` members; an explicit `undefined` clears that field. */
149
193
  savePresetOptions: (options: PresetOptionsPatch) => Promise<void>;
150
194
  }