Skip to content

The agent that grows with you

fix(gateway): send a raw arg preview on tool.start, not a phrased label

Brooklyn Nicholsonf0031abc3969
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index dbdd2ec5ffc..d51afc1af13 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -1456,12 +1456,24 @@ def test_history_to_messages_preserves_tool_calls_for_resume_display():
assert server._history_to_messages(history) == [
{"role": "user", "text": "first prompt"},
- {"context": "Searching files for resume", "name": "search_files", "role": "tool"},
+ {"context": "resume", "name": "search_files", "role": "tool"},
{"role": "assistant", "text": "first answer"},
{"role": "user", "text": "second prompt"},
]
+def test_tool_ctx_sends_an_arg_preview_not_a_phrased_label():
+ # Clients phrase their own verb around this string: the TUI renders
+ # `Terminal("<ctx>")` and the desktop prepends "Running"/"Ran". Sending a
+ # pre-phrased label made both stutter ("Ran Running sleep 70 + 2 commands")
+ # and stood in for the real command in the desktop's `$` transcript.
+ assert server._tool_ctx("terminal", {"command": 'sleep 70; echo "a"; echo "b"'}) == (
+ "sleep 70 + 2 commands"
+ )
+ assert server._tool_ctx("read_file", {"path": "/tmp/demo/package.json"}) == "package.json"
+ assert server._tool_ctx("web_search", {"query": "weather in NYC"}) == "weather in NYC"
+
+
def test_history_to_messages_keeps_reasoning_only_assistant_turn():
# A thinking-only assistant turn (reasoning present, no visible text) is
# persisted and recallable, but was dropped from the resumed session view
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index ec43de410a5..4b422e7f3f7 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -4497,10 +4497,20 @@ def _session_info(agent, session: dict | None = None) -> dict:
def _tool_ctx(name: str, args: dict) -> str:
+ """Argument preview for a tool row — never a phrased label.
+
+ Clients own their own phrasing: the TUI wraps this as ``Terminal("...")``
+ and the desktop prepends its own localized verb ("Running"/"Ran"). Sending
+ ``build_tool_label`` here instead of the raw preview stutters the verb on
+ both surfaces ("Running Running sleep 70 + 2 commands") and leaks a display
+ label into the desktop's ``args.context``, where it stands in for the real
+ command. The friendly labels belong on the CLI spinner, which builds them
+ from ``build_tool_label`` at its own call sites.
+ """
try:
- from agent.display import build_tool_label
+ from agent.display import build_tool_preview
- return build_tool_label(name, args, max_len=80) or ""
+ return build_tool_preview(name, args, max_len=80) or ""
except Exception:
return ""