dsh-ws-recency 0.16.0 → 0.18.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 +4 -2
  2. package/client.js +116 -74
  3. package/index.js +131 -2
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -15,7 +15,7 @@ DSH 已经把**组内**会话按 `updatedAt` 倒序排好了(排序方式 =
15
15
  - **每组一个控件**:宿主的「展开其余 N 条会话」被隐藏,由插件的 `展开历史 N` / `收起历史` 接管。N = 宿主还没渲染的行 + 已折叠的过期行;
16
16
  - 点「展开历史」→ 插件逐轮驱动宿主那个隐藏按钮(每轮它会多渲染 5 条,剩下 ≤5 条时一次全出),直到整组都渲染出来,同时展开过期行——**一次点到全展开**;
17
17
  - 点「收起历史」→ 重新折叠过期行(宿主已渲染的部分仍由插件按时间折叠,不会丢失);
18
- - 选中 / 运行中 / 等待处理的会话**永不折叠**(可在设置里关掉这个豁免);
18
+ - 选中 / 运行中 / 等待处理 / **标记「需要跟进」** 的会话**永不折叠**——标记就是为了提醒自己去看,收进历史等于白标(选中/运行中/等待处理的豁免可在设置里关掉,跟进标记的豁免始终生效);
19
19
  - 空白草稿行(新会话)不参与折叠判断;
20
20
  - 每 5 分钟自动重算一次,所以跨过 3 天边界的会话会自己折叠,不用刷新。
21
21
 
@@ -79,6 +79,8 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
79
79
 
80
80
  - 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,并重新挂到对应工作区;
81
81
  - 「彻底删除」:真正删掉这份日志(二次确认);
82
+ - 每条记录是一张**卡片**:标题、来源(已删除 / 移动前的旧副本 / 已归档)、轮次、步骤、token 总量、日志大小、时间、原目录(归档的统计按日志大小缓存,第一次读完后不再重算);
83
+ 已删除会话的标题与统计在删除时就写进 `.wsr-trash.json`,旧条目则在第一次打开面板时从日志里补算并缓存;
82
84
  - 恢复/扫描/移动之后宿主会广播 `api-session/added`;面板与「扫描并刷新」都能重载页面(不重启应用)让侧栏立刻看到改动;
83
85
  - 移动操作留下的旧副本会标成「移动时的旧副本」,只允许彻底删除。
84
86
 
@@ -152,7 +154,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
152
154
  或固定版本的预构建包:
153
155
 
154
156
  ```powershell
155
- dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.16.0/dsh-ws-recency-0.16.0.tgz
157
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.18.0/dsh-ws-recency-0.18.0.tgz
156
158
  ```
157
159
 
158
160
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -143,7 +143,18 @@
143
143
  ".wsr-page-head{display:flex;align-items:center;gap:8px}",
144
144
  ".wsr-page-heading{flex:1;font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary)}",
145
145
  ".wsr-page-list{display:flex;flex-direction:column;gap:6px}",
146
- ".wsr-page-row{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04))}",
146
+ ".wsr-page-row{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04))}",
147
+ ".wsr-card{display:flex;flex-direction:column;gap:8px;padding:12px 14px;border:.5px solid var(--dsw-alias-border-l1,rgba(255,255,255,.08));border-radius:10px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04))}",
148
+ ".wsr-card-head{display:flex;align-items:center;gap:10px;min-width:0}",
149
+ ".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)}",
150
+ ".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)}",
151
+ ".wsr-card-badge-muted{color:var(--dsw-alias-label-tertiary)}",
152
+ ".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}",
153
+ ".wsr-card-title-id{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--dsw-alias-label-tertiary)}",
154
+ ".wsr-card-actions{flex:none;display:flex;gap:6px;align-items:center;white-space:nowrap}",
155
+ ".wsr-chips{display:flex;flex-wrap:wrap;gap:6px}",
156
+ ".wsr-chip{font-size:11px;line-height:18px;padding:0 7px;border-radius:9px;background:var(--dsw-alias-bg-layer-3,rgba(255,255,255,.06));color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
157
+ ".wsr-card-path{font-size:11px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
147
158
  ".wsr-page-text{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}",
148
159
  ".wsr-page-title{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
149
160
  ".wsr-page-meta{font-size:11px;color:var(--dsw-alias-label-tertiary)}",
@@ -211,7 +222,7 @@
211
222
  var ZH = {
212
223
  "settings.title": "\u5386\u53f2\u6298\u53e0\u5929\u6570",
213
224
  "settings.description": "\u4f1a\u8bdd\u8d85\u8fc7\u8fd9\u4e48\u591a\u5929\u6ca1\u6709\u66f4\u65b0\u5c31\u6298\u53e0\uff1b\u6574\u4e2a\u5de5\u4f5c\u533a\u90fd\u8fc7\u671f\u65f6\u53ea\u5269\u5de5\u4f5c\u533a\u6807\u9898\u3002",
214
- "settings.exempt": "\u9009\u4e2d / \u8fd0\u884c\u4e2d / \u7b49\u5f85\u5904\u7406\u7684\u4f1a\u8bdd\u4e0d\u6298\u53e0",
225
+ "settings.exempt": "选中 / 运行中 / 等待处理 / 标记跟进的会话不折叠",
215
226
  "fold.show": "\u5c55\u5f00\u5386\u53f2 {n}",
216
227
  "fold.hide": "\u6536\u8d77\u5386\u53f2",
217
228
  "color.title": "\u989c\u8272\u4e0e\u8ddf\u8fdb\u6807\u8bb0",
@@ -283,6 +294,8 @@
283
294
  "trash.working": "处理中…",
284
295
  "trash.failed": "操作失败:",
285
296
  "trash.note": "回收站里的都是完整日志目录;恢复会按记录的 cwd 放回 sessions/<项目> 并重新挂到对应工作区。",
297
+ "trash.turns": "轮次",
298
+ "trash.steps": "步骤",
286
299
  "trash.section.trash": "已删除的会话",
287
300
  "trash.section.archived": "已归档的会话",
288
301
  "archive.description": "归档是宿主的「视图选项 → 仅显示已归档」那一套:会话被隐藏,但日志仍在 sessions/ 里,原工作区的槽位也保留着。这里可以取消归档、移入回收站,或者彻底删除。",
@@ -298,6 +311,7 @@
298
311
  "archive.forgotten": "已彻底删除。",
299
312
  "archive.failed": "归档操作失败:",
300
313
  "archive.noWorkspace": "(它原来的目录现在没有对应的工作区,需要先建一个同名工作区才能看到它)",
314
+ "archive.badge": "已归档",
301
315
  "archive.blank": "空白草稿",
302
316
  "archive.workspace": "工作区",
303
317
  "move.failed": "移动失败:",
@@ -314,7 +328,7 @@
314
328
  var EN = {
315
329
  "settings.title": "Fold history after (days)",
316
330
  "settings.description": "Sessions with no update for this many days are folded; a workspace older than that shows as a bare header.",
317
- "settings.exempt": "Never fold the selected / running / waiting session",
331
+ "settings.exempt": "Never fold the selected, running, waiting or follow-up session",
318
332
  "fold.show": "Show history ({n})",
319
333
  "fold.hide": "Hide history",
320
334
  "color.title": "Colors and follow-up marks",
@@ -386,6 +400,8 @@
386
400
  "trash.working": "Working\u2026",
387
401
  "trash.failed": "Action failed: ",
388
402
  "trash.note": "Every entry is a complete log directory; restoring puts it back under sessions/<project> using the recorded cwd and re-attaches it.",
403
+ "trash.turns": "turns",
404
+ "trash.steps": "steps",
389
405
  "trash.section.trash": "Deleted sessions",
390
406
  "trash.section.archived": "Archived sessions",
391
407
  "archive.description": "Archiving is the Host's own view filter (\"Show archived only\"): the session is hidden, but its log stays under sessions/ and its workspace still holds its slot. Unarchive it here, move it into the trash, or delete it for good.",
@@ -742,7 +758,13 @@
742
758
  var updated = updatedAtOf(row, sessions);
743
759
  var stale = updated !== null && updated < cutoff;
744
760
  var blank = isBlankRow(row, sessions);
745
- var exempt = settings.keepActive && (isActiveRow(row) || isSelectedRow(row));
761
+ /* "Needs follow-up" means "I still owe this one an answer": hiding it
762
+ behind a fold defeats the mark, so it is exempt like a running row. */
763
+ var marked = sessionIdOf(row);
764
+ var flagged = marked !== null && settings.followUps !== null
765
+ && typeof settings.followUps === "object"
766
+ && settings.followUps[marked] !== undefined;
767
+ var exempt = flagged || (settings.keepActive && (isActiveRow(row) || isSelectedRow(row)));
746
768
  var hide = !expanded && stale && !exempt && !blank;
747
769
  if (hide) {
748
770
  if (row.getAttribute(HIDDEN_ATTR) !== "true") row.setAttribute(HIDDEN_ATTR, "true");
@@ -2096,6 +2118,27 @@
2096
2118
  * Host's archive set (hidden sessions whose logs are still in place)
2097
2119
  * below. Both are "put away", so both are managed from here.
2098
2120
  */
2121
+ /** One entry as a card: badge, title, the numbers that matter, and actions. */
2122
+ function entryCard(options) {
2123
+ return h("div", { className: "wsr-card", key: options.key, title: options.titleAttr || "" },
2124
+ h("div", { className: "wsr-card-head" },
2125
+ options.badge !== null && options.badge !== undefined
2126
+ ? h("span", { className: "wsr-card-badge " + (options.badgeClass || "") }, options.badge)
2127
+ : null,
2128
+ h("div", { className: options.titleClass || "wsr-card-title" }, options.title),
2129
+ h("div", { className: "wsr-card-actions" }, options.actions),
2130
+ ),
2131
+ options.chips.length > 0
2132
+ ? h("div", { className: "wsr-chips" }, options.chips.map(function (text, index) {
2133
+ return h("span", { className: "wsr-chip", key: String(index) }, text);
2134
+ }))
2135
+ : null,
2136
+ typeof options.path === "string" && options.path !== ""
2137
+ ? h("div", { className: "wsr-card-path" }, options.path)
2138
+ : null,
2139
+ );
2140
+ }
2141
+
2099
2142
  function TrashPanelPage() {
2100
2143
  var state = react.useState({ loaded: false, entries: [], archived: [], note: "", failed: "" });
2101
2144
  var view = state[0];
@@ -2168,76 +2211,75 @@
2168
2211
  });
2169
2212
  };
2170
2213
 
2171
- var rows = [];
2172
- for (var i = 0; i < view.entries.length; i += 1) {
2173
- (function (entry) {
2174
- var meta = [];
2175
- if (entry.reason === "delete") meta.push(t("trash.reason.delete"));
2176
- else if (entry.reason === "move") meta.push(t("trash.reason.move"));
2177
- meta.push(formatBytes(entry.sizeBytes));
2178
- var when = formatWhen(entry.at);
2179
- if (when !== "") meta.push(when);
2180
- var actions = [h("button", {
2181
- type: "button",
2182
- className: "wsr-btn",
2183
- onClick: function () { act(entry, "restore"); },
2184
- }, t("trash.restore"))].filter(function () { return entry.restorable === true; });
2185
- actions.push(h("button", {
2186
- type: "button",
2187
- className: "wsr-btn wsr-btn-danger",
2188
- onClick: function () { act(entry, "purge"); },
2189
- }, t("trash.purge")));
2190
- rows.push(h("div", { className: "wsr-page-row", key: entry.name },
2191
- h("div", { className: "wsr-page-text" },
2192
- h("div", { className: "wsr-page-title" }, entry.sessionId === null ? entry.name : entry.sessionId),
2193
- h("div", { className: "wsr-page-meta" }, meta.join(" \u00b7 ")),
2194
- typeof entry.cwd === "string" && entry.cwd !== "" ? h("div", { className: "wsr-page-path" }, entry.cwd) : null,
2195
- ),
2196
- h("div", { className: "wsr-page-actions" }, actions),
2197
- ));
2198
- })(view.entries[i]);
2199
- }
2200
-
2201
- var archivedRows = [];
2202
- var archivedList = Array.isArray(view.archived) ? view.archived : [];
2203
- for (var j = 0; j < archivedList.length; j += 1) {
2204
- (function (entry) {
2205
- var meta = [];
2206
- if (entry.blank === true) meta.push(t("archive.blank"));
2207
- if (typeof entry.workspacePath === "string" && entry.workspacePath !== "") meta.push(entry.workspacePath);
2208
- meta.push(formatBytes(entry.sizeBytes));
2209
- var when = formatWhen(entry.lastAt !== 0 ? entry.lastAt : entry.createdAt);
2210
- if (when !== "") meta.push(when);
2211
- var label = typeof entry.title === "string" && entry.title !== "" ? entry.title : entry.sessionId;
2212
- archivedRows.push(h("div", { className: "wsr-page-row", key: entry.sessionId },
2213
- h("div", { className: "wsr-page-text" },
2214
- h("div", {
2215
- className: typeof entry.title === "string" && entry.title !== "" ? "wsr-page-title" : "wsr-page-title wsr-page-title-blank",
2216
- }, label),
2217
- h("div", { className: "wsr-page-meta" }, meta.join(" \u00b7 ")),
2218
- typeof entry.cwd === "string" && entry.cwd !== "" ? h("div", { className: "wsr-page-path" }, entry.cwd) : null,
2219
- ),
2220
- h("div", { className: "wsr-page-actions" },
2221
- h("button", {
2222
- type: "button",
2223
- className: "wsr-btn",
2224
- onClick: function () { actArchived(entry, "unarchive"); },
2225
- }, t("archive.unarchive")),
2226
- h("button", {
2227
- type: "button",
2228
- className: "wsr-btn",
2229
- onClick: function () { actArchived(entry, "delete"); },
2230
- }, t("archive.delete")),
2231
- h("button", {
2232
- type: "button",
2233
- className: "wsr-btn wsr-btn-danger",
2234
- onClick: function () { actArchived(entry, "forget"); },
2235
- }, t("archive.forget")),
2236
- ),
2237
- ));
2238
- })(archivedList[j]);
2239
- }
2240
-
2214
+ var rows = [];
2215
+ for (var i = 0; i < view.entries.length; i += 1) {
2216
+ (function (entry) {
2217
+ var chips = [];
2218
+ if (entry.turns > 0) chips.push(t("trash.turns") + " " + entry.turns);
2219
+ if (entry.steps > 0) chips.push(t("trash.steps") + " " + entry.steps);
2220
+ if (entry.tokens > 0) chips.push(formatTokens(entry.tokens) + " tokens");
2221
+ chips.push(formatBytes(entry.sizeBytes));
2222
+ var when = formatWhen(entry.at);
2223
+ if (when !== "") chips.push(when);
2224
+ var actions = [];
2225
+ if (entry.restorable === true) {
2226
+ actions.push(h("button", {
2227
+ type: "button",
2228
+ className: "wsr-btn",
2229
+ onClick: function () { act(entry, "restore"); },
2230
+ }, t("trash.restore")));
2231
+ }
2232
+ actions.push(h("button", {
2233
+ type: "button",
2234
+ className: "wsr-btn wsr-btn-danger",
2235
+ onClick: function () { act(entry, "purge"); },
2236
+ }, t("trash.purge")));
2237
+ var hasTitle = typeof entry.title === "string" && entry.title !== "";
2238
+ rows.push(entryCard({
2239
+ key: entry.name,
2240
+ badge: entry.reason === "move" ? t("trash.reason.move") : t("trash.reason.delete"),
2241
+ badgeClass: entry.reason === "move" ? "wsr-card-badge-muted" : "wsr-card-badge-danger",
2242
+ titleClass: hasTitle ? "wsr-card-title" : "wsr-card-title wsr-card-title-id",
2243
+ title: hasTitle ? entry.title : (entry.sessionId === null ? entry.name : entry.sessionId),
2244
+ titleAttr: entry.sessionId === null ? entry.name : entry.sessionId,
2245
+ chips: chips,
2246
+ path: entry.cwd,
2247
+ actions: actions,
2248
+ }));
2249
+ })(view.entries[i]);
2250
+ }
2251
+
2252
+ var archivedRows = [];
2253
+ var archivedList = Array.isArray(view.archived) ? view.archived : [];
2254
+ for (var j = 0; j < archivedList.length; j += 1) {
2255
+ (function (entry) {
2256
+ var chips = [];
2257
+ if (entry.turns > 0) chips.push(t("trash.turns") + " " + entry.turns);
2258
+ if (entry.steps > 0) chips.push(t("trash.steps") + " " + entry.steps);
2259
+ if (entry.tokens > 0) chips.push(formatTokens(entry.tokens) + " tokens");
2260
+ chips.push(formatBytes(entry.sizeBytes));
2261
+ var when = formatWhen(entry.lastAt !== 0 ? entry.lastAt : entry.createdAt);
2262
+ if (when !== "") chips.push(when);
2263
+ if (entry.blank === true) chips.push(t("archive.blank"));
2264
+ var hasTitle = typeof entry.title === "string" && entry.title !== "";
2265
+ archivedRows.push(entryCard({
2266
+ key: entry.sessionId,
2267
+ badge: t("archive.badge"),
2268
+ badgeClass: "wsr-card-badge-muted",
2269
+ titleClass: hasTitle ? "wsr-card-title" : "wsr-card-title wsr-card-title-id",
2270
+ title: hasTitle ? entry.title : entry.sessionId,
2271
+ titleAttr: entry.sessionId,
2272
+ chips: chips,
2273
+ path: typeof entry.workspacePath === "string" && entry.workspacePath !== "" ? entry.workspacePath : entry.cwd,
2274
+ actions: [
2275
+ h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "unarchive"); } }, t("archive.unarchive")),
2276
+ h("button", { type: "button", className: "wsr-btn", onClick: function () { actArchived(entry, "delete"); } }, t("archive.delete")),
2277
+ h("button", { type: "button", className: "wsr-btn wsr-btn-danger", onClick: function () { actArchived(entry, "forget"); } }, t("archive.forget")),
2278
+ ],
2279
+ }));
2280
+ })(archivedList[j]);
2281
+ }
2282
+
2241
2283
  var archiveSection = view.archived === null ? null : [
2242
2284
  h("div", { className: "wsr-page-section", key: "archive-head" },
2243
2285
  h("span", null, t("trash.section.archived")),
package/index.js CHANGED
@@ -25,13 +25,14 @@
25
25
  * @module dsh-ws-recency
26
26
  */
27
27
  import { mkdir, readFile, readdir, rename, rm, stat as statPath, writeFile } from "node:fs/promises";
28
+ import zlib from "node:zlib";
28
29
  import { dirname, join } from "node:path";
29
30
 
30
31
  /** Cordis plugin name shown by the loader. */
31
32
  export const name = "ws-recency";
32
33
 
33
34
  /** Version marker reported by the health route. */
34
- export const HOST_VERSION = "0.16.0";
35
+ export const HOST_VERSION = "0.18.0";
35
36
 
36
37
  /**
37
38
  * Exact routes the client half calls. Registered on the bare web server, so they
@@ -212,7 +213,16 @@ export async function trashSession(ctx, sessionId) {
212
213
  try {
213
214
  moved = await trashSessionLog(ctx, meta, trashRoot);
214
215
  if (moved !== undefined) {
215
- await writeTrashSidecar(moved, { sessionId: meta.id, cwd: typeof meta.cwd === "string" ? meta.cwd : null, reason: "delete", at: Date.now() });
216
+ /* Card facts are captured now, while the log is still on this machine:
217
+ the list only has to read the sidecar afterwards. */
218
+ const card = await trashEntryMetadata(moved);
219
+ await writeTrashSidecar(moved, {
220
+ sessionId: meta.id,
221
+ cwd: typeof meta.cwd === "string" ? meta.cwd : null,
222
+ reason: "delete",
223
+ at: Date.now(),
224
+ ...(card === null ? {} : { meta: card }),
225
+ });
216
226
  }
217
227
  } catch (error) {
218
228
  return { ok: false, error: error instanceof Error ? error.message : String(error) };
@@ -264,6 +274,9 @@ export async function handleTrashRequest(ctx, req, res) {
264
274
  const STATS_CACHE_MS = 10 * 1000;
265
275
  const statsCache = new Map();
266
276
 
277
+ /** Archived sessions keep their log, so their card facts never change: key by size. */
278
+ const archiveMetaCache = new Map();
279
+
267
280
  /** bytes/4 per Latin character, ~1 token per CJK character. */
268
281
  export function estimateTokens(text) {
269
282
  if (typeof text !== "string" || text === "") return 0;
@@ -826,6 +839,85 @@ async function readTrashSidecar(directory) {
826
839
  }
827
840
  }
828
841
 
842
+ /** The one log file a session directory holds. */
843
+ const SESSION_LOG = "session.v4.jsonl.zstd";
844
+
845
+ /** zstd frame magic: every append is its own frame, so a log must be split on it. */
846
+ const ZSTD_MAGIC = Buffer.from([0x28, 0xb5, 0x2f, 0xfd]);
847
+
848
+ /**
849
+ * Read a session log that is no longer reachable through the persistence service.
850
+ *
851
+ * A trashed log sits outside `sessions/`, so the Host's own reader cannot open
852
+ * it; the frames are decompressed directly with the bundled zstd support (Node
853
+ * 22.15 and newer). Without it the caller keeps the id-only card.
854
+ */
855
+ async function readLogEvents(file) {
856
+ if (typeof zlib.zstdDecompressSync !== "function") return null;
857
+ const buffer = await readFile(file);
858
+ const offsets = [];
859
+ let index = buffer.indexOf(ZSTD_MAGIC, 0);
860
+ while (index !== -1) {
861
+ offsets.push(index);
862
+ index = buffer.indexOf(ZSTD_MAGIC, index + ZSTD_MAGIC.length);
863
+ }
864
+ if (offsets.length === 0) return null;
865
+ const parts = [];
866
+ for (let frame = 0; frame < offsets.length; frame += 1) {
867
+ const end = frame + 1 < offsets.length ? offsets[frame + 1] : buffer.length;
868
+ try {
869
+ parts.push(zlib.zstdDecompressSync(buffer.subarray(offsets[frame], end)));
870
+ } catch {
871
+ /* a torn tail frame is normal after a crash */
872
+ }
873
+ }
874
+ const text = Buffer.concat(parts).toString("utf8");
875
+ const events = [];
876
+ for (const line of text.split("\n")) {
877
+ if (line === "") continue;
878
+ try {
879
+ events.push(JSON.parse(line));
880
+ } catch {
881
+ /* skip a partial line */
882
+ }
883
+ }
884
+ return events;
885
+ }
886
+
887
+ /**
888
+ * The card facts for a trashed session: title, turns, steps and recorded tokens.
889
+ * @param directory - one entry of the trash root.
890
+ * @returns metadata, or null when the log cannot be read here.
891
+ */
892
+ export async function trashEntryMetadata(directory) {
893
+ let events;
894
+ try {
895
+ events = await readLogEvents(join(directory, SESSION_LOG));
896
+ } catch {
897
+ return null;
898
+ }
899
+ if (events === null || events.length === 0) return null;
900
+ const summary = aggregateSession(events);
901
+ let turns = 0;
902
+ let messages = 0;
903
+ for (const event of events) {
904
+ if (event === null || typeof event !== "object") continue;
905
+ if (event.type === "turn/start") turns += 1;
906
+ if (event.type === "user/message") messages += 1;
907
+ }
908
+ if (turns === 0) turns = messages;
909
+ return {
910
+ title: typeof summary.session.title === "string" ? summary.session.title : "",
911
+ turns,
912
+ messages,
913
+ steps: summary.steps,
914
+ tokens: summary.totals.totalTokens,
915
+ inputTokens: summary.totals.inputTokens,
916
+ outputTokens: summary.totals.outputTokens,
917
+ lastAt: summary.session.lastAt,
918
+ };
919
+ }
920
+
829
921
  /** Every entry in the plugin's trash, newest first. */
830
922
  export async function listTrash() {
831
923
  const root = await trashRoot();
@@ -853,9 +945,29 @@ export async function listTrash() {
853
945
  } catch {
854
946
  /* skip unreadable directories */
855
947
  }
948
+ let meta = sidecar !== null && sidecar.meta !== null && typeof sidecar.meta === "object" ? sidecar.meta : null;
949
+ if (meta === null) {
950
+ /* One decode per entry, then cached in its sidecar so the list stays cheap. */
951
+ const computed = await trashEntryMetadata(directory);
952
+ if (computed !== null) {
953
+ meta = computed;
954
+ await writeTrashSidecar(directory, {
955
+ sessionId: sidecar !== null && typeof sidecar.sessionId === "string" ? sidecar.sessionId : null,
956
+ cwd: sidecar !== null && typeof sidecar.cwd === "string" ? sidecar.cwd : null,
957
+ reason: sidecar !== null && typeof sidecar.reason === "string" ? sidecar.reason : "unknown",
958
+ at: sidecar !== null && typeof sidecar.at === "number" ? sidecar.at : 0,
959
+ meta: computed,
960
+ });
961
+ }
962
+ }
856
963
  results.push({
857
964
  name: entry.name,
858
965
  sizeBytes: size,
966
+ title: meta !== null && typeof meta.title === "string" ? meta.title : "",
967
+ turns: meta !== null && typeof meta.turns === "number" ? meta.turns : 0,
968
+ steps: meta !== null && typeof meta.steps === "number" ? meta.steps : 0,
969
+ tokens: meta !== null && typeof meta.tokens === "number" ? meta.tokens : 0,
970
+ lastAt: meta !== null && typeof meta.lastAt === "number" ? meta.lastAt : 0,
859
971
  sessionId: sidecar !== null && typeof sidecar.sessionId === "string" ? sidecar.sessionId : null,
860
972
  cwd: sidecar !== null && typeof sidecar.cwd === "string" ? sidecar.cwd : null,
861
973
  reason: sidecar !== null && typeof sidecar.reason === "string" ? sidecar.reason : "unknown",
@@ -1074,6 +1186,20 @@ export async function listArchivedSessions(ctx) {
1074
1186
  /* Last resort: the cache may have no record for this session at all. */
1075
1187
  if (title === "") title = await titleFromLog(ctx, sessionId);
1076
1188
 
1189
+ const outlineTurns = checkpointValue(checkpoint, "turnOutline");
1190
+ const turns = Array.isArray(outlineTurns?.turns) ? outlineTurns.turns.length : 0;
1191
+ /* Same facts the trash cards show, so both sections read alike. */
1192
+ const metaKey = `${sessionId}:${sizeBytes}`;
1193
+ let archiveMeta = archiveMetaCache.get(metaKey);
1194
+ if (archiveMeta === undefined) {
1195
+ try {
1196
+ const stats = await sessionStatistics(ctx, sessionId);
1197
+ archiveMeta = stats.ok === true ? { steps: stats.stats.steps, tokens: stats.stats.totals.totalTokens } : { steps: 0, tokens: 0 };
1198
+ } catch {
1199
+ archiveMeta = { steps: 0, tokens: 0 };
1200
+ }
1201
+ archiveMetaCache.set(metaKey, archiveMeta);
1202
+ }
1077
1203
  const listMeta = checkpointValue(checkpoint, "sessionListMetadata");
1078
1204
  let lastAt = typeof listMeta?.lastPromptAt === "number" ? listMeta.lastPromptAt : 0;
1079
1205
  if (lastAt === 0 && typeof header?.updatedAt === "number") lastAt = header.updatedAt;
@@ -1086,6 +1212,9 @@ export async function listArchivedSessions(ctx) {
1086
1212
  entries.push({
1087
1213
  sessionId,
1088
1214
  title,
1215
+ turns,
1216
+ steps: archiveMeta.steps,
1217
+ tokens: archiveMeta.tokens,
1089
1218
  cwd,
1090
1219
  createdAt: typeof header?.createdAt === "number" ? header.createdAt : 0,
1091
1220
  lastAt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.16.0",
3
+ "version": "0.18.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, and moving a session to another workspace.",
5
5
  "license": "MIT",
6
6
  "author": "chyxhtc",