@ddtcorex/dsh-maestro-core 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +7 -7
  2. package/assets/icon.svg +4 -0
  3. package/cordis.patch.yml +0 -12
  4. package/lib/client.js +3 -1744
  5. package/lib/health-poller.js +1 -1
  6. package/lib/self-kill-guard.d.ts +25 -8
  7. package/lib/self-kill-guard.js +81 -27
  8. package/lib/types/client/config/components/BrandMark.d.ts +3 -3
  9. package/lib/types/client/index.d.ts.map +1 -1
  10. package/locale/en.json +6 -0
  11. package/package.json +9 -5
  12. package/src/client/config/components/BrandMark.tsx +3 -3
  13. package/src/client/index.tsx +0 -2
  14. package/src/host/health-poller.ts +1 -1
  15. package/src/host/self-kill-guard.ts +84 -26
  16. package/lib/sync/backup-config.d.ts +0 -55
  17. package/lib/sync/backup-config.js +0 -119
  18. package/lib/sync/backup-service.d.ts +0 -123
  19. package/lib/sync/backup-service.js +0 -486
  20. package/lib/sync/bidirectional.d.ts +0 -39
  21. package/lib/sync/bidirectional.js +0 -25
  22. package/lib/sync/cli.d.ts +0 -38
  23. package/lib/sync/cli.js +0 -528
  24. package/lib/sync/config.d.ts +0 -59
  25. package/lib/sync/config.js +0 -72
  26. package/lib/sync/fingerprint.d.ts +0 -29
  27. package/lib/sync/fingerprint.js +0 -65
  28. package/lib/sync/hashing.d.ts +0 -22
  29. package/lib/sync/hashing.js +0 -77
  30. package/lib/sync/index.d.ts +0 -6
  31. package/lib/sync/index.js +0 -619
  32. package/lib/sync/machine-id.d.ts +0 -29
  33. package/lib/sync/machine-id.js +0 -66
  34. package/lib/sync/merge.d.ts +0 -31
  35. package/lib/sync/merge.js +0 -86
  36. package/lib/sync/peer-host.d.ts +0 -22
  37. package/lib/sync/peer-host.js +0 -62
  38. package/lib/sync/process-runner.d.ts +0 -31
  39. package/lib/sync/process-runner.js +0 -161
  40. package/lib/sync/remote-agent.d.ts +0 -41
  41. package/lib/sync/remote-agent.js +0 -227
  42. package/lib/sync/remote-cache.d.ts +0 -18
  43. package/lib/sync/remote-cache.js +0 -60
  44. package/lib/sync/remote-manifest.d.ts +0 -33
  45. package/lib/sync/remote-manifest.js +0 -111
  46. package/lib/sync/s3-object-store.d.ts +0 -38
  47. package/lib/sync/s3-object-store.js +0 -126
  48. package/lib/sync/session-plan.d.ts +0 -29
  49. package/lib/sync/session-plan.js +0 -213
  50. package/lib/sync/sigv4.d.ts +0 -20
  51. package/lib/sync/sigv4.js +0 -57
  52. package/lib/sync/snapshot.d.ts +0 -16
  53. package/lib/sync/snapshot.js +0 -143
  54. package/lib/sync/ssh-mux.d.ts +0 -12
  55. package/lib/sync/ssh-mux.js +0 -48
  56. package/lib/sync/store-root.d.ts +0 -44
  57. package/lib/sync/store-root.js +0 -67
  58. package/lib/sync/sync-plan.d.ts +0 -24
  59. package/lib/sync/sync-plan.js +0 -366
  60. package/lib/sync/sync-service.d.ts +0 -181
  61. package/lib/sync/sync-service.js +0 -911
  62. package/lib/sync/sync-types.d.ts +0 -87
  63. package/lib/sync/sync-types.js +0 -1
  64. package/lib/sync/transport.d.ts +0 -75
  65. package/lib/sync/transport.js +0 -196
  66. package/lib/sync/tunnel-restore.d.ts +0 -77
  67. package/lib/sync/tunnel-restore.js +0 -142
  68. package/lib/sync/validation.d.ts +0 -12
  69. package/lib/sync/validation.js +0 -96
  70. package/lib/types/client/sync/R2SyncPanel.d.ts +0 -6
  71. package/lib/types/client/sync/R2SyncPanel.d.ts.map +0 -1
  72. package/lib/types/client/sync/SyncPanel.d.ts +0 -12
  73. package/lib/types/client/sync/SyncPanel.d.ts.map +0 -1
  74. package/lib/types/client/sync/confirm-dialog.d.ts +0 -43
  75. package/lib/types/client/sync/confirm-dialog.d.ts.map +0 -1
  76. package/lib/types/client/sync/index.d.ts +0 -10
  77. package/lib/types/client/sync/index.d.ts.map +0 -1
  78. package/lib/types/client/sync/ui.d.ts +0 -75
  79. package/lib/types/client/sync/ui.d.ts.map +0 -1
  80. package/lib/types/client/sync/use-backup.d.ts +0 -50
  81. package/lib/types/client/sync/use-backup.d.ts.map +0 -1
  82. package/lib/types/client/sync/use-sync.d.ts +0 -88
  83. package/lib/types/client/sync/use-sync.d.ts.map +0 -1
  84. package/src/client/sync/R2SyncPanel.tsx +0 -260
  85. package/src/client/sync/SyncPanel.tsx +0 -422
  86. package/src/client/sync/confirm-dialog.tsx +0 -202
  87. package/src/client/sync/index.tsx +0 -286
  88. package/src/client/sync/ui.tsx +0 -297
  89. package/src/client/sync/use-backup.ts +0 -207
  90. package/src/client/sync/use-sync.ts +0 -502
  91. package/src/host/sync/backup-config.ts +0 -158
  92. package/src/host/sync/backup-service.ts +0 -506
  93. package/src/host/sync/bidirectional.ts +0 -66
  94. package/src/host/sync/cli.ts +0 -530
  95. package/src/host/sync/config.ts +0 -96
  96. package/src/host/sync/fingerprint.ts +0 -83
  97. package/src/host/sync/hashing.ts +0 -91
  98. package/src/host/sync/index.ts +0 -697
  99. package/src/host/sync/machine-id.ts +0 -81
  100. package/src/host/sync/merge.ts +0 -99
  101. package/src/host/sync/peer-host.ts +0 -65
  102. package/src/host/sync/process-runner.ts +0 -177
  103. package/src/host/sync/remote-agent.ts +0 -223
  104. package/src/host/sync/remote-cache.ts +0 -68
  105. package/src/host/sync/remote-manifest.ts +0 -117
  106. package/src/host/sync/s3-object-store.ts +0 -144
  107. package/src/host/sync/session-plan.ts +0 -237
  108. package/src/host/sync/sigv4.ts +0 -81
  109. package/src/host/sync/snapshot.ts +0 -132
  110. package/src/host/sync/ssh-mux.ts +0 -55
  111. package/src/host/sync/store-root.ts +0 -83
  112. package/src/host/sync/sync-plan.ts +0 -366
  113. package/src/host/sync/sync-service.ts +0 -944
  114. package/src/host/sync/sync-types.ts +0 -102
  115. package/src/host/sync/transport.ts +0 -256
  116. package/src/host/sync/tunnel-restore.ts +0 -160
  117. package/src/host/sync/validation.ts +0 -104
