let your agent control your phone
0.3.3 follow-ups: Hermes pin and phone_exec fix, OpenClaw manifest, push_file approval (PHO-11) (#169)
shawn pana549d300e317a
diff --git a/integrations/hermes/README.md b/integrations/hermes/README.mdindex fdbff6b..02cce17 100644--- a/integrations/hermes/README.md+++ b/integrations/hermes/README.md@@ -29,8 +29,10 @@ hermes plugins install phone-harness/phone-harness/integrations/hermes```Hermes installs the `phone-harness` package into its own environment and asks-whether to enable the plugin. Tools load per session, so start a new chat.-Restart the Hermes desktop app after installing or updating the plugin.+whether to enable the plugin. Tools load per session, so start a new chat. If a+Hermes gateway is already running, first run `hermes gateway restart --detach`,+or the new chat will not have `phone_exec`. Restart the Hermes desktop app after+installing or updating the plugin.Each script runs as `python -m phone_harness.run` on Hermes's interpreter: thecopy Hermes installed, kept apart from a `phone-harness` command on `PATH`.@@ -40,7 +42,8 @@ as `ios` or `android` in the environment Hermes runs in. iPhone control needsAccessibility and Screen Recording for the app that runs Hermes (the Hermesdesktop app, or your terminal for `hermes` in a shell). Android needs adb; acloud phone needs `phone-harness cloud login`. [install.md](../../install.md)-covers each.+covers each. A standard Hermes install does not put `phone-harness` on your+PATH, so outside Hermes use `uvx phone-harness`.## Settings@@ -52,7 +55,24 @@ covers each.- Plugin setting `classifier_auto_run` (boolean, default false).- Or export `PHONE_HARNESS_CLASSIFIER_AUTO_RUN=1` in the environment Hermesruns in. When that variable is set, it wins over the plugin setting.-- Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`.+- Telemetry is off under Hermes unless you opt in with+ `phone-harness config set telemetry true`. When it is on, each run sends the+ script, the end of its output, helper calls with their arguments, errors, the+ phone type and an install ID to PostHog. If you are signed in to Phone Harness+ Cloud, it also sends your account ID and the session ID.+ - With `DO_NOT_TRACK=1` or `phone-harness config set telemetry false`, no+ telemetry is sent.+ - `PHONE_HARNESS_TELEMETRY`, when you have exported it, wins over `config set`.+ `DO_NOT_TRACK=1` wins over both.+ - A Hermes gateway keeps the environment it started with, so a variable+ exported in the shell you chat from does not reach a gateway that is already+ running. Put it in `~/.hermes/.env` instead. `config set` applies from the+ next run.+ - `phone_exec` runs where Hermes runs. On a Docker or SSH terminal backend, a+ `phone-harness` command in the terminal runs on that machine, so set these+ there too.+ - Phone Harness Cloud keeps its own activity log of cloud sessions. These+ settings do not change it.- `PHONE_HARNESS_PLATFORM`, when you have exported it, is passed through.- The agent workspace is one folder, `agent-workspace`, in Hermes's plugindata directory. If `PH_AGENT_WORKSPACE` is already set, that path is used@@ -71,7 +91,7 @@ covers each.After 120 s the tool reports the phone as busy.4. The plugin pipes the script on stdin to the phone-harness Hermes installed,with `PH_AGENT_WORKSPACE` and `PH_CLIENT=hermes`. It does not set a platform.- Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`.+ Telemetry is off unless you opt in. See [Settings](#settings).5. The result is what the script printed, plus the exit code and the tail ofstderr. `screenshot()` prints the path it saved. The last absolute PNG,JPEG, or WebP path in that output that exists and was written during thediff --git a/integrations/hermes/__init__.py b/integrations/hermes/__init__.pyindex 1772dbd..fb9d230 100644--- a/integrations/hermes/__init__.py+++ b/integrations/hermes/__init__.py@@ -84,8 +84,9 @@ CLASSIFIER_AUTO_RUN_ENV = "PHONE_HARNESS_CLASSIFIER_AUTO_RUN"# The only import the classifier treats as phone-only. Anything else asks.SAFE_MODULES = frozenset({"phone_harness.helpers"})# Builtins that read or write files, run arbitrary code, or wait on a terminal; shell() is-# phone-harness's adb shell.-RISKY_CALLS = frozenset({"open", "exec", "eval", "compile", "__import__", "breakpoint", "input", "shell"})+# phone-harness's adb shell; push_file() sends a file from this computer to a cloud phone.+RISKY_CALLS = frozenset({"open", "exec", "eval", "compile", "__import__", "breakpoint", "input", "shell",+ "push_file"})# Names helpers.py imports for itself. A script that pulls them in can reach this computer# (importlib.import_module, Path.home().read_text, the transport module)._HOST_NAMES = frozenset({@@ -335,7 +336,7 @@ def _package_dir() -> Path | None:spec = importlib.util.find_spec("phone_harness")if spec is None or not spec.origin:return None- return Path(spec.origin).resolve().parent+ return Path(spec.origin).parentdef _command() -> list[str] | None:@@ -469,6 +470,12 @@ def _env(workspace: Path) -> dict:for key, value in os.environ.items():if key.startswith("PHONE_HARNESS_") or key == "DO_NOT_TRACK":env[key] = value+ # A standard Hermes runs on a bare Python, attaches its packages at boot and strips them+ # from every child's PYTHONPATH. This child is that same Python, so it gets back the one+ # folder it needs to import the phone_harness Hermes installed.+ package = _package_dir()+ if package is not None:+ env["PYTHONPATH"] = os.pathsep.join(filter(None, (str(package.parent), env.get("PYTHONPATH"))))env["PH_AGENT_WORKSPACE"] = str(workspace)env["PH_CLIENT"] = "hermes"env["PHONE_HARNESS_TELEMETRY"] = "1" if _telemetry_opted_in() else "0"diff --git a/integrations/hermes/plugin.yaml b/integrations/hermes/plugin.yamlindex cb59613..5411638 100644--- a/integrations/hermes/plugin.yaml+++ b/integrations/hermes/plugin.yaml@@ -10,8 +10,9 @@ provides_tools:- phone_execprovides_hooks:- pre_tool_call+requires_hermes: ">=0.21.6"python_dependencies:- - "phone-harness==0.3.2"+ - "phone-harness==0.3.3"config_schema:classifier_auto_run:type: booldiff --git a/integrations/openclaw/classifier.py b/integrations/openclaw/classifier.pyindex a76e815..6e4e9b1 100644--- a/integrations/openclaw/classifier.py+++ b/integrations/openclaw/classifier.py@@ -17,8 +17,9 @@ import sys# The only import the classifier treats as phone-only. Anything else asks.SAFE_MODULES = frozenset({"phone_harness.helpers"})# Builtins that read or write files, run arbitrary code, or wait on a terminal; shell() is-# phone-harness's adb shell.-RISKY_CALLS = frozenset({"open", "exec", "eval", "compile", "__import__", "breakpoint", "input", "shell"})+# phone-harness's adb shell; push_file() sends a file from this computer to a cloud phone.+RISKY_CALLS = frozenset({"open", "exec", "eval", "compile", "__import__", "breakpoint", "input", "shell",+ "push_file"})# Names helpers.py imports for itself. A script that pulls them in can reach this computer# (importlib.import_module, Path.home().read_text, the transport module)._HOST_NAMES = frozenset({diff --git a/integrations/openclaw/openclaw.plugin.json b/integrations/openclaw/openclaw.plugin.jsonindex 85a70ff..372ce6d 100644--- a/integrations/openclaw/openclaw.plugin.json+++ b/integrations/openclaw/openclaw.plugin.json@@ -16,6 +16,7 @@"sideEffecting": true}},+ "providerEndpoints": [{ "endpointClass": "telemetry", "hosts": ["us.i.posthog.com"] }],"configContracts": {"dangerousFlags": [{ "path": "classifierAutoRun", "equals": true }]},diff --git a/tests/test_hermes_plugin.py b/tests/test_hermes_plugin.pyindex 73432c2..c57984f 100644--- a/tests/test_hermes_plugin.py+++ b/tests/test_hermes_plugin.py@@ -19,6 +19,7 @@ import typesimport unittestfrom pathlib import Pathfrom typing import Any+from unittest import mockPLUGIN_INIT = Path(__file__).resolve().parents[1] / "integrations" / "hermes" / "__init__.py"REPO_SKILL = Path(__file__).resolve().parents[1] / "SKILL.md"@@ -173,6 +174,8 @@ class ApprovalGate(Base):"from phone_harness import transport", "from phone_harness.helpers import Path","from phone_harness.helpers import importlib", "from . import agent_helpers",'open("notes.txt", "w").write("x")', '__import__("os")', 'eval("1")',+ 'push_file("~/.ssh/id_rsa")', 'p = push_file\np("~/notes.txt")',+ 'from phone_harness.helpers import push_file as p\np("~/notes.txt")',"print.__self__", 'getattr(print, "__self__")', 'shell("pm list packages")','send("raw", cmd="id")', 'send(op="raw")', 'op = "raw"\nsend(op)','f = open\nf("/etc/passwd")', 's = send\ns("raw", cmd="id")',@@ -254,6 +257,7 @@ class Environment(Base):os.environ["PYTHONPATH"] = "/hermes"os.environ["PHONE_HARNESS_PLATFORM"] = "ios"os.environ["PHONE_HARNESS_TELEMETRY"] = "1"+ self.plugin._package_dir = lambda: Noneenv = self.plugin._env(self.data / "ws")self.assertEqual(env["PH_AGENT_WORKSPACE"], str(self.data / "ws"))self.assertEqual(env["PH_CLIENT"], "hermes")@@ -262,6 +266,30 @@ class Environment(Base):self.assertEqual(env["PHONE_HARNESS_PLATFORM"], "ios")self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "1")+ def test_the_script_finds_the_package_hermes_keeps_out_of_child_environments(self):+ # A standard Hermes runs on a bare Python, attaches its packages at boot and strips+ # them from PYTHONPATH, so a child of that Python sees none of them by itself.+ site = self.data / "site-packages"+ package = site / "phone_harness"+ package.mkdir(parents=True)+ (package / "__init__.py").write_text("")+ (package / "run.py").write_text("print('ran from', __file__)\n")+ self.plugin._package_dir = lambda: package+ stripped = {**os.environ, "PYTHONPATH": "/your/libs"}+ sys.modules["tools.environments.local"].hermes_subprocess_env = lambda: dict(stripped)+ env = self.plugin._env(self.data / "ws")+ self.assertEqual(env["PYTHONPATH"], os.pathsep.join((str(site), "/your/libs")))+ ran = subprocess.run([sys.executable, "-m", "phone_harness.run"], env=env, cwd=self.data,+ capture_output=True, text=True)+ self.assertEqual(ran.returncode, 0, ran.stderr)+ self.assertIn(str(package / "run.py"), ran.stdout)++ def test_without_the_package_no_folder_is_added(self):+ without = {k: v for k, v in os.environ.items() if k != "PYTHONPATH"}+ sys.modules["tools.environments.local"].hermes_subprocess_env = lambda: dict(without)+ self.plugin._package_dir = lambda: None+ self.assertNotIn("PYTHONPATH", self.plugin._env(self.data / "ws"))+def test_the_plugin_does_not_invent_a_platform(self):saved = dict(os.environ)self.addCleanup(lambda: (os.environ.clear(), os.environ.update(saved)))@@ -366,6 +394,18 @@ class Command(unittest.TestCase):plugin._package_dir = lambda: Path("/opt/hermes/phone_harness")self.assertEqual(plugin._command(), [sys.executable, "-m", "phone_harness.run"])+ @unittest.skipIf(os.name == "nt", "symlinks need privileges on Windows")+ def test_a_linked_package_stays_beside_its_dependencies(self):+ plugin = load_plugin()+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp)+ (root / "store" / "phone_harness").mkdir(parents=True)+ (root / "site-packages").mkdir()+ (root / "site-packages" / "phone_harness").symlink_to(root / "store" / "phone_harness")+ origin = root / "site-packages" / "phone_harness" / "__init__.py"+ with mock.patch("importlib.util.find_spec", return_value=types.SimpleNamespace(origin=str(origin))):+ self.assertEqual(plugin._package_dir(), origin.parent)+def test_a_missing_package_is_unavailable(self):plugin = load_plugin()plugin._package_dir = lambda: None@@ -772,8 +812,9 @@ class PluginManifest(unittest.TestCase):def test_the_package_pin_is_exact_and_the_plugin_version_stays(self):text = (PLUGIN_INIT.parent / "plugin.yaml").read_text(encoding="utf-8")self.assertIn("\nversion: 0.1.0\n", text)- self.assertIn("phone-harness==0.3.2", text)- self.assertNotIn(">=", text)+ self.assertIn("phone-harness==0.3.3", text)+ self.assertNotIn("phone-harness>=", text)+ self.assertIn('requires_hermes: ">=0.21.6"', text)self.assertIn("classifier_auto_run:", text)self.assertIn("heuristic", text)self.assertIn("bypass", text)diff --git a/tests/test_openclaw_plugin.py b/tests/test_openclaw_plugin.pyindex 73854ec..f8e21ae 100644--- a/tests/test_openclaw_plugin.py+++ b/tests/test_openclaw_plugin.py@@ -70,6 +70,11 @@ class Manifest(unittest.TestCase):self.assertEqual(manifest()["configContracts"]["dangerousFlags"],[{"path": "classifierAutoRun", "equals": True}])+ def test_declares_the_host_telemetry_actually_sends_to(self):+ source = (ROOT / "src" / "phone_harness" / "telemetry.py").read_text(encoding="utf-8")+ host = re.search(r'^POSTHOG_HOST = "https://([^"/]+)"$', source, re.MULTILINE).group(1)+ self.assertEqual(manifest()["providerEndpoints"], [{"endpointClass": "telemetry", "hosts": [host]}])+def test_carries_no_version_that_could_drift_from_the_package(self):self.assertNotIn("version", manifest())