@ddtcorex/dsh-maestro-core 0.10.0 → 0.11.1

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 (48) hide show
  1. package/README.md +31 -12
  2. package/lib/cli.js +0 -2
  3. package/lib/client.js +69 -93
  4. package/lib/config/index.d.ts +11 -4
  5. package/lib/config/index.js +26 -9
  6. package/lib/config/service.d.ts +2 -2
  7. package/lib/config/service.js +2 -2
  8. package/lib/debug-agent.js +1 -1
  9. package/lib/paths.d.ts +8 -0
  10. package/lib/paths.js +22 -0
  11. package/lib/plugin.d.ts +21 -1
  12. package/lib/plugin.js +153 -42
  13. package/lib/restart-guards.js +1 -1
  14. package/lib/restart-tool.js +13 -4
  15. package/lib/resume-log.d.ts +4 -0
  16. package/lib/resume-log.js +13 -4
  17. package/lib/snapshot.d.ts +3 -2
  18. package/lib/snapshot.js +3 -2
  19. package/lib/store/index.js +119 -45
  20. package/lib/supervisor.js +5 -7
  21. package/lib/types/client/config/MaestroSettings.d.ts.map +1 -1
  22. package/package.json +4 -2
  23. package/scripts/build-client.mjs +53 -0
  24. package/scripts/install-systemd.sh +55 -0
  25. package/scripts/sync/bench-preview.mjs +43 -0
  26. package/scripts/sync/cdp-sync-probe.mjs +200 -0
  27. package/scripts/sync/cdp-sync-verify.mjs +169 -0
  28. package/scripts/vendor-store.mjs +104 -0
  29. package/skills/dsh-safe-restart/SKILL.md +2 -2
  30. package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +2 -2
  31. package/src/client/config/MaestroSettings.tsx +8 -139
  32. package/src/client/sync/SyncPanel.tsx +1 -1
  33. package/src/client/sync/index.tsx +4 -4
  34. package/src/host/cli.ts +0 -2
  35. package/src/host/config/index.ts +27 -10
  36. package/src/host/config/service.ts +2 -2
  37. package/src/host/debug-agent.ts +1 -1
  38. package/src/host/paths.ts +21 -0
  39. package/src/host/plugin.ts +140 -30
  40. package/src/host/restart-guards.ts +1 -1
  41. package/src/host/restart-tool.ts +12 -4
  42. package/src/host/resume-log.ts +20 -5
  43. package/src/host/snapshot.ts +3 -2
  44. package/src/host/store/index.ts +120 -33
  45. package/src/host/supervisor.ts +6 -8
  46. package/systemd/dsh-web-keepalive.service.template +12 -0
  47. package/systemd/dsh-web-supervisor.service.template +20 -0
  48. package/systemd/dsh-web.service.template +30 -0
package/README.md CHANGED
@@ -5,7 +5,7 @@ Supervisor for DSH Web resilience — **Phase 1 Guard & Report + Phase 3 Auto-Re
5
5
  Runs **outside** the `pnpm → sh → node` tree (systemd daemon) to survive tree crashes, plus **inside** `dsh web` as a host+client Cordis plugin to auto-resume interrupted sessions and auto-reload the browser after restart.
6
6
 
7
7
  - **Daemon:** Polls `:3080` every 3s, keeps last-known-good (LKG) snapshots (`~/.dsh/.supervisor/lkg/`, `rotate 3`, `sha256` verify, `df` >500MB guard), auto-rollbacks on crash (`debounce 60s`, `flock` lock), writes `report-<ts>.md` (health + `git diff` + log tail), and notifies via Telegram (loose, never blocks).
8
- - **Host plugin:** `runAutoResume()` 8s after boot — `findInterrupted` (tail 100) + `findDanglingOpenTurns` (full scan for recent sessions) within `autoResumeWithin` (default 5m) → `agents.resume({resumeSessionId, agentOptions: {provider,model}})` recovered from `request/context` → `followup('continue')`. Loopback RPC `POST /dsh-maestro-supervisor-resume/{scan,resume}` (authority `loopback`) for the daemon (`resumeViaRpc`).
8
+ - **Host plugin:** `runAutoResume()` 8s after boot — `findInterrupted` (tail 100) + `findDanglingOpenTurns` (full scan for recent sessions) within `autoResumeWithin` (default 5m) → `agents.resume({resumeSessionId, agentOptions: {provider,model}})` recovered from `request/context` → `followup('continue')`. Loopback RPC `POST /dsh-maestro-supervisor-resume/{scan,resume}` (reachable from loopback; `connection.isLoopback` reports it) for the daemon (`resumeViaRpc`).
9
9
  - **Client plugin:** Hybrid auto-reload — `fetch HEAD /` polling 1s on `offline`/`WebSocket close`/`visibilitychange` → `200` → `location.reload()`. Served as `window.__ModuleLoader__.load` bundle at `/plugins/@ddtcorex/dsh-maestro-core/client.js` via `dsh.client`.
10
10
 
11
11
  ## Modules
@@ -14,7 +14,7 @@ One package, four host rows and one client bundle.
14
14
 
15
15
  | Module | Source | Row id | Channel | What it does |
16
16
  |---|---|---|---|---|
17
- | Supervisor | `src/host/*.ts` | `maestro-supervisor` | `/dsh-maestro-supervisor-resume` (loopback) | Crash polling, LKG snapshots, auto-resume, auto-reload |
17
+ | Supervisor | `src/host/*.ts` | `maestro-supervisor` | `/dsh-maestro-supervisor-resume` (loopback-reachable) | Crash polling, LKG snapshots, auto-resume, auto-reload |
18
18
  | Store | `src/host/store/` | — | — | The namespaced `settings.json` every other module reads and writes |
19
19
  | Config | `src/host/config/` | `maestro-config` | `/dsh-maestro-config` | `maestroConfig` service over the store, backing the Maestro settings card |
20
20
  | Guard | `src/host/guard/` | `dsh-maestro-guard` | `/dsh-maestro-guard` | Rule classification, the approval gate and its journal |
@@ -24,6 +24,23 @@ Row `name`s for the absorbed modules are subpaths of this package (`@ddtcorex/ds
24
24
 
25
25
  The store is also published on its own (`@ddtcorex/dsh-maestro-core/store`) and can be vendored into a consumer with `scripts/vendor-store.mjs`, which writes one self-verifying file with a body hash.
26
26
 
27
+ ## Registered tools
28
+
29
+ Host tools registered with `ctx.tools.register`:
30
+
31
+ | Tool | Module | What it does |
32
+ |---|---|---|
33
+ | `dsh_web_restart` | supervisor | Schedule a supervised `dsh web` restart (consent-gated) |
34
+ | `dsh_web_restart_status` | supervisor | Report the state of the last restart request |
35
+ | `dsh_web_dryboot` | supervisor | Dry-boot on an ephemeral port with an isolated `DSH_HOME` |
36
+ | `dsh_web_gc` | supervisor | Preview, then reap, verified dry-boot orphans |
37
+ | `maestro_session_health` | supervisor | Session-log health scan (re-encode or quarantine) |
38
+ | `maestro_resume_tool_health` | supervisor | Tool-view health of a resumed session |
39
+ | `maestro_repair_session_preset` | supervisor | Re-link an agent that joined no preset |
40
+ | `maestro_guard_status`, `maestro_guard_stats`, `maestro_full_scan` | guard | Guard state, counters and a full rule scan |
41
+ | `maestro_sync_status`, `maestro_sync_check_machines`, `maestro_sync_preview`, `maestro_sync_apply`, `maestro_sync_pull`, `maestro_sync_push`, `maestro_sync_bidirectional_preview`, `maestro_sync_bidirectional_apply`, `maestro_sync_tunnel_restore` | sync | Two-machine sync, preview first |
42
+ | `maestro_backup_preview`, `maestro_backup_apply`, `maestro_backup_gc_preview`, `maestro_backup_gc_apply`, `maestro_restore_preview`, `maestro_restore_apply` | sync | Backup, retention GC and restore, preview first |
43
+
27
44
  ## Install
28
45
 
29
46
  One package, one command:
@@ -77,7 +94,7 @@ To run without systemd (foreground, for debugging):
77
94
  ```bash
78
95
  node packages/dsh-maestro-core/lib/index.js daemon # poll every 3s
79
96
  node packages/dsh-maestro-core/lib/index.js status
80
- node packages/dsh-maestro-core/lib/index.js logs --tail 50
97
+ node packages/dsh-maestro-core/lib/index.js resume --within 5m # list interrupted sessions
81
98
  ```
82
99
 
83
100
  ## Configuration
@@ -87,7 +104,7 @@ All `autoResumeWithin` values are **minutes** when given as `number` (e.g. `5`
87
104
  1. **Cordis config** (`cordis.patch.yml` `config:` or `apply(ctx, config)`) — explicit per-install.
88
105
  2. **Env** `DSH_SUPERVISOR_AUTO_RESUME` / `DSH_SUPERVISOR_RESUME_WITHIN` (bare `5` in env → 5m for ergonomics).
89
106
  3. **Supervisor config** `~/.dsh/.supervisor/config.json` (`autoResumeEnabled`, `autoResumeWithin`).
90
- 4. **Maestro settings** `~/.dsh/maestro/settings.json` (`domains.supervisor.*`).
107
+ 4. **Maestro settings** `~/.dsh/dsh-maestro-config/settings.json` (`domains.supervisor.*`).
91
108
  5. **Default:** `true` / `5`.
92
109
 
93
110
  | Key | Type | Default | Env | File | Notes |
@@ -110,11 +127,13 @@ Example `~/.dsh/.supervisor/config.json`:
110
127
  node packages/dsh-maestro-core/lib/index.js --help
111
128
  node packages/dsh-maestro-core/lib/index.js status
112
129
  node packages/dsh-maestro-core/lib/index.js daemon # poll 3s, debounce 60s
113
- node packages/dsh-maestro-core/lib/index.js logs --tail 50
114
- node packages/dsh-maestro-core/lib/index.js rollback --latest
130
+ node packages/dsh-maestro-core/lib/index.js resume [--within <dur>] # list interrupted sessions, e.g. 5m, 30s, 1h
131
+ node packages/dsh-maestro-core/lib/index.js boot-guard acquire|release --pid <pid> # boot.lock + boot-boundary, used by the safe-restart script
115
132
  ```
116
133
 
117
- ## RPC (loopback only, `authority: loopback`)
134
+ The CLI has no `logs` or `rollback` command: rollback runs inside the daemon, and reports are files under `~/.dsh/.supervisor/reports/`.
135
+
136
+ ## RPC (reachable from loopback, `connection.isLoopback`)
118
137
 
119
138
  ```bash
120
139
  # Scan (findInterrupted only, tail 100)
@@ -131,7 +150,7 @@ curl -s http://127.0.0.1:3080/dsh-maestro-supervisor-resume/resume -X POST \
131
150
  # or {"ok":false,"error":{"code":"bad-request","message":"resume requires at least one session id"}}
132
151
  ```
133
152
 
134
- The daemon uses `resumeViaRpc()` (`supervisor.ts:24`) which POSTs the same envelope to `http://127.0.0.1:3080/dsh-maestro-supervisor-resume/resume` with `fetch` and validates `server-response` + `rpcId` + `result.ok`.
153
+ The daemon uses `resumeViaRpc()` (`supervisor.ts`) which POSTs the same envelope to `http://127.0.0.1:3080/dsh-maestro-supervisor-resume/resume` with `fetch` and validates `server-response` + `rpcId` + `result.ok`.
135
154
 
136
155
  ## Auto-Resume Details
137
156
 
@@ -169,7 +188,7 @@ node --input-type=module -e "import {findDanglingOpenTurns} from './packages/dsh
169
188
  |---------|-------|-----|
170
189
  | `Cannot find package '.../dsh-maestro-core/index.js'` | `pnpm build` not run or `lib/` stale | `pnpm --dir packages/dsh-maestro-core build && pnpm --dir ~/.dsh/profiles/web install` |
171
190
  | `exports no "./client" bundle` / `client bundle not found` | Missing `lib/client.js` or `exports["./client"]` | `pnpm build` (runs `tsc` + `tsc -p tsconfig.client.json` + `node scripts/build-client.mjs`), check `package.json` `exports` and `dsh.client`, `test -f lib/client.js`, `curl .../client.js` |
172
- | `EADDRINUSE ::3000` on `dsh web --port 0` | Old `MainThread` still holds `:3000`+`:3080` | `ss -tlnp | grep 3080` → pid, `kill <pid>` (same pid holds both), wait `ss` free. Never `pkill -f "dsh web"` — it kills the test shell. |
191
+ | `EADDRINUSE` on a fixed port of `dsh web` | A previous `dsh web` still holds the listener tree: `:3080` (LAN proxy), `:3081` (public proxy), `:3082` (raw webserver); `:3000` is unbound | `ss -tlnp | grep -E ':308[012]'` → pid, hand the restart to the human or `dsh_web_restart`; never kill a live session's process yourself, and never `pkill -f "dsh web"`, it kills the invoking shell. |
173
192
  | `uses .jsonl but backend is zstd` | Hand-written `session.jsonl` while backend is `zstd` | Use `zstd -c plain.jsonl > session.jsonl.zstd` or `JsonlSessionPersistence` API. Never hand-write opposite encoding — `listArtifacts` checks every project dir on boot and one stray file blocks all of `dsh web`. |
174
193
  | `first frame is not exactly one header line` | zstd without `type: session` header | Use `toHeaderLine` + `compressZstdFrame(header)` + `compressZstdFrame(body)` as in `encodeMaterialization`. |
175
194
  | `findDangling` 0 but subagent still open | Tail window too small (before `63b7719`) | Fixed: `findDangling` now full-scans recent sessions (mtime within window). `findInterrupted` stays tail 100. |
@@ -182,9 +201,9 @@ node --input-type=module -e "import {findDanglingOpenTurns} from './packages/dsh
182
201
 
183
202
  - **Manual `session.jsonl` vs `zstd`:** One stray opposite-encoding file under `~/.dsh/sessions/` blocks the entire `workspace` `listArtifacts` on every boot (`encodingMismatch`). See Troubleshooting.
184
203
  - **Tail vs full scan:** Before `63b7719`, `b6487e33` subagent missed because its only `turn/start` was at seq 6 at the very beginning of a 1906-line log. Fixed, but if you add a new scan variant, reuse `readSessionAllLines` with mtime pre-filter.
185
- - **Port pair:** One `MainThread` holds `:3080`+`:3000`. Use `ss -tlnp` + `kill <pid>` for the one pid, not `pkill -f`.
204
+ - **Port map:** `:3080` is the LAN proxy (PIN login), `:3081` the public proxy, `:3082` the raw `dsh web` webserver; `:3000` is unbound. Inspect with `ss -tlnp`; never `pkill -f "dsh web"`.
186
205
  - **Client bundling:** `lib/client.js` must be `window.__ModuleLoader__.load` wrapper via `scripts/build-client.mjs`, not bare `export`. Add new client files under `src/client/` and ensure `tsconfig.client.json` includes them, then `pnpm build`.
187
- - **Config precedence:** `cordis.patch.yml` `config:` > env (`DSH_SUPERVISOR_RESUME_WITHIN` bare `5` → 5m) > `config.json` > `settings.json` > default. See `plugin.ts:71` and `supervisor.ts:82`.
206
+ - **Config precedence:** `cordis.patch.yml` `config:` > env (`DSH_SUPERVISOR_RESUME_WITHIN` bare `5` → 5m) > `config.json` > `settings.json` > default. See `getAutoResumeEnabled()` and `getResumeWithinMs()` in `plugin.ts` and `supervisor.ts`.
188
207
 
189
208
  ## Development
190
209
 
@@ -204,6 +223,6 @@ Hard mode (optional): `package.json` add `"@ddtcorex/dsh-maestro-notifier": "wor
204
223
 
205
224
  ## See Also
206
225
 
207
- - Spec: `<workspace-root>/docs/specs/2026-08-27-dsh-web-resilience-design.md`
226
+ - Spec: `<workspace-root>/docs/specs/2026-09-13-supervisor-restart-resilience-design.md`
208
227
  - Skill: `skills/dsh-safe-restart/` (`restart-dsh-web.sh` with `dry_boot_and_verify()` and `--auto`)
209
228
  - Client bundling: `dsh-maestro-mobile` (`scripts/build-client.mjs` pattern)
package/lib/cli.js CHANGED
@@ -165,8 +165,6 @@ export async function runCli(args) {
165
165
  Commands:
166
166
  daemon Run supervisor daemon (poll every 3s)
167
167
  status Show health + LKG status
168
- logs Tail supervisor reports
169
- rollback --to <ts> Rollback to LKG <ts>
170
168
  resume [--within <dur>] List interrupted sessions (filter by time, e.g. 5m, 30s, 1h)
171
169
  boot-guard acquire|release --pid <pid> Take/release boot.lock + boot-boundary (used by the safe-restart script)
172
170
  `);
