jiesou/dsh-stream-rules 预览 preview

jiesou/dsh-stream-rules

插件Plugin 原生Native ⭐ 5 MIT 开发工具Developer Tools

模式匹配时自动注入规则,仅在需要时注入,不浪费上下文。类似oh-my-pi的“时间旅行流规则”,但代码实现极为简洁紧凑。

项目介绍Project Overview

dsh-stream-rules 是一款 DSH 插件,用于在流式输出中按需注入自定义规则。它通过 tools/pre-execute 拦截工具调用,匹配成功时通过 agent.inject() 注入 SYSTEM NOTICE 提示,或以 reject: true 仅拒绝首次调用。适用于需要引导代理行为、避免重复约束的场景。注意:插件安装后默认不生效,需自行在 rules/rules.local.js 中编写规则;每个规则每个会话最多触发一次。

dsh-stream-rules is a DSH plugin that injects custom rules into the agent stream only when a tool call matches a pattern. It uses the tools/pre-execute waterfall to either deny the first matching call or steer the agent via agent.inject() with a SYSTEM NOTICE, then retries from the same point. Use it to bound agent behavior without burning context on always-on instructions. Each rule fires at most once per session per agent. Note: it ships inactive; you must author your own rules/rules.local.js, and the steering message does not interrupt an in-flight run.

或使用命令行安装(适合开发者)Or use CLI install (for developers)

命令行安装CLI Install

dsh plugin --profile web add @jiesou/dsh-stream-rules

jiesou/dsh-stream-rules 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-stream-rules

简体中文

Inject rules when needed, without wasting context.

-6336866371853030306_121

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 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 rule fires at most once per session (per agent), mirroring the original's notified dedup.

Install

From npm (prebuilt, recommended):

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

Or from GitHub (runs prepare to build on install):

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

Or add the row to your profile's cordis.patch.yml:

- id: stream-rules
  name: '@jiesou/dsh-stream-rules'

After installing

You need to write the rules in your own .js file. This plugin won't work by default until you edit the rules.

  1. Locate the plugin's path:
$DSH_HOME/profiles/<name>/node_modules/@jiesou/dsh-stream-rules

where $DSH_HOME defaults to ~/.dsh.

  1. Write rules:
mv rules/rules.js.example rules/rules.local.js
  • Files starting with _ are skipped.
  • To point at a different rules directory: config.rules:
- id: stream-rules
  name: '@jiesou/dsh-stream-rules'
  config:
    rules: /path/to/your/rules
  • A rule with reject: true will only be rejected on the first toolcall; subsequent attempts by the agent will be allowed. This provides steering while avoiding overly restricting the model (e.g., allowing pip install if it's already in a container).

Writing rules

// rules/rules.local.js
export default [
  {
    match: (v) =>
      v.includes('pip') &&
      v.includes('install') &&
      !v.includes('uv pip') &&
      !v.includes('uvx'),
    reject: true,
    prompt: 'Use `uvx` or `uv venv` + `uv pip` instead of `pip install` directly',
  },
  {
    match: (v) => v.includes('curl') && v.includes('api.github.com'),
    prompt: 'Prefer using `gh` cli over `curl https://api.github.com/...`. gh offers more requests limits.',
  },
  {
    match: (v) => v.includes('pdf'),
    prompt: 'Use the `markitdown` skill to read PDF files.',
  },
  // add your rules here
]
field required description
match (v: string) => boolean; every tool call is flattened to a string and matched
prompt The prompt for steering
reject If true, prevent the tool call first, instead of just steering

Implementation notes

  • A single src/index.ts (~60 lines).
  • Uses DSH's tools/pre-execute waterfall (deny) and agent.inject() (steering), the documented native extension points. No core changes, no monkey-patching.
上一个 Prev deepseek-harness-for-ide 下一个 Next dsh-client-usage