dsh-ws-recency 0.31.1 → 0.32.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.
Files changed (4) hide show
  1. package/README.md +1 -0
  2. package/client.js +365 -127
  3. package/index.js +38 -1
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -168,6 +168,7 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
168
168
  - 搜的是**对话正文**:你的提问 + 助手的回复;不搜思维链、不搜工具参数和工具结果(那些会让命中被日志噪声淹没);
169
169
  - 多个词用空格分隔,**要求同时出现在同一条消息里**(AND);大小写不敏感,纯字面匹配,不支持正则;
170
170
  - 范围用**控件**选,不用记语法:搜索框下面有「工作区」下拉、「会话标题」输入框、「角色」三个按钮(全部 / 我 / 助手)。改控件会用当前关键词自动重搜;
171
+ - **只选范围、不输关键词也可以搜**:这时答案是「符合范围的会话列表」(标题、工作区、路径、时间),点一下就打开——用来找「那件事是哪个会话」。会话模式按会话标题匹配,不读正文,所以很快;
171
172
  - 搜索框里仍然可以写匹配方式:`"一个词组"`(整句匹配)、`a|b` 或 `a or b`(任一即可)、`-词`(排除);
172
173
  - 想用键盘也行:`ws:工作区`、`in:会话标题`、`role:user|assistant`,中文别名 `工作区:` / `会话:` / `角色:` 同样可用。控件与语法同时给出时,**以控件为准**(那是屏幕上看得见的选择);
173
174
  - 结果按新到旧排列,每条给出角色、会话标题、所属工作区、第几轮/第几步,以及带高亮的片段;
package/client.js CHANGED
@@ -362,15 +362,30 @@
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}",
373
- ".wsr-search-history{display:flex;align-items:center;flex-wrap:wrap;gap:6px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
365
+ /* A column flex box with a fixed height shrinks its children once the
366
+ content is taller than the box, and the shortest row goes first - that
367
+ is how the recent-searches row vanished only after a search returned
368
+ many results. Chrome keeps its size; the lists scroll. */
369
+ ".wsr-search-page > *{flex:0 0 auto}",
370
+ ".wsr-search-page > .wsr-page-list{flex:1 1 auto;min-height:0;overflow-y:auto}",
371
+ ".wsr-search-toolbar{display:flex;align-items:center;gap:8px;min-width:0}",
372
+ ".wsr-filters{display:flex;flex-wrap:wrap;align-items:center;gap:8px;flex:1;min-width:0;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
373
+ ".wsr-filter{display:inline-flex;align-items:center;gap:4px;min-width:0}",
374
+ ".wsr-filter-label{flex:none;color:var(--dsw-alias-label-tertiary)}",
375
+ ".wsr-filter-select,.wsr-filter-input{height:24px;box-sizing:border-box;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:170px}",
376
+ ".wsr-filter-input{width:120px}",
377
+ ".wsr-seg{display:inline-flex;height:24px;border-radius:6px;border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));overflow:hidden}",
378
+ ".wsr-seg-item{height:100%;padding:0 8px;border:none;border-left:.5px solid rgba(255,255,255,.12);background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;cursor:pointer}",
379
+ ".wsr-seg-item:first-child{border-left:none}",
380
+ ".wsr-seg-item:hover{color:var(--dsw-alias-label-primary)}",
381
+ ".wsr-seg-item-on{color:var(--dsw-alias-label-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f9df7) 16%,transparent)}",
382
+ ".wsr-help{flex:none;width:24px;height:24px;border-radius:50%;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}",
383
+ ".wsr-help:hover,.wsr-help-on{color:var(--dsw-alias-label-primary);border-color:rgba(255,255,255,.3)}",
384
+ ".wsr-search-hint{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}",
385
+ ".wsr-search-status{display:flex;flex-wrap:wrap;gap:4px 10px;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums;padding-top:3px;border-top:.5px solid rgba(255,255,255,.06)}",
386
+ ".wsr-search-group{font-size:11px;color:var(--dsw-alias-label-tertiary);padding:2px 0}",
387
+ ".wsr-btn-primary{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f9df7) 55%,transparent);color:var(--dsw-alias-label-primary)}",
388
+ ".wsr-search-history{display:flex;align-items:center;flex-wrap:nowrap;overflow-x:auto;gap:6px;font-size:11px;color:var(--dsw-alias-label-tertiary);scrollbar-width:none}",
374
389
  ".wsr-search-history-label{flex:none}",
