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