dsh-subagent-model-guard
Manifest validGates subagent delegation against DSH's official model allow-list, and can replace the delegation and model-discovery tools so a session snapshot cannot hide newly published models. Its HTTP routes ha
子智能体模型路由守卫(dsh-subagent-model-guard)
一个为 DeepSeek Harness 的「派发子智能体」把门的 DSH 插件:按 provider/model 白名单拦截子智能体路由,堵住「省略模型就静默回退父级模型」这条绕过口子,并可选替换官方 subagent 工具让新上架模型立即可用。它不新增业务工具,只守卫与替换已有的派发能力,另提供一个只读诊断工具。
为什么做这个
DSH 的子智能体派发有两处与「实际运行的是哪个模型」有关的问题。
一是继承。派发时省略 model,子智能体会继承父级路由。这本身是合理的设计,但当成本或权限取决于模型时,实际执行的模型就应当是可校验的,而不该只取决于调用方是否显式写了 model。
二是会话快照(会话启动时记下的模型选择策略)。官方白名单在会话启动时冻结,此后新上架的模型在既有会话中派发不出去。
插件对前者做校验——包含继承路径,实际会运行的 provider/model 都要过白名单;对后者提供可选的替身工具,绕开会话快照。名单仍以官方设置为准,插件不维护自己的一份。
术语说明(请先读)
- 参数:智能体每次派发子智能体时传入的值,只对本次派发生效,例如
provider、model、cwd。- 设置:你在插件页配置、跨派发持续生效的值,例如
strict、enforcement、replaceSubagentTool。
它提供什么
它对 DSH 已有的派发链路做五件事:
- 路由校验(Gate):在
agent/created和/或包住ctx.subagents(由enforcement决定agent-created/start-activation/both)校验子智能体真正要跑的 provider/model。两条路径都覆盖——既管官方subagent工具,也管 workflow 里绕过工具层的agent()。守卫对象包括官方subagent与subagent_fork两个派发工具(tools/pre-execute层负责给出可读的拒绝原因)。 - 可选替换官方
list_subagent_models工具(replaceListModelsTool:true):官方那份按会话快照回答,会话期间新加的模型会被报成不可用,而且报错是not allowed for this Session——看起来像权限问题,其实是会话快照过期。本插件那份改按当前官方设置回答,与守卫的放行依据同源,输出格式与官方对齐(provider 列表、模型列表、推理档位三段)。建议与replaceSubagentTool一起开,否则列出来的模型可能派不出去。 - 可选替换官方
subagent工具(replaceSubagentTool:true):用本插件自己的subagent替身工具取代官方全局工具,直接走ctx.subagents.startActivation(),绕开会话快照,让新发布的模型在旧会话里也能立刻使用;subagent_fork刻意不替换(它的forkprovider 行为不同,半吊子的替身只会更糟)。替身工具的cwd参数始终可用(它早已不再是设置项),用于指定子智能体的初始工作目录。 - 审计与拒绝记录:可选的每步审计(
auditEveryStep,只记不拦)与内存中的最近拒绝记录(recentDenialLimit,绝不落盘,因为包含模型名);审计可按auditDedupeMs去重。 - 只读自检工具
guard_selfcheck:严格只读、不改任何状态。它报告本插件实例的当前生效状态(严格/启用标志、enforcement 模式、官方白名单的读取结果、闸门与替换工具安装情况、最近拒绝计数),供排查「某个路由为何被放行或拒绝」。唯一的参数是可选的route("provider/model")——传了它就在不派发的情况下回答「这条路由现在会不会被放行、为什么」。它是诊断工具,不是业务工具。
放行依据只有 DSH 官方的子智能体白名单:每次派发实时读取 subagentModelSelection 服务的 allowedModels。官方列表为空、官方关闭、或服务不可用时不拦截(与 DSH 原生行为一致)。本插件不维护自己的白名单、黑名单,也不支持通配符——要封禁某个模型,请到官方设置里把它删掉。
它带设置页(8 项):总开关 strict、错误信息是否暴露名单、审计与去重、执行点(三选一)、是否用替身工具。名单不在这里配——去 DSH 官方设置里改。
安装(本地 bundle)
本插件以 link: 方式装进你的 profile(vendored 依赖必须随目录链接,见下方「已知限制」)。插件包自带的 cordis.patch.yml 内容为:
- insert:
- id: subagent-model-guard
name: '@local/dsh-subagent-model-guard'
在 profile 的 cordis.patch.yml 里插入同样一条,即可把 @local/dsh-subagent-model-guard 这一行挂到 Loader:
- insert:
- id: subagent-model-guard
name: '@local/dsh-subagent-model-guard'
id 是 Loader 行 id,name 必须与 package.json 的 name 一致。装好后到 DSH 官方设置里配好白名单,再到插件页选执行点;若要用新上架模型,打开 replaceSubagentTool。
设置项
与 index.js 中的 Config(Schemastery schema)逐项对应,共 8 项;全部为 .volatile(),保存后立即生效,无需重启插件:
| 字段 | 类型 | 缺省值 | 说明 |
|---|---|---|---|
strict | boolean | true | 关闭后整段守卫失效,所有路由一律放行。 |
includeAllowedListInError | boolean | true | 拒绝时是否在错误信息里列出当前生效的名单;关闭后只说明被拒路由,不暴露其余模型名。 |
recentDenialLimit | number | 0 | 内存里保留最近 N 条拒绝记录(0 = 不记录);只活在进程内存里,绝不落盘。 |
auditDedupeMs | number | 0 | 同一个 agent + 路由在此时间窗(毫秒)内只记一条审计日志(0 = 不去重),避免刷屏。 |
enforcement | enum | "agent-created" | 校验点:agent-created(契约稳定、覆盖 workflow,但被拒会留一个空 session 记录)/ start-activation(agent 构造前拒绝、零残留,依赖 internal/get)/ both(两处都校验)。 |
replaceListModelsTool | boolean | false | 用本插件实现的 list_subagent_models 取代官方工具:按当前官方设置列出/查询模型,而不是按会话快照;建议与 replaceSubagentTool 同开。 |
replaceSubagentTool | boolean | false | 用本插件实现的 subagent 取代官方工具;开启后直接走 startActivation,绕开会话快照,新模型立即可用;关闭则保留官方工具。 |
auditEveryStep | boolean | false | 在每一步模型调用时检查路由是否在白名单内,只记录不拦截(此时拒绝会导致「创建成功却立刻失败」,故只写 host 日志)。 |
原第 13 项
cwd设置已删除:cwd不再是一个设置项,替身subagent工具的cwd参数现在始终可用,无需先开启某个设置。
已知限制 / 注意事项
- vendored 依赖:
node_modules/@deepseek-ai/schemastery与@deepseek-ai/cosmokit随包附带(见VENDORED.md),只能用link:安装;npm pack/ 仓库安装会丢掉node_modules导致配置表单失效。升级 DSH 后需从新app.asar重新提取对齐版本。 - 执行点有取舍:
agent-created被拒会留下一个空 session 记录;start-activation依赖内部internal/get服务,可能在未来 DSH 版本变动;按需选择both。 - 替换工具仅覆盖
subagent:subagent_fork因 provider 语义不同刻意不替换;tools/pre-execute层仍会对官方subagent_fork给出拒绝说明,但它本身不会被替身工具接管。替身工具支持cwd参数(始终可用),但不支持forkprovider。 - 官方白名单读取依赖
subagentModelSelection服务;服务不可用、官方enabled未开启(enabled !== true)或其current()抛错时,本次不施加任何限制(fail-open),并通过ctx.logger单次告警。 - 拒绝记录不落盘:
recentDenialLimit只影响内存缓冲,重启即清空——这是刻意设计(模型名属于隐私)。guard_selfcheck读取的拒绝计数同样只反映当前进程内存。 guard_selfcheck只报告状态、不修改任何配置或队列;即使某个配置引用或服务损坏,其外层捕获也保证它不会抛错(会以ok:false的 check 呈现)。
与同类的差异
DSH 生态里「管子智能体模型」的插件不止一个,但方向并不相同:
| 项目 | 机制 | 与我们的差别 |
|---|---|---|
ccsert/dsh-subagent-hub | 具名预设 + 路由表守卫,派发前拒绝越界;也读官方 allowedModels | 定位更偏「按预设组队」,我们只做单一判定 |
643048695/dsh-subagent-role-router | 白名单外的模型替换成允许的,并支持运行中换模型 | 我们拒绝并说明原因,不做静默替换 |
CypherNaught-0x/DSH-Subagent-Model-Router | 按能力标签自动选优 | 目的相反:它选优,我们守门 |
Funny1Potato/dsh-outsourcing-expert | preset 层面强制外包,并先侦察可用模型 | 提示层引导,不是运行时强制 |
最实在的一条差异:可选地替换官方 subagent 工具,直接走 ctx.subagents.startActivation(),绕开会话快照。上面这些项目都在「会话快照生效之前」的路由层做文章,没有正面处理「旧会话里 subagent 的工具 schema 已经冻结、新上架的模型根本传不进去」这个限制。
另外两条是设计取向,不是能力差异:
- 不维护自己的名单:放行依据只有 DSH 官方设置里的
allowedModels,每次派发实时读取,因此官方那边改了模型立刻生效。 - 拒绝留痕:把「父路由 → 子路由 + 原因」记在内存里,并展示在设置页的表格中,方便回答「刚才那次为什么被拒」。
安全说明(哪些操作有破坏性)
- 本插件不删除文件、不联网、不执行 shell;最坏影响是拒绝一次子智能体派发(在
tools/pre-execute返回kind:'deny',或替换工具的execute抛错)。guard_selfcheck只读。 - 两个替换开关都是屏蔽官方全局工具并注册同名替身工具(scoped 影子实现):插件加载时对已存在的 agent 补齐一次,之后新建的 agent 在
agent/created时安装。若开关是在会话运行中从设置页打开的,已存在的 agent 不会重新补齐,需要新开会话或新建 agent 才生效。 - 开启
replaceSubagentTool会屏蔽官方全局subagent工具并注册自己的替身工具,插件加载时已开启的情况下影响所有 agent(含当前会话已存在的 agent)。替身工具只支持spawnprovider,不支持fork;如依赖 fork 语义,请保持关闭。 - 关闭
strict会让整段守卫失效、所有路由放行;enforcement/白名单设置仍在但不起作用,请勿误以为仍受保护。 includeAllowedListInError:true会在拒绝信息里列出允许的模型名;若不愿暴露模型名,请关闭。
License
MIT © 2026 a-molecule-of-ATP。详见 LICENSE。
English summary: A DeepSeek Harness plugin that gates subagent delegation by provider/model allow-list, covering both the official subagent tool and workflow agent() calls. It can optionally replace the official subagent tool so newly published models work in old sessions, provides audit logging plus in-memory denial records (never persisted), and adds a read-only guard_selfcheck diagnostic tool with an optional route ("provider/model") argument. It registers no new business tool; eight volatile settings control the enforcement point, error verbosity, auditing and tool replacement — the allow-list itself comes from DSH's own subagent model selection, not from this plugin. Link-installed with vendored Schemastery; licensed MIT.
Comments
Loading…
Similar plugins
by LittleChenLiya
Runs one goal as parallel subtasks and merges the reports into one answer; the run survives a host restart, spending is capped, and the cost is printed. Its HTTP routes have no DSH access check, so a
★ 4
↓ 8.8k/wk
MIT
JavaScript
Nov 22, 2026
dsh plugin --profile web add @xiangyixie/dsh-superagentby gengwg
Deterministic, inspectable delegation-time model routing for DeepSeek Harness (dsh) subagents
★ 1
MIT
JavaScript
Nov 7, 2026
dsh plugin --profile web add dsh-agent-routerby 643048695
Route DSH subagent delegations to configured models with per-role routing for explore, plan and patch subagents, round-robin or random distribution, cross-provider failover, and active-window slicing
★ 1
MIT
JavaScript
Nov 8, 2026
dsh plugin --profile web add dsh-subagent-role-routerby twoweeks1995
Named model routes for subagent delegations, configured from a settings page: each alias binds a subagent provider, model and optional reasoning effort, token cap, agent preset, tags, plus a "when to
★ 0
MIT
JavaScript
Nov 2, 2026
dsh plugin --profile web add dsh-subagent-setupby ringoage
The visual, manual subagent-model picker for DeepSeek Harness — predictable per-session routing with global coverage of every in-process subagent path, complementary to auto-routing plugins.
★ 0
MIT
JavaScript
Aug 16, 2026
dsh plugin --profile web add dsh-subagent-model-picker为 DeepSeek Harness 的子代理单独指定第三方模型(Settings → 子模型)
★ 1
MIT
JavaScript
dsh plugin --profile web add dsh-subagent-toolkit