// engine/whats-new.ts — Extract changelog highlights between two versions (best-effort)
import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
export function getWhatsNew(lastSeenVersion, currentVersion) {
    if (lastSeenVersion === currentVersion) {
        return null;
    }
    try {
        const changelogPath = join(dirname(fileURLToPath(import.meta.url)), '../../CHANGELOG.md');
        const content = readFileSync(changelogPath, 'utf-8');
        const sections = content.split(/^## \[/m).slice(1); // skip preamble
        const newSections = [];
        for (const section of sections) {
            const versionMatch = /^([\d.]+)\]/.exec(section);
            if (!versionMatch) {
                continue;
            }
            const sectionVersion = versionMatch[1];
            if (sectionVersion === lastSeenVersion) {
                break;
            }
            const lines = section.split('\n');
            const highlights = lines
                .filter((l) => /^\* \*\*(feat|fix)\*\*/.test(l.trim()))
                .slice(0, 5)
                .map((l) => l.trim());
            if (highlights.length > 0) {
                newSections.push(`**v${sectionVersion}**\n${highlights.join('\n')}`);
            }
        }
        if (newSections.length === 0) {
            return null;
        }
        const limited = newSections.slice(0, 3);
        return `🆕 **What's New since v${lastSeenVersion}**\n\n${limited.join('\n\n')}`;
    }
    catch {
        return null; // best-effort
    }
}
//# sourceMappingURL=whats-new.js.map