diff --git a/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx b/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx
index d01d23811..036339b33 100644
--- a/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx
+++ b/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx
@@ -63,8 +63,8 @@ export function CancelTurnBadge({
return (
);
diff --git a/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx b/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx
index b64ed3a65..50e3a8cea 100644
--- a/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx
+++ b/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx
@@ -15,6 +15,7 @@ import {
type RefreshIntervalMs,
} from "../ui/refresh-interval/RefreshInterval.js";
import { fetchJson, usePolled } from "../ui/polled/usePolled.js";
+import { StaleNote } from "../ui/polled/StaleNote.js";
import { Table, type TableColumn } from "../ui/table/Table.js";
import { TableSkeleton } from "../ui/table/TableSkeleton.js";
import { Toolbar } from "../ui/toolbar/Toolbar.js";
@@ -81,6 +82,7 @@ function AlertsBody() {
const {
data: alerts,
error,
+ updatedAt,
refreshing,
} = usePolled(
intervalMs,
@@ -114,6 +116,11 @@ function AlertsBody() {
problem={error}
/>
) : null}
+
{!error && alerts === null ? (
) : null}
diff --git a/frontend/packages/swarm-ui/src/pages/CreateAgentForm.tsx b/frontend/packages/swarm-ui/src/pages/CreateAgentForm.tsx
index ffa52d4d3..4f66184a3 100644
--- a/frontend/packages/swarm-ui/src/pages/CreateAgentForm.tsx
+++ b/frontend/packages/swarm-ui/src/pages/CreateAgentForm.tsx
@@ -72,6 +72,7 @@ import {
} from "./CreateAgentAgentsMd.js";
import {
NAME_PATTERN,
+ lastReachableStep,
nextStep,
previousStep,
STEP_TITLES,
@@ -285,6 +286,32 @@ export function CreateAgentForm({
});
const done = result.status === "done";
const at = STEPS.indexOf(step);
+ // The tabs go forward again as far as the operator has been, as long as the
+ // steps before are still valid.
+ const [reached, setReached] = useState(0);
+ useEffect(() => {
+ setReached((r) => Math.max(r, at));
+ }, [at]);
+ const firstBad = STEPS.findIndex(
+ (s) =>
+ stepProblem(s, {
+ name,
+ hive,
+ permissionsReady: catalogue !== null,
+ inferenceProblem,
+ }) !== null,
+ );
+ const lastTab = lastReachableStep(reached, firstBad, at);
+ // Why the primary button is off, said in words.
+ const createProblem =
+ step === "summary" && result.status !== "submitting"
+ ? !hivesReady
+ ? "the hive list has not loaded"
+ : !catalogue
+ ? "the permission list has not loaded"
+ : null
+ : null;
+ const shownProblem = problem ?? createProblem;
// Enter goes on to the next step, and creates only from the summary.
function onSubmit(e: Event) {
@@ -314,7 +341,7 @@ export function CreateAgentForm({
type="button"
class={`create-agent-step-tab${s === step ? " create-agent-step-current" : ""}`}
aria-current={s === step ? "step" : undefined}
- disabled={i > at || done}
+ disabled={i > lastTab || done}
onClick={() => setStep(s)}
>
{i + 1}. {STEP_TITLES[s]}
@@ -555,9 +582,14 @@ export function CreateAgentForm({
>
back
- {problem !== null && (step !== "identity" || name !== "") && (
-
- {problem}
+ {shownProblem !== null && (
+
+ {shownProblem}
)}
{step === "summary" ? (
@@ -567,6 +599,9 @@ export function CreateAgentForm({
disabled={
result.status === "submitting" || !hivesReady || !catalogue
}
+ describedBy={
+ createProblem !== null ? "create-agent-hint" : undefined
+ }
>
{result.status === "submitting" ? "creating…" : "create"}
@@ -575,6 +610,9 @@ export function CreateAgentForm({
variant="primary"
type="submit"
disabled={problem !== null}
+ describedBy={
+ problem !== null ? "create-agent-hint" : undefined
+ }
>
next
diff --git a/frontend/packages/swarm-ui/src/pages/CreateAgentSteps.ts b/frontend/packages/swarm-ui/src/pages/CreateAgentSteps.ts
index 93437f0ed..203575da5 100644
--- a/frontend/packages/swarm-ui/src/pages/CreateAgentSteps.ts
+++ b/frontend/packages/swarm-ui/src/pages/CreateAgentSteps.ts
@@ -73,6 +73,21 @@ export function stepProblem(step: Step, input: StepInputs): string | null {
}
}
+/**
+ * The last step a tab can go to. The tabs reach as far as the operator has
+ * got (`reached`, an index into `STEPS`), but not past a step whose inputs are
+ * not valid now (`firstBad`, its index, or -1 for none), and never behind the
+ * current step (`at`).
+ */
+export function lastReachableStep(
+ reached: number,
+ firstBad: number,
+ at: number,
+): number {
+ const limit = firstBad === -1 ? reached : Math.min(reached, firstBad);
+ return Math.max(limit, at);
+}
+
/** One line of the summary: a setting and what will be sent for it. */
export interface SummaryRow {
label: string;
diff --git a/frontend/packages/swarm-ui/src/pages/builds/BuildsPage.tsx b/frontend/packages/swarm-ui/src/pages/builds/BuildsPage.tsx
index 0121930de..fd03e9608 100644
--- a/frontend/packages/swarm-ui/src/pages/builds/BuildsPage.tsx
+++ b/frontend/packages/swarm-ui/src/pages/builds/BuildsPage.tsx
@@ -23,6 +23,7 @@ import {
type RefreshIntervalMs,
} from "../../ui/refresh-interval/RefreshInterval.js";
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js";
+import { StaleNote } from "../../ui/polled/StaleNote.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
import { durationLabel } from "../../util.js";
import {
@@ -100,6 +101,7 @@ function BuildsBody() {
const {
data: runs,
error,
+ updatedAt,
refreshing,
} = usePolled(intervalMs, (signal) => fetchJson(RUNS, signal), {
cacheKey: "builds",
@@ -153,6 +155,11 @@ function BuildsBody() {
problem={error}
/>
) : null}
+
{missing ? (
the build in this link is no longer listed: the builder keeps only its
diff --git a/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx b/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx
index 8cba2829f..78562910f 100644
--- a/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx
+++ b/frontend/packages/swarm-ui/src/pages/notifications/FlowEditorPage.tsx
@@ -12,6 +12,7 @@
// were changed elsewhere, and the editor offers to reload or to keep the draft
// on top of the latest.
import { useCallback, useEffect, useState } from "preact/hooks";
+import { usePageTitle } from "../../shell/page-title.js";
import {
Link,
useLocation,
@@ -76,6 +77,7 @@ export function FlowEditorPage({
// With `from` an archetype flow: the one agent this copy is for.
const agent = search.get("agent");
const [, navigate] = useLocation();
+ usePageTitle(isNew ? "new flow" : `flow ${flowId}`);
const [view, setView] = useState(null);
const [draft, setDraft] = useState(null);
// What a new draft started as, so leaving it untouched is not "unsaved".
diff --git a/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx b/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx
index 6a7fbb54a..16b51ad1e 100644
--- a/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx
+++ b/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx
@@ -22,6 +22,7 @@ import {
type RefreshIntervalMs,
} from "../../ui/refresh-interval/RefreshInterval.js";
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js";
+import { StaleNote } from "../../ui/polled/StaleNote.js";
import { Deliveries, DeliveriesSkeleton } from "./Deliveries.js";
import { FlowListSkeleton } from "./FlowListSkeleton.js";
import { NEW_FLOW_PATH, withMembersAs } from "./FlowDraft.js";
@@ -45,6 +46,7 @@ export function NotificationRouter() {
const {
data: view,
error,
+ updatedAt,
refreshing: flowsRefreshing,
refresh,
} = usePolled(intervalMs, (signal) =>
@@ -126,6 +128,11 @@ export function NotificationRouter() {
{error ? (
) : null}
+
{actionError ? (
) : null}
+
{runs !== null && runs.length === 0 && !error ? (
No runs yet.
) : null}
diff --git a/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx b/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx
index 4711ebd51..1f18d1216 100644
--- a/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx
+++ b/frontend/packages/swarm-ui/src/pages/schedules/SchedulesPage.tsx
@@ -22,6 +22,7 @@ import {
type RefreshIntervalMs,
} from "../../ui/refresh-interval/RefreshInterval.js";
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js";
+import { StaleNote } from "../../ui/polled/StaleNote.js";
import type { TableColumn } from "../../ui/table/Table.js";
import type { AgentRow } from "../../agent/AgentTypes.js";
import { ScheduleCard, ScheduleListSkeleton } from "./ScheduleCard.js";
@@ -64,6 +65,7 @@ function SchedulesBody() {
const {
data: schedules,
error,
+ updatedAt,
refreshing: schedulesRefreshing,
refresh,
} = usePolled(intervalMs, (signal) =>
@@ -180,6 +182,11 @@ function SchedulesBody() {
{error ? (
) : null}
+
{actionError ? (
) : null}
+
{!error && hives === null ? (
) : null}
diff --git a/frontend/packages/swarm-ui/src/shell/Shell.tsx b/frontend/packages/swarm-ui/src/shell/Shell.tsx
index 5ef26d6b0..930bc1a66 100644
--- a/frontend/packages/swarm-ui/src/shell/Shell.tsx
+++ b/frontend/packages/swarm-ui/src/shell/Shell.tsx
@@ -29,6 +29,7 @@
import { useEffect, useRef, useState } from "preact/hooks";
import type { ComponentChildren } from "preact";
import { Link, useLocation } from "wouter-preact";
+import { usePageTitleValue } from "./page-title.js";
import { LinksMenu } from "./LinksMenu.js";
import { UserMenu } from "./UserMenu.js";
import { useHideDebug } from "./useHideDebug.js";
@@ -408,7 +409,9 @@ export function Shell({ children }: { children: ComponentChildren }) {
// top-level route takes its nav label, a terminal route takes the
// label its page registered as a dynamic tab. An unmatched path gets
// the bare brand.
+ const pageTitle = usePageTitleValue();
const pageLabel =
+ pageTitle ??
navItems.find((item) => item.href === location)?.label ??
tabs.find((tab) => tab.href === location)?.label;
useEffect(() => {
diff --git a/frontend/packages/swarm-ui/src/shell/page-title.ts b/frontend/packages/swarm-ui/src/shell/page-title.ts
new file mode 100644
index 000000000..aa2039f9b
--- /dev/null
+++ b/frontend/packages/swarm-ui/src/shell/page-title.ts
@@ -0,0 +1,44 @@
+// The title a page gives itself, for the browser tab and the page's heading: for
+// a route the shell cannot name from its nav items or open tabs, such as the
+// flow editor, where several tabs would otherwise all read as the bare brand.
+// A page calls `usePageTitle("flow fan-out")`; the shell reads it with
+// `usePageTitleValue()` and falls back to its own label when none is set.
+import { useEffect, useState } from "preact/hooks";
+
+let current: string | undefined;
+const listeners = new Set<() => void>();
+
+/** Set the page's title (or clear it with `undefined`). */
+export function setPageTitle(title: string | undefined): void {
+ if (current === title) return;
+ current = title;
+ listeners.forEach((fn) => fn());
+}
+
+export function getPageTitle(): string | undefined {
+ return current;
+}
+
+/** Subscribe to changes; returns the way to stop. */
+export function subscribePageTitle(fn: () => void): () => void {
+ listeners.add(fn);
+ return () => listeners.delete(fn);
+}
+
+/** Give the page this title while it is mounted. */
+export function usePageTitle(title: string | undefined): void {
+ useEffect(() => {
+ setPageTitle(title);
+ return () => setPageTitle(undefined);
+ }, [title]);
+}
+
+/** The title a page has set, if any, following changes. */
+export function usePageTitleValue(): string | undefined {
+ const [title, setTitle] = useState(getPageTitle());
+ useEffect(() => {
+ setTitle(getPageTitle());
+ return subscribePageTitle(() => setTitle(getPageTitle()));
+ }, []);
+ return title;
+}
diff --git a/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx b/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx
index de5f7637b..53430ce58 100644
--- a/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx
+++ b/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx
@@ -16,12 +16,15 @@ export function Hint({
tone = "muted",
as: Tag = "p",
role,
+ id,
class: extraClass,
children,
}: {
tone?: HintTone;
as?: "p" | "span" | "div";
role?: "status" | "alert";
+ /** For a control's `aria-describedby`: the hint says why it is off. */
+ id?: string;
class?: string;
children: ComponentChildren;
}) {
@@ -30,6 +33,7 @@ export function Hint({
.join(" ");
return (
diff --git a/frontend/packages/swarm-ui/src/ui/polled/StaleNote.tsx b/frontend/packages/swarm-ui/src/ui/polled/StaleNote.tsx
new file mode 100644
index 000000000..b396f925a
--- /dev/null
+++ b/frontend/packages/swarm-ui/src/ui/polled/StaleNote.tsx
@@ -0,0 +1,36 @@
+// — says how old a polled list is when it is not live: under a failed
+// refresh it shows the last good answer, and with a `cacheKey` the first paint is
+// the answer saved on the last visit. Neither says so by itself, so a list such as
+// "nothing is alerting" could be days old without a mark. Renders nothing for a
+// list that is current.
+import { Hint } from "../hint/Hint.js";
+import { RelativeTime } from "../relative-time/RelativeTime.js";
+
+export function StaleNote({
+ updatedAt,
+ failed,
+ hasData,
+}: {
+ /** When the last live answer arrived (`usePolled`), or null if none has. */
+ updatedAt: number | null;
+ /** The latest refresh failed. */
+ failed: boolean;
+ /** The page has a list to show at all. */
+ hasData: boolean;
+}) {
+ if (!hasData) return null;
+ if (updatedAt === null) {
+ return (
+
+ showing the answer saved from your last visit, until a fresh one
+ arrives.
+
+ );
+ }
+ if (!failed) return null;
+ return (
+
+ showing the last answer, from .
+
+ );
+}
diff --git a/frontend/packages/swarm-ui/src/ui/polled/usePolled.ts b/frontend/packages/swarm-ui/src/ui/polled/usePolled.ts
index cc07ca48e..ffb759508 100644
--- a/frontend/packages/swarm-ui/src/ui/polled/usePolled.ts
+++ b/frontend/packages/swarm-ui/src/ui/polled/usePolled.ts
@@ -1,4 +1,6 @@
// A resource refetched on a timer: `{ data, error, refreshing, refresh, setData }`.
+// `updatedAt` is when the last live answer arrived, for saying how old a list
+// is under a failed refresh (`StaleNote`).
// `data` is `null` until the first answer (or, with a `cacheKey`, the saved one
// of the last visit, which is shown at once and replaced by the fresh answer;
// see `answer-cache.ts`); a failed fetch sets `error` and
@@ -53,6 +55,9 @@ export function usePolled(
): {
data: T | null;
error: ProblemDetails | null;
+ /** When the last live answer arrived; null until one has (a saved answer
+ * from the last visit is not one). */
+ updatedAt: number | null;
refreshing: boolean;
refresh: () => void;
setData: (update: (prev: T | null) => T | null) => void;
@@ -64,6 +69,7 @@ export function usePolled(
cacheKey === undefined ? null : readAnswer(cacheKey),
);
const [error, setError] = useState(null);
+ const [updatedAt, setUpdatedAt] = useState(null);
const [refreshing, setRefreshing] = useState(false);
const fetcherRef = useRef(fetcher);
@@ -83,6 +89,7 @@ export function usePolled(
}
setData(next);
setError(null);
+ setUpdatedAt(Date.now());
},
onError: (e) => setError(toProblem(e)),
onBusy: (busy) => hold.busy(busy),
@@ -99,5 +106,12 @@ export function usePolled(
);
useRefreshInterval(intervalMs, () => poller.tick());
- return { data, error, refreshing, refresh: () => poller.refetch(), setData };
+ return {
+ data,
+ error,
+ updatedAt,
+ refreshing,
+ refresh: () => poller.refetch(),
+ setData,
+ };
}
diff --git a/frontend/packages/swarm-ui/test/create-agent-steps.test.mjs b/frontend/packages/swarm-ui/test/create-agent-steps.test.mjs
index 67f2da36f..95bf8fe91 100644
--- a/frontend/packages/swarm-ui/test/create-agent-steps.test.mjs
+++ b/frontend/packages/swarm-ui/test/create-agent-steps.test.mjs
@@ -3,6 +3,7 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import {
+ lastReachableStep,
nameProblem,
nextStep,
previousStep,
@@ -99,3 +100,16 @@ test("the summary lists what is sent and what stays at its default", () => {
assert.equal(rows({ permissions: [] }).permissions, "none");
assert.equal(rows({ agentsMd: "x" }).instructions, "AGENTS.md, 1 word");
});
+
+test("the tabs go forward as far as the operator has been, not past a bad step", () => {
+ // On the summary (4) having been there: every step is open.
+ assert.equal(lastReachableStep(4, -1, 4), 4);
+ // Back on the identity step (0) after reaching the summary: still open to 4.
+ assert.equal(lastReachableStep(4, -1, 0), 4);
+ // The name went bad (step 0): only the current step is open.
+ assert.equal(lastReachableStep(4, 0, 0), 0);
+ // A bad permissions step (2) stops the tabs there.
+ assert.equal(lastReachableStep(4, 2, 0), 2);
+ // Never behind the current step.
+ assert.equal(lastReachableStep(1, 0, 3), 3);
+});
diff --git a/frontend/packages/swarm-ui/test/page-title.test.mjs b/frontend/packages/swarm-ui/test/page-title.test.mjs
new file mode 100644
index 000000000..6c7d9939e
--- /dev/null
+++ b/frontend/packages/swarm-ui/test/page-title.test.mjs
@@ -0,0 +1,28 @@
+// The title a page gives itself: set, change, clear, and who hears of it.
+// Run by `npm test`.
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import {
+ getPageTitle,
+ setPageTitle,
+ subscribePageTitle,
+} from "../src/shell/page-title.ts";
+
+test("a page sets its title and clears it again", () => {
+ setPageTitle("flow fan-out");
+ assert.equal(getPageTitle(), "flow fan-out");
+ setPageTitle(undefined);
+ assert.equal(getPageTitle(), undefined);
+});
+
+test("a subscriber hears of a change, not of the same title set again", () => {
+ let heard = 0;
+ const stop = subscribePageTitle(() => heard++);
+ setPageTitle("a");
+ setPageTitle("a");
+ setPageTitle("b");
+ assert.equal(heard, 2);
+ stop();
+ setPageTitle(undefined);
+ assert.equal(heard, 2);
+});