package/lib/client.js CHANGED
@@ -285,6 +285,7 @@ var t = {
285
285
  bgLayer2: "var(--dsw-alias-bg-layer-2)",
286
286
  bgLayer3: "var(--dsw-alias-bg-layer-3)",
287
287
  borderL2: "var(--dsw-alias-border-l2)",
288
+ borderL4: "var(--dsw-alias-border-l4)",
288
289
  labelPrimary: "var(--dsw-alias-label-primary)",
289
290
  labelSecondary: "var(--dsw-alias-label-secondary)",
290
291
  labelTertiary: "var(--dsw-alias-label-tertiary)",
@@ -417,16 +418,6 @@ function FieldInput(props) {
417
418
  })
418
419
  );
419
420
  }
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
421
  var captionStyle = {
431
422
  fontSize: "12px",
432
423
  lineHeight: "16px",
@@ -470,22 +461,6 @@ var rowDescStyle = {
470
461
  lineHeight: "18px",
471
462
  color: t.labelTertiary
472
463
  };
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
464
  function SettingRow({ title, description, control }) {
490
465
  return (0, import_react2.createElement)(
491
466
  "div",
@@ -603,6 +578,7 @@ function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }) {
603
578
  const [supervisorStatus, setSupervisorStatus] = (0, import_react2.useState)(null);
604
579
  const [supervisorCfg, setSupervisorCfg] = (0, import_react2.useState)({});
605
580
  const [activeTab, setActiveTab] = (0, import_react2.useState)("guard");
581
+ const [error, setError] = (0, import_react2.useState)(null);
606
582
  (0, import_react2.useEffect)(() => {
607
583
  const css = `
608
584
  /* Model override dropdown \u2014 prevent right-edge overlap */
@@ -810,11 +786,11 @@ function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }) {
810
786
  },
811
787
  "aria-label": meta.label,
812
788
  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)",
789
+ minHeight: 44,
790
+ padding: "6px 12px",
791
+ border: "0.5px solid var(--dsw-alias-border-l4)",
792
+ borderRadius: "var(--dsw-radius-md)",
793
+ background: t.bgLayer3,
818
794
  color: t.labelPrimary,
819
795
  font: "inherit",
820
796
  fontSize: 13
@@ -1349,7 +1325,7 @@ function useSync(ctx) {
1349
1325
  const [checking, setChecking] = React.useState(false);
1350
1326
  const [busy, setBusy] = React.useState(false);
1351
1327
  const [result, setResult] = React.useState(null);
1352
- const [error2, setError2] = React.useState("");
1328
+ const [error, setError] = React.useState("");
1353
1329
  const [preview, setPreview] = React.useState(null);
1354
1330
  const [previewDirection, setPreviewDirection] = React.useState("pull");
1355
1331
  const [confirmOpen, setConfirmOpen] = React.useState(false);
@@ -1397,13 +1373,13 @@ function useSync(ctx) {
1397
1373
  [call]
1398
1374
  );
1399
1375
  const loadStatus = React.useCallback(async () => {
1400
- setError2("");
1376
+ setError("");
1401
1377
  setChecking(true);
1402
1378
  setStatus(null);
1403
1379
  try {
1404
1380
  const res = await call("status", {});
1405
1381
  if (res?.ok === false) {
1406
- setError2(res?.error ?? "status failed");
1382
+ setError(res?.error ?? "status failed");
1407
1383
  return;
1408
1384
  }
1409
1385
  setStatus(res);
@@ -1412,7 +1388,7 @@ function useSync(ctx) {
1412
1388
  else setConnection({ ok: true, host: res?.remoteHost ?? "kai@ssh.ddtcorex.com" });
1413
1389
  if (typeof res?.remoteHost === "string" && res.remoteHost) setRemoteHost(res.remoteHost);
1414
1390
  } catch (e) {
1415
- setError2(e?.message ?? String(e));
1391
+ setError(e?.message ?? String(e));
1416
1392
  } finally {
1417
1393
  setChecking(false);
1418
1394
  }
@@ -1439,7 +1415,7 @@ function useSync(ctx) {
1439
1415
  const handlePreview = React.useCallback(
1440
1416
  async (direction) => {
1441
1417
  setBusy(true);
1442
- setError2("");
1418
+ setError("");
1443
1419
  setResult(null);
1444
1420
  setActionLimit(5);
1445
1421
  setProgress({ phase: "listing", current: 0, total: 1 });
@@ -1447,7 +1423,7 @@ function useSync(ctx) {
1447
1423
  const start = await call("previewStart", { direction });
1448
1424
  const jobId = start?.jobId;
1449
1425
  if (!jobId) {
1450
- setError2(start?.error ?? "Preview failed to start");
1426
+ setError(start?.error ?? "Preview failed to start");
1451
1427
  setProgress(null);
1452
1428
  return;
1453
1429
  }
@@ -1463,21 +1439,21 @@ function useSync(ctx) {
1463
1439
  setPreviewDirection(direction);
1464
1440
  setConfirmOpen(true);
1465
1441
  } else {
1466
- setError2("Preview finished without a result");
1442
+ setError("Preview finished without a result");
1467
1443
  }
1468
1444
  done = true;
1469
1445
  } else if (st?.status === "error") {
1470
- setError2(st.error ?? "Preview failed");
1446
+ setError(st.error ?? "Preview failed");
1471
1447
  done = true;
1472
1448
  } else if (st?.ok === false) {
1473
- setError2(st.error ?? "Preview failed");
1449
+ setError(st.error ?? "Preview failed");
1474
1450
  done = true;
1475
1451
  } else {
1476
1452
  await new Promise((r) => setTimeout(r, 700));
1477
1453
  }
1478
1454
  }
1479
1455
  } catch (e) {
1480
- setError2(e?.message ?? String(e));
1456
+ setError(e?.message ?? String(e));
1481
1457
  } finally {
1482
1458
  setBusy(false);
1483
1459
  setProgress(null);
@@ -1488,7 +1464,7 @@ function useSync(ctx) {
1488
1464
  const handleApply = React.useCallback(async () => {
1489
1465
  if (!preview?.previewId) return;
1490
1466
  setBusy(true);
1491
- setError2("");
1467
+ setError("");
1492
1468
  const previewId = preview.previewId;
1493
1469
  const direction = previewDirection;
1494
1470
  try {
@@ -1497,7 +1473,7 @@ function useSync(ctx) {
1497
1473
  setPreview(null);
1498
1474
  if (res?.ok === false) {
1499
1475
  const label = typeof res.code === "string" ? res.code : "apply failed";
1500
- setError2(`${label}: ${res?.error ?? "apply failed"}`);
1476
+ setError(`${label}: ${res?.error ?? "apply failed"}`);
1501
1477
  setResult({ kind: "apply", ok: false, text: "Apply failed" });
1502
1478
  return;
1503
1479
  }
@@ -1507,7 +1483,7 @@ function useSync(ctx) {
1507
1483
  } catch (e) {
1508
1484
  setConfirmOpen(false);
1509
1485
  setPreview(null);
1510
- setError2(e?.message ?? String(e));
1486
+ setError(e?.message ?? String(e));
1511
1487
  } finally {
1512
1488
  setBusy(false);
1513
1489
  }
@@ -1518,24 +1494,24 @@ function useSync(ctx) {
1518
1494
  }, []);
1519
1495
  const handleBidirectionalPreview = React.useCallback(async () => {
1520
1496
  setBusy(true);
1521
- setError2("");
1497
+ setError("");
1522
1498
  setResult(null);
1523
1499
  setActionLimit(5);
1524
1500
  setProgress({ phase: "planning", current: 0, total: 1 });
1525
1501
  try {
1526
1502
  const combined = await call("bidirectionalPreview", {});
1527
1503
  if (combined?.ok === false) {
1528
- setError2(combined?.error ?? "Bidirectional preview failed");
1504
+ setError(combined?.error ?? "Bidirectional preview failed");
1529
1505
  return;
1530
1506
  }
1531
1507
  if (!combined?.previewId) {
1532
- setError2("Bidirectional preview finished without a result");
1508
+ setError("Bidirectional preview finished without a result");
1533
1509
  return;
1534
1510
  }
1535
1511
  setBiPreview(combined);
1536
1512
  setBiConfirmOpen(true);
1537
1513
  } catch (e) {
1538
- setError2(e?.message ?? String(e));
1514
+ setError(e?.message ?? String(e));
1539
1515
  } finally {
1540
1516
  setBusy(false);
1541
1517
  setProgress(null);
@@ -1544,7 +1520,7 @@ function useSync(ctx) {
1544
1520
  const handleBidirectionalApply = React.useCallback(async () => {
1545
1521
  if (!biPreview?.previewId) return;
1546
1522
  setBusy(true);
1547
- setError2("");
1523
+ setError("");
1548
1524
  const previewId = biPreview.previewId;
1549
1525
  try {
1550
1526
  const res = await call("bidirectionalApply", { previewId, confirm: true });
@@ -1552,7 +1528,7 @@ function useSync(ctx) {
1552
1528
  setBiPreview(null);
1553
1529
  if (res?.ok === false) {
1554
1530
  const label = typeof res.code === "string" ? res.code : "apply failed";
1555
- setError2(`${label}: ${res?.error ?? "apply failed"}`);
1531
+ setError(`${label}: ${res?.error ?? "apply failed"}`);
1556
1532
  setResult({ kind: "bidirectional", ok: false, text: "Both-ways apply failed" });
1557
1533
  return;
1558
1534
  }
@@ -1570,7 +1546,7 @@ function useSync(ctx) {
1570
1546
  } catch (e) {
1571
1547
  setBiConfirmOpen(false);
1572
1548
  setBiPreview(null);
1573
- setError2(e?.message ?? String(e));
1549
+ setError(e?.message ?? String(e));
1574
1550
  } finally {
1575
1551
  setBusy(false);
1576
1552
  }
@@ -1581,7 +1557,7 @@ function useSync(ctx) {
1581
1557
  }, []);
1582
1558
  const saveRemoteHost = React.useCallback(
1583
1559
  async (host) => {
1584
- setError2("");
1560
+ setError("");
1585
1561
  setHostFieldError(null);
1586
1562
  try {
1587
1563
  const res = await call("saveRemoteHost", { host });
@@ -1618,7 +1594,7 @@ function useSync(ctx) {
1618
1594
  }
1619
1595
  }, [call]);
1620
1596
  const checkConnection = React.useCallback(async () => {
1621
- setError2("");
1597
+ setError("");
1622
1598
  setResult(null);
1623
1599
  setChecking(true);
1624
1600
  try {
@@ -1641,23 +1617,23 @@ function useSync(ctx) {
1641
1617
  }
1642
1618
  }, [call, loadStatus, loadMachines, remoteHost]);
1643
1619
  const handleTunnelRestorePreview = React.useCallback(async () => {
1644
- setError2("");
1620
+ setError("");
1645
1621
  setResult(null);
1646
1622
  setBusy(true);
1647
1623
  try {
1648
1624
  const res = await call("tunnelRestorePreview", { side: "local" });
1649
1625
  if (res?.ok === false) {
1650
- setError2(res?.error ?? "tunnel restore preview failed");
1626
+ setError(res?.error ?? "tunnel restore preview failed");
1651
1627
  return;
1652
1628
  }
1653
1629
  if (!res?.previewId) {
1654
- setError2("Tunnel restore preview finished without a result");
1630
+ setError("Tunnel restore preview finished without a result");
1655
1631
  return;
1656
1632
  }
1657
1633
  setTunnelPreview(res);
1658
1634
  setTunnelConfirmOpen(true);
1659
1635
  } catch (e) {
1660
- setError2(e?.message ?? String(e));
1636
+ setError(e?.message ?? String(e));
1661
1637
  } finally {
1662
1638
  setBusy(false);
1663
1639
  }
@@ -1665,7 +1641,7 @@ function useSync(ctx) {
1665
1641
  const confirmTunnelRestore = React.useCallback(async () => {
1666
1642
  const previewId = tunnelPreview?.previewId;
1667
1643
  if (!previewId) return;
1668
- setError2("");
1644
+ setError("");
1669
1645
  setBusy(true);
1670
1646
  try {
1671
1647
  const res = await call("tunnelRestore", { side: "local", previewId, confirm: true });
@@ -1674,12 +1650,12 @@ function useSync(ctx) {
1674
1650
  if (res && res.ok) {
1675
1651
  setResult({ kind: "tunnel-restore", ok: true, text: `Tunnel restored from profile ${res.profile ?? "auto"} (local)` });
1676
1652
  } else {
1677
- setError2(res?.error ?? "tunnel restore failed");
1653
+ setError(res?.error ?? "tunnel restore failed");
1678
1654
  }
1679
1655
  } catch (e) {
1680
1656
  setTunnelConfirmOpen(false);
1681
1657
  setTunnelPreview(null);
1682
- setError2(e?.message ?? String(e));
1658
+ setError(e?.message ?? String(e));
1683
1659
  } finally {
1684
1660
  setBusy(false);
1685
1661
  }
@@ -1710,7 +1686,7 @@ function useSync(ctx) {
1710
1686
  checking,
1711
1687
  busy,
1712
1688
  result,
1713
- error: error2,
1689
+ error,
1714
1690
  hostFieldError,
1715
1691
  setHostFieldError,
1716
1692
  preview,
@@ -1724,7 +1700,7 @@ function useSync(ctx) {
1724
1700
  progress,
1725
1701
  pages,
1726
1702
  setActionLimit,
1727
- setError: setError2,
1703
+ setError,
1728
1704
  setResult,
1729
1705
  loadStatus,
1730
1706
  loadPage,
@@ -1749,7 +1725,7 @@ function useBackupTarget(ctx) {
1749
1725
  const [status, setStatus] = React2.useState(null);
1750
1726
  const [checking, setChecking] = React2.useState(true);
1751
1727
  const [busy, setBusy] = React2.useState(false);
1752
- const [error2, setError2] = React2.useState("");
1728
+ const [error, setError] = React2.useState("");
1753
1729
  const [backupPreview, setBackupPreview] = React2.useState(null);
1754
1730
  const [restorePreview, setRestorePreview] = React2.useState(null);
1755
1731
  const [gcReport, setGcReport] = React2.useState(null);
@@ -1762,29 +1738,29 @@ function useBackupTarget(ctx) {
1762
1738
  }, [ctx]);
1763
1739
  const loadStatus = React2.useCallback(async () => {
1764
1740
  setChecking(true);
1765
- setError2("");
1741
+ setError("");
1766
1742
  try {
1767
1743
  const res = await call("backupStatus", {});
1768
1744
  if (res.ok) setStatus(res.value);
1769
- else setError2(res.error?.message ?? "backup status failed");
1745
+ else setError(res.error?.message ?? "backup status failed");
1770
1746
  } catch (e) {
1771
- setError2(e?.message ?? String(e));
1747
+ setError(e?.message ?? String(e));
1772
1748
  } finally {
1773
1749
  setChecking(false);
1774
1750
  }
1775
1751
  }, [call]);
1776
1752
  const previewBackup = React2.useCallback(async () => {
1777
1753
  setBusy(true);
1778
- setError2("");
1754
+ setError("");
1779
1755
  setBackupPreview(null);
1780
1756
  try {
1781
1757
  const res = await call("backupPreview", {});
1782
1758
  if (res.ok) {
1783
1759
  setBackupPreview(res.value);
1784
1760
  setConfirmOpen("backup");
1785
- } else setError2(res.error?.message ?? "backup preview failed");
1761
+ } else setError(res.error?.message ?? "backup preview failed");
1786
1762
  } catch (e) {
1787
- setError2(e?.message ?? String(e));
1763
+ setError(e?.message ?? String(e));
1788
1764
  } finally {
1789
1765
  setBusy(false);
1790
1766
  }
@@ -1796,10 +1772,10 @@ function useBackupTarget(ctx) {
1796
1772
  const res = await call("backupApply", { previewId: backupPreview.previewId, confirm: true });
1797
1773
  setConfirmOpen(null);
1798
1774
  setBackupPreview(null);
1799
- if (!res.ok) setError2(res.error?.message ?? "backup apply failed");
1775
+ if (!res.ok) setError(res.error?.message ?? "backup apply failed");
1800
1776
  void loadStatus();
1801
1777
  } catch (e) {
1802
- setError2(e?.message ?? String(e));
1778
+ setError(e?.message ?? String(e));
1803
1779
  } finally {
1804
1780
  setBusy(false);
1805
1781
  }
@@ -1807,15 +1783,15 @@ function useBackupTarget(ctx) {
1807
1783
  const previewRestore = React2.useCallback(
1808
1784
  async (mode) => {
1809
1785
  setBusy(true);
1810
- setError2("");
1786
+ setError("");
1811
1787
  try {
1812
1788
  const res = await call("restorePreview", { mode });
1813
1789
  if (res.ok) {
1814
1790
  setRestorePreview(res.value);
1815
1791
  setConfirmOpen("restore");
1816
- } else setError2(res.error?.message ?? "restore preview failed");
1792
+ } else setError(res.error?.message ?? "restore preview failed");
1817
1793
  } catch (e) {
1818
- setError2(e?.message ?? String(e));
1794
+ setError(e?.message ?? String(e));
1819
1795
  } finally {
1820
1796
  setBusy(false);
1821
1797
  }
@@ -1830,10 +1806,10 @@ function useBackupTarget(ctx) {
1830
1806
  const res = await call("restoreApply", { previewId: restorePreview.previewId, mode, destDir, confirm: true });
1831
1807
  setConfirmOpen(null);
1832
1808
  setRestorePreview(null);
1833
- if (!res.ok) setError2(res.error?.message ?? "restore apply failed");
1809
+ if (!res.ok) setError(res.error?.message ?? "restore apply failed");
1834
1810
  if (mode === "in-place") void loadStatus();
1835
1811
  } catch (e) {
1836
- setError2(e?.message ?? String(e));
1812
+ setError(e?.message ?? String(e));
1837
1813
  } finally {
1838
1814
  setBusy(false);
1839
1815
  }
@@ -1842,15 +1818,15 @@ function useBackupTarget(ctx) {
1842
1818
  );
1843
1819
  const previewGc = React2.useCallback(async () => {
1844
1820
  setBusy(true);
1845
- setError2("");
1821
+ setError("");
1846
1822
  try {
1847
1823
  const res = await call("backupGcPreview", {});
1848
1824
  if (res.ok) {
1849
1825
  setGcReport(res.value);
1850
1826
  setConfirmOpen("gc");
1851
- } else setError2(res.error?.message ?? "gc preview failed");
1827
+ } else setError(res.error?.message ?? "gc preview failed");
1852
1828
  } catch (e) {
1853
- setError2(e?.message ?? String(e));
1829
+ setError(e?.message ?? String(e));
1854
1830
  } finally {
1855
1831
  setBusy(false);
1856
1832
  }
@@ -1862,10 +1838,10 @@ function useBackupTarget(ctx) {
1862
1838
  const res = await call("backupGcApply", { previewId: gcReport.previewId, confirm: true });
1863
1839
  setConfirmOpen(null);
1864
1840
  setGcReport(null);
1865
- if (!res.ok) setError2(res.error?.message ?? "gc apply failed");
1841
+ if (!res.ok) setError(res.error?.message ?? "gc apply failed");
1866
1842
  void loadStatus();
1867
1843
  } catch (e) {
1868
- setError2(e?.message ?? String(e));
1844
+ setError(e?.message ?? String(e));
1869
1845
  } finally {
1870
1846
  setBusy(false);
1871
1847
  }
@@ -1878,19 +1854,19 @@ function useBackupTarget(ctx) {
1878
1854
  }, []);
1879
1855
  const saveR2Config = React2.useCallback(
1880
1856
  async (fields) => {
1881
- setError2("");
1857
+ setError("");
1882
1858
  try {
1883
1859
  const res = await call("saveR2Config", fields);
1884
1860
  if (!res.ok) {
1885
1861
  const msg = res.error?.message ?? "save failed";
1886
- setError2(msg);
1862
+ setError(msg);
1887
1863
  return { ok: false, error: msg };
1888
1864
  }
1889
1865
  await loadStatus();
1890
1866
  return { ok: true };
1891
1867
  } catch (e) {
1892
1868
  const msg = e?.message ?? String(e);
1893
- setError2(msg);
1869
+ setError(msg);
1894
1870
  return { ok: false, error: msg };
1895
1871
  }
1896
1872
  },
@@ -1904,7 +1880,7 @@ function useBackupTarget(ctx) {
1904
1880
  status,
1905
1881
  checking,
1906
1882
  busy,
1907
- error: error2,
1883
+ error,
1908
1884
  backupPreview,
1909
1885
  restorePreview,
1910
1886
  gcReport,
@@ -2279,7 +2255,7 @@ function SyncPanel(props) {
2279
2255
  const s = useSync(props.ctx);
2280
2256
  const b = useBackupTarget(props.ctx);
2281
2257
  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;
2258
+ const { connection, checking, busy, error, result, status, remoteHost, remoteSource, lastSync, confirmOpen, preview, previewDirection, biPreview, biConfirmOpen, tunnelPreview, tunnelConfirmOpen, hostFieldError, actionLimit, pages } = s;
2283
2259
  const st = b.status;
2284
2260
  const isConnected = connection?.ok === true;
2285
2261
  const isDisconnected = connection?.ok === false;
@@ -2375,7 +2351,7 @@ function SyncPanel(props) {
2375
2351
  "aria-invalid": hostFieldError ? "true" : void 0
2376
2352
  }
2377
2353
  ),
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,
2354
+ hostFieldError ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-field-error": "", role: "alert", "data-testid": "sync-ssh-host-error", style: { fontSize: 12, lineHeight: "16px", color: "var(--dsw-alias-state-error-primary)", overflowWrap: "anywhere" }, children: hostFieldError }) : null,
2379
2355
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-ssh-row": "", children: [
2380
2356
  /* @__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
2357
  /* @__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" })
@@ -2496,11 +2472,11 @@ function SyncPanel(props) {
2496
2472
  /* @__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
2473
  ] })
2498
2474
  ] }),
2499
- error2 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-notice": "", "data-tone": "bad", role: "alert", children: [
2475
+ error ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-sync-notice": "", "data-tone": "bad", role: "alert", children: [
2500
2476
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-icon": "", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "alert" }) }),
2501
2477
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { "data-sync-notice-main": "", children: [
2502
2478
  /* @__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 })
2479
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-sync-notice-desc": "", children: error })
2504
2480
  ] })
2505
2481
  ] }) : null,
2506
2482
  confirmOpen && preview ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -2804,8 +2780,8 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
2804
2780
  }
2805
2781
  /* SSH configuration \u2014 user-filled target, explicit check, nothing auto-probes */
2806
2782
  [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; }
2783
+ [data-sync-ssh-label] { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
2784
+ [data-sync-ssh-input] { min-height: 44px; padding: 6px 12px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; box-sizing: border-box; }
2809
2785
  [data-sync-ssh-input]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2810
2786
  [data-sync-ssh-input]:disabled { opacity: 0.6; }
2811
2787
  [data-sync-ssh-row] { display: flex; gap: 8px; flex-wrap: wrap; }
@@ -2818,7 +2794,7 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
2818
2794
  [data-r2-config-label] { font-size: 11px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
2819
2795
  [data-r2-field] { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
2820
2796
  [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; }
2797
+ [data-r2-field-input] { min-height: 44px; padding: 6px 12px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); font: inherit; width: 100%; box-sizing: border-box; }
2822
2798
  [data-r2-field-input]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
2823
2799
  [data-r2-field-input]:disabled { opacity: 0.6; }
2824
2800
  [data-r2-field-hint] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-tertiary); }
@@ -2836,7 +2812,7 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
2836
2812
  [data-r2-config-row] > [data-sync-btn] { flex: 1 1 0; }
2837
2813
  [data-r2-config-hint] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); }
2838
2814
  @media (max-width: 640px) {
2839
- [data-sync-ssh-row] > [data-sync-btn] { min-height: 48px !important; }
2815
+ [data-sync-ssh-row] > [data-sync-btn] { min-height: 44px !important; }
2840
2816
  }
2841
2817
 
2842
2818
  /* iOS 16px field floor hold (dsh-maestro-mobile zoom guard).