Align CLI help output (#248)
Browse files* Align CLI help output
Co-authored-by: OpenAI Codex <codex@openai.com>
* Address CLI help review feedback
Co-authored-by: OpenAI Codex <codex@openai.com>
---------
Co-authored-by: OpenAI Codex <codex@openai.com>
Files changed (2)
5 unmodified lines67891011434 unmodified lines4464474484494504514524534544554564574584594604614624634644654664674685 unmodified linesimport refrom rich.console import Consolefrom rich.markdown import Heading, Markdownfrom rich.panel import Panelfrom rich.theme import Theme434 unmodified lines# ββ Help βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββHELP_TEXT = f"""\{_I}[bold]Commands[/bold]{_I} [cyan]/help[/cyan] Show this help{_I} [cyan]/undo[/cyan] Undo last turn{_I} [cyan]/compact[/cyan] Compact context window{_I} [cyan]/resume[/cyan] [index|id|path] Pick up from a log in ./session_logs{_I} [cyan]/model[/cyan] [id] Show available models or switch{_I} [cyan]/effort[/cyan] [level] Reasoning effort (minimal|low|medium|high|xhigh|max|off){_I} [cyan]/yolo[/cyan] Toggle auto-approve mode{_I} [cyan]/status[/cyan] Current model & turn count{_I} [cyan]/share-traces[/cyan] [public|private] Show/flip visibility of your HF trace dataset{_I} [cyan]/quit[/cyan] Exit"""def print_help() -> None:_console.print()_console.print(HELP_TEXT)_console.print()5 unmodified lines6789101112434 unmodified lines4474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185 unmodified linesimport refrom rich.console import Consolefrom rich.markup import escapefrom rich.markdown import Heading, Markdownfrom rich.panel import Panelfrom rich.theme import Theme434 unmodified lines# ββ Help βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββHELP_ROWS: tuple[tuple[str, str, str], ...] = (("/help", "", "Show this help"),("/undo", "", "Undo last turn"),("/compact", "", "Compact context window"),("/resume", "[index|id|path]", "Pick up from ./session_logs"),("/model", "[id]", "Show available models or switch"),("/effort","[level]","Set reasoning effort preference",),("/yolo", "", "Toggle auto-approve mode"),("/status", "", "Current model & turn count"),("/share-traces","[public|private]","Show or change HF trace visibility",),("/quit", "", "Exit"),)def _help_column_widths(rows: tuple[tuple[str, str, str], ...],) -> tuple[int, int]:return (max(len(command) for command, _, _ in rows),max(len(args) for _, args, _ in rows),)def _format_help_row(command: str,args: str,description: str,command_width: int,args_width: int,) -> str:command_gap = " " * (command_width - len(command) + 2)args_gap = " " * (args_width - len(args) + 2)command_markup = f"[cyan]{escape(command)}[/cyan]"args_markup = f"[muted]{escape(args)}[/muted]" if args else ""return f"{_I} {command_markup}{command_gap}{args_markup}{args_gap}{description}"def format_help_text(rows: tuple[tuple[str, str, str], ...] | None = None) -> str:help_rows = HELP_ROWS if rows is None else rowscommand_width, args_width = _help_column_widths(help_rows)return "\n".join([f"{_I}[bold]Commands[/bold]"]+ [_format_help_row(command,args,description,command_width,args_width,)for command, args, description in help_rows])def print_help() -> None:_console.print()_console.print(format_help_text())_console.print()
4 unmodified lines567891018 unmodified lines2930313233344 unmodified linesfrom types import SimpleNamespaceimport pytestimport agent.main as main_modfrom agent.tools.research_tool import _get_research_model18 unmodified linesassert _get_research_model("openai/gpt-5.4") == "openai/gpt-5.4"def test_subagent_display_does_not_spawn_background_redraw(monkeypatch):calls: list[object] = []4 unmodified lines56789101118 unmodified lines30313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778794 unmodified linesfrom types import SimpleNamespaceimport pytestfrom rich.console import Consoleimport agent.main as main_modfrom agent.tools.research_tool import _get_research_model18 unmodified linesassert _get_research_model("openai/gpt-5.4") == "openai/gpt-5.4"def test_help_output_keeps_descriptions_aligned(monkeypatch):output = StringIO()console = Console(file=output,color_system=None,theme=terminal_display._THEME,width=120,)monkeypatch.setattr(terminal_display, "_console", console)terminal_display.print_help()lines = [line.rstrip() for line in output.getvalue().splitlines() if line.strip()]description_columns = []for command, args, description in terminal_display.HELP_ROWS:line = next(line for line in lines if command in line)if args:assert args in linedescription_columns.append(line.index(description))assert len(set(description_columns)) == 1def test_help_output_recomputes_widths_from_rows():rows = terminal_display.HELP_ROWS + (("/longer-command", "[longer-args]", "Synthetic help row"),)output = StringIO()Console(file=output,color_system=None,theme=terminal_display._THEME,width=140,).print(terminal_display.format_help_text(rows))lines = [line.rstrip() for line in output.getvalue().splitlines() if line.strip()]description_columns = [next(line for line in lines if command in line).index(description)for command, _args, description in rows]assert len(set(description_columns)) == 1def test_subagent_display_does_not_spawn_background_redraw(monkeypatch):calls: list[object] = []
agent/utils/terminal_display.py+63-13
tests/unit/test_cli_rendering.py+45