@kangyishuai/dsh-session-delete 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +121 -2
- package/README.zh-CN.md +122 -0
- package/cordis.patch.yml +3 -0
- package/lib/audit.js +93 -0
- package/lib/capability.js +104 -0
- package/lib/client.js +1146 -0
- package/lib/index.js +7 -0
- package/lib/journal.js +136 -0
- package/lib/locate.js +129 -0
- package/lib/operations.js +534 -0
- package/lib/paths.js +148 -0
- package/lib/plan.js +185 -0
- package/lib/refs.js +192 -0
- package/lib/service.js +166 -0
- package/lib/trash.js +246 -0
- package/locale/en.json +37 -0
- package/locale/zh.json +37 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kangyishuai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kangyishuai/dsh-session-delete
|
|
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
|
+
|
|
5
|
+
[中文](./README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai). Not affiliated with DeepSeek.
|
|
8
|
+
|
|
9
|
+
> **Status: v0.1, early.** Verified on DSH 0.2.1-rc.5 with `pnpm smoke:session-delete` (19 end-to-end assertions) plus a manual pass in the desktop GUI. Treat it as young software and keep backups of anything you cannot lose.
|
|
10
|
+
|
|
11
|
+
## What it does
|
|
12
|
+
|
|
13
|
+
DSH's built-in _archive_ only hides a session: the id goes into the workspace's archived set and the log files stay on disk forever. This plugin does the real deletion, with the guard rails that go with it.
|
|
14
|
+
|
|
15
|
+
- **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.
|
|
16
|
+
- **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.
|
|
17
|
+
- **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.
|
|
18
|
+
- **Audit log.** Every delete / restore / purge appends one JSON line to `~/.dsh/session-trash/audit.log`, readable from the trash panel.
|
|
19
|
+
- **Receipt after delete.** After the move, the plugin checks the places a session can be referenced and reports anything left behind (v0.1: one session at a time).
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
dsh plugin --profile desktop add @kangyishuai/dsh-session-delete
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
To run the working tree instead of a published version, pack it first — `link:` installs do not work (the host's `@deepseek-ai/*` resolution only covers packages whose real path is inside the profile):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
cd packages/session-delete
|
|
31
|
+
pnpm pack --pack-destination /tmp
|
|
32
|
+
dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Re-run `pnpm pack` + `add` after changing the code.
|
|
36
|
+
|
|
37
|
+
Restart the DSH desktop app afterwards. A fresh install adds a host half, so reloading the page is not enough.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
**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.
|
|
42
|
+
|
|
43
|
+
**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.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
Everything starts from a session row in the sidebar:
|
|
47
|
+
|
|
48
|
+
1. Open the session's "…" menu and choose **删除会话…** (Delete session…).
|
|
49
|
+
2. The confirmation dialog shows:
|
|
50
|
+
- how much disk space the session occupies;
|
|
51
|
+
- whether the session is live (running turn, subagents, background jobs) — a live session is stopped first, not refused;
|
|
52
|
+
- how many sub-sessions it has (informational: v0.1 deletes only the session you picked);
|
|
53
|
+
- the references that will be cleaned: archived set, pinned set, workspace membership, projection cache.
|
|
54
|
+
3. Confirm. The session moves to the trash and disappears from the sidebar.
|
|
55
|
+
4. **回收站…** (Trash…) in the same menu opens the trash panel, where you can:
|
|
56
|
+
- see each trashed entry (title, size, deletion time);
|
|
57
|
+
- **restore** it to the sidebar;
|
|
58
|
+
- **purge** it permanently;
|
|
59
|
+
- read the audit log.
|
|
60
|
+
|
|
61
|
+
## Side effects & risks
|
|
62
|
+
|
|
63
|
+
Files and directories it touches:
|
|
64
|
+
|
|
65
|
+
| Path | Access | What happens |
|
|
66
|
+
| ---------------------------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `~/.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. |
|
|
68
|
+
| `~/.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. |
|
|
69
|
+
| `~/.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. |
|
|
70
|
+
| `~/.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). |
|
|
71
|
+
|
|
72
|
+
- **No network access, no telemetry.**
|
|
73
|
+
- **Restorable by default.** Delete moves files; it does not erase them.
|
|
74
|
+
- **Purge is irreversible.** "Purge" (and emptying the trash) really deletes the bytes. There is no undo toast and no recovery.
|
|
75
|
+
- **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.
|
|
76
|
+
- **Uninstalling the plugin does not empty the trash.** `~/.dsh/session-trash/` is your recovery path and stays until you delete it yourself.
|
|
77
|
+
- **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.
|
|
78
|
+
- **Alpha software operating on your data.** Until v0.1 passes GUI acceptance, back up anything you care about.
|
|
79
|
+
|
|
80
|
+
## How this differs from the built-in archive
|
|
81
|
+
|
|
82
|
+
Archive is a bookmark, not a deletion: DSH adds the session id to the workspace's archived set and everything on disk stays where it was, still taking space and still indexed. This plugin moves the files out of the session tree, drops the references that pointed at them, keeps a recoverable copy in its own trash, and logs what it did. Archive keeps working exactly as before — this plugin adds a menu item, it doesn't replace anything.
|
|
83
|
+
|
|
84
|
+
## Compatibility & degradation
|
|
85
|
+
|
|
86
|
+
v0.1 declares no `engines.dsh` range. Instead there are three layers of defense:
|
|
87
|
+
|
|
88
|
+
| Layer | When it runs | What it does | What you see |
|
|
89
|
+
| ------------------------ | -------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
90
|
+
| L1 version gate | install / activation | `engines.dsh` version range. **Not declared in v0.1**, so this layer is currently inactive. | nothing |
|
|
91
|
+
| L2 startup self-check | plugin activation | Probes every host capability it depends on and grades them api / internal / unknown. | **Read-only mode**: plan, audit and trash listing keep working; delete, restore and purge are disabled. |
|
|
92
|
+
| L3 per-operation refusal | every operation | Each operation re-checks its own prerequisites; unknown always refuses. | A structured error code plus a human-readable reason, and no half-deleted state. |
|
|
93
|
+
|
|
94
|
+
| Plugin | Verified on DSH | Notes |
|
|
95
|
+
| ------ | ------------------------ | ------------------------------------------------------------------------------------------- |
|
|
96
|
+
| 0.1.0 | **0.2.1-rc.5** (desktop) | `pnpm smoke:session-delete`: 19 assertions green; manual GUI pass on the same host version. |
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
|
|
100
|
+
## Troubleshooting
|
|
101
|
+
|
|
102
|
+
| Symptom | Likely cause | What to do |
|
|
103
|
+
| ---------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
104
|
+
| 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 |
|
|
105
|
+
| 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 |
|
|
106
|
+
| 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 |
|
|
107
|
+
| 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 |
|
|
108
|
+
| 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 |
|
|
109
|
+
| 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 |
|
|
110
|
+
|
|
111
|
+
## Roadmap (v0.2, not implemented yet)
|
|
112
|
+
|
|
113
|
+
The following are planned and are **not** part of v0.1 — don't expect them in the current release:
|
|
114
|
+
|
|
115
|
+
- batch deletion (multi-select);
|
|
116
|
+
- cascade deletion with a checkbox per sub-session;
|
|
117
|
+
- an agent tool (plan first, then delete);
|
|
118
|
+
- an undo toast after a delete.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT — see [LICENSE](./LICENSE). The repository's [NOTICE](https://github.com/kangyishuai/dsh-plugins/blob/main/NOTICE) credits the community projects whose _design_ informed this plugin; no code was copied from them.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @kangyishuai/dsh-session-delete
|
|
2
|
+
|
|
3
|
+
> 真正的删除会话:默认进回收站、删前先预演、留审计日志,删完给你一份残留回执。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
非官方 [DeepSeek Harness (DSH)](https://github.com/deepseek-ai) 插件,与 DeepSeek 无关。
|
|
8
|
+
|
|
9
|
+
> **状态:v0.1,早期可用。** 已在 DSH 0.2.1-rc.5 上用 `pnpm smoke:session-delete`(19 项端到端断言)加一轮桌面版人工验收。仍是年轻软件,重要数据请自行备份。
|
|
10
|
+
|
|
11
|
+
## 做什么
|
|
12
|
+
|
|
13
|
+
DSH 自带的「归档」只是把会话藏起来:id 记进工作区的归档集合,日志文件一直留在磁盘上。这个插件做真正的删除,并且把安全措施一起做了。
|
|
14
|
+
|
|
15
|
+
- **真正的删除。** 把会话目录从 `~/.dsh/sessions/` 移走,同时清掉还指向它的记账(归档集合、置顶集合、工作区归属、投影缓存),所以会话不会复活,也不会留下幽灵条目。
|
|
16
|
+
- **默认进回收站。** 第一次点删除不会抹掉任何东西:会话进 `~/.dsh/session-trash/`,随时可恢复。「彻底删除」是另一个独立的显式动作。
|
|
17
|
+
- **删前预演(plan / dry-run)。** 确认框由一份计划生成:占用体积、是否 live、有几个子会话、将清理哪些引用。真正执行前会重新算一遍并与你确认时的计划比对,不一致就中止,避免删掉你没看到的东西。
|
|
18
|
+
- **审计日志。** 每次删除 / 恢复 / 彻底删除都往 `~/.dsh/session-trash/audit.log` 追加一行 JSON,回收站面板里能直接看。
|
|
19
|
+
- **删除回执。** 移走之后核对会话可能被引用的几处,把没清干净的残留列出来(v0.1 支持单条会话)。
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
dsh plugin --profile desktop add @kangyishuai/dsh-session-delete
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
想跑本地工作区而不是发布版,必须先打包——`link:` 安装不行(宿主对 `@deepseek-ai/*` 的解析只覆盖真实路径位于 profile 内的包,符号链接会激活失败):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
cd packages/session-delete
|
|
31
|
+
pnpm pack --pack-destination /tmp
|
|
32
|
+
dsh plugin --profile desktop add /tmp/kangyishuai-dsh-session-delete-*.tgz
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
改完代码后重新 `pnpm pack` 并再次 `add`。
|
|
36
|
+
|
|
37
|
+
装完重启 DSH 桌面版。新装会加载 host 半,只刷新页面不够。
|
|
38
|
+
|
|
39
|
+
## 使用
|
|
40
|
+
|
|
41
|
+
**键盘**:Tab 在各按钮间移动,Enter/Space 触发,Esc 关闭对话框;回收站面板里可用 ↑/↓/Home/End 在条目间移动焦点;`⌘/Ctrl + Alt + T` 直接打开回收站。删除始终需要菜单 + 确认框,没有一键删除的快捷键。
|
|
42
|
+
|
|
43
|
+
**刷新**:回收站面板没有刷新按钮——打开时自动加载,之后每 5 秒、窗口重新可见、以及每次恢复/彻底删除后自动同步。
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
入口都在侧栏的会话行上:
|
|
47
|
+
|
|
48
|
+
1. 打开会话的「…」菜单,选「删除会话…」。
|
|
49
|
+
2. 确认框会展示:
|
|
50
|
+
- 这条会话在磁盘上占多少体积;
|
|
51
|
+
- 会话是否 live(有没有在跑的轮次、子代理、后台任务)——live 会话会先被停下再删,而不是拒绝;
|
|
52
|
+
- 有几个子会话(只是提示:v0.1 只删你选中的这一条);
|
|
53
|
+
- 将被清理的引用:归档集合、置顶集合、工作区归属、投影缓存。
|
|
54
|
+
3. 确认。会话进入回收站,侧栏里的那一行消失。
|
|
55
|
+
4. 同一个菜单里的「回收站…」打开回收站面板,可以:
|
|
56
|
+
- 看回收站里有什么(标题、体积、删除时间);
|
|
57
|
+
- **恢复**到侧栏;
|
|
58
|
+
- **彻底删除**(不可恢复);
|
|
59
|
+
- 查看审计日志。
|
|
60
|
+
|
|
61
|
+
## 副作用与风险
|
|
62
|
+
|
|
63
|
+
会读写这些路径:
|
|
64
|
+
|
|
65
|
+
| 路径 | 操作 | 说明 |
|
|
66
|
+
| ------------------------------------ | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `~/.dsh/sessions/<工作区>/<会话>/` | 读 + 移动 | 通过宿主的持久化 seam(`stat` / `locate`)定位,不写死日志文件名。删除时整个会话目录移进回收站,恢复时移回来。同卷是 rename,跨卷退化为复制 + 校验 + 删除。 |
|
|
68
|
+
| `~/.dsh/storages/workspace.json` | 只经宿主 API | 归档 / 置顶集合与工作区归属通过 `workspaceRegistry` 的方法(archive、unarchive、pin、unpin、detachSession)改动,插件不会手改这个文件。 |
|
|
69
|
+
| `~/.dsh/storages/session_projcache/` | 优先宿主 API,兜底读文件 | 清掉该会话的投影缓存,避免删掉的会话在搜索里冒出来。只有能力探测落在 internal 档时才直接碰文件。 |
|
|
70
|
+
| `~/.dsh/session-trash/` | 创建 + 写入 | 每条被删会话一个条目(带 `meta.json`),另有 `audit.log`(JSONL,一次操作一行)和 `journal/`(两阶段提交记录,用于下次启动时把中断的操作补完或回滚)。 |
|
|
71
|
+
|
|
72
|
+
- **不联网、不上报。**
|
|
73
|
+
- **默认可恢复。** 删除是把文件移走,不是抹掉。
|
|
74
|
+
- **彻底删除不可恢复。** 「彻底删除」以及清空回收站是真的删字节,没有撤销 toast,也找不回来。
|
|
75
|
+
- **恢复不等于完整撤销。** 日志和工作区归属会回来,置顶与归档标记不会:DSH 归档时会顺手清掉 pin,取消归档时不会恢复。
|
|
76
|
+
- **卸载插件不会清空回收站。** `~/.dsh/session-trash/` 是你的恢复通道,会一直留着,除非你自己删。
|
|
77
|
+
- **数据根目录。** 按「插件配置 `dataRoot` → 环境变量 `DSH_HOME` → `~/.dsh`」的顺序解析。如果你的 DSH 把数据放在别处,要把插件指过去;根目录不像 DSH 数据目录时,插件会拒绝执行而不是瞎猜。
|
|
78
|
+
- **这是 alpha 软件,而且会动你的数据。** 在 v0.1 通过 GUI 验收之前,重要会话请自行备份。
|
|
79
|
+
|
|
80
|
+
## 与官方归档的区别
|
|
81
|
+
|
|
82
|
+
归档是个书签,不是删除:DSH 只把会话 id 加进工作区的归档集合,磁盘上的东西原封不动,照样占空间、照样被索引。这个插件把文件从会话目录里移走、把指向它的记账清掉,同时在自己的回收站里留一份可恢复的副本,并记录做了什么。官方归档不受影响,照常可用——插件只是加了一个菜单项,没有替换任何东西。
|
|
83
|
+
|
|
84
|
+
## 兼容性与降级
|
|
85
|
+
|
|
86
|
+
v0.1 没有声明 `engines.dsh` 版本范围,改用三层防线:
|
|
87
|
+
|
|
88
|
+
| 层 | 触发时机 | 做什么 | 你会看到什么 |
|
|
89
|
+
| ------------- | ----------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
90
|
+
| L1 版本闸门 | 安装 / 激活 | `engines.dsh` 版本范围。**v0.1 尚未声明**,这一层目前不生效。 | 无 |
|
|
91
|
+
| L2 启动自检 | 插件激活时 | 探测所有依赖的宿主能力,分成 api / internal / unknown 三档。 | 进入**只读模式**:plan、审计、回收站列表还能用;删除、恢复、彻底删除被禁用。 |
|
|
92
|
+
| L3 执行期拒绝 | 每次操作 | 每个操作自己再校验前置能力,unknown 一律拒绝。 | 结构化错误码 + 人类可读原因,磁盘上不会出现删了一半的状态。 |
|
|
93
|
+
|
|
94
|
+
| 插件版本 | 已验证的 DSH 版本 | 说明 |
|
|
95
|
+
| -------- | ------------------------ | -------------------------------------------------------------------------------- |
|
|
96
|
+
| 0.1.0 | **0.2.1-rc.5**(桌面版) | `pnpm smoke:session-delete` 19 项断言全绿,并在同一版本桌面版做过人工 GUI 验收。 |
|
|
97
|
+
|
|
98
|
+
DSH 升级之后:重启,然后看插件的状态条(设置 → 插件)。如果显示只读模式,说明宿主 API 变了——升级插件,或者把两个版本号一起报上来,别硬用。
|
|
99
|
+
|
|
100
|
+
## 故障排查
|
|
101
|
+
|
|
102
|
+
| 症状 | 大概率原因 | 怎么办 |
|
|
103
|
+
| ---------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
104
|
+
| 会话菜单里没有「删除会话…」 | client 半没加载:插件未激活,或菜单 slot 改名了 | 看插件状态,确认插件已启用;装完要重启桌面版 |
|
|
105
|
+
| 菜单项在,一点就提示只读模式 | L2 探测不到需要的宿主能力(DSH 升级后 API 变了) | 升级插件;升级后仍然只读,就带着状态输出和 DSH 版本提 issue |
|
|
106
|
+
| 删除成功,但侧栏的行还在 | client 端的移除通道变了 | 刷新页面;刷新后还在,就带着 DSH 版本提 issue |
|
|
107
|
+
| 恢复后置顶 / 归档标记丢了 | DSH 归档时清 pin、取消归档时不恢复 | 目前属预期行为;可以回回收站重试,日志本身没回来请提 issue |
|
|
108
|
+
| 彻底删除后还残留东西 | 删除回执里列出的残留 | 对回执和审计日志,按回执里的路径手动清理,并把回执附在 issue 里 |
|
|
109
|
+
| 删完之后回收站是空的 | 插件解析到的数据根目录和你的 DSH 不是同一个(`DSH_HOME` / 配置) | 去磁盘上看 `~/.dsh/session-trash/`,再核对插件的 `dataRoot` 配置 |
|
|
110
|
+
|
|
111
|
+
## 计划中(v0.2,尚未实现)
|
|
112
|
+
|
|
113
|
+
下面这些是计划,**v0.1 没有**,不要指望当前版本能用:
|
|
114
|
+
|
|
115
|
+
- 批量删除(多选);
|
|
116
|
+
- 子会话级联删除(逐个子会话勾选);
|
|
117
|
+
- agent 工具(先 plan 再删);
|
|
118
|
+
- 删除后的撤销 toast。
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT,见 [LICENSE](./LICENSE)。本插件借鉴了若干社区项目的**设计**(不是代码),来源记在仓库的 [NOTICE](https://github.com/kangyishuai/dsh-plugins/blob/main/NOTICE)。
|
package/cordis.patch.yml
ADDED
package/lib/audit.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 审计日志:append-only JSONL,一次操作一行。进程内串行写入,单行保持在 4KB 内,
|
|
3
|
+
// 保证多窗口并发时不会出现交错的半行(POSIX 上 O_APPEND 的小写入是原子的)。
|
|
4
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
import { auditPath } from "./paths.js";
|
|
7
|
+
|
|
8
|
+
/** 单行上限:超过就把自由文本字段截断,避免破坏原子写与可读性。 */
|
|
9
|
+
const MAX_LINE = 4096;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {object} AuditEntry
|
|
13
|
+
* @property {"plan" | "trash" | "restore" | "purge" | "reconcile" | "health"} action
|
|
14
|
+
* @property {"ok" | "refused" | "failed"} result
|
|
15
|
+
* @property {string} [sessionId]
|
|
16
|
+
* @property {string} [entryId]
|
|
17
|
+
* @property {string} [operator] ui / agent / system
|
|
18
|
+
* @property {string} [detail]
|
|
19
|
+
* @property {string} [ts]
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {unknown} value
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
function clip(value) {
|
|
27
|
+
if (typeof value !== "string") return "";
|
|
28
|
+
return value.length > 200 ? value.slice(0, 197) + "..." : value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} dataRoot
|
|
33
|
+
* @returns {{ append: (entry: AuditEntry & Record<string, unknown>) => Promise<{ ok: boolean, error?: string }>, read: (limit?: number) => Promise<AuditEntry[]> }}
|
|
34
|
+
*/
|
|
35
|
+
export function createAudit(dataRoot) {
|
|
36
|
+
const file = auditPath(dataRoot);
|
|
37
|
+
/** @type {Promise<unknown>} */
|
|
38
|
+
let chain = Promise.resolve();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {AuditEntry & Record<string, unknown>} entry
|
|
42
|
+
* @returns {Promise<{ ok: boolean, error?: string }>}
|
|
43
|
+
*/
|
|
44
|
+
function append(entry) {
|
|
45
|
+
const record = {
|
|
46
|
+
ts: new Date().toISOString(),
|
|
47
|
+
operator: "ui",
|
|
48
|
+
...entry,
|
|
49
|
+
detail: clip(entry.detail),
|
|
50
|
+
};
|
|
51
|
+
let line = JSON.stringify(record);
|
|
52
|
+
if (line.length > MAX_LINE)
|
|
53
|
+
line = JSON.stringify({ ...record, detail: clip(record.detail).slice(0, 80) });
|
|
54
|
+
const job = chain.then(async () => {
|
|
55
|
+
await mkdir(dirname(file), { recursive: true });
|
|
56
|
+
await appendFile(file, line + "\n", { encoding: "utf8", mode: 0o600 });
|
|
57
|
+
return { ok: true };
|
|
58
|
+
});
|
|
59
|
+
chain = job.catch(() => undefined);
|
|
60
|
+
return job.catch((error) => ({
|
|
61
|
+
ok: false,
|
|
62
|
+
error: String(error instanceof Error ? error.message : error),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 读取最近的审计条目(新的在后)。
|
|
68
|
+
* @param {number} [limit]
|
|
69
|
+
* @returns {Promise<AuditEntry[]>}
|
|
70
|
+
*/
|
|
71
|
+
async function read(limit = 100) {
|
|
72
|
+
let text = "";
|
|
73
|
+
try {
|
|
74
|
+
text = await readFile(file, "utf8");
|
|
75
|
+
} catch {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
const lines = text.split("\n").filter((line) => line.trim().length > 0);
|
|
79
|
+
const slice = lines.slice(Math.max(0, lines.length - Math.max(1, limit)));
|
|
80
|
+
/** @type {AuditEntry[]} */
|
|
81
|
+
const out = [];
|
|
82
|
+
for (const line of slice) {
|
|
83
|
+
try {
|
|
84
|
+
out.push(JSON.parse(line));
|
|
85
|
+
} catch {
|
|
86
|
+
// 坏行跳过,审计读取不应因为一行损坏而整体失败。
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { append, read };
|
|
93
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 宿主能力探测。整个插件对宿主内部契约的依赖只在这里出现一次,
|
|
3
|
+
// 这样 DSH 升级后需要改的地方永远只有一个文件(见 docs/adr/0005)。
|
|
4
|
+
|
|
5
|
+
/** @typedef {"api" | "internal" | "unknown"} CapabilityTier */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} Capabilities
|
|
9
|
+
* @property {CapabilityTier} tier
|
|
10
|
+
* @property {Record<string, boolean>} checks
|
|
11
|
+
* @property {string[]} notes
|
|
12
|
+
* @property {{ persistence?: any, sessions?: any, workspace?: any, storageDomain?: any, agents?: any }} services
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 安全地从 ctx 上取一个服务(Cordis 用 ctx.get,测试替身可能直接挂属性)。
|
|
17
|
+
* @param {any} ctx
|
|
18
|
+
* @param {string} name
|
|
19
|
+
* @returns {any}
|
|
20
|
+
*/
|
|
21
|
+
function serviceOf(ctx, name) {
|
|
22
|
+
try {
|
|
23
|
+
if (typeof ctx?.get === "function") return ctx.get(name);
|
|
24
|
+
} catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return ctx?.[name];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @param {any} target @param {string} key @returns {boolean} */
|
|
31
|
+
function callable(target, key) {
|
|
32
|
+
return typeof target?.[key] === "function";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 探测本插件依赖的全部宿主能力,并按三档给出结论:
|
|
37
|
+
* - api:官方文档里有的一等公民能力齐全;
|
|
38
|
+
* - internal:核心可用,但有依赖社区契约的部件(会降级执行并告警);
|
|
39
|
+
* - unknown:核心能力缺失,破坏性操作必须拒绝。
|
|
40
|
+
*
|
|
41
|
+
* @param {any} ctx host 上下文。
|
|
42
|
+
* @returns {Capabilities}
|
|
43
|
+
*/
|
|
44
|
+
export function probeCapabilities(ctx) {
|
|
45
|
+
const persistence = serviceOf(ctx, "sessionPersistence");
|
|
46
|
+
const sessions = serviceOf(ctx, "sessions");
|
|
47
|
+
const workspace = serviceOf(ctx, "workspaceRegistry");
|
|
48
|
+
const storageDomain = serviceOf(ctx, "storageDomain");
|
|
49
|
+
const agents = serviceOf(ctx, "agents");
|
|
50
|
+
|
|
51
|
+
const checks = {
|
|
52
|
+
"persistence.stat": callable(persistence, "stat"),
|
|
53
|
+
"persistence.locate": callable(persistence, "locate"),
|
|
54
|
+
"event.session-stop": typeof ctx?.parallel === "function",
|
|
55
|
+
"event.session-activity": typeof ctx?.waterfall === "function",
|
|
56
|
+
"sessions.get": callable(sessions, "get"),
|
|
57
|
+
"sessions.flush": callable(sessions, "flush"),
|
|
58
|
+
"sessions.detach": callable(sessions, "detachEntered") && Boolean(sessions?.store),
|
|
59
|
+
"agents.detach": callable(agents, "detachEntered") && Boolean(agents?.store),
|
|
60
|
+
"workspace.archive": callable(workspace, "archiveSession"),
|
|
61
|
+
"workspace.unarchive": callable(workspace, "unarchiveSession"),
|
|
62
|
+
"workspace.pin": callable(workspace, "pinSession"),
|
|
63
|
+
"workspace.unpin": callable(workspace, "unpinSession"),
|
|
64
|
+
"workspace.list": callable(workspace, "list"),
|
|
65
|
+
"storage.domain": callable(storageDomain, "get"),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const table = /** @type {Record<string, boolean>} */ (checks);
|
|
69
|
+
/** @type {string[]} */
|
|
70
|
+
const notes = [];
|
|
71
|
+
for (const [name, ok] of Object.entries(table)) {
|
|
72
|
+
if (!ok) notes.push(`missing: ${name}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @type {CapabilityTier} */
|
|
76
|
+
let tier = "api";
|
|
77
|
+
const essential = ["persistence.stat", "workspace.archive", "workspace.unarchive"];
|
|
78
|
+
const convenient = [
|
|
79
|
+
"persistence.locate",
|
|
80
|
+
"storage.domain",
|
|
81
|
+
"sessions.detach",
|
|
82
|
+
"agents.detach",
|
|
83
|
+
"event.session-stop",
|
|
84
|
+
"event.session-activity",
|
|
85
|
+
];
|
|
86
|
+
if (essential.some((k) => !table[k])) tier = "unknown";
|
|
87
|
+
else if (convenient.some((k) => !table[k])) tier = "internal";
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
tier,
|
|
91
|
+
checks,
|
|
92
|
+
notes,
|
|
93
|
+
services: { persistence, sessions, workspace, storageDomain, agents },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 给客户端展示的一份精简能力快照(不暴露服务对象)。
|
|
99
|
+
* @param {Capabilities} caps
|
|
100
|
+
* @returns {{ tier: CapabilityTier, checks: Record<string, boolean>, notes: string[] }}
|
|
101
|
+
*/
|
|
102
|
+
export function describeCapabilities(caps) {
|
|
103
|
+
return { tier: caps.tier, checks: caps.checks, notes: [...caps.notes] };
|
|
104
|
+
}
|