@@ -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,
@@ -1382,10 +1414,7 @@ export class ClineProvider
13821414
13831415 const telemetryKey = process . env . POSTHOG_API_KEY
13841416 const machineId = vscode . env . machineId
1385- const allowedCommandsState = allowedCommands || [ ]
1386- const allowedCommandsWorkspace =
1387- vscode . workspace . getConfiguration ( Package . name ) . get < string [ ] > ( "allowedCommands" ) || [ ]
1388- const allowedCommandsCombined = [ ...new Set ( [ ...allowedCommandsState , ...allowedCommandsWorkspace ] ) ]
1417+ const mergedAllowedCommands = this . mergeAllowedCommands ( allowedCommands )
13891418 const cwd = this . cwd
13901419
13911420 // Check if there's a system prompt override for the current mode
@@ -1424,7 +1453,7 @@ export class ClineProvider
14241453 enableCheckpoints : enableCheckpoints ?? true ,
14251454 shouldShowAnnouncement :
14261455 telemetrySetting !== "unset" && lastShownAnnouncementId !== this . latestAnnouncementId ,
1427- allowedCommands : allowedCommandsCombined ,
1456+ allowedCommands : mergedAllowedCommands ,
14281457 soundVolume : soundVolume ?? 0.5 ,
14291458 browserViewportSize : browserViewportSize ?? "900x600" ,
14301459 screenshotQuality : screenshotQuality ?? 75 ,
0 commit comments