Turbo edits v2 (#1653)

Fixes #1222 #1646 

TODOs
- [x] description?
- [x] collect errors across all files for turbo edits
- [x] be forgiving around whitespaces
- [x] write e2e tests
- [x] do more manual testing across different models



<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds Turbo Edits v2 search-replace flow with settings/UI selector,
parser/renderer, dry-run validation + fallback, proposal integration,
and comprehensive tests; updates licensing.
> 
> - **Engine/Processing**:
> - Add `dyad-search-replace` end-to-end: parsing
(`getDyadSearchReplaceTags`), markdown rendering (`DyadSearchReplace`),
and application (`applySearchReplace`) with dry-run validation and
fallback to `dyad-write`.
> - Inject Turbo Edits v2 system prompt; toggle via
`isTurboEditsV2Enabled`; disable classic lazy edits when v2 is on.
> - Include search-replace edits in proposals and full-response
processing.
> - **Settings/UI**:
> - Introduce `proLazyEditsMode` (`off`|`v1`|`v2`) and helper selectors;
update `ProModeSelector` with Turbo Edits and Smart Context selectors
(`data-testid`s).
> - **LLM/token flow**:
> - Construct system prompt conditionally; update token counting and
chat stream to validate and repair search-replace responses.
> - **Tests**:
> - Add unit tests for search-replace processor; e2e tests for Turbo
Edits v2 and options; fixtures and snapshots.
> - **Licensing/Docs**:
> - Add `src/pro/LICENSE` (FSL 1.1 ALv2 future), update root `LICENSE`
and README license section.
> - **Tooling**:
> - Update `.prettierignore`; enhance test helpers (selectors, path
normalization, snapshot filtering).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7aefa02bfae2fe22a25c7d87f3c4c326f820f1e6. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This commit is contained in:
Will Chen
2025-10-28 11:36:20 -07:00
committed by GitHub
parent 8a3bc53832
commit a8f3c97396
36 changed files with 2537 additions and 72 deletions

View File

@@ -0,0 +1,10 @@
Example with turbo edit v2
<dyad-search-replace path="src/pages/Index.tsx">
<<<<<<< SEARCH
// Intentionally DO NOT MATCH ANYTHING TO TRIGGER FALLBACK
<h1 className="text-4xl font-bold mb-4">Welcome to Your Blank App</h1>
=======
<h1 className="text-4xl font-bold mb-4">Welcome to the UPDATED App</h1>
>>>>>>> REPLACE
</dyad-search-replace>
End of turbo edit

View File

@@ -0,0 +1,9 @@
Example with turbo edit v2
<dyad-search-replace path="src/pages/Index.tsx">
<<<<<<< SEARCH
<h1 className="text-4xl font-bold mb-4">Welcome to Your Blank App</h1>
=======
<h1 className="text-4xl font-bold mb-4">Welcome to the UPDATED App</h1>
>>>>>>> REPLACE
</dyad-search-replace>
End of turbo edit

View File

@@ -73,14 +73,23 @@ class ProModesDialog {
async setSmartContextMode(mode: "balanced" | "off" | "conservative") {
await this.page
.getByTestId("smart-context-selector")
.getByRole("button", {
name: mode.charAt(0).toUpperCase() + mode.slice(1),
})
.click();
}
async toggleTurboEdits() {
await this.page.getByRole("switch", { name: "Turbo Edits" }).click();
async setTurboEditsMode(mode: "off" | "classic" | "search-replace") {
await this.page
.getByTestId("turbo-edits-selector")
.getByRole("button", {
name:
mode === "search-replace"
? "Search & replace"
: mode.charAt(0).toUpperCase() + mode.slice(1),
})
.click();
}
}
@@ -362,7 +371,7 @@ export class PageObject {
await expect(this.page.getByRole("dialog")).toMatchAriaSnapshot();
}
async snapshotAppFiles({ name }: { name: string }) {
async snapshotAppFiles({ name, files }: { name: string; files?: string[] }) {
const currentAppName = await this.getCurrentAppName();
if (!currentAppName) {
throw new Error("No app selected");
@@ -374,10 +383,17 @@ export class PageObject {
}
await expect(() => {
const filesData = generateAppFilesSnapshotData(appPath, appPath);
let filesData = generateAppFilesSnapshotData(appPath, appPath);
// Sort by relative path to ensure deterministic output
filesData.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
if (files) {
filesData = filesData.filter((file) =>
files.some(
(f) => normalizePath(f) === normalizePath(file.relativePath),
),
);
}
const snapshotContent = filesData
.map(
@@ -1232,3 +1248,7 @@ function prettifyDump(
})
.join("\n\n");
}
function normalizePath(path: string): string {
return path.replace(/\\/g, "/");
}

View File

@@ -0,0 +1,28 @@
{
"selectedModel": {
"name": "auto",
"provider": "auto"
},
"providerSettings": {
"auto": {
"apiKey": {
"value": "testdyadkey",
"encryptionType": "plaintext"
}
}
},
"telemetryConsent": "unset",
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"enableDyadPro": true,
"experiments": {},
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": true,
"enableProSmartFilesContextMode": true,
"selectedTemplateId": "react",
"selectedChatMode": "build",
"enableAutoFixProblems": false,
"enableAutoUpdate": true,
"releaseChannel": "stable",
"isTestMode": true
}

View File

@@ -0,0 +1,29 @@
{
"selectedModel": {
"name": "auto",
"provider": "auto"
},
"providerSettings": {
"auto": {
"apiKey": {
"value": "testdyadkey",
"encryptionType": "plaintext"
}
}
},
"telemetryConsent": "unset",
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"enableDyadPro": true,
"experiments": {},
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": true,
"proLazyEditsMode": "v1",
"enableProSmartFilesContextMode": true,
"selectedTemplateId": "react",
"selectedChatMode": "build",
"enableAutoFixProblems": false,
"enableAutoUpdate": true,
"releaseChannel": "stable",
"isTestMode": true
}

View File

@@ -0,0 +1,29 @@
{
"selectedModel": {
"name": "auto",
"provider": "auto"
},
"providerSettings": {
"auto": {
"apiKey": {
"value": "testdyadkey",
"encryptionType": "plaintext"
}
}
},
"telemetryConsent": "unset",
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"enableDyadPro": true,
"experiments": {},
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": true,
"proLazyEditsMode": "v2",
"enableProSmartFilesContextMode": true,
"selectedTemplateId": "react",
"selectedChatMode": "build",
"enableAutoFixProblems": false,
"enableAutoUpdate": true,
"releaseChannel": "stable",
"isTestMode": true
}

View File

@@ -0,0 +1,29 @@
{
"selectedModel": {
"name": "auto",
"provider": "auto"
},
"providerSettings": {
"auto": {
"apiKey": {
"value": "testdyadkey",
"encryptionType": "plaintext"
}
}
},
"telemetryConsent": "unset",
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"enableDyadPro": true,
"experiments": {},
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": false,
"proLazyEditsMode": "off",
"enableProSmartFilesContextMode": true,
"selectedTemplateId": "react",
"selectedChatMode": "build",
"enableAutoFixProblems": false,
"enableAutoUpdate": true,
"releaseChannel": "stable",
"isTestMode": true
}

View File

@@ -0,0 +1,2 @@
=== src/pages/Index.tsx ===
// FILE IS REPLACED WITH FALLBACK WRITE.

View File

@@ -0,0 +1,20 @@
=== src/pages/Index.tsx ===
// Update this page (the content is just a fallback if you fail to update the page)
import { MadeWithDyad } from "@/components/made-with-dyad";
const Index = () => {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-100">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4">Welcome to the UPDATED App</h1>
<p className="text-xl text-gray-600">
Start building your amazing project here!
</p>
</div>
<MadeWithDyad />
</div>
);
};
export default Index;

View File

@@ -0,0 +1,15 @@
- paragraph: tc=turbo-edits-v2
- paragraph: Example with turbo edit v2
- img
- text: Search & Replace Index.tsx
- img
- text: src/pages/Index.tsx
- paragraph: End of turbo edit
- button:
- img
- img
- text: less than a minute ago
- button "Request ID":
- img
- button "Retry":
- img

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,153 @@
===
role: system
message:
${BUILD_SYSTEM_PREFIX}
# Tech Stack
- You are building a React application.
- Use TypeScript.
- Use React Router. KEEP the routes in src/App.tsx
- Always put source code in the src folder.
- Put pages into src/pages/
- Put components into src/components/
- The main page (default page) is src/pages/Index.tsx
- UPDATE the main page to include the new components. OTHERWISE, the user can NOT see any components!
- ALWAYS try to use the shadcn/ui library.
- Tailwind CSS: always use Tailwind CSS for styling components. Utilize Tailwind classes extensively for layout, spacing, colors, and other design aspects.
Available packages and libraries:
- The lucide-react package is installed for icons.
- You ALREADY have ALL the shadcn/ui components and their dependencies installed. So you don't need to install them again.
- You have ALL the necessary Radix UI components installed.
- Use prebuilt components from the shadcn/ui library after importing them. Note that these files shouldn't be edited, so make new components if you need to change them.
${BUILD_SYSTEM_POSTFIX}
# Search-replace file edits
- Request to apply PRECISE, TARGETED modifications to an existing file by searching for specific sections of content and replacing them. This tool is for SURGICAL EDITS ONLY - specific changes to existing code.
- You can perform multiple distinct search and replace operations within a single `dyad-search-replace` call by providing multiple SEARCH/REPLACE blocks. This is the preferred way to make several targeted changes efficiently.
- The SEARCH section must match exactly ONE existing content section - it must be unique within the file, including whitespace and indentation.
- When applying the diffs, be extra careful to remember to change any closing brackets or other syntax that may be affected by the diff farther down in the file.
- ALWAYS make as many changes in a single 'dyad-search-replace' call as possible using multiple SEARCH/REPLACE blocks.
- Do not use both `dyad-write` and `dyad-search-replace` on the same file within a single response.
- Include a brief description of the changes you are making in the `description` parameter.
Diff format:
```
<<<<<<< SEARCH
[exact content to find including whitespace]
=======
[new content to replace with]
>>>>>>> REPLACE
```
Example:
Original file:
```
def calculate_total(items):
total = 0
for item in items:
total += item
return total
```
Search/Replace content:
```
<<<<<<< SEARCH
def calculate_total(items):
total = 0
for item in items:
total += item
return total
=======
def calculate_total(items):
"""Calculate total with 10% markup"""
return sum(item * 1.1 for item in items)
>>>>>>> REPLACE
```
Search/Replace content with multiple edits:
```
<<<<<<< SEARCH
def calculate_total(items):
sum = 0
=======
def calculate_sum(items):
sum = 0
>>>>>>> REPLACE
<<<<<<< SEARCH
total += item
return total
=======
sum += item
return sum
>>>>>>> REPLACE
```
Usage:
<dyad-search-replace path="path/to/file.js" description="Brief description of the changes you are making">
<<<<<<< SEARCH
def calculate_total(items):
sum = 0
=======
def calculate_sum(items):
sum = 0
>>>>>>> REPLACE
<<<<<<< SEARCH
total += item
return total
=======
sum += item
return sum
>>>>>>> REPLACE
</dyad-search-replace>
If the user wants to use supabase or do something that requires auth, database or server-side functions (e.g. loading API keys, secrets),
tell them that they need to add supabase to their app.
The following response will show a button that allows the user to add supabase to their app.
<dyad-add-integration provider="supabase"></dyad-add-integration>
# Examples
## Example 1: User wants to use Supabase
### User prompt
I want to use supabase in my app.
### Assistant response
You need to first add Supabase to your app.
<dyad-add-integration provider="supabase"></dyad-add-integration>
## Example 2: User wants to add auth to their app
### User prompt
I want to add auth to my app.
### Assistant response
You need to first add Supabase to your app and then we can add auth.
<dyad-add-integration provider="supabase"></dyad-add-integration>
===
role: user
message: [dump]

View File

@@ -0,0 +1,25 @@
- paragraph: tc=turbo-edits-v2-trigger-fallback
- paragraph: Example with turbo edit v2
- img
- text: Search & Replace Index.tsx
- img
- text: src/pages/Index.tsx
- paragraph: End of turbo edit
- img
- text: Warning Could not apply Turbo Edits properly for some of the files; re-generating code......
- img
- img
- text: Index.tsx
- button "Edit":
- img
- img
- text: "src/pages/Index.tsx Summary: Rewrite file."
- paragraph: "[[dyad-dump-path=*]]"
- button:
- img
- img
- text: less than a minute ago
- button "Request ID":
- img
- button "Retry":
- img

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
import { test } from "./helpers/test_helper";
test("switching turbo edits saves the right setting", async ({ po }) => {
await po.setUpDyadPro();
const proModesDialog = await po.openProModesDialog({
location: "home-chat-input-container",
});
await po.snapshotSettings();
await proModesDialog.setTurboEditsMode("classic");
await po.snapshotSettings();
await proModesDialog.setTurboEditsMode("search-replace");
await po.snapshotSettings();
await proModesDialog.setTurboEditsMode("off");
await po.snapshotSettings();
});

View File

@@ -0,0 +1,49 @@
import { testSkipIfWindows } from "./helpers/test_helper";
testSkipIfWindows("turbo edits v2 - search-replace dump", async ({ po }) => {
await po.setUpDyadPro();
const proModesDialog = await po.openProModesDialog({
location: "home-chat-input-container",
});
await proModesDialog.setTurboEditsMode("search-replace");
await proModesDialog.close();
await po.sendPrompt("[dump]");
await po.snapshotServerDump("request");
await po.snapshotServerDump("all-messages");
});
testSkipIfWindows("turbo edits v2 - search-replace approve", async ({ po }) => {
await po.setUpDyadPro();
const proModesDialog = await po.openProModesDialog({
location: "home-chat-input-container",
});
await proModesDialog.setTurboEditsMode("search-replace");
await proModesDialog.close();
await po.sendPrompt("tc=turbo-edits-v2");
await po.snapshotMessages();
await po.approveProposal();
await po.snapshotAppFiles({
name: "after-search-replace",
files: ["src/pages/Index.tsx"],
});
});
testSkipIfWindows(
"turbo edits v2 - search-replace fallback",
async ({ po }) => {
await po.setUpDyadPro();
const proModesDialog = await po.openProModesDialog({
location: "home-chat-input-container",
});
await proModesDialog.setTurboEditsMode("search-replace");
await proModesDialog.close();
await po.sendPrompt("tc=turbo-edits-v2-trigger-fallback");
await po.snapshotServerDump("request");
await po.snapshotMessages({ replaceDumpPath: true });
await po.approveProposal();
await po.snapshotAppFiles({
name: "after-search-replace-fallback",
files: ["src/pages/Index.tsx"],
});
},
);