lithe-cli 0.9.2__tar.gz → 0.9.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 (35) hide show
  1. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/PKG-INFO +3 -3
  2. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/README.md +1 -1
  3. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/__init__.py +1 -1
  4. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/agent.py +42 -8
  5. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/config.py +13 -6
  6. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/main.py +13 -7
  7. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/ttui.py +53 -1
  8. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/workbench.py +5 -0
  9. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli.egg-info/PKG-INFO +3 -3
  10. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli.egg-info/SOURCES.txt +1 -0
  11. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli.egg-info/requires.txt +1 -1
  12. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/pyproject.toml +1 -1
  13. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_cli.py +17 -0
  14. lithe_cli-0.9.5/tests/test_cli_guard.py +67 -0
  15. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_cli_subagents.py +22 -5
  16. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/LICENSE +0 -0
  17. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/__main__.py +0 -0
  18. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/commands.py +0 -0
  19. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/profiles.py +0 -0
  20. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/prompts.py +0 -0
  21. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/py.typed +0 -0
  22. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/sessions.py +0 -0
  23. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/setup.py +0 -0
  24. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/tui.py +0 -0
  25. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli/ui.py +0 -0
  26. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli.egg-info/dependency_links.txt +0 -0
  27. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli.egg-info/entry_points.txt +0 -0
  28. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/lithe_cli.egg-info/top_level.txt +0 -0
  29. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/setup.cfg +0 -0
  30. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_cli_budget_steer.py +0 -0
  31. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_cli_sessions.py +0 -0
  32. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_profiles.py +0 -0
  33. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_ttui.py +0 -0
  34. {lithe_cli-0.9.2 → lithe_cli-0.9.5}/tests/test_tui_v2.py +0 -0
  35. {lithe_cli-0.9.2 → lithe_cli-0.9.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.9.2
3
+ Version: 0.9.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
 
@@ -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.22
42
+ Requires-Dist: lithe>=0.9.26
43
43
  Requires-Dist: prompt-toolkit>=3.0.38
44
44
  Requires-Dist: textual>=1.0
45
45
  Provides-Extra: dev
@@ -260,7 +260,7 @@ The kernel ships these as bundles; the CLI grants them per flag:
260
260
  | `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
261
261
  | `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
262
262
  | `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
263
- | `--subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; `/set subagents` toggles in-session |
263
+ | `--subagents` / `--no-subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; **on by default** (the roster reuses already-enabled tools only — no new powers); `/set subagents` toggles in-session |
264
264
  | `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
265
265
 
266
266
  ```bash
@@ -211,7 +211,7 @@ The kernel ships these as bundles; the CLI grants them per flag:
211
211
  | `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
212
212
  | `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
213
213
  | `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
214
- | `--subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; `/set subagents` toggles in-session |
214
+ | `--subagents` / `--no-subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; **on by default** (the roster reuses already-enabled tools only — no new powers); `/set subagents` toggles in-session |
215
215
  | `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
216
216
 
217
217
  ```bash
@@ -1,3 +1,3 @@
1
1
  """lithe-cli: the command-line interface for the lithe agent kernel."""
2
2
 
3
- __version__ = "0.9.2"
3
+ __version__ = "0.9.5"
@@ -20,12 +20,14 @@ Everything here maps lithe's host contract onto CLI defaults:
20
20
 
21
21
  from __future__ import annotations
22
22
 
23
+ import asyncio
23
24
  import hashlib
24
25
  import json
25
26
  import shutil
26
27
  import sys
27
28
  import time
28
29
  import uuid
30
+ from collections.abc import Awaitable, Callable
29
31
  from pathlib import Path
30
32
  from typing import Any
31
33
 
@@ -37,7 +39,7 @@ from lithe.bundles import (
37
39
  Workspace,
38
40
  undo_run,
39
41
  )
40
- from lithe.bundles.command import register_command_tools
42
+ from lithe.bundles.command import make_command_guard, register_command_tools
41
43
  from lithe.bundles.download import register_download_tools
42
44
  from lithe.bundles.patch import register_apply_patch_tool
43
45
  from lithe.bundles.workspace import register_file_tools
@@ -48,11 +50,14 @@ from .ui import CYAN, GREEN, YELLOW, ui
48
50
 
49
51
  SYSTEM_PROMPT_BASE = (
50
52
  "你是运行在命令行里的助理,工作区是用户的当前目录。"
51
- "用提供的文件工具完成任务(读写前先读、谨慎修改);修改已有文件时优先用 edit_file 或 apply_patch 做局部修改,"
52
- "仅在新建文件或确需整体重写时使用 write_file。"
53
+ "文件路径一律用工作区内的相对路径,不要用绝对路径或 ../ 指向工作区之外。\n"
54
+ "用提供的文件工具完成任务:改文件前先读它,谨慎修改;"
55
+ "修改已有文件时优先用 edit_file 或 apply_patch 做局部修改,"
56
+ "仅在新建文件或确需整体重写时使用 write_file。\n"
57
+ "工具调用失败时,先读返回的错误信息,修正参数后重试,不要原样重发。\n"
53
58
  "只有用户明确要求计划/跟踪,或任务确有多个需要追踪的独立阶段时才调用 update_todos;"
54
59
  "普通问答、解释、单步操作和小改动不创建待办。已有清单仅在用户继续相关工作时更新,无关请求保持不变;"
55
- "更新前读取并保留相关的现有任务,条数按实际步骤确定,不使用固定数量。"
60
+ "更新前读取并保留相关的现有任务,条数按实际步骤确定,不使用固定数量。\n"
56
61
  "最后用简洁中文汇报结果。"
57
62
  )
58
63
 
@@ -94,7 +99,7 @@ def build_system_prompt(cfg: Config) -> str:
94
99
  "子代理与本对话共享预算,汇报时合并它们的结果。")
