lithe-cli 0.9.1__tar.gz → 0.9.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.9.1 → lithe_cli-0.9.3}/PKG-INFO +2 -2
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/agent.py +35 -4
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/main.py +5 -1
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/ttui.py +71 -3
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/tui.py +9 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/workbench.py +5 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli.egg-info/PKG-INFO +2 -2
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli.egg-info/SOURCES.txt +1 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/pyproject.toml +1 -1
- lithe_cli-0.9.3/tests/test_cli_guard.py +67 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_tui_v2.py +19 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/LICENSE +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/README.md +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/commands.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/config.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/profiles.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/setup.cfg +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_cli.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_cli_budget_steer.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_cli_subagents.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_profiles.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/tests/test_ttui.py +0 -0
- {lithe_cli-0.9.1 → lithe_cli-0.9.3}/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.
|
|
3
|
+
Version: 0.9.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.24
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -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
|
|
@@ -141,8 +143,13 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
141
143
|
return LLMConfig(**overrides)
|
|
142
144
|
|
|
143
145
|
|
|
144
|
-
def build_registry(cfg: Config) -> ToolRegistry:
|
|
145
|
-
"""Register the CLI's tool set against the configured workspace.
|
|
146
|
+
def build_registry(cfg: Config, approver: Callable[[str], Awaitable[bool]] | None = None) -> ToolRegistry:
|
|
147
|
+
"""Register the CLI's tool set against the configured workspace.
|
|
148
|
+
|
|
149
|
+
``approver`` is the human-confirmation channel for destructive
|
|
150
|
+
``run_command`` calls (the kernel guard's "approve" tier); without one
|
|
151
|
+
those are denied with guidance instead of running silently.
|
|
152
|
+
"""
|
|
146
153
|
reg = ToolRegistry()
|
|
147
154
|
|
|
148
155
|
def workspace_for(ctx) -> Workspace:
|
|
@@ -165,6 +172,10 @@ def build_registry(cfg: Config) -> ToolRegistry:
|
|
|
165
172
|
register_command_tools(
|
|
166
173
|
reg, lambda ctx: cfg.workspace_dir.resolve(), CommandRunner()
|
|
167
174
|
)
|
|
175
|
+
# Dangerous-command guard: catastrophic commands never run; the
|
|
176
|
+
# destructive-but-scoped tier (rm -r <path>, git push --force,
|
|
177
|
+
# sudo, ...) asks the approver first.
|
|
178
|
+
reg.add_middleware(make_command_guard(approver))
|
|
168
179
|
if cfg.skills_dir is not None:
|
|
169
180
|
from lithe.bundles.skills import SkillLibrary, register_skill_tool
|
|
170
181
|
|
|
@@ -350,6 +361,25 @@ def render_event(
|
|
|
350
361
|
print(ui.reasoning(digest[:120]))
|
|
351
362
|
|
|
352
363
|
|
|
364
|
+
def interactive_approver() -> Callable[[str], Awaitable[bool]] | None:
|
|
365
|
+
"""A stdin y/n approver for interactive line-mode front-ends.
|
|
366
|
+
|
|
367
|
+
Returns None on a non-TTY stdin (piped/scripted runs): nobody can
|
|
368
|
+
answer, so the guard's destructive tier denies instead of hanging.
|
|
369
|
+
"""
|
|
370
|
+
if not sys.stdin.isatty():
|
|
371
|
+
return None
|
|
372
|
+
|
|
373
|
+
async def approver(command: str) -> bool:
|
|
374
|
+
from . import prompts
|
|
375
|
+
|
|
376
|
+
preview = command if len(command) <= 90 else command[:87] + "..."
|
|
377
|
+
return await asyncio.to_thread(
|
|
378
|
+
prompts.yes_no, f"⚠ 破坏性命令需确认,允许执行:{preview}", False)
|
|
379
|
+
|
|
380
|
+
return approver
|
|
381
|
+
|
|
382
|
+
|
|
353
383
|
async def execute(
|
|
354
384
|
cfg: Config,
|
|
355
385
|
task: str,
|
|
@@ -359,6 +389,7 @@ async def execute(
|
|
|
359
389
|
stop=None,
|
|
360
390
|
conversation_id: int | None = None,
|
|
361
391
|
inbox=None,
|
|
392
|
+
approver: Callable[[str], Awaitable[bool]] | None = None,
|
|
362
393
|
) -> tuple[str, dict, Any]:
|
|
363
394
|
"""Run one task end-to-end; returns (run_id, done_event, host).
|
|
364
395
|
|
|
@@ -371,7 +402,7 @@ async def execute(
|
|
|
371
402
|
the steering channel: a queue of user texts the kernel drains at step
|
|
372
403
|
boundaries and injects as user messages (see AgentRuntime.run).
|
|
373
404
|
"""
|
|
374
|
-
reg = build_registry(cfg)
|
|
405
|
+
reg = build_registry(cfg, approver)
|
|
375
406
|
host = build_host(cfg, reg)
|
|
376
407
|
if cfg.subagents:
|
|
377
408
|
register_subagents(cfg, host, reg)
|
|
@@ -498,7 +498,9 @@ def _cmd_doctor() -> int:
|
|
|
498
498
|
|
|
499
499
|
|
|
500
500
|
def _cmd_run(cfg: Any, task: str) -> int:
|
|
501
|
-
|
|
501
|
+
from .agent import interactive_approver
|
|
502
|
+
|
|
503
|
+
_, done, _ = asyncio.run(execute(cfg, task, approver=interactive_approver()))
|
|
502
504
|
return 0 if done.get("status") == "done" else 1
|
|
503
505
|
|
|
504
506
|
|
|
@@ -611,9 +613,11 @@ def _chat_loop(
|
|
|
611
613
|
title: str | None = None,
|
|
612
614
|
) -> int:
|
|
613
615
|
"""Plain (non-TTY) chat: same Workbench and commands as the full screen."""
|
|
616
|
+
from .agent import interactive_approver
|
|
614
617
|
from .workbench import Workbench
|
|
615
618
|
|
|
616
619
|
wb = Workbench(cfg)
|
|
620
|
+
wb.approver = interactive_approver() # y/n on stdin when a TTY exists
|
|
617
621
|
opening = wb.open(
|
|
618
622
|
resume=resume, continue_latest=continue_latest, title=title
|
|
619
623
|
)
|
|
@@ -83,7 +83,11 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
83
83
|
status_color = "red"
|
|
84
84
|
out.append(f"[{status_color}]● {state.status}[/]")
|
|
85
85
|
out.append(f"[dim]步骤 {state.step}/{state.max_steps}[/]")
|
|
86
|
-
|
|
86
|
+
live = state.elapsed()
|
|
87
|
+
if state.running:
|
|
88
|
+
if live is not None:
|
|
89
|
+
out.append(f"[yellow]已进行 {fmt_duration(live)}[/]")
|
|
90
|
+
elif state.last_turn_duration is not None:
|
|
87
91
|
out.append(f"[dim]本轮耗时 {fmt_duration(state.last_turn_duration)}[/]")
|
|
88
92
|
out.append("[dim]◆ 工具[/]")
|
|
89
93
|
if not state.tools:
|
|
@@ -137,7 +141,10 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
137
141
|
|
|
138
142
|
def footer_text(state: TuiState) -> str:
|
|
139
143
|
if state.running:
|
|
140
|
-
|
|
144
|
+
live = state.elapsed()
|
|
145
|
+
timer = f" · {fmt_duration(live)}" if live is not None else ""
|
|
146
|
+
return (f" ● {state.status}{timer} · Ctrl+C 取消 · F3 会话"
|
|
147
|
+
f" · F4 模型 · F6 推理 ")
|
|
141
148
|
return (f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
|
|
142
149
|
f" · F5 设置 · F6 推理 · /help ")
|
|
143
150
|
|
|
@@ -345,6 +352,34 @@ class PickerModal(ModalScreen):
|
|
|
345
352
|
row.children[0].update(label)
|
|
346
353
|
|
|
347
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
|
+
|
|
348
383
|
# -- the app ----------------------------------------------------------------------
|
|
349
384
|
|
|
350
385
|
class LitheApp(App):
|
|
@@ -411,6 +446,9 @@ class LitheApp(App):
|
|
|
411
446
|
from .workbench import Workbench
|
|
412
447
|
|
|
413
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
|
|
414
452
|
self.todo_store = JsonTodoStore(todo_store_path(self.cfg))
|
|
415
453
|
self.version = __version__
|
|
416
454
|
prompt = self.query_one("#prompt", HistoryInput)
|
|
@@ -440,6 +478,10 @@ class LitheApp(App):
|
|
|
440
478
|
self._sync_feed()
|
|
441
479
|
self._refresh_chrome()
|
|
442
480
|
self.query_one("#prompt", Input).focus()
|
|
481
|
+
# Live turn timer: kernel events alone leave the screen static
|
|
482
|
+
# during long model calls, so the chrome repaints on a heartbeat
|
|
483
|
+
# while a turn runs (elapsed comes from TuiState.elapsed()).
|
|
484
|
+
self.set_interval(0.5, self._tick_elapsed)
|
|
443
485
|
if self.mode == "run" and self.initial_task:
|
|
444
486
|
self.query_one("#prompt", Input).disabled = True
|
|
445
487
|
asyncio.create_task(self._run_one_shot(self.initial_task))
|
|
@@ -546,6 +588,11 @@ class LitheApp(App):
|
|
|
546
588
|
self.query_one("#side-wrap", VerticalScroll).display = \
|
|
547
589
|
self.state.show_sidebar
|
|
548
590
|
|
|
591
|
+
def _tick_elapsed(self) -> None:
|
|
592
|
+
"""Heartbeat for the running turn's live timer (see on_mount)."""
|
|
593
|
+
if self.state.running:
|
|
594
|
+
self._refresh_chrome()
|
|
595
|
+
|
|
549
596
|
# -- workbench events -------------------------------------------------------
|
|
550
597
|
|
|
551
598
|
def on_wb_event(self, message: WbEvent) -> None:
|
|
@@ -924,6 +971,27 @@ class LitheApp(App):
|
|
|
924
971
|
|
|
925
972
|
# -- one-shot run mode --------------------------------------------------------
|
|
926
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
|
+
|
|
927
995
|
async def _run_one_shot(self, text: str) -> None:
|
|
928
996
|
from .agent import execute
|
|
929
997
|
|
|
@@ -936,7 +1004,7 @@ class LitheApp(App):
|
|
|
936
1004
|
self._refresh_chrome()
|
|
937
1005
|
try:
|
|
938
1006
|
await execute(self.cfg, text, on_event=self.state.on_event,
|
|
939
|
-
stop=stop)
|
|
1007
|
+
stop=stop, approver=self.confirm_command)
|
|
940
1008
|
except Exception as exc: # noqa: BLE001
|
|
941
1009
|
self.state.say("err", f"运行出错:{exc}")
|
|
942
1010
|
finally:
|
|
@@ -106,6 +106,15 @@ class TuiState:
|
|
|
106
106
|
"""Presentation refresh hook. The Textual front-end repaints on its
|
|
107
107
|
own event loop, so this is deliberately a no-op here."""
|
|
108
108
|
|
|
109
|
+
def elapsed(self) -> float | None:
|
|
110
|
+
"""Live seconds since the running turn started (None when idle or
|
|
111
|
+
before the first ``run_start``). Frontends pair this with a periodic
|
|
112
|
+
repaint so the timer advances even while the model call itself
|
|
113
|
+
emits no events."""
|
|
114
|
+
if self.running and self.started is not None:
|
|
115
|
+
return max(0.0, time.monotonic() - self.started)
|
|
116
|
+
return None
|
|
117
|
+
|
|
109
118
|
# -- sessions -------------------------------------------------------------
|
|
110
119
|
|
|
111
120
|
def set_sessions(self, rows: list[dict], busy: set[int]) -> None:
|
|
@@ -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.
|
|
3
|
+
Version: 0.9.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.24
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -9,7 +9,7 @@ description = "Command-line interface for the lithe agent kernel: chat, one-shot
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
requires-python = ">=3.10"
|
|
12
|
-
dependencies = ["lithe>=0.9.
|
|
12
|
+
dependencies = ["lithe>=0.9.24", "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",
|
|
@@ -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
|
|
@@ -63,6 +63,25 @@ def test_footer_switches_hints_by_running_state():
|
|
|
63
63
|
assert "Ctrl+C 取消" in busy and "F3" in busy and "F4" in busy
|
|
64
64
|
|
|
65
65
|
|
|
66
|
+
def test_live_elapsed_shown_while_running():
|
|
67
|
+
import re
|
|
68
|
+
import time as _time
|
|
69
|
+
|
|
70
|
+
state = TuiState("m", "/ws", 5)
|
|
71
|
+
state.on_event({"type": "run_start"})
|
|
72
|
+
state.running = True
|
|
73
|
+
state.started = _time.monotonic() - 12.0
|
|
74
|
+
side = sidebar_markup(state)
|
|
75
|
+
foot = footer_text(state)
|
|
76
|
+
assert re.search(r"已进行 12\.\ds", side)
|
|
77
|
+
assert re.search(r"● 思考中 · 12\.\ds", foot)
|
|
78
|
+
# idle: the live line disappears and the settled duration takes over
|
|
79
|
+
state.running = False
|
|
80
|
+
state.last_turn_duration = 65.0
|
|
81
|
+
assert "已进行" not in sidebar_markup(state)
|
|
82
|
+
assert "本轮耗时 1m05s" in sidebar_markup(state)
|
|
83
|
+
|
|
84
|
+
|
|
66
85
|
def test_completion_suggestions_cover_commands_and_args():
|
|
67
86
|
state = TuiState("m", "/ws", 5)
|
|
68
87
|
state.model_candidates = ["glm-4.6", "glm-4.5-air"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|