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