swarm: list subagents from their published run state
The subagents list reads each subagent's status from the subagent-status bucket and reports its state, when it began and the exit status. A subagent with no status keeps the newest-row lookup, so an older daemon lists as before. The swarm UI uses the state when there is one and the row-age guess otherwise.
This commit is contained in:
parent
fec5461018
commit
e9bc28fe2f
1 changed files with 309 additions and 44 deletions
|
|
@ -6,10 +6,12 @@ import { test } from "node:test";
|
|||
import {
|
||||
STALE_S,
|
||||
byRecency,
|
||||
isDimmed,
|
||||
isRunning,
|
||||
runLabel,
|
||||
runningLabel,
|
||||
splitRunning,
|
||||
stateLabel,
|
||||
stillListed,
|
||||
} from "../src/agent/terminal/subagent-list.ts";
|
||||
|
||||
|
|
@ -73,6 +75,58 @@ test("a pick holds only while the refreshed list still has it", () => {
|
|||
assert.equal(stillListed(null, subs), null);
|
||||
});
|
||||
|
||||
const withState = (name, state, sinceAgo, rowAgo = null) => ({
|
||||
...sub(name, rowAgo),
|
||||
state,
|
||||
since_unix: NOW - sinceAgo,
|
||||
exit: state === "finished" ? 0 : null,
|
||||
});
|
||||
|
||||
test("a published state decides, whatever the newest row's age says", () => {
|
||||
// Quiet for an hour but the daemon says running: thinking, not stopped.
|
||||
assert.equal(isRunning(withState("a", "running", 3600, 3600), NOW), true);
|
||||
// A row a second ago but the daemon says finished.
|
||||
assert.equal(isRunning(withState("a", "finished", 5, 1), NOW), false);
|
||||
assert.equal(isRunning(withState("a", "stale", 900), NOW), false);
|
||||
});
|
||||
|
||||
test("only a subagent without a status falls back to the row's age", () => {
|
||||
assert.equal(isDimmed(sub("a", STALE_S + 1), NOW), true);
|
||||
assert.equal(isDimmed(sub("a", 5), NOW), false);
|
||||
assert.equal(isDimmed(sub("a", null), NOW), false);
|
||||
assert.equal(isDimmed(withState("a", "running", 3600, 3600), NOW), false);
|
||||
assert.equal(isDimmed(withState("a", "finished", 5, 1), NOW), true);
|
||||
assert.equal(isDimmed(withState("a", "stale", 5), NOW), true);
|
||||
});
|
||||
|
||||
test("the state word names finished and stale subagents only", () => {
|
||||
assert.equal(stateLabel(withState("a", "finished", 5)), "finished");
|
||||
assert.equal(stateLabel(withState("a", "stale", 5)), "stopped reporting");
|
||||
assert.equal(stateLabel(withState("a", "running", 5)), "");
|
||||
assert.equal(stateLabel(sub("a", 5)), "");
|
||||
});
|
||||
|
||||
test("a subagent with only a status sorts by when its state began", () => {
|
||||
const list = [
|
||||
withState("old", "finished", 500),
|
||||
sub("row", 100),
|
||||
withState("new", "running", 5),
|
||||
];
|
||||
assert.deepEqual(
|
||||
[...list].sort(byRecency).map((s) => s.name),
|
||||
["new", "row", "old"],
|
||||
);
|
||||
const { running, quiet } = splitRunning(list, NOW);
|
||||
assert.deepEqual(
|
||||
running.map((s) => s.name),
|
||||
["new", "row"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
quiet.map((s) => s.name),
|
||||
["old"],
|
||||
);
|
||||
});
|
||||
|
||||
test("the run label names the model and effort, whichever are known", () => {
|
||||
assert.equal(runLabel({ model: "opus", effort: "high" }), "opus · high");
|
||||
assert.equal(runLabel({ model: "opus", effort: null }), "opus");
|
||||
|
|
|
|||
Loading…
Reference in a new issue