617 lines
40 KiB
HTML
617 lines
40 KiB
HTML
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<title>Storage</title>
|
||
<style>
|
||
* { box-sizing: border-box; }
|
||
[hidden] { display: none !important; }
|
||
html, body { margin: 0; background: hsl(var(--background, 0 0% 100%)); color: hsl(var(--foreground, 222 47% 11%)); }
|
||
body { overflow-x: hidden; font-size: 12px; }
|
||
.content { display: flex; flex-direction: column; gap: 20px; transition: opacity .15s; }
|
||
.content.busy { opacity: .6; }
|
||
.mono { font-family: var(--aia-mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; }
|
||
.muted { color: hsl(var(--muted-foreground, 215 16% 47%)); }
|
||
.trunc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
svg.i { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
|
||
svg.i.sm { width: 12px; height: 12px; }
|
||
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: flex-end; }
|
||
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-right: auto; }
|
||
.ph { margin-bottom: 12px; }
|
||
.ph h2 { margin: 0; font-size: 14px; font-weight: 600; }
|
||
.ph p { margin: 2px 0 0; font-size: 11px; }
|
||
.finding { margin: 0 0 12px; border-left: 2px solid hsl(var(--primary, 24 95% 53%) / .6); background: hsl(var(--muted, 210 40% 96%) / .4);
|
||
border-radius: 8px; padding: 8px 12px; font-size: 12px; line-height: 1.6; }
|
||
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||
.grow { min-width: 0; flex: 1; }
|
||
.runner { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font: inherit; font-size: 11px; border: 0; cursor: pointer;
|
||
background: hsl(var(--muted, 210 40% 96%)); color: hsl(var(--muted-foreground, 215 16% 47%)); }
|
||
.runner.on { background: hsl(var(--primary, 24 95% 53%) / .15); color: hsl(var(--primary, 24 95% 53%)); font-weight: 500; }
|
||
.disks { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
|
||
@media (min-width: 640px) { .disks { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||
.meter .top { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; }
|
||
.track { margin-top: 4px; display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; background: hsl(var(--muted, 210 40% 96%)); }
|
||
.track .a { background: hsl(var(--primary, 24 95% 53%)); }
|
||
.track .o { background: hsl(var(--muted-foreground, 215 16% 47%) / .4); }
|
||
.warnc { color: rgb(245 158 11); } .badc { color: rgb(239 68 68); }
|
||
.kinds { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||
@media (min-width: 640px) { .kinds { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
|
||
.kind { border: 1px solid hsl(var(--border, 214 32% 91%)); border-radius: 8px; padding: 8px 10px; }
|
||
.kind .l { display: flex; align-items: center; gap: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
|
||
.kind .v { font-size: 16px; font-weight: 600; }
|
||
.kind .s { font-size: 11px; }
|
||
.clean { border: 1px solid hsl(var(--border, 214 32% 91%)); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
|
||
.clean label { display: flex; align-items: center; gap: 8px; }
|
||
.clean input[type=number] { width: 44px; text-align: center; }
|
||
.stale { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; border-radius: 6px; border: 0; padding: 4px 8px; font: inherit; font-size: 11px; font-weight: 500; cursor: pointer;
|
||
background: rgb(245 158 11 / .15); color: rgb(180 83 9); }
|
||
html.dark .stale { color: rgb(252 211 77); }
|
||
.stale.armed { background: rgb(245 158 11); color: #fff; }
|
||
.stale:disabled { opacity: .5; }
|
||
ul.items { list-style: none; margin: 0; padding: 0; }
|
||
ul.items > li { padding: 8px 0; }
|
||
ul.items > li + li { border-top: 1px solid hsl(var(--border, 214 32% 91%)); }
|
||
li.gone { opacity: .5; }
|
||
.it { display: flex; min-width: 0; align-items: flex-start; gap: 8px; }
|
||
.ib { margin-top: 2px; flex-shrink: 0; border: 0; background: none; padding: 0; color: hsl(var(--muted-foreground, 215 16% 47%)); cursor: pointer; }
|
||
.ib:disabled { opacity: .3; cursor: default; }
|
||
.chev { transition: transform .15s; } .chev.open { transform: rotate(90deg); }
|
||
.path { font-family: var(--aia-mono, ui-monospace, monospace); font-size: 12px; }
|
||
li.gone .path { text-decoration: line-through; }
|
||
.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); padding: 1px 6px; cursor: default; }
|
||
.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); }
|
||
.pulse { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 999px; background: rgb(16 185 129); }
|
||
.size { flex-shrink: 0; text-align: right; }
|
||
.size .o { font-family: var(--aia-mono, ui-monospace, monospace); font-size: 12px; font-weight: 600; }
|
||
.size .sh { font-family: var(--aia-mono, ui-monospace, 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, 215 16% 47%)); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; font: inherit; font-size: 11px; }
|
||
.rm:hover { background: hsl(var(--destructive, 0 84% 60%) / .1); color: hsl(var(--destructive, 0 84% 60%)); }
|
||
.rm.armed { background: hsl(var(--destructive, 0 84% 60%)); color: #fff; padding: 4px 8px; }
|
||
.rm.invisible { visibility: hidden; }
|
||
.top { margin: 4px 0 0; padding: 0 0 0 8px; list-style: none; border-left: 1px solid hsl(var(--border, 214 32% 91%)); font-family: var(--aia-mono, ui-monospace, monospace); font-size: 11px; }
|
||
.top li { display: flex; justify-content: space-between; gap: 12px; }
|
||
.refused { margin-top: 6px; border-radius: 6px; padding: 6px 8px; font-size: 11px; background: hsl(var(--destructive, 0 84% 60%) / .08); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||
a.conv { color: inherit; text-decoration: none; cursor: pointer; max-width: 18rem; }
|
||
a.conv:hover { text-decoration: underline; }
|
||
.more { border: 0; background: none; padding: 0; font: inherit; font-size: 11px; color: hsl(var(--muted-foreground, 215 16% 47%)); cursor: pointer; }
|
||
.more:hover { color: hsl(var(--foreground, 222 47% 11%)); }
|
||
.net { flex-shrink: 0; font-family: var(--aia-mono, ui-monospace, monospace); font-size: 12px; font-weight: 600; }
|
||
.net.big { color: rgb(217 119 6); }
|
||
.gp { display: inline-flex; flex-shrink: 0; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 6px 1px 1px; font-size: 10px; font-weight: 500;
|
||
line-height: 1; cursor: pointer; background: hsl(var(--primary, 24 95% 53%) / .12); color: hsl(var(--foreground, 222 47% 11%)); }
|
||
.gp .nm { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 0; }
|
||
.av { display: inline-flex; width: 14px; height: 14px; border-radius: 999px; align-items: center; justify-content: center; font-size: 7px; font-weight: 700; color: #fff; flex-shrink: 0; }
|
||
.stack { display: inline-flex; align-items: center; flex-shrink: 0; }
|
||
.stack .av { width: 16px; height: 16px; margin-left: -4px; box-shadow: 0 0 0 1px hsl(var(--card, 0 0% 100%)); cursor: pointer; }
|
||
.stack .av:first-child { margin-left: 0; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="aia-page">
|
||
<div class="aia-stack">
|
||
<div class="bar" id="bar" hidden>
|
||
<div class="chips" id="guestchips"></div>
|
||
<div class="aia-seg" id="scopes" role="group" aria-label="Profile"></div>
|
||
</div>
|
||
<div class="aia-note" id="note" hidden></div>
|
||
<div id="msg" hidden></div>
|
||
<div id="content" class="content" hidden>
|
||
<section class="aia-card" id="disk"></section>
|
||
<section class="aia-card" id="writers"></section>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script>
|
||
(function () {
|
||
"use strict";
|
||
var api = window.aiAgentPlugin || null;
|
||
var init = (api && api.init) || {};
|
||
var KEY = "aia-performance-storage";
|
||
var saved = {};
|
||
try { saved = JSON.parse(localStorage.getItem(KEY) || "{}") || {}; } catch (e) { saved = {}; }
|
||
var RANGES = ["24h", "7d", "30d"];
|
||
var FILTERS = [["all", "All"], ["stale", "Stale"], ["worktree", "Worktrees"], ["scratchpad", "Scratchpads"], ["transcript", "Transcripts"]];
|
||
var KIND_LABEL = { scratchpad: "Scratchpads", worktree: "Worktrees", transcript: "Transcripts", snapshot: "Snapshots", output: "Command output", root: "Other" };
|
||
var SHOW = 25;
|
||
var state = {
|
||
scope: typeof init.scope === "string" && init.scope ? init.scope : (saved.scope || ""),
|
||
guests: [], runner: null, filter: "all", all: false, open: {}, range: RANGES.indexOf(saved.range) >= 0 ? saved.range : "7d",
|
||
refused: {}, busy: {}, scanning: false, cleaning: false,
|
||
};
|
||
function persist() { try { localStorage.setItem(KEY, JSON.stringify({ scope: state.scope, range: state.range })); } catch (e) {} }
|
||
var D = { storage: null, writers: null, config: {} };
|
||
var errs = {};
|
||
var profiles = [], guestNames = {};
|
||
|
||
// ── helpers ──────────────────────────────────────────────────────────────
|
||
function $(id) { return document.getElementById(id); }
|
||
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 = {
|
||
server: "M2 4h20v6H2zM2 14h20v6H2zM6 7h.01M6 17h.01",
|
||
laptop: "M4 5h16v10H4zM2 19h20",
|
||
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",
|
||
refresh: "M3 12a9 9 0 0 1 15-6.7L21 8M21 3v5h-5M21 12a9 9 0 0 1-15 6.7L3 16M3 21v-5h5",
|
||
eraser: "M7 21l-4.3-4.3a1 1 0 0 1 0-1.4l10-10a1 1 0 0 1 1.4 0l5.6 5.6a1 1 0 0 1 0 1.4L13 19M22 21H7M5 11l9 9",
|
||
chev: "M9 18l6-6-6-6",
|
||
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, cls) { return s("svg", { viewBox: "0 0 24 24", class: "i" + (cls ? " " + cls : "") }, [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 signed(n) { return (n >= 0 ? "+" : "−") + fmtBytes(Math.abs(n)); }
|
||
function tilde(p) { return String(p).replace(/^\/(?:home|Users)\/[^/]+(?=\/|$)/, "~"); }
|
||
|
||
// ── the bridge ───────────────────────────────────────────────────────────
|
||
function read(payload, cb) {
|
||
if (api.query) return api.query("read", payload, cb);
|
||
var live = true, last = null;
|
||
function run() {
|
||
return api.action("read", payload).then(
|
||
function (d) { last = d; if (live) cb(d, { fromCache: false, fetching: false, at: Date.now() }); },
|
||
function (e) { if (live) cb(last, { error: String((e && e.message) || e), fromCache: false, fetching: false, at: Date.now() }); });
|
||
}
|
||
run();
|
||
return { stop: function () { live = false; }, refresh: run };
|
||
}
|
||
function act(payload) { return api.action("act", payload); }
|
||
function toast(msg, tone) { if (api && api.toast) api.toast(msg, tone || "info"); }
|
||
var headerJson = "";
|
||
function setHeader(h) {
|
||
var j = JSON.stringify(h);
|
||
if (j === headerJson || !api || !api.setHeader) return;
|
||
headerJson = j;
|
||
api.setHeader(h);
|
||
}
|
||
function go(path) { if (api && api.navigate) api.navigate(path); }
|
||
function msgOf(e) { return String((e && e.message) || e); }
|
||
|
||
// ── guests ───────────────────────────────────────────────────────────────
|
||
function hue(uid) { var h = 0; for (var i = 0; i < uid.length; i++) h = (h * 31 + uid.charCodeAt(i)) % 360; return "hsl(" + h + " 55% 45%)"; }
|
||
function nameOf(uid) { return guestNames[uid] || uid; }
|
||
function avatar(uid) {
|
||
var ini = nameOf(uid).split(/\s+/).map(function (w) { return w.charAt(0); }).join("").slice(0, 2).toUpperCase();
|
||
return el("span", { class: "av", style: "background:" + hue(uid), text: ini || "?" });
|
||
}
|
||
function guestPill(uid) {
|
||
if (!uid) return null;
|
||
var nm = nameOf(uid);
|
||
return el("span", { class: "gp", role: "button", tabindex: "0", title: nm + "'s — tap to show only " + nm + "'s",
|
||
onclick: function (e) { e.preventDefault(); e.stopPropagation(); pickGuest(uid); } }, [avatar(uid), el("span", { class: "nm", text: nm })]);
|
||
}
|
||
function guestStack(uids) {
|
||
if (!uids || !uids.length) return null;
|
||
var box = el("span", { class: "stack", title: uids.map(nameOf).join(", ") });
|
||
uids.slice(0, 4).forEach(function (u) {
|
||
var a = avatar(u);
|
||
a.addEventListener("click", function (e) { e.preventDefault(); e.stopPropagation(); pickGuest(u); });
|
||
box.appendChild(a);
|
||
});
|
||
return box;
|
||
}
|
||
function pickGuest(uid) {
|
||
var again = state.scope === "profile:guests" && state.guests.length === 1 && state.guests[0] === uid;
|
||
state.scope = "profile:guests";
|
||
state.guests = again ? [] : [uid];
|
||
persist(); loadAll();
|
||
}
|
||
function scopeSegs() {
|
||
var segs = profiles.map(function (p) { return { id: "profile:" + p.id, label: p.label || p.id }; });
|
||
if (segs.length) segs.push({ id: "all", label: "All" });
|
||
return segs;
|
||
}
|
||
function renderScope() {
|
||
var box = $("scopes");
|
||
box.textContent = "";
|
||
var segs = scopeSegs();
|
||
$("bar").hidden = !segs.length;
|
||
segs.forEach(function (x) {
|
||
var on = x.id === (state.scope || "all");
|
||
box.appendChild(el("button", { type: "button", class: on ? "aia-active" : null, "aria-pressed": on ? "true" : "false", text: x.label,
|
||
onclick: function () { if (on) return; state.scope = x.id; if (x.id !== "profile:guests") state.guests = []; persist(); loadAll(); } }));
|
||
});
|
||
var chips = $("guestchips");
|
||
chips.textContent = "";
|
||
if (state.scope !== "profile:guests") return;
|
||
Object.keys(guestNames).sort(function (a, b) { return nameOf(a).localeCompare(nameOf(b)); }).forEach(function (uid) {
|
||
var on = state.guests.indexOf(uid) >= 0;
|
||
chips.appendChild(el("button", { type: "button", class: "aia-chip" + (on ? " aia-active" : ""), "aria-pressed": on ? "true" : "false",
|
||
onclick: function () { state.guests = on ? state.guests.filter(function (g) { return g !== uid; }) : state.guests.concat([uid]); loadAll(); } },
|
||
[avatar(uid), " " + nameOf(uid)]));
|
||
});
|
||
}
|
||
|
||
// ── one item on disk ─────────────────────────────────────────────────────
|
||
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");
|
||
}
|
||
function shortName(it) {
|
||
if (it.label) return it.label;
|
||
var base = String(it.path).replace(/\/+$/, "").split("/").pop() || it.path;
|
||
return it.kind === "scratchpad" || it.kind === "transcript" ? base.slice(0, 8) : base;
|
||
}
|
||
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 verdict(v) {
|
||
if (!VERDICT[v]) return null;
|
||
return el("span", { class: "vb " + v, title: VERDICT[v][1] }, [v === "live" ? el("span", { class: "pulse" }) : null, VERDICT[v][0]]);
|
||
}
|
||
/** Remove (a second tap confirms); when agent-probe keeps it, say why and offer to force it. */
|
||
function remove(it, force) {
|
||
var key = it.runner + ":" + it.path;
|
||
state.busy[key] = true; delete state.refused[key]; renderDisk();
|
||
return act({ op: "storageRm", runner: it.runner, path: it.path, force: !!force }).then(function (r) {
|
||
delete state.busy[key];
|
||
if (!r.ok && r.unsafe) { state.refused[key] = String(r.error || "").replace(/^unsafe: /, ""); renderDisk(); return false; }
|
||
if (!r.ok) { toast("Couldn't remove " + shortName(it) + ": " + (r.error || "it is still there"), "error"); renderDisk(); return false; }
|
||
toast("Removed " + shortName(it) + " · " + [fmtBytes((r.removal && r.removal.freed) || it.own) + " freed", r.removal && r.removal.note].filter(Boolean).join(" · "), "success");
|
||
refreshStorage();
|
||
return true;
|
||
}).catch(function (e) { delete state.busy[key]; toast("Couldn't remove " + shortName(it) + ": " + msgOf(e), "error"); renderDisk(); return false; });
|
||
}
|
||
function removeBtn(it) {
|
||
var removable = !it.gone && (it.kind === "scratchpad" || it.kind === "worktree");
|
||
var key = it.runner + ":" + it.path;
|
||
var armed = false, t = null;
|
||
var b = el("button", { type: "button", class: "rm" + (removable ? "" : " invisible"), disabled: !removable || state.busy[key] ? true : null,
|
||
title: removable ? "Remove " + tilde(it.path) + " — frees " + fmtBytes(it.own) + (it.kind === "worktree" && it.git && it.git.merged ? "; its merged branch " + (it.git.branch || "") + " goes with it" : "")
|
||
: "Transcripts and extra roots aren't removed from here", "aria-label": "Remove " + tilde(it.path) });
|
||
function paint() { b.classList.toggle("armed", armed); b.textContent = ""; if (armed) b.textContent = "Remove?"; else b.appendChild(svg("trash")); }
|
||
b.addEventListener("click", function () {
|
||
if (armed) { armed = false; clearTimeout(t); remove(it); }
|
||
else { armed = true; paint(); t = setTimeout(function () { armed = false; paint(); }, 4000); }
|
||
});
|
||
paint();
|
||
return b;
|
||
}
|
||
function itemRow(it) {
|
||
var key = it.runner + ":" + it.path;
|
||
var open = !!state.open[key];
|
||
var shared = Math.max(0, (it.bytes || 0) - (it.own || 0));
|
||
var top = (it.top || []).filter(function (e) { return (e.own || 0) >= 1 << 20 || (e.bytes || 0) >= 1 << 20; });
|
||
var convs = it.conversations || [];
|
||
var git = gitWords(it);
|
||
var kids = [el("div", { class: "it" }, [
|
||
el("button", { type: "button", class: "ib", disabled: top.length ? null : true, "aria-label": open ? "Hide what is in it" : "What is in it",
|
||
onclick: function () { state.open[key] = !open; renderDisk(); } }, [svg("chev", "chev" + (open ? " open" : ""))]),
|
||
el("span", { class: "muted", style: "margin-top:2px;display:inline-flex" }, [kindIcon(it)]),
|
||
el("div", { class: "grow" }, [
|
||
el("div", { class: "row", style: "gap:6px;flex-wrap:nowrap" }, [el("span", { class: "path trunc", title: it.path, text: tilde(it.path) }), verdict(it.verdict),
|
||
(it.guests || []).length === 1 ? guestPill(it.guests[0]) : guestStack(it.guests || [])]),
|
||
el("div", { class: "sub muted" }, [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].concat(convs.map(function (c) {
|
||
return c.conversationId ? el("a", { class: "conv trunc", href: "#", text: c.title || "session " + String(c.sessionId).slice(0, 8),
|
||
onclick: function (e) { e.preventDefault(); go("/conversation/" + c.conversationId); } })
|
||
: el("span", { class: "mono", text: String(c.sessionId).slice(0, 8) });
|
||
}))),
|
||
open && top.length ? el("ul", { class: "top muted" }, top.map(function (e) {
|
||
return el("li", null, [el("span", { class: "trunc", text: e.name }), el("span", null, [fmtBytes(e.own || 0),
|
||
(e.bytes || 0) - (e.own || 0) > 1 << 20 ? el("span", { style: "opacity:.6", text: " +" + fmtBytes((e.bytes || 0) - (e.own || 0)) + " shared" }) : null])]);
|
||
})) : 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 (a hardlink-copied node_modules): removing it frees none of this", text: "+" + fmtBytes(shared) + " shared" }) : null]),
|
||
removeBtn(it),
|
||
])];
|
||
if (state.refused[key]) {
|
||
kids.push(el("div", { class: "refused" }, [el("span", { class: "grow", text: "agent-probe kept it: " + state.refused[key] + ". Remove it anyway? What it holds is lost." }),
|
||
el("button", { type: "button", class: "aia-btn aia-btn-danger aia-btn-sm", text: "Remove anyway", onclick: function () { remove(it, true); } }),
|
||
el("button", { type: "button", class: "aia-btn aia-btn-ghost aia-btn-sm", text: "Keep", onclick: function () { delete state.refused[key]; renderDisk(); } })]));
|
||
}
|
||
return el("li", { class: it.gone ? "gone" : null, "data-testid": "storage-item" }, kids);
|
||
}
|
||
|
||
// ── a machine's disk ─────────────────────────────────────────────────────
|
||
function usedPct(d) { return d.total ? (100 * (d.total - d.avail)) / d.total : 0; }
|
||
function agentsOwn(d) { var o = 0; for (var k in d.agents || {}) o += (d.agents[k] && d.agents[k].own) || 0; return o; }
|
||
function diskMeter(d) {
|
||
var pct = usedPct(d), t = d.total || 0, used = d.total - d.avail, a = t ? Math.min(100, (agentsOwn(d) / t) * 100) : 0;
|
||
var o = t ? Math.max(0, Math.min(100 - a, ((used - agentsOwn(d)) / t) * 100)) : 0;
|
||
var parts = Object.keys(d.agents || {}).filter(function (k) { return ((d.agents[k] || {}).own || 0) > 0; })
|
||
.sort(function (x, y) { return (d.agents[y].own || 0) - (d.agents[x].own || 0); })
|
||
.map(function (k) { return (KIND_LABEL[k] || k).toLowerCase() + " " + fmtBytes(d.agents[k].own); });
|
||
var track = el("div", { class: "track", title: "agents " + fmtBytes(agentsOwn(d)) + " · the rest " + fmtBytes(Math.max(0, used - agentsOwn(d))) });
|
||
if (a > 0) track.appendChild(el("div", { class: "a", style: "width:" + a + "%" }));
|
||
if (o > 0) track.appendChild(el("div", { class: "o", style: "width:" + o + "%" }));
|
||
return el("div", { class: "meter" }, [
|
||
el("div", { class: "top" }, [el("span", { class: "muted", text: d.mount + (d.ram ? " · RAM (tmpfs)" : "") }),
|
||
el("span", { class: "mono" + (pct >= 90 ? " badc" : pct >= 80 ? " warnc" : "") }, [fmtBytes(d.avail) + " free ", el("span", { class: "muted", text: "of " + fmtBytes(d.total) })])]),
|
||
track,
|
||
el("div", { class: "muted", style: "margin-top:4px;font-size:11px", text: (parts.length ? "Agents': " + parts.join(" · ") : "nothing of the agents'") +
|
||
((d.emptyScratch || 0) > 0 ? " · " + d.emptyScratch.toLocaleString() + " empty session dirs" : "") }),
|
||
]);
|
||
}
|
||
function finding(r) {
|
||
var ram = r.disks.filter(function (d) { return d.ram && usedPct(d) >= 70; })[0];
|
||
if (ram) return ram.mount + " (RAM) is " + Math.round(usedPct(ram)) + "% full — " + fmtBytes(((ram.agents || {}).scratchpad || {}).own || 0) +
|
||
" of it is session scratchpads, which nothing cleans until a reboot.";
|
||
if (r.stale.items > 0) return plural(r.stale.items, "stale item") + " hold " + fmtBytes(r.stale.own) + " — merged, clean worktrees and scratch dirs untouched for 3 days.";
|
||
var full = r.disks.filter(function (d) { return usedPct(d) >= 85; })[0];
|
||
if (full) return full.mount + " is " + Math.round(usedPct(full)) + "% full.";
|
||
return null;
|
||
}
|
||
function kindTiles(r) {
|
||
var ram = r.disks.some(function (d) { return d.ram; });
|
||
return el("div", { class: "kinds" }, Object.keys(r.kinds || {}).sort(function (a, b) { return r.kinds[b].own - r.kinds[a].own; }).map(function (k) {
|
||
var x = r.kinds[k];
|
||
return el("div", { class: "kind" }, [el("div", { class: "l muted" }, [kindIcon({ kind: k, ram: k === "scratchpad" && ram }), KIND_LABEL[k] || k]),
|
||
el("div", { class: "v mono", text: fmtBytes(x.own) }),
|
||
el("div", { class: "s muted", text: x.items.toLocaleString() + " · " + (x.bytes - x.own > 1 << 30 ? fmtBytes(x.bytes) + " on disk" : "owned") })]);
|
||
}));
|
||
}
|
||
function autoClean(runner) {
|
||
var c = D.config[runner];
|
||
if (c && c.error) return el("p", { class: "muted", style: "font-size:11px;margin:0", text: "Settings unavailable: " + c.error });
|
||
if (!c || !c.data) return el("div");
|
||
var cfg = c.data, on = cfg.autoCleanDays > 0, days = on ? cfg.autoCleanDays : 3;
|
||
function save(b) {
|
||
act(Object.assign({ op: "storageConfig", runner: runner }, b)).then(function (r) { D.config[runner] = { data: r }; renderDisk(); })
|
||
.catch(function (e) { toast("Couldn't save: " + msgOf(e), "error"); });
|
||
}
|
||
var sw1 = el("input", { type: "checkbox", checked: on ? true : null });
|
||
sw1.addEventListener("change", function () { save({ autoCleanDays: sw1.checked ? days : 0 }); });
|
||
var num = el("input", { type: "number", min: "1", max: "60", class: "aia-input mono", value: String(days), disabled: on ? null : true });
|
||
num.addEventListener("blur", function () { var n = Number(num.value); if (on && n >= 1 && n !== days) save({ autoCleanDays: n }); });
|
||
var sw2 = el("input", { type: "checkbox", checked: cfg.nudgeAt > 0 ? true : null });
|
||
sw2.addEventListener("change", function () { save({ nudgeAt: sw2.checked ? 0.9 : 0 }); });
|
||
return el("div", { class: "clean" }, [
|
||
el("label", null, [sw1, el("span", null, ["Auto-clean the scratch dirs of sessions quiet for ", num, " days"])]),
|
||
el("label", null, [sw2, el("span", null, ["Tell the agent when its disk is " + (cfg.nudgeAt > 0 ? Math.round(cfg.nudgeAt * 100) + "%" : "90%") + " full",
|
||
el("span", { class: "muted", text: " — a line in its next prompt" })])]),
|
||
]);
|
||
}
|
||
function cleanStale(stale) {
|
||
var own = sum(stale, function (i) { return i.own; });
|
||
state.cleaning = true; renderDisk();
|
||
toast("Removing " + stale.length + "…");
|
||
var freed = 0, kept = 0, i = 0;
|
||
function next() {
|
||
if (i >= stale.length) {
|
||
state.cleaning = false;
|
||
toast(fmtBytes(freed) + " freed" + (kept ? " · " + kept + " kept" : ""), kept ? "info" : "success");
|
||
refreshStorage();
|
||
return;
|
||
}
|
||
var it = stale[i++];
|
||
act({ op: "storageRm", runner: it.runner, path: it.path }).then(function (r) {
|
||
if (r.ok) freed += (r.removal && r.removal.freed) || it.own; else kept++;
|
||
}).catch(function () { kept++; }).then(next);
|
||
}
|
||
next();
|
||
return own;
|
||
}
|
||
function staleBtn(r, stale) {
|
||
var armed = false, t = null;
|
||
var b = el("button", { type: "button", class: "stale", disabled: state.cleaning ? true : null,
|
||
title: "Frees about " + fmtBytes(r.stale.own) + ": merged, clean worktrees (their merged branches go too) and scratch dirs nobody touched for 3 days. agent-probe re-checks each one and keeps any that turned out to hold work or be in use." });
|
||
function paint() {
|
||
b.classList.toggle("armed", armed); b.textContent = "";
|
||
if (armed) b.textContent = "Clean up " + plural(stale.length, "stale item") + "?";
|
||
else { b.appendChild(svg("eraser", "sm")); b.appendChild(document.createTextNode(" Clean up stale · " + fmtBytes(r.stale.own))); }
|
||
}
|
||
b.addEventListener("click", function () {
|
||
if (armed) { armed = false; clearTimeout(t); cleanStale(stale); }
|
||
else { armed = true; paint(); t = setTimeout(function () { armed = false; paint(); }, 4000); }
|
||
});
|
||
paint();
|
||
return b;
|
||
}
|
||
function scan(r) {
|
||
state.scanning = true; renderDisk();
|
||
act({ op: "storageScan", runner: r.runner }).then(function () { toast("Measured " + (r.name || r.runner), "success"); })
|
||
.catch(function (e) { toast("Couldn't measure: " + msgOf(e), "error"); })
|
||
.then(function () { state.scanning = false; refreshStorage(); });
|
||
}
|
||
function renderDisk() {
|
||
var box = $("disk");
|
||
if (box.contains(document.activeElement) && document.activeElement.tagName === "INPUT") return; // typing a setting
|
||
var d = D.storage, runners = (d && d.runners) || [];
|
||
var r = runners.filter(function (x) { return x.runner === state.runner; })[0] || runners[0];
|
||
box.textContent = "";
|
||
box.appendChild(el("div", { class: "ph" }, [el("h2", { text: "On disk" }),
|
||
el("p", { class: "muted", text: "What do the sessions keep on disk — scratchpads, worktrees, transcripts — and what can go?" })]));
|
||
if (!r) { box.appendChild(el("p", { class: "muted", text: errs.storage || "No runner has reported its storage yet — it needs agent-probe." })); return; }
|
||
var f = finding(r);
|
||
if (f) box.appendChild(el("p", { class: "finding", text: f }));
|
||
if (!D.config[r.runner]) loadConfig(r.runner);
|
||
var age = Math.max(0, Date.now() / 1000 - Math.max.apply(null, [0].concat(r.disks.map(function (x) { return x.at || 0; }))));
|
||
var head = el("div", { class: "row", style: "margin-bottom:16px" });
|
||
if (runners.length > 1) runners.forEach(function (x) {
|
||
head.appendChild(el("button", { type: "button", class: "runner" + (x.runner === r.runner ? " on" : ""), onclick: function () { state.runner = x.runner; renderDisk(); } },
|
||
[x.owner ? avatar(x.owner) : svg(x.runner === "lab" ? "server" : "laptop", "sm"), " " + (x.name || x.runner), x.owner ? el("span", { style: "opacity:.7", text: " · " + nameOf(x.owner) }) : null]));
|
||
});
|
||
head.appendChild(el("span", { class: "muted row", style: "gap:4px;font-size:11px" }, [svg("drive", "sm"), "measured " + fmtSpan(age) + " ago"]));
|
||
head.appendChild(el("span", { class: "grow" }));
|
||
head.appendChild(el("button", { type: "button", class: "aia-btn aia-btn-ghost aia-btn-sm", disabled: state.scanning ? true : null,
|
||
title: "Measure everything now (a full pass takes a minute or two)", onclick: function () { scan(r); } },
|
||
[svg("refresh", "sm" + (state.scanning ? " aia-spin" : "")), state.scanning ? " Measuring…" : " Measure now"]));
|
||
box.appendChild(head);
|
||
var body = el("div", { class: "aia-stack" });
|
||
body.appendChild(el("div", { class: "disks" }, r.disks.map(diskMeter)));
|
||
body.appendChild(kindTiles(r));
|
||
body.appendChild(autoClean(r.runner));
|
||
var stale = r.items.filter(function (i) { return i.verdict === "stale"; });
|
||
var items = r.items.filter(function (i) { return state.filter === "all" ? true : state.filter === "stale" ? i.verdict === "stale" : i.kind === state.filter; });
|
||
var fbar = el("div", { class: "aia-seg", role: "group" }, FILTERS.map(function (fl) {
|
||
var on = fl[0] === state.filter;
|
||
return el("button", { type: "button", class: on ? "aia-active" : null, "aria-pressed": on ? "true" : "false",
|
||
onclick: function () { state.filter = fl[0]; state.all = false; renderDisk(); } }, [fl[1], fl[0] === "stale" && stale.length ? " " + stale.length : null]);
|
||
}));
|
||
body.appendChild(el("div", { class: "row" }, [fbar, el("span", { class: "grow" }), stale.length ? staleBtn(r, stale) : null]));
|
||
var shown = state.all ? items : items.slice(0, SHOW);
|
||
body.appendChild(shown.length ? el("ul", { class: "items" }, shown.map(itemRow)) : el("p", { class: "muted", text: "Nothing here." }));
|
||
if (items.length > shown.length) body.appendChild(el("button", { type: "button", class: "more", text: "Show " + (items.length - shown.length) + " more",
|
||
onclick: function () { state.all = true; renderDisk(); } }));
|
||
box.appendChild(body);
|
||
}
|
||
|
||
// ── biggest writers ──────────────────────────────────────────────────────
|
||
function renderWriters() {
|
||
var box = $("writers");
|
||
var rows = ((D.writers && D.writers.rows) || []).filter(function (r) { return r.net >= 64 << 10; });
|
||
box.textContent = "";
|
||
box.appendChild(el("div", { class: "ph" }, [el("h2", { text: "Biggest writers" }),
|
||
el("p", { class: "muted", text: "Which calls left the most on disk? Exact: every file their processes wrote, unlinked or renamed over." })]));
|
||
box.appendChild(el("div", { class: "aia-seg", role: "group", style: "margin-bottom:8px" }, RANGES.map(function (x) {
|
||
var on = x === state.range;
|
||
return el("button", { type: "button", class: on ? "aia-active" : null, "aria-pressed": on ? "true" : "false", text: x,
|
||
onclick: function () { if (on) return; state.range = x; persist(); loadWriters(); } });
|
||
})));
|
||
if (!rows.length) {
|
||
box.appendChild(el("p", { class: "muted", text: D.writers ? "Nothing yet — calls report their writes once their runner has agent-probe (Linux)." : (errs.writers || "") }));
|
||
return;
|
||
}
|
||
box.appendChild(el("ul", { class: "items" }, rows.map(function (r) {
|
||
var where = (r.dirs && r.dirs[0] && r.dirs[0].dir) || (r.top && r.top[0] && r.top[0].path);
|
||
return el("li", { "data-testid": "writer-row" }, [el("div", { class: "it" }, [
|
||
el("div", { class: "grow" }, [
|
||
el("code", { class: "path trunc", style: "display:block", title: r.command || null,
|
||
text: r.tool && r.tool !== "Bash" ? r.tool + " " + ((r.top && r.top[0] && r.top[0].path) || "") : (r.command || "") }),
|
||
el("div", { class: "sub muted" }, [where ? el("span", { class: "mono trunc", title: String(where), text: tilde(where) }) : null,
|
||
el("span", { text: plural(r.files || 0, "file") }),
|
||
r.freed > 0 ? el("span", { text: "freed " + fmtBytes(r.freed) }) : null,
|
||
r.startedAt != null ? el("span", { text: fmtSpan(Date.now() / 1000 - r.startedAt) + " ago" }) : null,
|
||
r.conversationId ? el("a", { class: "conv trunc", href: "#", text: r.title || "session " + String(r.sessionId).slice(0, 8),
|
||
onclick: function (e) { e.preventDefault(); go("/conversation/" + r.conversationId); } })
|
||
: el("span", { class: "mono", text: String(r.sessionId || "").slice(0, 8) }),
|
||
guestPill(r.guest)]),
|
||
]),
|
||
el("span", { class: "net" + (r.net >= 1 << 30 ? " big" : ""), text: signed(r.net) }),
|
||
])]);
|
||
})));
|
||
}
|
||
|
||
// ── reads ────────────────────────────────────────────────────────────────
|
||
var Q = {};
|
||
function sub(name, payload, every, onData) {
|
||
if (Q[name]) { Q[name].h.stop(); clearInterval(Q[name].t); }
|
||
var my = (Q[name] = { h: null, t: null });
|
||
my.h = read(payload, function (d, meta) { if (Q[name] === my) onData(d, meta || {}); });
|
||
if (every) my.t = setInterval(function () { if (!document.hidden && Q[name] === my) my.h.refresh(); }, every);
|
||
}
|
||
function scopePayload(extra) { return Object.assign({ scope: state.scope, guests: state.guests }, extra || {}); }
|
||
function refreshStorage() { if (Q.storage) Q.storage.h.refresh(); if (Q.writers) Q.writers.h.refresh(); }
|
||
function loadConfig(runner) {
|
||
D.config[runner] = { loading: true };
|
||
read({ view: "storageConfig", runner: runner }, function (d, meta) {
|
||
D.config[runner] = d ? { data: d } : { error: (meta && meta.error) || "no answer" };
|
||
renderDisk();
|
||
});
|
||
}
|
||
function loadWriters() {
|
||
sub("writers", scopePayload({ view: "writers", range: state.range }), 120000, function (d, meta) {
|
||
errs.writers = meta.error || null;
|
||
if (d) D.writers = d;
|
||
render();
|
||
});
|
||
render();
|
||
}
|
||
function loadAll() {
|
||
$("content").classList.add("busy");
|
||
sub("storage", scopePayload({ view: "storage" }), 60000, function (d, meta) {
|
||
errs.storage = meta.error || null;
|
||
if (d) {
|
||
D.storage = d;
|
||
if (Array.isArray(d.profiles) && d.profiles.length) profiles = d.profiles;
|
||
if (d.guestNames) guestNames = d.guestNames;
|
||
}
|
||
render();
|
||
});
|
||
loadWriters();
|
||
renderScope();
|
||
}
|
||
|
||
function showMsg(kind, title, text) {
|
||
var box = $("msg");
|
||
box.textContent = "";
|
||
box.className = kind === "error" ? "aia-error" : "aia-empty";
|
||
if (kind === "error") box.textContent = text;
|
||
else { box.appendChild(el("strong", { text: title })); if (text) box.appendChild(document.createTextNode(text)); }
|
||
box.hidden = false;
|
||
$("content").hidden = true;
|
||
}
|
||
function render() {
|
||
var d = D.storage;
|
||
if (!d) { if (errs.storage) showMsg("error", "", errs.storage); return; }
|
||
$("msg").hidden = true; $("content").hidden = false;
|
||
$("content").classList.remove("busy");
|
||
var note = $("note");
|
||
note.hidden = !errs.storage;
|
||
note.textContent = errs.storage ? "Couldn't refresh (" + errs.storage + ") — showing the last reading." : "";
|
||
var lab = (d.runners || [])[0], ram = lab && lab.disks.filter(function (x) { return x.ram; })[0];
|
||
setHeader({ subtitle: lab ? [ram ? ram.mount + " " + Math.round((100 * (ram.total - ram.avail)) / Math.max(1, ram.total)) + "% full" : null,
|
||
lab.stale.items ? lab.stale.items + " stale · " + fmtBytes(lab.stale.own) : "nothing stale"].filter(Boolean).join(" · ") : "what the agents keep on disk" });
|
||
var y = window.scrollY;
|
||
renderScope();
|
||
renderDisk();
|
||
renderWriters();
|
||
window.scrollTo(0, y);
|
||
}
|
||
|
||
document.addEventListener("visibilitychange", function () { if (!document.hidden) refreshStorage(); });
|
||
if (api && typeof api.onTheme === "function") api.onTheme(function () { if (D.storage) render(); });
|
||
if (!api) showMsg("empty", "Open this page from the ai-agent", "");
|
||
else loadAll();
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|