dsh-session-inject: Directly Injecting into an Existing Session Without Sub-Agents

Introduction

In DeepSeek Harness (dsh), many developers are accustomed to spawning a sub-agent for each task, letting it execute and return results. This pattern is convenient for simple scenarios, but it gives rise to two problems when maintaining long-lived projects:

  1. The parent session “over-edits”: After a sub-agent finishes, the parent session wakes up and starts “improving” the result—rewriting confirmed checklists, replacing verified screenshots, editing files the sub-agent just delivered—turning correct output into something unrecognizable.
  2. Sub-agents have insufficient context and poor cache utilization: Sub-agents start from a narrow prompt, are unaware of project conventions, and require manually supplementing CONTEXT.md for every dispatch. Moreover, since each one is a fresh conversational session, the prefix cache starts from 0, and identical instructions are counted as uncached input; in contrast, the parent session already enjoys a 77–82% cache hit rate.

The author wants a simpler approach: send instructions to a session that already holds the project context and long-term memory, let it handle the round on its own—no sub-agent, and no post-hoc rewriting by the parent session.

What This Is

dsh-session-inject is a DeepSeek Harness (dsh) plugin maintained by jackfengzhao. It provides a loopback MCP endpoint that allows any MCP client (e.g., Hermes) to send a single round of user instructions to a specific running dsh session and read that session’s final reply for the round. The session handles the round logic itself, using its own model, tools, working directory, permission presets, and context—no sub-agent is spawned.

Core Features

  • Runs within the session: Injected content enters the session as a source.kind = "user" message, and the session responds using its own model, tools, working directory, and context.
  • Five MCP tools (JSON-RPC 2.0): sessions_list, session_inject, inject_status, submissions_list, session_create.
  • Wait without losing the handle: The wait_ms cap is 240 seconds, below the MCP client’s 300-second timeout; every response (including errors) carries a submission_id.
  • Recoverable: If a response is lost, the submission can be re-located by session via submissions_list; records are persisted, and after restarting dsh, old ids return phase: "orphaned" with their last known state rather than unknown.
  • Observable: phase, idle_ms, last_event_type, and steps_seen are drawn from the session’s event stream (turn/start, step/start, tool/call, assistant/message, turn/end), allowing you to distinguish states such as “thinking,” “calling a tool,” and “dead.”
  • Optional SSE progress: When the client sends a progress token in params._meta.progressToken, the plugin pushes notifications/progress every 8 seconds, consistent with the official SDK validation.
  • Zero runtime dependencies: Loopback communication only, with optional Bearer Token authentication.

Installation & Activation

  1. Install the plugin into one or more dsh configuration profiles:
dsh plugin --profile web     add /path/to/dsh-session-inject
dsh plugin --profile desktop add /path/to/dsh-session-inject
  1. Ensure the plugin is included in the bundle (dsh plugin add does not always write it automatically):
    - Edit ~/.dsh/profiles/<profile>/package.json and make sure dsh.profile.bundles contains "dsh-session-inject".
  2. Restart dsh (the plugin is loaded in-process), then check the health endpoint:
curl -s http://127.0.0.1:3090/health
  1. Add the endpoint in Hermes (or any other MCP-capable client):
hermes mcp add dsh-session-inject --url http://127.0.0.1:3090/mcp/session-inject
  • If prompted “require authentication?”, choose n.
  • If prompted “enable all tools?”, choose y.
    5. Reload MCP in Hermes (/reload-mcp) or start a new session to begin using it.

Typical Usage

Inject a round of conversation into a specified session via the session_inject tool:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "session_inject",
    "arguments": {
      "session_id": "<target session id>",
      "content": "Please generate a test case based on the existing code, covering edge cases.",
      "delivery": "queue",
      "wait_ms": 120000
    }
  }
}

Example response (key fields shown):

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "ok": true,
    "session_id": "<target session id>",
    "submission_id": "<submission id>",
    "status": "completed",
    "phase": "turn/end",
    "wait_capped": true,
    "requested_ms": 120000,
    "effective_ms": 84320,
    "elapsed_ms": 84320,
    "steps_seen": 7,
    "last_event_type": "turn/end",
    "last_activity_at": "2026-12-01T10:23:45Z",
    "idle_ms": 0,
    "reply_text": "<the session's final reply for this round>",
    "turn_end_seq": 42,
    "turn_end_reason": "completed",
    "assistant_texts": ["<list of assistant messages>"]
  }
}

If you need to query the status of a specific submission, use inject_status or submissions_list, locating the record by submission_id. It returns observable fields such as phase, idle_ms, last_event_type, and steps_seen.

Use Cases & Notes

  • Ideal for scenarios where you already have a long-lived session, need to continuously inject instructions without the parent session over-editing results, or want to leverage the parent session’s existing cached context.
  • The plugin runs with the permissions of the current dsh process, so ensure the installation source and license are compliant. It is recommended to review the source code and LICENSE before installing.
  • dsh version requirement: 0.2.x (uses ctx.sessionController.prompt); compatibility verified on dsh 0.8.x desktop builds.
  • Network communication is limited to loopback (default 127.0.0.1); no external dependencies.

In Summary

dsh-session-inject lets you send instructions directly to a session that already understands the project, avoiding the context gaps caused by sub-agents and the parent session’s tendency to “over-edit” results. It provides controllable, recoverable, and observable injection capability through five MCP tools, making it well-suited for workflow scenarios that require long-lived sessions and stable outputs.

  • Directory page: https://www.skillhub.cn/plugins/jackfengzhao/dsh-session-inject
  • GitHub: https://github.com/jackfengzhao/dsh-session-inject
羽毛球分组比赛记分
小程序二维码

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

Xiaoye