375
390
  ".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}",
376
391
  ".wsr-search-chip-run{border:none;background:0 0;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:18px;padding:0 4px 0 8px;cursor:pointer;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
@@ -525,10 +540,13 @@
525
540
  "search.filterSessionPlaceholder": "包含…(回车)",
526
541
  "search.filterRole": "角色",
527
542
  "search.filterAll": "全部",
543
+ "search.sessionResults": "会话({n})",
528
544
  "search.history": "最近搜索",
529
545
  "search.historyRun": "再搜一次:{query}",
530
546
  "search.historyDrop": "从历史里删除",
531
547
  "search.historyClear": "清空",
548
+
549
+ "search.historyEmpty": "还没有记录",
532
550
  "search.step": "第 {n} 步",
533
551
  "search.jumpTurn": "已定位:第 {turn} 轮 · 按轮次",
534
552
  "search.jumpText": "已定位:第 {turn} 轮 · 按文字",
@@ -736,10 +754,13 @@
736
754
  "search.filterSessionPlaceholder": "title contains… (Enter)",
737
755
  "search.filterRole": "Role",
738
756
  "search.filterAll": "All",
757
+ "search.sessionResults": "Sessions ({n})",
739
758
  "search.history": "Recent",
740
759
  "search.historyRun": "Search again: {query}",
741
760
  "search.historyDrop": "Remove from history",
742
761
  "search.historyClear": "Clear",
762
+
763
+ "search.historyEmpty": "nothing yet",
743
764
  "search.step": "step {n}",
744
765
  "search.jumpTurn": "Landed on turn {turn} (by turn)",
745
766
  "search.jumpText": "Landed on turn {turn} (by text)",
@@ -3928,6 +3949,98 @@
3928
3949
  */
3929
3950
  var searchFilters = { workspace: "", session: "", role: "" };
3930
3951
 
