Skip to content

Commit 2ed2dc5

Browse files
committed
Add checkbox for editing with diffs
1 parent e03fdd7 commit 2ed2dc5

File tree

12 files changed

+60
-19
lines changed

12 files changed

+60
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Roo Cline Changelog
22

3+
## [2.1.12]
4+
5+
- Incorporate JoziGila's [PR](https://github.com/cline/cline/pull/158) to add support for editing through diffs
6+
37
## [2.1.11]
48

59
- Incorporate lloydchang's [PR](https://github.com/RooVetGit/Roo-Cline/pull/42) to add support for OpenRouter compression

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Roo Cline",
44
"description": "A fork of Cline, an autonomous coding agent, with some added experimental configuration and automation features.",
55
"publisher": "RooVeterinaryInc",
6-
"version": "2.1.11",
6+
"version": "2.1.12",
77
"icon": "assets/icons/rocket.png",
88
"galleryBanner": {
99
"color": "#617A91",

src/core/Cline.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class Cline {
6565
private browserSession: BrowserSession
6666
private didEditFile: boolean = false
6767
customInstructions?: string
68+
diffEnabled?: boolean
6869

6970
apiConversationHistory: Anthropic.MessageParam[] = []
7071
clineMessages: ClineMessage[] = []
@@ -94,6 +95,7 @@ export class Cline {
9495
provider: ClineProvider,
9596
apiConfiguration: ApiConfiguration,
9697
customInstructions?: string,
98+
diffEnabled?: boolean,
9799
task?: string,
98100
images?: string[],
99101
historyItem?: HistoryItem,
@@ -105,7 +107,7 @@ export class Cline {
105107
this.browserSession = new BrowserSession(provider.context)
106108
this.diffViewProvider = new DiffViewProvider(cwd)
107109
this.customInstructions = customInstructions
108-
110+
this.diffEnabled = diffEnabled
109111
if (historyItem) {
110112
this.taskId = historyItem.id
111113
this.resumeTaskFromHistory()
@@ -750,7 +752,7 @@ export class Cline {
750752
}
751753

752754
async *attemptApiRequest(previousApiReqIndex: number): ApiStream {
753-
const systemPrompt = await SYSTEM_PROMPT(cwd, this.api.getModel().info.supportsComputerUse ?? false, true) + await addCustomInstructions(this.customInstructions ?? '', cwd)
755+
const systemPrompt = await SYSTEM_PROMPT(cwd, this.api.getModel().info.supportsComputerUse ?? false, !!this.diffEnabled) + await addCustomInstructions(this.customInstructions ?? '', cwd)
754756

755757
// If the previous API request's total token usage is close to the context window, truncate the conversation history to free up space for the new request
756758
if (previousApiReqIndex >= 0) {
@@ -1200,10 +1202,6 @@ export class Cline {
12001202
break
12011203
}
12021204

1203-
if (originalContent.endsWith("\n") && !newContent.endsWith("\n")) {
1204-
newContent += "\n"
1205-
}
1206-
12071205
// Create a diff for display purposes
12081206
const diffRepresentation = diff
12091207
.diffLines(originalContent, newContent)
@@ -1217,9 +1215,9 @@ export class Cline {
12171215
.join("")
12181216

12191217
// Show diff view before asking for approval
1218+
this.diffViewProvider.editType = "modify"
12201219
await this.diffViewProvider.open(relPath);
12211220
await this.diffViewProvider.update(newContent, true);
1222-
await delay(300);
12231221
await this.diffViewProvider.scrollToFirstDiff();
12241222

12251223
const completeMessage = JSON.stringify({

src/core/__tests__/Cline.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ describe('Cline', () => {
236236
mockProvider,
237237
mockApiConfig,
238238
'custom instructions',
239+
false,
239240
'test task'
240241
);
241242

src/core/prompts/system.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path'
77
export const SYSTEM_PROMPT = async (
88
cwd: string,
99
supportsComputerUse: boolean,
10-
supportsDiff: boolean
10+
diffEnabled: boolean
1111
) => `You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
1212
1313
====
@@ -67,7 +67,7 @@ Your file content here
6767
</content>
6868
</write_to_file>
6969
70-
${supportsDiff ? `
70+
${diffEnabled ? `
7171
## apply_diff
7272
Description: Apply a diff to a file at the specified path. The diff should be in unified format (diff -u) and can be used to apply changes to a file. This tool is useful when you need to make specific modifications to a file based on a set of changes provided in a diff.
7373
Parameters:
@@ -238,7 +238,7 @@ CAPABILITIES
238238
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory ('${cwd.toPosix()}') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current working directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.
239239
- You can use search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
240240
- You can use the list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
241-
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the write_to_file ${supportsDiff ? "or apply_diff " : ""}tool to apply the changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
241+
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the write_to_file ${diffEnabled ? "or apply_diff " : ""}tool to apply the changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
242242
- You can use the execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.${
243243
supportsComputerUse
244244
? "\n- You can use the browser_action tool to interact with websites (including html files and locally running development servers) through a Puppeteer-controlled browser when you feel it is necessary in accomplishing the user's task. This tool is particularly useful for web development tasks as it allows you to launch a browser, navigate to pages, interact with elements through clicks and keyboard input, and capture the results through screenshots and console logs. This tool may be useful at key stages of web development tasks-such as after implementing new features, making substantial changes, when troubleshooting issues, or to verify the result of your work. You can analyze the provided screenshots to ensure correct rendering or identify errors, and review console logs for runtime issues.\n - For example, if asked to add a component to a react website, you might create the necessary files, use execute_command to run the site locally, then use browser_action to launch the browser, navigate to the local server, and verify the component renders & functions correctly before closing the browser."
@@ -255,7 +255,7 @@ RULES
255255
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '${cwd.toPosix()}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd.toPosix()}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd.toPosix()}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
256256
- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using write_to_file to make informed changes.
257257
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when writing files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
258-
${supportsDiff ? "- Prefer to use apply_diff over write_to_file when making changes to existing files, particularly when editing files more than 200 lines of code, as it allows you to apply specific modifications based on a set of changes provided in a diff. This is particularly useful when you need to make targeted edits or updates to a file without overwriting the entire content." : ""}
258+
${diffEnabled ? "- Prefer to use apply_diff over write_to_file when making changes to existing files, particularly when editing files more than 200 lines of code, as it allows you to apply specific modifications based on a set of changes provided in a diff. This is particularly useful when you need to make targeted edits or updates to a file without overwriting the entire content." : ""}
259259
- Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write.
260260
- When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.
261261
- When you want to modify a file, use the write_to_file tool directly with the desired content. You do not need to display the content before using the tool.

src/core/webview/ClineProvider.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type GlobalStateKey =
6464
| "openRouterUseMiddleOutTransform"
6565
| "allowedCommands"
6666
| "soundEnabled"
67+
| "diffEnabled"
6768

6869
export const GlobalFileNames = {
6970
apiConversationHistory: "api_conversation_history.json",
@@ -201,12 +202,14 @@ export class ClineProvider implements vscode.WebviewViewProvider {
201202
const {
202203
apiConfiguration,
203204
customInstructions,
205+
diffEnabled,
204206
} = await this.getState()
205207

206208
this.cline = new Cline(
207209
this,
208210
apiConfiguration,
209211
customInstructions,
212+
diffEnabled,
210213
task,
211214
images
212215
)
@@ -217,12 +220,14 @@ export class ClineProvider implements vscode.WebviewViewProvider {
217220
const {
218221
apiConfiguration,
219222
customInstructions,
223+
diffEnabled,
220224
} = await this.getState()
221225

222226
this.cline = new Cline(
223227
this,
224228
apiConfiguration,
225229
customInstructions,
230+
diffEnabled,
226231
undefined,
227232
undefined,
228233
historyItem,
@@ -532,9 +537,13 @@ export class ClineProvider implements vscode.WebviewViewProvider {
532537
}
533538
break
534539
case "soundEnabled":
535-
const enabled = message.bool ?? true
536-
await this.updateGlobalState("soundEnabled", enabled)
537-
setSoundEnabled(enabled)
540+
const soundEnabled = message.bool ?? true
541+
await this.updateGlobalState("soundEnabled", soundEnabled)
542+
await this.postStateToWebview()
543+
break
544+
case "diffEnabled":
545+
const diffEnabled = message.bool ?? true
546+
await this.updateGlobalState("diffEnabled", diffEnabled)
538547
await this.postStateToWebview()
539548
break
540549
}
@@ -843,6 +852,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
843852
alwaysAllowExecute,
844853
alwaysAllowBrowser,
845854
soundEnabled,
855+
diffEnabled,
846856
taskHistory,
847857
} = await this.getState()
848858

@@ -863,7 +873,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
863873
taskHistory: (taskHistory || [])
864874
.filter((item) => item.ts && item.task)
865875
.sort((a, b) => b.ts - a.ts),
866-
soundEnabled: soundEnabled ?? true,
876+
soundEnabled: soundEnabled ?? false,
877+
diffEnabled: diffEnabled ?? false,
867878
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
868879
allowedCommands,
869880
}
@@ -956,6 +967,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
956967
taskHistory,
957968
allowedCommands,
958969
soundEnabled,
970+
diffEnabled,
959971
] = await Promise.all([
960972
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
961973
this.getGlobalState("apiModelId") as Promise<string | undefined>,
@@ -991,6 +1003,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
9911003
this.getGlobalState("taskHistory") as Promise<HistoryItem[] | undefined>,
9921004
this.getGlobalState("allowedCommands") as Promise<string[] | undefined>,
9931005
this.getGlobalState("soundEnabled") as Promise<boolean | undefined>,
1006+
this.getGlobalState("diffEnabled") as Promise<boolean | undefined>,
9941007
])
9951008

9961009
let apiProvider: ApiProvider
@@ -1044,6 +1057,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10441057
taskHistory,
10451058
allowedCommands,
10461059
soundEnabled,
1060+
diffEnabled,
10471061
}
10481062
}
10491063

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ describe('ClineProvider', () => {
181181
alwaysAllowExecute: false,
182182
alwaysAllowBrowser: false,
183183
uriScheme: 'vscode',
184-
soundEnabled: true
184+
soundEnabled: false,
185+
diffEnabled: false
185186
}
186187

187188
const message: ExtensionMessage = {
@@ -230,5 +231,6 @@ describe('ClineProvider', () => {
230231
expect(state).toHaveProperty('alwaysAllowBrowser')
231232
expect(state).toHaveProperty('taskHistory')
232233
expect(state).toHaveProperty('soundEnabled')
234+
expect(state).toHaveProperty('diffEnabled')
233235
})
234236
})

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface ExtensionState {
4242
uriScheme?: string
4343
allowedCommands?: string[]
4444
soundEnabled?: boolean
45+
diffEnabled?: boolean
4546
}
4647

4748
export interface ClineMessage {

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface WebviewMessage {
3131
| "alwaysAllowBrowser"
3232
| "playSound"
3333
| "soundEnabled"
34+
| "diffEnabled"
3435
text?: string
3536
askResponse?: ClineAskResponse
3637
apiConfiguration?: ApiConfiguration

0 commit comments

Comments
 (0)