dsh-ws-recency 0.11.6 → 0.12.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 +7 -3
  2. package/client.js +195 -0
  3. package/index.js +194 -2
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -56,12 +56,16 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
56
56
 
57
57
  1. 先停掉它正在跑的工作;
58
58
  2. 摘掉归档标记与置顶;
59
- 3. 从每个工作区的 `sessionIds` 记账里 detach;
59
+ 3. 从每个工作区的记账里 detach(按 `workspace.json` 的原始记录判断,避免过滤视图漏删);
60
60
  4. 删掉投影缓存记录;
61
61
  5. 把日志目录移动到 `~/.hypers-work/.trash/ws-recency/<sessionId>-<时间戳>/`;
62
62
  6. 广播 `api-session/removed`,浏览器立即移除该行。
63
63
 
64
- **不是物理删除**:目录只是被改名搬走,恢复就是把 `.trash/ws-recency/<id>-<时间>/` 移回 `sessions/<project>/<id>/`。这条删除走的是宿主侧路由(`POST /ws-recency/session-trash`,仅接受回环来源),因为浏览器侧碰不到文件系统。
64
+ **不是物理删除**:目录只是被改名搬走。每个条目在 `.trash/ws-recency/` 下带一份 `.wsr-trash.json`(会话 id、原 cwd、时间、来源),界面里的**回收站**(设置 → 通用 → 回收站 → 打开)会列出它们:
65
+
66
+ - 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,并重新挂到对应工作区;
67
+ - 「彻底删除」:真正删掉这份日志(二次确认);
68
+ - 移动操作留下的旧副本会标成「移动时的旧副本」,只允许彻底删除。
65
69
 
66
70
  ## 六、Token 消耗统计
67
71
 
@@ -130,7 +134,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
130
134
  或固定版本的预构建包:
131
135
 
132
136
  ```powershell
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
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
134
138
  ```
135
139
 
136
140
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -132,6 +132,9 @@
132
132
  ".wsr-move-title{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
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
+ ".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-trash-actions{display:flex;gap:6px;flex:none}",
137
+ ".wsr-danger{border-color:var(--dsw-alias-state-error-primary,#d9534f);color:var(--dsw-alias-state-error-primary,#d9534f)}",
135
138
  ".wsr-chart{display:flex;flex-direction:column;gap:6px}",
136
139
  ".wsr-chart-title{font-size:11px;color:var(--dsw-alias-label-tertiary)}",
137
140
  ".wsr-chart-row{display:grid;grid-template-columns:120px 1fr 64px 56px;align-items:center;gap:8px}",
@@ -221,6 +224,22 @@
221
224
  "adopt.done": "已补登记 {n} 个会话。",
222
225
  "adopt.cleaned": "清理了 {n} 处重复/失效的工作区归属。",
223
226
  "adopt.failed": "扫描失败:",
227
+ "trash.title": "回收站",
228
+ "trash.description": "被删除的会话会移到这里(日志目录),可以恢复,也可以彻底删除。",
229
+ "trash.open": "打开",
230
+ "trash.loading": "读取中…",
231
+ "trash.empty": "回收站是空的。",
232
+ "trash.reason.delete": "已删除",
233
+ "trash.reason.move": "移动时的旧副本",
234
+ "trash.restore": "恢复",
235
+ "trash.purge": "彻底删除",
236
+ "trash.confirmRestore": "恢复到原来的工作区?",
237
+ "trash.confirmPurge": "彻底删除这份日志?不可恢复。",
238
+ "trash.restored": "已恢复,并重新挂回原工作区。",
239
+ "trash.purged": "已彻底删除。",
240
+ "trash.working": "处理中…",
241
+ "trash.failed": "操作失败:",
242
+ "trash.note": "回收站里的都是完整日志目录;恢复会按记录的 cwd 放回 sessions/<项目> 并重新挂到对应工作区。",
224
243
  "move.failed": "移动失败:",
225
244
  "stats.chart": "消耗分布",
226
245
  "stats.details.show": "显示明细 ▾",
@@ -283,6 +302,22 @@
283
302
  "adopt.done": "Re-attached {n} session(s).",
284
303
  "adopt.cleaned": " Cleared {n} stale membership(s).",
285
304
  "adopt.failed": "Scan failed: ",
305
+ "trash.title": "Trash",
306
+ "trash.description": "Deleted sessions land here (their log directory). Restore them, or delete them for good.",
307
+ "trash.open": "Open",
308
+ "trash.loading": "Loading\u2026",
309
+ "trash.empty": "The trash is empty.",
310
+ "trash.reason.delete": "deleted",
311
+ "trash.reason.move": "old copy from a move",
312
+ "trash.restore": "Restore",
313
+ "trash.purge": "Delete for good",
314
+ "trash.confirmRestore": "Restore it to its original workspace?",
315
+ "trash.confirmPurge": "Delete this log for good? This cannot be undone.",
316
+ "trash.restored": "Restored and re-attached to its workspace.",
317
+ "trash.purged": "Deleted for good.",
318
+ "trash.working": "Working\u2026",
319
+ "trash.failed": "Action failed: ",
320
+ "trash.note": "Every entry is a complete log directory; restoring puts it back under sessions/<project> using the recorded cwd and re-attaches it.",
286
321
  "move.failed": "Move failed: ",
287
322
  "stats.chart": "Where the tokens went",
288
323
  "stats.details.show": "Show details",
@@ -1581,6 +1616,156 @@
1581
1616
  );
1582
1617
  }
1583
1618
 
1619
+ /* ---------------------------- trash panel ---------------------------- */
1620
+
1621
+ function formatBytes(value) {
1622
+ var n = Number(value) || 0;
1623
+ if (n >= 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + " MB";
1624
+ if (n >= 1024) return (n / 1024).toFixed(0) + " KB";
1625
+ return n + " B";
1626
+ }
1627
+
1628
+ function formatWhen(at) {
1629
+ if (typeof at !== "number" || at <= 0) return "";
1630
+ try {
1631
+ return new Date(at).toLocaleString();
1632
+ } catch (error) {
1633
+ return "";
1634
+ }
1635
+ }
1636
+
1637
+ /** Modal: list the plugin's trash, restore an entry or delete it for good. */
1638
+ function openTrashPanel() {
1639
+ if (typeof document === "undefined") return;
1640
+ closeStatsPanel();
1641
+ var backdrop = statsDiv("wsr-modal-backdrop");
1642
+ var panel = statsDiv("wsr-modal");
1643
+ backdrop.appendChild(panel);
1644
+ var head = statsDiv("wsr-modal-head");
1645
+ head.appendChild(statsDiv("wsr-modal-title", t("trash.title")));
1646
+ var close = document.createElement("button");
1647
+ close.type = "button";
1648
+ close.className = "wsr-modal-close";
1649
+ close.textContent = "\u00d7";
1650
+ close.addEventListener("click", closeStatsPanel);
1651
+ head.appendChild(close);
1652
+ panel.appendChild(head);
1653
+ var body = statsDiv("wsr-modal-body");
1654
+ panel.appendChild(body);
1655
+ backdrop.addEventListener("click", function (event) {
1656
+ if (event !== undefined && event.target === backdrop) closeStatsPanel();
1657
+ });
1658
+ document.body.appendChild(backdrop);
1659
+ statsModal = backdrop;
1660
+ document.addEventListener("keydown", onStatsKey);
1661
+
1662
+ var post = function (payload) {
1663
+ return fetch("/ws-recency/trash", {
1664
+ method: "POST",
1665
+ headers: { "content-type": "application/json" },
1666
+ body: JSON.stringify(payload),
1667
+ }).then(function (response) {
1668
+ return response.text().then(function (text) {
1669
+ var parsed = null;
1670
+ try { parsed = JSON.parse(text); } catch (error) { parsed = null; }
1671
+ return { status: response.status, text: text, json: parsed };
1672
+ });
1673
+ });
1674
+ };
1675
+
1676
+ var load = function (note) {
1677
+ body.textContent = t("trash.loading");
1678
+ post({ action: "list" }).then(function (answer) {
1679
+ body.textContent = "";
1680
+ if (note !== undefined && note !== "") body.appendChild(statsDiv("wsr-stats-detail", note));
1681
+ if (answer.json === null || answer.json.ok !== true) {
1682
+ body.appendChild(statsDiv("wsr-stats-note", t("trash.failed") + "HTTP " + answer.status + " \u00b7 " + (answer.text || "").slice(0, 120)));
1683
+ return;
1684
+ }
1685
+ var entries = Array.isArray(answer.json.entries) ? answer.json.entries : [];
1686
+ if (entries.length === 0) {
1687
+ body.appendChild(statsDiv("wsr-stats-note", t("trash.empty")));
1688
+ return;
1689
+ }
1690
+ var list = statsDiv("wsr-move-list");
1691
+ for (var i = 0; i < entries.length; i += 1) {
1692
+ (function (entry) {
1693
+ var row = document.createElement("div");
1694
+ row.className = "wsr-trash-row";
1695
+ var text = statsDiv("wsr-move-text");
1696
+ var title = entry.sessionId === null ? entry.name : entry.sessionId;
1697
+ text.appendChild(statsDiv("wsr-move-title", title));
1698
+ var meta = [];
1699
+ if (entry.reason === "delete") meta.push(t("trash.reason.delete"));
1700
+ else if (entry.reason === "move") meta.push(t("trash.reason.move"));
1701
+ meta.push(formatBytes(entry.sizeBytes));
1702
+ var when = formatWhen(entry.at);
1703
+ if (when !== "") meta.push(when);
1704
+ text.appendChild(statsDiv("wsr-move-path", meta.join(" \u00b7 ")));
1705
+ if (typeof entry.cwd === "string" && entry.cwd !== "") {
1706
+ text.appendChild(statsDiv("wsr-move-path", entry.cwd));
1707
+ }
1708
+ row.appendChild(text);
1709
+
1710
+ var actions = statsDiv("wsr-trash-actions");
1711
+ if (entry.restorable === true) {
1712
+ var restore = document.createElement("button");
1713
+ restore.type = "button";
1714
+ restore.className = "wsr-step";
1715
+ restore.textContent = t("trash.restore");
1716
+ restore.addEventListener("click", function () {
1717
+ if (typeof window.confirm === "function" && !window.confirm(t("trash.confirmRestore"))) return;
1718
+ load(t("trash.working"));
1719
+ post({ action: "restore", name: entry.name }).then(function (result) {
1720
+ var ok = result.json !== null && result.json.ok === true;
1721
+ load(ok ? t("trash.restored") : t("trash.failed") + (result.json && result.json.error ? result.json.error : result.text));
1722
+ }).catch(function (error) {
1723
+ load(t("trash.failed") + (error && error.message ? error.message : error));
1724
+ });
1725
+ });
1726
+ actions.appendChild(restore);
1727
+ }
1728
+ var purge = document.createElement("button");
1729
+ purge.type = "button";
1730
+ purge.className = "wsr-step wsr-danger";
1731
+ purge.textContent = t("trash.purge");
1732
+ purge.addEventListener("click", function () {
1733
+ if (typeof window.confirm === "function" && !window.confirm(t("trash.confirmPurge"))) return;
1734
+ load(t("trash.working"));
1735
+ post({ action: "purge", name: entry.name }).then(function (result) {
1736
+ var ok = result.json !== null && result.json.ok === true;
1737
+ load(ok ? t("trash.purged") : t("trash.failed") + (result.json && result.json.error ? result.json.error : result.text));
1738
+ }).catch(function (error) {
1739
+ load(t("trash.failed") + (error && error.message ? error.message : error));
1740
+ });
1741
+ });
1742
+ actions.appendChild(purge);
1743
+ row.appendChild(actions);
1744
+ list.appendChild(row);
1745
+ })(entries[i]);
1746
+ }
1747
+ body.appendChild(list);
1748
+ body.appendChild(statsDiv("wsr-stats-note", t("trash.note")));
1749
+ }).catch(function (error) {
1750
+ body.textContent = t("trash.failed") + (error && error.message ? error.message : error);
1751
+ });
1752
+ };
1753
+ load("");
1754
+ }
1755
+
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
+ );
1767
+ }
1768
+
1584
1769
  /** Settings -> General: re-attach sessions that belong to no workspace. */
