@kangyishuai/dsh-session-delete 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +123 -2
- package/README.zh-CN.md +124 -0
- package/cordis.patch.yml +3 -0
- package/lib/audit.js +93 -0
- package/lib/capability.js +106 -0
- package/lib/client.js +1412 -0
- package/lib/index.js +7 -0
- package/lib/journal.js +136 -0
- package/lib/locate.js +129 -0
- package/lib/operations.js +848 -0
- package/lib/paths.js +148 -0
- package/lib/plan.js +185 -0
- package/lib/receipts.js +65 -0
- package/lib/refs.js +192 -0
- package/lib/service.js +202 -0
- package/lib/trash.js +250 -0
- package/locale/en.json +49 -0
- package/locale/zh.json +49 -0
- package/package.json +57 -3
package/lib/service.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Typert Remote 包装层:把 operations 的方法暴露给浏览器,一条 /api 通道。
|
|
3
|
+
// declareRemote 的写法参考 Jaylor-Wang/dsh-tool-session-delete(MIT),见根目录 NOTICE。
|
|
4
|
+
import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
5
|
+
import { createOperations } from "./operations.js";
|
|
6
|
+
import { resolveDataRoot } from "./paths.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 在 decorator 语法不可用(V8 装饰器关闭)的运行时里登记一个 Remote 方法。
|
|
10
|
+
* @param {any} Proto 承载方法的类
|
|
11
|
+
* @param {string} method 方法名,同时也是线缆上的 export 名
|
|
12
|
+
* @returns {void}
|
|
13
|
+
*/
|
|
14
|
+
function declareRemote(Proto, method) {
|
|
15
|
+
/** @type {Function[]} */
|
|
16
|
+
const initializers = [];
|
|
17
|
+
Remote(method)(void 0, {
|
|
18
|
+
name: method,
|
|
19
|
+
static: false,
|
|
20
|
+
private: false,
|
|
21
|
+
addInitializer(/** @type {Function} */ initializer) {
|
|
22
|
+
initializers.push(initializer);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
if (initializers.length !== 1) {
|
|
26
|
+
throw new Error("session-delete: cannot declare Remote method " + method);
|
|
27
|
+
}
|
|
28
|
+
initializers[0].call(Object.create(Proto.prototype));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {unknown} error
|
|
33
|
+
* @returns {never}
|
|
34
|
+
*/
|
|
35
|
+
function rethrow(error) {
|
|
36
|
+
if (error instanceof RemoteError) throw error;
|
|
37
|
+
const code = /** @type {any} */ (error)?.code;
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
throw new RemoteError(typeof code === "string" ? code : "session-delete/failed", message, {
|
|
40
|
+
details: /** @type {any} */ (error)?.details ?? null,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class SessionDeleteService extends TypertRemoteService {
|
|
45
|
+
/**
|
|
46
|
+
* @param {any} ctx host 上下文
|
|
47
|
+
* @param {{ dataRoot?: unknown }} [config]
|
|
48
|
+
*/
|
|
49
|
+
constructor(ctx, config) {
|
|
50
|
+
super(ctx, "sessionDelete");
|
|
51
|
+
this.config = config ?? {};
|
|
52
|
+
/** @type {any} */
|
|
53
|
+
this._ops = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 惰性创建操作层:能力探测必须发生在宿主服务挂载之后,不能在构造函数里固化。
|
|
58
|
+
* @returns {any}
|
|
59
|
+
*/
|
|
60
|
+
get ops() {
|
|
61
|
+
if (this._ops === null) {
|
|
62
|
+
this._ops = createOperations({
|
|
63
|
+
ctx: this.ctx,
|
|
64
|
+
dataRoot: resolveDataRoot(this.config),
|
|
65
|
+
logger: this.ctx.logger ?? console,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return this._ops;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 能力快照、数据根、待恢复的操作数。 */
|
|
72
|
+
async health() {
|
|
73
|
+
return this.ops.health();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 只读:返回完整影响面(plan/dry-run 的数据源)。
|
|
78
|
+
* @param {{ sessionId: string }} request
|
|
79
|
+
*/
|
|
80
|
+
async plan(request) {
|
|
81
|
+
try {
|
|
82
|
+
return await this.ops.plan(request?.sessionId);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
rethrow(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 把会话移入回收站。
|
|
90
|
+
* @param {{ sessionId: string, digest?: string, title?: string | null }} request
|
|
91
|
+
*/
|
|
92
|
+
async trash(request) {
|
|
93
|
+
try {
|
|
94
|
+
return await this.ops.trash(request?.sessionId, {
|
|
95
|
+
digest: request?.digest,
|
|
96
|
+
title: request?.title,
|
|
97
|
+
operator: "ui",
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
rethrow(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async list() {
|
|
105
|
+
try {
|
|
106
|
+
return await this.ops.list();
|
|
107
|
+
} catch (error) {
|
|
108
|
+
rethrow(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 从回收站恢复。
|
|
114
|
+
* @param {{ entryId: string }} request
|
|
115
|
+
*/
|
|
116
|
+
async restore(request) {
|
|
117
|
+
try {
|
|
118
|
+
return await this.ops.restore(request?.entryId, { operator: "ui" });
|
|
119
|
+
} catch (error) {
|
|
120
|
+
rethrow(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 彻底删除一个回收站条目。
|
|
126
|
+
* @param {{ entryId: string }} request
|
|
127
|
+
*/
|
|
128
|
+
async purge(request) {
|
|
129
|
+
try {
|
|
130
|
+
return await this.ops.purge(request?.entryId, { operator: "ui" });
|
|
131
|
+
} catch (error) {
|
|
132
|
+
rethrow(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @param {{ limit?: number }} [request]
|
|
138
|
+
*/
|
|
139
|
+
async audit(request) {
|
|
140
|
+
try {
|
|
141
|
+
return await this.ops.auditLog(request?.limit ?? 100);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
rethrow(error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 最近的操作回执。
|
|
149
|
+
* @param {{ limit?: number }} [request]
|
|
150
|
+
*/
|
|
151
|
+
async receipts(request) {
|
|
152
|
+
try {
|
|
153
|
+
return await this.ops.receipts(request?.limit ?? 50);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
rethrow(error);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 全库体检:只读。 */
|
|
160
|
+
async healthScan() {
|
|
161
|
+
try {
|
|
162
|
+
return await this.ops.scanHealth();
|
|
163
|
+
} catch (error) {
|
|
164
|
+
rethrow(error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 清理体检发现的失效引用(只动登记表)。
|
|
170
|
+
* @param {{ classes?: string[] }} [request]
|
|
171
|
+
*/
|
|
172
|
+
async cleanHealth(request) {
|
|
173
|
+
try {
|
|
174
|
+
return await this.ops.cleanHealth({ classes: request?.classes, operator: "ui" });
|
|
175
|
+
} catch (error) {
|
|
176
|
+
rethrow(error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @param {{ sessionId: string }} request
|
|
182
|
+
*/
|
|
183
|
+
async reconcile(request) {
|
|
184
|
+
try {
|
|
185
|
+
return { checks: await this.ops.reconcile(request?.sessionId) };
|
|
186
|
+
} catch (error) {
|
|
187
|
+
rethrow(error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declareRemote(SessionDeleteService, "health");
|
|
193
|
+
declareRemote(SessionDeleteService, "plan");
|
|
194
|
+
declareRemote(SessionDeleteService, "trash");
|
|
195
|
+
declareRemote(SessionDeleteService, "list");
|
|
196
|
+
declareRemote(SessionDeleteService, "restore");
|
|
197
|
+
declareRemote(SessionDeleteService, "purge");
|
|
198
|
+
declareRemote(SessionDeleteService, "audit");
|
|
199
|
+
declareRemote(SessionDeleteService, "receipts");
|
|
200
|
+
declareRemote(SessionDeleteService, "healthScan");
|
|
201
|
+
declareRemote(SessionDeleteService, "cleanHealth");
|
|
202
|
+
declareRemote(SessionDeleteService, "reconcile");
|
package/lib/trash.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 回收站:原子移动 + meta.json + 恢复 + 彻底删除。
|
|
3
|
+
// 回收站目录固定放在数据根下(同卷,rename 才是 O(1)),陌生条目一律保留并告警。
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { cp, mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { isInside, requireInside, requireSessionId, trashRoot } from "./paths.js";
|
|
8
|
+
|
|
9
|
+
/** meta.json 的格式版本;新版本读旧条目,旧版本忽略新字段。 */
|
|
10
|
+
export const TRASH_SCHEMA = 1;
|
|
11
|
+
/** 回收站里由本插件创建的条目必须带这个标记,彻底删除前会核对。 */
|
|
12
|
+
export const TRASH_PLUGIN = "@kangyishuai/dsh-session-delete";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} TrashMetaInput
|
|
16
|
+
* @property {string | null} [title]
|
|
17
|
+
* @property {string | null} [cwd]
|
|
18
|
+
* @property {number} [bytes]
|
|
19
|
+
* @property {boolean} [live]
|
|
20
|
+
* @property {{ id: string, title: string | null }[]} [children]
|
|
21
|
+
* @property {string[]} [workspaceIds]
|
|
22
|
+
* @property {boolean | null} [pinned]
|
|
23
|
+
* @property {string} [trashedAt]
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const ENTRY_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} TrashMeta
|
|
30
|
+
* @property {number} schema
|
|
31
|
+
* @property {string} entryId
|
|
32
|
+
* @property {string} sessionId
|
|
33
|
+
* @property {string | null} title
|
|
34
|
+
* @property {string | null} cwd
|
|
35
|
+
* @property {string} trashedAt
|
|
36
|
+
* @property {number} bytes
|
|
37
|
+
* @property {boolean} live
|
|
38
|
+
* @property {{ id: string, title: string | null }[]} children
|
|
39
|
+
* @property {string[]} workspaceIds
|
|
40
|
+
* @property {boolean | null} pinned
|
|
41
|
+
* @property {string} originPath
|
|
42
|
+
* @property {string} plugin
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/** @param {string} sessionId @param {number} [now] @returns {string} */
|
|
46
|
+
export function makeEntryId(sessionId, now = Date.now()) {
|
|
47
|
+
const stamp = new Date(now).toISOString().replace(/[:.]/gu, "-");
|
|
48
|
+
const salt = randomUUID().slice(0, 4);
|
|
49
|
+
return `${stamp}-${salt}-${sessionId}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @param {string} entryId @returns {string} */
|
|
53
|
+
export function requireEntryId(entryId) {
|
|
54
|
+
if (typeof entryId !== "string" || !ENTRY_ID.test(entryId)) {
|
|
55
|
+
throw Object.assign(new Error("invalid trash entry id"), {
|
|
56
|
+
code: "session-delete/invalid-entry",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return entryId;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @param {string} dataRoot @param {string} entryId @returns {string} */
|
|
63
|
+
export function entryDir(dataRoot, entryId) {
|
|
64
|
+
return join(trashRoot(dataRoot), requireEntryId(entryId));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {string} dataRoot @param {string} entryId @returns {string} */
|
|
68
|
+
export function entryDataDir(dataRoot, entryId) {
|
|
69
|
+
return join(entryDir(dataRoot, entryId), "data");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @param {string} dataRoot @param {string} entryId @returns {string} */
|
|
73
|
+
export function entryMetaPath(dataRoot, entryId) {
|
|
74
|
+
return join(entryDir(dataRoot, entryId), "meta.json");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 原子移动目录。同卷 rename;跨卷(EXDEV)退化为 cp → 校验 → 删源。
|
|
79
|
+
* @param {string} source
|
|
80
|
+
* @param {string} target
|
|
81
|
+
* @returns {Promise<void>}
|
|
82
|
+
*/
|
|
83
|
+
async function moveDirectory(source, target) {
|
|
84
|
+
try {
|
|
85
|
+
await rename(source, target);
|
|
86
|
+
return;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const code = /** @type {any} */ (error)?.code;
|
|
89
|
+
if (code !== "EXDEV") throw error;
|
|
90
|
+
}
|
|
91
|
+
await cp(source, target, { recursive: true, errorOnExist: true, force: false });
|
|
92
|
+
const [sourceStat, targetStat] = await Promise.all([stat(source), stat(target)]);
|
|
93
|
+
if (!targetStat.isDirectory()) throw new Error("cross-device copy did not produce a directory");
|
|
94
|
+
void sourceStat;
|
|
95
|
+
await rm(source, { recursive: true, force: false });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 把会话目录移入回收站并写 meta.json。
|
|
100
|
+
* @param {object} options
|
|
101
|
+
* @param {string} options.dataRoot
|
|
102
|
+
* @param {string} options.sessionId
|
|
103
|
+
* @param {string} options.sourceDir 会话目录(调用方已校验在 sessions 根内)。
|
|
104
|
+
* @param {TrashMetaInput} options.meta
|
|
105
|
+
* @returns {Promise<{ entryId: string, meta: TrashMeta }>}
|
|
106
|
+
*/
|
|
107
|
+
export async function moveIntoTrash({ dataRoot, sessionId, sourceDir, meta }) {
|
|
108
|
+
requireSessionId(sessionId);
|
|
109
|
+
requireInside(dataRoot, sourceDir);
|
|
110
|
+
|
|
111
|
+
const entryId = makeEntryId(sessionId);
|
|
112
|
+
const root = trashRoot(dataRoot);
|
|
113
|
+
const target = join(root, entryId);
|
|
114
|
+
requireInside(dataRoot, target);
|
|
115
|
+
if (!isInside(root, target)) throw new Error("trash entry escaped the trash root");
|
|
116
|
+
|
|
117
|
+
await mkdir(root, { recursive: true });
|
|
118
|
+
await mkdir(target, { recursive: false });
|
|
119
|
+
const dataDir = join(target, "data");
|
|
120
|
+
await moveDirectory(sourceDir, dataDir);
|
|
121
|
+
|
|
122
|
+
/** @type {TrashMeta} */
|
|
123
|
+
const full = {
|
|
124
|
+
schema: TRASH_SCHEMA,
|
|
125
|
+
entryId,
|
|
126
|
+
sessionId,
|
|
127
|
+
title: meta.title ?? null,
|
|
128
|
+
cwd: meta.cwd ?? null,
|
|
129
|
+
trashedAt: meta.trashedAt ?? new Date().toISOString(),
|
|
130
|
+
bytes: meta.bytes ?? 0,
|
|
131
|
+
live: Boolean(meta.live),
|
|
132
|
+
children: meta.children ?? [],
|
|
133
|
+
workspaceIds: meta.workspaceIds ?? [],
|
|
134
|
+
pinned: meta.pinned ?? null,
|
|
135
|
+
originPath: sourceDir,
|
|
136
|
+
plugin: TRASH_PLUGIN,
|
|
137
|
+
};
|
|
138
|
+
await writeFile(entryMetaPath(dataRoot, entryId), JSON.stringify(full, null, 2), "utf8");
|
|
139
|
+
return { entryId, meta: full };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} dataRoot
|
|
144
|
+
* @param {string} entryId
|
|
145
|
+
* @returns {Promise<TrashMeta>}
|
|
146
|
+
*/
|
|
147
|
+
export async function readEntry(dataRoot, entryId) {
|
|
148
|
+
const raw = await readFile(entryMetaPath(dataRoot, entryId), "utf8");
|
|
149
|
+
const parsed = JSON.parse(raw);
|
|
150
|
+
if (parsed?.plugin !== TRASH_PLUGIN || typeof parsed?.sessionId !== "string") {
|
|
151
|
+
throw Object.assign(new Error("trash entry was not created by this plugin"), {
|
|
152
|
+
code: "session-delete/foreign-entry",
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return /** @type {TrashMeta} */ (parsed);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 列出回收站条目。没有 meta.json 的陌生目录原样保留并单独返回,绝不删除。
|
|
160
|
+
* @param {string} dataRoot
|
|
161
|
+
* @returns {Promise<{ entries: TrashMeta[], unknown: string[] }>}
|
|
162
|
+
*/
|
|
163
|
+
export async function listEntries(dataRoot) {
|
|
164
|
+
const root = trashRoot(dataRoot);
|
|
165
|
+
/** @type {string[]} */
|
|
166
|
+
let names = [];
|
|
167
|
+
try {
|
|
168
|
+
names = (await readdir(root, { withFileTypes: true }))
|
|
169
|
+
.filter(
|
|
170
|
+
(entry) =>
|
|
171
|
+
entry.isDirectory() &&
|
|
172
|
+
!entry.name.startsWith(".") &&
|
|
173
|
+
entry.name !== "journal" &&
|
|
174
|
+
entry.name !== "receipts",
|
|
175
|
+
)
|
|
176
|
+
.map((entry) => entry.name);
|
|
177
|
+
} catch {
|
|
178
|
+
return { entries: [], unknown: [] };
|
|
179
|
+
}
|
|
180
|
+
/** @type {TrashMeta[]} */
|
|
181
|
+
const entries = [];
|
|
182
|
+
/** @type {string[]} */
|
|
183
|
+
const unknown = [];
|
|
184
|
+
for (const name of names) {
|
|
185
|
+
try {
|
|
186
|
+
entries.push(await readEntry(dataRoot, name));
|
|
187
|
+
} catch {
|
|
188
|
+
unknown.push(name);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
entries.sort((a, b) => b.trashedAt.localeCompare(a.trashedAt));
|
|
192
|
+
return { entries, unknown };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 从回收站恢复:把 data/ 移回原路径,成功后再清理条目目录。
|
|
197
|
+
* @param {object} options
|
|
198
|
+
* @param {string} options.dataRoot
|
|
199
|
+
* @param {string} options.entryId
|
|
200
|
+
* @param {string} [options.destinationDir] 覆盖默认的原路径(测试/迁移用)。
|
|
201
|
+
* @returns {Promise<{ meta: TrashMeta, restoredTo: string }>}
|
|
202
|
+
*/
|
|
203
|
+
export async function restoreEntry({ dataRoot, entryId, destinationDir }) {
|
|
204
|
+
const meta = await readEntry(dataRoot, entryId);
|
|
205
|
+
const destination = destinationDir ?? meta.originPath;
|
|
206
|
+
requireInside(dataRoot, destination);
|
|
207
|
+
const dataDir = entryDataDir(dataRoot, entryId);
|
|
208
|
+
requireInside(dataRoot, dataDir);
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await stat(destination);
|
|
212
|
+
throw Object.assign(new Error("the original session directory already exists"), {
|
|
213
|
+
code: "session-delete/restore-conflict",
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (/** @type {any} */ (error)?.code === "session-delete/restore-conflict") throw error;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
220
|
+
await moveDirectory(dataDir, destination);
|
|
221
|
+
|
|
222
|
+
const historyDir = join(trashRoot(dataRoot), ".history");
|
|
223
|
+
await mkdir(historyDir, { recursive: true });
|
|
224
|
+
await writeFile(
|
|
225
|
+
join(historyDir, `${entryId}.json`),
|
|
226
|
+
JSON.stringify(
|
|
227
|
+
{ ...meta, restoredAt: new Date().toISOString(), restoredTo: destination },
|
|
228
|
+
null,
|
|
229
|
+
2,
|
|
230
|
+
),
|
|
231
|
+
"utf8",
|
|
232
|
+
);
|
|
233
|
+
await rm(entryDir(dataRoot, entryId), { recursive: true, force: true });
|
|
234
|
+
return { meta, restoredTo: destination };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 彻底删除一个回收站条目(不可恢复)。
|
|
239
|
+
* @param {object} options
|
|
240
|
+
* @param {string} options.dataRoot
|
|
241
|
+
* @param {string} options.entryId
|
|
242
|
+
* @returns {Promise<{ bytes: number }>}
|
|
243
|
+
*/
|
|
244
|
+
export async function purgeEntry({ dataRoot, entryId }) {
|
|
245
|
+
const meta = await readEntry(dataRoot, entryId);
|
|
246
|
+
const dir = entryDir(dataRoot, entryId);
|
|
247
|
+
requireInside(dataRoot, dir);
|
|
248
|
+
await rm(dir, { recursive: true, force: false });
|
|
249
|
+
return { bytes: meta.bytes ?? 0 };
|
|
250
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sessionDelete": {
|
|
3
|
+
"menu.delete": "Delete session…",
|
|
4
|
+
"menu.trash": "Trash…",
|
|
5
|
+
"confirm.title": "Delete this session?",
|
|
6
|
+
"confirm.loading": "Reading what will be removed…",
|
|
7
|
+
"confirm.desc": "The session moves to the local trash and can be restored.",
|
|
8
|
+
"confirm.size": "Session log is about {size}",
|
|
9
|
+
"confirm.live": "This session is still open; its work is stopped first.",
|
|
10
|
+
"confirm.children": "{n} subagent session(s) come along",
|
|
11
|
+
"confirm.refs": "Will clean: {list}",
|
|
12
|
+
"confirm.trashPath": "Trash location: {path}",
|
|
13
|
+
"confirm.blocked": "Cannot delete right now: {reason}",
|
|
14
|
+
"confirm.cancel": "Cancel",
|
|
15
|
+
"confirm.confirm": "Move to trash",
|
|
16
|
+
"confirm.pending": "Moving to trash…",
|
|
17
|
+
"confirm.done": "Moved to trash",
|
|
18
|
+
"confirm.undo": "Undo",
|
|
19
|
+
"confirm.failed": "Deletion failed",
|
|
20
|
+
"panel.title": "Session trash",
|
|
21
|
+
"panel.tabTrash": "Trash",
|
|
22
|
+
"panel.tabAudit": "Audit",
|
|
23
|
+
"panel.empty": "The trash is empty.",
|
|
24
|
+
"panel.auditEmpty": "No audit entries yet.",
|
|
25
|
+
"panel.restore": "Restore",
|
|
26
|
+
"panel.purge": "Delete for good",
|
|
27
|
+
"panel.purgeConfirm": "Delete for good? This cannot be undone",
|
|
28
|
+
"panel.size": "{size}",
|
|
29
|
+
"panel.trashedAt": "Trashed {time}",
|
|
30
|
+
"panel.unknown": "{n} unrecognized director(ies) kept",
|
|
31
|
+
"panel.pending": "{n} unfinished operation(s)",
|
|
32
|
+
"panel.readOnly": "Read-only: this DSH version is missing required APIs; deletion is disabled.",
|
|
33
|
+
"panel.close": "Close",
|
|
34
|
+
"toast.failed": "Operation failed: {message}",
|
|
35
|
+
"footer.trash": "Trash",
|
|
36
|
+
"panel.tabHealth": "Health",
|
|
37
|
+
"health.loading": "Checking…",
|
|
38
|
+
"health.inventory": "stored {stored} · live {live} · archived {archived} · trash {trash} · pending {pending}",
|
|
39
|
+
"health.ok": "No dangling references found.",
|
|
40
|
+
"health.items": "{n} item(s)",
|
|
41
|
+
"health.unavailable": "Cannot run the check: {reason}",
|
|
42
|
+
"health.clean": "Clean dangling references ({n})",
|
|
43
|
+
"health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only, no session files.",
|
|
44
|
+
"health.cleanDone": "Cleaned {n}",
|
|
45
|
+
"panel.tabReceipts": "Receipts",
|
|
46
|
+
"receipts.empty": "No operation receipts yet.",
|
|
47
|
+
"receipts.restored": "restored"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sessionDelete": {
|
|
3
|
+
"menu.delete": "删除会话…",
|
|
4
|
+
"menu.trash": "回收站…",
|
|
5
|
+
"confirm.title": "删除这个会话?",
|
|
6
|
+
"confirm.loading": "正在读取影响面…",
|
|
7
|
+
"confirm.desc": "会话会被移入本机回收站,可以恢复。",
|
|
8
|
+
"confirm.size": "会话日志约 {size}",
|
|
9
|
+
"confirm.live": "该会话仍在本机打开,删除前会先停止它的工作。",
|
|
10
|
+
"confirm.children": "会一并带上 {n} 个子代理会话",
|
|
11
|
+
"confirm.refs": "将清理:{list}",
|
|
12
|
+
"confirm.trashPath": "回收站位置:{path}",
|
|
13
|
+
"confirm.blocked": "暂时无法删除:{reason}",
|
|
14
|
+
"confirm.cancel": "取消",
|
|
15
|
+
"confirm.confirm": "移入回收站",
|
|
16
|
+
"confirm.pending": "正在移入回收站…",
|
|
17
|
+
"confirm.done": "已移入回收站",
|
|
18
|
+
"confirm.undo": "撤销",
|
|
19
|
+
"confirm.failed": "删除失败",
|
|
20
|
+
"panel.title": "会话回收站",
|
|
21
|
+
"panel.tabTrash": "回收站",
|
|
22
|
+
"panel.tabAudit": "审计",
|
|
23
|
+
"panel.empty": "回收站是空的。",
|
|
24
|
+
"panel.auditEmpty": "还没有审计记录。",
|
|
25
|
+
"panel.restore": "恢复",
|
|
26
|
+
"panel.purge": "彻底删除",
|
|
27
|
+
"panel.purgeConfirm": "彻底删除?不可恢复",
|
|
28
|
+
"panel.size": "占用 {size}",
|
|
29
|
+
"panel.trashedAt": "删除于 {time}",
|
|
30
|
+
"panel.unknown": "{n} 个无法识别的目录已保留",
|
|
31
|
+
"panel.pending": "{n} 个未完成的操作",
|
|
32
|
+
"panel.readOnly": "只读模式:当前 DSH 版本缺少依赖接口,删除功能已禁用。",
|
|
33
|
+
"panel.close": "关闭",
|
|
34
|
+
"toast.failed": "操作失败:{message}",
|
|
35
|
+
"footer.trash": "回收站",
|
|
36
|
+
"panel.tabHealth": "体检",
|
|
37
|
+
"health.loading": "正在检查…",
|
|
38
|
+
"health.inventory": "已存 {stored} · live {live} · 归档 {archived} · 回收站 {trash} · 待处理 {pending}",
|
|
39
|
+
"health.ok": "未发现失效引用。",
|
|
40
|
+
"health.items": "{n} 条",
|
|
41
|
+
"health.unavailable": "无法体检:{reason}",
|
|
42
|
+
"health.clean": "清理失效引用({n})",
|
|
43
|
+
"health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
|
|
44
|
+
"health.cleanDone": "已清理 {n}",
|
|
45
|
+
"panel.tabReceipts": "回执",
|
|
46
|
+
"receipts.empty": "还没有操作回执。",
|
|
47
|
+
"receipts.restored": "已移回原位置"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-session-delete",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Real session deletion for DSH: trash by default, plan before delete, audit log, residue receipt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"session",
|
|
10
|
+
"delete",
|
|
11
|
+
"trash",
|
|
12
|
+
"audit",
|
|
13
|
+
"dry-run"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "nano (https://github.com/kangyishuai)",
|
|
17
|
+
"homepage": "https://github.com/kangyishuai/dsh-plugins/tree/main/packages/session-delete#readme",
|
|
18
|
+
"bugs": "https://github.com/kangyishuai/dsh-plugins/issues",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/kangyishuai/dsh-plugins.git",
|
|
22
|
+
"directory": "packages/session-delete"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "lib/index.js",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./lib/index.js",
|
|
28
|
+
"./client": "./lib/client.js",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"cordis.patch.yml",
|
|
33
|
+
"lib",
|
|
34
|
+
"locale",
|
|
35
|
+
"README.md",
|
|
36
|
+
"README.zh-CN.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dsh": {
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
},
|
|
46
|
+
"client": {
|
|
47
|
+
"platform": "web",
|
|
48
|
+
"inject": [
|
|
49
|
+
"@deepseek-ai/dsh-client-ui-workspace",
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-slots",
|
|
51
|
+
"@deepseek-ai/dsh-client-locale",
|
|
52
|
+
"@deepseek-ai/dsh-client-connection",
|
|
53
|
+
"@deepseek-ai/dsh-client-ui-primitives"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "node --test"
|
|
59
|
+
}
|
|
6
60
|
}
|