MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / processMdRules

Function processMdRules

src/utils/claudemd.ts:696–787  ·  view source on GitHub ↗
({
  rulesDir,
  type,
  processedPaths,
  includeExternal,
  conditionalRule,
  visitedDirs = new Set(),
}: {
  rulesDir: string
  type: MemoryType
  processedPaths: Set<string>
  includeExternal: boolean
  conditionalRule: boolean
  visitedDirs?: Set<string>
})

Source from the content-addressed store, hash-verified

694 * @returns Array of MemoryFileInfo objects
695 */
696export async function processMdRules({
697 rulesDir,
698 type,
699 processedPaths,
700 includeExternal,
701 conditionalRule,
702 visitedDirs = new Set(),
703}: {
704 rulesDir: string
705 type: MemoryType
706 processedPaths: Set<string>
707 includeExternal: boolean
708 conditionalRule: boolean
709 visitedDirs?: Set<string>
710}): Promise<MemoryFileInfo[]> {
711 if (visitedDirs.has(rulesDir)) {
712 return []
713 }
714
715 try {
716 const fs = getFsImplementation()
717
718 const { resolvedPath: resolvedRulesDir, isSymlink } = safeResolvePath(
719 fs,
720 rulesDir,
721 )
722
723 visitedDirs.add(rulesDir)
724 if (isSymlink) {
725 visitedDirs.add(resolvedRulesDir)
726 }
727
728 const result: MemoryFileInfo[] = []
729 let entries: import('fs').Dirent[]
730 try {
731 entries = await fs.readdir(resolvedRulesDir)
732 } catch (e: unknown) {
733 const code = getErrnoCode(e)
734 if (code === 'ENOENT' || code === 'EACCES' || code === 'ENOTDIR') {
735 return []
736 }
737 throw e
738 }
739
740 for (const entry of entries) {
741 const entryPath = join(rulesDir, entry.name)
742 const { resolvedPath: resolvedEntryPath, isSymlink } = safeResolvePath(
743 fs,
744 entryPath,
745 )
746
747 // Use Dirent methods for non-symlinks to avoid extra stat calls.
748 // For symlinks, we need stat to determine what the target is.
749 const stats = isSymlink ? await fs.stat(resolvedEntryPath) : null
750 const isDirectory = stats ? stats.isDirectory() : entry.isDirectory()
751 const isFile = stats ? stats.isFile() : entry.isFile()
752
753 if (isDirectory) {

Callers 3

claudemd.tsFile · 0.85

Calls 8

getFsImplementationFunction · 0.85
safeResolvePathFunction · 0.85
getErrnoCodeFunction · 0.85
processMemoryFileFunction · 0.85
logEventFunction · 0.85
hasMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected