dsh-zed-cc-workbench 0.0.0-stage → 2.0.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/index.js ADDED
@@ -0,0 +1,616 @@
1
+ /**
2
+ * Host half of the All sessions bundle.
3
+ *
4
+ * The browser page cannot read Zed's SQLite database, so this row keeps a small
5
+ * projection of Zed's own thread metadata on disk:
6
+ *
7
+ * <DSH_HOME>/storages/zed-thread-titles.json
8
+ *
9
+ * For every Zed sidebar thread that originated from an external agent it stores
10
+ * the effective title (Zed's rename override when present, otherwise the stored
11
+ * title). The client half reads that file through `workspaceFiles.readBytes`
12
+ * and shows the same name the user sees in Zed.
13
+ *
14
+ * The projection is refreshed on an interval while the DSH app is running; it
15
+ * is best-effort and never throws into the profile tree.
16
+ */
17
+ import fs from 'node:fs';
18
+ import os from 'node:os';
19
+ import path from 'node:path';
20
+ import zlib from 'node:zlib';
21
+ import { createHash } from 'node:crypto';
22
+
23
+ const POLL_MS = 5000;
24
+ const DIGEST_POLL_MS = 15000;
25
+ const CLAUDE_POLL_MS = 10000;
26
+ const DIGEST_TEXT_LIMIT = 6000;
27
+ const TOOL_ARGS_LIMIT = 1200;
28
+ const ZSTD_MAGIC = Buffer.from([0x28, 0xb5, 0x2f, 0xfd]);
29
+
30
+ function dshHome() {
31
+ return process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
32
+ }
33
+
34
+ function projectionPath() {
35
+ return path.join(dshHome(), 'storages', 'zed-thread-titles.json');
36
+ }
37
+
38
+ export function digestPath() {
39
+ return path.join(dshHome(), 'storages', 'all-sessions-messages.json');
40
+ }
41
+
42
+ function sessionsRoot() {
43
+ return path.join(dshHome(), 'sessions');
44
+ }
45
+
46
+ export function claudeMetaPath() {
47
+ return path.join(dshHome(), 'storages', 'claude-sessions.json');
48
+ }
49
+
50
+ export function claudeMessagesPath() {
51
+ return path.join(dshHome(), 'storages', 'claude-messages.json');
52
+ }
53
+
54
+ function claudeProjectsRoot() {
55
+ return path.join(os.homedir(), '.claude', 'projects');
56
+ }
57
+
58
+ /** Locate the Claude Code CLI; cmd.exe sessions do not always have the npm shim on PATH. */
59
+ export function resolveClaudeCommand() {
60
+ const candidates = [];
61
+ if (process.platform === 'win32') {
62
+ const appData = process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
63
+ candidates.push(path.join(os.homedir(), 'AppData', 'Roaming', 'npm', 'node_modules', '@anthropic-ai', 'claude-code', 'bin', 'claude.exe'));
64
+ candidates.push(path.join(appData, 'npm', 'claude.cmd'));
65
+ candidates.push(path.join(appData, 'npm', 'claude.exe'));
66
+ } else {
67
+ candidates.push(path.join(os.homedir(), '.local', 'bin', 'claude'));
68
+ candidates.push('/usr/local/bin/claude');
69
+ candidates.push('/opt/homebrew/bin/claude');
70
+ }
71
+ for (const candidate of candidates) {
72
+ try {
73
+ if (fs.existsSync(candidate)) return candidate;
74
+ } catch {}
75
+ }
76
+ const names = process.platform === 'win32' ? ['claude.cmd', 'claude.exe', 'claude'] : ['claude'];
77
+ for (const dir of String(process.env.PATH || '').split(path.delimiter)) {
78
+ if (!dir) continue;
79
+ for (const name of names) {
80
+ const candidate = path.join(dir, name);
81
+ try {
82
+ if (fs.existsSync(candidate)) return candidate;
83
+ } catch {}
84
+ }
85
+ }
86
+ return 'claude';
87
+ }
88
+
89
+ function zedThreadsDbPath() {
90
+ const candidates = [];
91
+ if (process.platform === 'darwin') {
92
+ candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'Zed', 'db', '0-stable', 'db.sqlite'));
93
+ } else if (process.platform === 'linux') {
94
+ const dataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');
95
+ candidates.push(path.join(dataHome, 'zed', 'db', '0-stable', 'db.sqlite'));
96
+ candidates.push(path.join(dataHome, 'Zed', 'db', '0-stable', 'db.sqlite'));
97
+ } else {
98
+ const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
99
+ candidates.push(path.join(localAppData, 'Zed', 'db', '0-stable', 'db.sqlite'));
100
+ }
101
+ return candidates.find((candidate) => fs.existsSync(candidate)) || candidates[0];
102
+ }
103
+
104
+ const THREAD_SQL = 'select session_id, agent_id, title, title_override, archived, updated_at from sidebar_threads where session_id is not null';
105
+
106
+ async function queryThreads(source) {
107
+ const { DatabaseSync } = await import('node:sqlite');
108
+ const db = new DatabaseSync(source, { readOnly: true });
109
+ try {
110
+ return db.prepare(THREAD_SQL).all();
111
+ } finally {
112
+ try { db.close(); } catch {}
113
+ }
114
+ }
115
+
116
+ async function readZedThreads() {
117
+ const source = zedThreadsDbPath();
118
+ if (!fs.existsSync(source)) return [];
119
+ try {
120
+ return await queryThreads(source);
121
+ } catch {
122
+ // WAL mode may refuse read-only opens while Zed holds the write lock; copy
123
+ // the database triple into a scratch directory and read that snapshot.
124
+ let scratch;
125
+ try {
126
+ scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-zed-threads-'));
127
+ for (const suffix of ['', '-wal', '-shm']) {
128
+ const from = source + suffix;
129
+ if (fs.existsSync(from)) fs.copyFileSync(from, path.join(scratch, 'db.sqlite' + suffix));
130
+ }
131
+ return await queryThreads(path.join(scratch, 'db.sqlite'));
132
+ } catch {
133
+ return [];
134
+ } finally {
135
+ if (scratch) {
136
+ try { fs.rmSync(scratch, { recursive: true, force: true }); } catch {}
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ /** Build the wire projection from raw `sidebar_threads` rows. */
143
+ export function buildProjection(rows, now = new Date()) {
144
+ const threads = {};
145
+ for (const row of rows) {
146
+ const sessionId = row.session_id === null || row.session_id === undefined ? '' : String(row.session_id).trim();
147
+ if (sessionId.length === 0) continue;
148
+ const storedTitle = typeof row.title === 'string' ? row.title.trim() : '';
149
+ const override = typeof row.title_override === 'string' ? row.title_override.trim() : '';
150
+ threads[sessionId] = {
151
+ title: override.length > 0 ? override : storedTitle,
152
+ storedTitle,
153
+ override: override.length > 0 ? override : null,
154
+ archived: row.archived === 1 || row.archived === true || row.archived === '1',
155
+ agentId: row.agent_id === null || row.agent_id === undefined ? null : String(row.agent_id),
156
+ updatedAt: row.updated_at === null || row.updated_at === undefined ? null : String(row.updated_at),
157
+ };
158
+ }
159
+ return {
160
+ version: 1,
161
+ updatedAt: now.toISOString(),
162
+ source: zedThreadsDbPath(),
163
+ threads,
164
+ };
165
+ }
166
+
167
+ /** One refresh of the on-disk projection; safe to call from a test harness. */
168
+ export async function syncZedThreads(now = new Date()) {
169
+ const rows = await readZedThreads();
170
+ const projection = buildProjection(rows, now);
171
+ const target = projectionPath();
172
+ fs.mkdirSync(path.dirname(target), { recursive: true });
173
+ const serialized = JSON.stringify(projection);
174
+ const temporary = `${target}.${process.pid}.tmp`;
175
+ fs.writeFileSync(temporary, serialized, 'utf8');
176
+ fs.renameSync(temporary, target);
177
+ return projection;
178
+ }
179
+
180
+ function textParts(content) {
181
+ if (!Array.isArray(content)) return '';
182
+ const parts = [];
183
+ for (const part of content) {
184
+ if (part && part.type === 'text' && typeof part.text === 'string' && part.text.trim()) parts.push(part.text);
185
+ }
186
+ return parts.join('\n');
187
+ }
188
+
189
+ function decodeZstdFrames(file) {
190
+ const raw = fs.readFileSync(file);
191
+ let text = '';
192
+ let offset = 0;
193
+ while (offset < raw.length) {
194
+ const next = raw.indexOf(ZSTD_MAGIC, offset + 1);
195
+ const end = next === -1 ? raw.length : next;
196
+ try {
197
+ text += zlib.zstdDecompressSync(raw.subarray(offset, end)).toString('utf8');
198
+ } catch {}
199
+ offset = end;
200
+ }
201
+ return text;
202
+ }
203
+
204
+ function pickSessionLogs(dir) {
205
+ let names = [];
206
+ try {
207
+ names = fs.readdirSync(dir).filter((name) => /^session.*\.jsonl\.zstd$/.test(name));
208
+ } catch {
209
+ return [];
210
+ }
211
+ // A session can keep both a legacy log and a v4 log (e.g. after migration);
212
+ // the message history may only be complete in one of them, so read them all
213
+ // and merge by time+text later.
214
+ return names.map((name) => path.join(dir, name));
215
+ }
216
+
217
+ function listSessionLogs() {
218
+ const root = sessionsRoot();
219
+ const out = [];
220
+ let buckets = [];
221
+ try {
222
+ buckets = fs.readdirSync(root, { withFileTypes: true });
223
+ } catch {
224
+ return out;
225
+ }
226
+ for (const bucket of buckets) {
227
+ if (!bucket.isDirectory()) continue;
228
+ const bucketDir = path.join(root, bucket.name);
229
+ let entries = [];
230
+ try {
231
+ entries = fs.readdirSync(bucketDir, { withFileTypes: true });
232
+ } catch {
233
+ continue;
234
+ }
235
+ for (const entry of entries) {
236
+ if (!entry.isDirectory()) continue;
237
+ // Session directories are usually named `session-<uuid>`, but ACP/Zed
238
+ // sessions use the bare session id, so accept any directory with a log.
239
+ const files = pickSessionLogs(path.join(bucketDir, entry.name));
240
+ if (files.length > 0) out.push({ sessionId: entry.name, files });
241
+ }
242
+ }
243
+ return out;
244
+ }
245
+
246
+ /**
247
+ * Extract the searchable conversation text of one session:
248
+ * u — user messages, a — assistant text, c — tool call name + arguments.
249
+ * Tool results (command output, file contents, search results) are excluded.
250
+ */
251
+ export function extractSessionMessages(sessionId, text) {
252
+ const messages = [];
253
+ const seen = new Set();
254
+ for (const line of text.split('\n')) {
255
+ if (!line.trim()) continue;
256
+ let event;
257
+ try {
258
+ event = JSON.parse(line);
259
+ } catch {
260
+ continue;
261
+ }
262
+ const data = event && event.data;
263
+ if (!data) continue;
264
+ let kind = '';
265
+ let body = '';
266
+ if (event.type === 'user/message') {
267
+ kind = 'u';
268
+ body = textParts(data.content);
269
+ } else if (event.type === 'assistant/message') {
270
+ kind = 'a';
271
+ body = textParts((data.message || {}).content);
272
+ } else if (event.type === 'tool/call') {
273
+ kind = 'c';
274
+ const name = typeof data.name === 'string' ? data.name : '';
275
+ let args = '';
276
+ if (typeof data.arguments === 'string') args = data.arguments;
277
+ else if (data.arguments !== undefined) {
278
+ try { args = JSON.stringify(data.arguments); } catch { args = ''; }
279
+ }
280
+ body = `${name} ${args}`.trim();
281
+ }
282
+ if (!kind || !body) continue;
283
+ body = body.trim();
284
+ const limit = kind === 'c' ? TOOL_ARGS_LIMIT : DIGEST_TEXT_LIMIT;
285
+ if (body.length > limit) body = `${body.slice(0, limit)}…`;
286
+ const key = `${kind}:${event.seq}:${body.slice(0, 120)}`;
287
+ if (seen.has(key)) continue;
288
+ seen.add(key);
289
+ messages.push({ s: sessionId, k: kind, t: Number(event.time) || 0, x: body });
290
+ }
291
+ return messages;
292
+ }
293
+
294
+ const digestCache = new Map();
295
+ let digestFingerprint = '';
296
+
297
+ /** Rebuild the client-side search digest from changed session logs. */
298
+ export async function syncMessageDigest(ctx = {}) {
299
+ const logs = listSessionLogs();
300
+ if (logs.length === 0) return false;
301
+ let changed = false;
302
+ const seen = new Set();
303
+ for (const { sessionId, files } of logs) {
304
+ seen.add(sessionId);
305
+ const stats = [];
306
+ for (const file of files) {
307
+ try {
308
+ const stat = fs.statSync(file);
309
+ stats.push({ file, mtimeMs: stat.mtimeMs, size: stat.size });
310
+ } catch {}
311
+ }
312
+ if (stats.length === 0) continue;
313
+ const cached = digestCache.get(sessionId);
314
+ const same = cached
315
+ && cached.files.length === stats.length
316
+ && stats.every((entry) => cached.files.some((old) => old.file === entry.file && old.mtimeMs === entry.mtimeMs && old.size === entry.size));
317
+ if (same) continue;
318
+ try {
319
+ const messages = [];
320
+ const seenMessages = new Set();
321
+ for (const { file } of stats) {
322
+ const text = decodeZstdFrames(file);
323
+ for (const message of extractSessionMessages(sessionId, text)) {
324
+ const key = `${message.k}:${message.t}:${message.x.slice(0, 200)}`;
325
+ if (seenMessages.has(key)) continue;
326
+ seenMessages.add(key);
327
+ messages.push(message);
328
+ }
329
+ }
330
+ digestCache.set(sessionId, { files: stats, messages });
331
+ changed = true;
332
+ } catch (error) {
333
+ ctx.logger?.warn?.(`all-sessions: digest skipped ${sessionId}: ${String(error)}`);
334
+ }
335
+ await new Promise((resolve) => setImmediate(resolve));
336
+ }
337
+ for (const id of [...digestCache.keys()]) {
338
+ if (!seen.has(id)) {
339
+ digestCache.delete(id);
340
+ changed = true;
341
+ }
342
+ }
343
+ if (!changed) return false;
344
+ const messages = [];
345
+ for (const entry of digestCache.values()) messages.push(...entry.messages);
346
+ messages.sort((a, b) => a.t - b.t);
347
+ const serialized = JSON.stringify({ version: 1, generatedAt: new Date().toISOString(), messages });
348
+ const fingerprint = createHash('sha1').update(serialized).digest('hex');
349
+ if (fingerprint === digestFingerprint && fs.existsSync(digestPath())) return false;
350
+ const target = digestPath();
351
+ fs.mkdirSync(path.dirname(target), { recursive: true });
352
+ const temporary = `${target}.${process.pid}.tmp`;
353
+ fs.writeFileSync(temporary, serialized, 'utf8');
354
+ fs.renameSync(temporary, target);
355
+ digestFingerprint = fingerprint;
356
+ return true;
357
+ }
358
+
359
+ function writeAtomic(target, serialized) {
360
+ fs.mkdirSync(path.dirname(target), { recursive: true });
361
+ const temporary = `${target}.${process.pid}.tmp`;
362
+ fs.writeFileSync(temporary, serialized, 'utf8');
363
+ fs.renameSync(temporary, target);
364
+ }
365
+
366
+ function listClaudeSessionFiles() {
367
+ const root = claudeProjectsRoot();
368
+ const out = [];
369
+ let buckets = [];
370
+ try {
371
+ buckets = fs.readdirSync(root, { withFileTypes: true });
372
+ } catch {
373
+ return out;
374
+ }
375
+ const walk = (dir) => {
376
+ let entries = [];
377
+ try {
378
+ entries = fs.readdirSync(dir, { withFileTypes: true });
379
+ } catch {
380
+ return;
381
+ }
382
+ for (const entry of entries) {
383
+ const full = path.join(dir, entry.name);
384
+ if (entry.isDirectory()) {
385
+ walk(full);
386
+ continue;
387
+ }
388
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.jsonl$/i.test(entry.name)) continue;
389
+ out.push(full);
390
+ }
391
+ };
392
+ walk(root);
393
+ return out;
394
+ }
395
+
396
+ /** Extract one Claude Code transcript: metadata plus searchable messages. */
397
+ export function extractClaudeSession(sessionId, text) {
398
+ const meta = { id: sessionId, cwd: '', aiTitle: '', firstUser: '', surface: 'cc', updatedAt: 0 };
399
+ const messages = [];
400
+ const seen = new Set();
401
+ const entrypoints = new Map();
402
+
403
+ const push = (kind, body, time) => {
404
+ const trimmed = String(body || '').trim();
405
+ if (!trimmed) return;
406
+ const limit = kind === 'c' ? TOOL_ARGS_LIMIT : DIGEST_TEXT_LIMIT;
407
+ const value = trimmed.length > limit ? `${trimmed.slice(0, limit)}…` : trimmed;
408
+ const key = `${kind}:${time}:${value.slice(0, 120)}`;
409
+ if (seen.has(key)) return;
410
+ seen.add(key);
411
+ messages.push({ s: sessionId, k: kind, t: Number(time) || 0, x: value });
412
+ };
413
+
414
+ for (const line of text.split('\n')) {
415
+ if (!line.trim()) continue;
416
+ let event;
417
+ try {
418
+ event = JSON.parse(line);
419
+ } catch {
420
+ continue;
421
+ }
422
+ if (typeof event.cwd === 'string' && event.cwd && !meta.cwd) meta.cwd = event.cwd;
423
+ if (typeof event.entrypoint === 'string' && event.entrypoint) entrypoints.set(event.entrypoint, (entrypoints.get(event.entrypoint) || 0) + 1);
424
+ if (event.type === 'ai-title' && typeof event.aiTitle === 'string' && event.aiTitle.trim()) meta.aiTitle = event.aiTitle.trim();
425
+ let time = 0;
426
+ if (event.timestamp) {
427
+ const ms = Date.parse(event.timestamp);
428
+ if (Number.isFinite(ms)) {
429
+ time = ms;
430
+ if (ms > meta.updatedAt) meta.updatedAt = ms;
431
+ }
432
+ }
433
+ if (event.type === 'user') {
434
+ const body = textParts(event.message && event.message.content).trim();
435
+ if (body) {
436
+ if (!meta.firstUser) meta.firstUser = body.slice(0, 200);
437
+ push('u', body, time);
438
+ }
439
+ } else if (event.type === 'assistant') {
440
+ const content = event.message && event.message.content;
441
+ if (!Array.isArray(content)) continue;
442
+ for (const part of content) {
443
+ if (!part) continue;
444
+ if (part.type === 'text' && typeof part.text === 'string' && part.text.trim()) push('a', part.text, time);
445
+ else if (part.type === 'tool_use') {
446
+ let args = '';
447
+ try {
448
+ args = JSON.stringify(part.input);
449
+ } catch {
450
+ args = '';
451
+ }
452
+ push('c', `${part.name || ''} ${args}`.trim(), time);
453
+ }
454
+ }
455
+ }
456
+ }
457
+
458
+ let surface = 'cc';
459
+ let best = 0;
460
+ for (const [entrypoint, count] of entrypoints) {
461
+ if (count <= best) continue;
462
+ best = count;
463
+ surface = entrypoint === 'sdk-cli'
464
+ ? 'cli'
465
+ : entrypoint === 'claude-vscode'
466
+ ? 'vscode'
467
+ : entrypoint === 'sdk-ts'
468
+ ? 'zed'
469
+ : 'cc';
470
+ }
471
+ meta.surface = surface;
472
+ return { meta, messages };
473
+ }
474
+
475
+ const claudeCache = new Map();
476
+ let claudeFingerprint = '';
477
+
478
+ /** Rebuild the Claude Code session list + message digest from changed transcripts. */
479
+ export async function syncClaudeSessions(ctx = {}) {
480
+ const files = listClaudeSessionFiles();
481
+ if (files.length === 0) return false;
482
+ let changed = false;
483
+ const seen = new Set();
484
+ for (const file of files) {
485
+ const sessionId = path.basename(file, '.jsonl');
486
+ seen.add(sessionId);
487
+ let stat;
488
+ try {
489
+ stat = fs.statSync(file);
490
+ } catch {
491
+ continue;
492
+ }
493
+ const cached = claudeCache.get(sessionId);
494
+ if (cached && cached.file === file && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) continue;
495
+ try {
496
+ const extracted = extractClaudeSession(sessionId, fs.readFileSync(file, 'utf8'));
497
+ claudeCache.set(sessionId, { file, mtimeMs: stat.mtimeMs, size: stat.size, meta: extracted.meta, messages: extracted.messages });
498
+ changed = true;
499
+ } catch (error) {
500
+ ctx.logger?.warn?.(`all-sessions: claude session skipped ${sessionId}: ${String(error)}`);
501
+ }
502
+ await new Promise((resolve) => setImmediate(resolve));
503
+ }
504
+ for (const id of [...claudeCache.keys()]) {
505
+ if (!seen.has(id)) {
506
+ claudeCache.delete(id);
507
+ changed = true;
508
+ }
509
+ }
510
+
511
+ // Zed renames live in Zed's DB; they win over Claude's own ai-title.
512
+ const zedTitles = new Map();
513
+ try {
514
+ for (const row of await readZedThreads()) {
515
+ if (!row || row.agent_id !== 'claude-acp') continue;
516
+ const id = row.session_id === null || row.session_id === undefined ? '' : String(row.session_id).trim();
517
+ if (!id) continue;
518
+ const override = typeof row.title_override === 'string' ? row.title_override.trim() : '';
519
+ const title = override || (typeof row.title === 'string' ? row.title.trim() : '');
520
+ if (title) zedTitles.set(id, title);
521
+ }
522
+ } catch {}
523
+
524
+ if (!changed && fs.existsSync(claudeMetaPath()) && fs.existsSync(claudeMessagesPath())) return false;
525
+
526
+ const sessions = [];
527
+ const messages = [];
528
+ for (const [id, entry] of claudeCache) {
529
+ const zedTitle = zedTitles.get(id);
530
+ const title = zedTitle || entry.meta.aiTitle || entry.meta.firstUser || '';
531
+ sessions.push({
532
+ id,
533
+ cwd: entry.meta.cwd,
534
+ title,
535
+ surface: zedTitle ? 'zed' : entry.meta.surface,
536
+ updatedAt: entry.meta.updatedAt || 0,
537
+ messageCount: entry.messages.length,
538
+ });
539
+ messages.push(...entry.messages);
540
+ }
541
+ sessions.sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0));
542
+ messages.sort((a, b) => (a.t || 0) - (b.t || 0));
543
+ const metaJson = JSON.stringify({ version: 1, generatedAt: new Date().toISOString(), cli: resolveClaudeCommand(), sessions });
544
+ const messageJson = JSON.stringify({ version: 1, generatedAt: new Date().toISOString(), messages });
545
+ const fingerprint = createHash('sha1').update(metaJson).update('\u0000').update(messageJson).digest('hex');
546
+ if (fingerprint === claudeFingerprint) return false;
547
+ writeAtomic(claudeMetaPath(), metaJson);
548
+ writeAtomic(claudeMessagesPath(), messageJson);
549
+ claudeFingerprint = fingerprint;
550
+ return true;
551
+ }
552
+
553
+ export function apply(ctx) {
554
+ let stopped = false;
555
+ let lastPayload = '';
556
+
557
+ const tick = async () => {
558
+ if (stopped) return;
559
+ try {
560
+ const rows = await readZedThreads();
561
+ if (rows.length === 0 && !fs.existsSync(zedThreadsDbPath())) return;
562
+ const projection = buildProjection(rows);
563
+ // Detect changes on the thread map alone: the timestamp would otherwise
564
+ // rewrite the file every poll.
565
+ const fingerprint = JSON.stringify(projection.threads);
566
+ if (fingerprint === lastPayload) return;
567
+ const target = projectionPath();
568
+ fs.mkdirSync(path.dirname(target), { recursive: true });
569
+ const temporary = `${target}.${process.pid}.tmp`;
570
+ fs.writeFileSync(temporary, JSON.stringify(projection), 'utf8');
571
+ fs.renameSync(temporary, target);
572
+ lastPayload = fingerprint;
573
+ } catch (error) {
574
+ ctx.logger?.warn?.(`all-sessions: Zed title sync skipped: ${String(error)}`);
575
+ }
576
+ };
577
+
578
+ void tick();
579
+ const timer = setInterval(() => { void tick(); }, POLL_MS);
580
+ timer.unref?.();
581
+
582
+ const digestTick = async () => {
583
+ if (stopped) return;
584
+ try {
585
+ await syncMessageDigest(ctx);
586
+ } catch (error) {
587
+ ctx.logger?.warn?.(`all-sessions: message digest skipped: ${String(error)}`);
588
+ }
589
+ };
590
+ const digestStart = setTimeout(() => { void digestTick(); }, 1500);
591
+ digestStart.unref?.();
592
+ const digestTimer = setInterval(() => { void digestTick(); }, DIGEST_POLL_MS);
593
+ digestTimer.unref?.();
594
+
595
+ const claudeTick = async () => {
596
+ if (stopped) return;
597
+ try {
598
+ await syncClaudeSessions(ctx);
599
+ } catch (error) {
600
+ ctx.logger?.warn?.(`all-sessions: claude digest skipped: ${String(error)}`);
601
+ }
602
+ };
603
+ const claudeStart = setTimeout(() => { void claudeTick(); }, 2500);
604
+ claudeStart.unref?.();
605
+ const claudeTimer = setInterval(() => { void claudeTick(); }, CLAUDE_POLL_MS);
606
+ claudeTimer.unref?.();
607
+
608
+ ctx.effect(() => () => {
609
+ stopped = true;
610
+ clearInterval(timer);
611
+ clearTimeout(digestStart);
612
+ clearInterval(digestTimer);
613
+ clearTimeout(claudeStart);
614
+ clearInterval(claudeTimer);
615
+ }, 'all-sessions: zed thread title sync');
616
+ }
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Zed / Claude Code session workbench",
4
+ "description": "One page for every local DSH session plus Claude Code sessions (CLI / VS Code / Zed ACP): cross-workspace overview, Chinese message-text search, Zed rename sync, in-page terminal resume and confirmed archiving.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Zed / Claude Code 会话工作台",
4
+ "description": "把本机所有 DSH 会话和 Claude Code 会话(CLI / VS Code / Zed ACP)汇总到一个页面:跨工作区总览、中文正文搜索、Zed 改名同步、页内终端恢复与确认后归档。",
5
+ "detail": "docs/DETAIL.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "dsh-zed-cc-workbench",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/handelxh/dsh-zed-cc-workbench.git"
9
+ },
10
+ "homepage": "https://github.com/handelxh/dsh-zed-cc-workbench",
11
+ "bugs": {
12
+ "url": "https://github.com/handelxh/dsh-zed-cc-workbench/issues"
13
+ },
14
+ "description": "Zed / Claude Code 会话工作台:跨工作区会话总览、中文正文搜索、Zed 线程改名同步、Claude Code 会话与页内终端恢复。",
15
+ "keywords": [
16
+ "dsh",
17
+ "deepseek-harness",
18
+ "plugin",
19
+ "sessions",
20
+ "claude-code"
21
+ ],
22
+ "type": "module",
23
+ "exports": {
24
+ ".": "./index.js",
25
+ "./client": "./client.js",
26
+ "./locale/*.json": "./locale/*.json",
27
+ "./icon": "./icon.svg"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "client.js",
32
+ "cordis.patch.yml",
33
+ "locale/*.json",
34
+ "docs",
35
+ "icon.svg",
36
+ "LICENSE",
37
+ "THIRD_PARTY_NOTICES.md"
38
+ ],
39
+ "dsh": {
40
+ "bundle": {
41
+ "patch": "./cordis.patch.yml"
42
+ },
43
+ "client": {
44
+ "platform": "web",
45
+ "immediately": true,
46
+ "inject": [
47
+ "@deepseek-ai/dsh-api-session-controller",
48
+ "@deepseek-ai/dsh-api-workspace-controller",
49
+ "@deepseek-ai/dsh-client-locale",
50
+ "@deepseek-ai/dsh-client-ui-layout",
51
+ "@deepseek-ai/dsh-client-ui-sidebar",
52
+ "@deepseek-ai/dsh-client-ui-workspace"
53
+ ]
54
+ }
55
+ }
56
+ }