import React, { useMemo, useState } from 'react'; import { Link } from 'wouter'; import { toast } from 'sonner'; import { emitProof } from '@workspace/a11oy-orchestration/client'; import { RELAY_DESTINATIONS, RELAY_MAPPINGS, RELAY_OUTCOMES, RELAY_POLICIES, RELAY_RUN_EVENTS, RELAY_SOURCES, RELAY_MODELS, AMARU_AGENTS, VERTICAL_PLAYBOOKS, } from '@/data/fabric'; import { buildApprovalQueue, buildCockpitKpis, calculateDestinationHealth, computeLutarSigma, rankSyncRisk, generateRecommendedAction, } from '@/lib/agentic'; import { ConduitGovernancePanels } from '../components/GovernancePanels'; import { FabricCard, FabricStat, GovernanceDot, HeatCell, MicroBar, SeverityChip, Sparkline, } from '@/components/fabric/primitives'; import { Badge, Button } from '@/components/ui'; import { INNOVATION_CAPABILITIES } from '@/data/innovation/competitive'; import { useStats, useConnections, useSyncs } from '@/lib/api-hooks'; import { AmaruHealthPanel } from '@/components/AmaruLive'; export default function Dashboard() { const liveStats = useStats(); const liveConnections = useConnections(); const liveSyncs = useSyncs(); const kpis = useMemo( () => buildCockpitKpis({ events: RELAY_RUN_EVENTS, destinations: RELAY_DESTINATIONS, mappings: RELAY_MAPPINGS, outcomes: RELAY_OUTCOMES, policies: RELAY_POLICIES }), [], ); const approvals = useMemo( () => buildApprovalQueue(RELAY_MAPPINGS, (mid) => { const m = RELAY_MODELS.find((mo) => mo.id === mid); return m ? RELAY_SOURCES.find((s) => s.id === m.sourceId) ?? null : null; }), [], ); const risk = useMemo(() => rankSyncRisk(RELAY_RUN_EVENTS).slice(0, 6), []); const sigma = useMemo( () => computeLutarSigma({ P: 0.92, K: RELAY_DESTINATIONS.reduce((s, d) => s + d.fieldContractStrength, 0) / RELAY_DESTINATIONS.length, phi: RELAY_MAPPINGS.reduce((s, m) => s + m.confidence, 0) / RELAY_MAPPINGS.length, C: kpis.failedRecords24h === 0 ? 1 : Math.max(0.5, 1 - kpis.failedRecords24h / Math.max(1, kpis.recordsActivated24h)), }), [kpis], ); const blockFeed = useMemo( () => RELAY_POLICIES.flatMap((p) => p.recentHits.map((h) => ({ ...h, policy: p }))) .sort((a, b) => (a.atIso < b.atIso ? 1 : -1)) .slice(0, 8), [], ); const throughput = useMemo(() => { const buckets = new Array(12).fill(0); const now = Date.now(); for (const e of RELAY_RUN_EVENTS) { if (e.type !== 'completed') continue; const idx = Math.floor((now - Date.parse(e.atIso)) / (60 * 60 * 1000)); if (idx >= 0 && idx < 12) buckets[11 - idx] += e.recordsAffected; } return buckets; }, []); const heat = useMemo(() => { const verticals = Array.from(new Set(RELAY_RUN_EVENTS.map((e) => e.verticalId))).slice(0, 7); const cats = Array.from(new Set(RELAY_DESTINATIONS.map((d) => d.category))); const grid: { vertical: string; category: string; count: number }[] = []; for (const v of verticals) { for (const c of cats) { const count = RELAY_RUN_EVENTS.filter( (e) => (e.type === 'failed' || e.type === 'rolled_back' || e.type === 'quarantined') && e.verticalId === v && RELAY_DESTINATIONS.find((d) => d.id === e.destinationId)?.category === c, ).length; grid.push({ vertical: v, category: c, count }); } } const max = Math.max(1, ...grid.map((g) => g.count)); return { verticals, cats, grid, max }; }, []); const [handoffPending, setHandoffPending] = useState(false); async function handoffToA11oy() { if (handoffPending) return; setHandoffPending(true); const refId = `amaru-cycle-${Date.now().toString(36)}`; try { const proof = await emitProof({ product: 'amaru', kind: 'action_executed', summary: `Amaru ouroboros cycle snapshot · ${kpis.activeSyncs} active syncs · LUTAR Σ ${(sigma.sigma * 100).toFixed(1)}%`, deepLink: '/conduit/', payload: { cycleRefId: refId, activeSyncs: kpis.activeSyncs, recordsActivated24h: kpis.recordsActivated24h, failedRecords24h: kpis.failedRecords24h, lutarSigma: sigma.sigma, }, }); toast.success(`Anchored to A11oy ledger · proof ${proof.id.slice(0, 12)}…`, { description: 'Inspect the cycle in A11oy → Conductor → Recent Proofs.', }); } catch (err) { toast.error('A11oy handoff failed', { description: (err as Error).message }); } finally { setHandoffPending(false); } } return (
{/* Hero */}
AMARU · COCKPIT

The Andean Ouroboros

Sovereign agentic activation. The serpent that holds the spine: discover sources, compose models, govern by policy, deliver with witness, and learn from outcomes — in one closed loop, replay-grade.

LUTAR Σ — LIVE
{(sigma.sigma * 100).toFixed(1)}%
{sigma.formula}
{([['P', sigma.axes.P], ['K', sigma.axes.K], ['Φ', sigma.axes.phi], ['C', sigma.axes.C]] as const).map(([label, val]) => (
{label}
{((val as number) * 100).toFixed(0)}
))}
{/* Live KPI tiles — wired to /api/conduit/* */} {liveStats.isError || liveConnections.isError || liveSyncs.isError ? (
Live API unreachable — showing fabric reference values. {' '}{(liveStats.error || liveConnections.error || liveSyncs.error)?.message}
) : null}
{liveStats.isLoading ? ( Array.from({ length: 8 }).map((_, i) => (
)) ) : liveStats.data ? ( <> 0 ? 'warn' : 'good'} /> = 0.95 ? 'good' : liveStats.data.successRate >= 0.8 ? 'warn' : 'bad'} /> ) : ( <> 5000 ? 'bad' : 'warn'} /> 4 ? 'warn' : 'good'} /> )}
{/* Live recent runs from /api/conduit/stats.recentRuns */} view all →} className="mb-6"> {liveStats.isLoading ? (
Loading recent runs…
) : liveStats.isError ? (
Failed to load: {liveStats.error?.message}
) : !liveStats.data || liveStats.data.recentRuns.length === 0 ? (
No runs yet. Create your first sync →
) : (
{liveStats.data.recentRuns.slice(0, 6).map((run) => (
{run.status} {run.syncName ?? run.syncId} {run.rowsWritten}/{run.rowsRead} rows {new Date(run.startedAt).toLocaleTimeString()}
))}
)}
{/* Activation flow */} } className="mb-6">
{[ { label: 'Sources', value: RELAY_SOURCES.length, href: '/sources' }, { label: 'Models', value: RELAY_MODELS.length, href: '/models' }, { label: 'Mappings', value: RELAY_MAPPINGS.length, href: '/mappings' }, { label: 'Destinations', value: RELAY_DESTINATIONS.length, href: '/destinations' }, { label: 'Outcomes', value: RELAY_OUTCOMES.length, href: '/outcomes' }, ].map((step, i, arr) => (
{String(i + 1).padStart(2, '0')} {arr.length - 1 === i ? '' : '↓'}
{step.value}
{step.label}
))}
{/* Top syncs at risk */}
{risk.map((r) => (
{r.syncName}
{r.health}
{r.drivers.join(' · ') || 'no recent issues'}
→ {generateRecommendedAction(r)}
))}
{/* Approval queue */} view all →}>
{approvals.slice(0, 6).map((a) => (
{a.syncName}
{a.reason}
{a.recordsImpacted.toLocaleString()} records · {a.verticalId}
))}
{/* Risk heatmap */}
Failures + rollbacks + quarantines (last events)
{heat.cats.map((c) =>
{c}
)} {heat.verticals.map((v) => (
{v}
{heat.cats.map((c) => { const cell = heat.grid.find((g) => g.vertical === v && g.category === c); return ; })}
))}
{/* Policy block feed */} view all →}>
{blockFeed.map((h, i) => (
{h.policy.name}
{h.outcome}
{h.summary}
{h.syncId} · {new Date(h.atIso).toLocaleTimeString()}
))}
{/* Destination health */} view all →}>
{RELAY_DESTINATIONS .map((d) => ({ d, h: calculateDestinationHealth(d, RELAY_RUN_EVENTS) })) .sort((a, b) => a.h - b.h) .slice(0, 7) .map(({ d, h }) => (
{d.name}
= 85 ? 'good' : h >= 70 ? 'warn' : 'bad'} />
{h}
))}
{/* Agent activity */} view all →}>
{AMARU_AGENTS.map((a) => (
{a.lutarAxisAffinity} {a.name}
b.recentDecisionCount))} tone="gold" />
{a.recentDecisionCount} {a.recentBlockCount}
))}
{/* Vertical playbooks */} {/* One-of-One Innovation Panel */} Full competitive brief →} >

Original capabilities assembled from field research across 10 public reverse ETL projects — re-implemented as A11oy-native, governed, proof-anchored primitives.

{INNOVATION_CAPABILITIES.map((cap) => (
{String(cap.number).padStart(2, '0')}
{cap.title}
{cap.tagline}
))}
); }