lithe-cli 0.8.0__tar.gz → 0.8.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lithe-cli might be problematic. Click here for more details.
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/PKG-INFO +28 -6
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/README.md +26 -4
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/agent.py +29 -10
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/commands.py +2 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/config.py +35 -5
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/main.py +4 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/profiles.py +6 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/ttui.py +43 -3
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/tui.py +43 -3
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/workbench.py +110 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli.egg-info/PKG-INFO +28 -6
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/pyproject.toml +1 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/tests/test_profiles.py +87 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/tests/test_tui_v2.py +18 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/tests/test_workbench.py +77 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/LICENSE +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli.egg-info/SOURCES.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/setup.cfg +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/tests/test_cli.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.2}/tests/test_ttui.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.2
|
|
4
4
|
Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -39,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.9.17
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -82,11 +82,20 @@ The config file holds **named profiles** — several endpoints, one active:
|
|
|
82
82
|
"profiles": {
|
|
83
83
|
"zhipu": {"base_url": "https://…", "api_key": "…", "model": "glm-4.6",
|
|
84
84
|
"context_window": 128000, "cached_models": ["glm-4.6"]},
|
|
85
|
-
"
|
|
85
|
+
"zai-preset": {"provider": "zai", "api_key": "…", "model": "glm-4.6"}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
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
|
+
|
|
90
99
|
```bash
|
|
91
100
|
lithe config # wizard (edits the active profile)
|
|
92
101
|
lithe config --list # profiles, key masked
|
|
@@ -162,16 +171,17 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
162
171
|
╰──────────────────────────────────────╯╰──────────────────────────╯
|
|
163
172
|
Tab 采纳 → /model /models /new
|
|
164
173
|
lithe ❯ _
|
|
165
|
-
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · /help
|
|
174
|
+
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help
|
|
166
175
|
```
|
|
167
176
|
|
|
168
177
|
**Switch without leaving the screen**: `F3` opens the session picker
|
|
169
178
|
(`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
|
|
170
179
|
(grouped by profile; `Enter` switch, `s` save as the profile's default,
|
|
171
|
-
`r` fetch `/models`)
|
|
180
|
+
`r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
|
|
181
|
+
capability; see below). Switching away from a running session does **not**
|
|
172
182
|
cancel it — its badge stays lit and the pane rebuilds from the store when
|
|
173
183
|
you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
174
|
-
accepts; `/model`, `/profile`, `/
|
|
184
|
+
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
175
185
|
and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
|
|
176
186
|
current turn and exits when idle.
|
|
177
187
|
|
|
@@ -200,6 +210,18 @@ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
|
|
|
200
210
|
`/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
|
|
201
211
|
`/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
|
|
202
212
|
|
|
213
|
+
### In-session settings
|
|
214
|
+
|
|
215
|
+
The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
|
|
216
|
+
where `Enter` toggles a capability, and typed forms set anything —
|
|
217
|
+
`/set shell on`, `/set code off`, `/set vision`, `/set max-steps 50`,
|
|
218
|
+
`/set timeout 240`, `/set attempts 3`, `/set stream on`, `/set verbose`.
|
|
219
|
+
Settings apply to the **next turn** (the running turn keeps its own tool
|
|
220
|
+
set), stay session-scoped (nothing is written to the profile), and
|
|
221
|
+
turning `shell` on restates its trust warning. `/tools` re-derives the
|
|
222
|
+
registry after a capability flip, so the listing always matches what the
|
|
223
|
+
next turn will see.
|
|
224
|
+
|
|
203
225
|
### Extra capabilities
|
|
204
226
|
|
|
205
227
|
The kernel ships these as bundles; the CLI grants them per flag:
|
|
@@ -33,11 +33,20 @@ The config file holds **named profiles** — several endpoints, one active:
|
|
|
33
33
|
"profiles": {
|
|
34
34
|
"zhipu": {"base_url": "https://…", "api_key": "…", "model": "glm-4.6",
|
|
35
35
|
"context_window": 128000, "cached_models": ["glm-4.6"]},
|
|
36
|
-
"
|
|
36
|
+
"zai-preset": {"provider": "zai", "api_key": "…", "model": "glm-4.6"}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
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
|
+
|
|
41
50
|
```bash
|
|
42
51
|
lithe config # wizard (edits the active profile)
|
|
43
52
|
lithe config --list # profiles, key masked
|
|
@@ -113,16 +122,17 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
113
122
|
╰──────────────────────────────────────╯╰──────────────────────────╯
|
|
114
123
|
Tab 采纳 → /model /models /new
|
|
115
124
|
lithe ❯ _
|
|
116
|
-
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · /help
|
|
125
|
+
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help
|
|
117
126
|
```
|
|
118
127
|
|
|
119
128
|
**Switch without leaving the screen**: `F3` opens the session picker
|
|
120
129
|
(`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
|
|
121
130
|
(grouped by profile; `Enter` switch, `s` save as the profile's default,
|
|
122
|
-
`r` fetch `/models`)
|
|
131
|
+
`r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
|
|
132
|
+
capability; see below). Switching away from a running session does **not**
|
|
123
133
|
cancel it — its badge stays lit and the pane rebuilds from the store when
|
|
124
134
|
you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
125
|
-
accepts; `/model`, `/profile`, `/
|
|
135
|
+
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
126
136
|
and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
|
|
127
137
|
current turn and exits when idle.
|
|
128
138
|
|
|
@@ -151,6 +161,18 @@ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
|
|
|
151
161
|
`/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
|
|
152
162
|
`/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
|
|
153
163
|
|
|
164
|
+
### In-session settings
|
|
165
|
+
|
|
166
|
+
The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
|
|
167
|
+
where `Enter` toggles a capability, and typed forms set anything —
|
|
168
|
+
`/set shell on`, `/set code off`, `/set vision`, `/set max-steps 50`,
|
|
169
|
+
`/set timeout 240`, `/set attempts 3`, `/set stream on`, `/set verbose`.
|
|
170
|
+
Settings apply to the **next turn** (the running turn keeps its own tool
|
|
171
|
+
set), stay session-scoped (nothing is written to the profile), and
|
|
172
|
+
turning `shell` on restates its trust warning. `/tools` re-derives the
|
|
173
|
+
registry after a capability flip, so the listing always matches what the
|
|
174
|
+
next turn will see.
|
|
175
|
+
|
|
154
176
|
### Extra capabilities
|
|
155
177
|
|
|
156
178
|
The kernel ships these as bundles; the CLI grants them per flag:
|
|
@@ -88,16 +88,35 @@ def build_system_prompt(cfg: Config) -> str:
|
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
def build_llm(cfg: Config) -> LLMConfig:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
"""LLMConfig from the CLI config; a vendor preset (``provider``) acts as
|
|
92
|
+
defaults under the user's explicit values: transport / extra_body /
|
|
93
|
+
default_headers come from the preset unless the config says otherwise,
|
|
94
|
+
and dict fields merge per key."""
|
|
95
|
+
overrides = {
|
|
96
|
+
"model": cfg.model or "unused",
|
|
97
|
+
"base_url": cfg.base_url or "unused",
|
|
98
|
+
"api_key": cfg.api_key or "unused",
|
|
99
|
+
"timeout": cfg.timeout,
|
|
100
|
+
"attempts": cfg.attempts,
|
|
101
|
+
"stream": cfg.stream,
|
|
102
|
+
"context_window": cfg.context_window,
|
|
103
|
+
}
|
|
104
|
+
# The CLI's transport field defaults to "chat" and is only overridden by
|
|
105
|
+
# offline tests (custom transports); the default must not clobber a
|
|
106
|
+
# preset that knows better (e.g. a future "responses" preset).
|
|
107
|
+
if cfg.transport != "chat":
|
|
108
|
+
overrides["transport"] = cfg.transport
|
|
109
|
+
if cfg.provider:
|
|
110
|
+
from lithe.bundles.providers import apply_preset
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
kwargs = apply_preset(cfg.provider, **overrides)
|
|
114
|
+
except ValueError as exc:
|
|
115
|
+
raise SystemExit(
|
|
116
|
+
f"{exc}。请修正档案里的 provider 字段,或清除它。"
|
|
117
|
+
) from exc
|
|
118
|
+
return LLMConfig(**kwargs)
|
|
119
|
+
return LLMConfig(**overrides)
|
|
101
120
|
|
|
102
121
|
|
|
103
122
|
def build_registry(cfg: Config) -> ToolRegistry:
|
|
@@ -23,6 +23,7 @@ COMMANDS: dict[str, tuple[str, str]] = {
|
|
|
23
23
|
"model": ("[名称|--save]", "查看/切换模型(F4 同效);--save 同时存为档案默认"),
|
|
24
24
|
"models": ("", "从端点拉取模型列表并缓存"),
|
|
25
25
|
"profile": ("[名称]", "查看/切换 provider 档案"),
|
|
26
|
+
"set": ("[名称] [值]", "查看/调整运行设置(F5 同效);开关项回车或 on/off,下一轮生效"),
|
|
26
27
|
"tools": ("", "列出已注册的工具"),
|
|
27
28
|
"undo": ("[run]", "撤销当前会话最近一轮(或指定 run)的文件改动"),
|
|
28
29
|
"sidebar": ("", "显示/隐藏右侧状态栏(F2 同效)"),
|
|
@@ -47,7 +48,7 @@ class ActionResult:
|
|
|
47
48
|
action: str = "none" # none | submit | exit
|
|
48
49
|
text: str = "" # submit payload
|
|
49
50
|
messages: list[tuple[str, str]] = field(default_factory=list)
|
|
50
|
-
overlay: str | None = None # TUI picker: "sessions" | "model"
|
|
51
|
+
overlay: str | None = None # TUI picker: "sessions" | "model" | "set"
|
|
51
52
|
toggle_sidebar: bool = False
|
|
52
53
|
changed: bool = False # model/session changed → refresh banner/sidebar
|
|
53
54
|
# Zero-arg coroutine the frontend must run: plain → asyncio.run,
|
|
@@ -38,6 +38,7 @@ ENV_MODEL = "LITHE_MODEL"
|
|
|
38
38
|
ENV_HOME = "LITHE_HOME"
|
|
39
39
|
ENV_MCP = "LITHE_MCP"
|
|
40
40
|
ENV_PROFILE = "LITHE_PROFILE"
|
|
41
|
+
ENV_PROVIDER = "LITHE_PROVIDER"
|
|
41
42
|
|
|
42
43
|
DEFAULT_USER = "cli"
|
|
43
44
|
|
|
@@ -52,6 +53,10 @@ class Config:
|
|
|
52
53
|
# Which saved profile the endpoint came from (display / doctor / TUI);
|
|
53
54
|
# None when the endpoint is env/flag-only or nothing is saved.
|
|
54
55
|
profile: str | None = None
|
|
56
|
+
# Optional vendor preset name (profile field "provider" or LITHE_PROVIDER):
|
|
57
|
+
# fills base_url when unset and contributes LLMConfig defaults (transport,
|
|
58
|
+
# extra_body, ...) under the user's explicit values. See lithe.bundles.providers.
|
|
59
|
+
provider: str | None = None
|
|
55
60
|
store_dir: Path = field(default_factory=lambda: default_store_dir())
|
|
56
61
|
workspace_dir: Path = field(default_factory=lambda: Path.cwd())
|
|
57
62
|
user_id: str = DEFAULT_USER
|
|
@@ -130,7 +135,7 @@ def config_file() -> Path:
|
|
|
130
135
|
|
|
131
136
|
|
|
132
137
|
def load_saved_endpoint() -> dict:
|
|
133
|
-
"""Read the active profile's {api_key, base_url, model}; {} if none.
|
|
138
|
+
"""Read the active profile's {api_key, base_url, model, provider}; {} if none.
|
|
134
139
|
|
|
135
140
|
A corrupt file is treated as absent — a bad edit should cost the user
|
|
136
141
|
one re-prompt, not a broken CLI.
|
|
@@ -138,7 +143,8 @@ def load_saved_endpoint() -> dict:
|
|
|
138
143
|
from .profiles import ProfileStore
|
|
139
144
|
|
|
140
145
|
endpoint = ProfileStore().endpoint()
|
|
141
|
-
|
|
146
|
+
keys = (*_ENDPOINT_KEYS, "provider")
|
|
147
|
+
return {k: endpoint[k] for k in keys if endpoint.get(k)}
|
|
142
148
|
|
|
143
149
|
|
|
144
150
|
def _restrict_to_owner(path: Path, directory: bool = False) -> None:
|
|
@@ -229,15 +235,39 @@ def load_config(args: Any) -> Config:
|
|
|
229
235
|
)
|
|
230
236
|
if flag or os.environ.get(env)
|
|
231
237
|
)
|
|
238
|
+
# Vendor preset (profile "provider" field > LITHE_PROVIDER): fills
|
|
239
|
+
# base_url when nothing explicit set it — the preset's whole point —
|
|
240
|
+
# while every explicit value stays untouched. An unknown name is a
|
|
241
|
+
# config typo: die loudly like an unknown --profile, listing options.
|
|
242
|
+
provider = (os.environ.get(ENV_PROVIDER) or saved.get("provider")
|
|
243
|
+
or g("provider", None))
|
|
244
|
+
base_url = (
|
|
245
|
+
g("base_url", None) or os.environ.get(ENV_BASE_URL)
|
|
246
|
+
or saved.get("base_url")
|
|
247
|
+
)
|
|
248
|
+
if provider and not base_url:
|
|
249
|
+
try:
|
|
250
|
+
from lithe.bundles.providers import get_preset
|
|
251
|
+
|
|
252
|
+
base_url = get_preset(provider).get("base_url")
|
|
253
|
+
except ValueError as exc:
|
|
254
|
+
# get_preset's message already lists the known providers.
|
|
255
|
+
raise SystemExit(
|
|
256
|
+
f"{exc}。可手写 base_url,或从上述 preset 中选择。"
|
|
257
|
+
) from exc
|
|
258
|
+
if not base_url:
|
|
259
|
+
raise SystemExit(
|
|
260
|
+
f"provider {provider!r} 的 preset 未提供 base_url;"
|
|
261
|
+
f"请在档案中手写 base_url。"
|
|
262
|
+
)
|
|
232
263
|
return Config(
|
|
233
264
|
api_key=(
|
|
234
265
|
g("api_key", None) or os.environ.get(ENV_API_KEY) or saved.get("api_key")
|
|
235
266
|
),
|
|
236
|
-
base_url=
|
|
237
|
-
g("base_url", None) or os.environ.get(ENV_BASE_URL) or saved.get("base_url")
|
|
238
|
-
),
|
|
267
|
+
base_url=base_url,
|
|
239
268
|
model=(g("model", None) or os.environ.get(ENV_MODEL) or saved.get("model")),
|
|
240
269
|
profile=active,
|
|
270
|
+
provider=provider,
|
|
241
271
|
store_dir=store_dir,
|
|
242
272
|
workspace_dir=workspace_dir,
|
|
243
273
|
user_id=g("user", None) or DEFAULT_USER,
|
|
@@ -454,9 +454,11 @@ def _cmd_config(args: Any) -> int:
|
|
|
454
454
|
for name in names:
|
|
455
455
|
ep = store.masked(name)
|
|
456
456
|
mark = "*" if name == active else " "
|
|
457
|
+
prov = f" [{ep['provider']}]" if ep.get("provider") else ""
|
|
457
458
|
print(
|
|
458
459
|
f"{mark} {ui.s(name, CYAN)} · {ep.get('model', '—')} "
|
|
459
460
|
f"@ {ep.get('base_url', '—')}(key {ep.get('api_key', '—')})"
|
|
461
|
+
f"{prov}"
|
|
460
462
|
)
|
|
461
463
|
print(ui.s("(* 为当前档案;config --use NAME 切换)", YELLOW))
|
|
462
464
|
return 0
|
|
@@ -482,6 +484,8 @@ def _cmd_config(args: Any) -> int:
|
|
|
482
484
|
masked = key if len(key) <= 8 else f"{key[:5]}…{key[-4:]}"
|
|
483
485
|
print(ui.kv("config", str(config_file())))
|
|
484
486
|
print(ui.kv("profile", str(store.active_name() or "—")))
|
|
487
|
+
if saved.get("provider"):
|
|
488
|
+
print(ui.kv("provider", saved["provider"]))
|
|
485
489
|
print(ui.kv("base_url", saved["base_url"]))
|
|
486
490
|
print(ui.kv("api_key", masked))
|
|
487
491
|
print(ui.kv("model", saved["model"]))
|
|
@@ -59,6 +59,9 @@ def _clean_endpoint(data: dict) -> dict:
|
|
|
59
59
|
v = data.get(k)
|
|
60
60
|
if isinstance(v, str) and v.strip():
|
|
61
61
|
out[k] = v.strip()
|
|
62
|
+
provider = data.get("provider")
|
|
63
|
+
if isinstance(provider, str) and provider.strip():
|
|
64
|
+
out["provider"] = provider.strip()
|
|
62
65
|
for k in ("context_window",):
|
|
63
66
|
v = data.get(k)
|
|
64
67
|
if isinstance(v, int) and v > 0:
|
|
@@ -169,6 +172,7 @@ class ProfileStore:
|
|
|
169
172
|
api_key: str,
|
|
170
173
|
model: str,
|
|
171
174
|
context_window: int | None = None,
|
|
175
|
+
provider: str | None = None,
|
|
172
176
|
) -> Path:
|
|
173
177
|
if not valid_name(name):
|
|
174
178
|
raise SystemExit(
|
|
@@ -179,6 +183,8 @@ class ProfileStore:
|
|
|
179
183
|
"model": model.strip()}
|
|
180
184
|
if context_window:
|
|
181
185
|
endpoint["context_window"] = int(context_window)
|
|
186
|
+
if provider and provider.strip():
|
|
187
|
+
endpoint["provider"] = provider.strip()
|
|
182
188
|
# keep a previously cached model list when the base_url is unchanged
|
|
183
189
|
old = data["profiles"].get(name) or {}
|
|
184
190
|
if old.get("cached_models") and old.get("base_url") == endpoint["base_url"]:
|
|
@@ -131,8 +131,9 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
131
131
|
|
|
132
132
|
def footer_text(state: TuiState) -> str:
|
|
133
133
|
if state.running:
|
|
134
|
-
return f" ● {state.status} · Ctrl+C 取消 · F3 会话 · F4 模型 "
|
|
135
|
-
return f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型
|
|
134
|
+
return f" ● {state.status} · Ctrl+C 取消 · F3 会话 · F4 模型 · F5 设置 "
|
|
135
|
+
return (f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
|
|
136
|
+
f" · F5 设置 · /help ")
|
|
136
137
|
|
|
137
138
|
|
|
138
139
|
# -- input: completion + persistent history ------------------------------------
|
|
@@ -343,6 +344,7 @@ class LitheApp(App):
|
|
|
343
344
|
Binding("f2", "toggle_sidebar", "侧栏", priority=True),
|
|
344
345
|
Binding("f3", "open_sessions", "会话", priority=True),
|
|
345
346
|
Binding("f4", "open_model", "模型", priority=True),
|
|
347
|
+
Binding("f5", "open_set", "设置", priority=True),
|
|
346
348
|
Binding("ctrl+c", "cancel_or_exit", "取消/退出", priority=True),
|
|
347
349
|
]
|
|
348
350
|
|
|
@@ -585,7 +587,7 @@ class LitheApp(App):
|
|
|
585
587
|
return
|
|
586
588
|
if r.awaitable is not None:
|
|
587
589
|
asyncio.create_task(r.awaitable())
|
|
588
|
-
if r.overlay in ("sessions", "model"):
|
|
590
|
+
if r.overlay in ("sessions", "model", "set"):
|
|
589
591
|
self._open_picker(r.overlay)
|
|
590
592
|
if r.overlay == "rebuild" and self._current_cid() is not None:
|
|
591
593
|
self._activate(self._current_cid())
|
|
@@ -643,6 +645,27 @@ class LitheApp(App):
|
|
|
643
645
|
letter_actions={"s": "_picker_save_model",
|
|
644
646
|
"r": "_picker_fetch_models"},
|
|
645
647
|
), self._model_picked)
|
|
648
|
+
elif name == "set":
|
|
649
|
+
items = []
|
|
650
|
+
for row in self.wb.settings_rows():
|
|
651
|
+
value = row["value"]
|
|
652
|
+
if row["kind"] == "bool":
|
|
653
|
+
shown = "on" if value else "off"
|
|
654
|
+
items.append((
|
|
655
|
+
{"key": row["key"]},
|
|
656
|
+
f"{'[green]●[/] ' if value else '○ '}"
|
|
657
|
+
f"{row['key']:<10} {shown:<4}{row['label']}",
|
|
658
|
+
))
|
|
659
|
+
else:
|
|
660
|
+
items.append((
|
|
661
|
+
{"kind": "hint"},
|
|
662
|
+
f" {row['key']:<10} {value:<6}{row['label']}"
|
|
663
|
+
f"(/set {row['key']} 值)",
|
|
664
|
+
))
|
|
665
|
+
self.push_screen(PickerModal(
|
|
666
|
+
"运行设置", items,
|
|
667
|
+
"Enter 切换开关 · 数值项用 /set 名称 值 · Esc 关闭",
|
|
668
|
+
), self._set_picked)
|
|
646
669
|
|
|
647
670
|
def action_open_sessions(self) -> None:
|
|
648
671
|
if self.mode == "chat" and not isinstance(self.screen, PickerModal):
|
|
@@ -652,6 +675,23 @@ class LitheApp(App):
|
|
|
652
675
|
if not isinstance(self.screen, PickerModal):
|
|
653
676
|
self._open_picker("model")
|
|
654
677
|
|
|
678
|
+
def action_open_set(self) -> None:
|
|
679
|
+
if not isinstance(self.screen, PickerModal):
|
|
680
|
+
self._open_picker("set")
|
|
681
|
+
|
|
682
|
+
def _set_picked(self, result) -> None:
|
|
683
|
+
if not result or result[0] != "select" or not result[1]:
|
|
684
|
+
return
|
|
685
|
+
payload = result[1]
|
|
686
|
+
if payload.get("kind") == "hint":
|
|
687
|
+
return
|
|
688
|
+
r = self.wb.set_setting(payload["key"], "toggle")
|
|
689
|
+
for cls, text in r.messages:
|
|
690
|
+
self.state.say(cls, text)
|
|
691
|
+
if r.changed:
|
|
692
|
+
self._refresh_meta()
|
|
693
|
+
self._refresh_chrome()
|
|
694
|
+
|
|
655
695
|
def _sessions_picked(self, result) -> None:
|
|
656
696
|
if not result:
|
|
657
697
|
return
|
|
@@ -727,6 +727,30 @@ def models_overlay_items(
|
|
|
727
727
|
return items
|
|
728
728
|
|
|
729
729
|
|
|
730
|
+
def settings_overlay_items(setting_rows: list[dict]) -> list[dict]:
|
|
731
|
+
"""Items for the /set picker: booleans are selectable (Enter toggles),
|
|
732
|
+
numerics render as hints — a value cannot be picked from a list."""
|
|
733
|
+
items: list[dict] = []
|
|
734
|
+
for row in setting_rows:
|
|
735
|
+
value = row["value"]
|
|
736
|
+
if row["kind"] == "bool":
|
|
737
|
+
shown = "on" if value else "off"
|
|
738
|
+
items.append({
|
|
739
|
+
"kind": "item",
|
|
740
|
+
"label": f"{'●' if value else '○'} {row['key']:<10} {shown:<4}"
|
|
741
|
+
f"{row['label']}",
|
|
742
|
+
"key": row["key"],
|
|
743
|
+
"active": bool(value),
|
|
744
|
+
})
|
|
745
|
+
else:
|
|
746
|
+
items.append({"kind": "hint",
|
|
747
|
+
"label": f" {row['key']:<10} {value:<6}{row['label']}"
|
|
748
|
+
f"(/set {row['key']} 值)"})
|
|
749
|
+
items.append({"kind": "hint",
|
|
750
|
+
"label": "Enter 切换开关 · 数值项用 /set 名称 值 · Esc 关闭"})
|
|
751
|
+
return items
|
|
752
|
+
|
|
753
|
+
|
|
730
754
|
def picker_rows(state: TuiState, width: int, height: int) -> list[list]:
|
|
731
755
|
"""The modal picker panel that replaces the body while an overlay is open.
|
|
732
756
|
|
|
@@ -788,6 +812,13 @@ class SlashCompleter(Completer):
|
|
|
788
812
|
words = self.state.profile_names
|
|
789
813
|
elif command == "resume":
|
|
790
814
|
words = [f"#{row['id']}" for row in self.state.sessions]
|
|
815
|
+
elif command == "set":
|
|
816
|
+
from .workbench import _SETTING_DEFS
|
|
817
|
+
|
|
818
|
+
words = [d[0] for d in _SETTING_DEFS]
|
|
819
|
+
if arg.strip() and " " not in arg.strip():
|
|
820
|
+
# second word: boolean on/off offers itself
|
|
821
|
+
words = words + ["on", "off"]
|
|
791
822
|
for word in words:
|
|
792
823
|
if word.startswith(arg) and word != arg:
|
|
793
824
|
yield Completion(word, start_position=-len(arg))
|
|
@@ -907,6 +938,7 @@ def build_app(
|
|
|
907
938
|
# -- pickers: modal navigation while an overlay is open -------------------
|
|
908
939
|
kb.add("f3")(lambda event: on_line("/sessions"))
|
|
909
940
|
kb.add("f4")(lambda event: on_line("/model"))
|
|
941
|
+
kb.add("f5")(lambda event: on_line("/set"))
|
|
910
942
|
|
|
911
943
|
@kb.add("escape", filter=overlay_open, eager=True)
|
|
912
944
|
@kb.add("q", filter=overlay_open, eager=True)
|
|
@@ -1017,9 +1049,9 @@ def build_app(
|
|
|
1017
1049
|
elif mode == "run":
|
|
1018
1050
|
hint = " q 退出 · F2 侧栏 " if not state.running else " Ctrl+C 取消 · PgUp/PgDn 滚动 "
|
|
1019
1051
|
elif state.running:
|
|
1020
|
-
hint = " Ctrl+C 取消本轮 · F3 会话 · F4 模型 "
|
|
1052
|
+
hint = " Ctrl+C 取消本轮 · F3 会话 · F4 模型 · F5 设置 "
|
|
1021
1053
|
else:
|
|
1022
|
-
hint = " Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · /help 命令 "
|
|
1054
|
+
hint = " Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help 命令 "
|
|
1023
1055
|
return FormattedText(compose_footer(state, cols, hint))
|
|
1024
1056
|
|
|
1025
1057
|
def _prompt_text():
|
|
@@ -1226,6 +1258,11 @@ async def run_screen(cfg, task, mode, args=None):
|
|
|
1226
1258
|
cfg.profile, cfg.model, wb.model_candidates(),
|
|
1227
1259
|
),
|
|
1228
1260
|
)
|
|
1261
|
+
elif name == "set":
|
|
1262
|
+
state.open_overlay(
|
|
1263
|
+
"set", "运行设置",
|
|
1264
|
+
settings_overlay_items(wb.settings_rows()),
|
|
1265
|
+
)
|
|
1229
1266
|
|
|
1230
1267
|
def _after_switch():
|
|
1231
1268
|
cid = _current_cid()
|
|
@@ -1244,6 +1281,9 @@ async def run_screen(cfg, task, mode, args=None):
|
|
|
1244
1281
|
_say_result(wb.set_profile(item["profile"]))
|
|
1245
1282
|
_say_result(wb.set_model(item["model"]))
|
|
1246
1283
|
_refresh_meta(state)
|
|
1284
|
+
elif name == "set":
|
|
1285
|
+
# Enter on a boolean row toggles it (same call /set 名称 makes)
|
|
1286
|
+
_say_result(wb.set_setting(item["key"], "toggle"))
|
|
1247
1287
|
|
|
1248
1288
|
def on_overlay_key(name, key):
|
|
1249
1289
|
if name == "sessions":
|
|
@@ -1302,7 +1342,7 @@ async def run_screen(cfg, task, mode, args=None):
|
|
|
1302
1342
|
return
|
|
1303
1343
|
if r.awaitable is not None:
|
|
1304
1344
|
asyncio.create_task(r.awaitable())
|
|
1305
|
-
if r.overlay in ("sessions", "model"):
|
|
1345
|
+
if r.overlay in ("sessions", "model", "set"):
|
|
1306
1346
|
_open_picker(r.overlay)
|
|
1307
1347
|
if r.overlay == "rebuild":
|
|
1308
1348
|
_after_switch()
|
|
@@ -31,6 +31,28 @@ from .config import Config
|
|
|
31
31
|
from .profiles import ProfileStore, fetch_models
|
|
32
32
|
from .sessions import SessionManager, auto_title, format_session_rows
|
|
33
33
|
|
|
34
|
+
# Session-adjustable settings for /set: (user key, cfg attr, label, kind).
|
|
35
|
+
# Order is the /set display order. Only per-turn assembly inputs belong
|
|
36
|
+
# here — workspace/store/user stay startup-level (session identity), and
|
|
37
|
+
# --ui/--mcp are process-scoped. `kind` drives parsing: bool accepts
|
|
38
|
+
# on/off/开/关 (bare invocation toggles); int/float require a value.
|
|
39
|
+
_SETTING_DEFS: list[tuple[str, str, str, str]] = [
|
|
40
|
+
("shell", "shell", "run_command(宿主 shell,不可撤销)", "bool"),
|
|
41
|
+
("code", "code", "run_code / run_file(沙箱 Python)", "bool"),
|
|
42
|
+
("vision", "vision", "image_info / analyze_image(图像理解)", "bool"),
|
|
43
|
+
("download", "download", "download_file(网络下载)", "bool"),
|
|
44
|
+
("stream", "stream", "流式输出 token", "bool"),
|
|
45
|
+
("verbose", "verbose", "显示 usage / reasoning 事件", "bool"),
|
|
46
|
+
("max-steps", "max_steps", "工具循环步数上限", "int"),
|
|
47
|
+
("timeout", "timeout", "单次模型调用超时(秒)", "float"),
|
|
48
|
+
("attempts", "attempts", "模型调用重试次数", "int"),
|
|
49
|
+
]
|
|
50
|
+
# Settings whose change alters the next turn's tool registry (vs. sampling
|
|
51
|
+
# or rendering knobs): flipping them invalidates the /tools cache.
|
|
52
|
+
_TOOL_AFFECTING = {"shell", "code", "vision", "download"}
|
|
53
|
+
_TRUTHY = {"on", "true", "1", "开"}
|
|
54
|
+
_FALSY = {"off", "false", "0", "关"}
|
|
55
|
+
|
|
34
56
|
|
|
35
57
|
class Workbench:
|
|
36
58
|
def __init__(self, cfg: Config):
|
|
@@ -392,6 +414,82 @@ class Workbench:
|
|
|
392
414
|
self._emit(cid, {"type": "undo_done", "run_id": rid,
|
|
393
415
|
"reverted": reverted})
|
|
394
416
|
|
|
417
|
+
# -- session-adjustable settings (/set) -------------------------------------
|
|
418
|
+
|
|
419
|
+
def settings_rows(self) -> list[dict]:
|
|
420
|
+
"""Current values of the /set-able knobs, in display order."""
|
|
421
|
+
return [
|
|
422
|
+
{"key": key, "label": label, "kind": kind,
|
|
423
|
+
"value": getattr(self.cfg, attr)}
|
|
424
|
+
for key, attr, label, kind in _SETTING_DEFS
|
|
425
|
+
]
|
|
426
|
+
|
|
427
|
+
def _setting_def(self, key: str) -> tuple[str, str, str, str] | None:
|
|
428
|
+
"""Resolve a /set argument (user key, underscore variant, or 序号)."""
|
|
429
|
+
norm = key.strip().lower().replace("_", "-")
|
|
430
|
+
for defn in _SETTING_DEFS:
|
|
431
|
+
if defn[0] == norm:
|
|
432
|
+
return defn
|
|
433
|
+
if key.strip().isdigit():
|
|
434
|
+
idx = int(key.strip()) - 1
|
|
435
|
+
if 0 <= idx < len(_SETTING_DEFS):
|
|
436
|
+
return _SETTING_DEFS[idx]
|
|
437
|
+
return None
|
|
438
|
+
|
|
439
|
+
def set_setting(self, key: str, value: str = "") -> ActionResult:
|
|
440
|
+
"""Flip one /set-able knob on the shared cfg; applies next turn.
|
|
441
|
+
|
|
442
|
+
Booleans accept on/off (bare = toggle); numerics need a value.
|
|
443
|
+
Tool-affecting flips invalidate the /tools cache; turning shell on
|
|
444
|
+
restates its trust warning so the escalation is never silent.
|
|
445
|
+
"""
|
|
446
|
+
result = ActionResult()
|
|
447
|
+
defn = self._setting_def(key)
|
|
448
|
+
if defn is None:
|
|
449
|
+
names = "、".join(d[0] for d in _SETTING_DEFS)
|
|
450
|
+
result.say("err", f"未知设置项 {key!r}(可用:{names})")
|
|
451
|
+
return result
|
|
452
|
+
ukey, attr, label, kind = defn
|
|
453
|
+
current = getattr(self.cfg, attr)
|
|
454
|
+
if kind == "bool":
|
|
455
|
+
token = value.strip().lower()
|
|
456
|
+
if not token:
|
|
457
|
+
new = not current # bare invocation toggles
|
|
458
|
+
elif token in _TRUTHY:
|
|
459
|
+
new = True
|
|
460
|
+
elif token in _FALSY:
|
|
461
|
+
new = False
|
|
462
|
+
else:
|
|
463
|
+
result.say("err", f"{ukey} 是开关:on / off(不带值则为切换)")
|
|
464
|
+
return result
|
|
465
|
+
else:
|
|
466
|
+
if not value.strip():
|
|
467
|
+
result.say("err", f"用法:/set {ukey} 值(当前 {current})")
|
|
468
|
+
return result
|
|
469
|
+
try:
|
|
470
|
+
new = int(value.strip()) if kind == "int" else float(value.strip())
|
|
471
|
+
except ValueError:
|
|
472
|
+
result.say("err", f"{ukey} 需要一个{'整数' if kind == 'int' else '数值'}")
|
|
473
|
+
return result
|
|
474
|
+
if kind == "int" and new < 1 or kind == "float" and new <= 0:
|
|
475
|
+
result.say("err", f"{ukey} 必须为正数")
|
|
476
|
+
return result
|
|
477
|
+
if new == current:
|
|
478
|
+
result.say("dim", f"{label}:已是 {new}")
|
|
479
|
+
return result
|
|
480
|
+
setattr(self.cfg, attr, new)
|
|
481
|
+
if ukey in _TOOL_AFFECTING:
|
|
482
|
+
self._tool_names = None # /tools must re-derive the registry
|
|
483
|
+
result.changed = True
|
|
484
|
+
shown = "on" if new is True else "off" if new is False else new
|
|
485
|
+
was = "on" if current is True else "off" if current is False else current
|
|
486
|
+
result.say("ok", f"{ukey}:{was} → {shown},下一轮生效")
|
|
487
|
+
if ukey == "shell" and new is True:
|
|
488
|
+
result.say("warn", "run_command 以当前用户权限执行、非沙箱、结果不可撤销")
|
|
489
|
+
elif ukey == "code" and new is True:
|
|
490
|
+
result.say("dim", "(无 bubblewrap 的环境回退为非沙箱直通执行)")
|
|
491
|
+
return result
|
|
492
|
+
|
|
395
493
|
# -- dispatch -----------------------------------------------------------------
|
|
396
494
|
|
|
397
495
|
def dispatch(self, line: str) -> ActionResult:
|
|
@@ -480,6 +578,18 @@ class Workbench:
|
|
|
480
578
|
if cmd == "undo":
|
|
481
579
|
result.awaitable = lambda: self._undo(arg or None)
|
|
482
580
|
return result
|
|
581
|
+
if cmd == "set":
|
|
582
|
+
if not arg:
|
|
583
|
+
for row in self.settings_rows():
|
|
584
|
+
shown = "on" if row["value"] is True else \
|
|
585
|
+
"off" if row["value"] is False else row["value"]
|
|
586
|
+
result.say("dim",
|
|
587
|
+
f" {row['key']:<10} {str(shown):<6} {row['label']}")
|
|
588
|
+
result.say("dim", "(/set 名称 on|off 或 /set 序号;数值项 /set 名称 值)")
|
|
589
|
+
result.overlay = "set"
|
|
590
|
+
return result
|
|
591
|
+
key, _, value = arg.partition(" ")
|
|
592
|
+
return self.set_setting(key, value)
|
|
483
593
|
if cmd == "sidebar":
|
|
484
594
|
result.toggle_sidebar = True
|
|
485
595
|
return result
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.2
|
|
4
4
|
Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -39,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.9.17
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -82,11 +82,20 @@ The config file holds **named profiles** — several endpoints, one active:
|
|
|
82
82
|
"profiles": {
|
|
83
83
|
"zhipu": {"base_url": "https://…", "api_key": "…", "model": "glm-4.6",
|
|
84
84
|
"context_window": 128000, "cached_models": ["glm-4.6"]},
|
|
85
|
-
"
|
|
85
|
+
"zai-preset": {"provider": "zai", "api_key": "…", "model": "glm-4.6"}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
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
|
+
|
|
90
99
|
```bash
|
|
91
100
|
lithe config # wizard (edits the active profile)
|
|
92
101
|
lithe config --list # profiles, key masked
|
|
@@ -162,16 +171,17 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
162
171
|
╰──────────────────────────────────────╯╰──────────────────────────╯
|
|
163
172
|
Tab 采纳 → /model /models /new
|
|
164
173
|
lithe ❯ _
|
|
165
|
-
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · /help
|
|
174
|
+
● 运行中 · 步骤 2/35 Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help
|
|
166
175
|
```
|
|
167
176
|
|
|
168
177
|
**Switch without leaving the screen**: `F3` opens the session picker
|
|
169
178
|
(`Enter` switch, `n` new, `d` delete, `r` rename), `F4` the model picker
|
|
170
179
|
(grouped by profile; `Enter` switch, `s` save as the profile's default,
|
|
171
|
-
`r` fetch `/models`)
|
|
180
|
+
`r` fetch `/models`), and `F5` the settings picker (`Enter` toggles a
|
|
181
|
+
capability; see below). Switching away from a running session does **not**
|
|
172
182
|
cancel it — its badge stays lit and the pane rebuilds from the store when
|
|
173
183
|
you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
174
|
-
accepts; `/model`, `/profile`, `/
|
|
184
|
+
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
175
185
|
and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
|
|
176
186
|
current turn and exits when idle.
|
|
177
187
|
|
|
@@ -200,6 +210,18 @@ are slash commands: `/sessions`, `/resume 12`, `/new [标题]`,
|
|
|
200
210
|
`/rename 标题`, `/model glm-4.5 [--save]`, `/profile zhipu`,
|
|
201
211
|
`/models`, `/undo`, `/tools`, `/sidebar`, `/help`, `/exit`.
|
|
202
212
|
|
|
213
|
+
### In-session settings
|
|
214
|
+
|
|
215
|
+
The per-turn knobs don't need a restart: `/set` (or `F5`) opens a picker
|
|
216
|
+
where `Enter` toggles a capability, and typed forms set anything —
|
|
217
|
+
`/set shell on`, `/set code off`, `/set vision`, `/set max-steps 50`,
|
|
218
|
+
`/set timeout 240`, `/set attempts 3`, `/set stream on`, `/set verbose`.
|
|
219
|
+
Settings apply to the **next turn** (the running turn keeps its own tool
|
|
220
|
+
set), stay session-scoped (nothing is written to the profile), and
|
|
221
|
+
turning `shell` on restates its trust warning. `/tools` re-derives the
|
|
222
|
+
registry after a capability flip, so the listing always matches what the
|
|
223
|
+
next turn will see.
|
|
224
|
+
|
|
203
225
|
### Extra capabilities
|
|
204
226
|
|
|
205
227
|
The kernel ships these as bundles; the CLI grants them per flag:
|
|
@@ -9,7 +9,7 @@ description = "Command-line interface for the lithe agent kernel: chat, one-shot
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
requires-python = ">=3.10"
|
|
12
|
-
dependencies = ["lithe>=0.9.
|
|
12
|
+
dependencies = ["lithe>=0.9.17", "prompt-toolkit>=3.0.38", "textual>=1.0"]
|
|
13
13
|
keywords = ["agent", "llm", "react", "cli", "tool-calling"]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Development Status :: 4 - Beta",
|
|
@@ -206,3 +206,90 @@ def test_corrupt_profile_file_reads_empty(tmp_path, monkeypatch):
|
|
|
206
206
|
(tmp_path / "config.json").write_text("{oops", encoding="utf-8")
|
|
207
207
|
assert ProfileStore().names() == []
|
|
208
208
|
assert ProfileStore().endpoint() == {}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
# --- provider presets -------------------------------------------------------
|
|
212
|
+
|
|
213
|
+
class _PresetArgs:
|
|
214
|
+
api_key = base_url = model = profile = provider = None
|
|
215
|
+
store = workspace = user = None
|
|
216
|
+
skills = mcp = None
|
|
217
|
+
context_window = None
|
|
218
|
+
download = code = shell = vision = color = no_color = verbose = False
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def test_provider_preset_fills_base_url_and_build_llm(tmp_path, monkeypatch):
|
|
222
|
+
from lithe_cli.agent import build_llm
|
|
223
|
+
from lithe_cli.config import ENV_PROVIDER, load_config
|
|
224
|
+
|
|
225
|
+
monkeypatch.setenv("LITHE_HOME", str(tmp_path))
|
|
226
|
+
for var in ("LITHE_API_KEY", "LITHE_BASE_URL", "LITHE_MODEL",
|
|
227
|
+
"LITHE_PROFILE", ENV_PROVIDER):
|
|
228
|
+
monkeypatch.delenv(var, raising=False)
|
|
229
|
+
# 档案只写 provider + 凭据 + 模型:base_url 由 preset 补齐
|
|
230
|
+
ProfileStore().upsert("myzai", "", "sk-z", "glm-4.6", provider="zai")
|
|
231
|
+
|
|
232
|
+
cfg = load_config(_PresetArgs())
|
|
233
|
+
assert cfg.provider == "zai"
|
|
234
|
+
assert cfg.base_url == "https://open.bigmodel.cn/api/paas/v4"
|
|
235
|
+
assert cfg.has_endpoint, "preset 补齐 base_url 后即视为完整端点"
|
|
236
|
+
|
|
237
|
+
llm = build_llm(cfg)
|
|
238
|
+
assert llm.base_url == "https://open.bigmodel.cn/api/paas/v4"
|
|
239
|
+
assert llm.model == "glm-4.6" and llm.transport == "chat"
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_provider_preset_explicit_values_win(tmp_path, monkeypatch):
|
|
243
|
+
from lithe_cli.agent import build_llm
|
|
244
|
+
from lithe_cli.config import ENV_PROVIDER, load_config
|
|
245
|
+
|
|
246
|
+
monkeypatch.setenv("LITHE_HOME", str(tmp_path))
|
|
247
|
+
for var in ("LITHE_API_KEY", "LITHE_BASE_URL", "LITHE_MODEL",
|
|
248
|
+
"LITHE_PROFILE", ENV_PROVIDER):
|
|
249
|
+
monkeypatch.delenv(var, raising=False)
|
|
250
|
+
# 档案手写了 base_url:显式值覆盖 preset
|
|
251
|
+
ProfileStore().upsert("proxy", "https://my-proxy.example/v1", "sk-z",
|
|
252
|
+
"glm-4.6", provider="zai", context_window=128000)
|
|
253
|
+
|
|
254
|
+
cfg = load_config(_PresetArgs())
|
|
255
|
+
assert cfg.base_url == "https://my-proxy.example/v1"
|
|
256
|
+
llm = build_llm(cfg)
|
|
257
|
+
assert llm.base_url == "https://my-proxy.example/v1"
|
|
258
|
+
assert llm.context_window == 128000
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def test_provider_via_env_beats_profile_field(tmp_path, monkeypatch):
|
|
262
|
+
from lithe_cli.config import ENV_PROVIDER, load_config
|
|
263
|
+
|
|
264
|
+
monkeypatch.setenv("LITHE_HOME", str(tmp_path))
|
|
265
|
+
for var in ("LITHE_API_KEY", "LITHE_BASE_URL", "LITHE_MODEL",
|
|
266
|
+
"LITHE_PROFILE"):
|
|
267
|
+
monkeypatch.delenv(var, raising=False)
|
|
268
|
+
ProfileStore().upsert("a", "", "sk", "m", provider="zai")
|
|
269
|
+
monkeypatch.setenv(ENV_PROVIDER, "deepseek")
|
|
270
|
+
cfg = load_config(_PresetArgs())
|
|
271
|
+
assert cfg.provider == "deepseek"
|
|
272
|
+
assert cfg.base_url == "https://api.deepseek.com"
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def test_unknown_provider_dies_loudly(tmp_path, monkeypatch):
|
|
276
|
+
from lithe_cli.config import ENV_PROVIDER, load_config
|
|
277
|
+
|
|
278
|
+
monkeypatch.setenv("LITHE_HOME", str(tmp_path))
|
|
279
|
+
for var in ("LITHE_API_KEY", "LITHE_BASE_URL", "LITHE_MODEL",
|
|
280
|
+
"LITHE_PROFILE", ENV_PROVIDER):
|
|
281
|
+
monkeypatch.delenv(var, raising=False)
|
|
282
|
+
ProfileStore().upsert("bad", "", "sk", "m", provider="nonexistent")
|
|
283
|
+
with pytest.raises(SystemExit, match="未知 provider"):
|
|
284
|
+
load_config(_PresetArgs())
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def test_endpoint_roundtrips_provider_field(tmp_path, monkeypatch):
|
|
288
|
+
monkeypatch.setenv("LITHE_HOME", str(tmp_path))
|
|
289
|
+
store = ProfileStore()
|
|
290
|
+
store.upsert("zai", "", "sk", "glm-4.6", provider="zai")
|
|
291
|
+
fresh = ProfileStore() # re-read from disk
|
|
292
|
+
assert fresh.endpoint("zai")["provider"] == "zai"
|
|
293
|
+
# 无 provider 的档案不受影响
|
|
294
|
+
store.upsert("plain", "https://p.example", "sk", "m")
|
|
295
|
+
assert "provider" not in fresh.endpoint("plain")
|
|
@@ -11,6 +11,7 @@ from lithe_cli.tui import (
|
|
|
11
11
|
models_overlay_items,
|
|
12
12
|
picker_rows,
|
|
13
13
|
sessions_overlay_items,
|
|
14
|
+
settings_overlay_items,
|
|
14
15
|
transcript_feed_lines,
|
|
15
16
|
)
|
|
16
17
|
from lithe_cli.ui import display_width
|
|
@@ -104,6 +105,23 @@ def test_models_overlay_items_groups_by_profile():
|
|
|
104
105
|
assert or_models == ["sonnet-4"]
|
|
105
106
|
|
|
106
107
|
|
|
108
|
+
def test_settings_overlay_items_toggles_and_hints():
|
|
109
|
+
items = settings_overlay_items([
|
|
110
|
+
{"key": "shell", "label": "run_command(宿主 shell)", "kind": "bool",
|
|
111
|
+
"value": True},
|
|
112
|
+
{"key": "vision", "label": "图像理解", "kind": "bool", "value": False},
|
|
113
|
+
{"key": "max-steps", "label": "步数上限", "kind": "int", "value": 35},
|
|
114
|
+
])
|
|
115
|
+
selectable = [i for i in items if i["kind"] == "item"]
|
|
116
|
+
assert [i["key"] for i in selectable] == ["shell", "vision"]
|
|
117
|
+
assert "●" in selectable[0]["label"] and "on" in selectable[0]["label"]
|
|
118
|
+
assert "○" in selectable[1]["label"] and "off" in selectable[1]["label"]
|
|
119
|
+
# 数值项不可选,以 hint 呈现并带用法提示
|
|
120
|
+
hints = [i["label"] for i in items if i["kind"] == "hint"]
|
|
121
|
+
assert any("max-steps" in h and "35" in h and "/set" in h for h in hints)
|
|
122
|
+
assert "Enter" in items[-1]["label"]
|
|
123
|
+
|
|
124
|
+
|
|
107
125
|
def test_picker_rows_fit_and_highlight_cursor():
|
|
108
126
|
state = TuiState("m", "/ws", 5)
|
|
109
127
|
items = [{"kind": "item", "label": f"选项 {i}"} for i in range(20)]
|
|
@@ -259,6 +259,83 @@ def test_plain_dispatch_submits_and_exit(tmp_path):
|
|
|
259
259
|
assert "write_file" in r.messages[0][1]
|
|
260
260
|
|
|
261
261
|
|
|
262
|
+
# --- /set: session-adjustable settings ------------------------------------------
|
|
263
|
+
|
|
264
|
+
def test_set_bare_lists_current_values_and_opens_picker(tmp_path):
|
|
265
|
+
wb = _wb(tmp_path, [])
|
|
266
|
+
r = wb.dispatch("/set")
|
|
267
|
+
text = "".join(t for _, t in r.messages)
|
|
268
|
+
assert "shell" in text and "max-steps" in text and "35" in text
|
|
269
|
+
assert r.overlay == "set"
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def test_set_bool_toggle_and_explicit_values(tmp_path):
|
|
273
|
+
wb = _wb(tmp_path, [])
|
|
274
|
+
wb._tool_names = ["stale"] # 预填缓存,翻转后必须失效
|
|
275
|
+
|
|
276
|
+
r = wb.dispatch("/set shell on")
|
|
277
|
+
assert wb.cfg.shell is True
|
|
278
|
+
assert r.messages[0][0] == "ok" and "下一轮生效" in r.messages[0][1]
|
|
279
|
+
assert any("不可撤销" in t for c, t in r.messages), "shell 开启要重述信任警示"
|
|
280
|
+
assert wb._tool_names is None, "影响工具集的设置要清空 /tools 缓存"
|
|
281
|
+
|
|
282
|
+
r = wb.dispatch("/set shell") # 不带值 = 切换
|
|
283
|
+
assert wb.cfg.shell is False
|
|
284
|
+
|
|
285
|
+
r = wb.dispatch("/set vision true")
|
|
286
|
+
assert wb.cfg.vision is True and r.messages[0][0] == "ok"
|
|
287
|
+
r = wb.dispatch("/set vision 0")
|
|
288
|
+
assert wb.cfg.vision is False
|
|
289
|
+
|
|
290
|
+
# 关到已是 off 的值:友好提示,不算错误
|
|
291
|
+
r = wb.dispatch("/set vision off")
|
|
292
|
+
assert wb.cfg.vision is False and r.messages[0][0] == "dim"
|
|
293
|
+
|
|
294
|
+
r = wb.dispatch("/set shell maybe")
|
|
295
|
+
assert r.messages[0][0] == "err" and wb.cfg.vision is False
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def test_set_by_index_and_underscore_alias(tmp_path):
|
|
299
|
+
wb = _wb(tmp_path, [])
|
|
300
|
+
r = wb.dispatch("/set 1 on") # 序号 1 = shell
|
|
301
|
+
assert wb.cfg.shell is True
|
|
302
|
+
r = wb.dispatch("/set max_steps 50") # 下划线别名
|
|
303
|
+
assert wb.cfg.max_steps == 50
|
|
304
|
+
r = wb.dispatch("/set 99 on")
|
|
305
|
+
assert r.messages[0][0] == "err" and "可用" in r.messages[0][1]
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def test_set_numeric_validation(tmp_path):
|
|
309
|
+
wb = _wb(tmp_path, [])
|
|
310
|
+
wb.dispatch("/set max-steps 50")
|
|
311
|
+
assert wb.cfg.max_steps == 50
|
|
312
|
+
wb.dispatch("/set timeout 30.5")
|
|
313
|
+
assert wb.cfg.timeout == 30.5
|
|
314
|
+
wb.dispatch("/set attempts 3")
|
|
315
|
+
assert wb.cfg.attempts == 3
|
|
316
|
+
# 缺值 / 非数值 / 非法数值都有可行动的报错
|
|
317
|
+
assert wb.dispatch("/set max-steps").messages[0][0] == "err"
|
|
318
|
+
assert wb.dispatch("/set max-steps abc").messages[0][0] == "err"
|
|
319
|
+
assert wb.dispatch("/set timeout -1").messages[0][0] == "err"
|
|
320
|
+
assert wb.cfg.max_steps == 50 and wb.cfg.timeout == 30.5
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def test_set_unknown_key_lists_available(tmp_path):
|
|
324
|
+
wb = _wb(tmp_path, [])
|
|
325
|
+
r = wb.dispatch("/set turbo on")
|
|
326
|
+
assert r.messages[0][0] == "err" and "shell" in r.messages[0][1]
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def test_set_tools_cache_reflected_in_next_tools_listing(tmp_path):
|
|
330
|
+
wb = _wb(tmp_path, [])
|
|
331
|
+
wb.dispatch("/tools") # 填充缓存
|
|
332
|
+
assert wb._tool_names is not None and "run_command" not in wb._tool_names
|
|
333
|
+
wb.dispatch("/set shell on") # 缓存失效
|
|
334
|
+
assert wb._tool_names is None
|
|
335
|
+
r = wb.dispatch("/tools") # 重新派生,包含 shell 工具
|
|
336
|
+
assert "run_command" in r.messages[0][1]
|
|
337
|
+
|
|
338
|
+
|
|
262
339
|
def test_undo_targets_last_session_run(tmp_path):
|
|
263
340
|
wb = _wb(tmp_path, WRITE_THEN_ANSWER + [{"content": "完成"}])
|
|
264
341
|
wb.open()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|