lithe-cli 0.9.0__tar.gz → 0.9.1__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.0 → lithe_cli-0.9.1}/PKG-INFO +2 -2
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/agent.py +14 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/main.py +13 -3
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/ttui.py +3 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/tui.py +44 -12
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/ui.py +43 -1
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli.egg-info/PKG-INFO +2 -2
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/pyproject.toml +1 -1
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_cli.py +90 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/LICENSE +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/README.md +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/commands.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/config.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/profiles.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli/workbench.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli.egg-info/SOURCES.txt +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/setup.cfg +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_cli_budget_steer.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_cli_subagents.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_profiles.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_ttui.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/tests/test_tui_v2.py +0 -0
- {lithe_cli-0.9.0 → lithe_cli-0.9.1}/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.1
|
|
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.22
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -314,9 +314,23 @@ def render_event(
|
|
|
314
314
|
pending[ev["id"]] = time.monotonic()
|
|
315
315
|
elif t == "tool_result":
|
|
316
316
|
summary = (ev.get("summary") or "").replace("\n", " ")
|
|
317
|
+
if not ev.get("ok") and ev.get("error"):
|
|
318
|
+
# Failed calls carry the diagnostic in ``error``; the summary
|
|
319
|
+
# alone ("参数错误") tells the user nothing actionable. When one
|
|
320
|
+
# text already contains the other (common: summary is a prefix
|
|
321
|
+
# of the error), show only the longer one instead of echoing.
|
|
322
|
+
detail = str(ev["error"]).replace("\n", " ")
|
|
323
|
+
if detail and summary and (detail in summary or summary in detail):
|
|
324
|
+
summary = detail if len(detail) > len(summary) else summary
|
|
325
|
+
elif detail:
|
|
326
|
+
summary = f"{summary} · {detail}" if summary else detail
|
|
317
327
|
started = pending.pop(ev.get("id"), None) if ev.get("id") else None
|
|
318
328
|
elapsed = (time.monotonic() - started) if started is not None else None
|
|
319
329
|
ui.tool_result(bool(ev.get("ok")), summary, elapsed)
|
|
330
|
+
elif t == "todo_change":
|
|
331
|
+
# update_todos replaced the list; print what it now contains —
|
|
332
|
+
# the tool's own result line only reports the item count.
|
|
333
|
+
ui.todo_change(ev.get("new") or [])
|
|
320
334
|
elif t == "error":
|
|
321
335
|
ui.error(str(ev.get("message", "")))
|
|
322
336
|
elif t == "cancelled":
|
|
@@ -285,15 +285,20 @@ def _cmd_runs(cfg: Any, limit: int) -> int:
|
|
|
285
285
|
if not runs:
|
|
286
286
|
print(ui.s(f"({cfg.store_dir} 下没有 run 记录)", YELLOW))
|
|
287
287
|
return 0
|
|
288
|
+
from .ui import fmt_duration
|
|
289
|
+
|
|
288
290
|
rows = []
|
|
289
291
|
for r in reversed(runs): # newest last, like a log
|
|
290
292
|
task = (r.task or "").replace("\n", " ")
|
|
291
|
-
|
|
293
|
+
duration = (fmt_duration(r.finished_at - r.created_at)
|
|
294
|
+
if r.created_at and r.finished_at else "—")
|
|
295
|
+
rows.append([r.run_id, r.status, str(r.steps), f"{r.cost:.4f}",
|
|
296
|
+
duration, truncate(task, 60)])
|
|
292
297
|
print(
|
|
293
298
|
ui.table(
|
|
294
|
-
["run", "status", "steps", "cost", "task"],
|
|
299
|
+
["run", "status", "steps", "cost", "time", "task"],
|
|
295
300
|
rows,
|
|
296
|
-
cell_styles=[ui.s, ui.status, ui.s, ui.s, ui.s],
|
|
301
|
+
cell_styles=[ui.s, ui.status, ui.s, ui.s, ui.s, ui.s],
|
|
297
302
|
)
|
|
298
303
|
)
|
|
299
304
|
return 0
|
|
@@ -305,9 +310,14 @@ def _cmd_log(cfg: Any, run_id: str) -> int:
|
|
|
305
310
|
if run is None:
|
|
306
311
|
print(ui.s(f"找不到 run {run_id}(user={cfg.user_id})", RED))
|
|
307
312
|
return 1
|
|
313
|
+
from .ui import fmt_duration
|
|
314
|
+
|
|
315
|
+
duration = (fmt_duration(run.finished_at - run.created_at)
|
|
316
|
+
if run.created_at and run.finished_at else None)
|
|
308
317
|
print(
|
|
309
318
|
f"run {ui.s(run.run_id, CYAN)} status={ui.status(run.status)} "
|
|
310
319
|
f"steps={run.steps} model={run.model}"
|
|
320
|
+
+ (f" 耗时={duration}" if duration else "")
|
|
311
321
|
)
|
|
312
322
|
print(f"task: {run.task}")
|
|
313
323
|
if run.final:
|
|
@@ -31,6 +31,7 @@ from textual.screen import ModalScreen
|
|
|
31
31
|
from textual.widgets import Input, Label, ListItem, ListView, Static
|
|
32
32
|
|
|
33
33
|
from .tui import TuiState, transcript_feed_lines
|
|
34
|
+
from .ui import fmt_duration
|
|
34
35
|
|
|
35
36
|
_MAX_FEED = 400 # mounted conversation lines before trimming the oldest
|
|
36
37
|
|
|
@@ -82,6 +83,8 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
82
83
|
status_color = "red"
|
|
83
84
|
out.append(f"[{status_color}]● {state.status}[/]")
|
|
84
85
|
out.append(f"[dim]步骤 {state.step}/{state.max_steps}[/]")
|
|
86
|
+
if not state.running and state.last_turn_duration is not None:
|
|
87
|
+
out.append(f"[dim]本轮耗时 {fmt_duration(state.last_turn_duration)}[/]")
|
|
85
88
|
out.append("[dim]◆ 工具[/]")
|
|
86
89
|
if not state.tools:
|
|
87
90
|
out.append("[dim]暂无调用[/]")
|
|
@@ -22,7 +22,7 @@ import os
|
|
|
22
22
|
import sys
|
|
23
23
|
import time
|
|
24
24
|
|
|
25
|
-
from .ui import tool_call_label, truncate
|
|
25
|
+
from .ui import fmt_duration, tool_call_label, truncate
|
|
26
26
|
|
|
27
27
|
_STATUS_DONE = "done"
|
|
28
28
|
|
|
@@ -73,6 +73,7 @@ class TuiState:
|
|
|
73
73
|
self.output_tokens = 0
|
|
74
74
|
self.cached_tokens = 0
|
|
75
75
|
self.last_turn_cost = 0.0
|
|
76
|
+
self.last_turn_duration: float | None = None
|
|
76
77
|
self._turn_tokens = 0
|
|
77
78
|
self._turn_cost = 0.0
|
|
78
79
|
self._turn_input_tokens = 0
|
|
@@ -186,10 +187,24 @@ class TuiState:
|
|
|
186
187
|
self.say("tool", f"◆ {tool_call_label(name, args)}")
|
|
187
188
|
self.status = f"工具 {name}"
|
|
188
189
|
elif kind == "tool_result":
|
|
189
|
-
self._settle_tool(ev.get("id"), bool(ev.get("ok")),
|
|
190
|
+
self._settle_tool(ev.get("id"), bool(ev.get("ok")),
|
|
191
|
+
ev.get("summary"), ev.get("error"))
|
|
190
192
|
elif kind == "todo_change":
|
|
191
193
|
self.todos = list(ev.get("new") or [])
|
|
192
|
-
|
|
194
|
+
done = sum(1 for t in self.todos if t.get("status") == "completed")
|
|
195
|
+
# The list belongs in the conversation feed, not only the
|
|
196
|
+
# sidebar: the sidebar can be hidden (F2) and caps at the last
|
|
197
|
+
# few items, which is exactly how "todos were created but I
|
|
198
|
+
# can't see them" happens.
|
|
199
|
+
self.say("dim", f"▤ 任务清单已更新({done}/{len(self.todos)} 完成)")
|
|
200
|
+
marks = {"pending": "[ ]", "in_progress": "[~]",
|
|
201
|
+
"completed": "[x]", "cancelled": "[-]"}
|
|
202
|
+
row_cls = {"in_progress": "warn", "completed": "ok"}
|
|
203
|
+
for n, item in enumerate(self.todos, 1):
|
|
204
|
+
status = str(item.get("status") or "pending")
|
|
205
|
+
self.say(row_cls.get(status, "dim"),
|
|
206
|
+
f" {n}. {marks.get(status, '[ ]')} "
|
|
207
|
+
f"{item.get('content', '')}")
|
|
193
208
|
elif kind == "usage":
|
|
194
209
|
self._turn_input_tokens += int(ev.get("prompt_tokens") or 0)
|
|
195
210
|
self._turn_output_tokens += int(ev.get("completion_tokens") or 0)
|
|
@@ -244,21 +259,38 @@ class TuiState:
|
|
|
244
259
|
self.context_window = int(ev["context_window"])
|
|
245
260
|
if ev.get("context_percent") is not None:
|
|
246
261
|
self.context_percent = ev["context_percent"]
|
|
247
|
-
|
|
248
|
-
|
|
262
|
+
# Turn length: prefer the kernel's duration_s (covers the whole
|
|
263
|
+
# run incl. prompt assembly); fall back to the local run_start
|
|
264
|
+
# timer for envelopes that predate the field.
|
|
265
|
+
if ev.get("duration_s") is not None:
|
|
266
|
+
self.last_turn_duration = float(ev["duration_s"])
|
|
267
|
+
elif self.started is not None:
|
|
268
|
+
self.last_turn_duration = time.monotonic() - self.started
|
|
269
|
+
if self.last_turn_duration is not None:
|
|
270
|
+
self.status += f" · {fmt_duration(self.last_turn_duration)}"
|
|
249
271
|
self.invalidate()
|
|
250
272
|
|
|
251
|
-
def _settle_tool(self, tool_id, ok: bool, summary) -> None:
|
|
273
|
+
def _settle_tool(self, tool_id, ok: bool, summary, error=None) -> None:
|
|
252
274
|
tool = next(
|
|
253
275
|
(t for t in reversed(self.tools) if t["id"] == tool_id and t["status"] == "running"),
|
|
254
276
|
None,
|
|
255
277
|
)
|
|
256
|
-
if tool is
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
278
|
+
if tool is None:
|
|
279
|
+
return
|
|
280
|
+
tool["elapsed"] = time.monotonic() - tool["t0"]
|
|
281
|
+
tool["status"] = "done" if ok else "failed"
|
|
282
|
+
label = str(summary or tool["name"]).replace("\n", " ")
|
|
283
|
+
if not ok and error:
|
|
284
|
+
# Same rule as the plain CLI: a failed call's summary ("参数错误")
|
|
285
|
+
# without the diagnostic is not readable output; when one text
|
|
286
|
+
# contains the other, keep only the longer one.
|
|
287
|
+
detail = str(error).replace("\n", " ")
|
|
288
|
+
if detail and label and (detail in label or label in detail):
|
|
289
|
+
label = detail if len(detail) > len(label) else label
|
|
290
|
+
elif detail:
|
|
291
|
+
label = f"{label} · {detail}" if label else detail
|
|
292
|
+
mark = "✓" if ok else "✗"
|
|
293
|
+
self.say("ok" if ok else "err", f"{mark} {label} {tool['elapsed']:.1f}s")
|
|
262
294
|
|
|
263
295
|
|
|
264
296
|
_CHAT_KEYS = """按键:PgUp/PgDn 或鼠标滚轮 滚动对话,Home/End 跳到顶/底。
|
|
@@ -126,6 +126,23 @@ def tool_call_label(name: str, args: dict) -> str:
|
|
|
126
126
|
return name
|
|
127
127
|
|
|
128
128
|
|
|
129
|
+
def fmt_duration(seconds: float | None) -> str:
|
|
130
|
+
"""Human wall-clock length: ``12.3s`` / ``2m05s`` / ``1h04m``.
|
|
131
|
+
|
|
132
|
+
Empty string for ``None`` so callers can drop the field silently.
|
|
133
|
+
"""
|
|
134
|
+
if seconds is None:
|
|
135
|
+
return ""
|
|
136
|
+
seconds = max(0.0, float(seconds))
|
|
137
|
+
if seconds < 60:
|
|
138
|
+
return f"{seconds:.1f}s"
|
|
139
|
+
minutes = int(seconds // 60)
|
|
140
|
+
sec = int(round(seconds % 60))
|
|
141
|
+
if minutes < 60:
|
|
142
|
+
return f"{minutes}m{sec:02d}s"
|
|
143
|
+
return f"{minutes // 60}h{minutes % 60:02d}m"
|
|
144
|
+
|
|
145
|
+
|
|
129
146
|
class UI:
|
|
130
147
|
"""All terminal output goes through here; ``color`` gates every code."""
|
|
131
148
|
|
|
@@ -227,6 +244,28 @@ class UI:
|
|
|
227
244
|
label = truncate(summary, max(8, self.width - 8 - display_width(tail)))
|
|
228
245
|
print(f" {mark} {self.s(label, GREEN if ok else RED)}{tail}")
|
|
229
246
|
|
|
247
|
+
_TODO_MARKS = {"pending": "[ ]", "in_progress": "[~]",
|
|
248
|
+
"completed": "[x]", "cancelled": "[-]"}
|
|
249
|
+
_TODO_COLORS = {"in_progress": YELLOW, "completed": GREEN}
|
|
250
|
+
|
|
251
|
+
def todo_change(self, items: list) -> None:
|
|
252
|
+
"""Print the full task list after an ``update_todos`` replace.
|
|
253
|
+
|
|
254
|
+
The tool's one-line summary only carries the count; without this
|
|
255
|
+
block the user never sees what the agent actually planned.
|
|
256
|
+
"""
|
|
257
|
+
done = sum(1 for it in items if it.get("status") == "completed")
|
|
258
|
+
head = f"任务清单({done}/{len(items)} 完成)"
|
|
259
|
+
print(f" {self.s('▤', MAGENTA)} {self.s(head, MAGENTA, BOLD)}")
|
|
260
|
+
for n, it in enumerate(items, 1):
|
|
261
|
+
status = str(it.get("status") or "pending")
|
|
262
|
+
mark = self._TODO_MARKS.get(status, "[ ]")
|
|
263
|
+
color = self._TODO_COLORS.get(status)
|
|
264
|
+
mark = self.s(mark, color) if color else mark
|
|
265
|
+
content = truncate(str(it.get("content") or ""),
|
|
266
|
+
max(8, self.width - 12))
|
|
267
|
+
print(f" {n}. {mark} {content}")
|
|
268
|
+
|
|
230
269
|
def error(self, msg: str) -> None:
|
|
231
270
|
print(f" {self.s('!', RED)} {self.s(msg, RED)}")
|
|
232
271
|
|
|
@@ -244,7 +283,7 @@ class UI:
|
|
|
244
283
|
return self.s(f" ~ {digest}", DIM)
|
|
245
284
|
|
|
246
285
|
def footer(self, ev: dict) -> None:
|
|
247
|
-
"""The one-line wrap-up after a run: status · steps · tokens · cost."""
|
|
286
|
+
"""The one-line wrap-up after a run: status · steps · tokens · cost · time."""
|
|
248
287
|
parts = [self.status(str(ev.get("status", "?")))]
|
|
249
288
|
if ev.get("steps") is not None:
|
|
250
289
|
parts.append(f"steps {ev['steps']}")
|
|
@@ -256,6 +295,9 @@ class UI:
|
|
|
256
295
|
cost = ev.get("cost")
|
|
257
296
|
if cost:
|
|
258
297
|
parts.append(f"cost {cost:.4f}")
|
|
298
|
+
duration = fmt_duration(ev.get("duration_s"))
|
|
299
|
+
if duration:
|
|
300
|
+
parts.append(duration)
|
|
259
301
|
print(f"{self.s('──', DIM)} {' · '.join(parts)}")
|
|
260
302
|
|
|
261
303
|
# -- chat ---------------------------------------------------------------
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
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.22
|
|
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.22", "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",
|
|
@@ -240,6 +240,96 @@ def test_execute_prints_footer(tmp_path, capsys):
|
|
|
240
240
|
assert (cfg.workspace_dir / "a.txt").exists()
|
|
241
241
|
|
|
242
242
|
|
|
243
|
+
def test_execute_reports_turn_duration(tmp_path, capsys):
|
|
244
|
+
import re
|
|
245
|
+
|
|
246
|
+
cfg = make_config(tmp_path, WRITE_THEN_ANSWER)
|
|
247
|
+
_, done, _ = asyncio.run(execute(cfg, "把 a.txt 写为 hi"))
|
|
248
|
+
# the host's done envelope carries the wall-clock length, and the
|
|
249
|
+
# plain-CLI footer prints it
|
|
250
|
+
assert isinstance(done.get("duration_s"), float)
|
|
251
|
+
assert done["duration_s"] >= 0
|
|
252
|
+
out = capsys.readouterr().out
|
|
253
|
+
assert re.search(r"\d+(\.\d+)?s\s*$", out.strip().splitlines()[-1])
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def test_render_event_shows_todo_contents(capsys):
|
|
257
|
+
from lithe_cli.agent import render_event
|
|
258
|
+
|
|
259
|
+
render_event({"type": "todo_change", "old": [], "new": [
|
|
260
|
+
{"content": "检查测试", "status": "in_progress"},
|
|
261
|
+
{"content": "修复问题", "status": "pending"},
|
|
262
|
+
]})
|
|
263
|
+
out = capsys.readouterr().out
|
|
264
|
+
assert "任务清单" in out
|
|
265
|
+
assert "检查测试" in out and "修复问题" in out
|
|
266
|
+
assert "[~]" in out and "[ ]" in out
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def test_render_event_tool_failure_shows_error_detail(capsys):
|
|
270
|
+
from lithe_cli.agent import render_event
|
|
271
|
+
|
|
272
|
+
render_event({"type": "tool_result", "id": "c1", "ok": False,
|
|
273
|
+
"summary": "参数错误",
|
|
274
|
+
"error": "old_text 不是唯一匹配(3 处)"})
|
|
275
|
+
out = capsys.readouterr().out
|
|
276
|
+
assert "参数错误" in out and "不是唯一匹配" in out
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def test_footer_shows_formatted_duration(capsys):
|
|
280
|
+
from lithe_cli.ui import UI, fmt_duration
|
|
281
|
+
|
|
282
|
+
assert fmt_duration(None) == ""
|
|
283
|
+
assert fmt_duration(12.34) == "12.3s"
|
|
284
|
+
assert fmt_duration(65.0) == "1m05s"
|
|
285
|
+
assert fmt_duration(3725.0) == "1h02m"
|
|
286
|
+
UI(color=False).footer({"status": "done", "steps": 2, "tokens": 240,
|
|
287
|
+
"duration_s": 65.0})
|
|
288
|
+
out = capsys.readouterr().out
|
|
289
|
+
assert "done" in out and "1m05s" in out
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def test_runs_command_shows_time_column(tmp_path, capsys):
|
|
293
|
+
import re
|
|
294
|
+
|
|
295
|
+
cfg = make_config(tmp_path, WRITE_THEN_ANSWER)
|
|
296
|
+
asyncio.run(execute(cfg, "把 a.txt 写为 hi"))
|
|
297
|
+
capsys.readouterr()
|
|
298
|
+
from lithe_cli.main import _cmd_runs
|
|
299
|
+
|
|
300
|
+
assert _cmd_runs(cfg, 10) == 0
|
|
301
|
+
out = capsys.readouterr().out
|
|
302
|
+
assert "time" in out
|
|
303
|
+
assert re.search(r"\d+\.\d+s", out) # created_at→finished_at rendered
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def test_tui_feed_shows_todo_contents():
|
|
307
|
+
from lithe_cli.tui import TuiState
|
|
308
|
+
|
|
309
|
+
state = TuiState("m", "/ws", 5)
|
|
310
|
+
state.on_event({"type": "run_start"})
|
|
311
|
+
state.on_event({"type": "todo_change", "new": [
|
|
312
|
+
{"content": "检查测试", "status": "in_progress"},
|
|
313
|
+
{"content": "修复问题", "status": "pending"},
|
|
314
|
+
]})
|
|
315
|
+
feed_text = "\n".join(text for _, text in state.feed)
|
|
316
|
+
assert "▤" in feed_text and "0/2" in feed_text
|
|
317
|
+
assert "1. [~] 检查测试" in feed_text
|
|
318
|
+
assert "2. [ ] 修复问题" in feed_text
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def test_tui_done_records_turn_duration():
|
|
322
|
+
from lithe_cli.tui import TuiState
|
|
323
|
+
from lithe_cli.ttui import sidebar_markup
|
|
324
|
+
|
|
325
|
+
state = TuiState("m", "/ws", 5)
|
|
326
|
+
state.on_event({"type": "done", "status": "done", "steps": 1,
|
|
327
|
+
"duration_s": 65.0})
|
|
328
|
+
assert state.last_turn_duration == 65.0
|
|
329
|
+
assert "1m05s" in state.status
|
|
330
|
+
assert "本轮耗时 1m05s" in sidebar_markup(state)
|
|
331
|
+
|
|
332
|
+
|
|
243
333
|
def test_system_prompt_mentions_capabilities(tmp_path):
|
|
244
334
|
from lithe_cli.agent import build_system_prompt
|
|
245
335
|
from lithe_cli.config import Config
|
|
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
|
|
File without changes
|