fix(cli): support reliable setup menu navigation

Decode Ghostty/Kitty enhanced selection and cancellation keys, make setup cancellation terminal, and add cross-terminal previous-step navigation to setup and model flows.

Refs #92833
This commit is contained in:
fyzanshaik
2026-08-23 14:53:50 +05:30
committed by kshitij
parent d9a48f656a
commit 8345effc4e
7 changed files with 1202 additions and 104 deletions
@@ -4,6 +4,8 @@ cannot initialize (e.g. non-TTY, curses unavailable, terminal error)."""
import subprocess
from types import SimpleNamespace
import pytest
from hermes_cli.config import load_config, save_config
@@ -13,6 +15,46 @@ def _raise_menu(*args, **kwargs):
raise subprocess.CalledProcessError(2, ["tput", "clear"])
@pytest.mark.parametrize(
("sequence", "expected"),
[
("\x1b[27u", "cancel"),
("\x1b[D", "back"),
("\x1b[99;5u", "cancel"),
],
)
def test_scoped_numbered_input_handles_navigation_keys(sequence, expected):
"""The curses fallback stays escapable on POSIX and native Windows."""
from prompt_toolkit.application import create_app_session
from prompt_toolkit.input.defaults import create_pipe_input
from prompt_toolkit.output import DummyOutput
from hermes_cli.curses_ui import (
MenuNavigationStart,
_NUMBERED_BACK_ENABLED,
_NumberedNavigation,
_read_numbered_input,
reset_menu_navigation_handler,
set_menu_navigation_handler,
)
def handler(event, *_args):
return MenuNavigationStart(allow_back=True) if event == "begin" else None
token = set_menu_navigation_handler(handler)
back_token = _NUMBERED_BACK_ENABLED.set(True)
try:
with create_pipe_input() as pipe_input:
pipe_input.send_text(sequence)
with create_app_session(input=pipe_input, output=DummyOutput()):
result = _read_numbered_input("Choice: ")
finally:
_NUMBERED_BACK_ENABLED.reset(back_token)
reset_menu_navigation_handler(token)
assert result is getattr(_NumberedNavigation, expected.upper())
def test_prompt_model_selection_requires_expensive_confirmation(monkeypatch, capsys):