@@ -178,8 +178,8 @@ export async function executeCommand(
178178 }
179179
180180 let message : { text ?: string ; images ?: string [ ] } | undefined
181- let runInBackground = runInBackgroundRequested
182181 let completed = false
182+ let userChoseBackgroundMode = false
183183 let result : string = ""
184184 let exitDetails : ExitCodeDetails | undefined
185185 let shellIntegrationError : string | undefined
@@ -199,16 +199,13 @@ export async function executeCommand(
199199 const status : CommandExecutionStatus = { executionId, status : "output" , output : compressedOutput }
200200 provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
201201
202- // If runInBackgroundRequested, automatically continue the process
203- if ( runInBackgroundRequested && ! completed ) {
204- completed = true
205- process . continue ( )
202+ if ( userChoseBackgroundMode ) {
206203 return
207204 }
208205
209206 try {
210207 const { response, text, images } = await task . ask ( "command_output" , "" )
211- runInBackground = true
208+ userChoseBackgroundMode = true
212209
213210 if ( response === "messageResponse" ) {
214211 message = { text, images }
@@ -230,6 +227,12 @@ export async function executeCommand(
230227 console . log ( `[executeCommand] onShellExecutionStarted: ${ pid } ` )
231228 const status : CommandExecutionStatus = { executionId, status : "started" , pid, command }
232229 provider ?. postMessageToWebview ( { type : "commandExecutionStatus" , text : JSON . stringify ( status ) } )
230+
231+ if ( runInBackgroundRequested ) {
232+ userChoseBackgroundMode = true
233+ process . continue ( )
234+ return
235+ }
233236 } ,
234237 onShellExecutionComplete : ( details : ExitCodeDetails ) => {
235238 const status : CommandExecutionStatus = { executionId, status : "exited" , exitCode : details . exitCode }
@@ -330,7 +333,7 @@ export async function executeCommand(
330333 images ,
331334 ) ,
332335 ]
333- } else if ( completed || exitDetails ) {
336+ } else if ( exitDetails ) {
334337 let exitStatus : string = ""
335338
336339 if ( exitDetails !== undefined ) {
0 commit comments