giter00/dsh-headroom ↗★ 18

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开销的用户。

Package
dsh-headroom
Compatibility
Unverified
Harness peer range
>=0.0.1-rc.5 <0.1.0 || >=0.1.0-rc.1 <0.2.0-0
Cordis peer range
>=4.0.1-rc.4 <4.1.0 || >=4.1.0-rc.1 <5.0.0-0
Version
0.3.0
License
Apache-2.0
Last updated
Aug 23, 2026

Install

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:giter00/dsh-headroom

压力测试配置(更激进,用于验证压缩器上限)

node scripts/verify-compress.mjs 在 minChars=120, maxRows=40, maxCellChars=80, maxTextChars=400 下的结果:

样本类型压缩前(字符)压缩后(字符)节省
JSON 数组 200 行json62 4919 30285.1%
grep 结果 270 条search10 7724 60357.3%
日志 180 行log3 9091 12571.2%
CSV 201 行tabular19 8143 02984.7%
长文本 400 段text29 50654698.1%
Kompress 长文本(事实+重复词)text16 4392 02987.7%
代码code4934930%(故意不压)
短文本text19190%(未达阈值)

token 估算:脚本按 chars / 4 粗估,实际 token 与模型 tokenizer 相关。 所有有损压缩均保存原文,headroom_retrieve 可精确取回。 Kompress 样本:关键事实(HTTP/500/hex/路径/IndexError)全部保留, 重复的 boilerplatephrase 被删除且可从 CCR 恢复。

默认配置

默认配置更保守(minChars=4000, maxRows=80, maxCellChars=200, maxTextChars=2400):

样本类型节省
JSON 数组 200 行json65.6%
grep 结果 90 条search41.3%
日志 180 行log56.8%
CSV 201 行tabular59.8%
长文本 400 段text94.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
字段默认值说明
enabledtrue总开关
minChars600文本块至少多少字符才考虑压缩
maxRows80JSON 透视保留的最大行数
maxCellChars200JSON 单元格字符串截断长度(search 匹配行保持全文)
maxSearchMatchesPerFile60每个文件保留的搜索命中数
maxLogLines80日志保留的首尾行数
maxTextChars2400长文本首尾保留字符数(head-tail 策略)
maxTabularLines80表格保留的首尾行数
excludeTools[]* 通配符;命中的工具不压缩
noFoldForTools['read','str_replace_editor','edit','write']文件内容类工具永不压缩,避免 read→edit 快照不一致
noFoldForPatterns['*.js','*.ts','*.json','*.yml','*.yaml']匹配到的文件路径/工具名不压缩;保护源码与配置文件
markerStyle'full'full=保留策略/节省量与 headroom_retrieve 提示;compact=只保留 id="hr:…",减少标记噪音
includeErrorsfalse是否压缩工具错误输出
textStrategy'auto'长文本策略:auto=Kompress 优先、无收益回退 head-tail;kompress=仅 Kompress;head-tail=仅首尾截断
kompress.enabledtruefalse 时文本走 head-tail
kompress.minWords10少于该词数的文本跳过(与 Headroom 一致)
kompress.chunkWords350每块词数(Kompress-v2-base 训练口径,与模型耦合)
kompress.scoreThreshold0.5保留阈值:score > 阈值 才保留(与 Headroom 默认一致)
kompress.targetRationull强制保留比例(按分数取 top-k);null 用阈值决策
kompress.mustKeeptrue语义脆弱词(数字/hex/全大写/路径/扩展名/flag/CamelCase)强制保留
kompress.maxWordChars64超过该长度的词(如无空格中文长串)细分后评分
ccr.enabledtrue关闭后不进行有损压缩
ccr.persisttrue是否持久化 CCR store
ccr.ttlMs86400000原始内容保留时长(毫秒)
ccr.maxEntries2000内存/持久化 store 最大条目数