lithe-cli 0.6.7__tar.gz → 0.8.0__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 (32) hide show
  1. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/PKG-INFO +95 -50
  2. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/README.md +92 -48
  3. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/__init__.py +1 -1
  4. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/agent.py +11 -7
  5. lithe_cli-0.8.0/lithe_cli/commands.py +58 -0
  6. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/config.py +41 -31
  7. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/main.py +282 -47
  8. lithe_cli-0.8.0/lithe_cli/profiles.py +247 -0
  9. lithe_cli-0.8.0/lithe_cli/sessions.py +154 -0
  10. lithe_cli-0.8.0/lithe_cli/ttui.py +776 -0
  11. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/tui.py +587 -84
  12. lithe_cli-0.8.0/lithe_cli/workbench.py +494 -0
  13. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli.egg-info/PKG-INFO +95 -50
  14. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli.egg-info/SOURCES.txt +11 -1
  15. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli.egg-info/requires.txt +2 -1
  16. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/pyproject.toml +1 -1
  17. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/tests/test_cli.py +1 -1
  18. lithe_cli-0.8.0/tests/test_cli_sessions.py +192 -0
  19. lithe_cli-0.8.0/tests/test_profiles.py +208 -0
  20. lithe_cli-0.8.0/tests/test_ttui.py +308 -0
  21. lithe_cli-0.8.0/tests/test_tui_v2.py +199 -0
  22. lithe_cli-0.8.0/tests/test_workbench.py +273 -0
  23. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/LICENSE +0 -0
  24. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/__main__.py +0 -0
  25. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/prompts.py +0 -0
  26. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/py.typed +0 -0
  27. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/setup.py +0 -0
  28. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli/ui.py +0 -0
  29. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli.egg-info/dependency_links.txt +0 -0
  30. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli.egg-info/entry_points.txt +0 -0
  31. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/lithe_cli.egg-info/top_level.txt +0 -0
  32. {lithe_cli-0.6.7 → lithe_cli-0.8.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.6.7
3
+ Version: 0.8.0
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.14
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,28 @@ 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
+ "openrouter": {"base_url": "https://…", "api_key": "…", "model": "…"}
86
+ }
87
+ }
88
+ ```
89
+
90
+ ```bash
91
+ lithe config # wizard (edits the active profile)
92
+ lithe config --list # profiles, key masked
93
+ lithe config --use openrouter # switch active profile (script-friendly)
94
+ lithe config --model glm-4.5 # set the active profile's default model
95
+ lithe models # GET {base_url}/models, cached into the profile
96
+ ```
97
+
75
98
  To configure by hand instead, point the CLI at any OpenAI-compatible
76
99
  endpoint:
77
100
 
@@ -82,10 +105,11 @@ export LITHE_MODEL=your-model
82
105
  ```
83
106
 
84
107
  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.
108
+ environment > the selected profile's fields, per key; `--profile NAME`
109
+ (or `LITHE_PROFILE`) selects a profile for one invocation. The wizard
110
+ never runs without a TTY on both ends, so pipes and CI keep the hard
111
+ refusal; `--no-setup` restores that fail-fast behavior on terminals
112
+ too. `lithe config --show` peeks at the saved values with a masked key.
89
113
 
90
114
  `LITHE_HOME` (default `~/.lithe`) locates the run store; the agent's
91
115
  workspace defaults to the current directory (`--workspace` to change).
@@ -118,50 +142,63 @@ usage/context gauges; `--max-steps` caps the tool loop;
118
142
  ### Full-screen interface
119
143
 
120
144
  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:
