Evidence snapshot reviewed Sep 9, 2026GitHub checked Aug 21, 2026
Evidence-verifiedPlugin BundleMemory & ContextWeb Profile

DSH Token Optimizer

A DeepSeek Harness plugin bundle for reducing long-session context and tool-output token payloads.

At a glance

What it does

A DeepSeek Harness plugin bundle for reducing long-session context and tool-output token payloads.

Use cases
Memory & ContextConfiguration
Works with
Deepseek HarnessDsh Web AppMCP
Compatibility

Web Profile
Not declared in supplied evidence

Trust & status

Evidence-verified
Checked Sep 6, 2026, 1:51 PM UTC

Code-evidenced contributions

What it adds to DSH

Model ToolsLayered token optimization pipeline

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.
Data handling
  • text2img and outputLadder are documented to save original content when saveOriginal is enabled.
  • A cache is documented with a default 3600-second TTL.
External services
  • 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.
Credentials
  • 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.

Visit the source project

Maintainer source

Project README

View at commit aca6c70
Maintainer-authored contentCaptured from README.md on Sep 6, 2026. The text and repository-relative media are fixed to commit aca6c7038d48 with content hash 47244c6e667a; provider-hosted badges may update independently. README commands are upstream documentation; the DSHub copy action above is the verified, version-pinned install.

dsh-token-optimizer

DeepSeek Harness 分层 Token 优化管道。在 DSH 已内置能力之外做真实增量: 把进入模型的文本压缩/裁剪/采样,降低 token 开销,不牺牲模型能力。

基于真实 DSH 插件 API(agent/pre-steptools/executetools/post-executeagent/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-metercompaction-basictool-result-prunerspillllm-retryrepeat-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-basiccommand-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
Verify
dsh plugin --profile web list

Compatibility and access

DeepSeek Harness DSH bundle; web profile setup is documented Not declared in supplied evidence

Review compatibility evidence

Risk facts

Tool Visibility

The bundled patch enables tool trimming and allows a specific list of file, shell, web, collaboration, GitHub, memory, and undo tools.

Evidence
External Api

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

AI reviewed

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 UTCGitHub facts last checked Sep 9, 2026, 1:56 PM UTC

No material source change has been recorded since this evidence baseline.

Next step

Follow the Plugin installation workflow

Subscribe to material changes for DSH Token Optimizer