Skip to content

The agent that grows with you

fix(tui): pair file-edit tool.start with its tool.complete under answer-only

Hermes Agentf41c6517ea1e
diff --git a/tests/tui_gateway/test_show_reasoning_display_gate.py b/tests/tui_gateway/test_show_reasoning_display_gate.py
index d99bb37b736..76bf25fef06 100644
--- a/tests/tui_gateway/test_show_reasoning_display_gate.py
+++ b/tests/tui_gateway/test_show_reasoning_display_gate.py
@@ -5,6 +5,8 @@ deltas and non-essential tool chrome leave the gateway.
"""
import json
+import re
+from pathlib import Path
from types import SimpleNamespace
from tui_gateway import server
@@ -202,6 +204,61 @@ def test_hidden_reasoning_keeps_card_tool_lifecycle(monkeypatch):
assert lifecycle == ["tool.start", "tool.complete"], tool_id
+def test_hidden_reasoning_keeps_file_edit_lifecycle_pair(monkeypatch):
+ """A file edit is a diff card (`isFileEditTool`): answer-only keeps it visible.
+
+ The complete-side guard admits edits through `inline_diff`; without the same
+ membership on the start side, the diff arrived with no row and a lifecycle
+ consumer got a `tool.complete` it never saw a `tool.start` for.
+ """
+ events = _capture(monkeypatch)
+ _session(monkeypatch, "hide-edit", show_reasoning=False, effort="high")
+
+ def fake_edit_diff(tool_name, result, *, function_args=None, snapshot=None, print_fn=None):
+ if print_fn is not None:
+ print_fn("— edited src/a.py —")
+ return True
+
+ monkeypatch.setattr("agent.display.render_edit_diff_with_delta", fake_edit_diff)
+
+ cases = {
+ "tool-edit": ("edit_file", {"path": "src/a.py", "old_string": "a", "new_string": "b"}),
+ "tool-patch": ("patch", {"path": "src/a.py", "patches": []}),
+ "tool-write": ("write_file", {"path": "src/a.py", "content": "b"}),
+ }
+ for tool_id, (name, args) in cases.items():
+ server._on_tool_start("hide-edit", tool_id, name, args)
+ server._on_tool_complete("hide-edit", tool_id, name, args, json.dumps({"success": True}))
+
+ for tool_id in cases:
+ lifecycle = [event[0] for event in events if event[2].get("tool_id") == tool_id]
+ assert lifecycle == ["tool.start", "tool.complete"], tool_id
+
+
+def test_gateway_lifecycle_set_covers_desktop_card_tools():
+ """`isCardTool` (tool-render-class.ts) and the gateway lifecycle set must not drift.
+
+ Every name the desktop classifies as a card needs its full lifecycle under
+ answer-only, or its `tool.complete` arrives orphaned.
+ """
+ ts_path = Path(__file__).resolve().parents[2] / "apps" / "desktop" / "src" / "lib" / "tool-render-class.ts"
+ source = ts_path.read_text(encoding="utf-8")
+
+ def set_literal(var: str) -> set[str]:
+ match = re.search(rf"const {var} = new Set\(\[(.*?)\]\)", source, re.DOTALL)
+ assert match, f"{var} not found in {ts_path.name}"
+ return set(re.findall(r"'([^']+)'", match.group(1)))
+
+ # CONNECTION_CARD_KEY is the run-splitter's alias for a manage_connections
+ # part, not a tool name the gateway ever sees.
+ desktop_cards = (
+ set_literal("CARD_TOOL_NAMES")
+ | set_literal("FILE_EDIT_TOOL_NAMES")
+ | {"manage_connections"}
+ )
+ assert desktop_cards <= set(server._TOOL_LIFECYCLE_UI_TOOLS)
+
+
def test_hidden_reasoning_shows_failed_terminal_exit_code(monkeypatch):
events = _capture(monkeypatch)
_session(monkeypatch, "hide-exit", show_reasoning=False, effort="high")
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index 534ea7585ef..013c4085294 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -2023,19 +2023,30 @@ def _tool_progress_enabled(sid: str) -> bool:
return _session_tool_progress_mode(sid) != "off"
+# Names whose lifecycle a UI renders as a card even in answer-only mode. `isCardTool` /
+# `isFileEditTool` in apps/desktop/src/lib/tool-render-class.ts must stay in sync with this
+# set (test_gateway_lifecycle_set_covers_desktop_card_tools pins the direction that matters).
+_TOOL_LIFECYCLE_UI_TOOLS = frozenset({
+ "clarify", "manage_connections", "setup_mcp",
+ "image_generate", "manage_catalog", "delegate_task",
+ # File edits are the turn's deliverable — the diff card the user reviews.
+ "edit_file", "patch", "write_file",
+})
+
+
def _tool_lifecycle_required_for_ui(name: str) -> bool:
"""Interactive UI / card surfaces, not optional chrome.
Desktop renders these from the tool-call part itself, so suppressing the
- lifecycle hides the turn's deliverable entirely (`isCardTool` in
- apps/desktop/src/lib/tool-render-class.ts must stay in sync with this set):
- clarify / connection cards are consent surfaces, and image_generate /
- manage_catalog / delegate_task draw the thing the user asked for.
+ lifecycle hides the turn's deliverable entirely (`isCardTool` /
+ `isFileEditTool` in apps/desktop/src/lib/tool-render-class.ts must stay in
+ sync with `_TOOL_LIFECYCLE_UI_TOOLS`): clarify / connection cards are
+ consent surfaces, image_generate / manage_catalog / delegate_task draw the
+ thing the user asked for, and file edits are the diff the user reviews.
+ The start and complete guards both consult this set, so a card's
+ `tool.complete` can never arrive without its `tool.start`.
"""
- return name in (
- "clarify", "manage_connections", "setup_mcp",
- "image_generate", "manage_catalog", "delegate_task",
- )
+ return name in _TOOL_LIFECYCLE_UI_TOOLS
def _restart_slash_worker(sid: str, session: dict):