Files
archie/ui/src/settings/settings.jsx
T
sam 7d7e900e47 fix(webui): stop the UI contradicting itself, and clear the AA failures
Four P1 findings from the audit.

Workflows claimed "No workflow runs yet" directly above stage tables listing
those runs (archie-core-rcbf). The rows were built from the definition list
alone, so a workflow with statistics but no definition produced no row at all.
workflow-rows.js now merges both sides: a run is evidence the workflow exists.
The producer is also at fault -- /api/workflows returns definitions: [] from
the archie-ui composition while the daemon logs a registry of seven -- which
also means "Start work" never renders there. Filed as archie-core-3tij.

The logs page said "Durable history unavailable" twice and promised live logs
from a stream that had stopped (archie-core-c5bz). EventSource fires onerror
both for a retry and for a give-up; readyState tells them apart, so a dead
stream now reports "unavailable" in red instead of "reconnecting" in amber
forever. The toolbar says "Live only" and the empty state carries the
explanation, each once. An unconfigured update check (501) now says so on
Configuration rather than rendering nothing at all.

Contrast (archie-core-umdn). --fg-subtle was 3.37:1 dark and 2.72:1 light,
used for every KPI caption and column header; both move to values clearing
4.5:1 on every surface they actually land on, down to surface-hover at 4.51.
White on the dark accent was 3.2:1 on the active nav item and every primary
button: --accent-fg becomes near-black at 5.96:1 and the accent itself is
untouched, since it is also the link colour and reads correctly on the canvas.
Swept four routes in both themes: no remaining failures outside elements
painted on a gradient, which a compositing check cannot judge and which are
white on blue-purple anyway.

The HEALTH cards take their own height again
(archie-core-1786637500926-421-7c63bcd3). Equalising them was right when both
held a checklist; once setup completes, that card is a title and one line
while Gate pulse carries a gauge and four rows, so matching heights left a
~400px empty box in the first screen.
2026-09-20 16:50:28 +10:00

493 lines
16 KiB
React

