Skip to content

The agent that grows with you

fix(tui): emit multi_select hint only when true — single-select clarify payloads keep the pre-existing protocol shape

teknium162e8842d07d6
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index f57373752d3..64ec7f75b2f 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -13869,6 +13869,30 @@ def test_clarify_callback_uses_configured_timeout(monkeypatch):
assert captured["payload"] == {"question": "Pick one", "choices": ["a", "b"]}
+def test_clarify_callback_multi_select_hint(monkeypatch):
+ """multi_select=True adds the hint to the payload; the single-select
+ payload shape stays byte-identical to the pre-multi-select protocol
+ (older renderers must never see the extra field)."""
+ captured = {}
+
+ def fake_block(event, sid, payload, timeout=300):
+ captured.update(payload=payload)
+ return "answer"
+
+ monkeypatch.setattr(server, "_block", fake_block)
+ cb = server._agent_cbs("sid-1")["clarify_callback"]
+
+ cb("Pick many", ["a", "b"], multi_select=True)
+ assert captured["payload"] == {
+ "question": "Pick many",
+ "choices": ["a", "b"],
+ "multi_select": True,
+ }
+
+ cb("Pick one", ["a", "b"], multi_select=False)
+ assert captured["payload"] == {"question": "Pick one", "choices": ["a", "b"]}
+
+
@pytest.mark.parametrize(
("configured", "expected"),
[(0, None), (-1, None), (42, 42)],
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index c4b499cd860..39253e14561 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -5040,8 +5040,13 @@ def _agent_cbs(sid: str) -> dict:
# multi_select is a pass-through hint: renderers with checkbox
# support can honor it; older renderers ignore the extra field
# and stay single-select (a single answer still parses as a
- # one-element list on the tool side).
- {"question": q, "choices": c, "multi_select": bool(multi_select)},
+ # one-element list on the tool side). Only emitted when True so
+ # single-select payloads keep the exact pre-multi-select shape.
+ (
+ {"question": q, "choices": c, "multi_select": True}
+ if multi_select
+ else {"question": q, "choices": c}
+ ),
timeout=_clarify_timeout_seconds(),
),
# read_terminal tool (desktop GUI): same blocking bridge as clarify — the