giter00/dsh-headroom

工具输出在进入模型之前先被压缩:JSON、搜索、日志、表格与长文本各自走专用压缩器; 所有有损压缩都会把原文存入本地 CCR store,并在压缩结果里注入一个短 marker, 模型需要精确原文时调用 headroomretrieve(id=…) 即可逐字节取回。

catalog descriptioncatalog 简介 / catalog description:deepSeek harness上下文压缩工具

Project Overview项目介绍

This is a native DeepSeek Harness plugin that automatically compresses tool output context before it is saved to the agent's session history. It hooks into DSH's tools/post-execute event, runs after tool execution completes and before results are finalized. It sorts output into different content types and routes each to a dedicated compressor. All lossy compression saves the full original output to a local CCR store and injects a marker into the compressed result. When the agent needs the full original content, it can call the headroom_retrieve tool with the provided ID to get the exact original bytes back.

It includes custom compression strategies for JSON, search output, logs, tables, long text, code, and file tools. By default, it skips compression for code and file tool outputs to preserve patchability and line number accuracy. For long text, it uses a Kompress-style word-level scoring pipeline that forces retention of semantically critical tokens like paths, numbers, and flags. Users can configure it to use a head-tail truncation fallback for text, or enable the official ONNX-formatted Kompress-v2-base model for ML-powered scoring. It also ships three extra tools for manual use.

The plugin runs entirely on JavaScript and Node.js built-in modules by default, so it has no native compilation dependencies and works across Windows, macOS, and Linux. To use the official ONNX model, you need to install two optional dependencies: onnxruntime-node and @huggingface/transformers. If the dependencies or model are missing, the plugin automatically falls back to a deterministic heuristic scorer and issues a warning. DSH users can install it directly via the DSH plugin manager with no extra build steps. It is released under the open-source Apache-2.0 license.

这是专为 DeepSeek Harness 开发的原生上下文自动压缩插件,设计思路参考开源 Headroom 项目。插件挂载到 DSH 的 tools/post-execute 钩子,在工具执行完成后、结果存入会话上下文之前,对工具输出分类路由并调用专用压缩器处理。所有有损压缩都会将原文存入本地 CCR 存储,并在压缩结果中注入标记,模型需要完整原文时可调用 headroom_retrieve 工具逐字节取回。

它针对 JSON、搜索结果、日志、表格、长文本、代码等不同内容类型提供了定制压缩策略,默认对代码和文件工具输出不压缩。长文本默认采用 Kompress 风格逐词评分压缩,语义关键内容强制保留,支持切换为头尾截断策略,也可启用真实的 ONNX 格式 Kompress-v2-base 模型做评分。还提供了 headroom_stats 查看压缩统计、headroom_compress 压缩任意自定义文本。

默认配置下仅依赖纯 JavaScript 和 Node 内置模块,无原生编译依赖,跨 Windows、macOS、Linux 全平台可用。启用真实 ONNX 模型压缩需要额外安装 onnxruntime-node 和 @huggingface/transformers,未安装或模型缺失时自动回退到启发式压缩。项目采用 Apache-2.0 许可证开源,是 Headroom 的衍生合规项目。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 note1 项提示
  • 16 stars - an early-stage project星标 16,属于早期项目
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin --profile web add github:giter00/dsh-headroom

把 giter00/dsh-headroom 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-headroom

适配 DeepSeek Harness (dsh) 的上下文自动压缩插件,思路参考 Headroom。

工具输出在进入模型之前先被压缩:JSON、搜索、日志、表格与长文本各自走专用压缩器; 所有有损压缩都会把原文存入本地 CCR store,并在压缩结果里注入一个短 marker, 模型需要精确原文时调用 headroom_retrieve(id=…) 即可逐字节取回。

 tool body settles
        │
        ▼
 tools/post-execute   ← dsh-headroom 在此压缩
        │
        ▼
 tool/result 进入 session log / 模型历史(压缩后内容 + CCR marker)
        │
        ▼
 模型需要原文时调用 headroom_retrieve(id=…)

特性

  • 自动压缩工具输出:挂载 tools/post-execute,在工具结果物化之前替换文本内容。

  • 内容路由,专用压缩器:

    内容类型 压缩策略
    JSON 数组/对象 SmartCrusher 风格透视:_keys + _rows + _common,长单元格截断
    grep/ripgrep 结果 按文件折叠:file (N matches) + line[:col]: rest
    构建/测试/日志 连续重复行折叠 + 保留 error/fail/exception/assert 上下文
    CSV/TSV/markdown 表格 保留表头与首尾行,中间行 offload
    长文本 Kompress 风格 ML 压缩(默认):逐词打分 + must-keep 保护 + CCR 可逆取回;textStrategy: 'head-tail' 可切回首尾截断
    代码 默认不压缩(JS 端口不做 AST 压缩,避免破坏可补丁字节;read/str_replace_editor 的行号前缀会先剥离再识别)
    文件工具 默认不压缩(read/str_replace_editor/edit/write 及其匹配 *.js/*.ts/*.json/*.yml 的路径)

Kompress 文本压缩(参考 Headroom 的 Kompress-v2-base ML 模型): 文本按词切分 → 每词打分(score = keep概率 × (0.5 + 0.5 × span分数),模拟模型的 token 分类头 + span CNN 双头)→ score > 0.5 保留(或 targetRatio 取 top-k)→ 数字 / hex / 全大写标识符 / 路径 / 扩展名 / CLI flag / CamelCase 等语义脆弱词强制保留 → 保留词重组。默认评分器是确定性纯 JS 启发式;也可启用真实 Kompress-v2-base ONNX 模型打分(kompress.scorer: 'onnx',见下文「真实模型压缩」)。

  • 可逆压缩(CCR):所有有损压缩都保存原文,headroom_retrieve 按 id 精确取回; headroom_stats 查看节省量;headroom_compress 压缩任意文本。
  • 持久化:CCR store 默认写入 <DSH_HOME>/storages/dsh-headroom-ccr.json (1 秒去抖、原子替换、TTL + 最大条目数可配)。
  • 无害跳过:短文本、代码、错误输出、excludeTools 命中的工具、本插件自身工具 都不会被压缩。
  • 跨平台:纯 JavaScript + Node 内置模块,无原生编译依赖;路径全部通过 node:path 处理,DSH_HOME 支持环境变量覆盖,Windows / macOS / Linux 行为一致。 CI 矩阵见 .github/workflows/ci.yml。

实现方式

flowchart LR
  A[ToolRuntime 工具执行完成] --> B[tools/post-execute]
  B --> C{文本块总长 >= minChars?}
  C -- 否 --> Z[原样返回]
  C -- 是 --> D[ContentRouter 类型检测]
  D --> E[json] --> E1[SmartCrusher 透视]
  D --> F[search] --> F1[按文件折叠]
  D --> G[log] --> G1[重复折叠 + 错误保留]
  D --> H[tabular] --> H1[首尾行保留]
  D --> I[text] --> I1[Kompress 逐词打分 + must-keep 保护]
  I1 -. 无收益 .-> I2[回退首尾截断]
  D --> J[code] --> Z
  E1 & F1 & G1 & H1 & I1 & I2 --> K{压缩后 + marker 更小?}
  K -- 否 --> Z
  K -- 是 --> L[写入 CCR store]
  L --> M[替换 decision.content]
  M --> N[模型看到压缩内容 + headroom_retrieve marker]

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-hub-plugin 下一个 Next dsh-mobile-hanui →