openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
38 lines (37 loc) • 1.2 kB
JavaScript
import { t as escapeRegExp } from "./regexp-dj3rRPbj.mjs";
//#region src/agents/glob-pattern.ts
/**
* Compiles and matches lightweight glob patterns used by agent policies.
*/
function compileGlobPattern(e) {
const t = e.normalize(e.raw);
if (t === "*") return { kind: "all" };
if (!t.includes("*")) return {
kind: "exact",
value: t
};
return {
kind: "regex",
value: new RegExp(`^${escapeRegExp(t).replaceAll("\\*", ".*")}$`)
};
}
function compileGlobPatterns(e) {
if (!Array.isArray(e.raw)) return [];
return e.raw.map((t) => compileGlobPattern({
raw: t,
normalize: e.normalize
})).filter((e) => e.kind !== "exact" || e.value);
}
function matchesAnyGlobPattern(e, t) {
for (const n of t) if (n.kind === "all" || n.kind === "exact" && e === n.value || n.kind === "regex" && n.value.test(e)) return true;
return false;
}
/** Conservative discovery hint; concrete values still need the full glob matcher. */
function mayMatchGlobWithPrefix(e, t) {
const n = e.indexOf("*");
if (n < 0) return false;
const r = e.slice(0, n);
return t.startsWith(r) || r.startsWith(t);
}
//#endregion
export { matchesAnyGlobPattern as n, mayMatchGlobWithPrefix as r, compileGlobPatterns as t };