dsh-ws-recency 0.12.0 → 0.12.2

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
@@ -65,6 +65,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
65
65
 
66
66
  - 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,并重新挂到对应工作区;
67
67
  - 「彻底删除」:真正删掉这份日志(二次确认);
68
+ - 恢复/扫描/移动之后宿主会广播 `api-session/added`,面板里还提供一个「刷新界面」按钮(重载页面,不重启应用),让侧栏立刻看到改动;
68
69
  - 移动操作留下的旧副本会标成「移动时的旧副本」,只允许彻底删除。
69
70
 
70
71
  ## 六、Token 消耗统计
@@ -134,7 +135,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
134
135
  或固定版本的预构建包:
135
136
 
136
137
  ```powershell
137
- dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.12.0/dsh-ws-recency-0.12.0.tgz
138
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.12.2/dsh-ws-recency-0.12.2.tgz
138
139
  ```
139
140
 
140
141
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -224,6 +224,7 @@
224
224
  "adopt.done": "已补登记 {n} 个会话。",
225
225
  "adopt.cleaned": "清理了 {n} 处重复/失效的工作区归属。",
226
226
  "adopt.failed": "扫描失败:",
227
+ "ui.reload": "刷新界面",
227
228
  "trash.title": "回收站",
228
229
  "trash.description": "被删除的会话会移到这里(日志目录),可以恢复,也可以彻底删除。",
229
230
  "trash.open": "打开",
@@ -235,7 +236,7 @@
235
236
  "trash.purge": "彻底删除",
236
237
  "trash.confirmRestore": "恢复到原来的工作区?",
237
238
  "trash.confirmPurge": "彻底删除这份日志?不可恢复。",
238
- "trash.restored": "已恢复,并重新挂回原工作区。",
239
+ "trash.restored": "已恢复,并重新挂回原工作区。若侧栏还没出现,去「补登记游离会话」点一下扫描(或重启应用)刷新列表。",
239
240
  "trash.purged": "已彻底删除。",
240
241
  "trash.working": "处理中…",
241
242
  "trash.failed": "操作失败:",
@@ -302,6 +303,7 @@
302
303
  "adopt.done": "Re-attached {n} session(s).",
303
304
  "adopt.cleaned": " Cleared {n} stale membership(s).",
304
305
  "adopt.failed": "Scan failed: ",
306
+ "ui.reload": "Reload UI",
305
307
  "trash.title": "Trash",
306
308
  "trash.description": "Deleted sessions land here (their log directory). Restore them, or delete them for good.",
307
309
  "trash.open": "Open",
@@ -313,7 +315,7 @@
313
315
  "trash.purge": "Delete for good",
314
316
  "trash.confirmRestore": "Restore it to its original workspace?",
315
317
  "trash.confirmPurge": "Delete this log for good? This cannot be undone.",
316
- "trash.restored": "Restored and re-attached to its workspace.",
318
+ "trash.restored": "Restored and re-attached to its workspace. If the sidebar has not picked it up, run the \"Adopt unlisted sessions\" scan (or restart the app).",
317
319
  "trash.purged": "Deleted for good.",
318
320
  "trash.working": "Working\u2026",
319
321
  "trash.failed": "Action failed: ",
@@ -1618,6 +1620,22 @@
1618
1620
 
1619
1621
  /* ---------------------------- trash panel ---------------------------- */
1620
1622
 
