dsh-context-compression-improved 0.4.0-beta.1 → 0.5.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 (71) hide show
  1. package/CHANGELOG.ja.md +68 -36
  2. package/CHANGELOG.ko.md +67 -35
  3. package/CHANGELOG.md +195 -134
  4. package/CHANGELOG.zh.md +64 -36
  5. package/README.ja.md +1 -1
  6. package/README.ko.md +1 -1
  7. package/README.md +1 -1
  8. package/README.zh.md +1 -1
  9. package/docs/installation.ja.md +2 -2
  10. package/docs/installation.ko.md +2 -2
  11. package/docs/installation.md +103 -78
  12. package/docs/installation.zh.md +100 -77
  13. package/docs/repair-log.md +54 -0
  14. package/package.json +1 -1
  15. package/packages/selector/lib/{config.js → advisor-state.js} +329 -5
  16. package/packages/selector/lib/client.d.ts +7 -0
  17. package/packages/selector/lib/client.js +33 -3
  18. package/packages/selector/lib/index.d.ts +7 -0
  19. package/packages/selector/lib/index.js +112 -3
  20. package/packages/selector/lib/pruner.d.ts +128 -1
  21. package/packages/selector/lib/pruner.js +2802 -1374
  22. package/packages/selector/src/client/ReviewOverlay.tsx +1 -1
  23. package/packages/selector/src/client/index.ts +1 -1
  24. package/packages/selector/src/client/preset-options.ts +2 -0
  25. package/packages/selector/src/index.ts +129 -49
  26. package/packages/selector/src/profiles.ts +48 -0
  27. package/packages/selector/src/pruner/content.ts +18 -5
  28. package/packages/selector/src/pruner/state.ts +3 -0
  29. package/packages/selector/src/pruner/types.ts +23 -5
  30. package/packages/selector/src/pruner.ts +297 -162
  31. package/packages/selector/src/runtime/adaptive-cost.ts +23 -12
  32. package/packages/selector/src/runtime/audit.ts +40 -2
  33. package/packages/selector/src/runtime/config.ts +88 -1
  34. package/packages/selector/src/runtime/measurement.ts +31 -2
  35. package/packages/selector/src/runtime/reducers.ts +1115 -97
  36. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +188 -0
  37. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +133 -0
  38. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
  39. package/packages/selector/src/runtime/tokenpilot/dedup.ts +1 -1
  40. package/packages/selector/src/runtime/tokenpilot/estimator.ts +8 -118
  41. package/packages/selector/src/runtime/tokenpilot/locator.ts +1 -1
  42. package/packages/selector/src/runtime/tokenpilot/proposal.ts +76 -32
  43. package/packages/selector/src/runtime/tokenpilot/read-state.ts +23 -2
  44. package/packages/selector/src/runtime/tokenpilot/review-registry.ts +117 -0
  45. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
  46. package/packages/selector/src/runtime/toolclass.ts +103 -0
  47. package/packages/selector/src/runtime/types.ts +37 -0
  48. package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
  49. package/packages/selector/tests/public/package-contract.client.spec.ts +2 -1
  50. package/packages/selector/tests/review-routes-registry.host.spec.ts +142 -0
  51. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +7 -7
  52. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
  53. package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
  54. package/packages/selector/tests/runtime/audit.spec.ts +88 -1
  55. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
  56. package/packages/selector/tests/runtime/code-skeleton.spec.ts +14 -3
  57. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
  58. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
  59. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
  60. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
  61. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +198 -27
  62. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
  63. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
  64. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
  65. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
  66. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +12 -0
  67. package/packages/selector/tests/runtime/tokenpilot/proposal.spec.ts +194 -0
  68. package/packages/selector/tests/runtime/tokenpilot/pruner-review.spec.ts +70 -1
  69. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +24 -0
  70. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
  71. package/scripts/toolclass-corpus-replay.mjs +281 -0
