Introduction¶
DeepSeek Harness (DSH) is in the developer preview stage, and the plugin-based philosophy is “everything is a plugin.” In long conversations, the model’s context window is limited, and early instructions can easily be pushed out of view by newer messages, leading to “forgetfulness.” The existing dsh-context and dsh-cost-meter plugins primarily focus on usage display and billing, whereas this plugin focuses on proactively managing the context budget through monitoring, compression, pinning, and snapshot mechanisms, ensuring the model retains access to critical instructions throughout long conversations.
What Is This¶
This is a DeepSeek Harness (DSH) plugin maintained by tianbaoZeng, categorized under model inference. It provides context window optimization capabilities, including a real-time token usage meter, automatic summarization, file pinning, diff-based incremental injection, and session snapshots, addressing the problem of early instructions being forgotten due to context overflow in long conversations.
Core Features¶
Real-Time Usage Meter¶
The plugin listens to session/event and llm/stream events to accumulate token usage. It prioritizes the actual usage data carried in the event; otherwise, it estimates using CJK ≈ 1 token/character and other text ≈ 4 characters/token. Users can check the usage ratio and progress bar via the /context-status command. When the threshold is reached, the progress bar turns red.
Automatic Summarization¶
When the usage ratio reaches the threshold (default 0.80) and there are enough new messages, the plugin compresses the earlier history into a summary message and passes the result to the host for context injection via the dsh-context-window/summary-ready event. It uses extractive summarization by default; if an LLM callback is connected in src/adapter.ts, it can be switched to model-based summarization.
File Pinning¶
The /pin <file> command pins file content in the context, and the plugin records a content snapshot at the time of pinning. /unpin <file> releases the lock. The number of simultaneously pinned files is constrained by the maxPinnedFiles limit (default 5).
Diff-Based Incremental Injection¶
When a user message hits a trigger phrase (default “continue from where we left off”, case-insensitive), the plugin computes a git diff on the pinned files and emits the incremental changes (rather than the full content) via the dsh-context-window/diff-inject event. The Agent can also call the context_diff tool at any time to proactively pull the diff.
Session Snapshot¶
The /snapshot command saves the current usage, pin list, and recent messages to <snapshotDir>/snapshot-<id>.json. /restore <id> can restore a snapshot by id, including usage and re-pinning files.
Installation & Activation¶
Install using the following commands:
# Local directory (development)
dsh plugin --profile <name> add ./dsh-context-window
# tarball
pnpm pack
dsh plugin --profile <name> add ./dsh-context-window-0.1.0.tgz
# GitHub / npm
dsh plugin --profile <name> add github:tianbaoZeng/dsh-context-window
dsh plugin --profile <name> add dsh-context-window
After installation, enable it in the Profile. The minimal patch is in cordis.patch.yml; for parameter tuning, you can override the config field in the assembly configuration.
Configuration¶
| Field | Default | Description |
|---|---|---|
threshold |
0.80 |
Usage ratio (0..1) that triggers automatic summarization |
maxPinnedFiles |
5 |
Maximum number of simultaneously pinned files |
windowTokens |
65536 |
Model context window size (meter denominator) |
diffTrigger |
"continue from where we left off" |
Phrase that triggers diff injection (case-insensitive) |
snapshotDir |
".dsh" |
Snapshot storage directory |
autoSummarize |
true |
Whether to enable automatic summarization |
Typical Usage¶
Slash Commands (User-Triggered)¶
| Command | Description |
|---|---|
/pin <file> |
Pin a file to the context |
/unpin <file> |
Release a pinned file |
/snapshot |
Save the current context state |
/restore <id> |
Restore a snapshot by id |
/context-status |
View usage ratio, progress bar, and pin list |
Tools (Agent-Callable)¶
| Tool | Parameters | Description |
|---|---|---|
context_status |
— | Query usage and pin list |
context_diff |
path? |
Pull git diff of pinned files |
context_pin / context_unpin |
path |
Pin / unpin a file |
context_snapshot |
— | Save a snapshot |
context_restore |
id |
Restore a snapshot |
Use Cases & Notes¶
This plugin runs with the permissions of the current DSH process. It is recommended to review the source code and license (MIT) before installation. The plugin is currently in the DSH developer preview stage; the plugin API evolves with each version. If the type definitions of the installed version are inconsistent with src/types/dsh-api.d.ts in this repository, modify src/adapter.ts first rather than src/core/.
This plugin only manages the context budget of the current session, and is complementary to the dsh-mnemon plugin, which provides cross-session long-term memory.
Summary¶
The context window optimizer ensures the model retains access to critical instructions throughout long conversations through monitoring, compression, pinning, and snapshot mechanisms. For more details or to download the plugin, visit: Directory Page or GitHub Repository.