MCPcopy Create free account
hub / github.com/WJX20/claude-code / getDirectoriesToProcess

Function getDirectoriesToProcess

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 2

parseFunction · 0.85
resolveFunction · 0.70

Tested by

no test coverage detected