dsh-context-compression-improved 0.2.3 → 0.2.5

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 (149) hide show
  1. package/.gitattributes +2 -1
  2. package/.githooks/pre-push +37 -0
  3. package/.github/workflows/ci.yml +39 -39
  4. package/CHANGELOG.ja.md +169 -39
  5. package/CHANGELOG.ko.md +167 -39
  6. package/CHANGELOG.md +333 -135
  7. package/CHANGELOG.zh.md +152 -39
  8. package/CONTRIBUTING.md +22 -22
  9. package/README.ja.md +85 -104
  10. package/README.ko.md +85 -103
  11. package/README.md +94 -112
  12. package/README.zh.md +85 -101
  13. package/THIRD_PARTY_NOTICES.md +14 -14
  14. package/docs/compat-0.1.5-report.md +77 -0
  15. package/docs/installation.ja.md +78 -76
  16. package/docs/installation.ko.md +78 -76
  17. package/docs/installation.md +103 -76
  18. package/docs/installation.zh.md +100 -76
  19. package/docs/repair-log.md +657 -582
  20. package/eslint.config.js +30 -30
  21. package/package.json +163 -142
  22. package/packages/selector/README.md +26 -31
  23. package/packages/selector/README.zh.md +24 -31
  24. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
  25. package/packages/selector/cordis.patch.yml +27 -19
  26. package/packages/selector/dsh.plugin.json +2 -2
  27. package/packages/selector/lib/client.d.ts +320 -228
  28. package/packages/selector/lib/client.js +3254 -1462
  29. package/packages/selector/lib/config.js +1713 -842
  30. package/packages/selector/lib/index.d.ts +46 -38
  31. package/packages/selector/lib/index.js +1099 -645
  32. package/packages/selector/lib/invariant.js +70 -70
  33. package/packages/selector/lib/pruner.d.ts +904 -684
  34. package/packages/selector/lib/pruner.js +5800 -3807
  35. package/packages/selector/lib/style.css +88 -46
  36. package/packages/selector/lib/tail-trim.js +145 -136
  37. package/packages/selector/package.json +18 -19
  38. package/packages/selector/screenshots.json +3 -6
  39. package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
  40. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
  41. package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
  42. package/packages/selector/src/client/EstimatorControls.tsx +277 -281
  43. package/packages/selector/src/client/decode.ts +57 -49
  44. package/packages/selector/src/client/index.ts +249 -111
  45. package/packages/selector/src/client/locales/de.ts +141 -0
  46. package/packages/selector/src/client/locales/es.ts +141 -0
  47. package/packages/selector/src/client/locales/fr.ts +141 -0
  48. package/packages/selector/src/client/locales/it.ts +141 -0
  49. package/packages/selector/src/client/locales/ja.ts +141 -0
  50. package/packages/selector/src/client/locales/ko.ts +141 -0
  51. package/packages/selector/src/client/locales/ru.ts +141 -0
  52. package/packages/selector/src/client/locales.ts +282 -198
  53. package/packages/selector/src/client/monitor-fab.ts +336 -0
  54. package/packages/selector/src/client/preset-options.ts +88 -70
  55. package/packages/selector/src/client/savings-card.tsx +150 -0
  56. package/packages/selector/src/client/settings-section.tsx +140 -126
  57. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
  58. package/packages/selector/src/index.ts +671 -327
  59. package/packages/selector/src/invariant.ts +113 -113
  60. package/packages/selector/src/preset-overlay.ts +60 -1
  61. package/packages/selector/src/profiles.ts +431 -342
  62. package/packages/selector/src/pruner/content.ts +18 -5
  63. package/packages/selector/src/pruner/state.ts +57 -43
  64. package/packages/selector/src/pruner/types.ts +23 -5
  65. package/packages/selector/src/pruner.ts +2736 -2144
  66. package/packages/selector/src/runtime/adaptive-cost.ts +23 -12
  67. package/packages/selector/src/runtime/audit.ts +303 -215
  68. package/packages/selector/src/runtime/config.ts +756 -613
  69. package/packages/selector/src/runtime/measurement.ts +436 -403
  70. package/packages/selector/src/runtime/monitor.ts +235 -0
  71. package/packages/selector/src/runtime/reducers.ts +1115 -97
  72. package/packages/selector/src/runtime/retrieve.ts +479 -457
  73. package/packages/selector/src/runtime/savings.ts +337 -0
  74. package/packages/selector/src/runtime/session-events.ts +30 -17
  75. package/packages/selector/src/runtime/summary-command.ts +127 -0
  76. package/packages/selector/src/runtime/tail-trim.ts +166 -166
  77. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
  78. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
  79. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
  80. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
  81. package/packages/selector/src/runtime/tokenpilot/dedup.ts +1 -1
  82. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
  83. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  84. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  85. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  86. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  87. package/packages/selector/src/runtime/tokenpilot/locator.ts +1 -1
  88. package/packages/selector/src/runtime/tokenpilot/read-state.ts +23 -2
  89. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
  90. package/packages/selector/src/runtime/toolclass.ts +103 -0
  91. package/packages/selector/src/runtime/types.ts +365 -309
  92. package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
  93. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
  94. package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
  95. package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
  96. package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
  97. package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
  98. package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
  99. package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
  100. package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
  101. package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
  102. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
  103. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -243
  104. package/packages/selector/tests/profiles.client.spec.tsx +436 -434
  105. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
  106. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +7 -7
  107. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
  108. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
  109. package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
  110. package/packages/selector/tests/runtime/audit.spec.ts +275 -129
  111. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
  112. package/packages/selector/tests/runtime/code-skeleton.spec.ts +14 -3
  113. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
  114. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
  115. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
  116. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  117. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  118. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
  119. package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
  120. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
  121. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2531
  122. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
  123. package/packages/selector/tests/runtime/savings.spec.ts +120 -0
  124. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
  125. package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
  126. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
  127. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  128. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
  129. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
  130. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
  131. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
  132. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +24 -0
  133. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
  134. package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
  135. package/packages/selector/tests/standing-generation.host.spec.ts +697 -631
  136. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
  137. package/pnpm-workspace.yaml +66 -19
  138. package/scripts/capture-profile-baseline.mjs +42 -0
  139. package/scripts/generate-tokenizer-fixtures.py +81 -81
  140. package/scripts/generate-vision-fixtures.py +208 -208
  141. package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
  142. package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
  143. package/scripts/toolclass-corpus-replay.mjs +281 -0
  144. package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
  145. package/tests/TEST_INVENTORY.md +41 -42
  146. package/scripts/capture-profile-baseline.ts +0 -80
  147. package/tsconfig.scripts.json +0 -13
  148. /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
  149. /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
