lithe-cli 0.6.6__tar.gz → 0.8.2__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 (33) hide show
  1. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/PKG-INFO +117 -50
  2. lithe_cli-0.8.2/README.md +277 -0
  3. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/__init__.py +1 -1
  4. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/agent.py +40 -17
  5. lithe_cli-0.8.2/lithe_cli/commands.py +59 -0
  6. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/config.py +74 -34
  7. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/main.py +286 -47
  8. lithe_cli-0.8.2/lithe_cli/profiles.py +253 -0
  9. lithe_cli-0.8.2/lithe_cli/sessions.py +154 -0
  10. lithe_cli-0.8.2/lithe_cli/ttui.py +816 -0
  11. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/tui.py +662 -101
  12. lithe_cli-0.8.2/lithe_cli/workbench.py +604 -0
  13. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli.egg-info/PKG-INFO +117 -50
  14. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli.egg-info/SOURCES.txt +11 -1
  15. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli.egg-info/requires.txt +2 -1
  16. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/pyproject.toml +1 -1
  17. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/tests/test_cli.py +55 -3
  18. lithe_cli-0.8.2/tests/test_cli_sessions.py +192 -0
  19. lithe_cli-0.8.2/tests/test_profiles.py +295 -0
  20. lithe_cli-0.8.2/tests/test_ttui.py +308 -0
  21. lithe_cli-0.8.2/tests/test_tui_v2.py +217 -0
  22. lithe_cli-0.8.2/tests/test_workbench.py +350 -0
  23. lithe_cli-0.6.6/README.md +0 -211
  24. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/LICENSE +0 -0
  25. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/__main__.py +0 -0
  26. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/prompts.py +0 -0
  27. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/py.typed +0 -0
  28. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/setup.py +0 -0
  29. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli/ui.py +0 -0
  30. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli.egg-info/dependency_links.txt +0 -0
  31. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli.egg-info/entry_points.txt +0 -0
  32. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/lithe_cli.egg-info/top_level.txt +0 -0
  33. {lithe_cli-0.6.6 → lithe_cli-0.8.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.6.6
3
+ Version: 0.8.2
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,8 +39,9 @@ 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.13
42
+ Requires-Dist: lithe>=0.9.17
43
43
  Requires-Dist: prompt-toolkit>=3.0.38
44
+ Requires-Dist: textual>=1.0
44
45
  Provides-Extra: dev
45
46
  Requires-Dist: pytest>=8; extra == "dev"
46
47
  Requires-Dist: ruff>=0.4; extra == "dev"
@@ -72,6 +73,37 @@ interactive terminal prompts for the three essentials and saves them to
72
73
  `$LITHE_HOME/config.json` (mode 0600 — it holds the key). An optional
73
74
  connectivity probe catches typos before your first turn.
74
75
 
76
+ The config file holds **named profiles** — several endpoints, one active:
77
+
78
+ ```json
79
+ {
80
+ "version": 2,
81
+ "active": "zhipu",
82
+ "profiles": {
83
+ "zhipu": {"base_url": "https://…", "api_key": "…", "model": "glm-4.6",
84
+ "context_window": 128000, "cached_models": ["glm-4.6"]},
85
+ "zai-preset": {"provider": "zai", "api_key": "…", "model": "glm-4.6"}
86
+ }
87
+ }
88
+ ```
89
+
90
+ A profile may set `"provider"` instead of (or alongside) `base_url`: the
91
+ vendor preset from `lithe.bundles.providers` fills `base_url` when unset
92
+ and contributes `LLMConfig` defaults (transport, `extra_body`,
93
+ `default_headers`) **under** your explicit values — you write the key and
94
+ model, the preset knows the endpoint shape. `LITHE_PROVIDER` overrides the
95
+ profile field; `config --list` / `--show` display it; an unknown name fails
96
+ loudly with the available presets (openai / zai / deepseek / openrouter /
97
+ qwen / moonshot).
98
+
99
+ ```bash
100
+ lithe config # wizard (edits the active profile)
101
+ lithe config --list # profiles, key masked
102
+ lithe config --use openrouter # switch active profile (script-friendly)
103
+ lithe config --model glm-4.5 # set the active profile's default model
104
+ lithe models # GET {base_url}/models, cached into the profile
105
+ ```
106
+
75
107
  To configure by hand instead, point the CLI at any OpenAI-compatible
76
108
  endpoint:
77
109
 
@@ -82,10 +114,11 @@ export LITHE_MODEL=your-model
82
114
  ```
83
115
 
84
116
  Resolution order is flag (`--api-key`, `--base-url`, `--model`) >
85
- environment > saved config file, per key. The wizard never runs without
86
- a TTY on both ends, so pipes and CI keep the hard refusal; `--no-setup`
87
- restores that fail-fast behavior on terminals too. `lithe config --show`
88
- peeks at the saved values with a masked key.
117
+ environment > the selected profile's fields, per key; `--profile NAME`
118
+ (or `LITHE_PROFILE`) selects a profile for one invocation. The wizard
119
+ never runs without a TTY on both ends, so pipes and CI keep the hard
120
+ refusal; `--no-setup` restores that fail-fast behavior on terminals
121
+ too. `lithe config --show` peeks at the saved values with a masked key.
89
122
 
90
123
  `LITHE_HOME` (default `~/.lithe`) locates the run store; the agent's
91
124
  workspace defaults to the current directory (`--workspace` to change).
@@ -118,50 +151,76 @@ usage/context gauges; `--max-steps` caps the tool loop;
118
151
  ### Full-screen interface
119
152
 
120
153
  On an interactive terminal, `lithe chat` and `lithe run TASK` open a
121
- persistent full-screen interface instead of scribbling one-line events
122
- into the console:
154
+ persistent full-screen interface (built on [Textual](https://textual.textualize.io))
155
+ instead of scribbling one-line events into the console. The left pane is
156
+ the conversation; the right sidebar is five fixed sections — 会话(current
157
+ + recent ones, `●` marks sessions with a turn still running)、模型、运行、
158
+ 工具/待办、用量:
123
159
 
124
160
  ```text
125
- lithe 0.6.2 · your-model · /home/me/my-project ● 完成 · 0.2s
126
- ╭─ 对话 ──────────────────────────────╮╭─ 运行状态 ─────────╮
127
- │ 把 a.txt 改成三行待办清单 ││ ● 完成 · 0.2s │
128
- │ ◆ update_todos ││ 步骤 2/35 · 0.2s │
129
- │ ✓ 任务清单已更新(3 条) 0.0s ││ ✓ update_todos 0.0s│
130
- │ ◆ edit_file · 局部修改 a.txt ││ ✓ edit_file 0.0s │
131
- │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ ◆ 待办 1/3 │
132
- │ 已完成。 ││ [~] 修改 a.txt │
133
- │ ││ ◆ 会话用量 │
134
- │ ││ 输入 1,024 · 输出 216│
135
- │ ││ 缓存输入 768 │
136
- │ ││ 合计 1,240 · $0.0021│
137
- │ ││ 上下文 1,024 / 128,000 (0.8%)│
138
- ╰─────────────────────────────────────╯╰────────────────────╯
139
- lithe ❯ _
140
- ● 完成 · 0.2s Enter 发送 · F2 侧栏 · /help 命令
161
+ lithe 0.8.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
162
+ ╭──────────────────────────────────────╮╭──────────────────────────╮
163
+ │ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
164
+ │ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
165
+ │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ #11 bugfix ✓ 7轮 │
166
+ │ 已完成。 ││ F3 切换 · /new 新建 │
167
+ │ ││ ◆ 模型 │
168
+ │ ││ zhipu · glm-4.6 │
169
+ │ ││ ◆ 会话用量 │
170
+ │ ││ 输入 1,024 · 输出 216 │
171
+ ╰──────────────────────────────────────╯╰──────────────────────────╯
172
+ Tab 采纳 → /model /models /new
173
+ lithe ❯ _
174
+ ● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help
141
175
  ```
142
176
 
143
- The left pane is the conversation (task, compact tool-call summaries
144
- and outcomes — file edits land with `+N -M 行` counts — and the
145
- streaming assistant reply). The right sidebar shows run status, recent
146
- tools, todos, session-wide cumulative input/output/cached tokens and
147
- cost, plus the latest model-call context length and window percentage;
148
- usage numbers live only there, the bottom bar keeps status and key
149
- hints. The conversation has an application-managed mouse selection: drag across
150
- its text and press `Ctrl+C` to copy only the selected conversation, without
151
- sidebar content. `Shift+drag` bypasses the application and uses the terminal's
152
- native selection, which can cross both panes; hide the sidebar with F2 or
153
- `/sidebar` before using native selection. The conversation scrolls with the
154
- mouse wheel, PageUp/PageDown and Home/End (a new turn jumps back to the output).
155
- `Ctrl+C` cancels the current turn when there is no conversation selection and
156
- exits when idle. In `lithe run` mode the result stays on screen until you press
157
- `q`. Layout, wrapping and alignment are East-Asian-width aware; narrower
158
- terminals stack the two panes vertically. Pipes and CI keep the plain per-line
177
+ **Switch without leaving the screen**: `F3` opens the session picker
178
+ (`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
179
+ (grouped by profile; `Enter` switch, `s` save as the profile's default,
180
+ `r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
181
+ capability; see below). Switching away from a running session does **not**
182
+ cancel it — its badge stays lit and the pane rebuilds from the store when
183
+ you come back. Typing `/` shows matching commands above the prompt (`Tab`
184
+ accepts; `/model`, `/profile`, `/set` complete their arguments too),
185
+ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
186
+ current turn and exits when idle.
187
+
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
159
192
  output unchanged.
160
193
 
161
- History carries across turns within a session (each turn is its own run
162
- in the store, replayed as context for the next). `/new` clears the
163
- conversation history and session usage totals; `/tools` lists the
164
- registered tools, `/help` lists the commands.
194
+ ### Sessions
195
+
196
+ Every chat conversation persists as a kernel conversation (one run per
197
+ turn, messages written incrementally):
198
+
199
+ ```bash
200
+ lithe chat -c # continue the most recent session
201
+ lithe chat --resume 12 # by id (or unique title prefix)
202
+ lithe sessions # list; newest activity first
203
+ lithe sessions --rename 12 规划 # rename
204
+ lithe sessions --delete 12 # soft delete (runs stay: log/undo work)
205
+ ```
206
+
207
+ A session remembers its last profile and model and restores them on
208
+ resume (unless `--model`/env pinned). Inside chat, the same operations
209
+ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
210
+ `/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
211
+ `/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
212
+
213
+ ### In-session settings
214
+
215
+ The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
216
+ where `Enter` toggles a capability, and typed forms set anything —
217
+ `/set shell on`, `/set code off`, `/set vision`, `/set max-steps 50`,
218
+ `/set timeout 240`, `/set attempts 3`, `/set stream on`, `/set verbose`.
219
+ Settings apply to the **next turn** (the running turn keeps its own tool
220
+ set), stay session-scoped (nothing is written to the profile), and
221
+ turning `shell` on restates its trust warning. `/tools` re-derives the
222
+ registry after a capability flip, so the listing always matches what the
223
+ next turn will see.
165
224
 
166
225
  ### Extra capabilities
167
226
 
@@ -204,7 +263,9 @@ the model.)
204
263
 
205
264
  ```bash
206
265
  $ lithe runs # stored runs (newest last)
266
+ $ lithe sessions # stored conversations (newest first)
207
267
  $ lithe log abc123def456 # messages + actions of one run
268
+ $ lithe models # what the endpoint offers (cached)
208
269
  $ lithe doctor # config + capability status
209
270
  ```
210
271
 
@@ -240,18 +301,24 @@ keys, inline wizard validation, and persistent history.
240
301
  | Path | Contents |
241
302
  | --- | --- |
242
303
  | current dir (or `--workspace`) | the agent's sandboxed workspace — every tool path resolves strictly inside it |
243
- | `~/.lithe/runs` (or `--store`) | JSONL run store: messages, actions, undo records |
304
+ | `~/.lithe/config.json` (or `LITHE_HOME`) | endpoint profiles: `{version, active, profiles}` (0600 — it holds keys) |
305
+ | `~/.lithe/runs` (or `--store`) | JSONL run store: conversations, runs, messages, actions, undo records |
244
306
  | `~/.lithe/runs/todos-<scope-hash>.json` | the agent's task list, isolated by user and resolved workspace |
245
307
  | `~/.lithe/skills` (or `--skills`) | the markdown skill library, when enabled |
246
308
  | `~/.lithe/history` | chat input history (prompt_toolkit `FileHistory`; Up/Ctrl+R recall) |
247
309
 
248
310
  ## Design notes
249
311
 
250
- - The CLI is a thin host: it supplies tools, a system prompt, and the
251
- kernel's `JsonlRunStore`; everything else (ReAct loop, streaming, budgets,
252
- replay, undo engine) is reused from lithe.
253
- - End-to-end behavior is tested offline against a scripted transport — no
254
- test spends tokens.
312
+ - The CLI is a thin host over a `Workbench`: the workbench owns the
313
+ endpoint view (profile + model), the session manager and the running
314
+ turns; the plain REPL and the full-screen Textual app are both just
315
+ subscribers to its event bus and callers of one dispatcher. Everything
316
+ else (ReAct loop, streaming, budgets, replay, undo engine) is reused
317
+ from lithe.
318
+ - The Textual screen is tested headlessly with `App.run_test()` pilots
319
+ (turns, F2/F3/F4, history, completion) — real interaction tests that
320
+ also run on Windows; the legacy prompt_toolkit screen keeps its pure
321
+ row-builder tests plus POSIX-only PTY tests.
255
322
  - `python -m lithe_cli` works alongside the `lithe` console script.
256
323
 
257
324
  ## License
@@ -0,0 +1,277 @@
1
+ # lithe-cli
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/lithe-cli.svg)](https://pypi.org/project/lithe-cli/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/lithe-cli.svg)](https://pypi.org/project/lithe-cli/)
5
+ [![License: MIT](https://img.shields.io/pypi/lithe-cli.svg)](https://pypi.org/project/lithe-cli/)
6
+
7
+ **lithe-cli** is the command-line interface for
8
+ [lithe](https://pypi.org/project/lithe/) — the storage-free ReAct agent
9
+ kernel. Installing it pulls in `lithe` automatically and gives you a `lithe`
10
+ command: chat with an agent that reads and writes files in your workspace,
11
+ runs code, searches the web through MCP tools, inspects stored runs, and
12
+ undoes a run's mutations.
13
+
14
+ ```bash
15
+ pip install lithe-cli
16
+ ```
17
+
18
+ ## Configure
19
+
20
+ There is no default endpoint — the CLI refuses to run rather than silently
21
+ hitting some third-party URL. The easiest way in is the wizard: on the
22
+ first `lithe chat` / `lithe run` (or any time, via `lithe config`) an
23
+ interactive terminal prompts for the three essentials and saves them to
24
+ `$LITHE_HOME/config.json` (mode 0600 — it holds the key). An optional
25
+ connectivity probe catches typos before your first turn.
26
+
27
+ The config file holds **named profiles** — several endpoints, one active:
28
+
29
+ ```json
30
+ {
31
+ "version": 2,
32
+ "active": "zhipu",
33
+ "profiles": {
34
+ "zhipu": {"base_url": "https://…", "api_key": "…", "model": "glm-4.6",
35
+ "context_window": 128000, "cached_models": ["glm-4.6"]},
36
+ "zai-preset": {"provider": "zai", "api_key": "…", "model": "glm-4.6"}
37
+ }
38
+ }
39
+ ```
40
+
41
+ A profile may set `"provider"` instead of (or alongside) `base_url`: the
42
+ vendor preset from `lithe.bundles.providers` fills `base_url` when unset
43
+ and contributes `LLMConfig` defaults (transport, `extra_body`,
44
+ `default_headers`) **under** your explicit values — you write the key and
45
+ model, the preset knows the endpoint shape. `LITHE_PROVIDER` overrides the
46
+ profile field; `config --list` / `--show` display it; an unknown name fails
47
+ loudly with the available presets (openai / zai / deepseek / openrouter /
48
+ qwen / moonshot).
49
+
50
+ ```bash
51
+ lithe config # wizard (edits the active profile)
52
+ lithe config --list # profiles, key masked
53
+ lithe config --use openrouter # switch active profile (script-friendly)
54
+ lithe config --model glm-4.5 # set the active profile's default model
55
+ lithe models # GET {base_url}/models, cached into the profile
56
+ ```
57
+
58
+ To configure by hand instead, point the CLI at any OpenAI-compatible
59
+ endpoint:
60
+
61
+ ```bash
62
+ export LITHE_API_KEY=sk-...
63
+ export LITHE_BASE_URL=https://your-endpoint/api/v1
64
+ export LITHE_MODEL=your-model
65
+ ```
66
+
67
+ Resolution order is flag (`--api-key`, `--base-url`, `--model`) >
68
+ environment > the selected profile's fields, per key; `--profile NAME`
69
+ (or `LITHE_PROFILE`) selects a profile for one invocation. The wizard
70
+ never runs without a TTY on both ends, so pipes and CI keep the hard
71
+ refusal; `--no-setup` restores that fail-fast behavior on terminals
72
+ too. `lithe config --show` peeks at the saved values with a masked key.
73
+
74
+ `LITHE_HOME` (default `~/.lithe`) locates the run store; the agent's
75
+ workspace defaults to the current directory (`--workspace` to change).
76
+
77
+ `lithe doctor` prints the effective configuration — endpoint (with a
78
+ masked key), config file, store, workspace, sandbox backend, skills, MCP
79
+ servers — so you can see what a run would use before starting one.
80
+
81
+ ## Use
82
+
83
+ ### One-shot task
84
+
85
+ ```bash
86
+ $ cd my-project
87
+ $ lithe run "总结 README.md 的要点,存到 SUMMARY.md"
88
+ ⚒ read_file 读取 README.md
89
+ ✓ 已读取 README.md(120 行) 0.1s
90
+ ⚒ write_file 写入 SUMMARY.md
91
+ ✓ 写入 SUMMARY.md(+12 行,新建) 0.0s
92
+ 已把要点写入 SUMMARY.md。
93
+ ── done · steps 3 · tokens 2100 · cost 0.0042
94
+ ```
95
+
96
+ 修改已有文件时,助手优先调用 `edit_file` 或 `apply_patch` 做局部更新;只有新建文件或需要整体替换时才使用 `write_file`。工具调用界面只显示工具名、文件路径等摘要,文件写入/编辑的结果带 `+N -M 行` 的行数变化提示(lithe 0.9.10 起由内核统计)。
97
+
98
+ `--stream` streams tokens as they generate; `-v` adds per-call
99
+ usage/context gauges; `--max-steps` caps the tool loop;
100
+ `--context-window` enables fullness gauges.
101
+
102
+ ### Full-screen interface
103
+
104
+ On an interactive terminal, `lithe chat` and `lithe run TASK` open a
105
+ persistent full-screen interface (built on [Textual](https://textual.textualize.io))
106
+ instead of scribbling one-line events into the console. The left pane is
107
+ the conversation; the right sidebar is five fixed sections — 会话(current
108
+ + recent ones, `●` marks sessions with a turn still running)、模型、运行、
109
+ 工具/待办、用量:
110
+
111
+ ```text
112
+ lithe 0.8.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
113
+ ╭──────────────────────────────────────╮╭──────────────────────────╮
114
+ │ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
115
+ │ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
116
+ │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ #11 bugfix ✓ 7轮 │
117
+ │ 已完成。 ││ F3 切换 · /new 新建 │
118
+ │ ││ ◆ 模型 │
119
+ │ ││ zhipu · glm-4.6 │
120
+ │ ││ ◆ 会话用量 │
121
+ │ ││ 输入 1,024 · 输出 216 │
122
+ ╰──────────────────────────────────────╯╰──────────────────────────╯
123
+ Tab 采纳 → /model /models /new
124
+ lithe ❯ _
125
+ ● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help
126
+ ```
127
+
128
+ **Switch without leaving the screen**: `F3` opens the session picker
129
+ (`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
130
+ (grouped by profile; `Enter` switch, `s` save as the profile's default,
131
+ `r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
132
+ capability; see below). Switching away from a running session does **not**
133
+ cancel it — its badge stays lit and the pane rebuilds from the store when
134
+ you come back. Typing `/` shows matching commands above the prompt (`Tab`
135
+ accepts; `/model`, `/profile`, `/set` complete their arguments too),
136
+ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
137
+ current turn and exits when idle.
138
+
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.
144
+
145
+ ### Sessions
146
+
147
+ Every chat conversation persists as a kernel conversation (one run per
148
+ turn, messages written incrementally):
149
+
150
+ ```bash
151
+ lithe chat -c # continue the most recent session
152
+ lithe chat --resume 12 # by id (or unique title prefix)
153
+ lithe sessions # list; newest activity first
154
+ lithe sessions --rename 12 规划 # rename
155
+ lithe sessions --delete 12 # soft delete (runs stay: log/undo work)
156
+ ```
157
+
158
+ A session remembers its last profile and model and restores them on
159
+ resume (unless `--model`/env pinned). Inside chat, the same operations
160
+ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
161
+ `/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
162
+ `/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
163
+
164
+ ### In-session settings
165
+
166
+ The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
167
+ where `Enter` toggles a capability, and typed forms set anything —
168
+ `/set shell on`, `/set code off`, `/set vision`, `/set max-steps 50`,
169
+ `/set timeout 240`, `/set attempts 3`, `/set stream on`, `/set verbose`.
170
+ Settings apply to the **next turn** (the running turn keeps its own tool
171
+ set), stay session-scoped (nothing is written to the profile), and
172
+ turning `shell` on restates its trust warning. `/tools` re-derives the
173
+ registry after a capability flip, so the listing always matches what the
174
+ next turn will see.
175
+
176
+ ### Extra capabilities
177
+
178
+ The kernel ships these as bundles; the CLI grants them per flag:
179
+
180
+ | Flag | Tools granted | Notes |
181
+ | --- | --- | --- |
182
+ | `--code` | `run_code` / `run_file` | Python under bubblewrap when installed (passthrough otherwise); `doctor` shows which |
183
+ | `--shell` | `run_command` | Native bash/sh on Linux and macOS, PowerShell/cmd on Windows; runs with the current user's host permissions, is not sandboxed, and cannot be undone |
184
+ | `--skills DIR` | `load_skill` | markdown skill library; defaults to `$LITHE_HOME/skills` when it exists, `--skills ""` disables |
185
+ | `--download` | `download_file` | SSRF-guarded, size-capped network fetch |
186
+ | `--vision` | `image_info` / `analyze_image` | image probe is stdlib-only; analysis routes one vision call to the main endpoint |
187
+ | `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
188
+
189
+ ```bash
190
+ $ lithe run --code "用 run_code 验证 results.csv 的行数"
191
+ $ lithe run --shell "检查当前目录的项目状态"
192
+ $ lithe chat --skills ~/my-skills --mcp @~/mcp.json
193
+ ```
194
+
195
+ ### Undo a run
196
+
197
+ The bundled file and todo tools register reverters, so undo works with zero
198
+ configuration:
199
+
200
+ ```bash
201
+ $ lithe runs # find the run
202
+ run status steps cost task
203
+ ──────────── ────── ───── ──── ────────────────
204
+ abc123def456 done 3 0.01 总结 README.md …
205
+ $ lithe undo abc123def456
206
+ ✓ 已撤销 2 个操作(run abc123def456)
207
+ ```
208
+
209
+ A file the run created is deleted; a file it overwrote is restored.
210
+ (`run_code` side effects are not revertible — its tool description warns
211
+ the model.)
212
+
213
+ ### Inspect
214
+
215
+ ```bash
216
+ $ lithe runs # stored runs (newest last)
217
+ $ lithe sessions # stored conversations (newest first)
218
+ $ lithe log abc123def456 # messages + actions of one run
219
+ $ lithe models # what the endpoint offers (cached)
220
+ $ lithe doctor # config + capability status
221
+ ```
222
+
223
+ ### Tools
224
+
225
+ ```bash
226
+ $ lithe tools # what the agent can do
227
+ tool category description
228
+ ──────────── ──────── ──────────────────────────────
229
+ apply_patch WRITE 以行级 patch 一次修改多个文件…
230
+ read_file READ 读取文件内容…
231
+ ...
232
+ ```
233
+
234
+ The default tool set is the workspace bundle (`read_file` / `write_file` /
235
+ `edit_file` / `list_files` / `search_files` / `glob_files` /
236
+ `apply_patch`) plus todos (`update_todos` / `list_todos`); the flags above
237
+ add capabilities. (MCP tools attach at run time, so `lithe tools` lists
238
+ them only after a session has started the servers.)
239
+
240
+ ### Colors
241
+
242
+ Output is colored when stdout is a TTY and `NO_COLOR` is unset; `--color`
243
+ / `--no-color` force either way. Output rendering itself stays
244
+ dependency-free — plain text degrades cleanly through pipes and cron.
245
+ Interactive *input* (the chat prompt and the setup wizard) is
246
+ [prompt_toolkit](https://python-prompt-toolkit.readthedocs.io/):
247
+ wide-character-safe editing, bracketed-paste handling, star-echoed API
248
+ keys, inline wizard validation, and persistent history.
249
+
250
+ ## Where things land
251
+
252
+ | Path | Contents |
253
+ | --- | --- |
254
+ | current dir (or `--workspace`) | the agent's sandboxed workspace — every tool path resolves strictly inside it |
255
+ | `~/.lithe/config.json` (or `LITHE_HOME`) | endpoint profiles: `{version, active, profiles}` (0600 — it holds keys) |
256
+ | `~/.lithe/runs` (or `--store`) | JSONL run store: conversations, runs, messages, actions, undo records |
257
+ | `~/.lithe/runs/todos-<scope-hash>.json` | the agent's task list, isolated by user and resolved workspace |
258
+ | `~/.lithe/skills` (or `--skills`) | the markdown skill library, when enabled |
259
+ | `~/.lithe/history` | chat input history (prompt_toolkit `FileHistory`; Up/Ctrl+R recall) |
260
+
261
+ ## Design notes
262
+
263
+ - The CLI is a thin host over a `Workbench`: the workbench owns the
264
+ endpoint view (profile + model), the session manager and the running
265
+ turns; the plain REPL and the full-screen Textual app are both just
266
+ subscribers to its event bus and callers of one dispatcher. Everything
267
+ else (ReAct loop, streaming, budgets, replay, undo engine) is reused
268
+ from lithe.
269
+ - The Textual screen is tested headlessly with `App.run_test()` pilots
270
+ (turns, F2/F3/F4, history, completion) — real interaction tests that
271
+ also run on Windows; the legacy prompt_toolkit screen keeps its pure
272
+ row-builder tests plus POSIX-only PTY tests.
273
+ - `python -m lithe_cli` works alongside the `lithe` console script.
274
+
275
+ ## License
276
+
277
+ MIT
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.6.6"
3
+ __version__ = "0.8.2"
@@ -88,16 +88,35 @@ def build_system_prompt(cfg: Config) -> str:
88
88
 
89
89
 
90
90
  def build_llm(cfg: Config) -> LLMConfig:
91
- return LLMConfig(
92
- model=cfg.model or "unused",
93
- base_url=cfg.base_url or "unused",
94
- api_key=cfg.api_key or "unused",
95
- timeout=cfg.timeout,
96
- attempts=cfg.attempts,
97
- stream=cfg.stream,
98
- context_window=cfg.context_window,
99
- transport=cfg.transport,
100
- )
91
+ """LLMConfig from the CLI config; a vendor preset (``provider``) acts as
92
+ defaults under the user's explicit values: transport / extra_body /
93
+ default_headers come from the preset unless the config says otherwise,
94
+ and dict fields merge per key."""
95
+ overrides = {
96
+ "model": cfg.model or "unused",
97
+ "base_url": cfg.base_url or "unused",
98
+ "api_key": cfg.api_key or "unused",
99
+ "timeout": cfg.timeout,
100
+ "attempts": cfg.attempts,
101
+ "stream": cfg.stream,
102
+ "context_window": cfg.context_window,
103
+ }
104
+ # The CLI's transport field defaults to "chat" and is only overridden by
105
+ # offline tests (custom transports); the default must not clobber a
106
+ # preset that knows better (e.g. a future "responses" preset).
107
+ if cfg.transport != "chat":
108
+ overrides["transport"] = cfg.transport
109
+ if cfg.provider:
110
+ from lithe.bundles.providers import apply_preset
111
+
112
+ try:
113
+ kwargs = apply_preset(cfg.provider, **overrides)
114
+ except ValueError as exc:
115
+ raise SystemExit(
116
+ f"{exc}。请修正档案里的 provider 字段,或清除它。"
117
+ ) from exc
118
+ return LLMConfig(**kwargs)
119
+ return LLMConfig(**overrides)
101
120
 
102
121
 
103
122
  def build_registry(cfg: Config) -> ToolRegistry:
@@ -207,6 +226,7 @@ async def execute(
207
226
  run_id: str | None = None,
208
227
  on_event=None,
209
228
  stop=None,
229
+ conversation_id: int | None = None,
210
230
  ) -> tuple[str, dict, Any]:
211
231
  """Run one task end-to-end; returns (run_id, done_event, host).
212
232
 
@@ -214,12 +234,14 @@ async def execute(
214
234
  event and silences the line-oriented printing below, including the
215
235
  footer — the caller renders from the events instead. ``stop`` is the
216
236
  kernel's cancellation handle, surfaced so Ctrl+C can cancel a turn
217
- without killing the process.
237
+ without killing the process. ``conversation_id`` attaches the run to a
238
+ stored session (kernel host already consumes ctx.extra).
218
239
  """
219
240
  reg = build_registry(cfg)
220
241
  host = build_host(cfg, reg)
221
242
  rid = run_id or uuid.uuid4().hex[:12]
222
- ctx = AgentContext(run_id=rid, user_id=cfg.user_id)
243
+ extra = {"conversation_id": conversation_id} if conversation_id is not None else {}
244
+ ctx = AgentContext(run_id=rid, user_id=cfg.user_id, extra=extra)
223
245
  manager = None
224
246
  if cfg.mcp_servers:
225
247
  from lithe.bundles.mcp import MCPManager
@@ -253,11 +275,12 @@ async def execute(
253
275
  return rid, ev, host
254
276
 
255
277
 
256
- async def undo(cfg: Config, run_id: str) -> int:
257
- """Revert a run's mutations with the bundled tools' reverters."""
278
+ async def undo(cfg: Config, run_id: str, quiet: bool = False) -> int:
279
+ """Revert a run's mutations; returns how many actions were reverted."""
258
280
  reg = build_registry(cfg)
259
281
  host = build_host(cfg, reg)
260
282
  report = await undo_run(host, run_id, cfg.user_id)
261
- mark = ui.s("✓", GREEN) if report.reverted else ui.s("·", YELLOW)
262
- print(f"{mark} 已撤销 {report.reverted} 个操作(run {run_id})")
263
- return 0
283
+ if not quiet:
284
+ mark = ui.s("✓", GREEN) if report.reverted else ui.s("·", YELLOW)
285
+ print(f"{mark} 已撤销 {report.reverted} 个操作(run {run_id})")
286
+ return report.reverted