@xsok/dsh-enhanced 0.2.2-6 → 0.2.2-8
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/CHANGELOG.md +29 -0
- package/README.md +1 -15
- package/client.js +1001 -102
- package/host/engine/index.js +8 -0
- package/host/engine/projcache.js +15 -1
- package/host/engine/sessions.js +27 -6
- package/host/schedule.js +24 -9
- package/host/search.js +75 -7
- package/host/sync.js +6 -0
- package/index.js +62 -0
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -73,6 +73,10 @@ window.__ModuleLoader__.load({
|
|
|
73
73
|
'restart.desc': 'Restart the desktop app now?',
|
|
74
74
|
'restart.confirm': 'Restart',
|
|
75
75
|
'restart.busy': 'A turn is still running. Stop it, then restart.',
|
|
76
|
+
'restart.auto': '{reason} · restarting in {seconds}s',
|
|
77
|
+
'restart.reason.sync': 'Sync done',
|
|
78
|
+
'restart.reason.move': 'Session moved',
|
|
79
|
+
'restart.reason.restore': 'Cloud applied',
|
|
76
80
|
'overwrite.cloud': 'Overwrite cloud',
|
|
77
81
|
'overwrite.local': 'Overwrite this machine',
|
|
78
82
|
'overwrite.awayCloud': 'Replaces the cloud with this machine\'s data. Nothing is merged.',
|
|
@@ -173,6 +177,7 @@ window.__ModuleLoader__.load({
|
|
|
173
177
|
'sync.probe': 'Check',
|
|
174
178
|
'sync.run': 'Sync now',
|
|
175
179
|
'sync.running': 'Syncing…',
|
|
180
|
+
'sync.done': 'Sessions synced',
|
|
176
181
|
'sync.never': 'Not run yet.',
|
|
177
182
|
'sync.last': 'Last run: {time} · {result} · {ms} ms',
|
|
178
183
|
'sync.result.ok': 'ok',
|
|
@@ -212,6 +217,12 @@ window.__ModuleLoader__.load({
|
|
|
212
217
|
'delete.failed': 'Delete failed: {message}',
|
|
213
218
|
'delete.blocked': 'A running session cannot be deleted.',
|
|
214
219
|
'move.label': 'Move to workspace…',
|
|
220
|
+
'hover.sessionId': 'Session ID: ',
|
|
221
|
+
'hover.copy.title': 'Session name',
|
|
222
|
+
'hover.copy.id': 'Session ID',
|
|
223
|
+
'hover.copy.path': 'Workspace path',
|
|
224
|
+
'hover.copy.done': 'Copied: {label}',
|
|
225
|
+
'hover.copy.failed': 'Copy failed: {label}',
|
|
215
226
|
'move.running': 'Move to workspace (running)',
|
|
216
227
|
'move.title': 'Move to workspace',
|
|
217
228
|
'move.desc': 'Moves the session into the target workspace in place: the session itself is unchanged and only its working directory becomes the target. Later tool calls run there. The new grouping appears after the app restarts.',
|
|
@@ -264,6 +275,10 @@ window.__ModuleLoader__.load({
|
|
|
264
275
|
'restart.desc': '立即重启桌面应用?',
|
|
265
276
|
'restart.confirm': '重启',
|
|
266
277
|
'restart.busy': '有任务正在运行,结束或停止后再重启。',
|
|
278
|
+
'restart.auto': '{reason} · 即将自动重启 {seconds}s',
|
|
279
|
+
'restart.reason.sync': '同步完成',
|
|
280
|
+
'restart.reason.move': '会话已移动',
|
|
281
|
+
'restart.reason.restore': '已应用云端',
|
|
267
282
|
'overwrite.cloud': '覆盖云端',
|
|
268
283
|
'overwrite.local': '覆盖本机',
|
|
269
284
|
'overwrite.awayCloud': '将以本机数据完全替换云端,不做合并。',
|
|
@@ -364,6 +379,7 @@ window.__ModuleLoader__.load({
|
|
|
364
379
|
'sync.probe': '检查',
|
|
365
380
|
'sync.run': '立即同步',
|
|
366
381
|
'sync.running': '正在同步…',
|
|
382
|
+
'sync.done': '会话同步完成',
|
|
367
383
|
'sync.never': '尚未运行。',
|
|
368
384
|
'sync.last': '上次同步:{time} · {result} · {ms} ms',
|
|
369
385
|
'sync.result.ok': '成功',
|
|
@@ -403,6 +419,12 @@ window.__ModuleLoader__.load({
|
|
|
403
419
|
'delete.failed': '删除失败:{message}',
|
|
404
420
|
'delete.blocked': '运行中的会话不可删除。',
|
|
405
421
|
'move.label': '移动到工作区…',
|
|
422
|
+
'hover.sessionId': '会话ID:',
|
|
423
|
+
'hover.copy.title': '会话名称',
|
|
424
|
+
'hover.copy.id': '会话ID',
|
|
425
|
+
'hover.copy.path': '工作区路径',
|
|
426
|
+
'hover.copy.done': '已复制:{label}',
|
|
427
|
+
'hover.copy.failed': '复制失败:{label}',
|
|
406
428
|
'move.running': '移动到工作区(运行中)',
|
|
407
429
|
'move.title': '移动到工作区',
|
|
408
430
|
'move.desc': '将该会话整体移入目标工作区:会话本身不变,只是工作目录改到目标目录,之后的工具调用会在那里执行。分组变化需要重启应用后完全生效。',
|
|
@@ -468,14 +490,28 @@ window.__ModuleLoader__.load({
|
|
|
468
490
|
font:inherit;font-weight:600;padding:6px 10px;border-radius:8px;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
469
491
|
.dshe-group-title:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.05))}
|
|
470
492
|
.dshe-group-meta{color:var(--dsw-alias-label-secondary,#8a919c);font-weight:400;font-size:11px;margin-left:8px}
|
|
471
|
-
.dshe-match{display:flex;gap:
|
|
493
|
+
.dshe-match{display:flex;gap:6px;width:100%;text-align:left;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#4b5563);
|
|
472
494
|
font:inherit;padding:5px 10px 5px 18px;border-radius:8px;cursor:pointer;line-height:18px}
|
|
473
495
|
.dshe-match:hover,.dshe-match[data-active="true"]{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.06))}
|
|
474
496
|
.dshe-role{flex:none;font-size:11px;padding:0 6px;border-radius:6px;background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.05));
|
|
475
497
|
color:var(--dsw-alias-label-secondary,#6b7280);height:18px;line-height:18px}
|
|
476
498
|
.dshe-snippet{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-primary,#2b2f36)}
|
|
499
|
+
.dshe-group-title{display:flex;align-items:center;gap:6px}
|
|
500
|
+
.dshe-group-caret{flex:none;width:12px;color:var(--dsw-alias-label-secondary,#8a919c);font-size:11px}
|
|
501
|
+
.dshe-group-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
502
|
+
.dshe-group-meta{flex:none;margin-left:0}
|
|
503
|
+
.dshe-match-time{flex:none;min-width:0;color:var(--dsw-alias-label-secondary,#8a919c);font-size:11px;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
477
504
|
.dshe-mark{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#3b6ef5) 26%,transparent);color:inherit;border-radius:3px;padding:0 1px}
|
|
478
505
|
.dshe-section{display:flex;flex-direction:column;gap:14px;width:100%;font-size:13px}
|
|
506
|
+
.dshe-match-time[data-tier="1"]{min-width:52px}
|
|
507
|
+
.dshe-match-time[data-tier="2"]{min-width:60px}
|
|
508
|
+
.dshe-match-time[data-tier="3"]{min-width:88px}
|
|
509
|
+
.dshe-preview{position:fixed;z-index:2147482000;max-width:min(560px,46vw);max-height:46vh;overflow:auto;
|
|
510
|
+
background:var(--dsw-alias-bg-overlay,#fff);color:var(--dsw-alias-label-primary,#1b1d22);
|
|
511
|
+
border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.12));border-radius:10px;padding:10px 12px;
|
|
512
|
+
font-size:12px;line-height:1.6;white-space:pre-wrap;word-break:break-word;box-shadow:0 12px 32px rgba(0,0,0,.18)}
|
|
513
|
+
.dshe-mark-current{background:#ffd76a;color:#1b1d22;border-radius:3px;box-shadow:0 0 0 2px rgba(255,193,7,.5)}
|
|
514
|
+
::highlight(dshe-flash){background-color:#ffe27a;color:#1b1d22;border-radius:3px}
|
|
479
515
|
.dshe-section-title{margin:0;font-size:15px;font-weight:600;color:var(--dsw-alias-label-primary,#1b1d22)}
|
|
480
516
|
.dshe-subsection-title{margin:4px 0 0;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary,#1b1d22);
|
|
481
517
|
padding-top:10px;border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.08))}
|
|
@@ -560,9 +596,14 @@ window.__ModuleLoader__.load({
|
|
|
560
596
|
.dshe-preset-chip{display:inline-flex;align-items:center;gap:4px}
|
|
561
597
|
.dshe-action-active{background:var(--dsw-alias-brand-primary,#3b6ef5);color:#fff;border-color:transparent}
|
|
562
598
|
.dshe-action-danger{color:var(--dsw-alias-state-error-primary,#c0392b);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c0392b) 45%,transparent)}
|
|
563
|
-
.dshe-toast{position:
|
|
564
|
-
|
|
565
|
-
|
|
599
|
+
.dshe-toast{position:static;pointer-events:auto;z-index:2010;
|
|
600
|
+
background:rgba(24,26,30,.96);color:#fff;border:1px solid rgba(255,255,255,.18);
|
|
601
|
+
border-radius:14px;padding:10px 18px;font-size:13px;line-height:1.5;
|
|
602
|
+
box-shadow:0 18px 40px rgba(0,0,0,.38);max-width:70vw;user-select:none}
|
|
603
|
+
.dshe-toast[data-kind="error"]{color:#ff4600}
|
|
604
|
+
.dshe-toast-spinner{display:inline-block;width:14px;height:14px;margin-left:8px;vertical-align:-2px;
|
|
605
|
+
animation:dshe-toast-spin .8s linear infinite}
|
|
606
|
+
@keyframes dshe-toast-spin{to{transform:rotate(360deg)}}
|
|
566
607
|
`;
|
|
567
608
|
|
|
568
609
|
// ── store ────────────────────────────────────────────────────────────────
|
|
@@ -581,6 +622,9 @@ window.__ModuleLoader__.load({
|
|
|
581
622
|
sync: { loading: false, busy: false, target: null, state: null, error: null, showLog: false, webdav: null, webdavBusy: false, history: [], historyOpen: null, historyLimit: 5, auto: null },
|
|
582
623
|
overwrite: { open: false, direction: 'cloud', busy: false, preview: null, error: null },
|
|
583
624
|
restartConfirm: false,
|
|
625
|
+
syncLive: false,
|
|
626
|
+
syncDone: false,
|
|
627
|
+
restartCountdown: null,
|
|
584
628
|
presetEdit: null,
|
|
585
629
|
presetReplace: null,
|
|
586
630
|
pauseOpen: false,
|
|
@@ -603,6 +647,8 @@ window.__ModuleLoader__.load({
|
|
|
603
647
|
&& trim(item.root) === trim(settings.webdavRoot);
|
|
604
648
|
}
|
|
605
649
|
|
|
650
|
+
let restartCountdownTimer = null;
|
|
651
|
+
|
|
606
652
|
const store = {
|
|
607
653
|
get: () => state,
|
|
608
654
|
subscribe(listener) {
|
|
@@ -624,8 +670,25 @@ window.__ModuleLoader__.load({
|
|
|
624
670
|
},
|
|
625
671
|
toast(kind, text) {
|
|
626
672
|
if (toastTimer !== null) clearTimeout(toastTimer);
|
|
673
|
+
toastTimer = null;
|
|
627
674
|
store.set({ toast: { kind, text, id: Date.now() } });
|
|
628
|
-
toastTimer = setTimeout(() => store.set({ toast: null }), kind === 'error' ?
|
|
675
|
+
toastTimer = setTimeout(() => store.set({ toast: null }), kind === 'error' ? 5000 : 3000);
|
|
676
|
+
},
|
|
677
|
+
/** A notice that stays until the work finishes; the spinner shows progress. */
|
|
678
|
+
toastBusy(text) {
|
|
679
|
+
if (toastTimer !== null) {
|
|
680
|
+
clearTimeout(toastTimer);
|
|
681
|
+
toastTimer = null;
|
|
682
|
+
}
|
|
683
|
+
store.set({ toast: { kind: 'info', text, spinner: true, id: Date.now() } });
|
|
684
|
+
},
|
|
685
|
+
/** Remove the sticky notice once the work has an answer of its own. */
|
|
686
|
+
clearToast() {
|
|
687
|
+
if (toastTimer !== null) {
|
|
688
|
+
clearTimeout(toastTimer);
|
|
689
|
+
toastTimer = null;
|
|
690
|
+
}
|
|
691
|
+
store.set({ toast: null });
|
|
629
692
|
},
|
|
630
693
|
async init() {
|
|
631
694
|
try {
|
|
@@ -639,6 +702,32 @@ window.__ModuleLoader__.load({
|
|
|
639
702
|
store.set({ ready: true });
|
|
640
703
|
console.warn('[dsh-enhanced] initial state failed:', error);
|
|
641
704
|
}
|
|
705
|
+
// Launch-time catch-up: runs regardless of the automatic sync switch.
|
|
706
|
+
window.setTimeout(() => { void store.startupSync(); }, 2000);
|
|
707
|
+
// Follow the automatic sync only; the manual one has its own notice.
|
|
708
|
+
// The call waits until the run flips, so there is no polling timer.
|
|
709
|
+
void store.watchSyncState();
|
|
710
|
+
},
|
|
711
|
+
/**
|
|
712
|
+
* Sync once shortly after launch, reusing the normal run path.
|
|
713
|
+
*
|
|
714
|
+
* Doing it here (instead of on the host) means a restart that follows can
|
|
715
|
+
* show its countdown in the UI first.
|
|
716
|
+
*/
|
|
717
|
+
async startupSync() {
|
|
718
|
+
// Launch-time catch-up: unconditional on the sync switch, but it must not
|
|
719
|
+
// run while a turn is in progress.
|
|
720
|
+
if (store.get().sync.busy === true) return;
|
|
721
|
+
try {
|
|
722
|
+
const data = await runtime.rpc('sync.run', { quiet: true });
|
|
723
|
+
if (data?.skipped === 'busy') return;
|
|
724
|
+
store.set({ sync: { ...store.get().sync, state: data, error: null } });
|
|
725
|
+
await store.loadSync();
|
|
726
|
+
const pulled = Number(data?.summary?.sessions?.pulled) || Number(data?.summary?.sessions?.created) || 0;
|
|
727
|
+
if (pulled > 0) store.restartSoon('restart.reason.sync');
|
|
728
|
+
} catch (error) {
|
|
729
|
+
console.warn('[dsh-enhanced] startup sync failed:', error);
|
|
730
|
+
}
|
|
642
731
|
},
|
|
643
732
|
async refreshCount() {
|
|
644
733
|
try {
|
|
@@ -880,7 +969,7 @@ window.__ModuleLoader__.load({
|
|
|
880
969
|
const warning = typeof data?.warning === 'string' && data.warning !== '' ? data.warning : null;
|
|
881
970
|
store.toast(warning === null ? 'success' : 'info', warning ?? runtime.t('move.done', { title: target?.title ?? '' }));
|
|
882
971
|
await store.refreshCount();
|
|
883
|
-
if (data?.needsRestart === true) store.
|
|
972
|
+
if (data?.needsRestart === true) store.restartSoon('restart.reason.move');
|
|
884
973
|
} catch (error) {
|
|
885
974
|
store.set({ move: { ...state.move, busy: false, error: String(error?.message ?? error) } });
|
|
886
975
|
}
|
|
@@ -907,6 +996,41 @@ window.__ModuleLoader__.load({
|
|
|
907
996
|
store.set({ sync: { ...state.sync, loading: false, error: String(error?.message ?? error) } });
|
|
908
997
|
}
|
|
909
998
|
},
|
|
999
|
+
/**
|
|
1000
|
+
* Wait for the AUTOMATIC sync to start or stop, then wait again.
|
|
1001
|
+
*
|
|
1002
|
+
* The host resolves the call when the run flips (or after 25 s), so the
|
|
1003
|
+
* badge updates at once and the idle cost is one open request.
|
|
1004
|
+
*/
|
|
1005
|
+
async watchSyncState() {
|
|
1006
|
+
let lastUserSeq = null;
|
|
1007
|
+
for (;;) {
|
|
1008
|
+
try {
|
|
1009
|
+
const data = await runtime.rpc('sync.watch');
|
|
1010
|
+
// A new user message (in any session) is the send signal the host sees.
|
|
1011
|
+
if (Number.isFinite(data?.userSeq)) {
|
|
1012
|
+
if (lastUserSeq === null) lastUserSeq = data.userSeq;
|
|
1013
|
+
else if (data.userSeq > lastUserSeq) {
|
|
1014
|
+
lastUserSeq = data.userSeq;
|
|
1015
|
+
if (store.get().syncDone === true) store.set({ syncDone: false });
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const running = data?.auto?.running === true;
|
|
1019
|
+
const wasRunning = store.get().syncLive === true;
|
|
1020
|
+
if (running) {
|
|
1021
|
+
store.set({ syncLive: true, syncDone: false });
|
|
1022
|
+
} else if (wasRunning) {
|
|
1023
|
+
// The run just finished: keep a short "done" line until a click.
|
|
1024
|
+
store.set({ syncLive: false, syncDone: true });
|
|
1025
|
+
} else {
|
|
1026
|
+
store.set({ syncLive: false });
|
|
1027
|
+
}
|
|
1028
|
+
} catch {
|
|
1029
|
+
// A dropped connection only means a short pause before retrying.
|
|
1030
|
+
await new Promise((resolve) => { window.setTimeout(resolve, 3000); });
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
},
|
|
910
1034
|
async probeSync() {
|
|
911
1035
|
if (state.sync.busy) return;
|
|
912
1036
|
store.set({ sync: { ...state.sync, busy: true, error: null } });
|
|
@@ -921,10 +1045,15 @@ window.__ModuleLoader__.load({
|
|
|
921
1045
|
},
|
|
922
1046
|
async runSyncNow() {
|
|
923
1047
|
if (state.sync.busy) return;
|
|
924
|
-
store.set({ sync: { ...state.sync, busy: true, error: null } });
|
|
1048
|
+
store.set({ sync: { ...state.sync, busy: true, error: null }, syncDone: false });
|
|
1049
|
+
store.toastBusy(runtime.t('sync.running'));
|
|
925
1050
|
try {
|
|
926
1051
|
const data = await runtime.rpc('sync.run');
|
|
927
|
-
store.
|
|
1052
|
+
store.clearToast();
|
|
1053
|
+
store.set({
|
|
1054
|
+
sync: { ...state.sync, busy: false, state: data, error: null },
|
|
1055
|
+
syncDone: data?.ok !== false,
|
|
1056
|
+
});
|
|
928
1057
|
store.toast(
|
|
929
1058
|
data?.ok === false ? 'error' : 'success',
|
|
930
1059
|
data?.ok === false
|
|
@@ -934,15 +1063,37 @@ window.__ModuleLoader__.load({
|
|
|
934
1063
|
await store.loadSync();
|
|
935
1064
|
const pulled = Number(data?.summary?.sessions?.pulled) || Number(data?.summary?.sessions?.created) || 0;
|
|
936
1065
|
if (pulled > 0) {
|
|
937
|
-
store.
|
|
938
|
-
store.restartApp();
|
|
1066
|
+
store.restartSoon('restart.reason.sync');
|
|
939
1067
|
}
|
|
940
1068
|
} catch (error) {
|
|
1069
|
+
store.clearToast();
|
|
941
1070
|
store.set({ sync: { ...state.sync, busy: false, error: String(error?.message ?? error) } });
|
|
942
1071
|
store.toast('error', String(error?.message ?? error));
|
|
943
1072
|
await store.loadSync();
|
|
944
1073
|
}
|
|
945
1074
|
},
|
|
1075
|
+
/**
|
|
1076
|
+
* Announce an automatic restart, counting down from three, then restart.
|
|
1077
|
+
*/
|
|
1078
|
+
restartSoon(reasonKey) {
|
|
1079
|
+
if (restartCountdownTimer !== null) return;
|
|
1080
|
+
const reason = runtime.t(reasonKey);
|
|
1081
|
+
let left = 3;
|
|
1082
|
+
const tick = () => {
|
|
1083
|
+
store.toast('info', runtime.t('restart.auto', { reason, seconds: String(left) }));
|
|
1084
|
+
if (left === 0) {
|
|
1085
|
+
window.clearInterval(restartCountdownTimer);
|
|
1086
|
+
restartCountdownTimer = null;
|
|
1087
|
+
store.set({ restartCountdown: null });
|
|
1088
|
+
store.restartApp();
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
store.set({ restartCountdown: left });
|
|
1092
|
+
left -= 1;
|
|
1093
|
+
};
|
|
1094
|
+
tick();
|
|
1095
|
+
restartCountdownTimer = window.setInterval(tick, 1000);
|
|
1096
|
+
},
|
|
946
1097
|
/** Restart the app so a structural change becomes visible. */
|
|
947
1098
|
restartApp() {
|
|
948
1099
|
window.setTimeout(() => {
|
|
@@ -1105,7 +1256,7 @@ window.__ModuleLoader__.load({
|
|
|
1105
1256
|
: runtime.t('overwrite.localDone', { n: String(result?.copied ?? 0) }));
|
|
1106
1257
|
await store.loadSync();
|
|
1107
1258
|
// Replacing this machine wholesale only takes effect after a restart.
|
|
1108
|
-
if (direction === 'local') store.
|
|
1259
|
+
if (direction === 'local') store.restartSoon('restart.reason.restore');
|
|
1109
1260
|
} catch (error) {
|
|
1110
1261
|
store.set({ overwrite: { ...state.overwrite, busy: false, error: String(error?.message ?? error) } });
|
|
1111
1262
|
}
|
|
@@ -1250,6 +1401,44 @@ window.__ModuleLoader__.load({
|
|
|
1250
1401
|
}, h('span', {}));
|
|
1251
1402
|
}
|
|
1252
1403
|
|
|
1404
|
+
/**
|
|
1405
|
+
* Compact stamp for one search hit: 今日 10:11 / 昨日 10:11 / 周三 12:11 /
|
|
1406
|
+
* 11-02 11:12 / 2025-12-31 08:44.
|
|
1407
|
+
*/
|
|
1408
|
+
function formatMatchTime(value) {
|
|
1409
|
+
const ms = Number(value);
|
|
1410
|
+
if (!Number.isFinite(ms) || ms <= 0) return '';
|
|
1411
|
+
const date = new Date(ms);
|
|
1412
|
+
const now = new Date();
|
|
1413
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
1414
|
+
const clock = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
1415
|
+
const dayStart = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
1416
|
+
const days = Math.round((dayStart(now) - dayStart(date)) / 86400000);
|
|
1417
|
+
if (days === 0) return `今日 ${clock}`;
|
|
1418
|
+
if (days === 1) return `昨日 ${clock}`;
|
|
1419
|
+
const monday = (d) => {
|
|
1420
|
+
const start = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
1421
|
+
start.setDate(start.getDate() - ((start.getDay() + 6) % 7));
|
|
1422
|
+
return start.getTime();
|
|
1423
|
+
};
|
|
1424
|
+
if (monday(date) === monday(now)) {
|
|
1425
|
+
const names = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
|
1426
|
+
return `${names[(date.getDay() + 6) % 7]} ${clock}`;
|
|
1427
|
+
}
|
|
1428
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
1429
|
+
return `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${clock}`;
|
|
1430
|
+
}
|
|
1431
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${clock}`;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
/** Width class for a match stamp: 1 = 今日/昨日/周X, 2 = MM-DD, 3 = YYYY-MM-DD. */
|
|
1435
|
+
function timeTier(text) {
|
|
1436
|
+
if (typeof text !== 'string' || text === '') return 1;
|
|
1437
|
+
if (/^(今日|昨日|周[一二三四五六日])/u.test(text)) return 1;
|
|
1438
|
+
if (/^\d{2}-\d{2} /u.test(text)) return 2;
|
|
1439
|
+
return 3;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1253
1442
|
function formatSize(bytes) {
|
|
1254
1443
|
const value = Number(bytes) || 0;
|
|
1255
1444
|
if (value < 1024) return `${String(value)} B`;
|
|
@@ -1263,6 +1452,28 @@ window.__ModuleLoader__.load({
|
|
|
1263
1452
|
return new Date(time).toLocaleString();
|
|
1264
1453
|
}
|
|
1265
1454
|
|
|
1455
|
+
/** Highlight every hit; the one at focusIndex also gets the current style. */
|
|
1456
|
+
function highlightFocus(text, query, focusIndex) {
|
|
1457
|
+
const needle = typeof query === 'string' ? query.trim() : '';
|
|
1458
|
+
if (needle === '') return text;
|
|
1459
|
+
const lower = text.toLowerCase();
|
|
1460
|
+
const target = needle.toLowerCase();
|
|
1461
|
+
const parts = [];
|
|
1462
|
+
let from = 0;
|
|
1463
|
+
let key = 0;
|
|
1464
|
+
let index = lower.indexOf(target);
|
|
1465
|
+
while (index >= 0) {
|
|
1466
|
+
if (index > from) parts.push(text.slice(from, index));
|
|
1467
|
+
const current = Number(focusIndex) === index;
|
|
1468
|
+
parts.push(h('mark', { className: current ? 'dshe-mark dshe-mark-current' : 'dshe-mark', key: `f${String(key)}` }, text.slice(index, index + target.length)));
|
|
1469
|
+
key += 1;
|
|
1470
|
+
from = index + target.length;
|
|
1471
|
+
index = lower.indexOf(target, from);
|
|
1472
|
+
}
|
|
1473
|
+
if (from < text.length) parts.push(text.slice(from));
|
|
1474
|
+
return parts;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1266
1477
|
function highlight(text, query) {
|
|
1267
1478
|
const needle = typeof query === 'string' ? query.trim() : '';
|
|
1268
1479
|
if (needle === '') return text;
|
|
@@ -1346,6 +1557,154 @@ window.__ModuleLoader__.load({
|
|
|
1346
1557
|
}, running ? runtime.t('delete.running') : runtime.t('delete.label'));
|
|
1347
1558
|
}
|
|
1348
1559
|
|
|
1560
|
+
/**
|
|
1561
|
+
* Dismiss on a double click anywhere in the window.
|
|
1562
|
+
*
|
|
1563
|
+
* A single click stays harmless, so a stray click does not hide a notice the
|
|
1564
|
+
* reader is still reading. The listener lives on the document, so a double
|
|
1565
|
+
* click on the notice, on the chat, or in the sidebar all count.
|
|
1566
|
+
*/
|
|
1567
|
+
function armQuickClose(node, close) {
|
|
1568
|
+
let done = false;
|
|
1569
|
+
const onDouble = () => {
|
|
1570
|
+
if (done) return;
|
|
1571
|
+
done = true;
|
|
1572
|
+
document.removeEventListener('dblclick', onDouble, true);
|
|
1573
|
+
close();
|
|
1574
|
+
};
|
|
1575
|
+
const onSingle = (event) => event.stopPropagation();
|
|
1576
|
+
node.addEventListener('click', onSingle);
|
|
1577
|
+
document.addEventListener('dblclick', onDouble, true);
|
|
1578
|
+
return () => {
|
|
1579
|
+
done = true;
|
|
1580
|
+
document.removeEventListener('dblclick', onDouble, true);
|
|
1581
|
+
node.removeEventListener('click', onSingle);
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
/**
|
|
1586
|
+
* Put one string on the clipboard, then say what happened.
|
|
1587
|
+
*
|
|
1588
|
+
* The async Clipboard API needs a secure context; the textarea fallback keeps
|
|
1589
|
+
* the action working when the page is served from elsewhere.
|
|
1590
|
+
*/
|
|
1591
|
+
async function copyWithNotice(value, labelKey) {
|
|
1592
|
+
const label = runtime.t(labelKey);
|
|
1593
|
+
const done = () => runtime.store.toast('success', runtime.t('hover.copy.done', { label }));
|
|
1594
|
+
const failed = () => runtime.store.toast('error', runtime.t('hover.copy.failed', { label }));
|
|
1595
|
+
try {
|
|
1596
|
+
await navigator.clipboard.writeText(value);
|
|
1597
|
+
done();
|
|
1598
|
+
return;
|
|
1599
|
+
} catch {
|
|
1600
|
+
// fall through to the legacy path
|
|
1601
|
+
}
|
|
1602
|
+
try {
|
|
1603
|
+
const area = document.createElement('textarea');
|
|
1604
|
+
area.value = value;
|
|
1605
|
+
area.setAttribute('readonly', '');
|
|
1606
|
+
area.style.cssText = 'position:fixed;top:-1000px;opacity:0';
|
|
1607
|
+
document.body.appendChild(area);
|
|
1608
|
+
area.select();
|
|
1609
|
+
const ok = document.execCommand('copy');
|
|
1610
|
+
area.remove();
|
|
1611
|
+
if (ok) done();
|
|
1612
|
+
else failed();
|
|
1613
|
+
} catch {
|
|
1614
|
+
failed();
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Session id line inside the row's hover card.
|
|
1620
|
+
*
|
|
1621
|
+
* The hover slot sits below the relative time, but the id reads better right
|
|
1622
|
+
* under the title, so the slot only carries the session identity: the line
|
|
1623
|
+
* itself is created imperatively and parked after the title element, which
|
|
1624
|
+
* keeps React's own layout untouched. Any structural surprise means no line.
|
|
1625
|
+
*/
|
|
1626
|
+
function SessionIdRow(props) {
|
|
1627
|
+
const id = typeof props?.sessionId === 'string' ? props.sessionId : '';
|
|
1628
|
+
const markerRef = React.useRef(null);
|
|
1629
|
+
|
|
1630
|
+
React.useEffect(() => {
|
|
1631
|
+
const marker = markerRef.current;
|
|
1632
|
+
if (marker === null || id === '') return undefined;
|
|
1633
|
+
try {
|
|
1634
|
+
const host = marker.closest('[data-slot="sidebar.session.row.hover"]');
|
|
1635
|
+
const content = host === null ? null : host.parentElement;
|
|
1636
|
+
const title = content === null ? null : content.firstElementChild;
|
|
1637
|
+
if (title === null) return undefined;
|
|
1638
|
+
|
|
1639
|
+
const children = Array.from(content.children);
|
|
1640
|
+
const candidatePath = children.length > 1 ? children[1] : null;
|
|
1641
|
+
// The path line is the one carrying a separator; a reshaped card just
|
|
1642
|
+
// leaves this field unbound.
|
|
1643
|
+
const pathText = candidatePath === null ? '' : (candidatePath.textContent ?? '').trim();
|
|
1644
|
+
const pathLine = /[\\/:]/.test(pathText) ? candidatePath : null;
|
|
1645
|
+
|
|
1646
|
+
// The card's own click copies the session id; each field now copies its
|
|
1647
|
+
// own text instead, so a mis-click still produces something useful.
|
|
1648
|
+
const bindings = [];
|
|
1649
|
+
const bind = (element, value, labelKey) => {
|
|
1650
|
+
if (element === null || typeof value !== 'string' || value.trim() === '') return;
|
|
1651
|
+
const handler = (event) => {
|
|
1652
|
+
event.preventDefault();
|
|
1653
|
+
event.stopPropagation();
|
|
1654
|
+
void copyWithNotice(value.trim(), labelKey);
|
|
1655
|
+
};
|
|
1656
|
+
element.addEventListener('click', handler);
|
|
1657
|
+
element.style.cursor = 'pointer';
|
|
1658
|
+
bindings.push({ element, handler });
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1661
|
+
bind(title, title.textContent ?? '', 'hover.copy.title');
|
|
1662
|
+
bind(pathLine, pathLine === null ? '' : pathLine.textContent ?? '', 'hover.copy.path');
|
|
1663
|
+
|
|
1664
|
+
const line = document.createElement('div');
|
|
1665
|
+
line.className = 'dshe-session-id';
|
|
1666
|
+
line.title = id;
|
|
1667
|
+
line.dataset.sessionId = id;
|
|
1668
|
+
line.style.cssText = [
|
|
1669
|
+
'margin-top:2px',
|
|
1670
|
+
'color:var(--dsw-alias-hovercard-label-secondary, currentColor)',
|
|
1671
|
+
'font-size:12px',
|
|
1672
|
+
'line-height:16px',
|
|
1673
|
+
'overflow-wrap:anywhere',
|
|
1674
|
+
'word-break:break-all',
|
|
1675
|
+
'user-select:text',
|
|
1676
|
+
'cursor:pointer',
|
|
1677
|
+
].join(';');
|
|
1678
|
+
line.textContent = runtime.t('hover.sessionId') + id;
|
|
1679
|
+
line.addEventListener('click', (event) => {
|
|
1680
|
+
event.preventDefault();
|
|
1681
|
+
event.stopPropagation();
|
|
1682
|
+
void copyWithNotice(id, 'hover.copy.id');
|
|
1683
|
+
});
|
|
1684
|
+
title.insertAdjacentElement('afterend', line);
|
|
1685
|
+
|
|
1686
|
+
// The slot's own wrapper also forwards clicks to the card; keep it quiet.
|
|
1687
|
+
const markerClick = (event) => event.stopPropagation();
|
|
1688
|
+
marker.addEventListener('click', markerClick);
|
|
1689
|
+
|
|
1690
|
+
return () => {
|
|
1691
|
+
for (const binding of bindings) {
|
|
1692
|
+
binding.element.removeEventListener('click', binding.handler);
|
|
1693
|
+
binding.element.style.cursor = '';
|
|
1694
|
+
}
|
|
1695
|
+
marker.removeEventListener('click', markerClick);
|
|
1696
|
+
line.remove();
|
|
1697
|
+
};
|
|
1698
|
+
} catch {
|
|
1699
|
+
// A layout change without a line is better than a broken card.
|
|
1700
|
+
return undefined;
|
|
1701
|
+
}
|
|
1702
|
+
}, [id]);
|
|
1703
|
+
|
|
1704
|
+
if (id === '') return null;
|
|
1705
|
+
return h('span', { ref: markerRef, style: { display: 'none' } });
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1349
1708
|
// ── delete confirmation ──────────────────────────────────────────────────
|
|
1350
1709
|
|
|
1351
1710
|
const displayName = (value) => {
|
|
@@ -1614,12 +1973,108 @@ const displayName = (value) => {
|
|
|
1614
1973
|
return Math.max(0, Math.round(bottom));
|
|
1615
1974
|
}
|
|
1616
1975
|
|
|
1976
|
+
|
|
1977
|
+
|
|
1617
1978
|
function SearchOverlay() {
|
|
1618
1979
|
const state = useStore();
|
|
1619
1980
|
const search = state.search;
|
|
1620
1981
|
const inputRef = React.useRef(null);
|
|
1621
1982
|
const resultsRef = React.useRef(null);
|
|
1622
1983
|
const [active, setActive] = React.useState(0);
|
|
1984
|
+
const [expanded, setExpanded] = React.useState(null);
|
|
1985
|
+
const [preview, setPreview] = React.useState(null);
|
|
1986
|
+
|
|
1987
|
+
// The card lives on document.body: inside the dialog an animated ancestor would
|
|
1988
|
+
// turn position:fixed into a local coordinate system and clip it.
|
|
1989
|
+
React.useEffect(() => {
|
|
1990
|
+
const existing = document.getElementById('dshe-preview-el');
|
|
1991
|
+
if (existing !== null) existing.remove();
|
|
1992
|
+
if (preview === null) return;
|
|
1993
|
+
|
|
1994
|
+
const node = document.createElement('div');
|
|
1995
|
+
node.id = 'dshe-preview-el';
|
|
1996
|
+
node.className = 'dshe-preview';
|
|
1997
|
+
node.style.cssText = [
|
|
1998
|
+
'position:fixed',
|
|
1999
|
+
'z-index:2147482000',
|
|
2000
|
+
'box-sizing:border-box',
|
|
2001
|
+
'overflow:auto',
|
|
2002
|
+
'width:' + String(preview.width) + 'px',
|
|
2003
|
+
'left:' + String(preview.left) + 'px',
|
|
2004
|
+
'max-height:' + String(preview.maxHeight ?? 320) + 'px',
|
|
2005
|
+
preview.bottom !== null && preview.bottom !== undefined
|
|
2006
|
+
? 'bottom:' + String(preview.bottom) + 'px'
|
|
2007
|
+
: 'top:' + String(Math.max(12, preview.top ?? 12)) + 'px',
|
|
2008
|
+
].join(';');
|
|
2009
|
+
|
|
2010
|
+
const needle = search.query.trim().toLowerCase();
|
|
2011
|
+
const text = String(preview.text ?? '');
|
|
2012
|
+
if (needle === '') {
|
|
2013
|
+
node.textContent = text;
|
|
2014
|
+
} else {
|
|
2015
|
+
let from = 0;
|
|
2016
|
+
let at = text.toLowerCase().indexOf(needle);
|
|
2017
|
+
while (at >= 0) {
|
|
2018
|
+
if (at > from) node.appendChild(document.createTextNode(text.slice(from, at)));
|
|
2019
|
+
const mark = document.createElement('mark');
|
|
2020
|
+
mark.className = at === preview.hit ? 'dshe-mark dshe-mark-current' : 'dshe-mark';
|
|
2021
|
+
mark.textContent = text.slice(at, at + needle.length);
|
|
2022
|
+
node.appendChild(mark);
|
|
2023
|
+
from = at + needle.length;
|
|
2024
|
+
at = text.toLowerCase().indexOf(needle, from);
|
|
2025
|
+
}
|
|
2026
|
+
if (from < text.length) node.appendChild(document.createTextNode(text.slice(from)));
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
node.addEventListener('mouseenter', () => {
|
|
2030
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
2031
|
+
});
|
|
2032
|
+
node.addEventListener('mouseleave', () => {
|
|
2033
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
2034
|
+
previewTimer.current = window.setTimeout(() => setPreview(null), 160);
|
|
2035
|
+
});
|
|
2036
|
+
document.body.appendChild(node);
|
|
2037
|
+
|
|
2038
|
+
// Keep it inside the window, then centre the focused hit.
|
|
2039
|
+
const rect = node.getBoundingClientRect();
|
|
2040
|
+
if (rect.bottom > window.innerHeight - 12) {
|
|
2041
|
+
node.style.top = 'auto';
|
|
2042
|
+
node.style.bottom = String(Math.max(12, Math.round(window.innerHeight - rect.top - (window.innerHeight - 24 - rect.height)))) + 'px';
|
|
2043
|
+
}
|
|
2044
|
+
const mark = node.querySelector('.dshe-mark-current');
|
|
2045
|
+
if (mark !== null) {
|
|
2046
|
+
const box = node.getBoundingClientRect();
|
|
2047
|
+
const markRect = mark.getBoundingClientRect();
|
|
2048
|
+
node.scrollTop += markRect.top - box.top - node.clientHeight / 2 + markRect.height / 2;
|
|
2049
|
+
}
|
|
2050
|
+
return () => { node.remove(); };
|
|
2051
|
+
}, [preview, search.query]);
|
|
2052
|
+
|
|
2053
|
+
const previewRef = React.useRef(null);
|
|
2054
|
+
const previewTimer = React.useRef(null);
|
|
2055
|
+
const previewGate = React.useRef(true);
|
|
2056
|
+
const previewHover = React.useRef(null);
|
|
2057
|
+
const previewPointer = React.useRef({ x: 0, y: 0 });
|
|
2058
|
+
const previewEpoch = React.useRef(0);
|
|
2059
|
+
|
|
2060
|
+
React.useEffect(() => {
|
|
2061
|
+
// Typing hides the preview; it may only reappear after the pointer moves.
|
|
2062
|
+
previewGate.current = true;
|
|
2063
|
+
if (previewHover.current !== null) {
|
|
2064
|
+
window.clearTimeout(previewHover.current);
|
|
2065
|
+
previewHover.current = null;
|
|
2066
|
+
}
|
|
2067
|
+
setPreview(null);
|
|
2068
|
+
}, [search.query]);
|
|
2069
|
+
|
|
2070
|
+
React.useEffect(() => {
|
|
2071
|
+
const onMove = (event) => {
|
|
2072
|
+
previewGate.current = false;
|
|
2073
|
+
previewPointer.current = { x: event.clientX, y: event.clientY };
|
|
2074
|
+
};
|
|
2075
|
+
window.addEventListener('mousemove', onMove, { passive: true });
|
|
2076
|
+
return () => window.removeEventListener('mousemove', onMove);
|
|
2077
|
+
}, []);
|
|
1623
2078
|
|
|
1624
2079
|
React.useEffect(() => {
|
|
1625
2080
|
if (search.open !== true) return undefined;
|
|
@@ -1648,26 +2103,34 @@ const displayName = (value) => {
|
|
|
1648
2103
|
}, [search.open]);
|
|
1649
2104
|
|
|
1650
2105
|
const flat = React.useMemo(() => {
|
|
1651
|
-
const
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
2106
|
+
const groups = search.groups ?? [];
|
|
2107
|
+
const target = expanded === null ? groups[0] : groups.find((group) => group.sessionId === expanded);
|
|
2108
|
+
return (target?.matches ?? []).map((match) => ({ group: target, match }));
|
|
2109
|
+
}, [search.groups, expanded]);
|
|
2110
|
+
|
|
2111
|
+
const groups = search.groups ?? [];
|
|
2112
|
+
const totalMatches = React.useMemo(
|
|
2113
|
+
() => groups.reduce((sum, group) => sum + (group.matches ?? []).length, 0),
|
|
2114
|
+
[search.groups],
|
|
2115
|
+
);
|
|
1657
2116
|
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
let cursor = 0;
|
|
1661
|
-
for (const group of search.groups ?? []) {
|
|
1662
|
-
map.set(group.sessionId, cursor);
|
|
1663
|
-
cursor += (group.matches ?? []).length;
|
|
1664
|
-
}
|
|
1665
|
-
return map;
|
|
2117
|
+
React.useEffect(() => {
|
|
2118
|
+
setExpanded((groups[0]?.sessionId) ?? null);
|
|
1666
2119
|
}, [search.groups]);
|
|
1667
2120
|
|
|
1668
2121
|
React.useEffect(() => {
|
|
1669
2122
|
setActive(0);
|
|
1670
|
-
}, [
|
|
2123
|
+
}, [expanded]);
|
|
2124
|
+
|
|
2125
|
+
React.useEffect(() => {
|
|
2126
|
+
previewEpoch.current += 1;
|
|
2127
|
+
if (previewHover.current !== null) {
|
|
2128
|
+
window.clearTimeout(previewHover.current);
|
|
2129
|
+
previewHover.current = null;
|
|
2130
|
+
}
|
|
2131
|
+
setPreview(null);
|
|
2132
|
+
}, [search.open, search.groups]);
|
|
2133
|
+
|
|
1671
2134
|
|
|
1672
2135
|
React.useEffect(() => {
|
|
1673
2136
|
if (active >= flat.length) setActive(flat.length === 0 ? 0 : flat.length - 1);
|
|
@@ -1710,11 +2173,11 @@ const displayName = (value) => {
|
|
|
1710
2173
|
}
|
|
1711
2174
|
};
|
|
1712
2175
|
|
|
1713
|
-
const totalMatches = flat.length;
|
|
1714
2176
|
const meta = search.status === 'done'
|
|
1715
2177
|
? runtime.t('search.meta', { count: (search.groups ?? []).length, matches: totalMatches })
|
|
1716
2178
|
: '';
|
|
1717
2179
|
|
|
2180
|
+
|
|
1718
2181
|
const panel = h('div', { className: 'dshe-overlay dshe-overlay-top', role: 'presentation', style: { top: `${String(captionHeight())}px` } },
|
|
1719
2182
|
h('div', { className: 'dshe-backdrop', 'aria-hidden': 'true', onClick: () => runtime.store.closeSearch() }),
|
|
1720
2183
|
h('div', {
|
|
@@ -1748,27 +2211,82 @@ const displayName = (value) => {
|
|
|
1748
2211
|
search.status === 'idle' ? h('div', { className: 'dshe-status' }, runtime.t('search.hint')) : null,
|
|
1749
2212
|
search.status === 'done' && totalMatches === 0 ? h('div', { className: 'dshe-status' }, runtime.t('search.empty')) : null,
|
|
1750
2213
|
search.status === 'done'
|
|
1751
|
-
?
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
title: group.title,
|
|
1756
|
-
onClick: () => open(group.sessionId),
|
|
1757
|
-
}, group.title, h('span', { className: 'dshe-group-meta' }, (group.matches ?? []).length + '')),
|
|
1758
|
-
(group.matches ?? []).map((match, index) => {
|
|
1759
|
-
const rowIndex = (offsets.get(group.sessionId) ?? 0) + index;
|
|
1760
|
-
return h('button', {
|
|
2214
|
+
? groups.map((group) => {
|
|
2215
|
+
const isOpen = group.sessionId === expanded;
|
|
2216
|
+
return h('div', { className: 'dshe-group', key: group.sessionId },
|
|
2217
|
+
h('button', {
|
|
1761
2218
|
type: 'button',
|
|
1762
|
-
className: 'dshe-
|
|
1763
|
-
|
|
1764
|
-
'
|
|
1765
|
-
onClick: () =>
|
|
2219
|
+
className: 'dshe-group-title',
|
|
2220
|
+
title: group.title,
|
|
2221
|
+
'aria-expanded': isOpen ? 'true' : 'false',
|
|
2222
|
+
onClick: () => setExpanded(isOpen ? null : group.sessionId),
|
|
1766
2223
|
},
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
)
|
|
1770
|
-
|
|
1771
|
-
|
|
2224
|
+
h('span', { className: 'dshe-group-caret' }, isOpen ? '▾' : '▸'),
|
|
2225
|
+
h('span', { className: 'dshe-group-name' }, group.title),
|
|
2226
|
+
h('span', { className: 'dshe-group-meta' }, (group.matches ?? []).length + '')),
|
|
2227
|
+
isOpen
|
|
2228
|
+
? (group.matches ?? []).map((match, index) => h('button', {
|
|
2229
|
+
type: 'button',
|
|
2230
|
+
className: 'dshe-match',
|
|
2231
|
+
onMouseEnter: (event) => {
|
|
2232
|
+
if (previewHover.current !== null) window.clearTimeout(previewHover.current);
|
|
2233
|
+
if (previewGate.current === true) return;
|
|
2234
|
+
const row = event.currentTarget;
|
|
2235
|
+
if (event.clientX !== undefined) previewPointer.current = { x: event.clientX, y: event.clientY };
|
|
2236
|
+
const epoch = previewEpoch.current;
|
|
2237
|
+
previewHover.current = window.setTimeout(() => {
|
|
2238
|
+
if (previewEpoch.current !== epoch) return;
|
|
2239
|
+
previewHover.current = null;
|
|
2240
|
+
const rect = row.getBoundingClientRect();
|
|
2241
|
+
const dialog = row.closest('.dshe-search');
|
|
2242
|
+
const box = dialog === null ? null : dialog.getBoundingClientRect();
|
|
2243
|
+
const base = box !== null && box.width > 200 ? box.width : window.innerWidth;
|
|
2244
|
+
const width = Math.max(280, Math.min(460, Math.round(base * 0.62)));
|
|
2245
|
+
const pointer = previewPointer.current;
|
|
2246
|
+
const left = Math.max(12, Math.min(Math.round(pointer.x + 16), window.innerWidth - width - 12));
|
|
2247
|
+
const spaceBelow = Math.round(window.innerHeight - rect.bottom - 12);
|
|
2248
|
+
const spaceAbove = Math.round(rect.top - 12);
|
|
2249
|
+
// Pick whichever side has more room, so a row near the bottom opens upwards.
|
|
2250
|
+
const goAbove = spaceAbove > spaceBelow;
|
|
2251
|
+
if (goAbove) {
|
|
2252
|
+
const bottom = Math.max(12, Math.round(window.innerHeight - (rect.top - 6)));
|
|
2253
|
+
const maxHeight = Math.max(160, Math.min(Math.round(window.innerHeight * 0.7), spaceAbove - 6));
|
|
2254
|
+
setPreview({ text: match.preview || match.snippet || '', hit: match.previewHit ?? -1, left, width, maxHeight, top: null, bottom });
|
|
2255
|
+
} else {
|
|
2256
|
+
const top = Math.round(rect.bottom + 6);
|
|
2257
|
+
const maxHeight = Math.max(160, Math.min(Math.round(window.innerHeight * 0.7), spaceBelow - 6));
|
|
2258
|
+
setPreview({ text: match.preview || match.snippet || '', hit: match.previewHit ?? -1, left, width, maxHeight, top, bottom: null });
|
|
2259
|
+
}
|
|
2260
|
+
}, 1000);
|
|
2261
|
+
},
|
|
2262
|
+
onMouseLeave: () => {
|
|
2263
|
+
if (previewHover.current !== null) {
|
|
2264
|
+
window.clearTimeout(previewHover.current);
|
|
2265
|
+
previewHover.current = null;
|
|
2266
|
+
}
|
|
2267
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
2268
|
+
previewTimer.current = window.setTimeout(() => setPreview(null), 160);
|
|
2269
|
+
},
|
|
2270
|
+
key: `${group.sessionId}-${String(match.seq ?? 'title')}-${String(index)}`,
|
|
2271
|
+
'data-active': index === active ? 'true' : 'false',
|
|
2272
|
+
onClick: () => {
|
|
2273
|
+
previewEpoch.current += 1;
|
|
2274
|
+
if (previewHover.current !== null) {
|
|
2275
|
+
window.clearTimeout(previewHover.current);
|
|
2276
|
+
previewHover.current = null;
|
|
2277
|
+
}
|
|
2278
|
+
if (previewTimer.current !== null) window.clearTimeout(previewTimer.current);
|
|
2279
|
+
setPreview(null);
|
|
2280
|
+
open(group.sessionId, match);
|
|
2281
|
+
},
|
|
2282
|
+
},
|
|
2283
|
+
h('span', { className: 'dshe-match-time', 'data-tier': String(timeTier(formatMatchTime(match.time))) }, formatMatchTime(match.time)),
|
|
2284
|
+
h('span', { className: 'dshe-role' }, runtime.t(`role.${match.role ?? 'body'}`)),
|
|
2285
|
+
h('span', { className: 'dshe-snippet' }, highlight(match.snippet ?? '', search.query)),
|
|
2286
|
+
))
|
|
2287
|
+
: null,
|
|
2288
|
+
);
|
|
2289
|
+
})
|
|
1772
2290
|
: null,
|
|
1773
2291
|
),
|
|
1774
2292
|
),
|
|
@@ -2337,9 +2855,11 @@ const displayName = (value) => {
|
|
|
2337
2855
|
if (host === null) {
|
|
2338
2856
|
host = document.createElement('div');
|
|
2339
2857
|
host.id = 'dshe-toast-host';
|
|
2340
|
-
host.style.cssText = 'position:fixed;left:0;right:0;bottom:28px;display:flex;justify-content:center;pointer-events:none;z-index:2147483000';
|
|
2341
2858
|
document.body.appendChild(host);
|
|
2342
2859
|
}
|
|
2860
|
+
// A full-window flex box keeps every toast dead centre; rewriting it each
|
|
2861
|
+
// time also repairs a host left behind by an older build.
|
|
2862
|
+
host.style.cssText = 'position:fixed;top:33vh;left:0;right:0;display:flex;justify-content:center;pointer-events:none;z-index:2147483000';
|
|
2343
2863
|
host.textContent = '';
|
|
2344
2864
|
if (toast === null || toast === undefined) return;
|
|
2345
2865
|
const node = document.createElement('div');
|
|
@@ -2351,11 +2871,165 @@ const displayName = (value) => {
|
|
|
2351
2871
|
node.style.left = 'auto';
|
|
2352
2872
|
node.style.bottom = 'auto';
|
|
2353
2873
|
node.textContent = String(toast.text ?? '');
|
|
2874
|
+
if (toast.spinner === true) {
|
|
2875
|
+
const spinner = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
2876
|
+
spinner.setAttribute('class', 'dshe-toast-spinner');
|
|
2877
|
+
spinner.setAttribute('viewBox', '0 0 16 16');
|
|
2878
|
+
spinner.setAttribute('aria-hidden', 'true');
|
|
2879
|
+
const track = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
2880
|
+
track.setAttribute('cx', '8');
|
|
2881
|
+
track.setAttribute('cy', '8');
|
|
2882
|
+
track.setAttribute('r', '6');
|
|
2883
|
+
track.setAttribute('fill', 'none');
|
|
2884
|
+
track.setAttribute('stroke', 'rgba(255,255,255,.28)');
|
|
2885
|
+
track.setAttribute('stroke-width', '2');
|
|
2886
|
+
const arc = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
2887
|
+
arc.setAttribute('cx', '8');
|
|
2888
|
+
arc.setAttribute('cy', '8');
|
|
2889
|
+
arc.setAttribute('r', '6');
|
|
2890
|
+
arc.setAttribute('fill', 'none');
|
|
2891
|
+
arc.setAttribute('stroke', '#fff');
|
|
2892
|
+
arc.setAttribute('stroke-width', '2');
|
|
2893
|
+
arc.setAttribute('stroke-linecap', 'round');
|
|
2894
|
+
arc.setAttribute('stroke-dasharray', '26 12');
|
|
2895
|
+
spinner.appendChild(track);
|
|
2896
|
+
spinner.appendChild(arc);
|
|
2897
|
+
node.appendChild(spinner);
|
|
2898
|
+
}
|
|
2899
|
+
const release = armQuickClose(node, () => { node.remove(); });
|
|
2354
2900
|
host.appendChild(node);
|
|
2901
|
+
return () => {
|
|
2902
|
+
release();
|
|
2903
|
+
node.remove();
|
|
2904
|
+
};
|
|
2355
2905
|
}, [toast]);
|
|
2356
2906
|
return null;
|
|
2357
2907
|
}
|
|
2358
2908
|
|
|
2909
|
+
/**
|
|
2910
|
+
* The automatic-sync hint, parked on the composer status row.
|
|
2911
|
+
*
|
|
2912
|
+
* The dock entry itself renders nothing: it only marks where the row is. The
|
|
2913
|
+
* visible node lives on document.body and is aligned to the row's own measured
|
|
2914
|
+
* rectangle on every layout change, so it keeps that row's baseline and right
|
|
2915
|
+
* edge without hard-coded offsets.
|
|
2916
|
+
*/
|
|
2917
|
+
function SyncRunningBadge() {
|
|
2918
|
+
const state = useStore();
|
|
2919
|
+
// Manual runs own their centred toast, but the status line follows them too.
|
|
2920
|
+
const live = state.syncLive === true || state.sync.busy === true;
|
|
2921
|
+
const done = state.syncDone === true;
|
|
2922
|
+
const show = live || done;
|
|
2923
|
+
const markerRef = React.useRef(null);
|
|
2924
|
+
|
|
2925
|
+
React.useEffect(() => {
|
|
2926
|
+
if (!show) return undefined;
|
|
2927
|
+
const holder = markerRef.current;
|
|
2928
|
+
if (holder === null) return undefined;
|
|
2929
|
+
const ownRow = holder.parentElement;
|
|
2930
|
+
const dock = ownRow === null ? null : ownRow.parentElement;
|
|
2931
|
+
if (dock === null) return undefined;
|
|
2932
|
+
|
|
2933
|
+
const node = document.createElement('div');
|
|
2934
|
+
node.className = 'dshe-sync-inline';
|
|
2935
|
+
node.style.cssText = [
|
|
2936
|
+
'position:fixed',
|
|
2937
|
+
'z-index:2147483001',
|
|
2938
|
+
'pointer-events:none',
|
|
2939
|
+
'display:inline-flex',
|
|
2940
|
+
'align-items:center',
|
|
2941
|
+
'gap:6px',
|
|
2942
|
+
'font-size:12px',
|
|
2943
|
+
'line-height:16px',
|
|
2944
|
+
'color:var(--dsw-alias-label-secondary, currentColor)',
|
|
2945
|
+
'white-space:nowrap',
|
|
2946
|
+
].join(';');
|
|
2947
|
+
const label = document.createElement('span');
|
|
2948
|
+
label.textContent = runtime.t(live ? 'sync.running' : 'sync.done');
|
|
2949
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
2950
|
+
svg.setAttribute('class', live ? 'dshe-toast-spinner' : 'dshe-sync-done');
|
|
2951
|
+
svg.setAttribute('viewBox', '0 0 16 16');
|
|
2952
|
+
svg.setAttribute('width', '12');
|
|
2953
|
+
svg.setAttribute('height', '12');
|
|
2954
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
2955
|
+
svg.style.flex = 'none';
|
|
2956
|
+
if (live) {
|
|
2957
|
+
const track = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
2958
|
+
track.setAttribute('cx', '8');
|
|
2959
|
+
track.setAttribute('cy', '8');
|
|
2960
|
+
track.setAttribute('r', '6');
|
|
2961
|
+
track.setAttribute('fill', 'none');
|
|
2962
|
+
track.setAttribute('stroke', 'currentColor');
|
|
2963
|
+
track.setAttribute('stroke-opacity', '0.25');
|
|
2964
|
+
track.setAttribute('stroke-width', '2');
|
|
2965
|
+
const arc = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
2966
|
+
arc.setAttribute('cx', '8');
|
|
2967
|
+
arc.setAttribute('cy', '8');
|
|
2968
|
+
arc.setAttribute('r', '6');
|
|
2969
|
+
arc.setAttribute('fill', 'none');
|
|
2970
|
+
arc.setAttribute('stroke', 'currentColor');
|
|
2971
|
+
arc.setAttribute('stroke-width', '2');
|
|
2972
|
+
arc.setAttribute('stroke-linecap', 'round');
|
|
2973
|
+
arc.setAttribute('stroke-dasharray', '26 12');
|
|
2974
|
+
svg.appendChild(track);
|
|
2975
|
+
svg.appendChild(arc);
|
|
2976
|
+
} else {
|
|
2977
|
+
// Finished: a quiet tick instead of the turning ring.
|
|
2978
|
+
const tick = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
2979
|
+
tick.setAttribute('d', 'M3.5 8.5 L6.5 11.5 L12.5 4.5');
|
|
2980
|
+
tick.setAttribute('fill', 'none');
|
|
2981
|
+
tick.setAttribute('stroke', 'currentColor');
|
|
2982
|
+
tick.setAttribute('stroke-width', '1.8');
|
|
2983
|
+
tick.setAttribute('stroke-linecap', 'round');
|
|
2984
|
+
tick.setAttribute('stroke-linejoin', 'round');
|
|
2985
|
+
svg.appendChild(tick);
|
|
2986
|
+
}
|
|
2987
|
+
node.appendChild(label);
|
|
2988
|
+
node.appendChild(svg);
|
|
2989
|
+
document.body.appendChild(node);
|
|
2990
|
+
|
|
2991
|
+
// The last foreign row of the dock is the status line; our own row keeps
|
|
2992
|
+
// its normal place, so the shipped text never moves.
|
|
2993
|
+
const measure = () => {
|
|
2994
|
+
if (!node.isConnected) return;
|
|
2995
|
+
const rows = Array.from(dock.children).filter((child) => child !== ownRow);
|
|
2996
|
+
const anchor = rows.length > 0 ? rows[rows.length - 1] : dock;
|
|
2997
|
+
const rect = anchor.getBoundingClientRect();
|
|
2998
|
+
if (rect.width === 0 || rect.height === 0) return;
|
|
2999
|
+
const width = node.offsetWidth;
|
|
3000
|
+
const height = node.offsetHeight;
|
|
3001
|
+
const right = Math.max(12, window.innerWidth - 16);
|
|
3002
|
+
const left = Math.max(12, right - width);
|
|
3003
|
+
const top = Math.max(0, rect.top + (rect.height - height) / 2);
|
|
3004
|
+
node.style.left = Math.round(left) + 'px';
|
|
3005
|
+
node.style.top = Math.round(top) + 'px';
|
|
3006
|
+
};
|
|
3007
|
+
|
|
3008
|
+
measure();
|
|
3009
|
+
const frame = window.requestAnimationFrame(measure);
|
|
3010
|
+
// One late pass covers fonts and row heights that settle after the frame.
|
|
3011
|
+
const settle = window.setTimeout(measure, 300);
|
|
3012
|
+
window.addEventListener('resize', measure);
|
|
3013
|
+
// The row only moves when its container changes size, so observing the dock
|
|
3014
|
+
// is enough; no timer keeps running while the line just sits there.
|
|
3015
|
+
let observer = null;
|
|
3016
|
+
if (typeof ResizeObserver === 'function') {
|
|
3017
|
+
observer = new ResizeObserver(() => { measure(); });
|
|
3018
|
+
observer.observe(dock);
|
|
3019
|
+
}
|
|
3020
|
+
return () => {
|
|
3021
|
+
window.cancelAnimationFrame(frame);
|
|
3022
|
+
window.clearTimeout(settle);
|
|
3023
|
+
window.removeEventListener('resize', measure);
|
|
3024
|
+
if (observer !== null) observer.disconnect();
|
|
3025
|
+
node.remove();
|
|
3026
|
+
};
|
|
3027
|
+
}, [show, live]);
|
|
3028
|
+
|
|
3029
|
+
if (!show) return null;
|
|
3030
|
+
return h('span', { ref: markerRef, style: { display: 'none' } });
|
|
3031
|
+
}
|
|
3032
|
+
|
|
2359
3033
|
/** Environment check result, including the "export report" path. */
|
|
2360
3034
|
function EnvDialog() {
|
|
2361
3035
|
const state = useStore();
|
|
@@ -2534,62 +3208,255 @@ const displayName = (value) => {
|
|
|
2534
3208
|
console.warn('[dsh-enhanced] refreshing the workspace failed:', error);
|
|
2535
3209
|
}
|
|
2536
3210
|
};
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
3211
|
+
/**
|
|
3212
|
+
* Scroll to the start of one turn.
|
|
3213
|
+
*
|
|
3214
|
+
* Text-level precision inside a turn is not reliable: the same sentence can
|
|
3215
|
+
* appear in the prompt and in the reply, and markdown rendering shifts the
|
|
3216
|
+
* offsets. Landing on the turn boundary is predictable.
|
|
3217
|
+
*/
|
|
3218
|
+
/** Normalise for a loose containment check: markdown noise and spaces out. */
|
|
3219
|
+
const looseText = (value) => String(value ?? '').replace(/[\s`*_#>~\[\]()…⋯]/gu, '').toLowerCase();
|
|
2540
3220
|
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
3221
|
+
/** Keep only letters and digits: markdown markers differ between log and UI. */
|
|
3222
|
+
const bareText = (value) => String(value ?? '').replace(/[^\p{L}\p{N}]/gu, '').toLowerCase();
|
|
3223
|
+
|
|
3224
|
+
/** Wrap every occurrence of the query inside the given nodes, then undo it later. */
|
|
3225
|
+
/**
|
|
3226
|
+
* Highlight every occurrence inside the given nodes with the CSS Highlight API.
|
|
3227
|
+
*
|
|
3228
|
+
* Ranges leave the DOM untouched, so a later render cannot break the markup,
|
|
3229
|
+
* and the ten-second timer starts only after the target page is on screen.
|
|
3230
|
+
*/
|
|
3231
|
+
let releaseFlash = null;
|
|
3232
|
+
const highlightMatches = (nodes, query) => {
|
|
3233
|
+
if (releaseFlash !== null) {
|
|
3234
|
+
releaseFlash();
|
|
3235
|
+
releaseFlash = null;
|
|
2553
3236
|
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
3237
|
+
const needle = typeof query === 'string' ? query.trim() : '';
|
|
3238
|
+
if (needle === '' || nodes.length === 0) return;
|
|
3239
|
+
if (typeof CSS === 'undefined' || CSS.highlights === undefined || typeof Highlight === 'undefined') return;
|
|
3240
|
+
const lowerNeedle = needle.toLowerCase();
|
|
3241
|
+
const ranges = [];
|
|
3242
|
+
for (const node of nodes.slice(0, 8)) {
|
|
3243
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, {
|
|
3244
|
+
acceptNode: (textNode) => (textNode.nodeValue ?? '').toLowerCase().includes(lowerNeedle)
|
|
3245
|
+
? NodeFilter.FILTER_ACCEPT
|
|
3246
|
+
: NodeFilter.FILTER_SKIP,
|
|
3247
|
+
});
|
|
3248
|
+
while (walker.nextNode() !== null) {
|
|
3249
|
+
const textNode = walker.currentNode;
|
|
3250
|
+
const value = textNode.nodeValue ?? '';
|
|
3251
|
+
const lower = value.toLowerCase();
|
|
3252
|
+
let from = 0;
|
|
3253
|
+
let at = lower.indexOf(lowerNeedle);
|
|
3254
|
+
while (at >= 0) {
|
|
3255
|
+
const range = document.createRange();
|
|
3256
|
+
range.setStart(textNode, at);
|
|
3257
|
+
range.setEnd(textNode, at + needle.length);
|
|
3258
|
+
ranges.push(range);
|
|
3259
|
+
from = at + needle.length;
|
|
3260
|
+
at = lower.indexOf(lowerNeedle, from);
|
|
2574
3261
|
}
|
|
2575
3262
|
}
|
|
2576
|
-
|
|
2577
|
-
|
|
3263
|
+
}
|
|
3264
|
+
if (ranges.length === 0) return;
|
|
3265
|
+
CSS.highlights.set('dshe-flash', new Highlight(...ranges));
|
|
3266
|
+
const timer = window.setTimeout(() => {
|
|
3267
|
+
CSS.highlights.delete('dshe-flash');
|
|
3268
|
+
releaseFlash = null;
|
|
3269
|
+
}, 10_000);
|
|
3270
|
+
releaseFlash = () => {
|
|
3271
|
+
window.clearTimeout(timer);
|
|
3272
|
+
CSS.highlights.delete('dshe-flash');
|
|
2578
3273
|
};
|
|
2579
|
-
window.setTimeout(tick, 60);
|
|
2580
3274
|
};
|
|
2581
3275
|
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
3276
|
+
|
|
3277
|
+
/**
|
|
3278
|
+
* Scroll to the turn a hit belongs to and flash the matched text for ten seconds.
|
|
3279
|
+
*
|
|
3280
|
+
* The event seq keys the rendered node ("13:input-message…"), so that is the
|
|
3281
|
+
* primary anchor. Assistant nodes are keyed by turn instead, and the stored
|
|
3282
|
+
* turn can be off by one across the host/UI numbering, so neighbouring turns
|
|
3283
|
+
* are tried and the one whose own text contains the hit wins.
|
|
3284
|
+
*/
|
|
3285
|
+
/**
|
|
3286
|
+
* Fixed-position banner for jump feedback.
|
|
3287
|
+
*
|
|
3288
|
+
* It does not depend on React or the toast store and always lands at a
|
|
3289
|
+
* constant place in the window, so nothing can push it off-screen.
|
|
3290
|
+
*/
|
|
3291
|
+
const showJumpNotice = (text, ms) => {
|
|
3292
|
+
try {
|
|
3293
|
+
const existing = document.getElementById('dshe-jump-notice');
|
|
3294
|
+
if (existing !== null) existing.remove();
|
|
3295
|
+
const node = document.createElement('div');
|
|
3296
|
+
node.id = 'dshe-jump-notice';
|
|
3297
|
+
node.textContent = String(text ?? '');
|
|
3298
|
+
node.style.cssText = [
|
|
3299
|
+
'position:fixed',
|
|
3300
|
+
'z-index:2147483002',
|
|
3301
|
+
'top:33vh',
|
|
3302
|
+
'left:50%',
|
|
3303
|
+
'transform:translateX(-50%)',
|
|
3304
|
+
'pointer-events:auto',
|
|
3305
|
+
'background:rgba(24,26,30,.96)',
|
|
3306
|
+
'color:#fff',
|
|
3307
|
+
'border:1px solid rgba(255,255,255,.18)',
|
|
3308
|
+
'border-radius:14px',
|
|
3309
|
+
'padding:16px 26px',
|
|
3310
|
+
'font-size:16px',
|
|
3311
|
+
'font-weight:500',
|
|
3312
|
+
'line-height:1.55',
|
|
3313
|
+
'box-shadow:0 24px 60px rgba(0,0,0,.38)',
|
|
3314
|
+
'max-width:70vw',
|
|
3315
|
+
'text-align:center',
|
|
3316
|
+
'cursor:pointer',
|
|
3317
|
+
'user-select:none',
|
|
3318
|
+
].join(';');
|
|
3319
|
+
let release = () => {};
|
|
3320
|
+
const closeNotice = () => {
|
|
3321
|
+
release();
|
|
3322
|
+
node.remove();
|
|
3323
|
+
};
|
|
3324
|
+
release = armQuickClose(node, closeNotice);
|
|
3325
|
+
document.body.appendChild(node);
|
|
3326
|
+
window.setTimeout(closeNotice, typeof ms === 'number' ? ms : 5000);
|
|
3327
|
+
} catch (error) {
|
|
3328
|
+
console.warn('[dsh-enhanced] notice failed:', error);
|
|
3329
|
+
}
|
|
3330
|
+
};
|
|
3331
|
+
|
|
3332
|
+
/**
|
|
3333
|
+
* Locate one hit inside the mounted transcript.
|
|
3334
|
+
*
|
|
3335
|
+
* Only rendered rows can be found: a hit that lives in older history is
|
|
3336
|
+
* reported instead of being searched for where it cannot exist.
|
|
3337
|
+
*/
|
|
3338
|
+
runtime.jumpToAnchor = (options) => {
|
|
3339
|
+
const query = typeof options?.query === 'string' ? options.query : '';
|
|
3340
|
+
const previewText = typeof options?.preview === 'string' ? options.preview : '';
|
|
3341
|
+
const previewHit = Number.isInteger(options?.previewHit) ? options.previewHit : -1;
|
|
3342
|
+
const probe = bareText(options?.snippet ?? '').slice(0, 40);
|
|
3343
|
+
const anchorText = previewText !== '' && previewHit >= 0
|
|
3344
|
+
? bareText(previewText.slice(Math.max(0, previewHit - 60), previewHit + 60))
|
|
3345
|
+
: '';
|
|
3346
|
+
const kinds = options?.role === 'user'
|
|
3347
|
+
? ['user', 'steering']
|
|
3348
|
+
: (options?.role === 'assistant'
|
|
3349
|
+
? ['assistant-step', 'turn-tail']
|
|
3350
|
+
: (options?.role === 'tool' ? ['tool-call'] : null));
|
|
3351
|
+
|
|
3352
|
+
let settled = false;
|
|
3353
|
+
let tries = 0;
|
|
3354
|
+
|
|
3355
|
+
const finish = (row) => {
|
|
3356
|
+
settled = true;
|
|
3357
|
+
scrollToKeyword(row, query);
|
|
3358
|
+
highlightMatches([row], query);
|
|
3359
|
+
showJumpNotice('已定位到匹配位置', 2000);
|
|
3360
|
+
};
|
|
3361
|
+
|
|
3362
|
+
/** Scroll the transcript so one occurrence of the keyword is centred. */
|
|
3363
|
+
const scrollToKeyword = (row, queryText) => {
|
|
3364
|
+
const needle = String(queryText ?? '').trim().toLowerCase();
|
|
3365
|
+
if (needle === '') {
|
|
3366
|
+
row.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
let scroller = row.parentElement;
|
|
3370
|
+
while (scroller !== null && scroller !== document.body) {
|
|
3371
|
+
const style = window.getComputedStyle(scroller);
|
|
3372
|
+
if ((style.overflowY === 'auto' || style.overflowY === 'scroll') && scroller.scrollHeight > scroller.clientHeight) break;
|
|
3373
|
+
scroller = scroller.parentElement;
|
|
3374
|
+
}
|
|
3375
|
+
const walker = document.createTreeWalker(row, NodeFilter.SHOW_TEXT, {
|
|
3376
|
+
acceptNode: (textNode) => (textNode.nodeValue ?? '').toLowerCase().includes(needle)
|
|
3377
|
+
? NodeFilter.FILTER_ACCEPT
|
|
3378
|
+
: NodeFilter.FILTER_SKIP,
|
|
3379
|
+
});
|
|
3380
|
+
while (walker.nextNode() !== null) {
|
|
3381
|
+
const textNode = walker.currentNode;
|
|
3382
|
+
const value = textNode.nodeValue ?? '';
|
|
3383
|
+
const at = value.toLowerCase().indexOf(needle);
|
|
3384
|
+
if (at < 0) continue;
|
|
3385
|
+
if (scroller === null) break;
|
|
3386
|
+
const range = document.createRange();
|
|
3387
|
+
range.setStart(textNode, at);
|
|
3388
|
+
range.setEnd(textNode, at + needle.length);
|
|
3389
|
+
const rect = range.getBoundingClientRect();
|
|
3390
|
+
const box = scroller.getBoundingClientRect();
|
|
3391
|
+
if (rect.height > 0) {
|
|
3392
|
+
scroller.scrollTop += rect.top - box.top - box.height / 2 + rect.height / 2;
|
|
3393
|
+
return;
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
row.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
3397
|
+
};
|
|
3398
|
+
|
|
3399
|
+
/** Row that carries most of the excerpt, or null. */
|
|
3400
|
+
const pickRow = (rows) => {
|
|
3401
|
+
const chunks = anchorText === ''
|
|
3402
|
+
? []
|
|
3403
|
+
: (() => {
|
|
3404
|
+
const size = Math.max(10, Math.floor(anchorText.length / 3));
|
|
3405
|
+
const parts = [];
|
|
3406
|
+
for (let i = 0; i + size <= anchorText.length; i += size) parts.push(anchorText.slice(i, i + size));
|
|
3407
|
+
return parts;
|
|
3408
|
+
})();
|
|
3409
|
+
const needed = Math.max(2, Math.ceil(chunks.length * 0.6));
|
|
3410
|
+
for (const row of rows) {
|
|
3411
|
+
const text = bareText(row.textContent);
|
|
3412
|
+
if (query !== '' && !text.includes(bareText(query))) continue;
|
|
3413
|
+
if (chunks.length > 0 && chunks.filter((part) => text.includes(part)).length >= needed) return row;
|
|
3414
|
+
if (probe.length >= 24 && text.includes(probe)) return row;
|
|
3415
|
+
}
|
|
3416
|
+
return null;
|
|
3417
|
+
};
|
|
3418
|
+
|
|
3419
|
+
const attempt = () => {
|
|
3420
|
+
if (settled === true) return;
|
|
3421
|
+
tries += 1;
|
|
2585
3422
|
try {
|
|
2586
|
-
const
|
|
2587
|
-
|
|
3423
|
+
const flows = Array.from(document.querySelectorAll('[data-chat-flow]'))
|
|
3424
|
+
.filter((node) => node.querySelector('[data-chat-flow-key]') !== null);
|
|
3425
|
+
for (const flow of flows) {
|
|
3426
|
+
let rows = Array.from(flow.querySelectorAll('[data-chat-flow-key]'));
|
|
3427
|
+
if (kinds !== null) {
|
|
3428
|
+
const byKind = rows.filter((row) => kinds.includes(row.getAttribute('data-chat-flow-kind') ?? ''));
|
|
3429
|
+
if (byKind.length > 0) rows = byKind;
|
|
3430
|
+
}
|
|
3431
|
+
const hit = pickRow(rows);
|
|
3432
|
+
if (hit !== null) {
|
|
3433
|
+
finish(hit);
|
|
3434
|
+
return;
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
2588
3437
|
} catch (error) {
|
|
2589
|
-
console.warn('[dsh-enhanced]
|
|
3438
|
+
console.warn('[dsh-enhanced] locate failed:', error);
|
|
2590
3439
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
3440
|
+
if (tries >= 8) {
|
|
3441
|
+
settled = true;
|
|
3442
|
+
showJumpNotice('该命中在更早的会话中,已打开会话但未自动定位', 5000);
|
|
3443
|
+
return;
|
|
3444
|
+
}
|
|
3445
|
+
window.setTimeout(attempt, 350);
|
|
3446
|
+
};
|
|
3447
|
+
attempt();
|
|
3448
|
+
};
|
|
3449
|
+
|
|
3450
|
+
runtime.focusMatch = (sessionId, match, query) => {
|
|
3451
|
+
// The hit already names its session, and only mounted rows can be located,
|
|
3452
|
+
// so the click navigates by text alone.
|
|
3453
|
+
runtime.jumpToAnchor({
|
|
3454
|
+
role: match?.role,
|
|
3455
|
+
snippet: match?.snippet,
|
|
3456
|
+
preview: match?.preview,
|
|
3457
|
+
previewHit: match?.previewHit,
|
|
3458
|
+
query,
|
|
3459
|
+
});
|
|
2593
3460
|
};
|
|
2594
3461
|
runtime.rpc = async (action, payload, signal) => {
|
|
2595
3462
|
const url = new URL('api/dsh-enhanced/rpc', document.baseURI);
|
|
@@ -2621,6 +3488,20 @@ const displayName = (value) => {
|
|
|
2621
3488
|
return () => tag.remove();
|
|
2622
3489
|
}, 'dsh-enhanced: styles');
|
|
2623
3490
|
|
|
3491
|
+
// Ctrl+Alt+Shift+T starts one immediate sync while this window has focus.
|
|
3492
|
+
ctx.effect(() => {
|
|
3493
|
+
const onKeyDown = (event) => {
|
|
3494
|
+
if (!event.ctrlKey || !event.altKey || !event.shiftKey) return;
|
|
3495
|
+
if (event.code !== 'KeyT' && (event.key ?? '').toLowerCase() !== 't') return;
|
|
3496
|
+
if (event.repeat) return;
|
|
3497
|
+
event.preventDefault();
|
|
3498
|
+
event.stopPropagation();
|
|
3499
|
+
void runtime.store.runSyncNow();
|
|
3500
|
+
};
|
|
3501
|
+
window.addEventListener('keydown', onKeyDown, true);
|
|
3502
|
+
return () => window.removeEventListener('keydown', onKeyDown, true);
|
|
3503
|
+
}, 'dsh-enhanced: sync hotkey');
|
|
3504
|
+
|
|
2624
3505
|
ctx.effect(() => {
|
|
2625
3506
|
const onKeyDown = (event) => {
|
|
2626
3507
|
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey) return;
|
|
@@ -2647,11 +3528,13 @@ const displayName = (value) => {
|
|
|
2647
3528
|
return () => window.removeEventListener('keydown', onKeyDown, true);
|
|
2648
3529
|
}, 'dsh-enhanced: restart shortcut');
|
|
2649
3530
|
|
|
3531
|
+
|
|
3532
|
+
|
|
2650
3533
|
ctx.effect(() => {
|
|
2651
3534
|
// Prefetch distance from the top of the loaded history, in pixels.
|
|
2652
|
-
const PREFETCH_PX =
|
|
3535
|
+
const PREFETCH_PX = 600;
|
|
2653
3536
|
// Do not stack requests closer than this, so one flick loads one page.
|
|
2654
|
-
const MIN_GAP_MS =
|
|
3537
|
+
const MIN_GAP_MS = 600;
|
|
2655
3538
|
let cachedScroller = null;
|
|
2656
3539
|
let loading = null;
|
|
2657
3540
|
let scheduled = null;
|
|
@@ -2682,12 +3565,13 @@ const displayName = (value) => {
|
|
|
2682
3565
|
};
|
|
2683
3566
|
|
|
2684
3567
|
const findOlderButton = () => {
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
3568
|
+
const candidates = Array.from(document.querySelectorAll('button, [role="button"], a, [data-load-older]'));
|
|
3569
|
+
for (const node of candidates) {
|
|
3570
|
+
const label = (node.textContent ?? '').trim();
|
|
3571
|
+
if (label === 'Load earlier' || label.startsWith('加载更早')) return node;
|
|
3572
|
+
if (node.hasAttribute('data-load-older')) return node;
|
|
3573
|
+
const className = [String(node.className ?? ''), String(node.parentElement?.className ?? '')].join(' ');
|
|
3574
|
+
if (/(?:^|[_\s-])older(?:[_\s-]|$)/iu.test(className)) return node;
|
|
2691
3575
|
}
|
|
2692
3576
|
return null;
|
|
2693
3577
|
};
|
|
@@ -2736,7 +3620,7 @@ const displayName = (value) => {
|
|
|
2736
3620
|
if (grown > 0 && !moved) scroller.scrollTop = before.top + grown;
|
|
2737
3621
|
loading = null;
|
|
2738
3622
|
// Chain straight into the next page while the reader is still near the top.
|
|
2739
|
-
schedule(
|
|
3623
|
+
schedule(400);
|
|
2740
3624
|
};
|
|
2741
3625
|
window.setTimeout(settle, 100);
|
|
2742
3626
|
};
|
|
@@ -2841,6 +3725,14 @@ const displayName = (value) => {
|
|
|
2841
3725
|
locale: NS,
|
|
2842
3726
|
}, SessionMoveRow));
|
|
2843
3727
|
|
|
3728
|
+
// Session id inside the row's hover card, between time and status.
|
|
3729
|
+
ctx.slots.inject('sidebar.session.row.hover', () => ctx.slots.register({
|
|
3730
|
+
name: 'sidebar.session.row.hover',
|
|
3731
|
+
id: 'dsh-enhanced.session-id',
|
|
3732
|
+
order: 20,
|
|
3733
|
+
locale: NS,
|
|
3734
|
+
}, SessionIdRow));
|
|
3735
|
+
|
|
2844
3736
|
|
|
2845
3737
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
2846
3738
|
name: 'shell.overlay',
|
|
@@ -2856,6 +3748,13 @@ const displayName = (value) => {
|
|
|
2856
3748
|
locale: NS,
|
|
2857
3749
|
}, OverlayStack));
|
|
2858
3750
|
|
|
3751
|
+
ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
|
|
3752
|
+
name: 'conversation.composer.dock',
|
|
3753
|
+
id: 'dsh-enhanced.sync-running',
|
|
3754
|
+
order: 40,
|
|
3755
|
+
locale: NS,
|
|
3756
|
+
}, SyncRunningBadge));
|
|
3757
|
+
|
|
2859
3758
|
ctx.slots.inject('conversation.input.left', () => ctx.slots.register({
|
|
2860
3759
|
name: 'conversation.input.left',
|
|
2861
3760
|
id: 'dsh-enhanced.composer-bridge',
|