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

Function processMdRules

src/utils/claudemd.ts:870–961  ·  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

868 * @returns Array of MemoryFileInfo objects
869 */
870export async function processMdRules({
871 rulesDir,
872 type,
873 processedPaths,
874 includeExternal,
875 conditionalRule,
876 visitedDirs = new Set(),
877}: {
878 rulesDir: string
879 type: MemoryType
880 processedPaths: Set<string>
881 includeExternal: boolean
882 conditionalRule: boolean
883 visitedDirs?: Set<string>
884}): Promise<MemoryFileInfo[]> {
885 if (visitedDirs.has(rulesDir)) {
886 return []
887 }
888
889 try {
890 const fs = getFsImplementation()
891
892 const { resolvedPath: resolvedRulesDir, isSymlink } = safeResolvePath(
893 fs,
894 rulesDir,
895 )
896
897 visitedDirs.add(rulesDir)
898 if (isSymlink) {
899 visitedDirs.add(resolvedRulesDir)
900 }
901
902 const result: MemoryFileInfo[] = []
903 let entries: import('fs').Dirent[]
904 try {
905 entries = await fs.readdir(resolvedRulesDir)
906 } catch (e: unknown) {
907 const code = getErrnoCode(e)
908 if (code === 'ENOENT' || code === 'EACCES' || code === 'ENOTDIR') {
909 return []
910 }
911 throw e
912 }
913
914 for (const entry of entries) {
915 const entryPath = join(rulesDir, entry.name)
916 const { resolvedPath: resolvedEntryPath, isSymlink } = safeResolvePath(
917 fs,
918 entryPath,
919 )
920
921 // Use Dirent methods for non-symlinks to avoid extra stat calls.
922 // For symlinks, we need stat to determine what the target is.
923 const stats = isSymlink ? await fs.stat(resolvedEntryPath) : null
924 const isDirectory = stats ? stats.isDirectory() : entry.isDirectory()
925 const isFile = stats ? stats.isFile() : entry.isFile()
926
927 if (isDirectory) {

Callers 4

agentsmd.tsFile · 0.85
claudemd.tsFile · 0.85

Calls 7

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

Tested by

no test coverage detected