/** * AmaruLive — shared live-feed cards backed by the read-only Amaru sidecar * proxy (artifacts/api-server/src/routes/amaru-proxy.ts → services/amaru on * port 6810). Round 5 / T003 wires real upstream evidence into Conduit tabs. * * All endpoints are GET-only and read-only by doctrine. No mock data: if the * sidecar is unreachable we render an explicit "unavailable" surface; if it * returns an empty stream we render an explicit "no data yet" surface. */ import { useEffect, useState } from 'react'; type FetchState = | { kind: 'loading' } | { kind: 'error'; message: string; status?: number } | { kind: 'ok'; data: T }; function useAmaru(path: string, intervalMs = 15_000): FetchState { const [state, setState] = useState>({ kind: 'loading' }); useEffect(() => { let cancelled = false; async function tick() { try { const r = await fetch(path, { credentials: 'include' }); const text = await r.text(); if (!r.ok) { if (!cancelled) setState({ kind: 'error', status: r.status, message: text.slice(0, 240) }); return; } const data = JSON.parse(text) as T; if (!cancelled) setState({ kind: 'ok', data }); } catch (err) { if (!cancelled) setState({ kind: 'error', message: err instanceof Error ? err.message : String(err) }); } } void tick(); const id = window.setInterval(tick, intervalMs); return () => { cancelled = true; window.clearInterval(id); }; }, [path, intervalMs]); return state; } function Card({ title, source, children }: { title: string; source: string; children: React.ReactNode }) { return (
{title}
{source}
{children}
); } function ErrorBlock({ s }: { s: { status?: number; message: string } }) { return (
Amaru sidecar unavailable{s.status ? ` (HTTP ${s.status})` : ''}: {s.message || 'no detail'}
); } interface AmaruStatePayload { chakras?: string[]; last_evaluation?: Record; scheduler_ticks?: number; receipts?: number; bus?: { publishes?: number; failures?: number }; } // Snapshot view of the Amaru event bus. The sidecar's /events is a Server-Sent // Events stream and intentionally not proxied; /state exposes the same counters // as a point-in-time snapshot (publishes, failures, scheduler_ticks, receipts). export function AmaruEventsPanel() { const s = useAmaru('/api/amaru/state', 10_000); return ( {s.kind === 'loading' &&
Loading…
} {s.kind === 'error' && } {s.kind === 'ok' && (
publishes
{s.data.bus?.publishes ?? 0}
failures
{s.data.bus?.failures ?? 0}
scheduler_ticks
{s.data.scheduler_ticks ?? 0}
receipts
{s.data.receipts ?? 0}
{s.data.chakras && (
{s.data.chakras.map((c) => { const ev = s.data.last_evaluation?.[c]; return (
{c} {ev === null || ev === undefined ? 'no evaluation yet' : JSON.stringify(ev).slice(0, 240)}
); })}
)}
)}
); } interface WiringPayload { chakras: string[]; edges: { src: string; dst: string; role: string }[]; shape: string } export function AmaruWiringPanel() { const s = useAmaru('/api/amaru/scheduler/wiring'); return ( {s.kind === 'loading' &&
Loading…
} {s.kind === 'error' && } {s.kind === 'ok' && (
shape {s.data.shape} · {s.data.chakras.length} chakras · {s.data.edges.length} edges
{s.data.chakras.map((c) => ( {c} ))}
{s.data.edges.map((e, i) => (
{e.role} {e.src} {e.dst}
))}
)}
); } interface Tripwire { id: string; title: string; status: 'pass' | 'warn' | 'trip'; detail: string } interface TripwiresPayload { summary: { pass: number; warn: number; trip: number; total: number }; tripwires: Tripwire[] } const TRIP_TONE: Record = { pass: 'text-emerald-400 border-emerald-500/30 bg-emerald-500/10', warn: 'text-amber-400 border-amber-500/30 bg-amber-500/10', trip: 'text-red-400 border-red-500/30 bg-red-500/10', }; export function AmaruTripwiresPanel() { const s = useAmaru('/api/amaru/tripwires'); return ( {s.kind === 'loading' &&
Loading…
} {s.kind === 'error' && } {s.kind === 'ok' && ( <>
{s.data.summary.pass} PASS {s.data.summary.warn} WARN {s.data.summary.trip} TRIP · {s.data.summary.total} total
{s.data.tripwires.map((t) => (
{t.status} {t.id} {t.title} {t.detail}
))}
)}
); } interface Receipt { seq?: number; ts?: string | number; kind?: string; hash?: string; [k: string]: unknown } interface ReceiptsPayload { total: number; head_seq: number; items: Receipt[] } export function AmaruReceiptsPanel({ limit = 12 }: { limit?: number }) { const s = useAmaru(`/api/amaru/receipts?limit=${limit}`); return ( {s.kind === 'loading' &&
Loading…
} {s.kind === 'error' && } {s.kind === 'ok' && ( <>
head_seq {s.data.head_seq} · total {s.data.total}
{s.data.items.length === 0 ? (
No receipts yet — chain initialised, no signed runs recorded.
) : (
{s.data.items.slice(0, limit).map((r, i) => (
#{r.seq ?? i} {String(r.kind ?? '—')} {JSON.stringify(r).slice(0, 240)}
))}
)} )}
); } interface OverwatchPayload { panel_version?: string; thesis_kernel_hash?: string; thesis_brain_hash?: string; read_only?: boolean; summary?: Record } interface StatePayload { [k: string]: unknown } export function AmaruHealthPanel() { const s = useAmaru('/api/amaru/overwatch/snapshot', 30_000); const st = useAmaru('/api/amaru/state', 30_000); return ( {(s.kind === 'loading' || st.kind === 'loading') &&
Loading…
} {s.kind === 'error' && } {s.kind === 'ok' && (
panel {s.data.panel_version ?? '—'}
kernel {String(s.data.thesis_kernel_hash ?? '—').slice(0, 12)}
brain {String(s.data.thesis_brain_hash ?? '—').slice(0, 12)}
{s.data.summary && (
{s.data.summary.pass ?? 0} pass {s.data.summary.warn ?? 0} warn {s.data.summary.trip ?? 0} trip
)}
)} {st.kind === 'ok' && (
/state payload
{JSON.stringify(st.data, null, 2)}
)}
); }