lithe-cli 0.8.3__tar.gz → 0.8.5__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.3 → lithe_cli-0.8.5}/PKG-INFO +1 -1
  2. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/__init__.py +1 -1
  3. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/commands.py +1 -1
  4. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/main.py +2 -1
  5. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/ttui.py +60 -5
  6. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/tui.py +30 -5
  7. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli.egg-info/PKG-INFO +1 -1
  8. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/tests/test_ttui.py +96 -1
  9. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/LICENSE +0 -0
  10. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/README.md +0 -0
  11. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/__main__.py +0 -0
  12. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/agent.py +0 -0
  13. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/config.py +0 -0
  14. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/profiles.py +0 -0
  15. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/prompts.py +0 -0
  16. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/py.typed +0 -0
  17. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/sessions.py +0 -0
  18. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/setup.py +0 -0
  19. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/ui.py +0 -0
  20. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli/workbench.py +0 -0
  21. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli.egg-info/SOURCES.txt +0 -0
  22. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli.egg-info/dependency_links.txt +0 -0
  23. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli.egg-info/entry_points.txt +0 -0
  24. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli.egg-info/requires.txt +0 -0
  25. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/lithe_cli.egg-info/top_level.txt +0 -0
  26. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/pyproject.toml +0 -0
  27. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/setup.cfg +0 -0
  28. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/tests/test_cli.py +0 -0
  29. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/tests/test_cli_sessions.py +0 -0
  30. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/tests/test_profiles.py +0 -0
  31. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/tests/test_tui_v2.py +0 -0
  32. {lithe_cli-0.8.3 → lithe_cli-0.8.5}/tests/test_workbench.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.8.3
3
+ Version: 0.8.5
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
 
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.8.3"
3
+ __version__ = "0.8.5"
@@ -24,7 +24,7 @@ COMMANDS: dict[str, tuple[str, str]] = {
24
24
  "models": ("", "从端点拉取模型列表并缓存"),
25
25
  "reasoning": ("[级别|--save]", "查看/设置推理强度(F6 同效);off/minimal/low/medium/high,下一轮生效"),
26
26
  "profile": ("[名称]", "查看/切换 provider 档案"),
27
- "set": ("[名称] [值]", "查看/调整运行设置(F5 同效);开关项回车或 on/off,下一轮生效"),
27
+ "set": ("[名称] [值]", "查看/调整运行设置(F5 同效);面板内空格连切不关闭、Enter 切换并关闭,下一轮生效"),
28
28
  "tools": ("", "列出已注册的工具"),
29
29
  "undo": ("[run]", "撤销当前会话最近一轮(或指定 run)的文件改动"),
30
30
  "sidebar": ("", "显示/隐藏右侧状态栏(F2 同效)"),
@@ -618,7 +618,8 @@ def _run_textual(cfg: Any, task: str | None, mode: str, args: Any) -> int:
618
618
  f"Textual 前端不可用({exc})。pip install textual,"
619
619
  "或用 --ui prompt 走旧版界面。"
620
620
  ) from exc
621
- return asyncio.run(run_textual_screen(cfg, task, mode, args))
621
+ # run_textual_screen is sync: it drives its own asyncio.run inside.
622
+ return run_textual_screen(cfg, task, mode, args)
622
623
 
623
624
 
624
625
  def main(argv: list[str] | None = None) -> int:
@@ -24,6 +24,7 @@ Known gap versus the prompt_toolkit screen: no in-app mouse-drag selection
24
24
  from __future__ import annotations
25
25
 
26
26
  import asyncio
27
+ from collections.abc import Callable
27
28
  from typing import Any
28
29
 
29
30
  from textual.app import App, ComposeResult
@@ -271,15 +272,20 @@ class PickerModal(ModalScreen):
271
272
  Binding("d", "letter('d')", show=False),
272
273
  Binding("r", "letter('r')", show=False),
