Elffuss BraidHub

kikocis/continue public

Merge pull request #6475 from continuedev/nate/adjust-find-replace-prompt

Polishing find / replace tool (UI, prompt)
Changeset74b917bba7fc23c57623f59b3d0ea16ff51198283bbffe17144b816c3e6cb681
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-08 10:23 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-08 10:23 -07:00
Parentsfcc262fbb143, 9e87b2fb4169

Browse the files at this changeset

12 files changed

modified core/llm/toolSupport.ts +3 −0
@@ -19,6 +19,7 @@
1919 "claude-3-7",
2020 "claude-3.7",
2121 "claude-sonnet-4",
22+ "claude-4-sonnet",
2223 "gpt-4",
2324 "o3",
2425 "gemini",
@@ -33,6 +34,7 @@
3334 "claude-3-7",
3435 "claude-3.7",
3536 "claude-sonnet-4",
37+ "claude-4-sonnet",
3638 "claude-opus-4",
3739 ].some((part) => model.toLowerCase().startsWith(part))
3840 ) {
@@ -95,6 +97,7 @@
9597 "claude-3-7-sonnet",
9698 "claude-3.7-sonnet",
9799 "claude-sonnet-4",
100+ "claude-4-sonnet",
98101 "claude-opus-4",
99102 "nova-lite",
100103 "nova-pro",
modified core/tools/definitions/searchAndReplaceInFile.ts +5 −1
@@ -56,7 +56,11 @@
5656 * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
5757 * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
5858 * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
59-4. Special operations:
59+4. Splitting up tool calls:
60+ * When making multiple closely related edits to the same file, you should try to use multiple SEARCH/REPLACE blocks in a single tool call, rather than making multiple separate tool calls
61+ * If you need to make follow up edits or group your work into logical segments, it is okay to perform additional tool calls
62+ * DO NOT make back-to-back tool calls. Instead interleave with brief explanation of what each will do. For example, instead of [explanation, tool call, tool call] you should do [explanation, tool call, explanation, tool call]
63+5. Special operations:
6064 * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
6165 * To delete code: Use empty REPLACE section
6266
modified core/tools/index.ts +6 −7
@@ -39,14 +39,13 @@
3939 params: ConfigDependentToolParams,
4040 ): Tool[] => [
4141 requestRuleTool(params),
42+ // Search and replace is now generally available
43+ searchAndReplaceInFileTool,
44+ // Keep edit file tool available for models that need it
45+ editFileTool,
4246 ...(params.enableExperimentalTools
43- ? [
44- searchAndReplaceInFileTool,
45- viewRepoMapTool,
46- viewSubdirectoryTool,
47- codebaseTool,
48- ]
49- : [editFileTool]),
47+ ? [viewRepoMapTool, viewSubdirectoryTool, codebaseTool]
48+ : []),
5049 ];
5150
5251 export const getToolsForIde = async (ide: IDE): Promise<Tool[]> =>
modified extensions/vscode/e2e/tests/GUI.test.ts +0 −14
@@ -357,20 +357,6 @@
357357 await messageInput.sendKeys(Key.ENTER);
358358 await messageInput.sendKeys(Key.ENTER);
359359
360- // Open the context items peek
361- const contextItemsPeek = await GUISelectors.getContextItemsPeek(view);
362- await contextItemsPeek.click();
363-
364- await TestUtils.waitForSuccess(async () => {
365- const firstContextItemInPeek =
366- await GUISelectors.getFirstContextItemsPeekItem(view);
367- await firstContextItemInPeek.click();
368-
369- // Check that item is there with correct name
370- const description = await firstContextItemInPeek.getText();
371- expect(description).to.include("Terminal");
372- });
373-
374360 // Check that the contents match what we expect (repeated back by the mock LLM)
375361 await TestUtils.waitForSuccess(() => {
376362 return GUISelectors.getThreadMessageByText(
modified extensions/vscode/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified extensions/vscode/package.json +1 −1
@@ -2,7 +2,7 @@
22 "name": "continue",
33 "icon": "media/icon.png",
44 "author": "Continue Dev, Inc",
5- "version": "1.1.58",
5+ "version": "1.1.59",
66 "repository": {
77 "type": "git",
88 "url": "https://github.com/continuedev/continue"
modified extensions/vscode/src/diff/vertical/handler.ts +21 −3
@@ -174,9 +174,12 @@
174174 // Clear deletion buffer
175175 await this.insertDeletionBuffer();
176176
177- await this.reapplyWithMyersDiff(diffLines);
178-
179- const range = new vscode.Range(this.startLine, 0, this.startLine, 0);
177+ const myersDiffs = await this.reapplyWithMyersDiff(diffLines);
178+
179+ // Scroll to the first diff
180+ const scrollToLine =
181+ this.getFirstChangedLine(myersDiffs) ?? this.startLine;
182+ const range = new vscode.Range(scrollToLine, 0, scrollToLine, 0);
180183 this.editor.revealRange(range, vscode.TextEditorRevealType.Default);
181184
182185 this.options.onStatusUpdate(
@@ -370,6 +373,8 @@
370373
371374 this.editorToVerticalDiffCodeLens.set(this.fileUri, codeLensBlocks);
372375 this.refreshCodeLens();
376+
377+ return myersDiffs;
373378 }
374379
375380 private async insertDeletionBuffer() {
@@ -550,4 +555,17 @@
550555
551556 this.refreshCodeLens();
552557 }
558+
559+ /**
560+ * Gets the first line number that was changed in a diff
561+ */
562+ private getFirstChangedLine(diff: DiffLine[]): number | null {
563+ for (let i = 0; i < diff.length; i++) {
564+ const item = diff[i];
565+ if (item.type === "old" || item.type === "new") {
566+ return this.startLine + i;
567+ }
568+ }
569+ return null;
570+ }
553571 }
modified gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +0 −1
@@ -219,7 +219,6 @@
219219 if (isGeneratingCodeBlock) {
220220 return (
221221 <span className="text-lightgray inline-flex items-center gap-2 text-right">
222- {!isExpanded ? `${numLines} line${plural}` : "Generating"}{" "}
223222 <div>
224223 <Spinner />
225224 </div>
modified gui/src/pages/gui/ToolCallDiv/EditFile.tsx +2 −3
@@ -6,15 +6,14 @@
66 changes: string;
77 historyIndex: number;
88 toolCallId?: string;
9- expandCodeblocks?: boolean;
109 };
1110
1211 export function EditFile(props: EditToolCallProps) {
13- if (!props.relativeFilePath || !props.changes) {
12+ if (!props.relativeFilePath) {
1413 return null;
1514 }
1615
17- const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath ?? "test.txt")} ${props.relativeFilePath}\n${props.changes}\n\`\`\``;
16+ const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath)} ${props.relativeFilePath}\n${props.changes}\n\`\`\``;
1817
1918 return (
2019 <StyledMarkdownPreview
modified gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx +0 −1
@@ -36,7 +36,6 @@
3636 case BuiltInToolNames.SearchAndReplaceInFile:
3737 return (
3838 <EditFile
39- expandCodeblocks
4039 relativeFilePath={args.filepath ?? ""}
4140 changes={args.diff ?? ""}
4241 toolCallId={toolCall.id}
modified gui/src/pages/gui/ToolCallDiv/index.tsx +16 −0
@@ -85,6 +85,22 @@
8585 );
8686 }
8787
88+ // Trying this out while it's an experimental feature
89+ // Obviously missing the truncate and args buttons
90+ // All the info from args is displayed here
91+ // But we'd need a nicer place to put the truncate button and the X icon when tool call fails
92+ if (
93+ props.toolCall.function?.name === BuiltInToolNames.SearchAndReplaceInFile
94+ ) {
95+ return (
96+ <FunctionSpecificToolCallDiv
97+ toolCall={props.toolCall}
98+ toolCallState={props.toolCallState}
99+ historyIndex={props.historyIndex}
100+ />
101+ );
102+ }
103+
88104 return (
89105 <ToolCallDisplay
90106 icon={getStatusIcon(props.toolCallState.status)}
modified gui/src/redux/thunks/streamNormalInput.ts +48 −3
@@ -1,7 +1,8 @@
11 import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
2-import { LLMFullCompletionOptions } from "core";
2+import { LLMFullCompletionOptions, ModelDescription, Tool } from "core";
33 import { modelSupportsTools } from "core/llm/autodetect";
44 import { ToCoreProtocol } from "core/protocol";
5+import { BuiltInToolNames } from "core/tools/builtIn";
56 import { selectActiveTools } from "../selectors/selectActiveTools";
67 import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
78 import { selectSelectedChatModel } from "../slices/configSlice";
@@ -21,6 +22,49 @@
2122 } from "../util/constructMessages";
2223 import { callCurrentTool } from "./callCurrentTool";
2324
25+/**
26+ * Filters tools based on the selected model's capabilities.
27+ * Returns either the edit file tool or search and replace tool, but not both.
28+ */
29+function filterToolsForModel(
30+ tools: Tool[],
31+ selectedModel: ModelDescription,
32+): Tool[] {
33+ const editFileTool = tools.find(
34+ (tool) => tool.function.name === BuiltInToolNames.EditExistingFile,
35+ );
36+ const searchAndReplaceTool = tools.find(
37+ (tool) => tool.function.name === BuiltInToolNames.SearchAndReplaceInFile,
38+ );
39+
40+ // If we don't have both tools, return tools as-is
41+ if (!editFileTool || !searchAndReplaceTool) {
42+ return tools;
43+ }
44+
45+ // Determine which tool to use based on the model
46+ const shouldUseFindReplace = shouldUseFindReplaceEdits(selectedModel);
47+
48+ // Filter out the unwanted tool
49+ return tools.filter((tool) => {
50+ if (tool.function.name === BuiltInToolNames.EditExistingFile) {
51+ return !shouldUseFindReplace;
52+ }
53+ if (tool.function.name === BuiltInToolNames.SearchAndReplaceInFile) {
54+ return shouldUseFindReplace;
55+ }
56+ return true;
57+ });
58+}
59+
60+/**
61+ * Determines whether to use search and replace tool instead of edit file
62+ * Right now we only know that this is reliable with Claude models
63+ */
64+function shouldUseFindReplaceEdits(model: ModelDescription): boolean {
65+ return model.model.includes("claude");
66+}
67+
2468 export const streamNormalInput = createAsyncThunk<
2569 void,
2670 {
@@ -37,8 +81,9 @@
3781 throw new Error("No chat model selected");
3882 }
3983
40- // Get tools
41- const activeTools = selectActiveTools(state);
84+ // Get tools and filter them based on the selected model
85+ const allActiveTools = selectActiveTools(state);
86+ const activeTools = filterToolsForModel(allActiveTools, selectedChatModel);
4287 const toolsSupported = modelSupportsTools(selectedChatModel);
4388
4489 // Construct completion options