Skip to content

Commit 83b6f3c

Browse files
committed
refactor: simplify command allow/deny implementation
- Remove redundant allowCommand/denyCommand message types from WebviewMessage - Remove corresponding handlers from webviewMessageHandler - Remove unused test file for allowCommand functionality - Remove unused i18n keys for command_allowed and command_denied - Simplify to use existing allowedCommands/deniedCommands infrastructure
1 parent 2f321e9 commit 83b6f3c

File tree

4 files changed

+1
-268
lines changed

4 files changed

+1
-268
lines changed

src/core/webview/__tests__/webviewMessageHandler.spec.ts

Lines changed: 0 additions & 216 deletions
This file was deleted.

src/core/webview/webviewMessageHandler.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -771,29 +771,6 @@ export const webviewMessageHandler = async (
771771

772772
break
773773
}
774-
case "allowCommand": {
775-
// Add a command pattern to the allowed commands list
776-
if (message.pattern && typeof message.pattern === "string") {
777-
const currentCommands = getGlobalState("allowedCommands") ?? []
778-
const validCommands = Array.isArray(currentCommands)
779-
? currentCommands.filter((cmd) => typeof cmd === "string" && cmd.trim().length > 0)
780-
: []
781-
782-
// Add the new pattern if it's not already in the list
783-
if (!validCommands.includes(message.pattern)) {
784-
validCommands.push(message.pattern)
785-
786-
await updateGlobalState("allowedCommands", validCommands)
787-
788-
// Show confirmation to the user
789-
vscode.window.showInformationMessage(t("common:info.command_allowed", { pattern: message.pattern }))
790-
791-
// Update the webview state
792-
await provider.postStateToWebview()
793-
}
794-
}
795-
break
796-
}
797774
case "deniedCommands": {
798775
// Validate and sanitize the commands array
799776
const commands = message.commands ?? []
@@ -805,29 +782,6 @@ export const webviewMessageHandler = async (
805782

806783
break
807784
}
808-
case "denyCommand": {
809-
// Add a command pattern to the denied commands list
810-
if (message.pattern && typeof message.pattern === "string") {
811-
const currentCommands = getGlobalState("deniedCommands") ?? []
812-
const validCommands = Array.isArray(currentCommands)
813-
? currentCommands.filter((cmd) => typeof cmd === "string" && cmd.trim().length > 0)
814-
: []
815-
816-
// Add the new pattern if it's not already in the list
817-
if (!validCommands.includes(message.pattern)) {
818-
validCommands.push(message.pattern)
819-
820-
await updateGlobalState("deniedCommands", validCommands)
821-
822-
// Show confirmation to the user
823-
vscode.window.showInformationMessage(t("common:info.command_denied", { pattern: message.pattern }))
824-
825-
// Update the webview state
826-
await provider.postStateToWebview()
827-
}
828-
}
829-
break
830-
}
831785
case "openCustomModesSettings": {
832786
const customModesFilePath = await provider.customModesManager.getCustomModesFilePath()
833787

src/i18n/locales/en/common.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@
102102
"image_copied_to_clipboard": "Image data URI copied to clipboard",
103103
"image_saved": "Image saved to {{path}}",
104104
"mode_exported": "Mode '{{mode}}' exported successfully",
105-
"mode_imported": "Mode imported successfully",
106-
"command_allowed": "Command pattern '{{pattern}}' has been added to the allowed commands list",
107-
"command_denied": "Command pattern '{{pattern}}' has been added to the denied commands list"
105+
"mode_imported": "Mode imported successfully"
108106
},
109107
"answers": {
110108
"yes": "Yes",

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export interface WebviewMessage {
3636
| "getListApiConfiguration"
3737
| "customInstructions"
3838
| "allowedCommands"
39-
| "allowCommand"
4039
| "deniedCommands"
41-
| "denyCommand"
4240
| "alwaysAllowReadOnly"
4341
| "alwaysAllowReadOnlyOutsideWorkspace"
4442
| "alwaysAllowWrite"
@@ -237,7 +235,6 @@ export interface WebviewMessage {
237235
visibility?: ShareVisibility // For share visibility
238236
hasContent?: boolean // For checkRulesDirectoryResult
239237
checkOnly?: boolean // For deleteCustomMode check
240-
pattern?: string // For allowCommand
241238
codeIndexSettings?: {
242239
// Global state settings
243240
codebaseIndexEnabled: boolean

0 commit comments

Comments
 (0)