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

Function positionForNewPattern

packages/core/sdk/src/policies.ts:170–181  ·  view source on GitHub ↗
(
  pattern: string,
  rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>,
)

Source from the content-addressed store, hash-verified

168 * existing rule by racing to the top of the list.
169 */
170export const positionForNewPattern = (
171 pattern: string,
172 rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>,
173): string => {
174 const committed = [...rows].sort(comparePolicyRow);
175 const newScore = patternSpecificity(pattern);
176 let idx = committed.findIndex((r) => patternSpecificity(r.pattern) <= newScore);
177 if (idx === -1) idx = committed.length; // below every more-specific rule
178 const prev = idx === 0 ? null : committed[idx - 1]!.position;
179 const next = idx === committed.length ? null : committed[idx]!.position;
180 return generateKeyBetween(prev, next);
181};
182
183const actionRestrictionRank = (action: ToolPolicyAction): number =>
184 Match.value(action).pipe(

Callers 2

policiesCreateFunction · 0.90
usePolicyActionsFunction · 0.85

Calls 1

patternSpecificityFunction · 0.85

Tested by

no test coverage detected