DSH (DeepSeek Harness) never actively feeds back the current context token usage to the model. The model can only estimate it based on conversation length, which leads it to conclude “out of context” even when actual usage is only 17%, and this occurs repeatedly in long sessions. More seriously, this incorrect judgment can “survive” when compaction summaries are generated; it is then re-injected as an established background and cannot be corrected.

This plugin cuts this loop at both ends through measured occupancy backfill and compaction instruction rules. It depends on the host services tokenMeter and compaction (included in the standard dsh-base deployment), introduces schemastery only as a single peer dependency, requires no build, is under the MIT license, and is version 0.2.0.

Core Capabilities

1. Measured Occupancy Backfill (Enabled by Default)

Each turn, the host’s tokenMeter measures and backfills context occupancy information. It presents to the model the used tokens, total window size, remaining tokens, and the headroom before the automatic compaction point.

The system automatically classifies the state into tiers (ample / moderate / tight / critical) based on the compaction threshold ratio, and includes an estimate of how many steps the remaining headroom can sustain (computed from the median step size in the current session). This line is “host backend telemetry” and explicitly tells the model that this is the only authoritative source and that it should not count down by itself.

Display example:

Context occupancy (host-measured): 300K / 1.00M tokens used (30%).
Automatic compaction fires at 678K (68% of the window).
About 378K tokens of headroom remain before it.
There is still real headroom — keep going.

2. Compaction Instruction Rules (Enabled by Default)

At the end of the final message in a compaction-summary call (purpose: 'compaction'), the plugin appends two rules. This ensures that the model does not write its own statements about “context almost being used up” into the summary, preventing an incorrect judgment from surviving across compaction.

Example appended rules:

- Never record the assistant's own statements about its remaining context, token budget, or context-window pressure...
- Never record a plan to stop, defer, or hand off work whose only justification was context pressure.

3. Idle-Boundary Folding (Optional, Disabled by Default)

The host’s automatic compaction is usually triggered by “crossing the threshold,” which can lead the model to avoid important operations near the threshold, causing the reading to remain below the threshold for a long time and preventing completion of tasks that require continuous iteration.

This capability triggers one fold when the model is idle and the remaining headroom falls below 5% of the window. After the fold, the headroom is reset and the condition no longer holds, ensuring that only one fold occurs per cycle and resolving task convergence issues.

Installation

Install via the official CLI:

dsh plugin --profile web add dsh-context-truth

Or write it directly into the profile patch layer:

# <DSH home>/profiles/<profile>/cordis.patch.yml
- insert:
    - id: context-truth
      name: dsh-context-truth
      config:
        language: zh

Host requirements:
* Requires the host services tokenMeter and compaction (included in the standard deployment).
* Requires the host to include schemastery.
* Required injection items: inject = ['systemPrompt', 'tokenMeter'].

Configuration

Key Default Description
enabled true Top-level switch
language en Message language (en / zh)
order 100 Ordering in runtime-context
quantumPercent 5 Display step (as a percentage of the window)
paceEstimate true Whether to convert remaining headroom into a session pace
paceSamples 16 Number of samples used for the median pace
paceMargin 0.25 Excess ratio required to move up to a higher bucket
thresholdRatio 0.8 Automatic compaction threshold ratio
tightAdvice none Closing sentence for the tight bucket (none / inform / stop)
foldAtIdle false Whether to enable idle-boundary folding
foldAtIdleMethod auto Fold request channel (auto / command / service)

Notes

  • Dependencies: Depends on @deepseek-ai/schemastery.
  • Folding method: foldAtIdleMethod supports three modes: auto, service, and command.
  • No build required: lib/index.js is both the source code and the build output.

Summary

dsh-context-truth provides accurate host-measured data and corrects compaction instructions, solving the problem where a model may reduce its work enthusiasm or fail to converge during long sessions due to misjudging the context state. It is suitable for projects that need to maintain stable workflows in long conversations.