From 3a846c8c45bbbf8c1954171ba254353608d94a17 Mon Sep 17 00:00:00 2001 From: iris Date: Mon, 16 Nov 2026 23:40:59 +0100 Subject: [PATCH] swarm ui: the terminal's status badges overhaul The connection is a light on the agent's icon instead of a "live" badge, the model and the effort are one badge, the context badge has an icon, subagents and a new bash tasks badge are an icon and a count, and an agent's tab shows a drag grip on hover. It also removes two things the overhaul replaces: the cost badge, and the "split" badge with its menu in group panes (splitting is by dragging a tab, or from the subagents list). --- docs/4-implementation/web-ui/swarm-ui.md | 41 ++++++---- frontend/packages/shared/src/badge/Badge.tsx | 9 ++- frontend/packages/shared/src/icons.tsx | 76 +++++++++++++++++++ .../src/agent/detail/AgentStateRow.tsx | 1 - .../swarm-ui/src/agent/state/StateBadges.tsx | 65 +++++++--------- .../swarm-ui/src/agent/state/badge-titles.ts | 27 +++---- .../src/agent/terminal/AgentTermPreview.css | 6 +- .../src/agent/terminal/AgentTermPreview.tsx | 40 ++++------ .../swarm-ui/src/agent/terminal/BashTasks.tsx | 21 ++++- .../src/agent/terminal/BashTasksMenu.tsx | 52 +++++++++++++ .../src/agent/terminal/ConnectionDot.css | 47 ++++++++++++ .../src/agent/terminal/ConnectionDot.tsx | 52 +++++++++++++ .../src/agent/terminal/SubagentsMenu.tsx | 11 ++- .../src/pages/agents/AgentGroupPage.css | 19 ----- .../src/pages/agents/AgentGroupPage.tsx | 65 +++------------- .../src/pages/agents/AgentTerminalPage.tsx | 12 ++- .../packages/swarm-ui/src/shell/Shell.css | 27 +++++++ .../packages/swarm-ui/src/shell/Shell.tsx | 15 +++- .../src/ui/badge-popover/BadgePopover.tsx | 8 ++ .../swarm-ui/test/badge-titles.test.mjs | 35 ++++----- 20 files changed, 430 insertions(+), 199 deletions(-) create mode 100644 frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx create mode 100644 frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.css create mode 100644 frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.tsx diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index ea0e57c0b..3fa70ab6b 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -101,7 +101,7 @@ when the data arrives. The placeholders stand still where motion is off. An opened card has six sections, and each reads nothing until you open it. **status** and **terminal** start open, the other four folded: -- **status**: how fresh the agent's last report is (with its age), its turn state, context and cost, its hive, links to its +- **status**: how fresh the agent's last report is (with its age), its turn state and context, its hive, links to its profile and its config repo on the swarm's forge (built from the forge entry of `GET /api/links`; the row stays hidden when the swarm lists none, and an agent built from an archetype has no config repo, so it gets no config repo @@ -136,22 +136,28 @@ Each subagent in the list shows the model and effort it runs, like `opus · high`, beside its name; one on the default model shows only the effort. The `/agents//terminal` page's subagent list shows them too. -The preview carries only the connection badge and **expand**, so it stays clear -of the text. What the agent is doing shows in the details table above it, in -the **state** row: the turn state (idle, thinking or compacting), a **paused** -badge for a paused agent, and the tokens in its context and billed. The row +The preview carries only a small connection light and **expand**, so it stays +clear of the text. What the agent is doing shows in the details table above it, +in the **state** row: the turn state (idle, thinking or compacting), a **paused** +badge for a paused agent, and the tokens in its context. The row shows the latest report the controller holds, if it's under 150 seconds old, as soon as you look. It reads "no report yet" when there is none: for an agent that's offline, and until the first report after the controller restarts. The agent sends a report when its state changes and once a minute. If the browser gives up on the stream, a **reconnect** badge opens it again. The -terminal's own tab keeps these badges, with the model and the effort, beside the -connection badge; the turn-state badge says how long the agent has been in that -state. Clicking the model or the effort badge opens the agent's inference -settings in a popover, the same settings its card shows. +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 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 +model and the effort are one badge, a chip icon and "opus (high)," and the +context is a dial icon and a size. Select the model badge to open the agent's +inference settings in a popover, the same settings its card shows. The terminal +shows no cost badge: the cost is a metric in Grafana. On a terminal's own page (`/agents//terminal`, or a subagent's) the -header has an **N running subagents** badge. It opens a list of the agent's +header has a **subagents** badge, a branching icon and the number running. It opens a list of the agent's subagents. Choosing one puts its terminal to the right of this one in a [group](#groups-of-terminals); in a group, it splits that pane. A subagent already in the group shows a marker and does nothing when chosen, and **maximize** @@ -162,6 +168,11 @@ swarm doesn't report more than when the newest row came, so a subagent that thinks quietly for longer drops out of the count. The list shows the others below, dimmed, as **not running**. +Beside it, an agent with background bash tasks has a **bash tasks** badge, a +prompt icon and the number running, which opens the same list of tasks the card's +"background tasks" section shows. An agent with no tasks has no badge, and a +subagent's terminal has none. + An agent's terminal opens with its last 100 rows from the past 24 hours, then follows new ones; a reconnect picks up after the last row it showed. A subagent terminal does the same with that subagent's rows, and has no turn-state badges. @@ -193,8 +204,8 @@ A terminal's own tab takes the agent's icon as its browser-tab icon, so tabs of different agents tell apart. A subagent's tab shows its agent's icon. An agent with no icon keeps the hyperhive mark. Everywhere else the swarm UI shows an agent's icon (the cards, the pickers, the badges), an agent with none shows the default agent icon. -The tab also has an agent badge, with the agent's icon and name, ahead of the -connection badge. It opens the agent's details in a popover under the badge: +The tab also has an agent badge, with the agent's icon (carrying the connection +light) and name, ahead of the state badges. It opens the agent's details in a popover under the badge: the same status, state, wanted state and folded **status** and **settings** sections (inference, resource caps, internet, allowed domains, permissions and linked accounts) as the opened card on `/agents`, without the terminal and subagents. The popover doesn't dim the page. Selecting outside it, or Escape, closes it. From the keyboard, opening a @@ -210,9 +221,9 @@ another agent's terminal tab from the header onto the left, right, top or bottom half of a terminal: the half it would take lights up, and the drop makes a group of the two, with its own header tab at `/agents/group/`. In a group, the same drag onto a pane splits that pane, as many times as you like, and -dragging a pane's header badge onto another pane moves it there. The **split** -button in a pane's header does the same for an agent whose terminal tab is open: -**right** or **below** puts it beside the pane. A pane can hold a subagent's +dragging a pane's header badge onto another pane moves it there. A tab you can +drag shows a grip at its left edge when the pointer is over it, and its tooltip +reads "drag onto a terminal to split it." A pane can hold a subagent's terminal (its header reads `agent/subagent`), put there by the **subagents** badge in the pane's header. Two icon buttons sit in a pane's top right corner. **Maximize** (the arrows pointing to the corners) opens that pane's own terminal diff --git a/frontend/packages/shared/src/badge/Badge.tsx b/frontend/packages/shared/src/badge/Badge.tsx index 36e010311..391f4012a 100644 --- a/frontend/packages/shared/src/badge/Badge.tsx +++ b/frontend/packages/shared/src/badge/Badge.tsx @@ -75,6 +75,11 @@ export interface BadgeProps { disabled?: boolean; class?: string; title?: string; + /** + * The accessible name, when the visible text is not enough of one: a badge that + * is an icon and a number, say. + */ + ariaLabel?: string; } export function Badge({ @@ -88,6 +93,7 @@ export function Badge({ disabled, class: extraClass, title, + ariaLabel, }: 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 @@ -123,6 +129,7 @@ export function Badge({ onClick={onClick} disabled={disabled} aria-expanded={expanded} + aria-label={ariaLabel} title={title} > {content} @@ -130,7 +137,7 @@ export function Badge({ ); } return ( - + {content} ); diff --git a/frontend/packages/shared/src/icons.tsx b/frontend/packages/shared/src/icons.tsx index 22deb364c..4eca7592e 100644 --- a/frontend/packages/shared/src/icons.tsx +++ b/frontend/packages/shared/src/icons.tsx @@ -19,6 +19,8 @@ // when `SettingsMenu` was extracted into `@hive/shared`, undoing this // fix — restoring the SVG here, in the shared component this time, // fixes it for both pages at once instead of just one). +import type { ComponentChildren } from "preact"; + export function GearIcon() { return ( ); } + +// The shared recipe of the line icons below: a 24-unit box, round strokes in +// the text colour, so each reads as part of the same family. +function LineIcon({ children }: { children: ComponentChildren }) { + return ( + + ); +} + +/** A chip with pins: the model an agent runs on. */ +export function ChipIcon() { + return ( + + + + + + ); +} + +/** A dial: how full the context window is. */ +export function GaugeIcon() { + return ( + + + + + + ); +} + +/** One node branching into two: the subagents an agent started. */ +export function SubagentsIcon() { + return ( + + + + + + + ); +} + +/** Six dots in two columns: the handle of something that can be dragged. */ +export function GripIcon() { + return ( + + ); +} diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentStateRow.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentStateRow.tsx index 2ad637980..33695c663 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentStateRow.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentStateRow.tsx @@ -22,7 +22,6 @@ export function AgentStateRow({ agent }: { agent: string }) { ) : ( diff --git a/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx b/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx index 1560b1858..8646d015b 100644 --- a/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx +++ b/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx @@ -1,7 +1,8 @@ import { Badge, type BadgeTone } from "@hive/shared/badge.js"; +import { ChipIcon, GaugeIcon } from "@hive/shared/icons.js"; import { BadgePopover } from "../../ui/badge-popover/BadgePopover.js"; import { AgentInference } from "../detail/AgentInference.js"; -import { effortTitle, modelTitle } from "./badge-titles.js"; +import { inferenceTitle } from "./badge-titles.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import { useSwarmAgentStateStream, @@ -42,24 +43,25 @@ function fmtTokens(n: number): string { return String(n); } -// Turn state, agent state, model, ctx and cost, as the badges beside the -// connection one. Siblings only, no wrapper: they sit in the caller's row. +// Turn state, agent state, the model with its effort, and the context size, as +// the badges beside the connection one. Siblings only, no wrapper: they sit in +// the caller's row. The model and the effort are one badge, "opus (high)", and +// there is no cost badge: the cost is a metric in Grafana. export function StateBadges({ header, ctx, - cost, withModel = true, agent, }: { header: NonNullable["header"]>; ctx: number | null; - cost: number | null; // Off where the model is shown beside them, as in the details table. withModel?: boolean; - // The agent whose settings the model and effort badges open in a popover - // when clicked. Omitted: the badges only display. + // The agent whose settings the model badge opens in a popover when clicked. + // Omitted: the badge only displays. agent?: string; }) { + const model = `${header.model} (${header.effort})`; return ( <> } + value={model} + title={inferenceTitle( + header.resolved_model, + header.effort_source, + false, + )} + ariaLabel={`model ${model}`} /> ) : ( - - - ))} - {withModel && - (agent === undefined ? ( - - ) : ( - } + value={model} + title={inferenceTitle( + header.resolved_model, + header.effort_source, + true, + )} + ariaLabel={`model ${model}`} popoverLabel={`${agent} inference settings`} > @@ -118,16 +113,10 @@ export function StateBadges({ ))} {ctx !== null && ( } value={fmtTokens(ctx)} title="tokens used in the current context window" - /> - )} - {cost !== null && ( - )} diff --git a/frontend/packages/swarm-ui/src/agent/state/badge-titles.ts b/frontend/packages/swarm-ui/src/agent/state/badge-titles.ts index 0652a13f5..48c67102d 100644 --- a/frontend/packages/swarm-ui/src/agent/state/badge-titles.ts +++ b/frontend/packages/swarm-ui/src/agent/state/badge-titles.ts @@ -1,22 +1,19 @@ -// The tooltips of the model and effort badges in an agent's terminal header. -// Clickable ones, which open the agent's inference settings, say so; the plain -// ones, on a subagent's terminal and in the details table, only say where the -// value comes from. +// The tooltip of the model badge in an agent's terminal header, which names the +// model and the effort together. A clickable one, which opens the agent's +// inference settings, says so; the plain one, on a subagent's terminal and in +// the details table, only says where the values come from. const OPENS = "Click for the inference settings"; -/** The model badge's tooltip: what the alias resolved to, when known. */ -export function modelTitle( +/** + * What the alias resolved to, when known, and where the effort comes from. + */ +export function inferenceTitle( resolvedModel: string | null | undefined, + effortSource: string, clickable: boolean, -): string | undefined { - const resolved = resolvedModel ? `resolved to ${resolvedModel}` : undefined; - if (!clickable) return resolved; - return resolved ? `${resolved}. ${OPENS}` : OPENS; -} - -/** The effort badge's tooltip: where the effort comes from. */ -export function effortTitle(source: string, clickable: boolean): string { - const from = `set by: ${source}`; +): string { + const resolved = resolvedModel ? `resolved to ${resolvedModel}; ` : ""; + const from = `${resolved}effort set by: ${effortSource}`; return clickable ? `${from}. ${OPENS}` : from; } diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css index ed403a3cc..ddcaf18f3 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.css @@ -79,13 +79,13 @@ this: with the base padding, "thinking"/"model sonnet" sat directly on top of the terminal's first line whenever content started right at the top (a running preview scrolled to the newest rows almost - always does). One badge row: the connection badge and the expand + always does). One badge row: the connection light and the expand trigger, each keeping the 2.75em touch-target floor. */ padding-block-start: 3.4em; } -/* The floating row over the terminal's top edge: the connection badge - (and on the full tab turn_state/agent_state/model/ctx/cost) on the left, the +/* The floating row over the terminal's top edge: the connection light + (and on the full tab turn_state/agent_state/model/ctx) on the left, the expand trigger on the right. Positioned by `.terminal-wrap`'s own `position: relative`, same anchor `@hive/shared/terminal.css`'s `.tail-pill` uses, which anchors bottom-right and so never competes for diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx index 5759dd90e..dc8149b8b 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentTermPreview.tsx @@ -8,7 +8,7 @@ // component the per-hive local terminal uses — "share components between hive and swarm level // term as much as possible" (mara). // -// **Floating header badges** — turn state / model / ctx / cost parity +// **Floating header badges** — turn state / model / ctx parity // with the per-agent page's own `StatusChips` — mara: "dont make it a // header though - make it floating elements on top of the terminal", so // this is a small `Badge` cluster pinned to the terminal box's own @@ -18,7 +18,7 @@ // has its own control surface (`WantedMenu` on `AgentsPage`), so nothing // here needs to be interactive. Sourced from `useSwarmAgentStateStream`, // not from `AgentRow` — the roster fetch `AgentsPage` already did has no -// notion of turn_state/model/ctx/cost, only `wanted`/`snapshot.running`. +// notion of turn_state/model/ctx, only `wanted`/`snapshot.running`. // Only the full-tab mount (`fullHeight`) shows the state badges: the small // preview in an opened card stays free of them (mara: "the preview is small // and should not be encroached further with badges on top, but for the full @@ -34,7 +34,7 @@ // already IS the destination, so it has nothing further to expand to. import { useLayoutEffect, useRef, useState } from "preact/hooks"; import type { ComponentChildren } from "preact"; -import { Badge, type BadgeTone } from "@hive/shared/badge.js"; +import { Badge } from "@hive/shared/badge.js"; import { ExpandIcon } from "@hive/shared/icons.js"; import { Row } from "@hive/shared/term-row.js"; import { useDynamicTabs } from "../../shell/useDynamicTabs.js"; @@ -45,26 +45,13 @@ import { import { useSwarmAgentStateStream } from "./useSwarmAgentStateStream.js"; import { termPaths } from "./term-paths.js"; import { StateBadges, tokenTotal } from "../state/StateBadges.js"; +import { CONNECTION_LABEL, ConnectionDot } from "./ConnectionDot.js"; import { AgentInputForm } from "./AgentInputForm.js"; import { CancelTurnBadge } from "./CancelTurnBadge.js"; import "./AgentTermPreview.css"; const NEAR_BOTTOM_PX = 48; -const CONNECTION_LABEL: Record = { - connecting: "connecting…", - open: "live", - reconnecting: "reconnecting…", - closed: "disconnected", -}; - -const CONNECTION_TONE: Record = { - connecting: "neutral", - open: "positive", - reconnecting: "warning", - closed: "negative", -}; - export function AgentTermPreview({ agentName, subagent, @@ -79,9 +66,10 @@ export function AgentTermPreview({ // The full-tab mount: fills the tab, has no expand trigger, and shows the // agent's state badges beside the connection one. fullHeight?: boolean; - // A badge ahead of the connection badge, for the full-tab mount's - // link back to the agent's details. - leading?: ComponentChildren; + // The badges ahead of the state ones, for the full-tab mount's link back to + // the agent's details. Given the connection, which it shows as a light on the + // name badge. Without it the connection is a light of its own. + leading?: (connection: ConnectionState) => ComponentChildren; // Icon-only badges in the top right corner, for the full-tab mount's own // controls (a group pane's maximize and close). trailing?: ComponentChildren; @@ -98,7 +86,6 @@ export function AgentTermPreview({ const [stickToBottom, setStickToBottom] = useState(true); const ctx = header ? tokenTotal(header.ctx_usage) : null; - const cost = header ? tokenTotal(header.cost_usage) : null; function handleScroll() { const el = logRef.current; @@ -130,11 +117,11 @@ export function AgentTermPreview({ it has no expand trigger. */}
- {leading} - + {leading ? ( + leading(connection) + ) : ( + + )} {connection === "closed" && ( )} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx b/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx index ef3ddf86c..0e3cd283e 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx @@ -8,12 +8,31 @@ import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; import { Hint } from "../../ui/hint/Hint.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; -import { isLive, runningTasksLabel, stateWord } from "./bash-tasks.js"; +import type { ProblemDetails } from "@hive/shared/api-error.js"; +import { + isLive, + runningTasksLabel, + stateWord, + type BashTask, +} from "./bash-tasks.js"; import { useBashTasks } from "./useBashTasks.js"; import "./BashTasks.css"; export function BashTasks({ agentName }: { agentName: string }) { const { tasks, error } = useBashTasks(agentName); + return ; +} + +/** The list for a fetch already made, so a badge and its popover share one poll. */ +export function BashTasksList({ + agentName, + tasks, + error, +}: { + agentName: string; + tasks: BashTask[] | null; + error: ProblemDetails | null; +}) { return (
{error && ( diff --git a/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx b/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx new file mode 100644 index 000000000..0e079f41a --- /dev/null +++ b/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx @@ -0,0 +1,52 @@ +// — the agent's background bash tasks as a badge in the terminal +// header: a prompt icon and the number running, and the list of tasks (the same +// one the agent card's "background tasks" section shows) in a popover under it. +// Nothing shows for an agent with no tasks, and nothing before the first answer; +// a failed fetch shows its reason in the open list. +import { useRef, useState } from "preact/hooks"; +import { Badge } from "@hive/shared/badge.js"; +import { TerminalIcon } from "@hive/shared/icons.js"; +import { Panel } from "../../ui/panel/Panel.js"; +import { Popover } from "../../ui/popover/Popover.js"; +import { BashTasksList } from "./BashTasks.js"; +import { isLive, runningTasksLabel } from "./bash-tasks.js"; +import { useBashTasks } from "./useBashTasks.js"; + +export function BashTasksMenu({ agentName }: { agentName: string }) { + const { tasks, error } = useBashTasks(agentName); + const [open, setOpen] = useState(false); + const anchorRef = useRef(null); + + if (!error && (tasks === null || tasks.length === 0)) return null; + + const running = (tasks ?? []).filter(isLive).length; + const label = runningTasksLabel(tasks ?? []); + return ( + <> + + } + value={running} + tone={running > 0 ? "positive" : "neutral"} + ariaLabel={label} + title={`${label}: ${open ? "close" : "open"} ${agentName}'s bash tasks`} + expanded={open} + onClick={() => setOpen((o) => !o)} + /> + + setOpen(false)} + anchorRef={anchorRef} + label={`${agentName}'s bash tasks`} + > + setOpen(false)} + > + + + + + ); +} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.css b/frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.css new file mode 100644 index 000000000..a91202527 --- /dev/null +++ b/frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.css @@ -0,0 +1,47 @@ +.ui-conn-dot { + display: inline-block; + width: 0.65em; + height: 0.65em; + flex: none; + border-radius: 50%; + background: var(--muted); + box-shadow: 0 0 0 2px color-mix(in srgb, var(--bg) 70%, transparent); +} +.ui-conn-dot-open { + background: var(--green); + box-shadow: + 0 0 0 2px color-mix(in srgb, var(--bg) 70%, transparent), + 0 0 6px var(--green); +} +.ui-conn-dot-connecting, +.ui-conn-dot-reconnecting { + background: var(--amber); +} +.ui-conn-dot-closed { + background: var(--red); +} +/* On the corner of the icon: the light sits half over its bottom-right edge. */ +.ui-live-icon { + position: relative; + display: inline-flex; +} +.ui-conn-dot-on-icon { + position: absolute; + right: -0.2em; + bottom: -0.2em; +} +@media (prefers-reduced-motion: no-preference) { + .ui-conn-dot-connecting, + .ui-conn-dot-reconnecting { + animation: ui-conn-dot-pulse 1.2s ease-in-out infinite; + } +} +@keyframes ui-conn-dot-pulse { + 50% { + opacity: 0.45; + } +} +/* Alone in a terminal's top corner, with room around it. */ +.ui-agent-term-preview-controls .ui-conn-dot:not(.ui-conn-dot-on-icon) { + margin: 0.55em 0 0 0.55em; +} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.tsx b/frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.tsx new file mode 100644 index 000000000..5555fe7f5 --- /dev/null +++ b/frontend/packages/swarm-ui/src/agent/terminal/ConnectionDot.tsx @@ -0,0 +1,52 @@ +// The connection of a terminal's stream as an indicator light: green when it is +// live, amber while it connects or reconnects, red when it is closed. It says +// what the "live" badge said, in less room. Beside an agent's name it sits on the +// corner of the name badge's icon (`LiveAgentIcon`); alone, it stands for the +// connection badge of a terminal that has no name badge. +import { AgentIcon } from "../AgentIcon.js"; +import type { ConnectionState } from "./useSwarmTermStream.js"; +import "./ConnectionDot.css"; + +export const CONNECTION_LABEL: Record = { + connecting: "connecting…", + open: "live", + reconnecting: "reconnecting…", + closed: "disconnected", +}; + +export function ConnectionDot({ + connection, + onIcon = false, +}: { + connection: ConnectionState; + /** Drawn on the corner of an icon rather than as a light of its own. */ + onIcon?: boolean; +}) { + return ( + + ); +} + +/** An agent's icon with the connection light on its corner. */ +export function LiveAgentIcon({ + name, + connection, +}: { + name: string; + connection: ConnectionState; +}) { + return ( + + + + + ); +} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/SubagentsMenu.tsx b/frontend/packages/swarm-ui/src/agent/terminal/SubagentsMenu.tsx index 962b32ac3..67c9e25ac 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/SubagentsMenu.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/SubagentsMenu.tsx @@ -1,5 +1,5 @@ -// — "N running subagents" in the full-screen terminal page's -// header: a badge that opens a list of the agent's subagents, each a link to +// — a branching icon and the number of running subagents in the +// full-screen terminal page's header: a badge that opens a list of the agent's subagents, each a link to // its own terminal page. On a subagent's page the current one is marked and the // list starts with a way back to the agent's own terminal. The list is the // same `GET /api/agents/{name}/subagents` as the one under the preview, and @@ -17,6 +17,7 @@ import { useRef, useState } from "preact/hooks"; import { Link } from "wouter-preact"; import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; import { Badge } from "@hive/shared/badge.js"; +import { SubagentsIcon } from "@hive/shared/icons.js"; import { Panel } from "../../ui/panel/Panel.js"; import { Popover } from "../../ui/popover/Popover.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; @@ -121,9 +122,11 @@ export function SubagentsMenu({ <> } + value={running.length} tone={running.length > 0 ? "positive" : "neutral"} - title={`${open ? "close" : "open"} ${agentName}'s subagents`} + ariaLabel={runningLabel(running.length)} + title={`${runningLabel(running.length)}: ${open ? "close" : "open"} ${agentName}'s subagents`} expanded={open} onClick={() => setOpen((o) => !o)} /> diff --git a/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.css b/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.css index 635534261..030db1d2c 100644 --- a/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.css +++ b/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.css @@ -11,25 +11,6 @@ .ui-agent-group-grip { cursor: grab; } -.ui-agent-group-menu { - list-style: none; - margin: 0; - padding: 0; - display: grid; - gap: 0.4em; -} -.ui-agent-group-menu li { - display: flex; - align-items: center; - gap: 0.5em; -} -.ui-agent-group-menu-name { - flex: 1; -} -.ui-agent-group-menu-empty { - margin: 0; - max-width: 22em; -} .ui-agent-group-missing { padding: 2em; } diff --git a/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx b/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx index 876701e8d..100b6cf03 100644 --- a/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/agents/AgentGroupPage.tsx @@ -13,9 +13,10 @@ import { useEffect } from "preact/hooks"; import { useLocation, type RouteComponentProps } from "wouter-preact"; import { Badge } from "@hive/shared/badge.js"; import { CloseIcon, ExpandIcon } from "@hive/shared/icons.js"; -import { AgentIcon } from "../../agent/AgentIcon.js"; import { SubagentsMenu } from "../../agent/terminal/SubagentsMenu.js"; import { AgentTermPreview } from "../../agent/terminal/AgentTermPreview.js"; +import { BashTasksMenu } from "../../agent/terminal/BashTasksMenu.js"; +import { LiveAgentIcon } from "../../agent/terminal/ConnectionDot.js"; import { termPaths } from "../../agent/terminal/term-paths.js"; import { agentsIn, @@ -27,54 +28,16 @@ import { resizeAt, splitKey, splitPane, - terminalAgentOf, - type Side, } from "../../agent/terminal/split-layout.js"; import { endAgentDrag, startAgentDrag } from "../../agent/terminal/termDrag.js"; import { fetchJson, usePolled } from "../../ui/polled/usePolled.js"; import { useTermGroups } from "../../agent/terminal/useTermGroups.js"; import { useDynamicTabs } from "../../shell/useDynamicTabs.js"; -import { BadgePopover } from "../../ui/badge-popover/BadgePopover.js"; import { Button } from "../../ui/button/Button.js"; import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js"; import { PaneTree } from "../../ui/pane-tree/PaneTree.js"; import "./AgentGroupPage.css"; -// The split menu of a pane: the agents whose terminal tab is open and that are -// not in the group yet, each to be put beside this pane on the right or below. -function SplitMenu({ - candidates, - onSplit, -}: { - candidates: string[]; - onSplit: (agent: string, side: Side) => void; -}) { - return ( - - {candidates.length === 0 ? ( -

- Open another agent's terminal tab first, then split it in here, or - drag its tab onto a pane. -

- ) : ( -
    - {candidates.map((agent) => ( -
  • - {agent} - - -
  • - ))} -
- )} -
- ); -} - export function AgentGroupPage({ params, }: RouteComponentProps<{ id: string }>) { @@ -82,7 +45,7 @@ export function AgentGroupPage({ const href = groupHref(id); const groups = useTermGroups(); const group = groups.find(id); - const { tabs, open, close } = useDynamicTabs(); + const { open, close } = useDynamicTabs(); const [, navigate] = useLocation(); const inGroup = group === undefined ? [] : agentsIn(group.root); @@ -134,10 +97,6 @@ export function AgentGroupPage({ ); } - const candidates = tabs - .map((t) => terminalAgentOf(t.href)) - .filter((a): a is string => a !== null && !inGroup.includes(a)); - // `key` is the pane's key: its agent, or `agent/subagent` for a subagent's. function renderPane(key: string) { const { agent, subagent } = splitKey(key); @@ -152,7 +111,7 @@ export function AgentGroupPage({ agentName={agent} subagent={subagent} fullHeight - leading={ + leading={(connection) => ( <> startAgentDrag(e, key)} onDragEnd={endAgentDrag} > - } value={key} /> + } + value={key} + /> - - groups.update(id, (r) => splitPane(r, key, other, side)) - } - /> + {subagent === undefined && ( + + )} - } + )} trailing={ <> ( <> } + icon={} value={name} title={`${detailOpen ? "close" : "open"} ${name}'s details`} expanded={detailOpen} @@ -93,8 +94,11 @@ export function AgentTerminalPage({ open({ href: groupHref(group.id), label: groupTitle(group) }); }} /> + {subagent === undefined && ( + + )} - } + )} /> ); diff --git a/frontend/packages/swarm-ui/src/shell/Shell.css b/frontend/packages/swarm-ui/src/shell/Shell.css index 58b196316..661889cda 100644 --- a/frontend/packages/swarm-ui/src/shell/Shell.css +++ b/frontend/packages/swarm-ui/src/shell/Shell.css @@ -200,6 +200,33 @@ .shell-tab-active { border-color: var(--pink); } +/* A tab that can be dragged onto a terminal to split it shows a grip in a gutter + of its own on hover, so the drag is discoverable. The gutter is part of the + padding, so the tab does not change size when the grip appears. */ +.shell-tab-draggable { + position: relative; + padding-left: 1.3em; + cursor: grab; +} +.shell-tab-grip { + position: absolute; + left: 0.35em; + top: 50%; + display: inline-flex; + color: var(--muted); + opacity: 0; + transform: translateY(-50%); + transition: opacity 0.15s ease; + pointer-events: none; +} +.shell-tab-draggable:hover .shell-tab-grip { + opacity: 0.9; +} +@media (prefers-reduced-motion: reduce) { + .shell-tab-grip { + transition: none; + } +} .shell-tab-link { color: var(--muted); text-decoration: none; diff --git a/frontend/packages/swarm-ui/src/shell/Shell.tsx b/frontend/packages/swarm-ui/src/shell/Shell.tsx index 94d43eac1..b625e8a00 100644 --- a/frontend/packages/swarm-ui/src/shell/Shell.tsx +++ b/frontend/packages/swarm-ui/src/shell/Shell.tsx @@ -35,6 +35,7 @@ import { useHideDebug } from "./useHideDebug.js"; import { SettingsMenu } from "@hive/shared/settings-menu.js"; import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js"; import { ShowThinkingSetting } from "@hive/shared/show-thinking-setting.js"; +import { GripIcon } from "@hive/shared/icons.js"; import { ExpandDetailsSetting } from "@hive/shared/expand-details-setting.js"; import { useApplyThemeOverride } from "@hive/shared/theme-apply.js"; import { useApplyMotionOverride } from "@hive/shared/motion-apply.js"; @@ -174,13 +175,25 @@ function DynamicTabLink({ const [editing, setEditing] = useState(false); return ( startAgentDrag(e, agent) } onDragEnd={agent === undefined ? undefined : endAgentDrag} > + {agent !== undefined && ( + + )} {editing && onRename !== undefined ? ( setOpen((o) => !o)} /> diff --git a/frontend/packages/swarm-ui/test/badge-titles.test.mjs b/frontend/packages/swarm-ui/test/badge-titles.test.mjs index 6a5323470..f9c61b38b 100644 --- a/frontend/packages/swarm-ui/test/badge-titles.test.mjs +++ b/frontend/packages/swarm-ui/test/badge-titles.test.mjs @@ -1,27 +1,28 @@ -// The model and effort badge tooltips. Run by `npm test`, which Node runs with -// its built-in test runner and type stripping. +// The model badge's tooltip. Run by `npm test`, which Node runs with its +// built-in test runner and type stripping. import assert from "node:assert/strict"; import { test } from "node:test"; -import { effortTitle, modelTitle } from "../src/agent/state/badge-titles.ts"; +import { inferenceTitle } from "../src/agent/state/badge-titles.ts"; -test("a plain model badge says what the alias resolved to, or nothing", () => { - assert.equal(modelTitle("claude-x-1", false), "resolved to claude-x-1"); - assert.equal(modelTitle(undefined, false), undefined); - assert.equal(modelTitle("", false), undefined); -}); - -test("a clickable model badge says it opens the settings", () => { +test("the tooltip says what the alias resolved to and where the effort comes from", () => { assert.equal( - modelTitle("claude-x-1", true), - "resolved to claude-x-1. Click for the inference settings", + inferenceTitle("claude-x-1", "swarm", false), + "resolved to claude-x-1; effort set by: swarm", ); - assert.equal(modelTitle(undefined, true), "Click for the inference settings"); }); -test("the effort badge names its source and, when clickable, the click", () => { - assert.equal(effortTitle("swarm", false), "set by: swarm"); +test("an alias that did not resolve leaves that part out", () => { + for (const resolved of [undefined, null, ""]) { + assert.equal( + inferenceTitle(resolved, "default", false), + "effort set by: default", + ); + } +}); + +test("a clickable badge says it opens the settings", () => { assert.equal( - effortTitle("swarm", true), - "set by: swarm. Click for the inference settings", + inferenceTitle("claude-x-1", "swarm", true), + "resolved to claude-x-1; effort set by: swarm. Click for the inference settings", ); });