my-homelab-configs/apps/opsproof/overlay/resources/js/pages/Welcome.tsx

358 lines
20 KiB
TypeScript

import { router } from '@inertiajs/react';
interface Props {
laravelVersion: string;
overview: Overview;
operator: Operator;
}
interface Operator {
authenticated: boolean;
name?: string;
email?: string;
role?: string;
}
interface StatusRow {
status: 'ok' | 'warn' | 'fail' | 'skip';
area: string;
check: string;
summary: string;
incidentPath?: string;
}
interface Overview {
available: boolean;
message: string;
title: string;
mode: string;
rows: StatusRow[];
cluster: {
profile: string;
runtime: string;
};
collectedAt: string;
}
const evidence = [
['Service', 'k3s.service', 'failed', 'ExecMainStatus=1'],
['Mount', '/var/lib/rancher/k3s', 'read-only', '/dev/sda1[/jeannie/k3s-runtime]'],
['Device', 'Pinned SSD', 'reappeared', 'UUID 19972338-9757-4f4b-89d7-c202df14a9aa'],
['Kernel', 'ext4', 'errors found', '__ext4_find_entry: reading directory'],
];
const stages = [
['01', 'Detect', 'Desired and observed state differ'],
['02', 'Explain', 'Evidence supports a stale read-only mount'],
['03', 'Approve', 'Guarded Jeannie repair awaits an operator'],
['04', 'Prove', 'Identity and readiness checks validate recovery'],
];
function Mark() {
return (
<div className="grid size-9 place-items-center rounded-xl bg-cyan-300 text-sm font-black text-slate-950 shadow-[0_0_28px_rgba(103,232,249,0.25)]">
OP
</div>
);
}
const statusTone = {
ok: 'border-emerald-300/20 bg-emerald-300/10 text-emerald-200',
warn: 'border-amber-300/20 bg-amber-300/10 text-amber-200',
fail: 'border-rose-300/20 bg-rose-300/10 text-rose-200',
skip: 'border-slate-500/20 bg-slate-500/10 text-slate-400',
};
function doctorCommand(row: StatusRow) {
if (row.area === 'Kubernetes apps') {
return `./jeannie doctor cluster ${row.check}`;
}
if (row.area.startsWith('Kubernetes')) {
return './jeannie doctor cluster';
}
if (row.area.startsWith('Orange Pi')) {
return './jeannie doctor opi5';
}
if (row.area.startsWith('RPi4')) {
return './jeannie doctor rpi';
}
if (row.area.startsWith('OCI edge')) {
return './jeannie doctor oci';
}
return './jeannie doctor debian';
}
function LiveOverview({ overview }: { overview: Overview }) {
const grouped = overview.rows.reduce<Record<string, StatusRow[]>>((areas, row) => {
(areas[row.area] ??= []).push(row);
return areas;
}, {});
const healthy = overview.rows.filter((row) => row.status === 'ok').length;
const attention = overview.rows.filter((row) => row.status === 'warn' || row.status === 'fail').length;
return (
<section className="mb-8 overflow-hidden rounded-3xl border border-white/10 bg-[#0a141e]/95 shadow-2xl shadow-black/30">
<div className="flex flex-col gap-4 border-b border-white/10 px-6 py-5 sm:flex-row sm:items-center sm:justify-between">
<div>
<p className="text-xs uppercase tracking-[0.2em] text-slate-500">Live read-only inventory</p>
<h2 className="mt-1 text-xl font-semibold text-white">Homelab operational overview</h2>
<p className="mt-2 text-sm text-slate-500">{overview.message}</p>
</div>
<a href="/" className="w-fit rounded-lg border border-white/10 px-3 py-2 text-xs text-slate-300 hover:border-cyan-300/40 hover:text-cyan-200">
Refresh evidence
</a>
</div>
{!overview.available ? (
<div className="p-6">
<div className="rounded-xl border border-rose-300/20 bg-rose-300/[0.06] p-5">
<p className="font-medium text-rose-200">Jeannie control plane unavailable</p>
<p className="mt-2 text-sm leading-6 text-slate-400">
OpsProof failed closed. No cached state is presented as current and no action can be submitted.
</p>
</div>
</div>
) : (
<>
<div className="grid gap-px border-b border-white/10 bg-white/10 sm:grid-cols-4">
<div className="bg-[#0b1621] p-5">
<p className="text-xs text-slate-500">Healthy checks</p>
<p className="mt-2 text-2xl font-semibold text-emerald-300">{healthy}</p>
</div>
<div className="bg-[#0b1621] p-5">
<p className="text-xs text-slate-500">Needs attention</p>
<p className="mt-2 text-2xl font-semibold text-amber-200">{attention}</p>
</div>
<div className="bg-[#0b1621] p-5">
<p className="text-xs text-slate-500">Cluster profile</p>
<p className="mt-2 font-mono text-sm text-cyan-200">{overview.cluster.profile || 'not selected'}</p>
</div>
<div className="bg-[#0b1621] p-5">
<p className="text-xs text-slate-500">Runtime</p>
<p className="mt-2 font-mono text-sm text-cyan-200">{overview.cluster.runtime || 'unknown'}</p>
</div>
</div>
<div className="grid gap-5 p-6 lg:grid-cols-2">
{Object.entries(grouped).map(([area, rows]) => (
<div key={area} className="rounded-2xl border border-white/8 bg-white/[0.02] p-4">
<div className="mb-3 flex items-center justify-between">
<h3 className="font-medium text-white">{area}</h3>
<span className="font-mono text-[11px] text-slate-600">{rows.length} checks</span>
</div>
<div className="space-y-2">
{rows.map((row) => (
<div key={`${row.area}-${row.check}`} className="rounded-xl border border-white/8 bg-[#071019] p-3">
<div className="flex items-start justify-between gap-3">
<div>
<p className="text-sm font-medium text-slate-200">{row.check}</p>
<p className="mt-1 text-xs text-slate-500">
Desired: declared intent satisfied
</p>
<p className="mt-1 text-xs text-slate-400">
Observed: {row.summary || row.status}
</p>
</div>
<span className={`rounded-md border px-2 py-1 text-[10px] uppercase ${statusTone[row.status]}`}>
{row.status}
</span>
</div>
{(row.status === 'warn' || row.status === 'fail') && (
<div className="mt-3 flex flex-col gap-2">
<code className="block overflow-x-auto rounded-md bg-white/[0.03] px-2 py-1.5 text-[11px] text-cyan-200">
{doctorCommand(row)}
</code>
{row.incidentPath && (
<a
href={row.incidentPath}
className="text-[11px] font-medium text-cyan-300 hover:text-cyan-200"
>
Open evidence →
</a>
)}
</div>
)}
</div>
))}
</div>
</div>
))}
</div>
<p className="border-t border-white/10 px-6 py-3 font-mono text-[10px] text-slate-600">
COLLECTED {overview.collectedAt || 'unknown'} · MODE {overview.mode || 'fast'} · bearer token retained server-side
</p>
</>
)}
</section>
);
}
function JeannieClient({ overview }: { overview: Overview }) {
return (
<section className="mb-8 grid gap-px overflow-hidden rounded-3xl border border-white/10 bg-white/10 lg:grid-cols-[1fr_1.4fr]">
<div className="bg-[#0b1621] p-6">
<p className="text-xs uppercase tracking-[0.2em] text-cyan-300">Jeannie client</p>
<h2 className="mt-2 text-xl font-semibold text-white">Server-side, authenticated, fail-closed</h2>
<p className="mt-3 text-sm leading-6 text-slate-400">
OpsProof calls Jeannie from Debian. The API address, bearer token, and raw private response never enter browser props.
</p>
</div>
<div className="grid gap-px bg-white/10 sm:grid-cols-3">
<div className="bg-[#0a141e] p-5">
<p className="text-xs text-slate-500">Connection</p>
<p className={`mt-2 text-sm font-medium ${overview.available ? 'text-emerald-300' : 'text-rose-300'}`}>
{overview.available ? 'Available' : 'Unavailable'}
</p>
</div>
<div className="bg-[#0a141e] p-5">
<p className="text-xs text-slate-500">Read operation</p>
<code className="mt-2 block text-xs text-cyan-200">status all --json</code>
</div>
<div className="bg-[#0a141e] p-5">
<p className="text-xs text-slate-500">Evidence time</p>
<p className="mt-2 font-mono text-xs text-slate-300">{overview.collectedAt || 'not collected'}</p>
</div>
</div>
</section>
);
}
export default function Welcome({ laravelVersion, overview, operator }: Props) {
return (
<main className="min-h-screen bg-[#071019] text-slate-100 selection:bg-cyan-300 selection:text-slate-950">
<div className="pointer-events-none fixed inset-0 bg-[radial-gradient(circle_at_15%_10%,rgba(34,211,238,0.10),transparent_25%),radial-gradient(circle_at_85%_20%,rgba(99,102,241,0.12),transparent_28%)]" />
<div className="relative mx-auto max-w-7xl px-5 py-6 sm:px-8 lg:px-10">
<header className="flex items-center justify-between border-b border-white/10 pb-5">
<div className="flex items-center gap-3">
<Mark />
<div>
<p className="font-semibold tracking-tight">OpsProof</p>
<p className="text-xs text-slate-500">Evidence before action</p>
</div>
</div>
<div className="flex items-center gap-3 text-xs">
{operator.authenticated ? (
<button
type="button"
onClick={() => router.post('/logout')}
className="rounded-full border border-white/10 px-3 py-1.5 text-slate-300 hover:border-cyan-300/40 hover:text-cyan-200"
>
{operator.name} · sign out
</button>
) : (
<a href="/login" className="rounded-full border border-cyan-300/30 px-3 py-1.5 text-cyan-200 hover:bg-cyan-300/10">
Operator sign in
</a>
)}
<span className="hidden rounded-full border border-cyan-300/30 bg-cyan-300/10 px-3 py-1.5 text-cyan-200 sm:inline">
Read-only live view
</span>
<span className={`rounded-full border px-3 py-1.5 ${overview.available ? 'border-emerald-300/30 bg-emerald-300/10 text-emerald-200' : 'border-rose-300/30 bg-rose-300/10 text-rose-200'}`}>
Control plane {overview.available ? 'available' : 'unavailable'}
</span>
</div>
</header>
<section className="grid gap-8 py-12 lg:grid-cols-[1.05fr_0.95fr] lg:items-end">
<div>
<p className="mb-4 font-mono text-xs uppercase tracking-[0.24em] text-cyan-300">
AI-assisted operations · human-approved repair
</p>
<h1 className="max-w-3xl text-4xl font-semibold leading-[1.05] tracking-[-0.04em] text-white sm:text-6xl">
Turn infrastructure incidents into{' '}
<span className="text-cyan-300">provable outcomes.</span>
</h1>
<p className="mt-6 max-w-2xl text-base leading-7 text-slate-400 sm:text-lg">
OpsProof combines desired state, live evidence, cited AI reasoning, guarded Jeannie
automation, and post-change validation in one auditable workflow.
</p>
</div>
<div className="grid grid-cols-2 gap-px overflow-hidden rounded-2xl border border-white/10 bg-white/10">
{stages.map(([number, title, detail]) => (
<div key={number} className="bg-[#0b1621] p-5">
<p className="font-mono text-xs text-cyan-300">{number}</p>
<p className="mt-4 font-semibold text-white">{title}</p>
<p className="mt-1 text-xs leading-5 text-slate-500">{detail}</p>
</div>
))}
</div>
</section>
<JeannieClient overview={overview} />
<LiveOverview overview={overview} />
<section className="overflow-hidden rounded-3xl border border-white/10 bg-[#0a141e]/95 shadow-2xl shadow-black/30">
<div className="flex flex-col gap-4 border-b border-white/10 px-6 py-5 sm:flex-row sm:items-center sm:justify-between">
<div>
<p className="text-xs uppercase tracking-[0.2em] text-slate-500">Sanitized incident scenario · OP-0001</p>
<h2 className="mt-1 text-xl font-semibold text-white">Orange Pi K3s storage became read-only</h2>
</div>
<div className="flex items-center gap-2">
<span className="rounded-full bg-rose-400/10 px-3 py-1.5 text-xs font-medium text-rose-300">High impact</span>
<span className="rounded-full bg-cyan-400/10 px-3 py-1.5 text-xs font-medium text-cyan-200">4 evidence checks</span>
</div>
</div>
<div className="grid lg:grid-cols-[1.15fr_0.85fr]">
<div className="border-b border-white/10 p-6 lg:border-b-0 lg:border-r">
<div className="mb-5 flex items-center justify-between">
<h3 className="font-medium text-white">Command-backed evidence</h3>
<span className="font-mono text-[11px] text-slate-600">COLLECTED 14:08:31Z</span>
</div>
<div className="space-y-3">
{evidence.map(([kind, subject, state, proof]) => (
<div key={`${kind}-${subject}`} className="grid gap-3 rounded-xl border border-white/8 bg-white/[0.025] p-4 sm:grid-cols-[90px_1fr_auto] sm:items-center">
<span className="font-mono text-[11px] uppercase tracking-wider text-slate-600">{kind}</span>
<div>
<p className="text-sm font-medium text-slate-200">{subject}</p>
<p className="mt-1 truncate font-mono text-[11px] text-slate-500">{proof}</p>
</div>
<span className="w-fit rounded-md bg-rose-400/10 px-2 py-1 text-[11px] text-rose-300">{state}</span>
</div>
))}
</div>
</div>
<aside className="p-6">
<p className="text-xs uppercase tracking-[0.2em] text-slate-500">Diagnosis</p>
<h3 className="mt-3 text-lg font-semibold text-white">Stale mount points to a disappeared device</h3>
<p className="mt-3 text-sm leading-6 text-slate-400">
The SSD reappeared under a new device name. Recovery must prove its pinned K3s CA before
replacing the stale mount; device names alone are not trusted.
</p>
<div className="mt-6 rounded-xl border border-cyan-300/20 bg-cyan-300/[0.06] p-4">
<p className="text-xs font-medium uppercase tracking-wider text-cyan-200">Guarded proposal</p>
<code className="mt-3 block overflow-x-auto text-xs text-cyan-100">
./jeannie doctor opi5 --repair-k3s
</code>
<ul className="mt-4 space-y-2 text-xs leading-5 text-slate-400">
<li>• Verify the disk against the pinned cluster CA</li>
<li>• Refuse busy mounts instead of forcing unmount</li>
<li>• Validate cluster identity and node readiness</li>
</ul>
</div>
<a
href="/incidents/opi5/k3s-storage"
className="mt-5 flex w-full items-center justify-center rounded-xl bg-cyan-300 px-4 py-3 text-sm font-semibold text-slate-950 hover:bg-cyan-200"
>
Open live SSD evidence
</a>
<p className="mt-3 text-center text-[11px] text-slate-600">
Live evidence is recollected before proposal, approval, and execution
</p>
</aside>
</div>
</section>
<footer className="flex flex-col gap-2 py-8 text-xs text-slate-600 sm:flex-row sm:items-center sm:justify-between">
<span>Built with Laravel Go {laravelVersion}, Inertia, React, TypeScript, Jeannie, and OpenTelemetry.</span>
<span>Diagnosis is a hypothesis until deterministic validation passes.</span>
</footer>
</div>
</main>
);
}