@@ -1303,6 +1303,38 @@ export class ClineProvider
13031303 return await fileExistsAtPath ( promptFilePath )
13041304 }
13051305
1306+ /**
1307+ * Merges allowed commands from global state and workspace configuration
1308+ * with proper validation and deduplication
1309+ */
1310+ private mergeAllowedCommands ( globalStateCommands ?: string [ ] ) : string [ ] {
1311+ try {
1312+ // Validate and sanitize global state commands
1313+ const validGlobalCommands = Array . isArray ( globalStateCommands )
1314+ ? globalStateCommands . filter ( ( cmd ) => typeof cmd === "string" && cmd . trim ( ) . length > 0 )
1315+ : [ ]
1316+
1317+ // Get workspace configuration commands
1318+ const workspaceCommands =
1319+ vscode . workspace . getConfiguration ( Package . name ) . get < string [ ] > ( "allowedCommands" ) || [ ]
1320+
1321+ // Validate and sanitize workspace commands
1322+ const validWorkspaceCommands = Array . isArray ( workspaceCommands )
1323+ ? workspaceCommands . filter ( ( cmd ) => typeof cmd === "string" && cmd . trim ( ) . length > 0 )
1324+ : [ ]
1325+
1326+ // Combine and deduplicate commands
1327+ // Global state takes precedence over workspace configuration
1328+ const mergedCommands = [ ...new Set ( [ ...validGlobalCommands , ...validWorkspaceCommands ] ) ]
1329+
1330+ return mergedCommands
1331+ } catch ( error ) {
1332+ console . error ( "Error merging allowed commands:" , error )
1333+ // Return empty array as fallback to prevent crashes
1334+ return [ ]
1335+ }
1336+ }
1337+
13061338 async getStateToPostToWebview ( ) {
13071339 const {
13081340 apiConfiguration,
@@ -1314,6 +1346,7 @@ export class ClineProvider
13141346 alwaysAllowWriteOutsideWorkspace,
13151347 alwaysAllowWriteProtected,
13161348 alwaysAllowExecute,
1349+ allowedCommands,
13171350 alwaysAllowBrowser,
13181351 alwaysAllowMcp,
13191352 alwaysAllowModeSwitch,
@@ -1381,7 +1414,7 @@ export class ClineProvider
13811414
13821415 const telemetryKey = process . env . POSTHOG_API_KEY
13831416 const machineId = vscode . env . machineId
1384- const allowedCommands = vscode . workspace . getConfiguration ( Package . name ) . get < string [ ] > ( " allowedCommands" ) || [ ]
1417+ const mergedAllowedCommands = this . mergeAllowedCommands ( allowedCommands )
13851418 const cwd = this . cwd
13861419
13871420 // Check if there's a system prompt override for the current mode
@@ -1420,7 +1453,7 @@ export class ClineProvider
14201453 enableCheckpoints : enableCheckpoints ?? true ,
14211454 shouldShowAnnouncement :
14221455 telemetrySetting !== "unset" && lastShownAnnouncementId !== this . latestAnnouncementId ,
1423- allowedCommands,
1456+ allowedCommands : mergedAllowedCommands ,
14241457 soundVolume : soundVolume ?? 0.5 ,
14251458 browserViewportSize : browserViewportSize ?? "900x600" ,
14261459 screenshotQuality : screenshotQuality ?? 75 ,
0 commit comments