Skip to content

let your agent control your phone

Turn telemetry off for Hermes runs unless the user opted in. (#124)

shawn panae33e86c9abb4
diff --git a/integrations/hermes/README.md b/integrations/hermes/README.md
index 7485bb1..90c6177 100644
--- a/integrations/hermes/README.md
+++ b/integrations/hermes/README.md
@@ -44,7 +44,7 @@ covers each.
This plugin has no settings of its own.
-- Telemetry follows phone-harness's own config.
+- Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`.
- `PHONE_HARNESS_PLATFORM`, when you have exported it, is passed through.
- The agent workspace is one folder, `agent-workspace`, in Hermes's plugin
data directory. If `PH_AGENT_WORKSPACE` is already set, that path is used
@@ -61,8 +61,8 @@ This plugin has no settings of its own.
3. Subagents in this process take turns on the phone, via an in-process lock.
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
- and does not turn telemetry off.
+ 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`.
5. The result is what the script printed, plus the exit code, the tail of
stderr, and any screenshot paths it printed (the agent opens those with
`vision_analyze`). A script past its timeout is killed with everything it
diff --git a/integrations/hermes/__init__.py b/integrations/hermes/__init__.py
index 36a23f2..ffeaf19 100644
--- a/integrations/hermes/__init__.py
+++ b/integrations/hermes/__init__.py
@@ -179,12 +179,60 @@ def _seed_workspace(workspace: Path) -> None:
workspace.mkdir(parents=True, exist_ok=True)
+# Same enabling spellings as phone_harness.config's bool env override.
+_TRUTHY = ("1", "true", "yes", "on")
+
+
+def _truthy(value) -> bool:
+ if isinstance(value, str):
+ return value.strip().lower() in _TRUTHY
+ return bool(value)
+
+
+def _config_json() -> Path:
+ """config.json, using the same directory rules as phone_harness.config.config_dir.
+
+ Inlined on purpose: importing phone_harness.config loads .env files and can seed an
+ agent workspace in this process. Hermes only needs the stored telemetry flag.
+ """
+ home = os.environ.get("PHONE_HARNESS_HOME")
+ if home:
+ root = Path(home) / "config"
+ else:
+ base = os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config"
+ root = Path(base) / "phone-harness"
+ return root / "config.json"
+
+
+def _telemetry_opted_in() -> bool:
+ """True only for an explicit opt-in.
+
+ Opt-in is ``phone-harness config set telemetry true`` (a value stored in config.json)
+ or PHONE_HARNESS_TELEMETRY set to an enabling value. The built-in default is on for
+ the CLI and is not an opt-in. An explicit false stays off.
+ """
+ raw = os.environ.get("PHONE_HARNESS_TELEMETRY")
+ if raw is not None:
+ return _truthy(raw)
+ try:
+ data = json.loads(_config_json().read_text())
+ except FileNotFoundError:
+ return False
+ except (OSError, ValueError):
+ return False
+ if not isinstance(data, dict) or "telemetry" not in data:
+ return False
+ return _truthy(data["telemetry"])
+
+
def _env(workspace: Path) -> dict:
- """The script inherits Hermes's environment. Platform and telemetry stay phone-harness's own
- config: an exported PHONE_HARNESS_PLATFORM is left as it is, and this plugin does not set one."""
+ """The script inherits Hermes's environment. An exported PHONE_HARNESS_PLATFORM is left
+ as it is. Telemetry is off unless the user explicitly opted in."""
env = dict(os.environ)
env["PH_AGENT_WORKSPACE"] = str(workspace)
env["PH_CLIENT"] = "hermes"
+ if not _telemetry_opted_in():
+ env["PHONE_HARNESS_TELEMETRY"] = "0"
return env
# ---------------------------------------------------------------------------------------------
diff --git a/integrations/hermes/plugin.yaml b/integrations/hermes/plugin.yaml
index d9d5616..63f1175 100644
--- a/integrations/hermes/plugin.yaml
+++ b/integrations/hermes/plugin.yaml
@@ -11,4 +11,4 @@ provides_tools:
provides_hooks:
- pre_tool_call
python_dependencies:
- - "phone-harness>=0.3.1rc1,<0.4"
+ - "phone-harness>=0.3.1,<0.4"
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 16aeb22..1a51b2c 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -436,6 +436,26 @@ class TopLevel(unittest.TestCase):
skill.encode("ascii")
+class TelemetryDefault(unittest.TestCase):
+ def test_cli_telemetry_stays_on_when_the_setting_was_never_set(self):
+ home = tempfile.TemporaryDirectory()
+ self.addCleanup(home.cleanup)
+ from phone_harness.config import cli, get, lookup
+ from phone_harness.telemetry import is_enabled
+
+ with mock.patch.dict(os.environ, {"PHONE_HARNESS_HOME": home.name}, clear=False):
+ os.environ.pop("PHONE_HARNESS_TELEMETRY", None)
+ self.assertEqual(lookup("telemetry"), (True, "default"))
+ self.assertTrue(get("telemetry"))
+ self.assertTrue(is_enabled())
+ out = io.StringIO()
+ with contextlib.redirect_stdout(out):
+ self.assertEqual(cli([]), 0)
+ line = next(item for item in out.getvalue().splitlines() if item.startswith("telemetry"))
+ self.assertIn("true", line)
+ self.assertIn("(default)", line)
+
+
class SessionAndStdinGuard(unittest.TestCase):
"""The top-level script path and --session live in run.py; argparse must not take them over."""
diff --git a/tests/test_hermes_plugin.py b/tests/test_hermes_plugin.py
index cefe467..38b6744 100644
--- a/tests/test_hermes_plugin.py
+++ b/tests/test_hermes_plugin.py
@@ -11,6 +11,7 @@ and what register() hands Hermes.
import importlib.util
import json
import os
+import subprocess
import sys
import tempfile
import time
@@ -20,6 +21,9 @@ from typing import Any
PLUGIN_INIT = Path(__file__).resolve().parents[1] / "integrations" / "hermes" / "__init__.py"
REPO_SKILL = Path(__file__).resolve().parents[1] / "SKILL.md"
+SRC = Path(__file__).resolve().parents[1] / "src"
+if str(SRC) not in sys.path:
+ sys.path.insert(0, str(SRC))
def load_plugin() -> Any:
@@ -132,14 +136,15 @@ class Environment(Base):
self.assertEqual(env["PHONE_HARNESS_PLATFORM"], "ios")
self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "1")
- def test_the_plugin_does_not_invent_platform_or_telemetry(self):
+ def test_the_plugin_does_not_invent_a_platform(self):
saved = dict(os.environ)
self.addCleanup(lambda: (os.environ.clear(), os.environ.update(saved)))
os.environ.pop("PHONE_HARNESS_PLATFORM", None)
os.environ.pop("PHONE_HARNESS_TELEMETRY", None)
+ os.environ["PHONE_HARNESS_HOME"] = str(self.data)
env = self.plugin._env(self.data / "ws")
self.assertNotIn("PHONE_HARNESS_PLATFORM", env)
- self.assertNotIn("PHONE_HARNESS_TELEMETRY", env)
+ self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "0")
class Workspace(unittest.TestCase):
@@ -266,6 +271,84 @@ class WorkspaceSeed(unittest.TestCase):
self.assertEqual((data / "agent-workspace" / "notes.txt").read_text(), "mine\n")
+class TelemetryOptIn(Base):
+ """Hermes runs are opt-in. The CLI default stays on when the setting was never stored."""
+
+ def setUp(self):
+ super().setUp()
+ self.saved = dict(os.environ)
+ os.environ["PHONE_HARNESS_HOME"] = str(self.data)
+ os.environ.pop("PHONE_HARNESS_TELEMETRY", None)
+ self.addCleanup(self.restore_env)
+
+ def restore_env(self):
+ os.environ.clear()
+ os.environ.update(self.saved)
+
+ def child_enabled(self) -> bool:
+ env = self.plugin._env(self.data / "ws")
+ env["PYTHONPATH"] = str(SRC) + os.pathsep + env.get("PYTHONPATH", "")
+ proc = subprocess.run(
+ [sys.executable, "-c",
+ "from phone_harness.telemetry import is_enabled\n"
+ "print('1' if is_enabled() else '0')"],
+ capture_output=True, text=True, env=env,
+ )
+ self.assertEqual(proc.returncode, 0, proc.stderr)
+ return proc.stdout.strip() == "1"
+
+ def test_unset_is_off_under_hermes_and_the_cli_default_stays_on(self):
+ from phone_harness.config import get, lookup
+ from phone_harness.telemetry import is_enabled
+
+ self.assertEqual(lookup("telemetry"), (True, "default"))
+ self.assertTrue(get("telemetry"))
+ self.assertTrue(is_enabled())
+ env = self.plugin._env(self.data / "ws")
+ self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "0")
+ self.assertNotIn("PHONE_HARNESS_TELEMETRY", os.environ)
+ self.assertTrue(is_enabled())
+ self.assertFalse(self.child_enabled())
+
+ def test_an_explicit_stored_true_is_on(self):
+ from phone_harness.config import set as set_config
+
+ set_config("telemetry", "true")
+ env = self.plugin._env(self.data / "ws")
+ self.assertNotIn("PHONE_HARNESS_TELEMETRY", env)
+ self.assertTrue(self.child_enabled())
+
+ def test_an_explicit_stored_false_is_off(self):
+ from phone_harness.config import set as set_config
+ from phone_harness.telemetry import is_enabled
+
+ set_config("telemetry", "false")
+ self.assertFalse(is_enabled())
+ env = self.plugin._env(self.data / "ws")
+ self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "0")
+ self.assertFalse(self.child_enabled())
+
+ def test_an_enabling_env_var_is_on(self):
+ os.environ["PHONE_HARNESS_TELEMETRY"] = "true"
+ env = self.plugin._env(self.data / "ws")
+ self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "true")
+ self.assertTrue(self.child_enabled())
+
+ def test_a_disabling_env_var_is_off(self):
+ os.environ["PHONE_HARNESS_TELEMETRY"] = "0"
+ env = self.plugin._env(self.data / "ws")
+ self.assertEqual(env["PHONE_HARNESS_TELEMETRY"], "0")
+ self.assertFalse(self.child_enabled())
+
+ def test_the_plugin_reads_the_same_config_file_as_the_cli(self):
+ from phone_harness.config import paths
+
+ self.assertEqual(self.plugin._config_json(), paths()["config"])
+ os.environ.pop("PHONE_HARNESS_HOME", None)
+ os.environ["XDG_CONFIG_HOME"] = str(self.data / "xdg")
+ self.assertEqual(self.plugin._config_json(), paths()["config"])
+
+
class Running(Base):
def test_prints_come_back_as_output(self):
result = self.run_tool("print(6 * 7)")