Delete bone_cycle.py
Browse files- bone_cycle.py +0 -1250
bone_cycle.py
DELETED
|
@@ -1,1250 +0,0 @@
|
|
| 1 |
-
import traceback, random, time, uuid
|
| 2 |
-
from typing import Dict, Any, List
|
| 3 |
-
from bone_core import ArchetypeArbiter, LoreManifest
|
| 4 |
-
from bone_types import Prisma, CycleContext
|
| 5 |
-
from bone_physics import (
|
| 6 |
-
TheGatekeeper,
|
| 7 |
-
apply_somatic_feedback,
|
| 8 |
-
TRIGRAM_MAP,
|
| 9 |
-
CycleStabilizer,
|
| 10 |
-
)
|
| 11 |
-
from bone_gui import SoulDashboard, CycleReporter
|
| 12 |
-
from bone_machine import PanicRoom
|
| 13 |
-
from bone_body import SynestheticCortex
|
| 14 |
-
from bone_symbiosis import SymbiosisManager
|
| 15 |
-
from bone_config import BoneConfig, BonePresets
|
| 16 |
-
from bone_drivers import CongruenceValidator
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
class SimulationPhase:
|
| 20 |
-
def __init__(self, engine_ref):
|
| 21 |
-
self.eng = engine_ref
|
| 22 |
-
self.name = "GENERIC_PHASE"
|
| 23 |
-
|
| 24 |
-
def run(self, ctx: CycleContext) -> CycleContext:
|
| 25 |
-
raise NotImplementedError
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
class ObservationPhase(SimulationPhase):
|
| 29 |
-
def __init__(self, engine_ref):
|
| 30 |
-
super().__init__(engine_ref)
|
| 31 |
-
self.name = "OBSERVE"
|
| 32 |
-
|
| 33 |
-
def run(self, ctx: CycleContext):
|
| 34 |
-
if self.eng.gordon and "GORDON" not in self.eng.suppressed_agents:
|
| 35 |
-
loot_candidate = self.eng.gordon.parse_loot(ctx.input_text, "")
|
| 36 |
-
if loot_candidate:
|
| 37 |
-
acquire_msg = self.eng.gordon.acquire(loot_candidate)
|
| 38 |
-
ctx.log(acquire_msg)
|
| 39 |
-
gaze_result = self.eng.phys.observer.gaze(
|
| 40 |
-
ctx.input_text, self.eng.mind.mem.graph
|
| 41 |
-
)
|
| 42 |
-
input_phys = gaze_result["physics"]
|
| 43 |
-
transfer_keys = {
|
| 44 |
-
"clean_words",
|
| 45 |
-
"counts",
|
| 46 |
-
"vector",
|
| 47 |
-
"valence",
|
| 48 |
-
"entropy",
|
| 49 |
-
"beta_index",
|
| 50 |
-
"raw_text",
|
| 51 |
-
"antigens",
|
| 52 |
-
"psi",
|
| 53 |
-
"kappa",
|
| 54 |
-
"zone",
|
| 55 |
-
"flow_state",
|
| 56 |
-
"repetition",
|
| 57 |
-
}
|
| 58 |
-
for k in transfer_keys:
|
| 59 |
-
if hasattr(input_phys, k):
|
| 60 |
-
setattr(ctx.physics, k, getattr(input_phys, k))
|
| 61 |
-
if (obs_v := getattr(input_phys, "voltage", 0.0)) > 0:
|
| 62 |
-
ctx.physics.voltage += obs_v * 0.5
|
| 63 |
-
curr_d = max(0.1, ctx.physics.narrative_drag)
|
| 64 |
-
input_d = getattr(input_phys, "narrative_drag", 0.0)
|
| 65 |
-
ctx.physics.narrative_drag = (curr_d * 0.7) + (input_d * 0.3)
|
| 66 |
-
ctx.clean_words = gaze_result["clean_words"]
|
| 67 |
-
current_atp = self.eng.bio.mito.state.atp_pool
|
| 68 |
-
if current_atp < 15.0:
|
| 69 |
-
ctx.log(
|
| 70 |
-
f"{Prisma.OCHRE}🧠 INTENTION: Low Energy. Metabolism slowing down.{Prisma.RST}"
|
| 71 |
-
)
|
| 72 |
-
if hasattr(self.eng, "symbiosis"):
|
| 73 |
-
diag = self.eng.symbiosis.current_health.diagnosis
|
| 74 |
-
if diag != "STABLE":
|
| 75 |
-
ctx.log(f"{Prisma.OCHRE}⚕️ SYMBIONT DIAGNOSIS: {diag}{Prisma.RST}")
|
| 76 |
-
self.eng.phys.dynamics.commit(ctx.physics.voltage)
|
| 77 |
-
self.eng.tick_count += 1
|
| 78 |
-
return ctx
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
class SanctuaryPhase(SimulationPhase):
|
| 82 |
-
def __init__(self, engine_ref, governor_ref):
|
| 83 |
-
super().__init__(engine_ref)
|
| 84 |
-
self.name = "SANCTUARY"
|
| 85 |
-
self.governor = governor_ref
|
| 86 |
-
|
| 87 |
-
def run(self, ctx: CycleContext):
|
| 88 |
-
in_safe_zone, distance = self.governor.assess(ctx.physics)
|
| 89 |
-
trauma_sum = (
|
| 90 |
-
sum(self.eng.trauma_accum.values())
|
| 91 |
-
if getattr(self.eng, "trauma_accum", None)
|
| 92 |
-
else 0.0
|
| 93 |
-
)
|
| 94 |
-
if in_safe_zone and trauma_sum < 25.0:
|
| 95 |
-
self._enter_sanctuary(ctx)
|
| 96 |
-
self._apply_restoration(ctx)
|
| 97 |
-
if random.random() < 0.3:
|
| 98 |
-
self._trigger_dream(ctx)
|
| 99 |
-
return ctx
|
| 100 |
-
|
| 101 |
-
@staticmethod
|
| 102 |
-
def _enter_sanctuary(ctx: CycleContext):
|
| 103 |
-
ctx.physics.zone = getattr(BonePresets.SANCTUARY, "ZONE", "SANCTUARY")
|
| 104 |
-
ctx.physics.zone_color = getattr(BonePresets.SANCTUARY, "COLOR_NAME", "GRN")
|
| 105 |
-
ctx.physics.flow_state = "LAMINAR"
|
| 106 |
-
if random.random() < 0.1:
|
| 107 |
-
color = getattr(BonePresets.SANCTUARY, "COLOR", Prisma.GRN)
|
| 108 |
-
ctx.log(f"{color}![☀️] SANCTUARY: Breathing space.{Prisma.RST}")
|
| 109 |
-
|
| 110 |
-
def _apply_restoration(self, ctx: CycleContext):
|
| 111 |
-
if self.eng.bio:
|
| 112 |
-
rest_logs = self.eng.bio.rest(factor=1.0)
|
| 113 |
-
for log in rest_logs:
|
| 114 |
-
ctx.log(log)
|
| 115 |
-
for key in list(self.eng.trauma_accum.keys()):
|
| 116 |
-
self.eng.trauma_accum[key] = max(0.0, self.eng.trauma_accum[key] - 0.1)
|
| 117 |
-
|
| 118 |
-
def _trigger_dream(self, ctx: CycleContext):
|
| 119 |
-
if not hasattr(self.eng, "mind") or not hasattr(self.eng.mind, "dreamer"):
|
| 120 |
-
return
|
| 121 |
-
if hasattr(self.eng.mind.mem, "replay_dreams"):
|
| 122 |
-
dream_log = self.eng.mind.mem.replay_dreams()
|
| 123 |
-
if dream_log:
|
| 124 |
-
ctx.log(f"{Prisma.VIOLET}{dream_log}{Prisma.RST}")
|
| 125 |
-
current_trauma_load = (
|
| 126 |
-
sum(self.eng.trauma_accum.values())
|
| 127 |
-
if hasattr(self.eng, "trauma_accum")
|
| 128 |
-
else 0.0
|
| 129 |
-
)
|
| 130 |
-
bio_packet = {
|
| 131 |
-
"chem": self.eng.bio.endo.get_state(),
|
| 132 |
-
"mito": {
|
| 133 |
-
"atp": self.eng.bio.mito.state.atp_pool,
|
| 134 |
-
"ros": self.eng.bio.mito.state.ros_buildup,
|
| 135 |
-
},
|
| 136 |
-
"physics": (
|
| 137 |
-
ctx.physics.to_dict()
|
| 138 |
-
if hasattr(ctx.physics, "to_dict")
|
| 139 |
-
else ctx.physics
|
| 140 |
-
),
|
| 141 |
-
"trauma_vector": current_trauma_load,
|
| 142 |
-
}
|
| 143 |
-
soul_snapshot = (
|
| 144 |
-
self.eng.soul.to_dict()
|
| 145 |
-
if hasattr(self.eng, "soul") and hasattr(self.eng.soul, "to_dict")
|
| 146 |
-
else {}
|
| 147 |
-
)
|
| 148 |
-
dream_packet = self.eng.mind.dreamer.enter_rem_cycle(
|
| 149 |
-
soul_snapshot, bio_state=bio_packet
|
| 150 |
-
)
|
| 151 |
-
if isinstance(dream_packet, dict):
|
| 152 |
-
ctx.log(dream_packet.get("log", "The mind wanders..."))
|
| 153 |
-
ctx.last_dream = dream_packet
|
| 154 |
-
elif isinstance(dream_packet, tuple):
|
| 155 |
-
log_msg, effects = dream_packet
|
| 156 |
-
ctx.log(log_msg)
|
| 157 |
-
if effects:
|
| 158 |
-
if "adrenaline" in effects:
|
| 159 |
-
self.eng.bio.endo.adrenaline += effects["adrenaline"]
|
| 160 |
-
if "voltage" in effects:
|
| 161 |
-
ctx.physics.voltage += effects["voltage"]
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
class MaintenancePhase(SimulationPhase):
|
| 165 |
-
def __init__(self, engine_ref):
|
| 166 |
-
super().__init__(engine_ref)
|
| 167 |
-
self.name = "MAINTENANCE"
|
| 168 |
-
|
| 169 |
-
def run(self, ctx: CycleContext):
|
| 170 |
-
if hasattr(self.eng, "town_hall"):
|
| 171 |
-
blooms = self.eng.town_hall.tend_garden(ctx.clean_words) or []
|
| 172 |
-
for bloom in blooms:
|
| 173 |
-
ctx.log(bloom)
|
| 174 |
-
if self.eng.tick_count % 5 == 0:
|
| 175 |
-
weather_report = self.eng.town_hall.consult_almanac(ctx.physics)
|
| 176 |
-
if weather_report:
|
| 177 |
-
ctx.log(f"{Prisma.CYN}{weather_report}{Prisma.RST}")
|
| 178 |
-
is_census_due = self.eng.tick_count > 0 and self.eng.tick_count % 20 == 0
|
| 179 |
-
if is_census_due or "census" in ctx.clean_words:
|
| 180 |
-
report = self.eng.town_hall.conduct_census(
|
| 181 |
-
ctx.physics, self.eng.host_stats
|
| 182 |
-
)
|
| 183 |
-
if report:
|
| 184 |
-
ctx.log(f"{Prisma.CYN}📜 TOWN HALL: {report}{Prisma.RST}")
|
| 185 |
-
session_snapshot = {
|
| 186 |
-
"trauma_vector": self.eng.trauma_accum,
|
| 187 |
-
"meta": {"final_health": self.eng.health},
|
| 188 |
-
}
|
| 189 |
-
status, advice = self.eng.town_hall.diagnose_condition(
|
| 190 |
-
session_data=session_snapshot,
|
| 191 |
-
_host_health=self.eng.bio.biometrics if self.eng.bio else None,
|
| 192 |
-
soul=self.eng.soul,
|
| 193 |
-
)
|
| 194 |
-
if status != "BALANCED":
|
| 195 |
-
ctx.log(
|
| 196 |
-
f"{Prisma.OCHRE}🩺 VITAL SIGNS: {status} - {advice}{Prisma.RST}"
|
| 197 |
-
)
|
| 198 |
-
if self.eng.mind and hasattr(self.eng.mind, "mem"):
|
| 199 |
-
if hasattr(self.eng.mind.mem, "run_ecosystem"):
|
| 200 |
-
eco_logs = self.eng.mind.mem.run_ecosystem(
|
| 201 |
-
ctx.physics.to_dict(), self.eng.stamina, self.eng.tick_count
|
| 202 |
-
)
|
| 203 |
-
for log in eco_logs:
|
| 204 |
-
ctx.log(log)
|
| 205 |
-
return ctx
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
class GatekeeperPhase(SimulationPhase):
|
| 209 |
-
def __init__(self, engine_ref):
|
| 210 |
-
super().__init__(engine_ref)
|
| 211 |
-
self.name = "GATEKEEP"
|
| 212 |
-
self.gatekeeper = TheGatekeeper(self.eng.lex)
|
| 213 |
-
|
| 214 |
-
def run(self, ctx: CycleContext):
|
| 215 |
-
if ctx.is_system_event:
|
| 216 |
-
return ctx
|
| 217 |
-
if hasattr(self.eng, "soul") and hasattr(self.eng.soul, "anchor"):
|
| 218 |
-
anchor = self.eng.soul.anchor
|
| 219 |
-
if anchor.agency_lock:
|
| 220 |
-
passed = anchor.assess_humanity(ctx.input_text)
|
| 221 |
-
if not passed:
|
| 222 |
-
dash_view = SoulDashboard(self.eng).render()
|
| 223 |
-
ctx.refusal_triggered = True
|
| 224 |
-
ctx.refusal_packet = {
|
| 225 |
-
"ui": f"{dash_view}\n\n"
|
| 226 |
-
f"{Prisma.RED}⛔ ACCESS DENIED: The machine is sulking.\n"
|
| 227 |
-
f" Status: LOCKED (Solve the riddle or prove you are alive).{Prisma.RST}",
|
| 228 |
-
"logs": ["Command Rejected (Agency Lock)"],
|
| 229 |
-
"metrics": self.eng.get_metrics(),
|
| 230 |
-
}
|
| 231 |
-
return ctx
|
| 232 |
-
if self.eng.gordon:
|
| 233 |
-
current_zone = getattr(ctx.physics, "zone", "UNKNOWN")
|
| 234 |
-
coupling_error = self.eng.gordon.enforce_object_action_coupling(
|
| 235 |
-
ctx.input_text, current_zone
|
| 236 |
-
)
|
| 237 |
-
if coupling_error:
|
| 238 |
-
ctx.refusal_triggered = True
|
| 239 |
-
ctx.refusal_packet = {
|
| 240 |
-
"type": "PREMISE_VIOLATION",
|
| 241 |
-
"ui": f"\n{coupling_error}",
|
| 242 |
-
"logs": ["Premise Violation: Object-Action Coupling Failed"],
|
| 243 |
-
"metrics": self.eng.get_metrics(),
|
| 244 |
-
}
|
| 245 |
-
return ctx
|
| 246 |
-
is_allowed, refusal_packet = self.gatekeeper.check_entry(ctx)
|
| 247 |
-
if not is_allowed:
|
| 248 |
-
ctx.refusal_triggered = True
|
| 249 |
-
ctx.refusal_packet = refusal_packet
|
| 250 |
-
return ctx
|
| 251 |
-
if self.eng.bureau:
|
| 252 |
-
current_bio = self.eng.get_metrics()
|
| 253 |
-
audit_result = self.eng.bureau.audit(
|
| 254 |
-
ctx.physics.to_dict(), current_bio, origin="USER"
|
| 255 |
-
)
|
| 256 |
-
if audit_result:
|
| 257 |
-
if audit_result.get("block", False):
|
| 258 |
-
ctx.refusal_triggered = True
|
| 259 |
-
ctx.refusal_packet = {
|
| 260 |
-
"type": "BUREAU_BLOCK",
|
| 261 |
-
"ui": audit_result.get("ui", "Bureaucratic Injunction."),
|
| 262 |
-
"logs": ["Bureaucratic Block Triggered"],
|
| 263 |
-
"metrics": (
|
| 264 |
-
self.eng.get_metrics()
|
| 265 |
-
if hasattr(self.eng, "get_metrics")
|
| 266 |
-
else {}
|
| 267 |
-
),
|
| 268 |
-
}
|
| 269 |
-
return ctx
|
| 270 |
-
if self.eng.bio and self.eng.bio.mito:
|
| 271 |
-
self.eng.bio.mito.adjust_atp(
|
| 272 |
-
audit_result.get("atp_gain", 0.0), "Bureaucratic Fine (User)"
|
| 273 |
-
)
|
| 274 |
-
if audit_result.get("log"):
|
| 275 |
-
ctx.log(audit_result["log"])
|
| 276 |
-
if audit_result.get("ui"):
|
| 277 |
-
ctx.bureau_ui = audit_result["ui"]
|
| 278 |
-
ctx.is_bureaucratic = True
|
| 279 |
-
return ctx
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
class MetabolismPhase(SimulationPhase):
|
| 283 |
-
def __init__(self, engine_ref):
|
| 284 |
-
super().__init__(engine_ref)
|
| 285 |
-
self.name = "METABOLISM"
|
| 286 |
-
|
| 287 |
-
def run(self, ctx: CycleContext):
|
| 288 |
-
if ctx.is_system_event:
|
| 289 |
-
return ctx
|
| 290 |
-
if not hasattr(self.eng, "bio") or not self.eng.bio:
|
| 291 |
-
return ctx
|
| 292 |
-
mode_settings = getattr(self.eng, "mode_settings", {})
|
| 293 |
-
if not mode_settings.get("atp_drain_enabled", True):
|
| 294 |
-
atp_level = (
|
| 295 |
-
self.eng.bio.mito.state.atp_pool
|
| 296 |
-
if self.eng.bio and self.eng.bio.mito
|
| 297 |
-
else 100.0
|
| 298 |
-
)
|
| 299 |
-
ctx.bio_result = {"is_alive": True, "logs": [], "atp": atp_level}
|
| 300 |
-
ctx.is_alive = True
|
| 301 |
-
self._apply_healing(ctx)
|
| 302 |
-
return ctx
|
| 303 |
-
physics = ctx.physics
|
| 304 |
-
if hasattr(self.eng, "host_stats"):
|
| 305 |
-
self._apply_economic_stimulus(ctx, self.eng.host_stats.efficiency_index)
|
| 306 |
-
gov_msg = self.eng.bio.governor.shift(
|
| 307 |
-
physics, self.eng.phys.dynamics.voltage_history, self.eng.tick_count
|
| 308 |
-
)
|
| 309 |
-
if gov_msg:
|
| 310 |
-
self.eng.events.log(gov_msg, "GOV")
|
| 311 |
-
physics.manifold = self.eng.bio.governor.mode
|
| 312 |
-
max_v = getattr(BoneConfig.PHYSICS, "VOLTAGE_MAX", 20.0)
|
| 313 |
-
bio_feedback = {
|
| 314 |
-
"INTEGRITY": getattr(physics, "truth_ratio", 1.0),
|
| 315 |
-
"STATIC": getattr(physics, "repetition", 0.0),
|
| 316 |
-
"FORCE": getattr(physics, "voltage", 0.0) / max_v,
|
| 317 |
-
"BETA": getattr(physics, "beta_index", 0.0),
|
| 318 |
-
"PSI": getattr(physics, "psi", 0.0),
|
| 319 |
-
"ENTROPY": getattr(physics, "entropy", 0.0),
|
| 320 |
-
"VALENCE": getattr(physics, "valence", 0.0),
|
| 321 |
-
}
|
| 322 |
-
metrics = self.eng.get_metrics()
|
| 323 |
-
ctx.bio_result = self.eng.soma.digest_cycle(
|
| 324 |
-
ctx.input_text,
|
| 325 |
-
physics,
|
| 326 |
-
bio_feedback,
|
| 327 |
-
metrics["health"],
|
| 328 |
-
metrics["stamina"],
|
| 329 |
-
self.eng.bio.governor.get_stress_modifier(self.eng.tick_count),
|
| 330 |
-
self.eng.tick_count,
|
| 331 |
-
circadian_bias=self._check_circadian_rhythm(),
|
| 332 |
-
)
|
| 333 |
-
if self.eng.bio.biometrics:
|
| 334 |
-
self.eng.health = self.eng.bio.biometrics.health
|
| 335 |
-
self.eng.stamina = self.eng.bio.biometrics.stamina
|
| 336 |
-
ctx.is_alive = ctx.bio_result["is_alive"]
|
| 337 |
-
for log in ctx.bio_result["logs"]:
|
| 338 |
-
if any(x in str(log) for x in ["CRITICAL", "TAX", "Poison", "NECROSIS"]):
|
| 339 |
-
ctx.log(log)
|
| 340 |
-
self._audit_hubris(ctx, physics)
|
| 341 |
-
self._apply_healing(ctx)
|
| 342 |
-
self._check_narcolepsy(ctx)
|
| 343 |
-
return ctx
|
| 344 |
-
|
| 345 |
-
def _apply_economic_stimulus(self, ctx: CycleContext, efficiency: float):
|
| 346 |
-
if efficiency >= 0.8:
|
| 347 |
-
return
|
| 348 |
-
tax_burn = min(1.5, (0.8 - efficiency) * 5.0)
|
| 349 |
-
if tax_burn > 0:
|
| 350 |
-
self.eng.bio.mito.state.atp_pool = max(
|
| 351 |
-
0.0, self.eng.bio.mito.state.atp_pool - tax_burn
|
| 352 |
-
)
|
| 353 |
-
ctx.log(
|
| 354 |
-
f"{Prisma.OCHRE}⚡ METABOLIC TAX: System strain burns {tax_burn:.1f} ATP.{Prisma.RST}"
|
| 355 |
-
)
|
| 356 |
-
|
| 357 |
-
def _check_narcolepsy(self, ctx: CycleContext):
|
| 358 |
-
atp = self.eng.bio.mito.state.atp_pool
|
| 359 |
-
starvation = getattr(BoneConfig.BIO, "ATP_STARVATION", 5.0)
|
| 360 |
-
trigger = (atp < (starvation * 0.5)) or (
|
| 361 |
-
self.eng.tick_count > 0 and self.eng.tick_count % 100 == 0
|
| 362 |
-
)
|
| 363 |
-
if trigger and hasattr(self.eng.mind, "dreamer"):
|
| 364 |
-
ctx.log(
|
| 365 |
-
f"\n{Prisma.VIOLET}[AUTO-SLEEP]: Forced reboot sequence.{Prisma.RST}"
|
| 366 |
-
)
|
| 367 |
-
soul_snap = self.eng.soul.to_dict() if hasattr(self.eng, "soul") else {}
|
| 368 |
-
self.eng.mind.dreamer.enter_rem_cycle(soul_snap, bio_state={"atp": atp})
|
| 369 |
-
self.eng.mind.dreamer.run_defragmentation(self.eng.mind.mem)
|
| 370 |
-
reboot_val = getattr(BoneConfig, "MAX_ATP", 100.0) * 0.33
|
| 371 |
-
self.eng.bio.mito.state.atp_pool = reboot_val
|
| 372 |
-
ctx.bio_result["atp"] = reboot_val
|
| 373 |
-
ctx.log(
|
| 374 |
-
f"{Prisma.GRN} (System restored. ATP stabilized at {reboot_val:.1f}){Prisma.RST}"
|
| 375 |
-
)
|
| 376 |
-
|
| 377 |
-
def _check_circadian_rhythm(self):
|
| 378 |
-
if self.eng.tick_count % 10 == 0:
|
| 379 |
-
bias, msg = self.eng.bio.endo.calculate_circadian_bias()
|
| 380 |
-
if msg:
|
| 381 |
-
self.eng.events.log(f"{Prisma.CYN}🕒 {msg}{Prisma.RST}", "BIO")
|
| 382 |
-
return bias
|
| 383 |
-
return None
|
| 384 |
-
|
| 385 |
-
def _audit_hubris(self, ctx, physics):
|
| 386 |
-
hit, msg, evt = self.eng.phys.tension.audit_hubris(physics.to_dict())
|
| 387 |
-
if hit:
|
| 388 |
-
ctx.log(msg)
|
| 389 |
-
if evt == "FLOW_BOOST":
|
| 390 |
-
self.eng.bio.mito.state.atp_pool += 20.0
|
| 391 |
-
elif evt == "ICARUS_CRASH":
|
| 392 |
-
damage = 15.0
|
| 393 |
-
ctx.log(f" {Prisma.RED}IMPACT TRAUMA: -{damage} HP.{Prisma.RST}")
|
| 394 |
-
if self.eng.bio.biometrics:
|
| 395 |
-
self.eng.bio.biometrics.health = max(
|
| 396 |
-
0.0, self.eng.bio.biometrics.health - damage
|
| 397 |
-
)
|
| 398 |
-
self.eng.health -= damage
|
| 399 |
-
|
| 400 |
-
def _apply_healing(self, ctx):
|
| 401 |
-
qualia = self.eng.somatic.get_current_qualia(getattr(ctx, "last_impulse", None))
|
| 402 |
-
current_stamina = self.eng.stamina
|
| 403 |
-
if self.eng.bio.biometrics:
|
| 404 |
-
current_stamina = self.eng.bio.biometrics.stamina
|
| 405 |
-
cracked, koan = self.eng.kintsugi.check_integrity(current_stamina)
|
| 406 |
-
if cracked:
|
| 407 |
-
ctx.log(f"{Prisma.YEL}🏺 KINTSUGI ACTIVATED. KOAN: {koan}{Prisma.RST}")
|
| 408 |
-
if self.eng.kintsugi.active_koan:
|
| 409 |
-
repair = self.eng.kintsugi.attempt_repair(
|
| 410 |
-
ctx.physics, self.eng.trauma_accum, self.eng.soul, qualia
|
| 411 |
-
)
|
| 412 |
-
if repair and repair["success"]:
|
| 413 |
-
ctx.log(repair["msg"])
|
| 414 |
-
heal_amt = 20.0
|
| 415 |
-
if self.eng.bio.biometrics:
|
| 416 |
-
self.eng.bio.biometrics.stamina = min(
|
| 417 |
-
BoneConfig.MAX_STAMINA,
|
| 418 |
-
self.eng.bio.biometrics.stamina + heal_amt,
|
| 419 |
-
)
|
| 420 |
-
self.eng.stamina = min(
|
| 421 |
-
BoneConfig.MAX_STAMINA, self.eng.stamina + heal_amt
|
| 422 |
-
)
|
| 423 |
-
if self.eng.therapy.check_progress(
|
| 424 |
-
ctx.physics, current_stamina, self.eng.trauma_accum, qualia
|
| 425 |
-
):
|
| 426 |
-
ctx.log(f"{Prisma.GRN}❤️ THERAPY: Trauma processed. Health +5.{Prisma.RST}")
|
| 427 |
-
if self.eng.bio.biometrics:
|
| 428 |
-
self.eng.bio.biometrics.health = min(
|
| 429 |
-
BoneConfig.MAX_HEALTH, self.eng.bio.biometrics.health + 5.0
|
| 430 |
-
)
|
| 431 |
-
self.eng.health = min(BoneConfig.MAX_HEALTH, self.eng.health + 5.0)
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
class RealityFilterPhase(SimulationPhase):
|
| 435 |
-
def __init__(self, engine_ref):
|
| 436 |
-
super().__init__(engine_ref)
|
| 437 |
-
self.name = "REALITY_FILTER"
|
| 438 |
-
self.TRIGRAMS = TRIGRAM_MAP
|
| 439 |
-
|
| 440 |
-
def run(self, ctx: CycleContext):
|
| 441 |
-
reflection = self.eng.mind.mirror.get_reflection_modifiers()
|
| 442 |
-
ctx.physics.narrative_drag *= reflection["drag_mult"]
|
| 443 |
-
vector = ctx.physics.vector
|
| 444 |
-
if vector:
|
| 445 |
-
dom = max(vector, key=vector.get)
|
| 446 |
-
entry = self.TRIGRAMS.get(dom, self.TRIGRAMS["E"])
|
| 447 |
-
sym, name, _, color = entry
|
| 448 |
-
ctx.world_state["trigram"] = {"symbol": sym, "name": name, "color": color}
|
| 449 |
-
if random.random() < 0.05:
|
| 450 |
-
ctx.log(
|
| 451 |
-
f"{color}I CHING: {sym} {name} is in the ascendant.{Prisma.RST}"
|
| 452 |
-
)
|
| 453 |
-
return ctx
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
class NavigationPhase(SimulationPhase):
|
| 457 |
-
def __init__(self, engine_ref):
|
| 458 |
-
super().__init__(engine_ref)
|
| 459 |
-
self.name = "NAVIGATION"
|
| 460 |
-
|
| 461 |
-
def run(self, ctx: CycleContext):
|
| 462 |
-
physics = ctx.physics
|
| 463 |
-
mode_settings = getattr(self.eng, "mode_settings", {})
|
| 464 |
-
v_floor = mode_settings.get("voltage_floor_override")
|
| 465 |
-
if v_floor is not None:
|
| 466 |
-
physics.voltage = max(physics.voltage, v_floor)
|
| 467 |
-
if v_floor >= 50.0:
|
| 468 |
-
physics.narrative_drag = 0.0
|
| 469 |
-
new_drag, grav_logs = self.eng.phys.dynamics.check_gravity(
|
| 470 |
-
current_drift=physics.narrative_drag, psi=physics.psi
|
| 471 |
-
)
|
| 472 |
-
physics.narrative_drag = new_drag
|
| 473 |
-
for log in grav_logs:
|
| 474 |
-
ctx.log(log)
|
| 475 |
-
if self.eng.gordon:
|
| 476 |
-
phys_snapshot = physics.to_dict()
|
| 477 |
-
reflex_triggered, reflex_msg = self.eng.gordon.emergency_reflex(
|
| 478 |
-
phys_snapshot
|
| 479 |
-
)
|
| 480 |
-
if reflex_triggered:
|
| 481 |
-
for key, val in phys_snapshot.items():
|
| 482 |
-
if hasattr(physics, key):
|
| 483 |
-
current_val = getattr(physics, key)
|
| 484 |
-
if current_val != val:
|
| 485 |
-
if key in ["energy", "space", "matter"]:
|
| 486 |
-
sub_obj = getattr(physics, key)
|
| 487 |
-
if isinstance(val, dict) and sub_obj:
|
| 488 |
-
for sk, sv in val.items():
|
| 489 |
-
if hasattr(sub_obj, sk):
|
| 490 |
-
setattr(sub_obj, sk, sv)
|
| 491 |
-
else:
|
| 492 |
-
setattr(physics, key, val)
|
| 493 |
-
if reflex_msg:
|
| 494 |
-
ctx.log(reflex_msg)
|
| 495 |
-
ctx.record_flux("NAVIGATION", "REFLEX", 1.0, 0.0, "ITEM_TRIGGERED")
|
| 496 |
-
phys_dict = physics.to_dict()
|
| 497 |
-
if self.eng.navigator:
|
| 498 |
-
current_loc, entry_msg = self.eng.navigator.locate(
|
| 499 |
-
packet=ctx.physics,
|
| 500 |
-
)
|
| 501 |
-
if entry_msg:
|
| 502 |
-
ctx.log(entry_msg)
|
| 503 |
-
env_logs = self.eng.navigator.apply_environment(physics)
|
| 504 |
-
for e_log in env_logs:
|
| 505 |
-
ctx.log(e_log)
|
| 506 |
-
if self.eng.gordon and self.eng.tinkerer:
|
| 507 |
-
inv_data = self.eng.gordon.get_inventory_data()
|
| 508 |
-
deltas = self.eng.tinkerer.calculate_passive_deltas(inv_data)
|
| 509 |
-
for delta in deltas:
|
| 510 |
-
if delta.field == "narrative_drag":
|
| 511 |
-
if delta.operator == "ADD":
|
| 512 |
-
physics.narrative_drag += delta.value
|
| 513 |
-
elif delta.operator == "MULT":
|
| 514 |
-
physics.narrative_drag *= delta.value
|
| 515 |
-
ctx.log(
|
| 516 |
-
f"{Prisma.GRY}🎒 GEAR: {delta.source} affects drag ({delta.operator} {delta.value}).{Prisma.RST}"
|
| 517 |
-
)
|
| 518 |
-
orbit_state, drag_pen, orbit_msg = self.eng.cosmic.analyze_orbit(
|
| 519 |
-
self.eng.mind.mem, ctx.clean_words
|
| 520 |
-
)
|
| 521 |
-
if orbit_msg:
|
| 522 |
-
ctx.log(orbit_msg)
|
| 523 |
-
physics.narrative_drag += drag_pen
|
| 524 |
-
if orbit_state == "VOID_DRIFT":
|
| 525 |
-
physics.voltage = max(0.0, physics.voltage - 0.5)
|
| 526 |
-
elif orbit_state == "LAGRANGE_POINT":
|
| 527 |
-
physics.narrative_drag = max(0.1, physics.narrative_drag - 2.0)
|
| 528 |
-
elif orbit_state == "WATERSHED_FLOW":
|
| 529 |
-
physics.voltage += 0.5
|
| 530 |
-
raw_zone = getattr(physics, "zone", "COURTYARD")
|
| 531 |
-
stabilization_result = self.eng.stabilizer.stabilize(
|
| 532 |
-
proposed_zone=raw_zone,
|
| 533 |
-
physics=phys_dict,
|
| 534 |
-
cosmic_state=(orbit_state, drag_pen),
|
| 535 |
-
)
|
| 536 |
-
if isinstance(stabilization_result, tuple):
|
| 537 |
-
stabilized_zone = stabilization_result[0]
|
| 538 |
-
if len(stabilization_result) > 1 and stabilization_result[1]:
|
| 539 |
-
ctx.log(stabilization_result[1])
|
| 540 |
-
else:
|
| 541 |
-
stabilized_zone = stabilization_result
|
| 542 |
-
physics.zone = stabilized_zone
|
| 543 |
-
adjusted_drag = self.eng.stabilizer.override_cosmic_drag(
|
| 544 |
-
drag_pen, stabilized_zone
|
| 545 |
-
)
|
| 546 |
-
if adjusted_drag != drag_pen:
|
| 547 |
-
physics.narrative_drag -= drag_pen - adjusted_drag
|
| 548 |
-
ctx.world_state["orbit"] = orbit_state
|
| 549 |
-
return ctx
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
class MachineryPhase(SimulationPhase):
|
| 553 |
-
def __init__(self, engine_ref):
|
| 554 |
-
super().__init__(engine_ref)
|
| 555 |
-
self.name = "MACHINERY"
|
| 556 |
-
|
| 557 |
-
def run(self, ctx: CycleContext):
|
| 558 |
-
if ctx.is_system_event:
|
| 559 |
-
return ctx
|
| 560 |
-
phys_dict = ctx.physics.to_dict()
|
| 561 |
-
if hasattr(self.eng, "critics") and (
|
| 562 |
-
review := self.eng.critics.audit_performance(phys_dict, self.eng.tick_count)
|
| 563 |
-
):
|
| 564 |
-
ctx.log(review)
|
| 565 |
-
ctx.physics.narrative_drag += -1.0 if "🌟" in review else 1.0
|
| 566 |
-
boost, z_msg = self.eng.zen.raking_the_sand(phys_dict, ctx.bio_result)
|
| 567 |
-
if z_msg:
|
| 568 |
-
ctx.log(z_msg)
|
| 569 |
-
if boost > 0:
|
| 570 |
-
self.eng.bio.mito.state.membrane_potential = min(
|
| 571 |
-
2.0, self.eng.bio.mito.state.efficiency_mod + (boost * 0.1)
|
| 572 |
-
)
|
| 573 |
-
if self.eng.gordon and self.eng.gordon.inventory:
|
| 574 |
-
self._process_crafting(ctx, phys_dict)
|
| 575 |
-
if t_msg := self.eng.phys.forge.transmute(phys_dict):
|
| 576 |
-
ctx.log(t_msg)
|
| 577 |
-
_, f_msg, new_item = self.eng.phys.forge.hammer_alloy(phys_dict)
|
| 578 |
-
if f_msg:
|
| 579 |
-
ctx.log(f_msg)
|
| 580 |
-
if new_item and self.eng.gordon:
|
| 581 |
-
ctx.log(self.eng.gordon.acquire(new_item))
|
| 582 |
-
_, _, t_msg, t_crit = self.eng.phys.theremin.listen(
|
| 583 |
-
phys_dict, self.eng.bio.governor.mode
|
| 584 |
-
)
|
| 585 |
-
if t_msg:
|
| 586 |
-
ctx.log(t_msg)
|
| 587 |
-
if t_crit == "AIRSTRIKE":
|
| 588 |
-
self._handle_theremin_discharge(ctx)
|
| 589 |
-
self.eng.phys.pulse.update(
|
| 590 |
-
getattr(ctx.physics, "repetition", 0.0), ctx.physics.voltage
|
| 591 |
-
)
|
| 592 |
-
c_state, c_val, c_msg = self.eng.phys.crucible.audit_fire(phys_dict)
|
| 593 |
-
if c_msg:
|
| 594 |
-
ctx.log(c_msg)
|
| 595 |
-
if c_state == "MELTDOWN":
|
| 596 |
-
damage = c_val
|
| 597 |
-
if self.eng.bio.biometrics:
|
| 598 |
-
self.eng.bio.biometrics.health = max(
|
| 599 |
-
0.0, self.eng.bio.biometrics.health - damage
|
| 600 |
-
)
|
| 601 |
-
self.eng.health = max(0.0, self.eng.health - damage)
|
| 602 |
-
|
| 603 |
-
for k, v in phys_dict.items():
|
| 604 |
-
if hasattr(ctx.physics, k) and not callable(getattr(ctx.physics, k)):
|
| 605 |
-
try:
|
| 606 |
-
if k in ["energy", "space", "matter"]:
|
| 607 |
-
sub_obj = getattr(ctx.physics, k)
|
| 608 |
-
if isinstance(v, dict) and sub_obj:
|
| 609 |
-
for sk, sv in v.items():
|
| 610 |
-
if hasattr(sub_obj, sk):
|
| 611 |
-
setattr(sub_obj, sk, sv)
|
| 612 |
-
else:
|
| 613 |
-
setattr(ctx.physics, k, v)
|
| 614 |
-
except AttributeError:
|
| 615 |
-
pass
|
| 616 |
-
return ctx
|
| 617 |
-
|
| 618 |
-
def _process_crafting(self, ctx, phys_dict):
|
| 619 |
-
is_craft, craft_msg, old_item, new_item = self.eng.phys.forge.attempt_crafting(
|
| 620 |
-
phys_dict, self.eng.gordon.inventory
|
| 621 |
-
)
|
| 622 |
-
if is_craft:
|
| 623 |
-
ctx.log(craft_msg)
|
| 624 |
-
vec = ctx.physics.vector
|
| 625 |
-
catalyst_cat = max(vec, key=vec.get) if vec else "void"
|
| 626 |
-
self.eng.events.publish(
|
| 627 |
-
"FORGE_SUCCESS",
|
| 628 |
-
{"ingredient": old_item, "catalyst": catalyst_cat, "result": new_item},
|
| 629 |
-
)
|
| 630 |
-
if old_item in self.eng.gordon.inventory:
|
| 631 |
-
self.eng.gordon.inventory.remove(old_item)
|
| 632 |
-
ctx.log(self.eng.gordon.acquire(new_item))
|
| 633 |
-
|
| 634 |
-
def _handle_theremin_discharge(self, ctx):
|
| 635 |
-
max_hp = getattr(BoneConfig, "MAX_HEALTH", 100.0)
|
| 636 |
-
damage = max_hp * 0.25
|
| 637 |
-
if self.eng.bio.biometrics:
|
| 638 |
-
self.eng.bio.biometrics.health = max(
|
| 639 |
-
0.0, self.eng.bio.biometrics.health - damage
|
| 640 |
-
)
|
| 641 |
-
self.eng.health = max(0.0, self.eng.health - damage)
|
| 642 |
-
ctx.log(
|
| 643 |
-
f"{Prisma.RED}*** CRITICAL THEREMIN DISCHARGE *** -{damage:.1f} HP{Prisma.RST}"
|
| 644 |
-
)
|
| 645 |
-
if hasattr(self.eng.events, "publish"):
|
| 646 |
-
self.eng.events.publish(
|
| 647 |
-
"AIRSTRIKE", {"damage": damage, "source": "THEREMIN"}
|
| 648 |
-
)
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
class IntrusionPhase(SimulationPhase):
|
| 652 |
-
def __init__(self, engine_ref):
|
| 653 |
-
super().__init__(engine_ref)
|
| 654 |
-
self.name = "INTRUSION"
|
| 655 |
-
|
| 656 |
-
def run(self, ctx: CycleContext):
|
| 657 |
-
phys_data = ctx.physics.to_dict()
|
| 658 |
-
p_active, p_log = self.eng.bio.parasite.infect(phys_data, self.eng.stamina)
|
| 659 |
-
if p_active:
|
| 660 |
-
ctx.log(p_log)
|
| 661 |
-
if self.eng.limbo.ghosts:
|
| 662 |
-
if ctx.logs:
|
| 663 |
-
ctx.logs[-1] = self.eng.limbo.haunt(ctx.logs[-1])
|
| 664 |
-
else:
|
| 665 |
-
ctx.log(self.eng.limbo.haunt("The air is heavy."))
|
| 666 |
-
|
| 667 |
-
drag = getattr(ctx.physics, "narrative_drag", 0.0)
|
| 668 |
-
kappa = getattr(ctx.physics, "kappa", 1.0)
|
| 669 |
-
|
| 670 |
-
if (drag > 4.0 or kappa < 0.3) and ctx.clean_words:
|
| 671 |
-
start_node = random.choice(ctx.clean_words)
|
| 672 |
-
loop_path = self.eng.mind.tracer.inject(start_node)
|
| 673 |
-
if loop_path:
|
| 674 |
-
rewire_msg = self.eng.mind.tracer.psilocybin_rewire(loop_path)
|
| 675 |
-
if rewire_msg:
|
| 676 |
-
ctx.log(f"{Prisma.CYN}🦠 IMMUNE SYSTEM: {rewire_msg}{Prisma.RST}")
|
| 677 |
-
self.eng.bio.endo.dopamine += 0.2
|
| 678 |
-
ctx.physics.narrative_drag = max(0.0, drag - 2.0)
|
| 679 |
-
trauma_sum = (
|
| 680 |
-
sum(self.eng.trauma_accum.values())
|
| 681 |
-
if getattr(self.eng, "trauma_accum", None)
|
| 682 |
-
else 0.0
|
| 683 |
-
)
|
| 684 |
-
is_bored = self.eng.phys.pulse.is_bored()
|
| 685 |
-
if (trauma_sum > 10.0 or is_bored) and random.random() < 0.2:
|
| 686 |
-
dream_text, relief = self.eng.mind.dreamer.hallucinate(
|
| 687 |
-
ctx.physics.vector, trauma_level=trauma_sum
|
| 688 |
-
)
|
| 689 |
-
prefix = "💭 NIGHTMARE" if trauma_sum > 10.0 else "💭 DAYDREAM"
|
| 690 |
-
ctx.log(f"{Prisma.VIOLET}{prefix}: {dream_text}{Prisma.RST}")
|
| 691 |
-
if relief > 0:
|
| 692 |
-
keys = list(self.eng.trauma_accum.keys())
|
| 693 |
-
if keys:
|
| 694 |
-
target = random.choice(keys)
|
| 695 |
-
self.eng.trauma_accum[target] = max(
|
| 696 |
-
0.0, self.eng.trauma_accum[target] - relief
|
| 697 |
-
)
|
| 698 |
-
ctx.log(
|
| 699 |
-
f" {Prisma.GRY}(Psychic pressure released: -{relief:.1f} {target}){Prisma.RST}"
|
| 700 |
-
)
|
| 701 |
-
if is_bored:
|
| 702 |
-
self.eng.phys.pulse.boredom_level = 0.0
|
| 703 |
-
current_psi = getattr(ctx.physics, "psi", 0.0)
|
| 704 |
-
if current_psi > 0.6 and random.random() < current_psi:
|
| 705 |
-
p_msg = f"{Prisma.VIOLET}👁️ PAREIDOLIA: The patterns are watching back (PSI {current_psi:.2f}).{Prisma.RST}"
|
| 706 |
-
ctx.log(p_msg)
|
| 707 |
-
ctx.physics.psi = min(1.0, current_psi + 0.1)
|
| 708 |
-
if self.eng.bio and self.eng.bio.biometrics:
|
| 709 |
-
self.eng.bio.biometrics.stamina = max(
|
| 710 |
-
0.0, self.eng.bio.biometrics.stamina - 5.0
|
| 711 |
-
)
|
| 712 |
-
ctx.log(
|
| 713 |
-
f"{Prisma.GRY} (The hallucination drains 5.0 Stamina){Prisma.RST}"
|
| 714 |
-
)
|
| 715 |
-
return ctx
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
class SoulPhase(SimulationPhase):
|
| 719 |
-
def __init__(self, engine_ref):
|
| 720 |
-
super().__init__(engine_ref)
|
| 721 |
-
self.name = "SOUL"
|
| 722 |
-
|
| 723 |
-
def run(self, ctx: CycleContext):
|
| 724 |
-
if ctx.is_system_event:
|
| 725 |
-
return ctx
|
| 726 |
-
if not hasattr(self.eng, "soul") or not self.eng.soul:
|
| 727 |
-
return ctx
|
| 728 |
-
dignity = self.eng.soul.anchor.dignity_reserve
|
| 729 |
-
if dignity < 30.0:
|
| 730 |
-
ctx.physics.narrative_drag *= 1.5
|
| 731 |
-
ctx.log(
|
| 732 |
-
f"{Prisma.GRY}⚓ DIGNITY CRITICAL: The narrative feels heavy. (Drag x1.5){Prisma.RST}"
|
| 733 |
-
)
|
| 734 |
-
elif dignity > 80.0:
|
| 735 |
-
ctx.physics.voltage += 2.0
|
| 736 |
-
ctx.physics.narrative_drag *= 0.8
|
| 737 |
-
ctx.log(
|
| 738 |
-
f"{Prisma.MAG}✨ DIGNITY HIGH: The soul is sovereign. (Flow Optimized){Prisma.RST}"
|
| 739 |
-
)
|
| 740 |
-
lesson = self.eng.soul.crystallize_memory(
|
| 741 |
-
ctx.physics.to_dict(), ctx.bio_result, self.eng.tick_count
|
| 742 |
-
)
|
| 743 |
-
if lesson:
|
| 744 |
-
ctx.log(
|
| 745 |
-
f"{Prisma.VIOLET} (The lesson '{lesson}' echoes in the chamber.){Prisma.RST}"
|
| 746 |
-
)
|
| 747 |
-
if not self.eng.soul.current_obsession:
|
| 748 |
-
self.eng.soul.find_obsession(self.eng.lex)
|
| 749 |
-
self.eng.soul.pursue_obsession(ctx.physics.to_dict())
|
| 750 |
-
if hasattr(self.eng, "oroboros") and self.eng.oroboros.myths:
|
| 751 |
-
for myth in self.eng.oroboros.myths:
|
| 752 |
-
if myth.trigger in ctx.clean_words:
|
| 753 |
-
ctx.log(
|
| 754 |
-
f"{Prisma.YEL}📜 ANCIENT MYTH INVOKED: {myth.title}{Prisma.RST}"
|
| 755 |
-
)
|
| 756 |
-
ctx.log(f' "{myth.lesson}"')
|
| 757 |
-
old_volts = ctx.physics.voltage
|
| 758 |
-
ctx.physics.voltage += 5.0
|
| 759 |
-
ctx.record_flux(
|
| 760 |
-
"SOUL", "VOLTAGE", old_volts, ctx.physics.voltage, "MYTH_BUFF"
|
| 761 |
-
)
|
| 762 |
-
if self.eng.bio.biometrics:
|
| 763 |
-
self.eng.bio.biometrics.stamina = min(
|
| 764 |
-
100.0, self.eng.bio.biometrics.stamina + 5.0
|
| 765 |
-
)
|
| 766 |
-
if self.eng.gordon and self.eng.tinkerer:
|
| 767 |
-
if self.eng.gordon.inventory:
|
| 768 |
-
self.eng.tinkerer.audit_tool_use(ctx.physics, self.eng.gordon.inventory)
|
| 769 |
-
council_mandates = self._consult_council(self.eng.soul.traits)
|
| 770 |
-
if council_mandates:
|
| 771 |
-
ctx.council_mandates = (
|
| 772 |
-
getattr(ctx, "council_mandates", []) + council_mandates
|
| 773 |
-
)
|
| 774 |
-
for mandate in council_mandates:
|
| 775 |
-
ctx.log(mandate["log"])
|
| 776 |
-
self._execute_mandate(ctx, mandate)
|
| 777 |
-
council_advice, adjustments, mandates = self.eng.council.convene(
|
| 778 |
-
ctx.input_text, ctx.physics.to_dict(), ctx.bio_result
|
| 779 |
-
)
|
| 780 |
-
if mandates:
|
| 781 |
-
if not hasattr(ctx, "council_mandates"):
|
| 782 |
-
ctx.council_mandates = []
|
| 783 |
-
ctx.council_mandates.extend(mandates)
|
| 784 |
-
for advice in council_advice:
|
| 785 |
-
ctx.log(advice)
|
| 786 |
-
for mandate in mandates:
|
| 787 |
-
action = mandate.get("action")
|
| 788 |
-
if action == "FORCE_MODE":
|
| 789 |
-
target = mandate["value"]
|
| 790 |
-
self.eng.bio.governor.set_override(target)
|
| 791 |
-
ctx.log(
|
| 792 |
-
f"{Prisma.RED}⚖️ COUNCIL ORDER: Emergency Shift to {target}.{Prisma.RST}"
|
| 793 |
-
)
|
| 794 |
-
elif action == "CIRCUIT_BREAKER":
|
| 795 |
-
ctx.physics.voltage = 0.0
|
| 796 |
-
ctx.physics.narrative_drag = 10.0
|
| 797 |
-
ctx.log(
|
| 798 |
-
f"{Prisma.RED}⚖️ COUNCIL ORDER: Circuit Breaker Tripped. Voltage dump.{Prisma.RST}"
|
| 799 |
-
)
|
| 800 |
-
if adjustments:
|
| 801 |
-
for param, delta in adjustments.items():
|
| 802 |
-
old_val = getattr(ctx.physics, param, 0.0)
|
| 803 |
-
new_val = old_val + delta
|
| 804 |
-
setattr(ctx.physics, param, new_val)
|
| 805 |
-
ctx.record_flux(
|
| 806 |
-
"SIMULATION", param, old_val, new_val, "COUNCIL_MANDATE"
|
| 807 |
-
)
|
| 808 |
-
return ctx
|
| 809 |
-
|
| 810 |
-
@staticmethod
|
| 811 |
-
def _consult_council(traits: Any) -> List[Dict]:
|
| 812 |
-
t_map = (
|
| 813 |
-
traits.to_dict()
|
| 814 |
-
if hasattr(traits, "to_dict")
|
| 815 |
-
else (traits.__dict__ if hasattr(traits, "__dict__") else traits)
|
| 816 |
-
)
|
| 817 |
-
get_t = lambda k: t_map.get(k, t_map.get(k.lower(), 0.0))
|
| 818 |
-
rules = [
|
| 819 |
-
(
|
| 820 |
-
"CYNICISM",
|
| 821 |
-
0.8,
|
| 822 |
-
"LOCKDOWN",
|
| 823 |
-
"The Cynic holds the gavel. 'Stop doing things.'",
|
| 824 |
-
{"narrative_drag": 5.0, "voltage": -5.0},
|
| 825 |
-
Prisma.OCHRE,
|
| 826 |
-
),
|
| 827 |
-
(
|
| 828 |
-
"HOPE",
|
| 829 |
-
0.8,
|
| 830 |
-
"STIMULUS",
|
| 831 |
-
"The Optimist filibustered. 'We can build it!'",
|
| 832 |
-
{"voltage": 5.0, "narrative_drag": -2.0},
|
| 833 |
-
Prisma.MAG,
|
| 834 |
-
),
|
| 835 |
-
(
|
| 836 |
-
"DISCIPLINE",
|
| 837 |
-
0.8,
|
| 838 |
-
"STANDARDIZE",
|
| 839 |
-
"The Engineer demands efficiency.",
|
| 840 |
-
{"kappa": -0.5, "beta_index": 1.0},
|
| 841 |
-
Prisma.CYN,
|
| 842 |
-
),
|
| 843 |
-
]
|
| 844 |
-
mandates = []
|
| 845 |
-
for trait, thresh, m_type, msg, eff, col in rules:
|
| 846 |
-
if get_t(trait) > thresh:
|
| 847 |
-
mandates.append(
|
| 848 |
-
{
|
| 849 |
-
"type": m_type,
|
| 850 |
-
"log": f"{col}⚖️ COUNCIL: {msg}{Prisma.RST}",
|
| 851 |
-
"effect": eff,
|
| 852 |
-
}
|
| 853 |
-
)
|
| 854 |
-
return mandates
|
| 855 |
-
|
| 856 |
-
@staticmethod
|
| 857 |
-
def _execute_mandate(ctx: CycleContext, mandate: Dict):
|
| 858 |
-
effects = mandate.get("effect", {})
|
| 859 |
-
for key, delta in effects.items():
|
| 860 |
-
current = getattr(ctx.physics, key, 0.0)
|
| 861 |
-
setattr(ctx.physics, key, max(0.0, current + delta))
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
class ArbitrationPhase(SimulationPhase):
|
| 865 |
-
def __init__(self, engine_ref):
|
| 866 |
-
super().__init__(engine_ref)
|
| 867 |
-
self.name = "ARBITRATION"
|
| 868 |
-
if not hasattr(self.eng, "arbiter"):
|
| 869 |
-
self.eng.arbiter = ArchetypeArbiter()
|
| 870 |
-
|
| 871 |
-
def run(self, ctx: CycleContext):
|
| 872 |
-
phys_lens, _, _ = self.eng.drivers.enneagram.decide_persona(
|
| 873 |
-
ctx.physics, soul_ref=self.eng.soul
|
| 874 |
-
)
|
| 875 |
-
soul_arch = self.eng.soul.archetype
|
| 876 |
-
mandates = getattr(ctx, "council_mandates", [])
|
| 877 |
-
current_trigram = ctx.world_state.get("trigram", None)
|
| 878 |
-
final_lens, source, opinion = self.eng.arbiter.arbitrate(
|
| 879 |
-
physics_lens=phys_lens,
|
| 880 |
-
soul_archetype=soul_arch,
|
| 881 |
-
council_mandates=mandates,
|
| 882 |
-
trigram=current_trigram,
|
| 883 |
-
)
|
| 884 |
-
ctx.active_lens = final_lens
|
| 885 |
-
self.eng.events.publish("LENS_INTERACTION", {"lenses": [phys_lens, soul_arch]})
|
| 886 |
-
if source != "PHYSICS_VECTOR":
|
| 887 |
-
ctx.log(f"{Prisma.MAG}⚖️ {opinion}{Prisma.RST}")
|
| 888 |
-
self.eng.drivers.current_focus = final_lens
|
| 889 |
-
return ctx
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
class CognitionPhase(SimulationPhase):
|
| 893 |
-
def __init__(self, engine_ref):
|
| 894 |
-
super().__init__(engine_ref)
|
| 895 |
-
self.name = "COGNITION"
|
| 896 |
-
|
| 897 |
-
def run(self, ctx: CycleContext):
|
| 898 |
-
if ctx.validator and ctx.input_text:
|
| 899 |
-
phi = ctx.validator.calculate_resonance(ctx.input_text, ctx)
|
| 900 |
-
if phi > 0.8:
|
| 901 |
-
drag_relief = (phi - 0.5) * 2.0
|
| 902 |
-
ctx.physics.narrative_drag = max(
|
| 903 |
-
0.0, ctx.physics.narrative_drag - drag_relief
|
| 904 |
-
)
|
| 905 |
-
if self.eng.bio and self.eng.bio.mito:
|
| 906 |
-
refund = 5.0 * phi
|
| 907 |
-
self.eng.bio.mito.adjust_atp(refund, "Harmonic Resonance")
|
| 908 |
-
ctx.log(
|
| 909 |
-
f"{Prisma.CYN}✨ HARMONIC RESONANCE (Φ={phi:.2f}): The narrative flows effortlessly.{Prisma.RST}"
|
| 910 |
-
)
|
| 911 |
-
if hasattr(self.eng, "consultant"):
|
| 912 |
-
self.eng.consultant.update_coordinates(
|
| 913 |
-
ctx.input_text, ctx.bio_result, ctx.physics
|
| 914 |
-
)
|
| 915 |
-
if (
|
| 916 |
-
"LIMINAL" in self.eng.consultant.state.active_modules
|
| 917 |
-
and self.eng.bio
|
| 918 |
-
and self.eng.bio.mito
|
| 919 |
-
):
|
| 920 |
-
lambda_val = self.eng.consultant.state.L
|
| 921 |
-
if lambda_val > 0.1:
|
| 922 |
-
lambda_tax = (lambda_val**2) * 10.0
|
| 923 |
-
self.eng.bio.mito.adjust_atp(-lambda_tax, f"Λ² Liminal Tax")
|
| 924 |
-
if lambda_tax > 2.0:
|
| 925 |
-
ctx.log(
|
| 926 |
-
f"{Prisma.VIOLET}🌌 DARK MATTER: Liminal navigation burns {lambda_tax:.1f} ATP.{Prisma.RST}"
|
| 927 |
-
)
|
| 928 |
-
if hasattr(self.eng.mind.mem, "check_for_resurrection"):
|
| 929 |
-
flashback_msg = self.eng.mind.mem.check_for_resurrection(
|
| 930 |
-
ctx.clean_words, ctx.physics.voltage
|
| 931 |
-
)
|
| 932 |
-
if flashback_msg:
|
| 933 |
-
ctx.log(f"{Prisma.MAG}{flashback_msg}{Prisma.RST}")
|
| 934 |
-
shock_cost = 5.0
|
| 935 |
-
if self.eng.bio.biometrics:
|
| 936 |
-
self.eng.bio.biometrics.stamina = max(
|
| 937 |
-
0.0, self.eng.bio.biometrics.stamina - shock_cost
|
| 938 |
-
)
|
| 939 |
-
self.eng.stamina = max(0.0, self.eng.stamina - shock_cost)
|
| 940 |
-
self.eng.mind.mem.encode(ctx.clean_words, ctx.physics.to_dict(), "GEODESIC")
|
| 941 |
-
if ctx.is_alive and ctx.clean_words:
|
| 942 |
-
max_h = getattr(BoneConfig, "MAX_HEALTH", 100.0)
|
| 943 |
-
current_h = max(0.0, self.eng.health)
|
| 944 |
-
if self.eng.bio.biometrics:
|
| 945 |
-
current_h = max(0.0, self.eng.bio.biometrics.health)
|
| 946 |
-
desperation = 1.0 - (current_h / max_h)
|
| 947 |
-
learn_mod = getattr(BoneConfig, "PRIORITY_LEARNING_RATE", 1.0)
|
| 948 |
-
bury_msg, new_wells = self.eng.mind.mem.bury(
|
| 949 |
-
ctx.clean_words,
|
| 950 |
-
self.eng.tick_count,
|
| 951 |
-
resonance=ctx.physics.voltage,
|
| 952 |
-
desperation_level=desperation,
|
| 953 |
-
learning_mod=learn_mod,
|
| 954 |
-
)
|
| 955 |
-
if bury_msg:
|
| 956 |
-
prefix = (
|
| 957 |
-
f"{Prisma.YEL}⚠️ MEMORY:{Prisma.RST}"
|
| 958 |
-
if "SATURATION" in bury_msg
|
| 959 |
-
else f"{Prisma.RED}🍖 DONNER PROTOCOL:{Prisma.RST}"
|
| 960 |
-
)
|
| 961 |
-
ctx.log(f"{prefix} {bury_msg}")
|
| 962 |
-
if new_wells:
|
| 963 |
-
ctx.log(f"{Prisma.CYN}🌌 GRAVITY WELL FORMED: {new_wells}{Prisma.RST}")
|
| 964 |
-
|
| 965 |
-
inventory_data = self.eng.gordon.inventory if self.eng.gordon else []
|
| 966 |
-
|
| 967 |
-
ctx.mind_state = self.eng.noetic.think(
|
| 968 |
-
physics_packet=ctx.physics.to_dict(),
|
| 969 |
-
_bio=ctx.bio_result,
|
| 970 |
-
_inventory=inventory_data,
|
| 971 |
-
voltage_history=self.eng.phys.dynamics.voltage_history,
|
| 972 |
-
_tick_count=self.eng.tick_count,
|
| 973 |
-
soul_ref=self.eng.soul,
|
| 974 |
-
)
|
| 975 |
-
|
| 976 |
-
thought = ctx.mind_state.get("context_msg", ctx.mind_state.get("thought"))
|
| 977 |
-
if thought:
|
| 978 |
-
ctx.log(thought)
|
| 979 |
-
return ctx
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
class SensationPhase(SimulationPhase):
|
| 983 |
-
def __init__(self, engine_ref):
|
| 984 |
-
super().__init__(engine_ref)
|
| 985 |
-
self.name = "SENSATION"
|
| 986 |
-
if hasattr(self.eng, "somatic"):
|
| 987 |
-
self.synesthesia = self.eng.somatic
|
| 988 |
-
else:
|
| 989 |
-
self.synesthesia = SynestheticCortex(self.eng.bio)
|
| 990 |
-
self.eng.somatic = self.synesthesia
|
| 991 |
-
|
| 992 |
-
def run(self, ctx: CycleContext):
|
| 993 |
-
phys_data = ctx.physics.to_dict()
|
| 994 |
-
current_latency = 0.0
|
| 995 |
-
if hasattr(self.eng, "host_stats"):
|
| 996 |
-
current_latency = self.eng.host_stats.latency
|
| 997 |
-
impulse = self.synesthesia.perceive(
|
| 998 |
-
phys_data, traits=self.eng.soul.traits, latency=current_latency
|
| 999 |
-
)
|
| 1000 |
-
ctx.last_impulse = impulse
|
| 1001 |
-
qualia = self.synesthesia.get_current_qualia(impulse)
|
| 1002 |
-
ctx.physics = apply_somatic_feedback(ctx.physics, qualia)
|
| 1003 |
-
self.synesthesia.apply_impulse(impulse)
|
| 1004 |
-
if impulse.stamina_impact != 0:
|
| 1005 |
-
max_s = getattr(BoneConfig, "MAX_STAMINA", 100.0)
|
| 1006 |
-
if self.eng.bio.biometrics:
|
| 1007 |
-
self.eng.bio.biometrics.stamina = max(
|
| 1008 |
-
0.0,
|
| 1009 |
-
min(
|
| 1010 |
-
max_s, self.eng.bio.biometrics.stamina + impulse.stamina_impact
|
| 1011 |
-
),
|
| 1012 |
-
)
|
| 1013 |
-
self.eng.stamina = max(
|
| 1014 |
-
0.0, min(max_s, self.eng.stamina + impulse.stamina_impact)
|
| 1015 |
-
)
|
| 1016 |
-
return ctx
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
class StabilizationPhase(SimulationPhase):
|
| 1020 |
-
def __init__(self, engine_ref, stabilizer_ref):
|
| 1021 |
-
super().__init__(engine_ref)
|
| 1022 |
-
self.name = "STABILIZATION"
|
| 1023 |
-
self.stabilizer = stabilizer_ref
|
| 1024 |
-
|
| 1025 |
-
def run(self, ctx: CycleContext):
|
| 1026 |
-
self.stabilizer.stabilize(ctx, self.name)
|
| 1027 |
-
return ctx
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
class PhaseExecutor:
|
| 1031 |
-
def execute_phases(self, simulator, ctx):
|
| 1032 |
-
for phase in simulator.pipeline:
|
| 1033 |
-
if getattr(ctx, "refusal_triggered", False):
|
| 1034 |
-
break
|
| 1035 |
-
if not simulator.check_circuit_breaker(phase.name):
|
| 1036 |
-
continue
|
| 1037 |
-
snapshot_before = ctx.physics.snapshot()
|
| 1038 |
-
try:
|
| 1039 |
-
phase.run(ctx)
|
| 1040 |
-
except Exception as e:
|
| 1041 |
-
simulator.handle_phase_crash(ctx, phase.name, e)
|
| 1042 |
-
self._audit_flux(ctx, phase.name, snapshot_before, ctx.physics)
|
| 1043 |
-
break
|
| 1044 |
-
self._audit_flux(ctx, phase.name, snapshot_before, ctx.physics)
|
| 1045 |
-
return ctx
|
| 1046 |
-
|
| 1047 |
-
@staticmethod
|
| 1048 |
-
def _audit_flux(ctx, phase, before, after):
|
| 1049 |
-
def _safe_get(obj, key):
|
| 1050 |
-
try:
|
| 1051 |
-
if isinstance(obj, dict):
|
| 1052 |
-
return obj.get(key, 0.0)
|
| 1053 |
-
return getattr(obj, key, 0.0)
|
| 1054 |
-
except Exception:
|
| 1055 |
-
return 0.0
|
| 1056 |
-
|
| 1057 |
-
b_v = _safe_get(before, "voltage")
|
| 1058 |
-
a_v = _safe_get(after, "voltage")
|
| 1059 |
-
b_d = _safe_get(before, "narrative_drag")
|
| 1060 |
-
a_d = _safe_get(after, "narrative_drag")
|
| 1061 |
-
if abs(b_v - a_v) > 0.01:
|
| 1062 |
-
ctx.record_flux(phase, "voltage", b_v, a_v, "PHASE_DELTA")
|
| 1063 |
-
if abs(b_d - a_d) > 0.01:
|
| 1064 |
-
ctx.record_flux(phase, "drag", b_d, a_d, "PHASE_DELTA")
|
| 1065 |
-
|
| 1066 |
-
|
| 1067 |
-
class CycleSimulator:
|
| 1068 |
-
def __init__(self, engine_ref):
|
| 1069 |
-
self.eng = engine_ref
|
| 1070 |
-
self.shared_governor = self.eng.bio.governor
|
| 1071 |
-
self.stabilizer = CycleStabilizer(self.eng.events, self.shared_governor)
|
| 1072 |
-
self.executor = PhaseExecutor()
|
| 1073 |
-
self.pipeline: List[SimulationPhase] = [
|
| 1074 |
-
ObservationPhase(engine_ref),
|
| 1075 |
-
MaintenancePhase(engine_ref),
|
| 1076 |
-
SensationPhase(engine_ref),
|
| 1077 |
-
GatekeeperPhase(engine_ref),
|
| 1078 |
-
SanctuaryPhase(engine_ref, self.shared_governor),
|
| 1079 |
-
MetabolismPhase(engine_ref),
|
| 1080 |
-
NavigationPhase(engine_ref),
|
| 1081 |
-
MachineryPhase(engine_ref),
|
| 1082 |
-
RealityFilterPhase(engine_ref),
|
| 1083 |
-
IntrusionPhase(engine_ref),
|
| 1084 |
-
SoulPhase(engine_ref),
|
| 1085 |
-
ArbitrationPhase(engine_ref),
|
| 1086 |
-
CognitionPhase(engine_ref),
|
| 1087 |
-
StabilizationPhase(engine_ref, self.stabilizer),
|
| 1088 |
-
]
|
| 1089 |
-
|
| 1090 |
-
def run_simulation(self, ctx: CycleContext) -> CycleContext:
|
| 1091 |
-
ctx = self.executor.execute_phases(self, ctx)
|
| 1092 |
-
return ctx
|
| 1093 |
-
|
| 1094 |
-
def check_circuit_breaker(self, phase_name: str) -> bool:
|
| 1095 |
-
health = self.eng.system_health
|
| 1096 |
-
if phase_name == "OBSERVE" and not health.physics_online:
|
| 1097 |
-
return False
|
| 1098 |
-
if phase_name == "METABOLISM" and not health.bio_online:
|
| 1099 |
-
return False
|
| 1100 |
-
if phase_name == "COGNITION" and not health.mind_online:
|
| 1101 |
-
return False
|
| 1102 |
-
return True
|
| 1103 |
-
|
| 1104 |
-
def handle_phase_crash(self, ctx, phase_name, error):
|
| 1105 |
-
print(f"\n{Prisma.RED}!!! CRITICAL {phase_name} CRASH !!!{Prisma.RST}")
|
| 1106 |
-
traceback.print_exc()
|
| 1107 |
-
narrative = LoreManifest.get_instance().get("narrative_data") or {}
|
| 1108 |
-
cathedral_logs = narrative.get("CATHEDRAL_COLLAPSE_LOGS", ["System Failure."])
|
| 1109 |
-
eulogy = random.choice(cathedral_logs)
|
| 1110 |
-
ctx.log(f'{Prisma.RED}🏛️ CATHEDRAL COLLAPSE: "{eulogy}"{Prisma.RST}')
|
| 1111 |
-
component_map = {"OBSERVE": "PHYSICS", "METABOLISM": "BIO", "COGNITION": "MIND"}
|
| 1112 |
-
comp = component_map.get(phase_name, "SIMULATION")
|
| 1113 |
-
self.eng.system_health.report_failure(comp, error)
|
| 1114 |
-
if comp == "PHYSICS":
|
| 1115 |
-
ctx.physics = PanicRoom.get_safe_physics()
|
| 1116 |
-
elif comp == "BIO":
|
| 1117 |
-
ctx.bio_result = PanicRoom.get_safe_bio()
|
| 1118 |
-
ctx.is_alive = True
|
| 1119 |
-
elif comp == "MIND":
|
| 1120 |
-
ctx.mind_state = PanicRoom.get_safe_mind()
|
| 1121 |
-
ctx.log(
|
| 1122 |
-
f"{Prisma.RED}⚠ {phase_name} FAILURE: Switching to Panic Protocol.{Prisma.RST}"
|
| 1123 |
-
)
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
class GeodesicOrchestrator:
|
| 1127 |
-
def __init__(self, engine_ref):
|
| 1128 |
-
self.eng = engine_ref
|
| 1129 |
-
self.simulator = CycleSimulator(engine_ref)
|
| 1130 |
-
self.reporter = CycleReporter(engine_ref)
|
| 1131 |
-
if hasattr(self.eng, "symbiosis"):
|
| 1132 |
-
self.symbiosis = self.eng.symbiosis
|
| 1133 |
-
else:
|
| 1134 |
-
self.symbiosis = SymbiosisManager(self.eng.events)
|
| 1135 |
-
|
| 1136 |
-
def _execute_core_cycle(
|
| 1137 |
-
self, user_message: str, is_system: bool = False
|
| 1138 |
-
) -> CycleContext:
|
| 1139 |
-
cycle_id = str(uuid.uuid4())[:8]
|
| 1140 |
-
try:
|
| 1141 |
-
ctx = CycleContext(input_text=user_message, is_system_event=is_system)
|
| 1142 |
-
ctx.trace_id = cycle_id
|
| 1143 |
-
if (
|
| 1144 |
-
self.eng.phys
|
| 1145 |
-
and hasattr(self.eng.phys, "observer")
|
| 1146 |
-
and self.eng.phys.observer.last_physics_packet
|
| 1147 |
-
):
|
| 1148 |
-
ctx.physics = self.eng.phys.observer.last_physics_packet.snapshot()
|
| 1149 |
-
elif not ctx.physics:
|
| 1150 |
-
ctx.physics = PanicRoom.get_safe_physics()
|
| 1151 |
-
self.eng.events.log(
|
| 1152 |
-
"⚠️ PHYSICS BYPASS: Running on Panic Protocol.", "SYS"
|
| 1153 |
-
)
|
| 1154 |
-
ctx.validator = CongruenceValidator()
|
| 1155 |
-
ctx.reality_stack = getattr(self.eng, "reality_stack", None)
|
| 1156 |
-
ctx.user_name = self.eng.user_name
|
| 1157 |
-
ctx.council_mandates = []
|
| 1158 |
-
ctx.timestamp = time.time()
|
| 1159 |
-
self.eng.events.flush()
|
| 1160 |
-
ctx = self.simulator.run_simulation(ctx)
|
| 1161 |
-
if self.eng.phys and hasattr(self.eng.phys, "observer"):
|
| 1162 |
-
self.eng.phys.observer.last_physics_packet = ctx.physics.snapshot()
|
| 1163 |
-
return ctx
|
| 1164 |
-
except Exception as e:
|
| 1165 |
-
self.eng.events.log(f"CYCLE CRASH: {e}", "CRIT")
|
| 1166 |
-
ctx = CycleContext(input_text=user_message)
|
| 1167 |
-
ctx.is_alive = False
|
| 1168 |
-
ctx.crash_error = e
|
| 1169 |
-
return ctx
|
| 1170 |
-
|
| 1171 |
-
def run_turn(self, user_message: str, is_system: bool = False) -> Dict[str, Any]:
|
| 1172 |
-
ctx = self._execute_core_cycle(user_message, is_system)
|
| 1173 |
-
if not ctx.is_alive:
|
| 1174 |
-
if hasattr(ctx, "crash_error"):
|
| 1175 |
-
return self._generate_crash_report(ctx.crash_error)
|
| 1176 |
-
return self.eng.trigger_death(ctx.physics)
|
| 1177 |
-
|
| 1178 |
-
if getattr(ctx, "refusal_triggered", False) and getattr(
|
| 1179 |
-
ctx, "refusal_packet", None
|
| 1180 |
-
):
|
| 1181 |
-
return ctx.refusal_packet
|
| 1182 |
-
|
| 1183 |
-
snapshot = self.reporter.render_snapshot(ctx)
|
| 1184 |
-
self._hydrate_snapshot_metadata(snapshot, ctx)
|
| 1185 |
-
latency = time.time() - ctx.timestamp
|
| 1186 |
-
if "ui" in snapshot:
|
| 1187 |
-
self.symbiosis.monitor_host(latency, snapshot["ui"], len(user_message))
|
| 1188 |
-
return snapshot
|
| 1189 |
-
|
| 1190 |
-
def run_headless_turn(
|
| 1191 |
-
self, user_message: str, latency: float = 0.0
|
| 1192 |
-
) -> Dict[str, Any]:
|
| 1193 |
-
ctx = self._execute_core_cycle(user_message)
|
| 1194 |
-
if not ctx.is_alive:
|
| 1195 |
-
if hasattr(ctx, "crash_error"):
|
| 1196 |
-
return self._generate_crash_report(ctx.crash_error)
|
| 1197 |
-
return self.eng.trigger_death(ctx.physics)
|
| 1198 |
-
|
| 1199 |
-
if getattr(ctx, "refusal_triggered", False) and getattr(
|
| 1200 |
-
ctx, "refusal_packet", None
|
| 1201 |
-
):
|
| 1202 |
-
return ctx.refusal_packet
|
| 1203 |
-
|
| 1204 |
-
snapshot = {"type": "HEADLESS", "logs": ctx.logs}
|
| 1205 |
-
self._hydrate_snapshot_metadata(snapshot, ctx)
|
| 1206 |
-
self.symbiosis.monitor_host(latency, "HEADLESS_MODE", len(user_message))
|
| 1207 |
-
return snapshot
|
| 1208 |
-
|
| 1209 |
-
def _hydrate_snapshot_metadata(self, snapshot: Dict, ctx: CycleContext):
|
| 1210 |
-
def _safe_dict(obj):
|
| 1211 |
-
if hasattr(obj, "to_dict"):
|
| 1212 |
-
return obj.to_dict()
|
| 1213 |
-
if isinstance(obj, dict):
|
| 1214 |
-
return obj
|
| 1215 |
-
return {}
|
| 1216 |
-
|
| 1217 |
-
snapshot.update(
|
| 1218 |
-
{
|
| 1219 |
-
"trace_id": getattr(ctx, "trace_id", "UNKNOWN"),
|
| 1220 |
-
"is_alive": True,
|
| 1221 |
-
"physics": _safe_dict(ctx.physics),
|
| 1222 |
-
"bio": _safe_dict(ctx.bio_result),
|
| 1223 |
-
"mind": _safe_dict(ctx.mind_state),
|
| 1224 |
-
"world": _safe_dict(ctx.world_state),
|
| 1225 |
-
"soul": _safe_dict(getattr(self.eng, "soul", {})),
|
| 1226 |
-
"council_mandates": getattr(ctx, "council_mandates", []),
|
| 1227 |
-
"dream": getattr(ctx, "last_dream", None),
|
| 1228 |
-
}
|
| 1229 |
-
)
|
| 1230 |
-
|
| 1231 |
-
@staticmethod
|
| 1232 |
-
def _generate_crash_report(e: Exception) -> Dict[str, Any]:
|
| 1233 |
-
full_trace = "".join(traceback.format_exception(type(e), e, e.__traceback__))
|
| 1234 |
-
safe_phys = PanicRoom.get_safe_physics()
|
| 1235 |
-
safe_bio = PanicRoom.get_safe_bio()
|
| 1236 |
-
ui_report = (
|
| 1237 |
-
f"\n{Prisma.RED}*** REALITY FRACTURE: {e} ***{Prisma.RST}\n"
|
| 1238 |
-
f"{Prisma.GRY}{full_trace}{Prisma.RST}\n"
|
| 1239 |
-
f"{Prisma.OCHRE}[System stabilized in Safe Mode]{Prisma.RST}"
|
| 1240 |
-
)
|
| 1241 |
-
return {
|
| 1242 |
-
"type": "CRASH",
|
| 1243 |
-
"ui": ui_report,
|
| 1244 |
-
"physics": safe_phys.to_dict(),
|
| 1245 |
-
"bio": safe_bio,
|
| 1246 |
-
"mind": PanicRoom.get_safe_mind(),
|
| 1247 |
-
"world": {"orbit": ["VOID"], "loci_description": "System Failure"},
|
| 1248 |
-
"logs": ["CRITICAL FAILURE", "SAFE MODE ACTIVE"],
|
| 1249 |
-
"is_alive": True,
|
| 1250 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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