fix: expose spawned session owners in sessions list

This commit is contained in:
Tak Hoffman
2026-03-26 13:00:54 -05:00
parent c041fcc04d
commit 1062a048eb
3 changed files with 21 additions and 1 deletions

View File

@@ -167,6 +167,13 @@ describe("sessions tools", () => {
updatedAt: 12,
parentSessionKey: "agent:main:main",
},
{
key: "agent:main:subagent:worker",
kind: "direct",
sessionId: "s-subagent-worker",
updatedAt: 13,
spawnedBy: "agent:main:main",
},
{
key: "cron:job-1",
kind: "direct",
@@ -203,6 +210,7 @@ describe("sessions tools", () => {
sessions?: Array<{
key?: string;
channel?: string;
spawnedBy?: string;
status?: string;
startedAt?: number;
runtimeMs?: number;
@@ -212,7 +220,7 @@ describe("sessions tools", () => {
messages?: Array<{ role?: string }>;
}>;
};
expect(details.sessions).toHaveLength(4);
expect(details.sessions).toHaveLength(5);
const main = details.sessions?.find((s) => s.key === "main");
expect(main?.channel).toBe("whatsapp");
expect(main?.messages?.length).toBe(1);
@@ -228,6 +236,9 @@ describe("sessions tools", () => {
const dashboardChild = details.sessions?.find((s) => s.key === "agent:main:dashboard:child");
expect(dashboardChild?.parentSessionKey).toBe("agent:main:main");
const subagentWorker = details.sessions?.find((s) => s.key === "agent:main:subagent:worker");
expect(subagentWorker?.spawnedBy).toBe("agent:main:main");
const cronOnly = await tool.execute("call2", { kinds: ["cron"] });
const cronDetails = cronOnly.details as {
sessions?: Array<Record<string, unknown>>;

View File

@@ -52,6 +52,7 @@ export type SessionListRow = {
key: string;
kind: SessionKind;
channel: string;
spawnedBy?: string;
label?: string;
displayName?: string;
parentSessionKey?: string;

View File

@@ -193,6 +193,14 @@ export function createSessionsListTool(opts?: {
key: displayKey,
kind,
channel: derivedChannel,
spawnedBy:
typeof entry.spawnedBy === "string"
? resolveDisplaySessionKey({
key: entry.spawnedBy,
alias,
mainKey,
})
: undefined,
label: typeof entry.label === "string" ? entry.label : undefined,
displayName: typeof entry.displayName === "string" ? entry.displayName : undefined,
parentSessionKey: