- Inicio
- Plugins
- Herramientas y funciones
- dsh-plugin-trim
dsh-plugin-trim
haidai233/dsh-plugin-trim
Trims the tool surface per session. Each session owns a profile — a tool whitelist — applied through `agent.ctx.tools.restrict({ allow })` on that agent scope only, and switching one session never touches another; `full` is the built-in no-restriction profile. The provider only picks the default: a session created or switched onto a local provider (explicit `localProvider`, `routes`, a loopback/private baseURL, or a local-ish id) gets the `local` profile, a cloud one gets `full`, and the re-plan runs on model-selection events plus one delayed pass because the projection can land after the event. Profiles are editable from the panel and persisted under `~/.dsh/plugin-trim-state.json`; an explicit per-session choice overrides the provider default until cleared. A separate, opt-in layer physically disables whole plugin entries through `pluginManager.setPluginEnabled` — that one is profile-scoped by API and the panel labels it as such rather than pretending it can be per-session. A `tool_trim` tool exposes list/status/profile/set/apply/restore to the model. The panel is served by a loopback-only HTTP server the plugin starts on its own fixed port — `http://127.0.0.1:12256/` (auto-bumps on collision, configurable) — because the DSH port changes on every restart and a locally linked package gets no market card in the sidebar; it lists live sessions with their profile and tool count, an editor per profile, a provider picker limited to providers declared in the profile or currently in use, and the full plugin list with search and paging. Two implementation details worth knowing: `tools.restrict()` is an intersection and cannot widen, so the old restriction is released before the visible set is read — otherwise switching to a bigger profile would shrink instead of grow; and every disposer is registered on `ctx.effect`, without which a hot reload leaves an unremovable restriction behind. Measured on a 12GB laptop GPU with a 27B model and a fully resident 256K cache, same conversation: 105 tools / 56,306 prompt tokens / 22.5 tok/s decode, 62 / 34,207 / 43.0 after disabling three tool-heavy plugins, 14 / 12,890 / 66.8 after a session moved to the local profile, with prefill rising from 487 to 1,310 tok/s. Restricting also drops the skill catalog injection, roughly 4.3K more tokens. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.
Instalar
dsh plugin --profile web add github:haidai233/dsh-plugin-trimREADME
dsh-plugin-trim
按会话裁剪工具面的 DSH 插件:每个会话自己一个「档位」,provider 只负责给它自动套默认档。另带一层 profile 级的插件物理开关,和一个自托管面板。
Per-session tool trimming for DeepSeek Harness: every session carries its own profile (a tool whitelist); the provider only decides which profile a session starts on. A second, profile-level layer physically disables plugin entries. Self-hosted panel included.
为什么按会话,而不是按 provider
这不是风格选择,是 API 的硬约束:
| 能力 | 作用域 | 依据 |
|---|---|---|
tools.restrict({ allow }) | 只能 agent 作用域 | 源码:requires a scoped context (agent.ctx): a context-global restriction would mask every agent |
pluginManager.setPluginEnabled() | profile 作用域 | 它写 cordis.patch.yml 的 disabled: true,一改影响全部会话 |
所以:
- 工具面只能按会话裁 —— 按 provider 裁只是「把同一份白名单套给所有本地会话」
- 插件只能 profile 级物理开关 —— "只对这个会话关掉某插件"物理上做不到,别假装能做
实测收益
12GB 笔记本显卡跑 27B、256K 全驻留,同一段对话:
| 阶段 | tools | prompt | decode | prefill |
|---|---|---|---|---|
| 全开 | 105 | 56,306 | 22.5 tok/s | 487 tok/s |
| 关三个插件(插件层) | 62 | 34,207 | 43.0 tok/s | 136 tok/s |
| 会话套 local 档(工具层) | 14 | 12,890 | 66.8 tok/s | 1.31k tok/s |
裁工具面会连带去掉技能目录注入,再省约 4.3K token。
三层
| 层 | 作用域 | 做什么 |
|---|---|---|
| 会话档位 | 单个会话 | agent.ctx.tools.restrict({ allow }),full 档 = 不限制 |
| provider 默认档 | 触发条件 | 本地 provider 的新会话套 local,云端套 full;切了就重算这一条会话 |
| 插件开关 | profile | setPluginEnabled,物理启停,影响全部会话 |
装
dsh plugin --profile <你的 profile> add github:haidai233/dsh-plugin-trim
或本地目录:
dsh plugin --profile desktop add D:\path\to\dsh-plugin-trim
装完重启 DSH。
面板
固定地址,装完就能开:
http://127.0.0.1:12256/
插件自己起一个只监听回环的 HTTP 服务(默认 12256,被占则自动 +1 顺延,可用 panelPort 改)。跟 DSH 的端口无关,DSH 重启多少次都不变。
Windows 上还有个启动器(包里自带):
open-panel.cmd # 打开面板;12256 不通时回退扫 DSH 端口
open-panel.cmd check # 只打印地址
面板内容:
- 会话:每行一个会话(本地/云端、provider、工具档位下拉、工具数、是否已裁),可以给单条会话换档或改回「跟随 provider」
- 档位定义 · 工具名单:一个档位就是一份工具白名单。内置
full(不裁剪)和local(14 项),可以随便新建(如coding/chat),逐个工具勾选后保存;面板新建的档位也能删,引用它的会话会自动回到「跟随 provider」 - 本地 provider:指定哪个 provider 算本地
- 插件(profile 级):全部可管理插件,带搜索/分页/「只看已停用」,核心组件停用前弹确认
给模型的工具
tool_trim:
| action | 作用 |
|---|---|
list | 本会话可见的工具名 |
status | 本会话的 provider / 档位 / 是否已裁 |
profile | 给本会话换档(full / local / custom) |
set | 把某个工具加进/移出本会话当前档位 |
apply | 按当前档位重装 |
restore | 撤掉限制,恢复全部 |
配置(cordis.patch.yml 的 config 段)
| 键 | 默认 | 说明 |
|---|---|---|
enabled | true | 总开关 |
followTools | true | provider 变化时给这条会话自动套默认档 |
auto | false | true = 切到本地 provider 时顺带物理开关插件(profile 级,慎用) |
localProvider | 空 | 哪个 provider 算本地;面板选的值存在 ~/.dsh/plugin-trim-state.json,优先于这里 |
routes | [] | 非空时只认这些 provider |
localEntries | 示例 3 条 | 插件层要关掉的 entryId |
defaultProfileFor | {local: local, cloud: full} | 本地/云端各套哪个档 |
profiles.<名字> | local 14 项 | 任意键名都是一个档位;面板里新建的档位存在 ~/.dsh/plugin-trim-state.json,不写回配置 |
本地 provider 判定:localProvider 写死 / routes 命中 / baseURL 落在回环或私有网段 / id 带 local、ollama、llama、vllm、sglang 等标记。
HTTP 接口
固定端口面板(127.0.0.1:12256):
| 方法 | 路径 |
|---|---|
| GET | / 面板页 |
| GET | /health |
| POST | /api/plugin-trim/{status,setProfile,autoProfile,setProfileTools,setProvider,applyAll,restoreAll,set,applyPlugins,restorePlugins} |
同一套处理函数还会注册到 DSH 自带 webServer 上(/api/plugin-trim/...,带同源校验),两个入口等价。
已知限制
- 换到更宽的档位之前必须先撤旧限制,否则读到的是上一次裁过的工具集,越裁越少。已修(
applyProfile里先 release 再读可见集),但热重载会泄漏:v0.1 没有把 restrict 的 disposer 注册到ctx.effect,重载后旧限制留在工具层撤不掉。v0.2 已修;升级后重启一次 DSH 清掉遗留。 - 插件层:整条 bundle 停用后会脱离组合,DSH 自己也认不回来(
unknown-plugin)。这类条目「还原」无效,只能去 patch 文件删掉那两行再重启;接口会以skipped[].hint提示。 - 裁工具会把
skill一起裁掉,技能目录随之不再注入(约 4.3K token)。要用技能就把skill加进档位。 tool_trim自己不在白名单里,装了小档位后模型侧调不到它 —— 换档走面板或 HTTP。- 与
dsh-local-trim功能有重叠,不要同时启用两者对同一 provider 做裁剪。
许可
MIT
Plugins relacionados
archify (deepseek-harness)
tt-a1i/archify
WeKnora (dsh-weknora)
tencent/weknora
next-ai-draw-io (dsh-plugin)
dayuanjiang/next-ai-draw-io
weknora
tencent/weknora