@@ -1,422 +0,0 @@
1
- import * as React from 'react'
2
- import { useSync, type Bucket } from './use-sync.js'
3
- import { useBackupTarget } from './use-backup.js'
4
- import { R2SyncPanel } from './R2SyncPanel.js'
5
- import { ConfirmDialog, TunnelRestoreDialog } from './confirm-dialog.js'
6
- import { Button, Icon, MaestroLogo, StatTile, formatFile, formatLastSync, humanSummary } from './ui.js'
7
-
8
- /**
9
- * Maestro Sync — the complete settings card (settings.section, id maestro-sync).
10
- * Mobile-first summary + the two paged file lists (Only here / Only there);
11
- * everything lives in Settings. Keeps the confirmation-first contract: Preview
12
- * is read-only; apply exists only inside the dialog bound to the live preview
13
- * id (confirm:true).
14
- */
15
- export function SyncPanel(props: { ctx: any }): React.ReactElement {
16
- const s = useSync(props.ctx)
17
- const b = useBackupTarget(props.ctx)
18
- const [tab, setTab] = React.useState<'remote' | 'r2'>('remote')
19
- const { connection, checking, busy, error, result, status, remoteHost, remoteSource, lastSync, confirmOpen, preview, previewDirection, biPreview, biConfirmOpen, tunnelPreview, tunnelConfirmOpen, hostFieldError, actionLimit, pages } = s
20
- const st = b.status
21
-
22
- const isConnected = connection?.ok === true
23
- const isDisconnected = connection?.ok === false
24
- // Machine identity is a real precondition, not decoration: a failed verdict
25
- // (same machine on both sides, or the peer reporting our own id) means every
26
- // plan below would be computed against the wrong peer, so it gates the
27
- // actions instead of only rendering a line. `machines === null` = not checked
28
- // yet, which the SSH gate already covers.
29
- const machinesBlocked = s.machines?.ok === false
30
- const canSync = isConnected && !checking && !busy && !machinesBlocked
31
- const planAgeSecs = preview?.expiresAt ? Math.max(0, Math.round((new Date(preview.expiresAt).getTime() - Date.now()) / 1000)) : 0
32
-
33
- // SSH target form state — prefilled from the saved/env/default target once
34
- // it loads; the user edits, Saves, then explicitly Checks. Nothing probes
35
- // SSH until Check is pressed and nothing unlocks until it passes.
36
- const [hostInput, setHostInput] = React.useState('')
37
- React.useEffect(() => {
38
- if (hostInput === '' && remoteHost !== '…') setHostInput(remoteHost)
39
- }, [remoteHost, hostInput])
40
- const handleCheck = React.useCallback(async () => {
41
- const host = hostInput.trim()
42
- if (!host) return
43
- const saved = await s.saveRemoteHost(host)
44
- if (!saved.ok) return
45
- await s.checkConnection()
46
- }, [hostInput, s])
47
- // `machine` is the machine-local peer file, which outranks the shared store
48
- // because the store travels between the two machines.
49
- const sourceLabel = remoteSource === 'machine' ? 'Saved for this machine' : remoteSource === 'settings' ? 'Saved in settings' : remoteSource === 'env' ? 'From REMOTE_HOST env' : 'Built-in default'
50
-
51
- // Mobile-first progressive disclosure: buckets start collapsed on narrow
52
- // screens (<640px) so the summary + actions fit one viewport; desktop and
53
- // wider start expanded. jsdom (tests) reports 1024px → expanded.
54
- const [collapsed, setCollapsed] = React.useState<Record<Bucket, boolean>>(() => {
55
- const narrow = typeof window !== 'undefined' && typeof window.innerWidth === 'number' && window.innerWidth < 640
56
- return { localOnly: narrow, remoteOnly: narrow }
57
- })
58
-
59
- const renderBucket = (bucket: Bucket, heading: string, empty: string) => {
60
- const page = pages[bucket]
61
- const icon = bucket === 'localOnly' ? 'upload' : 'download'
62
- const open = !collapsed[bucket]
63
- return (
64
- <section data-sync-dcol="" data-bucket={bucket} data-collapsed={String(!open)} aria-label={heading}>
65
- <header data-sync-dcol-head="">
66
- <button
67
- type="button"
68
- data-sync-dcol-toggle=""
69
- aria-expanded={open}
70
- aria-label={`${open ? 'Collapse' : 'Expand'} ${heading}`}
71
- onClick={() => setCollapsed((prev) => ({ ...prev, [bucket]: !prev[bucket] }))}
72
- >
73
- <span data-sync-dcol-title="">
74
- <Icon name={open ? 'chevron-down' : 'chevron-right'} />
75
- <Icon name={icon} />
76
- {heading}
77
- </span>
78
- <span data-sync-dcol-count="">
79
- {page.files.length}/{page.total}
80
- </span>
81
- </button>
82
- </header>
83
- {open ? (
84
- isDisconnected ? (
85
- <div data-sync-empty="">Cannot check remote — SSH to {connection!.host} is not connected.</div>
86
- ) : page.files.length === 0 && !page.loaded ? (
87
- <div data-sync-loading="">Checking {heading.toLowerCase()}…</div>
88
- ) : page.files.length === 0 && !checking ? (
89
- <div data-sync-empty="">{empty}</div>
90
- ) : (
91
- page.files.map((p: string) => {
92
- const f = formatFile(p)
93
- return (
94
- <div key={p} data-sync-file="" title={p}>
95
- <span data-sync-file-icon="" style={{ color: 'var(--dsw-alias-label-tertiary)' }}>
96
- <Icon name={f.icon} />
97
- </span>
98
- <span data-sync-file-main="">
99
- <span data-sync-file-title="">{f.title}</span>
100
- <span data-sync-file-path="">{f.path}</span>
101
- </span>
102
- <span data-sync-file-meta="">{f.meta}</span>
103
- </div>
104
- )
105
- })
106
- )
107
- ) : null}
108
- {open && page.next != null ? (
109
- <footer data-sync-dcol-foot="">
110
- <Button size="sm" variant="ghost" onClick={() => void s.loadPage(bucket, page.next!)} aria-label={`Show more ${heading}`}>
111
- Show more
112
- </Button>
113
- </footer>
114
- ) : null}
115
- </section>
116
- )
117
- }
118
-
119
- // House pattern: ONE header (badge + title + live status) above the tabs.
120
- // The status line follows the active tab; per-tab headers were removed.
121
- const headerStatus =
122
- tab === 'remote'
123
- ? checking
124
- ? 'Checking connection…'
125
- : isConnected
126
- ? `${connection!.host} · ${humanSummary(status)}`
127
- : isDisconnected
128
- ? `Cannot reach ${connection!.host}`
129
- : connection === null
130
- ? 'Not checked yet — configure SSH and check'
131
- : humanSummary(status)
132
- : b.checking
133
- ? 'Checking backup configuration…'
134
- : st?.configured
135
- ? `Backup ${st.prefix}`
136
- : 'Not configured'
137
-
138
- const renderRemote = () => (
139
- <div data-sync-root="" aria-busy={busy || checking}>
140
- {/* SSH configuration — the user fills the target, Saves, then explicitly
141
- Checks. Nothing below unlocks until the check passes. */}
142
- <div data-sync-ssh="">
143
- <label data-sync-ssh-label="" htmlFor="sync-ssh-host">SSH target</label>
144
- <input
145
- id="sync-ssh-host"
146
- data-sync-ssh-input=""
147
- data-testid="sync-ssh-host"
148
- value={hostInput}
149
- onChange={(e) => { setHostInput(e.target.value); void s.setHostFieldError?.(null) }}
150
- placeholder="user@host"
151
- autoComplete="off"
152
- autoCapitalize="off"
153
- spellCheck={false}
154
- disabled={checking || busy}
155
- aria-describedby="sync-ssh-src"
156
- aria-invalid={hostFieldError ? 'true' : undefined}
157
- />
158
- {hostFieldError ? (
159
- <span data-sync-field-error="" role="alert" data-testid="sync-ssh-host-error" style={{ fontSize: 12, lineHeight: '16px', color: 'var(--dsw-alias-state-error-primary)', overflowWrap: 'anywhere' }}>
160
- {hostFieldError}
161
- </span>
162
- ) : null}
163
- <div data-sync-ssh-row="">
164
- <Button variant="outline" data-testid="sync-save-host" disabled={checking || busy || hostInput.trim().length === 0} onClick={() => void s.saveRemoteHost(hostInput.trim())}>
165
- Save
166
- </Button>
167
- <Button variant="primary" data-testid="sync-check-connection" disabled={checking || busy || hostInput.trim().length === 0} busy={checking} onClick={() => void handleCheck()}>
168
- {checking ? 'Checking…' : 'Check connection'}
169
- </Button>
170
- </div>
171
- <span id="sync-ssh-src" data-sync-ssh-src="">{sourceLabel}</span>
172
- </div>
173
-
174
- {/* Connection banner (Refresh lives here so the header stays badge+title+status) */}
175
- <div data-sync-conn="" data-state={isDisconnected ? 'bad' : checking ? 'checking' : 'ok'} data-testid="sync-connection">
176
- <span data-sync-conn-dot="" />
177
- <span data-sync-conn-main="">
178
- {checking ? (
179
- <span data-sync-conn-title="">Checking SSH to {remoteHost}…</span>
180
- ) : isConnected ? (
181
- <>
182
- <span data-sync-conn-title="">
183
- Connected to {connection!.host}
184
- {connection!.latencyMs != null ? ` · ${connection!.latencyMs}ms` : ''} · SSH ready
185
- </span>
186
- <span data-sync-conn-desc="">Use Preview to see the exact plan — Apply always requires confirmation.</span>
187
- </>
188
- ) : isDisconnected ? (
189
- <>
190
- <span data-sync-conn-title="">Cannot reach {connection!.host} — sync is paused</span>
191
- <span data-sync-conn-desc="">{connection!.error ? String(connection!.error).slice(0, 220) : 'SSH failed. Check that the host is reachable and your key is loaded.'}</span>
192
- </>
193
- ) : (
194
- <span data-sync-conn-title="">Not checked yet — configure SSH above, then Check connection.</span>
195
- )}
196
- </span>
197
- <Button variant="ghost" size="sm" icon="refresh" busy={checking} disabled={!isConnected} onClick={() => void s.loadStatus()} aria-label="Refresh connection status" style={{ marginLeft: 'auto', flex: 'none', alignSelf: 'center' }}>
198
- {checking ? 'Checking' : 'Refresh'}
199
- </Button>
200
- </div>
201
-
202
- {isConnected ? (
203
- <>
204
- {/* Identity fields — host + last sync */}
205
- <div data-sync-fields="">
206
- <div data-sync-field="">
207
- <span data-sync-field-label="">Remote host</span>
208
- <span data-sync-field-value="" data-testid="sync-remote-host">{remoteHost}</span>
209
- </div>
210
- <div data-sync-field="">
211
- {/* Browser-local, client-only (localStorage). A CLI apply on this
212
- machine never updates it, so the label says whose history this is
213
- instead of implying it is the canonical sync state. */}
214
- <span data-sync-field-label="">Last sync (this browser)</span>
215
- <span data-sync-field-value="" data-testid="sync-last-sync">{formatLastSync(lastSync)}</span>
216
- </div>
217
- {s.machines ? (
218
- <div data-sync-field="">
219
- <span data-sync-field-label="">Machines</span>
220
- <span data-sync-field-value="" data-testid="sync-machines">{s.machines.localId ?? '?'} ↔ {s.machines.remoteId ?? '?'}</span>
221
- {s.machines.reason ? (
222
- <span data-sync-field-note="" data-testid="sync-machines-error" style={{ fontSize: 12, lineHeight: '16px', color: 'var(--dsw-alias-label-secondary)', overflowWrap: 'anywhere' }}>{s.machines.reason}</span>
223
- ) : null}
224
- <Button variant="outline" size="sm" data-testid="sync-tunnel-restore" disabled={checking || busy} onClick={() => void s.handleTunnelRestorePreview()}>
225
- Restore tunnel
226
- </Button>
227
- </div>
228
- ) : null}
229
- </div>
230
-
231
- {/* Stats */}
232
- <div data-sync-stats="">
233
- <StatTile
234
- icon="upload"
235
- value={status ? String(status.localOnly ?? 0) : '—'}
236
- label="Only here"
237
- hint={status?.localOnly ? 'Pushed on Preview Push' : 'Nothing here'}
238
- ariaLabel="Files only on this machine"
239
- />
240
- <StatTile
241
- icon="swap"
242
- value={status ? String(status.both ?? 0) : '—'}
243
- label="On both"
244
- hint="Content compared in Preview"
245
- ariaLabel="Files on both machines"
246
- />
247
- <StatTile
248
- icon="download"
249
- value={status ? String(status.remoteOnly ?? 0) : '—'}
250
- label="Only there"
251
- hint={status?.remoteOnly ? 'Pulled on Preview Pull' : 'Nothing there'}
252
- ariaLabel="Files only on the other machine"
253
- />
254
- </div>
255
-
256
- {/* Primary actions — sticky bottom bar on mobile (thumb reach) */}
257
- {machinesBlocked ? (
258
- <div data-sync-notice="" data-tone="bad" role="status" data-testid="sync-machines-gate">
259
- <span data-sync-notice-icon="">
260
- <Icon name="alert" />
261
- </span>
262
- <span data-sync-notice-main="">
263
- <span data-sync-notice-title="">Sync is locked — machine identity check failed</span>
264
- <span data-sync-notice-desc="">
265
- {s.machines?.reason ?? 'The two sides do not look like two distinct machines.'} Fix the SSH target so it points at the OTHER machine, then Check connection again.
266
- </span>
267
- </span>
268
- </div>
269
- ) : null}
270
- <div data-sync-actions="" data-sync-actions-bar="">
271
- <Button variant="primary" icon="swap" disabled={!canSync} data-testid="sync-both-ways" onClick={() => void s.handleBidirectionalPreview()}>
272
- {busy ? 'Working…' : 'Sync both ways'}
273
- </Button>
274
- <Button variant="outline" icon="download" disabled={!canSync} data-testid="sync-preview-pull" onClick={() => void s.handlePreview('pull')}>
275
- {busy ? 'Working…' : 'Preview Pull'}
276
- </Button>
277
- <Button variant="outline" icon="upload" disabled={!canSync} data-testid="sync-preview-push" onClick={() => void s.handlePreview('push')}>
278
- {busy ? 'Working…' : 'Preview Push'}
279
- </Button>
280
- </div>
281
-
282
- {/* Preview progress — shows the session file currently being counted */}
283
- {busy && s.progress ? (
284
- <div data-sync-progress="" role="status" aria-live="polite" data-testid="sync-progress">
285
- <span data-sync-progress-meta="">
286
- {s.progress.phase === 'hashing'
287
- ? `Reviewing sessions ${s.progress.current}/${s.progress.total}${s.progress.file ? ` — ${formatFile(s.progress.file).path}` : ''}`
288
- : s.progress.phase === 'staging'
289
- ? `Staging files ${s.progress.current}/${s.progress.total}`
290
- : s.progress.phase === 'planning'
291
- ? 'Building the exact plan…'
292
- : 'Listing both machines…'}
293
- </span>
294
- <span data-sync-progress-track="" role="progressbar" aria-valuemin={0} aria-valuemax={s.progress.total} aria-valuenow={s.progress.current}>
295
- <span data-sync-progress-fill="" style={{ width: `${s.progress.total > 0 ? Math.min(100, Math.round((s.progress.current / s.progress.total) * 100)) : 0}%` }} />
296
- </span>
297
- </div>
298
- ) : null}
299
-
300
- {/* Results + errors (announced) */}
301
- {result ? (
302
- <div data-sync-notice="" data-tone={result.ok ? 'ok' : 'bad'} role="status" aria-live="polite">
303
- <span data-sync-notice-icon="">
304
- <Icon name={result.ok ? 'check' : 'alert'} />
305
- </span>
306
- <span data-sync-notice-main="">
307
- <span data-sync-notice-title="">{result.ok ? 'Apply complete' : 'Apply failed'}</span>
308
- <span data-sync-notice-desc="">{result.text}</span>
309
- </span>
310
- </div>
311
- ) : null}
312
- {/* Results (announced) — inside the gate: only a passed check produces one */}
313
-
314
- {/* File list sections — everything stays inside Settings */}
315
- <div data-sync-filetables="">
316
- {renderBucket('remoteOnly', 'Coming from the other machine', 'Nothing to pull — the other machine has no eligible files here.')}
317
- {renderBucket('localOnly', 'Ready to send', 'Nothing to push — this machine has no eligible files here.')}
318
- </div>
319
- </>
320
- ) : (
321
- <div data-sync-notice="" data-tone="ok" role="status">
322
- <span data-sync-notice-icon="">
323
- <Icon name={isDisconnected ? 'alert' : 'clock'} />
324
- </span>
325
- <span data-sync-notice-main="">
326
- <span data-sync-notice-title="">{isDisconnected ? 'Connection failed' : 'Preview and file lists are locked'}</span>
327
- <span data-sync-notice-desc="">
328
- {isDisconnected
329
- ? 'Fix the SSH target above and check again.'
330
- : 'Configure the SSH target above, then Check connection — everything below unlocks after a successful check.'}
331
- </span>
332
- </span>
333
- </div>
334
- )}
335
-
336
- {error ? (
337
- <div data-sync-notice="" data-tone="bad" role="alert">
338
- <span data-sync-notice-icon="">
339
- <Icon name="alert" />
340
- </span>
341
- <span data-sync-notice-main="">
342
- <span data-sync-notice-title="">Something went wrong</span>
343
- <span data-sync-notice-desc="">{error}</span>
344
- </span>
345
- </div>
346
- ) : null}
347
-
348
- {/* Confirmation dialog — the only place apply exists */}
349
- {confirmOpen && preview ? (
350
- <ConfirmDialog
351
- preview={preview}
352
- previewDirection={previewDirection}
353
- remoteHost={remoteHost}
354
- busy={busy}
355
- actionLimit={actionLimit}
356
- planAgeSecs={planAgeSecs}
357
- onShowMore={() => s.setActionLimit((n: number) => n + 5)}
358
- onCancel={s.cancelDialog}
359
- onApply={() => void s.handleApply()}
360
- />
361
- ) : null}
362
-
363
- {/* Bidirectional dialog — exact push plan plus the projected pull plan */}
364
- {biConfirmOpen && biPreview ? (
365
- <ConfirmDialog
366
- preview={biPreview.push}
367
- previewDirection="push"
368
- remoteHost={remoteHost}
369
- busy={busy}
370
- actionLimit={actionLimit}
371
- planAgeSecs={Math.max(0, Math.round((new Date(biPreview.expiresAt).getTime() - Date.now()) / 1000))}
372
- onShowMore={() => s.setActionLimit((n: number) => n + 5)}
373
- onCancel={s.cancelBidirectionalDialog}
374
- onApply={() => void s.handleBidirectionalApply()}
375
- title={`Apply both ways — preview ${String(biPreview.previewId ?? '').slice(0, 8)}`}
376
- projectedTitle="Pull plan (projected)"
377
- projectedPreview={biPreview.pullProjected}
378
- projectedNote="Projected — recomputed exact after the push lands."
379
- applyLabel="Apply both ways"
380
- />
381
- ) : null}
382
-
383
- {/* Tunnel-restore dialog — the only place the domains.tunnel write exists */}
384
- {tunnelConfirmOpen && tunnelPreview ? (
385
- <TunnelRestoreDialog
386
- preview={tunnelPreview}
387
- busy={busy}
388
- onCancel={s.cancelTunnelRestore}
389
- onConfirm={() => void s.confirmTunnelRestore()}
390
- />
391
- ) : null}
392
-
393
- <div data-sync-muted="" style={{ textAlign: 'center' }}>
394
- Notes and sessions are merged — never overwritten. Apply always requires confirmation.
395
- </div>
396
- </div>
397
- )
398
-
399
- return (
400
- <div data-sync-shell="">
401
- {/* Header — shared Maestro badge + title + live status line (same as Maestro Jobs) */}
402
- <div style={{ display: 'flex', gap: 10, alignItems: 'flex-start', padding: '2px 2px 4px' }}>
403
- <MaestroLogo />
404
- <div style={{ display: 'flex', flexDirection: 'column', minWidth: 0, gap: 2 }}>
405
- <div style={{ fontSize: 15, fontWeight: 600, lineHeight: '22px', color: 'var(--dsw-alias-label-primary)' }}>Maestro Sync</div>
406
- <span style={{ fontSize: 12, lineHeight: '16px', color: 'var(--dsw-alias-label-secondary)', overflowWrap: 'anywhere' }}>
407
- {headerStatus}
408
- </span>
409
- </div>
410
- </div>
411
- <div data-sync-tabs="" role="tablist" aria-label="Maestro Sync modes">
412
- <button data-testid="sync-tab-remote" role="tab" aria-selected={tab === 'remote'} data-sync-tab="" onClick={() => setTab('remote')}>
413
- Remote Sync
414
- </button>
415
- <button data-testid="sync-tab-r2" role="tab" aria-selected={tab === 'r2'} data-sync-tab="" onClick={() => setTab('r2')}>
416
- R2 Sync
417
- </button>
418
- </div>
419
- {tab === 'remote' ? renderRemote() : <R2SyncPanel b={b} />}
420
- </div>
421
- )
422
- }
@@ -1,202 +0,0 @@
1
- import * as React from 'react'
2
- import { Button, Icon, actionLabel, actionTone, formatFile } from './ui.js'
3
-
4
- /** Renders a tunnel domain object as a stable, comparable one-liner. */
5
- function tunnelLine(v: any): string {
6
- if (v === null || v === undefined) return 'not set'
7
- if (typeof v !== 'object') return String(v)
8
- const keys = Object.keys(v).sort()
9
- if (keys.length === 0) return 'not set'
10
- return keys.map((k) => `${k}=${String((v as any)[k])}`).join(' · ')
11
- }
12
-
13
- /**
14
- * Tunnel-restore confirmation — the only place a restore can be issued.
15
- *
16
- * The restore rewrites `domains.tunnel` in the shared store, the same data
17
- * class whose uncoordinated write took a machine's tunnel down (HTTP 530) on
18
- * 2026-08-26/2026-09-09, so it follows the preview → single-use id → dialog
19
- * contract every other mutation in this panel already uses. The preview body is
20
- * read-only and shows exactly which fields change.
21
- */
22
- export function TunnelRestoreDialog(props: {
23
- preview: any
24
- busy: boolean
25
- onCancel: () => void
26
- onConfirm: () => void
27
- }): React.ReactElement {
28
- const { preview, busy, onCancel, onConfirm } = props
29
- const expiresIn = preview?.expiresAt ? Math.max(0, Math.round((new Date(preview.expiresAt).getTime() - Date.now()) / 1000)) : 0
30
- const changed = preview?.changed === true
31
- return (
32
- <div data-sync-dialog-overlay="" data-testid="sync-tunnel-dialog-overlay">
33
- <div role="dialog" aria-modal="true" aria-labelledby="sync-tunnel-dialog-title" data-sync-dialog="" data-testid="sync-tunnel-dialog">
34
- <div data-sync-dialog-top="">
35
- <div data-sync-dialog-heading="">
36
- <div id="sync-tunnel-dialog-title" data-sync-dialog-title="">Restore tunnel — profile {preview?.profile ?? '?'}</div>
37
- <div data-sync-dialog-desc="">
38
- Rewrites <code>domains.tunnel</code> in the shared settings store on this machine · preview expires in {expiresIn}s
39
- </div>
40
- </div>
41
- <button type="button" data-sync-dialog-close="" aria-label="Cancel" onClick={onCancel} disabled={busy}>
42
- <Icon name="close" />
43
- </button>
44
- </div>
45
-
46
- <div data-sync-planlist="" data-testid="sync-tunnel-plan">
47
- <div data-action-row="" data-sync-planrow="">
48
- <span data-sync-planfile="">
49
- <span data-sync-planfile-title="">Current value</span>
50
- <span data-sync-planfile-path="" data-testid="sync-tunnel-current">{tunnelLine(preview?.current)}</span>
51
- </span>
52
- </div>
53
- <div data-action-row="" data-sync-planrow="">
54
- <span data-sync-planfile="">
55
- <span data-sync-planfile-title="">Restored from profile</span>
56
- <span data-sync-planfile-path="" data-testid="sync-tunnel-desired">{tunnelLine(preview?.desired)}</span>
57
- </span>
58
- </div>
59
- <div data-sync-planlist-note="">
60
- {changed
61
- ? 'Only domains.tunnel changes — every other domain (jobs, notifier, guard, …) is left untouched.'
62
- : 'The stored value already matches this profile — confirming is a no-op.'}
63
- </div>
64
- </div>
65
-
66
- <div data-sync-dialog-actions="">
67
- <Button variant="outline" onClick={onCancel} disabled={busy} aria-label="Cancel">Cancel</Button>
68
- <Button variant="primary" data-testid="sync-tunnel-confirm" onClick={onConfirm} disabled={busy} busy={busy} aria-label="Restore tunnel">
69
- {busy ? 'Restoring…' : 'Restore tunnel'}
70
- </Button>
71
- </div>
72
- </div>
73
- </div>
74
- )
75
- }
76
-
77
- /**
78
- * Confirmation-first apply dialog — the ONLY place an apply can be issued.
79
- * Bound to a live preview id; Escape cancels; actions list paginates.
80
- * Bottom-sheet on mobile, centered card on ≥640px.
81
- */
82
- export function ConfirmDialog(props: {
83
- preview: any
84
- previewDirection: 'pull' | 'push'
85
- remoteHost: string
86
- busy: boolean
87
- actionLimit: number
88
- planAgeSecs: number
89
- onShowMore: () => void
90
- onCancel: () => void
91
- onApply: () => void
92
- /** R2 flows: title + target label override; defaults keep the remote-sync wording. */
93
- kind?: 'sync' | 'backup' | 'restore' | 'gc'
94
- title?: string
95
- targetLabel?: string
96
- /** Bidirectional flow: second plan section rendered below the primary one. */
97
- projectedTitle?: string
98
- projectedPreview?: any
99
- projectedNote?: string
100
- /** Bidirectional flow: apply button label override. */
101
- applyLabel?: string
102
- }): React.ReactElement {
103
- const { preview, previewDirection, remoteHost, busy, actionLimit, planAgeSecs, onShowMore, onCancel, onApply, title, targetLabel, projectedTitle, projectedPreview, projectedNote, applyLabel } = props
104
- const actions = (preview?.actions ?? []).slice(0, actionLimit)
105
- const hasMore = (preview?.actions?.length ?? 0) > actionLimit
106
- const summary = preview?.summary ?? {}
107
- const sessionCounts = preview?.sessionCounts
108
- const previewId = String(preview?.previewId ?? '').slice(0, 8)
109
-
110
- const sessionLine = sessionCounts
111
- ? `${sessionCounts.added ?? 0} added · ${sessionCounts.updated ?? 0} updated · ${sessionCounts.deleted ?? 0} deleted · ${sessionCounts.identical ?? 0} identical`
112
- : null
113
-
114
- return (
115
- <div data-sync-dialog-overlay="" data-testid="sync-dialog-overlay">
116
- <div role="dialog" aria-modal="true" aria-labelledby="sync-dialog-title" data-sync-dialog="" data-testid="sync-dialog">
117
- <div data-sync-dialog-top="">
118
- <div data-sync-dialog-heading="">
119
- <div id="sync-dialog-title" data-sync-dialog-title="">
120
- {title ?? `Apply ${previewDirection} — preview ${previewId}`}
121
- </div>
122
- <div data-sync-dialog-desc="">
123
- {targetLabel ?? remoteHost} · plan {planAgeSecs}s before expiry · {summary.copied ?? 0} copy · {summary.merged ?? 0} merge (+{summary.added ?? 0} added) · {summary.skipped ?? 0} skip · {summary.conflicts ?? 0} conflict
124
- </div>
125
- </div>
126
- <button type="button" data-sync-dialog-close="" aria-label="Cancel" onClick={onCancel} disabled={busy}>
127
- <Icon name="close" />
128
- </button>
129
- </div>
130
-
131
- <div data-sync-planlist="">
132
- {sessionLine ? (
133
- <div data-sync-sessioncounts="" data-testid="sync-session-counts">
134
- <span data-sync-sessioncounts-lbl="">
135
- <Icon name="swap" />
136
- Sessions (counted by checksum)
137
- </span>
138
- <span data-sync-sessioncounts-line="">{sessionLine}</span>
139
- </div>
140
- ) : null}
141
- {actions.length === 0 ? (
142
- <div data-sync-empty="">Nothing to do — every file is already in sync.</div>
143
- ) : (
144
- actions.map((a: any) => {
145
- const f = formatFile(a.path)
146
- return (
147
- <div key={a.path} data-action-row="" title={a.path} data-sync-planrow="">
148
- <span data-sync-planfile-icon="" style={{ color: 'var(--dsw-alias-label-tertiary)' }}>
149
- <Icon name={f.icon} />
150
- </span>
151
- <span data-sync-planfile="">
152
- <span data-sync-planfile-title="">{f.title} — {actionLabel(a)}</span>
153
- <span data-sync-planfile-path="">{a.path}</span>
154
- </span>
155
- <span data-sync-planrow-meta="">
156
- <span data-sync-badge="" data-tone={actionTone(a)}>{a.reason ?? a.action}</span>
157
- </span>
158
- </div>
159
- )
160
- })
161
- )}
162
- {hasMore ? (
163
- <div data-sync-planmore="">
164
- <Button size="sm" variant="ghost" onClick={onShowMore} aria-label="Show more actions">Show more</Button>
165
- </div>
166
- ) : null}
167
- </div>
168
-
169
- {projectedPreview ? (
170
- <div data-sync-planlist="" data-testid="sync-projected-plan">
171
- <div data-sync-planlist-title="">{projectedTitle ?? 'Pull plan (projected)'}</div>
172
- {projectedNote ? <div data-sync-planlist-note="">{projectedNote}</div> : null}
173
- {((projectedPreview?.actions ?? []) as any[]).slice(0, actionLimit).map((a: any) => {
174
- const f = formatFile(a.path)
175
- return (
176
- <div key={a.path} data-action-row="" title={a.path} data-sync-planrow="">
177
- <span data-sync-planfile-icon="" style={{ color: 'var(--dsw-alias-label-tertiary)' }}>
178
- <Icon name={f.icon} />
179
- </span>
180
- <span data-sync-planfile="">
181
- <span data-sync-planfile-title="">{f.title} — {actionLabel(a)}</span>
182
- <span data-sync-planfile-path="">{a.path}</span>
183
- </span>
184
- <span data-sync-planrow-meta="">
185
- <span data-sync-badge="" data-tone={actionTone(a)}>{a.reason ?? a.action}</span>
186
- </span>
187
- </div>
188
- )
189
- })}
190
- </div>
191
- ) : null}
192
-
193
- <div data-sync-dialog-actions="">
194
- <Button variant="outline" onClick={onCancel} disabled={busy} aria-label="Cancel">Cancel</Button>
195
- <Button variant="primary" onClick={onApply} disabled={busy} busy={busy} aria-label={applyLabel ?? `Apply ${previewDirection}`}>
196
- {busy ? 'Applying…' : (applyLabel ?? `Apply ${previewDirection} — ${summary.copied ?? 0} copy, ${summary.merged ?? 0} merge`)}
197
- </Button>
198
- </div>
199
- </div>
200
- </div>
201
- )
202
- }