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

Function resolveToolPolicy

packages/core/sdk/src/policies.ts:201–229  ·  view source on GitHub ↗
(
  toolId: string,
  policies: readonly ToolPolicyRow[],
  ownerRank: (row: Pick<ToolPolicyRow, "owner">) => number,
)

Source from the content-addressed store, hash-verified

199};
200
201export const resolveToolPolicy = (
202 toolId: string,
203 policies: readonly ToolPolicyRow[],
204 ownerRank: (row: Pick<ToolPolicyRow, "owner">) => number,
205): PolicyMatch | undefined => {
206 if (policies.length === 0) return undefined;
207 const sorted = [...policies].sort((a, b) => {
208 const sa = ownerRank(a);
209 const sb = ownerRank(b);
210 if (sa !== sb) return sa - sb;
211 return comparePolicyRow(a, b);
212 });
213 const firstMatchByOwner = new Map<string, PolicyMatch>();
214 for (const row of sorted) {
215 if (firstMatchByOwner.has(row.owner)) continue;
216 if (matchPattern(row.pattern, toolId)) {
217 firstMatchByOwner.set(row.owner, {
218 action: row.action as ToolPolicyAction,
219 pattern: row.pattern,
220 policyId: row.id,
221 });
222 }
223 }
224 let selected: PolicyMatch | undefined;
225 for (const match of firstMatchByOwner.values()) {
226 selected = moreRestrictive(selected, match);
227 }
228 return selected;
229};
230
231// ---------------------------------------------------------------------------
232// Layered resolution — user-authored rules + plugin default `requiresApproval`.

Callers 2

policies.test.tsFile · 0.90
resolveEffectivePolicyFunction · 0.85

Calls 6

comparePolicyRowFunction · 0.85
moreRestrictiveFunction · 0.85
setMethod · 0.80
valuesMethod · 0.80
ownerRankFunction · 0.70
matchPatternFunction · 0.70

Tested by

no test coverage detected