Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: an open todos section on the agent card

This commit is contained in:
iris 2026-11-16 00:28:54 +01:00 • committed by mara
commit fa2a75d499
10 changed files with 200 additions and 12 deletions

View file

@ -29,6 +29,10 @@ declared state, destroy included. A card shows **updating** while the hive
updates the agent, from the moment the update stops its container until the
container is back up, so the stopped agent doesn't read as lost.
An agent's card also lists its **open todos**: what each says, which part of the
system raised it and how long ago. The list is read only and follows the agent's
own within a few seconds.
Type `/` in an agent's message box and a menu lists what that agent accepts:
the swarm's own commands (`/compact`, `/clear-todos`) and the skills the
agent's harness published. Arrow keys move, Tab completes, Esc closes. Skills

View file

@ -98,8 +98,8 @@ 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.
An opened card has four sections, and each reads nothing until you open it.
**status** and **terminal** start open, the other two folded:
An opened card has six sections, and each reads nothing until you open it.
**status** and **terminal** start open, the other four folded:
- **status**: how fresh the agent's last report is (with its age), its turn state, context and cost, its hive, links to its
profile and its config repo on the swarm's forge (built from the forge entry
@ -109,7 +109,10 @@ An opened card has four sections, and each reads nothing until you open it.
- **terminal**: the live terminal with its message box. Typing `/` opens a menu
filled from `GET /api/agents/<name>/commands`, which lists the swarm's own
commands and the skills the agent published.
- **open todos**: the agent's 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.
- **subagents**: the agent's subagents and their terminal preview (next section).
- **background tasks**: the agent's bash tasks (see the section on them below).
- **settings**: inference, instructions, resource caps, internet, allowed
domains and permissions, then the agent's linked accounts and the menu that
links another. Internet, allowed domains and permissions show a badge; select

View file

