feat(fifth-domain): add whole language system runtime
This commit is contained in:
parent
beb7fbd805
commit
e3e494338a
20 changed files with 1340 additions and 3 deletions
207
runtime/fifth-domain-language-system/scripts/language_system.py
Normal file
207
runtime/fifth-domain-language-system/scripts/language_system.py
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
#!/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", "曜冥", "铸渊", "/Volumes/JZAO", "ZCODE-TASK-",
|
||||
)
|
||||
EXPECTED_PUBLIC_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")
|
||||
functions = {item.get("public_function") for item in organs if item.get("public_extractable") is not False}
|
||||
if functions != {"MAIN_DOMAIN", "SUB_DOMAIN", "ZERO_DOMAIN", "ZERO_SENSE_DOMAIN"}:
|
||||
raise ValueError("private/public functional mapping incomplete")
|
||||
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.public-four-domain-language-system-template/v1":
|
||||
raise ValueError("unsupported public template schema")
|
||||
domains = manifest.get("domains", [])
|
||||
ids = [item.get("id") for item in domains]
|
||||
if len(domains) != 4 or set(ids) != EXPECTED_PUBLIC_DOMAINS or len(ids) != len(set(ids)):
|
||||
raise ValueError("public 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 public template: " + ",".join(leaked))
|
||||
if not str(manifest.get("responsible_human", "")).startswith("UNBOUND-"):
|
||||
raise ValueError("public human responsibility must remain unbound")
|
||||
if not str(manifest.get("persona_controller", "")).startswith("UNBOUND-"):
|
||||
raise ValueError("public persona controller must remain unbound")
|
||||
|
||||
|
||||
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": 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") == "public-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["public_function"] for item in private["organs"] if item.get("public_extractable") is not False}
|
||||
public_functions = {item["source_function"] for item in public["domains"]}
|
||||
expected = {
|
||||
"BROADCAST_AND_CANONICAL_FACT",
|
||||
"DYNAMIC_BRAINS_MODULES_SKILLS_RESOURCES",
|
||||
"LANGUAGE_REASONING_ARCHITECTURE_EXPERIMENT",
|
||||
"HUMAN_AUTHORITY_REALITY_BOUNDARY_EXECUTION",
|
||||
}
|
||||
if public_functions != expected or len(mapping) != 4:
|
||||
raise ValueError("private/public functional correspondence mismatch")
|
||||
return {
|
||||
"schema": "hololake.fifth-domain-language-system-meta-audit/v1",
|
||||
"outcome": "PASS",
|
||||
"private_organs": len(private["organs"]),
|
||||
"public_domains": len(public["domains"]),
|
||||
"legacy_routes": len(legacy["routes"]),
|
||||
"yaoming_current_id": "ICE-BB-0001",
|
||||
"history_preserved": True,
|
||||
"private_markers_in_public": 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"))
|
||||
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()
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Materialize the closed public four-domain blank template without private context."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
|
||||
EXPECTED_DOMAINS = {"DOMAIN-MAIN", "DOMAIN-SUB", "DOMAIN-ZERO", "DOMAIN-ZS"}
|
||||
ALLOWED_TOP = {
|
||||
"schema", "lifecycle", "system_id", "language_protocols", "responsible_human",
|
||||
"persona_controller", "number_namespace", "domains", "execution", "privacy",
|
||||
}
|
||||
|
||||
|
||||
def canonical(value):
|
||||
return (json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n").encode()
|
||||
|
||||
|
||||
def digest(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def load(path):
|
||||
if path.is_symlink() or not path.is_file() or path.stat().st_size > 1024 * 1024:
|
||||
raise ValueError("regular bounded template required")
|
||||
return json.loads(path.read_text())
|
||||
|
||||
|
||||
def validate(value):
|
||||
if value.get("schema") != "hololake.public-four-domain-language-system-template/v1":
|
||||
raise ValueError("unsupported public template")
|
||||
if set(value) != ALLOWED_TOP:
|
||||
raise ValueError("public template has unknown or missing top-level fields")
|
||||
ids = [item.get("id") for item in value.get("domains", [])]
|
||||
if len(ids) != 4 or set(ids) != EXPECTED_DOMAINS:
|
||||
raise ValueError("exactly four canonical public domains required")
|
||||
if not str(value.get("responsible_human", "")).startswith("UNBOUND-"):
|
||||
raise ValueError("responsible human must remain unbound")
|
||||
if not str(value.get("persona_controller", "")).startswith("UNBOUND-"):
|
||||
raise ValueError("persona controller must remain unbound")
|
||||
raw = canonical(value).decode()
|
||||
if any(marker in raw for marker in ("ICE-", "ZCODE-", "/Volumes/", "/Users/")):
|
||||
raise ValueError("private namespace or host path rejected")
|
||||
|
||||
|
||||
def write(path, data):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.NamedTemporaryFile(dir=path.parent, prefix=".public-world-", delete=False) as handle:
|
||||
handle.write(data)
|
||||
handle.flush()
|
||||
os.fsync(handle.fileno())
|
||||
temporary = Path(handle.name)
|
||||
temporary.replace(path)
|
||||
|
||||
|
||||
def build(template_path, output):
|
||||
value = load(template_path)
|
||||
validate(value)
|
||||
if output.exists() and any(output.iterdir()):
|
||||
raise ValueError("output directory must be absent or empty")
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
files = {}
|
||||
world = {
|
||||
"schema": "hololake.materialized-language-world/v1",
|
||||
"flavor": "public-four-domain",
|
||||
"source_sha256": digest(canonical(value)),
|
||||
"node_ids": [item["id"] for item in value["domains"]],
|
||||
"language_protocols": value["language_protocols"],
|
||||
}
|
||||
write(output / "WORLD.json", canonical(world))
|
||||
files["WORLD.json"] = digest((output / "WORLD.json").read_bytes())
|
||||
for item in value["domains"]:
|
||||
path = output / item["id"].lower() / "NODE.json"
|
||||
write(path, canonical(item))
|
||||
files[str(path.relative_to(output))] = digest(path.read_bytes())
|
||||
receipt = {
|
||||
"schema": "hololake.language-system-materialization-receipt/v1",
|
||||
"outcome": "PASS",
|
||||
"flavor": "public-four-domain",
|
||||
"source_sha256": digest(canonical(value)),
|
||||
"files": files,
|
||||
"model_api_used": False,
|
||||
"network_used": False,
|
||||
}
|
||||
write(output / "RECEIPT.json", canonical(receipt))
|
||||
return receipt
|
||||
|
||||
|
||||
def verify(root):
|
||||
receipt = load(root / "RECEIPT.json")
|
||||
for relative, expected in receipt.get("files", {}).items():
|
||||
path = root / relative
|
||||
if path.is_symlink() or not path.is_file() or digest(path.read_bytes()) != expected:
|
||||
raise ValueError("public output hash mismatch")
|
||||
return {"outcome": "PASS", "files_verified": len(receipt["files"])}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
build_parser = sub.add_parser("build")
|
||||
build_parser.add_argument("--template", 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)
|
||||
args = parser.parse_args()
|
||||
result = build(args.template, args.output) if args.command == "build" else verify(args.root)
|
||||
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue