Skip to main content
M

dsh-token-squeeze

mutao106/dsh-token-squeeze

Squeezes every tool result before the model reads it, stripping terminal noise, folding JSON and console tables into compact records, capping oversized output with an on-disk spill and collapsing repeated results.

Install

dsh plugin --profile web add github:mutao106/dsh-token-squeeze

README

dsh-token-squeeze

Lossless-first tool-output compression for DeepSeek Harness.

Every tool result the model is about to read goes through one pass:

StepWhat it doesLoses content?
denoisestrips ANSI/OSC terminal escapes, collapses blank-line runs, folds long runs of an identical line into [… previous line repeated N more times]no
reshapeJSONL → compact record table, whitespace-heavy JSON → minified, aligned console tables → head/tail/omitted-rows tableyes, bounded
budgetcaps one result at budgetChars, keeping the head and the tail with an explicit N lines / M chars omitted markeryes, bounded
dedupea byte-identical result already returned earlier in the same session (same tool, same arguments) collapses to a one-line pointer at that earlier callyes, by design

Anything a lossy step drops is written to disk first (the spill), and the notice line in the compressed result carries the absolute path, so the model — or you — can read the original back at any time.

Two invariants hold on every call:

  1. Never worse. Content is only replaced when the new text is strictly shorter, and a lossy step must save at least minSavingChars on its own.
  2. Programs are untouched. The hook only rewrites model-facing content, never the programmatic value of a tool call, so PTC programs still see exact data.

Install

From GitHub — clone, then point dsh at the checkout:

git clone https://github.com/MuTao106/dsh-token-squeeze.git
dsh plugin add ./dsh-token-squeeze

From a local bundle (recommended if you already have the directory):

dsh plugin add E:\path\to\dsh-token-squeeze

or ask the agent to run plugin_manager with action install_bundle and the absolute package directory. The bundle's cordis.patch.yml inserts one plugin row with the defaults below; override any key by id: token-squeeze in a later profile patch layer.

Manual install: add the package to the profile's packages/ directory, then add "dsh-token-squeeze": "link:packages/dsh-token-squeeze" to the profile package.json dependencies and re-run the profile install. Do not hand-edit cordis.patch.yml — use a patch layer.

Configuration

KeyDefaultMeaning
enabledtruemaster switch
denoisetrueescapes, blank runs, repeated lines
reshapetrueJSON/JSONL/aligned-table compaction
budgettrueapply the character cap
budgetChars16000per-result cap; 0 disables
errorBudgetChars12000floor for failed results, so errors stay readable
minSavingChars800a lossy step must save this much to apply
minChars200ignore results shorter than this
skipTools["write","edit"]never rewrite these tools
dedupetruecollapse repeated results
dedupeTtlMs600000how long a fingerprint stays live
dedupeMinChars400only dedupe results at least this long
spilltruepersist the original before dropping content
spillDir""empty means ~/.dsh/token-squeeze/spill
spillMaxBytes4000000never spill originals larger than this
noticetrueprefix the one-line savings notice
verbosefalselog every rewrite to the plugin logger

A conservative profile for code-heavy work:

- id: token-squeeze
  config:
    budgetChars: 24000
    minSavingChars: 2000
    skipTools: ["write", "edit", "read"]

read results are already file-backed, so skipping them keeps exact source lines in front of the model.

Relationship to the built-in plugins

dsh-token-squeeze deliberately covers ground the stock plugins do not:

  • @deepseek-ai/dsh-spill-policy spills and truncates large results, but does not denoise, reshape, or deduplicate.
  • @deepseek-ai/dsh-compaction-tool-result-pruner prunes tool results later, at the Session layer. Running both is fine; the pruner then only sees text this plugin already shrank.
  • dsh-plugin-save-token (third-party) overlaps on blank-line and repeated-line collapse and on cross-turn dedupe. Running both double-rewrites the same result and doubles the notices — keep one of them enabled.

Cost model

No model calls, no network, no timers. The pass is pure string work plus, only when a lossy rewrite actually applies, one writeFile of the original. The estimate in notices counts CJK characters as one token and everything else at four characters per token.

Development

node --test          # the compressor's unit tests, no DSH needed

lib/compress.js is dependency-free and usable on its own:

import { squeezeText } from 'dsh-token-squeeze/compress'

const { text, steps, before, after, lossy } = squeezeText(raw, { budgetChars: 8000 })

Related plugins