import { useEffect, useRef } from 'react'; import { motion } from 'framer-motion'; import { useSimulationState } from '../../store/simulationStore'; const GAUGES = [ { key: 'ram', label: 'RAM', unit: 'MB', max: 900, thresholds: { warn: 700, crit: 860 } }, { key: 'vram', label: 'VRAM', unit: 'MB', max: 500, thresholds: { warn: 380, crit: 480 } }, { key: 'cpu', label: 'CPU', unit: '%', max: 100, thresholds: { warn: 50, crit: 80 } }, ]; function getGaugeColor(value, thresholds) { if (value >= thresholds.crit) return { bar: 'bg-red-500', text: 'text-red-400' }; if (value >= thresholds.warn) return { bar: 'bg-amber-500', text: 'text-amber-400' }; return { bar: 'bg-emerald-500', text: 'text-emerald-400' }; } const STATUS_MAP = { idle: { label: 'IDLE', color: 'bg-zinc-500', pulse: false }, running: { label: 'RUNNING', color: 'bg-emerald-500', pulse: true }, warning: { label: 'WARNING', color: 'bg-amber-500', pulse: true }, critical: { label: 'CRITICAL', color: 'bg-red-500', pulse: true }, stable: { label: 'STABLE', color: 'bg-emerald-500', pulse: false }, }; // Tag → colour mapping for structured think lines const TAG_COLOURS = { '[STATE]': 'text-sky-400', '[METRICS]': 'text-violet-400', '[CONSTRAINT]': 'text-amber-400', '[ANALYSIS]': 'text-zinc-300', '[DECISION]': 'text-emerald-400', }; /** Render a single line of a think block with tag colouring */ function ThinkLine({ line }) { const trimmed = line.trimStart(); const matchedTag = Object.keys(TAG_COLOURS).find(t => trimmed.startsWith(t)); if (matchedTag) { const rest = trimmed.slice(matchedTag.length); return (
{matchedTag} {rest}
); } // Indented continuation lines (options / sub-points) return (
{trimmed || '\u00a0'}
); } export default function DockerPhysicsMonitor() { const { telemetry, preflight, validatorRuntime, lastValidatorResult, reasoningTrace } = useSimulationState(); const traceEndRef = useRef(null); const isCritical = telemetry.containerStatus === 'critical'; const runtime = validatorRuntime || telemetry.validator_runtime || {}; const validatorStatus = lastValidatorResult?.status || telemetry.last_validator_status || 'n/a'; const isPass = validatorStatus === 'PASS' || validatorStatus === 'pass'; const validatorLabel = lastValidatorResult?.validation_label || runtime.label || 'Docker Sandbox'; const validatorMode = lastValidatorResult?.validation_mode || runtime.mode || 'Strict VRAM Enforcement'; const validatorDetail = lastValidatorResult?.validator_detail || telemetry.validator_detail || runtime.detail || 'Remediation executed within 500MB VRAM limit.'; // Lock telemetry to verified sandbox result on PASS const resolvedTelemetry = { ...telemetry, vram: isPass ? (lastValidatorResult?.vram_peak_mb || 295) : telemetry.vram, cpu: isPass ? 2 : telemetry.cpu, }; // Auto-scroll to bottom on new trace entries useEffect(() => { traceEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [reasoningTrace.length]); return (
{/* ── Live Sandbox Telemetry ── */}
Live Sandbox Telemetry {GAUGES.map((gauge) => { const value = typeof resolvedTelemetry[gauge.key] === 'number' ? resolvedTelemetry[gauge.key] : 0; const pct = Math.min((value / gauge.max) * 100, 100); const colors = getGaugeColor(value, gauge.thresholds); return (
{gauge.label} {value.toFixed(0)}{gauge.unit}
); })}
{/* ── VRAM Reasoning Trace (think stream) ── */}
VRAM Math {reasoningTrace.length > 0 ? `${reasoningTrace.length} steps` : 'awaiting run…'}
{/* Terminal window */}
{/* Chrome bar — no live badge, neutral */}
<think> stream
{/* Scrollable think log */}
{reasoningTrace.length === 0 ? (

The model's VRAM reasoning will appear here as it evaluates each step against the 500MB sandbox limit…

) : ( reasoningTrace.map((entry) => (
{/* Entry header: timestamp + agent */}
{entry.ts} {entry.agent}
{/* Render each line of the think block */} {entry.text.split('\n').map((line, i) => ( ))}
)) )}
{/* ── Validator Runtime ── */}
Validator Runtime
{/* ── Pre-Flight Check ── */}
Pre-Flight Check
); } function ContainerStatusBadge({ status }) { const info = STATUS_MAP[status] || STATUS_MAP.idle; return (
{info.label}
); } function PreFlightItem({ label, status }) { const icon = status === null ? '○' : status ? '✓' : '✗'; const color = status === null ? 'text-zinc-600' : status ? 'text-emerald-400' : 'text-red-400'; return (
{icon} {label}
); } function InfoRow({ label, value, valueClass = 'text-zinc-200' }) { return (
{label} {value}
); }