FerrellSyntheticIntelligence commited on
Commit ·
fc2988c
1
Parent(s): fa6e2ea
[VITALIS] Advanced systems — Dream Mode, Resonance, Semantic Diff, Temporal Memory
Browse files- src/brain/resonance.py +49 -0
- src/brain/semantic_diff.py +45 -0
- src/hippocampus.py +94 -4
- src/ide_kernel/daemon.py +19 -24
- src/loop/dream.py +75 -0
- start.sh +32 -0
src/brain/resonance.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Resonance Engine.
|
| 3 |
+
Success strengthens weights. Failure weakens them.
|
| 4 |
+
The system learns from its own execution history.
|
| 5 |
+
No backpropagation. No gradient descent. Pure HDC resonance.
|
| 6 |
+
"""
|
| 7 |
+
import numpy as np
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
class ResonanceEngine:
|
| 11 |
+
LEARNING_RATE = 0.05
|
| 12 |
+
MAX_WEIGHT = 2.0
|
| 13 |
+
MIN_WEIGHT = 0.1
|
| 14 |
+
|
| 15 |
+
def __init__(self):
|
| 16 |
+
self.path = os.path.expanduser("~/.vitalis_workspace/resonance_weights.npy")
|
| 17 |
+
os.makedirs(os.path.dirname(self.path), exist_ok=True)
|
| 18 |
+
self.weights = np.load(self.path, allow_pickle=True).item() \
|
| 19 |
+
if os.path.exists(self.path) else {}
|
| 20 |
+
|
| 21 |
+
def _save(self):
|
| 22 |
+
np.save(self.path, self.weights)
|
| 23 |
+
|
| 24 |
+
def reinforce(self, pattern_key: str, success: bool):
|
| 25 |
+
w = self.weights.get(pattern_key, 1.0)
|
| 26 |
+
if success:
|
| 27 |
+
w = min(w * (1 + self.LEARNING_RATE), self.MAX_WEIGHT)
|
| 28 |
+
print(f"[RESONANCE] Strengthened: {pattern_key} → {w:.3f}")
|
| 29 |
+
else:
|
| 30 |
+
w = max(w * (1 - self.LEARNING_RATE), self.MIN_WEIGHT)
|
| 31 |
+
print(f"[RESONANCE] Weakened: {pattern_key} → {w:.3f}")
|
| 32 |
+
self.weights[pattern_key] = w
|
| 33 |
+
self._save()
|
| 34 |
+
|
| 35 |
+
def get_weight(self, pattern_key: str) -> float:
|
| 36 |
+
return self.weights.get(pattern_key, 1.0)
|
| 37 |
+
|
| 38 |
+
def top_patterns(self, n=10) -> list:
|
| 39 |
+
sorted_w = sorted(self.weights.items(), key=lambda x: x[1], reverse=True)
|
| 40 |
+
return sorted_w[:n]
|
| 41 |
+
|
| 42 |
+
def report(self) -> dict:
|
| 43 |
+
if not self.weights:
|
| 44 |
+
return {"status": "No patterns learned yet"}
|
| 45 |
+
return {
|
| 46 |
+
"total_patterns": len(self.weights),
|
| 47 |
+
"strongest": self.top_patterns(5),
|
| 48 |
+
"avg_weight": round(float(np.mean(list(self.weights.values()))), 3)
|
| 49 |
+
}
|
src/brain/semantic_diff.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Semantic Diff Engine.
|
| 3 |
+
Normal diff tells you WHAT changed.
|
| 4 |
+
This tells you WHAT IT MEANS that it changed.
|
| 5 |
+
"""
|
| 6 |
+
from vitalis_ide.math_core.kernel import VitalisKernel
|
| 7 |
+
|
| 8 |
+
class SemanticDiff:
|
| 9 |
+
DRIFT_THRESHOLD = 0.3
|
| 10 |
+
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self.kernel = VitalisKernel()
|
| 13 |
+
|
| 14 |
+
def diff(self, code_before: str, code_after: str) -> dict:
|
| 15 |
+
vec_before = self.kernel.vectorize_source(code_before)
|
| 16 |
+
vec_after = self.kernel.vectorize_source(code_after)
|
| 17 |
+
similarity = self.kernel.similarity(vec_before, vec_after)
|
| 18 |
+
drift = 1.0 - similarity
|
| 19 |
+
|
| 20 |
+
if drift < 0.05:
|
| 21 |
+
verdict = "TRIVIAL"
|
| 22 |
+
description = "Cosmetic change only. Logic unchanged."
|
| 23 |
+
elif drift < self.DRIFT_THRESHOLD:
|
| 24 |
+
verdict = "MINOR"
|
| 25 |
+
description = "Minor semantic shift. Core logic preserved."
|
| 26 |
+
elif drift < 0.6:
|
| 27 |
+
verdict = "SIGNIFICANT"
|
| 28 |
+
description = "Significant semantic drift. Logic has changed."
|
| 29 |
+
else:
|
| 30 |
+
verdict = "BREAKING"
|
| 31 |
+
description = "Near-complete semantic rewrite. Treat as new module."
|
| 32 |
+
|
| 33 |
+
return {
|
| 34 |
+
"similarity": round(similarity, 4),
|
| 35 |
+
"drift": round(drift, 4),
|
| 36 |
+
"verdict": verdict,
|
| 37 |
+
"description": description,
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
def diff_files(self, path_before: str, path_after: str) -> dict:
|
| 41 |
+
with open(path_before) as f: before = f.read()
|
| 42 |
+
with open(path_after) as f: after = f.read()
|
| 43 |
+
result = self.diff(before, after)
|
| 44 |
+
result["files"] = {"before": path_before, "after": path_after}
|
| 45 |
+
return result
|
src/hippocampus.py
CHANGED
|
@@ -1,21 +1,111 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import os
|
|
|
|
|
|
|
| 3 |
|
| 4 |
class Hippocampus:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def __init__(self, path=None):
|
| 6 |
self.path = path or os.path.expanduser("~/.vitalis_workspace/hippocampus.npy")
|
|
|
|
| 7 |
os.makedirs(os.path.dirname(self.path), exist_ok=True)
|
| 8 |
-
if os.path.exists(self.path)
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
else:
|
| 11 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def store(self, slot, vector):
|
|
|
|
| 14 |
self.memory[slot] = vector
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
np.save(self.path, self.memory)
|
|
|
|
| 16 |
|
| 17 |
def recall(self, slot):
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def all_slots(self):
|
| 21 |
return list(self.memory.keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import os
|
| 3 |
+
import json
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
class Hippocampus:
|
| 7 |
+
"""
|
| 8 |
+
Biologically-inspired vector memory.
|
| 9 |
+
Memories strengthen with use. Memories decay without use.
|
| 10 |
+
Based on Ebbinghaus forgetting curve.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
def __init__(self, path=None):
|
| 14 |
self.path = path or os.path.expanduser("~/.vitalis_workspace/hippocampus.npy")
|
| 15 |
+
self.meta_path = os.path.expanduser("~/.vitalis_workspace/hippocampus_meta.json")
|
| 16 |
os.makedirs(os.path.dirname(self.path), exist_ok=True)
|
| 17 |
+
self.memory = np.load(self.path, allow_pickle=True).item() if os.path.exists(self.path) else {}
|
| 18 |
+
self._load_meta()
|
| 19 |
+
|
| 20 |
+
def _load_meta(self):
|
| 21 |
+
if os.path.exists(self.meta_path):
|
| 22 |
+
with open(self.meta_path) as f:
|
| 23 |
+
self.meta = json.load(f)
|
| 24 |
else:
|
| 25 |
+
self.meta = {}
|
| 26 |
+
|
| 27 |
+
def _save_meta(self):
|
| 28 |
+
with open(self.meta_path, 'w') as f:
|
| 29 |
+
json.dump(self.meta, f, indent=2)
|
| 30 |
+
|
| 31 |
+
def _strength(self, slot) -> float:
|
| 32 |
+
"""Ebbinghaus forgetting curve: R = e^(-t/S)"""
|
| 33 |
+
if slot not in self.meta:
|
| 34 |
+
return 1.0
|
| 35 |
+
m = self.meta[slot]
|
| 36 |
+
t = (time.time() - m.get("last_access", time.time())) / 3600
|
| 37 |
+
S = m.get("stability", 24.0)
|
| 38 |
+
return float(np.exp(-t / S))
|
| 39 |
|
| 40 |
def store(self, slot, vector):
|
| 41 |
+
slot = str(slot)
|
| 42 |
self.memory[slot] = vector
|
| 43 |
+
now = time.time()
|
| 44 |
+
if slot not in self.meta:
|
| 45 |
+
self.meta[slot] = {"created": now, "access_count": 0, "stability": 24.0}
|
| 46 |
+
self.meta[slot]["last_access"] = now
|
| 47 |
np.save(self.path, self.memory)
|
| 48 |
+
self._save_meta()
|
| 49 |
|
| 50 |
def recall(self, slot):
|
| 51 |
+
slot = str(slot)
|
| 52 |
+
vec = self.memory.get(slot)
|
| 53 |
+
if vec is not None:
|
| 54 |
+
# Strengthen on recall — spaced repetition
|
| 55 |
+
if slot in self.meta:
|
| 56 |
+
self.meta[slot]["access_count"] = self.meta[slot].get("access_count", 0) + 1
|
| 57 |
+
self.meta[slot]["stability"] = min(
|
| 58 |
+
self.meta[slot].get("stability", 24.0) * 1.2, 720.0
|
| 59 |
+
)
|
| 60 |
+
self.meta[slot]["last_access"] = time.time()
|
| 61 |
+
self._save_meta()
|
| 62 |
+
return vec
|
| 63 |
+
|
| 64 |
+
def forget_weak(self, threshold=0.05):
|
| 65 |
+
"""Prune memories below strength threshold. Called during dream mode."""
|
| 66 |
+
pruned = []
|
| 67 |
+
for slot in list(self.memory.keys()):
|
| 68 |
+
if self._strength(slot) < threshold:
|
| 69 |
+
del self.memory[slot]
|
| 70 |
+
self.meta.pop(slot, None)
|
| 71 |
+
pruned.append(slot)
|
| 72 |
+
if pruned:
|
| 73 |
+
np.save(self.path, self.memory)
|
| 74 |
+
self._save_meta()
|
| 75 |
+
print(f"[HIPPOCAMPUS] Pruned {len(pruned)} weak memories.")
|
| 76 |
+
return pruned
|
| 77 |
|
| 78 |
def all_slots(self):
|
| 79 |
return list(self.memory.keys())
|
| 80 |
+
|
| 81 |
+
def memory_report(self) -> dict:
|
| 82 |
+
report = {}
|
| 83 |
+
for slot in self.memory:
|
| 84 |
+
report[slot] = {
|
| 85 |
+
"strength": round(self._strength(slot), 3),
|
| 86 |
+
"access_count": self.meta.get(slot, {}).get("access_count", 0),
|
| 87 |
+
"stability_hours": round(self.meta.get(slot, {}).get("stability", 24.0), 1)
|
| 88 |
+
}
|
| 89 |
+
return report
|
| 90 |
+
|
| 91 |
+
def similarity_search(self, query_vec, top_k=5):
|
| 92 |
+
qf = query_vec.astype(np.float32)
|
| 93 |
+
qn = np.linalg.norm(qf)
|
| 94 |
+
if qn == 0:
|
| 95 |
+
return []
|
| 96 |
+
results = []
|
| 97 |
+
for slot, vec in self.memory.items():
|
| 98 |
+
if vec is None:
|
| 99 |
+
continue
|
| 100 |
+
strength = self._strength(slot)
|
| 101 |
+
if strength < 0.01:
|
| 102 |
+
continue
|
| 103 |
+
vf = vec.astype(np.float32)
|
| 104 |
+
vn = np.linalg.norm(vf)
|
| 105 |
+
if vn == 0:
|
| 106 |
+
continue
|
| 107 |
+
# Similarity weighted by memory strength
|
| 108 |
+
sim = float(np.dot(qf, vf) / (qn * vn)) * strength
|
| 109 |
+
results.append((sim, slot))
|
| 110 |
+
results.sort(reverse=True)
|
| 111 |
+
return results[:top_k]
|
src/ide_kernel/daemon.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import os
|
| 3 |
-
import time
|
| 4 |
from src.ide_kernel.kernel import SovereignKernel
|
| 5 |
from src.ide_kernel.validator import KernelValidator
|
| 6 |
from src.ide_kernel.ledger import ProjectLedger
|
|
|
|
| 7 |
|
| 8 |
class KernelDaemon:
|
| 9 |
def __init__(self, workspace_path):
|
|
@@ -11,52 +10,48 @@ class KernelDaemon:
|
|
| 11 |
self.task_file = os.path.join(self.root, "workspace_tasks.json")
|
| 12 |
self.kernel = SovereignKernel(self.root)
|
| 13 |
self.ledger = ProjectLedger(self.root)
|
|
|
|
| 14 |
|
| 15 |
def handle_failure(self, task, output):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
"intent":
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
}
|
| 22 |
-
with open(failure_path, 'w') as f:
|
| 23 |
-
json.dump(failure_data, f)
|
| 24 |
-
print(f"[!] FAILURE LOGGED. Auto-Debug agent initialized: {failure_path}")
|
| 25 |
|
| 26 |
def start(self):
|
| 27 |
-
print("[+] FSI Kernel Daemon Active (Self-Healing Enabled).")
|
| 28 |
while True:
|
| 29 |
if os.path.exists(self.task_file):
|
| 30 |
with open(self.task_file, 'r') as f:
|
| 31 |
-
try:
|
| 32 |
-
task = json.load(f)
|
| 33 |
except json.JSONDecodeError:
|
| 34 |
print("[!] Error reading task file. Retrying...")
|
| 35 |
time.sleep(1)
|
| 36 |
continue
|
| 37 |
-
|
| 38 |
-
# 1. Execute
|
| 39 |
intent = task.get('intent')
|
| 40 |
try:
|
| 41 |
if intent == 'scaffold':
|
| 42 |
res = self.kernel.scaffold_module(task.get('module_name'))
|
| 43 |
else:
|
| 44 |
res = self.kernel.write_code(task.get('file'), task.get('code'))
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
target = self.root if intent == 'scaffold' else os.path.dirname(os.path.join(self.root, task.get('file', '')))
|
| 48 |
success, output = KernelValidator.run_tests(target)
|
| 49 |
-
|
| 50 |
-
# 3. Memory & Recovery
|
| 51 |
if success:
|
| 52 |
self.ledger.update_state(intent, "Completed")
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
else:
|
| 55 |
self.handle_failure(task, output)
|
| 56 |
self.ledger.update_state(intent, f"Failed: {output[:50]}...")
|
| 57 |
except Exception as e:
|
| 58 |
print(f"[CRITICAL ERROR] {e}")
|
| 59 |
-
|
| 60 |
os.remove(self.task_file)
|
| 61 |
time.sleep(1)
|
| 62 |
|
|
|
|
| 1 |
+
import json, os, time
|
|
|
|
|
|
|
| 2 |
from src.ide_kernel.kernel import SovereignKernel
|
| 3 |
from src.ide_kernel.validator import KernelValidator
|
| 4 |
from src.ide_kernel.ledger import ProjectLedger
|
| 5 |
+
from src.brain.resonance import ResonanceEngine
|
| 6 |
|
| 7 |
class KernelDaemon:
|
| 8 |
def __init__(self, workspace_path):
|
|
|
|
| 10 |
self.task_file = os.path.join(self.root, "workspace_tasks.json")
|
| 11 |
self.kernel = SovereignKernel(self.root)
|
| 12 |
self.ledger = ProjectLedger(self.root)
|
| 13 |
+
self.resonance = ResonanceEngine()
|
| 14 |
|
| 15 |
def handle_failure(self, task, output):
|
| 16 |
+
path = os.path.join(self.root, "failure_report.json")
|
| 17 |
+
with open(path, 'w') as f:
|
| 18 |
+
json.dump({"intent":"auto_debug","original_task":task,"error_log":output}, f)
|
| 19 |
+
self.resonance.reinforce(task.get('intent','unknown'), success=False)
|
| 20 |
+
print(f"[!] FAILURE LOGGED. Auto-Debug initialized: {path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def start(self):
|
| 23 |
+
print("[+] FSI Kernel Daemon Active (Self-Healing + Resonance Enabled).")
|
| 24 |
while True:
|
| 25 |
if os.path.exists(self.task_file):
|
| 26 |
with open(self.task_file, 'r') as f:
|
| 27 |
+
try: task = json.load(f)
|
|
|
|
| 28 |
except json.JSONDecodeError:
|
| 29 |
print("[!] Error reading task file. Retrying...")
|
| 30 |
time.sleep(1)
|
| 31 |
continue
|
|
|
|
|
|
|
| 32 |
intent = task.get('intent')
|
| 33 |
try:
|
| 34 |
if intent == 'scaffold':
|
| 35 |
res = self.kernel.scaffold_module(task.get('module_name'))
|
| 36 |
else:
|
| 37 |
res = self.kernel.write_code(task.get('file'), task.get('code'))
|
| 38 |
+
target = self.root if intent == 'scaffold' else os.path.dirname(
|
| 39 |
+
os.path.join(self.root, task.get('file', '')))
|
|
|
|
| 40 |
success, output = KernelValidator.run_tests(target)
|
|
|
|
|
|
|
| 41 |
if success:
|
| 42 |
self.ledger.update_state(intent, "Completed")
|
| 43 |
+
self.resonance.reinforce(intent, success=True)
|
| 44 |
+
try:
|
| 45 |
+
from src.brain.pattern_library import PatternLibrary
|
| 46 |
+
PatternLibrary().store(intent, task.get('code') or intent, task.get('file'))
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"[DAEMON] Pattern learning skipped: {e}")
|
| 49 |
+
print(f"[SUCCESS] Action: {intent}. Resonance reinforced.")
|
| 50 |
else:
|
| 51 |
self.handle_failure(task, output)
|
| 52 |
self.ledger.update_state(intent, f"Failed: {output[:50]}...")
|
| 53 |
except Exception as e:
|
| 54 |
print(f"[CRITICAL ERROR] {e}")
|
|
|
|
| 55 |
os.remove(self.task_file)
|
| 56 |
time.sleep(1)
|
| 57 |
|
src/loop/dream.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Dream Mode — Vitalis FSI Memory Consolidation Engine.
|
| 4 |
+
Runs during idle time. Strengthens important patterns.
|
| 5 |
+
Prunes weak memories. Merges similar vectors.
|
| 6 |
+
This is what makes the system get smarter without explicit training.
|
| 7 |
+
"""
|
| 8 |
+
import time
|
| 9 |
+
import os
|
| 10 |
+
import numpy as np
|
| 11 |
+
from src.hippocampus import Hippocampus
|
| 12 |
+
from vitalis_ide.math_core.kernel import VitalisKernel
|
| 13 |
+
|
| 14 |
+
IDLE_THRESHOLD = 30 # seconds of no tasks before dream starts
|
| 15 |
+
|
| 16 |
+
class DreamEngine:
|
| 17 |
+
def __init__(self):
|
| 18 |
+
self.hippocampus = Hippocampus()
|
| 19 |
+
self.kernel = VitalisKernel()
|
| 20 |
+
self.task_file = os.path.expanduser("~/vitalis_devcore/workspace_tasks.json")
|
| 21 |
+
self.dream_log = os.path.expanduser("~/.vitalis_workspace/dream_log.json")
|
| 22 |
+
self.cycles = 0
|
| 23 |
+
|
| 24 |
+
def _system_idle(self) -> bool:
|
| 25 |
+
if not os.path.exists(self.task_file):
|
| 26 |
+
return True
|
| 27 |
+
age = time.time() - os.path.getmtime(self.task_file)
|
| 28 |
+
return age > IDLE_THRESHOLD
|
| 29 |
+
|
| 30 |
+
def _consolidate(self):
|
| 31 |
+
"""Merge similar memory vectors to build stronger generalizations."""
|
| 32 |
+
slots = self.hippocampus.all_slots()
|
| 33 |
+
if len(slots) < 2:
|
| 34 |
+
return 0
|
| 35 |
+
merged = 0
|
| 36 |
+
checked = set()
|
| 37 |
+
for i, slot_a in enumerate(slots):
|
| 38 |
+
if slot_a in checked:
|
| 39 |
+
continue
|
| 40 |
+
vec_a = self.hippocampus.recall(slot_a)
|
| 41 |
+
if vec_a is None:
|
| 42 |
+
continue
|
| 43 |
+
for slot_b in slots[i+1:]:
|
| 44 |
+
if slot_b in checked:
|
| 45 |
+
continue
|
| 46 |
+
vec_b = self.hippocampus.recall(slot_b)
|
| 47 |
+
if vec_b is None:
|
| 48 |
+
continue
|
| 49 |
+
sim = self.kernel.similarity(vec_a, vec_b)
|
| 50 |
+
# Merge very similar memories into one stronger pattern
|
| 51 |
+
if sim > 0.92:
|
| 52 |
+
bundle = np.sign(
|
| 53 |
+
vec_a.astype(np.int32) + vec_b.astype(np.int32)
|
| 54 |
+
).astype(np.int8)
|
| 55 |
+
bundle[bundle == 0] = 1
|
| 56 |
+
self.hippocampus.store(slot_a, bundle)
|
| 57 |
+
checked.add(slot_b)
|
| 58 |
+
merged += 1
|
| 59 |
+
return merged
|
| 60 |
+
|
| 61 |
+
def run(self):
|
| 62 |
+
print("[DREAM] Memory consolidation engine online.")
|
| 63 |
+
while True:
|
| 64 |
+
if self._system_idle():
|
| 65 |
+
print(f"[DREAM] Cycle {self.cycles + 1} — consolidating...")
|
| 66 |
+
pruned = self.hippocampus.forget_weak(threshold=0.03)
|
| 67 |
+
merged = self._consolidate()
|
| 68 |
+
report = self.hippocampus.memory_report()
|
| 69 |
+
active = sum(1 for v in report.values() if v["strength"] > 0.5)
|
| 70 |
+
self.cycles += 1
|
| 71 |
+
print(f"[DREAM] Complete — Active:{active} Pruned:{len(pruned)} Merged:{merged}")
|
| 72 |
+
time.sleep(60)
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
DreamEngine().run()
|
start.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
ROOT="$HOME/vitalis_devcore"
|
| 3 |
+
SESSION="vitalis"
|
| 4 |
+
|
| 5 |
+
echo "╔══════════════════════════════════════════╗"
|
| 6 |
+
echo "║ VITALIS FSI — SOVEREIGN BOOT ║"
|
| 7 |
+
echo "║ Local. Private. Autonomous. ║"
|
| 8 |
+
echo "╚══════════════════════════════════════════╝"
|
| 9 |
+
|
| 10 |
+
if ! command -v tmux &>/dev/null; then
|
| 11 |
+
sudo apt-get install -y tmux -q
|
| 12 |
+
fi
|
| 13 |
+
|
| 14 |
+
tmux kill-session -t $SESSION 2>/dev/null
|
| 15 |
+
tmux new-session -d -s $SESSION -n daemon "cd $ROOT && python3 -m src.ide_kernel.daemon; bash"
|
| 16 |
+
tmux new-window -t $SESSION -n gateway "cd $ROOT && python3 -m flask --app src.ide_kernel.gateway run --port 5001; bash"
|
| 17 |
+
tmux new-window -t $SESSION -n healing "cd $ROOT && python3 -m src.loop.self_healing; bash"
|
| 18 |
+
tmux new-window -t $SESSION -n trainer "cd $ROOT && python3 -m src.loop.trainer; bash"
|
| 19 |
+
tmux new-window -t $SESSION -n dream "cd $ROOT && python3 -m src.loop.dream; bash"
|
| 20 |
+
tmux new-window -t $SESSION -n shell "cd $ROOT; bash"
|
| 21 |
+
|
| 22 |
+
echo ""
|
| 23 |
+
echo "[+] ALL SYSTEMS ONLINE"
|
| 24 |
+
echo "[+] Dashboard → http://localhost:5001"
|
| 25 |
+
echo "[+] Daemon → task execution + resonance learning"
|
| 26 |
+
echo "[+] Gateway → REST API"
|
| 27 |
+
echo "[+] Healer → failure recovery"
|
| 28 |
+
echo "[+] Trainer → pattern learning"
|
| 29 |
+
echo "[+] Dream → memory consolidation"
|
| 30 |
+
echo ""
|
| 31 |
+
sleep 2
|
| 32 |
+
tmux attach -t $SESSION
|