diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index e03966feb..7483bf922 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -153,6 +153,15 @@ the browser gives up on the stream, a **reconnect** badge opens it again. The terminal's own tab keeps these badges, with the model, beside the agent's name; the turn-state badge says how long the agent has been in that state. +The terminal is a `role="log"` that takes the keyboard focus, so the arrow keys +scroll it, and it doesn't announce new rows, since many can arrive in a second. +Once you scroll up it stops following the newest row, and a **latest** badge over +its bottom-right corner scrolls back and follows again. + +The page around it has a skip link (**skip to content**, the first Tab stop), a +`
` landmark that takes the focus when a page opens, and a hidden `

` +with the page's name. The active tab in the header carries `aria-current`. + The connection is a **light** on the agent's icon in the name badge: green when the stream is live, amber while it connects or reconnects, red when it closes. In the card's preview, which has no name badge, the light stands alone. The diff --git a/frontend/packages/shared/src/badge/Badge.tsx b/frontend/packages/shared/src/badge/Badge.tsx index 883f1a619..1fe14cb90 100644 --- a/frontend/packages/shared/src/badge/Badge.tsx +++ b/frontend/packages/shared/src/badge/Badge.tsx @@ -78,6 +78,11 @@ export interface BadgeProps { * is an icon and a number, say. */ ariaLabel?: string; + /** + * A badge that is one choice of a few: whether it is the chosen one, said to a + * screen reader (`aria-pressed`). Its look already says it, by fill. + */ + pressed?: boolean; } export function Badge({ @@ -92,13 +97,17 @@ export function Badge({ class: extraClass, title, ariaLabel, + pressed, }: BadgeProps) { // `disabled` alone still means "button, just not clickable right // now" — see the prop's own doc above for why this can't just check // `onClick`. Both the branch below and the interactive-styling class // key off this one derived flag, not off `onClick` separately, so // they can no longer drift apart the way they used to. - const interactive = Boolean(onClick) || Boolean(disabled); + // A `pressed` badge is a toggle, so it is a button even when it is the one + // already chosen and has nothing to do on a click. + const interactive = + Boolean(onClick) || Boolean(disabled) || pressed !== undefined; const classes = [ "ui-badge", `ui-badge-${tone}`, @@ -127,6 +136,7 @@ export function Badge({ onClick={onClick} disabled={disabled} aria-expanded={expanded} + aria-pressed={pressed} aria-label={ariaLabel} title={title} > diff --git a/frontend/packages/shared/src/icons.tsx b/frontend/packages/shared/src/icons.tsx index a33303b20..d01559f1b 100644 --- a/frontend/packages/shared/src/icons.tsx +++ b/frontend/packages/shared/src/icons.tsx @@ -238,3 +238,25 @@ export function GripIcon() { ); } + +// An arrow pointing down at a line, for "scroll to the end". Same size and +// stroke as `ExpandIcon`. +export function ArrowDownIcon() { + return ( + + ); +} diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentInference.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentInference.tsx index 93047a233..93aec6554 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentInference.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentInference.tsx @@ -336,6 +336,7 @@ export function AgentInference({ agent }: { agent: string }) { setEditing(true)} /> diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx index 8f45cf8ef..909e15dc7 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentInstructions.tsx @@ -46,6 +46,7 @@ export function AgentInstructions({ agent }: { agent: string }) { setEditing(true)} /> diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentLimits.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentLimits.tsx index 05d722d9e..ec3c1fa22 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentLimits.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentLimits.tsx @@ -149,6 +149,7 @@ export function AgentLimits({ agent }: { agent: string }) { setEditing(true)} /> diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx index 195003028..a10d178fa 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx @@ -280,6 +280,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) { <user> replaced by the account it logs in as. The key is the swarm's CA, a public value.

-
+
{TARGET_FORMS.map(([f, label]) => ( setForm(f)} /> diff --git a/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx b/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx index c822c72bb..c3810a235 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AllowedDomains.tsx @@ -109,6 +109,7 @@ export function AllowedDomains({ agent }: { agent: string }) { openDelete(a)} /> diff --git a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx index fff2b1eab..4a19a1700 100644 --- a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx +++ b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx @@ -115,6 +115,7 @@ export function AgentCard({ } + ariaLabel={`open ${row.name}'s terminal`} title={`open ${row.name}'s terminal in its own tab`} onClick={() => openTab({ href: term.page, label: term.label })} /> diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css index 9a1c737c4..2be0761a1 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css @@ -14,6 +14,18 @@ padding-block-end: 4.8em; } +/* The way back to the newest row, over the terminal's bottom-right corner, + above the message box where there is one. */ +.ui-agent-term-preview-latest { + position: absolute; + right: 1.8em; + bottom: 1em; + z-index: 1; +} +.ui-agent-term-preview-with-input .ui-agent-term-preview-latest { + bottom: 5.4em; +} + .ui-agent-term-preview-wrap.terminal-wrap { max-height: 18em; } diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx index f6464e9ef..04596cd7b 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx @@ -22,7 +22,7 @@ import { useLayoutEffect, useRef, useState } from "preact/hooks"; import type { ComponentChildren } from "preact"; import { Badge } from "@hive/shared/badge.js"; -import { ExpandIcon } from "@hive/shared/icons.js"; +import { ArrowDownIcon, ExpandIcon } from "@hive/shared/icons.js"; import { Row } from "@hive/shared/term-row.js"; import { useDynamicTabs } from "../../shell/useDynamicTabs.js"; import { @@ -146,7 +146,18 @@ export function AgentTermPreview({
{trailing}
)}
-
+ {/* A log, so a screen reader knows what it is; `aria-live="off"` as + rows can arrive many a second, and the operator reads them on + demand. Focusable, so the arrow keys scroll it. */} +
{rows.length === 0 ? (
{/* Explicit `.row-content` wrapper, not a bare text child — @@ -168,6 +179,17 @@ export function AgentTermPreview({ rows.map((row) => ) )}
+ {/* Scrolled up, the terminal stops following: this is the way back. */} + {!stickToBottom && rows.length > 0 && ( +
+ } + value="latest" + title="scroll to the newest row and follow it again" + onClick={() => setStickToBottom(true)} + /> +
+ )}
{subagent === undefined && }
diff --git a/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx b/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx index 100b6cf03..b75c9ae78 100644 --- a/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx @@ -149,6 +149,7 @@ export function AgentGroupPage({ <> } + ariaLabel={`open ${key}'s terminal on its own`} title={`maximize: open ${key}'s terminal on its own`} onClick={() => open({ @@ -159,6 +160,7 @@ export function AgentGroupPage({ /> } + ariaLabel={`take ${key} out of this group`} title={`close: take ${key} out of this group`} onClick={() => groups.update(id, (r) => removeAgent(r, key) ?? r) diff --git a/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx b/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx index e952b4051..6a7fbb54a 100644 --- a/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/notifications/NotificationsPage.tsx @@ -159,7 +159,10 @@ export function NotificationRouter() { onChange={(checked) => setBuiltin(flow.id, checked)} /> - @@ -188,7 +191,12 @@ export function NotificationRouter() { onChange={(checked) => setBuiltin(af.key, checked)} /> - +
@@ -232,13 +240,19 @@ export function NotificationRouter() { - +
diff --git a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx index 3ec824227..3c64527b2 100644 --- a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx +++ b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx @@ -77,7 +77,11 @@ export function ScheduleCard({ )} - - - - diff --git a/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx b/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx index 126b34d74..ca42909a0 100644 --- a/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx +++ b/frontend/packages/swarm-ui/src/pages/swarm/EgressCard.tsx @@ -91,7 +91,11 @@ function DomainSection({ {swarmWide.map((e) => (
  • {e.domain} -
  • diff --git a/frontend/packages/swarm-ui/src/shell/Shell.css b/frontend/packages/swarm-ui/src/shell/Shell.css index da6604e6f..5bf662492 100644 --- a/frontend/packages/swarm-ui/src/shell/Shell.css +++ b/frontend/packages/swarm-ui/src/shell/Shell.css @@ -262,10 +262,36 @@ all: unset; cursor: pointer; line-height: 1; - padding: 0.1em 0.3em; + padding: 0.25em 0.45em; border-radius: 0.2em; color: var(--muted); } +/* `all: unset` drops the browser's focus ring, and so does the tab link's + own reset, so both draw one. */ +.shell-tab-close:focus-visible, +.shell-tab-link:focus-visible { + outline: 2px solid var(--purple); + outline-offset: 2px; +} +/* A skip link, drawn only while it has the keyboard focus. */ +.shell-skip-link { + position: absolute; + left: 0.5em; + top: -4em; + z-index: 100; + padding: 0.5em 1em; + border-radius: 0.3em; + background: var(--bg-elev); + color: var(--fg); + border: 1px solid var(--purple); +} +.shell-skip-link:focus { + top: 0.5em; +} +/* The page container takes the focus when a page opens, and is not a control. */ +.shell-body:focus { + outline: none; +} .shell-tab-close:hover { color: var(--fg); background: color-mix(in srgb, var(--fg) 10%, transparent); diff --git a/frontend/packages/swarm-ui/src/shell/Shell.tsx b/frontend/packages/swarm-ui/src/shell/Shell.tsx index b39e49e5b..5ef26d6b0 100644 --- a/frontend/packages/swarm-ui/src/shell/Shell.tsx +++ b/frontend/packages/swarm-ui/src/shell/Shell.tsx @@ -120,7 +120,11 @@ function NavLink({ textRef: (el: HTMLSpanElement | null) => void; }) { return ( - + {/* Touch target (min-height) lives on the so the whole row is tappable. The underline lives on the shared `.shell-nav-indicator`, not here — this span is still what @@ -216,6 +220,7 @@ function DynamicTabLink({ (null); + const mainRef = useRef(null); const textRefs = useRef>({}); const [indicator, setIndicator] = useState(null); // The nav-item index the indicator is currently sitting at (or mid-hop @@ -409,6 +415,17 @@ export function Shell({ children }: { children: ComponentChildren }) { document.title = pageLabel ? `${pageLabel} · ${brand}` : brand; }, [brand, pageLabel]); + // A new page starts at the top for the keyboard and a screen reader: the + // focus goes to the page's container, not left on the link that was used. + const firstPage = useRef(true); + useEffect(() => { + if (firstPage.current) { + firstPage.current = false; + return; + } + mainRef.current?.focus({ preventScroll: true }); + }, [location]); + // Same value the indicator itself is drawn with, including mid-sweep — // the brand text rides the identical hop sequence rather than // computing its own, so "the header's accent" reads as one thing @@ -417,6 +434,18 @@ export function Shell({ children }: { children: ComponentChildren }) { return (
    + { + // A plain hash would hand the click to the router; move the focus + // here instead. + e.preventDefault(); + mainRef.current?.focus(); + }} + > + skip to content +
    -

    ); } diff --git a/frontend/packages/swarm-ui/src/swarm-ui.css b/frontend/packages/swarm-ui/src/swarm-ui.css index e8bdca3f5..8068a5abb 100644 --- a/frontend/packages/swarm-ui/src/swarm-ui.css +++ b/frontend/packages/swarm-ui/src/swarm-ui.css @@ -12,3 +12,16 @@ a { color: var(--blue); } + +/* Text for a screen reader that is not drawn: the page's `

    `. */ +.ui-visually-hidden { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; + border: 0; +} diff --git a/frontend/packages/swarm-ui/src/ui/button/Button.tsx b/frontend/packages/swarm-ui/src/ui/button/Button.tsx index decb138dc..7b5424dc4 100644 --- a/frontend/packages/swarm-ui/src/ui/button/Button.tsx +++ b/frontend/packages/swarm-ui/src/ui/button/Button.tsx @@ -17,6 +17,7 @@ export function Button({ busy = false, onClick, describedBy, + ariaLabel, children, }: { variant?: ButtonVariant; @@ -29,6 +30,9 @@ export function Button({ onClick?: (e: Event) => void; /** Id of the element that says why the button is disabled. */ describedBy?: string; + /** A name that says what the button acts on, where its visible text repeats + * across a list ("remove", "edit"). It should start with the visible text. */ + ariaLabel?: string; children: ComponentChildren; }) { return ( @@ -39,6 +43,7 @@ export function Button({ aria-busy={busy || undefined} onClick={onClick} aria-describedby={describedBy} + aria-label={ariaLabel} > {children} {busy ? (