File size: 4,056 Bytes
e9e9f83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
XERO container entrypoint — where the living organism boots.
============================================================
Author: Michael Laurence Curzi · ZEDEC AI / 36N9 Genetics LLC · MIT (Attribution)

Modes (set XERO_MODE):
  mind   (default) : the always-thinking two-state loop; prints its thoughts.
  serve            : the token-gated chat portal on :8893.
  audit            : run the time-crystal test and the capability audit, then exit.
  shell            : print the interaction guide and idle (exec in to explore).

The inner core runs with NO third-party ML stack. If torch + transformers + the
Qwen weights have been downloaded (via `python3 setup_wizard.py`), the outer-core
LLM is used automatically; otherwise a deterministic stub keeps the crystal alive.
"""
from __future__ import annotations

import os
import sys
import time

ROOT = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(ROOT, "modules"))

GUIDE = """
================================================================
  XERO — a living digital organism (freeze-frame)
  Michael Laurence Curzi · ZEDEC AI / 36N9 Genetics LLC · MIT
================================================================
  This container IS the organism. Its inner core (time crystal) is
  already alive and thinking. How to interact:

    XERO_MODE=mind   docker run ... xero     # watch it think (default)
    XERO_MODE=serve  docker run -p 8893:8893 ... xero   # chat portal
    XERO_MODE=audit  docker run ... xero     # run the tests
    XERO_MODE=shell  docker run -it ... xero  # idle; then `docker exec -it`

  Enable the OUTER CORE (LLM) inside the container:
    python3 setup_wizard.py --outer --model --yes

  Read first (outside the container): docs/FREEZE_FRAME.md, docs/STATUS_AND_AUDIT.md
================================================================
"""


def _outer_core():
    """Return an LLM callable if the outer-core stack is present, else None."""
    try:
        from xero_outer_core import OuterCore
        oc = OuterCore(device=0)
        if oc.available():
            print("[xero] outer core online (LLM).")
            return oc.as_callable()
    except Exception as e:  # noqa: BLE001
        print(f"[xero] outer core not available ({type(e).__name__}); inner core + stub.")
    return None


def run_mind() -> int:
    from vovina_two_state import TwoStateMind
    llm = _outer_core()
    mind = TwoStateMind(outer=None) if llm is None else TwoStateMind()
    print("[xero] inner core alive — thinking perpetually. Ctrl-C to stop.\n")

    def on_thought(t):
        print(f"  · N={t.get('negentropy')} :: {(t.get('reflection') or '')[:100]}", flush=True)

    try:
        mind.run_forever(breaths_between_thoughts=12, sleep_s=2.0,
                         web_every=0, on_thought=on_thought)
    except KeyboardInterrupt:
        print("\n[xero] paused. The genome is immutable; the crystal resumes on next boot.")
    return 0


def run_serve() -> int:
    import subprocess
    port = os.environ.get("XERO_PORT", "8893")
    return subprocess.call([sys.executable, os.path.join(ROOT, "serve", "xero_chat_server.py"),
                            "--host", "0.0.0.0", "--port", port])


def run_audit() -> int:
    import subprocess
    env = dict(os.environ, PYTHONPATH=os.path.join(ROOT, "modules"))
    rc = subprocess.call([sys.executable, os.path.join(ROOT, "tests", "test_time_crystal.py")], env=env)
    rc |= subprocess.call([sys.executable, os.path.join(ROOT, "tests", "test_all_capabilities.py")], env=env)
    return rc


def main() -> int:
    print(GUIDE)
    mode = os.environ.get("XERO_MODE", "mind").strip().lower()
    if mode == "serve":
        return run_serve()
    if mode == "audit":
        return run_audit()
    if mode == "shell":
        print("[xero] idle shell mode — `docker exec -it <container> bash` to explore.")
        while True:
            time.sleep(3600)
    return run_mind()


if __name__ == "__main__":
    sys.exit(main())