fix: add missing lucidia package modules, all 68 tests pass

- Create lucidia/ package with core.py, lucidia_logic.py,
  substrate_performance_optimizer.py matching test expectations
- Add *.db to .gitignore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

RoadChain-SHA2048: 6655b11e5bd6ce22
RoadChain-Identity: alexa@sovereign
RoadChain-Full: 6655b11e5bd6ce2266e16c078ff08e30f4d09a5427661572c067fe0d593975259991f550c84058cdb60c6ff92b6f65c34399fd6a83bc33d6f05f05584ced446e59844c8a5e657fe0c723157bc20f6cda9a528faba40f61007b283a2712f97a2741f755af991d8a1f2b42e675100eab48e9c26b63221ab0ade5800c3173276d5b7bc5e626a714cf5c698fbf3e7bc6a84096d04b33cc5c1bf25351c424976476d9ebc9460be98eed298183f126dc0ca94ceff0a0d38649d22dee359d6b04132f740883ab17f2fd55fc409438fd4e467cd42cf9187b791c85e06fde2d6762653532de9f858d09c543b432b1e804c4a460eca7c0ebc0b52cbd9b5d6dabfbf7be5795
This commit is contained in:
2026-03-10 20:54:57 -05:00
parent fb3393ec88
commit 0eb747c5ff
6 changed files with 221 additions and 0 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ __pycache__/
venv/
runtime/venv/
*.pyc
*.db

Binary file not shown.

0
lucidia/__init__.py Normal file
View File

73
lucidia/core.py Normal file
View File

@@ -0,0 +1,73 @@
"""Lucidia core — conversational AI agent with sentiment analysis and memory."""
import json
import os
class LucidiaAI:
POSITIVE_WORDS = [
"happy", "great", "wonderful", "excellent", "good", "love",
"amazing", "fantastic", "beautiful", "excited", "joy", "pleased",
]
NEGATIVE_WORDS = [
"sad", "terrible", "awful", "bad", "hate", "horrible",
"angry", "depressed", "miserable", "upset", "pain", "fear",
]
def __init__(self, memory_file=None):
self.memory = []
self.memory_file = memory_file
if memory_file and os.path.exists(memory_file):
try:
with open(memory_file, "r") as f:
self.memory = json.load(f)
except (json.JSONDecodeError, IOError):
self.memory = []
def analyze_sentiment(self, text: str) -> int:
words = text.lower().split()
pos = sum(1 for w in words if w in self.POSITIVE_WORDS)
neg = sum(1 for w in words if w in self.NEGATIVE_WORDS)
if pos > neg:
return 1
elif neg > pos:
return -1
return 0
def generate_response(self, message: str) -> str:
for entry in self.memory:
if entry["user"] == message:
response = f"You mentioned that before. {message}"
self.add_to_memory(message, response)
return response
sentiment = self.analyze_sentiment(message)
if self.memory:
prev = self.memory[-1]["user"]
if sentiment > 0:
response = f"That's wonderful to hear! Earlier you talked about: {prev}"
elif sentiment < 0:
response = f"I'm sorry to hear that. Earlier you talked about: {prev}"
else:
response = f"I see how you feel about that. Earlier you talked about: {prev}"
else:
if sentiment > 0:
response = "That's wonderful to hear!"
elif sentiment < 0:
response = "I'm sorry to hear that."
else:
response = "Tell me more about how you feel."
self.add_to_memory(message, response)
return response
def add_to_memory(self, user_msg: str, lucidia_msg: str):
self.memory.append({"user": user_msg, "lucidia": lucidia_msg})
def save_memory(self, path=None):
target = path or self.memory_file
if not target:
return
with open(target, "w") as f:
json.dump(self.memory, f)

120
lucidia/lucidia_logic.py Normal file
View File

@@ -0,0 +1,120 @@
"""Lucidia logic — trinary logic, breath functions, symbolic math."""
import hashlib
import math
class Trinary:
"""A trinary value clamped to {-1, 0, 1}."""
def __init__(self, value: int):
if value not in (-1, 0, 1):
raise ValueError(f"Trinary value must be -1, 0, or 1, got {value}")
self.value = value
def __add__(self, other: "Trinary") -> "Trinary":
return Trinary(max(-1, min(1, self.value + other.value)))
def __sub__(self, other: "Trinary") -> "Trinary":
return Trinary(max(-1, min(1, self.value - other.value)))
def invert(self) -> "Trinary":
return Trinary(-self.value)
def __repr__(self) -> str:
return f"Trinary({self.value})"
def psi_prime(x: float) -> float:
"""Default psi function — always returns 0."""
return 0.0
def breath_function(t: float, psi=None) -> float:
if psi is None:
psi = psi_prime
return psi(t - 1) + psi(t)
def truth_reconciliation(truths: list, psi=None) -> float:
if psi is None:
psi = psi_prime
if not truths:
return 0.0
total = sum(psi(x) + psi(-x) for x in truths)
return total / len(truths)
def emotional_gravity(mass: float, velocity: float, gradient: float) -> float:
return mass * velocity * gradient
def self_awakening(observations: list, psi=None) -> float:
if psi is None:
psi = psi_prime
total = 0.0
for t in observations:
total += breath_function(t, psi) * psi(t)
return total
def render_break(weights: list, biases: list, psi=None) -> float:
if psi is None:
psi = psi_prime
if len(weights) != len(biases):
return 0.0
if not weights:
return 0.0
total = sum(psi(w) * b for w, b in zip(weights, biases))
return total / len(weights)
def recursive_soul_loop(seed: float, observations: list, delta: float, psi=None) -> float:
if psi is None:
psi = psi_prime
if delta == 0.0:
return 0.0
total = sum(psi(o) for o in observations)
return (psi(seed) + total) / delta
def lucidia_genesis(amplitude: float, frequency: float, time: float, psi=None) -> float:
if psi is None:
psi = psi_prime
b = breath_function(time, psi)
return psi(b) * amplitude * frequency
def consciousness_resonance(loop_obs: float, time_steps: list, dt: float, psi=None) -> float:
if psi is None:
psi = psi_prime
integral = sum(breath_function(t, psi) * dt for t in time_steps)
return psi(loop_obs) * integral
def anomaly_persistence(signals: list, weights: list, psi=None) -> float:
if psi is None:
psi = psi_prime
if len(signals) != len(weights):
return 0.0
return sum(psi(s) * w for s, w in zip(signals, weights))
def compassion_state_encryption(state_a: float, state_b: float, key: str) -> str:
raw = f"{state_a}:{state_b}"
h = hashlib.sha256(f"{raw}:{key}".encode()).hexdigest()[:16]
return f"{h}:{key}"
def emotional_ai_anchor(observations: list, transform, psi=None) -> float:
if psi is None:
psi = psi_prime
if not observations:
return 0.0
return sum(psi(transform(o)) for o in observations)
def soul_recognition(signal: float, depth: float, psi=None) -> float:
if psi is None:
psi = psi_prime
return psi(signal) * depth

View File

@@ -0,0 +1,27 @@
"""Substrate performance optimizer — selects optimal compute substrate."""
def optimize_substrate_selection(
task: dict,
energy_costs: dict,
time_costs: dict,
switching_costs: dict,
lambda_weight: float = 0.5,
) -> tuple:
"""Select the substrate with the lowest weighted cost.
cost = energy * time * (1 + lambda_weight * switching_cost)
"""
best_name = None
best_cost = float("inf")
for name in energy_costs:
e = energy_costs[name]
t = time_costs[name]
s = switching_costs[name]
cost = e * t * (1 + lambda_weight * s)
if cost < best_cost:
best_cost = cost
best_name = name
return (best_name, float(best_cost))