dsh-mode-exchange: Switching Agent Mode in an Existing Session and Migrating Rebuild

Preface

DeepSeek Harness (DSH) Agent modes (Standard, PTC, Code, Research, etc.) are locked into a fixed plugin combination when a session starts. Existing sessions with messages are blocked by agent-preset/locked, and the only official workaround is to create a new session. This means that switching modes mid-conversation or rebuilding a session forces you to either interrupt the task or lose context.

dsh-mode-exchange is a general-purpose DSH plugin that allows you to dynamically switch to any built-in Agent mode in any existing session, or to migrate and rebuild a session into the target mode. It works by reconfiguring the session’s toolset and system prompt to achieve a seamless switch without interrupting the current task or recreating the session.

Feature Overview

The plugin provides two capabilities: runtime soft switching and migration rebuild.

Capability A: Runtime Soft Switch

Switch modes within the current session, scoped to that session only.

Commands

  • /switch-mode <mode-name> — Switch to the specified mode
  • /switch-mode --revert — Roll back entirely using the entry-point snapshot
  • /switch-mode --list — Enumerate all modes at runtime (zero hardcoding), marking the current, default, and assembly-failed ones

Implementation

  • Swap system prompt: In the system-prompt/assemble waterfall, remove the existing section and replace it with a section generated by this plugin that describes the target mode (including its tool inventory and working style)
  • Unload old tools: agent.ctx.tools.restrict({ deny }) removes tools that “exist now but not in the target” from both the declaration and dispatch sides — invisible to the model, and calls are rejected
  • Attach new tools: agent.ctx.tools.register() + when gating registers tools that “exist in target but not now” into the session scope
  • An additional tools.guard backstop prevents bypassing the schema to dispatch directly

Snapshot & Logging

  • Snapshots are persisted to state/switches.json; after settings changes trigger a plugin rebuild, the snapshot is automatically read back and reconstructed
  • Sessions that cannot be switched (nonexistent / archived / sub-agent / no active Agent / no scope) receive a specific reason message rather than a silent failure

Capability B: Migration Rebuild (Seven Steps)

Migrate and rebuild a session into the target mode, with the new session having a real mode and a real import of the native message sequence.

