// engine/verifier/bdd-entity-extractor.ts — BDD criterion entity extraction (SPEC-786)
// Extracted from criterion-matcher.ts to keep file sizes within limits.
/**
 * BDD prose stop words — Gherkin keywords and result-description words that
 * appear in acceptance criteria text but carry no technical signal for source
 * matching. Used to detect "pure behavioural prose" criteria (e.g. THEN-lines
 * like "that criterion is marked matched") which cannot be verified by scanning
 * source code and should receive `partial` rather than `unverified`.
 */
export const BDD_STOP_WORDS = new Set([
    // Common English stop words (mirrors STOP_WORDS in criterion-matcher.ts)
    'the',
    'a',
    'an',
    'and',
    'or',
    'but',
    'in',
    'on',
    'at',
    'to',
    'for',
    'of',
    'with',
    'by',
    'from',
    'is',
    'are',
    'was',
    'were',
    'be',
    'been',
    'have',
    'has',
    'had',
    'do',
    'does',
    'did',
    'will',
    'would',
    'could',
    'should',
    'may',
    'might',
    'must',
    'shall',
    'can',
    'need',
    'that',
    'this',
    'it',
    'its',
    'when',
    'if',
    'then',
    'else',
    'not',
    'no',
    'yes',
    'all',
    'each',
    'every',
    'any',
    'some',
    'which',
    'who',
    'what',
    'where',
    'how',
    'so',
    'as',
    'than',
    'into',
    'about',
    'after',
    'before',
    'between',
    'such',
    'only',
    'also',
    'return',
    'returns',
    'given',
    'there',
    'their',
    'they',
    'them',
    'user',
    'users',
    'system',
    'data',
    'value',
    'values',
    'true',
    'false',
    'null',
    'undefined',
    'new',
    'type',
    'types',
    // Gherkin keywords
    'scenario',
    'feature',
    'background',
    'examples',
    // BDD result/behaviour description words (SPEC-786)
    'criterion',
    'criteria',
    'marked',
    'matched',
    'missing',
    'found',
    'exists',
    'exist',
    'passes',
    'passed',
    'fails',
    'failed',
    'runs',
    'run',
    'calls',
    'called',
    'returned',
    'assert',
    'check',
    'verify',
    'validates',
    'validated',
    'test',
    'tests',
    'score',
    'result',
    'output',
    'input',
    'file',
    'files',
    'function',
    'functions',
    'class',
    'method',
    'module',
    'spec',
    'specs',
    'behavior',
    'behaviour',
    'expected',
    'actual',
    'correct',
    'correctly',
    'complete',
    'completed',
    'done',
    'implement',
    'implemented',
    'create',
    'created',
    'update',
    'updated',
    'delete',
    'deleted',
    'add',
    'added',
    'remove',
    'removed',
    'change',
    'changed',
    'emit',
    'emits',
    'trigger',
    'triggers',
    'handle',
    'handles',
    'cover',
    'covers',
    'meet',
    'meets',
    'satisfy',
    'satisfied',
]);
/**
 * Extracts technical entities from a BDD criterion text.
 * These are identifiers that can be cross-referenced against the codebase:
 *   - Backtick-enclosed literals (highest signal: exact names, file paths)
 *   - camelCase identifiers (function/variable names)
 *   - PascalCase identifiers (class/type names)
 *   - File-system path fragments (src/…, tests/…)
 *
 * BDD prose words (given/when/then/matched/criterion…) are excluded via BDD_STOP_WORDS.
 * Returns an empty array when the criterion is pure behavioural prose with
 * no verifiable technical signal — callers use this to decide whether to return
 * `partial` instead of `unverified` for THEN-line criteria.
 */
export function extractBddEntities(criterion) {
    const entities = new Set();
    let match;
    // 1. Backtick-enclosed literals — highest signal (explicit names/paths).
    const backtickPattern = /`([^`]+)`/g;
    while ((match = backtickPattern.exec(criterion)) !== null) {
        const val = match[1]?.trim();
        if (val && val.length > 1) {
            entities.add(val);
        }
    }
    // 2. camelCase identifiers (at least 2 segments, not BDD stop words).
    const camelCasePattern = /\b[a-z][a-zA-Z0-9]*[A-Z][a-zA-Z0-9]*\b/g;
    while ((match = camelCasePattern.exec(criterion)) !== null) {
        const word = match[0];
        if (!BDD_STOP_WORDS.has(word.toLowerCase())) {
            entities.add(word);
        }
    }
    // 3. PascalCase identifiers (length >= 3, not BDD stop words).
    const pascalCasePattern = /\b[A-Z][a-zA-Z0-9]{2,}\b/g;
    while ((match = pascalCasePattern.exec(criterion)) !== null) {
        const word = match[0];
        if (!BDD_STOP_WORDS.has(word.toLowerCase())) {
            entities.add(word);
        }
    }
    // 4. File-system path fragments (src/… or tests/…) not in backticks.
    const pathPattern = /(?:src|tests|lib|app)\/[\w./-]{3,}/g;
    while ((match = pathPattern.exec(criterion)) !== null) {
        entities.add(match[0]);
    }
    return Array.from(entities);
}
//# sourceMappingURL=bdd-entity-extractor.js.map