@kangyishuai/dsh-session-delete 0.4.9 → 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,16 +2,16 @@
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` (24 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
- ![Delete confirmation with the plan: size, sub-sessions, references to clean](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/overview.png)
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)
15
15
 
16
16
  ## What it does
17
17
 
@@ -20,16 +20,18 @@ DSH's built-in _archive_ only hides a session: the id goes into the workspace's
20
20
  - **Real deletion.** The session directory is moved out of `~/.dsh/sessions/`, and the bookkeeping that still points at it (archived set, pinned set, workspace membership, projection cache) is cleaned up — so the session doesn't come back and doesn't leave a ghost entry behind.
21
21
  - **Trash by default.** The first click erases nothing: the session goes to `~/.dsh/session-trash/` and can be restored. Permanent deletion is a separate, explicit action.
22
22
  - **Plan before you delete (dry-run).** The confirmation dialog is generated from a plan: on-disk size, whether the session is live, how many sub-sessions it has, and which references will be cleaned. Right before execution the plan is recomputed and compared with what you confirmed; a mismatch aborts the operation instead of deleting something you didn't see.
23
- - **Audit log.** Every delete / restore / purge appends one JSON line to `~/.dsh/session-trash/audit.log`, readable from the trash panel.
24
- - **Receipt after delete.** After the move, the plugin checks the places a session can be referenced and reports anything left behind (deletion is one session at a time; the trash tab supports batch restore / batch permanent delete).
23
+ - **Audit log.** Every delete / restore / purge appends one JSON line to `~/.dsh/session-trash/audit.log`, readable from **Settings → Session trash**.
24
+ - **Receipt after delete.** After the move, the plugin checks the places a session can be referenced and reports anything left behind (deletion is one session at a time; the trash list supports batch restore / batch permanent delete).
25
+ - **Keyboard + workspace batch.** `⌘⌥⌫` (rebindable in Settings → General → Shortcuts) opens the same confirmation for the current session, and the workspace `…` menu gains **Delete all sessions in this workspace…**, which previews the whole group and deletes it session by session.
26
+ - **Quiet UI.** One dialog line tells you what will happen (size · sub-sessions · live), the technical detail hides under **Details**, the trash panel is a single page, and maintenance (health check, audit log, receipts) moved to its own settings section. Child-session handling remembers your last choice, stored host-side in `~/.dsh/session-trash/preferences.json`.
25
27
 
26
28
  ## Screenshots
27
29
 
28
- | Plan before delete | Trash | Audit log | Receipts |
29
- | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
30
- | ![Plan before delete](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/confirm-dialog.png) | ![Trash](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/trash-panel.png) | ![Audit log](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/audit-tab.png) | ![Receipts](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/receipts-tab.png) |
30
+ | Delete confirmation | Workspace batch | Trash | Settings → Session trash |
31
+ | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
32
+ | ![Delete confirmation](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/confirm-dialog.png) | ![Workspace batch](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/workspace-batch.png) | ![Trash](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/trash-panel.png) | ![Settings section](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/settings-section.png) |
31
33
 
32
- <sub>Screenshots come from <code>SMOKE_DEMO=1 pnpm smoke:session-delete</code>: workspace names, session titles and IDs are replaced with demo data. The UI language follows DSH (Chinese here).</sub>
34
+ <sub>Screenshots are captured from a live DSH desktop session with the demo data substituted in the DOM (workspace names, session titles, UUIDs and the local user path), so no real content is published. The UI language follows DSH (Chinese here).</sub>
33
35
 
34
36
  ## Install
35
37
 
@@ -51,14 +53,18 @@ Restart the DSH desktop app afterwards. A fresh install adds a host half, so rel
51
53
 
52
54
  ## Usage
53
55
 
54
- **Batch (in trash)**: the trash tab supports select-all / clear / batch restore / batch permanent delete; each entry is handled independently and failures are reported inline.
56
+ **Batch (in trash)**: the trash list has a sticky toolbar with select-all, batch restore and batch permanent delete. Batches run 20 entries at a time with a live `n/total` progress line and a Stop button, so a selection far larger than the host's single-request bound still completes; failures are summarised and stay selected for a retry.
55
57
 
56
58
  **Agent tool**: models can call `session_delete`, but only in two steps — `action=plan` returns the impact summary plus a single-use token (2 minutes), and `action=delete` needs that token. It refuses to delete the calling session, and a changed session invalidates the token. Deleting from the UI never requires the tool.
57
59
 
58
- **Keyboard**: Tab between controls, Enter/Space to activate, Esc to close a dialog. In the trash panel, ↑/↓/Home/End move focus between rows. `⌘/Ctrl + Alt + T` opens the trash. There is no one-key delete shortcut — deletion always goes through the menu and a confirmation dialog.
60
+ **Keyboard**: the delete confirmation opens with focus on **Move to trash**, so Enter deletes and Esc cancels; when deletion is blocked, focus falls back to **Cancel**. Tab moves between the checkbox, the Details disclosure and the buttons. `⌘/Ctrl + Alt + T` opens the trash. The remembered cascade checkbox means the trigger is one key press away from a batch delete — the dialog always spells out how many child sessions come along.
61
+
62
+ **Settings → Session trash**: deletion preferences (remember cascade, reset to default), a trash overview (entries, size, path), and maintenance — health check with a bookkeeping-only clean-up, operation receipts, and the audit log.
59
63
 
60
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.
61
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
+
62
68
 
63
69
  Everything starts from a session row in the sidebar:
64
70
 
@@ -75,24 +81,27 @@ Everything starts from a session row in the sidebar:
75
81
  - **purge** it permanently;
76
82
  - read the audit log.
77
83
 
78
- **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.
79
85
 
80
86
  ## Side effects & risks
81
87
 
82
88
  Files and directories it touches:
83
89
 
84
- | Path | Access | What happens |
85
- | ---------------------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86
- | `~/.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. |
87
- | `~/.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. |
88
- | `~/.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. |
89
- | `~/.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). |
90
96
 
91
97
  - **No network access, no telemetry.**
92
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.
93
99
  - **Restorable by default.** Delete moves files; it does not erase them.
94
100
  - **Purge is irreversible.** "Purge" (and emptying the trash) really deletes the bytes. There is no undo toast and no recovery.
95
- - **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.
96
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.
97
106
  - **Uninstalling the plugin does not empty the trash.** `~/.dsh/session-trash/` is your recovery path and stays until you delete it yourself.
98
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.
@@ -118,25 +127,29 @@ Capability grades:
118
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.
119
128
  - `unknown` — the persistence seam itself is missing: **read-only mode**. Plan, audit and trash listing keep working; delete/restore/purge are disabled.
120
129
 
121
- | Plugin | Verified on DSH | Notes |
122
- | ------ | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
123
- | 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. |
124
- | 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. |
125
- | 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. |
126
- | 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. |
127
140
 
128
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.
129
142
 
130
143
  ## Troubleshooting
131
144
 
132
- | Symptom | Likely cause | What to do |
133
- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
134
- | 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 |
135
- | 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 |
136
- | 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 |
137
- | 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 |
138
- | 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 |
139
- | 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 |
140
153
 
141
154
  ## License
142
155
 
package/README.zh-CN.md CHANGED
@@ -2,16 +2,16 @@
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
 
9
9
  非官方 [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/deepseek-harness) 插件,与 DeepSeek 无关。
10
10
 
11
- > **状态:早期可用。** 已在当前目标 DSH 版本上用 `pnpm smoke:session-delete`(临时 DSH home,24 项端到端断言)和 `pnpm probe:runtime` 验证;桌面只读回归是在更早的版本上做的。具体范围见[兼容性与降级](#兼容性与降级)表格。`pnpm gate session-delete` 一条命令跑完发版门禁。仍是年轻软件,重要数据请自行备份。
11
+ > **状态:早期可用。** 已在当前目标 DSH 版本上用 `pnpm smoke:session-delete`(临时 DSH home,33 项端到端断言)和 `pnpm probe:runtime` 验证;桌面只读回归是在更早的版本上做的。具体范围见[兼容性与降级](#兼容性与降级)表格。`pnpm gate session-delete` 一条命令跑完发版门禁。仍是年轻软件,重要数据请自行备份。
12
12
 
13
13
 
14
- ![删除确认框:展示体积、子会话和将要清理的引用](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/overview.png)
14
+ ![删除确认框:一行影响面、可选的级联勾选、以及「详情」折叠](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/overview.png)
15
15
 
16
16
  ## 做什么
17
17
 
@@ -20,16 +20,18 @@ DSH 自带的「归档」只是把会话藏起来:id 记进工作区的归档
20
20
  - **真正的删除。** 把会话目录从 `~/.dsh/sessions/` 移走,同时清掉还指向它的记账(归档集合、置顶集合、工作区归属、投影缓存),所以会话不会复活,也不会留下幽灵条目。
21
21
  - **默认进回收站。** 第一次点删除不会抹掉任何东西:会话进 `~/.dsh/session-trash/`,随时可恢复。「彻底删除」是另一个独立的显式动作。
22
22
  - **删前预演(plan / dry-run)。** 确认框由一份计划生成:占用体积、是否 live、有几个子会话、将清理哪些引用。真正执行前会重新算一遍并与你确认时的计划比对,不一致就中止,避免删掉你没看到的东西。
23
- - **审计日志。** 每次删除 / 恢复 / 彻底删除都往 `~/.dsh/session-trash/audit.log` 追加一行 JSON,回收站面板里能直接看。
24
- - **删除回执。** 移走之后核对会话可能被引用的几处,把没清干净的残留列出来(删除仍是一次一条;回收站页签支持批量恢复 / 批量彻底删除)。
23
+ - **审计日志。** 每次删除 / 恢复 / 彻底删除都往 `~/.dsh/session-trash/audit.log` 追加一行 JSON,在 **设置 → 会话回收站** 里能直接看。
24
+ - **删除回执。** 移走之后核对会话可能被引用的几处,把没清干净的残留列出来(删除仍是一次一条;回收站列表支持批量恢复 / 批量彻底删除)。
25
+ - **快捷键与工作区批量。** `⌘⌥⌫`(可在 设置 → 通用 → 快捷键 改)对当前会话直接打开同一个确认框;工作区「…」菜单里多了 **删除此工作区的全部会话…**,先给出整组影响面,再逐条删除。
26
+ - **安静的界面。** 确认框只留一行「体积 · 子会话 · 正在运行」,技术细节收进「详情」;回收站是单页列表;体检、审计、回执搬到设置页。子会话的勾选沿用你上次的选择,存在宿主侧 `~/.dsh/session-trash/preferences.json`。
25
27
 
26
28
  ## 截图
27
29
 
28
- | 删前预演 | 回收站 | 审计日志 | 回执 |
29
- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
30
- | ![删前预演](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/confirm-dialog.png) | ![回收站](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/trash-panel.png) | ![审计日志](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/audit-tab.png) | ![回执](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/receipts-tab.png) |
30
+ | 删除确认 | 工作区批量 | 回收站 | 设置 → 会话回收站 |
31
+ | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
32
+ | ![删除确认](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/confirm-dialog.png) | ![工作区批量](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/workspace-batch.png) | ![回收站](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/trash-panel.png) | ![设置页分节](https://raw.githubusercontent.com/kangyishuai/dsh-plugins/main/packages/session-delete/docs/images/settings-section.png) |
31
33
 
32
- <sub>截图由 <code>SMOKE_DEMO=1 pnpm smoke:session-delete</code> 生成,工作区名、会话标题和 ID 都已替换为演示数据。</sub>
34
+ <sub>截图从真实 DSH 桌面版现场截取,并在 DOM 层把工作区名、会话标题、UUID 与本机用户路径替换为演示数据,不含真实内容。</sub>
33
35
 
34
36
  ## 安装
35
37
 
@@ -51,14 +53,18 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
51
53
 
52
54
  ## 使用
53
55
 
54
- **回收站内批量**:回收站页签支持全选/清空/批量恢复/批量彻底删除,逐条执行,失败的条目会在面板里说明。
56
+ **回收站内批量**:列表上方是吸顶的批量条(全选 / 批量恢复 / 批量彻底删除)。批量按 20 条一批执行,显示「处理中 n/总」,可随时「停止」——所以一次选 80 条也不会被宿主单次上限整单拒绝;失败的条目会汇总并保持选中,方便重试。
55
57
 
56
58
  **Agent 工具**:模型可以调用 `session_delete`,但必须两段式——`action=plan` 返回影响面摘要和一次性 token(2 分钟有效),`action=delete` 必须带这个 token。它拒绝删除调用者自己的会话,会话在此期间变化会让 token 失效。通过 UI 删除不需要这个工具。
57
59
 
58
- **键盘**:Tab 在各按钮间移动,Enter/Space 触发,Esc 关闭对话框;回收站面板里可用 ↑/↓/Home/End 在条目间移动焦点;`⌘/Ctrl + Alt + T` 直接打开回收站。删除始终需要菜单 + 确认框,没有一键删除的快捷键。
60
+ **键盘**:删除确认框打开时焦点就在「移入回收站」上,**回车即执行**、Esc 取消;不可删除时焦点回落到「取消」。Tab 在勾选框、详情折叠与按钮之间移动。`⌘/Ctrl + Alt + T` 直接打开回收站。因为级联勾选会被记住,回车离批量删除只有一步——所以确认框始终写明会带上多少个子会话。
61
+
62
+ **设置 → 会话回收站**:删除偏好(记住级联 / 重置为默认)、回收站概览(条目数、占用、路径),以及维护——体检(只动登记表)、操作回执、审计日志。
59
63
 
60
64
  **刷新**:回收站面板没有刷新按钮——打开时自动加载,之后每 5 秒、窗口重新可见、以及每次恢复/彻底删除后自动同步。
61
65
 
66
+ **视图跟着会话走。** 删掉当前正在看的会话时,界面会自动切到下一个可用会话(没有就回同一工作区的新会话页),并留一条「已移入回收站,可在回收站恢复」的提示——不会把你留在已删除的会话上对着「会话不可用」。恢复会话(面板单条恢复或 toast「撤销」)会关闭面板、把主视图重新绑定到该会话并打开它——即使你当时正在看别的会话;批量恢复只刷新列表、不会在多个会话间来回跳。若某个 DSH 版本不提供客户端导航服务,插件降级为刷新列表/投影,此时可能仍需手动切换会话。
67
+
62
68
 
63
69
  入口都在侧栏的会话行上:
64
70
 
@@ -75,24 +81,27 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
75
81
  - **彻底删除**(不可恢复);
76
82
  - 查看审计日志。
77
83
 
78
- **体检**:回收站面板有第三个页签。它把会话存储与工作区记账对账,列出失效引用(归档/置顶幽灵、工作区记账、孤儿会话目录、损坏的回收站条目、未完成操作)。清理**只动登记表**,绝不删会话文件。
84
+ **体检**:设置 → 会话回收站 → 维护。它是**手动动作**——打开设置页不再扫全库——本次页面会话内会复用上次结论。体检查把会话存储与工作区记账对账,列出失效引用(归档/置顶幽灵、工作区记账、孤儿会话目录、损坏的回收站条目、启动对账没能自动处理的未完成操作)。清理**只动登记表**,绝不删会话文件。
79
85
 
80
86
  ## 副作用与风险
81
87
 
82
88
  会读写这些路径:
83
89
 
84
- | 路径 | 操作 | 说明 |
85
- | ------------------------------------ | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
86
- | `~/.dsh/sessions/<工作区>/<会话>/` | 读 + 移动 | 通过宿主的持久化 seam(`stat` / `locate`)定位,不写死日志文件名。删除时整个会话目录移进回收站,恢复时移回来。同卷是 rename,跨卷退化为复制 + 校验 + 删除。 |
87
- | `~/.dsh/storages/workspace.json` | 只经宿主 API | 归档 / 置顶集合与工作区归属通过 `workspaceRegistry` 的方法(archive、unarchive、pin、unpin、detachSession)改动,插件不会手改这个文件。 |
88
- | `~/.dsh/storages/session_projcache/` | 优先宿主 API,兜底读文件 | 清掉该会话的投影缓存,避免删掉的会话在搜索里冒出来。只有能力探测落在 internal 档时才直接碰文件。 |
89
- | `~/.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` 行)。 |
90
96
 
91
97
  - **不联网、不上报。**
92
98
  - **macOS 窗口拖动。** 自绘确认框 fallback 的遮罩声明了 `data-window-drag-exclude`,覆盖页头时拖动不会拖走窗口。
93
99
  - **默认可恢复。** 删除是把文件移走,不是抹掉。
94
100
  - **彻底删除不可恢复。** 「彻底删除」以及清空回收站是真的删字节,没有撤销 toast,也找不回来。
95
- - **恢复不等于完整撤销。** 日志和工作区归属会回来,置顶与归档标记不会:DSH 归档时会顺手清掉 pin,取消归档时不会恢复。
101
+ - **中断的操作会在下次启动时对账。** 每个破坏性步骤先写 journal `intent`;启动时按磁盘事实补完收尾或回滚归档闸门。两边都在、两边都不在这类解释不了的现场**一律不动**,保留为「需人工核对」——绝不猜。
102
+ - **部分成功会如实说出来。** 会话已进回收站但引用清理失败时,界面按事实提示、回执标 `partial`;恢复把会话搬回来但引用/工作区/置顶没全还原时同样如此,回执里有逐项引用结果与恢复后校验。失败项会**逐条点名并给出下一步动作**(例如「未挂回工作区:ws1;可在会话右键菜单「归属到项目…」里手动挂回」),审计日志写同一份清单,设置页的回执可展开逐项查看;恢复时会先自动重试一次失败的引用,界面另有「重试未通过的引用」按钮可再试。
103
+ - **重检会按「删除前的快照」重放。** 「重试未通过的引用」按回执里的快照重新挂回工作区、写回置顶、解除归档;当回执缺少快照(旧版本写的)或会话目录已不存在时它会拒绝,而不是报一个假的「全部恢复」。
104
+ - **恢复不等于完整撤销。** 日志、工作区归属和置顶会回来:置顶状态在**归档步骤之前**取(DSH 归档时会清 pin),记在回收站条目里并在恢复时写回。归档标记不会——插件把取消归档当作删除闸门的收尾,但不会重新归档。宿主不提供的工作区接口一律记为「跳过」而不是「失败」,不会伪造成功;如果恢复后发送被拒并提示 `session/agent-busy`,说明宿主仍把这个会话标记为忙碌,重启 DSH 或新建会话继续即可(插件不会去杀宿主进程)。
96
105
  - **归档可能清理干净的工作树(DSH 0.2.2-rc.2 起)。** 「移入回收站」本质是归档会话:新版本 DSH 会记录会话创建的工作树,并在归档时对满足条件(没有未归档会话引用、Git 干净、不是分离 HEAD 等)的目录执行 `git worktree remove`。分支和提交保留,被忽略的文件(如 `node_modules`)不会保留。要保住检出目录,删除前用 `git worktree lock <path>`,或在 Forge 套件的 worktree 行打开 `retainOnArchive`。
97
106
  - **卸载插件不会清空回收站。** `~/.dsh/session-trash/` 是你的恢复通道,会一直留着,除非你自己删。
98
107
  - **数据根目录。** 按「插件配置 `dataRoot` → 环境变量 `DSH_HOME` → `~/.dsh`」的顺序解析。如果你的 DSH 把数据放在别处,要把插件指过去;根目录不像 DSH 数据目录时,插件会拒绝执行而不是瞎猜。
@@ -118,12 +127,16 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
118
127
  - `minimal` —— 宿主没有 `workspaceRegistry`(例如 headless 组合)。删除照常进行;归档闸门、置顶/工作区记账、投影缓存这些步骤被跳过并写进回执。
119
128
  - `unknown` —— 持久化本体缺失:**只读模式**。plan、审计、回收站列表还能用;删除、恢复、彻底删除被禁用。
120
129
 
121
- | 插件版本 | 已验证的 DSH 版本 | 说明 |
122
- | -------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
123
- | 0.4.8 | **0.2.2-rc.2**(桌面版) | macOS 窗口拖动修复:自绘确认框 fallback 的遮罩声明 `data-window-drag-exclude`。桌面只读回归在发布版上复跑 14/14,宿主探针 67/67。 |
124
- | 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。 |
125
- | 0.4.2 | **0.2.2-rc.1**(桌面版) | `pnpm smoke:session-delete` 24 项断言全绿,并确认同一版本桌面版里插件正常激活、没有 bundle 错误。 |
126
- | 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 验收。 |
127
140
 
128
141
  目前只在 **macOS** 上验证过。Windows 相关路径(`session.lock` 的 EBUSY/EPERM 重试、宿主在那儿用的命名信号量)代码里有,但**还没实测**。
129
142
 
@@ -136,7 +149,7 @@ DSH 升级之后:重启,然后看插件的状态条(设置 → 插件)
136
149
  | 会话菜单里没有「删除会话…」 | client 半没加载:插件未激活,或菜单 slot 改名了 | 看插件状态,确认插件已启用;装完要重启桌面版 |
137
150
  | 菜单项在,一点就提示只读模式 | L2 探测不到需要的宿主能力(DSH 升级后 API 变了) | 升级插件;升级后仍然只读,就带着状态输出和 DSH 版本提 issue |
138
151
  | 删除成功,但侧栏的行还在 | client 端的移除通道变了 | 刷新页面;刷新后还在,就带着 DSH 版本提 issue |
139
- | 恢复后置顶 / 归档标记丢了 | DSH 归档时清 pin、取消归档时不恢复 | 目前属预期行为;可以回回收站重试,日志本身没回来请提 issue |
152
+ | 恢复后归档标记丢了 | DSH 归档时清 pin;插件会还原置顶,但不还原归档标记 | 属预期行为;日志或工作区归属本身没回来请提 issue |
140
153
  | 彻底删除后还残留东西 | 删除回执里列出的残留 | 对回执和审计日志,按回执里的路径手动清理,并把回执附在 issue 里 |
141
154
  | 删完之后回收站是空的 | 插件解析到的数据根目录和你的 DSH 不是同一个(`DSH_HOME` / 配置) | 去磁盘上看 `~/.dsh/session-trash/`,再核对插件的 `dataRoot` 配置 |
142
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]