dsh-ws-recency 0.26.2 → 0.27.1

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 +4 -1
  2. package/client.js +26 -9
  3. package/index.js +163 -6
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -65,6 +65,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
65
65
  - **移到回收站**:走下面那套正常删除,日志改名搬进 `.trash/ws-recency/`,之后仍可恢复;
66
66
  - **彻底删除**:先移进回收站再立即清空,和回收站的「彻底删除」是同一条路径(二次确认);
67
67
  - 宿主的归档集合变动会通过它的 workspace feed 推到浏览器,所以取消归档后侧栏会自己把行放回去,不用刷新界面。
68
+ - **记录失效的行(0.27.0)**:如果日志目录被外部删掉(手工删除、磁盘清理、别的工具清理),归档标记会留下来。这时这一行会标「记录失效」,三个常规动作全部隐藏——它们都会报 session not found——只留一个 **移出归档**:只清掉归档标记、工作区槽位和投影缓存,**不删除任何文件**,确认框里也写明了这一点。日志还存在的会话不会出现这个按钮。
68
69
 
69
70
  ### 删除(宿主没有的,本插件补上)
70
71
 
@@ -84,6 +85,8 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
84
85
  - 每条记录是一张**卡片**:标题、来源(已删除 / 移动前的旧副本 / 已归档)、轮次、步骤、token 总量、日志大小、时间、原目录(归档的统计按日志大小缓存,第一次读完后不再重算);
85
86
  已删除会话的标题与统计在删除时就写进 `.wsr-trash.json`,旧条目则在第一次打开面板时从日志里补算并缓存;
86
87
  - 恢复/扫描/移动之后宿主会广播 `api-session/added`;面板与「扫描并刷新」都能重载页面(不重启应用)让侧栏立刻看到改动;
88
+ - 广播里带**列表投影**(标题、最后提问时间来自投影缓存,缓存没记录时读日志第一页):侧栏是靠这些投影把会话分进工作区分组的,只有摘要没有投影时,会话会“进了列表但不进分组”,看起来像没恢复——0.27.1 修;
89
+ - 恢复 = 恢复日志 + 重新挂到工作区 + 广播;先归档再删除的会话,恢复后重新出现在原工作区分组里,不需要重启;
87
90
  - 移动操作留下的旧副本会标成「移动时的旧副本」,只允许彻底删除;
88
91
  - 所有确认(删除、恢复、彻底删除、移动、取消归档)都是**页面内弹层**,不调用系统 `confirm`/`alert`:系统对话框在 Windows 上关掉后会让渲染进程丢掉键盘焦点,表现为输入框点不进去、切换会话也没用,只能切走再切回来(0.24.2 修)。
89
92
 
@@ -196,7 +199,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
196
199
  或固定版本的预构建包:
197
200
 
198
201
  ```powershell
199
- dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.26.2/dsh-ws-recency-0.26.2.tgz
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
200
203
  ```
201
204
 
202
205
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -197,6 +197,7 @@
197
197
  ".wsr-card-badge{flex:none;font-size:11px;line-height:18px;padding:0 8px;border-radius:9px;background:var(--dsw-alias-bg-layer-3,rgba(255,255,255,.08));color:var(--dsw-alias-label-secondary)}",
198
198
  ".wsr-card-badge-danger{color:var(--dsw-alias-state-error-primary,#d9534f);background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#d9534f) 14%,transparent)}",
199
199
  ".wsr-card-badge-muted{color:var(--dsw-alias-label-tertiary)}",
200
+ ".wsr-card-badge-warning{color:#d99a2b}",
200
201
  ".wsr-card-title{flex:1;min-width:0;font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
201
202
  ".wsr-card-title-id{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-tertiary)}",
202
203
  ".wsr-card-actions{flex:none;display:flex;gap:6px;align-items:center;white-space:nowrap}",
@@ -443,6 +444,10 @@
443
444
  "archive.confirmUnarchive": "把这个会话放回原工作区的原位置?",
444
445
  "archive.confirmDelete": "把这个会话移入回收站?之后仍可在上面一栏恢复。",
