MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getSingleCommandDecision

Function getSingleCommandDecision

src/core/auto-approval/commands.ts:352–380  ·  view source on GitHub ↗
(
	command: string,
	allowedCommands: string[],
	deniedCommands?: string[],
)

Source from the content-addressed store, hash-verified

350 * @returns Decision for this specific command
351 */
352export 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}

Callers 1

getCommandDecisionFunction · 0.85

Calls 1

findLongestPrefixMatchFunction · 0.85

Tested by

no test coverage detected