From 63c766f380fd925d4656a5bb095d61989d9bf150 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Sun, 15 Dec 2024 19:47:13 -0800 Subject: [PATCH 01/18] fix soundEnabled init bug --- src/core/webview/ClineProvider.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index e998332..15aa32a 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -136,6 +136,11 @@ export class ClineProvider implements vscode.WebviewViewProvider { this.outputChannel.appendLine("Resolving webview view") this.view = webviewView + // Initialize sound enabled state + this.getState().then(({ soundEnabled }) => { + setSoundEnabled(soundEnabled ?? false) + }) + webviewView.webview.options = { // Allow scripts in the webview enableScripts: true, From 09934e20f7bddc4d45ab92a618b838d828d92732 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Sun, 15 Dec 2024 23:13:32 -0800 Subject: [PATCH 02/18] only play sounds on errors, task completion, or when user intervention is needed --- webview-ui/src/components/chat/ChatView.tsx | 181 ++++++++++---------- 1 file changed, 90 insertions(+), 91 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index e4e0880..777425e 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -64,7 +64,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie const [isAtBottom, setIsAtBottom] = useState(false) const [wasStreaming, setWasStreaming] = useState(false) - const [hasStarted, setHasStarted] = useState(false) // UI layout depends on the last 2 messages // (since it relies on the content of these messages, we are deep comparing. i.e. the button state after hitting button sets enableButtons to false, and this effect otherwise would have to true again even if messages didn't change @@ -75,12 +74,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie vscode.postMessage({ type: "playSound", audioType }) } - function playSoundOnMessage(audioType: AudioType) { - if (hasStarted && !isStreaming) { - playSound(audioType) - } - } - useDeepCompareEffect(() => { // if last message is an ask, show user ask UI // if user finished a task, then start a new task with a new conversation history since in this moment that the extension is waiting for user response, the user could close the extension and the conversation history would be lost. @@ -91,7 +84,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie const isPartial = lastMessage.partial === true switch (lastMessage.ask) { case "api_req_failed": - playSoundOnMessage("progress_loop") + playSound("progress_loop") setTextAreaDisabled(true) setClineAsk("api_req_failed") setEnableButtons(true) @@ -99,7 +92,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Start New Task") break case "mistake_limit_reached": - playSoundOnMessage("progress_loop") + playSound("progress_loop") setTextAreaDisabled(false) setClineAsk("mistake_limit_reached") setEnableButtons(true) @@ -107,7 +100,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Start New Task") break case "followup": - playSoundOnMessage("notification") + playSound("notification") setTextAreaDisabled(isPartial) setClineAsk("followup") setEnableButtons(isPartial) @@ -115,7 +108,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie // setSecondaryButtonText(undefined) break case "tool": - playSoundOnMessage("notification") + if (!isAutoApproved(lastMessage)) { + playSound("notification") + } setTextAreaDisabled(isPartial) setClineAsk("tool") setEnableButtons(!isPartial) @@ -134,7 +129,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } break case "browser_action_launch": - playSoundOnMessage("notification") + if (!isAutoApproved(lastMessage)) { + playSound("notification") + } setTextAreaDisabled(isPartial) setClineAsk("browser_action_launch") setEnableButtons(!isPartial) @@ -142,7 +139,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Reject") break case "command": - playSoundOnMessage("notification") + if (!isAutoApproved(lastMessage)) { + playSound("notification") + } setTextAreaDisabled(isPartial) setClineAsk("command") setEnableButtons(!isPartial) @@ -150,7 +149,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Reject") break case "command_output": - playSoundOnMessage("notification") setTextAreaDisabled(false) setClineAsk("command_output") setEnableButtons(true) @@ -166,7 +164,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie break case "completion_result": // extension waiting for feedback. but we can just present a new task button - playSoundOnMessage("celebration") + playSound("celebration") setTextAreaDisabled(isPartial) setClineAsk("completion_result") setEnableButtons(!isPartial) @@ -174,7 +172,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText(undefined) break case "resume_task": - playSoundOnMessage("notification") setTextAreaDisabled(false) setClineAsk("resume_task") setEnableButtons(true) @@ -183,7 +180,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setDidClickCancel(false) // special case where we reset the cancel button state break case "resume_completed_task": - playSoundOnMessage("celebration") + playSound("celebration") setTextAreaDisabled(false) setClineAsk("resume_completed_task") setEnableButtons(true) @@ -482,30 +479,86 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie return true }) }, [modifiedMessages]) - useEffect(() => { - if (isStreaming) { - // Set to true once any request has started - setHasStarted(true) + + const isReadOnlyToolAction = (message: ClineMessage | undefined) => { + if (message?.type === "ask" && message.text) { + const tool = JSON.parse(message.text) + return ["readFile", "listFiles", "listFilesTopLevel", "listFilesRecursive", "listCodeDefinitionNames", "searchFiles"].includes(tool.tool) } + return false + } + + const isWriteToolAction = (message: ClineMessage | undefined) => { + if (message?.type === "ask" && message.text) { + const tool = JSON.parse(message.text) + return ["editedExistingFile", "appliedDiff", "newFileCreated"].includes(tool.tool) + } + return false + } + + const isMcpToolAlwaysAllowed = (message: ClineMessage | undefined) => { + if (message?.type === "ask" && message.ask === "use_mcp_server" && message.text) { + const mcpServerUse = JSON.parse(message.text) as { type: string; serverName: string; toolName: string } + if (mcpServerUse.type === "use_mcp_tool") { + const server = mcpServers?.find((s: McpServer) => s.name === mcpServerUse.serverName) + const tool = server?.tools?.find((t: McpTool) => t.name === mcpServerUse.toolName) + return tool?.alwaysAllow || false + } + } + return false + } + + const isAllowedCommand = (message: ClineMessage | undefined) => { + if (message?.type === "ask" && message.text) { + const command = message.text + + // Split command by chaining operators + const commands = command.split(/&&|\|\||;|\||\$\(|`/).map(cmd => cmd.trim()) + + // Check if all individual commands are allowed + return commands.every((cmd) => { + const trimmedCommand = cmd.toLowerCase() + return allowedCommands?.some((prefix) => trimmedCommand.startsWith(prefix.toLowerCase())) + }) + } + return false + } + + const isAutoApproved = (message: ClineMessage | undefined) => { + if (!message || message.type !== "ask") return false + + return ( + (alwaysAllowBrowser && message.ask === "browser_action_launch") || + (alwaysAllowReadOnly && message.ask === "tool" && isReadOnlyToolAction(message)) || + (alwaysAllowWrite && message.ask === "tool" && isWriteToolAction(message)) || + (alwaysAllowExecute && message.ask === "command" && isAllowedCommand(message)) || + (alwaysAllowMcp && message.ask === "use_mcp_server" && isMcpToolAlwaysAllowed(message)) + ) + } + + useEffect(() => { // Only execute when isStreaming changes from true to false if (wasStreaming && !isStreaming && lastMessage) { // Play appropriate sound based on lastMessage content if (lastMessage.type === "ask") { - switch (lastMessage.ask) { - case "api_req_failed": - case "mistake_limit_reached": - playSound("progress_loop") - break - case "tool": - case "followup": - case "browser_action_launch": - case "resume_task": - playSound("notification") - break - case "completion_result": - case "resume_completed_task": - playSound("celebration") - break + // Don't play sounds for auto-approved actions + if (!isAutoApproved(lastMessage)) { + switch (lastMessage.ask) { + case "api_req_failed": + case "mistake_limit_reached": + playSound("progress_loop") + break + case "tool": + case "followup": + case "browser_action_launch": + case "resume_task": + playSound("notification") + break + case "completion_result": + case "resume_completed_task": + playSound("celebration") + break + } } } } @@ -750,61 +803,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie // Only proceed if we have an ask and buttons are enabled if (!clineAsk || !enableButtons) return - const isReadOnlyToolAction = () => { - const lastMessage = messages.at(-1) - if (lastMessage?.type === "ask" && lastMessage.text) { - const tool = JSON.parse(lastMessage.text) - return ["readFile", "listFiles", "listFilesTopLevel", "listFilesRecursive", "listCodeDefinitionNames", "searchFiles"].includes(tool.tool) - } - return false - } - - const isWriteToolAction = () => { - const lastMessage = messages.at(-1) - if (lastMessage?.type === "ask" && lastMessage.text) { - const tool = JSON.parse(lastMessage.text) - return ["editedExistingFile", "appliedDiff", "newFileCreated"].includes(tool.tool) - } - return false - } - - const isMcpToolAlwaysAllowed = () => { - const lastMessage = messages.at(-1) - if (lastMessage?.type === "ask" && lastMessage.ask === "use_mcp_server" && lastMessage.text) { - const mcpServerUse = JSON.parse(lastMessage.text) as { type: string; serverName: string; toolName: string } - if (mcpServerUse.type === "use_mcp_tool") { - const server = mcpServers?.find((s: McpServer) => s.name === mcpServerUse.serverName) - const tool = server?.tools?.find((t: McpTool) => t.name === mcpServerUse.toolName) - return tool?.alwaysAllow || false - } - } - return false - } - - const isAllowedCommand = () => { - const lastMessage = messages.at(-1) - if (lastMessage?.type === "ask" && lastMessage.text) { - const command = lastMessage.text - - // Split command by chaining operators - const commands = command.split(/&&|\|\||;|\||\$\(|`/).map(cmd => cmd.trim()) - - // Check if all individual commands are allowed - return commands.every((cmd) => { - const trimmedCommand = cmd.toLowerCase() - return allowedCommands?.some((prefix) => trimmedCommand.startsWith(prefix.toLowerCase())) - }) - } - return false - } - - if ( - (alwaysAllowBrowser && clineAsk === "browser_action_launch") || - (alwaysAllowReadOnly && clineAsk === "tool" && isReadOnlyToolAction()) || - (alwaysAllowWrite && clineAsk === "tool" && isWriteToolAction()) || - (alwaysAllowExecute && clineAsk === "command" && isAllowedCommand()) || - (alwaysAllowMcp && clineAsk === "use_mcp_server" && isMcpToolAlwaysAllowed()) - ) { + if (isAutoApproved(lastMessage)) { handlePrimaryButtonClick() } }, [clineAsk, enableButtons, handlePrimaryButtonClick, alwaysAllowBrowser, alwaysAllowReadOnly, alwaysAllowWrite, alwaysAllowExecute, alwaysAllowMcp, messages, allowedCommands, mcpServers]) From 1adc36a2928095371ee03859644aa4018574e8ae Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Sun, 15 Dec 2024 23:22:44 -0800 Subject: [PATCH 03/18] add volume setting --- package-lock.json | 6 +++ package.json | 1 + src/core/webview/ClineProvider.ts | 14 +++++- src/shared/ExtensionMessage.ts | 1 + src/shared/WebviewMessage.ts | 2 + src/utils/sound.ts | 17 +++++-- .../src/components/settings/SettingsView.tsx | 50 +++++++++++++++---- .../src/context/ExtensionStateContext.tsx | 4 ++ 8 files changed, 78 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 744ce85..43781fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "puppeteer-chromium-resolver": "^23.0.0", "puppeteer-core": "^23.4.0", "serialize-error": "^11.0.3", + "sound-play": "^1.1.0", "strip-ansi": "^7.1.0", "tree-sitter-wasms": "^0.1.11", "turndown": "^7.2.0", @@ -14001,6 +14002,11 @@ "node": ">= 14" } }, + "node_modules/sound-play": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/sound-play/-/sound-play-1.1.0.tgz", + "integrity": "sha512-Bd/L0AoCwITFeOnpNLMsfPXrV5GG5NhrC/T6odveahYbhPZkdTnrFXRia9FCC5WBWdUTw1d+yvLBvi4wnD1xOA==" + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", diff --git a/package.json b/package.json index 7d9d6d3..ab18a7c 100644 --- a/package.json +++ b/package.json @@ -220,6 +220,7 @@ "puppeteer-chromium-resolver": "^23.0.0", "puppeteer-core": "^23.4.0", "serialize-error": "^11.0.3", + "sound-play": "^1.1.0", "strip-ansi": "^7.1.0", "tree-sitter-wasms": "^0.1.11", "turndown": "^7.2.0", diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 15aa32a..1ce56ae 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -22,7 +22,7 @@ import { Cline } from "../Cline" import { openMention } from "../mentions" import { getNonce } from "./getNonce" import { getUri } from "./getUri" -import { playSound, setSoundEnabled } from "../../utils/sound" +import { playSound, setSoundEnabled, setSoundVolume } from "../../utils/sound" /* https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts @@ -66,6 +66,7 @@ type GlobalStateKey = | "openRouterUseMiddleOutTransform" | "allowedCommands" | "soundEnabled" + | "soundVolume" | "diffEnabled" | "alwaysAllowMcp" @@ -597,6 +598,12 @@ export class ClineProvider implements vscode.WebviewViewProvider { setSoundEnabled(soundEnabled) // Add this line to update the sound utility await this.postStateToWebview() break + case "soundVolume": + const soundVolume = message.value ?? 0.5 + await this.updateGlobalState("soundVolume", soundVolume) + setSoundVolume(soundVolume) + await this.postStateToWebview() + break case "diffEnabled": const diffEnabled = message.bool ?? true await this.updateGlobalState("diffEnabled", diffEnabled) @@ -929,6 +936,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { soundEnabled, diffEnabled, taskHistory, + soundVolume, } = await this.getState() const allowedCommands = vscode.workspace @@ -953,6 +961,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { diffEnabled: diffEnabled ?? false, shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId, allowedCommands, + soundVolume: soundVolume ?? 0.5, } } @@ -1045,6 +1054,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { allowedCommands, soundEnabled, diffEnabled, + soundVolume, ] = await Promise.all([ this.getGlobalState("apiProvider") as Promise, this.getGlobalState("apiModelId") as Promise, @@ -1082,6 +1092,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { this.getGlobalState("allowedCommands") as Promise, this.getGlobalState("soundEnabled") as Promise, this.getGlobalState("diffEnabled") as Promise, + this.getGlobalState("soundVolume") as Promise, ]) let apiProvider: ApiProvider @@ -1137,6 +1148,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { allowedCommands, soundEnabled, diffEnabled, + soundVolume, } } diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 608b5e5..07a3dde 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -51,6 +51,7 @@ export interface ExtensionState { uriScheme?: string allowedCommands?: string[] soundEnabled?: boolean + soundVolume?: number diffEnabled?: boolean } diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index 31802b9..2864a94 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -32,6 +32,7 @@ export interface WebviewMessage { | "alwaysAllowMcp" | "playSound" | "soundEnabled" + | "soundVolume" | "diffEnabled" | "openMcpSettings" | "restartMcpServer" @@ -43,6 +44,7 @@ export interface WebviewMessage { apiConfiguration?: ApiConfiguration images?: string[] bool?: boolean + value?: number commands?: string[] audioType?: AudioType // For toggleToolAutoApprove diff --git a/src/utils/sound.ts b/src/utils/sound.ts index 9255db4..a7f0d73 100644 --- a/src/utils/sound.ts +++ b/src/utils/sound.ts @@ -21,6 +21,7 @@ export const isWAV = (filepath: string): boolean => { } let isSoundEnabled = false +let volume = .5 /** * Set sound configuration @@ -30,6 +31,14 @@ export const setSoundEnabled = (enabled: boolean): void => { isSoundEnabled = enabled } +/** + * Set sound volume + * @param volume number + */ +export const setSoundVolume = (newVolume: number): void => { + volume = newVolume +} + /** * Play a sound file * @param filepath string @@ -54,11 +63,9 @@ export const playSound = (filepath: string): void => { return // Skip playback within minimum interval to prevent continuous playback } - const player = require("play-sound")() - player.play(filepath, function (err: any) { - if (err) { - throw new Error("Failed to play sound effect") - } + const sound = require("sound-play") + sound.play(filepath, volume).catch(() => { + throw new Error("Failed to play sound effect") }) lastPlayedTime = currentTime diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index deab3d6..f4e2da9 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -29,6 +29,8 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { setAlwaysAllowMcp, soundEnabled, setSoundEnabled, + soundVolume, + setSoundVolume, diffEnabled, setDiffEnabled, openRouterModels, @@ -55,6 +57,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { vscode.postMessage({ type: "alwaysAllowMcp", bool: alwaysAllowMcp }) vscode.postMessage({ type: "allowedCommands", commands: allowedCommands ?? [] }) vscode.postMessage({ type: "soundEnabled", bool: soundEnabled }) + vscode.postMessage({ type: "soundVolume", value: soundVolume }) vscode.postMessage({ type: "diffEnabled", bool: diffEnabled }) onDone() } @@ -306,17 +309,42 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {

Experimental Features

- setSoundEnabled(e.target.checked)}> - Enable sound effects - -

