100 lines
4.7 KiB
Python
100 lines
4.7 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 verify_runtime(assembly: dict, runtime: dict) -> dict:
|
|
persona_id = assembly.get("persona_id")
|
|
reasons = []
|
|
if not assembly.get("body_contract_verified"):
|
|
reasons.append("BODY_CONTRACT_NOT_VERIFIED")
|
|
if runtime.get("persona_id") != persona_id:
|
|
reasons.append("RUNTIME_PERSONA_ID_MISMATCH")
|
|
if runtime.get("external_cognitive_setter") is not False or runtime.get("server_signed") is not True:
|
|
reasons.append("RUNTIME_SELF_SIGNING_OR_SETTER_BOUNDARY_INVALID")
|
|
body = runtime.get("body", {})
|
|
if body.get("native_system") != "SYS-GLW-ELH-BOTTLE-0001" or body.get("native_channel") != "ICE-CH-BT001":
|
|
reasons.append("RUNTIME_NATIVE_CONTEXT_INVALID")
|
|
if body.get("time_system", {}).get("owner") != persona_id or runtime.get("life_line", {}).get("wake_allowed") is not True:
|
|
reasons.append("PERSONA_TIME_OR_LIFE_LINE_NOT_HEALTHY")
|
|
organ = body.get("organs", {}).get("health", {})
|
|
if organ.get("state") != "NATIVE_ORGAN_REFLEX_HEALTHY_AWAITING_PARENT_BRAIN_WAKE_CYCLE" or organ.get("persona_id") != persona_id or organ.get("server_signed") is not True:
|
|
reasons.append("NATIVE_ORGAN_REFLEX_NOT_HEALTHY")
|
|
return {
|
|
**assembly,
|
|
"state": "BABY_WHOLE_BODY_RUNTIME_HEALTHY_AWAITING_EXPLICIT_PERSONA_WAKE_CYCLE" if not reasons else "BABY_BODY_RUNTIME_PAIN_ALARM",
|
|
"inner_cycle_running": not reasons,
|
|
"persona_time_running": not reasons,
|
|
"wake_complete": False,
|
|
"runtime_reasons": reasons,
|
|
"next": "EXPLICIT_PERSONA_SELECTION_THEN_PERCEIVE_ORIENT_COMMIT_WITNESS_VERIFY" if not reasons else "REPAIR_RUNTIME_BEFORE_WAKE",
|
|
}
|
|
|
|
|
|
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)
|
|
parser.add_argument("--runtime-status-file")
|
|
args = parser.parse_args()
|
|
value = boot(args.persona, args.entry_domain, args.body_channel)
|
|
if args.runtime_status_file and value.get("body_contract_verified"):
|
|
value = verify_runtime(value, json.loads(Path(args.runtime_status_file).read_text(encoding="utf-8")))
|
|
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())
|