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