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:
parent
1448168569
commit
ef4c9214f7
9 changed files with 271 additions and 88 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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,8 +31,10 @@ export function AgentTodos({ agentName }: { agentName: string }) {
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<p class="ui-agent-todos-count">{todosLabel(todos)}</p>
|
<p class="ui-agent-todos-count">{todosLabel(todos)}</p>
|
||||||
|
<CappedRows rows={todos} noun="todos">
|
||||||
|
{(shown) => (
|
||||||
<ul class="ui-agent-todos-list">
|
<ul class="ui-agent-todos-list">
|
||||||
{todos.map((t) => (
|
{shown.map((t) => (
|
||||||
<li key={t.id} class="ui-agent-todos-item">
|
<li key={t.id} class="ui-agent-todos-item">
|
||||||
<span class="ui-agent-todos-subsystem">{t.subsystem}</span>
|
<span class="ui-agent-todos-subsystem">{t.subsystem}</span>
|
||||||
<span class="ui-agent-todos-summary" title={t.summary}>
|
<span class="ui-agent-todos-summary" title={t.summary}>
|
||||||
|
|
@ -43,6 +46,8 @@ export function AgentTodos({ agentName }: { agentName: string }) {
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
)}
|
||||||
|
</CappedRows>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -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,8 +51,10 @@ export function BashTasksList({
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<p class="ui-bash-tasks-count">{runningTasksLabel(tasks)}</p>
|
<p class="ui-bash-tasks-count">{runningTasksLabel(tasks)}</p>
|
||||||
|
<CappedRows rows={tasks} noun="tasks">
|
||||||
|
{(shown) => (
|
||||||
<ul class="ui-bash-tasks-list">
|
<ul class="ui-bash-tasks-list">
|
||||||
{tasks.map((t) => (
|
{shown.map((t) => (
|
||||||
<li
|
<li
|
||||||
key={t.task}
|
key={t.task}
|
||||||
class={`ui-bash-tasks-item${isLive(t) ? "" : " ui-bash-tasks-item-over"}`}
|
class={`ui-bash-tasks-item${isLive(t) ? "" : " ui-bash-tasks-item-over"}`}
|
||||||
|
|
@ -72,6 +75,8 @@ export function BashTasksList({
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
)}
|
||||||
|
</CappedRows>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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">
|
||||||
|
{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 { name } = sub;
|
||||||
const runs = runLabel(sub);
|
const runs = runLabel(sub);
|
||||||
const active = ageUnix(sub);
|
const active = ageUnix(sub);
|
||||||
const status = stateLabel(sub);
|
const status = stateLabel(sub);
|
||||||
const stale = isDimmed(sub, nowS);
|
|
||||||
return (
|
return (
|
||||||
<span
|
<li key={name}>
|
||||||
key={name}
|
<button
|
||||||
class={`ui-subagent-terms-item${stale ? " ui-subagent-terms-item-stale" : ""}`}
|
type="button"
|
||||||
>
|
class={`ui-subagent-terms-item${isDimmed(sub, nowS) ? " ui-subagent-terms-item-stale" : ""}`}
|
||||||
<Badge
|
aria-expanded={name === selected}
|
||||||
variant={name === selected ? "default" : "quiet"}
|
|
||||||
value={name}
|
|
||||||
expanded={name === selected}
|
|
||||||
title={
|
title={
|
||||||
name === selected
|
name === selected
|
||||||
? `hide ${name}'s terminal`
|
? `hide ${name}'s terminal`
|
||||||
: `show ${name}'s terminal`
|
: `show ${name}'s terminal`
|
||||||
}
|
}
|
||||||
onClick={() => setPicked(name === selected ? null : name)}
|
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-name">{name}</span>
|
||||||
|
<span class="ui-subagent-terms-age">{runs}</span>
|
||||||
<span class="ui-subagent-terms-age">
|
<span class="ui-subagent-terms-age">
|
||||||
|
{status}
|
||||||
|
{active !== null && (
|
||||||
|
<>
|
||||||
|
{status ? " " : ""}
|
||||||
<RelativeTime epochMs={active * 1000} />
|
<RelativeTime epochMs={active * 1000} />
|
||||||
</span>
|
</>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</ul>
|
||||||
|
)}
|
||||||
|
</CappedRows>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
{error && (
|
{error && (
|
||||||
<ApiErrorPanel
|
<ApiErrorPanel
|
||||||
problem={error}
|
problem={error}
|
||||||
|
|
|
||||||
19
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.css
Normal file
19
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.css
Normal 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;
|
||||||
|
}
|
||||||
44
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx
Normal file
44
frontend/packages/swarm-ui/src/ui/capped-rows/CappedRows.tsx
Normal 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}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
21
frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts
Normal file
21
frontend/packages/swarm-ui/src/ui/capped-rows/cap-rows.ts
Normal 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 };
|
||||||
|
}
|
||||||
34
frontend/packages/swarm-ui/test/cap-rows.test.mjs
Normal file
34
frontend/packages/swarm-ui/test/cap-rows.test.mjs
Normal 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);
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue