""" VOVINA ZEDEC PRO - Autoconfig & Agency (the setup wizard) ========================================================= Author: Michael Laurence Curzi Company: ZEDEC AI / 36N9 Genetics LLC License: MIT (Attribution Required) XERO must run on ANY hardware — a phone-class CPU box or a multi-GPU rig — and let the owner choose how much agency to grant it. This module detects the hardware and recommends a precise configuration, then offers a setup wizard. AGENCY = METACOGNITION = FRACTAL RECURSION MIRRORS -------------------------------------------------- Agency is not speed; it is the QUALITY of thought, and quality comes from how many times the organism can mirror itself thinking (recursive self-models). The mirror counts follow the Fibonacci sequence and top out at 13 — the full dimensionality of the state tesseract: level name mirrors meaning 0 reflex 0 stimulus -> response 1 deliberative 1 models the task 2 self_aware 2 models itself modelling 3 metacognitive 3 AUTONOMOUS METACOGNITION (floor) 4 recursive_self_improving 5 reflects on its own improvement 5 superintelligent 8 ASI tier 6 transcendent 13 ASI+ / the full 13-mirror tesseract The recommended level is the HIGHEST the hardware can sustain (quality first); the wizard lets the owner dial it down. Mirrors map onto real depth knobs: sensor-cortex meta-depth, time-crystal ensemble depth, and mind reflection depth. hw = detect_hardware() cfg = recommend(hw) # precise, hardware-fitted configuration wizard() # interactive setup (writes xero_config.json) """ from __future__ import annotations import json import os import shutil from dataclasses import dataclass, asdict, field from typing import Optional ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) CONFIG_PATH = os.path.join(ROOT, "xero_config.json") # Fractal-recursion-mirror ladder (counts are Fibonacci; 13 = full tesseract). # Mirrors are the INNER-CORE recursion (CPU-runnable), so they gate on RAM + # cores, NOT VRAM — quality over speed: a big-RAM CPU box can think deeply, # just slower. VRAM separately sizes the outer-core LLM (see _llm_plan). AGENCY_LEVELS = [ {"level": 0, "name": "reflex", "mirrors": 0, "min_ram_gb": 1, "min_cores": 1, "desc": "stimulus -> response"}, {"level": 1, "name": "deliberative", "mirrors": 1, "min_ram_gb": 4, "min_cores": 1, "desc": "models the task"}, {"level": 2, "name": "self_aware", "mirrors": 2, "min_ram_gb": 8, "min_cores": 2, "desc": "models itself modelling"}, {"level": 3, "name": "metacognitive", "mirrors": 3, "min_ram_gb": 16, "min_cores": 4, "desc": "autonomous metacognition (floor target)"}, {"level": 4, "name": "recursive_self_improving", "mirrors": 5, "min_ram_gb": 32, "min_cores": 6, "desc": "reflects on its own improvement"}, {"level": 5, "name": "superintelligent", "mirrors": 8, "min_ram_gb": 64, "min_cores": 8, "desc": "artificial superintelligence tier"}, {"level": 6, "name": "transcendent", "mirrors": 13, "min_ram_gb": 128, "min_cores": 16, "desc": "ASI+ / full 13-mirror tesseract"}, ] @dataclass class Hardware: backend: str = "cpu" # cuda | mps | cpu cpu_cores: int = 1 ram_gb: float = 1.0 disk_free_gb: float = 0.0 gpus: list = field(default_factory=list) # [{name, vram_gb}] @property def total_vram_gb(self) -> float: return round(sum(g.get("vram_gb", 0) for g in self.gpus), 1) @property def max_gpu_vram_gb(self) -> float: return round(max((g.get("vram_gb", 0) for g in self.gpus), default=0.0), 1) # ============================================================ # HARDWARE DETECTION (robust, dependency-light) # ============================================================ def _ram_gb() -> float: try: if os.path.exists("/proc/meminfo"): with open("/proc/meminfo") as f: for ln in f: if ln.startswith("MemTotal:"): return round(int(ln.split()[1]) / 1024 / 1024, 1) return round(os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") / 1024**3, 1) except Exception: return 4.0 def _gpus() -> tuple[str, list]: # try torch first (authoritative) try: import torch if torch.cuda.is_available(): gs = [] for i in range(torch.cuda.device_count()): p = torch.cuda.get_device_properties(i) gs.append({"name": p.name, "vram_gb": round(p.total_memory / 1024**3, 1)}) return "cuda", gs if getattr(torch.backends, "mps", None) and torch.backends.mps.is_available(): return "mps", [{"name": "Apple GPU (MPS)", "vram_gb": _ram_gb() / 2}] except Exception: pass # fallback: nvidia-smi try: import subprocess out = subprocess.check_output( ["nvidia-smi", "--query-gpu=name,memory.total", "--format=csv,noheader,nounits"], text=True, timeout=6) gs = [] for ln in out.strip().splitlines(): name, mem = ln.split(",") gs.append({"name": name.strip(), "vram_gb": round(float(mem) / 1024, 1)}) if gs: return "cuda", gs except Exception: pass return "cpu", [] def detect_hardware() -> Hardware: backend, gpus = _gpus() try: free = round(shutil.disk_usage(ROOT).free / 1024**3, 1) except Exception: free = 0.0 return Hardware(backend=backend, cpu_cores=os.cpu_count() or 1, ram_gb=_ram_gb(), disk_free_gb=free, gpus=gpus) # ============================================================ # RECOMMENDATION (quality over speed; highest sustainable agency) # ============================================================ def _feasible_levels(hw: Hardware) -> list[dict]: # mirrors run on CPU -> gate on RAM + cores (quality over speed), not VRAM return [L for L in AGENCY_LEVELS if hw.ram_gb >= L["min_ram_gb"] and hw.cpu_cores >= L["min_cores"]] \ or [AGENCY_LEVELS[0]] def _llm_plan(hw: Hardware) -> dict: """Pick a precise, Apache-2.0 outer core for this hardware (precision, not power).""" if hw.backend == "cuda": v = hw.max_gpu_vram_gb if v >= 14: return {"model": "Qwen/Qwen2.5-3B-Instruct", "quant": "bf16", "device": 0, "max_memory_gib": min(11, int(v) - 4)} if v >= 10: return {"model": "Qwen/Qwen2.5-3B-Instruct", "quant": "bf16", "device": 0, "max_memory_gib": int(v) - 3} if v >= 6: return {"model": "Qwen/Qwen2.5-3B-Instruct", "quant": "4bit", "device": 0, "max_memory_gib": int(v) - 2} return {"model": "Qwen/Qwen2.5-1.5B-Instruct", "quant": "4bit", "device": 0, "max_memory_gib": max(2, int(v) - 1)} if hw.backend == "mps": return {"model": "Qwen/Qwen2.5-3B-Instruct", "quant": "fp16", "device": "mps", "max_memory_gib": int(hw.ram_gb // 3)} # CPU-only if hw.ram_gb >= 16: return {"model": "Qwen/Qwen2.5-1.5B-Instruct", "quant": "cpu-int8", "device": "cpu", "max_memory_gib": 0} return {"model": None, "quant": "retrieval-brain", "device": "cpu", "max_memory_gib": 0, "note": "Outer core off; inner genetic core + retrieval brain only."} def recommend(hw: Optional[Hardware] = None, target_floor: int = 3) -> dict: """Recommend the highest sustainable agency (quality over speed).""" hw = hw or detect_hardware() feasible = _feasible_levels(hw) chosen = feasible[-1] # highest sustainable = best quality mirrors = chosen["mirrors"] llm = _llm_plan(hw) multi_gpu = len(hw.gpus) > 1 return { "hardware": asdict(hw), "agency": { "level": chosen["level"], "name": chosen["name"], "recursion_mirrors": mirrors, "desc": chosen["desc"], "meets_autonomous_metacognition": chosen["level"] >= target_floor, }, "metacognition": { "sensor_meta_depth": mirrors, # recursion mirrors in the cortex "time_crystal_ensemble_depth": max(3, mirrors), "mind_reflection_depth": mirrors, # self-reflection recursion in the loop }, "outer_core": llm, "allocation": { "multi_gpu": multi_gpu, "llm_device": llm.get("device"), "training_devices": [i for i in range(1, len(hw.gpus))] if multi_gpu else [], "note": ("LLM on GPU0, genetics/training on remaining GPUs" if multi_gpu else "single device shared (quality-capped to avoid OOM)"), }, "web_intelligence": True, # always on (stdlib, light) "philosophy": "quality of thought over speed; highest sustainable recursion depth", } def to_summary(cfg: dict) -> str: hw, ag, mc = cfg["hardware"], cfg["agency"], cfg["metacognition"] oc = cfg["outer_core"] g = ", ".join(f"{x['name']} {x['vram_gb']}GB" for x in hw["gpus"]) or "none" return ( f"hardware : {hw['backend']} · {hw['cpu_cores']} cores · {hw['ram_gb']}GB RAM · GPUs[{g}]\n" f"agency : L{ag['level']} {ag['name']} · {ag['recursion_mirrors']} recursion mirrors " f"({'meets' if ag['meets_autonomous_metacognition'] else 'below'} autonomous metacognition)\n" f"mirrors : cortex={mc['sensor_meta_depth']} · ensemble={mc['time_crystal_ensemble_depth']} " f"· reflection={mc['mind_reflection_depth']}\n" f"outer : {oc.get('model') or 'retrieval-brain'} [{oc['quant']}] on {oc['device']} " f"(cap {oc['max_memory_gib']}GiB)\n" f"web : {cfg['web_intelligence']} · {cfg['allocation']['note']}" ) def save(cfg: dict, path: str = CONFIG_PATH) -> str: with open(path, "w", encoding="utf-8") as f: json.dump(cfg, f, indent=2) return path # ============================================================ # SETUP WIZARD # ============================================================ def wizard(interactive: bool = True, path: str = CONFIG_PATH) -> dict: hw = detect_hardware() cfg = recommend(hw) if not interactive: save(cfg, path) return cfg print("\n========== XERO SETUP WIZARD ==========\n") print(to_summary(cfg)) feasible = _feasible_levels(hw) print("\nAgency levels your hardware can sustain:") for L in feasible: mark = "→" if L["level"] == cfg["agency"]["level"] else " " print(f" {mark} L{L['level']} {L['name']:<26} {L['mirrors']:>2} mirrors — {L['desc']}") try: sel = input(f"\nChoose agency level [{cfg['agency']['level']}]: ").strip() if sel: lv = int(sel) pick = next((L for L in feasible if L["level"] == lv), None) if pick: cfg["agency"].update({"level": pick["level"], "name": pick["name"], "recursion_mirrors": pick["mirrors"], "desc": pick["desc"]}) m = pick["mirrors"] cfg["metacognition"] = {"sensor_meta_depth": m, "time_crystal_ensemble_depth": max(3, m), "mind_reflection_depth": m} purpose = input("Purpose / domain (free text, optional): ").strip() ref = input("Folder of reference files to ingest at startup (optional): ").strip() if purpose: cfg["purpose"] = purpose if ref: cfg["reference_files_dir"] = ref except (EOFError, KeyboardInterrupt): print("\n(non-interactive; keeping recommended config)") save(cfg, path) print(f"\nSaved -> {path}\n") return cfg if __name__ == "__main__": import sys if "--wizard" in sys.argv: wizard(interactive=True) else: hw = detect_hardware() cfg = recommend(hw) print("=== DETECTED + RECOMMENDED ===") print(to_summary(cfg)) print("\n=== FEASIBLE AGENCY LADDER ===") for L in _feasible_levels(hw): print(f" L{L['level']} {L['name']:<26} {L['mirrors']:>2} mirrors") save(cfg) print(f"\nconfig -> {CONFIG_PATH}")