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

Function effectivePolicyFromSorted

packages/core/sdk/src/policies.ts:216–240  ·  view source on GitHub ↗
(
  toolId: string,
  sortedPolicies: readonly (Pick<ToolPolicy, "pattern" | "action" | "id"> &
    Partial<Pick<ToolPolicy, "owner">>)[],
  defaultRequiresApproval?: boolean,
)

Source from the content-addressed store, hash-verified

214};
215
216export const effectivePolicyFromSorted = (
217 toolId: string,
218 sortedPolicies: readonly (Pick<ToolPolicy, "pattern" | "action" | "id"> &
219 Partial<Pick<ToolPolicy, "owner">>)[],
220 defaultRequiresApproval?: boolean,
221): EffectivePolicy => {
222 const firstMatchByOwner = new Map<string, EffectivePolicy>();
223 for (const p of sortedPolicies) {
224 const ownerKey = "owner" in p && p.owner ? String(p.owner) : "__flat__";
225 if (firstMatchByOwner.has(ownerKey)) continue;
226 if (matchPattern(p.pattern, toolId)) {
227 firstMatchByOwner.set(ownerKey, {
228 action: p.action,
229 source: "user",
230 pattern: p.pattern,
231 policyId: p.id,
232 });
233 }
234 }
235 let selected: EffectivePolicy | undefined;
236 for (const match of firstMatchByOwner.values()) {
237 selected = moreRestrictive(selected, match);
238 }
239 return selected ?? liftPlugin(defaultRequiresApproval);
240};
241
242// ---------------------------------------------------------------------------
243// Row → public projection.

Callers 3

policies.test.tsFile · 0.90
IntegrationDetailPageFunction · 0.85
ToolsPageFunction · 0.85

Calls 5

matchPatternFunction · 0.85
moreRestrictiveFunction · 0.85
liftPluginFunction · 0.85
setMethod · 0.80
valuesMethod · 0.80

Tested by

no test coverage detected