Skip to content

Commit 9702261

Browse files
authored
Merge pull request #457 from RooVetGit/add_diffs_to_preview
Add diff strategy to system prompt preview
2 parents 9a2bfcc + 77fa8b1 commit 9702261

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

.changeset/poor-adults-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Fix bug where apply_diff wasn't showing up in system prompt preview

src/core/webview/ClineProvider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { downloadTask } from "../../integrations/misc/export-markdown"
1010
import { openFile, openImage } from "../../integrations/misc/open-file"
1111
import { selectImages } from "../../integrations/misc/process-images"
1212
import { getTheme } from "../../integrations/theme/getTheme"
13+
import { getDiffStrategy } from "../diff/DiffStrategy"
1314
import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker"
1415
import { McpHub } from "../../services/mcp/McpHub"
1516
import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
@@ -962,7 +963,16 @@ export class ClineProvider implements vscode.WebviewViewProvider {
962963
preferredLanguage,
963964
browserViewportSize,
964965
mcpEnabled,
966+
fuzzyMatchThreshold,
967+
experimentalDiffStrategy,
965968
} = await this.getState()
969+
970+
// Create diffStrategy based on current model and settings
971+
const diffStrategy = getDiffStrategy(
972+
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
973+
fuzzyMatchThreshold,
974+
experimentalDiffStrategy,
975+
)
966976
const cwd =
967977
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""
968978

@@ -979,7 +989,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
979989
cwd,
980990
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
981991
mcpEnabled ? this.mcpHub : undefined,
982-
undefined,
992+
diffStrategy,
983993
browserViewportSize ?? "900x600",
984994
mode,
985995
{

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ jest.mock(
7070
{ virtual: true },
7171
)
7272

73+
// Mock DiffStrategy
74+
jest.mock("../../diff/DiffStrategy", () => ({
75+
getDiffStrategy: jest.fn().mockImplementation(() => ({
76+
getToolDescription: jest.fn().mockReturnValue("apply_diff tool description"),
77+
})),
78+
}))
79+
7380
// Mock dependencies
7481
jest.mock("vscode", () => ({
7582
ExtensionContext: jest.fn(),
@@ -963,6 +970,52 @@ describe("ClineProvider", () => {
963970
)
964971
})
965972

973+
test("passes diffStrategy to SYSTEM_PROMPT when previewing", async () => {
974+
// Mock getState to return experimentalDiffStrategy and fuzzyMatchThreshold
975+
jest.spyOn(provider, "getState").mockResolvedValue({
976+
apiConfiguration: {
977+
apiProvider: "openrouter",
978+
apiModelId: "test-model",
979+
openRouterModelInfo: { supportsComputerUse: true },
980+
},
981+
customPrompts: {},
982+
mode: "code",
983+
mcpEnabled: false,
984+
browserViewportSize: "900x600",
985+
experimentalDiffStrategy: true,
986+
fuzzyMatchThreshold: 0.8,
987+
} as any)
988+
989+
// Mock SYSTEM_PROMPT to verify diffStrategy is passed
990+
const systemPromptModule = require("../../prompts/system")
991+
const systemPromptSpy = jest.spyOn(systemPromptModule, "SYSTEM_PROMPT")
992+
993+
// Trigger getSystemPrompt
994+
const handler = getMessageHandler()
995+
await handler({ type: "getSystemPrompt", mode: "code" })
996+
997+
// Verify SYSTEM_PROMPT was called with correct arguments
998+
expect(systemPromptSpy).toHaveBeenCalledWith(
999+
expect.anything(), // context
1000+
expect.any(String), // cwd
1001+
true, // supportsComputerUse
1002+
undefined, // mcpHub (disabled)
1003+
expect.objectContaining({
1004+
// diffStrategy
1005+
getToolDescription: expect.any(Function),
1006+
}),
1007+
"900x600", // browserViewportSize
1008+
"code", // mode
1009+
expect.any(Object), // customPrompts
1010+
expect.any(Object), // customModes
1011+
undefined, // effectiveInstructions
1012+
)
1013+
1014+
// Run the test again to verify it's consistent
1015+
await handler({ type: "getSystemPrompt", mode: "code" })
1016+
expect(systemPromptSpy).toHaveBeenCalledTimes(2)
1017+
})
1018+
9661019
test("uses correct mode-specific instructions when mode is specified", async () => {
9671020
// Mock getState to return architect mode instructions
9681021
jest.spyOn(provider, "getState").mockResolvedValue({

0 commit comments

Comments
 (0)