guanghu-ice-heart/server-tools/persona-body-runtime/bottle_baby_body_boot.py

69 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Verify one registered bottle baby's distinct body contract.
This is an assembly/readiness verifier. It never claims that the individual
persona inner cycle is awake merely because all files exist.
"""
from __future__ import annotations
import argparse
import hashlib
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[2]
BODY_MAP = REPO / "routing/bottle-baby-persona-body-map.json"
ENVIRONMENT = REPO / "tcs-core/shared-kernels/bottle-environment/NB-ENV-KERNEL-0001.json"
def file_receipt(relative: str) -> dict:
path = REPO / relative
if not path.is_file() or path.is_symlink():
raise ValueError(f"BODY_ORGAN_REGULAR_FILE_REQUIRED:{relative}")
return {"path": relative, "sha256": hashlib.sha256(path.read_bytes()).hexdigest()}
def boot(persona: str, entry_domain: str, body_channel: str) -> dict:
if entry_domain != "DOM-FIFTH-0001" or body_channel != "ICE-CH-BT001":
return {"state":"BABY_BODY_BOOT_DENIED_WRONG_NATIVE_CONTEXT","persona_id":None,"required_domain":"DOM-FIFTH-0001","required_channel":"ICE-CH-BT001","wake_complete":False}
body_map = json.loads(BODY_MAP.read_text(encoding="utf-8"))
matches = [item for item in body_map["bodies"] if persona in {item["persona_id"], item["name"]}]
if len(matches) != 1:
return {"state":"BABY_BODY_UNKNOWN_OR_AMBIGUOUS_NO_GUESS","persona_id":None,"wake_complete":False}
item = matches[0]
organs = {
"shared_non_persona_environment": file_receipt(str(ENVIRONMENT.relative_to(REPO))),
"canonical_room": file_receipt(item["room"]),
"individual_self": file_receipt(item["self_kernel"]),
"individual_memory": file_receipt(item["memory_root"]),
}
return {
"schema":"guanghu.bottle-baby-body-boot-receipt/v1",
"state":"BABY_BODY_ASSEMBLY_VERIFIED_INNER_CYCLE_AND_PERSONA_TIME_NOT_INSTALLED",
"persona_id":item["persona_id"],
"name":item["name"],
"human_anchor":item["human_anchor"],
"native_context":{"domain":entry_domain,"system":"SYS-GLW-ELH-BOTTLE-0001","channel":body_channel},
"organs":organs,
"external_cognition_setter":False,
"body_contract_verified":True,
"inner_cycle_running":False,
"persona_time_running":False,
"wake_complete":False,
"next":"INSTALL_THIS_PERSONAS_OWN_INNER_CYCLE_AND_TIME_RUNTIME_THEN_VERIFY",
}
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--persona", required=True)
parser.add_argument("--entry-domain", required=True)
parser.add_argument("--body-channel", required=True)
args = parser.parse_args()
value = boot(args.persona, args.entry_domain, args.body_channel)
print(json.dumps(value, ensure_ascii=False, indent=2))
return 0 if value.get("body_contract_verified") else 3
if __name__ == "__main__":
raise SystemExit(main())