From 2d3bdbe256871c219f7abfa252141a002691cd3f Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 22:23:39 -0700 Subject: [PATCH] refactor: :recycle: Updates to code to remove negative cases first (linting) --- .../implementations/runTerminalCommand.ts | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index 785f4ee30..4f0596535 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -130,26 +130,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { return; } - if (!waitForCompletion) { - // Already resolved, just update the UI with final output - if (extras.onPartialOutput) { - const status = - code === 0 || !code - ? "\nBackground command completed" - : `\nBackground command failed with exit code ${code}`; - extras.onPartialOutput({ - toolCallId, - contextItems: [ - { - name: "Terminal", - description: "Terminal command output", - content: terminalOutput, - status: status, - }, - ], - }); - } - } else { + if (waitForCompletion) { // Normal completion, resolve now if (code === 0) { const status = "Command completed"; @@ -172,6 +153,25 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { }, ]); } + } else { + // Already resolved, just update the UI with final output + if (extras.onPartialOutput) { + const status = + code === 0 || !code + ? "\nBackground command completed" + : `\nBackground command failed with exit code ${code}`; + extras.onPartialOutput({ + toolCallId, + contextItems: [ + { + name: "Terminal", + description: "Terminal command output", + content: terminalOutput, + status: status, + }, + ], + }); + } } }); @@ -197,7 +197,31 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { const workspaceDirs = await extras.ide.getWorkspaceDirs(); const cwd = fileURLToPath(workspaceDirs[0]); - if (!waitForCompletion) { + if (waitForCompletion) { + // Standard execution, waiting for completion + try { + const output = await asyncExec(args.command, { cwd }); + const status = "Command completed"; + return [ + { + name: "Terminal", + description: "Terminal command output", + content: output.stdout ?? "", + status: status, + }, + ]; + } catch (error: any) { + const status = `Command failed with: ${error.message || error.toString()}`; + return [ + { + name: "Terminal", + description: "Terminal command output", + content: error.stderr ?? error.toString(), + status: status, + }, + ]; + } + } else { // For non-streaming but also not waiting for completion, use spawn // but don't attach any listeners other than error try { @@ -246,30 +270,6 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { }, ]; } - } else { - // Standard execution, waiting for completion - try { - const output = await asyncExec(args.command, { cwd }); - const status = "Command completed"; - return [ - { - name: "Terminal", - description: "Terminal command output", - content: output.stdout ?? "", - status: status, - }, - ]; - } catch (error: any) { - const status = `Command failed with: ${error.message || error.toString()}`; - return [ - { - name: "Terminal", - description: "Terminal command output", - content: error.stderr ?? error.toString(), - status: status, - }, - ]; - } } } }