MCPcopy Create free account
hub / github.com/Noumena-Network/code / getPatternsByRoot

Function getPatternsByRoot

src/utils/permissions/filesystem.ts:929–963  ·  view source on GitHub ↗
(
  toolPermissionContext: ToolPermissionContext,
  toolType: 'edit' | 'read',
  behavior: 'allow' | 'deny' | 'ask',
)

Source from the content-addressed store, hash-verified

927}
928
929function getPatternsByRoot(
930 toolPermissionContext: ToolPermissionContext,
931 toolType: 'edit' | 'read',
932 behavior: 'allow' | 'deny' | 'ask',
933): Map<string | null, Map<string, PermissionRule>> {
934 const toolName = (() => {
935 switch (toolType) {
936 case 'edit':
937 // Apply Edit tool rules to any tool editing files
938 return FILE_EDIT_TOOL_NAME
939 case 'read':
940 // Apply Read tool rules to any tool reading files
941 return FILE_READ_TOOL_NAME
942 }
943 })()
944
945 const rules = getRuleByContentsForToolName(
946 toolPermissionContext,
947 toolName,
948 behavior,
949 )
950 // Resolve rules relative to path based on source
951 const patternsByRoot = new Map<string | null, Map<string, PermissionRule>>()
952 for (const [pattern, rule] of rules.entries()) {
953 const { relativePattern, root } = patternWithRoot(pattern, rule.source)
954 let patternsForRoot = patternsByRoot.get(root)
955 if (patternsForRoot === undefined) {
956 patternsForRoot = new Map<string, PermissionRule>()
957 patternsByRoot.set(root, patternsForRoot)
958 }
959 // Store the rule keyed by the root
960 patternsForRoot.set(relativePattern, rule)
961 }
962 return patternsByRoot
963}
964
965export function matchingRuleForInput(
966 path: string,

Callers 2

matchingRuleForInputFunction · 0.85

Calls 5

patternWithRootFunction · 0.85
entriesMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected