@@ -385,11 +385,29 @@ function isHeadlessLikely(env: NodeJS.ProcessEnv): boolean {
385385 return ! env . DISPLAY && ! env . WAYLAND_DISPLAY && ! env . TERM_PROGRAM ;
386386}
387387
388- function detectNvidiaGpu ( runCaptureImpl : RunCaptureFn ) : boolean {
389- if ( ! commandExists ( "nvidia-smi" , runCaptureImpl ) ) {
390- return false ;
391- }
392- return Boolean ( String ( runCaptureImpl ( [ "nvidia-smi" , "-L" ] , { ignoreError : true } ) || "" ) . trim ( ) ) ;
388+ function detectNvidiaGpu ( opts : {
389+ platform : NodeJS . Platform | string ;
390+ isWsl : boolean ;
391+ runCaptureImpl : RunCaptureFn ;
392+ commandExistsImpl ?: ( commandName : string ) => boolean ;
393+ } ) : boolean {
394+ const commandExistsImpl =
395+ opts . commandExistsImpl ??
396+ ( ( commandName : string ) => commandExists ( commandName , opts . runCaptureImpl ) ) ;
397+ if ( commandExistsImpl ( "nvidia-smi" ) ) {
398+ const smiOutput = opts . runCaptureImpl ( [ "nvidia-smi" , "-L" ] , { ignoreError : true } ) ;
399+ if ( String ( smiOutput || "" ) . trim ( ) ) return true ;
400+ }
401+
402+ if ( opts . platform !== "linux" || opts . isWsl || ! commandExistsImpl ( "lspci" ) ) return false ;
403+ const pciOutput = opts . runCaptureImpl ( [ "lspci" , "-nn" ] , { ignoreError : true } ) ;
404+ return String ( pciOutput || "" )
405+ . split ( / \r ? \n / )
406+ . some (
407+ ( line ) =>
408+ / n v i d i a / i. test ( line ) &&
409+ / ( v g a c o m p a t i b l e c o n t r o l l e r | 3 d c o n t r o l l e r | d i s p l a y c o n t r o l l e r ) / i. test ( line ) ,
410+ ) ;
393411}
394412
395413function detectPackageManager ( runCaptureImpl : RunCaptureFn ) : PackageManager {
@@ -456,12 +474,33 @@ export function assessHost(opts: AssessHostOpts = {}): HostAssessment {
456474 runCapture ( command , { ignoreError : options ?. ignoreError ?? false } ) ) ;
457475 const readFileImpl = opts . readFileImpl ?? fs . readFileSync ;
458476 const readdirImpl = opts . readdirImpl ?? ( ( dir : string ) => fs . readdirSync ( dir ) ) ;
477+ const shouldReadLinuxHostDetails = platform === "linux" ;
478+ const release = opts . release ?? ( shouldReadLinuxHostDetails ? os . release ( ) : "" ) ;
479+ const procVersion =
480+ opts . procVersion ??
481+ ( shouldReadLinuxHostDetails
482+ ? ( ( ) => {
483+ try {
484+ return readFileImpl ( "/proc/version" , "utf-8" ) ;
485+ } catch {
486+ return "" ;
487+ }
488+ } ) ( )
489+ : "" ) ;
490+ const isWslHost = detectWsl ( { platform, env, release, procVersion } ) ;
459491 const dockerInstalled =
460492 opts . commandExistsImpl ?.( "docker" ) ?? commandExists ( "docker" , runCaptureImpl ) ;
461493 const nodeInstalled = opts . commandExistsImpl ?.( "node" ) ?? commandExists ( "node" , runCaptureImpl ) ;
462494 const openshellInstalled =
463495 opts . commandExistsImpl ?.( "openshell" ) ?? commandExists ( "openshell" , runCaptureImpl ) ;
464- const hasNvidiaGpu = opts . gpuProbeImpl ?.( ) ?? detectNvidiaGpu ( runCaptureImpl ) ;
496+ const hasNvidiaGpu =
497+ opts . gpuProbeImpl ?.( ) ??
498+ detectNvidiaGpu ( {
499+ platform,
500+ isWsl : isWslHost ,
501+ runCaptureImpl,
502+ commandExistsImpl : opts . commandExistsImpl ,
503+ } ) ;
465504 const nvidiaContainerToolkitInstalled =
466505 opts . commandExistsImpl ?.( "nvidia-ctk" ) ?? commandExists ( "nvidia-ctk" , runCaptureImpl ) ;
467506 const packageManager = detectPackageManager ( runCaptureImpl ) ;
@@ -480,22 +519,10 @@ export function assessHost(opts: AssessHostOpts = {}): HostAssessment {
480519 dockerReachable = true ;
481520 dockerRunning = true ;
482521 }
483-
484- const release = opts . release ?? os . release ( ) ;
485- const procVersion =
486- opts . procVersion ??
487- ( ( ) => {
488- try {
489- return readFileImpl ( "/proc/version" , "utf-8" ) ;
490- } catch {
491- return "" ;
492- }
493- } ) ( ) ;
494522 let runtime = inferContainerRuntime ( dockerInfoOutput ) ;
495523 if ( dockerReachable && runtime === "unknown" && platform === "linux" ) {
496524 runtime = "docker" ;
497525 }
498- const isWslHost = detectWsl ( { platform, env, release, procVersion } ) ;
499526 const dockerCgroupVersion = dockerReachable
500527 ? parseDockerCgroupVersion ( dockerInfoOutput )
501528 : "unknown" ;
0 commit comments