( context: ToolPermissionContext, toolName: string, behavior: PermissionBehavior, )
| 360 | |
| 361 | // Used to break circular dependency where a Tool calls this function |
| 362 | export function getRuleByContentsForToolName( |
| 363 | context: ToolPermissionContext, |
| 364 | toolName: string, |
| 365 | behavior: PermissionBehavior, |
| 366 | ): Map<string, PermissionRule> { |
| 367 | const ruleByContents = new Map<string, PermissionRule>() |
| 368 | let rules: PermissionRule[] = [] |
| 369 | switch (behavior) { |
| 370 | case 'allow': |
| 371 | rules = getAllowRules(context) |
| 372 | break |
| 373 | case 'deny': |
| 374 | rules = getDenyRules(context) |
| 375 | break |
| 376 | case 'ask': |
| 377 | rules = getAskRules(context) |
| 378 | break |
| 379 | } |
| 380 | for (const rule of rules) { |
| 381 | if ( |
| 382 | rule.ruleValue.toolName === toolName && |
| 383 | rule.ruleValue.ruleContent !== undefined && |
| 384 | rule.ruleBehavior === behavior |
| 385 | ) { |
| 386 | ruleByContents.set(rule.ruleValue.ruleContent, rule) |
| 387 | } |
| 388 | } |
| 389 | return ruleByContents |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Runs PermissionRequest hooks for headless/async agents that cannot show |
no test coverage detected