package/README.ko.md CHANGED
@@ -1,103 +1,85 @@
1
- # dsh-context-compression-improved
2
-
3
- > [dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector)의 개선 포크——DeepSeek Harness용 감사 가능한 도구 결과 컨텍스트 압축 셀렉터에, 직교하는 **코드 스켈레톤 압축 게이트**를 추가했습니다.
4
-
5
- [English](README.md) · [中文说明](README.zh.md) · [日本語](README.ja.md) · [변경 로그](CHANGELOG.ko.md) · [설치 가이드](docs/installation.ko.md)
6
-
7
- > [!NOTE]
8
- > **이 포크가 업스트림 0.1.0에 추가한 것:**
9
- >
10
- > - 직교하는 **코드 스켈레톤 압축 게이트**(`codeSkeleton.enabled`, 기본값 off): 매우 큰 소스코드 도구 결과가 처음 노출될 때, 일반 리듀서로 넘어가기 전에 임포트와 선언부의 스켈레톤을 보존할 수 있습니다(함수 본문은 생략, 에러 라인은 유지).
11
- > - 동일한 셀렉터 설정 섹션에 모든 압축 프로파일과 독립적인 이 게이트의 토글을 추가.
12
- > - CI에 통합된 ESLint 베이스라인, `test:watch` TDD 루프, 영어/중국어(간체)/일본어/한국어 문서.
13
-
14
- > [!IMPORTANT]
15
- > 이 프로젝트는 **DeepSeek 모델만** 지원합니다. 손실 없는 측정과 손실 압축은 번들된 DeepSeek 공식 토크나이저(`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
- 장시간 실행되는 에이전트 작업은 대량의 도구 출력을 축적합니다. 이 커뮤니티 플러그인은 DeepSeek Harness 코어를 수정하지 않고, 선택 가능하고 감사 가능한 도구 결과 컨텍스트 압축 정책을 제공합니다:
20
-
21
- - **Fresh**: 모델이 받기 전에 새로 커진 도구 결과 세그먼트를 사전 압축합니다.
22
- - **Aggregate**: Fresh 압축 후에도 예산을 초과하면 다시 압축합니다.
23
- - **History / micro-compact**: 최근 작업 컨텍스트를 보호하면서 대상이 되는 오래된 도구 결과를 교체합니다.
24
- - **TailTrim**: Custom에서만 활성화할 수 있는 선택적 테일 축소 경로입니다.
25
- - **Native**: Harness 방식의 head/중간/tail 트리밍을 하나의 명시적 프로파일로 유지합니다.
26
- - **코드 스켈레톤(신규, 직교 게이트)**——아래 참고.
27
-
28
- 모든 결정은 기록됩니다: 단계, 리듀서, 트리거 이유, 건너뜀 이유, 그리고 가능한 경우 정확한 토큰 수.
29
-
30
- ## 코드 스켈레톤 게이트(신규)
31
-
32
- 게이트를 활성화하면 매우 큰 **소스코드 도구 결과**(예: 큰 `read_file`)에 대해 먼저 스켈레톤 축소를 시도합니다: 임포트와 타입/함수/클래스 선언을 유지하고, 함수 본문은 마커와 함께 생략하며, 생략된 본문 안의 에러 라인은 보존합니다. 스켈레톤을 생성하거나 검증할 수 없으면 원래의 head 트리밍으로 폴백합니다——이 게이트가 컨텍스트를 악화시킬 수는 없습니다.
33
-
34
- 특성:
35
-
36
- - **직교**: 선택된 프로파일(`balanced`, `savings`, `cache-strict`, `adaptive`, `custom`, `off`, `native`)과 독립적입니다. 모든 프로파일이 이 게이트를 받습니다.
37
- - **기본값 off**: `codeSkeleton: { enabled: false }`이며, 직접 켜기 전까지는 동작하지 않습니다.
38
- - **측정이 선행**: 정확한 DeepSeek 토크나이저가 필요하며, 사용할 수 없으면 fail-open합니다.
39
- - **세션 고정**: 다른 셀렉터 설정과 마찬가지로 변경 사항은 새로 관찰된 세션에만 적용됩니다.
40
- - **엄격한 파싱**: `codeSkeleton`은 정확히 `{ enabled: boolean }`이어야 합니다. 잘못된 값은 런타임 쪽에서 예외를 던지고, 브라우저 UI에서는 읽을 수 없음으로 표시됩니다.
41
-
42
- ### 출처, 그리고 이 수치는 누구의 것인가
43
-
44
- 스켈레톤화 접근은 **[Headroom](https://github.com/headroomlabs-ai/headroom)**(Apache-2.0)에서
45
- 차용했습니다. AI 에이전트용 컨텍스트 압축 계층으로, JSON·소스 코드·산문을 각각 다른 압축기로
46
- 분기하며(JSON은 `SmartCrusher`, 코드는 `CodeCompressor`), 스켈레톤 변환은
47
- `crates/headroom-core/src/transforms/live_zone.rs`와 `smart_crusher/planning.rs`에 있습니다.
48
-
49
- **감축 수치는 Headroom의 것이며 이 플러그인의 것이 아닙니다.** Headroom이 공개한 공식 표현은
50
- 다음과 같습니다.
51
-
52
- > 20% fewer tokens for coding agents, **60–95% fewer tokens for JSON**, same answers.
53
-
54
- **최대 95% 감축**이라는 수치는 이 문장에서 나온 것이며, 기준은 JSON 페이로드이고 Headroom 자체
55
- 압축기가 Headroom 자체 벤치마크에서 측정한 값입니다. 이 게이트의 메커니즘은 여기에 동원(同源)을
56
- 둡니다. 이 저장소는 **자체 벤치마크가 전혀 없으므로 자체 감축률을 주장하지 않습니다.** 수치가
57
- 필요하면 출처에서 확인하십시오.
58
-
59
- ## 설정 UI
60
-
61
- 동일한 설정 섹션에서 압축 프로파일 선택, Auto Compact 트리거 레벨 조정, 코드 스켈레톤 압축 토글을 모두 처리할 수 있습니다. 토글은 변경 시 즉시 저장되며, 다시 불러올 때 저장된 상태가 표시됩니다.
62
-
63
- ![Context Compression Selector 설정 UI](packages/selector/assets/screenshots/context-compression-selector-settings.png)
64
-
65
- ## 설치
66
-
67
- 소스에서 빌드하여 설치합니다(이 포크는 아직 npm에 게시되지 않았습니다. 내부 패키지 이름은 의도적으로 업스트림과 동일하게 유지됩니다):
68
-
69
- ```sh
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
74
- ```
75
-
76
- 이후 셀렉터 패키지를 pack 해서 Harness 프로파일에 추가합니다——검증과 제거를 포함한 전체 절차는 [설치 가이드](docs/installation.ko.md)를 참고하세요.
77
-
78
- ## 개발
79
-
80
- ```sh
81
- pnpm install --frozen-lockfile
82
- pnpm lint # ESLint 베이스라인(CI에서도 강제)
83
- pnpm typecheck # runtime + selector + tests tsc 및 bundle 단계
84
- pnpm test # vitest 전체 스위트
85
- pnpm test:watch # TDD 루프: 먼저 실패하는 회귀 테스트를 작성하고, 통과시킨다
86
- pnpm build
87
- pnpm verify:release
88
- ```
89
-
90
- 기여는 업스트림의 규율을 따릅니다: 먼저 실패하는 회귀 테스트를 추가하고, 모든 프로덕션 변경은 이 저장소 안에 유지하며, "트리거됨", "활성화되었지만 건너뜀", "fail-open"의 증거를 각각 따로 제시하세요. [CONTRIBUTING.md](CONTRIBUTING.md) 참고.
91
-
92
- ## 호환성
93
-
94
- - 공개된 플러그인 및 프로파일 API만 사용하여 DeepSeek Harness `dsh-v0.1.1-rc.2`에서 검증되었으며, 공식 `dsh-v0.1.2-alpha.5` 릴리스와 호환됩니다.
95
- - Node `^22.19.0 || >=24`와 pnpm `11.7.0`이 필요합니다.
96
- - 플러그인은 Harness의 공개 확장 API만 사용하며 Harness 코어를 수정하지 않습니다. 비공식 커뮤니티 프로젝트이며 DeepSeek과 제휴하거나 승인받지 않았습니다.
97
-
98
- ## 크레딧과 라이선스
99
-
100
- - 업스트림 프로젝트와 기존의 모든 작업: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector), 작성자 WilliamShi666(MIT).
101
- - 포크에서 추가된 것(코드 스켈레톤 게이트, 툴체인, 다국어 문서): drscrewdriver.
102
- - 코드 스켈레톤 메커니즘 출처: [Headroom](https://github.com/headroomlabs-ai/headroom) (Apache-2.0) — 위의 "출처, 그리고 이 수치는 누구의 것인가"를 참조하십시오.
103
- - MIT——[LICENSE](LICENSE)(업스트림 저작권 표기 유지) 참고. 번들된 토크나이저의 출처는 [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)의 개선 포크——DeepSeek Harness용 감사 가능한 도구 결과 컨텍스트 압축 셀렉터에, 직교하는 **코드 스켈레톤 압축 게이트*를추가했습니다.
4
+
5
+ [English](README.md) · [中文说明](README.zh.md) · [日本語](README.ja.md) · [변경 로그](CHANGELOG.ko.md) · [설치 가이드](docs/installation.ko.md)
6
+
7
+ > [!NOTE]
8
+ > **이 포크가 업스트림 0.1.0에 추가한것**
9
+ >
10
+ > - 직교하는 **코드 스켈레톤 압축 게이트**(`codeSkeleton.enabled`, 기본값 off): 매우 큰 소스코드 도구 결과가 처음 노출될때 일반 리듀서로 넘어가기 전에 임포트와 선언부의 스켈레톤을 보존할수있습니다(함수 본문은 생략, 에러 라인은 유지).
11
+ > - 동일한 셀렉터 설정 섹션에 모든 압축 프로파일과 독립적인 이 게이트의 토글을 추가.
12
+ > - CI에 통합된 ESLint 베이스라인, `test:watch` TDD 루프, 영어/중국어(간체)/일본어/한국어 문서.
13
+
14
+ > [!IMPORTANT]
15
+ > 이 프로젝트는 **DeepSeek 모델만** 지원합니다. 손실 없는 측정과 손실 압축은 번들된 DeepSeek 공식 토크나이저(`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
+ 장시간 실행되는 에이전트 작업은 대량의 도구 출력을 축적합니다. 이커뮤니티 플러그인은 DeepSeek Harness 코어를 수정하지 않고, 선택 가능하고 감사 가능한 도구 결과 컨텍스트 압축 정책을 제공합니다:
20
+
21
+ - **Fresh**: 모델이 받기 전에 새로 커진 도구 결과 세그먼트를 사전 압축합니다.
22
+ - **Aggregate**: Fresh 압축 후에도 예산을 초과하면 다시 압축합니다.
23
+ - **History / micro-compact**: 최근 작업 컨텍스트를 보호하면서 대상이 되는 오래된 도구 결과를 교체합니다.
24
+ - **TailTrim**: Custom에서만 활성화할 수 있는 선택적 테일 축소 경로입니다.
25
+ - **Native**: Harness 방식의 head/중간/tail 트리밍을 하나의 명시적 프로파일로 유지합니다.
26
+ - **코드 스켈레톤(신규, 직교 게이트)**——아래 참고.
27
+
28
+ 모든 결정은 기록됩니다: 단계, 리듀서, 트리거 이유, 건너뜀 이유, 그리고 가능한 경우 정확한 토큰 수.
29
+
30
+ ## 코드 스켈레톤 게이트(신규)
31
+
32
+ 게이트를 활성화하면 매우 큰 **소스코드 도구 결과**(예: 큰`read_file`)에 대해 먼저 스켈레톤 축소를 시도합니다: 임포트와 타입/함수/클래스 선언을 유지하고, 함수 본문은 마커와 함께 생략하며, 생략된 본문 안의 에러 라인은 보존합니다. 스켈레톤을 생성하거나 검증할 수 없으면 원래의 head 트리밍으로 폴백합니다——이 게이트가 컨텍스트를 악화시킬 수는 없습니다.
33
+
34
+ 특성:
35
+
36
+ - **직교**: 선택된 프로파일(`balanced`, `savings`, `cache-strict`, `adaptive`, `custom`, `off`, `native`)과 독립적입니다. 모든 프로파일이이게이트를 받습니다.
37
+ - **기본값 off**: `codeSkeleton: { enabled: false }`이며, 직접 켜기 전까지는 동작하지 않습니다.
38
+ - **측정이 선행**: 정확한 DeepSeek 토크나이저가 필요하며, 사용할수없으면 fail-open합니다.
39
+ - **세션 고정**: 다른 셀렉터 설정과 마찬가지로 변경 사항은 새로 관찰된 세션에만 적용됩니다.
40
+ - **엄격한 파싱**: `codeSkeleton`은 정확히 `{ enabled: boolean }`이어야 합니다. 잘못된 값은 런타임 쪽에서 예외를 던지고, 브라우저 UI에서는 읽을 수 없음으로 표시됩니다.
41
+
42
+ ## 설정 UI
43
+
44
+ 동일한 설정 섹션에서 압축 프로파일 선택, Auto Compact 트리거 레벨 조정, 코드 스켈레톤 압축 토글을 모두 처리할수있습니다. 토글은 변경시즉시 저장되며, 다시 불러올때저장된 상태가 표시됩니다.
45
+
46
+ ![Context Compression Selector 설정 UI](docs/assets/context-compression-selector-settings.png)
47
+
48
+ ## 설치
49
+
50
+ 소스에서 빌드하여 설치합니다 —— 이 포크는 npm에도 `dsh-context-compression-improved`로 게시되어 있습니다(dist-tag `dsh-0.1.5`). 내부 패키지 이름은 의도적으로 업스트림과 동일하게 유지됩니다:
51
+
52
+ ```sh
53
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
54
+ cd dsh-context-compression-improved
55
+ pnpm install --frozen-lockfile
56
+ pnpm build
57
+ ```
58
+
59
+ 이후 셀렉터 패키지를 pack 해서 Harness 프로파일에 추가합니다——검증과 제거를 포함한 전체 절차는 [설치 가이드](docs/installation.ko.md)를 참고하세요.
60
+
61
+ ## 개발
62
+
63
+ ```sh
64
+ pnpm install --frozen-lockfile
65
+ pnpm lint # ESLint 베이스라인(CI에서도 강제)
66
+ pnpm typecheck # runtime + selector + tests tsc 및 bundle 단계
67
+ pnpm test # vitest 전체 스위트
68
+ pnpm test:watch # TDD 루프: 먼저 실패하는 회귀 테스트를 작성하고, 통과시킨다
69
+ pnpm build
70
+ pnpm verify:release
71
+ ```
72
+
73
+ 기여는 업스트림의 규율을 따릅니다: 먼저 실패하는 회귀 테스트를 추가하고, 모든 프로덕션 변경은 이 저장소 안에 유지하며, "트리거됨", "활성화되었지만 건너뜀", "fail-open"의 증거를 각각 따로 제시하세요. [CONTRIBUTING.md](CONTRIBUTING.md) 참고.
74
+
75
+ ## 호환성
76
+
77
+ - 공개된 플러그인 및 프로파일 API만 사용하여 DeepSeek Harness `dsh-v0.1.1-rc.2`에서 검증되었으며, 공식 `dsh-v0.1.2-alpha.5` 릴리스와 호환됩니다.
78
+ - Node `^22.19.0 || >=24`와 pnpm `11.7.0`이 필요합니다.
79
+ - 플러그인은 Harness의 공개 확장 API만 사용하며 Harness 코어를 수정하지 않습니다. 비공식 커뮤니티 프로젝트이며 DeepSeek과 제휴하거나 승인받지 않았습니다.
80
+
81
+ ## 크레딧과 라이선스
82
+
83
+ - 업스트림 프로젝트와 기존의 모든 작업: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector), 작성자 WilliamShi666(MIT).
84
+ - 포크에서 추가된것코드 스켈레톤 게이트, 툴체인, 다국어 문서): drscrewdriver.
85
+ - MIT——[LICENSE](LICENSE)(업스트림 저작권 표기 유지) 참고. 번들된 토크나이저의 출처는 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
package/README.md CHANGED
@@ -1,112 +1,94 @@
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
- > - 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
- **Recommended: install from npm.** One dist-tag per Harness line — `dsh-0.1.5` for the 0.1.5 line (this branch), `dsh-0.1.2` for the 0.1.2 line.
68
-
69
- ```sh
70
- dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
71
- # DSH 0.1.2 line:
72
- # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
73
- dsh --profile web --dump-config
74
- ```
75
-
76
- From source (alternative — the internal package names intentionally stay upstream's):
77
-
78
- ```sh
79
- git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
80
- cd dsh-context-compression-improved
81
- pnpm install --frozen-lockfile
82
- pnpm build
83
- ```
84
-
85
- 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).
86
-
87
- ## Development
88
-
89
- ```sh
90
- pnpm install --frozen-lockfile
91
- pnpm lint # ESLint baseline (also enforced in CI)
92
- pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
93
- pnpm test # full vitest suite
94
- pnpm test:watch # TDD loop: write the failing regression first, then make it pass
95
- pnpm build
96
- pnpm verify:release
97
- ```
98
-
99
- 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).
100
-
101
- ## Compatibility
102
-
103
- - 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.
104
- - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
105
- - 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.
106
-
107
- ## Credits and license
108
-
109
- - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
110
- - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
111
- - Code-skeleton mechanism: [Headroom](https://github.com/headroomlabs-ai/headroom) (Apache-2.0) — see "Provenance, and whose numbers these are" above.
112
- - 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
+ > - 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
+ ## Settings UI
43
+
44
+ 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.
45
+
46
+ ![Context Compression Selector settings UI](docs/assets/context-compression-selector-settings.png)
47
+
48
+ ## Install
49
+
50
+ **Recommended: install from npm.** One dist-tag per Harness line — `dsh-0.1.5` for the 0.1.5 line (this branch), `dsh-0.1.2` for the 0.1.2 line.
51
+
52
+ ```sh
53
+ dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
54
+ # DSH 0.1.2 line:
55
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
56
+ dsh --profile web --dump-config
57
+ ```
58
+
59
+ From source (alternative — the internal package names intentionally stay upstream's):
60
+
61
+ ```sh
62
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
63
+ cd dsh-context-compression-improved
64
+ pnpm install --frozen-lockfile
65
+ pnpm build
66
+ ```
67
+
68
+ 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).
69
+
70
+ ## Development
71
+
72
+ ```sh
73
+ pnpm install --frozen-lockfile
74
+ pnpm lint # ESLint baseline (also enforced in CI)
75
+ pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
76
+ pnpm test # full vitest suite
77
+ pnpm test:watch # TDD loop: write the failing regression first, then make it pass
78
+ pnpm build
79
+ pnpm verify:release
80
+ ```
81
+
82
+ 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).
83
+
84
+ ## Compatibility
85
+
86
+ - 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.
87
+ - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
88
+ - 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.
89
+
90
+ ## Credits and license
91
+
92
+ - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
93
+ - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
94
+ - 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,101 +1,85 @@
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
- > - 正交的**代码骨架压缩门**(`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 包;内部包名有意保持与上游一致):
66
-
67
- ```sh
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
72
- ```
73
-
74
- 随后打包 selector 包并安装到某个 Harness Profile——完整步骤(含验证与卸载)见[安装教程](docs/installation.zh.md)。
75
-
76
- ## 开发
77
-
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
- ```
87
-
88
- 贡献遵循上游纪律:先写失败的回归用例;所有生产改动收敛在本仓库内;对“已触发”“已启用但跳过”“fail-open”分别给出证据。见 [CONTRIBUTING.md](CONTRIBUTING.md)。
89
-
90
- ## 兼容性
91
-
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 无隶属或背书关系。
95
-
96
- ## 致谢与许可
97
-
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)。
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
+ > - 正交的**代码骨架压缩门**(`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
+ 在同一设置区内选择压缩 Profile、调整 Auto Compact 触发水位,并开关代码骨架压缩。开关即改即存,刷新后显示已保存状态。
45
+
46
+ ![Context Compression Selector 设置界面](docs/assets/context-compression-selector-settings.png)
47
+
48
+ ## 安装
49
+
50
+ 从源码构建并安装 —— 本 fork 亦已发布到 npm,包名为 `dsh-context-compression-improved`(dist-tag `dsh-0.1.5`);内部包名有意保持与上游一致:
51
+
52
+ ```sh
53
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
54
+ cd dsh-context-compression-improved
55
+ pnpm install --frozen-lockfile
56
+ pnpm build
57
+ ```
58
+
59
+ 随后打包 selector 包并安装到某个 Harness Profile——完整步骤(含验证与卸载)见[安装教程](docs/installation.zh.md)。
60
+
61
+ ## 开发
62
+
63
+ ```sh
64
+ pnpm install --frozen-lockfile
65
+ pnpm lint # ESLint 基线(CI 同步强制)
66
+ pnpm typecheck # runtime + selector + tests tsc,含 bundle 步
67
+ pnpm test # vitest 全量
68
+ pnpm test:watch # TDD 环路:先写失败的回归用例,再让它通过
69
+ pnpm build
70
+ pnpm verify:release
71
+ ```
72
+
73
+ 贡献遵循上游纪律:先写失败的回归用例;所有生产改动收敛在本仓库内;对“已触发”“已启用但跳过”“fail-open”分别给出证据。见 [CONTRIBUTING.md](CONTRIBUTING.md)。
74
+
75
+ ## 兼容性
76
+
77
+ - 仅使用公开的插件与 Profile API,针对 DeepSeek Harness `dsh-v0.1.1-rc.2` 验证;兼容官方 `dsh-v0.1.2-alpha.5` 版本。
78
+ - 需要 Node `^22.19.0 || >=24` 与 pnpm `11.7.0`。
79
+ - 插件只使用 Harness 公开扩展 API,不修改 Harness 核心代码。非官方社区项目,与 DeepSeek 无隶属或背书关系。
80
+
81
+ ## 致谢与许可
82
+
83
+ - 上游项目与全部既有工作:[WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector),作者 WilliamShi666(MIT)。
84
+ - fork 新增内容(代码骨架门、工具链、多语文档):drscrewdriver。
85
+ - MIT——见 [LICENSE](LICENSE)(保留上游版权声明);内置 tokenizer 来源见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。