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 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/<name>/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/<name>/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,

View file

@ -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 }) {
) : (
<>
<p class="ui-agent-todos-count">{todosLabel(todos)}</p>
<ul class="ui-agent-todos-list">
{todos.map((t) => (
<li key={t.id} class="ui-agent-todos-item">
<span class="ui-agent-todos-subsystem">{t.subsystem}</span>
<span class="ui-agent-todos-summary" title={t.summary}>
{t.summary}
</span>
<span class="ui-agent-todos-age">
<RelativeTime epochMs={t.updated_unix * 1000} />
</span>
</li>
))}
</ul>
<CappedRows rows={todos} noun="todos">
{(shown) => (
<ul class="ui-agent-todos-list">
{shown.map((t) => (
<li key={t.id} class="ui-agent-todos-item">
<span class="ui-agent-todos-subsystem">{t.subsystem}</span>
<span class="ui-agent-todos-summary" title={t.summary}>
{t.summary}
</span>
<span class="ui-agent-todos-age">
<RelativeTime epochMs={t.updated_unix * 1000} />
</span>
</li>
))}
</ul>
)}
</CappedRows>
</>
)}
</section>

View file

@ -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({
) : (
<>
<p class="ui-bash-tasks-count">{runningTasksLabel(tasks)}</p>
<ul class="ui-bash-tasks-list">
{tasks.map((t) => (
<li
key={t.task}
class={`ui-bash-tasks-item${isLive(t) ? "" : " ui-bash-tasks-item-over"}`}
>
<code class="ui-bash-tasks-cmd" title={t.cmd}>
{t.cmd}
</code>
<span class="ui-bash-tasks-id">{t.task}</span>
<span class="ui-bash-tasks-age">
{stateWord(t)}
{t.state === "stale" ? null : (
<>
{" "}
<RelativeTime epochMs={t.since_unix * 1000} />
</>
)}
</span>
</li>
))}
</ul>
<CappedRows rows={tasks} noun="tasks">
{(shown) => (
<ul class="ui-bash-tasks-list">
{shown.map((t) => (
<li
key={t.task}
class={`ui-bash-tasks-item${isLive(t) ? "" : " ui-bash-tasks-item-over"}`}
>
<code class="ui-bash-tasks-cmd" title={t.cmd}>
{t.cmd}
</code>
<span class="ui-bash-tasks-id">{t.task}</span>
<span class="ui-bash-tasks-age">
{stateWord(t)}
{t.state === "stale" ? null : (
<>
{" "}
<RelativeTime epochMs={t.since_unix * 1000} />
</>
)}
</span>
</li>
))}
</ul>
)}
</CappedRows>
</>
)}
</section>

View file

@ -1,31 +1,58 @@
/* <SubagentTerms> — one row of subagent names under the agent's own
terminal preview; the picked subagent's preview sits below it. */
/* <SubagentTerms> — 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;
}

View file

@ -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 (
<section class="ui-subagent-terms" aria-label={`${agentName}'s subagents`}>
<div class="ui-subagent-terms-list">
<span class="ui-subagent-terms-heading">subagents</span>
{subagents?.map((sub) => {
const { name } = sub;
const runs = runLabel(sub);
const active = ageUnix(sub);
const status = stateLabel(sub);
const stale = isDimmed(sub, nowS);
return (
<span
key={name}
class={`ui-subagent-terms-item${stale ? " ui-subagent-terms-item-stale" : ""}`}
>
<Badge
variant={name === selected ? "default" : "quiet"}
value={name}
expanded={name === selected}
title={
name === selected
? `hide ${name}'s terminal`
: `show ${name}'s terminal`
}
onClick={() => setPicked(name === selected ? null : name)}
/>
{runs && <span class="ui-subagent-terms-age">{runs}</span>}
{status && <span class="ui-subagent-terms-age">{status}</span>}
{active !== null && (
<span class="ui-subagent-terms-age">
<RelativeTime epochMs={active * 1000} />
</span>
)}
</span>
);
})}
</div>
{subagents !== null && rows.length > 0 && (
<>
<p class="ui-subagent-terms-count">
{runningLabel(running.length)}
{quiet.length > 0 ? `, ${quiet.length} not running` : ""}
</p>
<CappedRows
rows={rows}
keep={(s) => s.name === selected}
noun="subagents"
>
{(shown) => (
<ul class="ui-subagent-terms-list">
{shown.map((sub) => {
const { name } = sub;
const runs = runLabel(sub);
const active = ageUnix(sub);
const status = stateLabel(sub);
return (
<li key={name}>
<button
type="button"
class={`ui-subagent-terms-item${isDimmed(sub, nowS) ? " ui-subagent-terms-item-stale" : ""}`}
aria-expanded={name === selected}
title={
name === selected
? `hide ${name}'s terminal`
: `show ${name}'s terminal`
}
onClick={() =>
setPicked(name === selected ? null : name)
}
>
<span class="ui-subagent-terms-name">{name}</span>
<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 && (
<ApiErrorPanel
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);
});