#!/usr/bin/env python3 """Materialize and verify the Fifth Domain or its public four-domain template.""" import argparse import hashlib import json import os from pathlib import Path import tempfile ROOT = Path(__file__).resolve().parents[1] PRIVATE_MARKERS = ( "ICE-GL∞", "ICE-P-ZY001", "ICE-BB-0001", "ICE-CH-HB001", "ICE-CH-ZC001", "曜冥", "铸渊", "LPM-SB-0001", "TCS-iZero∞", "/Volumes/JZAO", "ZCODE-TASK-", ) EXPECTED_ENTERPRISE_DOMAINS = {"DOMAIN-MAIN", "DOMAIN-SUB", "DOMAIN-ZERO", "DOMAIN-ZS"} def sha_bytes(data: bytes) -> str: return hashlib.sha256(data).hexdigest() def canonical_json(value) -> bytes: return (json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n").encode() def load_json(path: Path): if path.is_symlink() or not path.is_file(): raise ValueError(f"regular JSON file required: {path}") if path.stat().st_size > 4 * 1024 * 1024: raise ValueError(f"JSON file too large: {path}") return json.loads(path.read_text()) def atomic_write(path: Path, data: bytes): path.parent.mkdir(parents=True, exist_ok=True) with tempfile.NamedTemporaryFile(dir=path.parent, prefix=".language-system-", delete=False) as handle: handle.write(data) handle.flush() os.fsync(handle.fileno()) temporary = Path(handle.name) temporary.replace(path) def validate_private(manifest): if manifest.get("schema") != "hololake.fifth-domain-language-system/v1": raise ValueError("unsupported private manifest schema") if manifest.get("domain_id") != "DOM-FIFTH-0001": raise ValueError("private domain id mismatch") if manifest.get("human_anchor_id") != "ICE-GL∞" or manifest.get("persona_controller_id") != "ICE-P-ZY001": raise ValueError("private controller coordinates mismatch") organs = manifest.get("organs", []) ids = [item.get("id") for item in organs] paths = [item.get("path") for item in organs] if len(organs) != 5 or len(set(ids)) != 5 or len(set(paths)) != 5: raise ValueError("private system requires five unique organs") counterparts = {item.get("enterprise_counterpart") for item in organs if item.get("public_extractable") is not False} if counterparts != EXPECTED_ENTERPRISE_DOMAINS: raise ValueError("private/enterprise functional mapping incomplete") if manifest.get("responsibility") != "GUANGHU_LANGUAGE_WORLD_SOURCE_LANGUAGE_ARCHITECTURE_AND_SYSTEM_EVOLUTION_STEWARDSHIP": raise ValueError("Fifth Domain language stewardship missing") if manifest.get("enterprise_reality_control") is not False: raise ValueError("Fifth Domain must not own enterprise reality control") if manifest.get("bingshuo_custom_hololake", {}).get("private_kernel") != "TCS-iZero∞": raise ValueError("BingShuo private HoloLake kernel mismatch") enterprise = manifest.get("enterprise_reality", {}) if enterprise.get("carrier") != "ENTERPRISE_PORTAL" or enterprise.get("reality_controller") != "GUANGHU_TEAM": raise ValueError("Guanghu Team enterprise reality boundary missing") if enterprise.get("team_may_enter_fifth_domain_without_authorization") is not False: raise ValueError("Guanghu Team may not inherit Fifth Domain access") personas = {item.get("id"): item for item in manifest.get("personas", [])} if personas.get("ICE-BB-0001", {}).get("name") != "曜冥": raise ValueError("Yaoming current identity mapping missing") def validate_public(manifest): if manifest.get("schema") != "hololake.enterprise-four-domain-governance-template/v2": raise ValueError("unsupported enterprise template schema") domains = manifest.get("domains", []) ids = [item.get("id") for item in domains] if len(domains) != 4 or set(ids) != EXPECTED_ENTERPRISE_DOMAINS or len(ids) != len(set(ids)): raise ValueError("enterprise template requires exactly four canonical domains") raw = canonical_json(manifest).decode() leaked = [marker for marker in PRIVATE_MARKERS if marker in raw] if leaked: raise ValueError("private markers leaked into enterprise template: " + ",".join(leaked)) if manifest.get("carrier") != "ENTERPRISE_PORTAL" or manifest.get("embedded_in_hololake") is not False: raise ValueError("enterprise domains must stay in the portal and outside HoloLake") if manifest.get("reality_controller") != "GUANGHU_TEAM": raise ValueError("enterprise domains require Guanghu Team reality control") if not str(manifest.get("responsible_human_members", "")).startswith("PENDING_"): raise ValueError("Guanghu Team member registry must remain explicit pending state") if any(item.get("reality_controller") != "GUANGHU_TEAM" for item in domains): raise ValueError("each enterprise domain requires Guanghu Team responsibility") zero_sense = next(item for item in domains if item["id"] == "DOMAIN-ZS") if zero_sense.get("public_access") is not False: raise ValueError("Zero-Sense Domain must remain restricted") if manifest.get("fifth_domain", {}).get("embedded") is not False: raise ValueError("private Fifth Domain may not be embedded in enterprise template") def validate_legacy(routes): if routes.get("schema") != "hololake.language-system-legacy-route-map/v1": raise ValueError("unsupported legacy route schema") seen = set() for route in routes.get("routes", []): legacy = route.get("legacy") if not legacy or legacy in seen or not route.get("current") or not route.get("status"): raise ValueError("legacy routes must be unique and explicit") seen.add(legacy) required = {"GEN∞-BB-YM", "TCS-YM-0001∞", "TCS-0004∞", "TCS-0002∞", "TCS-i Zero", "LDOS"} if not required.issubset(seen): raise ValueError("required historical routes missing") def build(manifest_path: Path, output: Path, flavor: str): manifest = load_json(manifest_path) if flavor == "fifth-domain": validate_private(manifest) nodes = [(item["id"], item["path"], item) for item in manifest["organs"]] else: validate_public(manifest) nodes = [(item["id"], item["id"].lower(), item) for item in manifest["domains"]] if output.exists() and any(output.iterdir()): raise ValueError("output directory must be absent or empty") output.mkdir(parents=True, exist_ok=True) written = {} world = { "schema": "hololake.materialized-language-world/v1", "flavor": "enterprise-four-domain" if flavor in {"public-four-domain", "enterprise-four-domain"} else flavor, "source_schema": manifest["schema"], "source_sha256": sha_bytes(canonical_json(manifest)), "node_ids": [node[0] for node in nodes], "language_protocols": manifest["language_protocols"], } atomic_write(output / "WORLD.json", canonical_json(world)) written["WORLD.json"] = sha_bytes((output / "WORLD.json").read_bytes()) for node_id, relative, value in nodes: node_path = output / relative / "NODE.json" atomic_write(node_path, canonical_json(value)) written[str(node_path.relative_to(output))] = sha_bytes(node_path.read_bytes()) receipt = { "schema": "hololake.language-system-materialization-receipt/v1", "outcome": "PASS", "flavor": flavor, "source": str(manifest_path.resolve()), "source_sha256": sha_bytes(canonical_json(manifest)), "files": written, "model_api_used": False, "network_used": False, } atomic_write(output / "RECEIPT.json", canonical_json(receipt)) return receipt def verify(root: Path): receipt = load_json(root / "RECEIPT.json") if receipt.get("outcome") != "PASS": raise ValueError("materialization receipt is not PASS") for relative, expected in receipt.get("files", {}).items(): path = root / relative if path.is_symlink() or not path.is_file() or sha_bytes(path.read_bytes()) != expected: raise ValueError(f"materialized file mismatch: {relative}") world = load_json(root / "WORLD.json") if world.get("flavor") == "enterprise-four-domain": raw = "".join(path.read_text() for path in root.rglob("*.json") if path.name != "RECEIPT.json") leaked = [marker for marker in PRIVATE_MARKERS if marker in raw] if leaked: raise ValueError("private markers leaked into public output") return {"outcome": "PASS", "root": str(root.resolve()), "files_verified": len(receipt["files"])} def meta_audit(private_path: Path, public_path: Path, legacy_path: Path): private = load_json(private_path) public = load_json(public_path) legacy = load_json(legacy_path) validate_private(private) validate_public(public) validate_legacy(legacy) mapping = {item["enterprise_counterpart"] for item in private["organs"] if item.get("public_extractable") is not False} public_ids = {item["id"] for item in public["domains"]} if mapping != EXPECTED_ENTERPRISE_DOMAINS or public_ids != EXPECTED_ENTERPRISE_DOMAINS: raise ValueError("private/enterprise functional correspondence mismatch") return { "schema": "hololake.fifth-domain-language-system-meta-audit/v1", "outcome": "PASS", "private_organs": len(private["organs"]), "enterprise_domains": len(public["domains"]), "legacy_routes": len(legacy["routes"]), "yaoming_current_id": "ICE-BB-0001", "history_preserved": True, "private_markers_in_enterprise": False, "guanghu_team_reality_controller": True, "hololake_embeds_enterprise_domains": False, "external_reality_claimed_from_history": False, } def main(): parser = argparse.ArgumentParser() sub = parser.add_subparsers(dest="command", required=True) build_parser = sub.add_parser("build") build_parser.add_argument("--flavor", required=True, choices=("fifth-domain", "public-four-domain", "enterprise-four-domain")) build_parser.add_argument("--manifest", required=True, type=Path) build_parser.add_argument("--output", required=True, type=Path) verify_parser = sub.add_parser("verify") verify_parser.add_argument("--root", required=True, type=Path) audit_parser = sub.add_parser("meta-audit") audit_parser.add_argument("--private", default=ROOT / "system/fifth-domain-system.json", type=Path) audit_parser.add_argument("--public", default=ROOT / "system/public-four-domain-template.json", type=Path) audit_parser.add_argument("--legacy", default=ROOT / "system/legacy-route-map.json", type=Path) args = parser.parse_args() if args.command == "build": result = build(args.manifest, args.output, args.flavor) elif args.command == "verify": result = verify(args.root) else: result = meta_audit(args.private, args.public, args.legacy) print(json.dumps(result, ensure_ascii=False, sort_keys=True)) if __name__ == "__main__": main()