From 09d85149eed105a31273bdbe01145304b718384b Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 3 Sep 2026 00:16:48 +1000 Subject: [PATCH] Refactor workflows and skills modules to use Preact components --- ui/src/skills/skills.jsx | 176 ++++++------ ui/src/workflows/workflows.jsx | 488 ++++++++++++++++++--------------- 2 files changed, 350 insertions(+), 314 deletions(-) diff --git a/ui/src/skills/skills.jsx b/ui/src/skills/skills.jsx index 918d79b01..087bbeec6 100644 --- a/ui/src/skills/skills.jsx +++ b/ui/src/skills/skills.jsx @@ -1,113 +1,101 @@ +import { h, Fragment } from "preact"; +import { useState, useEffect, useMemo } from "preact/hooks"; import "./skills.css"; import { api } from "../base/api.jsx"; -import { el, empty, mount } from "../base/dom.jsx"; -/** - * What Archie can actually do, beyond what is in the source. Backed by - * GET /api/skills, which scans project, shared, and user-global - * .agents/skills//SKILL.md files and returns each skill's name, - * plain-language description, and where it was found. - * - * This page exists for someone who has never read the source: a search box - * over a card grid, and an empty state that explains what a skill is and - * how to add one rather than a blank box. - */ -export function skillsPage() { - const root = el("div"); - const cardGrid = el("div.grid.grid-2"); - const searchInput = el("input.skill-search", { - type: "search", - placeholder: "Search skills…", - oninput: (e) => { - search = e.target.value.trim().toLowerCase(); - renderCards(); - }, - }); +function Empty({ title, detail }) { + return ( +
+
{title}
+ {detail &&
{detail}
} +
+ ); +} - let skills = []; - let search = ""; - let loadError = null; +function Pill({ text, kind = "idle" }) { + return {text}; +} - render(); - load(); +export function skillsPage(query) { + return ; +} - function render() { - mount( - root, - el( - "div.page-head", - el( - "div", - el("h1.page-title", "Skills"), - el("p.page-sub", "What Archie can do, in plain language."), - ), - el("div.page-actions", el("button.btn", { onclick: load }, "Refresh")), - ), - el( - "div.card", - el( - "div.card-head", - el("div", el("h2.card-title", "Catalogue"), el("p.card-sub", "Project, shared, and user-global skills")), - searchInput, - ), - cardGrid, - ), - ); - renderCards(); - } +function SkillsApp() { + const [skills, setSkills] = useState([]); + const [search, setSearch] = useState(""); + const [loadError, setLoadError] = useState(null); - async function load() { + const load = async () => { try { const res = await api.skills(); - skills = res?.skills || []; - loadError = null; + setSkills(res?.skills || []); + setLoadError(null); } catch (err) { - skills = []; - loadError = String(err.message || err); + setSkills([]); + setLoadError(String(err.message || err)); } - renderCards(); - } + }; - function renderCards() { - if (loadError) { - return mount(cardGrid, empty("Cannot reach archied", loadError)); - } - if (!skills.length) { - return mount( - cardGrid, - empty( - "No skills discovered yet", - "Skills live as SKILL.md files under project, shared, or user-global .agents/skills// directories. Add one and refresh to make it available.", - ), - ); - } + useEffect(() => { + load(); + }, []); - const filtered = skills.filter((s) => matches(s, search)); - if (!filtered.length) { - return mount(cardGrid, empty("No skills match", `Nothing found for "${search}".`)); - } - - mount(cardGrid, ...filtered.map(skillCard)); - } - - function matches(skill, term) { + const matches = (skill, term) => { if (!term) return true; const haystack = `${skill.name} ${skill.description}`.toLowerCase(); return haystack.includes(term); - } + }; - function skillCard(skill) { - return el( - "div.card.skill-card", - el( - "div.card-head", - el("h3.card-title", skill.name || "Untitled skill"), - skill.workflow && el("span.pill.pill-info", skill.workflow), - ), - el("p.skill-desc", skill.description || "No description provided."), - el("div.skill-source", skill.source || "Unknown source"), - ); - } + const filteredSkills = useMemo(() => skills.filter((s) => matches(s, search)), [skills, search]); - return root; + return ( +
+
+
+

Skills

+

What Archie can do, in plain language.

+
+
+ +
+
+
+
+
+

Catalogue

+

Project, shared, and user-global skills

+
+ setSearch(e.target.value.trim().toLowerCase())} + /> +
+
+ {loadError ? ( + + ) : !skills.length ? ( + + ) : !filteredSkills.length ? ( + + ) : ( + filteredSkills.map((skill) => ( +
+
+

{skill.name || "Untitled skill"}

+ {skill.workflow && } +
+

{skill.description || "No description provided."}

+
{skill.source || "Unknown source"}
+
+ )) + )} +
+
+
+ ); } diff --git a/ui/src/workflows/workflows.jsx b/ui/src/workflows/workflows.jsx index f0a23be64..de907ad88 100644 --- a/ui/src/workflows/workflows.jsx +++ b/ui/src/workflows/workflows.jsx @@ -1,12 +1,8 @@ +import { h, Fragment } from "preact"; +import { useState, useEffect } from "preact/hooks"; import "./workflows.css"; import { api } from "../base/api.jsx"; -import { el, empty, mount } from "../base/dom.jsx"; -/** - * Plain-language workflow names. Falls back to a title-cased version of the - * raw identifier for anything not listed here, so a new workflow never - * renders blank. - */ const WORKFLOW_LABELS = { bootstrap: "Bootstrap", implement: "Implement", @@ -25,13 +21,6 @@ function pct(part, whole) { return Math.round((part / whole) * 100); } -function bar(fraction, kind = "ok") { - return el( - "div.wf-bar", - el(`div.wf-bar-fill.wf-bar-${kind}`, { style: `width:${Math.min(100, Math.max(0, fraction))}%` }), - ); -} - function formatMs(ms) { if (!ms) return "—"; if (ms < 1000) return `${ms} ms`; @@ -40,229 +29,288 @@ function formatMs(ms) { return `${(secs / 60).toFixed(1)} min`; } -/** - * How work actually flows: per-workflow outcomes and spend, then per-stage - * duration and failure counts -- the "where does it get stuck" view. Both - * come from a single /api/workflows call built on the same store queries - * that back the dashboard's summary stats. - */ -export function workflowsPage() { - const root = el("div"); - const workflowSlot = el("div"); - const stageSlot = el("div"); - const startSlot = el("div"); +function Empty({ title, detail }) { + return ( +
+
{title}
+ {detail &&
{detail}
} +
+ ); +} - render(); - load(); +function Bar({ fraction, kind = "ok" }) { + const boundedFraction = Math.min(100, Math.max(0, fraction)); + return ( +
+
+
+ ); +} - function render() { - mount( - root, - el( - "div.page-head", - el( - "div", - el("h1.page-title", "Workflows"), - el("p.page-sub", "Run outcomes and spend per workflow, and where stages get stuck."), - ), - el("div.page-actions", el("button.btn", { onclick: load }, "Refresh")), - ), - startSlot, - workflowSlot, - stageSlot, - ); - } +export function workflowsPage(query) { + return ; +} - async function load() { +function WorkflowsApp() { + const [definitions, setDefinitions] = useState([]); + const [workflows, setWorkflows] = useState([]); + const [stages, setStages] = useState([]); + const [error, setError] = useState(null); + + const load = async () => { try { const data = await api.workflows(); - renderStartWork(data?.definitions || []); - renderWorkflows(data?.workflows || [], data?.definitions || []); - renderStages(data?.stages || []); + setDefinitions(data?.definitions || []); + setWorkflows(data?.workflows || []); + setStages(data?.stages || []); + setError(null); } catch (err) { - mount(workflowSlot, el("div.card", empty("Cannot reach archied", String(err.message || err)))); - mount(stageSlot); + setError(String(err.message || err)); } - } + }; - function renderStartWork(definitions) { - if (!definitions.length) { - mount(startSlot); - return; - } - const identity = el("input", { placeholder: "Identity", required: true }); - const repository = el("input", { placeholder: "owner/repository", required: true }); - const workflow = el("select", { required: true }, ...definitions.filter((d) => d.enabled).map((d) => el("option", { value: d.id }, workflowLabel(d.name || d.id)))); - const title = el("input", { placeholder: "Short task title", required: true }); - const instructions = el("textarea", { placeholder: "Instructions for the work", required: true, rows: 3 }); - const notice = el("p.card-sub"); - const submit = el("button.btn", { type: "submit" }, "Start work"); - const form = el("form.wf-form", { - onsubmit: async (event) => { - event.preventDefault(); - submit.disabled = true; - try { - const result = await api.workRequest({ identity: identity.value, repository: repository.value, workflow: workflow.value, title: title.value, instructions: instructions.value }); - notice.textContent = `Queued task #${result.task_id}.`; - form.reset(); - } catch (err) { - notice.textContent = String(err.message || err); - } finally { - submit.disabled = false; - } - }, - }, identity, repository, workflow, title, instructions, submit, notice); - mount(startSlot, el("div.card", el("div.card-head", el("div", el("h2.card-title", "Start work"), el("p.card-sub", "This enters Archie’s normal admitted task queue."))), form)); - } + useEffect(() => { + load(); + }, []); - function renderWorkflows(workflows, definitions) { - const byID = new Map(workflows.map((workflow) => [workflow.workflow, workflow])); - const rows = definitions.map((definition) => ({ ...definition, ...(byID.get(definition.id) || { workflow: definition.id, runs: 0, merged: 0 }) })); - if (!rows.length) { - mount( - workflowSlot, - el( - "div.card", - el("div.card-head", el("div", el("h2.card-title", "Per workflow"))), - empty("No workflow runs yet", "Stats appear here once a task has run through a workflow."), - ), - ); - return; + return ( +
+
+
+

Workflows

+

Run outcomes and spend per workflow, and where stages get stuck.

+
+
+ +
+
+ + {error ? ( +
+ +
+ ) : ( + + + + + )} +
+ ); +} + +function StartWork({ definitions }) { + if (!definitions.length) return null; + + const defaultWorkflow = definitions.filter((d) => d.enabled)[0]?.id || ""; + const [identity, setIdentity] = useState(""); + const [repository, setRepository] = useState(""); + const [workflow, setWorkflow] = useState(defaultWorkflow); + const [title, setTitle] = useState(""); + const [instructions, setInstructions] = useState(""); + const [submitting, setSubmitting] = useState(false); + const [notice, setNotice] = useState(""); + + useEffect(() => { + if (!workflow && defaultWorkflow) { + setWorkflow(defaultWorkflow); + } + }, [defaultWorkflow, workflow]); + + const onSubmit = async (e) => { + e.preventDefault(); + setSubmitting(true); + setNotice(""); + try { + const result = await api.workRequest({ identity, repository, workflow, title, instructions }); + setNotice(`Queued task #${result.task_id}.`); + setIdentity(""); + setRepository(""); + setWorkflow(defaultWorkflow); + setTitle(""); + setInstructions(""); + } catch (err) { + setNotice(String(err.message || err)); + } finally { + setSubmitting(false); } + }; - mount( - workflowSlot, - el( - "div.card", - el( - "div.card-head", - el( - "div", - el("h2.card-title", "Per workflow"), - el("p.card-sub", "Success rate is merged tasks over all runs"), - ), - ), - el( - "div.table-scroll", - el( - "table.table", - el( - "thead", - el( - "tr", - ...["Workflow", "Origin", "Runs", "Success rate", "Avg tokens", "Avg steps"].map((h) => el("th", h)), - ), - ), - el( - "tbody", - ...rows.map((w) => { - const rate = pct(w.merged, w.runs); - return el( - "tr", - el("td.strong", workflowLabel(w.workflow)), - el("td.mono", w.origin || "registry"), - el("td", `${w.runs} run${w.runs === 1 ? "" : "s"}`), - el( - "td", - el("div.wf-rate", `${rate}%`, el("span.wf-rate-sub", `${w.merged} of ${w.runs} merged`)), - bar(rate, rate >= 50 ? "ok" : "warn"), - ), - el("td.mono", w.avg_tokens ? w.avg_tokens.toLocaleString() : "—"), - el("td.mono", w.avg_steps ? w.avg_steps.toFixed(1) : "—"), - ); - }), - ), - ), - ), - ), + return ( +
+
+
+

Start work

+

This enters Archie’s normal admitted task queue.

+
+
+
+ setIdentity(e.target.value)} /> + setRepository(e.target.value)} /> + + setTitle(e.target.value)} /> + + + {notice &&

{notice}

} +
+
+ ); +} + +function Workflows({ workflows, definitions }) { + const byID = new Map(workflows.map((workflow) => [workflow.workflow, workflow])); + const rows = definitions.map((definition) => ({ + ...definition, + ...(byID.get(definition.id) || { workflow: definition.id, runs: 0, merged: 0 }), + })); + + if (!rows.length) { + return ( +
+
+

Per workflow

+
+ +
); } - function renderStages(stages) { - if (!stages.length) { - mount( - stageSlot, - el( - "div.card.wf-stage-card", - el("div.card-head", el("div", el("h2.card-title", "Per stage"))), - empty("No stage data yet", "Stage timing and failures appear here once workflows have run."), - ), - ); - return; - } + return ( +
+
+
+

Per workflow

+

Success rate is merged tasks over all runs

+
+
+
+ + + + + + + + + + + + + {rows.map((w) => { + const rate = pct(w.merged, w.runs); + return ( + + + + + + + + + ); + })} + +
WorkflowOriginRunsSuccess rateAvg tokensAvg steps
{workflowLabel(w.workflow)}{w.origin || "registry"}{`${w.runs} run${w.runs === 1 ? "" : "s"}`} +
+ {rate}%{w.merged} of {w.runs} merged +
+ = 50 ? "ok" : "warn"} /> +
{w.avg_tokens ? w.avg_tokens.toLocaleString() : "—"}{w.avg_steps ? w.avg_steps.toFixed(1) : "—"}
+
+
+ ); +} - const maxMs = Math.max(...stages.map((s) => s.avg_ms || 0), 1); - const byDuration = [...stages].sort((a, b) => (b.avg_ms || 0) - (a.avg_ms || 0)); - const byErrors = [...stages].filter((s) => s.errors > 0).sort((a, b) => b.errors - a.errors); - - mount( - stageSlot, - el( - "div.grid.grid-2.wf-stage-card", - el( - "div.card", - el( - "div.card-head", - el("div", el("h2.card-title", "Slowest stages"), el("p.card-sub", "Average duration, this workflow's stages")), - ), - el( - "div.table-scroll", - el( - "table.table", - el("thead", el("tr", ...["Workflow", "Stage", "Runs", "Avg duration"].map((h) => el("th", h)))), - el( - "tbody", - ...byDuration.map((s) => - el( - "tr", - el("td", workflowLabel(s.workflow)), - el("td.strong", s.stage), - el("td", `${s.runs}`), - el( - "td", - el("div.wf-rate", formatMs(s.avg_ms)), - bar(pct(s.avg_ms, maxMs), "info"), - ), - ), - ), - ), - ), - ), - ), - el( - "div.card", - el( - "div.card-head", - el("div", el("h2.card-title", "Most failures"), el("p.card-sub", "Stages that error out, over their runs")), - ), - byErrors.length - ? el( - "div.table-scroll", - el( - "table.table", - el("thead", el("tr", ...["Workflow", "Stage", "Failures"].map((h) => el("th", h)))), - el( - "tbody", - ...byErrors.map((s) => - el( - "tr", - el("td", workflowLabel(s.workflow)), - el("td.strong", s.stage), - el( - "td", - el("div.wf-rate", `${s.errors} of ${s.runs}`), - bar(pct(s.errors, s.runs), "danger"), - ), - ), - ), - ), - ), - ) - : empty("No failures recorded", "Every stage has completed cleanly so far."), - ), - ), +function Stages({ stages }) { + if (!stages.length) { + return ( +
+
+

Per stage

+
+ +
); } + + const maxMs = Math.max(...stages.map((s) => s.avg_ms || 0), 1); + const byDuration = [...stages].sort((a, b) => (b.avg_ms || 0) - (a.avg_ms || 0)); + const byErrors = [...stages].filter((s) => s.errors > 0).sort((a, b) => b.errors - a.errors); - return root; + return ( +
+
+
+
+

Slowest stages

+

Average duration, this workflow's stages

+
+
+
+ + + + + + + + + + + {byDuration.map((s, idx) => ( + + + + + + + ))} + +
WorkflowStageRunsAvg duration
{workflowLabel(s.workflow)}{s.stage}{s.runs} +
{formatMs(s.avg_ms)}
+ +
+
+
+
+
+
+

Most failures

+

Stages that error out, over their runs

+
+
+ {byErrors.length ? ( +
+ + + + + + + + + + {byErrors.map((s, idx) => ( + + + + + + ))} + +
WorkflowStageFailures
{workflowLabel(s.workflow)}{s.stage} +
{s.errors} of {s.runs}
+ +
+
+ ) : ( + + )} +
+
+ ); }