1234567export type SyncOutcome =8 | "completed_changes"9 | "completed_no_changes"10 | "no_paired_devices"11 | "no_eligible_host"12 | "runner_unavailable"13 | "sync_disabled"14 | "private_relay_unset"15 | "vault_locked"16 | "relay_unreachable"17 | "handshake_failed"18 | "vault_id_mismatch"19 | "sync_timeout"20 | "run_failed";212223const FAILURES: ReadonlySet<SyncOutcome> = new Set<SyncOutcome>([24 "no_eligible_host",25 "runner_unavailable",26 "private_relay_unset",27 "vault_locked",28 "relay_unreachable",29 "handshake_failed",30 "vault_id_mismatch",31 "sync_timeout",32 "run_failed",33]);3435export function isSyncFailure(outcome: SyncOutcome): boolean {36 return FAILURES.has(outcome);37}3839export interface SyncOutcomeSummary {40 status?: "idle" | "syncing" | "error";41 outcome?: SyncOutcome;42 entriesSent?: number;43 entriesReceived?: number;44 detail?: string;45}46474849505152export type SyncIndicator = "busy" | "ok" | "error" | "idle";5354export function syncIndicator(s: SyncOutcomeSummary, pairedCount: number): SyncIndicator {55 if (s.status === "syncing") return "busy";56 if (s.outcome && isSyncFailure(s.outcome)) return "error";57 if (s.outcome === "completed_changes" || s.outcome === "completed_no_changes") {58 return "ok";59 }60 61 62 if (pairedCount > 0 && s.outcome === undefined) return "ok";63 return "idle";64}6566const INDICATOR_LABEL: Record<SyncIndicator, string> = {67 busy: "Syncing",68 ok: "Sync healthy",69 error: "Sync problem",70 idle: "Not syncing",71};727374export function syncIndicatorLabel(75 indicator: SyncIndicator,76 s: SyncOutcomeSummary,77): string {78 return `${INDICATOR_LABEL[indicator]} — ${describeSyncOutcome(s)}`;79}8081const COPY: Record<SyncOutcome, string> = {82 completed_changes: "Synced",83 completed_no_changes: "Up to date — nothing to send or receive",84 no_paired_devices: "No devices paired yet",85 no_eligible_host: "Paired, but no device here can accept a sync",86 runner_unavailable: "Sync isn't running in the background — reload Peach",87 sync_disabled: "Sync is switched off",88 private_relay_unset: "Private relay chosen but no address set",89 vault_locked: "Vault was locked — unlock and sync again",90 relay_unreachable: "Couldn't reach the relay",91 handshake_failed: "Reached the relay, but the device didn't answer",92 vault_id_mismatch: "That device holds a different vault",93 sync_timeout: "The device stopped responding mid-sync",94 run_failed: "Sync failed",95};96979899100101102103export function describeSyncOutcome(s: SyncOutcomeSummary): string {104 if (!s.outcome) return "Not synced yet";105 const base = COPY[s.outcome] ?? "Sync failed";106 if (s.outcome === "completed_changes") {107 const moved = [108 (s.entriesSent ?? 0) > 0 ? `${s.entriesSent} sent` : null,109 (s.entriesReceived ?? 0) > 0 ? `${s.entriesReceived} received` : null,110 ].filter(Boolean);111 return moved.length > 0 ? `${base} — ${moved.join(", ")}` : base;112 }113 return s.detail ? `${base} (${s.detail})` : base;114}