dsh-auto-compact
Automatic context compaction for DeepSeek Harness: at every agent step it prices the routed request against the model's context window, and once pressure crosses the configured threshold it condenses the older span of the conversation into a durable <compacted-summary> checkpoint (via the conversation's own model, reusing the warm prefix cache) — so long sessions keep working without losing essential context.
It wraps the harness's own token-meter-driven engine (@deepseek-ai/dsh-compaction-basic); this plugin adds a LATE-by-default trigger, a settings card, and install docs.
Why "compact later"?
The harness's pi-ai provider falls back to DEFAULT_CONTEXT_WINDOW = 262144 (256K) for models that do not declare a window. With the default thresholdRatio of 0.8 that means compression can fire at ~205K tokens — only ~20% of a real 1M-window model. This plugin defaults to thresholdRatio: 0.92 and documents the window fix, so big windows are actually used.
Install
# profile dir (C:\Users\<you>\.dsh\profiles\<name>)
pnpm add -w dsh-auto-compact
# or from GitHub:
pnpm add -w dsh-auto-compact@github:lileikeji/dsh-auto-compactAdd dsh-auto-compact to the profile package.json dsh.profile.bundles list, then disable the harness's own engine so only one engine owns compaction:
# profile cordis.patch.yml
- id: compaction-basic
name: '@deepseek-ai/dsh-compaction-basic'
disabled: trueWindow configuration (important)
The engine reads the model's context window from the LLM adapter. If your model's window is not declared (pi-ai defaults to 256K), set it per provider in ~/.dsh/settings.yaml:
llm-pi-ai:
providers:
my-provider:
apiKeyEnv: MY_API_KEY
defaultContextWindow: 1000000 # the model's real windowConfiguration (settings card)
Settings → 插件 → 自动压缩上下文(auto-compact):
thresholdRatio— trigger threshold as a fraction of the context window (default0.92).retainRatio— fraction of the recent conversation kept verbatim (default0.12).maxTokens— summary output cap (default8192).auto— enable/disable automatic compaction.
Changes apply after a profile restart.
How it works
1. agent/pre-step: price the latest durable routed request with the token meter. 2. If totalTokens ≥ thresholdRatio × contextWindow (output-budget aware when known), pick a head-anchored span that never splits a tool call/result pair, retaining the recent tail. 3. Summarize that span with the conversation's own model (system prompt + tools + leading messages replayed verbatim so the provider's KV cache is reused), appending the compaction instruction. 4. Land the checkpoint as a compaction/start → summary → compaction/end transaction on the session surface; subsequent steps continue from the checkpoint.
License
MIT