lithe-cli 0.8.5__tar.gz → 0.8.6__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.

Files changed (34) hide show
  1. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/PKG-INFO +8 -8
  2. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/README.md +6 -6
  3. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/__init__.py +1 -1
  4. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/agent.py +20 -1
  5. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/config.py +21 -3
  6. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/main.py +21 -27
  7. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/profiles.py +17 -1
  8. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/ttui.py +12 -16
  9. lithe_cli-0.8.6/lithe_cli/tui.py +308 -0
  10. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/workbench.py +3 -2
  11. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli.egg-info/PKG-INFO +8 -8
  12. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli.egg-info/requires.txt +1 -1
  13. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/pyproject.toml +1 -1
  14. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/tests/test_cli.py +55 -180
  15. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/tests/test_profiles.py +81 -0
  16. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/tests/test_ttui.py +0 -18
  17. lithe_cli-0.8.6/tests/test_tui_v2.py +124 -0
  18. lithe_cli-0.8.5/lithe_cli/tui.py +0 -1458
  19. lithe_cli-0.8.5/tests/test_tui_v2.py +0 -232
  20. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/LICENSE +0 -0
  21. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/__main__.py +0 -0
  22. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/commands.py +0 -0
  23. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/prompts.py +0 -0
  24. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/py.typed +0 -0
  25. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/sessions.py +0 -0
  26. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/setup.py +0 -0
  27. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli/ui.py +0 -0
  28. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli.egg-info/SOURCES.txt +0 -0
  29. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli.egg-info/dependency_links.txt +0 -0
  30. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli.egg-info/entry_points.txt +0 -0
  31. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/lithe_cli.egg-info/top_level.txt +0 -0
  32. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/setup.cfg +0 -0
  33. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/tests/test_cli_sessions.py +0 -0
  34. {lithe_cli-0.8.5 → lithe_cli-0.8.6}/tests/test_workbench.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.8.5
3
+ Version: 0.8.6
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
 
@@ -39,7 +39,7 @@ Classifier: Typing :: Typed
39
39
  Requires-Python: >=3.10
40
40
  Description-Content-Type: text/markdown
41
41
  License-File: LICENSE
42
- Requires-Dist: lithe>=0.9.18
42
+ Requires-Dist: lithe>=0.9.19
43
43
  Requires-Dist: prompt-toolkit>=3.0.38
44
44
  Requires-Dist: textual>=1.0
45
45
  Provides-Extra: dev
@@ -186,10 +186,9 @@ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
186
186
  current turn and exits when idle.
187
187
 
188
188
  Text selection uses the terminal's native `Shift+drag` (hide the sidebar
189
- with F2 first if it grabs both panes). The earlier prompt_toolkit screen —
190
- which adds in-app mouse selection and OSC 52 copy — remains available with
191
- `--ui prompt` / `LITHE_UI=prompt`. Pipes and CI keep the plain per-line
192
- output unchanged.
189
+ with F2 first if it grabs both panes). Pipes and CI keep the plain
190
+ per-line output unchanged; the legacy prompt_toolkit full-screen was
191
+ removed — the Textual UI is the only full-screen front-end.
193
192
 
194
193
  ### Sessions
195
194
 
@@ -325,8 +324,9 @@ keys, inline wizard validation, and persistent history.
325
324
  from lithe.
326
325
  - The Textual screen is tested headlessly with `App.run_test()` pilots
327
326
  (turns, F2/F3/F4, history, completion) — real interaction tests that
328
- also run on Windows; the legacy prompt_toolkit screen keeps its pure
329
- row-builder tests plus POSIX-only PTY tests.
327
+ also run on Windows; its pure builders (sidebar/header/footer markup,
328
+ completion suggestions) and the shared `TuiState` event folding have
329
+ direct unit tests.
330
330
  - `python -m lithe_cli` works alongside the `lithe` console script.
331
331
 
332
332
  ## License
@@ -137,10 +137,9 @@ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
137
137
  current turn and exits when idle.
138
138
 
139
139
  Text selection uses the terminal's native `Shift+drag` (hide the sidebar
140
- with F2 first if it grabs both panes). The earlier prompt_toolkit screen —
141
- which adds in-app mouse selection and OSC 52 copy — remains available with
142
- `--ui prompt` / `LITHE_UI=prompt`. Pipes and CI keep the plain per-line
143
- output unchanged.
140
+ with F2 first if it grabs both panes). Pipes and CI keep the plain
141
+ per-line output unchanged; the legacy prompt_toolkit full-screen was
142
+ removed — the Textual UI is the only full-screen front-end.
144
143
 
145
144
  ### Sessions
146
145
 
@@ -276,8 +275,9 @@ keys, inline wizard validation, and persistent history.
276
275
  from lithe.
277
276
  - The Textual screen is tested headlessly with `App.run_test()` pilots
278
277
  (turns, F2/F3/F4, history, completion) — real interaction tests that
279
- also run on Windows; the legacy prompt_toolkit screen keeps its pure
280
- row-builder tests plus POSIX-only PTY tests.
278
+ also run on Windows; its pure builders (sidebar/header/footer markup,
279
+ completion suggestions) and the shared `TuiState` event folding have
280
+ direct unit tests.
281
281
  - `python -m lithe_cli` works alongside the `lithe` console script.
282
282
 
283
283
  ## License
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.8.5"
3
+ __version__ = "0.8.6"
@@ -9,7 +9,9 @@ Everything here maps lithe's host contract onto CLI defaults:
9
9
  - tools — the workspace bundle (read/write/edit/list/search/glob +
10
10
  apply_patch) and todos, plus opt-in capabilities: ``--code`` (sandboxed
11
11
  Python), ``--shell`` (native host commands), ``--skills`` (markdown skill
12
- library), ``--vision`` (image probe/analysis), ``--download`` (SSRF-guarded
12
+ library), ``--vision`` (image probe/analysis), ``--document``
13
+ (PDF/OOXML probe/analysis — dialect from ``--document-format`` > profile
14
+ ``document_format`` > provider preset), ``--download`` (SSRF-guarded
13
15
  network fetch) and ``--mcp`` (external MCP servers);
14
16
  - undo — the bundled tools register reverters, so ``lithe undo`` works with
15
17
  zero configuration.
@@ -82,6 +84,9 @@ def build_system_prompt(cfg: Config) -> str:
82
84
  extras.append("可以用 download_file 下载网络文件到工作区。")
83
85
  if cfg.skills_dir is not None:
84
86
  extras.append("可以先 load_skill 查看可用技能并按需加载规范。")
87
+ if cfg.document:
88
+ extras.append("可以用 analyze_document 直接阅读 PDF/DOCX/XLSX/PPTX 文档并回答关于它的具体问题;"
89
+ "确定元信息(格式/页数)先用 document_info。")
85
90
  if not extras:
86
91
  return SYSTEM_PROMPT_BASE
87
92
  return SYSTEM_PROMPT_BASE + "".join(extras)
@@ -101,6 +106,9 @@ def build_llm(cfg: Config) -> LLMConfig:
101
106
  "stream": cfg.stream,
102
107
  "context_window": cfg.context_window,
103
108
  "reasoning_effort": cfg.reasoning_effort,
109
+ # Explicit dialect (flag/profile) overrides the preset default;
110
+ # apply_preset skips the None override so the preset fills in.
111
+ "document_format": cfg.document_format,
104
112
  }
105
113
  # The CLI's transport field defaults to "chat" and is only overridden by
106
114
  # offline tests (custom transports); the default must not clobber a
@@ -152,6 +160,17 @@ def build_registry(cfg: Config) -> ToolRegistry:
152
160
  from lithe.bundles.images import register_image_tools
153
161
 
154
162
  register_image_tools(reg, workspace_for, llm_config=build_llm(cfg))
163
+ if cfg.document:
164
+ from lithe.bundles.documents import register_document_tools
165
+
166
+ try:
167
+ register_document_tools(
168
+ reg, workspace_for, llm_config=build_llm(cfg),
169
+ document_format=cfg.document_format)
170
+ except ValueError as exc:
171
+ raise SystemExit(
172
+ f"{exc}。请修正 --document-format 或档案里的 document_format "
173
+ f"字段。") from exc
155
174
  return reg
156
175
 
157
176
 
@@ -19,7 +19,11 @@ Capability flags (all off unless asked for):
19
19
  - ``--mcp SPEC`` external MCP servers (JSON array/object, or ``@file``);
20
20
  env ``LITHE_MCP`` holds the same spec;
