dsh-plugin-jev-compaction: Context Compaction Based on Relevance Scoring

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:

  1. 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.

  2. Configurable byte budget
    Set targetBytes as 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.

  3. 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:// or https://.
    • Constraint statements: e.g., you must, do not, never, always, Important: at the beginning of a line or sentence.
  4. 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.

  5. Receipt logging and replay
    When receiptPath is 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.

  6. 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_KEY environment 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 receiptPath must 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.
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye