Watch
0
0
Fork
You've already forked hyperhive
0

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.
This commit is contained in:
iris 2026-11-23 18:14:26 +01:00
commit ef4c9214f7
9 changed files with 271 additions and 88 deletions

View file

@ -195,7 +195,9 @@ starts open, the other five folded:
Its open todos from `GET /api/agents/<name>/todos`, newest first, each with Its open todos from `GET /api/agents/<name>/todos`, newest first, each with
its subsystem, one line of text and how long ago it changed (read only, 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 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. - **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 - **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 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 **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. 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 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 with the same name starts unpicked. The list is one row per subagent, as in the
and effort it runs, like `opus · high`, beside its name; one on the default terminal page's menu: its name, the model and effort it runs, like `opus · high`
model shows only the effort. The `/agents/<name>/terminal` page's subagent list (one on the default model shows only the effort), and its state with an age. The
shows them too. 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/<name>/terminal`
page's subagent list shows them too.
The preview carries only a small connection light and **expand**, so it stays 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, clear of the text. What the agent is doing shows in the identity card above it,

View file

@ -5,6 +5,7 @@
// //
// Mount it keyed by agent name: the refresh timer is armed once per mount. // Mount it keyed by agent name: the refresh timer is armed once per mount.
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; 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 { Hint } from "../../ui/hint/Hint.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
import { todosLabel } from "./agent-todos.js"; import { todosLabel } from "./agent-todos.js";
@ -30,19 +31,23 @@ export function AgentTodos({ agentName }: { agentName: string }) {
) : ( ) : (
<> <>
<p class="ui-agent-todos-count">{todosLabel(todos)}</p> <p class="ui-agent-todos-count">{todosLabel(todos)}</p>
<ul class="ui-agent-todos-list"> <CappedRows rows={todos} noun="todos">
{todos.map((t) => ( {(shown) => (
<li key={t.id} class="ui-agent-todos-item"> <ul class="ui-agent-todos-list">
<span class="ui-agent-todos-subsystem">{t.subsystem}</span> {shown.map((t) => (
<span class="ui-agent-todos-summary" title={t.summary}> <li key={t.id} class="ui-agent-todos-item">
{t.summary} <span class="ui-agent-todos-subsystem">{t.subsystem}</span>
</span> <span class="ui-agent-todos-summary" title={t.summary}>
<span class="ui-agent-todos-age"> {t.summary}
<RelativeTime epochMs={t.updated_unix * 1000} /> </span>
</span> <span class="ui-agent-todos-age">
</li> <RelativeTime epochMs={t.updated_unix * 1000} />
))} </span>
</ul> </li>
))}
</ul>
)}
</CappedRows>
</> </>
)} )}
</section> </section>

View file

@ -6,6 +6,7 @@
// //
// Mount it keyed by agent name: the refresh timer is armed once per mount. // Mount it keyed by agent name: the refresh timer is armed once per mount.
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; 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 { Hint } from "../../ui/hint/Hint.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
import type { ProblemDetails } from "@hive/shared/api-error.js"; import type { ProblemDetails } from "@hive/shared/api-error.js";
@ -50,28 +51,32 @@ export function BashTasksList({
) : ( ) : (
<> <>
<p class="ui-bash-tasks-count">{runningTasksLabel(tasks)}</p> <p class="ui-bash-tasks-count">{runningTasksLabel(tasks)}</p>
<ul class="ui-bash-tasks-list"> <CappedRows rows={tasks} noun="tasks">
{tasks.map((t) => ( {(shown) => (
<li <ul class="ui-bash-tasks-list">
key={t.task} {shown.map((t) => (
class={`ui-bash-tasks-item${isLive(t) ? "" : " ui-bash-tasks-item-over"}`} <li
> key={t.task}
<code class="ui-bash-tasks-cmd" title={t.cmd}> class={`ui-bash-tasks-item${isLive(t) ? "" : " ui-bash-tasks-item-over"}`}
{t.cmd} >
</code> <code class="ui-bash-tasks-cmd" title={t.cmd}>
<span class="ui-bash-tasks-id">{t.task}</span> {t.cmd}
<span class="ui-bash-tasks-age"> </code>
{stateWord(t)} <span class="ui-bash-tasks-id">{t.task}</span>
{t.state === "stale" ? null : ( <span class="ui-bash-tasks-age">
<> {stateWord(t)}
{" "} {t.state === "stale" ? null : (
<RelativeTime epochMs={t.since_unix * 1000} /> <>
</> {" "}
)} <RelativeTime epochMs={t.since_unix * 1000} />
</span> </>
</li> )}
))} </span>
</ul> </li>
))}
</ul>
)}
</CappedRows>
</> </>
)} )}
</section> </section>

View file

@ -1,31 +1,58 @@
/* <SubagentTerms> — one row of subagent names under the agent's own /* <SubagentTerms> — an agent's subagents as rows under its own terminal
terminal preview; the picked subagent's preview sits below it. */ preview, the way the menu on the terminal page lists them; the picked
subagent's preview sits below. */
.ui-subagent-terms { .ui-subagent-terms {
margin-block-start: 1rem; margin-block-start: 1rem;
} }
.ui-subagent-terms-count {
margin: 0 0 0.5em;
color: var(--muted);
}
.ui-subagent-terms-list { .ui-subagent-terms-list {
display: flex; display: flex;
flex-wrap: wrap; flex-direction: column;
align-items: center; margin: 0;
gap: 0.5em; padding: 0;
list-style: none;
} }
.ui-subagent-terms-item { .ui-subagent-terms-item {
display: inline-flex; display: grid;
align-items: center; grid-template-columns: minmax(0, 1fr) auto auto;
gap: 0.35em; 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 { .ui-subagent-terms-item-stale {
opacity: 0.6; opacity: 0.6;
} }
.ui-subagent-terms-name {
overflow-wrap: anywhere;
}
.ui-subagent-terms-age { .ui-subagent-terms-age {
color: var(--muted); color: var(--muted);
font-size: 0.85em; font-size: 0.85em;
} white-space: nowrap;
.ui-subagent-terms-heading {
color: var(--muted);
} }

View file

@ -11,12 +11,14 @@
// Mount it keyed by agent name: the refresh timer is armed once per mount. // Mount it keyed by agent name: the refresh timer is armed once per mount.
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; 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 { AgentTermPreview } from "./AgentTermPreview.js";
import { import {
isDimmed, isDimmed,
ageUnix, ageUnix,
runLabel, runLabel,
runningLabel,
splitRunning,
stateLabel, stateLabel,
stillListed, stillListed,
} from "./subagent-list.js"; } from "./subagent-list.js";
@ -43,44 +45,66 @@ export function SubagentTerms({ agentName }: { agentName: string }) {
if (!error && (subagents === null || subagents.length === 0)) return null; if (!error && (subagents === null || subagents.length === 0)) return null;
const nowS = Date.now() / 1000; 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 ( return (
<section class="ui-subagent-terms" aria-label={`${agentName}'s subagents`}> <section class="ui-subagent-terms" aria-label={`${agentName}'s subagents`}>
<div class="ui-subagent-terms-list"> {subagents !== null && rows.length > 0 && (
<span class="ui-subagent-terms-heading">subagents</span> <>
{subagents?.map((sub) => { <p class="ui-subagent-terms-count">
const { name } = sub; {runningLabel(running.length)}
const runs = runLabel(sub); {quiet.length > 0 ? `, ${quiet.length} not running` : ""}
const active = ageUnix(sub); </p>
const status = stateLabel(sub); <CappedRows
const stale = isDimmed(sub, nowS); rows={rows}
return ( keep={(s) => s.name === selected}
<span noun="subagents"
key={name} >
class={`ui-subagent-terms-item${stale ? " ui-subagent-terms-item-stale" : ""}`} {(shown) => (
> <ul class="ui-subagent-terms-list">
<Badge {shown.map((sub) => {
variant={name === selected ? "default" : "quiet"} const { name } = sub;
value={name} const runs = runLabel(sub);
expanded={name === selected} const active = ageUnix(sub);
title={ const status = stateLabel(sub);
name === selected return (
? `hide ${name}'s terminal` <li key={name}>
: `show ${name}'s terminal` <button
} type="button"
onClick={() => setPicked(name === selected ? null : name)} class={`ui-subagent-terms-item${isDimmed(sub, nowS) ? " ui-subagent-terms-item-stale" : ""}`}
/> aria-expanded={name === selected}
{runs && <span class="ui-subagent-terms-age">{runs}</span>} title={
{status && <span class="ui-subagent-terms-age">{status}</span>} name === selected
{active !== null && ( ? `hide ${name}'s terminal`
<span class="ui-subagent-terms-age"> : `show ${name}'s terminal`
<RelativeTime epochMs={active * 1000} /> }
</span> onClick={() =>
)} setPicked(name === selected ? null : name)
</span> }
); >
})} <span class="ui-subagent-terms-name">{name}</span>
</div> <span class="ui-subagent-terms-age">{runs}</span>
<span class="ui-subagent-terms-age">
{status}
{active !== null && (
<>
{status ? " " : ""}
<RelativeTime epochMs={active * 1000} />
</>
)}
</span>
</button>
</li>
);
})}
</ul>
)}
</CappedRows>
</>
)}
{error && ( {error && (
<ApiErrorPanel <ApiErrorPanel
problem={error} problem={error}

View file

@ -0,0 +1,19 @@
/* <CappedRows> — 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;
}

View file

@ -0,0 +1,44 @@
// <CappedRows> — 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<T>({
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 (
<>
<div class={expanded ? "ui-capped-rows ui-capped-rows-open" : undefined}>
{children(shown)}
</div>
{foldable ? (
<button
type="button"
class="ui-capped-rows-toggle"
aria-expanded={expanded}
onClick={() => setExpanded((e) => !e)}
>
{expanded ? "show fewer" : `show all ${rows.length} ${noun}`}
</button>
) : null}
</>
);
}

View file

@ -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<T>(
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 };
}

View file

@ -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);
});