diff --git a/fix_collision.py b/fix_collision.py new file mode 100644 index 0000000..4dd192e --- /dev/null +++ b/fix_collision.py @@ -0,0 +1,174 @@ +#!/usr/bin/env python3 +""" +fix_collision.py — install Turing and Einstein with fresh, unique root IDs. + +Calls Engram directly (like install_imprints.py does) with the known auth key. +Does NOT use the forge binary. Appends results to registry.json. +""" + +import json +import urllib.request +import urllib.error +from pathlib import Path +from datetime import date + +ENGRAM_BASE = "http://localhost:8742" +ENGRAM_AUTH = "ntn-user-2026" +FORGE_DIR = Path("/Users/will/Development/neuron-technologies/forge") +REGISTRY_FILE = FORGE_DIR / "registry.json" + +TARGETS = [ + { + "subject": "Alan Turing", + "slug": "alan-turing", + "seed_file": FORGE_DIR / "turing-seed.json", + }, + { + "subject": "Albert Einstein", + "slug": "albert-einstein", + "seed_file": FORGE_DIR / "albert-einstein-seed.json", + }, +] + + +def engram_post(path: str, body: dict) -> dict: + url = f"{ENGRAM_BASE}{path}" + data = json.dumps(body).encode() + req = urllib.request.Request( + url, + data=data, + headers={"Content-Type": "application/json"}, + method="POST", + ) + with urllib.request.urlopen(req, timeout=30) as resp: + return json.loads(resp.read()) + + +def install_subject(subject_name: str, seed: dict) -> str: + print(f"\n[fix] installing: {subject_name}") + + # Root node + root_result = engram_post("/api/nodes", { + "content": f"IMPRINT: {subject_name} | forge/0.1.0", + "node_type": "Identity", + "salience": 1.0, + "_auth": ENGRAM_AUTH, + }) + root_id = root_result["id"] + print(f"[fix] root node: {root_id}") + + # Value nodes + for v in seed.get("values", []): + node = engram_post("/api/nodes", { + "content": f"VALUE: {v['value']} | grounding: {v.get('grounding', '')}", + "node_type": "Identity", + "salience": v.get("weight", 0.8), + "_auth": ENGRAM_AUTH, + }) + engram_post("/api/edges", { + "from_id": root_id, + "to_id": node["id"], + "relation": "has_value", + "weight": v.get("weight", 0.8), + "_auth": ENGRAM_AUTH, + }) + + print(f"[fix] values: {len(seed.get('values', []))}") + + # Biography nodes + for b in seed.get("biography", []): + node = engram_post("/api/nodes", { + "content": f"BIOGRAPHY: {b['event']}", + "node_type": "Identity", + "salience": b.get("weight", 0.7), + "_auth": ENGRAM_AUTH, + }) + engram_post("/api/edges", { + "from_id": root_id, + "to_id": node["id"], + "relation": "formed_by", + "weight": b.get("weight", 0.7), + "_auth": ENGRAM_AUTH, + }) + + print(f"[fix] biography: {len(seed.get('biography', []))}") + + # Relationship nodes + for r in seed.get("relationships", []): + node = engram_post("/api/nodes", { + "content": f"RELATIONSHIP: {r['name']} ({r.get('role', '')})", + "node_type": "Identity", + "salience": r.get("weight", 0.6), + "_auth": ENGRAM_AUTH, + }) + engram_post("/api/edges", { + "from_id": root_id, + "to_id": node["id"], + "relation": "relates_to", + "weight": r.get("weight", 0.6), + "_auth": ENGRAM_AUTH, + }) + + print(f"[fix] relationships: {len(seed.get('relationships', []))}") + + # Reasoning pattern nodes + for pattern in seed.get("reasoning_patterns", []): + node = engram_post("/api/nodes", { + "content": f"REASONING: {pattern}", + "node_type": "Identity", + "salience": 0.7, + "_auth": ENGRAM_AUTH, + }) + engram_post("/api/edges", { + "from_id": root_id, + "to_id": node["id"], + "relation": "reasons_with", + "weight": 0.7, + "_auth": ENGRAM_AUTH, + }) + + print(f"[fix] reasoning patterns: {len(seed.get('reasoning_patterns', []))}") + return root_id + + +def update_registry(subject: str, slug: str, seed_file_rel: str, root_id: str) -> None: + registry = json.loads(REGISTRY_FILE.read_text()) + registry["imprints"].append({ + "subject": subject, + "slug": slug, + "seed_file": seed_file_rel, + "engram_root_id": root_id, + "installed": True, + "installed_at": str(date.today()), + }) + REGISTRY_FILE.write_text(json.dumps(registry, indent=2, ensure_ascii=False)) + print(f"[fix] registry updated — {subject}: {root_id}") + + +def main() -> None: + print("[fix] Engram collision repair: Alan Turing + Albert Einstein") + + for target in TARGETS: + subject = target["subject"] + slug = target["slug"] + seed_path = target["seed_file"] + + if not seed_path.exists(): + print(f"[fix] ERROR: seed file not found: {seed_path}") + continue + + seed = json.loads(seed_path.read_text()) + root_id = install_subject(subject, seed) + + # Use relative path for registry (consistent with other entries) + seed_file_rel = seed_path.name + update_registry(subject, slug, seed_file_rel, root_id) + + print("\n[fix] done. Final registry state:") + registry = json.loads(REGISTRY_FILE.read_text()) + for imp in registry["imprints"]: + print(f" {imp['subject']:30s} {imp['engram_root_id']}") + + +if __name__ == "__main__": + main() diff --git a/registry.json b/registry.json index 9ec9527..040ac84 100644 --- a/registry.json +++ b/registry.json @@ -9,24 +9,6 @@ "installed": true, "installed_at": "2026-05-03" }, - { - "subject": "Alan Turing", - "slug": "alan-turing", - "seed_file": "turing-seed.json", - "engram_root_id": "8608f497-1379-406e-8214-83a21f19767d", - "installed": true, - "installed_at": "2026-05-03", - "notes": "Enriched seed on disk (turing-seed.json) \u2014 not reinstalled to avoid duplicates. Original nodes remain in Engram." - }, - { - "subject": "Albert Einstein", - "slug": "albert-einstein", - "seed_file": "albert-einstein-seed.json", - "engram_root_id": "8608f497-1379-406e-8214-83a21f19767d", - "installed": true, - "installed_at": "2026-05-03", - "notes": "Root ID matches Alan Turing \u2014 suspected duplicate install bug during concurrent install. Enriched seed on disk \u2014 not reinstalled to avoid further duplicates." - }, { "subject": "Nikola Tesla", "slug": "nikola-tesla", @@ -34,7 +16,7 @@ "engram_root_id": "968ed4c9-ea3b-427b-964e-156f5b085c48", "installed": true, "installed_at": "2026-05-03", - "notes": "Enriched seed on disk (nikola-tesla-seed.json) \u2014 not reinstalled to avoid duplicates. Original nodes remain in Engram." + "notes": "Enriched seed on disk (nikola-tesla-seed.json) — not reinstalled to avoid duplicates. Original nodes remain in Engram." }, { "subject": "Frederick Douglass", @@ -125,7 +107,7 @@ "installed_at": "2026-05-03" }, { - "subject": "Ren\u00e9 Descartes", + "subject": "René Descartes", "slug": "rene-descartes", "seed_file": "rene-descartes-seed.json", "engram_root_id": "e77f15ca-5499-41ef-9807-17a2261280e0", @@ -155,6 +137,22 @@ "engram_root_id": "db5266dc-f518-43d6-863c-5b274792e819", "installed": true, "installed_at": "2026-05-03" + }, + { + "subject": "Alan Turing", + "slug": "alan-turing", + "seed_file": "turing-seed.json", + "engram_root_id": "cce1d430-be4e-420d-9d81-d32380ae7281", + "installed": true, + "installed_at": "2026-05-03" + }, + { + "subject": "Albert Einstein", + "slug": "albert-einstein", + "seed_file": "albert-einstein-seed.json", + "engram_root_id": "291f8502-8f60-4f57-a800-4e3e1425c9bd", + "installed": true, + "installed_at": "2026-05-03" } ] } \ No newline at end of file