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

Function positionForNewPattern

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

Source from the content-addressed store, hash-verified

211 * existing rule by racing to the top of the list.
212 */
213export const positionForNewPattern = (
214 pattern: string,
215 rows: ReadonlyArray<Pick<ToolPolicyRow, "pattern" | "position" | "id">>,
216): string => {
217 const committed = [...rows].sort(comparePolicyRow);
218 const newScore = patternSpecificity(pattern);
219 let idx = committed.findIndex((r) => patternSpecificity(r.pattern) <= newScore);
220 if (idx === -1) idx = committed.length; // below every more-specific rule
221 const prev = idx === 0 ? null : committed[idx - 1]!.position;
222 const next = idx === committed.length ? null : committed[idx]!.position;
223 return generateKeyBetween(prev, next);
224};
225
226const actionRestrictionRank = (action: ToolPolicyAction): number =>
227 Match.value(action).pipe(

Callers 2

policiesCreateFunction · 0.90
usePolicyActionsFunction · 0.85

Calls 1

patternSpecificityFunction · 0.85

Tested by

no test coverage detected