Long-running agent tasks accumulate large amounts of tool output, causing context to expand rapidly. The design philosophy of DeepSeek Harness is “everything is a plugin,” allowing context management capabilities to be extended without modifying core code. dsh-context-compression-improved is an improved fork of dsh-context-compression-selector, focused on providing auditable context-compression strategies for tool results and adding an orthogonal code skeleton compression gate.
This is a context compression selector plugin optimized for DeepSeek models. It reduces context length through mechanisms such as pre-compression, aggregate replacement, and history compaction. The main difference from upstream is the added code skeleton compression gate, which specifically handles oversized source-code tool results, greatly reducing redundant code bodies while preserving key declarations.
Core Features¶
The plugin provides multiple compression strategies, each with decision logs (stage, compressor, trigger condition, skip reason, and token count):
- Fresh pre-compression: Compresses oversized result segments before the model receives new tool results.
- Aggregate pre-compression: Compresses fresh material again when accumulated tool-result material exceeds the budget.
- History / Micro Compact: Replaces current results with qualifying older tool results while retaining recent context.
- TailTrim: An optional custom tail-reduction path.
- Native profile: Explicitly preserves Harness-style head/middle/tail trimming.
- Code skeleton gate: This is the new orthogonal feature. When enabled, oversized source-code tool results (such as
read_file) first attempt skeleton reduction: imports and type/function/class declarations are preserved, function bodies are omitted, but error lines inside function bodies are retained. If the skeleton cannot be generated or validated, it falls back to the original head trim.
Installation and Enablement¶
Install via plugin:
dsh plugin --profile web add dsh-context-compression-improved@dsh-0.2.0
After installation, open the Harness settings UI. In the “Context Compression Selector” settings area, choose a compression profile, set the “Auto Compact trigger level,” and toggle the “Code skeleton compression” switch. This switch is disabled by default.
Applicable Scenarios and Notes¶
- Model support: Supports only DeepSeek model families, including
deepseek-v4-flash,deepseek-v4-pro, anddeepseek-v4-flash-vision-exp. The plugin relies on the official DeepSeek tokenizer for lossless measurement and lossy compression. If the correct tokenizer is unavailable, the plugin falls back to retaining the original result. - Code skeleton disabled by default: The configuration is
codeSkeleton: { enabled: false }. It takes effect for oversized source-code results only after being manually enabled. - Session freezing: After configuration changes, they apply only to newly created sessions; running session configurations remain unchanged.
- Code format: The
codeSkeletonconfiguration must be in the format{ enabled: boolean }; an invalid format throws a runtime exception.
The plugin helps developers control context length and improve DeepSeek inference efficiency through tiered compression strategies and the code skeleton gate. The project is licensed under the MIT License and its source code is hosted on GitHub.