Files
hermes-agent/tools/focus_pane_tool.py
Brooklyn Nicholson 7ad9ace2cc fix(agent): the desktop's tools reach it on remote and cloud backends too
The pane, in-app browser, and reaction tools were gated on HERMES_DESKTOP=1 —
an env var set only on backends Electron spawns itself (local and SSH). A
desktop client connected to a plain URL gateway or Hermes Cloud lost all six:
they were stripped from the schema before the model saw them, on the same
backend whose platform hint was telling it "you are chatting inside the Hermes
desktop app". open_preview, read_preview, read_terminal, close_terminal,
focus_pane, and react_to_message were all silently absent.

The client is not the host. Capability now resolves from the session's own
source, which session.create already carries:

- The six tools move into a `desktop_ui` toolset, off _HERMES_CORE_TOOLS so no
  other platform pays their schema.
- _gui_surface_toolsets(platform) folds `desktop_ui` (and the existing
  `project` tools) into the GUI gateway's resolution when the session's
  platform is the desktop app — the same answer on every topology.
- check_fn drops the env probe. It kept the one thing that is genuinely a
  per-process/user fact: react_to_message's display.message_reactions opt-in,
  which the desktop mirrors onto whichever gateway it is connected to.

react_to_message was doubly broken: it read that toggle behind the env gate, so
even a local-backend user's Settings toggle could not reach a remote session.

The embedded terminal pane keeps working correctly the other way round: it runs
`hermes --tui` against a desktop-spawned backend, and a tui-sourced session
gets no GUI tools even though HERMES_DESKTOP=1 is set on that process.
2026-08-06 19:35:47 -06:00

65 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Reveal/focus a pane in the Hermes desktop GUI.
Lives in the ``desktop_ui`` toolset (like the other GUI affordances), which the
GUI gateway enables only for desktop-sourced sessions. Emits ``pane.reveal``
through the shared ``desktop_ui`` bridge; the renderer runs each pane's own
reveal path and only acts on the active window (a background turn never moves
the user's focus). To show a URL/file, use ``open_preview``.
"""
import json
from tools import desktop_ui
from tools.registry import registry, tool_error
PANES = ("chat", "files", "terminal", "review", "sessions")
def focus_pane_tool(pane: str) -> str:
"""Ask the desktop GUI to reveal and focus ``pane``."""
name = (pane or "").strip().lower()
if name not in PANES:
return tool_error(f"pane must be one of: {', '.join(PANES)}.")
try:
ok = desktop_ui.emit("pane.reveal", {"pane": name})
except Exception as exc:
return tool_error(f"Failed to focus the {name} pane: {exc}")
if not ok:
return tool_error("Pane focus is only available in the Hermes desktop app.")
return json.dumps({"success": True, "pane": name}, ensure_ascii=False)
FOCUS_PANE_SCHEMA = {
"name": "focus_pane",
"description": (
"Reveal and focus a pane in the Hermes desktop app when the user asks to "
"see it — e.g. \"show me the terminal\", \"open the file browser\", \"show "
"the diff\". Panes: chat (the conversation), files (project file browser), "
"terminal (embedded shell), review (git diff), sessions (the session list). "
"To show a URL or file in the preview pane, use open_preview instead."
),
"parameters": {
"type": "object",
"properties": {
"pane": {
"type": "string",
"enum": list(PANES),
"description": "Which pane to reveal.",
},
},
"required": ["pane"],
},
}
registry.register(
name="focus_pane",
toolset="desktop_ui",
schema=FOCUS_PANE_SCHEMA,
handler=lambda args, **kw: focus_pane_tool(pane=args.get("pane", "")),
emoji="🪟",
)