# dsh-desktop-tool

Desktop controls for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH). Plain JavaScript, no build step.

| Capability | What it does | Where it lives |
| --- | --- | --- |
| **Delete a session** | Removes one session's stored log and every registry record pointing at it | Trash button in the session row, and the session's "…" menu |
| **Clean up sessions** | Select several sessions in one workspace, confirm once, receive a per-row report | Workspace "…" menu → "Clean up sessions…" |
| **Retract a message** | Retracts a message and everything after it; a retracted prompt is restored to the composer | Every message's own action row |

- **Stored history is never rewritten.** A retraction appends one surface replacement; the original records stay.
- **No model-visible tools.** Both features change what the model sees next, so neither is exposed to an agent.
- **Destructive work is predictable.** Deletion confirms once and reports a per-row outcome.

## Install

Install through DSH's Plugins page (by name or absolute path), or from a shell: `dsh plugin --profile <profile> add dsh-desktop-tool`.

**Install it into a DSH profile.** The Host half resolves `@deepseek-ai/schemastery` from the Host, and the client half receives `react` from the Host's module table; both are declared as peers. The client UI modules come from that same module table at runtime, so the package carries its own code and lets the Host supply every shared module.

A linked bundle is loaded once per Host process: after editing `lib/*.js`, disable and re-enable the plugin (or restart DSH).

## Deleting a session

DSH's archive only hides a session; nothing in the persistence, session, workspace or Remote layers can remove one. This package removes the log directory `<DSH_HOME>/sessions/<project>/<sessionId>/`, its projection cache checkpoint under `<DSH_HOME>/storages/session_projcache/sessions/`, and every durable record pointing at it (workspace ledger, archive set, pin set). The row then disappears without a restart.

- **The directory must be provable** — it must be named exactly after the session id; otherwise the request is refused rather than guessed at.
- **Running work does not block deletion.** A session in the middle of a turn, a job or a subagent can be deleted like any other session; the Host's agent may keep writing into the removed directory until it is restarted, which leaves an orphan folder that no listing shows.
- **A live agent does not block deletion by default.** The Host keeps an agent for every session it has opened until the process exits; set `allowLiveSessionDelete: false` to refuse those instead.
- **Leftover records can be cleaned again** — a session whose log is already gone but is still referenced can be deleted again, which only clears the records.

**Batch cleanup**: the workspace "…" menu enters cleanup mode (the only entry). A mode bar takes over the row with a tri-state select-all, a trash icon and an exit ✕; checkboxes appear only on idle, unarchived rows. Confirming deletes them one by one and reports each row's result with a total. A failed row never aborts the batch, and only rows actually deleted leave the selection. Limit: 200 sessions per request.

## Retracting a message

The clicked message and everything after it leave the model context, and the transcript hides those rows. Every retraction asks for confirmation first and states how many conversation items leave the context.

- **User message**: retract and edit-again icons in the message's own action row.
- **Assistant message**: a retract icon in the finalized message's action strip.
- **A retracted prompt is restored**: its text is written into the composer, replacing the draft there. Nothing is sent automatically.
- **Edit again** opens an editor over the bubble without retracting; "Replace and send" then retracts the range and submits the new text. The range is bounded by `untilSeq`, so messages arriving during editing are not swept up.

Underneath, the Host appends one surface replacement covering the clicked message and every message after it, with an empty body that adapters drop. Stored records are untouched — a replay yields the shortened conversation. **The model context no longer contains the retracted range; the interface hides the corresponding rows.**

Refused for: work in progress (`session-active`), a session not open in the Host (`session-not-live`), a message already shadowed (`message-retracted`).

Not a physical delete: the log keeps every record, so reading or exporting it still shows the retracted content. Hide rules are rebuilt from the log on reload.

## Configuration

All fields are optional. A profile's `cordis.patch.yml` overrides them by row id:

```yaml
- id: desktop-pro
  config:
    allowLiveSessionDelete: false
```

| Field | Default | Meaning |
| --- | --- | --- |
| `allowLiveSessionDelete` | `true` | Allow deleting a session whose agent is still live. On by default because the Host keeps an agent for every session it has opened, so refusing them would block deletion until a restart. |

## Known limitations

- **A deleted row can come back until DSH restarts.** The agent outlives the log, so the row may reappear empty on the next list refresh.
- **A retraction is not a deletion**, and **a restored prompt is text only** — attachments and images are not brought back.
- **Controls are anchored to client row attributes.** If a future DSH renames them, the model context is still retracted but the rows may stay visible.
- **Replace-and-send depends on the composer.** A composer missing `setDraft` or `submit` gets the retraction refused before anything is retracted.
- **There is no UI to undo a retraction.** Recovering the original conversation means opening a branch or reading the log.

## Troubleshooting

**Retract / edit icons never appear** — check `placement` in `client.reports` at `/desktop-pro/info`: `action-row` means they were mounted into the shipped row, `own-row` means the fallback above the bubble.

**A session will not load after a restart**, reporting `system/message does not match an open turn and step` — an early build wrote a replacement row outside an open turn. Quit DSH completely, then run `tools/repair-retraction-rows.cmd` (lists only), then `tools/repair-retraction-rows.cmd --apply`, which asks for a typed `YES`, rewrites only the affected sessions and keeps a timestamped `.bak-<time>` beside each log. For one session: `node tools/repair-retraction-rows.mjs --session <id> --apply`.

**A retraction is refused with `session-not-live`** — the session is not open in the Host. Send one message in it first.

## License

MIT.
