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

Function matchPattern

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

Source from the content-addressed store, hash-verified

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

Callers 7

policies.test.tsFile · 0.90
resolveToolkitPolicyFunction · 0.90
resolveToolPolicyFunction · 0.85
resolveToolkitPolicyFunction · 0.85
ToolkitWorkspaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected