read_window_tool.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. """Read which OS window sits directly underneath the Hermes desktop window.
  3. The window list lives with the OS, so this round-trips through the gateway's
  4. blocking-prompt bridge like `read_terminal`: ``window.read.request`` -> the renderer's
  5. main process (native window enumeration) -> ``window.read.respond``.
  6. """
  7. from typing import Callable, Optional
  8. from tools.read_terminal_tool import read_pane
  9. from tools.registry import registry
  10. def read_window_below_tool(callback: Optional[Callable] = None) -> str:
  11. """Return the window underneath the Hermes window as a JSON string."""
  12. return read_pane(callback, (), (
  13. "read_window_below is only available in the Hermes desktop app.",
  14. "",
  15. "Failed to read the window below: ",
  16. "Could not determine the window underneath (the desktop app did "
  17. "not answer, or window enumeration is unavailable on this system).",
  18. ))
  19. READ_WINDOW_BELOW_SCHEMA = {
  20. "name": "read_window_below",
  21. "description": (
  22. "Identify the app window behind the Hermes desktop window (what the user is in). JSON: {window: {app, title, bounds, "
  23. "id}, frontmost, platform}. title may be empty when the OS withholds "
  24. "it (noted in `note`); where windows cannot be enumerated at all, "
  25. "{error, platform} says what would fix it — relay that instead of "
  26. "retrying. Metadata only; never captures pixels."
  27. ),
  28. "parameters": {
  29. "type": "object", "properties": {}
  30. },
  31. }
  32. registry.register(
  33. name="read_window_below",
  34. toolset="desktop_ui",
  35. schema=READ_WINDOW_BELOW_SCHEMA,
  36. handler=lambda args, **kw: read_window_below_tool(callback=kw.get("callback")),
  37. emoji="🪟",
  38. )