Skip to content

The agent that grows with you

fix(tui): guard the clipboard helper's dependency activation

Teknium21fdbef28463
diff --git a/tests/tui_gateway/test_ink_helper_dependencies.py b/tests/tui_gateway/test_ink_helper_dependencies.py
index a9912ce9acc..7b85d04ba53 100644
--- a/tests/tui_gateway/test_ink_helper_dependencies.py
+++ b/tests/tui_gateway/test_ink_helper_dependencies.py
@@ -102,6 +102,15 @@ def test_store_python_without_a_generation_names_the_remedy():
assert lines[-1] == "gateway unavailable: run `hermes pm repair`, then restart the TUI", bootstrap.stderr
+def test_clipboard_helper_without_a_generation_answers_false(tmp_path):
+ """The clipboard helper activates before importing Hermes, and a missing generation is `false`
+ on stdout (no image), not a traceback before Ink can parse anything."""
+ clipboard = _store_python_child("clipboard_image.py", str(tmp_path / "paste.png"))
+ assert clipboard.returncode == 0, clipboard.stderr
+ assert json.loads(clipboard.stdout) is False
+ assert "Traceback" not in clipboard.stderr
+
+
def test_unreadable_install_state_is_retried_not_terminal():
"""An I/O error on the install state can be one-off: it takes the ordinary failure path the
client retries, never the terminal verdict that ends the TUI's gateway for its lifetime."""
diff --git a/ui-tui/scripts/clipboard_image.py b/ui-tui/scripts/clipboard_image.py
index 04f2b96681c..7d464b8a73a 100644
--- a/ui-tui/scripts/clipboard_image.py
+++ b/ui-tui/scripts/clipboard_image.py
@@ -12,12 +12,23 @@ def python_root() -> Path:
sys.path.insert(0, str(python_root()))
-from hermes_cli.clipboard import save_clipboard_image
-from pm.environments import activate_dependencies
-
-if __name__ == "__main__":
+def main(destination: Path) -> bool:
# Ink runs this on HERMES_PYTHON with PYTHONPATH=<root> only, which on a source install is PM's
# store Python: without the committed generation, Pillow is missing and non-PNG clipboard
- # images silently depend on ImageMagick being installed.
- activate_dependencies(python_root())
- print(json.dumps(bool(save_clipboard_image(Path(sys.argv[1])))))
+ # images silently depend on ImageMagick being installed. Activate before any Hermes import, so
+ # a module that grows a third-party import still loads from the generation.
+ from pm.environments import activate_dependencies
+
+ try:
+ activate_dependencies(python_root())
+ except (RuntimeError, OSError) as exc:
+ # No generation / unreadable install state: no image, not a traceback (Ink reads stdout).
+ print(f"clipboard helper: dependency environment unavailable: {exc}", file=sys.stderr)
+ return False
+ from hermes_cli.clipboard import save_clipboard_image
+
+ return bool(save_clipboard_image(destination))
+
+
+if __name__ == "__main__":
+ print(json.dumps(main(Path(sys.argv[1]))))