Saltar al contenido principal
O

dsh-turn-recycle

op-singularity/dsh-turn-recycle

Delete a single Q&A turn from a DeepSeek Harness session into a restorable recycle bin, and restore it at its original turn; physical archive rewrite is opt-in and verified.

Instalar

dsh plugin --profile web add github:op-singularity/dsh-turn-recycle

README

dsh-turn-recycle

CI

Delete a single Q&A turn from a DeepSeek Harness conversation — and get it back if you change your mind.

A 🗑 appears next to the native copy button on every reply. Delete one turn, or that turn and everything after it: it leaves the view immediately and is recorded in a workspace recycle bin. ♻ restores it at its original Host turn. The archive is never rewritten while DSH has the session open; physical rewrite is opt-in, always backed up, and verified against the Host's own invariants before the swap.

No service. No API key. No cloud. Plain JS inside the harness process (so Windows Smart App Control, which blocks unsigned helper binaries, is not an issue).

It also ships a small cross-conversation memory index — a MEMORY.md injected once per session, plus on-demand search over past sessions — for about 400 tokens per session. That half is described under Also included: memory.

What it does

🗑 in-chat deleteA button in the message's own action row, right after the native copy button. Deletes one Q&A turn (or, with the dialog checkbox, that turn and every later turn).
♻ recycle binBottom-right panel listing deleted turns for the current session; restore puts the turn back at its original Host turn.
session_recycleSame delete from the agent side: { turns: "7" } or { from: "7" } for a truncate. Hide + queue by default.
recycle_list / recycle_restoreList the recycle bin and restore a record at its original position.
session_pending / session_apply_pendingInspect the queue; apply it explicitly to a closed, idle session.
session_hideNon-destructive hide — affects only this plugin's views; the archive is untouched.
Auto-injectAt the first step of every session, injects MEMORY.md from the workspace (once per session, and again only if the file changed). Capped at 3000 chars.
memory_read / memory_appendRead MEMORY.md (hot index) or MEMORY-details.md (long-form notes); append a timestamped line to either.
session_list / session_search / session_read / session_turns / session_showSearch and read past sessions on request (hidden turns skipped), with hard caps.

In-chat delete (Web UI)

The plugin appends the 🗑 button into the message's own action row, immediately after the native copy button.

