lithe-cli 0.8.0__tar.gz → 0.8.3__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.3}/PKG-INFO +36 -6
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/README.md +34 -4
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/agent.py +30 -10
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/commands.py +3 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/config.py +46 -5
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/main.py +11 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/profiles.py +22 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/ttui.py +84 -3
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/tui.py +89 -3
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/workbench.py +171 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli.egg-info/PKG-INFO +36 -6
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/pyproject.toml +1 -1
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/tests/test_profiles.py +108 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/tests/test_tui_v2.py +33 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/tests/test_workbench.py +140 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/LICENSE +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli.egg-info/SOURCES.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/setup.cfg +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/tests/test_cli.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.8.0 → lithe_cli-0.8.3}/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.3
|
|
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.18
|
|
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,26 @@ 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
|
+
|
|
225
|
+
**Reasoning intensity**: `/reasoning` (or `F6`) picks a level —
|
|
226
|
+
`off / minimal / low / medium / high`, or any value your model accepts
|
|
227
|
+
(`none` on some) typed directly; `--save` persists it to the profile. The
|
|
228
|
+
kernel maps it per protocol (`reasoning_effort` on chat-completions,
|
|
229
|
+
`reasoning.effort` on Responses) and combines it with
|
|
230
|
+
`extra_body["reasoning"]` siblings such as OpenRouter's
|
|
231
|
+
`max_tokens`/`exclude`. The sidebar shows the active level when set.
|
|
232
|
+
|
|
203
233
|
### Extra capabilities
|
|
204
234
|
|
|
205
235
|
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,26 @@ 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
|
+
|
|
176
|
+
**Reasoning intensity**: `/reasoning` (or `F6`) picks a level —
|
|
177
|
+
`off / minimal / low / medium / high`, or any value your model accepts
|
|
178
|
+
(`none` on some) typed directly; `--save` persists it to the profile. The
|
|
179
|
+
kernel maps it per protocol (`reasoning_effort` on chat-completions,
|
|
180
|
+
`reasoning.effort` on Responses) and combines it with
|
|
181
|
+
`extra_body["reasoning"]` siblings such as OpenRouter's
|
|
182
|
+
`max_tokens`/`exclude`. The sidebar shows the active level when set.
|
|
183
|
+
|
|
154
184
|
### Extra capabilities
|
|
155
185
|
|
|
156
186
|
The kernel ships these as bundles; the CLI grants them per flag:
|
|
@@ -88,16 +88,36 @@ 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
|
+
"reasoning_effort": cfg.reasoning_effort,
|
|
104
|
+
}
|
|
105
|
+
# The CLI's transport field defaults to "chat" and is only overridden by
|
|
106
|
+
# offline tests (custom transports); the default must not clobber a
|
|
107
|
+
# preset that knows better (e.g. a future "responses" preset).
|
|
108
|
+
if cfg.transport != "chat":
|
|
109
|
+
overrides["transport"] = cfg.transport
|
|
110
|
+
if cfg.provider:
|
|
111
|
+
from lithe.bundles.providers import apply_preset
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
kwargs = apply_preset(cfg.provider, **overrides)
|
|
115
|
+
except ValueError as exc:
|
|
116
|
+
raise SystemExit(
|
|
117
|
+
f"{exc}。请修正档案里的 provider 字段,或清除它。"
|
|
118
|
+
) from exc
|
|
119
|
+
return LLMConfig(**kwargs)
|
|
120
|
+
return LLMConfig(**overrides)
|
|
101
121
|
|
|
102
122
|
|
|
103
123
|
def build_registry(cfg: Config) -> ToolRegistry:
|
|
@@ -22,7 +22,9 @@ COMMANDS: dict[str, tuple[str, str]] = {
|
|
|
22
22
|
"rename": ("标题", "重命名当前会话"),
|
|
23
23
|
"model": ("[名称|--save]", "查看/切换模型(F4 同效);--save 同时存为档案默认"),
|
|
24
24
|
"models": ("", "从端点拉取模型列表并缓存"),
|
|
25
|
+
"reasoning": ("[级别|--save]", "查看/设置推理强度(F6 同效);off/minimal/low/medium/high,下一轮生效"),
|
|
25
26
|
"profile": ("[名称]", "查看/切换 provider 档案"),
|
|
27
|
+
"set": ("[名称] [值]", "查看/调整运行设置(F5 同效);开关项回车或 on/off,下一轮生效"),
|
|
26
28
|
"tools": ("", "列出已注册的工具"),
|
|
27
29
|
"undo": ("[run]", "撤销当前会话最近一轮(或指定 run)的文件改动"),
|
|
28
30
|
"sidebar": ("", "显示/隐藏右侧状态栏(F2 同效)"),
|
|
@@ -47,7 +49,7 @@ class ActionResult:
|
|
|
47
49
|
action: str = "none" # none | submit | exit
|
|
48
50
|
text: str = "" # submit payload
|
|
49
51
|
messages: list[tuple[str, str]] = field(default_factory=list)
|
|
50
|
-
overlay: str | None = None # TUI picker: "sessions" | "model"
|
|
52
|
+
overlay: str | None = None # TUI picker: "sessions" | "model" | "set"
|
|
51
53
|
toggle_sidebar: bool = False
|
|
52
54
|
changed: bool = False # model/session changed → refresh banner/sidebar
|
|
53
55
|
# 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
|
|
@@ -75,6 +80,10 @@ class Config:
|
|
|
75
80
|
# Wire protocol ("chat" | "responses") or a custom LLMTransport instance.
|
|
76
81
|
# Not exposed as a flag: the injection point for offline tests.
|
|
77
82
|
transport: Any = "chat"
|
|
83
|
+
# Reasoning intensity (None = send nothing; "off" normalizes to None at
|
|
84
|
+
# load). Passed verbatim to the kernel's reasoning_effort — which values
|
|
85
|
+
# the current model accepts is the endpoint's call.
|
|
86
|
+
reasoning_effort: str | None = None
|
|
78
87
|
|
|
79
88
|
@property
|
|
80
89
|
def has_endpoint(self) -> bool:
|
|
@@ -130,7 +139,7 @@ def config_file() -> Path:
|
|
|
130
139
|
|
|
131
140
|
|
|
132
141
|
def load_saved_endpoint() -> dict:
|
|
133
|
-
"""Read the active profile's {api_key, base_url, model}; {} if none.
|
|
142
|
+
"""Read the active profile's {api_key, base_url, model, provider}; {} if none.
|
|
134
143
|
|
|
135
144
|
A corrupt file is treated as absent — a bad edit should cost the user
|
|
136
145
|
one re-prompt, not a broken CLI.
|
|
@@ -138,7 +147,8 @@ def load_saved_endpoint() -> dict:
|
|
|
138
147
|
from .profiles import ProfileStore
|
|
139
148
|
|
|
140
149
|
endpoint = ProfileStore().endpoint()
|
|
141
|
-
|
|
150
|
+
keys = (*_ENDPOINT_KEYS, "provider")
|
|
151
|
+
return {k: endpoint[k] for k in keys if endpoint.get(k)}
|
|
142
152
|
|
|
143
153
|
|
|
144
154
|
def _restrict_to_owner(path: Path, directory: bool = False) -> None:
|
|
@@ -229,15 +239,46 @@ def load_config(args: Any) -> Config:
|
|
|
229
239
|
)
|
|
230
240
|
if flag or os.environ.get(env)
|
|
231
241
|
)
|
|
242
|
+
# Vendor preset (profile "provider" field > LITHE_PROVIDER): fills
|
|
243
|
+
# base_url when nothing explicit set it — the preset's whole point —
|
|
244
|
+
# while every explicit value stays untouched. An unknown name is a
|
|
245
|
+
# config typo: die loudly like an unknown --profile, listing options.
|
|
246
|
+
provider = (os.environ.get(ENV_PROVIDER) or saved.get("provider")
|
|
247
|
+
or g("provider", None))
|
|
248
|
+
base_url = (
|
|
249
|
+
g("base_url", None) or os.environ.get(ENV_BASE_URL)
|
|
250
|
+
or saved.get("base_url")
|
|
251
|
+
)
|
|
252
|
+
if provider and not base_url:
|
|
253
|
+
try:
|
|
254
|
+
from lithe.bundles.providers import get_preset
|
|
255
|
+
|
|
256
|
+
base_url = get_preset(provider).get("base_url")
|
|
257
|
+
except ValueError as exc:
|
|
258
|
+
# get_preset's message already lists the known providers.
|
|
259
|
+
raise SystemExit(
|
|
260
|
+
f"{exc}。可手写 base_url,或从上述 preset 中选择。"
|
|
261
|
+
) from exc
|
|
262
|
+
if not base_url:
|
|
263
|
+
raise SystemExit(
|
|
264
|
+
f"provider {provider!r} 的 preset 未提供 base_url;"
|
|
265
|
+
f"请在档案中手写 base_url。"
|
|
266
|
+
)
|
|
267
|
+
# Reasoning effort: flag > saved profile field; "off" normalizes to None
|
|
268
|
+
# (send nothing). An in-session /reasoning overrides both.
|
|
269
|
+
effort = g("reasoning_effort", None) or saved.get("reasoning_effort")
|
|
270
|
+
if effort is not None and effort.strip().lower() == "off":
|
|
271
|
+
effort = None
|
|
232
272
|
return Config(
|
|
233
273
|
api_key=(
|
|
234
274
|
g("api_key", None) or os.environ.get(ENV_API_KEY) or saved.get("api_key")
|
|
235
275
|
),
|
|
236
|
-
base_url=
|
|
237
|
-
g("base_url", None) or os.environ.get(ENV_BASE_URL) or saved.get("base_url")
|
|
238
|
-
),
|
|
276
|
+
base_url=base_url,
|
|
239
277
|
model=(g("model", None) or os.environ.get(ENV_MODEL) or saved.get("model")),
|
|
240
278
|
profile=active,
|
|
279
|
+
provider=provider,
|
|
280
|
+
reasoning_effort=(effort.strip() if isinstance(effort, str) and effort.strip()
|
|
281
|
+
else None),
|
|
241
282
|
store_dir=store_dir,
|
|
242
283
|
workspace_dir=workspace_dir,
|
|
243
284
|
user_id=g("user", None) or DEFAULT_USER,
|
|
@@ -144,6 +144,13 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
144
144
|
sp.add_argument(
|
|
145
145
|
"--attempts", type=int, default=2, help="per-call retry attempts"
|
|
146
146
|
)
|
|
147
|
+
sp.add_argument(
|
|
148
|
+
"--reasoning-effort",
|
|
149
|
+
metavar="LEVEL",
|
|
150
|
+
default=None,
|
|
151
|
+
help="reasoning intensity (off/minimal/low/medium/high, model "
|
|
152
|
+
"dependent; profile field reasoning_effort; in-session /reasoning)",
|
|
153
|
+
)
|
|
147
154
|
|
|
148
155
|
run_p = sub.add_parser("run", help="run one task")
|
|
149
156
|
runtime(run_p)
|
|
@@ -454,9 +461,11 @@ def _cmd_config(args: Any) -> int:
|
|
|
454
461
|
for name in names:
|
|
455
462
|
ep = store.masked(name)
|
|
456
463
|
mark = "*" if name == active else " "
|
|
464
|
+
prov = f" [{ep['provider']}]" if ep.get("provider") else ""
|
|
457
465
|
print(
|
|
458
466
|
f"{mark} {ui.s(name, CYAN)} · {ep.get('model', '—')} "
|
|
459
467
|
f"@ {ep.get('base_url', '—')}(key {ep.get('api_key', '—')})"
|
|
468
|
+
f"{prov}"
|
|
460
469
|
)
|
|
461
470
|
print(ui.s("(* 为当前档案;config --use NAME 切换)", YELLOW))
|
|
462
471
|
return 0
|
|
@@ -482,6 +491,8 @@ def _cmd_config(args: Any) -> int:
|
|
|
482
491
|
masked = key if len(key) <= 8 else f"{key[:5]}…{key[-4:]}"
|
|
483
492
|
print(ui.kv("config", str(config_file())))
|
|
484
493
|
print(ui.kv("profile", str(store.active_name() or "—")))
|
|
494
|
+
if saved.get("provider"):
|
|
495
|
+
print(ui.kv("provider", saved["provider"]))
|
|
485
496
|
print(ui.kv("base_url", saved["base_url"]))
|
|
486
497
|
print(ui.kv("api_key", masked))
|
|
487
498
|
print(ui.kv("model", saved["model"]))
|
|
@@ -59,6 +59,12 @@ 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()
|
|
65
|
+
effort = data.get("reasoning_effort")
|
|
66
|
+
if isinstance(effort, str) and effort.strip():
|
|
67
|
+
out["reasoning_effort"] = effort.strip()
|
|
62
68
|
for k in ("context_window",):
|
|
63
69
|
v = data.get(k)
|
|
64
70
|
if isinstance(v, int) and v > 0:
|
|
@@ -169,6 +175,7 @@ class ProfileStore:
|
|
|
169
175
|
api_key: str,
|
|
170
176
|
model: str,
|
|
171
177
|
context_window: int | None = None,
|
|
178
|
+
provider: str | None = None,
|
|
172
179
|
) -> Path:
|
|
173
180
|
if not valid_name(name):
|
|
174
181
|
raise SystemExit(
|
|
@@ -179,6 +186,8 @@ class ProfileStore:
|
|
|
179
186
|
"model": model.strip()}
|
|
180
187
|
if context_window:
|
|
181
188
|
endpoint["context_window"] = int(context_window)
|
|
189
|
+
if provider and provider.strip():
|
|
190
|
+
endpoint["provider"] = provider.strip()
|
|
182
191
|
# keep a previously cached model list when the base_url is unchanged
|
|
183
192
|
old = data["profiles"].get(name) or {}
|
|
184
193
|
if old.get("cached_models") and old.get("base_url") == endpoint["base_url"]:
|
|
@@ -203,6 +212,19 @@ class ProfileStore:
|
|
|
203
212
|
self._save(data["active"], data["profiles"])
|
|
204
213
|
return True
|
|
205
214
|
|
|
215
|
+
def set_reasoning_effort(self, name: str, effort: str | None) -> bool:
|
|
216
|
+
"""Set (or clear, with None/"off") a profile's reasoning effort."""
|
|
217
|
+
data = self.load()
|
|
218
|
+
if name not in data["profiles"]:
|
|
219
|
+
return False
|
|
220
|
+
endpoint = data["profiles"][name]
|
|
221
|
+
if effort is None or effort.strip().lower() == "off":
|
|
222
|
+
endpoint.pop("reasoning_effort", None)
|
|
223
|
+
else:
|
|
224
|
+
endpoint["reasoning_effort"] = effort.strip()
|
|
225
|
+
self._save(data["active"], data["profiles"])
|
|
226
|
+
return True
|
|
227
|
+
|
|
206
228
|
def cache_models(self, name: str, models: list[str]) -> bool:
|
|
207
229
|
data = self.load()
|
|
208
230
|
if name not in data["profiles"]:
|
|
@@ -70,6 +70,8 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
70
70
|
out.append("[dim]◆ 模型[/]")
|
|
71
71
|
label = f"{state.profile} · {state.model}" if state.profile else state.model
|
|
72
72
|
out.append(f"[cyan]{label}[/]")
|
|
73
|
+
if state.reasoning_effort:
|
|
74
|
+
out.append(f"[dim]推理 {state.reasoning_effort} · F6 切换[/]")
|
|
73
75
|
if state.context_window:
|
|
74
76
|
out.append(f"[dim]窗口 {state.context_window:,} · F4 切换[/]")
|
|
75
77
|
else:
|
|
@@ -131,8 +133,9 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
131
133
|
|
|
132
134
|
def footer_text(state: TuiState) -> str:
|
|
133
135
|
if state.running:
|
|
134
|
-
return f" ● {state.status} · Ctrl+C 取消 · F3 会话 · F4 模型 "
|
|
135
|
-
return f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型
|
|
136
|
+
return f" ● {state.status} · Ctrl+C 取消 · F3 会话 · F4 模型 · F6 推理 "
|
|
137
|
+
return (f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
|
|
138
|
+
f" · F5 设置 · F6 推理 · /help ")
|
|
136
139
|
|
|
137
140
|
|
|
138
141
|
# -- input: completion + persistent history ------------------------------------
|
|
@@ -343,6 +346,8 @@ class LitheApp(App):
|
|
|
343
346
|
Binding("f2", "toggle_sidebar", "侧栏", priority=True),
|
|
344
347
|
Binding("f3", "open_sessions", "会话", priority=True),
|
|
345
348
|
Binding("f4", "open_model", "模型", priority=True),
|
|
349
|
+
Binding("f5", "open_set", "设置", priority=True),
|
|
350
|
+
Binding("f6", "open_reasoning", "推理", priority=True),
|
|
346
351
|
Binding("ctrl+c", "cancel_or_exit", "取消/退出", priority=True),
|
|
347
352
|
]
|
|
348
353
|
|
|
@@ -434,6 +439,7 @@ class LitheApp(App):
|
|
|
434
439
|
st = self.state
|
|
435
440
|
st.model = self.cfg.model or "(scripted)"
|
|
436
441
|
st.profile = self.cfg.profile or ""
|
|
442
|
+
st.reasoning_effort = self.cfg.reasoning_effort
|
|
437
443
|
if self.wb.current is not None:
|
|
438
444
|
st.session_id = self.wb.current["id"]
|
|
439
445
|
st.session_title = self.wb.current.get("title") or ""
|
|
@@ -585,7 +591,7 @@ class LitheApp(App):
|
|
|
585
591
|
return
|
|
586
592
|
if r.awaitable is not None:
|
|
587
593
|
asyncio.create_task(r.awaitable())
|
|
588
|
-
if r.overlay in ("sessions", "model"):
|
|
594
|
+
if r.overlay in ("sessions", "model", "set", "reasoning"):
|
|
589
595
|
self._open_picker(r.overlay)
|
|
590
596
|
if r.overlay == "rebuild" and self._current_cid() is not None:
|
|
591
597
|
self._activate(self._current_cid())
|
|
@@ -643,6 +649,42 @@ class LitheApp(App):
|
|
|
643
649
|
letter_actions={"s": "_picker_save_model",
|
|
644
650
|
"r": "_picker_fetch_models"},
|
|
645
651
|
), self._model_picked)
|
|
652
|
+
elif name == "set":
|
|
653
|
+
items = []
|
|
654
|
+
for row in self.wb.settings_rows():
|
|
655
|
+
value = row["value"]
|
|
656
|
+
if row["kind"] == "bool":
|
|
657
|
+
shown = "on" if value else "off"
|
|
658
|
+
items.append((
|
|
659
|
+
{"key": row["key"]},
|
|
660
|
+
f"{'[green]●[/] ' if value else '○ '}"
|
|
661
|
+
f"{row['key']:<10} {shown:<4}{row['label']}",
|
|
662
|
+
))
|
|
663
|
+
else:
|
|
664
|
+
items.append((
|
|
665
|
+
{"kind": "hint"},
|
|
666
|
+
f" {row['key']:<10} {value:<6}{row['label']}"
|
|
667
|
+
f"(/set {row['key']} 值)",
|
|
668
|
+
))
|
|
669
|
+
self.push_screen(PickerModal(
|
|
670
|
+
"运行设置", items,
|
|
671
|
+
"Enter 切换开关 · 数值项用 /set 名称 值 · Esc 关闭",
|
|
672
|
+
), self._set_picked)
|
|
673
|
+
elif name == "reasoning":
|
|
674
|
+
current = self.cfg.reasoning_effort or "off"
|
|
675
|
+
items = []
|
|
676
|
+
for level in self.wb.REASONING_LEVELS:
|
|
677
|
+
active = level == current
|
|
678
|
+
label = {"off": "关闭(不发送该字段)"}.get(level, level)
|
|
679
|
+
items.append((
|
|
680
|
+
{"level": level},
|
|
681
|
+
f"{'[green]●[/] ' if active else ' '}{label}",
|
|
682
|
+
))
|
|
683
|
+
self.push_screen(PickerModal(
|
|
684
|
+
"推理强度", items,
|
|
685
|
+
"Enter 应用 · s 存为档案默认 · Esc 关闭",
|
|
686
|
+
letter_actions={"s": "_picker_save_reasoning"},
|
|
687
|
+
), self._reasoning_picked)
|
|
646
688
|
|
|
647
689
|
def action_open_sessions(self) -> None:
|
|
648
690
|
if self.mode == "chat" and not isinstance(self.screen, PickerModal):
|
|
@@ -652,6 +694,45 @@ class LitheApp(App):
|
|
|
652
694
|
if not isinstance(self.screen, PickerModal):
|
|
653
695
|
self._open_picker("model")
|
|
654
696
|
|
|
697
|
+
def action_open_set(self) -> None:
|
|
698
|
+
if not isinstance(self.screen, PickerModal):
|
|
699
|
+
self._open_picker("set")
|
|
700
|
+
|
|
701
|
+
def action_open_reasoning(self) -> None:
|
|
702
|
+
if not isinstance(self.screen, PickerModal):
|
|
703
|
+
self._open_picker("reasoning")
|
|
704
|
+
|
|
705
|
+
def _reasoning_picked(self, result) -> None:
|
|
706
|
+
if not result or result[0] != "select" or not result[1]:
|
|
707
|
+
return
|
|
708
|
+
r = self.wb.set_reasoning(result[1]["level"])
|
|
709
|
+
for cls, text in r.messages:
|
|
710
|
+
self.state.say(cls, text)
|
|
711
|
+
self._refresh_meta()
|
|
712
|
+
self._refresh_chrome()
|
|
713
|
+
|
|
714
|
+
def _picker_save_reasoning(self, payload) -> None:
|
|
715
|
+
if not payload:
|
|
716
|
+
return
|
|
717
|
+
r = self.wb.set_reasoning(payload.get("level", ""), save=True)
|
|
718
|
+
for cls, text in r.messages:
|
|
719
|
+
self.state.say(cls, text)
|
|
720
|
+
self._refresh_meta()
|
|
721
|
+
self._refresh_chrome()
|
|
722
|
+
|
|
723
|
+
def _set_picked(self, result) -> None:
|
|
724
|
+
if not result or result[0] != "select" or not result[1]:
|
|
725
|
+
return
|
|
726
|
+
payload = result[1]
|
|
727
|
+
if payload.get("kind") == "hint":
|
|
728
|
+
return
|
|
729
|
+
r = self.wb.set_setting(payload["key"], "toggle")
|
|
730
|
+
for cls, text in r.messages:
|
|
731
|
+
self.state.say(cls, text)
|
|
732
|
+
if r.changed:
|
|
733
|
+
self._refresh_meta()
|
|
734
|
+
self._refresh_chrome()
|
|
735
|
+
|
|
655
736
|
def _sessions_picked(self, result) -> None:
|
|
656
737
|
if not result:
|
|
657
738
|
return
|