@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
package/lib/client.js ADDED
@@ -0,0 +1,2901 @@
1
+ window.__ModuleLoader__.load({
2
+ id: '@ddtcorex/dsh-maestro-core',
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ var React = require("react");
7
+ "use strict";
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // src/client/index.tsx
37
+ var index_exports = {};
38
+ __export(index_exports, {
39
+ apply: () => apply4,
40
+ inject: () => inject
41
+ });
42
+ module.exports = __toCommonJS(index_exports);
43
+
44
+ // src/client/auto-reload.ts
45
+ function apply(ctx) {
46
+ try {
47
+ ctx.effect(() => {
48
+ let timer = null;
49
+ let reloading = false;
50
+ const checkAndReload = async () => {
51
+ if (reloading) return;
52
+ try {
53
+ const res = await fetch("/", { method: "HEAD", cache: "no-store" });
54
+ if (res.ok) {
55
+ reloading = true;
56
+ if (timer) {
57
+ clearInterval(timer);
58
+ timer = null;
59
+ }
60
+ window.location.reload();
61
+ }
62
+ } catch {
63
+ }
64
+ };
65
+ const startPolling = () => {
66
+ if (timer || reloading) return;
67
+ timer = setInterval(checkAndReload, 1e3);
68
+ };
69
+ const stopPolling = () => {
70
+ if (timer) {
71
+ clearInterval(timer);
72
+ timer = null;
73
+ }
74
+ };
75
+ const onOffline = () => startPolling();
76
+ const onOnline = () => {
77
+ const wasPolling = !!timer;
78
+ stopPolling();
79
+ if (wasPolling) void checkAndReload();
80
+ };
81
+ const OriginalWebSocket = window.WebSocket;
82
+ let wsCloseHandler = null;
83
+ try {
84
+ if (OriginalWebSocket) {
85
+ const Patched = function(url, protocols) {
86
+ const ws = protocols ? new OriginalWebSocket(url, protocols) : new OriginalWebSocket(url);
87
+ ws.addEventListener("close", () => {
88
+ try {
89
+ const u = new URL(url, window.location.href);
90
+ if (u.host !== window.location.host) return;
91
+ } catch {
92
+ }
93
+ fetch("/", { method: "HEAD", cache: "no-store" }).then((res) => {
94
+ if (!res.ok) startPolling();
95
+ }).catch(() => startPolling());
96
+ });
97
+ ws.addEventListener("open", () => {
98
+ if (timer) void checkAndReload();
99
+ });
100
+ return ws;
101
+ };
102
+ Patched.prototype = OriginalWebSocket.prototype;
103
+ Object.setPrototypeOf(Patched, OriginalWebSocket);
104
+ window.WebSocket = Patched;
105
+ wsCloseHandler = () => {
106
+ window.WebSocket = OriginalWebSocket;
107
+ };
108
+ }
109
+ } catch {
110
+ }
111
+ window.addEventListener("offline", onOffline);
112
+ window.addEventListener("online", onOnline);
113
+ document.addEventListener("visibilitychange", () => {
114
+ if (document.visibilityState === "visible" && timer) void checkAndReload();
115
+ });
116
+ const onHostPush = () => {
117
+ if (!reloading) window.location.reload();
118
+ };
119
+ window.addEventListener("dsh-maestro-supervisor-reload", onHostPush);
120
+ void fetch("/", { method: "HEAD", cache: "no-store" }).catch(() => startPolling());
121
+ return () => {
122
+ window.removeEventListener("offline", onOffline);
123
+ window.removeEventListener("online", onOnline);
124
+ window.removeEventListener("dsh-maestro-supervisor-reload", onHostPush);
125
+ if (timer) clearInterval(timer);
126
+ if (wsCloseHandler) wsCloseHandler();
127
+ };
128
+ }, "supervisor:auto-reload");
129
+ } catch {
130
+ }
131
+ }
132
+
133
+ // src/client/config/MaestroSettings.tsx
134
+ var import_react2 = require("react");
135
+
136
+ // src/client/config/guard-view.ts
137
+ function isGuardTier(v) {
138
+ return v === "allow" || v === "journal" || v === "ask" || v === "deny";
139
+ }
140
+ var RULE_META = [
141
+ { id: "git.push.protected", group: "Git", label: "Push to protected branch", hint: "Direct push to master/main (or your branch list).", defaultTier: "ask" },
142
+ { id: "git.merge.protected", group: "Git", label: "Merge into protected branch", hint: "Local merge targeting a protected branch.", defaultTier: "journal" },
143
+ { id: "git.tag.release", group: "Git", label: "Release tag push", hint: "Pushing a version-looking tag (v1.2.3).", defaultTier: "ask" },
144
+ { id: "git.push.force", group: "Git", label: "Force push", hint: "push --force / --force-with-lease anywhere.", defaultTier: "ask" },
145
+ { id: "gh.release.create", group: "Publish", label: "Create GitHub/GitLab release", hint: "gh release create and equivalents.", defaultTier: "ask" },
146
+ { id: "gh.protection.delete", group: "Publish", label: "Delete branch protection", hint: "Removing protection rules from a branch.", defaultTier: "ask" },
147
+ { id: "pkg.publish", group: "Publish", label: "Publish a package", hint: "pnpm/npm publish and tag pushes that trigger it.", defaultTier: "ask" },
148
+ { id: "secret.access", group: "Filesystem", label: "Read a secret location", hint: "Any read of a protected credential path.", defaultTier: "ask" },
149
+ { id: "fs.write.outside", group: "Filesystem", label: "Write outside working dir", hint: "File writes escaping the session cwd (temp dir exempt).", defaultTier: "ask" },
150
+ { id: "net.exec.remote", group: "Network", label: "Remote execution", hint: "ssh / cloudflared-tunnelled commands.", defaultTier: "ask" },
151
+ { id: "guard.tamper", group: "Self-protection", label: "Edit guard config or journal", hint: "Any write to the guard settings or its audit trail.", defaultTier: "deny", locked: true }
152
+ ];
153
+ var LEGACY_GIT_RULES = ["git.push.protected", "git.tag.release", "git.push.force"];
154
+ var DEFAULT_BRANCHES = ["master", "main"];
155
+ function stringArray(v) {
156
+ if (!Array.isArray(v)) return void 0;
157
+ const out = v.filter((x) => typeof x === "string" && x.trim() !== "");
158
+ return out.length > 0 ? out : void 0;
159
+ }
160
+ function booleanOr(v, fallback) {
161
+ return typeof v === "boolean" ? v : fallback;
162
+ }
163
+ function positiveIntOr(v, fallback) {
164
+ return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : fallback;
165
+ }
166
+ function isRecord(v) {
167
+ return typeof v === "object" && v !== null && !Array.isArray(v);
168
+ }
169
+ function effectiveGuardView(raw) {
170
+ const doc = isRecord(raw) ? raw : {};
171
+ const storedRules = isRecord(doc.rules) ? doc.rules : {};
172
+ const rules = RULE_META.map((meta) => {
173
+ const stored = storedRules[meta.id];
174
+ if (isGuardTier(stored)) return { ...meta, tier: stored, source: "stored" };
175
+ const legacyTier = legacyTierFor(meta.id, doc);
176
+ if (legacyTier !== void 0) return { ...meta, tier: legacyTier, source: "legacy" };
177
+ return { ...meta, tier: meta.defaultTier, source: "default" };
178
+ });
179
+ const v2Branches = stringArray(doc.protectedBranches);
180
+ const legacyBranches = isRecord(doc.gitProtection) ? stringArray(doc.gitProtection.branches) : void 0;
181
+ const protectedBranches = v2Branches ?? legacyBranches ?? [...DEFAULT_BRANCHES];
182
+ const v2Paths = stringArray(doc.protectedPaths) ?? [];
183
+ const legacyPaths = stringArray(doc.credentialPaths) ?? [];
184
+ const protectedPaths = [.../* @__PURE__ */ new Set([...v2Paths, ...legacyPaths])];
185
+ const containmentRaw = isRecord(doc.workingDirContainment) ? doc.workingDirContainment : {};
186
+ const containment = {
187
+ enabled: booleanOr(containmentRaw.enabled, true),
188
+ spillReads: booleanOr(containmentRaw.spillReads, true)
189
+ };
190
+ const journalRaw = isRecord(doc.journal) ? doc.journal : {};
191
+ const journal = {
192
+ enabled: booleanOr(journalRaw.enabled, true),
193
+ allowCounters: booleanOr(journalRaw.allowCounters, true),
194
+ retainDays: positiveIntOr(journalRaw.retainDays, 30),
195
+ retainFiles: positiveIntOr(journalRaw.retainFiles, 14)
196
+ };
197
+ return {
198
+ rules,
199
+ protectedBranches,
200
+ branchesSource: v2Branches !== void 0 ? "stored" : legacyBranches !== void 0 ? "legacy" : "default",
201
+ protectedPaths,
202
+ containment,
203
+ journal
204
+ };
205
+ }
206
+ function legacyTierFor(ruleId, doc) {
207
+ if (LEGACY_GIT_RULES.includes(ruleId)) {
208
+ const gp = doc.gitProtection;
209
+ if (isRecord(gp) && Object.keys(gp).length > 0 && gp.enabled === false) return "journal";
210
+ return void 0;
211
+ }
212
+ if (ruleId === "pkg.publish" && doc.publishBlocked === false) return "journal";
213
+ if (ruleId === "fs.write.outside" && doc.cwdContainment === false) return "journal";
214
+ return void 0;
215
+ }
216
+ function ruleTierPatch(ruleId, tier) {
217
+ return { [ruleId]: tier === "default" ? null : tier };
218
+ }
219
+
220
+ // src/client/config/components/BrandMark.tsx
221
+ var import_react = require("react");
222
+
223
+ // src/client/config/maestro-mark.ts
224
+ var MAESTRO_MARK_PATH = "M2 11 L5 4 L8 9 L11 4 L14 11";
225
+ var MAESTRO_MARK_VIEWBOX = "0 0 16 16";
226
+ var MAESTRO_MARK_STROKE_WIDTH = 1.6;
227
+ var MAESTRO_BRAND_TILE = "#0A84FF";
228
+ function maestroMarkMaskUri() {
229
+ const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='${MAESTRO_MARK_VIEWBOX}' fill='none' stroke='black' stroke-width='${MAESTRO_MARK_STROKE_WIDTH}' stroke-linecap='round' stroke-linejoin='round'><path d='${MAESTRO_MARK_PATH}'/></svg>`;
230
+ return `data:image/svg+xml,${svg.replace(/</g, "%3C").replace(/>/g, "%3E")}`;
231
+ }
232
+
233
+ // src/client/config/components/BrandMark.tsx
234
+ var BRAND_BADGE_LAYOUT_KEYS = [
235
+ "alignSelf",
236
+ "margin",
237
+ "marginTop",
238
+ "marginRight",
239
+ "marginBottom",
240
+ "marginLeft"
241
+ ];
242
+ function layoutOnly(style) {
243
+ const out = {};
244
+ for (const key of BRAND_BADGE_LAYOUT_KEYS) {
245
+ if (style?.[key] !== void 0) out[key] = style[key];
246
+ }
247
+ return out;
248
+ }
249
+ function MaestroMark(props) {
250
+ const s = props.size ?? 16;
251
+ return (0, import_react.createElement)(
252
+ "svg",
253
+ { width: s, height: s, viewBox: MAESTRO_MARK_VIEWBOX, fill: "none", "aria-hidden": "true" },
254
+ (0, import_react.createElement)("path", { d: MAESTRO_MARK_PATH, stroke: "currentColor", strokeWidth: MAESTRO_MARK_STROKE_WIDTH, strokeLinecap: "round", strokeLinejoin: "round" })
255
+ );
256
+ }
257
+ function BrandBadge(props) {
258
+ const outer = props.outer ?? 28;
259
+ const size = props.size ?? 16;
260
+ const radius = props.radius ?? 8;
261
+ return (0, import_react.createElement)("span", {
262
+ "data-maestro-logo": "",
263
+ style: {
264
+ width: outer,
265
+ height: outer,
266
+ borderRadius: radius,
267
+ display: "inline-flex",
268
+ alignItems: "center",
269
+ justifyContent: "center",
270
+ background: `var(--dsw-alias-brand-primary, ${MAESTRO_BRAND_TILE})`,
271
+ backgroundColor: MAESTRO_BRAND_TILE,
272
+ color: "#fff",
273
+ flex: "none",
274
+ border: "1px solid rgba(0,0,0,0.08)",
275
+ boxShadow: "0 0 0 1px var(--dsw-alias-border-l1)",
276
+ boxSizing: "border-box",
277
+ ...layoutOnly(props.style)
278
+ }
279
+ }, (0, import_react.createElement)(MaestroMark, { size }));
280
+ }
281
+
282
+ // src/client/config/MaestroSettings.tsx
283
+ var t = {
284
+ bgLayer1: "var(--dsw-alias-bg-layer-1)",
285
+ bgLayer2: "var(--dsw-alias-bg-layer-2)",
286
+ bgLayer3: "var(--dsw-alias-bg-layer-3)",
287
+ borderL2: "var(--dsw-alias-border-l2)",
288
+ labelPrimary: "var(--dsw-alias-label-primary)",
289
+ labelSecondary: "var(--dsw-alias-label-secondary)",
290
+ labelTertiary: "var(--dsw-alias-label-tertiary)",
291
+ labelDimmed: "var(--dsw-alias-label-dimmed)",
292
+ labelFg: "var(--dsw-alias-label-primary-foreground)",
293
+ primaryFill: "var(--dsw-alias-button-primary-fill)",
294
+ primaryHover: "var(--dsw-alias-button-primary-hover)",
295
+ interactiveHover: "var(--dsw-alias-interactive-bg-hover)",
296
+ interactiveActive: "var(--dsw-alias-interactive-bg-active)",
297
+ stateError: "var(--dsw-alias-state-error-primary)",
298
+ brand: "var(--dsw-alias-brand-primary)",
299
+ shadowLv3: "var(--dsw-shadow-lv3)",
300
+ scrollbarL2: "var(--dsw-alias-scrollbar-bg-l2)"
301
+ };
302
+ var TAB_ICON_PATHS = {
303
+ shield: "M12 2l7 4v5c0 5-3.5 7.5-7 9-3.5-1.5-7-4-7-9V6l7-4z",
304
+ cpu: "M5 12H2a2 2 0 0 1 2-2h2M12 5V2a2 2 0 0 1 2 2v2M19 12h2a2 2 0 0 1-2 2h-2M12 19v2a2 2 0 0 1-2-2v-2M8 8h8v8H8z"
305
+ };
306
+ function TabIcon({ name, size = 14 }) {
307
+ return (0, import_react2.createElement)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", style: { flex: "none" } }, (0, import_react2.createElement)("path", { d: TAB_ICON_PATHS[name] }));
308
+ }
309
+ function Button({
310
+ variant = "ghost",
311
+ size = "md",
312
+ icon,
313
+ children,
314
+ style,
315
+ ...rest
316
+ }) {
317
+ const base = {
318
+ display: "inline-flex",
319
+ alignItems: "center",
320
+ justifyContent: "center",
321
+ gap: 4,
322
+ border: "none",
323
+ borderRadius: size === "sm" ? 16 : 18,
324
+ cursor: "pointer",
325
+ fontSize: size === "sm" ? 13 : 14,
326
+ lineHeight: size === "sm" ? "18px" : "22px",
327
+ padding: size === "sm" ? "0 12px" : "0 14px",
328
+ height: size === "sm" ? 32 : 36,
329
+ color: t.labelPrimary,
330
+ background: "transparent",
331
+ fontFamily: "inherit"
332
+ };
333
+ if (variant === "primary") {
334
+ base.background = t.primaryFill;
335
+ base.color = t.labelFg;
336
+ }
337
+ if (variant === "outline") {
338
+ base.border = `1px solid ${t.borderL2}`;
339
+ base.background = "transparent";
340
+ }
341
+ const merged = { ...base, ...style };
342
+ return (0, import_react2.createElement)(
343
+ "button",
344
+ {
345
+ type: "button",
346
+ style: merged,
347
+ onMouseEnter: (e) => {
348
+ if (rest.disabled) return;
349
+ if (variant === "primary") e.currentTarget.style.background = t.primaryHover;
350
+ else e.currentTarget.style.background = t.interactiveHover;
351
+ },
352
+ onMouseLeave: (e) => {
353
+ if (variant === "primary") e.currentTarget.style.background = t.primaryFill;
354
+ else e.currentTarget.style.background = variant === "outline" ? "transparent" : "transparent";
355
+ },
356
+ ...rest
357
+ },
358
+ icon ? (0, import_react2.createElement)("span", { style: { display: "inline-flex", width: 16, height: 16, alignItems: "center", justifyContent: "center" } }, icon) : null,
359
+ children
360
+ );
361
+ }
362
+ function InputWrap({
363
+ icon,
364
+ children,
365
+ style,
366
+ focused
367
+ }) {
368
+ return (0, import_react2.createElement)(
369
+ "span",
370
+ {
371
+ style: {
372
+ display: "inline-flex",
373
+ alignItems: "center",
374
+ gap: 8,
375
+ height: 36,
376
+ padding: "0 12px",
377
+ border: `1px solid ${focused ? t.brand : t.borderL2}`,
378
+ borderRadius: 10,
379
+ background: t.bgLayer1,
380
+ flex: 1,
381
+ minWidth: 0,
382
+ boxSizing: "border-box",
383
+ ...style
384
+ }
385
+ },
386
+ icon ? (0, import_react2.createElement)("span", { style: { display: "inline-flex", width: 16, height: 16, color: t.labelTertiary } }, icon) : null,
387
+ children
388
+ );
389
+ }
390
+ function FieldInput(props) {
391
+ const [focused, setFocused] = (0, import_react2.useState)(false);
392
+ const { icon, style, ...rest } = props;
393
+ return (0, import_react2.createElement)(
394
+ InputWrap,
395
+ { icon, focused, style: { ...style, flex: "1 1 auto" } },
396
+ (0, import_react2.createElement)("input", {
397
+ ...rest,
398
+ onFocus: (e) => {
399
+ setFocused(true);
400
+ rest.onFocus?.(e);
401
+ },
402
+ onBlur: (e) => {
403
+ setFocused(false);
404
+ rest.onBlur?.(e);
405
+ },
406
+ style: {
407
+ flex: 1,
408
+ minWidth: 0,
409
+ border: "none",
410
+ outline: "none",
411
+ background: "transparent",
412
+ fontSize: 14,
413
+ lineHeight: "22px",
414
+ color: t.labelPrimary,
415
+ fontFamily: "inherit"
416
+ }
417
+ })
418
+ );
419
+ }
420
+ var fieldLabelStyle = {
421
+ display: "flex",
422
+ flexDirection: "column",
423
+ gap: "6px",
424
+ fontSize: "12px",
425
+ lineHeight: "16px",
426
+ fontWeight: "500",
427
+ color: t.labelSecondary,
428
+ margin: "12px 0 0"
429
+ };
430
+ var captionStyle = {
431
+ fontSize: "12px",
432
+ lineHeight: "16px",
433
+ color: t.labelSecondary,
434
+ margin: "4px 0"
435
+ };
436
+ var cardInsetStyle = {
437
+ display: "flex",
438
+ flexDirection: "column",
439
+ gap: "8px",
440
+ padding: "12px",
441
+ borderRadius: "12px",
442
+ border: `1px solid ${t.borderL2}`,
443
+ background: t.bgLayer1
444
+ };
445
+ var rowStyle = {
446
+ display: "flex",
447
+ alignItems: "center",
448
+ gap: "8px",
449
+ padding: "16px 0",
450
+ borderBottom: `1px solid ${t.borderL2}`,
451
+ minWidth: "0"
452
+ };
453
+ var rowTextStyle = {
454
+ flex: "1",
455
+ minWidth: "0",
456
+ display: "flex",
457
+ flexDirection: "column",
458
+ gap: "4px",
459
+ paddingRight: "48px"
460
+ };
461
+ var rowTitleStyle = {
462
+ fontSize: "14px",
463
+ fontWeight: "400",
464
+ lineHeight: "22px",
465
+ color: t.labelPrimary
466
+ };
467
+ var rowDescStyle = {
468
+ fontSize: "12px",
469
+ fontWeight: "400",
470
+ lineHeight: "18px",
471
+ color: t.labelTertiary
472
+ };
473
+ var pillSelectorStyle = {
474
+ display: "inline-flex",
475
+ alignItems: "center",
476
+ gap: "12px",
477
+ height: "36px",
478
+ padding: "0 14px",
479
+ border: "none",
480
+ borderRadius: "18px",
481
+ background: "var(--dsw-alias-bg-module-platform, #F5F6F7)",
482
+ font: "inherit",
483
+ fontSize: "14px",
484
+ lineHeight: "22px",
485
+ color: t.labelPrimary,
486
+ cursor: "pointer",
487
+ whiteSpace: "nowrap"
488
+ };
489
+ function SettingRow({ title, description, control }) {
490
+ return (0, import_react2.createElement)(
491
+ "div",
492
+ { "data-maestro-row": "", style: rowStyle },
493
+ (0, import_react2.createElement)("div", { "data-maestro-row-text": "", style: rowTextStyle }, (0, import_react2.createElement)("div", { style: rowTitleStyle }, title), description ? (0, import_react2.createElement)("div", { style: rowDescStyle }, description) : null),
494
+ (0, import_react2.createElement)("div", { "data-maestro-control": "", style: { flex: "none", display: "flex", alignItems: "center", justifyContent: "flex-end", gap: 8, minHeight: "36px" } }, control)
495
+ );
496
+ }
497
+ function ToggleRow({ title, description, checked, onChange, disabled }) {
498
+ const locked = disabled === true;
499
+ return (0, import_react2.createElement)(
500
+ "label",
501
+ {
502
+ "data-maestro-row": "",
503
+ "data-maestro-locked": locked ? "true" : void 0,
504
+ style: { ...rowStyle, cursor: locked ? "default" : "pointer", alignItems: "flex-start", opacity: locked ? 0.65 : 1 }
505
+ },
506
+ (0, import_react2.createElement)("input", { type: "checkbox", checked: checked === true, disabled: locked, "aria-disabled": locked ? "true" : void 0, onChange: (e) => {
507
+ if (!locked) onChange(e.target.checked);
508
+ }, style: { width: 16, height: 16, accentColor: t.primaryFill, marginTop: 4, flex: "none" } }),
509
+ (0, import_react2.createElement)("div", { "data-maestro-row-text": "", style: { ...rowTextStyle, paddingRight: "0" } }, (0, import_react2.createElement)("div", { style: rowTitleStyle }, title), description ? (0, import_react2.createElement)("div", { style: rowDescStyle }, description) : null)
510
+ );
511
+ }
512
+ function deepMergeGuard(base, patch) {
513
+ if (typeof base !== "object" || base === null || Array.isArray(base)) return patch;
514
+ if (typeof patch !== "object" || patch === null || Array.isArray(patch)) return patch;
515
+ const out = { ...base };
516
+ for (const key of Object.keys(patch)) out[key] = key in out ? deepMergeGuard(out[key], patch[key]) : patch[key];
517
+ return out;
518
+ }
519
+ function CommitField({ value, placeholder, onCommit, width, ariaLabel }) {
520
+ const [draft, setDraft] = (0, import_react2.useState)(value);
521
+ const [focused, setFocused] = (0, import_react2.useState)(false);
522
+ (0, import_react2.useEffect)(() => {
523
+ if (!focused) setDraft(value);
524
+ }, [value, focused]);
525
+ return (0, import_react2.createElement)(FieldInput, {
526
+ value: draft,
527
+ placeholder,
528
+ onChange: (e) => setDraft(e.target.value),
529
+ onFocus: () => setFocused(true),
530
+ onBlur: (e) => {
531
+ setFocused(false);
532
+ if (e.target.value !== value) onCommit(e.target.value);
533
+ },
534
+ onKeyDown: (e) => {
535
+ if (e.key === "Enter") e.target.blur();
536
+ },
537
+ "aria-label": ariaLabel ?? placeholder,
538
+ style: { width: width ?? 260 }
539
+ });
540
+ }
541
+ function ListEditor({ values, placeholder, onCommit, ariaLabel, emptyHint }) {
542
+ const [drafts, setDrafts] = (0, import_react2.useState)(values);
543
+ const [editing, setEditing] = (0, import_react2.useState)(false);
544
+ (0, import_react2.useEffect)(() => {
545
+ if (!editing) setDrafts(values);
546
+ }, [values, editing]);
547
+ const keyOf = (ds) => ds.join("\n");
548
+ const commitRows = (rows) => {
549
+ const cleaned = rows.map((s) => s.trim()).filter((s) => s !== "");
550
+ if (keyOf(cleaned) !== keyOf(values)) onCommit(cleaned);
551
+ setDrafts(cleaned.length > 0 ? cleaned : []);
552
+ setEditing(false);
553
+ };
554
+ return (0, import_react2.createElement)(
555
+ "div",
556
+ { "data-maestro-list": "", style: { display: "flex", flexDirection: "column", gap: 8, width: "100%", minWidth: 0 } },
557
+ drafts.length === 0 ? (0, import_react2.createElement)("p", { style: { ...captionStyle, margin: 0 } }, emptyHint ?? "No entries.") : null,
558
+ ...drafts.map(
559
+ (draft, i) => (0, import_react2.createElement)(
560
+ "div",
561
+ { key: `${i}`, style: { display: "flex", gap: 8, alignItems: "center", minWidth: 0 } },
562
+ (0, import_react2.createElement)(FieldInput, {
563
+ value: draft,
564
+ placeholder,
565
+ onChange: (e) => {
566
+ setEditing(true);
567
+ setDrafts((prev) => prev.map((d, j) => j === i ? e.target.value : d));
568
+ },
569
+ onFocus: () => setEditing(true),
570
+ onBlur: () => commitRows(drafts),
571
+ onKeyDown: (e) => {
572
+ if (e.key === "Enter") e.target.blur();
573
+ },
574
+ "aria-label": `${ariaLabel} ${i + 1}`,
575
+ style: { flex: "1 1 auto", minWidth: 0 }
576
+ }),
577
+ (0, import_react2.createElement)(
578
+ Button,
579
+ {
580
+ variant: "outline",
581
+ size: "sm",
582
+ onClick: () => commitRows(drafts.filter((_, j) => j !== i)),
583
+ "aria-label": `Remove ${ariaLabel} ${i + 1}`,
584
+ title: "Remove entry"
585
+ },
586
+ "\u2715"
587
+ )
588
+ )
589
+ ),
590
+ (0, import_react2.createElement)(
591
+ "div",
592
+ null,
593
+ (0, import_react2.createElement)(Button, { variant: "outline", size: "sm", onClick: () => {
594
+ setEditing(true);
595
+ setDrafts((prev) => [...prev, ""]);
596
+ } }, "+ Add entry")
597
+ )
598
+ );
599
+ }
600
+ function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }) {
601
+ const [guard, setGuard] = (0, import_react2.useState)({});
602
+ const [patterns, setPatterns] = (0, import_react2.useState)([]);
603
+ const [supervisorStatus, setSupervisorStatus] = (0, import_react2.useState)(null);
604
+ const [supervisorCfg, setSupervisorCfg] = (0, import_react2.useState)({});
605
+ const [activeTab, setActiveTab] = (0, import_react2.useState)("guard");
606
+ (0, import_react2.useEffect)(() => {
607
+ const css = `
608
+ /* Model override dropdown \u2014 prevent right-edge overlap */
609
+ [data-maestro-control] [data-maestro-menu] { left:auto !important; right:0 !important; }
610
+ [data-maestro-project-card] [data-maestro-menu] { left:auto !important; right:0 !important; }
611
+ [data-maestro-trigger-wrap] { min-width:0; }
612
+ /* Maestro nested tabs \u2014 unified with dsh-maestro-jobs (maestro-design pill bar) */
613
+ [data-maestro-tabs] { display:flex; gap:6px; overflow-x:auto; overflow-y:hidden; scrollbar-width:none; -webkit-overflow-scrolling:touch; overscroll-behavior-x:contain; touch-action:pan-x; padding:2px 2px 8px; margin:0 -2px 4px; border-bottom:1px solid var(--dsw-alias-border-l1, rgba(0,0,0,.08)); }
614
+ [data-maestro-tabs]::-webkit-scrollbar { display:none; width:0; height:0; }
615
+ [data-maestro-tab] { flex:none; min-width:fit-content; min-height:40px; padding:0 14px; border-radius:999px; border:1px solid var(--dsw-alias-border-l1, rgba(0,0,0,.12)); background:transparent; color:var(--dsw-alias-label-secondary); font-size:13px; line-height:20px; font-weight:500; font-family:inherit; white-space:nowrap; display:inline-flex; align-items:center; justify-content:center; gap:6px; cursor:pointer; -webkit-tap-highlight-color:transparent; transition: background 150ms ease, color 150ms ease, border-color 150ms ease; touch-action:manipulation; }
616
+ [data-maestro-tab][data-active="true"] { background:var(--dsw-specific-sidebar-nav-item-active, #EBEEF2); border-color:var(--dsw-specific-sidebar-nav-item-active, #EBEEF2); color:var(--dsw-alias-label-primary); font-weight:600; }
617
+ [data-maestro-tab]:hover { background:var(--dsw-alias-interactive-bg-hover, rgba(0,0,0,.06)); }
618
+ [data-maestro-tab][data-active="true"]:hover { background:var(--dsw-specific-sidebar-nav-item-active, #EBEEF2); }
619
+ [data-maestro-tab]:focus-visible { outline:2px solid var(--dsw-alias-state-business-primary, #4f6ef7); outline-offset:1px; }
620
+ [data-maestro-tab]:active { transform: scale(.97); }
621
+ [data-maestro-panel] { width:100%; min-width:0; box-sizing:border-box; }
622
+ /* label/input overlap fix: flex column gap + full width */
623
+ [data-maestro-panel] label { gap:6px !important; }
624
+ [data-maestro-row]:last-child { border-bottom:none !important; }
625
+ [data-maestro-panel] label > span { width:100% !important; box-sizing:border-box !important; }
626
+ @media (prefers-reduced-motion: reduce) {
627
+ [data-maestro-tab] { transition: none !important; }
628
+ [data-maestro-tab]:active { transform: none !important; }
629
+ }
630
+ @media (max-width: 640px) {
631
+ [data-maestro-settings-card] { max-width:100% !important; gap:6px !important; padding:0 2px !important; }
632
+ /* Guard status card: stack the summary above the Reset button \u2014 the
633
+ DSH shell keeps its nav column beside the content on phones, so the
634
+ panel is ~200px wide and a side-by-side row wraps the button. */
635
+ [data-maestro-guard-status] { flex-direction:column !important; align-items:stretch !important; gap:8px !important; }
636
+ [data-maestro-guard-status] button { align-self:stretch !important; white-space:normal !important; max-width:100% !important; box-sizing:border-box !important; }
637
+ [data-maestro-tabs] { gap:6px !important; padding:2px 2px 8px !important; margin:0 -2px 8px !important; }
638
+ [data-maestro-tab] { min-height:40px !important; height:auto !important; padding:0 12px !important; font-size:13px !important; }
639
+ [data-maestro-qr-row] { flex-direction:column !important; align-items:flex-start !important; }
640
+ [data-maestro-trigger-wrap] { max-width:100% !important; }
641
+ [data-maestro-menu] { min-width:0 !important; max-width:calc(100vw - 32px) !important; left:0 !important; right:auto !important; }
642
+ [data-maestro-control] [data-maestro-menu] { left:0 !important; right:auto !important; }
643
+ [data-maestro-project-card] [data-maestro-menu] { left:0 !important; right:auto !important; }
644
+ [data-maestro-panel] label { gap:8px !important; }
645
+ div[data-maestro-row] { flex-direction:column !important; align-items:stretch !important; padding:12px 0 !important; }
646
+ [data-maestro-row-text] { padding-right:0 !important; }
647
+ [data-maestro-control] { width:100% !important; justify-content:flex-start !important; }
648
+ [data-maestro-control] > span { width:100% !important; }
649
+ [data-maestro-control] select { width:100% !important; }
650
+ [data-maestro-project-grid] { grid-template-columns:1fr !important; }
651
+ [data-maestro-project-card] { padding:10px !important; }
652
+ [data-maestro-project-profile-row] { flex-direction:column !important; align-items:stretch !important; }
653
+ [data-maestro-project-profile-row] > label { flex:1 1 100% !important; width:100% !important; }
654
+ }
655
+ @media (max-width: 390px) {
656
+ [data-maestro-tab] { min-height:38px !important; height:auto !important; padding:0 10px !important; font-size:12px !important; }
657
+ }
658
+ /* iOS 16px field floor hold (dsh-maestro-mobile zoom guard).
659
+ Every text field on the page is held at 16px under
660
+ html[data-mobile-nav-ios] inside this same predicate, because iOS WebKit
661
+ magnifies the visual viewport for a focused field below 16px. An earlier
662
+ revision of this panel opted its own fields back out to inherit for a
663
+ compact scale - and every tap on those fields zoomed the page on
664
+ iPhone, with modal sheets never blurring back. Function beats pixels:
665
+ hold the same 16px here. The :not(#\u2026) clause matches every element (no node
666
+ carries that id) and exists purely for id-level specificity: the floor
667
+ carries ten :not([type=\u2026]) clauses, so an equal-specificity !important rule
668
+ keeps winning over competing field rules. Android and desktop never carry
669
+ the marker, so the compact scale they were designed with is untouched. */
670
+ @media (max-width: 1023px) and (pointer: coarse) {
671
+ html[data-mobile-nav-ios] [data-maestro-panel] input:not(#dsh-field-floor-opt-out),
672
+ html[data-mobile-nav-ios] [data-maestro-panel] textarea:not(#dsh-field-floor-opt-out),
673
+ html[data-mobile-nav-ios] [data-maestro-panel] select:not(#dsh-field-floor-opt-out) { font-size:16px !important; }
674
+ }
675
+ `;
676
+ const tag = document.createElement("style");
677
+ tag.dataset.plugin = "@ddtcorex/dsh-maestro-config";
678
+ tag.dataset.pluginCss = "maestro/mobile-tabs.css";
679
+ tag.textContent = css;
680
+ document.head.appendChild(tag);
681
+ return () => tag.remove();
682
+ }, []);
683
+ const unwrap = (res) => {
684
+ if (res && typeof res === "object" && "ok" in res) {
685
+ if (res.ok) return res.value;
686
+ throw new Error(res.error?.message ?? "RPC failed");
687
+ }
688
+ return res;
689
+ };
690
+ const cfgGet = async (domain) => {
691
+ if (!configRpcCall) throw new Error("config RPC not available");
692
+ const res = await configRpcCall("get", { domain });
693
+ return unwrap(res);
694
+ };
695
+ const cfgSet = async (domain, patch) => {
696
+ if (!configRpcCall) throw new Error("config RPC not available");
697
+ const res = await configRpcCall("set", { domain, patch });
698
+ return unwrap(res);
699
+ };
700
+ const saveGuard = async (patch) => {
701
+ setError(null);
702
+ setGuard((prev) => deepMergeGuard(prev ?? {}, patch));
703
+ try {
704
+ await cfgSet("guard", patch);
705
+ } catch (e) {
706
+ setError(e.message ?? String(e));
707
+ }
708
+ };
709
+ const saveGuardRule = async (ruleId, tier) => {
710
+ await saveGuard({ rules: ruleTierPatch(ruleId, tier) });
711
+ };
712
+ const resetGuardDefaults = async () => {
713
+ const rules = {};
714
+ for (const meta of RULE_META) rules[meta.id] = null;
715
+ await saveGuard({
716
+ gitProtection: { enabled: true, branches: ["master", "main"] },
717
+ publishBlocked: true,
718
+ cwdContainment: true,
719
+ credentialPaths: [],
720
+ rules,
721
+ protectedBranches: ["master", "main"],
722
+ protectedPaths: [],
723
+ workingDirContainment: { enabled: true, spillReads: true },
724
+ journal: { enabled: true, allowCounters: true, retainDays: 30, retainFiles: 14 }
725
+ });
726
+ };
727
+ const commitBlacklistPatterns = async (list) => {
728
+ setError(null);
729
+ setPatterns(list);
730
+ try {
731
+ await cfgSet("guardBlacklist", { patterns: list });
732
+ } catch (e) {
733
+ setError(e.message ?? String(e));
734
+ }
735
+ };
736
+ const saveSupervisorCfg = async (patch) => {
737
+ setError(null);
738
+ setSupervisorCfg((prev) => ({ ...prev, ...patch }));
739
+ if (typeof patch?.autoResumeEnabled === "boolean") {
740
+ setSupervisorStatus((prev) => prev ? { ...prev, autoResumeEnabled: patch.autoResumeEnabled } : prev);
741
+ }
742
+ try {
743
+ await cfgSet("supervisor", patch);
744
+ } catch (e) {
745
+ setError(e.message ?? String(e));
746
+ }
747
+ };
748
+ (0, import_react2.useEffect)(() => {
749
+ if (configRpcCall) {
750
+ Promise.all([cfgGet("guard").catch(() => ({})), cfgGet("guardBlacklist").catch(() => ({ patterns: [] })), cfgGet("supervisor").catch(() => ({}))]).then(([g, bl, sup]) => {
751
+ setGuard(g ?? {});
752
+ const pats = Array.isArray(bl?.patterns) ? bl.patterns.filter((p) => typeof p === "string") : [];
753
+ setPatterns(pats);
754
+ setSupervisorCfg(sup ?? {});
755
+ }).catch(() => {
756
+ });
757
+ }
758
+ if (supervisorRpcCall) {
759
+ supervisorRpcCall("status", {}).then((res) => setSupervisorStatus(unwrap(res))).catch(() => {
760
+ });
761
+ }
762
+ }, []);
763
+ const autoResumePinned = supervisorStatus?.autoResumePinned === true;
764
+ const autoResumeChecked = typeof supervisorStatus?.autoResumeEnabled === "boolean" ? supervisorStatus.autoResumeEnabled === true : supervisorCfg.autoResumeEnabled === true;
765
+ const TABS = [
766
+ { id: "guard", label: "Guard", icon: "shield" },
767
+ { id: "supervisor", label: "Supervisor", icon: "cpu" }
768
+ ];
769
+ const guardView = effectiveGuardView(guard);
770
+ const guardCustomCount = guardView.rules.filter((r) => r.source !== "default").length;
771
+ const tabContents = {
772
+ guard: (0, import_react2.createElement)(
773
+ "div",
774
+ { style: { display: "flex", flexDirection: "column" } },
775
+ // Status summary — what the stored document amounts to, in one line.
776
+ (0, import_react2.createElement)(
777
+ "div",
778
+ { style: { ...cardInsetStyle, marginTop: "12px" } },
779
+ (0, import_react2.createElement)("div", { style: { fontSize: 13, fontWeight: 600, color: t.labelPrimary } }, "Protection status"),
780
+ (0, import_react2.createElement)(
781
+ "div",
782
+ { "data-maestro-guard-status": "", style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12, flexWrap: "wrap", marginTop: 4 } },
783
+ (0, import_react2.createElement)(
784
+ "div",
785
+ { style: { fontSize: 12, color: t.labelSecondary, lineHeight: "16px" } },
786
+ `${guardCustomCount} of ${guardView.rules.length} rules customized \xB7 branches: ${guardView.protectedBranches.join(", ") || "defaults"} \xB7 journal ${guardView.journal.enabled ? `on (${guardView.journal.retainDays}d / ${guardView.journal.retainFiles} files)` : "off"}`
787
+ ),
788
+ (0, import_react2.createElement)(Button, { variant: "outline", size: "sm", onClick: resetGuardDefaults }, "Reset to defaults")
789
+ )
790
+ ),
791
+ ...["Git", "Publish", "Filesystem", "Network", "Self-protection"].map(
792
+ (group) => (0, import_react2.createElement)(
793
+ "div",
794
+ { key: group, style: { display: "flex", flexDirection: "column" } },
795
+ (0, import_react2.createElement)("div", { style: { fontSize: 13, fontWeight: 600, color: t.labelPrimary, padding: "12px 0 4px" } }, group),
796
+ ...RULE_META.filter((meta) => meta.group === group).map((meta) => {
797
+ const current = guardView.rules.find((r) => r.id === meta.id) ?? { ...meta, tier: meta.defaultTier, source: "default" };
798
+ const stateNote = current.source === "stored" ? " Currently customized." : current.source === "legacy" ? " Currently from an older setting." : ` Default: ${meta.defaultTier}.`;
799
+ return (0, import_react2.createElement)(SettingRow, {
800
+ title: meta.label,
801
+ description: `${meta.hint}${stateNote}${meta.locked ? " Locked: the guard never allows lowering this one." : ""}`,
802
+ control: (0, import_react2.createElement)(
803
+ "select",
804
+ {
805
+ value: current.source === "default" ? "default" : current.tier,
806
+ disabled: meta.locked === true,
807
+ onChange: (e) => {
808
+ const next = e.target.value;
809
+ void saveGuardRule(meta.id, next);
810
+ },
811
+ "aria-label": meta.label,
812
+ style: {
813
+ height: 36,
814
+ padding: "0 12px",
815
+ border: `1px solid ${t.borderL2}`,
816
+ borderRadius: 18,
817
+ background: "var(--dsw-alias-bg-module-platform, #F5F6F7)",
818
+ color: t.labelPrimary,
819
+ font: "inherit",
820
+ fontSize: 13
821
+ }
822
+ },
823
+ (0, import_react2.createElement)("option", { value: "default" }, `Default (${meta.defaultTier})`),
824
+ ...meta.locked === true ? [(0, import_react2.createElement)("option", { value: "deny" }, "Deny")] : [(0, import_react2.createElement)("option", { value: "allow" }, "Allow \u2014 run silently"), (0, import_react2.createElement)("option", { value: "journal" }, "Journal \u2014 run + record"), (0, import_react2.createElement)("option", { value: "ask" }, "Ask \u2014 prompt first"), (0, import_react2.createElement)("option", { value: "deny" }, "Deny \u2014 refuse")]
825
+ )
826
+ });
827
+ })
828
+ )
829
+ ),
830
+ // Lists + containment: live as soon as the next tool call runs.
831
+ (0, import_react2.createElement)("div", { style: { fontSize: 13, fontWeight: 600, color: t.labelPrimary, padding: "12px 0 4px" } }, "Scope"),
832
+ (0, import_react2.createElement)(
833
+ "div",
834
+ { style: { padding: "12px 0", borderBottom: `1px solid ${t.borderL2}`, display: "flex", flexDirection: "column", gap: 8 } },
835
+ (0, import_react2.createElement)("div", { style: rowTitleStyle }, "Protected branches"),
836
+ (0, import_react2.createElement)("div", { style: rowDescStyle }, "One branch per row. Empty restores the defaults (master, main). Each row commits on blur or Enter \u2014 never per keystroke."),
837
+ (0, import_react2.createElement)(ListEditor, {
838
+ values: guardView.protectedBranches,
839
+ placeholder: "main",
840
+ ariaLabel: "Protected branch",
841
+ emptyHint: "No branches listed \u2014 the defaults (master, main) apply.",
842
+ onCommit: (list) => {
843
+ void saveGuard({ protectedBranches: list });
844
+ }
845
+ })
846
+ ),
847
+ (0, import_react2.createElement)(
848
+ "div",
849
+ { style: { padding: "12px 0", borderBottom: `1px solid ${t.borderL2}`, display: "flex", flexDirection: "column", gap: 8 } },
850
+ (0, import_react2.createElement)("div", { style: rowTitleStyle }, "Extra protected paths"),
851
+ (0, import_react2.createElement)("div", { style: rowDescStyle }, "One path per row \u2014 paths may contain commas or spaces. These add to the built-in protected list \u2014 the defaults cannot be removed from here."),
852
+ (0, import_react2.createElement)(ListEditor, {
853
+ values: guardView.protectedPaths,
854
+ placeholder: "~/.config/credentials.yaml",
855
+ ariaLabel: "Protected path",
856
+ emptyHint: "No extra paths \u2014 only the built-in list applies.",
857
+ onCommit: (list) => {
858
+ void saveGuard({ protectedPaths: list });
859
+ }
860
+ })
861
+ ),
862
+ (0, import_react2.createElement)(ToggleRow, {
863
+ title: "Enforce working-directory containment",
864
+ description: "Keep file writes inside the session working directory (the OS temp dir stays exempt). Off turns the outside-writes rule off entirely.",
865
+ checked: guardView.containment.enabled === true,
866
+ onChange: (v) => {
867
+ void saveGuard({ workingDirContainment: { ...guardView.containment, enabled: v } });
868
+ }
869
+ }),
870
+ (0, import_react2.createElement)(ToggleRow, {
871
+ title: "Exempt runtime spill reads",
872
+ description: "Let agents read back their own oversized tool results from the OS temp dir \u2014 blocking those reads breaks the retrieval flow.",
873
+ checked: guardView.containment.spillReads === true,
874
+ onChange: (v) => {
875
+ void saveGuard({ workingDirContainment: { ...guardView.containment, spillReads: v } });
876
+ }
877
+ }),
878
+ // Journal: boot-time knobs — the guard reads them once at startup.
879
+ (0, import_react2.createElement)("div", { style: { fontSize: 13, fontWeight: 600, color: t.labelPrimary, padding: "12px 0 4px" } }, "Journal"),
880
+ (0, import_react2.createElement)("p", { style: { ...captionStyle, margin: "0 0 4px" } }, "Journal settings apply after a host restart \u2014 the guard reads them once at boot, unlike the rules above."),
881
+ (0, import_react2.createElement)(ToggleRow, {
882
+ title: "Keep a decision journal",
883
+ description: "Off stops all journal writes; the guard status tools go empty.",
884
+ checked: guardView.journal.enabled === true,
885
+ onChange: (v) => {
886
+ void saveGuard({ journal: { ...guardView.journal, enabled: v } });
887
+ }
888
+ }),
889
+ (0, import_react2.createElement)(ToggleRow, {
890
+ title: "Count silent allows",
891
+ description: "Fold allow decisions into one periodic aggregate line instead of dropping them.",
892
+ checked: guardView.journal.allowCounters === true,
893
+ onChange: (v) => {
894
+ void saveGuard({ journal: { ...guardView.journal, allowCounters: v } });
895
+ }
896
+ }),
897
+ (0, import_react2.createElement)(SettingRow, {
898
+ title: "Retain days",
899
+ description: "Keep journal archives newer than this many days.",
900
+ control: (0, import_react2.createElement)(CommitField, {
901
+ value: String(guardView.journal.retainDays),
902
+ placeholder: "30",
903
+ width: 160,
904
+ ariaLabel: "Retain days",
905
+ onCommit: (text) => {
906
+ const n = Number(text);
907
+ if (!Number.isInteger(n) || n <= 0) {
908
+ setError("Retention must be a positive whole number.");
909
+ return;
910
+ }
911
+ void saveGuard({ journal: { ...guardView.journal, retainDays: n } });
912
+ }
913
+ })
914
+ }),
915
+ (0, import_react2.createElement)(SettingRow, {
916
+ title: "Retain files",
917
+ description: "Keep at least this many newest archive files.",
918
+ control: (0, import_react2.createElement)(CommitField, {
919
+ value: String(guardView.journal.retainFiles),
920
+ placeholder: "14",
921
+ width: 160,
922
+ ariaLabel: "Retain files",
923
+ onCommit: (text) => {
924
+ const n = Number(text);
925
+ if (!Number.isInteger(n) || n <= 0) {
926
+ setError("Retention must be a positive whole number.");
927
+ return;
928
+ }
929
+ void saveGuard({ journal: { ...guardView.journal, retainFiles: n } });
930
+ }
931
+ })
932
+ }),
933
+ // Merged from the former Blacklist pill: an offline scan list, not a
934
+ // live gate — it belongs with the guard it is always confused with,
935
+ // labelled for what it actually is.
936
+ (0, import_react2.createElement)("div", { style: { fontSize: 13, fontWeight: 600, color: t.labelPrimary, padding: "12px 0 4px" } }, "Publish scan list (offline)"),
937
+ (0, import_react2.createElement)(
938
+ "div",
939
+ { style: { ...rowStyle, flexDirection: "column", alignItems: "stretch", gap: 8, borderBottom: "none" } },
940
+ (0, import_react2.createElement)("div", { style: rowTitleStyle }, "Blacklist patterns"),
941
+ (0, import_react2.createElement)("div", { style: rowDescStyle }, "One pattern per row. These do NOT gate any live tool call \u2014 the guard runtime never reads this list. It only feeds the offline scan a human runs by hand: node scripts/check-public-blacklist.mjs. Matching files are reported there, not blocked at runtime."),
942
+ (0, import_react2.createElement)(ListEditor, {
943
+ values: patterns,
944
+ placeholder: "example-project",
945
+ ariaLabel: "Blacklist pattern",
946
+ emptyHint: "No patterns \u2014 the offline scan reports nothing.",
947
+ onCommit: (list) => {
948
+ void commitBlacklistPatterns(list);
949
+ }
950
+ })
951
+ )
952
+ ),
953
+ supervisor: (0, import_react2.createElement)(
954
+ "div",
955
+ { style: { display: "flex", flexDirection: "column" } },
956
+ (0, import_react2.createElement)("div", { style: { padding: "12px 0", borderBottom: `1px solid ${t.borderL2}` } }, (0, import_react2.createElement)("p", { style: captionStyle }, "Check interval and Down threshold belong to the standalone dsh-web-supervisor daemon (systemd). They have no effect on the in-tree auto-resume plugin below unless that daemon is installed and running.")),
957
+ (0, import_react2.createElement)(SettingRow, { title: "Check interval", description: "Milliseconds between supervisor checks. Default 5000.", control: (0, import_react2.createElement)(FieldInput, { type: "number", value: supervisorCfg.intervalMs ?? "", placeholder: "5000", onChange: (e) => {
958
+ const v = e.target.value === "" ? void 0 : Number(e.target.value);
959
+ saveSupervisorCfg({ intervalMs: v });
960
+ }, style: { width: 160 } }) }),
961
+ (0, import_react2.createElement)(SettingRow, { title: "Down threshold", description: "Consecutive failures before marking a session as down.", control: (0, import_react2.createElement)(FieldInput, { type: "number", value: supervisorCfg.downThreshold ?? "", placeholder: "3", onChange: (e) => {
962
+ const v = e.target.value === "" ? void 0 : Number(e.target.value);
963
+ saveSupervisorCfg({ downThreshold: v });
964
+ }, style: { width: 160 } }) }),
965
+ (0, import_react2.createElement)(ToggleRow, {
966
+ title: "Auto-resume sessions",
967
+ description: autoResumePinned ? "Locked: this install pins auto-resume through its Cordis plugin config, which outranks this store. Change it where the supervisor row is mounted, not here." : "Automatically resume sessions interrupted by a DSH restart within the resume window. Shown as the supervisor reports it \u2014 plugin config, environment, and defaults folded together.",
968
+ // Effective value from the plugin, not the (possibly shadowed) store.
969
+ checked: autoResumeChecked,
970
+ onChange: (v) => saveSupervisorCfg({ autoResumeEnabled: v }),
971
+ disabled: autoResumePinned
972
+ })
973
+ )
974
+ };
975
+ return (0, import_react2.createElement)(
976
+ "div",
977
+ { "data-maestro-settings-card": "", style: { display: "flex", flexDirection: "column", gap: 8, width: "100%", maxWidth: 640, minWidth: 0, boxSizing: "border-box" } },
978
+ (0, import_react2.createElement)(
979
+ "div",
980
+ { style: { padding: "2px 2px 8px", display: "flex", gap: 10, alignItems: "flex-start" } },
981
+ // Shared BrandBadge — components/BrandMark.tsx, the workspace reference implementation
982
+ (0, import_react2.createElement)(BrandBadge, { style: { alignSelf: "flex-start", marginTop: 2 } }),
983
+ (0, import_react2.createElement)(
984
+ "div",
985
+ { style: { display: "flex", flexDirection: "column", minWidth: 0 } },
986
+ (0, import_react2.createElement)("div", { style: { fontSize: 15, fontWeight: 600, color: t.labelPrimary, lineHeight: "22px" } }, "Maestro"),
987
+ (0, import_react2.createElement)("div", { style: { fontSize: 12, color: t.labelSecondary, lineHeight: "16px", marginTop: 2 } }, "Guard and supervisor settings, via the shared Maestro store. Uses the same tokens and primitives as DSH settings.")
988
+ )
989
+ ),
990
+ (0, import_react2.createElement)("style", {}, "[data-maestro-logo]{background:#0A84FF !important; background-color:#0A84FF !important; color:#fff !important;}"),
991
+ (0, import_react2.createElement)(
992
+ "div",
993
+ { "data-maestro-tabs": "", role: "tablist", "aria-label": "Maestro settings sections" },
994
+ ...TABS.map((tab) => (0, import_react2.createElement)("button", { key: tab.id, "data-maestro-tab": "", "data-active": String(activeTab === tab.id), role: "tab", "aria-selected": activeTab === tab.id, onClick: (e) => {
995
+ setActiveTab(tab.id);
996
+ try {
997
+ e.currentTarget.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" });
998
+ } catch {
999
+ }
1000
+ } }, (0, import_react2.createElement)(TabIcon, { name: tab.icon }), tab.label))
1001
+ ),
1002
+ (0, import_react2.createElement)("div", { "data-maestro-panel": activeTab, style: { display: "flex", flexDirection: "column", gap: 10, minWidth: 0 } }, tabContents[activeTab]),
1003
+ error ? (0, import_react2.createElement)("p", { style: { color: t.stateError, fontSize: 12, margin: "8px 0 0", padding: "8px 10px", borderRadius: 8, background: "color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent)", border: `1px solid color-mix(in srgb, var(--dsw-alias-state-error-primary) 30%, transparent)` } }, error) : null
1004
+ );
1005
+ }
1006
+
1007
+ // src/client/config/settings-nav-icon.ts
1008
+ var SETTINGS_NAV_MARKER = "data-maestro-settings-nav";
1009
+ function registerSettingsNavIcon(label, root) {
1010
+ if (typeof document === "undefined" && root === void 0) {
1011
+ return () => {
1012
+ };
1013
+ }
1014
+ const scope = root ?? document;
1015
+ let disposed = false;
1016
+ const sync = () => {
1017
+ if (disposed) return;
1018
+ const currentLabel = label().trim();
1019
+ const buttons = scope.querySelectorAll('[role="dialog"] nav button');
1020
+ for (const button of Array.from(buttons)) {
1021
+ const el = button;
1022
+ const matches = currentLabel.length > 0 && button.textContent != null && button.textContent.trim() === currentLabel;
1023
+ if (matches) el.setAttribute(SETTINGS_NAV_MARKER, "");
1024
+ else el.removeAttribute(SETTINGS_NAV_MARKER);
1025
+ }
1026
+ };
1027
+ sync();
1028
+ let observer = null;
1029
+ if (typeof MutationObserver !== "undefined") {
1030
+ observer = new MutationObserver(sync);
1031
+ observer.observe(document.body, { childList: true, subtree: true, characterData: true });
1032
+ }
1033
+ return () => {
1034
+ disposed = true;
1035
+ if (observer !== null) observer.disconnect();
1036
+ for (const element of Array.from(scope.querySelectorAll(`[${SETTINGS_NAV_MARKER}]`))) {
1037
+ ;
1038
+ element.removeAttribute(SETTINGS_NAV_MARKER);
1039
+ }
1040
+ };
1041
+ }
1042
+
1043
+ // src/client/config/index.tsx
1044
+ var MAESTRO_SETTINGS_ORDER = 26;
1045
+ var SETTINGS_NAV_CSS = `
1046
+
1047
+ /* maestro: replace the settings-nav fallback gear with the Maestro M-logo glyph \u2014 same mark as components/BrandMark.tsx */
1048
+ [${SETTINGS_NAV_MARKER}] > svg:first-child,
1049
+ [${SETTINGS_NAV_MARKER}] > svg.zWKi1a_navIcon {
1050
+ display: none !important;
1051
+ }
1052
+
1053
+ [${SETTINGS_NAV_MARKER}]::before {
1054
+ content: '';
1055
+ flex: none;
1056
+ width: 16px;
1057
+ height: 16px;
1058
+ display: inline-block;
1059
+ background: currentColor;
1060
+ -webkit-mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
1061
+ mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
1062
+ }
1063
+ `;
1064
+ function installNavIconStyle() {
1065
+ const tag = document.createElement("style");
1066
+ tag.dataset.plugin = "@ddtcorex/dsh-maestro-config";
1067
+ tag.dataset.pluginCss = "maestro/settings-nav.css";
1068
+ tag.textContent = SETTINGS_NAV_CSS;
1069
+ document.head.appendChild(tag);
1070
+ return () => {
1071
+ document.querySelector('style[data-plugin-css="maestro/settings-nav.css"]')?.remove();
1072
+ };
1073
+ }
1074
+ function apply2(ctx) {
1075
+ const slots = ctx.get?.("slots");
1076
+ if (slots === void 0) return;
1077
+ const configRpcCall = (endpoint, payload, signal) => {
1078
+ const connection = ctx.get?.("connection");
1079
+ if (!connection?.rpc?.call) return Promise.reject(new Error("RPC not available"));
1080
+ return connection.rpc.call("/dsh-maestro-config", endpoint, payload, signal);
1081
+ };
1082
+ const supervisorRpcCall = (endpoint, payload, signal) => {
1083
+ const connection = ctx.get?.("connection");
1084
+ if (!connection?.rpc?.call) return Promise.reject(new Error("RPC not available"));
1085
+ return connection.rpc.call("/dsh-maestro-supervisor-resume", endpoint, payload, signal);
1086
+ };
1087
+ ctx.effect(() => registerSettingsNavIcon(() => "Maestro"), "maestro: settings nav icon");
1088
+ ctx.effect(installNavIconStyle, "maestro: settings nav css");
1089
+ slots.inject(
1090
+ "settings.section",
1091
+ () => slots.register(
1092
+ { name: "settings.section", id: "maestro", order: MAESTRO_SETTINGS_ORDER, label: () => "Maestro", inject: () => ({ configRpcCall, supervisorRpcCall }) },
1093
+ MaestroSettingsTab
1094
+ )
1095
+ );
1096
+ }
1097
+
1098
+ // src/client/sync/index.tsx
1099
+ var React5 = __toESM(require("react"), 1);
1100
+
1101
+ // src/client/sync/SyncPanel.tsx
1102
+ var React4 = __toESM(require("react"), 1);
1103
+
1104
+ // src/client/sync/use-sync.ts
1105
+ var React = __toESM(require("react"), 1);
1106
+
1107
+ // src/client/sync/ui.tsx
1108
+ var import_jsx_runtime = require("react/jsx-runtime");
1109
+ var RPC_CHANNEL = "/dsh-maestro-sync";
1110
+ var t2 = {
1111
+ bgBase: "var(--dsw-alias-bg-base)",
1112
+ bgLayer1: "var(--dsw-alias-bg-layer-1)",
1113
+ bgLayer2: "var(--dsw-alias-bg-layer-2)",
1114
+ bgLayer3: "var(--dsw-alias-bg-layer-3)",
1115
+ bgOverlay: "var(--dsw-alias-bg-overlay)",
1116
+ borderL1: "var(--dsw-alias-border-l1)",
1117
+ borderL2: "var(--dsw-alias-border-l2)",
1118
+ labelPrimary: "var(--dsw-alias-label-primary)",
1119
+ labelSecondary: "var(--dsw-alias-label-secondary)",
1120
+ labelTertiary: "var(--dsw-alias-label-tertiary)",
1121
+ labelFg: "var(--dsw-alias-label-primary-foreground)",
1122
+ primaryFill: "var(--dsw-alias-button-primary-fill)",
1123
+ primaryHover: "var(--dsw-alias-button-primary-hover)",
1124
+ interactiveHover: "var(--dsw-alias-interactive-bg-hover)",
1125
+ interactiveActive: "var(--dsw-alias-interactive-bg-active)",
1126
+ brand: "var(--dsw-alias-brand-primary)",
1127
+ stateError: "var(--dsw-alias-state-error-primary)",
1128
+ stateSuccess: "var(--dsw-alias-state-success-primary)",
1129
+ stateWarn: "var(--dsw-alias-state-warn-primary)",
1130
+ shadowLv3: "var(--dsw-shadow-lv3)"
1131
+ };
1132
+ function MaestroMark2(props) {
1133
+ const s = props.size ?? 16;
1134
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: s, height: s, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 11 L5 4 L8 9 L11 4 L14 11", stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" }) });
1135
+ }
1136
+ function MaestroLogo(props) {
1137
+ const outer = props.outer ?? 28;
1138
+ const size = props.size ?? 16;
1139
+ const radius = props.radius ?? 8;
1140
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1141
+ "span",
1142
+ {
1143
+ "data-maestro-logo": "",
1144
+ style: {
1145
+ width: outer,
1146
+ height: outer,
1147
+ borderRadius: radius,
1148
+ display: "inline-flex",
1149
+ alignItems: "center",
1150
+ justifyContent: "center",
1151
+ background: "var(--dsw-alias-brand-primary, #0A84FF)",
1152
+ backgroundColor: "#0A84FF",
1153
+ color: "#fff",
1154
+ flex: "none",
1155
+ border: "1px solid rgba(0, 0, 0, 0.08)",
1156
+ boxShadow: "0 0 0 1px var(--dsw-alias-border-l1)",
1157
+ boxSizing: "border-box",
1158
+ alignSelf: "flex-start",
1159
+ marginTop: 2
1160
+ },
1161
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MaestroMark2, { size })
1162
+ }
1163
+ );
1164
+ }
1165
+ var ICON_PATHS = {
1166
+ refresh: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3h-3", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }),
1167
+ download: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 2.5v7m0 0L5 6.5m3 3l3-3M3 12.5h10v1H3z", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }),
1168
+ upload: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 11.5v-7m0 0L5 7.5m3-3l3 3M3 12.5h10v1H3z", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }),
1169
+ swap: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4.5 3.5 2 6l2.5 2.5M2 6h7m2.5 5.5L14 9l-2.5-2.5M14 9H7", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round", strokeLinejoin: "round" }),
1170
+ file: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 13V3h6l4 4v6H3zM9 3v4h4", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }),
1171
+ folder: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 3.5h4.5l1.5 2H14v8H2v-10z", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }),
1172
+ star: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 2l1.8 3.7 4.2.6-3 3 .7 4.2L8 11.9 4.3 13.5l.7-4.2-3-3 4.2-.6z", fill: "none", stroke: "currentColor", strokeWidth: "1.2", strokeLinejoin: "round" }),
1173
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 3h10v8H6l-3 3V3z", fill: "none", stroke: "currentColor", strokeWidth: "1.2", strokeLinejoin: "round" }),
1174
+ calendar: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1175
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2.5", y: "4", width: "11", height: "9.5", rx: "1", fill: "none", stroke: "currentColor", strokeWidth: "1.2" }),
1176
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2.5 7.5h11M5.5 2.5v3m5-3v3", fill: "none", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round" })
1177
+ ] }),
1178
+ server: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1179
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2.5", y: "3", width: "11", height: "4", rx: "1", fill: "none", stroke: "currentColor", strokeWidth: "1.2" }),
1180
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2.5", y: "9", width: "11", height: "4", rx: "1", fill: "none", stroke: "currentColor", strokeWidth: "1.2" }),
1181
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5.5 5h.01M5.5 11h.01", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })
1182
+ ] }),
1183
+ clock: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1184
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "5.5", fill: "none", stroke: "currentColor", strokeWidth: "1.3" }),
1185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 5v3l2 1.5", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
1186
+ ] }),
1187
+ alert: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1188
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 2.5 14 13H2L8 2.5z", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }),
1189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 7v2.5M8 11.5v.01", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
1190
+ ] }),
1191
+ check: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3.5 8.2l2.8 2.8L12.5 4.8", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }),
1192
+ close: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 4l8 8M12 4l-8 8", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }),
1193
+ "chevron-down": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3.5 5.5 7 9l3.5-3.5", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }),
1194
+ "chevron-right": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5.5 3.5 9 7l-3.5 3.5", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }),
1195
+ external: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 3h7v7M13 3 7 9M13 9v4H3V3h4", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round", strokeLinejoin: "round" })
1196
+ };
1197
+ function Icon(props) {
1198
+ const size = props.size ?? 14;
1199
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", style: { flex: "none" }, children: ICON_PATHS[props.name] });
1200
+ }
1201
+ function Button2(props) {
1202
+ const { variant = "outline", size = "md", icon, busy, children, style, ...rest } = props;
1203
+ const base = {
1204
+ display: "inline-flex",
1205
+ alignItems: "center",
1206
+ justifyContent: "center",
1207
+ gap: 6,
1208
+ minHeight: size === "sm" ? 32 : 36,
1209
+ padding: size === "sm" ? "0 12px" : "0 14px",
1210
+ borderRadius: size === "sm" ? 16 : 18,
1211
+ border: "1px solid var(--dsw-alias-border-l2)",
1212
+ background: variant === "primary" ? "var(--dsw-alias-button-primary-fill)" : "transparent",
1213
+ color: variant === "primary" ? "var(--dsw-alias-label-primary-foreground)" : "var(--dsw-alias-label-primary)",
1214
+ font: "inherit",
1215
+ fontSize: 13,
1216
+ lineHeight: "20px",
1217
+ fontWeight: 500,
1218
+ cursor: "pointer",
1219
+ fontFamily: "inherit",
1220
+ whiteSpace: "nowrap",
1221
+ boxSizing: "border-box"
1222
+ };
1223
+ if (variant === "ghost") base.border = "1px solid transparent";
1224
+ const disabled = rest.disabled === true;
1225
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1226
+ "button",
1227
+ {
1228
+ type: "button",
1229
+ "data-sync-btn": "",
1230
+ "data-variant": variant,
1231
+ "data-size": size,
1232
+ ...rest,
1233
+ disabled: disabled || busy === true,
1234
+ style: { ...base, ...style ?? {} },
1235
+ onMouseEnter: (e) => {
1236
+ if (disabled || busy) return;
1237
+ if (variant === "primary") e.currentTarget.style.background = "var(--dsw-alias-button-primary-hover)";
1238
+ else e.currentTarget.style.background = "var(--dsw-alias-interactive-bg-hover)";
1239
+ },
1240
+ onMouseLeave: (e) => {
1241
+ if (variant === "primary") e.currentTarget.style.background = "var(--dsw-alias-button-primary-fill)";
1242
+ else e.currentTarget.style.background = variant === "outline" ? "transparent" : "transparent";
1243
+ },
1244
+ children: [
1245
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "sync-spin", "aria-hidden": "true", children: "\u25CC" }) : icon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: icon }) : null,
1246
+ children
1247
+ ]
1248
+ }
1249
+ );
1250
+ }
1251
+ function StatTile(props) {
1252
+ const toneColor = props.tone === "success" ? t2.stateSuccess : props.tone === "error" ? t2.stateError : props.tone === "warn" ? t2.stateWarn : void 0;
1253
+ const isBtn = props.onClick !== void 0;
1254
+ const inner = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1255
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-sync-stat-icon": "", style: { color: toneColor ?? "var(--dsw-alias-label-tertiary)", display: "inline-flex" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: props.icon }) }),
1256
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-sync-stat-value": "", style: { color: "var(--dsw-alias-label-primary)" }, children: props.value }),
1257
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-sync-stat-label": "", style: { color: "var(--dsw-alias-label-secondary)" }, children: props.label }),
1258
+ props.hint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-sync-stat-hint": "", style: { color: "var(--dsw-alias-label-tertiary)" }, children: props.hint }) : null
1259
+ ] });
1260
+ if (isBtn) {
1261
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", "data-sync-stat": "", role: "button", "aria-label": props.ariaLabel, onClick: props.onClick, children: inner });
1262
+ }
1263
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-sync-stat": "", children: inner });
1264
+ }
1265
+ function Badge(props) {
1266
+ const tone = props.tone ?? "default";
1267
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { "data-sync-badge": "", "data-tone": tone, children: [
1268
+ props.icon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, { name: props.icon, size: 11 }) : null,
1269
+ props.children
1270
+ ] });
1271
+ }
1272
+ function formatLastSync(v) {
1273
+ if (!v) return "never";
1274
+ try {
1275
+ const d = new Date(v);
1276
+ if (Number.isNaN(d.getTime())) return v;
1277
+ return d.toLocaleString();
1278
+ } catch {
1279
+ return v;
1280
+ }
1281
+ }
1282
+ function formatFile(path) {
1283
+ if (path.startsWith("dsh-maestro-memory/daily/")) {
1284
+ const date = path.replace("dsh-maestro-memory/daily/", "").replace(".md", "");
1285
+ try {
1286
+ const d = new Date(date);
1287
+ if (!isNaN(d.getTime())) return { icon: "calendar", title: `Daily notes \u2014 ${d.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" })}`, path, meta: "Daily" };
1288
+ } catch {
1289
+ }
1290
+ return { icon: "calendar", title: `Daily notes \u2014 ${date}`, path, meta: "Daily" };
1291
+ }
1292
+ if (path.startsWith("dsh-maestro-memory/projects/")) {
1293
+ const hash = path.split("/")[2] ?? "";
1294
+ return { icon: "folder", title: "Project memory", path, meta: hash.slice(0, 7) };
1295
+ }
1296
+ if (path === "dsh-maestro-memory/MEMORY.md") return { icon: "star", title: "Global memory", path, meta: "Global" };
1297
+ if (path.startsWith("sessions/")) {
1298
+ const hash = path.split("/")[1] ?? "";
1299
+ return { icon: "message", title: "Session", path, meta: hash.slice(0, 7) };
1300
+ }
1301
+ return { icon: "file", title: path.split("/").pop() ?? path, path, meta: path.split("/")[0] ?? "" };
1302
+ }
1303
+ function actionLabel(action) {
1304
+ switch (action?.action) {
1305
+ case "copy":
1306
+ return "copy";
1307
+ case "merge":
1308
+ return `merge +${action.added ?? 0} ${(action.added ?? 0) === 1 ? "new entry" : "new entries"}`;
1309
+ case "conflict":
1310
+ return "conflict";
1311
+ default:
1312
+ return "skip";
1313
+ }
1314
+ }
1315
+ function actionTone(action) {
1316
+ switch (action?.action) {
1317
+ case "copy":
1318
+ return "brand";
1319
+ case "merge":
1320
+ return "success";
1321
+ case "conflict":
1322
+ return "error";
1323
+ default:
1324
+ return "default";
1325
+ }
1326
+ }
1327
+ function humanSummary(status) {
1328
+ const localOnly = status?.localOnly ?? 0;
1329
+ const remoteOnly = status?.remoteOnly ?? 0;
1330
+ const both = status?.both ?? 0;
1331
+ if (localOnly === 0 && remoteOnly === 0 && both === 0) return "No eligible files found on either side.";
1332
+ return `${localOnly} only here \xB7 ${remoteOnly} only there \xB7 ${both} on both (content compared in Preview)`;
1333
+ }
1334
+
1335
+ // src/client/sync/use-sync.ts
1336
+ function useSync(ctx) {
1337
+ const [remoteHost, setRemoteHost] = React.useState("\u2026");
1338
+ const [remoteSource, setRemoteSource] = React.useState("default");
1339
+ const [lastSync, setLastSync] = React.useState(() => {
1340
+ try {
1341
+ return typeof localStorage !== "undefined" ? localStorage.getItem("dsh-maestro-sync:lastSync") : null;
1342
+ } catch {
1343
+ return null;
1344
+ }
1345
+ });
1346
+ const [status, setStatus] = React.useState(null);
1347
+ const [connection, setConnection] = React.useState(null);
1348
+ const [machines, setMachines] = React.useState(null);
1349
+ const [checking, setChecking] = React.useState(false);
1350
+ const [busy, setBusy] = React.useState(false);
1351
+ const [result, setResult] = React.useState(null);
1352
+ const [error2, setError2] = React.useState("");
1353
+ const [preview, setPreview] = React.useState(null);
1354
+ const [previewDirection, setPreviewDirection] = React.useState("pull");
1355
+ const [confirmOpen, setConfirmOpen] = React.useState(false);
1356
+ const [tunnelPreview, setTunnelPreview] = React.useState(null);
1357
+ const [tunnelConfirmOpen, setTunnelConfirmOpen] = React.useState(false);
1358
+ const [hostFieldError, setHostFieldError] = React.useState(null);
1359
+ const [biPreview, setBiPreview] = React.useState(null);
1360
+ const [biConfirmOpen, setBiConfirmOpen] = React.useState(false);
1361
+ const [actionLimit, setActionLimit] = React.useState(5);
1362
+ const [progress, setProgress] = React.useState(null);
1363
+ const cancelledRef = React.useRef(false);
1364
+ const [pages, setPages] = React.useState({
1365
+ localOnly: { files: [], total: 0, next: null, loaded: false },
1366
+ remoteOnly: { files: [], total: 0, next: null, loaded: false }
1367
+ });
1368
+ const call = React.useCallback(async (method, payload) => {
1369
+ const conn = ctx.connection ?? ctx.get?.("connection");
1370
+ if (!conn?.rpc?.call) throw new Error("RPC not available");
1371
+ const res = await conn.rpc.call(RPC_CHANNEL, method, payload);
1372
+ if (res && typeof res === "object" && "ok" in res) {
1373
+ if (res.ok) return res.value;
1374
+ const err = res.error;
1375
+ if (typeof err === "string") return { ok: false, error: err };
1376
+ return { ok: false, error: err?.message ?? "RPC failed", code: typeof err?.code === "string" ? err.code : void 0 };
1377
+ }
1378
+ return res;
1379
+ }, [ctx]);
1380
+ const loadPage = React.useCallback(
1381
+ async (bucket, cursor) => {
1382
+ try {
1383
+ const res = await call("status", { bucket, cursor, limit: 10 });
1384
+ if (!res) return;
1385
+ setPages((prev) => ({
1386
+ ...prev,
1387
+ [bucket]: {
1388
+ files: cursor === 0 ? res.files ?? [] : [...prev[bucket].files, ...res.files ?? []],
1389
+ total: res.total ?? prev[bucket].total,
1390
+ next: res.nextCursor ?? null,
1391
+ loaded: true
1392
+ }
1393
+ }));
1394
+ } catch {
1395
+ }
1396
+ },
1397
+ [call]
1398
+ );
1399
+ const loadStatus = React.useCallback(async () => {
1400
+ setError2("");
1401
+ setChecking(true);
1402
+ setStatus(null);
1403
+ try {
1404
+ const res = await call("status", {});
1405
+ if (res?.ok === false) {
1406
+ setError2(res?.error ?? "status failed");
1407
+ return;
1408
+ }
1409
+ setStatus(res);
1410
+ const conn = res?.connection ?? null;
1411
+ if (conn) setConnection(conn);
1412
+ else setConnection({ ok: true, host: res?.remoteHost ?? "kai@ssh.ddtcorex.com" });
1413
+ if (typeof res?.remoteHost === "string" && res.remoteHost) setRemoteHost(res.remoteHost);
1414
+ } catch (e) {
1415
+ setError2(e?.message ?? String(e));
1416
+ } finally {
1417
+ setChecking(false);
1418
+ }
1419
+ await loadPage("localOnly", 0);
1420
+ await loadPage("remoteOnly", 0);
1421
+ }, [call, loadPage]);
1422
+ React.useEffect(() => {
1423
+ void (async () => {
1424
+ try {
1425
+ const v = await call("getRemoteConfig", {});
1426
+ if (v?.remoteHost) setRemoteHost(String(v.remoteHost));
1427
+ if (typeof v?.source === "string") setRemoteSource(v.source);
1428
+ } catch {
1429
+ }
1430
+ })();
1431
+ }, [call]);
1432
+ const persistLastSync = React.useCallback((ts) => {
1433
+ setLastSync(ts);
1434
+ try {
1435
+ if (typeof localStorage !== "undefined") localStorage.setItem("dsh-maestro-sync:lastSync", ts);
1436
+ } catch {
1437
+ }
1438
+ }, []);
1439
+ const handlePreview = React.useCallback(
1440
+ async (direction) => {
1441
+ setBusy(true);
1442
+ setError2("");
1443
+ setResult(null);
1444
+ setActionLimit(5);
1445
+ setProgress({ phase: "listing", current: 0, total: 1 });
1446
+ try {
1447
+ const start = await call("previewStart", { direction });
1448
+ const jobId = start?.jobId;
1449
+ if (!jobId) {
1450
+ setError2(start?.error ?? "Preview failed to start");
1451
+ setProgress(null);
1452
+ return;
1453
+ }
1454
+ let done = false;
1455
+ while (!done && !cancelledRef.current) {
1456
+ const st = await call("previewStatus", { jobId });
1457
+ if (st?.status === "running" && st?.progress) {
1458
+ setProgress({ phase: st.progress.phase, current: st.progress.current, total: st.progress.total, file: st.progress.file });
1459
+ }
1460
+ if (st?.status === "done") {
1461
+ if (st.preview) {
1462
+ setPreview(st.preview);
1463
+ setPreviewDirection(direction);
1464
+ setConfirmOpen(true);
1465
+ } else {
1466
+ setError2("Preview finished without a result");
1467
+ }
1468
+ done = true;
1469
+ } else if (st?.status === "error") {
1470
+ setError2(st.error ?? "Preview failed");
1471
+ done = true;
1472
+ } else if (st?.ok === false) {
1473
+ setError2(st.error ?? "Preview failed");
1474
+ done = true;
1475
+ } else {
1476
+ await new Promise((r) => setTimeout(r, 700));
1477
+ }
1478
+ }
1479
+ } catch (e) {
1480
+ setError2(e?.message ?? String(e));
1481
+ } finally {
1482
+ setBusy(false);
1483
+ setProgress(null);
1484
+ }
1485
+ },
1486
+ [call]
1487
+ );
1488
+ const handleApply = React.useCallback(async () => {
1489
+ if (!preview?.previewId) return;
1490
+ setBusy(true);
1491
+ setError2("");
1492
+ const previewId = preview.previewId;
1493
+ const direction = previewDirection;
1494
+ try {
1495
+ const res = await call("apply", { previewId, direction, confirm: true });
1496
+ setConfirmOpen(false);
1497
+ setPreview(null);
1498
+ if (res?.ok === false) {
1499
+ const label = typeof res.code === "string" ? res.code : "apply failed";
1500
+ setError2(`${label}: ${res?.error ?? "apply failed"}`);
1501
+ setResult({ kind: "apply", ok: false, text: "Apply failed" });
1502
+ return;
1503
+ }
1504
+ setResult({ kind: "apply", ok: true, text: `Applied preview ${previewId.slice(0, 8)} \u2014 committed ${(res?.committed ?? []).length} file(s), +${res?.summary?.added ?? 0} entries` });
1505
+ persistLastSync((/* @__PURE__ */ new Date()).toISOString());
1506
+ void loadStatus();
1507
+ } catch (e) {
1508
+ setConfirmOpen(false);
1509
+ setPreview(null);
1510
+ setError2(e?.message ?? String(e));
1511
+ } finally {
1512
+ setBusy(false);
1513
+ }
1514
+ }, [preview, previewDirection, call, loadStatus, persistLastSync]);
1515
+ const cancelDialog = React.useCallback(() => {
1516
+ setConfirmOpen(false);
1517
+ setPreview(null);
1518
+ }, []);
1519
+ const handleBidirectionalPreview = React.useCallback(async () => {
1520
+ setBusy(true);
1521
+ setError2("");
1522
+ setResult(null);
1523
+ setActionLimit(5);
1524
+ setProgress({ phase: "planning", current: 0, total: 1 });
1525
+ try {
1526
+ const combined = await call("bidirectionalPreview", {});
1527
+ if (combined?.ok === false) {
1528
+ setError2(combined?.error ?? "Bidirectional preview failed");
1529
+ return;
1530
+ }
1531
+ if (!combined?.previewId) {
1532
+ setError2("Bidirectional preview finished without a result");
1533
+ return;
1534
+ }
1535
+ setBiPreview(combined);
1536
+ setBiConfirmOpen(true);
1537
+ } catch (e) {
1538
+ setError2(e?.message ?? String(e));
1539
+ } finally {
1540
+ setBusy(false);
1541
+ setProgress(null);
1542
+ }
1543
+ }, [call]);
1544
+ const handleBidirectionalApply = React.useCallback(async () => {
1545
+ if (!biPreview?.previewId) return;
1546
+ setBusy(true);
1547
+ setError2("");
1548
+ const previewId = biPreview.previewId;
1549
+ try {
1550
+ const res = await call("bidirectionalApply", { previewId, confirm: true });
1551
+ setBiConfirmOpen(false);
1552
+ setBiPreview(null);
1553
+ if (res?.ok === false) {
1554
+ const label = typeof res.code === "string" ? res.code : "apply failed";
1555
+ setError2(`${label}: ${res?.error ?? "apply failed"}`);
1556
+ setResult({ kind: "bidirectional", ok: false, text: "Both-ways apply failed" });
1557
+ return;
1558
+ }
1559
+ const pushAdded = res?.push?.summary?.added ?? 0;
1560
+ const pullAdded = res?.pull?.summary?.added ?? 0;
1561
+ const verification = res?.verification;
1562
+ const converged = verification && (verification.copied ?? 0) === 0 && (verification.merged ?? 0) === 0 && (verification.conflicts ?? 0) === 0;
1563
+ setResult({
1564
+ kind: "bidirectional",
1565
+ ok: true,
1566
+ text: `Both ways applied \u2014 push +${pushAdded}, pull +${pullAdded} entries \xB7 ${converged ? "converged" : "remaining delta, review and re-run"}`
1567
+ });
1568
+ persistLastSync((/* @__PURE__ */ new Date()).toISOString());
1569
+ void loadStatus();
1570
+ } catch (e) {
1571
+ setBiConfirmOpen(false);
1572
+ setBiPreview(null);
1573
+ setError2(e?.message ?? String(e));
1574
+ } finally {
1575
+ setBusy(false);
1576
+ }
1577
+ }, [biPreview, call, loadStatus, persistLastSync]);
1578
+ const cancelBidirectionalDialog = React.useCallback(() => {
1579
+ setBiConfirmOpen(false);
1580
+ setBiPreview(null);
1581
+ }, []);
1582
+ const saveRemoteHost = React.useCallback(
1583
+ async (host) => {
1584
+ setError2("");
1585
+ setHostFieldError(null);
1586
+ try {
1587
+ const res = await call("saveRemoteHost", { host });
1588
+ if (res?.ok === false) {
1589
+ const msg = res?.error ?? "save failed";
1590
+ setHostFieldError(msg);
1591
+ return { ok: false, error: msg };
1592
+ }
1593
+ if (res?.remoteHost) {
1594
+ setRemoteHost(String(res.remoteHost));
1595
+ setRemoteSource("settings");
1596
+ }
1597
+ return { ok: true };
1598
+ } catch (e) {
1599
+ const msg = e?.message ?? String(e);
1600
+ setHostFieldError(msg);
1601
+ return { ok: false, error: msg };
1602
+ }
1603
+ },
1604
+ [call]
1605
+ );
1606
+ const loadMachines = React.useCallback(async () => {
1607
+ try {
1608
+ const res = await call("checkMachines", {});
1609
+ if (res && typeof res === "object" && (res.localId !== void 0 || res.remoteId !== void 0)) {
1610
+ setMachines({ localId: res.localId ?? null, remoteId: res.remoteId ?? null, from: res.from, to: res.to, ok: res.ok, reason: res.reason ?? res.error });
1611
+ } else if (res && typeof res === "object" && (res.ok === false || typeof res.reason === "string" || typeof res.error === "string")) {
1612
+ setMachines({ localId: res.localId ?? null, remoteId: res.remoteId ?? null, from: res.from, to: res.to, ok: false, reason: typeof res.reason === "string" ? res.reason : String(res.error ?? "machines check failed") });
1613
+ } else {
1614
+ setMachines(null);
1615
+ }
1616
+ } catch (e) {
1617
+ setMachines({ localId: null, remoteId: null, ok: false, reason: e?.message ?? String(e) });
1618
+ }
1619
+ }, [call]);
1620
+ const checkConnection = React.useCallback(async () => {
1621
+ setError2("");
1622
+ setResult(null);
1623
+ setChecking(true);
1624
+ try {
1625
+ const res = await call("check", {});
1626
+ const conn = res?.connection ?? null;
1627
+ if (!conn || conn.ok !== true) {
1628
+ setConnection(conn ?? { ok: false, host: remoteHost, error: res?.error ?? "connection failed" });
1629
+ return false;
1630
+ }
1631
+ setConnection(conn);
1632
+ if (typeof res?.remoteHost === "string" && res.remoteHost) setRemoteHost(res.remoteHost);
1633
+ await loadStatus();
1634
+ await loadMachines();
1635
+ return true;
1636
+ } catch (e) {
1637
+ setConnection({ ok: false, host: remoteHost, error: e?.message ?? String(e) });
1638
+ return false;
1639
+ } finally {
1640
+ setChecking(false);
1641
+ }
1642
+ }, [call, loadStatus, loadMachines, remoteHost]);
1643
+ const handleTunnelRestorePreview = React.useCallback(async () => {
1644
+ setError2("");
1645
+ setResult(null);
1646
+ setBusy(true);
1647
+ try {
1648
+ const res = await call("tunnelRestorePreview", { side: "local" });
1649
+ if (res?.ok === false) {
1650
+ setError2(res?.error ?? "tunnel restore preview failed");
1651
+ return;
1652
+ }
1653
+ if (!res?.previewId) {
1654
+ setError2("Tunnel restore preview finished without a result");
1655
+ return;
1656
+ }
1657
+ setTunnelPreview(res);
1658
+ setTunnelConfirmOpen(true);
1659
+ } catch (e) {
1660
+ setError2(e?.message ?? String(e));
1661
+ } finally {
1662
+ setBusy(false);
1663
+ }
1664
+ }, [call]);
1665
+ const confirmTunnelRestore = React.useCallback(async () => {
1666
+ const previewId = tunnelPreview?.previewId;
1667
+ if (!previewId) return;
1668
+ setError2("");
1669
+ setBusy(true);
1670
+ try {
1671
+ const res = await call("tunnelRestore", { side: "local", previewId, confirm: true });
1672
+ setTunnelConfirmOpen(false);
1673
+ setTunnelPreview(null);
1674
+ if (res && res.ok) {
1675
+ setResult({ kind: "tunnel-restore", ok: true, text: `Tunnel restored from profile ${res.profile ?? "auto"} (local)` });
1676
+ } else {
1677
+ setError2(res?.error ?? "tunnel restore failed");
1678
+ }
1679
+ } catch (e) {
1680
+ setTunnelConfirmOpen(false);
1681
+ setTunnelPreview(null);
1682
+ setError2(e?.message ?? String(e));
1683
+ } finally {
1684
+ setBusy(false);
1685
+ }
1686
+ }, [tunnelPreview, call]);
1687
+ const cancelTunnelRestore = React.useCallback(() => {
1688
+ setTunnelConfirmOpen(false);
1689
+ setTunnelPreview(null);
1690
+ }, []);
1691
+ React.useEffect(() => {
1692
+ if (!confirmOpen && !biConfirmOpen && !tunnelConfirmOpen) return;
1693
+ const onKey = (e) => {
1694
+ if (e.key === "Escape") {
1695
+ cancelDialog();
1696
+ cancelBidirectionalDialog();
1697
+ cancelTunnelRestore();
1698
+ }
1699
+ };
1700
+ window.addEventListener("keydown", onKey);
1701
+ return () => window.removeEventListener("keydown", onKey);
1702
+ }, [confirmOpen, biConfirmOpen, tunnelConfirmOpen, cancelDialog, cancelBidirectionalDialog, cancelTunnelRestore]);
1703
+ return {
1704
+ remoteHost,
1705
+ remoteSource,
1706
+ lastSync,
1707
+ status,
1708
+ connection,
1709
+ machines,
1710
+ checking,
1711
+ busy,
1712
+ result,
1713
+ error: error2,
1714
+ hostFieldError,
1715
+ setHostFieldError,
1716
+ preview,
1717
+ previewDirection,
1718
+ confirmOpen,
1719
+ biPreview,
1720
+ biConfirmOpen,
1721
+ tunnelPreview,
1722
+ tunnelConfirmOpen,
1723
+ actionLimit,
1724
+ progress,
1725
+ pages,
1726
+ setActionLimit,
1727
+ setError: setError2,
1728
+ setResult,
1729
+ loadStatus,
1730
+ loadPage,
1731
+ saveRemoteHost,
1732
+ checkConnection,
1733
+ loadMachines,
1734
+ handleTunnelRestorePreview,
1735
+ confirmTunnelRestore,
1736
+ cancelTunnelRestore,
1737
+ handlePreview,
1738
+ handleApply,
1739
+ cancelDialog,
1740
+ handleBidirectionalPreview,
1741
+ handleBidirectionalApply,
1742
+ cancelBidirectionalDialog
1743
+ };
1744
+ }
1745
+
1746
+ // src/client/sync/use-backup.ts
1747
+ var React2 = __toESM(require("react"), 1);
1748
+ function useBackupTarget(ctx) {
1749
+ const [status, setStatus] = React2.useState(null);
1750
+ const [checking, setChecking] = React2.useState(true);
1751
+ const [busy, setBusy] = React2.useState(false);
1752
+ const [error2, setError2] = React2.useState("");
1753
+ const [backupPreview, setBackupPreview] = React2.useState(null);
1754
+ const [restorePreview, setRestorePreview] = React2.useState(null);
1755
+ const [gcReport, setGcReport] = React2.useState(null);
1756
+ const [confirmOpen, setConfirmOpen] = React2.useState(null);
1757
+ const call = React2.useCallback(async (method, payload) => {
1758
+ const conn = ctx.connection ?? ctx.get?.("connection");
1759
+ const res = await conn.rpc.call(RPC_CHANNEL, method, payload);
1760
+ if (res && typeof res === "object" && "ok" in res) return res;
1761
+ return { ok: true, value: res };
1762
+ }, [ctx]);
1763
+ const loadStatus = React2.useCallback(async () => {
1764
+ setChecking(true);
1765
+ setError2("");
1766
+ try {
1767
+ const res = await call("backupStatus", {});
1768
+ if (res.ok) setStatus(res.value);
1769
+ else setError2(res.error?.message ?? "backup status failed");
1770
+ } catch (e) {
1771
+ setError2(e?.message ?? String(e));
1772
+ } finally {
1773
+ setChecking(false);
1774
+ }
1775
+ }, [call]);
1776
+ const previewBackup = React2.useCallback(async () => {
1777
+ setBusy(true);
1778
+ setError2("");
1779
+ setBackupPreview(null);
1780
+ try {
1781
+ const res = await call("backupPreview", {});
1782
+ if (res.ok) {
1783
+ setBackupPreview(res.value);
1784
+ setConfirmOpen("backup");
1785
+ } else setError2(res.error?.message ?? "backup preview failed");
1786
+ } catch (e) {
1787
+ setError2(e?.message ?? String(e));
1788
+ } finally {
1789
+ setBusy(false);
1790
+ }
1791
+ }, [call]);
1792
+ const applyBackup = React2.useCallback(async () => {
1793
+ if (!backupPreview?.previewId) return;
1794
+ setBusy(true);
1795
+ try {
1796
+ const res = await call("backupApply", { previewId: backupPreview.previewId, confirm: true });
1797
+ setConfirmOpen(null);
1798
+ setBackupPreview(null);
1799
+ if (!res.ok) setError2(res.error?.message ?? "backup apply failed");
1800
+ void loadStatus();
1801
+ } catch (e) {
1802
+ setError2(e?.message ?? String(e));
1803
+ } finally {
1804
+ setBusy(false);
1805
+ }
1806
+ }, [backupPreview, call, loadStatus]);
1807
+ const previewRestore = React2.useCallback(
1808
+ async (mode) => {
1809
+ setBusy(true);
1810
+ setError2("");
1811
+ try {
1812
+ const res = await call("restorePreview", { mode });
1813
+ if (res.ok) {
1814
+ setRestorePreview(res.value);
1815
+ setConfirmOpen("restore");
1816
+ } else setError2(res.error?.message ?? "restore preview failed");
1817
+ } catch (e) {
1818
+ setError2(e?.message ?? String(e));
1819
+ } finally {
1820
+ setBusy(false);
1821
+ }
1822
+ },
1823
+ [call]
1824
+ );
1825
+ const applyRestore = React2.useCallback(
1826
+ async (mode, destDir) => {
1827
+ if (!restorePreview?.previewId) return;
1828
+ setBusy(true);
1829
+ try {
1830
+ const res = await call("restoreApply", { previewId: restorePreview.previewId, mode, destDir, confirm: true });
1831
+ setConfirmOpen(null);
1832
+ setRestorePreview(null);
1833
+ if (!res.ok) setError2(res.error?.message ?? "restore apply failed");
1834
+ if (mode === "in-place") void loadStatus();
1835
+ } catch (e) {
1836
+ setError2(e?.message ?? String(e));
1837
+ } finally {
1838
+ setBusy(false);
1839
+ }
1840
+ },
1841
+ [restorePreview, call, loadStatus]
1842
+ );
1843
+ const previewGc = React2.useCallback(async () => {
1844
+ setBusy(true);
1845
+ setError2("");
1846
+ try {
1847
+ const res = await call("backupGcPreview", {});
1848
+ if (res.ok) {
1849
+ setGcReport(res.value);
1850
+ setConfirmOpen("gc");
1851
+ } else setError2(res.error?.message ?? "gc preview failed");
1852
+ } catch (e) {
1853
+ setError2(e?.message ?? String(e));
1854
+ } finally {
1855
+ setBusy(false);
1856
+ }
1857
+ }, [call]);
1858
+ const applyGc = React2.useCallback(async () => {
1859
+ if (!gcReport?.previewId) return;
1860
+ setBusy(true);
1861
+ try {
1862
+ const res = await call("backupGcApply", { previewId: gcReport.previewId, confirm: true });
1863
+ setConfirmOpen(null);
1864
+ setGcReport(null);
1865
+ if (!res.ok) setError2(res.error?.message ?? "gc apply failed");
1866
+ void loadStatus();
1867
+ } catch (e) {
1868
+ setError2(e?.message ?? String(e));
1869
+ } finally {
1870
+ setBusy(false);
1871
+ }
1872
+ }, [gcReport, call, loadStatus]);
1873
+ const cancelDialog = React2.useCallback(() => {
1874
+ setConfirmOpen(null);
1875
+ setBackupPreview(null);
1876
+ setRestorePreview(null);
1877
+ setGcReport(null);
1878
+ }, []);
1879
+ const saveR2Config = React2.useCallback(
1880
+ async (fields) => {
1881
+ setError2("");
1882
+ try {
1883
+ const res = await call("saveR2Config", fields);
1884
+ if (!res.ok) {
1885
+ const msg = res.error?.message ?? "save failed";
1886
+ setError2(msg);
1887
+ return { ok: false, error: msg };
1888
+ }
1889
+ await loadStatus();
1890
+ return { ok: true };
1891
+ } catch (e) {
1892
+ const msg = e?.message ?? String(e);
1893
+ setError2(msg);
1894
+ return { ok: false, error: msg };
1895
+ }
1896
+ },
1897
+ [call, loadStatus]
1898
+ );
1899
+ React2.useEffect(() => {
1900
+ void loadStatus();
1901
+ }, [loadStatus]);
1902
+ const configured = status?.configured === true;
1903
+ return {
1904
+ status,
1905
+ checking,
1906
+ busy,
1907
+ error: error2,
1908
+ backupPreview,
1909
+ restorePreview,
1910
+ gcReport,
1911
+ confirmOpen,
1912
+ canBackup: configured && !checking && !busy,
1913
+ loadStatus,
1914
+ saveR2Config,
1915
+ previewBackup,
1916
+ applyBackup,
1917
+ previewRestore,
1918
+ applyRestore,
1919
+ previewGc,
1920
+ applyGc,
1921
+ cancelDialog
1922
+ };
1923
+ }
1924
+
1925
+ // src/client/sync/R2SyncPanel.tsx
1926
+ var React3 = __toESM(require("react"), 1);
1927
+
1928
+ // src/client/sync/confirm-dialog.tsx
1929
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1930
+ function tunnelLine(v) {
1931
+ if (v === null || v === void 0) return "not set";
1932
+ if (typeof v !== "object") return String(v);
1933
+ const keys = Object.keys(v).sort();
1934
+ if (keys.length === 0) return "not set";
1935
+ return keys.map((k) => `${k}=${String(v[k])}`).join(" \xB7 ");
1936
+ }
1937
+ function TunnelRestoreDialog(props) {
1938
+ const { preview, busy, onCancel, onConfirm } = props;
1939
+ const expiresIn = preview?.expiresAt ? Math.max(0, Math.round((new Date(preview.expiresAt).getTime() - Date.now()) / 1e3)) : 0;
1940
+ const changed = preview?.changed === true;
1941
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-dialog-overlay": "", "data-testid": "sync-tunnel-dialog-overlay", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { role: "dialog", "aria-modal": "true", "aria-labelledby": "sync-tunnel-dialog-title", "data-sync-dialog": "", "data-testid": "sync-tunnel-dialog", children: [
1942
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-top": "", children: [
1943
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-heading": "", children: [
1944
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { id: "sync-tunnel-dialog-title", "data-sync-dialog-title": "", children: [
1945
+ "Restore tunnel \u2014 profile ",
1946
+ preview?.profile ?? "?"
1947
+ ] }),
1948
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-desc": "", children: [
1949
+ "Rewrites ",
1950
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { children: "domains.tunnel" }),
1951
+ " in the shared settings store on this machine \xB7 preview expires in ",
1952
+ expiresIn,
1953
+ "s"
1954
+ ] })
1955
+ ] }),
1956
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "data-sync-dialog-close": "", "aria-label": "Cancel", onClick: onCancel, disabled: busy, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close" }) })
1957
+ ] }),
1958
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-planlist": "", "data-testid": "sync-tunnel-plan", children: [
1959
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-action-row": "", "data-sync-planrow": "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-planfile": "", children: [
1960
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-title": "", children: "Current value" }),
1961
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-path": "", "data-testid": "sync-tunnel-current", children: tunnelLine(preview?.current) })
1962
+ ] }) }),
1963
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-action-row": "", "data-sync-planrow": "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-planfile": "", children: [
1964
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-title": "", children: "Restored from profile" }),
1965
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-path": "", "data-testid": "sync-tunnel-desired", children: tunnelLine(preview?.desired) })
1966
+ ] }) }),
1967
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-planlist-note": "", children: changed ? "Only domains.tunnel changes \u2014 every other domain (jobs, notifier, guard, \u2026) is left untouched." : "The stored value already matches this profile \u2014 confirming is a no-op." })
1968
+ ] }),
1969
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-actions": "", children: [
1970
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button2, { variant: "outline", onClick: onCancel, disabled: busy, "aria-label": "Cancel", children: "Cancel" }),
1971
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button2, { variant: "primary", "data-testid": "sync-tunnel-confirm", onClick: onConfirm, disabled: busy, busy, "aria-label": "Restore tunnel", children: busy ? "Restoring\u2026" : "Restore tunnel" })
1972
+ ] })
1973
+ ] }) });
1974
+ }
1975
+ function ConfirmDialog(props) {
1976
+ const { preview, previewDirection, remoteHost, busy, actionLimit, planAgeSecs, onShowMore, onCancel, onApply, title, targetLabel, projectedTitle, projectedPreview, projectedNote, applyLabel } = props;
1977
+ const actions = (preview?.actions ?? []).slice(0, actionLimit);
1978
+ const hasMore = (preview?.actions?.length ?? 0) > actionLimit;
1979
+ const summary = preview?.summary ?? {};
1980
+ const sessionCounts = preview?.sessionCounts;
1981
+ const previewId = String(preview?.previewId ?? "").slice(0, 8);
1982
+ const sessionLine = sessionCounts ? `${sessionCounts.added ?? 0} added \xB7 ${sessionCounts.updated ?? 0} updated \xB7 ${sessionCounts.deleted ?? 0} deleted \xB7 ${sessionCounts.identical ?? 0} identical` : null;
1983
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-dialog-overlay": "", "data-testid": "sync-dialog-overlay", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { role: "dialog", "aria-modal": "true", "aria-labelledby": "sync-dialog-title", "data-sync-dialog": "", "data-testid": "sync-dialog", children: [
1984
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-top": "", children: [
1985
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-heading": "", children: [
1986
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { id: "sync-dialog-title", "data-sync-dialog-title": "", children: title ?? `Apply ${previewDirection} \u2014 preview ${previewId}` }),
1987
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-desc": "", children: [
1988
+ targetLabel ?? remoteHost,
1989
+ " \xB7 plan ",
1990
+ planAgeSecs,
1991
+ "s before expiry \xB7 ",
1992
+ summary.copied ?? 0,
1993
+ " copy \xB7 ",
1994
+ summary.merged ?? 0,
1995
+ " merge (+",
1996
+ summary.added ?? 0,
1997
+ " added) \xB7 ",
1998
+ summary.skipped ?? 0,
1999
+ " skip \xB7 ",
2000
+ summary.conflicts ?? 0,
2001
+ " conflict"
2002
+ ] })
2003
+ ] }),
2004
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "data-sync-dialog-close": "", "aria-label": "Cancel", onClick: onCancel, disabled: busy, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "close" }) })
2005
+ ] }),
2006
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-planlist": "", children: [
2007
+ sessionLine ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-sessioncounts": "", "data-testid": "sync-session-counts", children: [
2008
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-sessioncounts-lbl": "", children: [
2009
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: "swap" }),
2010
+ "Sessions (counted by checksum)"
2011
+ ] }),
2012
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-sessioncounts-line": "", children: sessionLine })
2013
+ ] }) : null,
2014
+ actions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-empty": "", children: "Nothing to do \u2014 every file is already in sync." }) : actions.map((a) => {
2015
+ const f = formatFile(a.path);
2016
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-action-row": "", title: a.path, "data-sync-planrow": "", children: [
2017
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-icon": "", style: { color: "var(--dsw-alias-label-tertiary)" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: f.icon }) }),
2018
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-planfile": "", children: [
2019
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-planfile-title": "", children: [
2020
+ f.title,
2021
+ " \u2014 ",
2022
+ actionLabel(a)
2023
+ ] }),
2024
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-path": "", children: a.path })
2025
+ ] }),
2026
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planrow-meta": "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-badge": "", "data-tone": actionTone(a), children: a.reason ?? a.action }) })
2027
+ ] }, a.path);
2028
+ }),
2029
+ hasMore ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-planmore": "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button2, { size: "sm", variant: "ghost", onClick: onShowMore, "aria-label": "Show more actions", children: "Show more" }) }) : null
2030
+ ] }),
2031
+ projectedPreview ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-planlist": "", "data-testid": "sync-projected-plan", children: [
2032
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-planlist-title": "", children: projectedTitle ?? "Pull plan (projected)" }),
2033
+ projectedNote ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-sync-planlist-note": "", children: projectedNote }) : null,
2034
+ (projectedPreview?.actions ?? []).slice(0, actionLimit).map((a) => {
2035
+ const f = formatFile(a.path);
2036
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-action-row": "", title: a.path, "data-sync-planrow": "", children: [
2037
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-icon": "", style: { color: "var(--dsw-alias-label-tertiary)" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { name: f.icon }) }),
2038
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-planfile": "", children: [
2039
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { "data-sync-planfile-title": "", children: [
2040
+ f.title,
2041
+ " \u2014 ",
2042
+ actionLabel(a)
2043
+ ] }),
2044
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planfile-path": "", children: a.path })
2045
+ ] }),
2046
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-planrow-meta": "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-sync-badge": "", "data-tone": actionTone(a), children: a.reason ?? a.action }) })
2047
+ ] }, a.path);
2048
+ })
2049
+ ] }) : null,
2050
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-sync-dialog-actions": "", children: [
2051
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button2, { variant: "outline", onClick: onCancel, disabled: busy, "aria-label": "Cancel", children: "Cancel" }),
2052
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button2, { variant: "primary", onClick: onApply, disabled: busy, busy, "aria-label": applyLabel ?? `Apply ${previewDirection}`, children: busy ? "Applying\u2026" : applyLabel ?? `Apply ${previewDirection} \u2014 ${summary.copied ?? 0} copy, ${summary.merged ?? 0} merge` })
2053
+ ] })
2054
+ ] }) });
2055
+ }
2056
+
2057
+ // src/client/sync/R2SyncPanel.tsx
2058
+ var import_jsx_runtime3 = require("react/jsx-runtime");
2059
+ var sourceLabel = (s) => s === "env" ? "Env" : s === "file" ? "Private file" : "Not configured";
2060
+ function field(input) {
2061
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-field": "", children: [
2062
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { "data-r2-field-label": "", htmlFor: input.id, children: input.label }),
2063
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2064
+ "input",
2065
+ {
2066
+ id: input.id,
2067
+ "data-r2-field-input": "",
2068
+ "data-testid": input.id,
2069
+ value: input.value,
2070
+ onChange: (e) => input.onChange(e.target.value),
2071
+ placeholder: input.placeholder,
2072
+ autoComplete: "off",
2073
+ autoCapitalize: "off",
2074
+ spellCheck: false,
2075
+ disabled: input.disabled,
2076
+ "aria-invalid": input.error ? "true" : void 0,
2077
+ "aria-describedby": input.error ? `${input.id}-error` : void 0
2078
+ }
2079
+ ),
2080
+ input.error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { id: `${input.id}-error`, "data-r2-field-error": "", role: "alert", "data-testid": `${input.id}-error`, children: input.error }) : null,
2081
+ input.hint ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-r2-field-hint": "", children: input.hint }) : null
2082
+ ] });
2083
+ }
2084
+ function routeR2FieldError(msg) {
2085
+ const m = /^\s*(?:invalid\s+)?(accountId|endpoint|region|bucket|prefix|provider)\b/i.exec(msg);
2086
+ if (!m || m[1] === void 0) return null;
2087
+ return { field: m[1], message: msg };
2088
+ }
2089
+ function ConfigForm(props) {
2090
+ const b = props.b;
2091
+ const st = b.status;
2092
+ const [provider, setProvider] = React3.useState("r2");
2093
+ const [accountId, setAccountId] = React3.useState("");
2094
+ const [endpoint, setEndpoint] = React3.useState("");
2095
+ const [region, setRegion] = React3.useState("");
2096
+ const [bucket, setBucket] = React3.useState("");
2097
+ const [prefix, setPrefix] = React3.useState("");
2098
+ const [fieldErrors, setFieldErrors] = React3.useState({});
2099
+ const [primed, setPrimed] = React3.useState(false);
2100
+ React3.useEffect(() => {
2101
+ if (primed || !st) return;
2102
+ const r = st.r2;
2103
+ setProvider(r?.provider === "aws" ? "aws" : "r2");
2104
+ setAccountId("");
2105
+ setEndpoint(r?.endpoint ?? "");
2106
+ setRegion(r?.region ?? "");
2107
+ setBucket(r?.bucket ?? "");
2108
+ setPrefix(st.prefix ?? "");
2109
+ setPrimed(true);
2110
+ }, [st, primed]);
2111
+ const busy = b.busy || b.checking;
2112
+ const bind = (key, set) => (v) => {
2113
+ set(v);
2114
+ setFieldErrors((prev) => {
2115
+ if (!(key in prev)) return prev;
2116
+ const next = { ...prev };
2117
+ delete next[key];
2118
+ return next;
2119
+ });
2120
+ };
2121
+ const save = async () => {
2122
+ setFieldErrors({});
2123
+ const res = await b.saveR2Config({ provider, accountId, endpoint, region, bucket, prefix });
2124
+ if (!res.ok) {
2125
+ const routed = routeR2FieldError(res.error ?? "");
2126
+ if (routed) setFieldErrors({ [routed.field]: routed.message });
2127
+ }
2128
+ };
2129
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-config": "", children: [
2130
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-r2-config-label": "", children: "Backup target" }),
2131
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-field": "", children: [
2132
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { "data-r2-field-label": "", htmlFor: "r2-cfg-provider", children: "Provider" }),
2133
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-r2-provider-row": "", role: "radiogroup", "aria-label": "Provider", children: ["r2", "aws"].map((p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2134
+ "button",
2135
+ {
2136
+ type: "button",
2137
+ "data-testid": `r2-cfg-provider-${p}`,
2138
+ "data-r2-provider-opt": "",
2139
+ "aria-pressed": provider === p,
2140
+ disabled: busy,
2141
+ onClick: () => setProvider(p),
2142
+ children: p === "r2" ? "Cloudflare R2" : "AWS S3"
2143
+ },
2144
+ p
2145
+ )) })
2146
+ ] }),
2147
+ provider === "r2" ? field({ id: "r2-cfg-account", label: "Account ID", value: accountId, placeholder: "32 hex chars \u2014 leave empty to keep the default endpoint", onChange: bind("accountId", setAccountId), disabled: busy, error: fieldErrors.accountId }) : null,
2148
+ field({ id: "r2-cfg-endpoint", label: "Endpoint", value: endpoint, placeholder: "https://<account>.r2.cloudflarestorage.com", onChange: bind("endpoint", setEndpoint), disabled: busy, error: fieldErrors.endpoint }),
2149
+ field({ id: "r2-cfg-region", label: "Region", value: region, placeholder: "auto", onChange: bind("region", setRegion), disabled: busy, error: fieldErrors.region }),
2150
+ field({ id: "r2-cfg-bucket", label: "Bucket", value: bucket, placeholder: "your-bucket-name", onChange: bind("bucket", setBucket), disabled: busy, error: fieldErrors.bucket }),
2151
+ field({ id: "r2-cfg-prefix", label: "Prefix", value: prefix, placeholder: "your-prefix/", onChange: bind("prefix", setPrefix), disabled: busy, error: fieldErrors.prefix }),
2152
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-r2-config-row": "", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Button2, { "data-testid": "r2-save-config", variant: "primary", disabled: busy, busy: b.busy, onClick: () => void save(), children: b.busy ? "Saving\u2026" : "Save target" }) }),
2153
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-r2-config-hint": "", children: "Access keys are never entered here \u2014 set R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY env or the 0600 sidecar file." })
2154
+ ] });
2155
+ }
2156
+ function R2SyncPanel(props) {
2157
+ const b = props.b;
2158
+ const st = b.status;
2159
+ const [moreOpen, setMoreOpen] = React3.useState(false);
2160
+ const closeMore = () => setMoreOpen(false);
2161
+ const banner = () => {
2162
+ if (!st) return null;
2163
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-summary": "", children: [
2164
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Badge, { tone: st.configured ? "success" : "error", children: st.configured ? sourceLabel(st.source) : sourceLabel("none") }),
2165
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-r2-muted": "", children: st.configured ? `${st.bucket} \xB7 ${st.prefix}` : "Set domains.sync.r2 + secret material to enable backup" })
2166
+ ] });
2167
+ };
2168
+ const dialog = () => {
2169
+ if (b.confirmOpen === "backup" && b.backupPreview) {
2170
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2171
+ ConfirmDialog,
2172
+ {
2173
+ kind: "backup",
2174
+ title: "Apply backup",
2175
+ targetLabel: `${st?.bucket ?? ""} / ${st?.prefix ?? ""}`,
2176
+ preview: b.backupPreview,
2177
+ previewDirection: "push",
2178
+ remoteHost: st?.bucket ?? "R2",
2179
+ busy: b.busy,
2180
+ actionLimit: 5,
2181
+ planAgeSecs: 0,
2182
+ onShowMore: () => {
2183
+ },
2184
+ onCancel: b.cancelDialog,
2185
+ onApply: () => void b.applyBackup()
2186
+ }
2187
+ );
2188
+ }
2189
+ if (b.confirmOpen === "restore" && b.restorePreview) {
2190
+ const r = b.restorePreview;
2191
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2192
+ ConfirmDialog,
2193
+ {
2194
+ kind: "restore",
2195
+ title: `Apply restore (${r.mode === "new-dir" ? "new dir" : "in place"})`,
2196
+ targetLabel: "from backup HEAD",
2197
+ preview: { ...r, summary: r.summary, actions: [] },
2198
+ previewDirection: "pull",
2199
+ remoteHost: "R2 backup",
2200
+ busy: b.busy,
2201
+ actionLimit: 5,
2202
+ planAgeSecs: 0,
2203
+ onShowMore: () => {
2204
+ },
2205
+ onCancel: b.cancelDialog,
2206
+ onApply: () => void b.applyRestore(r.mode)
2207
+ }
2208
+ );
2209
+ }
2210
+ if (b.confirmOpen === "gc" && b.gcReport) {
2211
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2212
+ ConfirmDialog,
2213
+ {
2214
+ kind: "gc",
2215
+ title: "Apply GC",
2216
+ targetLabel: `${b.gcReport.deletableBlobs?.length ?? 0} blobs \xB7 ${b.gcReport.freedBytes ?? 0} bytes`,
2217
+ preview: { ...b.gcReport, summary: {}, actions: [] },
2218
+ previewDirection: "push",
2219
+ remoteHost: st?.bucket ?? "R2",
2220
+ busy: b.busy,
2221
+ actionLimit: 5,
2222
+ planAgeSecs: 0,
2223
+ onShowMore: () => {
2224
+ },
2225
+ onCancel: b.cancelDialog,
2226
+ onApply: () => void b.applyGc()
2227
+ }
2228
+ );
2229
+ }
2230
+ return null;
2231
+ };
2232
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-sync-root": "", "data-r2-root": "", "aria-busy": b.busy, children: [
2233
+ banner(),
2234
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfigForm, { b }),
2235
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-stats": "", children: [
2236
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StatTile, { icon: "server", value: String(st?.eligible?.md ?? 0), label: "memory" }),
2237
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StatTile, { icon: "refresh", value: String(st?.eligible?.sessions ?? 0), label: "sessions" }),
2238
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StatTile, { icon: "check", value: st?.lastManifest ? "yes" : "no", label: "last backup" })
2239
+ ] }),
2240
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-actions": "", "data-sync-actions-bar": "", children: [
2241
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Button2, { "data-testid": "r2-preview-backup", kind: "primary", disabled: !b.canBackup, onClick: () => void b.previewBackup(), children: "Preview Backup" }),
2242
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-more": "", children: [
2243
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2244
+ Button2,
2245
+ {
2246
+ "data-testid": "r2-more",
2247
+ variant: "outline",
2248
+ disabled: !b.canBackup,
2249
+ "aria-haspopup": "menu",
2250
+ "aria-expanded": moreOpen,
2251
+ onClick: () => setMoreOpen((v) => !v),
2252
+ children: "More"
2253
+ }
2254
+ ),
2255
+ moreOpen ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-r2-more-menu": "", role: "menu", "aria-label": "More backup actions", children: [
2256
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Button2, { "data-testid": "r2-restore-newdir", role: "menuitem", variant: "ghost", disabled: !b.canBackup, onClick: () => {
2257
+ closeMore();
2258
+ void b.previewRestore("new-dir");
2259
+ }, children: "Restore to new folder\u2026" }),
2260
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Button2, { "data-testid": "r2-restore-inplace", role: "menuitem", variant: "ghost", disabled: !b.canBackup, onClick: () => {
2261
+ closeMore();
2262
+ void b.previewRestore("in-place");
2263
+ }, children: "Restore in place\u2026" }),
2264
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Button2, { "data-testid": "r2-preview-gc", role: "menuitem", variant: "ghost", disabled: !b.canBackup, onClick: () => {
2265
+ closeMore();
2266
+ void b.previewGc();
2267
+ }, children: "Preview GC" })
2268
+ ] }) : null
2269
+ ] })
2270
+ ] }),
2271
+ b.error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { role: "alert", "data-sync-error": "", children: b.error }) : null,
2272
+ dialog()
2273
+ ] });
2274
+ }
2275
+
2276
+ // src/client/sync/SyncPanel.tsx
2277
+ var import_jsx_runtime4 = require("react/jsx-runtime");
2278
+ function SyncPanel(props) {
2279
+ const s = useSync(props.ctx);
2280
+ const b = useBackupTarget(props.ctx);
2281
+ const [tab, setTab] = React4.useState("remote");
2282
+ const { connection, checking, busy, error: error2, result, status, remoteHost, remoteSource, lastSync, confirmOpen, preview, previewDirection, biPreview, biConfirmOpen, tunnelPreview, tunnelConfirmOpen, hostFieldError, actionLimit, pages } = s;
2283
+ const st = b.status;
2284
+ const isConnected = connection?.ok === true;
2285
+ const isDisconnected = connection?.ok === false;
2286
+ const machinesBlocked = s.machines?.ok === false;
2287
+ const canSync = isConnected && !checking && !busy && !machinesBlocked;
2288
+ const planAgeSecs = preview?.expiresAt ? Math.max(0, Math.round((new Date(preview.expiresAt).getTime() - Date.now()) / 1e3)) : 0;
2289
+ const [hostInput, setHostInput] = React4.useState("");
2290
+ React4.useEffect(() => {
2291
+ if (hostInput === "" && remoteHost !== "\u2026") setHostInput(remoteHost);
2292
+ }, [remoteHost, hostInput]);
2293
+ const handleCheck = React4.useCallback(async () => {
2294
+ const host = hostInput.trim();
2295
+ if (!host) return;
2296
+ const saved = await s.saveRemoteHost(host);
2297
+ if (!saved.ok) return;
2298
+ await s.checkConnection();
2299
+ }, [hostInput, s]);
2300
+ const sourceLabel2 = remoteSource === "machine" ? "Saved for this machine" : remoteSource === "settings" ? "Saved in settings" : remoteSource === "env" ? "From REMOTE_HOST env" : "Built-in default";
2301
+ const [collapsed, setCollapsed] = React4.useState(() => {
2302
+ const narrow = typeof window !== "undefined" && typeof window.innerWidth === "number" && window.innerWidth < 640;
2303
+ return { localOnly: narrow, remoteOnly: narrow };
2304
+ });
2305
+ const renderBucket = (bucket, heading, empty) => {
2306
+ const page = pages[bucket];
2307
+ const icon = bucket === "localOnly" ? "upload" : "download";
2308
+ const open = !collapsed[bucket];
2309
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { "data-sync-dcol": "", "data-bucket": bucket, "data-collapsed": String(!open), "aria-label": heading, children: [
2310
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("header", { "data-sync-dcol-head": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2311
+ "button",
2312
+ {
2313
+ type: "button",
2314
+ "data-sync-dcol-toggle": "",
2315
+ "aria-expanded": open,
2316
+ "aria-label": `${open ? "Collapse" : "Expand"} ${heading}`,
2317
+ onClick: () => setCollapsed((prev) => ({ ...prev, [bucket]: !prev[bucket] })),
2318
+ children: [
2319
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-dcol-title": "", children: [
2320
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: open ? "chevron-down" : "chevron-right" }),
2321
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: icon }),
2322
+ heading
2323
+ ] }),
2324
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-dcol-count": "", children: [
2325
+ page.files.length,
2326
+ "/",
2327
+ page.total
2328
+ ] })
2329
+ ]
2330
+ }
2331
+ ) }),
2332
+ open ? isDisconnected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-empty": "", children: [
2333
+ "Cannot check remote \u2014 SSH to ",
2334
+ connection.host,
2335
+ " is not connected."
2336
+ ] }) : page.files.length === 0 && !page.loaded ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-loading": "", children: [
2337
+ "Checking ",
2338
+ heading.toLowerCase(),
2339
+ "\u2026"
2340
+ ] }) : page.files.length === 0 && !checking ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-sync-empty": "", children: empty }) : page.files.map((p) => {
2341
+ const f = formatFile(p);
2342
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-file": "", title: p, children: [
2343
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-file-icon": "", style: { color: "var(--dsw-alias-label-tertiary)" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: f.icon }) }),
2344
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-file-main": "", children: [
2345
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-file-title": "", children: f.title }),
2346
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-file-path": "", children: f.path })
2347
+ ] }),
2348
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-file-meta": "", children: f.meta })
2349
+ ] }, p);
2350
+ }) : null,
2351
+ open && page.next != null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("footer", { "data-sync-dcol-foot": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { size: "sm", variant: "ghost", onClick: () => void s.loadPage(bucket, page.next), "aria-label": `Show more ${heading}`, children: "Show more" }) }) : null
2352
+ ] });
2353
+ };
2354
+ const headerStatus = tab === "remote" ? checking ? "Checking connection\u2026" : isConnected ? `${connection.host} \xB7 ${humanSummary(status)}` : isDisconnected ? `Cannot reach ${connection.host}` : connection === null ? "Not checked yet \u2014 configure SSH and check" : humanSummary(status) : b.checking ? "Checking backup configuration\u2026" : st?.configured ? `Backup ${st.prefix}` : "Not configured";
2355
+ const renderRemote = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-root": "", "aria-busy": busy || checking, children: [
2356
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-ssh": "", children: [
2357
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { "data-sync-ssh-label": "", htmlFor: "sync-ssh-host", children: "SSH target" }),
2358
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2359
+ "input",
2360
+ {
2361
+ id: "sync-ssh-host",
2362
+ "data-sync-ssh-input": "",
2363
+ "data-testid": "sync-ssh-host",
2364
+ value: hostInput,
2365
+ onChange: (e) => {
2366
+ setHostInput(e.target.value);
2367
+ void s.setHostFieldError?.(null);
2368
+ },
2369
+ placeholder: "user@host",
2370
+ autoComplete: "off",
2371
+ autoCapitalize: "off",
2372
+ spellCheck: false,
2373
+ disabled: checking || busy,
2374
+ "aria-describedby": "sync-ssh-src",
2375
+ "aria-invalid": hostFieldError ? "true" : void 0
2376
+ }
2377
+ ),
2378
+ hostFieldError ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-error": "", role: "alert", "data-testid": "sync-ssh-host-error", style: { gridColumn: "1 / -1", fontSize: 12, lineHeight: "16px", color: "var(--dsw-alias-state-error-primary)", overflowWrap: "anywhere" }, children: hostFieldError }) : null,
2379
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-ssh-row": "", children: [
2380
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { variant: "outline", "data-testid": "sync-save-host", disabled: checking || busy || hostInput.trim().length === 0, onClick: () => void s.saveRemoteHost(hostInput.trim()), children: "Save" }),
2381
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { variant: "primary", "data-testid": "sync-check-connection", disabled: checking || busy || hostInput.trim().length === 0, busy: checking, onClick: () => void handleCheck(), children: checking ? "Checking\u2026" : "Check connection" })
2382
+ ] }),
2383
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { id: "sync-ssh-src", "data-sync-ssh-src": "", children: sourceLabel2 })
2384
+ ] }),
2385
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-conn": "", "data-state": isDisconnected ? "bad" : checking ? "checking" : "ok", "data-testid": "sync-connection", children: [
2386
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-conn-dot": "" }),
2387
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-conn-main": "", children: checking ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-conn-title": "", children: [
2388
+ "Checking SSH to ",
2389
+ remoteHost,
2390
+ "\u2026"
2391
+ ] }) : isConnected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2392
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-conn-title": "", children: [
2393
+ "Connected to ",
2394
+ connection.host,
2395
+ connection.latencyMs != null ? ` \xB7 ${connection.latencyMs}ms` : "",
2396
+ " \xB7 SSH ready"
2397
+ ] }),
2398
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-conn-desc": "", children: "Use Preview to see the exact plan \u2014 Apply always requires confirmation." })
2399
+ ] }) : isDisconnected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2400
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-conn-title": "", children: [
2401
+ "Cannot reach ",
2402
+ connection.host,
2403
+ " \u2014 sync is paused"
2404
+ ] }),
2405
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-conn-desc": "", children: connection.error ? String(connection.error).slice(0, 220) : "SSH failed. Check that the host is reachable and your key is loaded." })
2406
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-conn-title": "", children: "Not checked yet \u2014 configure SSH above, then Check connection." }) }),
2407
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { 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" }, children: checking ? "Checking" : "Refresh" })
2408
+ ] }),
2409
+ isConnected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
2410
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-fields": "", children: [
2411
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-field": "", children: [
2412
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-label": "", children: "Remote host" }),
2413
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-value": "", "data-testid": "sync-remote-host", children: remoteHost })
2414
+ ] }),
2415
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-field": "", children: [
2416
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-label": "", children: "Last sync (this browser)" }),
2417
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-value": "", "data-testid": "sync-last-sync", children: formatLastSync(lastSync) })
2418
+ ] }),
2419
+ s.machines ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-field": "", children: [
2420
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-label": "", children: "Machines" }),
2421
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-field-value": "", "data-testid": "sync-machines", children: [
2422
+ s.machines.localId ?? "?",
2423
+ " \u2194 ",
2424
+ s.machines.remoteId ?? "?"
2425
+ ] }),
2426
+ s.machines.reason ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-note": "", "data-testid": "sync-machines-error", style: { fontSize: 12, lineHeight: "16px", color: "var(--dsw-alias-label-secondary)", overflowWrap: "anywhere" }, children: s.machines.reason }) : null,
2427
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { variant: "outline", size: "sm", "data-testid": "sync-tunnel-restore", disabled: checking || busy, onClick: () => void s.handleTunnelRestorePreview(), children: "Restore tunnel" })
2428
+ ] }) : null
2429
+ ] }),
2430
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-stats": "", children: [
2431
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2432
+ StatTile,
2433
+ {
2434
+ icon: "upload",
2435
+ value: status ? String(status.localOnly ?? 0) : "\u2014",
2436
+ label: "Only here",
2437
+ hint: status?.localOnly ? "Pushed on Preview Push" : "Nothing here",
2438
+ ariaLabel: "Files only on this machine"
2439
+ }
2440
+ ),
2441
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2442
+ StatTile,
2443
+ {
2444
+ icon: "swap",
2445
+ value: status ? String(status.both ?? 0) : "\u2014",
2446
+ label: "On both",
2447
+ hint: "Content compared in Preview",
2448
+ ariaLabel: "Files on both machines"
2449
+ }
2450
+ ),
2451
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2452
+ StatTile,
2453
+ {
2454
+ icon: "download",
2455
+ value: status ? String(status.remoteOnly ?? 0) : "\u2014",
2456
+ label: "Only there",
2457
+ hint: status?.remoteOnly ? "Pulled on Preview Pull" : "Nothing there",
2458
+ ariaLabel: "Files only on the other machine"
2459
+ }
2460
+ )
2461
+ ] }),
2462
+ machinesBlocked ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-notice": "", "data-tone": "bad", role: "status", "data-testid": "sync-machines-gate", children: [
2463
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-icon": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }) }),
2464
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-notice-main": "", children: [
2465
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-title": "", children: "Sync is locked \u2014 machine identity check failed" }),
2466
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-notice-desc": "", children: [
2467
+ s.machines?.reason ?? "The two sides do not look like two distinct machines.",
2468
+ " Fix the SSH target so it points at the OTHER machine, then Check connection again."
2469
+ ] })
2470
+ ] })
2471
+ ] }) : null,
2472
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-actions": "", "data-sync-actions-bar": "", children: [
2473
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { variant: "primary", icon: "swap", disabled: !canSync, "data-testid": "sync-both-ways", onClick: () => void s.handleBidirectionalPreview(), children: busy ? "Working\u2026" : "Sync both ways" }),
2474
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { variant: "outline", icon: "download", disabled: !canSync, "data-testid": "sync-preview-pull", onClick: () => void s.handlePreview("pull"), children: busy ? "Working\u2026" : "Preview Pull" }),
2475
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Button2, { variant: "outline", icon: "upload", disabled: !canSync, "data-testid": "sync-preview-push", onClick: () => void s.handlePreview("push"), children: busy ? "Working\u2026" : "Preview Push" })
2476
+ ] }),
2477
+ busy && s.progress ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-progress": "", role: "status", "aria-live": "polite", "data-testid": "sync-progress", children: [
2478
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-progress-meta": "", children: s.progress.phase === "hashing" ? `Reviewing sessions ${s.progress.current}/${s.progress.total}${s.progress.file ? ` \u2014 ${formatFile(s.progress.file).path}` : ""}` : s.progress.phase === "staging" ? `Staging files ${s.progress.current}/${s.progress.total}` : s.progress.phase === "planning" ? "Building the exact plan\u2026" : "Listing both machines\u2026" }),
2479
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-progress-track": "", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": s.progress.total, "aria-valuenow": s.progress.current, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-progress-fill": "", style: { width: `${s.progress.total > 0 ? Math.min(100, Math.round(s.progress.current / s.progress.total * 100)) : 0}%` } }) })
2480
+ ] }) : null,
2481
+ result ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-notice": "", "data-tone": result.ok ? "ok" : "bad", role: "status", "aria-live": "polite", children: [
2482
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-icon": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: result.ok ? "check" : "alert" }) }),
2483
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-notice-main": "", children: [
2484
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-title": "", children: result.ok ? "Apply complete" : "Apply failed" }),
2485
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-desc": "", children: result.text })
2486
+ ] })
2487
+ ] }) : null,
2488
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-filetables": "", children: [
2489
+ renderBucket("remoteOnly", "Coming from the other machine", "Nothing to pull \u2014 the other machine has no eligible files here."),
2490
+ renderBucket("localOnly", "Ready to send", "Nothing to push \u2014 this machine has no eligible files here.")
2491
+ ] })
2492
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-notice": "", "data-tone": "ok", role: "status", children: [
2493
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-icon": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: isDisconnected ? "alert" : "clock" }) }),
2494
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-notice-main": "", children: [
2495
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-title": "", children: isDisconnected ? "Connection failed" : "Preview and file lists are locked" }),
2496
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-desc": "", children: isDisconnected ? "Fix the SSH target above and check again." : "Configure the SSH target above, then Check connection \u2014 everything below unlocks after a successful check." })
2497
+ ] })
2498
+ ] }),
2499
+ error2 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-notice": "", "data-tone": "bad", role: "alert", children: [
2500
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-icon": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }) }),
2501
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-notice-main": "", children: [
2502
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-title": "", children: "Something went wrong" }),
2503
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-desc": "", children: error2 })
2504
+ ] })
2505
+ ] }) : null,
2506
+ confirmOpen && preview ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2507
+ ConfirmDialog,
2508
+ {
2509
+ preview,
2510
+ previewDirection,
2511
+ remoteHost,
2512
+ busy,
2513
+ actionLimit,
2514
+ planAgeSecs,
2515
+ onShowMore: () => s.setActionLimit((n) => n + 5),
2516
+ onCancel: s.cancelDialog,
2517
+ onApply: () => void s.handleApply()
2518
+ }
2519
+ ) : null,
2520
+ biConfirmOpen && biPreview ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2521
+ ConfirmDialog,
2522
+ {
2523
+ preview: biPreview.push,
2524
+ previewDirection: "push",
2525
+ remoteHost,
2526
+ busy,
2527
+ actionLimit,
2528
+ planAgeSecs: Math.max(0, Math.round((new Date(biPreview.expiresAt).getTime() - Date.now()) / 1e3)),
2529
+ onShowMore: () => s.setActionLimit((n) => n + 5),
2530
+ onCancel: s.cancelBidirectionalDialog,
2531
+ onApply: () => void s.handleBidirectionalApply(),
2532
+ title: `Apply both ways \u2014 preview ${String(biPreview.previewId ?? "").slice(0, 8)}`,
2533
+ projectedTitle: "Pull plan (projected)",
2534
+ projectedPreview: biPreview.pullProjected,
2535
+ projectedNote: "Projected \u2014 recomputed exact after the push lands.",
2536
+ applyLabel: "Apply both ways"
2537
+ }
2538
+ ) : null,
2539
+ tunnelConfirmOpen && tunnelPreview ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2540
+ TunnelRestoreDialog,
2541
+ {
2542
+ preview: tunnelPreview,
2543
+ busy,
2544
+ onCancel: s.cancelTunnelRestore,
2545
+ onConfirm: () => void s.confirmTunnelRestore()
2546
+ }
2547
+ ) : null,
2548
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-sync-muted": "", style: { textAlign: "center" }, children: "Notes and sessions are merged \u2014 never overwritten. Apply always requires confirmation." })
2549
+ ] });
2550
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-shell": "", children: [
2551
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", gap: 10, alignItems: "flex-start", padding: "2px 2px 4px" }, children: [
2552
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MaestroLogo, {}),
2553
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", flexDirection: "column", minWidth: 0, gap: 2 }, children: [
2554
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: 15, fontWeight: 600, lineHeight: "22px", color: "var(--dsw-alias-label-primary)" }, children: "Maestro Sync" }),
2555
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: 12, lineHeight: "16px", color: "var(--dsw-alias-label-secondary)", overflowWrap: "anywhere" }, children: headerStatus })
2556
+ ] })
2557
+ ] }),
2558
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-tabs": "", role: "tablist", "aria-label": "Maestro Sync modes", children: [
2559
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { "data-testid": "sync-tab-remote", role: "tab", "aria-selected": tab === "remote", "data-sync-tab": "", onClick: () => setTab("remote"), children: "Remote Sync" }),
2560
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { "data-testid": "sync-tab-r2", role: "tab", "aria-selected": tab === "r2", "data-sync-tab": "", onClick: () => setTab("r2"), children: "R2 Sync" })
2561
+ ] }),
2562
+ tab === "remote" ? renderRemote() : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(R2SyncPanel, { b })
2563
+ ] });
2564
+ }
2565
+
2566
+ // src/client/sync/index.tsx
2567
+ var SETTINGS_NAV_MARKER2 = "data-maestro-sync-settings-nav";
2568
+ var SETTINGS_NAV_CSS2 = `
2569
+ [${SETTINGS_NAV_MARKER2}] > svg:first-child,
2570
+ [${SETTINGS_NAV_MARKER2}] > svg.zWKi1a_navIcon {
2571
+ display: none !important;
2572
+ }
2573
+ [${SETTINGS_NAV_MARKER2}]::before {
2574
+ content: '';
2575
+ flex: none;
2576
+ width: 16px;
2577
+ height: 16px;
2578
+ display: inline-block;
2579
+ background: currentColor;
2580
+ -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 11 L5 4 L8 9 L11 4 L14 11'/%3E%3C/svg%3E") center / contain no-repeat;
2581
+ mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 11 L5 4 L8 9 L11 4 L14 11'/%3E%3C/svg%3E") center / contain no-repeat;
2582
+ }
2583
+ `;
2584
+ function registerSyncNavIcon(label, root) {
2585
+ if (typeof document === "undefined" && root === void 0) return () => {
2586
+ };
2587
+ const scope = root ?? document;
2588
+ let disposed = false;
2589
+ const sync = () => {
2590
+ if (disposed) return;
2591
+ const currentLabel = label().trim();
2592
+ const buttons = scope.querySelectorAll('[role="dialog"] nav button');
2593
+ for (const button of Array.from(buttons)) {
2594
+ const el = button;
2595
+ const matches = currentLabel.length > 0 && button.textContent != null && button.textContent.trim() === currentLabel;
2596
+ if (matches) el.setAttribute(SETTINGS_NAV_MARKER2, "");
2597
+ else el.removeAttribute(SETTINGS_NAV_MARKER2);
2598
+ }
2599
+ };
2600
+ sync();
2601
+ let observer = null;
2602
+ if (typeof MutationObserver !== "undefined") {
2603
+ observer = new MutationObserver(sync);
2604
+ observer.observe(document.body, { childList: true, subtree: true, characterData: true });
2605
+ }
2606
+ return () => {
2607
+ disposed = true;
2608
+ if (observer !== null) observer.disconnect();
2609
+ for (const element of Array.from(scope.querySelectorAll(`[${SETTINGS_NAV_MARKER2}]`))) {
2610
+ ;
2611
+ element.removeAttribute(SETTINGS_NAV_MARKER2);
2612
+ }
2613
+ };
2614
+ }
2615
+ function installStyleTag(css, pluginCss) {
2616
+ if (typeof document === "undefined") return () => {
2617
+ };
2618
+ const tag = document.createElement("style");
2619
+ tag.dataset.plugin = "@ddtcorex/dsh-maestro-sync";
2620
+ tag.dataset.pluginCss = pluginCss;
2621
+ tag.textContent = css;
2622
+ document.head.appendChild(tag);
2623
+ return () => {
2624
+ document.querySelector(`style[data-plugin-css="${pluginCss}"]`)?.remove();
2625
+ };
2626
+ }
2627
+ var SYNC_CSS = `
2628
+ [data-sync-root], [data-sync-root] * { box-sizing: border-box; }
2629
+ [data-sync-root] { display: flex; flex-direction: column; gap: 12px; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 1.5; min-width: 0; width: 100%; max-width: 640px; }
2630
+
2631
+ /* connection banner */
2632
+ [data-sync-conn] { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
2633
+ [data-sync-conn][data-state="bad"] { border-color: var(--dsw-alias-state-error-primary, #DC2626); }
2634
+ [data-sync-conn-dot] { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; }
2635
+ [data-sync-conn][data-state="ok"] [data-sync-conn-dot] { background: var(--dsw-alias-state-success-primary, #16A34A); box-shadow: 0 0 0 4px color-mix(in srgb, var(--dsw-alias-state-success-primary, #16A34A) 16%, transparent); }
2636
+ [data-sync-conn][data-state="bad"] [data-sync-conn-dot] { background: var(--dsw-alias-state-error-primary, #DC2626); box-shadow: 0 0 0 4px color-mix(in srgb, var(--dsw-alias-state-error-primary, #DC2626) 12%, transparent); }
2637
+ [data-sync-conn][data-state="checking"] [data-sync-conn-dot] { background: var(--dsw-alias-label-secondary); opacity: 0.6; }
2638
+ [data-sync-conn-main] { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
2639
+ [data-sync-conn-title] { font-size: 12px; font-weight: 600; line-height: 16px; }
2640
+ [data-sync-conn-desc] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); word-break: break-word; }
2641
+
2642
+ /* identity fields */
2643
+ [data-sync-fields] { display: flex; gap: 10px; flex-wrap: wrap; }
2644
+ [data-sync-field] { flex: 1 1 160px; min-width: 0; border: 1px solid var(--dsw-alias-border-l1); border-radius: 8px; background: var(--dsw-alias-bg-layer-2); padding: 8px 10px; }
2645
+ [data-sync-field-label] { font-size: 11px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; display: block; }
2646
+ [data-sync-field-value] { font-size: 13px; font-weight: 600; word-break: break-all; margin-top: 2px; display: block; }
2647
+
2648
+ /* stat tiles */
2649
+ [data-sync-stats] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
2650
+ [data-sync-stat] { display: flex; flex-direction: column; gap: 4px; min-width: 0; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); padding: 10px 12px; text-align: left; font: inherit; cursor: default; color: inherit; }
2651
+ button[data-sync-stat] { cursor: pointer; }
2652
+ button[data-sync-stat]:hover { border-color: var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-3); }
2653
+ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2654
+ [data-sync-stat-icon] { display: inline-flex; color: var(--dsw-alias-label-tertiary); }
2655
+ [data-sync-stat-value] { font-size: 22px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
2656
+ [data-sync-stat-label] { font-size: 12px; font-weight: 600; line-height: 16px; }
2657
+ [data-sync-stat-hint] { font-size: 10px; line-height: 13px; color: var(--dsw-alias-label-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2658
+
2659
+ /* actions */
2660
+ [data-sync-actions] { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
2661
+
2662
+ /* preview progress \u2014 live per-file ticks while sessions are counted */
2663
+ [data-sync-progress] { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
2664
+ [data-sync-progress-meta] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); word-break: break-word; }
2665
+ [data-sync-progress-track] { display: block; height: 4px; border-radius: 999px; background: var(--dsw-alias-bg-layer-3); overflow: hidden; }
2666
+ [data-sync-progress-fill] { display: block; height: 100%; border-radius: 999px; background: var(--dsw-alias-state-info-primary, #0A84FF); transition: width 0.3s ease; }
2667
+ @media (prefers-reduced-motion: reduce) { [data-sync-progress-fill] { transition: none; } }
2668
+
2669
+ /* dialog session counts \u2014 counted by checksum, no per-file rows */
2670
+ [data-sync-sessioncounts] { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: 8px; border: 1px dashed var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-2); margin-bottom: 6px; }
2671
+ [data-sync-sessioncounts-lbl] { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); }
2672
+ [data-sync-sessioncounts-line] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); }
2673
+
2674
+ /* notice / error */
2675
+ [data-sync-notice] { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
2676
+ [data-sync-notice][data-tone="bad"] { border-color: var(--dsw-alias-state-error-primary, #DC2626); }
2677
+ [data-sync-notice-icon] { display: inline-flex; color: var(--dsw-alias-label-tertiary); margin-top: 1px; }
2678
+ [data-sync-notice][data-tone="bad"] [data-sync-notice-icon] { color: var(--dsw-alias-state-error-primary, #DC2626); }
2679
+ [data-sync-notice][data-tone="ok"] [data-sync-notice-icon] { color: var(--dsw-alias-state-success-primary, #16A34A); }
2680
+ [data-sync-notice-main] { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
2681
+ [data-sync-notice-title] { font-size: 12px; font-weight: 600; }
2682
+ [data-sync-notice-desc] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); word-break: break-word; }
2683
+
2684
+ /* badges */
2685
+ [data-sync-badge] { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
2686
+ [data-sync-badge][data-tone="brand"] { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-border-l2); }
2687
+ [data-sync-badge][data-tone="success"] { color: var(--dsw-alias-state-success-primary); }
2688
+ [data-sync-badge][data-tone="error"] { color: var(--dsw-alias-state-error-primary); border-color: var(--dsw-alias-state-error-primary); }
2689
+ [data-sync-badge][data-tone="warn"] { color: var(--dsw-alias-state-warn-primary); }
2690
+
2691
+ [data-sync-muted] { color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 14px; }
2692
+
2693
+ /* ---- confirmation dialog: bottom sheet on mobile, centered card \u2265640 ---- */
2694
+ [data-sync-dialog-overlay] { position: fixed; inset: 0; z-index: 1000; background: color-mix(in srgb, var(--dsw-alias-bg-base, #000) 55%, transparent); display: flex; align-items: flex-end; justify-content: center; }
2695
+ [data-sync-dialog] { width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto; border: 1px solid var(--dsw-alias-border-l2); border-radius: 16px 16px 0 0; background: var(--dsw-alias-bg-layer-1); box-shadow: 0 -16px 50px rgba(0, 0, 0, 0.3); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
2696
+ [data-sync-dialog-top] { display: flex; align-items: flex-start; gap: 8px; }
2697
+ [data-sync-dialog-heading] { flex: 1; min-width: 0; }
2698
+ [data-sync-dialog-title] { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; line-height: 20px; }
2699
+ [data-sync-dialog-desc] { font-size: 12px; line-height: 16px; color: var(--dsw-alias-label-secondary); margin-top: 2px; }
2700
+ [data-sync-dialog-close] { flex: none; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--dsw-alias-border-l1); border-radius: 8px; background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary); cursor: pointer; padding: 0; }
2701
+ [data-sync-dialog-close]:hover { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-border-l2); }
2702
+ [data-sync-dialog-close]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2703
+ [data-sync-planlist] { display: flex; flex-direction: column; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; overflow: hidden; }
2704
+ [data-sync-planrow] { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); }
2705
+ [data-sync-planrow]:last-child { border-bottom: none; }
2706
+ [data-sync-planfile-icon] { display: inline-flex; flex: none; }
2707
+ [data-sync-planfile] { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
2708
+ [data-sync-planfile-title] { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2709
+ [data-sync-planfile-path] { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2710
+ [data-sync-planrow-meta] { flex: none; }
2711
+ [data-sync-planmore] { display: flex; justify-content: center; padding: 8px; }
2712
+ [data-sync-empty] { padding: 16px 12px; text-align: center; color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 16px; }
2713
+ [data-sync-loading] { padding: 16px 12px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 16px; }
2714
+ [data-sync-dialog-actions] { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
2715
+
2716
+ /* ---- file list sections (in-card) ---- */
2717
+ [data-sync-filetables] { display: grid; grid-template-columns: 1fr; gap: 12px; }
2718
+ @media (min-width: 1024px) {
2719
+ [data-sync-filetables] { grid-template-columns: 1fr 1fr; }
2720
+ }
2721
+ [data-sync-dcol] { display: flex; flex-direction: column; border: 1px solid var(--dsw-alias-border-l1); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); overflow: hidden; min-width: 0; }
2722
+ [data-sync-dcol-head] { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
2723
+ [data-sync-dcol-title] { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
2724
+ [data-sync-dcol-count] { font-size: 11px; font-weight: 600; color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; padding: 2px 8px; }
2725
+ [data-sync-file] { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--dsw-alias-border-l1); font-size: 12px; min-width: 0; }
2726
+ [data-sync-file]:last-child { border-bottom: none; }
2727
+ [data-sync-file-icon] { display: inline-flex; flex: none; color: var(--dsw-alias-label-tertiary); }
2728
+ [data-sync-file-main] { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
2729
+ [data-sync-file-title] { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
2730
+ [data-sync-file-path] { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2731
+ [data-sync-file-meta] { flex: none; font-size: 11px; color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
2732
+ [data-sync-dcol-foot] { display: flex; justify-content: center; padding: 8px; border-top: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
2733
+
2734
+ /* spinner */
2735
+ @keyframes sync-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
2736
+ .sync-spin { display: inline-block; animation: sync-spin 0.8s linear infinite; font-size: 14px; line-height: 1; }
2737
+
2738
+ /* ---- breakpoints ---- */
2739
+ @media (max-width: 640px) {
2740
+ [data-sync-fields] { gap: 8px; }
2741
+ [data-sync-field] { flex: 1 1 0; min-width: 0; padding: 7px 8px; border-radius: 8px; }
2742
+ [data-sync-field-label] { font-size: 10px; line-height: 12px; }
2743
+ [data-sync-field-value] { font-size: 12px; line-height: 14px; }
2744
+ }
2745
+ @media (max-width: 480px) {
2746
+ [data-sync-actions] > [data-sync-btn] { flex: 1 1 auto; }
2747
+ [data-sync-fields] { flex-direction: row; gap: 6px; }
2748
+ [data-sync-field] { flex: 1 1 0; min-width: 0; padding: 6px 8px; border-radius: 8px; }
2749
+ [data-sync-field-label] { font-size: 10px; line-height: 11px; }
2750
+ [data-sync-field-value] { font-size: 11px; line-height: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: normal; }
2751
+ }
2752
+ @media (min-width: 640px) {
2753
+ [data-sync-dialog-overlay] { align-items: center; padding: 24px; }
2754
+ [data-sync-dialog] { border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); }
2755
+ }
2756
+ @media (min-width: 1024px) {
2757
+ [data-sync-dash-content] { padding: 20px; }
2758
+ }
2759
+ @media (max-width: 390px) {
2760
+ [data-sync-card] { padding: 12px; }
2761
+ }
2762
+ @media (prefers-reduced-motion: reduce) {
2763
+ [data-sync-root] *, [data-sync-dialog] * { transition: none !important; animation: none !important; }
2764
+ .sync-spin { animation: none; }
2765
+ }
2766
+
2767
+ /* ---- mobile-first (2026-09-03): thumb reach, disclosure, touch targets ---- */
2768
+ [data-sync-shell] { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
2769
+ /* mode tabs \u2014 pill bar, 44px touch height on every viewport */
2770
+ [data-sync-tabs] { display: flex; gap: 4px; padding: 3px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
2771
+ [data-sync-tab] { flex: 1 1 0; min-height: 44px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
2772
+ [data-sync-tab][aria-selected="true"] { background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); box-shadow: inset 0 0 0 1px var(--dsw-alias-border-l1); }
2773
+ [data-sync-tab]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2774
+ /* collapsible bucket header toggle (header padding moves onto the button) */
2775
+ [data-sync-dcol-head] { padding: 0; }
2776
+ [data-sync-dcol-toggle] { all: unset; display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 10px 12px; cursor: pointer; box-sizing: border-box; font: inherit; color: inherit; }
2777
+ [data-sync-dcol-toggle]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: -2px; }
2778
+ /* R2 actions: primary + More menu (menu never overflows 360px) */
2779
+ [data-r2-actions] { display: flex; gap: 8px; flex-wrap: wrap; align-items: stretch; }
2780
+ [data-r2-actions] > [data-sync-btn] { flex: 2 1 0; }
2781
+ [data-r2-more] { position: relative; flex: 1 1 0; display: flex; }
2782
+ [data-r2-more] > [data-sync-btn] { flex: 1 1 auto; width: 100%; }
2783
+ [data-r2-more-menu] { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 220px; max-width: calc(100vw - 48px); display: flex; flex-direction: column; gap: 2px; padding: 6px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); box-shadow: var(--dsw-shadow-lv3); }
2784
+ [data-r2-more-menu] > [data-sync-btn] { justify-content: flex-start; width: 100%; }
2785
+ /* sticky thumb-reach bars + condensed stats on narrow screens */
2786
+ @media (max-width: 640px) {
2787
+ [data-sync-actions-bar] { position: sticky; bottom: 0; z-index: 10; padding: 10px 2px calc(10px + env(safe-area-inset-bottom, 0px)); background: color-mix(in srgb, var(--dsw-alias-bg-base, #fff) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
2788
+ [data-sync-actions-bar] > [data-sync-btn] { flex: 1 1 0; min-height: 48px !important; font-size: 14px; }
2789
+ [data-sync-actions-bar] [data-r2-more] > [data-sync-btn] { min-height: 48px !important; }
2790
+ [data-sync-dialog-actions] { position: sticky; bottom: 0; padding: 10px 0 calc(4px + env(safe-area-inset-bottom, 0px)); background: var(--dsw-alias-bg-layer-1); }
2791
+ [data-sync-dialog-actions] > [data-sync-btn]:last-child { flex: 1 1 100%; min-height: 48px !important; }
2792
+ [data-sync-stats] { gap: 6px; }
2793
+ [data-sync-stat] { padding: 8px 10px; }
2794
+ }
2795
+ /* coarse pointers: 40\u201344px targets (inline min-heights need !important) */
2796
+ @media (pointer: coarse) {
2797
+ [data-sync-btn][data-size="sm"] { min-height: 40px !important; }
2798
+ [data-sync-btn][data-size="md"], [data-sync-btn]:not([data-size]) { min-height: 44px !important; }
2799
+ [data-sync-dialog-close] { width: 40px; height: 40px; }
2800
+ }
2801
+ @media (max-width: 390px) {
2802
+ [data-sync-stat-value] { font-size: 18px; }
2803
+ [data-sync-stat-hint] { display: none; }
2804
+ }
2805
+ /* SSH configuration \u2014 user-filled target, explicit check, nothing auto-probes */
2806
+ [data-sync-ssh] { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); }
2807
+ [data-sync-ssh-label] { font-size: 11px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
2808
+ [data-sync-ssh-input] { min-height: 44px; padding: 0 12px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; box-sizing: border-box; }
2809
+ [data-sync-ssh-input]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2810
+ [data-sync-ssh-input]:disabled { opacity: 0.6; }
2811
+ [data-sync-ssh-row] { display: flex; gap: 8px; flex-wrap: wrap; }
2812
+ [data-sync-ssh-row] > [data-sync-btn] { flex: 1 1 0; }
2813
+ [data-sync-ssh-src] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); }
2814
+ /* R2 status banner \u2014 badge + hint need a real gap (was running together) */
2815
+ [data-r2-summary] { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
2816
+ /* R2 backup-target form \u2014 same language as the SSH section */
2817
+ [data-r2-config] { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); }
2818
+ [data-r2-config-label] { font-size: 11px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
2819
+ [data-r2-field] { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
2820
+ [data-r2-field-label] { font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); }
2821
+ [data-r2-field-input] { min-height: 44px; padding: 0 12px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; width: 100%; box-sizing: border-box; }
2822
+ [data-r2-field-input]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2823
+ [data-r2-field-input]:disabled { opacity: 0.6; }
2824
+ [data-r2-field-hint] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-tertiary); }
2825
+ /* Field-level validation feedback: the message must sit under the input it
2826
+ names, not only in the panel-wide banner. */
2827
+ [data-r2-field-error] { font-size: 11px; line-height: 15px; color: var(--dsw-alias-state-error-primary); overflow-wrap: anywhere; }
2828
+ [data-r2-field-input][aria-invalid="true"] { border-color: var(--dsw-alias-state-error-primary); }
2829
+ [data-sync-field-error] { font-size: 12px; line-height: 16px; color: var(--dsw-alias-state-error-primary); overflow-wrap: anywhere; }
2830
+ [data-sync-ssh-input][aria-invalid="true"] { border-color: var(--dsw-alias-state-error-primary); }
2831
+ [data-r2-provider-row] { display: flex; gap: 8px; }
2832
+ [data-r2-provider-opt] { flex: 1 1 0; min-height: 44px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l2); background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
2833
+ [data-r2-provider-opt][aria-pressed="true"] { background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); box-shadow: inset 0 0 0 1px var(--dsw-alias-border-l1); }
2834
+ [data-r2-provider-opt]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2835
+ [data-r2-config-row] { display: flex; gap: 8px; }
2836
+ [data-r2-config-row] > [data-sync-btn] { flex: 1 1 0; }
2837
+ [data-r2-config-hint] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); }
2838
+ @media (max-width: 640px) {
2839
+ [data-sync-ssh-row] > [data-sync-btn] { min-height: 48px !important; }
2840
+ }
2841
+
2842
+ /* iOS 16px field floor hold (dsh-maestro-mobile zoom guard).
2843
+ Every text field on the page is held at 16px under html[data-mobile-nav-ios]
2844
+ inside this same predicate, because iOS WebKit magnifies the visual viewport
2845
+ for a focused field below 16px. An earlier revision of this panel opted its
2846
+ own fields back out to inherit for a compact 13px scale \u2014 and every tap on
2847
+ those fields zoomed the page on iPhone, with modal sheets never blurring
2848
+ back. Function beats pixels: hold the same 16px here (the :not(#...) clause
2849
+ matches every element \u2014 no node carries that id \u2014 and exists purely for
2850
+ id-level specificity, so this declaration keeps winning over competing
2851
+ field rules). Android and desktop never carry the marker, so the compact
2852
+ scale they were designed with is untouched. */
2853
+ @media (max-width: 1023px) and (pointer: coarse) {
2854
+ html[data-mobile-nav-ios] [data-sync-root] input:not(#dsh-field-floor-opt-out),
2855
+ html[data-mobile-nav-ios] [data-sync-root] textarea:not(#dsh-field-floor-opt-out),
2856
+ html[data-mobile-nav-ios] [data-sync-root] select:not(#dsh-field-floor-opt-out) { font-size:16px !important; }
2857
+ }
2858
+ `;
2859
+ function apply3(ctx) {
2860
+ const slots = ctx.slots ?? ctx.get?.("slots");
2861
+ if (!slots?.inject || !slots?.register) return;
2862
+ ctx.effect(() => registerSyncNavIcon(() => "Maestro Sync"), "maestro-sync: settings nav icon");
2863
+ ctx.effect(() => installStyleTag(SETTINGS_NAV_CSS2, "maestro-sync/settings-nav.css"), "maestro-sync: settings nav css");
2864
+ ctx.effect(() => installStyleTag(SYNC_CSS, "maestro-sync/settings.css"), "maestro-sync: settings css");
2865
+ ctx.effect(() => {
2866
+ const dispose = slots.inject(
2867
+ "settings.section",
2868
+ () => slots.register(
2869
+ { name: "settings.section", id: "maestro-sync", order: 28, label: () => "Maestro Sync" },
2870
+ () => React5.createElement(SyncPanel, { ctx })
2871
+ )
2872
+ );
2873
+ return () => {
2874
+ try {
2875
+ dispose?.();
2876
+ } catch {
2877
+ }
2878
+ };
2879
+ }, "maestro-sync: settings");
2880
+ }
2881
+
2882
+ // src/client/index.tsx
2883
+ var inject = ["slots", "connection"];
2884
+ var MODULES = [
2885
+ ["auto-reload", apply],
2886
+ ["config", apply2],
2887
+ ["sync", apply3]
2888
+ ];
2889
+ function apply4(ctx) {
2890
+ for (const [name, register] of MODULES) {
2891
+ try {
2892
+ register(ctx);
2893
+ } catch (err) {
2894
+ console.error(`[dsh-maestro-core] ${name} client module failed to apply`, err);
2895
+ }
2896
+ }
2897
+ }
2898
+
2899
+ return module.exports;
2900
+ }
2901
+ });