DeepSeek Harness (DSH) manages the context window, by default, in chronological order of messages. When the window is full, the system discards the oldest messages. This age-based ordering is often inaccurate: a critical constraint, error stack trace, or file path mentioned earlier might be mistakenly removed due to age, while recent trivial chatter is retained. Consequently, subsequent reasoning may need to re-read the repository or may produce incorrect answers based on outdated constraints.
dsh-plugin-jev-compaction solves this problem by introducing a relevance scoring mechanism. Instead of relying on time, it leverages Jev (TypeSafe System One) to directly score the relevance of each message. Only when the context byte count exceeds the budget are low-value messages discarded based on their scores.
Core Capabilities¶
The plugin primarily addresses the “wrongful deletion” issue in context compaction and provides the following features:
-
Jev-scored relevance scoring
Each message receives a relevance score. The system does not blindly discard old messages; instead, it decides whether to keep or drop them based on the score and a configurable confidence threshold (minConfidence). Messages below the threshold are retained because their importance is uncertain. -
Configurable byte budget
SettargetBytesas the upper limit for the total size of the context output. The system sorts messages by score, prioritizing high-value messages to fill the budget. -
Message pinning mechanism
Supports “pinning” specific types of messages via regex patterns so they are never discarded. Five default patterns are included:- File paths: e.g.,
src/ingest/parser.py,C:\app\main.ts. - Stack traces: Python errors,
File "...", line N, etc. - Error codes: e.g.,
HTTP 429,HTTP 500,status: 503. - URLs: Any link starting with
http://orhttps://. - Constraint statements: e.g.,
you must,do not,never,always,Important:at the beginning of a line or sentence.
- File paths: e.g.,
-
Degradation and fault tolerance
If the Jev service is unreachable, the API key is missing, or scoring requests fail, the plugin automatically degrades to age-based ordering (the default DSH behavior). This ensures the context list remains available without throwing errors. -
Receipt logging and replay
WhenreceiptPathis enabled, the plugin logs the hash, score, decision, and reason for each message. These receipts can be used to replay previous scoring decisions in subsequent reasoning steps at zero cost. -
Direct API export
In addition to running as a DSH policy plugin, the plugin exports core functions that can be directly called by other plugins or tests.
Installation and Activation¶
Before installation, ensure the Jev API key environment variable JEV_API_KEY is configured. The plugin uses JEV_API_URL as the default endpoint.
Method 1: Via DSH Plugin Manager
dsh plugin --profile your-profile add dsh-plugin-jev-compaction
Method 2: Via npm
npm install dsh-plugin-jev-compaction
Typical Usage¶
Command Line Tool¶
The plugin provides a CLI tool jev-compact for manually processing message lists.
# Compact the messages.l file, target byte count 60000, and read previous scoring receipts
jev-compact compact messages.l --target-bytes 60000 --scores receipts.l
Programmatic Invocation¶
In DSH code or other scripts, you can directly import and call the compaction function.
import { compactMessages } from 'dsh-plugin-jev-compaction'
const result = await compactMessages(messages, 'finish the parser fix', {
targetBytes: 65536,
keepRecent: 6,
})
Configuration Parameters¶
In the DSH plugin configuration file, the config field must be defined. Below are commonly used parameters:
- id: jev-compaction
name: dsh-plugin-jev-compaction
inject: []
config:
targetBytes: 262144 # Output byte budget, default 262144
keepRecent: 4 # Always keep the most recent N messages regardless of score
batchSize: 8 # Batch size for messages sent to Jev each time
minConfidence: 0.35 # Below this confidence is considered uncertain; prefer to keep
summaryBytes: 1024 # Max byte length for summary filling discarded messages
summaryRole: system # Role for summary messages
stateMessageBytes: 2000 # Truncation length for messages sent to Jev
enablePinning: true # Enable message pinning (default true)
receiptPath: ~/.dsh/jev-compaction/receipts.jsonl # Path for receipt logs
pinPatterns: [] # Additional pinning regex patterns
pinFlags: i # Regex compilation flags (default case-insensitive)
Use Cases and Notes¶
- Applicable scenarios: Suitable for long conversations or long-running reasoning tasks where the context window is about to overflow, and it is critical to ensure that key constraints or error information are not mistakenly deleted.
- Environment dependencies: The plugin requires the
JEV_API_KEYenvironment variable. If the variable is missing or API calls fail, the system reverts to the age-based default compaction strategy without interrupting the process. - Permission checks: The directory specified by
receiptPathmust have write permissions; otherwise, errors are only recorded in statistics and do not affect the compaction result. - Ecosystem context: DSH adopts a plugin-based architecture. This plugin is maintained by the community developer YYTbit. You can find more details in the SkillHub Plugin Directory, and the source code is hosted on GitHub.