File size: 3,486 Bytes
f568a4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**

 * Intent Compiler

 * ---------------

 * Symbolic compiler that translates human intent to harmonic frequencies

 * Based on the symbolic_compiler_layer.json structure

 */

export interface IntentResult {
  frequencies: number[];
  decay?: number;
  harmonics?: number[];
  emotion?: string;
}

// Emotional frequency mappings (Hz)
const EMOTION_FREQUENCIES: Record<string, number[]> = {
  peace: [7.83, 136.1, 256], // Schumann + OM + C
  joy: [528, 741, 852], // Solfeggio frequencies
  love: [528, 693.3, 1111], // Love frequency + harmonics
  healing: [174, 285, 396, 417], // Lower solfeggio
  transformation: [741, 852, 963], // Higher solfeggio
  grounding: [7.83, 14.3, 20.8], // Pure Schumann
  clarity: [40, 80, 160], // Gamma + harmonics
  compassion: [341.3, 528, 852], // Heart chakra based
  courage: [456.8, 741, 963], // Solar plexus + higher
  wisdom: [426.7, 639, 852] // Throat + heart + third eye
};

// Intent keywords to emotion mapping
const INTENT_KEYWORDS: Record<string, string> = {
  'peace': 'peace',
  'calm': 'peace',
  'serenity': 'peace',
  'joy': 'joy',
  'happiness': 'joy',
  'bliss': 'joy',
  'love': 'love',
  'compassion': 'compassion',
  'kindness': 'compassion',
  'heal': 'healing',
  'healing': 'healing',
  'restore': 'healing',
  'transform': 'transformation',
  'change': 'transformation',
  'evolve': 'transformation',
  'ground': 'grounding',
  'center': 'grounding',
  'focus': 'clarity',
  'clarity': 'clarity',
  'clear': 'clarity',
  'courage': 'courage',
  'strength': 'courage',
  'brave': 'courage',
  'wisdom': 'wisdom',
  'insight': 'wisdom',
  'understand': 'wisdom'
};

export class IntentCompiler {
  /**

   * Process human intent text into harmonic frequencies

   */
  async processIntent(text: string): Promise<IntentResult> {
    const words = text.toLowerCase().split(/\s+/);
    const emotions = new Set<string>();
    
    // Extract emotions from intent text
    words.forEach(word => {
      const emotion = INTENT_KEYWORDS[word];
      if (emotion) {
        emotions.add(emotion);
      }
    });

    // If no specific emotions found, default to peace/grounding
    if (emotions.size === 0) {
      emotions.add('peace');
      emotions.add('grounding');
    }

    // Combine frequencies from all detected emotions
    const allFreqs = Array.from(emotions).flatMap(emotion => 
      EMOTION_FREQUENCIES[emotion] || []
    );

    // Remove duplicates and sort
    const uniqueFreqs = [...new Set(allFreqs)].sort((a, b) => a - b);

    // Generate harmonics for fundamental frequencies
    const harmonics = uniqueFreqs.flatMap(freq => [
      freq * 2,    // Octave
      freq * 3,    // Perfect fifth
      freq * 4,    // Double octave
      freq * 1.5   // Perfect fifth below octave
    ]).filter(f => f < 2000); // Keep within reasonable range

    return {
      frequencies: uniqueFreqs,
      harmonics,
      decay: 0.8, // Default decay rate
      emotion: Array.from(emotions).join(', ')
    };
  }

  /**

   * Get frequency for specific emotion

   */
  getEmotionFrequencies(emotion: string): number[] {
    return EMOTION_FREQUENCIES[emotion.toLowerCase()] || [];
  }

  /**

   * List available emotions

   */
  getAvailableEmotions(): string[] {
    return Object.keys(EMOTION_FREQUENCIES);
  }
}

// Export singleton instance
export const intentCompiler = new IntentCompiler();