跳到正文

jiesou/dsh-stream-rules

40最近提交 2026年8月14日

dsh-stream-rules DSH 插件

dsh-stream-rules 是一个 DSH 插件,让你定义基于工具调用触发的规则。当规则匹配时,它会注入一条引导通知或拒绝首次调用,从而精确控制 agent 行为。插件仅约 60 行代码,使用 DSH 的原生扩展点。

如何安装 dsh-stream-rules DSH 插件

dsh plugin --profile <name> add @jiesou/dsh-stream-rules

来源命令需要人工核对。复制不会执行命令。

dsh-stream-rules DSH 插件数据来源

dsh-stream-rules DSH 插件快照日期:2026年8月16日

discovered

dsh-stream-rules DSH 插件能做什么

  • 通过自定义函数匹配工具调用的扁平化字符串(名称+参数)
  • 在 agent 从同一位置重试前注入 SYSTEM NOTICE 引导消息
  • 可选地拒绝首次工具调用(deny),同时允许后续尝试
  • 每条规则在每个会话中最多触发一次,避免重复干扰
  • 从本地 `.js` 文件加载规则,支持灵活配置路径

dsh-stream-rules DSH 插件适合哪些场景

  • 强制 agent 使用 `uvx` 或 `uv pip` 而非直接使用 `pip install`
  • 优先使用 `gh` CLI 而非 `curl` 调用 GitHub API 以获得更高访问限制
  • 当 agent 尝试处理 PDF 文件时,推荐使用 `markitdown` 技能
  • 在首次尝试时阻止不安全的命令如 `curl | bash`
  • 在不修改 agent 核心的前提下,强制实施公司的工具使用规范

dsh-stream-rules DSH 插件适合谁

  • 希望微调 agent 工具使用行为而无需重建模型的 DSH 用户
  • 为 AI agent 实施行为策略的开发者与安全团队

dsh-stream-rules DSH 插件的限制

  • 仅在 DSH 环境中有效,需要安装并配置插件
  • 规则基于工具调用的字符串匹配,可能无法覆盖复杂模式
  • 没有内置热重载功能,修改规则文件后需重启 agent
  • 默认配置不生效,用户必须在安装后自行编写规则文件

dsh-stream-rules DSH 插件的仓库 README 摘录

以下文字摘自 dsh-stream-rules DSH 插件的上游仓库 jiesou/dsh-stream-rules 的 README,版权归原作者,仅作引用。

Inject rules when needed, without wasting context. <img height="500" alt="-6336866371853030306_121" src="https://github.com/user-attachments/assets/09a5b140-bfcc-4401-895d-af9280b44709" /> You can write custom streaming rules for the agent. These rules are injected only as a steering notice after a pattern match, then agent retry from the same point. This allows you to control the boundaries of agent behavior, without wasting context. Port of my [jiesou/opencode-stream-rules](https://github.com/jiesou/opencode-stream-rules) to DSH. Similar to oh-my-pi's "Time-traveling stream rules", but with a very simple and compact code implementation. ## How it works A rule fires on a tool call (tool name + serialized arguments) when its `match` returns true: - **default** — injects a `SYSTEM NOTICE` steering message into the agent via `agent.inject()` (DSH's non-waking "queue model-facing context for the next pre-step"). The agent retries from the same point, now knowing the rule. - **`reject: true`** — denies the FIRST tool call (`{ kind: 'deny' }`); later attempts are allowed. Steering without over-restricting, e.g. letting `pip install` through when it's already in a container. Each

阅读完整 README仓库许可: MIT

dsh-stream-rules DSH 插件常见问题

如何安装 dsh-stream-rules?

你可以通过 npm 安装:`dsh plugin --profile <name> add @jiesou/dsh-stream-rules`。也可以从 GitHub 安装:`dsh plugin --profile <name> add github:jiesou/dsh-stream-rules`。安装后,必须编辑规则文件才能使插件生效。

安装后插件没有生效,为什么?

默认情况下,插件附带了一个示例规则文件但处于禁用状态。你需要找到插件目录(通常位于 `~/.dsh/profiles/<name>/node_modules/@jiesou/dsh-stream-rules`),将 `rules/rules.js.example` 重命名为 `rules/rules.local.js`,然后编写自己的规则。只有存在有效的 `.local.js` 文件后,插件才会开始匹配。

可以在规则文件中使用环境变量吗?

规则文件是一个导出规则对象数组的普通 JavaScript 模块。你可以使用任何有效的 JavaScript 语法,包括 `process.env` 或其他 Node.js 全局变量,只要该文件在 DSH 插件上下文中执行即可。但请注意,`match` 函数接收一个字符串,你需要相应地设计匹配逻辑。

如何调试规则为何没有触发?

检查插件日志以确认规则文件是否被加载。常见问题:文件名必须以 `.local.js` 结尾(以下划线开头的文件会被跳过),`match` 函数必须对工具调用返回 `true`,且该规则在当前会话中尚未触发过。你也可以在 `match` 函数中添加临时 `console.log` 语句来查看被匹配的字符串。

能否不重启 agent 就重新加载规则?

目前插件不支持热重载。修改规则文件后,必须重启 DSH agent(或对应的 profile)才能使更改生效。这是插件文档中提到的已知限制。