@kangyishuai/dsh-session-delete 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  > Real session deletion for DeepSeek Harness: trash by default, a plan before you delete, an audit log, and a receipt for whatever is left behind.
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-session-delete?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-session-delete) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.2-4b6bfb)](#compatibility--degradation) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-session-delete?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-session-delete) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.5-4b6bfb)](#compatibility--degradation) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6
6
 
7
7
  [中文](./README.zh-CN.md)
8
8
 
9
9
  Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/deepseek-harness). Not affiliated with DeepSeek.
10
10
 
11
- > **Status: early.** Verified on the current target DSH version with `pnpm smoke:session-delete` (32 end-to-end assertions on a throwaway DSH home) and `pnpm probe:runtime`; the desktop read-only pass was done on an earlier version. The [Compatibility](#compatibility--degradation) table records exactly what was run. `pnpm gate session-delete` runs the whole release gate in one command. Treat it as young software and keep backups of anything you cannot lose.
11
+ > **Status: early.** Verified on the current target DSH version with `pnpm smoke:session-delete` (33 end-to-end assertions on a throwaway DSH home) and `pnpm probe:runtime`; the desktop read-only pass was done on an earlier version. The [Compatibility](#compatibility--degradation) table records exactly what was run. `pnpm gate session-delete` runs the whole release gate in one command. Treat it as young software and keep backups of anything you cannot lose.
12
12
 
13
13
 
14
14
  ![Delete confirmation: one line of impact, an opt-in cascade checkbox, and a Details disclosure](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/overview.png)
@@ -63,6 +63,8 @@ Restart the DSH desktop app afterwards. A fresh install adds a host half, so rel
63
63
 
64
64
  **Refresh**: the trash panel has no refresh button. It loads on open and re-syncs every 5 seconds, when the window becomes visible again, and after every restore or permanent delete.
65
65
 
66
+ **The view follows the session.** Deleting the session you are currently reading switches you to the next available session (or to a new-session page in the same workspace) and leaves a toast that says it went to the trash and can be restored from there — instead of leaving you on a deleted session with a disabled composer. Restoring a session (single entry or the undo toast) closes the panel, re-binds the main view to that session and opens it, even if you were reading a different one; a batch restore only refreshes the list and does not jump between sessions. If a DSH build does not expose the client navigation service, the plugin degrades to a list/projection refresh — you may still need to switch sessions by hand.
67
+
66
68
 
67
69
  Everything starts from a session row in the sidebar:
68
70
 
@@ -79,24 +81,27 @@ Everything starts from a session row in the sidebar:
79
81
  - **purge** it permanently;
80
82
  - read the audit log.
81
83
 
82
- **Health check**: the trash panel has a third tab. It reconciles the session store against the workspace bookkeeping and reports dangling references (archived/pinned ghosts, workspace membership, orphan session dirs, broken trash entries, unfinished operations). Cleaning removes **bookkeeping only** — session files are never touched.
84
+ **Health check**: Settings → Session trash → Maintenance. It is **user-triggered** — opening the settings section no longer scans your library — and the last result is cached for the rest of the page session. The check reconciles the session store against the workspace bookkeeping and reports dangling references (archived/pinned ghosts, workspace membership, orphan session dirs, broken trash entries, unfinished operations that startup reconciliation could not settle). Cleaning removes **bookkeeping only** — session files are never touched.
83
85
 
84
86
  ## Side effects & risks
85
87
 
86
88
  Files and directories it touches:
87
89
 
88
- | Path | Access | What happens |
89
- | ---------------------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
- | `~/.dsh/sessions/<workspace>/<session>/` | read + move | Located through the host's persistence seam (`stat` / `locate`); the log filename is never hardcoded. On delete the whole session directory is moved into the trash, on restore it is moved back. Same-volume moves are a rename; across volumes it falls back to copy + verify + delete. |
91
- | `~/.dsh/storages/workspace.json` | through host API only | Archived / pinned sets and workspace membership change via `workspaceRegistry` methods (archive, unarchive, pin, unpin, detachSession). The file is never edited by hand. |
92
- | `~/.dsh/storages/session_projcache/` | through host API, file fallback | Projection-cache entries for the session are cleared so a deleted session can't resurface in search. Direct file access happens only in the "internal" capability tier. |
93
- | `~/.dsh/session-trash/` | create + write | One entry per deleted session (with a `meta.json`), `audit.log` (JSONL, one line per operation) and `journal/` (two-phase-commit records so an interrupted operation can be finished or rolled back on the next start). |
90
+ | Path | Access | What happens |
91
+ | ---------------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
92
+ | `~/.dsh/sessions/<workspace>/<session>/` | read + move | Located through the host's persistence seam (`stat` / `locate`); the log filename is never hardcoded. On delete the whole session directory is moved into the trash, on restore it is moved back. Same-volume moves are a rename; across volumes it falls back to copy + verify + delete. |
93
+ | `~/.dsh/storages/workspace.json` | through host API only | Archived / pinned sets and workspace membership change via `workspaceRegistry` methods (archive, unarchive, pin, unpin, detachSession). The file is never edited by hand. |
94
+ | `~/.dsh/storages/session_projcache/` | through host API, file fallback | Projection-cache entries for the session are cleared so a deleted session can't resurface in search. Direct file access happens only in the "internal" capability tier. |
95
+ | `~/.dsh/session-trash/` | create + write | One entry per deleted session (with a `meta.json`), `audit.log` (JSONL, one line per operation) and `journal/` (two-phase-commit records; on the next start every unfinished record is compared against what is actually on disk and the operation is either completed or rolled back, with `recover` lines in the audit log). |
94
96
 
95
97
  - **No network access, no telemetry.**
96
98
  - **macOS window drag.** The self-drawn confirmation fallback declares `data-window-drag-exclude`, so the mask cannot drag the window when it covers the title bar.
97
99
  - **Restorable by default.** Delete moves files; it does not erase them.
98
100
  - **Purge is irreversible.** "Purge" (and emptying the trash) really deletes the bytes. There is no undo toast and no recovery.
99
- - **Restore is not a full undo.** The log and workspace membership come back; the pin and archive flags do not. DSH clears a pin when it archives a session and doesn't restore it when it unarchives.
101
+ - **Interrupted operations are reconciled on the next start.** Every destructive step writes a journal `intent` first; startup compares it with the disk and either finishes the bookkeeping or rolls the archive gate back. States that cannot be explained from disk are left untouched and reported for manual review — never guessed.
102
+ - **Partial results are reported, not rounded up.** If a session reached the trash but reference clean-up failed, the UI says so and the receipt is marked `partial`. A restore that brought the session back but could not restore every reference/workspace/pin is reported the same way, with per-reference results and post-restore checks in the receipt. Failed references are named one by one with the next action (for example "未挂回工作区:ws1;可在会话右键菜单「归属到项目…」里手动挂回"), the audit log records the same list, the receipt expands to show every reference and check in the settings section, and the failed references are retried once automatically on restore — with a **Retry the failed references** button for a second attempt.
103
+ - **Re-checking a restore replays the delete-time snapshot.** "Retry the failed references" re-attaches workspace membership, re-applies the pin and unarchives according to the snapshot stored in the receipt. It refuses to run when that snapshot is missing (receipt written by an older plugin version) or when the session directory is gone, instead of reporting a false "everything recovered".
104
+ - **Restore is not a full undo.** The log, workspace membership and the pin come back. Commands that need the host's workspace service are skipped, not faked, when a DSH build does not provide it — a skipped reference is reported as skipped, never as a failure. If sending a prompt right after a restore is rejected with `session/agent-busy`, the host still marks that session busy: restart DSH or continue in a new session (the plugin never kills host processes). The pin state is captured **before** the archive step — DSH clears a pin when it archives a session — stored in the trash entry and re-applied on restore. The archive flag does not come back: the plugin unarchives as the deletion gate and does not re-archive.
100
105
  - **Archiving can remove a clean git worktree (DSH 0.2.2-rc.2 and later).** Moving a session to the trash archives it. Newer DSH releases record the worktrees a session created and may run `git worktree remove` on a clean one when its owning session is archived: branches and commits stay, ignored files do not. If a checkout must survive, `git worktree lock <path>` it or turn on the worktree row's `retainOnArchive` setting before deleting the session.
101
106
  - **Uninstalling the plugin does not empty the trash.** `~/.dsh/session-trash/` is your recovery path and stays until you delete it yourself.
102
107
  - **Data root.** Resolved as plugin config `dataRoot` → `DSH_HOME` → `~/.dsh`. If your DSH keeps its data somewhere else, point the plugin at it. If the root doesn't look like a DSH data directory, the plugin refuses instead of guessing.
@@ -122,26 +127,29 @@ Capability grades:
122
127
  - `minimal` — the host has no `workspaceRegistry` (for example the headless composition). Deletion works; the archive gate, pin/workspace bookkeeping and projection-cache steps are skipped and listed in the receipt.
123
128
  - `unknown` — the persistence seam itself is missing: **read-only mode**. Plan, audit and trash listing keep working; delete/restore/purge are disabled.
124
129
 
125
- | Plugin | Verified on DSH | Notes |
126
- | ------ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
127
- | 0.4.9 | **0.2.2-rc.2** (desktop) | Trash-count badge foreground now uses a paired token: the dark theme's `state-error` is a light red (`#f25a5a`), so hardcoded white sat at 3.29:1 while `label-primary-foreground` gives 5.75:1 (still 4.5:1 in the light theme). Adds `test/client.test.js`, which asserts every theme token really exists and that the badge fill and foreground stay paired. Desktop read-only regression 14/14, unit tests 53. |
128
- | 0.4.8 | **0.2.2-rc.2** (desktop) | macOS window-drag fix: the self-drawn dialog fallback mask declares `data-window-drag-exclude`. Desktop read-only regression on the published build: 14/14; runtime probe 67/67. |
129
- | 0.4.7 | **0.2.2-rc.2** (throwaway home) | `pnpm smoke:session-delete`: 24/24 on a throwaway DSH home, after fixing the smoke's row selection (it had counted the unsaved “new chat” row as a session — see [runtime 0.2.2-rc.2 §7](../../docs/runtime/0.2.2-rc.2.md)). Desktop read-only regression on the installed 0.4.6 (same code except one Biome template literal): 14/14. |
130
- | 0.4.2 | **0.2.2-rc.1** (desktop) | `pnpm smoke:session-delete`: 24 assertions green; plugin active with no bundle error on the same host version. |
131
- | 0.4.2 | 0.2.1-rc.5 (desktop) | `pnpm smoke:session-delete`: 24 assertions green; manual GUI pass on the same host version. |
130
+ | Plugin | Verified on DSH | Notes |
131
+ | ------ | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132
+ | 0.5.0 | **0.2.2-rc.5** (desktop) | No code change needed for this DSH build. Verified: 86 unit tests + `pnpm probe:runtime` 72/72 + web `pnpm smoke:session-delete` **33/33** (throwaway DSH home) + desktop read-only regression **16 PASS + 2 SKIP** — with an empty recycle bin the two list-only assertions are data-dependent SKIPs (see [runtime rc.5 §6.1](../../docs/runtime/0.2.2-rc.5.md#61-session-delete-桌面回归空回收站会假红)). |
133
+ | 0.5.0 | **0.2.2-rc.3** (desktop) | No code change needed for this DSH build. Verified: 86 unit tests + `pnpm probe:runtime` 72/72 + web `pnpm smoke:session-delete` **33/33** (throwaway DSH home) + desktop read-only regression **18/18**. |
134
+ | 0.5.0 | **0.2.2-rc.2** (desktop) | UI rebuild: the confirmation dialog opens with focus on **Move to trash** (Enter deletes), the child-session choice is remembered, the trash panel became a single page with audit/health/receipts moved to Settings, and batch permanent deletion runs in chunks of 20. The session menu now uses the official `contextMenus` contribution with `⌘⌥⌫`, and the workspace menu gained **Delete all sessions in this workspace**. Release gate green on all four stages (verify / runtime probe 72 / web smoke 33 / desktop read-only 18), and the desktop pass was re-run against the **published 0.5.0 artifact**: 18/18. |
135
+ | 0.4.9 | **0.2.2-rc.2** (desktop) | Trash-count badge foreground now uses a paired token: the dark theme's `state-error` is a light red (`#f25a5a`), so hardcoded white sat at 3.29:1 while `label-primary-foreground` gives 5.75:1 (still 4.5:1 in the light theme). Adds `test/client.test.js`, which asserts every theme token really exists and that the badge fill and foreground stay paired. Desktop read-only regression 14/14, unit tests 53. |
136
+ | 0.4.8 | **0.2.2-rc.2** (desktop) | macOS window-drag fix: the self-drawn dialog fallback mask declares `data-window-drag-exclude`. Desktop read-only regression on the published build: 14/14; runtime probe 67/67. |
137
+ | 0.4.7 | **0.2.2-rc.2** (throwaway home) | `pnpm smoke:session-delete`: 24/24 on a throwaway DSH home, after fixing the smoke's row selection (it had counted the unsaved “new chat” row as a session — see [runtime 0.2.2-rc.2 §7](../../docs/runtime/0.2.2-rc.2.md)). Desktop read-only regression on the installed 0.4.6 (same code except one Biome template literal): 14/14. |
138
+ | 0.4.2 | **0.2.2-rc.1** (desktop) | `pnpm smoke:session-delete`: 24 assertions green; plugin active with no bundle error on the same host version. |
139
+ | 0.4.2 | 0.2.1-rc.5 (desktop) | `pnpm smoke:session-delete`: 24 assertions green; manual GUI pass on the same host version. |
132
140
 
133
141
  After a DSH upgrade: restart, then open the plugin status (settings → plugins). If it reports read-only mode, the host API changed — upgrade the plugin or report the version pair; don't force it.
134
142
 
135
143
  ## Troubleshooting
136
144
 
137
- | Symptom | Likely cause | What to do |
138
- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
139
- | No 「删除会话…」 in the session menu | The client half didn't load: plugin inactive, or the menu slot was renamed | Check the plugin status, make sure the plugin is enabled, restart the app after installing |
140
- | The menu item is there, clicking it reports read-only mode | The L2 probe can't find a host capability it needs (a DSH update changed an API) | Upgrade the plugin; if it stays read-only, open an issue with the status output and your DSH version |
141
- | Delete succeeded but the row stays in the sidebar | The client-side removal channel changed | Refresh the page; if the row survives, open an issue with your DSH version |
142
- | A restored session lost its pin or archive flag | DSH clears pin when archiving and doesn't restore it when unarchiving | Expected for now; retry from the trash, and file an issue if the log itself didn't come back |
143
- | Purge left something behind | Residue that the post-delete receipt lists | Read the receipt and the audit log, clean the listed path by hand, and open an issue with the receipt |
144
- | The trash panel is empty after a delete | The plugin resolved a different data root than your DSH (`DSH_HOME` / config) | Look at `~/.dsh/session-trash/` on disk and check the plugin's `dataRoot` config |
145
+ | Symptom | Likely cause | What to do |
146
+ | ---------------------------------------------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
147
+ | No 「删除会话…」 in the session menu | The client half didn't load: plugin inactive, or the menu slot was renamed | Check the plugin status, make sure the plugin is enabled, restart the app after installing |
148
+ | The menu item is there, clicking it reports read-only mode | The L2 probe can't find a host capability it needs (a DSH update changed an API) | Upgrade the plugin; if it stays read-only, open an issue with the status output and your DSH version |
149
+ | Delete succeeded but the row stays in the sidebar | The client-side removal channel changed | Refresh the page; if the row survives, open an issue with your DSH version |
150
+ | A restored session lost its archive flag | DSH clears the pin when archiving; the plugin restores the pin but not the archive flag | Expected; file an issue if the log or workspace membership itself didn't come back |
151
+ | Purge left something behind | Residue that the post-delete receipt lists | Read the receipt and the audit log, clean the listed path by hand, and open an issue with the receipt |
152
+ | The trash panel is empty after a delete | The plugin resolved a different data root than your DSH (`DSH_HOME` / config) | Look at `~/.dsh/session-trash/` on disk and check the plugin's `dataRoot` config |
145
153
 
146
154
  ## License
147
155
 
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 真正的删除会话:默认进回收站、删前先预演、留审计日志,删完给你一份残留回执。
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-session-delete?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-session-delete) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.2-4b6bfb)](#兼容性与降级) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-session-delete?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-session-delete) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.5-4b6bfb)](#兼容性与降级) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6
6
 
7
7
  [English](./README.md)
8
8
 
@@ -63,6 +63,8 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
63
63
 
64
64
  **刷新**:回收站面板没有刷新按钮——打开时自动加载,之后每 5 秒、窗口重新可见、以及每次恢复/彻底删除后自动同步。
65
65
 
66
+ **视图跟着会话走。** 删掉当前正在看的会话时,界面会自动切到下一个可用会话(没有就回同一工作区的新会话页),并留一条「已移入回收站,可在回收站恢复」的提示——不会把你留在已删除的会话上对着「会话不可用」。恢复会话(面板单条恢复或 toast「撤销」)会关闭面板、把主视图重新绑定到该会话并打开它——即使你当时正在看别的会话;批量恢复只刷新列表、不会在多个会话间来回跳。若某个 DSH 版本不提供客户端导航服务,插件降级为刷新列表/投影,此时可能仍需手动切换会话。
67
+
66
68
 
67
69
  入口都在侧栏的会话行上:
68
70
 
@@ -79,24 +81,27 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
79
81
  - **彻底删除**(不可恢复);
80
82
  - 查看审计日志。
81
83
 
82
- **体检**:回收站面板有第三个页签。它把会话存储与工作区记账对账,列出失效引用(归档/置顶幽灵、工作区记账、孤儿会话目录、损坏的回收站条目、未完成操作)。清理**只动登记表**,绝不删会话文件。
84
+ **体检**:设置 → 会话回收站 → 维护。它是**手动动作**——打开设置页不再扫全库——本次页面会话内会复用上次结论。体检查把会话存储与工作区记账对账,列出失效引用(归档/置顶幽灵、工作区记账、孤儿会话目录、损坏的回收站条目、启动对账没能自动处理的未完成操作)。清理**只动登记表**,绝不删会话文件。
83
85
 
84
86
  ## 副作用与风险
85
87
 
86
88
  会读写这些路径:
87
89
 
88
- | 路径 | 操作 | 说明 |
89
- | ------------------------------------ | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
- | `~/.dsh/sessions/<工作区>/<会话>/` | 读 + 移动 | 通过宿主的持久化 seam(`stat` / `locate`)定位,不写死日志文件名。删除时整个会话目录移进回收站,恢复时移回来。同卷是 rename,跨卷退化为复制 + 校验 + 删除。 |
91
- | `~/.dsh/storages/workspace.json` | 只经宿主 API | 归档 / 置顶集合与工作区归属通过 `workspaceRegistry` 的方法(archive、unarchive、pin、unpin、detachSession)改动,插件不会手改这个文件。 |
92
- | `~/.dsh/storages/session_projcache/` | 优先宿主 API,兜底读文件 | 清掉该会话的投影缓存,避免删掉的会话在搜索里冒出来。只有能力探测落在 internal 档时才直接碰文件。 |
93
- | `~/.dsh/session-trash/` | 创建 + 写入 | 每条被删会话一个条目(带 `meta.json`),另有 `audit.log`(JSONL,一次操作一行)和 `journal/`(两阶段提交记录,用于下次启动时把中断的操作补完或回滚)。 |
90
+ | 路径 | 操作 | 说明 |
91
+ | ------------------------------------ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
92
+ | `~/.dsh/sessions/<工作区>/<会话>/` | 读 + 移动 | 通过宿主的持久化 seam(`stat` / `locate`)定位,不写死日志文件名。删除时整个会话目录移进回收站,恢复时移回来。同卷是 rename,跨卷退化为复制 + 校验 + 删除。 |
93
+ | `~/.dsh/storages/workspace.json` | 只经宿主 API | 归档 / 置顶集合与工作区归属通过 `workspaceRegistry` 的方法(archive、unarchive、pin、unpin、detachSession)改动,插件不会手改这个文件。 |
94
+ | `~/.dsh/storages/session_projcache/` | 优先宿主 API,兜底读文件 | 清掉该会话的投影缓存,避免删掉的会话在搜索里冒出来。只有能力探测落在 internal 档时才直接碰文件。 |
95
+ | `~/.dsh/session-trash/` | 创建 + 写入 | 每条被删会话一个条目(带 `meta.json`),另有 `audit.log`(JSONL,一次操作一行)和 `journal/`(两阶段提交记录:下次启动时按磁盘事实把每条未完成记录补完或回滚,并在审计里留 `recover` 行)。 |
94
96
 
95
97
  - **不联网、不上报。**
96
98
  - **macOS 窗口拖动。** 自绘确认框 fallback 的遮罩声明了 `data-window-drag-exclude`,覆盖页头时拖动不会拖走窗口。
97
99
  - **默认可恢复。** 删除是把文件移走,不是抹掉。
98
100
  - **彻底删除不可恢复。** 「彻底删除」以及清空回收站是真的删字节,没有撤销 toast,也找不回来。
99
- - **恢复不等于完整撤销。** 日志和工作区归属会回来,置顶与归档标记不会:DSH 归档时会顺手清掉 pin,取消归档时不会恢复。
101
+ - **中断的操作会在下次启动时对账。** 每个破坏性步骤先写 journal `intent`;启动时按磁盘事实补完收尾或回滚归档闸门。两边都在、两边都不在这类解释不了的现场**一律不动**,保留为「需人工核对」——绝不猜。
102
+ - **部分成功会如实说出来。** 会话已进回收站但引用清理失败时,界面按事实提示、回执标 `partial`;恢复把会话搬回来但引用/工作区/置顶没全还原时同样如此,回执里有逐项引用结果与恢复后校验。失败项会**逐条点名并给出下一步动作**(例如「未挂回工作区:ws1;可在会话右键菜单「归属到项目…」里手动挂回」),审计日志写同一份清单,设置页的回执可展开逐项查看;恢复时会先自动重试一次失败的引用,界面另有「重试未通过的引用」按钮可再试。
103
+ - **重检会按「删除前的快照」重放。** 「重试未通过的引用」按回执里的快照重新挂回工作区、写回置顶、解除归档;当回执缺少快照(旧版本写的)或会话目录已不存在时它会拒绝,而不是报一个假的「全部恢复」。
104
+ - **恢复不等于完整撤销。** 日志、工作区归属和置顶会回来:置顶状态在**归档步骤之前**取(DSH 归档时会清 pin),记在回收站条目里并在恢复时写回。归档标记不会——插件把取消归档当作删除闸门的收尾,但不会重新归档。宿主不提供的工作区接口一律记为「跳过」而不是「失败」,不会伪造成功;如果恢复后发送被拒并提示 `session/agent-busy`,说明宿主仍把这个会话标记为忙碌,重启 DSH 或新建会话继续即可(插件不会去杀宿主进程)。
100
105
  - **归档可能清理干净的工作树(DSH 0.2.2-rc.2 起)。** 「移入回收站」本质是归档会话:新版本 DSH 会记录会话创建的工作树,并在归档时对满足条件(没有未归档会话引用、Git 干净、不是分离 HEAD 等)的目录执行 `git worktree remove`。分支和提交保留,被忽略的文件(如 `node_modules`)不会保留。要保住检出目录,删除前用 `git worktree lock <path>`,或在 Forge 套件的 worktree 行打开 `retainOnArchive`。
101
106
  - **卸载插件不会清空回收站。** `~/.dsh/session-trash/` 是你的恢复通道,会一直留着,除非你自己删。
102
107
  - **数据根目录。** 按「插件配置 `dataRoot` → 环境变量 `DSH_HOME` → `~/.dsh`」的顺序解析。如果你的 DSH 把数据放在别处,要把插件指过去;根目录不像 DSH 数据目录时,插件会拒绝执行而不是瞎猜。
@@ -122,13 +127,16 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
122
127
  - `minimal` —— 宿主没有 `workspaceRegistry`(例如 headless 组合)。删除照常进行;归档闸门、置顶/工作区记账、投影缓存这些步骤被跳过并写进回执。
123
128
  - `unknown` —— 持久化本体缺失:**只读模式**。plan、审计、回收站列表还能用;删除、恢复、彻底删除被禁用。
124
129
 
125
- | 插件版本 | 已验证的 DSH 版本 | 说明 |
126
- | -------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
127
- | 0.4.9 | **0.2.2-rc.2**(桌面版) | 回收站计数徽章的前景色改用配对 token:深色主题下 `state-error` 是浅红 `#f25a5a`,原先配写死白只有 3.29:1,配 `label-primary-foreground` 是 5.75:1(浅色仍 4.5:1)。新增 `test/client.test.js` 守住「token 必须真实存在 + 底色/前景成对」。桌面只读回归 14/14,单测 53。 |
128
- | 0.4.8 | **0.2.2-rc.2**(桌面版) | macOS 窗口拖动修复:自绘确认框 fallback 的遮罩声明 `data-window-drag-exclude`。桌面只读回归在发布版上复跑 14/14,宿主探针 67/67。 |
129
- | 0.4.7 | **0.2.2-rc.2**(临时 DSH home) | `pnpm smoke:session-delete` 24/24(临时 DSH home);此前 23/24 是冒烟把「新会话」临时行当成会话计数,修好行选择与按 ID 断言后全绿(见 [runtime 0.2.2-rc.2 §7](../../docs/runtime/0.2.2-rc.2.md))。桌面只读回归跑在已装的 0.4.6 上(与 0.4.7 只差一处 Biome 模板字符串):14/14。 |
130
- | 0.4.2 | **0.2.2-rc.1**(桌面版) | `pnpm smoke:session-delete` 24 项断言全绿,并确认同一版本桌面版里插件正常激活、没有 bundle 错误。 |
131
- | 0.4.2 | 0.2.1-rc.5(桌面版) | `pnpm smoke:session-delete` 24 项断言全绿,并在同一版本桌面版做过人工 GUI 验收。 |
130
+ | 插件版本 | 已验证的 DSH 版本 | 说明 |
131
+ | -------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132
+ | 0.5.0 | **0.2.2-rc.5**(桌面版) | 这一版 DSH 不需要改代码。已验证:86 项单测 + `pnpm probe:runtime` 72/72 + web `pnpm smoke:session-delete` **33/33**(临时 DSH home)+ 桌面只读回归 **16 PASS + 2 SKIP**——回收站为空时「保留全选与批量操作」「条目布局」两条数据相关断言记 SKIP(见 [runtime rc.5 §6.1](../../docs/runtime/0.2.2-rc.5.md#61-session-delete-桌面回归空回收站会假红))。 |
133
+ | 0.5.0 | **0.2.2-rc.3**(桌面版) | 这一版 DSH 不需要改代码。已验证:86 项单测 + `pnpm probe:runtime` 72/72 + web `pnpm smoke:session-delete` **33/33**(临时 DSH home)+ 桌面只读回归 **18/18**。 |
134
+ | 0.5.0 | **0.2.2-rc.2**(桌面版) | 界面重构:确认框默认焦点落在「移入回收站」(回车即执行)、记忆「同时删除子会话」、回收站单页化并把审计/体检/回执迁到设置页、批量彻底删除按 20 条分批;会话菜单走官方 `contextMenus` 并新增 `⌘⌥⌫`、工作区菜单新增「删除此工作区的全部会话」。发版门禁 4 步全绿(verify / 探针 72 项 / web 冒烟 33 项 / 桌面只读回归 18 项),桌面回归在**发布产物 0.5.0** 上复跑 18/18。 |
135
+ | 0.4.9 | **0.2.2-rc.2**(桌面版) | 回收站计数徽章的前景色改用配对 token:深色主题下 `state-error` 是浅红 `#f25a5a`,原先配写死白只有 3.29:1,配 `label-primary-foreground` 是 5.75:1(浅色仍 4.5:1)。新增 `test/client.test.js` 守住「token 必须真实存在 + 底色/前景成对」。桌面只读回归 14/14,单测 53。 |
136
+ | 0.4.8 | **0.2.2-rc.2**(桌面版) | macOS 窗口拖动修复:自绘确认框 fallback 的遮罩声明 `data-window-drag-exclude`。桌面只读回归在发布版上复跑 14/14,宿主探针 67/67。 |
137
+ | 0.4.7 | **0.2.2-rc.2**(临时 DSH home) | `pnpm smoke:session-delete` 24/24(临时 DSH home);此前 23/24 是冒烟把「新会话」临时行当成会话计数,修好行选择与按 ID 断言后全绿(见 [runtime 0.2.2-rc.2 §7](../../docs/runtime/0.2.2-rc.2.md))。桌面只读回归跑在已装的 0.4.6 上(与 0.4.7 只差一处 Biome 模板字符串):14/14。 |
138
+ | 0.4.2 | **0.2.2-rc.1**(桌面版) | `pnpm smoke:session-delete` 24 项断言全绿,并确认同一版本桌面版里插件正常激活、没有 bundle 错误。 |
139
+ | 0.4.2 | 0.2.1-rc.5(桌面版) | `pnpm smoke:session-delete` 24 项断言全绿,并在同一版本桌面版做过人工 GUI 验收。 |
132
140
 
133
141
  目前只在 **macOS** 上验证过。Windows 相关路径(`session.lock` 的 EBUSY/EPERM 重试、宿主在那儿用的命名信号量)代码里有,但**还没实测**。
134
142
 
@@ -141,7 +149,7 @@ DSH 升级之后:重启,然后看插件的状态条(设置 → 插件)
141
149
  | 会话菜单里没有「删除会话…」 | client 半没加载:插件未激活,或菜单 slot 改名了 | 看插件状态,确认插件已启用;装完要重启桌面版 |
142
150
  | 菜单项在,一点就提示只读模式 | L2 探测不到需要的宿主能力(DSH 升级后 API 变了) | 升级插件;升级后仍然只读,就带着状态输出和 DSH 版本提 issue |
143
151
  | 删除成功,但侧栏的行还在 | client 端的移除通道变了 | 刷新页面;刷新后还在,就带着 DSH 版本提 issue |
144
- | 恢复后置顶 / 归档标记丢了 | DSH 归档时清 pin、取消归档时不恢复 | 目前属预期行为;可以回回收站重试,日志本身没回来请提 issue |
152
+ | 恢复后归档标记丢了 | DSH 归档时清 pin;插件会还原置顶,但不还原归档标记 | 属预期行为;日志或工作区归属本身没回来请提 issue |
145
153
  | 彻底删除后还残留东西 | 删除回执里列出的残留 | 对回执和审计日志,按回执里的路径手动清理,并把回执附在 issue 里 |
146
154
  | 删完之后回收站是空的 | 插件解析到的数据根目录和你的 DSH 不是同一个(`DSH_HOME` / 配置) | 去磁盘上看 `~/.dsh/session-trash/`,再核对插件的 `dataRoot` 配置 |
147
155
 
package/lib/agent-tool.js CHANGED
@@ -10,11 +10,38 @@ const DEFAULT_TTL_MS = 120_000;
10
10
  * @param {{ plan: (sessionId: string) => Promise<any>, trash: (sessionId: string, request: any) => Promise<any> }} options.ops
11
11
  * @param {() => number} [options.now]
12
12
  * @param {number} [options.ttlMs]
13
+ * @param {(event: { action: string, sessionId?: string, code: string, operator: string }) => Promise<void> | void} [options.onRefusal]
14
+ * 拒绝钩子:宿主用来写审计(AUD-SD-04)。钩子失败不改变拒绝结论。
13
15
  */
14
- export function createAgentToolController({ ops, now = Date.now, ttlMs = DEFAULT_TTL_MS }) {
16
+ export function createAgentToolController({
17
+ ops,
18
+ now = Date.now,
19
+ ttlMs = DEFAULT_TTL_MS,
20
+ onRefusal,
21
+ }) {
15
22
  /** @type {Map<string, { sessionId: string, digest: string, cascade: boolean, expiresAt: number }>} */
16
23
  const tokens = new Map();
17
24
 
25
+ /**
26
+ * 记录一次拒绝。模型工具的所有 return {ok:false} 都要经过这里。
27
+ * @param {string} action
28
+ * @param {unknown} sessionId
29
+ * @param {string} code
30
+ */
31
+ async function refuse(action, sessionId, code) {
32
+ if (typeof onRefusal !== "function") return;
33
+ try {
34
+ await onRefusal({
35
+ action,
36
+ sessionId: typeof sessionId === "string" && sessionId.length > 0 ? sessionId : undefined,
37
+ code,
38
+ operator: "agent",
39
+ });
40
+ } catch {
41
+ // 审计写入失败不改变「这次调用被拒绝」的结论;宿主侧另有 logger 告警。
42
+ }
43
+ }
44
+
18
45
  /** @param {string} token */
19
46
  function takeToken(token) {
20
47
  const entry = tokens.get(token);
@@ -31,6 +58,7 @@ export function createAgentToolController({ ops, now = Date.now, ttlMs = DEFAULT
31
58
  async function plan(args) {
32
59
  const plan = await ops.plan(args.sessionId);
33
60
  if (plan.blockers.length > 0) {
61
+ await refuse("plan", plan.sessionId, "blocked");
34
62
  return {
35
63
  ok: false,
36
64
  code: "blocked",
@@ -75,34 +103,42 @@ export function createAgentToolController({ ops, now = Date.now, ttlMs = DEFAULT
75
103
  */
76
104
  async function remove(args) {
77
105
  if (args.callerSessionId && args.callerSessionId === args.sessionId) {
106
+ await refuse("trash", args.sessionId, "caller-session");
78
107
  return {
79
108
  ok: false,
80
109
  code: "caller-session",
81
110
  message: "refusing to delete the session that is calling this tool",
82
111
  };
83
112
  }
84
- if (!args.token)
113
+ if (!args.token) {
114
+ await refuse("trash", args.sessionId, "token-required");
85
115
  return {
86
116
  ok: false,
87
117
  code: "token-required",
88
118
  message: "call action=plan first to obtain a token",
89
119
  };
120
+ }
90
121
  const taken = takeToken(args.token);
91
- if (taken.error)
122
+ if (taken.error) {
123
+ await refuse("trash", args.sessionId, taken.error);
92
124
  return {
93
125
  ok: false,
94
126
  code: taken.error,
95
127
  message: "token is invalid or expired; run action=plan again",
96
128
  };
129
+ }
97
130
  const entry = /** @type {any} */ (taken.entry);
98
131
  if (entry.sessionId !== args.sessionId) {
132
+ await refuse("trash", args.sessionId, "token-mismatch");
99
133
  return { ok: false, code: "token-mismatch", message: "token was issued for another session" };
100
134
  }
101
135
  const plan = await ops.plan(args.sessionId);
102
136
  if (plan.blockers.length > 0) {
137
+ await refuse("trash", args.sessionId, "blocked");
103
138
  return { ok: false, code: "blocked", blockers: plan.blockers };
104
139
  }
105
140
  if (plan.digest !== entry.digest) {
141
+ await refuse("trash", args.sessionId, "stale-plan");
106
142
  return {
107
143
  ok: false,
108
144
  code: "stale-plan",
package/lib/audit.js CHANGED
@@ -10,7 +10,7 @@ const MAX_LINE = 4096;
10
10
 
11
11
  /**
12
12
  * @typedef {object} AuditEntry
13
- * @property {"plan" | "trash" | "restore" | "purge" | "reconcile" | "health"} action
13
+ * @property {"plan" | "trash" | "restore" | "purge" | "reconcile" | "health" | "recover"} action
14
14
  * @property {"ok" | "refused" | "failed"} result
15
15
  * @property {string} [sessionId]
16
16
  * @property {string} [entryId]