( command: string, allowedCommands: string[], deniedCommands?: string[], )
| 350 | * @returns Decision for this specific command |
| 351 | */ |
| 352 | export function getSingleCommandDecision( |
| 353 | command: string, |
| 354 | allowedCommands: string[], |
| 355 | deniedCommands?: string[], |
| 356 | ): CommandDecision { |
| 357 | if (!command) return "auto_approve" |
| 358 | |
| 359 | // Find longest matching prefixes in both lists |
| 360 | const longestAllowedMatch = findLongestPrefixMatch(command, allowedCommands || []) |
| 361 | const longestDeniedMatch = findLongestPrefixMatch(command, deniedCommands || []) |
| 362 | |
| 363 | // If only allowlist has a match, auto-approve |
| 364 | if (longestAllowedMatch && !longestDeniedMatch) { |
| 365 | return "auto_approve" |
| 366 | } |
| 367 | |
| 368 | // If only denylist has a match, auto-deny |
| 369 | if (!longestAllowedMatch && longestDeniedMatch) { |
| 370 | return "auto_deny" |
| 371 | } |
| 372 | |
| 373 | // Both lists have matches - apply longest prefix match rule |
| 374 | if (longestAllowedMatch && longestDeniedMatch) { |
| 375 | return longestAllowedMatch.length > longestDeniedMatch.length ? "auto_approve" : "auto_deny" |
| 376 | } |
| 377 | |
| 378 | // If neither list has a match, ask user |
| 379 | return "ask_user" |
| 380 | } |
no test coverage detected