diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index 5186b1635..2df2cb45c 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -153,6 +153,21 @@ and config PR. While the agent list loads for the first time, the page shows gre placeholder cards with the same layout as the real ones, so the cards don't jump when the data arrives. The placeholders stand still where motion is off. +To act on several agents at once, press the **select** button in the filter +card, select an agent's icon, or press and hold a card (half a second; moving +the pointer cancels it). That turns on select mode: a round tick marks each +card, selecting a card ticks or unticks it instead of opening its details, and +the card's own buttons (terminal, wanted menu, log in) stop answering so a stray +tap can't start or stop an agent. A bar sticks to the foot of the list with the +count, **select all shown** (the agents the filter leaves), **clear**, +**broadcast…** and **done**. **done**, the button in the filter card, or Escape +leaves select mode and forgets the picks. **broadcast…** opens a dialog that +lists the picked agents and a message box, and sends through the same +`POST /api/agents/broadcast` as the broadcast card (see below). When every agent +got the message, a toast says so and select mode ends. Otherwise the dialog +stays with the per-agent result, and **select the N that failed** picks just +those for another send. One broadcast takes at most 64 agents. + Below the agent's state, message and wanted menu, the details have six sections, and each reads nothing until you open it. **status** and **terminal** start open, the other four folded: diff --git a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.css b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.css index 5da145bbd..c4a4ce3f6 100644 --- a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.css +++ b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.css @@ -62,3 +62,68 @@ outline: 2px solid var(--purple); outline-offset: 2px; } + +/* The icon is where a press starts select mode, so it shows the pointer; the tick + sits over its corner while picking. */ +.ui-agent-card-icon { + position: relative; + flex: none; + display: block; + cursor: pointer; +} +.ui-agent-card-row[role="checkbox"] { + cursor: pointer; +} +.ui-agent-card-row[role="checkbox"] .ui-agent-card-icon { + cursor: inherit; +} +.ui-agent-card-tick { + position: absolute; + top: 0.3em; + right: 0.3em; + width: 1.4em; + height: 1.4em; + box-sizing: border-box; + border: 2px solid var(--muted); + border-radius: 50%; + background: color-mix(in srgb, var(--bg) 70%, transparent); + transition: + background-color 0.15s ease, + border-color 0.15s ease, + transform 0.15s ease; +} +.ui-agent-card-tick-on { + border-color: var(--purple); + background: var(--purple); + transform: scale(1.1); +} +/* The check mark inside, drawn with two borders, in the card's own background. */ +.ui-agent-card-tick-on::after { + content: ""; + position: absolute; + left: 0.38em; + top: 0.14em; + width: 0.28em; + height: 0.58em; + border: solid var(--bg); + border-width: 0 2px 2px 0; + transform: rotate(45deg); +} +/* Not a control while picking: the card takes the click. */ +.ui-agent-card-row[role="checkbox"] [inert] { + opacity: 0.55; +} +@media (prefers-reduced-motion: reduce) { + .ui-agent-card-tick { + transition: none; + } +} +:root[data-motion="reduce"] .ui-agent-card-tick { + transition: none; +} +/* A press and hold starts select mode, so it must not also select the text. */ +.ui-agent-card-row { + -webkit-user-select: none; + user-select: none; + -webkit-touch-callout: none; +} diff --git a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx index 759f014f5..fbff2ed3d 100644 --- a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx +++ b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx @@ -5,6 +5,12 @@ // which the page turns into `/agents/`); the card of the open agent is // marked `selected`. // +// In select mode (`select` is set) a choice toggles the card's tick instead, to +// pick several agents for something to do to all of them. A tick on the icon +// shows which are picked; the card's own controls (terminal, wanted menu, login) +// stop answering so a stray tap can't start or stop an agent. Outside select +// mode, a press on the icon, or a long press on the card, starts it (`onStartSelect`). +// // The terminal badge beside the wanted menu opens the agent's terminal tab, the // most common action, without opening the card. // @@ -17,6 +23,7 @@ import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; import { Badge } from "@hive/shared/badge.js"; import { TerminalIcon } from "@hive/shared/icons.js"; import { Card } from "../../ui/card/Card.js"; +import { useLongPress } from "./useLongPress.js"; import { useDynamicTabs } from "../../shell/useDynamicTabs.js"; import { AgentIcon } from "../AgentIcon.js"; import { ClaudeLoginDialog } from "../claude-login/ClaudeLoginDialog.js"; @@ -41,6 +48,8 @@ export function AgentCard({ actions, selected = false, onOpen, + select, + onStartSelect, }: { row: AgentRow; actions: AgentActions; @@ -48,29 +57,63 @@ export function AgentCard({ selected?: boolean; /** Called when the card is chosen, to open the agent's details. */ onOpen: () => void; + /** Set in select mode: whether this agent is picked, and the way to flip it. */ + select?: { picked: boolean; onToggle: () => void }; + /** Called to enter select mode with this agent picked. */ + onStartSelect: () => void; }) { const [loggingIn, setLoggingIn] = useState(false); const error = actions.actionErrors.get(row.name); const { open: openTab } = useDynamicTabs(); const term = termPaths(row.name); + const selecting = select !== undefined; + const choose = selecting ? select.onToggle : onOpen; + const press = useLongPress(onStartSelect, !selecting); + // The controls inside the card do nothing while picking. + const inert = selecting ? { inert: true } : {}; return ( - + { + if (!press.shouldIgnoreClick()) choose(); + }, onKeyDown: (e) => { if (e.target !== e.currentTarget) return; if (e.key === "Enter" || e.key === " ") { e.preventDefault(); - onOpen(); + choose(); } }, + ...press.handlers, }} - icon={} + icon={ + { + if (selecting) return; + e.stopPropagation(); + onStartSelect(); + }} + > + + {selecting ? ( + + } name={{row.name}} status={ <> @@ -116,6 +159,7 @@ export function AgentCard({