Spaces:
Running
Running
Download index.html from AmiriHayes/sae-program-viewer: direct link, hf CLI and curl.
- Browser
- Download file 48 kB
-
https://huggingface.co/spaces/AmiriHayes/sae-program-viewer/resolve/main/index.html
- Command line
-
hf download hf://spaces/AmiriHayes/sae-program-viewer/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AmiriHayes/sae-program-viewer/resolve/main/index.html
48 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SAE Feature Viewer</title>
<style>
:root{
--bg:#fff; --panel:#fafafa; --ink:#15151a; --dim:#5d5d68; --faint:#8a8a96;
--rule:#e4e4ea; --accent:#674ea7; --accent-soft:#efeaf8;
--both:#2f7d4f; --both-bg:#dff1e4;
--progonly:#9a6a00; --progonly-bg:#fdf0d0;
--fireonly:#1d5fa8; --fireonly-bg:#dceafa;
--crash:#b3261e; --crash-bg:#fbe0de;
--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
--bg:#131318; --panel:#1b1b22; --ink:#ececf1; --dim:#a4a4b2; --faint:#74747f;
--rule:#2c2c36; --accent:#b4a7d6; --accent-soft:#2a2440;
--both:#79d79b; --both-bg:#1d3a28;
--progonly:#e8c06a; --progonly-bg:#3b3015;
--fireonly:#86b6f0; --fireonly-bg:#17293f;
--crash:#f0908a; --crash-bg:#3d1b1a;
}}
:root[data-theme="dark"]{
--bg:#131318; --panel:#1b1b22; --ink:#ececf1; --dim:#a4a4b2; --faint:#74747f;
--rule:#2c2c36; --accent:#b4a7d6; --accent-soft:#2a2440;
--both:#79d79b; --both-bg:#1d3a28;
--progonly:#e8c06a; --progonly-bg:#3b3015;
--fireonly:#86b6f0; --fireonly-bg:#17293f;
--crash:#f0908a; --crash-bg:#3d1b1a;
}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);
font:15px/1.5 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;}
a{color:var(--accent)}
header{position:sticky;top:0;z-index:20;background:var(--bg);
border-bottom:1px solid var(--rule);padding:10px 16px;display:flex;
gap:12px;align-items:center;flex-wrap:wrap}
header h1{font-size:15px;margin:0;font-weight:650;letter-spacing:-.01em}
.badge{font-size:11px;padding:2px 8px;border-radius:999px;border:1px solid var(--rule);
color:var(--dim);white-space:nowrap}
.badge.live{color:var(--both);border-color:var(--both);background:var(--both-bg)}
.badge.browse{color:var(--dim)}
main{max-width:1060px;margin:0 auto;padding:18px 16px 80px}
button{font:inherit;color:var(--ink);background:var(--panel);
border:1px solid var(--rule);border-radius:7px;padding:5px 11px;cursor:pointer}
button:hover{border-color:var(--accent)}
button.primary{background:var(--accent);color:#fff;border-color:var(--accent);font-weight:600}
button.primary:disabled{opacity:.5;cursor:not-allowed}
select,input[type=text],input[type=number],textarea{font:inherit;color:var(--ink);
background:var(--bg);border:1px solid var(--rule);border-radius:7px;padding:5px 8px}
textarea{width:100%;font-family:var(--mono);font-size:13px;resize:vertical}
code,pre{font-family:var(--mono)}
pre{background:var(--panel);border:1px solid var(--rule);border-radius:8px;
padding:11px 13px;overflow-x:auto;font-size:12.5px;line-height:1.55;margin:0}
.muted{color:var(--dim)}
.tiny{font-size:12px}
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
.card{background:var(--panel);border:1px solid var(--rule);border-radius:10px;
padding:14px;margin:14px 0}
h2{font-size:14px;margin:0 0 9px;letter-spacing:.02em;text-transform:uppercase;
color:var(--dim);font-weight:650}
table{width:100%;border-collapse:collapse;font-size:13.5px}
th,td{text-align:left;padding:6px 9px;border-bottom:1px solid var(--rule)}
th{color:var(--dim);font-weight:600;font-size:12px;cursor:pointer;white-space:nowrap}
th.sorted{color:var(--accent)}
tbody tr{cursor:pointer}
tbody tr:hover{background:var(--accent-soft)}
.num{text-align:right;font-variant-numeric:tabular-nums}
.pill{font-size:11px;padding:1px 7px;border-radius:999px;border:1px solid var(--rule);
color:var(--dim);white-space:nowrap;display:inline-block;margin:1px 2px 1px 0}
.pill.win{color:var(--both);border-color:var(--both)}
.pill.loss{color:var(--crash);border-color:var(--crash)}
.tok{display:inline-block;padding:2px 3px;margin:1px 0;border-radius:4px;
font-family:var(--mono);font-size:13px;white-space:pre;cursor:default;
border:1px solid transparent}
.tok.unscored{color:var(--faint);background:transparent}
.tok.neither{color:var(--dim)}
.tok.both{color:var(--both);background:var(--both-bg);border-color:var(--both)}
.tok.progonly{color:var(--progonly);background:var(--progonly-bg);border-color:var(--progonly)}
.tok.fireonly{color:var(--fireonly);background:var(--fireonly-bg);border-color:var(--fireonly)}
.tok.crash{color:var(--crash);background:var(--crash-bg);border-color:var(--crash)}
.legend{display:flex;gap:7px;flex-wrap:wrap;font-size:12px;margin:9px 0}
.legend span{padding:2px 8px;border-radius:5px;border:1px solid}
details{border:1px solid var(--rule);border-radius:8px;margin:7px 0;background:var(--bg)}
details>summary{cursor:pointer;padding:8px 11px;font-size:13px;color:var(--dim)}
details[open]>summary{border-bottom:1px solid var(--rule);color:var(--ink)}
details .body{padding:11px}
.ex{font-family:var(--mono);font-size:12.5px;padding:5px 7px;border-bottom:1px solid var(--rule);
display:flex;gap:8px;align-items:flex-start}
.ex .t{flex:1;white-space:pre-wrap;word-break:break-word}
.ex mark{background:var(--both-bg);color:var(--both);border-radius:3px;padding:0 2px;font-weight:600}
.err{border-left:3px solid var(--crash);background:var(--crash-bg);color:var(--crash);
padding:9px 12px;border-radius:0 7px 7px 0;margin:9px 0;font-size:13.5px}
.warn{border-left:3px solid var(--progonly);background:var(--progonly-bg);color:var(--progonly);
padding:9px 12px;border-radius:0 7px 7px 0;margin:9px 0;font-size:13.5px}
.info{border-left:3px solid var(--accent);background:var(--accent-soft);
padding:9px 12px;border-radius:0 7px 7px 0;margin:9px 0;font-size:13.5px}
.spin{display:inline-block;width:12px;height:12px;border:2px solid var(--rule);
border-top-color:var(--accent);border-radius:50%;animation:s .7s linear infinite;
vertical-align:-2px;margin-right:6px}
@keyframes s{to{transform:rotate(360deg)}}
.tipbox{position:fixed;z-index:50;background:var(--bg);border:1px solid var(--accent);
border-radius:8px;padding:8px 11px;font-size:12.5px;font-family:var(--mono);
box-shadow:0 6px 24px rgba(0,0,0,.18);pointer-events:none;max-width:300px}
.counts{display:flex;gap:7px;flex-wrap:wrap;font-size:12.5px;margin:9px 0}
.counts b{font-variant-numeric:tabular-nums}
.hist{font-family:var(--mono);font-size:12px;padding:4px 7px;border-bottom:1px solid var(--rule);
cursor:pointer;display:flex;gap:8px}
.hist:hover{background:var(--accent-soft)}
@media(max-width:620px){
main{padding:14px 11px 70px}
/* keep L, feature, description, test F1 and the delta; the rest are in the
feature page anyway, and a 8-column table on a phone is unreadable */
th:nth-child(n+6),td:nth-child(n+6){display:none}
td:nth-child(3){max-width:40vw}
table{font-size:12.5px}
th,td{padding:5px 6px}
.card{padding:11px}
textarea{font-size:16px} /* iOS zooms the page under 16px */
}
@media(max-width:520px){
/* phone: L, feature, description, test F1 only — anything narrower clips */
th:nth-child(n+5),td:nth-child(n+5){display:none}
td:nth-child(3){max-width:52vw}
}
</style>
</head>
<body>
<header>
<h1>SAE Feature Viewer</h1>
<span id="mode" class="badge">checking backend…</span>
<span style="flex:1"></span>
<button id="themeBtn" class="tiny" title="Toggle light / dark">◐</button>
<button id="homeBtn" class="tiny">All features</button>
</header>
<main id="app"><p class="muted"><span class="spin"></span>Loading…</p></main>
<div id="tip" class="tipbox" style="display:none"></div>
<script>
"use strict";
/* ---------------------------------------------------------------- state */
const S = {
live: false, health: null, feats: null,
progs: {}, trans: {}, shared: null, desc: {},
filt: {layer:"", source:"", outcome:"", low:"", f1min:"", f1max:"", q:""},
sort: {key:"test_f1", dir:-1},
coldWarned: false,
nav: 0, // navigation token; a stale render must not write
};
const TIE = 0.01; // win/loss margin against Plan A, per spec
const FIRST_SCORED = 2; // overridden by /api/health when live
const $ = (s,r)=> (r||document).querySelector(s);
const el = (t,c,x)=>{const n=document.createElement(t); if(c)n.className=c;
if(x!==undefined)n.textContent=x; return n;};
const esc = s => String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
const f3 = v => (v===null||v===undefined||v==="MISSING"||Number.isNaN(v)) ? "—" : Number(v).toFixed(3);
const isMissing = v => v===undefined||v===null||v==="MISSING";
/* data/ sits beside the page when the backend serves it, and may sit one level
up in a static deployment that puts the page at the root. Try both. */
let DATA_BASE = null;
async function dataUrl(p){
if(DATA_BASE!==null) return DATA_BASE+p;
for(const base of ["data/","../data/","./data/"]){
try{ const r = await fetch(base+p,{method:"HEAD"}); if(r.ok){ DATA_BASE=base; return base+p; } }catch(e){}
}
DATA_BASE="data/"; return "data/"+p;
}
async function getJSON(p){
const u = await dataUrl(p);
let r;
try{
r = await fetch(u);
}catch(e){
// TypeError: Failed to fetch — the connection was refused or aborted.
// That is the server being gone, not a missing file.
const e2 = new Error(`could not reach ${u}`);
e2.offline = true;
throw e2;
}
if(!r.ok) throw new Error(`${p} → HTTP ${r.status}`);
return r.json();
}
async function backendAlive(){
try{
const c = new AbortController();
const t = setTimeout(()=>c.abort(), 2500);
const r = await fetch("api/health",{signal:c.signal, cache:"no-store"});
clearTimeout(t);
return r.ok;
}catch(e){ return false; }
}
function setMode(live){
S.live = live;
const m = $("#mode");
if(!m) return;
m.textContent = live ? "live backend" : "browse-only";
m.className = "badge " + (live ? "live" : "browse");
}
async function layerProgs(L){
const k="L"+String(L).padStart(2,"0");
if(!S.progs[k]) S.progs[k] = await getJSON(`programs/${k}.json`);
return S.progs[k];
}
async function layerFN(L){
const k="L"+String(L).padStart(2,"0");
if(!S.fns) S.fns = {};
if(!S.fns[k]) S.fns[k] = await getJSON(`errors/${k}.json`);
return S.fns[k];
}
/* One error panel: false negatives or false positives, same shape. */
function errorRows(list, live){
const box = el("div");
box.style.maxHeight = "510px"; // 1.5x the examples block's 340px
box.style.overflowY = "auto";
list.forEach(x=>{
const row = el("div","ex");
const t = el("div","t");
t.innerHTML = esc(x).replace(/\[\[([\s\S]*?)\]\]/g, (_,m)=>`<mark>${m}</mark>`);
row.appendChild(t);
if(live){
const b = el("button","tiny","try");
b.onclick=()=>{
const plain = x.replace(/^\.\.\./,"").replace(/\[\[([\s\S]*?)\]\]/g,"$1");
const ta = $("#lcText"); if(!ta) return;
ta.value = plain; ta.dispatchEvent(new Event("input"));
window.__lcExpect = plain;
$("#lcRun").click();
ta.scrollIntoView({behavior:"smooth",block:"center"});
};
row.appendChild(b);
}
box.appendChild(row);
});
return box;
}
async function layerV2(L){
const k="L"+String(L).padStart(2,"0");
if(!S.v2) S.v2 = {};
if(!S.v2shared) S.v2shared = await getJSON("v2/shared.json");
if(!S.v2[k]) S.v2[k] = await getJSON(`v2/${k}.json`);
return S.v2[k];
}
async function layerTrans(L){
const k="L"+String(L).padStart(2,"0");
if(!S.shared) S.shared = await getJSON("transcripts/shared.json");
if(!S.trans[k]) S.trans[k] = await getJSON(`transcripts/${k}.json`);
return S.trans[k];
}
/* ------------------------------------------------------------ bootstrap */
function outcome(f){
const d = f.test_f1 - f.plan_a_f1;
return d > TIE ? "win" : d < -TIE ? "loss" : "tie";
}
async function boot(){
try{
const ctrl = new AbortController();
const t = setTimeout(()=>ctrl.abort(), 4000);
const r = await fetch("api/health",{signal:ctrl.signal});
clearTimeout(t);
if(r.ok){ S.health = await r.json(); S.live = true; }
}catch(e){ S.live = false; }
const m = $("#mode");
m.textContent = S.live ? "live backend" : "browse-only";
m.className = "badge " + (S.live ? "live" : "browse");
m.title = S.live
? `${S.health.model} · ${S.health.sae_release} · first scored ${S.health.first_scored}`
: "No backend on this origin — the live check needs the local version.";
try{
S.feats = (await getJSON("features.json")).features;
S.desc = await getJSON("descriptions.json");
}catch(e){
$("#app").innerHTML = `<div class="err">Could not load the feature index: ${esc(e.message)}</div>`;
return;
}
S.feats.forEach(f=>{ f._d = f.test_f1 - f.plan_a_f1; f._o = outcome(f); });
window.addEventListener("hashchange", route);
route();
}
/* ----------------------------------------------------------------- list */
function listView(){
const a = $("#app"); a.innerHTML = "";
const f = S.filt;
const bar = el("div","card");
bar.innerHTML = `
<div class="row">
<label class="tiny muted">Layer <select id="fLayer"><option value="">all</option>
${Array.from({length:12},(_,i)=>`<option ${f.layer==i+1?"selected":""}>${i+1}</option>`).join("")}</select></label>
<label class="tiny muted">Source <select id="fSource">
<option value="">all</option>
<option value="agent" ${f.source==="agent"?"selected":""}>agent</option>
<option value="agent, identical to Plan A" ${f.source.startsWith("agent,")?"selected":""}>identical to Plan A</option>
</select></label>
<label class="tiny muted">vs Plan A <select id="fOut">
<option value="">all</option>
<option value="win" ${f.outcome==="win"?"selected":""}>win</option>
<option value="loss" ${f.outcome==="loss"?"selected":""}>loss</option>
<option value="tie" ${f.outcome==="tie"?"selected":""}>tie (±${TIE})</option>
</select></label>
<label class="tiny muted">Support <select id="fLow">
<option value="">all</option>
<option value="1" ${f.low==="1"?"selected":""}>low support only</option>
<option value="0" ${f.low==="0"?"selected":""}>exclude low support</option>
</select></label>
<label class="tiny muted">F1 <input id="fMin" type="number" step="0.05" min="0" max="1"
style="width:68px" placeholder="min" value="${f.f1min}">
– <input id="fMax" type="number" step="0.05" min="0" max="1"
style="width:68px" placeholder="max" value="${f.f1max}"></label>
<input id="fQ" type="text" placeholder="feature id or description…" style="flex:1;min-width:180px" value="${esc(f.q)}">
</div>
<div class="tiny muted" id="cnt" style="margin-top:9px"></div>`;
a.appendChild(bar);
const wrap = el("div","card"); wrap.style.padding="0"; wrap.style.overflowX="auto";
const tb = el("table");
const cols = [["layer","L"],["feature","feature"],["description","description"],
["test_f1","test F1"],["_d","agent − Plan A"],["plan_a_f1","Plan A F1"],
["test_positives","test +"],["source","source"]];
const thead = el("thead"), tr = el("tr");
cols.forEach(([k,label])=>{
const th = el("th",S.sort.key===k?"sorted":"",
label + (S.sort.key===k ? (S.sort.dir<0?" ↓":" ↑") : ""));
if(["test_f1","_d","test_positives","layer","feature","plan_a_f1"].includes(k))
th.classList.add("num");
th.onclick=()=>{ if(S.sort.key===k) S.sort.dir*=-1; else {S.sort.key=k;S.sort.dir=-1;} draw(); };
tr.appendChild(th);
});
thead.appendChild(tr); tb.appendChild(thead);
const tbody = el("tbody"); tb.appendChild(tbody); wrap.appendChild(tb); a.appendChild(wrap);
function readFilters(){
f.layer=$("#fLayer").value; f.source=$("#fSource").value; f.outcome=$("#fOut").value;
f.low=$("#fLow").value; f.f1min=$("#fMin").value; f.f1max=$("#fMax").value;
f.q=$("#fQ").value.trim();
}
function rows(){
const q = f.q.toLowerCase();
return S.feats.filter(x=>{
if(f.layer && x.layer!==+f.layer) return false;
if(f.source && x.source!==f.source) return false;
if(f.outcome && x._o!==f.outcome) return false;
if(f.low==="1" && !x.low_support) return false;
if(f.low==="0" && x.low_support) return false;
if(f.f1min!=="" && x.test_f1 < +f.f1min) return false;
if(f.f1max!=="" && x.test_f1 > +f.f1max) return false;
if(q){
const d = (S.desc[x.layer+":"+x.feature]||"").toLowerCase();
if(!(String(x.feature).includes(q) || d.includes(q))) return false;
}
return true;
}).sort((p,r)=>{
const k=S.sort.key; let A=p[k],B=r[k];
if(k==="description"){A=S.desc[p.layer+":"+p.feature]||"";B=S.desc[r.layer+":"+r.feature]||"";}
if(typeof A==="string") return S.sort.dir*A.localeCompare(B);
return S.sort.dir*((A||0)-(B||0));
});
}
function draw(){
readFilters();
const rs = rows();
$("#cnt").textContent = `${rs.length.toLocaleString()} of ${S.feats.length.toLocaleString()} features`
+ (rs.length>400 ? " — showing the first 400" : "");
tbody.innerHTML="";
rs.slice(0,400).forEach(x=>{
const r = el("tr");
r.onclick=()=>{location.hash=`#/L${x.layer}/${x.feature}`;};
const d = S.desc[x.layer+":"+x.feature];
[[x.layer,"num"],[x.feature,"num"],
[d||"(none)", d?"":"muted"],
[f3(x.test_f1),"num"],
[(x._d>=0?"+":"")+x._d.toFixed(3),"num"],
[f3(x.plan_a_f1),"num"],
[x.test_positives.toLocaleString(),"num"],
[null,""]].forEach(([v,c],i)=>{
const td=el("td",c);
if(i===7){
td.appendChild(el("span","pill "+(x._o==="tie"?"":x._o), x._o));
if(x.source.startsWith("agent,")) td.appendChild(el("span","pill"," = Plan A"));
if(x.low_support) td.appendChild(el("span","pill","low support"));
} else td.textContent=v;
r.appendChild(td);
});
tbody.appendChild(r);
});
}
["fLayer","fSource","fOut","fLow"].forEach(i=>$("#"+i).onchange=draw);
["fMin","fMax","fQ"].forEach(i=>$("#"+i).oninput=draw);
draw();
}
/* --------------------------------------------------------- feature page */
function setBlock(name, members, open){
const n = members.length;
const d = el("details"); if(open) d.open = true;
d.appendChild(el("summary","",`${name} — ${n.toLocaleString()} token${n===1?"":"s"}`));
const b = el("div","body");
const pre = el("pre");
const show = open ? n : Math.min(30,n);
pre.textContent = members.slice(0,show).map(t=>JSON.stringify(t)).join(", ")
+ (show<n ? ", …" : "");
b.appendChild(pre);
if(n>30){
// Expand in pages. One of these sets has 20,210 members; rendering them
// all into a single text node is what makes a tab hang.
const PAGE = 2000;
let shown = 30;
const btn = el("button","tiny","");
const less = el("button","tiny","show first 30");
less.style.display = "none";
const note = el("span","tiny muted","");
const paint = ()=>{
pre.textContent = members.slice(0,shown).map(t=>JSON.stringify(t)).join(", ")
+ (shown<n ? ", …" : "");
btn.textContent = shown>=n ? "" :
`show ${Math.min(PAGE, n-shown).toLocaleString()} more`;
btn.style.display = shown>=n ? "none" : "";
less.style.display = shown>30 ? "" : "none";
note.textContent = `${shown.toLocaleString()} of ${n.toLocaleString()} shown`;
};
btn.onclick = ()=>{ shown = Math.min(n, shown + PAGE); paint(); };
less.onclick = ()=>{ shown = 30; paint(); };
b.appendChild(btn); b.appendChild(less); b.appendChild(note);
paint();
}
d.appendChild(b); return d;
}
async function featureView(L,F){
const a = $("#app");
// Navigation token. featureView is async and route() does not await it, so
// clicking a second feature while the first is still fetching used to let
// the slower one finish and overwrite the newer page — or drop its "could
// not load" box onto a feature that had loaded fine. Every write below is
// gated on still being the current navigation.
const myNav = ++S.nav;
const stale = () => S.nav !== myNav;
a.innerHTML = `<p class="muted"><span class="spin"></span>Loading L${L} feature ${F}…</p>`;
const meta = S.feats.find(x=>x.layer===L && x.feature===F);
if(!meta){ a.innerHTML = `<div class="err">L${L} feature ${F} is not one of the
${S.feats.length.toLocaleString()} scored features.</div>`; return; }
let prog, tr;
try{
const [P,T] = await Promise.all([layerProgs(L), layerTrans(L)]);
prog = P.programs.find(p=>p.feature===F);
tr = T.features.find(p=>p.feature===F);
}catch(e){
if(stale()) return;
if(e.offline){
// The data files and the API come from the same server, so if it is gone
// nothing more can load. Say so once, plainly, with the fix.
const alive = await backendAlive();
if(stale()) return;
if(!alive){
setMode(false);
a.innerHTML = `<div class="err"><b>The server has stopped.</b>
Nothing more can load — the feature data and the live check both come
from it.<br><br>Restart it and reload this page:
<pre style="margin-top:8px">cd space && uvicorn app:app --port 7860</pre>
<button id="retryBtn" class="tiny">Retry now</button></div>`;
const rb = $("#retryBtn");
if(rb) rb.onclick = async ()=>{
rb.disabled = true; rb.textContent = "checking…";
if(await backendAlive()){ setMode(true); featureView(L,F); }
else { rb.disabled = false; rb.textContent = "still down — retry"; }
};
return;
}
}
a.innerHTML = `<div class="err"><b>Could not load layer ${L} data.</b>
${esc(e.message)}<br><span class="tiny">If this mentions 404, the page is
newer than the server — restart it, then hard-reload (⇧⌘R / Ctrl-F5).
</span></div>`;
return;
}
if(stale()) return;
a.innerHTML = "";
/* ---- header */
const desc = S.desc[L+":"+F];
const h = el("div","card");
const npid = `gpt2-small/${L-1}-res_post_32k-oai/${F}`;
h.innerHTML = `
<div class="row" style="justify-content:space-between">
<div><strong style="font-size:17px">Layer ${L} · feature ${F.toLocaleString()}</strong>
<span class="pill ${meta._o==="tie"?"":meta._o}">${meta._o} vs Plan A</span>
${meta.source.startsWith("agent,")?'<span class="pill">= Plan A</span>':''}
${meta.low_support?'<span class="pill">low support</span>':''}</div>
<a class="tiny" target="_blank" rel="noopener"
href="https://neuronpedia.org/${npid}">Neuronpedia ↗</a>
</div>
<p style="margin:8px 0 10px">${desc?esc(desc):'<span class="muted">(no description)</span>'}</p>
<div class="row tiny">
<span>test F1 <b>${f3(meta.test_f1)}</b></span>
<span class="muted">P ${f3(meta.test_precision)} · R ${f3(meta.test_recall)}</span>
<span>Plan A F1 <b>${f3(meta.plan_a_f1)}</b> <span class="muted">(${esc(meta.plan_a_program)})</span></span>
<span>Δ <b>${(meta._d>=0?"+":"")+meta._d.toFixed(3)}</b></span>
<span>test positives <b>${meta.test_positives.toLocaleString()}</b></span>
<span class="muted">source: ${esc(meta.source)}</span>
</div>`;
a.appendChild(h);
/* ---- program */
const pc = el("div","card"); pc.appendChild(el("h2","","Program"));
if(!prog){ pc.appendChild(el("div","err","Program source is MISSING for this feature.")); }
else{
let src = prog.source;
// replace each set literal with a placeholder; the members get their own
// collapsible block so a 20,000-token set cannot blow up the page
const names = Object.keys(prog.sets||{});
names.forEach(n=>{
src = src.replace(new RegExp(`^(\\s*${n} = ).*$`,"m"),
(_,p1)=>`${p1}{…${(prog.sets[n]||[]).length.toLocaleString()} tokens, below…}`);
});
const pre = el("pre"); pre.textContent = src; pc.appendChild(pre);
names.forEach(n=> pc.appendChild(setBlock(n, prog.sets[n]||[], (prog.sets[n]||[]).length<=30)));
const hd = el("details");
hd.appendChild(el("summary","","helpers these programs call"));
const hb = el("div","body"); const hp = el("pre");
hp.textContent = (S.helpers&&S.helpers.helpers_source)||"(loading…)";
hb.appendChild(hp); hd.appendChild(hb); pc.appendChild(hd);
if(!S.helpers) getJSON("programs/helpers.json").then(x=>{S.helpers=x;hp.textContent=x.helpers_source;}).catch(()=>{});
}
a.appendChild(pc);
/* ---- examples */
const ec = el("div","card");
ec.appendChild(el("h2","",`Examples the agent saw (${(tr&&!isMissing(tr.examples)?tr.examples.length:0)})`));
if(!tr || isMissing(tr.examples) || !tr.examples.length){
ec.appendChild(el("div","muted","MISSING — no examples recorded for this feature."));
} else {
ec.appendChild(el("p","tiny muted",
"A deduplicated random sample of firing positions; the firing token is marked. "
+ (S.live ? "“try” sends the surrounding text to the live check."
: "Running them needs the local version.")));
const box = el("div"); box.style.maxHeight="340px"; box.style.overflowY="auto";
tr.examples.forEach(x=>{
const row = el("div","ex");
const t = el("div","t");
// the renderer marks the firing token as [[tok]]
t.innerHTML = esc(x).replace(/\[\[([\s\S]*?)\]\]/g, (_,m)=>`<mark>${m}</mark>`);
row.appendChild(t);
if(S.live){
const b = el("button","tiny","try");
b.onclick=()=>{
const plain = x.replace(/^\.\.\./,"").replace(/\[\[([\s\S]*?)\]\]/g,"$1");
const ta = $("#lcText"); if(!ta) return;
ta.value = plain; ta.dispatchEvent(new Event("input"));
window.__lcExpect = plain;
$("#lcRun").click();
ta.scrollIntoView({behavior:"smooth",block:"center"});
};
row.appendChild(b);
}
box.appendChild(row);
});
ec.appendChild(box);
}
a.appendChild(ec);
/* ---- transcript */
a.appendChild(transcript(tr, meta));
/* ---- the v2 agent's run on the same feature, below v1 */
const v2c = el("div","card");
v2c.appendChild(el("h2","","Transcript — v2 agent"));
v2c.appendChild(el("div","muted","Loading…"));
a.appendChild(v2c);
layerV2(L).then(d=>{
const rec = d && d.features ? d.features.find(x=>x.feature===F) : null;
const built = transcriptV2(rec);
v2c.replaceWith(built);
}).catch(()=>{
v2c.innerHTML = "";
v2c.appendChild(el("h2","","Transcript — v2 agent"));
v2c.appendChild(el("div","err","MISSING — the v2 data could not be loaded."));
});
/* ---- false negatives, then false positives, before the live check */
const fnc = el("div","card");
fnc.appendChild(el("h2","","False negatives"));
fnc.appendChild(el("div","muted","Loading…"));
a.appendChild(fnc);
const fpc = el("div","card");
fpc.appendChild(el("h2","","False positives"));
fpc.appendChild(el("div","muted","Loading…"));
a.appendChild(fpc);
layerFN(L).then(d=>{
const rec = (d && d.features) ? d.features[String(F)] : null;
fnc.innerHTML = ""; fpc.innerHTML = "";
if(!rec){
fnc.appendChild(el("h2","","False negatives"));
fnc.appendChild(el("div","muted","MISSING — no record for this feature."));
fpc.appendChild(el("h2","","False positives"));
fpc.appendChild(el("div","muted","MISSING — no record for this feature."));
return;
}
/* false negatives */
fnc.appendChild(el("h2","",
`False negatives (${rec.n_shown.toLocaleString()} of `
+ `${rec.n_false_negatives.toLocaleString()} shown)`));
fnc.appendChild(el("p","tiny muted",
`Held-out TEST positions where the feature fires and the program does `
+ `not — ${rec.n_false_negatives.toLocaleString()} of its `
+ `${rec.n_firings_test.toLocaleString()} test firings are missed. `
+ `Largest activation first. `
+ (S.live ? "“try” sends the surrounding text to the live check."
: "Running them needs the local version.")));
if(!rec.n_false_negatives)
fnc.appendChild(el("div","muted","None — the program catches every firing."));
else fnc.appendChild(errorRows(rec.examples, S.live));
/* false positives */
const nfp = rec.n_false_positives || 0;
fpc.appendChild(el("h2","",
`False positives (${(rec.n_fp_shown||0).toLocaleString()} of `
+ `${nfp.toLocaleString()} shown)`));
fpc.appendChild(el("p","tiny muted",
`Held-out TEST positions where the program fires and the feature does `
+ `not. Ordered by how many false positives share the scored token, so `
+ `the most systematic false alarm comes first. `
+ (S.live ? "“try” sends the surrounding text to the live check."
: "Running them needs the local version.")));
if(!nfp)
fpc.appendChild(el("div","muted","None — the program never fires where the feature is silent."));
else fpc.appendChild(errorRows(rec.fp_examples||[], S.live));
}).catch(e=>{
const msg = "Could not load: "+(e&&e.message||e);
fnc.innerHTML=""; fnc.appendChild(el("h2","","False negatives"));
fnc.appendChild(el("div","err",msg));
fpc.innerHTML=""; fpc.appendChild(el("h2","","False positives"));
fpc.appendChild(el("div","err",msg));
});
/* ---- live check, last on the page */
if(S.live) a.appendChild(liveCheck(L,F,meta));
else{
const n = el("div","info");
n.innerHTML = `The live check — run your own sentence and see the activation and
program output at every token — runs in the local version only.
This page is served as a static Space with no backend.`;
a.appendChild(n);
}
}
/* -------------------------------------------------------- v2 transcript */
/* The second agent run: harness v2 + prompt v2. Shown below the v1
transcript so the two readings of the same feature sit together. The
programs here were verified position-by-position against the scored mask. */
function transcriptV2(v2){
const c = el("div","card"); c.appendChild(el("h2","","Transcript — v2 agent"));
if(!v2){ c.appendChild(el("div","err","MISSING — no v2 record for this feature.")); return c; }
const line = el("div","row tiny");
const kept = (v2.kept_round===0)
? `round 1, candidate ${(v2.kept_candidate||0)+1}`
: `round ${(v2.kept_round||0)+1}`;
line.innerHTML = `
<span>protocol <b>${esc(v2.protocol||"?")}</b>
<span class="muted">${esc(v2.protocol_note||"")}</span></span>
<span>proposals scored <b>${v2.rounds_used==null?"MISSING":v2.rounds_used}</b></span>
<span>invalid <b>${v2.invalid==null?0:v2.invalid}</b></span>
<span>kept: <b>${kept}</b></span>
<span>cross-validated F1 <b>${f3(v2.cross_validated_f1)}</b></span>
<span>test F1 <b>${f3(v2.test_f1)}</b>
<span class="muted">P ${f3(v2.test_precision)} / R ${f3(v2.test_recall)}</span></span>`;
c.appendChild(line);
c.appendChild(el("p","tiny muted",
"The kept program is the one with the best cross-validated F1 over three "
+ "folds of the fitting data, not the best fit."));
/* the final program, open by default: it is the thing most people want */
if(v2.program){
const pd = el("details"); pd.open = true;
pd.appendChild(el("summary","","final program — Python"));
const pb = el("div","body"); const pp = el("pre");
pp.textContent = v2.program; pb.appendChild(pp);
if(v2.set_sizes && Object.keys(v2.set_sizes).length){
pb.appendChild(el("div","tiny muted",
"set sizes: " + Object.entries(v2.set_sizes)
.map(([k,n])=>`${k} ${n}`).join(", ")));
}
pd.appendChild(pb); c.appendChild(pd);
} else {
c.appendChild(el("div","warn","MISSING — no program was rendered."));
}
const sd = el("details");
sd.appendChild(el("summary","","shared prompt text — the v2 grammar (identical for every feature)"));
const sb = el("div","body"); const sp = el("pre");
sp.textContent = (S.v2shared && S.v2shared.shared_prompt_prefix) || "MISSING";
sb.appendChild(sp); sd.appendChild(sb); c.appendChild(sd);
const fd0 = el("details");
fd0.appendChild(el("summary","","round 1 — prompt sent to the agent (feature-specific part)"));
const f0 = el("div","body"); const f0p = el("pre");
f0p.textContent = v2.prompt_tail || "MISSING";
f0.appendChild(f0p); fd0.appendChild(f0); c.appendChild(fd0);
(v2.rounds||[]).forEach(r=>{
const d = el("details");
const rn = (r.round==null?"?":r.round+1);
if(r.reply!==undefined){
d.appendChild(el("summary","",`round ${rn} — agent reply`));
const b = el("div","body");
if(r.rationale){
b.appendChild(el("div","tiny muted","rationale"));
b.appendChild(el("p","tiny",r.rationale));
}
const pre = el("pre"); pre.textContent = r.reply; b.appendChild(pre);
d.appendChild(b);
} else if(r.spec!==undefined){
const h = r.harness||{};
const cand = (r.candidate==null)?"":` candidate ${r.candidate+1}`;
const cv = h.cross_validated_f1;
d.appendChild(el("summary","",
`round ${rn}${cand} — harness`
+ (cv!=null?` — cross-validated F1 ${f3(cv)}`:"")));
const b = el("div","body");
b.appendChild(el("div","tiny muted","program proposed"));
const p1 = el("pre"); p1.textContent = JSON.stringify(r.spec,null,1); b.appendChild(p1);
if(r.fit_settings && Object.keys(r.fit_settings).length){
b.appendChild(el("div","tiny muted","fit settings"));
const p2 = el("pre"); p2.textContent = JSON.stringify(r.fit_settings,null,1);
b.appendChild(p2);
}
b.appendChild(el("div","tiny muted","harness reply"));
const p3 = el("pre"); p3.textContent = JSON.stringify(h,null,1); b.appendChild(p3);
if(h.false_negatives_shown || h.false_positives_shown){
b.appendChild(el("p","tiny muted",
`wrong positions: ${h.n_false_negatives==null?"?":h.n_false_negatives} missed, `
+ `${h.n_false_positives==null?"?":h.n_false_positives} spurious; `
+ `the agent saw all of them, this panel lists the first `
+ `${h.false_negatives_shown||h.false_positives_shown} of each.`));
}
d.appendChild(b);
} else if(r.validator_error){
d.appendChild(el("summary","",`round ${rn} — rejected by the validator`));
const b = el("div","body"); b.appendChild(el("div","err",r.validator_error));
d.appendChild(b);
} else if(r.harness_error){
d.appendChild(el("summary","",`round ${rn} — ${r.harness_error}`));
d.appendChild(el("div","body"));
} else if(r.submitted){
d.appendChild(el("summary","",`round ${rn} — agent submitted, stopping early`));
d.appendChild(el("div","body"));
}
c.appendChild(d);
});
return c;
}
/* ----------------------------------------------------------- transcript */
function transcript(tr, meta){
const c = el("div","card"); c.appendChild(el("h2","","Transcript"));
if(!tr){ c.appendChild(el("div","err","MISSING — no transcript record.")); return c; }
const kept = isMissing(tr.round1_kept) ? "MISSING"
: (tr.round1_kept ? "round 1" : "a later round");
const line = el("div","row tiny");
line.innerHTML = `
<span>rounds evaluated <b>${isMissing(tr.n_evaluated)?"MISSING":tr.n_evaluated}</b></span>
<span>invalid <b>${isMissing(tr.n_invalid)?"MISSING":tr.n_invalid}</b></span>
<span>kept: <b>${kept}</b></span>
<span>fit F1 <b>${f3(tr.agent_fit_f1)}</b></span>
<span>select F1 <b>${f3(tr.agent_select_f1)}</b>
<span class="muted">vs Plan A ${f3(tr.plan_a_select_f1)}</span></span>
<span>chosen on select: <b>${isMissing(tr.chosen)?"MISSING":esc(tr.chosen)}</b></span>`;
c.appendChild(line);
if(!isMissing(tr.plan_a_fit_f1_shown))
c.appendChild(el("p","tiny muted",
`Plan A fit F1 shown to the agent in the prompt: ${f3(tr.plan_a_fit_f1_shown)}`));
/* shared prompt, stored once for all 1,167 features */
const sd = el("details");
sd.appendChild(el("summary","","shared prompt text — the grammar and the ten program shapes (identical for every feature)"));
const sb = el("div","body"); const sp = el("pre");
sp.textContent = (S.shared && S.shared.shared_prompt_prefix) || "MISSING";
sb.appendChild(sp); sd.appendChild(sb); c.appendChild(sd);
if(isMissing(tr.messages)){
c.appendChild(el("div","warn","MISSING — the conversation could not be recovered from the cache."));
return c;
}
/* round 1 = the first user message (feature-specific tail), then each
assistant reply paired with the harness report that answered it */
const first = el("details"); first.open = false;
first.appendChild(el("summary","","round 1 — prompt sent to the agent (feature-specific part)"));
const fb = el("div","body"); const fp = el("pre");
fp.textContent = isMissing(tr.prompt_tail) ? "MISSING" : tr.prompt_tail;
fb.appendChild(fp); first.appendChild(fb); c.appendChild(first);
const msgs = tr.messages || [];
let round = 0;
for(let i=0;i<msgs.length;i++){
const m = msgs[i];
if(m.role!=="assistant") continue;
round++;
const nxt = msgs[i+1] && msgs[i+1].role==="user" ? msgs[i+1].content : null;
const d = el("details");
let spec = null, parsed = "";
try{ const o = JSON.parse(m.content); spec = o.spec || null;
parsed = o.action ? `action: ${o.action}` : ""; }catch(e){ parsed = "unparseable JSON"; }
let fit = null;
if(nxt){ try{ const r = JSON.parse(nxt); fit = r.fit_f1; }catch(e){} }
d.appendChild(el("summary","",
`round ${round}` + (fit!==undefined && fit!==null ? ` — harness fit F1 ${f3(fit)}` : "")
+ (parsed?` — ${parsed}`:"")));
const b = el("div","body");
b.appendChild(el("div","tiny muted","agent response"));
const p1 = el("pre"); p1.textContent = m.content; b.appendChild(p1);
if(spec){
b.appendChild(el("div","tiny muted","parsed program"));
const p2 = el("pre"); p2.textContent = JSON.stringify(spec,null,1); b.appendChild(p2);
}
b.appendChild(el("div","tiny muted", nxt ? "harness reply" : "harness reply — none (final round)"));
const p3 = el("pre"); p3.textContent = nxt || "MISSING"; b.appendChild(p3);
d.appendChild(b); c.appendChild(d);
}
const fd = el("details");
fd.appendChild(el("summary","","final reply — the spec that was kept"));
const fbb = el("div","body"); const fpp = el("pre");
fpp.textContent = isMissing(tr.final_reply) ? "MISSING" : tr.final_reply;
fbb.appendChild(fpp);
if(!isMissing(tr.agent_spec)){
fbb.appendChild(el("div","tiny muted","spec kept and re-fitted"));
const q = el("pre"); q.textContent = JSON.stringify(tr.agent_spec,null,1); fbb.appendChild(q);
}
fd.appendChild(fbb); c.appendChild(fd);
return c;
}
/* ---------------------------------------------------------- live check */
const STATES = {
both: ["both","fires & program yes"],
progonly: ["progonly","program yes, no firing"],
fireonly: ["fireonly","fires, program no"],
neither: ["neither","neither"],
crash: ["crash","program crashed"],
unscored: ["unscored","unscored (0, 1)"],
};
function tokenState(i, firstScored, fires, program){
if(i < firstScored) return "unscored";
const p = program[i];
if(p === null || p === undefined) return "crash";
if(fires[i] && p) return "both";
if(!fires[i] && p) return "progonly";
if(fires[i] && !p) return "fireonly";
return "neither";
}
function histKey(L,F){ return `saeviewer:hist:L${L}:F${F}`; }
function histLoad(L,F){
try{ return JSON.parse(localStorage.getItem(histKey(L,F))||"[]"); }catch(e){ return []; }
}
function histPush(L,F,text){
try{
const h = histLoad(L,F).filter(x=>x!==text);
h.unshift(text);
localStorage.setItem(histKey(L,F), JSON.stringify(h.slice(0,12)));
}catch(e){ /* private mode, blocked storage, quota — never fatal */ }
}
function liveCheck(L,F,meta){
const c = el("div","card");
c.appendChild(el("h2","","Live check"));
const cap = (S.health && S.health.max_content_tokens) || 127;
c.innerHTML += `
<textarea id="lcText" rows="3" placeholder="Type a sentence and press Run…"></textarea>
<div class="row" style="margin-top:8px">
<button id="lcRun" class="primary">Run</button>
<span id="lcCount" class="tiny muted"></span>
<span style="flex:1"></span>
<span id="lcStatus" class="tiny muted"></span>
</div>
<div id="lcOut"></div>
<div id="lcHist"></div>`;
setTimeout(()=>wireLive(L,F,cap),0);
return c;
}
function wireLive(L,F,cap){
const ta=$("#lcText"), out=$("#lcOut"), st=$("#lcStatus"), cnt=$("#lcCount");
if(!ta) return;
const estimate = s => s ? Math.ceil(s.trim().split(/\s+/).length*1.35) : 0;
ta.oninput = ()=>{
const n = estimate(ta.value);
cnt.textContent = `≈${n} / ${cap} tokens`;
cnt.style.color = n>cap ? "var(--progonly)" : "";
cnt.title = "Rough estimate. The server counts exactly and caps at "+cap+".";
};
ta.oninput();
drawHist(L,F);
$("#lcRun").onclick = async ()=>{
const text = ta.value;
if(!text.trim()){ out.innerHTML = `<div class="warn">Type a sentence first.</div>`; return; }
const btn=$("#lcRun"); btn.disabled=true;
st.innerHTML = `<span class="spin"></span>running…`;
out.innerHTML = "";
const started = performance.now();
let slow = setTimeout(()=>{
if(!S.coldWarned){ st.innerHTML =
`<span class="spin"></span>first run — loading GPT-2 and the layer ${L} SAE…`; }
}, 2000);
let r, d;
try{
r = await fetch("api/run",{method:"POST",
headers:{"content-type":"application/json"},
body: JSON.stringify({text, layer:L, feature:F})});
d = await r.json();
}catch(e){
clearTimeout(slow); btn.disabled=false; st.textContent="";
out.innerHTML = `<div class="err"><b>Backend not reachable.</b> ${esc(e.message)}
— is the server still running?</div>`;
return;
}
clearTimeout(slow); btn.disabled=false;
const ms = Math.round(performance.now()-started);
st.textContent = `${ms} ms`;
if(ms>2000) S.coldWarned = true;
if(!r.ok || (d && d.error)){
out.innerHTML = `<div class="err">${esc(explainError(r.status, d))}</div>`;
return;
}
histPush(L,F,text); drawHist(L,F);
renderRun(d, out, L, F);
};
}
function explainError(status, d){
const raw = (d && d.error) ? String(d.error) : `HTTP ${status}`;
if(status===413) return "That text is too long to send. Shorten it and try again.";
if(/exceeds .* bytes/.test(raw)) return "That text is too long to send. Shorten it and try again.";
if(/not one of the/.test(raw)) return "This feature is not one of the 1,167 scored features, so it has no program to run.";
if(/at least \d+ tokens/.test(raw)) return "Too short — type at least a couple of words.";
if(/less than or equal|greater than or equal|Input should/.test(raw))
return "The request was rejected as invalid: " + raw.replace(/^invalid request:\s*/,"");
if(/missing from all_programs/.test(raw)) return "This feature's program is missing from the shipped program file.";
return raw;
}
function renderRun(d, out, L, F){
out.innerHTML = "";
const firstScored = d.first_scored ?? FIRST_SCORED;
if(d.program_errors){
const w = el("div","err");
w.innerHTML = `<b>The program crashed at ${d.program_errors} position${d.program_errors===1?"":"s"}.</b>
Those are marked separately below — they are not a “no”.
<br><code>${esc(d.program_error_detail||"no detail returned")}</code>`;
out.appendChild(w);
}
if(d.preact_available === false){
out.appendChild(el("div","warn",
"Pre-activations were not available for this run, so the hover shows activation only."));
}
/* did we get back the tokens the example implied? */
if(window.__lcExpect){
const joined = d.tokens.slice(1).join("");
if(!joined.includes(window.__lcExpect.trim().slice(0,24))){
out.appendChild(el("div","warn",
"The tokens returned do not match the example text that was sent — "
+ "the tokenizer re-split it, so this is a different sequence from the one the label came from."));
}
window.__lcExpect = null;
}
const counts = {both:0,progonly:0,fireonly:0,neither:0,crash:0,unscored:0};
const strip = el("div"); strip.style.lineHeight="2";
d.tokens.forEach((t,i)=>{
const s = tokenState(i, firstScored, d.fires, d.program);
counts[s]++;
const sp = el("span","tok "+s);
sp.textContent = t.replace(/\n/g,"⏎").replace(/^ /,"␣");
const act = d.activation[i], pre = d.preact ? d.preact[i] : null;
sp.dataset.tip = `#${i} ${JSON.stringify(t)}\n`
+ (i<firstScored ? "unscored position"
: `activation ${act===null?"—":Number(act).toFixed(4)}\n`
+ `preact ${pre===null||pre===undefined?"—":Number(pre).toFixed(4)}\n`
+ `fires ${d.fires[i]}\n`
+ `program ${d.program[i]===null?"crashed":d.program[i]}`);
strip.appendChild(sp);
});
out.appendChild(strip);
const lg = el("div","legend");
Object.entries(STATES).forEach(([k,[cls,label]])=>{
const s = el("span","", `${label} · ${counts[k]}`);
s.className = "tok "+cls; lg.appendChild(s);
});
out.appendChild(lg);
const agree = counts.both + counts.neither;
const scored = d.tokens.length - firstScored;
out.appendChild(el("div","tiny muted",
`${agree} of ${scored} scored positions agree · `
+ `${counts.fireonly} missed firing${counts.fireonly===1?"":"s"} · `
+ `${counts.progonly} false positive${counts.progonly===1?"":"s"}`
+ (counts.crash?` · ${counts.crash} crashed`:"")));
}
/* tooltip: hover on a laptop, tap on a phone */
(function(){
const tip = $("#tip");
function show(e,t){
tip.textContent = t; tip.style.display="block";
const r = tip.getBoundingClientRect();
let x = (e.clientX||0)+12, y=(e.clientY||0)+14;
if(x+r.width > innerWidth-8) x = innerWidth-r.width-8;
if(y+r.height > innerHeight-8) y = (e.clientY||0)-r.height-10;
tip.style.left=x+"px"; tip.style.top=Math.max(8,y)+"px";
}
document.addEventListener("mouseover",e=>{
const t=e.target.closest(".tok"); if(t&&t.dataset.tip) show(e,t.dataset.tip);
else tip.style.display="none";
});
document.addEventListener("mousemove",e=>{
const t=e.target.closest(".tok");
if(t&&t.dataset.tip && tip.style.display==="block") show(e,t.dataset.tip);
});
document.addEventListener("click",e=>{
const t=e.target.closest(".tok");
if(t&&t.dataset.tip) show(e,t.dataset.tip); else tip.style.display="none";
});
})();
function drawHist(L,F){
const box = $("#lcHist"); if(!box) return;
const h = histLoad(L,F);
box.innerHTML = "";
if(!h.length) return;
box.appendChild(el("div","tiny muted","Tried on this feature (kept in this browser only)"));
h.forEach(t=>{
const r = el("div","hist", t.length>90 ? t.slice(0,90)+"…" : t);
r.title = "click to load";
r.onclick=()=>{ const ta=$("#lcText"); ta.value=t; ta.dispatchEvent(new Event("input")); };
box.appendChild(r);
});
}
/* -------------------------------------------------------------- routing */
function route(){
const m = /^#\/L(\d+)\/(\d+)/.exec(location.hash||"");
if(m) featureView(+m[1], +m[2]);
else listView();
window.scrollTo(0,0);
}
$("#homeBtn").onclick = ()=>{ location.hash = ""; if(!location.hash) route(); };
$("#themeBtn").onclick = ()=>{
const cur = document.documentElement.getAttribute("data-theme");
const next = cur==="dark" ? "light" : cur==="light" ? "dark"
: (matchMedia("(prefers-color-scheme: dark)").matches ? "light" : "dark");
document.documentElement.setAttribute("data-theme", next);
try{ localStorage.setItem("saeviewer:theme", next); }catch(e){}
};
try{
const t = localStorage.getItem("saeviewer:theme");
if(t) document.documentElement.setAttribute("data-theme", t);
}catch(e){}
boot();
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SAE Feature Viewer</title>
<style>
:root{
--bg:#fff; --panel:#fafafa; --ink:#15151a; --dim:#5d5d68; --faint:#8a8a96;
--rule:#e4e4ea; --accent:#674ea7; --accent-soft:#efeaf8;
--both:#2f7d4f; --both-bg:#dff1e4;
--progonly:#9a6a00; --progonly-bg:#fdf0d0;
--fireonly:#1d5fa8; --fireonly-bg:#dceafa;
--crash:#b3261e; --crash-bg:#fbe0de;
--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
--bg:#131318; --panel:#1b1b22; --ink:#ececf1; --dim:#a4a4b2; --faint:#74747f;
--rule:#2c2c36; --accent:#b4a7d6; --accent-soft:#2a2440;
--both:#79d79b; --both-bg:#1d3a28;
--progonly:#e8c06a; --progonly-bg:#3b3015;
--fireonly:#86b6f0; --fireonly-bg:#17293f;
--crash:#f0908a; --crash-bg:#3d1b1a;
}}
:root[data-theme="dark"]{
--bg:#131318; --panel:#1b1b22; --ink:#ececf1; --dim:#a4a4b2; --faint:#74747f;
--rule:#2c2c36; --accent:#b4a7d6; --accent-soft:#2a2440;
--both:#79d79b; --both-bg:#1d3a28;
--progonly:#e8c06a; --progonly-bg:#3b3015;
--fireonly:#86b6f0; --fireonly-bg:#17293f;
--crash:#f0908a; --crash-bg:#3d1b1a;
}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);
font:15px/1.5 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;}
a{color:var(--accent)}
header{position:sticky;top:0;z-index:20;background:var(--bg);
border-bottom:1px solid var(--rule);padding:10px 16px;display:flex;
gap:12px;align-items:center;flex-wrap:wrap}
header h1{font-size:15px;margin:0;font-weight:650;letter-spacing:-.01em}
.badge{font-size:11px;padding:2px 8px;border-radius:999px;border:1px solid var(--rule);
color:var(--dim);white-space:nowrap}
.badge.live{color:var(--both);border-color:var(--both);background:var(--both-bg)}
.badge.browse{color:var(--dim)}
main{max-width:1060px;margin:0 auto;padding:18px 16px 80px}
button{font:inherit;color:var(--ink);background:var(--panel);
border:1px solid var(--rule);border-radius:7px;padding:5px 11px;cursor:pointer}
button:hover{border-color:var(--accent)}
button.primary{background:var(--accent);color:#fff;border-color:var(--accent);font-weight:600}
button.primary:disabled{opacity:.5;cursor:not-allowed}
select,input[type=text],input[type=number],textarea{font:inherit;color:var(--ink);
background:var(--bg);border:1px solid var(--rule);border-radius:7px;padding:5px 8px}
textarea{width:100%;font-family:var(--mono);font-size:13px;resize:vertical}
code,pre{font-family:var(--mono)}
pre{background:var(--panel);border:1px solid var(--rule);border-radius:8px;
padding:11px 13px;overflow-x:auto;font-size:12.5px;line-height:1.55;margin:0}
.muted{color:var(--dim)}
.tiny{font-size:12px}
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
.card{background:var(--panel);border:1px solid var(--rule);border-radius:10px;
padding:14px;margin:14px 0}
h2{font-size:14px;margin:0 0 9px;letter-spacing:.02em;text-transform:uppercase;
color:var(--dim);font-weight:650}
table{width:100%;border-collapse:collapse;font-size:13.5px}
th,td{text-align:left;padding:6px 9px;border-bottom:1px solid var(--rule)}
th{color:var(--dim);font-weight:600;font-size:12px;cursor:pointer;white-space:nowrap}
th.sorted{color:var(--accent)}
tbody tr{cursor:pointer}
tbody tr:hover{background:var(--accent-soft)}
.num{text-align:right;font-variant-numeric:tabular-nums}
.pill{font-size:11px;padding:1px 7px;border-radius:999px;border:1px solid var(--rule);
color:var(--dim);white-space:nowrap;display:inline-block;margin:1px 2px 1px 0}
.pill.win{color:var(--both);border-color:var(--both)}
.pill.loss{color:var(--crash);border-color:var(--crash)}
.tok{display:inline-block;padding:2px 3px;margin:1px 0;border-radius:4px;
font-family:var(--mono);font-size:13px;white-space:pre;cursor:default;
border:1px solid transparent}
.tok.unscored{color:var(--faint);background:transparent}
.tok.neither{color:var(--dim)}
.tok.both{color:var(--both);background:var(--both-bg);border-color:var(--both)}
.tok.progonly{color:var(--progonly);background:var(--progonly-bg);border-color:var(--progonly)}
.tok.fireonly{color:var(--fireonly);background:var(--fireonly-bg);border-color:var(--fireonly)}
.tok.crash{color:var(--crash);background:var(--crash-bg);border-color:var(--crash)}
.legend{display:flex;gap:7px;flex-wrap:wrap;font-size:12px;margin:9px 0}
.legend span{padding:2px 8px;border-radius:5px;border:1px solid}
details{border:1px solid var(--rule);border-radius:8px;margin:7px 0;background:var(--bg)}
details>summary{cursor:pointer;padding:8px 11px;font-size:13px;color:var(--dim)}
details[open]>summary{border-bottom:1px solid var(--rule);color:var(--ink)}
details .body{padding:11px}
.ex{font-family:var(--mono);font-size:12.5px;padding:5px 7px;border-bottom:1px solid var(--rule);
display:flex;gap:8px;align-items:flex-start}
.ex .t{flex:1;white-space:pre-wrap;word-break:break-word}
.ex mark{background:var(--both-bg);color:var(--both);border-radius:3px;padding:0 2px;font-weight:600}
.err{border-left:3px solid var(--crash);background:var(--crash-bg);color:var(--crash);
padding:9px 12px;border-radius:0 7px 7px 0;margin:9px 0;font-size:13.5px}
.warn{border-left:3px solid var(--progonly);background:var(--progonly-bg);color:var(--progonly);
padding:9px 12px;border-radius:0 7px 7px 0;margin:9px 0;font-size:13.5px}
.info{border-left:3px solid var(--accent);background:var(--accent-soft);
padding:9px 12px;border-radius:0 7px 7px 0;margin:9px 0;font-size:13.5px}
.spin{display:inline-block;width:12px;height:12px;border:2px solid var(--rule);