const CRITERIA_SECTION_RE = /^criteria:\n([\s\S]*?)(?=^[a-zA-Z_][\w-]*:|\n---|\s*$)/m;
const CRITERION_TEXT_RE = /^\s+- text:\s*"?(.+?)"?\s*$/gm;
const FILE_LINE_RE = /^-\s+(.+?)\s+\((pending|done)\)\s*$/gm;
const GENERIC_CRITERION_RULES = [
    {
        pattern: /\bimplementation (is )?complete\b/i,
        reason: 'self-certifying completion is not a testable behavior',
    },
    {
        pattern: /\bcomplete and tested\b/i,
        reason: 'completion and testing must be proven by evidence, not criteria text',
    },
    {
        pattern: /\ball edge cases\b/i,
        reason: 'edge cases must be named explicitly',
    },
    {
        pattern: /\bgeneric validation\b/i,
        reason: 'validation must identify the behavior and expected result',
    },
    {
        pattern: /\bensure (adequate )?coverage\b/i,
        reason: 'coverage claims must map to concrete validation evidence',
    },
    {
        pattern: /\bautopilot could not infer testable behavior\b/i,
        reason: 'fallback uncertainty cannot become an acceptance criterion',
    },
    {
        pattern: /\bdefine acceptance criteria\b/i,
        reason: 'a request to define criteria is not itself a criterion',
    },
    {
        pattern: /\b(example only|for example|sample)\b/i,
        reason: 'example-only references cannot become contract criteria',
    },
    {
        pattern: /\b(add|create|implement)\s+(api\s+)?(endpoint|route|migration)s?\b/i,
        reason: 'broad implementation references must name grounded behavior and evidence',
    },
];
const PLACEHOLDER_REFERENCE_RULES = [
    {
        pattern: /\b(to be determined|tbd|placeholder|not specified)\b/i,
        reason: 'placeholder references are not grounded implementation ownership',
    },
    {
        pattern: /(^|\/)(example|sample|mock|dummy)[\w.-]*\.[a-z]+$/i,
        reason: 'example file names must not be persisted as technical ownership',
    },
];
export function checkGenericSpecOutput(content) {
    const issues = [
        ...checkCriteria(frontmatterCriteria(content)),
        ...checkTechnicalReferences(content),
    ];
    return { passed: issues.length === 0, issues };
}
function frontmatterCriteria(content) {
    const criteriaSection = CRITERIA_SECTION_RE.exec(content)?.[1] ?? '';
    const criteria = [];
    let match = CRITERION_TEXT_RE.exec(criteriaSection);
    while (match) {
        const phrase = match[1]?.replace(/\\"/g, '"').trim() ?? '';
        if (phrase.length > 0) {
            criteria.push(phrase);
        }
        match = CRITERION_TEXT_RE.exec(criteriaSection);
    }
    return criteria;
}
function checkCriteria(criteria) {
    const issues = [];
    for (const criterion of criteria) {
        for (const rule of GENERIC_CRITERION_RULES) {
            if (rule.pattern.test(criterion)) {
                issues.push({
                    kind: rule.reason.includes('coverage') ? 'unsupported-verification' : 'generic-criterion',
                    phrase: criterion,
                    reason: rule.reason,
                });
            }
        }
    }
    return issues;
}
function checkTechnicalReferences(content) {
    const issues = [];
    let match = FILE_LINE_RE.exec(content);
    while (match) {
        const phrase = match[1]?.replace(/`/g, '').trim() ?? '';
        for (const rule of PLACEHOLDER_REFERENCE_RULES) {
            if (rule.pattern.test(phrase)) {
                issues.push({
                    kind: 'placeholder-reference',
                    phrase,
                    reason: rule.reason,
                });
            }
        }
        match = FILE_LINE_RE.exec(content);
    }
    return issues;
}
//# sourceMappingURL=generic-output-gate.js.map