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

Function getDirectoriesToProcess

src/utils/attachments.ts:1662–1695  ·  view source on GitHub ↗
(
  targetPath: string,
  originalCwd: string,
)

Source from the content-addressed store, hash-verified

1660 * @returns Object with nestedDirs and cwdLevelDirs arrays, both ordered from parent to child
1661 */
1662export function getDirectoriesToProcess(
1663 targetPath: string,
1664 originalCwd: string,
1665): { nestedDirs: string[]; cwdLevelDirs: string[] } {
1666 // Build list of directories from original CWD to targetPath's directory
1667 const targetDir = dirname(resolve(targetPath))
1668 const nestedDirs: string[] = []
1669 let currentDir = targetDir
1670
1671 // Walk up from target directory to original CWD
1672 while (currentDir !== originalCwd && currentDir !== parse(currentDir).root) {
1673 if (currentDir.startsWith(originalCwd)) {
1674 nestedDirs.push(currentDir)
1675 }
1676 currentDir = dirname(currentDir)
1677 }
1678
1679 // Reverse to get order from CWD down to target
1680 nestedDirs.reverse()
1681
1682 // Build list of directories from root to CWD (for conditional rules only)
1683 const cwdLevelDirs: string[] = []
1684 currentDir = originalCwd
1685
1686 while (currentDir !== parse(currentDir).root) {
1687 cwdLevelDirs.push(currentDir)
1688 currentDir = dirname(currentDir)
1689 }
1690
1691 // Reverse to get order from root to CWD
1692 cwdLevelDirs.reverse()
1693
1694 return { nestedDirs, cwdLevelDirs }
1695}
1696
1697/**
1698 * Converts memory files to attachments, filtering out already-loaded files.

Callers 1

Calls 2

resolveFunction · 0.70
parseFunction · 0.50

Tested by

no test coverage detected