@xrn1997/dsh-session-delete 0.8.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.
Files changed (91) hide show
  1. package/README.md +133 -173
  2. package/THIRD_PARTY_NOTICES.md +4 -2
  3. package/docs/DETAIL.md +1 -0
  4. package/docs/DETAIL.zh.md +1 -0
  5. package/docs/preview.svg +119 -0
  6. package/docs/preview.zh.svg +117 -0
  7. package/docs/screenshots/screenshot-01.png +0 -0
  8. package/lib/client.js +4244 -2086
  9. package/lib/index.js +1237 -336
  10. package/lib/types/api/archive-rows.d.ts +20 -0
  11. package/lib/types/api/connection-route.d.ts +1 -1
  12. package/lib/types/api/route-table.d.ts +100 -11
  13. package/lib/types/client/archive-detail.d.ts +27 -0
  14. package/lib/types/client/archive-pane.d.ts +60 -0
  15. package/lib/types/client/archive-store.d.ts +6 -0
  16. package/lib/types/client/attachment-view.d.ts +0 -7
  17. package/lib/types/client/batch-bar.d.ts +3 -2
  18. package/lib/types/client/batch-confirm.d.ts +13 -4
  19. package/lib/types/client/batch-menu-item.d.ts +1 -1
  20. package/lib/types/client/batch-pick.d.ts +2 -1
  21. package/lib/types/client/config-settings.d.ts +2 -2
  22. package/lib/types/client/confirm-dialog.d.ts +2 -2
  23. package/lib/types/client/copy.d.ts +53 -13
  24. package/lib/types/client/detail-ledger.d.ts +23 -0
  25. package/lib/types/client/detail-pane.d.ts +33 -0
  26. package/lib/types/client/host-archive-watch.d.ts +22 -0
  27. package/lib/types/client/host-rows.d.ts +7 -0
  28. package/lib/types/client/maintenance-parts.d.ts +4 -3
  29. package/lib/types/client/maintenance-settings.d.ts +4 -3
  30. package/lib/types/client/notice.d.ts +16 -0
  31. package/lib/types/client/orphan-maintenance.d.ts +1 -1
  32. package/lib/types/client/receipt.d.ts +4 -1
  33. package/lib/types/client/remote.d.ts +38 -7
  34. package/lib/types/client/session-detail.d.ts +94 -0
  35. package/lib/types/client/session-list.d.ts +112 -0
  36. package/lib/types/client/settings-cards.d.ts +1 -1
  37. package/lib/types/client/subagent-section.d.ts +45 -0
  38. package/lib/types/client/trash-confirm.d.ts +2 -1
  39. package/lib/types/client/trash-detail.d.ts +9 -60
  40. package/lib/types/client/trash-nav.d.ts +8 -7
  41. package/lib/types/client/trash-panel.d.ts +1 -1
  42. package/lib/types/client/trash-snapshot.d.ts +10 -23
  43. package/lib/types/client/trash-view.d.ts +39 -9
  44. package/lib/types/client/ui/ErrorBoundary.d.ts +32 -0
  45. package/lib/types/client/ui/icons.d.ts +10 -4
  46. package/lib/types/client/undo-notices.d.ts +23 -3
  47. package/lib/types/client/undo-toast.d.ts +4 -1
  48. package/lib/types/client/use-archive-detail-reader.d.ts +28 -0
  49. package/lib/types/client/use-archive-panel-controller.d.ts +73 -0
  50. package/lib/types/client/use-archive-query.d.ts +29 -0
  51. package/lib/types/client/use-detail-rail.d.ts +48 -0
  52. package/lib/types/client/use-detail-reader.d.ts +71 -0
  53. package/lib/types/client/use-gated-refresh.d.ts +27 -0
  54. package/lib/types/client/{use-trash-selection.d.ts → use-list-selection.d.ts} +16 -14
  55. package/lib/types/client/use-maintenance.d.ts +11 -7
  56. package/lib/types/client/use-panel-selection.d.ts +38 -0
  57. package/lib/types/client/use-prompt-rail.d.ts +1 -1
  58. package/lib/types/client/use-trash-detail-reader.d.ts +14 -20
  59. package/lib/types/client/use-trash-panel-controller.d.ts +17 -5
  60. package/lib/types/client/write-seats.d.ts +80 -8
  61. package/lib/types/deps.d.ts +7 -4
  62. package/lib/types/{verbs/errors.d.ts → errors.d.ts} +1 -1
  63. package/lib/types/index.d.ts +1 -1
  64. package/lib/types/log/session-log.d.ts +22 -2
  65. package/lib/types/log/zstd-frames.d.ts +8 -1
  66. package/lib/types/ports/fs-port.d.ts +16 -4
  67. package/lib/types/ports/host-port.d.ts +89 -5
  68. package/lib/types/shared/session-path.d.ts +35 -0
  69. package/lib/types/shared/wire.d.ts +205 -27
  70. package/lib/types/trash/archive-detail.d.ts +27 -0
  71. package/lib/types/trash/attachments.d.ts +4 -1
  72. package/lib/types/trash/detail.d.ts +24 -1
  73. package/lib/types/trash/entry.d.ts +23 -8
  74. package/lib/types/trash/groups.d.ts +1 -0
  75. package/lib/types/trash/ledger.d.ts +4 -2
  76. package/lib/types/trash/projection-cache.d.ts +24 -0
  77. package/lib/types/trash/reconcile.d.ts +5 -3
  78. package/lib/types/trash/session-rows.d.ts +83 -0
  79. package/lib/types/trash/shrinking-view.d.ts +30 -0
  80. package/lib/types/verbs/batch-carried.d.ts +4 -2
  81. package/lib/types/verbs/live-admission.d.ts +7 -2
  82. package/lib/types/verbs/member-journal.d.ts +1 -1
  83. package/lib/types/verbs/permanent-removal.d.ts +15 -5
  84. package/lib/types/verbs/restore-session.d.ts +6 -4
  85. package/lib/types/verbs/trash-scope.d.ts +14 -13
  86. package/locale/en.json +7 -6
  87. package/locale/zh.json +2 -1
  88. package/package.json +10 -4
  89. package/lib/types/client/confirm-close.d.ts +0 -14
  90. package/lib/types/client/write-settlement.d.ts +0 -66
  91. package/lib/types/client/write.d.ts +0 -66
