"use strict";
// vibe-intelligence.ts — Supreme identity layer
// Converts raw signals into accurate, personal, human-like insights
// Cross-signal correlation + contradiction resolution + natural language
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateCorrelatedInsights = generateCorrelatedInsights;
exports.generateTraitInsights = generateTraitInsights;
exports.generateIdentitySummary = generateIdentitySummary;
exports.generateAiGuide = generateAiGuide;
exports.rankInsights = rankInsights;
// Pairs of signals that MEAN SOMETHING when seen together
const CORRELATIONS = [
    // Direct + hinglish = aggressive communicator
    { signalA: 'tone_direct', signalB: 'language_hindi', strength: 'reinforce',
        identityHint: 'No-nonsense Hinglish communicator — direct, fast, no sugar-coating in mixed language.' },
    { signalA: 'tone_direct', signalB: 'correction_style', strength: 'reinforce',
        identityHint: 'Gives and expects brutally honest feedback — values truth over politeness.' },
    // Audit + patience = strategic thinker
    { signalA: 'audit_first', signalB: 'patience_level', strength: 'reinforce',
        identityHint: 'Strategic operator — invests time upfront to audit and understand before executing.' },
    { signalA: 'audit_first', signalB: 'architecture_question_depth', strength: 'reinforce',
        identityHint: 'Deep-dive auditor — doesn\'t just scan surface, asks "kyun" before "kaise."' },
    // Fast ship + minimal changes = pragmatic builder
    { signalA: 'ship_fast', signalB: 'changes_minimal', strength: 'reinforce',
        identityHint: 'Pragmatic shipper — values speed and small, safe changes. Ships at 80%, fixes at 100%.' },
    { signalA: 'ship_fast', signalB: 'simplicity_bias', strength: 'reinforce',
        identityHint: 'Moves fast by keeping things simple — complexity is the enemy of velocity.' },
    // Frustration + urgency = pressure cooker
    { signalA: 'frustration_signal', signalB: 'urgency_detection', strength: 'reinforce',
        identityHint: 'Pressure intensifies communication — frustration surfaces when deadlines loom.' },
    // Satisfaction + appreciation = positive collaborator
    { signalA: 'satisfaction_signal', signalB: 'appreciation_style', strength: 'reinforce',
        identityHint: 'Generous with praise — when output is right, genuinely acknowledges it.' },
    // Deep work + single session = flow state achiever
    { signalA: 'deep_work_detection', signalB: 'completion_discipline', strength: 'reinforce',
        identityHint: 'Flow state developer — enters deep focus, stays there, emerges with completed work.' },
    // Explore + completion low = idea explorer
    { signalA: 'exploration_bias', signalB: 'tech_curiosity', strength: 'reinforce',
        identityHint: 'Restless explorer — drawn to new ideas and tech, sometimes at the cost of finishing.' },
    // ROI + monetization = business builder
    { signalA: 'roi_first', signalB: 'monetization_thinking', strength: 'reinforce',
        identityHint: 'Revenue-minded builder — every technical decision passes through a business filter.' },
    // ROI + simplicity = lean operator
    { signalA: 'roi_first', signalB: 'simplicity_bias', strength: 'reinforce',
        identityHint: 'Lean operator — maximizes output with minimal complexity. Every line earns its keep.' },
    // Stick to known + stack loyalty = reliable veteran
    { signalA: 'stick_to_known', signalB: 'stack_loyalty', strength: 'reinforce',
        identityHint: 'Proven-tech advocate — trusts what works, adopts only after evidence.' },
    // Refactor bug-driven + error response fast = firefighter
    { signalA: 'refactoring_motivation', signalB: 'error_response_pattern', strength: 'reinforce',
        identityHint: 'Firefighter coder — jumps on bugs immediately, refactors only when fire forces it.' },
    // Thinking aloud + iterative = visible worker
    { signalA: 'thinking_aloud', signalB: 'iterative_prompter', strength: 'reinforce',
        identityHint: 'Visible thinker — externalizes thought process, iterates publicly through ideas.' },
    // Example seeking + deep architecture = thorough learner
    { signalA: 'example_request_style', signalB: 'architecture_question_depth', strength: 'reinforce',
        identityHint: 'Thorough learner — wants concrete examples AND deep explanations, not one or the other.' },
    // Ownership + solo dev = independent builder
    { signalA: 'ownership_language', signalB: 'solo_developer', strength: 'reinforce',
        identityHint: 'Independent builder — owns everything end-to-end, prefers full control.' },
    // Contradiction: fast ship + quality over speed = balanced
    { signalA: 'ship_fast', signalB: 'quality_over_speed', strength: 'contradict',
        identityHint: 'Context-dependent speed — ships fast when needed, polishes when time allows.' },
    // Hinglish + English both = true bilingual
    { signalA: 'language_hindi', signalB: 'language_english', strength: 'contradict',
        identityHint: 'True bilingual — code explanation flows between Hindi and English naturally.' },
    // Minimal changes + thorough rewrites = strategic scaler
    { signalA: 'changes_minimal', signalB: 'changes_thorough', strength: 'contradict',
        identityHint: 'Strategic scaler — knows when to patch and when to rebuild. Context determines approach.' },
];
function generateCorrelatedInsights(signals) {
    const insights = [];
    const sigMap = new Map(signals.filter(s => s.vibe >= 50).map(s => [s.id, s]));
    for (const corr of CORRELATIONS) {
        const a = sigMap.get(corr.signalA);
        const b = sigMap.get(corr.signalB);
        if (!a || !b)
            continue;
        if (corr.strength === 'reinforce' && a.vibe >= 50 && b.vibe >= 50) {
            const avgVibe = Math.round((a.vibe + b.vibe) / 2);
            if (avgVibe >= 55) {
                insights.push({
                    text: corr.identityHint,
                    confidence: avgVibe,
                    signals: [corr.signalA, corr.signalB],
                    type: 'identity',
                });
            }
        }
        if (corr.strength === 'contradict' && a.vibe >= 45 && b.vibe >= 45) {
            const avgVibe = Math.round((a.vibe + b.vibe) / 2);
            if (avgVibe >= 55) {
                insights.push({
                    text: corr.identityHint,
                    confidence: avgVibe,
                    signals: [corr.signalA, corr.signalB],
                    type: 'trait',
                });
            }
        }
    }
    return insights;
}
// Single-signal insights for powerful standalone signals
function generateTraitInsights(signals) {
    const insights = [];
    const strongSignalInsights = {
        frustration_signal: { minVibe: 60, text: 'Passionate communicator — frustration shows investment, not anger.', type: 'trait' },
        correction_style: { minVibe: 65, text: 'High standards — calls out mistakes immediately because quality matters personally.', type: 'trait' },
        simplicity_bias: { minVibe: 70, text: 'Simplicity-first mindset — believes the best code is the code that doesn\'t exist.', type: 'identity' },
        tech_curiosity: { minVibe: 65, text: 'Naturally curious — drawn to what\'s new and what could work better.', type: 'trait' },
        deep_work_detection: { minVibe: 65, text: 'Capable of deep, uninterrupted focus — produces quality work in intense sessions.', type: 'strength' },
        ownership_language: { minVibe: 65, text: 'Full-ownership mentality — takes personal responsibility for every line and decision.', type: 'identity' },
        thinking_aloud: { minVibe: 60, text: 'Transparent thinker — doesn\'t hide the reasoning process, thinks openly.', type: 'trait' },
        exploration_bias: { minVibe: 70, text: 'Restless creator — energized by new starts, sometimes struggles with finishing.', type: 'warning' },
        audit_first: { minVibe: 75, text: 'Methodical strategist — systematically audits before acting. Rare and valuable.', type: 'strength' },
    };
    for (const s of signals) {
        const insight = strongSignalInsights[s.id];
        if (insight && s.vibe >= insight.minVibe) {
            insights.push({
                text: insight.text,
                confidence: s.vibe,
                signals: [s.id],
                type: insight.type,
            });
        }
    }
    return insights;
}
// Generate "what this means" summary combining all insights
function generateIdentitySummary(signals, correlatedInsights) {
    const sigMap = new Map(signals.map(s => [s.id, s]));
    const parts = [];
    // 1. Communication identity
    const langHindi = sigMap.get('language_hindi');
    const langEnglish = sigMap.get('language_english');
    if (langHindi && langHindi.vibe >= 60 && langEnglish && langEnglish.vibe >= 60) {
        parts.push('Bilingual communicator — flows naturally between Hindi and English');
    }
    else if (langHindi && langHindi.vibe >= 60) {
        parts.push('Hinglish communicator — prefers Hindi explanations with English code');
    }
    const tone = sigMap.get('tone_direct');
    if (tone && tone.vibe >= 60) {
        parts.push('direct and no-nonsense');
    }
    const correction = sigMap.get('correction_style');
    if (correction && correction.vibe >= 55) {
        parts.push('gives brutally honest feedback');
    }
    const urgency = sigMap.get('urgency_detection');
    if (urgency && urgency.vibe >= 60) {
        parts.push('operates with urgency');
    }
    // 2. Work style
    const audit = sigMap.get('audit_first');
    const ship = sigMap.get('ship_fast');
    if (audit && audit.vibe >= 70) {
        parts.push('strategic auditor — analyzes before executing');
    }
    if (ship && ship.vibe >= 60) {
        parts.push('ships fast at 80%, polishes later');
    }
    if (audit && audit.vibe >= 70 && ship && ship.vibe >= 60) {
        parts.push('balanced execution style — strategic planning with fast delivery');
    }
    // 3. Code philosophy
    const changes = sigMap.get('changes_minimal');
    const simple = sigMap.get('simplicity_bias');
    if (changes && changes.vibe >= 65) {
        parts.push('prefers minimal surgical changes over large rewrites');
    }
    if (simple && simple.vibe >= 65) {
        parts.push('values simplicity over cleverness');
    }
    // 4. Decision driver
    const roi = sigMap.get('roi_first');
    const monetize = sigMap.get('monetization_thinking');
    if (roi && roi.vibe >= 60) {
        parts.push('decisions filtered through ROI');
    }
    if (monetize && monetize.vibe >= 55) {
        parts.push('business-aware technical thinking');
    }
    // Deduplicate and build
    const unique = [...new Set(parts.filter(p => p.length > 0))];
    if (unique.length === 0) {
        return 'Style still emerging — more sessions will reveal your unique developer DNA.';
    }
    // Build flowing sentence
    const keyTraits = unique.slice(0, 5);
    let summary = keyTraits.join('. ') + '.';
    // Add warning if relevant
    const exploreBias = sigMap.get('exploration_bias');
    if (exploreBias && exploreBias.vibe >= 65) {
        summary += ' Tends to start more than finish — high creative energy with execution risk.';
    }
    return summary;
}
// Generate "how to work with this developer" guide
function generateAiGuide(signals) {
    const sigMap = new Map(signals.map(s => [s.id, s]));
    const guides = [];
    const tone = sigMap.get('tone_direct');
    if (tone && tone.vibe >= 60) {
        guides.push('Be direct — no sugar-coating, no fluff, just the facts');
    }
    const lang = sigMap.get('language_hindi');
    if (lang && lang.vibe >= 60) {
        guides.push('Use Hinglish — Hindi explanations with English code');
    }
    const structure = sigMap.get('structure_bullets');
    if (structure && structure.vibe >= 55) {
        guides.push('Use bullet points — short, scannable, 3 lines max per bullet');
    }
    const changes = sigMap.get('changes_minimal');
    if (changes && changes.vibe >= 60) {
        guides.push('Keep changes minimal — under 50 lines, single file when possible');
    }
    const audit = sigMap.get('audit_first');
    if (audit && audit.vibe >= 65) {
        guides.push('Start with audit — show understanding before proposing solutions');
    }
    const frustration = sigMap.get('frustration_signal');
    const urgency = sigMap.get('urgency_detection');
    if (frustration && frustration.vibe >= 55 || urgency && urgency.vibe >= 60) {
        guides.push('Respect urgency — deliver fast when time pressure is visible');
    }
    const satisfaction = sigMap.get('satisfaction_signal');
    if (satisfaction && satisfaction.vibe >= 55) {
        guides.push('Celebrate wins — positive acknowledgment when output hits the mark');
    }
    const simple = sigMap.get('simplicity_bias');
    if (simple && simple.vibe >= 65) {
        guides.push('Default to simple — prefer the straightforward solution over the clever one');
    }
    const thinking = sigMap.get('thinking_aloud');
    if (thinking && thinking.vibe >= 55) {
        guides.push('Think openly — share reasoning process, not just final answer');
    }
    const roi = sigMap.get('roi_first');
    if (roi && roi.vibe >= 60) {
        guides.push('Connect to ROI — justify technical decisions with business impact');
    }
    if (guides.length === 0) {
        return 'Standard professional approach — clear, concise, respectful.';
    }
    return guides.map((g, i) => `${i + 1}. ${g}`).join('\n');
}
// Rank all insights by confidence and type priority
function rankInsights(insights) {
    return insights
        .filter(i => i.confidence >= 55)
        .sort((a, b) => {
        const typeOrder = { identity: 0, trait: 1, strength: 2, habit: 3, warning: 4 };
        const typeA = typeOrder[a.type] || 5;
        const typeB = typeOrder[b.type] || 5;
        if (typeA !== typeB)
            return typeA - typeB;
        return b.confidence - a.confidence;
    });
}
//# sourceMappingURL=vibe-intelligence.js.map