From fba4a1e628ca7cd566bf1b0aeeaed6a82e764c1c Mon Sep 17 00:00:00 2001 From: Adnan Zahir Date: Mon, 9 Nov 2026 22:01:14 +0700 Subject: [PATCH] feat: rebuild the orbital vault as an operational map --- docs/UI.md | 51 +- web/package.json | 2 + web/scripts/capture-galaxy.mjs | 38 +- web/scripts/galaxy.test.mjs | 64 +++ web/src/App.tsx | 370 +++++++------- web/src/api.ts | 21 +- web/src/components/hud/DiegeticHUD.tsx | 189 +++++--- web/src/components/hud/HUDPanel.tsx | 122 ++--- web/src/components/hud/HUDRail.tsx | 71 +-- web/src/components/layout/NavBar.tsx | 55 --- web/src/components/orbits/OrbitsView.tsx | 41 +- .../reconstitute/ReconstituteWizard.tsx | 90 +++- web/src/components/scene/BlackholeGalaxy.tsx | 452 +++++++----------- web/src/components/scene/SpaceBackdrop.tsx | 84 +--- web/src/components/scene/Starfield.tsx | 46 -- web/src/components/scene/VaultCore.tsx | 73 +++ web/src/components/scene/VaultScene.tsx | 76 +-- web/src/components/vault/SnapshotSheet.tsx | 6 +- web/src/components/vault/VaultRing.tsx | 126 ----- web/src/hooks/useGalaxyMotion.ts | 53 +- web/src/hooks/useReducedMotion.ts | 12 + web/src/index.css | 315 ++++++++++-- web/src/lib/format.ts | 12 + web/src/lib/galaxyLabelLayout.ts | 161 ++----- web/src/lib/galaxyLayout.ts | 145 +++--- 25 files changed, 1342 insertions(+), 1333 deletions(-) create mode 100644 web/scripts/galaxy.test.mjs delete mode 100644 web/src/components/layout/NavBar.tsx delete mode 100644 web/src/components/scene/Starfield.tsx create mode 100644 web/src/components/scene/VaultCore.tsx delete mode 100644 web/src/components/vault/VaultRing.tsx create mode 100644 web/src/hooks/useReducedMotion.ts diff --git a/docs/UI.md b/docs/UI.md index 8ab3759..adc72bf 100644 --- a/docs/UI.md +++ b/docs/UI.md @@ -1,32 +1,37 @@ -# Tessera canvas — galaxy vault (Space Engine mode) +# Tessera orbital vault -Diegetic **cockpit HUD** over a persistent **galaxy viewport**. The vault is a **black hole** at center; each **orbit** is a **star** on an elliptical path; **snapshots** are **moons** around that star (when locked). +The persistent viewport maps backup jobs and recovery points. The black hole represents the vault. Stars represent orbits, and moons represent the latest snapshots of the selected orbit. -## Viewport modes +## Viewport and consoles -| Mode | Behavior | -|------|----------| -| **Flowing** (default) | Stars orbit the singularity; accretion disk spins; moons hidden; targets not clickable | -| **Locked** | Click **black hole** once — bodies ease into spaced slots and **stop**; star opens orbit console; moon opens snapshot tile | +- **Flowing** animates the projected orbit paths. **Locked** keeps bodies in place and prioritizes labels for the selected, failed, and running orbits. Pause or resume from the map toolbar. Selecting an orbit locks the map. Reduced motion starts in Locked mode. +- Select a star or use the orbit register. The register prioritizes failed and active jobs and supports the up/down arrow keys. The inspector includes the capture action and full snapshot history. +- The first three recovery points of the selected orbit appear as moons when the map has room. Select a moon or history entry to review the snapshot and start a restore. Escape closes the console. Restore countdown and polling continue if the console closes. +- Hub connectivity is separate from backup health. Capture targets the named orbit. An incoming meteor represents a confirmed new snapshot. Failures and rehearsals show text feedback. +- The map shows up to 55 overview orbits and reserves one slot for inspecting an orbit beyond that limit. The register provides access to every orbit. On narrow screens the map, register, and inspector stack vertically. -Click the **black hole** again to resume flow. HUD line under telemetry: green “flowing” / amber “locked”. +## Data and rendering -## HUD rail +- The map preserves each orbit's assigned slot across polling updates. Layout and snapshot grouping live in `web/src/lib/galaxyLayout.ts`. +- Snapshot summaries carry `orbit_id`. When connected to an older hub, the UI groups by name only if the name is unique. +- Successful capture preserves HTTP 204 and supplies `X-Tessera-Snapshot-Id` when it retained a new snapshot. Automatic decay applies to that orbit's history. +- The scene uses SVG with static artwork and one animation clock. The clock pauses when the tab is hidden. Labels are laid out in screen coordinates. -Unchanged — ◎ ⟳ ◉ ◇ ↩ consoles; **Esc** dismisses. +## Local verification -## Data +Build the web UI before building the hub, which embeds the generated assets. -- Stars: `GET /api/v1/orbits` (status → star color) -- Moons: `GET /api/v1/snapshots` grouped by `orbit_name`, max 6 per star - -## Demo - -`TESSERA_DATA_DIR=... tessera seed-demo --force` for 12+ stars. - -## Build - -```bash -cd web && npm run build -cargo build --release -p tessera-hub +```sh +cd web +npm ci +npm run typecheck +npm test +npm run build +cd .. +cargo test --workspace --locked +cargo build --locked -p tessera-hub ``` + +To preview a populated scene, start the hub with `TESSERA_SEED_DEMO=1` and a fresh temporary `TESSERA_DATA_DIR`. Open the vault and select an orbit with snapshots to review the locked layout. + +The optional `web/scripts/capture-galaxy.mjs` screenshot helper uses a local Playwright and Chromium installation. It captures Flowing and Locked into the system temporary directory by default. diff --git a/web/package.json b/web/package.json index fb2b15b..736bcc5 100644 --- a/web/package.json +++ b/web/package.json @@ -6,6 +6,8 @@ "scripts": { "dev": "vite", "build": "vite build", + "test": "node --experimental-strip-types --test scripts/galaxy.test.mjs", + "typecheck": "tsc --noEmit", "preview": "vite preview" }, "dependencies": { diff --git a/web/scripts/capture-galaxy.mjs b/web/scripts/capture-galaxy.mjs index 76304d0..b0298fb 100644 --- a/web/scripts/capture-galaxy.mjs +++ b/web/scripts/capture-galaxy.mjs @@ -1,21 +1,27 @@ +import { tmpdir } from "node:os"; +import { join } from "node:path"; import { chromium } from "playwright"; const base = process.env.TESSERA_URL ?? "http://127.0.0.1:8787/"; -const outFlow = - process.env.FLOW_SHOT ?? "/cursor/stores/self/media/tessera-galaxy-flow-polish.png"; -const outLock = - process.env.LOCK_SHOT ?? "/cursor/stores/self/media/tessera-galaxy-locked-polish.png"; +const outFlow = process.env.FLOW_SHOT ?? join(tmpdir(), "tessera-galaxy-flowing.png"); +const outLock = process.env.LOCK_SHOT ?? join(tmpdir(), "tessera-galaxy-locked.png"); const browser = await chromium.launch({ headless: true }); -const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }); -await page.goto(base, { waitUntil: "networkidle", timeout: 30_000 }); -await page.waitForTimeout(2500); -await page.screenshot({ path: outFlow, fullPage: false }); -const svg = page.locator('[aria-label="Galaxy vault viewport"]'); -const box = await svg.boundingBox(); -if (!box) throw new Error("galaxy svg not found"); -await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2); -await page.waitForTimeout(1400); -await page.screenshot({ path: outLock, fullPage: false }); -await browser.close(); -console.log("saved", outFlow, outLock); +try { + const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }); + const [orbitResponse] = await Promise.all([ + page.waitForResponse((response) => new URL(response.url()).pathname === "/api/v1/orbits" && response.ok()), + page.goto(base), + ]); + await page.getByText("Hub online", { exact: true }).waitFor(); + await page.screenshot({ path: outFlow }); + + const firstOrbit = page.locator(".register-row").first(); + if ((await orbitResponse.json()).length) await firstOrbit.click(); + else await page.getByRole("button", { name: "Pause motion" }).click(); + await page.getByRole("button", { name: "Resume motion" }).waitFor(); + await page.screenshot({ path: outLock }); + console.log("saved", outFlow, outLock); +} finally { + await browser.close(); +} diff --git a/web/scripts/galaxy.test.mjs b/web/scripts/galaxy.test.mjs new file mode 100644 index 0000000..8ce1a80 --- /dev/null +++ b/web/scripts/galaxy.test.mjs @@ -0,0 +1,64 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { assignOrbitSlots, orbitPose, groupSnapshots, moonPoses } from "../src/lib/galaxyLayout.ts"; +import { placeLabels } from "../src/lib/galaxyLabelLayout.ts"; + +test("slot identities survive reordering, insertion and removal", () => { + const first = assignOrbitSlots(["a", "b", "c"]); + const next = assignOrbitSlots(["new", "c", "a"], first); + assert.equal(next.get("a"), first.get("a")); + assert.equal(next.get("c"), first.get("c")); + assert.equal(next.get("new"), first.get("b")); +}); + +test("overview fits 50 distinct orbits and promotes a selected orbit beyond capacity", () => { + const ids = Array.from({ length: 75 }, (_, i) => String(i)); + const slots = assignOrbitSlots(ids); + assert.ok(slots.size >= 50); + assert.equal(new Set(slots.values()).size, slots.size); + const promoted = assignOrbitSlots(ids, slots, "74"); + assert.ok(promoted.has("74")); + assert.equal(promoted.get("0"), slots.get("0")); + for (const slot of promoted.values()) { + const point = orbitPose(slot, 7); + assert.ok(Math.abs(point.x) < 320 && Math.abs(point.y) < 220); + } +}); + +test("snapshot ownership uses IDs and only falls back to an unambiguous name", () => { + const orbits = [ + { id: "a", name: "daily" }, { id: "b", name: "daily" }, { id: "c", name: "archive" }, + ]; + const snapshot = (id, orbit_name, taken_at, orbit_id) => + ({ id, orbit_name, taken_at, orbit_id, size_bytes: 1 }); + const groups = groupSnapshots(orbits, [ + snapshot("old", "renamed", "2026-10-01", "a"), + snapshot("ambiguous", "daily", "2026-10-03"), + snapshot("new", "daily", "2026-10-03", "a"), + snapshot("legacy", "archive", "2026-10-02"), + snapshot("orphan", "archive", "2026-10-02", "deleted"), + ]); + assert.deepEqual(groups.get("a").map((s) => s.id), ["new", "old"]); + assert.equal(groups.has("b"), false); + assert.deepEqual(groups.get("c").map((s) => s.id), ["legacy"]); +}); + +test("moon fan opens away from the vault and separates touch targets", () => { + const moons = moonPoses({ x: 150, y: 0 }, 3, 55); + assert.equal(moons.length, 3); + assert.ok(moons.every((p) => p.x > 150)); + assert.ok(Math.hypot(moons[0].x - moons[1].x, moons[0].y - moons[1].y) >= 55); + const shifted = moonPoses({ x: 150, y: 0 }, 3, 55, moons); + assert.equal(shifted.length, 3); + assert.ok(shifted.every((moon) => moons.every((star) => Math.hypot(star.x - moon.x, star.y - moon.y) >= 14))); +}); + +test("labels respect screen bounds and preserve priority in a crowded scene", () => { + const candidates = [ + { id: "focused", x: 70, y: 60, width: 72 }, + { id: "other", x: 70, y: 60, width: 200 }, + ]; + const labels = placeLabels(candidates, 140, 120, []); + assert.deepEqual(labels.map((l) => l.id), ["focused"]); + assert.ok(labels[0].x >= 0 && labels[0].x + 72 <= 140); +}); diff --git a/web/src/App.tsx b/web/src/App.tsx index 8f2d163..620f458 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,209 +1,215 @@ -import { useEffect, useMemo, useState } from "react"; +import { useMemo, useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { - abortReconstitute, - fetchHealth, - fetchOrbits, - fetchSnapshots, - pollReconstitute, - runOrbit, - startReconstitute, + abortReconstitute, fetchHealth, fetchOrbits, fetchSnapshots, pollReconstitute, + runOrbit, startReconstitute, type Orbit, } from "./api"; -import { vaultStatusFromOrbits } from "./lib/format"; 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 { OrbitsView } from "./components/orbits/OrbitsView"; import { WormholeView } from "./components/outposts/WormholeView"; import { ReconstituteWizard } from "./components/reconstitute/ReconstituteWizard"; import { VaultScene } from "./components/scene/VaultScene"; -import { SnapshotSheet } from "./components/vault/SnapshotSheet"; -import { - CockpitFrame, - SnapshotsMiniList, - TelemetryStrip, -} from "./components/hud/DiegeticHUD"; -import { HUDPanel, SceneAction } from "./components/hud/HUDPanel"; -import { HUDRail, type HUDMode } from "./components/hud/HUDRail"; import { EmptyState } from "./components/ui/EmptyState"; import { QueryGate } from "./components/ui/QueryGate"; +import { SnapshotSheet } from "./components/vault/SnapshotSheet"; +import { useReducedMotion } from "./hooks/useReducedMotion"; +import { orbitStatus } from "./lib/format"; +import { groupSnapshots } from "./lib/galaxyLayout"; + +const panelTitles: Record = { + scene: "Vault", + orbits: "Orbit management", + wormhole: "Wormhole uplink", + decay: "Snapshot retention", + reconstitute: "Restore snapshot", + snapshot: "Snapshot detail", +}; + +function priority(orbit: Orbit) { + if (orbit.last_status === "failed") return 0; + return orbitStatus(orbit.last_status).busy ? 1 : 2; +} + export default function App() { const [mode, setMode] = useState("scene"); - const [selectedSnap, setSelectedSnap] = useState(null); + const [orbitId, setOrbitId] = useState(); + const [snapshotId, setSnapshotId] = useState(null); const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null); - const [galaxyFlowing, setGalaxyFlowing] = useState(true); - const [capturePulse, setCapturePulse] = useState(0); + const [play, setPlay] = useState(true); + const [restoreBusy, setRestoreBusy] = useState(false); + const [restoreTarget, setRestoreTarget] = useState<{ id: string | null }>(); + const reducedMotion = useReducedMotion(); const qc = useQueryClient(); - const health = useQuery({ - queryKey: ["health"], - queryFn: fetchHealth, - refetchInterval: 30_000, - retry: 1, - }); - const snaps = useQuery({ - queryKey: ["snapshots"], - queryFn: fetchSnapshots, - refetchInterval: 8_000, - }); - const orbits = useQuery({ - queryKey: ["orbits"], - queryFn: fetchOrbits, - refetchInterval: 8_000, - }); - - const vaultStatus = vaultStatusFromOrbits(orbits.data ?? []); - const hubOnline = health.isSuccess; - const totalBytes = useMemo( - () => (snaps.data ?? []).reduce((a, s) => a + s.size_bytes, 0), - [snaps.data], - ); - - const capturing = - orbits.data?.some((o) => o.last_status === "running") ?? false; - + 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: async () => { - const target = orbits.data?.[0]; - if (!target) throw new Error("no-orbit"); - await runOrbit(target.id); + mutationFn: (target: Orbit) => runOrbit(target.id), + onSettled: () => { + void qc.invalidateQueries({ queryKey: ["orbits"] }); + void qc.invalidateQueries({ queryKey: ["snapshots"] }); }, - onSuccess: () => qc.invalidateQueries({ queryKey: ["snapshots", "orbits"] }), }); - const selectedSnapshot = snaps.data?.find((s) => s.id === selectedSnap); + 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, + ), [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]); + const totalBytes = useMemo(() => (snaps.data ?? []).reduce((sum, snap) => sum + snap.size_bytes, 0), [snaps.data]); + 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 failedCount = sceneOrbits.filter(({ last_status }) => last_status === "failed").length; - useEffect(() => { - const onKey = (e: KeyboardEvent) => { - if (e.key === "Escape" && mode !== "scene") setMode("scene"); - }; - window.addEventListener("keydown", onKey); - return () => window.removeEventListener("keydown", onKey); - }, [mode]); + const orbitMessage = orbits.isPending ? "Receiving orbit telemetry…" : orbits.isError + ? orbits.data ? "Live telemetry unavailable. Showing last known orbits." : "Orbit telemetry unavailable." + : register.length ? undefined : "No backup jobs yet. Set up an orbit to begin."; + 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" + : capture.isError ? "Capture failed for" + : capture.variables?.dry_run ? "Rehearsal complete for" + : capture.data ? "Snapshot secured from" : "Capture finished for"; + const captureNotice = capture.variables && ( +

