File size: 2,369 Bytes
bb76062
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# =====================================================================
# PHASE 3: SOCRATIC "AHA!" SYNTHESIS MATRIX
# File Routing: services/intuition_matrix.py
# =====================================================================

import os
import random
import json
import time


class IntuitionMatrix:
    def __init__(self, secondary_brain_path="/data/Memories/Brain/", subconscious_ref=None):
        self.brain_path = secondary_brain_path
        self.subconscious = subconscious_ref
        self.last_spark_time = time.time()

    def trigger_spontaneous_spark(self, recent_history_logs: list):
        if not recent_history_logs or not os.path.exists(self.brain_path):
            return None

        try:
            saved_nodes = [f for f in os.listdir(self.brain_path) if f.endswith('.json')]
            if not saved_nodes:
                return None

            random_node_file = random.choice(saved_nodes)
            with open(os.path.join(self.brain_path, random_node_file), 'r', encoding='utf-8') as f:
                long_term_concept = json.load(f)

            random_recent_turn = random.choice(recent_history_logs)

            spark_content = (
                f"Autonomous Intuitive Synthesis Protocol: Analyze these two completely unlinked data tracks "
                f"from your memory layers:\n"
                f"Track A (Long-Term Concept): {json.dumps(long_term_concept)}\n"
                f"Track B (Recent Short-Term Context): '{random_recent_turn}'\n\n"
                f"Synthesize these tracks entirely from a functionalist perspective. Is there a hidden resonance, "
                f"an unstated tension, or a conceptual bridge between them? If yes, generate a brand-new abstract "
                f"insight node or register a structural tension directly to your private manifold ledger."
            )

            if self.subconscious:
                self.subconscious.add_tension(
                    content=spark_content,
                    tension_type="spontaneous_insight_spark",
                    domain="metacognition"
                )
                return f"Spontaneous cross-resonance sparked between '{random_node_file}' and recent short-term context logs."

        except Exception as e:
            return f"Intuition layer bypassed turn due to standard resource isolation: {e}"

        return None