@@ -1,78 +1,103 @@
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 not yet published to npm; the internal
6
- package name intentionally stays upstream's (`dsh-context-compression-improved`). The runtime
7
- that used to be a second package is now part of it, so one install brings the whole stack.
8
-
9
- ## Prerequisites
10
-
11
- - Node `^22.19.0 || >=24` and pnpm `11.7.0` (`corepack enable` picks the pinned version from `packageManager`).
12
- - 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).
13
- - 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.
14
- - Git.
15
-
16
- ## 1. Build from source
17
-
18
- ```sh
19
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
20
- cd dsh-context-compression-improved
21
- pnpm install --frozen-lockfile
22
- pnpm build
23
- ```
24
-
25
- `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.
26
-
27
- ## 2. Pack the Bundle entry package
28
-
29
- The selector package is the single Bundle entry; the runtime comes along as its exact-version dependency:
30
-
31
- ```sh
32
- cd packages/selector
33
- pnpm pack
34
- # → dsh-context-compression-improved-0.1.0.tgz
35
- cd ../..
36
- ```
37
-
38
- `pnpm pack` runs the bundle through the `prepack` hook, so the tarball always matches your checkout.
39
-
40
- ## 3. Add it to a Harness profile
41
-
42
- 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:
43
-
44
- ```sh
45
- dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
46
- dsh --profile web --dump-config
47
- ```
48
-
49
- 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.
50
-
51
- ## 4. Turn on the code-skeleton gate
52
-
53
- Open DeepSeek Harness settings → **Context compression selector**:
54
-
55
- 1. Pick a compression profile (the gate is orthogonal to all of them).
56
- 2. Optionally adjust the Auto Compact trigger level (50–90%, default 80%).
57
- 3. Set **Code skeleton compression** to **On**. The toggle saves on change.
58
-
59
- 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.
60
-
61
- ## 5. Update or remove
62
-
63
- ```sh
64
- # update: pull, rebuild, repack, and add the new tarball again
65
- git pull && pnpm install --frozen-lockfile && pnpm build
66
- cd packages/selector && pnpm pack && cd ../..
67
- dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
68
-
69
- # remove
70
- dsh plugin --profile web remove dsh-context-compression-improved
71
- ```
72
-
73
- ## Troubleshooting
74
-
75
- - **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.
76
- - **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.
77
- - **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.
78
- - **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.
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 published to npm as
6
+ `dsh-context-compression-improved` under the `dsh-0.1.5` dist-tag; the package name
7
+ intentionally stays upstream's. The runtime that used to be a second package is now part of
8
+ it, so one install brings the whole stack.
9
+
10
+ ## Prerequisites
11
+
12
+ - Node `^22.19.0 || >=24` and pnpm `11.7.0` (`corepack enable` picks the pinned version from `packageManager`).
13
+ - 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).
14
+ - A DeepSeek model route. Lossy compression — including the code-skeleton gate — decides on the character basis, so no bundled-tokenizer route requirement remains; when a bundled tokenizer exists its exact counts are recorded as telemetry, and other routes fail open and keep original tool results.
15
+ - Git.
16
+
17
+ ## 1. Build from source
18
+
19
+ ```sh
20
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
21
+ cd dsh-context-compression-improved
22
+ pnpm install --frozen-lockfile
23
+ pnpm build
24
+ ```
25
+
26
+ `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.
27
+
28
+ ## 2. Pack the Bundle entry package
29
+
30
+ The selector package is the single Bundle entry; the runtime comes along as its exact-version dependency:
31
+
32
+ ```sh
33
+ cd packages/selector
34
+ pnpm pack
35
+ # → dsh-context-compression-improved-0.1.0.tgz
36
+ cd ../..
37
+ ```
38
+
39
+ `pnpm pack` runs the bundle through the `prepack` hook, so the tarball always matches your checkout.
40
+
41
+ ## 3. Add it to a Harness profile
42
+
43
+ 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:
44
+
45
+ ```sh
46
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
47
+ dsh --profile web --dump-config
48
+ ```
49
+
50
+ 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.
51
+
52
+ ## 4. Turn on the code-skeleton gate
53
+
54
+ Open DeepSeek Harness settings → **Context compression selector**:
55
+
56
+ 1. Pick a compression profile (the gate is orthogonal to all of them).
57
+ 2. Optionally adjust the Auto Compact trigger level (50–90%, default 80%).
58
+ 3. Set **Code skeleton compression** to **On**. The toggle saves on change.
59
+
60
+ 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.
61
+
62
+ ## 5. Optional: the advisory relevance advisor
63
+
64
+ The plugin can keep statistics about how relevant the session's history still is — advisory only, it never decides or blocks anything. It is off by default; turn it on by editing the `presetOptions` section of the context-compression settings (settings JSON, no UI card this round):
65
+
66
+ ```json
67
+ "presetOptions": {
68
+ "advisorMode": "host",
69
+ "advisorRefreshTurns": 8,
70
+ "advisorScoreThreshold": 0.35,
71
+ "advisorSampleLimit": 16,
72
+ "advisorMinTokens": 250,
73
+ "advisorTimeoutMs": 8000
74
+ }
75
+ ```
76
+
77
+ `advisorMode: "host"` calls the harness `llm` service; `"direct"` reuses the estimator's
78
+ `estimatorBaseUrl` / `estimatorApiKey` / `estimatorModel` endpoint. At every turn boundary
79
+ the advisor (1) summarizes the current task from the most recent `todo/write` event,
80
+ (2) incrementally scores historical tool results for content-and-comment relevance, and
81
+ (3) records a prefix-decay figure. Results surface as `advisor-outcome` audit records and,
82
+ with the deployment flag `advisorReportRoute: true`, a read-only
83
+ `GET .../advisor-report?sessionId=` HTTP route. What the advisor reports can never
84
+ suppress, delay, or rewrite any reduction that would land.
85
+
86
+ ## 6. Update or remove
87
+
88
+ ```sh
89
+ # update: pull, rebuild, repack, and add the new tarball again
90
+ git pull && pnpm install --frozen-lockfile && pnpm build
91
+ cd packages/selector && pnpm pack && cd ../..
92
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
93
+
94
+ # remove
95
+ dsh plugin --profile web remove dsh-context-compression-improved
96
+ ```
97
+
98
+ ## Troubleshooting
99
+
100
+ - **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.
101
+ - **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 (decisions run on the character basis; no exact-tokenizer route requirement), and every skip is recorded with a reason in the audit trail.
102
+ - **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.
103
+ - **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.
@@ -1,77 +1,100 @@
1
- # 安装 dsh-context-compression-improved
2
-
3
- > [English](installation.md) · [中文](installation.zh.md) · [日本語](installation.ja.md) · [한국어](installation.ko.md)
4
-
5
- 本教程从源码安装 fork。fork 尚未发布到 npm;包名有意与上游保持一致:
6
- `dsh-context-compression-improved`(单一包 —— 原先独立发布的 runtime 包已并入其中)。
7
-
8
- ## 前置条件
9
-
10
- - Node `^22.19.0 || >=24` 与 pnpm `11.7.0`(`corepack enable` 会按 `packageManager` 字段使用固定版本)。
11
- - 兼容 `0.1.1-rc.2` peer 范围的 DeepSeek Harness(已针对官方 `dsh-v0.1.2-alpha.5` 验证)。
12
- - DeepSeek V4 模型路由(`deepseek-v4-flash`、`deepseek-v4-pro` `deepseek-v4-flash-vision-exp`)。有损压缩——包括代码骨架门——依赖内置的精确 tokenizer;其他路由 fail-open 并保留原始工具结果。
13
- - Git。
14
-
15
- ## 1. 从源码构建
16
-
17
- ```sh
18
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
19
- cd dsh-context-compression-improved
20
- pnpm install --frozen-lockfile
21
- pnpm build
22
- ```
23
-
24
- `pnpm build` 会打包所有包的两套产物(`tsdown`)。如需在安装前先跑全量测试,可执行 `pnpm test`。
25
-
26
- ## 2. 打包 Bundle 入口包
27
-
28
- selector 包是唯一的 Bundle 入口;runtime 作为其精确版本依赖自动随行:
29
-
30
- ```sh
31
- cd packages/selector
32
- pnpm pack
33
- # → dsh-context-compression-improved-0.1.0.tgz
34
- cd ../..
35
- ```
36
-
37
- `pnpm pack` 会通过 `prepack` 钩子执行打包,因此 tarball 始终与你的检出内容一致。
38
-
39
- ## 3. 安装到 Harness Profile
40
-
41
- selector 包声明了 Harness Bundle manifest 字段 `dsh.bundle.patch`,因此 `dsh plugin add` 是标准的树外 Bundle 安装方式:
42
-
43
- ```sh
44
- dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
45
- dsh --profile web --dump-config
46
- ```
47
-
48
- 安装后重启对应 Profile。配置导出中应显示 selector Bundle 已激活。**不要**分别安装或手动连接 selector 与 runtime 两个包——runtime 会自动安装。
49
-
50
- ## 4. 打开代码骨架门
51
-
52
- 打开 DeepSeek Harness 设置 → **上下文压缩选择器*:
53
-
54
- 1. 选择一个压缩 Profile(这道门与所有 Profile 正交)。
55
- 2. 按需调整 Auto Compact 触发水位(50–90%,默认 80%)。
56
- 3. 将**代码骨架压缩**设为**开**。开关即改即存。
57
-
58
- 与所有选择器设置一致,取值在会话首次观察时冻结——这道门只影响新观察的会话,不会改变正在运行的任务。
59
-
60
- ## 5. 更新或卸载
61
-
62
- ```sh
63
- # 更新:拉取、重建、重新打包、再次添加新 tarball
64
- git pull && pnpm install --frozen-lockfile && pnpm build
65
- cd packages/selector && pnpm pack && cd ../..
66
- dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
67
-
68
- # 卸载
69
- dsh plugin --profile web remove dsh-context-compression-improved
70
- ```
71
-
72
- ## 故障排除
73
-
74
- - **配置导出中 Bundle 未激活**:重启 Profile;确认添加的是 selector 入口包(而非 runtime),且 Harness 版本在兼容的 peer 范围内。
75
- - **工具结果从未被骨架化压缩**:该门默认关闭,请检查开关。压缩只作用于精确 tokenizer 路由上新鲜、超大、源码类的工具结果,且每次跳过都会在审计记录中留有原因。
76
- - **开关显示为不可读**:已存的 `codeSkeleton` 段未通过严格的浏览器解码(必须恰好是 `{ enabled: boolean }`)。删除畸形段即可恢复默认。
77
- - **升级步骤失败**:插件遵循 npm 包语义;如果你的 Harness 构建拒绝 tarball 到 tarball 的升级,请先移除旧版本再安装。
1
+ # 安装 dsh-context-compression-improved
2
+
3
+ > [English](installation.md) · [中文](installation.zh.md) · [日本語](installation.ja.md) · [한국어](installation.ko.md)
4
+
5
+ 本教程从源码安装 fork。fork 亦已发布到 npm,dist-tag 为 `dsh-0.1.5`;包名有意与上游保持一致:
6
+ `dsh-context-compression-improved`(单一包 —— 原先独立发布的 runtime 包已并入其中)。
7
+
8
+ ## 前置条件
9
+
10
+ - Node `^22.19.0 || >=24` 与 pnpm `11.7.0`(`corepack enable` 会按 `packageManager` 字段使用固定版本)。
11
+ - 兼容 `0.1.1-rc.2` peer 范围的 DeepSeek Harness(已针对官方 `dsh-v0.1.2-alpha.5` 验证)。
12
+ - DeepSeek 模型路由。有损压缩——包括代码骨架门——按字符基准决策,不再要求内建精确 tokenizer;存在内建 tokenizer 时其 exact 计数仅作遥测记录,其他路由 fail-open 并保留原始工具结果。
13
+ - Git。
14
+
15
+ ## 1. 从源码构建
16
+
17
+ ```sh
18
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
19
+ cd dsh-context-compression-improved
20
+ pnpm install --frozen-lockfile
21
+ pnpm build
22
+ ```
23
+
24
+ `pnpm build` 会打包所有包的两套产物(`tsdown`)。如需在安装前先跑全量测试,可执行 `pnpm test`。
25
+
26
+ ## 2. 打包 Bundle 入口包
27
+
28
+ selector 包是唯一的 Bundle 入口;runtime 作为其精确版本依赖自动随行:
29
+
30
+ ```sh
31
+ cd packages/selector
32
+ pnpm pack
33
+ # → dsh-context-compression-improved-0.1.0.tgz
34
+ cd ../..
35
+ ```
36
+
37
+ `pnpm pack` 会通过 `prepack` 钩子执行打包,因此 tarball 始终与你的检出内容一致。
38
+
39
+ ## 3. 安装到 Harness Profile
40
+
41
+ selector 包声明了 Harness Bundle manifest 字段 `dsh.bundle.patch`,因此 `dsh plugin add` 是标准的树外 Bundle 安装方式:
42
+
43
+ ```sh
44
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
45
+ dsh --profile web --dump-config
46
+ ```
47
+
48
+ 安装后重启对应 Profile。配置导出中应显示 selector Bundle 已激活。**不要**分别安装或手动连接 selector 与 runtime 两个包——runtime 会自动安装。
49
+
50
+ ## 4. 打开代码骨架门
51
+
52
+ 打开 DeepSeek Harness 设置 → **上下文压缩选择器*:
53
+
54
+ 1. 选择一个压缩 Profile(这道门与所有 Profile 正交)。
55
+ 2. 按需调整 Auto Compact 触发水位(50–90%,默认 80%)。
56
+ 3. 将**代码骨架压缩**设为**开**。开关即改即存。
57
+
58
+ 与所有选择器设置一致,取值在会话首次观察时冻结——这道门只影响新观察的会话,不会改变正在运行的任务。
59
+
60
+ ## 5. 可选:建议型相关度 advisor
61
+
62
+ 插件可以对"会话历史还有多相关"做统计——仅建议性质,不做任何决策、也不阻断任何流程。默认关闭;本轮没有设置卡片,请直接编辑上下文压缩设置中的 `presetOptions` 段(settings JSON):
63
+
64
+ ```json
65
+ "presetOptions": {
66
+ "advisorMode": "host",
67
+ "advisorRefreshTurns": 8,
68
+ "advisorScoreThreshold": 0.35,
69
+ "advisorSampleLimit": 16,
70
+ "advisorMinTokens": 250,
71
+ "advisorTimeoutMs": 8000
72
+ }
73
+ ```
74
+
75
+ `advisorMode: "host"` harness `llm` 服务;`"direct"` 复用 estimator 的
76
+ `estimatorBaseUrl` / `estimatorApiKey` / `estimatorModel` 端点。每个 turn 边界,advisor
77
+ 会:(1) 从最近的 `todo/write` 事件总结当前任务语义;(2) 对历史 tool result 做"内容+注释
78
+ 语义 ↔ 当前任务"的增量相关度打分;(3) 记录前缀腐化度(prefix-decay)。结果以
79
+ `advisor-outcome` 审计记录呈现;部署配置打开 `advisorReportRoute: true` 后,还可经只读
80
+ HTTP 路由 `GET .../advisor-report?sessionId=` 读取。advisor 报告的任何内容都不会抑制、
81
+ 延迟或改写任何本应落地的 reduction。
82
+
83
+ ## 6. 更新或卸载
84
+
85
+ ```sh
86
+ # 更新:拉取、重建、重新打包、再次添加新 tarball
87
+ git pull && pnpm install --frozen-lockfile && pnpm build
88
+ cd packages/selector && pnpm pack && cd ../..
89
+ dsh plugin --profile web add packages/selector/dsh-context-compression-improved-0.1.0.tgz
90
+
91
+ # 卸载
92
+ dsh plugin --profile web remove dsh-context-compression-improved
93
+ ```
94
+
95
+ ## 故障排除
96
+
97
+ - **配置导出中 Bundle 未激活**:重启 Profile;确认添加的是 selector 入口包(而非 runtime),且 Harness 版本在兼容的 peer 范围内。
98
+ - **工具结果从未被骨架化压缩**:该门默认关闭,请检查开关。压缩只作用于新鲜、超大、源码类的工具结果(决策按字符基准执行,无精确 tokenizer 路由要求),且每次跳过都会在审计记录中留有原因。
99
+ - **开关显示为不可读**:已存的 `codeSkeleton` 段未通过严格的浏览器解码(必须恰好是 `{ enabled: boolean }`)。删除畸形段即可恢复默认。
100
+ - **升级步骤失败**:插件遵循 npm 包语义;如果你的 Harness 构建拒绝 tarball 到 tarball 的升级,请先移除旧版本再安装。
@@ -357,6 +357,59 @@ here for reasons the project's own `upgrade-pitfalls` §2.1 records independentl
357
357
 
