diff --git a/.changeset/poor-adults-fetch.md b/.changeset/poor-adults-fetch.md new file mode 100644 index 0000000..32ac663 --- /dev/null +++ b/.changeset/poor-adults-fetch.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Fix bug where apply_diff wasn't showing up in system prompt preview diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 72e7e27..cce08e2 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -10,6 +10,7 @@ import { downloadTask } from "../../integrations/misc/export-markdown" import { openFile, openImage } from "../../integrations/misc/open-file" import { selectImages } from "../../integrations/misc/process-images" import { getTheme } from "../../integrations/theme/getTheme" +import { getDiffStrategy } from "../diff/DiffStrategy" import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker" import { McpHub } from "../../services/mcp/McpHub" import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api" @@ -962,7 +963,16 @@ export class ClineProvider implements vscode.WebviewViewProvider { preferredLanguage, browserViewportSize, mcpEnabled, + fuzzyMatchThreshold, + experimentalDiffStrategy, } = await this.getState() + + // Create diffStrategy based on current model and settings + const diffStrategy = getDiffStrategy( + apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "", + fuzzyMatchThreshold, + experimentalDiffStrategy, + ) const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || "" @@ -979,7 +989,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { cwd, apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false, mcpEnabled ? this.mcpHub : undefined, - undefined, + diffStrategy, browserViewportSize ?? "900x600", mode, { diff --git a/src/core/webview/__tests__/ClineProvider.test.ts b/src/core/webview/__tests__/ClineProvider.test.ts index ff427a9..b672110 100644 --- a/src/core/webview/__tests__/ClineProvider.test.ts +++ b/src/core/webview/__tests__/ClineProvider.test.ts @@ -70,6 +70,13 @@ jest.mock( { virtual: true }, ) +// Mock DiffStrategy +jest.mock("../../diff/DiffStrategy", () => ({ + getDiffStrategy: jest.fn().mockImplementation(() => ({ + getToolDescription: jest.fn().mockReturnValue("apply_diff tool description"), + })), +})) + // Mock dependencies jest.mock("vscode", () => ({ ExtensionContext: jest.fn(), @@ -963,6 +970,52 @@ describe("ClineProvider", () => { ) }) + test("passes diffStrategy to SYSTEM_PROMPT when previewing", async () => { + // Mock getState to return experimentalDiffStrategy and fuzzyMatchThreshold + jest.spyOn(provider, "getState").mockResolvedValue({ + apiConfiguration: { + apiProvider: "openrouter", + apiModelId: "test-model", + openRouterModelInfo: { supportsComputerUse: true }, + }, + customPrompts: {}, + mode: "code", + mcpEnabled: false, + browserViewportSize: "900x600", + experimentalDiffStrategy: true, + fuzzyMatchThreshold: 0.8, + } as any) + + // Mock SYSTEM_PROMPT to verify diffStrategy is passed + const systemPromptModule = require("../../prompts/system") + const systemPromptSpy = jest.spyOn(systemPromptModule, "SYSTEM_PROMPT") + + // Trigger getSystemPrompt + const handler = getMessageHandler() + await handler({ type: "getSystemPrompt", mode: "code" }) + + // Verify SYSTEM_PROMPT was called with correct arguments + expect(systemPromptSpy).toHaveBeenCalledWith( + expect.anything(), // context + expect.any(String), // cwd + true, // supportsComputerUse + undefined, // mcpHub (disabled) + expect.objectContaining({ + // diffStrategy + getToolDescription: expect.any(Function), + }), + "900x600", // browserViewportSize + "code", // mode + expect.any(Object), // customPrompts + expect.any(Object), // customModes + undefined, // effectiveInstructions + ) + + // Run the test again to verify it's consistent + await handler({ type: "getSystemPrompt", mode: "code" }) + expect(systemPromptSpy).toHaveBeenCalledTimes(2) + }) + test("uses correct mode-specific instructions when mode is specified", async () => { // Mock getState to return architect mode instructions jest.spyOn(provider, "getState").mockResolvedValue({