DSH Plugins Marketplace

DSH Plugins

Plugins

/

dsh-lib-context-injection

d

dsh-lib-context-injection

Discovered

Context injection library to be used in DeepSeek Harness plugins.

dsh-lib-context-injection

Shared agent context-injection helpers for dsh web plugins.

Several dsh web host plugins need to push context into a live agent's session with no browser in the loop, and they used to each implement the same two patterns by hand:

  • Follow-up message injection — agent.followup(createUserMessage(...)): dsh-plugin-cost-lens fires scheduled off-peak sends, releases deferred (cheapass) prompts, and wakes interrupted work at the next off-peak start; dsh-plugin-watchdog wakes a crash-resumed agent with a "continue where you left off" prompt.
  • Model-selection restoration — deriving the session's last durable route (provider / model / reasoning effort) from its request/header + assistant/message events and installing it via installModelSelection, so the persona prompt's {{model}} / {{provider}} variables resolve on headless/resumed agents (which have no browser to install the selection).

This package is the single implementation of both patterns.

Install

Host-only ESM library; it runs inside the dsh server process and imports @deepseek-ai/dsh-llm + @deepseek-ai/dsh-agent (both shipped with dsh web).

This is a dependency package, not a Cordis plugin — there is no loader entry to add to cordis.patch.yml, and dsh plugin add will not make anything load it. If you use one of the consuming plugins (cost-lens, watchdog), it is installed automatically as their git dependency — you don't need to install it yourself.

From GitHub (add as a dependency of your own host code)

pnpm ≥ 11 note. pnpm 11 blocks git-hosted transitive dependencies (blockExoticSubdeps defaults to true). If you install this into a dsh profile (or any pnpm workspace) as a direct dependency, pass the flag below; as a transitive dependency of dsh-plugin-cost-lens / dsh-plugin-watchdog, their install commands already include it.

npm install --save github:davidgereb/dsh-lib-context-injection --config.block-exotic-subdeps=false
# or with pnpm:
pnpm add github:davidgereb/dsh-lib-context-injection --config.block-exotic-subdeps=false

From a local checkout

npm install /path/to/dsh-lib-context-injection
# or with pnpm:
pnpm add /path/to/dsh-lib-context-injection

API

ExportPurpose
deriveModelSelection(events, opts?)Fold session events into the last durable { provider, model, reasoningEffort? } route. opts.fallbackProvider / opts.fallbackModel cover sessions with no recorded route; opts.includeReasoningEffort also carries the effort from request/header config.
installModelSelectionOn(target, selection, opts?)Safe wrapper around @deepseek-ai/dsh-agent's installModelSelection — never throws; logs via opts.logger.warn (tagged with opts.plugin) and returns false on failure. target is an agent (uses agent.ctx) or a raw agent-scoped context.
ensureModelSelection(target, events, opts?)deriveModelSelection + installModelSelectionOn with two guards: per-context dedupe (WeakSet — one install per context per process) and an optional "route already carried" skip (opts.skipIfRouted, default true): when the agent's options.model already carries a route, the {{model}} variable resolves on its own, so nothing is installed.
injectUserMessage(agent, message)agent.followup(createUserMessage(...)). message.text becomes a text block (or pass full message.content); message.plugin becomes the default { kind: "plugin", plugin } source (or pass message.source explicitly). Returns the created message.

Usage

import { deriveModelSelection, injectUserMessage, ensureModelSelection } from "dsh-lib-context-injection";

// wake an agent with a plugin-tagged follow-up
injectUserMessage(agent, { text: "Continue where you left off.", plugin: "my-plugin" });

// restore the session's model route on a headless/resumed agent
ensureModelSelection(agent, agent.session?.events ?? [], {
  fallbackProvider: "deepseek",
  fallbackModel: "deepseek-v4-flash",
  logger: ctx.logger,
  plugin: "my-plugin"
});

Cordis scoped-context note. The resume setup(agentCtx) callback passes a Cordis scoped-context proxy; reading a non-injected property on it (e.g. agentCtx.ctx) throws cannot get property "ctx" without inject. installModelSelectionOn/ensureModelSelection handle this: they probe target.ctx in a guarded try/catch and fall back to using the raw context itself — the same as the pre-library callers did.

Layout / build

dsh-lib-context-injection/
├── index.js              # the library (host-only)
├── package.json          # dsh-lib-context-injection
└── scripts/
    └── smoke-test.mjs    # derive/install/inject unit checks

No build step — index.js is the package.

Testing

node scripts/smoke-test.mjs

Consumers

Compatibility. Tested against dsh 0.1.0-rc.6 on Node.js v24.19.0 (dsh web profile). Older or newer dsh releases may change the internals this plugin hooks into — check the changelog before upgrading.


⚠️ AI-generated, provided as-is. This project was written with the assistance of an AI. It is provided AS IS without warranty of any kind, express or implied. The author cannot be held responsible for any damage, data loss, or misbehaviour that results from using it. Use at your own risk.

Comments

Loading…

Similar plugins

dsh-plugin-context-compressor

by YYTbit

Context compression skill for DeepSeek Harness

Development & InfrastructureManifest valid

★ 1

MIT

TypeScript

Aug 14, 2026

dsh plugin --profile web add dsh-plugin-context-compressor

by QQQW114

DeepSeek Harness (DSH) plugin - inject context when user input or model output hits configured keywords, with toggleable/configurable rules and model-editable memory.

Manifest valid

★ 0

MIT

JavaScript

Aug 17, 2026

dsh plugin --profile web add dsh-keyword-context

by d3vmeh

DeepSeek Harness plugin: keep a local model's context at a size your GPU handles well (measured prefill speed, hard ceiling, early compaction)

Models & ProvidersTools & CapabilitiesDevelopment & InfrastructureManifest valid

★ 0

↓ 74/wk

MIT

JavaScript

Oct 4, 2026

dsh plugin --profile web add dsh-context-budget

by xiangnan0811

DeepSeek Harness plugin for ClinePass: models, API key, and usage limits.

Development & InfrastructureManifest valid

★ 0

MIT

JavaScript

Oct 3, 2026

dsh plugin --profile web add dsh-clinepass

by TheYoungChen

DeepSeek Harness plugin market - browse, search & install dsh-plugin topic plugins (dsh 插件市场:浏览/搜索/安装插件)

Manifest valid

★ 4

↓ 271/wk

MIT

JavaScript

Oct 11, 2026

dsh plugin --profile web add dsh-plugin-market

by aerince

Model-authored context pruning for DeepSeek Harness through the official compaction API.

Memory & ContextTools & CapabilitiesDevelopment & InfrastructureManifest valid

★ 2

MIT

JavaScript

Aug 15, 2026

dsh plugin --profile web add dsh-active-context-pruning