3952
+ /**
3953
+ * Recent searches recorded since the plugin loaded.
3954
+ *
3955
+ * Shown merged with the store's own list. Freezing one copy of the store was
3956
+ * wrong: when the panel rendered before the store hydrated, that copy stayed
3957
+ * empty and every search looked like it wiped the history.
3958
+ */
3959
+ var searchHistoryMirror = [];
3960
+
3961
+ /** Keys removed here; hidden until the store drops them as well. */
3962
+ var historyDropped = {};
3963
+
3964
+ /** Set by "clear", so a store that has not caught up cannot restore them. */
3965
+ var historyCleared = false;
3966
+
3967
+ function mergedHistory(stored) {
3968
+ var storedList = Array.isArray(stored) ? stored : [];
3969
+ var out = [];
3970
+ var seen = {};
3971
+ var push = function (item) {
3972
+ var key = historyKey(item);
3973
+ if (seen[key] === true || historyDropped[key] === true) return;
3974
+ seen[key] = true;
3975
+ out.push(item);
3976
+ };
3977
+ for (var i = 0; i < searchHistoryMirror.length; i += 1) push(searchHistoryMirror[i]);
3978
+ if (!historyCleared) {
3979
+ for (var j = 0; j < storedList.length; j += 1) push(storedList[j]);
3980
+ } else if (storedList.length === 0) {
3981
+ historyCleared = false;
3982
+ }
3983
+ return out.slice(0, SEARCH_HISTORY_MAX);
3984
+ }
3985
+
3986
+ /** Bumped when a stored query restores the controls, so the title box remounts. */
3987
+ var filterEpoch = 0;
3988
+
3989
+ /**
3990
+ * One stored search: the words plus the scope they were run with.
3991
+ *
3992
+ * A query without its scope is an incomplete memory - "CDP" under one
3993
+ * workspace is not the same search as "CDP" everywhere - so both travel
3994
+ * together. Entries written by older versions were plain strings.
3995
+ */
3996
+ /** Separator for the stored form; a control character cannot appear in a query. */
3997
+ var HISTORY_SEP = "\u0001";
3998
+
3999
+ function historyEntry(item) {
4000
+ if (typeof item === "string") {
4001
+ var parts = item.split(HISTORY_SEP);
4002
+ return {
4003
+ query: parts[0] === undefined ? "" : parts[0],
4004
+ workspace: parts[1] === undefined ? "" : parts[1],
4005
+ session: parts[2] === undefined ? "" : parts[2],
4006
+ role: parts[3] === undefined ? "" : parts[3],
4007
+ };
4008
+ }
4009
+ if (item === null || typeof item !== "object") {
4010
+ return { query: "", workspace: "", session: "", role: "" };
4011
+ }
4012
+ return {
4013
+ query: typeof item.query === "string" ? item.query : "",
4014
+ workspace: typeof item.workspace === "string" ? item.workspace : "",
4015
+ session: typeof item.session === "string" ? item.session : "",
4016
+ role: typeof item.role === "string" ? item.role : "",
4017
+ };
4018
+ }
4019
+
4020
+ /** The stored form: one string, so the store keeps handling it like it always did. */
4021
+ function historyEncode(item) {
4022
+ var entry = historyEntry(item);
4023
+ return [entry.query, entry.workspace, entry.session, entry.role]
4024
+ .map(function (part) { return String(part).split(HISTORY_SEP).join(" "); })
4025
+ .join(HISTORY_SEP);
4026
+ }
4027
+
4028
+ function historyKey(item) {
4029
+ var entry = historyEntry(item);
4030
+ return entry.query + "\u0000" + entry.workspace + "\u0000" + entry.session + "\u0000" + entry.role;
4031
+ }
4032
+
4033
+ /** What a chip says: the words, plus whichever scope parts it carries. */
4034
+ function historyLabel(item) {
4035
+ var entry = historyEntry(item);
4036
+ var parts = [];
4037
+ if (entry.workspace !== "") parts.push(entry.workspace);
4038
+ if (entry.session !== "") parts.push("in:" + entry.session);
4039
+ if (entry.role !== "") parts.push(entry.role === "user" ? "me" : "assistant");
4040
+ var scope = parts.length > 0 ? " (" + parts.join(" · ") + ")" : "";
4041
+ return (entry.query === "" ? "(scope only)" : entry.query) + scope;
4042
+ }
4043
+
3931
4044
  /** How many recent queries the panel remembers. */
3932
4045
  var SEARCH_HISTORY_MAX = 12;
3933
4046
 
@@ -3974,6 +4087,9 @@
3974
4087
  * a synthetic scroll event is what lets the next page load.
3975
4088
  */
3976
4089
  function scrollTo(scroller, top) {
4090
+ /* Only used on the turn rail. No synthetic scroll event: the rail
4091
+ virtualises on scrollTop alone, and a fabricated event is one more
4092
+ thing the host can read as the reader moving. */
3977
4093
  if (scroller === null || scroller === undefined) return;
3978
4094
  var target = Math.max(0, Number(top) || 0);
3979
4095
  try {
@@ -3990,13 +4106,7 @@
3990
4106
  /* an engine without createEvent still got the assignment */
3991
4107
  }
3992
4108
  };
3993
- fire();
3994
- try {
3995
- if (typeof requestAnimationFrame === "function") requestAnimationFrame(fire);
3996
- else window.setTimeout(fire, 16);
3997
- } catch (error) {
3998
- /* the first dispatch is usually enough */
3999
- }
4109
+ void fire;
4000
4110
  }
4001
4111
  function conversationScroller() {
4002
4112
  if (typeof document === "undefined") return null;
@@ -4201,13 +4311,25 @@
4201
4311
  }
4202
4312
 
4203
4313
 
4204
- /** The rail mark for one turn, if the rail currently renders it. */
4314
+ /**
4315
+ * The rail mark for one turn, if that mark is actually on screen.
4316
+ *
4317
+ * The rail is part of the chat shell, and during a session switch two of
4318
+ * them can be in the document at once. Matching by turn number alone could
4319
+ * therefore click the departing session's rail and start a history load
4320
+ * nobody asked for, so the mark has to be visible to qualify.
4321
+ */
4205
4322
  function railMarkFor(turn) {
4206
4323
  var wanted = Number(turn);
4207
4324
  if (!isFinite(wanted)) return null;
4208
4325
  var marks = railMarks();
4209
4326
  for (var i = 0; i < marks.length; i += 1) {
4210
- if (turnOfRailMark(marks[i]) === wanted) return marks[i];
4327
+ if (turnOfRailMark(marks[i]) !== wanted) continue;
4328
+ var rect = typeof marks[i].getBoundingClientRect === "function"
4329
+ ? marks[i].getBoundingClientRect()
4330
+ : null;
4331
+ if (rect === null || !(rect.height > 0) || !(rect.width > 0)) continue;
4332
+ return marks[i];
4211
4333
  }
4212
4334
  return null;
4213
4335
  }
