The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-screen): `computer-use screen status` redacts the lease holder's viewer id like every RPC surface
teknium1bead012b912f
diff --git a/hermes_cli/subcommands/computer_use_screen.py b/hermes_cli/subcommands/computer_use_screen.pyindex b1afe1710e7..711ec824201 100644--- a/hermes_cli/subcommands/computer_use_screen.py+++ b/hermes_cli/subcommands/computer_use_screen.py@@ -13,7 +13,7 @@ def _screen_status(args) -> int:from tools.bot_desktop import lease, runtimest = runtime.status()if bool(getattr(args, "json", False)):- print(json.dumps({**st.as_dict(), "lease": lease.get().as_dict()}, indent=2, sort_keys=True))+ print(json.dumps({**st.as_dict(), "lease": lease.public_view(lease.get())}, indent=2, sort_keys=True))return 0 if st.running else 1if not st.supported:print("Bot Desktop screens run on Linux gateway hosts only (this host keeps its real display).")@@ -23,8 +23,8 @@ def _screen_status(args) -> int:print(" Install: " + (st.install_command or "hermes computer-use screen install"))return 1if st.running:- holder = lease.get()- who = f"human ({holder.viewer_id})" if holder.holder == "human" else "agent"+ holder = lease.public_view(lease.get())+ who = f"human (viewer {holder['viewer_hash']})" if holder["holder"] == lease.HUMAN else "agent"print(f"Bot Desktop [{st.profile}]: running on DISPLAY {st.display} ({st.geometry}), pid {st.pid}")print(f" control: {who} rfb socket: {st.socket}")print(" View it: Hermes Desktop → Bots → this bot → Screen")diff --git a/tests/hermes_cli/test_bot_desktop_screen_status.py b/tests/hermes_cli/test_bot_desktop_screen_status.pynew file mode 100644index 00000000000..926e982d82f--- /dev/null+++ b/tests/hermes_cli/test_bot_desktop_screen_status.py@@ -0,0 +1,47 @@+"""``hermes computer-use screen status`` shows the lease the way every RPC surface does: the holder's viewer+id is a capability (whoever presents it co-drives or releases the lease), so only its short hash leaves the+gateway. Regression for #110006."""++import argparse+import hashlib+import json++import pytest++from hermes_cli.subcommands import computer_use_screen+from tools.bot_desktop import lease, runtime+++def _parse(argv):+ parser = argparse.ArgumentParser()+ computer_use_screen.build_screen_parser(+ parser.add_subparsers(), lambda sub, help_text: sub.add_argument("--json", action="store_true"))+ return parser.parse_args(argv)+++def running_screen(monkeypatch):+ monkeypatch.setattr(runtime, "status", lambda profile=None: runtime.DesktopStatus(+ profile="default", supported=True, installed=True, missing=[], running=True, pid=4242, display=":20",+ socket="/x/rfb.sock", geometry="1440x900", install_command=None, browser=None))+ yield+ lease._reset_for_tests()+++def test_status_never_prints_the_holders_raw_viewer_id(running_screen, capsys):+ from tui_gateway import methods_display++ secret = "secret-viewer-token-ABC123"+ lease.acquire(secret, reason="typing a password")+ rpc_view = methods_display._display_snapshot()["lease"] # what display.status / display.lease emit+ assert secret not in json.dumps(rpc_view)++ assert computer_use_screen.SCREEN_ACTIONS["status"](_parse(["screen", "status", "--json"])) == 0+ payload = json.loads(capsys.readouterr().out)+ assert secret not in json.dumps(payload)+ assert payload["lease"] == rpc_view, "the CLI and the RPC surfaces emit one and the same redacted lease"+ assert payload["lease"]["viewer_hash"] == hashlib.sha256(secret.encode()).hexdigest()[:12]++ assert computer_use_screen.SCREEN_ACTIONS["status"](_parse(["screen", "status"])) == 0+ human = capsys.readouterr().out+ assert secret not in human and "control: human" in humandiff --git a/tools/bot_desktop/lease.py b/tools/bot_desktop/lease.pyindex 8941152bbe3..d7a0c2b86cd 100644--- a/tools/bot_desktop/lease.py+++ b/tools/bot_desktop/lease.py@@ -52,6 +52,17 @@ class Lease:return asdict(self)+def public_view(lease: Lease) -> Dict[str, object]:+ """The lease as anything outside the gateway may see it (RPC results, the ``display.lease`` broadcast,+ the CLI): the holder's viewer id is a capability — whoever presents it co-drives or releases the lease —+ so it is replaced by a short hash the holder can match against its own id to know it is in control."""+ import hashlib+ d = lease.as_dict()+ d["viewer_id"] = None+ d["viewer_hash"] = hashlib.sha256(lease.viewer_id.encode()).hexdigest()[:12] if lease.viewer_id else None+ return d++_lock = threading.Condition()_listeners: List[Callable[[str, Lease], None]] = []diff --git a/tui_gateway/methods_display.py b/tui_gateway/methods_display.pyindex fc4d83cc8e5..c3bbebb5484 100644--- a/tui_gateway/methods_display.py+++ b/tui_gateway/methods_display.py@@ -28,23 +28,11 @@ _DISPLAY_ERR = 5300_lease_listener_installed = threading.Event()-def _lease_view(lease) -> dict:- """The lease as clients may see it: the holder's viewer id is a capability (whoever presents it- co-drives or releases the lease), so it is replaced by a short hash the holder can match against- its own id to know it is the one in control."""- import hashlib- d = lease.as_dict()- vid = d.pop("viewer_id")- d["viewer_id"] = None- d["viewer_hash"] = hashlib.sha256(vid.encode()).hexdigest()[:12] if vid else None- return d--def _display_snapshot() -> dict:from hermes_constants import hermes_home_keyfrom tools.bot_desktop import lease as _bd_lease, runtime as _bd_runtimest = _bd_runtime.status()- return {**st.as_dict(), "lease": _lease_view(_bd_lease.get()), "profile_key": hermes_home_key()}+ return {**st.as_dict(), "lease": _bd_lease.public_view(_bd_lease.get()), "profile_key": hermes_home_key()}def _install_lease_listener() -> None:@@ -54,7 +42,7 @@ def _install_lease_listener() -> None:from tools.bot_desktop import lease as _bd_leasedef _on_change(profile_key: str, lease) -> None:- _broadcast_global_event("display.lease", {"profile_key": profile_key, "lease": _lease_view(lease)})+ _broadcast_global_event("display.lease", {"profile_key": profile_key, "lease": _bd_lease.public_view(lease)})_bd_lease.on_change(_on_change)_lease_listener_installed.set() # only once the subscription exists, or a failed import would silence every client@@ -234,7 +222,7 @@ def _(rid, params: dict) -> dict:if (refused := _foreign_viewer_id(rid, viewer_id)) is not None:return refusedlease = _bd_lease.acquire(viewer_id, reason=str(params.get("reason") or ""))- return _ok(rid, {"lease": _lease_view(lease)})+ return _ok(rid, {"lease": _bd_lease.public_view(lease)})@method("display.lease.release")@@ -251,7 +239,7 @@ def _(rid, params: dict) -> dict:if viewer_id is None and lease.holder == _bd_lease.HUMAN:return _err(rid, _DISPLAY_ERR, "viewer_id required to release another viewer's lease (or pass force: true)",data={"code": "viewer_mismatch"})- return _ok(rid, {"lease": _lease_view(lease)})+ return _ok(rid, {"lease": _bd_lease.public_view(lease)})def register(server) -> None:diff --git a/tui_gateway/methods_display_watch.py b/tui_gateway/methods_display_watch.pyindex a96b64c3d08..9e0ce28c982 100644--- a/tui_gateway/methods_display_watch.py+++ b/tui_gateway/methods_display_watch.py@@ -31,8 +31,8 @@ _runtime_marks: dict[str, tuple] = {}def _lease_event_payload(profile_key: str, lease) -> dict:# Same shape and the same redaction (viewer_hash, never the raw id) as the in-process broadcast.- from tui_gateway.methods_display import _lease_view- return {"profile_key": profile_key, "lease": _lease_view(lease)}+ from tools.bot_desktop.lease import public_view+ return {"profile_key": profile_key, "lease": public_view(lease)}def _watched_lease_homes() -> list[Path]: