@xrn1997/dsh-session-delete 0.6.1 → 0.8.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 +18 -10
- package/THIRD_PARTY_NOTICES.md +179 -0
- package/cordis.patch.yml +1 -1
- package/docs/screenshots/screenshot-01.png +0 -0
- package/docs/screenshots/screenshot-02.png +0 -0
- package/docs/screenshots/screenshot-03.png +0 -0
- package/icon.svg +24 -18
- package/lib/client.js +3117 -1324
- package/lib/index.js +593 -254
- package/lib/types/api/attachment.d.ts +2 -2
- package/lib/types/api/connection-route.d.ts +1 -1
- package/lib/types/api/dispatch.d.ts +1 -1
- package/lib/types/api/route-table.d.ts +14 -9
- package/lib/types/client/batch-bar.d.ts +2 -4
- package/lib/types/client/batch-confirm.d.ts +6 -7
- package/lib/types/client/busy-gate.d.ts +12 -5
- package/lib/types/client/config-settings.d.ts +13 -0
- package/lib/types/client/confirm-dialog.d.ts +23 -0
- package/lib/types/client/context-menu-actions.d.ts +11 -5
- package/lib/types/client/context.d.ts +3 -0
- package/lib/types/client/copy.d.ts +46 -7
- package/lib/types/client/delete-confirm.d.ts +2 -2
- package/lib/types/client/delete-menu-item.d.ts +2 -2
- package/lib/types/client/detail-blocks.d.ts +25 -0
- package/lib/types/client/index.d.ts +3 -2
- package/lib/types/client/maintenance-settings.d.ts +6 -7
- package/lib/types/client/plugin.d.ts +6 -0
- package/lib/types/client/prompt-rail.d.ts +22 -0
- package/lib/types/client/remote.d.ts +64 -87
- package/lib/types/client/reset-client-state.d.ts +1 -0
- package/lib/types/client/session-live.d.ts +31 -0
- package/lib/types/client/settings-cards.d.ts +19 -0
- package/lib/types/client/settings-view.d.ts +9 -0
- package/lib/types/client/trash-detail.d.ts +14 -4
- package/lib/types/client/trash-snapshot.d.ts +51 -0
- package/lib/types/client/trash-view.d.ts +33 -6
- package/lib/types/client/ui/icons.d.ts +23 -7
- package/lib/types/client/ui/recipe.d.ts +2 -0
- package/lib/types/client/ui/styles.d.ts +2 -0
- package/lib/types/client/undo-notices.d.ts +4 -4
- package/lib/types/client/undo-toast.d.ts +1 -2
- package/lib/types/client/use-detail-pager.d.ts +37 -0
- package/lib/types/client/use-maintenance-section.d.ts +29 -18
- package/lib/types/client/use-maintenance.d.ts +14 -5
- package/lib/types/client/use-prefetch.d.ts +14 -0
- package/lib/types/client/use-prompt-rail.d.ts +60 -0
- package/lib/types/client/use-trash-detail-reader.d.ts +33 -0
- package/lib/types/client/use-trash-panel-controller.d.ts +6 -4
- package/lib/types/client/use-trash-query.d.ts +14 -7
- package/lib/types/client/write-seats.d.ts +17 -17
- package/lib/types/client/write-settlement.d.ts +3 -3
- package/lib/types/client/write.d.ts +9 -7
- package/lib/types/config.d.ts +10 -11
- package/lib/types/deps.d.ts +11 -3
- package/lib/types/index.d.ts +3 -1
- package/lib/types/log/session-log.d.ts +2 -0
- package/lib/types/ports/agent-handles.d.ts +10 -2
- package/lib/types/ports/fs-port.d.ts +23 -2
- package/lib/types/ports/host-port.d.ts +18 -10
- package/lib/types/shared/project-key.d.ts +28 -0
- package/lib/types/shared/wire.d.ts +92 -24
- package/lib/types/trash/attachments.d.ts +3 -3
- package/lib/types/trash/detail.d.ts +4 -2
- package/lib/types/trash/display-name.d.ts +16 -0
- package/lib/types/trash/entry.d.ts +4 -2
- package/lib/types/verbs/config.d.ts +25 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +6 -6
- package/package.json +20 -14
package/lib/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import path, { join, resolve } from "node:path";
|
|
2
1
|
import { mkdir, readFile, readdir, realpath, rename, rm, stat } from "node:fs/promises";
|
|
2
|
+
import path, { join, resolve } from "node:path";
|
|
3
3
|
import zlib from "node:zlib";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
//#region src/shared/wire.ts
|
|
6
6
|
/**
|
|
7
|
-
* 跨半 wire
|
|
7
|
+
* 跨半 wire 契约:前缀、十个端点、请求/响应形状与失败码。
|
|
8
8
|
* Node 半(src/api/dispatch.ts)与浏览器半(src/client/remote.ts)共用这一份,不各写字面量。
|
|
9
9
|
*
|
|
10
10
|
* 构建约束:本文件零运行时依赖、无 import;浏览器半把整个文件 inline 进 bundle。
|
|
11
11
|
* 信封 {ok:true,value} / {ok:false,error:{code,message,details?}} 也是两半的共同契约。
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* 插件专属前缀(十段相对它命名)。
|
|
15
15
|
*
|
|
16
16
|
* 为什么必须带插件名:宿主 `connection.fetch.register` 对**重复的精确路径**直接抛错
|
|
17
17
|
* (`connection: exact Fetch route "…" is already registered`),撞了就是整棵插件树 boot 失败——
|
|
@@ -19,14 +19,14 @@ import { homedir } from "node:os";
|
|
|
19
19
|
*/
|
|
20
20
|
const SESSION_DELETE_API_PREFIX = "/dsh-session-delete-api";
|
|
21
21
|
/**
|
|
22
|
-
* 唯一的取数基础路径:宿主 `/api` +
|
|
22
|
+
* 唯一的取数基础路径:宿主 `/api` + 插件前缀。十段 exact Fetch 路由、客户端探测与附件 URL
|
|
23
23
|
* 都从它起;`SESSION_DELETE_API_PREFIX` 只作为段名的相对前缀与错误原文。
|
|
24
24
|
*/
|
|
25
25
|
const OFFICIAL_SESSION_DELETE_API_PREFIX = `/api${SESSION_DELETE_API_PREFIX}`;
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
/** 十段段名(相对前缀)。**每项 `{ path, method, body }` 三键**:某段用什么方法、带什么请求体也是线上
|
|
27
|
+
* 形状的一部分(ADR-0003),家就在这一张表——路由记录(`src/api/route-table.ts`)逐行投影
|
|
28
|
+
* (`ROUTES.x.method` / `bodyOf(ROUTES.x)`),浏览器半的取数通道(`src/client/remote.ts`)从同一格
|
|
29
|
+
* 投影路径与方法,两半都不逐段手写一份字面量。
|
|
30
30
|
* 写动作统一走一段 `/apply`:一次 HTTP 带一组 id、逐条回结果;
|
|
31
31
|
* 单条就是长度为 1 的批量,仓里不留第二条执行路径。
|
|
32
32
|
* - `list`:对账并读清单(`session-trash/` 里的目录是准)。
|
|
@@ -36,53 +36,85 @@ const OFFICIAL_SESSION_DELETE_API_PREFIX = `/api${SESSION_DELETE_API_PREFIX}`;
|
|
|
36
36
|
* - `empty`:清空回收站(聚合回执,不按条回)。
|
|
37
37
|
* - `orphans`:无主子会话的扫描报告(纯读)。清理是 `/apply` 的第五个动作,
|
|
38
38
|
* 这一段只负责"有多少、在哪、多大"。
|
|
39
|
-
* - `attachment
|
|
39
|
+
* - `attachment`:附件原始字节(全仓唯一的二进制响应段;按查询串寻址,失败仍回 JSON 信封)。
|
|
40
40
|
* - `attachmentOrphans`:无引用图片对象的扫描报告(纯读;数量/字节 + 供预览的对象清单)。
|
|
41
|
-
* - `attachmentClean`:清掉报告那一刻无引用的图片对象(聚合回执 `AttachmentCleanupWire`)。
|
|
41
|
+
* - `attachmentClean`:清掉报告那一刻无引用的图片对象(聚合回执 `AttachmentCleanupWire`)。
|
|
42
|
+
* - `config`:三只可调项的读/写共用一段——空体读当前值,带字段写回 profile 的 patch 层。 */
|
|
42
43
|
const ROUTES = {
|
|
43
44
|
list: {
|
|
44
45
|
path: "/list",
|
|
45
|
-
method: "GET"
|
|
46
|
+
method: "GET",
|
|
47
|
+
body: "none"
|
|
46
48
|
},
|
|
47
49
|
/** 通道的"在不在"专用:没有入参、没有副作用、没有磁盘读。 */
|
|
48
50
|
ping: {
|
|
49
51
|
path: "/ping",
|
|
50
|
-
method: "GET"
|
|
52
|
+
method: "GET",
|
|
53
|
+
body: "none"
|
|
54
|
+
},
|
|
55
|
+
/** 可调项:空体读(与 `/detail` 同法,用 POST 表达一个读);带字段写,写必须进到达序链。 */
|
|
56
|
+
config: {
|
|
57
|
+
path: "/config",
|
|
58
|
+
method: "POST",
|
|
59
|
+
body: "config"
|
|
51
60
|
},
|
|
52
61
|
/** 单条详情(读回收站目录里那条会话自己的日志)。 */
|
|
53
62
|
detail: {
|
|
54
63
|
path: "/detail",
|
|
55
|
-
method: "POST"
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: "entry"
|
|
56
66
|
},
|
|
57
67
|
/** 一组 id 上的同一个动作;删除确认框那句「含 N 个子会话」也走这里(`action: 'count'`,纯读语义)。 */
|
|
58
68
|
apply: {
|
|
59
69
|
path: "/apply",
|
|
60
|
-
method: "POST"
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: "apply"
|
|
61
72
|
},
|
|
62
73
|
/** 清空回收站。 */
|
|
63
74
|
empty: {
|
|
64
75
|
path: "/empty",
|
|
65
|
-
method: "POST"
|
|
76
|
+
method: "POST",
|
|
77
|
+
body: "none"
|
|
66
78
|
},
|
|
67
79
|
/** 纯读:扫描回收站之外的无主子会话(父已不在语料/清册)。 */
|
|
68
80
|
orphans: {
|
|
69
81
|
path: "/orphans",
|
|
70
|
-
method: "GET"
|
|
82
|
+
method: "GET",
|
|
83
|
+
body: "none"
|
|
71
84
|
},
|
|
72
|
-
/**
|
|
85
|
+
/** 附件字节(图片/普通文件):全仓唯一的二进制响应段,按查询串寻址。 */
|
|
73
86
|
attachment: {
|
|
74
87
|
path: "/attachment",
|
|
75
|
-
method: "GET"
|
|
88
|
+
method: "GET",
|
|
89
|
+
body: "query"
|
|
76
90
|
},
|
|
77
91
|
/** 纯读:扫全部引用源与附件库 `objects`,报无引用图片的数量、字节与预览清单。 */
|
|
78
92
|
attachmentOrphans: {
|
|
79
93
|
path: "/attachment-orphans",
|
|
80
|
-
method: "GET"
|
|
94
|
+
method: "GET",
|
|
95
|
+
body: "none"
|
|
81
96
|
},
|
|
82
97
|
/** 聚合清理:只删 `objects` 下无引用的图片,回 `AttachmentCleanupWire`。 */
|
|
83
98
|
attachmentClean: {
|
|
84
99
|
path: "/attachment-clean",
|
|
85
|
-
method: "POST"
|
|
100
|
+
method: "POST",
|
|
101
|
+
body: "none"
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/** 三只可调项的接受范围(闭区间整数)。Node 半的归一与浏览器半的表单共用这一格:
|
|
105
|
+
* 两处各写一份范围就会「表单说能存、宿主激活时说越界」。 */
|
|
106
|
+
const CONFIG_LIMITS = {
|
|
107
|
+
orphanPreviewLimit: {
|
|
108
|
+
min: 1,
|
|
109
|
+
max: 1e4
|
|
110
|
+
},
|
|
111
|
+
maxAttachmentBytes: {
|
|
112
|
+
min: 1,
|
|
113
|
+
max: 209715200
|
|
114
|
+
},
|
|
115
|
+
maxJsonRefBytes: {
|
|
116
|
+
min: 1,
|
|
117
|
+
max: 104857600
|
|
86
118
|
}
|
|
87
119
|
};
|
|
88
120
|
/** 请求参数名:浏览器半发、Node 半读,同名同义(`empty` 没有入参)。
|
|
@@ -109,8 +141,11 @@ const PARAMS = {
|
|
|
109
141
|
* 位名与判法取自宿主网关客户端面的原文:
|
|
110
142
|
* `if (typeof value === "object" && value !== null && value.isDSHRemoteError === true && typeof value.code === "string") return value`。
|
|
111
143
|
*
|
|
112
|
-
* 线上递过来的是**一段 JSON**(标记位不跟着过线)⇒
|
|
113
|
-
*
|
|
144
|
+
* 线上递过来的是**一段 JSON**(标记位不跟着过线)⇒ 标记位只由**宿主服务抛出的 `RemoteError`** 自带,
|
|
145
|
+
* 本仓生产侧不造它:Node 半的 `toRemoteFailure`(`src/remote/map-error.ts`)只**消费**它,产出的
|
|
146
|
+
* `RemoteFailure` 是普通过线对象;浏览器半的取数通道**不抛失败、也不补标记**——信封原样当数据交回
|
|
147
|
+
* (`RemoteOutcome`),通道自己造的诊断(打不通 / 非信封 / 401·403)是普通失败对象,不进这条判别;
|
|
148
|
+
* 测试假件同样只消费(`tests/client/support/fake-remote.ts` 的 `failureOf`)。
|
|
114
149
|
*/
|
|
115
150
|
function isDSHRemoteError(value) {
|
|
116
151
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -157,6 +192,113 @@ function verbCodeOf(error) {
|
|
|
157
192
|
/** 回收站目录名(相对宿主数据根)。Node 半拼路径,浏览器半在页脚念它——同一个字面量。 */
|
|
158
193
|
const TRASH_DIR_NAME = "session-trash";
|
|
159
194
|
//#endregion
|
|
195
|
+
//#region src/ports/fs-port.ts
|
|
196
|
+
/**
|
|
197
|
+
* **缺席**只认 ENOENT 与 ENOTDIR("路径中间有一截不是目录"与"不存在"是同一种回答)。
|
|
198
|
+
*
|
|
199
|
+
* EACCES / EIO / ELOOP / 断挂载**不是缺席**:这些读数说明"我们看不见",不是"那里没有"。
|
|
200
|
+
* 破坏性动作(删目录、删附件对象、按"没有引用"清共享图)据此做决定,把读不出折成没有
|
|
201
|
+
* 就是数据消失;ADR-0039 是这条判据的裁决。
|
|
202
|
+
*/
|
|
203
|
+
function isAbsentPath(error) {
|
|
204
|
+
const code = error?.code;
|
|
205
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
206
|
+
}
|
|
207
|
+
/** 动词的基础面:读与搬移都有,**不拿删除**。删目录与删单文件只挂在 `RemovalDeps` 上(ADR-0027)。
|
|
208
|
+
* 名单是运行期收窄的**唯一依据**(ADR-0032):`src/api/dispatch.ts` 的 `coreDepsOf` 按它挑方法,
|
|
209
|
+
* 所以「基础面不含删除」既在类型上、也在运行期成立。 */
|
|
210
|
+
const FS_CORE_METHODS = [
|
|
211
|
+
"exists",
|
|
212
|
+
"ensureDir",
|
|
213
|
+
"rename",
|
|
214
|
+
"sizeOfDir",
|
|
215
|
+
"listFiles",
|
|
216
|
+
"listDirs",
|
|
217
|
+
"realpath",
|
|
218
|
+
"readFile",
|
|
219
|
+
"statFile"
|
|
220
|
+
];
|
|
221
|
+
/** 删除能力(目录 / 单文件):只挂在 `RemovalDeps` 与孤儿附件清理段上。 */
|
|
222
|
+
const FS_REMOVAL_METHODS = ["removeDir", "removeFile"];
|
|
223
|
+
/** 按名单从全量端口切一片(复制方法引用;端口方法都是属性、不读 `this`)。
|
|
224
|
+
* **运行期真的只带这些方法**:ADR-0032 的收窄不是类型投影。 */
|
|
225
|
+
function fsSlice(port, keys) {
|
|
226
|
+
return Object.fromEntries(keys.map((key) => [key, port[key]]));
|
|
227
|
+
}
|
|
228
|
+
/** 模块级递归:端口方法**解构出来单独调**也不能靠 `this`(`{ sizeOfDir } = port` 会让方法体的
|
|
229
|
+
* `this` 变成 undefined)。所以端口只做转发,递归在模块作用域里自调。 */
|
|
230
|
+
async function sizeOfDir(p) {
|
|
231
|
+
let total = 0;
|
|
232
|
+
for (const e of await readdir(p, { withFileTypes: true })) {
|
|
233
|
+
const child = join(p, e.name);
|
|
234
|
+
total += e.isDirectory() ? await sizeOfDir(child) : (await stat(child)).size;
|
|
235
|
+
}
|
|
236
|
+
return total;
|
|
237
|
+
}
|
|
238
|
+
/** 路径在不在:只有缺席两种错误回 `false`,其余读错误照抛。`exists` 与 `rename` 的目标检查共用。 */
|
|
239
|
+
async function pathPresent(p) {
|
|
240
|
+
try {
|
|
241
|
+
await stat(p);
|
|
242
|
+
return true;
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (isAbsentPath(error)) return false;
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function createFsPort() {
|
|
249
|
+
return {
|
|
250
|
+
exists: pathPresent,
|
|
251
|
+
async ensureDir(p) {
|
|
252
|
+
await mkdir(p, { recursive: true });
|
|
253
|
+
},
|
|
254
|
+
async rename(from, to) {
|
|
255
|
+
if (await pathPresent(to)) throw new Error(`目标已存在,拒绝覆盖:${to}`);
|
|
256
|
+
try {
|
|
257
|
+
await rename(from, to);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (error.code === "EXDEV") throw new Error(`跨文件系统搬不动(sessions 与 session-trash 需在同一卷):${from} → ${to}`, { cause: error });
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
async removeDir(p) {
|
|
264
|
+
await rm(p, {
|
|
265
|
+
recursive: true,
|
|
266
|
+
force: true
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
sizeOfDir: (p) => sizeOfDir(p),
|
|
270
|
+
async listFiles(p) {
|
|
271
|
+
return readdir(p);
|
|
272
|
+
},
|
|
273
|
+
async listDirs(p) {
|
|
274
|
+
const dirs = [];
|
|
275
|
+
for (const entry of await readdir(p, { withFileTypes: true })) {
|
|
276
|
+
if (entry.isDirectory()) {
|
|
277
|
+
dirs.push(entry.name);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (!entry.isSymbolicLink()) continue;
|
|
281
|
+
try {
|
|
282
|
+
if ((await stat(join(p, entry.name))).isDirectory()) dirs.push(entry.name);
|
|
283
|
+
} catch {}
|
|
284
|
+
}
|
|
285
|
+
return dirs;
|
|
286
|
+
},
|
|
287
|
+
async realpath(p) {
|
|
288
|
+
return realpath(p);
|
|
289
|
+
},
|
|
290
|
+
async readFile(p) {
|
|
291
|
+
return readFile(p);
|
|
292
|
+
},
|
|
293
|
+
async statFile(p) {
|
|
294
|
+
return { size: (await stat(p)).size };
|
|
295
|
+
},
|
|
296
|
+
async removeFile(p) {
|
|
297
|
+
await rm(p, { force: true });
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
160
302
|
//#region src/verbs/errors.ts
|
|
161
303
|
/** 失败的**结构与措辞**。码本身、码的前缀读法与动词词表都住在 `shared/wire.ts`(ADR-0003):
|
|
162
304
|
* 浏览器半也要认它们,它们属于两半共同的契约,不属于 Node 半。这里只做动词抛错与回滚措辞。 */
|
|
@@ -928,92 +1070,6 @@ async function memberMove(deps, presence, member, deletedAt, parentEntryId) {
|
|
|
928
1070
|
};
|
|
929
1071
|
}
|
|
930
1072
|
//#endregion
|
|
931
|
-
//#region src/ports/fs-port.ts
|
|
932
|
-
/**
|
|
933
|
-
* **缺席**只认 ENOENT 与 ENOTDIR("路径中间有一截不是目录"与"不存在"是同一种回答)。
|
|
934
|
-
*
|
|
935
|
-
* EACCES / EIO / ELOOP / 断挂载**不是缺席**:这些读数说明"我们看不见",不是"那里没有"。
|
|
936
|
-
* 破坏性动作(删目录、删附件对象、按"没有引用"清共享图)据此做决定,把读不出折成没有
|
|
937
|
-
* 就是数据消失;ADR-0039 是这条判据的裁决。
|
|
938
|
-
*/
|
|
939
|
-
function isAbsentPath(error) {
|
|
940
|
-
const code = error?.code;
|
|
941
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
942
|
-
}
|
|
943
|
-
/** 模块级递归:端口方法**解构出来单独调**也不能靠 `this`(`{ sizeOfDir } = port` 会让方法体的
|
|
944
|
-
* `this` 变成 undefined)。所以端口只做转发,递归在模块作用域里自调。 */
|
|
945
|
-
async function sizeOfDir(p) {
|
|
946
|
-
let total = 0;
|
|
947
|
-
for (const e of await readdir(p, { withFileTypes: true })) {
|
|
948
|
-
const child = join(p, e.name);
|
|
949
|
-
total += e.isDirectory() ? await sizeOfDir(child) : (await stat(child)).size;
|
|
950
|
-
}
|
|
951
|
-
return total;
|
|
952
|
-
}
|
|
953
|
-
/** 路径在不在:只有缺席两种错误回 `false`,其余读错误照抛。`exists` 与 `rename` 的目标检查共用。 */
|
|
954
|
-
async function pathPresent(p) {
|
|
955
|
-
try {
|
|
956
|
-
await stat(p);
|
|
957
|
-
return true;
|
|
958
|
-
} catch (error) {
|
|
959
|
-
if (isAbsentPath(error)) return false;
|
|
960
|
-
throw error;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
function createFsPort() {
|
|
964
|
-
return {
|
|
965
|
-
exists: pathPresent,
|
|
966
|
-
async ensureDir(p) {
|
|
967
|
-
await mkdir(p, { recursive: true });
|
|
968
|
-
},
|
|
969
|
-
async rename(from, to) {
|
|
970
|
-
if (await pathPresent(to)) throw new Error(`目标已存在,拒绝覆盖:${to}`);
|
|
971
|
-
try {
|
|
972
|
-
await rename(from, to);
|
|
973
|
-
} catch (error) {
|
|
974
|
-
if (error.code === "EXDEV") throw new Error(`跨文件系统搬不动(sessions 与 session-trash 需在同一卷):${from} → ${to}`, { cause: error });
|
|
975
|
-
throw error;
|
|
976
|
-
}
|
|
977
|
-
},
|
|
978
|
-
async removeDir(p) {
|
|
979
|
-
await rm(p, {
|
|
980
|
-
recursive: true,
|
|
981
|
-
force: true
|
|
982
|
-
});
|
|
983
|
-
},
|
|
984
|
-
sizeOfDir: (p) => sizeOfDir(p),
|
|
985
|
-
async listFiles(p) {
|
|
986
|
-
return readdir(p);
|
|
987
|
-
},
|
|
988
|
-
async listDirs(p) {
|
|
989
|
-
const dirs = [];
|
|
990
|
-
for (const entry of await readdir(p, { withFileTypes: true })) {
|
|
991
|
-
if (entry.isDirectory()) {
|
|
992
|
-
dirs.push(entry.name);
|
|
993
|
-
continue;
|
|
994
|
-
}
|
|
995
|
-
if (!entry.isSymbolicLink()) continue;
|
|
996
|
-
try {
|
|
997
|
-
if ((await stat(join(p, entry.name))).isDirectory()) dirs.push(entry.name);
|
|
998
|
-
} catch {}
|
|
999
|
-
}
|
|
1000
|
-
return dirs;
|
|
1001
|
-
},
|
|
1002
|
-
async realpath(p) {
|
|
1003
|
-
return realpath(p);
|
|
1004
|
-
},
|
|
1005
|
-
async readFile(p) {
|
|
1006
|
-
return readFile(p);
|
|
1007
|
-
},
|
|
1008
|
-
async statFile(p) {
|
|
1009
|
-
return { size: (await stat(p)).size };
|
|
1010
|
-
},
|
|
1011
|
-
async removeFile(p) {
|
|
1012
|
-
await rm(p, { force: true });
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
}
|
|
1016
|
-
//#endregion
|
|
1017
1073
|
//#region src/log/zstd-frames.ts
|
|
1018
1074
|
const MAGIC = [
|
|
1019
1075
|
40,
|
|
@@ -2158,6 +2214,7 @@ async function cleanOrphanGroup(deps, group) {
|
|
|
2158
2214
|
//#endregion
|
|
2159
2215
|
//#region src/ports/agent-handles.ts
|
|
2160
2216
|
const CAPTURED_AGENT_HANDLES = Symbol.for("dsh-session-delete.captured-agent-handles");
|
|
2217
|
+
const CAPTURED_AGENT_WRAPPERS = Symbol.for("dsh-session-delete.captured-agent-wrappers");
|
|
2161
2218
|
/** 在 `ctx.agents` 上包一层 `resume` / `create`,把返回的 agent handle 的 dispose 按会话 id 记下。
|
|
2162
2219
|
* 服务缺席时走 `ctx.inject(['agents'])` **等服务挂上再装**——live profile 的插件激活顺序可能早于
|
|
2163
2220
|
* `agents` 服务就绪;只在 apply 时 `get` 一次会让捕获静默缺席(真机症状:重启前在回收站的能冷恢复,
|
|
@@ -2166,14 +2223,46 @@ const CAPTURED_AGENT_HANDLES = Symbol.for("dsh-session-delete.captured-agent-han
|
|
|
2166
2223
|
* **安装时机**:先 `get('agents')`,没装成再 `inject(['agents'])`(两者只装一次,符号表兜住)。
|
|
2167
2224
|
* **symbol 表**:句柄表挂在服务实例的 {@link CAPTURED_AGENT_HANDLES} 上;同一个 agents 服务上的第二次
|
|
2168
2225
|
* 安装(`get` 与 `inject` 各一次,或第二个 `createHostPort`)看见它就直接共用,不把 wrapper 套第二层。
|
|
2226
|
+
* **安装者拥有 wrapper**:包装记录先在闭包里留一份(`ownWrappers`,建立于 symbol 写入之前),同时挂到
|
|
2227
|
+
* {@link CAPTURED_AGENT_WRAPPERS};第一次成功安装时经 `ctx.effect` 注册一条卸载恢复——按 own property
|
|
2228
|
+
* descriptor 的身份把 `resume` / `create` 写回目标自有的原函数(`restoreTo`;代理读回的影子不写回,
|
|
2229
|
+
* 别人后装的 wrapper 不动),并摘掉仍归本闭包的 symbol 表。恢复是总的:一条写回失败不跳过其余记录。
|
|
2230
|
+
* 恢复一次即锁死:晚到的安装与晚到的 handle 落地都被 `restored` 挡住。没有 `ctx.effect`(假件 / 旧 ctx)
|
|
2231
|
+
* 时包装照装,只是没有恢复。
|
|
2169
2232
|
* **读回判据**:cordis 的 traceable 服务代理每次读函数都会新包一层(`get` 里的 `createShadowMethod`),
|
|
2170
2233
|
* 所以只能看 own property descriptor 的身份;拿 `service[name]` 读回比身份是必然的假警报。
|
|
2171
2234
|
*/
|
|
2172
2235
|
function captureAgentHandles(ctx) {
|
|
2173
2236
|
let handles = /* @__PURE__ */ new Map();
|
|
2237
|
+
/** 本闭包装上的包装记录:symbol 写入是 best-effort,恢复不能只靠它。 */
|
|
2238
|
+
let ownWrappers;
|
|
2174
2239
|
let installed = false;
|
|
2240
|
+
/** 卸载恢复只跑一次;同时是「清理之后不再安装、不再捕获」的闸。 */
|
|
2241
|
+
let restored = false;
|
|
2242
|
+
/**
|
|
2243
|
+
* 卸载恢复:按记录倒序把仍是我们装的方法写回 `restoreTo`,再摘掉仍是本闭包那张表的 symbol 并清空
|
|
2244
|
+
* 句柄表。身份判据挡两件事:别人后装的 wrapper 不被覆盖;别人换过的 symbol 表不被误删。
|
|
2245
|
+
* 恢复必须走完:一条写回失败只跳过那一条,摘 symbol 与清表在 `finally` 里照做。
|
|
2246
|
+
*/
|
|
2247
|
+
const restore = (service) => {
|
|
2248
|
+
if (restored) return;
|
|
2249
|
+
restored = true;
|
|
2250
|
+
const records = ownWrappers ?? service[CAPTURED_AGENT_WRAPPERS] ?? [];
|
|
2251
|
+
try {
|
|
2252
|
+
for (const record of [...records].reverse()) try {
|
|
2253
|
+
if (Object.getOwnPropertyDescriptor(service, record.name)?.value === record.wrapped) service[record.name] = record.restoreTo;
|
|
2254
|
+
} catch {}
|
|
2255
|
+
} finally {
|
|
2256
|
+
try {
|
|
2257
|
+
if (service[CAPTURED_AGENT_HANDLES] === handles) Reflect.deleteProperty(service, CAPTURED_AGENT_HANDLES);
|
|
2258
|
+
if (service[CAPTURED_AGENT_WRAPPERS] === records) Reflect.deleteProperty(service, CAPTURED_AGENT_WRAPPERS);
|
|
2259
|
+
} finally {
|
|
2260
|
+
handles.clear();
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2175
2264
|
const install = (candidate) => {
|
|
2176
|
-
if (installed) return;
|
|
2265
|
+
if (installed || restored) return;
|
|
2177
2266
|
const service = candidate;
|
|
2178
2267
|
if (service === void 0 || service === null) return;
|
|
2179
2268
|
const existing = service[CAPTURED_AGENT_HANDLES];
|
|
@@ -2182,13 +2271,17 @@ function captureAgentHandles(ctx) {
|
|
|
2182
2271
|
installed = true;
|
|
2183
2272
|
return;
|
|
2184
2273
|
}
|
|
2274
|
+
const wrappers = [];
|
|
2185
2275
|
let wrappedCount = 0;
|
|
2186
2276
|
for (const name of ["resume", "create"]) try {
|
|
2187
2277
|
const original = service[name];
|
|
2188
2278
|
if (typeof original !== "function") continue;
|
|
2279
|
+
const own = Object.getOwnPropertyDescriptor(service, name)?.value;
|
|
2280
|
+
const restoreTo = typeof own === "function" ? own : original;
|
|
2189
2281
|
const wrapped = function(...args) {
|
|
2190
2282
|
const result = Reflect.apply(original, this, args);
|
|
2191
2283
|
result.then((value) => {
|
|
2284
|
+
if (restored) return;
|
|
2192
2285
|
const handle = value;
|
|
2193
2286
|
const id = handle?.agent?.id;
|
|
2194
2287
|
const dispose = handle?.dispose;
|
|
@@ -2201,13 +2294,24 @@ function captureAgentHandles(ctx) {
|
|
|
2201
2294
|
};
|
|
2202
2295
|
service[name] = wrapped;
|
|
2203
2296
|
if (Object.getOwnPropertyDescriptor(service, name)?.value !== wrapped) throw new Error(`agents.${name} is not writable`);
|
|
2297
|
+
wrappers.push({
|
|
2298
|
+
name,
|
|
2299
|
+
original,
|
|
2300
|
+
restoreTo,
|
|
2301
|
+
wrapped
|
|
2302
|
+
});
|
|
2204
2303
|
wrappedCount += 1;
|
|
2205
2304
|
} catch {}
|
|
2206
2305
|
if (wrappedCount === 0) return;
|
|
2306
|
+
ownWrappers = wrappers;
|
|
2207
2307
|
try {
|
|
2208
2308
|
service[CAPTURED_AGENT_HANDLES] = handles;
|
|
2309
|
+
service[CAPTURED_AGENT_WRAPPERS] = wrappers;
|
|
2209
2310
|
} catch {}
|
|
2210
2311
|
installed = true;
|
|
2312
|
+
try {
|
|
2313
|
+
ctx.effect?.(() => () => restore(service), "session-delete.agent-handles");
|
|
2314
|
+
} catch {}
|
|
2211
2315
|
};
|
|
2212
2316
|
const service = ctx.get("agents");
|
|
2213
2317
|
if (service !== void 0 && service !== null) install(service);
|
|
@@ -2227,6 +2331,52 @@ function captureAgentHandles(ctx) {
|
|
|
2227
2331
|
} };
|
|
2228
2332
|
}
|
|
2229
2333
|
//#endregion
|
|
2334
|
+
//#region src/shared/project-key.ts
|
|
2335
|
+
/**
|
|
2336
|
+
* 宿主 `projectKey(cwd)` 的**编码与解码一对**:字母表、转义与包裹规则只住这一份。
|
|
2337
|
+
*
|
|
2338
|
+
* - 编码是宿主实现的逐字镜像(跨插件不能 import,宿主也没把它暴露成服务)。出处:asar
|
|
2339
|
+
* `dsh-session-persistence-jsonl/lib/index.js` 的 `projectKey`;调用链
|
|
2340
|
+
* `locate` → `logPath` → `projectDir` → `projectKey`。本机实测
|
|
2341
|
+
* `D:/develop/GitHub/dsh-session-delete` → `--D-develop-GitHub-dsh-session-delete--`。
|
|
2342
|
+
* 宿主换代先复核算法。
|
|
2343
|
+
* 唯一有意偏离:宿主对空串直接抛(`cannot encode an empty project path`),这里把它编成
|
|
2344
|
+
* `--root--`——宿主写日志时不会产生空 cwd,读面碰到的是手工改过的 header;这里只做兜底,
|
|
2345
|
+
* 不让一条坏 header 把整次对账/列表读挂掉。
|
|
2346
|
+
* - 解码给浏览器半渲染回收站组头用;配对关系由 `tests/assembly.test.ts` 的往返用例钉住。
|
|
2347
|
+
* - **空串照常编码**(得到 `--root--`):`''` 不是"没有这格",它是读到了一个空路径。只有
|
|
2348
|
+
* **缺席** cwd 才落 `NO_CWD_PROJECT_DIR`,那一条判据住 `src/ports/host-port.ts` 的 `projectDirOfCwd`
|
|
2349
|
+
* (删除计划、列表投影与对账重建共用同一处)。宿主的 `projectDir` 在 cwd 缺席时用同名目录,
|
|
2350
|
+
* 浏览器半渲染组头时也要认它——所以字面量住这里,两半共用。宿主换代先复核算法。
|
|
2351
|
+
*
|
|
2352
|
+
* **只还原可还原的那部分**:不在 `[A-Za-z0-9._-]` 里、又不是 `~` 的字符编成 `~` + 4 位大写十六进制
|
|
2353
|
+
* 码元,字面 `~` 自己编成 `~007E` ⇒ `~XXXX` 不含歧义。而**分隔符(`/` `\` `:`)被折成一个 `-`,
|
|
2354
|
+
* 那一段是有损的**,解码还原不回来——调用方按"尽力显示"用它,别拿它反推真实路径。
|
|
2355
|
+
*/
|
|
2356
|
+
/** 无 cwd 的会话落在 `_no-cwd/`(宿主 `projectDir` 原文:`if (cwd === void 0) return join(root, "_no-cwd");`)。
|
|
2357
|
+
* Node 半用它合成目录名,浏览器半用它把组头念成「未记录项目」——同一事实只有这一份。 */
|
|
2358
|
+
const NO_CWD_PROJECT_DIR = "_no-cwd";
|
|
2359
|
+
/** cwd → 项目目录名(宿主 `projectKey` 的逐字镜像)。 */
|
|
2360
|
+
function escapeProjectKey(cwd) {
|
|
2361
|
+
let readable = "";
|
|
2362
|
+
let separatorRun = false;
|
|
2363
|
+
for (let i = 0; i < cwd.length; i++) {
|
|
2364
|
+
const code = cwd.charCodeAt(i);
|
|
2365
|
+
const ch = String.fromCharCode(code);
|
|
2366
|
+
if (ch === "/" || ch === "\\" || ch === ":") {
|
|
2367
|
+
if (!separatorRun) readable += "-";
|
|
2368
|
+
separatorRun = true;
|
|
2369
|
+
} else if (ch !== "~" && /^[A-Za-z0-9._-]$/.test(ch)) {
|
|
2370
|
+
readable += ch;
|
|
2371
|
+
separatorRun = false;
|
|
2372
|
+
} else {
|
|
2373
|
+
readable += `~${code.toString(16).toUpperCase().padStart(4, "0")}`;
|
|
2374
|
+
separatorRun = false;
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
return `--${(readable.replace(/^-+/, "") || "root").slice(0, 251)}--`;
|
|
2378
|
+
}
|
|
2379
|
+
//#endregion
|
|
2230
2380
|
//#region src/ports/host-port.ts
|
|
2231
2381
|
/** live store 的最小方法面判据(同 `projectionCacheOf` 的手法:按方法面判,不按 constructor.name)。 */
|
|
2232
2382
|
function liveSessionsOf(ctx) {
|
|
@@ -2250,6 +2400,12 @@ async function headerOf(host, sessionId) {
|
|
|
2250
2400
|
if (persistence === void 0 || persistence === null || typeof persistence.stat !== "function") throw new Error("session-delete: sessionPersistence 服务缺席");
|
|
2251
2401
|
return (await persistence.stat(sessionId))?.header;
|
|
2252
2402
|
}
|
|
2403
|
+
/** `subagent` 投影行里的 label:形状不符 / 空串一律当没有(降级,不响亮失败)。 */
|
|
2404
|
+
function subagentLabelOf(value) {
|
|
2405
|
+
if (typeof value !== "object" || value === null) return "";
|
|
2406
|
+
const label = value.label;
|
|
2407
|
+
return typeof label === "string" ? label : "";
|
|
2408
|
+
}
|
|
2253
2409
|
/** 官方的「这些父的孩子」那一支:`kind:'parent'` 的判据逐字是 `values.includes(record.header.parentSession ?? null)`。
|
|
2254
2410
|
* 它只按 `parentSession` 原样匹配,**不是**子会话分类器:旧宿主(≤0.2.1-rc.5)的普通 fork 也写
|
|
2255
2411
|
* `parentSession`,0.2.2-alpha.2 起才不写。子会话的判据是 `origin` 的 subagent 标记(宿主归档闸、归档
|
|
@@ -2287,7 +2443,7 @@ async function descendantsByParent(sessionQuery, roots) {
|
|
|
2287
2443
|
const cwd = record.header.cwd;
|
|
2288
2444
|
const descendant = {
|
|
2289
2445
|
sessionId: id,
|
|
2290
|
-
projectDir:
|
|
2446
|
+
projectDir: projectDirOfCwd(cwd)
|
|
2291
2447
|
};
|
|
2292
2448
|
const parentBare = bareSessionId(parent);
|
|
2293
2449
|
const siblings = children.get(parentBare);
|
|
@@ -2311,32 +2467,20 @@ async function membersFor(sessionQuery, parentIds) {
|
|
|
2311
2467
|
for (const id of wanted) out[id] = closureOf(children, id);
|
|
2312
2468
|
return out;
|
|
2313
2469
|
}
|
|
2314
|
-
/**
|
|
2315
|
-
*
|
|
2316
|
-
const NO_CWD_PROJECT_DIR = "_no-cwd";
|
|
2317
|
-
/** 宿主 `projectKey(cwd)` 的逐字镜像:跨插件不能 import,宿主也没把它暴露成服务。
|
|
2318
|
-
* 出处:asar `dsh-session-persistence-jsonl/lib/index.js` 的 `projectKey`;调用链
|
|
2319
|
-
* `locate` → `logPath` → `projectDir` → `projectKey`。本机实测 `D:/develop/GitHub/dsh-session-delete`
|
|
2320
|
-
* → `--D-develop-GitHub-dsh-session-delete--`。`projectDirOf` 与回收站对账重建共用这一份;
|
|
2470
|
+
/** 宿主 `projectKey(cwd)` 的逐字镜像:编码与解码配对住在 `src/shared/project-key.ts`
|
|
2471
|
+
* (字母表只有一份;解码给浏览器半渲染回收站组头)。`projectDirOf` 与回收站对账重建共用这一份;
|
|
2321
2472
|
* 宿主换代先复核算法。 */
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
separatorRun = false;
|
|
2334
|
-
} else {
|
|
2335
|
-
readable += `~${code.toString(16).toUpperCase().padStart(4, "0")}`;
|
|
2336
|
-
separatorRun = false;
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
return `--${(readable.replace(/^-+/, "") || "root").slice(0, 251)}--`;
|
|
2473
|
+
const projectKey = escapeProjectKey;
|
|
2474
|
+
/**
|
|
2475
|
+
* cwd(可缺席)→ 会话落盘的项目目录名:**只有缺席**(`undefined`)落 `_no-cwd`;
|
|
2476
|
+
* 空串照常编码——`''` 不是"没有这一格",它是读到了一个空路径。宿主的 `projectDir`
|
|
2477
|
+
* (`cwd === void 0` 才走 `_no-cwd`)就是这一支。
|
|
2478
|
+
*
|
|
2479
|
+
* 删除计划、会话列表投影与对账重建**共用这一处**:三处各自写一遍三元式,`''` 迟早有一处
|
|
2480
|
+
* 落成 `_no-cwd`,同一条会话在删除、恢复与孤儿扫描里就会指向两个目录。
|
|
2481
|
+
*/
|
|
2482
|
+
function projectDirOfCwd(cwd) {
|
|
2483
|
+
return cwd === void 0 ? NO_CWD_PROJECT_DIR : projectKey(cwd);
|
|
2340
2484
|
}
|
|
2341
2485
|
/** 投影缓存服务的最小方法面判据(按方法面判,不按 `constructor.name` 判)。 */
|
|
2342
2486
|
function projectionCacheOf(ctx) {
|
|
@@ -2392,15 +2536,20 @@ function createHostPort(ctx) {
|
|
|
2392
2536
|
async projectDirOf(sessionId) {
|
|
2393
2537
|
const header = await headerOf(host, sessionId);
|
|
2394
2538
|
if (header === void 0) return void 0;
|
|
2395
|
-
return
|
|
2539
|
+
return projectDirOfCwd(header.cwd);
|
|
2396
2540
|
},
|
|
2397
|
-
/**
|
|
2541
|
+
/** 显示名走宿主投影缓存(与工作中同名):子会话取 `subagent` 投影的 label,其余取 `title` 行的
|
|
2542
|
+
* **视图值**(缓存整条未命中才回落 predecessor 标题)。header 来自公开的 live/持久化读面,
|
|
2543
|
+
* 尽力取,取不到返回空串。 */
|
|
2398
2544
|
async titleOf(sessionId) {
|
|
2399
2545
|
try {
|
|
2400
2546
|
const header = await headerOf(host, sessionId);
|
|
2401
2547
|
if (header === void 0) return "";
|
|
2402
2548
|
const cache = projectionCacheOf(host);
|
|
2403
|
-
const
|
|
2549
|
+
const snapshot = cache?.cachedSnapshot(header, ["title", "subagent"]);
|
|
2550
|
+
const label = subagentLabelOf(snapshot?.values.subagent);
|
|
2551
|
+
if (label !== "") return label;
|
|
2552
|
+
const title = (snapshot !== void 0 && snapshot.values.title !== void 0 ? snapshot : cache?.cachedPredecessorTitle(header))?.values.title;
|
|
2404
2553
|
return typeof title === "string" ? title : "";
|
|
2405
2554
|
} catch {
|
|
2406
2555
|
return "";
|
|
@@ -2513,7 +2662,7 @@ function createHostPort(ctx) {
|
|
|
2513
2662
|
out.push({
|
|
2514
2663
|
sessionId: id,
|
|
2515
2664
|
...typeof parent === "string" && parent !== "" ? { parentSessionId: parent } : {},
|
|
2516
|
-
projectDir:
|
|
2665
|
+
projectDir: projectDirOfCwd(cwd),
|
|
2517
2666
|
subagent: record.header?.origin === "subagent"
|
|
2518
2667
|
});
|
|
2519
2668
|
}
|
|
@@ -2832,6 +2981,150 @@ function applyActions(deps, action, ids) {
|
|
|
2832
2981
|
}
|
|
2833
2982
|
}
|
|
2834
2983
|
//#endregion
|
|
2984
|
+
//#region src/config.ts
|
|
2985
|
+
/**
|
|
2986
|
+
* 可调项(Config,ADR-0037):三只旋钮 + 本地 Standard Schema。
|
|
2987
|
+
*
|
|
2988
|
+
* 为什么不用 `@deepseek-ai/schemastery` 写 schema:那是宿主包,值 import 会破本仓「跨插件一律
|
|
2989
|
+
* `import type`」的硬约束;Cordis 的 Config 接受 Standard Schema(`@standard-schema/spec`),
|
|
2990
|
+
* 手写这一小段即可,不需要把宿主 schema 库搬进插件。代价是宿主只为 native Schemastery schema 投影
|
|
2991
|
+
* 字段表单,这枚手写的 Standard Schema 不在其列——字段表单由插件设置页的「可调项」卡提供
|
|
2992
|
+
* (ADR-0043),profile 的 `cordis.patch.yml` 仍是默认值与覆盖的家。
|
|
2993
|
+
*
|
|
2994
|
+
* 这里只做**默认值、归一与 schema**,不持有运行期现场:`apply` 归一一次,结果作为
|
|
2995
|
+
* `CoreDeps.config` 注入;读方从自己的 deps 读,不 import 模块级单例。
|
|
2996
|
+
* 客户端 6 秒撤销时长不在这里:它是浏览器半的产品决定,不跨半传。
|
|
2997
|
+
*/
|
|
2998
|
+
const DEFAULT_CONFIG = Object.freeze({
|
|
2999
|
+
orphanPreviewLimit: 200,
|
|
3000
|
+
maxAttachmentBytes: 20971520,
|
|
3001
|
+
maxJsonRefBytes: 10485760
|
|
3002
|
+
});
|
|
3003
|
+
function intField(input, key, range) {
|
|
3004
|
+
const value = input[key];
|
|
3005
|
+
if (value === void 0) return DEFAULT_CONFIG[key];
|
|
3006
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < range.min || value > range.max) throw new Error(`配置项 ${key} 需为 ${range.min}..${range.max} 的整数`);
|
|
3007
|
+
return value;
|
|
3008
|
+
}
|
|
3009
|
+
/**
|
|
3010
|
+
* 把 patch 里的 `config` 归一成完整配置:缺省取默认值,未知键 / 非整数 / 越界都抛。
|
|
3011
|
+
* 抛错会让插件激活失败(响亮),而不是悄悄用半套配置跑。
|
|
3012
|
+
*/
|
|
3013
|
+
function normalizeConfig(value) {
|
|
3014
|
+
if (value === void 0 || value === null) return DEFAULT_CONFIG;
|
|
3015
|
+
if (typeof value !== "object" || Array.isArray(value)) throw new Error("配置需为对象");
|
|
3016
|
+
const input = value;
|
|
3017
|
+
const known = new Set(Object.keys(CONFIG_LIMITS));
|
|
3018
|
+
for (const key of Object.keys(input)) if (!known.has(key)) throw new Error(`未知配置项:${key}`);
|
|
3019
|
+
return {
|
|
3020
|
+
orphanPreviewLimit: intField(input, "orphanPreviewLimit", CONFIG_LIMITS.orphanPreviewLimit),
|
|
3021
|
+
maxAttachmentBytes: intField(input, "maxAttachmentBytes", CONFIG_LIMITS.maxAttachmentBytes),
|
|
3022
|
+
maxJsonRefBytes: intField(input, "maxJsonRefBytes", CONFIG_LIMITS.maxJsonRefBytes)
|
|
3023
|
+
};
|
|
3024
|
+
}
|
|
3025
|
+
/**
|
|
3026
|
+
* 插件 Config:Cordis 接受 Standard Schema,`~standard.validate` 交回归一后的配置。
|
|
3027
|
+
* 宿主在激活前校验;`apply` 再归一一次(同一份事实,不会漂)。
|
|
3028
|
+
*/
|
|
3029
|
+
const Config = { "~standard": {
|
|
3030
|
+
version: 1,
|
|
3031
|
+
vendor: "dsh-session-delete",
|
|
3032
|
+
validate(value) {
|
|
3033
|
+
try {
|
|
3034
|
+
return { value: normalizeConfig(value) };
|
|
3035
|
+
} catch (error) {
|
|
3036
|
+
return { issues: [{ message: error instanceof Error ? error.message : String(error) }] };
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
} };
|
|
3040
|
+
//#endregion
|
|
3041
|
+
//#region src/verbs/config.ts
|
|
3042
|
+
/**
|
|
3043
|
+
* `/config` 的读/写动词:三只可调项的当前值与写回。
|
|
3044
|
+
*
|
|
3045
|
+
* 读是免费快照(`apply` 归一后的那一份),写才碰宿主:
|
|
3046
|
+
* - 先按 `src/config.ts` 的 `normalizeConfig` 校验(未知键 / 非整数 / 越界回 400,不拿半套值写盘);
|
|
3047
|
+
* - 再走宿主 `configEditor.edit(entry, change)`:完整 raw config 落进 profile 的 patch 层,
|
|
3048
|
+
* 由编辑器串行化、校验并让这一行重启(字段不是 volatile,重启是它给的语义)。
|
|
3049
|
+
* - `configEditor` / `entry` 缺席(老宿主、嵌套上下文)回 `io` 并在原文里说清替代路径——
|
|
3050
|
+
* 不静默假装保存成功。
|
|
3051
|
+
*
|
|
3052
|
+
* `entry` 由组合根从 `ctx.fiber.entry` 取(见 `src/index.ts`);本文件不碰 ctx。
|
|
3053
|
+
*/
|
|
3054
|
+
/** `/config` 的请求体:`null` 或 `{}` 是读;只要带一个键就当写(未知键由 {@link normalizeConfig} 400 拒掉)。
|
|
3055
|
+
* 路由表按同一句话定纯度,所以别在别处再写一遍这个判据。 */
|
|
3056
|
+
function configPatchOf(body) {
|
|
3057
|
+
if (body === null || Object.keys(body).length === 0) return void 0;
|
|
3058
|
+
return body;
|
|
3059
|
+
}
|
|
3060
|
+
/** 空体 = 读当前值;带字段 = 写。请求体已经由适配器解析成对象或 null。 */
|
|
3061
|
+
function readOrSaveConfig(deps, body) {
|
|
3062
|
+
const patch = configPatchOf(body);
|
|
3063
|
+
if (patch === void 0) return deps.config;
|
|
3064
|
+
return saveConfig(deps, patch);
|
|
3065
|
+
}
|
|
3066
|
+
async function saveConfig(deps, patch) {
|
|
3067
|
+
let next;
|
|
3068
|
+
try {
|
|
3069
|
+
next = normalizeConfig({
|
|
3070
|
+
...deps.config,
|
|
3071
|
+
...patch
|
|
3072
|
+
});
|
|
3073
|
+
} catch (error) {
|
|
3074
|
+
throw routeError("bad-request", 400, error instanceof Error ? error.message : String(error));
|
|
3075
|
+
}
|
|
3076
|
+
const editor = deps.configEditor;
|
|
3077
|
+
if (editor === void 0 || deps.entry === void 0) throw verbError("io", "这一代宿主不能保存配置;请直接改 profile 的 cordis.patch.yml");
|
|
3078
|
+
try {
|
|
3079
|
+
await editor.edit(deps.entry, (current) => ({
|
|
3080
|
+
...current,
|
|
3081
|
+
...next
|
|
3082
|
+
}));
|
|
3083
|
+
} catch (error) {
|
|
3084
|
+
throw verbError("io", `配置没有保存:${error instanceof Error ? error.message : String(error)}`, error);
|
|
3085
|
+
}
|
|
3086
|
+
return next;
|
|
3087
|
+
}
|
|
3088
|
+
//#endregion
|
|
3089
|
+
//#region src/trash/display-name.ts
|
|
3090
|
+
/**
|
|
3091
|
+
* 回收站条目的**自己的显示名**:从被删会话自己的日志里折出,供没有父详情可兜的条目
|
|
3092
|
+
* (独立子会话、旧判据折进来的 fork 孩子)与父详情里没有 catalog 登记的 fork 孩子使用。
|
|
3093
|
+
*
|
|
3094
|
+
* 为什么不是 `titleOf` 的抄本:`titleOf` 读的是宿主投影缓存(删除那一刻的显示名),
|
|
3095
|
+
* 这里是**已经进了回收站的日志**——清册标题已经起错、父日志又没有 catalog 时,它是唯一还能
|
|
3096
|
+
* 读到的工作中名字。两份来源不同,判据各自住一处(ADR-0058)。
|
|
3097
|
+
*/
|
|
3098
|
+
/** `subagent/descriptor` 的 label;空/缺席 = 这条 descriptor 没有名字(one-shot 可以不给)。 */
|
|
3099
|
+
function descriptorLabelOf(data) {
|
|
3100
|
+
return typeof data.label === "string" ? data.label : "";
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* 走一遍日志,折出**这条会话自己**的 descriptor label 与最后一条日志标题。
|
|
3104
|
+
*
|
|
3105
|
+
* 折叠语义与宿主 `subagent` 投影一致:每遇一条 descriptor 就覆盖(空 label 也覆盖),
|
|
3106
|
+
* 所以 fork 种子里祖先的 descriptor 会被子会话自己的那条盖掉。日志标题取**最后一条**:
|
|
3107
|
+
* 它是会话改名 / 兜底标题之后的当前值。
|
|
3108
|
+
*/
|
|
3109
|
+
function displayNameOfLog(raw) {
|
|
3110
|
+
let label = "";
|
|
3111
|
+
let title = "";
|
|
3112
|
+
walkSessionLog(raw, (record) => {
|
|
3113
|
+
if (record.type === "subagent/descriptor") {
|
|
3114
|
+
label = descriptorLabelOf(record.data ?? {});
|
|
3115
|
+
return;
|
|
3116
|
+
}
|
|
3117
|
+
if (record.type === "session/title") {
|
|
3118
|
+
const data = record.data ?? {};
|
|
3119
|
+
if (typeof data.title === "string") title = data.title;
|
|
3120
|
+
}
|
|
3121
|
+
});
|
|
3122
|
+
return {
|
|
3123
|
+
label,
|
|
3124
|
+
title
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
3127
|
+
//#endregion
|
|
2835
3128
|
//#region src/trash/detail.ts
|
|
2836
3129
|
/**
|
|
2837
3130
|
* 回收站**单条详情**:从回收站目录里那条会话自己的日志读出元信息与正文块(用例见 `tests/trash-detail.test.ts`)。
|
|
@@ -2904,6 +3197,16 @@ function clip(text, cap) {
|
|
|
2904
3197
|
function hasContent(text, attachments) {
|
|
2905
3198
|
return text !== "" || attachments.length > 0;
|
|
2906
3199
|
}
|
|
3200
|
+
/** 提问索引的预览:空白折叠、超长带省略号。Markdown 记号不清——这是标签,读者要能一眼认出原句。
|
|
3201
|
+
*
|
|
3202
|
+
* **按码点截断**,不按 UTF-16 码元:`slice` 会把代理对(emoji 等)切成孤立的一半,过线后
|
|
3203
|
+
* 显示成替换字符——预览是读者认出这一句的唯一线索,不该在这里坏掉。 */
|
|
3204
|
+
function promptPreview(text) {
|
|
3205
|
+
const normalized = text.replace(/\s+/g, " ").trim();
|
|
3206
|
+
const chars = Array.from(normalized);
|
|
3207
|
+
if (chars.length <= 80) return normalized;
|
|
3208
|
+
return `${chars.slice(0, 79).join("").trimEnd()}…`;
|
|
3209
|
+
}
|
|
2907
3210
|
/** 一块的正文:没内容 ⇒ 这块不建;否则过单块闸截一刀。 */
|
|
2908
3211
|
function blockBody(rawText, attachments, cap) {
|
|
2909
3212
|
const text = rawText.trim();
|
|
@@ -2979,20 +3282,23 @@ var PageBuilder = class PageBuilder {
|
|
|
2979
3282
|
this.cap = cap;
|
|
2980
3283
|
this.pageChars = pageChars;
|
|
2981
3284
|
}
|
|
2982
|
-
/**
|
|
3285
|
+
/** 追加一块并回它在整条日志里的序号:id 用这个序号盖,页内只留最后 `limit` 块 / `pageChars` 字符。
|
|
3286
|
+
* 返回值**不管这块进没进页**都给(提问索引要拿它当游标),所以调用方不能拿返回值为空当"没入页"。 */
|
|
2983
3287
|
add(block) {
|
|
2984
3288
|
const index = this.nextIndex++;
|
|
2985
|
-
if (index
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
3289
|
+
if (index < this.end) {
|
|
3290
|
+
block.id = String(index);
|
|
3291
|
+
const chars = blockChars(block);
|
|
3292
|
+
this.buffer.push({
|
|
3293
|
+
index,
|
|
3294
|
+
block,
|
|
3295
|
+
chars
|
|
3296
|
+
});
|
|
3297
|
+
this.chars += chars;
|
|
3298
|
+
this.trim();
|
|
3299
|
+
if (block.kind === "tool") this.hook(block);
|
|
3300
|
+
}
|
|
3301
|
+
return String(index);
|
|
2996
3302
|
}
|
|
2997
3303
|
/** 挤出页首:块数超限,或正文超字符闸(但至少留一块,游标才能前进)。 */
|
|
2998
3304
|
trim() {
|
|
@@ -3073,6 +3379,22 @@ var PageBuilder = class PageBuilder {
|
|
|
3073
3379
|
};
|
|
3074
3380
|
}
|
|
3075
3381
|
};
|
|
3382
|
+
/**
|
|
3383
|
+
* 一条孩子的**自己日志**里的显示名:descriptor label 优先,其次最后一条 `session/title`。
|
|
3384
|
+
* 只给父详情里没有 catalog 登记、标题又撞名的 fork 孩子用(它们没有 label,清册标题是删除时的
|
|
3385
|
+
* 快照);读不出就返回 `undefined`,绝不让父详情失败——看不见那个名字比整条详情打不开轻。
|
|
3386
|
+
*/
|
|
3387
|
+
async function childDisplayNameOf(deps, entry) {
|
|
3388
|
+
try {
|
|
3389
|
+
const dir = trashDirOf(entry.id, deps.home);
|
|
3390
|
+
const logName = pickSessionLog(await deps.fs.listFiles(dir));
|
|
3391
|
+
if (logName === void 0) return void 0;
|
|
3392
|
+
const { label, title } = displayNameOfLog(await deps.fs.readFile(`${dir}/${logName}`));
|
|
3393
|
+
return label !== "" ? label : title !== "" ? title : void 0;
|
|
3394
|
+
} catch {
|
|
3395
|
+
return;
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3076
3398
|
function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
3077
3399
|
return async function readTrashDetail(entryId, before) {
|
|
3078
3400
|
const all = await deps.rows();
|
|
@@ -3105,6 +3427,18 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3105
3427
|
olderCursor: null
|
|
3106
3428
|
};
|
|
3107
3429
|
const models = /* @__PURE__ */ new Set();
|
|
3430
|
+
/** 子会话的显示名(bare id → label):父日志的 `subagent/catalog` 事件逐孩子记着委派时的
|
|
3431
|
+
* `description`(与宿主工作中同名)。清册标题是删除那一刻的快照,起错名的存量条目靠它兜(ADR-0058)。 */
|
|
3432
|
+
const subagentLabels = /* @__PURE__ */ new Map();
|
|
3433
|
+
/** 这条会话**自己**的 descriptor label(独立子会话没有父日志可查时的兜底)。
|
|
3434
|
+
* 与宿主 `subagent` 投影同一语义:每遇一条 descriptor 就覆盖,空 label 重置——fork 种子里的
|
|
3435
|
+
* 祖先 descriptor 必须被子会话自己的那条覆盖,坏/空的后写不保留祖先的名字。 */
|
|
3436
|
+
let ownLabel = "";
|
|
3437
|
+
/** 这条会话的 header 带 `parentSession`:它是子会话(fork / subagent),自己的日志标题才是
|
|
3438
|
+
* 当前名字;主会话没有这一格,仍按清册快照优先。 */
|
|
3439
|
+
let ownParentSession = false;
|
|
3440
|
+
/** 整条会话的提问索引:与分页无关,只在首次读时过线(见 `TrashDetailWire.prompts`)。 */
|
|
3441
|
+
const prompts = [];
|
|
3108
3442
|
const page = new PageBuilder(before ?? Number.POSITIVE_INFINITY, Math.max(1, limits.pageBlocks), limits.perBlockChars, Math.max(1, limits.pageChars ?? 5e5));
|
|
3109
3443
|
try {
|
|
3110
3444
|
walkSessionLog(raw, (r) => {
|
|
@@ -3115,10 +3449,20 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3115
3449
|
case "session":
|
|
3116
3450
|
if (typeof r.cwd === "string") detail.cwd = r.cwd;
|
|
3117
3451
|
if (typeof r.createdAt === "number") detail.createdAt = r.createdAt;
|
|
3452
|
+
if (typeof r.parentSession === "string" && r.parentSession !== "") ownParentSession = true;
|
|
3118
3453
|
return;
|
|
3119
3454
|
case "session/title":
|
|
3120
3455
|
if (typeof data.title === "string") detail.logTitle = data.title;
|
|
3121
3456
|
return;
|
|
3457
|
+
case "subagent/catalog": {
|
|
3458
|
+
const childId = data.childId;
|
|
3459
|
+
const label = data.label;
|
|
3460
|
+
if (typeof childId === "string" && childId !== "" && typeof label === "string" && label !== "") subagentLabels.set(bareSessionId(childId), label);
|
|
3461
|
+
return;
|
|
3462
|
+
}
|
|
3463
|
+
case "subagent/descriptor":
|
|
3464
|
+
ownLabel = descriptorLabelOf(data);
|
|
3465
|
+
return;
|
|
3122
3466
|
case "turn/start":
|
|
3123
3467
|
detail.turnCount += 1;
|
|
3124
3468
|
return;
|
|
@@ -3131,7 +3475,12 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3131
3475
|
const block = textBlock("user", time, text, attachments, limits.perBlockChars);
|
|
3132
3476
|
if (block !== void 0) {
|
|
3133
3477
|
detail.userMessageCount += 1;
|
|
3134
|
-
page.add(block);
|
|
3478
|
+
const id = page.add(block);
|
|
3479
|
+
if (before === void 0 && text !== "") prompts.push({
|
|
3480
|
+
id,
|
|
3481
|
+
at: time,
|
|
3482
|
+
preview: promptPreview(text)
|
|
3483
|
+
});
|
|
3135
3484
|
}
|
|
3136
3485
|
return;
|
|
3137
3486
|
}
|
|
@@ -3222,11 +3571,38 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3222
3571
|
const finished = page.finish();
|
|
3223
3572
|
detail.blocks = finished.blocks;
|
|
3224
3573
|
detail.olderCursor = finished.olderCursor;
|
|
3574
|
+
if (before === void 0) detail.prompts = prompts;
|
|
3225
3575
|
detail.models = [...models];
|
|
3576
|
+
const ownDisplayName = ownLabel !== "" ? ownLabel : ownParentSession ? detail.logTitle : "";
|
|
3577
|
+
if (ownDisplayName !== "") detail.label = ownDisplayName;
|
|
3226
3578
|
const kids = visibleGroups(all).find((group) => group.root.id === record.id)?.kids ?? [];
|
|
3227
3579
|
if (kids.length > 0) {
|
|
3228
3580
|
const limit = limits.subagents ?? 200;
|
|
3229
|
-
|
|
3581
|
+
const titleCounts = /* @__PURE__ */ new Map();
|
|
3582
|
+
for (const kid of kids) titleCounts.set(kid.title, (titleCounts.get(kid.title) ?? 0) + 1);
|
|
3583
|
+
const ambiguous = (kid) => kid.title === "" || kid.title === record.title || (titleCounts.get(kid.title) ?? 0) > 1;
|
|
3584
|
+
const listed = [];
|
|
3585
|
+
for (const kid of kids.slice(0, limit)) {
|
|
3586
|
+
const label = subagentLabels.get(bareSessionId(kid.sessionId));
|
|
3587
|
+
if (label !== void 0) {
|
|
3588
|
+
listed.push({
|
|
3589
|
+
...entryWire(kid),
|
|
3590
|
+
label
|
|
3591
|
+
});
|
|
3592
|
+
continue;
|
|
3593
|
+
}
|
|
3594
|
+
if (!kid.sessionId.startsWith("session-") || !ambiguous(kid)) {
|
|
3595
|
+
listed.push(entryWire(kid));
|
|
3596
|
+
continue;
|
|
3597
|
+
}
|
|
3598
|
+
const own = await childDisplayNameOf(deps, kid);
|
|
3599
|
+
listed.push(own === void 0 || own === kid.title ? entryWire(kid) : {
|
|
3600
|
+
...entryWire(kid),
|
|
3601
|
+
label: own
|
|
3602
|
+
});
|
|
3603
|
+
}
|
|
3604
|
+
detail.subagents = listed;
|
|
3605
|
+
detail.subagentsSizeBytes = kids.reduce((sum, kid) => sum + kid.sizeBytes, 0);
|
|
3230
3606
|
if (kids.length > limit) detail.subagentsTotal = kids.length;
|
|
3231
3607
|
}
|
|
3232
3608
|
return detail;
|
|
@@ -3547,9 +3923,23 @@ async function assembleTrashRows(deps, rows) {
|
|
|
3547
3923
|
* - 切片声明宽了 ⇒ 危险能力(删目录 / 时钟)漏进读段的 run;窄了 ⇒ 写段的处理编译不过。
|
|
3548
3924
|
*
|
|
3549
3925
|
* 这张表不放 shared/wire.ts:处理函数会 import 动词与 node:fs,而浏览器半要 import wire.ts。
|
|
3550
|
-
*
|
|
3551
|
-
*
|
|
3926
|
+
* 段名、方法与请求体形状住 wire.ts(`ROUTES` 每项 `{ path, method, body }`,本表的 method / body 只投影、
|
|
3927
|
+
* 不写第二份字面量);这张表只回答“怎么处理”。
|
|
3552
3928
|
*/
|
|
3929
|
+
/** 段名表那一格 → 分发器要不要预读 JSON。`satisfies` 让每个 `RouteBody` 值都必须在这里有
|
|
3930
|
+
* 明确的一格:以后加一种 body,缺了映射就是编译错,不会被默认折成 JSON 预读。 */
|
|
3931
|
+
const BODY_KIND = {
|
|
3932
|
+
none: "none",
|
|
3933
|
+
query: "none",
|
|
3934
|
+
config: "json",
|
|
3935
|
+
entry: "json",
|
|
3936
|
+
apply: "json"
|
|
3937
|
+
};
|
|
3938
|
+
/** 读的是 wire 那一格(`ROUTES.x.body`),本表不写第二份:无字段与查询串段不读;
|
|
3939
|
+
* 带 JSON 字段的段(config / entry / apply)读一次。 */
|
|
3940
|
+
function bodyOf(route) {
|
|
3941
|
+
return BODY_KIND[route.body];
|
|
3942
|
+
}
|
|
3553
3943
|
/** 必填的非空字符串字段(缺、空串、类型不对都是**同一句话**:说清是哪个字段)。 */
|
|
3554
3944
|
function requireString(body, field) {
|
|
3555
3945
|
const value = body?.[field];
|
|
@@ -3599,14 +3989,14 @@ function requireIdArray(body) {
|
|
|
3599
3989
|
return value;
|
|
3600
3990
|
}
|
|
3601
3991
|
/**
|
|
3602
|
-
*
|
|
3992
|
+
* 十个段名各一行。`Record<段名, AnyRouteSpec>` 是闸:`wire.ts` 加了段名而这里没加,编译不过;
|
|
3603
3993
|
* 每行的 `slice` 又把该行的 `run` 钉在自己那一格 deps 上(ADR-0032)。
|
|
3604
3994
|
*/
|
|
3605
3995
|
const ROUTE_TABLE = {
|
|
3606
3996
|
[ROUTES.list.path]: {
|
|
3607
3997
|
slice: "core",
|
|
3608
3998
|
method: ROUTES.list.method,
|
|
3609
|
-
body:
|
|
3999
|
+
body: bodyOf(ROUTES.list),
|
|
3610
4000
|
purity: "chained",
|
|
3611
4001
|
read: "list",
|
|
3612
4002
|
response: "json",
|
|
@@ -3615,16 +4005,25 @@ const ROUTE_TABLE = {
|
|
|
3615
4005
|
[ROUTES.ping.path]: {
|
|
3616
4006
|
slice: "core",
|
|
3617
4007
|
method: ROUTES.ping.method,
|
|
3618
|
-
body:
|
|
4008
|
+
body: bodyOf(ROUTES.ping),
|
|
3619
4009
|
purity: "pure",
|
|
3620
4010
|
read: "none",
|
|
3621
4011
|
response: "json",
|
|
3622
4012
|
run: async () => "pong"
|
|
3623
4013
|
},
|
|
4014
|
+
[ROUTES.config.path]: {
|
|
4015
|
+
slice: "config",
|
|
4016
|
+
method: ROUTES.config.method,
|
|
4017
|
+
body: bodyOf(ROUTES.config),
|
|
4018
|
+
purity: (body) => configPatchOf(body) === void 0 ? "pure" : "chained",
|
|
4019
|
+
read: "none",
|
|
4020
|
+
response: "json",
|
|
4021
|
+
run: async (deps, body) => readOrSaveConfig(deps, body)
|
|
4022
|
+
},
|
|
3624
4023
|
[ROUTES.attachment.path]: {
|
|
3625
4024
|
slice: "attachment",
|
|
3626
4025
|
method: ROUTES.attachment.method,
|
|
3627
|
-
body:
|
|
4026
|
+
body: bodyOf(ROUTES.attachment),
|
|
3628
4027
|
purity: "pure",
|
|
3629
4028
|
read: "none",
|
|
3630
4029
|
response: "binary",
|
|
@@ -3634,7 +4033,7 @@ const ROUTE_TABLE = {
|
|
|
3634
4033
|
[ROUTES.attachmentOrphans.path]: {
|
|
3635
4034
|
slice: "core",
|
|
3636
4035
|
method: ROUTES.attachmentOrphans.method,
|
|
3637
|
-
body:
|
|
4036
|
+
body: bodyOf(ROUTES.attachmentOrphans),
|
|
3638
4037
|
purity: "pure",
|
|
3639
4038
|
read: "none",
|
|
3640
4039
|
response: "json",
|
|
@@ -3643,7 +4042,7 @@ const ROUTE_TABLE = {
|
|
|
3643
4042
|
[ROUTES.attachmentClean.path]: {
|
|
3644
4043
|
slice: "removal",
|
|
3645
4044
|
method: ROUTES.attachmentClean.method,
|
|
3646
|
-
body:
|
|
4045
|
+
body: bodyOf(ROUTES.attachmentClean),
|
|
3647
4046
|
purity: "chained",
|
|
3648
4047
|
read: "none",
|
|
3649
4048
|
response: "json",
|
|
@@ -3652,7 +4051,7 @@ const ROUTE_TABLE = {
|
|
|
3652
4051
|
[ROUTES.orphans.path]: {
|
|
3653
4052
|
slice: "core",
|
|
3654
4053
|
method: ROUTES.orphans.method,
|
|
3655
|
-
body:
|
|
4054
|
+
body: bodyOf(ROUTES.orphans),
|
|
3656
4055
|
purity: "pure",
|
|
3657
4056
|
read: "raw",
|
|
3658
4057
|
response: "json",
|
|
@@ -3661,7 +4060,7 @@ const ROUTE_TABLE = {
|
|
|
3661
4060
|
[ROUTES.apply.path]: {
|
|
3662
4061
|
slice: "full",
|
|
3663
4062
|
method: ROUTES.apply.method,
|
|
3664
|
-
body:
|
|
4063
|
+
body: bodyOf(ROUTES.apply),
|
|
3665
4064
|
purity: (body) => {
|
|
3666
4065
|
const action = actionOf(body);
|
|
3667
4066
|
return action === void 0 ? "chained" : APPLY_ACTION_TABLE[action];
|
|
@@ -3673,7 +4072,7 @@ const ROUTE_TABLE = {
|
|
|
3673
4072
|
[ROUTES.empty.path]: {
|
|
3674
4073
|
slice: "removal",
|
|
3675
4074
|
method: ROUTES.empty.method,
|
|
3676
|
-
body:
|
|
4075
|
+
body: bodyOf(ROUTES.empty),
|
|
3677
4076
|
purity: "chained",
|
|
3678
4077
|
read: "list",
|
|
3679
4078
|
response: "json",
|
|
@@ -3684,7 +4083,7 @@ const ROUTE_TABLE = {
|
|
|
3684
4083
|
[ROUTES.detail.path]: {
|
|
3685
4084
|
slice: "core",
|
|
3686
4085
|
method: ROUTES.detail.method,
|
|
3687
|
-
body:
|
|
4086
|
+
body: bodyOf(ROUTES.detail),
|
|
3688
4087
|
purity: "pure",
|
|
3689
4088
|
read: "raw",
|
|
3690
4089
|
response: "json",
|
|
@@ -3704,7 +4103,7 @@ function routeOf(rest) {
|
|
|
3704
4103
|
/**
|
|
3705
4104
|
* /dsh-session-delete-api 的分发核心:只负责路由记录的执行。
|
|
3706
4105
|
*
|
|
3707
|
-
* 传输适配器只有 `src/api/connection-route.ts`
|
|
4106
|
+
* 传输适配器只有 `src/api/connection-route.ts` 一个:十段注册到宿主 `connection.fetch.register`
|
|
3708
4107
|
* 的 exact Fetch 路由(`Request` / `Response`),Host/Origin/浏览器认证由宿主 `/api` bridge 完成
|
|
3709
4108
|
* (ADR-0033)。`Request` 的字节闸 / JSON 解析、`Response` 的头与失败信封都归适配器;
|
|
3710
4109
|
* 这里只收已经解析好的请求,做查表 → 按段注入窄面 → 跑处理 → 回结果。
|
|
@@ -3731,21 +4130,12 @@ function isPure(purity, body) {
|
|
|
3731
4130
|
}
|
|
3732
4131
|
/**
|
|
3733
4132
|
* 全量面按行收窄(ADR-0032):组合根装出的 {@link DeleteDeps} 只交给 `/apply`;每一段只拿到
|
|
3734
|
-
* 自己声明的那一格(路由表的 `slice
|
|
4133
|
+
* 自己声明的那一格(路由表的 `slice`)。收窄是**运行期事实**,不是类型投影:`core` 的 fs 由
|
|
4134
|
+
* `FS_CORE_METHODS` 现切,删除能力根本不在对象上。
|
|
3735
4135
|
*/
|
|
3736
|
-
function
|
|
4136
|
+
function coreDepsOf(full) {
|
|
3737
4137
|
return {
|
|
3738
|
-
fs:
|
|
3739
|
-
exists: (p) => full.fs.exists(p),
|
|
3740
|
-
ensureDir: (p) => full.fs.ensureDir(p),
|
|
3741
|
-
rename: (from, to) => full.fs.rename(from, to),
|
|
3742
|
-
sizeOfDir: (p) => full.fs.sizeOfDir(p),
|
|
3743
|
-
listFiles: (p) => full.fs.listFiles(p),
|
|
3744
|
-
listDirs: (p) => full.fs.listDirs(p),
|
|
3745
|
-
realpath: (p) => full.fs.realpath(p),
|
|
3746
|
-
readFile: (p) => full.fs.readFile(p),
|
|
3747
|
-
statFile: (p) => full.fs.statFile(p)
|
|
3748
|
-
},
|
|
4138
|
+
fs: fsSlice(full.fs, FS_CORE_METHODS),
|
|
3749
4139
|
host: full.host,
|
|
3750
4140
|
ledger: full.ledger,
|
|
3751
4141
|
home: full.home,
|
|
@@ -3753,27 +4143,30 @@ function coreOf(full) {
|
|
|
3753
4143
|
config: full.config
|
|
3754
4144
|
};
|
|
3755
4145
|
}
|
|
3756
|
-
/** `removal` 保留删除能力,但不带会话删除的时钟;`full` 只给 `/apply`。
|
|
3757
|
-
|
|
4146
|
+
/** `removal` 保留删除能力,但不带会话删除的时钟;`full` 只给 `/apply`。fs 与 `core` 同一条:
|
|
4147
|
+
* 按 `FS_CORE_METHODS + FS_REMOVAL_METHODS` 现切——ADR-0032 的收窄是运行期事实,不是把
|
|
4148
|
+
* `full.fs` 的类型改一改。 */
|
|
4149
|
+
function removalOf(full, core) {
|
|
3758
4150
|
return {
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
ledger: full.ledger,
|
|
3762
|
-
home: full.home,
|
|
3763
|
-
presence: full.presence,
|
|
3764
|
-
config: full.config
|
|
4151
|
+
...core,
|
|
4152
|
+
fs: fsSlice(full.fs, [...FS_CORE_METHODS, ...FS_REMOVAL_METHODS])
|
|
3765
4153
|
};
|
|
3766
4154
|
}
|
|
3767
|
-
/**
|
|
4155
|
+
/** 五格只建一次:收窄对象在 dispatcher 构造期固定,请求路径只做引用选择。 */
|
|
3768
4156
|
function slicesOf(full) {
|
|
3769
|
-
const core =
|
|
4157
|
+
const core = coreDepsOf(full);
|
|
3770
4158
|
return {
|
|
3771
4159
|
core,
|
|
3772
|
-
removal: removalOf(full),
|
|
4160
|
+
removal: removalOf(full, core),
|
|
3773
4161
|
full,
|
|
3774
4162
|
attachment: {
|
|
3775
4163
|
...core,
|
|
3776
4164
|
attachments: full.attachments
|
|
4165
|
+
},
|
|
4166
|
+
config: {
|
|
4167
|
+
...core,
|
|
4168
|
+
...full.configEditor === void 0 ? {} : { configEditor: full.configEditor },
|
|
4169
|
+
...full.entry === void 0 ? {} : { entry: full.entry }
|
|
3777
4170
|
}
|
|
3778
4171
|
};
|
|
3779
4172
|
}
|
|
@@ -3824,7 +4217,7 @@ function createDispatcher(deps) {
|
|
|
3824
4217
|
//#endregion
|
|
3825
4218
|
//#region src/api/connection-route.ts
|
|
3826
4219
|
/**
|
|
3827
|
-
* 现代宿主的 exact Fetch
|
|
4220
|
+
* 现代宿主的 exact Fetch 路由适配器:把十段注册到 `connection.fetch.register`,
|
|
3828
4221
|
* 由宿主 `/api` bridge 做 Host/Origin/浏览器认证(ADR-0033)。
|
|
3829
4222
|
*
|
|
3830
4223
|
* 为什么路径必须带 `/api`:宿主 `assertFetchRoute` 用 `endpointFromPath('/api', path)` 校验,
|
|
@@ -3963,7 +4356,7 @@ function toResponse(result) {
|
|
|
3963
4356
|
});
|
|
3964
4357
|
}
|
|
3965
4358
|
/**
|
|
3966
|
-
*
|
|
4359
|
+
* 注册十段 exact Fetch 路由。返回一个组合 disposer;调用方把它挂在自己的 effect 上。
|
|
3967
4360
|
* `connection` 是插件的硬依赖(web UI / 桌面端都装 `client-connection`);`fetch.register`
|
|
3968
4361
|
* 缺席属于宿主形状漂移,直接抛——静默返回空 disposer 会让插件「在但没有入口」。
|
|
3969
4362
|
* `dispatch` 与分发器同源。
|
|
@@ -4007,64 +4400,6 @@ function registerConnectionRoutes(service, dispatch) {
|
|
|
4007
4400
|
return disposeAll;
|
|
4008
4401
|
}
|
|
4009
4402
|
//#endregion
|
|
4010
|
-
//#region src/config.ts
|
|
4011
|
-
const DEFAULT_CONFIG = Object.freeze({
|
|
4012
|
-
orphanPreviewLimit: 200,
|
|
4013
|
-
maxAttachmentBytes: 20971520,
|
|
4014
|
-
maxJsonRefBytes: 10485760
|
|
4015
|
-
});
|
|
4016
|
-
const LIMITS = {
|
|
4017
|
-
orphanPreviewLimit: {
|
|
4018
|
-
min: 1,
|
|
4019
|
-
max: 1e4
|
|
4020
|
-
},
|
|
4021
|
-
maxAttachmentBytes: {
|
|
4022
|
-
min: 1,
|
|
4023
|
-
max: 209715200
|
|
4024
|
-
},
|
|
4025
|
-
maxJsonRefBytes: {
|
|
4026
|
-
min: 1,
|
|
4027
|
-
max: 104857600
|
|
4028
|
-
}
|
|
4029
|
-
};
|
|
4030
|
-
function intField(input, key, range) {
|
|
4031
|
-
const value = input[key];
|
|
4032
|
-
if (value === void 0) return DEFAULT_CONFIG[key];
|
|
4033
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < range.min || value > range.max) throw new Error(`配置项 ${key} 需为 ${range.min}..${range.max} 的整数`);
|
|
4034
|
-
return value;
|
|
4035
|
-
}
|
|
4036
|
-
/**
|
|
4037
|
-
* 把 patch 里的 `config` 归一成完整配置:缺省取默认值,未知键 / 非整数 / 越界都抛。
|
|
4038
|
-
* 抛错会让插件激活失败(响亮),而不是悄悄用半套配置跑。
|
|
4039
|
-
*/
|
|
4040
|
-
function normalizeConfig(value) {
|
|
4041
|
-
if (value === void 0 || value === null) return DEFAULT_CONFIG;
|
|
4042
|
-
if (typeof value !== "object" || Array.isArray(value)) throw new Error("配置需为对象");
|
|
4043
|
-
const input = value;
|
|
4044
|
-
const known = new Set(Object.keys(LIMITS));
|
|
4045
|
-
for (const key of Object.keys(input)) if (!known.has(key)) throw new Error(`未知配置项:${key}`);
|
|
4046
|
-
return {
|
|
4047
|
-
orphanPreviewLimit: intField(input, "orphanPreviewLimit", LIMITS.orphanPreviewLimit),
|
|
4048
|
-
maxAttachmentBytes: intField(input, "maxAttachmentBytes", LIMITS.maxAttachmentBytes),
|
|
4049
|
-
maxJsonRefBytes: intField(input, "maxJsonRefBytes", LIMITS.maxJsonRefBytes)
|
|
4050
|
-
};
|
|
4051
|
-
}
|
|
4052
|
-
/**
|
|
4053
|
-
* 插件 Config:Cordis 接受 Standard Schema,`~standard.validate` 交回归一后的配置。
|
|
4054
|
-
* 宿主在激活前校验;`apply` 再归一一次(同一份事实,不会漂)。
|
|
4055
|
-
*/
|
|
4056
|
-
const Config = { "~standard": {
|
|
4057
|
-
version: 1,
|
|
4058
|
-
vendor: "dsh-session-delete",
|
|
4059
|
-
validate(value) {
|
|
4060
|
-
try {
|
|
4061
|
-
return { value: normalizeConfig(value) };
|
|
4062
|
-
} catch (error) {
|
|
4063
|
-
return { issues: [{ message: error instanceof Error ? error.message : String(error) }] };
|
|
4064
|
-
}
|
|
4065
|
-
}
|
|
4066
|
-
} };
|
|
4067
|
-
//#endregion
|
|
4068
4403
|
//#region src/ports/home.ts
|
|
4069
4404
|
/**
|
|
4070
4405
|
* 宿主数据根。官方解析器在 asar `dsh/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js`:
|
|
@@ -4164,11 +4499,11 @@ async function buildEntry(deps, id) {
|
|
|
4164
4499
|
return;
|
|
4165
4500
|
}
|
|
4166
4501
|
const { deletedAt, sessionDirName } = parseEntryId(id);
|
|
4167
|
-
const cwd = typeof header.cwd === "string" ? header.cwd :
|
|
4502
|
+
const cwd = typeof header.cwd === "string" ? header.cwd : void 0;
|
|
4168
4503
|
return {
|
|
4169
4504
|
id,
|
|
4170
4505
|
sessionId: typeof header.id === "string" && header.id !== "" ? header.id : sessionDirName,
|
|
4171
|
-
projectDir:
|
|
4506
|
+
projectDir: projectDirOfCwd(cwd),
|
|
4172
4507
|
workspaceId: "",
|
|
4173
4508
|
wasArchived: false,
|
|
4174
4509
|
deletedAt,
|
|
@@ -4330,7 +4665,7 @@ const name = "@xrn1997/dsh-session-delete";
|
|
|
4330
4665
|
* - `agents`:只给 handle 捕获用(`ctx.get('agents')`;缺席时 `ctx.inject(['agents'])` 等服务就绪再装)。
|
|
4331
4666
|
* 它同样可能晚于本插件激活,写进插件 inject 只会让整个插件 pending。
|
|
4332
4667
|
*
|
|
4333
|
-
* `connection`
|
|
4668
|
+
* `connection` 是浏览器半取数通道的唯一承载者:十段注册到 `connection.fetch.register` 的
|
|
4334
4669
|
* `/api/dsh-session-delete-api/*`,Host/Origin/浏览器认证由宿主 `/api` bridge 完成(ADR-0033)。
|
|
4335
4670
|
* 支持面是 web UI 与桌面端,二者的标准组合都装 `client-connection`;服务缺席时插件停在 pending
|
|
4336
4671
|
* ——可见的激活失败,而不是静默地没有入口。`webServer` 不再直接使用:exact route 仍由宿主的
|
|
@@ -4358,6 +4693,8 @@ function apply(ctx, rawConfig) {
|
|
|
4358
4693
|
const home = resolveHome();
|
|
4359
4694
|
const rawManifest = createHostStorageManifest(ctx);
|
|
4360
4695
|
const host = createHostPort(ctx);
|
|
4696
|
+
const configEditor = ctx.get("configEditor");
|
|
4697
|
+
const entry = ctx.fiber?.entry;
|
|
4361
4698
|
const deps = {
|
|
4362
4699
|
fs,
|
|
4363
4700
|
host,
|
|
@@ -4366,7 +4703,9 @@ function apply(ctx, rawConfig) {
|
|
|
4366
4703
|
presence: createMemberPresence(host),
|
|
4367
4704
|
config,
|
|
4368
4705
|
attachments: createAttachmentsPort(ctx),
|
|
4369
|
-
now: () => Date.now()
|
|
4706
|
+
now: () => Date.now(),
|
|
4707
|
+
...configEditor === void 0 ? {} : { configEditor },
|
|
4708
|
+
...entry === void 0 ? {} : { entry }
|
|
4370
4709
|
};
|
|
4371
4710
|
const connection = ctx.get("connection");
|
|
4372
4711
|
if (connection === void 0) throw new Error("session-delete: connection 服务缺席");
|