"use strict";
// vibe-confidence.ts — Vibe score engine (0-100 scale)
// Evolves confidence based on signal frequency and session count
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateVibe = calculateVibe;
exports.evolveVibe = evolveVibe;
exports.getVibeLevel = getVibeLevel;
exports.getVibeDescription = getVibeDescription;
exports.shouldShowInContext = shouldShowInContext;
exports.shouldWriteToFile = shouldWriteToFile;
exports.categoryVibeAverage = categoryVibeAverage;
exports.topVibeSignals = topVibeSignals;
exports.detectRisks = detectRisks;
function calculateVibe(signalCount, totalSessions, multiplier = 1.0) {
    if (signalCount === 0)
        return 0;
    // Base formula: rewards signal density and session consistency
    // Higher signal count per session = faster confidence growth
    const densityBonus = Math.min(Math.log10(Math.max(signalCount / Math.max(totalSessions, 1), 1)) * 20, 25);
    const logBonus = Math.log10(Math.max(signalCount, 1)) * 20;
    const sessionBonus = Math.min(Math.log10(Math.max(totalSessions, 1)) * 20, 25);
    const base = Math.min(95, Math.round(30 + logBonus + sessionBonus + densityBonus));
    return Math.min(100, Math.round(base * multiplier));
}
function evolveVibe(oldVibe, newEvidence, existingCount, totalSessions, multiplier = 1.0) {
    if (newEvidence) {
        const fresh = calculateVibe(existingCount + 1, totalSessions, multiplier);
        // Weighted blend: 70% new calculation, 30% old value (prevents jumps)
        return Math.min(100, Math.round(oldVibe * 0.3 + fresh * 0.7));
    }
    // No new evidence — slight decay (max 3 points) to keep stale patterns from staying high
    return Math.max(0, oldVibe - 1);
}
function getVibeLevel(vibe) {
    if (vibe >= 95)
        return 'certain';
    if (vibe >= 80)
        return 'very_strong';
    if (vibe >= 65)
        return 'strong';
    if (vibe >= 50)
        return 'learning';
    return 'uncertain';
}
function getVibeDescription(vibe) {
    if (vibe >= 95)
        return 'Identity-level — verified across many sessions';
    if (vibe >= 80)
        return 'Very strong pattern — reliable for context injection';
    if (vibe >= 65)
        return 'Strong pattern — consistently observed';
    if (vibe >= 50)
        return 'Emerging pattern — needs more sessions to confirm';
    return 'Uncertain — not enough data yet';
}
function shouldShowInContext(vibe) {
    return vibe >= 65; // Only show strong+ patterns in @cell context
}
function shouldWriteToFile(vibe) {
    return vibe >= 50; // Only write learning+ patterns to vibe.md
}
function categoryVibeAverage(signals) {
    if (signals.length === 0)
        return 0;
    const sum = signals.reduce((acc, s) => acc + s.vibe, 0);
    return Math.round(sum / signals.length);
}
function topVibeSignals(signals, limit = 5) {
    return [...signals]
        .sort((a, b) => b.vibe - a.vibe || b.count - a.count)
        .slice(0, limit);
}
// Combined risk assessment based on low-vibe signals that matter
function detectRisks(signals) {
    const risks = [];
    const riskSignals = {
        exploration_bias: { minVibe: 65, message: 'Exploration bias — starts more projects than finishes' },
        scope_creep: { minVibe: 60, message: 'Scope creep risk — task boundaries expand during work' },
        trust_low: { minVibe: 70, message: 'Low AI trust — spends extra time verifying everything' },
        commit_large: { minVibe: 55, message: 'Large commits — harder to review and roll back' },
        speed_over_quality: { minVibe: 65, message: 'Speed priority — may accumulate technical debt' },
    };
    for (const s of signals) {
        const risk = riskSignals[s.id];
        if (risk && s.vibe >= risk.minVibe) {
            risks.push(risk.message);
        }
    }
    return risks;
}
//# sourceMappingURL=vibe-confidence.js.map