MCPcopy
hub / github.com/codeaashu/claude-code / getPatternsByRoot

Function getPatternsByRoot

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

Source from the content-addressed store, hash-verified

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

Callers 2

matchingRuleForInputFunction · 0.85

Calls 5

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

Tested by

no test coverage detected