Extract a human-readable name from a system prompt section's content
(content: string)
| 259 | |
| 260 | /** Extract a human-readable name from a system prompt section's content */ |
| 261 | function extractSectionName(content: string): string { |
| 262 | // Try to find first markdown heading |
| 263 | const headingMatch = content.match(/^#+\s+(.+)$/m) |
| 264 | if (headingMatch) { |
| 265 | return headingMatch[1]!.trim() |
| 266 | } |
| 267 | // Fall back to a truncated preview of the first non-empty line |
| 268 | const firstLine = content.split('\n').find(l => l.trim().length > 0) ?? '' |
| 269 | return firstLine.length > 40 ? firstLine.slice(0, 40) + '…' : firstLine |
| 270 | } |
| 271 | |
| 272 | async function countSystemTokens( |
| 273 | effectiveSystemPrompt: readonly string[], |