@@ -4669,21 +4791,60 @@
4669
4791
  return searchHitRow(props.hit, props.terms, props.onJump, extra);
4670
4792
  }
4671
4793
 
4794
+ /**
4795
+ * One session, for a search that narrowed by title or workspace only.
4796
+ *
4797
+ * Without words there is nothing to point at inside a transcript, so the
4798
+ * useful answer is the session itself: its title, where it lives, and when.
4799
+ */
4800
+ function SearchSessionRow(props) {
4801
+ var item = props.item;
4802
+ var when = formatWhen(Number(item.at) || 0);
4803
+ return h("div", {
4804
+ className: "wsr-hit wsr-session-hit",
4805
+ title: item.title || "",
4806
+ onClick: function () {
4807
+ if (typeof props.onOpen === "function") props.onOpen();
4808
+ },
4809
+ },
4810
+ h("div", { className: "wsr-hit-head" },
4811
+ h("span", { className: "wsr-hit-title", title: item.title || "" }, item.title || props.shortId),
4812
+ typeof item.workspace === "string" && item.workspace !== "" ? h("span", { className: "wsr-hit-ws" }, item.workspace) : null,
4813
+ ),
4814
+ h("div", { className: "wsr-hit-meta" },
4815
+ when !== "" ? h("span", { className: "wsr-hit-time" }, when) : null,
4816
+ typeof item.cwd === "string" && item.cwd !== "" ? h("span", { className: "wsr-hit-cwd" }, item.cwd) : null,
4817
+ ),
4818
+ h("div", { className: "wsr-hit-actions" },
4819
+ h("button", {
4820
+ type: "button",
4821
+ className: "wsr-hit-context-jump",
4822
+ onClick: function (event) {
4823
+ if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
4824
+ if (typeof props.onOpen === "function") props.onOpen();
4825
+ },
4826
+ }, t("search.openSession")),
4827
+ ),
4828
+ );
4829
+ }
4830
+
4672
4831
  function SearchPanelPage(props) {
4673
4832
  var state = react.useState(searchLast === null
4674
- ? { loaded: false, query: "", hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" }
4833
+ ? { loaded: false, query: "", hits: [], sessions: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" }
4675
4834
  : searchLast);
4676
4835
  var view = state[0];
4677
4836
  var setView = state[1];
4837
+ /* The syntax hint is reference material, not a permanent line. */
4838
+ var help = react.useState(false);
4678
4839
  /* The recent-query list lives in the shared store, so it survives a
4679
4840
  restart and is the same list on every panel. */
4680
4841
  var preferences = props !== undefined && props !== null && typeof props.useStore === "function"
4681
4842
  ? props.useStore(function (snapshot) { return snapshot; })
4682
4843
  : (data.settings || {});
4683
4844
  var actions = props !== undefined && props !== null && props.actions !== undefined ? props.actions : {};
4684
- var historyList = preferences !== null && preferences !== undefined && Array.isArray(preferences.searchHistory)
4685
- ? preferences.searchHistory
4686
- : [];
4845
+ var storedHistory = preferences !== null && preferences !== undefined
4846
+ && Array.isArray(preferences.searchHistory) ? preferences.searchHistory : [];
4847
+ var historyList = mergedHistory(storedHistory);
4687
4848
  /* Every update also parks the answer outside the component, so coming
4688
4849
  back from a hit restores the list instead of asking for a new search. */
4689
4850
  var commit = function (next) {
@@ -4701,11 +4862,29 @@
4701
4862
  var query = typeof text === "string" ? text.trim() : "";
4702
4863
  searchGeneration += 1;
4703
4864
  var generation = searchGeneration;
4704
- if (query === "") {
4865
+ /* A filter alone is a question too: "which session was that?". */
4866
+ var hasFilters = searchFilters.workspace !== "" || searchFilters.session !== ""
4867
+ || searchFilters.role !== "";
4868
+ if (query === "" && !hasFilters) {
4705
4869
  commit({ loaded: true, query: "", hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" });
4706
4870
  return;
4707
4871
  }
4708
- if (typeof actions.pushSearch === "function") actions.pushSearch(query);
4872
+ var entry = {
4873
+ query: query,
4874
+ workspace: searchFilters.workspace,
4875
+ session: searchFilters.session,
4876
+ role: searchFilters.role,
4877
+ };
4878
+ if (typeof actions.pushSearch === "function") actions.pushSearch(entry);
4879
+ var entryKey = historyKey(entry);
4880
+ if (historyDropped[entryKey] === true) delete historyDropped[entryKey];
4881
+ var nextMirror = [historyEncode(entry)];
4882
+ for (var hi = 0; hi < searchHistoryMirror.length && nextMirror.length < SEARCH_HISTORY_MAX; hi += 1) {
4883
+ if (historyKey(searchHistoryMirror[hi]) === entryKey) continue;
4884
+ nextMirror.push(searchHistoryMirror[hi]);
4885
+ }
4886
+ searchHistoryMirror = nextMirror;
4887
+ historyCleared = false;
4709
4888
  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: "" });
4710
4889
  var ask = function (needRefresh) {
4711
4890
  searchPost({
@@ -4725,6 +4904,7 @@
4725
4904
  loaded: true,
4726
4905
  query: query,
4727
4906
  hits: Array.isArray(json.hits) ? json.hits : [],
4907
+ sessions: Array.isArray(json.sessions) ? json.sessions : [],
4728
4908
  terms: Array.isArray(json.terms) ? json.terms : [],
4729
4909
  scanned: json.scanned || 0,
4730
4910
  total: json.total || 0,
@@ -4763,6 +4943,16 @@
4763
4943
  },
4764
4944
  });
4765
4945
 
4946
+ var sessionRows = (Array.isArray(view.sessions) ? view.sessions : []).map(function (item, index) {
4947
+ var row = h(SearchSessionRow, {
4948
+ item: item,
4949
+ shortId: shortSessionId(String(item.sessionId || "")),
4950
+ onOpen: function () { openSessionRow(item.sessionId); },
4951
+ });
4952
+ row.key = "session:" + String(item.sessionId || index);
4953
+ return row;
4954
+ });
4955
+
4766
4956
  var rows = view.hits.map(function (hit, index) {
4767
4957
  var row = h(SearchHitRow, {
4768
4958
  hit: hit,
@@ -4777,20 +4967,115 @@
4777
4967
  h("div", { className: "wsr-page-head" },
4778
4968
  h("div", { className: "wsr-page-heading" }, t("search.title")),
4779
4969
  ),
4780
- historyList.length === 0 ? null : h("div", { className: "wsr-search-history" },
4970
+ h("div", { className: "wsr-search-toolbar" },
4971
+ h("div", { className: "wsr-filters" },
4972
+ h("label", { className: "wsr-filter" },
4973
+ h("span", { className: "wsr-filter-label" }, t("search.filterWorkspace")),
4974
+ h("select", {
4975
+ className: "wsr-filter-select",
4976
+ value: searchFilters.workspace,
4977
+ onChange: function (event) {
4978
+ searchFilters.workspace = event.target.value || "";
4979
+ rerun();
4980
+ },
4981
+ },
4982
+ h("option", { value: "" }, t("search.filterAll")),
4983
+ (function () {
4984
+ var items = data.workspaces !== null && data.workspaces !== undefined
4985
+ && Array.isArray(data.workspaces.items) ? data.workspaces.items : [];
4986
+ var options = [];
4987
+ for (var wi = 0; wi < items.length; wi += 1) {
4988
+ var name = typeof items[wi].name === "string" && items[wi].name !== ""
4989
+ ? items[wi].name
4990
+ : String(items[wi].title || "");
4991
+ if (name === "") continue;
4992
+ options.push(h("option", { value: name, key: "ws:" + name }, name));
4993
+ }
4994
+ return options;
4995
+ })(),
4996
+ ),
4997
+ ),
4998
+ h("label", { className: "wsr-filter" },
4999
+ h("span", { className: "wsr-filter-label" }, t("search.filterSession")),
5000
+ h("input", {
5001
+ type: "text",
5002
+ key: "wsr-filter-session:" + String(filterEpoch),
5003
+ className: "wsr-filter-input",
5004
+ defaultValue: searchFilters.session,
5005
+ placeholder: t("search.filterSessionPlaceholder"),
5006
+ onChange: function (event) {
5007
+ searchFilters.session = String(event.target.value || "").trim();
5008
+ },
5009
+ onKeyDown: function (event) {
5010
+ if (event !== undefined && event.key === "Enter") {
5011
+ event.preventDefault();
5012
+ rerun();
5013
+ }
5014
+ },
5015
+ }),
5016
+ ),
5017
+ h("span", { className: "wsr-filter" },
5018
+ h("span", { className: "wsr-filter-label" }, t("search.filterRole")),
5019
+ h("span", { className: "wsr-seg" },
5020
+ (function () {
5021
+ var roles = [
5022
+ ["", "search.filterAll"],
5023
+ ["user", "search.you"],
5024
+ ["assistant", "search.assistant"],
5025
+ ];
5026
+ var buttons = [];
5027
+ for (var ri = 0; ri < roles.length; ri += 1) {
5028
+ (function (value, label) {
5029
+ buttons.push(h("button", {
5030
+ type: "button",
5031
+ key: "role:" + value,
5032
+ className: "wsr-seg-item" + (searchFilters.role === value ? " wsr-seg-item-on" : ""),
5033
+ onClick: function () {
5034
+ searchFilters.role = value;
5035
+ rerun();
5036
+ },
5037
+ }, t(label)));
5038
+ })(roles[ri][0], roles[ri][1]);
5039
+ }
5040
+ return buttons;
5041
+ })(),
5042
+ ),
5043
+ ),
5044
+ ),
5045
+ h("button", {
5046
+ type: "button",
5047
+ className: "wsr-help" + (help[0] === true ? " wsr-help-on" : ""),
5048
+ title: t("search.hint"),
5049
+ "aria-label": t("search.hint"),
5050
+ onClick: function () { help[1](help[0] !== true); },
5051
+ }, "?"),
5052
+ ),
5053
+ help[0] === true ? h("div", { className: "wsr-search-hint" }, t("search.hint")) : null,
5054
+ h("div", { className: "wsr-search-bar" },
5055
+ input,
5056
+ h("button", { type: "button", className: "wsr-btn wsr-btn-primary", onClick: function () { run(searchDraft, false); } }, t("search.run")),
5057
+ ),
5058
+ h("div", { className: "wsr-search-history" },
4781
5059
  h("span", { className: "wsr-search-history-label" }, t("search.history")),
4782
5060
  historyList.map(function (item, index) {
4783
- var text = String(item);
4784
- return h("span", { className: "wsr-search-chip", key: text + ":" + String(index) },
5061
+ var entry = historyEntry(item);
5062
+ var label = historyLabel(entry);
5063
+ return h("span", { className: "wsr-search-chip", key: historyKey(entry) + ":" + String(index) },
4785
5064
  h("button", {
4786
5065
  type: "button",
4787
5066
  className: "wsr-search-chip-run",
4788
- title: t("search.historyRun", { query: text }),
5067
+ title: t("search.historyRun", { query: label }),
4789
5068
  onClick: function () {
4790
- searchDraft = text;
4791
- run(text, false);
4792
- },
4793
- }, text),
5069
+ /* Restore the scope too: the words alone would answer a
5070
+ different question than the one that was asked. */
5071
+ searchFilters.workspace = entry.workspace;
5072
+ searchFilters.session = entry.session;
5073
+ searchFilters.role = entry.role;
5074
+ filterEpoch += 1;
5075
+ searchDraft = entry.query;
5076
+ run(entry.query, false);
5077
+ },
5078
+ }, label),
4794
5079
  h("button", {
4795
5080
  type: "button",
4796
5081
  className: "wsr-search-chip-drop",
@@ -4798,102 +5083,50 @@
4798
5083
  "aria-label": t("search.historyDrop"),
4799
5084
  onClick: function (event) {
4800
5085
  if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
4801
- if (typeof actions.dropSearch === "function") actions.dropSearch(text);
5086
+ if (typeof actions.dropSearch === "function") actions.dropSearch(entry);
5087
+ var dropKey = historyKey(entry);
5088
+ historyDropped[dropKey] = true;
5089
+ searchHistoryMirror = searchHistoryMirror.filter(function (item) {
5090
+ return historyKey(item) !== dropKey;
5091
+ });
5092
+ commit(Object.assign({}, view));
4802
5093
  },
4803
5094
  }, "\u00d7"),
4804
5095
  );
4805
5096
  }),
5097
+ historyList.length === 0
5098
+ ? h("span", { className: "wsr-search-history-empty" }, t("search.historyEmpty"))
5099
+ : null,
4806
5100
  h("button", {
4807
5101
  type: "button",
4808
5102
  className: "wsr-search-history-clear",
4809
5103
  onClick: function () {
4810
5104
  if (typeof actions.clearSearches === "function") actions.clearSearches();
5105
+ searchHistoryMirror = [];
5106
+ historyDropped = {};
5107
+ historyCleared = true;
5108
+ commit(Object.assign({}, view));
4811
5109
  },
4812
5110
  }, t("search.historyClear")),
4813
5111
  ),
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" },
4888
- input,
4889
- h("button", { type: "button", className: "wsr-btn", onClick: function () { run(searchDraft, false); } }, t("search.run")),
5112
+ h("div", { className: "wsr-search-status" },
5113
+ view.busy ? t("search.searching") : null,
5114
+ view.error !== "" ? view.error : null,
5115
+ view.pending > 0 ? t("search.indexing", { n: String(view.pending) }) : null,
5116
+ view.loaded && !view.busy && view.error === ""
5117
+ ? t("search.summary", { hits: String(view.hits.length), sessions: String(view.total), ms: String(view.took) })
5118
+ : null,
4890
5119
  ),
4891
- view.busy ? h("div", { className: "wsr-page-note" }, t("search.searching")) : null,
4892
- view.error !== "" ? h("div", { className: "wsr-page-note wsr-page-error" }, view.error) : null,
4893
- view.pending > 0 ? h("div", { className: "wsr-page-note" }, t("search.indexing", { n: String(view.pending) })) : null,
4894
- view.loaded && !view.busy ? h("div", { className: "wsr-page-note" }, t("search.summary", { hits: String(view.hits.length), sessions: String(view.total), ms: String(view.took) })) : null,
4895
- view.loaded && !view.busy && view.hits.length === 0 ? h("div", { className: "wsr-page-note" }, t("search.empty")) : null,
4896
- h("div", { className: "wsr-page-list" }, rows),
5120
+ view.loaded && !view.busy && view.hits.length === 0 && sessionRows.length === 0
5121
+ ? h("div", { className: "wsr-page-note" }, t("search.empty"))
5122
+ : null,
5123
+ sessionRows.length > 0
5124
+ ? h("div", { className: "wsr-page-list" },
5125
+ h("div", { className: "wsr-search-group" }, t("search.sessionResults", { n: String(sessionRows.length) })),
5126
+ sessionRows,
5127
+ )
5128
+ : null,
5129
+ sessionRows.length === 0 ? h("div", { className: "wsr-page-list" }, rows) : null,
4897
5130
  );
4898
5131
  }
4899
5132
 
@@ -5351,25 +5584,25 @@
5351
5584
  if (draft.followUps === null || typeof draft.followUps !== "object") return;
5352
5585
  if (draft.followUps[sessionId] !== undefined) delete draft.followUps[sessionId];
5353
5586
  },
5354
- /* Recent queries, newest first, case-insensitively de-duplicated. */
5355
- pushSearch: function (draft, query) {
5356
- var text = typeof query === "string" ? query.trim() : "";
5357
- if (text === "") return;
5587
+ /* One entry per distinct search, newest first; identical searches
5588
+ move to the front instead of appearing twice. */
5589
+ pushSearch: function (draft, entry) {
5590
+ var item = historyEntry(entry);
5591
+ if (item.query === "" && item.workspace === "" && item.session === "" && item.role === "") return;
5358
5592
  var list = Array.isArray(draft.searchHistory) ? draft.searchHistory : [];
5359
- var lower = text.toLowerCase();
5360
- var next = [text];
5593
+ var key = historyKey(item);
5594
+ var next = [historyEncode(item)];
5361
5595
  for (var i = 0; i < list.length && next.length < SEARCH_HISTORY_MAX; i += 1) {
5362
- if (String(list[i]).toLowerCase() === lower) continue;
5363
- next.push(list[i]);
5596
+ if (historyKey(list[i]) === key) continue;
5597
+ next.push(historyEncode(list[i]));
5364
5598
  }
5365
5599
  draft.searchHistory = next;
5366
5600
  },
5367
- dropSearch: function (draft, query) {
5368
- var text = typeof query === "string" ? query.trim().toLowerCase() : "";
5369
- if (text === "") return;
5601
+ dropSearch: function (draft, entry) {
5602
+ var key = historyKey(entry);
5370
5603
  var list = Array.isArray(draft.searchHistory) ? draft.searchHistory : [];
5371
5604
  draft.searchHistory = list.filter(function (item) {
5372
- return String(item).trim().toLowerCase() !== text;
5605
+ return historyKey(item) !== key;
5373
5606
  });
5374
5607
  },
5375
5608
  clearSearches: function (draft) {
@@ -5619,6 +5852,11 @@
5619
5852
  hitRow: searchHitRow,
5620
5853
  shortId: shortSessionId,
5621
5854
  resumePasses: function () { suppressedUntil = 0; },
5855
+ filters: function () { return searchFilters; },
5856
+ resetHistoryMirror: function () { searchHistoryMirror = []; historyDropped = {}; historyCleared = false; },
5857
+ encodeSearch: historyEncode,
5858
+ decodeSearch: historyEntry,
5859
+ searchLabel: historyLabel,
5622
5860
  };
5623
5861
 
5624
5862
  /* The search feature ships disabled while its cost is being isolated;
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.31.1";
35
+ export const HOST_VERSION = "0.32.1";
36
36
 
37
37
  /**
38
38
  * Exact routes the client half calls. Registered on the bare web server, so they
@@ -1000,6 +1000,43 @@ export async function searchSessions(ctx, query, options = {}) {
1000
1000
  }
1001
1001
  sessions.sort((a, b) => b.updatedAt - a.updatedAt);
1002
1002
 
1003
+ /* No words, but a filter: the question is "which session was that?", so the
1004
+ answer is sessions, not messages. Listing them needs no transcript work. */
1005
+ if (parsed.terms.length === 0 && parsed.groups.length === 0) {
1006
+ const matchedSessions = [];
1007
+ for (const session of sessions) {
1008
+ const cwd = normalizedPath(session.header.cwd);
1009
+ if (parsed.filters.workspace !== "") {
1010
+ const name = String(workspaceByPath.get(cwd) ?? "").toLowerCase();
1011
+ if (name.indexOf(parsed.filters.workspace) === -1) continue;
1012
+ }
1013
+ if (parsed.filters.session !== "") {
1014
+ const headerTitle = typeof session.header.title === "string" ? session.header.title.toLowerCase() : "";
1015
+ if (headerTitle.indexOf(parsed.filters.session) === -1) continue;
1016
+ }
1017
+ matchedSessions.push({
1018
+ sessionId: session.id,
1019
+ title: typeof session.header.title === "string" ? session.header.title : "",
1020
+ workspace: workspaceByPath.get(cwd) ?? "",
1021
+ cwd: typeof session.header.cwd === "string" ? session.header.cwd : "",
1022
+ at: session.updatedAt,
1023
+ sizeBytes: session.sizeBytes,
1024
+ });
1025
+ if (matchedSessions.length >= SEARCH_TOTAL_CAP) break;
1026
+ }
1027
+ return {
1028
+ ok: true,
1029
+ query: "",
1030
+ terms: [],
1031
+ hits: [],
1032
+ sessions: matchedSessions,
1033
+ scanned: sessions.length,
1034
+ total: sessions.length,
1035
+ pending: 0,
1036
+ took: Date.now() - started,
1037
+ };
1038
+ }
1039
+
1003
1040
  const refresh = options.refresh === true;
1004
1041
  const hits = [];
1005
1042
  let scanned = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.31.1",
3
+ "version": "0.32.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",