@@ -119,6 +119,16 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
119119 // This is a new session not yet persisted to disk by SDK
120120 return undefined ;
121121 }
122+ const timestamp = metadata . startTime ;
123+ const id = metadata . sessionId ;
124+ const label = metadata . summary ? labelFromPrompt ( metadata . summary ) : undefined ;
125+ if ( label ) {
126+ return {
127+ id,
128+ label,
129+ timestamp,
130+ } satisfies ICopilotCLISessionItem ;
131+ }
122132 let dispose : ( ( ) => Promise < void > ) | undefined = undefined ;
123133 let session : Session | undefined = undefined ;
124134 try {
@@ -134,20 +144,8 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
134144 return undefined ;
135145 }
136146 const label = this . _generateSessionLabel ( session . sessionId , chatMessages , undefined ) ;
137-
138- // Get timestamp from last SDK event, or fallback to metadata.startTime
139- const sdkEvents = session . getEvents ( ) ;
140- const lastEventWithTimestamp = [ ...sdkEvents ] . reverse ( ) . find ( event =>
141- event . type !== 'session.import_legacy'
142- && event . type !== 'session.start'
143- && 'timestamp' in event
144- ) ;
145- const timestamp = lastEventWithTimestamp && 'timestamp' in lastEventWithTimestamp
146- ? new Date ( lastEventWithTimestamp . timestamp )
147- : metadata . startTime ;
148-
149147 return {
150- id : metadata . sessionId ,
148+ id,
151149 label,
152150 timestamp,
153151 } satisfies ICopilotCLISessionItem ;
@@ -333,13 +331,11 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
333331 : '' ;
334332
335333 if ( content ) {
336- // Strip system reminders and return first line or first 50 characters, whichever is shorter
337- const cleanContent = stripReminders ( content ) ;
338- const firstLine = cleanContent . split ( '\n' ) . find ( ( l : string ) => l . trim ( ) . length > 0 ) ?? '' ;
339- return firstLine . length > 50 ? firstLine . substring ( 0 , 47 ) + '...' : firstLine ;
334+ return labelFromPrompt ( content ) ;
340335 }
341336 } else if ( prompt && prompt . trim ( ) . length > 0 ) {
342- return prompt . trim ( ) . length > 50 ? prompt . trim ( ) . substring ( 0 , 47 ) + '...' : prompt . trim ( ) ;
337+ return labelFromPrompt ( prompt ) ;
338+
343339 }
344340 } catch ( error ) {
345341 this . logService . warn ( `Failed to generate session label for ${ sessionId } : ${ error } ` ) ;
@@ -349,3 +345,10 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
349345 return `Session ${ sessionId . slice ( 0 , 8 ) } ` ;
350346 }
351347}
348+
349+ function labelFromPrompt ( prompt : string ) : string {
350+ // Strip system reminders and return first line or first 50 characters, whichever is shorter
351+ const cleanContent = stripReminders ( prompt ) ;
352+ const firstLine = cleanContent . split ( '\n' ) . find ( ( l : string ) => l . trim ( ) . length > 0 ) ?? '' ;
353+ return firstLine . length > 50 ? firstLine . substring ( 0 , 47 ) + '...' : firstLine ;
354+ }
0 commit comments