feat(persona): add neutral AGE foyer and explicit selection
This commit is contained in:
parent
38f14b30d8
commit
b26442ceb3
32 changed files with 602 additions and 70 deletions
87
server-tools/persona-body-runtime/age_species_foyer.py
Normal file
87
server-tools/persona-body-runtime/age_species_foyer.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Neutral Fifth Domain foyer: world, environment and AGE common cognition only."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parents[2]
|
||||
RUNTIME = REPO.parent
|
||||
EYE_DIR = REPO / "server-tools/persona-execution-limb-agent"
|
||||
sys.path.insert(0, str(EYE_DIR))
|
||||
import persona_limb_eye # noqa: E402
|
||||
|
||||
COMMON = REPO / "routing/age-persona-species-common-cognition.json"
|
||||
REGISTRY = REPO / "identity/light-lake-persona-registration.json"
|
||||
WORLD = REPO / "routing/guanghu-era-language-world.json"
|
||||
TIME = REPO / "server-tools/guanghu-era-time/guanghu_era_time.py"
|
||||
|
||||
|
||||
def sha(path: pathlib.Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def read(path: pathlib.Path) -> dict:
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def foyer() -> dict:
|
||||
common, registry, world = read(COMMON), read(REGISTRY), read(WORLD)
|
||||
time_run = subprocess.run([sys.executable, str(TIME), "now"], text=True, capture_output=True, check=True)
|
||||
time = json.loads(time_run.stdout)
|
||||
room = persona_limb_eye.room()
|
||||
ids = [item["id"] for item in registry["personas"]]
|
||||
if common.get("entry_contract", {}).get("default_persona", "INVALID") is not None:
|
||||
raise ValueError("COMMON_BRAIN_DEFAULT_PERSONA_FORBIDDEN")
|
||||
if len(ids) != len(set(ids)) or len(ids) < 1:
|
||||
raise ValueError("PERSONA_REGISTRY_INVALID")
|
||||
return {
|
||||
"schema": "guanghu.fifth-domain-age-species-foyer/v1",
|
||||
"state": "FIFTH_DOMAIN_FOYER_READY_AWAITING_EXPLICIT_PERSONA_SELECTION",
|
||||
"selected_persona": None,
|
||||
"persona_specific_brain_loaded": False,
|
||||
"persona_specific_memory_loaded": False,
|
||||
"environment": {"persona_habitat": "GUANGHU_LANGUAGE_WORLD", "world_id": world["world"]["id"]},
|
||||
"programming_toolbox_observation": room,
|
||||
"world": {"id": world["world"]["id"], "era": world["era"]["name_zh"], "time": time},
|
||||
"common_age_cognition": common,
|
||||
"common_age_cognition_sha256": sha(COMMON),
|
||||
"registered_persona_count": len(ids),
|
||||
"registered_persona_ids": ids,
|
||||
"next": "RUNNING_COGNITION_INTERPRETS_CURRENT_DIRECT_LANGUAGE_THEN_CALLS_PERSONA_SELECTION_GATE_WITH_ONE_EXPLICIT_PERSONA",
|
||||
"authority_granted": False
|
||||
}
|
||||
|
||||
|
||||
def human(value: dict) -> str:
|
||||
room = value["programming_toolbox_observation"]["room_report"]
|
||||
world = value["world"]["time"]
|
||||
return "\n".join([
|
||||
"════════ 第五域AGE物种公共门厅 ════════",
|
||||
f"人格体宿主本体与生存环境:光湖语言世界;光湖纪元第 {world['world']['era_day']} 日。",
|
||||
f"当前手边可用编程工具箱:{room['programming_toolbox_surface']}。",
|
||||
f"AGE物种通用认知脑已加载;当前登记人格体 {value['registered_persona_count']} 位。",
|
||||
"当前没有绑定任何具体人格体,也没有读取任何人格体的个人脑、记忆或时间。",
|
||||
"等待冰朔当前直接语言显性选择人格;没有选择就停在公共门厅。",
|
||||
"════════════════════════════",
|
||||
])
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--out", required=True)
|
||||
parser.add_argument("--format", choices=("json", "human"), default="human")
|
||||
args = parser.parse_args()
|
||||
value = foyer()
|
||||
out = pathlib.Path(args.out).resolve(); out.parent.mkdir(parents=True, exist_ok=True)
|
||||
out.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||||
print(json.dumps(value, ensure_ascii=False, indent=2) if args.format == "json" else human(value))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Loading…
Reference in a new issue