@@ -0,0 +1,83 @@
1
+ /**
2
+ * 一批会话的**行读数装配**(Node 半),三层拆开:
3
+ * **批量面**({@link readRowSurfaces}:标题 / 最后活动 / 大小三个读面各预读一次)、
4
+ * **逐行面**({@link projectRowFacts}:旧宿主标题回退与 label 两种逐行读,共用一份有界并发预算、
5
+ * 只服务输出行)、**合计**({@link sizeTotalsForIds} 按 id 集合算,{@link sizeTotals} 按已投影
6
+ * facts 算)。归档清单(`api/archive-rows.ts`)与归档详情的子会话段(`trash/archive-detail.ts`)
7
+ * 共用这一份:两处的行形状读同一套缺席口径。
8
+ *
9
+ * 为什么逐行读要有界:孩子段一屏两百行、清单一档上千行,无界地把整批逐行读同时挂起是拿宿主的
10
+ * 并发换自己的省事——`ROW_READ_CONCURRENCY` 是这份预算的唯一旋钮。为什么按输出计划读:归档详情
11
+ * 只画前 N 条,显示外的孩子一条逐行读都不该付;摘要条的合计另按全量 id 算(报的是全部孩子的和)。
12
+ *
13
+ * 四条口径住这里,且只住这里:
14
+ * - **标题**:批量读面缺席(旧宿主没有 `titleSnapshots`)⇒ 逐条回退 `titleOf` 的投影标题;
15
+ * 批量在场 ⇒ map 里没有就是空串。`titleOf` / `labelOf` 按端口契约**不抛**(取不到给空串),
16
+ * 所以标题这一格永不失败整档。
17
+ * - **最后活动**:只有 `sessionActivity` 那一份读数,回落什么由调用方决定——`RowTarget.createdAt`
18
+ * 给了才回落(归档清单每行都带着身份记录的创建时间),不给就整格缺席(子会话段没有创建时间)。
19
+ * - **大小**:`persistedSizes` 的**服务缺席** ⇒ 逐行缺大小(显示「—」、合计只加已知);**抛错**怎么办
20
+ * 是调用方的策略(`sizeFailure`):清单要整档 `io`(不拿 0 冒充没有大小),详情那一段不许拖垮正文,
21
+ * 只能逐行缺。
22
+ * - **label**:一次宿主投影读,只为要画这一格的行付钱(`RowTarget.wantsLabel`);空串 = 没有 ⇒ 键不落。
23
+ *
24
+ * 输出与 `targets` **同序同长**:调用方按 index 或 `sessionId` 对齐都行,不另建一份身份表。
25
+ */
26
+ import type { CoreDeps } from '../deps.js';
27
+ import type { CorpusRead } from '../ports/host-port.js';
28
+ /** 一行要读哪些格:`createdAt` 是「没有提问时间时回落什么」,`wantsLabel` 决定要不要读 label 那格。 */
29
+ export interface RowTarget {
30
+ readonly sessionId: string;
31
+ readonly createdAt?: number;
32
+ readonly wantsLabel?: boolean;
33
+ }
34
+ /** 一行的读数:缺席的格**不落键**(`exactOptionalPropertyTypes` 下 `undefined` 与缺席是两件事)。 */
35
+ export interface SessionRowFact {
36
+ readonly sessionId: string;
37
+ readonly title: string;
38
+ readonly label?: string;
39
+ readonly updatedAt?: number;
40
+ readonly updatedAtSource?: 'prompt' | 'created';
41
+ readonly sizeBytes?: number;
42
+ }
43
+ export interface RowReadPolicy {
44
+ /** 大小读面抛错:`throw` ⇒ 原样上抛(整档 `io`);`absent` ⇒ 折成逐行缺大小。 */
45
+ readonly sizeFailure: 'throw' | 'absent';
46
+ }
47
+ /** 逐行读的并发预算:label 与旧宿主标题回退共用这一份——「逐行读」是一个概念,
48
+ * 不是一种读法一扇窗。 */
49
+ export declare const ROW_READ_CONCURRENCY = 8;
50
+ /** 批量面的一次预读快照({@link readRowSurfaces} 的结果):逐行面只消费它,不再发批量读。 */
51
+ export interface RowSurfaces {
52
+ readonly titles: CorpusRead<ReadonlyMap<string, string>>;
53
+ readonly activity: CorpusRead<ReadonlyMap<string, number>>;
54
+ /** 抛错被策略折掉时为 null(与逐行缺同义);服务缺席照旧是显式的 `CorpusRead` 缺席。 */
55
+ readonly sizes: CorpusRead<ReadonlyMap<string, number | undefined>> | null;
56
+ }
57
+ /** 批量面:三个读面各读一次、零逐行读。`ids` 是调用方要显示的那批行;大小读面抛错按策略
58
+ * 折成整档缺席(null)或原样上抛(见 {@link RowReadPolicy})。 */
59
+ export declare function readRowSurfaces(deps: CoreDeps, ids: readonly string[], policy: RowReadPolicy): Promise<RowSurfaces>;
60
+ /** 逐行面:旧宿主标题回退与 label 共用同一份有界并发({@link ROW_READ_CONCURRENCY}),
61
+ * 顺序与 `targets` 对齐、输出同序同长,缺席的格不落键。 */
62
+ export declare function projectRowFacts(deps: CoreDeps, surfaces: RowSurfaces, targets: readonly RowTarget[]): Promise<SessionRowFact[]>;
63
+ /** 兼容包装:一次调用走「批量面 + 逐行面」(归档清单继续用它)。 */
64
+ export declare function projectSessionRows(deps: CoreDeps, targets: readonly RowTarget[], policy: RowReadPolicy): Promise<SessionRowFact[]>;
65
+ /** 合计按 id 集合算(输出计划外的行也进合计):缺席按**传入的每个 id** 计数——读面缺席、
66
+ * 或某 id 在表里没有值,都算缺。摘要条报的是全部孩子的和,不是已列前 N 条的。 */
67
+ export declare function sizeTotalsForIds(ids: readonly string[], sizes: RowSurfaces['sizes']): {
68
+ totalBytes: number;
69
+ missingSizeCount: number;
70
+ };
71
+ /** 大小的合计口径:只加已知的那几行,缺大小的行数单独报(副标题要念「N 条大小缺席」)。 */
72
+ export declare function sizeTotals(facts: readonly SessionRowFact[]): {
73
+ totalBytes: number;
74
+ missingSizeCount: number;
75
+ };
76
+ /** 有界并发的逐条执行器:结果与 `items` **同序同长**、同时挂起的 `fn` 不超过 `limit`、首个失败
77
+ * 原样抛出(失败后不再起新活,已挂起的跑完即弃)。为什么不直接 `Promise.all`:它无界放飞,
78
+ * 而各条自己 settle 的失败还会留下没人收的 rejection。
79
+ *
80
+ * **导出面**:逐行读数用它({@link ROW_READ_CONCURRENCY}),`/list` 的盘上测量也用它
81
+ * (`src/verbs/permanent-removal.ts` 的组与 kids 两级)——"有界并发"只该有这一份实现。
82
+ * 预算由调用方给:两个调用点的窗口大小不是同一个语义。 */
83
+ export declare function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 收缩视图的持有机制的唯一家:entry 适配(restore 的同批已带走集)与清册作用域(purge)过去各手抄
3
+ * 一份「原始快照 + 会收缩的当前视图」,现在都接这一份。
4
+ *
5
+ * 判据不搬:三态读 `groups.ts` 的 `claimOf`、按组收缩读 `withoutGroup`——判据的家仍是组语义
6
+ * (`src/trash/groups.ts`),这里只**持有**两份行并把它们递给判据,无 I/O。
7
+ */
8
+ import type { TrashEntry } from './entry.js';
9
+ import { type GroupClaim } from './groups.js';
10
+ /** 收缩视图的持有面:原始快照判三态,当前视图按组收缩。 */
11
+ export interface ShrinkingView {
12
+ /** 这条 id 现在的三态。只读、可重复——判据读 `claimOf`,同一视图状态连问两次同一个答案。 */
13
+ claim(id: string): GroupClaim;
14
+ /** 收掉一条 id 所属的整组(判据读 `withoutGroup`)。 */
15
+ take(id: string): void;
16
+ /** 把当前视图收缩到空。 */
17
+ takeAll(): void;
18
+ /** 交当前行(选组与扫描都念它),不是原始快照。 */
19
+ view(): readonly TrashEntry[];
20
+ }
21
+ /**
22
+ * 开工时把整批的原始快照捕下来(三态判据的「整批开始前的样子」),当前视图从它出发、按组收缩。
23
+ *
24
+ * 调用纪律:`take` / `takeAll` 都在动作**成功之后**才调——清完才收缩,失败时视图不动、下一次
25
+ * 重试还能看见这一组。`takeAll` 是清空那一支的**收缩到底**(purgeAll 用它),与摘掉某一条 id
26
+ * 的整组是两回事。
27
+ *
28
+ * 什么时候收缩、把实例放在哪里仍归调用方:本函数只持有原始与当前两份行,不记账。
29
+ */
30
+ export declare function createShrinkingView(rows: readonly TrashEntry[]): ShrinkingView;
@@ -1,5 +1,5 @@
1
1
  import type { TrashEntry } from '../trash/entry.js';