1623
+ /** A page reload rebuilds the sidebar from disk without restarting the app. */
1624
+ function reloadButton() {
1625
+ var button = document.createElement("button");
1626
+ button.type = "button";
1627
+ button.className = "wsr-step";
1628
+ button.textContent = t("ui.reload");
1629
+ button.addEventListener("click", function () {
1630
+ try {
1631
+ if (typeof window !== "undefined" && window.location !== undefined && typeof window.location.reload === "function") window.location.reload();
1632
+ } catch (error) {
1633
+ /* nothing to do */
1634
+ }
1635
+ });
1636
+ return button;
1637
+ }
1638
+
1621
1639
  function formatBytes(value) {
1622
1640
  var n = Number(value) || 0;
1623
1641
  if (n >= 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + " MB";
@@ -1677,7 +1695,12 @@
1677
1695
  body.textContent = t("trash.loading");
1678
1696
  post({ action: "list" }).then(function (answer) {
1679
1697
  body.textContent = "";
1680
- if (note !== undefined && note !== "") body.appendChild(statsDiv("wsr-stats-detail", note));
1698
+ if (note !== undefined && note !== "") {
1699
+ body.appendChild(statsDiv("wsr-stats-detail", note));
1700
+ var noteActions = statsDiv("wsr-trash-actions");
1701
+ noteActions.appendChild(reloadButton());
1702
+ body.appendChild(noteActions);
1703
+ }
1681
1704
  if (answer.json === null || answer.json.ok !== true) {
1682
1705
  body.appendChild(statsDiv("wsr-stats-note", t("trash.failed") + "HTTP " + answer.status + " \u00b7 " + (answer.text || "").slice(0, 120)));
1683
1706
  return;
@@ -1803,6 +1826,7 @@
1803
1826
  ),
1804
1827
  h("div", { className: "wsr-controls" },
1805
1828
  h("button", { type: "button", className: "wsr-step", onClick: run }, t("adopt.action")),
1829
+ h("button", { type: "button", className: "wsr-step", onClick: function () { reloadButton().click(); } }, t("ui.reload")),
1806
1830
  ),
1807
1831
  );
1808
1832
  }
package/index.js CHANGED
@@ -676,6 +676,7 @@ export async function moveSessionToWorkspace(ctx, sessionId, workspaceId) {
676
676
  /* the cache is derived data */
677
677
  }
678
678
 
679
+ await announceSession(ctx, sessionId);
679
680
  return { ok: true, workspace: target.id, path: targetPath, detached, backup, live: wasLive };
680
681
  }
681
682
 
@@ -721,6 +722,7 @@ export async function adoptOrphanSessions(ctx) {
721
722
  try {
722
723
  await target.attachSession(header.id);
723
724
  adopted.push(header.id);
725
+ await announceSession(ctx, header.id);
724
726
  } catch {
725
727
  /* the registry refused it; leave it alone */
726
728
  }
@@ -728,6 +730,52 @@ export async function adoptOrphanSessions(ctx) {
728
730
  return { ok: true, adopted, cleaned };
729
731
  }
730
732
 
733
+ /**
734
+ * Tell the browser about a Session it does not know yet.
735
+ *
736
+ * A restored session exists on disk but not in the running Host's client-side
737
+ * list, so a sidebar that was loaded before the restore has no row to show. The
738
+ * session list is kept in sync by `api-session/added`; announce the summary the
739
+ * session controller itself would produce, or a minimal one built from the
740
+ * stored header when that service is not injected here.
741
+ */
742
+ export async function announceSession(ctx, sessionId) {
743
+ try {
744
+ const controller = ctx.get("sessionController");
745
+ if (controller !== undefined && controller !== null && typeof controller.list === "function") {
746
+ const items = await controller.list();
747
+ const summary = Array.isArray(items) ? items.find((item) => item !== null && item !== undefined && item.sessionId === sessionId) : undefined;
748
+ if (summary !== undefined) {
749
+ ctx.emit("api-session/added", summary);
750
+ return true;
751
+ }
752
+ }
753
+ } catch {
754
+ /* fall through to the header-built summary */
755
+ }
756
+ try {
757
+ const stat = await ctx.sessionPersistence.stat(sessionId);
758
+ const header = stat !== undefined && stat !== null ? stat.header : undefined;
759
+ if (header !== undefined && header !== null) {
760
+ ctx.emit("api-session/added", {
761
+ sessionId: header.id,
762
+ updatedAt: typeof header.updatedAt === "number" ? header.updatedAt : Date.now(),
763
+ agentAvailable: false,
764
+ formatStatus: "current",
765
+ running: false,
766
+ blank: false,
767
+ title: header.title,
768
+ cwd: header.cwd,
769
+ createdAt: header.createdAt,
770
+ });
771
+ return true;
772
+ }
773
+ } catch {
774
+ /* nothing to announce */
775
+ }
776
+ return false;
777
+ }
778
+
731
779
  /** The session root's project-directory key: separators collapse to `-`. */
732
780
  export function projectKey(cwd) {
733
781
  if (typeof cwd !== "string" || cwd === "") return undefined;
@@ -846,11 +894,27 @@ export async function restoreTrashEntry(ctx, name) {
846
894
  /* an old header may be refused; the files are back either way */
847
895
  }
848
896
  }
897
+ /* A restore must not resurrect the stale membership the delete left behind. */
898
+ const raw = await rawWorkspaceMembership();
899
+ for (const workspace of workspaces) {
900
+ if (owner !== undefined && workspace.id === owner.id) continue;
901
+ const record = raw === null ? undefined : raw.get(workspace.id);
902
+ const listed = record !== undefined
903
+ ? record.sessionIds.includes(sidecar.sessionId)
904
+ : Array.isArray(workspace.sessionIds) && workspace.sessionIds.includes(sidecar.sessionId);
905
+ if (!listed) continue;
906
+ try {
907
+ await workspace.detachSession(sidecar.sessionId);
908
+ } catch {
909
+ /* leave it; the scan can clean it later */
910
+ }
911
+ }
849
912
  try {
850
913
  await rm(directory, { recursive: true, force: true });
851
914
  } catch {
852
915
  /* an empty leftover directory is harmless */
853
916
  }
917
+ await announceSession(ctx, sidecar.sessionId);
854
918
  return { ok: true, sessionId: sidecar.sessionId, cwd: sidecar.cwd, attached };
855
919
  }
856
920
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
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",