145
+ persistent full-screen interface (built on [Textual](https://textual.textualize.io))
146
+ instead of scribbling one-line events into the console. The left pane is
147
+ the conversation; the right sidebar is five fixed sections — 会话(current
148
+ + recent ones, `●` marks sessions with a turn still running)、模型、运行、
149
+ 工具/待办、用量:
123
150
 
124
151
  ```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 命令
152
+ lithe 0.8.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
153
+ ╭──────────────────────────────────────╮╭──────────────────────────╮
154
+ │ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
155
+ │ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
156
+ │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ #11 bugfix ✓ 7轮 │
157
+ │ 已完成。 ││ F3 切换 · /new 新建 │
158
+ │ ││ ◆ 模型 │
159
+ │ ││ zhipu · glm-4.6 │
160
+ │ ││ ◆ 会话用量 │
161
+ │ ││ 输入 1,024 · 输出 216 │
162
+ ╰──────────────────────────────────────╯╰──────────────────────────╯
163
+ Tab 采纳 → /model /models /new
164
+ lithe ❯ _
165
+ ● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · /help
141
166
  ```
142
167
 
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
168
+ **Switch without leaving the screen**: `F3` opens the session picker
169
+ (`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
170
+ (grouped by profile; `Enter` switch, `s` save as the profile's default,
171
+ `r` fetch `/models`). Switching away from a running session does **not**
172
+ cancel it — its badge stays lit and the pane rebuilds from the store when
173
+ you come back. Typing `/` shows matching commands above the prompt (`Tab`
174
+ accepts; `/model`, `/profile`, `/resume` complete their arguments too),
175
+ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
176
+ current turn and exits when idle.
177
+
178
+ Text selection uses the terminal's native `Shift+drag` (hide the sidebar
179
+ with F2 first if it grabs both panes). The earlier prompt_toolkit screen —
180
+ which adds in-app mouse selection and OSC 52 copy — remains available with
181
+ `--ui prompt` / `LITHE_UI=prompt`. Pipes and CI keep the plain per-line
159
182
  output unchanged.
160
183
 
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.
184
+ ### Sessions
185
+
186
+ Every chat conversation persists as a kernel conversation (one run per
187
+ turn, messages written incrementally):
188
+
189
+ ```bash
190
+ lithe chat -c # continue the most recent session
191
+ lithe chat --resume 12 # by id (or unique title prefix)
192
+ lithe sessions # list; newest activity first
193
+ lithe sessions --rename 12 规划 # rename
194
+ lithe sessions --delete 12 # soft delete (runs stay: log/undo work)
195
+ ```
196
+
197
+ A session remembers its last profile and model and restores them on
198
+ resume (unless `--model`/env pinned). Inside chat, the same operations
199
+ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
200
+ `/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
201
+ `/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
165
202
 
166
203
  ### Extra capabilities
167
204
 
@@ -204,7 +241,9 @@ the model.)
204
241
 
205
242
  ```bash
206
243
  $ lithe runs # stored runs (newest last)
244
+ $ lithe sessions # stored conversations (newest first)
207
245
  $ lithe log abc123def456 # messages + actions of one run
246
+ $ lithe models # what the endpoint offers (cached)
208
247
  $ lithe doctor # config + capability status
209
248
  ```
210
249
 
@@ -240,18 +279,24 @@ keys, inline wizard validation, and persistent history.
240
279
  | Path | Contents |
241
280
  | --- | --- |
242
281
  | 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 |
282
+ | `~/.lithe/config.json` (or `LITHE_HOME`) | endpoint profiles: `{version, active, profiles}` (0600 — it holds keys) |
283
+ | `~/.lithe/runs` (or `--store`) | JSONL run store: conversations, runs, messages, actions, undo records |
244
284
  | `~/.lithe/runs/todos-<scope-hash>.json` | the agent's task list, isolated by user and resolved workspace |
245
285
  | `~/.lithe/skills` (or `--skills`) | the markdown skill library, when enabled |
246
286
  | `~/.lithe/history` | chat input history (prompt_toolkit `FileHistory`; Up/Ctrl+R recall) |
247
287
 
248
288
  ## Design notes
249
289
 
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.
290
+ - The CLI is a thin host over a `Workbench`: the workbench owns the
291
+ endpoint view (profile + model), the session manager and the running
292
+ turns; the plain REPL and the full-screen Textual app are both just
293
+ subscribers to its event bus and callers of one dispatcher. Everything
294
+ else (ReAct loop, streaming, budgets, replay, undo engine) is reused
295
+ from lithe.
296
+ - The Textual screen is tested headlessly with `App.run_test()` pilots
297
+ (turns, F2/F3/F4, history, completion) — real interaction tests that
298
+ also run on Windows; the legacy prompt_toolkit screen keeps its pure
299
+ row-builder tests plus POSIX-only PTY tests.
255
300
  - `python -m lithe_cli` works alongside the `lithe` console script.
256
301
 
257
302
  ## License
@@ -24,6 +24,28 @@ interactive terminal prompts for the three essentials and saves them to
24
24
  `$LITHE_HOME/config.json` (mode 0600 — it holds the key). An optional
25
25
  connectivity probe catches typos before your first turn.
26
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
+ "openrouter": {"base_url": "https://…", "api_key": "…", "model": "…"}
37
+ }
38
+ }
39
+ ```
40
+
41
+ ```bash
42
+ lithe config # wizard (edits the active profile)
43
+ lithe config --list # profiles, key masked
44
+ lithe config --use openrouter # switch active profile (script-friendly)
45
+ lithe config --model glm-4.5 # set the active profile's default model
46
+ lithe models # GET {base_url}/models, cached into the profile
47
+ ```
48
+
27
49
  To configure by hand instead, point the CLI at any OpenAI-compatible
28
50
  endpoint:
29
51
 
@@ -34,10 +56,11 @@ export LITHE_MODEL=your-model
34
56
  ```
35
57
 
36
58
  Resolution order is flag (`--api-key`, `--base-url`, `--model`) >
37
- environment > saved config file, per key. The wizard never runs without
38
- a TTY on both ends, so pipes and CI keep the hard refusal; `--no-setup`
39
- restores that fail-fast behavior on terminals too. `lithe config --show`
40
- peeks at the saved values with a masked key.
59
+ environment > the selected profile's fields, per key; `--profile NAME`
60
+ (or `LITHE_PROFILE`) selects a profile for one invocation. The wizard
61
+ never runs without a TTY on both ends, so pipes and CI keep the hard
62
+ refusal; `--no-setup` restores that fail-fast behavior on terminals
63
+ too. `lithe config --show` peeks at the saved values with a masked key.
41
64
 
42
65
  `LITHE_HOME` (default `~/.lithe`) locates the run store; the agent's
43
66
  workspace defaults to the current directory (`--workspace` to change).
@@ -70,50 +93,63 @@ usage/context gauges; `--max-steps` caps the tool loop;
70
93
  ### Full-screen interface
71
94
 
72
95
  On an interactive terminal, `lithe chat` and `lithe run TASK` open a
73
- persistent full-screen interface instead of scribbling one-line events
74
- into the console:
96
+ persistent full-screen interface (built on [Textual](https://textual.textualize.io))
97
+ instead of scribbling one-line events into the console. The left pane is
98
+ the conversation; the right sidebar is five fixed sections — 会话(current
99
+ + recent ones, `●` marks sessions with a turn still running)、模型、运行、
100
+ 工具/待办、用量:
75
101
 
76
102
  ```text
77
- lithe 0.6.2 · your-model · /home/me/my-project ● 完成 · 0.2s
78
- ╭─ 对话 ──────────────────────────────╮╭─ 运行状态 ─────────╮
79
- │ 把 a.txt 改成三行待办清单 ││ ● 完成 · 0.2s │
80
- │ ◆ update_todos ││ 步骤 2/35 · 0.2s │
81
- │ ✓ 任务清单已更新(3 条) 0.0s ││ ✓ update_todos 0.0s│
82
- │ ◆ edit_file · 局部修改 a.txt ││ ✓ edit_file 0.0s │
83
- │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ ◆ 待办 1/3 │
84
- │ 已完成。 ││ [~] 修改 a.txt │
85
- │ ││ ◆ 会话用量 │
86
- │ ││ 输入 1,024 · 输出 216│
87
- │ ││ 缓存输入 768 │
88
- │ ││ 合计 1,240 · $0.0021│
89
- │ ││ 上下文 1,024 / 128,000 (0.8%)│
90
- ╰─────────────────────────────────────╯╰────────────────────╯
91
- lithe ❯ _
92
- ● 完成 · 0.2s Enter 发送 · F2 侧栏 · /help 命令
103
+ lithe 0.8.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
104
+ ╭──────────────────────────────────────╮╭──────────────────────────╮
105
+ │ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
106
+ │ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
107
+ │ ✓ 编辑 a.txt(+3 -1 行) 0.0s ││ #11 bugfix ✓ 7轮 │
108
+ │ 已完成。 ││ F3 切换 · /new 新建 │
109
+ │ ││ ◆ 模型 │
110
+ │ ││ zhipu · glm-4.6 │
111
+ │ ││ ◆ 会话用量 │
112
+ │ ││ 输入 1,024 · 输出 216 │
113
+ ╰──────────────────────────────────────╯╰──────────────────────────╯
114
+ Tab 采纳 → /model /models /new
115
+ lithe ❯ _
116
+ ● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · /help
93
117
  ```
94
118
 
95
- The left pane is the conversation (task, compact tool-call summaries
96
- and outcomes — file edits land with `+N -M 行` counts — and the
97
- streaming assistant reply). The right sidebar shows run status, recent
98
- tools, todos, session-wide cumulative input/output/cached tokens and
99
- cost, plus the latest model-call context length and window percentage;
100
- usage numbers live only there, the bottom bar keeps status and key
101
- hints. The conversation has an application-managed mouse selection: drag across
102
- its text and press `Ctrl+C` to copy only the selected conversation, without
103
- sidebar content. `Shift+drag` bypasses the application and uses the terminal's
104
- native selection, which can cross both panes; hide the sidebar with F2 or
105
- `/sidebar` before using native selection. The conversation scrolls with the
106
- mouse wheel, PageUp/PageDown and Home/End (a new turn jumps back to the output).
107
- `Ctrl+C` cancels the current turn when there is no conversation selection and
108
- exits when idle. In `lithe run` mode the result stays on screen until you press
109
- `q`. Layout, wrapping and alignment are East-Asian-width aware; narrower
110
- terminals stack the two panes vertically. Pipes and CI keep the plain per-line
119
+ **Switch without leaving the screen**: `F3` opens the session picker
120
+ (`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
121
+ (grouped by profile; `Enter` switch, `s` save as the profile's default,
122
+ `r` fetch `/models`). Switching away from a running session does **not**
123
+ cancel it — its badge stays lit and the pane rebuilds from the store when
124
+ you come back. Typing `/` shows matching commands above the prompt (`Tab`
125
+ accepts; `/model`, `/profile`, `/resume` complete their arguments too),
126
+ and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
127
+ current turn and exits when idle.
128
+
129
+ Text selection uses the terminal's native `Shift+drag` (hide the sidebar
130
+ with F2 first if it grabs both panes). The earlier prompt_toolkit screen —
131
+ which adds in-app mouse selection and OSC 52 copy — remains available with
132
+ `--ui prompt` / `LITHE_UI=prompt`. Pipes and CI keep the plain per-line
111
133
  output unchanged.
112
134
 
113
- History carries across turns within a session (each turn is its own run
114
- in the store, replayed as context for the next). `/new` clears the
115
- conversation history and session usage totals; `/tools` lists the
116
- registered tools, `/help` lists the commands.
135
+ ### Sessions
136
+
137
+ Every chat conversation persists as a kernel conversation (one run per
138
+ turn, messages written incrementally):
139
+
140
+ ```bash
141
+ lithe chat -c # continue the most recent session
142
+ lithe chat --resume 12 # by id (or unique title prefix)
143
+ lithe sessions # list; newest activity first
144
+ lithe sessions --rename 12 规划 # rename
145
+ lithe sessions --delete 12 # soft delete (runs stay: log/undo work)
146
+ ```
147
+
148
+ A session remembers its last profile and model and restores them on
149
+ resume (unless `--model`/env pinned). Inside chat, the same operations
150
+ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
151
+ `/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
152
+ `/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
117
153
 
118
154
  ### Extra capabilities
119
155
 
@@ -156,7 +192,9 @@ the model.)
156
192
 
157
193
  ```bash
158
194
  $ lithe runs # stored runs (newest last)
195
+ $ lithe sessions # stored conversations (newest first)
159
196
  $ lithe log abc123def456 # messages + actions of one run
197
+ $ lithe models # what the endpoint offers (cached)
160
198
  $ lithe doctor # config + capability status
161
199
  ```
162
200
 
@@ -192,18 +230,24 @@ keys, inline wizard validation, and persistent history.
192
230
  | Path | Contents |
193
231
  | --- | --- |
194
232
  | current dir (or `--workspace`) | the agent's sandboxed workspace — every tool path resolves strictly inside it |
195
- | `~/.lithe/runs` (or `--store`) | JSONL run store: messages, actions, undo records |
233
+ | `~/.lithe/config.json` (or `LITHE_HOME`) | endpoint profiles: `{version, active, profiles}` (0600 — it holds keys) |
234
+ | `~/.lithe/runs` (or `--store`) | JSONL run store: conversations, runs, messages, actions, undo records |
196
235
  | `~/.lithe/runs/todos-<scope-hash>.json` | the agent's task list, isolated by user and resolved workspace |
197
236
  | `~/.lithe/skills` (or `--skills`) | the markdown skill library, when enabled |
198
237
  | `~/.lithe/history` | chat input history (prompt_toolkit `FileHistory`; Up/Ctrl+R recall) |
199
238
 
200
239
  ## Design notes
201
240
 
202
- - The CLI is a thin host: it supplies tools, a system prompt, and the
203
- kernel's `JsonlRunStore`; everything else (ReAct loop, streaming, budgets,
204
- replay, undo engine) is reused from lithe.
205
- - End-to-end behavior is tested offline against a scripted transport — no
206
- test spends tokens.
241
+ - The CLI is a thin host over a `Workbench`: the workbench owns the
242
+ endpoint view (profile + model), the session manager and the running
243
+ turns; the plain REPL and the full-screen Textual app are both just
244
+ subscribers to its event bus and callers of one dispatcher. Everything
245
+ else (ReAct loop, streaming, budgets, replay, undo engine) is reused
246
+ from lithe.
247
+ - The Textual screen is tested headlessly with `App.run_test()` pilots
248
+ (turns, F2/F3/F4, history, completion) — real interaction tests that
249
+ also run on Windows; the legacy prompt_toolkit screen keeps its pure
250
+ row-builder tests plus POSIX-only PTY tests.
207
251
  - `python -m lithe_cli` works alongside the `lithe` console script.