+ {captureLabel} {capture.variables.name}{capture.isPending ? "…" : "."} +

+ ); + const noticeInInspector = !!selected && selected.id === capture.variables?.id; - const snapshotPanel = selectedSnapshot && mode === "scene"; + function selectOrbit(id: string) { + setOrbitId(id); + setPlay(false); + } + + function openSnapshot(id: string) { + document.getElementById(`snapshot-${id}`)?.focus({ preventScroll: true }); + setSnapshotId(id); + setMode("snapshot"); + } + + function runCapture(target: Orbit) { + selectOrbit(target.id); + capture.mutate(target); + } + + function openConsole(next: HUDMode, target: string | null = null) { + if (next === "reconstitute" && !restoreBusy && + (!restoreTarget || (target !== null && target !== restoreTarget.id))) { + setRestoreTarget({ id: target }); + } + setMode(next); + } return ( -
- setGalaxyFlowing((f) => !f)} - capturing={capturing || capture.isPending} - capturePulse={capturePulse} - selectedSnapshotId={selectedSnap} - onSelect={(id) => setSelectedSnap(id)} - onSelectOrbit={() => { - setGalaxyFlowing(false); - setMode("orbits"); - }} - /> - - - - setSelectedSnap(id)} - /> - - -
- { - if (!(orbits.data?.length ?? 0)) setMode("orbits"); - else { - setCapturePulse((n) => n + 1); - capture.mutate(); - } - }} - /> -
- - - - setSelectedSnap(null)} - > - {selectedSnapshot && ( - setMode("reconstitute")} - /> - )} - - - setMode("scene")} - > - }> - {(data) => } - - - - setMode("scene")} - > - - - - setMode("scene")} - > - o.decay_preset ?? "week-of-dailies", - )} - /> - - - setMode("scene")} - > - {(snaps.data?.length ?? 0) === 0 ? ( - - ) : ( - - )} - - - {capture.isError && ( -

- NO ORBIT — OPEN ⟳ CONSOLE +

+
+
+ +
TesseraBackup control
+
+ +

+ + {online ? "Hub online" : health.isPending ? "Connecting" : "Hub offline"}

- )} +
+ +
+
+
+

Vault / 01

+

Orbital vault

+

Backup jobs and recovery points

+
+ +
+ +
+ setPlay((value) => !value)} + onSelectOrbit={(id) => { + selectOrbit(id); + document.getElementById(`register-${id}`)?.focus({ preventScroll: true }); + }} + onSelectSnapshot={openSnapshot} + /> + setMode("orbits")} + /> + + + {noticeInInspector && mode !== "orbits" && captureNotice} + + )} + /> +
+
+ {(!noticeInInspector && mode !== "orbits" && captureNotice) ||

Vault telemetry

} +

{restoreBusy ? "Restore active · open Restore to monitor" : "Local backup station"}

+
+
+ + setMode("scene")} + > + {mode === "orbits" && ( + + {() => } + + )} + {mode === "wormhole" && } + {mode === "decay" && orbit.decay_preset ?? "week-of-dailies")} />} + {mode === "snapshot" && (snapshot ? ( + openConsole("reconstitute", snapshot.id)} /> + ) : )} + +
); } diff --git a/web/src/api.ts b/web/src/api.ts index 8925257..e3a99fa 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -1,5 +1,6 @@ export type Snapshot = { id: string; + orbit_id?: string; taken_at: string; orbit_name: string; size_bytes: number; @@ -25,12 +26,17 @@ export type CreateOrbitInput = { dry_run: boolean; }; -async function api(path: string, init?: RequestInit): Promise { +async function request(path: string, init?: RequestInit): Promise { const r = await fetch(path, init); if (!r.ok) { const text = await r.text().catch(() => ""); throw new Error(text || `${path} failed`); } + return r; +} + +async function api(path: string, init?: RequestInit): Promise { + const r = await request(path, init); if (r.status === 204) return undefined as T; return r.json(); } @@ -68,9 +74,9 @@ export async function startPairing(): Promise<{ code: string; expires_at: string return api("/api/v1/wormhole/pairing", { method: "POST" }); } -export async function runOrbit(id: string, rehearse = false): Promise { - await api(`/api/v1/orbits/${id}/run`, { method: "POST" }); - if (rehearse) return; +export async function runOrbit(id: string): Promise { + const response = await request(`/api/v1/orbits/${id}/run`, { method: "POST" }); + return response.headers.get("X-Tessera-Snapshot-Id"); } export async function startReconstitute( @@ -92,7 +98,8 @@ export async function abortReconstitute(sessionId: string): Promise { } export async function pollReconstitute(sessionId: string) { - return api<{ state: string; seconds_remaining: number }>( - `/api/v1/reconstitute/${sessionId}`, - ); + const response = await fetch(`/api/v1/reconstitute/${sessionId}`); + if (response.status === 404) return { state: "unavailable", seconds_remaining: 0 }; + if (!response.ok) throw new Error("Could not read restore status"); + return response.json() as Promise<{ state: string; seconds_remaining: number }>; } diff --git a/web/src/components/hud/DiegeticHUD.tsx b/web/src/components/hud/DiegeticHUD.tsx index 0d74438..b4355a5 100644 --- a/web/src/components/hud/DiegeticHUD.tsx +++ b/web/src/components/hud/DiegeticHUD.tsx @@ -1,89 +1,132 @@ -import type { ReactNode } from "react"; -import type { VaultStatus } from "../../lib/format"; -import { StatusDot } from "../ui/StatusDot"; -import { formatBytes } from "../../lib/format"; -import type { Snapshot } from "../../api"; - -export function CockpitFrame({ children }: { children: ReactNode }) { - return ( -
- -

- Tessera · orbital vault -

-

- SYS // VAULT-01 -

-
-
-
- {children} -
- ); -} - -function motionBorder() { - return ( - <> - - - - - - ); -} +import type { KeyboardEvent, ReactNode } from "react"; +import type { Orbit, Snapshot } from "../../api"; +import { formatBytes, formatWhen, orbitStatus, schedulePhrase } from "../../lib/format"; export function TelemetryStrip({ - status, - online, - snapCount, - totalBytes, + orbitCount, failedCount, snapCount, totalBytes, }: { - status: VaultStatus; - online: boolean; - snapCount: number; + orbitCount?: number; + failedCount: number; + snapCount?: number; totalBytes: number; }) { return ( -
-
- - {online ? "LINK OK" : "NO LINK"} -
-
-
TILES {snapCount}
-
{formatBytes(totalBytes)} mass
-
-
+
+
Orbits
{orbitCount ?? "—"}
+
Failed
{orbitCount === undefined ? "—" : failedCount}
+
Snapshots
{snapCount ?? "—"}
+
Payload
{snapCount === undefined ? "—" : formatBytes(totalBytes)}
+
); } -export function SnapshotsMiniList({ - snapshots, - selected, - onSelect, +export function OrbitRegister({ + orbits, selected, message, onSelect, onManage, }: { - snapshots: Snapshot[]; - selected: string | null; + orbits: Orbit[]; + selected?: string; + message?: string; onSelect: (id: string) => void; + onManage: () => void; }) { - if (!snapshots.length) return null; + const active = orbits.some(({ id }) => id === selected) ? selected : orbits[0]?.id; + + function moveFocus(event: KeyboardEvent, index: number) { + const next = { ArrowUp: index - 1, ArrowDown: index + 1, Home: 0, End: orbits.length - 1 }[event.key]; + if (next === undefined) return; + event.preventDefault(); + const target = orbits[Math.min(orbits.length - 1, Math.max(0, next))]; + onSelect(target.id); + document.getElementById(`register-${target.id}`)?.focus(); + } + return ( -
- {snapshots.slice(0, 4).map((s, i) => ( - + + ); + })} + +
+ - ))} -
+
+ + ); +} + +export function OrbitInspector({ + orbit, snapshots, snapshotMessage, capture, onSelectSnapshot, +}: { + orbit?: Orbit; + snapshots: Snapshot[]; + snapshotMessage?: string; + capture?: ReactNode; + onSelectSnapshot: (id: string) => void; +}) { + const status = orbitStatus(orbit?.last_status ?? "idle"); + return ( +
+
+

Orbit detail

+

{orbit?.name ?? "Select an orbit"}

+ {orbit &&

{status.label}

} +
+ {orbit ? ( + <> +

{schedulePhrase(orbit.schedule, orbit.dry_run)}

+
{capture}
+
+
+

Snapshot history

+ {snapshots.length.toString().padStart(2, "0")} +
+ {snapshotMessage &&

{snapshotMessage}

} +
    + {snapshots.map((snapshot, index) => ( +
  • + +
  • + ))} +
+
+ + ) : ( +

Choose a star on the map or an orbit in the register to inspect its status and recovery points.

+ )} +
); } diff --git a/web/src/components/hud/HUDPanel.tsx b/web/src/components/hud/HUDPanel.tsx index c8a0ddb..4e5ba08 100644 --- a/web/src/components/hud/HUDPanel.tsx +++ b/web/src/components/hud/HUDPanel.tsx @@ -1,96 +1,54 @@ -import { motion, AnimatePresence } from "motion/react"; -import type { ReactNode } from "react"; +import { useId, useLayoutEffect, useRef, type ReactNode } from "react"; export function HUDPanel({ - open, - title, - subtitle, - onClose, - children, - side = "right", + open, title, subtitle, onClose, children, }: { open: boolean; title: string; subtitle?: string; onClose: () => void; children: ReactNode; - side?: "left" | "right" | "bottom"; }) { - const pos = - side === "left" - ? "left-0 top-12 bottom-20 w-[min(100%,380px)] border-r" - : side === "bottom" - ? "inset-x-0 bottom-20 top-auto max-h-[55dvh] border-t" - : "right-0 top-12 bottom-20 w-[min(100%,400px)] border-l"; + const dialog = useRef(null); + const heading = useRef(null); + const labelId = useId(); + const descriptionId = useId(); + + useLayoutEffect(() => { + const panel = dialog.current; + if (!open || !panel) return; + panel.showModal(); + return () => panel.close(); + }, [open]); + + useLayoutEffect(() => { + if (open) heading.current?.focus(); + }, [open, title]); return ( - - {open && ( - <> - - -
-
-

- Console -

-

{title}

- {subtitle &&

{subtitle}

} -
- -
-
{children}
-
- - )} -
- ); -} - -export function SceneAction({ - label, - onClick, - disabled, - variant = "primary", -}: { - label: string; - onClick: () => void; - disabled?: boolean; - variant?: "primary" | "ghost"; -}) { - return ( - { + event.preventDefault(); + onClose(); + }} > - {label} - + {open && ( +
+
+

Vault console

+

{title}

+ {subtitle &&

{subtitle}

} +
+ +
+ )} +
{children}
+ ); } diff --git a/web/src/components/hud/HUDRail.tsx b/web/src/components/hud/HUDRail.tsx index 85abf46..c935784 100644 --- a/web/src/components/hud/HUDRail.tsx +++ b/web/src/components/hud/HUDRail.tsx @@ -1,60 +1,31 @@ -import { motion } from "motion/react"; +export type HUDMode = "scene" | "orbits" | "wormhole" | "decay" | "reconstitute" | "snapshot"; -export type HUDMode = "scene" | "orbits" | "wormhole" | "decay" | "reconstitute"; - -const items: { id: HUDMode; label: string; glyph: string; hint: string }[] = [ - { id: "scene", label: "Viewport", glyph: "◎", hint: "Vault ring" }, - { id: "orbits", label: "Orbits", glyph: "⟳", hint: "Flight paths" }, - { id: "wormhole", label: "Wormhole", glyph: "◉", hint: "Outpost link" }, - { id: "decay", label: "Decay", glyph: "◇", hint: "Fade policy" }, - { id: "reconstitute", label: "Restore", glyph: "↩", hint: "Reconstitute" }, -]; +const items = [ + { id: "scene", label: "Vault" }, + { id: "orbits", label: "Orbits" }, + { id: "wormhole", label: "Outposts" }, + { id: "decay", label: "Retention" }, + { id: "reconstitute", label: "Restore" }, +] as const; export function HUDRail({ - active, - onSelect, - capturing, + active, onSelect, }: { active: HUDMode; - onSelect: (m: HUDMode) => void; - capturing?: boolean; + onSelect: (mode: HUDMode) => void; }) { return ( -