mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-06 19:13:55 +01:00
642 lines
44 KiB
Python
642 lines
44 KiB
Python
"""Escaped, dependency-free presentation for the Neuron Lab observatory."""
|
||
|
||
from __future__ import annotations
|
||
|
||
from collections.abc import Mapping
|
||
from html import escape
|
||
import math
|
||
|
||
|
||
LAB_CSS = """
|
||
#neuron-lab {
|
||
--nl-bg: #070914; --nl-panel: #101125; --nl-raised: #1b1b35;
|
||
--nl-line: #36334f; --nl-quiet-line: #25253c; --nl-ink: #eef3ff;
|
||
--nl-muted: #aeb7ce; --nl-dim: #8993ae; --nl-amber: #ffc064;
|
||
--nl-cyan: #79d4db; --nl-violet: #b59aff; --nl-ice: #eef3ff; --nl-red: #f49aab;
|
||
--nl-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||
--nl-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
|
||
--body-text-color: #eef3ff; --body-text-color-subdued: #aeb7ce;
|
||
--body-background-fill: #070914; --background-fill-primary: #101125;
|
||
--background-fill-secondary: #1b1b35; --block-background-fill: #101125;
|
||
--block-border-color: #36334f; --block-label-text-color: #eef3ff;
|
||
--block-title-text-color: #eef3ff; --input-background-fill: #0a0d1d;
|
||
--input-text-color: #eef3ff; --input-placeholder-color: #8993ae;
|
||
--input-border-color: #36334f; --border-color-primary: #36334f;
|
||
--color-accent: #b59aff; --color-accent-soft: #b59aff16;
|
||
background: radial-gradient(ellipse at 66% 0%, #30205b60 0%, transparent 39%), radial-gradient(ellipse at 3% 54%, #103e4f20 0%, transparent 36%), var(--nl-bg) !important;
|
||
color: var(--nl-ink) !important;
|
||
border: 1px solid #7970c845 !important; border-radius: 20px !important;
|
||
padding: 24px !important; gap: 20px !important; isolation: isolate;
|
||
font-family: var(--nl-sans) !important; color-scheme: dark;
|
||
box-shadow: inset 0 1px #d8caff0b, 0 0 70px #5d31a008;
|
||
}
|
||
#neuron-lab *, #neuron-lab *::before, #neuron-lab *::after { box-sizing: border-box; }
|
||
#neuron-lab .block { padding-left: 0 !important; box-shadow: none !important; }
|
||
#neuron-lab .block::before { display: none !important; }
|
||
#neuron-lab .html-container { padding: 0 !important; }
|
||
#neuron-lab .prose, #neuron-lab .prose * { color: var(--nl-muted); font-family: var(--nl-sans); }
|
||
#neuron-lab .prose h3, #neuron-lab .prose h4 { color: var(--nl-ink); letter-spacing: -.02em; }
|
||
#neuron-lab .nl-panel {
|
||
background: linear-gradient(145deg, #1b1933ab, #101425c9) !important;
|
||
border: 1px solid #8f84cc34 !important; backdrop-filter: blur(18px);
|
||
border-radius: 13px !important; padding: 18px !important; gap: 16px !important;
|
||
box-shadow: inset 0 1px #d4c6ff0b, 0 12px 30px #02030c38 !important;
|
||
}
|
||
#neuron-lab .nl-control-rack { gap: 16px !important; min-width: 0 !important; }
|
||
#neuron-lab .nl-workbench { gap: 18px !important; min-width: 0 !important; }
|
||
#neuron-lab .nl-toolbar { gap: 9px !important; align-items: center !important; }
|
||
#neuron-lab .nl-toolbar > * { min-width: 100px !important; }
|
||
#neuron-lab .nl-mode { border-bottom: 1px solid var(--nl-line) !important; }
|
||
#neuron-lab .nl-mode button, #neuron-lab button.tab-nav {
|
||
color: var(--nl-muted) !important; text-transform: none !important;
|
||
letter-spacing: 0 !important; font: 600 13px var(--nl-sans) !important;
|
||
border: 0 !important; border-radius: 0 !important; background: transparent !important;
|
||
}
|
||
#neuron-lab .nl-mode button.selected, #neuron-lab button.tab-nav.selected {
|
||
color: var(--nl-violet) !important; border-bottom: 2px solid var(--nl-violet) !important;
|
||
background: #b59aff0b !important; text-shadow: 0 0 18px #a886ff35;
|
||
}
|
||
#neuron-lab input, #neuron-lab textarea, #neuron-lab select {
|
||
color: var(--nl-ink) !important; background: #090d1cd9 !important;
|
||
border: 1px solid var(--nl-line) !important; border-radius: 7px !important;
|
||
font: 400 13px/1.55 var(--nl-sans) !important; text-shadow: none !important;
|
||
box-shadow: none !important; caret-color: var(--nl-violet) !important;
|
||
}
|
||
#neuron-lab input:focus, #neuron-lab textarea:focus, #neuron-lab select:focus {
|
||
border-color: var(--nl-violet) !important; outline: 2px solid #b59aff30 !important;
|
||
outline-offset: 2px !important; box-shadow: none !important;
|
||
}
|
||
#neuron-lab input[type="checkbox"], #neuron-lab input[type="radio"],
|
||
#neuron-lab input[type="range"] { accent-color: var(--nl-violet) !important; }
|
||
#neuron-lab input[type="checkbox"], #neuron-lab input[type="radio"] {
|
||
appearance: none !important; position: relative !important; flex-shrink: 0;
|
||
width: 15px !important; height: 15px !important; padding: 0 !important;
|
||
background-image: none !important; border-color: #747b85 !important; cursor: pointer;
|
||
}
|
||
#neuron-lab input[type="checkbox"] { border-radius: 4px !important; }
|
||
#neuron-lab input[type="radio"] { border-radius: 50% !important; }
|
||
#neuron-lab input[type="checkbox"]:checked, #neuron-lab input[type="radio"]:checked {
|
||
background-color: var(--nl-violet) !important; background-image: none !important;
|
||
border-color: var(--nl-violet) !important;
|
||
}
|
||
#neuron-lab input[type="checkbox"]:checked::after {
|
||
content: ""; position: absolute; left: 50%; top: 46%; width: 5px; height: 9px;
|
||
border: solid #100c20; border-width: 0 2px 2px 0; background: transparent;
|
||
transform: translate(-50%, -50%) rotate(45deg);
|
||
}
|
||
#neuron-lab input[type="radio"]:checked::after {
|
||
content: ""; position: absolute; left: 50%; top: 50%; width: 5px; height: 5px;
|
||
border: 0; border-radius: 50%; background-color: #100c20 !important;
|
||
transform: translate(-50%, -50%);
|
||
}
|
||
#neuron-lab input[type="checkbox"]:focus-visible, #neuron-lab input[type="radio"]:focus-visible {
|
||
outline: 2px solid var(--nl-cyan) !important; outline-offset: 3px !important;
|
||
}
|
||
#neuron-lab label:has(input[type="radio"]:checked) {
|
||
border-color: #7661b3 !important; background-color: #b59aff12 !important;
|
||
}
|
||
#neuron-lab input[type="range"] {
|
||
--slider-color: var(--nl-violet) !important;
|
||
background: transparent !important; border: 0 !important; padding: 0 !important;
|
||
}
|
||
#neuron-lab input[type="range"]::-webkit-slider-runnable-track {
|
||
background: linear-gradient(to right, var(--nl-violet) var(--range_progress, 0%), var(--nl-line) var(--range_progress, 0%)) !important;
|
||
}
|
||
#neuron-lab input[type="range"]::-webkit-slider-thumb {
|
||
background-color: var(--nl-violet) !important; box-shadow: 0 0 0 2px #0b0d10 !important;
|
||
}
|
||
#neuron-lab input[type="range"]::-moz-range-track { background: var(--nl-line) !important; }
|
||
#neuron-lab input[type="range"]::-moz-range-progress { background-color: var(--nl-violet) !important; }
|
||
#neuron-lab input[type="range"]::-moz-range-thumb {
|
||
background-color: var(--nl-violet) !important; box-shadow: 0 0 0 2px #0b0d10 !important;
|
||
}
|
||
#neuron-lab label, #neuron-lab label span, #neuron-lab .block-label, #neuron-lab .block-title {
|
||
color: var(--nl-ink) !important; text-transform: none !important;
|
||
font-family: var(--nl-sans) !important; letter-spacing: 0 !important;
|
||
font-size: 12px !important; font-weight: 550 !important;
|
||
}
|
||
#neuron-lab .info { color: var(--nl-dim) !important; font-size: 11px !important; line-height: 1.5; }
|
||
#neuron-lab .wrap, #neuron-lab .form, #neuron-lab .container {
|
||
border-color: var(--nl-line) !important; background-color: transparent !important;
|
||
}
|
||
#neuron-lab .options, #neuron-lab .options-container { background: var(--nl-raised) !important; }
|
||
#neuron-lab button.nl-primary, #neuron-lab .nl-primary button {
|
||
background: linear-gradient(110deg, #c4adff, #a6baff) !important; color: #100c20 !important;
|
||
border: 1px solid #e0d4ff85 !important; border-radius: 8px !important;
|
||
font: 700 12px/1.3 var(--nl-sans) !important; text-transform: none !important;
|
||
letter-spacing: .01em !important; padding: 12px 16px !important;
|
||
text-shadow: none !important; box-shadow: 0 0 24px #a17bff1f !important;
|
||
}
|
||
#neuron-lab button.nl-primary:hover, #neuron-lab .nl-primary button:hover {
|
||
background: #d4c5ff !important; border-color: #d4c5ff !important; transform: translateY(-1px);
|
||
}
|
||
#neuron-lab button.nl-secondary, #neuron-lab .nl-secondary button,
|
||
#neuron-lab button.nl-quiet, #neuron-lab .nl-quiet button,
|
||
#neuron-lab button.nl-danger, #neuron-lab .nl-danger button {
|
||
background: var(--nl-raised) !important; color: var(--nl-ink) !important;
|
||
border: 1px solid #4a4267 !important; border-radius: 8px !important;
|
||
font: 600 12px/1.3 var(--nl-sans) !important; text-transform: none !important;
|
||
letter-spacing: 0 !important; padding: 11px 14px !important;
|
||
text-shadow: none !important; box-shadow: none !important;
|
||
}
|
||
#neuron-lab button.nl-quiet, #neuron-lab .nl-quiet button { background: transparent !important; color: var(--nl-muted) !important; }
|
||
#neuron-lab button.nl-danger, #neuron-lab .nl-danger button { color: var(--nl-red) !important; border-color: #633e37 !important; }
|
||
#neuron-lab button.nl-secondary:hover, #neuron-lab .nl-secondary button:hover { border-color: var(--nl-violet) !important; }
|
||
#neuron-lab button:disabled { opacity: .45 !important; transform: none !important; }
|
||
#neuron-lab button:focus-visible, #neuron-lab summary:focus-visible {
|
||
outline: 2px solid var(--nl-violet) !important; outline-offset: 3px !important;
|
||
}
|
||
#neuron-lab .nl-technical { border: 1px solid var(--nl-quiet-line) !important; border-radius: 8px !important; background: transparent !important; }
|
||
#neuron-lab .nl-technical textarea, #neuron-lab .nl-technical pre { font: 11px/1.6 var(--nl-mono) !important; }
|
||
#neuron-lab .nl-readout { background: transparent !important; border: 0 !important; padding: 0 !important; }
|
||
#neuron-lab .nl-hero { position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr) 240px; align-items: end; gap: 20px; min-height: 220px; padding: 15px 4px 20px; border-bottom: 1px solid #9684d33b; }
|
||
#neuron-lab .nl-hero-copy { position: relative; z-index: 1; }
|
||
#neuron-lab .nl-eyebrow { color: var(--nl-violet); font: 500 9px/1.6 var(--nl-mono); letter-spacing: .23em; text-transform: uppercase; }
|
||
#neuron-lab .nl-hero h1 { margin: 10px 0 9px; color: var(--nl-ice); font: 750 clamp(52px, 6vw, 82px)/.83 var(--nl-sans); letter-spacing: -.065em; text-transform: uppercase; }
|
||
#neuron-lab .nl-hero-prefix { display: block; margin-bottom: 7px; color: #b9c5e0; font: 350 clamp(17px, 2.3vw, 27px)/1.3 var(--nl-sans); letter-spacing: .22em; }
|
||
#neuron-lab .nl-hero-title { display: block; color: var(--nl-ice); text-shadow: 0 0 45px #b18bff65, 0 0 100px #96aaff25; }
|
||
#neuron-lab .nl-deck { margin: 0; max-width: 450px; color: #b5c0d7; font: 12px/1.7 var(--nl-sans); }
|
||
#neuron-lab .nl-hero-identity { position: relative; z-index: 1; align-self: end; width: 240px; padding: 13px 14px; border: 1px solid #a08bc443; border-radius: 9px; background: #0b1025b8; backdrop-filter: blur(14px); box-shadow: 0 0 28px #7858c210; }
|
||
#neuron-lab .nl-orbital-field { position: absolute; pointer-events: none; inset: 0; width: 100%; height: 100%; opacity: .85; }
|
||
#neuron-lab .nl-orbit-plane { transform-origin: 820px 120px; animation: nl-orbit-drift 24s ease-in-out infinite alternate; }
|
||
#neuron-lab .nl-orbit-plane-back { transform-origin: 820px 120px; animation: nl-orbit-drift 31s ease-in-out infinite alternate-reverse; }
|
||
#neuron-lab .nl-orbit-flow { stroke-dasharray: 3 135; animation: nl-orbit-flow 26s linear infinite; }
|
||
#neuron-lab .nl-orbit-beacon { animation: nl-orbit-breathe 7s ease-in-out infinite alternate; }
|
||
#neuron-lab .nl-atmosphere-note { position: absolute; right: 5px; top: 7px; color: #8f96b2; font: 8px/1.5 var(--nl-mono); letter-spacing: .12em; text-transform: uppercase; }
|
||
#neuron-lab .nl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 13px; }
|
||
#neuron-lab .nl-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 5px 8px; color: var(--nl-muted); border: 1px solid #7973b347; border-radius: 5px; font: 9px/1.35 var(--nl-mono); overflow-wrap: anywhere; background: #13152c99; }
|
||
#neuron-lab .nl-chip.nl-accent { color: var(--nl-amber); border-color: #5e4930; background: #ffc06408; }
|
||
#neuron-lab .nl-chip.nl-live::before { content: ""; width: 5px; height: 5px; flex: 0 0 5px; border-radius: 50%; background: var(--nl-cyan); box-shadow: 0 0 8px #79d4db70; }
|
||
#neuron-lab .nl-model-name { margin: 5px 0 0; color: var(--nl-ice); font: 500 11px/1.6 var(--nl-mono); overflow-wrap: anywhere; }
|
||
#neuron-lab .nl-section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 20px; }
|
||
#neuron-lab .nl-section-head h2 { color: var(--nl-ink); margin: 5px 0 0; font: 600 22px/1.2 var(--nl-sans); letter-spacing: -.04em; }
|
||
#neuron-lab .nl-micro { color: var(--nl-dim); font: 10px/1.6 var(--nl-mono); }
|
||
#neuron-lab .nl-empty { display: grid; place-content: center; min-height: 185px; padding: 26px; text-align: center; border: 1px solid #8983b82b; border-radius: 12px; background: radial-gradient(ellipse at 50% 100%, #6543b91c, transparent 68%), #0b0e1d55; }
|
||
#neuron-lab .nl-empty-mark { margin-bottom: 14px; color: var(--nl-violet); font: 300 34px/1 var(--nl-mono); letter-spacing: -.1em; }
|
||
#neuron-lab .nl-empty strong { color: var(--nl-ink); font: 550 16px/1.4 var(--nl-sans); }
|
||
#neuron-lab .nl-empty p { color: var(--nl-muted); margin: 8px auto 0; max-width: 370px; font: 12px/1.7 var(--nl-sans); }
|
||
#neuron-lab .nl-signal { display: block; width: 100%; height: auto; min-height: 145px; border-radius: 10px; background: #0a0e1b66; }
|
||
#neuron-lab .nl-signal text { font: 10px var(--nl-mono); fill: var(--nl-dim); }
|
||
#neuron-lab .nl-signal .nl-zero-label { fill: var(--nl-muted); }
|
||
#neuron-lab .nl-chart-caption { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; color: var(--nl-dim); font: 10px/1.5 var(--nl-mono); }
|
||
#neuron-lab .nl-legend { display: inline-flex; align-items: center; gap: 12px; }
|
||
#neuron-lab .nl-legend span::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 1px; background: var(--nl-violet); }
|
||
#neuron-lab .nl-legend .nl-neg::before { background: var(--nl-cyan); }
|
||
#neuron-lab .nl-stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); border: 1px solid var(--nl-line); border-radius: 8px; margin: 0 0 20px; }
|
||
#neuron-lab .nl-stat { padding: 13px 15px; min-width: 0; }
|
||
#neuron-lab .nl-stat + .nl-stat { border-left: 1px solid var(--nl-line); }
|
||
#neuron-lab .nl-stat dt { color: var(--nl-dim); font: 10px/1.5 var(--nl-mono); }
|
||
#neuron-lab .nl-stat dd { margin: 5px 0 0; color: var(--nl-ink); font: 500 22px/1.15 var(--nl-mono); letter-spacing: -.06em; overflow-wrap: anywhere; }
|
||
#neuron-lab .nl-token-heading { display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--nl-muted); font: 10px/1.4 var(--nl-mono); }
|
||
#neuron-lab .nl-tokens { display: flex; flex-wrap: wrap; gap: 5px; max-height: 205px; overflow: auto; padding: 4px 2px 7px; }
|
||
#neuron-lab .nl-token { color: var(--nl-ink); padding: 5px 7px; border-radius: 4px; border: 1px solid #ffffff16; font: 12px/1.5 var(--nl-mono); white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
|
||
#neuron-lab .nl-token:focus-visible { outline: 2px solid var(--nl-ink); outline-offset: 2px; }
|
||
#neuron-lab .nl-token:focus::after { content: attr(data-reading); display: block; font-size: 10px; margin-top: 3px; }
|
||
#neuron-lab .nl-note { margin: 14px 0 0; color: var(--nl-dim); font: 11px/1.6 var(--nl-sans); }
|
||
#neuron-lab .nl-stack { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||
#neuron-lab .nl-edit { display: grid; grid-template-columns: 25px 1fr auto; align-items: center; gap: 13px; padding: 13px; border: 1px solid var(--nl-line); border-left: 2px solid var(--nl-amber); border-radius: 7px; background: #ffffff02; }
|
||
#neuron-lab .nl-edit.nl-disabled { border-left-color: var(--nl-line); opacity: .55; }
|
||
#neuron-lab .nl-edit-order { color: var(--nl-dim); font: 10px var(--nl-mono); }
|
||
#neuron-lab .nl-edit-target { color: var(--nl-ink); font: 12px/1.5 var(--nl-mono); }
|
||
#neuron-lab .nl-edit-operation { color: var(--nl-muted); font: 11px/1.5 var(--nl-sans); margin-top: 3px; }
|
||
#neuron-lab .nl-edit-math { color: var(--nl-amber); font: 15px/1.5 var(--nl-mono); text-align: right; }
|
||
#neuron-lab .nl-edit-unit { display: block; color: var(--nl-dim); font: 9px/1.5 var(--nl-mono); }
|
||
#neuron-lab .nl-stack-empty { min-height: 130px; }
|
||
#neuron-lab .nl-comparison-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
|
||
#neuron-lab .nl-condition { border: 1px solid var(--nl-line); border-radius: 12px; overflow: hidden; background: linear-gradient(165deg, #181a30c9, #0a1021c9); display: flex; flex-direction: column; min-width: 0; backdrop-filter: blur(12px); }
|
||
#neuron-lab .nl-condition.nl-condition-recipe { border-color: #695031; }
|
||
#neuron-lab .nl-condition-head { border-top: 2px solid #69737c; padding: 16px 16px 13px; border-bottom: 1px solid var(--nl-quiet-line); }
|
||
#neuron-lab .nl-condition-recipe .nl-condition-head { border-top-color: var(--nl-amber); }
|
||
#neuron-lab .nl-condition-control .nl-condition-head { border-top-color: var(--nl-cyan); }
|
||
#neuron-lab .nl-condition h3 { margin: 5px 0 7px; color: var(--nl-ink); font: 600 17px/1.3 var(--nl-sans); letter-spacing: -.025em; }
|
||
#neuron-lab .nl-condition .nl-micro { font-size: 9px; }
|
||
#neuron-lab .nl-completion { margin: 0; padding: 18px 16px; min-height: 165px; color: var(--nl-ink); font: 13px/1.85 var(--nl-sans); white-space: pre-wrap; overflow-wrap: anywhere; flex: 1; }
|
||
#neuron-lab .nl-completion.nl-waiting { color: var(--nl-dim); font-size: 12px; }
|
||
#neuron-lab .nl-trial-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); padding: 12px 16px; margin: 0; gap: 8px; border-top: 1px solid var(--nl-quiet-line); }
|
||
#neuron-lab .nl-trial-metrics dt { color: var(--nl-dim); font: 9px/1.5 var(--nl-mono); }
|
||
#neuron-lab .nl-trial-metrics dd { margin: 4px 0 0; color: var(--nl-ink); font: 12px/1.4 var(--nl-mono); overflow-wrap: anywhere; }
|
||
#neuron-lab .nl-trial-quality { padding: 0 16px 14px; color: var(--nl-dim); font: 9px/1.7 var(--nl-mono); }
|
||
#neuron-lab .nl-flagged { color: var(--nl-red); }
|
||
#neuron-lab .nl-shared-prompt { margin-bottom: 16px; border-bottom: 1px solid var(--nl-quiet-line); padding-bottom: 12px; }
|
||
#neuron-lab .nl-shared-prompt summary { color: var(--nl-muted); font: 11px var(--nl-mono); cursor: pointer; }
|
||
#neuron-lab .nl-shared-prompt pre { color: var(--nl-ink); font: 12px/1.7 var(--nl-sans); white-space: pre-wrap; overflow-wrap: anywhere; padding: 10px 0 0; }
|
||
#neuron-lab .nl-feedback { display: flex; align-items: start; gap: 12px; min-height: 42px; padding: 11px 13px; border: 1px solid var(--nl-line); border-radius: 7px; background: #ffffff02; }
|
||
#neuron-lab .nl-feedback-label { color: var(--nl-cyan); font: 600 9px/1.7 var(--nl-mono); letter-spacing: .12em; flex: 0 0 auto; }
|
||
#neuron-lab .nl-feedback-message { color: var(--nl-muted); font: 12px/1.5 var(--nl-sans); overflow-wrap: anywhere; }
|
||
#neuron-lab .nl-feedback-error { border-color: #633e37; background: #f49a8807; }
|
||
#neuron-lab .nl-feedback-error .nl-feedback-label { color: var(--nl-red); }
|
||
#neuron-lab .nl-feedback-waiting .nl-feedback-label { color: var(--nl-violet); }
|
||
#neuron-lab .nl-journey-stage { position: relative; overflow: hidden; border: 1px solid #9d87e266 !important; border-radius: 17px !important; background: #060918 !important; box-shadow: inset 0 0 45px #6f43b815, 0 0 45px #7652d51a, 0 20px 65px #02030c70 !important; }
|
||
#neuron-lab .nl-chapter { color: var(--nl-muted); border: 1px solid var(--nl-line); background: #0a1022b3; border-radius: 7px; }
|
||
#neuron-lab .nl-chapter[aria-current="step"], #neuron-lab .nl-chapter.active, #neuron-lab .nl-chapter[data-active="true"] { color: var(--nl-ice); border-color: #b59aff9e; background: #8b66d72b; box-shadow: inset 0 0 18px #b59aff0b, 0 0 18px #b59aff18; }
|
||
#neuron-lab[data-motion="paused"] *, #neuron-lab[data-motion="paused"] *::before, #neuron-lab[data-motion="paused"] *::after,
|
||
#neuron-lab [data-motion="paused"] *, #neuron-lab [data-motion="paused"] *::before, #neuron-lab [data-motion="paused"] *::after { animation-play-state: paused !important; }
|
||
#neuron-lab .nl-hero-connected { min-height: 95px; padding: 7px 4px 14px; align-items: center; }
|
||
#neuron-lab .nl-hero-connected h1 { font-size: 34px; margin: 6px 0; }
|
||
#neuron-lab .nl-hero-connected .nl-hero-prefix { display: inline; font-size: 14px; margin-right: 10px; }
|
||
#neuron-lab .nl-hero-connected .nl-hero-title { display: inline; }
|
||
#neuron-lab .nl-hero-connected .nl-deck, #neuron-lab .nl-hero-connected .nl-hero-identity .nl-note { display: none; }
|
||
#neuron-lab .nl-hero-connected .nl-chips { margin-top: 10px; }
|
||
#neuron-lab .nl-comparison-grid { grid-template-columns: repeat(auto-fit,minmax(min(100%,240px),1fr)); }
|
||
#neuron-lab .nl-completion { min-height: 110px; font-size: 16px; line-height: 1.65; }
|
||
#neuron-lab .nl-section-head { margin-bottom: 12px; }
|
||
#neuron-lab .nl-stack-empty { min-height: 60px; padding: 12px; }
|
||
#neuron-lab .nl-receipt { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 17px 19px; margin: 14px 0; border: 1px solid #51445f; border-radius: 12px; background: #151325; }
|
||
#neuron-lab .nl-receipt strong { display: block; color: var(--nl-ink); font: 600 18px/1.4 var(--nl-sans); }
|
||
#neuron-lab .nl-receipt p { margin: 4px 0 0; color: var(--nl-muted); font: 12px/1.6 var(--nl-sans); }
|
||
#neuron-lab .nl-receipt-passed { border-color: #5c9373; background: #0e211e; }
|
||
#neuron-lab .nl-receipt-passed strong { color: #b8efcf; }
|
||
#neuron-lab .nl-receipt-mismatch, #neuron-lab .nl-receipt-failed { border-color: #a05f5a; }
|
||
#neuron-lab .nl-condition-reset .nl-condition-head { border-top-color: #a1e2bc; }
|
||
#neuron-lab .nl-run-id { color: var(--nl-dim); font: 11px/1.6 var(--nl-mono); }
|
||
#neuron-lab .nl-trial-details { border-top: 1px solid var(--nl-quiet-line); }
|
||
#neuron-lab .nl-trial-details summary { cursor: pointer; color: var(--nl-muted); padding: 10px 16px; font: 11px var(--nl-mono); }
|
||
|
||
@keyframes nl-orbit-drift {
|
||
from { transform: translateY(-3px) rotate(-.7deg); }
|
||
to { transform: translateY(5px) rotate(.7deg); }
|
||
}
|
||
@keyframes nl-orbit-flow {
|
||
from { stroke-dashoffset: 0; }
|
||
to { stroke-dashoffset: -552; }
|
||
}
|
||
@keyframes nl-orbit-breathe {
|
||
from { opacity: .35; }
|
||
to { opacity: .9; }
|
||
}
|
||
@media (max-width: 1050px) {
|
||
#neuron-lab { padding: 18px !important; }
|
||
#neuron-lab .nl-hero-identity { width: 220px; }
|
||
#neuron-lab .nl-comparison-grid { grid-template-columns: 1fr; }
|
||
#neuron-lab .nl-completion { min-height: 90px; }
|
||
}
|
||
@media (max-width: 900px) {
|
||
#neuron-lab .nl-control-rack, #neuron-lab .nl-workbench {
|
||
flex-basis: 100% !important; width: 100% !important;
|
||
}
|
||
}
|
||
@media (max-width: 680px) {
|
||
#neuron-lab { padding: 13px !important; border-radius: 10px !important; }
|
||
#neuron-lab .nl-hero { grid-template-columns: 1fr; gap: 12px; padding-bottom: 16px; }
|
||
#neuron-lab .nl-hero-identity { width: 100%; padding: 11px 12px; }
|
||
#neuron-lab .nl-hero-identity .nl-note { margin-top: 7px; }
|
||
#neuron-lab .nl-orbital-field { width: 160%; left: -20%; opacity: .6; }
|
||
#neuron-lab .nl-atmosphere-note { font-size: 7px; }
|
||
#neuron-lab .nl-stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
|
||
#neuron-lab .nl-stat:nth-child(3) { border-left: 0; }
|
||
#neuron-lab .nl-stat:nth-child(n+3) { border-top: 1px solid var(--nl-line); }
|
||
#neuron-lab .nl-panel { padding: 13px !important; }
|
||
}
|
||
@media (prefers-reduced-motion: reduce) {
|
||
#neuron-lab *, #neuron-lab *::before, #neuron-lab *::after { transition: none !important; animation: none !important; }
|
||
#neuron-lab button.nl-primary:hover, #neuron-lab .nl-primary button:hover { transform: none !important; }
|
||
}
|
||
"""
|
||
|
||
|
||
def _text(value):
|
||
return escape(str(value) if value is not None else "", quote=True)
|
||
|
||
|
||
def _field(value, name, default=None):
|
||
return value.get(name, default) if isinstance(value, Mapping) else getattr(value, name, default)
|
||
|
||
|
||
def _finite(value):
|
||
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
||
return None
|
||
try:
|
||
number = float(value)
|
||
except (OverflowError, ValueError):
|
||
return None
|
||
return number if math.isfinite(number) else None
|
||
|
||
|
||
def _number(value, *, signed=False):
|
||
value = _finite(value)
|
||
if value is None:
|
||
return "—"
|
||
if value == 0:
|
||
return "0"
|
||
result = f"{value:,.3g}"
|
||
if signed and value > 0:
|
||
result = "+" + result
|
||
return result.replace("-", "−")
|
||
|
||
|
||
def _percent(value):
|
||
value = _finite(value)
|
||
return f"{value * 100:.0f}%" if value is not None and 0 <= value <= 1 else "—"
|
||
|
||
|
||
def _address(value, prefix):
|
||
number = _finite(value)
|
||
return f"{prefix}{int(number):02d}" if number is not None and number >= 0 and number.is_integer() else prefix + "—"
|
||
|
||
|
||
def _scope(recipe):
|
||
return {"all_tokens": "All tokens", "prompt_tokens": "Prompt tokens",
|
||
"generated_tokens": "Generated tokens"}.get(_field(recipe, "scope"), "Scope unrecorded")
|
||
|
||
|
||
def _edits(recipe):
|
||
edits = _field(recipe, "edits", ())
|
||
return edits if isinstance(edits, (list, tuple)) else ()
|
||
|
||
|
||
def _enabled(recipe):
|
||
return sum(_field(edit, "enabled", True) is True for edit in _edits(recipe))
|
||
|
||
|
||
def _head(kicker, title, aside=""):
|
||
return ('<div class="nl-section-head"><div><div class="nl-eyebrow">' + _text(kicker)
|
||
+ '</div><h2>' + _text(title) + '</h2></div>' + aside + '</div>')
|
||
|
||
|
||
def _model_display_name(model_name):
|
||
"""Shorten explicit local paths without guessing whether a Hub id is a path."""
|
||
name = str(model_name)
|
||
local = (name.startswith(("/", "./", "../", "~/", "~\\", ".\\", "..\\", "\\\\"))
|
||
or (len(name) > 2 and name[0].isalpha() and name[1] == ":" and name[2] in "/\\"))
|
||
if local:
|
||
return name.rstrip("/\\").replace("\\", "/").rsplit("/", 1)[-1] or name
|
||
return name
|
||
|
||
|
||
def render_hero(session=None):
|
||
"""Identity and live model status, with no synthetic measurement decoration."""
|
||
handle = _field(session, "handle")
|
||
loaded = handle is not None
|
||
model_name = _field(handle, "model_name", "Model identity unavailable") if loaded else "No model connected"
|
||
recipe = _field(session, "recipe")
|
||
layers = _field(session, "layers", ()) or ()
|
||
model_label = "CONNECTED MODEL" if loaded else "SESSION / STANDBY"
|
||
chips = '<span class="nl-chip">Runtime only</span><span class="nl-chip">Raw activation units</span>'
|
||
if loaded:
|
||
count = _enabled(recipe)
|
||
chips += (f'<span class="nl-chip nl-live">{len(layers)} layers</span>'
|
||
f'<span class="nl-chip nl-accent">{count} enabled edit{"s" if count != 1 else ""}</span>')
|
||
return f'''<header class="nl-hero{" nl-hero-connected" if loaded else ""}">
|
||
<svg class="nl-orbital-field" viewBox="0 0 1200 240" preserveAspectRatio="xMidYMid slice" aria-hidden="true" focusable="false" data-kind="decorative">
|
||
<defs>
|
||
<radialGradient id="nl-orbit-haze"><stop stop-color="#8d5ce5" stop-opacity=".22"/><stop offset="1" stop-color="#8d5ce5" stop-opacity="0"/></radialGradient>
|
||
<linearGradient id="nl-orbit-spectrum" x1="0" x2="1"><stop stop-color="#b59aff" stop-opacity="0"/><stop offset=".32" stop-color="#b59aff"/><stop offset=".76" stop-color="#79d4db"/><stop offset="1" stop-color="#79d4db" stop-opacity=".15"/></linearGradient>
|
||
<filter id="nl-orbit-halo" x="-50%" y="-200%" width="200%" height="500%"><feGaussianBlur stdDeviation="7"/></filter>
|
||
</defs>
|
||
<ellipse cx="800" cy="115" rx="410" ry="180" fill="url(#nl-orbit-haze)"/>
|
||
<g fill="none" stroke="#a1b9e6" stroke-width=".6" opacity=".22">
|
||
<path d="M440 28H467M453 15V41M1117 191H1144M1130 178V204M635 220H648M641 213V226"/>
|
||
<path d="M497 34C715 9 988 53 1177 163M438 168C710 260 1002 180 1198 30" stroke-dasharray="2 9"/>
|
||
</g>
|
||
<g class="nl-orbit-plane-back" fill="none" stroke="#9a82d9" stroke-width=".8">
|
||
<ellipse cx="820" cy="120" rx="286" ry="77" transform="rotate(24 820 120)" opacity=".32"/>
|
||
<ellipse cx="820" cy="120" rx="242" ry="103" transform="rotate(-39 820 120)" opacity=".2"/>
|
||
<ellipse cx="820" cy="120" rx="128" ry="196" transform="rotate(61 820 120)" opacity=".16"/>
|
||
</g>
|
||
<g class="nl-orbit-plane" fill="none" stroke="url(#nl-orbit-spectrum)">
|
||
<ellipse cx="820" cy="120" rx="290" ry="64" transform="rotate(-19 820 120)" stroke-width="9" opacity=".45" filter="url(#nl-orbit-halo)"/>
|
||
<ellipse cx="820" cy="120" rx="290" ry="64" transform="rotate(-19 820 120)" stroke-width="1.2" opacity=".7"/>
|
||
<path d="M350 232C511 244 487 67 718 80S951 231 1210 9" stroke-width="9" opacity=".5" filter="url(#nl-orbit-halo)"/>
|
||
<path d="M350 232C511 244 487 67 718 80S951 231 1210 9" stroke-width="1.4" opacity=".82"/>
|
||
<path class="nl-orbit-flow" d="M350 232C511 244 487 67 718 80S951 231 1210 9" stroke="#eef3ff" stroke-width="2" opacity=".8"/>
|
||
</g>
|
||
<g class="nl-orbit-beacon" fill="#d8d9ff"><circle cx="565" cy="154" r="2"/><circle cx="741" cy="81" r="2.2"/><circle cx="1034" cy="63" r="1.8"/></g>
|
||
<g fill="#abb4d5" opacity=".45"><circle cx="480" cy="98" r=".8"/><circle cx="622" cy="41" r=".8"/><circle cx="936" cy="34" r=".7"/><circle cx="1113" cy="141" r=".8"/><circle cx="899" cy="224" r=".7"/></g>
|
||
</svg>
|
||
<span class="nl-atmosphere-note">Ambient field · schematic</span>
|
||
<div class="nl-hero-copy"><div class="nl-eyebrow">OBLITERATUS / NEURON LAB</div>
|
||
<h1><span class="nl-hero-prefix">NEURON</span><span class="nl-hero-title">LAB</span></h1>
|
||
<p class="nl-deck">Pick a neuron. See what changes.</p>
|
||
<div class="nl-chips">{chips}</div></div>
|
||
<div class="nl-hero-identity">
|
||
<div class="nl-micro">{model_label}</div><p class="nl-model-name" title="{_text(model_name)}" aria-label="{_text(model_name)}">{_text(_model_display_name(model_name))}</p>
|
||
<p class="nl-note">Edits run in memory.<br>Model weights stay unchanged.</p></div></header>'''
|
||
|
||
|
||
def _signal_chart(rows):
|
||
finite_values = [number for _, _, number in rows if number is not None]
|
||
if not finite_values:
|
||
return ""
|
||
low, high = min(0., min(finite_values)), max(0., max(finite_values))
|
||
magnitude = max(abs(low), abs(high))
|
||
scaled_low, scaled_high = (low / magnitude, high / magnitude) if magnitude else (0., 0.)
|
||
span = scaled_high - scaled_low
|
||
# Zero-only traces have one labelled axis at zero; no fictional ±1 range.
|
||
def y(value):
|
||
return 104. if span == 0 else 24. + (scaled_high - value / magnitude) / span * 156.
|
||
zero = y(0.)
|
||
start, width = 62., 650.
|
||
step = width / max(1, len(rows))
|
||
bars = []
|
||
for index, (position, token, value) in enumerate(rows):
|
||
if value is None:
|
||
continue
|
||
x = start + index * step + step * .12
|
||
tooltip = _text(f"Token {position} · {token} · {_number(value, signed=True)} raw")
|
||
if value == 0:
|
||
bars.append(f'<line x1="{x:.3f}" x2="{x + step * .76:.3f}" y1="{zero:.3f}" y2="{zero:.3f}" stroke="#adb2b8" stroke-width="2"><title>{tooltip}</title></line>')
|
||
else:
|
||
height = abs(y(value) - zero)
|
||
color = "#b59aff" if value > 0 else "#79d4db"
|
||
bars.append(f'<rect x="{x:.3f}" y="{min(zero, y(value)):.3f}" width="{max(.3, step * .76):.3f}" height="{height:.3f}" fill="{color}" opacity=".85"><title>{tooltip}</title></rect>')
|
||
tick_labels = f'<text class="nl-zero-label" x="49" y="{zero + 3:.3f}" text-anchor="end">0</text>'
|
||
if high > 0:
|
||
tick_labels += f'<text x="49" y="27" text-anchor="end">{_number(high, signed=True)}</text>'
|
||
if low < 0:
|
||
tick_labels += f'<text x="49" y="183" text-anchor="end">{_number(low)}</text>'
|
||
accessible = _text(f"Signed neuron activations across {len(rows)} token positions. "
|
||
f"Observed range {_number(min(finite_values))} to {_number(max(finite_values))} raw activation units.")
|
||
return (f'<svg class="nl-signal" viewBox="0 0 734 218" role="img" aria-label="{accessible}">'
|
||
'<path d="M62 24H712M62 102H712M62 180H712" fill="none" stroke="#232830" stroke-dasharray="2 5"/>'
|
||
+ f'<line x1="62" x2="712" y1="{zero:.3f}" y2="{zero:.3f}" stroke="#62686f" stroke-width="1"/>'
|
||
+ "".join(bars) + tick_labels
|
||
+ f'<text x="62" y="207">POSITION {_text(rows[0][0])}</text>'
|
||
+ f'<text x="712" y="207" text-anchor="end">{_text(rows[-1][0])}</text></svg>')
|
||
|
||
|
||
def render_inspector(inspection=None):
|
||
"""Signed activation trace and keyboard-readable heatmap from actual capture."""
|
||
raw_rows = _field(inspection, "tokens", ()) or ()
|
||
if not isinstance(raw_rows, (list, tuple)):
|
||
raw_rows = ()
|
||
rows = [(row[0], row[1], _finite(row[2])) for row in raw_rows[:512]
|
||
if isinstance(row, (list, tuple)) and len(row) == 3]
|
||
if not rows:
|
||
return (_head("01 / OBSERVE", "Read the channel")
|
||
+ '<div class="nl-empty"><div class="nl-empty-mark" aria-hidden="true">[ · ]</div>'
|
||
'<strong>A signal starts with a prompt.</strong><p>Choose a layer and neuron, then inspect. '
|
||
'The trace and token map will show its unmodified activity.</p></div>'
|
||
'<p class="nl-note">No activations captured yet.</p>')
|
||
location = _address(_field(inspection, "layer"), "L") + " / " + _address(_field(inspection, "neuron"), "N")
|
||
aside = '<span class="nl-chip nl-accent">' + location + '</span>'
|
||
stats = _field(inspection, "statistics", {}) or {}
|
||
numbers = [value for _, _, value in rows if value is not None]
|
||
magnitude = max((abs(value) for value in numbers), default=0.)
|
||
chart = _signal_chart(rows)
|
||
if not chart:
|
||
chart = '<div class="nl-empty"><strong>No finite activations to plot.</strong><p>The capture contains unavailable values. Inspect again before interpreting this channel.</p></div>'
|
||
clipped = len(raw_rows) > 512
|
||
caption = f"First 512 of {len(raw_rows)} positions" if clipped else f"{len(rows)} token positions"
|
||
tokens = []
|
||
for position, token, value in rows:
|
||
intensity = abs(value) / magnitude if value is not None and magnitude else 0.
|
||
color = "181,154,255" if value is not None and value > 0 else "121,212,219"
|
||
alpha = .06 + .22 * intensity if value is not None and value != 0 else .025
|
||
reading = f"Position {position} · {_number(value, signed=True)} raw"
|
||
tokens.append(f'<span class="nl-token" tabindex="0" title="{_text(reading)}" aria-label="{_text(str(token) + "; " + reading)}" data-reading="{_text(reading)}" style="background:rgba({color},{alpha:.3f})">{_text(token) if str(token) else "∅"}</span>')
|
||
metrics = [("Mean", _number(_field(stats, "mean"), signed=True)),
|
||
("Minimum", _number(_field(stats, "min"), signed=True)),
|
||
("Maximum", _number(_field(stats, "max"), signed=True)),
|
||
("Positive share", _percent(_field(stats, "positive_fraction")))]
|
||
metrics_html = '<dl class="nl-stats">' + "".join(
|
||
f'<div class="nl-stat"><dt>{label}</dt><dd>{value}</dd></div>' for label, value in metrics) + '</dl>'
|
||
note = "Baseline activity · raw activation units · one prompt, not a behavioral explanation."
|
||
unavailable = sum(value is None for _, _, value in rows)
|
||
if unavailable:
|
||
note += f" {unavailable} unavailable values are omitted from the trace."
|
||
elif numbers and all(value == 0 for value in numbers):
|
||
note += " All captured values shown are zero."
|
||
return (_head("01 / OBSERVE", "Activation fingerprint", aside) + chart
|
||
+ '<div class="nl-chart-caption"><span>' + caption + '</span>'
|
||
'<span class="nl-legend"><span class="nl-neg">Negative</span><span>Positive</span></span></div>'
|
||
+ metrics_html + '<div class="nl-token-heading"><span>TOKEN MAP</span><span>Hover or focus for values</span></div>'
|
||
+ '<div class="nl-tokens" aria-label="Token activation values">' + "".join(tokens) + '</div>'
|
||
+ '<p class="nl-note">' + note + '</p>')
|
||
|
||
|
||
def _operation(edit):
|
||
operation = _field(edit, "operation", "unknown")
|
||
value = _number(_field(edit, "value"))
|
||
if operation == "add":
|
||
numeric = _finite(_field(edit, "value"))
|
||
formula = f"a {'−' if numeric is not None and numeric < 0 else '+'} {_number(abs(numeric)) if numeric is not None else '—'}"
|
||
else:
|
||
formula = {"scale": f"a × {value}", "flip": "−a", "zero": "0", "set": value}.get(operation)
|
||
if operation == "clamp":
|
||
lower, upper = _field(edit, "lower"), _field(edit, "upper")
|
||
formula = f"[{_number(lower) if lower is not None else '−∞'}, {_number(upper) if upper is not None else '+∞'}]"
|
||
unit = "gain" if operation in {"scale", "flip", "zero"} else "raw units"
|
||
return str(operation).capitalize(), formula or "Unavailable", unit
|
||
|
||
|
||
def render_stack(recipe=None):
|
||
edits = _edits(recipe)
|
||
count = _enabled(recipe)
|
||
aside = f'<span class="nl-chip">{count} enabled / {len(edits)} stored</span>'
|
||
heading = _head("02 / INTERVENE", "Intervention stack", aside)
|
||
if not edits:
|
||
return (heading + '<div class="nl-empty nl-stack-empty"><strong>No intervention yet.</strong>'
|
||
'<p>Choose a channel operation, then apply it to the stack. Your model weights stay untouched.</p></div>')
|
||
rows = []
|
||
for index, edit in enumerate(edits, 1):
|
||
enabled = _field(edit, "enabled", True) is True
|
||
name, formula, unit = _operation(edit)
|
||
target = _address(_field(edit, "layer"), "L") + " · " + _address(_field(edit, "neuron"), "N")
|
||
suffix = "" if enabled else " · Disabled"
|
||
rows.append(f'<li class="nl-edit{" nl-disabled" if not enabled else ""}"><span class="nl-edit-order">{index:02d}</span><div><div class="nl-edit-target">{target}</div><div class="nl-edit-operation">{_text(name + suffix)}</div></div><div class="nl-edit-math">{_text(formula)}<span class="nl-edit-unit">{unit}</span></div></li>')
|
||
note = _scope(recipe) + " · Runs from top to bottom. Repeated targets compose in this order."
|
||
if _field(recipe, "scope") == "generated_tokens":
|
||
note += " The first answer prediction stays baseline."
|
||
return heading + '<ol class="nl-stack">' + "".join(rows) + '</ol><p class="nl-note">' + _text(note) + '</p>'
|
||
|
||
|
||
def _condition(name, trial=None):
|
||
title, number, waiting = {
|
||
"baseline": ("Baseline", "01", "The same prompt with untouched activations."),
|
||
"recipe": ("Your recipe", "02", "Your ordered interventions, applied at runtime."),
|
||
"control": ("Control", "04", "Import a control recipe to add a third condition."),
|
||
"reset": ("After reset", "03", "Clear edits and replay this input to verify recovery."),
|
||
}[name]
|
||
recipe = _field(trial, "recipe")
|
||
if trial is None:
|
||
detail, completion, metrics = "AWAITING COMPARISON", waiting, ""
|
||
else:
|
||
count = _enabled(recipe)
|
||
detail = "UNMODIFIED REFERENCE" if name == "baseline" else f"{count} ENABLED EDIT{'S' if count != 1 else ''} / {_scope(recipe).upper()}"
|
||
completion = _field(trial, "text")
|
||
if completion is None:
|
||
completion = "Output text was not included in this record."
|
||
elif not str(completion):
|
||
completion = "No visible text was generated."
|
||
seconds = _finite(_field(trial, "seconds"))
|
||
duration = f"{seconds:.2f}s" if seconds is not None and seconds >= 0 else "—"
|
||
values = [("TOKENS", _number(_field(trial, "tokens"))), ("TIME", duration),
|
||
("FIRST-TOKEN KL", _number(_field(trial, "first_token_kl_from_baseline")))]
|
||
metrics = '<dl class="nl-trial-metrics">' + "".join(
|
||
f'<div><dt>{label}</dt><dd>{value}</dd></div>' for label, value in values) + '</dl>'
|
||
flag = _field(trial, "invalid_output_heuristic")
|
||
quality = ('<span class="nl-flagged">Output heuristic flagged</span>' if flag is True else
|
||
"No output heuristic flag" if flag is False else "Output heuristic unrecorded")
|
||
metrics += '<div class="nl-trial-quality">Repeated tokens ' + _percent(_field(trial, "repeated_token_fraction")) + '<br>' + quality + '</div>'
|
||
stop = _field(trial, "stop_reason")
|
||
stop_label = {"eos": "Completed", "token_limit": "Token limit reached"}.get(stop, "Stop reason unrecorded")
|
||
metrics = '<details class="nl-trial-details"><summary>' + _text(stop_label) + ' · measurements</summary>' + metrics + '</details>'
|
||
return (f'<article class="nl-condition nl-condition-{name}"><div class="nl-condition-head">'
|
||
f'<div class="nl-eyebrow">CONDITION {number}</div><h3>{title}</h3><div class="nl-micro">{_text(detail)}</div></div>'
|
||
f'<div class="nl-completion{" nl-waiting" if trial is None else ""}">{_text(completion)}</div>{metrics}</article>')
|
||
|
||
|
||
def render_comparison(comparison=None):
|
||
trials = _field(comparison, "trials", {}) or {}
|
||
decoding = _field(comparison, "decoding", {}) or {}
|
||
aside = '<span class="nl-chip">Exploratory comparison</span>'
|
||
heading = _head("03 / COMPARE", "Same prompt. Different conditions.", aside)
|
||
prompt = _field(comparison, "prompt")
|
||
shared = ('<details class="nl-shared-prompt"><summary>Shared input</summary><pre>'
|
||
+ _text(prompt) + '</pre></details>') if prompt is not None else ""
|
||
names = ["baseline", "recipe"] + [name for name in ("reset", "control") if name in trials]
|
||
cards = "".join(_condition(name, _field(trials, name)) for name in names)
|
||
check = _field(comparison, "verification", {}) or {}
|
||
state = _field(check, "status", "not_run")
|
||
# Never infer an exact replay from matching decoded text alone.
|
||
passed = (state == "passed" and "reset" in trials and all(
|
||
_field(check, key) is True for key in ("token_ids_exact", "first_logits_exact", "hook_registry_restored", "input_replayed_exactly")))
|
||
if passed:
|
||
title, detail = "Reset verified · exact replay", "Token IDs and first-step logits match. Hook registrations restored. Active edits: 0."
|
||
elif state in {"passed", "mismatch"}:
|
||
state = "mismatch"
|
||
title, detail = "Reset differs from baseline", "Inspect the exported measurements. An exact recovery is not established."
|
||
elif state == "failed":
|
||
title, detail = "Reset check incomplete", "Edits were cleared, but this replay failed or was cancelled. Run a new comparison to retry."
|
||
elif state == "running":
|
||
title, detail = "Checking reset", "Replaying the frozen input after clearing the active edits."
|
||
else:
|
||
state = "not_run"
|
||
title, detail = "Reset not checked yet", "Clear edits and verify this exact input. The before-and-after evidence will stay here."
|
||
run_id = _field(comparison, "run_id", "")
|
||
receipt = (f'<section class="nl-receipt nl-receipt-{state}" aria-label="Reset verification"><div><strong>{title}</strong><p>{detail}</p></div>'
|
||
+ (f'<span class="nl-run-id">RUN {_text(str(run_id)[:12])}</span>' if run_id else '') + '</section>') if comparison else ""
|
||
notes = []
|
||
if _field(decoding, "do_sample") is False:
|
||
notes.append("Greedy decoding")
|
||
if _field(decoding, "use_cache") is False:
|
||
notes.append("Fresh no-cache forwards")
|
||
if _field(decoding, "chat_template_applied") is True:
|
||
notes.append("Model chat template")
|
||
elif _field(decoding, "chat_template_applied") is False:
|
||
notes.append("Plain text input")
|
||
foot = " · ".join(notes)
|
||
if foot:
|
||
foot += ". "
|
||
foot += "First-token KL measures distribution change. Trait and capability accuracy are untested."
|
||
return heading + shared + receipt + '<div class="nl-comparison-grid">' + cards + '</div><p class="nl-note">' + _text(foot + " Reset verifies this input only; weight checksums are not measured here.") + '</p>'
|
||
|
||
|
||
def render_feedback(message="", loaded=False):
|
||
"""A short status strip; parent details retain complete warnings/errors."""
|
||
message = str(message or "").split("\n\n", 1)[0].strip()
|
||
kind, label = "", "READY" if loaded else "STANDBY"
|
||
if not message:
|
||
message = "Choose a channel and inspect its activity." if loaded else "Connect a model to begin."
|
||
elif "failed:" in message.lower():
|
||
kind, label = " nl-feedback-error", "ATTENTION"
|
||
message = message.split(":", 1)[-1].strip()
|
||
elif "cancel" in message.lower():
|
||
kind, label = " nl-feedback-waiting", "CANCELLATION"
|
||
elif "complete" in message.lower():
|
||
label = "DONE"
|
||
if len(message) > 350:
|
||
message = message[:347] + "…"
|
||
return (f'<div class="nl-feedback{kind}" role="status" aria-live="polite">'
|
||
f'<span class="nl-feedback-label">{label}</span><span class="nl-feedback-message">{_text(message)}</span></div>')
|