idianzi/dsh-context-handoff ↗★ 1
dsh-context-handoff
Token-aware context handoff for DeepSeek Harness: summarize a long session into a Markdown file, compare continue-versus-switch token costs, switch auto mode from the sidebar, and resume in a fresh session.
同名パッケージの別リポジトリ
インストール
npx -p @deepseek-ai/dsh dsh plugin --profile web add dsh-context-handoffドキュメント
README 全文を読む ↗Usage
| Command | Effect |
|---|---|
/handoff | Write a handoff and report the comparison. |
/handoff plan [turns] | Analyze only; no model call, no file. turns is the horizon (default horizonTurns). |
/handoff now [tokens] | Write now with an explicit digest budget (minimum 600). |
/handoff status | Current pressure plus the latest file. |
/handoff list | Newest files in the output directory. |
/handoff stats | Aggregate the local JSONL ledger. |
/handoff auto [on|off] | Show or set the per-workspace auto switch. |
/handoff help | Help. |
Sidebar panel
Next to the session title there is a small chip — 上下文 545k, or 自动总结 545k while auto mode is on. Clicking it expands the right sidebar and opens the handoff panel, so you do not have to know where the sidebar is. You can also open it from the right sidebar's add menu: 上下文交接 / Context Handoff.
- Condensation is automatic and has no switch. At the recommendation point the plugin condenses once with the same backend
/compactuses (compactNowfromdsh-compaction-basic), replacing older history with a single summary: up tomaxCompactionsPerSessiontimes per session (default 3), and it stops early when a condense frees less than 10% of the context. - That backend lives inside the session's preset group (
isolate: { compaction: true }), so a host-plane plugin cannot reachctx.compaction. The plugin therefore drives it through the official command —ctx.commands.execute(agent, '/compact')— whose handler runs inside that scope and calls the same backend. The panel's compaction row reports which route was used:agent,context,command, ornone. - A handoff only runs when the context is still over the threshold after condensing. That step is what the switch controls: off means condense only, on means write the file and start a new session.
- The switch controls the new-session step of auto mode. It is stored in
.dsh/handoff/auto.jsonand survives restarts. - The panel shows current context, the recommendation point, a progress bar, and buttons for file-only or file-plus-new-session.
- When auto mode fires, the host writes the file, creates a new root session in the same workspace, and queues
Read @...as its first message. The panel switches to it when the source session is the one on screen; otherwise it offers an Open new session button. autoNewSession: trueby default; set it tofalseto write files only.
Auto mode is per workspace and performs at most one automatic handoff per source session.
Example plan:
Context: 118k / 128k (92%), 10.0k headroom
Composition: 11.0k fixed prefix + 107k messages
Digest: 3.0k tokens (budget 3.0k)
Per-turn saving: 57.2k tokens (cache factor 0.55) · break-even 1.2 turns
Over 8 turns: saves 388k tokens after paying for the summary
Recommended now: a handoff repays itself in 1.2 turns, and the context is already at 92% of the window.
Recommendation point: 70.4k tokens (55% of window)
Earliest efficient point: 17.2k tokens over 8 turns
Cache assumption: 50% hit, cache-read weight 0.1
The file goes to .dsh/handoff/ by default and starts with YAML frontmatter, a copy-paste resume line, and then the summary. The resume workflow is:
/handoff plan 10to check the economics./handoffwhen you are ready to leave.- Open a fresh session and paste
Read @.dsh/handoff/.md and continue from the "Next steps" section. - Continue from that section; keep the old session as evidence if useful.
The output directory also contains ledger.jsonl (token numbers, model, file name, session id; no conversation text). Set ledger: false to disable it.
Configuration
- id: context-handoff
config:
outputDir: .dsh/handoff
targetDigestTokens: 3000
recommendAtRatio: 0.55
recommendMaxTokens: 256000
horizonTurns: 8
auto: false
autoNewSession: true
A bundle install already inserts the row; use - id: context-handoff to override it. For a hand-composed profile without the bundle patch, insert it explicitly:
- insert:
- id: context-handoff
name: dsh-context-handoff
| Field | Default | Meaning |
|---|---|---|
outputDir | .dsh/handoff | Output directory, relative to the workspace or absolute. |
targetDigestTokens | 3000 | Digest token budget. |
minDigestTokens | 700 | Lower bound for small contexts. |
maxDigestTokens | 8000 | Absolute cap. |
digestRatio | 0.03 | Budget as a share of current context, then clamped. |
recommendAtRatio | 0.55 | Quality threshold as a window fraction. |
recommendMaxTokens | 256000 | Absolute cap for the recommendation point; 0 disables it. |
horizonTurns | 8 | Cost-comparison horizon; at least 2. |
cacheHitRatio | 0.5 | Assumed cache hit share. |
cacheReadWeight | 0.1 | Relative cache-read cost. |
switchOverheadTokens | 1500 | Re-orientation cost of a new session. |
keepFiles | 20 | Files kept per directory; 0 disables pruning. |
auto | false | Default for workspaces without an auto.json override. |
autoNewSession | true | Auto mode creates a new session and queues the resume prompt. |
autoMinGrowthTokens | 8000 | Minimum growth between auto handoffs. |
autoCooldownMinutes | 10 | Cooldown between auto handoffs. |
maxCompactionsPerSession | 3 | How many automatic condensations one session may get; 0 disables automatic condensation. |
provider / model | empty | Summarization route; empty follows the routed request or agent options. Set both or neither. |
maxOutputTokens | 0 | Summary output cap; 0 derives it from the budget. |
language | auto | auto, en, or zh. |
includeToolDetails | true | Include tool names/short arguments in the fallback. |
transcriptBudgetRatio | 0.7 | Window share for the plain-text fallback transcript. |
redactSecrets | true | Redact common credentials before writing. |
fallbackDigest | true | Write a deterministic digest if the model fails. |
ledger | true | Append ledger.jsonl. |
Auto mode writes only when the workspace switch is on, the agent is idle, the session is not a subagent, the plan is useful, the recommendation point is crossed, this source session has not already completed an automatic handoff, and no recent handoff exists. It runs through agent.runMaintenance(), never interrupts a live turn, then creates a new root session in the same workspace with the resume prompt queued. The file remains valid if session creation fails.