2
- import { type GroupClaim } from '../trash/groups.js';
2
+ import type { GroupClaim } from '../trash/groups.js';
3
3
  export interface EntryBatchCarried {
4
4
  claim(id: string): GroupClaim;
5
5
  take(id: string): void;
@@ -12,7 +12,9 @@ export interface SessionBatchCarried {
12
12
  claim(id: string): SessionClaim;
13
13
  take(id: string): void;
14
14
  }
15
- /** 恢复:原始快照认得、当前视图已经空了 ⇒ 同批前一条带走的。 */
15
+ /** 恢复:原始快照认得、当前视图已经空了 ⇒ 同批前一条带走的。这里只接 entry 域的面,
16
+ * 持有与收缩都是 `src/trash/shrinking-view.ts` 的 `createShrinkingView` 那一份(多出的
17
+ * `takeAll` / `view` 不外递,返回值只按 `EntryBatchCarried` 看)。 */
16
18
  export declare function createEntryCarried(original: readonly TrashEntry[]): EntryBatchCarried;
17
19
  /** 删除:会话 id 域;`take` 只收这次真的搬走的成员(父 + 盘上的孩子)。 */
18
20
  export declare function createSessionCarried(): SessionBatchCarried;
@@ -1,6 +1,11 @@
1
1
  /**
2
- * 活体准入:删除 / 永久删除 / 孤儿清理之前,逐个问会话是否在宿主内存里 attach 着;
3
- * 任一在跑就整组拒绝、零副作用(ADR-0008)。
2
+ * 活体准入:删除 / 永久删除 / 孤儿清理之前,逐个问会话**有没有活动**;
3
+ * 判据与宿主端口 `isLive` 一致(`workspace/session-activity` waterfall 非空即算),任一有活动就
4
+ * 整组拒绝、零副作用(ADR-0008)。
5
+ *
6
+ * 「有活动」不是只有 turn 在跑:宿主的 waterfall 还会因为该会话的后台 job、仍指向它的活动定时
7
+ * 任务等回条目(各 family 的安装态实现见宿主 `dsh-jobs` / `dsh-schedule` 的 archive admission)。
8
+ * 所以判定一律问 waterfall 非空,不按某一个 family 现推;宿主换代复核 family 清单。
4
9
  *
5
10
  * 边界:什么时候查归调用方——永久删除在计划里查一次、执行器第一笔写前用计划里的会话名单再查一次(ADR-0027);
6
11
  * 本模块只拥有「查什么、怎么判、怎么说」。
@@ -39,7 +39,7 @@ export declare function attempt(label: string, run: () => Promise<unknown>): Pro
39
39
  export declare function stepUndo(label: string, run: () => Promise<unknown>): Promise<StepUndo>;
40
40
  /**
41
41
  * **组级回滚**:把已经做成的成员按相反顺序退回;某一步退不干净时把失败并进原错误的
42
- * `details.rollbackFailures`,绝不让原错误独走。那些失败句子的合并与措辞住 `src/verbs/errors.ts`;
42
+ * `details.rollbackFailures`,绝不让原错误独走。那些失败句子的合并与措辞住 `src/errors.ts`;
43
43
  * 删除与恢复两个按组走的动词共用这一处。
44
44
  */
45
45
  export declare function rollbackJournals(journals: readonly Journal[], error: unknown): Promise<never>;
@@ -68,6 +68,9 @@ export interface VisibleTrashGroup extends TrashGroupView {
68
68
  * 盘上后代经 `selectStrandedMembers` 选出(排除全部清册 id、bare id 全局只算一次);目录不在的成员
69
69
  * 不进 `members`(与 purge 计划同口径)。成员只吃 {@link measureMembers}:**零账本读**——不再为每个
70
70
  * 盘上后代问一次 `workspaceOf`,`/list` 的失败面不再含账本归属读(归属只有 purge 摘账本才付)。
71
+ *
72
+ * 两级都有界({@link VISIBLE_MEASURE_CONCURRENCY}):组之间、组内 kids 各一扇窗;输出顺序仍按
73
+ * `groups` 原序(`mapLimit` 按 index 落位),首个失败原样抛。
71
74
  */
72
75
  export declare function planVisibleTrash(deps: CoreDeps, rows: readonly TrashEntry[], groups: readonly TrashGroupView[]): Promise<VisibleTrashGroup[]>;
73
76
  /** 一次永久删除的只读计划:哪些目录要删、各自实测多少字节、哪些会话要先摘归档集。
@@ -117,6 +120,17 @@ export declare function planOrphanRemoval(deps: CoreDeps, members: readonly {
117
120
  readonly sessionId: string;
118
121
  readonly projectDir: string;
119
122
  }[]): Promise<RemovalPlan>;
123
+ /** 一次永久删除的成功回执:条数、计划合计字节与附件读数(purge 与 orphan-clean 共用这一形状)。 */
124
+ export interface RemovalStats {
125
+ readonly removed: number;
126
+ readonly freedBytes: number;
127
+ readonly attachments: AttachmentCleanupWire;
128
+ }
129
+ /**
130
+ * 执行器的窄面:把一份计划动成盘、把 {@link RemovalStats} 交回来。清册作用域只拿这一件——
131
+ * 删的能力(`RemovalDeps`)留在持有它的调用方手里、按调用点注入,作用域自己够不着。
132
+ */
133
+ export type RemovalExecutor = (plan: RemovalPlan) => Promise<RemovalStats>;
120
134
  /**
121
135
  * 按计划执行一次永久删除:不再量。回执的字节念计划(`plan.bytes`),执行期不再累加一遍。
122
136
  *
@@ -147,8 +161,4 @@ export declare function planOrphanRemoval(deps: CoreDeps, members: readonly {
147
161
  *
148
162
  * 通告只经 `member-presence`(摘活体三态 + `api-session/removed`),不在这里另写一份。
149
163
  */
150
- export declare function executeRemoval(deps: RemovalDeps, plan: RemovalPlan): Promise<{
151
- removed: number;
152
- freedBytes: number;
153
- attachments: AttachmentCleanupWire;
154
- }>;
164
+ export declare function executeRemoval(deps: RemovalDeps, plan: RemovalPlan): Promise<RemovalStats>;
@@ -13,10 +13,12 @@ import type { CoreDeps } from '../deps.js';
13
13
  * 通告不在本文件:批量层在批尾一次 `announceRestored(ids)`(ADR-0002)。
14
14
  */
15
15
  export declare function restoreSession(deps: CoreDeps): (entryId: string,
16
- /** 这一组(只读):批量层由 `batch-carried.ts` 的 `claimOf` 给出,直调者按 `trash/groups.ts`
17
- * 的 `groupOf` 自己算。ghost 父(父行已摘、只剩孩子)的组只有孩子、不含 `entryId`,这里照旧
18
- * 报 `trash-empty`;其余调用按这一组整体恢复。动词**不收缩**它——收缩与同批已带走集都归
19
- * `verbs/batch-carried.ts`,组语义归 `trash/groups.ts`。 */
16
+ /** 这一组(只读):批量层由 `src/verbs/batch-carried.ts` 的 `claim` 交出(三态判据是
17
+ * `src/trash/groups.ts` 的 `claimOf`、经 `src/trash/shrinking-view.ts` 的持有机制),
18
+ * 直调者按 `src/trash/groups.ts` 的 `groupOf` 自己算。ghost 父(父行已摘、只剩孩子)的组
19
+ * 只有孩子、不含 `entryId`,这里照旧报 `trash-empty`;其余调用按这一组整体恢复。动词
20
+ * **不收缩**它——收缩与同批已带走集都归 `src/verbs/batch-carried.ts`,组语义归
21
+ * `src/trash/groups.ts`。 */
20
22
  group: readonly TrashEntry[]) => Promise<TrashEntry>;
21
23
  /**
22
24
  * 这一次恢复**到底挂不挂账本**:交出能挂的那个 `workspaceId`,挂不了就 `undefined`。
@@ -1,19 +1,22 @@
1
1
  import type { TrashEntry } from '../trash/entry.js';
2
- import type { RemovalDeps } from '../deps.js';
2
+ import type { CoreDeps } from '../deps.js';
3
3
  import type { PurgeStatsWire } from '../shared/wire.js';
4
- import { type OrphanGroup } from './orphan-subagents.js';
4
+ import { type RemovalExecutor } from './permanent-removal.js';
5
5
  /**
6
6
  * **清册作用域(trash scope)**:purge 这条写路径的「拿目标」owner。调用方把一份选好读面的清册
7
- * 快照交进来(写入口 = 真相读;报告入口不经作用域——`/orphans` 直接把 raw 快照交 `loadOrphanGroups`。
8
- * 选哪一格是路由行 / 批量层的事,ADR-0012 的边界不在这里翻),快照与**收缩视图**从此归本模块、
9
- * **不外露**:三态判据与按组收缩都仍读 `trash/groups.ts` 的 `claimOf` / `withoutGroup`,这里只**持有**
10
- * 那份视图,不抄第二遍判据。三个成员的输入输出以 `CONTEXT.md` 的「清册作用域」与下面各成员的
11
- * 注释为准,头注不重写一遍表面契约。
7
+ * 快照交进来(写入口 = 真相读;报告与 orphan-clean 入口不经作用域——`/orphans` 直接把 raw 快照、
8
+ * `applyOrphanClean` 直接把对账行交 `loadOrphanGroups`。选哪一格是路由行 / 批量层的事,ADR-0012
9
+ * 的边界不在这里翻),快照与**收缩视图的实例**从此归本模块、**不外露**:持有机制是
10
+ * `src/trash/shrinking-view.ts` 的 `createShrinkingView`,三态与按组收缩的判据仍住
11
+ * `src/trash/groups.ts`,这里只**持有**那个实例,不抄第二遍判据。两个成员的输入输出以
12
+ * `CONTEXT.md` 的「清册作用域」与下面各成员的注释为准,头注不重写一遍表面契约。
12
13
  *
13
14
  * 彻底删除:从回收站里**真的**抹掉一组(或整站),并连带那些"还留在盘上、没被带走"的后代。
14
- * **这里只做两件事:拿目标、把计划交给执行器**。量目录、筛盘上后代、活体准入与"先退归档集、
15
- * 再摘账本、最后删目录"的顺序都住 `verbs/permanent-removal.ts`——计划只读,执行器不再量、只在第一笔
16
- * 写前补一次只读的活体复查,计划是执行前的第一道闸(别在这里再长出一段手写步骤)。
15
+ * **这里只做两件事:拿目标、把计划交给执行器**——而删的能力**根本不在这个作用域手里**:它收
16
+ * `CoreDeps`(够不着 `removeDir`),执行器由调用方按调用点注入,purge 除注入那一支外没有第二条
17
+ * 删除路径。量目录、筛盘上后代、活体准入与"先退归档集、再摘账本、最后删目录"的顺序都住
18
+ * `src/verbs/permanent-removal.ts`——计划只读,执行器不再量、只在第一笔写前补一次只读的活体复查,
19
+ * 计划是执行前的第一道闸(别在这里再长出一段手写步骤)。
17
20
  *
18
21
  * **不做回滚**:目录删掉就没有"退回去"这回事(删到一半失败时已删目录不回滚;带部分计数的
19
22
  * `details` 回执只属于 `orphan-clean`,purge 的 `removed` / `freedBytes` 仍只在成功回执里给)。
@@ -30,7 +33,5 @@ export interface TrashScope {
30
33
  purge(id: string): Promise<PurgeStatsWire>;
31
34
  /** 清空:全部行一组。 */
32
35
  purgeAll(): Promise<PurgeStatsWire>;
33
- /** 点名根的无主组(根两边去 `session-` 前缀再比);roots 缺席 = 全量。 */
34
- orphanGroups(roots?: readonly string[]): Promise<readonly OrphanGroup[]>;
35
36
  }
36
- export declare function createTrashScope(deps: RemovalDeps, rows: readonly TrashEntry[]): TrashScope;
37
+ export declare function createTrashScope(deps: CoreDeps, rows: readonly TrashEntry[], execute: RemovalExecutor): TrashScope;
package/locale/en.json CHANGED
@@ -1,6 +1,7 @@
1
- {
2
- "meta": {
3
- "title": "Session delete",
4
- "description": "Delete sessions: delete moves them to a recoverable trash, with an explicit permanent delete."
5
- }
6
- }
1
+ {
2
+ "meta": {
3
+ "title": "Session delete",
4
+ "description": "Choose Delete from a session row's ⋯ menu and confirm to move it to Trash in the sidebar, where it can be restored at any time; permanent deletion is a separate, confirmed action. Running sessions cannot be deleted and Trash never expires; all data stays on this machine.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "会话删除",
4
- "description": "删除会话:删除 = 移入回收站(可恢复),另设显式的彻底删除。"
4
+ "description": "在会话行的「⋯」菜单里选「删除」、确认后移入左侧栏的「回收站」,可随时恢复;彻底删除是另一件需要二次确认的显式动作。正在运行的会话删不了,回收站永不自动过期;数据全在本机,不联网。",
5
+ "detail": "docs/DETAIL.zh.md"
5
6
  }
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xrn1997/dsh-session-delete",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "在 DeepSeek Harness 里删除会话:删除=移入回收站(可恢复),另设显式彻底删除",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@11.25.0",
@@ -29,7 +29,11 @@
29
29
  "README.md",
30
30
  "LICENSE",
31
31
  "THIRD_PARTY_NOTICES.md",
32
- "docs/screenshots"
32
+ "docs/screenshots",
33
+ "docs/DETAIL.zh.md",
34
+ "docs/DETAIL.md",
35
+ "docs/preview.zh.svg",
36
+ "docs/preview.svg"
33
37
  ],
34
38
  "engines": {
35
39
  "node": ">=24",
@@ -41,7 +45,7 @@
41
45
  "lint": "eslint .",
42
46
  "test": "vitest run",
43
47
  "test:watch": "vitest",
44
- "pack:dry": "npm pack --dry-run --ignore-scripts",
48
+ "pack:dry": "node scripts/verify-pack.mjs",
45
49
  "prepack": "npm run build",
46
50
  "gates": "pnpm typecheck && pnpm lint && pnpm test && pnpm build && pnpm run pack:dry"
47
51
  },
@@ -101,7 +105,9 @@
101
105
  "0.2.1-rc.2": "compatible",
102
106
  "0.2.1-rc.3": "compatible",
103
107
  "0.2.1-rc.5": "compatible",
104
- "0.2.2-rc.1": "compatible"
108
+ "0.2.2-rc.1": "compatible",
109
+ "0.2.2-rc.2": "compatible",
110
+ "0.2.2-rc.3": "compatible"
105
111
  }
106
112
  },
107
113
  "publishConfig": {
@@ -1,14 +0,0 @@
1
- /** 写入在飞时,确认框的关闭/取消都拦住:一次批量在飞时关掉框,用户会以为"没动",而它其实正在动。
2
- * 各张确认框(单删 / 批量删除 / 回收站恢复与彻底删除 / 孤儿会话清理 / 孤儿附件清理)共用这一条规则;
3
- * `Modal` 的遮罩 / X / Esc 都走同一个 `onClose`。
4
- *
5
- * 返回的 `closeDisabled` 与 `close` 同源:取消键的置灰读数也从这里取,各组件不再各写一遍
6
- * `disabled={busy}`——否则"拦住"这件事会有两个判据。 */
7
- export interface IdleClose {
8
- /** 属性声明而不是方法简写:实现体不读 `this`,调用方会把 `close` 摘下来直接交给 `Modal`/
9
- * `Button`(`onClose={close}`);方法简写会给它隐式 `this: IdleClose`,`unbound-method`
10
- * 就会把这种正常交接报成可疑。形状仍是同一个函数,零运行时改动。 */
11
- close: () => void;
12
- readonly closeDisabled: boolean;
13
- }
14
- export declare function useIdleClose(busy: boolean, onClose: () => void): IdleClose;
@@ -1,66 +0,0 @@
1
- /**
2
- * 一次逐条 `/apply` 写入成功后的**收尾顺序**,按 action 各一条固定序列。
3
- *
4
- * 调用方只交呈现材质(`WritePresentation`),顺序与 `anySuccess` 门只住这里;`runWrite` 在拿到
5
- * `WriteSuccess` 后、`refresh` 前调一次。为什么按 action 收成一处见 ADR-0013。
6
- *
7
- * 四条判据:
8
- * - **跨槽位在信封成功时就跑**:`afterDelete` / `afterRestore` 与 `invalidate` 不管逐条成败都跑
9
- * (回滚失败可能留下半套,回收站清单不能继续摆旧行);呈现钩子(发布/熄灭撤销、遗忘主视图、
10
- * 清详情账本)只在至少一条落地(`anySuccess`)时跑——没有落点的撤销是假动作。delete 的撤销
11
- * 另要求落地名单非空:全部被同批前一条带走时没有可撤销的条目。
12
- * - **面板恢复用 `panelSeat: true` 明说**(「缺席」不再承载语义):外部恢复(撤销横幅)由 settlement
13
- * 调 `afterRestore` 重开;面板恢复自带「回来」的结算,只 `forgetMainView`、不重开、不抢焦点。
14
- * 判据住 `src/client/main-view.ts` 的 `forgetMainView`。
15
- * - **撤销名单由摘要给、座位发布**:delete 支从 `summary.landedIds`(域是条目 id)取名单、用
16
- * `summary.successIds.length` 作条数,组成 `{ entryIds, n }` 交给座位,座位只决定发布哪一形
17
- * (单条带标题、批量带条数)——那句文案与它的键住 `undo-toast.tsx` 与 `copy.ts`;purge 支在
18
- * `anySuccess` 时熄灭指向这些条目的横幅——留着就是一条注定失败的「撤销」。
19
- * - **`count` 不结算**;`orphan-clean` 没有跨槽位收尾(维护卡的 `use-maintenance.ts` 清完自己重查)。
20
- * 不直接读 DOM、不问宿主:主视图收尾只经 `main-view.ts` 的 `afterDelete` / `afterRestore`
21
- * (服务缺席或抛错都静默退回);重读仍归各调用方的 `refresh`(面板那侧的最新票在 `use-trash-query.ts`)。
22
- */
23
- import type { ApplyAction } from '../shared/wire.js';
24
- import type { ReceiptSummary } from './receipt.js';
25
- /** 一次写入里与渲染无关的那部分:动作、请求 id、以及唯一的那份回执摘要。 */
26
- export interface SettledFacts<A extends ApplyAction> {
27
- readonly action: A;
28
- readonly ids: readonly string[];
29
- readonly summary: ReceiptSummary;
30
- }
31
- /**
32
- * 按 action 切开的一族呈现材质:每个座位只能拿到自己动作那几手,形状对不上的钩子在类型面就不存在。
33
- * - `delete` 的 `publishUndo` 存在即「这个座位要发撤销横幅」;它拿到的是 settlement 从摘要取出并组好的落地名单。
34
- * - `restore` 的 `panelSeat: true` 才是「面板已替这条完成『回来』的结算」,不再靠缺席某个钩子暗示。
35
- * - `count` / `orphan-clean` 没有呈现材质(用 `noPresentation`)。
36
- * 钩子都是同步的:settlement 在 `refresh` 前一次跑完,不 await。
37
- */
38
- export type WritePresentationByAction = {
39
- delete: {
40
- /** 外部写入座位:让回收站面板重读。面板写不传(自己的清单重读 `reload` 不走这条通告)。 */
41
- invalidate?(): void;
42
- /** 撤销发布:settlement 从回执摘要取出落地条目 id 与请求名单、组好形之后交来;名单**非空**——
43
- * 全被同批前一条带走时没有落点,settlement 不发布没有可撤销动作的横幅。座位只决定发布哪一形与那一形带的标题。 */
44
- publishUndo?(landed: {
45
- readonly entryIds: readonly [string, ...string[]];
46
- readonly n: number;
47
- }): void;
48
- };
49
- restore: {
50
- invalidate?(): void;
51
- /** 面板恢复座位:true = 面板已替这条完成「回来」的结算,只遗忘、不重开、不抢焦点。 */
52
- panelSeat?: true;
53
- dismissUndo?(entryIds: readonly string[]): void;
54
- forgetTrashDetails?(entryIds: readonly string[]): void;
55
- };
56
- purge: {
57
- dismissUndo?(entryIds: readonly string[]): void;
58
- forgetTrashDetails?(entryIds: readonly string[]): void;
59
- };
60
- count: Record<string, never>;
61
- 'orphan-clean': Record<string, never>;
62
- };
63
- export type WritePresentation<A extends ApplyAction> = WritePresentationByAction[A];
64
- /** 没有呈现材质的座位用它:抛掉按 action 的联合,调用点不用各自造一个空对象字面量。 */
65
- export declare function noPresentation<A extends ApplyAction>(action: A): WritePresentation<A>;
66
- export declare function settleWrite<A extends ApplyAction>(success: SettledFacts<A>, presentation: WritePresentation<A>): void;
@@ -1,66 +0,0 @@
1
- /**
2
- * 一次逐条 `/apply` 写入的**唯一生命周期**:apply → 解信封 → `readReceipt` → 回执摘要 → settlement → refresh。
3
- *
4
- * 收尾顺序与 `anySuccess` 门住 `src/client/write-settlement.ts`(为什么按 action 收见 ADR-0013);
5
- * 这里只管时机、信封判读、整趟的闸与 `refresh` 的交法。清空回收站是聚合回执(`/empty`),收尾仍住
6
- * `use-trash-query.ts` 的 `emptyTrash`。
7
- *
8
- * 五条判据:
9
- * - `ok` 只说**信封**成不成;逐条成败在 `failures` 里,调用方自己决定怎么上屏。
10
- * - 顶层失败把同一句原文铺到每个 id,不结算;`refresh` 照样交(成败都在 outcome 里)。
11
- * - **信封成功就结算**(逐条全失败也跑:批量写入的失效通告不能漏);`anySuccess` 与落地名单由
12
- * `receipt.ts` 的回执摘要算好,settlement 按它上闸。调用方只交呈现材质,再按 `outcome` 决定是否真的重读。
13
- * 结算在 `refresh` 之前:列表重读看得到收尾后的现场。
14
- * - `single: true` 时把 N=1 模式交给 `receipt.ts` 的读法;单条 null 在那一处折成 failed,
15
- * 这里不再重复守卫。
16
- * - **闸包住整趟**:给了 `gate` 就把 apply → settle → refresh 一起包进去——refresh 落在闸外时,
17
- * 旧清单还在屏上,同一个动作能被再点一次;调用方不再自己 `around`。同一枚闸已有任务在飞时
18
- * 这一趟**不跑**(连点不发第二条),交回 `{ kind: 'blocked' }`:座位照它收「这一趟没跑」,
19
- * 不伪造 outcome。
20
- */
21
- import type { BusyGate, GateRun } from './busy-gate.js';
22
- import type { OneShotDeps } from './remote.js';
23
- import { type SettledFacts, type WritePresentation } from './write-settlement.js';
24
- import type { ApplyAction, RemoteFailure } from '../shared/wire.js';
25
- export type WriteSuccess<A extends ApplyAction> = SettledFacts<A> & {
26
- readonly ok: true;
27
- /** 逐条失败原文(failed / neutral / missing),按 id。这是失败表的**唯一落点**:
28
- * 摘要只带聚合与落地 id,不再复制一份逐条原文。 */
29
- readonly failures: ReadonlyMap<string, string>;
30
- };
31
- export interface WriteFailure<A extends ApplyAction> {
32
- readonly ok: false;
33
- readonly action: A;
34
- readonly ids: readonly string[];
35
- readonly failure: RemoteFailure;
36
- /** 顶层失败时同一句原文铺到每个请求 id。 */
37
- readonly failures: ReadonlyMap<string, string>;
38
- }
39
- export type WriteOutcome<A extends ApplyAction> = WriteSuccess<A> | WriteFailure<A>;
40
- export interface WriteInput<A extends ApplyAction> {
41
- readonly deps: OneShotDeps;
42
- readonly action: A;
43
- readonly ids: readonly string[];
44
- /** 单条写入面:把 N=1 模式交给 receipt 读法(null 折成协议错)。 */
45
- readonly single?: boolean | undefined;
46
- /** restore 的 already-gone 回执不带行,它的 sessionId 只能由调用方从当前清单里查。 */
47
- readonly sessionIdOfEntry?: (entryId: string) => string | undefined;
48
- /** 信封成功时交给 settlement 的呈现材质(摘要里的成功名单可能为空);按 action 的收尾顺序住 `write-settlement.ts`。 */
49
- readonly presentation?: WritePresentation<A>;
50
- /** 这一趟的闸:给了就把 apply → settle → refresh 整趟包进 busy。refresh 不许落在闸外。 */
51
- readonly gate?: BusyGate;
52
- /** 写完(顶层失败或信封成功,无论逐条成败)后的重读策略;成败与 `anySuccess` 都在 outcome 里,
53
- * 是否真的重读由调用方决定。 */
54
- readonly refresh?: (outcome: WriteOutcome<A>) => void | Promise<void>;
55
- }
56
- /** 签名上的分岔就是判据:**没传闸 ⇒ 这一趟一定跑**,回真结果;**传了闸 ⇒ 可能被同一枚闸的在飞那一趟
57
- * 挡回**,那时这一趟什么都没做、回 `{ kind: 'blocked' }`。`runWrite` 不替调用方编造成果——挡回来的
58
- * 那趟怎么收尾归座位与界面(判据住 `busy-gate.ts`)。第二支把 `gate` 钉成 `undefined`:
59
- * `BusyGate | undefined` 这类"可能真有闸"的输入不许落到「一定跑完」那一支,否则类型会把挡回漏成
60
- * `WriteOutcome`。 */
61
- export declare function runWrite<A extends ApplyAction>(input: WriteInput<A> & {
62
- readonly gate: BusyGate;
63
- }): Promise<GateRun<WriteOutcome<A>>>;
64
- export declare function runWrite<A extends ApplyAction>(input: WriteInput<A> & {
65
- readonly gate?: undefined;
66
- }): Promise<WriteOutcome<A>>;