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
6 changed files with 200 additions and 12 deletions

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