dsh-session-ops 0.2.5 → 0.2.7
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 +10 -4
- package/README.zh.md +2 -2
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +2 -2
- package/lib/admin.js +72 -2
- package/lib/client.js +207 -27
- package/lib/index.js +2 -2
- package/lib/types/admin.d.ts +38 -0
- package/lib/types/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,14 +53,20 @@ shows the current Session's durable artifact:
|
|
|
53
53
|
|
|
54
54
|
- size, compression format (`zstd` / uncompressed), header format classification (current /
|
|
55
55
|
migration-required);
|
|
56
|
-
- the log file's
|
|
56
|
+
- the log file's **directory** (the full file path is in the row's tooltip);
|
|
57
57
|
- whether the Session is resident in the Host process and mid-turn, plus its workspace.
|
|
58
58
|
|
|
59
|
+
The section also carries an **打开目录** button: one click opens that directory in the OS file
|
|
60
|
+
manager (Finder / Explorer / xdg-open). It sends only the Session id to
|
|
61
|
+
`/session-admin/api/openDir`; the Host derives the directory from its own
|
|
62
|
+
`sessionPersistence.stat(sessionId)` result, so the browser never gets a generic
|
|
63
|
+
"open any folder" capability. A failed open is reported inline instead of throwing.
|
|
64
|
+
|
|
59
65
|
The data comes from one read-only `sessionPersistence.stat(sessionId)` call
|
|
60
66
|
(`/session-admin/api/health`). The route **never decompresses or reads the event log** and never
|
|
61
|
-
enumerates all sessions;
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
enumerates all sessions; deeper checks such as frame-level verification are out of scope. It
|
|
68
|
+
renders a placeholder while loading so the panel never hides the section title for lack of
|
|
69
|
+
content, and lowers its density when shown as an overlay.
|
|
64
70
|
|
|
65
71
|
On 0.2.1 hosts the slot is not declared: the registration stays pending without an error, and the
|
|
66
72
|
tabs, header icon, context menu, model tools and both HTTP prefixes keep working.
|
package/README.zh.md
CHANGED
|
@@ -28,7 +28,7 @@ dsh plugin --profile <profile> add dsh-session-ops
|
|
|
28
28
|
- `<DSH_HOME>/storages/session_projcache/sessions/<session-id>.json`:投影缓存
|
|
29
29
|
- `<DSH_HOME>/rewind-snapshots/<session-id>/`:回退快照(若有)
|
|
30
30
|
|
|
31
|
-
删除后顺手清理因此变空的项目目录。没有回收站,删了无法恢复;删除前请自行备份 `$DSH_HOME
|
|
31
|
+
删除后顺手清理因此变空的项目目录。没有回收站,删了无法恢复;删除前请自行备份 `$DSH_HOME`。面板提供预演与确认卡片(输入「删除」才能继续),但最终责任在操作者。
|
|
32
32
|
|
|
33
33
|
默认安全边界(可在配置里改):`allowWorkspaceSessions=false`、`allowLiveSessions=false`、`refuseRunning=true`。工作区会话、正在跑的会话、运行中的搬迁默认都被拒绝。
|
|
34
34
|
|
|
@@ -56,7 +56,7 @@ DSH 0.2.2-rc.3 起,会话标题栏的「会话面板」里会出现本插件
|
|
|
56
56
|
| `root` | `''` | 会话根目录;空则取 `sessionPersistence.root`(jsonl 后端为 `$DSH_HOME/sessions`) |
|
|
57
57
|
| `adminAllowHosts` | `[]` | 删除半边的 LAN 信任列表(按 `Host` 头解析 `host` 或 `host:port`) |
|
|
58
58
|
| `moveAllowHosts` | `[]` | 搬迁半边的 LAN 信任列表(按 `Host` 头完整值精确匹配) |
|
|
59
|
-
| `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 +
|
|
59
|
+
| `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 + 输入确认词的确认卡片) |
|
|
60
60
|
| `allowWorkspaceSessions` | `false` | 允许删除已归属工作区的会话 |
|
|
61
61
|
| `allowLiveSessions` | `false` | 允许删除宿主里驻留的会话 |
|
|
62
62
|
| `maxBatch` | `200` | 单次批量删除上限 |
|
package/docs/DETAIL.md
CHANGED
|
@@ -16,7 +16,7 @@ between workspaces while keeping the registry consistent.
|
|
|
16
16
|
|
|
17
17
|
Registers one read-only section in the conversation header's Session panel: slot `conversation.session.panel.section`, id `dsh-session-ops:session`, order 350 (after environment 0 / change-requests 100 / subagents 200 / shared-tasks 250 / background-jobs 300).
|
|
18
18
|
|
|
19
|
-
- Data plane: `/session-admin/api/health` — one `ctx.sessionPersistence.stat(sessionId)` call returns `path` / `sizeBytes` / `compression` / `formatStatus` / `workspaceId` / `resident` / `running
|
|
19
|
+
- Data plane: `/session-admin/api/health` — one `ctx.sessionPersistence.stat(sessionId)` call returns `path` / `dir` / `sizeBytes` / `compression` / `formatStatus` / `workspaceId` / `resident` / `running`; the panel shows the directory and carries an **open directory** button (`/session-admin/api/openDir`), which takes only the session id and lets the Host derive the path.
|
|
20
20
|
- No list, no scan, no full log read (`readStoredLog` decompresses the whole frame chain); the section offers a manual refresh, and deeper checks are left for later.
|
|
21
21
|
- A missing Session, a host without `stat`, or a throwing `stat` all come back as 200 + `{found:false, reason}`; an invalid id (empty string, path separators, …) is a structured 400.
|
|
22
22
|
- A 0.2.1 host does not declare the slot: the registration stays pending without an error, and every other entry keeps working.
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
在会话标题栏的会话面板里注册一个只读 section:槽 `conversation.session.panel.section`、id `dsh-session-ops:session`、order 350(排在 environment 0 / change-requests 100 / subagents 200 / shared-tasks 250 / background-jobs 300 之后)。
|
|
19
19
|
|
|
20
|
-
- 数据面:`/session-admin/api/health`,一次 `ctx.sessionPersistence.stat(sessionId)` 返回 `path` / `sizeBytes` / `compression` / `formatStatus` / `workspaceId` / `resident` / `running`。
|
|
21
|
-
- 不 list、不 scan、不整读日志(`readStoredLog`
|
|
20
|
+
- 数据面:`/session-admin/api/health`,一次 `ctx.sessionPersistence.stat(sessionId)` 返回 `path` / `dir` / `sizeBytes` / `compression` / `formatStatus` / `workspaceId` / `resident` / `running`。
|
|
21
|
+
- 不 list、不 scan、不整读日志(`readStoredLog` 会解压整条帧链);面板显示日志**目录**,并提供「打开目录」按钮(`/session-admin/api/openDir`):浏览器只传 sessionId,目录由 Host 从 stat 结果推导,没有任意路径打开能力;打开失败在面板内显示一句话。深度检查留给后续。
|
|
22
22
|
- 会话不存在、宿主没有 `stat`、`stat` 抛错都返回 200 + `{found:false, reason}`;非法 id(空串、路径分隔符等)返回 400 结构化错误。
|
|
23
23
|
- 0.2.1 宿主不声明该槽:注册挂起、不报错,其余入口照旧。
|
|
24
24
|
|
package/lib/admin.js
CHANGED
|
@@ -30,9 +30,10 @@
|
|
|
30
30
|
*
|
|
31
31
|
* @module dsh-session-ops/admin
|
|
32
32
|
*/
|
|
33
|
+
import { spawn } from 'node:child_process';
|
|
33
34
|
import { existsSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
34
35
|
import { tmpdir } from 'node:os';
|
|
35
|
-
import { join, resolve, sep } from 'node:path';
|
|
36
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
36
37
|
import { readSessionHeader } from './store/frames.js';
|
|
37
38
|
import { dshHome } from './store/host.js';
|
|
38
39
|
import { createApiHandler } from './store/http.js';
|
|
@@ -597,6 +598,7 @@ export async function sessionHealth(sessionId, source, holds) {
|
|
|
597
598
|
id,
|
|
598
599
|
found: false,
|
|
599
600
|
path: null,
|
|
601
|
+
dir: null,
|
|
600
602
|
sizeBytes: null,
|
|
601
603
|
compression: compressionOf(source),
|
|
602
604
|
formatStatus: null,
|
|
@@ -622,16 +624,76 @@ export async function sessionHealth(sessionId, source, holds) {
|
|
|
622
624
|
}
|
|
623
625
|
if (snapshot === undefined || snapshot === null)
|
|
624
626
|
return { ...base, reason: 'not-found' };
|
|
627
|
+
const path = typeof snapshot.location?.path === 'string' ? snapshot.location.path : null;
|
|
625
628
|
return {
|
|
626
629
|
...base,
|
|
627
630
|
found: true,
|
|
628
|
-
path
|
|
631
|
+
path,
|
|
632
|
+
dir: path === null ? null : dirname(path),
|
|
629
633
|
sizeBytes: typeof snapshot.sizeBytes === 'number' && Number.isFinite(snapshot.sizeBytes)
|
|
630
634
|
? snapshot.sizeBytes
|
|
631
635
|
: null,
|
|
632
636
|
formatStatus: typeof snapshot.formatStatus === 'string' ? snapshot.formatStatus : null,
|
|
633
637
|
};
|
|
634
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* 用系统文件管理器打开目录:macOS `open`、Windows `explorer`、其余 `xdg-open`。
|
|
641
|
+
*
|
|
642
|
+
* `detached + unref` 让子进程脱离 Host 的生命周期——面板点一下不该在 Host 里留下
|
|
643
|
+
* 一个常驻子进程;只等 `spawn` 事件确认命令确实起来,不等它退出。
|
|
644
|
+
* @returns 打开动作。
|
|
645
|
+
*/
|
|
646
|
+
export function systemDirOpener() {
|
|
647
|
+
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'explorer' : 'xdg-open';
|
|
648
|
+
return (dir) => new Promise((resolveOpen, rejectOpen) => {
|
|
649
|
+
let child;
|
|
650
|
+
try {
|
|
651
|
+
child = spawn(command, [dir], { detached: true, stdio: 'ignore' });
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
rejectOpen(error);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
child.once('error', (error) => rejectOpen(error));
|
|
658
|
+
child.once('spawn', () => {
|
|
659
|
+
child.unref();
|
|
660
|
+
resolveOpen();
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
/** 当前生效的打开动作;测试通过 {@link __setDirOpenerForTests} 替换。 */
|
|
665
|
+
let dirOpener = systemDirOpener();
|
|
666
|
+
/**
|
|
667
|
+
* 仅供测试:替换/还原 {@link openSessionDir} 使用的系统打开动作。
|
|
668
|
+
* @param opener - 假的打开动作;传 undefined 还原为真实实现。
|
|
669
|
+
*/
|
|
670
|
+
export function __setDirOpenerForTests(opener) {
|
|
671
|
+
dirOpener = opener ?? systemDirOpener();
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* 在系统文件管理器里打开一条会话的日志目录。
|
|
675
|
+
*
|
|
676
|
+
* 目录由 Host 从 `sessionPersistence.stat()` 的结果推导,**浏览器不能传任意路径**——
|
|
677
|
+
* 这个动作只可能打开本机会话日志所在目录,不构成通用的「打开任意文件夹」接口。
|
|
678
|
+
* @param sessionId - 请求里的会话 id(会先校验,非法时抛给路由层转 400)。
|
|
679
|
+
* @param source - 持久化后端与归属查询。
|
|
680
|
+
* @param holds - `{resident, running}`。
|
|
681
|
+
* @returns 结构化结果(`ok` + `dir` / 失败原因)。
|
|
682
|
+
*/
|
|
683
|
+
export async function openSessionDir(sessionId, source, holds) {
|
|
684
|
+
const health = await sessionHealth(sessionId, source, holds);
|
|
685
|
+
if (health.found !== true)
|
|
686
|
+
return { ok: false, reason: health.reason ?? 'not-found' };
|
|
687
|
+
if (health.dir === null)
|
|
688
|
+
return { ok: false, reason: 'no-directory' };
|
|
689
|
+
try {
|
|
690
|
+
await dirOpener(health.dir);
|
|
691
|
+
}
|
|
692
|
+
catch (error) {
|
|
693
|
+
return { ok: false, reason: 'open-failed', message: messageOf(error), dir: health.dir };
|
|
694
|
+
}
|
|
695
|
+
return { ok: true, dir: health.dir };
|
|
696
|
+
}
|
|
635
697
|
/** `GET` 与 `POST` 共用的方法表。 */
|
|
636
698
|
function buildApi(admin, config, log, holds, health) {
|
|
637
699
|
return {
|
|
@@ -661,6 +723,14 @@ function buildApi(admin, config, log, holds, health) {
|
|
|
661
723
|
async health(payload) {
|
|
662
724
|
return sessionHealth(payload?.sessionId, health, holds);
|
|
663
725
|
},
|
|
726
|
+
/**
|
|
727
|
+
* 在系统文件管理器里打开一条会话的日志目录(会话面板「会话日志」的按钮)。
|
|
728
|
+
*
|
|
729
|
+
* 只按 sessionId 打开本机已知的会话目录,不接受任意路径;非法 id 走 400。
|
|
730
|
+
*/
|
|
731
|
+
async openDir(payload) {
|
|
732
|
+
return openSessionDir(payload?.sessionId, health, holds);
|
|
733
|
+
},
|
|
664
734
|
/**
|
|
665
735
|
* 只要个数的轻量查询,供电标这类高频调用方使用。
|
|
666
736
|
*
|
package/lib/client.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* 与 `dsh-session-move:panel`(+`…:panel-via-better-sidebar`),标题分别是
|
|
23
23
|
* 「会话管理」「会话归位」,角标语义不变(删除半边:未分组条数;搬迁半边:无);
|
|
24
24
|
* - 会话标题栏垃圾桶的 id `dsh-session-admin:delete-current`(仍然是**图标**,
|
|
25
|
-
* 开关由 Host 的 `headerDeleteButton`
|
|
25
|
+
* 开关由 Host 的 `headerDeleteButton` 决定,默认开启,删除要在卡片里输入确认词);
|
|
26
26
|
* - 数据面仍然只打各自的前缀:`/session-admin/api` 与 `/session-move/api`。
|
|
27
27
|
*
|
|
28
28
|
* ## 统一右键菜单(DSH 0.2.2-rc.1 起)
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* - 「移动会话到工作区…」(搬迁半边,order 500):菜单里只判断能不能搬并写出理由,
|
|
34
34
|
* 点下去时重新读一次 Host 状态,然后打开既有右栏「会话归位」面板并选中这条会话;
|
|
35
35
|
* - 「删除会话…」(删除半边,order 620,`afterContent` 与原生「归档」同区):与标题栏
|
|
36
|
-
* 垃圾桶**共用** `deleteSessionFlow`(预演 →
|
|
36
|
+
* 垃圾桶**共用** `deleteSessionFlow`(预演 → 输入确认词 → 删除),`run` 里会再预演
|
|
37
37
|
* 一次,所以菜单打开到点下去之间状态变了也不会绕过守卫。
|
|
38
38
|
*
|
|
39
39
|
* 两项的图标注册在 `contextMenu.icon` 的 keyed slot 上;没有 `contextMenus` 服务
|
|
@@ -144,26 +144,147 @@
|
|
|
144
144
|
}
|
|
145
145
|
return `${value.toFixed(unit === 0 ? 0 : 1)} ${units[unit]}`;
|
|
146
146
|
}
|
|
147
|
+
/** 同一时刻只留一张确认卡片;重入按取消处理,不叠第二张。 */
|
|
148
|
+
let confirmDeletionOpen = false;
|
|
147
149
|
/**
|
|
148
|
-
*
|
|
150
|
+
* 删除确认:画在页面里的确认卡片,`Promise<boolean>`。
|
|
149
151
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
152
|
+
* **不能用 `window.prompt` / `window.confirm`**:DSH Desktop 跑在 Electron 里,
|
|
153
|
+
* `window.prompt` 直接抛 `prompt() is not supported.`(0.2.3-alpha.3 实测),旧实现
|
|
154
|
+
* 因此永远卡在「输入确认词」那一步,界面上只剩一句
|
|
155
|
+
* `删除失败:prompt() is not supported.`——功能看起来像坏了,其实一次都没删过。
|
|
156
|
+
* 卡片挂在 `document.body` 上,不依赖宿主对话框,桌面端与浏览器行为一致。
|
|
153
157
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @param summary -
|
|
158
|
+
* 防误删的口径没降:确认按钮在输入框里打出「删除」之前一直禁用——要求一次有意的
|
|
159
|
+
* 动作,回车或连点顺手确认不掉。
|
|
160
|
+
* @param summary - 这次删除的对象描述(条数、体积或会话 id)。
|
|
157
161
|
* @returns 用户是否确认删除。
|
|
158
162
|
*/
|
|
159
163
|
function confirmDeletion(summary) {
|
|
160
|
-
if (
|
|
161
|
-
return false;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
if (confirmDeletionOpen)
|
|
165
|
+
return Promise.resolve(false);
|
|
166
|
+
confirmDeletionOpen = true;
|
|
167
|
+
return new Promise((resolve) => {
|
|
168
|
+
const overlay = document.createElement('div');
|
|
169
|
+
overlay.style.position = 'fixed';
|
|
170
|
+
overlay.style.inset = '0';
|
|
171
|
+
overlay.style.zIndex = '2147483000';
|
|
172
|
+
overlay.style.display = 'flex';
|
|
173
|
+
overlay.style.alignItems = 'center';
|
|
174
|
+
overlay.style.justifyContent = 'center';
|
|
175
|
+
overlay.style.padding = '24px';
|
|
176
|
+
overlay.style.background = 'rgba(0, 0, 0, 0.42)';
|
|
177
|
+
const card = document.createElement('div');
|
|
178
|
+
card.setAttribute('role', 'alertdialog');
|
|
179
|
+
card.setAttribute('aria-modal', 'true');
|
|
180
|
+
card.style.width = '100%';
|
|
181
|
+
card.style.maxWidth = '420px';
|
|
182
|
+
card.style.boxSizing = 'border-box';
|
|
183
|
+
card.style.display = 'flex';
|
|
184
|
+
card.style.flexDirection = 'column';
|
|
185
|
+
card.style.gap = '10px';
|
|
186
|
+
card.style.padding = '16px';
|
|
187
|
+
card.style.borderRadius = '12px';
|
|
188
|
+
card.style.border = '1px solid var(--dsw-alias-border-l2, var(--dsh-border, #d0d5dd))';
|
|
189
|
+
card.style.background = 'var(--dsw-alias-bg-overlay, var(--dsh-surface, #fff))';
|
|
190
|
+
card.style.color = 'inherit';
|
|
191
|
+
card.style.boxShadow = '0 12px 32px rgba(0, 0, 0, 0.28)';
|
|
192
|
+
const what = document.createElement('div');
|
|
193
|
+
what.style.fontSize = '13px';
|
|
194
|
+
what.style.lineHeight = '1.55';
|
|
195
|
+
what.textContent = summary;
|
|
196
|
+
const note = document.createElement('div');
|
|
197
|
+
note.style.fontSize = '12px';
|
|
198
|
+
note.style.lineHeight = '1.5';
|
|
199
|
+
note.style.color = 'var(--dsw-alias-label-secondary, rgba(128, 128, 128, 0.95))';
|
|
200
|
+
note.textContent = '会话日志、投影缓存与回退快照一并移除,无法撤销。';
|
|
201
|
+
const input = document.createElement('input');
|
|
202
|
+
input.type = 'text';
|
|
203
|
+
input.autocomplete = 'off';
|
|
204
|
+
input.placeholder = '输入「删除」以确认';
|
|
205
|
+
input.style.padding = '6px 9px';
|
|
206
|
+
input.style.fontSize = '12.5px';
|
|
207
|
+
input.style.borderRadius = '8px';
|
|
208
|
+
input.style.border = '1px solid var(--dsw-alias-border-l2, var(--dsh-border, #d0d5dd))';
|
|
209
|
+
input.style.background = 'transparent';
|
|
210
|
+
input.style.color = 'inherit';
|
|
211
|
+
const bar = document.createElement('div');
|
|
212
|
+
bar.style.display = 'flex';
|
|
213
|
+
bar.style.gap = '8px';
|
|
214
|
+
bar.style.justifyContent = 'flex-end';
|
|
215
|
+
const dismiss = document.createElement('button');
|
|
216
|
+
dismiss.type = 'button';
|
|
217
|
+
dismiss.textContent = '取消';
|
|
218
|
+
dismiss.style.cssText =
|
|
219
|
+
'padding:5px 12px;font-size:12.5px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2, #d0d5dd);background:transparent;color:inherit;cursor:pointer';
|
|
220
|
+
const accept = document.createElement('button');
|
|
221
|
+
accept.type = 'button';
|
|
222
|
+
accept.textContent = '删除';
|
|
223
|
+
accept.style.cssText =
|
|
224
|
+
'padding:5px 12px;font-size:12.5px;border-radius:8px;border:1px solid transparent;background:var(--dsw-alias-state-error-primary, #d92d20);color:#fff';
|
|
225
|
+
/** 输入框内容 → 确认按钮可用性(唯一判据:整串等于「删除」)。 */
|
|
226
|
+
function syncAccept() {
|
|
227
|
+
const ready = input.value.trim() === '删除';
|
|
228
|
+
accept.disabled = !ready;
|
|
229
|
+
accept.style.opacity = ready ? '1' : '0.45';
|
|
230
|
+
accept.style.cursor = ready ? 'pointer' : 'default';
|
|
231
|
+
}
|
|
232
|
+
let settled = false;
|
|
233
|
+
function finish(confirmed) {
|
|
234
|
+
if (settled)
|
|
235
|
+
return;
|
|
236
|
+
settled = true;
|
|
237
|
+
confirmDeletionOpen = false;
|
|
238
|
+
input.removeEventListener('input', syncAccept);
|
|
239
|
+
input.removeEventListener('keydown', onKey);
|
|
240
|
+
dismiss.removeEventListener('click', onDismiss);
|
|
241
|
+
accept.removeEventListener('click', onAccept);
|
|
242
|
+
overlay.removeEventListener('mousedown', onBackdrop);
|
|
243
|
+
if (overlay.parentNode !== null)
|
|
244
|
+
overlay.parentNode.removeChild(overlay);
|
|
245
|
+
resolve(confirmed);
|
|
246
|
+
}
|
|
247
|
+
function onDismiss() {
|
|
248
|
+
finish(false);
|
|
249
|
+
}
|
|
250
|
+
function onAccept() {
|
|
251
|
+
if (accept.disabled !== true)
|
|
252
|
+
finish(true);
|
|
253
|
+
}
|
|
254
|
+
function onBackdrop(event) {
|
|
255
|
+
if (event.target === overlay)
|
|
256
|
+
finish(false);
|
|
257
|
+
}
|
|
258
|
+
function onKey(event) {
|
|
259
|
+
if (event.key === 'Escape') {
|
|
260
|
+
if (typeof event.preventDefault === 'function')
|
|
261
|
+
event.preventDefault();
|
|
262
|
+
finish(false);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (event.key === 'Enter' && input.value.trim() === '删除') {
|
|
266
|
+
if (typeof event.preventDefault === 'function')
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
finish(true);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
input.addEventListener('input', syncAccept);
|
|
272
|
+
input.addEventListener('keydown', onKey);
|
|
273
|
+
dismiss.addEventListener('click', onDismiss);
|
|
274
|
+
accept.addEventListener('click', onAccept);
|
|
275
|
+
overlay.addEventListener('mousedown', onBackdrop);
|
|
276
|
+
card.appendChild(what);
|
|
277
|
+
card.appendChild(note);
|
|
278
|
+
card.appendChild(input);
|
|
279
|
+
bar.appendChild(dismiss);
|
|
280
|
+
bar.appendChild(accept);
|
|
281
|
+
card.appendChild(bar);
|
|
282
|
+
overlay.appendChild(card);
|
|
283
|
+
syncAccept();
|
|
284
|
+
document.body.appendChild(overlay);
|
|
285
|
+
if (typeof input.focus === 'function')
|
|
286
|
+
input.focus();
|
|
287
|
+
});
|
|
167
288
|
}
|
|
168
289
|
/** 时间戳 → `MM-DD HH:mm`。 */
|
|
169
290
|
function stamp(ms) {
|
|
@@ -328,6 +449,23 @@
|
|
|
328
449
|
listeners.delete(listener);
|
|
329
450
|
};
|
|
330
451
|
},
|
|
452
|
+
/**
|
|
453
|
+
* 在系统文件管理器里打开该会话日志所在目录。
|
|
454
|
+
*
|
|
455
|
+
* 只把 sessionId 交给 Host(目录由 Host 从 stat 结果推导),浏览器拿不到任意
|
|
456
|
+
* 路径的打开能力;失败时返回结构化原因,交给按钮显示一句话。
|
|
457
|
+
* @param sessionId - 会话 id。
|
|
458
|
+
* @returns `{ok:true, dir}` 或 `{ok:false, reason, message?}`(请求本身失败也算结果)。
|
|
459
|
+
*/
|
|
460
|
+
async openDir(sessionId) {
|
|
461
|
+
try {
|
|
462
|
+
const result = await api.call('openDir', { sessionId });
|
|
463
|
+
return typeof result === 'object' && result !== null ? result : { ok: false, reason: 'unknown' };
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
return { ok: false, reason: 'request-failed', message: String(error?.message ?? error) };
|
|
467
|
+
}
|
|
468
|
+
},
|
|
331
469
|
/** 取消某条会话的在途请求(section 卸载时用:没人等这个结果了)。 */
|
|
332
470
|
abort(sessionId) {
|
|
333
471
|
const controller = controllers.get(sessionId);
|
|
@@ -372,6 +510,28 @@
|
|
|
372
510
|
return `读取失败:${entry?.value?.message ?? '未知错误'}`;
|
|
373
511
|
return '没有可显示的日志信息';
|
|
374
512
|
}
|
|
513
|
+
/** 「打开目录」失败时的界面文案。 */
|
|
514
|
+
function describeOpenFailure(reason) {
|
|
515
|
+
if (reason === 'not-found')
|
|
516
|
+
return '这条会话已不在磁盘上';
|
|
517
|
+
if (reason === 'persistence-unavailable')
|
|
518
|
+
return '宿主未暴露会话持久化 stat';
|
|
519
|
+
if (reason === 'read-failed')
|
|
520
|
+
return '读取会话失败';
|
|
521
|
+
if (reason === 'no-directory')
|
|
522
|
+
return '这条会话还没有落盘文件';
|
|
523
|
+
if (reason === 'open-failed')
|
|
524
|
+
return '系统没能打开目录';
|
|
525
|
+
if (reason === 'request-failed')
|
|
526
|
+
return '请求失败';
|
|
527
|
+
return '打开失败';
|
|
528
|
+
}
|
|
529
|
+
/** 从文件路径取目录(浏览器里没有 node:path,只做最小处理)。 */
|
|
530
|
+
function dirOfFile(path) {
|
|
531
|
+
const text = String(path);
|
|
532
|
+
const index = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
|
|
533
|
+
return index > 0 ? text.slice(0, index) : text;
|
|
534
|
+
}
|
|
375
535
|
/**
|
|
376
536
|
* 「会话日志」section:只读展示本会话的落盘工件。
|
|
377
537
|
*
|
|
@@ -402,13 +562,28 @@
|
|
|
402
562
|
};
|
|
403
563
|
}, [sessionId]);
|
|
404
564
|
const entry = health.entryOf(sessionId);
|
|
405
|
-
const
|
|
565
|
+
const [openState, setOpenState] = React.useState({ kind: 'idle', message: '' });
|
|
566
|
+
// 失败/读取中只给「重试」;有数据时给「打开目录」——刷新按钮对只读面板没有意义。
|
|
567
|
+
const retryButton = h('button', { type: 'button', style: S.button, onClick: () => void health.refresh(sessionId) }, '重试');
|
|
568
|
+
const openButton = h('button', {
|
|
569
|
+
type: 'button',
|
|
570
|
+
style: S.button,
|
|
571
|
+
onClick: () => {
|
|
572
|
+
setOpenState({ kind: 'opening', message: '' });
|
|
573
|
+
void health.openDir(sessionId).then((result) => {
|
|
574
|
+
if (result?.ok === true)
|
|
575
|
+
setOpenState({ kind: 'opened', message: '已在文件管理器中打开' });
|
|
576
|
+
else
|
|
577
|
+
setOpenState({ kind: 'error', message: describeOpenFailure(result?.reason) });
|
|
578
|
+
});
|
|
579
|
+
},
|
|
580
|
+
}, '打开目录');
|
|
406
581
|
if (entry === undefined || entry.state === 'error') {
|
|
407
|
-
return h('div', { style: S.log }, h('div', { style: entry === undefined ? S.muted : S.error }, entry === undefined ? '读取中…' : `读取失败:${entry.message}`), entry === undefined ? null :
|
|
582
|
+
return h('div', { style: S.log }, h('div', { style: entry === undefined ? S.muted : S.error }, entry === undefined ? '读取中…' : `读取失败:${entry.message}`), entry === undefined ? null : retryButton);
|
|
408
583
|
}
|
|
409
584
|
const value = entry.value;
|
|
410
585
|
if (value === undefined || value?.found !== true) {
|
|
411
|
-
return h('div', { style: S.log }, h('div', { style: S.muted }, describeMissingLog(entry)),
|
|
586
|
+
return h('div', { style: S.log }, h('div', { style: S.muted }, describeMissingLog(entry)), retryButton);
|
|
412
587
|
}
|
|
413
588
|
const badges = [
|
|
414
589
|
h('span', {
|
|
@@ -428,9 +603,14 @@
|
|
|
428
603
|
badges.push(h('span', { key: 'resident', style: S.badge }, '驻留'));
|
|
429
604
|
if (entry.state === 'loading')
|
|
430
605
|
badges.push(h('span', { key: 'loading', style: S.muted }, '刷新中…'));
|
|
431
|
-
|
|
606
|
+
// 界面上直接给「目录」而不是长文件路径:一键打开的就是这个目录。
|
|
607
|
+
const dir = typeof value.dir === 'string' ? value.dir : value.path === null ? null : dirOfFile(value.path);
|
|
608
|
+
const feedback = openState?.kind === 'opened' || openState?.kind === 'error'
|
|
609
|
+
? h('div', { style: openState.kind === 'error' ? S.error : S.muted }, openState.message)
|
|
610
|
+
: null;
|
|
611
|
+
return h('div', { style: S.log }, h('div', { style: S.logRow }, badges, h('span', { style: S.logRefresh }, openButton)), dir === null
|
|
432
612
|
? null
|
|
433
|
-
: h('div', { style: dense ? { ...S.logPath, ...S.logPathDense } : S.logPath, title: value.path },
|
|
613
|
+
: h('div', { style: dense ? { ...S.logPath, ...S.logPathDense } : S.logPath, title: value.path ?? undefined }, dir), feedback);
|
|
434
614
|
};
|
|
435
615
|
}
|
|
436
616
|
/**
|
|
@@ -564,7 +744,7 @@
|
|
|
564
744
|
return;
|
|
565
745
|
const bytes = rows.filter((r) => selected.has(r.id)).reduce((sum, r) => sum + (r.bytes ?? 0), 0);
|
|
566
746
|
if (dryRun !== true) {
|
|
567
|
-
if (!confirmDeletion(`将永久删除 ${ids.length} 个会话(约 ${human(bytes)})。`))
|
|
747
|
+
if (!(await confirmDeletion(`将永久删除 ${ids.length} 个会话(约 ${human(bytes)})。`)))
|
|
568
748
|
return;
|
|
569
749
|
}
|
|
570
750
|
setBusy(true);
|
|
@@ -636,7 +816,7 @@
|
|
|
636
816
|
? h('div', { style: { marginTop: 6 } }, h('div', { style: S.muted }, `未处理 ${refusalRows.length} 条:`), refusalRows.slice(0, 12).map((row) => h('div', { key: row.id, style: S.muted }, `${row.id} — ${REASONS[row.reason] ?? row.reason}`)), refusalRows.length > 12 ? h('div', { style: S.muted }, `…以及另外 ${refusalRows.length - 12} 条`) : null)
|
|
637
817
|
: null);
|
|
638
818
|
// 待删除队列:条目、状态、撤销、立即重试。
|
|
639
|
-
return h('div', { style: fill ? { ...S.root, ...S_FILL.root } : S.root }, h('div', { style: S.muted }, 'DSH
|
|
819
|
+
return h('div', { style: fill ? { ...S.root, ...S_FILL.root } : S.root }, h('div', { style: S.muted }, 'DSH 只能「归档」(隐藏)会话;这里做的是把会话的持久化数据真正从磁盘移除。删除要在确认卡片里输入「删除」,不可恢复。'), head, pathBar, toolbar, failure !== undefined ? h('div', { style: S.error }, `失败:${failure}`) : null, list, resultBox);
|
|
640
820
|
};
|
|
641
821
|
}
|
|
642
822
|
/** 右侧页签的标题条。 */
|
|
@@ -718,7 +898,7 @@
|
|
|
718
898
|
}
|
|
719
899
|
}
|
|
720
900
|
/**
|
|
721
|
-
* 删除一个会话的整条流程:预演 →
|
|
901
|
+
* 删除一个会话的整条流程:预演 → 输入确认词 → 删除。
|
|
722
902
|
*
|
|
723
903
|
* 标题栏垃圾桶与右键菜单共用这一段:两处删的是同一个东西,只是入口不同,守卫与
|
|
724
904
|
* 确认必须逐字一致,否则「从菜单删」就等于绕开「从图标删」的那些检查。
|
|
@@ -745,7 +925,7 @@
|
|
|
745
925
|
if (probe.removed === 0) {
|
|
746
926
|
return { ok: false, note: REASONS[entry?.reason] ?? entry?.reason ?? '无法删除' };
|
|
747
927
|
}
|
|
748
|
-
if (!confirmDeletion(`永久删除会话 ${sessionId}?`))
|
|
928
|
+
if (!(await confirmDeletion(`永久删除会话 ${sessionId}?`)))
|
|
749
929
|
return { ok: false };
|
|
750
930
|
const value = await api.call('delete', target);
|
|
751
931
|
const outcome = value.results[0];
|
|
@@ -757,7 +937,7 @@
|
|
|
757
937
|
/**
|
|
758
938
|
* 会话标题栏的垃圾桶图标:删除当前会话。
|
|
759
939
|
*
|
|
760
|
-
* 形态是「图标 +
|
|
940
|
+
* 形态是「图标 + 确认卡片」而不是带字面标签的按钮:标签会招来点击,而这里删的
|
|
761
941
|
* 正是你正在用的会话。图标不占字面位置,误点最多弹出一个确认框。
|
|
762
942
|
*/
|
|
763
943
|
function createHeaderButton(React, ctx, api) {
|
|
@@ -910,7 +1090,7 @@
|
|
|
910
1090
|
key: 'headerDeleteButton',
|
|
911
1091
|
kind: 'boolean',
|
|
912
1092
|
label: '标题栏删除图标',
|
|
913
|
-
hint: '
|
|
1093
|
+
hint: '在会话标题栏显示垃圾桶图标(默认开启)。它是图标而不是按钮,且删除要在卡片里输入确认词。改完刷新页面生效。',
|
|
914
1094
|
},
|
|
915
1095
|
{
|
|
916
1096
|
key: 'allowLiveSessions',
|
package/lib/index.js
CHANGED
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
*/
|
|
46
46
|
import z from '@deepseek-ai/schemastery';
|
|
47
47
|
import { LOG_LINE_LEVEL_FIRST, LOG_LINE_TIME_FIRST, createFileLogger, resolveVolatileConfig, } from './store/host.js';
|
|
48
|
-
import { ADMIN_API_PREFIX, createSessionAdmin, isInside, isTrustedRequest as isTrustedAdminRequest, mountAdmin, } from './admin.js';
|
|
48
|
+
import { ADMIN_API_PREFIX, __setDirOpenerForTests, createSessionAdmin, isInside, isTrustedRequest as isTrustedAdminRequest, mountAdmin, openSessionDir, sessionHealth, systemDirOpener, } from './admin.js';
|
|
49
49
|
import { MOVE_API_PREFIX, isTrustedRequest as isTrustedMoveRequest, mountForkMembershipRepair, mountMove, sweepForkChildrenOnBoot, } from './move.js';
|
|
50
50
|
import { messageOf } from './store/util.js';
|
|
51
|
-
export { ADMIN_API_PREFIX, MOVE_API_PREFIX, createSessionAdmin, isInside, isTrustedAdminRequest, isTrustedMoveRequest, mountAdmin, mountForkMembershipRepair, mountMove, sweepForkChildrenOnBoot, };
|
|
51
|
+
export { ADMIN_API_PREFIX, MOVE_API_PREFIX, __setDirOpenerForTests, createSessionAdmin, isInside, isTrustedAdminRequest, isTrustedMoveRequest, mountAdmin, mountForkMembershipRepair, mountMove, openSessionDir, sessionHealth, sweepForkChildrenOnBoot, systemDirOpener, };
|
|
52
52
|
/**
|
|
53
53
|
* 搬迁半边原来的公开名(`dsh-session-move` 的 `API_PREFIX = '/session-move/api'`)。
|
|
54
54
|
*
|
package/lib/types/admin.d.ts
CHANGED
|
@@ -219,6 +219,8 @@ export interface SessionHealth {
|
|
|
219
219
|
found: boolean;
|
|
220
220
|
/** 会话日志的物理路径;后端没有实体文件(未落盘)时为 null。 */
|
|
221
221
|
path: string | null;
|
|
222
|
+
/** 会话日志所在目录(`dirname(path)`);后端没有实体文件时为 null。 */
|
|
223
|
+
dir: string | null;
|
|
222
224
|
/** 物理文件字节数;后端给不出时为 null。 */
|
|
223
225
|
sizeBytes: number | null;
|
|
224
226
|
/** 压缩格式(`'zstd'` / `''` 未压缩);后端不暴露时为 null。 */
|
|
@@ -249,6 +251,42 @@ export interface SessionHealth {
|
|
|
249
251
|
* @throws 会话 id 不合法(交给路由层转 400)。
|
|
250
252
|
*/
|
|
251
253
|
export declare function sessionHealth(sessionId: unknown, source: HealthSource, holds: Holds): Promise<SessionHealth>;
|
|
254
|
+
/** 打开一个目录的宿主动作(默认调用系统文件管理器;测试可替换)。 */
|
|
255
|
+
export type DirOpener = (dir: string) => Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* 用系统文件管理器打开目录:macOS `open`、Windows `explorer`、其余 `xdg-open`。
|
|
258
|
+
*
|
|
259
|
+
* `detached + unref` 让子进程脱离 Host 的生命周期——面板点一下不该在 Host 里留下
|
|
260
|
+
* 一个常驻子进程;只等 `spawn` 事件确认命令确实起来,不等它退出。
|
|
261
|
+
* @returns 打开动作。
|
|
262
|
+
*/
|
|
263
|
+
export declare function systemDirOpener(): DirOpener;
|
|
264
|
+
/**
|
|
265
|
+
* 仅供测试:替换/还原 {@link openSessionDir} 使用的系统打开动作。
|
|
266
|
+
* @param opener - 假的打开动作;传 undefined 还原为真实实现。
|
|
267
|
+
*/
|
|
268
|
+
export declare function __setDirOpenerForTests(opener: DirOpener | undefined): void;
|
|
269
|
+
/** `/session-admin/api/openDir` 的结果。 */
|
|
270
|
+
export interface OpenDirResult {
|
|
271
|
+
ok: boolean;
|
|
272
|
+
/** 打开(或失败时想打开)的目录。 */
|
|
273
|
+
dir?: string | null;
|
|
274
|
+
/** `ok:false` 的机器可读原因。 */
|
|
275
|
+
reason?: 'not-found' | 'persistence-unavailable' | 'read-failed' | 'no-directory' | 'open-failed';
|
|
276
|
+
/** `open-failed` 时的错误正文。 */
|
|
277
|
+
message?: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 在系统文件管理器里打开一条会话的日志目录。
|
|
281
|
+
*
|
|
282
|
+
* 目录由 Host 从 `sessionPersistence.stat()` 的结果推导,**浏览器不能传任意路径**——
|
|
283
|
+
* 这个动作只可能打开本机会话日志所在目录,不构成通用的「打开任意文件夹」接口。
|
|
284
|
+
* @param sessionId - 请求里的会话 id(会先校验,非法时抛给路由层转 400)。
|
|
285
|
+
* @param source - 持久化后端与归属查询。
|
|
286
|
+
* @param holds - `{resident, running}`。
|
|
287
|
+
* @returns 结构化结果(`ok` + `dir` / 失败原因)。
|
|
288
|
+
*/
|
|
289
|
+
export declare function openSessionDir(sessionId: unknown, source: HealthSource, holds: Holds): Promise<OpenDirResult>;
|
|
252
290
|
/**
|
|
253
291
|
* Host cordis 上下文里删除半边用到的那部分(最小本地接口,见 `src/index.ts` 的说明)。
|
|
254
292
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
* @module dsh-session-ops
|
|
45
45
|
*/
|
|
46
46
|
import z from '@deepseek-ai/schemastery';
|
|
47
|
-
import { ADMIN_API_PREFIX, createSessionAdmin, isInside, isTrustedRequest as isTrustedAdminRequest, mountAdmin } from './admin.js';
|
|
47
|
+
import { ADMIN_API_PREFIX, __setDirOpenerForTests, createSessionAdmin, isInside, isTrustedRequest as isTrustedAdminRequest, mountAdmin, openSessionDir, sessionHealth, systemDirOpener } from './admin.js';
|
|
48
48
|
import { MOVE_API_PREFIX, isTrustedRequest as isTrustedMoveRequest, mountForkMembershipRepair, mountMove, sweepForkChildrenOnBoot } from './move.js';
|
|
49
49
|
import type { WorkspaceRegistryLike } from './store/registry.js';
|
|
50
50
|
import type { SessionPersistenceLike } from './move.js';
|
|
51
|
-
export { ADMIN_API_PREFIX, MOVE_API_PREFIX, createSessionAdmin, isInside, isTrustedAdminRequest, isTrustedMoveRequest, mountAdmin, mountForkMembershipRepair, mountMove, sweepForkChildrenOnBoot, };
|
|
51
|
+
export { ADMIN_API_PREFIX, MOVE_API_PREFIX, __setDirOpenerForTests, createSessionAdmin, isInside, isTrustedAdminRequest, isTrustedMoveRequest, mountAdmin, mountForkMembershipRepair, mountMove, openSessionDir, sessionHealth, sweepForkChildrenOnBoot, systemDirOpener, };
|
|
52
52
|
/**
|
|
53
53
|
* 搬迁半边原来的公开名(`dsh-session-move` 的 `API_PREFIX = '/session-move/api'`)。
|
|
54
54
|
*
|