// tools/clarify-requirements/interview-mode.ts — Structured Interview Mode (SPEC-252)
// Tracks coverage across 7 dimensions and guides toward create_spec
import { isShortTopic } from './questions.js';
/** Keywords per dimension used to detect coverage from answer text. */
const DIMENSION_KEYWORDS = {
    technical: [
        'typescript',
        'javascript',
        'python',
        'java',
        'rust',
        'go',
        'database',
        'sql',
        'nosql',
        'api',
        'rest',
        'graphql',
        'grpc',
        'microservice',
        'monolith',
        'architecture',
        'framework',
        'library',
        'sdk',
        'algorithm',
        'data structure',
        'cache',
        'queue',
        'message broker',
        'docker',
        'kubernetes',
        'serverless',
        'function',
        'endpoint',
        'backend',
        'frontend',
        'fullstack',
        'stack',
        'implementation',
        'deploy',
        'build',
        'compile',
        'runtime',
    ],
    ux: [
        'user',
        'ui',
        'interface',
        'ux',
        'experience',
        'design',
        'layout',
        'screen',
        'page',
        'form',
        'input',
        'button',
        'menu',
        'navigation',
        'mobile',
        'responsive',
        'accessible',
        'accessibility',
        'a11y',
        'wcag',
        'flow',
        'journey',
        'onboarding',
        'dashboard',
        'view',
        'visual',
        'theme',
        'color',
        'typography',
        'component',
        'widget',
    ],
    'edge-cases': [
        'edge case',
        'corner case',
        'error',
        'failure',
        'invalid',
        'empty',
        'null',
        'undefined',
        'exception',
        'boundary',
        'limit',
        'overflow',
        'timeout',
        'retry',
        'fallback',
        'race condition',
        'concurrent',
        'duplicate',
        'missing',
        'malformed',
        'validation',
        'constraint',
        'maximum',
        'minimum',
        'zero',
        'negative',
        'large',
        'empty list',
        'not found',
        '404',
        'conflict',
    ],
    tradeoffs: [
        'tradeoff',
        'trade-off',
        'vs',
        'versus',
        'alternative',
        'option',
        'approach',
        'decision',
        'pros',
        'cons',
        'advantage',
        'disadvantage',
        'balance',
        'priority',
        'complexity',
        'simplicity',
        'maintainability',
        'scalability',
        'cost',
        'benefit',
        'risk',
        'impact',
        'consistency',
        'availability',
        'partition',
        'cap theorem',
        'eventual',
        'strong consistency',
    ],
    security: [
        'security',
        'auth',
        'authentication',
        'authorization',
        'permission',
        'role',
        'rbac',
        'jwt',
        'token',
        'session',
        'cookie',
        'csrf',
        'xss',
        'sql injection',
        'sanitize',
        'encrypt',
        'encryption',
        'https',
        'tls',
        'ssl',
        'secret',
        'credential',
        'password',
        'hash',
        'salt',
        'oauth',
        'saml',
        'sso',
        'rate limit',
        'ddos',
        'audit log',
        'pii',
        'gdpr',
        'data protection',
        'vulnerability',
        'threat',
        'attack',
        'penetration',
    ],
    performance: [
        'performance',
        'latency',
        'throughput',
        'response time',
        'speed',
        'fast',
        'slow',
        'optimization',
        'cache',
        'caching',
        'cdn',
        'load',
        'scale',
        'concurrent',
        'async',
        'parallel',
        'batch',
        'benchmark',
        'profile',
        'metric',
        'monitor',
        'sla',
        'p99',
        'p95',
        'millisecond',
        'second',
        'rps',
        'tps',
        'qps',
        'memory',
        'cpu',
        'bandwidth',
        'bottleneck',
    ],
    integration: [
        'integration',
        'integrate',
        'api',
        'webhook',
        'event',
        'third-party',
        'external',
        'service',
        'provider',
        'vendor',
        'sdk',
        'library',
        'plugin',
        'connector',
        'adapter',
        'interface',
        'contract',
        'protocol',
        'format',
        'json',
        'xml',
        'csv',
        'import',
        'export',
        'sync',
        'async',
        'push',
        'pull',
        'poll',
        'stream',
        'batch',
        'migration',
        'interop',
    ],
};
/** Priority order for picking the next uncovered dimension. */
const DIMENSION_PRIORITY = [
    'technical',
    'security',
    'edge-cases',
    'performance',
    'integration',
    'tradeoffs',
    'ux',
];
/** Questions template per dimension. Avoids trivial things a senior dev already knows. */
const DIMENSION_QUESTION_TEMPLATES = {
    technical: (topic) => `For "${topic}", which architectural constraints or technology choices are non-negotiable — and which are open to discussion?`,
    ux: (topic) => `Who are the distinct user personas for "${topic}", and what are the critical interaction flows that must feel seamless?`,
    'edge-cases': (topic) => `What are the failure modes for "${topic}" that could silently corrupt data or leave the system in an inconsistent state?`,
    tradeoffs: (topic) => `What tradeoffs are you willing to accept for "${topic}" — e.g., consistency vs. availability, simplicity vs. extensibility, speed to ship vs. completeness?`,
    security: (topic) => `What is the threat model for "${topic}"? Which data is sensitive, who are the adversaries, and which attack vectors are in scope?`,
    performance: (topic) => `What are the concrete SLAs for "${topic}" — target latency (p95/p99), throughput (rps), and acceptable degradation under load?`,
    integration: (topic) => `Which external systems or third-party services must "${topic}" integrate with, and what are the contract/version constraints?`,
};
/**
 * Analyzes answers to update which dimensions are covered.
 * Merges with an existing coverage map if provided.
 */
