langstage-cli 0.6.58__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.58/langstage_cli.egg-info → langstage_cli-0.6.60}/PKG-INFO +14 -7
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/README.md +13 -6
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli/cli.py +118 -10
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli/sessions.py +48 -2
- {langstage_cli-0.6.58 → langstage_cli-0.6.60/langstage_cli.egg-info}/PKG-INFO +14 -7
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli.egg-info/SOURCES.txt +2 -0
- {langstage_cli-0.6.58 → 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.60/tests/test_session_agent_215.py +194 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/LICENSE +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/deepagent_code/__init__.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli/__init__.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli/agui_stream.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli/config.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli/exit_codes.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli.egg-info/dependency_links.txt +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli.egg-info/entry_points.txt +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli.egg-info/requires.txt +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/langstage_cli.egg-info/top_level.txt +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/setup.cfg +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_advertised_wave4.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_agui_stream.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_approval_menu_abort.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_approval_menu_keys_211.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_async_mode.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_checkpointer.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_cli.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_cli_help.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_codeconfig.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_config.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_config_command.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_configurable.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_ctrl_c_sync_tool.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_custom_decision_195.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_decision_shapes_209.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_deferred_pass.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_dumb_term.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_exit_codes.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_generic_interrupt.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_help_render.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_hidden_option_suggestions.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_history_persist.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_hitl_approval_preview.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_hitl_resume_warning.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_init.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_interrupt_answer_text_206.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_interrupt_non_tty.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_legacy_config_home.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_load_error.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_menu_allowed_197.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_message_boundaries.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_no_color.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_no_interactive_approve.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_no_persist_resume.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_paused_session_message.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_persist_env.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_quiet_output.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_quiet_tool_result_204.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_reasoning_render.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_rename_shim.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_render_markdown.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_routine_1024.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_session_lifecycle.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_sessions.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_show_config.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_show_config_bare_spec_213.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_show_config_malformed.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_spec_loading_core.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_spec_resolution.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_spinner_reply_survives.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_stdin_interactive.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_stdin_single_shot.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_stream_mode.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_streaming_marker.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_terminal_width.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_toml_relative_paths.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_tool_card_args.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_tool_output_escape.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_turn_error_verbose.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_turn_exit_and_render.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_unicode_console.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_usage_hint_186.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_verbose_command.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_verify_flag.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_workspace.py +0 -0
- {langstage_cli-0.6.58 → langstage_cli-0.6.60}/tests/test_wrong_type_graph.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langstage-cli
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.60
|
|
4
4
|
Summary: The terminal stage for your LangGraph agent — Claude Code-style CLI for any CompiledGraph
|
|
5
5
|
Author-email: Kedar Dabhadkar <kdabhadk@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -142,8 +142,8 @@ langstage-cli --show-config
|
|
|
142
142
|
|
|
143
143
|
# Resume a previous conversation across separate invocations
|
|
144
144
|
langstage-cli "remember: my name is Kedar" # a fresh, PERSISTED session
|
|
145
|
-
langstage-cli -c "what's my name?" # continue
|
|
146
|
-
langstage-cli --list-sessions # list resumable sessions
|
|
145
|
+
langstage-cli -c "what's my name?" # continue this agent's most recent session
|
|
146
|
+
langstage-cli --list-sessions # list resumable sessions, with their agents
|
|
147
147
|
langstage-cli --resume <id> # resume a specific one
|
|
148
148
|
```
|
|
149
149
|
|
|
@@ -166,11 +166,17 @@ Every invocation persists its conversation to a durable, per-workspace store so
|
|
|
166
166
|
run can pick it up — the terminal-agent continuity of Claude Code / Codex / Aider,
|
|
167
167
|
without you baking a checkpointer into your own graph:
|
|
168
168
|
|
|
169
|
-
- `--continue` / `-c` — resume the **most recent** session
|
|
170
|
-
going. If there's no prior session, it just starts a fresh one.
|
|
169
|
+
- `--continue` / `-c` — resume the **most recent** session this agent made in this
|
|
170
|
+
workspace and keep going. If there's no prior session, it just starts a fresh one.
|
|
171
|
+
Another agent's sessions are skipped, so trying `--demo` and then your own graph in the
|
|
172
|
+
same directory doesn't hand your graph the demo's conversation.
|
|
171
173
|
- `--resume <id>` — resume a **specific** session (ids come from `--list-sessions`; a
|
|
172
174
|
bare `--resume` also lists them). A short prefix works if it's unambiguous; an
|
|
173
|
-
ambiguous one is an error that lists the sessions it matches.
|
|
175
|
+
ambiguous one is an error that lists the sessions it matches. Resuming another agent's
|
|
176
|
+
session works but says so; one paused at another agent's approval is refused (exit `1`),
|
|
177
|
+
since this agent can't answer it.
|
|
178
|
+
- `--list-sessions` shows which agent made each session (`-` for sessions saved before
|
|
179
|
+
0.6.59, which `-c` still picks up).
|
|
174
180
|
- A plain run with no flag starts a **new** session that is still persisted, so it can be
|
|
175
181
|
continued later.
|
|
176
182
|
- A session left paused at an approval (exit `2`) is resolved before a new message: the
|
|
@@ -286,7 +292,8 @@ Options:
|
|
|
286
292
|
--show-config Print the resolved configuration and exit
|
|
287
293
|
-q, --quiet Scriptable single-shot output: only the reply
|
|
288
294
|
--verify Preflight the agent (one real turn); exit 0/1
|
|
289
|
-
-c, --continue Resume
|
|
295
|
+
-c, --continue Resume this agent's most recent session for this
|
|
296
|
+
workspace
|
|
290
297
|
--resume [ID] Resume a specific session (bare: list them)
|
|
291
298
|
--list-sessions List resumable sessions for this workspace
|
|
292
299
|
--persist/--no-persist Persist this session so it can be continued (default: on)
|
|
@@ -104,8 +104,8 @@ langstage-cli --show-config
|
|
|
104
104
|
|
|
105
105
|
# Resume a previous conversation across separate invocations
|
|
106
106
|
langstage-cli "remember: my name is Kedar" # a fresh, PERSISTED session
|
|
107
|
-
langstage-cli -c "what's my name?" # continue
|
|
108
|
-
langstage-cli --list-sessions # list resumable sessions
|
|
107
|
+
langstage-cli -c "what's my name?" # continue this agent's most recent session
|
|
108
|
+
langstage-cli --list-sessions # list resumable sessions, with their agents
|
|
109
109
|
langstage-cli --resume <id> # resume a specific one
|
|
110
110
|
```
|
|
111
111
|
|
|
@@ -128,11 +128,17 @@ Every invocation persists its conversation to a durable, per-workspace store so
|
|
|
128
128
|
run can pick it up — the terminal-agent continuity of Claude Code / Codex / Aider,
|
|
129
129
|
without you baking a checkpointer into your own graph:
|
|
130
130
|
|
|
131
|
-
- `--continue` / `-c` — resume the **most recent** session
|
|
132
|
-
going. If there's no prior session, it just starts a fresh one.
|
|
131
|
+
- `--continue` / `-c` — resume the **most recent** session this agent made in this
|
|
132
|
+
workspace and keep going. If there's no prior session, it just starts a fresh one.
|
|
133
|
+
Another agent's sessions are skipped, so trying `--demo` and then your own graph in the
|
|
134
|
+
same directory doesn't hand your graph the demo's conversation.
|
|
133
135
|
- `--resume <id>` — resume a **specific** session (ids come from `--list-sessions`; a
|
|
134
136
|
bare `--resume` also lists them). A short prefix works if it's unambiguous; an
|
|
135
|
-
ambiguous one is an error that lists the sessions it matches.
|
|
137
|
+
ambiguous one is an error that lists the sessions it matches. Resuming another agent's
|
|
138
|
+
session works but says so; one paused at another agent's approval is refused (exit `1`),
|
|
139
|
+
since this agent can't answer it.
|
|
140
|
+
- `--list-sessions` shows which agent made each session (`-` for sessions saved before
|
|
141
|
+
0.6.59, which `-c` still picks up).
|
|
136
142
|
- A plain run with no flag starts a **new** session that is still persisted, so it can be
|
|
137
143
|
continued later.
|
|
138
144
|
- A session left paused at an approval (exit `2`) is resolved before a new message: the
|
|
@@ -248,7 +254,8 @@ Options:
|
|
|
248
254
|
--show-config Print the resolved configuration and exit
|
|
249
255
|
-q, --quiet Scriptable single-shot output: only the reply
|
|
250
256
|
--verify Preflight the agent (one real turn); exit 0/1
|
|
251
|
-
-c, --continue Resume
|
|
257
|
+
-c, --continue Resume this agent's most recent session for this
|
|
258
|
+
workspace
|
|
252
259
|
--resume [ID] Resume a specific session (bare: list them)
|
|
253
260
|
--list-sessions List resumable sessions for this workspace
|
|
254
261
|
--persist/--no-persist Persist this session so it can be continued (default: on)
|
|
@@ -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).
|
|
@@ -1183,6 +1203,41 @@ def _absolutize_file_spec(spec: str) -> str:
|
|
|
1183
1203
|
return f"{Path(path_part).expanduser().resolve()}{suffix}"
|
|
1184
1204
|
|
|
1185
1205
|
|
|
1206
|
+
def _session_agent_id(spec: str, base_dir: Path, graph_name: str) -> str:
|
|
1207
|
+
"""The agent a session is recorded under in the session index (gh #215).
|
|
1208
|
+
|
|
1209
|
+
A file spec becomes its absolute path (resolved against ``base_dir``, the same base
|
|
1210
|
+
the spec was loaded from), so one agent reads alike from any subdirectory; a module
|
|
1211
|
+
spec stays as typed. The graph attribute is always named, so ``agent.py`` and
|
|
1212
|
+
``agent.py:graph`` are the same agent.
|
|
1213
|
+
"""
|
|
1214
|
+
parsed = _split_py_file_spec(spec)
|
|
1215
|
+
if parsed is not None:
|
|
1216
|
+
path = Path(parsed[0]).expanduser()
|
|
1217
|
+
if not path.is_absolute():
|
|
1218
|
+
path = Path(base_dir) / path
|
|
1219
|
+
return f"{path.resolve()}:{graph_name}"
|
|
1220
|
+
module = spec.rsplit(":", 1)[0] if ":" in spec else spec
|
|
1221
|
+
return f"{module}:{graph_name}"
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
def _shown_agent(agent: Optional[str], workspace: Path) -> str:
|
|
1225
|
+
"""A recorded agent as the session list and notes print it: a file inside the
|
|
1226
|
+
workspace relative to it, one under the home directory with ``~``."""
|
|
1227
|
+
if not agent:
|
|
1228
|
+
return "-"
|
|
1229
|
+
parsed = _split_py_file_spec(agent)
|
|
1230
|
+
if parsed is None:
|
|
1231
|
+
return agent
|
|
1232
|
+
path, suffix = Path(parsed[0]), parsed[1]
|
|
1233
|
+
for root, prefix in ((Path(workspace), ""), (Path.home(), "~/")):
|
|
1234
|
+
try:
|
|
1235
|
+
return f"{prefix}{path.relative_to(root).as_posix()}{suffix}"
|
|
1236
|
+
except ValueError:
|
|
1237
|
+
continue
|
|
1238
|
+
return agent
|
|
1239
|
+
|
|
1240
|
+
|
|
1186
1241
|
# Per-value cap on the tool-call card (default output; ``-v`` shows values in full).
|
|
1187
1242
|
_TOOL_ARG_VALUE_MAX = 50
|
|
1188
1243
|
|
|
@@ -1908,8 +1963,9 @@ def handle_interrupt_input(
|
|
|
1908
1963
|
# printed, and fail loudly rather than auto-approving: an interrupt() is a request
|
|
1909
1964
|
# for human review, so silently approving an action nobody saw is worse than
|
|
1910
1965
|
# stopping. `--no-interactive` remains the documented way to opt into
|
|
1911
|
-
# auto-approval, and the message points at it. (gh #86)
|
|
1912
|
-
|
|
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():
|
|
1913
1969
|
print(
|
|
1914
1970
|
"Error: approval required but stdin is not a terminal.\n"
|
|
1915
1971
|
"Re-run with --no-interactive to auto-approve pending actions.",
|
|
@@ -3454,18 +3510,35 @@ def scaffold_init(target_dir: Path, force: bool = False) -> int:
|
|
|
3454
3510
|
|
|
3455
3511
|
|
|
3456
3512
|
def _resolve_resume_thread(
|
|
3457
|
-
workspace: Path,
|
|
3513
|
+
workspace: Path,
|
|
3514
|
+
continue_session: bool,
|
|
3515
|
+
resume_id: Optional[str],
|
|
3516
|
+
agent: Optional[str] = None,
|
|
3458
3517
|
) -> Optional[str]:
|
|
3459
3518
|
"""The thread ``--continue`` / ``--resume <id>`` targets, or ``None`` for a fresh one.
|
|
3460
3519
|
|
|
3461
3520
|
``--continue`` with nothing to continue notes it and starts fresh; an unknown
|
|
3462
3521
|
``--resume`` id is an error (exit 1).
|
|
3522
|
+
|
|
3523
|
+
With ``agent`` (the loaded agent, gh #215), ``--continue`` takes the most recent
|
|
3524
|
+
session recorded for THIS agent (or one recorded before agents were), never another
|
|
3525
|
+
agent's. ``--resume`` of another agent's session says so; if that session is paused
|
|
3526
|
+
at an approval, it is an error (exit 1): this agent can't answer it, and a new
|
|
3527
|
+
message must not be stacked onto the paused turn.
|
|
3463
3528
|
"""
|
|
3464
3529
|
thread: Optional[str] = None
|
|
3465
3530
|
if continue_session:
|
|
3466
|
-
thread = sessions.most_recent_thread(workspace)
|
|
3531
|
+
thread = sessions.most_recent_thread(workspace, agent=agent)
|
|
3467
3532
|
if thread is None:
|
|
3468
|
-
|
|
3533
|
+
if agent is not None and sessions.most_recent_thread(workspace) is not None:
|
|
3534
|
+
_status(
|
|
3535
|
+
f"{DIM}⏺ No prior session for this agent in this workspace (only other "
|
|
3536
|
+
f"agents' sessions, see --list-sessions) — starting a fresh one.{RESET}"
|
|
3537
|
+
)
|
|
3538
|
+
else:
|
|
3539
|
+
_status(
|
|
3540
|
+
f"{DIM}⏺ No prior session for this workspace — starting a fresh one.{RESET}"
|
|
3541
|
+
)
|
|
3469
3542
|
return None
|
|
3470
3543
|
elif resume_id is not None:
|
|
3471
3544
|
matches = sessions.match_threads(workspace, resume_id)
|
|
@@ -3485,6 +3558,24 @@ def _resolve_resume_thread(
|
|
|
3485
3558
|
_status(f"{DIM}Run --list-sessions to see available sessions.{RESET}")
|
|
3486
3559
|
sys.exit(1)
|
|
3487
3560
|
thread = matches[0]
|
|
3561
|
+
recorded = sessions.load_index(workspace).get(thread, {}).get("agent")
|
|
3562
|
+
if agent is not None and recorded and recorded != agent:
|
|
3563
|
+
shown = sessions.display_id(thread)
|
|
3564
|
+
made_by, current = _shown_agent(recorded, workspace), _shown_agent(agent, workspace)
|
|
3565
|
+
if sessions.thread_is_paused(workspace, thread):
|
|
3566
|
+
_status(
|
|
3567
|
+
f"{RED}⏺ Error: session {shown} is paused at an approval from {made_by}, "
|
|
3568
|
+
f"which {current} can't answer.{RESET}"
|
|
3569
|
+
)
|
|
3570
|
+
_status(
|
|
3571
|
+
f"{DIM}Resume it with its own agent (-a {made_by} --resume {shown}), "
|
|
3572
|
+
f"or start a new session.{RESET}"
|
|
3573
|
+
)
|
|
3574
|
+
sys.exit(1)
|
|
3575
|
+
_status(
|
|
3576
|
+
f"{YELLOW}note: session {shown} was created by {made_by}; "
|
|
3577
|
+
f"resuming it with {current}.{RESET}"
|
|
3578
|
+
)
|
|
3488
3579
|
if (
|
|
3489
3580
|
thread is not None
|
|
3490
3581
|
and sessions.load_index(workspace).get(thread, {}).get("checkpointer") == "agent"
|
|
@@ -3679,6 +3770,9 @@ def _print_sessions(workspace: Path) -> None:
|
|
|
3679
3770
|
all_ids = [tid for tid, _ in rows]
|
|
3680
3771
|
shown = {tid: sessions.display_id(tid, all_ids) for tid in all_ids}
|
|
3681
3772
|
width = max(len(s) for s in shown.values())
|
|
3773
|
+
# The agent each session was made by (gh #215); "-" for one recorded before that.
|
|
3774
|
+
agents = {tid: _shown_agent(entry.get("agent"), workspace) for tid, entry in rows}
|
|
3775
|
+
agent_width = max(len(a) for a in agents.values())
|
|
3682
3776
|
for tid, entry in rows:
|
|
3683
3777
|
when = _format_ts(entry.get("updated"))
|
|
3684
3778
|
first = entry.get("first_message") or f"{DIM}(no message yet){RESET}"
|
|
@@ -3691,8 +3785,14 @@ def _print_sessions(workspace: Path) -> None:
|
|
|
3691
3785
|
)
|
|
3692
3786
|
# A pinned id is shown in full and a minted UUID by its shortest unique prefix, so
|
|
3693
3787
|
# two sessions never look alike and each shown id works with --resume (gh #188).
|
|
3694
|
-
print(
|
|
3695
|
-
|
|
3788
|
+
print(
|
|
3789
|
+
f" {CYAN}{shown[tid]:<{width}}{RESET} {DIM}{when}{RESET} "
|
|
3790
|
+
f"{GRAY}{agents[tid]:<{agent_width}}{RESET} {first}{mark}"
|
|
3791
|
+
)
|
|
3792
|
+
print(
|
|
3793
|
+
f"\n{DIM}Resume with: langstage-cli --resume <id> "
|
|
3794
|
+
f"(or -c for this agent's most recent){RESET}\n"
|
|
3795
|
+
)
|
|
3696
3796
|
|
|
3697
3797
|
|
|
3698
3798
|
@click.command(
|
|
@@ -3800,7 +3900,7 @@ def _print_sessions(workspace: Path) -> None:
|
|
|
3800
3900
|
"continue_session",
|
|
3801
3901
|
is_flag=True,
|
|
3802
3902
|
default=False,
|
|
3803
|
-
help="Resume
|
|
3903
|
+
help="Resume this agent's MOST RECENT session for this workspace and keep the "
|
|
3804
3904
|
"conversation going (cross-invocation memory). Starts fresh if there is none.",
|
|
3805
3905
|
)
|
|
3806
3906
|
@click.option(
|
|
@@ -4255,11 +4355,16 @@ def main(
|
|
|
4255
4355
|
)
|
|
4256
4356
|
|
|
4257
4357
|
# ---- Resolve the session thread + wire up persistence (gh #102) ----
|
|
4358
|
+
# Each session records the agent that made it, so --continue stays with this
|
|
4359
|
+
# agent's sessions and --resume of another agent's says so (gh #215).
|
|
4360
|
+
session_agent = _session_agent_id(final_spec, spec_base, final_graph_name)
|
|
4258
4361
|
persist_sqlite_path: Optional[Path] = None
|
|
4259
4362
|
session_thread: Optional[str] = None
|
|
4260
4363
|
on_turn = None
|
|
4261
4364
|
if read_only_resume:
|
|
4262
|
-
session_thread = _resolve_resume_thread(
|
|
4365
|
+
session_thread = _resolve_resume_thread(
|
|
4366
|
+
workspace, continue_session, resume_id, agent=session_agent
|
|
4367
|
+
)
|
|
4263
4368
|
persist_sqlite_path = None
|
|
4264
4369
|
if session_thread is not None:
|
|
4265
4370
|
config_dict["configurable"]["thread_id"] = session_thread
|
|
@@ -4282,7 +4387,9 @@ def main(
|
|
|
4282
4387
|
"thread": session_thread,
|
|
4283
4388
|
}
|
|
4284
4389
|
elif persist:
|
|
4285
|
-
session_thread = _resolve_resume_thread(
|
|
4390
|
+
session_thread = _resolve_resume_thread(
|
|
4391
|
+
workspace, continue_session, resume_id, agent=session_agent
|
|
4392
|
+
)
|
|
4286
4393
|
if session_thread is None:
|
|
4287
4394
|
# Fresh persisted session: honour a pinned [configurable] thread_id if the
|
|
4288
4395
|
# user set one (now it actually persists across runs — closing the "I
|
|
@@ -4303,6 +4410,7 @@ def main(
|
|
|
4303
4410
|
thread_id,
|
|
4304
4411
|
first_message=msg,
|
|
4305
4412
|
agent_checkpointer=had_user_checkpointer,
|
|
4413
|
+
agent=session_agent,
|
|
4306
4414
|
)
|
|
4307
4415
|
|
|
4308
4416
|
config_dict["_session_info"] = {
|
|
@@ -154,6 +154,7 @@ def touch_session(
|
|
|
154
154
|
first_message: Optional[str] = None,
|
|
155
155
|
*,
|
|
156
156
|
agent_checkpointer: bool = False,
|
|
157
|
+
agent: Optional[str] = None,
|
|
157
158
|
) -> None:
|
|
158
159
|
"""Bump a thread's ``updated`` timestamp (creating the entry if missing).
|
|
159
160
|
|
|
@@ -163,6 +164,10 @@ def touch_session(
|
|
|
163
164
|
``agent_checkpointer`` marks a session whose state lives in the agent's OWN
|
|
164
165
|
checkpointer, not the CLI's store (``"checkpointer": "agent"``), so the session list
|
|
165
166
|
and a resume can say the CLI holds no history for it (gh #128).
|
|
167
|
+
|
|
168
|
+
``agent`` is the resolved agent spec the turn ran (gh #215). It is recorded when the
|
|
169
|
+
entry is created, or filled into an older entry that has none; an entry that already
|
|
170
|
+
names an agent keeps it, so the session stays attributed to the agent that made it.
|
|
166
171
|
"""
|
|
167
172
|
sessions = load_index(workspace)
|
|
168
173
|
entry = sessions.get(thread_id)
|
|
@@ -171,22 +176,63 @@ def touch_session(
|
|
|
171
176
|
entry = {"created": now, "updated": now, "first_message": _snippet(first_message)}
|
|
172
177
|
if agent_checkpointer:
|
|
173
178
|
entry["checkpointer"] = "agent"
|
|
179
|
+
if agent:
|
|
180
|
+
entry["agent"] = agent
|
|
174
181
|
sessions[thread_id] = entry
|
|
175
182
|
else:
|
|
176
183
|
entry["updated"] = now
|
|
177
184
|
if not entry.get("first_message") and first_message:
|
|
178
185
|
entry["first_message"] = _snippet(first_message)
|
|
186
|
+
if agent and not entry.get("agent"):
|
|
187
|
+
entry["agent"] = agent
|
|
179
188
|
_save_index(workspace, sessions)
|
|
180
189
|
|
|
181
190
|
|
|
182
|
-
def most_recent_thread(workspace: Path) -> Optional[str]:
|
|
183
|
-
"""The most-recently-updated thread id for this workspace, or ``None`` if none.
|
|
191
|
+
def most_recent_thread(workspace: Path, agent: Optional[str] = None) -> Optional[str]:
|
|
192
|
+
"""The most-recently-updated thread id for this workspace, or ``None`` if none.
|
|
193
|
+
|
|
194
|
+
With ``agent``, only sessions recorded for that agent count, plus older entries that
|
|
195
|
+
record no agent (written before gh #215), so ``--continue`` never picks up a session
|
|
196
|
+
another agent made.
|
|
197
|
+
"""
|
|
184
198
|
sessions = load_index(workspace)
|
|
199
|
+
if agent is not None:
|
|
200
|
+
sessions = {t: e for t, e in sessions.items() if e.get("agent") in (None, "", agent)}
|
|
185
201
|
if not sessions:
|
|
186
202
|
return None
|
|
187
203
|
return max(sessions.items(), key=lambda kv: kv[1].get("updated", 0))[0]
|
|
188
204
|
|
|
189
205
|
|
|
206
|
+
def thread_is_paused(workspace: Path, thread_id: str) -> bool:
|
|
207
|
+
"""Whether the thread's latest checkpoint in the CLI's store ends on an ``interrupt()``.
|
|
208
|
+
|
|
209
|
+
Read from the store itself, not through a graph, so it works whichever agent is
|
|
210
|
+
loaded (gh #215): a graph without the interrupting node sees no pending task and
|
|
211
|
+
would otherwise let a new message stack onto the paused turn. Anything unreadable
|
|
212
|
+
(no store, no such thread, an agent-owned checkpointer) counts as not paused.
|
|
213
|
+
"""
|
|
214
|
+
path = sessions_dir() / f"{workspace_key(workspace)}.sqlite"
|
|
215
|
+
if not path.is_file():
|
|
216
|
+
return False
|
|
217
|
+
try:
|
|
218
|
+
import sqlite3
|
|
219
|
+
|
|
220
|
+
from langgraph.checkpoint.sqlite import SqliteSaver
|
|
221
|
+
|
|
222
|
+
conn = sqlite3.connect(f"file:{path}?mode=ro", uri=True)
|
|
223
|
+
try:
|
|
224
|
+
saver = SqliteSaver(conn)
|
|
225
|
+
saver.is_setup = True # read-only: the tables exist, never create them
|
|
226
|
+
tup = saver.get_tuple({"configurable": {"thread_id": thread_id}})
|
|
227
|
+
finally:
|
|
228
|
+
conn.close()
|
|
229
|
+
except Exception: # noqa: BLE001 - a store we can't read is "not paused"
|
|
230
|
+
return False
|
|
231
|
+
if tup is None:
|
|
232
|
+
return False
|
|
233
|
+
return any(w[1] == "__interrupt__" for w in (tup.pending_writes or ()))
|
|
234
|
+
|
|
235
|
+
|
|
190
236
|
def resolve_thread(workspace: Path, ref: str) -> Optional[str]:
|
|
191
237
|
"""Resolve a ``--resume`` reference to a full thread id.
|
|
192
238
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langstage-cli
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.60
|
|
4
4
|
Summary: The terminal stage for your LangGraph agent — Claude Code-style CLI for any CompiledGraph
|
|
5
5
|
Author-email: Kedar Dabhadkar <kdabhadk@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -142,8 +142,8 @@ langstage-cli --show-config
|
|
|
142
142
|
|
|
143
143
|
# Resume a previous conversation across separate invocations
|
|
144
144
|
langstage-cli "remember: my name is Kedar" # a fresh, PERSISTED session
|
|
145
|
-
langstage-cli -c "what's my name?" # continue
|
|
146
|
-
langstage-cli --list-sessions # list resumable sessions
|
|
145
|
+
langstage-cli -c "what's my name?" # continue this agent's most recent session
|
|
146
|
+
langstage-cli --list-sessions # list resumable sessions, with their agents
|
|
147
147
|
langstage-cli --resume <id> # resume a specific one
|
|
148
148
|
```
|
|
149
149
|
|
|
@@ -166,11 +166,17 @@ Every invocation persists its conversation to a durable, per-workspace store so
|
|
|
166
166
|
run can pick it up — the terminal-agent continuity of Claude Code / Codex / Aider,
|
|
167
167
|
without you baking a checkpointer into your own graph:
|
|
168
168
|
|
|
169
|
-
- `--continue` / `-c` — resume the **most recent** session
|
|
170
|
-
going. If there's no prior session, it just starts a fresh one.
|
|
169
|
+
- `--continue` / `-c` — resume the **most recent** session this agent made in this
|
|
170
|
+
workspace and keep going. If there's no prior session, it just starts a fresh one.
|
|
171
|
+
Another agent's sessions are skipped, so trying `--demo` and then your own graph in the
|
|
172
|
+
same directory doesn't hand your graph the demo's conversation.
|
|
171
173
|
- `--resume <id>` — resume a **specific** session (ids come from `--list-sessions`; a
|
|
172
174
|
bare `--resume` also lists them). A short prefix works if it's unambiguous; an
|
|
173
|
-
ambiguous one is an error that lists the sessions it matches.
|
|
175
|
+
ambiguous one is an error that lists the sessions it matches. Resuming another agent's
|
|
176
|
+
session works but says so; one paused at another agent's approval is refused (exit `1`),
|
|
177
|
+
since this agent can't answer it.
|
|
178
|
+
- `--list-sessions` shows which agent made each session (`-` for sessions saved before
|
|
179
|
+
0.6.59, which `-c` still picks up).
|
|
174
180
|
- A plain run with no flag starts a **new** session that is still persisted, so it can be
|
|
175
181
|
continued later.
|
|
176
182
|
- A session left paused at an approval (exit `2`) is resolved before a new message: the
|
|
@@ -286,7 +292,8 @@ Options:
|
|
|
286
292
|
--show-config Print the resolved configuration and exit
|
|
287
293
|
-q, --quiet Scriptable single-shot output: only the reply
|
|
288
294
|
--verify Preflight the agent (one real turn); exit 0/1
|
|
289
|
-
-c, --continue Resume
|
|
295
|
+
-c, --continue Resume this agent's most recent session for this
|
|
296
|
+
workspace
|
|
290
297
|
--resume [ID] Resume a specific session (bare: list them)
|
|
291
298
|
--list-sessions List resumable sessions for this workspace
|
|
292
299
|
--persist/--no-persist Persist this session so it can be continued (default: on)
|
|
@@ -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
|
|
@@ -56,6 +57,7 @@ tests/test_reasoning_render.py
|
|
|
56
57
|
tests/test_rename_shim.py
|
|
57
58
|
tests/test_render_markdown.py
|
|
58
59
|
tests/test_routine_1024.py
|
|
60
|
+
tests/test_session_agent_215.py
|
|
59
61
|
tests/test_session_lifecycle.py
|
|
60
62
|
tests/test_sessions.py
|
|
61
63
|
tests/test_show_config.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
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""Sessions remember which agent made them (gh #215).
|
|
2
|
+
|
|
3
|
+
The session index stored no agent, so ``-a b.py -c`` fed agent A's transcript (tool
|
|
4
|
+
calls and all) to agent B without a word, ``--list-sessions`` couldn't tell sessions
|
|
5
|
+
apart, and continuing a session paused at A's approval with B dropped the approval and
|
|
6
|
+
stacked a second human message, exit 0. Now each index entry records its agent:
|
|
7
|
+
``--continue`` takes this agent's most recent session, ``--resume`` of another agent's
|
|
8
|
+
session says so, and one paused at another agent's approval is refused (exit 1).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import textwrap
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
from click.testing import CliRunner
|
|
16
|
+
|
|
17
|
+
pytest.importorskip("ag_ui_langgraph")
|
|
18
|
+
pytest.importorskip("langgraph.checkpoint.sqlite.aio")
|
|
19
|
+
|
|
20
|
+
from langstage_cli import cli, sessions # noqa: E402
|
|
21
|
+
from langstage_cli.cli import main # noqa: E402
|
|
22
|
+
|
|
23
|
+
# Reports the message types it was handed: another agent's tool transcript shows up as
|
|
24
|
+
# 'tool' entries, a dropped approval as two 'human' entries in a row.
|
|
25
|
+
_OTHER = textwrap.dedent(
|
|
26
|
+
"""
|
|
27
|
+
from langgraph.graph import StateGraph, START, END
|
|
28
|
+
from langgraph.graph.message import MessagesState
|
|
29
|
+
from langchain_core.messages import AIMessage
|
|
30
|
+
|
|
31
|
+
def respond(state):
|
|
32
|
+
return {"messages": [AIMessage(content=f"I see {[m.type for m in state['messages']]}")]}
|
|
33
|
+
|
|
34
|
+
g = StateGraph(MessagesState)
|
|
35
|
+
g.add_node("respond", respond)
|
|
36
|
+
g.add_edge(START, "respond")
|
|
37
|
+
g.add_edge("respond", END)
|
|
38
|
+
graph = g.compile()
|
|
39
|
+
"""
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Agent A: calls a tool (so its transcript has a 'tool' message) and pauses on "ask me".
|
|
43
|
+
# A file agent, not the packaged demo: a module-level graph is shared across this test
|
|
44
|
+
# process, and an earlier test's checkpointer on it would read as the agent's own.
|
|
45
|
+
_FIRST = textwrap.dedent(
|
|
46
|
+
"""
|
|
47
|
+
from langgraph.graph import StateGraph, START, END
|
|
48
|
+
from langgraph.graph.message import MessagesState
|
|
49
|
+
from langgraph.types import interrupt
|
|
50
|
+
from langchain_core.messages import AIMessage, ToolMessage
|
|
51
|
+
|
|
52
|
+
def respond(state):
|
|
53
|
+
last = state["messages"][-1].content
|
|
54
|
+
if "ask me" in last:
|
|
55
|
+
ok = interrupt("Proceed?")
|
|
56
|
+
return {"messages": [AIMessage(content=f"answered: {ok!r}")]}
|
|
57
|
+
return {"messages": [
|
|
58
|
+
AIMessage(content="", tool_calls=[{"name": "kb", "args": {}, "id": "t1"}]),
|
|
59
|
+
ToolMessage(content="42", tool_call_id="t1"),
|
|
60
|
+
AIMessage(content="the answer is 42"),
|
|
61
|
+
]}
|
|
62
|
+
|
|
63
|
+
g = StateGraph(MessagesState)
|
|
64
|
+
g.add_node("respond", respond)
|
|
65
|
+
g.add_edge(START, "respond")
|
|
66
|
+
g.add_edge("respond", END)
|
|
67
|
+
graph = g.compile()
|
|
68
|
+
"""
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
_DEMO = "first_agent.py:graph"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture
|
|
75
|
+
def ws(tmp_path, monkeypatch):
|
|
76
|
+
d = tmp_path / "ws"
|
|
77
|
+
d.mkdir()
|
|
78
|
+
(d / "other_agent.py").write_text(_OTHER, encoding="utf-8")
|
|
79
|
+
(d / "first_agent.py").write_text(_FIRST, encoding="utf-8")
|
|
80
|
+
monkeypatch.setenv("LANGSTAGE_CONFIG_HOME", str(tmp_path / "empty_home"))
|
|
81
|
+
monkeypatch.chdir(d)
|
|
82
|
+
return d
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _run(*args):
|
|
86
|
+
return CliRunner().invoke(main, list(args))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _index(ws):
|
|
90
|
+
return sessions.load_index(ws.resolve())
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _newest(ws):
|
|
94
|
+
idx = _index(ws)
|
|
95
|
+
return max(idx, key=lambda t: idx[t]["updated"])
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_index_records_the_agent_and_the_list_shows_it(ws):
|
|
99
|
+
assert _run("-a", _DEMO, "use a tool").exit_code == 0
|
|
100
|
+
assert _run("-a", "other_agent.py:graph", "hello").exit_code == 0
|
|
101
|
+
agents = sorted(e.get("agent") for e in _index(ws).values())
|
|
102
|
+
assert agents == [f"{(ws / n).resolve()}:graph" for n in ("first_agent.py", "other_agent.py")]
|
|
103
|
+
|
|
104
|
+
out = _run("--list-sessions").output
|
|
105
|
+
assert "other_agent.py:graph" in out # shown relative to the workspace
|
|
106
|
+
assert _DEMO in out
|
|
107
|
+
assert str(ws) + "/other_agent.py" not in out.replace("\\", "/")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_bare_file_spec_and_its_graph_suffix_are_one_agent(ws):
|
|
111
|
+
assert _run("-a", "other_agent.py:graph", "one").exit_code == 0
|
|
112
|
+
r = _run("-a", "other_agent.py", "-c", "two")
|
|
113
|
+
assert r.exit_code == 0, r.output
|
|
114
|
+
assert "I see ['human', 'ai', 'human']" in r.output
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_continue_skips_another_agents_session(ws):
|
|
118
|
+
assert _run("-a", _DEMO, "use a tool").exit_code == 0
|
|
119
|
+
r = _run("-a", "other_agent.py:graph", "-c", "hello")
|
|
120
|
+
assert r.exit_code == 0, r.output
|
|
121
|
+
assert "I see ['human']" in r.output # a fresh session, not the demo's transcript
|
|
122
|
+
assert "No prior session for this agent" in r.output
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_continue_picks_this_agents_session_past_a_newer_other_one(ws):
|
|
126
|
+
assert _run("-a", "other_agent.py:graph", "mine").exit_code == 0
|
|
127
|
+
assert _run("-a", _DEMO, "use a tool").exit_code == 0
|
|
128
|
+
r = _run("-a", "other_agent.py:graph", "-c", "again")
|
|
129
|
+
assert r.exit_code == 0, r.output
|
|
130
|
+
assert "I see ['human', 'ai', 'human']" in r.output
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_continue_still_takes_a_session_recorded_before_agents_were(ws):
|
|
134
|
+
assert _run("-a", "other_agent.py:graph", "old").exit_code == 0
|
|
135
|
+
idx = _index(ws)
|
|
136
|
+
for entry in idx.values():
|
|
137
|
+
entry.pop("agent")
|
|
138
|
+
sessions._save_index(ws.resolve(), idx)
|
|
139
|
+
r = _run("-a", "other_agent.py:graph", "-c", "new")
|
|
140
|
+
assert r.exit_code == 0, r.output
|
|
141
|
+
assert "I see ['human', 'ai', 'human']" in r.output
|
|
142
|
+
# The resume fills the agent into the old entry.
|
|
143
|
+
assert all(e.get("agent") for e in _index(ws).values())
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_resume_of_another_agents_session_says_so(ws):
|
|
147
|
+
assert _run("-a", _DEMO, "use a tool").exit_code == 0
|
|
148
|
+
tid = _newest(ws)
|
|
149
|
+
r = _run("-a", "other_agent.py:graph", "--resume", tid, "hello")
|
|
150
|
+
assert r.exit_code == 0, r.output
|
|
151
|
+
assert f"was created by {_DEMO}; resuming it with other_agent.py:graph" in r.output
|
|
152
|
+
assert "'tool'" in r.output # the user asked for that session, so it is used
|
|
153
|
+
# It stays attributed to the agent that made it.
|
|
154
|
+
assert _index(ws)[tid]["agent"] == f"{(ws / 'first_agent.py').resolve()}:graph"
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_resume_of_another_agents_paused_session_is_refused(ws):
|
|
158
|
+
r = _run("-a", _DEMO, "ask me")
|
|
159
|
+
assert r.exit_code == 2, r.output
|
|
160
|
+
tid = _newest(ws)
|
|
161
|
+
assert sessions.thread_is_paused(ws.resolve(), tid)
|
|
162
|
+
|
|
163
|
+
r = _run("-a", "other_agent.py:graph", "--resume", tid, "hello again")
|
|
164
|
+
assert r.exit_code == 1, r.output
|
|
165
|
+
assert "is paused at an approval from" in r.output
|
|
166
|
+
assert f"-a {_DEMO} --resume" in r.output
|
|
167
|
+
assert "I see" not in r.output # nothing reached the other agent
|
|
168
|
+
|
|
169
|
+
# Its own agent still finds the approval and resolves it.
|
|
170
|
+
r = _run("-a", _DEMO, "--resume", tid, "--no-interactive", "and now")
|
|
171
|
+
assert r.exit_code == 0, r.output
|
|
172
|
+
assert "paused at an approval from its previous turn" in r.output
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_a_finished_session_is_not_paused(ws):
|
|
176
|
+
assert _run("-a", "other_agent.py:graph", "hello").exit_code == 0
|
|
177
|
+
assert not sessions.thread_is_paused(ws.resolve(), _newest(ws))
|
|
178
|
+
assert not sessions.thread_is_paused(ws.resolve(), "no-such-thread")
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_session_agent_id_forms(tmp_path):
|
|
182
|
+
f = tmp_path / "a.py"
|
|
183
|
+
assert cli._session_agent_id("a.py", tmp_path, "graph") == f"{f.resolve()}:graph"
|
|
184
|
+
assert cli._session_agent_id(f"{f}:agent", tmp_path, "agent") == f"{f.resolve()}:agent"
|
|
185
|
+
assert cli._session_agent_id("pkg.mod", tmp_path, "graph") == "pkg.mod:graph"
|
|
186
|
+
assert cli._session_agent_id("pkg.mod:g", tmp_path, "g") == "pkg.mod:g"
|
|
187
|
+
assert cli._shown_agent(None, tmp_path) == "-"
|
|
188
|
+
assert cli._shown_agent(f"{f.resolve()}:graph", tmp_path.resolve()) == "a.py:graph"
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def test_index_stays_valid_json(ws):
|
|
192
|
+
assert _run("-a", "other_agent.py:graph", "hello").exit_code == 0
|
|
193
|
+
path = sessions._index_path(ws.resolve())
|
|
194
|
+
assert json.loads(path.read_text(encoding="utf-8"))["sessions"]
|
|
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
|