formatProjectContext function

String formatProjectContext(
  1. List<ProjectContextFile> files
)

Renders the context files as a system-prompt section (kimi's wrapper, reduced): each file annotated with its source path, precedence note for deeper-vs-shallower rules. Empty when nothing was discovered.

Implementation

String formatProjectContext(List<ProjectContextFile> files) {
  if (files.isEmpty) return '';
  final buffer = StringBuffer()
    ..writeln('<project_context>')
    ..writeln()
    ..writeln('Project-specific instructions and guidelines:')
    ..writeln();
  for (final file in files) {
    buffer
      ..writeln('<!-- From: ${file.path} -->')
      ..writeln(file.content.trim())
      ..writeln();
  }
  buffer
    ..writeln('</project_context>')
    ..write(
      'When instructions in deeper files conflict with shallower ones, the '
      'deeper file takes precedence; user instructions given directly in '
      'the conversation take the highest precedence.',
    );
  return buffer.toString();
}