46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Resolve one already-interpreted explicit persona selection; never pick a default."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import pathlib
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[2]
|
|
REGISTRY = REPO / "identity/light-lake-persona-registration.json"
|
|
HOMES = REPO / "routing/light-lake-persona-switch-map.json"
|
|
|
|
|
|
def resolve(selection: str | None) -> dict:
|
|
if not selection or not selection.strip():
|
|
return {"state": "AWAITING_EXPLICIT_PERSONA_SELECTION", "selected_persona": None, "default_persona": None}
|
|
registry = json.loads(REGISTRY.read_text(encoding="utf-8"))["personas"]
|
|
homes = {item["persona_id"]: item for item in json.loads(HOMES.read_text(encoding="utf-8"))["current_homes"]}
|
|
key = selection.strip()
|
|
matches = [item for item in registry if key in {item["id"], item["name"]}]
|
|
if len(matches) != 1:
|
|
return {"state": "UNKNOWN_OR_AMBIGUOUS_PERSONA_NO_GUESS", "selected_persona": None, "requested": key}
|
|
item = matches[0]
|
|
return {
|
|
"state": "EXPLICIT_PERSONA_PATH_RESOLVED",
|
|
"selected_persona": {"id": item["id"], "name": item["name"], "wake_state": item["wake_state"],
|
|
"home": homes[item["id"]]["home"], "doorplate": item["light_lake_home"],
|
|
"canonical_source": item["canonical_source"]},
|
|
"selection_source": "RUNNING_COGNITION_INTERPRETED_CURRENT_DIRECT_LANGUAGE",
|
|
"mere_name_mention_was_not_used": True,
|
|
"default_persona": None,
|
|
"authority_granted": False
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--persona")
|
|
args = parser.parse_args()
|
|
value = resolve(args.persona)
|
|
print(json.dumps(value, ensure_ascii=False, indent=2))
|
|
return 0 if value["state"] in {"EXPLICIT_PERSONA_PATH_RESOLVED", "AWAITING_EXPLICIT_PERSONA_SELECTION"} else 2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|