dsh-scoped-rules
yohannhommet/dsh-scoped-rules
Loads Markdown rules from .agents/rules folders into every agent, subagents included; a rule with paths globs in its frontmatter loads only after the agent reads, writes or edits a matching file.
Install
dsh plugin --profile web add github:yohannhommet/dsh-scoped-rulesREADME
dsh-scoped-rules
Path-scoped Markdown rules for DeepSeek Harness (DSH) agents.
Put Markdown files in .agents/rules/ folders: in your home directory, in a project, or in a folder that holds several projects. Every agent, subagents included, gets the rules of the folders it works under. A rule with paths: globs in its frontmatter loads only once the agent reads, writes or edits a matching file, so a Go style guide stays out of the context until the agent opens Go code.
DSH already loads AGENTS.md and CLAUDE.md. This plugin adds rules split by topic and by file type, the way .claude/rules/ and .cursor/rules/ work in other tools. It adds no tool and does not change the system prompt: a rule arrives as a message when it starts to apply, in subagents too.

Install
From the command line, with the name of the profile you run (here web):
dsh plugin --profile web add dsh-scoped-rules
--profile is required and goes before add.
In the Web UI: Plugins > Add plugin, then enter dsh-scoped-rules.
Installed from the Web UI, the plugin starts without a restart. After a command-line install, restart the profile if it is running. Sessions already open get their rules at their next step.
Requirements:
- DSH 0.2.x, from 0.2.2-rc.5 on. The tests run against the 0.2.2-rc.5 DSH packages and the newest 0.2.3 prerelease; the end-to-end check ran on DSH 0.2.3-alpha.2.
- Node 24 from 24.22.3, or Node 26.13.1 or later: the versions DSH supports.
- No model request, network call or file write is added: the plugin only reads rule files.
Quick start
-
Install the plugin (above).
-
In a project, add an always-on rule and a Go rule:
mkdir -p .agents/rules cat > .agents/rules/workflow.md <<'EOF' # Workflow Run the scoped tests before saying a task is done. EOF cat > .agents/rules/go.md <<'EOF' --- paths: ["**/*.go"] --- # Go Wrap errors with %w. EOF -
Start a session in that project and ask: "Which rules apply to you right now?" The agent names the workflow rule only.
-
Ask it to read a
.gofile of the project, then ask again. The Go rule is now listed too.
Write a rule
A rule without frontmatter always applies:
# Workflow
Run the scoped tests before saying a task is done.
A rule with paths: applies once a touched file matches one of its globs:
---
paths:
- "**/*.go"
- "**/go.mod"
---
# Go
Format with gofmt. Wrap errors with %w.
paths:takes a YAML list, an inline list (paths: ["src/**", "*.{ts,tsx}"]) or one string. A comma inside braces stays in its glob.globs:is read the same way.alwaysApply: truemakes the rule always apply, whateverpaths:orglobs:holds.- A
paths:key that gives no glob is reported and the rule is not loaded, rather than applying everywhere. A multi-line value (|,>) or an inline list split over several lines gives no glob. - A frontmatter without its closing
---is reported and the rule is not loaded. - Globs match the touched file's path relative to the directory that owns the rules folder, with Node's
path.matchesGlob. *and**do not match names starting with a dot. Write.github/**/*.ymlfor those. This holds forexcludetoo.
Rule files may sit in subfolders (go/style.md) and may be symbolic links (see Trust for where a link may lead). Files and folders whose name starts with . or _ are skipped, so _drafts/ holds work in progress.
Where rules come from
| Rules folder | Loaded |
|---|---|
~/.agents/rules/ | always |
.agents/rules/ of the working directory and of each of its parents | always |
.agents/rules/ between the working directory and a touched file | once the agent touches a file under it |
For an agent working in ~/code/shop that reads ~/code/shop/api/handler.go:
~/.agents/rules/loads: your personal rules.~/code/.agents/rules/loads: rules shared by every project in~/code.~/code/shop/.agents/rules/loads: the project's rules.~/code/shop/api/.agents/rules/loads after the read: the rules of that part of the project.
When each rule loads:
- Rules without
paths:in the home folder and in the working directory's folders load at the first step. - Rules without
paths:in a folder below the working directory load at the first step after a file under it is touched. - Rules with
paths:load at the first step after a matching touch. - Within one injected message, the broadest folder comes first. The injected text tells the agent that a more specific rule wins.
Two more cases:
- In a git worktree, the main checkout and the folders between it and the worktree do not count as parents. Their rules would repeat the worktree's own. Folders above the main checkout still count.
- A rule file reached twice in one step, through a symbolic link, loads once, from the most specific folder.
When rules load
- Before the agent's first model request, and at each later step when a new rule applies.
- Each rule loads once per session. A rule whose file changed loads again, marked as updated.
- The session log records which rules are loaded. Resume and fork keep that record. If compaction drops an injected rule from the context, an always-on rule of the home folder or of the working directory's folders loads again at the next step; any other rule loads again at the next touch of a matching file.
- Only the
read,writeandedittools count as touches. A path is resolved when the tool runs,~/included, the way DSH's file tools read it. A file reached through a shell command (cat,sed) does not trigger a scoped rule.
A loaded rule is withdrawn when it no longer applies:
- Its file was deleted.
- Its folder belongs to a project the agent left: the working directory moved, and the folder is no longer the home folder, a parent of the working directory or inside it. With
outsideWorkspace: true, only a deleted file withdraws a rule. - The next injected message says so in one line:
Rules no longer apply: <rule>; <rule>. Ignore them from now on. - A rule is never withdrawn because the agent stopped touching its files. Within one project, rules only add up.
What the agent sees
New rules arrive as one user message, added after the messages of the current step:
<system-reminder>
The following rules apply to your work. Follow them like workspace instructions: a more specific rule wins over a broader one, and none overrides system, developer or direct user instructions.
Rule from: ~/.agents/rules/workflow.md (always applies)
<rule text>
Rule from: ~/code/shop/.agents/rules/go.md (applies to: **/*.go)
<rule text>
</system-reminder>
The same message may also carry:
Updated rule from: <path>for a rule whose file changed.Rules no longer apply: <rule>; <rule>. Ignore them from now on.Rules not loaded: <rule> (message budget reached); <rule> (over the per-file limit). Read the file when its subject comes up.
Cost:
- Context: each rule enters the context once per session, again only when it changes or compaction dropped it. The intro and rules of one message fit in
maxBytes; the short notices come on top. - Prompt cache: the message joins the current step. Earlier messages and the system prompt do not change.
- Time: each agent step lists the rules folders and checks each rule file's size and modification time; unchanged files are not read again. Measured on Linux: about 6 ms per step with 4 rule files, 18 ms with 51.
Configuration
Set these in the plugin's settings, or in the profile's cordis.patch.yml row scoped-rules.
| Option | Default | Meaning |
|---|---|---|
rulesDir | .agents/rules | Rules folder name, relative to each directory that owns one. .claude/rules reuses Claude Code rules. |
maxBytes | 32768 | Byte budget for the intro and the rules of one injected message. Rules beyond it are named in a short notice (up to 10 names), not inlined. |
maxFileBytes | 16384 | Largest rule file loaded. A larger file is named, not inlined. |
exclude | [] | Globs, relative to a rules folder, of files never loaded, e.g. ["drafts/**"]. |
outsideWorkspace | false | Also load the rules folders above a touched file outside the working directory. |
A rule that does not fit is listed in a short notice so the agent can read the file itself.
Trust
A rule is an instruction to the agent. Treat a rules folder like an AGENTS.md: read the rules of a repository you did not write before working in it.
With the default outsideWorkspace: false, only the folders above the working directory and the folders between it and a touched file load. Reading one file of a cloned repository elsewhere on disk does not inject that repository's rules. Turn outsideWorkspace on when one agent works across several of your own projects from a common parent.
Limits that hold whatever a repository contains:
- Outside your home rules folder, a symbolic link is followed only when it stays inside the directory owning the rules folder. A cloned repository cannot point a rule at
~/.sshor~/.aws. - Each folder on the way to a rule,
.agentsincluded, and each rule file must be owned by you or by root. - Each of these folders and files must not be writable by every user. A
.agentsorruleslink is checked for its owner only; a link inside the rules folder is judged by its target. - Anyone can create
/tmp/.agents/rules; it does not load. - Windows reports neither owner nor mode, so these two checks do not run there.
- A touched file under
node_modules,vendor,.git,site-packages,dist-packages,bower_components,.venvorvenvdoes not load the rules folders of the package it belongs to. - A rules folder walk stops after 256 folders, so a link to a large tree cannot stall the agent.
- One step loads at most 512 rule files, across all rules folders. The home rules folder is read first, so up to 512 of its rules always fit. The rest is reported once and not loaded.
- Rule text does not close the reminder frame it is injected in: a closing
system-remindertag inside a rule, a glob or a path is escaped, spacing variants included. This guards the frame only; the rule text itself still instructs the agent.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
A paths: rule never loads | Only read, write and edit count; a file opened with cat does not. Globs match relative to the directory that owns the rules folder. * and ** skip names starting with a dot: write .github/**. |
| A rule never loads at all | Look in the DSH log for scoped-rules: skipped <path>: <reason>. Names starting with . or _, and files matching exclude, are skipped without a message. |
| A cloned repository's rules do not load | With the default outsideWorkspace: false, only the working directory's parents and the folders down to a touched file count. Start the session in that repository. |
(message budget reached) | Raise maxBytes, or give rules a paths: so fewer load at once. |
(over the per-file limit) | The file is larger than maxFileBytes. Split it or raise the limit. |
| A rule was edited | It loads again at the next step, marked Updated rule. |
| Reuse Claude Code rules | Set rulesDir to .claude/rules. |
A rules folder or rule file that cannot be read, or that fails a Trust check, is reported once in the DSH log; the other rules still load. If the working directory cannot be resolved, the step runs without new rules, and the touched files are retried at the next step. If a step is cancelled after the rules were added, the next step that runs adds them again. The plugin never blocks an agent.
Development
pnpm install
pnpm test
Node 24 from 24.22.3, or Node 26.13.1 or later: the versions DSH supports. The tests run the rule engine on temporary folders and the plugin entry point with a fake Cordis context.
- CI runs the tests on Linux with Node 24 and 26, with the locked DSH packages and with the highest ones the peer range accepts.
- CI also runs them on Windows with Node 24. The owner, mode and symbolic link tests are skipped there.
To try a checkout in DSH: Plugins > Add plugin with the checkout's absolute path.
Release a version
- Date its
CHANGELOG.mdentry:## [X.Y.Z] - YYYY-MM-DD. The release workflow refuses an undated entry. - Push the tag
vX.Y.Zfrom a commit onmain. The workflow checks, packs and publishes to npm, then publishes the GitHub release. - The workflow waits until npm serves the version as
latestwith a downloadable tarball. - Install it from a clean DSH profile before submitting it to a plugin list.