As conversations grow longer, each step resends the full history, causing context costs and session logs to grow without bound. At the same time, the Web UI must render more and more historical nodes, which slows down interaction. As a long-session resource manager for DeepSeek Harness, dsh-optimize addresses these issues by measuring context growth, reporting load status, providing automatic compaction options, and optimizing browser rendering.

Plugin Positioning

This is a DSH plugin maintained by aoripus, used to monitor and optimize resource consumption in long conversational sessions. It does not modify system prompts, tool schemas, or request prefixes; it only handles statistics, warnings, and assisted compaction.

Installation and Enablement

Use the official command to install the plugin into a specified Profile:

dsh plugin --profile <profile> add dsh-optimize

Configuration

The default configuration is included in the packaged patch and usually does not need modification. If you need to override it, edit the Profile patch-layer file:

~/.dsh/profiles/<profile>/cordis.patch.yml

- id: dsh-optimize
  config:
    warnTokens: 120000
    criticalTokens: 300000
    autoCompact: false
    compactAtTokens: 200000
    compactCooldownMs: 300000
    verbose: false

Configuration options:

  • warnTokens (default 120000): request weight threshold that triggers a warning.
  • criticalTokens (default 300000): request weight threshold that triggers a critical warning.
  • autoCompact (default false): whether to enable automatic compaction.
  • compactAtTokens (default 200000): allows compaction to run when this weight is reached.
  • compactCooldownMs (default 300000): minimum interval between two automatic compactions.
  • verbose (default false): whether to log measurement data for all requests, not only those that cross thresholds.

The estimation logic is: Latin text is about 4 characters per Token, while CJK text is about 1.5 characters per Token. The plugin uses the upper bound for comparison, so mixed-language sessions tend to report earlier.

Core Features

1. Context Load Measurement

The plugin measures the outgoing request weight on each agent or pre-step, including message count, character count, and estimated Token range. It also reads the Harness’s own contextPressure projection to obtain authoritative Token values.

2. Session State Recording

The plugin maintains a record for each session in $DSH_HOME/storages/dsh-optimize/state.json, containing request history, events, last and maximum request weight, projected Token count, and compaction count.

3. Automatic Compaction

It invokes the Harness compaction engine through the ctx.agentPresets.serviceFor(agent, 'compaction') interface.
* Note that compaction is disabled by default.
* Compaction requires the Agent to be idle; otherwise, the request is rejected and retried.
* It decides when to compact, while the specific summary content is determined by the Harness engine.

4. Optimize Host Service

The plugin provides an optimize host service with the following methods:
* snapshot(id): get a snapshot for the specified session.
* list(): list the sessions.
* flush(): flush data.

5. Browser View Optimization

In the Web UI, the plugin enables “Lite rendering” mode by default.
* By setting content-visibility: auto and contain-intrinsic-size with CSS, the browser skips layout and paint for nodes outside the scroll viewport.
* React still reconciles nodes normally, but this does not cause page jank.
* You can toggle this mode by clicking the Composer chip or going to Settings -> General.
* The switch state is persisted in localStorage under the dsh-optimize:lite key.

Notes

  1. Permissions and Impact: The plugin runs with the current DSH process permissions. Please review the source code before installing.
  2. Default Behavior: Automatic compaction is disabled by default to avoid changing the context actually received by the model.
  3. Rendering Mechanism: Lite rendering does not hide DOM nodes; all nodes still exist and remain accessible. It only optimizes rendering performance.
  4. Log Isolation: The plugin does not write session events or touch session log files.

Summary

dsh-optimize focuses on making the cost of long sessions visible. Through precise measurement and optional automated controls, it helps developers manage resource consumption; through browser-side optimization, it improves the smoothness of long conversational interfaces. For more details, refer to the plugin directory or the source repository.