DeepSeek Harness Plugin Hub

Publish and manage complete Harness Profiles. Discover Plugins for your next setup.

Explore

PluginsPresetsDocsNews

Community

Publish a pluginContactReport an issue

Resources

Plugin Hub on GitHubDeepSeek HarnessSystem statusPrivacy notice
© 2026 DeepSeek Harness Plugin HubPowered byPaxTech

Independent and unofficial. Not affiliated with, authorized by, or endorsed by DeepSeek.

Token Optimizer — DSH Plugin for DeepSeek Harness
DeepSeek Harness Plugin Hub
ProfilesPluginsCategoriesNewsDocsSign inManage Profiles
ProfilesPluginsCategoriesNewsDocsSign in
← Plugins

@zoria-lind/dsh-token-optimizer

Token Optimizer

Layered Token Optimization Pipeline v2: tiered output / result caching / file diff / tool pruning + MCP lazy loading / compression scheduling / cache hit rate, based on the real DSH plugin API

The plugin will be installed here. Keep web if you are unsure.

npx -y @deepseek-ai/dsh plugin --profile web add @zoria-lind/dsh-token-optimizer@2.2.0
READMECompatibilityVersions

Compatibility and provenance

Token Optimizer is published as @zoria-lind/dsh-token-optimizer and currently resolves to version 2.2.0. The Hub verifies its manifest and preserves the exact installation source for reproducible installs.

DSH compatibility
*
Runtime surfaces
any
Release source
npm
Registry updated
9/15/2026

Versions

2.2.0stable
9/15/2026

Related plugins

Loading related plugins…

Latest
2.2.0
DSH
*
HMR
Process restart
Tree shaking
Safe tree shaking not declared
Unpacked size
125.8 kB
Files
17
Surface
any
License
MIT
Source
npm
GitHub
★ 15
Weekly downloads
0
Last push
9/17/2026
View source ↗
README badge

Click the badge to copy Markdown for your README.

Do you maintain this Plugin?Claim benefit · Priority security scan

Verify the GitHub repository declared in package.json to manage this listing. After you claim it, Hub will prioritize a security scan of the current version and publish the result when it passes.

Claim this Plugin →
Report an issue

Related plugins

More verified plugins in models-usage.

Whale Widgetdsh-whale-widgetDeepSeek balance whale widget in the bottom-right corner of the DSH Web interface: balance/today’s usage/peak-off-peak pricing, customizable bubble click sequence (text/balance/today/peak-off-peak/image/random phrases and parallel weighted selection), per-line styles and fonts, floating quick editinUsage Stats@ychris12138/dsh-usage-statsToken usage heatmap, provider balances, and subscription quotas for the dsh web GUICodex Connectdsh-codex-connectChatGPT OAuth and Codex models for DeepSeek Harness.Ui Usage Billing@kenz1117/dsh-ui-usage-billingUsage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.

README

dsh-token-optimizer

v2.2 变更摘要:新增分层压缩编排 layeredCompact(L0 观测 / L1 toolResultPruner 无损 / L2 compactNow 有损,默认关,启用即旁路旧 compactionDriver)、/token-status 状态命令、outputLadder/fileDiff 基线重建缺陷修复(T7,以 decision.content ?? result.content 为基线 + 透传 additionalContexts)、错误按 err.code 分类记账、统计按会话分桶与 token/金额估算。

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

基于真实 DSH 插件 API(agent/pre-step、tools/execute、tools/post-execute、agent/status 等)实现, 与社区方案文档中虚构的事件(如 message:before / context:building)无关。

它做什么(30秒知)

