dsh-ws-recency 0.18.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.
- package/README.md +14 -1
- package/client.js +268 -3
- package/index.js +89 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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.
|
|
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}",
|
|
@@ -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。",
|
|
@@ -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.",
|
|
@@ -1836,6 +1866,231 @@
|
|
|
1836
1866
|
}, t("menu.move"));
|
|
1837
1867
|
}
|
|
1838
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
|
+
|
|
1839
2094
|
/** Session "..." menu row: token statistics of that session. */
|
|
1840
2095
|
function StatsMenuItem(props) {
|
|
1841
2096
|
var Item = ui.MenuItemButton;
|
|
@@ -2652,6 +2907,16 @@
|
|
|
2652
2907
|
ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
|
|
2653
2908
|
return ctx.slots.register({
|
|
2654
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",
|
|
2655
2920
|
id: "ws-recency-stats",
|
|
2656
2921
|
order: 710,
|
|
2657
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.
|
|
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;
|
|
@@ -1306,6 +1308,84 @@ export async function forgetArchivedSession(ctx, sessionId) {
|
|
|
1306
1308
|
* `list`/`restore`/`purge` address trash entries by directory name; `archived`
|
|
1307
1309
|
* lists the archive set, and `unarchive`/`forget`/`delete` address sessions by id.
|
|
1308
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
|
+
|
|
1309
1389
|
export async function handleTrashListRequest(ctx, req, res) {
|
|
1310
1390
|
if ((req.method ?? "POST").toUpperCase() !== "POST") {
|
|
1311
1391
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
@@ -1481,6 +1561,14 @@ export function apply(ctx) {
|
|
|
1481
1561
|
}), "ws-recency: adopt route");
|
|
1482
1562
|
});
|
|
1483
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
|
+
|
|
1484
1572
|
webCtx.inject(["sessionPersistence", "workspaceRegistry", "sessions"], (trashCtx) => {
|
|
1485
1573
|
trashMounted = true;
|
|
1486
1574
|
webCtx.effect(() => server.register({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "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",
|