// engine/github/pr-template.ts — Generate PR template from spec content.
/**
 * Generate a PR title from a spec ID and name.
 */
export function generatePRTitle(specId, specName) {
    const slug = specName
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, '-')
        .replace(/^-|-$/g, '');
    return `feat(${specId}): ${slug}`;
}
/**
 * Parse a spec.md file content and extract structured data for PR body.
 */
export function parseSpecContent(content) {
    const lines = content.split('\n');
    let title = '';
    let userStory = '';
    const criteria = [];
    let inUserStory = false;
    let inCriteria = false;
    for (const line of lines) {
        if (line.startsWith('# ')) {
            title = line.replace(/^#\s+/, '').trim();
            continue;
        }
        if (/##\s*(Historia de Usuario|User Story)/i.test(line)) {
            inUserStory = true;
            inCriteria = false;
            continue;
        }
        if (/##\s*(Criterios|Acceptance Criteria)/i.test(line)) {
            inUserStory = false;
            inCriteria = true;
            continue;
        }
        if (/^##\s/.test(line)) {
            inUserStory = false;
            inCriteria = false;
            continue;
        }
        if (inUserStory && line.trim()) {
            userStory += (userStory ? ' ' : '') + line.trim();
        }
        if (inCriteria && /^###\s+AC-\d+/.test(line)) {
            criteria.push(line.replace(/^###\s+/, '').trim());
        }
    }
    return { title, userStory, criteria };
}
/**
 * Generate a full PR body from spec content.
 */
export function generatePRBody(specId, specContent, filesChanged) {
    const { userStory, criteria } = parseSpecContent(specContent);
    const sections = [];
    sections.push(`## ${specId}\n`);
    if (userStory) {
        sections.push(`### Summary\n\n${userStory}\n`);
    }
    if (criteria.length > 0) {
        sections.push('### Acceptance Criteria\n');
        for (const c of criteria) {
            sections.push(`- [ ] ${c}`);
        }
        sections.push('');
    }
    if (filesChanged && filesChanged.length > 0) {
        sections.push('### Files Changed\n');
        for (const f of filesChanged) {
            sections.push(`- \`${f}\``);
        }
        sections.push('');
    }
    sections.push('---');
    sections.push('*Generated by Planu MCP Server*');
    return sections.join('\n');
}
//# sourceMappingURL=pr-template.js.map