refactor(tools): trim small tool modules (docstrings, dead constant, prefix table)

- audio_container: CONTAINER_TO_EXT built from one tuple; fixed-prefix sniffs table-driven.
- apply_layout_tool: dead _TIMEOUT_NOTE indirection inlined.
- Module/function docstrings compacted by hand; regexes, byte patterns, schemas and
  registry.register kwargs byte-identical (SCHEMA_SAME verified).
This commit is contained in:
Teknium
2026-09-02 22:36:16 -07:00
parent ffbd5ef633
commit 5442a2a371
11 changed files with 128 additions and 329 deletions
+13 -38
View File
@@ -1,13 +1,10 @@
#!/usr/bin/env python3
"""Persistent element annotations in the Hermes desktop GUI's in-app browser.
``drive_preview`` draws transient marks (one per action, self-retiring). An
annotation outlines an element — or, with ``hold``, the whole visible field —
and stays until the agent removes it. Annotations bind to elements, not
coordinates: they ride scrolls/reflows and vanish with their element, so a
navigation clears them. Rides the same ``preview.act`` bridge as
``drive_preview`` (the renderer resolves ``@e`` refs and owns the overlay).
Lives in the ``desktop_ui`` toolset, enabled only for desktop-sourced sessions.
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.
"""
import json
@@ -17,54 +14,32 @@ from tools.registry import registry, tool_error
ACTIONS = ("add", "hold", "remove", "clear")
# Verbs the renderer knows, keyed by ours. `clear` is `unpin` with nothing to
# aim at, which the overlay reads as "all of them".
# 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,
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."
)
payload = {
name: val
for name, val in (
("action", WIRE[verb]),
("ref", None if verb in ("clear", "hold") else ref),
("selector", None if verb in ("clear", "hold") else selector),
("text", label),
)
if val is not None
}
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(
"The annotation timed out, or no GUI window answered. "
"Open a page with open_preview first."
)
return tool_error("The annotation timed out, or no GUI window answered. Open a page with open_preview first.")
try:
return json.dumps(json.loads(raw), ensure_ascii=False)
except (TypeError, ValueError):