MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / matchPattern

Function matchPattern

packages/core/sdk/src/policies.ts:86–104  ·  view source on GitHub ↗
(pattern: string, toolId: string)

Source from the content-addressed store, hash-verified

84// ---------------------------------------------------------------------------
85
86export const matchPattern = (pattern: string, toolId: string): boolean => {
87 if (pattern === "*") return true;
88 const patternSegments = pattern.split(".");
89 const toolSegments = toolId.split(".");
90 for (let i = 0; i < patternSegments.length; i++) {
91 const seg = patternSegments[i]!;
92 if (seg === "*") {
93 // Trailing `*` is a subtree: the literal prefix already matched, so the
94 // address matches at this position and anything deeper (or nothing).
95 if (i === patternSegments.length - 1) return toolSegments.length >= i;
96 // A non-trailing `*` consumes EXACTLY ONE segment; one must exist here.
97 if (i >= toolSegments.length) return false;
98 continue;
99 }
100 if (i >= toolSegments.length || toolSegments[i] !== seg) return false;
101 }
102 // Pattern exhausted with no trailing `*`: an exact match requires equal length.
103 return patternSegments.length === toolSegments.length;
104};
105
106export const isValidPattern = (pattern: string): boolean => {
107 if (pattern.length === 0) return false;

Callers 5

policies.test.tsFile · 0.90
resolveToolkitPolicyFunction · 0.90
resolveToolPolicyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected