The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): open a gated Webapp to its sign-in page
emozilla288a5364fab0
diff --git a/gateway/webapp_listener.py b/gateway/webapp_listener.pyindex bead1d3193f..7f7a9b8b047 100644--- a/gateway/webapp_listener.py+++ b/gateway/webapp_listener.py@@ -193,6 +193,10 @@ def register_control_verbs(runner, home) -> None:raise ValueError("profile must be a profile name")query = f"?profile={profile}" if profile else "" # the page opens on that profilestatus, web = serving()+ from hermes_cli.web_server_surface import private_launch+ if not private_launch(web.app.state):+ # Behind the dashboard's sign-in the page asks for it; a launch link opens only a private Webapp.+ return {"url": f"{status['url']}/{query}", "private": False, "expires_in_seconds": None, "sign_in": True}if not _one_use_links_work():return {"url": f"{status['url']}/{query}#hermes-session={web._SESSION_TOKEN}", "private": True,"expires_in_seconds": None}diff --git a/hermes_cli/webapp_launcher.py b/hermes_cli/webapp_launcher.pyindex 09fbca7c0db..1b1681f0ade 100644--- a/hermes_cli/webapp_launcher.py+++ b/hermes_cli/webapp_launcher.py@@ -166,6 +166,13 @@ def cmd_webapp(args) -> int:if not response.get("ok"):return _explain_refused_launch(target, response)link = response["result"]+ if link.get("sign_in"):+ # The Webapp is behind the dashboard's sign-in: the page asks for it, so its address is no secret.+ if not args.no_open and _open(link["url"]):+ print("Opened the Webapp in your browser. Sign in with your dashboard account.")+ else:+ print(f"Open the Webapp and sign in with your dashboard account: {link['url']}")+ return 0if link.get("private"):# The gateway's own credential (macOS, where a one-use link cannot be redeemed): for the user# to open, never for a browser launcher whose arguments other processes can read.diff --git a/tests/gateway/test_webapp_listener.py b/tests/gateway/test_webapp_listener.pyindex 944b9d32d77..f33b94be559 100644--- a/tests/gateway/test_webapp_listener.py+++ b/tests/gateway/test_webapp_listener.py@@ -179,7 +179,8 @@ def test_webapp_verbs_answer_only_an_authenticated_same_user_peer(monkeypatch, tdef test_where_one_use_links_cannot_be_redeemed_the_launcher_gets_the_private_link(monkeypatch, tmp_path):monkeypatch.setattr(webapp, "_one_use_links_work", lambda: False) # macOSrunner, _, _ = _start_runtime_api(monkeypatch, tmp_path, "webapp:\n enabled: true\n port: 9555\n")- web = SimpleNamespace(_SESSION_TOKEN="s" * 43, app=SimpleNamespace(state=SimpleNamespace()))+ # The gateway mounts the dashboard app as the Webapp surface on a private (loopback) listener.+ web = SimpleNamespace(_SESSION_TOKEN="s" * 43, app=SimpleNamespace(state=SimpleNamespace(ui_surface="webapp")))runner.session_api.app = SimpleNamespace(web=web)result = _ask(runner, "webapp-launch")["result"]assert result == {"url": "http://127.0.0.1:9555/#hermes-session=" + "s" * 43, "private": True,@@ -187,9 +188,22 @@ def test_where_one_use_links_cannot_be_redeemed_the_launcher_gets_the_private_liassert not getattr(web.app.state, "webapp_window_tickets", None)+def test_behind_the_dashboard_sign_in_the_launcher_gets_the_webapp_address(monkeypatch, tmp_path):+ # The page asks for the sign-in itself; a launch link only works on a private (loopback) Webapp.+ runner, _, _ = _start_runtime_api(+ monkeypatch, tmp_path, "webapp:\n enabled: true\n host: 0.0.0.0\n port: 9555\n")+ state = SimpleNamespace(ui_surface="webapp", auth_required=True)+ runner.session_api.app = SimpleNamespace(web=SimpleNamespace(_SESSION_TOKEN="s" * 43, app=SimpleNamespace(state=state)))+ result = _ask(runner, "webapp-launch", params={"profile": "work"})["result"]+ assert result == {"url": "http://127.0.0.1:9555/?profile=work", "private": False,+ "expires_in_seconds": None, "sign_in": True}+ assert not getattr(state, "webapp_window_tickets", None)++def _serving_runner(monkeypatch, tmp_path):runner, _, _ = _start_runtime_api(monkeypatch, tmp_path, "webapp:\n enabled: true\n port: 9555\n")- web = SimpleNamespace(_SESSION_TOKEN="s" * 43, app=SimpleNamespace(state=SimpleNamespace()))+ # The gateway mounts the dashboard app as the Webapp surface on a private (loopback) listener.+ web = SimpleNamespace(_SESSION_TOKEN="s" * 43, app=SimpleNamespace(state=SimpleNamespace(ui_surface="webapp")))runner.session_api.app = SimpleNamespace(web=web)return runnerdiff --git a/tests/hermes_cli/test_webapp_launcher.py b/tests/hermes_cli/test_webapp_launcher.pyindex eaab4b7caa7..78f44cc1da4 100644--- a/tests/hermes_cli/test_webapp_launcher.py+++ b/tests/hermes_cli/test_webapp_launcher.py@@ -127,6 +127,18 @@ def test_a_webapp_the_gateway_could_not_serve_reports_why_and_how_to_retry(worldassert reason in out and "hermes gateway restart" in out+def test_behind_the_dashboard_sign_in_the_launcher_opens_the_webapp_to_sign_in(world, capsys):+ url = "http://127.0.0.1:9120/"+ world["answers"]["webapp-launch"] = {"ok": True, "result": {+ "url": url, "private": False, "expires_in_seconds": None, "sign_in": True}}+ assert launcher.cmd_webapp(_args()) == 0+ assert world["calls"]["opened"] == [url]+ assert "sign in" in capsys.readouterr().out.lower()+ assert launcher.cmd_webapp(_args(no_open=True)) == 0+ out = capsys.readouterr().out+ assert url in out and "sign in" in out.lower() and "one-use" not in out++def test_no_open_prints_the_link_instead(world, capsys):assert launcher.cmd_webapp(_args(no_open=True)) == 0assert world["calls"]["opened"] == []