Introduction¶
The built-in context reclamation mechanism in DeepSeek Harness (DSH) is based on size and model summarization. When a tool result exceeds a character threshold, the middle part is truncated; region compression replaces old history with a model-written summary. The former cannot distinguish between “the result is large but still needed” and “the result is stale,” while the latter easily leads to summarization hallucinations.
The dsh-jev-prune plugin replaces the decision logic in both places with TypeSafe Jev structured outputs (noul / choice). Following the design principle that the model does not generate what it should not generate, it only decides whether to keep or discard, without changing the original text. Region compression uses code-generated deterministic receipts and contains no model reasoning.
Core Features¶
This plugin provides two-layer context compression mechanisms:
- Two-layer context compression: handles result pruning and receipt compression simultaneously.
- Jev structured output-based result pruning: determines whether each tool result is still needed.
- Deterministic receipt compression: generates code-generated receipts in region compression instead of model summaries.
- Original text preservation: the text after the decision remains unchanged and is not processed by the model.
- Tool call recognition: supports matching and managing tool calls and results.
How It Works¶
Layer 1: Result Pruning¶
The interception point is ctx.toolResultPruner.pruneSession.
DSH’s default logic is to truncate the middle once the threshold is exceeded. This plugin introduces a Jev judgment:
- Needed result: no matter how large, it is not pruned.
- Stale result: no matter how small (unless shorter than
minCharsToPrune), it is pruned. - When there is no judgment: falls back to DSH’s original behavior.
Layer 2: Receipt Compression¶
The interception point is ctx.compaction.summarize or compactRegion.
DSH’s default logic is to have the model read the history and write a summary. This plugin moves out eligible (see “Gating” below) read-only steps from the surface. In parallel batches, it only replaces eligible result bodies with deterministic receipts.
Deterministic receipt example:
[已压缩 · 确定性回执] 原历史 s25–s27 是 1 次工具调用(共约 16489 字符输出),
为释放上下文已移出。以下为事实清单(工具名/入参/字符数/seq 由代码算出;模型原话逐字引用,不含任何推断):
· s25 模型原话(逐字引用):identifiers:把版本字符串拆成标识符。Next inc.js.
· s27 read:C:\Users\you\project\src\state.js → 16489 字符输出
原始事件仍完整保存在会话日志中(seqs 25–27)。需要内容时重跑相同命令/读取相同文件即可;本回执不含对内容的解释。
Gating Mechanism¶
The default policy is conservative. The second-layer compression is triggered only if all of the following conditions are met:
- Intersection check: result need (
result) and side-effect-free status (effect) are both within thecompactQuantilerange at the session tail. - Tool allowlist: the tool is not in
neverCompactTools(write-type calls are hard-excluded). - Evidence guard: results matching
error/assert/fail/todoare not moved. - Length limit: assistant text (
text) or reasoning (reasoning) exceedingmaxStepTextChars/maxStepReasoningCharsis not moved. - Freshness: the latest
compactPreserveRecentnodes are not moved. - Balance check: both ends must satisfy DSH tool-call pairing balance, the span must save at least
compactMinChars, and the receipt length must be less thanreceiptMaxRatioof the original content.
Dependencies and Installation¶
This plugin depends on the following environment and libraries:
- Node.js:
^22.19.0 || >=24.0.0 - DSH Tools:
@deepseek-ai/dsh-tools(^0.1.5-rc.2 || ^0.2.0-rc.2) - Schemastery:
@deepseek-ai/schemastery(^3.18.2) - License: MIT
When installing, ensure that the environment versions meet the requirements above. The plugin is introduced via a plugin directory or a GitHub repository.
Notes¶
- Runtime permissions: the plugin runs under the current DSH process permissions.
- Source code review: it is recommended to check the source code and license (MIT) before installation.
- Directory and source code: