Passer au contenu principal
D

dsh-plugin-context-mode

domush/dsh-plugin-context-mode

Native DSH support for context-mode (mksglu/context-mode), intercepting large tool outputs with SQLite FTS5 indexing, BM25+RRF search, and session continuity. On by default: tool outputs over 4 KB are replaced with a short preview while the full text is indexed into ~/.context-mode/context.db, and a section is added to the system prompt. Its ctx_execute and ctx_batch tools run shell, Node, Python, PowerShell or cmd commands with DSH's own permissions and environment (not sandboxed), and ctx_index reads any local file path or fetches any http(s) URL it is given.

Installer

dsh plugin --profile web add github:domush/dsh-plugin-context-mode

README

dsh-plugin-context-mode

npm version DSH Plugin Context Mode License: MIT

Native DeepSeek Harness (DSH) plugin adding full, native support for context-mode by Mert Koseoglu.


image

What is Context Mode?

Context Mode is a lightweight, local-first context optimization engine designed to prevent LLM context window degradation and token bloat. In standard agentic loops, commands and tools often dump dozens or hundreds of kilobytes into the context window, causing:

  1. Context Window Saturation: Hitting context limits and incurring high token costs.
  2. Context Degradation & Amnesia: "Lost in the middle" phenomena where the model loses track of core instructions and goals due to noise.
  3. Redundant Repetitions: Repeatedly reading the same files or command outputs over multiple turns.

Context Mode solves this by keeping tool outputs out of the model's context window:

  • Large tool outputs (>4 KB) are automatically intercepted and indexed into a local SQLite FTS5 database.
  • A compact preview with an indexed source handle is returned to the model.
  • The model uses semantic BM25 + Trigram Reciprocal Rank Fusion (RRF) search (ctx_search) to retrieve only the exact snippets it needs on demand.
  • Continuity across compaction or subagents is maintained via session journals and compact state blocks (ctx_resume).

Features

  • 8 Native Tools:
    • ctx_execute: Sandboxed execution of Node.js, Python, or shell code with an output cap of 16 KB. Full outputs are indexed; intent-guided semantic filtering retrieves only relevant excerpts.
    • ctx_batch: Batch execution of multiple shell commands, concatenated and indexed into SQLite FTS5 for unified querying.
    • ctx_index: Explicitly index files, raw text, or web URLs into SQLite FTS5 without expanding the context window.
    • ctx_search: Query indexed chunks across sessions or worktrees using BM25 and Trigram Reciprocal Rank Fusion (RRF_K=60).
    • ctx_resume: Rebuild context state and memory across compaction boundaries or subagent delegates with compact state blocks (<= 2048 B).
    • ctx_stats: Real-time analytics on intercepted bytes, kept-out bytes, and estimated token savings.
    • ctx_doctor: Health diagnostics for SQLite FTS5 tokenizers (Porter + Trigram) and runtime environments.
    • ctx_purge: Clean up indexed sources or wipe Context Mode tables.
  • Zero-Dependency SQLite FTS5 Engine:
    • Utilizes Node.js native node:sqlite (DatabaseSync) with virtual FTS5 tables (porter unicode61 and trigram).
    • No external C++ compilation or native binary installation required.
  • Automatic Lifecycle Interception:
    • Plugs into DSH's tools/post-execute waterfall lifecycle.
    • Outputs exceeding replaceTriggerBytes (default 4 KB) are safely intercepted and replaced with head/tail previews and search handles.
  • Full Web UI Integration:
    • Custom Settings section in the DSH Web UI.
    • Live metric cards showing bytes kept out, token savings, and context reduction progress bars.
    • Built-in diagnostic inspection table and one-click database vacuum/purge controls.
  • Bilingual Support: Full English and Simplified Chinese localization (en.json, zh.json).

Installation

In DeepSeek Harness UI (No Command Line Needed)

  1. Open the DeepSeek Harness Web UI and navigate to Settings → Plugins.
  2. Click the "Add Plugin" button.
  3. Paste in the plugin name:
    dsh-plugin-context-mode
    
  4. Click Install. The plugin will be fetched from NPM and activated immediately.

Via DeepSeek Harness CLI

Run the plugin install command in your terminal:

dsh plugin install dsh-plugin-context-mode

Via Profile Configuration (package.json)

Add the plugin to your DeepSeek Harness profile dependencies:

{
  "dependencies": {
    "dsh-plugin-context-mode": "^1.0.0"
  },
  "dsh": {
    "profile": {
      "bundles": [
        "dsh-plugin-context-mode"
      ]
    }
  }
}

Configuration

In your cordis.patch.yml or DSH Settings:

- insert:
    - id: dsh-plugin-context-mode
      name: dsh-plugin-context-mode
      config:
        enabled: true
        autoIntercept: true
        replaceTriggerBytes: 4096
        injectSystemPrompt: true
        dbPath: "" # defaults to ~/.context-mode/context.db
KeyTypeDefaultDescription
enabledbooleantrueEnable or disable the plugin.
autoInterceptbooleantrueAutomatically intercept and index tool outputs exceeding threshold.
replaceTriggerBytesnumber4096Output byte threshold to trigger interception & FTS5 indexing.
injectSystemPromptbooleantrueInject Context Mode tool guidelines into model system prompt.
dbPathstring""Optional custom SQLite database path.

Tool Reference

ctx_execute

Execute code in a child process with output bounding (16 KB cap). Commands run with DSH's permissions and environment; outputs exceeding the cap are automatically indexed into SQLite FTS5.

{
  "language": "shell",
  "code": "git log --oneline -n 100",
  "intent": "merge commit"
}

ctx_batch

Execute multiple shell commands in batch and query results.

{
  "commands": ["pnpm test", "git status --short", "cat package.json"],
  "queries": ["dependencies", "test failed"]
}

ctx_index

Index a file, URL, or string into SQLite FTS5.

{
  "path": "docs/architecture.md",
  "source": "architecture-doc"
}

Search indexed content using BM25 + Trigram RRF.

{
  "queries": ["PostToolUse", "FTS5 schema"],
  "limit": 5
}

ctx_stats

Check your context savings report.

{
  "scope": "all"
}

Architecture & Storage Schema

SQLite database is located at ~/.context-mode/context.db.

Tables:

  • events: Turn-by-turn journal tracking executed commands, intercepted outputs, and token savings.
  • sources: Catalog of all indexed files, batches, and outputs.
  • chunks: Virtual table using FTS5 tokenize = 'porter unicode61 remove_diacritics 2' for English and stemmed terms.
  • chunks_tri: Virtual table using FTS5 tokenize = 'trigram' for exact code symbols, paths, and substrings.
  • meta: Key-value configuration metadata.

Credits


License

MIT © Domush

Plugins associés