dsh-rtk
A DeepSeek Harness plugin that
routes eligible bash commands through RTK (Rust Token Killer) so the output
an agent reads back is already filtered, grouped, truncated, and deduplicated —
saving context tokens the same way RTK's own agent hooks do.
- Zero prompt changes: the
bash tool keeps working, but commands like
git status, cat src/main.rs, grep -rn TODO src, npm test, git diff,
and find . -name '*.ts' are transparently rewritten to their rtk
equivalents (rtk git status, rtk read src/main.rs, rtk grep ...,
rtk cargo test, ...) before execution.
- Fail-open: if RTK is not installed, times out, has no equivalent for a
command, or a deny rule matches, the original command runs unchanged.
- An
rtk skill is registered for the agent, teaching it how to interpret
compressed output, recall elided content (rtk recall), bypass filtering
(rtk bypass), and read savings analytics (rtk gain).
How it works
DSH's tool pipeline deliberately cannot rewrite exec.arguments (tools/pre-execute
and tools/execute receive deep-frozen arguments). Instead, this plugin wraps the
shell executor seam: the bash tool resolves a ShellExecSpec through
ctx.shell.resolve(...) and spawns with ctx.shell.execute(spec). The plugin
wraps ctx.shell.execute and, for each command, calls rtk rewrite <command>
(RTK's own "single source of truth" hook command):
rtk rewrite exit | meaning | plugin behavior |
|---|
| 0 / 3 | rewrite printed | executes the rewritten rtk ... command |
| 1 | no RTK equivalent | passes the command through unchanged |
| 2 | deny rule matched | passes through (DSH's own approval already ran) |
| spawn error / timeout | RTK unavailable | passes through; failure is not cached |
The rewritten command runs with RTK_SUPPRESS_HOOK_WARNING=1 so RTK's
"install a hook" nag never pollutes tool output. A bounded LRU cache avoids
re-spawning rtk rewrite for repeated commands.
Sandboxing is unaffected: the sandbox executor still applies the configured
sandbox mode to the spawned process, and RTK preserves exit codes, so the
[exit code: N] markers stay accurate.
Installation
The plugin is a DSH bundle (an npm package whose package.json declares
dsh.bundle.patch). Install it into a profile with the plugin manager:
- Web UI: open the Plugins page in the DeepSeek Harness sidebar and
install the bundle by spec (registry name
dsh-rtk-compressor, git URL
https://github.com/sondin/dsh-rtk, or a local
link:/absolute/path/to/dsh-rtk).
plugin_manager tool: call installBundle with the same spec.
- CLI (when available):
dsh plugin --profile <profile> add <spec> then
enable the dsh-rtk bundle.
The bundle's cordis.patch.yml mounts the plugin row:
- insert:
- id: rtk
name: dsh-rtk
config:
enabled: true
After installation, restart DSH (or rely on HMR when the profile runs with
live patch reload). The plugin takes effect for every bash tool call.
Configuration
The plugin row accepts a Schemastery config:
| field | type | default | description |
|---|
enabled | boolean | true | master switch; when false every command passes through |
binary | string | "rtk" | path to the RTK binary |
timeoutMs | number | 2000 | per-rtk rewrite call timeout |
cacheSize | number | 256 | LRU cache size for rewrite results |
excludedCommands | string[] | [] | command prefixes that are never rewritten |
debug | boolean | false | log each rewrite decision to the harness logger |
Example:
- id: rtk
name: dsh-rtk
config:
enabled: true
excludedCommands:
- sudo
- ssh
debug: false
Skill
When the skills service is present (it is in the default composition), the
plugin registers a runtime skill named rtk. The skill tells the agent:
- bash output may be compressed; exit codes remain accurate
- use
rtk recall <hash> / rtk recall --grep <pattern> to recover elided content
- use
rtk bypass <command> to execute a command without filtering
- use
rtk gain, rtk discover, rtk session for savings analytics
Development
pnpm install
pnpm test
Tests cover the rewrite decision logic (with a fake shell executor), the disposer
restoring the original executor on plugin unload, and the real rtk rewrite
CLI behavior (rewrites, chains, no-equivalent, already-rtk commands).
Related projects
- DeepTrial/dsh-bash-rtk — a
TypeScript implementation of the same idea (subclassing the official DSH
executors with a whitelist-based rewrite). This project differs by rewriting
command chains (
a && b), using RTK's own rtk rewrite as the source of
truth (so new RTK commands work without plugin updates), registering an rtk
skill for agents, and requiring no build step.
- rtk — the Rust Token Killer CLI this plugin
routes commands through.
License
MIT