diff --git a/.gitignore b/.gitignore index 2fb9c4dc3..29c78383d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,10 @@ config.production.toml /ui/.vite/ /ui/*.tsbuildinfo # ui/dist IS committed: the Go build must not need a Node toolchain. +/dashboard-v2/node_modules/ +/dashboard-v2/.vite/ +/dashboard-v2/*.tsbuildinfo +/dashboard-v2/dist/ # air live-reload /.air/ diff --git a/dashboard-v2/AGENTS.md b/dashboard-v2/AGENTS.md new file mode 100644 index 000000000..0b7d1886a --- /dev/null +++ b/dashboard-v2/AGENTS.md @@ -0,0 +1,34 @@ +# AGENTS.md + +Project-specific guidance for AI coding agents. + + +Astryx v0.7.4 · 173 components +CLI: run every command as `pnpm dlx @astryxdesign/cli@0.7.4 ` (shown below as `astryx ...`). + +SETUP (once, in app entry e.g. main.tsx) — without these, components render unstyled: + import "@astryxdesign/core/reset.css"; + import "@astryxdesign/core/astryx.css"; + +WORKFLOW — start every page from a template, never from scratch: +1. `astryx build ""` — names the template to scaffold from and the parts it lacks. +2. `astryx template ` — scaffold it; keep its frame, gap and padding; replace the content. +3. `astryx template ` for parts it lacks; `astryx component ` to read props before using one. +Changing an existing page? Keep it: skip step 2 and add blocks/components inside its sections. + +RULES: +- No
— components handle all layout and spacing. +- Read `astryx docs layout` before changing a template's frame. +- Dense data = rows (Table, List/Item), not Card-wrapped lists. Badge = counts only. +- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes directly. Some templates use StyleX and need a compiler plugin; see `astryx docs styling-overview`. +- Palettes and custom colors go through the theme, never :root overrides. Run `astryx theme add ` to import; `theme eject ` only forks source. See `astryx docs theme`. +- SELF-CHECK: re-read the file; replace any raw
/, imported .css/@apply, or hardcoded #hex/px with the component or a token. + +`astryx help` lists every command. Key ones beyond the workflow: + search "" find any component / hook / doc / template + discover integrations you could add + docs getting-started, principles, tokens, theme … (`astryx docs` lists all) + docs cli commands and API reference + docs authoring build an integration package, and every field it holds + upgrade --from --apply run after a dependency bump + diff --git a/dashboard-v2/GEMINI.md b/dashboard-v2/GEMINI.md new file mode 100644 index 000000000..cd644b8aa --- /dev/null +++ b/dashboard-v2/GEMINI.md @@ -0,0 +1,3 @@ + +@./AGENTS.md + diff --git a/dashboard-v2/README.md b/dashboard-v2/README.md new file mode 100644 index 000000000..095945a43 --- /dev/null +++ b/dashboard-v2/README.md @@ -0,0 +1,28 @@ +# dashboard-v2 + +React plus Astryx replacement for the Vue dashboard (`ui/`), growing by +strangler: new pages land here, served beside the Vue app until v2 covers +everything. The server owns every contract; this app presents them. + +First slice: System status (service health plus component versions), a +read-only mirror of the Vue status page. + +## Run + +```bash +cd dashboard-v2 +pnpm install +astryx theme add neutral # regenerates src/astryx-themes.ts +pnpm run dev # http://localhost:5174 +``` + +Open http://localhost:5174 in a browser after starting it. `/api` proxies +to a locally running archie-ui on 127.0.0.1:8484, same as the Vue dev +server. Port 5174 keeps v2 beside the Vue app on 5173. + +`pnpm run build` typechecks and builds to `dist/`, which is not committed: +serving v2 (embed vs separate deploy) is still an open decision. + +Dependency versions were chosen offline to match Astryx CLI 0.7.4 +(`@astryxdesign/*` 0.7.4, React 19, Vite 8); if `pnpm install` reports peer +conflicts, follow its resolution and commit the lockfile. diff --git a/dashboard-v2/index.html b/dashboard-v2/index.html new file mode 100644 index 000000000..e70f60f6c --- /dev/null +++ b/dashboard-v2/index.html @@ -0,0 +1,12 @@ + + + + + + Status | Archie + + +
+ + + diff --git a/dashboard-v2/package.json b/dashboard-v2/package.json new file mode 100644 index 000000000..9ac040da5 --- /dev/null +++ b/dashboard-v2/package.json @@ -0,0 +1,29 @@ +{ + "name": "archie-dashboard-v2", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc --noEmit && vite build", + "preview": "vite preview", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@astryxdesign/core": "0.7.4", + "@astryxdesign/theme-neutral": "0.7.4", + "@heroicons/react": "^2.2.0", + "@stylexjs/stylex": "^0.8.0", + "react": "^19.1.0", + "react-dom": "^19.1.0" + }, + "devDependencies": { + "@astryxdesign/cli": "0.7.4", + "@types/react": "^19.1.0", + "@types/react-dom": "^19.1.0", + "@vitejs/plugin-react": "^5.0.0", + "typescript": "~6.0.3", + "vite": "^8.3.0" + }, + "packageManager": "pnpm@12.10.1" +} diff --git a/dashboard-v2/pnpm-lock.yaml b/dashboard-v2/pnpm-lock.yaml new file mode 100644 index 000000000..c23260d1b --- /dev/null +++ b/dashboard-v2/pnpm-lock.yaml @@ -0,0 +1,158 @@ +--- +lockfileVersion: '9.0' + +importers: + + .: + configDependencies: {} + packageManagerDependencies: + pnpm: + specifier: 12.10.1 + version: 12.10.1 + +packages: + + '@pnpm/exe.android-arm64@12.10.1': + resolution: {integrity: sha512-CVTlHPwNvadQCJD9bGSMzWIhFX8QpjtqC2c27dhdnn/9iKzEjZ3qL62o3gHpKbIuo6qn4WxTKRoaokgNdReBig==} + cpu: [arm64] + os: [android] + + '@pnpm/exe.android-x64@12.10.1': + resolution: {integrity: sha512-NFiYLIaodY7da0XIebwcU3JoP7IK/lzF7zgKSSP+9H+QcFnQ1GDfBkuBKCYJzZ+Xu0WH54neIPLBBCaOjaaauA==} + cpu: [x64] + os: [android] + + '@pnpm/exe.darwin-arm64@12.10.1': + resolution: {integrity: sha512-0O8tdQ8ijlPJudXspLMTcitMkdBEz6uUflazL5uQE0WMs85oQIp0U+5hfEktMFB64QqEhjqlvvujTwbzdr9oMg==} + cpu: [arm64] + os: [darwin] + + '@pnpm/exe.darwin-x64@12.10.1': + resolution: {integrity: sha512-ud+1/uZOKEo8P/AsPynOJc/LNwfI0j6WwCElibj71rU9l4nIBnsSn+wWTIPZPkZ4BBSH5+82azSnAARMyJ1lNA==} + cpu: [x64] + os: [darwin] + + '@pnpm/exe.freebsd-x64@12.10.1': + resolution: {integrity: sha512-mj9PE5rf8uAfQQ2K66HSATMSut+lNiB4eSqFd5+azFVCMnxNSy/32xpZQJT21PhnN3Y4qbK+iKHe5nWAxSuRhw==} + cpu: [x64] + os: [freebsd] + + '@pnpm/exe.linux-arm64-musl@12.10.1': + resolution: {integrity: sha512-xba+00wZJ8Um6rBJJjWl88uJj0tydB8dtomvjlCLvi0uL32vpa9CRP8Vv26FIXvbiZ1bo2RCzYt/eChxJVV52w==} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@pnpm/exe.linux-arm64@12.10.1': + resolution: {integrity: sha512-oBdMp69ScC9UnniG4qZAQVr2fBDSXjm4yk/72vkEVyrlwS23yMxcRQl7Qdo3sgXPAygY6TWnPRKm4rXzjoyW7w==} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-ppc64@12.10.1': + resolution: {integrity: sha512-Yyb3wu09h3c7mLme270uHFiVaAIUHC411Ru9LIU2BKUIstrGlXa9OqqVWoXaRgYRdFdOFknkwG7GNn6ygwLbnw==} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-riscv64@12.10.1': + resolution: {integrity: sha512-PdkeUFFkybknnGkWP0H22eMpIiS4OZXL5BcQzF4lh+vmrW3IaC2HOkbANKgot/PKO0Kl77pzA/6PKFxgbgfXIQ==} + cpu: [riscv64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-s390x@12.10.1': + resolution: {integrity: sha512-1okKuHKJwJPAbofDxfhZWAUxEWtee4ZSf7Pah8kcvocaJkf2WxFJ5KVTiNIvDml5GLidDQsgf7Pcf/WHbCak7Q==} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@pnpm/exe.linux-x64-musl@12.10.1': + resolution: {integrity: sha512-e6IqzVNkPa7srFKJKnY23uWJ+qz0LaRWiTUo/sHfFXRRMRzB5uNOr6qWWip/jqhdGwU91n9J7LrEYZ6e0tRczw==} + cpu: [x64] + os: [linux] + libc: [musl] + + '@pnpm/exe.linux-x64@12.10.1': + resolution: {integrity: sha512-ZByV0DRgWzGaDSjT5ddRBASdwz+r/qPMYh7o6RGmPQjtRGNFbSl94xY2DcAM8mqCOZJUUDtAXQ+wpBXcdpKlkg==} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@pnpm/exe.win32-arm64@12.10.1': + resolution: {integrity: sha512-I7QZHcjioG7orFeCRUFUHByJ1G0zFPnAlaGGyrUvb6MGkv5oeNwNPl7t+Gp+7zHfnMcgLGJ1a+Wfim0IDw3lOw==} + cpu: [arm64] + os: [win32] + + '@pnpm/exe.win32-x64@12.10.1': + resolution: {integrity: sha512-4WJFdp58EKlCj0zLobrXU0vpszSZIr4X/3y/uNbAQqGW0zE+VdruZB0gFc3L2kzsUzVwTYbaCn+XEhnCYSAlTg==} + cpu: [x64] + os: [win32] + + pnpm@12.10.1: + resolution: {integrity: sha512-ukCjfrGjcNYP6oxM8dNkwTvMzvUY6YrSvO6VT1OdONo3RY5YJho/pV4GUjRQ6g//+fSXsTW+QfLBXBZCusrObA==} + engines: {node: '>=18.*'} + hasBin: true + +snapshots: + + '@pnpm/exe.android-arm64@12.10.1': + optional: true + + '@pnpm/exe.android-x64@12.10.1': + optional: true + + '@pnpm/exe.darwin-arm64@12.10.1': + optional: true + + '@pnpm/exe.darwin-x64@12.10.1': + optional: true + + '@pnpm/exe.freebsd-x64@12.10.1': + optional: true + + '@pnpm/exe.linux-arm64-musl@12.10.1': + optional: true + + '@pnpm/exe.linux-arm64@12.10.1': + optional: true + + '@pnpm/exe.linux-ppc64@12.10.1': + optional: true + + '@pnpm/exe.linux-riscv64@12.10.1': + optional: true + + '@pnpm/exe.linux-s390x@12.10.1': + optional: true + + '@pnpm/exe.linux-x64-musl@12.10.1': + optional: true + + '@pnpm/exe.linux-x64@12.10.1': + optional: true + + '@pnpm/exe.win32-arm64@12.10.1': + optional: true + + '@pnpm/exe.win32-x64@12.10.1': + optional: true + + pnpm@12.10.1: + optionalDependencies: + '@pnpm/exe.android-arm64': 12.10.1 + '@pnpm/exe.android-x64': 12.10.1 + '@pnpm/exe.darwin-arm64': 12.10.1 + '@pnpm/exe.darwin-x64': 12.10.1 + '@pnpm/exe.freebsd-x64': 12.10.1 + '@pnpm/exe.linux-arm64': 12.10.1 + '@pnpm/exe.linux-arm64-musl': 12.10.1 + '@pnpm/exe.linux-ppc64': 12.10.1 + '@pnpm/exe.linux-riscv64': 12.10.1 + '@pnpm/exe.linux-s390x': 12.10.1 + '@pnpm/exe.linux-x64': 12.10.1 + '@pnpm/exe.linux-x64-musl': 12.10.1 + '@pnpm/exe.win32-arm64': 12.10.1 + '@pnpm/exe.win32-x64': 12.10.1 + +--- diff --git a/dashboard-v2/src/App.tsx b/dashboard-v2/src/App.tsx new file mode 100644 index 000000000..2114db18e --- /dev/null +++ b/dashboard-v2/src/App.tsx @@ -0,0 +1,6 @@ +import StatusPage from "./pages/StatusPage.tsx"; + +// One page so far, so no shell or router yet: they land with the second page. +export default function App() { + return ; +} diff --git a/dashboard-v2/src/astryx-themes.ts b/dashboard-v2/src/astryx-themes.ts new file mode 100644 index 000000000..e8b540b0b --- /dev/null +++ b/dashboard-v2/src/astryx-themes.ts @@ -0,0 +1,9 @@ +// Theme wiring in the shape `astryx theme add neutral` generates. It could +// not run before install (offline), so regenerate it then: install, run +// `astryx theme add neutral`, and let it overwrite this module. +import neutral from "@astryxdesign/theme-neutral/built"; +import "@astryxdesign/theme-neutral/theme.css"; + +export const themes = { neutral }; +export type ThemeSlug = keyof typeof themes; +export const defaultThemeSlug: ThemeSlug = "neutral"; diff --git a/dashboard-v2/src/globals.css b/dashboard-v2/src/globals.css new file mode 100644 index 000000000..4b78b1049 --- /dev/null +++ b/dashboard-v2/src/globals.css @@ -0,0 +1,2 @@ +@import "@astryxdesign/core/reset.css"; +@import "@astryxdesign/core/astryx.css"; diff --git a/dashboard-v2/src/lib/api.ts b/dashboard-v2/src/lib/api.ts new file mode 100644 index 000000000..7dd4ac154 --- /dev/null +++ b/dashboard-v2/src/lib/api.ts @@ -0,0 +1,95 @@ +// Minimal port of the Vue dashboard's api client: same request semantics +// (timeout, CSRF on mutation, server-first error text), only the endpoints +// v2 pages use. The server owns every shape below. + +const DEFAULT_TIMEOUT_MS = 15000; + +export class ApiError extends Error { + status: number; + + constructor(message: string, status: number) { + super(message); + this.name = "ApiError"; + this.status = status; + } +} + +// errorMessage prefers what the server actually said: archie-ui answers with +// a plain-text reason, the only part an operator can act on. +async function errorMessage(res: Response): Promise { + try { + const body = (await res.text()).trim(); + if (body) return body.split("\n")[0].slice(0, 200); + } catch { + // Body already consumed or unreadable; fall through to the status. + } + return `${res.status} ${res.statusText}`; +} + +interface RequestOptions { + method?: string; + body?: unknown; + timeoutMs?: number; +} + +async function request( + path: string, + opts: RequestOptions = {}, +): Promise { + const { method = "GET", body, timeoutMs = DEFAULT_TIMEOUT_MS } = opts; + const headers: Record = { Accept: "application/json" }; + const init: RequestInit = { + method, + headers, + signal: AbortSignal.timeout(timeoutMs), + }; + if (method !== "GET") { + headers["Content-Type"] = "application/json"; + headers["X-Archie-CSRF"] = "1"; + } + if (body !== undefined) init.body = JSON.stringify(body); + + const res = await fetch(path, init); + if (!res.ok) throw new ApiError(await errorMessage(res), res.status); + return (await res.json()) as T; +} + +export interface ServiceCheck { + name: string; + status: "ok" | "degraded"; + detail?: string; +} + +export interface Service { + service: string; + instance_id: string; + state: "up" | "degraded" | "down" | "unknown"; + version: string; + install_type: string; + started_at: string; + reported_at: string; + detail?: string; + applied: { + kind: string; + applied_version: number; + error?: string; + state: "current" | "failed" | "unknown"; + }[]; + checks?: ServiceCheck[]; +} + +export interface ComponentVersion { + id: string; + label: string; + install_type?: string; + reference?: string; + running_version?: string; + installed_claim?: string; + latest_available?: string; + status: "ok" | "update_available" | "drift" | "unknown"; +} + +export const api = { + services: () => request("/api/services"), + version: () => request<{ components: ComponentVersion[] }>("/api/version"), +}; diff --git a/dashboard-v2/src/main.tsx b/dashboard-v2/src/main.tsx new file mode 100644 index 000000000..c0ce98fb6 --- /dev/null +++ b/dashboard-v2/src/main.tsx @@ -0,0 +1,19 @@ +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; + +import { Theme } from "@astryxdesign/core/theme"; + +import { defaultThemeSlug, themes } from "./astryx-themes.ts"; +import App from "./App.tsx"; +import "./globals.css"; + +const root = document.getElementById("root"); +if (!root) throw new Error("missing #root element"); + +createRoot(root).render( + + + + + , +); diff --git a/dashboard-v2/src/pages/StatusPage.tsx b/dashboard-v2/src/pages/StatusPage.tsx new file mode 100644 index 000000000..9a519472c --- /dev/null +++ b/dashboard-v2/src/pages/StatusPage.tsx @@ -0,0 +1,292 @@ +import { useCallback, useEffect, useState } from "react"; + +import { Button } from "@astryxdesign/core/Button"; +import { Card } from "@astryxdesign/core/Card"; +import { Divider } from "@astryxdesign/core/Divider"; +import { Grid } from "@astryxdesign/core/Grid"; +import { Icon } from "@astryxdesign/core/Icon"; +import { + HStack, + Layout, + LayoutContent, + VStack, +} from "@astryxdesign/core/Layout"; +import { StatusDot } from "@astryxdesign/core/StatusDot"; +import { + Table, + pixel, + proportional, + type TableColumn, +} from "@astryxdesign/core/Table"; +import { Heading, Text } from "@astryxdesign/core/Text"; +import { ArrowPathIcon } from "@heroicons/react/24/outline"; + +import { + api, + type ComponentVersion, + type Service, +} from "../lib/api.ts"; + +// Mirror of the Vue dashboard's SystemStatusPage: service health plus +// per-component versions, in the dashboard template's frame. + +function uptime(startedAt: string, state: Service["state"]): string { + if (!startedAt || state === "down") return "not reported"; + const seconds = Math.max( + 0, + Math.round((Date.now() - Date.parse(startedAt)) / 1000), + ); + const days = Math.floor(seconds / 86400); + const hours = Math.floor((seconds % 86400) / 3600); + const minutes = Math.floor((seconds % 3600) / 60); + if (days) return `${days}d ${hours}h`; + if (hours) return `${hours}h ${minutes}m`; + return `${minutes}m`; +} + +const serviceVariant = { + up: "success", + degraded: "warning", + down: "error", + unknown: "neutral", +} as const; + +const versionVariant = { + ok: "success", + update_available: "warning", + drift: "error", + unknown: "neutral", +} as const; + +const versionLabel = { + ok: "Current", + update_available: "Update available", + drift: "Version drift", + unknown: "Unknown", +} as const; + +function MetricCard({ + label, + value, + caption, +}: { + label: string; + value: string; + caption: string; +}) { + return ( + + + {label} + {value} + + {caption} + + + + ); +} + +interface ServiceRow extends Record { + id: string; + service: string; + state: Service["state"]; + version: string; + uptime: string; + detail?: string; +} + +const serviceColumns: TableColumn[] = [ + { key: "service", header: "Service", width: proportional(1) }, + { + key: "state", + header: "State", + width: pixel(160), + renderCell: (item: ServiceRow) => ( + + + {item.state} + + ), + }, + { key: "version", header: "Version", width: pixel(120) }, + { key: "uptime", header: "Uptime", width: pixel(120) }, +]; + +interface VersionRow extends Record { + id: string; + component: string; + running: string; + latest: string; + status: ComponentVersion["status"]; +} + +const versionColumns: TableColumn[] = [ + { key: "component", header: "Component", width: proportional(1) }, + { key: "running", header: "Running", width: pixel(140) }, + { key: "latest", header: "Latest", width: pixel(140) }, + { + key: "status", + header: "State", + width: pixel(180), + renderCell: (item: VersionRow) => ( + + + {versionLabel[item.status]} + + ), + }, +]; + +export default function StatusPage() { + const [services, setServices] = useState([]); + const [components, setComponents] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + const load = useCallback(async () => { + setLoading(true); + setError(null); + try { + const [fetchedServices, report] = await Promise.all([ + api.services(), + api.version(), + ]); + setServices(fetchedServices); + setComponents(report.components); + } catch (err) { + setError(err instanceof Error ? err.message : "Could not load status"); + } finally { + setLoading(false); + } + }, []); + + useEffect(() => { + void load(); + }, [load]); + + const up = services.filter((s) => s.state === "up").length; + const attention = services.filter( + (s) => s.state === "degraded" || s.state === "down", + ).length; + const current = components.filter((c) => c.status === "ok").length; + + const serviceRows: ServiceRow[] = services.map((s) => ({ + id: `${s.service}/${s.instance_id}`, + service: s.service, + state: s.state, + version: s.version || "not reported", + uptime: uptime(s.started_at, s.state), + detail: s.detail, + })); + + const versionRows: VersionRow[] = components.map((c) => ({ + id: c.id, + component: c.label, + running: c.running_version || c.installed_claim || "not reported", + latest: c.latest_available || "not reported", + status: c.status, + })); + + return ( + + + + + System status +