Skip to content

Commit bb5faba

Browse files
committed
Merge branch 'main' into jq/sound-setting-improvements
2 parents d4ceee3 + 4756833 commit bb5faba

File tree

16 files changed

+160
-60
lines changed

16 files changed

+160
-60
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.2.11]
4+
5+
- Added settings checkbox for verbose diff debugging
6+
37
## [2.2.6 - 2.2.10]
48

59
- More fixes to search/replace diffs

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.2.10",
6+
"version": "2.2.11",
77
"icon": "assets/icons/rocket.png",
88
"galleryBanner": {
99
"color": "#617A91",

src/core/Cline.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class Cline {
9797
apiConfiguration: ApiConfiguration,
9898
customInstructions?: string,
9999
diffEnabled?: boolean,
100+
debugDiffEnabled?: boolean,
100101
task?: string,
101102
images?: string[],
102103
historyItem?: HistoryItem,
@@ -109,7 +110,7 @@ export class Cline {
109110
this.diffViewProvider = new DiffViewProvider(cwd)
110111
this.customInstructions = customInstructions
111112
if (diffEnabled && this.api.getModel().id) {
112-
this.diffStrategy = getDiffStrategy(this.api.getModel().id)
113+
this.diffStrategy = getDiffStrategy(this.api.getModel().id, debugDiffEnabled)
113114
}
114115
if (historyItem) {
115116
this.taskId = historyItem.id
@@ -1237,7 +1238,12 @@ export class Cline {
12371238
const originalContent = await fs.readFile(absolutePath, "utf-8")
12381239

12391240
// Apply the diff to the original content
1240-
const diffResult = this.diffStrategy?.applyDiff(originalContent, diffContent) ?? {
1241+
const diffResult = this.diffStrategy?.applyDiff(
1242+
originalContent,
1243+
diffContent,
1244+
parseInt(block.params.start_line ?? ''),
1245+
parseInt(block.params.end_line ?? '')
1246+
) ?? {
12411247
success: false,
12421248
error: "No diff strategy available"
12431249
}

src/core/__tests__/Cline.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ describe('Cline', () => {
278278
mockProvider,
279279
mockApiConfig,
280280
'custom instructions',
281-
false,
281+
false, // diffEnabled
282+
false, // debugDiffEnabled
282283
'test task'
283284
);
284285

src/core/assistant-message/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const toolParamNames = [
4444
"question",
4545
"result",
4646
"diff",
47+
"start_line",
48+
"end_line",
4749
] as const
4850

4951
export type ToolParamName = (typeof toolParamNames)[number]

src/core/diff/DiffStrategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { SearchReplaceDiffStrategy } from './strategies/search-replace'
66
* @param model The name of the model being used (e.g., 'gpt-4', 'claude-3-opus')
77
* @returns The appropriate diff strategy for the model
88
*/
9-
export function getDiffStrategy(model: string): DiffStrategy {
9+
export function getDiffStrategy(model: string, debugEnabled?: boolean): DiffStrategy {
1010
// For now, return SearchReplaceDiffStrategy for all models (with a fuzzy threshold of 0.9)
1111
// This architecture allows for future optimizations based on model capabilities
12-
return new SearchReplaceDiffStrategy(0.9)
12+
return new SearchReplaceDiffStrategy(0.9, debugEnabled)
1313
}
1414

1515
export type { DiffStrategy }

src/core/diff/strategies/search-replace.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { DiffStrategy, DiffResult } from "../types"
2+
import { addLineNumbers } from "../../../integrations/misc/extract-text"
3+
4+
const BUFFER_LINES = 5; // Number of extra context lines to show before and after matches
25

36
function levenshteinDistance(a: string, b: string): number {
47
const matrix: number[][] = [];
@@ -48,10 +51,12 @@ function getSimilarity(original: string, search: string): number {
4851

4952
export class SearchReplaceDiffStrategy implements DiffStrategy {
5053
private fuzzyThreshold: number;
54+
public debugEnabled: boolean;
5155

52-
constructor(fuzzyThreshold?: number) {
56+
constructor(fuzzyThreshold?: number, debugEnabled?: boolean) {
5357
// Default to exact matching (1.0) unless fuzzy threshold specified
5458
this.fuzzyThreshold = fuzzyThreshold ?? 1.0;
59+
this.debugEnabled = debugEnabled ?? false;
5560
}
5661

5762
getToolDescription(cwd: string): string {
@@ -119,15 +124,11 @@ Your search/replace content here
119124
// Extract the search and replace blocks
120125
const match = diffContent.match(/<<<<<<< SEARCH\n([\s\S]*?)\n=======\n([\s\S]*?)\n>>>>>>> REPLACE/);
121126
if (!match) {
122-
// Log detailed format information
123-
console.log('Invalid Diff Format Debug:', {
124-
expectedFormat: "<<<<<<< SEARCH\\n[search content]\\n=======\\n[replace content]\\n>>>>>>> REPLACE",
125-
tip: "Make sure to include both SEARCH and REPLACE sections with correct markers"
126-
});
127+
const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Expected Format: <<<<<<< SEARCH\\n[search content]\\n=======\\n[replace content]\\n>>>>>>> REPLACE\n- Tip: Make sure to include both SEARCH and REPLACE sections with correct markers` : '';
127128

128129
return {
129130
success: false,
130-
error: "Invalid diff format - missing required SEARCH/REPLACE sections"
131+
error: `Invalid diff format - missing required SEARCH/REPLACE sections${debugInfo}`
131132
};
132133
}
133134

@@ -161,21 +162,17 @@ Your search/replace content here
161162
let bestMatchScore = 0;
162163
let bestMatchContent = "";
163164

164-
if (startLine !== undefined && endLine !== undefined) {
165+
if (startLine && endLine) {
165166
// Convert to 0-based index
166167
const exactStartIndex = startLine - 1;
167168
const exactEndIndex = endLine - 1;
168169

169-
if (exactStartIndex < 0 || exactEndIndex >= originalLines.length) {
170-
// Log detailed debug information
171-
console.log('Invalid Line Range Debug:', {
172-
requestedRange: { start: startLine, end: endLine },
173-
fileBounds: { start: 1, end: originalLines.length }
174-
});
175-
170+
if (exactStartIndex < 0 || exactEndIndex >= originalLines.length || exactStartIndex > exactEndIndex) {
171+
const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Requested Range: lines ${startLine}-${endLine}\n- File Bounds: lines 1-${originalLines.length}` : '';
172+
176173
return {
177174
success: false,
178-
error: `Line range ${startLine}-${endLine} is invalid (file has ${originalLines.length} lines)`,
175+
error: `Line range ${startLine}-${endLine} is invalid (file has ${originalLines.length} lines)${debugInfo}`,
179176
};
180177
}
181178

@@ -196,13 +193,13 @@ Your search/replace content here
196193
let searchStartIndex = 0;
197194
let searchEndIndex = originalLines.length;
198195

199-
if (startLine !== undefined || endLine !== undefined) {
196+
if (startLine || endLine) {
200197
// Convert to 0-based index and add buffer
201-
if (startLine !== undefined) {
202-
searchStartIndex = Math.max(0, startLine - 6);
198+
if (startLine) {
199+
searchStartIndex = Math.max(0, startLine - (BUFFER_LINES + 1));
203200
}
204-
if (endLine !== undefined) {
205-
searchEndIndex = Math.min(originalLines.length, endLine + 5);
201+
if (endLine) {
202+
searchEndIndex = Math.min(originalLines.length, endLine + BUFFER_LINES);
206203
}
207204
}
208205

@@ -224,17 +221,27 @@ Your search/replace content here
224221
// Require similarity to meet threshold
225222
if (matchIndex === -1 || bestMatchScore < this.fuzzyThreshold) {
226223
const searchChunk = searchLines.join('\n');
227-
// Log detailed debug information to console
228-
console.log('Search/Replace Debug Info:', {
229-
similarity: bestMatchScore,
230-
threshold: this.fuzzyThreshold,
231-
searchContent: searchChunk,
232-
bestMatch: bestMatchContent || undefined
233-
});
234-
224+
const originalContentSection = startLine !== undefined && endLine !== undefined
225+
? `\n\nOriginal Content:\n${addLineNumbers(
226+
originalLines.slice(
227+
Math.max(0, startLine - 1 - BUFFER_LINES),
228+
Math.min(originalLines.length, endLine + BUFFER_LINES)
229+
).join('\n'),
230+
Math.max(1, startLine - BUFFER_LINES)
231+
)}`
232+
: `\n\nOriginal Content:\n${addLineNumbers(originalLines.join('\n'))}`;
233+
234+
const bestMatchSection = bestMatchContent
235+
? `\n\nBest Match Found:\n${addLineNumbers(bestMatchContent, matchIndex + 1)}`
236+
: `\n\nBest Match Found:\n(no match)`;
237+
238+
const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine && endLine ? `lines ${startLine}-${endLine}` : 'start to end'}\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}` : '';
239+
240+
const lineRange = startLine || endLine ?
241+
` at ${startLine ? `start: ${startLine}` : 'start'} to ${endLine ? `end: ${endLine}` : 'end'}` : '';
235242
return {
236243
success: false,
237-
error: `No sufficiently similar match found${startLine !== undefined ? ` near lines ${startLine}-${endLine}` : ''} (${Math.round(bestMatchScore * 100)}% similar, needs ${Math.round(this.fuzzyThreshold * 100)}%)`
244+
error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)${debugInfo}`
238245
};
239246
}
240247

src/core/diff/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export type DiffResult =
1313
}};
1414

1515
export interface DiffStrategy {
16+
/**
17+
* Whether to enable detailed debug logging
18+
*/
19+
debugEnabled?: boolean;
20+
1621
/**
1722
* Get the tool description for this diff strategy
1823
* @param cwd The current working directory

src/core/webview/ClineProvider.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type GlobalStateKey =
6868
| "soundEnabled"
6969
| "soundVolume"
7070
| "diffEnabled"
71+
| "debugDiffEnabled"
7172
| "alwaysAllowMcp"
7273

7374
export const GlobalFileNames = {
@@ -213,35 +214,39 @@ export class ClineProvider implements vscode.WebviewViewProvider {
213214

214215
async initClineWithTask(task?: string, images?: string[]) {
215216
await this.clearTask()
216-
const {
217-
apiConfiguration,
218-
customInstructions,
217+
const {
218+
apiConfiguration,
219+
customInstructions,
219220
diffEnabled,
221+
debugDiffEnabled,
220222
} = await this.getState()
221223

222224
this.cline = new Cline(
223-
this,
224-
apiConfiguration,
225-
customInstructions,
225+
this,
226+
apiConfiguration,
227+
customInstructions,
226228
diffEnabled,
227-
task,
229+
debugDiffEnabled,
230+
task,
228231
images
229232
)
230233
}
231234

232235
async initClineWithHistoryItem(historyItem: HistoryItem) {
233236
await this.clearTask()
234-
const {
235-
apiConfiguration,
236-
customInstructions,
237+
const {
238+
apiConfiguration,
239+
customInstructions,
237240
diffEnabled,
241+
debugDiffEnabled,
238242
} = await this.getState()
239243

240244
this.cline = new Cline(
241245
this,
242246
apiConfiguration,
243247
customInstructions,
244248
diffEnabled,
249+
debugDiffEnabled,
245250
undefined,
246251
undefined,
247252
historyItem,
@@ -609,6 +614,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
609614
await this.updateGlobalState("diffEnabled", diffEnabled)
610615
await this.postStateToWebview()
611616
break
617+
case "debugDiffEnabled":
618+
const debugDiffEnabled = message.bool ?? false
619+
await this.updateGlobalState("debugDiffEnabled", debugDiffEnabled)
620+
await this.postStateToWebview()
621+
break
612622
}
613623
},
614624
null,
@@ -935,6 +945,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
935945
alwaysAllowMcp,
936946
soundEnabled,
937947
diffEnabled,
948+
debugDiffEnabled,
938949
taskHistory,
939950
soundVolume,
940951
} = await this.getState()
@@ -959,6 +970,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
959970
.sort((a, b) => b.ts - a.ts),
960971
soundEnabled: soundEnabled ?? false,
961972
diffEnabled: diffEnabled ?? false,
973+
debugDiffEnabled: debugDiffEnabled ?? false,
962974
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
963975
allowedCommands,
964976
soundVolume: soundVolume ?? 0.5,
@@ -1054,6 +1066,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10541066
allowedCommands,
10551067
soundEnabled,
10561068
diffEnabled,
1069+
debugDiffEnabled,
10571070
soundVolume,
10581071
] = await Promise.all([
10591072
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
@@ -1092,6 +1105,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10921105
this.getGlobalState("allowedCommands") as Promise<string[] | undefined>,
10931106
this.getGlobalState("soundEnabled") as Promise<boolean | undefined>,
10941107
this.getGlobalState("diffEnabled") as Promise<boolean | undefined>,
1108+
this.getGlobalState("debugDiffEnabled") as Promise<boolean | undefined>,
10951109
this.getGlobalState("soundVolume") as Promise<number | undefined>,
10961110
])
10971111

@@ -1146,8 +1160,9 @@ export class ClineProvider implements vscode.WebviewViewProvider {
11461160
alwaysAllowMcp: alwaysAllowMcp ?? false,
11471161
taskHistory,
11481162
allowedCommands,
1149-
soundEnabled,
1150-
diffEnabled,
1163+
soundEnabled: soundEnabled ?? false,
1164+
diffEnabled: diffEnabled ?? false,
1165+
debugDiffEnabled: debugDiffEnabled ?? false,
11511166
soundVolume,
11521167
}
11531168
}

0 commit comments

Comments
 (0)