Preface

When building DSH agents, a common requirement is to correct certain tool calls: for example, avoid using pip install directly and prefer the gh CLI, or use the markitdown skill when reading PDFs. If such rules are always kept in the context, they add unnecessary context overhead. dsh-stream-rules works by injecting a redirect prompt after a tool call matches a rule, allowing the agent to retry from the same point.

What This Is

@jiesou/dsh-stream-rules is a DSH plugin maintained by jiesou, MIT licensed, with package version 0.1.7. It ports the approach of jiesou/opencode-stream-rules to DSH, injecting rules on demand instead of keeping them resident in the context.

How It Works

The plugin evaluates rules when a tool call is triggered. The tool name and arguments of each tool call are serialized into a string, and a rule takes effect when its match returns true.

  • Default: Injects a SYSTEM NOTICE redirect message via agent.inject(), and the agent retries from the same point.
  • reject: true: Rejects the first tool call; subsequent attempts are allowed.
  • Each rule triggers at most once per session (per agent).

The implementation uses DSH’s tools/pre-execute waterfall (deny) and agent.inject() with no core modifications and no monkey-patching.

Installation

Add from npm:

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

Add from GitHub; installing from GitHub runs the prepare build:

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

You can also add it to the cordis.patch.yml in your profile:

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

Enabling Rules

The plugin does not take effect immediately after installation; you need to write rules yourself.

  1. Locate the plugin path:
$DSH_HOME/profiles/<name>/node_modules/@jiesou/dsh-stream-rules
  1. Copy the example rules file:
mv rules/rules.js.example rules/rules.local.js

The rules file exports an array. Each rule must have match and prompt, with reject optional. Files whose names start with _ are skipped.

Rule Examples

The following examples come from the plugin’s documentation:

// 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 descriptions:

match: (v: string) => boolean, used to determine whether a tool call matches
prompt: the redirect prompt content
reject: if true, blocks the tool call first rather than only injecting the prompt

To point to a different rules directory, use config.rules:

- id: stream-rules
  name: '@jiesou/dsh-stream-rules'
  config:
    rules: /path/to/your/rules

Use Cases and Notes

This is suitable for scenarios where you want to add lightweight behavioral boundaries within DSH agents: restricting certain tool calls, correcting command choices, or prioritizing specific skills.

Notes before use:

  • The plugin runs with the current dsh process permissions; review the source code and license before installation.
  • The package declares the following peerDependencies:
@deepseek-ai/cordis >=4.0.1 <5
@deepseek-ai/dsh-llm >=0.1.0-rc.6 <0.2.0
@deepseek-ai/schemastery ^3.18.1
  • Rules are not active by default; you need to write or copy a rules file first.
  • reject: true only rejects the first tool call; subsequent attempts are allowed.
  • Each rule triggers at most once per session.

Links

GitHub: https://github.com/jiesou/dsh-stream-rules