208
252
 
209
253
  ## License
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.6.7"
3
+ __version__ = "0.8.0"
@@ -207,6 +207,7 @@ async def execute(
207
207
  run_id: str | None = None,
208
208
  on_event=None,
209
209
  stop=None,
210
+ conversation_id: int | None = None,
210
211
  ) -> tuple[str, dict, Any]:
211
212
  """Run one task end-to-end; returns (run_id, done_event, host).
212
213
 
@@ -214,12 +215,14 @@ async def execute(
214
215
  event and silences the line-oriented printing below, including the
215
216
  footer — the caller renders from the events instead. ``stop`` is the
216
217
  kernel's cancellation handle, surfaced so Ctrl+C can cancel a turn
217
- without killing the process.
218
+ without killing the process. ``conversation_id`` attaches the run to a
219
+ stored session (kernel host already consumes ctx.extra).
218
220
  """
219
221
  reg = build_registry(cfg)
220
222
  host = build_host(cfg, reg)
221
223
  rid = run_id or uuid.uuid4().hex[:12]
222
- ctx = AgentContext(run_id=rid, user_id=cfg.user_id)
224
+ extra = {"conversation_id": conversation_id} if conversation_id is not None else {}
225
+ ctx = AgentContext(run_id=rid, user_id=cfg.user_id, extra=extra)
223
226
  manager = None
