@ddtcorex/dsh-maestro-core 0.10.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 (285) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -0
  3. package/cordis.patch.yml +43 -0
  4. package/lib/bin.d.ts +2 -0
  5. package/lib/bin.js +3 -0
  6. package/lib/boot-guard.d.ts +33 -0
  7. package/lib/boot-guard.js +68 -0
  8. package/lib/boot-lock.d.ts +56 -0
  9. package/lib/boot-lock.js +155 -0
  10. package/lib/cli.d.ts +31 -0
  11. package/lib/cli.js +336 -0
  12. package/lib/client.js +2901 -0
  13. package/lib/config/index.d.ts +34 -0
  14. package/lib/config/index.js +62 -0
  15. package/lib/config/service.d.ts +18 -0
  16. package/lib/config/service.js +28 -0
  17. package/lib/config.d.ts +1 -0
  18. package/lib/config.js +19 -0
  19. package/lib/daemon-freshness.d.ts +48 -0
  20. package/lib/daemon-freshness.js +122 -0
  21. package/lib/debug-agent.d.ts +17 -0
  22. package/lib/debug-agent.js +144 -0
  23. package/lib/dsh-session.d.ts +26 -0
  24. package/lib/dsh-session.js +45 -0
  25. package/lib/guard/config.d.ts +82 -0
  26. package/lib/guard/config.js +211 -0
  27. package/lib/guard/decide.d.ts +30 -0
  28. package/lib/guard/decide.js +38 -0
  29. package/lib/guard/full-scan-tool.d.ts +6 -0
  30. package/lib/guard/full-scan-tool.js +65 -0
  31. package/lib/guard/index.d.ts +85 -0
  32. package/lib/guard/index.js +254 -0
  33. package/lib/guard/journal.d.ts +146 -0
  34. package/lib/guard/journal.js +398 -0
  35. package/lib/guard/migrate.d.ts +15 -0
  36. package/lib/guard/migrate.js +42 -0
  37. package/lib/guard/parse.d.ts +193 -0
  38. package/lib/guard/parse.js +1103 -0
  39. package/lib/guard/paths.d.ts +104 -0
  40. package/lib/guard/paths.js +254 -0
  41. package/lib/guard/permission-policy.d.ts +10 -0
  42. package/lib/guard/permission-policy.js +21 -0
  43. package/lib/guard/redact.d.ts +25 -0
  44. package/lib/guard/redact.js +52 -0
  45. package/lib/guard/rules.d.ts +65 -0
  46. package/lib/guard/rules.js +832 -0
  47. package/lib/guard/status-tool.d.ts +54 -0
  48. package/lib/guard/status-tool.js +195 -0
  49. package/lib/guard/tiers.d.ts +2 -0
  50. package/lib/guard/tiers.js +1 -0
  51. package/lib/guard/validators.d.ts +4 -0
  52. package/lib/guard/validators.js +45 -0
  53. package/lib/health-poller.d.ts +90 -0
  54. package/lib/health-poller.js +430 -0
  55. package/lib/index.d.ts +7 -0
  56. package/lib/index.js +7 -0
  57. package/lib/intents.d.ts +32 -0
  58. package/lib/intents.js +49 -0
  59. package/lib/notifier.d.ts +12 -0
  60. package/lib/notifier.js +62 -0
  61. package/lib/paths.d.ts +13 -0
  62. package/lib/paths.js +70 -0
  63. package/lib/plugin.d.ts +250 -0
  64. package/lib/plugin.js +1126 -0
  65. package/lib/preset.d.ts +73 -0
  66. package/lib/preset.js +158 -0
  67. package/lib/report.d.ts +11 -0
  68. package/lib/report.js +58 -0
  69. package/lib/restart-exec.d.ts +35 -0
  70. package/lib/restart-exec.js +60 -0
  71. package/lib/restart-guards.d.ts +39 -0
  72. package/lib/restart-guards.js +150 -0
  73. package/lib/restart-tool.d.ts +124 -0
  74. package/lib/restart-tool.js +539 -0
  75. package/lib/restart-web.d.ts +26 -0
  76. package/lib/restart-web.js +58 -0
  77. package/lib/resume-log.d.ts +24 -0
  78. package/lib/resume-log.js +18 -0
  79. package/lib/resume-tools.d.ts +131 -0
  80. package/lib/resume-tools.js +337 -0
  81. package/lib/resume.d.ts +33 -0
  82. package/lib/resume.js +221 -0
  83. package/lib/scan.d.ts +20 -0
  84. package/lib/scan.js +71 -0
  85. package/lib/self-kill-guard.d.ts +81 -0
  86. package/lib/self-kill-guard.js +208 -0
  87. package/lib/session-health.d.ts +89 -0
  88. package/lib/session-health.js +274 -0
  89. package/lib/session-log-file.d.ts +22 -0
  90. package/lib/session-log-file.js +74 -0
  91. package/lib/skill-provider.d.ts +6 -0
  92. package/lib/skill-provider.js +73 -0
  93. package/lib/snapshot.d.ts +59 -0
  94. package/lib/snapshot.js +358 -0
  95. package/lib/source.d.ts +19 -0
  96. package/lib/source.js +19 -0
  97. package/lib/store/index.d.ts +42 -0
  98. package/lib/store/index.js +340 -0
  99. package/lib/store/legacy.d.ts +17 -0
  100. package/lib/store/legacy.js +85 -0
  101. package/lib/supervisor.d.ts +119 -0
  102. package/lib/supervisor.js +741 -0
  103. package/lib/sync/backup-config.d.ts +55 -0
  104. package/lib/sync/backup-config.js +119 -0
  105. package/lib/sync/backup-service.d.ts +110 -0
  106. package/lib/sync/backup-service.js +440 -0
  107. package/lib/sync/bidirectional.d.ts +39 -0
  108. package/lib/sync/bidirectional.js +25 -0
  109. package/lib/sync/cli.d.ts +38 -0
  110. package/lib/sync/cli.js +536 -0
  111. package/lib/sync/config.d.ts +77 -0
  112. package/lib/sync/config.js +90 -0
  113. package/lib/sync/fingerprint.d.ts +29 -0
  114. package/lib/sync/fingerprint.js +65 -0
  115. package/lib/sync/hashing.d.ts +9 -0
  116. package/lib/sync/hashing.js +47 -0
  117. package/lib/sync/index.d.ts +6 -0
  118. package/lib/sync/index.js +634 -0
  119. package/lib/sync/machine-id.d.ts +29 -0
  120. package/lib/sync/machine-id.js +66 -0
  121. package/lib/sync/merge.d.ts +33 -0
  122. package/lib/sync/merge.js +88 -0
  123. package/lib/sync/peer-host.d.ts +22 -0
  124. package/lib/sync/peer-host.js +62 -0
  125. package/lib/sync/process-runner.d.ts +31 -0
  126. package/lib/sync/process-runner.js +161 -0
  127. package/lib/sync/remote-agent.d.ts +42 -0
  128. package/lib/sync/remote-agent.js +217 -0
  129. package/lib/sync/remote-cache.d.ts +18 -0
  130. package/lib/sync/remote-cache.js +60 -0
  131. package/lib/sync/remote-manifest.d.ts +8 -0
  132. package/lib/sync/remote-manifest.js +64 -0
  133. package/lib/sync/s3-object-store.d.ts +38 -0
  134. package/lib/sync/s3-object-store.js +126 -0
  135. package/lib/sync/session-merge.d.ts +18 -0
  136. package/lib/sync/session-merge.js +191 -0
  137. package/lib/sync/session-plan.d.ts +29 -0
  138. package/lib/sync/session-plan.js +213 -0
  139. package/lib/sync/sigv4.d.ts +20 -0
  140. package/lib/sync/sigv4.js +57 -0
  141. package/lib/sync/snapshot.d.ts +21 -0
  142. package/lib/sync/snapshot.js +176 -0
  143. package/lib/sync/ssh-mux.d.ts +12 -0
  144. package/lib/sync/ssh-mux.js +48 -0
  145. package/lib/sync/sync-plan.d.ts +24 -0
  146. package/lib/sync/sync-plan.js +366 -0
  147. package/lib/sync/sync-service.d.ts +177 -0
  148. package/lib/sync/sync-service.js +819 -0
  149. package/lib/sync/sync-types.d.ts +87 -0
  150. package/lib/sync/sync-types.js +1 -0
  151. package/lib/sync/transport.d.ts +75 -0
  152. package/lib/sync/transport.js +200 -0
  153. package/lib/sync/tunnel-restore.d.ts +77 -0
  154. package/lib/sync/tunnel-restore.js +142 -0
  155. package/lib/sync/validation.d.ts +10 -0
  156. package/lib/sync/validation.js +83 -0
  157. package/lib/tool-view.d.ts +62 -0
  158. package/lib/tool-view.js +70 -0
  159. package/lib/types/client/auto-reload.d.ts +8 -0
  160. package/lib/types/client/auto-reload.d.ts.map +1 -0
  161. package/lib/types/client/config/MaestroSettings.d.ts +25 -0
  162. package/lib/types/client/config/MaestroSettings.d.ts.map +1 -0
  163. package/lib/types/client/config/components/BrandMark.d.ts +50 -0
  164. package/lib/types/client/config/components/BrandMark.d.ts.map +1 -0
  165. package/lib/types/client/config/guard-view.d.ts +83 -0
  166. package/lib/types/client/config/guard-view.d.ts.map +1 -0
  167. package/lib/types/client/config/index.d.ts +20 -0
  168. package/lib/types/client/config/index.d.ts.map +1 -0
  169. package/lib/types/client/config/maestro-mark.d.ts +29 -0
  170. package/lib/types/client/config/maestro-mark.d.ts.map +1 -0
  171. package/lib/types/client/config/settings-nav-icon.d.ts +21 -0
  172. package/lib/types/client/config/settings-nav-icon.d.ts.map +1 -0
  173. package/lib/types/client/index.d.ts +16 -0
  174. package/lib/types/client/index.d.ts.map +1 -0
  175. package/lib/types/client/sync/R2SyncPanel.d.ts +6 -0
  176. package/lib/types/client/sync/R2SyncPanel.d.ts.map +1 -0
  177. package/lib/types/client/sync/SyncPanel.d.ts +12 -0
  178. package/lib/types/client/sync/SyncPanel.d.ts.map +1 -0
  179. package/lib/types/client/sync/confirm-dialog.d.ts +43 -0
  180. package/lib/types/client/sync/confirm-dialog.d.ts.map +1 -0
  181. package/lib/types/client/sync/index.d.ts +10 -0
  182. package/lib/types/client/sync/index.d.ts.map +1 -0
  183. package/lib/types/client/sync/ui.d.ts +79 -0
  184. package/lib/types/client/sync/ui.d.ts.map +1 -0
  185. package/lib/types/client/sync/use-backup.d.ts +50 -0
  186. package/lib/types/client/sync/use-backup.d.ts.map +1 -0
  187. package/lib/types/client/sync/use-sync.d.ts +88 -0
  188. package/lib/types/client/sync/use-sync.d.ts.map +1 -0
  189. package/package.json +89 -0
  190. package/skills/dsh-safe-restart/SKILL.md +206 -0
  191. package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +468 -0
  192. package/src/client/auto-reload.ts +104 -0
  193. package/src/client/config/MaestroSettings.tsx +892 -0
  194. package/src/client/config/components/BrandMark.tsx +94 -0
  195. package/src/client/config/guard-view.ts +187 -0
  196. package/src/client/config/index.tsx +109 -0
  197. package/src/client/config/maestro-mark.ts +37 -0
  198. package/src/client/config/settings-nav-icon.ts +68 -0
  199. package/src/client/index.tsx +33 -0
  200. package/src/client/sync/R2SyncPanel.tsx +260 -0
  201. package/src/client/sync/SyncPanel.tsx +422 -0
  202. package/src/client/sync/confirm-dialog.tsx +202 -0
  203. package/src/client/sync/index.tsx +336 -0
  204. package/src/client/sync/ui.tsx +313 -0
  205. package/src/client/sync/use-backup.ts +207 -0
  206. package/src/client/sync/use-sync.ts +502 -0
  207. package/src/host/bin.ts +3 -0
  208. package/src/host/boot-guard.ts +76 -0
  209. package/src/host/boot-lock.ts +155 -0
  210. package/src/host/cli.ts +288 -0
  211. package/src/host/config/index.ts +78 -0
  212. package/src/host/config/service.ts +40 -0
  213. package/src/host/config.ts +18 -0
  214. package/src/host/daemon-freshness.ts +143 -0
  215. package/src/host/debug-agent.ts +145 -0
  216. package/src/host/dsh-session.ts +56 -0
  217. package/src/host/dsh-skill.d.ts +44 -0
  218. package/src/host/guard/augment.d.ts +33 -0
  219. package/src/host/guard/config.ts +244 -0
  220. package/src/host/guard/decide.ts +40 -0
  221. package/src/host/guard/full-scan-tool.ts +61 -0
  222. package/src/host/guard/index.ts +281 -0
  223. package/src/host/guard/journal.ts +440 -0
  224. package/src/host/guard/migrate.ts +41 -0
  225. package/src/host/guard/parse.ts +1150 -0
  226. package/src/host/guard/paths.ts +239 -0
  227. package/src/host/guard/permission-policy.ts +15 -0
  228. package/src/host/guard/redact.ts +64 -0
  229. package/src/host/guard/rules.ts +891 -0
  230. package/src/host/guard/status-tool.ts +229 -0
  231. package/src/host/guard/tiers.ts +2 -0
  232. package/src/host/guard/validators.ts +29 -0
  233. package/src/host/health-poller.ts +446 -0
  234. package/src/host/index.ts +7 -0
  235. package/src/host/intents.ts +67 -0
  236. package/src/host/notifier.ts +71 -0
  237. package/src/host/paths.ts +70 -0
  238. package/src/host/plugin.ts +1097 -0
  239. package/src/host/preset.ts +170 -0
  240. package/src/host/report.ts +71 -0
  241. package/src/host/restart-exec.ts +81 -0
  242. package/src/host/restart-guards.ts +150 -0
  243. package/src/host/restart-tool.ts +483 -0
  244. package/src/host/restart-web.ts +72 -0
  245. package/src/host/resume-log.ts +39 -0
  246. package/src/host/resume-tools.ts +385 -0
  247. package/src/host/resume.ts +204 -0
  248. package/src/host/scan.ts +61 -0
  249. package/src/host/self-kill-guard.ts +216 -0
  250. package/src/host/session-health.ts +236 -0
  251. package/src/host/session-log-file.ts +77 -0
  252. package/src/host/skill-provider.ts +69 -0
  253. package/src/host/snapshot.ts +337 -0
  254. package/src/host/source.ts +19 -0
  255. package/src/host/store/index.ts +348 -0
  256. package/src/host/store/legacy.ts +96 -0
  257. package/src/host/supervisor.ts +720 -0
  258. package/src/host/sync/backup-config.ts +159 -0
  259. package/src/host/sync/backup-service.ts +453 -0
  260. package/src/host/sync/bidirectional.ts +66 -0
  261. package/src/host/sync/cli.ts +539 -0
  262. package/src/host/sync/config.ts +119 -0
  263. package/src/host/sync/fingerprint.ts +83 -0
  264. package/src/host/sync/hashing.ts +58 -0
  265. package/src/host/sync/index.ts +737 -0
  266. package/src/host/sync/machine-id.ts +81 -0
  267. package/src/host/sync/merge.ts +102 -0
  268. package/src/host/sync/peer-host.ts +65 -0
  269. package/src/host/sync/process-runner.ts +177 -0
  270. package/src/host/sync/remote-agent.ts +213 -0
  271. package/src/host/sync/remote-cache.ts +68 -0
  272. package/src/host/sync/remote-manifest.ts +70 -0
  273. package/src/host/sync/s3-object-store.ts +144 -0
  274. package/src/host/sync/session-merge.ts +220 -0
  275. package/src/host/sync/session-plan.ts +237 -0
  276. package/src/host/sync/sigv4.ts +81 -0
  277. package/src/host/sync/snapshot.ts +162 -0
  278. package/src/host/sync/ssh-mux.ts +56 -0
  279. package/src/host/sync/sync-plan.ts +366 -0
  280. package/src/host/sync/sync-service.ts +855 -0
  281. package/src/host/sync/sync-types.ts +102 -0
  282. package/src/host/sync/transport.ts +261 -0
  283. package/src/host/sync/tunnel-restore.ts +160 -0
  284. package/src/host/sync/validation.ts +91 -0
  285. package/src/host/tool-view.ts +98 -0
