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. 适合频繁处理长文本或大批量工具输出、需要节省Token开销的用户。
インストール
$
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% |
| Kompress 长文本(事实+重复词) | text | 16 439 | 2 029 | 87.7% |
| 代码 | code | 493 | 493 | 0%(故意不压) |
| 短文本 | text | 19 | 19 | 0%(未达阈值) |
token 估算:脚本按
chars / 4粗估,实际 token 与模型 tokenizer 相关。 所有有损压缩均保存原文,headroom_retrieve可精确取回。 Kompress 样本:关键事实(HTTP/500/hex/路径/IndexError)全部保留, 重复的boilerplatephrase被删除且可从 CCR 恢复。
默认配置
默认配置更保守(minChars=4000, 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: []
noFoldForTools: ['read', 'str_replace_editor', 'edit', 'write']
noFoldForPatterns: ['*.js', '*.ts', '*.json', '*.yml', '*.yaml']
markerStyle: full # full | compact
includeErrors: false
textStrategy: auto # auto | kompress | head-tail
kompress:
enabled: true
minWords: 10
chunkWords: 350
scoreThreshold: 0.5
targetRatio: null # null=阈值决策;0.3=强制保留 30% 最高分词
mustKeep: true
maxWordChars: 64
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 | 长文本首尾保留字符数(head-tail 策略) |
maxTabularLines | 80 | 表格保留的首尾行数 |
excludeTools | [] | * 通配符;命中的工具不压缩 |
noFoldForTools | ['read','str_replace_editor','edit','write'] | 文件内容类工具永不压缩,避免 read→edit 快照不一致 |
noFoldForPatterns | ['*.js','*.ts','*.json','*.yml','*.yaml'] | 匹配到的文件路径/工具名不压缩;保护源码与配置文件 |
markerStyle | 'full' | full=保留策略/节省量与 headroom_retrieve 提示;compact=只保留 id="hr:…",减少标记噪音 |
includeErrors | false | 是否压缩工具错误输出 |
textStrategy | 'auto' | 长文本策略:auto=Kompress 优先、无收益回退 head-tail;kompress=仅 Kompress;head-tail=仅首尾截断 |
kompress.enabled | true | false 时文本走 head-tail |
kompress.minWords | 10 | 少于该词数的文本跳过(与 Headroom 一致) |
kompress.chunkWords | 350 | 每块词数(Kompress-v2-base 训练口径,与模型耦合) |
kompress.scoreThreshold | 0.5 | 保留阈值:score > 阈值 才保留(与 Headroom 默认一致) |
kompress.targetRatio | null | 强制保留比例(按分数取 top-k);null 用阈值决策 |
kompress.mustKeep | true | 语义脆弱词(数字/hex/全大写/路径/扩展名/flag/CamelCase)强制保留 |
kompress.maxWordChars | 64 | 超过该长度的词(如无空格中文长串)细分后评分 |
ccr.enabled | true | 关闭后不进行有损压缩 |
ccr.persist | true | 是否持久化 CCR store |
ccr.ttlMs | 86400000 | 原始内容保留时长(毫秒) |
ccr.maxEntries | 2000 | 内存/持久化 store 最大条目数 |