- When enabled, Cline will play sound effects for notifications and events. -

+
+ setSoundEnabled(e.target.checked)}> + Enable sound effects + +

+ When enabled, Cline will play sound effects for notifications and events. +

+
+ {soundEnabled && ( +
+
+ Volume + setSoundVolume(parseFloat(e.target.value))} + style={{ + flexGrow: 1, + accentColor: 'var(--vscode-button-background)', + height: '2px' + }} + /> + + {Math.round((soundVolume ?? 0.5) * 100)}% + +
+
+ )}
diff --git a/webview-ui/src/context/ExtensionStateContext.tsx b/webview-ui/src/context/ExtensionStateContext.tsx index f9690b6..c8307ff 100644 --- a/webview-ui/src/context/ExtensionStateContext.tsx +++ b/webview-ui/src/context/ExtensionStateContext.tsx @@ -29,6 +29,7 @@ export interface ExtensionStateContextType extends ExtensionState { setShowAnnouncement: (value: boolean) => void setAllowedCommands: (value: string[]) => void setSoundEnabled: (value: boolean) => void + setSoundVolume: (value: number) => void setDiffEnabled: (value: boolean) => void } @@ -42,6 +43,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode shouldShowAnnouncement: false, allowedCommands: [], soundEnabled: false, + soundVolume: 0.5, diffEnabled: false, }) const [didHydrateState, setDidHydrateState] = useState(false) @@ -129,6 +131,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode openRouterModels, mcpServers, filePaths, + soundVolume: state.soundVolume, setApiConfiguration: (value) => setState((prevState) => ({ ...prevState, apiConfiguration: value })), setCustomInstructions: (value) => setState((prevState) => ({ ...prevState, customInstructions: value })), setAlwaysAllowReadOnly: (value) => setState((prevState) => ({ ...prevState, alwaysAllowReadOnly: value })), @@ -139,6 +142,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode setShowAnnouncement: (value) => setState((prevState) => ({ ...prevState, shouldShowAnnouncement: value })), setAllowedCommands: (value) => setState((prevState) => ({ ...prevState, allowedCommands: value })), setSoundEnabled: (value) => setState((prevState) => ({ ...prevState, soundEnabled: value })), + setSoundVolume: (value) => setState((prevState) => ({ ...prevState, soundVolume: value })), setDiffEnabled: (value) => setState((prevState) => ({ ...prevState, diffEnabled: value })), } From 5e771cf783cfd7198a975035c4d64569ead25de3 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Sun, 15 Dec 2024 23:44:50 -0800 Subject: [PATCH 04/18] add volume slider tests --- .../settings/__tests__/SettingsView.test.tsx | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx b/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx index 50fd597..42d7021 100644 --- a/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx +++ b/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx @@ -104,6 +104,9 @@ describe('SettingsView - Sound Settings', () => { name: /Enable sound effects/i }) expect(soundCheckbox).not.toBeChecked() + + // Volume slider should not be visible when sound is disabled + expect(screen.queryByRole('slider')).not.toBeInTheDocument() }) it('toggles sound setting and sends message to VSCode', () => { @@ -128,6 +131,50 @@ describe('SettingsView - Sound Settings', () => { }) ) }) + + it('shows volume slider when sound is enabled', () => { + renderSettingsView() + + // Enable sound + const soundCheckbox = screen.getByRole('checkbox', { + name: /Enable sound effects/i + }) + fireEvent.click(soundCheckbox) + + // Volume slider should be visible + const volumeSlider = screen.getByRole('slider') + expect(volumeSlider).toBeInTheDocument() + expect(volumeSlider).toHaveValue('0.5') // Default value + }) + + it('updates volume and sends message to VSCode when slider changes', () => { + renderSettingsView() + + // Enable sound + const soundCheckbox = screen.getByRole('checkbox', { + name: /Enable sound effects/i + }) + fireEvent.click(soundCheckbox) + + // Change volume + const volumeSlider = screen.getByRole('slider') + fireEvent.change(volumeSlider, { target: { value: '0.75' } }) + + // Verify volume display updates + expect(screen.getByText('75%')).toBeInTheDocument() + + // Click Done to save settings + const doneButton = screen.getByText('Done') + fireEvent.click(doneButton) + + // Verify message sent to VSCode + expect(vscode.postMessage).toHaveBeenCalledWith( + expect.objectContaining({ + type: 'soundVolume', + value: 0.75 + }) + ) + }) }) describe('SettingsView - Allowed Commands', () => { From 95222a9a5dd4cb96ed8edc61a63e09d1f68c1566 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Sun, 15 Dec 2024 23:47:10 -0800 Subject: [PATCH 05/18] add sounds to mcp server approval --- webview-ui/src/components/chat/ChatView.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 777425e..a959cdb 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -156,6 +156,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText(undefined) break case "use_mcp_server": + if (!isAutoApproved(lastMessage)) { + playSound("notification") + } setTextAreaDisabled(isPartial) setClineAsk("use_mcp_server") setEnableButtons(!isPartial) @@ -552,6 +555,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie case "followup": case "browser_action_launch": case "resume_task": + case "use_mcp_server": playSound("notification") break case "completion_result": From efdc3a86392c464fbb5f18bb5e638efaea58c031 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 00:26:00 -0800 Subject: [PATCH 06/18] ChatView tests --- .../chat/__tests__/ChatView.test.tsx | 244 ++++++++++++++++++ 1 file changed, 244 insertions(+) diff --git a/webview-ui/src/components/chat/__tests__/ChatView.test.tsx b/webview-ui/src/components/chat/__tests__/ChatView.test.tsx index ad7565a..9e2d2c4 100644 --- a/webview-ui/src/components/chat/__tests__/ChatView.test.tsx +++ b/webview-ui/src/components/chat/__tests__/ChatView.test.tsx @@ -547,3 +547,247 @@ describe('ChatView - Auto Approval Tests', () => { }) }) }) + +describe('ChatView - Sound Playing Tests', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + + it('does not play sound for auto-approved browser actions', async () => { + render( + + {}} + showHistoryView={() => {}} + /> + + ) + + // First hydrate state with initial task and streaming + mockPostMessage({ + alwaysAllowBrowser: true, + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'say', + say: 'api_req_started', + ts: Date.now() - 1000, + text: JSON.stringify({}), + partial: true + } + ] + }) + + // Then send the browser action ask message (streaming finished) + mockPostMessage({ + alwaysAllowBrowser: true, + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'ask', + ask: 'browser_action_launch', + ts: Date.now(), + text: JSON.stringify({ action: 'launch', url: 'http://example.com' }), + partial: false + } + ] + }) + + // Verify no sound was played + expect(vscode.postMessage).not.toHaveBeenCalledWith({ + type: 'playSound', + audioType: expect.any(String) + }) + }) + + it('plays notification sound for non-auto-approved browser actions', async () => { + render( + + {}} + showHistoryView={() => {}} + /> + + ) + + // First hydrate state with initial task and streaming + mockPostMessage({ + alwaysAllowBrowser: false, + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'say', + say: 'api_req_started', + ts: Date.now() - 1000, + text: JSON.stringify({}), + partial: true + } + ] + }) + + // Then send the browser action ask message (streaming finished) + mockPostMessage({ + alwaysAllowBrowser: false, + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'ask', + ask: 'browser_action_launch', + ts: Date.now(), + text: JSON.stringify({ action: 'launch', url: 'http://example.com' }), + partial: false + } + ] + }) + + // Verify notification sound was played + await waitFor(() => { + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: 'playSound', + audioType: 'notification' + }) + }) + }) + + it('plays celebration sound for completion results', async () => { + render( + + {}} + showHistoryView={() => {}} + /> + + ) + + // First hydrate state with initial task and streaming + mockPostMessage({ + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'say', + say: 'api_req_started', + ts: Date.now() - 1000, + text: JSON.stringify({}), + partial: true + } + ] + }) + + // Then send the completion result message (streaming finished) + mockPostMessage({ + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'ask', + ask: 'completion_result', + ts: Date.now(), + text: 'Task completed successfully', + partial: false + } + ] + }) + + // Verify celebration sound was played + await waitFor(() => { + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: 'playSound', + audioType: 'celebration' + }) + }) + }) + + it('plays progress_loop sound for api failures', async () => { + render( + + {}} + showHistoryView={() => {}} + /> + + ) + + // First hydrate state with initial task and streaming + mockPostMessage({ + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'say', + say: 'api_req_started', + ts: Date.now() - 1000, + text: JSON.stringify({}), + partial: true + } + ] + }) + + // Then send the api failure message (streaming finished) + mockPostMessage({ + clineMessages: [ + { + type: 'say', + say: 'task', + ts: Date.now() - 2000, + text: 'Initial task' + }, + { + type: 'ask', + ask: 'api_req_failed', + ts: Date.now(), + text: 'API request failed', + partial: false + } + ] + }) + + // Verify progress_loop sound was played + await waitFor(() => { + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: 'playSound', + audioType: 'progress_loop' + }) + }) + }) +}) From c66fe250601a2d38282334b1d37958502bdd2329 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 09:30:20 -0800 Subject: [PATCH 07/18] ignore command and mcp asks with no text --- webview-ui/src/components/chat/ChatView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index a959cdb..604285d 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -139,7 +139,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Reject") break case "command": - if (!isAutoApproved(lastMessage)) { + if (lastMessage.text && !isAutoApproved(lastMessage)) { playSound("notification") } setTextAreaDisabled(isPartial) @@ -156,7 +156,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText(undefined) break case "use_mcp_server": - if (!isAutoApproved(lastMessage)) { + if (lastMessage.text && !isAutoApproved(lastMessage)) { playSound("notification") } setTextAreaDisabled(isPartial) From 05d6c295be548bbee34b1d5cd0f2b81acfa6031a Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 10:41:13 -0800 Subject: [PATCH 08/18] fix auto-approved and duplicate sounds --- webview-ui/src/components/chat/ChatView.tsx | 31 +++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 604285d..6972430 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -100,7 +100,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Start New Task") break case "followup": - playSound("notification") setTextAreaDisabled(isPartial) setClineAsk("followup") setEnableButtons(isPartial) @@ -139,7 +138,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText("Reject") break case "command": - if (lastMessage.text && !isAutoApproved(lastMessage)) { + if (!isAutoApproved(lastMessage)) { playSound("notification") } setTextAreaDisabled(isPartial) @@ -156,7 +155,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText(undefined) break case "use_mcp_server": - if (lastMessage.text && !isAutoApproved(lastMessage)) { + if (!isAutoApproved(lastMessage)) { playSound("notification") } setTextAreaDisabled(isPartial) @@ -484,7 +483,10 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie }, [modifiedMessages]) const isReadOnlyToolAction = (message: ClineMessage | undefined) => { - if (message?.type === "ask" && message.text) { + if (message?.type === "ask") { + if (!message.text) { + return true + } const tool = JSON.parse(message.text) return ["readFile", "listFiles", "listFilesTopLevel", "listFilesRecursive", "listCodeDefinitionNames", "searchFiles"].includes(tool.tool) } @@ -492,7 +494,10 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } const isWriteToolAction = (message: ClineMessage | undefined) => { - if (message?.type === "ask" && message.text) { + if (message?.type === "ask") { + if (!message.text) { + return true + } const tool = JSON.parse(message.text) return ["editedExistingFile", "appliedDiff", "newFileCreated"].includes(tool.tool) } @@ -500,7 +505,10 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } const isMcpToolAlwaysAllowed = (message: ClineMessage | undefined) => { - if (message?.type === "ask" && message.ask === "use_mcp_server" && message.text) { + if (message?.type === "ask" && message.ask === "use_mcp_server") { + if (!message.text) { + return true + } const mcpServerUse = JSON.parse(message.text) as { type: string; serverName: string; toolName: string } if (mcpServerUse.type === "use_mcp_tool") { const server = mcpServers?.find((s: McpServer) => s.name === mcpServerUse.serverName) @@ -512,8 +520,11 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } const isAllowedCommand = (message: ClineMessage | undefined) => { - if (message?.type === "ask" && message.text) { + if (message?.type === "ask") { const command = message.text + if (!command) { + return true + } // Split command by chaining operators const commands = command.split(/&&|\|\||;|\||\$\(|`/).map(cmd => cmd.trim()) @@ -551,8 +562,12 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie case "mistake_limit_reached": playSound("progress_loop") break - case "tool": case "followup": + if (!lastMessage.partial) { + playSound("notification") + } + break + case "tool": case "browser_action_launch": case "resume_task": case "use_mcp_server": From d4ceee396d12f070b2446d75546629177568a58d Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 10:46:11 -0800 Subject: [PATCH 09/18] uninstall play-sound --- package-lock.json | 18 +----------------- package.json | 1 - 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9790f1d..ae7aa41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,6 @@ "os-name": "^6.0.0", "p-wait-for": "^5.0.2", "pdf-parse": "^1.1.1", - "play-sound": "^1.1.6", "puppeteer-chromium-resolver": "^23.0.0", "puppeteer-core": "^23.4.0", "serialize-error": "^11.0.3", @@ -8851,14 +8850,6 @@ "node": ">=8" } }, - "node_modules/find-exec": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/find-exec/-/find-exec-1.0.3.tgz", - "integrity": "sha512-gnG38zW90mS8hm5smNcrBnakPEt+cGJoiMkJwCU0IYnEb0H2NQk0NIljhNW+48oniCriFek/PH6QXbwsJo/qug==", - "dependencies": { - "shell-quote": "^1.8.1" - } - }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -13103,14 +13094,6 @@ "node": ">=8" } }, - "node_modules/play-sound": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/play-sound/-/play-sound-1.1.6.tgz", - "integrity": "sha512-09eO4QiXNFXJffJaOW5P6x6F5RLihpLUkXttvUZeWml0fU6x6Zp7AjG9zaeMpgH2ZNvq4GR1ytB22ddYcqJIZA==", - "dependencies": { - "find-exec": "1.0.3" - } - }, "node_modules/possible-typed-array-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", @@ -13874,6 +13857,7 @@ "version": "1.8.2", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.2.tgz", "integrity": "sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==", + "dev": true, "engines": { "node": ">= 0.4" }, diff --git a/package.json b/package.json index 2f74913..98dc4bd 100644 --- a/package.json +++ b/package.json @@ -216,7 +216,6 @@ "os-name": "^6.0.0", "p-wait-for": "^5.0.2", "pdf-parse": "^1.1.1", - "play-sound": "^1.1.6", "puppeteer-chromium-resolver": "^23.0.0", "puppeteer-core": "^23.4.0", "serialize-error": "^11.0.3", From 905c68dd9ea7428867264e026b0a0b5f80044881 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 16 Dec 2024 11:43:08 -0500 Subject: [PATCH 10/18] Handle pure insertions and deletions with diffs --- CHANGELOG.md | 4 + package-lock.json | 4 +- package.json | 2 +- .../__tests__/search-replace.test.ts | 210 +++++++++++++++++- src/core/diff/strategies/search-replace.ts | 91 ++++++-- 5 files changed, 290 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeba972..f7db7df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Roo Cline Changelog +## [2.2.12] + +- Better support for pure deletion and insertion diffs + ## [2.2.11] - Added settings checkbox for verbose diff debugging diff --git a/package-lock.json b/package-lock.json index 4e5c9e4..6ea5438 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "roo-cline", - "version": "2.2.11", + "version": "2.2.12", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "roo-cline", - "version": "2.2.11", + "version": "2.2.12", "dependencies": { "@anthropic-ai/bedrock-sdk": "^0.10.2", "@anthropic-ai/sdk": "^0.26.0", diff --git a/package.json b/package.json index c0dd669..2f76cca 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Roo Cline", "description": "A fork of Cline, an autonomous coding agent, with some added experimental configuration and automation features.", "publisher": "RooVeterinaryInc", - "version": "2.2.11", + "version": "2.2.12", "icon": "assets/icons/rocket.png", "galleryBanner": { "color": "#617A91", diff --git a/src/core/diff/strategies/__tests__/search-replace.test.ts b/src/core/diff/strategies/__tests__/search-replace.test.ts index 8e48680..99aff99 100644 --- a/src/core/diff/strategies/__tests__/search-replace.test.ts +++ b/src/core/diff/strategies/__tests__/search-replace.test.ts @@ -711,6 +711,212 @@ this.init(); }) }); + describe('insertion/deletion', () => { + let strategy: SearchReplaceDiffStrategy + + beforeEach(() => { + strategy = new SearchReplaceDiffStrategy() + }) + + describe('deletion', () => { + it('should delete code when replace block is empty', () => { + const originalContent = `function test() { + console.log("hello"); + // Comment to remove + console.log("world"); +}` + const diffContent = `test.ts +<<<<<<< SEARCH + // Comment to remove +======= +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`function test() { + console.log("hello"); + console.log("world"); +}`) + } + }) + + it('should delete multiple lines when replace block is empty', () => { + const originalContent = `class Example { + constructor() { + // Initialize + this.value = 0; + // Set defaults + this.name = ""; + // End init + } +}` + const diffContent = `test.ts +<<<<<<< SEARCH + // Initialize + this.value = 0; + // Set defaults + this.name = ""; + // End init +======= +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`class Example { + constructor() { + } +}`) + } + }) + + it('should preserve indentation when deleting nested code', () => { + const originalContent = `function outer() { + if (true) { + // Remove this + console.log("test"); + // And this + } + return true; +}` + const diffContent = `test.ts +<<<<<<< SEARCH + // Remove this + console.log("test"); + // And this +======= +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`function outer() { + if (true) { + } + return true; +}`) + } + }) + }) + + describe('insertion', () => { + it('should insert code at specified line when search block is empty', () => { + const originalContent = `function test() { + const x = 1; + return x; +}` + const diffContent = `test.ts +<<<<<<< SEARCH +======= + console.log("Adding log"); +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent, 2, 2) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`function test() { + console.log("Adding log"); + const x = 1; + return x; +}`) + } + }) + + it('should preserve indentation when inserting at nested location', () => { + const originalContent = `function test() { + if (true) { + const x = 1; + } +}` + const diffContent = `test.ts +<<<<<<< SEARCH +======= + console.log("Before"); + console.log("After"); +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent, 3, 3) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`function test() { + if (true) { + console.log("Before"); + console.log("After"); + const x = 1; + } +}`) + } + }) + + it('should handle insertion at start of file', () => { + const originalContent = `function test() { + return true; +}` + const diffContent = `test.ts +<<<<<<< SEARCH +======= +// Copyright 2024 +// License: MIT + +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent, 1, 1) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`// Copyright 2024 +// License: MIT + +function test() { + return true; +}`) + } + }) + + it('should handle insertion at end of file', () => { + const originalContent = `function test() { + return true; +}` + const diffContent = `test.ts +<<<<<<< SEARCH +======= + +// End of file +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent, 4, 4) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`function test() { + return true; +} + +// End of file`) + } + }) + + it('should insert at the start of the file if no start_line is provided for insertion', () => { + const originalContent = `function test() { + return true; +}` + const diffContent = `test.ts +<<<<<<< SEARCH +======= +console.log("test"); +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe(`console.log("test"); +function test() { + return true; +}`) + } + }) + }) + }) + describe('fuzzy matching', () => { let strategy: SearchReplaceDiffStrategy @@ -1241,8 +1447,8 @@ function two() { it('should document start_line and end_line parameters', () => { const description = strategy.getToolDescription('/test') - expect(description).toContain('start_line: (required) The line number where the search block starts.') - expect(description).toContain('end_line: (required) The line number where the search block ends.') + expect(description).toContain('start_line: (required) The line number where the search block starts (inclusive).') + expect(description).toContain('end_line: (required) The line number where the search block ends (inclusive).') }) }) }) diff --git a/src/core/diff/strategies/search-replace.ts b/src/core/diff/strategies/search-replace.ts index 2fbfe5b..660d364 100644 --- a/src/core/diff/strategies/search-replace.ts +++ b/src/core/diff/strategies/search-replace.ts @@ -33,6 +33,10 @@ function levenshteinDistance(a: string, b: string): number { } function getSimilarity(original: string, search: string): number { + if (original === '' || search === '') { + return 1; + } + // Normalize strings by removing extra whitespace but preserve case const normalizeStr = (str: string) => str.replace(/\s+/g, ' ').trim(); @@ -71,8 +75,8 @@ If you're not confident in the exact content to search for, use the read_file to Parameters: - path: (required) The path of the file to modify (relative to the current working directory ${cwd}) - diff: (required) The search/replace block defining the changes. -- start_line: (required) The line number where the search block starts. -- end_line: (required) The line number where the search block ends. +- start_line: (required) The line number where the search block starts (inclusive). +- end_line: (required) The line number where the search block ends (inclusive). Diff format: \`\`\` @@ -94,35 +98,84 @@ Original file: 5 | return total \`\`\` -Search/Replace content: +1. Search/replace a specific chunk of code: \`\`\` + +File path here + <<<<<<< 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 + +2 +5 + \`\`\` -Usage: +Result: +\`\`\` +1 | def calculate_total(items): +2 | """Calculate total with 10% markup""" +3 | return sum(item * 1.1 for item in items) +\`\`\` + +2. Insert code at a specific line (start_line and end_line must be the same, and the content gets inserted before whatever is currently at that line): +\`\`\` File path here -Your search/replace content here +<<<<<<< SEARCH +======= + """TODO: Write a test for this""" +>>>>>>> REPLACE -1 +2 +2 + +\`\`\` + +Result: +\`\`\` +1 | def calculate_total(items): +2 | """TODO: Write a test for this""" +3 | """Calculate total with 10% markup""" +4 | return sum(item * 1.1 for item in items) +\`\`\` + +3. Delete code at a specific line range: +\`\`\` + +File path here + +<<<<<<< SEARCH + total = 0 + for item in items: + total += item + return total +======= +>>>>>>> REPLACE + +2 5 -` + +\`\`\` + +Result: +\`\`\` +1 | def calculate_total(items): +\`\`\` +` } applyDiff(originalContent: string, diffContent: string, startLine?: number, endLine?: number): DiffResult { // Extract the search and replace blocks - const match = diffContent.match(/<<<<<<< SEARCH\n([\s\S]*?)\n=======\n([\s\S]*?)\n>>>>>>> REPLACE/); + const match = diffContent.match(/<<<<<<< SEARCH\n([\s\S]*?)\n?=======\n([\s\S]*?)\n?>>>>>>> REPLACE/); if (!match) { 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` : ''; @@ -133,7 +186,7 @@ Your search/replace content here } let [_, searchContent, replaceContent] = match; - + // Detect line ending from original content const lineEnding = originalContent.includes('\r\n') ? '\r\n' : '\n'; @@ -145,7 +198,7 @@ Your search/replace content here if (hasLineNumbers(searchContent) && hasLineNumbers(replaceContent)) { const stripLineNumbers = (content: string) => { - return content.replace(/^\d+\s+\|(?!\|)/gm, '') + return content.replace(/^\d+\s+\|(?!\|)/gm, ''); }; searchContent = stripLineNumbers(searchContent); @@ -153,8 +206,8 @@ Your search/replace content here } // Split content into lines, handling both \n and \r\n - const searchLines = searchContent.split(/\r?\n/); - const replaceLines = replaceContent.split(/\r?\n/); + const searchLines = searchContent === '' ? [] : searchContent.split(/\r?\n/); + const replaceLines = replaceContent === '' ? [] : replaceContent.split(/\r?\n/); const originalLines = originalContent.split(/\r?\n/); // First try exact line range if provided @@ -167,9 +220,15 @@ Your search/replace content here const exactStartIndex = startLine - 1; const exactEndIndex = endLine - 1; - if (exactStartIndex < 0 || exactEndIndex >= originalLines.length || exactStartIndex > exactEndIndex) { + if (exactStartIndex < 0 || exactEndIndex > originalLines.length || exactStartIndex > exactEndIndex) { const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Requested Range: lines ${startLine}-${endLine}\n- File Bounds: lines 1-${originalLines.length}` : ''; + // Log detailed debug information + console.log('Invalid Line Range Debug:', { + requestedRange: { start: startLine, end: endLine }, + fileBounds: { start: 1, end: originalLines.length } + }); + return { success: false, error: `Line range ${startLine}-${endLine} is invalid (file has ${originalLines.length} lines)${debugInfo}`, @@ -263,7 +322,7 @@ Your search/replace content here // Apply the replacement while preserving exact indentation const indentedReplaceLines = replaceLines.map((line, i) => { // Get the matched line's exact indentation - const matchedIndent = originalIndents[0]; + const matchedIndent = originalIndents[0] || ''; // Get the current line's indentation relative to the search content const currentIndentMatch = line.match(/^[\t ]*/); From ac2babfd82d0a7b2778f54bf36abafe193484932 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 14:07:07 -0800 Subject: [PATCH 11/18] remove double ping for mcp approval --- webview-ui/src/components/chat/ChatView.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 6972430..696df80 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -155,9 +155,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText(undefined) break case "use_mcp_server": - if (!isAutoApproved(lastMessage)) { - playSound("notification") - } setTextAreaDisabled(isPartial) setClineAsk("use_mcp_server") setEnableButtons(!isPartial) From 8f1fef249b321f4ab48bb8fc829854d82da72f18 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 14:17:38 -0800 Subject: [PATCH 12/18] changeset --- .changeset/eighty-nails-peel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eighty-nails-peel.md diff --git a/.changeset/eighty-nails-peel.md b/.changeset/eighty-nails-peel.md new file mode 100644 index 0000000..bfcedc8 --- /dev/null +++ b/.changeset/eighty-nails-peel.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Add volume slider and change sound effect triggers From ca4806db224ba1b702deced67ee01139cbb8d18e Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 14:23:13 -0800 Subject: [PATCH 13/18] add details to changeset --- .changeset/eighty-nails-peel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eighty-nails-peel.md b/.changeset/eighty-nails-peel.md index bfcedc8..1810d53 100644 --- a/.changeset/eighty-nails-peel.md +++ b/.changeset/eighty-nails-peel.md @@ -2,4 +2,4 @@ "roo-cline": patch --- -Add volume slider and change sound effect triggers +Add volume slider in settings and change sound effects to only trigger when user intervention is required, an error occurs, or a task is completed. From 475776da98b4d9434150e2ac5008bd900ca40052 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 16 Dec 2024 17:40:36 -0500 Subject: [PATCH 14/18] Bugfix to strip line numbers with leading space --- .../__tests__/search-replace.test.ts | 20 +++++++++++++++++++ src/core/diff/strategies/search-replace.ts | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/core/diff/strategies/__tests__/search-replace.test.ts b/src/core/diff/strategies/__tests__/search-replace.test.ts index 99aff99..f96aa17 100644 --- a/src/core/diff/strategies/__tests__/search-replace.test.ts +++ b/src/core/diff/strategies/__tests__/search-replace.test.ts @@ -591,6 +591,26 @@ this.init(); expect(result.content).toBe('function test() {\n return false;\n}\n') } }) + + it('should strip line numbers with leading spaces', () => { + const originalContent = 'function test() {\n return true;\n}\n' + const diffContent = `test.ts +<<<<<<< SEARCH + 1 | function test() { + 2 | return true; + 3 | } +======= + 1 | function test() { + 2 | return false; + 3 | } +>>>>>>> REPLACE` + + const result = strategy.applyDiff(originalContent, diffContent) + expect(result.success).toBe(true) + if (result.success) { + expect(result.content).toBe('function test() {\n return false;\n}\n') + } + }) it('should not strip when not all lines have numbers in either section', () => { const originalContent = 'function test() {\n return true;\n}\n' diff --git a/src/core/diff/strategies/search-replace.ts b/src/core/diff/strategies/search-replace.ts index 660d364..9153c4e 100644 --- a/src/core/diff/strategies/search-replace.ts +++ b/src/core/diff/strategies/search-replace.ts @@ -193,12 +193,12 @@ Result: // Strip line numbers from search and replace content if every line starts with a line number const hasLineNumbers = (content: string) => { const lines = content.split(/\r?\n/); - return lines.length > 0 && lines.every(line => /^\d+\s+\|(?!\|)/.test(line)); + return lines.length > 0 && lines.every(line => /^\s*\d+\s+\|(?!\|)/.test(line)); }; if (hasLineNumbers(searchContent) && hasLineNumbers(replaceContent)) { const stripLineNumbers = (content: string) => { - return content.replace(/^\d+\s+\|(?!\|)/gm, ''); + return content.replace(/^\s*\d+\s+\|(?!\|)/gm, ''); }; searchContent = stripLineNumbers(searchContent); From 6db30b5e9022c42e07f6a0ad48fbcf0a0bbd4116 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 15:00:41 -0800 Subject: [PATCH 15/18] fix lint error --- webview-ui/src/components/chat/ChatView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 696df80..811056b 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -580,7 +580,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } // Update previous value setWasStreaming(isStreaming) - }, [isStreaming, lastMessage, wasStreaming]) + }, [isStreaming, lastMessage, wasStreaming, isAutoApproved]) const isBrowserSessionMessage = (message: ClineMessage): boolean => { // which of visible messages are browser session messages, see above @@ -822,7 +822,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie if (isAutoApproved(lastMessage)) { handlePrimaryButtonClick() } - }, [clineAsk, enableButtons, handlePrimaryButtonClick, alwaysAllowBrowser, alwaysAllowReadOnly, alwaysAllowWrite, alwaysAllowExecute, alwaysAllowMcp, messages, allowedCommands, mcpServers]) + }, [clineAsk, enableButtons, handlePrimaryButtonClick, alwaysAllowBrowser, alwaysAllowReadOnly, alwaysAllowWrite, alwaysAllowExecute, alwaysAllowMcp, messages, allowedCommands, mcpServers, isAutoApproved, lastMessage]) return (
Date: Mon, 16 Dec 2024 15:01:07 -0800 Subject: [PATCH 16/18] run lint on webview-ui --- package.json | 2 +- webview-ui/package-lock.json | 3 ++- webview-ui/package.json | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5a54432..64a0b1b 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "compile": "npm run check-types && npm run lint && node esbuild.js", "compile-tests": "tsc -p . --outDir out", "install:all": "npm install && cd webview-ui && npm install", - "lint": "eslint src --ext ts", + "lint": "eslint src --ext ts && npm run lint --prefix webview-ui", "package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production", "pretest": "npm run compile-tests && npm run compile && npm run lint", "start:webview": "cd webview-ui && npm run start", diff --git a/webview-ui/package-lock.json b/webview-ui/package-lock.json index 189ee43..ade601f 100644 --- a/webview-ui/package-lock.json +++ b/webview-ui/package-lock.json @@ -34,7 +34,8 @@ }, "devDependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", - "@types/vscode-webview": "^1.57.5" + "@types/vscode-webview": "^1.57.5", + "eslint": "^8.57.0" } }, "node_modules/@adobe/css-tools": { diff --git a/webview-ui/package.json b/webview-ui/package.json index 3d12cb9..2ede80f 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -31,7 +31,8 @@ "start": "react-scripts start", "build": "node ./scripts/build-react-no-split.js", "test": "react-scripts test --watchAll=false", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "lint": "eslint src --ext ts,tsx" }, "eslintConfig": { "extends": [ @@ -53,7 +54,8 @@ }, "devDependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", - "@types/vscode-webview": "^1.57.5" + "@types/vscode-webview": "^1.57.5", + "eslint": "^8.57.0" }, "jest": { "transformIgnorePatterns": [ From 267fb441d9504feeb346ca84b66a39d38328acf9 Mon Sep 17 00:00:00 2001 From: Justin Quan Date: Mon, 16 Dec 2024 15:12:49 -0800 Subject: [PATCH 17/18] fix all lint warnings --- webview-ui/src/components/chat/ChatView.tsx | 49 ++++++++++++------- .../mcp/__tests__/McpToolRow.test.tsx | 1 - .../settings/__tests__/SettingsView.test.tsx | 2 +- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 811056b..ff765e2 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -479,7 +479,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie }) }, [modifiedMessages]) - const isReadOnlyToolAction = (message: ClineMessage | undefined) => { + const isReadOnlyToolAction = useCallback((message: ClineMessage | undefined) => { if (message?.type === "ask") { if (!message.text) { return true @@ -488,9 +488,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie return ["readFile", "listFiles", "listFilesTopLevel", "listFilesRecursive", "listCodeDefinitionNames", "searchFiles"].includes(tool.tool) } return false - } + }, []) - const isWriteToolAction = (message: ClineMessage | undefined) => { + const isWriteToolAction = useCallback((message: ClineMessage | undefined) => { if (message?.type === "ask") { if (!message.text) { return true @@ -499,9 +499,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie return ["editedExistingFile", "appliedDiff", "newFileCreated"].includes(tool.tool) } return false - } + }, []) - const isMcpToolAlwaysAllowed = (message: ClineMessage | undefined) => { + const isMcpToolAlwaysAllowed = useCallback((message: ClineMessage | undefined) => { if (message?.type === "ask" && message.ask === "use_mcp_server") { if (!message.text) { return true @@ -514,9 +514,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie } } return false - } + }, [mcpServers]) - const isAllowedCommand = (message: ClineMessage | undefined) => { + const isAllowedCommand = useCallback((message: ClineMessage | undefined) => { if (message?.type === "ask") { const command = message.text if (!command) { @@ -533,19 +533,32 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie }) } return false - } + }, [allowedCommands]) - const isAutoApproved = (message: ClineMessage | undefined) => { - if (!message || message.type !== "ask") return false + const isAutoApproved = useCallback( + (message: ClineMessage | undefined) => { + if (!message || message.type !== "ask") return false - return ( - (alwaysAllowBrowser && message.ask === "browser_action_launch") || - (alwaysAllowReadOnly && message.ask === "tool" && isReadOnlyToolAction(message)) || - (alwaysAllowWrite && message.ask === "tool" && isWriteToolAction(message)) || - (alwaysAllowExecute && message.ask === "command" && isAllowedCommand(message)) || - (alwaysAllowMcp && message.ask === "use_mcp_server" && isMcpToolAlwaysAllowed(message)) - ) - } + return ( + (alwaysAllowBrowser && message.ask === "browser_action_launch") || + (alwaysAllowReadOnly && message.ask === "tool" && isReadOnlyToolAction(message)) || + (alwaysAllowWrite && message.ask === "tool" && isWriteToolAction(message)) || + (alwaysAllowExecute && message.ask === "command" && isAllowedCommand(message)) || + (alwaysAllowMcp && message.ask === "use_mcp_server" && isMcpToolAlwaysAllowed(message)) + ) + }, + [ + alwaysAllowBrowser, + alwaysAllowReadOnly, + alwaysAllowWrite, + alwaysAllowExecute, + alwaysAllowMcp, + isReadOnlyToolAction, + isWriteToolAction, + isAllowedCommand, + isMcpToolAlwaysAllowed + ] + ) useEffect(() => { // Only execute when isStreaming changes from true to false diff --git a/webview-ui/src/components/mcp/__tests__/McpToolRow.test.tsx b/webview-ui/src/components/mcp/__tests__/McpToolRow.test.tsx index 9f3cd96..2f4d286 100644 --- a/webview-ui/src/components/mcp/__tests__/McpToolRow.test.tsx +++ b/webview-ui/src/components/mcp/__tests__/McpToolRow.test.tsx @@ -23,7 +23,6 @@ jest.mock('@vscode/webview-ui-toolkit/react', () => ({