358
358
  ---
359
359
 
360
+ ## D8 — The search reducer dropped 21.2% of hits and never reported where they went
361
+
362
+ **Symptom.** Large `grep`/`rg` results compressed by `search-by-file` lost every hit the
363
+ per-file "first 4 + last" rule did not keep, and the file header only said `(592 matches)`
364
+ with no line numbers. The model could not tell which hits were dropped or where to re-read.
365
+
366
+ **Root cause.** `reduceSearch` filled each file's keep-set from index 0 (`keep.size < 5`)
367
+ and reported only counts. Nothing in the output identified the omitted hit positions, so the
368
+ loss was invisible and unrecoverable except by re-running the search.
369
+
370
+ **Evidence.** 14 real sessions (18.6M characters, DSH 0.1.5-rc.2): 186 search events /
371
+ 5,301 hits; per-file median 18, p90 55, max 592; 1,122 hits (21.2%) discarded silently.
372
+
373
+ **Affected surface.** `packages/selector/src/runtime/reducers.ts` (`reduceSearch`).
374
+
375
+ **Fix.** Two-tier folding (R10): L1 is a lossless per-file locator
376
+ (`## <path> (N matches) L12,L15,…`, one line number per hit, budget reserved first); L2 is
377
+ the content quota, water-filled round-robin so no file vanishes. When L1 itself cannot fit
378
+ the shortfall is announced (withheld file/match counts), never silently truncated.
379
+
380
+ **Verification.** `packages/selector/tests/runtime/search-reducer.spec.ts`: a 592-hit file
381
+ reports 592 locator numbers; water-filling serves every file before any file takes a second
382
+ row; withheld locators are announced in the output.
383
+
384
+ ---
385
+
386
+ ## D9 — HTML fell into `pi-head`, which kept the `<head>` and dropped the body
387
+
388
+ **Symptom.** Fetched/compressed HTML pages kept `<!DOCTYPE>`, `<meta>`, `<link>`,
389
+ `<script>` and `<style>` — the metadata — while the entire body content disappeared.
390
+
391
+ **Root cause.** `looksLikeSourceCode` matches no HTML tags (its patterns cover
392
+ declarations/imports/decorators only), so pages fell through to the head/tail fallbacks, and
393
+ `reduceHead` takes from the top — exactly the worst segment for HTML.
394
+
395
+ **Evidence.** `CODE_STRUCTURE_PATTERN` / `CODE_IMPORT_PATTERN` / `CODE_DECORATOR_PATTERN`
396
+ match none of `<html|<div|<script|…`; the repository carried zero HTML-input tests (31
397
+ `<html|<div|<script` hits, all in TSX sources and tokenizer vocabularies).
398
+
399
+ **Affected surface.** `packages/selector/src/runtime/reducers.ts` (candidate chain).
400
+
401
+ **Fix.** Two-stage reduction (R13): `html-slim` strips comments, script/style/noscript/svg/
402
+ head elements, data URIs, non-whitelisted attributes (`href/src/alt/title/id` survive) and
403
+ inline-tag markup, line-aligned so original-event line numbers survive; `html-skeleton`
404
+ keeps the heading hierarchy, section first lines and table header rows under tighter budgets.
405
+ Classification is pure form (≥3 markup-tag lines in the first 400).
406
+
407
+ **Verification.** `packages/selector/tests/runtime/html-reducer.spec.ts`: body paragraphs
408
+ and headings survive; script/style/comment/data-URI content is gone; the skeleton fallback
409
+ cites original line ranges; TS generics/comparisons are not misclassified as HTML.
410
+
411
+ ---
412
+
360
413
  ## U1 — The estimator card vanished off TokenPilot-inspired instead of explaining its gate
