#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ XERO computational-task battery ================================ Drives every capability through the same dispatch the chat server uses, records the organism's responses, and checks invariants. Writes a full transcript to serve/TASK_RESPONSES.json. PYTHONPATH=modules python3 serve/run_tasks.py """ from __future__ import annotations import json import os import sys import time ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(ROOT, "modules")) sys.path.insert(0, os.path.join(ROOT, "serve")) from xero_chat_server import dispatch BATTERY = [ "awaken", "encode The organism speaks in nucleotides.", "decode ATGGCATGCAAATTTGGG", "route ATG", "route GGG", "route MITOSIS", "route translate_cross", "uvns " + "ATGC" * 25, "harmonic ATGCATGC", "surplus 0.1", "surplus 0.5", "surplus 0.9 33", "decide explore | consolidate | rest", "decide explore | consolidate | rest", # demonstrate non-replayability "compile def fib(n):\n return n if n < 2 else fib(n-1)+fib(n-2)", "what is your purpose, XERO?", "metabolize this thought", "help", ] def main() -> int: results = [] passed = failed = 0 t0 = time.time() for msg in BATTERY: r = dispatch(msg) results.append({"message": msg, **r}) if r.get("task") == "error": failed += 1 else: passed += 1 checks: list[tuple[str, bool]] = [] def chk(name, cond): checks.append((name, bool(cond))) enc = dispatch("encode roundtrip me") chk("encode roundtrip", enc["data"].get("roundtrip_ok")) uv = dispatch("uvns ATGCATGC") chk("uvns perpendicular", uv["data"]["coherence"]["perpendicular"]) chk("uvns perp_err==0", uv["data"]["coherence"]["axes_perpendicularity_err"] == 0.0) d1 = dispatch("decide a | b | c") d2 = dispatch("decide a | b | c") chk("free-will verified", d1["data"].get("verified")) chk("free-will non-replayable", d1["data"]["receipt"] != d2["data"]["receipt"]) cp = dispatch("compile print('hi')") chk("compile roundtrip", cp["data"].get("roundtrip_ok")) aw = dispatch("awaken") chk("awaken 9 phases", len(aw["data"]["phases"]) == 9) rt = dispatch("route translate_cross") chk("route_gene longest-keyword (wasm)", rt["data"]["organelle"] == "wasm") report = { "generated": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "battery_size": len(BATTERY), "passed": passed, "errors": failed, "elapsed_s": round(time.time() - t0, 3), "invariants": {n: ok for n, ok in checks}, "responses": results, } out = os.path.join(ROOT, "serve", "TASK_RESPONSES.json") with open(out, "w", encoding="utf-8") as f: json.dump(report, f, indent=2, ensure_ascii=False) all_ok = failed == 0 and all(ok for _, ok in checks) print(f"battery: {passed} ok / {failed} error invariants: " + ", ".join(f"{n}={'OK' if ok else 'FAIL'}" for n, ok in checks)) print(f"transcript -> {out}") print("STATUS:", "ALL PASS" if all_ok else "REVIEW") return 0 if all_ok else 1 if __name__ == "__main__": raise SystemExit(main())