dsh-ws-recency 0.11.5 → 0.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/client.js +8 -3
- package/index.js +57 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
56
56
|
|
|
57
57
|
1. 先停掉它正在跑的工作;
|
|
58
58
|
2. 摘掉归档标记与置顶;
|
|
59
|
-
3.
|
|
59
|
+
3. 从每个工作区的记账里 detach(按 `workspace.json` 的原始记录判断,避免过滤视图漏删);
|
|
60
60
|
4. 删掉投影缓存记录;
|
|
61
61
|
5. 把日志目录移动到 `~/.hypers-work/.trash/ws-recency/<sessionId>-<时间戳>/`;
|
|
62
62
|
6. 广播 `api-session/removed`,浏览器立即移除该行。
|
|
@@ -88,7 +88,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
88
88
|
3. 把旧日志目录移进 `.trash/ws-recency/<id>-move-<时间戳>`(既是备份,也腾出这个 id);
|
|
89
89
|
4. 用新 `cwd`、原 id 重建日志,再回放全部事件;
|
|
90
90
|
5. 校验新 header 的 cwd;
|
|
91
|
-
6. 把新 cwd 同步到工作区的 header 索引和这个会话的内存对象(否则宿主会用旧目录拒绝 attach),再 attach
|
|
91
|
+
6. 把新 cwd 同步到工作区的 header 索引和这个会话的内存对象(否则宿主会用旧目录拒绝 attach),再 attach 到目标(失败就回滚原目录),最后**按 workspace.json 的原始记录** detach 旧工作区——工作区自己的 `sessionIds` getter 会按 cwd 过滤,用它判断会漏掉要删的那一条,导致会话同时出现在两个分组;
|
|
92
92
|
7. 删投影缓存,让它按新路径重建。
|
|
93
93
|
|
|
94
94
|
**只移动会话**:对话框里明确提示——它在旧工作区里创建/修改的文件不会跟着走,仍留在原目录(附件与 rewind 快照按会话 id 存,不受影响)。
|
|
@@ -130,7 +130,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
|
|
|
130
130
|
或固定版本的预构建包:
|
|
131
131
|
|
|
132
132
|
```powershell
|
|
133
|
-
dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.11.
|
|
133
|
+
dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.11.7/dsh-ws-recency-0.11.7.tgz
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
|
package/client.js
CHANGED
|
@@ -215,10 +215,11 @@
|
|
|
215
215
|
"move.doneLive": "\n\n这个会话刚才是打开状态:建议重启应用后再继续对话,避免它沿用旧的目录。",
|
|
216
216
|
"move.repaired": "已补登记到「{workspace}」:上一次移动只搬了日志、没登记工作区,这次把它补上了。",
|
|
217
217
|
"adopt.title": "补登记游离会话",
|
|
218
|
-
"adopt.description": "
|
|
218
|
+
"adopt.description": "修复会话归属:把“目录属于某工作区却不在任何分组”的会话挂回去,并把仍挂在旧工作区分组里的重复归属清掉。",
|
|
219
219
|
"adopt.action": "扫描",
|
|
220
220
|
"adopt.working": "扫描中…",
|
|
221
221
|
"adopt.done": "已补登记 {n} 个会话。",
|
|
222
|
+
"adopt.cleaned": "清理了 {n} 处重复/失效的工作区归属。",
|
|
222
223
|
"adopt.failed": "扫描失败:",
|
|
223
224
|
"move.failed": "移动失败:",
|
|
224
225
|
"stats.chart": "消耗分布",
|
|
@@ -276,10 +277,11 @@
|
|
|
276
277
|
"move.doneLive": "\n\nThe session was open: restart the app before continuing it so it does not keep using the old directory.",
|
|
277
278
|
"move.repaired": "Registered in \"{workspace}\": the previous attempt moved the log without the bookkeeping, and this repaired it.",
|
|
278
279
|
"adopt.title": "Adopt unlisted sessions",
|
|
279
|
-
"adopt.description": "
|
|
280
|
+
"adopt.description": "Repairs session membership: re-attaches sessions whose directory belongs to a workspace but are listed nowhere, and clears stale memberships that make one session appear twice.",
|
|
280
281
|
"adopt.action": "Scan",
|
|
281
282
|
"adopt.working": "Scanning\u2026",
|
|
282
283
|
"adopt.done": "Re-attached {n} session(s).",
|
|
284
|
+
"adopt.cleaned": " Cleared {n} stale membership(s).",
|
|
283
285
|
"adopt.failed": "Scan failed: ",
|
|
284
286
|
"move.failed": "Move failed: ",
|
|
285
287
|
"stats.chart": "Where the tokens went",
|
|
@@ -1597,7 +1599,10 @@
|
|
|
1597
1599
|
.then(function (answer) {
|
|
1598
1600
|
if (answer.json !== null && answer.json.ok === true) {
|
|
1599
1601
|
var count = Array.isArray(answer.json.adopted) ? answer.json.adopted.length : 0;
|
|
1600
|
-
|
|
1602
|
+
var cleaned = typeof answer.json.cleaned === "number" ? answer.json.cleaned : 0;
|
|
1603
|
+
var text = t("adopt.done", { n: count });
|
|
1604
|
+
if (cleaned > 0) text += t("adopt.cleaned", { n: cleaned });
|
|
1605
|
+
setMessage(text);
|
|
1601
1606
|
return;
|
|
1602
1607
|
}
|
|
1603
1608
|
setMessage(t("adopt.failed") + (answer.json && answer.json.error ? answer.json.error : answer.text.slice(0, 120)));
|
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @module dsh-ws-recency
|
|
21
21
|
*/
|
|
22
|
-
import { mkdir, readdir, rename, rm, stat as statPath } from "node:fs/promises";
|
|
22
|
+
import { mkdir, readFile, readdir, rename, rm, stat as statPath } from "node:fs/promises";
|
|
23
23
|
import { dirname, join } from "node:path";
|
|
24
24
|
|
|
25
25
|
/** Cordis plugin name shown by the loader. */
|
|
@@ -178,8 +178,15 @@ export async function trashSession(ctx, sessionId) {
|
|
|
178
178
|
try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* not archived */ }
|
|
179
179
|
try { await ctx.workspaceRegistry.unpinSession(sessionId); } catch { /* not pinned */ }
|
|
180
180
|
|
|
181
|
+
/* Same filtered-view trap as the move: the workspace's own sessionIds may
|
|
182
|
+
already hide the id while the stored record still lists it. */
|
|
183
|
+
const rawMembers = await rawWorkspaceMembership();
|
|
181
184
|
for (const workspace of ctx.workspaceRegistry.list()) {
|
|
182
|
-
|
|
185
|
+
const record = rawMembers === null ? undefined : rawMembers.get(workspace.id);
|
|
186
|
+
const listed = record !== undefined
|
|
187
|
+
? record.sessionIds.includes(sessionId)
|
|
188
|
+
: Array.isArray(workspace.sessionIds) && workspace.sessionIds.includes(sessionId);
|
|
189
|
+
if (!listed) continue;
|
|
183
190
|
try { await workspace.detachSession(sessionId); } catch { /* keep going */ }
|
|
184
191
|
}
|
|
185
192
|
|
|
@@ -440,6 +447,24 @@ export async function sessionStatistics(ctx, sessionId) {
|
|
|
440
447
|
}
|
|
441
448
|
}
|
|
442
449
|
|
|
450
|
+
/** Which workspaces list a session in the stored table (the registry view is filtered). */
|
|
451
|
+
async function rawWorkspaceMembership() {
|
|
452
|
+
try {
|
|
453
|
+
const home = await dshHome();
|
|
454
|
+
const raw = JSON.parse(await readFile(join(home, "storages", "workspace.json"), "utf8"));
|
|
455
|
+
const table = raw !== null && raw.tables !== undefined && raw.tables !== null ? raw.tables.workspaces : undefined;
|
|
456
|
+
if (table === undefined || table === null || typeof table !== "object") return null;
|
|
457
|
+
const map = new Map();
|
|
458
|
+
for (const [id, record] of Object.entries(table)) {
|
|
459
|
+
const ids = record !== null && Array.isArray(record.sessionIds) ? record.sessionIds : [];
|
|
460
|
+
map.set(id, { path: typeof record.path === "string" ? record.path : "", sessionIds: ids });
|
|
461
|
+
}
|
|
462
|
+
return map;
|
|
463
|
+
} catch {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
443
468
|
/**
|
|
444
469
|
* Move one session into another workspace.
|
|
445
470
|
*
|
|
@@ -619,10 +644,15 @@ export async function moveSessionToWorkspace(ctx, sessionId, workspaceId) {
|
|
|
619
644
|
return { ok: false, error: `the workspace refused the attach: ${error instanceof Error ? error.message : String(error)}` };
|
|
620
645
|
}
|
|
621
646
|
|
|
647
|
+
/* Detach by the RAW record, not the filtered view: once the header carries the
|
|
648
|
+
new cwd, the old workspace's own `sessionIds` getter already hides the id, so
|
|
649
|
+
an "is it listed?" check would skip exactly the membership that has to go. */
|
|
622
650
|
const detached = [];
|
|
651
|
+
const raw = await rawWorkspaceMembership();
|
|
623
652
|
for (const workspace of workspaces) {
|
|
624
|
-
if (!Array.isArray(workspace.sessionIds) || !workspace.sessionIds.includes(sessionId)) continue;
|
|
625
653
|
if (workspace.id === target.id) continue;
|
|
654
|
+
const record = raw === null ? undefined : raw.get(workspace.id);
|
|
655
|
+
if (record !== undefined && !record.sessionIds.includes(sessionId)) continue;
|
|
626
656
|
try {
|
|
627
657
|
await workspace.detachSession(sessionId);
|
|
628
658
|
detached.push(workspace.id);
|
|
@@ -653,13 +683,34 @@ export async function adoptOrphanSessions(ctx) {
|
|
|
653
683
|
const byPath = new Map();
|
|
654
684
|
for (const workspace of workspaces) byPath.set(workspace.path, workspace);
|
|
655
685
|
const adopted = [];
|
|
686
|
+
const raw = await rawWorkspaceMembership();
|
|
687
|
+
let cleaned = 0;
|
|
656
688
|
for (const snapshot of snapshots) {
|
|
657
689
|
const header = snapshot !== null && snapshot !== undefined ? snapshot.header : undefined;
|
|
658
690
|
if (header === undefined || header === null || typeof header.cwd !== "string" || typeof header.id !== "string") continue;
|
|
659
691
|
const target = byPath.get(header.cwd);
|
|
692
|
+
/* Stale memberships first: a workspace whose path is not this session's cwd
|
|
693
|
+
must not keep listing it - that is what puts one session in two groups. */
|
|
694
|
+
if (raw !== null) {
|
|
695
|
+
for (const workspace of workspaces) {
|
|
696
|
+
if (target !== undefined && workspace.id === target.id) continue;
|
|
697
|
+
const record = raw.get(workspace.id);
|
|
698
|
+
if (record === undefined || !record.sessionIds.includes(header.id)) continue;
|
|
699
|
+
try {
|
|
700
|
+
await workspace.detachSession(header.id);
|
|
701
|
+
cleaned += 1;
|
|
702
|
+
} catch {
|
|
703
|
+
/* leave it */
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
660
707
|
if (target === undefined) continue;
|
|
661
|
-
const
|
|
662
|
-
|
|
708
|
+
const record = raw === null ? undefined : raw.get(target.id);
|
|
709
|
+
/* Without the raw table, fall back to the registry's own (filtered) view. */
|
|
710
|
+
const physically = record !== undefined
|
|
711
|
+
? record.sessionIds.includes(header.id)
|
|
712
|
+
: Array.isArray(target.sessionIds) && target.sessionIds.includes(header.id);
|
|
713
|
+
if (physically) continue;
|
|
663
714
|
try {
|
|
664
715
|
await target.attachSession(header.id);
|
|
665
716
|
adopted.push(header.id);
|
|
@@ -667,7 +718,7 @@ export async function adoptOrphanSessions(ctx) {
|
|
|
667
718
|
/* the registry refused it; leave it alone */
|
|
668
719
|
}
|
|
669
720
|
}
|
|
670
|
-
return { ok: true, adopted };
|
|
721
|
+
return { ok: true, adopted, cleaned };
|
|
671
722
|
}
|
|
672
723
|
|
|
673
724
|
/** POST {} -> attach every session that belongs nowhere. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.7",
|
|
4
4
|
"description": "Sidebar session management for DeepSeek Harness: workspace groups sorted by latest activity, stale history folded, a global pinned section, follow-up marks, session delete into a recoverable trash, per-session token statistics split by tool, and moving a session to another workspace.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chyxhtc",
|