Files

257 lines
15 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>On disk</title>
<!--
conversation.details: what a conversation keeps on disk (perf.read's
hub/perf/conversation/{sid}/storage, agent-probe's records) — its
scratchpad (RAM on the lab, where /tmp is a tmpfs), the worktrees it made
or worked in, its transcript, what its calls wrote — each with a Remove
that agent-probe re-checks on the machine. Folds away when it keeps
nothing and wrote nothing.
-->
<style>
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: transparent; }
body { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 12px;
line-height: 1.35; color: hsl(var(--foreground)); -webkit-font-smoothing: antialiased; }
.card { border: 1px solid hsl(var(--border)); border-radius: 12px; background: hsl(var(--card)); padding: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: hsl(var(--muted-foreground)); }
.trunc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 10px; font-weight: 600; text-transform: uppercase;
letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
.head svg { color: hsl(var(--primary)); }
svg.i { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
p { margin: 0; }
.writes { margin-top: 4px; font-size: 11px; }
ul { list-style: none; margin: 0; padding: 0; }
li { padding: 8px 0; }
li + li { border-top: 1px solid hsl(var(--border)); }
li.gone { opacity: .5; }
li.gone .path { text-decoration: line-through; }
.it { display: flex; min-width: 0; align-items: flex-start; gap: 8px; }
.grow { min-width: 0; flex: 1; }
.path { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.sub { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 0 6px; font-size: 11px; }
.vb { flex-shrink: 0; border-radius: 999px; padding: 1px 6px; font-size: 10px; font-weight: 500; }
.vb.stale { background: rgb(245 158 11 / .15); color: rgb(217 119 6); }
.vb.work { background: rgb(14 165 233 / .15); color: rgb(2 132 199); }
.vb.live { background: rgb(16 185 129 / .15); color: rgb(5 150 105); }
.size { flex-shrink: 0; text-align: right; }
.size .o { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-weight: 600; }
.size .sh { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; }
.rm { margin-top: 2px; flex-shrink: 0; border-radius: 4px; border: 0; background: none; padding: 4px; color: hsl(var(--muted-foreground)); cursor: pointer; font: inherit; font-size: 11px; display: inline-flex; }
.rm:hover { background: hsl(var(--destructive) / .1); color: hsl(var(--destructive)); }
.rm.armed { background: hsl(var(--destructive)); color: #fff; padding: 4px 8px; }
.rm.invisible { visibility: hidden; }
.refused { margin-top: 6px; border-radius: 6px; padding: 6px 8px; font-size: 11px; background: hsl(var(--destructive) / .08); }
.refused .b { margin-top: 6px; display: flex; gap: 6px; }
.refused button { border-radius: 6px; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); padding: 2px 8px; font: inherit; font-size: 11px; cursor: pointer; color: inherit; }
.refused button.d { border-color: hsl(var(--destructive)); background: hsl(var(--destructive)); color: #fff; }
</style>
</head>
<body>
<div id="root"></div>
<script>
(function () {
"use strict";
var A = window.aiAgentPlugin || {};
var init = A.init || {};
var root = document.getElementById("root");
var U = {}, data = null, q = null, timer = null;
// reuseFrame: the host keeps this frame across conversation switches; the
// session comes in init.update / onUpdate (init.sessionId on older hosts).
var sid = String((init.update && init.update.sessionId) || init.sessionId || "");
var refused = {}, busy = {};
function el(tag, attrs, kids) {
var n = document.createElement(tag);
for (var k in attrs || {}) {
if (attrs[k] == null || attrs[k] === false) continue;
if (k === "text") n.textContent = attrs[k];
else if (k === "style") n.setAttribute("style", attrs[k]);
else if (k === "onclick") n.addEventListener("click", attrs[k]);
else n.setAttribute(k, attrs[k] === true ? "" : attrs[k]);
}
(kids || []).forEach(function (c) {
if (c == null || c === false) return;
n.appendChild(typeof c === "string" || typeof c === "number" ? document.createTextNode(String(c)) : c);
});
return n;
}
var NS = "http://www.w3.org/2000/svg";
function s(tag, attrs, kids) {
var n = document.createElementNS(NS, tag);
for (var k in attrs || {}) if (attrs[k] != null) n.setAttribute(k, attrs[k]);
(kids || []).forEach(function (c) { if (c) n.appendChild(c); });
return n;
}
var ICONS = {
drive: "M22 12H2M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11zM6 16h.01M10 16h.01",
folder: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9l-.8-1.2A2 2 0 0 0 7.9 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2z",
git: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9l-.8-1.2A2 2 0 0 0 7.9 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2zM12 10v6M12 10a2 2 0 1 0 0-.01M15 13a2 2 0 1 0 0 .01",
scroll: "M8 21h12a2 2 0 0 0 2-2v-2H10v2a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v3h4M19 17V5a2 2 0 0 0-2-2H4M15 8h-5M15 12h-5",
mem: "M6 19v-3M10 19v-3M14 19v-3M18 19v-3M2 15h20M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2z",
trash: "M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",
};
function svg(name) { return s("svg", { viewBox: "0 0 24 24", class: "i" }, [s("path", { d: ICONS[name] })]); }
function sum(a, f) { return a.reduce(function (n, x) { return n + ((f ? f(x) : x) || 0); }, 0); }
function plural(n, w, ws) { return n + " " + (n === 1 ? w : (ws || w + "s")); }
function fmtBytes(n) {
if (n == null) return "—";
var u = ["B", "KB", "MB", "GB", "TB"], v = n, i = 0;
while (v >= 1024 && i < u.length - 1) { v /= 1024; i++; }
return (v >= 100 || i < 2 ? v.toFixed(0) : v.toFixed(1)) + " " + u[i];
}
function fmtSpan(x) {
if (x < 60) return Math.max(0, Math.round(x)) + "s";
if (x < 3600) return Math.round(x / 60) + " min";
if (x < 86400 * 2) return (x / 3600).toFixed(x < 36000 ? 1 : 0) + " h";
return Math.round(x / 86400) + " d";
}
function tilde(p) { return String(p).replace(/^\/(?:home|Users)\/[^/]+(?=\/|$)/, "~"); }
function toast(m, tone) { if (A.toast) A.toast(m, tone || "info"); }
function kindIcon(it) {
if (it.kind === "worktree") return svg("git");
if (it.kind === "transcript") return svg("scroll");
if (it.kind === "scratchpad" && it.ram) return svg("mem");
return svg("folder");
}
/** A narrow column: the worktree's dir, "scratchpad", "transcript" (the full path is the tooltip). */
function compactName(it) {
if (it.kind === "worktree" || it.kind === "root") return it.label || String(it.path).replace(/\/+$/, "").split("/").pop() || it.path;
return it.kind;
}
function gitWords(it) {
var g = it.git, w = [];
if (!g) return w;
if (g.branch) w.push(g.branch); else if (g.head) w.push("detached " + String(g.head).slice(0, 7));
if (g.merged === true) w.push("merged into " + (g.base || "main"));
else if (g.merged === false && g.ahead != null) w.push(plural(g.ahead, "commit") + " not on " + g.base);
if (g.dirty != null) w.push(g.dirty ? g.dirty + " uncommitted" : "clean");
if (g.native) w.push("Claude Code worktree");
return w;
}
var VERDICT = { stale: ["stale", "Safe to remove: nothing in it main lacks, nobody has touched it for 3 days"],
work: ["holds work", "Commits or changes its repo's main branch doesn't have"], live: ["in use", "A conversation using it is running"] };
function remove(it, force) {
var key = it.runner + ":" + it.path;
busy[key] = true; delete refused[key]; render();
A.action("act", { op: "storageRm", runner: it.runner, path: it.path, force: !!force }).then(function (r) {
delete busy[key];
if (!r.ok && r.unsafe) { refused[key] = String(r.error || "").replace(/^unsafe: /, ""); render(); return; }
if (!r.ok) { toast("Couldn't remove " + compactName(it) + ": " + (r.error || "it is still there"), "error"); render(); return; }
toast("Removed " + compactName(it) + " · " + fmtBytes((r.removal && r.removal.freed) || it.own) + " freed", "success");
if (q) q.refresh();
}).catch(function (e) { delete busy[key]; toast("Couldn't remove: " + ((e && e.message) || e), "error"); render(); });
}
function row(it) {
var key = it.runner + ":" + it.path;
var removable = !it.gone && (it.kind === "scratchpad" || it.kind === "worktree");
var shared = Math.max(0, (it.bytes || 0) - (it.own || 0));
var git = gitWords(it);
var armed = false, t = null;
var rm = el("button", { type: "button", class: "rm" + (removable ? "" : " invisible"), disabled: !removable || busy[key] ? true : null, "aria-label": "Remove " + tilde(it.path),
title: removable ? "Remove " + tilde(it.path) + " — frees " + fmtBytes(it.own) : "Transcripts aren't removed from here" });
function paint() { rm.classList.toggle("armed", armed); rm.textContent = ""; if (armed) rm.textContent = "Remove?"; else rm.appendChild(svg("trash")); }
rm.addEventListener("click", function () { if (armed) { armed = false; clearTimeout(t); remove(it); } else { armed = true; paint(); t = setTimeout(function () { armed = false; paint(); }, 4000); } });
paint();
var kids = [el("div", { class: "it" }, [
el("span", { class: "muted", style: "margin-top:2px;display:inline-flex" }, [kindIcon(it)]),
el("div", { class: "grow" }, [
el("div", { class: "path trunc", title: it.path, text: compactName(it) }),
el("div", { class: "sub muted" }, [VERDICT[it.verdict] ? el("span", { class: "vb " + it.verdict, title: VERDICT[it.verdict][1], text: VERDICT[it.verdict][0] }) : null,
it.gone ? el("span", { text: "removed" }) : null, git.length ? el("span", { class: "trunc", text: git.join(" · ") }) : null,
it.idleS != null ? el("span", { text: "idle " + fmtSpan(it.idleS) }) : null,
it.ram && it.kind === "scratchpad" ? el("span", { title: "/tmp is a tmpfs: these bytes are memory", text: "in RAM" }) : null]),
]),
el("div", { class: "size" }, [el("div", { class: "o", text: fmtBytes(it.own) }),
shared > 1 << 20 ? el("div", { class: "sh muted", title: "hard links it shares: removing it frees none of this", text: "+" + fmtBytes(shared) + " shared" }) : null]),
rm,
])];
if (refused[key]) kids.push(el("div", { class: "refused" }, [el("div", { text: "agent-probe kept it: " + refused[key] + ". Remove it anyway? What it holds is lost." }),
el("div", { class: "b" }, [el("button", { type: "button", class: "d", text: "Remove anyway", onclick: function () { remove(it, true); } }),
el("button", { type: "button", text: "Keep", onclick: function () { delete refused[key]; render(); } })])]));
return el("li", { class: it.gone ? "gone" : null }, kids);
}
function render() {
var d = data;
if (!d || ((d.items || []).length === 0 && !(d.writes && d.writes.calls))) return show(null);
var items = d.items || [], kept = items.filter(function (i) { return !i.gone; });
var by = function (k) { return kept.filter(function (i) { return i.kind === k; }); };
var parts = [by("scratchpad").length ? "scratchpad " + fmtBytes(sum(by("scratchpad"), function (i) { return i.own; })) : null,
by("worktree").length ? plural(by("worktree").length, "worktree") + " " + fmtBytes(sum(by("worktree"), function (i) { return i.own; })) : null,
d.transcript ? "transcript " + fmtBytes(d.transcript) : null].filter(Boolean);
var w = d.writes;
show(el("section", { class: "card" }, [
el("div", { class: "head" }, [svg("drive"), "On disk"]),
el("p", null, kept.length ? ["Keeps ", el("span", { class: "mono", style: "font-weight:600", text: fmtBytes((d.left || 0) + (d.transcript || 0)) }),
el("span", { class: "muted", text: " — " + parts.join(" · ") })] : [el("span", { class: "muted", text: "Nothing left on disk." })]),
w && w.calls > 0 ? el("p", { class: "writes muted", title: "exact: every file its Bash calls' processes wrote, unlinked or renamed over, and its Write / Edit calls" },
["Its calls wrote ", el("span", { class: "mono", text: fmtBytes(w.written) }), ", freed ", el("span", { class: "mono", text: fmtBytes(w.freed) }), " — net ",
el("span", { class: "mono", style: "font-weight:500;color:hsl(var(--foreground))", text: (w.net >= 0 ? "+" : "−") + fmtBytes(Math.abs(w.net)) })]) : null,
el("ul", null, items.map(row)),
]));
}
var lastH = -1, empty = null;
function fit() {
var h = empty ? 0 : Math.ceil(root.getBoundingClientRect().height);
if (h !== lastH) { lastH = h; if (A.resize) A.resize(h); }
}
function show(node) {
var nowEmpty = !node;
while (root.firstChild) root.removeChild(root.firstChild);
if (node) root.appendChild(node);
if (nowEmpty !== empty) { empty = nowEmpty; if (A.setEmpty) A.setEmpty(nowEmpty); }
fit();
}
if (window.ResizeObserver) new ResizeObserver(fit).observe(root);
function read(payload, cb) {
if (A.query) return A.query("read", payload, cb);
var live = true;
function run() { return A.action("read", payload).then(function (x) { if (live) cb(x, {}); }, function (e) { if (live) cb(null, { error: String((e && e.message) || e) }); }); }
run();
return { stop: function () { live = false; }, refresh: run };
}
function schedule() {
clearInterval(timer);
if (U.running && U.drawerOpen !== false) timer = setInterval(function () { if (!document.hidden && q) q.refresh(); }, 30000);
}
function start() {
if (q) q.stop();
q = null;
if (!sid) { show(null); return; }
q = read({ view: "conversationStorage", sid: sid }, function (x) { if (x) data = x; render(); });
}
var wasRunning = null;
function onUpdate(u) {
U = u && typeof u === "object" ? u : {};
if (Object.prototype.hasOwnProperty.call(U, "sessionId") && String(U.sessionId || "") !== sid) {
// Another conversation in the same frame: drop the last one's numbers
// at once, then read the new one's.
sid = String(U.sessionId || "");
data = null;
wasRunning = null;
show(null);
start();
}
if (wasRunning === true && !U.running && q) q.refresh();
wasRunning = !!U.running;
schedule();
}
start();
if (typeof A.onUpdate === "function") A.onUpdate(onUpdate);
onUpdate(init.update || {});
if (typeof A.onTheme === "function") A.onTheme(function () { if (data) render(); });
})();
</script>
</body>
</html>