/**
 * Normalize text for matching: lowercase, replace separators with space.
 */
function normalize(text) {
    return text
        .toLowerCase()
        .replace(/[-_/\\.]/g, ' ')
        .replace(/\s+/g, ' ')
        .trim();
}
/**
 * Extract keywords from an out-of-scope item phrase (>3 chars).
 */
const STOP_WORDS = new Set(['the', 'and', 'for', 'with', 'that', 'this', 'from', 'will']);
function keywords(phrase) {
    return normalize(phrase)
        .split(' ')
        .filter((w) => w.length > 3 && !STOP_WORDS.has(w));
}
/**
 * Determine whether a file path matches an out-of-scope item.
 * Strategy: keyword overlap between normalized file path and out-of-scope keywords.
 */
function fileMatchesScopeItem(filePath, scopeItem) {
    const normPath = normalize(filePath);
    const scopeKws = keywords(scopeItem);
    if (scopeKws.length === 0) {
        return false;
    }
    const matchCount = scopeKws.filter((kw) => normPath.includes(kw)).length;
    // Require at least 1 keyword match for a warning
    return matchCount >= 1;
}
/**
 * Validate implementation file paths against the spec's outOfScope declarations.
 * Returns warnings for every file that appears to implement something declared out of scope.
 */
export function validateScopeCompliance(outOfScope, filePaths) {
    const warnings = [];
    for (const filePath of filePaths) {
        for (const scopeItem of outOfScope) {
            if (fileMatchesScopeItem(filePath, scopeItem)) {
                const matchedKws = keywords(scopeItem)
                    .filter((kw) => normalize(filePath).includes(kw))
                    .join(', ');
                warnings.push({
                    filePath,
                    violates: scopeItem,
                    reason: `File path contains keyword(s) matching out-of-scope item: "${matchedKws}"`,
                });
                break; // one warning per file per scope item is enough; avoid duplicates per file
            }
        }
    }
    const isClean = warnings.length === 0;
    const summary = isClean
        ? 'No scope violations detected in implementation files.'
        : `Found ${warnings.length} potential scope violation(s) in implementation files.`;
    return { warnings, isClean, summary };
}
//# sourceMappingURL=scope-validator.js.map