It does not guess by message text. DSH already renders, on every flow item, data-chat-turn (the Host's own turn number), and data-conversation-session on the conversation root. The button reads those two attributes:

  • the right session, even after switching conversations;
  • the right turn, even when two questions have identical text;
  • no dependency on /current, no global "latest session" guess.

🗑 opens a confirm dialog with an optional checkbox:

  • default — delete just this Q&A;
  • checked — also delete every later turn (truncate, like 千问). The server expands "later" from the archive, not only from what the DOM has loaded.

What happens now: the turn leaves the view immediately and the content goes to .session-recycle/. The physical archive is never rewritten while the Host is using it, and nothing auto-rewrites by default. The queue is applied only when you explicitly run session_apply_pending / tools/apply-pending, or — if you opt in by creating .session-rewrite-enabled in the workspace (or setting DSH_MEMORY_AUTO_REWRITE=1) — when the session is disposed. It is never applied at DSH startup: the Host auto-opens the last conversation immediately, and a startup rewrite races with it.

Until the queue is applied and the session is reopened, DSH's own model context for that open session still contains the deleted turn. New sessions never see it; after the explicit apply + reopen it is gone from context too.

Restore

The ♻ button at the bottom-right lists the recycle records for the current session. Restore:

  • if the physical delete has not run yet, the queued delete is simply cancelled and the record is removed;
  • otherwise a restore is queued and inserted at the original Host turn when the explicit apply runs (or when the session is disposed and auto-rewrite is enabled). Event sequence numbers are checked for reuse first; a tail turn whose numbers were reused by new content is refused rather than corrupting the log.

Safety model

This plugin can edit session archives, so it is built around not losing data:

  1. Deleting is restorable and hide-only by default. A UI delete records the turn into .session-recycle/*.json and hides it; this package ships no irreversible delete tool. Physical rewrite is opt-in: run session_apply_pending / tools/apply-pending, or create .session-rewrite-enabled in the workspace to allow auto-rewrite when the session is disposed. Nothing rewrites on startup.
  2. Nothing is rewritten while the Host has the conversation open. The explicit apply refuses the live session and any session still present in the Host's agents registry; the offline tool refuses while DeepSeek Harness.exe is running (and fails closed if it cannot inspect the process). /current is retired (410) because the server cannot know which UI session is open.
  3. Every rewrite is backed up and verified. A .bak-<ts> copy is made; the new file is built in a temp file and swapped in only after a strict re-decode matches the expected text and the Host's own invariants (contiguous seq, contiguous turn, one record per zstd frame, legal surface/shadowed spans). Any mismatch leaves the original untouched.
  4. No Host code is patched. The web UI layer is additive: it reads data-conversation-session / data-chat-turn and clones the native copy button. If DSH changes its DOM the worst case is that the button does not appear — the Host keeps working.
  5. Memory injection is a prompt surface. MEMORY.md is injected as a user-role message with its absolute path. Only point a workspace at notes you trust; a shared or foreign MEMORY.md is effectively user instructions to the model. Set DSH_MEMORY_NO_INJECT=1 to disable injection.
  6. DSH is a Developer Preview. This plugin's archive rewriting is reverse-engineered and verified against DSH 0.2.1-rc.5 and 0.2.2-rc.5 (session.v4). A future Host format change can break it. Back up ~/.dsh/sessions before enabling physical rewrite, and prefer the hide-only path for important sessions.

Deleting a single Q&A (tools)

session_turns lists Host turn numbers (the same numbers the UI shows), then:

session_recycle({ session: "session-…", turns: "7" })   # just turn 7
session_recycle({ session: "session-…", from: "7" })    # turn 7 and everything after it

session_pending shows the queue, session_apply_pending flushes one closed session, and recycle_list / recycle_restore bring a turn back at its original position.

The default is hide + queue. To make the physical rewrite happen you either run an explicit apply (session_apply_pending, or tools/apply-pending.mjs after quitting DSH) or create an empty .session-rewrite-enabled in the workspace to allow auto-apply on session dispose. The offline tool refuses while DSH is running and fails closed when it cannot check.

Rewriting keeps the original file untouched until a strict re-decode of the temp file equals the expected text and the turn-number sequence exactly; only then is it swapped in, with a .bak-<ts> copy. The archive is re-framed one zstd frame per turn.

What deletion cannot remove: copies of the text that later events already captured — agent/inbox/spliced context snapshots, compaction/summary condensations, and quotes inside later user messages. The turn itself is gone; the echoes stay.

Also included: memory

The memory half is deliberately small: one file in, one file out.

  • Auto-inject — at the first step of every session, MEMORY.md from the workspace is injected once (and again only if the file changed; capped at 3000 chars).
  • memory_read / memory_append — read the hot index or the long-form MEMORY-details.md; append a timestamped line.
  • session_list / session_search / session_read / session_turns / session_show — search and read past sessions on request, with hard caps.

Create MEMORY.md in the workspace root — that file is what gets injected. Typically:

# MEMORY.md — hot index
## Environment
- ...
## Active projects
- ...
## Todo
- ...
> Details live in MEMORY-details.md

Then just talk. Say "remember: ..." and the agent calls memory_append; say "what did we decide last time?" and it calls session_search.

Why it stays cheap:

  • The injected file is a hot index, not an archive: keep MEMORY.md around 1 KB (~400 tokens) and move detail into MEMORY-details.md, which is only read on demand.
  • Session history is read from the harness's own archive (~/.dsh/sessions/**/session.v4.jsonl.zstd) on request, with hard caps: 8 rows / 5 hits / 20 turns, snippets truncated.
  • Only user / assistant turns are returned; tool output and system prompts (≈95% of a stored session) are dropped.

A naively written memory plugin injects everything every turn. This one pays ~400 tokens per session and nothing else until you ask.

