dsh-ws-recency 0.11.4 → 0.11.6
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 +2 -2
- package/client.js +65 -0
- package/index.js +97 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
88
88
|
3. 把旧日志目录移进 `.trash/ws-recency/<id>-move-<时间戳>`(既是备份,也腾出这个 id);
|
|
89
89
|
4. 用新 `cwd`、原 id 重建日志,再回放全部事件;
|
|
90
90
|
5. 校验新 header 的 cwd;
|
|
91
|
-
6. 把新 cwd 同步到工作区的 header 索引和这个会话的内存对象(否则宿主会用旧目录拒绝 attach),再 attach
|
|
91
|
+
6. 把新 cwd 同步到工作区的 header 索引和这个会话的内存对象(否则宿主会用旧目录拒绝 attach),再 attach 到目标(失败就回滚原目录),最后**按 workspace.json 的原始记录** detach 旧工作区——工作区自己的 `sessionIds` getter 会按 cwd 过滤,用它判断会漏掉要删的那一条,导致会话同时出现在两个分组;
|
|
92
92
|
7. 删投影缓存,让它按新路径重建。
|
|
93
93
|
|
|
94
94
|
**只移动会话**:对话框里明确提示——它在旧工作区里创建/修改的文件不会跟着走,仍留在原目录(附件与 rewind 快照按会话 id 存,不受影响)。
|
|
@@ -130,7 +130,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
|
|
|
130
130
|
或固定版本的预构建包:
|
|
131
131
|
|
|
132
132
|
```powershell
|
|
133
|
-
dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.11.
|
|
133
|
+
dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.11.6/dsh-ws-recency-0.11.6.tgz
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
|
package/client.js
CHANGED
|
@@ -214,6 +214,13 @@
|
|
|
214
214
|
"move.done": "已移动到「{workspace}」。若列表没刷新,切换一下工作区或重启应用。",
|
|
215
215
|
"move.doneLive": "\n\n这个会话刚才是打开状态:建议重启应用后再继续对话,避免它沿用旧的目录。",
|
|
216
216
|
"move.repaired": "已补登记到「{workspace}」:上一次移动只搬了日志、没登记工作区,这次把它补上了。",
|
|
217
|
+
"adopt.title": "补登记游离会话",
|
|
218
|
+
"adopt.description": "修复会话归属:把“目录属于某工作区却不在任何分组”的会话挂回去,并把仍挂在旧工作区分组里的重复归属清掉。",
|
|
219
|
+
"adopt.action": "扫描",
|
|
220
|
+
"adopt.working": "扫描中…",
|
|
221
|
+
"adopt.done": "已补登记 {n} 个会话。",
|
|
222
|
+
"adopt.cleaned": "清理了 {n} 处重复/失效的工作区归属。",
|
|
223
|
+
"adopt.failed": "扫描失败:",
|
|
217
224
|
"move.failed": "移动失败:",
|
|
218
225
|
"stats.chart": "消耗分布",
|
|
219
226
|
"stats.details.show": "显示明细 ▾",
|
|
@@ -269,6 +276,13 @@
|
|
|
269
276
|
"move.done": "Moved to \"{workspace}\". If the list has not refreshed, switch workspaces or restart the app.",
|
|
270
277
|
"move.doneLive": "\n\nThe session was open: restart the app before continuing it so it does not keep using the old directory.",
|
|
271
278
|
"move.repaired": "Registered in \"{workspace}\": the previous attempt moved the log without the bookkeeping, and this repaired it.",
|
|
279
|
+
"adopt.title": "Adopt unlisted sessions",
|
|
280
|
+
"adopt.description": "Repairs session membership: re-attaches sessions whose directory belongs to a workspace but are listed nowhere, and clears stale memberships that make one session appear twice.",
|
|
281
|
+
"adopt.action": "Scan",
|
|
282
|
+
"adopt.working": "Scanning\u2026",
|
|
283
|
+
"adopt.done": "Re-attached {n} session(s).",
|
|
284
|
+
"adopt.cleaned": " Cleared {n} stale membership(s).",
|
|
285
|
+
"adopt.failed": "Scan failed: ",
|
|
272
286
|
"move.failed": "Move failed: ",
|
|
273
287
|
"stats.chart": "Where the tokens went",
|
|
274
288
|
"stats.details.show": "Show details",
|
|
@@ -1567,6 +1581,47 @@
|
|
|
1567
1581
|
);
|
|
1568
1582
|
}
|
|
1569
1583
|
|
|
1584
|
+
/** Settings -> General: re-attach sessions that belong to no workspace. */
|
|
1585
|
+
function AdoptRow() {
|
|
1586
|
+
var result = react.useState("");
|
|
1587
|
+
var message = result[0];
|
|
1588
|
+
var setMessage = result[1];
|
|
1589
|
+
var run = function () {
|
|
1590
|
+
setMessage(t("adopt.working"));
|
|
1591
|
+
fetch("/ws-recency/session-adopt", { method: "POST", headers: { "content-type": "application/json" }, body: "{}" })
|
|
1592
|
+
.then(function (response) {
|
|
1593
|
+
return response.text().then(function (text) {
|
|
1594
|
+
var parsed = null;
|
|
1595
|
+
try { parsed = JSON.parse(text); } catch (error) { parsed = null; }
|
|
1596
|
+
return { status: response.status, text: text, json: parsed };
|
|
1597
|
+
});
|
|
1598
|
+
})
|
|
1599
|
+
.then(function (answer) {
|
|
1600
|
+
if (answer.json !== null && answer.json.ok === true) {
|
|
1601
|
+
var count = Array.isArray(answer.json.adopted) ? answer.json.adopted.length : 0;
|
|
1602
|
+
var cleaned = typeof answer.json.cleaned === "number" ? answer.json.cleaned : 0;
|
|
1603
|
+
var text = t("adopt.done", { n: count });
|
|
1604
|
+
if (cleaned > 0) text += t("adopt.cleaned", { n: cleaned });
|
|
1605
|
+
setMessage(text);
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
setMessage(t("adopt.failed") + (answer.json && answer.json.error ? answer.json.error : answer.text.slice(0, 120)));
|
|
1609
|
+
})
|
|
1610
|
+
.catch(function (error) {
|
|
1611
|
+
setMessage(t("adopt.failed") + (error && error.message ? error.message : error));
|
|
1612
|
+
});
|
|
1613
|
+
};
|
|
1614
|
+
return h("div", { className: "wsr-setRow" },
|
|
1615
|
+
h("div", { className: "wsr-setText" },
|
|
1616
|
+
h("div", { className: "wsr-setTitle" }, t("adopt.title")),
|
|
1617
|
+
h("div", { className: "wsr-setDesc" }, message === "" ? t("adopt.description") : message),
|
|
1618
|
+
),
|
|
1619
|
+
h("div", { className: "wsr-controls" },
|
|
1620
|
+
h("button", { type: "button", className: "wsr-step", onClick: run }, t("adopt.action")),
|
|
1621
|
+
),
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1570
1625
|
/** Settings -> General row: the global pinned section on/off. */
|
|
1571
1626
|
function PinSectionRow(props) {
|
|
1572
1627
|
var settings = props.useStore(function (state) { return state; });
|
|
@@ -1705,6 +1760,16 @@
|
|
|
1705
1760
|
}, ColorsRow);
|
|
1706
1761
|
});
|
|
1707
1762
|
|
|
1763
|
+
ctx.slots.inject("settings.general.item", function () {
|
|
1764
|
+
return ctx.slots.register({
|
|
1765
|
+
name: "settings.general.item",
|
|
1766
|
+
id: "ws-recency-adopt",
|
|
1767
|
+
order: 49,
|
|
1768
|
+
store: prefs,
|
|
1769
|
+
locale: NS,
|
|
1770
|
+
}, AdoptRow);
|
|
1771
|
+
});
|
|
1772
|
+
|
|
1708
1773
|
ctx.slots.inject("settings.general.item", function () {
|
|
1709
1774
|
return ctx.slots.register({
|
|
1710
1775
|
name: "settings.general.item",
|
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @module dsh-ws-recency
|
|
21
21
|
*/
|
|
22
|
-
import { mkdir, readdir, rename, rm, stat as statPath } from "node:fs/promises";
|
|
22
|
+
import { mkdir, readFile, readdir, rename, rm, stat as statPath } from "node:fs/promises";
|
|
23
23
|
import { dirname, join } from "node:path";
|
|
24
24
|
|
|
25
25
|
/** Cordis plugin name shown by the loader. */
|
|
@@ -36,6 +36,7 @@ export const TRASH_SESSION_PATH = "/ws-recency/session-trash";
|
|
|
36
36
|
export const STATS_SESSION_PATH = "/ws-recency/session-stats";
|
|
37
37
|
export const HEALTH_PATH = "/ws-recency/health";
|
|
38
38
|
export const MOVE_SESSION_PATH = "/ws-recency/session-move";
|
|
39
|
+
export const ADOPT_SESSION_PATH = "/ws-recency/session-adopt";
|
|
39
40
|
|
|
40
41
|
const STOP_SETTLE_MS = 500;
|
|
41
42
|
const MAX_BODY_BYTES = 16 * 1024;
|
|
@@ -439,6 +440,24 @@ export async function sessionStatistics(ctx, sessionId) {
|
|
|
439
440
|
}
|
|
440
441
|
}
|
|
441
442
|
|
|
443
|
+
/** Which workspaces list a session in the stored table (the registry view is filtered). */
|
|
444
|
+
async function rawWorkspaceMembership() {
|
|
445
|
+
try {
|
|
446
|
+
const home = await dshHome();
|
|
447
|
+
const raw = JSON.parse(await readFile(join(home, "storages", "workspace.json"), "utf8"));
|
|
448
|
+
const table = raw !== null && raw.tables !== undefined && raw.tables !== null ? raw.tables.workspaces : undefined;
|
|
449
|
+
if (table === undefined || table === null || typeof table !== "object") return null;
|
|
450
|
+
const map = new Map();
|
|
451
|
+
for (const [id, record] of Object.entries(table)) {
|
|
452
|
+
const ids = record !== null && Array.isArray(record.sessionIds) ? record.sessionIds : [];
|
|
453
|
+
map.set(id, { path: typeof record.path === "string" ? record.path : "", sessionIds: ids });
|
|
454
|
+
}
|
|
455
|
+
return map;
|
|
456
|
+
} catch {
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
442
461
|
/**
|
|
443
462
|
* Move one session into another workspace.
|
|
444
463
|
*
|
|
@@ -618,10 +637,15 @@ export async function moveSessionToWorkspace(ctx, sessionId, workspaceId) {
|
|
|
618
637
|
return { ok: false, error: `the workspace refused the attach: ${error instanceof Error ? error.message : String(error)}` };
|
|
619
638
|
}
|
|
620
639
|
|
|
640
|
+
/* Detach by the RAW record, not the filtered view: once the header carries the
|
|
641
|
+
new cwd, the old workspace's own `sessionIds` getter already hides the id, so
|
|
642
|
+
an "is it listed?" check would skip exactly the membership that has to go. */
|
|
621
643
|
const detached = [];
|
|
644
|
+
const raw = await rawWorkspaceMembership();
|
|
622
645
|
for (const workspace of workspaces) {
|
|
623
|
-
if (!Array.isArray(workspace.sessionIds) || !workspace.sessionIds.includes(sessionId)) continue;
|
|
624
646
|
if (workspace.id === target.id) continue;
|
|
647
|
+
const record = raw === null ? undefined : raw.get(workspace.id);
|
|
648
|
+
if (record !== undefined && !record.sessionIds.includes(sessionId)) continue;
|
|
625
649
|
try {
|
|
626
650
|
await workspace.detachSession(sessionId);
|
|
627
651
|
detached.push(workspace.id);
|
|
@@ -641,6 +665,72 @@ export async function moveSessionToWorkspace(ctx, sessionId, workspaceId) {
|
|
|
641
665
|
return { ok: true, workspace: target.id, path: targetPath, detached, backup, live: wasLive };
|
|
642
666
|
}
|
|
643
667
|
|
|
668
|
+
/**
|
|
669
|
+
* Re-attach sessions whose stored cwd already names a workspace but which are
|
|
670
|
+
* listed by none - the shape an aborted move leaves behind. Idempotent: it only
|
|
671
|
+
* ever adds memberships the registry's own validation accepts.
|
|
672
|
+
*/
|
|
673
|
+
export async function adoptOrphanSessions(ctx) {
|
|
674
|
+
const snapshots = await ctx.sessionPersistence.list();
|
|
675
|
+
const workspaces = ctx.workspaceRegistry.list();
|
|
676
|
+
const byPath = new Map();
|
|
677
|
+
for (const workspace of workspaces) byPath.set(workspace.path, workspace);
|
|
678
|
+
const adopted = [];
|
|
679
|
+
const raw = await rawWorkspaceMembership();
|
|
680
|
+
let cleaned = 0;
|
|
681
|
+
for (const snapshot of snapshots) {
|
|
682
|
+
const header = snapshot !== null && snapshot !== undefined ? snapshot.header : undefined;
|
|
683
|
+
if (header === undefined || header === null || typeof header.cwd !== "string" || typeof header.id !== "string") continue;
|
|
684
|
+
const target = byPath.get(header.cwd);
|
|
685
|
+
/* Stale memberships first: a workspace whose path is not this session's cwd
|
|
686
|
+
must not keep listing it - that is what puts one session in two groups. */
|
|
687
|
+
if (raw !== null) {
|
|
688
|
+
for (const workspace of workspaces) {
|
|
689
|
+
if (target !== undefined && workspace.id === target.id) continue;
|
|
690
|
+
const record = raw.get(workspace.id);
|
|
691
|
+
if (record === undefined || !record.sessionIds.includes(header.id)) continue;
|
|
692
|
+
try {
|
|
693
|
+
await workspace.detachSession(header.id);
|
|
694
|
+
cleaned += 1;
|
|
695
|
+
} catch {
|
|
696
|
+
/* leave it */
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (target === undefined) continue;
|
|
701
|
+
const record = raw === null ? undefined : raw.get(target.id);
|
|
702
|
+
/* Without the raw table, fall back to the registry's own (filtered) view. */
|
|
703
|
+
const physically = record !== undefined
|
|
704
|
+
? record.sessionIds.includes(header.id)
|
|
705
|
+
: Array.isArray(target.sessionIds) && target.sessionIds.includes(header.id);
|
|
706
|
+
if (physically) continue;
|
|
707
|
+
try {
|
|
708
|
+
await target.attachSession(header.id);
|
|
709
|
+
adopted.push(header.id);
|
|
710
|
+
} catch {
|
|
711
|
+
/* the registry refused it; leave it alone */
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return { ok: true, adopted, cleaned };
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** POST {} -> attach every session that belongs nowhere. */
|
|
718
|
+
export async function handleAdoptRequest(ctx, req, res) {
|
|
719
|
+
if ((req.method ?? "POST").toUpperCase() !== "POST") {
|
|
720
|
+
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (!loopbackOrigin(req)) {
|
|
724
|
+
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
sendJson(res, 200, await adoptOrphanSessions(ctx));
|
|
729
|
+
} catch (error) {
|
|
730
|
+
sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
644
734
|
/** POST { sessionId, workspaceId } -> move that session to another workspace. */
|
|
645
735
|
export async function handleMoveRequest(ctx, req, res) {
|
|
646
736
|
if ((req.method ?? "POST").toUpperCase() !== "POST") {
|
|
@@ -731,6 +821,11 @@ export function apply(ctx) {
|
|
|
731
821
|
path: MOVE_SESSION_PATH,
|
|
732
822
|
handler: (req, res) => handleMoveRequest(moveCtx, req, res),
|
|
733
823
|
}), "ws-recency: move route");
|
|
824
|
+
webCtx.effect(() => server.register({
|
|
825
|
+
kind: "exact",
|
|
826
|
+
path: ADOPT_SESSION_PATH,
|
|
827
|
+
handler: (req, res) => handleAdoptRequest(moveCtx, req, res),
|
|
828
|
+
}), "ws-recency: adopt route");
|
|
734
829
|
});
|
|
735
830
|
|
|
736
831
|
webCtx.inject(["sessionPersistence", "workspaceRegistry", "sessions"], (trashCtx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
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, per-session token statistics split by tool, and moving a session to another workspace.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chyxhtc",
|