kusesad-1122/dsh-context-compactor

DSH 上下文压缩/总结插件:80% 自动全局详细总结压缩(保留核心任务/决策/待解决问题/重要文件位置,删除调试细节与已解决错误),压缩后验保证 totalTokens 必须真实下降,context-overflow 自动恢复,/compact + /context-status,输入框上方一键按钮

Project Overview项目介绍

This is a context compression plugin built natively for DeepSeek Harness (DSH). It automatically triggers detailed summary compression of full conversation history when token usage reaches 80% of the model’s context window. This prevents conversations from failing when the maximum context length is exceeded. The plugin integrates DSH’s official dsh-compaction-basic compression engine and tool result pruner, mounting them in an isolated scope for each agent, and runs before any default compression engine to prioritize detailed summary compression. To install it, you first run the build script bash scripts/build.sh, then add it as a dependency to your DSH profile. A hot install can be done to activate it immediately without a full DSH restart.

The plugin enforces mandatory token verification before and after every compression to guarantee that the post-compression token count is strictly lower than the pre-compression count. It never performs "fake compression" that does not reduce token count. It also adapts to third-party providers that incorrectly report large context window sizes, which is a common issue with some modlens providers that overreport their available context. When a context overflow error is explicitly thrown by a provider, the plugin automatically compresses and retries the current request up to a configurable maximum number of retries. It can also automatically reduce the retained conversation tail and summary budget if the first compression attempt does not meet the token reduction requirement.

The plugin adds a toolbar with two buttons above the DSH conversation input box. One button triggers a manual compression, and the other enhances the prompt in the input box using the active DSH model, then writes the enhanced prompt back to the input box. The toolbar also displays the current context usage percentage in real time, and highlights it when the 80% threshold is crossed to warn users. The plugin also provides three manual commands: /compact to trigger manual compression, /enhance-prompt for prompt enhancement, and /context-status to check current token usage and settings. The summary of each compressed session is also automatically saved to a Markdown file in your DSH storage directory, and this feature can be disabled in the plugin configuration if needed.

这是一款原生的DSH上下文压缩插件,用于在会话token用量达到模型上下文窗口的80%时自动压缩总结对话历史,解决超过最大上下文长度导致对话失败的问题。它集成了DSH官方的dsh-compaction-basic压缩引擎和工具结果裁剪器,挂载到agent作用域内独立运行,抢在所有默认压缩引擎之前执行,保证详细总结压缩优先处理。

本插件支持多项实用功能:压缩前后必须进行token校验,保证压缩后token数一定小于压缩前,绝不做“假压缩”;适配了上报错误上下文窗口的第三方provider,上下文溢出时会自动重试压缩;能裁剪超大工具结果但不粗暴截断对话历史。输入框上方还添加了手动压缩和提示增强两个按钮,同时提供了三条可用手动命令。

安装本插件需要先运行构建脚本,再将其作为依赖添加到你的DSH配置profile中,重启DSH即可激活。也可以使用热注入命令让它立即生效,无需重启。安装完成后,输入框上方会自动出现包含两个按钮的工具条,实时显示上下文用量百分比,你还可以运行/context-status查看当前token用量、阈值和总结保存路径等信息。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 2 warnings2 项注意
  • No license declared - all rights reserved by default; ask the author before commercial use or redistribution未声明开源许可证 —— 默认「保留所有权利」,商用或再分发前先问作者
  • Only 3 stars - very few users, little community feedback星标只有 3,几乎没人在用,遇到问题缺少社区反馈
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:kusesad-1122/dsh-context-compactor

把 kusesad-1122/dsh-context-compactor 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-context-compactor

开箱即用的 上下文压缩 / 上下文总结 插件。它把 DSH 官方 dsh-compaction-basic 压缩引擎 + 工具结果裁剪器一次性装配进 profile,解决「对话满了不会自动压缩、模型 直接报 maximum context length 导致本轮失败」的问题。

功能

