* fix(ui): make the served lifecycle vocabulary actually load
base/task-meta.jsx documents the backend as the source of truth: /api/task-meta
returns the statuses (label, pill severity, "needs you") and the operator
actions, and loadTaskMeta() replaces the freeze-dried defaults with that
catalog. Nothing called it. Every pill, status filter and action control read
the snapshot, so a catalogue change on the server never reached the browser --
the module's first paragraph was simply not true.
main.jsx now asks for the catalog once at boot, alongside the capabilities read
it already does for the same reason: the shell paints immediately and upgrades a
moment later.
The two vocabularies the dashboard mirrors rather than serves -- FILE_STATUS
(ids owned by internal/domain/workflow/task/changes.go) and CONFIG_SCHEMA
(events.ConfigCapturedSchema) -- are now documented as the deliberate second
tier, with their two-sided pins named, so the tree stops telling two stories
about where a vocabulary comes from. Both degrade to a raw id or the verbatim
payload rather than rendering something wrong, which is why mirroring is
tolerable there and not for a presentation catalog.
RED before (loader never called):
x booting the dashboard replaces the freeze-dried vocabulary with the served catalog
actual: 'custom_status', expected: 'Custom status'
Also repairs a drifted LAW asset. A fresh build of pristine main dirties both
ui/dist/assets/index.css and index.js: 04d4d8f1 (#889, memory unification slice
5) changed ui/src without rebuilding ui/dist, and task check runs task ui --
which repairs dist instead of verifying it -- so a stale dist is invisible to
the gate. Rebuilding here restores the invariant; a dist-freshness gate is filed
as follow-up.
* fix(ui,gateway): restore the search focus the port dropped, and the page registry truth
An adversarial review of the port (278b7fc6) found three things worth acting on.
1. Topbar search -- a regression the port introduced. The el() version focused
the input when the narrow-layout toggle opened it, and blurred it after a
successful jump; the port kept neither. That layout hides the field with
width:0/pointer-events:none until .is-open or :focus-within, so without
focus() the caret was not in the field the operator had just opened, and
without blur() :focus-within left it expanded across the topbar after the
jump. Both calls are back, with the ref they need.
2. dashboard_tools.go advertised a page that does not exist and omitted two that
do. The registry calls itself "the single source of truth for what the
dashboard exposes", but it is a hand-copy of the route table in
ui/src/main.jsx: /memory stayed after the page was deleted (that deletion
also left ui/dist stale -- archie-core-1vhh), and /bindings and /curators
were never added. So the agent could hand the operator a chip to a route that
now falls back to the dashboard, and could not answer "where do I go for
playbook bindings?".
3. TestDashboardPagesRegistryCoversEveryRoute did not test that. It asserted
three hardcoded paths and passed while the registry listed a deleted page. It
now reads the route table back out of ui/src/main.jsx and compares in both
directions, which is what makes the registry's claim holdable. RED before:
route "/bindings" is a dashboard page the registry does not list, so the agent cannot point at it
route "/curators" is a dashboard page the registry does not list, so the agent cannot point at it
registry lists "/memory" (Memory), which is not a dashboard route: the agent would send the operator somewhere that does not exist
Also deletes the dead .chat-page rules the deleted chatPage() bridge left
behind: nothing renders .chat-page any more (chat.jsx renders
.chat-page-content, and the drawer sizes it from layout.css).
Not changed: the unreachable `soon` path, which predates the port and was
reported rather than acted on.
* fix(build): verify ui/dist is fresh instead of never looking at it
ui/dist is committed because the Go build embeds it, so it is a generated
source file. Nothing in the gate read it: task check does not run task ui, and
nothing else compares the bundle with ui/src. So when 04d4d8f1 (#889) changed
ui/src without rebuilding, the committed bundle went on serving the Memory page
whose source had been deleted -- with the gate green throughout.
task ui:check (tools/uidist.sh) rebuilds into a temporary directory and compares,
never rewriting the committed artifact. That is the rule docs:check already
states for the contract reference -- a gate that silently rewrote the artifact
would bless an unintended change with no reviewer ever seeing it -- and it
matters more now that several agents work in their own worktrees, where each
could otherwise pass while producing a different bundle.
Evidence:
fresh tree exit 0, matches
hand-staled bundle exit 1, names the differing file
the #889 drift replayed exit 1, names BOTH index.css and index.js
(pre-#889 bundle, post-#889 sources)
git status after a run unchanged: the check never writes ui/dist
Cost: ui:check declares ui:deps like ui and test:ui do, so the gate runs npm
install once per dependent. Task's sources/generates up-to-date check does not
apply to a node_modules directory (measured: it ran on every invocation), so the
target does not claim otherwise; guarding that is follow-up work.
Gate: task check exit 0, UI suite 230/230, all Go packages ok.
* fix(ui): make the served vocabulary reach an already-painted page
Greptile's finding on the first cut of this fix, and it was right: loadTaskMeta()
resolves after a page has painted and only mutated module state. The route tree
renders into its own root, so App re-rendering cannot reach it, and a painted
page kept the freeze-dried labels it read on the way up.
show() is split so the page render can be repeated on its own: renderRoute()
mounts the current route into the outlet without the teardown/chrome side
effects, and the catalog effect calls it once the catalog lands. The key is
unchanged, so Preact re-renders the mounted page in place and keeps its state.
Deeper instance of the same defect, found while fixing that one:
task-filters.jsx captured the vocabulary in module-level constants at import
(ATTENTION_STATUSES/TASK_STATUSES), so the task filter could never see a served
status, no matter when or how correctly the catalog landed. Both are read at
call time now.
Tests, and what they actually cover:
- the task-filter test has teeth: with the source fix stashed it fails, with
the fix it passes.
- task-meta-late-catalog.test.js guards the boot fetch end to end (it fails
when loadTaskMeta is never called), but it does NOT isolate the re-render:
a page also re-renders for its own reasons, so the assertion holds without
renderRoute too. Said plainly here rather than implied as coverage -- the
fix makes the re-render deterministic instead of incidental, and this
harness cannot tell those apart.
- it lives in its own file because main.jsx boots once per process; a second
test in the same file would assert against a detached tree.
UI suite 232/232, task check exit 0.
390 lines
15 KiB
React
390 lines
15 KiB
React
import "./css/_main.css";
|
|
import { h, render } from "preact";
|
|
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
|
|
import { api } from "./base/api.jsx";
|
|
import { hiddenRoutes } from "./capabilities.jsx";
|
|
import { loadTaskMeta } from "./base/task-meta.jsx";
|
|
import { Icon } from "./base/icons.jsx";
|
|
import { dashboardPage } from "./dashboard/dashboard.jsx";
|
|
import { tasksPage } from "./tasks/tasks.jsx";
|
|
import { taskDetailPage } from "./tasks/task-detail.jsx";
|
|
import { skillsPage } from "./skills/skills.jsx";
|
|
import { workflowsPage } from "./workflows/workflows.jsx";
|
|
import { channelsPage } from "./channels/channels.jsx";
|
|
import { curatorsPage } from "./curators/curators.jsx";
|
|
import { settingsPage } from "./settings/settings.jsx";
|
|
import { logsPage } from "./logs/logs.jsx";
|
|
import { capturesPage } from "./captures/captures.jsx";
|
|
import { mappingsPage } from "./mappings/mappings.jsx";
|
|
import { bindingsPage } from "./bindings/bindings.jsx";
|
|
import { ChatPage } from "./chat/chat.jsx";
|
|
import { matchRoute, navPath } from "./routing.jsx";
|
|
|
|
/**
|
|
* Routes are declared once here. Adding a section means adding a feature
|
|
* folder and one entry -- there is no switch statement to hunt for.
|
|
*
|
|
* `soon: true` sections are deliberately visible before they are built: a
|
|
* greyed, labelled entry tells you the capability exists and is coming, which
|
|
* is more honest than hiding it and more useful than a 404.
|
|
*/
|
|
// section names the capability a route needs, as reported by
|
|
// GET /api/capabilities. A route with no section is served in every
|
|
// composition. The dashboard is rendered by two different processes -- the
|
|
// daemon and the extracted UI service -- and a section the serving process
|
|
// cannot back would otherwise render as permanently empty rather than as
|
|
// absent (archie-core-8cda.5.4).
|
|
//
|
|
// A route may also carry:
|
|
// nav:false -- addressed by URL but not a navigation entry (a detail page
|
|
// reached from its section)
|
|
// navPath -- the navigation entry this route keeps current; a parameterised
|
|
// route is not itself in the nav, so without this the section it
|
|
// belongs to would lose its aria-current highlight
|
|
// :name -- one captured path segment, e.g. /tasks/:id
|
|
const routes = [
|
|
{ path: "/", label: "Dashboard", icon: "dashboard", view: dashboardPage },
|
|
{ path: "/chat", label: "Chat", icon: "chat", view: ChatPage, section: "chat" },
|
|
{ path: "/tasks", label: "Tasks", icon: "tasks", view: tasksPage },
|
|
{ path: "/tasks/:id", label: "Task run", view: taskDetailPage, nav: false, navPath: "/tasks" },
|
|
{ path: "/logs", label: "Logs", icon: "logs", view: logsPage, section: "logs" },
|
|
{ path: "/captures", label: "Event inspector", icon: "captures", view: capturesPage, section: "captures" },
|
|
{ path: "/mappings", label: "Field mappings", icon: "mappings", view: mappingsPage, section: "mappings" },
|
|
{ path: "/bindings", label: "Playbook bindings", icon: "bindings", view: bindingsPage, section: "bindings" },
|
|
{ path: "/skills", label: "Skills", icon: "skills", view: skillsPage, section: "skills" },
|
|
{ path: "/workflows", label: "Workflows", icon: "workflows", view: workflowsPage, section: "workflows" },
|
|
{ path: "/curators", label: "Curators", icon: "curators", view: curatorsPage, section: "curators" },
|
|
{ path: "/channels", label: "Channels", icon: "channels", view: channelsPage, section: "channels" },
|
|
{ path: "/settings", label: "Configuration", icon: "settings", view: settingsPage, section: "settings" },
|
|
];
|
|
|
|
const THEME_KEY = "archie.theme";
|
|
|
|
function currentTheme() {
|
|
return localStorage.getItem(THEME_KEY) || "dark";
|
|
}
|
|
|
|
function applyTheme(theme) {
|
|
document.documentElement.dataset.theme = theme;
|
|
localStorage.setItem(THEME_KEY, theme);
|
|
}
|
|
|
|
// navEntries lists what gets a navigation item: a detail route (nav:false) is
|
|
// addressed by URL but reached from its section, so it is not an entry.
|
|
function navEntries(hidden) {
|
|
return routes.filter((route) => route.nav !== false && !hidden.includes(route.path));
|
|
}
|
|
|
|
function Topbar({ activePath, hidden, onNavigate, chatOpen, onToggleChat, theme, onToggleTheme }) {
|
|
const [searchOpen, setSearchOpen] = useState(false);
|
|
const searchRef = useRef(null);
|
|
|
|
const closeSearch = () => setSearchOpen(false);
|
|
|
|
const onSearchKeyDown = (event) => {
|
|
if (event.key === "Escape") {
|
|
// preventDefault so the window-level handler (chat drawer close) does not
|
|
// also fire: dismissing the search should not dismiss the drawer.
|
|
event.preventDefault();
|
|
closeSearch();
|
|
event.target.blur();
|
|
return;
|
|
}
|
|
if (event.key !== "Enter") return;
|
|
// Search jumps between sections. It is deliberately not a data search: the
|
|
// sections own their own filtering, and a second search that means
|
|
// something different in each place is worse than none.
|
|
const query = event.target.value.trim().toLowerCase();
|
|
const hit = routes.find(
|
|
(route) => route.nav !== false && !route.soon && route.label.toLowerCase().startsWith(query),
|
|
);
|
|
if (hit) {
|
|
onNavigate(hit.path);
|
|
event.target.value = "";
|
|
event.target.blur();
|
|
closeSearch();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<header className="topbar">
|
|
<div className="brand">
|
|
<span className="brand-mark">A</span>
|
|
Archie
|
|
</div>
|
|
<nav className="nav">
|
|
{navEntries(hidden).map((route) => (
|
|
<a
|
|
className="nav-item"
|
|
key={route.path}
|
|
href={`#${route.path}`}
|
|
aria-current={route.path === activePath ? "page" : undefined}
|
|
aria-disabled={route.soon || undefined}
|
|
title={route.soon ? "Coming soon" : undefined}
|
|
onClick={(event) => {
|
|
if (route.soon) event.preventDefault();
|
|
else onNavigate(route.path);
|
|
}}
|
|
>
|
|
<Icon name={route.icon} />
|
|
<span className="nav-label">{route.label}</span>
|
|
{route.soon ? <span className="nav-soon">soon</span> : null}
|
|
</a>
|
|
))}
|
|
</nav>
|
|
<div className="topbar-end">
|
|
<div className={`topbar-search${searchOpen ? " is-open" : ""}`}>
|
|
<span className="topbar-search-icon" aria-hidden="true">
|
|
<Icon name="search" size={15} />
|
|
</span>
|
|
<button
|
|
className="icon-btn mobile-search-toggle"
|
|
type="button"
|
|
aria-label="Open Jump to navigation"
|
|
aria-expanded={searchOpen ? "true" : "false"}
|
|
onClick={() => {
|
|
setSearchOpen(true);
|
|
// The field is always mounted -- the narrow layout only hides it --
|
|
// so focus can land in it straight away instead of on the toggle.
|
|
searchRef.current?.focus();
|
|
}}
|
|
>
|
|
<Icon name="search" size={15} />
|
|
</button>
|
|
<input
|
|
ref={searchRef}
|
|
type="search"
|
|
placeholder="Jump to…"
|
|
aria-label="Jump to a section"
|
|
onKeyDown={onSearchKeyDown}
|
|
/>
|
|
</div>
|
|
<button
|
|
className="icon-btn icon-btn-chat"
|
|
aria-label="Open chat"
|
|
title="Chat with Archie"
|
|
aria-expanded={chatOpen ? "true" : "false"}
|
|
onClick={() => onToggleChat()}
|
|
>
|
|
<Icon name="chat" />
|
|
</button>
|
|
<button className="icon-btn" title="Documentation" aria-label="Documentation">
|
|
<Icon name="help" />
|
|
</button>
|
|
<button
|
|
className="icon-btn"
|
|
title="Toggle light and dark"
|
|
aria-label="Toggle light and dark"
|
|
onClick={onToggleTheme}
|
|
>
|
|
<Icon name={theme === "dark" ? "moon" : "sun"} />
|
|
</button>
|
|
<div className="avatar" title="Signed in locally">
|
|
A
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|
|
|
|
// The chat drawer lives beside the outlet, mounted once. It is closed by
|
|
// default and opened from the topbar launcher; because it is a slide-over
|
|
// rather than a route, the operator can talk to Archie from any page without
|
|
// leaving the work that prompted the question. It hosts a single ChatPage
|
|
// instance, so session state and the stream survive navigation and are not
|
|
// duplicated per page.
|
|
function ChatDrawer({ open, onClose }) {
|
|
return (
|
|
<aside className={`chat-drawer${open ? " is-open" : ""}`} aria-label="Chat with Archie">
|
|
<div className="chat-drawer-panel">
|
|
<div className="chat-drawer-head">
|
|
<strong>Archie</strong>
|
|
<button className="icon-btn chat-drawer-close" aria-label="Close chat" title="Close chat" onClick={onClose}>
|
|
<Icon name="close" />
|
|
</button>
|
|
</div>
|
|
<ChatPage />
|
|
</div>
|
|
<div className="chat-scrim" onClick={onClose} />
|
|
</aside>
|
|
);
|
|
}
|
|
|
|
function ComingSoon({ label }) {
|
|
return (
|
|
<div>
|
|
<div className="page-head">
|
|
<div>
|
|
<h1 className="page-title">{label}</h1>
|
|
</div>
|
|
</div>
|
|
<div className="card">
|
|
<div className="empty">
|
|
<div className="empty-title">{`${label} is not built yet`}</div>
|
|
<div>This section is next up. Nothing is broken.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// RouteView gives the router a keyed boundary. A page is a function of its
|
|
// query and its path parameters, and two ids on the same parameterised route
|
|
// must be two instances: without the key the second id diffs the first one in
|
|
// place and the operator's open tab from the previous task stays open on the
|
|
// next (W11).
|
|
function RouteView({ view, search, params }) {
|
|
return view(search, params);
|
|
}
|
|
|
|
// Routing is wired once, at import, and pages render into one long-lived outlet
|
|
// rather than as children of App.
|
|
//
|
|
// The listeners cannot live in an effect: a page installs its own
|
|
// hash-sensitive state as it mounts, and the outgoing page has to be gone in
|
|
// the same tick the hash changes. Task detail writes the tab selection back
|
|
// with replaceState as it settles; if it is still mounted when the hashchange
|
|
// lands, it canonicalises the URL back to its own route and the navigation is
|
|
// silently lost. App publishes its outlet and its two navigation-owned pieces
|
|
// of chrome through a callback ref, which runs at commit time -- before any
|
|
// page effect can run.
|
|
let outlet = null;
|
|
let chrome = null;
|
|
|
|
// renderRoute mounts the route's page into the outlet. It is separate from
|
|
// show() because the lifecycle catalog arrives after the first paint and the
|
|
// route tree renders into its own root: App re-rendering cannot reach into the
|
|
// outlet, so a late catalog has to re-render the page explicitly or it keeps
|
|
// the freeze-dried labels it read on the way up. The key is unchanged, so Preact
|
|
// re-renders the mounted page in place and keeps its state.
|
|
function renderRoute(rawPath) {
|
|
if (!outlet) return;
|
|
const [path, query = ""] = String(rawPath).split("?", 2);
|
|
const match = matchRoute(routes, path);
|
|
const route = match?.route || routes[0];
|
|
const params = match?.params || {};
|
|
|
|
// The chat is a drawer, not a page: /chat opens it rather than mounting a
|
|
// second ChatPage (which would duplicate session state and the stream).
|
|
if (route.path === "/chat") {
|
|
render(null, outlet);
|
|
return;
|
|
}
|
|
|
|
// The key covers the path and its parameters, but NOT the query: the query
|
|
// string is an entry state, so a navigation that only changes the query of
|
|
// the page already mounted keeps the operator's own filter selection.
|
|
render(
|
|
route.view ? (
|
|
<RouteView
|
|
key={`${route.path}|${Object.values(params).join("/")}`}
|
|
view={route.view}
|
|
search={new URLSearchParams(query)}
|
|
params={params}
|
|
/>
|
|
) : (
|
|
<ComingSoon label={route.label} />
|
|
),
|
|
outlet,
|
|
);
|
|
}
|
|
|
|
function show(rawPath) {
|
|
const [path] = String(rawPath).split("?", 2);
|
|
const match = matchRoute(routes, path);
|
|
const route = match?.route || routes[0];
|
|
|
|
// Let a page release its subscriptions before it is replaced, so the SSE
|
|
// stream does not leak a connection per navigation. The event goes to the
|
|
// outgoing page's root, before the swap.
|
|
outlet?.firstElementChild?.dispatchEvent(new CustomEvent("archie:teardown"));
|
|
// A detail route highlights the section it belongs to, so the nav item for
|
|
// Tasks stays current on #/tasks/42 instead of every item losing it.
|
|
chrome?.setActive(navPath(route));
|
|
|
|
// The chat is a drawer, not a page: /chat opens it rather than mounting a
|
|
// second ChatPage (which would duplicate session state and the stream).
|
|
chrome?.setChatOpen(route.path === "/chat");
|
|
renderRoute(rawPath);
|
|
}
|
|
|
|
function navigate(next) {
|
|
if (location.hash !== `#${next}`) location.hash = next;
|
|
else show(next);
|
|
}
|
|
|
|
window.addEventListener("hashchange", () => show(location.hash.slice(1) || "/"));
|
|
window.addEventListener("keydown", (event) => {
|
|
// A focused control (the composer dismissing its command menu, or the topbar
|
|
// search) already handled Escape via preventDefault; closing the drawer too
|
|
// would make the menu impossible to dismiss alone.
|
|
if (event.defaultPrevented) return;
|
|
if (event.key === "Escape") chrome?.setChatOpen(false);
|
|
});
|
|
|
|
function App() {
|
|
const [active, setActive] = useState("/");
|
|
const [theme, setTheme] = useState(currentTheme);
|
|
const [chatOpen, setChatOpen] = useState(false);
|
|
const [hidden, setHidden] = useState([]);
|
|
|
|
// Publishes the router's handles. A callback ref runs at commit time, so a
|
|
// hashchange that lands right after the first paint already finds them.
|
|
const publish = useCallback((element) => {
|
|
outlet = element;
|
|
chrome = { setActive, setChatOpen };
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
applyTheme(theme);
|
|
}, [theme]);
|
|
|
|
useEffect(() => {
|
|
document.body.classList.toggle("chat-open", chatOpen);
|
|
}, [chatOpen]);
|
|
|
|
// Asked for once, after the shell is up: the nav renders immediately and
|
|
// loses the entries this process cannot back a moment later, rather than
|
|
// holding the whole page behind one request.
|
|
useEffect(() => {
|
|
api
|
|
.capabilities()
|
|
.then((caps) => setHidden(hiddenRoutes(caps?.sections, routes)))
|
|
.catch(() => {});
|
|
}, []);
|
|
|
|
// The lifecycle vocabulary -- status labels, pill severity, "needs you"
|
|
// grouping, and the operator actions -- is served by /api/task-meta. Ask for
|
|
// it once, after the shell is up: the freeze-dried defaults paint
|
|
// immediately and this replaces them, so a catalogue change on the server
|
|
// reaches the browser without a UI release. loadTaskMeta never throws (a
|
|
// failed fetch keeps the defaults), so it needs no catch here.
|
|
useEffect(() => {
|
|
// The catalog lands after the first paint, and the route tree renders into
|
|
// its own root: without re-rendering it, an already-painted page keeps the
|
|
// freeze-dried labels it read on the way up until something else happens to
|
|
// re-render it.
|
|
loadTaskMeta().then(() => renderRoute(location.hash.slice(1) || "/"));
|
|
}, []);
|
|
|
|
return (
|
|
<div className="shell">
|
|
<Topbar
|
|
activePath={active}
|
|
hidden={hidden}
|
|
onNavigate={navigate}
|
|
chatOpen={chatOpen}
|
|
onToggleChat={() => setChatOpen((open) => !open)}
|
|
theme={theme}
|
|
onToggleTheme={() => setTheme((current) => (current === "dark" ? "light" : "dark"))}
|
|
/>
|
|
<main className="main" ref={publish} />
|
|
<ChatDrawer open={chatOpen} onClose={() => setChatOpen(false)} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
applyTheme(currentTheme());
|
|
render(<App />, document.getElementById("app"));
|
|
show(location.hash.slice(1) || "/");
|