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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.ja.md +226 -220
  2. package/CHANGELOG.ko.md +220 -214
  3. package/CHANGELOG.md +366 -376
  4. package/CHANGELOG.zh.md +204 -199
  5. package/README.ja.md +85 -85
  6. package/README.ko.md +85 -85
  7. package/README.md +98 -97
  8. package/README.zh.md +85 -86
  9. package/eslint.config.js +30 -76
  10. package/package.json +53 -55
  11. package/packages/selector/dsh.plugin.json +2 -2
  12. package/packages/selector/lib/{intent-gate.js → advisor-state.js} +3 -91
  13. package/packages/selector/lib/client.js +3 -14
  14. package/packages/selector/lib/index.js +1 -92
  15. package/packages/selector/lib/profiles.d.ts +0 -9
  16. package/packages/selector/lib/pruner.d.ts +0 -59
  17. package/packages/selector/lib/pruner.js +7 -410
  18. package/packages/selector/lib/style.css +46 -46
  19. package/packages/selector/package.json +114 -114
  20. package/packages/selector/src/client/decode.ts +2 -6
  21. package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
  22. package/packages/selector/src/index.ts +411 -418
  23. package/packages/selector/src/preset-overlay.ts +0 -3
  24. package/packages/selector/src/profiles.ts +10 -30
  25. package/packages/selector/src/pruner/content.ts +1 -1
  26. package/packages/selector/src/pruner/state.ts +0 -7
  27. package/packages/selector/src/pruner.ts +9 -253
  28. package/packages/selector/src/runtime/audit.ts +0 -17
  29. package/packages/selector/src/runtime/config.ts +11 -36
  30. package/packages/selector/src/runtime/reducers.ts +1 -1
  31. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +1 -46
  32. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -55
  33. package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
  34. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +1 -4
  35. package/packages/selector/src/runtime/types.ts +0 -12
  36. package/packages/selector/tests/auto-compact.client.spec.tsx +213 -214
  37. package/packages/selector/tests/built/client-artifact.spec.ts +59 -61
  38. package/packages/selector/tests/code-skeleton.client.spec.ts +93 -94
  39. package/packages/selector/tests/custom-contract.client.spec.ts +222 -223
  40. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  41. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
  42. package/packages/selector/tests/preset-options-write.client.spec.ts +187 -188
  43. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
  44. package/packages/selector/tests/profiles.client.spec.tsx +434 -436
  45. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  46. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
  47. package/packages/selector/tests/runtime/audit.spec.ts +274 -275
  48. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
  49. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
  50. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2736
  51. package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
  52. package/pnpm-workspace.yaml +66 -66
  53. package/scripts/packed-components-smoke.mjs +0 -2
  54. package/scripts/packed-install-e2e.mjs +5 -7
  55. package/scripts/verify-release.mjs +2 -3
  56. package/tsconfig.tests.json +1 -3
  57. package/vitest.config.ts +0 -14
  58. package/packages/selector/src/runtime/summary-command.ts +0 -133
  59. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  60. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  61. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  62. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  63. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  64. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  65. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
package/README.ko.md CHANGED
@@ -1,85 +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
- ## 설정 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`로 게시되어 있습니다(0.1.7 라인은 dist-tag `dsh-0.1.7`, 0.1.5 라인은 `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
- - 공식 DeepSeek Harness `dsh-v0.1.7-rc.2` 릴리스 기준으로 빌드·테스트되었습니다. peers는 `>=0.1.7-rc.1 <0.2.0-0`를 선언하며 공개된 플러그인 및 프로파일 API만 사용합니다. 이전 Harness 라인은 각자의 dist-tag(`dsh-0.1.5`, `dsh-0.1.2`)로 계속 제공됩니다.
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).
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`로 게시되어 있습니다(0.2.0 라인은 dist-tag `dsh-0.2.0`, 0.1.7 라인은 `dsh-0.1.7`, 0.1.5 라인은 `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
+ - 공식 DeepSeek Harness `dsh-v0.2.0-rc.1` 릴리스 기준으로 빌드·테스트되었습니다. peers는 `>=0.2.0-rc.1 <0.2.1-0`를 선언하며 공개된 플러그인 및 프로파일 API만 사용합니다. 이전 Harness 라인은 각자의 dist-tag(`dsh-0.1.7`, `dsh-0.1.5`, `dsh-0.1.2`)로 계속 제공됩니다.
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,97 +1,98 @@
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
+ > - 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.2.0` for the 0.2.0 line (this branch), `dsh-0.1.7` for the 0.1.7 line, `dsh-0.1.5` for the 0.1.5 line, `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.2.0
54
+ # DSH 0.1.7 line:
55
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.7
56
+ # DSH 0.1.5 line:
57
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.5
58
+ # DSH 0.1.2 line:
59
+ # dsh plugin --profile web add dsh-context-compression-improved@dsh-0.1.2
60
+ dsh --profile web --dump-config
61
+ ```
62
+
63
+ From source (alternative — the internal package names intentionally stay upstream's):
64
+
65
+ ```sh
66
+ git clone https://github.com/drscrewdriver/dsh-context-compression-improved.git
67
+ cd dsh-context-compression-improved
68
+ pnpm install --frozen-lockfile
69
+ pnpm build
70
+ ```
71
+
72
+ 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).
73
+
74
+ ## Development
75
+
76
+ ```sh
77
+ pnpm install --frozen-lockfile
78
+ pnpm lint # ESLint baseline (also enforced in CI)
79
+ pnpm typecheck # runtime + selector + tests tsc, plus the bundle step
80
+ pnpm test # full vitest suite
81
+ pnpm test:watch # TDD loop: write the failing regression first, then make it pass
82
+ pnpm build
83
+ pnpm verify:release
84
+ ```
85
+
86
+ 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).
87
+
88
+ ## Compatibility
89
+
90
+ - Built and tested against the official DeepSeek Harness `dsh-v0.2.0-rc.1` release; peers declare `>=0.2.0-rc.1 <0.2.1-0` and the plugin uses public plugin and profile APIs only. Earlier lines remain served from their own dist-tags (`dsh-0.1.7`, `dsh-0.1.5`, `dsh-0.1.2`).
91
+ - Requires Node `^22.19.0 || >=24` and pnpm `11.7.0`.
92
+ - 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.
93
+
94
+ ## Credits and license
95
+
96
+ - Upstream project and all prior work: [WilliamShi666/dsh-context-compression-selector](https://github.com/WilliamShi666/dsh-context-compression-selector) by WilliamShi666 (MIT).
97
+ - Fork additions (code-skeleton gate, tooling, localized docs): drscrewdriver.
98
+ - 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,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
- > - **回合末意图摘要**(`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
+ > - 正交的**代码骨架压缩门**(`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`(0.2.0 线使用 dist-tag `dsh-0.2.0`,0.1.7 线使用 `dsh-0.1.7`,0.1.5 线使用 `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
+ - 基于官方 DeepSeek Harness `dsh-v0.2.0-rc.1` 发布版构建并测试;peers 声明 `>=0.2.0-rc.1 <0.2.1-0`,仅使用公开的插件与 Profile API。更早的 Harness 线由各自的 dist-tag(`dsh-0.1.7`、`dsh-0.1.5`、`dsh-0.1.2`)继续服务。
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)。