Elffuss BraidHub

kikocis/continue public

Merge pull request #7660 from continuedev/pe/autoformat-results

feat: add autoformatting detection for edit tools
Changeseta368ad8eab5a12da76c63ad935694c934fe85fe0a38fa02cd5855b452b531da0
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-09-11 10:36 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-11 10:36 -07:00
Parentsb83510677c39, 579705a4fd4b

Browse the files at this changeset

4 files changed

modified core/config/types.ts +1 −0
@@ -1061,6 +1061,7 @@
10611061 filepath?: string;
10621062 fileContent?: string;
10631063 originalFileContent?: string;
1064+ autoFormattingDiff?: string;
10641065 }
10651066
10661067 export interface RangeInFileWithContents {
modified core/index.d.ts +1 −0
@@ -1387,6 +1387,7 @@
13871387 fileContent?: string;
13881388 originalFileContent?: string;
13891389 toolCallId?: string;
1390+ autoFormattingDiff?: string;
13901391 }
13911392
13921393 export interface StreamDiffLinesPayload {
modified extensions/vscode/src/diff/processDiff.ts +38 −5
@@ -1,8 +1,11 @@
11 import { Core } from "core/core";
22 import { DataLogger } from "core/data/log";
3+import { myersDiff } from "core/diff/myers";
4+
35 import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider";
46 import { editOutcomeTracker } from "../extension/EditOutcomeTracker";
57 import { VsCodeIde } from "../VsCodeIde";
8+
69 import { VerticalDiffManager } from "./vertical/manager";
710
811 export async function processDiff(
@@ -42,7 +45,8 @@
4245 }
4346
4447 if (streamId) {
45- const fileContent = await ide.readFile(newOrCurrentUri);
48+ // Capture file content before save to detect autoformatting
49+ const preSaveContent = await ide.readFile(newOrCurrentUri);
4650
4751 // Record the edit outcome before updating the apply state
4852 await editOutcomeTracker.recordEditOutcome(
@@ -51,16 +55,45 @@
5155 DataLogger.getInstance(),
5256 );
5357
58+ // Save the file
59+ await ide.saveFile(newOrCurrentUri);
60+
61+ // Capture file content after save to detect autoformatting
62+ const postSaveContent = await ide.readFile(newOrCurrentUri);
63+
64+ // Detect autoformatting by comparing normalized content
65+ let autoFormattingDiff: string | undefined;
66+ const normalizedPreSave = preSaveContent.trim();
67+ const normalizedPostSave = postSaveContent.trim();
68+
69+ if (normalizedPreSave !== normalizedPostSave) {
70+ // Auto-formatting was applied by the editor
71+ const diffLines = myersDiff(preSaveContent, postSaveContent);
72+ autoFormattingDiff = diffLines
73+ .map((line) => {
74+ switch (line.type) {
75+ case "old":
76+ return `-${line.line}`;
77+ case "new":
78+ return `+${line.line}`;
79+ case "same":
80+ return ` ${line.line}`;
81+ }
82+ })
83+ .join("\n");
84+ }
85+
5486 await sidebar.webviewProtocol.request("updateApplyState", {
55- fileContent,
87+ fileContent: postSaveContent, // Use post-save content
5688 filepath: newOrCurrentUri,
5789 streamId,
5890 status: "closed",
5991 numDiffs: 0,
6092 toolCallId,
93+ autoFormattingDiff, // Include autoformatting diff
6194 });
95+ } else {
96+ // Save the file even if no streamId
97+ await ide.saveFile(newOrCurrentUri);
6298 }
63-
64- // Save the file
65- await ide.saveFile(newOrCurrentUri);
6699 }
modified gui/src/redux/thunks/handleApplyStateUpdate.ts +18 −1
@@ -83,6 +83,24 @@
8383 }
8484
8585 if (accepted) {
86+ // Add autoformatting diff to tool output if present
87+ if (applyState.autoFormattingDiff) {
88+ dispatch(
89+ updateToolCallOutput({
90+ toolCallId: applyState.toolCallId,
91+ contextItems: [
92+ {
93+ icon: "info",
94+ name: "Auto-formatting Applied",
95+ description: "Editor auto-formatting changes",
96+ content: `Along with your edits, the editor applied the following auto-formatting:\n\n${applyState.autoFormattingDiff}\n\n(Note: Pay close attention to changes such as single quotes being converted to double quotes, semicolons being removed or added, long lines being broken into multiple lines, adjusting indentation style, adding/removing trailing commas, etc. This will help you ensure future SEARCH/REPLACE operations to this file are accurate.)`,
97+ hidden: false,
98+ },
99+ ],
100+ }),
101+ );
102+ }
103+
86104 if (toolCallState.status !== "errored") {
87105 dispatch(
88106 acceptToolCall({
@@ -125,7 +143,6 @@
125143 );
126144 }
127145 }
128- // TODO return output from edit tools so the model knows the result
129146 }
130147 }
131148 }