Skip to content

Commit 36e7f21

Browse files
fix(sessions): preserve lineage metadata in JSON
1 parent 5d52b5b commit 36e7f21

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎src/commands/sessions-table.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ export type SessionDisplayRow = {
1414
updatedAt: number | null;
1515
ageMs: number | null;
1616
sessionId?: string;
17+
sessionFile?: string;
18+
spawnedBy?: string;
19+
spawnedWorkspaceDir?: string;
20+
spawnedCwd?: string;
21+
parentSessionKey?: string;
22+
forkedFromParent?: boolean;
23+
spawnDepth?: number;
24+
subagentRole?: SessionEntry["subagentRole"];
25+
subagentControlScope?: SessionEntry["subagentControlScope"];
26+
sessionStartedAt?: number;
27+
lastInteractionAt?: number;
28+
label?: string;
29+
status?: SessionEntry["status"];
1730
systemSent?: boolean;
1831
abortedLastRun?: boolean;
1932
thinkingLevel?: string;
@@ -47,6 +60,19 @@ export function toSessionDisplayRow(key: string, entry: SessionEntry): SessionDi
4760
updatedAt,
4861
ageMs: updatedAt ? Date.now() - updatedAt : null,
4962
sessionId: entry?.sessionId,
63+
sessionFile: entry?.sessionFile,
64+
spawnedBy: entry?.spawnedBy,
65+
spawnedWorkspaceDir: entry?.spawnedWorkspaceDir,
66+
spawnedCwd: entry?.spawnedCwd,
67+
parentSessionKey: entry?.parentSessionKey,
68+
forkedFromParent: entry?.forkedFromParent,
69+
spawnDepth: entry?.spawnDepth,
70+
subagentRole: entry?.subagentRole,
71+
subagentControlScope: entry?.subagentControlScope,
72+
sessionStartedAt: entry?.sessionStartedAt,
73+
lastInteractionAt: entry?.lastInteractionAt,
74+
label: entry?.label,
75+
status: entry?.status,
5076
systemSent: entry?.systemSent,
5177
abortedLastRun: entry?.abortedLastRun,
5278
thinkingLevel: entry?.thinkingLevel,

‎src/commands/sessions.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,65 @@ describe("sessionsCommand", () => {
181181
expect(group?.totalTokensFresh).toBe(false);
182182
});
183183

184+
it("exports subagent lineage metadata in JSON output", async () => {
185+
const store = writeStore({
186+
"agent:child:main": {
187+
sessionId: "child-session",
188+
updatedAt: Date.now() - 10 * 60_000,
189+
sessionFile: "/tmp/openclaw/child-session.jsonl",
190+
spawnedBy: "agent:main:main",
191+
spawnedWorkspaceDir: "/workspace/project",
192+
spawnedCwd: "/workspace/project/tasks",
193+
parentSessionKey: "agent:main:main",
194+
forkedFromParent: true,
195+
spawnDepth: 1,
196+
subagentRole: "leaf",
197+
subagentControlScope: "none",
198+
sessionStartedAt: Date.now() - 20 * 60_000,
199+
lastInteractionAt: Date.now() - 5 * 60_000,
200+
label: "research helper",
201+
status: "done",
202+
model: "test:opus",
203+
},
204+
});
205+
206+
const payload = await runSessionsJson<{
207+
sessions?: Array<{
208+
key: string;
209+
sessionFile?: string;
210+
spawnedBy?: string;
211+
spawnedWorkspaceDir?: string;
212+
spawnedCwd?: string;
213+
parentSessionKey?: string;
214+
forkedFromParent?: boolean;
215+
spawnDepth?: number;
216+
subagentRole?: string;
217+
subagentControlScope?: string;
218+
sessionStartedAt?: number;
219+
lastInteractionAt?: number;
220+
label?: string;
221+
status?: string;
222+
}>;
223+
}>(sessionsCommand, store);
224+
225+
const child = payload.sessions?.find((row) => row.key === "agent:child:main");
226+
expect(child).toMatchObject({
227+
sessionFile: "/tmp/openclaw/child-session.jsonl",
228+
spawnedBy: "agent:main:main",
229+
spawnedWorkspaceDir: "/workspace/project",
230+
spawnedCwd: "/workspace/project/tasks",
231+
parentSessionKey: "agent:main:main",
232+
forkedFromParent: true,
233+
spawnDepth: 1,
234+
subagentRole: "leaf",
235+
subagentControlScope: "none",
236+
sessionStartedAt: Date.now() - 20 * 60_000,
237+
lastInteractionAt: Date.now() - 5 * 60_000,
238+
label: "research helper",
239+
status: "done",
240+
});
241+
});
242+
184243
it("shows preserved stale totals in JSON output", async () => {
185244
const store = writeStore({
186245
main: {

0 commit comments

Comments
 (0)