/** * XIC Pipeline Monitor - Real-time Telemetry Dashboard * Subscribes to FedMart telemetry feed and renders live pipeline state */ class XICMonitor { constructor() { this.ws = null; this.telemetryBuffer = []; this.currentRun = null; this.glyphs = new Map(); // glyph_id → metrics this.specStatus = {}; this.isConnected = false; this.connectBtn = document.getElementById('connectBtn'); this.runStatusEl = document.getElementById('runStatus'); this.timelineContent = document.getElementById('timelineContent'); this.stepCountEl = document.getElementById('stepCount'); this.execTimeEl = document.getElementById('execTime'); this.heatmapCanvas = document.getElementById('heatmapCanvas'); this.glyphDetailsEl = document.getElementById('glyphDetails'); this.glyphSelect = document.getElementById('glyphSelect'); this.inspectorContent = document.getElementById('inspectorContent'); this.guardrailList = document.getElementById('guardrailList'); this.pauseBtn = document.getElementById('pauseBtn'); this.throttleBtn = document.getElementById('throttleBtn'); this.specStatusEl = document.getElementById('specStatus'); this.initEventListeners(); this.initCanvas(); } initEventListeners() { this.connectBtn.addEventListener('click', () => this.connectToFeed()); this.glyphSelect.addEventListener('change', (e) => this.showGlyphMetrics(e.target.value)); this.pauseBtn.addEventListener('click', () => this.pauseRun()); this.throttleBtn.addEventListener('click', () => this.throttleRun()); } initCanvas() { this.ctx = this.heatmapCanvas.getContext('2d'); this.drawHeatmapPlaceholder(); } connectToFeed() { const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; const wsUrl = `${protocol}://${window.location.host}/ws/fedmart/xic`; console.log(`[XIC] Connecting to ${wsUrl}`); this.connectBtn.disabled = true; this.connectBtn.textContent = 'Connecting...'; this.ws = new WebSocket(wsUrl); this.ws.onopen = () => { console.log('[XIC] WebSocket connected'); this.setStatus('Connected', 'active'); this.connectBtn.textContent = 'Connected ✓'; this.isConnected = true; }; this.ws.onmessage = (event) => { try { const telemetry = JSON.parse(event.data); this.processTelemetry(telemetry); } catch (e) { console.error('[XIC] Failed to parse telemetry:', e); } }; this.ws.onerror = (error) => { console.error('[XIC] WebSocket error:', error); this.setStatus('Connection Error', 'error'); this.connectBtn.textContent = 'Reconnect'; this.connectBtn.disabled = false; this.isConnected = false; }; this.ws.onclose = () => { console.log('[XIC] WebSocket closed'); this.setStatus('Disconnected', 'error'); this.connectBtn.textContent = 'Connect to Feed'; this.connectBtn.disabled = false; this.isConnected = false; }; } processTelemetry(telemetry) { this.telemetryBuffer.push(telemetry); this.currentRun = telemetry; // Update timeline this.renderTimeline(telemetry); // Update glyph data if (telemetry.resonance_map_summary && telemetry.resonance_map_summary.top_glyphs) { this.updateGlyphData(telemetry.resonance_map_summary.top_glyphs); this.populateGlyphSelector(telemetry.glyph_ids || []); } // Update heatmap if (telemetry.resonance_map_summary && telemetry.resonance_map_summary.top_glyphs) { this.renderHeatmap(telemetry.resonance_map_summary.top_glyphs, telemetry.global_resonance_score); } // Update guardrails if (telemetry.guardrails_triggered && telemetry.guardrails_triggered.length > 0) { this.showGuardrailAlerts(telemetry.guardrails_triggered); } else { this.clearGuardrailAlerts(); } // Update spec status if available if (telemetry.spec_status) { this.updateSpecStatus(telemetry.spec_status); } // Update control button states this.updateControlButtons(telemetry); } renderTimeline(telemetry) { // Clear existing timeline this.timelineContent.innerHTML = ''; // Parse steps from telemetry const steps = []; const rawPayload = telemetry.raw_payload || {}; // Add initial step if (telemetry.program) { steps.push({ name: `Program: ${telemetry.program}`, kind: 'program', timestamp: telemetry.timestamp, }); } // Add chain label if present if (telemetry.chain_label) { steps.push({ name: `Chain: ${telemetry.chain_label}`, kind: 'chain', timestamp: telemetry.timestamp, }); } // Add multi-glyph resonance step if glyphs present if (telemetry.glyph_count > 0) { steps.push({ name: `Multi-Glyph Resonance (${telemetry.glyph_count} glyphs)`, kind: 'glyph', timestamp: telemetry.timestamp, }); } // Add guardrail step if triggered if (telemetry.guardrails_triggered && telemetry.guardrails_triggered.length > 0) { steps.push({ name: `Guardrail: ${telemetry.guardrails_triggered[0]}`, kind: 'guardrail', timestamp: telemetry.timestamp, }); } // Add fusion step if fused symbol present if (rawPayload.fused_symbol_summary) { steps.push({ name: 'Fusion', kind: 'fused_symbol', timestamp: telemetry.timestamp, }); } // Render steps if (steps.length === 0) { this.timelineContent.innerHTML = '
No execution steps
'; } else { steps.forEach((step) => { const stepEl = document.createElement('div'); stepEl.className = `timeline-step ${step.kind}`; stepEl.innerHTML = `${step.name}`; this.timelineContent.appendChild(stepEl); }); } // Update metadata this.stepCountEl.textContent = `Steps: ${steps.length}`; this.execTimeEl.textContent = `Time: ${telemetry.steps_executed * 10}ms`; // Estimate } updateGlyphData(topGlyphs) { this.glyphs.clear(); topGlyphs.forEach((glyph) => { this.glyphs.set(glyph.glyph_id, { weight: glyph.weight, id: glyph.glyph_id, }); }); // Update glyph details this.renderGlyphDetails(topGlyphs); } renderGlyphDetails(topGlyphs) { this.glyphDetailsEl.innerHTML = ''; if (topGlyphs.length === 0) { this.glyphDetailsEl.innerHTML = 'No glyph data
'; return; } topGlyphs.forEach((glyph) => { const itemEl = document.createElement('div'); itemEl.className = 'glyph-item'; const percentage = (glyph.weight * 100).toFixed(1); itemEl.innerHTML = ` ${glyph.glyph_id}: ${percentage}% `; this.glyphDetailsEl.appendChild(itemEl); }); } populateGlyphSelector(glyphIds) { const currentValue = this.glyphSelect.value; this.glyphSelect.innerHTML = ''; glyphIds.forEach((id) => { const option = document.createElement('option'); option.value = id; option.textContent = id; this.glyphSelect.appendChild(option); }); // Restore previous selection if still available if (currentValue && glyphIds.includes(currentValue)) { this.glyphSelect.value = currentValue; } } showGlyphMetrics(glyphId) { if (!glyphId || !this.glyphs.has(glyphId)) { this.inspectorContent.innerHTML = 'Select a glyph to view metrics...
'; return; } const glyph = this.glyphs.get(glyphId); this.inspectorContent.innerHTML = `No guardrails triggered
'; this.pauseBtn.disabled = true; this.throttleBtn.disabled = true; } updateControlButtons(telemetry) { const hasGuardrails = telemetry.guardrails_triggered && telemetry.guardrails_triggered.length > 0; if (hasGuardrails) { this.pauseBtn.disabled = false; this.throttleBtn.disabled = false; } } updateSpecStatus(specMap) { this.specStatusEl.innerHTML = ''; Object.entries(specMap).forEach(([instruction, status]) => { const entryEl = document.createElement('div'); entryEl.className = `spec-entry ${status.status}`; entryEl.innerHTML = `