7 7 <
meta charset=
"utf-8">
8 8 <
meta name=
"viewport" content=
"width=device-width, initial-scale=1">
9 9 <
title>__AUTORESEARCH_TITLE__</
title>
12 + const mode
= localStorage.getItem(
"diff-review-theme")
|| "system";
13 + const systemLight
= matchMedia(
"(prefers-color-scheme: light)").matches;
14 + document.documentElement.dataset.themeMode
= mode;
15 + document.documentElement.dataset.theme
= mode
=== "system" ? (systemLight
? "light" : "dark")
: mode;
11 - :root {
color-scheme: dark;
--bg:
#0d1117;
--panel:
#161b22;
--text:
#c9d1d9;
--muted:
#8b949e;
--line:
#30363d;
--good:
#3fb950;
--bad:
#f85149;
--warn:
#d29922;
--accent:
#58a6ff; }
20 + color-scheme: dark light;
23 + --nugu-debug:
#ed5eed;
24 + --nugu-error:
#e46479;
25 + --nugu-warning:
#9e9a69;
26 + --nugu-info:
#3ec5dd;
27 + --nugu-content-normal:
#ededed;
28 + --nugu-content-backdrop:
#121212;
29 + --nugu-content-accent:
#d151d1;
30 + --nugu-content-minor:
#8b8b8b;
31 + --nugu-content-focus:
#7ba1aa;
32 + --nugu-content-unfocus:
#5d5d5d;
33 + --nugu-content-important-local:
#b59ae4;
34 + --nugu-content-important-global:
#dfd3f3;
35 + --nugu-ui-normal:
#dbdbdb;
36 + --nugu-ui-backdrop:
#242424;
37 + --nugu-ui-accent:
#d86dd8;
38 + --nugu-ui-minor:
#9d9d9d;
39 + --nugu-ui-focus:
#9aabae;
40 + --nugu-ui-unfocus:
#6f6f6f;
41 + --nugu-ui-important-local:
#c9b6eb;
42 + --nugu-ui-important-global:
#f3effb;
44 + --bg:
var(
--nugu-content-backdrop);
45 + --panel:
color-mix(in srgb,
var(
--nugu-ui-backdrop)
86%,
var(
--nugu-content-backdrop));
46 + --panel-2:
var(
--nugu-ui-backdrop);
47 + --panel-3:
color-mix(in srgb,
var(
--nugu-ui-backdrop)
72%,
var(
--nugu-content-backdrop));
48 + --fg:
var(
--nugu-content-normal);
49 + --fg-soft:
var(
--nugu-ui-normal);
50 + --muted:
var(
--nugu-ui-minor);
51 + --faint:
var(
--nugu-ui-unfocus);
52 + --accent:
var(
--nugu-ui-accent);
53 + --accent-2:
var(
--nugu-info);
54 + --focus:
var(
--nugu-ui-focus);
55 + --border:
color-mix(in srgb,
var(
--nugu-ui-normal)
14%,
transparent);
56 + --shadow:
0 18px 60px color-mix(in srgb,
#000 45%,
transparent);
58 + font-family:
Inter,
ui-sans-serif,
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
sans-serif;
59 + background:
var(
--bg);
63 + :root[data-theme
="light"] {
64 + color-scheme: light;
65 + --nugu-debug:
#a112a1;
66 + --nugu-error:
#c0223c;
67 + --nugu-warning:
#242317;
68 + --nugu-info:
#13616e;
69 + --nugu-content-normal:
#121212;
70 + --nugu-content-backdrop:
#ededed;
71 + --nugu-content-accent:
#ae2eae;
72 + --nugu-content-minor:
#3b3b3b;
73 + --nugu-content-focus:
#184e5b;
74 + --nugu-content-unfocus:
#6f6f6f;
75 + --nugu-content-important-local:
#715696;
76 + --nugu-content-important-global:
#4f3c69;
77 + --nugu-ui-normal:
#242424;
78 + --nugu-ui-backdrop:
#dbdbdb;
79 + --nugu-ui-accent:
#922792;
80 + --nugu-ui-minor:
#292929;
81 + --nugu-ui-focus:
#15333b;
82 + --nugu-ui-unfocus:
#5d5d5d;
83 + --nugu-ui-important-local:
#604980;
84 + --nugu-ui-important-global:
#3e2f53;
85 + --panel:
color-mix(in srgb,
var(
--nugu-ui-backdrop)
72%,
white);
86 + --panel-2:
color-mix(in srgb,
var(
--nugu-ui-backdrop)
88%,
white);
87 + --panel-3:
color-mix(in srgb,
var(
--nugu-ui-backdrop)
55%,
white);
88 + --border:
color-mix(in srgb,
var(
--nugu-ui-normal)
16%,
transparent);
89 + --shadow:
0 18px 60px color-mix(in srgb,
#000 14%,
transparent);
12 92 * {
box-sizing:
border-box; }
13 - body {
margin:
0;
background:
var(
--bg);
color:
var(
--text);
font:
14px/
1.45 system-ui,
-apple-system,
Segoe UI,
Roboto,
sans-serif; }
14 - main {
max-width:
1180px;
margin:
0 auto;
padding:
24px; }
15 - header {
display:
flex;
justify-content:
space-between; gap:
16px;
align-items:
flex-start;
margin-bottom:
16px; }
16 - h1 {
margin:
0;
color:
#fff;
font-size:
26px; }
17 - .meta {
margin-top:
6px;
color:
var(
--muted);
font-size:
13px; }
18 - .grid {
display:
grid;
grid-template-columns:
2fr 1.2fr .8fr .8fr; gap:
12px;
margin:
16px 0; }
19 - .card, .panel {
background:
var(
--panel);
border:
1px solid var(
--line);
border-radius:
12px; }
20 - .card {
padding:
14px; }
21 - .label {
color:
var(
--muted);
font-size:
11px;
text-transform:
uppercase;
letter-spacing:
.07em; }
22 - .value {
margin-top:
7px;
font:
700 24px ui-monospace,
SFMono-Regular,
Menlo,
monospace; }
23 - .good {
color:
var(
--good); } .bad {
color:
var(
--bad); } .warn {
color:
var(
--warn); } .muted {
color:
var(
--muted); }
24 - .panel {
overflow:
hidden;
margin-top:
14px; }
25 - .chart-wrap {
height:
300px;
padding:
12px; }
26 - canvas {
width:
100%;
height:
100%;
display:
block; }
27 - table {
width:
100%;
border-collapse:
collapse;
font-size:
12px; }
28 - th,
td {
padding:
10px;
border-bottom:
1px solid #222a33;
text-align:
left;
vertical-align:
top; }
29 - th {
position:
sticky;
top:
0;
background:
#11161c;
color:
var(
--muted);
font-size:
11px;
text-transform:
uppercase;
letter-spacing:
.05em;
white-space:
nowrap; }
30 - .mono {
font-family:
ui-monospace,
SFMono-Regular,
Menlo,
monospace; }
31 - .status {
display:
inline-block;
padding:
2px 7px;
border-radius:
999px;
font-weight:
700;
font-size:
11px; }
32 - .status.keep {
color:
var(
--good);
background:
rgba(
63,
185,
80,
.15); }
33 - .status.discard {
color:
#ff9b95;
background:
rgba(
248,
81,
73,
.14); }
34 - .status.crash {
color:
var(
--bad);
background:
rgba(
248,
81,
73,
.22); }
35 - .status.checks_failed {
color:
var(
--warn);
background:
rgba(
210,
153,
34,
.18); }
36 - .best-row {
background:
rgba(
63,
185,
80,
.07); }
37 - .notice {
padding:
14px;
color:
var(
--warn); }
38 - @media (
max-width:
850px) { .grid {
grid-template-columns:
1fr 1fr; }
main {
padding:
14px; } }
93 + html,
body {
min-height:
100%; }
97 + radial-gradient(
circle at top left, color-mix(in srgb, var(--accent)
12%,
transparent), transparent 28rem),
100 + font:
14px/
1.45 Inter,
ui-sans-serif,
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
sans-serif;
102 + button,
select {
font:
inherit; }
103 + code, .mono, .value,
table {
font-family:
"JetBrains Mono Nerd",
"JetBrains Mono",
"Fira Code",
ui-monospace,
SFMono-Regular,
Menlo,
Consolas,
monospace; }
107 + grid-template-columns:
minmax(
0,
1fr)
360px;
110 + #main {
min-width:
0; }
113 + align-items:
center;
114 + justify-content:
space-between;
116 + padding:
16px 18px 12px;
117 + border-bottom:
1px solid var(
--border);
118 + background:
color-mix(in srgb,
var(
--bg)
92%,
var(
--panel));
122 + backdrop-
filter:
blur(
10px);
124 + .brand {
display:
grid;
grid-template-columns:
1fr auto; gap:
10px;
align-items:
start; }
125 + h1 {
font-size:
22px;
line-height:
1;
margin:
0;
letter-spacing:
-0.03em;
color:
var(
--nugu-content-important-global); }
127 + display:
inline-flex;
128 + align-items:
center;
129 + width:
fit-content;
132 + border:
1px solid color-mix(in srgb,
var(
--accent)
24%,
transparent);
133 + border-radius:
999px;
134 + background:
linear-gradient(
135deg, color-mix(in srgb, var(--accent)
14%,
transparent),
color-mix(in srgb, var(
--accent-2) 10%, transparent));
135 + color:
color-mix(in srgb,
var(
--fg-soft)
72%,
var(
--muted));
139 + .theme-label {
display:
inline-flex;
align-items:
center; gap:
6px;
color:
var(
--muted);
font-size:
12px; }
140 + .theme-label
select {
142 + border:
1px solid var(
--border);
143 + border-radius:
999px;
144 + background:
color-mix(in srgb,
var(
--bg)
60%,
var(
--panel-2));
148 + .theme-label
select:focus {
border-color:
var(
--focus);
box-shadow:
0 0 0 3px color-mix(in srgb,
var(
--focus)
22%,
transparent); }
149 + #summary {
color:
var(
--muted);
font-size:
12px;
line-height:
1.35;
margin-top:
6px; }
151 + .content {
padding:
16px 18px 24px; }
152 + .cards {
display:
grid;
grid-template-columns:
minmax(
220px,
2fr)
minmax(
160px,
1.3fr)
minmax(
110px,
.7fr)
minmax(
110px,
.7fr); gap:
12px; }
153 + .card, .panel, #drawer {
border:
1px solid var(
--border);
background:
color-mix(in srgb,
var(
--panel-3)
72%,
transparent);
border-radius:
var(
--radius); }
154 + .card {
padding:
12px;
min-width:
0; }
155 + .card-title {
color:
var(
--nugu-content-important-global);
font-weight:
800;
font-size:
15px;
margin-bottom:
8px; }
156 + .label {
color:
var(
--muted);
font-size:
11px;
text-transform:
uppercase;
letter-spacing:
.07em;
font-weight:
800; }
157 + .value {
margin-top:
7px;
color:
var(
--nugu-content-important-global);
font-size:
24px;
font-weight:
850;
white-space:
nowrap;
overflow:
hidden;
text-overflow:
ellipsis; }
158 + .value.good {
color:
var(
--nugu-info); }
159 + .value.bad {
color:
var(
--nugu-error); }
160 + .panel {
margin-top:
14px;
overflow:
hidden; }
161 + .chart-wrap {
height:
320px;
padding:
12px;
background:
color-mix(in srgb,
var(
--panel-2)
38%,
transparent); }
162 + canvas {
width:
100%;
height:
100%;
display:
block; }
165 + border-width:
0 0 0 1px;
167 + background:
color-mix(in srgb,
var(
--panel)
95%,
transparent);
168 + padding:
16px 14px;
172 + display:
inline-flex;
173 + align-items:
center;
174 + justify-content:
center;
177 + border-radius:
999px;
178 + border:
1px solid color-mix(in srgb,
var(
--accent)
35%,
var(
--border));
179 + background:
color-mix(in srgb,
var(
--accent)
16%,
transparent);
180 + color:
var(
--nugu-content-important-global);
184 + .stat-list {
display:
grid; gap:
8px; }
185 + .stat-row {
display:
flex;
justify-content:
space-between; gap:
10px;
padding:
8px 0;
border-bottom:
1px solid color-mix(in srgb,
var(
--border)
62%,
transparent); }
186 + .stat-row:last-child {
border-bottom:
0; }
187 + .stat-row
span:first-child {
color:
var(
--muted); }
188 + .stat-row
span:last-child {
color:
var(
--fg);
font-weight:
800; }
190 + table {
width:
100%;
border-collapse:
collapse;
font-size:
12px; }
191 + th,
td {
padding:
10px;
border-bottom:
1px solid color-mix(in srgb,
var(
--border)
62%,
transparent);
text-align:
left;
vertical-align:
top; }
192 + th {
position:
sticky;
top:
63px;
background:
color-mix(in srgb,
var(
--bg)
92%,
var(
--panel));
color:
var(
--muted);
font-size:
11px;
text-transform:
uppercase;
letter-spacing:
.05em;
white-space:
nowrap;
z-index:
2; }
193 + td {
color:
color-mix(in srgb,
var(
--fg)
88%,
var(
--muted)); }
194 + .status {
display:
inline-block;
padding:
2px 7px;
border-radius:
999px;
font-weight:
800;
font-size:
11px; }
195 + .status.keep {
color:
var(
--nugu-info);
background:
color-mix(in srgb,
var(
--nugu-info)
14%,
transparent);
border:
1px solid color-mix(in srgb,
var(
--nugu-info)
28%,
var(
--border)); }
196 + .status.discard {
color:
var(
--nugu-warning);
background:
color-mix(in srgb,
var(
--nugu-warning)
12%,
transparent);
border:
1px solid color-mix(in srgb,
var(
--nugu-warning)
24%,
var(
--border)); }
197 + .status.crash, .status.checks_failed {
color:
var(
--nugu-error);
background:
color-mix(in srgb,
var(
--nugu-error)
14%,
transparent);
border:
1px solid color-mix(in srgb,
var(
--nugu-error)
28%,
var(
--border)); }
198 + .best-row {
background:
color-mix(in srgb,
var(
--accent)
8%,
transparent); }
199 + .good {
color:
var(
--nugu-info); }
200 + .bad {
color:
var(
--nugu-error); }
201 + .warn {
color:
var(
--nugu-warning); }
202 + .muted {
color:
var(
--muted); }
203 + .notice {
padding:
14px;
color:
var(
--nugu-warning); }
208 + max-width: min(
520px,
calc(
100vw - 32px));
210 + border:
1px solid var(
--border);
211 + border-radius:
999px;
212 + background:
color-mix(in srgb,
var(
--bg)
65%,
var(
--panel));
213 + box-shadow:
var(
--shadow);
214 + color:
var(
--muted);
216 + white-space:
nowrap;
218 + text-overflow:
ellipsis;
220 + #status::before {
content:
"";
display:
inline-block;
width:
7px;
height:
7px;
margin-right:
7px;
border-radius:
50%;
background:
var(
--muted);
vertical-align:
1px; }
221 + #status.ok {
color:
var(
--nugu-info);
border-color:
color-mix(in srgb,
var(
--nugu-info)
34%,
var(
--border)); }
222 + #status.ok::before {
background:
var(
--nugu-info);
box-shadow:
0 0 14px var(
--nugu-info); }
223 + #status.error {
color:
var(
--nugu-error);
border-color:
color-mix(in srgb,
var(
--nugu-error)
40%,
var(
--border)); }
224 + #status.error::before {
background:
var(
--nugu-error);
box-shadow:
0 0 14px var(
--nugu-error); }
226 + @media (
max-width:
980px) {
227 + #app {
grid-template-columns:
1fr; }
228 + #drawer {
border-width:
1px 0 0; }
229 + .cards {
grid-template-columns:
1fr 1fr; }
232 + @media (
max-width:
620px) {
233 + #topbar {
align-items:
flex-start;
flex-direction:
column; }
234 + .cards {
grid-template-columns:
1fr; }
235 + .content {
padding-inline:
12px; }
45 - <
h1 id=
"title">Autoresearch</
h1>
46 - <
div class=
"meta" id=
"meta">Loading session.jsonl…</
div>
242 + <
header id=
"topbar">
243 + <
div class=
"brand">
245 + <
h1 id=
"title">Autoresearch</
h1>
246 + <
div class=
"subtitle">Pi × experiments</
div>
247 + <
div id=
"summary">Loading session.jsonl…</
div>
250 + <
label class=
"theme-label" aria-label=
"Theme mode">
251 + <
span aria-hidden=
"true">◐</
span>
252 + <
select id=
"theme-mode" aria-label=
"Theme mode">
253 + <
option value=
"system">system</
option>
254 + <
option value=
"dark">dark</
option>
255 + <
option value=
"light">light</
option>
260 + <
div class=
"content">
261 + <
section class=
"cards" aria-label=
"Experiment summary">
262 + <
div class=
"card"><
div class=
"label">Baseline → Best</
div><
div class=
"value" id=
"baseline-best">—</
div></
div>
263 + <
div class=
"card"><
div class=
"label">Improvement</
div><
div class=
"value good" id=
"improvement">—</
div></
div>
264 + <
div class=
"card"><
div class=
"label">Runs</
div><
div class=
"value" id=
"runs">0</
div></
div>
265 + <
div class=
"card"><
div class=
"label">Kept</
div><
div class=
"value" id=
"kept">0</
div></
div>
268 + <
section class=
"panel" aria-label=
"Metric chart"><
div class=
"chart-wrap"><
canvas id=
"chart"></
canvas></
div></
section>
269 + <
section class=
"panel" aria-label=
"Runs table">
271 + <
thead><
tr><
th>Run</
th><
th>Status</
th><
th id=
"metric-head">Metric</
th><
th>Δ baseline</
th><
th>Confidence</
th><
th>Commit</
th><
th>Description</
th><
th>Hypothesis</
th><
th>Next</
th></
tr></
thead>
272 + <
tbody id=
"rows"><
tr><
td colspan=
"9" class=
"notice">Waiting for runs…</
td></
tr></
tbody>
49 - <
section class=
"grid">
50 - <
div class=
"card"><
div class=
"label">Baseline → Best</
div><
div class=
"value" id=
"baseline-best">—</
div></
div>
51 - <
div class=
"card"><
div class=
"label">Improvement</
div><
div class=
"value good" id=
"improvement">—</
div></
div>
52 - <
div class=
"card"><
div class=
"label">Runs</
div><
div class=
"value" id=
"runs">0</
div></
div>
53 - <
div class=
"card"><
div class=
"label">Kept</
div><
div class=
"value" id=
"kept">0</
div></
div>
55 - <
section class=
"panel"><
div class=
"chart-wrap"><
canvas id=
"chart"></
canvas></
div></
section>
56 - <
section class=
"panel">
58 - <
thead><
tr><
th>Run</
th><
th>Status</
th><
th id=
"metric-head">Metric</
th><
th>Δ baseline</
th><
th>Confidence</
th><
th>Commit</
th><
th>Description</
th><
th>Hypothesis</
th><
th>Next</
th></
tr></
thead>
59 - <
tbody id=
"rows"><
tr><
td colspan=
"9" class=
"notice">Waiting for runs…</
td></
tr></
tbody>
278 + <
aside id=
"drawer">
279 + <
section class=
"card">
280 + <
div class=
"card-title">Session</
div>
281 + <
div class=
"stat-list">
282 + <
div class=
"stat-row"><
span>metric</
span><
span id=
"side-metric">metric</
span></
div>
283 + <
div class=
"stat-row"><
span>direction</
span><
span id=
"side-direction">lower</
span></
div>
284 + <
div class=
"stat-row"><
span>baseline</
span><
span id=
"side-baseline">—</
span></
div>
285 + <
div class=
"stat-row"><
span>best run</
span><
span id=
"side-best-run">—</
span></
div>
288 + <
section class=
"card">
289 + <
div class=
"card-title">Outcomes <
span class=
"count-pill" id=
"side-outcomes">0</
span></
div>
290 + <
div class=
"stat-list">
291 + <
div class=
"stat-row"><
span>kept</
span><
span id=
"side-kept">0</
span></
div>
292 + <
div class=
"stat-row"><
span>discarded</
span><
span id=
"side-discarded">0</
span></
div>
293 + <
div class=
"stat-row"><
span>crashed / failed</
span><
span id=
"side-failed">0</
span></
div>
298 + <
div id=
"status" role=
"status" aria-live=
"polite">Loading</
div>
64 - const VALID
= new Set([
'keep',
'discard',
'crash',
'checks_failed']);
65 - const COLORS
= { text:
'#c9d1d9', muted:
'#8b949e', line:
'#58a6ff', grid:
'rgba(255,255,255,.08)', good:
'#3fb950', bad:
'#f85149' };
66 - let state
= { config:{ name:
'Autoresearch', metricName:
'metric', metricUnit:
'', bestDirection:
'lower' }, runs:[] };
301 + const VALID
= new Set([
"keep",
"discard",
"crash",
"checks_failed"]);
302 + const COLORS
= { line:
"#d86dd8", info:
"#3ec5dd", error:
"#e46479", grid:
"rgba(157,157,157,.18)", muted:
"#9d9d9d" };
303 + let state
= { config:{ name:
"Autoresearch", metricName:
"metric", metricUnit:
"", bestDirection:
"lower" }, runs:[] };
70 307 function start() {
72 - if (
typeof EventSource
!== 'undefined') {
73 - const events
= new EventSource(
'/events');
74 - events.addEventListener(
'jsonl-updated', refresh);
75 - events.
onerror = ()
=> setMeta(
'Live update disconnected; retrying via refresh.',
true);
310 + if (
typeof EventSource
!== "undefined") {
311 + const events
= new EventSource(
"/events");
312 + events.addEventListener(
"jsonl-updated", refresh);
313 + events.
onerror = ()
=> setStatus(
"Live update disconnected; waiting…",
true);
77 - window.addEventListener(
'resize', ()
=> drawChart());
315 + window.addEventListener(
"resize", drawChart);
318 + function wireTheme() {
319 + const select
= document.getElementById(
"theme-mode");
320 + select.value
= localStorage.getItem(
"diff-review-theme")
|| "system";
321 + select.addEventListener(
"change", ()
=> {
322 + localStorage.setItem(
"diff-review-theme", select.value);
323 + applyTheme(select.value);
325 + matchMedia(
"(prefers-color-scheme: light)").addEventListener(
"change", ()
=> {
326 + if ((localStorage.getItem(
"diff-review-theme")
|| "system")
=== "system") applyTheme(
"system");
329 + function applyTheme(mode) {
330 + const systemLight
= matchMedia(
"(prefers-color-scheme: light)").matches;
331 + document.documentElement.dataset.themeMode
= mode;
332 + document.documentElement.dataset.theme
= mode
=== "system" ? (systemLight
? "light" : "dark")
: mode;
80 336 async function refresh() {
82 - const res
= await fetch(
'session.jsonl', { cache:
'no-store' });
83 - if (
!res.ok)
throw new Error(
'HTTP ' + res.status);
338 + const res
= await fetch(
"session.jsonl", { cache:
"no-store" });
339 + if (
!res.ok)
throw new Error(
"HTTP " + res.status);
84 340 const text
= await res.text();
85 341 if (text
=== lastText)
return;
89 - setMeta(
'Could not load session.jsonl: ' + err.message,
true);
345 + setStatus(
"Could not load session.jsonl: " + err.message,
true);
93 349 function load(text) {
94 - const entries
= text.trim().split(
/\n+/).filter(
Boolean).map((line, i)
=> {
95 - try {
return JSON.
parse(line); }
catch {
throw new Error(
'invalid JSONL line ' + (i
+ 1)); }
350 + const trimmed
= text.trim();
351 + if (
!trimmed)
throw new Error(
"empty session.jsonl");
352 + const entries
= trimmed.split(
/\n+/).filter(
Boolean).map((line, i)
=> {
353 + try {
return JSON.
parse(line); }
catch {
throw new Error(
"invalid JSONL line " + (i
+ 1)); }
97 - const config
= entries.find(x
=> x
&& x.type
=== 'config')
|| {};
355 + const config
= entries.find(x
=> x
&& x.type
=== "config")
|| {};
99 - name: config.name
|| 'Autoresearch',
100 - metricName: config.metricName
|| 'metric',
101 - metricUnit: config.metricUnit
|| '',
102 - bestDirection: config.bestDirection
=== 'higher' ? 'higher' : 'lower',
357 + name: config.name
|| "Autoresearch",
358 + metricName: config.metricName
|| "metric",
359 + metricUnit: config.metricUnit
|| "",
360 + bestDirection: config.bestDirection
=== "higher" ? "higher" : "lower",
104 - state.runs
= entries.filter(x
=> x
&& typeof x.run
=== 'number').map(normalizeRun);
362 + state.runs
= entries.filter(x
=> x
&& typeof x.run
=== "number").map(normalizeRun);
107 365 run: Number.isFinite(Number(run.run)) ? Number(run.run) : i + 1,
108 366 metric: Number.isFinite(Number(run.metric)) ? Number(run.metric) : 0,
109 - status: VALID.has(run.status) ? run.status : 'discard',
110 - commit: run.commit || '', description: run.description || '', confidence: run.confidence,
111 - asi: run.asi && typeof run.asi === 'object' ? run.asi : {},
367 + status: VALID.has(run.status) ? run.status : "discard",
368 + commit: run.commit || "",
369 + description: run.description || "",
370 + confidence: run.confidence,
371 + asi: run.asi && typeof run.asi === "object" ? run.asi : {},
115 375 function render() {
116 - document.title = state.config.name;
117 - text('title', state.config.name);
118 - text('metric-head', state.config.metricName);
119 - setMeta(`${state.config.metricName}${state.config.metricUnit ? ' (' + state.config.metricUnit + ')' : ''} · ${state.config.bestDirection} is better · live`, false);
120 376 const baseline = state.runs[0]?.metric ?? null;
121 - const best = bestRun()?.metric ?? null;
122 - text('baseline-best', fmt(baseline) + ' → ' + fmt(best));
123 - const pct = improvement(baseline, best);
124 - text('improvement', pct == null ? '—' : pct.toFixed(1) + '%');
125 - text('runs', String(state.runs.length));
126 - text('kept', String(state.runs.filter(r => r.status === 'keep').length));
127 - renderRows(baseline);
377 + const best = bestRun();
378 + document.title = state.config.name;
379 + text("title", state.config.name);
380 + text("metric-head", state.config.metricName);
381 + text("summary", `${state.config.metricName}${state.config.metricUnit ? " (" + state.config.metricUnit + ")" : ""} · ${state.config.bestDirection} is better · live`);
382 + text("baseline-best", fmt(baseline) + " → " + fmt(best?.metric ?? null));
383 + const pct = improvement(baseline, best?.metric ?? null);
384 + const imp = document.getElementById("improvement");
385 + imp.textContent = pct == null ? "—" : pct.toFixed(1) + "%";
386 + imp.className = "value " + (pct == null || pct >= 0 ? "good" : "bad");
387 + text("runs", String(state.runs.length));
388 + text("kept", String(count("keep")));
389 + text("side-metric", state.config.metricName);
390 + text("side-direction", state.config.bestDirection);
391 + text("side-baseline", fmt(baseline));
392 + text("side-best-run", best ? "#" + best.run : "—");
393 + text("side-outcomes", String(state.runs.length));
394 + text("side-kept", String(count("keep")));
395 + text("side-discarded", String(count("discard")));
396 + text("side-failed", String(count("crash") + count("checks_failed")));
397 + renderRows(baseline, best);
399 + setStatus(`Ready · ${state.runs.length} runs`, false);
131 - function renderRows(baseline) {
132 - const best = bestRun();
133 - const rows = document.getElementById('rows');
134 - if (!state.runs.length) { rows.innerHTML = '<
tr><
td colspan=
"9" class=
"notice">No runs found in session.jsonl.</
td></
tr>'; return; }
402 + function renderRows(baseline, best) {
403 + const rows = document.getElementById("rows");
404 + if (!state.runs.length) {
405 + rows.innerHTML = '<
tr><
td colspan=
"9" class=
"notice">No runs found in session.jsonl.</
td></
tr>';
135 408 rows.innerHTML = state.runs.map(r => {
136 409 const delta = deltaPct(r.metric, baseline);
137 - return `<
tr class=
"${best && r.run === best.run ? 'best-row' : ''}">
410 + return `<
tr class=
"${best && r.run === best.run ? "best-row" : ""}">
138 411 <
td class=
"mono">#${r.run}</
td><
td><
span class=
"status ${esc(r.status)}">${esc(r.status)}</
span></
td>
139 - <
td class=
"mono">${r.metric > 0 ? esc(fmt(r.metric)) : '—'}</
td><
td class=
"mono ${deltaClass(delta)}">${fmtDelta(delta)}</
td>
412 + <
td class=
"mono">${r.metric > 0 ? esc(fmt(r.metric)) : "—"}</
td><
td class=
"mono ${deltaClass(delta)}">${fmtDelta(delta)}</
td>
140 413 <
td class=
"mono">${fmtConfidence(r.confidence)}</
td><
td class=
"mono muted">${esc(r.commit)}</
td>
141 - <
td>${esc(r.description)}</
td><
td>${esc(r.asi.hypothesis || '')}</
td><
td>${esc(r.asi.next_action_hint || r.asi.next || '')}</
td>
414 + <
td>${esc(r.description)}</
td><
td>${esc(r.asi.hypothesis || "")}</
td><
td>${esc(r.asi.next_action_hint || r.asi.next || "")}</
td>
146 419 function drawChart() {
147 - const canvas = document.getElementById('chart');
420 + const canvas = document.getElementById("chart");
148 421 const rect = canvas.getBoundingClientRect();
149 422 const dpr = devicePixelRatio || 1;
150 - canvas.width = Math.max(1, Math.floor(rect.width * dpr)); canvas.height = Math.max(1, Math.floor(rect.height * dpr));
151 - const ctx = canvas.getContext('2d'); ctx.setTransform(dpr,0,0,dpr,0,0); ctx.clearRect(0,0,rect.width,rect.height);
152 - const runs = state.runs.filter(r => r.metric > 0); if (!runs.length) return;
153 - const values = runs.map(r => r.metric), minRaw = Math.min(...values), maxRaw = Math.max(...values), spread = maxRaw - minRaw || Math.max(1, maxRaw * .1);
423 + canvas.width = Math.max(1, Math.floor(rect.width * dpr));
424 + canvas.height = Math.max(1, Math.floor(rect.height * dpr));
425 + const ctx = canvas.getContext("2d");
426 + ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
427 + ctx.clearRect(0, 0, rect.width, rect.height);
428 + const runs = state.runs.filter(r => r.metric > 0);
429 + if (!runs.length) return;
430 + const css = getComputedStyle(document.documentElement);
431 + const lineColor = css.getPropertyValue("--accent").trim() || COLORS.line;
432 + const infoColor = css.getPropertyValue("--nugu-info").trim() || COLORS.info;
433 + const errorColor = css.getPropertyValue("--nugu-error").trim() || COLORS.error;
434 + const muted = css.getPropertyValue("--muted").trim() || COLORS.muted;
435 + const values = runs.map(r => r.metric);
436 + const minRaw = Math.min(...values), maxRaw = Math.max(...values), spread = maxRaw - minRaw || Math.max(1, maxRaw * .1);
154 437 const min = Math.max(0, minRaw - spread * .15), max = maxRaw + spread * .12, range = max - min || 1;
155 - const m = { l:56, r:18, t:14, b:28 }, w = rect.width - m.l - m.r, h = rect.height - m.t - m.b;
156 - const x = i => m.l + (runs.length === 1 ? w/2 : i * w/(runs.length - 1));
438 + const m = { l:60, r:18, t:14, b:28 }, w = rect.width - m.l - m.r, h = rect.height - m.t - m.b;
439 + const x = i => m.l + (runs.length === 1 ? w / 2 : i * w / (runs.length - 1));
157 440 const y = v => m.t + h - ((v - min) / range) * h;
158 - ctx.strokeStyle = COLORS.grid; ctx.fillStyle = COLORS.muted; ctx.font = '10px ui-monospace,monospace'; ctx.textAlign = 'right';
159 - for (let i=0;i<=4;i++) { const v = min + range * i / 4, yy = y(v); ctx.beginPath(); ctx.moveTo(m.l, yy); ctx.lineTo(rect.width - m.r, yy); ctx.stroke(); ctx.fillText(fmt(v), m.l - 8, yy + 3); }
160 - ctx.strokeStyle = COLORS.line; ctx.lineWidth = 2; ctx.beginPath(); runs.forEach((r,i) => i ? ctx.lineTo(x(i), y(r.metric)) : ctx.moveTo(x(i), y(r.metric))); ctx.stroke();
161 - runs.forEach((r,i) => { ctx.fillStyle = r.status === 'keep' ? COLORS.good : COLORS.bad; ctx.beginPath(); ctx.arc(x(i), y(r.metric), 4, 0, Math.PI*2); ctx.fill(); });
441 + ctx.strokeStyle = COLORS.grid;
442 + ctx.fillStyle = muted;
443 + ctx.font = '10px "JetBrains Mono", ui-monospace, monospace';
444 + ctx.textAlign = "right";
445 + for (let i = 0; i <= 4; i++) {
446 + const v = min + range * i / 4, yy = y(v);
447 + ctx.beginPath(); ctx.moveTo(m.l, yy); ctx.lineTo(rect.width - m.r, yy); ctx.stroke();
448 + ctx.fillText(fmt(v), m.l - 8, yy + 3);
450 + ctx.strokeStyle = lineColor;
451 + ctx.lineWidth = 2.5;
452 + ctx.lineJoin = "round";
453 + ctx.lineCap = "round";
455 + runs.forEach((r, i) => i ? ctx.lineTo(x(i), y(r.metric)) : ctx.moveTo(x(i), y(r.metric)));
457 + runs.forEach((r, i) => {
458 + ctx.fillStyle = r.status === "keep" ? infoColor : errorColor;
459 + ctx.beginPath(); ctx.arc(x(i), y(r.metric), 4.5, 0, Math.PI * 2); ctx.fill();
164 463 function bestRun() { return state.runs.filter(r => r.metric > 0).reduce((best, r) => !best || better(r.metric, best.metric) ? r : best, null); }
165 - function better(a,b) { return state.config.bestDirection === 'higher' ? a > b : a < b; }
166 - function improvement(base,best) { if (!base || best == null) return null; return state.config.bestDirection === 'higher' ? (best-base)/base*100 : (base-best)/base*100; }
464 + function better(a, b) { return state.config.bestDirection === "higher" ? a > b : a < b; }
465 + function improvement(base, best) { if (!base || best == null) return null; return state.config.bestDirection === "higher" ? (best - base) / base * 100 : (base - best) / base * 100; }
167 466 function deltaPct(value, base) { return !base || value <= 0 ? null : (value - base) / base * 100; }
168 - function deltaClass(d) { if (d == null || Math.abs(d) < .05) return 'muted'; return (state.config.bestDirection === 'higher' ? d > 0 : d < 0) ? 'good' : 'bad'; }
169 - function fmtDelta(d) { return d == null ? '—' : (Math.abs(d) < .05 ? '0%' : (d > 0 ? '+' : '') + d.toFixed(1) + '%'); }
170 - function fmt(v) { return v == null || Number.isNaN(v) ? '—' : Number(v).toLocaleString(undefined, { maximumFractionDigits: 2 }) + state.config.metricUnit; }
171 - function fmtConfidence(v) { return typeof v === 'number' ? v.toFixed(1) + '×' : '—'; }
467 + function deltaClass(d) { if (d == null || Math.abs(d) < .05) return "muted"; return (state.config.bestDirection === "higher" ? d > 0 : d < 0) ? "good" : "bad"; }
468 + function fmtDelta(d) { return d == null ? "—" : (Math.abs(d) < .05 ? "0%" : (d > 0 ? "+" : "") + d.toFixed(1) + "%"); }
469 + function fmt(v) { return v == null || Number.isNaN(v) ? "—" : Number(v).toLocaleString(undefined, { maximumFractionDigits: 2 }) + state.config.metricUnit; }
470 + function fmtConfidence(v) { return typeof v === "number" ? v.toFixed(1) + "×" : "—"; }
471 + function count(status) { return state.runs.filter(r => r.status === status).length; }
172 472 function text(id, value) { document.getElementById(id).textContent = value; }
173 - function setMeta(msg, warning) { const el = document.getElementById('meta'); el.textContent = msg; el.className = 'meta ' + (warning ? 'warn' : ''); }
174 - function esc(v) { return String(v).replace(/[&<>"']/g, ch => ({'&':'
&','<':'
<','>':'
>','"':'
"',"'":'
''}[ch])); }
473 + function setStatus(msg, error) { const el = document.getElementById("status"); el.textContent = msg; el.className = error ? "error" : "ok"; }
474 + function esc(v) { return String(v).replace(/[&<>"']/g, ch => ({"&":"
&", "<":"
<", ">":"
>", '"':"
"", "'":"
'"}[ch])); }