Skip to content

About

DSH plugin: check how big / how failure-prone the current session is, then hand off to a fresh session in the same process (session_volume / session_handoff / session_attach).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

dsh-session-handoff

A DeepSeek Harness (DSH) plugin that keeps long sessions from blowing up.

Long sessions grow until the transport layer starts failing (TRANSPORT errors, too busy responses, retry storms). This plugin lets the agent notice that, then open a fresh session in the same DSH process and hand the task over to it — instead of you manually creating a session, copying context and pasting a resume prompt.


🔴 Disclaimer — unpublished internal APIs

This plugin calls DSH internals that are not a public, supported API. Specifically it reaches for the services agents, sessions, agentDefaultModel and workspaceRegistry, and it dynamically imports @deepseek-ai/dsh-llm and @deepseek-ai/dsh-agent by deep path to call createUserMessage, installModelSelection and sessions.flush.

Verified against: DSH 0.1.5-rc.2 only (read from resources/dsh-runtime/node_modules/@deepseek-ai/dsh/package.json → version).

A DSH upgrade can rename, move or drop any of these, and the plugin may stop working without warning. It is written defensively — every failure is reported back to the calling agent as a normal tool error, and startup failures are swallowed so a broken plugin does not take DSH down — but "does not crash DSH" is not the same as "keeps working".


What it does — three tools

1. session_volume

Inspects the session that is currently running and reports:

Field Meaning
sessionId current session id
seq event count (how many events the session has accumulated)
file the session's persistence file on disk
size file size, compared against the soft / hard limits
failures llm/retry events, plus how many mention TRANSPORT / too busy
verdict whether this session should be replaced

The two criteria are reported separately:

  • Size — over the soft limit is a warning, over the hard limit means "replace this session now".
  • Retries — failLimit is an advisory threshold, not a hard line. A single burst of network trouble can rack up several retries on a perfectly healthy session, so hitting it alone does not mean "over the line".

Failures are counted by event type (llm/retry, assistant/attempt*), never by string matching over the whole transcript — otherwise a session that merely discusses TRANSPORT errors would count its own text as failures.

2. session_handoff

Creates a new session inside the same DSH process and posts the first message into it, so the new session can pick the work up. It:

  1. takes the current provider/model selection from agentDefaultModel,
  2. creates the session with agents.create({ sessionId, meta: { cwd }, agentOptions, setup }),
  3. injects the first message with createUserMessage(...) + agent.followup(...),
  4. flushes it to disk (awaited — the result text tells you whether the flush actually succeeded),
  5. attaches it to the sidebar workspace group whose path matches the session cwd.

It returns the new session id and does not wait for the new session to finish its work.

Note: the new session is created server-side, so the GUI does not switch to it. Open it from the sidebar.

Note: step 5 validates the cwd by exact string equality against the workspace path. If the session cwd is a subdirectory of a group, the attach fails by design; the tool says so and you can drag the session into the group manually.

3. session_attach

Attaches an already existing session to the sidebar group matching its cwd. Useful for orphan sessions sitting under "ungrouped" in the sidebar (for example sessions created before the handoff grouping worked). Idempotent. To create a session, use session_handoff instead.


Install

dsh plugin forwards its arguments to pnpm inside the profile directory, so anything pnpm accepts works:

# from a published package name
dsh plugin --profile <profile> add dsh-session-handoff

# from a git repository
dsh plugin --profile <profile> add github:an94-code/dsh-session-handoff

# from a local checkout or a packed tarball
dsh plugin --profile <profile> add ./path/to/dsh-session-handoff
dsh plugin --profile <profile> add ./dsh-session-handoff-0.1.1.tgz

Then restart DSH — plugins are loaded at boot.

Requirements: Node.js ^22.19.0 || >=24.0.0 (the plugin uses node:zlib's native zstd support) and a DSH version whose runtime provides the internal services listed in the disclaimer above.

Verify the plugin loaded by watching the start-up log for:

[dsh-session-handoff] 已加载:session_volume / session_handoff / session_attach(…)

Configuration

Configuration lives in the bundle patch (cordis.patch.yml) under the plugin's config: block, or in your profile's own override layer:

- id: session-handoff
  config:
    runtimeRoot: ''
    handoffPrompt: 'Continue from the previous session.'
    softLimitBytes: 1500000
    hardLimitBytes: 2000000
    failLimit: 3
    cwd: ''
Option Type Default Meaning
runtimeRoot string '' (auto) Base directory for the dynamic import of dsh-llm / dsh-agent. Empty means auto-resolve.
handoffPrompt string Continue from the previous session. First message posted into the new session.
softLimitBytes number 1500000 (1.5 MB) Size at which session_volume warns.
hardLimitBytes number 2000000 (2 MB) Size at which session_volume says "replace this session".
failLimit number 3 Retry count that raises an advisory warning (does not decide "over the line" by itself).
cwd string '' Working directory for new sessions. Empty means "follow the current session".

About runtimeRoot

The default is empty, and that is the recommended setting. Resolution order:

  1. Configured runtimeRoot — used as-is when non-empty.
  2. Package resolution — createRequire(import.meta.url).resolve('@deepseek-ai/dsh-llm') (with the global search paths DSH installs at boot), falling back to import.meta.resolve(...). The plugin then walks up from the resolved file until it finds the directory that actually contains dsh-llm/lib/index.js, so it works regardless of how deep the resolved entry point sits.
  3. A readable error — if neither works, the tool call fails with a message telling you exactly which absolute path to put into runtimeRoot.

Only set runtimeRoot by hand if step 2 fails on your machine. It must point at the runtime node_modules directory — that is, the directory that contains @deepseek-ai, not @deepseek-ai itself (the plugin appends @deepseek-ai/dsh-llm/lib/index.js to it), e.g. <DSH install dir>/resources/dsh-runtime/node_modules.


Design notes

  • Nothing but Node builtins is imported at module scope. Runtime packages are loaded with a dynamic import() inside try/catch, so a missing or renamed package can never break DSH boot.
  • Services are read with ctx.get() and reported back to the calling agent when absent.
  • apply() is fully wrapped in try/catch, as is each individual tool registration.
  • No third-party runtime dependencies.
  • Sessions are read from $DSH_HOME/sessions when DSH_HOME is set (non-blank), otherwise ~/.dsh/sessions — the same precedence DSH's own dsh-home-paths uses.
  • Reading a session file is capped at 12 MB and done in 1 MB chunks, so peak memory does not grow with the size of the file on disk.
  • Session persistence files are matched as session.v*.jsonl.zstd (highest version wins). When the runtime hands the plugin a concrete persistence path, that path is preferred over scanning.

Development

npm test          # node --test
node --check lib/index.js

The tests cover the pure parts — configuration normalisation, runtime-root resolution, session file discovery (against a temporary fake home directory) and failure scanning (against self-built zstd frames). The parts that call DSH internals need a running DSH and are not covered.


License

MIT © an94-code

About

DSH plugin: check how big / how failure-prone the current session is, then hand off to a fresh session in the same process (session_volume / session_handoff / session_attach).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages