dsh-ws-recency 0.32.1 → 0.33.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.
Files changed (4) hide show
  1. package/README.md +8 -0
  2. package/client.js +250 -32
  3. package/index.js +49 -13
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -175,6 +175,8 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
175
175
  - 每条结果有两个动作:`看上下文` 在行内展开命中处前后各约 400 字(不碰聊天区,长会话也不卡),`打开会话` 才真的跳转;
176
176
  - 搜索过的词会记进「最近搜索」,点一下重搜、点 × 删一条、右侧「清空」全清,重启后还在。
177
177
  - 点「打开会话」:打开那个会话 → 点右侧竖条上对应轮次的格子(这是宿主自己的跳转入口,会连带加载那一段历史)→ 关键词在正文里高亮。**跳转本身可能等几秒到十几秒**,那是宿主加载历史的时间;插件自己在浮标里报的那点是几十毫秒级。
178
+ - 命中离最新一轮太远时(默认超过 40 轮)会先问一句:「只看上下文」还是「仍然跳过去」。额度可在设置里改,填 0 就是每次都直接跳。
179
+ - 跳转期间浮标会显示「正在加载第 N 轮… 已等 Xs」,只有真正落到那一轮才换成「已定位」——之前是点击瞬间就报成功,于是界面在转、提示却说好了。
178
180
  - 第一次搜索要为每个会话建一次正文索引(存在 `~/.hypers-work/.wsr/search/<sessionId>.json`,按日志大小 + revision 决定是否失效)。面板顶部会显示「还有 N 个会话正在建立索引」,每轮补一批、结果自动刷新,之后同一份日志不再重复解码。
179
181
 
180
182
  ## 设置
@@ -188,6 +190,12 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
188
190
 
189
191
  偏好持久化在 Client store 的 `dsh.ws-recency.prefs.v1`。
190
192
 
