lithe-cli 0.1.0__tar.gz → 0.1.1__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 (44) hide show
  1. lithe_cli-0.1.1/PKG-INFO +357 -0
  2. lithe_cli-0.1.1/README.md +308 -0
  3. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/lithe_cli/__init__.py +1 -1
  4. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/lithe_cli/__main__.py +1 -0
  5. lithe_cli-0.1.1/lithe_cli/agent.py +457 -0
  6. lithe_cli-0.1.1/lithe_cli/commands.py +60 -0
  7. lithe_cli-0.1.1/lithe_cli/config.py +392 -0
  8. lithe_cli-0.1.1/lithe_cli/main.py +745 -0
  9. lithe_cli-0.1.1/lithe_cli/profiles.py +330 -0
  10. lithe_cli-0.1.1/lithe_cli/prompts.py +141 -0
  11. lithe_cli-0.1.1/lithe_cli/sessions.py +157 -0
  12. lithe_cli-0.1.1/lithe_cli/setup.py +109 -0
  13. lithe_cli-0.1.1/lithe_cli/ttui.py +1029 -0
  14. lithe_cli-0.1.1/lithe_cli/tui.py +339 -0
  15. lithe_cli-0.1.1/lithe_cli/ui.py +332 -0
  16. lithe_cli-0.1.1/lithe_cli/workbench.py +732 -0
  17. lithe_cli-0.1.1/lithe_cli.egg-info/PKG-INFO +357 -0
  18. lithe_cli-0.1.1/lithe_cli.egg-info/SOURCES.txt +33 -0
  19. lithe_cli-0.1.1/lithe_cli.egg-info/requires.txt +7 -0
  20. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/pyproject.toml +1 -1
  21. lithe_cli-0.1.1/tests/test_cli.py +1071 -0
  22. lithe_cli-0.1.1/tests/test_cli_budget_steer.py +272 -0
  23. lithe_cli-0.1.1/tests/test_cli_guard.py +67 -0
  24. lithe_cli-0.1.1/tests/test_cli_sessions.py +205 -0
  25. lithe_cli-0.1.1/tests/test_cli_subagents.py +135 -0
  26. lithe_cli-0.1.1/tests/test_profiles.py +450 -0
  27. lithe_cli-0.1.1/tests/test_ttui.py +515 -0
  28. lithe_cli-0.1.1/tests/test_tui_v2.py +143 -0
  29. lithe_cli-0.1.1/tests/test_workbench.py +413 -0
  30. lithe_cli-0.1.0/PKG-INFO +0 -168
  31. lithe_cli-0.1.0/README.md +0 -121
  32. lithe_cli-0.1.0/lithe_cli/agent.py +0 -123
  33. lithe_cli-0.1.0/lithe_cli/config.py +0 -91
  34. lithe_cli-0.1.0/lithe_cli/main.py +0 -201
  35. lithe_cli-0.1.0/lithe_cli.egg-info/PKG-INFO +0 -168
  36. lithe_cli-0.1.0/lithe_cli.egg-info/SOURCES.txt +0 -16
  37. lithe_cli-0.1.0/lithe_cli.egg-info/requires.txt +0 -5
  38. lithe_cli-0.1.0/tests/test_cli.py +0 -145
  39. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/LICENSE +0 -0
  40. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/lithe_cli/py.typed +0 -0
  41. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/lithe_cli.egg-info/dependency_links.txt +0 -0
  42. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/lithe_cli.egg-info/entry_points.txt +0 -0
  43. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/lithe_cli.egg-info/top_level.txt +0 -0
  44. {lithe_cli-0.1.0 → lithe_cli-0.1.1}/setup.cfg +0 -0
