(model: string, seen: Set<string> = new Set())
| 25 | const INHERIT_RE = /^\s*\{\{INHERIT:([a-z0-9-]+(?:\.[0-9]+)*)\}\}\s*\n/; |
| 26 | |
| 27 | export function readOverlay(model: string, seen: Set<string> = new Set()): string { |
| 28 | if (seen.has(model)) return ''; // cycle guard |
| 29 | seen.add(model); |
| 30 | |
| 31 | const filePath = path.join(OVERLAY_DIR, `${model}.md`); |
| 32 | if (!fs.existsSync(filePath)) return ''; |
| 33 | |
| 34 | const raw = fs.readFileSync(filePath, 'utf-8'); |
| 35 | const match = raw.match(INHERIT_RE); |
| 36 | if (!match) return raw.trim(); |
| 37 | |
| 38 | const baseModel = match[1]; |
| 39 | const base = readOverlay(baseModel, seen); |
| 40 | const rest = raw.replace(INHERIT_RE, '').trim(); |
| 41 | |
| 42 | if (!base) return rest; |
| 43 | return `${base}\n\n${rest}`; |
| 44 | } |
| 45 | |
| 46 | export function generateModelOverlay(ctx: TemplateContext): string { |
| 47 | if (!ctx.model) return ''; |
no outgoing calls