193
+ ## 局域网 / 网关访问
194
+
195
+ 插件的宿主路由(删除、回收站、统计、搜索、移动、交接)会校验请求来源:只接受**同源**请求,也就是 `Origin` 指向的 host 与请求的 `Host`(或代理的 `X-Forwarded-Host`)一致;没有 `Origin` 的非浏览器请求照旧放行。
196
+
197
+ 所以用 `dsh-gateway` 之类的转接插件、或直接从局域网 IP 访问时,删除和统计都能正常用;只有**真正的跨站页面**会被 403 拒绝。0.32.1 及更早的版本只认回环地址,非回环访问一律 403(issue #3)。
198
+
191
199
  ## 已知边界
192
200
 
193
201
  - 依赖宿主 DOM:分组容器带 `_groupSection`、分组头带 `data-row-key="workspace:<id>"`、行带 `data-row-key="session:<id>"`、溢出按钮类名含 `sessionOverflowButton`。宿主改结构就要跟着改。
package/client.js CHANGED
@@ -75,6 +75,10 @@
75
75
  var MIN_DAYS = 1;
76
76
  var MAX_DAYS = 90;
77
77
  var DEFAULT_DAYS = 3;
78
+
79
+ /** Turns behind the newest that make a jump ask first; 0 disables asking. */
80
+ var DEFAULT_COLD_JUMP = 40;
81
+ var MAX_COLD_JUMP = 500;
78
82
  /** Safety stop for driving the host's own "show more" (5 rows per click). */
79
83
  var MAX_EXPAND_CLICKS = 40;
80
84
  var TICK_MS = 5 * 60 * 1000;
@@ -410,6 +414,7 @@
410
414
  ".wsr-hit-step{flex:none;color:var(--dsw-alias-label-secondary)}",
411
415
  ".wsr-jump-toast{position:fixed;left:50%;bottom:28px;transform:translateX(-50%);z-index:9999;padding:6px 12px;border-radius:8px;font-size:12px;background:var(--dsw-alias-bg-layer-3,rgba(32,34,38,.96));color:var(--dsw-alias-label-primary);border:.5px solid var(--dsw-alias-border-l2,rgba(255,255,255,.14));box-shadow:0 8px 24px rgba(0,0,0,.4);pointer-events:none}",
412
416
  ".wsr-diagnose-toast{max-width:min(680px,90vw);white-space:normal;line-height:1.6;text-align:left;font-variant-numeric:tabular-nums}",
417
+ ".wsr-jump-loading{color:var(--dsw-alias-label-secondary)}",
413
418
  ".wsr-jump-toast-warn{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#d9534f) 45%,transparent);color:var(--dsw-alias-state-error-primary,#d9534f)}",
414
419
  ".wsr-hit-cwd{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl;text-align:left}",
415
420
  ".wsr-mark{background:rgba(79,142,247,.28);color:inherit;border-radius:2px}",
@@ -533,6 +538,11 @@
533
538
  "diagnose.report": "近 60 秒:扫描 {passes} 次 / 共 {total}ms / 最慢 {worst}ms · 页面节点 {nodes} · 已挂载轮次 {turns}",
534
539
  "search.contextShow": "看上下文",
535
540
  "search.contextHide": "收起",
541
+ "search.coldJump": "这一轮在最新一轮之前 {behind} 轮,跳过去要加载大量历史,可能十几秒。",
542
+ "search.coldContext": "只看上下文",
543
+ "search.coldJumpAnyway": "仍然跳过去",
544
+ "search.settings.coldTitle": "跳转前确认",
545
+ "search.settings.coldDesc": "命中离最新一轮超过这么多轮时先问一句;0 表示每次都直接跳。",
536
546
  "search.openSession": "打开会话",
537
547
  "search.hint": "空格=都要有 · \"词组\" · a|b 或 · -排除",
538
548
  "search.filterWorkspace": "工作区",
@@ -548,6 +558,8 @@
548
558
 
549
559
  "search.historyEmpty": "还没有记录",
550
560
  "search.step": "第 {n} 步",
561
+ "search.jumpLoading": "正在加载第 {turn} 轮… {secs}s",
562
+ "search.jumpLoadingCold": "正在加载第 {turn} 轮(历史较早,可能要十几秒)… {secs}s",
551
563
  "search.jumpTurn": "已定位:第 {turn} 轮 · 按轮次",
552
564
  "search.jumpText": "已定位:第 {turn} 轮 · 按文字",
553
565
  "search.jumpNoSession": "打不开这个会话(可能已归档、或不在当前工作区)",
@@ -747,6 +759,11 @@
747
759
  "diagnose.report": "Last 60s: {passes} passes / {total}ms total / {worst}ms worst · {nodes} nodes · {turns} turns mounted",
748
760
  "search.contextShow": "Show context",
749
761
  "search.contextHide": "Hide",
762
+ "search.coldJump": "This turn is {behind} turns behind the newest one; jumping there loads a lot of history and can take a while.",
763
+ "search.coldContext": "Show context",
764
+ "search.coldJumpAnyway": "Jump anyway",
765
+ "search.settings.coldTitle": "Ask before a long jump",
766
+ "search.settings.coldDesc": "Ask when a hit is this many turns behind the newest one; 0 jumps every time.",
750
767
  "search.openSession": "Open session",
751
768
  "search.hint": "space = all of them · \"phrase\" · a|b either · -exclude",
752
769
  "search.filterWorkspace": "Workspace",
@@ -762,6 +779,8 @@
762
779
 
763
780
  "search.historyEmpty": "nothing yet",
764
781
  "search.step": "step {n}",
782
+ "search.jumpLoading": "Loading turn {turn}… {secs}s",
783
+ "search.jumpLoadingCold": "Loading turn {turn} (older history, this can take a while)… {secs}s",
765
784
  "search.jumpTurn": "Landed on turn {turn} (by turn)",
766
785
  "search.jumpText": "Landed on turn {turn} (by text)",
767
786
  "search.jumpNoSession": "Could not open that session (archived, or outside the current workspace)",
@@ -3821,6 +3840,43 @@
3821
3840
  }, t("menu.stats"));
3822
3841
  }
3823
3842
 