273
274
  Binding("s", "letter('s')", show=False),
275
+ # In-place toggle for the settings picker: flips the focused row
276
+ # without dismissing, so several knobs change in one visit.
277
+ Binding("space", "toggle", "切换(不关闭)", priority=True),
274
278
  ]
275
279
 
276
280
  def __init__(self, title: str, items: list[tuple[dict, str]],
277
- hint: str = "", letter_actions: dict[str, str] | None = None):
281
+ hint: str = "", letter_actions: dict[str, str] | None = None,
282
+ live_toggle: Callable[[dict], str | None] | None = None):
278
283
  super().__init__()
279
284
  self.title = title
280
285
  self.items = items
281
286
  self.hint = hint
282
287
  self.letter_actions = letter_actions or {}
288
+ self.live_toggle = live_toggle
283
289
 
284
290
  def compose(self) -> ComposeResult:
285
291
  with Vertical(id="picker"):
@@ -316,6 +322,25 @@ class PickerModal(ModalScreen):
316
322
  payload = self._current_payload()
317
323
  self.dismiss(("letter", name, payload) if name else None)
318
324
 
325
+ def action_toggle(self) -> None:
326
+ """Flip the focused row in place: the ``live_toggle`` callback
327
+ applies the change and returns a rebuilt label (``None`` when the
328
+ row is not toggleable); the modal stays open."""
329
+ if self.live_toggle is None:
330
+ return
331
+ view = self.query_one("#picker-list", ListView)
332
+ index = view.index if view.index is not None else 0
333
+ if not 0 <= index < len(self.items):
334
+ return
335
+ payload = self.items[index][0]
336
+ label = self.live_toggle(payload)
337
+ if label is None:
338
+ return
339
+ self.items[index] = (payload, label)
340
+ row = view.children[index]
341
+ if row.children:
342
+ row.children[0].update(label)
343
+
319
344
 
320
345
  # -- the app ----------------------------------------------------------------------
321
346
 
@@ -524,6 +549,8 @@ class LitheApp(App):
524
549
  if t == "command_output":
525
550
  self.state.say(ev.get("style") or "", ev.get("text", ""))
526
551
  self._sync_feed()
552
+ self._refresh_meta() # e.g. /models just rewrote cached_models
553
+ self._refresh_chrome()
527
554
  return
528
555
  if t == "undo_done":
529
556
  self.state.say("ok", f"已撤销 {ev.get('reverted', 0)} 个操作"
@@ -661,19 +688,24 @@ class LitheApp(App):
661
688
  f"{row['key']:<10} {shown:<4}{row['label']}",
662
689
  ))
663
690
  else:
691
+ shown = "off" if value is None else value
664
692
  items.append((
665
693
  {"kind": "hint"},
666
- f" {row['key']:<10} {value:<6}{row['label']}"
694
+ f" {row['key']:<10} {shown!s:<6}{row['label']}"
667
695
  f"(/set {row['key']} 值)",
668
696
  ))
669
697
  self.push_screen(PickerModal(
670
698
  "运行设置", items,
671
- "Enter 切换开关 · 数值项用 /set 名称 值 · Esc 关闭",
699
+ "空格 切换(不关闭)· Enter 切换并关闭 · 数值项用 /set 名称 值"
700
+ " · Esc 关闭",
701
+ live_toggle=self._toggle_setting_live,
672
702
  ), self._set_picked)
673
703
  elif name == "reasoning":
704
+ from .workbench import REASONING_LEVELS
705
+
674
706
  current = self.cfg.reasoning_effort or "off"
675
707
  items = []
676
- for level in self.wb.REASONING_LEVELS:
708
+ for level in REASONING_LEVELS:
677
709
  active = level == current
678
710
  label = {"off": "关闭(不发送该字段)"}.get(level, level)
679
711
  items.append((
@@ -710,6 +742,7 @@ class LitheApp(App):
710
742
  self.state.say(cls, text)
711
743
  self._refresh_meta()
712
744
  self._refresh_chrome()
745
+ self._sync_feed()
713
746
 
714
747
  def _picker_save_reasoning(self, payload) -> None:
715
748
  if not payload:
@@ -719,6 +752,27 @@ class LitheApp(App):
719
752
  self.state.say(cls, text)
720
753
  self._refresh_meta()
721
754
  self._refresh_chrome()
755
+ self._sync_feed()
756
+
757
+ def _toggle_setting_live(self, payload) -> str | None:
758
+ """F5 picker's in-place toggle (space): flip the knob via the same
759
+ bare ``set_setting`` call /set makes, refresh the chrome, and hand
760
+ back the row's rebuilt label; hints are not toggleable."""
761
+ if not payload or payload.get("kind") == "hint":
762
+ return None
763
+ r = self.wb.set_setting(payload["key"]) # bare value toggles booleans
764
+ for cls, text in r.messages:
765
+ self.state.say(cls, text)
766
+ if r.changed:
767
+ self._refresh_meta()
768
+ self._refresh_chrome()
769
+ self._sync_feed()
770
+ row = next(row for row in self.wb.settings_rows()
771
+ if row["key"] == payload["key"])
772
+ value = row["value"]
773
+ shown = "on" if value else "off"
774
+ return (f"{'[green]●[/] ' if value else '○ '}"
775
+ f"{row['key']:<10} {shown:<4}{row['label']}")
722
776
 
723
777
  def _set_picked(self, result) -> None:
724
778
  if not result or result[0] != "select" or not result[1]:
@@ -726,12 +780,13 @@ class LitheApp(App):
726
780
  payload = result[1]
727
781
  if payload.get("kind") == "hint":
728
782
  return
729
- r = self.wb.set_setting(payload["key"], "toggle")
783
+ r = self.wb.set_setting(payload["key"]) # bare value toggles booleans
730
784
  for cls, text in r.messages:
731
785
  self.state.say(cls, text)
732
786
  if r.changed:
733
787
  self._refresh_meta()
734
788
  self._refresh_chrome()
789
+ self._sync_feed()
735
790
 
736
791
  def _sessions_picked(self, result) -> None:
737
792
  if not result:
@@ -766,11 +766,13 @@ def settings_overlay_items(setting_rows: list[dict]) -> list[dict]:
766
766
  "active": bool(value),
767
767
  })
768
768
  else:
769
+ shown = "off" if value is None else value
769
770
  items.append({"kind": "hint",
770
- "label": f" {row['key']:<10} {value:<6}{row['label']}"
771
+ "label": f" {row['key']:<10} {shown!s:<6}{row['label']}"
771
772
  f"(/set {row['key']} 值)"})
772
773
  items.append({"kind": "hint",
773
- "label": "Enter 切换开关 · 数值项用 /set 名称 值 · Esc 关闭"})
774
+ "label": "空格 切换(不关闭)· Enter 切换并关闭 · 数值项用 "
775
+ "/set 名称 值 · Esc 关闭"})
774
776
  return items
775
777
 
776
778
 
@@ -987,6 +989,10 @@ def build_app(
987
989
  def _overlay_enter(event):
988
990
  _select(state.overlay_current())
989
991
 
992
+ @kb.add("space", filter=overlay_open, eager=True)
993
+ def _overlay_space(event):
994
+ _key(" ")
995
+
990
996
  @kb.add("n", filter=overlay_open, eager=True)
991
997
  @kb.add("d", filter=overlay_open, eager=True)
992
998
  @kb.add("r", filter=overlay_open, eager=True)
@@ -1256,6 +1262,7 @@ async def run_screen(cfg, task, mode, args=None):
1256
1262
  if t == "command_output":
1257
1263
  state.say(ev.get("style") if ev.get("style") in _SAY_CLASSES
1258
1264
  else "dim", ev.get("text", ""))
1265
+ _refresh_meta(state) # e.g. /models just rewrote cached_models
1259
1266
  return
1260
1267
  if t == "undo_done":
1261
1268
  state.say("ok", "已撤销 " + str(ev.get("reverted", 0)) + " 个操作"
@@ -1294,10 +1301,12 @@ async def run_screen(cfg, task, mode, args=None):
1294
1301
  settings_overlay_items(wb.settings_rows()),
1295
1302
  )
1296
1303
  elif name == "reasoning":
1304
+ from .workbench import REASONING_LEVELS
1305
+
1297
1306
  state.open_overlay(
1298
1307
  "reasoning", "推理强度",
1299
1308
  reasoning_overlay_items(cfg.reasoning_effort,
1300
- wb.REASONING_LEVELS),
1309
+ REASONING_LEVELS),
1301
1310
  )
1302
1311
 
1303
1312
  def _after_switch():
@@ -1318,8 +1327,9 @@ async def run_screen(cfg, task, mode, args=None):
1318
1327
  _say_result(wb.set_model(item["model"]))
1319
1328
  _refresh_meta(state)
1320
1329
  elif name == "set":
1321
- # Enter on a boolean row toggles it (same call /set 名称 makes)
1322
- _say_result(wb.set_setting(item["key"], "toggle"))
1330
+ # Enter on a boolean row toggles it (same bare call /set makes)
1331
+ _say_result(wb.set_setting(item["key"]))
1332
+ _refresh_meta(state)
1323
1333
  elif name == "reasoning":
1324
1334
  _say_result(wb.set_reasoning(item["level"]))
1325
1335
  _refresh_meta(state)
@@ -1363,6 +1373,21 @@ async def run_screen(cfg, task, mode, args=None):
1363
1373
  _say_result(wb.set_reasoning(item["level"], save=True))
1364
1374
  _refresh_meta(state)
1365
1375
 
1376
+ elif name == "set":
1377
+ if key == " ":
1378
+ item = state.overlay_current()
1379
+ if not item: # hint rows are not toggleable
1380
+ return
1381
+ _say_result(wb.set_setting(item["key"]))
1382
+ _refresh_meta(state)
1383
+ row = next(r for r in wb.settings_rows()
1384
+ if r["key"] == item["key"])
1385
+ value = row["value"]
1386
+ shown = "on" if value else "off"
1387
+ item["label"] = (f"{'●' if value else '○'} "
1388
+ f"{row['key']:<10} {shown:<4}{row['label']}")
1389
+ state.invalidate()
1390
+
1366
1391
  # -- input ----------------------------------------------------------------
1367
1392
 
1368
1393
  def on_line(text):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.8.3
3
+ Version: 0.8.5
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
 
@@ -10,7 +10,13 @@ from conftest import _tc, make_config
10
10
 
11
11
  textual = pytest.importorskip("textual")
12
12
 
13
- from lithe_cli.ttui import LitheApp, footer_text, header_text, sidebar_markup # noqa: E402
13
+ from lithe_cli.ttui import ( # noqa: E402
14
+ LitheApp,
15
+ PickerModal,
16
+ footer_text,
17
+ header_text,
18
+ sidebar_markup,
19
+ )
14
20
  from lithe_cli.tui import TuiState # noqa: E402
15
21
 
16
22
  WRITE_THEN_ANSWER = [
@@ -306,3 +312,92 @@ def test_resolve_ui_defaults_to_textual(monkeypatch):
306
312
  assert _resolve_ui(args) == "prompt" # flag beats env
307
313
  monkeypatch.setenv("LITHE_UI", "garbage")
308
314
  assert _resolve_ui(Args()) == "textual" # unknown values fall back
315
+
316
+
317
+ def test_f6_opens_reasoning_picker_and_applies(tmp_path):
318
+ """Regression: F6 crashed with AttributeError (wb.REASONING_LEVELS)."""
319
+
320
+ async def scenario():
321
+ app = _app(tmp_path, [])
322
+ async with app.run_test(size=(100, 30)) as pilot:
323
+ await pilot.press("f6")
324
+ await pilot.pause()
325
+ assert isinstance(app.screen, PickerModal)
326
+ levels = [p["level"] for p, _ in app.screen.items]
327
+ assert levels == ["off", "minimal", "low", "medium", "high"]
328
+ for _ in range(4): # off -> high
329
+ await pilot.press("down")
330
+ await pilot.press("enter")
331
+ await pilot.pause()
332
+ assert app.cfg.reasoning_effort == "high"
333
+
334
+ asyncio.run(scenario())
335
+
336
+
337
+ def test_f5_settings_picker_toggles_bool(tmp_path):
338
+ """Regression: F5 crashed rendering the reasoning-effort row (None
339
+ value), and Enter on a bool row sent the literal token 'toggle',
340
+ which set_setting rejects — every toggle errored with 是开关."""
341
+
342
+ async def scenario():
343
+ app = _app(tmp_path, [])
344
+ async with app.run_test(size=(100, 30)) as pilot:
345
+ await pilot.press("f5")
346
+ await pilot.pause()
347
+ assert isinstance(app.screen, PickerModal)
348
+ keys = [p.get("key") for p, _ in app.screen.items]
349
+ assert keys[0] == "shell" # first bool row
350
+ assert app.cfg.shell is False
351
+ await pilot.press("enter") # toggle shell on
352
+ await pilot.pause()
353
+ assert app.cfg.shell is True
354
+ assert "shell:off → on" in _conv_text(app)
355
+
356
+ asyncio.run(scenario())
357
+
358
+
359
+ def test_f5_space_toggles_in_place_without_closing(tmp_path):
360
+ """Regression: Enter was the only toggle and it dismissed the picker,
361
+ so flipping several knobs meant reopening F5 per knob. Space now
362
+ flips the focused row in place and the modal stays open."""
363
+
364
+ async def scenario():
365
+ app = _app(tmp_path, [])
366
+ async with app.run_test(size=(100, 30)) as pilot:
367
+ await pilot.press("f5")
368
+ await pilot.pause()
369
+ assert isinstance(app.screen, PickerModal)
370
+ await pilot.press("space") # shell off -> on
371
+ await pilot.pause()
372
+ assert app.cfg.shell is True
373
+ assert isinstance(app.screen, PickerModal), "空格不得关闭设置面板"
374
+ await pilot.press("down")
375
+ await pilot.press("space") # code off -> on
376
+ await pilot.pause()
377
+ assert app.cfg.code is True and app.cfg.shell is True
378
+ assert isinstance(app.screen, PickerModal)
379
+ # the flipped row's label reflects the new state in place
380
+ labels = [label for _payload, label in app.screen.items]
381
+ assert any("shell" in text and "●" in text for text in labels)
382
+
383
+ asyncio.run(scenario())
384
+
385
+
386
+ def test_command_output_refreshes_model_candidates(tmp_path):
387
+ """Regression: /models rewrote cached_models in the profile, but the
388
+ session's F4 list and /model completion stayed stale until an
389
+ unrelated event happened to call _refresh_meta."""
390
+
391
+ async def scenario():
392
+ app = _app(tmp_path, [])
393
+ async with app.run_test(size=(100, 30)) as pilot:
394
+ await pilot.pause()
395
+ app.cfg.model = "fresh-model"
396
+ app.wb._emit(-1, {"type": "command_output", "style": "ok",
397
+ "text": "端点返回 2 个模型"})
398
+ await pilot.pause()
399
+ assert app.state.model == "fresh-model"
400
+ assert app.state.model_candidates[0] == "fresh-model"
401
+ assert "端点返回" in _conv_text(app)
402
+
403
+ asyncio.run(scenario())
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