MCPcopy Index your code
hub / github.com/Noumena-Network/code / safelyReadMemoryFileAsync

Function safelyReadMemoryFileAsync

src/utils/claudemd.ts:430–459  ·  view source on GitHub ↗

* Used by processMemoryFile → getMemoryFiles so the event loop stays * responsive during the directory walk (many readFile attempts, most * ENOENT). When includeBasePath is given, @include paths are resolved in * the same lex pass and returned alongside the parsed file.

(
  filePath: string,
  type: MemoryType,
  includeBasePath?: string,
)

Source from the content-addressed store, hash-verified

428 * the same lex pass and returned alongside the parsed file.
429 */
430async function safelyReadMemoryFileAsync(
431 filePath: string,
432 type: MemoryType,
433 includeBasePath?: string,
434): Promise<{ info: MemoryFileInfo | null; includePaths: string[] }> {
435 try {
436 const fs = getFsImplementation()
437 const rawContent = await fs.readFile(filePath, { encoding: 'utf-8' })
438 const {
439 content: sanitizedContent,
440 stripped: strippedOperationalSections,
441 } = stripOperationalProjectInstructions(rawContent, filePath, type)
442 const parsed = parseMemoryFileContent(
443 sanitizedContent,
444 filePath,
445 type,
446 includeBasePath,
447 )
448
449 if (parsed.info && strippedOperationalSections) {
450 parsed.info.contentDiffersFromDisk = true
451 parsed.info.rawContent = rawContent
452 }
453
454 return parsed
455 } catch (error) {
456 handleMemoryFileReadError(error, filePath)
457 return { info: null, includePaths: [] }
458 }
459}
460
461type MarkdownToken = {
462 type: string

Callers 2

processMemoryFileFunction · 0.85
claudemd.tsFile · 0.85

Calls 5

getFsImplementationFunction · 0.85
parseMemoryFileContentFunction · 0.85
readFileMethod · 0.80

Tested by

no test coverage detected