@@ -102,12 +102,18 @@ export class SubprocessCLITransport {
102102 }
103103 } ;
104104
105+ const jsonlString = JSON . stringify ( jsonlMessage ) + '\n' ;
106+
105107 this . debugLog (
106108 'DEBUG: [Transport] Writing JSONL to process stdin:' ,
107109 JSON . stringify ( jsonlMessage ) . substring ( 0 , 150 ) + '...'
108110 ) ;
109111
110- this . process . stdin . write ( JSON . stringify ( jsonlMessage ) + '\n' ) ;
112+ if ( this . options . debug ) {
113+ this . debugLog ( 'DEBUG stdin (raw):' , jsonlString ) ;
114+ }
115+
116+ this . process . stdin . write ( jsonlString ) ;
111117
112118 this . debugLog ( 'DEBUG: [Transport] Successfully wrote JSONL to stdin' ) ;
113119 } else {
@@ -116,6 +122,11 @@ export class SubprocessCLITransport {
116122 'DEBUG: [Transport] Writing raw data to stdin:' ,
117123 data . substring ( 0 , 100 ) + '...'
118124 ) ;
125+
126+ if ( this . options . debug ) {
127+ this . debugLog ( 'DEBUG stdin (raw):' , data ) ;
128+ }
129+
119130 this . process . stdin . write ( data ) ;
120131 }
121132 } catch ( error ) {
@@ -355,6 +366,20 @@ export class SubprocessCLITransport {
355366 this . debugLog ( 'DEBUG: Process exited:' , { code, signal } ) ;
356367 } ) ;
357368
369+ // Log all stderr output when debug is enabled
370+ if ( this . process . stderr && this . options . debug ) {
371+ this . process . stderr . on ( 'data' , ( chunk : Buffer ) => {
372+ this . debugLog ( 'DEBUG stderr (raw):' , chunk . toString ( ) ) ;
373+ } ) ;
374+ }
375+
376+ // Log all stdout output when debug is enabled
377+ if ( this . process . stdout && this . options . debug ) {
378+ this . process . stdout . on ( 'data' , ( chunk : Buffer ) => {
379+ this . debugLog ( 'DEBUG stdout (raw):' , chunk . toString ( ) ) ;
380+ } ) ;
381+ }
382+
358383 // Send prompt via stdin
359384 if ( this . process . stdin ) {
360385 if ( this . streamingMode ) {
@@ -367,6 +392,8 @@ export class SubprocessCLITransport {
367392 }
368393 } ;
369394
395+ const initialJsonlString = JSON . stringify ( jsonlMessage ) + '\n' ;
396+
370397 this . debugLog (
371398 'DEBUG: [Transport] Sending initial JSONL message in streaming mode' ,
372399 {
@@ -378,12 +405,22 @@ export class SubprocessCLITransport {
378405 }
379406 ) ;
380407
381- this . process . stdin . write ( JSON . stringify ( jsonlMessage ) + '\n' ) ;
408+ if ( this . options . debug ) {
409+ this . debugLog ( 'DEBUG stdin (raw):' , initialJsonlString ) ;
410+ }
411+
412+ this . process . stdin . write ( initialJsonlString ) ;
382413 // Keep stdin open for potential streaming input and for keepAlive behavior
383414 // stdin will be closed when we receive a result message (if keepAlive=false) or explicitly via end()
384415 } else {
385416 // For simple queries, send as plain text and close stdin
386- this . process . stdin . write ( this . prompt + '\n' ) ;
417+ const promptString = this . prompt + '\n' ;
418+
419+ if ( this . options . debug ) {
420+ this . debugLog ( 'DEBUG stdin (raw):' , promptString ) ;
421+ }
422+
423+ this . process . stdin . write ( promptString ) ;
387424 this . process . stdin . end ( ) ;
388425 }
389426 }
0 commit comments