Skip to content

The agent that grows with you

fix(desktop): HUD note fires again when tool search defers the desktop tools

kshitijk4poor312f6bc2fd6f
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py
index 4f1b075edf8..07c6490c5a7 100644
--- a/agent/prompt_builder.py
+++ b/agent/prompt_builder.py
@@ -596,14 +596,20 @@ STEER_CHANNEL_NOTE = (
)
-def hud_surface_note(valid_tool_names: "set[str] | None" = None) -> str:
+def hud_surface_note(valid_tool_names: "set[str] | None" = None,
+ deferred_tool_names: "frozenset[str] | set[str]" = frozenset()) -> str:
"""Per-turn note for a message typed into the desktop's floating HUD ("this"/"here" = the app behind it).
A per-turn fact, not a platform (one session alternates between app window and HUD), so it rides the
model-bound message, never the byte-stable system prompt. Each sentence is gated on the tool it names (an
unknown tool name invites a hallucinated call); without read_window_below the whole note is withheld.
+ ``deferred_tool_names`` are tools this session reaches only through the tool_call bridge (the default
+ tool_search defer list holds the desktop tools): they count as available, and the note says to invoke
+ them via tool_call, since a direct call to a deferred name is rejected as an unknown tool.
"""
- names = valid_tool_names or set()
+ direct = valid_tool_names or set()
+ deferred = set(deferred_tool_names) - direct
+ names = direct | deferred
if "read_window_below" not in names:
return ""
gated = (
@@ -622,9 +628,13 @@ def hud_surface_note(valid_tool_names: "set[str] | None" = None) -> str:
("computer_use" in names and "browser_navigate" in names,
"When the app underneath is a browser, that means driving the "
"user's browser rather than opening yours with browser_navigate."),
- (True, "This is a prior, not a rule: when the request names its own target, follow the request.]"),
+ (True, "This is a prior, not a rule: when the request names its own target, follow the request."),
)
- return " ".join(text for ok, text in gated if ok)
+ note = " ".join(text for ok, text in gated if ok)
+ bridged = [name for name in ("read_window_below", "computer_use") if name in deferred and name in note]
+ if bridged:
+ note += f" Call {' and '.join(bridged)} through the tool_call bridge (deferred behind tool search)."
+ return note + "]"
# Models whose system prompt is sent as the 'developer' role (stronger instruction-following weight);
diff --git a/tests/tui_gateway/test_hud_surface_note.py b/tests/tui_gateway/test_hud_surface_note.py
index 1ddcd9e1abd..60c5d9fb1ca 100644
--- a/tests/tui_gateway/test_hud_surface_note.py
+++ b/tests/tui_gateway/test_hud_surface_note.py
@@ -58,11 +58,32 @@ class TestNoteContents:
def test_no_tools_at_all(self):
assert hud_surface_note(None) == ""
+ def test_deferred_tools_count_and_are_routed_through_the_bridge(self):
+ """Tool search defers the desktop tools by default; the note must still fire and name the bridge."""
+ note = hud_surface_note({"tool_call"}, {"read_window_below", "computer_use"})
+
+ assert "read_window_below identifies that app" in note
+ assert "Call read_window_below and computer_use through the tool_call bridge" in note
+ assert hud_surface_note({"read_window_below"}, {"computer_use"}).count("tool_call") == 1
+
class TestTurnRouting:
def test_hud_turn_gets_the_note(self):
assert server._hud_surface_note(_session(client_surface="hud")) == hud_surface_note(FULL_KIT)
+ def test_default_desktop_session_with_tool_search_gets_the_note(self):
+ """Real toolset resolution + real defer list: read_window_below is deferred, not dropped."""
+ from tools.registry import discover_builtin_tools
+
+ discover_builtin_tools()
+ enabled = server._load_enabled_toolsets("desktop")
+ agent = types.SimpleNamespace(enabled_toolsets=enabled, disabled_toolsets=None,
+ valid_tool_names={"tool_search", "tool_describe", "tool_call"})
+
+ note = server._hud_surface_note(_session(client_surface="hud") | {"agent": agent})
+
+ assert "read_window_below" in note and "through the tool_call bridge" in note
+
def test_app_window_turn_gets_nothing(self):
assert server._hud_surface_note(_session(client_surface="")) == ""
diff --git a/tui_gateway/session_notifications.py b/tui_gateway/session_notifications.py
index b3540b743c8..b17807be8c6 100644
--- a/tui_gateway/session_notifications.py
+++ b/tui_gateway/session_notifications.py
@@ -844,7 +844,13 @@ def _hud_surface_note(session: dict) -> str:
surface = session.get("client_surface")
if surface == "hud":
from agent.prompt_builder import hud_surface_note
- return hud_surface_note(getattr(session.get("agent"), "valid_tool_names", None))
+ from tools.tool_search_catalog import TOOL_CALL_NAME
+ agent = session.get("agent")
+ direct = getattr(agent, "valid_tool_names", None) or set()
+ if TOOL_CALL_NAME not in direct:
+ return hud_surface_note(direct)
+ from agent.tool_executor import _tool_search_scoped_names
+ return hud_surface_note(direct, _tool_search_scoped_names(agent))
if surface == "voice-live":
from tools.voice_live import voice_live_turn_note
return voice_live_turn_note(session.get("voice_live_context") or "")