feat(webui): bootstrap Vue 3 + shadcn-vue, replacing the Preact dashboard
Sam owns this codebase and reads Vue fluently, not Preact; a UI its maintainer
cannot read is the liability that outweighs the port. shadcn-vue is Vue-only,
so adopting it means the framework moves with it.
Scaffolded per the official Vite guide: `npm create vite --template vue-ts`,
Tailwind v4 via @tailwindcss/vite, `shadcn-vue init` (Reka UI, Lucide, neutral
base, CSS variables). Button and DropdownMenu are added, the latter being what
the pending navigation restructure needs.
Two deviations from the guide, both forced:
- The guide sets `baseUrl` alongside `paths`. TypeScript 6 deprecates
`baseUrl` and errors on it, and this project is heading for TS 7 native, so
`paths` stands alone and resolves relative to the config file. Not a
downgrade: the scaffold's typescript ~6.0.2 is untouched.
- vite.config.ts keeps `base: "./"` and unhashed asset names. ui/embed.go
embeds a committed dist/, served from a path the build does not know;
hashed names would also orphan a file in git on every rebuild.
The Preact app and its 43 test files are deleted rather than ported, on Sam's
instruction: tests return when there is behaviour worth pinning rather than a
port to re-assert. `task test:ui` is now a vue-tsc typecheck, which is what
would actually catch a broken component; an empty `npm test` would pass
vacuously.
ui/src/router/index.ts carries the route table and is the new source of truth
for TestDashboardPagesRegistryCoversEveryRoute, which parsed main.jsx before.
Keeping that contract alive matters: it is what caught the stale /chat entry
earlier today. Every route resolves to a named placeholder view, so an unported
page is visibly unported rather than blank.
golangci-lint now excludes ui/node_modules. The dashboard toolchain pulls in
`flatted`, which ships a Go implementation beside its JavaScript, and the gate
was failing on complexity in a vendored third-party file.
The shadcn MCP server is registered in the root .mcp.json. `shadcn-vue mcp init`
writes it to the directory it runs in, which for a nested ui/ is a path Claude
Code never reads.
This commit is contained in:
1 parent
da0116f0ba
commit
d933d36449
166 files changed
+6768
-16833
No files matched your search
@@ -1,197 +0,0 @@
|
||||
// Single place that knows how to talk to archied. Every feature folder goes
|
||||
// through api.* below, and every api.* method goes through send(), so the CSRF
|
||||
// header, the Content-Type, the request timeout, and the error shape live in
|
||||
// this one file. ui/test/api-client.test.js asserts that: it fails if a second
|
||||
// fetch() call appears here, and it fails if any method omits a header the
|
||||
// server requires.
|
||||
import { randomUUID } from "./uuid.jsx";
|
||||
import { streamStateFor } from "./stream-state.js";
|
||||
|
||||
// DEFAULT_TIMEOUT_MS bounds a request so a daemon that accepts the connection
|
||||
// but never answers cannot leave the UI in a loading state with no way back.
|
||||
// The retry affordances rely on fetch settling, so bound it.
|
||||
const DEFAULT_TIMEOUT_MS = 15000;
|
||||
|
||||
// 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}` : "";
|
||||
}
|
||||
|
||||
// errorMessage prefers what the server actually said. archied answers these
|
||||
// with http.Error, i.e. a plain-text reason -- "task is not awaiting
|
||||
// approval", "max retries reached (3/3)", "Content-Type must be
|
||||
// application/json" -- and discarding it in favour of "409 Conflict" throws
|
||||
// away the only part an operator can act on.
|
||||
async function errorMessage(res) {
|
||||
try {
|
||||
const body = (await res.text()).trim();
|
||||
if (body) return body.split("\n")[0].slice(0, 200);
|
||||
} catch {
|
||||
// Body already consumed or unreadable; fall through to the status.
|
||||
}
|
||||
return `${res.status} ${res.statusText}`;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(message, status) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
// classifyActionError turns a failed operator action into a rendering
|
||||
// decision. archied's own handlers already return distinguishable status
|
||||
// codes for a refused mutation (400/403/409/415 -- bad input, missing CSRF,
|
||||
// cross-origin, conflicting state, a body that is not JSON) versus a broken
|
||||
// one (5xx, or no status at all when fetch itself failed -- network drop,
|
||||
// timeout); 401 additionally means the session -- archied's own token cookie,
|
||||
// or an upstream forward-auth proxy sitting in front of it -- has expired
|
||||
// rather than that the action was rejected or the daemon is unwell.
|
||||
export function classifyActionError(err) {
|
||||
const status = err instanceof ApiError ? err.status : undefined;
|
||||
const message = err?.message || "Action failed";
|
||||
if (status === 401) return { kind: "session-expired", message };
|
||||
if (status >= 400 && status < 500) return { kind: "refused", message };
|
||||
return { kind: "broken", message };
|
||||
}
|
||||
|
||||
// send is the only fetch() in the dashboard. It converts a non-ok response
|
||||
// into an ApiError carrying the server's own explanation and a usable status,
|
||||
// and hands the raw Response back so the streaming caller can read the body
|
||||
// itself.
|
||||
async function send(path, init) {
|
||||
const res = await fetch(path, init);
|
||||
if (!res.ok) throw new ApiError(await errorMessage(res), res.status);
|
||||
return res;
|
||||
}
|
||||
|
||||
// request performs a JSON request. Every mutating method must declare a JSON
|
||||
// body: archied's handlers run authorizeTaskMutation first, and it answers 415
|
||||
// unless Content-Type is application/json -- including for a mutation that has
|
||||
// no body to send, because that requirement is what makes a simple cross-origin
|
||||
// form post inexpressible. Sending the header on every mutation, rather than
|
||||
// only where a payload happens to exist, is what keeps a bodyless DELETE or
|
||||
// approve from being refused.
|
||||
async function request(path, { method = "GET", body, timeoutMs = DEFAULT_TIMEOUT_MS, parse = true } = {}) {
|
||||
const headers = { Accept: "application/json" };
|
||||
const init = { method, headers, signal: AbortSignal.timeout(timeoutMs) };
|
||||
if (method !== "GET") {
|
||||
headers["Content-Type"] = "application/json";
|
||||
headers["X-Archie-CSRF"] = "1";
|
||||
}
|
||||
if (body !== undefined) init.body = JSON.stringify(body);
|
||||
|
||||
const res = await send(path, init);
|
||||
return parse ? res.json() : undefined;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
summary: () => request("/api/summary"),
|
||||
tasks: () => request("/api/tasks"),
|
||||
taskMeta: () => request("/api/task-meta"),
|
||||
task: (id) => request(`/api/tasks/${id}`),
|
||||
taskAttempts: (id) => request(`/api/tasks/${id}/attempts`),
|
||||
taskChanges: (id, params) => request(`/api/tasks/${id}/changes` + qs(params)),
|
||||
taskDebug: (id, params) => request(`/api/tasks/${id}/debug` + qs(params)),
|
||||
taskAction: (id, action) => request(`/api/tasks/${id}/action`, { method: "POST", body: { action } }),
|
||||
setup: () => request("/api/setup"),
|
||||
capabilities: () => request("/api/capabilities"),
|
||||
workflows: () => request("/api/workflows"),
|
||||
workRequest: (workRequest) => request("/api/work-requests", { method: "POST", body: workRequest }),
|
||||
skills: () => request("/api/skills"),
|
||||
channels: () => request("/api/channels"),
|
||||
curators: () => request("/api/curators"),
|
||||
channelReload: (id) => request(`/api/channels/${encodeURIComponent(id)}/reload`, { method: "POST", body: {} }),
|
||||
config: () => request("/api/config"),
|
||||
version: () => request("/api/version"),
|
||||
configUpdate: (updates) => request("/api/config", { method: "PATCH", body: { updates } }),
|
||||
configRepoUpdate: (owner, name, field, value) =>
|
||||
request(`/api/config/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`, { method: "PATCH", body: { field, value } }),
|
||||
configReset: (key) => request("/api/config/reset", { method: "POST", body: { key } }),
|
||||
logs: (params) => request("/api/logs" + qs(params)),
|
||||
taskLogs: (id, params) => request(`/api/tasks/${id}/logs` + qs(params)),
|
||||
// A download is a navigation, not a fetch: the browser must own the
|
||||
// Content-Disposition filename and stream the body to disk rather than hold
|
||||
// a whole log in memory. The URL builder is the client-side contract, and
|
||||
// base/log-row's sibling module keeps it beside the panel that uses it.
|
||||
taskLogDownloadURL: (id, attempt) => `/api/tasks/${id}/logs/download` + (attempt == null ? "" : `?attempt=${attempt}`),
|
||||
captures: (limit) => request("/api/captures" + qs({ limit })),
|
||||
mappings: () => request("/api/mappings"),
|
||||
mappingCreate: (mapping) => request("/api/mappings", { method: "POST", body: mapping }),
|
||||
mappingUpdate: (id, mapping) => request(`/api/mappings/${id}`, { method: "PATCH", body: mapping }),
|
||||
// A delete answers 204, so there is no body to parse.
|
||||
mappingDelete: (id) => request(`/api/mappings/${id}`, { method: "DELETE", parse: false }),
|
||||
mappingPreview: (captureId, fields) => request("/api/mappings/preview", { method: "POST", body: { capture_id: captureId, fields } }),
|
||||
bindings: () => request("/api/bindings"),
|
||||
bindingCreate: (binding) => request("/api/bindings", { method: "POST", body: binding }),
|
||||
bindingUpdate: (id, binding) => request(`/api/bindings/${id}`, { method: "PATCH", body: binding }),
|
||||
bindingDelete: (id) => request(`/api/bindings/${id}`, { method: "DELETE", parse: false }),
|
||||
bindingApprove: (id) => request(`/api/bindings/${id}/approve`, { method: "POST" }),
|
||||
chatSessions: () => request("/api/chat/sessions"),
|
||||
chatMessages: (id) => request(`/api/chat/sessions/${encodeURIComponent(id)}/messages`),
|
||||
chatTurns: (id) => request(`/api/chat/sessions/${encodeURIComponent(id)}/turns`),
|
||||
chatCancel: (sessionID) => request("/api/chat/cancel", { method: "POST", body: { session_id: sessionID } }),
|
||||
chatMessage: (channelID, text) =>
|
||||
request("/api/chat/message", {
|
||||
method: "POST",
|
||||
body: { channel_id: channelID, source_id: randomUUID(), text, page: location.hash.slice(1) || "/" },
|
||||
}),
|
||||
chatPersona: (sessionID, name) => request("/api/chat/persona", { method: "POST", body: { session_id: sessionID, name } }),
|
||||
chatUpdate: () => request("/api/chat/update"),
|
||||
chatUpdateDefer: (snapshot) => request("/api/chat/update/defer", { method: "POST", body: { snapshot } }),
|
||||
// Installing restarts archied, so it is allowed far longer than a normal
|
||||
// request before the UI gives up.
|
||||
chatUpdateInstall: (snapshot) => request("/api/chat/update/install", { method: "POST", body: { snapshot }, timeoutMs: 120000 }),
|
||||
chatDangerous: () => request("/api/chat/dangerous"),
|
||||
chatDangerousRequest: (kind, spec) =>
|
||||
request(`/api/chat/dangerous/${encodeURIComponent(kind)}`, { method: "POST", body: { spec } }),
|
||||
chatDangerousDecision: (id, decision) =>
|
||||
request(`/api/chat/dangerous/${encodeURIComponent(id)}/decision`, { method: "POST", body: { decision } }),
|
||||
// A server-sent event stream cannot be parsed as JSON and outlives a normal
|
||||
// request, so the caller owns the abort controller and the timeout, and
|
||||
// reads the body itself. Only the URL, headers, and failure shape are shared.
|
||||
chatStream: (payload, { signal } = {}) =>
|
||||
send("/api/chat/stream", {
|
||||
method: "POST",
|
||||
headers: { Accept: "text/event-stream", "Content-Type": "application/json", "X-Archie-CSRF": "1" },
|
||||
body: JSON.stringify(payload),
|
||||
signal,
|
||||
}),
|
||||
};
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
export function subscribeLogs(onEntry, onStateChange) {
|
||||
const src = new EventSource("/api/logs/stream");
|
||||
src.onopen = () => onStateChange?.("live");
|
||||
// onerror fires both for a drop the browser will retry and for one it has
|
||||
// given up on; readyState is what tells them apart.
|
||||
src.onerror = () => onStateChange?.(streamStateFor(src.readyState));
|
||||
src.onmessage = (event) => {
|
||||
try { onEntry(JSON.parse(event.data)); } catch { /* malformed log frame */ }
|
||||
};
|
||||
return () => src.close();
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Display formatting shared across the dashboard pages. Pure functions: no
|
||||
* DOM, no framework.
|
||||
*/
|
||||
|
||||
/** 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);
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
import { h } from "preact";
|
||||
|
||||
/**
|
||||
* 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(" ");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="gauge-wrap">
|
||||
<svg className="gauge" viewBox={`0 0 ${size} ${size * 0.78}`} role="img" aria-label={`${label}: ${pct}%`}>
|
||||
<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)}
|
||||
className="gauge-value"
|
||||
/>
|
||||
</svg>
|
||||
<div className="gauge-center">
|
||||
<div className="gauge-pct">{`${Math.round(pct)}%`}</div>
|
||||
<div className="gauge-label">{label}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
<div>
|
||||
<div className="segbar">
|
||||
{segments
|
||||
.filter((s) => s.value > 0)
|
||||
.map((s) => (
|
||||
<span
|
||||
key={s.label}
|
||||
className={`segbar-part segbar-${s.kind || "idle"}`}
|
||||
style={`width:${((s.value / total) * 100).toFixed(1)}%`}
|
||||
title={`${s.label}: ${s.value}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="segbar-legend">
|
||||
{segments.map((s) => (
|
||||
<span className="segbar-key" key={s.label}>
|
||||
<span className={`segbar-dot segbar-${s.kind || "idle"}`} />
|
||||
{s.label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { h } from "preact";
|
||||
|
||||
/**
|
||||
* 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"/>',
|
||||
chat: '<path d="M4 5.5A2.5 2.5 0 0 1 6.5 3h11A2.5 2.5 0 0 1 20 5.5v7a2.5 2.5 0 0 1-2.5 2.5H11l-4.5 4v-4.1A2.5 2.5 0 0 1 4 12.5z"/><path d="M8 8h8M8 11h5"/>',
|
||||
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"/>',
|
||||
curators: '<circle cx="12" cy="12" r="8"/><path d="M12 8v4l3 2"/>',
|
||||
captures: '<path d="M12 3v11M12 14l-4-4M12 14l4-4"/><path d="M4 14v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4"/>',
|
||||
mappings: '<circle cx="5" cy="7" r="2"/><circle cx="5" cy="17" r="2"/><circle cx="19" cy="12" r="2"/><path d="M7 7l10 5M7 17l10-5"/>',
|
||||
bindings: '<rect x="3" y="9" width="8" height="6" rx="2.5"/><rect x="13" y="9" width="8" height="6" rx="2.5"/><path d="M9 12h6"/>',
|
||||
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"/>',
|
||||
close: '<path d="M6 6l12 12M18 6L6 18"/>',
|
||||
"message-circle-plus": '<path d="M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719"/><path d="M8 12h8"/><path d="M12 8v8"/>',
|
||||
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 draws one glyph from the set. size is the rendered box; the grid is
|
||||
* always 24 so stroke weight stays optically consistent at any size.
|
||||
*
|
||||
* The glyph bodies are the `paths` strings above, injected as raw SVG. They are
|
||||
* in-repo constants and Preact cannot turn markup into elements, so re-authoring
|
||||
* twenty multi-element glyphs as JSX would trade a data table for code without
|
||||
* changing a single drawn pixel.
|
||||
*/
|
||||
export function Icon({ name, size = 18, className = "" }) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
width={size}
|
||||
height={size}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
aria-hidden="true"
|
||||
className={`ico ${className}`.trim()}
|
||||
dangerouslySetInnerHTML={{ __html: paths[name] || paths.dashboard }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
import { h } from "preact";
|
||||
|
||||
/**
|
||||
* Shared log-entry rendering. Both the daemon-wide log page
|
||||
* (ui/src/logs/logs.jsx) and a task's own attempt log
|
||||
* (ui/src/tasks/task-logs.jsx) render the same Entry shape from
|
||||
* internal/logging, so the row markup lives here rather than being
|
||||
* duplicated a second time -- see CLAUDE.md's "extract to base on the
|
||||
* second distinct consumer".
|
||||
*/
|
||||
|
||||
// The level filter vocabulary. Server-side level filtering takes a CSV of
|
||||
// levels (`splitCSV` in internal/webui/api_tasks_logs.go), so the combined
|
||||
// options are a wire concern too, not a display choice. It lives here because
|
||||
// both the daemon log page and a task attempt's log pane filter by level.
|
||||
export const LOG_LEVELS = [
|
||||
{ value: "", label: "All levels" },
|
||||
{ value: "ERROR", label: "Errors" },
|
||||
{ value: "WARN,ERROR", label: "Warnings and errors" },
|
||||
{ value: "INFO,WARN,ERROR", label: "Info and above" },
|
||||
{ value: "DEBUG", label: "Debug only" },
|
||||
];
|
||||
|
||||
export function levelKind(level) {
|
||||
switch ((level || "").toUpperCase()) {
|
||||
case "ERROR":
|
||||
return "danger";
|
||||
case "WARN":
|
||||
return "warn";
|
||||
case "DEBUG":
|
||||
return "idle";
|
||||
default:
|
||||
return "info";
|
||||
}
|
||||
}
|
||||
|
||||
export function LogRow({ entry }) {
|
||||
const fields = entry.fields || {};
|
||||
return (
|
||||
<div className={`log-row log-${levelKind(entry.level)}`}>
|
||||
<span className="log-time mono">{shortTime(entry.time)}</span>
|
||||
<span className="log-level">{(entry.level || "info").toUpperCase()}</span>
|
||||
<span className="log-body">
|
||||
<span className="log-msg">{entry.message || entry.msg || ""}</span>
|
||||
{Object.entries(fields).map(([k, v]) => (
|
||||
<span className="log-field" key={k}>
|
||||
<span className="log-field-key">{k}</span>
|
||||
{String(fmtValue(v))}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function fmtValue(v) {
|
||||
if (v == null) return "";
|
||||
return typeof v === "object" ? JSON.stringify(v) : v;
|
||||
}
|
||||
|
||||
export function shortTime(value) {
|
||||
const d = value instanceof Date ? value : new Date(value);
|
||||
if (Number.isNaN(d.getTime())) return "--:--:--";
|
||||
return d.toTimeString().slice(0, 8);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { h } from "preact";
|
||||
|
||||
/**
|
||||
* Status pill: a small labeled badge whose color follows a semantic kind
|
||||
* (ok/warn/danger/info/idle -- see css/pill.css). Extracted from 11
|
||||
* independent, byte-identical local copies (tasks, logs, mappings,
|
||||
* captures, settings, update-status, skills, dashboard, memory, channels,
|
||||
* curators) per organisation.md's "extract on the second distinct
|
||||
* consumer" rule -- archie-core-mlro.
|
||||
*/
|
||||
export function Pill({ text, kind = "idle" }) {
|
||||
return <span className={`pill pill-${kind}`}>{text}</span>;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
import { h } from "preact";
|
||||
import { Icon } from "./icons.jsx";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* The headline value is rendered whatever its type, including 0 and "": a tile
|
||||
* that showed a label and a comparison line with no number above them read as
|
||||
* a broken dashboard on every fresh install.
|
||||
*/
|
||||
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 (
|
||||
<div className="card stat">
|
||||
<div className="stat-head">
|
||||
<span className="stat-label">{label}</span>
|
||||
{dir ? (
|
||||
<span className={`stat-trend ${good ? "up" : "down"}`}>
|
||||
<Icon name={dir === "up" ? "trendUp" : "trendDown"} size={13} />
|
||||
{`${Math.abs(trend).toFixed(1)}%`}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="stat-value">
|
||||
{value}
|
||||
{unit ? <span className="stat-unit">{unit}</span> : null}
|
||||
</div>
|
||||
{compare ? <div className="stat-compare">{compare}</div> : null}
|
||||
{series.length > 1 ? <Sparkline series={series} stroke={good === false ? "var(--danger)" : "var(--ok)"} /> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(" ");
|
||||
|
||||
return (
|
||||
<svg className="spark" viewBox={`0 0 ${width} ${height}`} preserveAspectRatio="none" aria-hidden="true">
|
||||
<polyline
|
||||
points={points}
|
||||
fill="none"
|
||||
stroke={stroke}
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
vector-effect="non-scaling-stroke"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// What an EventSource error actually means.
|
||||
//
|
||||
// In base/ rather than logs/ because this is EventSource semantics, not a
|
||||
// logs concept, and base must not import a feature folder.
|
||||
//
|
||||
// EventSource fires onerror both for a dropped connection it will retry and
|
||||
// for one it has given up on. Reporting "reconnecting" for both left the logs
|
||||
// page showing a permanent amber "reconnecting" pill against a stream that had
|
||||
// stopped for good, next to text claiming live logs were still arriving
|
||||
// (archie-core-c5bz).
|
||||
//
|
||||
// readyState is the difference: CONNECTING means a retry is scheduled, CLOSED
|
||||
// means the browser will not try again.
|
||||
|
||||
/**
|
||||
* streamStateFor maps an EventSource readyState to the state the UI reports:
|
||||
* "live", "reconnecting", or "unavailable".
|
||||
*/
|
||||
export function streamStateFor(readyState) {
|
||||
// Numeric literals rather than EventSource.* so this is testable without one.
|
||||
if (readyState === 0) return "reconnecting";
|
||||
if (readyState === 1) return "live";
|
||||
return "unavailable";
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
// Central lifecycle vocabulary for the dashboard. The backend is the source of
|
||||
// truth: /api/task-meta returns the statuses (label, pill severity, "needs you"
|
||||
// grouping) and operator actions (label, button variant, confirm prompt). This
|
||||
// module fetches that catalog and exposes the accessors the rest of the UI
|
||||
// reads, so no surface keeps a hand-synced copy of the vocabulary.
|
||||
//
|
||||
// The defaults below are a freeze-dried snapshot that render immediately and
|
||||
// keep working when archied is unreachable; loadTaskMeta() replaces them with
|
||||
// the live catalog as soon as it arrives. They must match the backend catalog
|
||||
// so drawing the page never flashes a stale label.
|
||||
//
|
||||
// loadTaskMeta() is called once at boot by main.jsx, and that call is the whole
|
||||
// mechanism: without it these accessors serve the snapshot forever and a
|
||||
// catalogue change on the server never reaches the browser, however true the
|
||||
// paragraph above reads.
|
||||
//
|
||||
// The dashboard draws a line here between two kinds of vocabulary. Anything
|
||||
// that is *presentation* -- a status's label, pill severity and "needs you"
|
||||
// grouping, or a control's label and confirm prompt -- is served, because the
|
||||
// server owns the words as well as the ids. A wire id the daemon produces and
|
||||
// the dashboard merely labels is mirrored instead, with a literal pin on each
|
||||
// side so a one-sided rename fails a test rather than drifting quietly: see
|
||||
// tasks/changed-files.jsx (FILE_STATUS) and tasks/attempt-config.jsx
|
||||
// (CONFIG_SCHEMA).
|
||||
import { api } from "./api.jsx";
|
||||
|
||||
const DEFAULT_STATUSES = [
|
||||
{ id: "queued", label: "Queued", kind: "idle" },
|
||||
{ id: "running", label: "Working", kind: "info" },
|
||||
{ id: "waiting_human", label: "Waiting for you", kind: "warn", needs_you: true },
|
||||
{ id: "pr_open", label: "In review", kind: "ok" },
|
||||
{ id: "merged", label: "Merged", kind: "ok" },
|
||||
{ id: "parked", label: "Parked", kind: "warn", needs_you: true },
|
||||
{ id: "dead", label: "Stopped (too many retries)", kind: "danger" },
|
||||
{ id: "rejected", label: "Rejected", kind: "danger" },
|
||||
{ id: "closed_wont_do", label: "Won't do", kind: "idle" },
|
||||
];
|
||||
|
||||
const DEFAULT_ACTIONS = [
|
||||
{ id: "cancel", label: "Cancel", kind: "quiet", confirm: `Cancel "{title}"? This closes the forge issue.` },
|
||||
{ id: "stop", label: "Stop", kind: "primary", confirm: `Stop "{title}"? Recoverable work will remain parked.` },
|
||||
{ id: "approve", label: "Approve", kind: "primary" },
|
||||
{ id: "reject", label: "Reject", kind: "quiet", confirm: `Reject "{title}"? This closes the forge issue.` },
|
||||
{ id: "retry", label: "Retry", kind: "primary" },
|
||||
{ id: "abandon", label: "Abandon", kind: "quiet", confirm: `Abandon "{title}"? This closes the forge issue.` },
|
||||
{ id: "archive", label: "Archive", kind: "quiet", confirm: `Archive the local record for "{title}"?` },
|
||||
{ id: "open_pr", label: "Open PR", kind: "link" },
|
||||
{ id: "open_issue", label: "Open issue", kind: "link" },
|
||||
];
|
||||
|
||||
let statuses = [...DEFAULT_STATUSES];
|
||||
let actions = [...DEFAULT_ACTIONS];
|
||||
let statusById = new Map(statuses.map((s) => [s.id, s]));
|
||||
let actionById = new Map(actions.map((a) => [a.id, a]));
|
||||
|
||||
function rebuildIndexes() {
|
||||
statusById = new Map(statuses.map((s) => [s.id, s]));
|
||||
actionById = new Map(actions.map((a) => [a.id, a]));
|
||||
}
|
||||
|
||||
// loadTaskMeta upgrades the dashboard from the server catalog. It never throws:
|
||||
// a failed fetch keeps the defaults so the UI still renders.
|
||||
export async function loadTaskMeta() {
|
||||
try {
|
||||
const data = await api.taskMeta();
|
||||
if (Array.isArray(data?.statuses)) statuses = data.statuses;
|
||||
if (Array.isArray(data?.actions)) actions = data.actions;
|
||||
rebuildIndexes();
|
||||
} catch {
|
||||
// archied unreachable or not yet serving this route; keep the defaults.
|
||||
}
|
||||
}
|
||||
|
||||
// statusLabel is the human-readable name for a lifecycle status.
|
||||
export function statusLabel(id) {
|
||||
return statusById.get(id)?.label || id || "Unknown";
|
||||
}
|
||||
|
||||
// statusKind is the pill severity token (idle, info, ok, warn, danger).
|
||||
export function statusKind(id) {
|
||||
return statusById.get(id)?.kind || "idle";
|
||||
}
|
||||
|
||||
// statusList returns every known lifecycle status in display order.
|
||||
export function statusList() {
|
||||
return statuses;
|
||||
}
|
||||
|
||||
// statusIds returns every known lifecycle status id, in display order.
|
||||
export function statusIds() {
|
||||
return statuses.map((s) => s.id);
|
||||
}
|
||||
|
||||
// attentionStatusIds is the set of statuses that count toward the "Needs you"
|
||||
// filter (work that is waiting on a human).
|
||||
export function attentionStatusIds() {
|
||||
return new Set(statuses.filter((s) => s.needs_you).map((s) => s.id));
|
||||
}
|
||||
|
||||
// actionFor returns the presentation metadata for an operator control, or null
|
||||
// if the backend has never seen it.
|
||||
export function actionFor(id) {
|
||||
return actionById.get(id) || null;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// randomUUID keeps client-generated identifiers working on HTTP deployments.
|
||||
// crypto.randomUUID is restricted to secure contexts, while getRandomValues
|
||||
// remains available on the older browsers and plain-HTTP origins Archie
|
||||
// supports.
|
||||
export function randomUUID(cryptoAPI = globalThis.crypto) {
|
||||
if (typeof cryptoAPI?.randomUUID === "function") return cryptoAPI.randomUUID();
|
||||
|
||||
const bytes = new Uint8Array(16);
|
||||
if (typeof cryptoAPI?.getRandomValues === "function") {
|
||||
cryptoAPI.getRandomValues(bytes);
|
||||
} else {
|
||||
for (let index = 0; index < bytes.length; index += 1) {
|
||||
bytes[index] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
}
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
||||
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
|
||||
}
|
||||
Reference in new issue
Block a user