const EPHEMERAL_PATTERNS = /\b(today|now|currently|temporary|todo|fix this|error log|stack trace|npm run|validation|token|secret|password)\b/i;
function cleanTerm(value) {
    return value
        .replaceAll("`", "")
        .replace(/[.:;]+$/g, "")
        .trim();
}
function isUsefulTerm(term, meaning) {
    if (term.length < 3 || meaning.length < 8)
        return false;
    if (term.length > 80 || meaning.length > 300)
        return false;
    if (EPHEMERAL_PATTERNS.test(`${term} ${meaning}`))
        return false;
    return /[A-Za-z]/.test(term) && /[A-Za-z]/.test(meaning);
}
function candidate(term, meaning, reason, confidence, source) {
    const name = cleanTerm(term);
    const description = cleanTerm(meaning);
    if (!isUsefulTerm(name, description))
        return undefined;
    return { name, meaning: description, reason, confidence, source };
}
export function detectContextCandidates(text, source = "user") {
    const candidates = [];
    const patterns = [
        {
            regex: /\b(?:call|llam(?:a|emos)|use|usar)\s+(.+?)\s+(?:as|como)\s+(.+?)(?:\.|\n|$)/gi,
            reason: "explicit naming convention",
            confidence: 0.8,
        },
        {
            regex: /\b(.+?)\s+(?:means|significa|is defined as|se define como)\s+(.+?)(?:\.|\n|$)/gi,
            reason: "explicit term definition",
            confidence: 0.85,
        },
        {
            regex: /\b(?:in this project|en este proyecto),?\s+(.+?)\s+(?:means|significa|refers to|se refiere a)\s+(.+?)(?:\.|\n|$)/gi,
            reason: "project-scoped vocabulary",
            confidence: 0.9,
        },
    ];
    for (const pattern of patterns) {
        for (const match of text.matchAll(pattern.regex)) {
            const found = candidate(match[1], match[2], pattern.reason, pattern.confidence, source);
            if (found)
                candidates.push(found);
        }
    }
    return dedupeContextCandidates(candidates);
}
export function dedupeContextCandidates(candidates) {
    const seen = new Set();
    const deduped = [];
    for (const entry of candidates) {
        const key = entry.name.toLowerCase();
        if (seen.has(key))
            continue;
        seen.add(key);
        deduped.push(entry);
    }
    return deduped.sort((left, right) => right.confidence - left.confidence);
}
//# sourceMappingURL=context-candidates.js.map