Zoria-Lind/dsh-token-optimizer ↗★ 19
@zoria-lind/dsh-token-optimizer
提供分层Token优化管道与缓存调度功能。 通过文本转图、缓存等手段优化Token消耗。适合需要降低API成本的用户。
同名套件的其他儲存庫
安裝
$
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:Zoria-Lind/dsh-token-optimizer說明文件
閱讀完整 README ↗配置
挂载后在 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