From ef4c9214f7194b45796623c1a8f64ccf8342afc8 Mon Sep 17 00:00:00 2001 From: iris Date: Mon, 23 Nov 2026 18:14:26 +0100 Subject: [PATCH] swarm-ui: fold an agent's long activity lists, and list subagents as rows On a busy agent the activity section grew long: the todos and bash tasks ran to dozens of rows, and the subagents were one wrapping line of badges. Each list now shows its first five rows with a "show all N" button; expanded, the rows scroll in a bounded box. The subagents are one row each (name, model and effort, state and age), running first and the rest dimmed, as in the menu on the terminal page, and a picked subagent stays in view when the list is folded. --- docs/4-implementation/web-ui/swarm-ui.md | 14 ++- .../src/agent/terminal/AgentTodos.tsx | 31 +++--- .../swarm-ui/src/agent/terminal/BashTasks.tsx | 49 +++++----- .../src/agent/terminal/SubagentTerms.css | 51 +++++++--- .../src/agent/terminal/SubagentTerms.tsx | 96 ++++++++++++------- .../src/ui/capped-rows/CappedRows.css | 19 ++++ .../src/ui/capped-rows/CappedRows.tsx | 44 +++++++++ .../swarm-ui/src/ui/capped-rows/cap-rows.ts | 21 ++++ .../packages/swarm-ui/test/cap-rows.test.mjs | 34 +++++++ 9 files changed, 271 insertions(+), 88 deletions(-) create mode 100644 frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.css create mode 100644 frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx create mode 100644 frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts create mode 100644 frontend/packages/swarm-ui/test/cap-rows.test.mjs diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index a0c33f675..e21b3f85c 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -195,7 +195,9 @@ starts open, the other five folded: Its open todos from `GET /api/agents//todos`, newest first, each with its subsystem, one line of text and how long ago it changed (read only, refetched every ten seconds); its subagents and their terminal preview (next - section); and its bash tasks (see the section on them below). + section); and its bash tasks (see the section on them below). Each list + shows its first five rows with a **show all N** button under them; expanded, + the rows scroll inside a box and **show fewer** folds them again. - **instructions**: the agent's AGENTS.md, as an editor you can type in. - **inference**: how the agent thinks and what it costs: its model and effort and the other inference settings, its resource caps, and the claude login and @@ -220,10 +222,12 @@ last 24 hours. Picking one shows its terminal in the same preview, and **expand** opens it in its own tab, as it does for the agent. The list refreshes every 10 seconds, so a subagent the agent spawns shows up once it writes output. A subagent that drops out of the list closes its terminal, and a later subagent -with the same name starts unpicked. 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. +with the same name starts unpicked. The list is one row per subagent, as in the +terminal page's menu: its name, the model and effort it runs, like `opus · high` +(one on the default model shows only the effort), and its state with an age. The +running ones come first, and the rest sit below them, dimmed. A subagent you +picked stays in view even when the rest fold away. The `/agents//terminal` +page's subagent list shows them too. 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 identity card above it, diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentTodos.tsx b/frontend/packages/swarm-ui/src/agent/terminal/AgentTodos.tsx index 9d26c8f08..606fac15b 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentTodos.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentTodos.tsx @@ -5,6 +5,7 @@ // // Mount it keyed by agent name: the refresh timer is armed once per mount. import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; +import { CappedRows } from "../../ui/capped-rows/CappedRows.js"; import { Hint } from "../../ui/hint/Hint.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import { todosLabel } from "./agent-todos.js"; @@ -30,19 +31,23 @@ export function AgentTodos({ agentName }: { agentName: string }) { ) : ( <>

{todosLabel(todos)}

-
    - {todos.map((t) => ( -
  • - {t.subsystem} - - {t.summary} - - - - -
  • - ))} -
+ + {(shown) => ( +
    + {shown.map((t) => ( +
  • + {t.subsystem} + + {t.summary} + + + + +
  • + ))} +
+ )} +
)} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx b/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx index 99ff34e1a..1d6c5624e 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/BashTasks.tsx @@ -6,6 +6,7 @@ // // Mount it keyed by agent name: the refresh timer is armed once per mount. import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; +import { CappedRows } from "../../ui/capped-rows/CappedRows.js"; import { Hint } from "../../ui/hint/Hint.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import type { ProblemDetails } from "@hive/shared/api-error.js"; @@ -50,28 +51,32 @@ export function BashTasksList({ ) : ( <>

