xiamubumu/dsh-context-reclaim ↗★ 0

dsh-context-reclaim

DSH plugin: context reclaim at tool-result creation time, and at every later seam where context grows. Lossless noise purification, per-content-type bounding with retrieval pointers, tool-definition folding, system-prompt section-order stabilisation, and prompt-line trimming. Five Cordis seams, zero runtime dependencies. Also takes over the host's writable-request path, so the official `dsh-llm` file patch is no longer needed, and reports — without ever applying — which other official file patches are present. Never rewrites committed history, so the provider prefix cache is never invalidated. 适合需要精简上下文、折叠工具定义以提升模型长文本处理效率的场景。

Package
dsh-context-reclaim
Compatibility
Unverified
Harness peer range
>=0.1.1-rc.1
Version
1.0.0
License
MIT
Last updated
Oct 14, 2026

Install

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:xiamubumu/dsh-context-reclaim

Configuration

The configuration file is the profile's cordis.patch.yml:

- id: reclaim
  config:
    enabled: true
    noise: true
    bounded: true
    stripLines: false
    noOpGuardRatio: 0.05
    maxInlineBytes: 50000
    attribution: true
    trimSections: false
    foldTools: true
    activePlugins: []
KeyTypeDefaultEffect
enabledbooleantrueMaster switch (!== false counts as on)
noisebooleantrueLossless purification (ANSI / trailing whitespace / CR)
boundedbooleantrueBounding by content type + retrieval pointer
stripLinesbooleanfalseStrip line-number prefixes
noOpGuardRationumber0.05The "only act if it saves enough" threshold for bounding, 5%
maxInlineBytesnumber50000Above this byte count, content goes to spill (spill plugin required)
readOnlyToolsstring[]see the table aboveRead-only tool list, a full-table replacement
sideEffectToolsstring[]see the table aboveSide-effecting tool list, a full-table replacement
faithfulToolsstring[]see the table aboveFaithful tool list, a full-table replacement
attributionbooleantruePrint the [reclaim/usage] attribution line
trimSectionsbooleanfalseSection trimming (note: the real gate is the environment variable DSH_RECLAIM_SECTION_TRIM, see below)
foldToolsbooleantrueFold the tool definition surface
activePluginsstring[][]Plugin list participating in section-ownership computation

⚠️ The value of the trimSections option does not actually open the gate — the gate in the code only honours the environment variable DSH_RECLAIM_SECTION_TRIM, and it additionally requires activePlugins to be non-empty. The old documentation got this one wrong; it is stated accurately here.

Common environment variables

There are more than 40 environment variables in total, covering every internal threshold. Grouped by function, the most commonly used ones are:

VariableDefaultEffect
DSH_RECLAIM_NOISE1Set to 0 to turn off lossless purification
DSH_RECLAIM_BOUNDED1Set to 0 to turn off bounding
DSH_RECLAIM_STRIP_LINES0Set to 1 to strip line numbers
DSH_RECLAIM_TOOL_FOLD1Set to 0 to turn off tool definition surface folding
DSH_RECLAIM_PROMPT_LINE_MAX120Truncation threshold for a single system-prompt line
DSH_RECLAIM_DEDUP_DENY1Set to 0 to turn off duplicate-edit interception
DSH_RECLAIM_SECTION_TRIM0Set to 1 to turn on section trimming (works together with activePlugins)
DSH_RECLAIM_STABILIZE1Set to 0 to turn off prefix stabilization
DSH_RECLAIM_WRITABLE_REQUEST1Set to 0 to stop taking over llm.streamWithRegistration (see section 8); the official dsh-llm patch is only needed if you turn this off
DSH_RECLAIM_PATCH_CHECK1Set to 0 to silence the one-line "official patch check" notice printed at startup
DSH_RECLAIM_LOG1Set to 0 to turn off this plugin's log output
DSH_RECLAIM_DUMP_SYSTEM0Set to 1 to dump the assembled system prompt to a temporary directory, for diagnosis

The remaining threshold variables (sampling line counts, budget observation, pollution-detection window, archive limits, reasoning stripping, etc.) each have a per-item comment at the top of the source.