dsh-ws-recency 0.30.0 → 0.30.2
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 +8 -3
- package/client.js +1069 -105
- package/index.js +155 -11
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -49,6 +49,12 @@
|
|
|
49
49
|
var NS = "ws-recency";
|
|
50
50
|
var h = react.createElement;
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Master switch for the search feature: its panel icon and the page behind
|
|
54
|
+
* it. Off leaves the plugin present but registers no search side at all.
|
|
55
|
+
*/
|
|
56
|
+
var SEARCH_ENABLED = true;
|
|
57
|
+
|
|
52
58
|
var HEADER_PREFIX = "workspace:";
|
|
53
59
|
var SESSION_PREFIX = "session:";
|
|
54
60
|
var SECTION_TOKEN = "_groupSection";
|
|
@@ -316,21 +322,19 @@
|
|
|
316
322
|
".wsr-context-jump-hit[data-wsr-rank=\"3\"] .wsr-context-jump-dot{background:#4f9df7}",
|
|
317
323
|
".wsr-context-jump-hit-hot .wsr-context-jump-dot{transform:scale(1.8);box-shadow:0 0 0 4px rgba(217,154,43,.25)}",
|
|
318
324
|
".wsr-context-jump:hover .wsr-context-bar-inner{filter:brightness(1.15)}",
|
|
319
|
-
".wsr-context-jumps{display:
|
|
320
|
-
".wsr-context-
|
|
321
|
-
/*
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
".wsr-context-jump-
|
|
325
|
-
".wsr-context-jump-
|
|
326
|
-
".wsr-context-jump-row{display:grid;grid-template-columns:8px auto 1fr;align-items:center;gap:5px;padding:1px 5px;border-radius:4px;transition:background .12s,color .12s}",
|
|
327
|
-
".wsr-context-jump-rank{display:inline-flex;align-items:center}",
|
|
328
|
-
".wsr-context-jump-rank-dot{width:6px;height:6px;border-radius:50%;background:#d99a2b}",
|
|
325
|
+
".wsr-context-jumps{display:flex;flex-direction:column;gap:2px;margin-top:2px}",
|
|
326
|
+
".wsr-context-jump-group{display:flex;flex-direction:column;gap:2px}",
|
|
327
|
+
/* Fixed columns on every row is what aligns them: each row is its own
|
|
328
|
+
grid, so `auto` widths would drift with the numbers they hold. */
|
|
329
|
+
".wsr-context-jump-row{display:grid;grid-template-columns:40px 84px 62px minmax(0,1fr);align-items:center;gap:10px;font-size:11px;color:var(--dsw-alias-label-secondary);padding:1px 5px;border-radius:4px;transition:background .12s,color .12s}",
|
|
330
|
+
".wsr-context-jump-segment{color:var(--dsw-alias-label-tertiary);white-space:nowrap}",
|
|
331
|
+
".wsr-context-jump-rank-dot{flex:none;width:6px;height:6px;border-radius:50%;background:#d99a2b}",
|
|
329
332
|
".wsr-context-jump-row[data-wsr-rank=\"1\"] .wsr-context-jump-rank-dot{background:#f0553d}",
|
|
330
333
|
".wsr-context-jump-row[data-wsr-rank=\"2\"] .wsr-context-jump-rank-dot{background:#f5c542}",
|
|
331
334
|
".wsr-context-jump-row[data-wsr-rank=\"3\"] .wsr-context-jump-rank-dot{background:#4f9df7}",
|
|
332
|
-
".wsr-context-jump-step{white-space:nowrap}",
|
|
335
|
+
".wsr-context-jump-step{display:flex;align-items:center;gap:6px;white-space:nowrap}",
|
|
333
336
|
".wsr-context-jump-rise{text-align:right;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary)}",
|
|
337
|
+
".wsr-context-jump-what{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-tertiary)}",
|
|
334
338
|
".wsr-context-jump-row-hot{background:rgba(217,154,43,.16);color:var(--dsw-alias-label-primary)}",
|
|
335
339
|
".wsr-kind-legend{display:flex;flex-wrap:wrap;gap:10px}",
|
|
336
340
|
".wsr-kind{display:flex;align-items:center;gap:5px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
@@ -344,6 +348,8 @@
|
|
|
344
348
|
".wsr-amplified-value{text-align:right;font-weight:600;font-variant-numeric:tabular-nums;font-size:12px}",
|
|
345
349
|
".wsr-amplified-share{text-align:right;color:var(--dsw-alias-label-tertiary);font-size:11px;font-variant-numeric:tabular-nums}",
|
|
346
350
|
".wsr-amplified-empty{font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
351
|
+
".wsr-amplified-subtitle{font-size:11px;font-weight:600;color:var(--dsw-alias-label-secondary);margin-top:4px}",
|
|
352
|
+
".wsr-amplified-lead{font-size:11px;line-height:1.6;color:var(--dsw-alias-label-tertiary)}",
|
|
347
353
|
".wsr-stats-footnote{padding-top:6px;border-top:.5px solid rgba(255,255,255,.06)}",
|
|
348
354
|
".wsr-toggle{width:100%;height:28px;padding:0 12px 0 calc(28px + var(--dsh-workspace-indent,0px));cursor:pointer;text-align:left;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;font-size:12px}",
|
|
349
355
|
".wsr-toggle:hover{color:var(--dsw-alias-label-secondary)}",
|
|
@@ -352,6 +358,19 @@
|
|
|
352
358
|
'[' + STATE_ATTR + '="followup"] [class*="_title"]{color:#d99a2b}',
|
|
353
359
|
'[' + STATE_ATTR + '="waiting"] [class*="_title"]{color:#d99a2b}',
|
|
354
360
|
".wsr-search-bar{display:flex;gap:8px;align-items:center}",
|
|
361
|
+
".wsr-hit-actions{display:flex;gap:6px;justify-content:flex-end;margin-top:2px}",
|
|
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
|
+
".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
|
+
".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-history{display:flex;align-items:center;flex-wrap:wrap;gap:6px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
366
|
+
".wsr-search-history-label{flex:none}",
|
|
367
|
+
".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}",
|
|
368
|
+
".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}",
|
|
369
|
+
".wsr-search-chip-run:hover{color:var(--dsw-alias-label-primary)}",
|
|
370
|
+
".wsr-search-chip-drop{border:none;background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:12px;line-height:18px;padding:0 7px 0 2px;cursor:pointer}",
|
|
371
|
+
".wsr-search-chip-drop:hover{color:var(--dsw-alias-state-error-primary,#d9534f)}",
|
|
372
|
+
".wsr-search-history-clear{border:none;background:0 0;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:11px;cursor:pointer;text-decoration:underline;padding:0 2px}",
|
|
373
|
+
".wsr-search-history-clear:hover{color:var(--dsw-alias-label-primary)}",
|
|
355
374
|
".wsr-search-input{flex:1;min-width:0;height:30px;padding:0 10px;border-radius:6px;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:inherit;font-size:13px}",
|
|
356
375
|
".wsr-hit{display:flex;flex-direction:column;gap:4px;padding:8px 10px;border-radius:8px;cursor:pointer}",
|
|
357
376
|
".wsr-hit:hover{background:var(--dsw-alias-bg-layer-2)}",
|
|
@@ -363,6 +382,13 @@
|
|
|
363
382
|
".wsr-hit-ws{flex:none;max-width:30%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
364
383
|
".wsr-hit-turn{flex:none}",
|
|
365
384
|
".wsr-hit-snippet{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);word-break:break-word}",
|
|
385
|
+
".wsr-hit-meta{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--dsw-alias-label-tertiary)}",
|
|
386
|
+
".wsr-hit-time{flex:none;font-variant-numeric:tabular-nums}",
|
|
387
|
+
".wsr-hit-step{flex:none;color:var(--dsw-alias-label-secondary)}",
|
|
388
|
+
".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}",
|
|
389
|
+
".wsr-diagnose-toast{max-width:min(680px,90vw);white-space:normal;line-height:1.6;text-align:left;font-variant-numeric:tabular-nums}",
|
|
390
|
+
".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)}",
|
|
391
|
+
".wsr-hit-cwd{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl;text-align:left}",
|
|
366
392
|
".wsr-mark{background:rgba(79,142,247,.28);color:inherit;border-radius:2px}",
|
|
367
393
|
'[data-wsr-flash="true"]{outline:2px solid #4f8ef7;outline-offset:2px;border-radius:8px}',
|
|
368
394
|
".wsr-dot{display:block;width:7px;height:7px;border-radius:50%;margin:0 auto;background:#d99a2b;cursor:pointer}",
|
|
@@ -414,7 +440,7 @@
|
|
|
414
440
|
"stats.col.source": "\u6765\u6e90",
|
|
415
441
|
"stats.col.calls": "\u8c03\u7528",
|
|
416
442
|
"stats.callsShort": "{n} 次",
|
|
417
|
-
"stats.col.tokensShort": "
|
|
443
|
+
"stats.col.tokensShort": "内容估算",
|
|
418
444
|
"stats.col.shareShort": "占比",
|
|
419
445
|
"stats.col.args": "\u53c2\u6570",
|
|
420
446
|
"stats.col.results": "\u7ed3\u679c",
|
|
@@ -479,6 +505,22 @@
|
|
|
479
505
|
"search.you": "你",
|
|
480
506
|
"search.assistant": "助手",
|
|
481
507
|
"search.turn": "第 {n} 轮",
|
|
508
|
+
"search.pluginCost": "插件 {ms}ms",
|
|
509
|
+
"menu.diagnose": "插件耗时诊断",
|
|
510
|
+
"diagnose.report": "近 60 秒:扫描 {passes} 次 / 共 {total}ms / 最慢 {worst}ms · 页面节点 {nodes} · 已挂载轮次 {turns}",
|
|
511
|
+
"search.contextShow": "看上下文",
|
|
512
|
+
"search.contextHide": "收起",
|
|
513
|
+
"search.openSession": "打开会话",
|
|
514
|
+
"search.history": "最近搜索",
|
|
515
|
+
"search.historyRun": "再搜一次:{query}",
|
|
516
|
+
"search.historyDrop": "从历史里删除",
|
|
517
|
+
"search.historyClear": "清空",
|
|
518
|
+
"search.step": "第 {n} 步",
|
|
519
|
+
"search.jumpTurn": "已定位:第 {turn} 轮 · 按轮次",
|
|
520
|
+
"search.jumpText": "已定位:第 {turn} 轮 · 按文字",
|
|
521
|
+
"search.jumpNoSession": "打不开这个会话(可能已归档、或不在当前工作区)",
|
|
522
|
+
"search.jumpNoTurn": "会话已打开,但没找到第 {turn} 轮(共 {turns} 轮)",
|
|
523
|
+
"search.jumpCollapsed": "找到了第 {turn} 轮,但这一轮的历史内容没有被渲染(长会话的旧轮次是折叠的),请手动向上翻一点",
|
|
482
524
|
"ui.reload": "刷新界面",
|
|
483
525
|
"ui.refresh": "刷新列表",
|
|
484
526
|
"trash.title": "回收站",
|
|
@@ -535,14 +577,16 @@
|
|
|
535
577
|
"stats.barTooltip": "{name} 共 {total}:参数 {args}({argsShare}),结果 {results}({resultsShare})",
|
|
536
578
|
"stats.argModeNote": "当前把工具参数计入主 agent:每个工具只算返回结果,表格里「参数」列显示为淡色(那些 token 记在主 agent 那一行)。",
|
|
537
579
|
"stats.amplified.title": "放大成本(账单归因)",
|
|
580
|
+
"stats.amplified.kindTitle": "账单构成",
|
|
581
|
+
"stats.amplified.lead": "按「内容大小 × 之后重读次数」排序:一块内容读进来一次,之后每一步都会再发一遍,乘上重读次数才是它真正的开销。上面的分布统计只算内容本身多大,两个数不能直接比。",
|
|
538
582
|
"stats.amplified.summary": "账单 {bill} token;可归因内容经重读放大后占 {share}({attributed})",
|
|
539
|
-
"stats.amplified.contextCaption": "
|
|
583
|
+
"stats.amplified.contextCaption": "每步上下文(面积≈账单):一步=一次模型调用,越早进入的内容被重读越多",
|
|
540
584
|
"stats.amplified.point": "第 {step} 步 · {context}",
|
|
541
585
|
"stats.amplified.jump": "第 {step} 步上下文涨了 {rise}",
|
|
542
586
|
"stats.amplified.jumpStep": "第 {step} 步",
|
|
543
587
|
"stats.amplified.segment": "第 {segment} 段",
|
|
544
588
|
"stats.amplified.jumpFrom": "({name} 进来 {tokens})",
|
|
545
|
-
"stats.amplified.meta": "
|
|
589
|
+
"stats.amplified.meta": "{tokens} token × {remaining} 次重读 · 第 {entry} 步进入",
|
|
546
590
|
"stats.amplified.whatIf": "若压到 20%,可省 {save}({share})",
|
|
547
591
|
"stats.amplified.empty": "没有可归因的放大内容(压缩后或旧日志可能缺失)",
|
|
548
592
|
"stats.amplified.note": "放大成本按内容长度估算;账单总量来自真实 usage。思维链通常不回传,故未计入。",
|
|
@@ -553,6 +597,7 @@
|
|
|
553
597
|
"stats.amplified.system": "系统消息",
|
|
554
598
|
"stats.tab.distribution": "分布统计",
|
|
555
599
|
"stats.tab.amplified": "放大归因",
|
|
600
|
+
"stats.tab.ranking": "放大排行",
|
|
556
601
|
"stats.tab.details": "明细",
|
|
557
602
|
"trash.confirm": "\u5220\u9664\u8fd9\u4e2a\u4f1a\u8bdd\uff1f\n\n\u4f1a\u5148\u505c\u6b62\u5b83\u6b63\u5728\u8fdb\u884c\u7684\u5de5\u4f5c\uff0c\u518d\u628a\u65e5\u5fd7\u76ee\u5f55\u79fb\u5165\u56de\u6536\u7ad9\uff08\u4e0d\u662f\u7269\u7406\u5220\u9664\uff0c\u53ef\u4ee5\u624b\u52a8\u6062\u590d\uff09\u3002",
|
|
558
603
|
"trash.failed": "\u5220\u9664\u5931\u8d25\uff1a",
|
|
@@ -596,7 +641,7 @@
|
|
|
596
641
|
"stats.col.source": "source",
|
|
597
642
|
"stats.col.calls": "calls",
|
|
598
643
|
"stats.callsShort": "{n}x",
|
|
599
|
-
"stats.col.tokensShort": "
|
|
644
|
+
"stats.col.tokensShort": "content est.",
|
|
600
645
|
"stats.col.shareShort": "share",
|
|
601
646
|
"stats.col.args": "args",
|
|
602
647
|
"stats.col.results": "results",
|
|
@@ -661,6 +706,22 @@
|
|
|
661
706
|
"search.you": "You",
|
|
662
707
|
"search.assistant": "Assistant",
|
|
663
708
|
"search.turn": "turn {n}",
|
|
709
|
+
"search.pluginCost": "plugin {ms}ms",
|
|
710
|
+
"menu.diagnose": "Plugin cost",
|
|
711
|
+
"diagnose.report": "Last 60s: {passes} passes / {total}ms total / {worst}ms worst · {nodes} nodes · {turns} turns mounted",
|
|
712
|
+
"search.contextShow": "Show context",
|
|
713
|
+
"search.contextHide": "Hide",
|
|
714
|
+
"search.openSession": "Open session",
|
|
715
|
+
"search.history": "Recent",
|
|
716
|
+
"search.historyRun": "Search again: {query}",
|
|
717
|
+
"search.historyDrop": "Remove from history",
|
|
718
|
+
"search.historyClear": "Clear",
|
|
719
|
+
"search.step": "step {n}",
|
|
720
|
+
"search.jumpTurn": "Landed on turn {turn} (by turn)",
|
|
721
|
+
"search.jumpText": "Landed on turn {turn} (by text)",
|
|
722
|
+
"search.jumpNoSession": "Could not open that session (archived, or outside the current workspace)",
|
|
723
|
+
"search.jumpNoTurn": "Session opened, but turn {turn} was not found (of {turns})",
|
|
724
|
+
"search.jumpCollapsed": "Turn {turn} was found, but its history is not rendered (old turns of a long session are collapsed); scroll up a little",
|
|
664
725
|
"ui.reload": "Reload UI",
|
|
665
726
|
"ui.refresh": "Refresh",
|
|
666
727
|
"trash.title": "Trash",
|
|
@@ -716,14 +777,16 @@
|
|
|
716
777
|
"stats.barTooltip": "{name}: {total} total - arguments {args} ({argsShare}), results {results} ({resultsShare})",
|
|
717
778
|
"stats.argModeNote": "Tool arguments currently count towards the agent: each tool shows only its results, and the table's \"args\" column is faded because those tokens sit on the agent's row.",
|
|
718
779
|
"stats.amplified.title": "Amplified cost (what the bill pays for)",
|
|
780
|
+
"stats.amplified.kindTitle": "What the bill is made of",
|
|
781
|
+
"stats.amplified.lead": "Ranked by content size × the later steps that re-read it: content is re-sent on every step after it enters, so the multiplier is what the bill actually pays. The distribution tab measures only the content itself, so the two numbers do not compare directly.",
|
|
719
782
|
"stats.amplified.summary": "Bill {bill} tokens; attributable content amplifies to {share} ({attributed})",
|
|
720
|
-
"stats.amplified.contextCaption": "Context per step (area ≈ bill): earlier content is re-read more",
|
|
783
|
+
"stats.amplified.contextCaption": "Context per step (area ≈ bill): one step is one model call; earlier content is re-read more",
|
|
721
784
|
"stats.amplified.point": "step {step} · {context}",
|
|
722
785
|
"stats.amplified.jump": "step {step} grew by {rise}",
|
|
723
786
|
"stats.amplified.jumpStep": "step {step}",
|
|
724
787
|
"stats.amplified.segment": "seg {segment}",
|
|
725
788
|
"stats.amplified.jumpFrom": "({name} brought {tokens})",
|
|
726
|
-
"stats.amplified.meta": "
|
|
789
|
+
"stats.amplified.meta": "{tokens} tokens × {remaining} re-reads · entered at step {entry}",
|
|
727
790
|
"stats.amplified.whatIf": "at 20%, saves {save} ({share})",
|
|
728
791
|
"stats.amplified.empty": "No amplifiable content (compacted or older logs may lack it)",
|
|
729
792
|
"stats.amplified.note": "Amplified cost is estimated from content length; the bill total comes from real usage. Reasoning is usually not resent, so it is excluded.",
|
|
@@ -734,6 +797,7 @@
|
|
|
734
797
|
"stats.amplified.system": "system messages",
|
|
735
798
|
"stats.tab.distribution": "Distribution",
|
|
736
799
|
"stats.tab.amplified": "Amplified",
|
|
800
|
+
"stats.tab.ranking": "Ranking",
|
|
737
801
|
"stats.tab.details": "Details",
|
|
738
802
|
"trash.confirm": "Delete this session?\n\nIt stops whatever the session is running, then moves the log directory into the trash folder (a move, not an erase: you can restore it by hand).",
|
|
739
803
|
"trash.failed": "Delete failed: ",
|
|
@@ -773,7 +837,62 @@
|
|
|
773
837
|
return text;
|
|
774
838
|
}
|
|
775
839
|
|
|
776
|
-
|
|
840
|
+
/**
|
|
841
|
+
* Whether a mutated node belongs to the conversation, not the sidebar.
|
|
842
|
+
*
|
|
843
|
+
* The observer used to watch the whole body, so a chat that mounts a page
|
|
844
|
+
* of history - thousands of nodes - ran this plugin's sidebar pass over and
|
|
845
|
+
* over while the host was rendering, and that is what made a jump into a
|
|
846
|
+
* long session feel frozen. Nothing here decorates the chat, so its
|
|
847
|
+
* mutations are none of this observer's business.
|
|
848
|
+
*/
|
|
849
|
+
/**
|
|
850
|
+
* The sidebar's own containers, as a set of ancestors of a workspace row.
|
|
851
|
+
*
|
|
852
|
+
* Filtering by "is the chat in this node" was not enough: the turn rail and
|
|
853
|
+
* the host's hover preview are portalled onto <body>, outside the chat, so
|
|
854
|
+
* moving the pointer along the rail ran this plugin's sidebar pass on every
|
|
855
|
+
* preview repaint - which is exactly the delay felt after a long jump. The
|
|
856
|
+
* sidebar is a sibling subtree, and only its containers can hold a row.
|
|
857
|
+
*/
|
|
858
|
+
var sidebarAncestors = null;
|
|
859
|
+
|
|
860
|
+
function sidebarChain() {
|
|
861
|
+
if (sidebarAncestors !== null && sidebarAncestors.size > 0) {
|
|
862
|
+
/* Revalidate cheaply: a stale set would stop noticing real changes. */
|
|
863
|
+
var alive = 0;
|
|
864
|
+
sidebarAncestors.forEach(function (node) {
|
|
865
|
+
if (node.isConnected !== false) alive += 1;
|
|
866
|
+
});
|
|
867
|
+
if (alive > 0) return sidebarAncestors;
|
|
868
|
+
}
|
|
869
|
+
var set = new Set();
|
|
870
|
+
var header = document.querySelector('[data-row-key^="' + HEADER_PREFIX + '"]');
|
|
871
|
+
if (header === null || header === undefined) return set;
|
|
872
|
+
var node = header.parentElement;
|
|
873
|
+
while (node !== null && node !== undefined && node.parentElement !== null
|
|
874
|
+
&& node.parentElement !== undefined && node.parentElement !== document.body) {
|
|
875
|
+
set.add(node);
|
|
876
|
+
node = node.parentElement;
|
|
877
|
+
}
|
|
878
|
+
sidebarAncestors = set;
|
|
879
|
+
return set;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function outsideSidebar(node, chain) {
|
|
883
|
+
if (node === null || node === undefined) return false;
|
|
884
|
+
var element = node;
|
|
885
|
+
if (element.nodeType !== 1) element = element.parentElement;
|
|
886
|
+
if (element === null || element === undefined) return false;
|
|
887
|
+
var containers = chain === undefined || chain === null ? sidebarChain() : chain;
|
|
888
|
+
var current = element;
|
|
889
|
+
while (current !== null && current !== undefined) {
|
|
890
|
+
if (containers.has(current)) return false;
|
|
891
|
+
if (current === document.body) return true;
|
|
892
|
+
current = current.parentElement;
|
|
893
|
+
}
|
|
894
|
+
return true;
|
|
895
|
+
} function top() {
|
|
777
896
|
return typeof document !== "undefined" && document.body !== null ? document.body : null;
|
|
778
897
|
}
|
|
779
898
|
|
|
@@ -1713,18 +1832,66 @@
|
|
|
1713
1832
|
decorateComposerStats();
|
|
1714
1833
|
}
|
|
1715
1834
|
|
|
1835
|
+
/**
|
|
1836
|
+
* While this is in the future the sidebar pass stays off.
|
|
1837
|
+
*
|
|
1838
|
+
* Jumping to a hit in a long session makes the host mount a whole page of
|
|
1839
|
+
* history. That is thousands of DOM changes, and each one used to run this
|
|
1840
|
+
* plugin's sidebar pass on top of the host's own rendering, which is what
|
|
1841
|
+
* still froze the window even after chat mutations were filtered out.
|
|
1842
|
+
*/
|
|
1843
|
+
var suppressedUntil = 0;
|
|
1844
|
+
|
|
1845
|
+
function suspendPasses(ms) {
|
|
1846
|
+
var span = typeof ms === "number" && ms > 0 ? ms : 8000;
|
|
1847
|
+
suppressedUntil = Date.now() + span;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
function passesSuspended() {
|
|
1851
|
+
return suppressedUntil !== 0 && Date.now() < suppressedUntil;
|
|
1852
|
+
}
|
|
1853
|
+
/** At most this often, whatever happens: a pass writes DOM, and writing DOM
|
|
1854
|
+
* can be observed by our own observer, so the interval is the guarantee that
|
|
1855
|
+
* a feedback loop cannot turn into a busy main thread. */
|
|
1856
|
+
var PASS_MIN_GAP = 400;
|
|
1857
|
+
var lastPassAt = 0;
|
|
1858
|
+
var passCount = 0;
|
|
1859
|
+
/* Rolling record for the diagnostic row: how often the pass runs and how
|
|
1860
|
+
long it takes, so a claim about cost can be checked on screen. */
|
|
1861
|
+
var passSamples = [];
|
|
1862
|
+
|
|
1863
|
+
function recordPass(spent) {
|
|
1864
|
+
passSamples.push({ at: Date.now(), ms: spent });
|
|
1865
|
+
if (passSamples.length > 200) passSamples.shift();
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1716
1868
|
function schedule() {
|
|
1717
1869
|
if (disposed || timer !== null) return;
|
|
1870
|
+
sidebarAncestors = null;
|
|
1871
|
+
if (passesSuspended()) {
|
|
1872
|
+
/* One pass, once the host has finished mounting. */
|
|
1873
|
+
var wait = Math.max(120, suppressedUntil - Date.now() + 60);
|
|
1874
|
+
window.setTimeout(function () {
|
|
1875
|
+
if (!disposed) schedule();
|
|
1876
|
+
}, wait);
|
|
1877
|
+
return;
|
|
1878
|
+
}
|
|
1879
|
+
var since = Date.now() - lastPassAt;
|
|
1880
|
+
var delay = since >= PASS_MIN_GAP ? 60 : PASS_MIN_GAP - since + 16;
|
|
1718
1881
|
timer = window.setTimeout(function () {
|
|
1719
1882
|
timer = null;
|
|
1883
|
+
lastPassAt = Date.now();
|
|
1884
|
+
passCount += 1;
|
|
1885
|
+
var began = Date.now();
|
|
1720
1886
|
try {
|
|
1721
1887
|
apply();
|
|
1722
1888
|
} catch (error) {
|
|
1723
1889
|
console.warn("[dsh-ws-recency] pass failed:", error);
|
|
1724
1890
|
}
|
|
1725
|
-
|
|
1891
|
+
recordPass(Date.now() - began);
|
|
1892
|
+
if (typeof window !== "undefined") window.__DSH_WSR_PASSES__ = passCount;
|
|
1893
|
+
}, delay);
|
|
1726
1894
|
}
|
|
1727
|
-
|
|
1728
1895
|
/** `shell.overlay` occupant; it renders no chrome of its own. */
|
|
1729
1896
|
function Sorter(props) {
|
|
1730
1897
|
if (typeof props.useSessions === "function") {
|
|
@@ -1791,6 +1958,46 @@
|
|
|
1791
1958
|
* `<home>/.trash/ws-recency/`. The browser half only asks for confirmation
|
|
1792
1959
|
* and posts the id.
|
|
1793
1960
|
*/
|
|
1961
|
+
/**
|
|
1962
|
+
* Session menu row that reports this plugin's own cost.
|
|
1963
|
+
*
|
|
1964
|
+
* Without devtools there was no way to tell a slow plugin from a slow host,
|
|
1965
|
+
* and several rounds went into guessing. This prints the numbers where the
|
|
1966
|
+
* lag is felt. */
|
|
1967
|
+
function DiagnoseMenuItem(props) {
|
|
1968
|
+
var Item = ui.MenuItemButton;
|
|
1969
|
+
if (typeof Item !== "function") return null;
|
|
1970
|
+
return h(Item, {
|
|
1971
|
+
icon: undefined,
|
|
1972
|
+
onSelect: function () {
|
|
1973
|
+
var now = Date.now();
|
|
1974
|
+
var recent = passSamples.filter(function (sample) {
|
|
1975
|
+
return now - sample.at <= 60000;
|
|
1976
|
+
});
|
|
1977
|
+
var total = 0;
|
|
1978
|
+
var worst = 0;
|
|
1979
|
+
for (var i = 0; i < recent.length; i += 1) {
|
|
1980
|
+
total += recent[i].ms;
|
|
1981
|
+
if (recent[i].ms > worst) worst = recent[i].ms;
|
|
1982
|
+
}
|
|
1983
|
+
var nodes = typeof document !== "undefined" ? document.querySelectorAll("*").length : 0;
|
|
1984
|
+
var turns = typeof document !== "undefined" ? document.querySelectorAll("[data-chat-turn]").length : 0;
|
|
1985
|
+
var note = statsDiv("wsr-jump-toast wsr-diagnose-toast");
|
|
1986
|
+
note.textContent = t("diagnose.report", {
|
|
1987
|
+
passes: String(recent.length),
|
|
1988
|
+
total: String(total),
|
|
1989
|
+
worst: String(worst),
|
|
1990
|
+
nodes: String(nodes),
|
|
1991
|
+
turns: String(turns),
|
|
1992
|
+
});
|
|
1993
|
+
document.body.appendChild(note);
|
|
1994
|
+
window.setTimeout(function () {
|
|
1995
|
+
if (note.parentElement !== null) note.remove();
|
|
1996
|
+
}, 8000);
|
|
1997
|
+
},
|
|
1998
|
+
}, t("menu.diagnose"));
|
|
1999
|
+
}
|
|
2000
|
+
|
|
1794
2001
|
function TrashMenuItem(props) {
|
|
1795
2002
|
var Item = ui.MenuItemButton;
|
|
1796
2003
|
if (typeof Item !== "function") return null;
|
|
@@ -2071,9 +2278,10 @@
|
|
|
2071
2278
|
}
|
|
2072
2279
|
track.appendChild(group);
|
|
2073
2280
|
line.appendChild(track);
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2281
|
+
var valueCell = statsDiv("wsr-chart-value", formatTokens(entry.value));
|
|
2282
|
+
valueCell.setAttribute("title", String(Math.round(entry.value)) + " tokens");
|
|
2283
|
+
line.appendChild(valueCell);
|
|
2284
|
+
line.appendChild(statsDiv("wsr-chart-share", formatShare(entry.share))); /* The count the chart cannot draw: a bar says how heavy a source is,
|
|
2077
2285
|
the call count says how often it got there. The details table used to
|
|
2078
2286
|
be the only place for it. It always renders (empty for rows without
|
|
2079
2287
|
a count) so the five-column grid stays aligned. */
|
|
@@ -2202,6 +2410,23 @@
|
|
|
2202
2410
|
}
|
|
2203
2411
|
}
|
|
2204
2412
|
|
|
2413
|
+
/**
|
|
2414
|
+
* A short "what entered" label for a jump row.
|
|
2415
|
+
*
|
|
2416
|
+
* The detail is often a full path or a whole command; the row has one
|
|
2417
|
+
* narrow cell. Keep the tool name and the last path segment, and let the
|
|
2418
|
+
* tooltip carry the rest.
|
|
2419
|
+
*/
|
|
2420
|
+
function jumpWhatOf(name, detail) {
|
|
2421
|
+
if (typeof name !== "string" || name === "") return "";
|
|
2422
|
+
if (typeof detail !== "string" || detail === "") return name;
|
|
2423
|
+
var text = detail.trim();
|
|
2424
|
+
var cut = Math.max(text.lastIndexOf("/"), text.lastIndexOf("\\"));
|
|
2425
|
+
if (cut !== -1 && cut < text.length - 1) text = text.slice(cut + 1);
|
|
2426
|
+
if (text.length > 22) text = text.slice(0, 21) + "…";
|
|
2427
|
+
return name + " " + text;
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2205
2430
|
/**
|
|
2206
2431
|
* The steepest rise in each compaction segment.
|
|
2207
2432
|
*
|
|
@@ -2232,7 +2457,10 @@
|
|
|
2232
2457
|
if (rise <= 0) continue;
|
|
2233
2458
|
var segment = segmentOf(to);
|
|
2234
2459
|
if (bySegment[segment] === undefined) bySegment[segment] = [];
|
|
2235
|
-
|
|
2460
|
+
/* `from` is the previous bar's step: on a downsampled curve one bar
|
|
2461
|
+
stands for several steps, and the content that entered during that
|
|
2462
|
+
span is what made it rise. The host labels each point with it. */
|
|
2463
|
+
bySegment[segment].push({ step: to, from: from, rise: rise, entered: series[i].entered || null });
|
|
2236
2464
|
}
|
|
2237
2465
|
var total = compactions.length + 1;
|
|
2238
2466
|
var picked = [];
|
|
@@ -2257,24 +2485,42 @@
|
|
|
2257
2485
|
}
|
|
2258
2486
|
for (var k = 0; k < chosen.length; k += 1) {
|
|
2259
2487
|
var best = chosen[k];
|
|
2260
|
-
/* The
|
|
2261
|
-
|
|
2488
|
+
/* The host labels each curve point with the biggest content block
|
|
2489
|
+
that first appeared inside it. That is the honest attribution: a
|
|
2490
|
+
bar spans several steps, so `entry === step` almost never holds,
|
|
2491
|
+
and guessing "the most recent entrant" pointed at the system
|
|
2492
|
+
prompt instead of the file that actually landed. */
|
|
2262
2493
|
var block = null;
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2494
|
+
var blockName = "";
|
|
2495
|
+
var blockDetail = "";
|
|
2496
|
+
var blockTokens = 0;
|
|
2497
|
+
if (best.entered !== null && best.entered !== undefined) {
|
|
2498
|
+
blockName = best.entered.kind === "tool" ? String(best.entered.name) : t("stats.agent");
|
|
2499
|
+
blockDetail = typeof best.entered.detail === "string" ? best.entered.detail : "";
|
|
2500
|
+
blockTokens = Number(best.entered.tokens) || 0;
|
|
2501
|
+
} else {
|
|
2502
|
+
/* An older host half sends no labels: fall back to the block that
|
|
2503
|
+
entered inside this span, and never to an unrelated older one. */
|
|
2504
|
+
for (var b = 0; b < blocks.length; b += 1) {
|
|
2505
|
+
var candidate = blocks[b];
|
|
2506
|
+
var entry = Number(candidate.entry);
|
|
2507
|
+
if (entry > best.step || entry <= best.from) continue;
|
|
2508
|
+
if (block === null || Number(candidate.tokens) > Number(block.tokens)) block = candidate;
|
|
2509
|
+
}
|
|
2510
|
+
if (block !== null) {
|
|
2511
|
+
blockName = block.kind === "tool" ? String(block.name) : t("stats.agent");
|
|
2512
|
+
if (typeof block.detail === "string" && block.detail !== "") blockDetail = block.detail;
|
|
2513
|
+
blockTokens = Number(block.tokens) || 0;
|
|
2514
|
+
}
|
|
2267
2515
|
}
|
|
2268
2516
|
var label = t("stats.amplified.jump", {
|
|
2269
2517
|
step: String(best.step),
|
|
2270
2518
|
rise: formatTokens(best.rise),
|
|
2271
2519
|
});
|
|
2272
|
-
|
|
2273
|
-
if (block !== null && Number(block.entry) === best.step) {
|
|
2274
|
-
blockName = block.kind === "tool" ? String(block.name) : t("stats.agent");
|
|
2520
|
+
if (blockName !== "") {
|
|
2275
2521
|
label += " " + t("stats.amplified.jumpFrom", {
|
|
2276
|
-
name: blockName,
|
|
2277
|
-
tokens: formatTokens(
|
|
2522
|
+
name: blockDetail === "" ? blockName : blockName + " " + blockDetail,
|
|
2523
|
+
tokens: formatTokens(blockTokens),
|
|
2278
2524
|
});
|
|
2279
2525
|
}
|
|
2280
2526
|
picked.push({
|
|
@@ -2285,6 +2531,7 @@
|
|
|
2285
2531
|
"first" markers apart when a session compacted more than once. */
|
|
2286
2532
|
rank: k + 1,
|
|
2287
2533
|
blockName: blockName,
|
|
2534
|
+
blockDetail: blockDetail,
|
|
2288
2535
|
label: label,
|
|
2289
2536
|
});
|
|
2290
2537
|
}
|
|
@@ -2362,31 +2609,40 @@
|
|
|
2362
2609
|
section.appendChild(chart);
|
|
2363
2610
|
section.appendChild(statsDiv("wsr-context-caption", t("stats.amplified.contextCaption")));
|
|
2364
2611
|
if (jumps.length > 0) {
|
|
2365
|
-
/* One
|
|
2366
|
-
|
|
2367
|
-
|
|
2612
|
+
/* One row per rise, in fixed columns (segment / step / rise / what).
|
|
2613
|
+
Packing three rises onto one line truncated every label, and a row
|
|
2614
|
+
per rise with prose labels was too tall; four fixed columns give
|
|
2615
|
+
both: aligned numbers and room for the file name. */
|
|
2368
2616
|
var segments = [];
|
|
2369
2617
|
for (var js = 0; js < jumps.length; js += 1) {
|
|
2370
2618
|
if (segments.indexOf(jumps[js].segment) === -1) segments.push(jumps[js].segment);
|
|
2371
2619
|
}
|
|
2372
2620
|
var multiSegment = segments.length > 1;
|
|
2373
|
-
var jumpList = statsDiv("wsr-context-jumps"
|
|
2621
|
+
var jumpList = statsDiv("wsr-context-jumps");
|
|
2374
2622
|
for (var sg = 0; sg < segments.length; sg += 1) {
|
|
2375
2623
|
var group = statsDiv("wsr-context-jump-group");
|
|
2376
|
-
|
|
2377
|
-
group.appendChild(statsDiv("wsr-context-jump-segment", t("stats.amplified.segment", { segment: String(segments[sg]) })));
|
|
2378
|
-
}
|
|
2624
|
+
var firstOfSegment = true;
|
|
2379
2625
|
for (var jl = 0; jl < jumps.length; jl += 1) {
|
|
2380
2626
|
if (jumps[jl].segment !== segments[sg]) continue;
|
|
2381
2627
|
var jumpRow = statsDiv("wsr-context-jump-row");
|
|
2382
2628
|
jumpRow.setAttribute("data-wsr-jump-row", String(jumps[jl].step));
|
|
2383
2629
|
jumpRow.setAttribute("data-wsr-rank", String(jumps[jl].rank));
|
|
2384
2630
|
jumpRow.setAttribute("title", jumps[jl].label);
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2631
|
+
/* The segment is named once per group, not on every row. */
|
|
2632
|
+
jumpRow.appendChild(statsDiv(
|
|
2633
|
+
"wsr-context-jump-segment",
|
|
2634
|
+
multiSegment && firstOfSegment ? t("stats.amplified.segment", { segment: String(segments[sg]) }) : "",
|
|
2635
|
+
));
|
|
2636
|
+
firstOfSegment = false;
|
|
2637
|
+
var stepCell = statsDiv("wsr-context-jump-step");
|
|
2638
|
+
stepCell.appendChild(statsDiv("wsr-context-jump-rank-dot"));
|
|
2639
|
+
stepCell.appendChild(statsDiv("wsr-context-jump-step-text", t("stats.amplified.jumpStep", { step: String(jumps[jl].step) })));
|
|
2640
|
+
jumpRow.appendChild(stepCell);
|
|
2389
2641
|
jumpRow.appendChild(statsDiv("wsr-context-jump-rise", "+" + formatTokens(jumps[jl].rise)));
|
|
2642
|
+
/* What entered: the tool and a short form of what it touched, so
|
|
2643
|
+
the row answers "which file" instead of only "read". The full
|
|
2644
|
+
detail stays in the tooltip. */
|
|
2645
|
+
jumpRow.appendChild(statsDiv("wsr-context-jump-what", jumpWhatOf(jumps[jl].blockName, jumps[jl].blockDetail)));
|
|
2390
2646
|
group.appendChild(jumpRow);
|
|
2391
2647
|
}
|
|
2392
2648
|
jumpList.appendChild(group);
|
|
@@ -2397,8 +2653,13 @@
|
|
|
2397
2653
|
bar or its row lifts both, which is what "挪上去更明显" means here. */
|
|
2398
2654
|
jumpHoverHosts.push({ chart: chart, list: section });
|
|
2399
2655
|
|
|
2656
|
+
/* The ranking is a separate tab: the curve answers "when", the ranking
|
|
2657
|
+
answers "what", and stacking both in one scroll hid half of each. */
|
|
2658
|
+
var ranking = statsDiv("wsr-amplified wsr-amplified-ranking");
|
|
2659
|
+
ranking.appendChild(statsDiv("wsr-amplified-lead", t("stats.amplified.lead")));
|
|
2400
2660
|
var kinds = amplified.byKind || [];
|
|
2401
2661
|
if (kinds.length > 0) {
|
|
2662
|
+
ranking.appendChild(statsDiv("wsr-amplified-subtitle", t("stats.amplified.kindTitle")));
|
|
2402
2663
|
var legend = statsDiv("wsr-kind-legend");
|
|
2403
2664
|
for (var k = 0; k < kinds.length; k += 1) {
|
|
2404
2665
|
var kind = kinds[k];
|
|
@@ -2410,7 +2671,7 @@
|
|
|
2410
2671
|
item.appendChild(statsDiv("", t(known === undefined ? kind.kind : known[0]) + " " + formatShare(kind.share || 0)));
|
|
2411
2672
|
legend.appendChild(item);
|
|
2412
2673
|
}
|
|
2413
|
-
|
|
2674
|
+
ranking.appendChild(legend);
|
|
2414
2675
|
}
|
|
2415
2676
|
|
|
2416
2677
|
var list = statsDiv("wsr-amplified-list");
|
|
@@ -2429,12 +2690,16 @@
|
|
|
2429
2690
|
remaining: String(block.remaining),
|
|
2430
2691
|
})));
|
|
2431
2692
|
row.appendChild(main);
|
|
2432
|
-
|
|
2693
|
+
var valueCell = statsDiv("wsr-amplified-value", formatTokens(block.amplified));
|
|
2694
|
+
/* The exact count, so a number here can be matched against the same
|
|
2695
|
+
figure on the distribution tab without converting K/M by hand. */
|
|
2696
|
+
valueCell.setAttribute("title", String(Math.round(Number(block.amplified) || 0)) + " tokens");
|
|
2697
|
+
row.appendChild(valueCell);
|
|
2433
2698
|
row.appendChild(statsDiv("wsr-amplified-share", formatShare(block.share || 0)));
|
|
2434
2699
|
list.appendChild(row);
|
|
2435
2700
|
}
|
|
2436
|
-
|
|
2437
|
-
return section;
|
|
2701
|
+
ranking.appendChild(list);
|
|
2702
|
+
return { top: section, ranking: ranking };
|
|
2438
2703
|
}
|
|
2439
2704
|
|
|
2440
2705
|
function renderStats(body, stats) {
|
|
@@ -2451,15 +2716,19 @@
|
|
|
2451
2716
|
var grid = document.createElement("div");
|
|
2452
2717
|
grid.className = "wsr-stats-grid";
|
|
2453
2718
|
var cards = [
|
|
2454
|
-
[t("stats.total"), formatTokens(totals.totalTokens), true],
|
|
2455
|
-
[t("stats.steps"), formatTokens(stats.steps), false],
|
|
2456
|
-
[t("stats.input"), formatTokens(totals.inputTokens), false],
|
|
2457
|
-
[t("stats.cache"), formatTokens(totals.cacheReadTokens), false],
|
|
2458
|
-
[t("stats.output"), formatTokens(totals.outputTokens), false],
|
|
2719
|
+
[t("stats.total"), formatTokens(totals.totalTokens), true, Number(totals.totalTokens) || 0],
|
|
2720
|
+
[t("stats.steps"), formatTokens(stats.steps), false, Number(stats.steps) || 0],
|
|
2721
|
+
[t("stats.input"), formatTokens(totals.inputTokens), false, Number(totals.inputTokens) || 0],
|
|
2722
|
+
[t("stats.cache"), formatTokens(totals.cacheReadTokens), false, Number(totals.cacheReadTokens) || 0],
|
|
2723
|
+
[t("stats.output"), formatTokens(totals.outputTokens), false, Number(totals.outputTokens) || 0],
|
|
2459
2724
|
];
|
|
2460
2725
|
for (var i = 0; i < cards.length; i += 1) {
|
|
2461
2726
|
var card = statsDiv("wsr-stats-card" + (cards[i][2] === true ? " wsr-stats-card-primary" : ""));
|
|
2462
|
-
|
|
2727
|
+
var valueCell = statsDiv("wsr-stats-value", cards[i][1]);
|
|
2728
|
+
/* Numbers auto-scale to K/M/B; the exact count on hover is what makes
|
|
2729
|
+
two tabs comparable without converting units in your head. */
|
|
2730
|
+
valueCell.setAttribute("title", String(cards[i][3]));
|
|
2731
|
+
card.appendChild(valueCell);
|
|
2463
2732
|
card.appendChild(statsDiv("wsr-stats-label", cards[i][0]));
|
|
2464
2733
|
grid.appendChild(card);
|
|
2465
2734
|
}
|
|
@@ -2572,8 +2841,11 @@
|
|
|
2572
2841
|
var defs = [["distribution", "stats.tab.distribution", distributionPanel]];
|
|
2573
2842
|
if (amplifiedSection !== null) {
|
|
2574
2843
|
var amplifiedPanel = statsDiv("wsr-stats-panel");
|
|
2575
|
-
amplifiedPanel.appendChild(amplifiedSection);
|
|
2844
|
+
amplifiedPanel.appendChild(amplifiedSection.top);
|
|
2576
2845
|
defs.push(["amplified", "stats.tab.amplified", amplifiedPanel]);
|
|
2846
|
+
var rankingPanel = statsDiv("wsr-stats-panel");
|
|
2847
|
+
rankingPanel.appendChild(amplifiedSection.ranking);
|
|
2848
|
+
defs.push(["ranking", "stats.tab.ranking", rankingPanel]);
|
|
2577
2849
|
}
|
|
2578
2850
|
if (mode === "agent") defs[0][2].appendChild(statsDiv("wsr-stats-note", t("stats.argModeNote")));
|
|
2579
2851
|
var tabButtons = {};
|
|
@@ -3704,10 +3976,21 @@
|
|
|
3704
3976
|
|
|
3705
3977
|
/* ---------- session content search -------------------------------- */
|
|
3706
3978
|
|
|
3979
|
+
/** How many recent queries the panel remembers. */
|
|
3980
|
+
var SEARCH_HISTORY_MAX = 12;
|
|
3981
|
+
|
|
3707
3982
|
/** What the uncontrolled input holds; the panel keeps only results in state. */
|
|
3708
3983
|
var searchDraft = "";
|
|
3709
3984
|
/** Bumped per search so a slow answer cannot overwrite a newer one. */
|
|
3710
3985
|
var searchGeneration = 0;
|
|
3986
|
+
/**
|
|
3987
|
+
* The last answer, kept outside the component.
|
|
3988
|
+
*
|
|
3989
|
+
* Opening a hit switches the main view to the conversation, which unmounts
|
|
3990
|
+
* this page; without this the results were gone when the user came back
|
|
3991
|
+
* and every search had to be run again.
|
|
3992
|
+
*/
|
|
3993
|
+
var searchLast = null;
|
|
3711
3994
|
|
|
3712
3995
|
function searchPost(body) {
|
|
3713
3996
|
return fetch("/ws-recency/search", {
|
|
@@ -3730,6 +4013,39 @@
|
|
|
3730
4013
|
return h(Icon, { size: size });
|
|
3731
4014
|
}
|
|
3732
4015
|
|
|
4016
|
+
/**
|
|
4017
|
+
* Move a scroller and announce it.
|
|
4018
|
+
*
|
|
4019
|
+
* The chat pages older history in when its own scroll handler sees movement.
|
|
4020
|
+
* Assigning `scrollTop` from script does not fire that handler, so a long
|
|
4021
|
+
* session stayed at the same page no matter how often the value was set;
|
|
4022
|
+
* a synthetic scroll event is what lets the next page load.
|
|
4023
|
+
*/
|
|
4024
|
+
function scrollTo(scroller, top) {
|
|
4025
|
+
if (scroller === null || scroller === undefined) return;
|
|
4026
|
+
var target = Math.max(0, Number(top) || 0);
|
|
4027
|
+
try {
|
|
4028
|
+
scroller.scrollTop = target;
|
|
4029
|
+
} catch (error) {
|
|
4030
|
+
return;
|
|
4031
|
+
}
|
|
4032
|
+
var fire = function () {
|
|
4033
|
+
try {
|
|
4034
|
+
var event = document.createEvent("Event");
|
|
4035
|
+
event.initEvent("scroll", true, false);
|
|
4036
|
+
scroller.dispatchEvent(event);
|
|
4037
|
+
} catch (error) {
|
|
4038
|
+
/* an engine without createEvent still got the assignment */
|
|
4039
|
+
}
|
|
4040
|
+
};
|
|
4041
|
+
fire();
|
|
4042
|
+
try {
|
|
4043
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(fire);
|
|
4044
|
+
else window.setTimeout(fire, 16);
|
|
4045
|
+
} catch (error) {
|
|
4046
|
+
/* the first dispatch is usually enough */
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
3733
4049
|
function conversationScroller() {
|
|
3734
4050
|
if (typeof document === "undefined") return null;
|
|
3735
4051
|
try {
|
|
@@ -3752,12 +4068,60 @@
|
|
|
3752
4068
|
function turnRowOf(turn) {
|
|
3753
4069
|
if (typeof document === "undefined" || !isFinite(turn)) return null;
|
|
3754
4070
|
try {
|
|
3755
|
-
|
|
4071
|
+
/* Scoped when possible: a document-wide attribute query on a long
|
|
4072
|
+
transcript is the expensive part of a jump's polling loop. The
|
|
4073
|
+
document stays as the fallback because the scroller is not always
|
|
4074
|
+
the element that holds the rows. */
|
|
4075
|
+
var selector = '[data-chat-turn="' + String(turn) + '"]';
|
|
4076
|
+
var scope = conversationScroller();
|
|
4077
|
+
if (scope !== null && typeof scope.querySelector === "function") {
|
|
4078
|
+
var scoped = scope.querySelector(selector);
|
|
4079
|
+
if (scoped !== null && scoped !== undefined) return scoped;
|
|
4080
|
+
}
|
|
4081
|
+
return document.querySelector(selector);
|
|
3756
4082
|
} catch (error) {
|
|
3757
4083
|
return null;
|
|
3758
4084
|
}
|
|
3759
4085
|
}
|
|
3760
4086
|
|
|
4087
|
+
/** A short-lived line that says where the jump landed and how it got there. */
|
|
4088
|
+
function announceJump(hit, byText, costMs) {
|
|
4089
|
+
if (typeof document === "undefined") return;
|
|
4090
|
+
try {
|
|
4091
|
+
var note = statsDiv("wsr-jump-toast");
|
|
4092
|
+
var text = t(byText === true ? "search.jumpText" : "search.jumpTurn", { turn: String(hit.turn) });
|
|
4093
|
+
if (isFinite(Number(costMs))) text += " · " + t("search.pluginCost", { ms: String(Math.round(Number(costMs))) });
|
|
4094
|
+
note.textContent = text;
|
|
4095
|
+
document.body.appendChild(note);
|
|
4096
|
+
window.setTimeout(function () {
|
|
4097
|
+
if (note.parentElement !== null) note.remove();
|
|
4098
|
+
}, 3200);
|
|
4099
|
+
} catch (error) {
|
|
4100
|
+
/* a toast is a nicety: never break the jump for it */
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Say why a jump did not land.
|
|
4105
|
+
*
|
|
4106
|
+
* Without this a failed jump is indistinguishable from a jump that landed
|
|
4107
|
+
* in the wrong place: the panel just sits where it was and the user cannot
|
|
4108
|
+
* tell whether the session opened, whether the turn exists, or whether the
|
|
4109
|
+
* text was never rendered.
|
|
4110
|
+
*/
|
|
4111
|
+
function announceJumpFailure(hit, reason) {
|
|
4112
|
+
if (typeof document === "undefined") return;
|
|
4113
|
+
try {
|
|
4114
|
+
var note = statsDiv("wsr-jump-toast wsr-jump-toast-warn");
|
|
4115
|
+
note.textContent = t(reason, { turn: String(hit.turn), turns: String(hit.turns) });
|
|
4116
|
+
document.body.appendChild(note);
|
|
4117
|
+
window.setTimeout(function () {
|
|
4118
|
+
if (note.parentElement !== null) note.remove();
|
|
4119
|
+
}, 5000);
|
|
4120
|
+
} catch (error) {
|
|
4121
|
+
/* nothing to do if the toast itself fails */
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
|
|
3761
4125
|
/** Ring the row the search sent the user to, without taking keyboard focus. */
|
|
3762
4126
|
function flashTurnRow(row) {
|
|
3763
4127
|
try {
|
|
@@ -3816,9 +4180,422 @@
|
|
|
3816
4180
|
window.setTimeout(tick, 120);
|
|
3817
4181
|
}
|
|
3818
4182
|
|
|
3819
|
-
|
|
4183
|
+
/** Collapsed text of an element, for matching a message fragment. */
|
|
4184
|
+
function normalizedText(node) {
|
|
4185
|
+
var text = node !== null && node !== undefined && typeof node.textContent === "string" ? node.textContent : "";
|
|
4186
|
+
return text.replace(/\s+/g, " ").trim();
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
/**
|
|
4190
|
+
* The smallest element in the transcript that holds this fragment.
|
|
4191
|
+
*
|
|
4192
|
+
* The conversation view renders no per-turn anchor (`data-chat-turn` does
|
|
4193
|
+
* not exist in it), so text is the only handle a jump has. The needle is
|
|
4194
|
+
* retried in shorter pieces because markdown rendering can split or drop
|
|
4195
|
+
* parts of a long sentence.
|
|
4196
|
+
*/
|
|
4197
|
+
function findByText(scroller, seeks) {
|
|
4198
|
+
if (scroller === null) return null;
|
|
4199
|
+
var candidates = Array.isArray(seeks) ? seeks : (typeof seeks === "string" ? [seeks] : []);
|
|
4200
|
+
if (candidates.length === 0) return null;
|
|
4201
|
+
var probes = [];
|
|
4202
|
+
for (var c = 0; c < candidates.length; c += 1) {
|
|
4203
|
+
var needle = String(candidates[c] || "").replace(/\s+/g, " ").trim();
|
|
4204
|
+
if (needle === "") continue;
|
|
4205
|
+
probes.push(needle);
|
|
4206
|
+
if (needle.length > 34) probes.push(needle.slice(0, 34));
|
|
4207
|
+
if (needle.length > 16) probes.push(needle.slice(0, 16));
|
|
4208
|
+
}
|
|
4209
|
+
/* Walk the turn rows, not every element: one `textContent` read per row
|
|
4210
|
+
is a few dozen reads, where sweeping `querySelectorAll("*")` over a
|
|
4211
|
+
126-turn transcript is tens of thousands and freezes the panel. */
|
|
4212
|
+
var rows = [];
|
|
4213
|
+
try {
|
|
4214
|
+
var found = scroller.querySelectorAll("[data-chat-turn]");
|
|
4215
|
+
for (var r = 0; r < found.length && r < 400; r += 1) rows.push(found[r]);
|
|
4216
|
+
} catch (error) {
|
|
4217
|
+
rows = [];
|
|
4218
|
+
}
|
|
4219
|
+
for (var p = 0; p < probes.length; p += 1) {
|
|
4220
|
+
var probe = probes[p].trim();
|
|
4221
|
+
if (probe === "") continue;
|
|
4222
|
+
for (var q = 0; q < rows.length; q += 1) {
|
|
4223
|
+
if (normalizedText(rows[q]).indexOf(probe) !== -1) return rows[q];
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
return null;
|
|
4227
|
+
}
|
|
4228
|
+
/**
|
|
4229
|
+
* Whether a turn row actually carries the matched text.
|
|
4230
|
+
*
|
|
4231
|
+
* A very long session renders its old turns through a lighter path than
|
|
4232
|
+
* the recent ones - the per-message action bar is absent - and that path
|
|
4233
|
+
* may hold a collapsed placeholder instead of the message body. Landing on
|
|
4234
|
+
* one of those scrolls somewhere useless, so a row is only trusted when
|
|
4235
|
+
* the matched text (or at least a real block of text) is inside it.
|
|
4236
|
+
*/
|
|
4237
|
+
function rowCarriesSeek(row, seeks) {
|
|
4238
|
+
if (row === null || row === undefined) return false;
|
|
4239
|
+
var text = normalizedText(row);
|
|
4240
|
+
var candidates = Array.isArray(seeks) ? seeks : (typeof seeks === "string" ? [seeks] : []);
|
|
4241
|
+
for (var i = 0; i < candidates.length; i += 1) {
|
|
4242
|
+
var needle = String(candidates[i] || "").replace(/\s+/g, " ").trim();
|
|
4243
|
+
if (needle === "") continue;
|
|
4244
|
+
if (text.indexOf(needle) !== -1) return true;
|
|
4245
|
+
if (needle.length > 20 && text.indexOf(needle.slice(0, 20)) !== -1) return true;
|
|
4246
|
+
}
|
|
4247
|
+
/* No needle matched: a body of text still proves the row is rendered. */
|
|
4248
|
+
return text.length > 200;
|
|
4249
|
+
}
|
|
4250
|
+
|
|
4251
|
+
|
|
4252
|
+
/** The rail mark for one turn, if the rail currently renders it. */
|
|
4253
|
+
function railMarkFor(turn) {
|
|
4254
|
+
var wanted = Number(turn);
|
|
4255
|
+
if (!isFinite(wanted)) return null;
|
|
4256
|
+
var marks = railMarks();
|
|
4257
|
+
for (var i = 0; i < marks.length; i += 1) {
|
|
4258
|
+
if (turnOfRailMark(marks[i]) === wanted) return marks[i];
|
|
4259
|
+
}
|
|
4260
|
+
return null;
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* The rail's own scroll container.
|
|
4264
|
+
*
|
|
4265
|
+
* A mark's parent is the marks list, not the scroller: scrolling the list
|
|
4266
|
+
* does nothing, so the ancestor that actually scrolls is what has to move.
|
|
4267
|
+
*/
|
|
4268
|
+
function railList() {
|
|
4269
|
+
var marks = railMarks();
|
|
4270
|
+
if (marks.length === 0) return null;
|
|
4271
|
+
var node = marks[0].parentElement;
|
|
4272
|
+
while (node !== null && node !== undefined) {
|
|
4273
|
+
var scrolls = typeof node.scrollHeight === "number" && typeof node.clientHeight === "number"
|
|
4274
|
+
&& node.scrollHeight > node.clientHeight && node.clientHeight > 0;
|
|
4275
|
+
if (scrolls) return node;
|
|
4276
|
+
node = node.parentElement;
|
|
4277
|
+
}
|
|
4278
|
+
return null;
|
|
4279
|
+
}
|
|
4280
|
+
|
|
4281
|
+
/** The style rule the Custom Highlight API paints matches with. */
|
|
4282
|
+
var searchHighlightReady = false;
|
|
4283
|
+
|
|
4284
|
+
function ensureSearchHighlight() {
|
|
4285
|
+
if (searchHighlightReady || typeof document === "undefined") return;
|
|
4286
|
+
searchHighlightReady = true;
|
|
4287
|
+
try {
|
|
4288
|
+
var style = document.createElement("style");
|
|
4289
|
+
style.setAttribute("data-wsr-search-highlight", "true");
|
|
4290
|
+
style.textContent = "::highlight(wsr-search-hit){background:rgba(245,197,66,.45);color:inherit}";
|
|
4291
|
+
if (document.head !== null && document.head !== undefined) document.head.appendChild(style);
|
|
4292
|
+
} catch (error) {
|
|
4293
|
+
/* without the rule the jump still scrolls; only the paint is lost */
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
|
|
4297
|
+
/** Text nodes under a root, for finding the query terms inside a message. */
|
|
4298
|
+
function textNodesIn(root, limit) {
|
|
4299
|
+
var out = [];
|
|
4300
|
+
var cap = typeof limit === "number" && limit > 0 ? limit : 3000;
|
|
4301
|
+
if (root === null || root === undefined) return out;
|
|
4302
|
+
if (typeof NodeFilter === "undefined" || typeof document.createTreeWalker !== "function") return out;
|
|
4303
|
+
try {
|
|
4304
|
+
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
|
|
4305
|
+
while (out.length < cap && walker.nextNode() !== null) out.push(walker.currentNode);
|
|
4306
|
+
} catch (error) {
|
|
4307
|
+
return out;
|
|
4308
|
+
}
|
|
4309
|
+
return out;
|
|
4310
|
+
}
|
|
4311
|
+
/**
|
|
4312
|
+
* Paints the query's terms where they appear and centres the first one.
|
|
4313
|
+
*
|
|
4314
|
+
* Landing on the right turn is not enough: a long turn buries the match,
|
|
4315
|
+
* and reading it out of the chat by hand is what this panel exists to
|
|
4316
|
+
* avoid. The Custom Highlight API paints the ranges without touching the
|
|
4317
|
+
* React-managed DOM, so nothing is re-rendered or fought over.
|
|
4318
|
+
*/
|
|
4319
|
+
function markHitTerms(terms) {
|
|
4320
|
+
if (typeof document === "undefined") return;
|
|
4321
|
+
var needles = [];
|
|
4322
|
+
for (var i = 0; i < (Array.isArray(terms) ? terms.length : 0); i += 1) {
|
|
4323
|
+
var term = String(terms[i] || "").toLowerCase();
|
|
4324
|
+
if (term !== "" && needles.indexOf(term) === -1) needles.push(term);
|
|
4325
|
+
}
|
|
4326
|
+
if (needles.length === 0) return;
|
|
4327
|
+
/* Four short attempts at most: every attempt walks text nodes, and a
|
|
4328
|
+
long transcript has enough of them that polling was felt as lag. */
|
|
4329
|
+
var attempts = 0;
|
|
4330
|
+
var tick = function () {
|
|
4331
|
+
attempts += 1;
|
|
4332
|
+
if (attempts > 2) return;
|
|
4333
|
+
var scroller = conversationScroller();
|
|
4334
|
+
if (scroller === null) {
|
|
4335
|
+
window.setTimeout(tick, 300);
|
|
4336
|
+
return;
|
|
4337
|
+
}
|
|
4338
|
+
var beganScan = Date.now();
|
|
4339
|
+
var nodes = textNodesIn(scroller, 1200);
|
|
4340
|
+
var ranges = [];
|
|
4341
|
+
for (var n = 0; n < nodes.length && ranges.length < 40; n += 1) {
|
|
4342
|
+
var node = nodes[n];
|
|
4343
|
+
var text = String(node.nodeValue || "");
|
|
4344
|
+
if (text === "") continue;
|
|
4345
|
+
var lower = text.toLowerCase();
|
|
4346
|
+
for (var k = 0; k < needles.length && ranges.length < 40; k += 1) {
|
|
4347
|
+
var from = 0;
|
|
4348
|
+
while (from < lower.length && ranges.length < 40) {
|
|
4349
|
+
var at = lower.indexOf(needles[k], from);
|
|
4350
|
+
if (at < 0) break;
|
|
4351
|
+
try {
|
|
4352
|
+
var range = document.createRange();
|
|
4353
|
+
range.setStart(node, at);
|
|
4354
|
+
range.setEnd(node, at + needles[k].length);
|
|
4355
|
+
ranges.push(range);
|
|
4356
|
+
} catch (error) {
|
|
4357
|
+
/* a node the range API refuses is simply skipped */
|
|
4358
|
+
}
|
|
4359
|
+
from = at + needles[k].length;
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
}
|
|
4363
|
+
if (ranges.length === 0) {
|
|
4364
|
+
if (attempts < 2) window.setTimeout(tick, 600);
|
|
4365
|
+
return;
|
|
4366
|
+
}
|
|
4367
|
+
var painted = false;
|
|
4368
|
+
try {
|
|
4369
|
+
/* `CSS` in this module is the plugin's stylesheet array, so the
|
|
4370
|
+
DOM API has to be reached through `window`. */
|
|
4371
|
+
var cssApi = typeof window !== "undefined" && window !== null ? window.CSS : undefined;
|
|
4372
|
+
var HighlightCtor = typeof window !== "undefined" && window !== null ? window.Highlight : undefined;
|
|
4373
|
+
if (cssApi !== undefined && cssApi !== null && cssApi.highlights !== undefined && typeof HighlightCtor === "function") {
|
|
4374
|
+
ensureSearchHighlight();
|
|
4375
|
+
cssApi.highlights.set("wsr-search-hit", new HighlightCtor(ranges));
|
|
4376
|
+
painted = true;
|
|
4377
|
+
window.setTimeout(function () {
|
|
4378
|
+
try {
|
|
4379
|
+
cssApi.highlights.delete("wsr-search-hit");
|
|
4380
|
+
} catch (error) {
|
|
4381
|
+
/* the panel may have closed already */
|
|
4382
|
+
}
|
|
4383
|
+
}, 12000);
|
|
4384
|
+
}
|
|
4385
|
+
} catch (error) {
|
|
4386
|
+
painted = false;
|
|
4387
|
+
}
|
|
4388
|
+
var spentScan = Date.now() - beganScan;
|
|
4389
|
+
if (spentScan > 120 && typeof window !== "undefined") window.__DSH_WSR_LAST_TAIL_MS__ = spentScan;
|
|
4390
|
+
var first = ranges[0];
|
|
4391
|
+
var holder = first !== undefined && first !== null
|
|
4392
|
+
&& first.startContainer !== undefined && first.startContainer !== null
|
|
4393
|
+
? first.startContainer.parentElement
|
|
4394
|
+
: null;
|
|
4395
|
+
if (holder !== null && holder !== undefined) flashTurnRow(holder);
|
|
4396
|
+
else if (!painted) window.setTimeout(tick, 300);
|
|
4397
|
+
};
|
|
4398
|
+
window.setTimeout(tick, 120);
|
|
4399
|
+
} /**
|
|
4400
|
+
* Bring one search hit into view.
|
|
4401
|
+
*
|
|
4402
|
+
* Three routes, best first: a mounted `data-chat-turn` row (the chat keeps
|
|
4403
|
+
* one per flow item), the turn rail's own mark for that turn (it loads a
|
|
4404
|
+
* turn that is outside the window), and finally a proportional scroll plus
|
|
4405
|
+
* a text search, with the upward walk while older history loads.
|
|
4406
|
+
*/
|
|
4407
|
+
/** The badge currently pinned to a rail cell, if any. */
|
|
4408
|
+
|
|
4409
|
+
|
|
4410
|
+
/**
|
|
4411
|
+
* Bring one search hit into view.
|
|
4412
|
+
*
|
|
4413
|
+
* Scrolling the transcript does not page older history in: the chat asks the
|
|
4414
|
+
* user to load it. Clicking the turn rail's mark for that turn does load it,
|
|
4415
|
+
* which is the route the host itself uses, so the rail is the primary path
|
|
4416
|
+
* here. Mounted rows and a text search remain as fallbacks.
|
|
4417
|
+
*/
|
|
4418
|
+
/**
|
|
4419
|
+
* One last look after a rail click: the host is loading a whole page of
|
|
4420
|
+
* history, so nothing here may poll while that runs.
|
|
4421
|
+
*/
|
|
4422
|
+
function finaliseJump(hit, terms) {
|
|
4423
|
+
if (typeof document === "undefined") return;
|
|
4424
|
+
var began = Date.now();
|
|
4425
|
+
var seeks = Array.isArray(hit.seeks) ? hit.seeks : hit.seek;
|
|
4426
|
+
var scroller = conversationScroller();
|
|
4427
|
+
if (scroller !== null) {
|
|
4428
|
+
var row = findByText(scroller, seeks);
|
|
4429
|
+
if (row !== null) flashTurnRow(row);
|
|
4430
|
+
}
|
|
4431
|
+
markHitTerms(terms);
|
|
4432
|
+
/* Anything past a frame is ours to answer for, so say so rather than
|
|
4433
|
+
letting it pass as the host being slow. */
|
|
4434
|
+
var spent = Date.now() - began;
|
|
4435
|
+
if (spent > 120 && typeof window !== "undefined") {
|
|
4436
|
+
window.__DSH_WSR_LAST_TAIL_MS__ = spent;
|
|
4437
|
+
}
|
|
4438
|
+
}
|
|
4439
|
+
/**
|
|
4440
|
+
* Bring one search hit into view.
|
|
4441
|
+
*
|
|
4442
|
+
* Scrolling the transcript does not page older history in: the chat asks the
|
|
4443
|
+
* user to load it, while clicking the turn rail's mark loads and aligns that
|
|
4444
|
+
* turn. The rail is therefore the primary route. Everything here is kept
|
|
4445
|
+
* to a few cheap lookups: the host is rendering history at the same time,
|
|
4446
|
+
* and a polling loop on top of that is what made the jump feel frozen.
|
|
4447
|
+
*/
|
|
4448
|
+
function revealHit(hit, terms) {
|
|
4449
|
+
if (typeof document === "undefined" || hit === null || hit === undefined) return;
|
|
4450
|
+
var sessionId = hit.sessionId;
|
|
4451
|
+
var turn = Number(hit.turn);
|
|
4452
|
+
var seeksNow = Array.isArray(hit.seeks) ? hit.seeks : hit.seek;
|
|
4453
|
+
var deadline = Date.now() + (Number(hit.turns) > 40 ? 15000 : 9000);
|
|
4454
|
+
var opened = false;
|
|
4455
|
+
var reportedStub = false;
|
|
4456
|
+
var pokes = 0;
|
|
4457
|
+
var ticks = 0;
|
|
4458
|
+
/* Wall time includes the host opening the session and loading its
|
|
4459
|
+
history; only the synchronous work in here belongs to this plugin. */
|
|
4460
|
+
var spentMs = 0;
|
|
4461
|
+
var started = Date.now();
|
|
4462
|
+
var tick = function () {
|
|
4463
|
+
var beganTick = Date.now();
|
|
4464
|
+
var done = function () {
|
|
4465
|
+
spentMs += Date.now() - beganTick;
|
|
4466
|
+
};
|
|
4467
|
+
var result = tickOnce();
|
|
4468
|
+
done();
|
|
4469
|
+
return result;
|
|
4470
|
+
};
|
|
4471
|
+
var tickOnce = function () {
|
|
4472
|
+
if (Date.now() > deadline) {
|
|
4473
|
+
announceJumpFailure(hit, opened ? "search.jumpNoTurn" : "search.jumpNoSession");
|
|
4474
|
+
return;
|
|
4475
|
+
}
|
|
4476
|
+
if (currentConversationId() !== sessionId) {
|
|
4477
|
+
window.setTimeout(tick, 250);
|
|
4478
|
+
return;
|
|
4479
|
+
}
|
|
4480
|
+
opened = true;
|
|
4481
|
+
ticks += 1;
|
|
4482
|
+
var row = turnRowOf(turn);
|
|
4483
|
+
if (row !== null) {
|
|
4484
|
+
flashTurnRow(row);
|
|
4485
|
+
if (rowCarriesSeek(row, seeksNow)) {
|
|
4486
|
+
announceJump(hit, false, spentMs);
|
|
4487
|
+
markHitTerms(terms);
|
|
4488
|
+
return;
|
|
4489
|
+
}
|
|
4490
|
+
if (!reportedStub) {
|
|
4491
|
+
reportedStub = true;
|
|
4492
|
+
announceJumpFailure(hit, "search.jumpCollapsed");
|
|
4493
|
+
}
|
|
4494
|
+
window.setTimeout(tick, 500);
|
|
4495
|
+
return;
|
|
4496
|
+
}
|
|
4497
|
+
/* Query the rail every other tick: it is a document-wide lookup. */
|
|
4498
|
+
if (ticks % 2 === 1) {
|
|
4499
|
+
var mark = railMarkFor(turn);
|
|
4500
|
+
if (mark !== null) {
|
|
4501
|
+
try {
|
|
4502
|
+
mark.click();
|
|
4503
|
+
announceJump(hit, false, spentMs);
|
|
4504
|
+
/* The click starts a real history load: hand the thread back to
|
|
4505
|
+
the host and look once when it has had time to render. */
|
|
4506
|
+
window.setTimeout(function () {
|
|
4507
|
+
finaliseJump(hit, terms);
|
|
4508
|
+
suppressedUntil = 0;
|
|
4509
|
+
schedule();
|
|
4510
|
+
}, 1200);
|
|
4511
|
+
return;
|
|
4512
|
+
} catch (error) {
|
|
4513
|
+
/* fall through */
|
|
4514
|
+
}
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
/* The rail is virtualised too: nudge it so the wanted mark renders. */
|
|
4518
|
+
if (pokes < 4) {
|
|
4519
|
+
var list = railList();
|
|
4520
|
+
var turns = Number(hit.turns);
|
|
4521
|
+
if (list !== null && turn > 0 && turns > 0) {
|
|
4522
|
+
var span = Math.max(0, (Number(list.scrollHeight) || 0) - (Number(list.clientHeight) || 0));
|
|
4523
|
+
var ratio = Math.min(1, Math.max(0, (turn - 1) / Math.max(1, turns - 1)));
|
|
4524
|
+
scrollTo(list, span * ratio);
|
|
4525
|
+
pokes += 1;
|
|
4526
|
+
window.setTimeout(tick, 350);
|
|
4527
|
+
return;
|
|
4528
|
+
}
|
|
4529
|
+
}
|
|
4530
|
+
window.setTimeout(tick, 350);
|
|
4531
|
+
};
|
|
4532
|
+
window.setTimeout(tick, 200);
|
|
4533
|
+
}
|
|
4534
|
+
function jumpToSearchHit(hit, terms) {
|
|
4535
|
+
suspendPasses(12000);
|
|
3820
4536
|
openSessionRow(hit.sessionId);
|
|
3821
|
-
|
|
4537
|
+
revealHit(hit, terms);
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
/**
|
|
4541
|
+
* The chat's own turn rail: one button per turn, `data-index` + an
|
|
4542
|
+
* aria-label that names the turn. Clicking a mark is the official
|
|
4543
|
+
* navigation, and it also loads a turn that is not in the window yet.
|
|
4544
|
+
*/
|
|
4545
|
+
function railMarks() {
|
|
4546
|
+
if (typeof document === "undefined") return [];
|
|
4547
|
+
var all = null;
|
|
4548
|
+
try {
|
|
4549
|
+
/* The rail's own frame first: the same collection, found without
|
|
4550
|
+
walking the whole document. */
|
|
4551
|
+
var frame = document.querySelector('[class*="_frame"]');
|
|
4552
|
+
var scopedAll = frame === null ? null : frame.querySelectorAll("button[data-index]");
|
|
4553
|
+
all = scopedAll !== null && scopedAll.length > 0 ? scopedAll : document.querySelectorAll("button[data-index]");
|
|
4554
|
+
} catch (error) {
|
|
4555
|
+
return [];
|
|
4556
|
+
}
|
|
4557
|
+
var marks = [];
|
|
4558
|
+
for (var i = 0; i < (all === null ? 0 : all.length); i += 1) {
|
|
4559
|
+
var button = all[i];
|
|
4560
|
+
var className = typeof button.className === "string" ? button.className : "";
|
|
4561
|
+
if (className.indexOf("_mark") === -1) continue;
|
|
4562
|
+
marks.push(button);
|
|
4563
|
+
}
|
|
4564
|
+
return marks;
|
|
4565
|
+
}
|
|
4566
|
+
|
|
4567
|
+
/** The turn a rail mark points at: the last integer in its label. */
|
|
4568
|
+
/**
|
|
4569
|
+
* The turn a rail mark points at.
|
|
4570
|
+
*
|
|
4571
|
+
* The label starts with the turn number ("Jump to turn 3", "跳转到第 3 轮");
|
|
4572
|
+
* any count a wording appends comes later, so the first integer is the turn.
|
|
4573
|
+
* A label that carries a count instead of a turn would make the FIRST match
|
|
4574
|
+
* wrong in exactly the same way the LAST one was, so both are tried and the
|
|
4575
|
+
* mark's own order breaks the tie.
|
|
4576
|
+
*/
|
|
4577
|
+
function turnOfRailMark(button) {
|
|
4578
|
+
if (button === null || button === undefined || typeof button.getAttribute !== "function") return NaN;
|
|
4579
|
+
var label = String(button.getAttribute("aria-label") || "");
|
|
4580
|
+
var found = label.match(/\d+/);
|
|
4581
|
+
return found === null ? NaN : Number(found[0]);
|
|
4582
|
+
}
|
|
4583
|
+
|
|
4584
|
+
/** Click the rail mark for one turn, if it is currently rendered. */
|
|
4585
|
+
function jumpViaRail(turn) {
|
|
4586
|
+
var wanted = Number(turn);
|
|
4587
|
+
if (!isFinite(wanted)) return false;
|
|
4588
|
+
var marks = railMarks();
|
|
4589
|
+
for (var i = 0; i < marks.length; i += 1) {
|
|
4590
|
+
if (turnOfRailMark(marks[i]) !== wanted) continue;
|
|
4591
|
+
try {
|
|
4592
|
+
marks[i].click();
|
|
4593
|
+
return true;
|
|
4594
|
+
} catch (error) {
|
|
4595
|
+
return false;
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
return false;
|
|
3822
4599
|
}
|
|
3823
4600
|
|
|
3824
4601
|
/** Snippet text with every query term wrapped in a mark. */
|
|
@@ -3858,29 +4635,129 @@
|
|
|
3858
4635
|
* budget plus how many are still pending, so this asks again until the
|
|
3859
4636
|
* index has caught up instead of making the user press search twice.
|
|
3860
4637
|
*/
|
|
3861
|
-
|
|
3862
|
-
|
|
4638
|
+
/** A session id is a UUID; the head and tail are what tells two apart. */
|
|
4639
|
+
function shortSessionId(sessionId) {
|
|
4640
|
+
if (typeof sessionId !== "string" || sessionId === "") return "";
|
|
4641
|
+
return sessionId.length > 12 ? sessionId.slice(0, 8) + "\u2026" + sessionId.slice(-4) : sessionId;
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
/**
|
|
4645
|
+
* One search hit.
|
|
4646
|
+
*
|
|
4647
|
+
* A hit is only useful if it says which conversation and when: the
|
|
4648
|
+
* workspace narrows it down, but two sessions in one workspace read the
|
|
4649
|
+
* same without a title and a timestamp.
|
|
4650
|
+
*/
|
|
4651
|
+
function searchHitRow(hit, terms, onClick, extra) {
|
|
4652
|
+
var title = typeof hit.title === "string" && hit.title.trim() !== ""
|
|
4653
|
+
? hit.title.trim()
|
|
4654
|
+
: (typeof hit.sessionId === "string" ? shortSessionId(hit.sessionId) : "");
|
|
4655
|
+
var when = formatWhen(Number(hit.at) || 0);
|
|
4656
|
+
return h("div", {
|
|
4657
|
+
className: "wsr-hit",
|
|
4658
|
+
title: hit.cwd || "",
|
|
4659
|
+
onClick: onClick,
|
|
4660
|
+
},
|
|
4661
|
+
h("div", { className: "wsr-hit-head" },
|
|
4662
|
+
h("span", { className: "wsr-hit-role " + (hit.role === "user" ? "wsr-hit-user" : "wsr-hit-agent") }, hit.role === "user" ? t("search.you") : t("search.assistant")),
|
|
4663
|
+
h("span", { className: "wsr-hit-title", title: title }, title),
|
|
4664
|
+
typeof hit.workspace === "string" && hit.workspace !== "" ? h("span", { className: "wsr-hit-ws" }, hit.workspace) : null,
|
|
4665
|
+
h("span", { className: "wsr-hit-turn" }, t("search.turn", { n: String(hit.turn) })),
|
|
4666
|
+
/* The step inside the turn: it is what the reader checks against the
|
|
4667
|
+
chat after jumping, so a hit that looks wrong can be told apart
|
|
4668
|
+
from a jump that landed wrong. */
|
|
4669
|
+
typeof hit.step === "number" && isFinite(hit.step)
|
|
4670
|
+
? h("span", { className: "wsr-hit-step" }, t("search.step", { n: String(hit.step) }))
|
|
4671
|
+
: null,
|
|
4672
|
+
),
|
|
4673
|
+
h("div", { className: "wsr-hit-meta" },
|
|
4674
|
+
when !== "" ? h("span", { className: "wsr-hit-time" }, when) : null,
|
|
4675
|
+
typeof hit.cwd === "string" && hit.cwd !== "" ? h("span", { className: "wsr-hit-cwd" }, hit.cwd) : null,
|
|
4676
|
+
),
|
|
4677
|
+
h("div", { className: "wsr-hit-snippet" },
|
|
4678
|
+
hit.lead === true ? "\u2026" : null,
|
|
4679
|
+
highlightSnippet(hit.snippet || "", terms),
|
|
4680
|
+
hit.tail === true ? "\u2026" : null,
|
|
4681
|
+
),
|
|
4682
|
+
extra === undefined || extra === null ? null : extra,
|
|
4683
|
+
);
|
|
4684
|
+
}
|
|
4685
|
+
|
|
4686
|
+
/**
|
|
4687
|
+
* One search hit, with the surrounding text on demand.
|
|
4688
|
+
*
|
|
4689
|
+
* Opening a hit in a long session makes the chat mount a page of history,
|
|
4690
|
+
* which can take seconds. Reading the hit does not have to: the host ships
|
|
4691
|
+
* the matched neighbourhood, so the row can show it where it stands.
|
|
4692
|
+
*/
|
|
4693
|
+
function SearchHitRow(props) {
|
|
4694
|
+
var opened = react.useState(false);
|
|
4695
|
+
var context = typeof props.hit.context === "string" ? props.hit.context : "";
|
|
4696
|
+
var extra = context === "" ? null : [
|
|
4697
|
+
h("div", { className: "wsr-hit-actions" },
|
|
4698
|
+
h("button", {
|
|
4699
|
+
type: "button",
|
|
4700
|
+
className: "wsr-hit-context-toggle",
|
|
4701
|
+
onClick: function (event) {
|
|
4702
|
+
if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
4703
|
+
opened[1](opened[0] !== true);
|
|
4704
|
+
},
|
|
4705
|
+
}, opened[0] === true ? t("search.contextHide") : t("search.contextShow")),
|
|
4706
|
+
h("button", {
|
|
4707
|
+
type: "button",
|
|
4708
|
+
className: "wsr-hit-context-jump",
|
|
4709
|
+
onClick: function (event) {
|
|
4710
|
+
if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
4711
|
+
if (typeof props.onJump === "function") props.onJump();
|
|
4712
|
+
},
|
|
4713
|
+
}, t("search.openSession")),
|
|
4714
|
+
),
|
|
4715
|
+
opened[0] === true ? h("div", { className: "wsr-hit-context" }, context) : null,
|
|
4716
|
+
];
|
|
4717
|
+
return searchHitRow(props.hit, props.terms, props.onJump, extra);
|
|
4718
|
+
}
|
|
4719
|
+
|
|
4720
|
+
function SearchPanelPage(props) {
|
|
4721
|
+
var state = react.useState(searchLast === null
|
|
4722
|
+
? { loaded: false, query: "", hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" }
|
|
4723
|
+
: searchLast);
|
|
3863
4724
|
var view = state[0];
|
|
3864
4725
|
var setView = state[1];
|
|
4726
|
+
/* The recent-query list lives in the shared store, so it survives a
|
|
4727
|
+
restart and is the same list on every panel. */
|
|
4728
|
+
var preferences = props !== undefined && props !== null && typeof props.useStore === "function"
|
|
4729
|
+
? props.useStore(function (snapshot) { return snapshot; })
|
|
4730
|
+
: (data.settings || {});
|
|
4731
|
+
var actions = props !== undefined && props !== null && props.actions !== undefined ? props.actions : {};
|
|
4732
|
+
var historyList = preferences !== null && preferences !== undefined && Array.isArray(preferences.searchHistory)
|
|
4733
|
+
? preferences.searchHistory
|
|
4734
|
+
: [];
|
|
4735
|
+
/* Every update also parks the answer outside the component, so coming
|
|
4736
|
+
back from a hit restores the list instead of asking for a new search. */
|
|
4737
|
+
var commit = function (next) {
|
|
4738
|
+
searchLast = next;
|
|
4739
|
+
setView(next);
|
|
4740
|
+
};
|
|
3865
4741
|
|
|
3866
4742
|
var run = function (text, refresh) {
|
|
3867
4743
|
var query = typeof text === "string" ? text.trim() : "";
|
|
3868
4744
|
searchGeneration += 1;
|
|
3869
4745
|
var generation = searchGeneration;
|
|
3870
4746
|
if (query === "") {
|
|
3871
|
-
|
|
4747
|
+
commit({ loaded: true, query: "", hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: "" });
|
|
3872
4748
|
return;
|
|
3873
4749
|
}
|
|
3874
|
-
|
|
4750
|
+
if (typeof actions.pushSearch === "function") actions.pushSearch(query);
|
|
4751
|
+
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: "" });
|
|
3875
4752
|
var ask = function (needRefresh) {
|
|
3876
4753
|
searchPost({ query: query, refresh: needRefresh === true }).then(function (answer) {
|
|
3877
4754
|
if (generation !== searchGeneration) return;
|
|
3878
4755
|
var json = answer.json;
|
|
3879
4756
|
if (json === null || json.ok !== true) {
|
|
3880
|
-
|
|
4757
|
+
commit({ loaded: true, query: query, hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: t("search.failed") + "HTTP " + answer.status });
|
|
3881
4758
|
return;
|
|
3882
4759
|
}
|
|
3883
|
-
|
|
4760
|
+
commit({
|
|
3884
4761
|
loaded: true,
|
|
3885
4762
|
query: query,
|
|
3886
4763
|
hits: Array.isArray(json.hits) ? json.hits : [],
|
|
@@ -3899,7 +4776,7 @@
|
|
|
3899
4776
|
}
|
|
3900
4777
|
}).catch(function (error) {
|
|
3901
4778
|
if (generation !== searchGeneration) return;
|
|
3902
|
-
|
|
4779
|
+
commit({ loaded: true, query: query, hits: [], terms: [], scanned: 0, total: 0, pending: 0, took: 0, busy: false, error: t("search.failed") + (error && error.message ? error.message : error) });
|
|
3903
4780
|
});
|
|
3904
4781
|
};
|
|
3905
4782
|
ask(refresh === true);
|
|
@@ -3909,7 +4786,8 @@
|
|
|
3909
4786
|
className: "wsr-search-input",
|
|
3910
4787
|
type: "search",
|
|
3911
4788
|
placeholder: t("search.placeholder"),
|
|
3912
|
-
|
|
4789
|
+
/* The box comes back with the query that produced the results below. */
|
|
4790
|
+
defaultValue: view.query || searchDraft,
|
|
3913
4791
|
onChange: function (event) {
|
|
3914
4792
|
searchDraft = event !== undefined && event.target !== undefined ? String(event.target.value || "") : "";
|
|
3915
4793
|
},
|
|
@@ -3922,31 +4800,54 @@
|
|
|
3922
4800
|
});
|
|
3923
4801
|
|
|
3924
4802
|
var rows = view.hits.map(function (hit, index) {
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
h("span", { className: "wsr-hit-role " + (hit.role === "user" ? "wsr-hit-user" : "wsr-hit-agent") }, hit.role === "user" ? t("search.you") : t("search.assistant")),
|
|
3933
|
-
h("span", { className: "wsr-hit-title" }, hit.title || hit.sessionId || ""),
|
|
3934
|
-
typeof hit.workspace === "string" && hit.workspace !== "" ? h("span", { className: "wsr-hit-ws" }, hit.workspace) : null,
|
|
3935
|
-
h("span", { className: "wsr-hit-turn" }, t("search.turn", { n: String(hit.turn) })),
|
|
3936
|
-
),
|
|
3937
|
-
h("div", { className: "wsr-hit-snippet" },
|
|
3938
|
-
hit.lead === true ? "\u2026" : null,
|
|
3939
|
-
highlightSnippet(hit.snippet || "", view.terms),
|
|
3940
|
-
hit.tail === true ? "\u2026" : null,
|
|
3941
|
-
),
|
|
3942
|
-
);
|
|
4803
|
+
var row = h(SearchHitRow, {
|
|
4804
|
+
hit: hit,
|
|
4805
|
+
terms: view.terms,
|
|
4806
|
+
onJump: function () { jumpToSearchHit(hit, view.terms); },
|
|
4807
|
+
});
|
|
4808
|
+
row.key = String(hit.sessionId || "") + ":" + String(hit.seq || 0) + ":" + String(index);
|
|
4809
|
+
return row;
|
|
3943
4810
|
});
|
|
3944
4811
|
|
|
3945
4812
|
return h("div", { className: "wsr-page wsr-search-page" },
|
|
3946
4813
|
h("div", { className: "wsr-page-head" },
|
|
3947
4814
|
h("div", { className: "wsr-page-heading" }, t("search.title")),
|
|
3948
4815
|
),
|
|
3949
|
-
h("div", { className: "wsr-search-
|
|
4816
|
+
historyList.length === 0 ? null : h("div", { className: "wsr-search-history" },
|
|
4817
|
+
h("span", { className: "wsr-search-history-label" }, t("search.history")),
|
|
4818
|
+
historyList.map(function (item, index) {
|
|
4819
|
+
var text = String(item);
|
|
4820
|
+
return h("span", { className: "wsr-search-chip", key: text + ":" + String(index) },
|
|
4821
|
+
h("button", {
|
|
4822
|
+
type: "button",
|
|
4823
|
+
className: "wsr-search-chip-run",
|
|
4824
|
+
title: t("search.historyRun", { query: text }),
|
|
4825
|
+
onClick: function () {
|
|
4826
|
+
searchDraft = text;
|
|
4827
|
+
run(text, false);
|
|
4828
|
+
},
|
|
4829
|
+
}, text),
|
|
4830
|
+
h("button", {
|
|
4831
|
+
type: "button",
|
|
4832
|
+
className: "wsr-search-chip-drop",
|
|
4833
|
+
title: t("search.historyDrop"),
|
|
4834
|
+
"aria-label": t("search.historyDrop"),
|
|
4835
|
+
onClick: function (event) {
|
|
4836
|
+
if (event !== undefined && typeof event.stopPropagation === "function") event.stopPropagation();
|
|
4837
|
+
if (typeof actions.dropSearch === "function") actions.dropSearch(text);
|
|
4838
|
+
},
|
|
4839
|
+
}, "\u00d7"),
|
|
4840
|
+
);
|
|
4841
|
+
}),
|
|
4842
|
+
h("button", {
|
|
4843
|
+
type: "button",
|
|
4844
|
+
className: "wsr-search-history-clear",
|
|
4845
|
+
onClick: function () {
|
|
4846
|
+
if (typeof actions.clearSearches === "function") actions.clearSearches();
|
|
4847
|
+
},
|
|
4848
|
+
}, t("search.historyClear")),
|
|
4849
|
+
),
|
|
4850
|
+
h("div", { className: "wsr-search-bar" },
|
|
3950
4851
|
input,
|
|
3951
4852
|
h("button", { type: "button", className: "wsr-btn", onClick: function () { run(searchDraft, false); } }, t("search.run")),
|
|
3952
4853
|
),
|
|
@@ -4414,6 +5315,10 @@
|
|
|
4414
5315
|
|
|
4415
5316
|
function apply_(ctx) {
|
|
4416
5317
|
installCss();
|
|
5318
|
+
/* The turn rail's cells carry no text, and the host's own hover preview
|
|
5319
|
+
shows a turn's prompt (a number appears only when that prompt is
|
|
5320
|
+
empty). Labelling belongs to the search feature, so it is off with
|
|
5321
|
+
it. */
|
|
4417
5322
|
/* Navigation and unpinning live in the Workspace UI service. It can be
|
|
4418
5323
|
provided after this plugin applies, so take it now when it is there and
|
|
4419
5324
|
let cordis hand it over later when it is not. Never fail the plugin over
|
|
@@ -4431,7 +5336,7 @@
|
|
|
4431
5336
|
}
|
|
4432
5337
|
var prefs = clientStore.defineStore({
|
|
4433
5338
|
init: function () {
|
|
4434
|
-
return { enabled: true, foldDays: DEFAULT_DAYS, keepActive: true, colors: true, pinnedSection: true, argMode: "tool", followUps: {} };
|
|
5339
|
+
return { enabled: true, foldDays: DEFAULT_DAYS, keepActive: true, colors: true, pinnedSection: true, argMode: "tool", followUps: {}, searchHistory: [] };
|
|
4435
5340
|
},
|
|
4436
5341
|
persist: "dsh.ws-recency.prefs.v1",
|
|
4437
5342
|
actions: {
|
|
@@ -4455,6 +5360,30 @@
|
|
|
4455
5360
|
if (draft.followUps === null || typeof draft.followUps !== "object") return;
|
|
4456
5361
|
if (draft.followUps[sessionId] !== undefined) delete draft.followUps[sessionId];
|
|
4457
5362
|
},
|
|
5363
|
+
/* Recent queries, newest first, case-insensitively de-duplicated. */
|
|
5364
|
+
pushSearch: function (draft, query) {
|
|
5365
|
+
var text = typeof query === "string" ? query.trim() : "";
|
|
5366
|
+
if (text === "") return;
|
|
5367
|
+
var list = Array.isArray(draft.searchHistory) ? draft.searchHistory : [];
|
|
5368
|
+
var lower = text.toLowerCase();
|
|
5369
|
+
var next = [text];
|
|
5370
|
+
for (var i = 0; i < list.length && next.length < SEARCH_HISTORY_MAX; i += 1) {
|
|
5371
|
+
if (String(list[i]).toLowerCase() === lower) continue;
|
|
5372
|
+
next.push(list[i]);
|
|
5373
|
+
}
|
|
5374
|
+
draft.searchHistory = next;
|
|
5375
|
+
},
|
|
5376
|
+
dropSearch: function (draft, query) {
|
|
5377
|
+
var text = typeof query === "string" ? query.trim().toLowerCase() : "";
|
|
5378
|
+
if (text === "") return;
|
|
5379
|
+
var list = Array.isArray(draft.searchHistory) ? draft.searchHistory : [];
|
|
5380
|
+
draft.searchHistory = list.filter(function (item) {
|
|
5381
|
+
return String(item).trim().toLowerCase() !== text;
|
|
5382
|
+
});
|
|
5383
|
+
},
|
|
5384
|
+
clearSearches: function (draft) {
|
|
5385
|
+
draft.searchHistory = [];
|
|
5386
|
+
},
|
|
4458
5387
|
},
|
|
4459
5388
|
});
|
|
4460
5389
|
|
|
@@ -4468,7 +5397,19 @@
|
|
|
4468
5397
|
prefsStore = prefs;
|
|
4469
5398
|
|
|
4470
5399
|
if (typeof MutationObserver === "function" && top() !== null) {
|
|
4471
|
-
observer = new MutationObserver(
|
|
5400
|
+
observer = new MutationObserver(function (records) {
|
|
5401
|
+
if (passesSuspended()) return;
|
|
5402
|
+
/* One relevant record is enough: the pass itself is the expensive
|
|
5403
|
+
part, and it always looks at the whole sidebar. */
|
|
5404
|
+
var list = Array.isArray(records) ? records : [];
|
|
5405
|
+
var chain = sidebarChain();
|
|
5406
|
+
for (var i = 0; i < list.length; i += 1) {
|
|
5407
|
+
if (outsideSidebar(list[i] === undefined || list[i] === null ? null : list[i].target, chain)) {
|
|
5408
|
+
schedule();
|
|
5409
|
+
return;
|
|
5410
|
+
}
|
|
5411
|
+
}
|
|
5412
|
+
});
|
|
4472
5413
|
observer.observe(top(), {
|
|
4473
5414
|
childList: true,
|
|
4474
5415
|
subtree: true,
|
|
@@ -4507,23 +5448,27 @@
|
|
|
4507
5448
|
}, ColorsRow);
|
|
4508
5449
|
});
|
|
4509
5450
|
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
5451
|
+
if (SEARCH_ENABLED) {
|
|
5452
|
+
ctx.slots.inject("sidebar.panellist", function () {
|
|
5453
|
+
return ctx.slots.register({
|
|
5454
|
+
name: "sidebar.panellist",
|
|
5455
|
+
id: "ws-recency-search",
|
|
5456
|
+
order: 19,
|
|
5457
|
+
locale: NS,
|
|
5458
|
+
label: function () { return t("search.title"); },
|
|
5459
|
+
}, SearchPanelIcon);
|
|
5460
|
+
});
|
|
5461
|
+
|
|
5462
|
+
ctx.slots.inject("main", function () {
|
|
5463
|
+
return ctx.slots.register({
|
|
5464
|
+
name: "main",
|
|
5465
|
+
key: "ws-recency-search",
|
|
5466
|
+
locale: NS,
|
|
5467
|
+
store: prefs,
|
|
5468
|
+
}, SearchPanelPage);
|
|
5469
|
+
});
|
|
5470
|
+
}
|
|
4519
5471
|
|
|
4520
|
-
ctx.slots.inject("main", function () {
|
|
4521
|
-
return ctx.slots.register({
|
|
4522
|
-
name: "main",
|
|
4523
|
-
key: "ws-recency-search",
|
|
4524
|
-
locale: NS,
|
|
4525
|
-
}, SearchPanelPage);
|
|
4526
|
-
});
|
|
4527
5472
|
|
|
4528
5473
|
ctx.slots.inject("sidebar.panellist", function () {
|
|
4529
5474
|
return ctx.slots.register({
|
|
@@ -4633,6 +5578,16 @@
|
|
|
4633
5578
|
}, StatsMenuItem);
|
|
4634
5579
|
});
|
|
4635
5580
|
|
|
5581
|
+
ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
|
|
5582
|
+
return ctx.slots.register({
|
|
5583
|
+
name: "sidebar.workspaces.session.menu.item",
|
|
5584
|
+
id: "ws-recency-diagnose",
|
|
5585
|
+
order: 690,
|
|
5586
|
+
store: prefs,
|
|
5587
|
+
locale: NS,
|
|
5588
|
+
}, DiagnoseMenuItem);
|
|
5589
|
+
});
|
|
5590
|
+
|
|
4636
5591
|
ctx.slots.inject("sidebar.workspaces.session.menu.item", function () {
|
|
4637
5592
|
return ctx.slots.register({
|
|
4638
5593
|
name: "sidebar.workspaces.session.menu.item",
|
|
@@ -4670,6 +5625,15 @@
|
|
|
4670
5625
|
reveal: revealTurn,
|
|
4671
5626
|
jump: jumpToSearchHit,
|
|
4672
5627
|
turnRow: turnRowOf,
|
|
5628
|
+
hitRow: searchHitRow,
|
|
5629
|
+
shortId: shortSessionId,
|
|
5630
|
+
resumePasses: function () { suppressedUntil = 0; },
|
|
5631
|
+
};
|
|
5632
|
+
|
|
5633
|
+
/* The search feature ships disabled while its cost is being isolated;
|
|
5634
|
+
tests turn it on so the code stays covered. */
|
|
5635
|
+
exports.__setSearchEnabled = function (value) {
|
|
5636
|
+
SEARCH_ENABLED = value === true;
|
|
4673
5637
|
};
|
|
4674
5638
|
|
|
4675
5639
|
exports.name = "dsh-ws-recency";
|