diff --git a/docs/UI.md b/docs/UI.md new file mode 100644 index 0000000..86921f7 --- /dev/null +++ b/docs/UI.md @@ -0,0 +1,22 @@ +# Tessera canvas — screen map + +One viewport (`100dvh`) with bottom tabs; detail flows use sheets (Labuh-style). + +| Tab | Purpose | +|-----|---------| +| **Vault** | Starfield + orbital SVG ring; snapshot tiles; Capture now; entry to reconstitute sheet | +| **Orbits** | Orbit cards (status dot, schedule phrase, rehearse badge); add orbit editor; capture; telemetry | +| **Wormhole** | Pairing code for outposts; placeholder outpost health (grey = offline) | +| **Decay** | Preset library with “in use” from orbit metadata | + +### Sheets (overlays) + +- **Snapshot tile** — evidence (time, size), reconstitute CTA, snapshot ID telemetry +- **Reconstitute** — pick snapshot/target, 12s grace ring + abort, state copy per SPEC + +### API wiring + +- `GET /api/v1/snapshots`, `/orbits`, `/health` +- `POST /api/v1/orbits`, `/orbits/:id/run`, `/reconstitute`, `/wormhole/pairing` + +See `web/README.md` for dev commands. diff --git a/web/README.md b/web/README.md new file mode 100644 index 0000000..87bf8da --- /dev/null +++ b/web/README.md @@ -0,0 +1,28 @@ +# Tessera web canvas + +React 19 + Vite + Tailwind 4 + TanStack Query + Motion. + +## Dev + +```bash +npm ci +npm run dev +``` + +Proxies `/api` and `/health` to `http://127.0.0.1:8787` (see `vite.config.ts`). + +## Production + +```bash +npm run build +``` + +Hub embeds `web/dist` at compile time — rebuild `tessera-hub` after UI changes: + +```bash +cargo build --release -p tessera-hub +``` + +## Screen map + +See [../docs/UI.md](../docs/UI.md). diff --git a/web/src/App.tsx b/web/src/App.tsx index e59345a..a59c07d 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,159 +1,178 @@ import { useState } from "react"; -import { useQuery } from "@tanstack/react-query"; -import { motion, AnimatePresence } from "motion/react"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { AnimatePresence } from "motion/react"; import { + abortReconstitute, + fetchHealth, fetchOrbits, fetchSnapshots, - runOrbit, - startPairing, - startReconstitute, - abortReconstitute, pollReconstitute, + runOrbit, + startReconstitute, } from "./api"; -import { VaultRing } from "./components/VaultRing"; -import { OrbitsPanel } from "./components/OrbitsPanel"; -import { ReconstituteWizard } from "./components/ReconstituteWizard"; +import { vaultStatusFromOrbits } from "./lib/format"; +import { DecayView } from "./components/decay/DecayView"; +import { AppHeader, NavBar, type Tab } from "./components/layout/NavBar"; +import { OrbitsView } from "./components/orbits/OrbitsView"; +import { WormholeView } from "./components/outposts/WormholeView"; +import { ReconstituteWizard } from "./components/reconstitute/ReconstituteWizard"; +import { Starfield } from "./components/scene/Starfield"; +import { SnapshotSheet } from "./components/vault/SnapshotSheet"; +import { VaultRing } from "./components/vault/VaultRing"; +import { EmptyState } from "./components/ui/EmptyState"; +import { QueryGate } from "./components/ui/QueryGate"; +import { Sheet } from "./components/ui/Sheet"; +import { StatusDot } from "./components/ui/StatusDot"; +import { Button } from "./components/ui/Button"; -type Sheet = "none" | "snapshot" | "reconstitute" | "wormhole"; +type Overlay = "none" | "snapshot" | "reconstitute"; export default function App() { - const [sheet, setSheet] = useState("none"); + const [tab, setTab] = useState("vault"); + const [overlay, setOverlay] = useState("none"); const [selectedSnap, setSelectedSnap] = useState(null); const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null); + const qc = useQueryClient(); - const snaps = useQuery({ queryKey: ["snapshots"], queryFn: fetchSnapshots, refetchInterval: 8000 }); - const orbits = useQuery({ queryKey: ["orbits"], queryFn: fetchOrbits, refetchInterval: 8000 }); + const health = useQuery({ + queryKey: ["health"], + queryFn: fetchHealth, + refetchInterval: 30_000, + retry: 1, + }); - const statusColor = - orbits.data?.some((o) => o.last_status === "failed") - ? "bg-orbit-red" - : orbits.data?.some((o) => o.last_status === "running" || o.last_status === "rehearsed") - ? "bg-orbit-amber" - : "bg-orbit-green"; + 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 capture = useMutation({ + mutationFn: async () => { + const list = orbits.data ?? []; + const target = list[0]; + if (!target) throw new Error("no-orbit"); + await runOrbit(target.id); + }, + onSuccess: () => { + qc.invalidateQueries({ queryKey: ["snapshots", "orbits"] }); + }, + }); + + const selectedSnapshot = snaps.data?.find((s) => s.id === selectedSnap); return ( -
-
-
-

