let your agent control your phone
cloud start opens the phone's live view; cloud open is the dashboard (#76)
shawn panaefab26a0d898
diff --git a/SKILL.md b/SKILL.mdindex 7f32b64..b7e70fe 100644--- a/SKILL.md+++ b/SKILL.md@@ -223,7 +223,7 @@ between sessions.```bashphone-harness cloud # signed in? a phone attached? minutes left?phone-harness cloud start # about 15s; safe to run twice, it reattaches-phone-harness cloud watch # opens the live view for the user+phone-harness cloud watch # (re)open the live view; `start` already opens itphone-harness cloud stop # ends billing and saves the phone```@@ -241,9 +241,14 @@ phone-harness cloud stop # ends billing and saves the phoneunless they ask you to stop it.- `Not signed in` means the user has to run `phone-harness cloud login` andapprove it in a browser. Relay that; you cannot do it for them.-- Offer `cloud watch` early on a long task, so the user can see the phone- instead of waiting for your report. `cloud start --temp` is a throwaway- phone that keeps nothing.+- `cloud start` opens the phone's live view in the user's browser, so they+ can watch you work; `cloud watch` reopens it if they closed it. That view+ is read-only. When the user wants to take the controls themselves — to+ type a password, pass a 2FA prompt, or just drive — run+ `phone-harness cloud open`: the dashboard, behind their own sign-in, with+ the interactive viewer. Wait for them to say they are done before you+ touch the phone again. `cloud start --temp` is a throwaway phone that+ keeps nothing.- The connection is handled for you, including reconnecting after a drop.The adb address the CLI shows is not a secret; the unlock code is, and younever need it — do not look for it, print it, or ask the user for it.diff --git a/src/phone_harness/cloud.py b/src/phone_harness/cloud.pyindex 3de892b..aef7a39 100644--- a/src/phone_harness/cloud.py+++ b/src/phone_harness/cloud.py@@ -500,6 +500,7 @@ def _wait_for_profile():def _start(args):temp = _flag(args, "--temp")+ watch = not _flag(args, "--no-watch")minutes = _option(args, "--minutes", "-m")if args:sys.exit(CLI_USAGE)@@ -522,7 +523,7 @@ def _start(args):live = Noneif live and live["state"] in ("provisioning", "ready"):print(f"Already attached to session {live['id']}; reusing it.")- return _report(_wait_ready(live["id"]))+ return _report(_wait_ready(live["id"]), watch=False) # its view is already open_detach()body = {"timeout_seconds": minutes * 60}@@ -530,7 +531,7 @@ def _start(args):if not temp:profile_id = _wait_for_profile()if isinstance(profile_id, dict): # it is already up: use it- return _report(profile_id["session"], profile_id["id"])+ return _report(profile_id["session"], profile_id["id"], watch)if profile_id:body["profile_id"] = profile_id@@ -549,10 +550,10 @@ def _start(args):created = _api("GET", f"/sessions/requests/{request_key}")if created.get("cleanup_complete") or not created.get("id"):raise- return _report(_wait_ready(created["id"]), profile_id)+ return _report(_wait_ready(created["id"]), profile_id, watch)-def _report(session, profile_id=None):+def _report(session, profile_id=None, watch=True):serial = _attach(session, profile_id)how = (session.get("startup") or {}).get("startup")note = {"exact": " Resumed exactly where you left it.",@@ -562,10 +563,24 @@ def _report(session, profile_id=None):print(f" adb {serial} (connected, unlocked)")print(f" expires in {_left(session.get('expires_at'))} — `phone-harness cloud stop` ""before then" + (" to keep the running state" if session.get("profile") else ""))- print(" watch phone-harness cloud watch")+ # The user asked for a phone; show it to them. Fails quietly where there+ # is no browser (an SSH box, CI), and the command is one line away.+ if watch and session.get("watch_url") and _open_browser(session["watch_url"]):+ print(" watch opened in your browser")+ else:+ print(" watch phone-harness cloud watch")return 0+def _open_browser(url):+ if not config.get("cloud.watch"):+ return False+ try:+ return bool(webbrowser.open(url))+ except Exception:+ return False++def _stop(args):everything = _flag(args, "--all")watch_save = _flag(args, "--wait")@@ -696,6 +711,17 @@ def _watch(args):return 0+def _open(args):+ """The dashboard: the interactive viewer, behind the user's own sign-in.+ `watch` is for looking; this is for taking the controls."""+ url = _dashboard()+ if _flag(args, "--print") or not _open_browser(url):+ print(url)+ else:+ print(f"opened {url} — sign in there to control the phone")+ return 0++def _whoami(args):me = _api("GET", "/me")if _flag(args, "--json"):@@ -775,15 +801,17 @@ CLI_USAGE = """Usage:phone-harness cloud who is signed in, what is attachedphone-harness cloud login [--no-browser] sign in through the browserphone-harness cloud logout | whoami- phone-harness cloud start [--temp] [--minutes N]- start your saved phone (or a throwaway one) and connect+ phone-harness cloud start [--temp] [--minutes N] [--no-watch]+ start your saved phone (or a throwaway one), connect,+ and open its live view (config: cloud.watch)phone-harness cloud stop [SID|--all] [--wait]end it; your phone is saved for next time(--wait watches the save finish)phone-harness cloud ls [-n NUM] running sessions (* = attached)phone-harness cloud show [SID] one session in fullphone-harness cloud use SID attach the helpers to another running session- phone-harness cloud watch [SID] [--print] open the live view+ phone-harness cloud watch [SID] [--print] the read-only live view (no sign-in; shareable)+ phone-harness cloud open [--print] the dashboard: control the phone yourself (sign-in)phone-harness cloud phone [reset --yes] your saved phonephone-harness cloud keys [create [LABEL] | revoke HASH] API keys, for CIphone-harness cloud history [-n NUM]@@ -794,7 +822,7 @@ They may live in a .env file at the repo root or in the agent workspace (never c"""_COMMANDS = {"login": _login, "logout": _logout, "whoami": _whoami, "start": _start,- "stop": _stop, "ls": _ls, "show": _show, "use": _use, "watch": _watch,+ "stop": _stop, "ls": _ls, "show": _show, "use": _use, "watch": _watch, "open": _open,"phone": _phone, "keys": _keys, "history": _history}diff --git a/src/phone_harness/config.py b/src/phone_harness/config.pyindex 0254ca5..f9bbe09 100644--- a/src/phone_harness/config.py+++ b/src/phone_harness/config.py@@ -72,6 +72,7 @@ DEFAULTS = {"cloud": {"minutes": 15, # how long `cloud start` rents a phone for"max_minutes": 30, # the most one `cloud start` may ask for+ "watch": True, # `cloud start` opens the phone's live view in the browser},"ios": {"restore_clipboard": False, # put the old clipboard back after a pastediff --git a/tests/test_cloud.py b/tests/test_cloud.pyindex 91b9a8a..0a0b047 100644--- a/tests/test_cloud.py+++ b/tests/test_cloud.py@@ -243,6 +243,35 @@ class CloudCli(unittest.TestCase):ls = self.run_cli("cloud", "ls")self.assertIn("* sid001", ls.stdout)+ def test_start_opens_the_live_view_unless_told_not_to(self):+ self.login()+ opened = Path(self.home.name) / "opened-urls"+ # a fake browser: `webbrowser` honours $BROWSER, so point it at a script that records the url+ fake = Path(self.home.name) / "browser"+ fake.write_text(f'#!/bin/sh\necho "$1" >> "{opened}"\n')+ fake.chmod(0o755)+ r = self.run_cli("cloud", "start", env={"BROWSER": str(fake)})+ self.assertEqual(r.returncode, 0, r.stderr)+ self.assertIn("opened in your browser", r.stdout)+ self.assertEqual(opened.read_text().strip(), "https://watch.example/secret")+ self.assertNotIn("watch.example", r.stdout) # the url itself is never printed+ again = self.run_cli("cloud", "start", env={"BROWSER": str(fake)}) # reattach: no second tab+ self.assertEqual(len(opened.read_text().split()), 1, again.stdout)+ self.run_cli("cloud", "stop")+ r = self.run_cli("cloud", "start", "--no-watch", env={"BROWSER": str(fake)})+ self.assertIn("phone-harness cloud watch", r.stdout)+ self.assertEqual(len(opened.read_text().split()), 1)+ self.run_cli("cloud", "stop")+ r = self.run_cli("cloud", "start", env={"BROWSER": str(fake), "PHONE_HARNESS_CLOUD_WATCH": "0"})+ self.assertIn("phone-harness cloud watch", r.stdout)+ self.assertEqual(len(opened.read_text().split()), 1)++ def test_open_is_the_dashboard_not_the_watch_link(self):+ self.login()+ r = self.run_cli("cloud", "open", "--print")+ self.assertEqual(r.stdout.strip(), "https://phone-harness.com/dashboard")+ self.assertNotIn("watch", r.stdout)+def test_temp_phone_and_minutes_cap(self):self.login()self.assertEqual(self.run_cli("cloud", "start", "--temp").returncode, 0)