MCPcopy Create free account
hub / github.com/TanStack/ai / evaluateCommand

Function evaluateCommand

packages/ai-sandbox/src/policy.ts:93–111  ·  view source on GitHub ↗
(
  command: string,
  policy: SandboxPolicy | undefined,
  scripts?: Record<string, string>,
)

Source from the content-addressed store, hash-verified

91 * or its expanded command value (and vice versa for the command under test).
92 */
93export function evaluateCommand(
94 command: string,
95 policy: SandboxPolicy | undefined,
96 scripts?: Record<string, string>,
97): PolicyDecision {
98 const fallback = policy?.default ?? 'ask'
99 const rules = policy?.commands
100 if (!rules) return fallback
101
102 const matches = (patterns: Array<string> | undefined): boolean =>
103 (patterns ?? []).some((pattern) =>
104 patternMatchesCommand(pattern, command, scripts),
105 )
106
107 if (matches(rules.deny)) return 'deny'
108 if (matches(rules.ask)) return 'ask'
109 if (matches(rules.allow)) return 'allow'
110 return fallback
111}

Callers 2

resolveApprovalFunction · 0.90
policy.test.tsFile · 0.90

Calls 1

matchesFunction · 0.85

Tested by

no test coverage detected