@@ -344,17 +344,26 @@ async function listSessions(registry: Registry, clientInfo: ClientInfo, all: boo
344344 return ;
345345 }
346346
347+ const runningSessions = new Set < string > ( ) ;
347348 if ( entries . size )
348349 console . log ( '### Browsers' ) ;
349350 for ( const [ workspace , list ] of entries )
350- await gcAndPrintSessions ( clientInfo , list . map ( entry => new Session ( entry ) ) , `${ path . relative ( process . cwd ( ) , workspace ) || '/' } :` ) ;
351+ await gcAndPrintSessions ( clientInfo , list . map ( entry => new Session ( entry ) ) , `${ path . relative ( process . cwd ( ) , workspace ) || '/' } :` , runningSessions ) ;
352+
353+ // Filter out server entries that already have an attached session.
354+ const filteredServerEntries = new Map < string , BrowserDescriptor [ ] > ( ) ;
355+ for ( const [ workspace , list ] of serverEntries ) {
356+ const unattached = list . filter ( d => ! runningSessions . has ( d . title ) ) ;
357+ if ( unattached . length )
358+ filteredServerEntries . set ( workspace , unattached ) ;
359+ }
351360
352- if ( serverEntries . size ) {
361+ if ( filteredServerEntries . size ) {
353362 if ( entries . size )
354363 console . log ( '' ) ;
355364 console . log ( '### Browser servers available for attach' ) ;
356365 }
357- for ( const [ workspace , list ] of serverEntries )
366+ for ( const [ workspace , list ] of filteredServerEntries )
358367 await gcAndPrintBrowserSessions ( workspace , list ) ;
359368 } else {
360369 console . log ( '### Browsers' ) ;
@@ -363,14 +372,15 @@ async function listSessions(registry: Registry, clientInfo: ClientInfo, all: boo
363372 }
364373}
365374
366- async function gcAndPrintSessions ( clientInfo : ClientInfo , sessions : Session [ ] , header ?: string ) {
375+ async function gcAndPrintSessions ( clientInfo : ClientInfo , sessions : Session [ ] , header ?: string , runningSessions ?: Set < string > ) {
367376 const running : Session [ ] = [ ] ;
368377 const stopped : Session [ ] = [ ] ;
369378
370379 for ( const session of sessions ) {
371380 const canConnect = await session . canConnect ( ) ;
372381 if ( canConnect ) {
373382 running . push ( session ) ;
383+ runningSessions ?. add ( session . name ) ;
374384 } else {
375385 if ( session . config . cli . persistent )
376386 stopped . push ( session ) ;
0 commit comments