Introduction¶
DeepSeek Harness (DSH) automatically triggers context compaction in long-conversation scenarios, but the default usage window only displays the used percentage. It is not intuitive when compaction triggers or where the trigger point lies. Developers often have to dig through logs or estimate the numbers, easily missing the compaction window or misjudging the context water level. In the DSH plugin ecosystem, dsh-context-compaction-meter integrates “context compaction” information directly into the usage window below the input box, layering a compaction line and compaction history on top of the original usage readings, making the compaction trigger point immediately visible at a glance.
Plugin Overview¶
- Name:
dsh-context-compaction-meter - Maintainer: Canvai1337
- Category: Client
- Core Value: Appends a compaction line and compaction count/threshold to DSH’s existing usage overlay, without occupying a separate panel.
Core Features¶
When the usage window is opened, the original content remains unchanged while compaction-related information is added:
- Compaction line: A vertical line is drawn on the usage bar at the point where the model actually triggers compaction, representing the compaction trigger point.
- Compaction count and threshold: Appends “Compacted N times” to the detail rows, along with the threshold corresponding to each compaction event.
- Color grading: The usage reading and ring are colored based on “proximity to the compaction line”:
- Current usage < 0.5 × compaction line: green
- 0.5 × compaction line ≤ current usage ≤ 0.75 × compaction line: yellow
- Current usage > 0.75 × compaction line: red
- The closer to the compaction line, the more prominent the color.
Trigger Point Calculation¶
The compaction line is not read back from logs but is calculated based on DSH’s default compaction strategy (dsh-compaction-basic) and the current model’s capacity:
threshold = floor( min(W × thresholdRatio, (W − outputReservation) − headroomTokens) )
Where:
- W: the current model’s context window size (e.g., 1,000,000)
- thresholdRatio: defaults to 0.8
- outputReservation: the maxTokens materialized in the request header
- headroomTokens: defaults to 65,536
For example, on a model with a 1M context window, 128K output reservation, and headroomTokens of 65,536:
floor( min(1,000,000 × 0.8, (1,000,000 − 128,000) − 65,536) )
= floor( min(800,000, 806,464) )
= 800,000 tokens → 80% of the window
The compaction line is drawn at the 80% mark of the usage bar. When switching models, the trigger point adjusts accordingly.
Installation & Activation¶
Method A (recommended): DSH → Plugins → Add plugin → select the folder containing this plugin → refresh the page.
Method B: Execute the following in DSH:
plugin_manager install_bundle target=<absolute path to this folder>
Once application: applied is returned, it takes effect.
If the plugin button does not appear, refresh the page first; if it still doesn’t show, try disabling/re-enabling it once in Plugins or restarting DSH.
Custom Configuration¶
The plugin provides default configuration via cordis.patch.yml; two values can be overridden:
- id: context-compaction-meter
name: '@local/context-compaction-meter'
config:
thresholdRatio: 0.8 # Keep in sync with dsh-compaction-basic.thresholdRatio
headroomTokens: 65536 # Keep in sync with dsh-compaction-basic.headroomTokens
If a specific model has a custom compaction threshold configured (modelPolicies), fill in the equivalent ratio/headroom here; otherwise the displayed value may not match the model’s actual trigger point.
Implementation Notes¶
- Host side (
index.js): Registers a readable projectioncontextCompaction(stateVersion: 2) toctx.sessionProjections, containing: request/context: recordscontextWindowrequest/header: records the materializedmaxTokensas the output reservationcompaction/summary: for each successful compaction, records the threshold, ordinal number (ordinal),compactionId, and the number of tokens freed.
The threshold formula is consistent with the compaction backend. History is capped at the most recent 100 entries to avoid bloating projection state and wire size in ultra-long sessions. Duplicate compactionId values are ignored. Configuration undergoes fast-fail validation inside apply; unknown keys, out-of-range ratios, and non-integer headroom values will raise errors directly.
-
Client side (
client.js): Registers toconversation.composer.dock. Since the built-inContextMeteris not extensible, this plugin renders a merged usage window (replicating the original header, segmented bar, and detail rows, with the compaction line/count/records appended), and uses a rule scoped only to the input box dock area that targets the built-in component’s root node ([data-composer-dock] > span[style*="anchor-name"]:not([data-dsh-ccm])) to hide the built-in instance, preventing two windows from appearing. This rule is written inside the component, so when the plugin is disabled or there is no data, the built-in usage window is restored as-is. -
Text strings use the client-side locale namespace
contextCompactionMeter(zh/en/ja); colors use theme tokens (--dsw-alias-state-*); the overlay is rendered todocument.bodyviacreatePortal(falling back to fixed positioning when unavailable), supports click-outside/Esc to close, focus on open, and keyboard navigation.
Caveats¶
- The compaction line is a trigger point calculated from the strategy and model capacity, not read back from historical events. It is consistent with this deployment’s default strategy; when you modify the actual compaction configuration, sync this plugin’s configuration accordingly.
- The compaction count tracks compactions that successfully produced a summary (
compaction/summary); transactions that only prune tool output without generating a summary are not counted separately. - Hiding the built-in usage window relies on its root node carrying an inline
anchor-namestyle; if a DSH upgrade changes this structure, the selector needs to be updated accordingly (or switch to modifying the built-in component directly). - The window only displays in conversations where context usage data exists (reported by the provider); when no data is available, it falls back to the built-in usage window.
Use Cases¶
- Long conversations or multi-turn agent development using DSH, where real-time monitoring of context water level and compaction trigger points is needed.
- Viewing context usage and compaction history in the same window, avoiding switching between multiple panels.
Summary¶
dsh-context-compaction-meter layers a compaction line and compaction history onto DSH’s existing usage overlay, turning the compaction trigger point from logs and estimation into an intuitive visual marker. It is ideal for developers who need fine-grained control over context and compaction behavior. The plugin relies on theme tokens and built-in projections, has no third-party dependencies, version 1.1.0 requires DSH 0.2.2-rc.2+, and is released under the MIT license.
- Plugin directory page: https://www.skillhub.cn/plugins/Canvai1337/dsh-context-compaction-meter
- GitHub: https://github.com/Canvai1337/dsh-context-compaction-meter