@@ -27,7 +27,7 @@ function detectGpu() {
2727 // Try NVIDIA first — query VRAM
2828 try {
2929 const output = runCapture (
30- "nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits" ,
30+ [ "nvidia-smi" , " --query-gpu=memory.total" , " --format=csv,noheader,nounits"] ,
3131 { ignoreError : true }
3232 ) ;
3333 if ( output ) {
@@ -49,15 +49,21 @@ function detectGpu() {
4949 // Fallback: DGX Spark (GB10) — VRAM not queryable due to unified memory architecture
5050 try {
5151 const nameOutput = runCapture (
52- "nvidia-smi --query-gpu=name --format=csv,noheader,nounits" ,
52+ [ "nvidia-smi" , " --query-gpu=name" , " --format=csv,noheader,nounits"] ,
5353 { ignoreError : true }
5454 ) ;
5555 if ( nameOutput && nameOutput . includes ( "GB10" ) ) {
5656 // GB10 has 128GB unified memory shared with Grace CPU — use system RAM
5757 let totalMemoryMB = 0 ;
5858 try {
59- const memLine = runCapture ( "free -m | awk '/Mem:/ {print $2}'" , { ignoreError : true } ) ;
60- if ( memLine ) totalMemoryMB = parseInt ( memLine . trim ( ) , 10 ) || 0 ;
59+ const freeOut = runCapture ( [ "free" , "-m" ] , { ignoreError : true } ) ;
60+ if ( freeOut ) {
61+ const memLine = freeOut . split ( "\n" ) . find ( ( l ) => l . includes ( "Mem:" ) ) ;
62+ if ( memLine ) {
63+ const parts = memLine . split ( / \s + / ) ;
64+ totalMemoryMB = parseInt ( parts [ 1 ] , 10 ) || 0 ;
65+ }
66+ }
6167 } catch { }
6268 return {
6369 type : "nvidia" ,
@@ -74,7 +80,7 @@ function detectGpu() {
7480 if ( process . platform === "darwin" ) {
7581 try {
7682 const spOutput = runCapture (
77- "system_profiler SPDisplaysDataType 2>/dev/null" ,
83+ [ "system_profiler" , " SPDisplaysDataType" ] ,
7884 { ignoreError : true }
7985 ) ;
8086 if ( spOutput ) {
@@ -92,7 +98,7 @@ function detectGpu() {
9298 } else {
9399 // Apple Silicon shares system RAM — read total memory
94100 try {
95- const memBytes = runCapture ( "sysctl -n hw.memsize" , { ignoreError : true } ) ;
101+ const memBytes = runCapture ( [ "sysctl" , "-n" , " hw.memsize"] , { ignoreError : true } ) ;
96102 if ( memBytes ) memoryMB = Math . floor ( parseInt ( memBytes , 10 ) / 1024 / 1024 ) ;
97103 } catch { }
98104 }
@@ -121,7 +127,7 @@ function pullNimImage(model) {
121127 process . exit ( 1 ) ;
122128 }
123129 console . log ( ` Pulling NIM image: ${ image } ` ) ;
124- run ( ` docker pull ${ shellQuote ( image ) } ` ) ;
130+ run ( [ " docker" , " pull" , image ] ) ;
125131 return image ;
126132}
127133
@@ -134,13 +140,23 @@ function startNimContainer(sandboxName, model, port = 8000) {
134140 }
135141
136142 // Stop any existing container with same name
137- const qn = shellQuote ( name ) ;
138- run ( `docker rm -f ${ qn } 2>/dev/null || true` , { ignoreError : true } ) ;
143+ run ( [ "docker" , "rm" , "-f" , name ] , { ignoreError : true } ) ;
139144
140145 console . log ( ` Starting NIM container: ${ name } ` ) ;
141- run (
142- `docker run -d --gpus all -p ${ Number ( port ) } :8000 --name ${ qn } --shm-size 16g ${ shellQuote ( image ) } `
143- ) ;
146+ run ( [
147+ "docker" ,
148+ "run" ,
149+ "-d" ,
150+ "--gpus" ,
151+ "all" ,
152+ "-p" ,
153+ `${ port } :8000` ,
154+ "--name" ,
155+ name ,
156+ "--shm-size" ,
157+ "16g" ,
158+ image ,
159+ ] ) ;
144160 return name ;
145161}
146162
@@ -152,7 +168,7 @@ function waitForNimHealth(port = 8000, timeout = 300) {
152168
153169 while ( ( Date . now ( ) - start ) / 1000 < timeout ) {
154170 try {
155- const result = runCapture ( ` curl -sf http://localhost:${ safePort } /v1/models`, {
171+ const result = runCapture ( [ " curl" , " -sf" , ` http://localhost:${ port } /v1/models`] , {
156172 ignoreError : true ,
157173 } ) ;
158174 if ( result ) {
@@ -169,24 +185,23 @@ function waitForNimHealth(port = 8000, timeout = 300) {
169185
170186function stopNimContainer ( sandboxName ) {
171187 const name = containerName ( sandboxName ) ;
172- const qn = shellQuote ( name ) ;
173188 console . log ( ` Stopping NIM container: ${ name } ` ) ;
174- run ( ` docker stop ${ qn } 2>/dev/null || true` , { ignoreError : true } ) ;
175- run ( ` docker rm ${ qn } 2>/dev/null || true` , { ignoreError : true } ) ;
189+ run ( [ " docker" , " stop" , name ] , { ignoreError : true } ) ;
190+ run ( [ " docker" , "rm" , name ] , { ignoreError : true } ) ;
176191}
177192
178193function nimStatus ( sandboxName ) {
179194 const name = containerName ( sandboxName ) ;
180195 try {
181196 const state = runCapture (
182- ` docker inspect --format ' {{.State.Status}}' ${ shellQuote ( name ) } 2>/dev/null` ,
197+ [ " docker" , " inspect" , " --format" , " {{.State.Status}}" , name ] ,
183198 { ignoreError : true }
184199 ) ;
185200 if ( ! state ) return { running : false , container : name } ;
186201
187202 let healthy = false ;
188203 if ( state === "running" ) {
189- const health = runCapture ( ` curl -sf http://localhost:8000/v1/models 2>/dev/null` , {
204+ const health = runCapture ( [ " curl" , " -sf" , " http://localhost:8000/v1/models" ] , {
190205 ignoreError : true ,
191206 } ) ;
192207 healthy = ! ! health ;
0 commit comments