dsh-session-ops 0.2.0 → 0.2.2
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 -8
- package/README.zh.md +26 -41
- package/cordis.patch.yml +1 -1
- package/docs/DETAIL.md +11 -8
- package/docs/DETAIL.zh.md +21 -14
- package/lib/client.js +80 -3
- package/lib/move.js +124 -0
- package/lib/types/move.d.ts +27 -0
- package/lib/types/store/registry.d.ts +11 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,8 +7,9 @@ One package, one host-plugin row, two halves:
|
|
|
7
7
|
|
|
8
8
|
| Half | What it does | Entry points |
|
|
9
9
|
| --- | --- | --- |
|
|
10
|
-
| delete | filter by
|
|
10
|
+
| delete | filter by ungrouped / temp / archive / subagent, batch select, per-session guards; removes data from disk | HTTP `/session-admin/api/*`, model tool `session_admin`, right-pane "会话管理" tab, conversation-header trash icon, settings page "会话工具" |
|
|
11
11
|
| move | relocate the log, rewrite `header.cwd`, follow workspace membership; optional memory follow (off by default) | HTTP `/session-move/api/*`, model tool `session_move`, right-pane "会话归位" tab, session context menu |
|
|
12
|
+
| workspace | register an **existing absolute directory** as a workspace (idempotent: an already-registered directory is returned unchanged); never moves a session | HTTP /session-move/api/workspaceCreate, model tool workspace_create, 新建工作区… in the right-pane 会话归位 tab |
|
|
12
13
|
|
|
13
14
|
The session-storage primitives live in this package under `lib/store/` (project-directory key
|
|
14
15
|
codec, `session[.vN].jsonl[.zstd]` frame read/write, workspace registry, `$DSH_HOME` and file
|
|
@@ -49,10 +50,10 @@ The plugin row has one shared `enabled` master switch; every other key is indepe
|
|
|
49
50
|
|
|
50
51
|
| Key | Default | Meaning |
|
|
51
52
|
| --- | --- | --- |
|
|
52
|
-
| `enabled` | `true` | master switch; `false` registers no routes
|
|
53
|
-
| `root` | `''` | session root override; empty
|
|
53
|
+
| `enabled` | `true` | master switch; `false` registers no host routes or tools (the browser half still loads its tabs) |
|
|
54
|
+
| `root` | `''` | session root override; empty reads `sessionPersistence.root` (`$DSH_HOME/sessions` for the jsonl backend) |
|
|
54
55
|
| `adminAllowHosts` | `[]` | delete-half LAN trust list (parsed from the `Host` header) |
|
|
55
|
-
| `moveAllowHosts` | `[]` | move-half LAN trust list (exact
|
|
56
|
+
| `moveAllowHosts` | `[]` | move-half LAN trust list (exact `Host` header match) |
|
|
56
57
|
| `headerDeleteButton` | `true` | conversation-header trash icon (icon + two confirmations) |
|
|
57
58
|
| `allowWorkspaceSessions` | `false` | allow deleting sessions that belong to a workspace |
|
|
58
59
|
| `allowLiveSessions` | `false` | allow deleting sessions still loaded in the host |
|
|
@@ -62,10 +63,11 @@ The plugin row has one shared `enabled` master switch; every other key is indepe
|
|
|
62
63
|
| `memoryFollow` | `off` | project-memory follow: `off` / `copy` / `move` (`move` is irreversible) |
|
|
63
64
|
| `repairForkChildrenOnBoot` | `true` | re-file fork children whose membership was lost, at boot |
|
|
64
65
|
|
|
65
|
-
The two trust keys **cannot** be merged: the delete half
|
|
66
|
-
|
|
67
|
-
socket
|
|
68
|
-
|
|
66
|
+
The two trust keys **cannot** be merged: the delete half decides loopback from the `Host` header and
|
|
67
|
+
matches `adminAllowHosts` as a `host` or `host:port` authority, while the move half decides loopback
|
|
68
|
+
from the socket's `remoteAddress` and matches `moveAllowHosts` against the exact `Host` value. Both
|
|
69
|
+
reject `sec-fetch-site: cross-site` and cross-origin `Origin`; merging them would change one half's
|
|
70
|
+
observable behaviour. Both only affect LAN access, and only loopback is trusted by default.
|
|
69
71
|
|
|
70
72
|
The browser half registers one config card on the Plugins page: slot `plugins.bundle.config`, key =
|
|
71
73
|
the package name `dsh-session-ops`, carrying the seven volatile knobs (4 delete + 3 move). Saving
|
package/README.zh.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# dsh-session-ops
|
|
2
2
|
|
|
3
|
-
DeepSeek Harness(DSH
|
|
3
|
+
DeepSeek Harness(DSH)的会话运维插件:真删除已持久化的会话,把会话搬到另一个工作区,并同步修好工作区成员关系。
|
|
4
4
|
|
|
5
5
|
一个包、一个插件行,包含两个半边:
|
|
6
6
|
|
|
7
7
|
| 半边 | 能力 | 入口 |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| 删除 |
|
|
9
|
+
| 删除 | 按未分组、临时或失效目录、归档、子代理筛选;批量选择;逐条守卫;真删磁盘数据 | HTTP `/session-admin/api/*`、模型工具 `session_admin`、右栏「会话管理」页签、会话标题栏垃圾桶、设置页「会话工具」 |
|
|
10
10
|
| 搬迁 | 搬日志、改写 header 的 `cwd`、跟随工作区成员表;可选项目记忆跟随(默认关) | HTTP `/session-move/api/*`、模型工具 `session_move`、右栏「会话归位」页签、会话右键菜单 |
|
|
11
|
+
| 建工作区 | 把一个**已存在的绝对目录**登记成工作区(已登记则原样返回);只登记,不动任何会话 | HTTP /session-move/api/workspaceCreate、模型工具 workspace_create、右栏「会话归位」页签的「新建工作区…」 |
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
`$DSH_HOME` 与文件日志、HTTP 底座)收在本包的 `lib/store/`,两个半边共用同一份实现。
|
|
13
|
+
会话存储原语收在本包的 `lib/store/`:项目目录键编解码、`session[.vN].jsonl[.zstd]` 帧读写、工作区注册表、`$DSH_HOME` 与文件日志、HTTP 底座。两个半边共用同一份实现。
|
|
14
14
|
|
|
15
15
|
## 安装
|
|
16
16
|
|
|
@@ -18,37 +18,32 @@ DeepSeek Harness(DSH)的**会话运维插件**:真删除会话、把会话
|
|
|
18
18
|
dsh plugin --profile <profile> add dsh-session-ops
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
`cordis.patch.yml` 声明,entry id 是 `session-toolbox`。
|
|
21
|
+
装好后重启宿主,或按 DSH 的热加载规则让 profile 重组。插件行由包内 `cordis.patch.yml` 声明,entry ID 是 `session-toolbox`。
|
|
23
22
|
|
|
24
|
-
##
|
|
23
|
+
## 破坏性删除
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
「删除」是真删除,不是归档。三处数据一起从磁盘移除:
|
|
27
26
|
|
|
28
|
-
- `<DSH_HOME>/sessions/<项目目录键>/<session-id
|
|
29
|
-
- `<DSH_HOME>/storages/session_projcache/sessions/<session-id>.json
|
|
30
|
-
- `<DSH_HOME>/rewind-snapshots/<session-id
|
|
27
|
+
- `<DSH_HOME>/sessions/<项目目录键>/<session-id>/`:会话日志
|
|
28
|
+
- `<DSH_HOME>/storages/session_projcache/sessions/<session-id>.json`:投影缓存
|
|
29
|
+
- `<DSH_HOME>/rewind-snapshots/<session-id>/`:回退快照(若有)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
删除前请自行备份 `$DSH_HOME`;面板提供预演与二次确认,但最终责任在操作者。
|
|
31
|
+
删除后顺手清理因此变空的项目目录。没有回收站,删了无法恢复;删除前请自行备份 `$DSH_HOME`。面板提供预演与二次确认,但最终责任在操作者。
|
|
34
32
|
|
|
35
|
-
默认安全边界(可在配置里改):`allowWorkspaceSessions=false`、`allowLiveSessions=false
|
|
36
|
-
`refuseRunning=true` —— 工作区会话、正在跑的会话、运行中的搬迁默认都被拒绝。
|
|
33
|
+
默认安全边界(可在配置里改):`allowWorkspaceSessions=false`、`allowLiveSessions=false`、`refuseRunning=true`。工作区会话、正在跑的会话、运行中的搬迁默认都被拒绝。
|
|
37
34
|
|
|
38
|
-
搬迁不是删除:日志目录从旧 project 目录整体移到新目录,`header.cwd`
|
|
39
|
-
成员表跟着变;0.2.2+ 内核里 `session.lock` 会一起搬走(inode 不变),目标目录已有
|
|
40
|
-
租约时直接拒绝,不会制造「锁在旧目录、日志在新目录」的半套状态。
|
|
35
|
+
搬迁不是删除:日志目录从旧 project 目录整体移到新目录,`header.cwd` 改写,工作区成员表跟着变。内核 0.2.2+ 的会话目录里有 `session.lock`,搬迁时会一起搬走(inode 不变);目标目录已有租约时直接拒绝,不会留下「锁在旧目录、日志在新目录」的半套状态。
|
|
41
36
|
|
|
42
37
|
## 配置
|
|
43
38
|
|
|
44
|
-
插件行只有一个 `enabled`
|
|
39
|
+
插件行只有一个 `enabled` 总开关,两个半边共用;其余键各自独立:
|
|
45
40
|
|
|
46
41
|
| 键 | 默认 | 作用 |
|
|
47
42
|
| --- | --- | --- |
|
|
48
|
-
| `enabled` | `true` | 总开关;`false`
|
|
49
|
-
| `root` | `''` |
|
|
50
|
-
| `adminAllowHosts` | `[]` | 删除半边的 LAN 信任列表(按 `Host` 头解析 host
|
|
51
|
-
| `moveAllowHosts` | `[]` | 搬迁半边的 LAN 信任列表(按
|
|
43
|
+
| `enabled` | `true` | 总开关;`false` 时宿主不注册路由与工具(浏览器侧页签仍会加载) |
|
|
44
|
+
| `root` | `''` | 会话根目录;空则取 `sessionPersistence.root`(jsonl 后端为 `$DSH_HOME/sessions`) |
|
|
45
|
+
| `adminAllowHosts` | `[]` | 删除半边的 LAN 信任列表(按 `Host` 头解析 `host` 或 `host:port`) |
|
|
46
|
+
| `moveAllowHosts` | `[]` | 搬迁半边的 LAN 信任列表(按 `Host` 头完整值精确匹配) |
|
|
52
47
|
| `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 + 两步确认) |
|
|
53
48
|
| `allowWorkspaceSessions` | `false` | 允许删除已归属工作区的会话 |
|
|
54
49
|
| `allowLiveSessions` | `false` | 允许删除宿主里驻留的会话 |
|
|
@@ -58,36 +53,29 @@ dsh plugin --profile <profile> add dsh-session-ops
|
|
|
58
53
|
| `memoryFollow` | `off` | 项目记忆跟随:`off` / `copy` / `move`(`move` 不可逆) |
|
|
59
54
|
| `repairForkChildrenOnBoot` | `true` | 启动时补挂漏记账的 fork 子会话 |
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
跨源 `Origin`,搬迁半边按 socket 地址精确匹配;合成一个等于放宽其中一边。两者都只
|
|
63
|
-
影响 LAN 访问,loopback 始终被信任。
|
|
56
|
+
两个信任键不能合并:删除半边按 `Host` 头解析回环 authority,`adminAllowHosts` 可写 `host` 或 `host:port`;搬迁半边按 socket 的 `remoteAddress` 判断回环,`moveAllowHosts` 只认 `Host` 头的完整值。两边都拒绝 `sec-fetch-site: cross-site` 与跨源 `Origin`,合并会改掉其中一边的对外行为。两者都只影响 LAN 访问,默认只信回环。
|
|
64
57
|
|
|
65
|
-
浏览器侧还有一处指向本行的配置卡片:槽 `plugins.bundle.config`,key 是包名
|
|
66
|
-
`dsh-session-ops`,7 个 volatile 旋钮(删除 4 + 搬迁 3)保存即写回 profile 的
|
|
67
|
-
`cordis.patch.yml`,无需重启。
|
|
58
|
+
浏览器侧还有一处指向本行的配置卡片:槽 `plugins.bundle.config`,key 是包名 `dsh-session-ops`,含 7 个 volatile 旋钮(删除 4 + 搬迁 3)。保存即写回 profile 的 `cordis.patch.yml`,无需重启宿主。
|
|
68
59
|
|
|
69
60
|
## 兼容区间
|
|
70
61
|
|
|
71
62
|
- Node.js `>=24`
|
|
72
63
|
- DSH `^0.2.1-rc.2 || ^0.2.2-alpha.2`
|
|
73
64
|
|
|
74
|
-
会话右键菜单需要内核提供 `@deepseek-ai/dsh-client-ui-context-menu`(0.2.2
|
|
75
|
-
服务时只少两个菜单项,页签、工具与 HTTP 入口照旧。搬迁时携带 `session.lock`、
|
|
76
|
-
启动期 fork 子会话补记账同样以 0.2.2+ 的持久化实现为准。
|
|
65
|
+
会话右键菜单需要内核提供 `@deepseek-ai/dsh-client-ui-context-menu`(0.2.2+)。没有这个服务时只少两个菜单项,页签、工具与 HTTP 入口照旧。搬迁时携带 `session.lock`、启动期 fork 子会话补记账,同样以 0.2.2+ 的持久化实现为准。
|
|
77
66
|
|
|
78
67
|
## 排障产物
|
|
79
68
|
|
|
80
69
|
两份文件日志保留各自原有的行格式(历史产物,刻意不统一):
|
|
81
70
|
|
|
82
|
-
- `$DSH_HOME/logs/dsh-session-admin.log
|
|
83
|
-
- `$DSH_HOME/logs/dsh-session-move.log
|
|
71
|
+
- `$DSH_HOME/logs/dsh-session-admin.log`:`[时间] 级别 正文`
|
|
72
|
+
- `$DSH_HOME/logs/dsh-session-move.log`:`时间 [级别] 正文`
|
|
84
73
|
|
|
85
|
-
搬迁与自愈的关键行:`membership repair mounted`、`membership: attached fork child
|
|
86
|
-
`membership: attach failed …`、`membership sweep: re-attached N of M fork child(ren) …`。
|
|
74
|
+
搬迁与自愈的关键行:`membership repair mounted`、`membership: attached fork child …`、`membership: attach failed …`、`membership sweep: re-attached N of M fork child(ren) …`。
|
|
87
75
|
|
|
88
76
|
## 作为库使用
|
|
89
77
|
|
|
90
|
-
`lib/store/`
|
|
78
|
+
`lib/store/` 与插件生命周期无关,零 `@deepseek-ai/*` 依赖,可以单独引用。包里提供两种入口:
|
|
91
79
|
|
|
92
80
|
```js
|
|
93
81
|
// 根入口(与合并前的会话存储共享库公开面一致)
|
|
@@ -105,10 +93,7 @@ npm run build # 宿主 tsc(src/ -> lib/、lib/types/)、浏览器 tsc(
|
|
|
105
93
|
npm test # 先 build,再用 node --test 跑 test/**/*.test.ts(Node ≥24 原生执行 TS)
|
|
106
94
|
```
|
|
107
95
|
|
|
108
|
-
|
|
109
|
-
`window.__ModuleLoader__` 用的经典脚本 IIFE,按单文件发射、不打包)。
|
|
110
|
-
`lib/**/*.js` 与 `lib/types/` 是随仓库入库的构建产物(checkout / profile 安装不先 build 也能用);
|
|
111
|
-
`test/*.ts` 由 Node 直接执行,不参与发射。
|
|
96
|
+
手写代码全部是 TypeScript:宿主在 `src/`,浏览器半边在 `client/`(给 `window.__ModuleLoader__` 用的经典脚本 IIFE,按单文件发射、不打包)。`lib/**/*.js` 与 `lib/types/` 是随仓库入库的构建产物,checkout 或 profile 安装不先 build 也能用;`test/*.ts` 由 Node 直接执行,不参与发射。
|
|
112
97
|
|
|
113
98
|
## License
|
|
114
99
|
|
package/cordis.patch.yml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# 合并包:一个插件行同时提供原先两个插件的能力。
|
|
4
4
|
# - 删除(原 dsh-session-admin):HTTP /session-admin/api,模型工具 session_admin,
|
|
5
|
-
#
|
|
5
|
+
# 右栏「会话管理」页签,会话标题栏垃圾桶图标,设置页「会话工具」卡片。
|
|
6
6
|
# - 搬迁(原 dsh-session-move):HTTP /session-move/api,模型工具 session_move,
|
|
7
7
|
# 右栏「会话归位」页签(含左栏底部入口)。
|
|
8
8
|
# 两个半边共用本行的这一份配置;插件页上本行的「配置」卡片就是合并后的那张(7 个旋钮)。
|
package/docs/DETAIL.md
CHANGED
|
@@ -4,19 +4,22 @@ Turns the session-to-workspace binding into an explicit tool: really delete sess
|
|
|
4
4
|
between workspaces while keeping the registry consistent.
|
|
5
5
|
|
|
6
6
|
## Two right-pane tabs
|
|
7
|
-
- Delete: filter by
|
|
7
|
+
- Delete: filter by ungrouped, temp, archived or subagent; batch select; running sessions refused by default.
|
|
8
8
|
- Move: relocate the log, rewrite header cwd, follow workspace membership; optional memory follow (off).
|
|
9
9
|
|
|
10
10
|
## Other entry points
|
|
11
11
|
- Session context menu: move / delete.
|
|
12
|
-
-
|
|
12
|
+
- 新建工作区… in the Move tab: pick an existing directory, register it as a workspace and select it as the move target.
|
|
13
|
+
- Model tools session_admin, session_move, workspace_create; host HTTP /session-admin/api, /session-move/api (including workspaceCreate).
|
|
13
14
|
|
|
14
|
-
## Shared storage primitives
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- `
|
|
18
|
-
- `
|
|
19
|
-
- `
|
|
15
|
+
## Shared storage primitives
|
|
16
|
+
|
|
17
|
+
Sources live in `src/store/*.ts` and are built to `lib/store/*.js`:
|
|
18
|
+
- `paths.ts`: project-directory key codec (`projectKey` / `encodeSegment`), session and generation file naming.
|
|
19
|
+
- `frames.ts`: `session[.vN].jsonl[.zstd]` frame scanning, header read (two strictness levels), cwd rewrite.
|
|
20
|
+
- `registry.ts`: workspace membership and archive sets, resident sessions, mid-turn detection, write-handle redirection.
|
|
21
|
+
- `host.ts`: `$DSH_HOME`, best-effort file logging, volatile config unwrapping.
|
|
22
|
+
- `http.ts`: shared JSON response / request-body plumbing and the prefixed route skeleton.
|
|
20
23
|
|
|
21
24
|
## Notes
|
|
22
25
|
- A move carries session.lock (0.2.2+ write lease) and empties the source directory; it refuses when the target already holds a lease.
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
# 会话运维
|
|
2
2
|
|
|
3
|
-
把 DSH 的「会话 →
|
|
3
|
+
把 DSH 的「会话 → 工作区」绑定关系做成可操作的工具:真删除会话、把会话搬到另一个工作区,并修好成员关系。
|
|
4
4
|
|
|
5
5
|
## 两个页签
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
- 删除:按未分组、临时或失效目录、归档、子代理筛选,支持批量选择;运行中的会话默认拒绝。
|
|
8
|
+
- 搬迁:列出会话与归属,选择目标工作区后搬日志、改 header 的 `cwd`、跟随注册表成员;支持项目记忆跟随(默认关)。
|
|
8
9
|
|
|
9
10
|
## 其他入口
|
|
10
|
-
- 会话右键菜单:移动会话到工作区…、删除会话…
|
|
11
|
-
- 模型工具 session_admin、session_move;宿主 HTTP /session-admin/api、/session-move/api。
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
- 会话右键菜单:移动会话到工作区…、删除会话…
|
|
13
|
+
- 「会话归位」页签的「新建工作区…」:选一个已存在的目录,登记成工作区并直接选为搬迁目标。
|
|
14
|
+
- 模型工具 session_admin、session_move、workspace_create;宿主 HTTP /session-admin/api、/session-move/api(含 workspaceCreate)。
|
|
15
|
+
|
|
16
|
+
## 共享存储原语
|
|
17
|
+
|
|
18
|
+
源码在 `src/store/*.ts`,构建后是 `lib/store/*.js`:
|
|
19
|
+
|
|
20
|
+
- `paths.ts`:项目目录 key 编解码(`projectKey` / `encodeSegment`)、会话目录与 generation 文件名规则。
|
|
21
|
+
- `frames.ts`:`session[.vN].jsonl[.zstd]` 帧扫描、header 读取(两种严格度)、cwd 改写。
|
|
22
|
+
- `registry.ts`:工作区成员表与归档集合、驻留会话、「正在跑一轮」判定、写入句柄重定向。
|
|
23
|
+
- `host.ts`:`$DSH_HOME`、尽力而为的文件日志、volatile 配置解包。
|
|
24
|
+
- `http.ts`:JSON 响应与请求体读取底座、前缀路由骨架。
|
|
19
25
|
|
|
20
26
|
## 注意
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
|
|
28
|
+
- 搬迁会把 `session.lock` 一起搬走(内核 0.2.2+ 写租约),源目录清空;目标已有租约时拒绝。
|
|
29
|
+
- 启动时会做一次 fork 子会话的定向补记账(`repairForkChildrenOnBoot`,默认开)。
|
|
30
|
+
- 删除是永久性的:没有回收站、无法恢复;操作前请备份 `$DSH_HOME`。
|
package/lib/client.js
CHANGED
|
@@ -1410,10 +1410,13 @@
|
|
|
1410
1410
|
* 拖放面板。
|
|
1411
1411
|
* @param React - 外壳预置的 React。
|
|
1412
1412
|
* @param api - Host API 客户端。
|
|
1413
|
+
* @param workspaceTools - `{ pickDirectory, createWorkspaceAt }`:内核目录选择器与
|
|
1414
|
+
* 工作区登记(客户端服务优先,回落 Host 路由)。
|
|
1413
1415
|
* @returns 面板组件。
|
|
1414
1416
|
*/
|
|
1415
|
-
function createPanel(React, api) {
|
|
1417
|
+
function createPanel(React, api, workspaceTools) {
|
|
1416
1418
|
const h = React.createElement;
|
|
1419
|
+
const { pickDirectory, createWorkspaceAt } = workspaceTools;
|
|
1417
1420
|
return function SessionMovePanel(props) {
|
|
1418
1421
|
const fill = props.fill === true;
|
|
1419
1422
|
const useSessions = props.useSessions;
|
|
@@ -1429,6 +1432,7 @@
|
|
|
1429
1432
|
const [hover, setHover] = React.useState('');
|
|
1430
1433
|
const [outcome, setOutcome] = React.useState(null);
|
|
1431
1434
|
const [token, setToken] = React.useState(0);
|
|
1435
|
+
const [creating, setCreating] = React.useState(false);
|
|
1432
1436
|
// 右键菜单的一次性交接:面板一直开着时靠订阅推过来;这次才挂载时,初始版本号
|
|
1433
1437
|
// 会让下面的 effect 在挂载后立刻把槽里的请求取走。
|
|
1434
1438
|
const [requestVersion, setRequestVersion] = React.useState(moveRequest.version);
|
|
@@ -1518,6 +1522,35 @@
|
|
|
1518
1522
|
(busy ? ' 处理中…' : '')));
|
|
1519
1523
|
if (failure !== null)
|
|
1520
1524
|
children.push(h('div', { key: 'fail', style: S.bad }, `读取失败:${failure}`));
|
|
1525
|
+
/**
|
|
1526
|
+
* 把一个已存在的目录登记成工作区,并直接选为搬迁目标。
|
|
1527
|
+
*
|
|
1528
|
+
* 目录由内核的原生选择器挑(`uiWorkspace.pickDirectory()`);登记优先走外壳自己的
|
|
1529
|
+
* 客户端服务 `ctx.workspaces.create({ path })`——与内核「添加工作区」同一个 remote
|
|
1530
|
+
* 方法,页面刷新即生效;外壳没提供这个服务时回落到 Host 的
|
|
1531
|
+
* `/session-move/api/workspaceCreate`(与模型工具 `workspace_create` 同一份实现)。
|
|
1532
|
+
*/
|
|
1533
|
+
const createWorkspace = () => {
|
|
1534
|
+
if (creating)
|
|
1535
|
+
return;
|
|
1536
|
+
setCreating(true);
|
|
1537
|
+
setOutcome(null);
|
|
1538
|
+
Promise.resolve()
|
|
1539
|
+
.then(() => pickDirectory())
|
|
1540
|
+
.then((path) => {
|
|
1541
|
+
if (typeof path !== 'string' || path.length === 0)
|
|
1542
|
+
return undefined;
|
|
1543
|
+
return createWorkspaceAt(path);
|
|
1544
|
+
})
|
|
1545
|
+
.then((workspace) => {
|
|
1546
|
+
if (workspace === undefined || workspace === null)
|
|
1547
|
+
return;
|
|
1548
|
+
setTargetPick(String(workspace.id));
|
|
1549
|
+
setToken((current) => current + 1);
|
|
1550
|
+
setOutcome({ ok: true, created: true, report: { workspace } });
|
|
1551
|
+
}, (error) => setOutcome({ ok: false, error: String(error?.message ?? error) }))
|
|
1552
|
+
.then(() => setCreating(false));
|
|
1553
|
+
};
|
|
1521
1554
|
children.push(h('div', { key: 'bar', style: S.bar }, [
|
|
1522
1555
|
h('input', {
|
|
1523
1556
|
key: 'q',
|
|
@@ -1528,6 +1561,14 @@
|
|
|
1528
1561
|
onChange: (event) => setFilter(event.target.value),
|
|
1529
1562
|
}),
|
|
1530
1563
|
h('button', { key: 'r', type: 'button', style: busy ? { ...S.button, ...S.disabled } : S.button, disabled: busy, onClick: () => setToken((current) => current + 1) }, '刷新'),
|
|
1564
|
+
h('button', {
|
|
1565
|
+
key: 'nw',
|
|
1566
|
+
type: 'button',
|
|
1567
|
+
style: creating ? { ...S.button, ...S.disabled } : S.button,
|
|
1568
|
+
disabled: creating,
|
|
1569
|
+
onClick: createWorkspace,
|
|
1570
|
+
title: '把一个已存在的目录登记成工作区,并选为搬迁目标',
|
|
1571
|
+
}, creating ? '新建中…' : '新建工作区…'),
|
|
1531
1572
|
]));
|
|
1532
1573
|
const sessionOptions = [h('option', { key: 'none', value: '' }, '(未选中)')];
|
|
1533
1574
|
for (const row of rows) {
|
|
@@ -1670,7 +1711,9 @@
|
|
|
1670
1711
|
const ok = outcome.ok === true;
|
|
1671
1712
|
children.push(h('div', { key: 'out', style: S.result }, [
|
|
1672
1713
|
h('div', { key: 's', style: ok ? S.good : S.bad }, ok
|
|
1673
|
-
?
|
|
1714
|
+
? (outcome.created === true
|
|
1715
|
+
? `✔ 已登记工作区「${outcome.report?.workspace?.title ?? ''}」`
|
|
1716
|
+
: `${outcome.dryRun === true ? '✔ 预演完成' : '✔ 已搬迁'}${outcome.report?.noop === true ? '(无需搬迁)' : ''}`)
|
|
1674
1717
|
: `✘ ${String(outcome.error)}`),
|
|
1675
1718
|
h('pre', { key: 'd', style: S.pre }, JSON.stringify(outcome.report ?? outcome, null, 2)),
|
|
1676
1719
|
]));
|
|
@@ -1691,7 +1734,41 @@
|
|
|
1691
1734
|
const React = require('react');
|
|
1692
1735
|
function apply(ctx) {
|
|
1693
1736
|
const api = createApi();
|
|
1694
|
-
|
|
1737
|
+
// 目录选择器(内核服务,可选注入):面板里「新建工作区…」用它挑目录。
|
|
1738
|
+
let uiWorkspaceService;
|
|
1739
|
+
ctx.inject(['uiWorkspace'], (injected) => {
|
|
1740
|
+
uiWorkspaceService = injected.get('uiWorkspace');
|
|
1741
|
+
return () => {
|
|
1742
|
+
uiWorkspaceService = undefined;
|
|
1743
|
+
};
|
|
1744
|
+
});
|
|
1745
|
+
const pickDirectory = async () => {
|
|
1746
|
+
const service = uiWorkspaceService;
|
|
1747
|
+
if (service === undefined || typeof service.pickDirectory !== 'function')
|
|
1748
|
+
throw new Error('当前外壳没有提供目录选择器(uiWorkspace.pickDirectory)');
|
|
1749
|
+
return await service.pickDirectory();
|
|
1750
|
+
};
|
|
1751
|
+
/**
|
|
1752
|
+
* 登记工作区:优先客户端服务(页面刷新即生效),回落 Host 路由。
|
|
1753
|
+
* 两条路都返回 `{ id, title, path }`。
|
|
1754
|
+
*/
|
|
1755
|
+
const createWorkspaceAt = async (path) => {
|
|
1756
|
+
const spaces = ctx.workspaces;
|
|
1757
|
+
if (spaces !== undefined && typeof spaces.create === 'function') {
|
|
1758
|
+
const workspace = await spaces.create({ path });
|
|
1759
|
+
return {
|
|
1760
|
+
id: String(workspace?.workspaceId ?? workspace?.id ?? ''),
|
|
1761
|
+
title: String(workspace?.title ?? ''),
|
|
1762
|
+
path: String(workspace?.path ?? path),
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
const value = await api.call('workspaceCreate', { path });
|
|
1766
|
+
const workspace = value !== null && typeof value === 'object' ? value.workspace : undefined;
|
|
1767
|
+
if (workspace === undefined || workspace === null)
|
|
1768
|
+
throw new Error('Host 没有返回工作区记录');
|
|
1769
|
+
return workspace;
|
|
1770
|
+
};
|
|
1771
|
+
const Panel = createPanel(React, api, { pickDirectory, createWorkspaceAt });
|
|
1695
1772
|
// 右侧面板服务:右键菜单要借它把搬迁页签打开(与删除半边同一套可选注入)。
|
|
1696
1773
|
let sidebarRight;
|
|
1697
1774
|
ctx.inject(['sidebarRight'], (injected) => {
|
package/lib/move.js
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { statSync } from 'node:fs';
|
|
29
29
|
import { realpath } from 'node:fs/promises';
|
|
30
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
30
31
|
import { createApiHandler, readJsonBody } from './store/http.js';
|
|
31
32
|
import { dshHome } from './store/host.js';
|
|
32
33
|
import { SESSION_RUNNING_STATUS, accountedSessionIds, agentSessionStatus, archivedSessionIds, findWorkspace, redirectSessionWriters, residentSessionIds, sessionWriteHandles, workspaceOwningSession, } from './store/registry.js';
|
|
@@ -526,6 +527,126 @@ function buildTool(mover, config, log) {
|
|
|
526
527
|
},
|
|
527
528
|
};
|
|
528
529
|
}
|
|
530
|
+
/**
|
|
531
|
+
* 工作区实体的对外投影。
|
|
532
|
+
* @param workspace - 注册表实体。
|
|
533
|
+
* @returns 纯数据行。
|
|
534
|
+
*/
|
|
535
|
+
function workspaceRow(workspace) {
|
|
536
|
+
return {
|
|
537
|
+
id: String(workspace.id),
|
|
538
|
+
title: String(workspace.title),
|
|
539
|
+
path: String(workspace.path),
|
|
540
|
+
sessions: Array.isArray(workspace.sessionIds) ? workspace.sessionIds.length : 0,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 把一个**已存在的绝对目录**登记成工作区;已经登记过时原样返回那条记录。
|
|
545
|
+
*
|
|
546
|
+
* 与内核 `workspace/create` remote 方法同一套语义(`resolveByPath` → `create`),
|
|
547
|
+
* 只是 Host 侧直接调注册表服务,不经过页面:于是模型工具与右栏面板的「新建工作区…」
|
|
548
|
+
* 共用这一份实现。
|
|
549
|
+
*
|
|
550
|
+
* 拒绝的输入(与内核一致):相对路径、盘符相对路径(`C:foo`)、不存在的路径、文件。
|
|
551
|
+
*
|
|
552
|
+
* @param ctx - Host 上下文(需要 `workspaceRegistry`)。
|
|
553
|
+
* @param payload - `{ path, title? }`。
|
|
554
|
+
* @returns `{ created, workspace }`。
|
|
555
|
+
*/
|
|
556
|
+
export async function createOrResolveWorkspace(ctx, payload) {
|
|
557
|
+
const registry = ctx.workspaceRegistry;
|
|
558
|
+
if (registry === undefined || typeof registry.create !== 'function') {
|
|
559
|
+
throw new Error('Host 没有提供 workspaceRegistry.create,无法新建工作区');
|
|
560
|
+
}
|
|
561
|
+
const raw = typeof payload?.path === 'string' ? payload.path.trim() : '';
|
|
562
|
+
if (raw.length === 0)
|
|
563
|
+
throw new Error('缺少目录路径(path)');
|
|
564
|
+
if (!isAbsolute(raw))
|
|
565
|
+
throw new Error(`不是绝对路径:${raw}`);
|
|
566
|
+
const absolute = resolve(raw);
|
|
567
|
+
let stats;
|
|
568
|
+
try {
|
|
569
|
+
stats = statSync(absolute);
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
throw new Error(`目录不存在:${absolute}`);
|
|
573
|
+
}
|
|
574
|
+
if (!stats.isDirectory())
|
|
575
|
+
throw new Error(`不是目录:${absolute}`);
|
|
576
|
+
if (typeof registry.resolveByPath === 'function') {
|
|
577
|
+
const existing = await registry.resolveByPath(absolute);
|
|
578
|
+
if (existing !== undefined && existing !== null) {
|
|
579
|
+
return { created: false, workspace: workspaceRow(existing) };
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const title = typeof payload?.title === 'string' && payload.title.trim().length > 0
|
|
583
|
+
? payload.title.trim()
|
|
584
|
+
: undefined;
|
|
585
|
+
const workspace = title === undefined ? await registry.create(absolute) : await registry.create(absolute, title);
|
|
586
|
+
return { created: true, workspace: workspaceRow(workspace) };
|
|
587
|
+
}
|
|
588
|
+
/** `workspace_create` 的输入 schema(真 JSON Schema,同 `session_move`)。 */
|
|
589
|
+
const WORKSPACE_TOOL_PARAMETERS = {
|
|
590
|
+
type: 'object',
|
|
591
|
+
additionalProperties: true,
|
|
592
|
+
properties: {
|
|
593
|
+
path: { type: 'string', description: '要登记为工作区的绝对目录路径(必须已存在;相对路径、不存在的路径、文件都会被拒绝)。' },
|
|
594
|
+
title: { type: 'string', description: '可选显示名;省略时内核用目录名。' },
|
|
595
|
+
},
|
|
596
|
+
required: ['path'],
|
|
597
|
+
};
|
|
598
|
+
/** `workspace_create` 的输出 schema。 */
|
|
599
|
+
const WORKSPACE_TOOL_OUTPUT = {
|
|
600
|
+
type: 'object',
|
|
601
|
+
additionalProperties: true,
|
|
602
|
+
required: ['ok', 'summary'],
|
|
603
|
+
properties: {
|
|
604
|
+
ok: { type: 'boolean', description: '调用本身是否成功。' },
|
|
605
|
+
summary: { type: 'string', description: '一句话结论。' },
|
|
606
|
+
created: { type: 'boolean', description: 'true = 新建;false = 该目录已有工作区,原样返回。' },
|
|
607
|
+
workspace: { type: 'object', additionalProperties: true, description: '工作区行(id / title / path / sessions)。' },
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
/** `workspace_create` 的注册体。 */
|
|
611
|
+
function buildWorkspaceTool(ctx, log) {
|
|
612
|
+
return {
|
|
613
|
+
name: 'workspace_create',
|
|
614
|
+
description: 'Register (or idempotently resolve) a DSH workspace over an existing absolute directory. ' +
|
|
615
|
+
'A workspace is the sidebar group that owns sessions; creating one never moves or touches any session. ' +
|
|
616
|
+
'Use it when a directory should become a workspace (for example before session_move files sessions into it), ' +
|
|
617
|
+
'then call session_move with action="move" and targetWorkspace set to the returned id or path. ' +
|
|
618
|
+
'An absolute path is required; relative paths, drive-relative paths (C:foo), missing paths and files are refused.',
|
|
619
|
+
parameters: WORKSPACE_TOOL_PARAMETERS,
|
|
620
|
+
output: {
|
|
621
|
+
schema: WORKSPACE_TOOL_OUTPUT,
|
|
622
|
+
render: (_args, value) => [{ type: 'text', text: value.summary }],
|
|
623
|
+
},
|
|
624
|
+
presentCall: (args) => ({
|
|
625
|
+
card: 'generic',
|
|
626
|
+
title: 'Create workspace',
|
|
627
|
+
kind: 'other',
|
|
628
|
+
rawInput: { path: args.path, title: args.title },
|
|
629
|
+
}),
|
|
630
|
+
async execute(args) {
|
|
631
|
+
try {
|
|
632
|
+
const result = await createOrResolveWorkspace(ctx, args);
|
|
633
|
+
const workspace = result.workspace;
|
|
634
|
+
log('info', `workspace_create: ${result.created ? 'created' : 'resolved'} ${workspace.id} path=${workspace.path}`);
|
|
635
|
+
return {
|
|
636
|
+
ok: true,
|
|
637
|
+
created: result.created,
|
|
638
|
+
workspace,
|
|
639
|
+
summary: result.created
|
|
640
|
+
? `Created workspace "${workspace.title}" at ${workspace.path} (id ${workspace.id}).`
|
|
641
|
+
: `Workspace "${workspace.title}" already covers ${workspace.path} (id ${workspace.id}); nothing was created.`,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
return { ok: false, summary: `workspace_create failed: ${messageOf(error)}` };
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
}
|
|
529
650
|
/**
|
|
530
651
|
* 挂载搬迁半边:路由 + 工具。
|
|
531
652
|
*
|
|
@@ -558,6 +679,8 @@ export function mountMove(ctx, config, log) {
|
|
|
558
679
|
list: async () => mover.list(),
|
|
559
680
|
/** 搬一条会话。 */
|
|
560
681
|
move: async (payload) => mover.move(payload),
|
|
682
|
+
/** 登记一个工作区(已登记则原样返回),供面板在没有客户端服务时回落。 */
|
|
683
|
+
workspaceCreate: async (payload) => createOrResolveWorkspace(ctx, payload),
|
|
561
684
|
/** 用 DSH 自己的读取器读回一条会话。 */
|
|
562
685
|
verify: async (payload) => mover.verify(String(payload.sessionId ?? '')),
|
|
563
686
|
/** 能力/诊断。 */
|
|
@@ -593,6 +716,7 @@ export function mountMove(ctx, config, log) {
|
|
|
593
716
|
}),
|
|
594
717
|
}), 'dsh-session-move: api route');
|
|
595
718
|
ctx.effect(() => ctx.tools.register(buildTool(mover, config, log)), 'dsh-session-move: session_move tool');
|
|
719
|
+
ctx.effect(() => ctx.tools.register(buildWorkspaceTool(ctx, log)), 'dsh-session-move: workspace_create tool');
|
|
596
720
|
}
|
|
597
721
|
// ---------------------------------------------------------------------------
|
|
598
722
|
// fork 子会话成员自愈
|
package/lib/types/move.d.ts
CHANGED
|
@@ -198,6 +198,33 @@ export interface MoveContext {
|
|
|
198
198
|
};
|
|
199
199
|
effect: (fn: () => unknown, label?: string) => unknown;
|
|
200
200
|
}
|
|
201
|
+
/** 工作区行(面板与工具共用的纯数据投影)。 */
|
|
202
|
+
export interface WorkspaceRow {
|
|
203
|
+
id: string;
|
|
204
|
+
title: string;
|
|
205
|
+
path: string;
|
|
206
|
+
sessions: number;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 把一个**已存在的绝对目录**登记成工作区;已经登记过时原样返回那条记录。
|
|
210
|
+
*
|
|
211
|
+
* 与内核 `workspace/create` remote 方法同一套语义(`resolveByPath` → `create`),
|
|
212
|
+
* 只是 Host 侧直接调注册表服务,不经过页面:于是模型工具与右栏面板的「新建工作区…」
|
|
213
|
+
* 共用这一份实现。
|
|
214
|
+
*
|
|
215
|
+
* 拒绝的输入(与内核一致):相对路径、盘符相对路径(`C:foo`)、不存在的路径、文件。
|
|
216
|
+
*
|
|
217
|
+
* @param ctx - Host 上下文(需要 `workspaceRegistry`)。
|
|
218
|
+
* @param payload - `{ path, title? }`。
|
|
219
|
+
* @returns `{ created, workspace }`。
|
|
220
|
+
*/
|
|
221
|
+
export declare function createOrResolveWorkspace(ctx: MoveContext, payload: {
|
|
222
|
+
path?: unknown;
|
|
223
|
+
title?: unknown;
|
|
224
|
+
} | undefined): Promise<{
|
|
225
|
+
created: boolean;
|
|
226
|
+
workspace: WorkspaceRow;
|
|
227
|
+
}>;
|
|
201
228
|
/**
|
|
202
229
|
* 挂载搬迁半边:路由 + 工具。
|
|
203
230
|
*
|
|
@@ -68,6 +68,17 @@ export interface WorkspaceRegistryLike {
|
|
|
68
68
|
headers?: Map<string, Record<string, unknown>> | undefined;
|
|
69
69
|
unarchiveSession(sessionId: string): Promise<unknown>;
|
|
70
70
|
unpinSession(sessionId: string): Promise<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* 把一个**已存在的绝对目录**登记成工作区;同路径重复调用返回既有实体且不改标题。
|
|
73
|
+
* 内核 `@deepseek-ai/dsh-workspace` 的 `WorkspaceRegistry.create`。可选:取值时
|
|
74
|
+
* `typeof === 'function'` 判断,缺这个能力时 `workspace_create` 直接报错而不是崩。
|
|
75
|
+
*/
|
|
76
|
+
create?: (path: string, title?: string) => Promise<WorkspaceEntity>;
|
|
77
|
+
/**
|
|
78
|
+
* 按规范化(`realpath`)路径解析已有工作区;目录存在但没登记时返回 `undefined`,
|
|
79
|
+
* 路径不存在时 reject。内核的 `WorkspaceRegistry.resolveByPath`。
|
|
80
|
+
*/
|
|
81
|
+
resolveByPath?: (path: string) => Promise<WorkspaceEntity | undefined>;
|
|
71
82
|
}
|
|
72
83
|
/** 持久化写入句柄(`persistence.tracker.writers` 的值)。 */
|
|
73
84
|
export interface SessionWriteHandle {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-ops",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"description": "Session operations for DeepSeek Harness: really delete persisted sessions (
|
|
8
|
+
"description": "Session operations for DeepSeek Harness: really delete persisted sessions (ungrouped/temp/archive/subagent filters, running-session guards) and move sessions between workspaces (log relocation, header.cwd rewrite, workspace registry follow). Ships the shared session-store primitives (project-directory keys, jsonl.zstd frames, workspace registry, host/HTTP plumbing) as lib/store. One host entry with two HTTP prefixes and two model tools, one browser bundle with two right-pane tabs and a merged config card.",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"dsh",
|
|
11
11
|
"dsh-plugin",
|