fix: update webviewMessageHandler to handle both string and object formats for deniedCommands

This commit is contained in:
Roo Code 2025-10-17 16:07:24 +00:00
parent 15f0ecd1fa
commit 9ade5a32cd
2 changed files with 37 additions and 8 deletions

View file

@ -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 }))
}
/**

View file

@ -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
}