@xsok/dsh-enhanced 0.2.2-7 → 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 +16 -0
- package/README.md +1 -15
- package/client.js +510 -15
- package/host/engine/index.js +8 -0
- package/host/engine/projcache.js +15 -1
- package/host/engine/sessions.js +20 -3
- package/host/schedule.js +24 -9
- package/host/sync.js +6 -0
- package/index.js +62 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
版本号前三位对应主程序版本,最后一段是插件自身的发布序号。
|
|
4
4
|
|
|
5
|
+
## Preview version
|
|
6
|
+
|
|
7
|
+
### 新增
|
|
8
|
+
|
|
9
|
+
- 新增快捷键 Ctrl+Alt+Shift+T,窗口激活时立即执行一次同步。
|
|
10
|
+
- 右下角状态行显示会话同步状态:同步中提示进度,同步完成后提示“会话同步完成”,发送消息后清除。
|
|
11
|
+
- 立即同步时显示“正在同步”提示与旋转动画。
|
|
12
|
+
- 侧栏会话悬浮卡新增会话 ID 行,并按名称、ID、路径拆分为独立复制目标。
|
|
13
|
+
- **同步空白会话守卫**:空会话不再被同步上传,缓存过期的会话自动修正,避免个别对话因此在特定设备上不显示。
|
|
14
|
+
|
|
15
|
+
### 优化
|
|
16
|
+
|
|
17
|
+
- 插件全部提示统一为深色卡片,显示在偏上居中的位置;提示弹窗支持双击关闭(窗口任意位置)。
|
|
18
|
+
- 自动重启前显示 3 秒倒计时,并注明触发事项。
|
|
19
|
+
- 启动同步若触发重启,同样显示倒计时。
|
|
20
|
+
|
|
5
21
|
## 0.2.2-7
|
|
6
22
|
|
|
7
23
|
### 改进
|
package/README.md
CHANGED
|
@@ -145,20 +145,6 @@
|
|
|
145
145
|
|
|
146
146
|
---
|
|
147
147
|
|
|
148
|
-
## 更新记录
|
|
149
|
-
|
|
150
|
-
完整记录见 [CHANGELOG.md](./CHANGELOG.md)。
|
|
151
|
-
|
|
152
|
-
### 0.2.2-4
|
|
153
|
-
|
|
154
|
-
- 自动加载更早消息改为提前预取:距顶部 800 像素即开始加载,加载期间不打断滚动,插入后保持视口位置不动。
|
|
155
|
-
- 会话同步在下载到新会话后自动重启,仅在无任务运行且超过同步冷却时间时执行。
|
|
156
|
-
- 修复内容寻址附件被反复下载、云端清单缺哈希。
|
|
157
|
-
|
|
158
|
-
### 0.2.2-3
|
|
159
|
-
|
|
160
|
-
首个公开版本:会话同步(WebDAV / 本地目录)、会话删除与找回、跨工作区移动、`Ctrl+F` 全库搜索、自动加载更早消息、环境检测与重启。
|
|
161
|
-
|
|
162
148
|
## 许可证
|
|
163
149
|
|
|
164
|
-
[MIT](./LICENSE)
|
|
150
|
+
[MIT](./LICENSE)
|
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': '将该会话整体移入目标工作区:会话本身不变,只是工作目录改到目标目录,之后的工具调用会在那里执行。分组变化需要重启应用后完全生效。',
|
|
@@ -574,9 +596,14 @@ window.__ModuleLoader__.load({
|
|
|
574
596
|
.dshe-preset-chip{display:inline-flex;align-items:center;gap:4px}
|
|
575
597
|
.dshe-action-active{background:var(--dsw-alias-brand-primary,#3b6ef5);color:#fff;border-color:transparent}
|
|
576
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)}
|
|
577
|
-
.dshe-toast{position:
|
|
578
|
-
|
|
579
|
-
|
|
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)}}
|
|
580
607
|
`;
|
|
581
608
|
|
|
582
609
|
// ── store ────────────────────────────────────────────────────────────────
|
|
@@ -595,6 +622,9 @@ window.__ModuleLoader__.load({
|
|
|
595
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 },
|
|
596
623
|
overwrite: { open: false, direction: 'cloud', busy: false, preview: null, error: null },
|
|
597
624
|
restartConfirm: false,
|
|
625
|
+
syncLive: false,
|
|
626
|
+
syncDone: false,
|
|
627
|
+
restartCountdown: null,
|
|
598
628
|
presetEdit: null,
|
|
599
629
|
presetReplace: null,
|
|
600
630
|
pauseOpen: false,
|
|
@@ -617,6 +647,8 @@ window.__ModuleLoader__.load({
|
|
|
617
647
|
&& trim(item.root) === trim(settings.webdavRoot);
|
|
618
648
|
}
|
|
619
649
|
|
|
650
|
+
let restartCountdownTimer = null;
|
|
651
|
+
|
|
620
652
|
const store = {
|
|
621
653
|
get: () => state,
|
|
622
654
|
subscribe(listener) {
|
|
@@ -638,9 +670,26 @@ window.__ModuleLoader__.load({
|
|
|
638
670
|
},
|
|
639
671
|
toast(kind, text) {
|
|
640
672
|
if (toastTimer !== null) clearTimeout(toastTimer);
|
|
673
|
+
toastTimer = null;
|
|
641
674
|
store.set({ toast: { kind, text, id: Date.now() } });
|
|
642
675
|
toastTimer = setTimeout(() => store.set({ toast: null }), kind === 'error' ? 5000 : 3000);
|
|
643
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 });
|
|
692
|
+
},
|
|
644
693
|
async init() {
|
|
645
694
|
try {
|
|
646
695
|
const data = await runtime.rpc('state');
|
|
@@ -653,6 +702,32 @@ window.__ModuleLoader__.load({
|
|
|
653
702
|
store.set({ ready: true });
|
|
654
703
|
console.warn('[dsh-enhanced] initial state failed:', error);
|
|
655
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
|
+
}
|
|
656
731
|
},
|
|
657
732
|
async refreshCount() {
|
|
658
733
|
try {
|
|
@@ -894,7 +969,7 @@ window.__ModuleLoader__.load({
|
|
|
894
969
|
const warning = typeof data?.warning === 'string' && data.warning !== '' ? data.warning : null;
|
|
895
970
|
store.toast(warning === null ? 'success' : 'info', warning ?? runtime.t('move.done', { title: target?.title ?? '' }));
|
|
896
971
|
await store.refreshCount();
|
|
897
|
-
if (data?.needsRestart === true) store.
|
|
972
|
+
if (data?.needsRestart === true) store.restartSoon('restart.reason.move');
|
|
898
973
|
} catch (error) {
|
|
899
974
|
store.set({ move: { ...state.move, busy: false, error: String(error?.message ?? error) } });
|
|
900
975
|
}
|
|
@@ -921,6 +996,41 @@ window.__ModuleLoader__.load({
|
|
|
921
996
|
store.set({ sync: { ...state.sync, loading: false, error: String(error?.message ?? error) } });
|
|
922
997
|
}
|
|
923
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
|
+
},
|
|
924
1034
|
async probeSync() {
|
|
925
1035
|
if (state.sync.busy) return;
|
|
926
1036
|
store.set({ sync: { ...state.sync, busy: true, error: null } });
|
|
@@ -935,10 +1045,15 @@ window.__ModuleLoader__.load({
|
|
|
935
1045
|
},
|
|
936
1046
|
async runSyncNow() {
|
|
937
1047
|
if (state.sync.busy) return;
|
|
938
|
-
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'));
|
|
939
1050
|
try {
|
|
940
1051
|
const data = await runtime.rpc('sync.run');
|
|
941
|
-
store.
|
|
1052
|
+
store.clearToast();
|
|
1053
|
+
store.set({
|
|
1054
|
+
sync: { ...state.sync, busy: false, state: data, error: null },
|
|
1055
|
+
syncDone: data?.ok !== false,
|
|
1056
|
+
});
|
|
942
1057
|
store.toast(
|
|
943
1058
|
data?.ok === false ? 'error' : 'success',
|
|
944
1059
|
data?.ok === false
|
|
@@ -948,15 +1063,37 @@ window.__ModuleLoader__.load({
|
|
|
948
1063
|
await store.loadSync();
|
|
949
1064
|
const pulled = Number(data?.summary?.sessions?.pulled) || Number(data?.summary?.sessions?.created) || 0;
|
|
950
1065
|
if (pulled > 0) {
|
|
951
|
-
store.
|
|
952
|
-
store.restartApp();
|
|
1066
|
+
store.restartSoon('restart.reason.sync');
|
|
953
1067
|
}
|
|
954
1068
|
} catch (error) {
|
|
1069
|
+
store.clearToast();
|
|
955
1070
|
store.set({ sync: { ...state.sync, busy: false, error: String(error?.message ?? error) } });
|
|
956
1071
|
store.toast('error', String(error?.message ?? error));
|
|
957
1072
|
await store.loadSync();
|
|
958
1073
|
}
|
|
959
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
|
+
},
|
|
960
1097
|
/** Restart the app so a structural change becomes visible. */
|
|
961
1098
|
restartApp() {
|
|
962
1099
|
window.setTimeout(() => {
|
|
@@ -1119,7 +1256,7 @@ window.__ModuleLoader__.load({
|
|
|
1119
1256
|
: runtime.t('overwrite.localDone', { n: String(result?.copied ?? 0) }));
|
|
1120
1257
|
await store.loadSync();
|
|
1121
1258
|
// Replacing this machine wholesale only takes effect after a restart.
|
|
1122
|
-
if (direction === 'local') store.
|
|
1259
|
+
if (direction === 'local') store.restartSoon('restart.reason.restore');
|
|
1123
1260
|
} catch (error) {
|
|
1124
1261
|
store.set({ overwrite: { ...state.overwrite, busy: false, error: String(error?.message ?? error) } });
|
|
1125
1262
|
}
|
|
@@ -1420,6 +1557,154 @@ function highlightFocus(text, query, focusIndex) {
|
|
|
1420
1557
|
}, running ? runtime.t('delete.running') : runtime.t('delete.label'));
|
|
1421
1558
|
}
|
|
1422
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
|
+
|
|
1423
1708
|
// ── delete confirmation ──────────────────────────────────────────────────
|
|
1424
1709
|
|
|
1425
1710
|
const displayName = (value) => {
|
|
@@ -1762,6 +2047,7 @@ const displayName = (value) => {
|
|
|
1762
2047
|
const markRect = mark.getBoundingClientRect();
|
|
1763
2048
|
node.scrollTop += markRect.top - box.top - node.clientHeight / 2 + markRect.height / 2;
|
|
1764
2049
|
}
|
|
2050
|
+
return () => { node.remove(); };
|
|
1765
2051
|
}, [preview, search.query]);
|
|
1766
2052
|
|
|
1767
2053
|
const previewRef = React.useRef(null);
|
|
@@ -1769,6 +2055,7 @@ const displayName = (value) => {
|
|
|
1769
2055
|
const previewGate = React.useRef(true);
|
|
1770
2056
|
const previewHover = React.useRef(null);
|
|
1771
2057
|
const previewPointer = React.useRef({ x: 0, y: 0 });
|
|
2058
|
+
const previewEpoch = React.useRef(0);
|
|
1772
2059
|
|
|
1773
2060
|
React.useEffect(() => {
|
|
1774
2061
|
// Typing hides the preview; it may only reappear after the pointer moves.
|
|
@@ -1836,6 +2123,11 @@ const displayName = (value) => {
|
|
|
1836
2123
|
}, [expanded]);
|
|
1837
2124
|
|
|
1838
2125
|
React.useEffect(() => {
|
|
2126
|
+
previewEpoch.current += 1;
|
|
2127
|
+
if (previewHover.current !== null) {
|
|
2128
|
+
window.clearTimeout(previewHover.current);
|
|
2129
|
+
previewHover.current = null;
|
|
2130
|
+
}
|
|
1839
2131
|
setPreview(null);
|
|
1840
2132
|
}, [search.open, search.groups]);
|
|
1841
2133
|
|
|
@@ -1941,12 +2233,15 @@ const displayName = (value) => {
|
|
|
1941
2233
|
if (previewGate.current === true) return;
|
|
1942
2234
|
const row = event.currentTarget;
|
|
1943
2235
|
if (event.clientX !== undefined) previewPointer.current = { x: event.clientX, y: event.clientY };
|
|
2236
|
+
const epoch = previewEpoch.current;
|
|
1944
2237
|
previewHover.current = window.setTimeout(() => {
|
|
2238
|
+
if (previewEpoch.current !== epoch) return;
|
|
1945
2239
|
previewHover.current = null;
|
|
1946
2240
|
const rect = row.getBoundingClientRect();
|
|
1947
2241
|
const dialog = row.closest('.dshe-search');
|
|
1948
2242
|
const box = dialog === null ? null : dialog.getBoundingClientRect();
|
|
1949
|
-
const
|
|
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)));
|
|
1950
2245
|
const pointer = previewPointer.current;
|
|
1951
2246
|
const left = Math.max(12, Math.min(Math.round(pointer.x + 16), window.innerWidth - width - 12));
|
|
1952
2247
|
const spaceBelow = Math.round(window.innerHeight - rect.bottom - 12);
|
|
@@ -1974,7 +2269,16 @@ const displayName = (value) => {
|
|
|
1974
2269
|
},
|
|
1975
2270
|
key: `${group.sessionId}-${String(match.seq ?? 'title')}-${String(index)}`,
|
|
1976
2271
|
'data-active': index === active ? 'true' : 'false',
|
|
1977
|
-
onClick: () =>
|
|
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
|
+
},
|
|
1978
2282
|
},
|
|
1979
2283
|
h('span', { className: 'dshe-match-time', 'data-tier': String(timeTier(formatMatchTime(match.time))) }, formatMatchTime(match.time)),
|
|
1980
2284
|
h('span', { className: 'dshe-role' }, runtime.t(`role.${match.role ?? 'body'}`)),
|
|
@@ -2551,9 +2855,11 @@ const displayName = (value) => {
|
|
|
2551
2855
|
if (host === null) {
|
|
2552
2856
|
host = document.createElement('div');
|
|
2553
2857
|
host.id = 'dshe-toast-host';
|
|
2554
|
-
host.style.cssText = 'position:fixed;left:0;right:0;bottom:28px;display:flex;justify-content:center;pointer-events:none;z-index:2147483000';
|
|
2555
2858
|
document.body.appendChild(host);
|
|
2556
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';
|
|
2557
2863
|
host.textContent = '';
|
|
2558
2864
|
if (toast === null || toast === undefined) return;
|
|
2559
2865
|
const node = document.createElement('div');
|
|
@@ -2565,11 +2871,165 @@ const displayName = (value) => {
|
|
|
2565
2871
|
node.style.left = 'auto';
|
|
2566
2872
|
node.style.bottom = 'auto';
|
|
2567
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(); });
|
|
2568
2900
|
host.appendChild(node);
|
|
2901
|
+
return () => {
|
|
2902
|
+
release();
|
|
2903
|
+
node.remove();
|
|
2904
|
+
};
|
|
2569
2905
|
}, [toast]);
|
|
2570
2906
|
return null;
|
|
2571
2907
|
}
|
|
2572
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
|
+
|
|
2573
3033
|
/** Environment check result, including the "export report" path. */
|
|
2574
3034
|
function EnvDialog() {
|
|
2575
3035
|
const state = useStore();
|
|
@@ -2838,7 +3298,7 @@ const displayName = (value) => {
|
|
|
2838
3298
|
node.style.cssText = [
|
|
2839
3299
|
'position:fixed',
|
|
2840
3300
|
'z-index:2147483002',
|
|
2841
|
-
'top:
|
|
3301
|
+
'top:33vh',
|
|
2842
3302
|
'left:50%',
|
|
2843
3303
|
'transform:translateX(-50%)',
|
|
2844
3304
|
'pointer-events:auto',
|
|
@@ -2854,10 +3314,16 @@ const displayName = (value) => {
|
|
|
2854
3314
|
'max-width:70vw',
|
|
2855
3315
|
'text-align:center',
|
|
2856
3316
|
'cursor:pointer',
|
|
3317
|
+
'user-select:none',
|
|
2857
3318
|
].join(';');
|
|
2858
|
-
|
|
3319
|
+
let release = () => {};
|
|
3320
|
+
const closeNotice = () => {
|
|
3321
|
+
release();
|
|
3322
|
+
node.remove();
|
|
3323
|
+
};
|
|
3324
|
+
release = armQuickClose(node, closeNotice);
|
|
2859
3325
|
document.body.appendChild(node);
|
|
2860
|
-
window.setTimeout(
|
|
3326
|
+
window.setTimeout(closeNotice, typeof ms === 'number' ? ms : 5000);
|
|
2861
3327
|
} catch (error) {
|
|
2862
3328
|
console.warn('[dsh-enhanced] notice failed:', error);
|
|
2863
3329
|
}
|
|
@@ -3022,6 +3488,20 @@ const displayName = (value) => {
|
|
|
3022
3488
|
return () => tag.remove();
|
|
3023
3489
|
}, 'dsh-enhanced: styles');
|
|
3024
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
|
+
|
|
3025
3505
|
ctx.effect(() => {
|
|
3026
3506
|
const onKeyDown = (event) => {
|
|
3027
3507
|
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey) return;
|
|
@@ -3245,6 +3725,14 @@ const displayName = (value) => {
|
|
|
3245
3725
|
locale: NS,
|
|
3246
3726
|
}, SessionMoveRow));
|
|
3247
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
|
+
|
|
3248
3736
|
|
|
3249
3737
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
3250
3738
|
name: 'shell.overlay',
|
|
@@ -3260,6 +3748,13 @@ const displayName = (value) => {
|
|
|
3260
3748
|
locale: NS,
|
|
3261
3749
|
}, OverlayStack));
|
|
3262
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
|
+
|
|
3263
3758
|
ctx.slots.inject('conversation.input.left', () => ctx.slots.register({
|
|
3264
3759
|
name: 'conversation.input.left',
|
|
3265
3760
|
id: 'dsh-enhanced.composer-bridge',
|
package/host/engine/index.js
CHANGED
|
@@ -164,6 +164,9 @@ async function runSyncJsInner(deps) {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
// A session that was created but never used carries a blank projection shard;
|
|
168
|
+
// uploading it hides the conversation on every machine that later pulls it.
|
|
169
|
+
// The session phase applies that guard while it already holds the scan.
|
|
167
170
|
sessions = await step('sessions', () => syncSessions({
|
|
168
171
|
localRoot: localSessions,
|
|
169
172
|
sharedRoot: sharedSessions,
|
|
@@ -171,6 +174,8 @@ async function runSyncJsInner(deps) {
|
|
|
171
174
|
machineId,
|
|
172
175
|
resolveCwd,
|
|
173
176
|
apply,
|
|
177
|
+
cacheDir: path.join(dshHome, 'storages', 'session_projcache', 'sessions'),
|
|
178
|
+
guardStateFile: path.join(dshHome, 'dsh-enhanced', 'blank-guard-state.json'),
|
|
174
179
|
journalFile: path.join(dshHome, 'dsh-enhanced', 'delete-journal.json'),
|
|
175
180
|
}));
|
|
176
181
|
|
|
@@ -250,6 +255,7 @@ async function runSyncJsInner(deps) {
|
|
|
250
255
|
machineId,
|
|
251
256
|
force: !apply,
|
|
252
257
|
apply,
|
|
258
|
+
skipIds: sessions.blankGuard?.skipIds ?? new Set(),
|
|
253
259
|
}));
|
|
254
260
|
|
|
255
261
|
pluginList = await step('plugins', () => (apply
|
|
@@ -292,6 +298,7 @@ async function runSyncJsInner(deps) {
|
|
|
292
298
|
prune: { quarantined: prune.quarantined, hardDeleted: prune.hardDeleted, sharedDeleted: prune.sharedDeleted, kept: prune.kept, throttled: prune.throttled, quarantinePurged: prune.quarantinePurged ?? 0 },
|
|
293
299
|
workspace: { local: Object.keys(workspace.local?.tables?.workspaces ?? {}).length, shared: Object.keys(workspace.shared?.tables?.workspaces ?? {}).length, skipped: workspace.skipped ?? null, error: workspace.error ?? null },
|
|
294
300
|
titleMerge: projcache,
|
|
301
|
+
blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: sessions.blankGuard?.repaired ?? 0 },
|
|
295
302
|
plugins: pluginList.count,
|
|
296
303
|
archive: { released: archive.released.length, archived: archive.archived.length, eventsPruned: prunedEvents.removed },
|
|
297
304
|
missing: { sessions: sessions.missing ?? 0, groups: missingGroups.length },
|
|
@@ -326,6 +333,7 @@ async function runSyncJsInner(deps) {
|
|
|
326
333
|
},
|
|
327
334
|
workspace: { local: Object.keys(workspace.local?.tables?.workspaces ?? {}).length, shared: Object.keys(workspace.shared?.tables?.workspaces ?? {}).length, skipped: workspace.skipped ?? null, error: workspace.error ?? null },
|
|
328
335
|
titleMerge: projcache,
|
|
336
|
+
blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: sessions.blankGuard?.repaired ?? 0 },
|
|
329
337
|
plugins: pluginList.count,
|
|
330
338
|
archive: { released: archive.released.length, archived: archive.archived.length, eventsPruned: prunedEvents.removed },
|
|
331
339
|
missing: { sessions: sessions.missing ?? 0, groups: missingGroups.length },
|
package/host/engine/projcache.js
CHANGED
|
@@ -83,7 +83,17 @@ async function indexShards(dir) {
|
|
|
83
83
|
* @returns counters for the run summary.
|
|
84
84
|
*/
|
|
85
85
|
export async function mergeProjcacheTitles(deps) {
|
|
86
|
-
const {
|
|
86
|
+
const {
|
|
87
|
+
localDir,
|
|
88
|
+
sharedDir,
|
|
89
|
+
stateDir,
|
|
90
|
+
machineId,
|
|
91
|
+
force = false,
|
|
92
|
+
apply = true,
|
|
93
|
+
// Sessions the blank-session guard keeps out of the share this run: their
|
|
94
|
+
// shard must not be mirrored either, or the empty state would still travel.
|
|
95
|
+
skipIds = new Set(),
|
|
96
|
+
} = deps;
|
|
87
97
|
const localIndex = await indexShards(localDir);
|
|
88
98
|
const sharedIndex = await indexShards(sharedDir);
|
|
89
99
|
if (localIndex.size === 0 && sharedIndex.size === 0) {
|
|
@@ -101,6 +111,10 @@ export async function mergeProjcacheTitles(deps) {
|
|
|
101
111
|
let untouched = 0;
|
|
102
112
|
|
|
103
113
|
for (const id of new Set([...localIndex.keys(), ...sharedIndex.keys()])) {
|
|
114
|
+
if (skipIds.has(id)) {
|
|
115
|
+
untouched += 1;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
104
118
|
const localEntry = localIndex.get(id);
|
|
105
119
|
const sharedEntry = sharedIndex.get(id);
|
|
106
120
|
const currentLocal = localEntry === undefined ? -1 : localEntry.mtime;
|
package/host/engine/sessions.js
CHANGED
|
@@ -9,6 +9,7 @@ import { promises as fsp } from 'node:fs';
|
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import { scanSessions, projectKey } from './scan.js';
|
|
12
|
+
import { buildBlankGuard } from './blank-guard.js';
|
|
12
13
|
import { lastContentSeq, readSessionFile, rewriteCwd, writeSessionFile } from './session.js';
|
|
13
14
|
import {
|
|
14
15
|
SESSION_LEDGER,
|
|
@@ -143,6 +144,8 @@ export async function syncSessions(deps) {
|
|
|
143
144
|
skipIds = new Set(),
|
|
144
145
|
apply = true,
|
|
145
146
|
journalFile = null,
|
|
147
|
+
cacheDir = null,
|
|
148
|
+
guardStateFile = null,
|
|
146
149
|
sharedTrashRoot = path.join(path.dirname(sharedRoot), 'trash'),
|
|
147
150
|
} = deps;
|
|
148
151
|
|
|
@@ -255,9 +258,23 @@ export async function syncSessions(deps) {
|
|
|
255
258
|
}
|
|
256
259
|
|
|
257
260
|
// 3. Push local sessions the share does not have (or has in an older state).
|
|
261
|
+
// A session that was created but never used carries a blank projection
|
|
262
|
+
// shard; letting it reach the share hides the conversation on every machine
|
|
263
|
+
// that later pulls it, so the guard keeps it (and its shard) out. The scan
|
|
264
|
+
// above is reused: no second walk of the sessions root.
|
|
265
|
+
let blankGuard = { skipIds: new Set(), skipped: 0, repaired: 0 };
|
|
266
|
+
if (cacheDir !== null) {
|
|
267
|
+
try {
|
|
268
|
+
blankGuard = await buildBlankGuard({ sessions: local, cacheDir, apply, stateFile: guardStateFile });
|
|
269
|
+
} catch {
|
|
270
|
+
blankGuard = { skipIds: new Set(), skipped: 0, repaired: 0 };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const guardedIds = new Set([...skipIds, ...blankGuard.skipIds]);
|
|
274
|
+
|
|
258
275
|
for (const [id, entry] of local) {
|
|
259
276
|
if (ledger.deleted[id] !== undefined) continue;
|
|
260
|
-
if (
|
|
277
|
+
if (guardedIds.has(id)) {
|
|
261
278
|
skipped += 1;
|
|
262
279
|
continue;
|
|
263
280
|
}
|
|
@@ -310,7 +327,7 @@ export async function syncSessions(deps) {
|
|
|
310
327
|
let missing = 0;
|
|
311
328
|
for (const [id, entry] of refreshedShare) {
|
|
312
329
|
if (ledger.deleted[id] !== undefined) continue;
|
|
313
|
-
if (
|
|
330
|
+
if (guardedIds.has(id)) continue;
|
|
314
331
|
const localEntry = local.get(id);
|
|
315
332
|
if (localEntry !== undefined) {
|
|
316
333
|
const sharedSeq = await lastContentSeq(entry.file);
|
|
@@ -359,5 +376,5 @@ export async function syncSessions(deps) {
|
|
|
359
376
|
await writeJsonAtomic(legacyFile, { version: 1, deleted: {} });
|
|
360
377
|
}
|
|
361
378
|
|
|
362
|
-
return { pushed, pulled, skipped, revived, tombstoned, created, missing, failed, trashed: Object.keys(ledger.deleted).length, pushedIds, pulledIds };
|
|
379
|
+
return { pushed, pulled, skipped, revived, tombstoned, created, missing, failed, trashed: Object.keys(ledger.deleted).length, pushedIds, pulledIds, blankGuard };
|
|
363
380
|
}
|
package/host/schedule.js
CHANGED
|
@@ -80,11 +80,22 @@ export function installSyncScheduler(ctx, deps) {
|
|
|
80
80
|
let retryTimer = null;
|
|
81
81
|
let disposed = false;
|
|
82
82
|
let running = false;
|
|
83
|
+
// Subscribers are told about start and finish so a reader can follow the run
|
|
84
|
+
// without polling.
|
|
85
|
+
const watchers = new Set();
|
|
86
|
+
const notifyWatchers = () => {
|
|
87
|
+
for (const watcher of [...watchers]) {
|
|
88
|
+
try {
|
|
89
|
+
watcher();
|
|
90
|
+
} catch {
|
|
91
|
+
// A broken watcher must not affect the run.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
83
95
|
let cooldownUntil = 0;
|
|
84
96
|
let failures = 0;
|
|
85
97
|
let paused = false;
|
|
86
98
|
let pausedAt = null;
|
|
87
|
-
let startupTimer = null;
|
|
88
99
|
let lastIntervalAt = 0;
|
|
89
100
|
let lastDailyKey = '';
|
|
90
101
|
|
|
@@ -177,6 +188,7 @@ async function autoRun(reason) {
|
|
|
177
188
|
return false;
|
|
178
189
|
}
|
|
179
190
|
running = true;
|
|
191
|
+
notifyWatchers();
|
|
180
192
|
trace(`autoRun ${reason}: start`);
|
|
181
193
|
try {
|
|
182
194
|
const record = await runSync({ paths, settings, agents }, { probe: false });
|
|
@@ -213,6 +225,7 @@ async function autoRun(reason) {
|
|
|
213
225
|
note(`${reason}: ${String(error?.message ?? error)}${paused ? ', auto sync paused' : ''}`, 'error');
|
|
214
226
|
} finally {
|
|
215
227
|
running = false;
|
|
228
|
+
notifyWatchers();
|
|
216
229
|
cooldownUntil = Date.now() + Math.max(1, Number(settings.syncCooldownMinutes) || 5) * 60_000;
|
|
217
230
|
}
|
|
218
231
|
}
|
|
@@ -254,6 +267,12 @@ async function autoRun(reason) {
|
|
|
254
267
|
|
|
255
268
|
const status = () => ({ paused, failures, pausedAt, cooldownUntil, running });
|
|
256
269
|
|
|
270
|
+
/** Wake every waiting reader; the returned function unsubscribes. */
|
|
271
|
+
const subscribe = (watcher) => {
|
|
272
|
+
watchers.add(watcher);
|
|
273
|
+
return () => watchers.delete(watcher);
|
|
274
|
+
};
|
|
275
|
+
|
|
257
276
|
const resume = () => {
|
|
258
277
|
failures = 0;
|
|
259
278
|
paused = false;
|
|
@@ -263,12 +282,8 @@ async function autoRun(reason) {
|
|
|
263
282
|
return status();
|
|
264
283
|
};
|
|
265
284
|
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
// costs nothing.
|
|
269
|
-
startupTimer = setTimeout(() => {
|
|
270
|
-
void autoRun('startup');
|
|
271
|
-
}, 5000);
|
|
285
|
+
// Launch-time catch-up is driven by the client, so the reader sees the restart
|
|
286
|
+
// countdown before the window closes. Host-side runs stay on idle/interval/daily.
|
|
272
287
|
|
|
273
288
|
const statusListener = ctx.on('agent/status', (payload) => {
|
|
274
289
|
trace(`agent/status=${String(payload?.status)}`);
|
|
@@ -288,9 +303,9 @@ async function autoRun(reason) {
|
|
|
288
303
|
if (tick !== null) clearInterval(tick);
|
|
289
304
|
if (idleTimer !== null) clearTimeout(idleTimer);
|
|
290
305
|
if (retryTimer !== null) clearTimeout(retryTimer);
|
|
291
|
-
if (startupTimer !== null) clearTimeout(startupTimer);
|
|
292
306
|
if (typeof statusListener === 'function') statusListener();
|
|
307
|
+
watchers.clear();
|
|
293
308
|
};
|
|
294
309
|
|
|
295
|
-
return { dispose, status, resume };
|
|
310
|
+
return { dispose, status, resume, subscribe };
|
|
296
311
|
}
|
package/host/sync.js
CHANGED
|
@@ -195,6 +195,12 @@ function logLines(summary, transport, titleMap = new Map()) {
|
|
|
195
195
|
...(summary.sessions?.pushedIds ?? []).map((id) => `推送上云:${titleMap.get(id) ?? id}`),
|
|
196
196
|
...(summary.sessions?.pulledIds ?? []).map((id) => `从云取回:${titleMap.get(id) ?? id}`),
|
|
197
197
|
]);
|
|
198
|
+
const guardSkipped = Number(summary.blankGuard?.skipped) || 0;
|
|
199
|
+
const guardRepaired = Number(summary.blankGuard?.repaired) || 0;
|
|
200
|
+
if (guardSkipped > 0 || guardRepaired > 0) {
|
|
201
|
+
const repaired = guardRepaired > 0 ? `,修复过期缓存 ${counts(guardRepaired)} 个` : '';
|
|
202
|
+
push(`空白会话:跳过 ${counts(guardSkipped)} 个${repaired}`);
|
|
203
|
+
}
|
|
198
204
|
push(configCopied === 0 && attachCopied === 0
|
|
199
205
|
? '配置附件:双端一致,无更新'
|
|
200
206
|
: `配置附件:更新配置 ${counts(configCopied)} 个、附件 ${counts(attachCopied)} 个`,
|
package/index.js
CHANGED
|
@@ -79,6 +79,27 @@ export function apply(ctx, config = {}) {
|
|
|
79
79
|
}
|
|
80
80
|
})();
|
|
81
81
|
|
|
82
|
+
// Bumped for every committed user message; the composer badge watches it to
|
|
83
|
+
// know the reader sent something and the finished-sync line may go away.
|
|
84
|
+
let userMessageSeq = 0;
|
|
85
|
+
const watchWaiters = new Set();
|
|
86
|
+
try {
|
|
87
|
+
ctx.effect(() => ctx.on('session/event', (session, event) => {
|
|
88
|
+
if (event?.type !== 'user/message') return;
|
|
89
|
+
userMessageSeq += 1;
|
|
90
|
+
// Wake the waiting call so the client sees the new count immediately.
|
|
91
|
+
for (const wake of [...watchWaiters]) {
|
|
92
|
+
try {
|
|
93
|
+
wake();
|
|
94
|
+
} catch {
|
|
95
|
+
// A broken waiter must not affect the others.
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}), 'dsh-enhanced: user message counter');
|
|
99
|
+
} catch {
|
|
100
|
+
// Without the event the line simply clears on the next sync instead.
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
const dependencies = (settings) => ({
|
|
83
104
|
paths,
|
|
84
105
|
settings,
|
|
@@ -148,8 +169,49 @@ export function apply(ctx, config = {}) {
|
|
|
148
169
|
const history = await readSyncHistory({ paths, settings });
|
|
149
170
|
return { settings: { syncEnabled: settings.syncEnabled, syncDir: settings.syncDir, syncScript: settings.syncScript, syncMachineId: settings.syncMachineId, syncSkipAttachments: settings.syncSkipAttachments }, target, state, history, auto: scheduler.status(), running: live };
|
|
150
171
|
}
|
|
172
|
+
case 'sync.watch': {
|
|
173
|
+
// Resolve as soon as the automatic run starts or stops (or after 25 s),
|
|
174
|
+
// so the client follows the state without a polling timer.
|
|
175
|
+
const current = () => {
|
|
176
|
+
const live = typeof ctx.get('agents')?.list === 'function'
|
|
177
|
+
? ctx.get('agents').list().filter((agent) => agent?.status === 'running').length
|
|
178
|
+
: 0;
|
|
179
|
+
return { auto: scheduler.status(), running: live, userSeq: userMessageSeq };
|
|
180
|
+
};
|
|
181
|
+
return await new Promise((resolve) => {
|
|
182
|
+
let settled = false;
|
|
183
|
+
let unsubscribe = () => {};
|
|
184
|
+
const finish = () => {
|
|
185
|
+
if (settled) return;
|
|
186
|
+
settled = true;
|
|
187
|
+
unsubscribe();
|
|
188
|
+
watchWaiters.delete(finish);
|
|
189
|
+
clearTimeout(timer);
|
|
190
|
+
resolve(current());
|
|
191
|
+
};
|
|
192
|
+
const timer = setTimeout(finish, 25_000);
|
|
193
|
+
unsubscribe = scheduler.subscribe(finish);
|
|
194
|
+
watchWaiters.add(finish);
|
|
195
|
+
signal?.addEventListener?.('abort', finish, { once: true });
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
case 'sync.auto': {
|
|
199
|
+
const live = typeof ctx.get('agents')?.list === 'function'
|
|
200
|
+
? ctx.get('agents').list().filter((agent) => agent?.status === 'running').length
|
|
201
|
+
: 0;
|
|
202
|
+
return { auto: scheduler.status(), running: live };
|
|
203
|
+
}
|
|
151
204
|
case 'sync.probe':
|
|
152
205
|
case 'sync.run': {
|
|
206
|
+
// A running turn is writing session files; syncing then risks reading a
|
|
207
|
+
// half-written log. The launch-time call asks for quiet so it can skip.
|
|
208
|
+
if (action === 'sync.run') {
|
|
209
|
+
const busy = (ctx.get('agents')?.list?.() ?? []).some((agent) => agent?.status === 'running');
|
|
210
|
+
if (busy) {
|
|
211
|
+
if (request?.quiet === true) return { skipped: 'busy' };
|
|
212
|
+
throw failure('sync-task-running', '有会话正在运行,稍后再同步。');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
153
215
|
const settings = await readSettings(paths);
|
|
154
216
|
return runSync({ paths, settings, agents: ctx.get('agents'), registry: ctx.workspaceRegistry }, { probe: action === 'sync.probe' });
|
|
155
217
|
}
|