Files
hermes-agent/tools/annotate_preview_tool.py
alt-glitch c5b7339ffa refactor(tools): a parameter's default is stated in its schema, not in description words
A default that a description stated in words is now stated once, by the
parameter's `default` key. A default moved only where the handler uses that
literal whenever the argument is omitted, on every call, and an explicit value
equal to it behaves the same. No handler, parameter or other wording changed.

`default` key already present; only the words went:
- browser_cdp.timeout (30)
- browser_exec.local (false; consent-gated variant)
- patch.replace_all (false), patch.mode ('replace'; OpenAI-family variant)
- read_file.offset (1), read_file.limit (2000)
- session_search.detail ('adaptive'), session_search.window (5)
- todo_list.merge (false)
- web_search.limit (5), also "(5 by default)" in the tool description

`default` key added:
- annotate_preview.action ('add')
- browser_dialog.prompt_text ('')
- computer_use.mode ('som'), .button ('left'), .amount (3),
  .raise_window (false), .delivery_mode ('background'), .bring_to_front (false)
- delegate_task.action ('spawn')
- drive_preview.allow_shortcut (false)
- gui_tour.surface ('app')
- kanban_list.include_archived (false), kanban_list.limit (50), also
  "Bounded to 50 rows by default" in the tool description
- kanban_create.initial_status ('running'), .goal_mode (false),
  .completion_contract ('local-only')
- manage_connections.action ('status')
- skill_manage patch operation replace_all (false)

Left in words: kanban_create.workspace_kind (an omitted kind inherits a
project-scoped board's project, unlike an explicit 'scratch'),
image_generate.upscale (provider config can turn it on), gui_tour's preset
(applies only to start without steps), and skill_manage file_path (an explicit
'SKILL.md' skips the frontmatter check that an omitted path runs).

The prompt-surface snapshot under tests/fixtures/prompt_surface/ is
re-rendered with this change.
2026-11-30 22:21:39 +05:30

99 lines
3.8 KiB
Python

"""Persistent element annotations in the Hermes desktop GUI's in-app browser.
Unlike ``drive_preview``'s self-retiring marks, an annotation outlines an element
(or, with ``hold``, the whole visible field) until removed. Annotations bind to
elements, not coordinates: they ride scrolls and vanish with their element, so
navigation clears them. Same ``preview.act`` bridge as ``drive_preview`` (the
renderer resolves refs and owns the overlay). ``desktop_ui`` toolset only.
"""
from typing import Callable, Optional
from tools.desktop_ui import passthrough_json
from tools.registry import registry, tool_error
ACTIONS = ("add", "hold", "remove", "clear")
# Renderer verbs keyed by ours; `clear` is `unpin` with no target = "all of them".
WIRE = {"add": "pin", "hold": "hold", "remove": "unpin", "clear": "unpin"}
def annotate_preview_tool(
action: str = "add", ref: Optional[str] = None, selector: Optional[str] = None,
label: Optional[str] = None, callback: Optional[Callable] = None,
) -> str:
"""Put one annotation up, take one down, or clear them all."""
if callback is None:
return tool_error("annotate_preview is only available in the Hermes desktop app.")
verb = (action or "add").strip().lower()
if verb not in ACTIONS:
return tool_error(f"action must be one of: {', '.join(ACTIONS)}.")
if verb in ("add", "remove") and not (ref or selector):
return tool_error(f"{verb} needs a ref from drive_preview action='elements' (e.g. 'btn-sign-in') or a CSS selector.")
targeted = verb not in ("clear", "hold")
fields = (("action", WIRE[verb]), ("ref", ref if targeted else None), ("selector", selector if targeted else None), ("text", label))
payload = {name: val for name, val in fields if val is not None}
try:
raw = callback(payload)
except Exception as exc:
return tool_error(f"Failed to annotate the in-app browser: {exc}")
if not raw:
return tool_error(
"No GUI window answered with a page: no preview tab is open. "
"Open a page with open_preview first. If the pane IS open, the desktop app "
"may be older than this backend — its bridge-unavailable error names that case.")
return passthrough_json(raw)
ANNOTATE_PREVIEW_SCHEMA = {
"name": "annotate_preview",
"description": (
"Highlight preview-pane elements with lasting marks (drive_preview's fade). "
"Point at findings, flag what you're about to change, keep your place. Use the refs "
"from drive_preview action='elements'. add: outline one element "
"(optional short label — a word or two, drawn on the page). hold: "
"freeze the whole visible field, every element outlined and named. "
"remove/clear: take one/all down. Marks follow their element on "
"scroll; navigation clears them."
),
"parameters": {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": list(ACTIONS),
"default": "add",
},
"ref": {
"type": "string",
"description": "Ref from drive_preview elements.",
},
"selector": {
"type": "string",
"description": "CSS selector fallback. Prefer ref.",
},
"label": {
"type": "string",
"description": "Optional caption, e.g. 'cheapest'.",
},
},
"required": [],
},
}
registry.register(
name="annotate_preview",
toolset="desktop_ui",
schema=ANNOTATE_PREVIEW_SCHEMA,
handler=lambda args, **kw: annotate_preview_tool(
action=args.get("action", "add"),
ref=args.get("ref"),
selector=args.get("selector"),
label=args.get("label"),
callback=kw.get("callback"),
),
emoji="🔖",
)