224
227
  if cfg.mcp_servers:
225
228
  from lithe.bundles.mcp import MCPManager
@@ -253,11 +256,12 @@ async def execute(
253
256
  return rid, ev, host
254
257
 
255
258
 
256
- async def undo(cfg: Config, run_id: str) -> int:
257
- """Revert a run's mutations with the bundled tools' reverters."""
259
+ async def undo(cfg: Config, run_id: str, quiet: bool = False) -> int:
260
+ """Revert a run's mutations; returns how many actions were reverted."""
258
261
  reg = build_registry(cfg)
259
262
  host = build_host(cfg, reg)
260
263
  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
264
+ if not quiet:
265
+ mark = ui.s("✓", GREEN) if report.reverted else ui.s("·", YELLOW)
266
+ print(f"{mark} 已撤销 {report.reverted} 个操作(run {run_id})")
267
+ return report.reverted
@@ -0,0 +1,58 @@
1
+ """Slash commands: one registry, two frontends.
2
+
3
+ ``Workbench.dispatch`` returns an :class:`ActionResult`; the plain REPL prints
4
+ ``messages`` and runs ``awaitable`` synchronously, the TUI prints the same
5
+ messages into the conversation feed, opens ``overlay`` pickers and schedules
6
+ the awaitable as a task. Help text and completion words come from
7
+ :data:`COMMANDS`, so the two frontends can never drift apart.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from dataclasses import dataclass, field
13
+ from typing import Any
14
+ from collections.abc import Callable
15
+
16
+ # name → (args hint, one-line description); order is the help order.
17
+ COMMANDS: dict[str, tuple[str, str]] = {
18
+ "help": ("", "显示这条帮助"),
19
+ "new": ("[标题]", "开始新会话(当前会话保留,可随时 /resume 回来)"),
20
+ "sessions": ("", "列出会话(F3 同效)"),
21
+ "resume": ("[编号|标题]", "切换会话;不带参数等同 /sessions"),
22
+ "rename": ("标题", "重命名当前会话"),
23
+ "model": ("[名称|--save]", "查看/切换模型(F4 同效);--save 同时存为档案默认"),
24
+ "models": ("", "从端点拉取模型列表并缓存"),
25
+ "profile": ("[名称]", "查看/切换 provider 档案"),
26
+ "tools": ("", "列出已注册的工具"),
27
+ "undo": ("[run]", "撤销当前会话最近一轮(或指定 run)的文件改动"),
28
+ "sidebar": ("", "显示/隐藏右侧状态栏(F2 同效)"),
29
+ "exit": ("", "退出(等同 /quit)"),
30
+ }
31
+
32
+
33
+ def help_text() -> list[tuple[str, str]]:
34
+ lines = ["可用命令:"]
35
+ width = max(len(name) for name in COMMANDS)
36
+ for name, (args, desc) in COMMANDS.items():
37
+ lines.append(f" /{name:<{width}} {args:<12} {desc}")
38
+ lines.append("")
39
+ lines.append("会话内随时可切模型/切会话,下一轮生效;运行中的轮次不受影响。")
40
+ return [("dim", ln) for ln in lines]
41
+
42
+
43
+ @dataclass
44
+ class ActionResult:
45
+ """What a dispatched line means to the calling frontend."""
46
+
47
+ action: str = "none" # none | submit | exit
48
+ text: str = "" # submit payload
49
+ messages: list[tuple[str, str]] = field(default_factory=list)
50
+ overlay: str | None = None # TUI picker: "sessions" | "model"
51
+ toggle_sidebar: bool = False
52
+ changed: bool = False # model/session changed → refresh banner/sidebar
53
+ # Zero-arg coroutine the frontend must run: plain → asyncio.run,
54
+ # TUI → create_task (so /models fetches never block the screen).
55
+ awaitable: Callable[[], Any] | None = None
56
+
57
+ def say(self, cls: str, text: str) -> None:
58
+ self.messages.append((cls, text))