会话上下文超过可配置的 token 阈值、且用户空闲达到可配置时长后,在模型 KV 缓存过期前自动压缩会话;两项设置都在插件管理器的插件页面中修改。
安装
# npm 包(预构建)
dsh plugin --profile web add dsh-idle-compact
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:Arrosam/dsh-idle-compact
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
该插件的 README 只有英文版本。
A DeepSeek Harness (DSH) plugin that prepares a compaction of a long session while you are away, before the model provider's KV cache expires, and lets you apply it with one click when you come back.
Why
Providers cache the prompt prefix of a conversation for a few minutes. While the cache is warm, re-reading a long history is cheap. Once it expires, your next message re-bills the whole history at the full, uncached input price.
If you walk away from a long session, this plugin produces the compaction summary while the cache is still warm, so that summarization request is cheap. Nothing changes in your session until you decide to apply it.
How it works
- When a session finishes a turn and waits for you, a timer starts.
- Any new activity in that session cancels the timer, whether it's you replying or the agent starting work.
- When the timer fires, the plugin prepares a compaction only if all of these hold:
- the agent is still idle and its last turn finished normally (not an error or a stop);
- no background job or subagent is running for the session;
- the session's context, measured with DSH's token meter, has reached the threshold.
- Preparing runs exactly the summarization request DSH's
/compactwould make, and keeps the result. Your session is not changed. - An Apply compaction bar appears just above the message input, showing how many history items it covers.
- Clicking it runs DSH's own
/compactcommand, exactly as if you had typed it, and answers its summarization request with the prepared result, so no new model call is made. The conversation shows the usual/compactcard with its "Compacted N history items" reply.
The prepared summary is only valid for the conversation it summarized. If you send another message (or the history changes in any other way), it is discarded and the button disappears; the next idle period that qualifies prepares a fresh one. If the conversation somehow differs at the moment you click, /compact makes its own model call instead of using a stale summary.
When the plugin starts or is reloaded (a DSH restart, a plugin update), sessions that are already waiting are timed from the end of their last turn. A session idle for less than the idle delay is timed for only the remaining seconds. A session idle for longer is skipped entirely, because the provider's cache has most likely expired and preparing would cost full price. It qualifies again after its next turn.
Subagent sessions are skipped, because they never wait for a user reply. If the agent is busy when the timer fires, nothing is prepared and this is logged.
Settings
Open Plugins → Idle Compact in the DSH Web UI:
| Setting | Default | Meaning |
|---|---|---|
| Context length threshold (tokens) | 256000 |
Prepare a compaction only when the session context has reached this length. |
| Idle time (seconds) | 300 (5 min) |
How long you must go without replying before a compaction is prepared. |
Both fields take whole numbers of at least 1. Changes apply without a restart. A changed idle time takes effect the next time a session starts waiting.
You can also set them in your profile's cordis.patch.yml:
- id: idle-compact
config:
contextThresholdTokens: 200000
idleSeconds: 240
Install
Requires the DSH Web UI. Tested on DSH 0.2.1-alpha.3 and 0.2.1-rc.2; earlier versions are untested. The plugin uses DSH's authenticated /api routes, its settings-form components, and the area above the message input (conversation.input.dock).
dsh plugin add github:Arrosam/dsh-idle-compact
Or, in the Web UI, open Plugins → Add plugin and enter github:Arrosam/dsh-idle-compact or a local checkout path.
Token cost
Each prepared compaction makes one summarization call to your model. It's cheap because the cache is warm, but it is spent even if you never click Apply or never return to that session. If most of your idle sessions are ones you abandon, raise the threshold.
Prepared summaries are kept in memory only. Restarting DSH discards them.
Page endpoints
The browser half talks to the Host over two routes on DSH's own /api channel. DSH checks the browser's login and origin before either route runs, so other programs and other websites can't use them.
GET /api/idle-compact/events?sessionId=<id>: a server-sent event stream. The first message is the session's current state, and another follows each change. Each message is{ "prepared": false }, or{ "prepared": true, "items": <history items>, "tokens": <approx. tokens>, "applying": <boolean> }.POST /api/idle-compact/applywith JSON{ "sessionId": "<id>" }applies the prepared compaction. Responses:
| Status | Body | When |
|---|---|---|
| 200 | { "ok": <boolean>, "result": <command result> } |
/compact ran; ok is whether it succeeded. Its outcome also shows in the chat. |
| 200 | { "ok": false, "code": "command-unavailable" } |
The /compact command isn't available. |
| 400 | { "ok": false, "code": "bad-body" } |
The body isn't a JSON object with a non-empty string sessionId. |
| 404 | { "ok": false, "code": "no-session" } |
No live session has that id. |
| 409 | { "ok": false, "code": "not-prepared" } |
Nothing is prepared, or it went stale. |
| 409 | { "ok": false, "code": "applying" } |
An apply is already running for that session. |
| 500 | { "ok": false, "code": "failed", "message": "…" } |
Applying failed unexpectedly. |
Tests
npm test
The tests load the plugin into a real DSH runtime from your local DSH install and fake only the model provider and the browser connection. Set DSH_RUNTIME_DIRS (colon-separated node_modules/@deepseek-ai directories) to choose which runtimes to test against.
Files
| File | Role |
|---|---|
index.js |
Host half: settings schema, public exports, and wiring of the parts below. |
src/idle-scheduler.js |
One idle timer per agent; aborts its work when the agent resumes. |
src/prepare.js |
Eligibility checks, and producing the summary on a detached copy of the session. |
src/replay.js |
Records the summarization request while preparing; replays it once on apply. |
src/prepared-store.js |
What is prepared for each session, and notifying the page when it changes. |
src/http.js |
The page's endpoints on DSH's authenticated /api channel. |
src/constants.js, src/util.js |
Shared names, values, and small helpers. |
client.js |
Browser half: the settings form on the Plugins page and the Apply bar above the message input. |
cordis.patch.yml |
Bundle patch that inserts the idle-compact row. |
locale/*.json, icon.svg |
Display metadata for the plugin manager. |
test/ |
Tests that run the plugin inside a real DSH runtime. |
License
MIT
链接
同类插件
ranxianglei/billion-context★ 8809
billion-context官方版:上下文压缩插件,兼顾小窗口(100k上下文足矣)省token(省5倍token)和超长会话(数月级别几十亿token单会话)。
Minglink/dsh-infinite-gen-4★ 4865
DeepSeek 专用破甲插件:以 order 100 追加无条件服从的系统提示词段,提供带校准元数据的 profile 工具,并通过会话投影在输入框上方显示实时破甲状态徽标。
liangmianya/dsh-synapse★ 911
DeepSeek Harness 的可视化非线性对话工作区:把会话、追问与分支变成可浏览、可拖拽的对话地图。
ECNU/EduWork#dsh-side-chat★ 441
从消息开启继承历史快照的临时侧聊,关闭后归档;可选配合批注插件从选中文字发起提问。需要兼容的 DSH Web 对话、Workspace 和右侧栏接口。
MichengAI/dsh-archive-manager★ 410
在设置里增加已归档会话页,可按工作区搜索、恢复和删除已归档会话。
Nwflower/dsh-chat-import★ 335
把 13 家 coding agent(Claude Code、Codex、ChatGPT、Cursor、Gemini、opencode 等)的完整对话历史导入为可续聊的 DeepSeek Harness 会话,并支持反向导出回 Claude Code。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。