extractSectionName static method
Extract a human-readable name from a system prompt section's content.
Implementation
static String extractSectionName(String content) {
// Try to find first markdown heading
final headingMatch = RegExp(
r'^#+\s+(.+)$',
multiLine: true,
).firstMatch(content);
if (headingMatch != null) return headingMatch.group(1)!.trim();
// Fall back to a truncated preview
final firstLine = content
.split('\n')
.firstWhere((l) => l.trim().isNotEmpty, orElse: () => '');
return firstLine.length > 40
? '${firstLine.substring(0, 40)}...'
: firstLine;
}