dsh-ws-recency 0.17.0 → 0.19.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 +16 -3
  2. package/client.js +279 -6
  3. package/index.js +106 -1
  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,7 +79,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
79
79
 
80
80
  - 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,并重新挂到对应工作区;
81
81
  - 「彻底删除」:真正删掉这份日志(二次确认);
82
- - 每条记录是一张**卡片**:标题、来源(已删除 / 移动前的旧副本 / 已归档)、轮次、步骤、token 总量、日志大小、时间、原目录;
82
+ - 每条记录是一张**卡片**:标题、来源(已删除 / 移动前的旧副本 / 已归档)、轮次、步骤、token 总量、日志大小、时间、原目录(归档的统计按日志大小缓存,第一次读完后不再重算);
83
83
  已删除会话的标题与统计在删除时就写进 `.wsr-trash.json`,旧条目则在第一次打开面板时从日志里补算并缓存;
84
84
  - 恢复/扫描/移动之后宿主会广播 `api-session/added`;面板与「扫描并刷新」都能重载页面(不重启应用)让侧栏立刻看到改动;
85
85
  - 移动操作留下的旧副本会标成「移动时的旧副本」,只允许彻底删除。
@@ -118,6 +118,19 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
118
118
 
119
119
  **风险与退路**:这是插件里唯一改写会话存储的操作。备份会保留,回滚 = 把备份目录移回 `sessions/<project>/<id>`。
120
120
 
121
+ ## 八、交接到新会话
122
+
123
+ 长期会话的上下文迟早会满,被动压缩往往比"换个新会话、带上交接"更差。交接做成两步:
124
+
125
+ 1. 会话「…」菜单 → **准备交接…**:插件把一段固定指令放进输入框(若放不进去就提供「复制指令」),你按回车发送;
126
+ 2. 当前会话的 AI 按指令输出一个 ```handoff 代码块——**只写文档路径和要点,不粘贴文档内容**;
127
+ 3. 插件每 2 秒轮询最新回复,抓到代码块后弹出预览(可直接编辑);
128
+ 4. 点 **确认交接,开新会话**:在当前工作区开一个新会话,把"开场要求 + 交接块"预填进输入框,你按回车就开始;点 **继续补充** 回到输入框继续打磨。
129
+
130
+ - 交接内容另存一份到 `~/.hypers-work/.wsr/handoff/<sessionId>-<时间>.md`;
131
+ - 新会话是草稿形态:侧栏显示为「新会话」,发出第一条消息后才转正;
132
+ - 没有公开的"自动发送"接口,所以最后一步是回车;开新会话与带入内容是自动的。
133
+
121
134
  ## 设置
122
135
 
123
136
  **设置 → 通用**:
@@ -154,7 +167,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
154
167
  或固定版本的预构建包:
155
168
 
156
169
  ```powershell
