feat: add managed database capture and operator restore

PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-10 23:26:49 +07:00
parent 30a1a9b8f0
commit 6320b6f244
96 changed files with 11061 additions and 725 deletions

View File

@@ -1,14 +1,15 @@
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { AnimatePresence } from "motion/react";
import { AnimatePresence, useMotionValue } from "motion/react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
abortReconstitute, fetchHealth, fetchOrbits, fetchSnapshots, pollReconstitute,
runOrbit, startReconstitute, type Orbit,
enqueueCapture, runOrbit, startReconstitute, type Orbit,
} from "./api";
import { DecayView } from "./components/decay/DecayView";
import { OrbitInspector, OrbitRegister, TelemetryStrip } from "./components/hud/DiegeticHUD";
import { HUDPanel } from "./components/hud/HUDPanel";
import { HUDRail, type HUDMode } from "./components/hud/HUDRail";
import { SearchIcon, VaultSearch } from "./components/hud/VaultSearch";
import { OperatorGate } from "./components/operator/OperatorGate";
import { OrbitsView } from "./components/orbits/OrbitsView";
import { WormholeView } from "./components/outposts/WormholeView";
import { ReconstituteWizard } from "./components/reconstitute/ReconstituteWizard";
@@ -20,12 +21,12 @@ import { SnapshotSheet } from "./components/vault/SnapshotSheet";
import { useReducedMotion } from "./hooks/useReducedMotion";
import { orbitStatus } from "./lib/format";
import { groupSnapshots } from "./lib/galaxyLayout";
import type { SearchResult } from "./lib/vaultSearch";
const panelTitles: Record<HUDMode, string> = {
scene: "Vault",
orbits: "Orbit management",
wormhole: "Wormhole uplink",
decay: "Snapshot retention",
reconstitute: "Restore snapshot",
snapshot: "Snapshot detail",
};
@@ -36,10 +37,17 @@ function priority(orbit: Orbit) {
}
export default function App() {
const app = useRef<HTMLDivElement>(null);
return <OperatorGate>{(operator) => <VaultApp {...operator} />}</OperatorGate>;
}
function VaultApp({ actor, onLogout }: { actor?: string; onLogout?: () => Promise<void> }) {
const [logoutError, setLogoutError] = useState(false);
const workspaceScroll = useRef<number>(undefined);
const [bigScreen, setBigScreen] = useState(false);
const [mode, setMode] = useState<HUDMode>("scene");
const [searchOpen, setSearchOpen] = useState(false);
const searchTrigger = useRef<HTMLButtonElement>(null);
const searchDestination = useRef<() => HTMLElement | null>(undefined);
const panelOpen = mode !== "scene";
const [orbitId, setOrbitId] = useState<string>();
const [snapshotId, setSnapshotId] = useState<string | null>(null);
@@ -50,18 +58,40 @@ export default function App() {
const reducedMotion = useReducedMotion();
const qc = useQueryClient();
useEffect(() => {
const root = app.current;
if (!root) return;
const syncFullscreen = () => setBigScreen(document.fullscreenElement === root);
root.addEventListener("fullscreenchange", syncFullscreen);
return () => root.removeEventListener("fullscreenchange", syncFullscreen);
}, []);
useLayoutEffect(() => {
function searchKeys(event: KeyboardEvent) {
const composing = event.isComposing || event.keyCode === 229;
if (event.key === "Escape" && searchOpen) {
event.stopPropagation();
if (!composing) {
event.preventDefault();
if (!event.repeat) setSearchOpen(false);
}
} else if (!composing && (event.metaKey || event.ctrlKey) && !event.altKey &&
!event.shiftKey && event.key.toLowerCase() === "k") {
event.preventDefault();
if (!event.repeat) setSearchOpen(true);
}
}
window.addEventListener("keydown", searchKeys, true);
return () => window.removeEventListener("keydown", searchKeys, true);
}, [searchOpen]);
useLayoutEffect(() => {
if (searchOpen) {
searchDestination.current = () => searchTrigger.current;
return;
}
if (!searchDestination.current) return;
const target = searchDestination.current() ?? searchTrigger.current;
searchDestination.current = undefined;
target?.focus();
}, [searchOpen]);
useEffect(() => {
if (!bigScreen || mode !== "scene") return;
const exitOnEscape = (event: KeyboardEvent) => {
if (event.key === "Escape" && !event.defaultPrevented && !document.fullscreenElement) {
if (event.key === "Escape" && !event.defaultPrevented && !event.repeat) {
setBigScreen(false);
}
};
@@ -76,37 +106,32 @@ export default function App() {
}, [bigScreen]);
function toggleBigScreen() {
const root = app.current;
if (bigScreen) {
if (document.fullscreenElement === root) {
void document.exitFullscreen().catch(() => {});
} else {
setBigScreen(false);
}
return;
}
workspaceScroll.current = window.scrollY;
setBigScreen(true);
// The viewport layout also works when the browser declines native fullscreen.
if (document.fullscreenEnabled) void root?.requestFullscreen?.().catch(() => {});
if (!bigScreen) workspaceScroll.current = window.scrollY;
setBigScreen(!bigScreen);
}
const health = useQuery({ queryKey: ["health"], queryFn: fetchHealth, refetchInterval: 15_000, retry: 1 });
const snaps = useQuery({ queryKey: ["snapshots"], queryFn: fetchSnapshots, refetchInterval: 8_000, retry: 1 });
const orbits = useQuery({ queryKey: ["orbits"], queryFn: fetchOrbits, refetchInterval: 8_000, retry: 1 });
const capture = useMutation({
mutationFn: (target: Orbit) => runOrbit(target.id),
mutationFn: async (target: Orbit) => {
if (target.application_id) {
await enqueueCapture(target.application_id);
return null;
}
return runOrbit(target.id);
},
onSettled: () => {
void qc.invalidateQueries({ queryKey: ["orbits"] });
void qc.invalidateQueries({ queryKey: ["snapshots"] });
void qc.invalidateQueries({ queryKey: ["capture-jobs"] });
},
});
const online = health.isSuccess;
const activeId = capture.isPending ? capture.variables.id : undefined;
const sceneOrbits = useMemo(() => (orbits.data ?? []).map((orbit) =>
orbit.id === activeId ? { ...orbit, last_status: orbit.dry_run ? "rehearsing" : "running" } : orbit,
orbit.id === activeId ? { ...orbit, last_status: orbit.application_id ? "queued" : orbit.dry_run ? "rehearsing" : "running" } : orbit,
), [orbits.data, activeId]);
const register = useMemo(() => [...sceneOrbits].sort((a, b) => priority(a) - priority(b)), [sceneOrbits]);
const grouped = useMemo(() => groupSnapshots(orbits.data ?? [], snaps.data ?? []), [orbits.data, snaps.data]);
@@ -114,10 +139,12 @@ export default function App() {
const selected = sceneOrbits.find(({ id }) => id === orbitId);
const history = (selected && grouped.get(selected.id)) ?? [];
const snapshot = snaps.data?.find(({ id }) => id === snapshotId);
const completedOrbitId = capture.isSuccess ? capture.variables.id : undefined;
const arrival = useMemo(() => !reducedMotion && completedOrbitId && capture.data
? { orbitId: completedOrbitId, snapshotId: capture.data }
: undefined, [reducedMotion, completedOrbitId, capture.data]);
const captureGlow = useMotionValue(0);
const captureOrbitId = capture.variables?.id;
const captureEffect = useMemo(() => captureOrbitId && (capture.isError || capture.data)
? { orbitId: captureOrbitId, key: capture.submittedAt, snapshotId: capture.data ?? undefined }
: undefined, [captureOrbitId, capture.submittedAt, capture.isError, capture.data]);
const captureReady = !!captureEffect?.snapshotId && !!snaps.data?.some(({ id }) => id === captureEffect.snapshotId);
const failedCount = sceneOrbits.filter(({ last_status }) => last_status === "failed").length;
const orbitMessage = orbits.isPending ? "Receiving orbit telemetry…" : orbits.isError
@@ -126,8 +153,9 @@ export default function App() {
const snapshotMessage = snaps.isPending ? "Loading snapshot history…" : snaps.isError
? snaps.data ? "Showing last known snapshots." : "Snapshot history unavailable."
: history.length ? undefined : "This orbit has no snapshots yet.";
const captureLabel = capture.isPending ? capture.variables.dry_run ? "Rehearsing" : "Capturing"
const captureLabel = capture.isPending ? capture.variables.application_id ? "Queueing backup for" : capture.variables.dry_run ? "Rehearsing" : "Capturing"
: capture.isError ? "Capture failed for"
: capture.variables?.application_id ? "Backup queued for"
: capture.variables?.dry_run ? "Rehearsal complete for"
: capture.data ? "Snapshot secured from" : "Capture finished for";
const captureNotice = capture.variables && (
@@ -149,6 +177,7 @@ export default function App() {
}
function runCapture(target: Orbit) {
if (target.access === "outpost" && !target.application_id) return;
selectOrbit(target.id);
capture.mutate(target);
}
@@ -161,9 +190,28 @@ export default function App() {
setMode(next);
}
function selectSearchResult(result: SearchResult) {
if (result.kind === "navigation") openConsole(result.id);
else if (result.kind === "snapshot") openSnapshot(result.id);
else if (result.kind === "orbit") {
selectOrbit(result.id);
openConsole("scene");
}
searchDestination.current = () => {
if (result.kind === "snapshot" || (result.kind === "navigation" && result.id !== "scene")) {
return document.querySelector<HTMLElement>(".vault-dialog .dialog-heading h2");
}
if (bigScreen) return document.querySelector<HTMLElement>(".scene-screen-control");
return result.kind === "orbit" ? document.getElementById(`register-${result.id}`)
: document.querySelector<HTMLElement>(".vault-overview h1");
};
setSearchOpen(false);
}
return (
<div ref={app} className={`vault-app${bigScreen ? " big-screen" : ""}`}>
<header className="vault-topbar">
<div className={`vault-app${bigScreen ? " big-screen" : ""}`}>
<header className="vault-topbar" inert={searchOpen}>
<div className="vault-brand">
<svg viewBox="0 0 38 38" width="34" height="34" aria-hidden="true">
<circle cx="19" cy="19" r="10.5" fill="none" stroke="currentColor" opacity=".5" />
@@ -173,26 +221,40 @@ export default function App() {
<div><strong>Tessera</strong><span>Backup control</span></div>
</div>
<HUDRail active={mode === "snapshot" ? "scene" : mode} floating={bigScreen} panelOpen={panelOpen} reducedMotion={reducedMotion} onSelect={openConsole} />
<p className="hub-link" role="status">
<span className={`register-signal signal-${online ? "green" : "grey"}`} />
{online ? "Hub online" : health.isPending ? "Connecting" : "Hub offline"}
</p>
<div className="vault-topbar-tools">
<p className="hub-link" role="status">
<span className={`register-signal signal-${online ? "green" : "grey"}`} />
{online ? "Hub online" : health.isPending ? "Connecting" : "Hub offline"}
</p>
{onLogout && <button type="button" className="console-control" aria-label="Sign out"
onClick={() => void onLogout().catch(() => setLogoutError(true))}>
Sign out <span className="sr-only">{actor}</span>
</button>}
{logoutError && <p role="alert" className="text-sm text-orbit-red">Could not sign out.</p>}
<button type="button" ref={searchTrigger} className="console-control search-trigger"
aria-label="Search" aria-haspopup="dialog" aria-expanded={searchOpen} aria-keyshortcuts="Meta+K Control+K"
onClick={() => setSearchOpen(true)}>
<SearchIcon />
<span>Search</span>
<kbd aria-hidden="true">⌘K / Ctrl+K</kbd>
</button>
</div>
</header>
<main className="vault-main" inert={panelOpen}>
<main className="vault-main" inert={panelOpen || searchOpen}>
<div className="vault-overview">
<div>
<p className="instrument-label overview-label"><span aria-hidden="true">◈</span> Vault / 01</p>
<h1>Orbital vault</h1>
<h1 tabIndex={-1}>Orbital vault</h1>
<p className="overview-copy">Backup jobs and recovery points</p>
</div>
<TelemetryStrip orbitCount={orbits.data?.length} failedCount={failedCount} snapCount={snaps.data?.length} totalBytes={totalBytes} />
<TelemetryStrip orbitCount={orbits.data?.length} failedCount={failedCount} snapCount={snaps.data?.length} totalBytes={totalBytes} bigScreen={bigScreen} reducedMotion={reducedMotion} />
</div>
<div className="vault-workspace">
<VaultScene
orbits={sceneOrbits} selectedOrbitId={selected?.id} recentSnapshots={history.slice(0, 3)}
flowing={play && !reducedMotion} reducedMotion={reducedMotion} arrival={arrival}
flowing={play && !reducedMotion} reducedMotion={reducedMotion} captureEffect={captureEffect} captureGlow={captureGlow} captureReady={captureReady}
bigScreen={bigScreen} onToggleBigScreen={toggleBigScreen}
onToggleFlow={() => setPlay((value) => !value)}
onSelectOrbit={(id) => {
@@ -202,21 +264,23 @@ export default function App() {
onSelectSnapshot={openSnapshot}
/>
<OrbitRegister
orbits={register} selected={selected?.id} message={orbitMessage}
orbits={register} selected={selected?.id} message={orbitMessage} bigScreen={bigScreen}
onSelect={selectOrbit} onManage={() => setMode("orbits")}
/>
<OrbitInspector
orbit={selected} snapshots={history} snapshotMessage={snapshotMessage}
highlightedId={captureEffect?.snapshotId} captureGlow={captureGlow} bigScreen={bigScreen}
onSelectSnapshot={openSnapshot}
capture={selected && (
<>
<button
type="button" className="console-control capture-button"
onClick={() => runCapture(selected)}
disabled={!online || capture.isPending || orbitStatus(selected.last_status).busy}
disabled={!online || capture.isPending || orbitStatus(selected.last_status).busy ||
(selected.access === "outpost" && !selected.application_id)}
>
<span aria-hidden="true">↘</span>
<span>{selected.dry_run ? "Rehearse" : "Capture"} {selected.name}</span>
<span>{selected.application_id ? "Queue backup for" : selected.dry_run ? "Rehearse" : "Capture"} {selected.name}</span>
</button>
{noticeInInspector && mode !== "orbits" && captureNotice}
</>
@@ -231,6 +295,7 @@ export default function App() {
<HUDPanel
open={panelOpen}
inert={searchOpen}
title={panelTitles[mode]}
subtitle={mode === "reconstitute" ? "Review the destination before starting the restore." : undefined}
onClose={() => setMode("scene")}
@@ -239,20 +304,17 @@ export default function App() {
{mode === "orbits" && (
<SpringPane key="orbits">
<QueryGate query={orbits}>
{() => <OrbitsView orbits={sceneOrbits} onRun={runCapture} captureDisabled={!online || capture.isPending} notice={captureNotice} />}
{() => <OrbitsView snapshots={snaps.isSuccess ? snaps.data : undefined} orbits={sceneOrbits} onRun={runCapture} onOpenSnapshot={openSnapshot} captureDisabled={!online || capture.isPending} notice={captureNotice} />}
</QueryGate>
</SpringPane>
)}
{mode === "wormhole" && (
<SpringPane key="wormhole"><WormholeView pairing={pairing} onPaired={setPairing} /></SpringPane>
)}
{mode === "decay" && (
<SpringPane key="decay"><DecayView orbits={sceneOrbits} /></SpringPane>
)}
{mode === "snapshot" && (
<SpringPane key="snapshot">
{snapshot
? <SnapshotSheet snap={snapshot} onReconstitute={() => openConsole("reconstitute", snapshot.id)} />
? <SnapshotSheet snap={snapshot} onDeleted={() => openConsole("scene")} onReconstitute={() => openConsole("reconstitute", snapshot.id)} />
: <EmptyState title="Snapshot unavailable" body="It may have expired under the retention policy." />}
</SpringPane>
)}
@@ -261,7 +323,7 @@ export default function App() {
{restoreTarget && (snaps.data?.length || restoreBusy ? (
<ReconstituteWizard
key={restoreTarget.id ?? "manual"}
snapshots={snaps.data ?? []} selected={restoreTarget.id}
snapshots={snaps.data ?? []} selected={restoreTarget.id} scopedExport={!!actor}
onStart={startReconstitute} onPoll={pollReconstitute} onAbort={abortReconstitute} onBusyChange={setRestoreBusy}
/>
) : (
@@ -271,6 +333,14 @@ export default function App() {
))}
</SpringPane>
</HUDPanel>
<VaultSearch
open={searchOpen} reducedMotion={reducedMotion}
orbits={orbits.data} snapshots={snaps.data}
orbitStatus={orbits.isPending ? "Loading orbits…" : orbits.isError
? orbits.data ? "Showing last known orbits." : "Orbits unavailable." : undefined}
snapshotStatus={snaps.isPending || snaps.isError ? snapshotMessage : undefined}
onClose={() => setSearchOpen(false)} onSelect={selectSearchResult}
/>
</div>
);
}