lithe-cli 0.9.4__tar.gz → 0.10.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.
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/PKG-INFO +39 -15
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/README.md +37 -13
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/agent.py +205 -15
- lithe_cli-0.10.0/lithe_cli/cli_parser.py +196 -0
- lithe_cli-0.10.0/lithe_cli/clipboard.py +123 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/commands.py +13 -3
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/config.py +38 -11
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/main.py +63 -228
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/profiles.py +164 -22
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/prompts.py +30 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/sessions.py +10 -3
- lithe_cli-0.10.0/lithe_cli/setup.py +190 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/ttui.py +551 -421
- lithe_cli-0.10.0/lithe_cli/ttui_render.py +134 -0
- lithe_cli-0.10.0/lithe_cli/ttui_widgets.py +652 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/tui.py +281 -2
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/ui.py +34 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/workbench.py +393 -54
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli.egg-info/PKG-INFO +39 -15
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli.egg-info/SOURCES.txt +6 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/pyproject.toml +1 -1
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_cli.py +88 -4
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_cli_budget_steer.py +14 -0
- lithe_cli-0.10.0/tests/test_cli_clipboard.py +179 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_cli_sessions.py +66 -0
- lithe_cli-0.10.0/tests/test_cli_subagents.py +341 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_profiles.py +180 -0
- lithe_cli-0.10.0/tests/test_setup.py +173 -0
- lithe_cli-0.10.0/tests/test_ttui.py +1108 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_tui_v2.py +86 -1
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_workbench.py +220 -0
- lithe_cli-0.9.4/lithe_cli/setup.py +0 -109
- lithe_cli-0.9.4/tests/test_cli_subagents.py +0 -135
- lithe_cli-0.9.4/tests/test_ttui.py +0 -515
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/LICENSE +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/setup.cfg +0 -0
- {lithe_cli-0.9.4 → lithe_cli-0.10.0}/tests/test_cli_guard.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.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,7 +39,7 @@ Classifier: Typing :: Typed
|
|
|
39
39
|
Requires-Python: >=3.10
|
|
40
40
|
Description-Content-Type: text/markdown
|
|
41
41
|
License-File: LICENSE
|
|
42
|
-
Requires-Dist: lithe>=0.9
|
|
42
|
+
Requires-Dist: lithe>=0.1.9
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -69,9 +69,14 @@ pip install lithe-cli
|
|
|
69
69
|
There is no default endpoint — the CLI refuses to run rather than silently
|
|
70
70
|
hitting some third-party URL. The easiest way in is the wizard: on the
|
|
71
71
|
first `lithe chat` / `lithe run` (or any time, via `lithe config`) an
|
|
72
|
-
interactive terminal
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
interactive terminal walks a **provider-first interview** — profile name,
|
|
73
|
+
provider type (Tab-completed: openai / anthropic / zai / deepseek /
|
|
74
|
+
openrouter / qwen / moonshot, or `none` for a hand-written endpoint),
|
|
75
|
+
base_url (defaults to the preset's official URL — override it to point a
|
|
76
|
+
provider's format at your own router), API key, model — and saves them
|
|
77
|
+
to `$LITHE_HOME/config.json` (mode 0600 — it holds the key). An optional
|
|
78
|
+
connectivity probe catches typos before your first turn, using the
|
|
79
|
+
provider's own auth (`x-api-key` for messages endpoints).
|
|
75
80
|
|
|
76
81
|
The config file holds **named profiles** — several endpoints, one active:
|
|
77
82
|
|
|
@@ -91,19 +96,30 @@ A profile may set `"provider"` instead of (or alongside) `base_url`: the
|
|
|
91
96
|
vendor preset from `lithe.bundles.providers` fills `base_url` when unset
|
|
92
97
|
and contributes `LLMConfig` defaults (transport, `extra_body`,
|
|
93
98
|
`default_headers`) **under** your explicit values — you write the key and
|
|
94
|
-
model, the preset knows the endpoint shape. `
|
|
95
|
-
profile field; `config --list` / `--show`
|
|
96
|
-
|
|
97
|
-
qwen / moonshot).
|
|
99
|
+
model, the preset knows the endpoint shape. `--provider` /
|
|
100
|
+
`LITHE_PROVIDER` override the profile field; `config --list` / `--show`
|
|
101
|
+
display it; an unknown name fails loudly with the available presets
|
|
102
|
+
(openai / anthropic / zai / deepseek / openrouter / qwen / moonshot).
|
|
98
103
|
|
|
99
104
|
```bash
|
|
100
|
-
lithe config # wizard (edits
|
|
105
|
+
lithe config # provider-first wizard (edits a named profile)
|
|
101
106
|
lithe config --list # profiles, key masked
|
|
102
107
|
lithe config --use openrouter # switch active profile (script-friendly)
|
|
103
108
|
lithe config --model glm-4.5 # set the active profile's default model
|
|
109
|
+
lithe config --provider anthropic # set the active profile's preset
|
|
110
|
+
# (none/off clears)
|
|
104
111
|
lithe models # GET {base_url}/models, cached into the profile
|
|
105
112
|
```
|
|
106
113
|
|
|
114
|
+
A one-shot provider for a single invocation pairs the flag with an
|
|
115
|
+
explicit `--base-url` — the custom-router form without touching the
|
|
116
|
+
config file:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
lithe run --provider openrouter --base-url https://my-router/api/v1 \
|
|
120
|
+
--api-key sk-... --model vendor/claude-sonnet-4 "task"
|
|
121
|
+
```
|
|
122
|
+
|
|
107
123
|
To configure by hand instead, point the CLI at any OpenAI-compatible
|
|
108
124
|
endpoint:
|
|
109
125
|
|
|
@@ -142,7 +158,7 @@ $ lithe run "总结 README.md 的要点,存到 SUMMARY.md"
|
|
|
142
158
|
── done · steps 3 · tokens 2100 · cost 0.0042
|
|
143
159
|
```
|
|
144
160
|
|
|
145
|
-
修改已有文件时,助手优先调用 `edit_file` 或 `apply_patch` 做局部更新;只有新建文件或需要整体替换时才使用 `write_file`。工具调用界面只显示工具名、文件路径等摘要,文件写入/编辑的结果带 `+N -M 行` 的行数变化提示(lithe 0.
|
|
161
|
+
修改已有文件时,助手优先调用 `edit_file` 或 `apply_patch` 做局部更新;只有新建文件或需要整体替换时才使用 `write_file`。工具调用界面只显示工具名、文件路径等摘要,文件写入/编辑的结果带 `+N -M 行` 的行数变化提示(lithe 0.1.0 起由内核统计)。
|
|
146
162
|
|
|
147
163
|
`--stream` streams tokens as they generate; `-v` adds per-call
|
|
148
164
|
usage/context gauges; `--max-steps` caps the tool loop;
|
|
@@ -165,7 +181,7 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
165
181
|
工具/待办、用量:
|
|
166
182
|
|
|
167
183
|
```text
|
|
168
|
-
lithe 0.
|
|
184
|
+
lithe 0.10.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
|
|
169
185
|
╭──────────────────────────────────────╮╭──────────────────────────╮
|
|
170
186
|
│ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
|
|
171
187
|
│ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
|
|
@@ -173,19 +189,27 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
173
189
|
│ 已完成。 ││ F3 切换 · /new 新建 │
|
|
174
190
|
│ ││ ◆ 模型 │
|
|
175
191
|
│ ││ zhipu · glm-4.6 │
|
|
192
|
+
│ ││ zai · chat · F7 端点 │
|
|
176
193
|
│ ││ ◆ 会话用量 │
|
|
177
194
|
│ ││ 输入 1,024 · 输出 216 │
|
|
178
195
|
╰──────────────────────────────────────╯╰──────────────────────────╯
|
|
179
196
|
Tab 采纳 → /model /models /new
|
|
180
197
|
lithe ❯ _
|
|
181
|
-
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · F6 推理 · /help
|
|
198
|
+
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · F6 推理 · F7 端点 · /help
|
|
182
199
|
```
|
|
183
200
|
|
|
184
201
|
**Switch without leaving the screen**: `F3` opens the session picker
|
|
185
202
|
(`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
|
|
186
203
|
(grouped by profile; `Enter` switch, `s` save as the profile's default,
|
|
187
|
-
`r` fetch `/models`),
|
|
188
|
-
capability; see below)
|
|
204
|
+
`r` fetch `/models`), `F5` the settings picker (`Enter` toggles a
|
|
205
|
+
capability; see below), and `F7` the **endpoint manager** — every saved
|
|
206
|
+
profile with its `provider · transport` dialect, base_url and masked
|
|
207
|
+
key; `Enter` switches, `n` creates a profile right in the form (provider
|
|
208
|
+
type cycled with Enter, base_url defaulting to each preset's official
|
|
209
|
+
URL — overridable for custom routers, star-echoed API key), `e` edits
|
|
210
|
+
one, `p` swaps its provider type. A profile created in the form is
|
|
211
|
+
switched to on save; edits to the current profile apply to the next
|
|
212
|
+
turn. Switching away from a running session does **not**
|
|
189
213
|
cancel it — its badge stays lit and the pane rebuilds from the store when
|
|
190
214
|
you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
191
215
|
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
@@ -20,9 +20,14 @@ pip install lithe-cli
|
|
|
20
20
|
There is no default endpoint — the CLI refuses to run rather than silently
|
|
21
21
|
hitting some third-party URL. The easiest way in is the wizard: on the
|
|
22
22
|
first `lithe chat` / `lithe run` (or any time, via `lithe config`) an
|
|
23
|
-
interactive terminal
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
interactive terminal walks a **provider-first interview** — profile name,
|
|
24
|
+
provider type (Tab-completed: openai / anthropic / zai / deepseek /
|
|
25
|
+
openrouter / qwen / moonshot, or `none` for a hand-written endpoint),
|
|
26
|
+
base_url (defaults to the preset's official URL — override it to point a
|
|
27
|
+
provider's format at your own router), API key, model — and saves them
|
|
28
|
+
to `$LITHE_HOME/config.json` (mode 0600 — it holds the key). An optional
|
|
29
|
+
connectivity probe catches typos before your first turn, using the
|
|
30
|
+
provider's own auth (`x-api-key` for messages endpoints).
|
|
26
31
|
|
|
27
32
|
The config file holds **named profiles** — several endpoints, one active:
|
|
28
33
|
|
|
@@ -42,19 +47,30 @@ A profile may set `"provider"` instead of (or alongside) `base_url`: the
|
|
|
42
47
|
vendor preset from `lithe.bundles.providers` fills `base_url` when unset
|
|
43
48
|
and contributes `LLMConfig` defaults (transport, `extra_body`,
|
|
44
49
|
`default_headers`) **under** your explicit values — you write the key and
|
|
45
|
-
model, the preset knows the endpoint shape. `
|
|
46
|
-
profile field; `config --list` / `--show`
|
|
47
|
-
|
|
48
|
-
qwen / moonshot).
|
|
50
|
+
model, the preset knows the endpoint shape. `--provider` /
|
|
51
|
+
`LITHE_PROVIDER` override the profile field; `config --list` / `--show`
|
|
52
|
+
display it; an unknown name fails loudly with the available presets
|
|
53
|
+
(openai / anthropic / zai / deepseek / openrouter / qwen / moonshot).
|
|
49
54
|
|
|
50
55
|
```bash
|
|
51
|
-
lithe config # wizard (edits
|
|
56
|
+
lithe config # provider-first wizard (edits a named profile)
|
|
52
57
|
lithe config --list # profiles, key masked
|
|
53
58
|
lithe config --use openrouter # switch active profile (script-friendly)
|
|
54
59
|
lithe config --model glm-4.5 # set the active profile's default model
|
|
60
|
+
lithe config --provider anthropic # set the active profile's preset
|
|
61
|
+
# (none/off clears)
|
|
55
62
|
lithe models # GET {base_url}/models, cached into the profile
|
|
56
63
|
```
|
|
57
64
|
|
|
65
|
+
A one-shot provider for a single invocation pairs the flag with an
|
|
66
|
+
explicit `--base-url` — the custom-router form without touching the
|
|
67
|
+
config file:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
lithe run --provider openrouter --base-url https://my-router/api/v1 \
|
|
71
|
+
--api-key sk-... --model vendor/claude-sonnet-4 "task"
|
|
72
|
+
```
|
|
73
|
+
|
|
58
74
|
To configure by hand instead, point the CLI at any OpenAI-compatible
|
|
59
75
|
endpoint:
|
|
60
76
|
|
|
@@ -93,7 +109,7 @@ $ lithe run "总结 README.md 的要点,存到 SUMMARY.md"
|
|
|
93
109
|
── done · steps 3 · tokens 2100 · cost 0.0042
|
|
94
110
|
```
|
|
95
111
|
|
|
96
|
-
修改已有文件时,助手优先调用 `edit_file` 或 `apply_patch` 做局部更新;只有新建文件或需要整体替换时才使用 `write_file`。工具调用界面只显示工具名、文件路径等摘要,文件写入/编辑的结果带 `+N -M 行` 的行数变化提示(lithe 0.
|
|
112
|
+
修改已有文件时,助手优先调用 `edit_file` 或 `apply_patch` 做局部更新;只有新建文件或需要整体替换时才使用 `write_file`。工具调用界面只显示工具名、文件路径等摘要,文件写入/编辑的结果带 `+N -M 行` 的行数变化提示(lithe 0.1.0 起由内核统计)。
|
|
97
113
|
|
|
98
114
|
`--stream` streams tokens as they generate; `-v` adds per-call
|
|
99
115
|
usage/context gauges; `--max-steps` caps the tool loop;
|
|
@@ -116,7 +132,7 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
116
132
|
工具/待办、用量:
|
|
117
133
|
|
|
118
134
|
```text
|
|
119
|
-
lithe 0.
|
|
135
|
+
lithe 0.10.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
|
|
120
136
|
╭──────────────────────────────────────╮╭──────────────────────────╮
|
|
121
137
|
│ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
|
|
122
138
|
│ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
|
|
@@ -124,19 +140,27 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
124
140
|
│ 已完成。 ││ F3 切换 · /new 新建 │
|
|
125
141
|
│ ││ ◆ 模型 │
|
|
126
142
|
│ ││ zhipu · glm-4.6 │
|
|
143
|
+
│ ││ zai · chat · F7 端点 │
|
|
127
144
|
│ ││ ◆ 会话用量 │
|
|
128
145
|
│ ││ 输入 1,024 · 输出 216 │
|
|
129
146
|
╰──────────────────────────────────────╯╰──────────────────────────╯
|
|
130
147
|
Tab 采纳 → /model /models /new
|
|
131
148
|
lithe ❯ _
|
|
132
|
-
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · F6 推理 · /help
|
|
149
|
+
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · F6 推理 · F7 端点 · /help
|
|
133
150
|
```
|
|
134
151
|
|
|
135
152
|
**Switch without leaving the screen**: `F3` opens the session picker
|
|
136
153
|
(`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
|
|
137
154
|
(grouped by profile; `Enter` switch, `s` save as the profile's default,
|
|
138
|
-
`r` fetch `/models`),
|
|
139
|
-
capability; see below)
|
|
155
|
+
`r` fetch `/models`), `F5` the settings picker (`Enter` toggles a
|
|
156
|
+
capability; see below), and `F7` the **endpoint manager** — every saved
|
|
157
|
+
profile with its `provider · transport` dialect, base_url and masked
|
|
158
|
+
key; `Enter` switches, `n` creates a profile right in the form (provider
|
|
159
|
+
type cycled with Enter, base_url defaulting to each preset's official
|
|
160
|
+
URL — overridable for custom routers, star-echoed API key), `e` edits
|
|
161
|
+
one, `p` swaps its provider type. A profile created in the form is
|
|
162
|
+
switched to on save; edits to the current profile apply to the next
|
|
163
|
+
turn. Switching away from a running session does **not**
|
|
140
164
|
cancel it — its badge stays lit and the pane rebuilds from the store when
|
|
141
165
|
you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
142
166
|
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
@@ -46,7 +46,20 @@ from lithe.bundles.workspace import register_file_tools
|
|
|
46
46
|
from lithe.bundles.todos import register_todo_tools
|
|
47
47
|
|
|
48
48
|
from .config import Config
|
|
49
|
-
from .ui import
|
|
49
|
+
from .ui import (
|
|
50
|
+
BOLD,
|
|
51
|
+
CYAN,
|
|
52
|
+
DIM,
|
|
53
|
+
GREEN,
|
|
54
|
+
MAGENTA,
|
|
55
|
+
RED,
|
|
56
|
+
SUBAGENT_STATUS,
|
|
57
|
+
YELLOW,
|
|
58
|
+
display_width,
|
|
59
|
+
truncate,
|
|
60
|
+
tool_call_label,
|
|
61
|
+
ui,
|
|
62
|
+
)
|
|
50
63
|
|
|
51
64
|
SYSTEM_PROMPT_BASE = (
|
|
52
65
|
"你是运行在命令行里的助理,工作区是用户的当前目录。"
|
|
@@ -62,10 +75,14 @@ SYSTEM_PROMPT_BASE = (
|
|
|
62
75
|
)
|
|
63
76
|
|
|
64
77
|
|
|
65
|
-
def todo_store_path(cfg: Config) -> Path:
|
|
78
|
+
def todo_store_path(cfg: Config, conversation_id: int | None = None) -> Path:
|
|
79
|
+
"""Path for one conversation's task list (None is the non-session scope)."""
|
|
66
80
|
workspace = str(cfg.workspace_dir.expanduser().resolve())
|
|
81
|
+
scope_data = {"user_id": str(cfg.user_id), "workspace": workspace}
|
|
82
|
+
if conversation_id is not None:
|
|
83
|
+
scope_data["conversation_id"] = conversation_id
|
|
67
84
|
scope = json.dumps(
|
|
68
|
-
|
|
85
|
+
scope_data,
|
|
69
86
|
ensure_ascii=False,
|
|
70
87
|
sort_keys=True,
|
|
71
88
|
separators=(",", ":"),
|
|
@@ -79,8 +96,55 @@ def sandbox_backend() -> str:
|
|
|
79
96
|
return "bwrap" if shutil.which("bwrap") else "passthrough"
|
|
80
97
|
|
|
81
98
|
|
|
99
|
+
def environment_facts(cfg: Config) -> str:
|
|
100
|
+
"""Env-fact lines for the system prompt (host, shell, workspace layout).
|
|
101
|
+
|
|
102
|
+
The layout line exists because the dominant first-hour failures in a
|
|
103
|
+
real delegation session were assumption mismatches, not tool bugs:
|
|
104
|
+
git run at a workspace root that is not a repo while the real repos
|
|
105
|
+
live in nested sub-directories, CI snippets with project-relative
|
|
106
|
+
paths, a husk ``.venv`` guessed usable. A few dozen tokens of facts
|
|
107
|
+
replace each of those wrong guesses (one failed round-trip apiece).
|
|
108
|
+
The ``run_command`` hint rides along only when the shell capability
|
|
109
|
+
is on, keeping the no-shell prompt free of the tool's name.
|
|
110
|
+
"""
|
|
111
|
+
if sys.platform == "win32":
|
|
112
|
+
if shutil.which("pwsh"):
|
|
113
|
+
shell = "PowerShell 7+(pwsh)"
|
|
114
|
+
elif shutil.which("powershell"):
|
|
115
|
+
shell = "Windows PowerShell 5.1(无 &&,用 cmd1; if ($?) { cmd2 })"
|
|
116
|
+
else:
|
|
117
|
+
shell = "cmd"
|
|
118
|
+
facts = f"宿主环境:Windows,shell 为 {shell}。"
|
|
119
|
+
else:
|
|
120
|
+
facts = "宿主环境:Linux/macOS(POSIX shell)。"
|
|
121
|
+
root = cfg.workspace_dir.expanduser().resolve()
|
|
122
|
+
try:
|
|
123
|
+
entries = sorted(
|
|
124
|
+
(p for p in root.iterdir()
|
|
125
|
+
if p.is_dir() and not p.name.startswith(".")),
|
|
126
|
+
key=lambda p: p.name.lower())
|
|
127
|
+
except OSError:
|
|
128
|
+
return facts
|
|
129
|
+
names = [p.name for p in entries[:10]]
|
|
130
|
+
layout = "、".join(names) if names else "(空)"
|
|
131
|
+
if len(entries) > 10:
|
|
132
|
+
layout += f" 等 {len(entries)} 项"
|
|
133
|
+
line = (f"工作区 {root}("
|
|
134
|
+
f"{'是' if (root / '.git').exists() else '不是'} git 仓库)"
|
|
135
|
+
f"顶层目录:{layout}")
|
|
136
|
+
repos = [p.name for p in entries if (p / ".git").exists()]
|
|
137
|
+
if repos:
|
|
138
|
+
line += f";其中的独立 git 仓库:{'、'.join(repos)}"
|
|
139
|
+
if cfg.shell:
|
|
140
|
+
line += ("。对子项目执行命令用 run_command 的 cwd 参数指定目录"
|
|
141
|
+
"(区内自由、区外需用户审批),不要假设工作区根是仓库,"
|
|
142
|
+
"也不要在命令里拼接 cd")
|
|
143
|
+
return facts + "\n" + line
|
|
144
|
+
|
|
145
|
+
|
|
82
146
|
def build_system_prompt(cfg: Config) -> str:
|
|
83
|
-
"""Base prompt plus one line per enabled capability."""
|
|
147
|
+
"""Base prompt plus one line per enabled capability, then env facts."""
|
|
84
148
|
extras = []
|
|
85
149
|
if cfg.code:
|
|
86
150
|
extras.append("可以用 run_code 执行 Python 来验证想法、计算或测试。")
|
|
@@ -97,8 +161,7 @@ def build_system_prompt(cfg: Config) -> str:
|
|
|
97
161
|
extras.append("可以用 delegate 把独立子任务委派给子代理(可用名单见工具说明:检索/编码/操作),"
|
|
98
162
|
"互不依赖的子任务用 delegate_parallel 并行委派;"
|
|
99
163
|
"子代理与本对话共享预算,汇报时合并它们的结果。")
|
|
100
|
-
|
|
101
|
-
return SYSTEM_PROMPT_BASE
|
|
164
|
+
extras.append(environment_facts(cfg))
|
|
102
165
|
return SYSTEM_PROMPT_BASE + "\n" + "\n".join(extras)
|
|
103
166
|
|
|
104
167
|
|
|
@@ -113,6 +176,8 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
113
176
|
"api_key": cfg.api_key or "unused",
|
|
114
177
|
"timeout": cfg.timeout,
|
|
115
178
|
"attempts": cfg.attempts,
|
|
179
|
+
"sleep_429": cfg.sleep_429,
|
|
180
|
+
"sleep_err": cfg.sleep_err,
|
|
116
181
|
"stream": cfg.stream,
|
|
117
182
|
"context_window": cfg.context_window,
|
|
118
183
|
"reasoning_effort": cfg.reasoning_effort,
|
|
@@ -146,7 +211,11 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
146
211
|
return LLMConfig(**overrides)
|
|
147
212
|
|
|
148
213
|
|
|
149
|
-
def build_registry(
|
|
214
|
+
def build_registry(
|
|
215
|
+
cfg: Config,
|
|
216
|
+
approver: Callable[[str], Awaitable[bool]] | None = None,
|
|
217
|
+
conversation_id: int | None = None,
|
|
218
|
+
) -> ToolRegistry:
|
|
150
219
|
"""Register the CLI's tool set against the configured workspace.
|
|
151
220
|
|
|
152
221
|
``approver`` is the human-confirmation channel for destructive
|
|
@@ -160,7 +229,7 @@ def build_registry(cfg: Config, approver: Callable[[str], Awaitable[bool]] | Non
|
|
|
160
229
|
|
|
161
230
|
register_file_tools(reg, workspace_for)
|
|
162
231
|
register_apply_patch_tool(reg, workspace_for)
|
|
163
|
-
todo_store = JsonTodoStore(todo_store_path(cfg))
|
|
232
|
+
todo_store = JsonTodoStore(todo_store_path(cfg, conversation_id))
|
|
164
233
|
register_todo_tools(reg, lambda ctx: todo_store)
|
|
165
234
|
if cfg.download:
|
|
166
235
|
register_download_tools(reg, workspace_for)
|
|
@@ -173,7 +242,8 @@ def build_registry(cfg: Config, approver: Callable[[str], Awaitable[bool]] | Non
|
|
|
173
242
|
from lithe.bundles.command import CommandRunner
|
|
174
243
|
|
|
175
244
|
register_command_tools(
|
|
176
|
-
reg, lambda ctx: cfg.workspace_dir.resolve(), CommandRunner()
|
|
245
|
+
reg, lambda ctx: cfg.workspace_dir.resolve(), CommandRunner(),
|
|
246
|
+
approver=approver,
|
|
177
247
|
)
|
|
178
248
|
# Dangerous-command guard: catastrophic commands never run; the
|
|
179
249
|
# destructive-but-scoped tier (rm -r <path>, git push --force,
|
|
@@ -238,12 +308,18 @@ _OPERATOR_PROMPT = (
|
|
|
238
308
|
)
|
|
239
309
|
|
|
240
310
|
|
|
241
|
-
def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry
|
|
311
|
+
def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry,
|
|
312
|
+
on_event=None):
|
|
242
313
|
"""Register delegate/delegate_parallel over the CLI's default roster.
|
|
243
314
|
|
|
244
315
|
Must run after ``build_host`` (the engine shares the host's registry,
|
|
245
316
|
store and LLM config — children inherit the endpoint, retry policy and
|
|
246
|
-
budgets; parallel siblings share one live cost ceiling, kernel ≥0.
|
|
317
|
+
budgets; parallel siblings share one live cost ceiling, kernel ≥0.1.0).
|
|
318
|
+
``on_event`` is the caller's event channel (the TUI's state folder, the
|
|
319
|
+
workbench emitter); the kernel's ``on_subagent_event`` progress hook is
|
|
320
|
+
wired onto it so live subagent heartbeats reach the same front-end as
|
|
321
|
+
the orchestrator's own events. Without a channel (plain `lithe run`),
|
|
322
|
+
they render through ``render_event`` directly.
|
|
247
323
|
Returns the engine (roster inspection for hosts and tests).
|
|
248
324
|
"""
|
|
249
325
|
from lithe.bundles.subagents import (
|
|
@@ -284,7 +360,29 @@ def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry):
|
|
|
284
360
|
# A spec whose tool list filtered to nothing can do nothing meaningful;
|
|
285
361
|
# researcher/coder always keep the ever-present file tools.
|
|
286
362
|
specs = [s for s in specs if s.tools]
|
|
287
|
-
|
|
363
|
+
roster = SubagentRoster(specs)
|
|
364
|
+
|
|
365
|
+
async def forward_progress(_sub_ctx, ev: dict) -> None:
|
|
366
|
+
# The kernel emits {"type": "subagent_progress", "agent": id,
|
|
367
|
+
# "event": <thin runtime event>}; enrich it with the roster's
|
|
368
|
+
# display name so front-ends can label lines without roster access.
|
|
369
|
+
spec = roster.get(str(ev.get("agent") or ""))
|
|
370
|
+
enriched = dict(ev)
|
|
371
|
+
if spec is not None:
|
|
372
|
+
enriched["display"] = spec.display
|
|
373
|
+
if on_event is not None:
|
|
374
|
+
on_event(enriched)
|
|
375
|
+
else:
|
|
376
|
+
render_event(enriched)
|
|
377
|
+
|
|
378
|
+
engine = SubagentEngine(
|
|
379
|
+
host, roster, on_subagent_event=forward_progress,
|
|
380
|
+
# Subagents do not inherit the orchestrator's system prompt — the
|
|
381
|
+
# roster's spec prompts are all they see. Prepending the same env
|
|
382
|
+
# facts (platform, shell, nested-repo layout) keeps the operator
|
|
383
|
+
# from re-learning the workspace layout by failed guesses.
|
|
384
|
+
prompt_builder=lambda spec, ctx: f"{environment_facts(cfg)}\n\n{spec.prompt}",
|
|
385
|
+
)
|
|
288
386
|
register_delegate_tools(reg, engine, parallel=True)
|
|
289
387
|
return engine
|
|
290
388
|
|
|
@@ -298,6 +396,70 @@ def tool_names(cfg: Config) -> list[str]:
|
|
|
298
396
|
return names
|
|
299
397
|
|
|
300
398
|
|
|
399
|
+
def _agent_label(ev: dict) -> str:
|
|
400
|
+
"""Display label for a delegation event: the roster display name, plus
|
|
401
|
+
the delegation instance's short suffix when present. Same-agent parallel
|
|
402
|
+
delegations (each its own instance, kernel >= 0.1.4) would otherwise be
|
|
403
|
+
indistinguishable in the live feed."""
|
|
404
|
+
who = str(ev.get("display") or ev.get("agent") or "?")
|
|
405
|
+
inst = str(ev.get("instance") or "")
|
|
406
|
+
if inst:
|
|
407
|
+
who = f"{who}·{inst.rsplit(':', 1)[-1][:4]}"
|
|
408
|
+
return who
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def _render_subagent_progress(ev: dict) -> None:
|
|
412
|
+
"""Render one live subagent heartbeat: ``[检索员·a3f2] ⚒ read_file · …``.
|
|
413
|
+
|
|
414
|
+
The kernel's progress hook caps text (300) and dumps ``tool_call`` args
|
|
415
|
+
to a capped JSON string, so parse them back for the label. ``step``
|
|
416
|
+
events are skipped — per-step chatter from every parallel worker is
|
|
417
|
+
noise, the tool lines carry the substance.
|
|
418
|
+
"""
|
|
419
|
+
who = _agent_label(ev)
|
|
420
|
+
tag = ui.s(f"[{who}]", MAGENTA)
|
|
421
|
+
inner = ev.get("event") or {}
|
|
422
|
+
t = inner.get("type")
|
|
423
|
+
room = max(8, ui.width - display_width(f" [{who}] "))
|
|
424
|
+
if t == "tool_call":
|
|
425
|
+
name = str(inner.get("name") or "")
|
|
426
|
+
args = inner.get("args")
|
|
427
|
+
if isinstance(args, str):
|
|
428
|
+
try:
|
|
429
|
+
args = json.loads(args)
|
|
430
|
+
except ValueError:
|
|
431
|
+
args = {}
|
|
432
|
+
args = args if isinstance(args, dict) else {}
|
|
433
|
+
label = tool_call_label(name, args)
|
|
434
|
+
detail = label[len(name):].strip(" ·") if label.startswith(name) else label
|
|
435
|
+
shown = truncate(detail, max(8, room - display_width(name) - 4))
|
|
436
|
+
print(f" {tag} {ui.s('⚒', CYAN)} {ui.s(name, CYAN, BOLD)} "
|
|
437
|
+
f"{ui.s(shown, DIM)}")
|
|
438
|
+
elif t == "tool_result":
|
|
439
|
+
ok = bool(inner.get("ok"))
|
|
440
|
+
summary = str(inner.get("summary") or "").replace("\n", " ")
|
|
441
|
+
if not ok and inner.get("error"):
|
|
442
|
+
# Same rule as the orchestrator's failed calls: a bare
|
|
443
|
+
# "参数错误" summary without the diagnostic tells nothing.
|
|
444
|
+
detail = str(inner["error"]).replace("\n", " ")
|
|
445
|
+
if detail and summary and (detail in summary or summary in detail):
|
|
446
|
+
summary = detail if len(detail) > len(summary) else summary
|
|
447
|
+
elif detail:
|
|
448
|
+
summary = f"{summary} · {detail}" if summary else detail
|
|
449
|
+
mark = ui.s("✓", GREEN) if ok else ui.s("✗", RED)
|
|
450
|
+
print(f" {tag} {mark} "
|
|
451
|
+
f"{ui.s(truncate(summary, max(8, room - 4)), GREEN if ok else RED)}")
|
|
452
|
+
elif t == "assistant":
|
|
453
|
+
text = str(inner.get("text") or "").replace("\n", " ").strip()
|
|
454
|
+
if text:
|
|
455
|
+
print(f" {tag} {ui.s(truncate(text, max(8, room - 2)), DIM)}")
|
|
456
|
+
elif t == "error":
|
|
457
|
+
msg = str(inner.get("message") or "").replace("\n", " ")
|
|
458
|
+
print(f" {tag} {ui.s('!', RED)} {ui.s(truncate(msg, max(8, room - 4)), RED)}")
|
|
459
|
+
elif t == "cancelled":
|
|
460
|
+
print(f" {tag} {ui.s('~ 已取消', YELLOW)}")
|
|
461
|
+
|
|
462
|
+
|
|
301
463
|
def render_event(
|
|
302
464
|
ev: dict,
|
|
303
465
|
verbose: bool = False,
|
|
@@ -345,6 +507,32 @@ def render_event(
|
|
|
345
507
|
# update_todos replaced the list; print what it now contains —
|
|
346
508
|
# the tool's own result line only reports the item count.
|
|
347
509
|
ui.todo_change(ev.get("new") or [])
|
|
510
|
+
elif t == "subagent_progress":
|
|
511
|
+
# Live heartbeat from a running subagent (kernel on_subagent_event,
|
|
512
|
+
# wired in register_subagents): each worker's tool calls and
|
|
513
|
+
# outputs, labeled with its display name.
|
|
514
|
+
_render_subagent_progress(ev)
|
|
515
|
+
elif t == "subagent_start":
|
|
516
|
+
# Emitted in ToolResult.ui after the delegation finished: the
|
|
517
|
+
# per-agent record of what it was tasked with.
|
|
518
|
+
who = _agent_label(ev)
|
|
519
|
+
task = str(ev.get("task") or "").replace("\n", " ").strip()
|
|
520
|
+
line = f"{who}:{truncate(task, max(8, ui.width - 14))}" if task else who
|
|
521
|
+
print(f" {ui.s('▸', MAGENTA)} {ui.s(line, MAGENTA)}")
|
|
522
|
+
elif t == "subagent_end":
|
|
523
|
+
who = _agent_label(ev)
|
|
524
|
+
status = str(ev.get("status") or "")
|
|
525
|
+
zh = SUBAGENT_STATUS.get(status, status or "?")
|
|
526
|
+
color = (GREEN if status == "done"
|
|
527
|
+
else YELLOW if status in ("cancelled", "max_steps")
|
|
528
|
+
else RED) if status else None
|
|
529
|
+
bits = [ui.s(zh, color) if color else zh]
|
|
530
|
+
if ev.get("steps") is not None:
|
|
531
|
+
bits.append(f"{ev['steps']} 步")
|
|
532
|
+
if ev.get("changes"):
|
|
533
|
+
bits.append(f"{ev['changes']} 处改动")
|
|
534
|
+
print(f" {ui.s('▪', MAGENTA)} {ui.s(who, MAGENTA, BOLD)} · "
|
|
535
|
+
f"{' · '.join(bits)}")
|
|
348
536
|
elif t == "error":
|
|
349
537
|
ui.error(str(ev.get("message", "")))
|
|
350
538
|
elif t == "cancelled":
|
|
@@ -405,10 +593,10 @@ async def execute(
|
|
|
405
593
|
the steering channel: a queue of user texts the kernel drains at step
|
|
406
594
|
boundaries and injects as user messages (see AgentRuntime.run).
|
|
407
595
|
"""
|
|
408
|
-
reg = build_registry(cfg, approver)
|
|
596
|
+
reg = build_registry(cfg, approver, conversation_id=conversation_id)
|
|
409
597
|
host = build_host(cfg, reg)
|
|
410
598
|
if cfg.subagents:
|
|
411
|
-
register_subagents(cfg, host, reg)
|
|
599
|
+
register_subagents(cfg, host, reg, on_event=on_event)
|
|
412
600
|
rid = run_id or uuid.uuid4().hex[:12]
|
|
413
601
|
extra = {"conversation_id": conversation_id} if conversation_id is not None else {}
|
|
414
602
|
ctx = AgentContext(run_id=rid, user_id=cfg.user_id, extra=extra)
|
|
@@ -448,7 +636,9 @@ async def execute(
|
|
|
448
636
|
|
|
449
637
|
async def undo(cfg: Config, run_id: str, quiet: bool = False) -> int:
|
|
450
638
|
"""Revert a run's mutations; returns how many actions were reverted."""
|
|
451
|
-
|
|
639
|
+
run = JsonlRunStore(cfg.store_dir).get_run(run_id, cfg.user_id)
|
|
640
|
+
conversation_id = run.conversation_id if run is not None else None
|
|
641
|
+
reg = build_registry(cfg, conversation_id=conversation_id)
|
|
452
642
|
host = build_host(cfg, reg)
|
|
453
643
|
report = await undo_run(host, run_id, cfg.user_id)
|
|
454
644
|
if not quiet:
|