langstage-cli 0.6.60__tar.gz → 0.6.62__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langstage_cli-0.6.60/langstage_cli.egg-info → langstage_cli-0.6.62}/PKG-INFO +1 -1
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli/cli.py +74 -8
- {langstage_cli-0.6.60 → langstage_cli-0.6.62/langstage_cli.egg-info}/PKG-INFO +1 -1
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli.egg-info/SOURCES.txt +1 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/pyproject.toml +1 -1
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_dumb_term.py +3 -1
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_hitl_approval_preview.py +78 -0
- langstage_cli-0.6.62/tests/test_mintty_approval_219.py +145 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/LICENSE +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/README.md +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/deepagent_code/__init__.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli/__init__.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli/agui_stream.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli/config.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli/exit_codes.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli/sessions.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli.egg-info/dependency_links.txt +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli.egg-info/entry_points.txt +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli.egg-info/requires.txt +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/langstage_cli.egg-info/top_level.txt +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/setup.cfg +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_advertised_wave4.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_agui_stream.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_approval_menu_abort.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_approval_menu_keys_211.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_async_mode.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_checkpointer.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_cli.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_cli_help.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_codeconfig.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_config.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_config_command.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_configurable.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_ctrl_c_sync_tool.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_custom_decision_195.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_decision_shapes_209.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_deferred_pass.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_exit_codes.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_generic_interrupt.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_help_render.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_hidden_option_suggestions.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_history_persist.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_hitl_resume_warning.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_init.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_interrupt_answer_text_206.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_interrupt_non_tty.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_legacy_config_home.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_load_error.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_menu_allowed_197.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_message_boundaries.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_no_color.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_no_interactive_approve.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_no_persist_resume.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_nul_approval_217.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_paused_session_message.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_persist_env.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_quiet_output.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_quiet_tool_result_204.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_reasoning_render.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_rename_shim.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_render_markdown.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_routine_1024.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_session_agent_215.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_session_lifecycle.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_sessions.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_show_config.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_show_config_bare_spec_213.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_show_config_malformed.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_spec_loading_core.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_spec_resolution.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_spinner_reply_survives.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_stdin_interactive.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_stdin_single_shot.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_stream_mode.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_streaming_marker.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_terminal_width.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_toml_relative_paths.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_tool_card_args.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_tool_output_escape.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_turn_error_verbose.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_turn_exit_and_render.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_unicode_console.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_usage_hint_186.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_verbose_command.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_verify_flag.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_workspace.py +0 -0
- {langstage_cli-0.6.60 → langstage_cli-0.6.62}/tests/test_wrong_type_graph.py +0 -0
|
@@ -1344,6 +1344,50 @@ def _tool_key(action: Any) -> str | None:
|
|
|
1344
1344
|
return None
|
|
1345
1345
|
|
|
1346
1346
|
|
|
1347
|
+
def _approval_description(action: Any) -> str:
|
|
1348
|
+
"""A tool-review request's ``description``, as text for the approver (gh #221).
|
|
1349
|
+
|
|
1350
|
+
``HumanInTheLoopMiddleware`` (and deepagents' ``interrupt_on``) puts the request's
|
|
1351
|
+
own human-readable text under ``description``: a warning the developer configured,
|
|
1352
|
+
or the default ``"<prefix>\\n\\nTool: <name>\\nArgs: <args>"``. It is shown in full,
|
|
1353
|
+
with its line breaks, rather than as one more capped ``k=v`` field. Every other
|
|
1354
|
+
control character is still escaped. The default's ``Tool:``/``Args:`` tail only
|
|
1355
|
+
repeats the label and the argument list shown under it, so it is dropped, and so is
|
|
1356
|
+
the default prefix (``"Tool execution requires approval"``) left on its own, which
|
|
1357
|
+
says nothing the ``Action Required`` banner doesn't.
|
|
1358
|
+
|
|
1359
|
+
Returns ``""`` when there is nothing to show (not a tool review, no description,
|
|
1360
|
+
or only the default text). The caller indents every line under the label.
|
|
1361
|
+
"""
|
|
1362
|
+
key = _tool_key(action)
|
|
1363
|
+
if not key:
|
|
1364
|
+
return ""
|
|
1365
|
+
text = action.get("description")
|
|
1366
|
+
if not isinstance(text, str):
|
|
1367
|
+
return ""
|
|
1368
|
+
name = action.get(key)
|
|
1369
|
+
if isinstance(name, str):
|
|
1370
|
+
# The middleware's default layout: the prefix, a blank line, then Tool/Args.
|
|
1371
|
+
m = re.match(rf"(.*?)\n\nTool: {re.escape(name)}\nArgs: ", text, re.S)
|
|
1372
|
+
if m:
|
|
1373
|
+
text = m.group(1)
|
|
1374
|
+
if text.strip() == _HITL_DEFAULT_PREFIX:
|
|
1375
|
+
return ""
|
|
1376
|
+
text = _escape_controls(text.strip("\n").rstrip(), keep="\n\t")
|
|
1377
|
+
return text if text.strip() else ""
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
# LangChain HumanInTheLoopMiddleware's default ``description_prefix``.
|
|
1381
|
+
_HITL_DEFAULT_PREFIX = "Tool execution requires approval"
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
def _print_approval_description(text: str) -> None:
|
|
1385
|
+
"""Print a tool request's description under its label, every line indented, so a
|
|
1386
|
+
line of it can't sit at column 0 where a menu option or prompt would."""
|
|
1387
|
+
for line in text.split("\n") if text else []:
|
|
1388
|
+
safe_print(f" {line}")
|
|
1389
|
+
|
|
1390
|
+
|
|
1347
1391
|
def format_interrupt_request(action: Any) -> Tuple[str, str]:
|
|
1348
1392
|
"""Render one HITL interrupt ``action_request`` to a ``(label, preview)`` pair.
|
|
1349
1393
|
|
|
@@ -1373,7 +1417,10 @@ def format_interrupt_request(action: Any) -> Tuple[str, str]:
|
|
|
1373
1417
|
if isinstance(action, dict):
|
|
1374
1418
|
key = _tool_key(action)
|
|
1375
1419
|
if key:
|
|
1376
|
-
|
|
1420
|
+
# A string description is shown as text by _approval_description (gh #221),
|
|
1421
|
+
# not as a capped, escaped description=... field.
|
|
1422
|
+
skip = (key, "description") if isinstance(action.get("description"), str) else (key,)
|
|
1423
|
+
return _approval_text(action[key], None), _approval_fields(action, skip=skip)
|
|
1377
1424
|
for key in _INTERRUPT_LABEL_KEYS:
|
|
1378
1425
|
val = action.get(key)
|
|
1379
1426
|
if isinstance(val, str) and val.strip():
|
|
@@ -1649,6 +1696,7 @@ def print_chunk(chunk: Dict[str, Any], verbose: bool = False):
|
|
|
1649
1696
|
# payload actionably (gh #82); the structured tool path is unchanged.
|
|
1650
1697
|
label, args_preview = format_interrupt_request(action)
|
|
1651
1698
|
safe_print(f" {DIM}{i + 1}. {label}{RESET}")
|
|
1699
|
+
_print_approval_description(_approval_description(action))
|
|
1652
1700
|
_print_approval_preview(args_preview)
|
|
1653
1701
|
else:
|
|
1654
1702
|
# No structured action_requests. A bare-string/scalar interrupt loses its
|
|
@@ -1663,6 +1711,7 @@ def print_chunk(chunk: Dict[str, Any], verbose: bool = False):
|
|
|
1663
1711
|
else:
|
|
1664
1712
|
label, args_preview = format_interrupt_request(raw)
|
|
1665
1713
|
safe_print(f" {DIM}{label}{RESET}")
|
|
1714
|
+
_print_approval_description(_approval_description(raw))
|
|
1666
1715
|
_print_approval_preview(args_preview)
|
|
1667
1716
|
|
|
1668
1717
|
elif status == "complete":
|
|
@@ -1890,12 +1939,18 @@ def select_option(options: List[str], prompt: str = "Select an option:") -> int:
|
|
|
1890
1939
|
|
|
1891
1940
|
|
|
1892
1941
|
def _select_option_typed(options: List[str], prompt: str) -> int:
|
|
1893
|
-
"""The approval menu
|
|
1942
|
+
"""The approval menu as a numbered list and a typed choice.
|
|
1894
1943
|
|
|
1895
1944
|
The arrow-key menu redraws itself with cursor-up and line-clear escapes, which a
|
|
1896
1945
|
dumb terminal prints as literal text, and editor shells (Emacs ``M-x shell``) send
|
|
1897
|
-
whole lines, not keypresses.
|
|
1898
|
-
|
|
1946
|
+
whole lines, not keypresses (gh #182). A mintty / Git Bash pty on Windows feeds
|
|
1947
|
+
lines to stdin but not the keypresses ``msvcrt.getch()`` reads, so it gets this
|
|
1948
|
+
menu too (gh #219).
|
|
1949
|
+
|
|
1950
|
+
A choice is the option's number, or a word that starts exactly one option's label
|
|
1951
|
+
(``a`` or ``approve`` for "Approve all actions", ``r``, ``e`` ...). Enter alone
|
|
1952
|
+
picks the first option. ``q``, Ctrl-C or end of input abandon the prompt the same
|
|
1953
|
+
way the arrow-key menu's Esc does: exit 2, paused.
|
|
1899
1954
|
"""
|
|
1900
1955
|
print(f"\n{prompt}")
|
|
1901
1956
|
for i, opt in enumerate(options, 1):
|
|
@@ -1910,7 +1965,14 @@ def _select_option_typed(options: List[str], prompt: str) -> int:
|
|
|
1910
1965
|
return 0
|
|
1911
1966
|
if raw.isdigit() and 1 <= int(raw) <= len(options):
|
|
1912
1967
|
return int(raw) - 1
|
|
1913
|
-
|
|
1968
|
+
word = raw.lower()
|
|
1969
|
+
if word in ("q", "quit"):
|
|
1970
|
+
print()
|
|
1971
|
+
sys.exit(EXIT_PAUSED)
|
|
1972
|
+
matches = [i for i, opt in enumerate(options) if opt.lower().startswith(word)]
|
|
1973
|
+
if len(matches) == 1:
|
|
1974
|
+
return matches[0]
|
|
1975
|
+
print(f"Enter a number from 1 to {len(options)}, or the start of an option's name.")
|
|
1914
1976
|
|
|
1915
1977
|
|
|
1916
1978
|
def _prompt_line(prompt: str) -> str:
|
|
@@ -1965,7 +2027,10 @@ def handle_interrupt_input(
|
|
|
1965
2027
|
# stopping. `--no-interactive` remains the documented way to opt into
|
|
1966
2028
|
# auto-approval, and the message points at it. (gh #86) On Windows `<NUL` passes
|
|
1967
2029
|
# isatty() but can't feed the menu's msvcrt.getch(), so it's checked too (gh #217).
|
|
1968
|
-
|
|
2030
|
+
# A mintty / Git Bash pty is a person at a terminal whose keypresses getch() can't
|
|
2031
|
+
# read either, but it does feed lines, so it gets the typed menu (gh #219).
|
|
2032
|
+
typed = not _stdin_drives_menu() and _stdin_is_interactive()
|
|
2033
|
+
if not typed and not _stdin_drives_menu():
|
|
1969
2034
|
print(
|
|
1970
2035
|
"Error: approval required but stdin is not a terminal.\n"
|
|
1971
2036
|
"Re-run with --no-interactive to auto-approve pending actions.",
|
|
@@ -1973,6 +2038,7 @@ def handle_interrupt_input(
|
|
|
1973
2038
|
)
|
|
1974
2039
|
# The run is fine but paused on human input: the family "paused" code (ADR 0007).
|
|
1975
2040
|
sys.exit(EXIT_PAUSED)
|
|
2041
|
+
pick = _select_option_typed if typed else select_option
|
|
1976
2042
|
|
|
1977
2043
|
if is_generic:
|
|
1978
2044
|
# A generic interrupt() asks for an arbitrary value, not tool approval, so
|
|
@@ -1982,7 +2048,7 @@ def handle_interrupt_input(
|
|
|
1982
2048
|
# case, where the user types `Alice` and the agent must receive `"Alice"`,
|
|
1983
2049
|
# not an envelope. What was typed is the answer, as text (gh #206).
|
|
1984
2050
|
options = ["Provide a response", "Exit"]
|
|
1985
|
-
choice =
|
|
2051
|
+
choice = pick(options, "How would you like to respond?")
|
|
1986
2052
|
if choice != 0:
|
|
1987
2053
|
sys.exit(EXIT_PAUSED) # left while paused on the interrupt (ADR 0007)
|
|
1988
2054
|
print(
|
|
@@ -2003,7 +2069,7 @@ def handle_interrupt_input(
|
|
|
2003
2069
|
options = [label for label, _ in entries]
|
|
2004
2070
|
|
|
2005
2071
|
while True:
|
|
2006
|
-
action = entries[
|
|
2072
|
+
action = entries[pick(options, "How would you like to proceed?")][1]
|
|
2007
2073
|
|
|
2008
2074
|
if action in ("approve", "reject"):
|
|
2009
2075
|
return {"decisions": [{"type": action} for _ in range(num_actions)]}
|
|
@@ -45,6 +45,7 @@ tests/test_legacy_config_home.py
|
|
|
45
45
|
tests/test_load_error.py
|
|
46
46
|
tests/test_menu_allowed_197.py
|
|
47
47
|
tests/test_message_boundaries.py
|
|
48
|
+
tests/test_mintty_approval_219.py
|
|
48
49
|
tests/test_no_color.py
|
|
49
50
|
tests/test_no_interactive_approve.py
|
|
50
51
|
tests/test_no_persist_resume.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "langstage-cli"
|
|
7
|
-
version = "0.6.
|
|
7
|
+
version = "0.6.62"
|
|
8
8
|
description = "The terminal stage for your LangGraph agent — Claude Code-style CLI for any CompiledGraph"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -96,7 +96,9 @@ def test_menu_asks_again_on_a_bad_choice(dumb, monkeypatch):
|
|
|
96
96
|
with redirect_stdout(buf):
|
|
97
97
|
assert cli.select_option(["Approve", "Reject"]) == 1
|
|
98
98
|
assert len(prompts) == 3
|
|
99
|
-
assert
|
|
99
|
+
assert (
|
|
100
|
+
buf.getvalue().count("Enter a number from 1 to 2, or the start of an option's name.") == 2
|
|
101
|
+
)
|
|
100
102
|
|
|
101
103
|
|
|
102
104
|
@pytest.mark.parametrize("abort", [KeyboardInterrupt(), EOFError()], ids=["ctrl-c", "eof"])
|
|
@@ -183,3 +183,81 @@ def test_langchain_hitl_middleware_request_is_labelled_by_its_tool():
|
|
|
183
183
|
assert label == "issue_refund"
|
|
184
184
|
assert "order_id=NW-1041" in preview and "amount=189" in preview
|
|
185
185
|
assert "name=" not in preview
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ---- gh #221: a tool request's description is text, in full, with its line breaks ----
|
|
189
|
+
|
|
190
|
+
from langstage_cli.cli import _approval_description # noqa: E402
|
|
191
|
+
|
|
192
|
+
_WARNING = (
|
|
193
|
+
"This permanently deletes the file and cannot be undone.\n"
|
|
194
|
+
"It is NOT recoverable from backups - double-check the path before approving."
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _hitl(description=None, **args):
|
|
199
|
+
req = {"name": "delete_file", "args": args or {"path": "/srv/data/customers.db"}}
|
|
200
|
+
if description is not None:
|
|
201
|
+
req["description"] = description
|
|
202
|
+
return req
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_custom_description_is_shown_in_full_with_its_line_breaks(capsys):
|
|
206
|
+
out = _render([_hitl(_WARNING)], capsys)
|
|
207
|
+
lines = out.splitlines()
|
|
208
|
+
# Both lines, uncut and unescaped, each indented under the label.
|
|
209
|
+
assert " This permanently deletes the file and cannot be undone." in lines
|
|
210
|
+
assert (
|
|
211
|
+
" It is NOT recoverable from backups - double-check the path before approving." in lines
|
|
212
|
+
)
|
|
213
|
+
assert "\\n" not in out and "description=" not in out
|
|
214
|
+
# The arguments are still listed under it.
|
|
215
|
+
assert "path=/srv/data/customers.db" in out
|
|
216
|
+
assert out.index("cannot be undone") < out.index("path=/srv/data")
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def test_description_is_not_cut_off_at_the_argument_cap():
|
|
220
|
+
text = "Read this before approving: " + "x" * 300
|
|
221
|
+
assert _approval_description(_hitl(text)) == text
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_default_middleware_description_is_hidden():
|
|
225
|
+
# "<prefix>\n\nTool: <name>\nArgs: <args>" only repeats the label and the args.
|
|
226
|
+
args = {"path": "/srv/data/customers.db"}
|
|
227
|
+
default = f"Tool execution requires approval\n\nTool: delete_file\nArgs: {args}"
|
|
228
|
+
assert _approval_description(_hitl(default, **args)) == ""
|
|
229
|
+
_, preview = format_interrupt_request(_hitl(default, **args))
|
|
230
|
+
assert preview == "path=/srv/data/customers.db"
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def test_custom_prefix_is_kept_and_its_tool_args_tail_dropped():
|
|
234
|
+
args = {"path": "/tmp/x"}
|
|
235
|
+
desc = f"Deleting needs a second pair of eyes\n\nTool: delete_file\nArgs: {args}"
|
|
236
|
+
assert _approval_description(_hitl(desc, **args)) == "Deleting needs a second pair of eyes"
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def test_description_control_characters_other_than_newline_and_tab_are_escaped(capsys):
|
|
240
|
+
out = _render([_hitl("Careful\x1b[2K\r\n\tsecond line")], capsys)
|
|
241
|
+
assert "\x1b[2K" not in out and "\r" not in out
|
|
242
|
+
assert "Careful\\x1b[2K\\r" in out
|
|
243
|
+
assert " \tsecond line" in out.splitlines()
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def test_description_lines_never_start_at_column_zero(capsys):
|
|
247
|
+
out = _render([_hitl("ok\n❯ Approve all actions")], capsys)
|
|
248
|
+
assert not any(line.startswith("❯") for line in out.splitlines()), out
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def test_args_keep_their_cap_next_to_a_description():
|
|
252
|
+
_, preview = format_interrupt_request(_hitl(_WARNING, content="y" * 500))
|
|
253
|
+
assert "y" * 500 not in preview and "..." in preview
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def test_non_string_description_and_generic_interrupts_are_unchanged():
|
|
257
|
+
# Only a tool review's string description becomes text; a generic interrupt's
|
|
258
|
+
# description is still its headline (gh #82).
|
|
259
|
+
assert _approval_description({"description": "Approve?"}) == ""
|
|
260
|
+
assert format_interrupt_request({"description": "Approve?"}) == ("Approve?", "")
|
|
261
|
+
req = {"name": "t", "args": {}, "description": {"k": 1}}
|
|
262
|
+
assert _approval_description(req) == ""
|
|
263
|
+
assert 'description={"k": 1}' in format_interrupt_request(req)[1]
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Approvals can be answered in a mintty / Git Bash terminal (gh #219).
|
|
2
|
+
|
|
3
|
+
On Windows a mintty pty is a pipe with an MSYS pty name. It counts as interactive, so
|
|
4
|
+
the REPL runs, but the arrow-key approval menu reads keys with ``msvcrt.getch()``,
|
|
5
|
+
which can't read it. Since gh #217 the first approval therefore exited 2. The menu now
|
|
6
|
+
falls back to the typed, line-based menu there: a number, or a word that starts one
|
|
7
|
+
option's name. ``NUL`` and real pipes still exit 2.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import builtins
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from langstage_cli import cli
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _mintty(monkeypatch):
|
|
18
|
+
monkeypatch.setattr(cli, "_stdin_drives_menu", lambda stream=None: False)
|
|
19
|
+
monkeypatch.setattr(cli, "_stdin_is_interactive", lambda stream=None: True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _feed(monkeypatch, *lines):
|
|
23
|
+
it = iter(lines)
|
|
24
|
+
|
|
25
|
+
def fake_input(prompt=""):
|
|
26
|
+
try:
|
|
27
|
+
return next(it)
|
|
28
|
+
except StopIteration:
|
|
29
|
+
raise EOFError from None
|
|
30
|
+
|
|
31
|
+
monkeypatch.setattr(builtins, "input", fake_input)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _no_keys(monkeypatch):
|
|
35
|
+
def boom():
|
|
36
|
+
raise AssertionError("the arrow-key menu must not read keys here")
|
|
37
|
+
|
|
38
|
+
monkeypatch.setattr(cli, "get_key", boom)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.mark.parametrize(
|
|
42
|
+
"answer, verb",
|
|
43
|
+
[
|
|
44
|
+
("1", "approve"),
|
|
45
|
+
("2", "reject"),
|
|
46
|
+
("a", "approve"),
|
|
47
|
+
("approve", "approve"),
|
|
48
|
+
("R", "reject"),
|
|
49
|
+
("Reject", "reject"),
|
|
50
|
+
("", "approve"),
|
|
51
|
+
],
|
|
52
|
+
)
|
|
53
|
+
def test_mintty_answers_the_approval_with_a_typed_line(monkeypatch, capsys, answer, verb):
|
|
54
|
+
_mintty(monkeypatch)
|
|
55
|
+
_no_keys(monkeypatch)
|
|
56
|
+
_feed(monkeypatch, answer)
|
|
57
|
+
result = cli.handle_interrupt_input(num_actions=2)
|
|
58
|
+
assert result == {"decisions": [{"type": verb}, {"type": verb}]}
|
|
59
|
+
out = capsys.readouterr().out
|
|
60
|
+
assert "1. Approve all actions" in out
|
|
61
|
+
assert "\033[?25l" not in out # no cursor escapes from the arrow-key menu
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.mark.parametrize("answer", ["4", "e", "exit", "q", "quit"])
|
|
65
|
+
def test_mintty_leaving_the_menu_exits_paused(monkeypatch, answer):
|
|
66
|
+
_mintty(monkeypatch)
|
|
67
|
+
_no_keys(monkeypatch)
|
|
68
|
+
_feed(monkeypatch, answer)
|
|
69
|
+
with pytest.raises(SystemExit) as exc:
|
|
70
|
+
cli.handle_interrupt_input(num_actions=1)
|
|
71
|
+
assert exc.value.code == cli.EXIT_PAUSED
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_mintty_end_of_input_exits_paused(monkeypatch):
|
|
75
|
+
_mintty(monkeypatch)
|
|
76
|
+
_no_keys(monkeypatch)
|
|
77
|
+
_feed(monkeypatch) # EOF at once
|
|
78
|
+
with pytest.raises(SystemExit) as exc:
|
|
79
|
+
cli.handle_interrupt_input(num_actions=1)
|
|
80
|
+
assert exc.value.code == cli.EXIT_PAUSED
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_mintty_unknown_answer_asks_again(monkeypatch, capsys):
|
|
84
|
+
_mintty(monkeypatch)
|
|
85
|
+
_no_keys(monkeypatch)
|
|
86
|
+
_feed(monkeypatch, "maybe", "9", "a")
|
|
87
|
+
assert cli.handle_interrupt_input(num_actions=1) == {"decisions": [{"type": "approve"}]}
|
|
88
|
+
out = capsys.readouterr().out
|
|
89
|
+
assert out.count("or the start of an option's name") == 2
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_mintty_generic_interrupt_takes_a_typed_answer(monkeypatch):
|
|
93
|
+
_mintty(monkeypatch)
|
|
94
|
+
_no_keys(monkeypatch)
|
|
95
|
+
_feed(monkeypatch, "p", "Alice")
|
|
96
|
+
assert cli.handle_interrupt_input(is_generic=True) == "Alice"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_mintty_custom_decision_flow(monkeypatch):
|
|
100
|
+
_mintty(monkeypatch)
|
|
101
|
+
_no_keys(monkeypatch)
|
|
102
|
+
_feed(monkeypatch, "3", '[{"type": "reject", "message": "not now"}]')
|
|
103
|
+
assert cli.handle_interrupt_input(num_actions=1) == {
|
|
104
|
+
"decisions": [{"type": "reject", "message": "not now"}]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_mintty_honours_allowed_decisions(monkeypatch, capsys):
|
|
109
|
+
# An approve-only action offers no "Reject all", so "r" matches nothing.
|
|
110
|
+
_mintty(monkeypatch)
|
|
111
|
+
_no_keys(monkeypatch)
|
|
112
|
+
_feed(monkeypatch, "r", "a")
|
|
113
|
+
interrupt = {
|
|
114
|
+
"action_requests": [{"name": "send_email", "args": {}}],
|
|
115
|
+
"review_configs": [{"action_name": "send_email", "allowed_decisions": ["approve"]}],
|
|
116
|
+
}
|
|
117
|
+
assert cli.handle_interrupt_input(num_actions=1, interrupt=interrupt) == {
|
|
118
|
+
"decisions": [{"type": "approve"}]
|
|
119
|
+
}
|
|
120
|
+
assert "Reject all actions" not in capsys.readouterr().out
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_ambiguous_prefix_asks_again(monkeypatch):
|
|
124
|
+
_feed(monkeypatch, "rej", "2")
|
|
125
|
+
assert cli._select_option_typed(["Reject all", "Reject one"], "Pick") == 1
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_not_interactive_still_exits_paused(monkeypatch, capsys):
|
|
129
|
+
# NUL or a real pipe: neither drives the menu nor counts as a person (gh #217).
|
|
130
|
+
monkeypatch.setattr(cli, "_stdin_drives_menu", lambda stream=None: False)
|
|
131
|
+
monkeypatch.setattr(cli, "_stdin_is_interactive", lambda stream=None: False)
|
|
132
|
+
_no_keys(monkeypatch)
|
|
133
|
+
with pytest.raises(SystemExit) as exc:
|
|
134
|
+
cli.handle_interrupt_input(num_actions=1)
|
|
135
|
+
assert exc.value.code == cli.EXIT_PAUSED
|
|
136
|
+
assert "approval required but stdin is not a terminal" in capsys.readouterr().err
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_real_console_keeps_the_arrow_menu(monkeypatch, capsys):
|
|
140
|
+
monkeypatch.setattr(cli, "_stdin_drives_menu", lambda stream=None: True)
|
|
141
|
+
monkeypatch.setattr(cli, "_stdin_is_interactive", lambda stream=None: True)
|
|
142
|
+
monkeypatch.setattr(cli, "_DUMB_TERM", False)
|
|
143
|
+
monkeypatch.setattr(cli, "get_key", lambda: "enter")
|
|
144
|
+
assert cli.handle_interrupt_input(num_actions=1) == {"decisions": [{"type": "approve"}]}
|
|
145
|
+
assert "Choose 1-" not in capsys.readouterr().out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|