The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(photon): look up the iMessage line before the opt-in wait; skip the wait when there is none
Teknium9bc94eb21dce
diff --git a/plugins/platforms/photon/cli.py b/plugins/platforms/photon/cli.pyindex 7296f25629f..8a4fc414373 100644--- a/plugins/platforms/photon/cli.py+++ b/plugins/platforms/photon/cli.py@@ -180,12 +180,17 @@ def _cmd_setup(args: argparse.Namespace) -> int:registered_user_id = user.get("id")# The number to text the agent is the user's assigned line ("TEXTS ON"); shared-number# plans have no dedicated /lines entry.- agent_number = photon_auth.user_assigned_line(user)+ agent_number = photon_auth.user_assigned_line(user) or _lookup_imessage_line(token, dashboard_id)# Opt-in gate: Photon only routes a number whose user row carries meta.opt_in, which the# service sets once the human texts the assigned line from their phone (the API cannot# set it). Name the line and wait for the opt-in; a re-run on an opted-in row passes.if photon_auth.user_opted_in(user):print(" ✓ number is opted in — routing is live")+ elif not agent_number: # nothing to text yet, so a wait could never end in an opt-in+ routing_live = False+ print(f" ⚠ No iMessage line is assigned to {phone} yet — skipping the opt-in wait.\n"+ f" Once the Photon dashboard shows your line, text it once from {phone},\n"+ " then check with `hermes photon status`.")else:opted = _wait_for_opt_in(dashboard_id, secret, phone, agent_number)routing_live = opted is not None@@ -193,13 +198,8 @@ def _cmd_setup(args: argparse.Namespace) -> int:# Otherwise the gateway denies the operator's own inbound and has no cron home space._autoconfigure_access(phone)# 5. Surface the agent's iMessage number.- if not agent_number:- try:- line = photon_auth.get_imessage_line(token, dashboard_id)- if line:- agent_number = line.get("phoneNumber")- except Exception as e:- print(f" (could not fetch the assigned line: {e})", file=sys.stderr)+ if not agent_number and not phone: # the phone path already looked the line up+ agent_number = _lookup_imessage_line(token, dashboard_id)if agent_number:print("\n" + "\n".join((color("┌─ Your agent's iMessage number ───────────────────────────────", Colors.GREEN),@@ -238,6 +238,16 @@ def _cmd_setup(args: argparse.Namespace) -> int:return 0+def _lookup_imessage_line(token: str, dashboard_id: str) -> Optional[str]:+ """The project's dedicated iMessage line (fallback when the user row names none)."""+ try:+ line = photon_auth.get_imessage_line(token, dashboard_id)+ except (photon_auth.httpx.HTTPError, RuntimeError, ValueError) as e: # transport / status / bad JSON+ print(f" (could not fetch the assigned line: {e})", file=sys.stderr)+ return None+ return line.get("phoneNumber") if line else None++_OPT_IN_WAIT_S = 300diff --git a/tests/plugins/platforms/photon/test_setup_access.py b/tests/plugins/platforms/photon/test_setup_access.pyindex 9b87994e9e7..0286b808a56 100644--- a/tests/plugins/platforms/photon/test_setup_access.py+++ b/tests/plugins/platforms/photon/test_setup_access.py@@ -173,3 +173,35 @@ def test_setup_without_opt_in_does_not_report_complete(assert rc == 0assert "setup complete" not in outassert "routing is NOT live" in out and "+16282679185" in out++[email protected]("dedicated_line", ["+16282679185", None])+def test_opt_in_wait_always_names_a_line_to_text(+ monkeypatch: pytest.MonkeyPatch, capsys, dedicated_line,+) -> None:+ """A row with no assignedPhoneNumber: the project-line lookup runs BEFORE the wait, and+ with no line at all the wait is skipped (the user would have nothing to text)."""+ monkeypatch.setattr(cli.photon_auth, "load_photon_token", lambda: "token")+ monkeypatch.setattr(cli.photon_auth, "check_photon_token_valid", lambda token: True)+ monkeypatch.setattr(cli.photon_auth, "load_dashboard_project_id", lambda: "dashboard")+ monkeypatch.setattr(cli.photon_auth, "load_project_credentials", lambda: ("dashboard", "s"))+ monkeypatch.setattr(cli.photon_auth, "list_users", lambda pid, secret: [])+ monkeypatch.setattr(cli.photon_auth, "store_project_credentials", lambda **kwargs: None)+ monkeypatch.setattr(cli.photon_auth, "register_user_if_absent", lambda *a, **k: (+ {"id": "u1", "phoneNumber": "+15551234567", "meta": {}}, True))+ monkeypatch.setattr(cli.photon_auth, "get_imessage_line", lambda token, pid: (+ {"phoneNumber": dedicated_line} if dedicated_line else None))+ monkeypatch.setattr(cli.photon_auth, "store_user_numbers", lambda **kwargs: None)+ waited: list = []+ monkeypatch.setattr(cli, "_wait_for_opt_in", lambda d, s, phone, line: waited.append(line))++ rc = cli._cmd_setup(argparse.Namespace(+ project_name=None, phone="+15551234567", first_name=None, last_name=None,+ email=None, no_browser=True, skip_sidecar_install=True))++ out = capsys.readouterr().out+ assert rc == 0 and "setup complete" not in out+ if dedicated_line:+ assert waited == [dedicated_line]+ else:+ assert waited == [] and "skipping the opt-in wait" in out and "hermes photon status" in out