dsh-ferry 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js ADDED
@@ -0,0 +1,1619 @@
1
+ /**
2
+ * dsh-ferry browser half.
3
+ *
4
+ * Three surfaces, one plugin:
5
+ * - a sidebar panel (`dsh-ferry`) that manages peers and pulls sessions,
6
+ * - a Session "..." menu entry that pushes to a connected peer,
7
+ * - an overlay toast host for transfer results.
8
+ *
9
+ * Plain JavaScript and React.createElement only; data crosses the browser
10
+ * Connection at `/api/dsh-ferry/rpc`.
11
+ */
12
+ window.__ModuleLoader__.load({
13
+ id: 'dsh-ferry',
14
+ factory(require) {
15
+ const React = require('react');
16
+ const h = React.createElement;
17
+ const { useState, useEffect, useMemo, useCallback } = React;
18
+
19
+ const CSS = `
20
+ .ferry-root{display:flex;flex-direction:column;gap:18px;font-size:14px;color:var(--dsw-alias-label-primary);padding:28px 32px 48px;max-width:940px;min-height:100%;overflow:auto;box-sizing:border-box}
21
+ .ferry-title{font-size:18px;font-weight:600;line-height:26px}
22
+ .ferry-desc{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;margin-top:4px;max-width:76ch}
23
+ .ferry-card{border:.5px solid var(--dsw-alias-border-l1);border-radius:10px;padding:16px 18px;background:var(--dsw-alias-bg-layer-1)}
24
+ .ferry-card-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
25
+ .ferry-section-title{font-size:14px;font-weight:600;line-height:20px}
26
+ .ferry-meta{color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px}
27
+ .ferry-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;word-break:break-all}
28
+ .ferry-spacer{flex:1 1 auto}
29
+ .ferry-btn{appearance:none;border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);border-radius:7px;padding:4px 11px;font-size:12px;line-height:18px;cursor:pointer;white-space:nowrap}
30
+ .ferry-btn:hover:not(:disabled){border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}
31
+ .ferry-btn.primary{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary);background:transparent}
32
+ .ferry-btn.danger{border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}
33
+ .ferry-btn:disabled{opacity:.45;cursor:default}
34
+ .ferry-input,.ferry-select{background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l2);border-radius:6px;padding:4px 8px;color:var(--dsw-alias-label-primary);font-size:12px;line-height:18px;min-width:0;box-sizing:border-box}
35
+ .ferry-input.wide{width:100%}
36
+ .ferry-field{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-secondary)}
37
+ .ferry-peer{border-top:.5px solid var(--dsw-alias-border-l1);padding:12px 0;display:flex;flex-direction:column;gap:8px}
38
+ .ferry-peer:first-of-type{border-top:none;padding-top:4px}
39
+ .ferry-peer-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
40
+ .ferry-dot{width:8px;height:8px;border-radius:50%;flex:none;display:inline-block}
41
+ .ferry-dot.on{background:var(--dsw-alias-state-success-primary)}
42
+ .ferry-dot.off{background:var(--dsw-alias-state-error-primary)}
43
+ .ferry-dot.idle{background:var(--dsw-alias-state-idle-primary)}
44
+ .ferry-list{max-height:340px;overflow:auto;margin-top:6px;border-top:.5px solid var(--dsw-alias-border-l1)}
45
+ .ferry-item{display:flex;gap:12px;align-items:center;padding:9px 0;border-bottom:.5px solid var(--dsw-alias-border-l1)}
46
+ .ferry-item-main{min-width:0;flex:1 1 auto}
47
+ .ferry-item-title{font-size:13px;line-height:18px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
48
+ .ferry-badge{display:inline-block;font-size:10px;line-height:16px;padding:0 6px;border-radius:999px;border:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);margin-left:6px}
49
+ .ferry-badge.run{color:var(--dsw-alias-state-warn-primary);border-color:var(--dsw-alias-state-warn-primary)}
50
+ .ferry-notice{border-radius:8px;padding:9px 12px;font-size:12px;line-height:18px;border:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);margin-top:10px}
51
+ .ferry-notice.success{border-color:var(--dsw-alias-state-success-primary)}
52
+ .ferry-notice.error{border-color:var(--dsw-alias-state-error-primary)}
53
+ .ferry-empty{padding:16px 0;color:var(--dsw-alias-label-secondary);font-size:12px;text-align:center}
54
+ .ferry-menu-item{display:flex;align-items:center;gap:8px;width:100%;padding:4px 7px;background:transparent;border:none;border-radius:var(--dsw-radius-md);color:inherit;font:inherit;font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);line-height:20px;text-align:left;cursor:pointer;box-sizing:border-box}
55
+ .ferry-menu-item:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2)}
56
+ .ferry-menu-item:disabled{opacity:.45;cursor:default}
57
+ .ferry-modal-backdrop{position:fixed;inset:0;z-index:85;pointer-events:auto;background:rgba(0,0,0,.45)}
58
+ .ferry-modal{position:fixed;z-index:86;left:50%;top:50%;transform:translate(-50%,-50%);width:min(460px,calc(100vw - 32px));max-height:calc(100vh - 32px);overflow:auto;box-sizing:border-box;padding:18px;border:.5px solid var(--dsw-alias-border-l2);border-radius:12px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);box-shadow:0 18px 48px rgba(0,0,0,.4);display:flex;flex-direction:column;gap:10px;outline:none;pointer-events:auto}
59
+ .ferry-modal-head{display:flex;flex-direction:column;gap:3px}
60
+ .ferry-modal-title{font-size:15px;font-weight:600;line-height:22px}
61
+ .ferry-modal-session{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
62
+ .ferry-modal-hint{font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary)}
63
+ .ferry-modal-toolbar{display:flex;align-items:flex-start;gap:10px}
64
+ .ferry-modal-toolbar .ferry-modal-hint{flex:1 1 auto}
65
+ .ferry-choice-list{display:flex;flex-direction:column;gap:2px;max-height:240px;overflow:auto;margin:2px 0}
66
+ .ferry-choice{display:flex;align-items:center;gap:10px;padding:8px 10px;border:.5px solid transparent;border-radius:7px;font-size:13px;line-height:19px;cursor:pointer}
67
+ .ferry-choice:hover{background:var(--dsw-alias-bg-layer-2)}
68
+ .ferry-choice.selected{border-color:var(--dsw-alias-brand-primary);background:var(--dsw-alias-bg-layer-2)}
69
+ .ferry-choice input[type=radio]{flex:none;margin:0;width:14px;height:14px;cursor:inherit}
70
+ .ferry-choice.offline{opacity:.5;cursor:default}
71
+ .ferry-choice.offline:hover{background:transparent}
72
+ .ferry-status{display:inline-flex;align-items:center;gap:6px;flex:none;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary)}
73
+ .ferry-choice-body{flex:1 1 auto;min-width:0}
74
+ .ferry-choice-row{display:flex;align-items:center;gap:8px;min-width:0}
75
+ .ferry-state{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);margin-top:2px;white-space:normal}
76
+ .ferry-mode{display:flex;flex-direction:column;gap:6px;border-top:.5px solid var(--dsw-alias-border-l1);padding-top:10px}
77
+ .ferry-mode-label{display:flex;align-items:flex-start;gap:8px;font-size:12px;line-height:18px;cursor:pointer}
78
+ .ferry-mode-label.disabled{opacity:.45;cursor:default}
79
+ .ferry-mode-text{display:flex;flex-direction:column;min-width:0}
80
+ .ferry-choice-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
81
+ .ferry-modal-error{font-size:11px;line-height:16px;color:var(--dsw-alias-state-error-primary)}
82
+ .ferry-modal-foot{display:flex;align-items:center;gap:8px;border-top:.5px solid var(--dsw-alias-border-l1);padding-top:12px;margin-top:2px}
83
+ .ferry-check{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--dsw-alias-label-secondary);cursor:pointer}
84
+ .ferry-toasts{position:fixed;right:20px;bottom:20px;z-index:90;display:flex;flex-direction:column;gap:8px;max-width:380px;pointer-events:none}
85
+ .ferry-toast{pointer-events:auto;border:.5px solid var(--dsw-alias-border-l2);border-left-width:3px;border-radius:8px;background:var(--dsw-alias-bg-overlay);padding:10px 12px;font-size:12px;line-height:18px;box-shadow:0 8px 24px rgba(0,0,0,.24)}
86
+ .ferry-toast.success{border-left-color:var(--dsw-alias-state-success-primary)}
87
+ .ferry-toast.error{border-left-color:var(--dsw-alias-state-error-primary)}
88
+ .ferry-toast.info{border-left-color:var(--dsw-alias-brand-primary)}
89
+ .ferry-toast-title{font-weight:600;margin-bottom:2px}
90
+ `;
91
+
92
+ /**
93
+ * Install the plugin stylesheet once for every slot surface. The sidebar
94
+ * panel, the Session menu flyout and the toasts live in different render
95
+ * trees, so a component-local <style> would leave the menu unstyled.
96
+ * @returns {() => void} disposer removing this generation's tag.
97
+ */
98
+ function installStyles() {
99
+ if (typeof document === 'undefined') return () => {};
100
+ const tag = document.createElement('style');
101
+ tag.setAttribute('data-dsh-ferry', String(Date.now()) + Math.random().toString(36).slice(2));
102
+ tag.textContent = CSS;
103
+ document.head.appendChild(tag);
104
+ return () => {
105
+ tag.remove();
106
+ };
107
+ }
108
+
109
+ const en = {
110
+ title: 'dsh-ferry',
111
+ description:
112
+ 'Push a Session (and the files it needs) to a connected DSH instance, or pull one back. Instances must be able to reach each other; configure peers below.',
113
+ instances: 'Peers',
114
+ thisInstance: 'This instance',
115
+ noPeers: 'No peers yet. Add one with its DSH web URL. Receiving pushes only needs the same token and incoming directory.',
116
+ addPeer: 'Add peer',
117
+ save: 'Save settings',
118
+ saving: 'Saving…',
119
+ saved: 'Settings saved',
120
+ name: 'Name',
121
+ url: 'URL',
122
+ token: 'Token',
123
+ urlNeeded: 'Enter the peer DSH web URL',
124
+ tokenKeep: 'Token is set; leave blank to keep it',
125
+ tokenNeeded: 'Enter a shared token',
126
+ remove: 'Remove',
127
+ refresh: 'Refresh status',
128
+ checking: 'Checking…',
129
+ online: 'online',
130
+ offline: 'offline',
131
+ latency: 'ms',
132
+ incomingRoot: 'Incoming workspace directory',
133
+ incomingRootHint:
134
+ 'When a received workspace has no directory on this machine, it lands here, in a subdirectory named after the source workspace and session.',
135
+ peersHint:
136
+ 'One shared token covers every instance. Only the side that can reach the other needs a peer entry; the receiving side just needs the same token and an incoming directory. The token never leaves this machine.',
137
+ tokenHint: 'Fleet-wide shared token. Leave blank to keep the current one.',
138
+ pullSection: 'Pull a session',
139
+ pullHint: 'Choose a peer, load its sessions, then pick one to pull and confirm how the local copy is treated.',
140
+ loadRemote: 'Load sessions',
141
+ noSessions: 'No matching sessions',
142
+ unnamed: 'Untitled session',
143
+ running: 'running',
144
+ targetDir: 'Target directory',
145
+ targetDirHint: 'Leave blank to map automatically: same path when it exists here, else the incoming directory.',
146
+ merge: 'Merge into an existing directory',
147
+ mergeHint: 'Overwrites differing files after backing them up.',
148
+ pull: 'Pull',
149
+ pulling: 'Pulling…',
150
+ push: 'Push',
151
+ pushing: 'Pushing…',
152
+ pushTo: 'Push to…',
153
+ pushDialogTitle: 'Push to another instance',
154
+ pushDialogHint:
155
+ 'Choose a target. When that instance has no local directory for this workspace, the files land in its incoming directory.',
156
+ pushDialogChecking: 'Checking instances…',
157
+ cancel: 'Cancel',
158
+ confirmPush: 'Push',
159
+ noOnlinePeer: 'No peer is connected right now',
160
+ managePeers: 'Manage peers…',
161
+ mergeInMenu: 'Merge into an existing directory (backs up)',
162
+ modeTitle: 'How to send it',
163
+ modeNew: 'New session',
164
+ modeNewHint: 'Create a separate copy there; the peer keeps whatever it already has.',
165
+ modeUpdate: 'Append update',
166
+ modeUpdateHint: 'Keep one session: add the events the peer is missing and merge the workspace.',
167
+ modeUpdateUnavailable: 'Not possible for this peer',
168
+ state_absent: 'No copy there yet; it will be created',
169
+ state_behind: 'The peer has {have} events; {add} will be appended',
170
+ state_same: 'The peer has {have} events and matches; only workspace files are synced',
171
+ state_ahead: 'The peer has {have} events, more than here; only a new copy is possible',
172
+ state_diverged: 'The peer copy has diverged; only a new copy is possible',
173
+ state_active: 'The peer has this session open; only a new copy is possible',
174
+ state_unknown: 'Cannot tell what the peer has (offline, or its plugin is older; append updates need the same version on both sides)',
175
+ local_absent: 'No local copy yet; it will be created',
176
+ local_behind: 'This instance has {have} events; {add} will be appended',
177
+ local_same: 'This instance has {have} events and matches; only workspace files are synced',
178
+ local_ahead: 'This instance has {have} events, more than the peer; only a new copy is possible',
179
+ local_diverged: 'The local copy has diverged; only a new copy is possible',
180
+ local_active: 'This session is open here; only a new copy is possible',
181
+ local_unknown: 'Cannot tell what this instance has',
182
+ pullDialogTitle: 'Pull from another instance',
183
+ pullDialogChecking: 'Checking the local copy…',
184
+ pullDialogHint: 'Choose how the local copy should be treated.',
185
+ confirmPull: 'Pull',
186
+ appended: 'events appended',
187
+ code_session_ahead: 'The peer has a longer copy of this session; send it as a new session.',
188
+ code_session_diverged: 'The peer has a different copy of this session; send it as a new session.',
189
+ code_session_active: 'The session is open there; close it or stop its turn before updating it.',
190
+ code_session_unreadable: 'The stored session log could not be read, so the peer copy cannot be compared.',
191
+ code_sessionForked: 'The two copies had diverged, so the push created a separate session on the peer.',
192
+ files: 'files',
193
+ overwritten: 'overwritten',
194
+ skippedTitle: 'Left behind',
195
+ warningsTitle: 'Notes',
196
+ dismiss: 'Dismiss',
197
+ success: 'Done',
198
+ failed: 'Failed',
199
+ alreadyThere: 'Already present with the same content; nothing was overwritten.',
200
+ resultTarget: 'Target',
201
+ settingsUnavailable: 'This profile has no config editor; edit cordis.patch.yml instead.',
202
+ noPeerSelected: 'Choose a peer first.',
203
+ category_dependency: 'dependencies',
204
+ category_build: 'build output',
205
+ category_cache: 'caches',
206
+ category_editor: 'editor state',
207
+ category_ignored: 'gitignored',
208
+ category_secret: 'credentials',
209
+ category_large: 'oversize files',
210
+ category_symlink: 'external symlinks',
211
+ category_special: 'special files',
212
+ category_git: 'git history',
213
+ 'category_user-exclude': 'excluded by config',
214
+ category_internal: 'transfer staging',
215
+ code_gitSkippedTooLarge: 'Git history was larger than the transfer cap and stayed behind; clone it on the target if needed.',
216
+ code_gitSkippedWorktree: 'This workspace uses a git worktree; the .git pointer was not transferred.',
217
+ code_gitConfigMayHoldCredentials: 'The copied .git/config may embed remote credentials.',
218
+ code_childSessionsStayBehind: 'Subagent sessions stay on this instance.',
219
+ code_parentLineageDangling: 'The parent session is not on the target instance.',
220
+ code_attachmentsIncomplete: 'Some attachments could not be read and stay referenced but missing.',
221
+ code_attachmentUnreadable: 'One attachment could not be read.',
222
+ code_attachmentBudgetExceeded: 'Attachment bytes exceeded the transfer budget.',
223
+ code_attachmentWriteFailed: 'One attachment could not be stored on the target.',
224
+ code_agentPresetMissing: 'The session uses an agent preset this instance does not have.',
225
+ code_workspaceAttachFailed: 'The workspace was materialized but the session was not attached to it.',
226
+ code_workspaceUnarchiveFailed: 'The session was updated but could not be unarchived.',
227
+ code_sourceArchiveFailed: 'The transfer succeeded but the source session could not be archived.',
228
+ code_workspaceOverLimit: 'The workspace exceeded the configured size limit.',
229
+ code_directoryUnreadable: 'A directory could not be read.',
230
+ code_entryUnreadable: 'A file could not be read.',
231
+ code_targetHasGit: 'The target already had a .git directory; its history was kept.',
232
+ code_target_not_empty: 'The target directory already exists and is not empty; enable merge to write into it.',
233
+ code_session_conflict: 'The target already has this session with different content; pull it under a new session id instead.',
234
+ code_unreachable: 'The peer is unreachable. Check that its DSH web server listens on an address this machine can reach.',
235
+ code_unauthorized: 'The peer rejected the token. Both sides must share the same token.',
236
+ code_unauthenticated: 'The peer rejected the request signature. Both sides must share the same token.',
237
+ code_replayed: 'The peer rejected a replayed request; check the clocks on both machines.',
238
+ code_no_token: 'No shared token is configured; set one in the dsh-ferry panel.',
239
+ };
240
+
241
+ const zh = {
242
+ title: 'dsh-ferry',
243
+ description:
244
+ '把会话以及它需要的工作区文件推送到另一个可达的 DSH 实例,或从对端拉取。实例之间必须网络可达;在下方配置对端。',
245
+ instances: '实例',
246
+ thisInstance: '本实例',
247
+ noPeers: '还没有对端。填写对端的 DSH Web 地址即可添加;只被动接收推送的一侧,只需要相同令牌和接收目录。',
248
+ addPeer: '添加实例',
249
+ save: '保存配置',
250
+ saving: '保存中…',
251
+ saved: '配置已保存',
252
+ name: '名称',
253
+ url: '地址',
254
+ token: '令牌',
255
+ urlNeeded: '请填写对端的 DSH Web 地址',
256
+ tokenKeep: '已设置令牌,留空保持不变',
257
+ tokenNeeded: '请填写共享令牌',
258
+ remove: '删除',
259
+ refresh: '刷新状态',
260
+ checking: '检查中…',
261
+ online: '在线',
262
+ offline: '离线',
263
+ latency: '毫秒',
264
+ incomingRoot: '工作区接收目录',
265
+ incomingRootHint: '收到的会话如果没有本机映射目录,会放到这里,并以“源工作区名-会话 ID”建立子目录。',
266
+ peersHint:
267
+ '同一个令牌适用于所有实例。只有能主动访问对方的一侧需要添加对端;接收侧只需相同令牌和接收目录。令牌不会离开本机。',
268
+ tokenHint: '全局共享令牌,所有实例一致;留空保持不变。',
269
+ pullSection: '拉取会话',
270
+ pullHint: '选择对端,加载它的会话列表,点“拉取”后确认本地副本怎么处理。',
271
+ loadRemote: '加载会话',
272
+ noSessions: '没有匹配的会话',
273
+ unnamed: '未命名会话',
274
+ running: '运行中',
275
+ targetDir: '目标目录',
276
+ targetDirHint: '留空则自动映射:本机存在同路径就用它,否则放到接收目录。',
277
+ merge: '合并到已有目录',
278
+ mergeHint: '覆盖同名文件前会先备份。',
279
+ pull: '拉取',
280
+ pulling: '拉取中…',
281
+ push: '推送',
282
+ pushing: '推送中…',
283
+ pushTo: '推送到…',
284
+ pushDialogTitle: '推送到其他实例',
285
+ pushDialogHint: '选择目标实例。对端没有该工作区的本机目录时,文件会落到对端的接收目录。',
286
+ pushDialogChecking: '正在检查实例状态…',
287
+ cancel: '取消',
288
+ confirmPush: '推送',
289
+ noOnlinePeer: '当前没有已连接的对端',
290
+ managePeers: '管理实例…',
291
+ mergeInMenu: '合并已有目录(自动备份)',
292
+ modeTitle: '推送方式',
293
+ modeNew: '新建会话',
294
+ modeNewHint: '在对方创建一份独立副本,对方已有的内容不动。',
295
+ modeUpdate: '追加更新',
296
+ modeUpdateHint: '沿用同一个会话:补上对方缺少的事件,并合并工作区。',
297
+ modeUpdateUnavailable: '当前对端不可用',
298
+ state_absent: '对方没有此会话,将新建',
299
+ state_behind: '对方已有 {have} 条,本次追加 {add} 条',
300
+ state_same: '对方已有 {have} 条且内容一致,只同步工作区文件',
301
+ state_ahead: '对方已有 {have} 条,比本地多,只能新建副本',
302
+ state_diverged: '对方内容与本地不同,只能新建副本',
303
+ state_active: '对方已打开该会话,只能新建副本',
304
+ state_unknown: '无法判断对方状态(离线,或对方插件较旧;追加更新需要两端同版本)',
305
+ local_absent: '本地没有此会话,将新建',
306
+ local_behind: '本地已有 {have} 条,本次追加 {add} 条',
307
+ local_same: '本地已有 {have} 条且内容一致,只同步工作区文件',
308
+ local_ahead: '本地已有 {have} 条,比远端多,只能新建副本',
309
+ local_diverged: '本地内容与远端不同,只能新建副本',
310
+ local_active: '本地已打开该会话,只能新建副本',
311
+ local_unknown: '无法判断本地状态',
312
+ pullDialogTitle: '从其他实例拉取',
313
+ pullDialogChecking: '正在检查本地副本…',
314
+ pullDialogHint: '选择本次拉取如何处理本地已有副本。',
315
+ confirmPull: '拉取',
316
+ appended: '条事件已追加',
317
+ code_session_ahead: '对方有比本地更长的副本,请改为新建会话推送。',
318
+ code_session_diverged: '对方已有内容不同的同名会话,请改为新建会话推送。',
319
+ code_session_active: '该会话在对端/本地处于打开状态,请先关闭或停止后再更新。',
320
+ code_session_unreadable: '会话日志无法读取,无法比较对方副本。',
321
+ code_sessionForked: '两边内容已分叉,已在对方新建独立会话。',
322
+ files: '文件',
323
+ overwritten: '覆盖',
324
+ skippedTitle: '未传输',
325
+ warningsTitle: '提示',
326
+ dismiss: '知道了',
327
+ success: '完成',
328
+ failed: '失败',
329
+ alreadyThere: '目标已有内容相同的会话,没有覆盖任何内容。',
330
+ resultTarget: '目标',
331
+ settingsUnavailable: '当前 profile 没有配置编辑器,请直接编辑 cordis.patch.yml。',
332
+ noPeerSelected: '请先选择一个对端。',
333
+ category_dependency: '依赖目录',
334
+ category_build: '构建产物',
335
+ category_cache: '缓存',
336
+ category_editor: '编辑器状态',
337
+ category_ignored: '被忽略文件',
338
+ category_secret: '凭据',
339
+ category_large: '超大文件',
340
+ category_symlink: '外部符号链接',
341
+ category_special: '特殊文件',
342
+ category_git: 'Git 历史',
343
+ 'category_user-exclude': '配置排除',
344
+ category_internal: '传输暂存',
345
+ code_gitSkippedTooLarge: 'Git 历史超过上限,未传输;需要时在目标机 clone。',
346
+ code_gitSkippedWorktree: '该工作区使用 git worktree,未传输 .git 指针。',
347
+ code_gitConfigMayHoldCredentials: '复制过去的 .git/config 可能包含远端凭据。',
348
+ code_childSessionsStayBehind: '子会话仍留在本实例。',
349
+ code_parentLineageDangling: '父会话不在目标实例上。',
350
+ code_attachmentsIncomplete: '部分附件无法读取,会话仍引用但目标缺失。',
351
+ code_attachmentUnreadable: '有一个附件无法读取。',
352
+ code_attachmentBudgetExceeded: '附件总量超过传输预算。',
353
+ code_attachmentWriteFailed: '有一个附件无法写入目标。',
354
+ code_agentPresetMissing: '该会话使用的 agent preset 在目标实例上不存在。',
355
+ code_workspaceAttachFailed: '工作区已写入,但会话没有挂到该工作区。',
356
+ code_workspaceUnarchiveFailed: '会话已更新,但没能从归档中恢复。',
357
+ code_sourceArchiveFailed: '传输成功,但源会话归档失败。',
358
+ code_workspaceOverLimit: '工作区超过配置的大小上限。',
359
+ code_directoryUnreadable: '有一个目录无法读取。',
360
+ code_entryUnreadable: '有一个文件无法读取。',
361
+ code_targetHasGit: '目标已有 .git,保留了目标的历史。',
362
+ code_target_not_empty: '目标目录已存在且非空;需要勾选合并才能写入。',
363
+ code_session_conflict: '目标已有同 ID 但内容不同的会话;请改用新会话 ID 拉取。',
364
+ code_unreachable: '对端不可达。检查它的 DSH Web 是否监听本机可达的地址。',
365
+ code_unauthorized: '对端拒绝了令牌。两端必须使用同一个令牌。',
366
+ code_unauthenticated: '对端拒绝了请求签名。两端必须使用同一个令牌。',
367
+ code_replayed: '对端拒绝了重放请求;检查两端的时钟。',
368
+ code_no_token: '还没有配置共享令牌;请在 dsh-ferry 面板里设置。',
369
+ };
370
+
371
+ /** Module-scoped toast bus shared by the panel, the menu item and the overlay. */
372
+ const toasts = (() => {
373
+ let items = [];
374
+ let next = 1;
375
+ const listeners = new Set();
376
+ const emit = () => {
377
+ for (const listener of listeners) listener();
378
+ };
379
+ const bus = {
380
+ push({ tone = 'info', title, text, durationMs = 9000 }) {
381
+ const id = next++;
382
+ items = [...items, { id, tone, title, text }];
383
+ emit();
384
+ if (durationMs > 0) setTimeout(() => bus.dismiss(id), durationMs);
385
+ return id;
386
+ },
387
+ dismiss(id) {
388
+ items = items.filter((item) => item.id !== id);
389
+ emit();
390
+ },
391
+ subscribe(listener) {
392
+ listeners.add(listener);
393
+ return () => {
394
+ listeners.delete(listener);
395
+ };
396
+ },
397
+ snapshot() {
398
+ return items;
399
+ },
400
+ };
401
+ return bus;
402
+ })();
403
+
404
+ async function rpc(body) {
405
+ let response;
406
+ try {
407
+ response = await fetch('/api/dsh-ferry/rpc', {
408
+ method: 'POST',
409
+ headers: { 'content-type': 'application/json' },
410
+ body: JSON.stringify(body),
411
+ });
412
+ } catch (error) {
413
+ throw new Error(String(error));
414
+ }
415
+ let payload;
416
+ try {
417
+ payload = await response.json();
418
+ } catch {
419
+ throw new Error(`HTTP ${response.status}`);
420
+ }
421
+ if (!response.ok || payload?.ok === false) {
422
+ const failure = payload?.error;
423
+ const error = new Error(failure?.message ?? `HTTP ${response.status}`);
424
+ error.code = failure?.code;
425
+ throw error;
426
+ }
427
+ return payload;
428
+ }
429
+
430
+ function formatBytes(bytes) {
431
+ if (typeof bytes !== 'number' || !Number.isFinite(bytes)) return '';
432
+ if (bytes < 1024) return `${bytes} B`;
433
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB`;
434
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
435
+ }
436
+
437
+ function formatTime(ts) {
438
+ if (typeof ts !== 'number') return '';
439
+ try {
440
+ return new Date(ts).toLocaleString();
441
+ } catch {
442
+ return '';
443
+ }
444
+ }
445
+
446
+ function codeText(code, t) {
447
+ const key = `code_${String(code).replace(/-/g, '_')}`;
448
+ const text = t(key);
449
+ return text === key ? String(code) : text;
450
+ }
451
+
452
+ function transferSummary(result, t) {
453
+ const pieces = [];
454
+ if (result?.status === 'updated' && typeof result.appended === 'number') {
455
+ pieces.push(`${result.appended} ${t('appended')}`);
456
+ }
457
+ if (result?.targetDir) pieces.push(`${t('resultTarget')}: ${result.targetDir}`);
458
+ if (result?.workspace) {
459
+ const parts = [
460
+ `${t('files')} ${result.workspace.written ?? result.workspace.files ?? 0}`,
461
+ formatBytes(result.workspace.bytes ?? 0),
462
+ ];
463
+ if (result.workspace.overwritten) parts.push(`${t('overwritten')} ${result.workspace.overwritten}`);
464
+ pieces.push(parts.join(' · '));
465
+ }
466
+ const skipped = result?.transfer?.workspace?.skipped ?? result?.workspace?.skipped ?? [];
467
+ if (skipped.length > 0) {
468
+ pieces.push(
469
+ `${t('skippedTitle')}: ${skipped.map((item) => `${t(`category_${item.category}`)} ${item.count}`).join(' · ')}`,
470
+ );
471
+ }
472
+ return pieces.join('\n');
473
+ }
474
+
475
+ function noticeFor(result, t) {
476
+ if (result?.status === 'exists') return { tone: 'success', text: t('alreadyThere') };
477
+ const text = transferSummary(result, t);
478
+ return { tone: 'success', text: text === '' ? t('success') : text };
479
+ }
480
+
481
+ function layoutError(error, t) {
482
+ const code = error?.code;
483
+ if (typeof code === 'string') {
484
+ const key = `code_${code.replace(/-/g, '_')}`;
485
+ if (t(key) !== key) return t(key);
486
+ }
487
+ return error?.message ?? String(error);
488
+ }
489
+
490
+ function WarningList({ warnings, t }) {
491
+ if (!Array.isArray(warnings) || warnings.length === 0) return null;
492
+ return h(
493
+ 'ul',
494
+ { style: { margin: '6px 0 0', paddingLeft: '16px', color: 'var(--dsw-alias-label-secondary)', fontSize: '11px' } },
495
+ warnings.slice(0, 8).map((warning, index) =>
496
+ h('li', { key: `${warning.code ?? 'warning'}-${index}` }, codeText(warning.code ?? warning, t)),
497
+ ),
498
+ );
499
+ }
500
+
501
+ /* ---------- shared icon ---------- */
502
+
503
+ function PeerIcon({ size = 18, active = false }) {
504
+ const color = active ? 'var(--dsw-alias-brand-primary)' : 'currentColor';
505
+ return h(
506
+ 'svg',
507
+ { width: size, height: size, viewBox: '0 0 24 24', 'aria-hidden': true, style: { display: 'block' } },
508
+ h('circle', { cx: 5, cy: 13, r: 2.4, fill: color }),
509
+ h('circle', { cx: 19, cy: 13, r: 2.4, fill: color }),
510
+ h('path', {
511
+ d: 'M7.4 13h9.2',
512
+ stroke: color,
513
+ strokeWidth: 1.6,
514
+ strokeLinecap: 'round',
515
+ strokeDasharray: '1.5 3',
516
+ }),
517
+ h('path', {
518
+ d: 'M12 4.5v4.2M9.8 6.7 12 4.5l2.2 2.2',
519
+ fill: 'none',
520
+ stroke: color,
521
+ strokeWidth: 1.6,
522
+ strokeLinecap: 'round',
523
+ strokeLinejoin: 'round',
524
+ }),
525
+ h('path', { d: 'M8 18.5h8l-1.4 2.2H9.4z', fill: color, opacity: 0.7 }),
526
+ );
527
+ }
528
+
529
+ /* ---------- sidebar panel: peers, incoming root, pull ---------- */
530
+
531
+ function FerryPage(props) {
532
+ const t = props.t;
533
+ const [settings, setSettings] = useState(null);
534
+ const [draftPeers, setDraftPeers] = useState([]);
535
+ const [incomingRoot, setIncomingRoot] = useState('');
536
+ const [status, setStatus] = useState(null);
537
+ const [statusError, setStatusError] = useState(null);
538
+ const [checking, setChecking] = useState(false);
539
+ const [saving, setSaving] = useState(false);
540
+ const [token, setToken] = useState('');
541
+ const [tokenSet, setTokenSet] = useState(false);
542
+ const [notice, setNotice] = useState(null);
543
+ const [pullPeer, setPullPeer] = useState('');
544
+ const [remote, setRemote] = useState({ peer: null, loading: false, sessions: [], error: null });
545
+
546
+ const applySettings = useCallback((next) => {
547
+ setSettings(next);
548
+ setDraftPeers(
549
+ (next?.peers ?? []).map((peer) => ({
550
+ id: peer.id,
551
+ name: peer.name ?? '',
552
+ url: peer.url ?? '',
553
+ })),
554
+ );
555
+ setToken('');
556
+ setTokenSet(next?.tokenSet === true);
557
+ setIncomingRoot(next?.incomingRoot ?? '');
558
+ if (next?.peers?.length > 0) setPullPeer((current) => (current === '' ? next.peers[0].id : current));
559
+ }, []);
560
+
561
+ const loadSettings = useCallback(async () => {
562
+ try {
563
+ const payload = await rpc({ action: 'settings' });
564
+ applySettings(payload.settings);
565
+ } catch (error) {
566
+ setNotice({ tone: 'error', text: error.message });
567
+ }
568
+ }, [applySettings]);
569
+
570
+ const loadStatus = useCallback(async () => {
571
+ setChecking(true);
572
+ try {
573
+ const payload = await rpc({ action: 'status' });
574
+ setStatus(payload);
575
+ setStatusError(null);
576
+ } catch (error) {
577
+ setStatusError(error.message);
578
+ } finally {
579
+ setChecking(false);
580
+ }
581
+ }, []);
582
+
583
+ useEffect(() => {
584
+ loadSettings();
585
+ loadStatus();
586
+ }, [loadSettings, loadStatus]);
587
+
588
+ const statusById = useMemo(() => {
589
+ const map = new Map();
590
+ for (const peer of status?.peers ?? []) map.set(peer.id, peer);
591
+ return map;
592
+ }, [status]);
593
+
594
+ const peerState = (peer) => {
595
+ const live = statusById.get(peer.id);
596
+ if (live === undefined) return { dot: 'idle', text: '' };
597
+ if (live.online === true) {
598
+ return {
599
+ dot: 'on',
600
+ text: `${t('online')}${typeof live.latencyMs === 'number' ? ` · ${live.latencyMs}${t('latency')}` : ''}`,
601
+ };
602
+ }
603
+ return { dot: 'off', text: `${t('offline')}: ${codeText(live.error?.code ?? 'unreachable', t)}` };
604
+ };
605
+
606
+ const updatePeer = (index, patch) => {
607
+ setDraftPeers((current) => current.map((peer, position) => (position === index ? { ...peer, ...patch } : peer)));
608
+ };
609
+
610
+ const addPeer = () => {
611
+ const suffix = Math.random().toString(36).slice(2, 8);
612
+ setDraftPeers((current) => [
613
+ ...current,
614
+ { id: `peer-${suffix}`, name: '', url: '' },
615
+ ]);
616
+ };
617
+
618
+ const save = async () => {
619
+ setSaving(true);
620
+ setNotice(null);
621
+ try {
622
+ for (const peer of draftPeers) {
623
+ if (peer.url.trim() === '') throw new Error(t('urlNeeded'));
624
+ }
625
+ if (draftPeers.length > 0 && !tokenSet && token.trim() === '') throw new Error(t('tokenNeeded'));
626
+ const payload = await rpc({
627
+ action: 'saveSettings',
628
+ incomingRoot,
629
+ ...(token.trim() === '' ? {} : { token: token.trim() }),
630
+ peers: draftPeers.map((peer) => ({
631
+ id: peer.id,
632
+ name: peer.name.trim() === '' ? peer.id : peer.name.trim(),
633
+ url: peer.url.trim(),
634
+ })),
635
+ });
636
+ applySettings(payload.settings);
637
+ setNotice({ tone: 'success', text: t('saved') });
638
+ // The host row reloads after the write; give it a moment before the
639
+ // next RPC so the new registration is in place.
640
+ setTimeout(() => loadStatus(), 400);
641
+ } catch (error) {
642
+ setNotice({ tone: 'error', text: `${t('failed')}: ${error.message}` });
643
+ } finally {
644
+ setSaving(false);
645
+ }
646
+ };
647
+
648
+ const loadRemote = async () => {
649
+ if (pullPeer === '') {
650
+ setNotice({ tone: 'error', text: t('noPeerSelected') });
651
+ return;
652
+ }
653
+ setRemote({ peer: pullPeer, loading: true, sessions: [], error: null });
654
+ try {
655
+ const payload = await rpc({ action: 'remoteSessions', peerId: pullPeer });
656
+ setRemote({ peer: pullPeer, loading: false, sessions: payload.sessions ?? [], error: null });
657
+ } catch (error) {
658
+ setRemote({ peer: pullPeer, loading: false, sessions: [], error: error.message });
659
+ }
660
+ };
661
+
662
+ const openPull = (session) => {
663
+ pullDialog.open({
664
+ peerId: pullPeer,
665
+ sessionId: session.sessionId,
666
+ title: session.title ?? '',
667
+ });
668
+ };
669
+
670
+ if (settings === null) {
671
+ return h('div', { className: 'ferry-root' }, h('div', { className: 'ferry-empty' }, t('checking')));
672
+ }
673
+
674
+ return h(
675
+ 'div',
676
+ { className: 'ferry-root' },
677
+ h(
678
+ 'div',
679
+ null,
680
+ h('div', { className: 'ferry-title' }, t('title')),
681
+ h('div', { className: 'ferry-desc' }, t('description')),
682
+ h(
683
+ 'div',
684
+ { className: 'ferry-meta', style: { marginTop: '8px' } },
685
+ `${t('thisInstance')}: ${settings.instance.name} (${settings.instance.id})`,
686
+ ),
687
+ ),
688
+ h(
689
+ 'div',
690
+ { className: 'ferry-card' },
691
+ h(
692
+ 'div',
693
+ { className: 'ferry-card-head' },
694
+ h('div', { className: 'ferry-section-title' }, t('instances')),
695
+ h('span', { className: 'ferry-spacer' }),
696
+ h(
697
+ 'button',
698
+ { className: 'ferry-btn', type: 'button', onClick: loadStatus, disabled: checking },
699
+ checking ? t('checking') : t('refresh'),
700
+ ),
701
+ h('button', { className: 'ferry-btn', type: 'button', onClick: addPeer }, t('addPeer')),
702
+ h(
703
+ 'button',
704
+ {
705
+ className: 'ferry-btn primary',
706
+ type: 'button',
707
+ onClick: save,
708
+ disabled: saving || settings.editable === false,
709
+ },
710
+ saving ? t('saving') : t('save'),
711
+ ),
712
+ ),
713
+ h('div', { className: 'ferry-meta', style: { marginTop: '6px' } }, t('peersHint')),
714
+ h(
715
+ 'div',
716
+ { style: { marginTop: '12px' } },
717
+ h(
718
+ 'label',
719
+ { className: 'ferry-field' },
720
+ h('span', null, t('token')),
721
+ h('input', {
722
+ className: 'ferry-input',
723
+ style: { minWidth: '320px' },
724
+ type: 'password',
725
+ value: token,
726
+ placeholder: tokenSet ? t('tokenKeep') : t('tokenNeeded'),
727
+ onChange: (event) => setToken(event.target.value),
728
+ }),
729
+ ),
730
+ h('div', { className: 'ferry-meta', style: { marginTop: '4px' } }, t('tokenHint')),
731
+ ),
732
+ statusError ? h('div', { className: 'ferry-meta', style: { marginTop: '6px' } }, statusError) : null,
733
+ settings.editable === false ? h('div', { className: 'ferry-notice error' }, t('settingsUnavailable')) : null,
734
+ draftPeers.length === 0
735
+ ? h('div', { className: 'ferry-empty' }, t('noPeers'))
736
+ : draftPeers.map((peer, index) => {
737
+ const state = peerState(peer);
738
+ return h(
739
+ 'div',
740
+ { className: 'ferry-peer', key: peer.id },
741
+ h(
742
+ 'div',
743
+ { className: 'ferry-peer-row' },
744
+ h('span', { className: `ferry-dot ${state.dot}` }),
745
+ h('span', { style: { fontSize: '13px', fontWeight: 600 } }, peer.name || peer.id),
746
+ h('span', { className: 'ferry-meta' }, state.text),
747
+ h('span', { className: 'ferry-spacer' }),
748
+ h(
749
+ 'button',
750
+ {
751
+ className: 'ferry-btn danger',
752
+ type: 'button',
753
+ onClick: () => setDraftPeers((current) => current.filter((_, position) => position !== index)),
754
+ },
755
+ t('remove'),
756
+ ),
757
+ ),
758
+ h(
759
+ 'div',
760
+ { className: 'ferry-peer-row' },
761
+ h(
762
+ 'label',
763
+ { className: 'ferry-field' },
764
+ h('span', null, t('name')),
765
+ h('input', {
766
+ className: 'ferry-input',
767
+ value: peer.name,
768
+ placeholder: peer.id,
769
+ onChange: (event) => updatePeer(index, { name: event.target.value }),
770
+ }),
771
+ ),
772
+ h(
773
+ 'label',
774
+ { className: 'ferry-field', style: { flex: '1 1 260px' } },
775
+ h('span', null, t('url')),
776
+ h('input', {
777
+ className: 'ferry-input wide',
778
+ value: peer.url,
779
+ placeholder: 'http://100.64.0.3:3080',
780
+ onChange: (event) => updatePeer(index, { url: event.target.value }),
781
+ }),
782
+ ),
783
+ ),
784
+ );
785
+ }),
786
+ h(
787
+ 'div',
788
+ { style: { marginTop: '14px', borderTop: '.5px solid var(--dsw-alias-border-l1)', paddingTop: '12px' } },
789
+ h('div', { className: 'ferry-section-title' }, t('incomingRoot')),
790
+ h('div', { className: 'ferry-meta', style: { margin: '4px 0 8px' } }, t('incomingRootHint')),
791
+ h('input', {
792
+ className: 'ferry-input wide',
793
+ value: incomingRoot,
794
+ placeholder: '/home/user/dsh-ferry/incoming',
795
+ onChange: (event) => setIncomingRoot(event.target.value),
796
+ }),
797
+ ),
798
+ notice
799
+ ? h(
800
+ 'div',
801
+ { className: `ferry-notice ${notice.tone === 'error' ? 'error' : 'success'}` },
802
+ h(
803
+ 'div',
804
+ { style: { display: 'flex', gap: '8px', alignItems: 'flex-start' } },
805
+ h('div', { style: { flex: '1 1 auto', whiteSpace: 'pre-wrap' } }, notice.text),
806
+ h('button', { type: 'button', className: 'ferry-btn', onClick: () => setNotice(null) }, t('dismiss')),
807
+ ),
808
+ notice.warnings?.length ? h(WarningList, { warnings: notice.warnings, t }) : null,
809
+ )
810
+ : null,
811
+ ),
812
+ h(
813
+ 'div',
814
+ { className: 'ferry-card' },
815
+ h('div', { className: 'ferry-section-title' }, t('pullSection')),
816
+ h('div', { className: 'ferry-meta', style: { margin: '4px 0 10px' } }, t('pullHint')),
817
+ h(
818
+ 'div',
819
+ { className: 'ferry-peer-row' },
820
+ h(
821
+ 'select',
822
+ {
823
+ className: 'ferry-select',
824
+ value: pullPeer,
825
+ onChange: (event) => {
826
+ setPullPeer(event.target.value);
827
+ setRemote({ peer: null, loading: false, sessions: [], error: null });
828
+ },
829
+ },
830
+ draftPeers.map((peer) =>
831
+ h(
832
+ 'option',
833
+ { key: peer.id, value: peer.id },
834
+ `${peer.name || peer.id}${statusById.get(peer.id)?.online ? '' : ` (${t('offline')})`}`,
835
+ ),
836
+ ),
837
+ ),
838
+ h(
839
+ 'button',
840
+ { className: 'ferry-btn', type: 'button', onClick: loadRemote, disabled: pullPeer === '' || remote.loading },
841
+ remote.loading ? t('checking') : t('loadRemote'),
842
+ ),
843
+ ),
844
+ remote.error ? h('div', { className: 'ferry-notice error' }, remote.error) : null,
845
+ remote.loading
846
+ ? h('div', { className: 'ferry-empty' }, t('checking'))
847
+ : remote.sessions.length === 0
848
+ ? h('div', { className: 'ferry-empty' }, t('noSessions'))
849
+ : h(
850
+ 'div',
851
+ { className: 'ferry-list' },
852
+ remote.sessions.map((session) =>
853
+ h(
854
+ 'div',
855
+ { className: 'ferry-item', key: session.sessionId },
856
+ h(
857
+ 'div',
858
+ { className: 'ferry-item-main' },
859
+ h(
860
+ 'div',
861
+ { className: 'ferry-item-title', title: session.title ?? '' },
862
+ session.title || t('unnamed'),
863
+ session.running ? h('span', { className: 'ferry-badge run' }, t('running')) : null,
864
+ ),
865
+ h(
866
+ 'div',
867
+ { className: 'ferry-meta ferry-mono' },
868
+ `${session.cwd ?? ''}${session.updatedAt ? ` · ${formatTime(session.updatedAt)}` : ''}`,
869
+ ),
870
+ h('div', { className: 'ferry-meta' }, session.sessionId),
871
+ ),
872
+ h(
873
+ 'button',
874
+ {
875
+ className: 'ferry-btn primary',
876
+ type: 'button',
877
+ disabled: pullPeer === '',
878
+ onClick: () => openPull(session),
879
+ },
880
+ t('pull'),
881
+ ),
882
+ ),
883
+ ),
884
+ ),
885
+ ),
886
+ );
887
+ }
888
+
889
+ /** Module-scoped push dialog shared by the Session menu and the overlay. */
890
+ const pushDialog = (() => {
891
+ let state = null;
892
+ const listeners = new Set();
893
+ const emit = () => {
894
+ for (const listener of listeners) listener();
895
+ };
896
+ return {
897
+ open(next) {
898
+ state = next;
899
+ emit();
900
+ },
901
+ close() {
902
+ state = null;
903
+ emit();
904
+ },
905
+ subscribe(listener) {
906
+ listeners.add(listener);
907
+ return () => {
908
+ listeners.delete(listener);
909
+ };
910
+ },
911
+ snapshot() {
912
+ return state;
913
+ },
914
+ };
915
+ })();
916
+
917
+ /* ---------- Session "..." menu: open the push dialog ---------- */
918
+
919
+ function PushMenuItem(props) {
920
+ const { sessionId, displayTitle, useMenuOpenState, openPanel, t } = props;
921
+ const [, setMenuOpen] = useMenuOpenState();
922
+ return h(
923
+ 'button',
924
+ {
925
+ type: 'button',
926
+ role: 'menuitem',
927
+ className: 'ferry-menu-item',
928
+ onClick: () => {
929
+ setMenuOpen(false);
930
+ pushDialog.open({ sessionId, displayTitle, openPanel });
931
+ },
932
+ },
933
+ h(PeerIcon, { size: 15 }),
934
+ h('span', null, t('pushTo')),
935
+ );
936
+ }
937
+
938
+ /* ---------- transfer planning: peer state shown before anything moves ---------- */
939
+
940
+ /**
941
+ * Substitute `{name}` placeholders in one locale string.
942
+ * @param {string} template - locale template.
943
+ * @param {Record<string, string|number>} values - replacements.
944
+ * @returns {string} text.
945
+ */
946
+ function fill(template, values) {
947
+ return String(template).replace(/\{(\w+)\}/g, (match, key) =>
948
+ values[key] === undefined ? match : String(values[key]),
949
+ );
950
+ }
951
+
952
+ /**
953
+ * Whether the receiving side can append to its own copy in place.
954
+ * @param {object | undefined} row - peer or local plan row.
955
+ * @returns {boolean} true when an append update is possible.
956
+ */
957
+ function appendAvailable(row) {
958
+ if (row === undefined || row === null) return false;
959
+ if (row.active === true) return false;
960
+ return row.state === 'behind' || row.state === 'same';
961
+ }
962
+
963
+ /**
964
+ * Render one state line for a peer row (`state_*`) or a local plan row
965
+ * (`local_*`).
966
+ * @param {'state'|'local'} side - whose copy the row describes.
967
+ * @param {object} row - plan row.
968
+ * @param {number | undefined} total - event count on the sending side.
969
+ * @param {(key: string) => string} t - translator.
970
+ * @returns {string} localized line.
971
+ */
972
+ function stateLine(side, row, total, t) {
973
+ const have = typeof row?.eventCount === 'number' ? row.eventCount : 0;
974
+ const add = typeof total === 'number' ? Math.max(0, total - have) : 0;
975
+ const key = row?.active === true ? `${side}_active` : `${side}_${row?.state ?? 'unknown'}`;
976
+ const template = t(key);
977
+ if (template === key) return t(`${side}_unknown`);
978
+ return fill(template, { have, add });
979
+ }
980
+
981
+ /* ---------- push dialog: reachability is checked here, not in the menu ---------- */
982
+
983
+ function PushDialogHost(props) {
984
+ const t = props.t;
985
+ const [state, setState] = useState(pushDialog.snapshot());
986
+ const [peers, setPeers] = useState(null);
987
+ const [plan, setPlan] = useState(null);
988
+ const [statusError, setStatusError] = useState(null);
989
+ const [checking, setChecking] = useState(false);
990
+ const [selected, setSelected] = useState('');
991
+ const [mode, setMode] = useState('new');
992
+ const [merge, setMerge] = useState(true);
993
+ const [busy, setBusy] = useState(false);
994
+ const [error, setError] = useState(null);
995
+ const dialogRef = React.useRef(null);
996
+
997
+ const refreshPeers = useCallback(async () => {
998
+ const current = pushDialog.snapshot();
999
+ if (current === null) return;
1000
+ setChecking(true);
1001
+ setStatusError(null);
1002
+ try {
1003
+ const payload = await rpc({ action: 'pushPlan', sessionId: current.sessionId });
1004
+ const rows = Array.isArray(payload.peers) ? payload.peers : [];
1005
+ setPlan(payload.session ?? null);
1006
+ setPeers(rows);
1007
+ setSelected((currentId) => {
1008
+ if (rows.some((row) => row.id === currentId && row.online === true)) return currentId;
1009
+ return rows.find((row) => row.online === true)?.id ?? '';
1010
+ });
1011
+ } catch (failure) {
1012
+ setPeers([]);
1013
+ setPlan(null);
1014
+ setStatusError(layoutError(failure, t));
1015
+ } finally {
1016
+ setChecking(false);
1017
+ }
1018
+ }, [t]);
1019
+
1020
+ useEffect(
1021
+ () =>
1022
+ pushDialog.subscribe(() => {
1023
+ const next = pushDialog.snapshot();
1024
+ setState(next);
1025
+ setBusy(false);
1026
+ setError(null);
1027
+ setMerge(true);
1028
+ setPeers(null);
1029
+ setPlan(null);
1030
+ setMode('new');
1031
+ setStatusError(null);
1032
+ setSelected('');
1033
+ if (next !== null) refreshPeers();
1034
+ }),
1035
+ [refreshPeers],
1036
+ );
1037
+
1038
+ const selectedPeer = (peers ?? []).find((row) => row.id === selected && row.online === true);
1039
+ const canAppend = appendAvailable(selectedPeer);
1040
+
1041
+ // Default to whatever the peer state allows; the operator can override
1042
+ // until the selected peer or the peer list changes.
1043
+ useEffect(() => {
1044
+ setMode(canAppend ? 'update' : 'new');
1045
+ }, [selected, peers]);
1046
+
1047
+ useEffect(() => {
1048
+ if (state === null) return;
1049
+ dialogRef.current?.focus();
1050
+ const onKey = (event) => {
1051
+ if (event.key === 'Escape' && !busy) pushDialog.close();
1052
+ };
1053
+ window.addEventListener('keydown', onKey);
1054
+ return () => window.removeEventListener('keydown', onKey);
1055
+ }, [state, busy]);
1056
+
1057
+ if (state === null) return null;
1058
+ const online = (peers ?? []).filter((row) => row.online === true);
1059
+ const peer = selectedPeer;
1060
+ const total = plan !== null && typeof plan.eventCount === 'number' ? plan.eventCount : undefined;
1061
+ const listPending = peers === null;
1062
+
1063
+ const submit = async () => {
1064
+ if (peer === undefined) return;
1065
+ setBusy(true);
1066
+ setError(null);
1067
+ toasts.push({
1068
+ tone: 'info',
1069
+ title: t('pushing'),
1070
+ text: `${state.displayTitle || state.sessionId} → ${peer.name || peer.id}`,
1071
+ durationMs: 0,
1072
+ });
1073
+ try {
1074
+ const result = await rpc({ action: 'push', peerId: peer.id, sessionId: state.sessionId, mode, merge });
1075
+ const summary = noticeFor(result, t);
1076
+ const warnings = (result.warnings ?? []).map((warning) => codeText(warning.code ?? warning, t));
1077
+ toasts.push({
1078
+ tone: 'success',
1079
+ title: `${t('success')} · ${peer.name || peer.id}`,
1080
+ text: `${summary.text}${warnings.length ? `\n${warnings.join('\n')}` : ''}`,
1081
+ });
1082
+ pushDialog.close();
1083
+ } catch (failure) {
1084
+ setError(layoutError(failure, t));
1085
+ toasts.push({
1086
+ tone: 'error',
1087
+ title: `${t('failed')} · ${peer.name || peer.id}`,
1088
+ text: layoutError(failure, t),
1089
+ });
1090
+ } finally {
1091
+ setBusy(false);
1092
+ }
1093
+ };
1094
+
1095
+ const modeOption = (value, label, hint, enabled) =>
1096
+ h(
1097
+ 'label',
1098
+ { key: value, className: `ferry-mode-label ${enabled ? '' : 'disabled'}` },
1099
+ h('input', {
1100
+ type: 'radio',
1101
+ name: 'dsh-ferry-push-mode',
1102
+ value,
1103
+ checked: mode === value,
1104
+ disabled: busy || !enabled,
1105
+ onChange: () => setMode(value),
1106
+ }),
1107
+ h(
1108
+ 'span',
1109
+ { className: 'ferry-mode-text' },
1110
+ h('span', null, label),
1111
+ h('span', { className: 'ferry-modal-hint' }, hint),
1112
+ ),
1113
+ );
1114
+
1115
+ let body;
1116
+ if (listPending) {
1117
+ body = h('div', { className: 'ferry-modal-hint' }, t('pushDialogChecking'));
1118
+ } else if (statusError !== null) {
1119
+ body = h('div', { className: 'ferry-modal-error' }, statusError);
1120
+ } else if (peers.length === 0) {
1121
+ body = h('div', { className: 'ferry-modal-hint' }, t('noPeers'));
1122
+ } else {
1123
+ body = h(
1124
+ React.Fragment,
1125
+ null,
1126
+ online.length === 0 ? h('div', { className: 'ferry-modal-hint' }, t('noOnlinePeer')) : null,
1127
+ h(
1128
+ 'div',
1129
+ { className: 'ferry-choice-list', role: 'radiogroup' },
1130
+ peers.map((candidate) =>
1131
+ h(
1132
+ 'label',
1133
+ {
1134
+ key: candidate.id,
1135
+ className: `ferry-choice ${selected === candidate.id ? 'selected' : ''}${
1136
+ candidate.online === true ? '' : ' offline'
1137
+ }`,
1138
+ },
1139
+ h('input', {
1140
+ type: 'radio',
1141
+ name: 'dsh-ferry-peer',
1142
+ value: candidate.id,
1143
+ checked: selected === candidate.id,
1144
+ disabled: busy || candidate.online !== true,
1145
+ onChange: () => setSelected(candidate.id),
1146
+ }),
1147
+ h(
1148
+ 'div',
1149
+ { className: 'ferry-choice-body' },
1150
+ h(
1151
+ 'div',
1152
+ { className: 'ferry-choice-row' },
1153
+ h(
1154
+ 'span',
1155
+ { className: 'ferry-choice-name', title: candidate.name || candidate.id },
1156
+ candidate.name || candidate.id,
1157
+ ),
1158
+ h('span', { className: 'ferry-spacer' }),
1159
+ h(
1160
+ 'span',
1161
+ { className: 'ferry-status' },
1162
+ h('span', { className: `ferry-dot ${candidate.online === true ? 'on' : 'off'}` }),
1163
+ h(
1164
+ 'span',
1165
+ null,
1166
+ candidate.online === true && typeof candidate.latencyMs === 'number'
1167
+ ? `${candidate.latencyMs}${t('latency')}`
1168
+ : t('offline'),
1169
+ ),
1170
+ ),
1171
+ ),
1172
+ candidate.online === true
1173
+ ? h('div', { className: 'ferry-state' }, stateLine('state', candidate, total, t))
1174
+ : null,
1175
+ ),
1176
+ ),
1177
+ ),
1178
+ ),
1179
+ );
1180
+ }
1181
+
1182
+ return h(
1183
+ React.Fragment,
1184
+ null,
1185
+ h('div', {
1186
+ className: 'ferry-modal-backdrop',
1187
+ onMouseDown: () => {
1188
+ if (!busy) pushDialog.close();
1189
+ },
1190
+ }),
1191
+ h(
1192
+ 'div',
1193
+ {
1194
+ className: 'ferry-modal',
1195
+ role: 'dialog',
1196
+ 'aria-modal': 'true',
1197
+ 'aria-labelledby': 'dsh-ferry-push-title',
1198
+ tabIndex: -1,
1199
+ ref: dialogRef,
1200
+ },
1201
+ h(
1202
+ 'div',
1203
+ { className: 'ferry-modal-head' },
1204
+ h('div', { className: 'ferry-modal-title', id: 'dsh-ferry-push-title' }, t('pushDialogTitle')),
1205
+ h(
1206
+ 'div',
1207
+ { className: 'ferry-modal-session', title: state.displayTitle || state.sessionId },
1208
+ state.displayTitle || state.sessionId,
1209
+ ),
1210
+ ),
1211
+ h(
1212
+ 'div',
1213
+ { className: 'ferry-modal-toolbar' },
1214
+ h('span', { className: 'ferry-modal-hint' }, t('pushDialogHint')),
1215
+ h(
1216
+ 'button',
1217
+ {
1218
+ type: 'button',
1219
+ className: 'ferry-btn',
1220
+ disabled: checking || busy,
1221
+ onClick: refreshPeers,
1222
+ },
1223
+ checking ? t('checking') : t('refresh'),
1224
+ ),
1225
+ ),
1226
+ body,
1227
+ peer === undefined
1228
+ ? null
1229
+ : h(
1230
+ 'div',
1231
+ { className: 'ferry-mode' },
1232
+ h('div', { className: 'ferry-modal-hint' }, t('modeTitle')),
1233
+ modeOption('new', t('modeNew'), t('modeNewHint'), true),
1234
+ modeOption(
1235
+ 'update',
1236
+ t('modeUpdate'),
1237
+ canAppend ? t('modeUpdateHint') : `${t('modeUpdateHint')} · ${t('modeUpdateUnavailable')}`,
1238
+ canAppend,
1239
+ ),
1240
+ ),
1241
+ mode === 'new'
1242
+ ? h(
1243
+ 'label',
1244
+ { className: 'ferry-check' },
1245
+ h('input', {
1246
+ type: 'checkbox',
1247
+ checked: merge,
1248
+ disabled: busy,
1249
+ onChange: (event) => setMerge(event.target.checked),
1250
+ }),
1251
+ h('span', null, t('mergeInMenu')),
1252
+ )
1253
+ : null,
1254
+ error !== null ? h('div', { className: 'ferry-modal-error' }, error) : null,
1255
+ h(
1256
+ 'div',
1257
+ { className: 'ferry-modal-foot' },
1258
+ h(
1259
+ 'button',
1260
+ {
1261
+ type: 'button',
1262
+ className: 'ferry-menu-item',
1263
+ style: { width: 'auto', fontSize: '11px', padding: '2px 0', opacity: 0.75 },
1264
+ onClick: () => {
1265
+ pushDialog.close();
1266
+ state.openPanel?.();
1267
+ },
1268
+ },
1269
+ t('managePeers'),
1270
+ ),
1271
+ h('span', { className: 'ferry-spacer' }),
1272
+ h(
1273
+ 'button',
1274
+ { type: 'button', className: 'ferry-btn', disabled: busy, onClick: () => pushDialog.close() },
1275
+ t('cancel'),
1276
+ ),
1277
+ h(
1278
+ 'button',
1279
+ { type: 'button', className: 'ferry-btn primary', disabled: busy || peer === undefined, onClick: submit },
1280
+ busy ? t('pushing') : t('confirmPush'),
1281
+ ),
1282
+ ),
1283
+ ),
1284
+ );
1285
+ }
1286
+
1287
+ /** Module-scoped pull dialog shared by the sidebar panel and the overlay. */
1288
+ const pullDialog = (() => {
1289
+ let state = null;
1290
+ const listeners = new Set();
1291
+ const emit = () => {
1292
+ for (const listener of listeners) listener();
1293
+ };
1294
+ return {
1295
+ open(next) {
1296
+ state = next;
1297
+ emit();
1298
+ },
1299
+ close() {
1300
+ state = null;
1301
+ emit();
1302
+ },
1303
+ subscribe(listener) {
1304
+ listeners.add(listener);
1305
+ return () => {
1306
+ listeners.delete(listener);
1307
+ };
1308
+ },
1309
+ snapshot() {
1310
+ return state;
1311
+ },
1312
+ };
1313
+ })();
1314
+
1315
+ /* ---------- pull dialog: inspect the local copy before downloading ---------- */
1316
+
1317
+ function PullDialogHost(props) {
1318
+ const t = props.t;
1319
+ const [state, setState] = useState(pullDialog.snapshot());
1320
+ const [plan, setPlan] = useState(null);
1321
+ const [checking, setChecking] = useState(false);
1322
+ const [statusError, setStatusError] = useState(null);
1323
+ const [mode, setMode] = useState('new');
1324
+ const [targetDir, setTargetDir] = useState('');
1325
+ const [merge, setMerge] = useState(false);
1326
+ const [busy, setBusy] = useState(false);
1327
+ const [error, setError] = useState(null);
1328
+ const dialogRef = React.useRef(null);
1329
+
1330
+ const loadPlan = useCallback(async () => {
1331
+ const current = pullDialog.snapshot();
1332
+ if (current === null) return;
1333
+ setChecking(true);
1334
+ setStatusError(null);
1335
+ try {
1336
+ const payload = await rpc({ action: 'pullPlan', peerId: current.peerId, sessionId: current.sessionId });
1337
+ setPlan(payload);
1338
+ } catch (failure) {
1339
+ setPlan(null);
1340
+ setStatusError(layoutError(failure, t));
1341
+ } finally {
1342
+ setChecking(false);
1343
+ }
1344
+ }, [t]);
1345
+
1346
+ useEffect(
1347
+ () =>
1348
+ pullDialog.subscribe(() => {
1349
+ const next = pullDialog.snapshot();
1350
+ setState(next);
1351
+ setPlan(null);
1352
+ setChecking(false);
1353
+ setError(null);
1354
+ setMode('new');
1355
+ setTargetDir('');
1356
+ setMerge(false);
1357
+ setStatusError(null);
1358
+ if (next !== null) loadPlan();
1359
+ }),
1360
+ [loadPlan],
1361
+ );
1362
+
1363
+ const canAppend = appendAvailable(plan);
1364
+ useEffect(() => {
1365
+ setMode(canAppend ? 'update' : 'new');
1366
+ }, [plan]);
1367
+
1368
+ useEffect(() => {
1369
+ if (state === null) return;
1370
+ dialogRef.current?.focus();
1371
+ const onKey = (event) => {
1372
+ if (event.key === 'Escape' && !busy) pullDialog.close();
1373
+ };
1374
+ window.addEventListener('keydown', onKey);
1375
+ return () => window.removeEventListener('keydown', onKey);
1376
+ }, [state, busy]);
1377
+
1378
+ if (state === null) return null;
1379
+ const title = state.title || state.sessionId;
1380
+
1381
+ const submit = async () => {
1382
+ setBusy(true);
1383
+ setError(null);
1384
+ toasts.push({ tone: 'info', title: t('pulling'), text: title, durationMs: 0 });
1385
+ try {
1386
+ const result = await rpc({
1387
+ action: 'pull',
1388
+ peerId: state.peerId,
1389
+ sessionId: state.sessionId,
1390
+ mode,
1391
+ ...(targetDir.trim() === '' ? {} : { targetDir: targetDir.trim() }),
1392
+ merge,
1393
+ });
1394
+ const summary = noticeFor(result, t);
1395
+ const warnings = (result.warnings ?? []).map((warning) => codeText(warning.code ?? warning, t));
1396
+ toasts.push({
1397
+ tone: 'success',
1398
+ title: `${t('success')} · ${t('pull')}`,
1399
+ text: `${summary.text}${warnings.length ? `\n${warnings.join('\n')}` : ''}`,
1400
+ });
1401
+ pullDialog.close();
1402
+ } catch (failure) {
1403
+ setError(layoutError(failure, t));
1404
+ toasts.push({ tone: 'error', title: `${t('failed')} · ${t('pull')}`, text: layoutError(failure, t) });
1405
+ } finally {
1406
+ setBusy(false);
1407
+ }
1408
+ };
1409
+
1410
+ const modeOption = (value, label, hint, enabled) =>
1411
+ h(
1412
+ 'label',
1413
+ { key: value, className: `ferry-mode-label ${enabled ? '' : 'disabled'}` },
1414
+ h('input', {
1415
+ type: 'radio',
1416
+ name: 'dsh-ferry-pull-mode',
1417
+ value,
1418
+ checked: mode === value,
1419
+ disabled: busy || !enabled,
1420
+ onChange: () => setMode(value),
1421
+ }),
1422
+ h(
1423
+ 'span',
1424
+ { className: 'ferry-mode-text' },
1425
+ h('span', null, label),
1426
+ h('span', { className: 'ferry-modal-hint' }, hint),
1427
+ ),
1428
+ );
1429
+
1430
+ const blocked = plan !== null && plan.ok === false;
1431
+ let body;
1432
+ if (plan === null) {
1433
+ body =
1434
+ statusError !== null
1435
+ ? h('div', { className: 'ferry-modal-error' }, statusError)
1436
+ : h('div', { className: 'ferry-modal-hint' }, t('pullDialogChecking'));
1437
+ } else if (blocked) {
1438
+ body = h(
1439
+ 'div',
1440
+ { className: 'ferry-modal-error' },
1441
+ plan.message ?? codeText(plan.code ?? 'preflight-failed', t),
1442
+ );
1443
+ } else {
1444
+ body = h(
1445
+ React.Fragment,
1446
+ null,
1447
+ h('div', { className: 'ferry-state' }, stateLine('local', plan, plan.session?.eventCount, t)),
1448
+ h(
1449
+ 'div',
1450
+ { className: 'ferry-mode' },
1451
+ h('div', { className: 'ferry-modal-hint' }, t('modeTitle')),
1452
+ modeOption('new', t('modeNew'), t('modeNewHint'), true),
1453
+ modeOption(
1454
+ 'update',
1455
+ t('modeUpdate'),
1456
+ canAppend ? t('modeUpdateHint') : `${t('modeUpdateHint')} · ${t('modeUpdateUnavailable')}`,
1457
+ canAppend,
1458
+ ),
1459
+ ),
1460
+ h(
1461
+ 'label',
1462
+ { className: 'ferry-mode-text', style: { gap: '4px' } },
1463
+ h('span', { className: 'ferry-modal-hint' }, t('targetDir')),
1464
+ h('input', {
1465
+ className: 'ferry-input wide',
1466
+ value: targetDir,
1467
+ placeholder: t('targetDirHint'),
1468
+ disabled: busy,
1469
+ onChange: (event) => setTargetDir(event.target.value),
1470
+ }),
1471
+ ),
1472
+ mode === 'new'
1473
+ ? h(
1474
+ 'label',
1475
+ { className: 'ferry-check' },
1476
+ h('input', {
1477
+ type: 'checkbox',
1478
+ checked: merge,
1479
+ disabled: busy,
1480
+ onChange: (event) => setMerge(event.target.checked),
1481
+ }),
1482
+ h('span', null, t('mergeInMenu')),
1483
+ )
1484
+ : null,
1485
+ );
1486
+ }
1487
+
1488
+ return h(
1489
+ React.Fragment,
1490
+ null,
1491
+ h('div', {
1492
+ className: 'ferry-modal-backdrop',
1493
+ onMouseDown: () => {
1494
+ if (!busy) pullDialog.close();
1495
+ },
1496
+ }),
1497
+ h(
1498
+ 'div',
1499
+ {
1500
+ className: 'ferry-modal',
1501
+ role: 'dialog',
1502
+ 'aria-modal': 'true',
1503
+ 'aria-labelledby': 'dsh-ferry-pull-title',
1504
+ tabIndex: -1,
1505
+ ref: dialogRef,
1506
+ },
1507
+ h(
1508
+ 'div',
1509
+ { className: 'ferry-modal-head' },
1510
+ h('div', { className: 'ferry-modal-title', id: 'dsh-ferry-pull-title' }, t('pullDialogTitle')),
1511
+ h('div', { className: 'ferry-modal-session', title }, title),
1512
+ ),
1513
+ h('div', { className: 'ferry-modal-hint' }, t('pullDialogHint')),
1514
+ body,
1515
+ error !== null ? h('div', { className: 'ferry-modal-error' }, error) : null,
1516
+ h(
1517
+ 'div',
1518
+ { className: 'ferry-modal-foot' },
1519
+ h('span', { className: 'ferry-spacer' }),
1520
+ h(
1521
+ 'button',
1522
+ { type: 'button', className: 'ferry-btn', disabled: busy, onClick: () => pullDialog.close() },
1523
+ t('cancel'),
1524
+ ),
1525
+ h(
1526
+ 'button',
1527
+ {
1528
+ type: 'button',
1529
+ className: 'ferry-btn primary',
1530
+ disabled: busy || plan === null || blocked || (mode === 'update' && !canAppend),
1531
+ onClick: submit,
1532
+ },
1533
+ busy ? t('pulling') : t('confirmPull'),
1534
+ ),
1535
+ ),
1536
+ ),
1537
+ );
1538
+ }
1539
+
1540
+ /* ---------- overlay toast host ---------- */
1541
+
1542
+ function ToastHost(props) {
1543
+ const t = props.t;
1544
+ const [items, setItems] = useState(toasts.snapshot());
1545
+ useEffect(() => toasts.subscribe(() => setItems(toasts.snapshot())), []);
1546
+ if (items.length === 0) return null;
1547
+ return h(
1548
+ 'div',
1549
+ { className: 'ferry-toasts' },
1550
+ items.map((item) =>
1551
+ h(
1552
+ 'div',
1553
+ { key: item.id, className: `ferry-toast ${item.tone}` },
1554
+ h(
1555
+ 'div',
1556
+ { style: { display: 'flex', gap: '8px', alignItems: 'flex-start' } },
1557
+ h(
1558
+ 'div',
1559
+ { style: { flex: '1 1 auto', whiteSpace: 'pre-wrap' } },
1560
+ item.title ? h('div', { className: 'ferry-toast-title' }, item.title) : null,
1561
+ item.text ? h('div', null, item.text) : null,
1562
+ ),
1563
+ h('button', { className: 'ferry-btn', type: 'button', onClick: () => toasts.dismiss(item.id) }, t('dismiss')),
1564
+ ),
1565
+ ),
1566
+ ),
1567
+ );
1568
+ }
1569
+
1570
+ /* ---------- wiring ---------- */
1571
+
1572
+ const inject = ['slots', 'locale', 'layout'];
1573
+
1574
+ function apply(ctx) {
1575
+ const ns = 'dshFerry';
1576
+ ctx.effect(() => installStyles());
1577
+ ctx.effect(() => ctx.locale.register(ns, { en, zh }));
1578
+ const t = ctx.locale.bind(ns);
1579
+ ctx.slots.inject('sidebar.panellist', () =>
1580
+ ctx.slots.register(
1581
+ {
1582
+ name: 'sidebar.panellist',
1583
+ id: 'dsh-ferry',
1584
+ order: 20,
1585
+ locale: ns,
1586
+ label: () => t('title'),
1587
+ },
1588
+ PeerIcon,
1589
+ ),
1590
+ );
1591
+ ctx.slots.inject('main', () =>
1592
+ ctx.slots.register({ name: 'main', key: 'dsh-ferry', locale: ns }, FerryPage),
1593
+ );
1594
+ ctx.slots.inject('sidebar.workspaces.session.menu.item', () =>
1595
+ ctx.slots.register(
1596
+ {
1597
+ name: 'sidebar.workspaces.session.menu.item',
1598
+ id: 'dsh-ferry-push',
1599
+ order: 500,
1600
+ locale: ns,
1601
+ inject: () => ({ openPanel: () => ctx.layout.selectPanel('dsh-ferry') }),
1602
+ },
1603
+ PushMenuItem,
1604
+ ),
1605
+ );
1606
+ ctx.slots.inject('shell.overlay', () =>
1607
+ ctx.slots.register({ name: 'shell.overlay', id: 'dsh-ferry-push-dialog', order: 90, locale: ns }, PushDialogHost),
1608
+ );
1609
+ ctx.slots.inject('shell.overlay', () =>
1610
+ ctx.slots.register({ name: 'shell.overlay', id: 'dsh-ferry-pull-dialog', order: 91, locale: ns }, PullDialogHost),
1611
+ );
1612
+ ctx.slots.inject('shell.overlay', () =>
1613
+ ctx.slots.register({ name: 'shell.overlay', id: 'dsh-ferry-toast', order: 100, locale: ns }, ToastHost),
1614
+ );
1615
+ }
1616
+
1617
+ return { inject, apply };
1618
+ },
1619
+ });