DSH Token Saver: Compressing Context Usage at Tool Boundaries

Introduction

When running agents in DeepSeek Harness (DSH), context is often filled up first by tool outputs: reading a large file, grep-ing a whole dump, or verbose command logs can stuff tens of thousands of bytes in at once, and the model has to carry these tokens through subsequent multi-turn dialogues. Common workarounds include manual truncation or using smaller queries, but to handle this stably after every tool return, it is better to implement it as a DSH plugin that hooks into the tool execution chain for unified trimming.

Below is an introduction to the community plugin dsh-token-saver (maintainer LoveDoLove, GitHub repo LoveDoLove/dsh-token-saver). It intercepts oversized outputs at the DSH tool execution boundary: retaining heads and tails, folding grep results, optional RTK compression and context-pressure handling, while supporting configuration and savings statistics viewing within DSH Web. Plugin catalog page: skillhub.cn/plugins/LoveDoLove/dsh-token-saver (Community catalog, no official affiliation with DeepSeek / High-Flyer).

What is this

DSH Token Saver is a configurable token efficiency plugin for DeepSeek Harness: it shrinks the size of file reads, greps, command logs, etc., before tool results enter the conversation, and optionally performs context-pressure handling, prompt shaping, local responses, and LLM summary compaction. By default, only relatively conservative trimming and grep folding are enabled; RTK, Caveman/Ponytail, local responses, and LLM summaries are independent switches that are off by default.

How it works

The plugin hooks into the DSH tool execution pipeline. The flow in the README can be summarized as:

  1. Post-execute hook: After a tool returns, perform head/tail retention or folding for overly long results (grep retains matching lines; if RTK is enabled, it performs structured compression on supported command outputs).
  2. Context-pressure handling: In balanced / aggressive modes, further compaction can be triggered when context pressure exceeds a threshold.
  3. LLM-summary compaction: Optional in balanced / aggressive modes; replaces large blocks of output with LLM summaries (requires callLlm configuration).
  4. Prompt-cache stability: Rearranges system prompt sections to stabilize the order of cacheable segments.

All paths are fail-open: if optimization fails, the original content is preserved; tool results marked as errors will not be compacted by the tool output filter.

Core Features

The following capabilities align with the README feature table; the meaning of the “Default” column is subject to the repository documentation.

Feature Description Default
Tool-output trimming Retain head and tail of overly long tool results Enabled except off
Grep folding Fold large greps, retaining useful context Enabled except off
Context-pressure handling Track context pressure; higher modes may trigger compaction Off for conservative; On for balanced/aggressive
RTK integration Compress supported command outputs via RTK Off
Caveman / Ponytail prompt shaping Configurable concise or minimally modified task styles Off
Local responses Respond locally to certain probe patterns without calling LLM Off
LLM-summary compaction Optional LLM summary compaction Off (effective only in balanced/aggressive)
Prompt-cache stability Stabilize system prompt section order Applied except off
Web settings Configure via DSH Web Settings → Token Saver Available

The master mode switch mode takes values off, conservative, balanced, aggressive: the default conservative only performs trimming/folding and retains DSH’s normal mode compaction paths; aggressive enables more radical compaction behaviors (potentially replacing the built-in compaction provider by default), so it is recommended to read the configuration instructions thoroughly before enabling.

Installation and Activation

The commands given in the official Quick install and Install sections are as follows (web profile subject to README):

dsh plugin --profile web add github:LoveDoLove/dsh-token-saver

If the installation process requires approval for a build script, approve it according to the instructions printed by DSH/pnpm and retry, then reload or restart the corresponding DSH profile according to local requirements. The README suggests using the GitHub repository and Releases as the version source; to pin a version, you can install the v1.0.4 currently documented:

dsh plugin --profile web add github:LoveDoLove/dsh-token-saver#v1.0.4

Release v1.0.4 also provides a pre-built package dsh-token-saver-1.0.4.tgz, which can be installed as a local package when there is no local build environment. package.json specifies the runtime environment as Node >=22.19.0 and the license as MIT.

Configuration Examples

Besides the Web panel, configuration can be done via the DSH bundle. README example:

dsh-token-saver:
  mode: conservative # off | conservative | balanced | aggressive
  rtkEnabled: false
  cavemanLevel: off # off | lite | full | ultra | wenyan-lite | wenyan | wenyan-ultra
  ponytailLevel: off # off | lite | full | ultra
  localResponsesEnabled: false
  localResponses: [quota, prefix, title, suggestion, filepath]
  llmSummaryEnabled: false

Common items (default values see README “Key options” table):

  • headBytes / tailBytes: Default 16384 / 8192 each; results are not modified if their length does not exceed headBytes + tailBytes + 256.
  • grepMaxMatches / grepContextLines: Default 30 / 2.
  • grepHeadBytes / grepTailBytes: Default 8192 / 4096.
  • pressureThreshold: Default 0.5.
  • includeToolNames / excludeToolNames: Limit or exclude tool names participating in trimming.
  • cacheStableSections: System prompt section IDs that need to be fixed at the front, beneficial for prompt cache.

Specific behavior relates to the installed DSH version and is subject to the settings panel and configuration defaults of the current build.

Statistics and Observability

The DSH Web settings page displays real-time savings telemetry; cumulative data is written to ~/.dsh/token-saver/stats.json (or $DSH_HOME/token-saver/stats.json), so historical totals remain readable on the dashboard after a host reboot. Metrics include Saved (bytes reduced by compaction), Saved ratio, Calls (number of compaction invocations that produced at least one trimmed block), and Blocks (number of text blocks actually compacted). The same output may be compacted once in the post-execute path and once in the LLM/stream path, so the meanings of calls and blocks differ; Saved bytes accumulate across passes. Persistent accumulation is supported since v1.0.2; for earlier versions, the dashboard resets to zero after a restart.

Use Cases and Notes

Who it is for: Teams or individuals developing agents long-term under the DSH Web profile, frequently reading files and grepping, with context often hitting the ceiling; scenarios wanting conservative defaults with RTK or LLM summaries enabled on demand.

Security and Permissions: The plugin runs with the same permissions as the current DSH process; please read the repository source code and MIT license before installation to confirm that build scripts and dependencies comply with local policies. Error-class tool outputs will not be compacted; optional capabilities must be explicitly turned on.

Ecosystem Position: DSH emphasizes “everything is a plugin”; skillhub.cn is a community plugin catalog, not an official app store.

Conclusion

DSH Token Saver places token savings at the tool return layer: default trimming and grep folding can alleviate context pressure, while higher modes and RTK, LLM summaries, and prompt shaping can be layered on demand. Installation and versions are subject to the README; for further information, see the catalog page LoveDoLove/dsh-token-saver and GitHub LoveDoLove/dsh-token-saver.

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

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

Xiaoye