dsh-ws-recency 0.12.1 → 0.13.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.
Files changed (4) hide show
  1. package/README.md +3 -2
  2. package/client.js +58 -20
  3. package/index.js +49 -0
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -61,10 +61,11 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
61
61
  5. 把日志目录移动到 `~/.hypers-work/.trash/ws-recency/<sessionId>-<时间戳>/`;
62
62
  6. 广播 `api-session/removed`,浏览器立即移除该行。
63
63
 
64
- **不是物理删除**:目录只是被改名搬走。每个条目在 `.trash/ws-recency/` 下带一份 `.wsr-trash.json`(会话 id、原 cwd、时间、来源),界面里的**回收站**(设置 → 通用 → 回收站 → 打开)会列出它们:
64
+ **不是物理删除**:目录只是被改名搬走。每个条目在 `.trash/ws-recency/` 下带一份 `.wsr-trash.json`(会话 id、原 cwd、时间、来源),界面里的**回收站**(侧栏底部「回收站」按钮)会列出它们:
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.1/dsh-ws-recency-0.12.1.tgz
138
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.13.0/dsh-ws-recency-0.13.0.tgz
138
139
  ```
139
140
 
140
141
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -133,6 +133,9 @@
133
133
  ".wsr-move-path{font-size:11px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
134
134
  ".wsr-move-badge{font-size:11px;color:var(--dsw-alias-label-tertiary)}",
135
135
  ".wsr-trash-row{display:flex;align-items:center;gap:8px;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04))}",
136
+ ".wsr-footer-action{display:inline-flex;align-items:center;gap:6px;border:none;background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;cursor:pointer;padding:4px 8px;border-radius:6px}",
137
+ ".wsr-footer-action:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));color:var(--dsw-alias-label-primary)}",
138
+ ".wsr-footer-label{font-size:12px}",
136
139
  ".wsr-trash-actions{display:flex;gap:6px;flex:none}",
137
140
  ".wsr-danger{border-color:var(--dsw-alias-state-error-primary,#d9534f);color:var(--dsw-alias-state-error-primary,#d9534f)}",
138
141
  ".wsr-chart{display:flex;flex-direction:column;gap:6px}",
@@ -219,11 +222,12 @@
219
222
  "move.repaired": "已补登记到「{workspace}」:上一次移动只搬了日志、没登记工作区,这次把它补上了。",
220
223
  "adopt.title": "补登记游离会话",
221
224
  "adopt.description": "修复会话归属:把“目录属于某工作区却不在任何分组”的会话挂回去,并把仍挂在旧工作区分组里的重复归属清掉。",
222
- "adopt.action": "扫描",
225
+ "adopt.action": "扫描并刷新",
223
226
  "adopt.working": "扫描中…",
224
227
  "adopt.done": "已补登记 {n} 个会话。",
225
228
  "adopt.cleaned": "清理了 {n} 处重复/失效的工作区归属。",
226
229
  "adopt.failed": "扫描失败:",
230
+ "ui.reload": "刷新界面",
227
231
  "trash.title": "回收站",
228
232
  "trash.description": "被删除的会话会移到这里(日志目录),可以恢复,也可以彻底删除。",
229
233
  "trash.open": "打开",
@@ -297,11 +301,12 @@
297
301
  "move.repaired": "Registered in \"{workspace}\": the previous attempt moved the log without the bookkeeping, and this repaired it.",
298
302
  "adopt.title": "Adopt unlisted sessions",
299
303
  "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.",
300
- "adopt.action": "Scan",
304
+ "adopt.action": "Scan and reload",
301
305
  "adopt.working": "Scanning\u2026",
302
306
  "adopt.done": "Re-attached {n} session(s).",
303
307
  "adopt.cleaned": " Cleared {n} stale membership(s).",
304
308
  "adopt.failed": "Scan failed: ",
309
+ "ui.reload": "Reload UI",
305
310
  "trash.title": "Trash",
306
311
  "trash.description": "Deleted sessions land here (their log directory). Restore them, or delete them for good.",
307
312
  "trash.open": "Open",
@@ -1618,6 +1623,22 @@
1618
1623
 
1619
1624
  /* ---------------------------- trash panel ---------------------------- */
1620
1625
 
1626
+ /** A page reload rebuilds the sidebar from disk without restarting the app. */
1627
+ function reloadButton() {
1628
+ var button = document.createElement("button");
1629
+ button.type = "button";
1630
+ button.className = "wsr-step";
1631
+ button.textContent = t("ui.reload");
1632
+ button.addEventListener("click", function () {
1633
+ try {
1634
+ if (typeof window !== "undefined" && window.location !== undefined && typeof window.location.reload === "function") window.location.reload();
1635
+ } catch (error) {
1636
+ /* nothing to do */
1637
+ }
1638
+ });
1639
+ return button;
1640
+ }
1641
+
1621
1642
  function formatBytes(value) {
1622
1643
  var n = Number(value) || 0;
1623
1644
  if (n >= 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + " MB";
@@ -1677,7 +1698,12 @@
1677
1698
  body.textContent = t("trash.loading");
1678
1699
  post({ action: "list" }).then(function (answer) {
1679
1700
  body.textContent = "";
1680
- if (note !== undefined && note !== "") body.appendChild(statsDiv("wsr-stats-detail", note));
1701
+ if (note !== undefined && note !== "") {
1702
+ body.appendChild(statsDiv("wsr-stats-detail", note));
1703
+ var noteActions = statsDiv("wsr-trash-actions");
1704
+ noteActions.appendChild(reloadButton());
1705
+ body.appendChild(noteActions);
1706
+ }
1681
1707
  if (answer.json === null || answer.json.ok !== true) {
1682
1708
  body.appendChild(statsDiv("wsr-stats-note", t("trash.failed") + "HTTP " + answer.status + " \u00b7 " + (answer.text || "").slice(0, 120)));
1683
1709
  return;
@@ -1753,17 +1779,20 @@
1753
1779
  load("");
1754
1780
  }
1755
1781
 
1756
- /** Settings -> General: open the trash panel. */
1757
- function TrashRow() {
1758
- return h("div", { className: "wsr-setRow" },
1759
- h("div", { className: "wsr-setText" },
1760
- h("div", { className: "wsr-setTitle" }, t("trash.title")),
1761
- h("div", { className: "wsr-setDesc" }, t("trash.description")),
1762
- ),
1763
- h("div", { className: "wsr-controls" },
1764
- h("button", { type: "button", className: "wsr-step", onClick: function () { openTrashPanel(); } }, t("trash.open")),
1765
- ),
1766
- );
1782
+ /** Sidebar footer action: the trash, one click away from the account area. */
1783
+ function TrashFooterAction(props) {
1784
+ var wide = props === undefined || props === null || props.wide !== false;
1785
+ var label = t("trash.title");
1786
+ var Icon = ui.IconTrashOutlineRegular;
1787
+ return h("button", {
1788
+ type: "button",
1789
+ className: "wsr-footer-action",
1790
+ title: label,
1791
+ "aria-label": label,
1792
+ onClick: function () { openTrashPanel(); },
1793
+ },
1794
+ typeof Icon === "function" ? h(Icon, {}) : null,
1795
+ wide ? h("span", { className: "wsr-footer-label" }, label) : null);
1767
1796
  }
1768
1797
 
1769
1798
  /** Settings -> General: re-attach sessions that belong to no workspace. */
@@ -1788,6 +1817,16 @@
1788
1817
  var text = t("adopt.done", { n: count });
1789
1818
  if (cleaned > 0) text += t("adopt.cleaned", { n: cleaned });
1790
1819
  setMessage(text);
1820
+ /* The scan is the refresh: reload once it has changed something. */
1821
+ if (count > 0 || cleaned > 0) {
1822
+ window.setTimeout(function () {
1823
+ try {
1824
+ if (window.location !== undefined && typeof window.location.reload === "function") window.location.reload();
1825
+ } catch (error) {
1826
+ /* nothing to do */
1827
+ }
1828
+ }, 900);
1829
+ }
1791
1830
  return;
1792
1831
  }
1793
1832
  setMessage(t("adopt.failed") + (answer.json && answer.json.error ? answer.json.error : answer.text.slice(0, 120)));
@@ -1945,14 +1984,13 @@
1945
1984
  }, ColorsRow);
1946
1985
  });
1947
1986
 
1948
- ctx.slots.inject("settings.general.item", function () {
1987
+ ctx.slots.inject("sidebar.footer.action", function () {
1949
1988
  return ctx.slots.register({
1950
- name: "settings.general.item",
1951
- id: "ws-recency-trash-panel",
1952
- order: 48,
1953
- store: prefs,
1989
+ name: "sidebar.footer.action",
1990
+ id: "ws-recency-trash-footer",
1991
+ order: 30,
1954
1992
  locale: NS,
1955
- }, TrashRow);
1993
+ }, TrashFooterAction);
1956
1994
  });
1957
1995
 
1958
1996
  ctx.slots.inject("settings.general.item", function () {
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;
@@ -866,6 +914,7 @@ export async function restoreTrashEntry(ctx, name) {
866
914
  } catch {
867
915
  /* an empty leftover directory is harmless */
868
916
  }
917
+ await announceSession(ctx, sidecar.sessionId);
869
918
  return { ok: true, sessionId: sidecar.sessionId, cwd: sidecar.cwd, attached };
870
919
  }
871
920
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
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",