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.
This commit is contained in:
1 parent
449c925f29
commit
4d44ef76f5
61 files changed
+5889
-576
No files matched your search
@@ -0,0 +1,63 @@
|
||||
// Single place that knows how to talk to archied. Every feature folder goes
|
||||
// through this, so auth handling and error shape live in one file.
|
||||
|
||||
async function req(path) {
|
||||
const res = await fetch(path, { headers: { Accept: "application/json" } });
|
||||
if (res.status === 401) {
|
||||
throw new ApiError("unauthorised", 401);
|
||||
}
|
||||
if (!res.ok) {
|
||||
throw new ApiError(`${res.status} ${res.statusText}`, res.status);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
// qs builds a query string, omitting empty values so the server sees an
|
||||
// absent filter rather than an empty one.
|
||||
function qs(params) {
|
||||
const q = new URLSearchParams();
|
||||
for (const [k, v] of Object.entries(params || {})) {
|
||||
if (v !== "" && v != null) q.set(k, v);
|
||||
}
|
||||
const s = q.toString();
|
||||
return s ? `?${s}` : "";
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(message, status) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
export const api = {
|
||||
summary: () => req("/api/summary"),
|
||||
tasks: () => req("/api/tasks"),
|
||||
task: (id) => req(`/api/tasks/${id}`),
|
||||
setup: () => req("/api/setup"),
|
||||
workflows: () => req("/api/workflows"),
|
||||
skills: () => req("/api/skills"),
|
||||
channels: () => req("/api/channels"),
|
||||
config: () => req("/api/config"),
|
||||
logs: (params) => req("/api/logs" + qs(params)),
|
||||
memory: () => req("/api/memory"),
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribe to archied's event stream. Returns an unsubscribe function.
|
||||
* Reconnection is the browser's job via EventSource, but a closed stream is
|
||||
* surfaced to the caller so the UI can show it rather than silently freezing.
|
||||
*/
|
||||
export function subscribeEvents(onEvent, onStateChange) {
|
||||
const src = new EventSource("/events");
|
||||
src.onopen = () => onStateChange?.("live");
|
||||
src.onerror = () => onStateChange?.("reconnecting");
|
||||
src.onmessage = (e) => {
|
||||
try {
|
||||
onEvent(JSON.parse(e.data));
|
||||
} catch {
|
||||
/* a malformed frame should not kill the stream */
|
||||
}
|
||||
};
|
||||
return () => src.close();
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// Tiny DOM helpers. Deliberately not a framework: the dashboard is a handful
|
||||
// of pages over a read-mostly API, and a build-free vanilla layer keeps the
|
||||
// embedded bundle small.
|
||||
|
||||
/**
|
||||
* el("div.card", {onclick}, child, child) -> HTMLElement
|
||||
* The tag string accepts CSS-ish shorthand: "button.btn.btn-primary".
|
||||
*/
|
||||
export function el(spec, attrs, ...children) {
|
||||
const [tag, ...classes] = spec.split(".");
|
||||
const node = document.createElement(tag || "div");
|
||||
if (classes.length) node.className = classes.join(" ");
|
||||
|
||||
if (attrs && (typeof attrs !== "object" || attrs instanceof Node)) {
|
||||
children.unshift(attrs);
|
||||
attrs = null;
|
||||
}
|
||||
for (const [k, v] of Object.entries(attrs || {})) {
|
||||
if (v == null || v === false) continue;
|
||||
if (k.startsWith("on") && typeof v === "function") {
|
||||
node.addEventListener(k.slice(2).toLowerCase(), v);
|
||||
} else if (k === "class") {
|
||||
node.className = [node.className, v].filter(Boolean).join(" ");
|
||||
} else if (k === "html") {
|
||||
node.innerHTML = v;
|
||||
} else {
|
||||
node.setAttribute(k, v === true ? "" : String(v));
|
||||
}
|
||||
}
|
||||
append(node, children);
|
||||
return node;
|
||||
}
|
||||
|
||||
function append(node, children) {
|
||||
for (const c of children.flat(Infinity)) {
|
||||
if (c == null || c === false) continue;
|
||||
node.append(c instanceof Node ? c : document.createTextNode(String(c)));
|
||||
}
|
||||
}
|
||||
|
||||
export function mount(parent, ...children) {
|
||||
parent.replaceChildren();
|
||||
append(parent, children);
|
||||
return parent;
|
||||
}
|
||||
|
||||
/** Status pill. Kind maps to the semantic colour tokens. */
|
||||
export function pill(text, kind = "idle") {
|
||||
return el(`span.pill.pill-${kind}`, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map an archie task status onto a pill kind. Centralised so "merged" is the
|
||||
* same green everywhere it appears.
|
||||
*/
|
||||
export function statusKind(status) {
|
||||
switch (status) {
|
||||
case "running":
|
||||
return "info";
|
||||
case "merged":
|
||||
case "pr_open":
|
||||
return "ok";
|
||||
case "parked":
|
||||
case "waiting_human":
|
||||
return "warn";
|
||||
case "dead":
|
||||
case "rejected":
|
||||
return "danger";
|
||||
default:
|
||||
return "idle";
|
||||
}
|
||||
}
|
||||
|
||||
/** Humanised relative time: "2 min ago". Raw timestamps make people do maths. */
|
||||
export function ago(value) {
|
||||
if (!value) return "—";
|
||||
const then = value instanceof Date ? value : new Date(value);
|
||||
const secs = Math.floor((Date.now() - then.getTime()) / 1000);
|
||||
if (!Number.isFinite(secs)) return "—";
|
||||
if (secs < 45) return "just now";
|
||||
const units = [
|
||||
["min", 60],
|
||||
["hr", 3600],
|
||||
["day", 86400],
|
||||
["wk", 604800],
|
||||
];
|
||||
let label = "min", size = 60;
|
||||
for (const [l, s] of units) {
|
||||
if (secs >= s) [label, size] = [l, s];
|
||||
}
|
||||
const n = Math.floor(secs / size);
|
||||
return `${n} ${label}${n === 1 ? "" : "s"} ago`;
|
||||
}
|
||||
|
||||
/** Compact number: 2_400_000 -> "2.4M". Long digit strings do not scan. */
|
||||
export function compact(n) {
|
||||
if (n == null || Number.isNaN(n)) return "—";
|
||||
return new Intl.NumberFormat(undefined, { notation: "compact", maximumFractionDigits: 1 }).format(n);
|
||||
}
|
||||
|
||||
export function empty(title, detail) {
|
||||
return el("div.empty", el("div.empty-title", title), detail && el("div", detail));
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Icon set.
|
||||
*
|
||||
* A single stroked 24-grid system rather than Unicode glyphs: glyphs render at
|
||||
* different weights and baselines per platform, cannot inherit stroke width,
|
||||
* and have no consistent optical size. Every icon here shares the same grid,
|
||||
* stroke and cap style, so a row of them lines up.
|
||||
*/
|
||||
|
||||
const paths = {
|
||||
dashboard: '<rect x="3" y="3" width="7" height="9" rx="1.5"/><rect x="14" y="3" width="7" height="5" rx="1.5"/><rect x="14" y="12" width="7" height="9" rx="1.5"/><rect x="3" y="16" width="7" height="5" rx="1.5"/>',
|
||||
tasks: '<path d="M9 6h11M9 12h11M9 18h11"/><path d="M4 6l1 1 2-2M4 12l1 1 2-2M4 18l1 1 2-2"/>',
|
||||
logs: '<path d="M4 5h16M4 10h16M4 15h10M4 20h7"/>',
|
||||
skills: '<path d="M12 3l2.6 5.6 6.1.8-4.5 4.2 1.2 6-5.4-3-5.4 3 1.2-6L3.3 9.4l6.1-.8z"/>',
|
||||
workflows: '<path d="M4 7h6a3 3 0 0 1 3 3v4a3 3 0 0 0 3 3h4"/><path d="M17 4l3 3-3 3"/><path d="M7 21l-3-3 3-3"/>',
|
||||
memory: '<circle cx="12" cy="12" r="3.2"/><path d="M12 3v3.4M12 17.6V21M3 12h3.4M17.6 12H21M5.6 5.6l2.4 2.4M16 16l2.4 2.4M18.4 5.6L16 8M8 16l-2.4 2.4"/>',
|
||||
channels: '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3.5 7l8.5 6 8.5-6"/>',
|
||||
settings: '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-2.9 1.2V21a2 2 0 1 1-4 0v-.1A1.7 1.7 0 0 0 7 19.4a1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.7 1.7 0 0 0 3 15H3a2 2 0 1 1 0-4h.1A1.7 1.7 0 0 0 4.6 7a1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.7 1.7 0 0 0 9 3.6V3a2 2 0 1 1 4 0v.1A1.7 1.7 0 0 0 15 4.6h.1a1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"/>',
|
||||
search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/>',
|
||||
moon: '<path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z"/>',
|
||||
sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M19.1 4.9l-1.4 1.4M6.3 17.7l-1.4 1.4"/>',
|
||||
refresh: '<path d="M20 11a8 8 0 1 0-1.2 5.2"/><path d="M20 4v7h-7"/>',
|
||||
bell: '<path d="M18 9a6 6 0 1 0-12 0c0 6-2 7-2 7h16s-2-1-2-7"/><path d="M13.7 20a2 2 0 0 1-3.4 0"/>',
|
||||
trendUp: '<path d="M4 17L10 11l4 4 6-6"/><path d="M14 7h6v6"/>',
|
||||
trendDown: '<path d="M4 7l6 6 4-4 6 6"/><path d="M14 17h6v-6"/>',
|
||||
check: '<path d="M4.5 12.5l5 5 10-11"/>',
|
||||
help: '<circle cx="12" cy="12" r="9"/><path d="M9.6 9.4a2.5 2.5 0 1 1 3.3 2.4c-.6.2-.9.8-.9 1.4v.4"/><path d="M12 17.2h.01"/>',
|
||||
};
|
||||
|
||||
/**
|
||||
* icon("tasks") -> SVGElement. size is the rendered box; the grid is always 24
|
||||
* so stroke weight stays optically consistent at any size.
|
||||
*/
|
||||
export function icon(name, { size = 18, className = "" } = {}) {
|
||||
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
svg.setAttribute("viewBox", "0 0 24 24");
|
||||
svg.setAttribute("width", String(size));
|
||||
svg.setAttribute("height", String(size));
|
||||
svg.setAttribute("fill", "none");
|
||||
svg.setAttribute("stroke", "currentColor");
|
||||
svg.setAttribute("stroke-width", "1.6");
|
||||
svg.setAttribute("stroke-linecap", "round");
|
||||
svg.setAttribute("stroke-linejoin", "round");
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.setAttribute("class", `ico ${className}`.trim());
|
||||
svg.innerHTML = paths[name] || paths.dashboard;
|
||||
return svg;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { el } from "./dom.js";
|
||||
import { icon } from "./icons.js";
|
||||
|
||||
/**
|
||||
* A KPI tile: label, big value, trend against a stated comparison window, and
|
||||
* a sparkline. The comparison line is not decoration -- a number without a
|
||||
* baseline cannot be acted on, so `compare` is required.
|
||||
*
|
||||
* trend > 0 renders as an increase. `goodDirection` says whether that is good,
|
||||
* because rising latency and rising success rate are not the same news.
|
||||
*/
|
||||
export function statTile({ label, value, unit, trend, compare, series = [], goodDirection = "up" }) {
|
||||
const dir = trend == null ? null : trend >= 0 ? "up" : "down";
|
||||
const good = dir == null ? null : dir === goodDirection;
|
||||
|
||||
return el(
|
||||
"div.card.stat",
|
||||
el(
|
||||
"div.stat-head",
|
||||
el("span.stat-label", label),
|
||||
dir &&
|
||||
el(
|
||||
`span.stat-trend.${good ? "up" : "down"}`,
|
||||
icon(dir === "up" ? "trendUp" : "trendDown", { size: 13 }),
|
||||
`${Math.abs(trend).toFixed(1)}%`,
|
||||
),
|
||||
),
|
||||
el("div.stat-value", value, unit && el("span.stat-unit", unit)),
|
||||
compare && el("div.stat-compare", compare),
|
||||
series.length > 1 && sparkline(series, good === false ? "var(--danger)" : "var(--ok)"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline SVG sparkline. Shows shape, not exact values -- the tile's headline
|
||||
* number carries the precision.
|
||||
*/
|
||||
export function sparkline(series, stroke = "var(--ok)", { width = 220, height = 34 } = {}) {
|
||||
const max = Math.max(...series, 1);
|
||||
const min = Math.min(...series, 0);
|
||||
const span = max - min || 1;
|
||||
const step = series.length > 1 ? width / (series.length - 1) : width;
|
||||
|
||||
const points = series
|
||||
.map((v, i) => `${(i * step).toFixed(1)},${(height - ((v - min) / span) * height).toFixed(1)}`)
|
||||
.join(" ");
|
||||
|
||||
const svg = el("svg.spark", {
|
||||
viewBox: `0 0 ${width} ${height}`,
|
||||
preserveAspectRatio: "none",
|
||||
"aria-hidden": "true",
|
||||
});
|
||||
svg.innerHTML =
|
||||
`<polyline points="${points}" fill="none" stroke="${stroke}" stroke-width="1.5" ` +
|
||||
`stroke-linecap="round" stroke-linejoin="round" vector-effect="non-scaling-stroke"/>`;
|
||||
return svg;
|
||||
}
|
||||
Reference in new issue
Block a user