/ utils / settings / toolValidationConfig.ts
toolValidationConfig.ts
  1  /**
  2   * Tool validation configuration
  3   *
  4   * Most tools need NO configuration - basic validation works automatically.
  5   * Only add your tool here if it has special pattern requirements.
  6   */
  7  
  8  export type ToolValidationConfig = {
  9    /** Tools that accept file glob patterns (e.g., *.ts, src/**) */
 10    filePatternTools: string[]
 11  
 12    /** Tools that accept bash wildcard patterns (* anywhere) and legacy :* prefix syntax */
 13    bashPrefixTools: string[]
 14  
 15    /** Custom validation rules for specific tools */
 16    customValidation: {
 17      [toolName: string]: (content: string) => {
 18        valid: boolean
 19        error?: string
 20        suggestion?: string
 21        examples?: string[]
 22      }
 23    }
 24  }
 25  
 26  export const TOOL_VALIDATION_CONFIG: ToolValidationConfig = {
 27    // File pattern tools (accept *.ts, src/**, etc.)
 28    filePatternTools: [
 29      'Read',
 30      'Write',
 31      'Edit',
 32      'Glob',
 33      'NotebookRead',
 34      'NotebookEdit',
 35    ],
 36  
 37    // Bash wildcard tools (accept * anywhere, and legacy command:* syntax)
 38    bashPrefixTools: ['Bash'],
 39  
 40    // Custom validation (only if needed)
 41    customValidation: {
 42      // WebSearch doesn't support wildcards or complex patterns
 43      WebSearch: content => {
 44        if (content.includes('*') || content.includes('?')) {
 45          return {
 46            valid: false,
 47            error: 'WebSearch does not support wildcards',
 48            suggestion: 'Use exact search terms without * or ?',
 49            examples: ['WebSearch(claude ai)', 'WebSearch(typescript tutorial)'],
 50          }
 51        }
 52        return { valid: true }
 53      },
 54  
 55      // WebFetch uses domain: prefix for hostname-based permissions
 56      WebFetch: content => {
 57        // Check if it's trying to use a URL format
 58        if (content.includes('://') || content.startsWith('http')) {
 59          return {
 60            valid: false,
 61            error: 'WebFetch permissions use domain format, not URLs',
 62            suggestion: 'Use "domain:hostname" format',
 63            examples: [
 64              'WebFetch(domain:example.com)',
 65              'WebFetch(domain:github.com)',
 66            ],
 67          }
 68        }
 69  
 70        // Must start with domain: prefix
 71        if (!content.startsWith('domain:')) {
 72          return {
 73            valid: false,
 74            error: 'WebFetch permissions must use "domain:" prefix',
 75            suggestion: 'Use "domain:hostname" format',
 76            examples: [
 77              'WebFetch(domain:example.com)',
 78              'WebFetch(domain:*.google.com)',
 79            ],
 80          }
 81        }
 82  
 83        // Allow wildcards in domain patterns
 84        // Valid: domain:*.example.com, domain:example.*, etc.
 85        return { valid: true }
 86      },
 87    },
 88  }
 89  
 90  // Helper to check if a tool uses file patterns
 91  export function isFilePatternTool(toolName: string): boolean {
 92    return TOOL_VALIDATION_CONFIG.filePatternTools.includes(toolName)
 93  }
 94  
 95  // Helper to check if a tool uses bash prefix patterns
 96  export function isBashPrefixTool(toolName: string): boolean {
 97    return TOOL_VALIDATION_CONFIG.bashPrefixTools.includes(toolName)
 98  }
 99  
100  // Helper to get custom validation for a tool
101  export function getCustomValidation(toolName: string) {
102    return TOOL_VALIDATION_CONFIG.customValidation[toolName]
103  }