Tessera Vault

-

Only stardust that changed

-
- -
+
+ + } + subtitle={hubOnline ? "Orbital backup vault" : "Hub unreachable"} + /> -
- { - setSelectedSnap(id); - setSheet("snapshot"); - }} - /> - + {(data) => ( + o.last_status === "running")} + onCapture={() => { + if (!(orbits.data?.length ?? 0)) setTab("orbits"); + else capture.mutate(); + }} + onSelect={(id) => { + setSelectedSnap(id); + setOverlay("snapshot"); + }} + /> + )} + + )} + {tab === "orbits" && ( + } + > + {(data) => } + + )} + {tab === "outposts" && ( + setPairing(p)} + /> + )} + {tab === "decay" && ( + o.decay_preset ?? "week-of-dailies")} /> + )} + + {tab === "vault" && ( +
+ +
+ )}
+ + - {sheet !== "none" && ( - setOverlay("none")} > - {sheet === "snapshot" && selectedSnap && ( - setSheet("none")} - onReconstitute={() => setSheet("reconstitute")} - /> - )} - {sheet === "reconstitute" && ( - - )} - {sheet === "wormhole" && pairing && ( -
-

Open a wormhole

-

- On your outpost, run{" "} - tessera-agent pair {pairing.code} -

-

{pairing.code}

-
- )} -
+ setOverlay("reconstitute")} + /> + + )} + {overlay === "reconstitute" && ( + setOverlay("none")}> + + )}
- runOrbit(id).then(() => orbits.refetch())} - /> -
- ); -} - -function TabButton({ children, onClick }: { children: React.ReactNode; onClick: () => void }) { - return ( - - ); -} - -function SnapshotDetail({ - id, - snaps, - onClose, - onReconstitute, -}: { - id: string; - snaps: { id: string; orbit_name: string; taken_at: string; size_bytes: number }[]; - onClose: () => void; - onReconstitute: () => void; -}) { - const snap = snaps.find((s) => s.id === id); - if (!snap) return null; - return ( -
-
-

Snapshot tile

- -
-

Orbit {snap.orbit_name}

-

{new Date(snap.taken_at).toLocaleString()}

-

{snap.size_bytes} bytes

- + {capture.isError && ( +

+ Add an orbit first, then capture. +

+ )}
); } diff --git a/web/src/api.ts b/web/src/api.ts index 0a2d5cc..8925257 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -9,49 +9,90 @@ export type Orbit = { id: string; name: string; provider: string; + provider_config?: string; last_status: string; dry_run: boolean; schedule?: string | null; + decay_preset?: string; }; -export async function fetchSnapshots(): Promise { - const r = await fetch("/api/v1/snapshots"); - if (!r.ok) throw new Error("snapshots"); +export type CreateOrbitInput = { + name: string; + provider: "filesystem" | "postgres"; + paths: string[]; + schedule?: string; + decay_preset: string; + dry_run: boolean; +}; + +async function api(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`); + } + if (r.status === 204) return undefined as T; return r.json(); } +export async function fetchHealth(): Promise { + const r = await fetch("/health"); + if (!r.ok) throw new Error("hub offline"); + return r.text(); +} + +export async function fetchSnapshots(): Promise { + return api("/api/v1/snapshots"); +} + export async function fetchOrbits(): Promise { - const r = await fetch("/api/v1/orbits"); - if (!r.ok) throw new Error("orbits"); - return r.json(); + return api("/api/v1/orbits"); +} + +export async function createOrbit(input: CreateOrbitInput): Promise { + return api("/api/v1/orbits", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + name: input.name, + provider: input.provider, + provider_config: { paths: input.paths }, + schedule: input.schedule || null, + decay_preset: input.decay_preset, + dry_run: input.dry_run, + }), + }); } export async function startPairing(): Promise<{ code: string; expires_at: string }> { - const r = await fetch("/api/v1/wormhole/pairing", { method: "POST" }); - return r.json(); + return api("/api/v1/wormhole/pairing", { method: "POST" }); } -export async function runOrbit(id: string): Promise { - await fetch(`/api/v1/orbits/${id}/run`, { 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 startReconstitute(snapshotId: string, target: string): Promise<{ +export async function startReconstitute( + snapshotId: string, + target: string, +): Promise<{ session_id: string; session: { seconds_remaining: number; state: string }; }> { - const r = await fetch("/api/v1/reconstitute", { + return api("/api/v1/reconstitute", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ snapshot_id: snapshotId, target_path: target }), }); - return r.json(); } export async function abortReconstitute(sessionId: string): Promise { - await fetch(`/api/v1/reconstitute/${sessionId}`, { method: "DELETE" }); + await api(`/api/v1/reconstitute/${sessionId}`, { method: "DELETE" }); } export async function pollReconstitute(sessionId: string) { - const r = await fetch(`/api/v1/reconstitute/${sessionId}`); - return r.json(); + return api<{ state: string; seconds_remaining: number }>( + `/api/v1/reconstitute/${sessionId}`, + ); } diff --git a/web/src/components/OrbitsPanel.tsx b/web/src/components/OrbitsPanel.tsx deleted file mode 100644 index 12efa69..0000000 --- a/web/src/components/OrbitsPanel.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import type { Orbit } from "../api"; - -export function OrbitsPanel({ - orbits, - onRun, -}: { - orbits: Orbit[]; - onRun: (id: string) => void; -}) { - if (!orbits.length) return null; - return ( -
- {orbits.map((o) => ( -
-
- - {o.name} -
-

- {o.dry_run ? "Rehearse orbit" : scheduleLabel(o.schedule)} -

- -
- ))} -
- ); -} - -function StatusDot({ status }: { status: string }) { - const color = - status === "failed" - ? "bg-orbit-red" - : status === "running" || status === "rehearsed" - ? "bg-orbit-amber" - : status === "completed" - ? "bg-orbit-green" - : "bg-star-300/40"; - return ; -} - -function scheduleLabel(schedule?: string | null) { - if (!schedule) return "On demand"; - if (schedule.includes("0 2")) return "Every night at 2am"; - return schedule; -} diff --git a/web/src/components/ReconstituteWizard.tsx b/web/src/components/ReconstituteWizard.tsx deleted file mode 100644 index 8b7bc77..0000000 --- a/web/src/components/ReconstituteWizard.tsx +++ /dev/null @@ -1,90 +0,0 @@ -import { useEffect, useState } from "react"; -import type { Snapshot } from "../api"; - -export function ReconstituteWizard({ - snapshots, - selected, - onStart, - onPoll, - onAbort, -}: { - snapshots: Snapshot[]; - selected: string | null; - onStart: (snapId: string, target: string) => Promise<{ session_id: string; session: { seconds_remaining: number; state: string } }>; - onPoll: (id: string) => Promise<{ state: string; seconds_remaining: number }>; - onAbort: (id: string) => Promise; -}) { - const [snapId, setSnapId] = useState(selected ?? snapshots[0]?.id ?? ""); - const [target, setTarget] = useState("./restore/out"); - const [sessionId, setSessionId] = useState(null); - const [remaining, setRemaining] = useState(12); - const [state, setState] = useState("idle"); - - useEffect(() => { - if (!sessionId) return; - const t = setInterval(async () => { - const s = await onPoll(sessionId); - setState(s.state); - setRemaining(s.seconds_remaining ?? 0); - }, 500); - return () => clearInterval(t); - }, [sessionId, onPoll]); - - return ( -
-

Reconstitute

-

Pick a snapshot and where it should land.

- - - {state === "countdown" && ( -

- Reconstituting in {remaining}s — abort restores nothing. -

- )} -
- - -
- {state === "completed" &&

Reconstitute complete.

} - {state === "aborted" &&

Reconstitute cancelled. Nothing was changed.

} -
- ); -} diff --git a/web/src/components/VaultRing.tsx b/web/src/components/VaultRing.tsx deleted file mode 100644 index 364f19c..0000000 --- a/web/src/components/VaultRing.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import { motion } from "motion/react"; -import type { Snapshot } from "../api"; - -export function VaultRing({ - snapshots, - onSelect, -}: { - snapshots: Snapshot[]; - onSelect: (id: string) => void; -}) { - const count = Math.max(snapshots.length, 6); - const radius = Math.min(140, typeof window !== "undefined" ? window.innerWidth * 0.35 : 140); - - return ( -
- - - - Vault - - {snapshots.slice(0, 12).map((snap, i) => { - const angle = (i / count) * Math.PI * 2 - Math.PI / 2; - const x = Math.cos(angle) * radius; - const y = Math.sin(angle) * radius; - return ( - onSelect(snap.id)} - > - - {snap.orbit_name} - - ); - })} - -
- ); -} diff --git a/web/src/components/decay/DecayView.tsx b/web/src/components/decay/DecayView.tsx new file mode 100644 index 0000000..08c401b --- /dev/null +++ b/web/src/components/decay/DecayView.tsx @@ -0,0 +1,51 @@ +import { DECAY_PRESETS } from "../../lib/format"; +import { Hint } from "../ui/EmptyState"; +import { TelemetryPanel } from "../ui/Telemetry"; + +export function DecayView({ appliedPresets }: { appliedPresets: string[] }) { + const unique = [...new Set(appliedPresets)]; + + return ( +
+

Decay

+

+ Old snapshots fade on purpose — friendly presets, not retention spreadsheets. +

+ + Presets — pick one when you create an orbit +
    + {DECAY_PRESETS.map((p) => { + const active = unique.includes(p.id); + return ( +
  • +
    +

    {p.title}

    + {active && ( + + In use + + )} +
    +

    {p.blurb}

    +
  • + ); + })} +
+ + + Decay runs after a successful capture — rehearsed orbits never prune the vault. + + + + {JSON.stringify(DECAY_PRESETS.map((p) => p.id), null, 2)} + +
+ ); +} diff --git a/web/src/components/layout/NavBar.tsx b/web/src/components/layout/NavBar.tsx new file mode 100644 index 0000000..e9d67ae --- /dev/null +++ b/web/src/components/layout/NavBar.tsx @@ -0,0 +1,55 @@ +import type { ReactNode } from "react"; + +export type Tab = "vault" | "orbits" | "outposts" | "decay"; + +const tabs: { id: Tab; label: string }[] = [ + { id: "vault", label: "Vault" }, + { id: "orbits", label: "Orbits" }, + { id: "outposts", label: "Wormhole" }, + { id: "decay", label: "Decay" }, +]; + +export function NavBar({ + active, + onChange, +}: { + active: Tab; + onChange: (t: Tab) => void; +}) { + return ( + + ); +} + +export function AppHeader({ + statusDot, + subtitle, +}: { + statusDot: ReactNode; + subtitle: string; +}) { + return ( +
+
+

Tessera

+

{subtitle}

+
+ {statusDot} +
+ ); +} diff --git a/web/src/components/orbits/OrbitsView.tsx b/web/src/components/orbits/OrbitsView.tsx new file mode 100644 index 0000000..e447643 --- /dev/null +++ b/web/src/components/orbits/OrbitsView.tsx @@ -0,0 +1,156 @@ +import { useState } from "react"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import type { Orbit } from "../../api"; +import { createOrbit, runOrbit } from "../../api"; +import { DECAY_PRESETS, schedulePhrase } from "../../lib/format"; +import { Button } from "../ui/Button"; +import { OrbitStatusDot } from "../ui/StatusDot"; +import { TelemetryPanel } from "../ui/Telemetry"; +import { Hint } from "../ui/EmptyState"; + +export function OrbitsView({ orbits }: { orbits: Orbit[] }) { + const [editing, setEditing] = useState(false); + const qc = useQueryClient(); + const [name, setName] = useState("nightly-docs"); + const [path, setPath] = useState("./docs"); + const [preset, setPreset] = useState(DECAY_PRESETS[0].id); + const [rehearse, setRehearse] = useState(false); + const [schedule, setSchedule] = useState("0 2 * * *"); + + const create = useMutation({ + mutationFn: () => + createOrbit({ + name, + provider: "filesystem", + paths: [path], + schedule: schedule || undefined, + decay_preset: preset, + dry_run: rehearse, + }), + onSuccess: () => { + qc.invalidateQueries({ queryKey: ["orbits"] }); + setEditing(false); + }, + }); + + const run = useMutation({ + mutationFn: (id: string) => runOrbit(id), + onSuccess: () => qc.invalidateQueries({ queryKey: ["orbits", "snapshots"] }), + }); + + return ( +
+
+

Orbits

+

+ Scheduled circles around your vault — not cron jargon in the headline. +

+
+ +
+ {orbits.map((o) => ( +
+
+ +
+

{o.name}

+

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

+ {o.dry_run && ( + + Rehearse mode + + )} +
+
+
+ +
+ + {JSON.stringify(o, null, 2)} + +
+ ))} +
+ + {editing ? ( +
+

New orbit

+ + + + + + + Rehearse orbits prove the path without writing to the vault — status shows amber “rehearsed”. + +
+ + +
+
+ ) : ( + + )} +
+ ); +} + +// fix motion.collapse - use div \ No newline at end of file diff --git a/web/src/components/outposts/WormholeView.tsx b/web/src/components/outposts/WormholeView.tsx new file mode 100644 index 0000000..162dd72 --- /dev/null +++ b/web/src/components/outposts/WormholeView.tsx @@ -0,0 +1,93 @@ +import { useMutation } from "@tanstack/react-query"; +import { motion } from "motion/react"; +import { startPairing } from "../../api"; +import { Button } from "../ui/Button"; +import { Hint } from "../ui/EmptyState"; +import { TelemetryPanel } from "../ui/Telemetry"; + +export function WormholeView({ + pairing, + onPaired, +}: { + pairing: { code: string; expires_at: string } | null; + onPaired: (p: { code: string; expires_at: string }) => void; +}) { + const gen = useMutation({ + mutationFn: startPairing, + onSuccess: onPaired, + }); + + const expires = pairing ? new Date(pairing.expires_at).toLocaleTimeString() : ""; + + return ( +
+

Outposts & wormholes

+

+ Link a remote machine once — it beams snapshots through an encrypted wormhole. +

+ + {!pairing ? ( + gen.mutate()} loading={gen.isPending} /> + ) : ( + +

+ Pairing code +

+

{pairing.code}

+

Burns at {expires}

+ + On the outpost:{" "} + tessera-agent pair {pairing.code} + + + + {JSON.stringify(pairing, null, 2)} + +
+ )} + +
+

Outpost health

+
+ +
+

No outposts paired yet

+

Grey dot means offline or waiting.

+
+
+
+
+ ); +} + +function EmptyWormhole({ + onGenerate, + loading, +}: { + onGenerate: () => void; + loading: boolean; +}) { + return ( +
+ + ◉ + +

+ Open a wormhole when you're ready to claim an outpost. +

+ +
+ ); +} diff --git a/web/src/components/reconstitute/ReconstituteWizard.tsx b/web/src/components/reconstitute/ReconstituteWizard.tsx new file mode 100644 index 0000000..48861c5 --- /dev/null +++ b/web/src/components/reconstitute/ReconstituteWizard.tsx @@ -0,0 +1,163 @@ +import { useEffect, useState } from "react"; +import { motion } from "motion/react"; +import type { Snapshot } from "../../api"; +import { formatBytes, formatWhen } from "../../lib/format"; +import { Button } from "../ui/Button"; +import { Hint } from "../ui/EmptyState"; +import { TelemetryPanel } from "../ui/Telemetry"; + +const GRACE = 12; + +export function ReconstituteWizard({ + snapshots, + selected, + onStart, + onPoll, + onAbort, +}: { + snapshots: Snapshot[]; + selected: string | null; + onStart: (snapId: string, target: string) => Promise<{ + session_id: string; + session: { seconds_remaining: number; state: string }; + }>; + onPoll: (id: string) => Promise<{ state: string; seconds_remaining: number }>; + onAbort: (id: string) => Promise; +}) { + const [snapId, setSnapId] = useState(selected ?? snapshots[0]?.id ?? ""); + const [target, setTarget] = useState("./restore/out"); + const [sessionId, setSessionId] = useState(null); + const [remaining, setRemaining] = useState(GRACE); + const [state, setState] = useState("idle"); + + const snap = snapshots.find((s) => s.id === snapId); + + useEffect(() => { + if (!sessionId) return; + const t = setInterval(async () => { + try { + const s = await onPoll(sessionId); + setState(s.state); + setRemaining(s.seconds_remaining ?? 0); + } catch { + /* hub may clear session */ + } + }, 400); + return () => clearInterval(t); + }, [sessionId, onPoll]); + + const inCountdown = state === "countdown"; + + return ( +
+

+ Pick a snapshot, choose where it lands, then wait through the grace window. +

+ + {snap && ( +
+

{snap.orbit_name}

+

{formatWhen(snap.taken_at)} · {formatBytes(snap.size_bytes)}

+
+ )} + + + + + + {inCountdown && ( + +
+ + + + + + {remaining} + +
+

+ Reconstituting in {remaining}s — abort restores nothing. +

+
+ )} + +
+ + +
+ + {state === "completed" && ( +

Reconstitute complete.

+ )} + {state === "aborted" && ( +

Reconstitute cancelled. Nothing was changed.

+ )} + {state === "failed" && ( +

Reconstitute failed — check telemetry.

+ )} + + Destructive-capable. Evidence above is what we'll write to disk after the timer. + + {sessionId && ( + + {JSON.stringify({ sessionId, state, remaining }, null, 2)} + + )} +
+ ); +} diff --git a/web/src/components/scene/Starfield.tsx b/web/src/components/scene/Starfield.tsx new file mode 100644 index 0000000..a5dc8c1 --- /dev/null +++ b/web/src/components/scene/Starfield.tsx @@ -0,0 +1,46 @@ +import { useMemo } from "react"; + +export function Starfield() { + const stars = useMemo( + () => + Array.from({ length: 48 }, (_, i) => ({ + id: i, + left: `${(i * 17 + 7) % 100}%`, + top: `${(i * 23 + 11) % 100}%`, + size: i % 3 === 0 ? 2 : 1, + opacity: 0.2 + (i % 5) * 0.12, + delay: `${(i % 8) * 0.4}s`, + })), + [], + ); + + return ( +
+
+ {stars.map((s) => ( + + ))} +
+ +
+ ); +} diff --git a/web/src/components/ui/Button.tsx b/web/src/components/ui/Button.tsx new file mode 100644 index 0000000..0683fb3 --- /dev/null +++ b/web/src/components/ui/Button.tsx @@ -0,0 +1,26 @@ +import type { ButtonHTMLAttributes } from "react"; + +const variants = { + primary: + "bg-wormhole-violet/25 text-star-100 border-wormhole-violet/40 hover:bg-wormhole-violet/35", + ghost: "bg-space-800/60 text-star-200 border-space-700 hover:bg-space-800", + danger: "bg-orbit-red/15 text-orbit-red border-orbit-red/35 hover:bg-orbit-red/25", + success: "bg-orbit-green/15 text-orbit-green border-orbit-green/35 hover:bg-orbit-green/25", + warn: "bg-orbit-amber/15 text-orbit-amber border-orbit-amber/40 hover:bg-orbit-amber/25", +}; + +export function Button({ + variant = "ghost", + className = "", + ...props +}: ButtonHTMLAttributes & { + variant?: keyof typeof variants; +}) { + return ( + + )} +
+ ); +} + +export function Hint({ children }: { children: ReactNode }) { + return ( +

+ {children} +

+ ); +} diff --git a/web/src/components/ui/QueryGate.tsx b/web/src/components/ui/QueryGate.tsx new file mode 100644 index 0000000..7228143 --- /dev/null +++ b/web/src/components/ui/QueryGate.tsx @@ -0,0 +1,36 @@ +import type { UseQueryResult } from "@tanstack/react-query"; +import type { ReactNode } from "react"; +import { Button } from "./Button"; + +export function QueryGate({ + query, + empty, + children, +}: { + query: UseQueryResult; + empty?: ReactNode; + children: (data: T) => ReactNode; +}) { + if (query.isLoading) { + return ( +
+
+

Pulling telemetry from the vault…

+
+ ); + } + if (query.isError) { + return ( +
+

We couldn’t reach the hub right now.

+ +
+ ); + } + const data = query.data; + const isEmpty = Array.isArray(data) && data.length === 0; + if (isEmpty && empty) return <>{empty}; + return <>{children(data as T)}; +} diff --git a/web/src/components/ui/Sheet.tsx b/web/src/components/ui/Sheet.tsx new file mode 100644 index 0000000..24433c2 --- /dev/null +++ b/web/src/components/ui/Sheet.tsx @@ -0,0 +1,51 @@ +import { motion } from "motion/react"; +import type { ReactNode } from "react"; + +export function Sheet({ + open, + onClose, + title, + children, +}: { + open: boolean; + onClose: () => void; + title: string; + children: ReactNode; +}) { + if (!open) return null; + return ( + + +
+ {children} + + + ); +} diff --git a/web/src/components/ui/StatusDot.tsx b/web/src/components/ui/StatusDot.tsx new file mode 100644 index 0000000..7076af5 --- /dev/null +++ b/web/src/components/ui/StatusDot.tsx @@ -0,0 +1,41 @@ +import type { VaultStatus } from "../../lib/format"; + +const colors: Record = { + green: "bg-orbit-green shadow-[0_0_12px_rgba(74,222,154,0.6)]", + amber: "bg-orbit-amber shadow-[0_0_12px_rgba(240,196,104,0.5)]", + grey: "bg-star-400/50", + red: "bg-orbit-red shadow-[0_0_12px_rgba(248,113,113,0.5)]", +}; + +const labels: Record = { + green: "All orbits current", + amber: "Something needs you", + grey: "Quiet vault — no orbits yet", + red: "Last capture failed", +}; + +export function StatusDot({ + status, + size = "md", +}: { + status: VaultStatus; + size?: "sm" | "md" | "lg"; +}) { + const sizeClass = + size === "sm" ? "w-2 h-2" : size === "lg" ? "w-4 h-4" : "w-3 h-3"; + return ( + + ); +} + +export function OrbitStatusDot({ status }: { status: string }) { + let vault: VaultStatus = "grey"; + if (status === "failed") vault = "red"; + else if (status === "running" || status === "rehearsed") vault = "amber"; + else if (status === "completed") vault = "green"; + return ; +} diff --git a/web/src/components/ui/Telemetry.tsx b/web/src/components/ui/Telemetry.tsx new file mode 100644 index 0000000..095bf69 --- /dev/null +++ b/web/src/components/ui/Telemetry.tsx @@ -0,0 +1,29 @@ +import { useState, type ReactNode } from "react"; + +export function TelemetryPanel({ + label, + children, +}: { + label?: string; + children: ReactNode; +}) { + const [open, setOpen] = useState(false); + return ( +
+ + {open && ( +
+          {children}
+        
+ )} +
+ ); +} diff --git a/web/src/components/vault/SnapshotSheet.tsx b/web/src/components/vault/SnapshotSheet.tsx new file mode 100644 index 0000000..42de533 --- /dev/null +++ b/web/src/components/vault/SnapshotSheet.tsx @@ -0,0 +1,32 @@ +import type { Snapshot } from "../../api"; +import { formatBytes, formatWhen } from "../../lib/format"; +import { Button } from "../ui/Button"; +import { TelemetryPanel } from "../ui/Telemetry"; + +export function SnapshotSheet({ + snap, + onReconstitute, +}: { + snap: Snapshot; + onReconstitute: () => void; +}) { + return ( +
+

+ A point-in-time tile on the vault ring — from orbit{" "} + {snap.orbit_name}. +

+
+

Captured

+

{formatWhen(snap.taken_at)}

+

Payload

+

{formatBytes(snap.size_bytes)}

+

Only stardust that changed

+
+ + {snap.id} +
+ ); +} diff --git a/web/src/components/vault/VaultRing.tsx b/web/src/components/vault/VaultRing.tsx new file mode 100644 index 0000000..14467df --- /dev/null +++ b/web/src/components/vault/VaultRing.tsx @@ -0,0 +1,126 @@ +import { motion } from "motion/react"; +import type { Snapshot } from "../../api"; +import { formatBytes, formatWhen } from "../../lib/format"; + +export function VaultRing({ + snapshots, + onSelect, + onCapture, + capturing, +}: { + snapshots: Snapshot[]; + onSelect: (id: string) => void; + onCapture?: () => void; + capturing?: boolean; +}) { + const count = Math.max(snapshots.length, 1); + const radius = 128; + const tiles = snapshots.slice(0, 16); + + return ( +
+
+ + + + + + + + + + + + Vault + + + {snapshots.length} snapshot{tiles.length === 1 ? "" : "s"} + + {tiles.length === 0 && ( + + Capture your first orbit + + )} + {tiles.map((snap, i) => { + const angle = (i / Math.max(count, tiles.length)) * Math.PI * 2 - Math.PI / 2; + const x = Math.cos(angle) * radius; + const y = Math.sin(angle) * radius; + return ( + onSelect(snap.id)} + > + + + + {snap.orbit_name} · {formatWhen(snap.taken_at)} + + + ); + })} + +
+ {onCapture && ( + + {capturing ? "Orbit in progress…" : "Capture now"} + + )} +

+ Tap a tile for snapshot detail. Only stardust that changed. +

+
+ ); +} + +export function SnapshotSummaryRow({ snap }: { snap: Snapshot }) { + return ( +
+ {snap.orbit_name} + {formatBytes(snap.size_bytes)} +
+ ); +} diff --git a/web/src/index.css b/web/src/index.css index 4d9dfdb..1b56b18 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -1,14 +1,25 @@ +@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=JetBrains+Mono:wght@400;500&display=swap"); @import "tailwindcss"; @theme { - --color-space-950: #05060f; - --color-space-900: #0c1024; - --color-space-800: #151b3a; - --color-star-100: #e8ecff; - --color-star-300: #a8b4e8; - --color-orbit-amber: #f5c56b; - --color-orbit-green: #5ee6a8; - --color-orbit-red: #ff6b7a; + --color-space-950: #04050c; + --color-space-900: #0a0e1f; + --color-space-800: #141a36; + --color-space-700: #1e2647; + --color-star-100: #eef1ff; + --color-star-200: #c9d2f5; + --color-star-300: #94a3d4; + --color-star-400: #6b7ab8; + --color-orbit-amber: #f0c468; + --color-orbit-green: #4ade9a; + --color-orbit-red: #f87171; + --color-wormhole-violet: #a78bfa; + --font-sans: "DM Sans", system-ui, sans-serif; + --font-mono: "JetBrains Mono", ui-monospace, monospace; +} + +html { + font-family: var(--font-sans); } html, @@ -17,3 +28,28 @@ body, height: 100%; margin: 0; } + +@layer utilities { + .font-mono { + font-family: var(--font-mono); + } + .scrollbar-none { + scrollbar-width: none; + } + .scrollbar-none::-webkit-scrollbar { + display: none; + } +} + +.stars-drift { + animation: drift 120s linear infinite; +} + +@keyframes drift { + from { + transform: translateY(0); + } + to { + transform: translateY(-120px); + } +} diff --git a/web/src/lib/format.ts b/web/src/lib/format.ts new file mode 100644 index 0000000..76165f5 --- /dev/null +++ b/web/src/lib/format.ts @@ -0,0 +1,60 @@ +export function formatBytes(n: number): string { + if (n < 1024) return `${n} B`; + if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`; + if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`; + return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`; +} + +export function formatWhen(iso: string): string { + return new Date(iso).toLocaleString(undefined, { + dateStyle: "medium", + timeStyle: "short", + }); +} + +export function schedulePhrase(cron?: string | null, dryRun?: boolean): string { + if (dryRun) return "Rehearse — no vault write"; + if (!cron) return "On your command"; + if (cron.includes("0 2")) return "Every night at 2am"; + if (cron.includes("0 */6")) return "Every six hours"; + return cron; +} + +export type VaultStatus = "green" | "amber" | "grey" | "red"; + +export function vaultStatusFromOrbits( + orbits: { last_status: string }[], +): VaultStatus { + if (!orbits.length) return "grey"; + if (orbits.some((o) => o.last_status === "failed")) return "red"; + if ( + orbits.some( + (o) => + o.last_status === "running" || + o.last_status === "rehearsed" || + o.last_status === "rehearsing", + ) + ) + return "amber"; + if (orbits.every((o) => o.last_status === "completed" || o.last_status === "idle")) + return "green"; + return "amber"; +} + +export const DECAY_PRESETS = [ + { + id: "week-of-dailies", + title: "A week of dailies", + blurb: "Keep 7 nightly snapshots, let the rest decay.", + }, + { + id: "month-of-weeklies", + title: "A month of weeklies", + blurb: "One snapshot per week, keep the last 4.", + }, + { + id: "year-of-monthlies", + title: "A year of monthlies", + blurb: "Twelve monthly tiles on the ring.", + }, +] as const;