445
446
  "archive.confirmForget": "彻底删除这个会话的日志?不可恢复。",
447
+ "archive.badgeMissing": "记录失效",
448
+ "archive.detach": "移出归档",
449
+ "archive.detached": "已移出归档:只清理了归档记录,没有删除任何文件。",
450
+ "archive.confirmDetach": "这个会话的日志已经不在磁盘上,只剩一条归档记录。要把它移出归档列表吗?\n\n只清理记录,不会删除任何文件;如果日志以后又被恢复,需要重新归档。",
446
451
  "archive.unarchived": "已取消归档,会话回到原来的位置。",
447
452
  "archive.deleted": "已移入回收站,可在「已删除的会话」里恢复。",
448
453
  "archive.forgotten": "已彻底删除。",
@@ -606,6 +611,10 @@
606
611
  "archive.confirmUnarchive": "Put this session back where it was in its workspace?",
607
612
  "archive.confirmDelete": "Move this session into the trash? You can still restore it from the section above.",
608
613
  "archive.confirmForget": "Delete this session's log for good? This cannot be undone.",
614
+ "archive.badgeMissing": "record only",
615
+ "archive.detach": "Remove from archive",
616
+ "archive.detached": "Removed from the archive: only the archive record was cleared, no files were touched.",
617
+ "archive.confirmDetach": "This session's log is no longer on disk; only its archive record is left. Remove that record from the archive list?\n\nNo files are touched. If the log ever comes back, the session has to be archived again.",
609
618
  "archive.unarchived": "Unarchived: the session is back in its place.",
610
619
  "archive.deleted": "Moved into the trash; restore it from \"Deleted sessions\".",
611
620
  "archive.forgotten": "Deleted for good.",
@@ -3697,8 +3706,9 @@
3697
3706
 
3698
3707
  var actArchived = function (entry, action) {
3699
3708
  var question = action === "unarchive" ? t("archive.confirmUnarchive")
3700
- : action === "forget" ? t("archive.confirmForget")
3701
- : t("archive.confirmDelete");
3709
+ : action === "detach" ? t("archive.confirmDetach")
3710
+ : action === "forget" ? t("archive.confirmForget")
3711
+ : t("archive.confirmDelete");
3702
3712
  askConfirm(question, function () {
3703
3713
  load(t("trash.working"));
3704
3714
  trashPost({ action: action, sessionId: entry.sessionId }).then(function (result) {
@@ -3708,6 +3718,8 @@
3708
3718
  }
3709
3719
  if (action === "unarchive") {
3710
3720
  load(t("archive.unarchived") + (result.json.listed === false ? t("archive.noWorkspace") : ""));
3721
+ } else if (action === "detach") {
3722
+ load(t("archive.detached"));
3711
3723
  } else if (action === "forget") {
3712
3724
  load(t("archive.forgotten"));
3713
3725
  } else {
@@ -3770,20 +3782,25 @@
3770
3782
  if (when !== "") chips.push(when);
3771
3783
  if (entry.blank === true) chips.push(t("archive.blank"));
3772
3784
  var hasTitle = typeof entry.title === "string" && entry.title !== "";
3785
+ /* A log that is gone can only be detached from the archive set;
3786
+ the other three actions would all fail with "session not found". */
3787
+ var missing = entry.missing === true;
3773
3788
  archivedRows.push(entryCard({
3774
3789
  key: entry.sessionId,
3775
- badge: t("archive.badge"),
3776
- badgeClass: "wsr-card-badge-muted",
3790
+ badge: missing ? t("archive.badgeMissing") : t("archive.badge"),
3791
+ badgeClass: missing ? "wsr-card-badge-warning" : "wsr-card-badge-muted",
3777
3792
  titleClass: hasTitle ? "wsr-card-title" : "wsr-card-title wsr-card-title-id",
3778
3793
  title: hasTitle ? entry.title : entry.sessionId,
3779
3794
  titleAttr: entry.sessionId,
3780
3795
  chips: chips,
3781
3796
  path: typeof entry.workspacePath === "string" && entry.workspacePath !== "" ? entry.workspacePath : entry.cwd,
3782
- actions: [
3783
- h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "unarchive"); } }, t("archive.unarchive")),
3784
- h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "delete"); } }, t("archive.delete")),
3785
- h("button", { type: "button", className: "wsr-btn wsr-btn-danger", onClick: function () { actArchived(entry, "forget"); } }, t("archive.forget")),
3786
- ],
3797
+ actions: missing
3798
+ ? [h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "detach"); } }, t("archive.detach"))]
3799
+ : [
3800
+ h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "unarchive"); } }, t("archive.unarchive")),
3801
+ h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "delete"); } }, t("archive.delete")),
3802
+ h("button", { type: "button", className: "wsr-btn wsr-btn-danger", onClick: function () { actArchived(entry, "forget"); } }, t("archive.forget")),
3803
+ ],
3787
3804
  }));