Seven-Step Flow

  1. Export → <export-dir>/exports/<YYYYMMDD-HHmmss>-<short-id>.jsonl + .meta.json (including sha256)
  2. Validate → Line-by-line parsability / event count match / seq continuous from 0 / sha256 match; abort on failure, preserve the scene
  3. Create Session → Create with the target mode as agentPreset, and call agentPresets.mount() in setup for a real assembly
  4. Import → Write the native event sequence as a constructor seed (not a restatement):
   Source event prefix (seq 0..N-1)
     + session/end-seed{inherited:true}   ← lands exactly at index = inheritedEventCount
     + Closing events: unclosed turn/step get step/end, turn/end;
                tool calls without a result get an isError tool/result
                (TOOL_OUTCOME_UNKNOWN / TOOL_NOT_STARTED, with the host's original "don't blindly retry" hint)
  1. Team → With --team on, call agentTeams.setEnabled(true) on the root Agent, then re-read isEnabled to verify
  2. Archive → With --delete-old true, back up first then archive the old session
  3. Report → Old/new session IDs, log path, message count, tool call count, team status, old session disposition, duration, timeline

Supporting Safeguards

  • Idempotent: Ledger migrations/<source-session-id>.json tracks progress per source session; re-running does not produce a second new session but instead prompts you to choose “resume / abandon”
  • No data loss on failure: If the new session is created but import validation fails, both the new session and logs are preserved, and the report lists the remaining steps that can be completed manually
  • Every failure has a reason: The real error is written into both the report’s error field and the first entry in remainingSteps (“Failure reason: …”), displayed directly below the failure badge in the panel
  • Stays on the new session after migration: On success, the main view automatically switches to the new session and pins it via workspaceRegistry.pinSession (result recorded in target.pinned); can be disabled in settings (autoOpenTarget)
  • Source marking: The first message in the new session is appended with a note stating “Migrated from session X at time T, original mode A → new mode B”, including the --note text
  • Export copy policy: With keepExportCopy=false, the export file is deleted on successful completion; on failure it is always retained

UI & Interaction

Sidebar Panel (sidebar.panellist + main, id/key both mode-exchange)

  • “Switch” tab: Session title, currently active mode, switchability, a collapsible “Select Session” window (identifies sessions by title + owning workspace, defaults to the one you just clicked into), target mode dropdown + Apply/Revert, entry snapshot, soft-switch warning
  • “Migrate” tab: Collapsible “Select Session” and “Select Workspace” windows (new session joins the target session’s workspace by default), target mode, archive old session (default on), team collaboration (greyed out with reason when unsupported), note, Execute/Cancel, resume card, seven-step progress with timing, report
  • “History” tab: Timestamp / source session / target session / result; click to view report; one-click open target session

Session Right-Click Menu (contextMenus with session / sessionHeader target)

  • “Switch Mode”: Lists all modes; the current mode is marked “(current)”, assembly-failed modes are greyed out; one click completes a soft switch with a host toast confirming the result; if the session cannot be switched, the reason is stated directly in the menu (no active Agent / archived / sub-agent, etc.)
  • “Migration Rebuild”: Also lists all modes; one click initiates a migration rebuild (parameters taken from settings defaults); after initiation, a notification bar shows “View Progress” — clicking it opens the plugin panel and displays the seven-step progress; during an active migration, modes in the menu are greyed out to prevent duplicate initiation

Settings Page (settings.section + settings.section.icon)

  • Default target mode
  • Default whether to archive old sessions
  • Default whether to enable team collaboration
  • Log export directory
  • Whether to keep export copies
  • Whether to require forced confirmation before migration (turning it off triggers a secondary warning)
  • Whether to automatically open the new session after successful migration (and pin it)

The sidebar and settings page share the same persistent configuration, synced instantly on change.

Installation

Requires DSH >=0.2.2-rc.3 <0.3.0, Node 22+. No install script, no build-time dependencies.

From npm (simplest when published): Sidebar Plugins → Add Plugin → enter the package name dsh-mode-exchange, then click “Enable Now” after installation. Equivalent tool call:

plugin_manager({ action: "install_bundle", target: "dsh-mode-exchange" })

From a local directory (development):

plugin_manager({ action: "install_bundle", target: "<absolute-path-to-this-repo>" })

Confirm after installation:

plugin_manager({ action: "list_plugins" })   // status should be active

Local directory installation links the entire checkout, and files does not take effect — if you want a clean install, copy it separately and then install. Replacing an already-installed package requires restarting the host; JS module generations are not hot-swapped. Do not manually edit the profile’s cordis.patch.yml — that is the most common way to corrupt a profile.

For direct mounting during development or installing to a different profile, see docs/LOCAL-DEV.md.

Usage Examples

Example 1: Switch a long session to PTC

/switch-mode --list
  → Available modes (4):
    · standard (Standard) (current)
    · ptc (PTC) (runtime default) — drives work through a single code execution tool
    · code (Code)
    · research (Research)

/switch-mode ptc
  → Switched to "PTC" mode. Toolset has changed.
    Unloaded (not provided by target mode): read_file, write_file, list_dir …
    Attached (new in target mode): run_code
    Note: This only performed a prompt-level switch; the **execution mechanism** of tools has not changed;
          to actually use PTC's code execution channel, use /migrate-session --mode ptc to rebuild the session.

/switch-mode --revert
  → Reverted to pre-switch state: standard mode.

Example 2: Migrate a session to PTC, keeping the old session

/migrate-session --mode ptc --delete-old false --note "Switching to PTC to continue refactoring"
  → Migration started (task 3f2a1b9c), 7 steps total:
    ① Export session log ② Validate integrity ③ Create new session with target mode ④ Import history
    ⑤ Team collaboration ⑥ Archive old session ⑦ Report
    Target mode: PTC (ptc)
    Old session: Retained
    Team collaboration: Not enabled

Watch the seven steps complete in the sidebar panel. The report shows the new session ID and log path. Open the new session — history messages and tool calls are all there, just continue chatting.

Example 3: Migrate + enable team + archive old session

/migrate-session --mode ptc --team on --yes

Without --yes, for safety the old session will not be archived (the command will state this explicitly). With --yes, it follows the “backup first, then delete” policy: backs up to backups/, then archives the old session. The panel path goes through a confirmation dialog showing the old session’s title, message count, log path, with an optional “backup first” option.

Example 4: Only want to archive an old session

Sidebar panel “History” tab or POST /api/mode-exchange/archive-old, with confirm and backup parameters.

Known Limitations

1. Capability A is a “soft switch”, not a real mode

Real mode assembly (new session) This plugin’s soft switch
Plugin combination Mounted per preset declaration Unchanged, only prompt and tool visibility change
Tool executor Determined by preset (native / PTC) Unchanged — PTC’s run_code transport layer does not appear due to switching
Session ID New Unchanged
History Copied over Retained in place
Sub-agents / Team Per new preset Unchanged

What it can do: which tools the target mode has, how the prompt is written, the working style the model sees. What it cannot do: change the tool execution channel. After a soft switch, calls to unloaded tools are rejected (with a clear error), rather than “appearing usable but not going through the right channel”. Both the command response and the panel proactively inform you of this.

2. FR-9’s “delete old session” is implemented as archiving

DSH has no session deletion API:

  • The workspace service only has archiveSession / unarchiveSession / pinSession;
  • workspaceRegistry.delete() deletes a workspace, not a session;
  • Session log files are in the persistence layer; the plugin layer has no delete handle.

So “delete” here = archive:

  • Hidden from all grouped views, removed from the pinned list;
  • Its activity is stopped as requested;
  • The log file on disk remains and can be undone with unarchiveSession.

If you expect “data to be erased”, archiving cannot do that; if you expect “it to not appear in my list”, archiving is exactly right. The report always says “archived”, never “deleted”.

Additionally, archiving may be deferred: /migrate-session runs in the old session’s… (truncated)

Use Cases

Suitable for scenarios where you need to switch modes within an existing session or rebuild a session, such as:
- Switching modes mid-conversation in a long session
- Migration requiring real mode assembly (including tool execution channels)
- Rebuild that needs to preserve historical context

The plugin runs with the current DSH process permissions. Review the source code and license before installation.

Summary

dsh-mode-exchange provides DSH with the ability to switch Agent modes within existing sessions and to migrate/rebuild sessions into a target mode. Runtime soft switching only modifies the prompt and tool visibility, suitable for scenarios where only the tool list and prompt differ; migration rebuild fully imports the native event sequence, suitable for scenarios requiring real mode assembly.

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

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

Xiaoye