File size: 1,493 Bytes
1dc8372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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]: <instruction>. 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 };