Repository navigation
Expand file tree
/
Copy pathmythos_sync.py
More file actions
388 lines (343 loc) · 17.9 KB
/
Copy pathmythos_sync.py
File metadata and controls
388 lines (343 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# =============================================================
# MYTHOS-SYNC FRAMEWORK — CORE ENGINE V1.0
# Connects: Classifier → Auditor → Generator → Data Persistence
# This is the full intelligent simulation engine.
# =============================================================
import random
import json
import os
from datetime import datetime
# Import our two modules
from console import use_utf8_output
from modality_classifier import classify_fusion, classify
from logic_auditor import audit_power, family_of, POWER_REGISTRY
# ------------------------------------------------------------------
# CONSTANTS
# ------------------------------------------------------------------
MATRIX_FILE = "containment_matrix.json" # persistent database file
BIOMES = {
"LEGACY": ["The Iron Forum", "Dust of Carthage", "The Underground Railroad", "Harlem Renaissance Streets"],
"GROUNDED": ["Neon Back-Alleys", "Cold War Safehouse", "Collapsed Industrial Zone", "The Borderlands"],
"HIGH_CONCEPT": ["Sea of Rot", "Floating Sky-Islands", "Submerged Neon City", "Clockwork Labyrinth"],
}
POWER_POOL = {
"LEGACY": [
# COGNITION
"Strategic Genius", "The Scientific Method", "Art of War",
"Pattern Recognition", "Mastermind Architecture", "Tactical Brilliance",
# INFLUENCE
"Rhetoric & Legacy", "Cultural Resonance", "Diplomatic Mastery",
"Symbolic Authority",
# DISCIPLINE
"Indomitable Will", "Martial Perfection", "Adaptive Combat",
"Iron Discipline",
# PERCEPTION
"Intuitive Insight", "Situational Awareness", "Psychological Mastery",
"Memory Palace",
],
"GROUNDED": ["Espionage", "Kinetic Mastery", "One-Inch Punch", "Electromagnetic Pulse"],
"HIGH_CONCEPT": ["Domain Expansion", "Cursed Energy", "Soul Resonance", "Reality Glitch", "Spiral Power", "Angelic Override"],
}
# Every power must be reachable from a tag, or it can only ever arrive through
# the single random universal slot — which produces more combinations that mean
# less. New powers were routed to the tags that already imply them.
TAG_POWER_MAP = {
"strategy": ["Strategic Genius", "Art of War", "Tactical Brilliance", "Mastermind Architecture", "Pattern Recognition"],
"rhetoric": ["Rhetoric & Legacy", "Symbolic Authority", "Cultural Resonance", "Psychological Mastery"],
"legacy": ["Rhetoric & Legacy", "Symbolic Authority", "Cultural Resonance", "Indomitable Will"],
"tactical": ["Tactical Brilliance", "Espionage", "Art of War", "Situational Awareness"],
"street_legend": ["Cultural Resonance", "Psychological Mastery", "Indomitable Will", "Symbolic Authority"],
"underworld": ["Espionage", "Psychological Mastery", "Situational Awareness", "Tactical Brilliance"],
"martial_arts": ["One-Inch Punch", "Kinetic Mastery", "Martial Perfection", "Adaptive Combat"],
"philosophy": ["The Scientific Method", "Intuitive Insight", "Iron Discipline", "Equivalent Exchange"],
"kinetic": ["Kinetic Mastery", "One-Inch Punch", "Martial Perfection"],
"inventor": ["The Scientific Method", "Electromagnetic Pulse", "Mastermind Architecture", "Pattern Recognition", "Equivalent Exchange"],
"electromagnetic": ["Electromagnetic Pulse", "Pattern Recognition"],
"visionary": ["The Scientific Method", "Pattern Recognition", "Mastermind Architecture"],
"espionage": ["Espionage", "Situational Awareness", "Psychological Mastery"],
"resourceful": ["Adaptive Combat", "Situational Awareness", "Tactical Brilliance"],
"warrior": ["Martial Perfection", "Iron Discipline", "Art of War", "Kinetic Mastery", "Titan-Shifting"],
"historical": ["Memory Palace", "Symbolic Authority", "Strategic Genius"],
"resilience": ["Iron Discipline", "Indomitable Will"],
"redemption": ["Symbolic Authority", "Cultural Resonance", "Indomitable Will"],
"influence": ["Cultural Resonance", "Diplomatic Mastery", "Rhetoric & Legacy"],
"pacifist": ["Diplomatic Mastery", "Iron Discipline", "Indomitable Will"],
"gunslinger": ["Adaptive Combat", "Situational Awareness", "Kinetic Mastery"],
"angelic_power": ["Soul Resonance", "Angelic Override", "Symbolic Authority"],
"soul_resonance": ["Soul Resonance", "Spiral Power", "Intuitive Insight"],
"meister": ["Soul Resonance", "Adaptive Combat", "Kinetic Mastery"],
"anti_demon": ["Cursed Energy", "Soul Resonance", "Iron Discipline", "Titan-Shifting"],
"spiritual": ["Cursed Energy", "Soul Resonance", "Intuitive Insight", "Domain Expansion"],
"cursed": ["Cursed Energy", "Reality Glitch", "Domain Expansion"],
"ancient": ["Art of War", "Memory Palace", "Symbolic Authority"],
"cyberpunk": ["Reality Glitch", "Electromagnetic Pulse", "Pattern Recognition"],
"investigator": ["Pattern Recognition", "Situational Awareness", "Psychological Mastery"],
"android_adjacent":["Electromagnetic Pulse", "Reality Glitch", "Memory Palace"],
"traveler": ["Situational Awareness", "Memory Palace", "Adaptive Combat"],
"observer": ["Intuitive Insight", "Situational Awareness", "Pattern Recognition"],
"survivalist": ["Adaptive Combat", "Situational Awareness", "Iron Discipline"],
}
INFLUENCE_PATTERNS = [
"rewrites the cultural memory of the realm",
"bends the will of generals through presence alone",
"leaves no fingerprints but reshapes every outcome",
"strikes once — the shockwave lasts generations",
"speaks in paradoxes that become prophecy",
"moves through systems like water through cracks",
]
RHETORICAL_STYLES = {
"LEGACY": ["Socratic dismantling", "Call-and-response", "Iron-fist rhetoric", "Legacy manifesto"],
"GROUNDED": ["Tactical misdirection", "Cold precision", "Kinetic storytelling", "Street-level truth"],
"HIGH_CONCEPT": ["Reality inversion", "Soul-frequency broadcast", "Dimensional proclamation", "Cursed verse"],
}
# ------------------------------------------------------------------
# PERSISTENCE — Load & Save Containment Matrix
# ------------------------------------------------------------------
def load_matrix() -> list:
if os.path.exists(MATRIX_FILE):
with open(MATRIX_FILE, "r") as f:
return json.load(f)
return []
def save_to_matrix(profile: dict):
matrix = load_matrix()
# Check if a duplicate already exists
is_duplicate = any(
m.get("fusion_name") == profile.get("fusion_name") and
m.get("signature_ability") == profile.get("signature_ability")
for m in matrix
)
if not is_duplicate:
matrix.append(profile)
with open(MATRIX_FILE, 'w') as f:
json.dump(matrix, f, indent=2)
print(f" ✅ [SERVER] Saved new fusion: {profile['fusion_name']}")
else:
# AUTH-013: fill-only. Add a missing `reasons` key to an existing record for the same
# fusion; never replace existing reasons, never touch any other field or record.
incoming = profile.get("reasons")
filled = False
if isinstance(incoming, list) and incoming:
for m in matrix:
if (m.get("fusion_name") == profile.get("fusion_name") and
m.get("signature_ability") == profile.get("signature_ability") and
"reasons" not in m):
m["reasons"] = list(incoming)
filled = True
if filled:
with open(MATRIX_FILE, 'w') as f:
json.dump(matrix, f, indent=2)
print(f" ✅ [SERVER] Added reasons to existing fusion: {profile['fusion_name']}")
else:
print(f" ⚠️ [SERVER] Duplicate fusion detected. Skipping save.")
# ------------------------------------------------------------------
# CORE: BUILD A FULL LEGACY PROFILE
# ------------------------------------------------------------------
def build_legacy_profile(
alpha: str,
beta: str,
dominance: int = 50
) -> dict:
"""
Full pipeline:
1. Classify the fusion
2. Pick powers from the correct modality pool
3. Audit every power (auto-transpose if illegal)
4. Generate lore, biome, rhetorical style, influence pattern
5. Package into a rich Legacy Profile dict
"""
print(f"\n{'═'*60}")
print(f" 🌌 MYTHOS-SYNC ENGINE — SYNTHESIZING FUSION")
print(f" Alpha: {alpha} | Beta: {beta} | Dominance: {dominance}%")
print(f"{'═'*60}")
# --- STEP 1: Classify ---
fusion = classify_fusion(alpha, beta, dominance)
# Ruling 001 §4: CAUTIONARY halts before any fusion output is generated.
# Stop here, before power selection/audit, so an unresolved input can
# never reach logic_auditor.py's audit_power()/ground_power().
if fusion.get("state") == "CAUTIONARY":
print(f"\n [MYTHOS-SYNC] ⚠️ CAUTIONARY — one or both concepts require normalization. No fusion output generated.")
return {
"fusion_name": fusion["fusion_name"],
"state": "CAUTIONARY",
"modality": None,
"reasons": fusion["reasons"],
}
modality = fusion["modality"]
print(f"\n [CLASSIFIER] Modality resolved → {modality}")
print(f" [CLASSIFIER] Dominant → {fusion['dominant']}")
# --- STEP 2 & 3: Thematic power selection + audit ---
# Gather thematic powers from the fused tags. Powers that exceed this
# fusion's modality ceiling are deliberately NOT filtered out here — they
# go to the auditor, which grounds them into legal equivalents. Filtering
# would silently discard a character's theme; transposing translates it.
thematic_pool = set()
for tag in fusion["tags"]:
for power in TAG_POWER_MAP.get(tag, []):
if power in POWER_REGISTRY:
thematic_pool.add(power)
thematic_pool = list(thematic_pool)
random.shuffle(thematic_pool)
approved_powers = []
audit_log = []
def audit_and_take(power: str):
"""Audit one power, log the verdict, and hold the result if it's new.
Transposition can map several illegal powers onto the same legal one,
so a power that gets audited is not necessarily a power that is gained.
"""
result = audit_power(power, fusion)
# Carry the auditor's four-state verdict. Deriving status from
# transposed_to instead collapsed UNVERIFIED into "approved", because
# transposed_to is None for both — an unregistered power was logged and
# rendered as if the registry had cleared it.
audit_log.append({
"power": result["power"],
"status": result["state"].lower(),
"transposed_to": result["transposed_to"],
"cost": result["cost_factor"],
"reason": result["message"] if result["state"] != "APPROVED" else None,
# Contract 002 I8(f) — which of the two grounding-halt causes this
# was, kept alongside the rest of the entry. None for every state
# other than GROUNDING_UNAVAILABLE. AUTH-005.
"unavailable_cause": result.get("unavailable_cause"),
})
# Contract 002 I8(d) — a halted grounding must not be promoted into
# approved_powers as if it had resolved to something concrete.
# GROUNDING_UNAVAILABLE contributes neither a substitute nor the
# original illegal power. AUTH-005.
if result["state"] == "GROUNDING_UNAVAILABLE":
return
final = result["transposed_to"] or result["power"]
if final not in approved_powers:
approved_powers.append(final)
# Pull thematic powers until we hold 2 distinct ones
for power in thematic_pool:
if len(approved_powers) >= 2:
break
audit_and_take(power)
# Fill remaining slots from generic pool if the tags came up short
if len(approved_powers) < 2:
generic_pool = [p for p in POWER_POOL[modality] if p not in approved_powers]
random.shuffle(generic_pool)
for power in generic_pool:
if len(approved_powers) >= 2:
break
audit_and_take(power)
# Always try to add one universal LEGACY power
universal_candidates = [p for p in POWER_POOL["LEGACY"] if p not in approved_powers]
if universal_candidates:
audit_and_take(random.choice(universal_candidates))
# --- STEP 4: Generate lore components ---
biome = random.choice(BIOMES[modality])
signature_ability = approved_powers[0]
influence = random.choice(INFLUENCE_PATTERNS)
rhetoric = random.choice(RHETORICAL_STYLES[modality])
# Character-aware lore (uses traits/elements from registry)
alpha_data = classify(alpha)
beta_data = classify(beta)
a_trait = alpha_data.get("trait", alpha)
b_trait = beta_data.get("trait", beta)
a_elem = alpha_data.get("element", "Neutral")
b_elem = beta_data.get("element", "Neutral")
lore_templates = [
f"Where {alpha}, the {a_trait} ({a_elem}), collides with {beta}, the {b_trait} ({b_elem}), a new force crystallizes. In {biome}, this fusion wields {signature_ability} to {influence}. Their doctrine: {rhetoric}.",
f"Born from the tension between the {a_trait} ({a_elem}) and the {b_trait} ({b_elem}), this fusion haunts {biome} with singular intent. They channel {signature_ability} to {influence}, their voice carrying only {rhetoric}.",
]
lore_summary = random.choice(lore_templates)
# --- STEP 5: Build the full Legacy Profile ---
# Which kinds of excellence this fusion actually embodies. The dominant
# family is the closest thing the engine currently has to a disposition,
# and is what a philosophy/tension layer would read from.
families = [family_of(p) for p in approved_powers]
dominant_family = max(set(families), key=families.count)
profile = {
"fusion_name": fusion["fusion_name"],
"modality": modality,
"dominant": fusion["dominant"],
"alpha": {"name": alpha, "modality": classify(alpha)["modality"]},
"beta": {"name": beta, "modality": classify(beta)["modality"]},
"dominance": dominance,
"tags": fusion["tags"],
"biome": biome,
"approved_powers": approved_powers,
"power_families": {p: family_of(p) for p in approved_powers},
"dominant_family": dominant_family,
"signature_ability": signature_ability,
"influence_pattern": influence,
"rhetorical_style": rhetoric,
"lore_summary": lore_summary,
"audit_log": audit_log,
"created_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
return profile
# ------------------------------------------------------------------
# DISPLAY — Print a Legacy Profile beautifully
# ------------------------------------------------------------------
def display_profile(profile: dict):
print(f"\n{'═'*60}")
print(f" 📜 LEGACY PROFILE: {profile['fusion_name']}")
print(f"{'═'*60}")
print(f" Modality : {profile['modality']}")
print(f" Dominant : {profile['dominant']}")
print(f" Biome : {profile['biome']}")
print(f" Approved Powers : {', '.join(profile['approved_powers'])}")
print(f" Dominant Family : {profile['dominant_family']}")
print(f" Signature Ability: {profile['signature_ability']}")
print(f" Influence Pattern: {profile['influence_pattern']}")
print(f" Rhetorical Style : {profile['rhetorical_style']}")
print(f"\n 📖 LORE:")
print(f" {profile['lore_summary']}")
print(f"\n 🕓 Created: {profile['created_at']}")
print(f"{'═'*60}\n")
# ------------------------------------------------------------------
# DISPLAY — Print the full Containment Matrix
# ------------------------------------------------------------------
def display_matrix():
matrix = load_matrix()
if not matrix:
print("\n [MATRIX] No fusions stored yet.\n")
return
print(f"\n{'═'*60}")
print(f" 🗃️ CONTAINMENT MATRIX ({len(matrix)} fusions stored)")
print(f"{'═'*60}")
for i, entry in enumerate(matrix, 1):
print(f"\n [{i}] {entry['fusion_name']}")
print(f" Modality : {entry['modality']}")
print(f" Signature : {entry['signature_ability']}")
print(f" Biome : {entry['biome']}")
print(f" Created : {entry['created_at']}")
print(f"\n{'═'*60}\n")
# ------------------------------------------------------------------
# WEB EXPORT — Adds IDs and engine version for dashboard.html
# ------------------------------------------------------------------
def export_for_web():
"""Exports containment_matrix.json with IDs — the dashboard reads this file."""
matrix = load_matrix()
for i, entry in enumerate(matrix):
if "id" not in entry:
entry["id"] = f"MSF-{str(i+1).zfill(3)}"
if "engine_version" not in entry:
entry["engine_version"] = "v3.0"
with open("containment_matrix.json", "w") as f:
json.dump(matrix, f, indent=2)
print(f"\n 🌐 Web export ready → open dashboard.html in your browser")
# ------------------------------------------------------------------
# MAIN
# ------------------------------------------------------------------
if __name__ == "__main__":
use_utf8_output()
print("\n" + "═"*60)
print(" 🌌 MYTHOS-SYNC FRAMEWORK — MULTIVERSE ENGINE V3.0 🌌")
print("═"*60)
test_fusions = [
("Malcolm X", "Vash", 80),
("Bruce Lee", "Maka", 50),
("James Bond", "Nikola Tesla", 40),
]
profiles = []
for alpha, beta, dominance in test_fusions:
profile = build_legacy_profile(alpha, beta, dominance)
display_profile(profile)
save_to_matrix(profile)
profiles.append(profile)
display_matrix()
export_for_web()