const GENERIC_QUESTION_PATTERNS = [
    /^who (are|is) the users\??$/i,
    /^what are the edge cases\??$/i,
    /^what should happen\??$/i,
    /^what is the scope\??$/i,
    /^what data is needed\??$/i,
    /^what are the requirements\??$/i,
];
export function validateQuestionGrounding(question, context) {
    const text = question.question.trim();
    if (GENERIC_QUESTION_PATTERNS.some((pattern) => pattern.test(text))) {
        return { passed: false, reason: 'Question is a generic reusable prompt.' };
    }
    const lowerQuestion = text.toLowerCase();
    const lowerEvidence = [context.requestText, ...context.gap.evidence].join(' ').toLowerCase();
    const evidenceTokens = tokenSet(lowerEvidence);
    const hasRequestEvidence = Array.from(evidenceTokens).some((token) => token.length >= 3 && lowerQuestion.includes(token));
    if (!hasRequestEvidence) {
        return {
            passed: false,
            reason: 'Question does not include evidence from the request or detected gap.',
        };
    }
    if (!/\bchanges?\b|\bthis changes\b|\baffects?\b|\bbecause\b|\bbecomes?\b/i.test(text)) {
        return {
            passed: false,
            reason: 'Question does not explain why the answer matters for the spec.',
        };
    }
    return { passed: true };
}
function tokenSet(text) {
    return new Set(text
        .replace(/[^a-z0-9 ]/gi, ' ')
        .split(/\s+/)
        .filter((token) => !STOP_WORDS.has(token) && token.length > 2));
}
const STOP_WORDS = new Set([
    'the',
    'and',
    'for',
    'this',
    'that',
    'with',
    'from',
    'what',
    'when',
    'where',
    'should',
    'action',
    'object',
    'risk',
]);
//# sourceMappingURL=question-grounding-gate.js.map