Skip to content

Commit ab3c336

Browse files
committed
fix(sessions): include subagent metadata in json
1 parent 4f4d108 commit ab3c336

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

src/commands/sessions-table.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export type SessionDisplayRow = {
2626
modelOverride?: string;
2727
contextTokens?: number;
2828
runtimePolicySessionKey?: string;
29+
sessionFile?: string;
30+
spawnedBy?: string;
31+
spawnedWorkspaceDir?: string;
32+
spawnDepth?: number;
33+
subagentRole?: SessionEntry["subagentRole"];
34+
subagentControlScope?: SessionEntry["subagentControlScope"];
35+
label?: string;
36+
status?: SessionEntry["status"];
37+
sessionStartedAt?: number;
38+
lastInteractionAt?: number;
2939
};
3040

3141
export const SESSION_KEY_PAD = 26;
@@ -57,6 +67,16 @@ export function toSessionDisplayRow(key: string, entry: SessionEntry): SessionDi
5767
providerOverride: entry?.providerOverride,
5868
modelOverride: entry?.modelOverride,
5969
contextTokens: entry?.contextTokens,
70+
sessionFile: entry?.sessionFile,
71+
spawnedBy: entry?.spawnedBy,
72+
spawnedWorkspaceDir: entry?.spawnedWorkspaceDir,
73+
spawnDepth: entry?.spawnDepth,
74+
subagentRole: entry?.subagentRole,
75+
subagentControlScope: entry?.subagentControlScope,
76+
label: entry?.label,
77+
status: entry?.status,
78+
sessionStartedAt: entry?.sessionStartedAt,
79+
lastInteractionAt: entry?.lastInteractionAt,
6080
};
6181
}
6282

src/commands/sessions.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,58 @@ describe("sessionsCommand", () => {
256256
expect(main?.runtimePolicySessionKey).toBe("agent:main:telegram:default:direct:42");
257257
});
258258

259+
it("exports subagent lineage metadata in JSON output", async () => {
260+
const store = writeStore(
261+
{
262+
"agent:main:subagent:child": {
263+
sessionId: "child-session",
264+
updatedAt: Date.now() - 60_000,
265+
sessionFile: "/tmp/openclaw-child.jsonl",
266+
spawnedBy: "agent:main:main",
267+
spawnedWorkspaceDir: "/tmp/openclaw-workspace",
268+
spawnDepth: 1,
269+
subagentRole: "leaf",
270+
subagentControlScope: "none",
271+
label: "review runner",
272+
status: "done",
273+
sessionStartedAt: Date.now() - 120_000,
274+
lastInteractionAt: Date.now() - 30_000,
275+
},
276+
},
277+
"sessions-subagent-metadata",
278+
);
279+
280+
const payload = await runSessionsJson<{
281+
sessions?: Array<{
282+
key: string;
283+
sessionFile?: string;
284+
spawnedBy?: string;
285+
spawnedWorkspaceDir?: string;
286+
spawnDepth?: number;
287+
subagentRole?: string;
288+
subagentControlScope?: string;
289+
label?: string;
290+
status?: string;
291+
sessionStartedAt?: number;
292+
lastInteractionAt?: number;
293+
}>;
294+
}>(sessionsCommand, store);
295+
296+
const child = payload.sessions?.find((row) => row.key === "agent:main:subagent:child");
297+
expect(child).toMatchObject({
298+
sessionFile: "/tmp/openclaw-child.jsonl",
299+
spawnedBy: "agent:main:main",
300+
spawnedWorkspaceDir: "/tmp/openclaw-workspace",
301+
spawnDepth: 1,
302+
subagentRole: "leaf",
303+
subagentControlScope: "none",
304+
label: "review runner",
305+
status: "done",
306+
sessionStartedAt: Date.now() - 120_000,
307+
lastInteractionAt: Date.now() - 30_000,
308+
});
309+
});
310+
259311
it("uses a default JSON output limit of 100 sessions", () => {
260312
expect(testing.parseSessionsLimit(undefined)).toBe(100);
261313
});

0 commit comments

Comments
 (0)