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,17 +1,18 @@
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
import { animate, spring, useMotionValue } from "motion/react";
import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { animate, motion, spring, useMotionValue, useTransform, type MotionStyle, type MotionValue } from "motion/react";
import type { Orbit, Snapshot } from "../../api";
import { orbitStatus } from "../../lib/format";
import { LABEL_HEIGHT, placeLabels, type Rect } from "../../lib/galaxyLabelLayout";
import {
assignOrbitSlots, moonPoses, orbitCapacity, orbitPose, orbitRadii, ORBIT_TILT,
assignOrbitSlots, CAPTURE_HIGHLIGHT_START, capturePhases, moonPoses, orbitCapacity, orbitPose, orbitRadii, ORBIT_TILT,
SCENE_HEIGHT, SCENE_WIDTH, spiralPoint, type Vec2,
} from "../../lib/galaxyLayout";
import { useGalaxyMotion } from "../../hooks/useGalaxyMotion";
import { uiSpring } from "../../lib/motion";
import { useScreenTransition } from "../../hooks/useScreenTransition";
import { ambientSpring, gentleSpring, uiSpring } from "../../lib/motion";
import { VaultCore } from "./VaultCore";
export type CaptureArrival = { orbitId: string; snapshotId: string };
export type CaptureEffect = { orbitId: string; key: number; snapshotId?: string };
type Props = {
orbits: Orbit[];
@@ -19,7 +20,10 @@ type Props = {
recentSnapshots: Snapshot[];
flowing: boolean;
reducedMotion: boolean;
arrival?: CaptureArrival;
bigScreen: boolean;
captureEffect?: CaptureEffect;
captureGlow: MotionValue<number>;
captureReady: boolean;
onSelectOrbit: (id: string) => void;
onSelectSnapshot: (id: string) => void;
};
@@ -28,107 +32,198 @@ const HALF_WIDTH = SCENE_WIDTH / 2;
const HALF_HEIGHT = SCENE_HEIGHT / 2;
const labelFont = "500 11px ui-monospace, monospace";
const MAX_LABELS = 12;
const clamp = (value: number) => Math.max(0, Math.min(1, value));
const ACCRETION_SECONDS = 6.4;
const TRAIL_WIDTHS = [0.8, 1.4, 2.3];
export function BlackholeGalaxy({
orbits, selectedOrbitId, recentSnapshots, flowing, reducedMotion, arrival, onSelectOrbit, onSelectSnapshot,
orbits, selectedOrbitId, recentSnapshots, flowing, reducedMotion, bigScreen, captureEffect, captureGlow, captureReady, onSelectOrbit, onSelectSnapshot,
}: Props) {
const frame = useRef<HTMLDivElement>(null);
const bodyNodes = useRef(new Map<SVGGElement, { id: string; far: boolean }>());
const bodyNodes = useRef(new Map<SVGGElement, { id: string; index: number }>());
const slotsBefore = useRef<ReturnType<typeof assignOrbitSlots>>(undefined);
const elapsed = useRef(0);
const entrance = useRef(0);
const core = useRef<SVGGElement>(null);
const meteor = useRef<{ id: string; time: number; source: Vec2; progress: ReturnType<typeof spring> }>(undefined);
const capture = useRef<{ event: CaptureEffect; time: number; source: Vec2; progress: ReturnType<typeof spring>; done: boolean; waiting: boolean }>(undefined);
const skippedCapture = useRef<CaptureEffect>(undefined);
const sourceFlare = useRef<SVGCircleElement>(null);
const busyAngle = useRef(0);
const diskTime = useRef(0);
const hasRunning = orbits.some(orbit => orbitStatus(orbit.last_status).busy);
const trailId = useId();
const trail = useRef<SVGPathElement>(null);
const trailSegments = useRef<(SVGUseElement | null)[]>([]);
const head = useRef<SVGCircleElement>(null);
const effect = useRef<SVGGElement>(null);
const [width, setWidth] = useState(0);
const [coasting, setCoasting] = useState(false);
const rate = useMotionValue(flowing && !reducedMotion ? 1 : 0);
const moving = !reducedMotion && (flowing || coasting);
const [lockedPhase, setLockedPhase] = useState(0);
const reveal = useMotionValue(flowing ? 0 : 1);
const revealStyle = useTransform(reveal, clamp);
const revealVariables: MotionStyle & { "--lock-reveal": MotionValue<number> } = { "--lock-reveal": revealStyle };
const selectionX = useMotionValue(0);
const selectionY = useMotionValue(0);
const selectionPlaced = useRef(false);
useLayoutEffect(() => () => rate.stop(), [rate]);
useLayoutEffect(() => () => {
rate.stop();
reveal.stop();
selectionX.stop();
selectionY.stop();
}, [rate, reveal, selectionX, selectionY]);
useLayoutEffect(() => {
if (reducedMotion) {
rate.jump(0);
reveal.jump(1);
setLockedPhase(elapsed.current);
setCoasting(false);
return;
}
if (flowing) animate(reveal, 0, gentleSpring);
const target = flowing ? 1 : 0;
if (rate.get() === target && !rate.isAnimating()) return;
setCoasting(!flowing);
animate(rate, target, { ...uiSpring, onComplete: () => setCoasting(false) });
}, [flowing, rate, reducedMotion]);
animate(rate, target, {
...uiSpring,
restDelta: 0.025,
restSpeed: 0.25,
onComplete: () => {
if (!flowing) {
setLockedPhase(elapsed.current);
animate(reveal, 1, gentleSpring);
}
setCoasting(false);
},
});
}, [flowing, rate, reducedMotion, reveal]);
const slots = useMemo(
() => assignOrbitSlots(orbits.map(({ id }) => id), slotsBefore.current, selectedOrbitId),
[orbits, selectedOrbitId],
);
useLayoutEffect(() => { slotsBefore.current = slots; }, [slots]);
useLayoutEffect(() => {
const element = frame.current;
if (!element) return;
const measure = () => setWidth(element.clientWidth);
const observer = new ResizeObserver(measure);
observer.observe(element);
measure();
return () => observer.disconnect();
}, []);
useScreenTransition(frame, bigScreen, reducedMotion, setWidth);
const draw = useCallback((delta: number) => {
if (moving && delta > 0) {
elapsed.current += delta * Math.max(0, rate.get());
const phase = (elapsed.current % ACCRETION_SECONDS) / ACCRETION_SECONDS;
const selectedSlot = selectedOrbitId ? slots.get(selectedOrbitId) : undefined;
const selectedPosition = selectedSlot && orbitPose(selectedSlot, lockedPhase);
const selectedX = selectedPosition?.x;
const selectedY = selectedPosition?.y;
useLayoutEffect(() => {
if (selectedX === undefined || selectedY === undefined) {
selectionPlaced.current = false;
} else if (!selectionPlaced.current || reducedMotion) {
selectionX.jump(selectedX);
selectionY.jump(selectedY);
selectionPlaced.current = true;
} else if (!moving) {
animate(selectionX, selectedX, uiSpring);
animate(selectionY, selectedY, uiSpring);
}
}, [moving, reducedMotion, selectedX, selectedY, selectionX, selectionY]);
useGalaxyMotion((delta) => {
const speed = moving ? Math.max(0, rate.get()) : 0;
elapsed.current += delta * speed;
if (hasRunning && !reducedMotion && delta > 0) {
busyAngle.current = (busyAngle.current + 105 * delta) % 360;
frame.current?.style.setProperty("--busy-angle", `${busyAngle.current}deg`);
}
const wasEntering = entrance.current < 0.6;
if (slots.size) entrance.current = reducedMotion ? 0.6 : Math.min(0.6, entrance.current + delta);
const entering = !reducedMotion && slots.size > 0 && entrance.current < 0.6;
if (!delta || moving || (!reducedMotion && wasEntering)) {
for (const [node, { id, index }] of bodyNodes.current) {
const slot = slots.get(id)!;
const { x, y } = orbitPose(slot, elapsed.current);
const depth = y / (slot.radius * ORBIT_TILT);
const appear = entering ? clamp((entrance.current - Math.min(index * 0.013, 0.33)) / 0.23) : 1;
node.setAttribute("transform", `translate(${x} ${y}) scale(${0.95 + depth * 0.08})`);
node.setAttribute("opacity", String(appear * (0.88 + depth * 0.12)));
}
}
if (moving && selectedSlot) {
const point = orbitPose(selectedSlot, elapsed.current);
selectionX.jump(point.x);
selectionY.jump(point.y);
}
if (reducedMotion) skippedCapture.current = captureEffect;
const event = captureEffect === skippedCapture.current ? undefined : captureEffect;
const slot = event && slots.get(event.orbitId);
if (event && slot && capture.current?.event !== event) {
captureGlow.set(0);
effect.current?.setAttribute("opacity", "0");
const source = orbitPose(slot, elapsed.current);
capture.current = {
event, source, time: 0, done: false, waiting: false,
progress: spring({ ...ambientSpring, keyframes: [0, 1], restDelta: 0.002 }),
};
if (event.snapshotId) {
const points = Array.from({ length: 36 }, (_, i) => spiralPoint(source, i / 35));
trail.current?.setAttribute("d", points.map(({ x, y }, i) => `${i ? "L" : "M"} ${x} ${y}`).join(" "));
}
}
const current = capture.current;
let absorption = 0;
let capturing = false;
if (event && current?.event === event && !current.done) {
// The impact can finish while the snapshot list is still refreshing.
if (!current.waiting || captureReady) current.time += delta * 1000;
const { value, done } = current.progress.next(current.time);
const success = !!event.snapshotId;
current.waiting = success && !captureReady && value >= CAPTURE_HIGHLIGHT_START;
const progress = current.waiting ? CAPTURE_HIGHLIGHT_START : done ? 1 : value;
const phases = capturePhases(progress);
current.done = done && !current.waiting;
const source = slot ? orbitPose(slot, elapsed.current) : current.source;
const pulse = success ? phases.flare : phases.failure;
sourceFlare.current?.setAttribute("cx", String(source.x));
sourceFlare.current?.setAttribute("cy", String(source.y));
sourceFlare.current?.setAttribute("r", String(7 + 13 * clamp(value)));
sourceFlare.current?.setAttribute("stroke", success ? "#ffd3a5" : "#f59183");
sourceFlare.current?.setAttribute("opacity", String(0.75 * pulse));
if (success) {
const { x, y } = spiralPoint(current.source, phases.flight);
head.current?.setAttribute("cx", String(x));
head.current?.setAttribute("cy", String(y));
head.current?.setAttribute("r", String(3.5 * (1 - phases.flight ** 4)));
const segmentLength = Math.min(phases.flight, 0.19) * (1 - phases.flight ** 6) / TRAIL_WIDTHS.length;
trailSegments.current.forEach((segment, index) => {
segment?.setAttribute("stroke-dasharray", `${segmentLength} 1`);
segment?.setAttribute("stroke-dashoffset", String((TRAIL_WIDTHS.length - index) * segmentLength - phases.flight));
});
effect.current?.setAttribute("opacity", String(clamp(phases.flight * 14) * (1 - phases.flight ** 8)));
absorption = phases.absorption;
captureGlow.set(phases.highlight);
}
capturing = !current.done && !current.waiting;
} else {
sourceFlare.current?.setAttribute("opacity", "0");
effect.current?.setAttribute("opacity", "0");
captureGlow.set(0);
}
if (delta > 0 && (speed || absorption)) {
diskTime.current += delta * (speed + 3.2 * absorption);
const phase = (diskTime.current % ACCRETION_SECONDS) / ACCRETION_SECONDS;
core.current?.style.setProperty("--accretion-offset", String(-100 * phase));
}
for (const [node, { id, far }] of bodyNodes.current) {
const slot = slots.get(id);
if (!slot) continue;
const { x, y } = orbitPose(slot, elapsed.current);
const visible = far === (y < 0);
const display = visible ? "" : "none";
if (node.style.display !== display) node.style.display = display;
if (!visible) continue;
node.setAttribute("transform", `translate(${x} ${y})`);
const coreStyle = core.current?.style;
if (coreStyle && (absorption || coreStyle.getPropertyValue("--capture-absorption") !== "0")) {
coreStyle.setProperty("--capture-absorption", String(absorption));
}
if (!arrival || reducedMotion) {
effect.current?.setAttribute("opacity", "0");
return moving;
}
const slot = slots.get(arrival.orbitId);
if (meteor.current?.id !== arrival.snapshotId && slot) {
const source = orbitPose(slot, elapsed.current);
meteor.current = {
id: arrival.snapshotId,
time: 0,
source,
progress: spring({ ...uiSpring, stiffness: 36, damping: 12, keyframes: [0, 1], restDelta: 0.002 }),
};
const points = Array.from({ length: 36 }, (_, i) => spiralPoint(source, i / 35));
trail.current?.setAttribute("d", points.map(({ x, y }, i) => `${i ? "L" : "M"} ${x} ${y}`).join(" "));
}
const current = meteor.current;
if (!current || current.id !== arrival.snapshotId) return moving;
current.time += delta * 1000;
const { value: progress, done } = current.progress.next(current.time);
const { x, y } = spiralPoint(current.source, progress);
head.current?.setAttribute("cx", String(x));
head.current?.setAttribute("cy", String(y));
trail.current?.setAttribute("stroke-dashoffset", String(0.2 - progress));
effect.current?.setAttribute("opacity", String(progress >= 1 ? 0 : Math.min(1, (1 - progress) * 6)));
return moving || !done;
}, [arrival, moving, rate, reducedMotion, slots]);
useGalaxyMotion(moving || (!reducedMotion && !!arrival), draw);
return moving || entering || capturing || (hasRunning && !reducedMotion);
});
const scale = width / SCENE_WIDTH;
const height = SCENE_HEIGHT * scale;
const hitRadius = Math.max(12, scale ? 12 / scale : 12);
const selectedSlot = selectedOrbitId ? slots.get(selectedOrbitId) : undefined;
const selectedPosition = !moving && selectedSlot ? orbitPose(selectedSlot, elapsed.current) : undefined;
const positions = !moving ? [...slots.values()].map((slot) => orbitPose(slot, elapsed.current)) : [];
const positions = [...slots.values()].map((slot) => orbitPose(slot, lockedPhase));
const moons = selectedPosition
? moonPoses(selectedPosition, recentSnapshots.length, 2 * hitRadius + 3, positions)
: [];
@@ -146,87 +241,100 @@ export function BlackholeGalaxy({
};
let labels: ReturnType<typeof placeLabels> = [];
if (!moving && width && labelCandidates.length) {
if (width && labelCandidates.length) {
const measure = document.createElement("canvas").getContext("2d");
if (measure) measure.font = labelFont;
const markers = positions.map((point) => box(point, 7));
const core = box({ x: 0, y: 0 }, 65 * scale);
labels = placeLabels(labelCandidates.map(({ id, name }) => {
const point = screen(orbitPose(slots.get(id)!, elapsed.current));
const point = screen(orbitPose(slots.get(id)!, lockedPhase));
return { id, ...point, width: Math.min(146, Math.ceil(measure?.measureText(name).width ?? name.length * 7) + 16) };
}), width, height, [core, ...markers, ...moons.map((moon) => box(moon, 12))]);
}), width, height, [core, ...markers, ...moons.map((moon) => box(moon, 12))], selectedOrbitId);
}
const focusLabel = labels.find(({ id }) => id === selectedOrbitId);
const renderOrbits = (far: boolean) => visible.map((orbit) => {
const point = orbitPose(slots.get(orbit.id)!, elapsed.current);
// Each marker switches layers when it crosses the orbital plane.
const renderOrbits = visible.map((orbit, index) => {
const selected = orbit.id === selectedOrbitId;
const status = orbitStatus(orbit.last_status);
return (
<g
<motion.g
key={orbit.id}
ref={(node) => {
if (!node) return;
bodyNodes.current.set(node, { id: orbit.id, far });
bodyNodes.current.set(node, { id: orbit.id, index });
return () => { bodyNodes.current.delete(node); };
}}
transform={`translate(${point.x} ${point.y})`}
style={{ display: far === (point.y < 0) ? "" : "none" }}
initial={false}
animate="idle"
whileHover="hover"
data-orbit-marker={orbit.id}
className={`orbit-marker orbit-marker--${status.tone}${selected ? " orbit-marker--selected" : ""}`}
>
<circle className="orbit-halo" r={selected ? 16 : 10} />
<motion.circle className="orbit-halo" r={selected ? 16 : 10}
variants={{ idle: { opacity: 0.08 }, hover: { opacity: 0.3 } }} />
{status.tone === "red" && <path className="orbit-alert" d="M0 -8 8 0 0 8 -8 0Z" />}
{status.busy && <circle className="orbit-busy" r="8.5" />}
{selected && <circle className="orbit-selection" r="13" />}
<circle className="orbit-light" r="4.6" />
<circle className="orbit-hit" r={hitRadius} onClick={() => onSelectOrbit(orbit.id)} />
</g>
</motion.g>
);
});
return (
<div ref={frame} className="galaxy-frame" data-flowing={flowing}>
<motion.div ref={frame} className="galaxy-frame" data-flowing={flowing} style={revealVariables}>
<svg viewBox={`${-HALF_WIDTH} ${-HALF_HEIGHT} ${SCENE_WIDTH} ${SCENE_HEIGHT}`} aria-hidden="true">
<g className="orbit-tracks" pointerEvents="none">
{orbitRadii.map((radius) => (
<ellipse key={radius} rx={radius} ry={radius * ORBIT_TILT} className={selectedSlot?.radius === radius ? "is-selected" : ""} />
))}
</g>
<g className="orbit-layer orbit-layer--far">{renderOrbits(true)}</g>
<VaultCore ref={core} />
<g className="orbit-layer orbit-layer--near">{renderOrbits(false)}</g>
{selectedPosition && moons.map(({ x, y }, index) => {
const snapshot = recentSnapshots[index];
return (
<g key={snapshot.id} data-snapshot-marker={snapshot.id} className="snapshot-marker">
<line x1={selectedPosition.x} y1={selectedPosition.y} x2={x} y2={y} />
<rect className="snapshot-light" x={x - 4} y={y - 4} width="8" height="8" rx="1" transform={`rotate(45 ${x} ${y})`} />
<circle className="orbit-hit" cx={x} cy={y} r={hitRadius} onClick={() => onSelectSnapshot(snapshot.id)} />
</g>
);
})}
{selectedPosition && focusLabel && (
<line className="focus-leader"
x1={selectedPosition.x} y1={selectedPosition.y}
x2={(focusLabel.x + focusLabel.width / 2) / scale - HALF_WIDTH}
y2={(focusLabel.y + LABEL_HEIGHT / 2) / scale - HALF_HEIGHT}
/>
)}
<g className="orbit-layer">{renderOrbits}</g>
{selectedPosition && <motion.circle className="orbit-selection" cx={selectionX} cy={selectionY} r="13" />}
<g className="lock-details" pointerEvents={moving ? "none" : undefined}>
{selectedPosition && moons.map(({ x, y }, index) => {
const snapshot = recentSnapshots[index];
return (
<g key={index} data-snapshot-marker={snapshot.id} className="snapshot-marker">
<motion.line x1={selectionX} y1={selectionY} initial={false} animate={{ x2: x, y2: y }} />
<motion.g initial={false} animate={{ x, y }}>
<rect className="snapshot-light" x="-4" y="-4" width="8" height="8" rx="1" transform="rotate(45)" />
{snapshot.id === captureEffect?.snapshotId && (
<motion.circle className="snapshot-flash" r="9" style={{ opacity: captureGlow }} />
)}
<circle className="orbit-hit" r={hitRadius} onClick={() => onSelectSnapshot(snapshot.id)} />
</motion.g>
</g>
);
})}
{selectedPosition && focusLabel && (
<motion.line className="focus-leader"
x1={selectionX} y1={selectionY} initial={false}
animate={{
x2: (focusLabel.x + focusLabel.width / 2) / scale - HALF_WIDTH,
y2: (focusLabel.y + LABEL_HEIGHT / 2) / scale - HALF_HEIGHT,
}}
/>
)}
</g>
<circle ref={sourceFlare} className="capture-flare" opacity="0" pointerEvents="none" fill="none" />
<g ref={effect} className="capture-arrival" opacity="0" pointerEvents="none">
<path ref={trail} pathLength="1" strokeDasharray=".2 1" fill="none" />
<defs><path id={trailId} ref={trail} pathLength="1" /></defs>
{TRAIL_WIDTHS.map((strokeWidth, index) => (
<use key={strokeWidth} ref={node => { trailSegments.current[index] = node; }}
href={`#${trailId}`} fill="none" strokeWidth={strokeWidth} opacity={0.35 + index * 0.3} />
))}
<circle ref={head} r="3.5" />
</g>
</svg>
<div aria-hidden="true" className="scene-labels" style={{ font: labelFont }}>
{labels.map(({ id, x, y, width: labelWidth }) => (
<span key={id} style={{ left: x, top: y, width: labelWidth }} className={id === selectedOrbitId ? "is-selected" : ""}>
{labels.map(({ id, x, y, width: labelWidth }, index) => (
<span key={id} style={{ left: `${100 * x / width}%`, top: `${100 * y / height}%`, width: labelWidth, opacity: reducedMotion ? 1 : `clamp(0, (var(--lock-reveal) - ${index * 0.035}) * 1.8, 1)` }} className={id === selectedOrbitId ? "is-selected" : ""}>
{labelCandidates.find((orbit) => orbit.id === id)?.name}
</span>
))}
</div>
{orbits.length >= orbitCapacity && <p className="scene-density">Select an orbit in the list to inspect it</p>}
</div>
</motion.div>
);
}