dsh-mop 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 +41 -2
- package/client.js +1859 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +5 -0
- package/index.js +40 -0
- package/lib/artifacts.mjs +47 -0
- package/lib/clean.mjs +316 -0
- package/lib/errors.mjs +6 -0
- package/lib/guard.mjs +20 -0
- package/lib/home.mjs +12 -0
- package/lib/routes.mjs +151 -0
- package/lib/session-shell.mjs +45 -0
- package/lib/store.mjs +386 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +43 -4
package/lib/store.mjs
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-mop · 会话存储索引
|
|
3
|
+
*
|
|
4
|
+
* 会话清单、标题、工作区分组、活跃状态一律走官方服务
|
|
5
|
+
* (sessionQuery / workspaceRegistry / agents / sessionProjections);
|
|
6
|
+
* 磁盘只补服务不提供的事实:日志路径与体积、投影缓存孤儿、残壳目录、
|
|
7
|
+
* 空项目目录。
|
|
8
|
+
*/
|
|
9
|
+
import { readdir, readFile, stat, lstat } from 'node:fs/promises';
|
|
10
|
+
import { basename as pathBasename, join } from 'node:path';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { dshHome } from './home.mjs';
|
|
13
|
+
import { isSystemMetadata } from './artifacts.mjs';
|
|
14
|
+
|
|
15
|
+
const SESSION_DIR_RE = /^session-[0-9a-zA-Z-]+$/;
|
|
16
|
+
const SESSION_LOG_RE = /^session(?:\.v\d+)?\.jsonl(?:\.zstd)?$/;
|
|
17
|
+
|
|
18
|
+
// The official reader distinguishes an event-only v4 log from unsupported
|
|
19
|
+
// formats and other corruption, for both raw and compressed storage.
|
|
20
|
+
export async function isEventOnlyLog(ctx, id, dir) {
|
|
21
|
+
const names = (await readdir(dir)).filter((name) => !isSystemMetadata(name));
|
|
22
|
+
const log = names.find((name) => name === 'session.v4.jsonl' || name === 'session.v4.jsonl.zstd');
|
|
23
|
+
if (!log || names.some((name) => name !== 'session.lock' && name !== log)) return false;
|
|
24
|
+
const path = join(dir, log);
|
|
25
|
+
const info = await lstat(path);
|
|
26
|
+
if (!info.isFile() || info.isSymbolicLink()) return false;
|
|
27
|
+
try {
|
|
28
|
+
const handle = await ctx.sessionPersistence.open(id, 'read');
|
|
29
|
+
await handle.close();
|
|
30
|
+
return false;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return error?.name === 'SessionPersistenceCorruptionError'
|
|
33
|
+
&& String(error.message).includes('first line is not a session header')
|
|
34
|
+
&& String(error.message).includes(`(raw log: ${path})`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function sessionsRoot() {
|
|
39
|
+
return dshHome('sessions');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function projcacheDir() {
|
|
43
|
+
return dshHome('storages', 'session_projcache', 'sessions');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The storageDomain workspace table behind the registry; read-only view. */
|
|
47
|
+
export function workspaceTable(ctx) {
|
|
48
|
+
const table = ctx.get('storageDomain')?.get('workspace')?.table('workspaces');
|
|
49
|
+
return table && typeof table.get === 'function' ? table : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Size is the sum of regular file contents, never follows symlinks. Unknown
|
|
53
|
+
// entries, access errors or very large trees produce an unknown measurement.
|
|
54
|
+
async function directoryMetrics(path) {
|
|
55
|
+
let files = 0;
|
|
56
|
+
async function visit(dir) {
|
|
57
|
+
const info = await lstat(dir);
|
|
58
|
+
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('not a directory');
|
|
59
|
+
let sizeBytes = 0;
|
|
60
|
+
let mtimeMs = info.mtimeMs;
|
|
61
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
62
|
+
if (++files > 10000) throw new Error('directory too large to measure');
|
|
63
|
+
const target = join(dir, entry.name);
|
|
64
|
+
if (entry.isDirectory()) {
|
|
65
|
+
const child = await visit(target);
|
|
66
|
+
sizeBytes += child.sizeBytes;
|
|
67
|
+
mtimeMs = Math.max(mtimeMs, child.mtimeMs);
|
|
68
|
+
} else if (entry.isFile()) {
|
|
69
|
+
const child = await lstat(target);
|
|
70
|
+
if (!child.isFile()) throw new Error('file changed while measuring');
|
|
71
|
+
sizeBytes += child.size;
|
|
72
|
+
mtimeMs = Math.max(mtimeMs, child.mtimeMs);
|
|
73
|
+
} else throw new Error('unsupported entry');
|
|
74
|
+
}
|
|
75
|
+
return { sizeBytes, mtimeMs };
|
|
76
|
+
}
|
|
77
|
+
try { return await visit(path); } catch { return { sizeBytes: null, mtimeMs: null }; }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 官方 listSessions 条目 → 统一头部(跨形状防御)。 */
|
|
81
|
+
function headerOf(item) {
|
|
82
|
+
return item?.header && typeof item.header.id === 'string' ? item.header : item;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function scanDisk() {
|
|
86
|
+
const root = sessionsRoot();
|
|
87
|
+
const logs = new Map(); // id → {sessionDir, sizeBytes, mtimeMs}
|
|
88
|
+
const shellDirs = [];
|
|
89
|
+
const emptyProjectDirs = [];
|
|
90
|
+
const projects = await readdir(root, { withFileTypes: true })
|
|
91
|
+
.then((entries) => entries.filter((e) => e.isDirectory()).map((e) => e.name))
|
|
92
|
+
.catch((error) => { if (error.code === 'ENOENT') return []; throw error; });
|
|
93
|
+
for (const project of projects) {
|
|
94
|
+
const projectDir = join(root, project);
|
|
95
|
+
let entries;
|
|
96
|
+
try {
|
|
97
|
+
entries = await readdir(projectDir, { withFileTypes: true });
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error.code === 'ENOENT') continue;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
let sessionCount = 0;
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
if (!entry.isDirectory() || !SESSION_DIR_RE.test(entry.name)) continue;
|
|
105
|
+
sessionCount += 1;
|
|
106
|
+
const sessionDir = join(projectDir, entry.name);
|
|
107
|
+
const names = (await readdir(sessionDir).catch((error) => { if (error.code === 'ENOENT') return []; throw error; }))
|
|
108
|
+
.filter((name) => !isSystemMetadata(name));
|
|
109
|
+
const logName = names.find((n) => SESSION_LOG_RE.test(n));
|
|
110
|
+
if (!logName) {
|
|
111
|
+
let shellType = names.length === 0 ? 'empty' : 'unknown';
|
|
112
|
+
if (names.length === 1 && names[0] === 'session.lock') {
|
|
113
|
+
const lock = await lstat(join(sessionDir, 'session.lock')).catch(() => null);
|
|
114
|
+
if (lock?.isFile() && !lock.isSymbolicLink()) shellType = 'lock';
|
|
115
|
+
}
|
|
116
|
+
shellDirs.push({ sessionId: entry.name, sessionDir, shellType, ...await directoryMetrics(sessionDir) });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const logPath = join(sessionDir, logName);
|
|
120
|
+
const info = await stat(logPath).catch(() => undefined);
|
|
121
|
+
logs.set(entry.name, {
|
|
122
|
+
sessionDir,
|
|
123
|
+
sizeBytes: info?.size ?? null,
|
|
124
|
+
mtimeMs: info?.mtimeMs ?? null,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (sessionCount === 0 && entries.every((entry) => entry.isFile() && isSystemMetadata(entry.name))) {
|
|
128
|
+
const info = await stat(projectDir).catch(() => null);
|
|
129
|
+
emptyProjectDirs.push({ path: projectDir, sizeBytes: 0, mtimeMs: info?.mtimeMs ?? null });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { logs, shellDirs, emptyProjectDirs };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function scanProjcache(knownIds) {
|
|
136
|
+
const orphans = [];
|
|
137
|
+
const files = new Map(); // id → 缓存文件路径
|
|
138
|
+
const titles = new Map(); // id → rows.title.val(侧边栏同源标题)
|
|
139
|
+
const names = await readdir(projcacheDir(), { withFileTypes: true })
|
|
140
|
+
.then((entries) => entries.filter((e) => e.isFile() && e.name.endsWith('.json')).map((e) => e.name))
|
|
141
|
+
.catch(() => []);
|
|
142
|
+
for (const name of names) {
|
|
143
|
+
const id = name.replace(/\.json$/, '');
|
|
144
|
+
const path = join(projcacheDir(), name);
|
|
145
|
+
let title, cwd;
|
|
146
|
+
try {
|
|
147
|
+
const record = JSON.parse(await readFile(path, 'utf8'))?.record;
|
|
148
|
+
title = record?.rows?.title?.val;
|
|
149
|
+
cwd = record?.identity?.cwd;
|
|
150
|
+
} catch { /* 无标题也可清理 */ }
|
|
151
|
+
if (typeof title === 'string' && title) titles.set(id, title);
|
|
152
|
+
files.set(id, path);
|
|
153
|
+
if (!knownIds.has(id)) {
|
|
154
|
+
const info = await stat(path).catch(() => null);
|
|
155
|
+
orphans.push({ id, title: typeof title === 'string' ? title : undefined, cwd: typeof cwd === 'string' && cwd ? cwd : undefined,
|
|
156
|
+
sizeBytes: info?.size ?? null, mtimeMs: info?.mtimeMs ?? null });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return { orphans, files, titles };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 会话列表元数据(blank / lastPromptAt),与官方 session/list 同源:
|
|
164
|
+
* 已挂载会话读 sessionProjections 投影,冷会话读 sessionProjectionCache。
|
|
165
|
+
* 服务缺失或投影未注册时按官方 summarizeCold 语义降级(blank=false)。
|
|
166
|
+
*/
|
|
167
|
+
async function listMetadataOf(ctx, header) {
|
|
168
|
+
try {
|
|
169
|
+
const attached = ctx.get('sessions')?.get(header.id);
|
|
170
|
+
const snapshot = attached !== undefined
|
|
171
|
+
? ctx.get('sessionProjections')?.snapshot(attached, ['sessionListMetadata'])
|
|
172
|
+
: ctx.get('sessionProjectionCache')?.cachedSnapshot(header, ['sessionListMetadata']);
|
|
173
|
+
return snapshot?.values?.sessionListMetadata;
|
|
174
|
+
} catch { return undefined; }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* DSH 的 workspace getter 只暴露可见注册。隐藏注册(被过滤的候选)通过
|
|
179
|
+
* storageDomain 的 workspace 域表读取——与 clean.mjs 校验所用的同一官方
|
|
180
|
+
* 服务面;只读用于展示,从不写该表。
|
|
181
|
+
*/
|
|
182
|
+
function filteredWorkspaceRegistrations(ctx, workspaces) {
|
|
183
|
+
const table = workspaceTable(ctx);
|
|
184
|
+
if (!table) return [];
|
|
185
|
+
const filtered = [];
|
|
186
|
+
for (const workspace of workspaces) {
|
|
187
|
+
const record = table.get(workspace.id);
|
|
188
|
+
if (!record || record.path !== workspace.path || !Array.isArray(record.sessionIds)) continue;
|
|
189
|
+
const visible = new Set(workspace.sessionIds ?? []);
|
|
190
|
+
for (const id of record.sessionIds) {
|
|
191
|
+
if (typeof id === 'string' && SESSION_DIR_RE.test(id) && !visible.has(id)) filtered.push({ id, workspace });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return filtered;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 建全量索引。
|
|
199
|
+
*/
|
|
200
|
+
export async function buildOverview(ctx, config) {
|
|
201
|
+
const [listed, workspaces, archivedIds, disk, persistence] = await Promise.all([
|
|
202
|
+
ctx.sessionQuery.listSessions(),
|
|
203
|
+
ctx.workspaceRegistry.list(),
|
|
204
|
+
Promise.resolve(ctx.workspaceRegistry.archivedSessionIds ?? []),
|
|
205
|
+
scanDisk(),
|
|
206
|
+
ctx.sessionPersistence.list(),
|
|
207
|
+
]);
|
|
208
|
+
|
|
209
|
+
const sessions = (Array.isArray(listed) ? listed : []).map(headerOf).filter(Boolean);
|
|
210
|
+
const listedIds = new Set(sessions.map((header) => header.id));
|
|
211
|
+
const sizeById = new Map();
|
|
212
|
+
for (const snapshot of persistence) {
|
|
213
|
+
const header = headerOf(snapshot);
|
|
214
|
+
if (header && typeof header.id === 'string' && typeof snapshot.sizeBytes === 'number') {
|
|
215
|
+
sizeById.set(header.id, snapshot.sizeBytes);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const titles = new Map();
|
|
220
|
+
try {
|
|
221
|
+
// 官方返回 result 包装数组:{status:'fulfilled', value:{session, title?}}
|
|
222
|
+
const snapshots = await ctx.sessionQuery.readTitleSnapshots(sessions.map((h) => h.id));
|
|
223
|
+
for (const result of Array.isArray(snapshots) ? snapshots : []) {
|
|
224
|
+
if (result?.status !== 'fulfilled') continue;
|
|
225
|
+
const value = result.value;
|
|
226
|
+
if (value?.session?.id && typeof value.title === 'string' && value.title) {
|
|
227
|
+
titles.set(value.session.id, value.title);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} catch { /* 标题缺失时退化 */ }
|
|
231
|
+
|
|
232
|
+
// 工作区分组与注册事实
|
|
233
|
+
const registered = new Map(); // sessionId → workspace entity
|
|
234
|
+
for (const workspace of workspaces) {
|
|
235
|
+
for (const sid of workspace.sessionIds ?? []) registered.set(sid, workspace);
|
|
236
|
+
}
|
|
237
|
+
const archivedSet = new Set(archivedIds);
|
|
238
|
+
const protectedWorkspaces = new Set(config.protectWorkspaces ?? []);
|
|
239
|
+
// Schedule catalog entries are durable references, including paused tasks.
|
|
240
|
+
// A completed session reference/fork is a copied snapshot, not such a link.
|
|
241
|
+
const scheduleRefs = new Map();
|
|
242
|
+
let scheduleCheckFailed = false;
|
|
243
|
+
let scheduleCatalog = [];
|
|
244
|
+
const schedule = ctx.get('schedule');
|
|
245
|
+
if (schedule) {
|
|
246
|
+
try {
|
|
247
|
+
const catalog = await schedule.catalog();
|
|
248
|
+
if (!Array.isArray(catalog)) throw new Error('invalid schedule catalog');
|
|
249
|
+
scheduleCatalog = catalog;
|
|
250
|
+
for (const task of catalog) {
|
|
251
|
+
const ids = new Set(task.involvedSessionIds ?? []);
|
|
252
|
+
if (task.target?.kind !== 'new' && typeof task.target?.sessionId === 'string') ids.add(task.target.sessionId);
|
|
253
|
+
if (typeof task.lastDelivery?.targetSessionId === 'string') ids.add(task.lastDelivery.targetSessionId);
|
|
254
|
+
for (const id of ids) {
|
|
255
|
+
if (typeof id !== 'string') continue;
|
|
256
|
+
if (!scheduleRefs.has(id)) scheduleRefs.set(id, []);
|
|
257
|
+
scheduleRefs.get(id).push({ id: task.id, title: task.title || task.id, status: task.status });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} catch { scheduleCheckFailed = true; scheduleCatalog = []; }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 投影缓存扫描(标题回退源 + 残留判定基线)
|
|
264
|
+
const persistedIds = new Set(persistence.map((s) => headerOf(s)?.id).filter(Boolean));
|
|
265
|
+
for (const [id, log] of disk.logs) {
|
|
266
|
+
if (persistedIds.has(id)) continue;
|
|
267
|
+
if (await isEventOnlyLog(ctx, id, log.sessionDir).catch(() => false)) {
|
|
268
|
+
disk.logs.delete(id);
|
|
269
|
+
disk.shellDirs.push({ sessionId: id, sessionDir: log.sessionDir, shellType: 'log', ...await directoryMetrics(log.sessionDir) });
|
|
270
|
+
} else if (!listedIds.has(id)) {
|
|
271
|
+
// Keep unrecognized and future formats visible without making them
|
|
272
|
+
// eligible for deletion.
|
|
273
|
+
disk.logs.delete(id);
|
|
274
|
+
disk.shellDirs.push({ sessionId: id, sessionDir: log.sessionDir, shellType: 'unknown', ...await directoryMetrics(log.sessionDir) });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const diskIds = new Set(disk.logs.keys());
|
|
278
|
+
const sessionIds = new Set([...diskIds, ...listedIds, ...persistedIds].filter(Boolean));
|
|
279
|
+
const knownIds = new Set([...sessionIds, ...disk.shellDirs.map((s) => s.sessionId)]);
|
|
280
|
+
const cache = await scanProjcache(knownIds);
|
|
281
|
+
|
|
282
|
+
const items = [];
|
|
283
|
+
for (const header of sessions) {
|
|
284
|
+
const log = disk.logs.get(header.id);
|
|
285
|
+
const agent = ctx.get('agents')?.get(header.id);
|
|
286
|
+
const live = agent !== undefined && agent.status !== 'idle';
|
|
287
|
+
// 官方查询包含尚未落盘的空白会话;即使无日志也应显示。
|
|
288
|
+
const workspace = registered.get(header.id);
|
|
289
|
+
// 官方 session/list 同源的列表元数据:blank 标志与最近活动时间。
|
|
290
|
+
const metadata = await listMetadataOf(ctx, header);
|
|
291
|
+
items.push({
|
|
292
|
+
id: header.id,
|
|
293
|
+
title: titles.get(header.id) ?? cache.titles.get(header.id) ?? basename(header.cwd) ?? header.id,
|
|
294
|
+
cwd: header.cwd ?? null,
|
|
295
|
+
live,
|
|
296
|
+
blank: metadata?.blank === true,
|
|
297
|
+
updatedAt: Math.max(
|
|
298
|
+
Number.isFinite(header.createdAt) ? header.createdAt : 0,
|
|
299
|
+
Number.isFinite(metadata?.lastPromptAt) ? metadata.lastPromptAt : 0,
|
|
300
|
+
) || null,
|
|
301
|
+
archived: archivedSet.has(header.id),
|
|
302
|
+
protected: protectedWorkspaces.has(workspace?.path ?? header.cwd),
|
|
303
|
+
purgeBlock: scheduleCheckFailed ? 'reference_check_failed' : scheduleRefs.has(header.id) ? 'schedule_reference' : null,
|
|
304
|
+
scheduleTasks: scheduleRefs.get(header.id) ?? [],
|
|
305
|
+
workspacePath: workspace?.path ?? header.cwd ?? null,
|
|
306
|
+
workspaceTitle: workspace?.title ?? basename(header.cwd) ?? '',
|
|
307
|
+
workspaceCreatedAt: workspace?.createdAt ?? null,
|
|
308
|
+
sizeBytes: sizeById.get(header.id) ?? log?.sizeBytes ?? null,
|
|
309
|
+
mtimeMs: log?.mtimeMs ?? null,
|
|
310
|
+
sessionDir: log?.sessionDir ?? null,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const filteredRegistrations = filteredWorkspaceRegistrations(ctx, workspaces);
|
|
315
|
+
const registrations = new Map();
|
|
316
|
+
for (const workspace of workspaces) {
|
|
317
|
+
for (const id of workspace.sessionIds ?? []) registrations.set(`${workspace.id}:${id}`, { id, workspace });
|
|
318
|
+
}
|
|
319
|
+
for (const entry of filteredRegistrations) registrations.set(`${entry.workspace.id}:${entry.id}`, entry);
|
|
320
|
+
const registrationsBySession = new Map();
|
|
321
|
+
for (const { id, workspace } of registrations.values()) {
|
|
322
|
+
if (!registrationsBySession.has(id)) registrationsBySession.set(id, new Map());
|
|
323
|
+
registrationsBySession.get(id).set(workspace.id, workspace);
|
|
324
|
+
}
|
|
325
|
+
const uniqueRegisteredWorkspace = (id) => {
|
|
326
|
+
const matches = registrationsBySession.get(id);
|
|
327
|
+
return matches?.size === 1 ? matches.values().next().value : undefined;
|
|
328
|
+
};
|
|
329
|
+
// Preserve archived IDs after an interrupted purge, even when the log has
|
|
330
|
+
// already gone. This also exposes pre-existing stale archive entries.
|
|
331
|
+
const itemIds = new Set(items.map((item) => item.id));
|
|
332
|
+
const recoverableShellIds = new Set(disk.shellDirs.filter((item) => ['empty', 'lock', 'log'].includes(item.shellType)).map((item) => item.sessionId));
|
|
333
|
+
for (const id of archivedSet) {
|
|
334
|
+
if (itemIds.has(id) || recoverableShellIds.has(id) || !SESSION_DIR_RE.test(id)) continue;
|
|
335
|
+
const workspace = uniqueRegisteredWorkspace(id);
|
|
336
|
+
items.push({ id, title: cache.titles.get(id) ?? id, cwd: workspace?.path ?? null,
|
|
337
|
+
live: false,
|
|
338
|
+
archived: true, protected: protectedWorkspaces.has(workspace?.path),
|
|
339
|
+
purgeBlock: scheduleCheckFailed ? 'reference_check_failed' : scheduleRefs.has(id) ? 'schedule_reference' : null,
|
|
340
|
+
scheduleTasks: scheduleRefs.get(id) ?? [], workspacePath: workspace?.path ?? null,
|
|
341
|
+
workspaceTitle: workspace?.title ?? '', workspaceCreatedAt: workspace?.createdAt ?? null,
|
|
342
|
+
sizeBytes: null, mtimeMs: null, sessionDir: null });
|
|
343
|
+
}
|
|
344
|
+
const ghostRegistrations = [...registrations.values()].filter(({ id }) => !knownIds.has(id)).map(({ id, workspace }) => ({
|
|
345
|
+
id, workspaceId: workspace.id, workspacePath: workspace.path, workspaceTitle: workspace.title, workspaceCreatedAt: workspace.createdAt ?? null,
|
|
346
|
+
}));
|
|
347
|
+
const workspacesByPath = new Map(workspaces.map((w) => [w.path, w]));
|
|
348
|
+
// `new_once` reserves an ID before its first delivery; it is not a missing
|
|
349
|
+
// session. After delivery DSH changes its target kind to `session`.
|
|
350
|
+
const orphanTasks = scheduleCatalog.filter((task) => task.target?.kind === 'session'
|
|
351
|
+
&& typeof task.target.sessionId === 'string' && !knownIds.has(task.target.sessionId)
|
|
352
|
+
&& !archivedSet.has(task.target.sessionId)).map((task) => {
|
|
353
|
+
const workspace = uniqueRegisteredWorkspace(task.target.sessionId);
|
|
354
|
+
const time = Date.parse(task.updatedAt ?? task.createdAt ?? '');
|
|
355
|
+
return { id: task.id, title: task.title || task.id, status: task.status,
|
|
356
|
+
targetSessionId: task.target.sessionId, updatedAt: task.updatedAt ?? null,
|
|
357
|
+
mtimeMs: Number.isFinite(time) ? time : null, workspacePath: workspace?.path,
|
|
358
|
+
workspaceTitle: workspace?.title, workspaceCreatedAt: workspace?.createdAt ?? null };
|
|
359
|
+
});
|
|
360
|
+
const orphanCaches = cache.orphans.map((item) => {
|
|
361
|
+
const workspace = item.cwd ? workspacesByPath.get(item.cwd) : uniqueRegisteredWorkspace(item.id);
|
|
362
|
+
const workspacePath = item.cwd ?? workspace?.path;
|
|
363
|
+
return { ...item, workspacePath, workspaceTitle: workspace?.title ?? basename(workspacePath), workspaceCreatedAt: workspace?.createdAt ?? null };
|
|
364
|
+
});
|
|
365
|
+
const shellDirs = disk.shellDirs.filter((s) => !sessionIds.has(s.sessionId)).map((item) => {
|
|
366
|
+
const workspace = uniqueRegisteredWorkspace(item.sessionId);
|
|
367
|
+
return { ...item, workspacePath: workspace?.path, workspaceTitle: workspace?.title, workspaceCreatedAt: workspace?.createdAt ?? null };
|
|
368
|
+
});
|
|
369
|
+
return {
|
|
370
|
+
sessions: items,
|
|
371
|
+
residue: {
|
|
372
|
+
orphanCaches,
|
|
373
|
+
orphanTasks,
|
|
374
|
+
ghostRegistrations,
|
|
375
|
+
shellDirs,
|
|
376
|
+
emptyProjectDirs: disk.emptyProjectDirs,
|
|
377
|
+
},
|
|
378
|
+
cacheFiles: cache.files,
|
|
379
|
+
home: homedir(),
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function basename(path) {
|
|
384
|
+
if (typeof path !== 'string' || !path) return undefined;
|
|
385
|
+
return pathBasename(path) || undefined;
|
|
386
|
+
}
|
package/locale/de.json
ADDED
package/locale/en.json
ADDED
package/locale/es.json
ADDED
package/locale/fr.json
ADDED
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "View, archive, and clean DSH sessions and residual data",
|
|
5
|
+
"author": "tryhub",
|
|
6
|
+
"homepage": "https://gitee.com/tryhub/dsh-mop",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://gitee.com/tryhub/dsh-mop.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./index.js",
|
|
14
|
+
"./client": "./client.js",
|
|
15
|
+
"./locale/*.json": "./locale/*.json",
|
|
16
|
+
"./icon": "./icon.svg"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"client.js",
|
|
21
|
+
"cordis.patch.yml",
|
|
22
|
+
"lib",
|
|
23
|
+
"locale/*.json",
|
|
24
|
+
"icon.svg"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@deepseek-ai/schemastery": "~3.19.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@deepseek-ai/cordis": "~4.1.0"
|
|
32
|
+
},
|
|
33
|
+
"dsh": {
|
|
34
|
+
"bundle": {
|
|
35
|
+
"patch": "./cordis.patch.yml"
|
|
36
|
+
},
|
|
37
|
+
"client": {
|
|
38
|
+
"platform": "web",
|
|
39
|
+
"inject": [
|
|
40
|
+
"@deepseek-ai/dsh-client-locale",
|
|
41
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|