dsh-ws-recency 0.30.2 → 0.31.1
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 -2
- package/client.js +185 -194
- package/index.js +142 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -167,8 +167,13 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
167
167
|
|
|
168
168
|
- 搜的是**对话正文**:你的提问 + 助手的回复;不搜思维链、不搜工具参数和工具结果(那些会让命中被日志噪声淹没);
|
|
169
169
|
- 多个词用空格分隔,**要求同时出现在同一条消息里**(AND);大小写不敏感,纯字面匹配,不支持正则;
|
|
170
|
-
-
|
|
171
|
-
-
|
|
170
|
+
- 范围用**控件**选,不用记语法:搜索框下面有「工作区」下拉、「会话标题」输入框、「角色」三个按钮(全部 / 我 / 助手)。改控件会用当前关键词自动重搜;
|
|
171
|
+
- 搜索框里仍然可以写匹配方式:`"一个词组"`(整句匹配)、`a|b` 或 `a or b`(任一即可)、`-词`(排除);
|
|
172
|
+
- 想用键盘也行:`ws:工作区`、`in:会话标题`、`role:user|assistant`,中文别名 `工作区:` / `会话:` / `角色:` 同样可用。控件与语法同时给出时,**以控件为准**(那是屏幕上看得见的选择);
|
|
173
|
+
- 结果按新到旧排列,每条给出角色、会话标题、所属工作区、第几轮/第几步,以及带高亮的片段;
|
|
174
|
+
- 每条结果有两个动作:`看上下文` 在行内展开命中处前后各约 400 字(不碰聊天区,长会话也不卡),`打开会话` 才真的跳转;
|
|
175
|
+
- 搜索过的词会记进「最近搜索」,点一下重搜、点 × 删一条、右侧「清空」全清,重启后还在。
|
|
176
|
+
- 点「打开会话」:打开那个会话 → 点右侧竖条上对应轮次的格子(这是宿主自己的跳转入口,会连带加载那一段历史)→ 关键词在正文里高亮。**跳转本身可能等几秒到十几秒**,那是宿主加载历史的时间;插件自己在浮标里报的那点是几十毫秒级。
|
|
172
177
|
- 第一次搜索要为每个会话建一次正文索引(存在 `~/.hypers-work/.wsr/search/<sessionId>.json`,按日志大小 + revision 决定是否失效)。面板顶部会显示「还有 N 个会话正在建立索引」,每轮补一批、结果自动刷新,之后同一份日志不再重复解码。
|
|
173
178
|
|
|
174
179
|
## 设置
|
package/client.js
CHANGED
|
@@ -362,6 +362,14 @@
|
|
|
362
362
|
".wsr-hit-context-toggle,.wsr-hit-context-jump{border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;line-height:18px;padding:0 8px;border-radius:9px;cursor:pointer}",
|
|
363
363
|
".wsr-hit-context-toggle:hover,.wsr-hit-context-jump:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l3,rgba(255,255,255,.24))}",
|
|
364
364
|
".wsr-hit-context{max-height:38vh;overflow:auto;margin-top:4px;padding:6px 8px;border-radius:6px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));color:var(--dsw-alias-label-secondary);font-size:11px;line-height:1.65;white-space:pre-wrap;word-break:break-word}",
|
|
365
|
+
".wsr-search-filters{display:flex;flex-wrap:wrap;align-items:center;gap:10px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
366
|
+
".wsr-filter{display:inline-flex;align-items:center;gap:5px}",
|
|
367
|
+
".wsr-filter-label{flex:none}",
|
|
368
|
+
".wsr-filter-select,.wsr-filter-input{height:22px;border-radius:6px;border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.05));color:var(--dsw-alias-label-primary);font:inherit;font-size:11px;padding:0 6px;max-width:180px}",
|
|
369
|
+
".wsr-filter-input{width:130px}",
|
|
370
|
+
".wsr-filter-chip{height:22px;padding:0 9px;border-radius:999px;border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;cursor:pointer}",
|
|
371
|
+
".wsr-filter-chip-on{color:var(--dsw-alias-label-primary);border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f9df7) 55%,transparent);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f9df7) 14%,transparent)}",
|
|
372
|
+
".wsr-search-hint{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}",
|
|
365
373
|
".wsr-search-history{display:flex;align-items:center;flex-wrap:wrap;gap:6px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
366
374
|
".wsr-search-history-label{flex:none}",
|
|
367
375
|
".wsr-search-chip{display:inline-flex;align-items:center;border-radius:9px;background:var(--dsw-alias-bg-layer-3,rgba(255,255,255,.07));overflow:hidden}",
|
|
@@ -511,6 +519,12 @@
|
|
|
511
519
|
"search.contextShow": "看上下文",
|
|
512
520
|
"search.contextHide": "收起",
|
|
513
521
|
"search.openSession": "打开会话",
|
|
522
|
+
"search.hint": "空格=都要有 · \"词组\" · a|b 或 · -排除",
|
|
523
|
+
"search.filterWorkspace": "工作区",
|
|
524
|
+
"search.filterSession": "会话标题",
|
|
525
|
+
"search.filterSessionPlaceholder": "包含…(回车)",
|
|
526
|
+
"search.filterRole": "角色",
|
|
527
|
+
"search.filterAll": "全部",
|
|
514
528
|
"search.history": "最近搜索",
|
|
515
529
|
"search.historyRun": "再搜一次:{query}",
|
|
516
530
|
"search.historyDrop": "从历史里删除",
|
|
@@ -578,6 +592,10 @@
|
|
|
578
592
|
"stats.argModeNote": "当前把工具参数计入主 agent:每个工具只算返回结果,表格里「参数」列显示为淡色(那些 token 记在主 agent 那一行)。",
|
|
579
593
|
"stats.amplified.title": "放大成本(账单归因)",
|
|
580
594
|
"stats.amplified.kindTitle": "账单构成",
|
|
595
|
+
"stats.amplified.repeatTitle": "重复读取合计",
|
|
596
|
+
"stats.amplified.repeatMeta": "{count} 次 · 合计 {tokens}",
|
|
597
|
+
"stats.amplified.repeatTitle": "Repeated reads",
|
|
598
|
+
"stats.amplified.repeatMeta": "{count} times · {tokens} total",
|
|
581
599
|
"stats.amplified.lead": "按「内容大小 × 之后重读次数」排序:一块内容读进来一次,之后每一步都会再发一遍,乘上重读次数才是它真正的开销。上面的分布统计只算内容本身多大,两个数不能直接比。",
|
|
582
600
|
"stats.amplified.summary": "账单 {bill} token;可归因内容经重读放大后占 {share}({attributed})",
|
|
583
601
|
"stats.amplified.contextCaption": "每步上下文(面积≈账单):一步=一次模型调用,越早进入的内容被重读越多",
|
|
@@ -712,6 +730,12 @@
|
|
|
712
730
|
"search.contextShow": "Show context",
|
|
713
731
|
"search.contextHide": "Hide",
|
|
714
732
|
"search.openSession": "Open session",
|
|
733
|
+
"search.hint": "space = all of them · \"phrase\" · a|b either · -exclude",
|
|
734
|
+
"search.filterWorkspace": "Workspace",
|
|
735
|
+
"search.filterSession": "Session",
|
|
736
|
+
"search.filterSessionPlaceholder": "title contains… (Enter)",
|
|
737
|
+
"search.filterRole": "Role",
|
|
738
|
+
"search.filterAll": "All",
|
|
715
739
|
"search.history": "Recent",
|
|
716
740
|
"search.historyRun": "Search again: {query}",
|
|
717
741
|
"search.historyDrop": "Remove from history",
|
|
@@ -1168,7 +1192,20 @@
|
|
|
1168
1192
|
var hostButton = overflowButtonOf(section);
|
|
1169
1193
|
markHeader(entry.header, entry.key);
|
|
1170
1194
|
|
|
1171
|
-
|
|
1195
|
+
/* Everything this project holds is history: no session inside it is
|
|
1196
|
+
recent, so the user's expansion of the project is itself the
|
|
1197
|
+
request to see its sessions. Folding here only adds a second click
|
|
1198
|
+
for a group the user has already gone looking for. */
|
|
1199
|
+
var onlyHistory = rows.length > 0;
|
|
1200
|
+
for (var scan = 0; scan < rows.length; scan += 1) {
|
|
1201
|
+
var scannedAt = updatedAtOf(rows[scan], sessions);
|
|
1202
|
+
var covers = scannedAt === null || scannedAt >= cutoff;
|
|
1203
|
+
if (covers && !isBlankRow(rows[scan], sessions)) {
|
|
1204
|
+
onlyHistory = false;
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
var expanded = expandedSections.has(entry.key) || onlyHistory;
|
|
1172
1209
|
var hostHidden = hostButton === null ? 0 : labelNumber(hostButton);
|
|
1173
1210
|
var hostExpanded = hostButton !== null
|
|
1174
1211
|
&& typeof hostButton.getAttribute === "function"
|
|
@@ -1217,7 +1254,9 @@
|
|
|
1217
1254
|
folded. Expanding drives the hidden host button until nothing is left
|
|
1218
1255
|
unrendered, so one click reveals the whole group. */
|
|
1219
1256
|
var remaining = folded + hostHidden;
|
|
1220
|
-
|
|
1257
|
+
/* A project that is entirely history is open because opening it is the
|
|
1258
|
+
request; there is nothing to offer to fold back. */
|
|
1259
|
+
if (expanded && !onlyHistory) {
|
|
1221
1260
|
(function (entryKey) {
|
|
1222
1261
|
ensureToggle(section, entryKey, t("fold.hide"), function () {
|
|
1223
1262
|
expandedSections.delete(entryKey);
|
|
@@ -2311,6 +2350,28 @@
|
|
|
2311
2350
|
/** The neutral an unknown tool gets: no family, no claim of one. */
|
|
2312
2351
|
var TOOL_FAMILY_NEUTRAL = { key: "other", hue: 210 };
|
|
2313
2352
|
|
|
2353
|
+
/**
|
|
2354
|
+
* A stable hue for a tool that belongs to no family.
|
|
2355
|
+
*
|
|
2356
|
+
* Every unknown tool used to share the neutral hue, so the chart showed
|
|
2357
|
+
* several tools in one colour. A hash of the name spreads them out, and a
|
|
2358
|
+
* nudge keeps the result clear of the family hues it would otherwise
|
|
2359
|
+
* collide with.
|
|
2360
|
+
*/
|
|
2361
|
+
function hueOfUnknown(name) {
|
|
2362
|
+
var hash = 2166136261;
|
|
2363
|
+
for (var i = 0; i < name.length; i += 1) {
|
|
2364
|
+
hash ^= name.charCodeAt(i);
|
|
2365
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
2366
|
+
}
|
|
2367
|
+
var hue = hash % 360;
|
|
2368
|
+
for (var f = 0; f < TOOL_FAMILIES.length; f += 1) {
|
|
2369
|
+
var distance = Math.abs(hue - TOOL_FAMILIES[f].hue);
|
|
2370
|
+
if (distance < 16 || distance > 344) hue = (hue + 41) % 360;
|
|
2371
|
+
}
|
|
2372
|
+
return hue;
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2314
2375
|
function toolFamily(name) {
|
|
2315
2376
|
if (typeof name !== "string" || name === "") return TOOL_FAMILY_NEUTRAL;
|
|
2316
2377
|
var key = name.toLowerCase();
|
|
@@ -2699,6 +2760,31 @@
|
|
|
2699
2760
|
list.appendChild(row);
|
|
2700
2761
|
}
|
|
2701
2762
|
ranking.appendChild(list);
|
|
2763
|
+
|
|
2764
|
+
/* Repetition is the actionable part: reading one file twice costs the
|
|
2765
|
+
same as two files, and the list above shows it as two rows. */
|
|
2766
|
+
var repeated = amplified.repeated || [];
|
|
2767
|
+
if (repeated.length > 0) {
|
|
2768
|
+
ranking.appendChild(statsDiv("wsr-amplified-subtitle", t("stats.amplified.repeatTitle")));
|
|
2769
|
+
var repeats = statsDiv("wsr-amplified-list");
|
|
2770
|
+
for (var rp = 0; rp < repeated.length; rp += 1) {
|
|
2771
|
+
var item = repeated[rp];
|
|
2772
|
+
var row = statsDiv("wsr-amplified-row");
|
|
2773
|
+
var main = statsDiv("wsr-amplified-main");
|
|
2774
|
+
main.appendChild(statsDiv("wsr-amplified-name", typeof item.detail === "string" ? item.detail : ""));
|
|
2775
|
+
main.appendChild(statsDiv("wsr-amplified-meta", t("stats.amplified.repeatMeta", {
|
|
2776
|
+
count: String(item.count),
|
|
2777
|
+
tokens: formatTokens(item.tokens),
|
|
2778
|
+
})));
|
|
2779
|
+
row.appendChild(main);
|
|
2780
|
+
var value = statsDiv("wsr-amplified-value", formatTokens(item.amplified));
|
|
2781
|
+
value.setAttribute("title", String(Math.round(Number(item.amplified) || 0)) + " tokens");
|
|
2782
|
+
row.appendChild(value);
|
|
2783
|
+
row.appendChild(statsDiv("wsr-amplified-share", formatShare(item.share || 0)));
|
|
2784
|
+
repeats.appendChild(row);
|
|
2785
|
+
}
|
|
2786
|
+
ranking.appendChild(repeats);
|
|
2787
|
+
}
|
|
2702
2788
|
return { top: section, ranking: ranking };
|
|
2703
2789
|
}
|
|
2704
2790
|
|
|
@@ -3815,149 +3901,7 @@
|
|
|
3815
3901
|
}
|
|
3816
3902
|
}
|
|
3817
3903
|
|
|
3818
|
-
|
|
3819
|
-
function openTrashPanel() {
|
|
3820
|
-
if (typeof document === "undefined") return;
|
|
3821
|
-
closeStatsPanel();
|
|
3822
|
-
var backdrop = statsDiv("wsr-modal-backdrop");
|
|
3823
|
-
var panel = statsDiv("wsr-modal");
|
|
3824
|
-
backdrop.appendChild(panel);
|
|
3825
|
-
var head = statsDiv("wsr-modal-head");
|
|
3826
|
-
head.appendChild(statsDiv("wsr-modal-title", t("trash.title")));
|
|
3827
|
-
var tools = statsDiv("wsr-modal-tools");
|
|
3828
|
-
var adopt = document.createElement("button");
|
|
3829
|
-
adopt.type = "button";
|
|
3830
|
-
adopt.className = "wsr-btn";
|
|
3831
|
-
adopt.title = t("adopt.description");
|
|
3832
|
-
adopt.textContent = t("adopt.action");
|
|
3833
|
-
tools.appendChild(adopt);
|
|
3834
|
-
var close = document.createElement("button");
|
|
3835
|
-
close.type = "button";
|
|
3836
|
-
close.className = "wsr-modal-close";
|
|
3837
|
-
close.textContent = "\u00d7";
|
|
3838
|
-
close.addEventListener("click", closeStatsPanel);
|
|
3839
|
-
tools.appendChild(close);
|
|
3840
|
-
head.appendChild(tools);
|
|
3841
|
-
panel.appendChild(head);
|
|
3842
|
-
var body = statsDiv("wsr-modal-body");
|
|
3843
|
-
panel.appendChild(body);
|
|
3844
|
-
backdrop.addEventListener("click", function (event) {
|
|
3845
|
-
if (event !== undefined && event.target === backdrop) closeStatsPanel();
|
|
3846
|
-
});
|
|
3847
|
-
document.body.appendChild(backdrop);
|
|
3848
|
-
statsModal = backdrop;
|
|
3849
|
-
document.addEventListener("keydown", onStatsKey);
|
|
3850
|
-
|
|
3851
|
-
var post = function (payload) {
|
|
3852
|
-
return fetch("/ws-recency/trash", {
|
|
3853
|
-
method: "POST",
|
|
3854
|
-
headers: { "content-type": "application/json" },
|
|
3855
|
-
body: JSON.stringify(payload),
|
|
3856
|
-
}).then(function (response) {
|
|
3857
|
-
return response.text().then(function (text) {
|
|
3858
|
-
var parsed = null;
|
|
3859
|
-
try { parsed = JSON.parse(text); } catch (error) { parsed = null; }
|
|
3860
|
-
return { status: response.status, text: text, json: parsed };
|
|
3861
|
-
});
|
|
3862
|
-
});
|
|
3863
|
-
};
|
|
3864
|
-
|
|
3865
|
-
var load = function (note) {
|
|
3866
|
-
body.textContent = t("trash.loading");
|
|
3867
|
-
post({ action: "list" }).then(function (answer) {
|
|
3868
|
-
body.textContent = "";
|
|
3869
|
-
if (note !== undefined && note !== "") {
|
|
3870
|
-
body.appendChild(statsDiv("wsr-stats-detail", note));
|
|
3871
|
-
var noteActions = statsDiv("wsr-trash-actions");
|
|
3872
|
-
noteActions.appendChild(reloadButton());
|
|
3873
|
-
body.appendChild(noteActions);
|
|
3874
|
-
}
|
|
3875
|
-
if (answer.json === null || answer.json.ok !== true) {
|
|
3876
|
-
body.appendChild(statsDiv("wsr-stats-note", t("trash.failed") + "HTTP " + answer.status + " \u00b7 " + (answer.text || "").slice(0, 120)));
|
|
3877
|
-
return;
|
|
3878
|
-
}
|
|
3879
|
-
var entries = Array.isArray(answer.json.entries) ? answer.json.entries : [];
|
|
3880
|
-
if (entries.length === 0) {
|
|
3881
|
-
body.appendChild(statsDiv("wsr-stats-note", t("trash.empty")));
|
|
3882
|
-
return;
|
|
3883
|
-
}
|
|
3884
|
-
var list = statsDiv("wsr-move-list");
|
|
3885
|
-
for (var i = 0; i < entries.length; i += 1) {
|
|
3886
|
-
(function (entry) {
|
|
3887
|
-
var row = document.createElement("div");
|
|
3888
|
-
row.className = "wsr-trash-row";
|
|
3889
|
-
var text = statsDiv("wsr-move-text");
|
|
3890
|
-
var title = entry.sessionId === null ? entry.name : entry.sessionId;
|
|
3891
|
-
text.appendChild(statsDiv("wsr-move-title", title));
|
|
3892
|
-
var meta = [];
|
|
3893
|
-
if (entry.reason === "delete") meta.push(t("trash.reason.delete"));
|
|
3894
|
-
else if (entry.reason === "move") meta.push(t("trash.reason.move"));
|
|
3895
|
-
meta.push(formatBytes(entry.sizeBytes));
|
|
3896
|
-
var when = formatWhen(entry.at);
|
|
3897
|
-
if (when !== "") meta.push(when);
|
|
3898
|
-
text.appendChild(statsDiv("wsr-move-path", meta.join(" \u00b7 ")));
|
|
3899
|
-
if (typeof entry.cwd === "string" && entry.cwd !== "") {
|
|
3900
|
-
text.appendChild(statsDiv("wsr-move-path", entry.cwd));
|
|
3901
|
-
}
|
|
3902
|
-
row.appendChild(text);
|
|
3903
|
-
|
|
3904
|
-
var actions = statsDiv("wsr-trash-actions");
|
|
3905
|
-
if (entry.restorable === true) {
|
|
3906
|
-
var restore = document.createElement("button");
|
|
3907
|
-
restore.type = "button";
|
|
3908
|
-
restore.className = "wsr-btn";
|
|
3909
|
-
restore.textContent = t("trash.restore");
|
|
3910
|
-
restore.addEventListener("click", function () {
|
|
3911
|
-
askConfirm(t("trash.confirmRestore"), function () {
|
|
3912
|
-
load(t("trash.working"));
|
|
3913
|
-
post({ action: "restore", name: entry.name }).then(function (result) {
|
|
3914
|
-
var ok = result.json !== null && result.json.ok === true;
|
|
3915
|
-
load(ok ? t("trash.restored") : t("trash.failed") + (result.json && result.json.error ? result.json.error : result.text));
|
|
3916
|
-
}).catch(function (error) {
|
|
3917
|
-
load(t("trash.failed") + (error && error.message ? error.message : error));
|
|
3918
|
-
});
|
|
3919
|
-
});
|
|
3920
|
-
});
|
|
3921
|
-
actions.appendChild(restore);
|
|
3922
|
-
}
|
|
3923
|
-
var purge = document.createElement("button");
|
|
3924
|
-
purge.type = "button";
|
|
3925
|
-
purge.className = "wsr-btn wsr-btn-danger";
|
|
3926
|
-
purge.textContent = t("trash.purge");
|
|
3927
|
-
purge.addEventListener("click", function () {
|
|
3928
|
-
askConfirm(t("trash.confirmPurge"), function () {
|
|
3929
|
-
load(t("trash.working"));
|
|
3930
|
-
post({ action: "purge", name: entry.name }).then(function (result) {
|
|
3931
|
-
var ok = result.json !== null && result.json.ok === true;
|
|
3932
|
-
load(ok ? t("trash.purged") : t("trash.failed") + (result.json && result.json.error ? result.json.error : result.text));
|
|
3933
|
-
}).catch(function (error) {
|
|
3934
|
-
load(t("trash.failed") + (error && error.message ? error.message : error));
|
|
3935
|
-
});
|
|
3936
|
-
});
|
|
3937
|
-
});
|
|
3938
|
-
actions.appendChild(purge);
|
|
3939
|
-
row.appendChild(actions);
|
|
3940
|
-
list.appendChild(row);
|
|
3941
|
-
})(entries[i]);
|
|
3942
|
-
}
|
|
3943
|
-
body.appendChild(list);
|
|
3944
|
-
body.appendChild(statsDiv("wsr-stats-note", t("trash.note")));
|
|
3945
|
-
}).catch(function (error) {
|
|
3946
|
-
body.textContent = t("trash.failed") + (error && error.message ? error.message : error);
|
|
3947
|
-
});
|
|
3948
|
-
};
|
|
3949
|
-
adopt.addEventListener("click", function () {
|
|
3950
|
-
adopt.disabled = true;
|
|
3951
|
-
adopt.textContent = t("adopt.working");
|
|
3952
|
-
adoptUnlistedSessions(function (message) {
|
|
3953
|
-
adopt.disabled = false;
|
|
3954
|
-
adopt.textContent = t("adopt.action");
|
|
3955
|
-
load(message);
|
|
3956
|
-
});
|
|
3957
|
-
});
|
|
3958
|
-
load("");
|
|
3959
|
-
}
|
|
3960
|
-
|
|
3904
|
+
|
|
3961
3905
|
/* --------------------------- trash panel page ------------------------ */
|
|
3962
3906
|
|
|
3963
3907
|
function trashPost(payload) {
|
|
@@ -3976,6 +3920,14 @@
|
|
|
3976
3920
|
|
|
3977
3921
|
/* ---------- session content search -------------------------------- */
|
|
3978
3922
|
|
|
3923
|
+
/**
|
|
3924
|
+
* Narrowing chosen through controls rather than typed syntax.
|
|
3925
|
+
*
|
|
3926
|
+
* Typing `ws:` is a sentence to learn; a select is not. The typed forms
|
|
3927
|
+
* still work, and both are merged on the host.
|
|
3928
|
+
*/
|
|
3929
|
+
var searchFilters = { workspace: "", session: "", role: "" };
|
|
3930
|
+
|
|
3979
3931
|
/** How many recent queries the panel remembers. */
|
|
3980
3932
|
var SEARCH_HISTORY_MAX = 12;
|
|
3981
3933
|
|
|
@@ -4739,6 +4691,12 @@
|
|
|
4739
4691
|
setView(next);
|
|
4740
4692
|
};
|
|
4741
4693
|
|
|
4694
|
+
/* Changing a filter with a query on screen should show the effect at
|
|
4695
|
+
once instead of waiting for another Enter. */
|
|
4696
|
+
var rerun = function () {
|
|
4697
|
+
if (view.query !== "") run(view.query, false);
|
|
4698
|
+
};
|
|
4699
|
+
|
|
4742
4700
|
var run = function (text, refresh) {
|
|
4743
4701
|
var query = typeof text === "string" ? text.trim() : "";
|
|
4744
4702
|
searchGeneration += 1;
|
|
@@ -4750,7 +4708,13 @@
|
|
|
4750
4708
|
if (typeof actions.pushSearch === "function") actions.pushSearch(query);
|
|
4751
4709
|
commit({ loaded: true, query: query, hits: view.hits, terms: view.terms, scanned: view.scanned, total: view.total, pending: view.pending, took: view.took, busy: true, error: "" });
|
|
4752
4710
|
var ask = function (needRefresh) {
|
|
4753
|
-
searchPost({
|
|
4711
|
+
searchPost({
|
|
4712
|
+
query: query,
|
|
4713
|
+
refresh: needRefresh === true,
|
|
4714
|
+
workspace: searchFilters.workspace,
|
|
4715
|
+
session: searchFilters.session,
|
|
4716
|
+
role: searchFilters.role,
|
|
4717
|
+
}).then(function (answer) {
|
|
4754
4718
|
if (generation !== searchGeneration) return;
|
|
4755
4719
|
var json = answer.json;
|
|
4756
4720
|
if (json === null || json.ok !== true) {
|
|
@@ -4847,7 +4811,80 @@
|
|
|
4847
4811
|
},
|
|
4848
4812
|
}, t("search.historyClear")),
|
|
4849
4813
|
),
|
|
4850
|
-
|
|
4814
|
+
h("div", { className: "wsr-search-filters" },
|
|
4815
|
+
h("label", { className: "wsr-filter" },
|
|
4816
|
+
h("span", { className: "wsr-filter-label" }, t("search.filterWorkspace")),
|
|
4817
|
+
h("select", {
|
|
4818
|
+
className: "wsr-filter-select",
|
|
4819
|
+
value: searchFilters.workspace,
|
|
4820
|
+
onChange: function (event) {
|
|
4821
|
+
searchFilters.workspace = event.target.value || "";
|
|
4822
|
+
rerun();
|
|
4823
|
+
},
|
|
4824
|
+
},
|
|
4825
|
+
h("option", { value: "" }, t("search.filterAll")),
|
|
4826
|
+
(function () {
|
|
4827
|
+
var items = data.workspaces !== null && data.workspaces !== undefined
|
|
4828
|
+
&& Array.isArray(data.workspaces.items) ? data.workspaces.items : [];
|
|
4829
|
+
var options = [];
|
|
4830
|
+
for (var wi = 0; wi < items.length; wi += 1) {
|
|
4831
|
+
var name = typeof items[wi].name === "string" && items[wi].name !== ""
|
|
4832
|
+
? items[wi].name
|
|
4833
|
+
: String(items[wi].title || "");
|
|
4834
|
+
if (name === "") continue;
|
|
4835
|
+
options.push(h("option", { value: name, key: "ws:" + name }, name));
|
|
4836
|
+
}
|
|
4837
|
+
return options;
|
|
4838
|
+
})(),
|
|
4839
|
+
),
|
|
4840
|
+
),
|
|
4841
|
+
h("label", { className: "wsr-filter" },
|
|
4842
|
+
h("span", { className: "wsr-filter-label" }, t("search.filterSession")),
|
|
4843
|
+
h("input", {
|
|
4844
|
+
type: "text",
|
|
4845
|
+
className: "wsr-filter-input",
|
|
4846
|
+
defaultValue: searchFilters.session,
|
|
4847
|
+
placeholder: t("search.filterSessionPlaceholder"),
|
|
4848
|
+
onChange: function (event) {
|
|
4849
|
+
searchFilters.session = String(event.target.value || "").trim();
|
|
4850
|
+
},
|
|
4851
|
+
onKeyDown: function (event) {
|
|
4852
|
+
if (event !== undefined && event.key === "Enter") {
|
|
4853
|
+
event.preventDefault();
|
|
4854
|
+
rerun();
|
|
4855
|
+
}
|
|
4856
|
+
},
|
|
4857
|
+
}),
|
|
4858
|
+
),
|
|
4859
|
+
h("span", { className: "wsr-filter" },
|
|
4860
|
+
h("span", { className: "wsr-filter-label" }, t("search.filterRole")),
|
|
4861
|
+
(function () {
|
|
4862
|
+
var roles = [
|
|
4863
|
+
["", "search.filterAll"],
|
|
4864
|
+
["user", "search.you"],
|
|
4865
|
+
["assistant", "search.assistant"],
|
|
4866
|
+
];
|
|
4867
|
+
var buttons = [];
|
|
4868
|
+
for (var ri = 0; ri < roles.length; ri += 1) {
|
|
4869
|
+
(function (value, label) {
|
|
4870
|
+
var active = searchFilters.role === value;
|
|
4871
|
+
buttons.push(h("button", {
|
|
4872
|
+
type: "button",
|
|
4873
|
+
key: "role:" + value,
|
|
4874
|
+
className: "wsr-filter-chip" + (active ? " wsr-filter-chip-on" : ""),
|
|
4875
|
+
onClick: function () {
|
|
4876
|
+
searchFilters.role = value;
|
|
4877
|
+
rerun();
|
|
4878
|
+
},
|
|
4879
|
+
}, t(label)));
|
|
4880
|
+
})(roles[ri][0], roles[ri][1]);
|
|
4881
|
+
}
|
|
4882
|
+
return buttons;
|
|
4883
|
+
})(),
|
|
4884
|
+
),
|
|
4885
|
+
),
|
|
4886
|
+
h("div", { className: "wsr-search-hint" }, t("search.hint")),
|
|
4887
|
+
h("div", { className: "wsr-search-bar" },
|
|
4851
4888
|
input,
|
|
4852
4889
|
h("button", { type: "button", className: "wsr-btn", onClick: function () { run(searchDraft, false); } }, t("search.run")),
|
|
4853
4890
|
),
|
|
@@ -5148,53 +5185,7 @@
|
|
|
5148
5185
|
);
|
|
5149
5186
|
}
|
|
5150
5187
|
|
|
5151
|
-
|
|
5152
|
-
* Sidebar footer action: the trash, one click away from the account area.
|
|
5153
|
-
*
|
|
5154
|
-
* Geometry is the same house rule the official launchers follow
|
|
5155
|
-
* (`dshUpdateLauncher` / `dshMarketLauncher`): full-width seat bled 2px
|
|
5156
|
-
* per side, 42px tall, 12px radius. `wide` comes from the slot, so the
|
|
5157
|
-
* narrow rail keeps its 36px circle instead of a stretched row.
|
|
5158
|
-
*/
|
|
5159
|
-
function TrashFooterAction(props) {
|
|
5160
|
-
var wide = props === undefined || props === null || props.wide !== false;
|
|
5161
|
-
var label = t("trash.title");
|
|
5162
|
-
var Icon = ui.IconTrashOutlineRegular;
|
|
5163
|
-
return h("button", {
|
|
5164
|
-
type: "button",
|
|
5165
|
-
className: "wsr-footer-action",
|
|
5166
|
-
title: label,
|
|
5167
|
-
"aria-label": label,
|
|
5168
|
-
"aria-haspopup": "dialog",
|
|
5169
|
-
style: {
|
|
5170
|
-
boxSizing: "border-box",
|
|
5171
|
-
width: "100%",
|
|
5172
|
-
alignSelf: "stretch",
|
|
5173
|
-
display: "flex",
|
|
5174
|
-
alignItems: "center",
|
|
5175
|
-
justifyContent: "flex-start",
|
|
5176
|
-
gap: "10px",
|
|
5177
|
-
minHeight: "40px",
|
|
5178
|
-
padding: "0 10px",
|
|
5179
|
-
border: "none",
|
|
5180
|
-
background: "transparent",
|
|
5181
|
-
color: "var(--dsw-alias-label-primary)",
|
|
5182
|
-
borderRadius: "10px",
|
|
5183
|
-
font: "inherit",
|
|
5184
|
-
fontSize: "14px",
|
|
5185
|
-
lineHeight: "22px",
|
|
5186
|
-
cursor: "pointer",
|
|
5187
|
-
textAlign: "left",
|
|
5188
|
-
},
|
|
5189
|
-
onClick: function () { openTrashPanel(); },
|
|
5190
|
-
},
|
|
5191
|
-
h("span", {
|
|
5192
|
-
style: { display: "inline-flex", alignItems: "center", justifyContent: "center", width: "20px", height: "20px", flex: "none" },
|
|
5193
|
-
"aria-hidden": "true",
|
|
5194
|
-
}, typeof Icon === "function" ? h(Icon, { size: 18 }) : null),
|
|
5195
|
-
wide ? h("span", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, label) : null);
|
|
5196
|
-
}
|
|
5197
|
-
|
|
5188
|
+
|
|
5198
5189
|
/**
|
|
5199
5190
|
* Re-attach sessions that belong to no workspace.
|
|
5200
5191
|
*
|
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.31.1";
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Exact routes the client half calls. Registered on the bare web server, so they
|
|
@@ -551,6 +551,35 @@ export function aggregateSession(events) {
|
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
const attributed = [...byKind.values()].reduce((sum, entry) => sum + entry.amplified, 0);
|
|
554
|
+
/* The same file read twice shows up as two entries, so a per-target total
|
|
555
|
+
answers "what content is actually costing me" better than a per-read list
|
|
556
|
+
does. Only repeats are interesting here: a single big read is already in
|
|
557
|
+
the ranking below. */
|
|
558
|
+
const byTarget = new Map();
|
|
559
|
+
for (const block of blocks) {
|
|
560
|
+
if (!(block.amplified > 0)) continue;
|
|
561
|
+
const detail = typeof block.detail === "string" ? block.detail.trim() : "";
|
|
562
|
+
if (detail === "") continue;
|
|
563
|
+
const key = block.kind + "\u0000" + block.name + "\u0000" + detail;
|
|
564
|
+
let entry = byTarget.get(key);
|
|
565
|
+
if (entry === undefined) {
|
|
566
|
+
entry = { kind: block.kind, name: block.name, detail, count: 0, tokens: 0, amplified: 0 };
|
|
567
|
+
byTarget.set(key, entry);
|
|
568
|
+
}
|
|
569
|
+
entry.count += 1;
|
|
570
|
+
entry.tokens += block.tokens;
|
|
571
|
+
entry.amplified += block.amplified;
|
|
572
|
+
}
|
|
573
|
+
const repeated = [...byTarget.values()]
|
|
574
|
+
.filter((entry) => entry.count > 1)
|
|
575
|
+
.sort((a, b) => b.amplified - a.amplified)
|
|
576
|
+
.slice(0, 10)
|
|
577
|
+
.map((entry) => ({
|
|
578
|
+
...entry,
|
|
579
|
+
share: bill > 0 ? entry.amplified / bill : 0,
|
|
580
|
+
saving: Math.round(entry.amplified * 0.8),
|
|
581
|
+
}));
|
|
582
|
+
|
|
554
583
|
const ranked = blocks
|
|
555
584
|
.filter((block) => block.amplified > 0)
|
|
556
585
|
.sort((a, b) => b.amplified - a.amplified)
|
|
@@ -611,6 +640,7 @@ export function aggregateSession(events) {
|
|
|
611
640
|
/* Steps after which the window was rewritten. The curve restarts there, so the
|
|
612
641
|
client reads each segment on its own instead of comparing across a rewrite. */
|
|
613
642
|
compactions: [...compactions],
|
|
643
|
+
repeated,
|
|
614
644
|
blocks: ranked,
|
|
615
645
|
byKind: [...byKind.values()]
|
|
616
646
|
.map((entry) => ({ ...entry, share: bill > 0 ? entry.amplified / bill : 0 }))
|
|
@@ -870,10 +900,83 @@ function searchSnippet(text, needle) {
|
|
|
870
900
|
* `terms` are the whitespace-separated pieces of the query; all of them have to
|
|
871
901
|
* appear in the same message, so a two-word query narrows instead of widening.
|
|
872
902
|
*/
|
|
903
|
+
/**
|
|
904
|
+
* Turn a typed query into groups of alternatives plus filters.
|
|
905
|
+
*
|
|
906
|
+
* Plain words are ANDed, `or` (or `|`) joins alternatives inside one group, a
|
|
907
|
+
* quoted phrase stays whole, a leading `-` excludes, and `ws:` / `in:` / `role:`
|
|
908
|
+
* narrow the sessions rather than the text. Parsing lives on the host because
|
|
909
|
+
* that is where the transcript is matched; the client only shows the result.
|
|
910
|
+
*/
|
|
911
|
+
function parseSearchQuery(raw) {
|
|
912
|
+
const filters = { workspace: "", session: "", role: "" };
|
|
913
|
+
const groups = [[]];
|
|
914
|
+
const exclude = [];
|
|
915
|
+
const positive = [];
|
|
916
|
+
const tokens = String(raw ?? "").match(/"[^"]*"|\S+/g) || [];
|
|
917
|
+
let joinNext = false;
|
|
918
|
+
const closeGroup = () => {
|
|
919
|
+
if (groups[groups.length - 1].length > 0) groups.push([]);
|
|
920
|
+
};
|
|
921
|
+
for (const token of tokens) {
|
|
922
|
+
const quoted = token.length > 1 && token.startsWith('"') && token.endsWith('"');
|
|
923
|
+
const text = quoted ? token.slice(1, -1) : token;
|
|
924
|
+
if (text === "") continue;
|
|
925
|
+
const lower = text.toLowerCase();
|
|
926
|
+
const filter = lower.match(/^(ws|in|role|工作区|会话|角色):(.*)$/);
|
|
927
|
+
if (filter !== null && filter[2] !== "") {
|
|
928
|
+
const value = filter[2];
|
|
929
|
+
if (filter[1] === "ws" || filter[1] === "工作区") filters.workspace = value.toLowerCase();
|
|
930
|
+
else if (filter[1] === "in" || filter[1] === "会话") filters.session = value.toLowerCase();
|
|
931
|
+
else filters.role = value.toLowerCase();
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
if (!quoted && (lower === "or" || text === "|")) {
|
|
935
|
+
/* Reopen the group the previous term closed: `a or b` is one
|
|
936
|
+
requirement satisfied by either, not two requirements. */
|
|
937
|
+
if (groups.length > 0 && groups[groups.length - 1].length === 0) groups.pop();
|
|
938
|
+
joinNext = true;
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (!quoted && text.length > 1 && text.startsWith("-")) {
|
|
942
|
+
exclude.push(text.slice(1).toLowerCase());
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
const term = text.toLowerCase();
|
|
946
|
+
groups[groups.length - 1].push(term);
|
|
947
|
+
if (positive.indexOf(term) === -1) positive.push(term);
|
|
948
|
+
if (!joinNext) closeGroup();
|
|
949
|
+
joinNext = false;
|
|
950
|
+
}
|
|
951
|
+
const cleaned = groups.filter((group) => group.length > 0);
|
|
952
|
+
return { groups: cleaned, filters, exclude, terms: positive };
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** Whether a message satisfies the parsed query. */
|
|
956
|
+
function matchesQuery(parsed, haystack) {
|
|
957
|
+
for (const group of parsed.groups) {
|
|
958
|
+
if (!group.some((term) => haystack.indexOf(term) !== -1)) return false;
|
|
959
|
+
}
|
|
960
|
+
for (const term of parsed.exclude) {
|
|
961
|
+
if (haystack.indexOf(term) !== -1) return false;
|
|
962
|
+
}
|
|
963
|
+
return true;
|
|
964
|
+
}
|
|
965
|
+
|
|
873
966
|
export async function searchSessions(ctx, query, options = {}) {
|
|
874
967
|
const started = Date.now();
|
|
875
|
-
const
|
|
876
|
-
|
|
968
|
+
const parsed = parseSearchQuery(query);
|
|
969
|
+
/* A control and a typed filter can both say something; the control wins because
|
|
970
|
+
it is the one on screen. */
|
|
971
|
+
if (typeof options.workspace === "string" && options.workspace.trim() !== "") parsed.filters.workspace = options.workspace.trim().toLowerCase();
|
|
972
|
+
if (typeof options.session === "string" && options.session.trim() !== "") parsed.filters.session = options.session.trim().toLowerCase();
|
|
973
|
+
if (typeof options.role === "string" && options.role.trim() !== "") parsed.filters.role = options.role.trim().toLowerCase();
|
|
974
|
+
const terms = parsed.terms;
|
|
975
|
+
const hasFilter = parsed.filters.workspace !== "" || parsed.filters.session !== ""
|
|
976
|
+
|| parsed.filters.role !== "";
|
|
977
|
+
if (terms.length === 0 && parsed.groups.length === 0 && !hasFilter) {
|
|
978
|
+
return { ok: true, query: "", terms: [], hits: [], scanned: 0, total: 0, pending: 0, took: 0 };
|
|
979
|
+
}
|
|
877
980
|
|
|
878
981
|
const directory = await searchIndexDirectory();
|
|
879
982
|
const workspaces = typeof ctx.workspaceRegistry?.list === "function" ? ctx.workspaceRegistry.list() : [];
|
|
@@ -934,6 +1037,20 @@ export async function searchSessions(ctx, query, options = {}) {
|
|
|
934
1037
|
cached = { key, messages, title };
|
|
935
1038
|
}
|
|
936
1039
|
|
|
1040
|
+
/* Filters narrow the sessions, so a filtered-out one costs nothing beyond
|
|
1041
|
+
the snapshot it was listed in. */
|
|
1042
|
+
if (parsed.filters.workspace !== "") {
|
|
1043
|
+
const cwd = normalizedPath(session.header.cwd);
|
|
1044
|
+
const name = String(workspaceByPath.get(cwd) ?? "").toLowerCase();
|
|
1045
|
+
if (name.indexOf(parsed.filters.workspace) === -1) continue;
|
|
1046
|
+
}
|
|
1047
|
+
if (parsed.filters.session !== "") {
|
|
1048
|
+
const headerTitle = typeof session.header.title === "string" ? session.header.title : "";
|
|
1049
|
+
const cachedTitle = typeof cached.title === "string" ? cached.title : "";
|
|
1050
|
+
const title = (headerTitle + " " + cachedTitle).toLowerCase();
|
|
1051
|
+
if (title.indexOf(parsed.filters.session) === -1) continue;
|
|
1052
|
+
}
|
|
1053
|
+
scanned += 0;
|
|
937
1054
|
let found = 0;
|
|
938
1055
|
/* How far down the transcript the last turn sits: the client uses it to jump
|
|
939
1056
|
to an approximate scroll position before it looks for the text. */
|
|
@@ -946,9 +1063,19 @@ export async function searchSessions(ctx, query, options = {}) {
|
|
|
946
1063
|
for (const message of cached.messages) {
|
|
947
1064
|
if (message === null || typeof message !== "object" || typeof message.text !== "string") continue;
|
|
948
1065
|
const haystack = message.text.toLowerCase();
|
|
949
|
-
if (!
|
|
950
|
-
|
|
951
|
-
|
|
1066
|
+
if (!matchesQuery(parsed, haystack)) continue;
|
|
1067
|
+
if (parsed.filters.role !== "") {
|
|
1068
|
+
const role = String(message.role || "").toLowerCase();
|
|
1069
|
+
const wanted = parsed.filters.role;
|
|
1070
|
+
const userish = wanted === "user" || wanted === "me" || wanted === "我";
|
|
1071
|
+
const agentish = wanted === "assistant" || wanted === "agent" || wanted === "助手";
|
|
1072
|
+
if (userish && role !== "user") continue;
|
|
1073
|
+
if (agentish && role === "user") continue;
|
|
1074
|
+
}
|
|
1075
|
+
const needle = terms.length > 0 ? terms[0] : "";
|
|
1076
|
+
const { snippet, lead, tail } = searchSnippet(message.text, needle);
|
|
1077
|
+
const seeks = searchSeeks(message.text, needle);
|
|
1078
|
+
const context = searchContext(message.text, needle);
|
|
952
1079
|
const headerTitle = typeof session.header.title === "string" ? session.header.title.trim() : "";
|
|
953
1080
|
const cachedTitle = typeof cached.title === "string" ? cached.title.trim() : "";
|
|
954
1081
|
const cwd = normalizedPath(session.header.cwd);
|
|
@@ -968,7 +1095,7 @@ export async function searchSessions(ctx, query, options = {}) {
|
|
|
968
1095
|
seek: seeks.length > 0 ? seeks[0] : "",
|
|
969
1096
|
seeks,
|
|
970
1097
|
/* The matched neighbourhood, so reading a hit never needs the chat. */
|
|
971
|
-
context
|
|
1098
|
+
context,
|
|
972
1099
|
/* How many turns the session has, so the client can scroll to a rough
|
|
973
1100
|
position before looking for the text. */
|
|
974
1101
|
turns: maxTurn,
|
|
@@ -2265,7 +2392,14 @@ export async function handleSearchRequest(ctx, req, res) {
|
|
|
2265
2392
|
try {
|
|
2266
2393
|
const body = await readJsonBody(req);
|
|
2267
2394
|
const query = body !== null && typeof body.query === "string" ? body.query : "";
|
|
2268
|
-
|
|
2395
|
+
/* The panel's controls arrive as fields; typed `ws:` / `in:` / `role:` still
|
|
2396
|
+
work and the two are merged. */
|
|
2397
|
+
const result = await searchSessions(ctx, query, {
|
|
2398
|
+
refresh: body !== null && body.refresh === true,
|
|
2399
|
+
workspace: body !== null && typeof body.workspace === "string" ? body.workspace : "",
|
|
2400
|
+
session: body !== null && typeof body.session === "string" ? body.session : "",
|
|
2401
|
+
role: body !== null && typeof body.role === "string" ? body.role : "",
|
|
2402
|
+
});
|
|
2269
2403
|
sendJson(res, 200, result);
|
|
2270
2404
|
} catch (error) {
|
|
2271
2405
|
sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.1",
|
|
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",
|