Install

# npm
dsh plugin --profile desktop add @opsingularity/dsh-turn-recycle

# or directly from GitHub
dsh plugin --profile desktop add github:Op-Singularity/dsh-turn-recycle#main

For a reproducible Git install, pin the commit instead of #main: github:Op-Singularity/dsh-turn-recycle#<commit-sha>.

The DSH Add plugin dialog also accepts a GitHub URL, a tarball URL, or an absolute local path. After adding, restart DSH. The 13 agent tools appear as session_*, recycle_*, and memory_*, and the in-chat 🗑 / ♻ buttons appear in the web UI.

Renamed. This plugin was previously published as @opsingularity/dsh-memory-local. That package is deprecated (not deleted) and the GitHub repository was renamed — old links redirect. The unscoped npm name dsh-memory-local belongs to an unrelated project by a different author; this plugin never published under it. Install @opsingularity/dsh-turn-recycle.

Upgrading from 2.1.x (dsh-memory-local)

The package name, plugin id, HTTP routes and state directory all changed:

2.1.x2.2.x
npm@opsingularity/dsh-memory-local@opsingularity/dsh-turn-recycle
plugin iddsh-memory-localdsh-turn-recycle
API prefix/api/dsh-memory-local/*/api/dsh-turn-recycle/*
state dir~/.dsh/dsh-memory-local/~/.dsh/dsh-turn-recycle/
  • If your profile's cordis.patch.yml has a - id: dsh-memory-local entry (including a disabled: true leftover), delete it — it now points at a plugin that no longer exists. Then add dsh-turn-recycle as above.
  • The old ~/.dsh/dsh-memory-local/ directory (cwd index, diagnostics) can be deleted; a new one is created on first run.
  • Your workspace state carries over: .session-edits.json and .session-recycle/ keep the same names and format, so queued deletes and recycle-bin records survive the rename. Pending work can still be applied with the new tools.

Compatibility

  • Tested against DeepSeek Harness 0.2.1-rc.5 (session.v4): a real 94-turn archive with compactions is read and rewritten, and the result is re-read. Deleting a turn inside a compaction span and then restoring it reproduces the original file byte for byte.
  • 0.2.2-rc.5 is checked at the layer the Host folds: foldSurface from @deepseek-ai/dsh-session@0.2.2-rc.5 accepts the original archive, the archive after the delete, and the archive after the restore. The 0.2.2 event vocabulary is identical apart from the added team/mode. No archive written by a 0.2.2 Host has been through the reader yet (the desktop app on the test machine is 0.2.1-rc.5), so 0.2.2 is "semantics checked", not "writer exercised".
  • Top-level engines.dsh is >=0.2.1-rc.5 <0.3.0-0. The Host compares it with includePrerelease, so 0.2.x rc/alpha builds pass and the bound only cuts at 0.3. The upper bound is deliberate: the archive format is undocumented and a 0.3 line may change it — -0 also excludes 0.3.0 prereleases.
  • If the running Host is outside the range, installation/profile startup do not load the plugin: the profile still opens, the plugin's row is disabled and a warning goes to stderr. The visible symptom is missing 🗑/♻ and tools, not a crash. An exact package@version exemption overrides this: dsh plugin --profile <profile> allow-version <pkg@version> --dsh-version <exact> --accept-risk (revoke with revoke-version <pkg@version> --dsh-version <exact>). Don't use it unless you accept the archive-format risk. These subcommands are not listed by dsh plugin --help (that forwards to pnpm); they were verified against the 0.2.2-rc.5 CLI, where version-exemptions returns the profile's grants as JSON.
  • Self-check: compare dsh --version with the range above, and run dsh plugin --profile desktop version-exemptions to see exemptions and warnings.
  • The Host is a Developer Preview. The reader is strict: an unknown or changed format is refused, not guessed.
  • The DOM layer depends on data-conversation-session / data-chat-turn; if the Host changes those attributes, the buttons disappear but the Host is unaffected.

Roadmap

  • Migrate the physical delete path to a Host-native surface/shadowed-span API if DSH exposes one publicly. As of 0.2.1-rc.5, the persistence seam has no per-turn delete/hide API; the internal compaction surface replacement is not a public plugin API, so the rewrite path stays opt-in and validated.

Development

  • npm test (Node's built-in test runner) runs:
    • archive-rewriter fixtures: delete a middle turn, keep seq/turn contiguous, restore to byte-identical content, refuse torn frames and seq gaps;
    • host-shaped fixtures: the real event vocabulary (tool/call, tool/result with sourceEventSeqs, step bookkeeping, surfaceOp replacements), including a delete + restore round trip;
    • a client selector contract test that loads lib/client.js in a VM and pins how data-chat-turn / data-conversation-session are parsed and how often the fallback scan runs.
  • DSH_TEST_ARCHIVE=<path-to-session.v4.jsonl.zstd> npm run test:real validates the strict reader against a real archive on your machine, read-only. CI skips it because transcript data is not checked in. Last run (2026-11-29, Host 0.2.1-rc.5): a local 94-turn archive with 40 compaction/* events passed, including validateSurface.
  • Cross-version check (2026-11-29): the same archive and rewritten copies (one turn deleted, then restored) pass foldSurface from @deepseek-ai/dsh-session 0.2.1-rc.5 and 0.2.2-rc.5. This caught a rewrite bug in 2.2.2 — tool/result replacement events carry the replaced turn in data.turn, and blanket renumbering made the Host reject the archive. 2.2.3 remaps turn references through a table, and the test suite now pins the Host's "tool/result replacement may change only message.content" rule. The restore pass also widens a compaction replacement's data.shadowedSeqs and sourceEventSeqs; the fixture test fails if that repair is disabled.
  • The client contract test covers attribute parsing and the fallback timer; MutationObserver and setTimeout are stubs there, so it is not evidence that the buttons work in a live UI.
  • The tests ship in the npm package (files includes test/), so npm test works from an installed copy as well as from a git checkout.
  • .github/workflows/ci.yml runs syntax checks, the tests, and npm pack --dry-run on Node 22 and 24.

Notes / limits

  • The archive reader decodes multi-frame zstd with the host's structural frame scanner (not a magic-byte split); the first frame must be exactly the header, every frame must end on a record, and seq / turn must be contiguous.
  • session_search reads sessions newest-first and stops at the hit cap, but it must decompress each scanned session — a large history costs a second or two.
  • Injection is per session id, keyed on size:mtimeMs, so editing MEMORY.md mid-session re-injects once.
  • A turn inside a compaction's shadowed span is handled by widening the stored shadowedSeqs / sourceEventSeqs as nodes are deleted and re-inserted (byte-identical round trip on the test archive). The rewrite still fails closed — original untouched, error in .session-edits.error.json — when that widening cannot be proven lossless (the stored list is not an in-order subsequence of the current span) or when the protected system head would be removed. Hide-only delete and restore still work then.
  • What a refused rewrite looks like to you. By default 🗑 only hides the turn and queues the work, so "nothing happened to the file yet" is normal. A refusal appears only when an apply / auto-rewrite actually runs: the turn stays hidden in this plugin's view, the archive is left untouched (so the Host still has the turn and may show it again after a restart), the operation stays queued, and the reason is in <workspace>/.session-edits.error.json. 2.2.3 added two refuse-before-swap rules (a tool/result replacement must shadow exactly one node and change only message.content; a compaction's stored shadowedSeqs must be an in-order subsequence of the current span). If you hit one, open an issue with the plugin version, Host version, and that error text — not the transcript.
  • /api/dsh-turn-recycle/current is retired (HTTP 410). The v2 client does not call it; it reads data-conversation-session / data-chat-turn from the Host's DOM. Do not use an empty /current as a diagnostic for "no current session".
  • tools/apply-pending.mjs refuses to run while DeepSeek Harness.exe is running; quit DSH first. tools/prune-backups.mjs keeps the newest two backups plus the largest one per session and is dry-run by default (--apply to delete).

License

MIT

Plugins relacionados