dsh-session-shift: Automatic Session Handoff Under Context Pressure

Foreword

Long sessions tend to degrade within DSH. The author’s own testing indicates that “thinking without output” occurs after approximately 70% of the context is used. DSH’s native compaction is an “in-place compression” that replaces the original text with a summary, effectively rewriting history. This plugin provides an alternative solution: when context pressure reaches a threshold or the session has been compacted too many times, it starts a new session, preserves a reviewable handoff package containing the original text, and keeps the old session as-is.

Introduction

dsh-session-shift is a DSH plugin owned by easerlee. Its core function is to hand over current work to a new session when context pressure reaches a threshold. It does not rely on model summarization; instead, it mechanically extracts the session’s own state (modified files, used tools, recent messages, where it stopped) to generate a handoff package on disk. All operations are performed locally only; there is no networking or external data transmission.

Installation

Installation commands differ based on the host environment (Desktop or Web).

Desktop (profile desktop):

"<DSH 安装目录>\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add dsh-session-shift

Note: You must open the desktop application at least once to initialize the profile, and fully exit the application before executing this command (the profile has a write lock).

Web (profile web):

dsh plugin --profile web add dsh-session-shift

Note: The profile will be automatically initialized upon first use.

After installation, restart the corresponding client, as the bundle list is only read at startup.

Configuration

The core configuration of the plugin is located in the profile’s cordis.patch.yml. This file is the configuration manifest for the DSH profile, declaring this plugin as a mounted bundle; it does not modify runtime code.

Configuration Example:

- id: dsh-session-shift
  config:
    enabled: true
    thresholdRatio: 0.6     # Context pressure ratio to trigger handoff
    maxCompactions: 2        # Number of compactions in this session before triggering handoff (0 = pressure only)
    cooldownMs: 300000      # Minimum interval between two handoffs in the same session
    handoffDir: .dsh/handoff
    recentMessages: 14
    maxChars: 24000
    renameOldSuffix: " [已交接]"
    dryRun: false
    stopOldSession: true     # Whether to stop the current turn of the old session after handoff

Usage

The plugin provides two trigger methods: tool calls and HTTP interfaces.

Desktop trial run (does not actually create a session):

handoff_now(dryRun: true)

Web or command line manual trigger:

curl -X POST http://127.0.0.1:<端口>/api/handoff/run \
  -H "content-type: application/json" \
  -d '{"reason":"手动换会话"}'

Check status:

curl http://127.0.0.1:<端口>/api/handoff/status

Handoff Mechanism

Automatic handoff is triggered when any of the following conditions are met, provided the time since the last handoff exceeds cooldownMs:
1. Context pressure reaches thresholdRatio.
2. The current session has been compacted maxCompactions times (default is 2).

When a handoff occurs, three things are executed in order:
1. First, the handoff package is saved to .dsh/handoff/.
2. A new session is created with a title format of Original Title (Cont. N), where N is the last number in the old title + 1.
3. The old session’s title is appended with [Handed Off], and depending on the stopOldSession configuration, the current running turn of the old session may be stopped.

Handoff Package Content

The handoff package is in Markdown format, entirely mechanically extracted, and does not pass through the model:
* Modified Files: Paths touched in this session (up to 120 entries).
* Used Tools: Top 12 tools sorted by call count.
* Recent Messages: User message segments + Assistant message segments, filled from newest to oldest based on budget.
* Where it Stopped: The last assistant message.

Known Limitations

  • Compatibility: Automatic session switching relies on the harness’s uiWorkspace.openSession interface. If the harness is older and lacks this interface, the plugin will not error out, nor will it automatically switch sessions; the reason will be recorded in $DSH_HOME/handoff-client-report.json.
  • Old Session Handling: The old session is only renamed, not archived (this is intentional).
  • HTTP Interface: Only affects active sessions within that host process.

License

MIT

羽毛球分组比赛记分
小程序二维码

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

Xiaoye