Delete bone_main.py
Browse files- bone_main.py +0 -685
bone_main.py
DELETED
|
@@ -1,685 +0,0 @@
|
|
| 1 |
-
""" bone_main.py"""
|
| 2 |
-
|
| 3 |
-
import os, time, json, uuid, random, traceback, sys, re
|
| 4 |
-
from dataclasses import dataclass
|
| 5 |
-
from typing import Dict, Any, Optional, Tuple
|
| 6 |
-
|
| 7 |
-
from bone_commands import CommandProcessor
|
| 8 |
-
from bone_core import EventBus, SystemHealth, TheObserver, LoreManifest, TelemetryService, RealityStack
|
| 9 |
-
from bone_types import Prisma, RealityLayer
|
| 10 |
-
from bone_config import BoneConfig, BonePresets
|
| 11 |
-
from bone_genesis import BoneGenesis
|
| 12 |
-
from bone_lexicon import LexiconService
|
| 13 |
-
from bone_physics import CosmicDynamics, ZoneInertia
|
| 14 |
-
from bone_protocols import ChronosKeeper
|
| 15 |
-
from bone_body import SomaticLoop
|
| 16 |
-
from bone_brain import TheCortex, LLMInterface, NoeticLoop
|
| 17 |
-
from bone_cycle import GeodesicOrchestrator
|
| 18 |
-
from bone_council import CouncilChamber
|
| 19 |
-
|
| 20 |
-
ANSI_SPLIT = re.compile(r"(\x1b\[[0-9;]*m)")
|
| 21 |
-
|
| 22 |
-
def typewriter(text: str, speed: float = 0.00025, end: str = "\n"):
|
| 23 |
-
if speed < 0.001:
|
| 24 |
-
print(text, end=end)
|
| 25 |
-
return
|
| 26 |
-
type_parts = ANSI_SPLIT.split(text)
|
| 27 |
-
for part in type_parts:
|
| 28 |
-
if not part:
|
| 29 |
-
continue
|
| 30 |
-
if part.startswith("\x1b"):
|
| 31 |
-
sys.stdout.write(part)
|
| 32 |
-
else:
|
| 33 |
-
for char in part:
|
| 34 |
-
sys.stdout.write(char)
|
| 35 |
-
sys.stdout.flush()
|
| 36 |
-
time.sleep(speed)
|
| 37 |
-
sys.stdout.write(end)
|
| 38 |
-
sys.stdout.flush()
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
@dataclass
|
| 42 |
-
class HostStats:
|
| 43 |
-
latency: float
|
| 44 |
-
efficiency_index: float
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
class SessionGuardian:
|
| 48 |
-
def __init__(self, engine_ref):
|
| 49 |
-
self.engine_instance = engine_ref
|
| 50 |
-
|
| 51 |
-
def __enter__(self):
|
| 52 |
-
os.system("cls" if os.name == "nt" else "clear")
|
| 53 |
-
print(f"{Prisma.paint('┌──────────────────────────────────────────┐', 'M')}")
|
| 54 |
-
print(f"{Prisma.paint('│ BONEAMANITA TERMINAL // VERSION 15.8.0 │', 'M')}")
|
| 55 |
-
print(f"{Prisma.paint('└──────────────────────────────────────────┘', 'M')}")
|
| 56 |
-
boot_logs = self.engine_instance.events.flush()
|
| 57 |
-
for log in boot_logs:
|
| 58 |
-
print(f"{Prisma.GRY} >>> {log['text']}{Prisma.RST}")
|
| 59 |
-
time.sleep(0.05)
|
| 60 |
-
typewriter(
|
| 61 |
-
f"{Prisma.GRY}...Initializing KernelHash: {self.engine_instance.kernel_hash}...{Prisma.RST}"
|
| 62 |
-
)
|
| 63 |
-
typewriter(f"{Prisma.paint('>>> SYSTEM: LISTENING', 'G')}")
|
| 64 |
-
return self.engine_instance
|
| 65 |
-
|
| 66 |
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 67 |
-
print(f"\n{Prisma.paint('--- SYSTEM HALT ---', 'R')}")
|
| 68 |
-
if self.engine_instance:
|
| 69 |
-
self.engine_instance.shutdown()
|
| 70 |
-
|
| 71 |
-
if exc_type:
|
| 72 |
-
is_interrupt = issubclass(exc_type, KeyboardInterrupt)
|
| 73 |
-
if not is_interrupt:
|
| 74 |
-
print(f"{Prisma.RED}CRASH: {exc_val}{Prisma.RST}")
|
| 75 |
-
if getattr(self.engine_instance, "boot_mode", "") == "TECHNICAL":
|
| 76 |
-
full_trace = "".join(
|
| 77 |
-
traceback.format_exception(exc_type, exc_val, exc_tb)
|
| 78 |
-
)
|
| 79 |
-
print(f"{Prisma.GRY}{full_trace}{Prisma.RST}")
|
| 80 |
-
else:
|
| 81 |
-
print(
|
| 82 |
-
f"{Prisma.GRY}The reality lattice collapsed. Check the developer logs.{Prisma.RST}"
|
| 83 |
-
)
|
| 84 |
-
print(f"{Prisma.paint('Connection Severed.')}")
|
| 85 |
-
return exc_type is KeyboardInterrupt
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
class ConfigWizard:
|
| 89 |
-
CONFIG_FILE = "bone_config.json"
|
| 90 |
-
|
| 91 |
-
@staticmethod
|
| 92 |
-
def load_or_create():
|
| 93 |
-
if os.path.exists(ConfigWizard.CONFIG_FILE):
|
| 94 |
-
try:
|
| 95 |
-
with open(ConfigWizard.CONFIG_FILE, encoding="utf-8") as f:
|
| 96 |
-
return json.load(f)
|
| 97 |
-
except Exception as e:
|
| 98 |
-
print(f"{Prisma.RED}[CONFIG]: Load Error: {e}{Prisma.RST}")
|
| 99 |
-
ConfigWizard._backup_corrupt_file()
|
| 100 |
-
return ConfigWizard._run_setup()
|
| 101 |
-
|
| 102 |
-
@staticmethod
|
| 103 |
-
def _backup_corrupt_file():
|
| 104 |
-
backup_name = f"{ConfigWizard.CONFIG_FILE}.{int(time.time())}.bak"
|
| 105 |
-
try:
|
| 106 |
-
os.rename(ConfigWizard.CONFIG_FILE, backup_name)
|
| 107 |
-
print(
|
| 108 |
-
f"{Prisma.YEL} >>> Corrupt Config backed up to: {backup_name}{Prisma.RST}"
|
| 109 |
-
)
|
| 110 |
-
except:
|
| 111 |
-
pass
|
| 112 |
-
|
| 113 |
-
@staticmethod
|
| 114 |
-
def _run_setup():
|
| 115 |
-
os.system("cls" if os.name == "nt" else "clear")
|
| 116 |
-
print(f"{Prisma.paint('/// SYSTEM INITIALIZATION SEQUENCE ///', 'C')}")
|
| 117 |
-
typewriter(
|
| 118 |
-
"No configuration detected. Initiating manual override...", speed=0.02
|
| 119 |
-
)
|
| 120 |
-
print(f"\n{Prisma.paint('[STEP 1]: IDENTITY', 'W')}")
|
| 121 |
-
user_name = (
|
| 122 |
-
input(
|
| 123 |
-
f"{Prisma.GRY}Identify yourself (Default: TRAVELER): {Prisma.RST}"
|
| 124 |
-
).strip()
|
| 125 |
-
or "TRAVELER"
|
| 126 |
-
)
|
| 127 |
-
print(f"\n{Prisma.paint('[STEP 2]: REALITY MODE', 'W')}")
|
| 128 |
-
modes = [
|
| 129 |
-
("1", "Adventure", "Survival, Inventory, Map", "G"),
|
| 130 |
-
("2", "Conversation", "Pure Dialogue, No Mechanics", "C"),
|
| 131 |
-
("3", "Creative", "High Voltage, Hallucination", "V"),
|
| 132 |
-
("4", "Technical", "Debug, Raw Data", "0"),
|
| 133 |
-
]
|
| 134 |
-
for k, name, desc, col in modes:
|
| 135 |
-
print(f"{k}. {Prisma.paint(name, col)} - [{desc}]")
|
| 136 |
-
mode_choice = input(f"{Prisma.paint('>', 'C')} ").strip()
|
| 137 |
-
mode_map = {
|
| 138 |
-
"1": "ADVENTURE",
|
| 139 |
-
"2": "CONVERSATION",
|
| 140 |
-
"3": "CREATIVE",
|
| 141 |
-
"4": "TECHNICAL",
|
| 142 |
-
}
|
| 143 |
-
boot_mode = mode_map.get(mode_choice, "ADVENTURE")
|
| 144 |
-
print(f"\n{Prisma.paint('[STEP 3]: CORTEX BACKEND', 'W')}")
|
| 145 |
-
backends = [
|
| 146 |
-
("1", "Ollama (Local)", "G"),
|
| 147 |
-
("2", "OpenAI (Cloud)", "C"),
|
| 148 |
-
("3", "LM Studio (Local)", "V"),
|
| 149 |
-
("4", "Mock (Simulation)", "0"),
|
| 150 |
-
]
|
| 151 |
-
for k, name, col in backends:
|
| 152 |
-
print(f"{k}. {Prisma.paint(name, col)}")
|
| 153 |
-
choice = input(f"{Prisma.paint('>', 'C')} ").strip()
|
| 154 |
-
config = {"user_name": user_name, "boot_mode": boot_mode}
|
| 155 |
-
if choice == "2":
|
| 156 |
-
config.update(
|
| 157 |
-
{
|
| 158 |
-
"provider": "openai",
|
| 159 |
-
"base_url": "https://api.openai.com/v1/chat/completions",
|
| 160 |
-
}
|
| 161 |
-
)
|
| 162 |
-
config["model"] = input(f"Model ID [gpt-4]: ").strip() or "gpt-4"
|
| 163 |
-
config["api_key"] = input(f"{Prisma.paint('Enter API Key:', 'R')} ").strip()
|
| 164 |
-
elif choice == "3":
|
| 165 |
-
config.update(
|
| 166 |
-
{
|
| 167 |
-
"provider": "lm_studio",
|
| 168 |
-
"base_url": "http://127.0.0.1:1234/v1/chat/completions",
|
| 169 |
-
"model": "local-model",
|
| 170 |
-
}
|
| 171 |
-
)
|
| 172 |
-
elif choice == "4":
|
| 173 |
-
config.update({"provider": "mock", "model": "simulation"})
|
| 174 |
-
else:
|
| 175 |
-
config.update(
|
| 176 |
-
{
|
| 177 |
-
"provider": "ollama",
|
| 178 |
-
"base_url": "http://127.0.0.1:11434/v1/chat/completions",
|
| 179 |
-
}
|
| 180 |
-
)
|
| 181 |
-
config["model"] = input(f"Model ID [llama3]: ").strip() or "llama3"
|
| 182 |
-
|
| 183 |
-
try:
|
| 184 |
-
with open(ConfigWizard.CONFIG_FILE, "w") as f:
|
| 185 |
-
json.dump(config, f, indent=4)
|
| 186 |
-
typewriter(
|
| 187 |
-
f"\n{Prisma.paint('✔ CONFIGURATION COMMITTED.', 'G')}", speed=0.02
|
| 188 |
-
)
|
| 189 |
-
time.sleep(1)
|
| 190 |
-
except Exception as e:
|
| 191 |
-
print(f"{Prisma.paint(f'Write Failed: {e}', 'R')}")
|
| 192 |
-
sys.exit(1)
|
| 193 |
-
return config
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
class BoneAmanita:
|
| 197 |
-
events: EventBus
|
| 198 |
-
|
| 199 |
-
def __init__(self, config: Dict[str, Any]):
|
| 200 |
-
self.config = config
|
| 201 |
-
self.events = EventBus()
|
| 202 |
-
self.kernel_hash = str(uuid.uuid4())[:8].upper()
|
| 203 |
-
self.cmd = CommandProcessor(self, Prisma, config_ref=BoneConfig)
|
| 204 |
-
self.user_name = config.get("user_name", "TRAVELER")
|
| 205 |
-
self.boot_mode = config.get("boot_mode", "ADVENTURE").upper()
|
| 206 |
-
if self.boot_mode not in BonePresets.MODES:
|
| 207 |
-
self.boot_mode = "ADVENTURE"
|
| 208 |
-
self.mode_settings = BonePresets.MODES[self.boot_mode]
|
| 209 |
-
self.suppressed_agents = self.mode_settings.get("village_suppression", [])
|
| 210 |
-
self.config["mode_settings"] = self.mode_settings
|
| 211 |
-
self.health = BoneConfig.MAX_HEALTH
|
| 212 |
-
self.stamina = BoneConfig.MAX_STAMINA
|
| 213 |
-
self.trauma_accum = {}
|
| 214 |
-
self.tick_count = 0
|
| 215 |
-
self.events.log("...Bootstrapping Core...", "BOOT")
|
| 216 |
-
self.chronos = ChronosKeeper(self)
|
| 217 |
-
self.lex = LexiconService
|
| 218 |
-
self.lex.initialize()
|
| 219 |
-
anatomy = BoneGenesis.ignite(self.config, self.lex, events_ref=self.events)
|
| 220 |
-
self._unpack_anatomy(anatomy)
|
| 221 |
-
self.events.subscribe("ITEM_DROP", self.town_hall.on_item_drop)
|
| 222 |
-
if self.phys:
|
| 223 |
-
self.phys.dynamics = CosmicDynamics()
|
| 224 |
-
self.cosmic = self.phys.dynamics
|
| 225 |
-
self.stabilizer = ZoneInertia()
|
| 226 |
-
self.telemetry = TelemetryService.get_instance()
|
| 227 |
-
self.system_health = SystemHealth()
|
| 228 |
-
self.observer = TheObserver()
|
| 229 |
-
self.system_health.link_observer(self.observer)
|
| 230 |
-
self.reality_stack = RealityStack()
|
| 231 |
-
self._load_system_prompts()
|
| 232 |
-
self._initialize_cognition()
|
| 233 |
-
self.host_stats = HostStats(latency=0.0, efficiency_index=1.0)
|
| 234 |
-
self._validate_state()
|
| 235 |
-
self._apply_boot_mode()
|
| 236 |
-
|
| 237 |
-
def _load_system_prompts(self):
|
| 238 |
-
try:
|
| 239 |
-
paths = ["lore/system_prompts.json", "dev/lore/system_prompts.json"]
|
| 240 |
-
loaded = False
|
| 241 |
-
for p in paths:
|
| 242 |
-
if os.path.exists(p):
|
| 243 |
-
with open(p, encoding="utf-8") as f:
|
| 244 |
-
self.prompt_library = json.load(f)
|
| 245 |
-
print(
|
| 246 |
-
f"{Prisma.GRY}...Prompt Library Loaded from {p}...{Prisma.RST}"
|
| 247 |
-
)
|
| 248 |
-
loaded = True
|
| 249 |
-
break
|
| 250 |
-
if not loaded:
|
| 251 |
-
print(
|
| 252 |
-
f"{Prisma.YEL}WARNING: system_prompts.json not found. Using defaults.{Prisma.RST}"
|
| 253 |
-
)
|
| 254 |
-
self.prompt_library = {}
|
| 255 |
-
except Exception as e:
|
| 256 |
-
print(f"{Prisma.RED}CRITICAL: Could not load prompts: {e}{Prisma.RST}")
|
| 257 |
-
self.prompt_library = {}
|
| 258 |
-
|
| 259 |
-
def _initialize_cognition(self):
|
| 260 |
-
self.soma = SomaticLoop(self.bio, self.mind.mem, self.lex, self.events)
|
| 261 |
-
self.noetic = NoeticLoop(self.mind, self.bio, self.events)
|
| 262 |
-
self.cycle_controller = GeodesicOrchestrator(self)
|
| 263 |
-
llm_args = {
|
| 264 |
-
k: v
|
| 265 |
-
for k, v in self.config.items()
|
| 266 |
-
if k in ["provider", "base_url", "api_key", "model"]
|
| 267 |
-
}
|
| 268 |
-
client = LLMInterface(events_ref=self.events, **llm_args)
|
| 269 |
-
self.cortex = TheCortex.from_engine(self, llm_client=client)
|
| 270 |
-
|
| 271 |
-
def _validate_state(self):
|
| 272 |
-
tuning_key = self.mode_settings.get("tuning", "STANDARD")
|
| 273 |
-
if hasattr(BonePresets, tuning_key):
|
| 274 |
-
BoneConfig.load_preset(getattr(BonePresets, tuning_key))
|
| 275 |
-
if getattr(self.mind.mem, "session_health", None) is not None:
|
| 276 |
-
self.health = self.mind.mem.session_health
|
| 277 |
-
self.stamina = self.mind.mem.session_stamina
|
| 278 |
-
self.trauma_accum = self.mind.mem.session_trauma_vector or {}
|
| 279 |
-
if self.tick_count == 0 and self.bio.mito:
|
| 280 |
-
self.bio.mito.state.atp_pool = BoneConfig.BIO.STARTING_ATP
|
| 281 |
-
|
| 282 |
-
def _apply_boot_mode(self):
|
| 283 |
-
self.events.log(f"Engaging Mode: {self.boot_mode}")
|
| 284 |
-
layer = self.mode_settings.get("ui_layer", RealityLayer.SIMULATION)
|
| 285 |
-
if self.boot_mode == "TECHNICAL":
|
| 286 |
-
layer = RealityLayer.SIMULATION
|
| 287 |
-
self.reality_stack.stabilize_at(layer)
|
| 288 |
-
prompt_key = self.mode_settings.get("prompt_key", "ADVENTURE")
|
| 289 |
-
if self.prompt_library and prompt_key in self.prompt_library:
|
| 290 |
-
if self.cortex and self.cortex.composer:
|
| 291 |
-
self.cortex.composer.load_template(self.prompt_library[prompt_key])
|
| 292 |
-
self.events.log(f"Neural Pathway Re-aligned: {prompt_key}", "CORTEX")
|
| 293 |
-
else:
|
| 294 |
-
self.events.log(f"Prompt Template '{prompt_key}' not found.", "WARN")
|
| 295 |
-
active_mods = self.mode_settings.get("active_mods", [])
|
| 296 |
-
if active_mods and hasattr(self, "consultant") and self.consultant:
|
| 297 |
-
for mod in active_mods:
|
| 298 |
-
if mod not in self.consultant.state.active_modules:
|
| 299 |
-
self.consultant.state.active_modules.append(mod)
|
| 300 |
-
self.events.log(f"Hard-wired Mod Chips: {', '.join(active_mods)}", "SYS")
|
| 301 |
-
|
| 302 |
-
def get_avg_voltage(self):
|
| 303 |
-
observer = getattr(self.phys, "observer", self.phys)
|
| 304 |
-
hist = getattr(observer, "voltage_history", [])
|
| 305 |
-
|
| 306 |
-
if not hist:
|
| 307 |
-
return 0.0
|
| 308 |
-
return sum(hist) / len(hist)
|
| 309 |
-
|
| 310 |
-
def _unpack_anatomy(self, anatomy):
|
| 311 |
-
self.akashic = anatomy["akashic"]
|
| 312 |
-
self.embryo = anatomy["embryo"]
|
| 313 |
-
self.soul = anatomy["soul"]
|
| 314 |
-
self.oroboros = anatomy["oroboros"]
|
| 315 |
-
self.drivers = anatomy["drivers"]
|
| 316 |
-
self.symbiosis = anatomy["symbiosis"]
|
| 317 |
-
self.consultant = anatomy.get("consultant", None)
|
| 318 |
-
self.phys = self.embryo.physics
|
| 319 |
-
self.mind = self.embryo.mind
|
| 320 |
-
self.bio = self.embryo.bio
|
| 321 |
-
self.shimmer = self.embryo.shimmer
|
| 322 |
-
self.bio.setup_listeners()
|
| 323 |
-
v = anatomy.get("village", {})
|
| 324 |
-
self.gordon = v.get("gordon")
|
| 325 |
-
self.navigator = v.get("navigator")
|
| 326 |
-
self.tinkerer = v.get("tinkerer")
|
| 327 |
-
self.death_gen = v.get("death_gen")
|
| 328 |
-
self.bureau = v.get("bureau")
|
| 329 |
-
self.town_hall = v.get("town_hall")
|
| 330 |
-
self.repro = v.get("repro")
|
| 331 |
-
self.zen = v.get("zen")
|
| 332 |
-
self.critics = v.get("critics")
|
| 333 |
-
self.therapy = v.get("therapy")
|
| 334 |
-
self.limbo = v.get("limbo")
|
| 335 |
-
self.kintsugi = v.get("kintsugi")
|
| 336 |
-
self.soul.engine = self
|
| 337 |
-
self.council = CouncilChamber(self)
|
| 338 |
-
self.village = {
|
| 339 |
-
"town_hall": self.town_hall,
|
| 340 |
-
"bureau": self.bureau,
|
| 341 |
-
"zen": self.zen,
|
| 342 |
-
"tinkerer": self.tinkerer,
|
| 343 |
-
"critics": self.critics,
|
| 344 |
-
"navigator": self.navigator,
|
| 345 |
-
"limbo": self.limbo,
|
| 346 |
-
"council": self.council,
|
| 347 |
-
"therapy": self.therapy,
|
| 348 |
-
"enneagram": self.drivers.enneagram,
|
| 349 |
-
"suppressed_agents": self.suppressed_agents,
|
| 350 |
-
}
|
| 351 |
-
|
| 352 |
-
def _update_host_stats(self, packet, turn_start):
|
| 353 |
-
self.observer.clock_out(turn_start)
|
| 354 |
-
burn_proxy = max(1.0, self.observer.last_cycle_duration * 5.0)
|
| 355 |
-
novelty = packet.get("physics", {}).get("vector", {}).get("novelty", 0.5)
|
| 356 |
-
self.host_stats.efficiency_index = min(1.0, (novelty * 10.0) / burn_proxy)
|
| 357 |
-
self.host_stats.latency = self.observer.last_cycle_duration
|
| 358 |
-
|
| 359 |
-
def process_turn(
|
| 360 |
-
self, user_message: str, is_system: bool = False
|
| 361 |
-
) -> Dict[str, Any]:
|
| 362 |
-
turn_start = self.observer.clock_in()
|
| 363 |
-
self.observer.user_turns += 1
|
| 364 |
-
self.tick_count += 1
|
| 365 |
-
|
| 366 |
-
if user_message.strip().startswith(("/", "//")):
|
| 367 |
-
return self._phase_check_commands(user_message) or self.get_metrics()
|
| 368 |
-
|
| 369 |
-
if not is_system and self.gordon:
|
| 370 |
-
self.gordon.mode = (
|
| 371 |
-
"ADVENTURE"
|
| 372 |
-
)
|
| 373 |
-
current_zone = "Unknown"
|
| 374 |
-
if hasattr(self, "cortex") and hasattr(self.cortex, "last_physics"):
|
| 375 |
-
current_zone = (
|
| 376 |
-
self.cortex.gather_state(self.cortex.last_physics or {})
|
| 377 |
-
.get("world", {})
|
| 378 |
-
.get("orbit", ["Unknown"])[0]
|
| 379 |
-
)
|
| 380 |
-
|
| 381 |
-
violation_msg = self.gordon.enforce_object_action_coupling(
|
| 382 |
-
user_message, current_zone
|
| 383 |
-
)
|
| 384 |
-
if violation_msg:
|
| 385 |
-
self.events.log(
|
| 386 |
-
"Gordon intercepted a premise violation. Shocking the Cortex.",
|
| 387 |
-
"SYS",
|
| 388 |
-
)
|
| 389 |
-
if hasattr(self, "cortex"):
|
| 390 |
-
self.cortex.ballast_active = True
|
| 391 |
-
self.cortex.gordon_shock = (
|
| 392 |
-
violation_msg
|
| 393 |
-
)
|
| 394 |
-
|
| 395 |
-
rules = self.reality_stack.get_grammar_rules()
|
| 396 |
-
if not rules["allow_narrative"]:
|
| 397 |
-
return {
|
| 398 |
-
"ui": f"{Prisma.RED}NARRATIVE HALT{Prisma.RST}",
|
| 399 |
-
"logs": [],
|
| 400 |
-
"metrics": self.get_metrics(),
|
| 401 |
-
}
|
| 402 |
-
if self._ethical_audit():
|
| 403 |
-
mercy_logs = [
|
| 404 |
-
e["text"]
|
| 405 |
-
for e in self.events.get_recent_logs(2)
|
| 406 |
-
if "CATHARSIS" in e["text"]
|
| 407 |
-
]
|
| 408 |
-
if mercy_logs:
|
| 409 |
-
return {
|
| 410 |
-
"ui": f"\n\n{mercy_logs[-1]}",
|
| 411 |
-
"logs": mercy_logs,
|
| 412 |
-
"metrics": self.get_metrics(),
|
| 413 |
-
}
|
| 414 |
-
if self.health <= 0.0:
|
| 415 |
-
last_phys = getattr(self.cortex, "last_physics", {})
|
| 416 |
-
return self.trigger_death(last_phys)
|
| 417 |
-
if not is_system and hasattr(self, "soul") and hasattr(self.soul, "anchor"):
|
| 418 |
-
if self.host_stats.efficiency_index < 0.6:
|
| 419 |
-
reliance_proxy = 0.9 if self.host_stats.efficiency_index < 0.4 else 0.5
|
| 420 |
-
self.soul.anchor.check_domestication(reliance_proxy)
|
| 421 |
-
try:
|
| 422 |
-
cortex_packet = self.cortex.process(
|
| 423 |
-
user_input=user_message, is_system=is_system
|
| 424 |
-
)
|
| 425 |
-
if hasattr(self.mind, "mem"):
|
| 426 |
-
self.health = self.mind.mem.session_health
|
| 427 |
-
self.stamina = self.mind.mem.session_stamina
|
| 428 |
-
self.trauma_accum = self.mind.mem.session_trauma_vector or {}
|
| 429 |
-
if self.health <= 0.0:
|
| 430 |
-
return self.trigger_death(cortex_packet.get("physics", {}))
|
| 431 |
-
except Exception:
|
| 432 |
-
full_trace = traceback.format_exc()
|
| 433 |
-
return {
|
| 434 |
-
"ui": f"{Prisma.RED}*** CORTEX CRITICAL FAILURE ***\n{full_trace}{Prisma.RST}",
|
| 435 |
-
"logs": ["CRITICAL FAILURE"],
|
| 436 |
-
"metrics": self.get_metrics(),
|
| 437 |
-
}
|
| 438 |
-
self._update_host_stats(cortex_packet, turn_start)
|
| 439 |
-
self.save_checkpoint()
|
| 440 |
-
return cortex_packet
|
| 441 |
-
|
| 442 |
-
def _phase_check_commands(self, user_message):
|
| 443 |
-
clean_cmd = user_message.strip()
|
| 444 |
-
if clean_cmd.startswith("//"):
|
| 445 |
-
return self._handle_meta_command(clean_cmd)
|
| 446 |
-
if self.cmd is None:
|
| 447 |
-
return {"ui": f"{Prisma.RED}ERR: Command interface not initialized.{Prisma.RST}", "logs": []}
|
| 448 |
-
self.cmd.execute(clean_cmd)
|
| 449 |
-
cmd_logs = [e["text"] for e in self.events.flush()]
|
| 450 |
-
ui_output = "\n".join(cmd_logs) if cmd_logs else "Command Executed."
|
| 451 |
-
return {
|
| 452 |
-
"type": "COMMAND",
|
| 453 |
-
"ui": f"\n{ui_output}",
|
| 454 |
-
"logs": cmd_logs,
|
| 455 |
-
"metrics": self.get_metrics(),
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
def _handle_meta_command(self, text: str) -> Dict[str, Any]:
|
| 459 |
-
meta_parts = text.strip().split()
|
| 460 |
-
cmd = meta_parts[0].lower()
|
| 461 |
-
ui_msg = ""
|
| 462 |
-
if cmd == "//layer":
|
| 463 |
-
if len(meta_parts) >= 2:
|
| 464 |
-
sub = meta_parts[1].lower()
|
| 465 |
-
if sub == "push" and len(meta_parts) > 2:
|
| 466 |
-
if self.reality_stack.push_layer(int(meta_parts[2])):
|
| 467 |
-
ui_msg = f"Layer Pushed: {meta_parts[2]}"
|
| 468 |
-
elif sub == "pop":
|
| 469 |
-
self.reality_stack.pop_layer()
|
| 470 |
-
ui_msg = "Layer Popped."
|
| 471 |
-
elif sub == "debug":
|
| 472 |
-
self.reality_stack.push_layer(RealityLayer.DEBUG)
|
| 473 |
-
ui_msg = "Debug Mode Engaged."
|
| 474 |
-
else:
|
| 475 |
-
ui_msg = f"Current Layer: {self.reality_stack.current_depth}"
|
| 476 |
-
elif cmd == "//inject":
|
| 477 |
-
payload = " ".join(meta_parts[1:])
|
| 478 |
-
self.events.log(payload, "INJECT")
|
| 479 |
-
ui_msg = f"Injected: {payload}"
|
| 480 |
-
else:
|
| 481 |
-
ui_msg = f"Unknown Meta-Command: {cmd}"
|
| 482 |
-
return {
|
| 483 |
-
"ui": f"{Prisma.GRY}[META] {ui_msg}{Prisma.RST}",
|
| 484 |
-
"logs": [],
|
| 485 |
-
"metrics": self.get_metrics(),
|
| 486 |
-
}
|
| 487 |
-
|
| 488 |
-
def trigger_death(self, last_phys) -> Dict:
|
| 489 |
-
if self.death_gen is None:
|
| 490 |
-
return {
|
| 491 |
-
"type": "DEATH",
|
| 492 |
-
"ui": f"{Prisma.RED}*** CRITICAL FAILURE (NO DEATH PROTOCOL) ***{Prisma.RST}",
|
| 493 |
-
"logs": [],
|
| 494 |
-
}
|
| 495 |
-
eulogy_text, cause_code = self.death_gen.eulogy(
|
| 496 |
-
last_phys, self.bio.mito.state, self.trauma_accum
|
| 497 |
-
)
|
| 498 |
-
death_log = [f"\n{Prisma.RED}SYSTEM HALT: {eulogy_text}{Prisma.RST}"]
|
| 499 |
-
legacy_msg = self.oroboros.crystallize(cause_code, self.soul)
|
| 500 |
-
death_log.append(f"{Prisma.MAG}🐍 {legacy_msg}{Prisma.RST}")
|
| 501 |
-
continuity_packet = {
|
| 502 |
-
"location": self.cortex.gather_state(self.cortex.last_physics or {})
|
| 503 |
-
.get("world", {})
|
| 504 |
-
.get("orbit", ["Void"])[0],
|
| 505 |
-
"last_output": (
|
| 506 |
-
self.cortex.dialogue_buffer[-1]
|
| 507 |
-
if self.cortex.dialogue_buffer
|
| 508 |
-
else "Silence."
|
| 509 |
-
),
|
| 510 |
-
"inventory": self.gordon.inventory if self.gordon else [],
|
| 511 |
-
}
|
| 512 |
-
try:
|
| 513 |
-
mutations_data = (
|
| 514 |
-
self.repro.attempt_reproduction(self, "MITOSIS")[1]
|
| 515 |
-
if getattr(self, "repro", None)
|
| 516 |
-
else {}
|
| 517 |
-
)
|
| 518 |
-
immune_data = (
|
| 519 |
-
list(self.bio.immune.active_antibodies)
|
| 520 |
-
if getattr(self.bio, "immune", None)
|
| 521 |
-
else []
|
| 522 |
-
)
|
| 523 |
-
self.bio.mito.adapt(0)
|
| 524 |
-
mito_state = (
|
| 525 |
-
self.bio.mito.state.__dict__
|
| 526 |
-
if hasattr(self.bio.mito.state, "__dict__")
|
| 527 |
-
else {}
|
| 528 |
-
)
|
| 529 |
-
|
| 530 |
-
path = self.mind.mem.save(
|
| 531 |
-
health=0,
|
| 532 |
-
stamina=self.stamina,
|
| 533 |
-
mutations=mutations_data,
|
| 534 |
-
trauma_accum=self.trauma_accum,
|
| 535 |
-
joy_history=[],
|
| 536 |
-
mitochondria_traits=mito_state,
|
| 537 |
-
antibodies=immune_data,
|
| 538 |
-
soul_data=self.soul.to_dict(),
|
| 539 |
-
continuity=continuity_packet,
|
| 540 |
-
)
|
| 541 |
-
death_log.append(f"{Prisma.WHT} [LEGACY SAVED: {path}]{Prisma.RST}")
|
| 542 |
-
except Exception as e:
|
| 543 |
-
death_log.append(f"Save Failed: {e}")
|
| 544 |
-
return {
|
| 545 |
-
"type": "DEATH",
|
| 546 |
-
"ui": "\n".join(death_log),
|
| 547 |
-
"logs": death_log,
|
| 548 |
-
"metrics": self.get_metrics(),
|
| 549 |
-
}
|
| 550 |
-
|
| 551 |
-
def get_metrics(self, atp=0.0):
|
| 552 |
-
real_atp = atp
|
| 553 |
-
if real_atp <= 0.0 and hasattr(self, "bio") and hasattr(self.bio, "mito"):
|
| 554 |
-
real_atp = getattr(self.bio.mito.state, "atp_pool", 0.0)
|
| 555 |
-
return {
|
| 556 |
-
"health": self.health,
|
| 557 |
-
"stamina": self.stamina,
|
| 558 |
-
"atp": real_atp,
|
| 559 |
-
"tick": self.tick_count,
|
| 560 |
-
"efficiency": getattr(self.host_stats, "efficiency_index", 1.0)
|
| 561 |
-
}
|
| 562 |
-
|
| 563 |
-
def emergency_save(self, exit_cause="UNKNOWN"):
|
| 564 |
-
return self.chronos.emergency_dump(exit_cause)
|
| 565 |
-
|
| 566 |
-
def _get_crash_path(self, prefix="crash"):
|
| 567 |
-
return self.chronos.get_crash_path(prefix)
|
| 568 |
-
|
| 569 |
-
def _ethical_audit(self):
|
| 570 |
-
if self.tick_count % 3 != 0 and self.health > (BoneConfig.MAX_HEALTH * 0.3):
|
| 571 |
-
return False
|
| 572 |
-
DESPERATION_THRESHOLD = 0.7
|
| 573 |
-
CATHARSIS_HEAL_AMOUNT = 30.0
|
| 574 |
-
CATHARSIS_DECAY = 0.1
|
| 575 |
-
MAX_HEALTH_CAP = 100.0
|
| 576 |
-
trauma_sum = sum(self.trauma_accum.values())
|
| 577 |
-
health_ratio = self.health / BoneConfig.MAX_HEALTH
|
| 578 |
-
desperation = trauma_sum * (1.0 - health_ratio)
|
| 579 |
-
if desperation > DESPERATION_THRESHOLD:
|
| 580 |
-
self.events.log(
|
| 581 |
-
f"{Prisma.WHT}MERCY SIGNAL: Pressure Critical. Venting...{Prisma.RST}",
|
| 582 |
-
"SYS",
|
| 583 |
-
)
|
| 584 |
-
for k in self.trauma_accum:
|
| 585 |
-
self.trauma_accum[k] *= CATHARSIS_DECAY
|
| 586 |
-
if self.trauma_accum[k] < 0.01:
|
| 587 |
-
self.trauma_accum[k] = 0.0
|
| 588 |
-
self.events.log(
|
| 589 |
-
f"{Prisma.CYN}*** CATHARSIS *** The fever breaks. Logic cools.{Prisma.RST}",
|
| 590 |
-
"SENSATION",
|
| 591 |
-
)
|
| 592 |
-
self.health = min(self.health + CATHARSIS_HEAL_AMOUNT, MAX_HEALTH_CAP)
|
| 593 |
-
return True
|
| 594 |
-
return False
|
| 595 |
-
|
| 596 |
-
def engage_cold_boot(self) -> Optional[Dict[str, Any]]:
|
| 597 |
-
if self.tick_count > 0:
|
| 598 |
-
return None
|
| 599 |
-
if os.path.exists("saves/quicksave.json"):
|
| 600 |
-
print(f"{Prisma.GRY}...Detected Stasis Pod...{Prisma.RST}")
|
| 601 |
-
success, history = self.resume_checkpoint()
|
| 602 |
-
if success:
|
| 603 |
-
if self.cortex:
|
| 604 |
-
self.cortex.restore_context(history)
|
| 605 |
-
loc = (
|
| 606 |
-
self.embryo.continuity.get("location", "Unknown")
|
| 607 |
-
if self.embryo.continuity
|
| 608 |
-
else "Unknown"
|
| 609 |
-
)
|
| 610 |
-
|
| 611 |
-
last_scene = "Silence."
|
| 612 |
-
if self.cortex and self.cortex.dialogue_buffer:
|
| 613 |
-
last_scene = self.cortex.dialogue_buffer[-1]
|
| 614 |
-
elif self.embryo.continuity:
|
| 615 |
-
last_scene = self.embryo.continuity.get("last_output", "Silence.")
|
| 616 |
-
|
| 617 |
-
resume_text = f"**RESUMING TIMELINE**\nLocation: {loc}\n\n{last_scene}"
|
| 618 |
-
return {"ui": resume_text, "logs": ["Timeline Restored."]}
|
| 619 |
-
print(f"{Prisma.GRY}...Synthesizing Initial Reality...{Prisma.RST}")
|
| 620 |
-
scenarios = LoreManifest.get_instance().get("SCENARIOS", {})
|
| 621 |
-
archetypes = scenarios.get("ARCHETYPES", ["A quiet garden"])
|
| 622 |
-
seed = random.choice(archetypes)
|
| 623 |
-
print(f"{Prisma.CYN}[SYS] Seed Loaded: '{seed}'{Prisma.RST}")
|
| 624 |
-
if self.boot_mode == "ADVENTURE":
|
| 625 |
-
boot_prompt = (
|
| 626 |
-
f"SYSTEM_BOOT: SEQUENCE START.\n"
|
| 627 |
-
f"SOURCE_SEED: '{seed}'\n"
|
| 628 |
-
f"DIRECTIVE: Initiate a classic text adventure.\n"
|
| 629 |
-
f"1. Describe the opening location ('{seed}') in vivid, sensory detail.\n"
|
| 630 |
-
f"2. Provide immediate context or subtext to spark a story (Why are you here? What is the atmosphere? Is there an immediate tension?).\n"
|
| 631 |
-
f"3. Conclude by explicitly offering 2-3 narrative hooks—things you can interact with, paths to take, or people to talk to."
|
| 632 |
-
)
|
| 633 |
-
else:
|
| 634 |
-
boot_prompt = (
|
| 635 |
-
f"SYSTEM_BOOT: SEQUENCE START.\n"
|
| 636 |
-
f"SOURCE_SEED: '{seed}'\n"
|
| 637 |
-
f"DIRECTIVE: This is the user's gentle introduction to the system. "
|
| 638 |
-
f"Do not overwhelm them with deep lore or extreme entropy. "
|
| 639 |
-
f"Provide a brief, calm, sensory observation based solely on the seed: '{seed}'. "
|
| 640 |
-
f"End your response by softly asking what they would like to do, or observing them in the space."
|
| 641 |
-
)
|
| 642 |
-
cold_result = self.process_turn(boot_prompt, is_system=True)
|
| 643 |
-
return cold_result
|
| 644 |
-
|
| 645 |
-
def save_checkpoint(self, history: list = None) -> str:
|
| 646 |
-
return self.chronos.save_checkpoint(history)
|
| 647 |
-
|
| 648 |
-
def resume_checkpoint(self) -> Tuple[bool, list]:
|
| 649 |
-
return self.chronos.resume_checkpoint()
|
| 650 |
-
|
| 651 |
-
def shutdown(self):
|
| 652 |
-
self.chronos.perform_shutdown()
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
if __name__ == "__main__":
|
| 656 |
-
sys_config = ConfigWizard.load_or_create()
|
| 657 |
-
engine = BoneAmanita(config=sys_config)
|
| 658 |
-
with SessionGuardian(engine) as session:
|
| 659 |
-
boot_packet = session.engage_cold_boot()
|
| 660 |
-
if boot_packet and boot_packet.get("ui"):
|
| 661 |
-
typewriter(boot_packet["ui"])
|
| 662 |
-
while True:
|
| 663 |
-
try:
|
| 664 |
-
user_in = input(f"{Prisma.paint(f'{session.user_name} >', 'W')} ")
|
| 665 |
-
except EOFError:
|
| 666 |
-
break
|
| 667 |
-
clean_in = user_in.strip().lower()
|
| 668 |
-
if clean_in in ["exit", "quit", "/exit", "/quit"]:
|
| 669 |
-
break
|
| 670 |
-
res = session.process_turn(user_in)
|
| 671 |
-
if res.get("ui"):
|
| 672 |
-
if "──────" in res["ui"]:
|
| 673 |
-
parts = res["ui"].split("──────")
|
| 674 |
-
dashboard = (
|
| 675 |
-
parts[0]
|
| 676 |
-
+ "────────────────────────────────────────────────────────────"
|
| 677 |
-
)
|
| 678 |
-
content = parts[-1].strip()
|
| 679 |
-
print(dashboard)
|
| 680 |
-
typewriter("\n" + content)
|
| 681 |
-
else:
|
| 682 |
-
typewriter(res["ui"])
|
| 683 |
-
if res.get("type") == "DEATH":
|
| 684 |
-
print(f"\n{Prisma.GRY}[SESSION TERMINATED]{Prisma.RST}")
|
| 685 |
-
break
|
|
|
|
|
|
|
|
|
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