@@ -0,0 +1,357 @@
1
+ Metadata-Version: 2.4
2
+ Name: lithe-cli
3
+ Version: 0.1.1
4
+ Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
5
+ License: MIT License
6
+
7
+ Copyright (c) 2026 betaloop contributors
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Keywords: agent,llm,react,cli,tool-calling
28
+ Classifier: Development Status :: 4 - Beta
29
+ Classifier: Environment :: Console
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3
33
+ Classifier: Programming Language :: Python :: 3.10
34
+ Classifier: Programming Language :: Python :: 3.11
35
+ Classifier: Programming Language :: Python :: 3.12
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
38
+ Classifier: Typing :: Typed
39
+ Requires-Python: >=3.10
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE
42
+ Requires-Dist: lithe>=0.1.0
43
+ Requires-Dist: prompt-toolkit>=3.0.38
44
+ Requires-Dist: textual>=1.0
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest>=8; extra == "dev"
47
+ Requires-Dist: ruff>=0.4; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ # lithe-cli
51
+
52
+ [![PyPI](https://img.shields.io/pypi/v/lithe-cli.svg)](https://pypi.org/project/lithe-cli/)
53
+ [![Python](https://img.shields.io/pypi/pyversions/lithe-cli.svg)](https://pypi.org/project/lithe-cli/)
54
+ [![License: MIT](https://img.shields.io/pypi/lithe-cli.svg)](https://pypi.org/project/lithe-cli/)
55
+
56
+ **lithe-cli** is the command-line interface for
57
+ [lithe](https://pypi.org/project/lithe/) — the storage-free ReAct agent
58
+ kernel. Installing it pulls in `lithe` automatically and gives you a `lithe`
59
+ command: chat with an agent that reads and writes files in your workspace,
60
+ runs code, searches the web through MCP tools, inspects stored runs, and
61
+ undoes a run's mutations.
62
+
63
+ ```bash
64
+ pip install lithe-cli
65
+ ```
66
+
67
+ ## Configure
68
+
69
+ There is no default endpoint — the CLI refuses to run rather than silently
70
+ hitting some third-party URL. The easiest way in is the wizard: on the
71
+ first `lithe chat` / `lithe run` (or any time, via `lithe config`) an
72
+ interactive terminal prompts for the three essentials and saves them to
73
+ `$LITHE_HOME/config.json` (mode 0600 — it holds the key). An optional
74
+ connectivity probe catches typos before your first turn.
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
+
107
+ To configure by hand instead, point the CLI at any OpenAI-compatible
108
+ endpoint:
109
+
110
+ ```bash
111
+ export LITHE_API_KEY=sk-...
112
+ export LITHE_BASE_URL=https://your-endpoint/api/v1
113
+ export LITHE_MODEL=your-model
114
+ ```
115
+
116
+ Resolution order is flag (`--api-key`, `--base-url`, `--model`) >
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.
122
+
123
+ `LITHE_HOME` (default `~/.lithe`) locates the run store; the agent's
124
+ workspace defaults to the current directory (`--workspace` to change).
125
+
126
+ `lithe doctor` prints the effective configuration — endpoint (with a
127
+ masked key), config file, store, workspace, sandbox backend, skills, MCP
128
+ servers — so you can see what a run would use before starting one.
129
+
130
+ ## Use
131
+
132
+ ### One-shot task
133
+
134
+ ```bash
135
+ $ cd my-project
136
+ $ lithe run "总结 README.md 的要点,存到 SUMMARY.md"
137
+ ⚒ read_file 读取 README.md
138
+ ✓ 已读取 README.md(120 行) 0.1s
139
+ ⚒ write_file 写入 SUMMARY.md
140
+ ✓ 写入 SUMMARY.md(+12 行,新建) 0.0s
141
+ 已把要点写入 SUMMARY.md。
142
+ ── done · steps 3 · tokens 2100 · cost 0.0042
143
+ ```
144
+
145
+ 修改已有文件时,助手优先调用 `edit_file` 或 `apply_patch` 做局部更新;只有新建文件或需要整体替换时才使用 `write_file`。工具调用界面只显示工具名、文件路径等摘要,文件写入/编辑的结果带 `+N -M 行` 的行数变化提示(lithe 0.9.10 起由内核统计)。
146
+
147
+ `--stream` streams tokens as they generate; `-v` adds per-call
148
+ usage/context gauges; `--max-steps` caps the tool loop;
149
+ `--context-window` enables fullness gauges; `--reasoning-effort LEVEL`
150
+ sets the reasoning intensity for one invocation (flag > profile field;
151
+ `/reasoning` adjusts it in-session). Run budgets end the turn with
152
+ status `budget_exceeded` once crossed: `--max-cost USD` (needs a
153
+ `pricing` table in the profile on endpoints that report no usage cost)
154
+ and `--max-tokens N` (cumulative); both show progress lines in the
155
+ sidebar and adjust via `/set` (`off` clears). Sampling:
156
+ `--temperature` / `--max-output-tokens` (flag > profile field).
157
+
158
+ ### Full-screen interface
159
+
160
+ On an interactive terminal, `lithe chat` and `lithe run TASK` open a
161
+ persistent full-screen interface (built on [Textual](https://textual.textualize.io))
162
+ instead of scribbling one-line events into the console. The left pane is
163
+ the conversation; the right sidebar is five fixed sections — 会话(current
164
+ + recent ones, `●` marks sessions with a turn still running)、模型、运行、
165
+ 工具/待办、用量:
166
+
167
+ ```text
168
+ lithe 0.9.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
169
+ ╭──────────────────────────────────────╮╭──────────────────────────╮
170
+ │ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
171
+ │ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
172
+ │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ #11 bugfix ✓ 7轮 │
173
+ │ 已完成。 ││ F3 切换 · /new 新建 │
174
+ │ ││ ◆ 模型 │
175
+ │ ││ zhipu · glm-4.6 │
176
+ │ ││ ◆ 会话用量 │
177
+ │ ││ 输入 1,024 · 输出 216 │
178
+ ╰──────────────────────────────────────╯╰──────────────────────────╯
179
+ Tab 采纳 → /model /models /new
180
+ lithe ❯ _
181
+ ● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · F6 推理 · /help
182
+ ```
183
+
184
+ **Switch without leaving the screen**: `F3` opens the session picker
185
+ (`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
186
+ (grouped by profile; `Enter` switch, `s` save as the profile's default,
187
+ `r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
188
+ capability; see below). Switching away from a running session does **not**
189
+ cancel it — its badge stays lit and the pane rebuilds from the store when
190
+ you come back. Typing `/` shows matching commands above the prompt (`Tab`
191
+ accepts; `/model`, `/profile`, `/set` complete their arguments too),
192
+ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
193
+ current turn (a second press during the same turn force-exits) and exits
194
+ when idle. Plain text typed mid-turn **steers** the running agent: it is
195
+ queued into the kernel's steering inbox and injected as a user message at
196
+ the next step boundary (rendered in the transcript; persistently
197
+ recorded), so you can correct course while it works — texts that cannot
198
+ be injected before the turn ends are honestly reported as dropped. Slash
199
+ commands work while a turn runs. The transcript follows new output only
200
+ while you're at the bottom — scroll up to re-read and your position
201
+ sticks.
202
+
203
+ Text selection uses the terminal's native `Shift+drag` (hide the sidebar
204
+ with F2 first if it grabs both panes). Pipes and CI keep the plain
205
+ per-line output unchanged; the legacy prompt_toolkit full-screen was
206
+ removed — the Textual UI is the only full-screen front-end.
207
+
208
+ ### Sessions
209
+
210
+ Every chat conversation persists as a kernel conversation (one run per
211
+ turn, messages written incrementally):
212
+
213
+ ```bash
214
+ lithe chat -c # continue the most recent session
215
+ lithe chat --resume 12 # by id (or unique title prefix)
216
+ lithe sessions # list; newest activity first
217
+ lithe sessions --rename 12 规划 # rename
218
+ lithe sessions --delete 12 # soft delete (runs stay: log/undo work)
219
+ ```
220
+
221
+ A session remembers its last profile and model and restores them on
222
+ resume (unless `--model`/env pinned). Inside chat, the same operations
223
+ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
224
+ `/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
225
+ `/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
226
+
227
+ ### In-session settings
228
+
229
+ The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
230
+ where `Enter` toggles a capability, and typed forms set anything —
231
+ `/set shell on`, `/set code off`, `/set vision`, `/set document on`,
232
+ `/set max-steps 50`, `/set timeout 240`, `/set attempts 3`,
233
+ `/set stream on`, `/set verbose`.
234
+ Settings apply to the **next turn** (the running turn keeps its own tool
235
+ set), stay session-scoped (nothing is written to the profile), and
236
+ turning `shell` on restates its trust warning. `/tools` re-derives the
237
+ registry after a capability flip, so the listing always matches what the
238
+ next turn will see.
239
+
240
+ **Reasoning intensity**: `/reasoning` (or `F6`) picks a level —
241
+ `off / minimal / low / medium / high`, or any value your model accepts
242
+ (`none` on some) typed directly; `--save` persists it to the profile. The
243
+ kernel maps it per protocol (`reasoning_effort` on chat-completions,
244
+ `reasoning.effort` on Responses) and combines it with
245
+ `extra_body["reasoning"]` siblings such as OpenRouter's
246
+ `max_tokens`/`exclude`. The sidebar shows the active level when set.
247
+
248
+ ### Extra capabilities
249
+
250
+ The kernel ships these as bundles; the CLI grants them per flag:
251
+
252
+ | Flag | Tools granted | Notes |
253
+ | --- | --- | --- |
254
+ | `--code` | `run_code` / `run_file` | Python under bubblewrap when installed (passthrough otherwise); `doctor` shows which |
255
+ | `--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 |
256
+ | `--skills DIR` | `load_skill` | markdown skill library; defaults to `$LITHE_HOME/skills` when it exists, `--skills ""` disables |
257
+ | `--download` | `download_file` | SSRF-guarded, size-capped network fetch |
258
+ | `--vision` | `image_info` / `analyze_image` | image probe is stdlib-only; analysis routes one vision call to the main endpoint |
259
+ | `--document` | `document_info` / `analyze_document` | PDF/DOCX/XLSX/PPTX reading on the main endpoint; `/set document` toggles in-session |
260
+ | `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
261
+ | `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
262
+ | `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
263
+ | `--subagents` / `--no-subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; **on by default** (the roster reuses already-enabled tools only — no new powers); `/set subagents` toggles in-session |
264
+ | `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
265
+
266
+ ```bash
267
+ $ lithe run --code "用 run_code 验证 results.csv 的行数"
268
+ $ lithe run --document "总结 report.pdf 的结论,存到 NOTES.md"
269
+ $ lithe run --subagents "先让 researcher 摸清 src 结构,再让 coder 分头改"
270
+ $ lithe run --shell "检查当前目录的项目状态"
271
+ $ lithe chat --skills ~/my-skills --mcp @~/mcp.json
272
+ ```
273
+
274
+ ### Undo a run
275
+
276
+ The bundled file and todo tools register reverters, so undo works with zero
277
+ configuration:
278
+
279
+ ```bash
280
+ $ lithe runs # find the run
281
+ run status steps cost task
282
+ ──────────── ────── ───── ──── ────────────────
283
+ abc123def456 done 3 0.01 总结 README.md …
284
+ $ lithe undo abc123def456
285
+ ✓ 已撤销 2 个操作(run abc123def456)
286
+ ```
287
+
288
+ A file the run created is deleted; a file it overwrote is restored.
289
+ (`run_code` side effects are not revertible — its tool description warns
290
+ the model.)
291
+
292
+ ### Inspect
293
+
294
+ ```bash
295
+ $ lithe runs # stored runs (newest last)
296
+ $ lithe sessions # stored conversations (newest first)
297
+ $ lithe log abc123def456 # messages + actions of one run
298
+ $ lithe models # what the endpoint offers (cached)
299
+ $ lithe doctor # config + capability status
300
+ ```
301
+
302
+ ### Tools
303
+
304
+ ```bash
305
+ $ lithe tools # what the agent can do
306
+ tool category description
307
+ ──────────── ──────── ──────────────────────────────
308
+ apply_patch WRITE 以行级 patch 一次修改多个文件…
309
+ read_file READ 读取文件内容…
310
+ ...
311
+ ```
312
+
313
+ The default tool set is the workspace bundle (`read_file` / `write_file` /
314
+ `edit_file` / `list_files` / `search_files` / `glob_files` /
315
+ `apply_patch`) plus todos (`update_todos` / `list_todos`); the flags above
316
+ add capabilities. (MCP tools attach at run time, so `lithe tools` lists
317
+ them only after a session has started the servers.)
318
+
319
+ ### Colors
320
+
321
+ Output is colored when stdout is a TTY and `NO_COLOR` is unset; `--color`
322
+ / `--no-color` force either way. Output rendering itself stays
323
+ dependency-free — plain text degrades cleanly through pipes and cron.
324
+ Interactive *input* (the chat prompt and the setup wizard) is
325
+ [prompt_toolkit](https://python-prompt-toolkit.readthedocs.io/):
326
+ wide-character-safe editing, bracketed-paste handling, star-echoed API
327
+ keys, inline wizard validation, and persistent history.
328
+
329
+ ## Where things land
330
+
331
+ | Path | Contents |
332
+ | --- | --- |
333
+ | current dir (or `--workspace`) | the agent's sandboxed workspace — every tool path resolves strictly inside it |
334
+ | `~/.lithe/config.json` (or `LITHE_HOME`) | endpoint profiles: `{version, active, profiles}` (0600 — it holds keys) |
335
+ | `~/.lithe/runs` (or `--store`) | JSONL run store: conversations, runs, messages, actions, undo records |
336
+ | `~/.lithe/runs/todos-<scope-hash>.json` | the agent's task list, isolated by user and resolved workspace |
337
+ | `~/.lithe/skills` (or `--skills`) | the markdown skill library, when enabled |
338
+ | `~/.lithe/history` | chat input history (prompt_toolkit `FileHistory`; `↑`/`↓` recall in the TUI, Ctrl+R search in the plain REPL) |
339
+
340
+ ## Design notes
341
+
342
+ - The CLI is a thin host over a `Workbench`: the workbench owns the
343
+ endpoint view (profile + model), the session manager and the running
344
+ turns; the plain REPL and the full-screen Textual app are both just
345
+ subscribers to its event bus and callers of one dispatcher. Everything
346
+ else (ReAct loop, streaming, budgets, replay, undo engine) is reused
347
+ from lithe.
348
+ - The Textual screen is tested headlessly with `App.run_test()` pilots
349
+ (turns, F2/F3/F4, history, completion) — real interaction tests that
350
+ also run on Windows; its pure builders (sidebar/header/footer markup,
351
+ completion suggestions) and the shared `TuiState` event folding have
352
+ direct unit tests.
353
+ - `python -m lithe_cli` works alongside the `lithe` console script.
354
+
355
+ ## License
356
+
357
+ MIT
@@ -0,0 +1,308 @@
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; `--reasoning-effort LEVEL`
101
+ sets the reasoning intensity for one invocation (flag > profile field;
102
+ `/reasoning` adjusts it in-session). Run budgets end the turn with
103
+ status `budget_exceeded` once crossed: `--max-cost USD` (needs a
104
+ `pricing` table in the profile on endpoints that report no usage cost)
105
+ and `--max-tokens N` (cumulative); both show progress lines in the
106
+ sidebar and adjust via `/set` (`off` clears). Sampling:
107
+ `--temperature` / `--max-output-tokens` (flag > profile field).
108
+
109
+ ### Full-screen interface
110
+
111
+ On an interactive terminal, `lithe chat` and `lithe run TASK` open a
112
+ persistent full-screen interface (built on [Textual](https://textual.textualize.io))
113
+ instead of scribbling one-line events into the console. The left pane is
114
+ the conversation; the right sidebar is five fixed sections — 会话(current
115
+ + recent ones, `●` marks sessions with a turn still running)、模型、运行、
116
+ 工具/待办、用量:
117
+
118
+ ```text
119
+ lithe 0.9.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
120
+ ╭──────────────────────────────────────╮╭──────────────────────────╮
121
+ │ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
122
+ │ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
123
+ │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ #11 bugfix ✓ 7轮 │
124
+ │ 已完成。 ││ F3 切换 · /new 新建 │
125
+ │ ││ ◆ 模型 │
126
+ │ ││ zhipu · glm-4.6 │
127
+ │ ││ ◆ 会话用量 │
128
+ │ ││ 输入 1,024 · 输出 216 │
129
+ ╰──────────────────────────────────────╯╰──────────────────────────╯
130
+ Tab 采纳 → /model /models /new
131
+ lithe ❯ _
132
+ ● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · F6 推理 · /help
133
+ ```
134
+
135
+ **Switch without leaving the screen**: `F3` opens the session picker
136
+ (`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
137
+ (grouped by profile; `Enter` switch, `s` save as the profile's default,
138
+ `r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
139
+ capability; see below). Switching away from a running session does **not**
140
+ cancel it — its badge stays lit and the pane rebuilds from the store when
141
+ you come back. Typing `/` shows matching commands above the prompt (`Tab`
142
+ accepts; `/model`, `/profile`, `/set` complete their arguments too),
143
+ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
144
+ current turn (a second press during the same turn force-exits) and exits
145
+ when idle. Plain text typed mid-turn **steers** the running agent: it is
146
+ queued into the kernel's steering inbox and injected as a user message at
147
+ the next step boundary (rendered in the transcript; persistently
148
+ recorded), so you can correct course while it works — texts that cannot
149
+ be injected before the turn ends are honestly reported as dropped. Slash
150
+ commands work while a turn runs. The transcript follows new output only
151
+ while you're at the bottom — scroll up to re-read and your position
152
+ sticks.
153
+
154
+ Text selection uses the terminal's native `Shift+drag` (hide the sidebar
155
+ with F2 first if it grabs both panes). Pipes and CI keep the plain
156
+ per-line output unchanged; the legacy prompt_toolkit full-screen was
157
+ removed — the Textual UI is the only full-screen front-end.
158
+
159
+ ### Sessions
160
+
161
+ Every chat conversation persists as a kernel conversation (one run per
162
+ turn, messages written incrementally):
163
+
164
+ ```bash
165
+ lithe chat -c # continue the most recent session
166
+ lithe chat --resume 12 # by id (or unique title prefix)
167
+ lithe sessions # list; newest activity first
168
+ lithe sessions --rename 12 规划 # rename
169
+ lithe sessions --delete 12 # soft delete (runs stay: log/undo work)
170
+ ```
171
+
172
+ A session remembers its last profile and model and restores them on
173
+ resume (unless `--model`/env pinned). Inside chat, the same operations
174
+ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
175
+ `/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
176
+ `/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
177
+
178
+ ### In-session settings
179
+
180
+ The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
181
+ where `Enter` toggles a capability, and typed forms set anything —
182
+ `/set shell on`, `/set code off`, `/set vision`, `/set document on`,
183
+ `/set max-steps 50`, `/set timeout 240`, `/set attempts 3`,
184
+ `/set stream on`, `/set verbose`.
185
+ Settings apply to the **next turn** (the running turn keeps its own tool
186
+ set), stay session-scoped (nothing is written to the profile), and
187
+ turning `shell` on restates its trust warning. `/tools` re-derives the
188
+ registry after a capability flip, so the listing always matches what the
189
+ next turn will see.
190
+
191
+ **Reasoning intensity**: `/reasoning` (or `F6`) picks a level —
192
+ `off / minimal / low / medium / high`, or any value your model accepts
193
+ (`none` on some) typed directly; `--save` persists it to the profile. The
194
+ kernel maps it per protocol (`reasoning_effort` on chat-completions,
195
+ `reasoning.effort` on Responses) and combines it with
196
+ `extra_body["reasoning"]` siblings such as OpenRouter's
197
+ `max_tokens`/`exclude`. The sidebar shows the active level when set.
198
+
199
+ ### Extra capabilities
200
+
201
+ The kernel ships these as bundles; the CLI grants them per flag:
202
+
203
+ | Flag | Tools granted | Notes |
204
+ | --- | --- | --- |
205
+ | `--code` | `run_code` / `run_file` | Python under bubblewrap when installed (passthrough otherwise); `doctor` shows which |
206
+ | `--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 |
207
+ | `--skills DIR` | `load_skill` | markdown skill library; defaults to `$LITHE_HOME/skills` when it exists, `--skills ""` disables |
208
+ | `--download` | `download_file` | SSRF-guarded, size-capped network fetch |
209
+ | `--vision` | `image_info` / `analyze_image` | image probe is stdlib-only; analysis routes one vision call to the main endpoint |
210
+ | `--document` | `document_info` / `analyze_document` | PDF/DOCX/XLSX/PPTX reading on the main endpoint; `/set document` toggles in-session |
211
+ | `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
212
+ | `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
213
+ | `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
214
+ | `--subagents` / `--no-subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; **on by default** (the roster reuses already-enabled tools only — no new powers); `/set subagents` toggles in-session |
215
+ | `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
216
+
217
+ ```bash
218
+ $ lithe run --code "用 run_code 验证 results.csv 的行数"
219
+ $ lithe run --document "总结 report.pdf 的结论,存到 NOTES.md"
220
+ $ lithe run --subagents "先让 researcher 摸清 src 结构,再让 coder 分头改"
221
+ $ lithe run --shell "检查当前目录的项目状态"
222
+ $ lithe chat --skills ~/my-skills --mcp @~/mcp.json
223
+ ```
224
+
225
+ ### Undo a run
226
+
227
+ The bundled file and todo tools register reverters, so undo works with zero
228
+ configuration:
229
+
230
+ ```bash
231
+ $ lithe runs # find the run
232
+ run status steps cost task
233
+ ──────────── ────── ───── ──── ────────────────
234
+ abc123def456 done 3 0.01 总结 README.md …
235
+ $ lithe undo abc123def456
236
+ ✓ 已撤销 2 个操作(run abc123def456)
237
+ ```
238
+
239
+ A file the run created is deleted; a file it overwrote is restored.
240
+ (`run_code` side effects are not revertible — its tool description warns
241
+ the model.)
242
+
243
+ ### Inspect
244
+
245
+ ```bash
246
+ $ lithe runs # stored runs (newest last)
247
+ $ lithe sessions # stored conversations (newest first)
248
+ $ lithe log abc123def456 # messages + actions of one run
249
+ $ lithe models # what the endpoint offers (cached)
250
+ $ lithe doctor # config + capability status
251
+ ```
252
+
253
+ ### Tools
254
+
255
+ ```bash
256
+ $ lithe tools # what the agent can do
257
+ tool category description
258
+ ──────────── ──────── ──────────────────────────────
259
+ apply_patch WRITE 以行级 patch 一次修改多个文件…
260
+ read_file READ 读取文件内容…
261
+ ...
262
+ ```
263
+
264
+ The default tool set is the workspace bundle (`read_file` / `write_file` /
265
+ `edit_file` / `list_files` / `search_files` / `glob_files` /
266
+ `apply_patch`) plus todos (`update_todos` / `list_todos`); the flags above
267
+ add capabilities. (MCP tools attach at run time, so `lithe tools` lists
268
+ them only after a session has started the servers.)
269
+
270
+ ### Colors
271
+
272
+ Output is colored when stdout is a TTY and `NO_COLOR` is unset; `--color`
273
+ / `--no-color` force either way. Output rendering itself stays
274
+ dependency-free — plain text degrades cleanly through pipes and cron.
275
+ Interactive *input* (the chat prompt and the setup wizard) is
276
+ [prompt_toolkit](https://python-prompt-toolkit.readthedocs.io/):
277
+ wide-character-safe editing, bracketed-paste handling, star-echoed API
278
+ keys, inline wizard validation, and persistent history.
279
+
280
+ ## Where things land
281
+
282
+ | Path | Contents |
283
+ | --- | --- |
284
+ | current dir (or `--workspace`) | the agent's sandboxed workspace — every tool path resolves strictly inside it |
285
+ | `~/.lithe/config.json` (or `LITHE_HOME`) | endpoint profiles: `{version, active, profiles}` (0600 — it holds keys) |
286
+ | `~/.lithe/runs` (or `--store`) | JSONL run store: conversations, runs, messages, actions, undo records |
287
+ | `~/.lithe/runs/todos-<scope-hash>.json` | the agent's task list, isolated by user and resolved workspace |
288
+ | `~/.lithe/skills` (or `--skills`) | the markdown skill library, when enabled |
289
+ | `~/.lithe/history` | chat input history (prompt_toolkit `FileHistory`; `↑`/`↓` recall in the TUI, Ctrl+R search in the plain REPL) |
290
+
291
+ ## Design notes
292
+
293
+ - The CLI is a thin host over a `Workbench`: the workbench owns the
294
+ endpoint view (profile + model), the session manager and the running
295
+ turns; the plain REPL and the full-screen Textual app are both just
296
+ subscribers to its event bus and callers of one dispatcher. Everything
297
+ else (ReAct loop, streaming, budgets, replay, undo engine) is reused
298
+ from lithe.
299
+ - The Textual screen is tested headlessly with `App.run_test()` pilots
300
+ (turns, F2/F3/F4, history, completion) — real interaction tests that
301
+ also run on Windows; its pure builders (sidebar/header/footer markup,
302
+ completion suggestions) and the shared `TuiState` event folding have
303
+ direct unit tests.
304
+ - `python -m lithe_cli` works alongside the `lithe` console script.
305
+
306
+ ## License
307
+
308
+ MIT
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.1.1"