{runningTasksLabel(tasks)}

-
    - {tasks.map((t) => ( -
  • - - {t.cmd} - - {t.task} - - {stateWord(t)} - {t.state === "stale" ? null : ( - <> - {" "} - - - )} - -
  • - ))} -
+ + {(shown) => ( +
    + {shown.map((t) => ( +
  • + + {t.cmd} + + {t.task} + + {stateWord(t)} + {t.state === "stale" ? null : ( + <> + {" "} + + + )} + +
  • + ))} +
+ )} +
)} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.css b/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.css index 042803012..94e45fc14 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.css +++ b/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.css @@ -1,31 +1,58 @@ -/* — one row of subagent names under the agent's own - terminal preview; the picked subagent's preview sits below it. */ +/* — an agent's subagents as rows under its own terminal + preview, the way the menu on the terminal page lists them; the picked + subagent's preview sits below. */ .ui-subagent-terms { margin-block-start: 1rem; } +.ui-subagent-terms-count { + margin: 0 0 0.5em; + color: var(--muted); +} + .ui-subagent-terms-list { display: flex; - flex-wrap: wrap; - align-items: center; - gap: 0.5em; + flex-direction: column; + margin: 0; + padding: 0; + list-style: none; } .ui-subagent-terms-item { - display: inline-flex; - align-items: center; - gap: 0.35em; + display: grid; + grid-template-columns: minmax(0, 1fr) auto auto; + align-items: baseline; + gap: 1em; + width: 100%; + padding: 0.35em 0.5em; + border: 0; + border-left: 3px solid transparent; + border-radius: 0.35em; + background: none; + color: inherit; + font: inherit; + text-align: left; + cursor: pointer; +} +.ui-subagent-terms-item:hover, +.ui-subagent-terms-item:focus-visible { + background: var(--bg); +} +.ui-subagent-terms-item[aria-expanded="true"] { + border-left-color: var(--purple); + font-weight: 600; } .ui-subagent-terms-item-stale { opacity: 0.6; } +.ui-subagent-terms-name { + overflow-wrap: anywhere; +} + .ui-subagent-terms-age { color: var(--muted); font-size: 0.85em; -} - -.ui-subagent-terms-heading { - color: var(--muted); + white-space: nowrap; } diff --git a/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.tsx b/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.tsx index b95b1c643..daa3ab2ab 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/SubagentTerms.tsx @@ -11,12 +11,14 @@ // Mount it keyed by agent name: the refresh timer is armed once per mount. import { useEffect, useState } from "preact/hooks"; import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; -import { Badge } from "@hive/shared/badge.js"; +import { CappedRows } from "../../ui/capped-rows/CappedRows.js"; import { AgentTermPreview } from "./AgentTermPreview.js"; import { isDimmed, ageUnix, runLabel, + runningLabel, + splitRunning, stateLabel, stillListed, } from "./subagent-list.js"; @@ -43,44 +45,66 @@ export function SubagentTerms({ agentName }: { agentName: string }) { if (!error && (subagents === null || subagents.length === 0)) return null; const nowS = Date.now() / 1000; + // The running ones first, then the quiet ones dimmed, each newest first, as + // in the menu on the terminal page. + const { running, quiet } = splitRunning(subagents ?? [], nowS); + const rows = [...running, ...quiet]; return (
-
- subagents - {subagents?.map((sub) => { - const { name } = sub; - const runs = runLabel(sub); - const active = ageUnix(sub); - const status = stateLabel(sub); - const stale = isDimmed(sub, nowS); - return ( - - setPicked(name === selected ? null : name)} - /> - {runs && {runs}} - {status && {status}} - {active !== null && ( - - - - )} - - ); - })} -
+ {subagents !== null && rows.length > 0 && ( + <> +

+ {runningLabel(running.length)} + {quiet.length > 0 ? `, ${quiet.length} not running` : ""} +

+ s.name === selected} + noun="subagents" + > + {(shown) => ( +
    + {shown.map((sub) => { + const { name } = sub; + const runs = runLabel(sub); + const active = ageUnix(sub); + const status = stateLabel(sub); + return ( +
  • + +
  • + ); + })} +
+ )} +
+ + )} {error && ( — the button under a folded list, and the bounded scroll box of + an expanded one. */ +.ui-capped-rows-open { + max-height: 18em; + overflow-y: auto; +} +.ui-capped-rows-toggle { + margin-top: 0.4em; + padding: 0; + border: 0; + background: none; + color: var(--blue); + font: inherit; + cursor: pointer; +} +.ui-capped-rows-toggle:hover, +.ui-capped-rows-toggle:focus-visible { + text-decoration: underline; +} diff --git a/frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx b/frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx new file mode 100644 index 000000000..62e4a480a --- /dev/null +++ b/frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx @@ -0,0 +1,44 @@ +// — a list that shows its first few rows and a "show all N" +// button for the rest, so a busy agent's long list doesn't push the rest of the +// details off the screen. Expanded, the rows scroll inside a bounded box. The +// caller draws the rows: it gets the ones to show and puts them in its own +// list element, so each list keeps its own markup and columns. +import type { ComponentChildren } from "preact"; +import { useState } from "preact/hooks"; +import { capRows } from "./cap-rows.js"; +import "./CappedRows.css"; + +export function CappedRows({ + rows, + keep, + noun, + children, +}: { + rows: readonly T[]; + /** Rows that show even while folded, such as the picked one. */ + keep?: (row: T) => boolean; + /** What the rows are, for the button: "show all 12 todos". */ + noun: string; + children: (shown: T[]) => ComponentChildren; +}) { + const [expanded, setExpanded] = useState(false); + const { shown, hidden } = capRows(rows, expanded, keep); + const foldable = expanded || hidden > 0; + return ( + <> +
+ {children(shown)} +
+ {foldable ? ( + + ) : null} + + ); +} diff --git a/frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts b/frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts new file mode 100644 index 000000000..064adc1c7 --- /dev/null +++ b/frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts @@ -0,0 +1,21 @@ +// Which rows of a long list show while it is folded to its first few, without +// a DOM, so the rule can be tested. + +/** How many rows a folded list shows. */ +export const CAP = 5; + +/** + * The rows to draw. Folded, that is the first `cap`, plus any later row `keep` + * names (a picked row must not vanish when the list refreshes and reorders); + * expanded, all of them. `hidden` counts the rows left out. + */ +export function capRows( + rows: readonly T[], + expanded: boolean, + keep: (row: T) => boolean = () => false, + cap: number = CAP, +): { shown: T[]; hidden: number } { + if (expanded || rows.length <= cap) return { shown: [...rows], hidden: 0 }; + const shown = rows.filter((row, i) => i < cap || keep(row)); + return { shown, hidden: rows.length - shown.length }; +} diff --git a/frontend/packages/swarm-ui/test/cap-rows.test.mjs b/frontend/packages/swarm-ui/test/cap-rows.test.mjs new file mode 100644 index 000000000..9a2b0654f --- /dev/null +++ b/frontend/packages/swarm-ui/test/cap-rows.test.mjs @@ -0,0 +1,34 @@ +// Which rows a folded list shows. 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 { CAP, capRows } from "../src/ui/capped-rows/cap-rows.ts"; + +const rows = (n) => Array.from({ length: n }, (_, i) => i); + +test("a list no longer than the cap shows whole", () => { + assert.deepEqual(capRows(rows(CAP), false), { + shown: rows(CAP), + hidden: 0, + }); +}); + +test("a longer list folds to the first rows and counts the rest", () => { + assert.deepEqual(capRows(rows(CAP + 3), false), { + shown: rows(CAP), + hidden: 3, + }); +}); + +test("expanded, every row shows", () => { + assert.deepEqual(capRows(rows(CAP + 3), true), { + shown: rows(CAP + 3), + hidden: 0, + }); +}); + +test("a kept row past the cap still shows, and is not counted as hidden", () => { + const out = capRows(rows(CAP + 3), false, (r) => r === CAP + 1); + assert.deepEqual(out.shown, [...rows(CAP), CAP + 1]); + assert.equal(out.hidden, 2); +});