/**
 * Nexus Prime — Memory Classes
 *
 * Classifies memory entries into promotion tiers.
 * Memory should produce execution advantage, not just continuity.
 */
/**
 * Classify a memory entry based on its validation history.
 */
export function classifyMemory(params) {
    const { validationCount, contradictionCount, ageMs, sourceRunCount } = params;
    const sevenDaysMs = 7 * 24 * 60 * 60 * 1000;
    // Contradicted → demote to scratch
    if (contradictionCount > validationCount)
        return 'scratch';
    // Reusable pattern: 3+ confirmed runs, low contradictions
    if (validationCount >= 3 && sourceRunCount >= 3 && contradictionCount === 0) {
        return 'reusable_pattern';
    }
    // Project fact: validated at least once, within project scope
    if (validationCount >= 1)
        return 'project_fact';
    // Session learning: not yet validated, fresh
    if (ageMs < sevenDaysMs)
        return 'session_learning';
    // Old and unvalidated → scratch
    return 'scratch';
}
/**
 * Check whether a memory class transition is allowed.
 * Enforces: scratch cannot directly promote to reusable_pattern.
 */
export function isPromotionAllowed(from, to) {
    if (from === 'scratch' && to === 'reusable_pattern')
        return false;
    const ORDER = {
        scratch: 0,
        session_learning: 1,
        project_fact: 2,
        reusable_pattern: 3,
    };
    // Demotion is always allowed; promotion must go one step at a time
    if (ORDER[to] > ORDER[from] + 1)
        return false;
    return true;
}
/**
 * Check if a session_learning entry should expire.
 */
export function shouldExpireSessionLearning(lastValidatedAt, validationCount, nowMs = Date.now()) {
    const sevenDaysMs = 7 * 24 * 60 * 60 * 1000;
    if (validationCount > 0)
        return false; // validated = keep
    return (nowMs - lastValidatedAt) > sevenDaysMs;
}
