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

Function getNestedMemoryAttachmentsForFile

src/utils/attachments.ts:1798–1868  ·  view source on GitHub ↗

* Loads nested memory files for a given file path and returns them as attachments. * This function performs directory traversal to find NCODE.md / legacy * CLAUDE.md files and conditional rules that apply to the target file path. * * Processing order (must be preserved): * 1. Managed/User condi

(
  filePath: string,
  toolUseContext: ToolUseContext,
  appState: { toolPermissionContext: ToolPermissionContext },
)

Source from the content-addressed store, hash-verified

1796 * @returns Array of nested memory attachments
1797 */
1798async function getNestedMemoryAttachmentsForFile(
1799 filePath: string,
1800 toolUseContext: ToolUseContext,
1801 appState: { toolPermissionContext: ToolPermissionContext },
1802): Promise<Attachment[]> {
1803 const attachments: Attachment[] = []
1804
1805 try {
1806 // Early return if path is not in allowed working path
1807 if (!pathInAllowedWorkingPath(filePath, appState.toolPermissionContext)) {
1808 return attachments
1809 }
1810
1811 const processedPaths = new Set<string>()
1812 const originalCwd = getOriginalCwd()
1813
1814 // Phase 1: Process Managed and User conditional rules
1815 const managedUserRules = await getManagedAndUserConditionalRules(
1816 filePath,
1817 processedPaths,
1818 )
1819 attachments.push(
1820 ...memoryFilesToAttachments(managedUserRules, toolUseContext, filePath),
1821 )
1822
1823 // Phase 2: Get directories to process
1824 const { nestedDirs, cwdLevelDirs } = getDirectoriesToProcess(
1825 filePath,
1826 originalCwd,
1827 )
1828
1829 const skipProjectLevel = getFeatureValue_CACHED_MAY_BE_STALE(
1830 'ncode_paper_halyard',
1831 false,
1832 )
1833
1834 // Phase 3: Process nested directories (CWD → target)
1835 // Each directory gets: CLAUDE.md + unconditional rules + conditional rules
1836 for (const dir of nestedDirs) {
1837 const memoryFiles = (
1838 await getMemoryFilesForNestedDirectory(dir, filePath, processedPaths)
1839 ).filter(
1840 f => !skipProjectLevel || (f.type !== 'Project' && f.type !== 'Local'),
1841 )
1842 attachments.push(
1843 ...memoryFilesToAttachments(memoryFiles, toolUseContext, filePath),
1844 )
1845 }
1846
1847 // Phase 4: Process CWD-level directories (root → CWD)
1848 // Only conditional rules (unconditional rules are already loaded eagerly)
1849 for (const dir of cwdLevelDirs) {
1850 const conditionalRules = (
1851 await getConditionalRulesForCwdLevelDirectory(
1852 dir,
1853 filePath,
1854 processedPaths,
1855 )

Callers 2

getOpenedFileFromIDEFunction · 0.85

Tested by

no test coverage detected