# dsh-session-management

**English** | [中文](README.md)

---

A DeepSeek Harness (DSH) plugin that manages sessions generated by the Harness: users can delete legacy sessions, and sessions can be imported from third-party agents (currently Claude Code and Codex).

### Features

- **Unified session management**: cross-source (DSH / Claude Code / Codex) session list, search, preview, open/resume, archive/unarchive, delete and batch cleanup, plus stats — all inside the DSH settings page.
- **Third-party session import**: converts local Claude Code / Codex session histories into resumable native DSH sessions with full fidelity (text, thinking, tool calls and results are all preserved; no fake executable tools are invented).
- **Safety invariants**: third-party source files are always read-only; running sessions can never be deleted; deletion is explicit and irreversible (batch deletion requires typing `DELETE`); cleanup always previews before it executes.

### Installation

One-step install from npm (recommended):

```bash
dsh plugin --profile web add @nathan110628/dsh-session-management
dsh --profile web --dump-config   # you should see the "# == @nathan110628/dsh-session-management" layer
dsh web
```

Or install from GitHub (equivalent; the repo ships prebuilt `lib/`):

```bash
dsh plugin --profile web add github:AndyWipe13/dsh-session-management
```

Uninstall:

```bash
dsh plugin --profile web remove @nathan110628/dsh-session-management
```

### Development build & local assembly

- `src/index.ts` — plugin entry point (exports `apply(ctx)`)
- `cordis.patch.yml` — config patch contributed by the bundle (`dsh.bundle.patch`)
- `package.json` — declares `dsh.bundle` and peer dependencies
- `scripts/build.js` — cross-platform Node build script

Build (no DSH source checkout needed; automatically falls back to the official dependency mirror at `~/.dsh/profiles/node_modules`):

```bash
npm install
npm run build
```

Output goes to `lib/` (entry `lib/index.js`, types `lib/types/index.d.ts`).

**Assembly:**

```bash
dsh plugin --profile web add .
dsh --profile web --dump-config
dsh web
```

### Baseline verification

On a Windows environment without a DSH source checkout (relying on the official dependency mirror at `~/.dsh/profiles/node_modules`), you can run directly:

```bash
npm run build       # compile src -> lib
npm run typecheck   # TypeScript type checking (builds and links dependencies first)
npm test            # run tests (builds first)
```

Tests use the Node built-in test runner (`--test-isolation=none`) and cover:

- plugin baseline exports and bundle-assembly self-check (the `hello` placeholder tool has been removed);
- assembly against fake official services (`sessions` / `sessionQuery` / `sessionPersistence` / `workspaceRegistry` / `storageDomain`);
- a read-only fixture bank (≥ 2 sessions each for Claude Code — including `archived_sessions` — and DSH, with empty-session / malformed-line / Chinese Unicode / subagent edge-case samples).

Fixtures live in `test/fixtures/`; their bytes and mtime must not change before or after any test. See `scripts/generate-fixtures.js` for the generator script.

Import creates or reuses the official workspace based on the source session's `cwd`, registers session members after the log is persisted, and saves the scan-page title as a `session/title` event. Import reports a failure when the working directory does not exist. On rc.7 the sidebar needs a page refresh to sync.

Host-interface regression tests live in `test/host-contract.test.js`, covering the official title's `value.title.title` nesting, workspace registration after persistence, and the release of the cold-preparation object in the legacy title-repair path. `scripts/check-session-ui.cjs` takes a Playwright `page` plus a temporary session's `{ sessionId, title }` and verifies selection, archive, unarchive, delete-cancel and actual deletion; it runs only against disposable test sessions.

### Reference

Official plugin development guide: <https://deepseek-harness.github.io/deepseek-harness/develop/basic/>
