dsh-ctx-trim: One-click manual compression of session header context

Introduction

After running a long session for a while, the context can easily grow to several hundred thousand tokens. DSH’s built-in automatic compression only keeps the last message, discarding all previous content. You want to decide for yourself “which turn to cut to” and “how much original text to keep,” but you can’t find the entry point. dsh-ctx-trim fills this gap: it adds a “Context” button to the right of the session title. Clicking it opens two compression modes, and the summary is generated locally without calling the model.

What is this

dsh-ctx-trim is a DSH client plugin maintained by AlexSh1ne. It solves a single problem: allowing developers to manually select a compression level without interrupting the flow, replacing the top context of the session with a local summary. It targets scenarios where “automatic compression is too aggressive and lacks control,” rather than being a generic session management tool.

Core Feature: Two Compression Modes

When the button is opened, the panel displays two rows of numbers corresponding to the two modes:

Mode Retain Lower Limit Extra Action
Normal Compression Recent 30% of original text At least 6k —
Deep Compression Recent 10% of original text At least 2.5k The cut original text is packed into ~/.dsh/im/ctxpacks/

The cut points fall on structural boundaries: it does not cut in the middle of a tool call, nor in the middle of a compression marker. Therefore, the compressed session remains a valid conversation.

Where Does the Summary Come From: Local Summary Without Model Calls

The summary is retrieved in the following order:

  1. Priority is given to the local summarizer in dsh-live-compact/plan.js within the same profile. If this plugin is installed, it is used; otherwise, it is skipped;
  2. If neither is available, use the built-in excerpt: keep only the beginning of each message and preserve mandatory clause lines.

No model is called throughout the process, so there are no costs and no waiting for generation. There is also a safeguard: if the calculated summary is larger than the original text that was cut, this run is aborted without writing to disk. It is better to leave it untouched than to write a longer context.

How It Ensures “Only Compress When Idle”

The plugin follows the DSH public compression transaction:

compaction/start → compaction/summary → user/message(replace) → compaction/end → flush

It is wrapped in agent.runMaintenance, which is mutually exclusive with the currently running turn. So, if you click the button while the current turn hasn’t finished, it will clearly prompt that the session is running and to wait until the turn ends before compressing, preventing corrupted logs.

Installation and Enablement

Use the official installation command; do not install into a regular project using npm i dsh-ctx-trim:

dsh plugin --profile <your-profile> add dsh-ctx-trim

After installation, refresh the page, and a “Context” button will appear to the right of the session title.

Installing directly via npm from a regular project will lead to issues; it will try to resolve @deepseek-ai/* peer dependencies, resulting in a string of ERESOLVE errors. The entry point for all DSH plugins is dsh plugin add, and the plugin marketplace follows this path as well.

Typical Usage

Click button → Check two lines of numbers in the panel → Click one mode → Wait for it to finish. There are no extra configuration items; the retention ratio is hardcoded into the two modes.

The plugin also exposes two routes, used by the client, but you can also use curl yourself:

# Check the current number of messages in this session and how much each mode will cut
curl "http://<host>:<port>/dsh-ctx-trim/status?sessionId=session-xxx"

First try a dry run (no disk write) to see how much is cut and how large the summary is:

curl -X POST http://<host>:<port>/dsh-ctx-trim/run \
  -H 'content-type: application/json' \
  -d '{"sessionId":"session-xxx","mode":"normal","dry":true}'

Confirm it works, then compress for real:

curl -X POST http://<host>:<port>/dsh-ctx-trim/run \
  -H 'content-type: application/json' \
  -d '{"sessionId":"session-xxx","mode":"deep"}'

The API only accepts application/json; cross-site requests from other sites in the browser (with sec-fetch-site: cross-site) will receive a direct 403.

Suitable Scenarios and Limitations

Suitable for DSH developers who need to control the retention range in long sessions, especially those who don’t want to rely on automatic compression and want to keep a recent segment of original text.

It has several clear limitations that you should know before using:

  • Only compress when the session is idle; compression during a turn is rejected. This is intentional;
  • No undo button. The collapsed original text still exists in the session log, but is invisible on the interface;
  • Only available on the Web client;
  • Retention ratios are hardcoded into two modes; custom ratios are not currently supported;
  • It does not use ctx.compaction.compactRegion, which hardcodes owner:'current-turn'. It will definitely throw no open turn on an idle session.

Security Note: The routes do not perform identity verification (it cannot access the GUI’s login state) and only block cross-site requests. In other words, anyone who can connect to the host port and knows a session ID can compress that session. Do not expose the DSH port to untrusted networks. If external access is needed, add a layer using the --trusted-host setup. Additionally, the plugin runs with the permissions of the current DSH process. Check the source code and license before installing.

Compatibility and Known Tests

  • DSH >=0.2.0-rc.2 <0.3.0-0
  • Node >=22.13.0
  • License: MIT
  • Tested on DSH 0.2.1-rc.5 + Web profile: 353 messages / 263k tokens compressed to 194 messages / 127.8k tokens.

Conclusion

The value of dsh-ctx-trim lies not in the novelty of the compression algorithm, but in providing an entry point: manually select a mode, generate the summary locally, and ensure the cut points fall on structural boundaries. If you are tired of automatic compression clearing your history in long sessions, it is worth installing and trying. See the directory page at https://www.skillhub.cn/plugins/AlexSh1ne/dsh-ctx-trim and the source code at https://github.com/AlexSh1ne/dsh-ctx-trim.

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

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

Xiaoye