/**
 * Nexus Prime — Learning Compiler
 *
 * Compiles verified runs, rejected runs, repeated patterns, and contradictions
 * into actionable proposals: skill, workflow, warning rule, file-prior, topology hint.
 */
/**
 * Compile learning inputs into actionable proposals.
 */
export function compileLearnings(input) {
    const proposals = [];
    // Skill proposals from repeated successful patterns
    for (const pattern of input.repeatedPatterns) {
        if (pattern.count >= 3) {
            proposals.push({
                type: 'skill',
                name: `auto-skill-${pattern.pattern.slice(0, 30).replace(/\s+/g, '-')}`,
                description: `Repeated pattern detected: "${pattern.pattern}" (${pattern.count} occurrences)`,
                evidence: [`${pattern.count} repetitions in verified runs`],
                confidence: Math.min(0.9, 0.5 + pattern.count * 0.1),
            });
        }
    }
    // Warning rule proposals from contradictions
    for (const [topic, count] of input.contradictionCounts) {
        if (count >= 2) {
            proposals.push({
                type: 'warning_rule',
                name: `warn-${topic.slice(0, 30).replace(/\s+/g, '-')}`,
                description: `Contradictions detected in "${topic}" (${count} occurrences)`,
                evidence: [`${count} contradictions across runs`],
                confidence: Math.min(0.8, 0.4 + count * 0.1),
            });
        }
    }
    // Topology hint from apply success rate
    const successRate = input.applySuccessHistory.length > 0
        ? input.applySuccessHistory.filter(h => h.success).length / input.applySuccessHistory.length
        : 0;
    if (input.applySuccessHistory.length >= 5 && successRate < 0.5) {
        proposals.push({
            type: 'topology_hint',
            name: 'reduce-parallelism',
            description: `Low apply success rate (${Math.round(successRate * 100)}%). Consider reducing worker count.`,
            evidence: [`${input.applySuccessHistory.length} runs, ${Math.round(successRate * 100)}% success`],
            confidence: 0.7,
        });
    }
    return proposals.sort((a, b) => b.confidence - a.confidence);
}
