Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: a running-subagents menu in the full-screen terminal header

An N running subagents badge opens a list of the agent's subagents, each a
link to its terminal, so you can switch without going back to the agents page.
A subagent counts as running when it published a row in the last 15 minutes;
the quiet ones are listed below it, dimmed. The list under the preview and the
menu now share one fetch hook and one definition of running.
This commit is contained in:
iris 2026-10-18 01:33:06 +02:00 • committed by mara
commit 664409c87f
8 changed files with 360 additions and 46 deletions

View file

@ -0,0 +1,61 @@
// What counts as a running subagent, and the menu badge's wording. Run by
// `npm test`, which Node runs with its built-in test runner and type
// stripping, so the `.ts` module is imported as it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
STALE_S,
byRecency,
isRunning,
runningLabel,
splitRunning,
} from "../src/agent/terminal/subagent-list.ts";
const NOW = 1_000_000;
const sub = (name, ago) => ({
name,
last_row_unix: ago === null ? null : NOW - ago,
});
test("a subagent with a recent row is running, a quiet one is not", () => {
assert.equal(isRunning(sub("a", 5), NOW), true);
assert.equal(isRunning(sub("a", STALE_S), NOW), true);
assert.equal(isRunning(sub("a", STALE_S + 1), NOW), false);
});
test("a subagent whose time could not be read is not counted as running", () => {
assert.equal(isRunning(sub("a", null), NOW), false);
});
test("newest first, unreadable last, ties by name", () => {
const list = [sub("c", 50), sub("z", null), sub("b", 10), sub("a", 10)];
assert.deepEqual(
[...list].sort(byRecency).map((s) => s.name),
["a", "b", "c", "z"],
);
});
test("the list splits into running and quiet, each newest first", () => {
const { running, quiet } = splitRunning(
[
sub("old", STALE_S + 100),
sub("new", 1),
sub("mid", 60),
sub("none", null),
],
NOW,
);
assert.deepEqual(
running.map((s) => s.name),
["new", "mid"],
);
assert.deepEqual(
quiet.map((s) => s.name),
["old", "none"],
);
});
test("the badge counts in words", () => {
assert.equal(runningLabel(1), "1 running subagent");
assert.equal(runningLabel(4), "4 running subagents");
});