From 2f1ed97e16c8bbb58a0a72a95f56fc7b43122a49 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 7 Oct 2025 09:35:50 -0700 Subject: [PATCH] fix: separate preprocessed tool args (#8111) --- core/index.d.ts | 1 + .../FunctionSpecificToolCallDiv.tsx | 29 ++++++----- gui/src/redux/slices/sessionSlice.ts | 6 +-- gui/src/redux/thunks/enhanceParsedArgs.ts | 52 ------------------- .../redux/thunks/preprocessToolCallArgs.ts | 4 +- gui/src/util/clientTools/editImpl.ts | 1 + 6 files changed, 22 insertions(+), 71 deletions(-) delete mode 100644 gui/src/redux/thunks/enhanceParsedArgs.ts diff --git a/core/index.d.ts b/core/index.d.ts index fde08bef2..bd21d4fe8 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -478,6 +478,7 @@ interface ToolCallState { toolCall: ToolCall; status: ToolStatus; parsedArgs: any; + processedArgs?: Record; // Added in preprocesing step output?: ContextItem[]; tool?: Tool; } diff --git a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx index 0ce5810d5..ed00060a4 100644 --- a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx @@ -14,6 +14,7 @@ function FunctionSpecificToolCallDiv({ historyIndex: number; }) { const args = toolCallState.parsedArgs; + const processedArgs = toolCallState.processedArgs; const toolCall = toolCallState.toolCall; switch (toolCall.function?.name) { @@ -28,8 +29,8 @@ function FunctionSpecificToolCallDiv({ case BuiltInToolNames.EditExistingFile: return ( @@ -37,17 +38,17 @@ function FunctionSpecificToolCallDiv({ case BuiltInToolNames.SingleFindAndReplace: const edits: EditOperation[] = [ { - old_string: args?.old_string ?? "", - new_string: args?.new_string ?? "", - replace_all: args?.replace_all, + old_string: processedArgs?.old_string ?? args?.old_string ?? "", + new_string: processedArgs?.new_string ?? args?.new_string ?? "", + replace_all: processedArgs?.replace_all ?? args?.replace_all, }, ]; return ( diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index dee39f856..1292bda69 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -848,7 +848,7 @@ export const sessionSlice = createSlice({ ); } }, - setToolCallArgs: ( + setProcessedToolCallArgs: ( state, action: PayloadAction<{ toolCallId: string; @@ -860,7 +860,7 @@ export const sessionSlice = createSlice({ action.payload.toolCallId, ); if (toolCallState) { - toolCallState.parsedArgs = action.payload.newArgs; + toolCallState.processedArgs = action.payload.newArgs; } }, cancelToolCall: ( @@ -1038,7 +1038,7 @@ export const { acceptToolCall, setToolGenerated, updateToolCallOutput, - setToolCallArgs, + setProcessedToolCallArgs, setMode, setIsSessionMetadataLoading, setAllSessionMetadata, diff --git a/gui/src/redux/thunks/enhanceParsedArgs.ts b/gui/src/redux/thunks/enhanceParsedArgs.ts deleted file mode 100644 index c3377e345..000000000 --- a/gui/src/redux/thunks/enhanceParsedArgs.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { BuiltInToolNames } from "core/tools/builtIn"; -import { resolveRelativePathInDir } from "core/util/ideUtils"; -import { getUriPathBasename } from "core/util/uri"; -import { IIdeMessenger } from "../../context/IdeMessenger"; -import { setToolCallArgs } from "../slices/sessionSlice"; -import { AppThunkDispatch } from "../store"; - -export async function enhanceParsedArgs( - ideMessenger: IIdeMessenger, - dispatch: AppThunkDispatch, - toolName: string | undefined, - toolCallId: string, - currentArgs: undefined | Record, -) { - // Add file content to parsedArgs for find/replace tools - let enhancedArgs = { ...currentArgs }; - if ( - (toolName === BuiltInToolNames.SingleFindAndReplace || - toolName === BuiltInToolNames.MultiEdit) && - currentArgs?.filepath && - !currentArgs?.editingFileContents - ) { - try { - const fileUri = await resolveRelativePathInDir( - currentArgs.filepath, - ideMessenger.ide, - ); - if (!fileUri) { - throw new Error(`File ${currentArgs.filepath} not found`); - } - const baseName = getUriPathBasename(fileUri); - const fileContent = await ideMessenger.ide.readFile(fileUri); - enhancedArgs = { - ...currentArgs, - fileUri, - baseName, - editingFileContents: fileContent, - }; - dispatch( - setToolCallArgs({ - toolCallId, - newArgs: enhancedArgs, - }), - ); - } catch (error) { - // If we can't read the file, let the tool handle the error - console.warn( - `Failed to enhance args: failed to read file ${currentArgs?.filepath}`, - ); - } - } -} diff --git a/gui/src/redux/thunks/preprocessToolCallArgs.ts b/gui/src/redux/thunks/preprocessToolCallArgs.ts index fd6a9e52d..be3f8c197 100644 --- a/gui/src/redux/thunks/preprocessToolCallArgs.ts +++ b/gui/src/redux/thunks/preprocessToolCallArgs.ts @@ -4,7 +4,7 @@ import posthog from "posthog-js"; import { IIdeMessenger } from "../../context/IdeMessenger"; import { errorToolCall, - setToolCallArgs, + setProcessedToolCallArgs, updateToolCallOutput, } from "../slices/sessionSlice"; import { AppThunkDispatch } from "../store"; @@ -61,7 +61,7 @@ export async function preprocessToolCalls( ); } else if (preprocessedArgs) { dispatch( - setToolCallArgs({ + setProcessedToolCallArgs({ toolCallId: tcState.toolCallId, newArgs: preprocessedArgs, }), diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index ccc7cc3fa..d26826981 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -2,6 +2,7 @@ import { resolveRelativePathInDir } from "core/util/ideUtils"; import { v4 as uuid } from "uuid"; import { applyForEditTool } from "../../redux/thunks/handleApplyStateUpdate"; import { ClientToolImpl } from "./callClientTool"; + export const editToolImpl: ClientToolImpl = async ( args, toolCallId,