95
100
  if not extras:
96
101
  return SYSTEM_PROMPT_BASE
97
- return SYSTEM_PROMPT_BASE + "".join(extras)
102
+ return SYSTEM_PROMPT_BASE + "\n" + "\n".join(extras)
98
103
 
99
104
 
100
105
  def build_llm(cfg: Config) -> LLMConfig:
@@ -141,8 +146,13 @@ def build_llm(cfg: Config) -> LLMConfig:
141
146
  return LLMConfig(**overrides)
142
147
 
143
148
 
144
- def build_registry(cfg: Config) -> ToolRegistry:
145
- """Register the CLI's tool set against the configured workspace."""
149
+ def build_registry(cfg: Config, approver: Callable[[str], Awaitable[bool]] | None = None) -> ToolRegistry:
150
+ """Register the CLI's tool set against the configured workspace.
151
+
152
+ ``approver`` is the human-confirmation channel for destructive
153
+ ``run_command`` calls (the kernel guard's "approve" tier); without one
154
+ those are denied with guidance instead of running silently.
155
+ """
146
156
  reg = ToolRegistry()
147
157
 
148
158
  def workspace_for(ctx) -> Workspace:
@@ -165,6 +175,10 @@ def build_registry(cfg: Config) -> ToolRegistry:
165
175
  register_command_tools(
166
176
  reg, lambda ctx: cfg.workspace_dir.resolve(), CommandRunner()
167
177
  )
178
+ # Dangerous-command guard: catastrophic commands never run; the
179
+ # destructive-but-scoped tier (rm -r <path>, git push --force,
180
+ # sudo, ...) asks the approver first.
181
+ reg.add_middleware(make_command_guard(approver))
168
182
  if cfg.skills_dir is not None:
169
183
  from lithe.bundles.skills import SkillLibrary, register_skill_tool
170
184
 