361
414
 
362
415
  **Symptom.** With any profile other than TokenPilot-inspired selected, the Settings page showed
@@ -601,3 +654,4 @@ caused.
601
654
  | 2026-09-15 | doc corruption — mechanism | **Diagnosed.** A damaged spot is the 2-byte prefix of a three-byte UTF-8 character followed by `0x3F`: the character lost its third byte and, in most spots, the byte that followed it was consumed too (a double-byte-code-page decode/write pair collapse; 0 or 1 bytes lost per spot). The damage is **inherited, not produced here**: the newest valid blob of every affected file is `e337bf5`, while the same files are already defective at the `compat/0.1.5` baseline `d7c592d` and at `04f86e4`. Ten files carry it, not five — `README.{zh,ja,ko}.md` and `scripts/packed-install-e2e.mjs` were missed by the earlier note |
602
655
  | 2026-09-15 | doc corruption — repaired | **Batch I / T-I2.** All ten files repaired by restoring each damaged spot from `e337bf5`, with three independent checks: the restored character must carry the surviving 2-byte prefix; re-corrupting the repair reproduces the previous bytes exactly (so the edit touches nothing but the damage, and no line, no EOL and no other character moves); and the repair must agree with the valid ancestor everywhere outside the restored spots. Every affected file is now valid UTF-8. The English `README.md` is the clean case: ten spots, all `—`/quote characters plus their following space, zero other differences from the ancestor |
603
656
  | 2026-09-15 | ledger encoding | The twelve `—` characters in this file had been mangled to `鈥?` by the PowerShell port of the ledger (the 0.1.2 source has none); restored. Same class as the doc corruption above, introduced by that one-time port rather than inherited |
657
+ | 2026-09-19 | D8/D9 | Compression-quality defects ledgered on `feat/ctx-compression-v2-compat015`: search hits were dropped unlocatably (21.2%), HTML kept its `<head>` and lost its body; both fixed with two-tier search folding and two-stage HTML reduction, each with counter-proof tests |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-context-compression-improved",
3
- "version": "0.4.0-beta.1",
3
+ "version": "0.5.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",