loadPromptFile function

String loadPromptFile(
  1. String path, {
  2. required String homeDir,
  3. required String baseDir,
  4. required String source,
})

Reads path as a prompt override file: YAML frontmatter is stripped (so the prompts/** Markdown sources can be copied verbatim as overrides) and the body is trimmed. A missing or unreadable file throws ConfigException prefixed with source — never a silent fallback.

Implementation

String loadPromptFile(
  String path, {
  required String homeDir,
  required String baseDir,
  required String source,
}) {
  final resolved = resolvePromptFilePath(
    path,
    homeDir: homeDir,
    baseDir: baseDir,
  );
  final file = File(resolved);
  if (!file.existsSync()) {
    throw ConfigException('$source: prompt file not found: $resolved');
  }
  final String content;
  try {
    content = file.readAsStringSync();
  } on Object catch (error) {
    throw ConfigException('$source: cannot read prompt file $resolved: $error');
  }
  final body = parseFrontmatter(content).body.trim();
  if (body.isEmpty) {
    throw ConfigException('$source: prompt file is empty: $resolved');
  }
  return body;
}