dsh-ws-recency 0.27.1 → 0.28.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 (3) hide show
  1. package/README.md +3 -2
  2. package/index.js +74 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -80,7 +80,8 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
80
80
 
81
81
  **不是物理删除**:目录只是被改名搬走。每个条目在 `.trash/ws-recency/` 下带一份 `.wsr-trash.json`(会话 id、原 cwd、时间、来源),回收站面板会列出它们:
82
82
 
83
- - 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,并重新挂到对应工作区;
83
+ - 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,重新挂到对应工作区,最后摘掉删除时打上的归档标记;
84
+ - 删除会**保留归档标记**(原来没有的会补上):日志已经离开 `sessions/`,宿主的列表里没有它,而归档是唯一一个其它插件都认识的“已收起来”状态——dsh-context 之类的看板就是靠它把已删会话显示成不可点。恢复时摘标记、彻底删除时先摘标记再删文件(0.28.0 起);
84
85
  - 「彻底删除」:真正删掉这份日志(二次确认);
85
86
  - 每条记录是一张**卡片**:标题、来源(已删除 / 移动前的旧副本 / 已归档)、轮次、步骤、token 总量、日志大小、时间、原目录(归档的统计按日志大小缓存,第一次读完后不再重算);
86
87
  已删除会话的标题与统计在删除时就写进 `.wsr-trash.json`,旧条目则在第一次打开面板时从日志里补算并缓存;
@@ -199,7 +200,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
199
200
  或固定版本的预构建包:
200
201
 
201
202
  ```powershell
202
- dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.27.1/dsh-ws-recency-0.27.1.tgz
203
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.28.0/dsh-ws-recency-0.28.0.tgz
203
204
  ```
204
205
 
205
206
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/index.js CHANGED
@@ -32,7 +32,7 @@ import { dirname, join } from "node:path";
32
32
  export const name = "ws-recency";
33
33
 
34
34
  /** Version marker reported by the health route. */
35
- export const HOST_VERSION = "0.27.1";
35
+ export const HOST_VERSION = "0.28.0";
36
36
 
37
37
  /**
38
38
  * Exact routes the client half calls. Registered on the bare web server, so they
@@ -130,6 +130,10 @@ async function moveWithRetry(source, target) {
130
130
  await rename(source, target);
131
131
  return true;
132
132
  } catch (error) {
133
+ /* Only a momentary lock is worth retrying; "not there" means the move
134
+ cannot happen at all, and treating it as success would leave the caller
135
+ with an empty trash entry and no error. */
136
+ if (error?.code === "ENOENT") return false;
133
137
  if (attempt === RENAME_RETRY - 1) throw error;
134
138
  await new Promise((resolve) => setTimeout(resolve, RENAME_GAP_MS));
135
139
  }
@@ -187,9 +191,18 @@ export async function trashSession(ctx, sessionId) {
187
191
  }
188
192
  await new Promise((resolve) => setTimeout(resolve, STOP_SETTLE_MS));
189
193
 
190
- try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* not archived */ }
191
194
  try { await ctx.workspaceRegistry.unpinSession(sessionId); } catch { /* not pinned */ }
192
195
 
196
+ /* Keep the archive flag instead of clearing it. A trashed session whose log
197
+ moved out of `sessions/` is invisible to the Host's listing, and the flag is
198
+ the only state other plugins can read; dropping it is what made a deleted
199
+ session look alive on boards that keep their own cache. The move below is
200
+ undone with the flag when it fails, so the session returns to its place. */
201
+ const wasArchived = archivedSessionIds(ctx).includes(sessionId);
202
+ if (!wasArchived) {
203
+ try { await ctx.workspaceRegistry.archiveSession(sessionId); } catch { /* an older Host may not offer it */ }
204
+ }
205
+
193
206
  /* Same filtered-view trap as the move: the workspace's own sessionIds may
194
207
  already hide the id while the stored record still lists it. */
195
208
  const rawMembers = await rawWorkspaceMembership();
@@ -215,24 +228,36 @@ export async function trashSession(ctx, sessionId) {
215
228
  let moved;
216
229
  try {
217
230
  moved = await trashSessionLog(ctx, meta, trashRoot);
218
- if (moved !== undefined) {
219
- /* Card facts are captured now, while the log is still on this machine:
220
- the list only has to read the sidecar afterwards. */
221
- const card = await trashEntryMetadata(moved);
222
- await writeTrashSidecar(moved, {
223
- sessionId: meta.id,
224
- cwd: typeof meta.cwd === "string" ? meta.cwd : null,
225
- reason: "delete",
226
- at: Date.now(),
227
- ...(card === null ? {} : { meta: card }),
228
- });
229
- }
231
+ if (moved === undefined) {
232
+ /* Nothing was parked and nothing was lost: the session could not even be
233
+ listed, so it may have been erased out of band. Roll the flag back. */
234
+ if (!wasArchived) {
235
+ try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* best effort */ }
236
+ }
237
+ return { ok: false, error: "the session's log is not on disk" };
238
+ }
239
+ /* Card facts are captured now, while the log is still on this machine:
240
+ the list only has to read the sidecar afterwards. */
241
+ const card = await trashEntryMetadata(moved);
242
+ await writeTrashSidecar(moved, {
243
+ sessionId: meta.id,
244
+ cwd: typeof meta.cwd === "string" ? meta.cwd : null,
245
+ reason: "delete",
246
+ at: Date.now(),
247
+ /* Restore has to know it owes the Host an unarchive. */
248
+ archived: true,
249
+ ...(card === null ? {} : { meta: card }),
250
+ });
230
251
  } catch (error) {
252
+ /* The flag would otherwise hide a session whose log never left the disk. */
253
+ if (!wasArchived) {
254
+ try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* best effort */ }
255
+ }
231
256
  return { ok: false, error: error instanceof Error ? error.message : String(error) };
232
257
  }
233
258
 
234
259
  ctx.emit("api-session/removed", sessionId);
235
- return { ok: true, trash: moved };
260
+ return { ok: true, trash: moved, archivedKept: true };
236
261
  }
237
262
 
238
263
  /** POST { sessionId } -> move that session into the trash folder. */
@@ -1486,6 +1511,14 @@ export async function restoreTrashEntry(ctx, name) {
1486
1511
  } catch (error) {
1487
1512
  return { ok: false, error: `could not move the files back: ${error instanceof Error ? error.message : String(error)}` };
1488
1513
  }
1514
+ /* The archive flag the delete kept is dropped only now: with the log back in
1515
+ place but the flag still set, the archive panel would show a record-only
1516
+ row for a session that has its log again. */
1517
+ try {
1518
+ await ctx.workspaceRegistry.unarchiveSession(sidecar.sessionId);
1519
+ } catch {
1520
+ /* not archived (older entries) or the Host refused; the attach below still runs */
1521
+ }
1489
1522
  const workspaces = ctx.workspaceRegistry.list();
1490
1523
  const owner = workspaces.find((workspace) => workspace.path === sidecar.cwd);
1491
1524
  let attached = false;
@@ -1521,13 +1554,31 @@ export async function restoreTrashEntry(ctx, name) {
1521
1554
  return { ok: true, sessionId: sidecar.sessionId, cwd: sidecar.cwd, attached };
1522
1555
  }
1523
1556
 
1524
- /** Delete one trash entry for good. */
1525
- export async function purgeTrashEntry(name) {
1557
+ /**
1558
+ * Erase one trash entry for good.
1559
+ *
1560
+ * A trashed session keeps the Host's archive flag (that flag is how the rest of
1561
+ * the app knows it is put away), so purging has to drop it first - otherwise the
1562
+ * archive set would keep an id whose log no longer exists.
1563
+ */
1564
+ export async function purgeTrashEntry(name, ctx = null) {
1526
1565
  const root = await trashRoot();
1527
1566
  if (name === "" || name.indexOf("..") !== -1 || name.indexOf("/") !== -1 || name.indexOf("\\") !== -1) {
1528
1567
  return { ok: false, error: "invalid entry name" };
1529
1568
  }
1530
- await rm(join(root, name), { recursive: true, force: true });
1569
+ const directory = join(root, name);
1570
+ if (ctx !== null && ctx !== undefined) {
1571
+ const sidecar = await readTrashSidecar(directory);
1572
+ const sessionId = sidecar !== null && typeof sidecar.sessionId === "string" ? sidecar.sessionId : "";
1573
+ if (sessionId !== "") {
1574
+ try {
1575
+ await ctx.workspaceRegistry.unarchiveSession(sessionId);
1576
+ } catch {
1577
+ /* not archived, or the Host refused; erasing the files still proceeds */
1578
+ }
1579
+ }
1580
+ }
1581
+ await rm(directory, { recursive: true, force: true });
1531
1582
  return { ok: true };
1532
1583
  }
1533
1584
 
@@ -1826,9 +1877,9 @@ export async function detachMissingArchive(ctx, sessionId) {
1826
1877
  /**
1827
1878
  * Delete an archived session for good.
1828
1879
  *
1829
- * The normal delete already unarchives, detaches and moves the log into the
1830
- * plugin's trash - erasing it is then the trash's own purge, so the two paths
1831
- * cannot drift apart.
1880
+ * The normal delete detaches, keeps the archive flag and moves the log into the
1881
+ * plugin's trash - erasing it is then the trash's own purge (which drops the
1882
+ * flag before the files), so the two paths cannot drift apart.
1832
1883
  */
1833
1884
  export async function forgetArchivedSession(ctx, sessionId) {
1834
1885
  const result = await trashSession(ctx, sessionId);
@@ -1838,7 +1889,7 @@ export async function forgetArchivedSession(ctx, sessionId) {
1838
1889
  const name = result.trash.split(/[/\\]/).filter((part) => part !== "").pop();
1839
1890
  if (typeof name === "string" && name !== "") {
1840
1891
  try {
1841
- purged = (await purgeTrashEntry(name)).ok === true;
1892
+ purged = (await purgeTrashEntry(name, ctx)).ok === true;
1842
1893
  } catch {
1843
1894
  purged = false;
1844
1895
  }
@@ -1999,7 +2050,7 @@ export async function handleTrashListRequest(ctx, req, res) {
1999
2050
  return;
2000
2051
  }
2001
2052
  if (action === "purge") {
2002
- sendJson(res, 200, await purgeTrashEntry(name));
2053
+ sendJson(res, 200, await purgeTrashEntry(name, ctx));
2003
2054
  return;
2004
2055
  }
2005
2056
  sendJson(res, 400, { ok: false, error: "unknown action" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.27.1",
3
+ "version": "0.28.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, archived sessions managed from that same trash panel, per-session token statistics with an argument/result split and an option to count tool arguments as the agent's writing, moving a session to another workspace, and a literal content search that jumps to the turn a word was said in.",
5
5
  "license": "MIT",
6
6
  "author": "chyxhtc",