@xrn1997/dsh-session-delete 0.7.0 → 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 +1 -1
- package/lib/client.js +2179 -1220
- package/lib/index.js +390 -186
- package/lib/types/api/attachment.d.ts +2 -2
- package/lib/types/api/route-table.d.ts +2 -2
- 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/confirm-dialog.d.ts +23 -0
- package/lib/types/client/context-menu-actions.d.ts +11 -5
- package/lib/types/client/copy.d.ts +13 -1
- 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/plugin.d.ts +6 -0
- package/lib/types/client/prompt-rail.d.ts +22 -0
- package/lib/types/client/remote.d.ts +48 -95
- 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/trash-detail.d.ts +13 -3
- package/lib/types/client/trash-snapshot.d.ts +51 -0
- package/lib/types/client/trash-view.d.ts +2 -1
- 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 +7 -3
- 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/deps.d.ts +2 -2
- package/lib/types/log/session-log.d.ts +2 -0
- 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 +56 -20
- 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/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
|
@@ -23,10 +23,10 @@ const SESSION_DELETE_API_PREFIX = "/dsh-session-delete-api";
|
|
|
23
23
|
* 都从它起;`SESSION_DELETE_API_PREFIX` 只作为段名的相对前缀与错误原文。
|
|
24
24
|
*/
|
|
25
25
|
const OFFICIAL_SESSION_DELETE_API_PREFIX = `/api${SESSION_DELETE_API_PREFIX}`;
|
|
26
|
-
/** 十段段名(相对前缀)。**每项 `{ path, method }`
|
|
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,59 +36,69 @@ 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
41
|
* - `attachmentClean`:清掉报告那一刻无引用的图片对象(聚合回执 `AttachmentCleanupWire`)。
|
|
42
42
|
* - `config`:三只可调项的读/写共用一段——空体读当前值,带字段写回 profile 的 patch 层。 */
|
|
43
43
|
const ROUTES = {
|
|
44
44
|
list: {
|
|
45
45
|
path: "/list",
|
|
46
|
-
method: "GET"
|
|
46
|
+
method: "GET",
|
|
47
|
+
body: "none"
|
|
47
48
|
},
|
|
48
49
|
/** 通道的"在不在"专用:没有入参、没有副作用、没有磁盘读。 */
|
|
49
50
|
ping: {
|
|
50
51
|
path: "/ping",
|
|
51
|
-
method: "GET"
|
|
52
|
+
method: "GET",
|
|
53
|
+
body: "none"
|
|
52
54
|
},
|
|
53
55
|
/** 可调项:空体读(与 `/detail` 同法,用 POST 表达一个读);带字段写,写必须进到达序链。 */
|
|
54
56
|
config: {
|
|
55
57
|
path: "/config",
|
|
56
|
-
method: "POST"
|
|
58
|
+
method: "POST",
|
|
59
|
+
body: "config"
|
|
57
60
|
},
|
|
58
61
|
/** 单条详情(读回收站目录里那条会话自己的日志)。 */
|
|
59
62
|
detail: {
|
|
60
63
|
path: "/detail",
|
|
61
|
-
method: "POST"
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: "entry"
|
|
62
66
|
},
|
|
63
67
|
/** 一组 id 上的同一个动作;删除确认框那句「含 N 个子会话」也走这里(`action: 'count'`,纯读语义)。 */
|
|
64
68
|
apply: {
|
|
65
69
|
path: "/apply",
|
|
66
|
-
method: "POST"
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: "apply"
|
|
67
72
|
},
|
|
68
73
|
/** 清空回收站。 */
|
|
69
74
|
empty: {
|
|
70
75
|
path: "/empty",
|
|
71
|
-
method: "POST"
|
|
76
|
+
method: "POST",
|
|
77
|
+
body: "none"
|
|
72
78
|
},
|
|
73
79
|
/** 纯读:扫描回收站之外的无主子会话(父已不在语料/清册)。 */
|
|
74
80
|
orphans: {
|
|
75
81
|
path: "/orphans",
|
|
76
|
-
method: "GET"
|
|
82
|
+
method: "GET",
|
|
83
|
+
body: "none"
|
|
77
84
|
},
|
|
78
|
-
/**
|
|
85
|
+
/** 附件字节(图片/普通文件):全仓唯一的二进制响应段,按查询串寻址。 */
|
|
79
86
|
attachment: {
|
|
80
87
|
path: "/attachment",
|
|
81
|
-
method: "GET"
|
|
88
|
+
method: "GET",
|
|
89
|
+
body: "query"
|
|
82
90
|
},
|
|
83
91
|
/** 纯读:扫全部引用源与附件库 `objects`,报无引用图片的数量、字节与预览清单。 */
|
|
84
92
|
attachmentOrphans: {
|
|
85
93
|
path: "/attachment-orphans",
|
|
86
|
-
method: "GET"
|
|
94
|
+
method: "GET",
|
|
95
|
+
body: "none"
|
|
87
96
|
},
|
|
88
97
|
/** 聚合清理:只删 `objects` 下无引用的图片,回 `AttachmentCleanupWire`。 */
|
|
89
98
|
attachmentClean: {
|
|
90
99
|
path: "/attachment-clean",
|
|
91
|
-
method: "POST"
|
|
100
|
+
method: "POST",
|
|
101
|
+
body: "none"
|
|
92
102
|
}
|
|
93
103
|
};
|
|
94
104
|
/** 三只可调项的接受范围(闭区间整数)。Node 半的归一与浏览器半的表单共用这一格:
|
|
@@ -131,8 +141,11 @@ const PARAMS = {
|
|
|
131
141
|
* 位名与判法取自宿主网关客户端面的原文:
|
|
132
142
|
* `if (typeof value === "object" && value !== null && value.isDSHRemoteError === true && typeof value.code === "string") return value`。
|
|
133
143
|
*
|
|
134
|
-
* 线上递过来的是**一段 JSON**(标记位不跟着过线)⇒
|
|
135
|
-
*
|
|
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`)。
|
|
136
149
|
*/
|
|
137
150
|
function isDSHRemoteError(value) {
|
|
138
151
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -179,6 +192,113 @@ function verbCodeOf(error) {
|
|
|
179
192
|
/** 回收站目录名(相对宿主数据根)。Node 半拼路径,浏览器半在页脚念它——同一个字面量。 */
|
|
180
193
|
const TRASH_DIR_NAME = "session-trash";
|
|
181
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
|
|
182
302
|
//#region src/verbs/errors.ts
|
|
183
303
|
/** 失败的**结构与措辞**。码本身、码的前缀读法与动词词表都住在 `shared/wire.ts`(ADR-0003):
|
|
184
304
|
* 浏览器半也要认它们,它们属于两半共同的契约,不属于 Node 半。这里只做动词抛错与回滚措辞。 */
|
|
@@ -950,92 +1070,6 @@ async function memberMove(deps, presence, member, deletedAt, parentEntryId) {
|
|
|
950
1070
|
};
|
|
951
1071
|
}
|
|
952
1072
|
//#endregion
|
|
953
|
-
//#region src/ports/fs-port.ts
|
|
954
|
-
/**
|
|
955
|
-
* **缺席**只认 ENOENT 与 ENOTDIR("路径中间有一截不是目录"与"不存在"是同一种回答)。
|
|
956
|
-
*
|
|
957
|
-
* EACCES / EIO / ELOOP / 断挂载**不是缺席**:这些读数说明"我们看不见",不是"那里没有"。
|
|
958
|
-
* 破坏性动作(删目录、删附件对象、按"没有引用"清共享图)据此做决定,把读不出折成没有
|
|
959
|
-
* 就是数据消失;ADR-0039 是这条判据的裁决。
|
|
960
|
-
*/
|
|
961
|
-
function isAbsentPath(error) {
|
|
962
|
-
const code = error?.code;
|
|
963
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
964
|
-
}
|
|
965
|
-
/** 模块级递归:端口方法**解构出来单独调**也不能靠 `this`(`{ sizeOfDir } = port` 会让方法体的
|
|
966
|
-
* `this` 变成 undefined)。所以端口只做转发,递归在模块作用域里自调。 */
|
|
967
|
-
async function sizeOfDir(p) {
|
|
968
|
-
let total = 0;
|
|
969
|
-
for (const e of await readdir(p, { withFileTypes: true })) {
|
|
970
|
-
const child = join(p, e.name);
|
|
971
|
-
total += e.isDirectory() ? await sizeOfDir(child) : (await stat(child)).size;
|
|
972
|
-
}
|
|
973
|
-
return total;
|
|
974
|
-
}
|
|
975
|
-
/** 路径在不在:只有缺席两种错误回 `false`,其余读错误照抛。`exists` 与 `rename` 的目标检查共用。 */
|
|
976
|
-
async function pathPresent(p) {
|
|
977
|
-
try {
|
|
978
|
-
await stat(p);
|
|
979
|
-
return true;
|
|
980
|
-
} catch (error) {
|
|
981
|
-
if (isAbsentPath(error)) return false;
|
|
982
|
-
throw error;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
function createFsPort() {
|
|
986
|
-
return {
|
|
987
|
-
exists: pathPresent,
|
|
988
|
-
async ensureDir(p) {
|
|
989
|
-
await mkdir(p, { recursive: true });
|
|
990
|
-
},
|
|
991
|
-
async rename(from, to) {
|
|
992
|
-
if (await pathPresent(to)) throw new Error(`目标已存在,拒绝覆盖:${to}`);
|
|
993
|
-
try {
|
|
994
|
-
await rename(from, to);
|
|
995
|
-
} catch (error) {
|
|
996
|
-
if (error.code === "EXDEV") throw new Error(`跨文件系统搬不动(sessions 与 session-trash 需在同一卷):${from} → ${to}`, { cause: error });
|
|
997
|
-
throw error;
|
|
998
|
-
}
|
|
999
|
-
},
|
|
1000
|
-
async removeDir(p) {
|
|
1001
|
-
await rm(p, {
|
|
1002
|
-
recursive: true,
|
|
1003
|
-
force: true
|
|
1004
|
-
});
|
|
1005
|
-
},
|
|
1006
|
-
sizeOfDir: (p) => sizeOfDir(p),
|
|
1007
|
-
async listFiles(p) {
|
|
1008
|
-
return readdir(p);
|
|
1009
|
-
},
|
|
1010
|
-
async listDirs(p) {
|
|
1011
|
-
const dirs = [];
|
|
1012
|
-
for (const entry of await readdir(p, { withFileTypes: true })) {
|
|
1013
|
-
if (entry.isDirectory()) {
|
|
1014
|
-
dirs.push(entry.name);
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
if (!entry.isSymbolicLink()) continue;
|
|
1018
|
-
try {
|
|
1019
|
-
if ((await stat(join(p, entry.name))).isDirectory()) dirs.push(entry.name);
|
|
1020
|
-
} catch {}
|
|
1021
|
-
}
|
|
1022
|
-
return dirs;
|
|
1023
|
-
},
|
|
1024
|
-
async realpath(p) {
|
|
1025
|
-
return realpath(p);
|
|
1026
|
-
},
|
|
1027
|
-
async readFile(p) {
|
|
1028
|
-
return readFile(p);
|
|
1029
|
-
},
|
|
1030
|
-
async statFile(p) {
|
|
1031
|
-
return { size: (await stat(p)).size };
|
|
1032
|
-
},
|
|
1033
|
-
async removeFile(p) {
|
|
1034
|
-
await rm(p, { force: true });
|
|
1035
|
-
}
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
//#endregion
|
|
1039
1073
|
//#region src/log/zstd-frames.ts
|
|
1040
1074
|
const MAGIC = [
|
|
1041
1075
|
40,
|
|
@@ -2297,6 +2331,52 @@ function captureAgentHandles(ctx) {
|
|
|
2297
2331
|
} };
|
|
2298
2332
|
}
|
|
2299
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
|
|
2300
2380
|
//#region src/ports/host-port.ts
|
|
2301
2381
|
/** live store 的最小方法面判据(同 `projectionCacheOf` 的手法:按方法面判,不按 constructor.name)。 */
|
|
2302
2382
|
function liveSessionsOf(ctx) {
|
|
@@ -2320,6 +2400,12 @@ async function headerOf(host, sessionId) {
|
|
|
2320
2400
|
if (persistence === void 0 || persistence === null || typeof persistence.stat !== "function") throw new Error("session-delete: sessionPersistence 服务缺席");
|
|
2321
2401
|
return (await persistence.stat(sessionId))?.header;
|
|
2322
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
|
+
}
|
|
2323
2409
|
/** 官方的「这些父的孩子」那一支:`kind:'parent'` 的判据逐字是 `values.includes(record.header.parentSession ?? null)`。
|
|
2324
2410
|
* 它只按 `parentSession` 原样匹配,**不是**子会话分类器:旧宿主(≤0.2.1-rc.5)的普通 fork 也写
|
|
2325
2411
|
* `parentSession`,0.2.2-alpha.2 起才不写。子会话的判据是 `origin` 的 subagent 标记(宿主归档闸、归档
|
|
@@ -2357,7 +2443,7 @@ async function descendantsByParent(sessionQuery, roots) {
|
|
|
2357
2443
|
const cwd = record.header.cwd;
|
|
2358
2444
|
const descendant = {
|
|
2359
2445
|
sessionId: id,
|
|
2360
|
-
projectDir:
|
|
2446
|
+
projectDir: projectDirOfCwd(cwd)
|
|
2361
2447
|
};
|
|
2362
2448
|
const parentBare = bareSessionId(parent);
|
|
2363
2449
|
const siblings = children.get(parentBare);
|
|
@@ -2381,32 +2467,20 @@ async function membersFor(sessionQuery, parentIds) {
|
|
|
2381
2467
|
for (const id of wanted) out[id] = closureOf(children, id);
|
|
2382
2468
|
return out;
|
|
2383
2469
|
}
|
|
2384
|
-
/**
|
|
2385
|
-
*
|
|
2386
|
-
const NO_CWD_PROJECT_DIR = "_no-cwd";
|
|
2387
|
-
/** 宿主 `projectKey(cwd)` 的逐字镜像:跨插件不能 import,宿主也没把它暴露成服务。
|
|
2388
|
-
* 出处:asar `dsh-session-persistence-jsonl/lib/index.js` 的 `projectKey`;调用链
|
|
2389
|
-
* `locate` → `logPath` → `projectDir` → `projectKey`。本机实测 `D:/develop/GitHub/dsh-session-delete`
|
|
2390
|
-
* → `--D-develop-GitHub-dsh-session-delete--`。`projectDirOf` 与回收站对账重建共用这一份;
|
|
2470
|
+
/** 宿主 `projectKey(cwd)` 的逐字镜像:编码与解码配对住在 `src/shared/project-key.ts`
|
|
2471
|
+
* (字母表只有一份;解码给浏览器半渲染回收站组头)。`projectDirOf` 与回收站对账重建共用这一份;
|
|
2391
2472
|
* 宿主换代先复核算法。 */
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
separatorRun = false;
|
|
2404
|
-
} else {
|
|
2405
|
-
readable += `~${code.toString(16).toUpperCase().padStart(4, "0")}`;
|
|
2406
|
-
separatorRun = false;
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
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);
|
|
2410
2484
|
}
|
|
2411
2485
|
/** 投影缓存服务的最小方法面判据(按方法面判,不按 `constructor.name` 判)。 */
|
|
2412
2486
|
function projectionCacheOf(ctx) {
|
|
@@ -2462,15 +2536,20 @@ function createHostPort(ctx) {
|
|
|
2462
2536
|
async projectDirOf(sessionId) {
|
|
2463
2537
|
const header = await headerOf(host, sessionId);
|
|
2464
2538
|
if (header === void 0) return void 0;
|
|
2465
|
-
return
|
|
2539
|
+
return projectDirOfCwd(header.cwd);
|
|
2466
2540
|
},
|
|
2467
|
-
/**
|
|
2541
|
+
/** 显示名走宿主投影缓存(与工作中同名):子会话取 `subagent` 投影的 label,其余取 `title` 行的
|
|
2542
|
+
* **视图值**(缓存整条未命中才回落 predecessor 标题)。header 来自公开的 live/持久化读面,
|
|
2543
|
+
* 尽力取,取不到返回空串。 */
|
|
2468
2544
|
async titleOf(sessionId) {
|
|
2469
2545
|
try {
|
|
2470
2546
|
const header = await headerOf(host, sessionId);
|
|
2471
2547
|
if (header === void 0) return "";
|
|
2472
2548
|
const cache = projectionCacheOf(host);
|
|
2473
|
-
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;
|
|
2474
2553
|
return typeof title === "string" ? title : "";
|
|
2475
2554
|
} catch {
|
|
2476
2555
|
return "";
|
|
@@ -2583,7 +2662,7 @@ function createHostPort(ctx) {
|
|
|
2583
2662
|
out.push({
|
|
2584
2663
|
sessionId: id,
|
|
2585
2664
|
...typeof parent === "string" && parent !== "" ? { parentSessionId: parent } : {},
|
|
2586
|
-
projectDir:
|
|
2665
|
+
projectDir: projectDirOfCwd(cwd),
|
|
2587
2666
|
subagent: record.header?.origin === "subagent"
|
|
2588
2667
|
});
|
|
2589
2668
|
}
|
|
@@ -3007,6 +3086,45 @@ async function saveConfig(deps, patch) {
|
|
|
3007
3086
|
return next;
|
|
3008
3087
|
}
|
|
3009
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
|
|
3010
3128
|
//#region src/trash/detail.ts
|
|
3011
3129
|
/**
|
|
3012
3130
|
* 回收站**单条详情**:从回收站目录里那条会话自己的日志读出元信息与正文块(用例见 `tests/trash-detail.test.ts`)。
|
|
@@ -3079,6 +3197,16 @@ function clip(text, cap) {
|
|
|
3079
3197
|
function hasContent(text, attachments) {
|
|
3080
3198
|
return text !== "" || attachments.length > 0;
|
|
3081
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
|
+
}
|
|
3082
3210
|
/** 一块的正文:没内容 ⇒ 这块不建;否则过单块闸截一刀。 */
|
|
3083
3211
|
function blockBody(rawText, attachments, cap) {
|
|
3084
3212
|
const text = rawText.trim();
|
|
@@ -3154,20 +3282,23 @@ var PageBuilder = class PageBuilder {
|
|
|
3154
3282
|
this.cap = cap;
|
|
3155
3283
|
this.pageChars = pageChars;
|
|
3156
3284
|
}
|
|
3157
|
-
/**
|
|
3285
|
+
/** 追加一块并回它在整条日志里的序号:id 用这个序号盖,页内只留最后 `limit` 块 / `pageChars` 字符。
|
|
3286
|
+
* 返回值**不管这块进没进页**都给(提问索引要拿它当游标),所以调用方不能拿返回值为空当"没入页"。 */
|
|
3158
3287
|
add(block) {
|
|
3159
3288
|
const index = this.nextIndex++;
|
|
3160
|
-
if (index
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
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);
|
|
3171
3302
|
}
|
|
3172
3303
|
/** 挤出页首:块数超限,或正文超字符闸(但至少留一块,游标才能前进)。 */
|
|
3173
3304
|
trim() {
|
|
@@ -3248,6 +3379,22 @@ var PageBuilder = class PageBuilder {
|
|
|
3248
3379
|
};
|
|
3249
3380
|
}
|
|
3250
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
|
+
}
|
|
3251
3398
|
function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
3252
3399
|
return async function readTrashDetail(entryId, before) {
|
|
3253
3400
|
const all = await deps.rows();
|
|
@@ -3280,6 +3427,18 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3280
3427
|
olderCursor: null
|
|
3281
3428
|
};
|
|
3282
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 = [];
|
|
3283
3442
|
const page = new PageBuilder(before ?? Number.POSITIVE_INFINITY, Math.max(1, limits.pageBlocks), limits.perBlockChars, Math.max(1, limits.pageChars ?? 5e5));
|
|
3284
3443
|
try {
|
|
3285
3444
|
walkSessionLog(raw, (r) => {
|
|
@@ -3290,10 +3449,20 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3290
3449
|
case "session":
|
|
3291
3450
|
if (typeof r.cwd === "string") detail.cwd = r.cwd;
|
|
3292
3451
|
if (typeof r.createdAt === "number") detail.createdAt = r.createdAt;
|
|
3452
|
+
if (typeof r.parentSession === "string" && r.parentSession !== "") ownParentSession = true;
|
|
3293
3453
|
return;
|
|
3294
3454
|
case "session/title":
|
|
3295
3455
|
if (typeof data.title === "string") detail.logTitle = data.title;
|
|
3296
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;
|
|
3297
3466
|
case "turn/start":
|
|
3298
3467
|
detail.turnCount += 1;
|
|
3299
3468
|
return;
|
|
@@ -3306,7 +3475,12 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3306
3475
|
const block = textBlock("user", time, text, attachments, limits.perBlockChars);
|
|
3307
3476
|
if (block !== void 0) {
|
|
3308
3477
|
detail.userMessageCount += 1;
|
|
3309
|
-
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
|
+
});
|
|
3310
3484
|
}
|
|
3311
3485
|
return;
|
|
3312
3486
|
}
|
|
@@ -3397,11 +3571,38 @@ function readTrashDetail(deps, limits = DEFAULT_LIMITS) {
|
|
|
3397
3571
|
const finished = page.finish();
|
|
3398
3572
|
detail.blocks = finished.blocks;
|
|
3399
3573
|
detail.olderCursor = finished.olderCursor;
|
|
3574
|
+
if (before === void 0) detail.prompts = prompts;
|
|
3400
3575
|
detail.models = [...models];
|
|
3576
|
+
const ownDisplayName = ownLabel !== "" ? ownLabel : ownParentSession ? detail.logTitle : "";
|
|
3577
|
+
if (ownDisplayName !== "") detail.label = ownDisplayName;
|
|
3401
3578
|
const kids = visibleGroups(all).find((group) => group.root.id === record.id)?.kids ?? [];
|
|
3402
3579
|
if (kids.length > 0) {
|
|
3403
3580
|
const limit = limits.subagents ?? 200;
|
|
3404
|
-
|
|
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);
|
|
3405
3606
|
if (kids.length > limit) detail.subagentsTotal = kids.length;
|
|
3406
3607
|
}
|
|
3407
3608
|
return detail;
|
|
@@ -3722,9 +3923,23 @@ async function assembleTrashRows(deps, rows) {
|
|
|
3722
3923
|
* - 切片声明宽了 ⇒ 危险能力(删目录 / 时钟)漏进读段的 run;窄了 ⇒ 写段的处理编译不过。
|
|
3723
3924
|
*
|
|
3724
3925
|
* 这张表不放 shared/wire.ts:处理函数会 import 动词与 node:fs,而浏览器半要 import wire.ts。
|
|
3725
|
-
*
|
|
3726
|
-
*
|
|
3926
|
+
* 段名、方法与请求体形状住 wire.ts(`ROUTES` 每项 `{ path, method, body }`,本表的 method / body 只投影、
|
|
3927
|
+
* 不写第二份字面量);这张表只回答“怎么处理”。
|
|
3727
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
|
+
}
|
|
3728
3943
|
/** 必填的非空字符串字段(缺、空串、类型不对都是**同一句话**:说清是哪个字段)。 */
|
|
3729
3944
|
function requireString(body, field) {
|
|
3730
3945
|
const value = body?.[field];
|
|
@@ -3781,7 +3996,7 @@ const ROUTE_TABLE = {
|
|
|
3781
3996
|
[ROUTES.list.path]: {
|
|
3782
3997
|
slice: "core",
|
|
3783
3998
|
method: ROUTES.list.method,
|
|
3784
|
-
body:
|
|
3999
|
+
body: bodyOf(ROUTES.list),
|
|
3785
4000
|
purity: "chained",
|
|
3786
4001
|
read: "list",
|
|
3787
4002
|
response: "json",
|
|
@@ -3790,7 +4005,7 @@ const ROUTE_TABLE = {
|
|
|
3790
4005
|
[ROUTES.ping.path]: {
|
|
3791
4006
|
slice: "core",
|
|
3792
4007
|
method: ROUTES.ping.method,
|
|
3793
|
-
body:
|
|
4008
|
+
body: bodyOf(ROUTES.ping),
|
|
3794
4009
|
purity: "pure",
|
|
3795
4010
|
read: "none",
|
|
3796
4011
|
response: "json",
|
|
@@ -3799,7 +4014,7 @@ const ROUTE_TABLE = {
|
|
|
3799
4014
|
[ROUTES.config.path]: {
|
|
3800
4015
|
slice: "config",
|
|
3801
4016
|
method: ROUTES.config.method,
|
|
3802
|
-
body:
|
|
4017
|
+
body: bodyOf(ROUTES.config),
|
|
3803
4018
|
purity: (body) => configPatchOf(body) === void 0 ? "pure" : "chained",
|
|
3804
4019
|
read: "none",
|
|
3805
4020
|
response: "json",
|
|
@@ -3808,7 +4023,7 @@ const ROUTE_TABLE = {
|
|
|
3808
4023
|
[ROUTES.attachment.path]: {
|
|
3809
4024
|
slice: "attachment",
|
|
3810
4025
|
method: ROUTES.attachment.method,
|
|
3811
|
-
body:
|
|
4026
|
+
body: bodyOf(ROUTES.attachment),
|
|
3812
4027
|
purity: "pure",
|
|
3813
4028
|
read: "none",
|
|
3814
4029
|
response: "binary",
|
|
@@ -3818,7 +4033,7 @@ const ROUTE_TABLE = {
|
|
|
3818
4033
|
[ROUTES.attachmentOrphans.path]: {
|
|
3819
4034
|
slice: "core",
|
|
3820
4035
|
method: ROUTES.attachmentOrphans.method,
|
|
3821
|
-
body:
|
|
4036
|
+
body: bodyOf(ROUTES.attachmentOrphans),
|
|
3822
4037
|
purity: "pure",
|
|
3823
4038
|
read: "none",
|
|
3824
4039
|
response: "json",
|
|
@@ -3827,7 +4042,7 @@ const ROUTE_TABLE = {
|
|
|
3827
4042
|
[ROUTES.attachmentClean.path]: {
|
|
3828
4043
|
slice: "removal",
|
|
3829
4044
|
method: ROUTES.attachmentClean.method,
|
|
3830
|
-
body:
|
|
4045
|
+
body: bodyOf(ROUTES.attachmentClean),
|
|
3831
4046
|
purity: "chained",
|
|
3832
4047
|
read: "none",
|
|
3833
4048
|
response: "json",
|
|
@@ -3836,7 +4051,7 @@ const ROUTE_TABLE = {
|
|
|
3836
4051
|
[ROUTES.orphans.path]: {
|
|
3837
4052
|
slice: "core",
|
|
3838
4053
|
method: ROUTES.orphans.method,
|
|
3839
|
-
body:
|
|
4054
|
+
body: bodyOf(ROUTES.orphans),
|
|
3840
4055
|
purity: "pure",
|
|
3841
4056
|
read: "raw",
|
|
3842
4057
|
response: "json",
|
|
@@ -3845,7 +4060,7 @@ const ROUTE_TABLE = {
|
|
|
3845
4060
|
[ROUTES.apply.path]: {
|
|
3846
4061
|
slice: "full",
|
|
3847
4062
|
method: ROUTES.apply.method,
|
|
3848
|
-
body:
|
|
4063
|
+
body: bodyOf(ROUTES.apply),
|
|
3849
4064
|
purity: (body) => {
|
|
3850
4065
|
const action = actionOf(body);
|
|
3851
4066
|
return action === void 0 ? "chained" : APPLY_ACTION_TABLE[action];
|
|
@@ -3857,7 +4072,7 @@ const ROUTE_TABLE = {
|
|
|
3857
4072
|
[ROUTES.empty.path]: {
|
|
3858
4073
|
slice: "removal",
|
|
3859
4074
|
method: ROUTES.empty.method,
|
|
3860
|
-
body:
|
|
4075
|
+
body: bodyOf(ROUTES.empty),
|
|
3861
4076
|
purity: "chained",
|
|
3862
4077
|
read: "list",
|
|
3863
4078
|
response: "json",
|
|
@@ -3868,7 +4083,7 @@ const ROUTE_TABLE = {
|
|
|
3868
4083
|
[ROUTES.detail.path]: {
|
|
3869
4084
|
slice: "core",
|
|
3870
4085
|
method: ROUTES.detail.method,
|
|
3871
|
-
body:
|
|
4086
|
+
body: bodyOf(ROUTES.detail),
|
|
3872
4087
|
purity: "pure",
|
|
3873
4088
|
read: "raw",
|
|
3874
4089
|
response: "json",
|
|
@@ -3915,21 +4130,12 @@ function isPure(purity, body) {
|
|
|
3915
4130
|
}
|
|
3916
4131
|
/**
|
|
3917
4132
|
* 全量面按行收窄(ADR-0032):组合根装出的 {@link DeleteDeps} 只交给 `/apply`;每一段只拿到
|
|
3918
|
-
* 自己声明的那一格(路由表的 `slice
|
|
4133
|
+
* 自己声明的那一格(路由表的 `slice`)。收窄是**运行期事实**,不是类型投影:`core` 的 fs 由
|
|
4134
|
+
* `FS_CORE_METHODS` 现切,删除能力根本不在对象上。
|
|
3919
4135
|
*/
|
|
3920
|
-
function
|
|
4136
|
+
function coreDepsOf(full) {
|
|
3921
4137
|
return {
|
|
3922
|
-
fs:
|
|
3923
|
-
exists: (p) => full.fs.exists(p),
|
|
3924
|
-
ensureDir: (p) => full.fs.ensureDir(p),
|
|
3925
|
-
rename: (from, to) => full.fs.rename(from, to),
|
|
3926
|
-
sizeOfDir: (p) => full.fs.sizeOfDir(p),
|
|
3927
|
-
listFiles: (p) => full.fs.listFiles(p),
|
|
3928
|
-
listDirs: (p) => full.fs.listDirs(p),
|
|
3929
|
-
realpath: (p) => full.fs.realpath(p),
|
|
3930
|
-
readFile: (p) => full.fs.readFile(p),
|
|
3931
|
-
statFile: (p) => full.fs.statFile(p)
|
|
3932
|
-
},
|
|
4138
|
+
fs: fsSlice(full.fs, FS_CORE_METHODS),
|
|
3933
4139
|
host: full.host,
|
|
3934
4140
|
ledger: full.ledger,
|
|
3935
4141
|
home: full.home,
|
|
@@ -3937,23 +4143,21 @@ function coreOf(full) {
|
|
|
3937
4143
|
config: full.config
|
|
3938
4144
|
};
|
|
3939
4145
|
}
|
|
3940
|
-
/** `removal` 保留删除能力,但不带会话删除的时钟;`full` 只给 `/apply`。
|
|
3941
|
-
|
|
4146
|
+
/** `removal` 保留删除能力,但不带会话删除的时钟;`full` 只给 `/apply`。fs 与 `core` 同一条:
|
|
4147
|
+
* 按 `FS_CORE_METHODS + FS_REMOVAL_METHODS` 现切——ADR-0032 的收窄是运行期事实,不是把
|
|
4148
|
+
* `full.fs` 的类型改一改。 */
|
|
4149
|
+
function removalOf(full, core) {
|
|
3942
4150
|
return {
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
ledger: full.ledger,
|
|
3946
|
-
home: full.home,
|
|
3947
|
-
presence: full.presence,
|
|
3948
|
-
config: full.config
|
|
4151
|
+
...core,
|
|
4152
|
+
fs: fsSlice(full.fs, [...FS_CORE_METHODS, ...FS_REMOVAL_METHODS])
|
|
3949
4153
|
};
|
|
3950
4154
|
}
|
|
3951
4155
|
/** 五格只建一次:收窄对象在 dispatcher 构造期固定,请求路径只做引用选择。 */
|
|
3952
4156
|
function slicesOf(full) {
|
|
3953
|
-
const core =
|
|
4157
|
+
const core = coreDepsOf(full);
|
|
3954
4158
|
return {
|
|
3955
4159
|
core,
|
|
3956
|
-
removal: removalOf(full),
|
|
4160
|
+
removal: removalOf(full, core),
|
|
3957
4161
|
full,
|
|
3958
4162
|
attachment: {
|
|
3959
4163
|
...core,
|
|
@@ -4295,11 +4499,11 @@ async function buildEntry(deps, id) {
|
|
|
4295
4499
|
return;
|
|
4296
4500
|
}
|
|
4297
4501
|
const { deletedAt, sessionDirName } = parseEntryId(id);
|
|
4298
|
-
const cwd = typeof header.cwd === "string" ? header.cwd :
|
|
4502
|
+
const cwd = typeof header.cwd === "string" ? header.cwd : void 0;
|
|
4299
4503
|
return {
|
|
4300
4504
|
id,
|
|
4301
4505
|
sessionId: typeof header.id === "string" && header.id !== "" ? header.id : sessionDirName,
|
|
4302
|
-
projectDir:
|
|
4506
|
+
projectDir: projectDirOfCwd(cwd),
|
|
4303
4507
|
workspaceId: "",
|
|
4304
4508
|
wasArchived: false,
|
|
4305
4509
|
deletedAt,
|