@@ -0,0 +1,260 @@
1
+ // src/client/R2SyncPanel.tsx — the R2 Sync tab (backup + restore + GC).
2
+ // Confirmation-first: every mutation route lives inside a ConfirmDialog bound
3
+ // to a live preview id; secret material is never rendered — only the redacted
4
+ // source label and non-secret config/status fields.
5
+ import * as React from 'react'
6
+ import { useBackupTarget } from './use-backup.js'
7
+ import { ConfirmDialog } from './confirm-dialog.js'
8
+ import { Button, StatTile, Badge } from './ui.js'
9
+
10
+ const sourceLabel = (s: string | undefined) => (s === 'env' ? 'Env' : s === 'file' ? 'Private file' : 'Not configured')
11
+
12
+ type BackupApi = ReturnType<typeof useBackupTarget>
13
+
14
+ function field(input: { id: string; label: string; value: string; placeholder: string; onChange: (v: string) => void; disabled: boolean; hint?: string; error?: string | undefined }) {
15
+ return (
16
+ <div data-r2-field="">
17
+ <label data-r2-field-label="" htmlFor={input.id}>{input.label}</label>
18
+ <input
19
+ id={input.id}
20
+ data-r2-field-input=""
21
+ data-testid={input.id}
22
+ value={input.value}
23
+ onChange={(e) => input.onChange(e.target.value)}
24
+ placeholder={input.placeholder}
25
+ autoComplete="off"
26
+ autoCapitalize="off"
27
+ spellCheck={false}
28
+ disabled={input.disabled}
29
+ aria-invalid={input.error ? 'true' : undefined}
30
+ aria-describedby={input.error ? `${input.id}-error` : undefined}
31
+ />
32
+ {/* Field-level error: the server validates, but the message belongs under
33
+ the field it names, not only in the panel banner. */}
34
+ {input.error ? (
35
+ <span id={`${input.id}-error`} data-r2-field-error="" role="alert" data-testid={`${input.id}-error`}>{input.error}</span>
36
+ ) : null}
37
+ {input.hint ? <span data-r2-field-hint="">{input.hint}</span> : null}
38
+ </div>
39
+ )
40
+ }
41
+
42
+ /**
43
+ * Route a server validation message to the field it names.
44
+ *
45
+ * `validateR2ConfigInput` throws messages that lead with the offending key
46
+ * ("bucket is required", "invalid endpoint: …"), so the client can put the text
47
+ * under that input instead of only in the panel banner. Anything unrecognized
48
+ * stays a banner error — never silently dropped.
49
+ */
50
+ function routeR2FieldError(msg: string): { field: string; message: string } | null {
51
+ const m = /^\s*(?:invalid\s+)?(accountId|endpoint|region|bucket|prefix|provider)\b/i.exec(msg)
52
+ if (!m || m[1] === undefined) return null
53
+ return { field: m[1], message: msg }
54
+ }
55
+
56
+ /**
57
+ * Non-secret backup target form — mirrors the SSH section on the Remote tab.
58
+ * Keys are never asked for here: they come from env or the 0600 sidecar.
59
+ */
60
+ function ConfigForm(props: { b: BackupApi }): React.ReactElement {
61
+ const b = props.b
62
+ const st = b.status
63
+ const [provider, setProvider] = React.useState('r2')
64
+ const [accountId, setAccountId] = React.useState('')
65
+ const [endpoint, setEndpoint] = React.useState('')
66
+ const [region, setRegion] = React.useState('')
67
+ const [bucket, setBucket] = React.useState('')
68
+ const [prefix, setPrefix] = React.useState('')
69
+ const [fieldErrors, setFieldErrors] = React.useState<Record<string, string>>({})
70
+ const [primed, setPrimed] = React.useState(false)
71
+ React.useEffect(() => {
72
+ if (primed || !st) return
73
+ const r = st.r2
74
+ setProvider(r?.provider === 'aws' ? 'aws' : 'r2')
75
+ setAccountId('')
76
+ setEndpoint(r?.endpoint ?? '')
77
+ setRegion(r?.region ?? '')
78
+ setBucket(r?.bucket ?? '')
79
+ setPrefix(st.prefix ?? '')
80
+ setPrimed(true)
81
+ }, [st, primed])
82
+ const busy = b.busy || b.checking
83
+ /** Clear one field's error as soon as the user edits it. */
84
+ const bind = (key: string, set: (v: string) => void) => (v: string) => {
85
+ set(v)
86
+ setFieldErrors((prev) => {
87
+ if (!(key in prev)) return prev
88
+ const next = { ...prev }
89
+ delete next[key]
90
+ return next
91
+ })
92
+ }
93
+ const save = async () => {
94
+ setFieldErrors({})
95
+ const res = await b.saveR2Config({ provider, accountId, endpoint, region, bucket, prefix })
96
+ if (!res.ok) {
97
+ const routed = routeR2FieldError(res.error ?? '')
98
+ if (routed) setFieldErrors({ [routed.field]: routed.message })
99
+ }
100
+ }
101
+ return (
102
+ <div data-r2-config="">
103
+ <span data-r2-config-label="">Backup target</span>
104
+ <div data-r2-field="">
105
+ <label data-r2-field-label="" htmlFor="r2-cfg-provider">Provider</label>
106
+ <div data-r2-provider-row="" role="radiogroup" aria-label="Provider">
107
+ {(['r2', 'aws'] as const).map((p) => (
108
+ <button
109
+ key={p}
110
+ type="button"
111
+ data-testid={`r2-cfg-provider-${p}`}
112
+ data-r2-provider-opt=""
113
+ aria-pressed={provider === p}
114
+ disabled={busy}
115
+ onClick={() => setProvider(p)}
116
+ >
117
+ {p === 'r2' ? 'Cloudflare R2' : 'AWS S3'}
118
+ </button>
119
+ ))}
120
+ </div>
121
+ </div>
122
+ {provider === 'r2' ? field({ id: 'r2-cfg-account', label: 'Account ID', value: accountId, placeholder: '32 hex chars — leave empty to keep the default endpoint', onChange: bind('accountId', setAccountId), disabled: busy, error: fieldErrors.accountId }) : null}
123
+ {field({ id: 'r2-cfg-endpoint', label: 'Endpoint', value: endpoint, placeholder: 'https://<account>.r2.cloudflarestorage.com', onChange: bind('endpoint', setEndpoint), disabled: busy, error: fieldErrors.endpoint })}
124
+ {field({ id: 'r2-cfg-region', label: 'Region', value: region, placeholder: 'auto', onChange: bind('region', setRegion), disabled: busy, error: fieldErrors.region })}
125
+ {/* Placeholders must not read as working defaults: `maestro-backup` /
126
+ `v1/hosts/<id>/` looked pre-filled, so an untouched form failed with a
127
+ generic "bucket is required" that nobody could tie to the empty input. */}
128
+ {field({ id: 'r2-cfg-bucket', label: 'Bucket', value: bucket, placeholder: 'your-bucket-name', onChange: bind('bucket', setBucket), disabled: busy, error: fieldErrors.bucket })}
129
+ {field({ id: 'r2-cfg-prefix', label: 'Prefix', value: prefix, placeholder: 'your-prefix/', onChange: bind('prefix', setPrefix), disabled: busy, error: fieldErrors.prefix })}
130
+ <div data-r2-config-row="">
131
+ <Button data-testid="r2-save-config" variant="primary" disabled={busy} busy={b.busy} onClick={() => void save()}>
132
+ {b.busy ? 'Saving…' : 'Save target'}
133
+ </Button>
134
+ </div>
135
+ <span data-r2-config-hint="">Access keys are never entered here — set R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY env or the 0600 sidecar file.</span>
136
+ </div>
137
+ )
138
+ }
139
+
140
+ export function R2SyncPanel(props: { b: ReturnType<typeof useBackupTarget> }): React.ReactElement {
141
+ const b = props.b
142
+ const st = b.status
143
+ // Mobile-first: only the primary backup action stays visible; restore/GC
144
+ // live behind a More menu so the row never overflows 360px viewports.
145
+ const [moreOpen, setMoreOpen] = React.useState(false)
146
+ const closeMore = () => setMoreOpen(false)
147
+
148
+ const banner = () => {
149
+ if (!st) return null
150
+ return (
151
+ <div data-r2-summary="">
152
+ <Badge tone={st.configured ? 'success' : 'error'}>{st.configured ? sourceLabel(st.source) : sourceLabel('none')}</Badge>
153
+ <span data-r2-muted="">{st.configured ? `${st.bucket} · ${st.prefix}` : 'Set domains.sync.r2 + secret material to enable backup'}</span>
154
+ </div>
155
+ )
156
+ }
157
+
158
+ const dialog = () => {
159
+ if (b.confirmOpen === 'backup' && b.backupPreview) {
160
+ return (
161
+ <ConfirmDialog
162
+ kind="backup"
163
+ title="Apply backup"
164
+ targetLabel={`${st?.bucket ?? ''} / ${st?.prefix ?? ''}`}
165
+ preview={b.backupPreview}
166
+ previewDirection={'push' as any}
167
+ remoteHost={st?.bucket ?? 'R2'}
168
+ busy={b.busy}
169
+ actionLimit={5}
170
+ planAgeSecs={0}
171
+ onShowMore={() => {}}
172
+ onCancel={b.cancelDialog}
173
+ onApply={() => void b.applyBackup()}
174
+ />
175
+ )
176
+ }
177
+ if (b.confirmOpen === 'restore' && b.restorePreview) {
178
+ const r = b.restorePreview
179
+ return (
180
+ <ConfirmDialog
181
+ kind="restore"
182
+ title={`Apply restore (${r.mode === 'new-dir' ? 'new dir' : 'in place'})`}
183
+ targetLabel="from backup HEAD"
184
+ preview={{ ...r, summary: r.summary, actions: [] }}
185
+ previewDirection={'pull' as any}
186
+ remoteHost="R2 backup"
187
+ busy={b.busy}
188
+ actionLimit={5}
189
+ planAgeSecs={0}
190
+ onShowMore={() => {}}
191
+ onCancel={b.cancelDialog}
192
+ onApply={() => void b.applyRestore(r.mode)}
193
+ />
194
+ )
195
+ }
196
+ if (b.confirmOpen === 'gc' && b.gcReport) {
197
+ return (
198
+ <ConfirmDialog
199
+ kind="gc"
200
+ title="Apply GC"
201
+ targetLabel={`${b.gcReport.deletableBlobs?.length ?? 0} blobs · ${b.gcReport.freedBytes ?? 0} bytes`}
202
+ preview={{ ...b.gcReport, summary: {}, actions: [] }}
203
+ previewDirection={'push' as any}
204
+ remoteHost={st?.bucket ?? 'R2'}
205
+ busy={b.busy}
206
+ actionLimit={5}
207
+ planAgeSecs={0}
208
+ onShowMore={() => {}}
209
+ onCancel={b.cancelDialog}
210
+ onApply={() => void b.applyGc()}
211
+ />
212
+ )
213
+ }
214
+ return null
215
+ }
216
+
217
+ return (
218
+ <div data-sync-root="" data-r2-root="" aria-busy={b.busy}>
219
+ {banner()}
220
+ <ConfigForm b={b} />
221
+ <div data-r2-stats="">
222
+ <StatTile icon="server" value={String(st?.eligible?.md ?? 0)} label="memory" />
223
+ <StatTile icon="refresh" value={String(st?.eligible?.sessions ?? 0)} label="sessions" />
224
+ <StatTile icon="check" value={st?.lastManifest ? 'yes' : 'no'} label="last backup" />
225
+ </div>
226
+ <div data-r2-actions="" data-sync-actions-bar="">
227
+ <Button data-testid="r2-preview-backup" kind="primary" disabled={!b.canBackup} onClick={() => void b.previewBackup()}>
228
+ Preview Backup
229
+ </Button>
230
+ <div data-r2-more="">
231
+ <Button
232
+ data-testid="r2-more"
233
+ variant="outline"
234
+ disabled={!b.canBackup}
235
+ aria-haspopup="menu"
236
+ aria-expanded={moreOpen}
237
+ onClick={() => setMoreOpen((v) => !v)}
238
+ >
239
+ More
240
+ </Button>
241
+ {moreOpen ? (
242
+ <div data-r2-more-menu="" role="menu" aria-label="More backup actions">
243
+ <Button data-testid="r2-restore-newdir" role="menuitem" variant="ghost" disabled={!b.canBackup} onClick={() => { closeMore(); void b.previewRestore('new-dir') }}>
244
+ Restore to new folder…
245
+ </Button>
246
+ <Button data-testid="r2-restore-inplace" role="menuitem" variant="ghost" disabled={!b.canBackup} onClick={() => { closeMore(); void b.previewRestore('in-place') }}>
247
+ Restore in place…
248
+ </Button>
249
+ <Button data-testid="r2-preview-gc" role="menuitem" variant="ghost" disabled={!b.canBackup} onClick={() => { closeMore(); void b.previewGc() }}>
250
+ Preview GC
251
+ </Button>
252
+ </div>
253
+ ) : null}
254
+ </div>
255
+ </div>
256
+ {b.error ? <div role="alert" data-sync-error="">{b.error}</div> : null}
257
+ {dialog()}
258
+ </div>
259
+ )
260
+ }