Elffuss BraidHub

kikocis/continue public

Merge pull request #7701 from continuedev/nate/improve-find-replace

feat: improvements to find and replace
Changeset87f75892af56dc4d1c4e30ea1bafae02b42f1fbf4ffda7dfecaeb3f86bee819e
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-09-15 11:19 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-15 11:19 -07:00
Parentsa660fc8009f5, fb1cad4526eb

Browse the files at this changeset

18 files changed

modified core/tools/definitions/createNewFile.ts +3 −3
@@ -4,9 +4,9 @@
44 export const createNewFileTool: Tool = {
55 type: "function",
66 displayTitle: "Create New File",
7- wouldLikeTo: "create a new file at {{{ filepath }}}",
8- isCurrently: "creating a new file at {{{ filepath }}}",
9- hasAlready: "created a new file at {{{ filepath }}}",
7+ wouldLikeTo: "create {{{ filepath }}}",
8+ isCurrently: "creating {{{ filepath }}}",
9+ hasAlready: "created {{{ filepath }}}",
1010 group: BUILT_IN_GROUP_NAME,
1111 readonly: false,
1212 isInstant: true,
modified core/tools/definitions/fetchUrlContent.ts +1 −1
@@ -6,7 +6,7 @@
66 displayTitle: "Read URL",
77 wouldLikeTo: "fetch {{{ url }}}",
88 isCurrently: "fetching {{{ url }}}",
9- hasAlready: "viewed {{{ url }}}",
9+ hasAlready: "fetched {{{ url }}}",
1010 readonly: true,
1111 isInstant: true,
1212 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/globSearch.ts +3 −3
@@ -4,9 +4,9 @@
44 export const globSearchTool: Tool = {
55 type: "function",
66 displayTitle: "Glob File Search",
7- wouldLikeTo: 'find file matches for "{{{ pattern }}}"',
8- isCurrently: 'finding file matches for "{{{ pattern }}}"',
9- hasAlready: 'retrieved file matches for "{{{ pattern }}}"',
7+ wouldLikeTo: 'search for files like "{{{ pattern }}}"',
8+ isCurrently: 'searching for files like "{{{ pattern }}}"',
9+ hasAlready: 'searched for files like "{{{ pattern }}}"',
1010 readonly: true,
1111 isInstant: true,
1212 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/grepSearch.ts +3 −3
@@ -4,9 +4,9 @@
44 export const grepSearchTool: Tool = {
55 type: "function",
66 displayTitle: "Grep Search",
7- wouldLikeTo: 'search for "{{{ query }}}" in the repository',
8- isCurrently: 'getting search results for "{{{ query }}}"',
9- hasAlready: 'retrieved search results for "{{{ query }}}"',
7+ wouldLikeTo: 'search for "{{{ query }}}"',
8+ isCurrently: 'searching for "{{{ query }}}"',
9+ hasAlready: 'searched for "{{{ query }}}"',
1010 readonly: true,
1111 isInstant: true,
1212 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/ls.ts +3 −3
@@ -5,9 +5,9 @@
55 export const lsTool: Tool = {
66 type: "function",
77 displayTitle: "ls",
8- wouldLikeTo: "list files and folders in {{{ dirPath }}}",
9- isCurrently: "listing files and folders in {{{ dirPath }}}",
10- hasAlready: "listed files and folders in {{{ dirPath }}}",
8+ wouldLikeTo: "list files in {{{ dirPath }}}",
9+ isCurrently: "listing files in {{{ dirPath }}}",
10+ hasAlready: "listed files in {{{ dirPath }}}",
1111 readonly: true,
1212 isInstant: true,
1313 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/readCurrentlyOpenFile.ts +1 −1
@@ -6,7 +6,7 @@
66 displayTitle: "Read Currently Open File",
77 wouldLikeTo: "read the current file",
88 isCurrently: "reading the current file",
9- hasAlready: "viewed the current file",
9+ hasAlready: "read the current file",
1010 readonly: true,
1111 isInstant: true,
1212 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/readFile.ts +1 −1
@@ -6,7 +6,7 @@
66 displayTitle: "Read File",
77 wouldLikeTo: "read {{{ filepath }}}",
88 isCurrently: "reading {{{ filepath }}}",
9- hasAlready: "viewed {{{ filepath }}}",
9+ hasAlready: "read {{{ filepath }}}",
1010 readonly: true,
1111 isInstant: true,
1212 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/readFileRange.ts +1 −1
@@ -9,7 +9,7 @@
99 isCurrently:
1010 "reading lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
1111 hasAlready:
12- "viewed lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
12+ "read lines {{{ startLine }}}-{{{ endLine }}} of {{{ filepath }}}",
1313 readonly: true,
1414 isInstant: true,
1515 group: BUILT_IN_GROUP_NAME,
modified core/tools/definitions/singleFindAndReplace.ts +3 −3
@@ -12,9 +12,9 @@
1212 export const singleFindAndReplaceTool: Tool = {
1313 type: "function",
1414 displayTitle: "Find and Replace",
15- wouldLikeTo: "find and replace in {{{ filepath }}}",
16- isCurrently: "finding and replacing in {{{ filepath }}}",
17- hasAlready: "found and replaced in {{{ filepath }}}",
15+ wouldLikeTo: "edit {{{ filepath }}}",
16+ isCurrently: "editing {{{ filepath }}}",
17+ hasAlready: "edited {{{ filepath }}}",
1818 group: BUILT_IN_GROUP_NAME,
1919 readonly: false,
2020 isInstant: false,
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.test.tsx +5 −4
@@ -236,10 +236,11 @@
236236
237237 render(<FindAndReplaceDisplay {...defaultProps} />);
238238
239- const toggleButton = screen.getByTestId("toggle-find-and-replace-diff");
240- fireEvent.click(toggleButton);
241-
242- expect(screen.getByText("Error generating diff")).toBeInTheDocument();
239+ // When diff generation errors, component shows a friendly message
240+ // without rendering the expand/collapse container
241+ expect(
242+ screen.getByText("The searched string was not found in the file"),
243+ ).toBeInTheDocument();
243244 });
244245
245246 it("should show 'No changes to display' when diff is empty", () => {
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +63 −23
@@ -30,7 +30,7 @@
3030
3131 function EllipsisLine() {
3232 return (
33- <div className="text-description-muted px-3 py-1 text-center font-mono">
33+ <div className="text-description-muted px-3 py-1 text-left font-mono">
3434 ⋯
3535 </div>
3636 );
@@ -68,6 +68,19 @@
6868 );
6969 }
7070
71+function DiffStats({ added, removed }: { added: number; removed: number }) {
72+ if (added === 0 && removed === 0) {
73+ return null;
74+ }
75+
76+ return (
77+ <div className="flex items-center gap-1 font-mono text-xs">
78+ {added > 0 && <span className="text-success">+{added}</span>}
79+ {removed > 0 && <span className="text-error">-{removed}</span>}
80+ </div>
81+ );
82+}
83+
7184 export function FindAndReplaceDisplay({
7285 fileUri,
7386 relativeFilePath,
@@ -141,6 +154,30 @@
141154 }
142155 }, [currentFileContent, edits]);
143156
157+ const diffStats = useMemo(() => {
158+ if (!diffResult?.diff) {
159+ return { added: 0, removed: 0 };
160+ }
161+
162+ let added = 0;
163+ let removed = 0;
164+
165+ diffResult.diff.forEach((part) => {
166+ const lines = part.value.split("\n");
167+ // Exclude empty line at the end (similar to DiffLines component logic)
168+ const lineCount =
169+ lines[lines.length - 1] === "" ? lines.length - 1 : lines.length;
170+
171+ if (part.added) {
172+ added += lineCount;
173+ } else if (part.removed) {
174+ removed += lineCount;
175+ }
176+ });
177+
178+ return { added, removed };
179+ }, [diffResult?.diff]);
180+
144181 const statusIcon = useMemo(() => {
145182 const status = toolCallState?.status;
146183 if (status) {
@@ -174,24 +211,27 @@
174211 setIsExpanded(!showContent);
175212 }}
176213 >
177- <div className="flex max-w-[50%] flex-row items-center text-xs">
178- {statusIcon}
179- <ChevronDownIcon
180- data-testid="toggle-find-and-replace-diff"
181- className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer select-none transition-all hover:brightness-125 ${
182- showContent ? "rotate-0" : "-rotate-90"
183- }`}
184- />
185- <FileInfo
186- filepath={displayName || "..."}
187- onClick={(e) => {
188- if (!fileUri) {
189- return;
190- }
191- e.stopPropagation();
192- ideMessenger.post("openFile", { path: fileUri });
193- }}
194- />
214+ <div className="flex min-w-0 flex-1 flex-row items-center gap-2 text-xs">
215+ <div className="flex min-w-0 flex-row items-center">
216+ {statusIcon}
217+ <ChevronDownIcon
218+ data-testid="toggle-find-and-replace-diff"
219+ className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer select-none transition-all hover:brightness-125 ${
220+ showContent ? "rotate-0" : "-rotate-90"
221+ }`}
222+ />
223+ <FileInfo
224+ filepath={displayName || "..."}
225+ onClick={(e) => {
226+ if (!fileUri) {
227+ return;
228+ }
229+ e.stopPropagation();
230+ ideMessenger.post("openFile", { path: fileUri });
231+ }}
232+ />
233+ </div>
234+ <DiffStats added={diffStats.added} removed={diffStats.removed} />
195235 </div>
196236
197237 {applyState && (
@@ -218,10 +258,10 @@
218258 );
219259
220260 if (diffResult?.error) {
221- return renderContainer(
222- <div className="text-error p-3 text-sm">
223- <strong>Error generating diff</strong>
224- </div>,
261+ return (
262+ <div className="text-description mt-2 px-3">
263+ The searched string was not found in the file
264+ </div>
225265 );
226266 }
227267
modified gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +0 −19
@@ -6,9 +6,7 @@
66 } from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
77 import { IdeMessengerContext } from "../../../context/IdeMessenger";
88 import { ToggleWithIcon } from "./ToggleWithIcon";
9-import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
109 import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
11-import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
1210 import { toolCallStateToContextItems } from "./utils";
1311
1412 interface SimpleToolCallUIProps {
@@ -31,11 +29,6 @@
3129 }, [toolCallState]);
3230
3331 const [open, setOpen] = useState(false);
34- const [showingArgs, setShowingArgs] = useState(false);
35-
36- const args: [string, any][] = useMemo(() => {
37- return Object.entries(toolCallState.parsedArgs);
38- }, [toolCallState.parsedArgs]);
3932
4033 const isToggleable = shownContextItems.length > 1;
4134 const isSingleItem = shownContextItems.length === 1;
@@ -81,19 +74,7 @@
8174 />
8275 <ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
8376 </div>
84- <div className="flex flex-row items-center gap-1.5">
85- {!!toolCallState.output?.length && (
86- <ToolTruncateHistoryIcon historyIndex={historyIndex} />
87- )}
88- {args.length > 0 ? (
89- <ArgsToggleIcon
90- isShowing={showingArgs}
91- setIsShowing={setShowingArgs}
92- />
93- ) : null}
94- </div>
9577 </div>
96- <ArgsItems args={args} isShowing={showingArgs} />
9778
9879 {isToggleable && (
9980 <div
modified gui/src/pages/gui/ToolCallDiv/ToolCallDisplay.tsx +0 −23
@@ -1,8 +1,5 @@
11 import { Tool, ToolCallState } from "core";
2-import { useMemo, useState } from "react";
3-import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
42 import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
5-import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
63
74 interface ToolCallDisplayProps {
85 children: React.ReactNode;
@@ -19,12 +16,6 @@
1916 icon,
2017 historyIndex,
2118 }: ToolCallDisplayProps) {
22- const [argsExpanded, setArgsExpanded] = useState(false);
23-
24- const args: [string, any][] = useMemo(() => {
25- return Object.entries(toolCallState.parsedArgs);
26- }, [toolCallState.parsedArgs]);
27-
2819 return (
2920 <div className="flex flex-col justify-center px-4">
3021 <div className="mb-2 flex flex-col">
@@ -38,21 +29,7 @@
3829 )}
3930 <ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
4031 </div>
41- <div className="flex flex-row items-center gap-1.5">
42- {!!toolCallState.output && (
43- <ToolTruncateHistoryIcon historyIndex={historyIndex} />
44- )}
45- {!!args.length ? (
46- <ArgsToggleIcon
47- isShowing={argsExpanded}
48- setIsShowing={setArgsExpanded}
49- />
50- ) : null}
51- </div>
5232 </div>
53- {argsExpanded && !!args.length && (
54- <ArgsItems args={args} isShowing={argsExpanded} />
55- )}
5633 </div>
5734 <div>{children}</div>
5835 </div>
modified gui/src/pages/gui/ToolCallDiv/utils.tsx +1 −1
@@ -34,7 +34,7 @@
3434
3535 switch (status) {
3636 case "generating":
37- return "is generating output to";
37+ return "will";
3838 case "generated":
3939 return "wants to";
4040 case "calling":
modified gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +2 −0
@@ -73,6 +73,8 @@
7373 store.dispatch(setInactive());
7474
7575 ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR];
76+ // Provide empty open files to avoid MockIdeMessenger throwing on getOpenFiles
77+ ideMessenger.responses["getOpenFiles"] = [] as any;
7678 ideMessenger.responses["tools/evaluatePolicy"] = {
7779 policy: "allowedWithPermission",
7880 };
modified gui/src/redux/thunks/callToolById.ts +5 −3
@@ -11,10 +11,10 @@
1111 setToolCallCalling,
1212 updateToolCallOutput,
1313 } from "../slices/sessionSlice";
14+import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
1415 import { ThunkApiType } from "../store";
1516 import { findToolCallById, logToolUsage } from "../util";
1617 import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
17-import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
1818
1919 export const callToolById = createAsyncThunk<
2020 void,
@@ -43,14 +43,15 @@
4343 DEFAULT_TOOL_SETTING;
4444 const isAutoApproved = toolPolicy === "allowedWithoutPermission";
4545
46+ const selectedChatModel = selectSelectedChatModel(state);
47+
4648 posthog.capture("gui_tool_call_decision", {
49+ model: selectedChatModel,
4750 decision: isAutoApproved ? "auto_accept" : "accept",
4851 toolName: toolCallState.toolCall.function.name,
4952 toolCallId: toolCallId,
5053 });
5154
52- const selectedChatModel = selectSelectedChatModel(state);
53-
5455 if (!selectedChatModel) {
5556 throw new Error("No model selected");
5657 }
@@ -129,6 +130,7 @@
129130 // Capture telemetry for tool call execution outcome with duration
130131 const duration_ms = Date.now() - startTime;
131132 posthog.capture("gui_tool_call_outcome", {
133+ model: selectedChatModel,
132134 succeeded: errorMessage === undefined,
133135 toolName: toolCallState.toolCall.function.name,
134136 errorMessage: errorMessage,
modified gui/src/redux/thunks/cancelToolCall.ts +3 −0
@@ -1,5 +1,6 @@
11 import { createAsyncThunk } from "@reduxjs/toolkit";
22 import posthog from "posthog-js";
3+import { selectSelectedChatModel } from "../slices/configSlice";
34 import {
45 cancelToolCall as cancelToolCallAction,
56 updateToolCallOutput,
@@ -19,6 +20,7 @@
1920 ThunkApiType
2021 >("chat/cancelToolCall", async ({ toolCallId }, { dispatch, getState }) => {
2122 const state = getState();
23+ const selectedChatModel = selectSelectedChatModel(state);
2224 const continueAfterToolRejection =
2325 state.config.config.ui?.continueAfterToolRejection;
2426 const toolCallState = findToolCallById(state.session.history, toolCallId);
@@ -26,6 +28,7 @@
2628 if (toolCallState) {
2729 // Track tool call rejection
2830 posthog.capture("gui_tool_call_decision", {
31+ model: selectedChatModel,
2932 decision: "reject",
3033 toolName: toolCallState.toolCall.function.name,
3134 toolCallId: toolCallId,
modified gui/src/redux/thunks/streamResponse_toolCalls.test.ts +36 −22
@@ -565,18 +565,25 @@
565565 expect(result.type).toBe("chat/streamResponse/fulfilled");
566566
567567 // Verify telemetry events for auto-approved tool execution
568- expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_decision", {
569- decision: "auto_accept",
570- toolName: "search_codebase",
571- toolCallId: "tool-call-1",
572- });
568+ // Use partial matching to allow additional fields (e.g. model) in payload
569+ expect(mockPosthog.capture).toHaveBeenCalledWith(
570+ "gui_tool_call_decision",
571+ expect.objectContaining({
572+ decision: "auto_accept",
573+ toolName: "search_codebase",
574+ toolCallId: "tool-call-1",
575+ }),
576+ );
573577
574- expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_outcome", {
575- succeeded: true,
576- toolName: "search_codebase",
577- errorMessage: undefined,
578- duration_ms: expect.any(Number),
579- });
578+ expect(mockPosthog.capture).toHaveBeenCalledWith(
579+ "gui_tool_call_outcome",
580+ expect.objectContaining({
581+ succeeded: true,
582+ toolName: "search_codebase",
583+ errorMessage: undefined,
584+ duration_ms: expect.any(Number),
585+ }),
586+ );
580587
581588 // Verify final state after tool call execution
582589 const finalState = mockStoreWithToolSettings.getState();
@@ -2810,18 +2817,25 @@
28102817 ]);
28112818
28122819 // Verify telemetry events for manual approval flow
2813- expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_decision", {
2814- decision: "accept",
2815- toolName: "search_codebase",
2816- toolCallId: "tool-approval-flow-1",
2817- });
2820+ // Use partial matching to allow additional fields (e.g. model) in payload
2821+ expect(mockPosthog.capture).toHaveBeenCalledWith(
2822+ "gui_tool_call_decision",
2823+ expect.objectContaining({
2824+ decision: "accept",
2825+ toolName: "search_codebase",
2826+ toolCallId: "tool-approval-flow-1",
2827+ }),
2828+ );
28182829
2819- expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_outcome", {
2820- succeeded: true,
2821- toolName: "search_codebase",
2822- errorMessage: undefined,
2823- duration_ms: expect.any(Number),
2824- });
2830+ expect(mockPosthog.capture).toHaveBeenCalledWith(
2831+ "gui_tool_call_outcome",
2832+ expect.objectContaining({
2833+ succeeded: true,
2834+ toolName: "search_codebase",
2835+ errorMessage: undefined,
2836+ duration_ms: expect.any(Number),
2837+ }),
2838+ );
28252839
28262840 // Verify IDE messenger calls for tool execution
28272841 expect(mockIdeMessengerApproval.request).toHaveBeenCalledWith(