export function updateCoverageFromAnswers(answers, existing) {
    const base = existing ?? {
        technical: false,
        ux: false,
        'edge-cases': false,
        tradeoffs: false,
        security: false,
        performance: false,
        integration: false,
    };
    const allText = Object.values(answers).join(' ').toLowerCase();
    const dimensions = Object.keys(DIMENSION_KEYWORDS);
    const updated = { ...base };
    for (const dim of dimensions) {
        if (updated[dim]) {
            continue;
        } // already covered
        const keywords = DIMENSION_KEYWORDS[dim];
        if (keywords.some((kw) => allText.includes(kw))) {
            updated[dim] = true;
        }
    }
    return updated;
}
/**
 * Returns the lowest-priority uncovered dimension, or null if all are covered.
 */
export function pickNextDimension(coverage) {
    for (const dim of DIMENSION_PRIORITY) {
        if (!coverage[dim]) {
            return dim;
        }
    }
    return null;
}
/**
 * Generates a targeted follow-up question for a specific dimension.
 * Takes existing answers into account to avoid repeating covered ground.
 */
export function generateDimensionQuestion(dimension, topic, answers) {
    const alreadyMentioned = Object.values(answers).join(' ').toLowerCase();
    const baseQuestion = DIMENSION_QUESTION_TEMPLATES[dimension](topic);
    // Add context hint if the answer set is non-empty and hints at partial coverage
    const keywords = DIMENSION_KEYWORDS[dimension];
    const partiallyMentioned = keywords.filter((kw) => alreadyMentioned.includes(kw));
    if (partiallyMentioned.length > 0 && partiallyMentioned.length < 3) {
        return `${baseQuestion} (You mentioned ${partiallyMentioned.slice(0, 2).join(', ')} — go deeper on constraints and non-obvious implications.)`;
    }
    return baseQuestion;
}
/**
 * Computes completion percentage based on how many dimensions are covered (0–100).
 */
export function computeCompletion(coverage) {
    const total = Object.keys(coverage).length;
    const covered = Object.values(coverage).filter(Boolean).length;
    return total === 0 ? 0 : Math.round((covered / total) * 100);
}
/**
 * Returns true if the topic is too simple for interview mode.
 * Delegates to isShortTopic from questions.ts.
 */
export function shouldSkipInterview(topic) {
    return isShortTopic(topic);
}
//# sourceMappingURL=interview-mode.js.map