Introduction¶
In long DSH sessions, context pressure increases with turns. DSH has a built-in compaction-basic with a default pressure threshold of 80%. If you only want to set a lower or higher compression point for the current session, dsh-auto-compact provides session-level thresholds. After exceeding the threshold, compact is executed automatically, and the session continues naturally after the summary is injected into the context.
What is this¶
dsh-auto-compact is a session-level automatic context compression plugin for DeepSeek Harness (DSH), maintained by JohnathonYe, licensed under MIT. It monitors the context usage of the current session and automatically executes compact when the session threshold is exceeded, without sending any “continue” messages.
Core Features¶
- Session-level threshold: Set independently for each session, persisted by
sessionId. - Real-time usage: Displays the current session’s context usage, sourced from the built-in
ContextMeter, readinguseProjection("contextPressure"). - Threshold adjustment: Supports
1%–90%, step1%; defaults to50%when not set. - Auto-detection: Checked before every step in a turn and at the end of the turn; executes
compactautomatically if the threshold is exceeded. - Session continuation: The session continues naturally after the summary is injected into the context, without sending any “continue” messages.
- Threshold persistence: Saved in the
dsh-auto-compactnamespace insettings.yaml, persists across restarts. - Coexistence with built-in mechanisms: DSH’s built-in
compaction-basic(default80%pressure threshold) remains active and does not interfere.
Installation & Enablement¶
First, confirm the prerequisites: DSH is installed and dsh web runs normally; Node.js ≥ 20 and pnpm ≥ 10. Also, DSH’s compaction-basic (@deepseek-ai/dsh-compaction-basic) must be enabled; default presets standard / code / cordis are built-in, except the minimal preset.
If you previously installed the old package name auto-compact, uninstall it first, then install the new package name dsh-auto-compact to avoid double mounting:
npx -y --package @deepseek-ai/dsh dsh plugin --profile web remove auto-compact
Recommended one-click installation command:
curl -fsSL https://raw.githubusercontent.com/JohnathonYe/auto-compact/main/scripts/install.sh | bash
After installing or updating, restart DSH and force refresh the browser: macOS uses Cmd+Shift+R, Windows / Linux uses Ctrl+Shift+R. Run the one-click installation command again when updating, then restart DSH and force refresh the browser as well.
Uninstall using the following command:
npx -y --package @deepseek-ai/dsh dsh plugin --profile web remove dsh-auto-compact
Typical Usage¶
- Click the ring on the right side of the input area to open the panel.
- The panel displays the current session’s real-time context usage (percentage).
- Drag the slider to set the threshold (
1%–90%, session-level independent; new sessions not dragged before default to50%, only effective for the current session). - Thereafter, whenever the usage exceeds the threshold (before a step in a turn, or at the end of a turn), the plugin automatically executes
compactand continues.
Implementation Details & Notes¶
- Checkpoints: All checks are executed in
agent/pre-step(waterfall middleware) andagent/turn-stopping(serial events), wrapped intry/catchat all times, never throwing. - Threshold storage: Thresholds are saved in the
dsh-auto-compactnamespace insettings.yaml. - Settings channel: The plugin uses a custom webServer route
/dsh-auto-compact/api, where the host side writes directly to the settings service, bypassing DSH’s official namespace whitelist forapi.settings. - Permissions and audit: The plugin runs with the permissions of the current
dshprocess. Source code, dependencies, and theMITlicense should be checked before installation; if the preset does not enablecompaction-basic, the plugin cannot meet the prerequisite for automaticcompact.
Conclusion¶
dsh-auto-compact changes the context compression threshold from a global default to a current session adjustable setting, suitable for DSH sessions requiring fine-grained control of context pressure.
GitHub repository:
https://github.com/JohnathonYe/auto-compact