dsh-ws-recency 0.11.5 → 0.11.6

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 CHANGED
@@ -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 到目标(失败就回滚原目录),最后 detach 旧工作区;
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.5/dsh-ws-recency-0.11.5.tgz
133
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.11.6/dsh-ws-recency-0.11.6.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": "A session whose directory already belongs to a workspace can end up listed nowhere (an interrupted move leaves exactly this). Scan to re-attach them.",
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
- setMessage(t("adopt.done", { n: count }));
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. */
@@ -440,6 +440,24 @@ export async function sessionStatistics(ctx, sessionId) {
440
440
  }
441
441
  }
442
442
 
443
+ /** Which workspaces list a session in the stored table (the registry view is filtered). */
444
+ async function rawWorkspaceMembership() {
445
+ try {
446
+ const home = await dshHome();
447
+ const raw = JSON.parse(await readFile(join(home, "storages", "workspace.json"), "utf8"));
448
+ const table = raw !== null && raw.tables !== undefined && raw.tables !== null ? raw.tables.workspaces : undefined;
449
+ if (table === undefined || table === null || typeof table !== "object") return null;
450
+ const map = new Map();
451
+ for (const [id, record] of Object.entries(table)) {
452
+ const ids = record !== null && Array.isArray(record.sessionIds) ? record.sessionIds : [];
453
+ map.set(id, { path: typeof record.path === "string" ? record.path : "", sessionIds: ids });
454
+ }
455
+ return map;
456
+ } catch {
457
+ return null;
458
+ }
459
+ }
460
+
443
461
  /**
444
462
  * Move one session into another workspace.
445
463
  *
@@ -619,10 +637,15 @@ export async function moveSessionToWorkspace(ctx, sessionId, workspaceId) {
619
637
  return { ok: false, error: `the workspace refused the attach: ${error instanceof Error ? error.message : String(error)}` };
620
638
  }
621
639
 
640
+ /* Detach by the RAW record, not the filtered view: once the header carries the
641
+ new cwd, the old workspace's own `sessionIds` getter already hides the id, so
642
+ an "is it listed?" check would skip exactly the membership that has to go. */
622
643
  const detached = [];
644
+ const raw = await rawWorkspaceMembership();
623
645
  for (const workspace of workspaces) {
624
- if (!Array.isArray(workspace.sessionIds) || !workspace.sessionIds.includes(sessionId)) continue;
625
646
  if (workspace.id === target.id) continue;
647
+ const record = raw === null ? undefined : raw.get(workspace.id);
648
+ if (record !== undefined && !record.sessionIds.includes(sessionId)) continue;
626
649
  try {
627
650
  await workspace.detachSession(sessionId);
628
651
  detached.push(workspace.id);
@@ -653,13 +676,34 @@ export async function adoptOrphanSessions(ctx) {
653
676
  const byPath = new Map();
654
677
  for (const workspace of workspaces) byPath.set(workspace.path, workspace);
655
678
  const adopted = [];
679
+ const raw = await rawWorkspaceMembership();
680
+ let cleaned = 0;
656
681
  for (const snapshot of snapshots) {
657
682
  const header = snapshot !== null && snapshot !== undefined ? snapshot.header : undefined;
658
683
  if (header === undefined || header === null || typeof header.cwd !== "string" || typeof header.id !== "string") continue;
659
684
  const target = byPath.get(header.cwd);
685
+ /* Stale memberships first: a workspace whose path is not this session's cwd
686
+ must not keep listing it - that is what puts one session in two groups. */
687
+ if (raw !== null) {
688
+ for (const workspace of workspaces) {
689
+ if (target !== undefined && workspace.id === target.id) continue;
690
+ const record = raw.get(workspace.id);
691
+ if (record === undefined || !record.sessionIds.includes(header.id)) continue;
692
+ try {
693
+ await workspace.detachSession(header.id);
694
+ cleaned += 1;
695
+ } catch {
696
+ /* leave it */
697
+ }
698
+ }
699
+ }
660
700
  if (target === undefined) continue;
661
- const listed = workspaces.some((workspace) => Array.isArray(workspace.sessionIds) && workspace.sessionIds.includes(header.id));
662
- if (listed) continue;
701
+ const record = raw === null ? undefined : raw.get(target.id);
702
+ /* Without the raw table, fall back to the registry's own (filtered) view. */
703
+ const physically = record !== undefined
704
+ ? record.sessionIds.includes(header.id)
705
+ : Array.isArray(target.sessionIds) && target.sessionIds.includes(header.id);
706
+ if (physically) continue;
663
707
  try {
664
708
  await target.attachSession(header.id);
665
709
  adopted.push(header.id);
@@ -667,7 +711,7 @@ export async function adoptOrphanSessions(ctx) {
667
711
  /* the registry refused it; leave it alone */
668
712
  }
669
713
  }
670
- return { ok: true, adopted };
714
+ return { ok: true, adopted, cleaned };
671
715
  }
672
716
 
673
717
  /** 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.5",
3
+ "version": "0.11.6",
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",