Passer au contenu principal
R

dsh-compaction-manager

rickt34/dsh-compaction-manager

Compaction settings panel: orders model-free compaction steps (official head/tail pruner, Magic Compact-style output omission, DCP-style dedupe and error purge, tool-call folding), tunes compaction-basic, adds a per-session Compaction tab that previews savings and queues a compact-now run, and adds a restore_context tool that returns hidden content.

Installer

dsh plugin --profile web add github:rickt34/dsh-compaction-manager

README

dsh-compaction-manager

English | 中文

A DeepSeek Harness plugin that puts context compaction in one panel:

  • Ordered compaction steps. When compaction triggers, the enabled steps run in the configured order. None of them calls a model. If the context is still over the threshold afterwards, compaction-basic writes its LLM summary as the fixed last step.
  • Automatic compaction settings. compaction-basic thresholds, retention, retries, summary model, and an auto on/off switch, applied at the next compaction without a restart.
  • Recall. Hidden content carries an id. The model can call restore_context to read the original back from the session log.
  • Preview and compact now. Each session gets a Compaction tab next to Chat and Trajectory. It previews the saved steps on that session, with per-item before/after text and estimated token savings, and has a Compact now button. DSH rewrites history only inside a model turn, so compact now runs right before the session's next model call.

The default configuration behaves exactly like stock DSH: only the official head/tail pruner runs, and it delegates to the original implementation.

Compaction steps

Preview

Install

Requires DeepSeek Harness >=0.2.2-rc.1 <0.3.0.

dsh plugin --profile web add dsh-compaction-manager

Or in the Web app: Plugins → Add plugin, enter dsh-compaction-manager. The panel appears in the sidebar as Compaction, and on the plugin's page under Plugins.

To install the latest commit from GitHub instead of the npm release, use github:RickT34/dsh-compaction-manager.

Built-in methods

MethodWhat it hidesRestorableDefault
Official head/tail trimMiddle of tool results over 8192 charsOnly with "Include recall id"On
Magic CompactOld bulky tool outputs, replaced with an omission notice (after aerovato/magic-compact /magic-trim)YesOff
OpenCode DCPDuplicate calls, errored call inputs after N turns, optionally superseded reads (after Opencode-DCP)YesOff
Fold old tool callsWhole call groups, including arguments such as file bodies in write/editYesOff

Folding replaces a closed assistant tool-call message and its results with one user message, because DSH does not allow rewriting tool-call arguments on their own.

How it hooks in

The Web app mounts compaction-basic and tool-result-pruner inside each agent preset. This plugin wraps their prototypes while it is loaded:

  • ToolResultPruner.prototype.pruneSession runs the configured steps.
  • BasicCompactionEngine.prototype methods apply panel overrides of the compaction policy.

Unloading the plugin restores the originals. Every replacement uses the same replay-safe events as the official pruner (compaction/prune followed by a surface replace), so sessions stay readable without this plugin.

Extending

Other plugins can add methods:

export const inject = ['compactionMethods']
export function apply(ctx) {
  ctx.effect(() => ctx.compactionMethods.register({
    id: 'my-method',
    name: { zh: '我的方法', en: 'My method' },
    summary: { zh: '…', en: '…' },
    details: { zh: '…', en: '…' },
    options: [{ key: 'minChars', type: 'number', label: { en: 'Min chars' }, default: 500 }],
    recall: () => true,
    // view.nodes: [{ seq, rootSeq, type, text, chars, toolName, args, isError, pending, turn, ... }]
    plan(view, options) {
      return view.nodes
        .filter(n => n.type === 'tool' && !n.pending && n.chars > options.minChars)
        .map(n => ({ type: 'result', seq: n.seq, content: [{ type: 'text', text: `[compacted · id=r${n.rootSeq}] …` }] }))
    },
  }))
}

plan must be pure. Candidates are { type: 'result', seq, content } (rewrite one tool result) or { type: 'fold', startSeq, endSeq, content } (replace a closed tool-call group with a user message). Notices that start with [compacted are skipped by the built-in methods; ids r<seq> and c<seq> work with restore_context.

Development

npm run link-dsh   # link DSH packages from the local `dsh` installation (needed by the tests)
npm test           # node --test test/*.test.mjs
npm run build      # regenerates dist/client.js from src/client/*.js

dist/client.js is committed so that installing from GitHub needs no build step. Rebuild and commit it after changing src/client/.

License

MIT

Plugins associés