@ -43,6 +43,7 @@ import {
startsOpen,
type DetailSection,
} from "./sections.js";
import { AgentTodos } from "../terminal/AgentTodos.js";
import { BashTasks } from "../terminal/BashTasks.js";
import { SubagentTerms } from "../terminal/SubagentTerms.js";
import { WantedMenu } from "../roster/WantedMenu.js";
@ -317,6 +318,8 @@ function SectionBody({
case "terminal":
// The agent's live terminal and its input box.
return <AgentTermPreview agentName={row.name} />;
case "todos":
return <AgentTodos key={row.name} agentName={row.name} />;
case "subagents":
return <SubagentTerms key={row.name} agentName={row.name} />;
case "tasks":
@ -332,7 +335,7 @@ export function AgentDetail({
}: {
row: AgentRow;
actions: AgentActions;
/** Add the live terminal, subagents and background tasks sections. */
/** Add the live terminal, todos, subagents and background tasks sections. */
withTerminal?: boolean;
/**
* An opened card, whose header already shows the state rows. Without it

View file

@ -4,29 +4,26 @@
/** One folded block of an opened agent card. */
export type DetailSection =
| "status"
| "terminal"
| "subagents"
| "tasks"
| "settings";
"status" | "terminal" | "todos" | "subagents" | "tasks" | "settings";
/** What each section's header says. */
export const SECTION_TITLE: Record<DetailSection, string> = {
status: "status",
terminal: "terminal",
todos: "open todos",
subagents: "subagents",
tasks: "background tasks",
settings: "settings",
};
/**
* The sections a card shows, top to bottom. The terminal, subagents and tasks are
* The sections a card shows, top to bottom. The terminal, todos, subagents and tasks are
* left out where the page is already beside a terminal (the terminal page's
* details popover).
*/
export function sectionsFor(withTerminal: boolean): DetailSection[] {
return withTerminal
? ["status", "terminal", "subagents", "tasks", "settings"]
? ["status", "terminal", "todos", "subagents", "tasks", "settings"]
: ["status", "settings"];
}

View file

@ -0,0 +1,42 @@
/* <AgentTodos> — the rows of an agent's open todos. */
.ui-agent-todos-count {
margin: 0 0 0.5em;
color: var(--muted);
}
.ui-agent-todos-list {
display: flex;
flex-direction: column;
gap: 0.35em;
margin: 0;
padding: 0;
list-style: none;
}
.ui-agent-todos-item {
display: grid;
grid-template-columns: 6em minmax(0, 1fr) auto;
align-items: baseline;
gap: 0.75em;
}
.ui-agent-todos-subsystem {
overflow: hidden;
color: var(--blue);
font-family: var(--mono, monospace);
font-size: 0.85em;
text-overflow: ellipsis;
white-space: nowrap;
}
.ui-agent-todos-summary {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.ui-agent-todos-age {
color: var(--muted);
font-size: 0.85em;
white-space: nowrap;
}

View file

@ -0,0 +1,50 @@
// <AgentTodos> — an agent's open todos, in its card's "todos" section: what each
// says, which subsystem raised it and since when. The list is
// `GET /api/agents/{name}/todos` (`useAgentTodos`), which swarm-controller reads
// from what the agent's harness published. Read-only.
//
// Mount it keyed by agent name: the refresh timer is armed once per mount.
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
import { Hint } from "../../ui/hint/Hint.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
import { todosLabel } from "./agent-todos.js";
import { useAgentTodos } from "./useAgentTodos.js";
import "./AgentTodos.css";
export function AgentTodos({ agentName }: { agentName: string }) {
const { todos, error } = useAgentTodos(agentName);
return (
<section class="ui-agent-todos" aria-label={`${agentName}'s open todos`}>
{error && (
<ApiErrorPanel
problem={error}
context={`failed to list ${agentName}'s todos`}
/>
)}
{todos === null ? (
error ? null : (
<Hint as="span">…</Hint>
)
) : todos.length === 0 ? (
<Hint as="span">{todosLabel(todos)}</Hint>
) : (
<>
<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>
</>
)}
</section>
);
}

View file

@ -0,0 +1,29 @@
// An agent's open todos as `GET /api/agents/{name}/todos` serves them: what the
// agent's harness last published, newest first.
/** One row of `GET /api/agents/{name}/todos`. */
export interface AgentTodo {
/** The harness's own id for it. */
id: number;
/** What produced it: `matrix`, `forge`, `bash`, … */
subsystem: string;
/** What it says, as one line. */
summary: string;
/** Where it came from, when the producer says. */
source?: string;
/** Unix seconds when it was last updated. */
updated_unix: number;
}
/** Newest first; ties by id, the higher one first. */
export function sortTodos(todos: AgentTodo[]): AgentTodo[] {
return [...todos].sort(
(a, b) => b.updated_unix - a.updated_unix || b.id - a.id,
);
}
/** The count in words: `no open todos`, `1 open todo`, `3 open todos`. */
export function todosLabel(todos: AgentTodo[]): string {
if (todos.length === 0) return "no open todos";
return todos.length === 1 ? "1 open todo" : `${todos.length} open todos`;
}

View file

@ -0,0 +1,23 @@
// An agent's open todos, refetched on a timer: `GET /api/agents/{name}/todos`.
// `null` until the first answer; a failed fetch sets `error` and keeps the last
// list. Mount per agent name: the poll belongs to one agent.
import type { ProblemDetails } from "@hive/shared/api-error.js";
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js";
import { sortTodos, type AgentTodo } from "./agent-todos.js";
const REFRESH_MS = 10_000;
export function useAgentTodos(agentName: string): {
todos: AgentTodo[] | null;
error: ProblemDetails | null;
} {
const { data, error } = usePolled(REFRESH_MS, async (signal) =>
sortTodos(
await fetchJson<AgentTodo[]>(
`/api/agents/${encodeURIComponent(agentName)}/todos`,
signal,
),
),
);
return { todos: data, error };
}

View file

@ -0,0 +1,36 @@
// An agent's open todos: their order and the count in words. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { sortTodos, todosLabel } from "../src/agent/terminal/agent-todos.ts";
const todo = (id, updated_unix) => ({
id,
subsystem: "forge",
summary: `todo ${id}`,
updated_unix,
});
test("the newest todo comes first and a tie goes to the higher id", () => {
const ids = sortTodos([
todo(1, 100),
todo(2, 300),
todo(3, 300),
todo(4, 200),
]).map((t) => t.id);
assert.deepEqual(ids, [3, 2, 4, 1]);
});
test("sorting leaves the list it was given alone", () => {
const list = [todo(1, 100), todo(2, 200)];
sortTodos(list);
assert.deepEqual(
list.map((t) => t.id),
[1, 2],
);
});
test("the count reads in words", () => {
assert.equal(todosLabel([]), "no open todos");
assert.equal(todosLabel([todo(1, 1)]), "1 open todo");
assert.equal(todosLabel([todo(1, 1), todo(2, 2)]), "2 open todos");
});

View file

@ -8,17 +8,18 @@ import {
startsOpen,
} from "../src/agent/detail/sections.ts";
test("a card holds status, terminal, subagents, background tasks, then settings", () => {
test("a card holds status, terminal, open todos, subagents, background tasks, then settings", () => {
assert.deepEqual(sectionsFor(true), [
"status",
"terminal",
"todos",
"subagents",
"tasks",
"settings",
]);
});
test("a page beside a terminal leaves the terminal, subagents and tasks out", () => {
test("a page beside a terminal leaves the terminal, todos, subagents and tasks out", () => {
assert.deepEqual(sectionsFor(false), ["status", "settings"]);
});