/** * Reads art/STYLE.md: §1, the system prompt every picture starts with, and §7, the * review points. The file is the only copy of both, so Mark edits one place. */ function section(markdown: string, n: number): string { const text = markdown.replace(/\r\n?/g, '\n'); const start = text.search(new RegExp(`^## ${n}\\.`, 'm')); if (start < 0) throw new Error(`art/STYLE.md has no "## ${n}." section`); const rest = text.slice(start); const end = rest.slice(1).search(/^## /m); return end < 0 ? rest : rest.slice(0, end + 1); } /** §1: the quoted paragraph, line breaks kept, the `> ` markers removed. */ export function stylePrompt(markdown: string): string { const lines = section(markdown, 1) .split('\n') .filter((l) => l.startsWith('>')) .map((l) => l.replace(/^>\s?/, '')); if (lines.length === 0) throw new Error('art/STYLE.md §1 has no quoted system prompt'); return lines.join('\n').trim(); } /** §7: the numbered review points, each joined into one line. */ export function reviewPoints(markdown: string): string[] { const points: string[] = []; for (const line of section(markdown, 7).split('\n')) { const item = /^(\d+)\.\s+(.*)$/.exec(line); if (item) { if (Number(item[1]) !== points.length) throw new Error(`art/STYLE.md §7: point ${item[1]} is out of order`); points.push((item[2] ?? '').trim()); } else if (/^\s+\S/.test(line) && points.length > 0) { points[points.length - 1] += ' ' + line.trim(); } } if (points.length === 0) throw new Error('art/STYLE.md §7 has no review points'); return points; }