3788
3805
  })(archivedList[j]);
3789
3806
  }
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.26.2";
35
+ export const HOST_VERSION = "0.27.1";
36
36
 
37
37
  /**
38
38
  * Exact routes the client half calls. Registered on the bare web server, so they
@@ -1168,6 +1168,60 @@ export async function announceSession(ctx, sessionId) {
1168
1168
  const stat = await ctx.sessionPersistence.stat(sessionId);
1169
1169
  const header = stat !== undefined && stat !== null ? stat.header : undefined;
1170
1170
  if (header !== undefined && header !== null) {
1171
+ /* The sidebar groups by workspace through list-surface projections; a
1172
+ summary without them lands in the list but never in a workspace group.
1173
+ Read them from the projection cache (cheap) and fall back to the first
1174
+ prompt of the log (one page) when the cache has no record. */
1175
+ let values = null;
1176
+ const checkpoint = cachedCheckpoint(ctx, sessionId);
1177
+ if (checkpoint !== undefined) {
1178
+ const projections = {};
1179
+ const title = checkpointValue(checkpoint, "title");
1180
+ if (typeof title === "string" && title.trim() !== "") projections.title = title.trim();
1181
+ const listMeta = checkpointValue(checkpoint, "sessionListMetadata");
1182
+ if (listMeta !== null && typeof listMeta === "object") {
1183
+ if (typeof listMeta.lastPromptAt === "number") projections.lastPromptAt = listMeta.lastPromptAt;
1184
+ if (listMeta.blank === true) projections.blank = true;
1185
+ }
1186
+ if (Object.keys(projections).length > 0) values = projections;
1187
+ }
1188
+ if (values !== null) {
1189
+ ctx.emit("api-session/added", {
1190
+ sessionId: header.id,
1191
+ updatedAt: typeof header.updatedAt === "number" ? header.updatedAt : Date.now(),
1192
+ agentAvailable: false,
1193
+ formatStatus: "current",
1194
+ running: false,
1195
+ blank: values.blank === true,
1196
+ title: values.title ?? header.title,
1197
+ cwd: header.cwd,
1198
+ createdAt: header.createdAt,
1199
+ projections: { kind: "cached", values },
1200
+ });
1201
+ return true;
1202
+ }
1203
+ const first = await firstPromptOf(ctx, sessionId);
1204
+ if (first.title !== "" || first.lastPromptAt > 0) {
1205
+ ctx.emit("api-session/added", {
1206
+ sessionId: header.id,
1207
+ updatedAt: typeof header.updatedAt === "number" ? header.updatedAt : Date.now(),
1208
+ agentAvailable: false,
1209
+ formatStatus: "current",
1210
+ running: false,
1211
+ blank: first.title === "" && first.lastPromptAt === 0,
1212
+ title: first.title !== "" ? first.title : header.title,
1213
+ cwd: header.cwd,
1214
+ createdAt: header.createdAt,
1215
+ projections: {
1216
+ kind: "cached",
1217
+ values: {
1218
+ ...(first.title !== "" ? { title: first.title } : {}),
1219
+ ...(first.lastPromptAt > 0 ? { lastPromptAt: first.lastPromptAt } : {}),
1220
+ },
1221
+ },
1222
+ });
1223
+ return true;
1224
+ }
1171
1225
  ctx.emit("api-session/added", {
1172
1226
  sessionId: header.id,
1173
1227
  updatedAt: typeof header.updatedAt === "number" ? header.updatedAt : Date.now(),
@@ -1187,6 +1241,45 @@ export async function announceSession(ctx, sessionId) {
1187
1241
  return false;
1188
1242
  }
1189
1243
 
1244
+ /** Title and first prompt time from the log's first page; empty when unreadable. */
1245
+ async function firstPromptOf(ctx, sessionId) {
1246
+ let handle;
1247
+ try {
1248
+ handle = await ctx.sessionPersistence.open(sessionId, "read");
1249
+ } catch {
1250
+ return { title: "", lastPromptAt: 0 };
1251
+ }
1252
+ try {
1253
+ const page = await handle.read(0, 500);
1254
+ const events = page !== null && page !== undefined && Array.isArray(page.events) ? page.events : [];
1255
+ let title = "";
1256
+ let lastPromptAt = 0;
1257
+ for (const event of events) {
1258
+ if (event === null || typeof event !== "object") continue;
1259
+ if (event.type === "session/title") {
1260
+ const value = event.data?.title ?? event.data;
1261
+ if (typeof value === "string" && value.trim() !== "") title = value.trim();
1262
+ } else if (event.type === "user/message" && lastPromptAt === 0 && typeof event.time === "number") {
1263
+ lastPromptAt = event.time;
1264
+ if (title === "") {
1265
+ const text = conversationText(event.data?.message?.content ?? event.data?.content);
1266
+ const line = text.trim().split("\n")[0];
1267
+ if (line !== "") title = line.slice(0, 120);
1268
+ }
1269
+ }
1270
+ }
1271
+ return { title, lastPromptAt };
1272
+ } catch {
1273
+ return { title: "", lastPromptAt: 0 };
1274
+ } finally {
1275
+ try {
1276
+ if (typeof handle.close === "function") await handle.close();
1277
+ } catch {
1278
+ /* closing is best effort */
1279
+ }
1280
+ }
1281
+ }
1282
+
1190
1283
  /** The session root's project-directory key: separators collapse to `-`. */
1191
1284
  export function projectKey(cwd) {
1192
1285
  if (typeof cwd !== "string" || cwd === "") return undefined;
@@ -1602,6 +1695,19 @@ export async function listArchivedSessions(ctx) {
1602
1695
  let workspace = workspaces.find((candidate) => listedBy(candidate, raw, sessionId));
1603
1696
  if (workspace === undefined && cwd !== null) workspace = workspaces.find((candidate) => candidate.path === cwd);
1604
1697
 
1698
+ /* Is the log still there? `stat` and the listing can disagree when the
1699
+ directory was removed under a running Host, so ask directly once and
1700
+ treat the answer as the authority for the row's actions. */
1701
+ let available = header !== undefined;
1702
+ if (!available) {
1703
+ try {
1704
+ const stat = await ctx.sessionPersistence.stat(sessionId);
1705
+ available = stat !== undefined && stat !== null;
1706
+ } catch {
1707
+ available = false;
1708
+ }
1709
+ }
1710
+
1605
1711
  entries.push({
1606
1712
  sessionId,
1607
1713
  title,
@@ -1617,6 +1723,8 @@ export async function listArchivedSessions(ctx) {
1617
1723
  workspacePath: workspace !== undefined ? workspace.path : null,
1618
1724
  /* Whether a Workspace still lists it: an unarchive without one has nowhere to show up. */
1619
1725
  listed: workspace !== undefined,
1726
+ /* The archive flag outlived its log: the row can only be detached from the set. */
1727
+ missing: !available,
1620
1728
  });
1621
1729
  }
1622
1730
  entries.sort((a, b) => b.lastAt - a.lastAt || (a.sessionId < b.sessionId ? -1 : 1));
@@ -1669,6 +1777,52 @@ export async function restoreArchivedSession(ctx, sessionId) {
1669
1777
  return { ok: true, sessionId, cwd, createdAt, listed };
1670
1778
  }
1671
1779
 
1780
+ /**
1781
+ * Detach an archive flag whose session is gone.
1782
+ *
1783
+ * Only bookkeeping is touched: the id leaves the registry's archive set, every
1784
+ * Workspace listing it drops the slot, and the projection cache row goes. No
1785
+ * directory is removed - the point is that after an out-of-band delete the flag
1786
+ * is all that is left, and leaving it behind is worse than removing it.
1787
+ *
1788
+ * Refuses when the session still exists: this entry point must never be a
1789
+ * second, quieter way to delete a live session.
1790
+ */
1791
+ export async function detachMissingArchive(ctx, sessionId) {
1792
+ if (!archivedSessionIds(ctx).includes(sessionId)) return { ok: false, error: "session is not archived" };
1793
+ try {
1794
+ const stat = await ctx.sessionPersistence.stat(sessionId);
1795
+ if (stat !== undefined && stat !== null) return { ok: false, error: "session still exists" };
1796
+ } catch {
1797
+ /* a failed stat is the case this action is for */
1798
+ }
1799
+
1800
+ try {
1801
+ await ctx.workspaceRegistry.unarchiveSession(sessionId);
1802
+ } catch (error) {
1803
+ return { ok: false, error: `could not unarchive: ${error instanceof Error ? error.message : String(error)}` };
1804
+ }
1805
+ const raw = await rawWorkspaceMembership();
1806
+ for (const workspace of ctx.workspaceRegistry.list()) {
1807
+ if (!listedBy(workspace, raw, sessionId)) continue;
1808
+ try {
1809
+ await workspace.detachSession(sessionId);
1810
+ } catch {
1811
+ /* keep going: the remaining holders are reported by the next listing */
1812
+ }
1813
+ }
1814
+ try {
1815
+ const domain = ctx.get("storageDomain");
1816
+ const projcache = typeof domain?.get === "function" ? domain.get("session_projcache") : undefined;
1817
+ if (projcache !== undefined) await projcache.table("sessions").delete(sessionId);
1818
+ } catch {
1819
+ /* derived data */
1820
+ }
1821
+ /* No `announceSession` here: with the log gone there is no summary to hand
1822
+ the sidebar, and a failed stat would only leave a stale row in view. */
1823
+ return { ok: true, sessionId, removedFromArchive: !archivedSessionIds(ctx).includes(sessionId) };
1824
+ }
1825
+
1672
1826
  /**
1673
1827
  * Delete an archived session for good.
1674
1828
  *
@@ -1815,19 +1969,22 @@ export async function handleTrashListRequest(ctx, req, res) {
1815
1969
  sendJson(res, 200, await listArchivedSessions(ctx));
1816
1970
  return;
1817
1971
  }
1818
- if (action === "unarchive" || action === "forget" || action === "delete") {
1972
+ if (action === "unarchive" || action === "forget" || action === "delete" || action === "detach") {
1819
1973
  const sessionId = sessionIdFrom(req, body);
1820
1974
  if (sessionId === "") {
1821
1975
  sendJson(res, 400, { ok: false, error: "sessionId required" });
1822
1976
  return;
1823
1977
  }
1824
1978
  /* `delete` is the archived row's way into the recoverable trash; the other
1825
- two either put the session back or erase it afterwards. */
1979
+ two either put the session back or erase it afterwards. `detach` only
1980
+ sheds an archive flag whose log is already gone. */
1826
1981
  const result = action === "unarchive"
1827
1982
  ? await restoreArchivedSession(ctx, sessionId)
1828
- : action === "forget"
1829
- ? await forgetArchivedSession(ctx, sessionId)
1830
- : await trashSession(ctx, sessionId);
1983
+ : action === "detach"
1984
+ ? await detachMissingArchive(ctx, sessionId)
1985
+ : action === "forget"
1986
+ ? await forgetArchivedSession(ctx, sessionId)
1987
+ : await trashSession(ctx, sessionId);
1831
1988
  sendJson(res, result.ok ? 200 : 500, result);
1832
1989
  return;
1833
1990
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.26.2",
3
+ "version": "0.27.1",
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",