插件目录 / Knowledge / dsh-context-guard
dsh-context-guard
已验证 · 实测可装 kpl0111
功能简介
Token-efficient tool-result pruning for DeepSeek Harness: compact previews, targeted recall, and long-session context control.
可用 — 实测通过,早期项目
Token-efficient tool-result pruning for DeepSeek Harness: compact previews, targeted recall, and long-session context control. 实测能干净安装、正常启动。早期项目,但功能可用。
「已验证」表示我们的自动化 CI 在干净 profile 里实际执行了 dsh plugin add 并启动成功——仅此而已。功能描述与版本兼容性均为作者声明。这不是安全审计,也不代表对第三方代码的背书。
README
dsh-context-guard
dsh-context-guard is a small DeepSeek Harness (DSH) preset add-on for controlling long-agent-session token growth. It prunes oversized tool results before the next model request, while leaving durable session history intact for targeted recovery.
It does not replace DSH compaction and does not send its own LLM request.
Policy
The recommended balanced policy is:
| Layer | Setting | Purpose |
|---|---|---|
| Immediate tool pruning | thresholdRatio: 0.001 |
Replace bulky tool output with a 2.3K-character preview before the next turn. |
| Preview | head 1792 / tail 448 | Retain the beginning plus terminal exit/spill-file marker. |
| Full compaction | Instant at 80% | Compact conversation history only when the useful context is genuinely large. |
| Recovery | recall <= 4096 tokens | Permit targeted recovery without a 16K accidental context refill. |
Installation
This is a standard DSH bundle. Installing it adds an isolated runtime realm containing the guard and its toolResultPruner; no preset merge is required.
dsh plugin --profile web add github:kpl0111/dsh-context-guard#v0.2.0
For bounded search and recall recovery, install dsh-compaction-instant as a companion bundle:
dsh plugin --profile web add github:KitDoesIt/dsh-compaction-instant
If DSH Desktop does not expose the dsh command on your PATH, install the package through its Plugins settings or the active profile's package-manager environment. The preset fragment and realm placement are unchanged.
Add this sentence to the persona/system prompt when using pruned output:
When prior tool output has been pruned, first use the retained file path, a narrow filesystem search, or search. Use recall only when that is insufficient, and recall the smallest relevant result or sequence; never broadly recall large historical output.
Restart DSH and create a new session after installing or updating bundles. The legacy presets/standard-lite.fragment.yml is retained only for users who deliberately manage the guard inside a preset; do not enable both the legacy row and this bundle at the same time.
Expected behavior
- Large ordinary tool results are replaced with the configured compact preview before the next model request.
searchresults follow the normal pruning policy.- A
recallresult is preserved in full for exactly the next model step, then becomes eligible for normal pruning again. - Original tool output remains available in DSH's append-only session history for targeted
searchandrecall.
Verify installation
- In a new session, run a tool that produces a large result (for example, a PowerShell command printing many lines).
- Inspect the session event log or context view: the next model step should retain a roughly 2.3K-character preview rather than the full result.
- Ask the model to locate a known value with
search, then require onerecallof the matching event. The recalled result should not receive an immediatecompaction/pruneevent, and the next assistant reply should be able to use the full recalled content.
Compatibility and safety
- Requires DSH/Cordis packages compatible with
@deepseek-ai/dsh-*0.1.0-rc.6. - Works with the built-in
@deepseek-ai/dsh-compaction-tool-result-pruner. thresholdRatio: 0.001is intentionally near-immediate but still checks the model context window. Use0.20if you prefer delayed pruning.- A
recallresult is deliberately kept intact for the immediately following model step once, then becomes eligible for normal pruning. This preserves recall usefulness without retaining its full payload for later turns. - Full original tool output remains in DSH's append-only session log. The plugin itself never deletes it.
Development
npm test
npm run check
License
MIT
安装
装一次目录插件,之后本站所有插件都能让 DeepSeek Harness 自动找、自动装:
dsh plugin add dshbase-catalog 然后对 agent 说「帮我装 dsh-context-guard」,它会在目录里找到并自动安装。文档:dshbase-catalog · 已验证场景包。
该插件是 GitHub 源码(未发 npm)——直接从仓库装:
Web profile:
dsh plugin --profile web add github:kpl0111/dsh-context-guard Headless(CLI)profile:
dsh plugin --profile headless add github:kpl0111/dsh-context-guard 实测报告
验证通过:从 GitHub 源码完成 L1 安装 + L2 加载 + L3 运行(dsh 0.1.0-rc.6)。