跳过主要内容
F

billion-compact

fanfan-2011/billion-compact

把较早的对话历史压缩成模型写的摘要:按上下文窗口的可配置比例自动触发(默认 90%),提供 /compact 命令、标题栏按钮、可指定摘要所用提供方与模型的设置页,并支持按轮删除消息。其 HTTP 路由未做 DSH 权限校验,浏览器中打开的任意网页都可能直接调用。

安装

dsh plugin --profile web add github:fanfan-2011/billion-compact

README

billion-compact

Fast, configurable context compaction for DeepSeek Harness (DSH).

billion-compact keeps long sessions inside the model's context window while using far fewer tokens. It replaces older history with a compact model-written summary, and gives you three ways to trigger that:

  • Automatic — when the context reaches 90% of the active model's detected context window (configurable 50–95%).
  • Command — type /compact in the composer.
  • One click — the compact icon at the top-right of the conversation header.
  • Oversized-request rescue — if a request body is already larger than the model window (for example the first message of a long imported chat), the failed send is compacted and retried automatically instead of surfacing an error.
  • Delete a turn — a small trash button sits in the message action row (next to the copy icon and the time) and removes that turn (its user, assistant and tool messages) from the context, so dead turns stop costing tokens. Turns that failed before any assistant message (the 处理失败 rows) have no action row, so their trash button is rendered below the error row instead.

Every compaction pops a toast in the bottom-right corner with how much history was replaced and how many tokens were saved. The toast stays for 10 seconds, pauses while you hover it, and can be closed with its own × button.

Install

Requires DeepSeek Harness >= 0.2.0-rc.1 (Node ^22.19.0 || >=24).

Install this folder as a local plugin/bundle, either from the DSH UI:

Settings → Plugins → Install plugin / bundle → choose the folder that contains package.json

or by pointing the plugin manager at a clone of this repository:

git clone git@github.com:fanfan-2011/billion-compact.git

Then enable billion-compact in Settings → Plugins and restart the profile once so the plugin's compaction rows replace the preset ones. The npm package is not published yet.

Settings

Settings → 上下文压缩 / Compaction (also available on the plugin's detail page):

SettingDefaultMeaning
自动压缩 / Auto compactiononCompact before a request when pressure exceeds the threshold.
触发阈值 / Trigger threshold90%Share of the model's context window that triggers auto-compaction.
压缩模型 / Summary modelmain modelProvider/model used to write the summary. Leave empty to follow the current main model.

The compaction engine itself is the shipped @deepseek-ai/dsh-compaction-basic (MIT), vendored and configured so that the pressure threshold tracks the model context window instead of a fixed headroom.

Commands and endpoints

  • /compact — manual compaction, no arguments.
  • GET /billion-compact/state?sessionId=… — effective config and live pressure.
  • GET /billion-compact/models — provider/model catalog for the settings UI.
  • POST /billion-compact/config — persist settings.
  • POST /billion-compact/compact — one-click/manual compaction.
  • GET /billion-compact/deleted-turns?sessionId=… — turn numbers hidden in this session.
  • POST /billion-compact/turn/delete — { sessionId, turn }: delete one turn.
  • GET /billion-compact/events — SSE stream of compaction results, auto errors and deleted turns.

Notes

  • Summaries are written with ctx.llm.stream, so they can use any configured provider, including a cheaper model than the conversation model.
  • The plugin owns the compaction service. It is compatible with the shipped /compact command shape, so its results appear as normal compaction rows in chat.
  • So that the configured threshold (default 90%) is the only trigger, the plugin disables the compaction rows that the stock agent presets compose themselves (@deepseek-ai/dsh-compaction-basic, @deepseek-ai/dsh-command-compact) while it is active. The same gate is used by other bundle plugins in this ecosystem; with billion-context installed, its gate already covers the presets.
  • Compaction is refused while the session has an open turn or another compaction is running; the UI reports “busy” instead of corrupting the transcript.
  • Oversized-request rescue. Some gateways (including the local egress fuse used by billion-context) reject an outbound body that is bigger than the effective model window with INVALID_REQUEST instead of the core context-overflow code. The plugin listens for that failure, compacts the session once, and retries the same step. It also caps the summarization call itself: when the region being compacted is too large for one request, the transcript is sanitized (text only, per-message head/tail clipping) and summarized in bounded chunks, then the partial checkpoints are merged. This keeps the rescue working even when the imported history alone is larger than the window. The rescue is retried at most twice per turn and follows the “Auto compaction” switch.
  • billion-context coexistence. billion-context refuses every DSH-side compaction request on a session it guards (“bili owns compression on this lane”). It detects two shapes: the stock summarization instruction in the last user message, and the purpose: "compaction" declaration that DSH attaches to summarization calls. This plugin therefore summarizes with its own bounded-chunk instruction and does not declare that purpose, so native checkpoints land normally; billion-context then rebases its own state on the next request instead of refusing. If a refusal still reaches the UI, the plugin shows a short hint with the two ways out (disable billion-context's DSH-compaction guard, or stop billion-context).
  • Deleting a turn. The trash button replaces that turn's whole surface span with an empty system message, so its messages leave the model context durably (tokens stop counting, and the stale-turn rows disappear). A 处理失败 row is derived from turn/end, not from the surface, so the client hides every row of a deleted turn by turn number; the list of deleted turns per session is kept in <profile>/billion-compact/deleted-turns.json and pushed to all open windows over SSE. Deletion is refused while the session is running.

License

MIT. The vendored engine is MIT, copyright the DeepSeek Harness authors.

相关插件