From 9ade5a32cdb47ae7c8e592574e626559d2010613 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 17 Oct 2025 16:07:24 +0000 Subject: [PATCH] fix: update webviewMessageHandler to handle both string and object formats for deniedCommands --- src/core/webview/ClineProvider.ts | 17 ++++++++++++-- src/core/webview/webviewMessageHandler.ts | 28 ++++++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 0f888e975a..6af397a7cc 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1676,8 +1676,21 @@ export class ClineProvider * Merges denied commands from global state and workspace configuration * with proper validation and deduplication */ - private mergeDeniedCommands(globalStateCommands?: string[]): string[] { - return this.mergeCommandLists("deniedCommands", "denied", globalStateCommands) + private mergeDeniedCommands( + globalStateCommands?: string[] | { command: string; message?: string }[], + ): { command: string; message?: string }[] { + // Handle both string[] and object[] formats + if (!globalStateCommands) { + return [] + } + + // If it's already in the new format, return as-is + if (globalStateCommands.length > 0 && typeof globalStateCommands[0] === "object") { + return globalStateCommands as { command: string; message?: string }[] + } + + // If it's in the old string format, convert to new format for compatibility + return (globalStateCommands as string[]).map((cmd) => ({ command: cmd })) } /** diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 5edd2fd7f2..530ba82d9e 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -1020,18 +1020,34 @@ export const webviewMessageHandler = async ( break } case "deniedCommands": { - // Validate and sanitize the commands array + // Validate and sanitize the commands array - now supports both strings and objects const commands = message.commands ?? [] - const validCommands = Array.isArray(commands) - ? commands.filter((cmd) => typeof cmd === "string" && cmd.trim().length > 0) - : [] - await updateGlobalState("deniedCommands", validCommands) + // Normalize to object format for consistency + const normalizedCommands: { command: string; message?: string }[] = [] + + if (Array.isArray(commands)) { + for (const cmd of commands) { + if (typeof cmd === "string" && cmd.trim().length > 0) { + normalizedCommands.push({ command: cmd.trim() }) + } else if (typeof cmd === "object" && cmd !== null && "command" in cmd) { + const cmdObj = cmd as { command: string; message?: string } + if (typeof cmdObj.command === "string" && cmdObj.command.trim().length > 0) { + normalizedCommands.push({ + command: cmdObj.command.trim(), + ...(cmdObj.message ? { message: cmdObj.message } : {}), + }) + } + } + } + } + + await updateGlobalState("deniedCommands", normalizedCommands) // Also update workspace settings. await vscode.workspace .getConfiguration(Package.name) - .update("deniedCommands", validCommands, vscode.ConfigurationTarget.Global) + .update("deniedCommands", normalizedCommands, vscode.ConfigurationTarget.Global) break }