dsh-rtk-plugin
其他 活跃维护

dsh-rtk-plugin

errrepe/dsh-rtk-plugin

集成RTK可复用token压缩,为高性能推理链路提供即插即用扩展。自动复用历史token,减少重复计算,提升长上下文推理速度与吞吐,安装简洁,不改现有调用逻辑。

0
Stars 标星
0
Forks 分支
0
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
32 KB
仓库大小
3 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:errrepe/dsh-rtk-plugin
git clone https://github.com/errrepe/dsh-rtk-plugin.git
git clone git@github.com:errrepe/dsh-rtk-plugin.git
README.md main

dsh-rtk-plugin

RTK (Reusable Token Kompressor) tool for
DeepSeek Harness — a
high-performance CLI proxy that filters and compresses command output
before it reaches the model context, saving substantial tokens.

This bundle exposes RTK as a model-facing rtk tool through the standard
ctx.shell capability seam, so every call inherits the harness's sandbox
policy, timeout handling, and cancellation
exactly like the native bash
tool.

What the tool does

The model (and you, via @) gets one tool, rtk, that runs any RTK
subcommand with token-optimized output:

Subcommand Use
read <file> Read a file with intelligent filtering (-n line numbers, -m N max lines, --tail-lines N, -l minimal\|aggressive)
ls / find Compact directory listing / file finding
git <args> Compact git output (status, log, diff, branch…)
grep / rg Compact search, grouped by file
err -- <cmd> Run any command, show only errors/warnings
test -- <cmd> Run tests, show only failures
json <file> Compact JSON (-d depth, --keys-only for structure only)
deps Summarize project dependencies
diff / log / wc Condensed diff / deduplicated logs / compact counts
smart <file> 2-line technical summary of a file
summary -- <cmd> Heuristic summary of command output

Plus wrappers for tree, gh, glab, aws, psql, pnpm, docker, kubectl, jest, vitest, prisma, tsc, next, lint, prettier, cargo, npm, npx, ruff, playwright, dotnet, wget, env, curl, format.

The tool's command parameter takes the subcommand without the leading
rtk (e.g. read -n -m 50 package.json, git status, err -- npm run build).

Prerequisites

  • RTK installed and on the PATH the shell
    executor uses (brew install rtk / rtk --version to check). If it lives
    elsewhere, see Configuration.

Install

Into a profile (recommended — survives restarts):

dsh plugin --profile web add dsh-rtk-plugin        # from npm (once published)
dsh plugin --profile web add /path/to/dsh-rtk-plugin  # from a local checkout

Then restart dsh web (or the profile's host) for the composition to pick
up the new bundle row.

Uninstall / disable

dsh plugin --profile web remove dsh-rtk-plugin

Or disable just the row in the profile's cordis.patch.yml:

- id: rtk
  disabled: true

Default routing (enforced)

By default (guardBash: true) every single bash command whose first word
maps 1:1 to an RTK wrapper (grep, rg, ls, cat→read, git, wc,
find) is denied at the tools/guard layer. The denial message tells the
model to retry through the rtk tool:

Route 'grep' through the rtk tool ... Retry as rtk command 'grep …'

Compound or piped commands (|, &&, ;, `, $(, >, <, () and
multi-line scripts are exempt — RTK cannot wrap them, so they run raw.

Explicit opt-out: when the model really needs raw output, it appends a
shell comment that the guard checks for:

grep pattern file.txt # no-rtk   # or: # raw

Either marker lets the call through.

Settings UI (enable/disable)

Since 0.3.0 the plugin exposes a persisted toggle in the browser, like dsh-simple-english:

  • Composer chip (conversation.input.left) — label RTK: On/Off, always visible while typing. Click to flip enabled.
  • Settings > General row — shows RTK title, hint, enabled toggle, guard toggle, and rtkPath input.
  • Settings > Plugins card — same controls inside the plugins configurable tab (settings.plugin.item), so the plugin appears where you expect it.

All three read and write through /api/dsh-rtk/{describe,mutate} (loopback-only) and persist to ~/.dsh/settings.yaml:

rtk:
  enabled: true      # master switch — when false, tool advises to enable and guard is off
  guardBash: true    # when true, single bash with wrappable tokens is denied
  rtkPath: rtk       # binary path, e.g. /opt/homebrew/bin/rtk

The settings layer resolves as: schema defaults → composition base (your cordis.patch.yml config) → user document (settings.yaml). Changing the UI re-shapes the very next model step via system prompt and guard.

i18n: the client detects navigator.language and shows labels in English, Chinese (zh), or Portuguese (pt).

Disable via code still works:

- id: rtk
  disabled: true

Or via CLI:

dsh plugin --profile web disable dsh-rtk-plugin
dsh plugin --profile web enable dsh-rtk-plugin

System prompt (always use RTK)

When enabled is true, the plugin registers a system prompt section tool:rtk at order 106 (near tool guidance):

RTK (Reusable Token Kompressor) is installed. Prefer the rtk tool for token-optimized output over raw bash. Use rtk read for file reads (cat maps to read), rtk grep/rg for search, rtk ls/find for listings, rtk git for git status/log/diff, plus rtk json, smart, diff, log, wc, deps, err, test, summary. Single bash commands with wrappable tokens (grep, rg, ls, cat, git, wc, find) will be denied — retry as rtk without leading rtk. Compound, piped, or multi-line commands run raw. Append '# no-rtk' or '# raw' to force raw output. rtk gain tracking needs workspace-write and may fail under sandbox — expected, not a bug.

When enabled is false, the section returns empty string and leaves no residue. When guardBash is false, the prompt says "Guard is off: rtk is opt-in, but prefer it".

This matches RTK upstream's hook behavior — the model should always use RTK for single commands that RTK wraps, and fall back to raw bash only for pipes/compounds or explicit bypass.

Configuration

The bundle row accepts options via the profile's cordis.patch.yml (the base layer that seeds the settings namespace on first run):

- id: rtk
  name: 'dsh-rtk-plugin'
  config:
    enabled: true                     # default: true — set false to start disabled
    rtkPath: /opt/homebrew/bin/rtk   # default: 'rtk' (PATH resolution)
    guardBash: true                   # default: true — set false to keep rtk opt-in

After first start you can edit the same keys in Settings UI instead of YAML — the UI writes to ~/.dsh/settings.yaml and survives restarts.

Notes and limitations

  • rtk gain (savings history) may fail under a file sandbox because its
    tracking DB lives outside the session workspace — expected, not a tool bug.
  • RTK output is already token-optimized; avoid piping it through additional
    filters.
  • Non-zero exits are reported as [exit code: N] markers; sandbox denials
    as [sandbox: file access denied under <mode> mode] — the same vocabulary
    as the native bash tool.

Development

npm test    # smoke tests (no harness needed)

Pure JavaScript, no build step — index.js is the published source.

License

MIT