dsh-headroom
Headroom-inspired automatic context compression plugin for DeepSeek Harness (dsh): compresses tool outputs before they reach the model and keeps every lossy compression reversible via CCR retrieval tools.
安装
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:giter00/dsh-headroom说明文档
阅读完整 README ↗压力测试配置(更激进,用于验证压缩器上限)
node scripts/verify-compress.mjs 在 minChars=120, maxRows=40, maxCellChars=80, maxTextChars=400 下的结果:
| 样本 | 类型 | 压缩前(字符) | 压缩后(字符) | 节省 |
|---|---|---|---|---|
| JSON 数组 200 行 | json | 62 491 | 9 302 | 85.1% |
| grep 结果 270 条 | search | 10 772 | 4 603 | 57.3% |
| 日志 180 行 | log | 3 909 | 1 125 | 71.2% |
| CSV 201 行 | tabular | 19 814 | 3 029 | 84.7% |
| 长文本 400 段 | text | 29 506 | 546 | 98.1% |
| 代码 | code | 493 | 493 | 0%(故意不压) |
| 短文本 | text | 19 | 19 | 0%(未达阈值) |
token 估算:脚本按
chars / 4粗估,实际 token 与模型 tokenizer 相关。 所有有损压缩均保存原文,headroom_retrieve可精确取回。
默认配置
默认配置更保守(minChars=600, maxRows=80, maxCellChars=200, maxTextChars=2400):
| 样本 | 类型 | 节省 |
|---|---|---|
| JSON 数组 200 行 | json | 65.6% |
| grep 结果 90 条 | search | 41.3% |
| 日志 180 行 | log | 56.8% |
| CSV 201 行 | tabular | 59.8% |
| 长文本 400 段 | text | 94.7% |
配置
在 profile 的 cordis.patch.yml(或 --patch 覆盖层)中可覆盖默认配置:
- id: dsh-headroom
config:
enabled: true
minChars: 600
maxRows: 80
maxCellChars: 200
maxSearchMatchesPerFile: 60
maxLogLines: 80
maxTextChars: 2400
maxTabularLines: 80
excludeTools: []
includeErrors: false
ccr:
enabled: true
persist: true
ttlMs: 86400000
maxEntries: 2000
| 字段 | 默认值 | 说明 |
|---|---|---|
enabled | true | 总开关 |
minChars | 600 | 文本块至少多少字符才考虑压缩 |
maxRows | 80 | JSON 透视保留的最大行数 |
maxCellChars | 200 | JSON/search 单元格字符串截断长度 |
maxSearchMatchesPerFile | 60 | 每个文件保留的搜索命中数 |
maxLogLines | 80 | 日志保留的首尾行数 |
maxTextChars | 2400 | 长文本首尾保留字符数 |
maxTabularLines | 80 | 表格保留的首尾行数 |
excludeTools | [] | * 通配符;命中的工具不压缩 |
includeErrors | false | 是否压缩工具错误输出 |
ccr.enabled | true | 关闭后不进行有损压缩 |
ccr.persist | true | 是否持久化 CCR store |
ccr.ttlMs | 86400000 | 原始内容保留时长(毫秒) |
ccr.maxEntries | 2000 | 内存/持久化 store 最大条目数 |