1585
1770
  function AdoptRow() {
1586
1771
  var result = react.useState("");
@@ -1760,6 +1945,16 @@
1760
1945
  }, ColorsRow);
1761
1946
  });
1762
1947
 
1948
+ ctx.slots.inject("settings.general.item", function () {
1949
+ return ctx.slots.register({
1950
+ name: "settings.general.item",
1951
+ id: "ws-recency-trash-panel",
1952
+ order: 48,
1953
+ store: prefs,
1954
+ locale: NS,
1955
+ }, TrashRow);
1956
+ });
1957
+
1763
1958
  ctx.slots.inject("settings.general.item", function () {
1764
1959
  return ctx.slots.register({
1765
1960
  name: "settings.general.item",
package/index.js CHANGED
@@ -19,7 +19,7 @@
19
19
  *
20
20
  * @module dsh-ws-recency
21
21
  */
22
- import { mkdir, readFile, readdir, rename, rm, stat as statPath } from "node:fs/promises";
22
+ import { mkdir, readFile, readdir, rename, rm, stat as statPath, writeFile } from "node:fs/promises";
23
23
  import { dirname, join } from "node:path";
24
24
 
25
25
  /** Cordis plugin name shown by the loader. */
@@ -37,6 +37,9 @@ export const STATS_SESSION_PATH = "/ws-recency/session-stats";
37
37
  export const HEALTH_PATH = "/ws-recency/health";
38
38
  export const MOVE_SESSION_PATH = "/ws-recency/session-move";
39
39
  export const ADOPT_SESSION_PATH = "/ws-recency/session-adopt";
40
+ export const TRASH_LIST_PATH = "/ws-recency/trash";
41
+
42
+ const TRASH_SIDECAR = ".wsr-trash.json";
40
43
 
41
44
  const STOP_SETTLE_MS = 500;
42
45
  const MAX_BODY_BYTES = 16 * 1024;
@@ -178,8 +181,15 @@ export async function trashSession(ctx, sessionId) {
178
181
  try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* not archived */ }
179
182
  try { await ctx.workspaceRegistry.unpinSession(sessionId); } catch { /* not pinned */ }
180
183
 
184
+ /* Same filtered-view trap as the move: the workspace's own sessionIds may
185
+ already hide the id while the stored record still lists it. */
186
+ const rawMembers = await rawWorkspaceMembership();
181
187
  for (const workspace of ctx.workspaceRegistry.list()) {
182
- if (!Array.isArray(workspace.sessionIds) || !workspace.sessionIds.includes(sessionId)) continue;
188
+ const record = rawMembers === null ? undefined : rawMembers.get(workspace.id);
189
+ const listed = record !== undefined
190
+ ? record.sessionIds.includes(sessionId)
191
+ : Array.isArray(workspace.sessionIds) && workspace.sessionIds.includes(sessionId);
192
+ if (!listed) continue;
183
193
  try { await workspace.detachSession(sessionId); } catch { /* keep going */ }
184
194
  }
185
195
 
@@ -196,6 +206,9 @@ export async function trashSession(ctx, sessionId) {
196
206
  let moved;
197
207
  try {
198
208
  moved = await trashSessionLog(ctx, meta, trashRoot);
209
+ if (moved !== undefined) {
210
+ await writeTrashSidecar(moved, { sessionId: meta.id, cwd: typeof meta.cwd === "string" ? meta.cwd : null, reason: "delete", at: Date.now() });
211
+ }
199
212
  } catch (error) {
200
213
  return { ok: false, error: error instanceof Error ? error.message : String(error) };
201
214
  }
@@ -545,6 +558,7 @@ export async function moveSessionToWorkspace(ctx, sessionId, workspaceId) {
545
558
  await mkdir(backupRoot, { recursive: true });
546
559
  await rename(sourceDirectory, backup);
547
560
  movedAside = true;
561
+ await writeTrashSidecar(backup, { sessionId, cwd: header.cwd, reason: "move", at: Date.now() });
548
562
  } catch (error) {
549
563
  return { ok: false, error: `could not park the old log: ${error instanceof Error ? error.message : String(error)}` };
550
564
  }
@@ -714,6 +728,179 @@ export async function adoptOrphanSessions(ctx) {
714
728
  return { ok: true, adopted, cleaned };
715
729
  }
716
730
 
731
+ /** The session root's project-directory key: separators collapse to `-`. */
732
+ export function projectKey(cwd) {
733
+ if (typeof cwd !== "string" || cwd === "") return undefined;
734
+ let readable = "";
735
+ let separatorRun = false;
736
+ for (let i = 0; i < cwd.length; i += 1) {
737
+ const code = cwd.charCodeAt(i);
738
+ const ch = String.fromCharCode(code);
739
+ if (ch === "/" || ch === "\\" || ch === ":") {
740
+ if (!separatorRun) readable += "-";
741
+ separatorRun = true;
742
+ } else if (ch !== "~" && /^[A-Za-z0-9._-]$/.test(ch)) {
743
+ readable += ch;
744
+ separatorRun = false;
745
+ } else {
746
+ readable += "~" + code.toString(16).toUpperCase().padStart(4, "0");
747
+ separatorRun = false;
748
+ }
749
+ }
750
+ return `--${(readable.replace(/^-+/, "") || "root").slice(0, 251)}--`;
751
+ }
752
+
753
+ async function trashRoot() {
754
+ return join(await dshHome(), ".trash", "ws-recency");
755
+ }
756
+
757
+ /** Record what a trashed directory was, so the UI can put it back. */
758
+ export async function writeTrashSidecar(directory, sidecar) {
759
+ try {
760
+ await mkdir(directory, { recursive: true });
761
+ await writeFile(join(directory, TRASH_SIDECAR), JSON.stringify(sidecar, null, 2), "utf8");
762
+ } catch {
763
+ /* the entry stays restorable-by-hand only */
764
+ }
765
+ }
766
+
767
+ async function readTrashSidecar(directory) {
768
+ try {
769
+ const raw = JSON.parse(await readFile(join(directory, TRASH_SIDECAR), "utf8"));
770
+ return raw !== null && typeof raw === "object" ? raw : null;
771
+ } catch {
772
+ return null;
773
+ }
774
+ }
775
+
776
+ /** Every entry in the plugin's trash, newest first. */
777
+ export async function listTrash() {
778
+ const root = await trashRoot();
779
+ let entries;
780
+ try {
781
+ entries = await readdir(root, { withFileTypes: true });
782
+ } catch {
783
+ return { ok: true, entries: [] };
784
+ }
785
+ const results = [];
786
+ for (const entry of entries) {
787
+ if (!entry.isDirectory()) continue;
788
+ const directory = join(root, entry.name);
789
+ const sidecar = await readTrashSidecar(directory);
790
+ let size = 0;
791
+ try {
792
+ for (const file of await readdir(directory, { withFileTypes: true })) {
793
+ if (file.name === TRASH_SIDECAR || !file.isFile()) continue;
794
+ try {
795
+ size += (await statPath(join(directory, file.name))).size;
796
+ } catch {
797
+ /* skip unreadable files */
798
+ }
799
+ }
800
+ } catch {
801
+ /* skip unreadable directories */
802
+ }
803
+ results.push({
804
+ name: entry.name,
805
+ sizeBytes: size,
806
+ sessionId: sidecar !== null && typeof sidecar.sessionId === "string" ? sidecar.sessionId : null,
807
+ cwd: sidecar !== null && typeof sidecar.cwd === "string" ? sidecar.cwd : null,
808
+ reason: sidecar !== null && typeof sidecar.reason === "string" ? sidecar.reason : "unknown",
809
+ at: sidecar !== null && typeof sidecar.at === "number" ? sidecar.at : 0,
810
+ restorable: sidecar !== null && sidecar.reason === "delete" && typeof sidecar.cwd === "string" && typeof sidecar.sessionId === "string",
811
+ });
812
+ }
813
+ results.sort((a, b) => b.at - a.at || (a.name < b.name ? 1 : -1));
814
+ return { ok: true, entries: results };
815
+ }
816
+
817
+ /** Put one deleted session back where its cwd says it belongs, and re-attach it. */
818
+ export async function restoreTrashEntry(ctx, name) {
819
+ const root = await trashRoot();
820
+ const directory = join(root, name);
821
+ const sidecar = await readTrashSidecar(directory);
822
+ if (sidecar === null || typeof sidecar.cwd !== "string" || typeof sidecar.sessionId !== "string") {
823
+ return { ok: false, error: "this entry has no recorded directory; restore it by hand" };
824
+ }
825
+ const key = projectKey(sidecar.cwd);
826
+ if (key === undefined) return { ok: false, error: "the recorded directory is not usable" };
827
+ const home = await dshHome();
828
+ const target = join(home, "sessions", key, sidecar.sessionId);
829
+ try {
830
+ await mkdir(target, { recursive: true });
831
+ for (const file of await readdir(directory, { withFileTypes: true })) {
832
+ if (file.name === TRASH_SIDECAR) continue;
833
+ await rename(join(directory, file.name), join(target, file.name));
834
+ }
835
+ } catch (error) {
836
+ return { ok: false, error: `could not move the files back: ${error instanceof Error ? error.message : String(error)}` };
837
+ }
838
+ const workspaces = ctx.workspaceRegistry.list();
839
+ const owner = workspaces.find((workspace) => workspace.path === sidecar.cwd);
840
+ let attached = false;
841
+ if (owner !== undefined) {
842
+ try {
843
+ await owner.attachSession(sidecar.sessionId);
844
+ attached = true;
845
+ } catch {
846
+ /* an old header may be refused; the files are back either way */
847
+ }
848
+ }
849
+ try {
850
+ await rm(directory, { recursive: true, force: true });
851
+ } catch {
852
+ /* an empty leftover directory is harmless */
853
+ }
854
+ return { ok: true, sessionId: sidecar.sessionId, cwd: sidecar.cwd, attached };
855
+ }
856
+
857
+ /** Delete one trash entry for good. */
858
+ export async function purgeTrashEntry(name) {
859
+ const root = await trashRoot();
860
+ if (name === "" || name.indexOf("..") !== -1 || name.indexOf("/") !== -1 || name.indexOf("\\") !== -1) {
861
+ return { ok: false, error: "invalid entry name" };
862
+ }
863
+ await rm(join(root, name), { recursive: true, force: true });
864
+ return { ok: true };
865
+ }
866
+
867
+ /** POST { action, name } -> list, restore or purge the plugin's trash. */
868
+ export async function handleTrashListRequest(ctx, req, res) {
869
+ if ((req.method ?? "POST").toUpperCase() !== "POST") {
870
+ sendJson(res, 405, { ok: false, error: "method not allowed" });
871
+ return;
872
+ }
873
+ if (!loopbackOrigin(req)) {
874
+ sendJson(res, 403, { ok: false, error: "origin not trusted" });
875
+ return;
876
+ }
877
+ try {
878
+ const body = await readJsonBody(req);
879
+ const action = body !== null && typeof body.action === "string" ? body.action : "list";
880
+ if (action === "list") {
881
+ sendJson(res, 200, await listTrash());
882
+ return;
883
+ }
884
+ const name = body !== null && typeof body.name === "string" ? body.name.trim() : "";
885
+ if (name === "") {
886
+ sendJson(res, 400, { ok: false, error: "entry name required" });
887
+ return;
888
+ }
889
+ if (action === "restore") {
890
+ const result = await restoreTrashEntry(ctx, name);
891
+ sendJson(res, result.ok ? 200 : 500, result);
892
+ return;
893
+ }
894
+ if (action === "purge") {
895
+ sendJson(res, 200, await purgeTrashEntry(name));
896
+ return;
897
+ }
898
+ sendJson(res, 400, { ok: false, error: "unknown action" });
899
+ } catch (error) {
900
+ sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
901
+ }
902
+ }
903
+
717
904
  /** POST {} -> attach every session that belongs nowhere. */
718
905
  export async function handleAdoptRequest(ctx, req, res) {
719
906
  if ((req.method ?? "POST").toUpperCase() !== "POST") {
@@ -821,6 +1008,11 @@ export function apply(ctx) {
821
1008
  path: MOVE_SESSION_PATH,
822
1009
  handler: (req, res) => handleMoveRequest(moveCtx, req, res),
823
1010
  }), "ws-recency: move route");
1011
+ webCtx.effect(() => server.register({
1012
+ kind: "exact",
1013
+ path: TRASH_LIST_PATH,
1014
+ handler: (req, res) => handleTrashListRequest(moveCtx, req, res),
1015
+ }), "ws-recency: trash route");
824
1016
  webCtx.effect(() => server.register({
825
1017
  kind: "exact",
826
1018
  path: ADOPT_SESSION_PATH,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.11.6",
3
+ "version": "0.12.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",