Files
archie/internal/webui/index.html
T

210 lines
9.3 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>archie</title>
<style>
:root {
--bg: #101418; --panel: #171d24; --line: #232b34;
--fg: #d5dde5; --dim: #7d8a96; --accent: #58a6ff;
--ok: #3fb950; --warn: #d29922; --bad: #f85149;
font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
font: 1rem/1.45 system-ui, sans-serif; }
header { display: flex; align-items: baseline; gap: .75rem;
padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); }
header h1 { font-size: 1.05rem; margin: 0; letter-spacing: .04em; }
header .sub { color: var(--dim); font-size: .85rem; }
main { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem;
padding: 1rem 1.2rem; max-width: 1500px; }
section { background: var(--panel); border: 1px solid var(--line);
border-radius: 8px; padding: .9rem 1rem; }
section h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
color: var(--dim); margin: 0 0 .6rem; }
.cards { display: flex; gap: .6rem; flex-wrap: wrap; grid-column: 1 / -1;
background: none; border: none; padding: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
padding: .55rem .9rem; min-width: 7.5rem; }
.card .n { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.card .l { color: var(--dim); font-size: .78rem; }
.section-table { overflow-x: auto; }
section .table-wrap { position: relative; overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; color: var(--dim); font-weight: 500; padding: .25rem .5rem .25rem 0; white-space: nowrap; }
td { padding: .3rem .5rem .3rem 0; border-top: 1px solid var(--line);
font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
.status { display: inline-block; padding: .05rem .5rem; border-radius: 99px;
font-size: .75rem; border: 1px solid var(--line); }
.status.merged { color: var(--ok); } .status.pr_open { color: var(--accent); }
.status.parked { color: var(--warn); } .status.rejected, .status.closed_wont_do { color: var(--bad); }
.status.running { color: var(--fg); } .status.queued { color: var(--dim); }
tr.task { cursor: pointer; } tr.task:hover td { background: #1c242d; }
#feed { font-family: ui-monospace, monospace; font-size: .78rem; max-height: 30rem;
overflow-y: auto; display: flex; flex-direction: column-reverse; }
#feed div { padding: .12rem 0; border-top: 1px solid var(--line); white-space: normal;
overflow-wrap: break-word; }
#feed .t { color: var(--dim); } #feed .k { color: var(--accent); }
#feed .k-parked, #feed .k-pr_rejected { color: var(--bad); }
#feed .k-pr_merged, #feed .k-outcome { color: var(--ok); }
#timeline { grid-column: 1 / -1; display: none; }
#timeline.open { display: block; }
.bar { background: #253141; height: .6rem; border-radius: 3px; display: inline-block;
vertical-align: middle; }
.muted { color: var(--dim); }
@media (max-width: 950px) { main { grid-template-columns: 1fr; } }
@media (max-width: 700px) {
header { padding: .6rem .8rem; }
header .sub { font-size: .75rem; }
main { padding: .5rem; gap: .5rem; }
section { padding: .5rem .6rem; }
section { min-height: 1.25rem; }
.card { min-width: 4rem; padding: .35rem .6rem; }
.card .n { font-size: 1.2rem; }
table { font-size: .75rem; }
th, td { padding: .15rem .3rem; }
#feed { font-size: .7rem; }
}
</style>
</head>
<body>
<header>
<h1>archie</h1>
<span class="sub">autonomous project agent — <span id="conn" class="muted">connecting…</span></span>
</header>
<main>
<div class="cards" id="cards"></div>
<section style="grid-column: 1">
<h2>Tasks</h2>
<div class="section-table"><table id="tasks"><thead><tr>
<th>repo</th><th>issue</th><th>title</th><th>workflow</th><th>status</th>
<th class="num">steps</th><th class="num">tokens</th>
</tr></thead><tbody></tbody></table></div>
</section>
<section style="grid-column: 2">
<h2>Live events</h2>
<div id="feed"></div>
</section>
<section id="timeline">
<h2>Task timeline — <span id="timeline-title"></span></h2>
<div class="section-table"><table id="timeline-table"><thead><tr>
<th>time</th><th>kind</th><th>stage</th><th>detail</th>
</tr></thead><tbody></tbody></table></div>
</section>
<section style="grid-column: 1">
<h2>Workflows</h2>
<div class="section-table"><table id="workflows"><thead><tr>
<th>workflow</th><th class="num">runs</th><th class="num">merged</th>
<th class="num">open</th><th class="num">parked</th>
<th class="num">avg tokens</th><th class="num">avg steps</th><th class="num">total tokens</th>
</tr></thead><tbody></tbody></table></div>
</section>
<section style="grid-column: 2">
<h2>Token spend by day</h2>
<div class="section-table"><table id="days"><tbody></tbody></table></div>
</section>
<section style="grid-column: 1 / -1">
<h2>Stages</h2>
<div class="section-table"><table id="stages"><thead><tr>
<th>workflow</th><th>stage</th><th class="num">runs</th>
<th class="num">avg duration</th><th class="num">errors</th>
</tr></thead><tbody></tbody></table></div>
</section>
</main>
<script>
const $ = s => document.querySelector(s);
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"}[c]));
const fmt = n => (n ?? 0).toLocaleString();
const ms = v => v >= 60000 ? (v/60000).toFixed(1)+"m" : v >= 1000 ? (v/1000).toFixed(1)+"s" : v+"ms";
async function refresh() {
const [summary, tasks] = await Promise.all([
fetch("/api/summary").then(r => r.json()),
fetch("/api/tasks").then(r => r.json()),
]);
const order = ["queued","running","waiting_human","pr_open","merged","parked","rejected","closed_wont_do"];
$("#cards").innerHTML = order.filter(s => summary.statuses[s])
.map(s => `<div class="card"><div class="n">${summary.statuses[s]}</div><div class="l">${s}</div></div>`)
.join("") || '<div class="card"><div class="n">0</div><div class="l">tasks</div></div>';
$("#tasks tbody").innerHTML = (tasks ?? []).map(t => `
<tr class="task" onclick="showTask(${t.ID}, '${esc(t.Owner)}/${esc(t.Repo)}#${t.IssueNumber}')">
<td>${esc(t.Owner)}/${esc(t.Repo)}</td><td>#${t.IssueNumber}</td>
<td>${esc(t.Title)}</td><td>${esc(t.Workflow)}</td>
<td><span class="status ${esc(t.Status)}">${esc(t.Status)}</span></td>
<td class="num">${fmt(t.Iterations)}</td><td class="num">${fmt(t.TokensUsed)}</td>
</tr>`).join("");
$("#workflows tbody").innerHTML = (summary.workflows ?? []).map(w => `
<tr><td>${esc(w.Workflow)}</td><td class="num">${w.Runs}</td>
<td class="num">${w.Merged}</td><td class="num">${w.PROpen}</td><td class="num">${w.Parked}</td>
<td class="num">${fmt(w.AvgTokens)}</td><td class="num">${w.AvgSteps.toFixed(1)}</td>
<td class="num">${fmt(w.TotalToken)}</td></tr>`).join("");
$("#stages tbody").innerHTML = (summary.stages ?? []).map(s => `
<tr><td>${esc(s.Workflow)}</td><td>${esc(s.Stage)}</td><td class="num">${s.Runs}</td>
<td class="num">${ms(s.AvgMs)}</td>
<td class="num">${s.Errors ? `<span style="color:var(--warn)">${s.Errors}</span>` : 0}</td></tr>`).join("");
const days = summary.tokens_by_day ?? [];
const max = Math.max(1, ...days.map(d => d.Tokens));
$("#days tbody").innerHTML = days.map(d => `
<tr><td>${esc(d.Day)}</td>
<td><span class="bar" style="width:${Math.round(140 * d.Tokens / max)}px"></span></td>
<td class="num">${fmt(d.Tokens)}</td></tr>`).join("");
}
async function showTask(id, label) {
const evs = await fetch("/api/tasks/" + id).then(r => r.json());
$("#timeline-title").textContent = label;
$("#timeline").classList.add("open");
$("#timeline-table tbody").innerHTML = (evs ?? []).map(e => `
<tr><td class="muted">${new Date(e.at).toLocaleTimeString()}</td>
<td>${esc(e.kind)}</td><td>${esc(e.stage)}</td>
<td>${esc(e.detail || JSON.stringify(e.data ?? ""))}</td></tr>`).join("");
$("#timeline").scrollIntoView({behavior: "smooth"});
}
let refreshTimer = null;
function feedLine(e) {
const div = document.createElement("div");
const where = e.repo ? `${e.repo}#${e.issue}` : "";
div.innerHTML = `<span class="t">${new Date(e.at).toLocaleTimeString()}</span>
<span class="k k-${esc(e.kind)}">${esc(e.kind)}</span>
${esc(where)} ${esc(e.stage)} <span class="muted">${esc(e.detail).slice(0, 160)}</span>`;
const feed = $("#feed");
feed.prepend(div);
while (feed.childElementCount > 300) feed.lastChild.remove();
clearTimeout(refreshTimer);
refreshTimer = setTimeout(refresh, 400);
}
function connect() {
const since = localStorage.getItem("archie-since") || "0";
const es = new EventSource("/events?since=" + since);
es.onopen = () => { $("#conn").textContent = "live"; $("#conn").style.color = "var(--ok)"; };
es.onmessage = m => {
const e = JSON.parse(m.data);
if (e.id) localStorage.setItem("archie-since", e.id);
feedLine(e);
};
es.onerror = () => { $("#conn").textContent = "reconnecting…"; $("#conn").style.color = "var(--warn)"; };
}
refresh();
connect();
</script>
</body>
</html>