/** * Amaru — Codex Loop. * * Visible surface for the @workspace/codex-kernel: runs the Dresden Venus * reference loop in two postures (governance ON vs OFF) and shows the * hash-chained transitions, decision receipts, validator severities, and * a live replay verifier. * * This is the page where "what does replay-grade actually look like?" gets * answered with a button you can press. */ import { useMemo, useState } from 'react'; import { DRESDEN_DEFAULT_CONFIG, DRESDEN_INITIAL_STATE, type DresdenSimConfig, dresdenSteps, type KernelRunResult, replay, runLoop, serializeTraceJsonl, shortHash, type VenusState, } from '@workspace/codex-kernel'; import { Activity, CheckCircle2, ChevronRight, Download, PlayCircle, ShieldCheck, ShieldOff, XCircle, } from 'lucide-react'; interface RunBundle { result: KernelRunResult; jsonl: string; replayed: ReturnType; } function executeRun( cfg: DresdenSimConfig, governance_enabled: boolean, ): RunBundle { const result = runLoop({ experiment_id: 'E4', initial_state: DRESDEN_INITIAL_STATE, policy_version: 'covenant-v1', budgets: { time_budget_ms: 5_000, step_budget: 30, retry_budget: 0 }, loop_policy: { max_steps: 30, adaptive_depth: { enabled: false }, entropy_regularized_exit: { enabled: false }, }, governance_enabled, steps: dresdenSteps(cfg), }); const jsonl = serializeTraceJsonl(result.trace); const replayed = replay( DRESDEN_INITIAL_STATE, result.trace, result.summary.final_state_hash, ); return { result, jsonl, replayed }; } function severityChip(sev: 'pass' | 'soft_fail' | 'hard_fail') { if (sev === 'pass') return 'bg-emerald-500/10 text-emerald-300 border-emerald-500/30'; if (sev === 'soft_fail') return 'bg-amber-500/10 text-amber-300 border-amber-500/30'; return 'bg-rose-500/10 text-rose-300 border-rose-500/30'; } function downloadJsonl(jsonl: string, name: string) { const blob = new Blob([jsonl], { type: 'application/x-jsonlines' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = name; a.click(); URL.revokeObjectURL(url); } const SCENARIOS: Array<{ id: string; label: string; cfg: DresdenSimConfig }> = [ { id: 'stable', label: 'Stable (no drift)', cfg: { ...DRESDEN_DEFAULT_CONFIG, drift_per_cycle: 0, rows_to_emit: 8 }, }, { id: 'drift-corrected', label: 'Drift +1d/cycle (auto-correcting)', cfg: { ...DRESDEN_DEFAULT_CONFIG, drift_per_cycle: 1, rows_to_emit: 10, }, }, { id: 'runaway', label: 'Runaway drift +3d/cycle', cfg: { ...DRESDEN_DEFAULT_CONFIG, drift_per_cycle: 3, hard_threshold: 8, rows_to_emit: 8, }, }, ]; export default function CodexLoop() { const [scenarioId, setScenarioId] = useState('drift-corrected'); const scenario = useMemo( () => SCENARIOS.find((s) => s.id === scenarioId) ?? SCENARIOS[0], [scenarioId], ); const [runs, setRuns] = useState<{ on: RunBundle; off: RunBundle } | null>( null, ); const [selectedStep, setSelectedStep] = useState(null); const triggerRun = () => { const on = executeRun(scenario.cfg, true); const off = executeRun(scenario.cfg, false); setRuns({ on, off }); setSelectedStep(1); }; return (
Codex-Kernel · E4 · governed loop

Codex Loop — Dresden Venus reference run

A replay-grade governed iteration. Each step proposes a delta, gets validated, and — if it passes — appends a hash-chained entry to the proof ledger with a decision receipt. The Maya astronomers tracked Venus this way: idealized 584-day cycles plus explicit drift corrections. Toggle the governance posture to see what the kernel actually changes.

cycle_days={scenario.cfg.cycle_days} · drift/cycle= {scenario.cfg.drift_per_cycle} · warn={scenario.cfg.warning_threshold}{' '} · hard={scenario.cfg.hard_threshold}
{!runs && (
Press Run loop to execute the kernel and produce a hash-chained trace + replay attestation.
)} {runs && (
} bundle={runs.on} selectedStep={selectedStep} onSelectStep={setSelectedStep} filename={`dresden-${scenario.id}-governance-on.jsonl`} /> } bundle={runs.off} selectedStep={selectedStep} onSelectStep={setSelectedStep} filename={`dresden-${scenario.id}-governance-off.jsonl`} />
)} {runs && selectedStep !== null && ( )}
); } interface PostureCardProps { title: string; icon: React.ReactNode; bundle: RunBundle; selectedStep: number | null; onSelectStep: (step: number) => void; filename: string; } function PostureCard({ title, icon, bundle, selectedStep, onSelectStep, filename, }: PostureCardProps) { const { result, jsonl, replayed } = bundle; const summary = result.summary; return (
{icon}

{title}

status
{summary.status}
steps_executed
{summary.steps_executed}
hard_stop_failures
{summary.hard_stop_failures}
soft_failures
{summary.soft_failures}
stop_reason
{summary.stop_reason ?? '—'}
final_state_hash
{shortHash(summary.final_state_hash)}
replay
{replayed.ok ? ( ) : ( )} {replayed.ok ? `verified · ${replayed.steps_replayed} steps` : `failed at step ${replayed.failed_step}`}
{result.trace.map((event) => ( onSelectStep(event.step)} className={`cursor-pointer border-t border-border/40 hover:bg-muted/30 ${ selectedStep === event.step ? 'bg-primary/10' : '' }`} > ))}
step stage prev → next validators
{event.step} {event.pipeline_stage} {shortHash(event.state_prev_hash)} {shortHash(event.state_next_hash)}
{event.validator_results.map((v) => ( {v.name} ))}
); } interface ReceiptInspectorProps { bundle: RunBundle; step: number; } function ReceiptInspector({ bundle, step }: ReceiptInspectorProps) { const event = bundle.result.trace.find((e) => e.step === step); if (!event) return null; const receipt = event.decision_receipt; return (
Step {step} — decision receipt
{!receipt && (

(no receipt — terminal or trivial step)

)} {receipt && (

Summary

{receipt.summary}

Decision type

{receipt.decision_type}

Policy

{receipt.policy_version} · approval={receipt.approval_status} {receipt.mocked && ' · mocked'}

Assumptions

    {receipt.assumptions.map((a) => (
  • {a}
  • ))}

Evidence

    {receipt.evidence.map((ev, i) => (
  • {ev.kind}:{' '} {ev.ref} {ev.mocked && ( (mocked) )}
  • ))}
)}
); }