Spaces:
Sleeping
Sleeping
Download src/lib/exec-approval-utils.ts from tao-shen/HuggingClaw-MissionControl: direct link, hf CLI and curl.
- Browser
- Download file 734 Bytes
-
https://huggingface.co/spaces/tao-shen/HuggingClaw-MissionControl/resolve/main/src/lib/exec-approval-utils.ts
- Command line
-
hf download hf://spaces/tao-shen/HuggingClaw-MissionControl/src/lib/exec-approval-utils.ts
-
curl -L -o exec-approval-utils.ts https://huggingface.co/spaces/tao-shen/HuggingClaw-MissionControl/resolve/main/src/lib/exec-approval-utils.ts
734 Bytes
| /** | |
| * Glob-style pattern matching for exec approval allowlists. | |
| * Supports `*` as a wildcard that matches any characters. | |
| */ | |
| export function matchesGlobPattern(pattern: string, command: string): boolean { | |
| const p = pattern.toLowerCase().trim() | |
| const c = command.toLowerCase().trim() | |
| if (!p) return false | |
| if (p === c) return true | |
| if (!p.includes('*')) return false | |
| const regex = new RegExp('^' + p.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') + '$') | |
| return regex.test(c) | |
| } | |
| /** | |
| * Find all patterns from a list that match a given command. | |
| */ | |
| export function findMatchingPatterns(patterns: string[], command: string): string[] { | |
| return patterns.filter(pattern => matchesGlobPattern(pattern, command)) | |
| } | |