loadMemoryPrompt method

Future<MemoryPromptResult> loadMemoryPrompt()

Build the memory prompt to inject into the system prompt. Loads MEMORY.md content and constructs behavioral instructions.

Implementation

Future<MemoryPromptResult> loadMemoryPrompt() async {
  await initialize();

  final memPath = getAutoMemPath(projectRoot: projectRoot);
  final entrypoint = getAutoMemEntrypoint(projectRoot: projectRoot);
  final entrypointFile = File(entrypoint);

  String? entrypointContent;
  if (await entrypointFile.exists()) {
    entrypointContent = await _readEntrypoint(entrypointFile);
  }

  // Count memory files for analytics
  final headers = await scanMemoryFiles(memPath);

  final prompt = _buildMemoryPrompt(
    memoryDir: memPath,
    entrypointContent: entrypointContent,
    memoryFileCount: headers.length,
  );

  return MemoryPromptResult(
    prompt: prompt,
    memoryFileCount: headers.length,
    memoryDirExists: true,
  );
}