Files
archie/ui/src/base/gauge.js
T
sam 4d44ef76f5 feat(webui): rebuild the dashboard
The old UI was a single 200-line Go file serving one hand-written HTML
page of task rows. It showed that archied was running and almost nothing
about what it was doing -- skills, workflows, memory, channels, logs and
configuration were all invisible unless you read the source or the
config file.

The dashboard now covers each of those as its own section, built as a
Vite app under ui/ at the repo root: it is a separate artefact from the
Go daemon, not an internal package of it. dist/ is committed so building
archied never needs a Node toolchain, and the !no_ui build tag keeps an
embed-free build available.

Both sides are split by concern rather than by layer -- one Go file per
API area, one folder per UI section with its own CSS -- so a change to
logs cannot disturb tasks.

Pages report consequences, not just state: an empty memory page says
Archie starts every conversation with no recollection of earlier ones,
and the setup checklist names what is missing in plain language instead
of showing a grid of zeroes. Nothing greets by a hardcoded name; the
operator comes from [chat], which is deployment data.

Auth is exposure control, not capability control -- the agent already
holds this user's authority through its own tools. So a loopback bind
needs no token, and only a reachable bind mints one and logs a URL,
which means an instance cannot be exposed merely by omitting config.

Container startup now degrades instead of aborting, for the reason
resolveForge already does: a missing agent image should not deny the
operator chat and the dashboard, and under Restart=on-failure it turns a
recoverable problem into a crash loop with the real error scrolling past.

`task dev` runs the daemon under air and the Vite server together in one
terminal.
2026-08-04 01:45:36 +10:00

90 lines
2.8 KiB
JavaScript

import { el } from "./dom.js";
/**
* Arc gauge for a single headline percentage.
*
* A percentage that decides whether you need to act deserves more than a line
* of text -- the arc is readable at a glance from across a room, which a
* number is not. Colour follows the value, so "is this bad" is answered before
* the digits are read.
*/
export function gauge({ value, label, size = 168 }) {
const pct = Math.max(0, Math.min(100, Number(value) || 0));
const stroke = pct >= 90 ? "var(--ok)" : pct >= 70 ? "var(--warn)" : "var(--danger)";
// 240-degree arc, opening downward, so the value reads left-to-right.
const r = 62;
const cx = size / 2;
const cy = size / 2;
const sweep = 240;
const start = 150;
const circumference = 2 * Math.PI * r * (sweep / 360);
const arc = (from, deg) => {
const a0 = (from * Math.PI) / 180;
const a1 = ((from + deg) * Math.PI) / 180;
const large = deg > 180 ? 1 : 0;
return [
`M ${cx + r * Math.cos(a0)} ${cy + r * Math.sin(a0)}`,
`A ${r} ${r} 0 ${large} 1 ${cx + r * Math.cos(a1)} ${cy + r * Math.sin(a1)}`,
].join(" ");
};
const svg = el("svg.gauge", {
viewBox: `0 0 ${size} ${size * 0.78}`,
role: "img",
"aria-label": `${label}: ${pct}%`,
});
svg.innerHTML = `
<path d="${arc(start, sweep)}" fill="none" stroke="var(--border)"
stroke-width="12" stroke-linecap="round"/>
<path d="${arc(start, sweep)}" fill="none" stroke="${stroke}"
stroke-width="12" stroke-linecap="round"
stroke-dasharray="${circumference}"
stroke-dashoffset="${circumference * (1 - pct / 100)}"
class="gauge-value"/>`;
return el(
"div.gauge-wrap",
svg,
el("div.gauge-center", el("div.gauge-pct", `${Math.round(pct)}%`), el("div.gauge-label", label)),
);
}
/**
* Segmented proportional bar with a legend.
*
* segments: [{ label, value, kind }] where kind maps to a status token.
* Used for budget composition -- what is spent, committed and still free --
* because three related quantities are easier to compare in one bar than in
* three separate numbers.
*/
export function segmentBar(segments) {
const total = segments.reduce((a, s) => a + (s.value || 0), 0) || 1;
return el(
"div",
el(
"div.segbar",
...segments
.filter((s) => s.value > 0)
.map((s) =>
el("span", {
class: `segbar-part segbar-${s.kind || "idle"}`,
style: `width:${((s.value / total) * 100).toFixed(1)}%`,
title: `${s.label}: ${s.value}`,
}),
),
),
el(
"div.segbar-legend",
...segments.map((s) =>
el(
"span.segbar-key",
el("span", { class: `segbar-dot segbar-${s.kind || "idle"}` }),
s.label,
),
),
),
);
}