3843
+ /** Settings -> General row: ask before a jump that loads a lot of history. */
3844
+ function ColdJumpRow(props) {
3845
+ var settings = props.useStore(function (state) { return state; });
3846
+ var value = Number(settings.coldJumpTurns);
3847
+ if (!Number.isFinite(value)) value = DEFAULT_COLD_JUMP;
3848
+ var text = t("search.settings.coldTitle");
3849
+ return h("div", { className: "wsr-setRow" },
3850
+ h("div", { className: "wsr-setText" },
3851
+ h("div", { className: "wsr-setTitle" }, text),
3852
+ h("div", { className: "wsr-setDesc" }, t("search.settings.coldDesc")),
3853
+ ),
3854
+ h("div", { className: "wsr-controls" },
3855
+ h("button", {
3856
+ type: "button",
3857
+ className: "wsr-step",
3858
+ "aria-label": text + " -1",
3859
+ onClick: function () { props.actions.setColdJumpTurns(value - 10); },
3860
+ }, "-"),
3861
+ h("input", {
3862
+ type: "number",
3863
+ className: "wsr-input",
3864
+ min: 0,
3865
+ max: MAX_COLD_JUMP,
3866
+ value: String(value),
3867
+ "aria-label": text,
3868
+ onChange: function (event) { props.actions.setColdJumpTurns(event.target.value); },
3869
+ }),
3870
+ h("button", {
3871
+ type: "button",
3872
+ className: "wsr-step",
3873
+ "aria-label": text + " +1",
3874
+ onClick: function () { props.actions.setColdJumpTurns(value + 10); },
3875
+ }, "+"),
3876
+ ),
3877
+ );
3878
+ }
3879
+
3824
3880
  /** Settings -> General row: how old a session must be before it is folded. */
3825
3881
  function SettingsRow(props) {
3826
3882
  var settings = props.useStore(function (state) { return state; });
@@ -4146,9 +4202,68 @@
4146
4202
  }
4147
4203
  }
4148
4204
 
4205
+ /** The progress line shown while a jump waits for the host. */
4206
+ var jumpNote = null;
4207
+ var jumpNoteTimer = 0;
4208
+ var jumpNoteStarted = 0;
4209
+
4210
+ function clearJumpNote() {
4211
+ try {
4212
+ if (jumpNoteTimer !== 0) {
4213
+ window.clearInterval(jumpNoteTimer);
4214
+ jumpNoteTimer = 0;
4215
+ }
4216
+ if (jumpNote !== null && jumpNote !== undefined) {
4217
+ if (jumpNote.parentElement !== null && jumpNote.parentElement !== undefined) jumpNote.remove();
4218
+ jumpNote = null;
4219
+ }
4220
+ } catch (error) {
4221
+ /* nothing to clean up */
4222
+ }
4223
+ }
4224
+
4225
+ /**
4226
+ * Say that history is being loaded, and for how long.
4227
+ *
4228
+ * Clicking a rail cell starts a real page load in the host; on a long
4229
+ * session that takes seconds. The old code announced "landed" at the moment
4230
+ * of the click, so the window looked frozen with a success note already on
4231
+ * screen.
4232
+ */
4233
+ function announceJumpLoading(hit) {
4234
+ if (typeof document === "undefined") return;
4235
+ clearJumpNote();
4236
+ jumpNoteStarted = Date.now();
4237
+ /* Far behind the newest turn: say so, because the wait is proportional. */
4238
+ var cold = Number(hit.turns) - Number(hit.turn) > 40;
4239
+ var text = function () {
4240
+ var secs = String(Math.max(0, Math.round((Date.now() - jumpNoteStarted) / 1000)));
4241
+ return cold
4242
+ ? t("search.jumpLoadingCold", { turn: String(hit.turn), secs: secs })
4243
+ : t("search.jumpLoading", { turn: String(hit.turn), secs: secs });
4244
+ };
4245
+ try {
4246
+ var note = statsDiv("wsr-jump-toast wsr-jump-loading");
4247
+ note.textContent = text();
4248
+ document.body.appendChild(note);
4249
+ jumpNote = note;
4250
+ jumpNoteTimer = window.setInterval(function () {
4251
+ if (jumpNote === null || jumpNote === undefined) return;
4252
+ try {
4253
+ jumpNote.textContent = text();
4254
+ } catch (error) {
4255
+ clearJumpNote();
4256
+ }
4257
+ }, 500);
4258
+ } catch (error) {
4259
+ /* a toast is a nicety: never break the jump for it */
4260
+ }
4261
+ }
4262
+
4149
4263
  /** A short-lived line that says where the jump landed and how it got there. */
4150
4264
  function announceJump(hit, byText, costMs) {
4151
4265
  if (typeof document === "undefined") return;
4266
+ clearJumpNote();
4152
4267
  try {
4153
4268
  var note = statsDiv("wsr-jump-toast");
4154
4269
  var text = t(byText === true ? "search.jumpText" : "search.jumpTurn", { turn: String(hit.turn) });
@@ -4172,6 +4287,7 @@
4172
4287
  */
4173
4288
  function announceJumpFailure(hit, reason) {
4174
4289
  if (typeof document === "undefined") return;
4290
+ clearJumpNote();
4175
4291
  try {
4176
4292
  var note = statsDiv("wsr-jump-toast wsr-jump-toast-warn");
4177
4293
  note.textContent = t(reason, { turn: String(hit.turn), turns: String(hit.turns) });
@@ -4493,31 +4609,56 @@
4493
4609
  * One last look after a rail click: the host is loading a whole page of
4494
4610
  * history, so nothing here may poll while that runs.
4495
4611
  */
4496
- function finaliseJump(hit, terms) {
4612
+ /**
4613
+ * Look for the landed turn, and keep looking while the host pages in.
4614
+ *
4615
+ * `settle` is what makes the progress note honest: it only turns into
4616
+ * "landed" once the turn is actually in the document.
4617
+ */
4618
+ /**
4619
+ * Watch for the landing and stop counting as soon as it happens.
4620
+ *
4621
+ * The row appearing is the landing: the host moves the viewport and mounts
4622
+ * the turn, and on a session whose turns hold dozens of steps the body can
4623
+ * take many more seconds to render than the move itself. Requiring the
4624
+ * matched text before declaring success reported "not found" for jumps that
4625
+ * had visibly worked, and kept the progress note counting to its deadline.
4626
+ */
4627
+ function settleJump(hit, terms, attempt, spentMs) {
4497
4628
  if (typeof document === "undefined") return;
4498
- var began = Date.now();
4499
4629
  var seeks = Array.isArray(hit.seeks) ? hit.seeks : hit.seek;
4500
- var scroller = conversationScroller();
4501
- if (scroller !== null) {
4502
- var row = findByText(scroller, seeks);
4503
- if (row !== null) flashTurnRow(row);
4630
+ var row = turnRowOf(Number(hit.turn));
4631
+ if (row === null) {
4632
+ /* The row can be missing while the window is still being replaced; the
4633
+ text search is only a fallback for the case the row never appears. */
4634
+ var scroller = conversationScroller();
4635
+ if (scroller !== null) row = findByText(scroller, seeks);
4636
+ }
4637
+ if (row !== null) {
4638
+ clearJumpNote();
4639
+ flashTurnRow(row);
4640
+ announceJump(hit, false, spentMs);
4641
+ markHitTerms(terms);
4642
+ suppressedUntil = 0;
4643
+ schedule();
4644
+ return;
4504
4645
  }
4505
- markHitTerms(terms);
4506
- /* Anything past a frame is ours to answer for, so say so rather than
4507
- letting it pass as the host being slow. */
4508
- var spent = Date.now() - began;
4509
- if (spent > 120 && typeof window !== "undefined") {
4510
- window.__DSH_WSR_LAST_TAIL_MS__ = spent;
4646
+ /* Roughly ten seconds: past that the host is not going to land it, and
4647
+ the note should stop pretending to know. */
4648
+ if (attempt < 14) {
4649
+ window.setTimeout(function () { settleJump(hit, terms, attempt + 1, spentMs); }, 700);
4650
+ return;
4511
4651
  }
4652
+ announceJumpFailure(hit, "search.jumpNoTurn");
4512
4653
  }
4654
+
4513
4655
  /**
4514
4656
  * Bring one search hit into view.
4515
4657
  *
4516
- * Scrolling the transcript does not page older history in: the chat asks the
4517
- * user to load it, while clicking the turn rail's mark loads and aligns that
4518
- * turn. The rail is therefore the primary route. Everything here is kept
4519
- * to a few cheap lookups: the host is rendering history at the same time,
4520
- * and a polling loop on top of that is what made the jump feel frozen.
4658
+ * Scrolling does not page older history in; clicking the rail's cell for the
4659
+ * turn does, so that is the route. Everything else here is a cheap poll that
4660
+ * stops as soon as the click has been made - the landing is decided by
4661
+ * settleJump, not by this loop.
4521
4662
  */
4522
4663
  function revealHit(hit, terms) {
4523
4664
  if (typeof document === "undefined" || hit === null || hit === undefined) return;
@@ -4532,14 +4673,10 @@
4532
4673
  /* Wall time includes the host opening the session and loading its
4533
4674
  history; only the synchronous work in here belongs to this plugin. */
4534
4675
  var spentMs = 0;
4535
- var started = Date.now();
4536
4676
  var tick = function () {
4537
4677
  var beganTick = Date.now();
4538
- var done = function () {
4539
- spentMs += Date.now() - beganTick;
4540
- };
4541
4678
  var result = tickOnce();
4542
- done();
4679
+ spentMs += Date.now() - beganTick;
4543
4680
  return result;
4544
4681
  };
4545
4682
  var tickOnce = function () {
@@ -4573,15 +4710,18 @@
4573
4710
  var mark = railMarkFor(turn);
4574
4711
  if (mark !== null) {
4575
4712
  try {
4713
+ /* The lookup above can straddle a switch, and clicking the wrong
4714
+ session's rail would page history into a conversation nobody
4715
+ asked about. */
4716
+ if (currentConversationId() !== sessionId) {
4717
+ window.setTimeout(tick, 200);
4718
+ return;
4719
+ }
4576
4720
  mark.click();
4577
- announceJump(hit, false, spentMs);
4578
- /* The click starts a real history load: hand the thread back to
4579
- the host and look once when it has had time to render. */
4580
- window.setTimeout(function () {
4581
- finaliseJump(hit, terms);
4582
- suppressedUntil = 0;
4583
- schedule();
4584
- }, 1200);
4721
+ /* The click starts a real history load; until it lands, the only
4722
+ honest thing to say is that it is under way. */
4723
+ announceJumpLoading(hit);
4724
+ window.setTimeout(function () { settleJump(hit, terms, 0, spentMs); }, 900);
4585
4725
  return;
4586
4726
  } catch (error) {
4587
4727
  /* fall through */
@@ -4605,6 +4745,7 @@
4605
4745
  };
4606
4746
  window.setTimeout(tick, 200);
4607
4747
  }
4748
+
4608
4749
  function jumpToSearchHit(hit, terms) {
4609
4750
  suspendPasses(12000);
4610
4751
  openSessionRow(hit.sessionId);
@@ -4766,6 +4907,19 @@
4766
4907
  */
4767
4908
  function SearchHitRow(props) {
4768
4909
  var opened = react.useState(false);
4910
+ /* A hit far behind the newest turn means the host has to mount a lot of
4911
+ history to show it; asking first keeps a search from stalling the app
4912
+ for ten seconds without warning. */
4913
+ var cold = props.coldAfter > 0
4914
+ && Number(props.hit.turns) - Number(props.hit.turn) > props.coldAfter;
4915
+ var openContext = function () { opened[1](true); };
4916
+ var go = function () {
4917
+ if (cold) {
4918
+ askColdJump(props.hit, props.onJump, openContext);
4919
+ return;
4920
+ }
4921
+ if (typeof props.onJump === "function") props.onJump();
4922
+ };
4769
4923
  var context = typeof props.hit.context === "string" ? props.hit.context : "";
4770
4924
  var extra = context === "" ? null : [
4771
4925
  h("div", { className: "wsr-hit-actions" },
@@ -4782,13 +4936,14 @@
4782
4936
  className: "wsr-hit-context-jump",
4783
4937
  onClick: function (event) {
4784
4938
  if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
4939
+ /* Pressing this is the confirmation. */
4785
4940
  if (typeof props.onJump === "function") props.onJump();
4786
4941
  },
4787
4942
  }, t("search.openSession")),
4788
4943
  ),
4789
4944
  opened[0] === true ? h("div", { className: "wsr-hit-context" }, context) : null,
4790
4945
  ];
4791
- return searchHitRow(props.hit, props.terms, props.onJump, extra);
4946
+ return searchHitRow(props.hit, props.terms, go, extra);
4792
4947
  }
4793
4948
 
4794
4949
  /**
@@ -4828,6 +4983,50 @@
4828
4983
  );
4829
4984
  }
4830
4985
 
4986
+ /** Ask whether a jump that means loading a lot of history should go ahead. */
4987
+ function askColdJump(hit, onJump, onContext) {
4988
+ if (typeof document === "undefined") return;
4989
+ closeConfirm();
4990
+ confirmPrevious = typeof document.activeElement !== "undefined" ? document.activeElement : null;
4991
+ var backdrop = statsDiv("wsr-modal-backdrop");
4992
+ backdrop.setAttribute("data-wsr-confirm", "cold");
4993
+ var panel = statsDiv("wsr-confirm");
4994
+ panel.setAttribute("role", "dialog");
4995
+ panel.setAttribute("aria-modal", "true");
4996
+ panel.setAttribute("tabindex", "-1");
4997
+ panel.appendChild(statsDiv("wsr-confirm-text", t("search.coldJump", {
4998
+ turn: String(hit.turn),
4999
+ behind: String(Math.max(0, Number(hit.turns) - Number(hit.turn))),
5000
+ })));
5001
+ var actions = statsDiv("wsr-confirm-actions");
5002
+ var context = document.createElement("button");
5003
+ context.type = "button";
5004
+ context.className = "wsr-qcancel";
5005
+ context.setAttribute("data-wsr-cold-context", "true");
5006
+ context.textContent = t("search.coldContext");
5007
+ context.addEventListener("click", function (event) {
5008
+ if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
5009
+ closeConfirm(null);
5010
+ if (typeof onContext === "function") onContext();
5011
+ });
5012
+ var accept = document.createElement("button");
5013
+ accept.type = "button";
5014
+ accept.className = "wsr-qsubmit";
5015
+ accept.setAttribute("data-wsr-cold-jump", "true");
5016
+ accept.textContent = t("search.coldJumpAnyway");
5017
+ accept.addEventListener("click", function (event) {
5018
+ if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
5019
+ closeConfirm(null);
5020
+ if (typeof onJump === "function") onJump();
5021
+ });
5022
+ actions.appendChild(context);
5023
+ actions.appendChild(accept);
5024
+ panel.appendChild(actions);
5025
+ backdrop.appendChild(panel);
5026
+ document.body.appendChild(backdrop);
5027
+ try { if (typeof panel.focus === "function") panel.focus(); } catch (error) { /* focus is a nicety */ }
5028
+ }
5029
+
4831
5030
  function SearchPanelPage(props) {
4832
5031
  var state = react.useState(searchLast === null
4833
5032
  ? { loaded: false, query: "", hits: [], sessions: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" }
@@ -4845,6 +5044,9 @@
4845
5044
  var storedHistory = preferences !== null && preferences !== undefined
4846
5045
  && Array.isArray(preferences.searchHistory) ? preferences.searchHistory : [];
4847
5046
  var historyList = mergedHistory(storedHistory);
5047
+ /* 0 turns the question off and jumps straight away, as before. */
5048
+ var coldAfterRaw = Number(preferences !== null && preferences !== undefined ? preferences.coldJumpTurns : 0);
5049
+ var coldJumpTurns = Number.isFinite(coldAfterRaw) ? Math.max(0, Math.round(coldAfterRaw)) : DEFAULT_COLD_JUMP;
4848
5050
  /* Every update also parks the answer outside the component, so coming
4849
5051
  back from a hit restores the list instead of asking for a new search. */
4850
5052
  var commit = function (next) {
@@ -4957,6 +5159,7 @@
4957
5159
  var row = h(SearchHitRow, {
4958
5160
  hit: hit,
4959
5161
  terms: view.terms,
5162
+ coldAfter: coldJumpTurns,
4960
5163
  onJump: function () { jumpToSearchHit(hit, view.terms); },
4961
5164
  });
4962
5165
  row.key = String(hit.sessionId || "") + ":" + String(hit.seq || 0) + ":" + String(index);
@@ -5560,7 +5763,7 @@
5560
5763
  }
5561
5764
  var prefs = clientStore.defineStore({
5562
5765
  init: function () {
5563
- return { enabled: true, foldDays: DEFAULT_DAYS, keepActive: true, colors: true, pinnedSection: true, argMode: "tool", followUps: {}, searchHistory: [] };
5766
+ return { enabled: true, foldDays: DEFAULT_DAYS, keepActive: true, colors: true, pinnedSection: true, argMode: "tool", followUps: {}, searchHistory: [], coldJumpTurns: DEFAULT_COLD_JUMP };
5564
5767
  },
5565
5768
  persist: "dsh.ws-recency.prefs.v1",
5566
5769
  actions: {
@@ -5569,6 +5772,11 @@
5569
5772
  setColors: function (draft, value) { draft.colors = value === true; },
5570
5773
  setPinnedSection: function (draft, value) { draft.pinnedSection = value === true; },
5571
5774
  setArgMode: function (draft, value) { draft.argMode = value === "agent" ? "agent" : "tool"; },
5775
+ setColdJumpTurns: function (draft, value) {
5776
+ var next = Number(value);
5777
+ if (!Number.isFinite(next)) return;
5778
+ draft.coldJumpTurns = Math.min(MAX_COLD_JUMP, Math.max(0, Math.round(next)));
5779
+ },
5572
5780
  setFoldDays: function (draft, value) {
5573
5781
  var next = Number(value);
5574
5782
  if (!Number.isFinite(next)) return;
@@ -5662,6 +5870,16 @@
5662
5870
  }, SettingsRow);
5663
5871
  });
5664
5872
 
5873
+ ctx.slots.inject("settings.general.item", function () {
5874
+ return ctx.slots.register({
5875
+ name: "settings.general.item",
5876
+ id: "ws-recency-cold-jump",
5877
+ order: 45,
5878
+ store: prefs,
5879
+ locale: NS,
5880
+ }, ColdJumpRow);
5881
+ });
5882
+
5665
5883
  ctx.slots.inject("settings.general.item", function () {
5666
5884
  return ctx.slots.register({
5667
5885
  name: "settings.general.item",
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.32.1";
35
+ export const HOST_VERSION = "0.33.0";
36
36
 
37
37
  /**
38
38
  * Exact routes the client half calls. Registered on the bare web server, so they
@@ -67,16 +67,52 @@ function sessionIdFrom(req, body) {
67
67
  return body !== null && body !== undefined && typeof body.sessionId === "string" ? body.sessionId.trim() : "";
68
68
  }
69
69
 
70
- /** Only the app itself may call these routes: a foreign origin is refused. */
71
- function loopbackOrigin(req) {
70
+ /** Hostnames that are this machine, whatever port is in front of them. */
71
+ function isLoopbackHostname(hostname) {
72
+ const name = String(hostname ?? "").toLowerCase().replace(/^\[|\]$/g, "");
73
+ return name === "localhost" || name === "127.0.0.1" || name === "::1" || name.endsWith(".localhost");
74
+ }
75
+
76
+ /**
77
+ * Whether a request comes from the app itself.
78
+ *
79
+ * The old rule demanded a loopback origin, which refused every page that reached
80
+ * the app through a LAN address or a gateway - those pages are the app too, and
81
+ * the user could not delete a session from them.
82
+ *
83
+ * What actually has to be stopped is a foreign page driving these destructive
84
+ * routes at a local server (a browser will send its own origin). So the rule is
85
+ * same-origin: the origin has to name the host the request was addressed to, as
86
+ * seen either directly or through a proxy's forwarded headers. A request with no
87
+ * origin comes from a non-browser client and is allowed, as before.
88
+ */
89
+ function trustedOrigin(req) {
72
90
  const origin = req.headers.origin;
73
- if (origin === undefined) return true;
91
+ if (origin === undefined || origin === null || origin === "") return true;
92
+ let originHost = "";
93
+ let originName = "";
74
94
  try {
75
- const { hostname } = new URL(origin);
76
- return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
95
+ const parsed = new URL(String(origin));
96
+ originHost = parsed.host.toLowerCase();
97
+ originName = parsed.hostname.toLowerCase();
77
98
  } catch {
78
99
  return false;
79
100
  }
101
+ const headers = req.headers ?? {};
102
+ const candidates = [headers.host, headers["x-forwarded-host"]]
103
+ .filter((value) => typeof value === "string" && value !== "")
104
+ .flatMap((value) => String(value).split(","))
105
+ .map((value) => value.trim().toLowerCase())
106
+ .filter((value) => value !== "");
107
+ for (const candidate of candidates) {
108
+ if (candidate === originHost) return true;
109
+ const name = candidate.replace(/:\d+$/, "");
110
+ if (name === originName) return true;
111
+ }
112
+ /* No host header at all: a non-browser client, judged by the old rule. */
113
+ if (candidates.length === 0) return isLoopbackHostname(originName);
114
+ /* Loopback to loopback stays allowed even if a proxy rewrote the host. */
115
+ return isLoopbackHostname(originName) && candidates.some((value) => isLoopbackHostname(value.replace(/:\d+$/, "")));
80
116
  }
81
117
 
82
118
  async function readJsonBody(req) {
@@ -266,7 +302,7 @@ export async function handleTrashRequest(ctx, req, res) {
266
302
  sendJson(res, 405, { ok: false, error: "method not allowed" });
267
303
  return;
268
304
  }
269
- if (!loopbackOrigin(req)) {
305
+ if (!trustedOrigin(req)) {
270
306
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
271
307
  return;
272
308
  }
@@ -2231,7 +2267,7 @@ export async function handleHandoffRequest(ctx, req, res) {
2231
2267
  sendJson(res, 405, { ok: false, error: "method not allowed" });
2232
2268
  return;
2233
2269
  }
2234
- if (!loopbackOrigin(req)) {
2270
+ if (!trustedOrigin(req)) {
2235
2271
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
2236
2272
  return;
2237
2273
  }
@@ -2320,7 +2356,7 @@ export async function handleTrashListRequest(ctx, req, res) {
2320
2356
  sendJson(res, 405, { ok: false, error: "method not allowed" });
2321
2357
  return;
2322
2358
  }
2323
- if (!loopbackOrigin(req)) {
2359
+ if (!trustedOrigin(req)) {
2324
2360
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
2325
2361
  return;
2326
2362
  }
@@ -2380,7 +2416,7 @@ export async function handleAdoptRequest(ctx, req, res) {
2380
2416
  sendJson(res, 405, { ok: false, error: "method not allowed" });
2381
2417
  return;
2382
2418
  }
2383
- if (!loopbackOrigin(req)) {
2419
+ if (!trustedOrigin(req)) {
2384
2420
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
2385
2421
  return;
2386
2422
  }
@@ -2397,7 +2433,7 @@ export async function handleMoveRequest(ctx, req, res) {
2397
2433
  sendJson(res, 405, { ok: false, error: "method not allowed" });
2398
2434
  return;
2399
2435
  }
2400
- if (!loopbackOrigin(req)) {
2436
+ if (!trustedOrigin(req)) {
2401
2437
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
2402
2438
  return;
2403
2439
  }
@@ -2422,7 +2458,7 @@ export async function handleSearchRequest(ctx, req, res) {
2422
2458
  sendJson(res, 405, { ok: false, error: "method not allowed" });
2423
2459
  return;
2424
2460
  }
2425
- if (!loopbackOrigin(req)) {
2461
+ if (!trustedOrigin(req)) {
2426
2462
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
2427
2463
  return;
2428
2464
  }
@@ -2449,7 +2485,7 @@ export async function handleStatsRequest(ctx, req, res) {
2449
2485
  sendJson(res, 405, { ok: false, error: "method not allowed" });
2450
2486
  return;
2451
2487
  }
2452
- if (!loopbackOrigin(req)) {
2488
+ if (!trustedOrigin(req)) {
2453
2489
  sendJson(res, 403, { ok: false, error: "origin not trusted" });
2454
2490
  return;
2455
2491
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ws-recency",
3
- "version": "0.32.1",
3
+ "version": "0.33.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",