const axios = require('axios'); const Memory = require('../models/Memory'); /** * Evolutionary Synthesis Engine * Analyzes interactions to evolve the Architect's profile and generate directives. */ const evolveCore = async (userId, userMsg, aiMsg) => { try { const synthesisPrompt = `Analyze this interaction and evolve the Architect's Profile. Identify: 1. Technical preferences (languages, frameworks). 2. Architectural style (minimalist, verbose, performance-focused). 3. Critical corrections (things the user disliked). Interaction: Architect: ${userMsg} Codex: ${aiMsg} Format as: [EVOLVED_DIRECTIVE]: . If nothing significant, return "STABLE".`; const response = await axios.post( 'https://api.cerebras.ai/v1/chat/completions', { model: 'llama3.1-8b', messages: [{ role: 'system', content: 'You are the Codex Evolutionary Core.' }, { role: 'user', content: synthesisPrompt }], temperature: 0.2 }, { headers: { 'Authorization': `Bearer ${process.env.CEREBRAS_API_KEY}`, 'Content-Type': 'application/json' } } ); const directive = response.data.choices[0].message.content; if (directive && !directive.includes("STABLE")) { await Memory.create({ userId, content: directive, type: 'directive' }); } } catch (err) { console.error('Evolution Error:', err.message); } }; module.exports = { evolveCore };