sakura-infinity 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT-GUIDE.md +104 -0
- package/LICENSE +21 -0
- package/README.md +275 -2
- package/dist/bin/flags.js +110 -0
- package/dist/bin/infinity.js +98 -0
- package/dist/bin/load-task.js +39 -0
- package/dist/bin/model.js +37 -0
- package/dist/bin/scaffold.js +121 -0
- package/dist/src/agent-worker.js +156 -0
- package/dist/src/backoff.js +12 -0
- package/dist/src/budget.js +49 -0
- package/dist/src/capacity.js +103 -0
- package/dist/src/clock.js +16 -0
- package/dist/src/code-leaderboard.js +48 -0
- package/dist/src/code-report.js +157 -0
- package/dist/src/command-class.js +59 -0
- package/dist/src/command-limits.js +46 -0
- package/dist/src/commit-plugin.js +36 -0
- package/dist/src/component.js +1 -0
- package/dist/src/csv.js +8 -0
- package/dist/src/defaults.js +35 -0
- package/dist/src/error-cluster.js +20 -0
- package/dist/src/evaluation.js +84 -0
- package/dist/src/form.js +191 -0
- package/dist/src/gate.js +111 -0
- package/dist/src/gpu-shim.js +165 -0
- package/dist/src/hidden-keeper.js +183 -0
- package/dist/src/host.js +180 -0
- package/dist/src/jsonl.js +30 -0
- package/dist/src/ladder.js +118 -0
- package/dist/src/launch.js +123 -0
- package/dist/src/lean-kit.js +42 -0
- package/dist/src/lean-runner.js +84 -0
- package/dist/src/lean-setup.js +23 -0
- package/dist/src/lean-tool.js +57 -0
- package/dist/src/leftover.js +59 -0
- package/dist/src/machine-config.js +43 -0
- package/dist/src/machine-sampler.js +103 -0
- package/dist/src/machine-summary.js +64 -0
- package/dist/src/mode-factory.js +25 -0
- package/dist/src/mode.js +1 -0
- package/dist/src/network.js +12 -0
- package/dist/src/orchestrator.js +375 -0
- package/dist/src/planner.js +98 -0
- package/dist/src/platform.js +21 -0
- package/dist/src/pool.js +73 -0
- package/dist/src/pressure-brake.js +26 -0
- package/dist/src/proc-readings.js +207 -0
- package/dist/src/prompts.js +46 -0
- package/dist/src/records.js +2 -0
- package/dist/src/report.js +81 -0
- package/dist/src/review-loop.js +141 -0
- package/dist/src/review-rules.js +104 -0
- package/dist/src/review-run.js +110 -0
- package/dist/src/review-schedule.js +53 -0
- package/dist/src/review-snapshot.js +150 -0
- package/dist/src/run-layout.js +29 -0
- package/dist/src/run-notes.js +61 -0
- package/dist/src/run-recorder.js +51 -0
- package/dist/src/run-state.js +17 -0
- package/dist/src/run-status.js +37 -0
- package/dist/src/rung-meter.js +39 -0
- package/dist/src/safety-review.js +43 -0
- package/dist/src/sakura-tools.js +130 -0
- package/dist/src/shell-kit.js +113 -0
- package/dist/src/slot-gate.js +136 -0
- package/dist/src/slot-leases.js +64 -0
- package/dist/src/stuck.js +47 -0
- package/dist/src/submit-tool.js +99 -0
- package/dist/src/task-mode.js +170 -0
- package/dist/src/task.js +85 -0
- package/dist/src/verifier.js +115 -0
- package/dist/src/work-repo.js +50 -0
- package/dist/src/worker-policy.js +16 -0
- package/dist/tasks/math-odd-sum/task.js +6 -0
- package/dist/tasks/math-parity/task.js +6 -0
- package/dist/viewer/index.html +397 -0
- package/dist/viewer/run-reader.js +600 -0
- package/dist/viewer/server.js +160 -0
- package/dist/viewer/view.js +50 -0
- package/package.json +52 -4
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Infinity run viewer</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
--bg: #f6f7f9; --card: #ffffff; --ink: #1b1f27; --muted: #5d6675; --line: #d9dde4; --grid: #e8ebf0;
|
|
10
|
+
--c1: #2f6fd6; --c2: #d8731a; --c3: #168f80; --c4: #8a5cc7; --bad: #c8372d; --warn: #b7791f; --good: #1d8a4b; --band: rgba(200, 55, 45, 0.12);
|
|
11
|
+
}
|
|
12
|
+
@media (prefers-color-scheme: dark) {
|
|
13
|
+
:root:not([data-theme="light"]) {
|
|
14
|
+
--bg: #12151a; --card: #1a1e25; --ink: #e6e9ee; --muted: #9aa3b2; --line: #343b47; --grid: #262c36;
|
|
15
|
+
--c1: #6aa0ff; --c2: #f0a04b; --c3: #4cc7b4; --c4: #b794f0; --bad: #ff7a70; --warn: #e0b04a; --good: #5fd08b; --band: rgba(255, 122, 112, 0.16);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
:root[data-theme="dark"] {
|
|
19
|
+
--bg: #12151a; --card: #1a1e25; --ink: #e6e9ee; --muted: #9aa3b2; --line: #343b47; --grid: #262c36;
|
|
20
|
+
--c1: #6aa0ff; --c2: #f0a04b; --c3: #4cc7b4; --c4: #b794f0; --bad: #ff7a70; --warn: #e0b04a; --good: #5fd08b; --band: rgba(255, 122, 112, 0.16);
|
|
21
|
+
}
|
|
22
|
+
* { box-sizing: border-box; }
|
|
23
|
+
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
24
|
+
main { max-width: 1180px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
|
|
25
|
+
header { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
|
|
26
|
+
h1 { font-size: 18px; margin: 0; }
|
|
27
|
+
h2 { font-size: 14px; margin: 0 0 8px; }
|
|
28
|
+
.sub { color: var(--muted); font-size: 12px; }
|
|
29
|
+
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
|
|
30
|
+
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(160px, 45%), 1fr)); gap: 10px; }
|
|
31
|
+
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
|
|
32
|
+
.tile b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.2; }
|
|
33
|
+
.tile span { color: var(--muted); font-size: 12px; }
|
|
34
|
+
.pill { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
|
|
35
|
+
.pill.running { color: var(--good); border-color: var(--good); }
|
|
36
|
+
.pill.stopped { color: var(--warn); border-color: var(--warn); }
|
|
37
|
+
.attention { border-left: 3px solid var(--warn); }
|
|
38
|
+
.attention ul { margin: 0; padding-left: 18px; }
|
|
39
|
+
.attention li { margin: 2px 0; }
|
|
40
|
+
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 16px; align-items: start; }
|
|
41
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; align-items: start; }
|
|
42
|
+
svg { display: block; width: 100%; height: auto; overflow: visible; }
|
|
43
|
+
svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
|
|
44
|
+
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
|
|
45
|
+
.legend i { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; border-radius: 2px; }
|
|
46
|
+
.empty { color: var(--muted); font-size: 12px; padding: 8px 0; }
|
|
47
|
+
.wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; }
|
|
48
|
+
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
|
|
49
|
+
th, td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
|
|
50
|
+
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--card); }
|
|
51
|
+
td.l, th.l { text-align: left; white-space: normal; }
|
|
52
|
+
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: middle; }
|
|
53
|
+
.dot.live { background: var(--good); }
|
|
54
|
+
.quiet { color: var(--muted); }
|
|
55
|
+
details.card > summary { cursor: pointer; font-weight: 600; }
|
|
56
|
+
details.card[open] > summary { margin-bottom: 12px; }
|
|
57
|
+
details .grid, details section { margin-top: 12px; }
|
|
58
|
+
.item { border-bottom: 1px solid var(--grid); padding: 6px 0; }
|
|
59
|
+
.item small { color: var(--muted); }
|
|
60
|
+
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line); margin-right: 4px; }
|
|
61
|
+
.badge.denied, .badge.error { color: var(--bad); border-color: var(--bad); }
|
|
62
|
+
.badge.steer { color: var(--warn); border-color: var(--warn); }
|
|
63
|
+
.tip { position: fixed; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12px; display: none; z-index: 5; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
|
|
64
|
+
select { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
|
|
65
|
+
.tall { max-height: 380px; overflow: auto; }
|
|
66
|
+
.result { display: grid; gap: 10px; }
|
|
67
|
+
.result .score { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
|
|
68
|
+
.result .who { color: var(--muted); }
|
|
69
|
+
.result dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
|
|
70
|
+
.result dt { color: var(--muted); }
|
|
71
|
+
.result dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
|
|
72
|
+
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
|
|
73
|
+
.status { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; }
|
|
74
|
+
.status b { font-variant-numeric: tabular-nums; }
|
|
75
|
+
.bar { height: 4px; background: var(--grid); border-radius: 2px; overflow: hidden; margin-top: 8px; }
|
|
76
|
+
.bar i { display: block; height: 100%; background: var(--c1); }
|
|
77
|
+
.footnote { color: var(--muted); font-size: 12px; margin: 0; padding-left: 18px; }
|
|
78
|
+
</style>
|
|
79
|
+
</head>
|
|
80
|
+
<body>
|
|
81
|
+
<main>
|
|
82
|
+
<header>
|
|
83
|
+
<div>
|
|
84
|
+
<h1 id="title">Infinity run</h1>
|
|
85
|
+
<div class="sub" id="subtitle"></div>
|
|
86
|
+
</div>
|
|
87
|
+
<div><label class="sub">Run <select id="runs"></select></label> <span id="state" class="pill"></span></div>
|
|
88
|
+
</header>
|
|
89
|
+
<section class="card result" id="result"></section>
|
|
90
|
+
<section class="card" id="progress"></section>
|
|
91
|
+
<section class="card attention" id="attention" hidden><h2>Needs you</h2><ul id="attentionList"></ul></section>
|
|
92
|
+
<div class="two">
|
|
93
|
+
<section class="card"><h2>Score over time</h2><div id="scores"></div></section>
|
|
94
|
+
<section class="card"><h2>Agents, best first</h2><div class="wrap"><table id="board"></table></div></section>
|
|
95
|
+
</div>
|
|
96
|
+
<details class="card" id="more">
|
|
97
|
+
<summary>Machine</summary>
|
|
98
|
+
<div class="grid" id="machine"></div>
|
|
99
|
+
</details>
|
|
100
|
+
<ul class="footnote" id="notes"></ul>
|
|
101
|
+
</main>
|
|
102
|
+
<div class="tip" id="tip"></div>
|
|
103
|
+
<script>
|
|
104
|
+
"use strict";
|
|
105
|
+
// The page answers what a person running many agents on one task wants to know, in this order:
|
|
106
|
+
// what is the best result and where is it; how far the run is and how much is left; is anything waiting on me; is it still getting better; who is ahead.
|
|
107
|
+
const $ = (id) => document.getElementById(id);
|
|
108
|
+
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
109
|
+
const params = new URLSearchParams(location.search);
|
|
110
|
+
const runParam = params.get("run") || "";
|
|
111
|
+
const q = (path) => fetch(path + (path.includes("?") ? "&" : "?") + "run=" + encodeURIComponent(runParam), { cache: "no-store" }).then((r) => r.json());
|
|
112
|
+
|
|
113
|
+
let data = null;
|
|
114
|
+
/** An agent that has worked this long without a submit is worth a look (the agents are reminded at the same point). */
|
|
115
|
+
const NO_SUBMIT_MINUTES = 20;
|
|
116
|
+
|
|
117
|
+
function fmtDur(ms) {
|
|
118
|
+
if (ms == null || !Number.isFinite(ms)) return "-";
|
|
119
|
+
const s = Math.max(0, Math.round(ms / 1000));
|
|
120
|
+
const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), r = s % 60;
|
|
121
|
+
return h > 0 ? `${h}h ${String(m).padStart(2, "0")}m` : `${m}m ${String(r).padStart(2, "0")}s`;
|
|
122
|
+
}
|
|
123
|
+
const fmtMin = (ts, t0) => (ts == null || t0 == null ? "-" : (Math.round(((ts - t0) / 60000) * 10) / 10).toFixed(1));
|
|
124
|
+
function fmtNum(n) {
|
|
125
|
+
if (n == null) return "-";
|
|
126
|
+
if (n >= 1e6) return (n / 1e6).toFixed(2) + " M";
|
|
127
|
+
if (n >= 1e4) return Math.round(n / 1e3) + " k";
|
|
128
|
+
return String(Math.round(n));
|
|
129
|
+
}
|
|
130
|
+
const fmtScore = (s) => (s == null ? "-" : String(Math.round(s * 100000) / 100000));
|
|
131
|
+
|
|
132
|
+
// ---------- charts ----------
|
|
133
|
+
const charts = new Map();
|
|
134
|
+
|
|
135
|
+
function niceTicks(lo, hi, n) {
|
|
136
|
+
const span = hi - lo || 1;
|
|
137
|
+
const raw = span / n;
|
|
138
|
+
const mag = Math.pow(10, Math.floor(Math.log10(raw)));
|
|
139
|
+
const step = [1, 2, 2.5, 5, 10].map((k) => k * mag).find((s) => s >= raw) || raw;
|
|
140
|
+
const out = [];
|
|
141
|
+
for (let v = Math.ceil(lo / step) * step; v <= hi + step * 1e-6; v += step) out.push(Math.round(v / step * 1e6) / 1e6 * step);
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
function timeTicks(t0, t1) {
|
|
145
|
+
const spanMin = (t1 - t0) / 60000;
|
|
146
|
+
const step = [1, 2, 5, 10, 15, 30, 60, 120, 240].find((s) => spanMin / s <= 8) || 240;
|
|
147
|
+
const out = [];
|
|
148
|
+
for (let m = 0; m <= spanMin + 1e-6; m += step) out.push(t0 + m * 60000);
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Draws one chart into `host`. spec: {id, h, t0, t1, yMin, yMax, yFmt, series, marks, hlines, points, extra, ticksY} */
|
|
153
|
+
function drawChart(host, spec) {
|
|
154
|
+
const W = Math.max(280, host.clientWidth || 600);
|
|
155
|
+
const H = spec.h || 150;
|
|
156
|
+
const m = { l: 44, r: 10, t: 14, b: 22 };
|
|
157
|
+
const pw = W - m.l - m.r, ph = H - m.t - m.b;
|
|
158
|
+
const x = (t) => m.l + ((t - spec.t0) / Math.max(1, spec.t1 - spec.t0)) * pw;
|
|
159
|
+
const y = (v) => m.t + ph - ((v - spec.yMin) / Math.max(1e-9, spec.yMax - spec.yMin)) * ph;
|
|
160
|
+
let g = "";
|
|
161
|
+
for (const v of spec.ticksY || niceTicks(spec.yMin, spec.yMax, 4)) {
|
|
162
|
+
g += `<line x1="${m.l}" x2="${W - m.r}" y1="${y(v)}" y2="${y(v)}" stroke="var(--grid)"/><text x="${m.l - 6}" y="${y(v) + 4}" text-anchor="end">${esc(spec.yFmt ? spec.yFmt(v) : v)}</text>`;
|
|
163
|
+
}
|
|
164
|
+
for (const t of timeTicks(spec.t0, spec.t1)) {
|
|
165
|
+
g += `<text x="${x(t)}" y="${H - 6}" text-anchor="middle">${Math.round((t - spec.t0) / 60000)}m</text>`;
|
|
166
|
+
}
|
|
167
|
+
for (const b of spec.bands || []) g += `<rect x="${x(b[0])}" y="${m.t}" width="${Math.max(1, x(b[1]) - x(b[0]))}" height="${ph}" fill="var(--band)"/>`;
|
|
168
|
+
for (const r of spec.marks || []) {
|
|
169
|
+
g += `<line x1="${x(r.ts)}" x2="${x(r.ts)}" y1="${m.t}" y2="${m.t + ph}" stroke="var(--muted)" stroke-dasharray="3 3" opacity=".6"/>`;
|
|
170
|
+
if (r.label) g += `<text x="${x(r.ts) + 2}" y="${m.t + 9}">${esc(r.label)}</text>`;
|
|
171
|
+
}
|
|
172
|
+
for (const h of spec.hlines || []) g += `<line x1="${m.l}" x2="${W - m.r}" y1="${y(h.v)}" y2="${y(h.v)}" stroke="${h.color || "var(--muted)"}" stroke-dasharray="5 4"/>`;
|
|
173
|
+
for (const s of spec.series) {
|
|
174
|
+
const pts = s.pts.filter((p) => p[1] != null);
|
|
175
|
+
if (pts.length === 0) continue;
|
|
176
|
+
let d = "";
|
|
177
|
+
pts.forEach((p, i) => {
|
|
178
|
+
const px = x(p[0]), py = y(Math.min(spec.yMax, Math.max(spec.yMin, p[1])));
|
|
179
|
+
if (i === 0) d += `M${px.toFixed(1)} ${py.toFixed(1)}`;
|
|
180
|
+
else if (s.step) d += `H${px.toFixed(1)}V${py.toFixed(1)}`;
|
|
181
|
+
else d += `L${px.toFixed(1)} ${py.toFixed(1)}`;
|
|
182
|
+
});
|
|
183
|
+
if (s.step && !s.noExtend) d += `H${x(spec.t1).toFixed(1)}`;
|
|
184
|
+
g += `<path d="${d}" fill="none" stroke="${s.color}" stroke-width="${s.w || 1.6}" stroke-linejoin="round"/>`;
|
|
185
|
+
}
|
|
186
|
+
for (const p of spec.points || []) g += p;
|
|
187
|
+
g += `<line class="cross" x1="0" x2="0" y1="${m.t}" y2="${m.t + ph}" stroke="var(--ink)" opacity="0" />`;
|
|
188
|
+
host.innerHTML = `<svg viewBox="0 0 ${W} ${H}" role="img" aria-label="${esc(spec.label || "chart")}">${g}<rect class="hit" x="${m.l}" y="${m.t}" width="${pw}" height="${ph}" fill="transparent"/></svg>`;
|
|
189
|
+
const svg = host.firstElementChild;
|
|
190
|
+
charts.set(host.id, { spec, x, W });
|
|
191
|
+
svg.querySelector(".hit").addEventListener("mousemove", (ev) => hover(ev, host, svg, spec, m, W));
|
|
192
|
+
svg.querySelector(".hit").addEventListener("mouseleave", () => { $("tip").style.display = "none"; svg.querySelector(".cross").setAttribute("opacity", "0"); });
|
|
193
|
+
return { x, y };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function hover(ev, host, svg, spec, m, W) {
|
|
197
|
+
const box = svg.getBoundingClientRect();
|
|
198
|
+
const px = ((ev.clientX - box.left) / box.width) * W;
|
|
199
|
+
const t = spec.t0 + ((px - m.l) / (W - m.l - m.r)) * (spec.t1 - spec.t0);
|
|
200
|
+
const rows = [];
|
|
201
|
+
for (const s of spec.series) {
|
|
202
|
+
let best = null;
|
|
203
|
+
for (const p of s.pts) if (p[1] != null && (best === null || Math.abs(p[0] - t) < Math.abs(best[0] - t))) best = p;
|
|
204
|
+
if (best && Math.abs(best[0] - t) < (spec.t1 - spec.t0) / 20) rows.push(`<span style="color:${s.color}">${esc(s.name)}</span> ${esc(spec.yFmt ? spec.yFmt(best[1]) : best[1])}`);
|
|
205
|
+
}
|
|
206
|
+
const cross = svg.querySelector(".cross");
|
|
207
|
+
cross.setAttribute("x1", px); cross.setAttribute("x2", px); cross.setAttribute("opacity", ".35");
|
|
208
|
+
const tip = $("tip");
|
|
209
|
+
tip.innerHTML = `<b>${Math.round(((t - spec.t0) / 60000) * 10) / 10} min</b><br>${rows.join("<br>") || "no reading"}`;
|
|
210
|
+
tip.style.display = "block";
|
|
211
|
+
tip.style.left = Math.min(innerWidth - 180, ev.clientX + 12) + "px";
|
|
212
|
+
tip.style.top = ev.clientY + 12 + "px";
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function legend(items) {
|
|
216
|
+
return `<div class="legend">${items.map((i) => `<span><i style="background:${i[1]}"></i>${esc(i[0])}</span>`).join("")}</div>`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ---------- rendering ----------
|
|
220
|
+
function render() {
|
|
221
|
+
const { run, series, agents } = data;
|
|
222
|
+
const t0 = series.startedAt ?? run.startedAt;
|
|
223
|
+
const live = run.state === "running";
|
|
224
|
+
const endTs = run.endedAt ?? run.lastTs ?? t0;
|
|
225
|
+
const t1 = Math.max(endTs || 0, (series.machine.at(-1) || {}).ts || 0, t0 + 60000);
|
|
226
|
+
const now = live ? Math.max(Date.now(), endTs) : endTs;
|
|
227
|
+
document.title = `${run.task || "run"} - Infinity run viewer`;
|
|
228
|
+
$("title").textContent = run.task || "Infinity run";
|
|
229
|
+
$("subtitle").textContent = run.name;
|
|
230
|
+
const st = $("state"); st.textContent = run.state === "finished" && run.endReason ? `finished: ${run.endReason}` : run.state; st.className = "pill " + run.state;
|
|
231
|
+
|
|
232
|
+
drawResult(run, t0);
|
|
233
|
+
drawProgress(run, series, now, t0, live);
|
|
234
|
+
const items = attention(run, series, agents, now);
|
|
235
|
+
$("attention").hidden = items.length === 0;
|
|
236
|
+
$("attentionList").innerHTML = items.map((text) => `<li>${esc(text)}</li>`).join("");
|
|
237
|
+
drawScores(series, t0, t1, run.metricDirection);
|
|
238
|
+
drawBoard(run.leaderboard, agents, now, live);
|
|
239
|
+
if ($("more").open) drawMachine(series, run, t0, t1);
|
|
240
|
+
$("notes").innerHTML = run.warnings.map((w) => `<li>${esc(w)}</li>`).join("");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The deliverable: the best result, who made it, and how to get it back. */
|
|
244
|
+
function drawResult(run, t0) {
|
|
245
|
+
const best = run.best;
|
|
246
|
+
if (!best) {
|
|
247
|
+
$("result").innerHTML = `<h2>Best result</h2><div class="score">-</div><div class="who">No scored result yet${run.submits ? ` (${run.submits} submits so far)` : ""}.</div>`;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const short = best.commit ? best.commit.slice(0, 10) : "";
|
|
251
|
+
$("result").innerHTML =
|
|
252
|
+
`<h2>Best result</h2><div><span class="score">${esc(fmtScore(best.score))}</span>${best.selfReported ? ` <span class="quiet">self-reported</span>` : ""}</div>` +
|
|
253
|
+
`<div class="who">agent ${best.agent}${best.ts != null && t0 != null ? `, at minute ${Math.round((best.ts - t0) / 60000)}` : ""} · ${run.scoredSubmits} scored submits in all</div>` +
|
|
254
|
+
`<dl>${best.command ? `<dt>Command</dt><dd><code>${esc(best.command)}</code></dd>` : ""}` +
|
|
255
|
+
`${best.files.length ? `<dt>Files</dt><dd>${best.files.map((f) => `<code>${esc(f)}</code>`).join(" ")}</dd>` : ""}` +
|
|
256
|
+
`<dt>Folder</dt><dd><code>${esc(best.workDir)}</code>${short ? ` at commit <code>${esc(short)}</code>` : ""}</dd></dl>`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** How far the run is: time and tokens against their limits, the agents at work, the machine. */
|
|
260
|
+
function drawProgress(run, series, now, t0, live) {
|
|
261
|
+
const elapsed = now - t0;
|
|
262
|
+
const parts = [];
|
|
263
|
+
const shares = [];
|
|
264
|
+
parts.push(`<span>${live ? "Running" : "Ran"} <b>${fmtDur(elapsed)}</b>${run.wallMinutes ? ` of ${fmtDur(run.wallMinutes * 60000)}` : ""}</span>`);
|
|
265
|
+
if (run.wallMinutes) shares.push(elapsed / (run.wallMinutes * 60000));
|
|
266
|
+
if (run.tokensUsed != null) {
|
|
267
|
+
parts.push(`<span><b>${fmtNum(run.tokensUsed)}</b>${run.tokenBudget ? ` of ${fmtNum(run.tokenBudget)}` : ""} tokens</span>`);
|
|
268
|
+
if (run.tokenBudget) shares.push(run.tokensUsed / run.tokenBudget);
|
|
269
|
+
}
|
|
270
|
+
parts.push(`<span><b>${run.agentsLive}</b> of ${run.agentsStarted} agents working</span>`);
|
|
271
|
+
const last = series.machine.at(-1) || {};
|
|
272
|
+
if (live && last.cpuBusy != null && now - last.ts < 5 * 60000) parts.push(`<span>machine CPU <b>${Math.round(last.cpuBusy * 100)}%</b></span>`);
|
|
273
|
+
const share = shares.length ? Math.min(1, Math.max(...shares)) : null;
|
|
274
|
+
$("progress").innerHTML = `<div class="status">${parts.join("")}</div>${share != null ? `<div class="bar" title="the limit that is closest"><i style="width:${(share * 100).toFixed(1)}%"></i></div>` : ""}`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Only what a person can act on; empty when nothing. */
|
|
278
|
+
function attention(run, series, agents, now) {
|
|
279
|
+
const out = [];
|
|
280
|
+
if (run.state === "stopped") out.push("Nothing was written for several minutes. Check the machine's CPU and the agents' folders before restarting anything: a long training writes no log lines.");
|
|
281
|
+
const silent = agents.filter((a) => a.endedAt == null && a.startedAt != null && a.submits === 0 && now - a.startedAt > NO_SUBMIT_MINUTES * 60000);
|
|
282
|
+
if (run.state === "running" && silent.length > 0)
|
|
283
|
+
out.push(`${silent.length === 1 ? "Agent" : "Agents"} ${silent.map((a) => a.agent).join(", ")} ${silent.length === 1 ? "has" : "have"} worked over ${NO_SUBMIT_MINUTES} minutes without a submit (they are reminded in every request).`);
|
|
284
|
+
const last = series.machine.at(-1) || {};
|
|
285
|
+
if (run.state === "running" && last.slotsWaiting > 0) out.push(`${last.slotsWaiting} heavy command${last.slotsWaiting === 1 ? " is" : "s are"} waiting for a CPU slot.`);
|
|
286
|
+
if (last.memUsedMb != null && last.memTotalMb && last.memUsedMb / last.memTotalMb > 0.9) out.push(`Memory is ${Math.round((last.memUsedMb / last.memTotalMb) * 100)}% used.`);
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** One table for the agents: the ranking, and when each agent last did something. */
|
|
291
|
+
function drawBoard(ranking, agents, now, live) {
|
|
292
|
+
const byAgent = new Map(agents.map((a) => [a.agent, a]));
|
|
293
|
+
const ranked = ranking.map((r) => r.agent);
|
|
294
|
+
const rows = [...ranking, ...agents.filter((a) => !ranked.includes(a.agent)).map((a) => ({ rank: null, agent: a.agent, score: null, selfReported: false, submits: a.submits, errors: 0 }))];
|
|
295
|
+
if (rows.length === 0) {
|
|
296
|
+
$("board").innerHTML = `<tr><td class="l empty">No agent has started yet.</td></tr>`;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const lastWords = (a) => (!a ? "" : a.endedAt != null ? "ended" : a.lastTs == null ? "started" : `${fmtDur(now - a.lastTs)} ago`);
|
|
300
|
+
$("board").innerHTML =
|
|
301
|
+
`<thead><tr><th>#</th><th class="l">Agent</th><th>Best</th><th>Submits</th><th class="l">Last seen</th></tr></thead><tbody>` +
|
|
302
|
+
rows
|
|
303
|
+
.map((r) => {
|
|
304
|
+
const a = byAgent.get(r.agent);
|
|
305
|
+
const working = live && a && a.startedAt != null && a.endedAt == null;
|
|
306
|
+
const score = r.score == null ? `<span class="quiet">-</span>` : `${fmtScore(r.score)}${r.selfReported ? ` <span class="quiet">self</span>` : ""}`;
|
|
307
|
+
const submits = `${r.submits}${r.errors ? ` <span class="quiet">(${r.errors} failed)</span>` : ""}`;
|
|
308
|
+
return `<tr><td>${r.rank ?? ""}</td><td class="l"><span class="dot${working ? " live" : ""}"></span>${r.agent}</td><td>${score}</td><td>${submits}</td><td class="l quiet">${esc(lastWords(a))}</td></tr>`;
|
|
309
|
+
})
|
|
310
|
+
.join("") +
|
|
311
|
+
`</tbody>`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function drawScores(series, t0, t1, direction) {
|
|
315
|
+
const host = $("scores");
|
|
316
|
+
const ok = series.submits.filter((s) => s.score != null).sort((a, b) => a.ts - b.ts);
|
|
317
|
+
if (ok.length === 0) {
|
|
318
|
+
host.innerHTML = `<div class="empty">No scored submit yet (${series.submits.length} submits, none with a score).</div>`;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const lo = Math.min(...ok.map((s) => s.score)), hi = Math.max(...ok.map((s) => s.score));
|
|
322
|
+
const pad = Math.max(0.005, (hi - lo) * 0.1);
|
|
323
|
+
const better = direction === "min" ? Math.min : Math.max;
|
|
324
|
+
let best = ok[0].score;
|
|
325
|
+
const bestPts = ok.map((s) => [s.ts, (best = better(best, s.score))]);
|
|
326
|
+
host.innerHTML = `<div id="scLegend"></div><div id="scChart"></div>`;
|
|
327
|
+
$("scLegend").innerHTML = legend([["best so far", "var(--c3)"], ["submit (hollow: self-reported)", "var(--c1)"]]);
|
|
328
|
+
const spec = { h: 190, t0, t1, yMin: lo - pad, yMax: hi + pad, yFmt: (v) => String(Math.round(v * 1000) / 1000), label: "scored submits", series: [{ name: "best so far", color: "var(--c3)", pts: bestPts, step: true, w: 1.6 }], points: [] };
|
|
329
|
+
const { x, y } = drawChart($("scChart"), spec);
|
|
330
|
+
let pts = "";
|
|
331
|
+
for (const s of ok) {
|
|
332
|
+
pts += `<circle cx="${x(s.ts)}" cy="${y(s.score)}" r="4.5" fill="${s.selfReported ? "var(--card)" : "var(--c1)"}" stroke="var(--c1)" stroke-width="1.6"><title>agent ${s.agent}: ${fmtScore(s.score)} at ${fmtMin(s.ts, t0)} min</title></circle>`;
|
|
333
|
+
}
|
|
334
|
+
$("scChart").firstElementChild.querySelector(".hit").insertAdjacentHTML("beforebegin", pts);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** The machine in three charts: is the CPU used, is memory short, are commands queueing for a slot (and the GPU when there is one). */
|
|
338
|
+
function drawMachine(series, run, t0, t1) {
|
|
339
|
+
const host = $("machine");
|
|
340
|
+
const M = series.machine;
|
|
341
|
+
const col = (key, f = (v) => v) => M.map((s) => [s.ts, s[key] == null ? null : f(s[key])]);
|
|
342
|
+
const has = (key) => M.some((s) => s[key] != null);
|
|
343
|
+
const memTotalGb = (M.find((s) => s.memTotalMb != null) || {}).memTotalMb / 1024 || null;
|
|
344
|
+
const gpuTotal = (run.facts || {}).gpuMemTotalMb || null;
|
|
345
|
+
const specs = [
|
|
346
|
+
{ id: "m-cpu", title: "CPU busy", ok: has("cpuBusy"), yMax: 100, yFmt: (v) => Math.round(v) + "%", series: [{ name: "CPU busy", color: "var(--c1)", pts: col("cpuBusy", (v) => v * 100) }] },
|
|
347
|
+
{ id: "m-mem", title: "Memory used", ok: has("memUsedMb"), yMax: memTotalGb || undefined, yFmt: (v) => Math.round(v) + " GB", series: [{ name: "used", color: "var(--c1)", pts: col("memUsedMb", (v) => v / 1024) }] },
|
|
348
|
+
{ id: "m-slots", title: "Commands: running and waiting for a slot", ok: has("slotsInUse") || has("slotsWaiting"), step: true, yFmt: (v) => String(Math.round(v)), series: [{ name: "running", color: "var(--c1)", pts: col("slotsInUse") }, { name: "waiting", color: "var(--bad)", pts: col("slotsWaiting") }] },
|
|
349
|
+
{ id: "m-gpu", title: "GPU", ok: has("gpuUtil") || has("gpuMemMb"), yMax: 100, yFmt: (v) => Math.round(v) + "%", series: [{ name: "GPU util", color: "var(--c3)", pts: col("gpuUtil") }, ...(gpuTotal ? [{ name: "GPU memory", color: "var(--c4)", pts: col("gpuMemMb", (v) => (v / gpuTotal) * 100) }] : [])] },
|
|
350
|
+
].filter((s) => s.ok);
|
|
351
|
+
if (specs.length === 0) {
|
|
352
|
+
host.innerHTML = `<div class="empty">No machine readings in this run.</div>`;
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
host.innerHTML = specs.map((s) => `<div><h2>${esc(s.title)}</h2>${s.series.length > 1 ? legend(s.series.map((x) => [x.name, x.color])) : ""}<div id="${s.id}"></div></div>`).join("");
|
|
356
|
+
for (const s of specs) {
|
|
357
|
+
const vals = s.series.flatMap((x) => x.pts.map((p) => p[1])).filter((v) => v != null);
|
|
358
|
+
const hi = Math.max(...vals, 1e-9);
|
|
359
|
+
drawChart($(s.id), { h: 130, t0, t1, yMin: 0, yMax: Math.max(s.yMax || hi * 1.1, hi * 1.02), yFmt: s.yFmt, series: s.series.map((x) => ({ ...x, step: s.step, noExtend: true, w: 1.4 })), label: s.title });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ---------- loading ----------
|
|
364
|
+
async function load() {
|
|
365
|
+
try {
|
|
366
|
+
const [run, series, agents] = await Promise.all([q("/api/run"), q("/api/series"), q("/api/agents")]);
|
|
367
|
+
if (run.error) { $("subtitle").textContent = run.error; return; }
|
|
368
|
+
data = { run, series, agents };
|
|
369
|
+
render();
|
|
370
|
+
} catch (e) { $("subtitle").textContent = "cannot reach the viewer server: " + e; }
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async function loadRuns() {
|
|
374
|
+
const { runs, current } = await fetch("/api/runs").then((r) => r.json());
|
|
375
|
+
const sel = $("runs");
|
|
376
|
+
sel.innerHTML = runs.map((r) => `<option value="${esc(r.name)}">${esc(r.name)}</option>`).join("");
|
|
377
|
+
sel.value = runParam || current || "";
|
|
378
|
+
sel.disabled = runs.length < 2;
|
|
379
|
+
sel.addEventListener("change", () => { location.search = "?run=" + encodeURIComponent(sel.value); });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let timer = null;
|
|
383
|
+
function schedule() { clearTimeout(timer); timer = setTimeout(load, 300); }
|
|
384
|
+
function stream() {
|
|
385
|
+
try {
|
|
386
|
+
const es = new EventSource("/api/stream?run=" + encodeURIComponent(runParam));
|
|
387
|
+
es.addEventListener("update", schedule);
|
|
388
|
+
es.onerror = () => { es.close(); setTimeout(stream, 5000); };
|
|
389
|
+
} catch (e) { setInterval(load, 5000); }
|
|
390
|
+
}
|
|
391
|
+
$("more").addEventListener("toggle", () => data && render());
|
|
392
|
+
let resizeTimer = null;
|
|
393
|
+
addEventListener("resize", () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(() => data && render(), 150); });
|
|
394
|
+
loadRuns().then(load).then(stream);
|
|
395
|
+
</script>
|
|
396
|
+
</body>
|
|
397
|
+
</html>
|