export function checkDoneDriftContract(args) {
    const issues = [];
    const uncovered = args.index.criteria.filter((entry) => {
        const hasChangedFile = entry.evidence.some((record) => record.kind === 'changed-file' &&
            (record.status === 'valid' || record.status === 'missing'));
        const hasValidation = entry.evidence.some((record) => record.kind === 'validation' && record.status === 'valid');
        return !hasChangedFile || !hasValidation;
    });
    if (uncovered.length > 0) {
        issues.push({
            code: 'done_drift_uncovered_criteria',
            message: `Done drift check found criteria without mapped changed files or validation evidence: ${uncovered.map((entry) => entry.criterion).join('; ')}`,
        });
    }
    const staleOrInvalid = args.index.criteria.flatMap((entry) => entry.evidence
        .filter((record) => record.status === 'stale' || record.status === 'invalid')
        .map((record) => `${entry.criterion}: ${record.value} (${record.status})`));
    if (staleOrInvalid.length > 0) {
        issues.push({
            code: 'done_drift_stale_evidence',
            message: `Done drift check found stale or invalid evidence: ${staleOrInvalid.join('; ')}`,
        });
    }
    const grounded = new Set(args.groundedTechnicalPaths);
    if (grounded.size > 0) {
        const unapproved = args.index.criteria.flatMap((entry) => {
            const hasScopeAmendment = entry.evidence.some((record) => record.kind === 'reviewer' && /scope amendment|approved scope/i.test(record.value));
            if (hasScopeAmendment) {
                return [];
            }
            return entry.evidence
                .filter((record) => record.kind === 'changed-file' && !grounded.has(record.value))
                .map((record) => `${entry.criterion}: ${record.value}`);
        });
        if (unapproved.length > 0) {
            issues.push({
                code: 'done_drift_unapproved_scope',
                message: `Done drift check found changed files outside grounded spec scope: ${unapproved.join('; ')}`,
            });
        }
    }
    return issues;
}
//# sourceMappingURL=done-drift.js.map