@@ -257,7 +257,7 @@ export class SshProcessMonitor implements vscode.Disposable {
257257 while ( ! this . disposed && this . currentPid === targetPid ) {
258258 try {
259259 const logFiles = await fs . readdir ( logDir ) ;
260- logFiles . reverse ( ) ;
260+ logFiles . sort ( ) . reverse ( ) ;
261261 const logFileName = logFiles . find (
262262 ( file ) =>
263263 file === `${ targetPid } .log` || file . endsWith ( `-${ targetPid } .log` ) ,
@@ -404,15 +404,11 @@ async function findRemoteSshLogPath(
404404 // Try extension-specific folder (for VS Code clones like Cursor, Windsurf)
405405 try {
406406 const extensionLogDir = path . join ( logsParentDir , extensionId ) ;
407- // Node returns these directories sorted already!
408- const files = await fs . readdir ( extensionLogDir ) ;
409- files . reverse ( ) ;
410-
411- const remoteSsh = files . find ( ( file ) => file . includes ( "Remote - SSH" ) ) ;
412- if ( remoteSsh ) {
413- return path . join ( extensionLogDir , remoteSsh ) ;
407+ const remoteSshLog = await findSshLogInDir ( extensionLogDir ) ;
408+ if ( remoteSshLog ) {
409+ return remoteSshLog ;
414410 }
415- // Folder exists but no Remote SSH log yet
411+
416412 logger . debug (
417413 `Extension log folder exists but no Remote SSH log found: ${ extensionLogDir } ` ,
418414 ) ;
@@ -421,18 +417,19 @@ async function findRemoteSshLogPath(
421417 }
422418
423419 try {
424- // Node returns these directories sorted already!
425420 const dirs = await fs . readdir ( logsParentDir ) ;
426- dirs . reverse ( ) ;
427- const outputDirs = dirs . filter ( ( d ) => d . startsWith ( "output_logging_" ) ) ;
421+ const outputDirs = dirs
422+ . filter ( ( d ) => d . startsWith ( "output_logging_" ) )
423+ . sort ( )
424+ . reverse ( ) ;
428425
429426 if ( outputDirs . length > 0 ) {
430427 const outputPath = path . join ( logsParentDir , outputDirs [ 0 ] ) ;
431- const files = await fs . readdir ( outputPath ) ;
432- const remoteSSHLog = files . find ( ( f ) => f . includes ( "Remote - SSH" ) ) ;
433- if ( remoteSSHLog ) {
434- return path . join ( outputPath , remoteSSHLog ) ;
428+ const remoteSshLog = await findSshLogInDir ( outputPath ) ;
429+ if ( remoteSshLog ) {
430+ return remoteSshLog ;
435431 }
432+
436433 logger . debug (
437434 `Output logging folder exists but no Remote SSH log found: ${ outputPath } ` ,
438435 ) ;
@@ -445,3 +442,9 @@ async function findRemoteSshLogPath(
445442
446443 return undefined ;
447444}
445+
446+ async function findSshLogInDir ( dirPath : string ) : Promise < string | undefined > {
447+ const files = await fs . readdir ( dirPath ) ;
448+ const remoteSshLog = files . find ( ( f ) => f . includes ( "Remote - SSH" ) ) ;
449+ return remoteSshLog ? path . join ( dirPath , remoteSshLog ) : undefined ;
450+ }
0 commit comments