根据可配置的允许、拒绝和审批规则控制 dsh 工具调用,包括对 shell 命令的匹配。
安装
# npm 包(预构建)
dsh plugin --profile web add @amaster.ai/dsh-policy
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:TGYD-helige/dsh-plugins#path:/packages/dsh-policy
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
该插件的 README 只有英文版本。

Declarative tool-call policy for DeepSeek Harness (dsh): config-driven allow / deny / ask rules on dsh's tools/pre-execute gate — the semantics of Gemini CLI's TOML policy files, expressed as plain plugin config (Schemastery-validated YAML, no code, no rule files).
Install
dsh plugin --profile my-agent add @amaster.ai/dsh-policy
Configuration
The plugin is disabled by default. Rules live in the profile's cordis.patch.yml like every other dsh plugin config (edits hot-reload with the config layer):
- name: '@amaster.ai/dsh-policy'
config:
enabled: true
rules:
- tool: '*' # every tool
decision: allow
priority: 20
- tool: bash # dsh's shell tool (pwsh works the same)
decision: deny
commandPrefix: npm
priority: 200
message: 'npm is not allowed. Use bun install / bun add / bun test instead.'
- tool: bash
decision: deny
commandPrefix: bun run
priority: 200
- tool: bash # …but one specific subcommand is fine
decision: allow
commandPrefix: bun run lint
priority: 300 # higher priority overrides the broader deny
- tool: bash # grep as a pipe filter stays allowed
decision: allow
commandPrefix: grep
priority: 300
- tool: write
decision: deny
argsPattern:
file_path: '\.md$' # matched against the file_path value directly
priority: 200
- tool: write # …except the project contract file
decision: allow
argsPattern:
file_path: 'PRODUCT\.md$'
priority: 300
- tool: write
decision: ask # resolved via ctx.approval (human/answerer chain)
argsPattern:
file_path: '(^|/)etc/'
message: 'writes to a system path'
Rule fields
| Field | Required | Meaning |
|---|---|---|
tool |
yes | Tool name or list of names; * matches every tool |
decision |
yes | allow runs the call, deny blocks it (the message reaches the model as the tool error), ask defers to dsh's approval seam |
priority |
no (0) | Higher priority wins among rules competing for the same command segment; ties break fail-closed (deny > ask > allow) |
message |
no | Deny reason / ask explanation (a generated default names the matched rule) |
argsPattern |
no | Regex (or list, any-of) matched against the JSON-stringified arguments — or a map of argument name → regex (or list): each key's pattern is matched against that argument's value (non-string values are JSON-stringified first), all keys must hold. Prefer the map form for field-targeted rules — no quote escaping, no key-order or cross-field accidents |
commandPrefix |
no | Anchored prefix match (or list, any-of) on each shell command segment, at a word boundary (npm matches npm install, never npmx) |
commandRegex |
no | Regex (or list, any-of) anchored at each shell command segment's start — Gemini-compatible; use .* to match mid-segment |
Plugin-level fields: enabled (master switch) and commandKeys (argument keys holding a shell command string — default ['command'], covering dsh's bash/pwsh tools).
Matching semantics
- Every condition on a rule must hold for the rule to match (AND). A rule with no conditions beyond
toolmatches every call of that tool. - Shell commands are checked segment by segment. Compound commands (
a && b | c, newlines, background&) are split, quote-aware, and the executable command word is normalized through quotes, escapes and line continuations. Fd redirections such as2>&1and&>filestay inside their segment. Bash$( ), backtick and<()/>()substitutions are extracted as their own segments; here-doc bodies are data, except for real substitutions in unquoted bodies. PowerShell backticks are escapes, not Bash-style substitutions. - Bash grouping is stripped before matching. Subshell parens,
{ … },!,time, and theif/then/else/while/dokeywords are removed, so(npm i)andif x; then npm i; fichecknpm i.denyandaskrules also match the segment without leadingNAME=valueassignments and with the command path reduced to its basename (FOO=1 /usr/bin/npm imatchesnpm).allowrules match the command as written, so they never cover a changed environment or another binary. Every unquoted paren splits, so an array assignment such asarr=(a b)or acasepattern becomes an extra segment; such extra segments can add a deny or ask match but never an allow. - Wrappers are not unwrapped.
env,sudo,command,exec,xargs,eval,sh -cand similar launchers are the segment's command word. Deny or ask those launchers explicitly when a deny rule must hold. - Priority resolves competition within one segment; across segments the aggregation is conservative: any segment's
denydenies the whole call, then anyaskescalates, andallowrequires every segment decided allow. A broad deny is still overridable by a specific allow because both compete on the same segment (bun run lintat 300 vsbun runat 200). - No rule matches → the call passes through to the rest of the
tools/pre-executechain (next()), so dsh's own gates and other plugins keep their say. Invalid regexes are config errors and fail the plugin load; a runtime evaluation failure is logged with the[dsh-policy]prefix and denied (fail-closed) without breaking the agent loop. - Denials carry a routable identity:
info: { name: 'PolicyError', code: 'POLICY_DENIED' }, orPOLICY_EVALUATION_FAILEDfor a failed evaluation. Telemetry and clients can tell policy denials from tool failures.
What the gate covers
Everything registered in ctx.tools passes tools/pre-execute — the gate is tool-agnostic and needs no per-tool support:
- Official tools (verified against the 0.1.6-alpha.2 sources):
bash,pwsh,read,write,edit,read_image,web_search,web_fetch,list_subagent_modelsand the delegation tool,run_code, plus goal/skill/workflow/cordis tools. Match them bytool+argsPattern(the object form fits their argument shapes:file_pathforwrite/edit,urlforweb_fetch,queryforweb_search, …). commandPrefix/commandRegexapply to tools whose arguments carry a shell command string —bashandpwshboth usecommand(covered by the defaultcommandKeys).- PTC mode:
run_codesub-dispatches re-enter the scheduler'spreparestage, which runs the same pre-execute gate — rules apply per sub-call, not just perrun_code. - MCP tools bridged by
dsh-mcp-clientregister into the samectx.toolspipeline — match them by their registered names like any other tool.
The ask decision
ask is resolved by dsh itself: through the composed answerers of @deepseek-ai/dsh-user-approval (a UI prompt, an auto-answerer, …), failing closed to deny when no approval service is composed, and short-circuiting to reject under a session's approval/policy: never. The model-facing deny reason is the rule's message only when no approval service exists at all; a rejected/cancelled/unavailable outcome carries dsh-tools' own reason wording (verified against dsh-tools@0.1.6-alpha.2). Gemini's modes (default/autoEdit/yolo/plan) have no dsh counterpart — dsh models that axis as the per-session approval policy (see dsh-permission-presets for the user-facing selector), and dsh profiles/cordis.patch.yml already scope config per deployment, so the plugin carries no mode axis of its own.
Gemini CLI policy mapping
| Gemini TOML | dsh-policy config |
|---|---|
toolName = "*" / "name" / ["a", "b"] |
tool: '*' / name / [a, b] |
decision = "allow" / "deny" / "ask_user" |
decision: allow / deny / ask |
priority = 300 |
priority: 300 (same direction) |
denyMessage |
message |
argsPattern (regex on the serialized args) |
argsPattern — plus a dsh-native object form { file_path: '…' } matching per-argument values (the string form keeps JSON.stringify key order, not Gemini's sorted-key form — patterns spanning multiple keys may need adjusting; the object form has no such issue) |
commandPrefix / commandRegex (single or list) |
same names, matched per command segment; commandRegex anchors at the segment start, like Gemini's at the command start |
modes = [...] |
no counterpart — use separate dsh profile patch rows |
allowRedirection |
not supported (dsh has no per-call redirection gate) |
Security
A policy plugin is advisory gating, not containment: deny rules keep a well-behaved agent off dangerous commands, but the agent process still runs with host privileges. Pair with dsh's sandbox stack (dsh-sandbox + a confining executor) for OS-level enforcement, and note that dsh ships no authentication or authorization of its own.
Compatibility
| @amaster.ai/dsh-policy | dsh | cordis |
|---|---|---|
| 0.1.x | `>=0.1.5-rc.1 |
Peer dependency: @deepseek-ai/dsh-tools (the tools/pre-execute gate). The approval seam (@deepseek-ai/dsh-user-approval) is optional and only involved in ask decisions.
License
MIT
链接
同类插件
kenryu42/cc-safety-net★ 2100
执行前守卫,在工具调用运行前拦截破坏性 Git 与文件系统命令,以及对 SSH 密钥、.env 等机密文件的访问。
ADWMC/helm-d#helmd★ 1492
DeepSeek Harness 的安全分析插件:33 个工具覆盖六大安全域、证据/报告与工具集,并提供案件生命周期、路由和工具账本;按会话绑定的案件工作区支持证据链、E 编号校验与可复现结论(repro_cmd);内置 362 篇按需参考、三档可热切换人设,以及带案件状态恢复的破甲 / Case / 拦截 / 关于四页工作台。
toby-bridges/api-relay-audit★ 932
从 DeepSeek Harness 对 AI API 中转站和 LLM 代理运行本地安全审计,生成 Markdown 报告,覆盖提示词注入、模型替换信号、工具调用改写、错误泄漏、流完整性和按 profile 启用的 Web3 风险。
SeaOf0/dsh-redteam-model★ 918
面向授权安全研究的 DSH 合集:九个工作模式(redteam 总控、渗透测试、代码审计、二进制分析、攻防评估、免杀对抗、应急溯源、云安全攻防、CTF 解题)与十五个运行时插件,设置页管理台支持一键部署、安装、更新与卸载。
howmp/dsh-pentest★ 623
面向 DeepSeek Harness 的授权渗透模式:以探索链路记录目标、线索、资产与漏洞,并在 Web 中可视化展示。
PerryLink/dsh-auto-review★ 255
审批链上的第二模型自动审查:只读审查子代理返回带理由的 allow/deny 结构化裁决,默认 fail-closed。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。