dsh-context-management: DSH Window Switching Compression, Session Notes, and Pagination History

Preface

When running long sessions in DeepSeek Harness (DSH), the context can max out the token budget. Native compression condenses earlier conversations into summaries, relying on the model to “remember” as much detail as possible. If a task spans many turns, involves long tool outputs, or requires verifying the raw text of a past tool call after the fact, relying solely on a single round of summarization is often insufficient.

The dsh-context-management introduced below (maintained by overact, categorized as “Memory” in the community directory) implements windowed compaction on top of DSH’s official compaction extension points: it cuts conversations into multiple windows, generates handoff documents with length limits when switching windows, and provides session-private notes and paged history retrieval. This allows the model to pull back original records using tools when needed. The approach borrows from Codex’s multi-window concept, but the README explicitly states it is not a 1:1 port of the Codex API, nor does it guarantee lossless recovery of all semantics.

What is this

dsh-context-management is a DSH plugin, package name @local/dsh-context-management, current version 0.3.6 (MIT). In one sentence: it provides windowed compaction, notes persisted across window switches/restarts, and paged recall of the full raw history of the current session in DSH 0.2.0 series environments with Node.js ≥ 22.15.

The plugin subclasses BasicCompactionEngine via @local/dsh-context-management/compaction, overriding summarize() and the dynamically dispatched compactIfNeeded(). It does not monkey-patch instances or read Cordis internals; automatic compaction is still driven by DSH’s original callbacks, and thresholds and retention ratios still use DSH’s thresholdRatio, headroomTokens, and retainRatio. The plugin does not modify these values.

Core Features

Window Switching and Handoff

Four entry points eventually follow the same window switching flow: usage reaching the automatic compaction threshold, a new_context request, manual /compact, and provider-reported context overflow. The automatic threshold path compresses old messages and retains the most recent ~16% verbatim; explicit window switching or overflow paths retain only the last message before compressing.

Upon successful window switching, a new window is entered (e.g., win_N+1), while the system prompt and tool list remain unchanged. Each switch generates a handoff with a character limit (default handoffMaxChars: 16000, adjustable 8000–32000). When handoffSummary: generated (default), the native summarization model is called once for the windowed-out range, and the result is wrapped in <generated_handoff>. This is combined with the goal, todo, the last four user instructions (with event addresses), a preview of recent notes, and window indices to form the handoff; if it fails or the budget is insufficient, it falls back to truncation without blocking the window switch. The window number only advances after DSH actually commits the message replacements.

The plugin also writes notes after each successful window switch: handoff.md is replaced with the latest complete handoff, and handoff-log.md appends a one-line summary index.

Tool List

Tool Function
new_context Requests a window switch at the next safe step boundary (returns requested, does not reset immediately)
notes_write_file / notes_append_to_file / notes_read_file / notes_list_files_by_prefix / notes_search_contents Session-private notes, persisted across window switches and restarts
history_list_windows / history_list_items / history_read_item / history_search_contents Paged retrieval of the session’s full raw history; history_read_item can read item IDs for window summaries, goals, checklists, etc. referenced in handoffs

new_context is only available in presets with this windowed engine mounted; other presets will explicitly report an error, but notes/history remain available.

Commands and Settings

  • /ctx: Toggles the plugin (affects all sessions of the current DSH instance, not just a single chat tab).
  • /compact: Executes compaction according to the current mode.
  • The Web “Context Management” settings page (DSH 0.2.0 configForms) shares the backend with /ctx; changing settings does not require a restart.

When the plugin is disabled or related tools are turned off, compaction behavior reverts to DSH’s native summarization.

Installation and Enablement

The plugin is not published to npm and needs to be introduced as a local link in the profile. The following steps are excerpted from the installation section of the GitHub README.zh-CN (execute after obtaining the source code).

  1. Install dependencies in the plugin directory and perform pre-installation checks (confirm DSH capabilities and no conflicts with the profile):
npm install
npm run preflight -- --profile web
  1. Add the local link to the dependencies in the package.json of the profile directory ($DSH_HOME/profiles/<profile>/), and run pnpm install in that directory:
"@local/dsh-context-management": "link:<plugin-directory>"
  1. Register the plugin in the profile’s cordis.patch.yml, for example:
- insert:
    - id: context-management
      name: '@local/dsh-context-management'
      config:
        enabled: true
        overrideCompaction: true
        injectTools: true
        defaultStrategy: window
        modelPolicies: []
        handoffSummary: generated
        handoffMaxChars: 16000
  1. Mount the windowed engine for the Web preset (it will run preflight again before writing; if it fails, the profile will not be modified):
node scripts/sync-presets.mjs --profile web
  1. Restart DSH and refresh the webpage. After upgrading DSH, sync-presets.mjs needs to be run again; if plugin source code is modified and lib is not added to DSH’s hmr root, the plugin needs to be reloaded or DSH restarted before refreshing the page.

Community directory page: skillhub.cn/plugins/overact/dsh-context-management (independent site, not officially affiliated with DeepSeek / High-Flyer).

Typical Usage

Daily Toggling and Compaction

In a DSH session:

/ctx
/compact

The model can call new_context at appropriate times; the window switch will wait until the tool results of the current step are fully written to history before executing. Even if DSH’s auto compaction is turned off, explicit window switch requests will still be processed.

Using Notes for Key State

Write decisions, todos, and paths into self/notes/<path> via tools like notes_write_file. Notes are stored in $DSH_HOME/context-management/notes/<sessionId>.json, isolated by session, and do not support arbitrary cross-session read/write. During window switching, recent notes can be injected into the handoff in a limited way, but full content still relies on notes tools for reading.

Using History to Find Original Text

Lists and searches return has_more and next_cursor; use next_offset_chars to read the body. history_read_item with format: "json" allows paged reading of complete raw events (including call parameters and metadata). History comes from the caller’s own immutable DSH session log; item_<seq> provides a stable address, and indices for old records are not discarded even after exceeding 2,000 entries.

Verifying the Plugin

In the plugin repository directory:

npm run verify

Tests use local fixtures and do not call paid models; version 0.3.6 on DSH 0.2.0-rc.2 is documented in the README as having 108 passing tests.

Use Cases and Notes

Who it is for: DSH users running long-time coding agents, multi-turn tool calls, and requiring the ability to query session logs and self-managed notes via tools after compression; scenarios that want to use “multiple windows + handoff” instead of a single native summary to carry the entire process.

Boundaries: Handoffs have hard character limits and are trimmed by priority; history/notes lists and single reads also have default limits (see the “Efficiency and Boundaries” table in the README). Backup or migration must include context-management/notes/; deleting a session does not automatically delete the corresponding note files.

Security and Permissions: The plugin runs with the permissions of the current DSH process and can read/write notes and session-related data under $DSH_HOME. Before installation, please read the GitHub source code and the MIT license, and execute preflight and sync-presets.mjs in a trusted environment to avoid conflicts with tools/commands of the same name or other compaction engines in the profile.

Conclusion

dsh-context-management extends DSH’s native compaction into a long-session workflow that is windowed, handoff-capable, and searchable: compaction saves tokens, notes retain state, and history supplements details. If you are doing “everything is a plugin” style agent development in the DSH ecosystem, you can start from the community directory or GitHub, follow the documentation to complete the link and preset synchronization, and then start long tasks.

  • Directory Page: https://www.skillhub.cn/plugins/overact/dsh-context-management
  • Repository: https://github.com/overact/dsh-context-management
羽毛球分组比赛记分
小程序二维码

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

Xiaoye