Preface¶
The DeepSeek Harness (DSH) ecosystem follows the philosophy of “everything is a plugin.” During development or use, a common issue is: a plugin development knowledge base is meaningless in pure chat scenarios, while image generation tools feel unnecessary in code-writing scenarios. By default, all plugins inject all capabilities into the model, causing the context window to be occupied by a large amount of irrelevant information. The dsh-plugin-context-trim plugin aims to solve this problem. It provides session-level injection gating, allowing users to trim the skills, tools, and system prompt sections injected into the model on a per-session basis.
Core Features¶
This plugin implements session-level trimming through a “shadow entry” mechanism without polluting the global registry. The main features include:
- Trim skills per session: Set
modelInvocable:falsefor a same-name shadow skill, making the skill invisible to the model during invocation. - Trim tools / MCP tools per session: Use
tools.restrict({ deny })to hide specific tools; unknown tools are skipped automatically. - Trim prompt sections per session: Create a same-name empty-text section or context; the rendering layer discards it automatically. Sections that cannot be attributed to a plugin are locked by default.
- Tree-table popup: Provides a view aggregated by plugin, supports bulk group-row setting and tri-state checkboxes, and can be dragged or resized.
- Critical capability protection: Critical capabilities such as file read/write, console, and the skill master switch carry warning icons; unchecking requires secondary confirmation.
- Session lock and forced changes: A session is locked once it starts (persisted for ≥1 step) to prevent modification while running; “forced changes” are hot-applied.
- New session default template: Supports saving the current trimming scheme as the workspace default template, automatically applied to new sessions.
- Status dot: Uses color to indicate session status (green = full, orange = trimmed, gray lock = locked).
Installation¶
No configuration is required for installation. Use the official command to complete the mount:
dsh plugin --profile web add dsh-plugin-context-trim
After installation, restart the dsh launcher and refresh the browser. The plugin automatically applies the mount line in cordis.patch.yml; no manual configuration changes are needed.
Usage¶
The steps to enable the trimming feature are as follows:
- Create a new session and click the funnel button in the lower-left corner of the input bar (labeled “Inject”).
- The popped-up tree-table view lists all plugins that can affect the model context. Expand the plugin groups you do not want to inject, and click the group-row checkbox to batch uncheck them.
- The bottom displays in real time the number of trimmed items and the estimated number of characters reduced.
- Click Apply, and the changes take effect immediately in this session. The trimmed content no longer appears in the model context.
- Click Save as Default to save the current checkbox state as the default template for new sessions in this workspace.
Implementation Mechanism¶
The plugin overlays same-name “shadow entries” in the agent scope layer to suppress the original global entries. The original entries in the registry remain unchanged and are effective only within the current agent’s lifecycle.
- Skill: Register a same-name shadow skill and set
modelInvocable:false, removing the<available_skills>catalog and rejecting attempts to load that skill by name. - Tool / MCP: Call
agent.ctx.tools.restrict({ deny:[name] })to hide tools one by one. - Prompt sections: Call
agent.ctx.systemPrompt.section(同名, text:'')to create an empty-text section, which the rendering layer automatically discards.
This mechanism ensures zero residue and zero cross-session impact. When reapplied, it first disposes the previous generation and then rebuilds it, ensuring idempotency.
Compatibility and Limitations¶
- Target version: DeepSeek Harness
0.1.2-rc.1. - Runtime environment: Node.js ≥ 18; pure plugin implementation without modifying the core package.
- Data storage: Zero configuration; data is automatically persisted under
$DSH_HOME/dsh-plugin-context-trim. - Security limitations: HTTP routes accept only local loopback sources (if
remoteAddressis empty, the request is rejected); theHostheader is validated to allow only 127.0.0.1/localhost with a matching port; the request body must not exceed 2MB.
Notes¶
- Historical messages: After trimming mid-session, the old catalog content in historical messages remains; the model uses the latest catalog as the source of truth.
- MCP race condition: Tools newly added after an MCP server reconnect may temporarily bypass the gating mechanism and require manual handling.
- Dynamic plugins: Scoped tools from dynamic cordis plugins (
cordis_run) are not constrained byrestrict.
Conclusion¶
dsh-plugin-context-trim is the first plugin in the DeepSeek Harness ecosystem that trims context injection on a per-session basis. With simple UI operations, developers can precisely control the information received by each session without modifying the core package, effectively optimizing context window utilization.