1. 80% 自动触发(总结最优先 + 压缩后验)

  • 通过 ctx.tokenMeter 估算当前会话 token 用量;
  • 达到模型窗口 80%(thresholdRatio 默认 0.8)时,下一步前自动先做详细总结: 把全部较早历史用 LLM 压缩成一份详尽中文 checkpoint,替换旧消息,只保留最近 retainRatio(默认 16%)的原样尾巴;
  • 本引擎的监听器以 prepend 注册,会抢在任何 preset 默认压缩引擎之前执行, 保证“总结最优先”且用的是详细版总结;
  • 压缩前后都有会话日志事件(compaction/start、compaction/summary、compaction/end)。

1.5 硬性保证:压缩必须真的变小

  • 每次压缩都会做 before/after 校验:压缩后 totalTokens 必须严格小于压缩前;
  • 自动压缩:
    • 目标 = 低于 80% 阈值(所以 80% → 必须 < 80%,不是“压完还是 80%”);
    • overflow 恢复:目标 = 低于压缩前;
    • 若第一次没达标,会自动逐级降保留尾巴(16% → 8% → 4% → 0%)并 逐级降总结预算(12288 → 6144 → 3072 → 1024)反复压缩全部较早历史;
  • 手动 /compact(包括按钮):同样做 before/after 校验;若总结反而变大, 自动降低总结预算重试,最多 4 次;仍不能下降就明确报错,绝不“假压缩”;
  • 日志会打印 before → after tokens(xx% reduced),方便确认真的压缩了。

1.6 真实上下文窗口(modlens / 第三方 provider 适配)

  • 部分 provider(如 modlens-qwen)会向 DSH 上报一个很大的 contextWindow (例如 1,000,000),但真实可用窗口只有 256k。这会导致阈值算错、永远“不到 80%”。
  • 插件现在的窗口解析顺序:
    1. modelPolicies[].contextWindow(显式覆盖,最优先);
    2. 会话请求头里 ≥100k 的 maxTokens(视为真实窗口兜底,如 256000);
    3. 适配器上报的 contextWindow(最后回退)。
  • 需要手动指定时,在 profile 的插件 config 里加:
modelPolicies:
  - provider: modlens-qwen
    model: DeepSeek-V4-Flash-0731
    contextWindow: 262144   # 按真实窗口填
    thresholdRatio: 0.8

2. 全局详细总结 + 双份保存

  • 全局,不是只压一段:每次触发都把“全部较早历史”(从最早消息到保留尾巴之前) 一次性做成一个全局 checkpoint;若历史里已有旧 checkpoint,会与本次新消息 全局合并——仍然成立的事实保留,已解决/过时的删除,相同内容只保留一份。
  • 总结严格按保留/删除策略执行:
    • 必须保留:① 核心任务与当前进度 ② 关键决策及理由 ③ 待解决问题 ④ 重要文件或代码位置(精确路径/函数/类位置,必要时保留简短关键片段);
    • 必须删除:详细调试过程(只留结论)、已解决的错误(不保留报错原文与排查过程)、 客套话与所有重复内容。
  • 保存 1:会话日志持久化 checkpoint 节点(可回放);
  • 保存 2:额外写 Markdown 到 ~/.dsh/storages/dsh-context-compactor/summaries/<session-id>.md(默认开启, 可关 saveSummaryFile: false);
  • 总结调用生成上限默认 maxTokens: 12288(详细预算,可调大)。

3. context-overflow 自动恢复(专治 context length 报错)

  • provider 明确报上下文超限时,先详细总结压缩,再自动 retry 本轮请求;
  • 默认最多连续恢复 maxOverflowRetries 次。

4. 超大工具结果裁剪(辅助手段,不替代总结)

  • 超过 pruneThresholdChars(默认 8192 字符)的工具输出,保留头 + 标记 + 尾;
  • 只裁剪工具结果文本,对话历史一律走详细总结,绝不粗暴截断。

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-tavily 下一个 Next dib →