At a glance
What it does
A DeepSeek Harness plugin bundle for reducing long-session context and tool-output token payloads.
Web Profile
Not declared in supplied evidence
Evidence-verified
Checked Sep 6, 2026, 1:51 PM UTC
Code-evidenced contributions
What it adds to DSH
Compresses or reduces selected context and tool-result payloads, tracks cache use, and can trigger compaction during long DSH sessions.
Mechanism evidence ↗Before you choose it
This bundle mounts dsh-token-optimizer in DeepSeek Harness. Its documented modules can summarize very long natural-language input through a vision workflow, compress large tool outputs, collapse repeated file reads into diffs, lazily expose MCP tools, drive compaction, and report cache and session savings.
Best for
DeepSeek Harness users managing long, tool-heavy sessions who want configurable context reduction and can review profile-level plugin settings.
Common tasks
- Reduce large shell, CSV, JSON-array, and error-result payloads before they remain in context.
- Avoid resending unchanged file content by using repeated-read collapse or changed-section diffs.
- Configure MCP lazy loading so unused MCP tool schemas do not enter requests.
- Enable a compaction driver for long web-profile sessions after restoring the required core compaction backend.
Permissions and data
The plugin processes agent context and tool outputs; optional modules can retain originals and contact an external API.
Permissions- Can process natural-language context, tool outputs, and repeated file-read results.
- The supplied bundle patch configures an allowlist for visible tools, including file, PowerShell, web search, collaboration, GitHub, memory, and undo tools.
- text2img and outputLadder are documented to save original content when saveOriginal is enabled.
- A cache is documented with a default 3600-second TTL.
- Optional text2img summarization uses the configured DeepSeek API endpoint.
- Optional MCP lazy loading requires a configured DSH MCP client and at least one MCP server.
- DEEPSEEK_API_KEY is required for text2img summarization.
Limitations
- The README’s token-saving figures are author-reported and were not independently verified in the supplied evidence.
- On non-Windows systems, text2img rendering falls back to saving the original text only.
- For web deployments, compactionDriver does not work until compaction-basic and command-compact are re-enabled in the profile.
- MCP lazy loading is a no-op when no MCP server is configured.
What DSHub checked
- The package manifest identifies version 2.0.0, MIT license, an ES module entry point, and a DSH bundle patch.
- The pinned source has a verified Git bundle delivery path and verified bundle structure.
- The bundle patch mounts a token-optimizer plugin configuration.
What DSHub did not check
- Installation was not executed.
- The smoke tests and end-to-end test were not run.
- Runtime compatibility with a particular DeepSeek Harness version was not established.
- Reported token savings and cache-hit rates were not independently reproduced.
Pinned install
Install DSH Token Optimizer
This plugin bundle does not have a DSH Plugin install action. Use its source documentation for the delivery method.
Maintainer source
Project README
dsh-token-optimizer
DeepSeek Harness 分层 Token 优化管道。在 DSH 已内置能力之外做真实增量: 把进入模型的文本压缩/裁剪/采样,降低 token 开销,不牺牲模型能力。
基于真实 DSH 插件 API(agent/pre-step、tools/execute、tools/post-execute、agent/status 等)实现,
与社区方案文档中虚构的事件(如 message:before / context:building)无关。
它做什么(30 秒版)
| 模块 | 钩子 | 作用 |
|---|---|---|
| text2img | agent/pre-step |
超长自然语言文本(>5000 字符)→ 渲染成图 → vision 读图 → 摘要替换进上下文。单次样本曾省 ~72%;真正价值是长会话越省(后续轮次不再携带原文)。JSON/代码自动跳过 |
| outputLadder | tools/post-execute |
工具输出出生点单次遍历分流:错误结果→300 字符摘要;JSON 数组/CSV(≥10k 字符)→结构感知压缩;shell 输出(≥8k 字符)→头尾+等距采样;≥50k 字节交核心 spill;read 类豁免。原文落盘可逆 |
| fileDiff | tools/post-execute |
重复读文件:未变→折叠标记;有变→只发变更区段 diff |
| toolTrim | agent/created |
工具可见性管理:静态裁剪 + MCP 懒加载——不用的 mcp__* 工具 schema 不进请求(实测省 ~9.4k token/请求) |
| compactionDriver | agent/status |
agent idle 时按自定义压力比(默认 45%)驱动核心 compactNow,让长会话压缩真正发生(核心 0.8 阈值对 1M 窗口几乎永不触发) |
| monitor | session/disposed |
会话结束输出节省统计 + 真实 usage 聚合与缓存命中率(长会话常态 97%–99.3%) |
与 DSH 核心的边界
DSH 已内置 token-meter、compaction-basic、tool-result-pruner、spill、llm-retry、repeat-tool-reminder——
本插件一律不重复实现,只做上面这些内置之外的增量。
安装
dsh plugin --profile web add ./dsh-token-optimizer
卸载:
dsh plugin --profile web remove dsh-token-optimizer
配置
挂载后在 profile 的 cordis.patch.yml 中覆盖(示例,均为默认值):
- id: token-optimizer
name: 'dsh-token-optimizer'
config:
text2img:
enabled: true
threshold: 5000
pageFontSize: 24
pageMaxHeight: 3000
visionModel: 'deepseek-v4-flash-vision-exp'
baseUrl: 'https://api.deepseek.com/v1'
maxSummaryChars: 2000
saveOriginal: true
askOnSkip: true
outputLadder:
enabled: true
structureThreshold: 10000
compressionRate: 0.5
preserveHeadTail: 1000
shellTools: ['pwsh', 'bash', 'sh', 'powershell', 'zsh', 'cmd']
shellThreshold: 8000
headLines: 10
tailLines: 10
sampleInterval: 20
errorSummaryChars: 300
spillBytes: 50000
readTools: ['read', 'read_image']
saveOriginal: true
cache:
enabled: true
ttl: 3600
fileDiff:
enabled: true
tools: ['read']
minSize: 2048
maxFileBytes: 200000
contextLines: 3
collapseUnchanged: true
toolTrim:
enabled: false # 默认关闭;启用后对每个 agent 作用域生效
allow: []
deny: []
mcpLazy: true
mcpPrefix: 'mcp__'
mcpLoadToolName: 'mcp_load_tools'
compactionDriver:
enabled: true
pressureRatio: 0.45 # totalTokens / contextWindow 超过该比才触发
minTurns: 6
minTokens: 100000
maxCompactionsPerSession: 3
contextWindow: 1000000
timeoutMs: 120000
v1 的
compress/sample/pruning/dedup节已退役(合并进 outputLadder),旧配置节会被静默忽略并在日志提示,不会导致加载失败。
web 部署必读:重新启用核心压缩后端
dsh-web-app 的 bundle patch 默认禁用了 compaction-basic 与 command-compact(配合 /compact 命令),
web 部署因此没有 compaction 服务,compactionDriver 会静默不生效。在 profile 的 cordis.patch.yml 顶层补:
- id: compaction-basic
disabled: false
- id: command-compact
disabled: false
依赖
- text2img 渲染:Windows 需 PowerShell + .NET System.Drawing(
scripts/render-text.ps1,免第三方依赖);非 Windows 渲染降级为仅落盘原文。 - text2img 摘要:需
DEEPSEEK_API_KEY环境变量(DSH 已配置)。 - mcpLazy:需 profile 挂载
@deepseek-ai/dsh-mcp-client并配置至少一个 MCP 服务器;无 MCP 时自动 no-op。
开发
node test/smoke.mjs # 单进程全量自检(无需 API),npm test 同
node --test test/modules.test.js
node test/text2img-e2e.mjs # 真实端到端(需 API key + Windows 渲染)
路线图
- 自然语言配置工具(让模型改配置)
- 长文本→图片的跨平台渲染 fallback
- 与 dsh-behavior-enhancer 协同(内容压缩 × 行为管理,可独立安装)
Operate deliberately
Install and manage
Prerequisites and target Profile
Target: Web Profile
Delivery: Dsh Bundle Git — Liora2050348900/dsh-token-optimizer#aca6c7038d48df53c2452fed82de471a58e773a6。
Verify, update, and remove
Show lifecycle commands
dsh plugin --profile web listCompatibility and access
DeepSeek Harness DSH bundle; web profile setup is documented: Not declared in supplied evidence。
Review compatibility evidence ↗
Risk facts
The bundled patch enables tool trimming and allows a specific list of file, shell, web, collaboration, GitHub, memory, and undo tools.
Evidence ↗The optional text-to-image summary feature requires DEEPSEEK_API_KEY and sends work to the configured DeepSeek API endpoint.
Evidence ↗Evidence and editorial reviewManifest, Bundle patch, distribution and freshness
Immutable evidence
Review status and source activity
Review the profile patch before installation, especially its enabled tool-trimming allowlist and any settings that retain original content or use the DeepSeek API.
AI reviewed Sep 9, 2026, 1:56 PM UTC。GitHub facts last checked Sep 9, 2026, 1:56 PM UTC。
No material source change has been recorded since this evidence baseline.