A call such as search_files without `pattern` ran anyway and returned matches, and a typo'd or invented argument was dropped with no signal, so the model assumed an option had taken effect. One check now sits in front of every tool Hermes ships (registry dispatch and the agent's inline executors; model_tools.py is untouched): - a missing `required` argument is refused before the handler runs, naming the field (with its allowed values when the schema enumerates them) and the valid parameters; - an argument the schema does not declare still reaches the handler exactly as sent; the result gains a `_warning` naming it. Nothing is stripped. Slim redo of #142503. What differs from it, and why: - scope is built-in tools only. MCP and plugin tools, and schemas that are open or union-shaped at the root, pass through untouched: a third-party `properties` list is not a promise about what the handler accepts. - nothing is stripped, so handlers that read an undeclared key and execution middleware that rewrites arguments keep main's contract. - legacy call shapes and tool-owned guidance are declared by each tool at registration (`compat_args`, `self_checked_args`) instead of a central table: skill_manage and memory flat shapes, delegate_task's single-task shape, patch's V4A mode, terminal(code=...), video_generate(video_url=...), and the handlers whose own missing-argument message says more than a generic refusal can. - the dynamic schema is only built when the registered one reports a finding. Co-authored-by: Elisa Martinez Abad <elisam@nvidia.com> Co-authored-by: James Nolan <jnolan@nvidia.com>
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
"""Close a read-only agent terminal tab in the Hermes desktop GUI WITHOUT killing
|
|
the mirrored ``terminal(background=true)`` process (output keeps buffering; the user
|
|
can reopen it). Routes through the process registry's ``on_close`` sink, which the
|
|
desktop gateway wires to a ``terminal.close`` event. ``desktop_ui`` toolset only."""
|
|
|
|
import json
|
|
|
|
from tools.process_registry import process_registry
|
|
from tools.registry import registry, tool_error
|
|
|
|
|
|
def close_terminal_tool(process_id: str) -> str:
|
|
"""Ask the desktop GUI to close a background process's read-only tab."""
|
|
pid = (process_id or "").strip()
|
|
if not pid:
|
|
return tool_error("process_id is required (the background process whose tab to close).")
|
|
return json.dumps(process_registry.request_close_terminal(pid), ensure_ascii=False)
|
|
|
|
|
|
CLOSE_TERMINAL_SCHEMA = {
|
|
"name": "close_terminal",
|
|
"description": (
|
|
"Hide a background process's desktop terminal tab; the process keeps running. "
|
|
"Tabs mirror terminal(background=true) runs. "
|
|
"This does NOT kill the process — it only drops the tab/view; the output "
|
|
"keeps buffering and the user can reopen it from the status stack. Use it "
|
|
"to tidy up when a background process's live terminal is no longer worth "
|
|
"showing. To actually stop the process, use process(action='kill') instead."
|
|
),
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"process_id": {
|
|
"type": "string",
|
|
"description": (
|
|
"The background process's session id (from terminal(background=true) "
|
|
"output or process(action='list')) whose tab should be closed."
|
|
),
|
|
},
|
|
},
|
|
"required": ["process_id"],
|
|
},
|
|
}
|
|
|
|
|
|
registry.register(
|
|
name="close_terminal",
|
|
toolset="desktop_ui",
|
|
schema=CLOSE_TERMINAL_SCHEMA,
|
|
handler=lambda args, **kw: close_terminal_tool(process_id=args.get("process_id", "")),
|
|
emoji="🖥️",
|
|
self_checked_args=("process_id",),
|
|
)
|