langstage-cli 0.6.59__tar.gz → 0.6.60__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.59/langstage_cli.egg-info → langstage_cli-0.6.60}/PKG-INFO +1 -1
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli/cli.py +23 -2
- {langstage_cli-0.6.59 → langstage_cli-0.6.60/langstage_cli.egg-info}/PKG-INFO +1 -1
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli.egg-info/SOURCES.txt +1 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/pyproject.toml +1 -1
- langstage_cli-0.6.60/tests/test_nul_approval_217.py +123 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/LICENSE +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/README.md +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/deepagent_code/__init__.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli/__init__.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli/agui_stream.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli/config.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli/exit_codes.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli/sessions.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli.egg-info/dependency_links.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli.egg-info/entry_points.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli.egg-info/requires.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/langstage_cli.egg-info/top_level.txt +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/setup.cfg +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_advertised_wave4.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_agui_stream.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_approval_menu_abort.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_approval_menu_keys_211.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_async_mode.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_checkpointer.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_cli.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_cli_help.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_codeconfig.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_config.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_config_command.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_configurable.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_ctrl_c_sync_tool.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_custom_decision_195.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_decision_shapes_209.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_deferred_pass.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_dumb_term.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_exit_codes.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_generic_interrupt.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_help_render.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_hidden_option_suggestions.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_history_persist.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_hitl_approval_preview.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_hitl_resume_warning.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_init.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_interrupt_answer_text_206.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_interrupt_non_tty.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_legacy_config_home.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_load_error.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_menu_allowed_197.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_message_boundaries.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_no_color.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_no_interactive_approve.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_no_persist_resume.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_paused_session_message.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_persist_env.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_quiet_output.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_quiet_tool_result_204.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_reasoning_render.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_rename_shim.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_render_markdown.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_routine_1024.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_session_agent_215.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_session_lifecycle.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_sessions.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_show_config.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_show_config_bare_spec_213.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_show_config_malformed.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_spec_loading_core.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_spec_resolution.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_spinner_reply_survives.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_stdin_interactive.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_stdin_single_shot.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_stream_mode.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_streaming_marker.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_terminal_width.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_toml_relative_paths.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_tool_card_args.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_tool_output_escape.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_turn_error_verbose.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_turn_exit_and_render.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_unicode_console.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_usage_hint_186.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_verbose_command.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_verify_flag.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_workspace.py +0 -0
- {langstage_cli-0.6.59 → langstage_cli-0.6.60}/tests/test_wrong_type_graph.py +0 -0
|
@@ -164,6 +164,26 @@ def _stdin_is_interactive(stream=None) -> bool:
|
|
|
164
164
|
return name is not None and _is_msys_pty_name(name)
|
|
165
165
|
|
|
166
166
|
|
|
167
|
+
def _stdin_drives_menu(stream=None) -> bool:
|
|
168
|
+
"""Whether the arrow-key approval menu can read keys from stdin (gh #217).
|
|
169
|
+
|
|
170
|
+
On POSIX the menu reads the stdin fd through termios, so it needs ``isatty()``.
|
|
171
|
+
On Windows ``get_key()`` reads keys with ``msvcrt.getch()``, which reads the
|
|
172
|
+
console, not stdin. So stdin itself has to be that console. ``NUL`` passes
|
|
173
|
+
``isatty()`` but isn't one: it used to reach the menu, and ``getch()`` then
|
|
174
|
+
waited forever for keys nobody would type. A mintty / Git Bash pty is a pipe that
|
|
175
|
+
``getch()`` can't read either, so it stays "not a terminal" for the menu, though
|
|
176
|
+
it does count as interactive for the REPL's own line input. If the console check
|
|
177
|
+
can't run, the ``isatty()`` answer stands.
|
|
178
|
+
"""
|
|
179
|
+
stream = sys.stdin if stream is None else stream
|
|
180
|
+
tty = _is_a_tty(stream)
|
|
181
|
+
if not IS_WINDOWS or not tty:
|
|
182
|
+
return tty
|
|
183
|
+
console = _win_is_console(stream)
|
|
184
|
+
return tty if console is None else console
|
|
185
|
+
|
|
186
|
+
|
|
167
187
|
def _disable_ansi() -> None:
|
|
168
188
|
"""Blank every ANSI constant so nothing colorized reaches a pipe, a file or a
|
|
169
189
|
``NO_COLOR`` terminal (gh #172).
|
|
@@ -1943,8 +1963,9 @@ def handle_interrupt_input(
|
|
|
1943
1963
|
# printed, and fail loudly rather than auto-approving: an interrupt() is a request
|
|
1944
1964
|
# for human review, so silently approving an action nobody saw is worse than
|
|
1945
1965
|
# stopping. `--no-interactive` remains the documented way to opt into
|
|
1946
|
-
# auto-approval, and the message points at it. (gh #86)
|
|
1947
|
-
|
|
1966
|
+
# auto-approval, and the message points at it. (gh #86) On Windows `<NUL` passes
|
|
1967
|
+
# isatty() but can't feed the menu's msvcrt.getch(), so it's checked too (gh #217).
|
|
1968
|
+
if not _stdin_drives_menu():
|
|
1948
1969
|
print(
|
|
1949
1970
|
"Error: approval required but stdin is not a terminal.\n"
|
|
1950
1971
|
"Re-run with --no-interactive to auto-approve pending actions.",
|
|
@@ -48,6 +48,7 @@ tests/test_message_boundaries.py
|
|
|
48
48
|
tests/test_no_color.py
|
|
49
49
|
tests/test_no_interactive_approve.py
|
|
50
50
|
tests/test_no_persist_resume.py
|
|
51
|
+
tests/test_nul_approval_217.py
|
|
51
52
|
tests/test_paused_session_message.py
|
|
52
53
|
tests/test_persist_env.py
|
|
53
54
|
tests/test_quiet_output.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.60"
|
|
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"
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""An approval with stdin from ``NUL`` exits 2 instead of hanging (gh #217).
|
|
2
|
+
|
|
3
|
+
On Windows ``NUL`` is a character device, so ``isatty()`` is True for ``<NUL``. The
|
|
4
|
+
approval guard used a plain ``isatty()``, let the run into the arrow-key menu, and
|
|
5
|
+
``msvcrt.getch()`` (which reads the console, not stdin) then waited forever. Task
|
|
6
|
+
Scheduler, services, CI runners and ``subprocess.run(..., stdin=DEVNULL)`` all hand a
|
|
7
|
+
process ``NUL``, so an unattended approval-gated run never ended. The guard now asks
|
|
8
|
+
whether stdin can actually drive the menu.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import textwrap
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
from click.testing import CliRunner
|
|
17
|
+
|
|
18
|
+
from langstage_cli import cli
|
|
19
|
+
from langstage_cli.cli import main
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class _Stream:
|
|
23
|
+
def __init__(self, tty: bool):
|
|
24
|
+
self._tty = tty
|
|
25
|
+
|
|
26
|
+
def isatty(self) -> bool:
|
|
27
|
+
return self._tty
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _on_windows(monkeypatch, *, console=None, name=None):
|
|
31
|
+
monkeypatch.setattr(cli, "IS_WINDOWS", True)
|
|
32
|
+
monkeypatch.setattr(cli, "_win_is_console", lambda stream: console)
|
|
33
|
+
monkeypatch.setattr(cli, "_win_handle_name", lambda stream: name)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_windows_console_drives_the_menu(monkeypatch):
|
|
37
|
+
_on_windows(monkeypatch, console=True)
|
|
38
|
+
assert cli._stdin_drives_menu(_Stream(tty=True)) is True
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_windows_nul_does_not_drive_the_menu(monkeypatch):
|
|
42
|
+
# isatty() is True for NUL, but GetConsoleMode fails on it.
|
|
43
|
+
_on_windows(monkeypatch, console=False)
|
|
44
|
+
assert cli._stdin_drives_menu(_Stream(tty=True)) is False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_windows_console_check_unavailable_keeps_isatty(monkeypatch):
|
|
48
|
+
_on_windows(monkeypatch, console=None)
|
|
49
|
+
assert cli._stdin_drives_menu(_Stream(tty=True)) is True
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_windows_mintty_pty_does_not_drive_the_menu(monkeypatch):
|
|
53
|
+
# A mintty pty is interactive for line input, but msvcrt.getch() can't read it,
|
|
54
|
+
# so the menu keeps refusing it cleanly (exit 2) rather than hanging.
|
|
55
|
+
_on_windows(monkeypatch, name="\\msys-dd50a72ab4668b33-pty0-from-master")
|
|
56
|
+
assert cli._stdin_is_interactive(_Stream(tty=False)) is True
|
|
57
|
+
assert cli._stdin_drives_menu(_Stream(tty=False)) is False
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.mark.parametrize("tty", [True, False])
|
|
61
|
+
def test_posix_is_plain_isatty(monkeypatch, tty):
|
|
62
|
+
monkeypatch.setattr(cli, "IS_WINDOWS", False)
|
|
63
|
+
assert cli._stdin_drives_menu(_Stream(tty=tty)) is tty
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_HITL_AGENT = textwrap.dedent(
|
|
67
|
+
"""
|
|
68
|
+
from langgraph.graph import StateGraph, START, END
|
|
69
|
+
from langgraph.graph.message import MessagesState
|
|
70
|
+
from langgraph.checkpoint.memory import MemorySaver
|
|
71
|
+
from langgraph.types import interrupt
|
|
72
|
+
from langchain_core.messages import AIMessage
|
|
73
|
+
|
|
74
|
+
def ask(state):
|
|
75
|
+
decision = interrupt({"action": "delete_file", "path": "/tmp/x"})
|
|
76
|
+
return {"messages": [AIMessage(content=f"Decision was: {decision}")]}
|
|
77
|
+
|
|
78
|
+
g = StateGraph(MessagesState)
|
|
79
|
+
g.add_node("ask", ask)
|
|
80
|
+
g.add_edge(START, "ask")
|
|
81
|
+
g.add_edge("ask", END)
|
|
82
|
+
graph = g.compile(checkpointer=MemorySaver())
|
|
83
|
+
"""
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_nul_stdin_approval_exits_paused_without_reading_keys(tmp_path, monkeypatch):
|
|
88
|
+
# Simulate Windows `<NUL`: isatty() True, not a console.
|
|
89
|
+
(tmp_path / "hitl_agent.py").write_text(_HITL_AGENT)
|
|
90
|
+
monkeypatch.chdir(tmp_path)
|
|
91
|
+
monkeypatch.setattr(cli, "IS_WINDOWS", True)
|
|
92
|
+
monkeypatch.setattr(cli, "_win_is_console", lambda stream: False)
|
|
93
|
+
monkeypatch.setattr(cli, "_is_a_tty", lambda stream: True)
|
|
94
|
+
|
|
95
|
+
def _no_keys():
|
|
96
|
+
raise AssertionError("the menu must not read keys from NUL")
|
|
97
|
+
|
|
98
|
+
monkeypatch.setattr(cli, "get_key", _no_keys)
|
|
99
|
+
r = CliRunner().invoke(main, ["-a", "hitl_agent.py:graph", "please act"])
|
|
100
|
+
|
|
101
|
+
assert r.exit_code == 2, (r.exit_code, r.output, r.exception)
|
|
102
|
+
assert "approval required but stdin is not a terminal" in r.stderr, r.stderr
|
|
103
|
+
assert "--no-interactive" in r.stderr, r.stderr
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@pytest.mark.skipif(sys.platform != "win32", reason="NUL passes isatty() only on Windows")
|
|
107
|
+
def test_real_devnull_run_exits_2_instead_of_hanging():
|
|
108
|
+
proc = subprocess.run(
|
|
109
|
+
[
|
|
110
|
+
sys.executable,
|
|
111
|
+
"-c",
|
|
112
|
+
"from langstage_cli.cli import main; main()",
|
|
113
|
+
"-a",
|
|
114
|
+
"langstage_core.demo.tools:graph",
|
|
115
|
+
"ask me",
|
|
116
|
+
],
|
|
117
|
+
stdin=subprocess.DEVNULL,
|
|
118
|
+
capture_output=True,
|
|
119
|
+
text=True,
|
|
120
|
+
timeout=120,
|
|
121
|
+
)
|
|
122
|
+
assert proc.returncode == 2, (proc.returncode, proc.stdout, proc.stderr)
|
|
123
|
+
assert "approval required but stdin is not a terminal" in proc.stderr, proc.stderr
|
|
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
|
|
File without changes
|