lithe-cli 0.6.4__tar.gz → 0.6.5__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.

Potentially problematic release.


This version of lithe-cli might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
5
5
  License: MIT License
6
6
 
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.6.4"
3
+ __version__ = "0.6.5"
@@ -13,6 +13,9 @@ used ``input``/``getpass``/readline are all upstream concerns now.
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
+ import re
17
+ import sys
18
+
16
19
  from prompt_toolkit import prompt
17
20
  from prompt_toolkit.formatted_text import ANSI
18
21
  from prompt_toolkit.history import FileHistory, InMemoryHistory
@@ -27,6 +30,24 @@ _UTF8_HINT = (
27
30
  "请把终端与 locale 设为 UTF-8(如 export LANG=C.UTF-8)后重试。"
28
31
  )
29
32
 
33
+ _ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
34
+
35
+
36
+ def _plain_line(message: str) -> str:
37
+ """Line input when prompt_toolkit cannot run: on Windows its console
38
+ backend (Win32Output/Windows10_Output) needs a real screen buffer and
39
+ raises NoConsoleScreenBufferError when either end is a pipe or redirect —
40
+ POSIX degrades to plain-text output there, Windows does not. No line
41
+ editing exists in a pipe anyway, so the builtin is enough."""
42
+ return input(_ANSI_RE.sub("", message))
43
+
44
+
45
+ def _pipe_safe() -> bool:
46
+ """True when both ends are interactive and prompt_toolkit can own them."""
47
+ if sys.platform == "win32":
48
+ return sys.stdout.isatty() and sys.stdin.isatty()
49
+ return True
50
+
30
51
 
31
52
  def history_file():
32
53
  """Where chat history persists, next to the saved endpoint."""
@@ -47,6 +68,8 @@ def open_history() -> FileHistory:
47
68
 
48
69
  def chat_line(message: str, history) -> str:
49
70
  """The chat REPL prompt: colored, history-searchable, paste-safe."""
71
+ if not _pipe_safe():
72
+ return _plain_line(message)
50
73
  return prompt(
51
74
  ANSI(message),
52
75
  history=history,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
5
5
  License: MIT License
6
6
 
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