@@ -6,6 +6,7 @@ import * as path from "path";
66import * as os from "os" ;
77import { findClaudeCliPath } from "./detection" ;
88import { ProgressCallback , Model } from "../types" ;
9+ import { log , logError , logCommand } from "../utils/logger" ;
910
1011const execAsync = promisify ( exec ) ;
1112
@@ -43,12 +44,21 @@ export async function generateWithCLI(
4344 ? `type "${ promptFile } " | ${ escapedCliPath } -p --model ${ model } `
4445 : `cat "${ promptFile } " | ${ escapedCliPath } -p --model ${ model } ` ;
4546
47+ logCommand ( command ) ;
48+
4649 const { stdout, stderr } = await execAsync ( command , {
4750 shell : process . platform === "win32" ? "cmd.exe" : "/bin/bash" ,
4851 maxBuffer : 10 * 1024 * 1024 ,
4952 timeout : 120000 ,
5053 } ) ;
5154
55+ if ( stderr ) {
56+ log ( `CLI stderr: ${ stderr . trim ( ) } ` ) ;
57+ }
58+ if ( stdout ) {
59+ log ( `CLI stdout (first 500 chars): ${ stdout . substring ( 0 , 500 ) } ` ) ;
60+ }
61+
5262 if ( stderr && ! stdout ) {
5363 throw new Error ( `CLI error output: ${ stderr . trim ( ) } ` ) ;
5464 }
@@ -91,7 +101,7 @@ export async function generateWithCLI(
91101
92102 return lines [ lines . length - 1 ] || "chore: update code" ;
93103 } catch ( error ) {
94- const err = error as NodeJS . ErrnoException & { killed ?: boolean } ;
104+ const err = error as NodeJS . ErrnoException & { killed ?: boolean ; stderr ?: string ; stdout ?: string } ;
95105 if ( err . killed ) {
96106 throw new Error (
97107 "CLI process timed out after 2 minutes. Try a smaller diff or check your connection."
@@ -100,7 +110,21 @@ export async function generateWithCLI(
100110 if ( err . code === "ENOENT" ) {
101111 throw new Error ( `CLI executable not found at: ${ cliPath } ` ) ;
102112 }
103- throw error ;
113+ // Provide detailed error information for debugging
114+ const stderr = err . stderr ?. trim ( ) || "" ;
115+ const stdout = err . stdout ?. trim ( ) || "" ;
116+ const details : string [ ] = [ ] ;
117+ if ( stderr ) {
118+ details . push ( `stderr: ${ stderr } ` ) ;
119+ }
120+ if ( stdout ) {
121+ details . push ( `stdout: ${ stdout } ` ) ;
122+ }
123+ const baseMessage = err . message || String ( error ) ;
124+ const detailStr = details . length > 0 ? ` [${ details . join ( "; " ) } ]` : "" ;
125+ const fullError = `CLI execution failed: ${ baseMessage } ${ detailStr } ` ;
126+ logError ( fullError , error ) ;
127+ throw new Error ( fullError ) ;
104128 } finally {
105129 try {
106130 await fs . promises . unlink ( promptFile ) ;
@@ -144,20 +168,29 @@ export async function generateWithCLIManaged(
144168 ? `type "${ promptFile } " | ${ escapedCliPath } -p --model haiku`
145169 : `cat "${ promptFile } " | ${ escapedCliPath } -p --model haiku` ;
146170
171+ logCommand ( command ) ;
172+
147173 const { stdout, stderr } = await execAsync ( command , {
148174 shell : process . platform === "win32" ? "cmd.exe" : "/bin/bash" ,
149175 maxBuffer : 10 * 1024 * 1024 ,
150176 timeout : 120000 ,
151177 cwd : repoPath ,
152178 } ) ;
153179
180+ if ( stderr ) {
181+ log ( `CLI stderr: ${ stderr . trim ( ) } ` ) ;
182+ }
183+ if ( stdout ) {
184+ log ( `CLI stdout (first 500 chars): ${ stdout . substring ( 0 , 500 ) } ` ) ;
185+ }
186+
154187 if ( stderr && ! stdout ) {
155188 throw new Error ( `CLI error output: ${ stderr . trim ( ) } ` ) ;
156189 }
157190
158191 return stdout . trim ( ) || "chore: update code" ;
159192 } catch ( error ) {
160- const err = error as NodeJS . ErrnoException & { killed ?: boolean } ;
193+ const err = error as NodeJS . ErrnoException & { killed ?: boolean ; stderr ?: string ; stdout ?: string } ;
161194 if ( err . killed ) {
162195 throw new Error (
163196 "CLI process timed out after 2 minutes. Try a smaller diff or check your connection."
@@ -166,7 +199,21 @@ export async function generateWithCLIManaged(
166199 if ( err . code === "ENOENT" ) {
167200 throw new Error ( `CLI executable not found at: ${ cliPath } ` ) ;
168201 }
169- throw error ;
202+ // Provide detailed error information for debugging
203+ const stderr = err . stderr ?. trim ( ) || "" ;
204+ const stdout = err . stdout ?. trim ( ) || "" ;
205+ const details : string [ ] = [ ] ;
206+ if ( stderr ) {
207+ details . push ( `stderr: ${ stderr } ` ) ;
208+ }
209+ if ( stdout ) {
210+ details . push ( `stdout: ${ stdout } ` ) ;
211+ }
212+ const baseMessage = err . message || String ( error ) ;
213+ const detailStr = details . length > 0 ? ` [${ details . join ( "; " ) } ]` : "" ;
214+ const fullError = `CLI execution failed: ${ baseMessage } ${ detailStr } ` ;
215+ logError ( fullError , error ) ;
216+ throw new Error ( fullError ) ;
170217 } finally {
171218 try {
172219 await fs . promises . unlink ( promptFile ) ;
0 commit comments