21
21
  - ``--vision`` ``image_info`` + ``analyze_image`` (one vision call on
22
- the main endpoint, memoized per file hash).
22
+ the main endpoint, memoized per file hash);
23
+ - ``--document`` ``document_info`` + ``analyze_document`` (PDF/OOXML
24
+ reading on the main endpoint; the content-block dialect
25
+ comes from ``--document-format`` > the profile's
26
+ ``document_format`` field > the provider preset).
23
27
  """
24
28
 
25
29
  from __future__ import annotations
@@ -57,6 +61,12 @@ class Config:
57
61
  # fills base_url when unset and contributes LLMConfig defaults (transport,
58
62
  # extra_body, ...) under the user's explicit values. See lithe.bundles.providers.
59
63
  provider: str | None = None
64
+ # Explicit document-block dialect for analyze_document:
65
+ # --document-format flag > this field; the provider preset's
66
+ # document_format fills in when neither is set (inside build_llm, so
67
+ # in-session profile switches re-resolve it). None = not explicit.
68
+ document_format: str | None = None
69
+ document: bool = False
60
70
  store_dir: Path = field(default_factory=lambda: default_store_dir())
61
71
  workspace_dir: Path = field(default_factory=lambda: Path.cwd())
62
72
  user_id: str = DEFAULT_USER
@@ -139,7 +149,7 @@ def config_file() -> Path:
139
149
 
140
150
 
141
151
  def load_saved_endpoint() -> dict:
142
- """Read the active profile's {api_key, base_url, model, provider}; {} if none.
152
+ """Read the active profile's endpoint fields; {} if none.
143
153
 
144
154
  A corrupt file is treated as absent — a bad edit should cost the user
145
155
  one re-prompt, not a broken CLI.
@@ -147,7 +157,7 @@ def load_saved_endpoint() -> dict:
147
157
  from .profiles import ProfileStore
148
158
 
149
159
  endpoint = ProfileStore().endpoint()
150
- keys = (*_ENDPOINT_KEYS, "provider")
160
+ keys = (*_ENDPOINT_KEYS, "provider", "document_format")
151
161
  return {k: endpoint[k] for k in keys if endpoint.get(k)}
152
162
 
153
163
 
@@ -269,6 +279,10 @@ def load_config(args: Any) -> Config:
269
279
  effort = g("reasoning_effort", None) or saved.get("reasoning_effort")
270
280
  if effort is not None and effort.strip().lower() == "off":
271
281
  effort = None
282
+ # Document dialect for analyze_document: flag > profile field. The
283
+ # provider preset's default fills in inside build_llm (apply_preset
284
+ # skips the None override), so in-session profile switches re-resolve.
285
+ document_format = g("document_format", None) or saved.get("document_format")
272
286
  return Config(
273
287
  api_key=(
274
288
  g("api_key", None) or os.environ.get(ENV_API_KEY) or saved.get("api_key")
@@ -277,6 +291,10 @@ def load_config(args: Any) -> Config:
277
291
  model=(g("model", None) or os.environ.get(ENV_MODEL) or saved.get("model")),
278
292
  profile=active,
279
293
  provider=provider,
294
+ document_format=(document_format.strip()
295
+ if isinstance(document_format, str)
296
+ and document_format.strip() else None),
297
+ document=g("document", False),
280
298
  reasoning_effort=(effort.strip() if isinstance(effort, str) and effort.strip()
281
299
  else None),
282
300
  store_dir=store_dir,
@@ -27,7 +27,6 @@ from __future__ import annotations
27
27
 
28
28
  import argparse
29
29
  import asyncio
30
- import os
31
30
  import sys
32
31
  from typing import Any
33
32
 
@@ -99,6 +98,22 @@ def build_parser() -> argparse.ArgumentParser:
99
98
  action="store_true",
100
99
  help="grant image_info/analyze_image (vision on the main endpoint)",
101
100
  )
101
+ sp.add_argument(
102
+ "--document",
103
+ action="store_true",
104
+ help="grant document_info/analyze_document "
105
+ "(PDF/OOXML reading on the main endpoint)",
106
+ )
107
+ sp.add_argument(
108
+ "--document-format",
109
+ metavar="DIALECT",
110
+ default=None,
111
+ choices=["inline-file", "files-api", "none"],
112
+ help="document block dialect for analyze_document: "
113
+ "inline-file = OpenRouter family (incl. self-built same-format "
114
+ "routers), files-api = strict OpenAI two-step upload "
115
+ "(default: profile field document_format, else provider preset)",
116
+ )
102
117
  color = sp.add_mutually_exclusive_group()
103
118
  color.add_argument("--color", action="store_true", help="force colored output")
104
119
  color.add_argument(
@@ -113,13 +128,6 @@ def build_parser() -> argparse.ArgumentParser:
113
128
  sp.add_argument(
114
129
  "--stream", action="store_true", help="stream tokens as they generate"
115
130
  )
116
- sp.add_argument(
117
- "--ui",
118
- choices=["textual", "prompt"],
119
- default=None,
120
- help="full-screen frontend (env LITHE_UI; default: textual; "
121
- "'prompt' is the legacy prompt_toolkit screen)",
122
- )
123
131
  sp.add_argument(
124
132
  "--no-setup",
125
133
  action="store_true",
@@ -493,6 +501,8 @@ def _cmd_config(args: Any) -> int:
493
501
  print(ui.kv("profile", str(store.active_name() or "—")))
494
502
  if saved.get("provider"):
495
503
  print(ui.kv("provider", saved["provider"]))
504
+ if saved.get("document_format"):
505
+ print(ui.kv("document_format", saved["document_format"]))
496
506
  print(ui.kv("base_url", saved["base_url"]))
497
507
  print(ui.kv("api_key", masked))
498
508
  print(ui.kv("model", saved["model"]))
@@ -603,20 +613,12 @@ def _chat_loop(
603
613
  return 0
604
614
 
605
615
 
606
- def _resolve_ui(args: Any) -> str:
607
- """Which full-screen frontend: 'textual' (default) or 'prompt'."""
608
- ui = getattr(args, "ui", None) or os.environ.get("LITHE_UI") or ""
609
- ui = ui.strip().lower()
610
- return ui if ui in ("prompt", "textual") else "textual"
611
-
612
-
613
616
  def _run_textual(cfg: Any, task: str | None, mode: str, args: Any) -> int:
614
617
  try:
615
618
  from .ttui import run_textual_screen
616
619
  except ImportError as exc: # pragma: no cover - depends on install
617
620
  raise SystemExit(
618
- f"Textual 前端不可用({exc})。pip install textual,"
619
- "或用 --ui prompt 走旧版界面。"
621
+ f"Textual 前端不可用({exc})。请 pip install textual 后重试。"
620
622
  ) from exc
621
623
  # run_textual_screen is sync: it drives its own asyncio.run inside.
622
624
  return run_textual_screen(cfg, task, mode, args)
@@ -632,20 +634,12 @@ def main(argv: list[str] | None = None) -> int:
632
634
  if args.command == "run":
633
635
  require_endpoint(cfg, interactive=not args.no_setup)
634
636
  if screen_supported():
635
- if _resolve_ui(args) == "textual":
636
- return _run_textual(cfg, args.task, "run", args)
637
- from .tui import run_screen
638
-
639
- return asyncio.run(run_screen(cfg, args.task, "run"))
637
+ return _run_textual(cfg, args.task, "run", args)
640
638
  return _cmd_run(cfg, args.task)
641
639
  if args.command == "chat":
642
640
  require_endpoint(cfg, interactive=not args.no_setup)
643
641
  if screen_supported():
644
- if _resolve_ui(args) == "textual":
645
- return _run_textual(cfg, None, "chat", args)
646
- from .tui import run_screen
647
-
648
- return asyncio.run(run_screen(cfg, None, "chat", args))
642
+ return _run_textual(cfg, None, "chat", args)
649
643
  return _chat_loop(
650
644
  cfg,
651
645
  resume=args.resume,
@@ -9,10 +9,20 @@ holds keys) grows from the original flat triple to a profile map::
9
9
  "profiles": {
10
10
  "zhipu": {"base_url": "...", "api_key": "...", "model": "glm-4.6",
11
11
  "context_window": 128000, "cached_models": ["glm-4.6"]},
12
- "openrouter": {"base_url": "...", "api_key": "...", "model": "..."}
12
+ "openrouter": {"base_url": "...", "api_key": "...", "model": "...",
13
+ "provider": "openrouter"},
14
+ "selfhost": {"base_url": "https://my-router/api/v1", "api_key": "...",
15
+ "model": "...", "provider": "openrouter",
16
+ "document_format": "inline-file"}
13
17
  }
14
18
  }
15
19
 
20
+ ``provider`` names a vendor preset (format family) and only fills values
21
+ left unset — an explicit ``base_url`` always wins, so a self-built router
22
+ speaking the OpenRouter format keeps its own URL. ``document_format``
23
+ overrides the preset's document-block dialect for ``analyze_document``
24
+ (see lithe.bundles.documents).
25
+
16
26
  A legacy flat ``{api_key, base_url, model}`` file is translated in memory to
17
27
  the single profile ``default`` and is never rewritten until an explicit save
18
28
  (a mutation through this module) — old installs keep working untouched.
@@ -65,6 +75,9 @@ def _clean_endpoint(data: dict) -> dict:
65
75
  effort = data.get("reasoning_effort")
66
76
  if isinstance(effort, str) and effort.strip():
67
77
  out["reasoning_effort"] = effort.strip()
78
+ dfmt = data.get("document_format")
79
+ if isinstance(dfmt, str) and dfmt.strip():
80
+ out["document_format"] = dfmt.strip()
68
81
  for k in ("context_window",):
69
82
  v = data.get(k)
70
83
  if isinstance(v, int) and v > 0:
@@ -176,6 +189,7 @@ class ProfileStore:
176
189
  model: str,
177
190
  context_window: int | None = None,
178
191
  provider: str | None = None,
192
+ document_format: str | None = None,
179
193
  ) -> Path:
180
194
  if not valid_name(name):
181
195
  raise SystemExit(
@@ -188,6 +202,8 @@ class ProfileStore:
188
202
  endpoint["context_window"] = int(context_window)
189
203
  if provider and provider.strip():
190
204
  endpoint["provider"] = provider.strip()
205
+ if document_format and document_format.strip():
206
+ endpoint["document_format"] = document_format.strip()
191
207
  # keep a previously cached model list when the base_url is unchanged
192
208
  old = data["profiles"].get(name) or {}
193
209
  if old.get("cached_models") and old.get("base_url") == endpoint["base_url"]:
@@ -1,24 +1,20 @@
1
- """The default full-screen front-end (Textual).
1
+ """The full-screen front-end (Textual).
2
2
 
3
- Selected by default for `lithe chat` / `lithe run` on an interactive
4
- terminal; the earlier prompt_toolkit screen stays available as
5
- ``--ui prompt`` (``LITHE_UI=prompt``). Same Workbench backend as that
6
- screen — this module only replaces the presentation layer. Layout, modals,
7
- scrolling and repaint are Textual's.
3
+ The only interactive UI: `lithe chat` / `lithe run` on an interactive
4
+ terminal always launch it; without a TTY `main` falls back to the plain
5
+ per-line REPL. Layout, modals, scrolling and repaint are Textual's.
8
6
 
9
- What is intentionally reused from the prompt_toolkit screen
10
- (:mod:`lithe_cli.tui`): ``TuiState`` (kernel-event folding, usage
11
- accounting), ``transcript_feed_lines`` (store → feed rows). The
12
- conversation pane renders *from* the state's feed, so both front-ends show
13
- identical content.
7
+ What it builds on from :mod:`lithe_cli.tui`: ``TuiState`` (kernel-event
8
+ folding, usage accounting), ``transcript_feed_lines`` (store → feed
9
+ rows). The conversation pane renders *from* the state's feed.
14
10
 
15
11
  Input niceties: ``/``-commands complete inline (suggestions above the
16
12
  prompt, Tab accepts the first), and ↑/↓ recall the persistent chat history
17
13
  (shared with the plain REPL through prompt_toolkit's FileHistory store).
18
14
 
19
- Known gap versus the prompt_toolkit screen: no in-app mouse-drag selection
20
- / OSC 52 copy — use the terminal's native Shift+drag selection instead
21
- (hide the sidebar with F2 first if it gets in the way).
15
+ No in-app mouse-drag selection / OSC 52 copy — use the terminal's native
16
+ Shift+drag selection instead (hide the sidebar with F2 first if it gets
17
+ in the way).
22
18
  """
23
19
 
24
20
  from __future__ import annotations
@@ -440,7 +436,7 @@ class LitheApp(App):
440
436
  self.query_one("#prompt", Input).disabled = True
441
437
  asyncio.create_task(self._run_one_shot(self.initial_task))
442
438
 
443
- # -- state management (mirrors the prompt_toolkit driver) -----------------
439
+ # -- state management --------------------------------------------------------
444
440
 
445
441
  def _current_cid(self) -> int | None:
446
442
  return self.wb.current["id"] if getattr(self, "wb", None) \
@@ -907,6 +903,6 @@ async def _driver(app: LitheApp) -> int:
907
903
 
908
904
  def run_textual_screen(cfg, task: str | None, mode: str,
909
905
  args: Any = None) -> int:
910
- """Drop-in Textual replacement for :func:`lithe_cli.tui.run_screen`."""
906
+ """The full-screen driver for `lithe chat` (mode='chat') and `lithe run`."""
911
907
  app = LitheApp(cfg, task, mode, args)
912
908
  return asyncio.run(_driver(app))