From e41f9cdffd6d1e334f1e46f40104d62e767e816d Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Fri, 18 Apr 2025 01:03:53 -0700 Subject: [PATCH] removed square brackets and simplified --- core/index.d.ts | 1 + .../implementations/runTerminalCommand.ts | 46 +++++++++++++------ .../gui/ToolCallDiv/RunTerminalCommand.tsx | 31 ++----------- .../thunks/moveTerminalProcessToBackground.ts | 25 +++++----- 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index d94ce58fa..696876f07 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -395,6 +395,7 @@ export interface ContextItem { icon?: string; uri?: ContextItemUri; hidden?: boolean; + status?: string; } export interface ContextItemWithId extends ContextItem { diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index 8d2391561..1bb83205d 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -25,6 +25,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { let terminalOutput = ""; if (!waitForCompletion) { + const status = "Command is running in the background..."; if (extras.onPartialOutput) { extras.onPartialOutput({ toolCallId, @@ -32,7 +33,8 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { { name: "Terminal", description: "Terminal command output", - content: "[Command is running in the background...]/n" + content: "", + status: status, }, ], }); @@ -54,13 +56,15 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { // Send partial output to UI if (extras.onPartialOutput) { + const status = waitForCompletion ? "" : "Command is running in the background..."; extras.onPartialOutput({ toolCallId, contextItems: [ { name: "Terminal", description: "Terminal command output", - content: (waitForCompletion ? terminalOutput : terminalOutput + "\n[Command is running in the background...]") + content: terminalOutput, + status: status, }, ], }); @@ -74,7 +78,7 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { const newOutput = data.toString(); terminalOutput += newOutput; - // Send partial output to UI + // Send partial output to UI, status is not required if (extras.onPartialOutput) { extras.onPartialOutput({ toolCallId, @@ -95,7 +99,8 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { { name: "Terminal", description: "Terminal command output", - content: terminalOutput + "\n[Command is running in the background...]", + content: terminalOutput, + status: "Command is runnning in the background...", }, ]); } @@ -110,15 +115,17 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { 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 + (code === 0 || !code - ? "\n[Background command completed]" - : `\n[Background command failed with exit code ${code}]`), + content: terminalOutput, + status: status, }, ], }); @@ -126,21 +133,24 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { } else { // Normal completion, resolve now if (code === 0) { + const status = "Command completed"; resolve([ { name: "Terminal", description: "Terminal command output", - content: terminalOutput + "\n[Command completed]", + content: terminalOutput, + status: status }, ]); } else { + const status = `Command failed with exit code ${code}`; resolve([ { name: "Terminal", description: "Terminal command output", content: - terminalOutput + - `\n[Command failed with exit code ${code}]`, + terminalOutput, + status: status, }, ]); } @@ -198,20 +208,23 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { // Unref the child to allow the Node.js process to exit childProc.unref(); - + const status = "Command is running in the background..."; return [ { name: "Terminal", description: "Terminal command output", - content: "[Command is running in the background...]", + content: status, + status: status, }, ]; } catch (error: any) { + const status = `Command failed with: ${error.message || error.toString()}`; return [ { name: "Terminal", description: "Terminal command output", - content: `[Command failed with: ${error.message || error.toString()}]`, + content: status, + status: status }, ]; } @@ -219,19 +232,23 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { // 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, }, ]; } @@ -247,7 +264,8 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { name: "Terminal", description: "Terminal command output", content: - "[Terminal output not available. This is only available in local development environments and not in SSH environments for example.]", + "Terminal output not available. This is only available in local development environments and not in SSH environments for example.", + status: "Command failed", }, ]; } diff --git a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx index ca9136e76..7356d01f5 100644 --- a/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx +++ b/gui/src/pages/gui/ToolCallDiv/RunTerminalCommand.tsx @@ -51,28 +51,6 @@ const BackgroundLink = styled.a` } `; -// Extract status message from terminal output -function parseTerminalOutput(output: string): { - commandOutput: string; - statusMessage: string | null; -} { - // Match status messages like [Command is running...], [Command completed], [Background command failed with...], etc. - const statusRegex = /\n\[(Command .+?|Background .+?)\]$/; - const match = output.match(statusRegex); - - if (match) { - return { - commandOutput: output.replace(statusRegex, ''), - statusMessage: match[1] - }; - } - - return { - commandOutput: output, - statusMessage: null - }; -} - export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { const dispatch = useAppDispatch(); @@ -81,11 +59,10 @@ export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { item => item.name === "Terminal" ); - const terminalOutput = terminalItem?.content || ""; - const { commandOutput, statusMessage } = parseTerminalOutput(terminalOutput); - + const terminalContent = terminalItem?.content || ""; + const statusMessage = terminalItem?.status || ""; const isRunning = props.toolCallState.status === "calling"; - const hasOutput = commandOutput.length > 0; + const hasOutput = terminalContent.length > 0; // Determine status type let statusType: 'running' | 'completed' | 'failed' | 'background' = 'completed'; @@ -102,7 +79,7 @@ export function RunTerminalCommand(props: RunTerminalCommandToolCallProps) { diff --git a/gui/src/redux/thunks/moveTerminalProcessToBackground.ts b/gui/src/redux/thunks/moveTerminalProcessToBackground.ts index 45312c066..1b592f549 100644 --- a/gui/src/redux/thunks/moveTerminalProcessToBackground.ts +++ b/gui/src/redux/thunks/moveTerminalProcessToBackground.ts @@ -7,7 +7,7 @@ import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall"; /** * This thunk is used to move a terminal command to the background * when the user clicks the "Continue" button in the UI - * + * * It marks the command as visually complete without stopping * the already running process */ @@ -21,30 +21,29 @@ export const moveTerminalProcessToBackground = createAsyncThunk< const toolCalls = state.session.history.filter( (item) => item.toolCallState?.toolCallId === toolCallId ); - + if (toolCalls.length === 0) { console.error("Could not find tool call with ID:", toolCallId); return; } - + const toolCall = toolCalls[0].toolCallState; if (!toolCall) { console.error("Tool call state is missing"); return; } - - // Update the tool call output to indicate it's running in background - const currentOutput = toolCall.output?.[0]?.content || ""; - const updatedOutput = currentOutput + "\n[Command moved to background. Further output will be ignored.]"; - + + const status = "Command moved to background. Further output will be ignored." + const contextItems: ContextItem[] = [ { name: "Terminal", description: "Terminal command output", - content: updatedOutput + content: "\n" + status, + status: status, } ]; - + // Abort any existing stream for this tool call dispatch(abortStream()); @@ -53,14 +52,14 @@ export const moveTerminalProcessToBackground = createAsyncThunk< toolCallId, contextItems })); - + // Mark the process as backgrounded so we ignore future events await extra.ideMessenger.request("process/markAsBackgrounded", { toolCallId }); - + // Mark the tool call as "done" in the UI // This will set isRunning to false in RunTerminalCommand.tsx dispatch(acceptToolCall()); - + // Trigger an LLM response about the command being moved to background dispatch(streamResponseAfterToolCall({ toolCallId,