@@ -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