MCPcopy Create free account
hub / github.com/anus-dev/ANUS / processFlat

Function processFlat

packages/core/src/utils/memoryImportProcessor.ts:242–311  ·  view source on GitHub ↗
(
      fileContent: string,
      fileBasePath: string,
      filePath: string,
      depth: number,
    )

Source from the content-addressed store, hash-verified

240
241 // Helper to recursively process imports
242 async function processFlat(
243 fileContent: string,
244 fileBasePath: string,
245 filePath: string,
246 depth: number,
247 ) {
248 // Normalize the file path to ensure consistent comparison
249 const normalizedPath = path.normalize(filePath);
250
251 // Skip if already processed
252 if (processedFiles.has(normalizedPath)) return;
253
254 // Mark as processed before processing to prevent infinite recursion
255 processedFiles.add(normalizedPath);
256
257 // Add this file to the flat list
258 flatFiles.push({ path: normalizedPath, content: fileContent });
259
260 // Find imports in this file
261 const codeRegions = findCodeRegions(fileContent);
262 const imports = findImports(fileContent);
263
264 // Process imports in reverse order to handle indices correctly
265 for (let i = imports.length - 1; i >= 0; i--) {
266 const { start, path: importPath } = imports[i];
267
268 // Skip if inside a code region
269 if (
270 codeRegions.some(
271 ([regionStart, regionEnd]) =>
272 start >= regionStart && start < regionEnd,
273 )
274 ) {
275 continue;
276 }
277
278 // Validate import path
279 if (
280 !validateImportPath(importPath, fileBasePath, [projectRoot || ''])
281 ) {
282 continue;
283 }
284
285 const fullPath = path.resolve(fileBasePath, importPath);
286 const normalizedFullPath = path.normalize(fullPath);
287
288 // Skip if already processed
289 if (processedFiles.has(normalizedFullPath)) continue;
290
291 try {
292 await fs.access(fullPath);
293 const importedContent = await fs.readFile(fullPath, 'utf-8');
294
295 // Process the imported file
296 await processFlat(
297 importedContent,
298 path.dirname(fullPath),
299 normalizedFullPath,

Callers 1

processImportsFunction · 0.85

Calls 6

findCodeRegionsFunction · 0.85
findImportsFunction · 0.85
validateImportPathFunction · 0.85
hasMessageFunction · 0.85
addMethod · 0.80
readFileMethod · 0.80

Tested by

no test coverage detected