@xrn1997/dsh-session-delete 0.7.0 → 0.9.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 +133 -173
- package/THIRD_PARTY_NOTICES.md +4 -2
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +119 -0
- package/docs/preview.zh.svg +117 -0
- package/docs/screenshots/screenshot-01.png +0 -0
- package/lib/client.js +5276 -2159
- package/lib/index.js +1594 -489
- package/lib/types/api/archive-rows.d.ts +20 -0
- package/lib/types/api/attachment.d.ts +2 -2
- package/lib/types/api/connection-route.d.ts +1 -1
- package/lib/types/api/route-table.d.ts +100 -11
- package/lib/types/client/archive-detail.d.ts +27 -0
- package/lib/types/client/archive-pane.d.ts +60 -0
- package/lib/types/client/archive-store.d.ts +6 -0
- package/lib/types/client/attachment-view.d.ts +0 -7
- package/lib/types/client/batch-bar.d.ts +5 -6
- package/lib/types/client/batch-confirm.d.ts +19 -11
- package/lib/types/client/batch-menu-item.d.ts +1 -1
- package/lib/types/client/batch-pick.d.ts +2 -1
- package/lib/types/client/busy-gate.d.ts +12 -5
- package/lib/types/client/config-settings.d.ts +2 -2
- 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 +66 -14
- 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-ledger.d.ts +23 -0
- package/lib/types/client/detail-pane.d.ts +33 -0
- package/lib/types/client/host-archive-watch.d.ts +22 -0
- package/lib/types/client/host-rows.d.ts +7 -0
- package/lib/types/client/maintenance-parts.d.ts +4 -3
- package/lib/types/client/maintenance-settings.d.ts +4 -3
- package/lib/types/client/notice.d.ts +16 -0
- package/lib/types/client/orphan-maintenance.d.ts +1 -1
- package/lib/types/client/plugin.d.ts +6 -0
- package/lib/types/client/prompt-rail.d.ts +22 -0
- package/lib/types/client/receipt.d.ts +4 -1
- package/lib/types/client/remote.d.ts +82 -98
- package/lib/types/client/reset-client-state.d.ts +1 -0
- package/lib/types/client/session-detail.d.ts +94 -0
- package/lib/types/client/session-list.d.ts +112 -0
- package/lib/types/client/session-live.d.ts +31 -0
- package/lib/types/client/settings-cards.d.ts +1 -1
- package/lib/types/client/subagent-section.d.ts +45 -0
- package/lib/types/client/trash-confirm.d.ts +2 -1
- package/lib/types/client/trash-detail.d.ts +9 -50
- package/lib/types/client/trash-nav.d.ts +8 -7
- package/lib/types/client/trash-panel.d.ts +1 -1
- package/lib/types/client/trash-snapshot.d.ts +38 -0
- package/lib/types/client/trash-view.d.ts +41 -10
- package/lib/types/client/ui/ErrorBoundary.d.ts +32 -0
- package/lib/types/client/ui/icons.d.ts +10 -4
- package/lib/types/client/undo-notices.d.ts +27 -7
- package/lib/types/client/undo-toast.d.ts +5 -3
- package/lib/types/client/use-archive-detail-reader.d.ts +28 -0
- package/lib/types/client/use-archive-panel-controller.d.ts +73 -0
- package/lib/types/client/use-archive-query.d.ts +29 -0
- package/lib/types/client/use-detail-pager.d.ts +7 -3
- package/lib/types/client/use-detail-rail.d.ts +48 -0
- package/lib/types/client/use-detail-reader.d.ts +71 -0
- package/lib/types/client/use-gated-refresh.d.ts +27 -0
- package/lib/types/client/{use-trash-selection.d.ts → use-list-selection.d.ts} +16 -14
- package/lib/types/client/use-maintenance-section.d.ts +29 -18
- package/lib/types/client/use-maintenance.d.ts +21 -8
- package/lib/types/client/use-panel-selection.d.ts +38 -0
- 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 +27 -0
- package/lib/types/client/use-trash-panel-controller.d.ts +23 -9
- package/lib/types/client/use-trash-query.d.ts +14 -7
- package/lib/types/client/write-seats.d.ts +95 -23
- package/lib/types/deps.d.ts +9 -6
- package/lib/types/{verbs/errors.d.ts → errors.d.ts} +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/log/session-log.d.ts +24 -2
- package/lib/types/log/zstd-frames.d.ts +8 -1
- package/lib/types/ports/fs-port.d.ts +35 -2
- package/lib/types/ports/host-port.d.ts +107 -15
- package/lib/types/shared/project-key.d.ts +28 -0
- package/lib/types/shared/session-path.d.ts +35 -0
- package/lib/types/shared/wire.d.ts +250 -36
- package/lib/types/trash/archive-detail.d.ts +27 -0
- package/lib/types/trash/attachments.d.ts +7 -4
- package/lib/types/trash/detail.d.ts +28 -3
- package/lib/types/trash/display-name.d.ts +16 -0
- package/lib/types/trash/entry.d.ts +27 -10
- package/lib/types/trash/groups.d.ts +1 -0
- package/lib/types/trash/ledger.d.ts +4 -2
- package/lib/types/trash/projection-cache.d.ts +24 -0
- package/lib/types/trash/reconcile.d.ts +5 -3
- package/lib/types/trash/session-rows.d.ts +83 -0
- package/lib/types/trash/shrinking-view.d.ts +30 -0
- package/lib/types/verbs/batch-carried.d.ts +4 -2
- package/lib/types/verbs/live-admission.d.ts +7 -2
- package/lib/types/verbs/member-journal.d.ts +1 -1
- package/lib/types/verbs/permanent-removal.d.ts +15 -5
- package/lib/types/verbs/restore-session.d.ts +6 -4
- package/lib/types/verbs/trash-scope.d.ts +14 -13
- package/locale/en.json +7 -6
- package/locale/zh.json +2 -1
- package/package.json +10 -4
- package/lib/types/client/confirm-close.d.ts +0 -14
- package/lib/types/client/write-settlement.d.ts +0 -66
- package/lib/types/client/write.d.ts +0 -64
package/lib/types/deps.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { CoreFsPort,
|
|
2
|
-
import type { HostCorePort } from './ports/host-port.js';
|
|
1
|
+
import type { CoreFsPort, RemovalFsPort } from './ports/fs-port.js';
|
|
2
|
+
import type { HostCorePort, HostRemovalPort } from './ports/host-port.js';
|
|
3
3
|
import type { AttachmentsPort } from './ports/attachments-port.js';
|
|
4
4
|
import type { PresenceCapability } from './ports/presence-port.js';
|
|
5
5
|
import type { SessionDeleteConfig } from './config.js';
|
|
6
6
|
import type { TrashLedger } from './trash/ledger.js';
|
|
7
7
|
/** Node 半的基础依赖面:组合根只装配这一颗;动词之间不互相 import 依赖面 interface。
|
|
8
|
-
* `fs` 不含 `removeDir` / `removeFile`,`host`
|
|
9
|
-
* {@link CoreDeps.presence}。`config` 是
|
|
8
|
+
* `fs` 不含 `removeDir` / `removeFile`,`host` 不含在场三件与删除面——删目录 / 删投影缓存记录走
|
|
9
|
+
* {@link RemovalDeps},在场三件(`evictLive` / `announce*`)走 {@link CoreDeps.presence}。`config` 是
|
|
10
|
+
* `apply` 归一后的只读快照:读方从 deps 读,不 import 模块级单例。 */
|
|
10
11
|
export interface CoreDeps {
|
|
11
12
|
fs: CoreFsPort;
|
|
12
13
|
host: HostCorePort;
|
|
@@ -19,9 +20,11 @@ export interface CoreDeps {
|
|
|
19
20
|
export type DeleteSessionDeps = CoreDeps & {
|
|
20
21
|
now(): number;
|
|
21
22
|
};
|
|
22
|
-
/** 永久删除的执行面:执行器及其分发拿得到 `removeDir`
|
|
23
|
+
/** 永久删除的执行面:执行器及其分发拿得到 `removeDir` / `removeFile` 与投影缓存删除面;
|
|
24
|
+
* 计划函数仍只收 `CoreDeps`(它们不写)。 */
|
|
23
25
|
export type RemovalDeps = CoreDeps & {
|
|
24
|
-
|
|
26
|
+
host: HostRemovalPort;
|
|
27
|
+
fs: RemovalFsPort;
|
|
25
28
|
};
|
|
26
29
|
/** 宿主 `configEditor` 的窄面:`edit(entry, change)` 把完整 raw config 落盘并让 Loader 重启这一行。
|
|
27
30
|
* `entry` 是 `ctx.fiber.entry`(Loader 挂在 fiber 上,Cordis 类型不声明它,组合根按窄镜像取)。 */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** 失败的**结构与措辞**。码本身、码的前缀读法与动词词表都住在 `shared/wire.ts`(ADR-0003):
|
|
2
2
|
* 浏览器半也要认它们,它们属于两半共同的契约,不属于 Node 半。这里只做动词抛错与回滚措辞。 */
|
|
3
|
-
import { type RouteCode, type VerbCode } from '
|
|
3
|
+
import { type RouteCode, type VerbCode } from './shared/wire.js';
|
|
4
4
|
/** 一次失败的**结构**:码、上屏原文、可选 cause(`map-error` 沿 cause 链认宿主类型化错误)、
|
|
5
5
|
* 可选的结构化附带物(对齐官方 `rpcErrorSchema` 的第三件 `details`)。 */
|
|
6
6
|
export interface VerbError extends Error {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export { Config };
|
|
|
20
20
|
* - `agents`:只给 handle 捕获用(`ctx.get('agents')`;缺席时 `ctx.inject(['agents'])` 等服务就绪再装)。
|
|
21
21
|
* 它同样可能晚于本插件激活,写进插件 inject 只会让整个插件 pending。
|
|
22
22
|
*
|
|
23
|
-
* `connection`
|
|
23
|
+
* `connection` 是浏览器半取数通道的唯一承载者:全部段名注册到 `connection.fetch.register` 的
|
|
24
24
|
* `/api/dsh-session-delete-api/*`,Host/Origin/浏览器认证由宿主 `/api` bridge 完成(ADR-0033)。
|
|
25
25
|
* 支持面是 web UI 与桌面端,二者的标准组合都装 `client-connection`;服务缺席时插件停在 pending
|
|
26
26
|
* ——可见的激活失败,而不是静默地没有入口。`webServer` 不再直接使用:exact route 仍由宿主的
|
|
@@ -6,6 +6,8 @@ export interface SessionRecord {
|
|
|
6
6
|
id?: string;
|
|
7
7
|
createdAt?: number;
|
|
8
8
|
cwd?: string;
|
|
9
|
+
/** `session` 头里的父会话(fork / subagent 子会话才有);显示名兜底用它认「这是一条子会话」。 */
|
|
10
|
+
parentSession?: string;
|
|
9
11
|
data?: unknown;
|
|
10
12
|
}
|
|
11
13
|
export interface SessionLogStats {
|
|
@@ -16,6 +18,19 @@ export interface SessionLogStats {
|
|
|
16
18
|
/** 整条日志最后一个换行之后的字节数(>0 说明尾巴被切了一刀)。 */
|
|
17
19
|
truncatedTailBytes: number;
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 单条会话日志**整本读取**的显式上限(256 MiB)。
|
|
23
|
+
*
|
|
24
|
+
* 逐帧解压把内存口径压在"最大那一帧的明文",但 `readFile` 本身仍会把整本字节读进内存;日志大小
|
|
25
|
+
* 没有宿主上限,坏文件 / 巨型工具输出可以把它撑到任意大。凡是"读整本"的解码路(回收站详情、
|
|
26
|
+
* 附件引用扫描)都先 stat 再读,超过这个量级就按**读不出**处理——不截断、不猜:
|
|
27
|
+
* - 详情抛 `io` + 原文(读者至少知道它有多大、为什么打不开);
|
|
28
|
+
* - 引用扫描按 `unreadable` 跳过(fail closed,宁可留孤儿也不删共享,ADR-0020)。
|
|
29
|
+
*
|
|
30
|
+
* 取值只住这一处:两个消费方引用同一个数,别各写一份。"读整本"的对立面是 `readFileHead` 那种
|
|
31
|
+
* 有界头读(对账只读 header,不该为一行付整本内存)。
|
|
32
|
+
*/
|
|
33
|
+
export declare const MAX_SESSION_LOG_BYTES: number;
|
|
19
34
|
/** 这个名字是不是规范日志(任意一代)。附件引用扫描用它区分"老一代日志"与"读不懂的旁文件"。 */
|
|
20
35
|
export declare function isCanonicalSessionLogName(name: string): boolean;
|
|
21
36
|
/**
|
|
@@ -30,12 +45,19 @@ export declare function pickSessionLog(names: readonly string[]): string | undef
|
|
|
30
45
|
*
|
|
31
46
|
* 回调返回 `false` = **提前停机**(后面的帧不再解——`readSessionHeader` 只要第一行)。
|
|
32
47
|
* 停机后 `stats` 只是停机前那部分,别拿来做全量对账。
|
|
48
|
+
*
|
|
49
|
+
* `tolerateTruncatedTail` 只给**前缀读**用(对账的有界头读):尾巴切在帧中间时丢掉不完整的那一帧,
|
|
50
|
+
* 前面的完整帧照常走。读整本的调用方不传——截断文件必须响亮失败,见 `frameRanges` 的注释。
|
|
33
51
|
*/
|
|
34
|
-
export declare function walkSessionLog(raw: Buffer, onRecord: (record: SessionRecord) => void | false
|
|
52
|
+
export declare function walkSessionLog(raw: Buffer, onRecord: (record: SessionRecord) => void | false, options?: {
|
|
53
|
+
readonly tolerateTruncatedTail?: boolean;
|
|
54
|
+
}): SessionLogStats;
|
|
35
55
|
/**
|
|
36
56
|
* 日志的 **header**:格式事实是"第一行即 header"(`type: 'session'`,含 `id` 与 `cwd`,v3/v4 均如此,
|
|
37
57
|
* AGENTS.md 有实测背书)——这里按 `type === 'session'` 找**第一条**这样的记录并就地停机
|
|
38
58
|
* (不要求它恰是第一个可解析行:坏一行前缀不该让整条日志判不出身份)。
|
|
39
59
|
* 找不到(空日志 / 全是别种记录)回 `undefined`;帧坏了照抛——那是"读不出来",与"没有 header"是两件事。
|
|
40
60
|
*/
|
|
41
|
-
export declare function readSessionHeader(raw: Buffer
|
|
61
|
+
export declare function readSessionHeader(raw: Buffer, options?: {
|
|
62
|
+
readonly tolerateTruncatedTail?: boolean;
|
|
63
|
+
}): SessionRecord | undefined;
|
|
@@ -31,5 +31,12 @@ export interface FrameRange {
|
|
|
31
31
|
* 把 `raw` 切成帧区间。
|
|
32
32
|
* @throws 起始处不是 magic、或某帧算到的末位既不是下一帧帧头也不是 EOF——**一律抛**,
|
|
33
33
|
* 绝不"尽力往下解":切错帧的后果是把半截压缩体当解压输入,那时解出来的东西不可信。
|
|
34
|
+
*
|
|
35
|
+
* `tolerateTruncatedTail` 只给**前缀读**(`readFileHead` 的有界头读):输入是某个合法日志的开头
|
|
36
|
+
* 一段,尾巴必然可能切在帧中间,这时"少最后一帧"不叫损坏。解析到切坏的尾巴就停,返回已经切出的
|
|
37
|
+
* 完整帧;中间的损坏也会让它提前停——但头读只需要最前面那几帧(header 在第一帧),够用。
|
|
38
|
+
* **默认仍是严格**:读整本的调用方拿到截断文件必须抛,不能把半份日志当完整日志。
|
|
34
39
|
*/
|
|
35
|
-
export declare function frameRanges(raw: Buffer
|
|
40
|
+
export declare function frameRanges(raw: Buffer, options?: {
|
|
41
|
+
readonly tolerateTruncatedTail?: boolean;
|
|
42
|
+
}): FrameRange[];
|
|
@@ -29,6 +29,12 @@ export interface FsPort {
|
|
|
29
29
|
realpath: (p: string) => Promise<string>;
|
|
30
30
|
/** 整个文件读进内存。实测本机回收站里最大单文件 4.66 MB;**内存口径由逐帧解压把住**(见 `src/log/session-log.ts`),不在这里。 */
|
|
31
31
|
readFile: (p: string) => Promise<Buffer>;
|
|
32
|
+
/** **有界头读**:只读文件开头至多 `maxBytes` 字节(文件更短就整份交回)。
|
|
33
|
+
* 对账只为读日志 header,却不必把整本日志读进内存——这是"整本读"之外的另一条读取口径,
|
|
34
|
+
* 不改变 `readFile` 的语义(它仍读整本,整本上限归 `MAX_SESSION_LOG_BYTES` 的消费方判)。
|
|
35
|
+
* 只做字节切取,不保证落在帧边界:前缀的尾巴可以切在帧中间,需要解 zstd 的调用方按自己的
|
|
36
|
+
* 容忍度判(对账走 `readSessionHeader` 的前缀容忍口径,丢掉最后那个不完整帧,见 `src/trash/reconcile.ts`)。 */
|
|
37
|
+
readFileHead: (p: string, maxBytes: number) => Promise<Buffer>;
|
|
32
38
|
/** 只读的单文件读数:附件渲染与独占计划都用它(不递归、不跟随目录)。 */
|
|
33
39
|
statFile: (p: string) => Promise<{
|
|
34
40
|
size: number;
|
|
@@ -36,6 +42,33 @@ export interface FsPort {
|
|
|
36
42
|
/** 删单个文件(不是目录)。危险能力,只挂到 `RemovalDeps` 上。 */
|
|
37
43
|
removeFile: (p: string) => Promise<void>;
|
|
38
44
|
}
|
|
39
|
-
/** 动词的基础面:读与搬移都有,**不拿删除**。删目录与删单文件只挂在 `RemovalDeps` 上(ADR-0027)。
|
|
40
|
-
|
|
45
|
+
/** 动词的基础面:读与搬移都有,**不拿删除**。删目录与删单文件只挂在 `RemovalDeps` 上(ADR-0027)。
|
|
46
|
+
* 名单是运行期收窄的**唯一依据**(ADR-0032):`src/api/dispatch.ts` 的 `coreDepsOf` 按它挑方法,
|
|
47
|
+
* 所以「基础面不含删除」既在类型上、也在运行期成立。 */
|
|
48
|
+
export declare const FS_CORE_METHODS: readonly ["exists", "ensureDir", "rename", "sizeOfDir", "listFiles", "listDirs", "realpath", "readFile", "statFile"];
|
|
49
|
+
/** 删除能力(目录 / 单文件):只挂在 `RemovalDeps` 与孤儿附件清理段上。 */
|
|
50
|
+
export declare const FS_REMOVAL_METHODS: readonly ["removeDir", "removeFile"];
|
|
51
|
+
/** 附件渲染:读一个文件的大小与字节。 */
|
|
52
|
+
export declare const FS_ATTACHMENT_METHODS: readonly ["statFile", "readFile"];
|
|
53
|
+
/** 详情读取:目录在不在、挑日志文件、读日志、读日志大小(整本读取上限的判据,`MAX_SESSION_LOG_BYTES`)。 */
|
|
54
|
+
export declare const FS_DETAIL_METHODS: readonly ["exists", "listFiles", "readFile", "statFile"];
|
|
55
|
+
/** 对账:目录存在性、枚举(条目目录 / 目录里的文件)、有界头读、量尺寸。**不读整本日志**——
|
|
56
|
+
* 对账只要 header,`readFileHead` 就是为它长出来的那条口径。 */
|
|
57
|
+
export declare const FS_RECONCILE_METHODS: readonly ["exists", "listDirs", "listFiles", "readFileHead", "sizeOfDir"];
|
|
58
|
+
/** 附件引用扫描(读侧)。 */
|
|
59
|
+
export declare const FS_REFERENCE_SCAN_METHODS: readonly ["exists", "listFiles", "listDirs", "readFile", "statFile", "realpath"];
|
|
60
|
+
/** 附件引用扫描 + 清孤儿图片(聚合写)。 */
|
|
61
|
+
export declare const FS_REFERENCE_SCAN_REMOVAL_METHODS: readonly ["exists", "listFiles", "listDirs", "readFile", "statFile", "realpath", "removeFile"];
|
|
62
|
+
export type CoreFsPort = Pick<FsPort, (typeof FS_CORE_METHODS)[number]>;
|
|
63
|
+
export type RemovalFsPort = CoreFsPort & Pick<FsPort, (typeof FS_REMOVAL_METHODS)[number]>;
|
|
64
|
+
export type FsAttachmentPort = Pick<FsPort, (typeof FS_ATTACHMENT_METHODS)[number]>;
|
|
65
|
+
export type FsDetailPort = Pick<FsPort, (typeof FS_DETAIL_METHODS)[number]>;
|
|
66
|
+
export type FsReconcilePort = Pick<FsPort, (typeof FS_RECONCILE_METHODS)[number]>;
|
|
67
|
+
export type FsReferenceScanPort = Pick<FsPort, (typeof FS_REFERENCE_SCAN_METHODS)[number]>;
|
|
68
|
+
export type FsReferenceScanRemovalPort = Pick<FsPort, (typeof FS_REFERENCE_SCAN_REMOVAL_METHODS)[number]>;
|
|
69
|
+
/** 按名单从全量端口切一片(复制方法引用;端口方法都是属性、不读 `this`)。
|
|
70
|
+
* **运行期真的只带这些方法**:ADR-0032 的收窄不是类型投影。入参按 **K 的键集**收窄(不是整份
|
|
71
|
+
* `FsPort`):本函数只会读名单里的那几个键,而 `RemovalDeps` 那样已经切过一片的面(`RemovalFsPort`)
|
|
72
|
+
* 不必先长回全量面才能再切。 */
|
|
73
|
+
export declare function fsSlice<const K extends readonly (keyof FsPort)[]>(port: Pick<FsPort, K[number]>, keys: K): Pick<FsPort, K[number]>;
|
|
41
74
|
export declare function createFsPort(): FsPort;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { escapeProjectKey } from '../shared/project-key.js';
|
|
1
2
|
/** 摘内存的三种落地(见 {@link HostPort.evictLive}):`not-live` / `evicted` 都意味着**宿主列表已经不含它**;
|
|
2
3
|
* `unknown` 意味着读不到或摘不掉,**不能**据此通告客户端(发了就是假话,重连后那一行会自己长回来)。 */
|
|
3
4
|
export type EvictionOutcome = 'evicted' | 'not-live' | 'unknown';
|
|
@@ -12,12 +13,21 @@ export interface HostIdentityPort {
|
|
|
12
13
|
* header 走公开 live/持久化读面;与 `workspaceOf` 同一口径:**未命中是正常的 no-op,不是故障**
|
|
13
14
|
* (存储真故障照抛)。 */
|
|
14
15
|
projectDirOf(sessionId: string): Promise<string | undefined>;
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
16
|
+
/** 删除时**尽力**取的会话显示名,**与宿主工作中同名**:子会话(`subagent` 投影有 label)取 label
|
|
17
|
+
* (委派 `subagent` 时的 `description`),其余取 `title` 投影;取不到返回空串,绝不因此让删除失败。
|
|
18
|
+
* 为什么子会话不按 `title` 投影起名:那是主会话那套起名法(LLM 标题 / 首句提示词截断兜底),
|
|
19
|
+
* 同批子会话会撞成同名分不清(ADR-0058)。
|
|
20
|
+
* 名字只存在于宿主自己的账本/缓存里(`FsPort` 不直读文件)⇒ 取数面归宿主端口,接官方投影缓存 API;
|
|
17
21
|
* header 与 `projectDirOf` 走同一个公开读面。 */
|
|
18
22
|
titleOf(sessionId: string): Promise<string>;
|
|
23
|
+
/** 子会话显示名的**投影 label 本体**(`subagent` 行的 `label`):空串 = 没有,**不回落标题**——
|
|
24
|
+
* 回落标题是 {@link HostIdentityPort.titleOf} 的口径。归档行要把 `label` 与日志标题分两格过线
|
|
25
|
+
* (界面按 label 非空优先显示),只有这一面能单独问出 label。 */
|
|
26
|
+
labelOf(sessionId: string): Promise<string>;
|
|
19
27
|
isLive(sessionId: string): Promise<boolean>;
|
|
20
28
|
isArchived(sessionId: string): Promise<boolean>;
|
|
29
|
+
/** registry **全局**归档集原样(同步数组读;Promise 外壳与在场其余成员同形)。 */
|
|
30
|
+
archivedSessionIds(): Promise<readonly string[]>;
|
|
21
31
|
unarchive(sessionId: string): Promise<void>;
|
|
22
32
|
detach(sessionId: string, workspaceId: string): Promise<void>;
|
|
23
33
|
attach(sessionId: string, workspaceId: string): Promise<void>;
|
|
@@ -59,8 +69,9 @@ export type CorpusRead<T> = {
|
|
|
59
69
|
/**
|
|
60
70
|
* 角色三:**会话语料**——整表身份与子会话闭包。
|
|
61
71
|
*
|
|
62
|
-
*
|
|
72
|
+
* 可缺席的读面都把"这一趟看不见语料"写成显式的 {@link CorpusRead}:`{ available: false }` 与
|
|
63
73
|
* "看见了、里面是空的"是两件事。**缺席之后怎么办归调用方,清单见 `docs/architecture.md` §2 的「语料缺席」**。
|
|
74
|
+
* `readSession` 是整本读:方法缺席与读失败都抛(调用方折 `io` / `not-found`),不折成缺席。
|
|
64
75
|
*/
|
|
65
76
|
export interface HostCorpusPort {
|
|
66
77
|
/** 整个会话语料(live ∪ persisted)的只读身份表。**服务缺席是显式的**:`sessionQuery` 没挂,或它的
|
|
@@ -72,32 +83,113 @@ export interface HostCorpusPort {
|
|
|
72
83
|
* 服务在场时,空入参 ⇒ `{ available: true, value: {} }`,一次宿主调用都不发。
|
|
73
84
|
* 键按调用方传进来的写法回(同一个父的 `session-x` / `x` 两种写法是同一个根,见 `membersFor`)。 */
|
|
74
85
|
subagentMembersOf(parentIds: readonly string[]): Promise<CorpusRead<Record<string, readonly SubagentMember[]>>>;
|
|
86
|
+
/** 批量读日志标题(`sessionQuery.readTitleSnapshots` 折叠 `session/title`):id → 标题;
|
|
87
|
+
* 无标题 / 单条 rejected ⇒ **该 id 不在 map**(不失败整张表)。方法缺席(旧宿主)或整次读抛错 ⇒
|
|
88
|
+
* `{ available: false }`(调用方逐条回退 `titleOf`,同样不失败整档)。 */
|
|
89
|
+
titleSnapshots(ids: readonly string[]): Promise<CorpusRead<ReadonlyMap<string, string>>>;
|
|
90
|
+
/** 提问时间表(`sessionController.list()` 的 `updatedAt`):id → 最后提问时间;服务缺席 / 抛错 ⇒
|
|
91
|
+
* `{ available: false }`(调用方回退 `header.createdAt` 并标 `created`)。冷无 cwd 会话被宿主列表
|
|
92
|
+
* 跳过 ⇒ 它们自然不在 map 里,走同一条回退。 */
|
|
93
|
+
sessionActivity(): Promise<CorpusRead<ReadonlyMap<string, number>>>;
|
|
94
|
+
/** 持久化日志工件字节表(`sessionPersistence.list()` 的 `sizeBytes`);值 `undefined` = 该行**没有
|
|
95
|
+
* 可信读数**(不是 0)。服务缺席 ⇒ `{ available: false }`(调用方逐行缺大小、整档照常);
|
|
96
|
+
* `list()` 抛错 ⇒ 抛(调用方整档 `io`,不拿 0 冒充没有大小)。 */
|
|
97
|
+
persistedSizes(): Promise<CorpusRead<ReadonlyMap<string, number | undefined>>>;
|
|
98
|
+
/** 持久化服务是否挂载(只探服务,不读列表)。用来区分两件事:
|
|
99
|
+
* 「没有持久化服务」= 没有 persisted-only 会话,语料仍是完整的保护面;
|
|
100
|
+
* 「服务在场但列表读面坏了」= 可能有看不见的会话,必须失败关闭(ADR-0062)。
|
|
101
|
+
* `persistedSizes()` 的 `{ available: false }` 两者都会回,单看它分不出来。 */
|
|
102
|
+
persistenceMounted(): boolean;
|
|
103
|
+
/** 整本读(`sessionQuery.readSession`,replay 校验、不 make live):header 事实 + 完整事件流。
|
|
104
|
+
* **事件流不含 `session` 头记录**(宿主把头放在 `session` 那一格)——调用方自己合成头喂块折叠。
|
|
105
|
+
* 方法缺席(旧宿主)⇒ 抛(调用方折 `io`);读失败**原样抛**(含 `SESSION_QUERY_SESSION_NOT_FOUND`,
|
|
106
|
+
* 折 `not-found` 归上层的归档详情读路 `readArchiveDetail`)。 */
|
|
107
|
+
readSession(sessionId: string): Promise<CorpusLogRead>;
|
|
75
108
|
}
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
109
|
+
/** `readSession` 的窄读面:header 事实三格 + 事件流。多余字段(`id` / `version` / `seq` / `origin`…)留在原对象上,
|
|
110
|
+
* 类型面只声明消费方用到的。 */
|
|
111
|
+
export interface CorpusLogRead {
|
|
112
|
+
readonly session: {
|
|
113
|
+
readonly createdAt?: number;
|
|
114
|
+
readonly cwd?: string;
|
|
115
|
+
readonly parentSession?: string;
|
|
116
|
+
};
|
|
117
|
+
readonly events: readonly CorpusEvent[];
|
|
118
|
+
}
|
|
119
|
+
/** 一条事件的窄读面(宿主 `SessionEvent` 的 `{ type, seq, time, data }` 信封;`seq` 等多余字段原样留着)。 */
|
|
120
|
+
export interface CorpusEvent {
|
|
121
|
+
readonly type: string;
|
|
122
|
+
readonly time: number;
|
|
123
|
+
readonly data?: unknown;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 角色四:**投影缓存**——宿主 `session_projcache` 域的会话记录键集与落盘删除面。
|
|
127
|
+
*
|
|
128
|
+
* 缓存服务本身(`sessionProjectionCache`)只有写与读,**没有删除方法**;记录由 storage domain 的
|
|
129
|
+
* `sessions` 表承载(`per-record` 布局,一条会话一份文档)。所以删除只能经
|
|
130
|
+
* `storageDomain.get('session_projcache').table('sessions')` 的同一条写链:**不直接删 `storages/`
|
|
131
|
+
* 下的文件**——那会绕过域的内存权威(`docs/architecture.md` §6 明写 storages 是内部索引,外面改它
|
|
132
|
+
* 要重启宿主才自洽)。
|
|
133
|
+
*
|
|
134
|
+
* 读面只认**已打开的存储域**,不拿缓存服务缺席当「没有记录」:旧版本或另一份 composition 可能留下
|
|
135
|
+
* 记录,服务没挂时更要报 `{ available: false }`(调用方折 `io`),不能折成 0 条。域不可用、形状
|
|
136
|
+
* 不符或 `keys()` 抛错都算读面不可用。
|
|
137
|
+
*
|
|
138
|
+
* 读/写再分两片:`HostCorePort` 只拿读面,`dropProjectionCache` 只进 `HostRemovalPort`(`RemovalDeps`)。
|
|
139
|
+
* 这样纯读的维护卡报告路由在类型上就够不到删除面(ADR-0032 / ADR-0019 的最小权限)。
|
|
140
|
+
*/
|
|
141
|
+
export interface HostProjectionReadPort {
|
|
142
|
+
/** `session_projcache` 域 `sessions` 表的全部键(**键就是会话 id**,per-record 布局;`session-` 与
|
|
143
|
+
* bare 两代写法原样返回,比较归一归 `bareSessionId`)。域不可用 ⇒ `{ available: false }`。 */
|
|
144
|
+
projectionCacheIds(): Promise<CorpusRead<readonly string[]>>;
|
|
145
|
+
}
|
|
146
|
+
/** 投影缓存的删除回执:真正删掉的条数与**逐条删除时**失败的条数(批量删除失败整体抛,不折回执)。 */
|
|
147
|
+
export interface ProjectionCacheDropResult {
|
|
148
|
+
readonly removed: number;
|
|
149
|
+
readonly failed: number;
|
|
150
|
+
}
|
|
151
|
+
export interface HostProjectionWritePort {
|
|
152
|
+
/** 从 `session_projcache` 域删掉这些会话的记录。批量写链抛错 ⇒ 原样抛;旧宿主逐条 `delete` 时
|
|
153
|
+
* 单条失败收进 `failed`、继续删其余条——调用方拿到的始终是这一趟的真实后果。 */
|
|
154
|
+
dropProjectionCache(sessionIds: readonly string[]): Promise<ProjectionCacheDropResult>;
|
|
155
|
+
}
|
|
156
|
+
export interface HostProjectionPort extends HostProjectionReadPort, HostProjectionWritePort {
|
|
157
|
+
}
|
|
158
|
+
/** 复合别名:adapter(`createHostPort`)与调用方把四个角色的方法当一个端口用;角色是它的切面。 */
|
|
159
|
+
export type HostPort = HostIdentityPort & HostPresencePort & HostCorpusPort & HostProjectionPort;
|
|
160
|
+
/** 动词的宿主面:身份、语料与投影缓存**读面**三片;不含在场三件,也不含投影缓存删除面。
|
|
161
|
+
* 摘活体与通告只经 `CoreDeps.presence`(`PresenceCapability`),删缓存只经 {@link HostRemovalPort}。
|
|
79
162
|
* 用交集而不是 `Omit` 黑名单:`HostPresencePort` 将来长出新方法时,不会自动漏进每个动词的 `host`。 */
|
|
80
|
-
export type HostCorePort = HostIdentityPort & HostCorpusPort;
|
|
163
|
+
export type HostCorePort = HostIdentityPort & HostCorpusPort & HostProjectionReadPort;
|
|
164
|
+
/** 永久删除的宿主面:核心面 + 投影缓存删除面。只给 `RemovalDeps`(执行器与维护卡清理段)。 */
|
|
165
|
+
export type HostRemovalPort = HostCorePort & HostProjectionWritePort;
|
|
81
166
|
export interface SessionIdentity {
|
|
82
167
|
readonly sessionId: string;
|
|
83
168
|
readonly parentSessionId?: string;
|
|
84
169
|
readonly projectDir: string;
|
|
85
170
|
readonly subagent: boolean;
|
|
171
|
+
/** `header.createdAt`(归档行「创建于」回退与排序的原料);header 上真缺席或非正数 ⇒ **不落键**
|
|
172
|
+
* (不拿 0 冒充 1970;消费方按「时间未知」处理)。 */
|
|
173
|
+
readonly createdAt?: number;
|
|
86
174
|
}
|
|
87
175
|
/** 闭包里的一条后代:`sessionId` 是宿主交回的原写法(身份只认它,归一比对交给闭包部件)。 */
|
|
88
176
|
export interface SubagentMember {
|
|
89
177
|
readonly sessionId: string;
|
|
90
178
|
readonly projectDir: string;
|
|
91
179
|
}
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
export declare const NO_CWD_PROJECT_DIR = "_no-cwd";
|
|
95
|
-
/** 宿主 `projectKey(cwd)` 的逐字镜像:跨插件不能 import,宿主也没把它暴露成服务。
|
|
96
|
-
* 出处:asar `dsh-session-persistence-jsonl/lib/index.js` 的 `projectKey`;调用链
|
|
97
|
-
* `locate` → `logPath` → `projectDir` → `projectKey`。本机实测 `D:/develop/GitHub/dsh-session-delete`
|
|
98
|
-
* → `--D-develop-GitHub-dsh-session-delete--`。`projectDirOf` 与回收站对账重建共用这一份;
|
|
180
|
+
/** 宿主 `projectKey(cwd)` 的逐字镜像:编码与解码配对住在 `src/shared/project-key.ts`
|
|
181
|
+
* (字母表只有一份;解码给浏览器半渲染回收站组头)。`projectDirOf` 与回收站对账重建共用这一份;
|
|
99
182
|
* 宿主换代先复核算法。 */
|
|
100
|
-
export declare
|
|
183
|
+
export declare const projectKey: typeof escapeProjectKey;
|
|
184
|
+
/**
|
|
185
|
+
* cwd(可缺席)→ 会话落盘的项目目录名:**只有缺席**(`undefined`)落 `_no-cwd`;
|
|
186
|
+
* 空串照常编码——`''` 不是"没有这一格",它是读到了一个空路径。宿主的 `projectDir`
|
|
187
|
+
* (`cwd === void 0` 才走 `_no-cwd`)就是这一支。
|
|
188
|
+
*
|
|
189
|
+
* 删除计划、会话列表投影与对账重建**共用这一处**:三处各自写一遍三元式,`''` 迟早有一处
|
|
190
|
+
* 落成 `_no-cwd`,同一条会话在删除、恢复与孤儿扫描里就会指向两个目录。
|
|
191
|
+
*/
|
|
192
|
+
export declare function projectDirOfCwd(cwd: string | undefined): string;
|
|
101
193
|
/** 这次失败是不是"账本里没那个工作区"(而不是另有故障)。恢复侧靠它把两种失败分开:
|
|
102
194
|
* 前者按「未分组」收,后者照旧回滚报 `io`——不给真故障静默改归属的机会。 */
|
|
103
195
|
export declare function isWorkspaceMissingError(error: unknown): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主 `projectKey(cwd)` 的**编码与解码一对**:字母表、转义与包裹规则只住这一份。
|
|
3
|
+
*
|
|
4
|
+
* - 编码是宿主实现的逐字镜像(跨插件不能 import,宿主也没把它暴露成服务)。出处:asar
|
|
5
|
+
* `dsh-session-persistence-jsonl/lib/index.js` 的 `projectKey`;调用链
|
|
6
|
+
* `locate` → `logPath` → `projectDir` → `projectKey`。本机实测
|
|
7
|
+
* `D:/develop/GitHub/dsh-session-delete` → `--D-develop-GitHub-dsh-session-delete--`。
|
|
8
|
+
* 宿主换代先复核算法。
|
|
9
|
+
* 唯一有意偏离:宿主对空串直接抛(`cannot encode an empty project path`),这里把它编成
|
|
10
|
+
* `--root--`——宿主写日志时不会产生空 cwd,读面碰到的是手工改过的 header;这里只做兜底,
|
|
11
|
+
* 不让一条坏 header 把整次对账/列表读挂掉。
|
|
12
|
+
* - 解码给浏览器半渲染回收站组头用;配对关系由 `tests/assembly.test.ts` 的往返用例钉住。
|
|
13
|
+
* - **空串照常编码**(得到 `--root--`):`''` 不是"没有这格",它是读到了一个空路径。只有
|
|
14
|
+
* **缺席** cwd 才落 `NO_CWD_PROJECT_DIR`,那一条判据住 `src/ports/host-port.ts` 的 `projectDirOfCwd`
|
|
15
|
+
* (删除计划、列表投影与对账重建共用同一处)。宿主的 `projectDir` 在 cwd 缺席时用同名目录,
|
|
16
|
+
* 浏览器半渲染组头时也要认它——所以字面量住这里,两半共用。宿主换代先复核算法。
|
|
17
|
+
*
|
|
18
|
+
* **只还原可还原的那部分**:不在 `[A-Za-z0-9._-]` 里、又不是 `~` 的字符编成 `~` + 4 位大写十六进制
|
|
19
|
+
* 码元,字面 `~` 自己编成 `~007E` ⇒ `~XXXX` 不含歧义。而**分隔符(`/` `\` `:`)被折成一个 `-`,
|
|
20
|
+
* 那一段是有损的**,解码还原不回来——调用方按"尽力显示"用它,别拿它反推真实路径。
|
|
21
|
+
*/
|
|
22
|
+
/** 无 cwd 的会话落在 `_no-cwd/`(宿主 `projectDir` 原文:`if (cwd === void 0) return join(root, "_no-cwd");`)。
|
|
23
|
+
* Node 半用它合成目录名,浏览器半用它把组头念成「未记录项目」——同一事实只有这一份。 */
|
|
24
|
+
export declare const NO_CWD_PROJECT_DIR = "_no-cwd";
|
|
25
|
+
/** cwd → 项目目录名(宿主 `projectKey` 的逐字镜像)。 */
|
|
26
|
+
export declare function escapeProjectKey(cwd: string): string;
|
|
27
|
+
/** 项目目录名 → 可读文本(只还原 `~XXXX`,分隔符折叠的那一段不还原)。 */
|
|
28
|
+
export declare function unescapeProjectKey(encoded: string): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主会话目录的**段编码**:`sessionId` → `sessions/<projectDir>/<段>` 里那一段。
|
|
3
|
+
*
|
|
4
|
+
* 这是宿主 `@deepseek-ai/dsh-session-persistence-jsonl` 的 `encodeSegment` 的逐字镜像(出处:asar 里
|
|
5
|
+
* `dsh-session-persistence-jsonl/src/format.ts`;同一文件的 `sessionDir` 就是它的调用点)。跨插件不能
|
|
6
|
+
* import 宿主源码,宿主也没把它暴露成服务,所以这一份是**镜像**而不是共享实现——宿主换代先复核算法。
|
|
7
|
+
*
|
|
8
|
+
* 为什么必须镜像:`SessionId` 是宿主未校验的品牌字符串,宿主在**任何文件系统调用之前**把它编成一段
|
|
9
|
+
* 安全目录名;本插件按 `sessions/<projectDir>/<段>` 找同一个目录(删除搬走、恢复放回、计划量字节)。
|
|
10
|
+
* 原始 id 拼路径在常见 id 上恰好同形(`session-<uuid>` 整段都在安全字母表里),一旦 id 含 `~`、空格或
|
|
11
|
+
* 非 ASCII 就会指向一个不存在的目录——删除报 not-found、计划量 0 字节,而那条会话其实还在盘上。
|
|
12
|
+
*
|
|
13
|
+
* 口径(与宿主逐字一致,不是口味):
|
|
14
|
+
* - **空串抛**(宿主原话 `cannot encode an empty path segment`):没有"空段"这种目录名;
|
|
15
|
+
* - 整段恰为 `.` / `..` 的**特判**先于逐码元循环:编成 `~002E` / `~002E~002E`,否则目录名会变成上跳;
|
|
16
|
+
* - `[A-Za-z0-9._-]` 码元原样保留;其余每个码元(**包括字面 `~` 自己**)编成 `~` + 4 位大写十六进制
|
|
17
|
+
* ⇒ `~XXXX` 无歧义(字面 `~` 是 `~007E`),且编码可逆;
|
|
18
|
+
* - 按 **UTF-16 码元**(不是码点)处理:孤立代理项也能原样往返——宿主的 `SessionId` 不做码点校验。
|
|
19
|
+
*
|
|
20
|
+
* **唯一调用点归 `src/trash/entry.ts`**:`sessionDirForId` / `sessionDirSegmentOf` 是仓内构造宿主会话
|
|
21
|
+
* 目录的两个口(路径与"写进条目 id 的段"),其余文件只消费**已编码段**——恢复照条目 id 里记下的段回放,
|
|
22
|
+
* 不拿 `sessionId` 再编一遍。
|
|
23
|
+
*
|
|
24
|
+
* **反解只给"目录是唯一线索"的两处**:对账重建(header 没有 `id` 时拿目录段反推会话 id)与投影缓存
|
|
25
|
+
* 的目录名保护(清册行缺失时按目录保护缓存)。恢复**不用**它:条目 id 里记着的段直接接回项目目录,
|
|
26
|
+
* 多一次编解码只会多一个会漂的判据。
|
|
27
|
+
*/
|
|
28
|
+
export declare function encodeSessionSegment(raw: string): string;
|
|
29
|
+
/** {@link encodeSessionSegment} 的逆:把 `~XXXX` 还原成 UTF-16 码元。
|
|
30
|
+
* 编码是单射且字面 `~` 自己也编成 `~007E`,所以"每个 `~` + 4 位大写十六进制"都一定是转义。
|
|
31
|
+
* **已知歧义(刻意接受)**:编码前写下的存量条目 id 第二段是原始 session id,若它本身恰好含
|
|
32
|
+
* `a~007Eb` 这类文本,反解无法与编码产物区分——但编码前的删除只可能发生在**全安全字符**的 id 上
|
|
33
|
+
* (含 `~` 的 id 当时根本找不到目录),所以真实存量里不会出现这种段;手改目录是唯一来源,按反解
|
|
34
|
+
* 结果处理并接受误判。不含 `~XXXX` 形态的旧条目原样交回。 */
|
|
35
|
+
export declare function decodeSessionSegment(encoded: string): string;
|