157
- dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.17.0/dsh-ws-recency-0.17.0.tgz
170
+ dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.19.0/dsh-ws-recency-0.19.0.tgz
158
171
  ```
159
172
 
160
173
  装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
package/client.js CHANGED
@@ -139,7 +139,9 @@
139
139
  ".wsr-trash-row{display:flex;align-items:flex-start;gap:8px;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04))}",
140
140
  ".wsr-footer-action{display:flex;box-sizing:border-box;flex:none;align-items:center;justify-content:flex-start;gap:8px;width:calc(100% + 4px);min-width:0;height:42px;margin:4px -2px;padding:0 10px 0 8px;border:0;border-radius:12px;background:transparent;color:var(--dsw-alias-label-primary);font-family:inherit;font-size:14px;line-height:22px;text-align:left;cursor:pointer}",
141
141
  ".wsr-footer-action:hover{background:var(--dsw-alias-interactive-bg-hover)}",
142
- ".wsr-page{display:flex;flex-direction:column;gap:10px;padding:16px 18px;min-width:0;box-sizing:border-box;height:100%;overflow:auto}",
142
+ ".wsr-page{display:flex;flex-direction:column;gap:10px;padding:16px 18px;min-width:0;box-sizing:border-box;height:100%;overflow:auto}",
143
+ ".wsr-handoff-status{font-size:12px;color:var(--dsw-alias-label-tertiary);line-height:1.6}",
144
+ ".wsr-handoff-text{width:100%;box-sizing:border-box;min-height:220px;max-height:46vh;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:1.6;padding:10px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-1,#1b1b1b);color:var(--dsw-alias-label-primary,#e6e6e6)}",
143
145
  ".wsr-page-head{display:flex;align-items:center;gap:8px}",
144
146
  ".wsr-page-heading{flex:1;font-size:14px;font-weight:600;color:var(--dsw-alias-label-primary)}",
145
147
  ".wsr-page-list{display:flex;flex-direction:column;gap:6px}",
@@ -222,7 +224,7 @@
222
224
  var ZH = {
223
225
  "settings.title": "\u5386\u53f2\u6298\u53e0\u5929\u6570",
224
226
  "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",
225
- "settings.exempt": "\u9009\u4e2d / \u8fd0\u884c\u4e2d / \u7b49\u5f85\u5904\u7406\u7684\u4f1a\u8bdd\u4e0d\u6298\u53e0",
227
+ "settings.exempt": "选中 / 运行中 / 等待处理 / 标记跟进的会话不折叠",
226
228
  "fold.show": "\u5c55\u5f00\u5386\u53f2 {n}",
227
229
  "fold.hide": "\u6536\u8d77\u5386\u53f2",
228
230
  "color.title": "\u989c\u8272\u4e0e\u8ddf\u8fdb\u6807\u8bb0",
@@ -259,7 +261,21 @@
259
261
  "stats.agentDetail": "主 agent 构成:思考 {reasoning} · 回复 {text} · 用户消息 {user} · 系统提示 {system}",
260
262
  "stats.diagnose.unmounted": "\n\n(宿主半已加载,但统计路由没挂上——重启应用再试)",
261
263
  "stats.diagnose.noHost": "\n\n(宿主半未加载:需要重启应用加载新版本)",
262
- "menu.move": "移动到工作区…",
264
+ "menu.move": "移动到工作区…",
265
+ "menu.handoff": "准备交接…",
266
+ "handoff.title": "会话交接",
267
+ "handoff.note": "交接指令已经放进输入框(或点「复制指令」自己粘),发送后我在这里等 AI 写出交接块;抓到以后可以直接开到新会话。",
268
+ "handoff.instruction": "我要把这个会话交接给一个新会话继续推进。请按下面的要求输出一份交接说明,写进一个 ```handoff 代码块里,我会原样交给新会话:\n\n1. 只给文档路径和一句话说明「读它为什么」,不要粘贴文档内容;\n2. 文档按重要性排序,标注哪些必读、哪些按需;\n3. 包含:目标、当前进度、尚未完成与下一步、关键决策与约束、踩过的坑、验证方式;\n4. 交接正文控制在 400 字以内(文档引用除外)。",
269
+ "handoff.inserted": "交接指令已放进输入框,按回车发送;我会自动抓取回复。",
270
+ "handoff.copyHint": "没能直接写入输入框,请点「复制指令」再粘贴到输入框发送。",
271
+ "handoff.copy": "复制指令",
272
+ "handoff.waiting": "等待 AI 写出交接块…({n} 秒)",
273
+ "handoff.found": "已抓到交接块,确认后会在当前工作区开一个新会话并把它带过去。",
274
+ "handoff.confirm": "确认交接,开新会话",
275
+ "handoff.more": "继续补充",
276
+ "handoff.noService": "没能自动开新会话,交接内容已复制到剪贴板,手动新建会话粘贴即可。",
277
+ "handoff.preamble": "以下是一个会话交接说明,来自上一个会话。请先按「文档引用」逐份阅读文档,再结合要点接续工作;已经完成的部分不要重做。",
278
+ "handoff.footnote": "交接内容会另存一份到 .wsr/handoff/,方便追溯。",
263
279
  "move.title": "移动到工作区",
