diff --git a/v3/@claude-flow/guidance/src/retriever.ts b/v3/@claude-flow/guidance/src/retriever.ts index 46e615bb58..7c31606e46 100644 --- a/v3/@claude-flow/guidance/src/retriever.ts +++ b/v3/@claude-flow/guidance/src/retriever.ts @@ -426,15 +426,21 @@ export class ShardRetriever { } /** - * Simple glob matching (supports * and **) + * Simple glob matching (supports * and **). + * Compiled regexes are cached per glob to avoid re-compiling on every call. */ private matchGlob(path: string, glob: string): boolean { - const regex = glob - .replace(/\*\*/g, '{{GLOBSTAR}}') - .replace(/\*/g, '[^/]*') - .replace(/{{GLOBSTAR}}/g, '.*') - .replace(/\//g, '\\/'); - return new RegExp(`^${regex}$`).test(path); + let re = this.globCache.get(glob); + if (!re) { + const pattern = glob + .replace(/\*\*/g, '{{GLOBSTAR}}') + .replace(/\*/g, '[^/]*') + .replace(/{{GLOBSTAR}}/g, '.*') + .replace(/\//g, '\\/'); + re = new RegExp(`^${pattern}$`); + this.globCache.set(glob, re); + } + return re.test(path); } /**