@@ -350,6 +364,25 @@ def render_event(
350
364
  print(ui.reasoning(digest[:120]))
351
365
 
352
366
 
367
+ def interactive_approver() -> Callable[[str], Awaitable[bool]] | None:
368
+ """A stdin y/n approver for interactive line-mode front-ends.
369
+
370
+ Returns None on a non-TTY stdin (piped/scripted runs): nobody can
371
+ answer, so the guard's destructive tier denies instead of hanging.
372
+ """
373
+ if not sys.stdin.isatty():
374
+ return None
375
+
376
+ async def approver(command: str) -> bool:
377
+ from . import prompts
378
+
379
+ preview = command if len(command) <= 90 else command[:87] + "..."
380
+ return await asyncio.to_thread(
381
+ prompts.yes_no, f"⚠ 破坏性命令需确认,允许执行:{preview}", False)
382
+
383
+ return approver
384
+
385
+
353
386
  async def execute(
354
387
  cfg: Config,
355
388
  task: str,
@@ -359,6 +392,7 @@ async def execute(
359
392
  stop=None,
360
393
  conversation_id: int | None = None,
361
394
  inbox=None,
395
+ approver: Callable[[str], Awaitable[bool]] | None = None,
362
396
  ) -> tuple[str, dict, Any]:
363
397
  """Run one task end-to-end; returns (run_id, done_event, host).
364
398
 
@@ -371,7 +405,7 @@ async def execute(
371
405
  the steering channel: a queue of user texts the kernel drains at step
372
406
  boundaries and injects as user messages (see AgentRuntime.run).
373
407
  """
374
- reg = build_registry(cfg)
408
+ reg = build_registry(cfg, approver)
375
409
  host = build_host(cfg, reg)
376
410
  if cfg.subagents:
377
411
  register_subagents(cfg, host, reg)
@@ -9,7 +9,7 @@ silently hitting some third-party URL. Resolution order is flag > env >
9
9
  interactive terminal a missing endpoint triggers the wizard instead of
10
10
  the refusal — see :mod:`lithe_cli.setup`.
11
11
 
12
- Capability flags (all off unless asked for):
12
+ Capability flags (off unless asked for, except where noted):
13
13
 
14
14
  - ``--code`` sandboxed ``run_code`` / ``run_file`` tools (bwrap when
15
15
  available, passthrough otherwise);
@@ -23,7 +23,11 @@ Capability flags (all off unless asked for):
23
23
  - ``--document`` ``document_info`` + ``analyze_document`` (PDF/OOXML
24
24
  reading on the main endpoint; the content-block dialect
25
25
  comes from ``--document-format`` > the profile's
26
- ``document_format`` field > the provider preset).
26
+ ``document_format`` field > the provider preset);
27
+ - ``--subagents`` delegate/delegate_parallel on the default roster; ON by
28
+ default — the roster reuses already-enabled tools only
29
+ (no new powers), so this is a spend selector, not a
30
+ security gate; ``--no-subagents`` disables.
27
31
  """
28
32
 
29
33
  from __future__ import annotations
@@ -68,9 +72,12 @@ class Config:
68
72
  document_format: str | None = None
69
73
  document: bool = False
70
74
  # Subagent delegation (kernel bundles.subagents): grants delegate /
71
- # delegate_parallel on the CLI's default roster. Off by default — each
72
- # delegation is a full agent run, so token spend multiplies.
73
- subagents: bool = False
75
+ # delegate_parallel on the CLI's default roster. ON by default — the
76
+ # roster only carries already-registered tools (delegation adds no new
77
+ # powers; workers inherit the same sandbox, guards and budgets), so the
78
+ # knob is a token-spend selector, not a security gate. --no-subagents
79
+ # (or /set subagents off) opts out.
80
+ subagents: bool = True
74
81
  # Run budgets (kernel AgentHost): the run ends with status
75
82
  # "budget_exceeded" once cumulative cost / tokens cross the cap. None
76
83
  # disables the cap.
@@ -319,7 +326,7 @@ def load_config(args: Any) -> Config:
319
326
  if isinstance(document_format, str)
320
327
  and document_format.strip() else None),
321
328
  document=g("document", False),
322
- subagents=g("subagents", False),
329
+ subagents=g("subagents", True),
323
330
  max_cost=g("max_cost", None),
324
331
  max_total_tokens=g("max_total_tokens", None),
325
332
  temperature=(
@@ -106,10 +106,12 @@ def build_parser() -> argparse.ArgumentParser:
106
106
  )
107
107
  sp.add_argument(
108
108
  "--subagents",
109
- action="store_true",
110
- help="grant delegate/delegate_parallel (subagent delegation on "
111
- "the default roster: researcher/coder/operator; multiplies "
112
- "token spend)",
109
+ action=argparse.BooleanOptionalAction,
110
+ default=True,
111
+ help="grant delegate/delegate_parallel on the default roster "
112
+ "(researcher/coder/operator). Default: on — the roster only "
113
+ "reuses already-enabled tools; multiplies token spend "
114
+ "(--no-subagents disables)",
113
115
  )
114
116
  sp.add_argument(
115
117
  "--document-format",
@@ -490,15 +492,17 @@ def _cmd_doctor() -> int:
490
492
  print(ui.kv("mcp", f"{len(cfg.mcp_servers)} 个服务器:{names}"))
491
493
  else:
492
494
  print(ui.kv("mcp", "未配置(--mcp 或环境变量 LITHE_MCP)"))
493
- delegation = "已启用(delegate 可委派子代理,token 花费会放大)" \
494
- if cfg.subagents else "未启用(--subagents 显式授权)"
495
+ delegation = "已启用(delegate 可委派子代理,token 花费会放大;--no-subagents 关闭)" \
496
+ if cfg.subagents else "未启用(--subagents 开启)"
495
497
  print(ui.kv("subagents", delegation))
496
498
  print(ui.kv("color", "on" if ui.color else "off"))
497
499
  return 0
498
500
 
499
501
 
500
502
  def _cmd_run(cfg: Any, task: str) -> int:
501
- _, done, _ = asyncio.run(execute(cfg, task))
503
+ from .agent import interactive_approver
504
+
505
+ _, done, _ = asyncio.run(execute(cfg, task, approver=interactive_approver()))
502
506
  return 0 if done.get("status") == "done" else 1
503
507
 
504
508
 
@@ -611,9 +615,11 @@ def _chat_loop(
611
615
  title: str | None = None,
612
616
  ) -> int:
613
617
  """Plain (non-TTY) chat: same Workbench and commands as the full screen."""
618
+ from .agent import interactive_approver
614
619
  from .workbench import Workbench
615
620
 
616
621
  wb = Workbench(cfg)
622
+ wb.approver = interactive_approver() # y/n on stdin when a TTY exists
617
623
  opening = wb.open(
618
624
  resume=resume, continue_latest=continue_latest, title=title
619
625
  )
@@ -352,6 +352,34 @@ class PickerModal(ModalScreen):
352
352
  row.children[0].update(label)
353
353
 
354
354
 
355
+ # -- command approval --------------------------------------------------------
356
+
357
+ class ConfirmModal(ModalScreen):
358
+ """y/n on a destructive run_command: y allows, n/Esc refuses."""
359
+
360
+ BINDINGS = [
361
+ Binding("y", "allow", "允许"),
362
+ Binding("n", "refuse", "拒绝"),
363
+ Binding("escape", "refuse", "拒绝", show=False),
364
+ ]
365
+
366
+ def __init__(self, command: str):
367
+ super().__init__()
368
+ self.command = command
369
+
370
+ def compose(self) -> ComposeResult:
371
+ with Vertical(id="picker"):
372
+ yield Static("⚠ 破坏性命令需确认", id="picker-title")
373
+ yield Static(self.command, id="picker-hint")
374
+ yield Static("y 允许执行 · n/Esc 拒绝", id="picker-hint")
375
+
376
+ def action_allow(self) -> None:
377
+ self.dismiss(True)
378
+
379
+ def action_refuse(self) -> None:
380
+ self.dismiss(False)
381
+
382
+
355
383
  # -- the app ----------------------------------------------------------------------
356
384
 
357
385
  class LitheApp(App):
@@ -418,6 +446,9 @@ class LitheApp(App):
418
446
  from .workbench import Workbench
419
447
 
420
448
  self.wb = Workbench(self.cfg)
449
+ # Destructive run_command approval rides a modal; the turn task and
450
+ # the app share one loop, so the middleware can await the human.
451
+ self.wb.approver = self.confirm_command
421
452
  self.todo_store = JsonTodoStore(todo_store_path(self.cfg))
422
453
  self.version = __version__
423
454
  prompt = self.query_one("#prompt", HistoryInput)
@@ -940,6 +971,27 @@ class LitheApp(App):
940
971
 
941
972
  # -- one-shot run mode --------------------------------------------------------
942
973
 
974
+ async def confirm_command(self, command: str) -> bool:
975
+ """Await a human y/n on a destructive command (guard middleware).
976
+
977
+ Bounded: an abandoned modal times out as a refusal instead of
978
+ wedging the turn forever; any UI failure also refuses.
979
+ """
980
+ fut: asyncio.Future[bool] = asyncio.get_running_loop().create_future()
981
+
982
+ def _resolved(result) -> None:
983
+ if not fut.done():
984
+ fut.set_result(bool(result))
985
+
986
+ try:
987
+ self.push_screen(ConfirmModal(command), _resolved)
988
+ except Exception: # noqa: BLE001 — a broken UI denies, never runs
989
+ return False
990
+ try:
991
+ return await asyncio.wait_for(fut, timeout=300)
992
+ except Exception: # noqa: BLE001 — timeout / cancelled → refuse
993
+ return False
994
+
943
995
  async def _run_one_shot(self, text: str) -> None:
944
996
  from .agent import execute
945
997
 
@@ -952,7 +1004,7 @@ class LitheApp(App):
952
1004
  self._refresh_chrome()
953
1005
  try:
954
1006
  await execute(self.cfg, text, on_event=self.state.on_event,
955
- stop=stop)
1007
+ stop=stop, approver=self.confirm_command)
956
1008
  except Exception as exc: # noqa: BLE001
957
1009
  self.state.say("err", f"运行出错:{exc}")
958
1010
  finally:
@@ -76,6 +76,10 @@ class Workbench:
76
76
  self.store = JsonlRunStore(cfg.store_dir)
77
77
  self.sessions = SessionManager(self.store, cfg.user_id)
78
78
  self.current: dict | None = None
79
+ # Human-confirmation channel for destructive run_command calls
80
+ # (kernel guard). Line-mode front-ends install a stdin y/n approver;
81
+ # the Textual TUI installs a modal one. None → deny with guidance.
82
+ self.approver = None
79
83
  self.turns: dict[int, dict] = {}
80
84
  self.subscribers: list[Callable[[int, dict], None]] = []
81
85
  self._tool_names: list[str] | None = None
@@ -391,6 +395,7 @@ class Workbench:
391
395
  on_event=lambda ev: self._emit(cid, ev),
392
396
  stop=stop,
393
397
  inbox=inbox,
398
+ approver=self.approver,
394
399
  )
395
400
  status = done.get("status")
396
401
  if self.current and self.current["id"] == cid:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.9.2
3
+ Version: 0.9.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
 
@@ -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.22
42
+ Requires-Dist: lithe>=0.9.26
43
43
  Requires-Dist: prompt-toolkit>=3.0.38
44
44
  Requires-Dist: textual>=1.0
45
45
  Provides-Extra: dev
@@ -260,7 +260,7 @@ The kernel ships these as bundles; the CLI grants them per flag:
260
260
  | `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
261
261
  | `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
262
262
  | `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
263
- | `--subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; `/set subagents` toggles in-session |
263
+ | `--subagents` / `--no-subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; **on by default** (the roster reuses already-enabled tools only — no new powers); `/set subagents` toggles in-session |
264
264
  | `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
265
265
 
266
266
  ```bash
@@ -24,6 +24,7 @@ lithe_cli.egg-info/requires.txt
24
24
  lithe_cli.egg-info/top_level.txt
25
25
  tests/test_cli.py
26
26
  tests/test_cli_budget_steer.py
27
+ tests/test_cli_guard.py
27
28
  tests/test_cli_sessions.py
28
29
  tests/test_cli_subagents.py
29
30
  tests/test_profiles.py
@@ -1,4 +1,4 @@
1
- lithe>=0.9.22
1
+ lithe>=0.9.26
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.22", "prompt-toolkit>=3.0.38", "textual>=1.0"]
12
+ dependencies = ["lithe>=0.9.26", "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",
@@ -535,6 +535,23 @@ def test_system_prompt_prefers_localized_file_edits_and_limits_todo_planning():
535
535
  assert "条数按实际步骤确定,不使用固定数量" in SYSTEM_PROMPT_BASE
536
536
 
537
537
 
538
+ def test_system_prompt_states_relative_path_rule_and_error_recovery():
539
+ from lithe_cli.agent import SYSTEM_PROMPT_BASE
540
+
541
+ assert "相对路径" in SYSTEM_PROMPT_BASE
542
+ assert "工作区之外" in SYSTEM_PROMPT_BASE
543
+ assert "错误信息" in SYSTEM_PROMPT_BASE
544
+
545
+
546
+ def test_system_prompt_puts_each_capability_on_its_own_line():
547
+ from lithe_cli.agent import build_system_prompt
548
+ from lithe_cli.config import Config
549
+
550
+ prompt = build_system_prompt(Config(code=True, shell=True))
551
+ assert "汇报结果。\n可以用 run_code" in prompt
552
+ assert "\n可以用 run_command" in prompt
553
+
554
+
538
555
  def test_todo_storage_is_scoped_to_user_and_workspace(tmp_path):
539
556
  from lithe_cli.agent import todo_store_path
540
557
  from lithe_cli.config import Config
@@ -0,0 +1,67 @@
1
+ """lithe-cli: the dangerous-command guard is wired into build_registry.
2
+
3
+ End-to-end through registry dispatch: catastrophic commands never reach a
4
+ runner (safe to test — nothing executes), and the destructive tier asks
5
+ the injected approver. Kernel-side classification tables live in the
6
+ kernel's own test suite; this pins the CLI wiring. Sync tests drive
7
+ coroutines with asyncio.run, the suite's convention (no async plugin).
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import asyncio
12
+
13
+ from lithe import AgentContext
14
+
15
+ from lithe_cli.agent import build_registry, interactive_approver
16
+ from lithe_cli.config import Config
17
+
18
+
19
+ def _ctx() -> AgentContext:
20
+ return AgentContext(run_id="r", user_id="u")
21
+
22
+
23
+ def test_guard_active_when_shell_enabled(tmp_path):
24
+ cfg = Config(store_dir=tmp_path / "s", workspace_dir=tmp_path / "ws",
25
+ shell=True)
26
+ reg = build_registry(cfg)
27
+ res = asyncio.run(reg.dispatch("run_command",
28
+ {"command": "rm -rf /"}, _ctx()))
29
+ assert res.ok is False and res.summary == "危险命令已拦截"
30
+
31
+ # destructive tier with no approver channel: denied with guidance
32
+ res = asyncio.run(reg.dispatch("run_command",
33
+ {"command": "rm -rf node_modules"}, _ctx()))
34
+ assert res.ok is False and res.summary == "需用户审批"
35
+
36
+
37
+ def test_guard_asks_injected_approver(tmp_path):
38
+ cfg = Config(store_dir=tmp_path / "s", workspace_dir=tmp_path / "ws",
39
+ shell=True)
40
+ asked: list[str] = []
41
+
42
+ async def approver(command: str) -> bool:
43
+ asked.append(command)
44
+ return False
45
+
46
+ reg = build_registry(cfg, approver)
47
+ res = asyncio.run(reg.dispatch(
48
+ "run_command", {"command": "git push --force origin main"}, _ctx()))
49
+ assert res.ok is False and res.summary == "用户已拒绝"
50
+ assert asked == ["git push --force origin main"]
51
+
52
+
53
+ def test_guard_absent_without_shell(tmp_path):
54
+ cfg = Config(store_dir=tmp_path / "s", workspace_dir=tmp_path / "ws")
55
+ reg = build_registry(cfg)
56
+ assert "run_command" not in reg.names()
57
+
58
+
59
+ def test_interactive_approver_none_without_tty(monkeypatch):
60
+ import sys as _sys
61
+
62
+ class _FakeStdin:
63
+ def isatty(self) -> bool:
64
+ return False
65
+
66
+ monkeypatch.setattr(_sys, "stdin", _FakeStdin())
67
+ assert interactive_approver() is None
@@ -40,12 +40,26 @@ DELEGATE_SCRIPT = [
40
40
  ]
41
41
 
42
42
 
43
- def test_delegation_disabled_by_default(tmp_path):
43
+ def test_delegation_enabled_by_default_with_opt_out(tmp_path):
44
+ """子代理委派默认包含(roster 只复用已启用工具,不新增能力),
45
+ --no-subagents 显式退出。"""
46
+ from lithe_cli.main import build_parser
47
+
48
+ parser = build_parser()
49
+ assert parser.parse_args(["run", "t"]).subagents is True
50
+ assert parser.parse_args(["run", "--no-subagents", "t"]).subagents is False
51
+ assert parser.parse_args(["run", "--subagents", "t"]).subagents is True
52
+
44
53
  cfg = make_config(tmp_path, DELEGATE_SCRIPT)
45
- reg = build_registry(cfg)
46
- assert reg.spec("delegate") is None and reg.spec("delegate_parallel") is None
47
- assert "delegate" not in tool_names(cfg)
48
- assert "delegate" not in build_system_prompt(Config())
54
+ assert cfg.subagents is True
55
+ assert "delegate" in tool_names(cfg)
56
+ assert "delegate" in build_system_prompt(Config())
57
+
58
+ # opting out keeps the delegation pair off the registry-facing surface
59
+ off = make_config(tmp_path / "off", [])
60
+ off.subagents = False
61
+ assert "delegate" not in tool_names(off)
62
+ assert "delegate" not in build_system_prompt(off)
49
63
 
50
64
 
51
65
  def test_delegation_runs_and_records_child_messages(tmp_path, capsys):
@@ -97,9 +111,12 @@ def test_roster_adapts_to_capability_flags(tmp_path):
97
111
 
98
112
  def test_set_subagents_toggles_and_warns(tmp_path):
99
113
  cfg = make_config(tmp_path, [])
114
+ assert cfg.subagents is True # default-on since the roster adds no powers
100
115
  wb = Workbench(cfg)
101
116
  keys = [row["key"] for row in wb.settings_rows()]
102
117
  assert "subagents" in keys
118
+ # enabling from off warns about token amplification
119
+ assert wb.dispatch("/set subagents off").changed
103
120
  r = wb.dispatch("/set subagents on")
104
121
  assert cfg.subagents is True
105
122
  assert any("token 花费" in text for cls, text in r.messages
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes