lithe-cli 0.8.2__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.

Files changed (32) hide show
  1. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/PKG-INFO +10 -2
  2. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/README.md +8 -0
  3. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/__init__.py +1 -1
  4. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/agent.py +1 -0
  5. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/commands.py +1 -0
  6. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/config.py +11 -0
  7. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/main.py +7 -0
  8. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/profiles.py +16 -0
  9. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/ttui.py +44 -3
  10. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/tui.py +49 -3
  11. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/workbench.py +67 -6
  12. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli.egg-info/PKG-INFO +10 -2
  13. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli.egg-info/requires.txt +1 -1
  14. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/pyproject.toml +1 -1
  15. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/tests/test_profiles.py +21 -0
  16. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/tests/test_tui_v2.py +15 -0
  17. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/tests/test_workbench.py +63 -0
  18. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/LICENSE +0 -0
  19. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/__main__.py +0 -0
  20. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/prompts.py +0 -0
  21. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/py.typed +0 -0
  22. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/sessions.py +0 -0
  23. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/setup.py +0 -0
  24. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli/ui.py +0 -0
  25. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli.egg-info/SOURCES.txt +0 -0
  26. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli.egg-info/dependency_links.txt +0 -0
  27. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli.egg-info/entry_points.txt +0 -0
  28. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/lithe_cli.egg-info/top_level.txt +0 -0
  29. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/setup.cfg +0 -0
  30. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/tests/test_cli.py +0 -0
  31. {lithe_cli-0.8.2 → lithe_cli-0.8.3}/tests/test_cli_sessions.py +0 -0
  32. {lithe_cli-0.8.2 → 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.2
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.17
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
@@ -222,6 +222,14 @@ turning `shell` on restates its trust warning. `/tools` re-derives the
222
222
  registry after a capability flip, so the listing always matches what the
223
223
  next turn will see.
224
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
+
225
233
  ### Extra capabilities
226
234
 
227
235
  The kernel ships these as bundles; the CLI grants them per flag:
@@ -173,6 +173,14 @@ turning `shell` on restates its trust warning. `/tools` re-derives the
173
173
  registry after a capability flip, so the listing always matches what the
174
174
  next turn will see.
175
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
+
176
184
  ### Extra capabilities
177
185
 
178
186
  The kernel ships these as bundles; the CLI grants them per flag:
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.8.2"
3
+ __version__ = "0.8.3"
@@ -100,6 +100,7 @@ def build_llm(cfg: Config) -> LLMConfig:
100
100
  "attempts": cfg.attempts,
101
101
  "stream": cfg.stream,
102
102
  "context_window": cfg.context_window,
103
+ "reasoning_effort": cfg.reasoning_effort,
103
104
  }
104
105
  # The CLI's transport field defaults to "chat" and is only overridden by
105
106
  # offline tests (custom transports); the default must not clobber a
@@ -22,6 +22,7 @@ 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 档案"),
26
27
  "set": ("[名称] [值]", "查看/调整运行设置(F5 同效);开关项回车或 on/off,下一轮生效"),
27
28
  "tools": ("", "列出已注册的工具"),
@@ -80,6 +80,10 @@ class Config:
80
80
  # Wire protocol ("chat" | "responses") or a custom LLMTransport instance.
81
81
  # Not exposed as a flag: the injection point for offline tests.
82
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
83
87
 
84
88
  @property
85
89
  def has_endpoint(self) -> bool:
@@ -260,6 +264,11 @@ def load_config(args: Any) -> Config:
260
264
  f"provider {provider!r} 的 preset 未提供 base_url;"
261
265
  f"请在档案中手写 base_url。"
262
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
263
272
  return Config(
264
273
  api_key=(
265
274
  g("api_key", None) or os.environ.get(ENV_API_KEY) or saved.get("api_key")
@@ -268,6 +277,8 @@ def load_config(args: Any) -> Config:
268
277
  model=(g("model", None) or os.environ.get(ENV_MODEL) or saved.get("model")),
269
278
  profile=active,
270
279
  provider=provider,
280
+ reasoning_effort=(effort.strip() if isinstance(effort, str) and effort.strip()
281
+ else None),
271
282
  store_dir=store_dir,
272
283
  workspace_dir=workspace_dir,
273
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)
@@ -62,6 +62,9 @@ def _clean_endpoint(data: dict) -> dict:
62
62
  provider = data.get("provider")
63
63
  if isinstance(provider, str) and provider.strip():
64
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()
65
68
  for k in ("context_window",):
66
69
  v = data.get(k)
67
70
  if isinstance(v, int) and v > 0:
@@ -209,6 +212,19 @@ class ProfileStore:
209
212
  self._save(data["active"], data["profiles"])
210
213
  return True
211
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
+
212
228
  def cache_models(self, name: str, models: list[str]) -> bool:
213
229
  data = self.load()
214
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,9 +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 模型 · F5 设置 "
136
+ return f" ● {state.status} · Ctrl+C 取消 · F3 会话 · F4 模型 · F6 推理 "
135
137
  return (f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
136
- f" · F5 设置 · /help ")
138
+ f" · F5 设置 · F6 推理 · /help ")
137
139
 
138
140
 
139
141
  # -- input: completion + persistent history ------------------------------------
@@ -345,6 +347,7 @@ class LitheApp(App):
345
347
  Binding("f3", "open_sessions", "会话", priority=True),
346
348
  Binding("f4", "open_model", "模型", priority=True),
347
349
  Binding("f5", "open_set", "设置", priority=True),
350
+ Binding("f6", "open_reasoning", "推理", priority=True),
348
351
  Binding("ctrl+c", "cancel_or_exit", "取消/退出", priority=True),
349
352
  ]
350
353
 
@@ -436,6 +439,7 @@ class LitheApp(App):
436
439
  st = self.state
437
440
  st.model = self.cfg.model or "(scripted)"
438
441
  st.profile = self.cfg.profile or ""
442
+ st.reasoning_effort = self.cfg.reasoning_effort
439
443
  if self.wb.current is not None:
440
444
  st.session_id = self.wb.current["id"]
441
445
  st.session_title = self.wb.current.get("title") or ""
@@ -587,7 +591,7 @@ class LitheApp(App):
587
591
  return
588
592
  if r.awaitable is not None:
589
593
  asyncio.create_task(r.awaitable())
590
- if r.overlay in ("sessions", "model", "set"):
594
+ if r.overlay in ("sessions", "model", "set", "reasoning"):
591
595
  self._open_picker(r.overlay)
592
596
  if r.overlay == "rebuild" and self._current_cid() is not None:
593
597
  self._activate(self._current_cid())
@@ -666,6 +670,21 @@ class LitheApp(App):
666
670
  "运行设置", items,
667
671
  "Enter 切换开关 · 数值项用 /set 名称 值 · Esc 关闭",
668
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)
669
688
 
670
689
  def action_open_sessions(self) -> None:
671
690
  if self.mode == "chat" and not isinstance(self.screen, PickerModal):
@@ -679,6 +698,28 @@ class LitheApp(App):
679
698
  if not isinstance(self.screen, PickerModal):
680
699
  self._open_picker("set")
681
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
+
682
723
  def _set_picked(self, result) -> None:
683
724
  if not result or result[0] != "select" or not result[1]:
684
725
  return
@@ -153,6 +153,7 @@ class TuiState:
153
153
  self.context_tokens = None
154
154
  self.context_window = None
155
155
  self.context_percent = None
156
+ self.reasoning_effort: str | None = None
156
157
  self.tools: list[dict] = []
157
158
  self.feed: list[tuple[str, str]] = []
158
159
  self.streaming = ""
@@ -566,6 +567,8 @@ def _sidebar_lines(state: TuiState) -> list[tuple[str, str]]:
566
567
  lines.append(("dim", "◆ 模型"))
567
568
  label = f"{state.profile} · {state.model}" if state.profile else state.model
568
569
  lines.append(("", truncate(label, 30)))
570
+ if state.reasoning_effort:
571
+ lines.append(("dim", f"推理 {state.reasoning_effort} · F6 切换"))
569
572
  if state.context_window:
570
573
  lines.append(("dim", f"窗口 {state.context_window:,} · F4 切换"))
571
574
  else:
@@ -727,6 +730,26 @@ def models_overlay_items(
727
730
  return items
728
731
 
729
732
 
733
+ def reasoning_overlay_items(current: str | None,
734
+ levels: tuple[str, ...]) -> list[dict]:
735
+ """Items for the /reasoning picker: one selectable row per level."""
736
+ cur = current or "off"
737
+ items: list[dict] = []
738
+ for level in levels:
739
+ active = level == cur
740
+ label = {"off": "关闭(不发送该字段)"}.get(level, level)
741
+ items.append({
742
+ "kind": "item",
743
+ "label": f"{'●' if active else ' '} {label}",
744
+ "level": level,
745
+ "active": active,
746
+ })
747
+ items.append({"kind": "hint",
748
+ "label": "Enter 应用 · s 存为档案默认 · Esc 关闭"
749
+ "(个别模型支持其它值,可用 /reasoning 值 直达)"})
750
+ return items
751
+
752
+
730
753
  def settings_overlay_items(setting_rows: list[dict]) -> list[dict]:
731
754
  """Items for the /set picker: booleans are selectable (Enter toggles),
732
755
  numerics render as hints — a value cannot be picked from a list."""
@@ -812,6 +835,10 @@ class SlashCompleter(Completer):
812
835
  words = self.state.profile_names
813
836
  elif command == "resume":
814
837
  words = [f"#{row['id']}" for row in self.state.sessions]
838
+ elif command == "reasoning":
839
+ from .workbench import REASONING_LEVELS
840
+
841
+ words = list(REASONING_LEVELS)
815
842
  elif command == "set":
816
843
  from .workbench import _SETTING_DEFS
817
844
 
@@ -939,6 +966,7 @@ def build_app(
939
966
  kb.add("f3")(lambda event: on_line("/sessions"))
940
967
  kb.add("f4")(lambda event: on_line("/model"))
941
968
  kb.add("f5")(lambda event: on_line("/set"))
969
+ kb.add("f6")(lambda event: on_line("/reasoning"))
942
970
 
943
971
  @kb.add("escape", filter=overlay_open, eager=True)
944
972
  @kb.add("q", filter=overlay_open, eager=True)
@@ -1049,9 +1077,10 @@ def build_app(
1049
1077
  elif mode == "run":
1050
1078
  hint = " q 退出 · F2 侧栏 " if not state.running else " Ctrl+C 取消 · PgUp/PgDn 滚动 "
1051
1079
  elif state.running:
1052
- hint = " Ctrl+C 取消本轮 · F3 会话 · F4 模型 · F5 设置 "
1080
+ hint = " Ctrl+C 取消本轮 · F3 会话 · F4 模型 · F6 推理 "
1053
1081
  else:
1054
- hint = " Enter 发送 · F2 侧栏 · F3 会话 · F4 模型 · F5 设置 · /help 命令 "
1082
+ hint = (" Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
1083
+ " · F5 设置 · F6 推理 · /help 命令 ")
1055
1084
  return FormattedText(compose_footer(state, cols, hint))
1056
1085
 
1057
1086
  def _prompt_text():
@@ -1167,6 +1196,7 @@ async def run_screen(cfg, task, mode, args=None):
1167
1196
  def _refresh_meta(st):
1168
1197
  st.model = cfg.model or "(scripted)"
1169
1198
  st.profile = cfg.profile or ""
1199
+ st.reasoning_effort = cfg.reasoning_effort
1170
1200
  if wb.current is not None:
1171
1201
  st.session_id = wb.current["id"]
1172
1202
  st.session_title = wb.current.get("title") or ""
@@ -1263,6 +1293,12 @@ async def run_screen(cfg, task, mode, args=None):
1263
1293
  "set", "运行设置",
1264
1294
  settings_overlay_items(wb.settings_rows()),
1265
1295
  )
1296
+ elif name == "reasoning":
1297
+ state.open_overlay(
1298
+ "reasoning", "推理强度",
1299
+ reasoning_overlay_items(cfg.reasoning_effort,
1300
+ wb.REASONING_LEVELS),
1301
+ )
1266
1302
 
1267
1303
  def _after_switch():
1268
1304
  cid = _current_cid()
@@ -1284,6 +1320,9 @@ async def run_screen(cfg, task, mode, args=None):
1284
1320
  elif name == "set":
1285
1321
  # Enter on a boolean row toggles it (same call /set 名称 makes)
1286
1322
  _say_result(wb.set_setting(item["key"], "toggle"))
1323
+ elif name == "reasoning":
1324
+ _say_result(wb.set_reasoning(item["level"]))
1325
+ _refresh_meta(state)
1287
1326
 
1288
1327
  def on_overlay_key(name, key):
1289
1328
  if name == "sessions":
@@ -1316,6 +1355,13 @@ async def run_screen(cfg, task, mode, args=None):
1316
1355
  _say_result(wb.set_profile(item["profile"]))
1317
1356
  _say_result(wb.set_model(item["model"], save=True))
1318
1357
  _refresh_meta(state)
1358
+ elif name == "reasoning":
1359
+ if key == "s":
1360
+ item = state.overlay_current()
1361
+ state.close_overlay()
1362
+ if item:
1363
+ _say_result(wb.set_reasoning(item["level"], save=True))
1364
+ _refresh_meta(state)
1319
1365
 
1320
1366
  # -- input ----------------------------------------------------------------
1321
1367
 
@@ -1342,7 +1388,7 @@ async def run_screen(cfg, task, mode, args=None):
1342
1388
  return
1343
1389
  if r.awaitable is not None:
1344
1390
  asyncio.create_task(r.awaitable())
1345
- if r.overlay in ("sessions", "model", "set"):
1391
+ if r.overlay in ("sessions", "model", "set", "reasoning"):
1346
1392
  _open_picker(r.overlay)
1347
1393
  if r.overlay == "rebuild":
1348
1394
  _after_switch()
@@ -46,12 +46,17 @@ _SETTING_DEFS: list[tuple[str, str, str, str]] = [
46
46
  ("max-steps", "max_steps", "工具循环步数上限", "int"),
47
47
  ("timeout", "timeout", "单次模型调用超时(秒)", "float"),
48
48
  ("attempts", "attempts", "模型调用重试次数", "int"),
49
+ ("reasoning-effort", "reasoning_effort",
50
+ "推理强度(off/minimal/low/medium/high,原样透传)", "enum"),
49
51
  ]
50
52
  # Settings whose change alters the next turn's tool registry (vs. sampling
51
53
  # or rendering knobs): flipping them invalidates the /tools cache.
52
54
  _TOOL_AFFECTING = {"shell", "code", "vision", "download"}
53
55
  _TRUTHY = {"on", "true", "1", "开"}
54
56
  _FALSY = {"off", "false", "0", "关"}
57
+ # Reasoning levels offered by /reasoning; any other typed token passes
58
+ # through verbatim (rare per-model values like "none" stay reachable).
59
+ REASONING_LEVELS = ("off", "minimal", "low", "medium", "high")
55
60
 
56
61
 
57
62
  class Workbench:
@@ -258,6 +263,41 @@ class Workbench:
258
263
  self.sessions.set_meta(self.current["id"], {"model": name})
259
264
  return result
260
265
 
266
+ def set_reasoning(self, arg: str, *, save: bool = False) -> ActionResult:
267
+ """``/reasoning`` — view / set the reasoning-effort knob.
268
+
269
+ ``arg`` empty → listing + picker overlay; otherwise a level (or any
270
+ verbatim token); ``off`` clears. ``--save`` persists to the profile.
271
+ """
272
+ result = ActionResult()
273
+ arg = arg.strip()
274
+ if not arg:
275
+ current = self.cfg.reasoning_effort or "off"
276
+ result.say("dim", f"当前推理强度:{current}")
277
+ for i, level in enumerate(REASONING_LEVELS, 1):
278
+ mark = "●" if level == current else " "
279
+ result.say("dim", f" {mark} {i}. {level}")
280
+ result.say("dim", "(/reasoning 级别 或 /reasoning 序号;off 表示不发送"
281
+ "该字段;--save 存为档案默认)")
282
+ result.overlay = "reasoning"
283
+ return result
284
+ if arg.isdigit():
285
+ idx = int(arg) - 1
286
+ if not 0 <= idx < len(REASONING_LEVELS):
287
+ result.say("err", f"序号超出范围(1–{len(REASONING_LEVELS)})")
288
+ return result
289
+ arg = REASONING_LEVELS[idx]
290
+ r = self.set_setting("reasoning-effort", arg)
291
+ result.messages.extend(r.messages)
292
+ if r.messages and r.messages[0][0] == "ok" and save:
293
+ if self.cfg.profile:
294
+ self.profiles.set_reasoning_effort(
295
+ self.cfg.profile, self.cfg.reasoning_effort)
296
+ result.say("ok", f"(已存为档案 {self.cfg.profile} 默认)")
297
+ else:
298
+ result.say("dim", "(没有已保存档案,--save 未生效)")
299
+ return result
300
+
261
301
  def set_profile(self, name: str) -> ActionResult:
262
302
  result = ActionResult(changed=True)
263
303
  try:
@@ -462,6 +502,17 @@ class Workbench:
462
502
  else:
463
503
  result.say("err", f"{ukey} 是开关:on / off(不带值则为切换)")
464
504
  return result
505
+ elif kind == "enum":
506
+ token = value.strip()
507
+ if not token:
508
+ known = "、".join(REASONING_LEVELS)
509
+ result.say("err", f"用法:/reasoning 级别({known};当前 "
510
+ f"{current or 'off'})")
511
+ return result
512
+ # "off" clears the knob (nothing sent); other tokens pass
513
+ # through verbatim — which values the model accepts is the
514
+ # endpoint's call (400 diagnostics catch mistakes).
515
+ new = None if token.lower() == "off" else token
465
516
  else:
466
517
  if not value.strip():
467
518
  result.say("err", f"用法:/set {ukey} 值(当前 {current})")
@@ -475,14 +526,16 @@ class Workbench:
475
526
  result.say("err", f"{ukey} 必须为正数")
476
527
  return result
477
528
  if new == current:
478
- result.say("dim", f"{label}:已是 {new}")
529
+ result.say("dim", f"{label}:已是 {new if new is not None else 'off'}")
479
530
  return result
480
531
  setattr(self.cfg, attr, new)
481
532
  if ukey in _TOOL_AFFECTING:
482
533
  self._tool_names = None # /tools must re-derive the registry
483
534
  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
535
+ shown = "on" if new is True else "off" \
536
+ if new is False or new is None else new
537
+ was = "on" if current is True else "off" \
538
+ if current is False or current is None else current
486
539
  result.say("ok", f"{ukey}:{was} → {shown},下一轮生效")
487
540
  if ukey == "shell" and new is True:
488
541
  result.say("warn", "run_command 以当前用户权限执行、非沙箱、结果不可撤销")
@@ -581,15 +634,23 @@ class Workbench:
581
634
  if cmd == "set":
582
635
  if not arg:
583
636
  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"]
637
+ value = row["value"]
638
+ shown = "on" if value is True else "off" \
639
+ if value is False or value is None else value
640
+ hint = "" if row["kind"] != "enum" \
641
+ else "(/reasoning 或 F6 调整)"
586
642
  result.say("dim",
587
- f" {row['key']:<10} {str(shown):<6} {row['label']}")
643
+ f" {row['key']:<10} {str(shown):<6} "
644
+ f"{row['label']}{hint}")
588
645
  result.say("dim", "(/set 名称 on|off 或 /set 序号;数值项 /set 名称 值)")
589
646
  result.overlay = "set"
590
647
  return result
591
648
  key, _, value = arg.partition(" ")
592
649
  return self.set_setting(key, value)
650
+ if cmd == "reasoning":
651
+ save = "--save" in arg
652
+ level = arg.replace("--save", "").strip()
653
+ return self.set_reasoning(level, save=save)
593
654
  if cmd == "sidebar":
594
655
  result.toggle_sidebar = True
595
656
  return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.8.2
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.17
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
@@ -222,6 +222,14 @@ turning `shell` on restates its trust warning. `/tools` re-derives the
222
222
  registry after a capability flip, so the listing always matches what the
223
223
  next turn will see.
224
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
+
225
233
  ### Extra capabilities
226
234
 
227
235
  The kernel ships these as bundles; the CLI grants them per flag:
@@ -1,4 +1,4 @@
1
- lithe>=0.9.17
1
+ lithe>=0.9.18
2
2
  prompt-toolkit>=3.0.38
3
3
  textual>=1.0
4
4
 
@@ -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.17", "prompt-toolkit>=3.0.38", "textual>=1.0"]
12
+ dependencies = ["lithe>=0.9.18", "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",
@@ -293,3 +293,24 @@ def test_endpoint_roundtrips_provider_field(tmp_path, monkeypatch):
293
293
  # 无 provider 的档案不受影响
294
294
  store.upsert("plain", "https://p.example", "sk", "m")
295
295
  assert "provider" not in fresh.endpoint("plain")
296
+
297
+
298
+ def test_reasoning_effort_profile_roundtrip(tmp_path, monkeypatch):
299
+ from lithe_cli.config import load_config
300
+
301
+ monkeypatch.setenv("LITHE_HOME", str(tmp_path / "home"))
302
+ for var in ("LITHE_API_KEY", "LITHE_BASE_URL", "LITHE_MODEL",
303
+ "LITHE_PROFILE", "LITHE_PROVIDER"):
304
+ monkeypatch.delenv(var, raising=False)
305
+ store = ProfileStore()
306
+ store.upsert("zai", "", "sk", "glm-4.6", provider="zai")
307
+ store.set_reasoning_effort("zai", "high")
308
+
309
+ cfg = load_config(_PresetArgs())
310
+ assert cfg.reasoning_effort == "high", "档案字段经 load_config 进入 cfg"
311
+
312
+ # "off" 归一化为不发(None),并存回时清除字段
313
+ store.set_reasoning_effort("zai", "off")
314
+ cfg = load_config(_PresetArgs())
315
+ assert cfg.reasoning_effort is None
316
+ assert "reasoning_effort" not in store.endpoint("zai")
@@ -122,6 +122,21 @@ def test_settings_overlay_items_toggles_and_hints():
122
122
  assert "Enter" in items[-1]["label"]
123
123
 
124
124
 
125
+ def test_reasoning_overlay_items_marks_current():
126
+ from lithe_cli.tui import reasoning_overlay_items
127
+ from lithe_cli.workbench import REASONING_LEVELS
128
+
129
+ items = reasoning_overlay_items("high", REASONING_LEVELS)
130
+ selectable = [i for i in items if i["kind"] == "item"]
131
+ assert [i["level"] for i in selectable] == list(REASONING_LEVELS)
132
+ active = [i for i in selectable if i.get("active")]
133
+ assert len(active) == 1 and active[0]["level"] == "high"
134
+ # None(未设置)时高亮 off
135
+ items = reasoning_overlay_items(None, REASONING_LEVELS)
136
+ assert [i["level"] for i in items if i.get("active")] == ["off"]
137
+ assert "s 存为档案默认" in items[-1]["label"]
138
+
139
+
125
140
  def test_picker_rows_fit_and_highlight_cursor():
126
141
  state = TuiState("m", "/ws", 5)
127
142
  items = [{"kind": "item", "label": f"选项 {i}"} for i in range(20)]
@@ -336,6 +336,69 @@ def test_set_tools_cache_reflected_in_next_tools_listing(tmp_path):
336
336
  assert "run_command" in r.messages[0][1]
337
337
 
338
338
 
339
+ # --- /reasoning: in-session reasoning effort -------------------------------------
340
+
341
+ def test_reasoning_bare_lists_levels_and_opens_picker(tmp_path):
342
+ wb = _wb(tmp_path, [])
343
+ r = wb.dispatch("/reasoning")
344
+ text = "".join(t for _, t in r.messages)
345
+ assert "当前推理强度:off" in text
346
+ for level in ("off", "minimal", "low", "medium", "high"):
347
+ assert level in text
348
+ assert r.overlay == "reasoning"
349
+
350
+
351
+ def test_reasoning_set_off_and_verbatim(tmp_path):
352
+ wb = _wb(tmp_path, [])
353
+ r = wb.dispatch("/reasoning high")
354
+ assert wb.cfg.reasoning_effort == "high"
355
+ assert r.messages[0][0] == "ok" and "下一轮生效" in r.messages[0][1]
356
+
357
+ r = wb.dispatch("/reasoning off")
358
+ assert wb.cfg.reasoning_effort is None
359
+ assert "off" in r.messages[0][1]
360
+
361
+ # 不在档位里的值原样透传(个别模型的 none 等)
362
+ wb.dispatch("/reasoning none")
363
+ assert wb.cfg.reasoning_effort == "none"
364
+
365
+ # 序号选择:2 → minimal
366
+ wb.dispatch("/reasoning off")
367
+ wb.dispatch("/reasoning 2")
368
+ assert wb.cfg.reasoning_effort == "minimal"
369
+ assert wb.dispatch("/reasoning 99").messages[0][0] == "err"
370
+
371
+
372
+ def test_reasoning_save_persists_to_profile(tmp_path, monkeypatch):
373
+ monkeypatch.setenv("LITHE_HOME", str(tmp_path / "home"))
374
+ wb = _wb(tmp_path, [])
375
+ wb.profiles.upsert("zai", "", "sk", "glm-4.6", provider="zai")
376
+ wb.cfg.profile = "zai"
377
+ wb.dispatch("/reasoning high --save")
378
+ assert wb.profiles.endpoint("zai")["reasoning_effort"] == "high"
379
+ # off + --save 清除档案字段
380
+ wb.dispatch("/reasoning off --save")
381
+ assert "reasoning_effort" not in wb.profiles.endpoint("zai")
382
+
383
+
384
+ def test_reasoning_effort_reaches_llm_config(tmp_path):
385
+ from lithe_cli.agent import build_llm
386
+
387
+ wb = _wb(tmp_path, [])
388
+ wb.dispatch("/reasoning high")
389
+ llm = build_llm(wb.cfg)
390
+ assert llm.reasoning_effort == "high"
391
+ wb.dispatch("/reasoning off")
392
+ assert build_llm(wb.cfg).reasoning_effort is None
393
+
394
+
395
+ def test_set_listing_includes_reasoning_hint(tmp_path):
396
+ wb = _wb(tmp_path, [])
397
+ r = wb.dispatch("/set")
398
+ text = "".join(t for _, t in r.messages)
399
+ assert "reasoning-effort" in text and "/reasoning" in text
400
+
401
+
339
402
  def test_undo_targets_last_session_run(tmp_path):
340
403
  wb = _wb(tmp_path, WRITE_THEN_ANSWER + [{"content": "完成"}])
341
404
  wb.open()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes