dsh-dialog-fence: Dialog Behavior Guardrail Preserving Prefix Cache

Preface

When running agents in DSH (DeepSeek Harness), the model “forgets” the rules you set for the current conversation every round. Common workarounds each carry costs: writing rules into the system prompt tends to invalidate the entire prefix cache whenever content changes; appending rules via user messages each round is safe but will consume a huge number of tokens after dozens of rounds; relying on the compression plugin’s built-in rule capabilities may, in some versions and modes, store rules without injecting them.

Below is the community plugin dsh-dialog-fence (maintained by ILoveHAKU): it writes general rules and session-specific rules into a single JSON file and injects them into the runtime context snapshot, so that constraints take effect from the next round onward — without touching the system prompt and without repeatedly consuming tokens when the rules haven’t changed. It applies to dsh CLI (web / headless / acp and other profiles) and DSH Desktop.

What Is This

dsh-dialog-fence is a set of “dialog fences”: behavioral constraint rules that can be added or removed at any time, all stored in a single JSON file (default <DSH_HOME>/dialog-fence/fence.json), which can be edited directly with an editor or maintained item by item in the DSH settings page and the session overlay.

Rules are injected in two stacked layers:

  1. General rules (the rules array in fence.json) — take effect for every conversation, including newly started ones.
  2. Session rules (sessions.<session id>.rules in fence.json) — take effect only for a specific conversation; optional; usually maintained in the “Fence” overlay at the top-right corner of the session.

The plugin concatenates both layers of rules into text and writes it into the runtime context via systemPrompt.context({ name: 'dialog-fence:rules', order: 118 }); it coexists with billion-context compression (the snapshot header Current runtime context is classified as durable/runtime-context). When the master switch is off, or both the general and session layers are empty, it renders as an empty string with no additional tokens produced.

Community directory page: dsh-dialog-fence @ SkillHub. Source code and documentation: GitHub - ILoveHAKU/dsh-dialog-fence. Current package version 0.10.0 (per the repository’s package.json); declared compatible with DSH 0.2.0-rc.2.

Core Features

Caching and Context Behavior

  • Doesn’t touch the system prompt: in the history, only pure appends occur when rule text changes; the prefix is never rewritten.
  • No injection if the text is unchanged: when the runtime context snapshot is identical to the previous one, no extra user message is sent every round.
  • Isolated from other conversations: when the general rules are empty and the current session has no session-specific rules enabled, there is zero injection and zero side effects.

Configuration and Interface

Five entry points read and write the same fence.json; changes are saved to disk and take effect at the next round’s assembly time, with no restart required (installing/uninstalling the plugin itself still requires fully exiting and restarting DSH):

Entry Point Description
Settings left column → “Dialog Fence” Master switch, visual editing of general rules, selecting and editing session-specific rules by conversation name, “Open Folder”, “Change Location”
Plugins → Installed → dsh-dialog-fence detail page The same configuration area (bundle slot plugins.bundle.config)
“Fence” button at the top-right of the session The badge shows the actual number of injected rules (general + current session); opens the overlay to edit the current session’s and general rules
Rules overlay Multi-line editing, enable/disable, add/remove; closes when clicking outside the panel
Settings → Built-in Plugins → “Dialog Fence” tab Legacy entry point, identical behavior

The above panels are only available in Web / Desktop; CLI / TUI / headless without a connection service will skip UI routing, but slash commands remain available.

Slash Commands (All Forms)

Command Function
/fence Status: enabled or not, number of rules, injected text, token estimate, file path
/fence on / /fence off Enable/disable session-specific rules for the current session (doesn’t affect general rules)
/fence add <text> Append a session-specific rule
/fence rm <index> / /fence clear / /fence reset Delete a rule, clear session rules, delete the session record
/fence dir / /fence open / /fence file <path> Path, open folder, move the fence file
/fence switch on / switch off General master switch
/fence all and all add / all rm / all clear View and manage general rules
/fence help Help

You can also use the environment variables DIALOG_FENCE_FILE or DIALOG_FENCE_HOME to specify the file or base directory; “Change Location” in the settings page leaves a location.json pointer in the original directory.

Installation and Activation

The official plugin installer is recommended (the card appears in the “Installed” group and can be uninstalled with one click). Since 0.5.0, the plugin is installed as a bundle (dependencies + dsh.profile.bundles + dsh.bundle.patch). After changing the installation method, you must fully exit and restart DSH (the host side does not use dsh-hmr hot reload).

GUI: left side “Plugins” → top-right “Add Plugin” → fill in the absolute path of this package on your machine in the input field (the example is the copy path under the default harness directory on Windows Desktop; please fill in according to your actual machine path):

C:\Users\<you>\AppData\Roaming\dsh-desktop\harness\dialog-fence

Command line (example when the profile is web):

dsh plugin --profile web add "C:\Users\<you>\AppData\Roaming\dsh-desktop\harness\dialog-fence"

Note: the Desktop installation backend copies the source directory to the generation snapshot before running pnpm add; changing the source in the original directory under harness will not automatically reflect in the installed copy — you need to uninstall and reinstall or rerun the above command. Rule data is stored in <DSH_HOME>/dialog-fence/, independent of generation, so upgrades won’t lose rules.

Method B: file:/// Mount (Development)

Run in the root directory of the plugin repository:

node scripts/install.mjs install

The script appends marked file:/// insertion lines to <DSH_HOME>/profiles/<profile>/cordis.patch.yml; changing client.js only requires a refresh, while changing index.js requires a restart. This method will not appear in the “Installed” list; do not use it together with Method A. Before switching back to Method A, run node scripts/install.mjs uninstall first.

Verification

After restarting and enabling the fence, run the following in the conversation:

/fence status

If a paragraph starting with Dialog fence (user-set rules binding this conversation; ...) appears in the runtime context of the next round, it indicates that injection succeeded. Without a host self-check, you can run:

node test/smoke.mjs && node test/route.mjs && node test/client.mjs && node test/render.mjs && node test/opensource.mjs

Typical Usage

Directly Editing fence.json

Key points of the structure of the default file <DSH_HOME>/dialog-fence/fence.json:

{
  "version": 3,
  "enabled": true,
  "rules": [
    "结论必须给出可复现证据(命令 / 文件:行号 / 实测输出三者至少其一);给不出就明说「未验证」。"
  ],
  "sessions": {
    "<会话 id>": {
      "enabled": true,
      "rules": ["本会话额外一条约束"]
    }
  }
}

When enabled: false, all conversations have zero injection, and the file content is preserved.

Panel and Command Combination Example

  1. In Settings → “Dialog Fence”, add general rules for all conversations (e.g., “read the file before modifying it”).
  2. Click “Fence” in the current session, and append a rule only for this conversation (or use /fence add 不要执行 destructive git 命令).
  3. Use /fence to view the number of rules and the estimated tokens; use /fence off to temporarily disable the session-specific layer without affecting the general layer.

All UI changes take effect in the next round; after turning off the master switch, there is immediate zero injection.

Applicable Scenarios and Caveats

Suitable for: conversation-level rules that need long-term, version-controllable management; wanting to coexist with prefix caching and billion-context compression; wanting visual maintenance in Desktop / Web while also scripting with /fence in headless mode.

Caveats:

  • The plugin runs under the permissions of the current dsh process; before installation, please read the source code and license of the GitHub repository (the repository includes LICENSE).
  • The community directory SkillHub has no official affiliation with DeepSeek / Huanfang; the DSH ecosystem follows the principle of “everything is a plugin”, and installation sources need to be evaluated by yourself.
  • Node >= 20.16.0 is required (for development scripts and tests); when Desktop has no standalone node, the README provides an example of running install.mjs with Electron.
  • Local path installation is a copy rather than a symbolic link; prefer Method B for development iterations, and Method A for daily use.

Conclusion

dsh-dialog-fence consolidates “rules that need to be re-emphasized every round” into a single JSON and one layer of runtime context injection: it doesn’t touch the system prompt, doesn’t consume extra tokens when the rules are unchanged, and still preserves the latest snapshot through the durable runtime-context after compression. If you’re already using DSH for long-conversation agents, it’s worth trying a round with /fence status and the “Dialog Fence” in the settings.

  • Directory page: https://www.skillhub.cn/plugins/ILoveHAKU/dsh-dialog-fence
  • GitHub: https://github.com/ILoveHAKU/dsh-dialog-fence
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye