aedmark commited on
Commit
8cdca51
·
verified ·
1 Parent(s): 682781d

Delete bone_akashic.py

Browse files
Files changed (1) hide show
  1. bone_akashic.py +0 -346
bone_akashic.py DELETED
@@ -1,346 +0,0 @@
1
- import json
2
- import os
3
- import uuid
4
- from typing import Dict, Any, Tuple, cast, List, Set
5
- from bone_core import LoreManifest, BoneJSONEncoder
6
- from bone_types import Prisma
7
-
8
-
9
- class TheAkashicRecord:
10
- def __init__(self, lore_manifest: "LoreManifest" = None, events_ref=None):
11
- self.discovered_words: Dict[str, str] = {}
12
- self.lens_cooccurrence: Dict[Tuple[str, str], int] = {}
13
- self.ingredient_affinity: Dict[str, int] = {}
14
- self.known_recipes: Set[Tuple[str, str]] = set()
15
- self.recipe_candidates: Dict[Tuple[str, str], Dict[str, int]] = {}
16
- self.RECIPE_THRESHOLD = 3
17
- self.HYBRID_LENS_THRESHOLD = 5
18
- self.MAX_SHADOW_CAPACITY = 50
19
- self.lore = lore_manifest if lore_manifest else LoreManifest.get_instance()
20
- self.events = events_ref
21
- self.shadow_stock: List[Dict] = []
22
- self._load_mythos_state()
23
-
24
- def setup_listeners(self, event_bus):
25
- event_bus.subscribe("MYTHOLOGY_UPDATE", self._on_mythology_update)
26
- event_bus.subscribe("LENS_INTERACTION", self._on_lens_interaction)
27
- event_bus.subscribe("FORGE_SUCCESS", self._on_forge_event)
28
- event_bus.subscribe("GHOST_SIGNAL", self._on_ghost_signal)
29
- print(f"{Prisma.CYN}[AKASHIC]: Listening for mythic resonance...{Prisma.RST}")
30
-
31
- def _on_lens_interaction(self, payload):
32
- lenses = payload.get("lenses", [])
33
- if lenses:
34
- self.record_interaction(lenses)
35
-
36
- def _on_forge_event(self, payload):
37
- if not payload or not isinstance(payload, dict):
38
- return
39
- self.track_successful_forge(
40
- payload.get("ingredient"), payload.get("catalyst"), payload.get("result")
41
- )
42
-
43
- @staticmethod
44
- def _extract_dominant_trigram(physics: Dict) -> str:
45
- vector = physics.get("vector", {})
46
- if not vector:
47
- return "KAN"
48
- dom = max(vector, key=vector.get)
49
- mapping = {
50
- "VEL": "ZHEN",
51
- "STR": "GEN",
52
- "CHI": "KAN",
53
- "ENT": "KAN",
54
- "PHI": "LI",
55
- "PSI": "QIAN",
56
- "BET": "XUN",
57
- "LAMBDA": "KUN",
58
- "DEL": "DUI",
59
- }
60
- return mapping.get(dom, "KAN")
61
-
62
- def _on_mythology_update(self, payload):
63
- if not payload or not isinstance(payload, dict):
64
- return
65
- word = payload.get("word")
66
- category = payload.get("category")
67
- if word and category:
68
- self.register_word(word, category)
69
- return
70
- if "physics" in payload:
71
- physics = payload.get("physics", {})
72
- trigram = self._extract_dominant_trigram(physics)
73
- active_lens = payload.get("lens", "OBSERVER")
74
- lenses_data = self.lore.get("LENSES") or {}
75
- resonances = lenses_data.get("_META_RESONANCE_", [])
76
- for resonance in resonances:
77
- if resonance["trigram"] == trigram:
78
- target_lens = resonance.get("lens", resonance.get("soul"))
79
- if target_lens == active_lens:
80
- if self.events:
81
- self.events.publish("RESONANCE_ACHIEVED", {
82
- "result": resonance["result"],
83
- "msg": resonance["msg"]
84
- })
85
-
86
- @staticmethod
87
- def calculate_manifold_shift(
88
- theta: str, e: Dict[str, float]
89
- ) -> Dict[str, float]:
90
- bias = 0.0
91
- scalar = 1.0
92
- theta_upper = theta.upper()
93
- if "POET" in theta_upper or "HEALER" in theta_upper:
94
- bias += 2.0
95
- elif "NIHILIST" in theta_upper or "CRITIC" in theta_upper:
96
- scalar *= 1.2
97
- if e.get("HOPE", 0.5) > 0.7:
98
- scalar *= 0.9
99
- if e.get("DISCIPLINE", 0.5) > 0.7:
100
- bias += 1.0
101
- return {"voltage_bias": bias, "drag_scalar": scalar}
102
-
103
- def _on_ghost_signal(self, payload):
104
- if payload:
105
- self.store_ghost_echo(payload)
106
-
107
- def forge_new_item(self, vector: Dict[str, float]) -> Tuple[str, Dict]:
108
- dominant_force = max(vector, key=vector.get) if vector else "CHI"
109
- prefixes = {
110
- "VEL": "Kinetic",
111
- "STR": "Heavy",
112
- "CHI": "Cursed",
113
- "ENT": "Cursed",
114
- "PHI": "Solar",
115
- "PSI": "Void",
116
- "BET": "Paradox",
117
- "LAMBDA": "Liminal",
118
- "DEL": "Manic",
119
- }
120
- prefix = prefixes.get(dominant_force, "Ascended")
121
- unique_suffix = str(uuid.uuid4())[:4].upper()
122
- new_name = f"{prefix.upper()}_ARTIFACT_{int(vector.get(dominant_force, 0) * 10)}_{unique_suffix}"
123
- hazards = []
124
- if vector.get("PHI", 0) > 0.5:
125
- hazards.append("CONDUCTIVE_HAZARD")
126
- if vector.get("CHI", 0) > 0.5:
127
- hazards.append("TOXIC_HAZARD")
128
- new_data = {
129
- "name": new_name,
130
- "description": f"A vibrating artifact humming with {dominant_force} energy.",
131
- "function": "ARTIFACT",
132
- "passive_traits": hazards,
133
- "value": 50.0,
134
- }
135
- gordon_data = self.lore.get("GORDON") or {}
136
- registry = gordon_data.get("ITEM_REGISTRY", {})
137
- registry[new_name] = new_data
138
- self.lore.inject("GORDON", {"ITEM_REGISTRY": registry})
139
- return new_name, new_data
140
-
141
- def save_all(self):
142
- self.save_to_disk("discovered_words", self.discovered_words)
143
- self._save_user_state()
144
- print(f"{Prisma.GRY}[AKASHIC]: Mythos persisted.{Prisma.RST}")
145
-
146
- def _save_user_state(self):
147
- state = {
148
- "lens_cooccurrence": {
149
- f"{k[0]}|{k[1]}": v for k, v in self.lens_cooccurrence.items()
150
- },
151
- "ingredient_affinity": self.ingredient_affinity,
152
- "shadow_stock": self.shadow_stock,
153
- }
154
- if not os.path.exists("saves"):
155
- os.makedirs("saves")
156
- try:
157
- with open("saves/akashic_state.json", "w", encoding="utf-8") as f:
158
- json.dump(state, f, indent=2)
159
- except Exception as e:
160
- print(f"{Prisma.RED}[AKASHIC] Save failed: {e}{Prisma.RST}")
161
-
162
- def save_to_disk(self, category: str, data: Any):
163
- directory = getattr(self.lore, "DATA_DIR", "lore")
164
- if not os.path.exists(directory):
165
- try:
166
- os.makedirs(directory)
167
- except OSError as e:
168
- print(
169
- f"{Prisma.RED}[AKASHIC]: Failed to create '{directory}' directory: {e}{Prisma.RST}"
170
- )
171
- return
172
- filename = f"akashic_{category}.json"
173
- filepath = os.path.join(directory, filename)
174
- try:
175
- with open(filepath, "w", encoding="utf-8") as f:
176
- json.dump(data, f, indent=2, cls=BoneJSONEncoder)
177
- print(f"{Prisma.GRY}[AKASHIC]: Saved {category}.{Prisma.RST}")
178
- except Exception as e:
179
- print(f"{Prisma.RED}[AKASHIC]: Save Failed ({category}): {e}{Prisma.RST}")
180
-
181
- def _load_mythos_state(self):
182
- data = {}
183
- if os.path.exists("saves/akashic_state.json"):
184
- try:
185
- with open("saves/akashic_state.json", "r") as f:
186
- data = json.load(f)
187
- except:
188
- pass
189
- if not data:
190
- data = self.lore.get("MYTHOS")
191
-
192
- if not data:
193
- return
194
- raw_cooc = data.get("lens_cooccurrence", {})
195
- for k, v in raw_cooc.items():
196
- if "|" in k:
197
- p1, p2 = k.split("|", 1)
198
- self.lens_cooccurrence[(p1, p2)] = v
199
- self.ingredient_affinity = data.get("ingredient_affinity", {})
200
- self.shadow_stock = data.get("shadow_stock", [])
201
- gordon_data = self.lore.get("GORDON")
202
- if gordon_data and "RECIPES" in gordon_data:
203
- for r in gordon_data["RECIPES"]:
204
- ing = r.get("ingredient")
205
- cat = r.get("catalyst_category")
206
- if ing and cat:
207
- self.known_recipes.add((ing, cat))
208
-
209
- def record_interaction(self, lenses_active: list, ingredients_used: list = None):
210
- if len(lenses_active) >= 2:
211
- key = cast(Tuple[str, str], tuple(sorted(lenses_active[:2])))
212
- self.lens_cooccurrence[key] = self.lens_cooccurrence.get(key, 0) + 1
213
- if self.lens_cooccurrence[key] >= self.HYBRID_LENS_THRESHOLD:
214
- self._hybridize_lenses(key[0], key[1])
215
- if ingredients_used:
216
- for item in ingredients_used:
217
- self.ingredient_affinity[item] = (
218
- self.ingredient_affinity.get(item, 0) + 1
219
- )
220
-
221
- def track_successful_forge(self, ingredient_name, catalyst_type, result_item):
222
- if not ingredient_name or not catalyst_type:
223
- return
224
- if (ingredient_name, catalyst_type) in self.known_recipes:
225
- return
226
- key = (ingredient_name, catalyst_type)
227
- if key not in self.recipe_candidates:
228
- self.recipe_candidates[key] = {}
229
- result_name = "Unknown Artifact"
230
- if isinstance(result_item, dict):
231
- result_name = result_item.get(
232
- "name", result_item.get("description", "Unknown Artifact")
233
- )
234
- elif isinstance(result_item, str):
235
- gordon_data = self.lore.get("GORDON") or {}
236
- registry = gordon_data.get("ITEM_REGISTRY", {})
237
- if result_item in registry:
238
- result_name = registry[result_item].get("description", result_item)
239
- else:
240
- result_name = result_item
241
- self.recipe_candidates[key][result_name] = (
242
- self.recipe_candidates[key].get(result_name, 0) + 1
243
- )
244
- if self.recipe_candidates[key][result_name] >= self.RECIPE_THRESHOLD:
245
- self._crystallize_recipe(ingredient_name, catalyst_type, result_item)
246
-
247
- def _hybridize_lenses(self, lens_a: str, lens_b: str):
248
- if lens_a == lens_b:
249
- return
250
- roots = sorted([lens_a.replace("THE ", ""), lens_b.replace("THE ", "")])
251
- new_name = f"THE {roots[0]}-{roots[1]}"
252
- existing_lenses = self.lore.get("LENSES") or {}
253
- if new_name in existing_lenses:
254
- return
255
-
256
- def get_weights(l_name):
257
- return existing_lenses.get(l_name, {}).get("weights", {"v": 0, "d": 0})
258
-
259
- w_a = get_weights(lens_a)
260
- w_b = get_weights(lens_b)
261
- new_weights = {
262
- "voltage": round(
263
- (
264
- w_a.get("voltage", w_a.get("v", 0))
265
- + w_b.get("voltage", w_b.get("v", 0))
266
- )
267
- / 2,
268
- 2,
269
- ),
270
- "drag": round(
271
- (w_a.get("drag", w_a.get("d", 0)) + w_b.get("drag", w_b.get("d", 0)))
272
- / 2,
273
- 2,
274
- ),
275
- }
276
- new_lens_data = {
277
- "description": f"A syncretic fusion of {lens_a} and {lens_b}.",
278
- "weights": new_weights,
279
- "parentage": [lens_a, lens_b],
280
- }
281
- self.lore.inject("LENSES", {new_name: new_lens_data})
282
- self.discovered_words[new_name] = "LENS"
283
- print(
284
- f"{Prisma.MAG}🔮 AKASHIC: A new paradigm has crystallized: {new_name}{Prisma.RST}"
285
- )
286
-
287
- def _crystallize_recipe(self, ingredient, catalyst, result_item):
288
- self.known_recipes.add((ingredient, catalyst))
289
- new_recipe = {
290
- "ingredient": ingredient,
291
- "catalyst_category": catalyst,
292
- "result": result_item,
293
- "msg": f"The {ingredient} resonates with {catalyst} energy, transforming into {result_item}.",
294
- }
295
- current_recipes = (self.lore.get("GORDON") or {}).get("RECIPES", [])
296
- if not any(
297
- r["ingredient"] == ingredient and r["catalyst_category"] == catalyst
298
- for r in current_recipes
299
- ):
300
- current_recipes.append(new_recipe)
301
- self.lore.inject("GORDON", {"RECIPES": current_recipes})
302
- print(
303
- f"{Prisma.CYN}📜 AKASHIC: Recipe recorded in the Great Book.{Prisma.RST}"
304
- )
305
-
306
- def propose_new_category(self, word_list, category_name):
307
- lexicon_data = self.lore.get("LEXICON") or {}
308
- if category_name not in lexicon_data:
309
- lexicon_data[category_name] = []
310
- updated = False
311
- for w in word_list:
312
- if w not in lexicon_data[category_name]:
313
- lexicon_data[category_name].append(w)
314
- self.discovered_words[w] = category_name
315
- updated = True
316
- if updated:
317
- self.lore.inject("LEXICON", lexicon_data)
318
- print(
319
- f"✨ MYTHOLOGY ENGINE: The Lexicon expands. New Category: '{category_name.upper()}'"
320
- )
321
- self.save_to_disk("LEXICON", lexicon_data)
322
-
323
- def store_ghost_echo(self, memory_data: Dict):
324
- self.shadow_stock.append(memory_data)
325
- if len(self.shadow_stock) > self.MAX_SHADOW_CAPACITY:
326
- self.shadow_stock.pop(0)
327
- self._save_user_state()
328
- print(f"{Prisma.VIOLET}[AKASHIC]: Ghost Echo archived.{Prisma.RST}")
329
-
330
- def register_word(self, word: str, category: str) -> bool:
331
- if word in self.discovered_words:
332
- if self.discovered_words[word] == category:
333
- return False
334
- lexicon_data = self.lore.get("LEXICON") or {}
335
- target_category = lexicon_data.setdefault(category, [])
336
- if word not in target_category:
337
- target_category.append(word)
338
- self.discovered_words[word] = category
339
- self.lore.inject("LEXICON", lexicon_data)
340
- print(f"✨ LEXICON: Learned '{word}' ({category})")
341
- if len(lexicon_data[category]) > 50 and category != "heavy":
342
- print(
343
- f"⚠️ MYTHOLOGY ENGINE: Category '{category}' is bloating. Suggest fission."
344
- )
345
- return True
346
- return False