Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
daemon(cli): C2 — daemon list AGENTS shows running/total, not just total
Gus919c9006a121
diff --git a/src/daemon/src/cli/daemonList.test.ts b/src/daemon/src/cli/daemonList.test.tsindex 029bab00c..f80871396 100644--- a/src/daemon/src/cli/daemonList.test.ts+++ b/src/daemon/src/cli/daemonList.test.ts@@ -67,12 +67,11 @@ describe("renderDaemonList — human table (C2)", () => {it("prints a table with the ID column and no machine key", () => {const out = renderDaemonList(- [{ id: "0ad8e360b064", pid: 39967, alive: true, agents: 8, lastActiveMs: NOW - 12_000 }],+ [{ id: "0ad8e360b064", pid: 39967, alive: true, agents: 8, running: 2, lastActiveMs: NOW - 12_000 }],NOW,);expect(out).toContain("ID");expect(out).toContain("0ad8e360b064");- expect(out).toContain("8"); // agentsexpect(out).toContain("39967"); // pidexpect(out).toContain("running");expect(out).toContain("just now (12s)");@@ -80,26 +79,36 @@ describe("renderDaemonList — human table (C2)", () => {expect(out).not.toContain("cmt_");});+ it("AGENTS column shows running/total, not just total (C2 imprecision fix)", () => {+ const out = renderDaemonList(+ [{ id: "d1", pid: 1, alive: true, agents: 8, running: 2, lastActiveMs: NOW }],+ NOW,+ );+ // "2/8" = 2 working of 8 registered — the fix for AGENTS overstating activity.+ expect(out).toContain("2/8");+ });+it("empty state is human, not JSON", () => {const out = renderDaemonList([], NOW);expect(out).toBe("No daemons running on this machine.");});- it("footnotes the global-status caveat only with >1 daemon (red line 5)", () => {- const one = renderDaemonList([{ id: "a", pid: 1, alive: true, agents: 3, lastActiveMs: NOW }], NOW);- expect(one).not.toContain("last writer");+ it("per-daemon data → NO multi-daemon caveat footnote (C0 made each row its own)", () => {const two = renderDaemonList([- { id: "a", pid: 1, alive: true, agents: 3, lastActiveMs: NOW },- { id: "b", pid: 2, alive: true, agents: 3, lastActiveMs: NOW },+ { id: "a", pid: 1, alive: true, agents: 3, running: 3, lastActiveMs: NOW },+ { id: "b", pid: 2, alive: true, agents: 7, running: 1, lastActiveMs: NOW },],NOW,);- expect(two).toContain("last writer");+ // Each row is its own daemon's snapshot now — no "last writer" caveat.+ expect(two).not.toContain("last writer");+ expect(two).toContain("3/3");+ expect(two).toContain("1/7"); // distinct per row, not a shared count});- it("renders — for missing agents/lastActive (dead or no snapshot)", () => {- const out = renderDaemonList([{ id: "x", pid: 5, alive: false, agents: null, lastActiveMs: null }], NOW);+ it("renders — for missing agents (dead or no snapshot)", () => {+ const out = renderDaemonList([{ id: "x", pid: 5, alive: false, agents: null, running: null, lastActiveMs: null }], NOW);expect(out).toContain("○ dead");expect(out).toContain("—");});@@ -110,7 +119,8 @@ describe("daemonList — C0 per-daemon subdir layout + multi-daemon isolation",beforeEach(() => { baseDir = fs.mkdtempSync(path.join(os.tmpdir(), "alook-c0-")); });afterEach(() => { fs.rmSync(baseDir, { recursive: true, force: true }); });- const writeDaemon = (id: string, pid: number, agents: number, writtenAt: number) => {+ // `running` defaults to all agents; pass fewer to mix in idle agents.+ const writeDaemon = (id: string, pid: number, agents: number, writtenAt: number, running = agents) => {const dir = path.join(baseDir, "daemons", id);fs.mkdirSync(dir, { recursive: true });fs.writeFileSync(path.join(dir, "daemon.pid"), JSON.stringify({ pid, key: `cmk_${id}` }));@@ -119,7 +129,10 @@ describe("daemonList — C0 per-daemon subdir layout + multi-daemon isolation",JSON.stringify({writtenAt,agents: Array.from({ length: agents }, (_, i) => ({- agentId: `${id}-a${i}`, status: "running", derivedActivity: "running", turnActive: true, inbox: 0, sinceProgressMs: 1, stoppingSince: null,+ agentId: `${id}-a${i}`,+ status: "running",+ derivedActivity: i < running ? "running" : "idle",+ turnActive: i < running, inbox: 0, sinceProgressMs: 1, stoppingSince: null,})),}),);@@ -134,6 +147,14 @@ describe("daemonList — C0 per-daemon subdir layout + multi-daemon isolation",expect(row!.agents).toBe(3); // this daemon's own count, from its own status.json});+ it("running counts only derivedActivity==='running', not total (C2)", () => {+ // 6 agents, but only 4 actually working (2 idle) — the AGENTS-imprecision case.+ writeDaemon("222222222222", process.pid, 6, Date.now(), 4);+ const row = daemonList({ baseDir }).find((d) => d.id === "222222222222");+ expect(row!.agents).toBe(6); // total registered+ expect(row!.running).toBe(4); // only the working ones → renders "4/6"+ });+it("TWO daemons each show their OWN agent count — not the last writer's (the multi-daemon bug fix)", () => {// The pre-C0 bug: a single global status.json meant both rows showed the// last writer's count. Per-key subdir status → each row is its own.diff --git a/src/daemon/src/cli/daemonStart.ts b/src/daemon/src/cli/daemonStart.tsindex 4a8c93cce..7ff110636 100644--- a/src/daemon/src/cli/daemonStart.ts+++ b/src/daemon/src/cli/daemonStart.ts@@ -143,13 +143,17 @@ export interface DaemonInfo {pid: number;alive: boolean;/**- * Agent count + last-activity ms-epoch from THIS daemon's own status.json+ * Agent counts + last-activity ms-epoch from THIS daemon's own status.json* (`daemons/<id>/status.json`, per-daemon since C0). NULL when no snapshot yet- * (or a dead daemon). Now accurate per-row even with multiple daemons sharing- * a baseDir — the pre-C0 global single file made every row show the last- * writer's count; the per-key subdir fixes that.+ * (or a dead daemon). Per-row accurate even with multiple daemons sharing a+ * baseDir (pre-C0 the global single file made every row show the last+ * writer's count). `running` = agents with derivedActivity "running" (actually+ * working a turn); `agents` = total registered — the render shows+ * `running/agents` so an operator sees "how many are busy" not just "how many+ * exist" (C2, the AGENTS-count-imprecision fix).*/agents: number | null;+ running: number | null;lastActiveMs: number | null;}@@ -171,15 +175,17 @@ export function daemonList(opts: DaemonListOpts): DaemonInfo[] {}// Per-daemon status: read THIS daemon's own snapshot (C0), not a global one.let agents: number | null = null;+ let running: number | null = null;let lastActiveMs: number | null = null;if (alive && statusPath) {const s = daemonStatusFromFile(statusPath, now);if (s.found) {agents = s.agents.length;+ running = s.agents.filter((a) => a.derivedActivity === "running").length;lastActiveMs = s.writtenAt;}}- results.push({ id, pid: data.pid, alive, agents, lastActiveMs });+ results.push({ id, pid: data.pid, alive, agents, running, lastActiveMs });};for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {diff --git a/src/daemon/src/cli/index.ts b/src/daemon/src/cli/index.tsindex 9cc4b0da0..ad5be2fa4 100755--- a/src/daemon/src/cli/index.ts+++ b/src/daemon/src/cli/index.ts@@ -75,29 +75,25 @@ function relTime(ms: number | null, nowMs: number): string {/*** Render `daemon list` as a human table (C2/C3). Columns: ID (pass to `daemon- * stop <id>`), AGENTS + LAST ACTIVE (from the global status.json — accurate at- * one-daemon-per-machine, a footnote flags the multi-daemon caveat, red line 5),- * PID, STATE. NO machine key / hash prefix (credential stays out of human view).+ * stop <id>`), AGENTS (`running/total` — how many are actually working a turn+ * vs total registered, C2), LAST ACTIVE, PID, STATE. Data is per-daemon since+ * C0 (each row reads its own daemon's status.json), so no multi-daemon caveat.+ * NO machine key / hash prefix (credential stays out of human view, red line 2).*/export function renderDaemonList(daemons: DaemonInfo[], nowMs: number = Date.now()): string {if (daemons.length === 0) return "No daemons running on this machine.";const header = ["ID", "AGENTS", "LAST ACTIVE", "PID", "STATE"];const rows = daemons.map((d) => [d.id,- d.agents == null ? "—" : String(d.agents),+ // `running/total`: e.g. "2/8" = 2 working, 8 registered. "—" if no snapshot.+ d.agents == null ? "—" : `${d.running ?? 0}/${d.agents}`,relTime(d.lastActiveMs, nowMs),String(d.pid),d.alive ? "● running" : "○ dead",]);const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i]!.length)));const fmt = (cols: string[]) => cols.map((c, i) => c.padEnd(widths[i]!)).join(" ");- const lines = [fmt(header), ...rows.map(fmt)];- // Footnote the global-status caveat only when it could mislead (>1 daemon).- if (daemons.length > 1) {- lines.push("");- lines.push("Note: AGENTS/LAST ACTIVE come from a per-machine snapshot; with multiple daemons they reflect the last writer, not each row.");- }- return lines.join("\n");+ return [fmt(header), ...rows.map(fmt)].join("\n");}/* ------------------------------------------------------------------ */