@amaster.ai/dsh-policy

中文文档
0.1.40发布于 2026/11/04MITTypeScriptES Module近 30 天下载 4367

Declarative tool-call policy for DeepSeek Harness: config-driven allow/deny/ask rules (tool name, args pattern, shell command prefix/regex, priority) on the tools/pre-execute gate — Gemini CLI-style policy files expressed as plain plugin config.

原始使用文档
文档目录10 节
  1. Install
  2. Configuration
  3. Rule fields
  4. Matching semantics
  5. What the gate covers
  6. The ask decision
  7. Gemini CLI policy mapping
  8. Security
  9. Compatibility
  10. License

@amaster.ai/dsh-policy

dsh-policy preview

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

FieldRequiredMeaning
toolyesTool name or list of names; * matches every tool
decisionyesallow runs the call, deny blocks it (the message reaches the model as the tool error), ask defers to dsh's approval seam
priorityno (0)Higher priority wins among rules competing for the same command segment; ties break fail-closed (deny > ask > allow)
messagenoDeny reason / ask explanation (a generated default names the matched rule)
argsPatternnoRegex (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
commandPrefixnoAnchored prefix match (or list, any-of) on each shell command segment, at a word boundary (npm matches npm install, never npmx)
commandRegexnoRegex (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 tool matches 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. 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.
  • Priority resolves competition within one segment; across segments the aggregation is conservative: any segment's deny denies the whole call, then any ask escalates, and allow requires every segment decided allow. A broad deny is still overridable by a specific allow because both compete on the same segment (bun run lint at 300 vs bun run at 200).
  • No rule matches → the call passes through to the rest of the tools/pre-execute chain (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.

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_models and the delegation tool, run_code, plus goal/skill/workflow/cordis tools. Match them by tool + argsPattern (the object form fits their argument shapes: file_path for write/edit, url for web_fetch, query for web_search, …).
  • commandPrefix/commandRegex apply to tools whose arguments carry a shell command string — bash and pwsh both use command (covered by the default commandKeys).
  • PTC mode: run_code sub-dispatches re-enter the scheduler's prepare stage, which runs the same pre-execute gate — rules apply per sub-call, not just per run_code.
  • MCP tools bridged by dsh-mcp-client register into the same ctx.tools pipeline — 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 [email protected]). 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 TOMLdsh-policy config
toolName = "*" / "name" / ["a", "b"]tool: '*' / name / [a, b]
decision = "allow" / "deny" / "ask_user"decision: allow / deny / ask
priority = 300priority: 300 (same direction)
denyMessagemessage
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
allowRedirectionnot 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-policydshcordis
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

版本与发布记录

@amaster.ai/dsh-policy 共发布 40 个版本,首次发布于 2026/09/11;过去 12 个月发布了 40 个版本。

版本发布日期距今
0.1.40latest2026/11/041 天前
0.1.392026/11/041 天前
0.1.382026/10/315 天前
0.1.372026/10/315 天前
0.1.362026/10/315 天前
0.1.352026/10/315 天前

关于 @amaster.ai/dsh-policy 的常见问题

@amaster.ai/dsh-policy 是什么?

Declarative tool-call policy for DeepSeek Harness: config-driven allow/deny/ask rules (tool name, args pattern, shell command prefix/regex, priority) on the tools/pre-execute gate — Gemini CLI-style policy files expressed as plain plugin config.

如何安装 @amaster.ai/dsh-policy?

在项目目录运行 npm install @amaster.ai/dsh-policy,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@deepseek-ai/cordis(^4.0.1)、@deepseek-ai/dsh-tools(>=0.1.5-rc.1 || >=0.1.6-alpha.1 || >=0.1.7-alpha.1 || >=0.2.0-rc.1 || >=0.2.1-rc.1 || >=0.2.2-rc.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amaster.ai/dsh-policy 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amaster.ai/dsh-policy 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@amaster.ai/dsh-policy 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.19 || ^22.12 || >=24.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@amaster.ai/dsh-policy 可以商用吗?

@amaster.ai/dsh-policy 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@amaster.ai/dsh-policy 的下载量有多少?

根据 npm 官方下载统计,@amaster.ai/dsh-policy 在 2026/10/06 – 2026/11/04 这 30 天内被下载 4,367 次,日均约 146 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amaster.ai/dsh-policy 还在维护吗?

最新版本 0.1.40 发布于 2026/11/04(1 天前);至今共发布 40 个版本,其中过去 12 个月发布了 40 个;首次发布于 2026/09/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。