264
280
  "move.warning": "只移动会话本身:它在旧工作区里创建或修改的文件不会跟着走,仍留在原目录。",
265
281
  "move.note": "会话属于哪个工作区,由它创建时的目录决定;移动会改写会话记录的 cwd,把日志搬到新工作区目录,旧日志备份在 .trash/ws-recency。",
@@ -328,7 +344,7 @@
328
344
  var EN = {
329
345
  "settings.title": "Fold history after (days)",
330
346
  "settings.description": "Sessions with no update for this many days are folded; a workspace older than that shows as a bare header.",
331
- "settings.exempt": "Never fold the selected / running / waiting session",
347
+ "settings.exempt": "Never fold the selected, running, waiting or follow-up session",
332
348
  "fold.show": "Show history ({n})",
333
349
  "fold.hide": "Hide history",
334
350
  "color.title": "Colors and follow-up marks",
@@ -365,7 +381,21 @@
365
381
  "stats.agentDetail": "Agent composition: reasoning {reasoning} \u00b7 reply {text} \u00b7 user messages {user} \u00b7 system prompt {system}",
366
382
  "stats.diagnose.unmounted": "\n\n(the host half is loaded but the statistics route did not mount - restart the app and retry)",
367
383
  "stats.diagnose.noHost": "\n\n(the host half is not loaded: restart the app to pick up the new version)",
368
- "menu.move": "Move to workspace\u2026",
384
+ "menu.move": "Move to workspace\u2026",
385
+ "menu.handoff": "Prepare handoff\u2026",
386
+ "handoff.title": "Session handoff",
387
+ "handoff.note": "The instruction is in the composer (or copy it yourself). Once you send it I watch for the handoff block and can carry it into a fresh Session.",
388
+ "handoff.instruction": "I am handing this session over to a new one. Please answer with a handoff note inside a ```handoff code block, which I will pass on verbatim:\n\n1. Reference documents by path with one line on why to read them; never paste document contents.\n2. Order them by importance and mark which are required and which are optional.\n3. Cover: goal, current progress, remaining work and next step, key decisions and constraints, pitfalls, and how to verify.\n4. Keep the note under 400 words (references excluded).",
389
+ "handoff.inserted": "Instruction placed in the composer; press Enter and I will pick up the reply.",
390
+ "handoff.copyHint": "Could not write into the composer; copy the instruction and paste it yourself.",
391
+ "handoff.copy": "Copy instruction",
392
+ "handoff.waiting": "Waiting for the handoff block… ({n}s)",
393
+ "handoff.found": "Handoff found. Confirming opens a new Session in this workspace with it carried over.",
394
+ "handoff.confirm": "Confirm and open new Session",
395
+ "handoff.more": "Keep refining",
396
+ "handoff.noService": "Could not open a Session automatically; the handoff was copied to the clipboard.",
397
+ "handoff.preamble": "Below is a handoff note from the previous Session. Read the referenced documents first, then continue from the notes; do not redo what is already done.",
398
+ "handoff.footnote": "A copy is saved under .wsr/handoff/ for later reference.",
369
399
  "move.title": "Move to workspace",
370
400
  "move.warning": "Only the session moves: files it created or changed in the old workspace stay where they are.",
371
401
  "move.note": "A session belongs to the workspace of the directory it was created in. Moving rewrites the stored cwd, relocates the log and keeps the old one as a backup in .trash/ws-recency.",
@@ -758,7 +788,13 @@
758
788
  var updated = updatedAtOf(row, sessions);
759
789
  var stale = updated !== null && updated < cutoff;
760
790
  var blank = isBlankRow(row, sessions);
761
- var exempt = settings.keepActive && (isActiveRow(row) || isSelectedRow(row));
791
+ /* "Needs follow-up" means "I still owe this one an answer": hiding it
792
+ behind a fold defeats the mark, so it is exempt like a running row. */
793
+ var marked = sessionIdOf(row);
794
+ var flagged = marked !== null && settings.followUps !== null
795
+ && typeof settings.followUps === "object"
796
+ && settings.followUps[marked] !== undefined;
797
+ var exempt = flagged || (settings.keepActive && (isActiveRow(row) || isSelectedRow(row)));
762
798
  var hide = !expanded && stale && !exempt && !blank;
763
799
  if (hide) {
764
800
  if (row.getAttribute(HIDDEN_ATTR) !== "true") row.setAttribute(HIDDEN_ATTR, "true");
@@ -1830,6 +1866,231 @@
1830
1866
  }, t("menu.move"));
