(
command: string,
permissionUpdates?: Array<{
type: string
rules: Array<{ toolName: string; ruleContent?: string }>
}>,
)
| 826 | * This is a Claude CLI-specific function that updates local settings. |
| 827 | */ |
| 828 | export function addToExcludedCommands( |
| 829 | command: string, |
| 830 | permissionUpdates?: Array<{ |
| 831 | type: string |
| 832 | rules: Array<{ toolName: string; ruleContent?: string }> |
| 833 | }>, |
| 834 | ): string { |
| 835 | const existingSettings = getSettingsForSource('localSettings') |
| 836 | const existingExcludedCommands = |
| 837 | existingSettings?.sandbox?.excludedCommands || [] |
| 838 | |
| 839 | // Determine the command pattern to add |
| 840 | // If there are suggestions with Bash rules, extract the pattern (e.g., "npm run test" from "npm run test:*") |
| 841 | // Otherwise use the exact command |
| 842 | let commandPattern: string = command |
| 843 | |
| 844 | if (permissionUpdates) { |
| 845 | const bashSuggestions = permissionUpdates.filter( |
| 846 | update => |
| 847 | update.type === 'addRules' && |
| 848 | update.rules.some(rule => rule.toolName === BASH_TOOL_NAME), |
| 849 | ) |
| 850 | |
| 851 | if (bashSuggestions.length > 0 && bashSuggestions[0]!.type === 'addRules') { |
| 852 | const firstBashRule = bashSuggestions[0]!.rules.find( |
| 853 | rule => rule.toolName === BASH_TOOL_NAME, |
| 854 | ) |
| 855 | if (firstBashRule?.ruleContent) { |
| 856 | // Extract pattern from Bash(command) or Bash(command:*) format |
| 857 | const prefix = permissionRuleExtractPrefix(firstBashRule.ruleContent) |
| 858 | commandPattern = prefix || firstBashRule.ruleContent |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | // Add to excludedCommands if not already present |
| 864 | if (!existingExcludedCommands.includes(commandPattern)) { |
| 865 | updateSettingsForSource('localSettings', { |
| 866 | sandbox: { |
| 867 | ...existingSettings?.sandbox, |
| 868 | excludedCommands: [...existingExcludedCommands, commandPattern], |
| 869 | }, |
| 870 | }) |
| 871 | } |
| 872 | |
| 873 | return commandPattern |
| 874 | } |
| 875 | |
| 876 | // ============================================================================ |
| 877 | // Export interface and implementation |
no test coverage detected