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

241 lines
15 KiB
TypeScript

interface Evidence {
id: string;
status: string;
area: string;
check: string;
summary: string;
output: string;
cause: string;
}
interface Incident {
scope: string;
target: string;
title: string;
executionId: string;
evidence: Evidence[];
missingEvidence: string[];
nextCommand: string;
proposal: {
id: string;
status: string;
summary: string;
action: string;
riskLevel: string;
evidenceIds: string[];
preconditions: string[];
riskNotes: string[];
rollback: string;
validation: string[];
readyForApproval: boolean;
};
collectedAt: string;
}
interface Props {
laravelVersion: string;
view: {
available: boolean;
message: string;
incident: Incident;
};
}
const tone: Record<string, string> = {
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',
};
export default function IncidentPage({ laravelVersion, view }: Props) {
const incident = view.incident;
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-6xl 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>
<a href="/" className="text-xs text-cyan-300 hover:text-cyan-200">
← Homelab overview
</a>
<p className="mt-3 font-semibold tracking-tight">OpsProof incident evidence</p>
</div>
<span className="rounded-full border border-cyan-300/30 bg-cyan-300/10 px-3 py-1.5 text-xs text-cyan-200">
Read-only investigation
</span>
</header>
{!view.available ? (
<section className="mt-10 rounded-3xl border border-rose-300/20 bg-rose-300/[0.06] p-7">
<p className="text-xs uppercase tracking-[0.2em] text-rose-300">Evidence unavailable</p>
<h1 className="mt-3 text-2xl font-semibold text-white">Doctor could not complete this investigation</h1>
<p className="mt-3 max-w-2xl text-sm leading-6 text-slate-400">{view.message}</p>
<p className="mt-5 text-xs text-slate-500">
OpsProof does not reuse stale evidence and cannot submit a mitigation from this page.
</p>
</section>
) : (
<>
<section className="grid gap-6 py-10 lg:grid-cols-[1fr_auto] lg:items-end">
<div>
<p className="font-mono text-xs uppercase tracking-[0.2em] text-cyan-300">
{incident.scope} / {incident.target}
</p>
<h1 className="mt-3 text-3xl font-semibold tracking-tight text-white sm:text-5xl">
{incident.title || 'Focused Doctor investigation'}
</h1>
<p className="mt-4 max-w-3xl text-sm leading-6 text-slate-400">{view.message}</p>
</div>
<div className="rounded-xl border border-white/10 bg-white/[0.03] px-4 py-3 font-mono text-[11px] text-slate-500">
<p>EXECUTION {incident.executionId}</p>
<p className="mt-1">COLLECTED {incident.collectedAt}</p>
</div>
</section>
<section className="space-y-4">
{incident.evidence.map((evidence) => (
<article key={evidence.id} className="overflow-hidden rounded-2xl border border-white/10 bg-[#0a141e]/95">
<div className="flex flex-col gap-3 border-b border-white/10 px-5 py-4 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-center gap-3">
<span className="font-mono text-xs text-cyan-300">{evidence.id}</span>
<div>
<h2 className="font-medium text-white">{evidence.check}</h2>
<p className="mt-1 text-xs text-slate-500">{evidence.area}</p>
</div>
</div>
<span className={`w-fit rounded-md border px-2 py-1 text-[10px] uppercase ${tone[evidence.status] ?? tone.skip}`}>
{evidence.status}
</span>
</div>
<div className="grid gap-px bg-white/10 lg:grid-cols-2">
<div className="bg-[#0b1621] p-5">
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Desired state</p>
<p className="mt-2 text-sm text-slate-300">The declared check passes without warning or failure.</p>
<p className="mt-5 text-xs uppercase tracking-[0.18em] text-slate-600">Observed state</p>
<p className="mt-2 text-sm text-slate-300">{evidence.summary || 'No summary was returned.'}</p>
</div>
<div className="bg-[#0b1621] p-5">
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Root-cause hypothesis</p>
<p className="mt-2 text-sm leading-6 text-slate-400">
{evidence.cause || 'Doctor did not establish a supported cause from this evidence.'}
</p>
<p className="mt-2 text-[11px] text-amber-200/70">A hypothesis is not proof until deterministic validation succeeds.</p>
</div>
</div>
<div className="p-5">
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Command output excerpt</p>
<pre className="mt-3 max-h-80 overflow-auto whitespace-pre-wrap rounded-xl border border-white/8 bg-black/20 p-4 font-mono text-xs leading-5 text-slate-400">
{evidence.output || 'No detailed output was returned for this evidence row.'}
</pre>
</div>
</article>
))}
</section>
<section className="mt-6 grid gap-5 lg:grid-cols-2">
<div className="rounded-2xl border border-amber-300/20 bg-amber-300/[0.05] p-5">
<p className="text-xs uppercase tracking-[0.18em] text-amber-200">Missing evidence</p>
{incident.missingEvidence.length === 0 ? (
<p className="mt-3 text-sm text-slate-400">No empty deterministic evidence rows were detected.</p>
) : (
<ul className="mt-3 space-y-2 text-sm text-slate-400">
{incident.missingEvidence.map((item) => (
<li key={item}>• {item}</li>
))}
</ul>
)}
</div>
<div className="rounded-2xl border border-cyan-300/20 bg-cyan-300/[0.05] p-5">
<p className="text-xs uppercase tracking-[0.18em] text-cyan-200">Read-only next command</p>
<code className="mt-3 block overflow-x-auto rounded-lg bg-black/20 p-3 text-xs text-cyan-100">
{incident.nextCommand}
</code>
</div>
</section>
<section className="mt-6 overflow-hidden rounded-3xl border border-violet-300/20 bg-violet-300/[0.04]">
<div className="flex flex-col gap-4 border-b border-white/10 p-6 sm:flex-row sm:items-start sm:justify-between">
<div>
<p className="text-xs uppercase tracking-[0.18em] text-violet-200">Remediation proposal</p>
<h2 className="mt-2 text-xl font-semibold text-white">{incident.proposal.summary}</h2>
<p className="mt-2 font-mono text-[11px] text-slate-500">
{incident.proposal.id} · evidence {incident.proposal.evidenceIds.join(', ') || 'none'}
</p>
</div>
<div className="flex gap-2">
<span className="rounded-md border border-white/10 bg-white/[0.04] px-2 py-1 text-[10px] uppercase text-slate-300">
{incident.proposal.status}
</span>
<span className="rounded-md border border-rose-300/20 bg-rose-300/10 px-2 py-1 text-[10px] uppercase text-rose-200">
risk {incident.proposal.riskLevel}
</span>
</div>
</div>
<div className="grid gap-px bg-white/10 lg:grid-cols-2">
<div className="space-y-6 bg-[#0b1621] p-6">
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Proposed Jeannie action</p>
<code className="mt-3 block overflow-x-auto rounded-lg bg-black/20 p-3 text-xs text-violet-100">
{incident.proposal.action || 'No state-changing action proposed.'}
</code>
</div>
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Preconditions</p>
<ul className="mt-3 space-y-2 text-sm text-slate-400">
{incident.proposal.preconditions.map((item) => (
<li key={item}>• {item}</li>
))}
{incident.proposal.preconditions.length === 0 && <li>• No change is proposed.</li>}
</ul>
</div>
</div>
<div className="space-y-6 bg-[#0b1621] p-6">
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Risk review</p>
<ul className="mt-3 space-y-2 text-sm text-slate-400">
{incident.proposal.riskNotes.map((item) => (
<li key={item}>• {item}</li>
))}
{incident.proposal.riskNotes.length === 0 && <li>• No state-changing risk was introduced.</li>}
</ul>
</div>
<div>
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Rollback</p>
<p className="mt-3 text-sm leading-6 text-slate-400">{incident.proposal.rollback}</p>
</div>
</div>
</div>
<div className="border-t border-white/10 p-6">
<p className="text-xs uppercase tracking-[0.18em] text-slate-600">Deterministic validation</p>
<div className="mt-3 grid gap-2 sm:grid-cols-2">
{incident.proposal.validation.map((command) => (
<code key={command} className="overflow-x-auto rounded-lg bg-black/20 p-3 text-xs text-cyan-100">
{command}
</code>
))}
</div>
<button
type="button"
disabled={!incident.proposal.readyForApproval}
className="mt-5 w-full cursor-not-allowed rounded-lg bg-white/8 px-4 py-3 text-sm text-slate-500"
>
Approval unavailable until identity, authorization, and rollback controls exist
</button>
</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>Laravel Go {laravelVersion} · Jeannie evidence retained server-side.</span>
<span>Raw execution output is not exposed as an action surface.</span>
</footer>
</div>
</main>
);
}