Skip to content

Commit 8788338

Browse files
committed
fix(tools): refine execute command background handling
Adjusts the logic for handling the `runInBackground` parameter in the `executeCommand` tool. Move the backgrounding logic into the process started callback instead of the online callback in case the process we're launching doesn't produce any output.
1 parent b8c112e commit 8788338

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/core/tools/executeCommandTool.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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 }

0 commit comments

Comments
 (0)