模块钩子作用
text2imgagent/pre-step长文本(≥1000 字符)→ 弹窗询问(转图摘要 / 直接阅读原文,推荐项与超时默认按内容类型定)→ 渲染成图 → vision 读图 → 摘要替换进上下文。动态分辨率分档(640×360 / 1280×720 / 1920×1080),摘要磁盘缓存跨会话 0 API 调用。单次样本曾省 ~72%;真正价值是长会话越省(后续轮次不再携带原文)
outputLaddertools/post-execute工具输出出生点单次遍历分流:错误结果→300 字符摘要;JSON 数组/CSV(≥10k 字符)→结构感知压缩;shell 输出(≥8k 字符)→头尾+等距采样;≥50k 字节交核心 spill;read 类豁免。原文落盘可逆
fileDifftools/post-execute重复读文件:未变→折叠标记;有变→只发变更区段 diff
toolTrimagent/created工具可见性管理:静态裁剪 + MCP 懒加载——不用的 mcp__* 工具 schema 不进请求(实测省 ~9.4k token/请求)
compactionDriveragent/statusagent idle 时按自定义压力比(默认 45%)驱动核心 compactNow,让长会话压缩真正发生(核心 0.8 阈值对 1M 窗口几乎永不触发)
monitorsession/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: 1000
      askOnSkip: true        # false = 不弹窗,回退自动行为(自然语言自动转图/结构性强跳过)
      askTimeoutMs: 120000   # 询问超时,超时按内容类型默认执行
      maxAsksPerSession: 0   # 每会话弹窗上限(0=不限),嫌弹窗多可设 3~5,超限按内容类型默认静默执行
      summaryCache: true     # 内容 hash → 摘要磁盘缓存,跨会话命中 0 API(含原文落盘去重)
      dynamicResolution: true
      resolutionTiers:       # 按字数分档(尺寸经实测校准:YaHei 行高 ≈1.9×字号,
                             # 密度保持在已验证安全的 ~1千字/页 以内)
        - { maxChars: 2000, width: 800, height: 450, fontSize: 24 }
        - { maxChars: 6000, width: 1440, height: 810, fontSize: 24 }
        - { maxChars: Infinity, width: 1920, height: 1080, fontSize: 36 }
      renderWidth: 1200      # dynamicResolution=false 时的固定宽度
      pageFontSize: 24       # dynamicResolution=false 时用
      pageMaxHeight: 3000    # dynamicResolution=false 时用
      visionModel: 'deepseek-v4-flash-vision-exp'
      baseUrl: 'https://api.deepseek.com/v1'
      maxSummaryChars: 2000
      maxSummaryRatio: 0.4    # 摘要上限 = min(maxSummaryChars, 输入字数×0.4),保证替换后比原文短
      pagesPerBatch: 4        # 分批摘要:每批最多 4 页送 vision(防"只读开头几页"),再纯文本合并
      saveOriginal: 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
    memory_bridge:            # dsh-memory-bridge 联动占位节(阶段 3b 完成后开开关)
      enabled: false
      sync_dir: '~/.dsh-memory'
      compress_on_sync: true
      compression_strategy: 'time_decay'
      text2img_threshold: 1000
      dynamic_resolution: true

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 协同(内容压缩 × 行为管理,可独立安装)
  • dsh-memory-bridge 联动(配置节已占位,扩展 + bridge 服务就绪后开开关)

权限与边界(上架声明)

本插件是高权限插件:为实现压缩/转图/调度功能,运行时需要访问文件、网络、命令与凭据。以下为完整边界声明(与 DSH Store 审查口径一致):

类别实际行为边界
文件 files写 ~/.dsh/token-optimizer/ 下的落盘原文(text2img-originals / originals / filediff-originals)与摘要磁盘缓存(text2img-summary-cache,含内容 hash→摘要映射)、系统临时目录的渲染 PNG;设 DSH_TOKEN_OPTIMIZER_DEBUG=1 时写调试日志只写插件自有状态目录与临时产物,不写 Profile 配置、不改 DSH 核心/官方包;日志默认关闭
网络 networktext2img 摘要调用 baseUrl(默认 https://api.deepseek.com/v1)的 /chat/completions只向该端点发送需摘要的文本与渲染图;请求失败即降级跳过转图,不阻断会话
命令 commandsWindows 上用 PowerShell + .NET System.Drawing 渲染文本图片(scripts/render-text.ps1)只执行插件自带渲染脚本,参数固定;非 Windows 自动降级为仅落盘,不执行任何命令
凭据 credentials经 DSH 凭据服务 ctx.credentials.resolve 读取;不可用时回退 process.env.DEEPSEEK_API_KEY仅用于 text2img 的 vision 调用,写入请求头后不落盘、不写日志、不外传
  • 运行时依赖:零 npm 依赖。text2img 摘要依赖外部服务 DeepSeek API(key 由 DSH 凭据/环境变量提供);Windows 渲染依赖 PowerShell + .NET System.Drawing(系统自带)。
  • 失败边界:所有模块 fail-open——任一步出错只降级跳过(保留原文),不影响 DSH 核心流程;模块间无共享可变状态,卸载时统一清理钩子。
  • 已知风险:text2img 摘要可能不准确(摘要自带警告标记,原文落盘可查;页数多时按 pagesPerBatch 分批摘要并合并,每次转图会产生多次 Flash vision 调用);outputLadder/fileDiff 压缩丢细节(原文落盘可回放);compactionDriver 触发压缩后旧历史按 DSH 核心语义进入可回放区;toolTrim 的 allow 为排他白名单,误配会让工具对模型不可见(默认关闭)。
  • 兼容范围:完整开发与验证基于 DSH 0.1.1-rc.2(Node ≥ 18);0.1.2+ 与 0.1.3+ 尚未验证,在 package.json 的 dsh.compatibility.dshReleases 中标为 unknown。

开发

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 协同(内容压缩 × 行为管理,可独立安装)
  • dsh-memory-bridge 联动(配置节已占位,扩展 + bridge 服务就绪后开开关)

许可 / License

MIT © 2026 Zoria Lind