1831
1867
  }
1832
1868
 
1869
+ /* ------------------------------ handoff ------------------------------ */
1870
+
1871
+ var handoffTimer = null;
1872
+ var handoffPanelSession = null;
1873
+
1874
+ /** The instruction the user sends to the current Session. */
1875
+ function handoffInstruction() {
1876
+ return t("handoff.instruction");
1877
+ }
1878
+
1879
+ /** Write text into the composer; returns false when there is no editor. */
1880
+ function insertIntoComposer(text) {
1881
+ if (typeof document === "undefined" || typeof text !== "string") return false;
1882
+ var seat = typeof document.querySelector === "function" ? document.querySelector("[data-composer-seat]") : null;
1883
+ if (seat === null || seat === undefined) return false;
1884
+ var editor = null;
1885
+ try { editor = seat.querySelector('[contenteditable="true"]'); } catch (error) { editor = null; }
1886
+ if (editor === null || editor === undefined) {
1887
+ try { editor = seat.querySelector("textarea"); } catch (error) { editor = null; }
1888
+ }
1889
+ if (editor === null || editor === undefined) return false;
1890
+ try {
1891
+ if (typeof editor.focus === "function") editor.focus();
1892
+ if (editor.tagName === "TEXTAREA" || editor.tagName === "INPUT") {
1893
+ editor.value = text;
1894
+ editor.dispatchEvent(new window.Event("input", { bubbles: true }));
1895
+ return true;
1896
+ }
1897
+ var selection = typeof window.getSelection === "function" ? window.getSelection() : null;
1898
+ if (selection !== null && typeof document.createRange === "function") {
1899
+ var range = document.createRange();
1900
+ range.selectNodeContents(editor);
1901
+ range.collapse(false);
1902
+ selection.removeAllRanges();
1903
+ selection.addRange(range);
1904
+ }
1905
+ if (typeof document.execCommand === "function" && document.execCommand("insertText", false, text)) return true;
1906
+ editor.textContent = text;
1907
+ editor.dispatchEvent(new window.Event("input", { bubbles: true }));
1908
+ return true;
1909
+ } catch (error) {
1910
+ return false;
1911
+ }
1912
+ }
1913
+
1914
+ function copyText(text) {
1915
+ try {
1916
+ if (navigator !== undefined && navigator.clipboard !== undefined && typeof navigator.clipboard.writeText === "function") {
1917
+ navigator.clipboard.writeText(text);
1918
+ return true;
1919
+ }
1920
+ } catch (error) {
1921
+ /* fall through */
1922
+ }
1923
+ return false;
1924
+ }
1925
+
1926
+ /** Pull the fenced block out of an assistant reply. */
1927
+ function handoffBlockOf(text) {
1928
+ if (typeof text !== "string") return "";
1929
+ var match = /```handoff[ \t]*\r?\n([\s\S]*?)```/i.exec(text);
1930
+ if (match !== null) return match[1].trim();
1931
+ var loose = /```[ \t]*\r?\n([\s\S]*?)```/.exec(text);
1932
+ if (loose !== null && loose[1].indexOf("#") !== -1) return loose[1].trim();
1933
+ return "";
1934
+ }
1935
+
1936
+ function closeHandoffPanel() {
1937
+ if (handoffTimer !== null && typeof window.clearTimeout === "function") window.clearTimeout(handoffTimer);
1938
+ handoffTimer = null;
1939
+ handoffPanelSession = null;
1940
+ closeStatsPanel();
1941
+ }
1942
+
1943
+ /**
1944
+ * The handoff flow: seed the instruction, watch for the reply, then open a
1945
+ * fresh Session in the same workspace with the handoff carried over.
1946
+ */
1947
+ function openHandoffPanel(sessionId) {
1948
+ if (typeof document === "undefined") return;
1949
+ closeStatsPanel();
1950
+ handoffPanelSession = sessionId;
1951
+
1952
+ var backdrop = statsDiv("wsr-modal-backdrop");
1953
+ var panel = statsDiv("wsr-modal");
1954
+ backdrop.appendChild(panel);
1955
+ var head = statsDiv("wsr-modal-head");
1956
+ head.appendChild(statsDiv("wsr-modal-title", t("handoff.title")));
1957
+ var close = document.createElement("button");
1958
+ close.type = "button";
1959
+ close.className = "wsr-modal-close";
1960
+ close.textContent = "\u00d7";
1961
+ close.addEventListener("click", closeHandoffPanel);
1962
+ head.appendChild(close);
1963
+ panel.appendChild(head);
1964
+
1965
+ var body = statsDiv("wsr-modal-body");
1966
+ panel.appendChild(body);
1967
+ body.appendChild(statsDiv("wsr-stats-note", t("handoff.note")));
1968
+
1969
+ var status = statsDiv("wsr-handoff-status", t("handoff.waiting", { n: 0 }));
1970
+ body.appendChild(status);
1971
+
1972
+ var preview = document.createElement("textarea");
1973
+ preview.className = "wsr-handoff-text";
1974
+ preview.setAttribute("data-wsr-handoff-text", "true");
1975
+ preview.style.display = "none";
1976
+ body.appendChild(preview);
1977
+
1978
+ var actions = statsDiv("wsr-trash-actions");
1979
+ var copy = document.createElement("button");
1980
+ copy.type = "button";
1981
+ copy.className = "wsr-btn";
1982
+ copy.textContent = t("handoff.copy");
1983
+ copy.addEventListener("click", function () {
1984
+ if (copyText(handoffInstruction())) status.textContent = t("handoff.inserted");
1985
+ });
1986
+ actions.appendChild(copy);
1987
+
1988
+ var more = document.createElement("button");
1989
+ more.type = "button";
1990
+ more.className = "wsr-btn";
1991
+ more.textContent = t("handoff.more");
1992
+ more.addEventListener("click", function () {
1993
+ preview.style.display = "none";
1994
+ baseline = replies;
1995
+ status.textContent = t("handoff.waiting", { n: 0 });
1996
+ insertIntoComposer(handoffInstruction());
1997
+ poll(0);
1998
+ });
1999
+ actions.appendChild(more);
2000
+
2001
+ var confirm = document.createElement("button");
2002
+ confirm.type = "button";
2003
+ confirm.className = "wsr-btn";
2004
+ confirm.disabled = true;
2005
+ confirm.style.display = "none";
2006
+ confirm.textContent = t("handoff.confirm");
2007
+ confirm.addEventListener("click", function () {
2008
+ var text = preview.value.trim();
2009
+ if (text === "") return;
2010
+ confirm.disabled = true;
2011
+ fetch("/ws-recency/handoff", {
2012
+ method: "POST",
2013
+ headers: { "content-type": "application/json" },
2014
+ body: JSON.stringify({ action: "save", sessionId: sessionId, text: text }),
2015
+ }).catch(function () { return null; }).then(function () {
2016
+ var owner = workspaceOfSession(sessionId);
2017
+ var workspaceId = owner === null ? undefined : owner.workspaceId;
2018
+ var service = data.service;
2019
+ var prompt = t("handoff.preamble") + "\n\n" + text;
2020
+ if (service !== null && service !== undefined && typeof service.startSession === "function") {
2021
+ try {
2022
+ service.startSession(workspaceId, { prompt: prompt, whenDraftExists: "replace" });
2023
+ closeHandoffPanel();
2024
+ return;
2025
+ } catch (error) {
2026
+ /* fall through to the clipboard */
2027
+ }
2028
+ }
2029
+ copyText(prompt);
2030
+ status.textContent = t("handoff.noService");
2031
+ });
2032
+ });
2033
+ actions.appendChild(confirm);
2034
+ body.appendChild(actions);
2035
+
2036
+ body.appendChild(statsDiv("wsr-stats-note", t("handoff.footnote")));
2037
+ document.body.appendChild(backdrop);
2038
+
2039
+ /* Seed the instruction: the user only presses Enter. */
2040
+ if (!insertIntoComposer(handoffInstruction())) {
2041
+ status.textContent = t("handoff.copyHint");
2042
+ } else {
2043
+ status.textContent = t("handoff.inserted");
2044
+ }
2045
+
2046
+ var baseline = 0;
2047
+ var replies = 0;
2048
+ var tries = 0;
2049
+ function poll(delay) {
2050
+ if (typeof window === "undefined") return;
2051
+ handoffTimer = window.setTimeout(function () {
2052
+ if (handoffPanelSession !== sessionId) return;
2053
+ fetch("/ws-recency/handoff", {
2054
+ method: "POST",
2055
+ headers: { "content-type": "application/json" },
2056
+ body: JSON.stringify({ action: "tail", sessionId: sessionId }),
2057
+ }).then(function (response) {
2058
+ return response.json().catch(function () { return null; });
2059
+ }).then(function (answer) {
2060
+ if (answer === null || answer.ok !== true) return;
2061
+ replies = typeof answer.replies === "number" ? answer.replies : 0;
2062
+ if (baseline === 0) baseline = replies > 0 ? replies - 1 : 0;
2063
+ tries += 1;
2064
+ var block = replies > baseline ? handoffBlockOf(answer.text) : "";
2065
+ if (block !== "") {
2066
+ preview.value = block;
2067
+ preview.style.display = "";
2068
+ confirm.style.display = "";
2069
+ confirm.disabled = false;
2070
+ status.textContent = t("handoff.found");
2071
+ return;
2072
+ }
2073
+ status.textContent = t("handoff.waiting", { n: tries * 2 });
2074
+ poll(2000);
2075
+ }).catch(function () {
2076
+ poll(4000);
2077
+ });
2078
+ }, delay);
2079
+ }
2080
+ poll(1500);
2081
+ }
2082
+
2083
+ /** Session "..." menu row: hand the work over to a fresh Session. */
2084
+ function HandoffMenuItem(props) {
2085
+ var Item = ui.MenuItemButton;
2086
+ if (typeof Item !== "function") return null;
2087
+ var Icon = ui.IconDataOutlineRegular;
2088
+ return h(Item, {
2089
+ icon: typeof Icon === "function" ? h(Icon, {}) : undefined,
2090
+ onSelect: function () { openHandoffPanel(props.sessionId); },
2091
+ }, t("menu.handoff"));
2092
+ }
2093
+
1833
2094
  /** Session "..." menu row: token statistics of that session. */
