@@ -130,26 +130,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
130130 return ;
131131 }
132132
133- if ( ! waitForCompletion ) {
134- // Already resolved, just update the UI with final output
135- if ( extras . onPartialOutput ) {
136- const status =
137- code === 0 || ! code
138- ? "\nBackground command completed"
139- : `\nBackground command failed with exit code ${ code } ` ;
140- extras . onPartialOutput ( {
141- toolCallId,
142- contextItems : [
143- {
144- name : "Terminal" ,
145- description : "Terminal command output" ,
146- content : terminalOutput ,
147- status : status ,
148- } ,
149- ] ,
150- } ) ;
151- }
152- } else {
133+ if ( waitForCompletion ) {
153134 // Normal completion, resolve now
154135 if ( code === 0 ) {
155136 const status = "Command completed" ;
@@ -172,6 +153,25 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
172153 } ,
173154 ] ) ;
174155 }
156+ } else {
157+ // Already resolved, just update the UI with final output
158+ if ( extras . onPartialOutput ) {
159+ const status =
160+ code === 0 || ! code
161+ ? "\nBackground command completed"
162+ : `\nBackground command failed with exit code ${ code } ` ;
163+ extras . onPartialOutput ( {
164+ toolCallId,
165+ contextItems : [
166+ {
167+ name : "Terminal" ,
168+ description : "Terminal command output" ,
169+ content : terminalOutput ,
170+ status : status ,
171+ } ,
172+ ] ,
173+ } ) ;
174+ }
175175 }
176176 } ) ;
177177
@@ -197,7 +197,31 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
197197 const workspaceDirs = await extras . ide . getWorkspaceDirs ( ) ;
198198 const cwd = fileURLToPath ( workspaceDirs [ 0 ] ) ;
199199
200- if ( ! waitForCompletion ) {
200+ if ( waitForCompletion ) {
201+ // Standard execution, waiting for completion
202+ try {
203+ const output = await asyncExec ( args . command , { cwd } ) ;
204+ const status = "Command completed" ;
205+ return [
206+ {
207+ name : "Terminal" ,
208+ description : "Terminal command output" ,
209+ content : output . stdout ?? "" ,
210+ status : status ,
211+ } ,
212+ ] ;
213+ } catch ( error : any ) {
214+ const status = `Command failed with: ${ error . message || error . toString ( ) } ` ;
215+ return [
216+ {
217+ name : "Terminal" ,
218+ description : "Terminal command output" ,
219+ content : error . stderr ?? error . toString ( ) ,
220+ status : status ,
221+ } ,
222+ ] ;
223+ }
224+ } else {
201225 // For non-streaming but also not waiting for completion, use spawn
202226 // but don't attach any listeners other than error
203227 try {
@@ -246,30 +270,6 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
246270 } ,
247271 ] ;
248272 }
249- } else {
250- // Standard execution, waiting for completion
251- try {
252- const output = await asyncExec ( args . command , { cwd } ) ;
253- const status = "Command completed" ;
254- return [
255- {
256- name : "Terminal" ,
257- description : "Terminal command output" ,
258- content : output . stdout ?? "" ,
259- status : status ,
260- } ,
261- ] ;
262- } catch ( error : any ) {
263- const status = `Command failed with: ${ error . message || error . toString ( ) } ` ;
264- return [
265- {
266- name : "Terminal" ,
267- description : "Terminal command output" ,
268- content : error . stderr ?? error . toString ( ) ,
269- status : status ,
270- } ,
271- ] ;
272- }
273273 }
274274 }
275275 }
0 commit comments