dsh-ws-recency 0.27.1 → 0.29.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 +7 -5
- package/client.js +95 -25
- package/index.js +74 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,7 +80,8 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
80
80
|
|
|
81
81
|
**不是物理删除**:目录只是被改名搬走。每个条目在 `.trash/ws-recency/` 下带一份 `.wsr-trash.json`(会话 id、原 cwd、时间、来源),回收站面板会列出它们:
|
|
82
82
|
|
|
83
|
-
- 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id
|
|
83
|
+
- 「恢复」:按记录的 cwd 算回 `sessions/<project>/<id>/`,重新挂到对应工作区,最后摘掉删除时打上的归档标记;
|
|
84
|
+
- 删除会**保留归档标记**(原来没有的会补上):日志已经离开 `sessions/`,宿主的列表里没有它,而归档是唯一一个其它插件都认识的“已收起来”状态——dsh-context 之类的看板就是靠它把已删会话显示成不可点。恢复时摘标记、彻底删除时先摘标记再删文件(0.28.0 起);
|
|
84
85
|
- 「彻底删除」:真正删掉这份日志(二次确认);
|
|
85
86
|
- 每条记录是一张**卡片**:标题、来源(已删除 / 移动前的旧副本 / 已归档)、轮次、步骤、token 总量、日志大小、时间、原目录(归档的统计按日志大小缓存,第一次读完后不再重算);
|
|
86
87
|
已删除会话的标题与统计在删除时就写进 `.wsr-trash.json`,旧条目则在第一次打开面板时从日志里补算并缓存;
|
|
@@ -98,9 +99,10 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
98
99
|
- **消耗分布图**(按内容估算):主 agent 自己(思考 / 回复 / 用户消息 / 系统提示)vs 每个工具,每个来源一条带颜色的横条,按占用长度直观对比;色相由工具身份决定(常用工具人工指定,其余按名字哈希,跨会话稳定),明艳度随占比排名递减;
|
|
99
100
|
- **参数 / 结果两段**:每个工具那条横条拆成「参数」(淡色,模型自己写的命令 / 文件内容)和「结果」(实色,环境返回的内容),一眼看出贵在输入还是贵在输出。图例在图右上角;
|
|
100
101
|
- **「参数计入主 agent」开关**(设置 → 通用):工具参数严格说是模型写的,不属于工具消耗。打开后每个工具只算返回结果,参数量并入主 agent——实测一个 pwsh 偏重的会话,pwsh 从 37.6% 掉到约 20%,主 agent 从 40.4% 升到约 58%。表格里「参数」列仍在,只是显示为淡色并计入主 agent 那一行;
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
102
|
+
- **调用次数**:每条横条右侧带「N 次」,说明这个来源被调用了多少次(图上看不出次数);
|
|
103
|
+
- **主 agent 拆分**:横条下方一行,给出思考 / 回复 / 用户消息 / 系统提示各占多少;
|
|
104
|
+
- **两个 tab(0.29.0)**:摘要卡片常驻顶部,下面按「分布统计 / 放大归因」分页,打开时记住上次停留的 tab。原先的「明细」表只是把图上的数字再列一遍,已去掉——它独有的调用次数和 agent 拆分分别挪到了横条和图表下方;
|
|
105
|
+
- **放大成本 / 账单归因(0.25.0)**:账单 = 每步上下文之和,所以一块内容的真实成本不是它出现时的 token 数,而是「token × 之后还会被重读多少步」。放大归因页给出:每步上下文曲线(面积≈账单)、账单构成(工具结果 / 工具参数 / 主 agent / 用户 / 系统)、以及按内容块排序的放大排行——进入第几步、原始 token、重读次数、放大后 token、占整场账单的百分比,以及「压到 20% 可省多少」。单次 9k 的 read 在 350 步的会话里会放大成 300 万 token(约 3% 账单),这样小数字才能读出结论。压缩之后旧内容不再重读,放大窗口会从压缩点截断。曲线上的琥珀点标出上下文**涨得最陡的三步**,下面附一行「第 N 步上下文涨了 X(read 进来 Y)」——「哪一步开始放大」一眼就能看到,不用自己比 96 根柱子。
|
|
104
106
|
|
|
105
107
|
口径说明:prompt 的 token 是「整段上下文每一步都计费」,没法精确归属到某一条消息,所以「主 agent / 工具」的拆分是按内容长度估算(中文≈1 token/字,英文≈4 字符/token),用来比较占比;**总量是真的**。放大排行里的块大小同样是估算,但账单总量、每步上下文、放大倍数的分母都来自真实 usage。思维链通常不回传给模型,因此不计入放大排行。数据从会话日志算,跨重启也能看。大会话第一次打开约 1–2 秒(29MB 日志实测 1.2 秒),10 秒内重复打开走缓存。
|
|
106
108
|
|
|
@@ -199,7 +201,7 @@ dsh plugin --profile <profile> add github:chyxhtc/dsh-ws-recency
|
|
|
199
201
|
或固定版本的预构建包:
|
|
200
202
|
|
|
201
203
|
```powershell
|
|
202
|
-
dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.
|
|
204
|
+
dsh plugin --profile <profile> add https://github.com/chyxhtc/dsh-ws-recency/releases/download/v0.29.0/dsh-ws-recency-0.29.0.tgz
|
|
203
205
|
```
|
|
204
206
|
|
|
205
207
|
装完把 `dsh-ws-recency` 加进 `~/.hypers-work/profiles/<profile>/package.json` 的 `dsh.profile.bundles`,重启应用。
|
package/client.js
CHANGED
|
@@ -246,6 +246,7 @@
|
|
|
246
246
|
".wsr-chart-legend-text{white-space:nowrap}",
|
|
247
247
|
".wsr-chart-value{text-align:right;font-variant-numeric:tabular-nums}",
|
|
248
248
|
".wsr-chart-share{text-align:right;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
249
|
+
".wsr-chart-calls{text-align:right;color:var(--dsw-alias-label-tertiary);font-size:10px;font-variant-numeric:tabular-nums}",
|
|
249
250
|
".wsr-stats-details{display:flex;flex-direction:column;gap:8px}",
|
|
250
251
|
".wsr-stats-table{display:flex;flex-direction:column}",
|
|
251
252
|
".wsr-stats-row{display:grid;grid-template-columns:1.4fr .6fr .8fr .8fr .8fr .6fr;gap:6px;padding:6px 4px;border-bottom:.5px solid rgba(255,255,255,.06)}",
|
|
@@ -271,6 +272,10 @@
|
|
|
271
272
|
".wsr-context-chart{display:flex;align-items:flex-end;gap:2px;height:54px;padding-top:4px;border-bottom:.5px solid rgba(255,255,255,.08)}",
|
|
272
273
|
".wsr-context-bar{flex:1;min-width:1px;border-radius:1px 1px 0 0;background:linear-gradient(180deg,rgba(79,124,255,.9),rgba(79,124,255,.3))}",
|
|
273
274
|
".wsr-context-caption{font-size:10px;color:var(--dsw-alias-label-tertiary)}",
|
|
275
|
+
".wsr-context-jump{position:relative}",
|
|
276
|
+
".wsr-context-jump-dot{position:absolute;left:50%;top:-5px;width:5px;height:5px;margin-left:-2.5px;border-radius:50%;background:#d99a2b}",
|
|
277
|
+
".wsr-context-jumps{display:flex;flex-direction:column;gap:2px}",
|
|
278
|
+
".wsr-context-jump-row{font-size:11px;color:var(--dsw-alias-label-secondary)}",
|
|
274
279
|
".wsr-kind-legend{display:flex;flex-wrap:wrap;gap:10px}",
|
|
275
280
|
".wsr-kind{display:flex;align-items:center;gap:5px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
276
281
|
".wsr-kind-dot{width:8px;height:8px;border-radius:2px;flex:none}",
|
|
@@ -352,6 +357,7 @@
|
|
|
352
357
|
"stats.agent": "\u4e3b agent",
|
|
353
358
|
"stats.col.source": "\u6765\u6e90",
|
|
354
359
|
"stats.col.calls": "\u8c03\u7528",
|
|
360
|
+
"stats.callsShort": "{n} 次",
|
|
355
361
|
"stats.col.args": "\u53c2\u6570",
|
|
356
362
|
"stats.col.results": "\u7ed3\u679c",
|
|
357
363
|
"stats.col.total": "\u4f30\u7b97",
|
|
@@ -466,6 +472,8 @@
|
|
|
466
472
|
"stats.amplified.summary": "账单 {bill} token;可归因内容经重读放大后占 {share}({attributed})",
|
|
467
473
|
"stats.amplified.contextCaption": "每步上下文(面积≈账单):越早进入的内容被重读越多",
|
|
468
474
|
"stats.amplified.point": "第 {step} 步 · {context}",
|
|
475
|
+
"stats.amplified.jump": "第 {step} 步上下文涨了 {rise}",
|
|
476
|
+
"stats.amplified.jumpFrom": "({name} 进来 {tokens})",
|
|
469
477
|
"stats.amplified.meta": "第 {entry} 步进入 · {tokens} token × {remaining} 次重读",
|
|
470
478
|
"stats.amplified.whatIf": "若压到 20%,可省 {save}({share})",
|
|
471
479
|
"stats.amplified.empty": "没有可归因的放大内容(压缩后或旧日志可能缺失)",
|
|
@@ -519,6 +527,7 @@
|
|
|
519
527
|
"stats.agent": "main agent",
|
|
520
528
|
"stats.col.source": "source",
|
|
521
529
|
"stats.col.calls": "calls",
|
|
530
|
+
"stats.callsShort": "{n}x",
|
|
522
531
|
"stats.col.args": "args",
|
|
523
532
|
"stats.col.results": "results",
|
|
524
533
|
"stats.col.total": "estimate",
|
|
@@ -632,6 +641,8 @@
|
|
|
632
641
|
"stats.amplified.summary": "Bill {bill} tokens; attributable content amplifies to {share} ({attributed})",
|
|
633
642
|
"stats.amplified.contextCaption": "Context per step (area ≈ bill): earlier content is re-read more",
|
|
634
643
|
"stats.amplified.point": "step {step} · {context}",
|
|
644
|
+
"stats.amplified.jump": "step {step} grew by {rise}",
|
|
645
|
+
"stats.amplified.jumpFrom": "({name} brought {tokens})",
|
|
635
646
|
"stats.amplified.meta": "entered at step {entry} · {tokens} tokens × {remaining} re-reads",
|
|
636
647
|
"stats.amplified.whatIf": "at 20%, saves {save} ({share})",
|
|
637
648
|
"stats.amplified.empty": "No amplifiable content (compacted or older logs may lack it)",
|
|
@@ -1963,6 +1974,12 @@
|
|
|
1963
1974
|
line.appendChild(track);
|
|
1964
1975
|
line.appendChild(statsDiv("wsr-chart-value", formatTokens(entry.value)));
|
|
1965
1976
|
line.appendChild(statsDiv("wsr-chart-share", formatShare(entry.share)));
|
|
1977
|
+
/* The count the chart cannot draw: a bar says how heavy a source is,
|
|
1978
|
+
the call count says how often it got there. The details table used to
|
|
1979
|
+
be the only place for it. */
|
|
1980
|
+
if (typeof entry.calls === "number" && entry.calls > 0) {
|
|
1981
|
+
line.appendChild(statsDiv("wsr-chart-calls", t("stats.callsShort", { n: String(entry.calls) })));
|
|
1982
|
+
}
|
|
1966
1983
|
return line;
|
|
1967
1984
|
}
|
|
1968
1985
|
|
|
@@ -2046,6 +2063,49 @@
|
|
|
2046
2063
|
* block's tokens times the number of later steps that re-read it. The
|
|
2047
2064
|
* host half computes that attribution; this only draws it.
|
|
2048
2065
|
*/
|
|
2066
|
+
/** The three steepest rises in the context curve, with the block behind each. */
|
|
2067
|
+
function contextJumps(amplified) {
|
|
2068
|
+
var series = Array.isArray(amplified.series) ? amplified.series : [];
|
|
2069
|
+
var blocks = Array.isArray(amplified.blocks) ? amplified.blocks : [];
|
|
2070
|
+
var rises = [];
|
|
2071
|
+
for (var i = 1; i < series.length; i += 1) {
|
|
2072
|
+
var rise = Number(series[i].context) - Number(series[i - 1].context);
|
|
2073
|
+
if (rise > 0) rises.push({ step: Number(series[i].step), rise: rise });
|
|
2074
|
+
}
|
|
2075
|
+
rises.sort(function (a, b) { return b.rise - a.rise; });
|
|
2076
|
+
var picked = [];
|
|
2077
|
+
for (var r = 0; r < rises.length && picked.length < 3; r += 1) {
|
|
2078
|
+
var rise2 = rises[r];
|
|
2079
|
+
/* Two markers next to each other would read as one long jump; keep
|
|
2080
|
+
the bars they sit on apart so each mark stays a single step. */
|
|
2081
|
+
var close = false;
|
|
2082
|
+
for (var p = 0; p < picked.length; p += 1) {
|
|
2083
|
+
if (Math.abs(picked[p].step - rise2.step) < Math.max(2, Math.round(series.length / 10))) close = true;
|
|
2084
|
+
}
|
|
2085
|
+
if (close) continue;
|
|
2086
|
+
/* The entering block: the biggest one whose entry step is this one,
|
|
2087
|
+
or (downsampled curves) the last entry at or before it. */
|
|
2088
|
+
var best = null;
|
|
2089
|
+
for (var b = 0; b < blocks.length; b += 1) {
|
|
2090
|
+
var block = blocks[b];
|
|
2091
|
+
if (Number(block.entry) > rise2.step) continue;
|
|
2092
|
+
if (best === null || Number(block.entry) > Number(best.entry)) best = block;
|
|
2093
|
+
}
|
|
2094
|
+
var label = t("stats.amplified.jump", {
|
|
2095
|
+
step: String(rise2.step),
|
|
2096
|
+
rise: formatTokens(rise2.rise),
|
|
2097
|
+
});
|
|
2098
|
+
if (best !== null && Number(best.entry) === rise2.step) {
|
|
2099
|
+
label += " " + t("stats.amplified.jumpFrom", {
|
|
2100
|
+
name: best.kind === "tool" ? String(best.name) : t("stats.agent"),
|
|
2101
|
+
tokens: formatTokens(best.tokens),
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
picked.push({ step: rise2.step, rise: rise2.rise, label: label });
|
|
2105
|
+
}
|
|
2106
|
+
return picked;
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2049
2109
|
function buildAmplified(stats) {
|
|
2050
2110
|
var amplified = stats.amplified;
|
|
2051
2111
|
if (amplified === null || amplified === undefined || !Array.isArray(amplified.series)) return null;
|
|
@@ -2067,14 +2127,37 @@
|
|
|
2067
2127
|
if (Number(series[i].context) > largest) largest = Number(series[i].context);
|
|
2068
2128
|
}
|
|
2069
2129
|
var chart = statsDiv("wsr-context-chart");
|
|
2130
|
+
/* Mark the steps where the window grew the most. A single read of a
|
|
2131
|
+
large file shows up here as one tall jump, which is the question the
|
|
2132
|
+
whole amplified view exists to answer, so the jump gets a marker
|
|
2133
|
+
instead of leaving the reader to compare 96 bars by eye. */
|
|
2134
|
+
var jumps = contextJumps(amplified);
|
|
2135
|
+
var jumpByStep = {};
|
|
2136
|
+
for (var jj = 0; jj < jumps.length; jj += 1) jumpByStep[jumps[jj].step] = jumps[jj];
|
|
2070
2137
|
for (var j = 0; j < series.length; j += 1) {
|
|
2071
2138
|
var bar = statsDiv("wsr-context-bar");
|
|
2072
2139
|
bar.style.height = Math.max(2, Math.round((Number(series[j].context) / largest) * 100)) + "%";
|
|
2073
|
-
|
|
2140
|
+
var jump = jumpByStep[Number(series[j].step)];
|
|
2141
|
+
if (jump !== undefined) {
|
|
2142
|
+
bar.className = "wsr-context-bar wsr-context-jump";
|
|
2143
|
+
bar.setAttribute("data-wsr-jump", String(jump.step));
|
|
2144
|
+
bar.setAttribute("title", jump.label);
|
|
2145
|
+
var marker = statsDiv("wsr-context-jump-dot");
|
|
2146
|
+
bar.appendChild(marker);
|
|
2147
|
+
} else {
|
|
2148
|
+
bar.setAttribute("title", t("stats.amplified.point", { step: String(series[j].step), context: formatTokens(series[j].context) }));
|
|
2149
|
+
}
|
|
2074
2150
|
chart.appendChild(bar);
|
|
2075
2151
|
}
|
|
2076
2152
|
section.appendChild(chart);
|
|
2077
2153
|
section.appendChild(statsDiv("wsr-context-caption", t("stats.amplified.contextCaption")));
|
|
2154
|
+
if (jumps.length > 0) {
|
|
2155
|
+
var jumpList = statsDiv("wsr-context-jumps");
|
|
2156
|
+
for (var jl = 0; jl < jumps.length; jl += 1) {
|
|
2157
|
+
jumpList.appendChild(statsDiv("wsr-context-jump-row", jumps[jl].label));
|
|
2158
|
+
}
|
|
2159
|
+
section.appendChild(jumpList);
|
|
2160
|
+
}
|
|
2078
2161
|
|
|
2079
2162
|
var kinds = amplified.byKind || [];
|
|
2080
2163
|
if (kinds.length > 0) {
|
|
@@ -2189,6 +2272,7 @@
|
|
|
2189
2272
|
share: shareOf(value),
|
|
2190
2273
|
hue: sourceHue(tool.name),
|
|
2191
2274
|
rank: j + 1,
|
|
2275
|
+
calls: tool.calls || 0,
|
|
2192
2276
|
args: args,
|
|
2193
2277
|
split: mode !== "agent" && args > 0 && results > 0,
|
|
2194
2278
|
});
|
|
@@ -2205,33 +2289,16 @@
|
|
|
2205
2289
|
for (var k = 0; k < entries.length; k += 1) chart.appendChild(chartBar(entries[k], largest));
|
|
2206
2290
|
var distributionPanel = statsDiv("wsr-stats-panel");
|
|
2207
2291
|
distributionPanel.appendChild(chart);
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
var table = statsDiv("wsr-stats-table");
|
|
2214
|
-
var head = document.createElement("div");
|
|
2215
|
-
head.className = "wsr-stats-row wsr-stats-head";
|
|
2216
|
-
var columns = ["stats.col.source", "stats.col.calls", "stats.col.args", "stats.col.results", "stats.col.total", "stats.col.share"];
|
|
2217
|
-
for (var n = 0; n < columns.length; n += 1) head.appendChild(statsDiv("wsr-td", t(columns[n])));
|
|
2218
|
-
table.appendChild(head);
|
|
2219
|
-
table.appendChild(statsRow(t("stats.agent"), stats.steps, null, null, agentValue, shareOf(agentValue)));
|
|
2220
|
-
for (var q = 0; q < tools.length; q += 1) {
|
|
2221
|
-
var toolRow = tools[q];
|
|
2222
|
-
var toolArgs = toolRow.args || 0;
|
|
2223
|
-
var toolResults = toolRow.results || 0;
|
|
2224
|
-
var toolValue = mode === "agent" ? toolResults : (toolRow.total || toolArgs + toolResults);
|
|
2225
|
-
table.appendChild(statsRow(toolRow.name, toolRow.calls, toolArgs, toolResults, toolValue, shareOf(toolValue), mode === "agent"));
|
|
2226
|
-
}
|
|
2227
|
-
detailsPanel.appendChild(table);
|
|
2228
|
-
detailsPanel.appendChild(statsDiv("wsr-stats-detail", t("stats.agentDetail", {
|
|
2292
|
+
/* The agent's own split is the one number the bars cannot show: the
|
|
2293
|
+
rows for tools already name their source, so a whole table was
|
|
2294
|
+
repeating the chart. It sits under the chart instead. */
|
|
2295
|
+
distributionPanel.appendChild(statsDiv("wsr-stats-detail", t("stats.agentDetail", {
|
|
2229
2296
|
reasoning: formatTokens(agent.reasoning),
|
|
2230
2297
|
text: formatTokens(agent.text),
|
|
2231
2298
|
user: formatTokens(agent.user),
|
|
2232
2299
|
system: formatTokens(agent.system),
|
|
2233
2300
|
})));
|
|
2234
|
-
|
|
2301
|
+
distributionPanel.appendChild(statsDiv("wsr-stats-note", t("stats.note")));
|
|
2235
2302
|
|
|
2236
2303
|
var tabs = statsDiv("wsr-stats-tabs");
|
|
2237
2304
|
tabs.setAttribute("role", "tablist");
|
|
@@ -2242,7 +2309,7 @@
|
|
|
2242
2309
|
amplifiedPanel.appendChild(amplifiedSection);
|
|
2243
2310
|
defs.push(["amplified", "stats.tab.amplified", amplifiedPanel]);
|
|
2244
2311
|
}
|
|
2245
|
-
defs.
|
|
2312
|
+
if (mode === "agent") defs[0][2].appendChild(statsDiv("wsr-stats-note", t("stats.argModeNote")));
|
|
2246
2313
|
var tabButtons = {};
|
|
2247
2314
|
var selectTab = function (id) {
|
|
2248
2315
|
statsTab = id;
|
|
@@ -2271,7 +2338,10 @@
|
|
|
2271
2338
|
})(defs[d]);
|
|
2272
2339
|
}
|
|
2273
2340
|
var initialTab = statsTab;
|
|
2274
|
-
|
|
2341
|
+
/* A remembered tab may name a view this build no longer has. */
|
|
2342
|
+
var known = false;
|
|
2343
|
+
for (var kt = 0; kt < defs.length; kt += 1) if (defs[kt][0] === initialTab) known = true;
|
|
2344
|
+
if (!known) initialTab = "distribution";
|
|
2275
2345
|
selectTab(initialTab);
|
|
2276
2346
|
body.appendChild(tabs);
|
|
2277
2347
|
body.appendChild(panels);
|
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.29.0";
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Exact routes the client half calls. Registered on the bare web server, so they
|
|
@@ -130,6 +130,10 @@ async function moveWithRetry(source, target) {
|
|
|
130
130
|
await rename(source, target);
|
|
131
131
|
return true;
|
|
132
132
|
} catch (error) {
|
|
133
|
+
/* Only a momentary lock is worth retrying; "not there" means the move
|
|
134
|
+
cannot happen at all, and treating it as success would leave the caller
|
|
135
|
+
with an empty trash entry and no error. */
|
|
136
|
+
if (error?.code === "ENOENT") return false;
|
|
133
137
|
if (attempt === RENAME_RETRY - 1) throw error;
|
|
134
138
|
await new Promise((resolve) => setTimeout(resolve, RENAME_GAP_MS));
|
|
135
139
|
}
|
|
@@ -187,9 +191,18 @@ export async function trashSession(ctx, sessionId) {
|
|
|
187
191
|
}
|
|
188
192
|
await new Promise((resolve) => setTimeout(resolve, STOP_SETTLE_MS));
|
|
189
193
|
|
|
190
|
-
try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* not archived */ }
|
|
191
194
|
try { await ctx.workspaceRegistry.unpinSession(sessionId); } catch { /* not pinned */ }
|
|
192
195
|
|
|
196
|
+
/* Keep the archive flag instead of clearing it. A trashed session whose log
|
|
197
|
+
moved out of `sessions/` is invisible to the Host's listing, and the flag is
|
|
198
|
+
the only state other plugins can read; dropping it is what made a deleted
|
|
199
|
+
session look alive on boards that keep their own cache. The move below is
|
|
200
|
+
undone with the flag when it fails, so the session returns to its place. */
|
|
201
|
+
const wasArchived = archivedSessionIds(ctx).includes(sessionId);
|
|
202
|
+
if (!wasArchived) {
|
|
203
|
+
try { await ctx.workspaceRegistry.archiveSession(sessionId); } catch { /* an older Host may not offer it */ }
|
|
204
|
+
}
|
|
205
|
+
|
|
193
206
|
/* Same filtered-view trap as the move: the workspace's own sessionIds may
|
|
194
207
|
already hide the id while the stored record still lists it. */
|
|
195
208
|
const rawMembers = await rawWorkspaceMembership();
|
|
@@ -215,24 +228,36 @@ export async function trashSession(ctx, sessionId) {
|
|
|
215
228
|
let moved;
|
|
216
229
|
try {
|
|
217
230
|
moved = await trashSessionLog(ctx, meta, trashRoot);
|
|
218
|
-
if (moved
|
|
219
|
-
/*
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
231
|
+
if (moved === undefined) {
|
|
232
|
+
/* Nothing was parked and nothing was lost: the session could not even be
|
|
233
|
+
listed, so it may have been erased out of band. Roll the flag back. */
|
|
234
|
+
if (!wasArchived) {
|
|
235
|
+
try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* best effort */ }
|
|
236
|
+
}
|
|
237
|
+
return { ok: false, error: "the session's log is not on disk" };
|
|
238
|
+
}
|
|
239
|
+
/* Card facts are captured now, while the log is still on this machine:
|
|
240
|
+
the list only has to read the sidecar afterwards. */
|
|
241
|
+
const card = await trashEntryMetadata(moved);
|
|
242
|
+
await writeTrashSidecar(moved, {
|
|
243
|
+
sessionId: meta.id,
|
|
244
|
+
cwd: typeof meta.cwd === "string" ? meta.cwd : null,
|
|
245
|
+
reason: "delete",
|
|
246
|
+
at: Date.now(),
|
|
247
|
+
/* Restore has to know it owes the Host an unarchive. */
|
|
248
|
+
archived: true,
|
|
249
|
+
...(card === null ? {} : { meta: card }),
|
|
250
|
+
});
|
|
230
251
|
} catch (error) {
|
|
252
|
+
/* The flag would otherwise hide a session whose log never left the disk. */
|
|
253
|
+
if (!wasArchived) {
|
|
254
|
+
try { await ctx.workspaceRegistry.unarchiveSession(sessionId); } catch { /* best effort */ }
|
|
255
|
+
}
|
|
231
256
|
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
232
257
|
}
|
|
233
258
|
|
|
234
259
|
ctx.emit("api-session/removed", sessionId);
|
|
235
|
-
return { ok: true, trash: moved };
|
|
260
|
+
return { ok: true, trash: moved, archivedKept: true };
|
|
236
261
|
}
|
|
237
262
|
|
|
238
263
|
/** POST { sessionId } -> move that session into the trash folder. */
|
|
@@ -1486,6 +1511,14 @@ export async function restoreTrashEntry(ctx, name) {
|
|
|
1486
1511
|
} catch (error) {
|
|
1487
1512
|
return { ok: false, error: `could not move the files back: ${error instanceof Error ? error.message : String(error)}` };
|
|
1488
1513
|
}
|
|
1514
|
+
/* The archive flag the delete kept is dropped only now: with the log back in
|
|
1515
|
+
place but the flag still set, the archive panel would show a record-only
|
|
1516
|
+
row for a session that has its log again. */
|
|
1517
|
+
try {
|
|
1518
|
+
await ctx.workspaceRegistry.unarchiveSession(sidecar.sessionId);
|
|
1519
|
+
} catch {
|
|
1520
|
+
/* not archived (older entries) or the Host refused; the attach below still runs */
|
|
1521
|
+
}
|
|
1489
1522
|
const workspaces = ctx.workspaceRegistry.list();
|
|
1490
1523
|
const owner = workspaces.find((workspace) => workspace.path === sidecar.cwd);
|
|
1491
1524
|
let attached = false;
|
|
@@ -1521,13 +1554,31 @@ export async function restoreTrashEntry(ctx, name) {
|
|
|
1521
1554
|
return { ok: true, sessionId: sidecar.sessionId, cwd: sidecar.cwd, attached };
|
|
1522
1555
|
}
|
|
1523
1556
|
|
|
1524
|
-
/**
|
|
1525
|
-
|
|
1557
|
+
/**
|
|
1558
|
+
* Erase one trash entry for good.
|
|
1559
|
+
*
|
|
1560
|
+
* A trashed session keeps the Host's archive flag (that flag is how the rest of
|
|
1561
|
+
* the app knows it is put away), so purging has to drop it first - otherwise the
|
|
1562
|
+
* archive set would keep an id whose log no longer exists.
|
|
1563
|
+
*/
|
|
1564
|
+
export async function purgeTrashEntry(name, ctx = null) {
|
|
1526
1565
|
const root = await trashRoot();
|
|
1527
1566
|
if (name === "" || name.indexOf("..") !== -1 || name.indexOf("/") !== -1 || name.indexOf("\\") !== -1) {
|
|
1528
1567
|
return { ok: false, error: "invalid entry name" };
|
|
1529
1568
|
}
|
|
1530
|
-
|
|
1569
|
+
const directory = join(root, name);
|
|
1570
|
+
if (ctx !== null && ctx !== undefined) {
|
|
1571
|
+
const sidecar = await readTrashSidecar(directory);
|
|
1572
|
+
const sessionId = sidecar !== null && typeof sidecar.sessionId === "string" ? sidecar.sessionId : "";
|
|
1573
|
+
if (sessionId !== "") {
|
|
1574
|
+
try {
|
|
1575
|
+
await ctx.workspaceRegistry.unarchiveSession(sessionId);
|
|
1576
|
+
} catch {
|
|
1577
|
+
/* not archived, or the Host refused; erasing the files still proceeds */
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
await rm(directory, { recursive: true, force: true });
|
|
1531
1582
|
return { ok: true };
|
|
1532
1583
|
}
|
|
1533
1584
|
|
|
@@ -1826,9 +1877,9 @@ export async function detachMissingArchive(ctx, sessionId) {
|
|
|
1826
1877
|
/**
|
|
1827
1878
|
* Delete an archived session for good.
|
|
1828
1879
|
*
|
|
1829
|
-
* The normal delete
|
|
1830
|
-
* plugin's trash - erasing it is then the trash's own purge
|
|
1831
|
-
* cannot drift apart.
|
|
1880
|
+
* The normal delete detaches, keeps the archive flag and moves the log into the
|
|
1881
|
+
* plugin's trash - erasing it is then the trash's own purge (which drops the
|
|
1882
|
+
* flag before the files), so the two paths cannot drift apart.
|
|
1832
1883
|
*/
|
|
1833
1884
|
export async function forgetArchivedSession(ctx, sessionId) {
|
|
1834
1885
|
const result = await trashSession(ctx, sessionId);
|
|
@@ -1838,7 +1889,7 @@ export async function forgetArchivedSession(ctx, sessionId) {
|
|
|
1838
1889
|
const name = result.trash.split(/[/\\]/).filter((part) => part !== "").pop();
|
|
1839
1890
|
if (typeof name === "string" && name !== "") {
|
|
1840
1891
|
try {
|
|
1841
|
-
purged = (await purgeTrashEntry(name)).ok === true;
|
|
1892
|
+
purged = (await purgeTrashEntry(name, ctx)).ok === true;
|
|
1842
1893
|
} catch {
|
|
1843
1894
|
purged = false;
|
|
1844
1895
|
}
|
|
@@ -1999,7 +2050,7 @@ export async function handleTrashListRequest(ctx, req, res) {
|
|
|
1999
2050
|
return;
|
|
2000
2051
|
}
|
|
2001
2052
|
if (action === "purge") {
|
|
2002
|
-
sendJson(res, 200, await purgeTrashEntry(name));
|
|
2053
|
+
sendJson(res, 200, await purgeTrashEntry(name, ctx));
|
|
2003
2054
|
return;
|
|
2004
2055
|
}
|
|
2005
2056
|
sendJson(res, 400, { ok: false, error: "unknown action" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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, moving a session to another workspace, and a literal content search that jumps to the turn a word was said in.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chyxhtc",
|