dsh-rtk-optimizer: Bash Rewriting Suggestions and Tool Output Compression

Foreword

When running agents in DSH, the returns of bash, grep, and read often consume a large amount of context: verbose test logs, terminal output with ANSI codes, and repetitive git status lines all crowd out the tokens available to the model. On the other hand, even if the rtk command line (rtk rewrite) is installed on the local machine, the model may still write out unrewritten shell commands directly, wasting a round of invocation or producing suboptimal syntax.

dsh-rtk-optimizer is a community-maintained DSH workflow plugin (maintainer sleepinginsummer), with logic ported from pi-rtk-optimizer in the Pi Coding Agent ecosystem. It does not register new tools with the model; instead, it hooks into two tool events on the Host, globally affecting bash/grep/read invocations across all sessions: on one side, it provides RTK rewrite suggestions before execution (or, under configuration, approaches auto-rewriting via deny+feedback); on the other side, it compresses text output via a pipeline after execution succeeds. The following describes its positioning, capabilities, and installation and usage.

What Is This

In one sentence: dsh-rtk-optimizer is a DSH Host interceptor plugin that provides RTK command rewrite suggestions and tool output compression, and lets you view configuration and statistics via /rtk.

The plugin itself does not register model tools; rewriting and compression are both implemented via the tools/pre-execute and tools/post-execute hooks.

Core Functions

RTK Command Rewriting (pre-execute)

When the model calls bash, if a usable rtk binary exists on the local machine, the plugin invokes rtk rewrite <command> to participate in decision-making.

  1. mode: suggest (default)
    Does not interrupt this bash call; appends [rtk-optimizer] rtk suggests: ... at the end of the tool result, so the model can adopt it in subsequent rounds.

  2. mode: rewrite (default off, needs to be switched via /rtk)
    For cases that require rewriting, it denies the call once and provides the rewritten command in the error feedback; the model uses the new command when retrying. The README notes: rtk rewriting is idempotent and will not form a loop; the same command is denied only once within 30 seconds.

DSH tool parameters are immutable in the dispatch pipeline (tools/execute can only modify exec.signal), so “auto-rewriting” is architecturally implemented via deny + feedback, which is the closest semantic to auto-rewriting under the current design.

When rtk is not installed: the original command is executed as-is (guardWhenRtkMissing: true); the detection result is cached for 60 seconds and not probed repeatedly. The implementation adapts to rtk 0.43: a successful rewrite may return exit code 3 (rather than the documented 0), and the plugin accepts both 0 and 3; for unsupported commands with exit code 1 and no output, the command is passed through as-is.

Output Compression (post-execute)

For successfully returned text output from bash/grep/read, the compression pipeline is applied according to configuration (each stage can be toggled individually):

Stage Description
ANSI stripping Removes CSI/OSC color control sequences
Git compression Summarizes git status --short lines into one line of statistics; shortens 40-character commit hashes to 7 characters
Test aggregation Keeps the Tests: N passed, M failed summary and failure lines, folds the rest (triggered by commands such as jest/mocha/vitest/go test/pytest)
Build filtering Only keeps error/warning lines and summary statistics (triggered by build/tsc/make/npm etc.)
Search grouping Groups path:line:content lines by file (grep tool output)
Smart truncation When exceeding maxOutputChars (default 30000), keeps the head and tail and inserts a truncation marker in the middle

The plugin tracks the number of characters saved per call, which can be viewed via /rtk stats.

/rtk Command

After installation and restarting DSH, it can be used within a session:

/rtk [show|verify|stats|clear-stats|reset|set|help]
Subcommand Description
show Current configuration, rtk binary status, statistics
verify Check whether the rtk binary is available (detection cache 60s)
stats / clear-stats View or reset compression savings statistics
set <key> <value> Switch at runtime: mode (suggest | rewrite), enabled, guardWhenRtkMissing, readCompaction
reset Restore default configuration

Installation and Activation

The installation method given in the official README is as follows (replace <name> with your profile name):

dsh plugin --profile <name> add dsh-rtk-optimizer

After installation, restart DSH. Compression and rewriting take effect for bash/grep/read invocations across all sessions; use /rtk show to confirm the configuration and rtk detection status.

The DeepSeek Harness community plugin directory is displayed on sites such as SkillHub, and has no official affiliation with DeepSeek / High-Flyer; before installing, it is recommended to read the repository source code and MIT license, and be aware that the plugin runs with the permissions of the current dsh process and intercepts and rewrites data along the tool chain.

Typical Usage

View the current status and whether rtk is available:

/rtk show
/rtk verify

Switch between suggest and rewrite (rewrite denies once and returns the new command in feedback):

/rtk set mode suggest
/rtk set mode rewrite

View the cumulative number of characters saved by output compression:

/rtk stats

Disable at runtime or restore defaults:

/rtk set enabled false
/rtk reset

If rtk is not installed locally, rewriting-related logic passes the original command through according to guardWhenRtkMissing; output compression can still work independently in the post-execute pipeline (depending on enabled and each stage switch).

Use Cases and Notes

Suitable for:

  • Long-term use of agents in DSH to run tests, builds, and repository searches, with the goal of reducing the context volume fed back from bash/grep/read;
  • Already installed or planning to install the rtk CLI, hoping the model sees rewrite suggestions before bash invocations, or, in rewrite mode, approaches auto-rewriting via deny+feedback.

Notes:

  • The plugin does not add model-visible tools; its behavior entirely depends on Host events; this differs from the integration approach of “adding a rewrite tool to the model”.
  • rewrite mode intentionally denies one invocation; the model must retry based on the feedback; the same command will not be denied repeatedly within 30 seconds.
  • Compression targets successfully returned text; failures or empty output do not go through the same “savings” logic.
  • The repository README notes that developers can run npm test to execute 20 test cases (ANSI, git compression, search grouping, test aggregation, build filtering, truncation, etc.), making it easy to self-verify pipeline behavior.

Conclusion

dsh-rtk-optimizer bundles “RTK rewrite suggestions” and “tool output compression” into a single global Host plugin: it does not change the model’s tool list, yet helps you save context before and after each bash/grep/read and aligns with rtk rewrite habits. For further documentation and issues, see the GitHub repository and the SkillHub directory page.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye