feat: expose child subagent sessions in subagents list

This commit is contained in:
Tyler Yust 2026-03-12 01:28:17 -07:00
parent 761e5ce5f8
commit cc4445e8bd
2 changed files with 22 additions and 1 deletions

View File

@ -844,6 +844,16 @@ describe("sessions tools", () => {
createdAt: now - 2 * 60_000,
startedAt: now - 2 * 60_000,
});
addSubagentRunForTests({
runId: "run-child",
childSessionKey: "agent:main:subagent:active:subagent:child",
requesterSessionKey: "agent:main:subagent:active",
requesterDisplayKey: "subagent:active",
task: "child worker",
cleanup: "keep",
createdAt: now - 60_000,
startedAt: now - 60_000,
});
addSubagentRunForTests({
runId: "run-recent",
childSessionKey: "agent:main:subagent:recent",
@ -880,12 +890,16 @@ describe("sessions tools", () => {
const result = await tool.execute("call-subagents-list", { action: "list" });
const details = result.details as {
status?: string;
active?: unknown[];
active?: Array<{ runId?: string; childSessions?: string[] }>;
recent?: unknown[];
text?: string;
};
expect(details.status).toBe("ok");
expect(details.active).toHaveLength(1);
expect(details.active?.[0]).toMatchObject({
runId: "run-active",
childSessions: ["agent:main:subagent:active:subagent:child"],
});
expect(details.recent).toHaveLength(1);
expect(details.text).toContain("active subagents:");
expect(details.text).toContain("recent (last 30m):");

View File

@ -73,6 +73,7 @@ export type SubagentListItem = {
pendingDescendants: number;
runtime: string;
runtimeMs: number;
childSessions?: string[];
model?: string;
totalTokens?: number;
startedAt?: number;
@ -273,6 +274,11 @@ export function buildSubagentList(params: {
const status = resolveRunStatus(entry, {
pendingDescendants,
});
const childSessions = Array.from(
new Set(
listSubagentRunsForController(entry.childSessionKey).map((run) => run.childSessionKey),
),
);
const runtime = formatDurationCompact(runtimeMs);
const label = truncateLine(resolveSubagentLabel(entry), 48);
const task = truncateLine(entry.task.trim(), params.taskMaxChars ?? 72);
@ -288,6 +294,7 @@ export function buildSubagentList(params: {
pendingDescendants,
runtime,
runtimeMs,
...(childSessions.length > 0 ? { childSessions } : {}),
model: resolveModelRef(sessionEntry) || entry.model,
totalTokens,
startedAt: entry.startedAt,