Skip to content

Commit 4b403ec

Browse files
committed
Question tool should use number as option as well.
1 parent 308cabd commit 4b403ec

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

python_agent_harness/tui.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,8 @@ def _ask_question_blocking(self) -> None:
761761
hint += ", or type your own answer"
762762
self.console.print(f"[dim]{hint}[/dim]")
763763
prompt = "> "
764-
elif options and any(len(o) > 1 for o in options):
765-
# long option labels get a numbered list: type the number to pick
764+
elif options:
765+
# option labels get a numbered list: type the number to pick
766766
self.console.print(Text(q.prompt))
767767
for i, opt in enumerate(options, 1):
768768
line = Text(f" {i}) ", style="cyan")
@@ -776,8 +776,6 @@ def _ask_question_blocking(self) -> None:
776776
hint += ", or type your own answer"
777777
self.console.print(f"[dim]{hint}[/dim]")
778778
prompt = "> "
779-
elif options:
780-
prompt = q.prompt + " [choices: " + ", ".join(options) + "] > "
781779
else:
782780
prompt = q.prompt + " > "
783781
try:

tests/test_tui.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,16 +1270,20 @@ def test_ask_question_prints_numbered_options(self):
12701270
self.assertIn("1) long option a", out)
12711271
self.assertIn("2) long option b", out)
12721272

1273-
def test_ask_question_short_options_stay_inline(self):
1274-
"""Single-letter options (y/n/a/d) keep the compact inline
1275-
format, but a number still resolves to the matching option."""
1276-
tui, _ = make_tui()
1273+
def test_ask_question_short_options_numbered_too(self):
1274+
"""Single-letter options (y/n/a/d) also render as a numbered
1275+
list — numbers apply to ALL option lists now — and a number
1276+
resolves to the matching option."""
1277+
tui, buf = make_tui()
12771278
q = UiQuestion("Proceed?", options=["y", "n"])
12781279
tui.question = q
1279-
with mock.patch.object(tui.prompt_session, "prompt", return_value="1") as m:
1280+
with mock.patch.object(tui.prompt_session, "prompt", return_value="2") as m:
12801281
tui._ask_question_blocking()
1281-
self.assertEqual(q.answer, "y")
1282-
m.assert_called_once_with("Proceed? [choices: y, n] > ", multiline=False)
1282+
self.assertEqual(q.answer, "n")
1283+
m.assert_called_once_with("> ", multiline=False)
1284+
out = buf.getvalue()
1285+
self.assertIn("1) y", out)
1286+
self.assertIn("2) n", out)
12831287

12841288
def test_ask_question_custom_answer_passthrough(self):
12851289
"""Free-text answers (not numbers) are returned verbatim."""

0 commit comments

Comments
 (0)