1834
2095
  function StatsMenuItem(props) {
1835
2096
  var Item = ui.MenuItemButton;
@@ -2249,6 +2510,8 @@
2249
2510
  (function (entry) {
2250
2511
  var chips = [];
2251
2512
  if (entry.turns > 0) chips.push(t("trash.turns") + " " + entry.turns);
2513
+ if (entry.steps > 0) chips.push(t("trash.steps") + " " + entry.steps);
2514
+ if (entry.tokens > 0) chips.push(formatTokens(entry.tokens) + " tokens");
2252
2515
  chips.push(formatBytes(entry.sizeBytes));
2253
2516
  var when = formatWhen(entry.lastAt !== 0 ? entry.lastAt : entry.createdAt);
2254
2517
  if (when !== "") chips.push(when);
@@ -2644,6 +2907,16 @@
2644
2907
  ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
2645
2908
  return ctx.slots.register({
2646
2909
  name: "sidebar.workspaces.session.menu.item",
2910
+ id: "ws-recency-handoff",
2911
+ order: 685,
2912
+ store: prefs,
2913
+ locale: NS,
2914
+ }, HandoffMenuItem);
2915
+ });
2916
+
2917
+ ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
2918
+ return ctx.slots.register({
2919
+ name: "sidebar.workspaces.session.menu.item",
2647
2920
  id: "ws-recency-stats",
2648
2921
  order: 710,
2649
2922
  store: prefs,
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.17.0";
35
+ export const HOST_VERSION = "0.19.0";
36
36
 
37
37
  /**
38
38
  * Exact routes the client half calls. Registered on the bare web server, so they
@@ -45,6 +45,8 @@ export const MOVE_SESSION_PATH = "/ws-recency/session-move";
45
45
  export const ADOPT_SESSION_PATH = "/ws-recency/session-adopt";
46
46
  export const TRASH_LIST_PATH = "/ws-recency/trash";
47
47
 
48
+ export const HANDOFF_PATH = "/ws-recency/handoff";
49
+
48
50
  const TRASH_SIDECAR = ".wsr-trash.json";
49
51
 
50
52
  const STOP_SETTLE_MS = 500;
@@ -274,6 +276,9 @@ export async function handleTrashRequest(ctx, req, res) {
274
276
  const STATS_CACHE_MS = 10 * 1000;
275
277
  const statsCache = new Map();
276
278
 
279
+ /** Archived sessions keep their log, so their card facts never change: key by size. */
280
+ const archiveMetaCache = new Map();
281
+
277
282
  /** bytes/4 per Latin character, ~1 token per CJK character. */
278
283
  export function estimateTokens(text) {
279
284
  if (typeof text !== "string" || text === "") return 0;
@@ -1185,6 +1190,18 @@ export async function listArchivedSessions(ctx) {
1185
1190
 
1186
1191
  const outlineTurns = checkpointValue(checkpoint, "turnOutline");
1187
1192
  const turns = Array.isArray(outlineTurns?.turns) ? outlineTurns.turns.length : 0;
1193
+ /* Same facts the trash cards show, so both sections read alike. */
1194
+ const metaKey = `${sessionId}:${sizeBytes}`;
1195
+ let archiveMeta = archiveMetaCache.get(metaKey);
1196
+ if (archiveMeta === undefined) {
1197
+ try {
1198
+ const stats = await sessionStatistics(ctx, sessionId);
1199
+ archiveMeta = stats.ok === true ? { steps: stats.stats.steps, tokens: stats.stats.totals.totalTokens } : { steps: 0, tokens: 0 };
1200
+ } catch {
1201
+ archiveMeta = { steps: 0, tokens: 0 };
1202
+ }
1203
+ archiveMetaCache.set(metaKey, archiveMeta);
1204
+ }
1188
1205
  const listMeta = checkpointValue(checkpoint, "sessionListMetadata");
1189
1206
  let lastAt = typeof listMeta?.lastPromptAt === "number" ? listMeta.lastPromptAt : 0;
1190
1207
  if (lastAt === 0 && typeof header?.updatedAt === "number") lastAt = header.updatedAt;
@@ -1198,6 +1215,8 @@ export async function listArchivedSessions(ctx) {
1198
1215
  sessionId,
1199
1216
  title,
1200
1217
  turns,
1218
+ steps: archiveMeta.steps,
1219
+ tokens: archiveMeta.tokens,
1201
1220
  cwd,
1202
1221
  createdAt: typeof header?.createdAt === "number" ? header.createdAt : 0,
1203
1222
  lastAt,
@@ -1289,6 +1308,84 @@ export async function forgetArchivedSession(ctx, sessionId) {
1289
1308
  * `list`/`restore`/`purge` address trash entries by directory name; `archived`
1290
1309
  * lists the archive set, and `unarchive`/`forget`/`delete` address sessions by id.
1291
1310
  */
1311
+ /**
1312
+ * Handoff support: the newest assistant reply, and a place to park the document.
1313
+ *
1314
+ * The Client cannot read a Session log, so it polls this route while the current
1315
+ * Session writes its handoff. Saving is a plain markdown file under the DSH home,
1316
+ * which keeps a record the next Session can be pointed at.
1317
+ */
1318
+ export async function handleHandoffRequest(ctx, req, res) {
1319
+ if ((req.method ?? "POST").toUpperCase() !== "POST") {
1320
+ sendJson(res, 405, { ok: false, error: "method not allowed" });
1321
+ return;
1322
+ }
1323
+ if (!loopbackOrigin(req)) {
1324
+ sendJson(res, 403, { ok: false, error: "origin not trusted" });
1325
+ return;
1326
+ }
1327
+ let body;
1328
+ try {
1329
+ body = await readJsonBody(req);
1330
+ } catch (error) {
1331
+ sendJson(res, 400, { ok: false, error: error instanceof Error ? error.message : String(error) });
1332
+ return;
1333
+ }
1334
+ const action = typeof body.action === "string" ? body.action : "tail";
1335
+
1336
+ if (action === "save") {
1337
+ const text = typeof body.text === "string" ? body.text : "";
1338
+ if (text.trim() === "") {
1339
+ sendJson(res, 400, { ok: false, error: "nothing to save" });
1340
+ return;
1341
+ }
1342
+ const sessionId = typeof body.sessionId === "string" ? body.sessionId : "session";
1343
+ const home = await dshHome();
1344
+ const directory = join(home, ".wsr", "handoff");
1345
+ try {
1346
+ await mkdir(directory, { recursive: true });
1347
+ const file = join(directory, `${sessionId}-${Date.now()}.md`);
1348
+ await writeFile(file, text, "utf8");
1349
+ sendJson(res, 200, { ok: true, path: file });
1350
+ } catch (error) {
1351
+ sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
1352
+ }
1353
+ return;
1354
+ }
1355
+
1356
+ const sessionId = typeof body.sessionId === "string" ? body.sessionId : "";
1357
+ if (sessionId === "") {
1358
+ sendJson(res, 400, { ok: false, error: "sessionId is required" });
1359
+ return;
1360
+ }
1361
+ let events;
1362
+ try {
1363
+ events = await readSessionEvents(ctx, sessionId);
1364
+ } catch (error) {
1365
+ sendJson(res, 200, { ok: false, error: error instanceof Error ? error.message : String(error) });
1366
+ return;
1367
+ }
1368
+ let text = "";
1369
+ let at = 0;
1370
+ let replies = 0;
1371
+ for (const event of events) {
1372
+ if (event === null || typeof event !== "object") continue;
1373
+ if (event.type !== "assistant/message") continue;
1374
+ replies += 1;
1375
+ const content = event.data?.message?.content ?? event.data?.content;
1376
+ const parts = [];
1377
+ for (const block of Array.isArray(content) ? content : []) {
1378
+ if (block !== null && typeof block === "object" && block.type === "text" && typeof block.text === "string") parts.push(block.text);
1379
+ }
1380
+ const joined = parts.join("\n").trim();
1381
+ if (joined !== "") {
1382
+ text = joined;
1383
+ at = typeof event.time === "number" ? event.time : 0;
1384
+ }
1385
+ }
1386
+ sendJson(res, 200, { ok: true, text, at, replies });
1387
+ }
1388
+
1292
1389
  export async function handleTrashListRequest(ctx, req, res) {
1293
1390
  if ((req.method ?? "POST").toUpperCase() !== "POST") {
1294
1391
  sendJson(res, 405, { ok: false, error: "method not allowed" });
@@ -1464,6 +1561,14 @@ export function apply(ctx) {
1464
1561
  }), "ws-recency: adopt route");
1465
1562
  });
1466
1563
 
1564
+ webCtx.inject(["sessionPersistence"], (handoffCtx) => {
1565
+ webCtx.effect(() => server.register({
1566
+ kind: "exact",
1567
+ path: HANDOFF_PATH,
1568
+ handler: (req, res) => handleHandoffRequest(handoffCtx, req, res),
1569
+ }), "ws-recency: handoff route");
1570
+ });
1571
+
1467
1572
  webCtx.inject(["sessionPersistence", "workspaceRegistry", "sessions"], (trashCtx) => {
1468
1573
  trashMounted = true;
1469
1574
  webCtx.effect(() => server.register({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.17.0",
3
+ "version": "0.19.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",