import { h } from "preact";
import { useState, useEffect } from "preact/hooks";
import "./settings.css";
import { api } from "../base/api.jsx";
import { statusKind, statusLabel } from "../base/task-meta.jsx";
import { Pill } from "../base/pill.jsx";
import { Row } from "./config-row.jsx";
import { UpdateStatusCard } from "./update-status.jsx";
import { UpdateActionsCard, DangerousActionsCard } from "./operator-cards.jsx";
function Empty({ title, detail }) {
return (
<div className="empty">
<div className="empty-title">{title}</div>
{detail && <div>{detail}</div>}
</div>
);
}
function Section({ title, sub, children }) {
return (
<div className="card cfg-section">
<div className="card-head">
<div>
<h2 className="card-title">{title}</h2>
<p className="card-sub">{sub}</p>
</div>
</div>
{children}
</div>
);
}
function ProvenanceCard({ origins }) {
if (!origins?.length) return (
<Section title="Configuration sources" sub="The files that supplied the running configuration.">
<Empty title="Source provenance is unavailable." />
</Section>
);
return (
<Section title="Configuration sources" sub="Applied from top to bottom; later entries take precedence over earlier ones.">
<div className="kv-list">
{origins.map((origin, i) => (
<Row key={i} label={`${origin.layer} ${origin.role}${origin.feature ? ` (${origin.feature})` : ""}`} value={origin.path} />
))}
</div>
</Section>
);
}
function roleButtonClass(kind) {
return kind === "quiet" ? "btn-quiet" : kind === "danger" ? "btn-danger" : "";
}
function LifecycleCard({ data, error }) {
if (error) {
return (
<Section title="Work lifecycle" sub="The task statuses and operator actions archied ships.">
<Empty title="Lifecycle unavailable" detail={error} />
</Section>
);
}
const statuses = data?.statuses || [];
const actions = data?.actions || [];
return (
<Section title="Work lifecycle" sub="The task statuses and operator actions archied ships. Add one on the backend and it appears here without a frontend change.">
<h3 className="cfg-subhead">Statuses</h3>
{statuses.length ? (
<div className="kv-list">
{statuses.map(s => {
const label = s.label ?? statusLabel(s.id);
const kind = s.kind ?? statusKind(s.id);
return (
<div className="kv" key={s.id}>
<span className="kv-label">{s.id}</span>
<span className="kv-value"><Pill text={label} kind={kind} /></span>
</div>
);
})}
</div>
) : (
<Empty title="No statuses reported" detail="The server did not return any lifecycle statuses." />
)}
<h3 className="cfg-subhead">Actions</h3>
{actions.length ? (
<div className="kv-list">
{actions.map(a => {
const label = a.label ?? a.id;
const cls = roleButtonClass(a.kind);
return (
<div className="kv" key={a.id}>
<span className="kv-label">{a.id}</span>
<span className="kv-value">
<button className={`btn btn-small ${cls}`} type="button" disabled>{label}</button>
</span>
</div>
);
})}
</div>
) : (
<Empty title="No actions reported" detail="The server did not return any operator actions." />
)}
</Section>
);
}
function RepoBoolCell({ r, field, onSaved, editable = true }) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const [checked, setChecked] = useState(!!r[field]);
const handleChange = async (e) => {
const next = e.target.checked;
setChecked(next);
setLoading(true);
setError(null);
try {
await api.configRepoUpdate(r.owner, r.name, field, next);
onSaved?.();
} catch (err) {
setChecked(!next);
setError(String(err.message || err));
} finally {
setLoading(false);
}
};
if (!editable) {
return <td>{checked ? "yes" : "no"}</td>;
}
return (
<td>
<input className="repo-field-checkbox" type="checkbox" checked={checked} onChange={handleChange} disabled={loading} />
{error && <span className="kv-note is-error">{error}</span>}
</td>
);
}
function RepoIntCell({ r, field, onSaved, editable = true }) {
const [val, setVal] = useState(String(r[field] ?? 0));
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const commit = async () => {
const n = parseInt(val, 10);
if (Number.isNaN(n)) {
setError("Enter a whole number");
return;
}
setLoading(true);
setError(null);
try {
await api.configRepoUpdate(r.owner, r.name, field, n);
onSaved?.();
} catch (err) {
setError(String(err.message || err));
} finally {
setLoading(false);
}
};
const handleKeyDown = (e) => {
if (e.key === "Enter") {
e.preventDefault();
e.target.blur();
}
};
if (!editable) {
return <td className="mono">{val}</td>;
}
return (
<td>
<input
className="kv-input"
type="text"
value={val}
onChange={e => setVal(e.target.value)}
onBlur={commit}
onKeyDown={handleKeyDown}
disabled={loading}
/>
{error && <span className="kv-note is-error">{error}</span>}
</td>
);
}
// editable is false in a process that only renders a published
// configuration snapshot: its PATCH routes answer 503, so the cells are
// values rather than controls (archie-core-ymut).
export function RepositoriesCard({ repos, onSaved, editable = true }) {
if (!repos?.length) {
return (
<Section title="Repositories" sub="The repositories Archie polls for work.">
<Empty title="No repositories configured" detail="Add a [[repos]] entry in config.toml so Archie has somewhere to work." />
</Section>
);
}
const gateSummary = (gate) => {
if (!gate?.length) return "—";
return gate.map((cmd) => cmd.join(" ")).join(" → ");
};
return (
<Section title="Repositories" sub="Each repository Archie polls, and the quality gate a change must pass before it opens a pull request. Concurrent tasks, retries, and self-review are per-repository overrides -- PATCH /api/config/repos/{owner}/{name}, not the file config.toml directly.">
<div className="table-scroll">
<table className="table">
<thead>
<tr>
<th>Repository</th><th>Base branch</th><th>Ecosystem</th><th>Quality gate</th><th>Protected paths</th><th>Concurrent</th><th>Max retries</th><th>Self-review</th>
</tr>
</thead>
<tbody>
{repos.map((r, i) => (
<tr key={i}>
<td className="strong">{r.owner}/{r.name}</td>
<td className="mono">{r.base}</td>
<td>{r.ecosystem || "go"}</td>
<td className="mono">{gateSummary(r.gate)}</td>
<td className="mono">{r.protect?.length ? r.protect.join(", ") : "—"}</td>
<RepoBoolCell r={r} field="allow_concurrent" onSaved={onSaved} editable={editable} />
<RepoIntCell r={r} field="max_retries" onSaved={onSaved} editable={editable} />
<RepoBoolCell r={r} field="review_enabled" onSaved={onSaved} editable={editable} />
</tr>
))}
</tbody>
</table>
</div>
</Section>
);
}
function roleLabel(role) {
if (!role) return "Unknown role";
return role.charAt(0).toUpperCase() + role.slice(1).replace(/_/g, " ");
}
function ModelsAndProvidersCard({ models, providers }) {
const modelEntries = Object.entries(models || {});
const providerEntries = Object.entries(providers || {});
return (
<Section title="Models & providers" sub="Which model handles each stage of work, and which LLM providers are wired up. Only the environment variable NAME is shown, never its value.">
<h3 className="cfg-subhead">Model roles</h3>
{modelEntries.length ? (
<div className="kv-list">
{modelEntries.map(([role, ref]) => (
<Row key={role} label={roleLabel(role)} value={ref} />
))}
</div>
) : (
<Empty title="No model roles configured" detail='Assign a model to at least one role (e.g. "builder") in [models].' />
)}
<h3 className="cfg-subhead">Providers</h3>
{providerEntries.length ? (
<div className="table-scroll">
<table className="table">
<thead>
<tr><th>Provider</th><th>Class</th><th>Base URL</th><th>API key env var</th><th>Status</th></tr>
</thead>
<tbody>
{providerEntries.map(([name, p]) => (
<tr key={name}>
<td className="strong">{name}</td>
<td>{p.class}</td>
<td className="mono">{p.base_url || "default"}</td>
<td className="mono">{p.api_key_env || "—"}</td>
<td>
{p.configured ? <Pill text="configured" kind="ok" /> : <Pill text="missing credentials" kind="warn" />}
</td>
</tr>
))}
</tbody>
</table>
</div>
) : (
<Empty title="No providers configured" detail="Add a [providers.<name>] entry so a model role above has something to run on." />
)}
</Section>
);
}
function SettingsApp() {
const [cfg, setCfg] = useState(null);
const [cfgError, setCfgError] = useState(null);
const [versionData, setVersionData] = useState(null);
const [versionError, setVersionError] = useState(null);
const [versionMissing, setVersionMissing] = useState(false);
const [lifecycleData, setLifecycleData] = useState(null);
const [lifecycleError, setLifecycleError] = useState(null);
// Update actions and dangerous-action approvals, rehomed from the chat panel
// (archie-core-tf20). Both degrade to absent rather than to an error banner:
// a deployment that does not wire them should show nothing, not a failure.
const [updateData, setUpdateData] = useState(null);
const [dangerousData, setDangerousData] = useState(null);
const loadAll = () => {
loadCfg();
loadVersion();
loadLifecycle();
loadUpdate();
loadDangerous();
};
const loadUpdate = async () => {
try {
setUpdateData(await api.chatUpdate());
} catch (err) {
setUpdateData(err?.status === 501 ? null : { error: String(err.message || err) });
}
};
const loadDangerous = async () => {
try {
setDangerousData(await api.chatDangerous());
} catch (err) {
setDangerousData(err?.status === 501 ? null : { error: String(err.message || err) });
}
};
const deferUpdate = async (snapshot) => {
await api.chatUpdateDefer(snapshot);
await loadUpdate();
};
const installUpdate = async (snapshot) => {
await api.chatUpdateInstall(snapshot);
await loadUpdate();
};
const requestDangerous = async (kind, spec) => {
await api.chatDangerousRequest(kind, spec);
await loadDangerous();
};
const decideDangerous = async (id, decision) => {
await api.chatDangerousDecision(id, decision);
await loadDangerous();
};
const loadCfg = async () => {
try {
const data = await api.config();
setCfg(data);
setCfgError(null);
} catch (err) {
setCfgError(String(err.message || err));
}
};
const loadVersion = async () => {
try {
const data = await api.version();
setVersionData(data?.components || []);
setVersionError(null);
setVersionMissing(false);
} catch (err) {
if (err?.status === 501) {
setVersionMissing(true);
} else {
setVersionError(String(err.message || err));
}
}
};
const loadLifecycle = async () => {
try {
const data = await api.taskMeta();
setLifecycleData(data);
setLifecycleError(null);
} catch (err) {
setLifecycleError(String(err.message || err));
}
};
useEffect(() => {
loadAll();
}, []);
return (
<div className="cfg-page">
<div className="page-head">
<div>
<h1 className="page-title">Configuration</h1>
<p className="page-sub">What archied is actually running with right now.</p>
</div>
<div className="page-actions">
<button className="btn" onClick={loadAll}>Refresh</button>
</div>
</div>
<div>
{/* A 501 is a deployment that did not wire update checking, which is a
legitimate state and a different thing from a broken one. Saying so
once here covers the absent UpdateActionsCard below too. */}
{versionMissing ? (
<div className="card cfg-section">
<div className="card-head">
<div>
<h2 className="card-title">Update status</h2>
<p className="card-sub">Not configured on this deployment, so there is nothing to check against.</p>
</div>
</div>
</div>
) : versionError ? (
<div className="card"><Empty title="Update status unavailable" detail={versionError} /></div>
) : versionData ? (
<UpdateStatusCard components={versionData} />
) : null}
</div>
{updateData && (
<div>
<UpdateActionsCard data={updateData} onDefer={deferUpdate} onInstall={installUpdate} />
</div>
)}
{dangerousData && (
<div>
<DangerousActionsCard data={dangerousData} onRequest={requestDangerous} onDecide={decideDangerous} />
</div>
)}
<div>
<LifecycleCard data={lifecycleData} error={lifecycleError} />
</div>
<div>
{cfgError ? (
<div className="card"><Empty title="Cannot reach archied" detail={cfgError} /></div>
) : !cfg || Object.keys(cfg).length === 0 ? (
<div className="card"><Empty title="No configuration loaded" detail="archied is running without a config file wired into the dashboard, so there is nothing to show." /></div>
) : (
<>
{cfg.reload?.overlay_unavailable && (
<div className="card cfg-notice"><p>The runtime config overlay is not in effect: {cfg.reload.overlay_unavailable}</p></div>
)}
{cfg.reload?.last_error && (
<div className="card cfg-notice"><p>The last config reload failed; the running config is unchanged: {cfg.reload.last_error}</p></div>
)}
{(cfg.schema || []).map((s, i) => {
const rows = s.fields.filter(f => f.type !== "structured");
if (!rows.length) return null;
return (
<Section title={s.label} sub={s.description} key={i}>
<div className="kv-list">
{rows.map(f => (
<Row
key={f.key}
label={f.label}
value={f.value}
opts={{
key: f.key,
type: f.type,
options: f.options,
raw: f.value,
hint: f.description,
editable: f.editable && cfg.editable !== false,
locked: cfg.locked || {},
overridden: cfg.overridden || [],
onSaved: loadCfg
}}
/>
))}
</div>
</Section>
);
})}
<RepositoriesCard repos={cfg.repositories} onSaved={loadCfg} editable={cfg.editable !== false} />
<ModelsAndProvidersCard models={cfg.models} providers={cfg.providers} />
<ProvenanceCard origins={cfg.provenance} />
</>
)}
</div>
</div>
);
}
export function settingsPage(query) {
return <SettingsApp query={query} />;
}