langstage-cli 0.6.49__tar.gz → 0.6.51__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.
Files changed (79) hide show
  1. {langstage_cli-0.6.49/langstage_cli.egg-info → langstage_cli-0.6.51}/PKG-INFO +4 -4
  2. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/README.md +1 -1
  3. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli/cli.py +54 -68
  4. {langstage_cli-0.6.49 → langstage_cli-0.6.51/langstage_cli.egg-info}/PKG-INFO +4 -4
  5. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli.egg-info/SOURCES.txt +1 -0
  6. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli.egg-info/requires.txt +2 -2
  7. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/pyproject.toml +3 -3
  8. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_custom_decision_195.py +30 -16
  9. langstage_cli-0.6.51/tests/test_menu_allowed_197.py +184 -0
  10. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/LICENSE +0 -0
  11. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/deepagent_code/__init__.py +0 -0
  12. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli/__init__.py +0 -0
  13. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli/agui_stream.py +0 -0
  14. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli/config.py +0 -0
  15. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli/exit_codes.py +0 -0
  16. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli/sessions.py +0 -0
  17. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli.egg-info/dependency_links.txt +0 -0
  18. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli.egg-info/entry_points.txt +0 -0
  19. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/langstage_cli.egg-info/top_level.txt +0 -0
  20. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/setup.cfg +0 -0
  21. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_advertised_wave4.py +0 -0
  22. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_agui_stream.py +0 -0
  23. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_approval_menu_abort.py +0 -0
  24. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_async_mode.py +0 -0
  25. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_checkpointer.py +0 -0
  26. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_cli.py +0 -0
  27. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_cli_help.py +0 -0
  28. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_codeconfig.py +0 -0
  29. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_config.py +0 -0
  30. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_config_command.py +0 -0
  31. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_configurable.py +0 -0
  32. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_ctrl_c_sync_tool.py +0 -0
  33. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_deferred_pass.py +0 -0
  34. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_dumb_term.py +0 -0
  35. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_exit_codes.py +0 -0
  36. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_generic_interrupt.py +0 -0
  37. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_help_render.py +0 -0
  38. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_hidden_option_suggestions.py +0 -0
  39. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_history_persist.py +0 -0
  40. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_hitl_approval_preview.py +0 -0
  41. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_hitl_resume_warning.py +0 -0
  42. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_init.py +0 -0
  43. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_interrupt_non_tty.py +0 -0
  44. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_legacy_config_home.py +0 -0
  45. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_load_error.py +0 -0
  46. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_message_boundaries.py +0 -0
  47. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_no_color.py +0 -0
  48. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_no_interactive_approve.py +0 -0
  49. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_no_persist_resume.py +0 -0
  50. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_paused_session_message.py +0 -0
  51. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_persist_env.py +0 -0
  52. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_quiet_output.py +0 -0
  53. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_reasoning_render.py +0 -0
  54. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_rename_shim.py +0 -0
  55. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_render_markdown.py +0 -0
  56. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_routine_1024.py +0 -0
  57. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_session_lifecycle.py +0 -0
  58. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_sessions.py +0 -0
  59. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_show_config.py +0 -0
  60. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_show_config_malformed.py +0 -0
  61. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_spec_loading_core.py +0 -0
  62. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_spec_resolution.py +0 -0
  63. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_spinner_reply_survives.py +0 -0
  64. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_stdin_interactive.py +0 -0
  65. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_stdin_single_shot.py +0 -0
  66. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_stream_mode.py +0 -0
  67. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_streaming_marker.py +0 -0
  68. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_terminal_width.py +0 -0
  69. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_toml_relative_paths.py +0 -0
  70. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_tool_card_args.py +0 -0
  71. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_tool_output_escape.py +0 -0
  72. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_turn_error_verbose.py +0 -0
  73. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_turn_exit_and_render.py +0 -0
  74. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_unicode_console.py +0 -0
  75. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_usage_hint_186.py +0 -0
  76. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_verbose_command.py +0 -0
  77. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_verify_flag.py +0 -0
  78. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/tests/test_workspace.py +0 -0
  79. {langstage_cli-0.6.49 → langstage_cli-0.6.51}/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.49
3
+ Version: 0.6.51
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
@@ -19,7 +19,7 @@ Requires-Python: >=3.11
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: langgraph>=0.2.0
22
- Requires-Dist: langstage-core[agui]>=1.0.47
22
+ Requires-Dist: langstage-core[agui]>=1.0.58
23
23
  Requires-Dist: click>=8.0.0
24
24
  Requires-Dist: python-dotenv
25
25
  Requires-Dist: langgraph-checkpoint-sqlite>=2.0.0
@@ -33,7 +33,7 @@ Requires-Dist: deepagents>=0.3; extra == "dev"
33
33
  Requires-Dist: ag-ui-langgraph>=0.0.41; extra == "dev"
34
34
  Requires-Dist: fastapi; extra == "dev"
35
35
  Provides-Extra: agui
36
- Requires-Dist: langstage-core[agui]>=1.0.7; extra == "agui"
36
+ Requires-Dist: langstage-core[agui]>=1.0.58; extra == "agui"
37
37
  Dynamic: license-file
38
38
 
39
39
  # langstage-cli
@@ -342,7 +342,7 @@ approval menu you answer by typing a number.
342
342
  |---|---|
343
343
  | `0` | success: the turn completed, `--verify` passed, `init` wrote its files |
344
344
  | `1` | failure: no agent configured, the agent failed to load, the turn errored or produced nothing, `--verify` failed, `--resume` found no session, `init` refused to overwrite |
345
- | `2` | paused on a human-in-the-loop interrupt: an approval is needed but stdin is not a terminal, or you left the approval prompt with **Exit** or Ctrl-C. `--no-interactive` auto-approves instead |
345
+ | `2` | paused on a human-in-the-loop interrupt: an approval is needed but stdin is not a terminal, or you left the approval prompt with **Exit** or Ctrl-C. `--no-interactive` auto-approves instead, unless the pending action doesn't allow approve, which also exits `2` |
346
346
  | `64` | usage error: an unknown option or bad value, `--demo` with `-a`, `--continue` with `--resume`, `MESSAGE` with `-f`, an empty `MESSAGE` |
347
347
 
348
348
  ## Creating Your Own Agent
@@ -304,7 +304,7 @@ approval menu you answer by typing a number.
304
304
  |---|---|
305
305
  | `0` | success: the turn completed, `--verify` passed, `init` wrote its files |
306
306
  | `1` | failure: no agent configured, the agent failed to load, the turn errored or produced nothing, `--verify` failed, `--resume` found no session, `init` refused to overwrite |
307
- | `2` | paused on a human-in-the-loop interrupt: an approval is needed but stdin is not a terminal, or you left the approval prompt with **Exit** or Ctrl-C. `--no-interactive` auto-approves instead |
307
+ | `2` | paused on a human-in-the-loop interrupt: an approval is needed but stdin is not a terminal, or you left the approval prompt with **Exit** or Ctrl-C. `--no-interactive` auto-approves instead, unless the pending action doesn't allow approve, which also exits `2` |
308
308
  | `64` | usage error: an unknown option or bad value, `--demo` with `-a`, `--continue` with `--resume`, `MESSAGE` with `-f`, an empty `MESSAGE` |
309
309
 
310
310
  ## Creating Your Own Agent
@@ -1833,23 +1833,24 @@ def handle_interrupt_input(
1833
1833
  except json.JSONDecodeError:
1834
1834
  return raw
1835
1835
 
1836
- options = [
1837
- "Approve all actions",
1838
- "Reject all actions",
1839
- "Provide custom decision (JSON)",
1840
- "Exit",
1841
- ]
1836
+ # "Approve all" / "Reject all" are offered only when every pending action allows
1837
+ # that verb. They used to be offered always, so on HumanInTheLoopMiddleware(
1838
+ # allowed_decisions=["approve", "edit"]) "Reject all" sent a decision the
1839
+ # middleware refuses and the turn errored (gh #197).
1840
+ entries = []
1841
+ if _all_actions_allow("approve", num_actions, interrupt):
1842
+ entries.append(("Approve all actions", "approve"))
1843
+ if _all_actions_allow("reject", num_actions, interrupt):
1844
+ entries.append(("Reject all actions", "reject"))
1845
+ entries += [("Provide custom decision (JSON)", "custom"), ("Exit", "exit")]
1846
+ options = [label for label, _ in entries]
1842
1847
 
1843
1848
  while True:
1844
- choice = select_option(options, "How would you like to proceed?")
1845
-
1846
- if choice == 0:
1847
- # Approve decision for each pending action
1848
- return {"decisions": [{"type": "approve"} for _ in range(num_actions)]}
1849
- elif choice == 1:
1850
- # Reject decision for each pending action
1851
- return {"decisions": [{"type": "reject"} for _ in range(num_actions)]}
1852
- elif choice == 2:
1849
+ action = entries[select_option(options, "How would you like to proceed?")][1]
1850
+
1851
+ if action in ("approve", "reject"):
1852
+ return {"decisions": [{"type": action} for _ in range(num_actions)]}
1853
+ elif action == "custom":
1853
1854
  decisions = _prompt_custom_decision(num_actions, interrupt)
1854
1855
  if decisions is _BACK_TO_MENU:
1855
1856
  continue # nothing sent; show the menu again
@@ -1932,6 +1933,16 @@ def _allowed_verbs(interrupt: Optional[Dict[str, Any]], index: int) -> List[str]
1932
1933
  return list(_FALLBACK_VERBS)
1933
1934
 
1934
1935
 
1936
+ def _all_actions_allow(verb: str, num_actions: int, interrupt: Optional[Dict[str, Any]]) -> bool:
1937
+ """Whether every pending action allows ``verb`` (gh #197)."""
1938
+ from langstage_core import normalize_decision
1939
+
1940
+ return all(
1941
+ normalize_decision(verb, _allowed_verbs(interrupt, i)) == verb
1942
+ for i in range(max(num_actions, 1))
1943
+ )
1944
+
1945
+
1935
1946
  def _decision_shapes(allowed: List[str], interrupt: Optional[Dict[str, Any]] = None) -> str:
1936
1947
  """One line showing the JSON shape of each allowed decision.
1937
1948
 
@@ -1986,36 +1997,30 @@ def _check_custom_decision(
1986
1997
  else:
1987
1998
  items = [value] * num_actions
1988
1999
 
1989
- # The edited_action / message fields are LangChain HumanInTheLoopMiddleware's
1990
- # shape (its interrupts carry review_configs); other interrupts read their own.
1991
- middleware = _is_middleware_interrupt(interrupt)
1992
2000
  for i, decision in enumerate(items):
1993
- allowed = _allowed_verbs(interrupt, i)
1994
2001
  if not isinstance(decision, dict) or not isinstance(decision.get("type"), str):
1995
2002
  return [], (
1996
2003
  'A decision is a JSON object with a "type", e.g. {"type": "approve"}; '
1997
- f"allowed: {', '.join(allowed)}."
2004
+ f"allowed: {', '.join(_allowed_verbs(interrupt, i))}."
1998
2005
  )
1999
- verb = normalize_decision(decision["type"], allowed)
2000
- if verb is None:
2006
+
2007
+ # LangChain HumanInTheLoopMiddleware interrupts (they carry review_configs) are
2008
+ # checked by core, with the same rules its resume path enforces (core gh #227).
2009
+ # Other interrupts read their own payload, so only the verb is checked here.
2010
+ if _is_middleware_interrupt(interrupt):
2011
+ from langstage_core import decision_problems
2012
+
2013
+ problems = decision_problems({"decisions": list(items)}, interrupt)
2014
+ if problems:
2015
+ return [], "; ".join(problems) + "."
2016
+ return list(items), None
2017
+ for i, decision in enumerate(items):
2018
+ allowed = _allowed_verbs(interrupt, i)
2019
+ if normalize_decision(decision["type"], allowed) is None:
2001
2020
  return [], (
2002
2021
  f"Decision type '{decision['type']}' is not allowed here; "
2003
2022
  f"allowed: {', '.join(allowed)}."
2004
2023
  )
2005
- if not middleware:
2006
- continue
2007
- if verb == "edit":
2008
- edited = decision.get("edited_action")
2009
- if not (
2010
- isinstance(edited, dict)
2011
- and isinstance(edited.get("name"), str)
2012
- and isinstance(edited.get("args"), dict)
2013
- ):
2014
- return [], 'An edit needs "edited_action": {"name": "<tool>", "args": {...}}.'
2015
- elif verb == "respond" and not isinstance(decision.get("message"), str):
2016
- return [], 'A respond decision needs a "message" string.'
2017
- elif verb == "reject" and not isinstance(decision.get("message", ""), str):
2018
- return [], 'The "message" of a reject decision must be a string.'
2019
2024
  return list(items), None
2020
2025
 
2021
2026
 
@@ -2558,36 +2563,6 @@ async def _pending_interrupt(agent: Any, thread_id: str) -> bool:
2558
2563
  return any(getattr(task, "interrupts", None) for task in getattr(state, "tasks", ()) or ())
2559
2564
 
2560
2565
 
2561
- async def _discard_failed_resume(agent: Any, thread_id: str) -> None:
2562
- """Drop the answer a failed resume left on the thread, so the next one is used.
2563
-
2564
- When resuming an interrupt raises (a decision the agent refused), LangGraph keeps
2565
- that resume value on the checkpoint and replays it on every later resume, so the
2566
- approval could never be answered again, even with ``-c`` (gh #195). The failed
2567
- task still shows its interrupt and carries the error. A checkpoint with no new
2568
- values drops the stale answer: the interrupted step runs again and takes the new
2569
- one. If that isn't possible the stale answer stays, and the error says so again.
2570
- """
2571
- graph = getattr(agent, "graph", None)
2572
- if not thread_id or graph is None or not hasattr(graph, "aupdate_state"):
2573
- return
2574
- config = {"configurable": {"thread_id": thread_id}}
2575
- try:
2576
- state = await graph.aget_state(config)
2577
- except Exception: # noqa: BLE001 - no checkpointer / no state: nothing to clear
2578
- return
2579
- tasks = getattr(state, "tasks", ()) or ()
2580
- if not any(getattr(t, "interrupts", None) and getattr(t, "error", None) for t in tasks):
2581
- return
2582
- try:
2583
- await graph.aupdate_state(config, None)
2584
- except Exception as e: # noqa: BLE001 - leave the thread as it is
2585
- _status(
2586
- f"{YELLOW}⏺ Couldn't clear the refused answer on this session ({e}); "
2587
- f"start a new session if the approval keeps failing.{RESET}"
2588
- )
2589
-
2590
-
2591
2566
  async def _stream_turn(
2592
2567
  agent: Any, message: str, thread_id: str, interactive: bool, verbose: bool
2593
2568
  ) -> tuple[bool, bool, bool]:
@@ -2615,8 +2590,6 @@ async def _stream_turn(
2615
2590
  spinner = None if _QUIET else Spinner("Thinking")
2616
2591
  if spinner:
2617
2592
  spinner.start()
2618
- if resume is not None:
2619
- await _discard_failed_resume(agent, thread_id)
2620
2593
  try:
2621
2594
  with _debug_tracebacks(verbose):
2622
2595
  async for chunk in agui_stream_updates(agent, message, thread_id, resume=resume):
@@ -2658,6 +2631,19 @@ async def _stream_turn(
2658
2631
  f"(--no-interactive){RESET}"
2659
2632
  )
2660
2633
  resume = ""
2634
+ elif has_interrupt and not _all_actions_allow(
2635
+ "approve", num_pending_actions, interrupt_data
2636
+ ):
2637
+ # --no-interactive can only approve. An action that doesn't allow approve
2638
+ # would refuse the decision and error the turn, so stop paused instead and
2639
+ # say why (gh #197).
2640
+ print(
2641
+ "Error: approval required, but the pending action does not allow "
2642
+ f"approve (allowed: {', '.join(_allowed_verbs(interrupt_data, 0))}).\n"
2643
+ "Answer it in an interactive session.",
2644
+ file=sys.stderr,
2645
+ )
2646
+ sys.exit(EXIT_PAUSED)
2661
2647
  elif has_interrupt:
2662
2648
  # --no-interactive: auto-approve and resume so the agent runs to
2663
2649
  # completion (same behavior as the default path, gh #32).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langstage-cli
3
- Version: 0.6.49
3
+ Version: 0.6.51
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
@@ -19,7 +19,7 @@ Requires-Python: >=3.11
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: langgraph>=0.2.0
22
- Requires-Dist: langstage-core[agui]>=1.0.47
22
+ Requires-Dist: langstage-core[agui]>=1.0.58
23
23
  Requires-Dist: click>=8.0.0
24
24
  Requires-Dist: python-dotenv
25
25
  Requires-Dist: langgraph-checkpoint-sqlite>=2.0.0
@@ -33,7 +33,7 @@ Requires-Dist: deepagents>=0.3; extra == "dev"
33
33
  Requires-Dist: ag-ui-langgraph>=0.0.41; extra == "dev"
34
34
  Requires-Dist: fastapi; extra == "dev"
35
35
  Provides-Extra: agui
36
- Requires-Dist: langstage-core[agui]>=1.0.7; extra == "agui"
36
+ Requires-Dist: langstage-core[agui]>=1.0.58; extra == "agui"
37
37
  Dynamic: license-file
38
38
 
39
39
  # langstage-cli
@@ -342,7 +342,7 @@ approval menu you answer by typing a number.
342
342
  |---|---|
343
343
  | `0` | success: the turn completed, `--verify` passed, `init` wrote its files |
344
344
  | `1` | failure: no agent configured, the agent failed to load, the turn errored or produced nothing, `--verify` failed, `--resume` found no session, `init` refused to overwrite |
345
- | `2` | paused on a human-in-the-loop interrupt: an approval is needed but stdin is not a terminal, or you left the approval prompt with **Exit** or Ctrl-C. `--no-interactive` auto-approves instead |
345
+ | `2` | paused on a human-in-the-loop interrupt: an approval is needed but stdin is not a terminal, or you left the approval prompt with **Exit** or Ctrl-C. `--no-interactive` auto-approves instead, unless the pending action doesn't allow approve, which also exits `2` |
346
346
  | `64` | usage error: an unknown option or bad value, `--demo` with `-a`, `--continue` with `--resume`, `MESSAGE` with `-f`, an empty `MESSAGE` |
347
347
 
348
348
  ## Creating Your Own Agent
@@ -40,6 +40,7 @@ tests/test_init.py
40
40
  tests/test_interrupt_non_tty.py
41
41
  tests/test_legacy_config_home.py
42
42
  tests/test_load_error.py
43
+ tests/test_menu_allowed_197.py
43
44
  tests/test_message_boundaries.py
44
45
  tests/test_no_color.py
45
46
  tests/test_no_interactive_approve.py
@@ -1,11 +1,11 @@
1
1
  langgraph>=0.2.0
2
- langstage-core[agui]>=1.0.47
2
+ langstage-core[agui]>=1.0.58
3
3
  click>=8.0.0
4
4
  python-dotenv
5
5
  langgraph-checkpoint-sqlite>=2.0.0
6
6
 
7
7
  [agui]
8
- langstage-core[agui]>=1.0.7
8
+ langstage-core[agui]>=1.0.58
9
9
 
10
10
  [dev]
11
11
  pytest>=7.0.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "langstage-cli"
7
- version = "0.6.49"
7
+ version = "0.6.51"
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"
@@ -36,7 +36,7 @@ dependencies = [
36
36
  # reporting, the non-deprecated HITL resume wire, message_id frames, and
37
37
  # langstage_core.console (gh #154, #153, #149, #145, #141, #140, #137, #136, #132,
38
38
  # #126, #119).
39
- "langstage-core[agui]>=1.0.47",
39
+ "langstage-core[agui]>=1.0.58",
40
40
  "click>=8.0.0",
41
41
  "python-dotenv",
42
42
  # Durable, cross-invocation session persistence (--continue / --resume, gh #102).
@@ -65,7 +65,7 @@ dev = [
65
65
  ]
66
66
  # Redundant since AG-UI moved into base deps (core 1.0); kept as a no-op alias so
67
67
  # existing `pip install langstage-cli[agui]` scripts/READMEs still resolve.
68
- agui = ["langstage-core[agui]>=1.0.7"]
68
+ agui = ["langstage-core[agui]>=1.0.58"]
69
69
 
70
70
  [project.scripts]
71
71
  langstage-cli = "langstage_cli.cli:main"
@@ -13,6 +13,7 @@ and a thread already holding a refused answer drops it before the next resume.
13
13
  """
14
14
 
15
15
  import io
16
+ import logging
16
17
  import textwrap
17
18
  from contextlib import redirect_stdout
18
19
 
@@ -101,7 +102,7 @@ def tty(monkeypatch):
101
102
  [
102
103
  (
103
104
  {"type": "aprove"},
104
- "Decision type 'aprove' is not allowed here; allowed: approve, reject.",
105
+ "decision 1 (send_email): type 'aprove' is not allowed; allowed: approve, reject",
105
106
  ),
106
107
  (
107
108
  {"type": "edit", "edited_action": {"name": "send_email", "args": {}}},
@@ -110,7 +111,7 @@ def tty(monkeypatch):
110
111
  (None, 'A decision is a JSON object with a "type"'),
111
112
  ({"decisions": [{"kind": "approve"}]}, 'A decision is a JSON object with a "type"'),
112
113
  ([{"type": "approve"}] * 3, "Got 3 decisions for 2 pending action(s)"),
113
- ({"type": "reject", "message": 5}, "must be a string"),
114
+ ({"type": "reject", "message": 5}, 'a reject "message" must be text'),
114
115
  ],
115
116
  )
116
117
  def test_bad_decisions_are_refused(value, problem):
@@ -120,17 +121,20 @@ def test_bad_decisions_are_refused(value, problem):
120
121
  assert problem in got
121
122
 
122
123
 
124
+ _FRAME2 = {**_FRAME, "action_requests": _FRAME["action_requests"] * 2}
125
+
126
+
123
127
  def test_one_decision_applies_to_every_action():
124
- decisions, problem = cli._check_custom_decision({"type": "reject", "message": "no"}, 2, _FRAME)
128
+ decisions, problem = cli._check_custom_decision({"type": "reject", "message": "no"}, 2, _FRAME2)
125
129
  assert problem is None
126
130
  assert decisions == [{"type": "reject", "message": "no"}] * 2
127
131
 
128
132
 
129
133
  def test_a_pasted_envelope_is_unwrapped():
130
134
  one = {"decisions": [{"type": "approve"}]}
131
- assert cli._check_custom_decision(one, 2, _FRAME) == ([{"type": "approve"}] * 2, None)
135
+ assert cli._check_custom_decision(one, 2, _FRAME2) == ([{"type": "approve"}] * 2, None)
132
136
  each = {"decisions": [{"type": "approve"}, {"type": "reject"}]}
133
- assert cli._check_custom_decision(each, 2, _FRAME) == (each["decisions"], None)
137
+ assert cli._check_custom_decision(each, 2, _FRAME2) == (each["decisions"], None)
134
138
 
135
139
 
136
140
  def test_legacy_alias_verbs_pass():
@@ -144,7 +148,10 @@ def test_langchain_shapes_are_checked_only_for_its_interrupts():
144
148
  "review_configs": [{"action_name": "send_email", "allowed_decisions": ["edit", "respond"]}],
145
149
  }
146
150
  assert "edited_action" in cli._check_custom_decision({"type": "edit"}, 1, frame)[1]
147
- assert '"message" string' in cli._check_custom_decision({"type": "respond"}, 1, frame)[1]
151
+ assert (
152
+ 'respond needs a text "message"'
153
+ in cli._check_custom_decision({"type": "respond"}, 1, frame)[1]
154
+ )
148
155
  edit = {"type": "edit", "edited_action": {"name": "send_email", "args": {"to": "b"}}}
149
156
  assert cli._check_custom_decision(edit, 1, frame) == ([edit], None)
150
157
  # A plain interrupt() payload (no review_configs) reads its own edit shape.
@@ -178,7 +185,7 @@ def test_menu_reprompts_on_a_refused_decision_and_shows_the_shapes(tty, monkeypa
178
185
  resume = cli.handle_interrupt_input(1, interrupt=_FRAME)
179
186
  out = buf.getvalue()
180
187
  assert resume == {"decisions": [{"type": "approve"}]}
181
- assert "'aprove' is not allowed here" in out and "Nothing was sent" in out
188
+ assert "type 'aprove' is not allowed" in out and "Nothing was sent" in out
182
189
  assert '{"type": "approve"} | {"type": "reject", "message": "why"}' in out
183
190
  assert '"edit"' not in out # not offered for this tool
184
191
  assert len(shown) == 1 # re-prompted in place
@@ -206,7 +213,7 @@ async def test_a_typo_is_refused_then_the_corrected_decision_runs_the_tool(tty,
206
213
  assert "done: sent to a@example.org" in out, out
207
214
 
208
215
 
209
- async def test_a_thread_holding_a_refused_answer_takes_the_next_one(monkeypatch):
216
+ async def test_a_thread_holding_a_refused_answer_takes_the_next_one(monkeypatch, caplog, capsys):
210
217
  # A thread wedged by an older CLI: the refused answer is already on the checkpoint.
211
218
  pytest.importorskip("ag_ui_langgraph")
212
219
  from langgraph.checkpoint.memory import MemorySaver
@@ -226,7 +233,7 @@ async def test_a_thread_holding_a_refused_answer_takes_the_next_one(monkeypatch)
226
233
 
227
234
  agent = build_session_agent(graph)
228
235
  buf = io.StringIO()
229
- with redirect_stdout(buf):
236
+ with caplog.at_level(logging.WARNING), redirect_stdout(buf):
230
237
  _elapsed, had_error = await cli.run_single_turn_agui(
231
238
  agent, "and now?", "t-wedged", interactive=False
232
239
  )
@@ -234,9 +241,14 @@ async def test_a_thread_holding_a_refused_answer_takes_the_next_one(monkeypatch)
234
241
  assert had_error is False, out
235
242
  assert "aprove" not in out, out
236
243
  assert "done: sent to a@example.org" in out, out
244
+ # Recovered by core (gh #227), so ag-ui never falls back to the deprecated wire.
245
+ logs = caplog.text + capsys.readouterr().err
246
+ assert "forwardedProps.command.resume is deprecated" not in out + logs, out + logs
237
247
 
238
248
 
239
- def test_continue_recovers_a_persisted_session_wedged_by_a_refused_answer(tmp_path, monkeypatch):
249
+ def test_continue_recovers_a_persisted_session_wedged_by_a_refused_answer(
250
+ tmp_path, monkeypatch, caplog
251
+ ):
240
252
  pytest.importorskip("ag_ui_langgraph")
241
253
  pytest.importorskip("langgraph.checkpoint.sqlite.aio")
242
254
  ws = tmp_path / "ws"
@@ -258,18 +270,20 @@ def test_continue_recovers_a_persisted_session_wedged_by_a_refused_answer(tmp_pa
258
270
 
259
271
  monkeypatch.setattr(cli, "_is_a_tty", lambda *a, **k: True)
260
272
  monkeypatch.setattr(cli, "handle_interrupt_input", old_menu)
261
- monkeypatch.setattr(cli, "_discard_failed_resume", _no_discard)
273
+ # ...and with a core older than 1.0.58, which didn't check it either.
274
+ monkeypatch.setattr("langstage_core.resume.decision_problems", lambda *_a, **_k: [])
262
275
  r = runner.invoke(main, ["email them"])
263
276
  assert "aprove" in r.output, r.output
264
277
  monkeypatch.undo()
265
278
  monkeypatch.setenv("LANGSTAGE_CONFIG_HOME", str(tmp_path / "empty_home"))
266
279
  monkeypatch.chdir(ws)
267
280
 
268
- r = runner.invoke(main, ["-c", "--no-interactive", "x"])
281
+ # Core 1.0.58's resume path drops the stale answer (core gh #227), without the
282
+ # ag-ui "forwardedProps.command.resume is deprecated" log the cli's own recovery
283
+ # caused by clearing the interrupt before core read it.
284
+ with caplog.at_level(logging.WARNING):
285
+ r = runner.invoke(main, ["-c", "--no-interactive", "x"])
269
286
  assert r.exit_code == 0, r.output
270
287
  assert "aprove" not in r.output, r.output
271
288
  assert "done: sent to a@example.org" in r.output, r.output
272
-
273
-
274
- async def _no_discard(*_a, **_k):
275
- return None
289
+ assert "deprecated" not in r.output + caplog.text, r.output + caplog.text
@@ -0,0 +1,184 @@
1
+ """The approval menu offers only the decisions the pending interrupt allows (gh #197).
2
+
3
+ "Approve all actions" and "Reject all actions" were always offered, so on LangChain's
4
+ HumanInTheLoopMiddleware(allowed_decisions=["approve", "edit"]) "Reject all" sent a
5
+ decision the middleware refuses and the turn errored. ``--no-interactive`` likewise
6
+ sent an approve to an action that doesn't allow one. Each is now offered (or sent) only
7
+ when every pending action allows it.
8
+ """
9
+
10
+ import io
11
+ import textwrap
12
+ from contextlib import redirect_stdout
13
+
14
+ import pytest
15
+
16
+ from langstage_cli import cli
17
+
18
+
19
+ def _frame(*tools):
20
+ """An interrupt frame for (name, allowed_decisions) pairs, as core emits it."""
21
+ union = sorted({v for _, allowed in tools for v in allowed})
22
+ return {
23
+ "action_requests": [{"name": n, "args": {}} for n, _ in tools],
24
+ "review_configs": [{"action_name": n, "allowed_decisions": a} for n, a in tools],
25
+ "allowed_decisions": union,
26
+ }
27
+
28
+
29
+ @pytest.fixture
30
+ def tty(monkeypatch):
31
+ monkeypatch.setattr(cli, "_is_a_tty", lambda *a, **k: True)
32
+
33
+
34
+ def _pick(monkeypatch, label):
35
+ """Choose the menu entry ``label``, recording every menu shown."""
36
+ shown = []
37
+
38
+ def fake_select(options, prompt=""):
39
+ shown.append(list(options))
40
+ return options.index(label)
41
+
42
+ monkeypatch.setattr(cli, "select_option", fake_select)
43
+ return shown
44
+
45
+
46
+ @pytest.mark.parametrize(
47
+ "frame, expected",
48
+ [
49
+ (
50
+ _frame(("send_email", ["approve", "edit"])),
51
+ ["Approve all actions", "Provide custom decision (JSON)", "Exit"],
52
+ ),
53
+ (
54
+ _frame(("send_email", ["edit", "reject"])),
55
+ ["Reject all actions", "Provide custom decision (JSON)", "Exit"],
56
+ ),
57
+ (
58
+ _frame(("send_email", ["respond"])),
59
+ ["Provide custom decision (JSON)", "Exit"],
60
+ ),
61
+ # Per tool: one of two actions doesn't allow reject, so "Reject all" can't apply.
62
+ (
63
+ _frame(("a", ["approve", "reject"]), ("b", ["approve"])),
64
+ ["Approve all actions", "Provide custom decision (JSON)", "Exit"],
65
+ ),
66
+ # No allowed list at all (an older or plain interrupt): the full menu, as before.
67
+ (
68
+ None,
69
+ [
70
+ "Approve all actions",
71
+ "Reject all actions",
72
+ "Provide custom decision (JSON)",
73
+ "Exit",
74
+ ],
75
+ ),
76
+ ],
77
+ )
78
+ def test_menu_offers_only_allowed_bulk_decisions(frame, expected, tty, monkeypatch):
79
+ shown = _pick(monkeypatch, "Exit")
80
+ n = len(frame["action_requests"]) if frame else 1
81
+ with pytest.raises(SystemExit) as exc:
82
+ cli.handle_interrupt_input(n, interrupt=frame)
83
+ assert exc.value.code == 2
84
+ assert shown == [expected]
85
+
86
+
87
+ def test_each_entry_sends_its_own_decision(tty, monkeypatch):
88
+ frame = _frame(("a", ["edit", "reject"]), ("b", ["reject"]))
89
+ _pick(monkeypatch, "Reject all actions")
90
+ assert cli.handle_interrupt_input(2, interrupt=frame) == {
91
+ "decisions": [{"type": "reject"}, {"type": "reject"}]
92
+ }
93
+ _pick(monkeypatch, "Provide custom decision (JSON)")
94
+ monkeypatch.setattr("builtins.input", lambda *_a, **_k: '{"type": "reject"}')
95
+ with redirect_stdout(io.StringIO()):
96
+ assert cli.handle_interrupt_input(2, interrupt=frame) == {
97
+ "decisions": [{"type": "reject"}, {"type": "reject"}]
98
+ }
99
+
100
+
101
+ # ---- End to end on the issue's agent ------------------------------------------------
102
+
103
+ _AGENT = textwrap.dedent(
104
+ """
105
+ from langchain.agents import create_agent
106
+ from langchain.agents.middleware import HumanInTheLoopMiddleware
107
+ from langchain_core.language_models.chat_models import BaseChatModel
108
+ from langchain_core.messages import AIMessage
109
+ from langchain_core.outputs import ChatGeneration, ChatResult
110
+
111
+ class Model(BaseChatModel):
112
+ @property
113
+ def _llm_type(self):
114
+ return "fake-197"
115
+
116
+ def bind_tools(self, tools, **kw):
117
+ return self
118
+
119
+ def _generate(self, messages, stop=None, run_manager=None, **kw):
120
+ if messages[-1].type == "tool":
121
+ msg = AIMessage(content=f"done: {messages[-1].content}")
122
+ else:
123
+ msg = AIMessage(content="", tool_calls=[
124
+ {"name": "send_email", "args": {"to": "a@example.org"}, "id": "c1"}
125
+ ])
126
+ return ChatResult(generations=[ChatGeneration(message=msg)])
127
+
128
+ def send_email(to: str) -> str:
129
+ \"\"\"Send an email.\"\"\"
130
+ return f"sent to {to}"
131
+
132
+ graph = create_agent(
133
+ Model(),
134
+ tools=[send_email],
135
+ middleware=[HumanInTheLoopMiddleware(interrupt_on={
136
+ "send_email": {"allowed_decisions": ALLOWED},
137
+ })],
138
+ )
139
+ """
140
+ )
141
+
142
+
143
+ def _agent(allowed):
144
+ pytest.importorskip("ag_ui_langgraph")
145
+ from langgraph.checkpoint.memory import MemorySaver
146
+
147
+ from langstage_cli.agui_stream import build_session_agent
148
+
149
+ ns: dict = {"ALLOWED": allowed}
150
+ exec(_AGENT, ns)
151
+ return build_session_agent(ns["graph"].copy(update={"checkpointer": MemorySaver()}))
152
+
153
+
154
+ async def test_the_issue_agent_never_shows_reject_and_approve_runs_the_tool(tty, monkeypatch):
155
+ agent = _agent(["approve", "edit"])
156
+ shown = _pick(monkeypatch, "Approve all actions")
157
+ buf = io.StringIO()
158
+ with redirect_stdout(buf):
159
+ _elapsed, had_error = await cli.run_single_turn_agui(agent, "email them", "t-197", True)
160
+ out = buf.getvalue()
161
+ assert had_error is False, out
162
+ assert "done: sent to a@example.org" in out, out
163
+ assert all("Reject all actions" not in menu for menu in shown)
164
+
165
+
166
+ async def test_no_interactive_stops_paused_when_approve_is_not_allowed(monkeypatch, capsys):
167
+ agent = _agent(["edit", "reject"])
168
+ with pytest.raises(SystemExit) as exc:
169
+ await cli.run_single_turn_agui(agent, "email them", "t-197-ni", False)
170
+ assert exc.value.code == 2
171
+ err = capsys.readouterr().err
172
+ assert "does not allow approve (allowed: edit, reject)" in err
173
+ assert "ValueError" not in err
174
+ # Nothing was sent: the thread is still paused on the same approval.
175
+ assert await cli._pending_interrupt(agent, "t-197-ni")
176
+
177
+
178
+ async def test_no_interactive_still_auto_approves_when_allowed(monkeypatch):
179
+ agent = _agent(["approve", "edit"])
180
+ buf = io.StringIO()
181
+ with redirect_stdout(buf):
182
+ _elapsed, had_error = await cli.run_single_turn_agui(agent, "email them", "t-197-ok", False)
183
+ assert had_error is False
184
+ assert "done: sent to a@example.org" in buf.getvalue()
File without changes
File without changes