lithe-cli 0.1.1__tar.gz → 0.1.2__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.
Files changed (35) hide show
  1. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/PKG-INFO +1 -1
  2. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/__init__.py +1 -1
  3. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/agent.py +116 -4
  4. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/tui.py +63 -1
  5. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/ui.py +34 -0
  6. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli.egg-info/PKG-INFO +1 -1
  7. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_cli_subagents.py +112 -0
  8. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/LICENSE +0 -0
  9. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/README.md +0 -0
  10. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/__main__.py +0 -0
  11. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/commands.py +0 -0
  12. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/config.py +0 -0
  13. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/main.py +0 -0
  14. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/profiles.py +0 -0
  15. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/prompts.py +0 -0
  16. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/py.typed +0 -0
  17. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/sessions.py +0 -0
  18. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/setup.py +0 -0
  19. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/ttui.py +0 -0
  20. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli/workbench.py +0 -0
  21. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli.egg-info/SOURCES.txt +0 -0
  22. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli.egg-info/dependency_links.txt +0 -0
  23. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli.egg-info/entry_points.txt +0 -0
  24. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli.egg-info/requires.txt +0 -0
  25. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/lithe_cli.egg-info/top_level.txt +0 -0
  26. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/pyproject.toml +0 -0
  27. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/setup.cfg +0 -0
  28. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_cli.py +0 -0
  29. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_cli_budget_steer.py +0 -0
  30. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_cli_guard.py +0 -0
  31. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_cli_sessions.py +0 -0
  32. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_profiles.py +0 -0
  33. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_ttui.py +0 -0
  34. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_tui_v2.py +0 -0
  35. {lithe_cli-0.1.1 → lithe_cli-0.1.2}/tests/test_workbench.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
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.1.1"
3
+ __version__ = "0.1.2"
@@ -46,7 +46,20 @@ from lithe.bundles.workspace import register_file_tools
46
46
  from lithe.bundles.todos import register_todo_tools
47
47
 
48
48
  from .config import Config
49
- from .ui import CYAN, GREEN, YELLOW, ui
49
+ from .ui import (
50
+ BOLD,
51
+ CYAN,
52
+ DIM,
53
+ GREEN,
54
+ MAGENTA,
55
+ RED,
56
+ SUBAGENT_STATUS,
57
+ YELLOW,
58
+ display_width,
59
+ truncate,
60
+ tool_call_label,
61
+ ui,
62
+ )
50
63
 
51
64
  SYSTEM_PROMPT_BASE = (
52
65
  "你是运行在命令行里的助理,工作区是用户的当前目录。"
@@ -238,12 +251,18 @@ _OPERATOR_PROMPT = (
238
251
  )
239
252
 
240
253
 
241
- def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry):
254
+ def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry,
255
+ on_event=None):
242
256
  """Register delegate/delegate_parallel over the CLI's default roster.
243
257
 
244
258
  Must run after ``build_host`` (the engine shares the host's registry,
245
259
  store and LLM config — children inherit the endpoint, retry policy and
246
260
  budgets; parallel siblings share one live cost ceiling, kernel ≥0.1.0).
261
+ ``on_event`` is the caller's event channel (the TUI's state folder, the
262
+ workbench emitter); the kernel's ``on_subagent_event`` progress hook is
263
+ wired onto it so live subagent heartbeats reach the same front-end as
264
+ the orchestrator's own events. Without a channel (plain `lithe run`),
265
+ they render through ``render_event`` directly.
247
266
  Returns the engine (roster inspection for hosts and tests).
248
267
  """
249
268
  from lithe.bundles.subagents import (
@@ -284,7 +303,22 @@ def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry):
284
303
  # A spec whose tool list filtered to nothing can do nothing meaningful;
285
304
  # researcher/coder always keep the ever-present file tools.
286
305
  specs = [s for s in specs if s.tools]
287
- engine = SubagentEngine(host, SubagentRoster(specs))
306
+ roster = SubagentRoster(specs)
307
+
308
+ async def forward_progress(_sub_ctx, ev: dict) -> None:
309
+ # The kernel emits {"type": "subagent_progress", "agent": id,
310
+ # "event": <thin runtime event>}; enrich it with the roster's
311
+ # display name so front-ends can label lines without roster access.
312
+ spec = roster.get(str(ev.get("agent") or ""))
313
+ enriched = dict(ev)
314
+ if spec is not None:
315
+ enriched["display"] = spec.display
316
+ if on_event is not None:
317
+ on_event(enriched)
318
+ else:
319
+ render_event(enriched)
320
+
321
+ engine = SubagentEngine(host, roster, on_subagent_event=forward_progress)
288
322
  register_delegate_tools(reg, engine, parallel=True)
289
323
  return engine
290
324
 
@@ -298,6 +332,58 @@ def tool_names(cfg: Config) -> list[str]:
298
332
  return names
299
333
 
300
334
 
335
+ def _render_subagent_progress(ev: dict) -> None:
336
+ """Render one live subagent heartbeat: ``[检索员] ⚒ read_file · …``.
337
+
338
+ The kernel's progress hook caps text (300) and dumps ``tool_call`` args
339
+ to a capped JSON string, so parse them back for the label. ``step``
340
+ events are skipped — per-step chatter from every parallel worker is
341
+ noise, the tool lines carry the substance.
342
+ """
343
+ who = str(ev.get("display") or ev.get("agent") or "?")
344
+ tag = ui.s(f"[{who}]", MAGENTA)
345
+ inner = ev.get("event") or {}
346
+ t = inner.get("type")
347
+ room = max(8, ui.width - display_width(f" [{who}] "))
348
+ if t == "tool_call":
349
+ name = str(inner.get("name") or "")
350
+ args = inner.get("args")
351
+ if isinstance(args, str):
352
+ try:
353
+ args = json.loads(args)
354
+ except ValueError:
355
+ args = {}
356
+ args = args if isinstance(args, dict) else {}
357
+ label = tool_call_label(name, args)
358
+ detail = label[len(name):].strip(" ·") if label.startswith(name) else label
359
+ shown = truncate(detail, max(8, room - display_width(name) - 4))
360
+ print(f" {tag} {ui.s('⚒', CYAN)} {ui.s(name, CYAN, BOLD)} "
361
+ f"{ui.s(shown, DIM)}")
362
+ elif t == "tool_result":
363
+ ok = bool(inner.get("ok"))
364
+ summary = str(inner.get("summary") or "").replace("\n", " ")
365
+ if not ok and inner.get("error"):
366
+ # Same rule as the orchestrator's failed calls: a bare
367
+ # "参数错误" summary without the diagnostic tells nothing.
368
+ detail = str(inner["error"]).replace("\n", " ")
369
+ if detail and summary and (detail in summary or summary in detail):
370
+ summary = detail if len(detail) > len(summary) else summary
371
+ elif detail:
372
+ summary = f"{summary} · {detail}" if summary else detail
373
+ mark = ui.s("✓", GREEN) if ok else ui.s("✗", RED)
374
+ print(f" {tag} {mark} "
375
+ f"{ui.s(truncate(summary, max(8, room - 4)), GREEN if ok else RED)}")
376
+ elif t == "assistant":
377
+ text = str(inner.get("text") or "").replace("\n", " ").strip()
378
+ if text:
379
+ print(f" {tag} {ui.s(truncate(text, max(8, room - 2)), DIM)}")
380
+ elif t == "error":
381
+ msg = str(inner.get("message") or "").replace("\n", " ")
382
+ print(f" {tag} {ui.s('!', RED)} {ui.s(truncate(msg, max(8, room - 4)), RED)}")
383
+ elif t == "cancelled":
384
+ print(f" {tag} {ui.s('~ 已取消', YELLOW)}")
385
+
386
+
301
387
  def render_event(
302
388
  ev: dict,
303
389
  verbose: bool = False,
@@ -345,6 +431,32 @@ def render_event(
345
431
  # update_todos replaced the list; print what it now contains —
346
432
  # the tool's own result line only reports the item count.
347
433
  ui.todo_change(ev.get("new") or [])
434
+ elif t == "subagent_progress":
435
+ # Live heartbeat from a running subagent (kernel on_subagent_event,
436
+ # wired in register_subagents): each worker's tool calls and
437
+ # outputs, labeled with its display name.
438
+ _render_subagent_progress(ev)
439
+ elif t == "subagent_start":
440
+ # Emitted in ToolResult.ui after the delegation finished: the
441
+ # per-agent record of what it was tasked with.
442
+ who = str(ev.get("display") or ev.get("agent") or "?")
443
+ task = str(ev.get("task") or "").replace("\n", " ").strip()
444
+ line = f"{who}:{truncate(task, max(8, ui.width - 14))}" if task else who
445
+ print(f" {ui.s('▸', MAGENTA)} {ui.s(line, MAGENTA)}")
446
+ elif t == "subagent_end":
447
+ who = str(ev.get("display") or ev.get("agent") or "?")
448
+ status = str(ev.get("status") or "")
449
+ zh = SUBAGENT_STATUS.get(status, status or "?")
450
+ color = (GREEN if status == "done"
451
+ else YELLOW if status in ("cancelled", "max_steps")
452
+ else RED) if status else None
453
+ bits = [ui.s(zh, color) if color else zh]
454
+ if ev.get("steps") is not None:
455
+ bits.append(f"{ev['steps']} 步")
456
+ if ev.get("changes"):
457
+ bits.append(f"{ev['changes']} 处改动")
458
+ print(f" {ui.s('▪', MAGENTA)} {ui.s(who, MAGENTA, BOLD)} · "
459
+ f"{' · '.join(bits)}")
348
460
  elif t == "error":
349
461
  ui.error(str(ev.get("message", "")))
350
462
  elif t == "cancelled":
@@ -408,7 +520,7 @@ async def execute(
408
520
  reg = build_registry(cfg, approver)
409
521
  host = build_host(cfg, reg)
410
522
  if cfg.subagents:
411
- register_subagents(cfg, host, reg)
523
+ register_subagents(cfg, host, reg, on_event=on_event)
412
524
  rid = run_id or uuid.uuid4().hex[:12]
413
525
  extra = {"conversation_id": conversation_id} if conversation_id is not None else {}
414
526
  ctx = AgentContext(run_id=rid, user_id=cfg.user_id, extra=extra)
@@ -18,11 +18,12 @@ Pure data and formatting only — no terminal ownership of any kind.
18
18
  from __future__ import annotations
19
19
 
20
20
  import asyncio
21
+ import json
21
22
  import os
22
23
  import sys
23
24
  import time
24
25
 
25
- from .ui import fmt_duration, tool_call_label, truncate
26
+ from .ui import SUBAGENT_STATUS, fmt_duration, tool_call_label, truncate
26
27
 
27
28
  _STATUS_DONE = "done"
28
29
 
@@ -240,6 +241,60 @@ class TuiState:
240
241
  # step boundary; render it as a user line so the transcript
241
242
  # shows why the model's course changed.
242
243
  self.say("user", str(ev.get("text") or ""))
244
+ elif kind == "subagent_start":
245
+ # Per-delegation record (ToolResult.ui): which worker got what
246
+ # task — the group's feed line, labeled with the display name.
247
+ who = str(ev.get("display") or ev.get("agent") or "?")
248
+ task = str(ev.get("task") or "").replace("\n", " ").strip()
249
+ self.say("tool", f"▸ {who}:{task[:120]}" if task else f"▸ {who}")
250
+ elif kind == "subagent_end":
251
+ who = str(ev.get("display") or ev.get("agent") or "?")
252
+ status = str(ev.get("status") or "")
253
+ bits = [SUBAGENT_STATUS.get(status, status or "?")]
254
+ if ev.get("steps") is not None:
255
+ bits.append(f"{ev['steps']} 步")
256
+ if ev.get("changes"):
257
+ bits.append(f"{ev['changes']} 处改动")
258
+ cls = ("ok" if ev.get("ok")
259
+ else "warn" if status == "cancelled" else "err")
260
+ self.say(cls, f"▪ {who} · " + " · ".join(bits))
261
+ elif kind == "subagent_progress":
262
+ # Live heartbeat (kernel on_subagent_event, wired in
263
+ # register_subagents): each worker's tool calls and outputs,
264
+ # prefixed so parallel workers stay distinguishable.
265
+ who = str(ev.get("display") or ev.get("agent") or "?")
266
+ inner = ev.get("event") or {}
267
+ t = inner.get("type")
268
+ if t == "tool_call":
269
+ name = str(inner.get("name") or "")
270
+ args = inner.get("args")
271
+ if isinstance(args, str):
272
+ try:
273
+ args = json.loads(args)
274
+ except (ValueError, TypeError):
275
+ args = {}
276
+ args = args if isinstance(args, dict) else {}
277
+ self.say("tool", f"[{who}] ◆ {tool_call_label(name, args)}")
278
+ elif t == "tool_result":
279
+ ok = bool(inner.get("ok"))
280
+ label = str(inner.get("summary") or "").replace("\n", " ")
281
+ if not ok and inner.get("error"):
282
+ detail = str(inner["error"]).replace("\n", " ")
283
+ if detail and label and (detail in label or label in detail):
284
+ label = detail if len(detail) > len(label) else label
285
+ elif detail:
286
+ label = f"{label} · {detail}" if label else detail
287
+ self.say("ok" if ok else "err",
288
+ f"[{who}] {'✓' if ok else '✗'} {label}")
289
+ elif t == "assistant":
290
+ text = str(inner.get("text") or "").replace("\n", " ").strip()
291
+ if text:
292
+ self.say("dim", f"[{who}] {text[:200]}")
293
+ elif t == "error":
294
+ msg = str(inner.get("message") or "出错").replace("\n", " ")
295
+ self.say("err", f"[{who}] {msg[:200]}")
296
+ elif t == "cancelled":
297
+ self.say("warn", f"[{who}] 已取消")
243
298
  elif kind == "done":
244
299
  status = str(ev.get("status") or _STATUS_DONE)
245
300
  self.last_status = status
@@ -262,6 +317,13 @@ class TuiState:
262
317
  self._turn_cost = float(ev["cost"])
263
318
  self._done_seen = True
264
319
  self._fold_turn()
320
+ if ev.get("subagent_delegations"):
321
+ # Delegation footprint in the feed: count + subagent-only
322
+ # spend (the folded cost above already includes it).
323
+ extra = f"委派 {ev['subagent_delegations']} 次"
324
+ if ev.get("subagent_cost"):
325
+ extra += f" · 子代理花费 ${float(ev['subagent_cost']):.4f}"
326
+ self.say("dim", extra)
265
327
  if ev.get("context_tokens") is not None:
266
328
  self.context_tokens = int(ev["context_tokens"])
267
329
  if ev.get("context_window") is not None:
@@ -32,6 +32,16 @@ _OK_STATES = frozenset({"done"})
32
32
  _BAD_STATES = frozenset({"failed", "error", "budget_exceeded", "max_steps"})
33
33
  _WARN_STATES = frozenset({"cancelled", "running"})
34
34
 
35
+ # Subagent end-states (kernel RunStats.status) → display text, shared by the
36
+ # line renderer and the TUI feed.
37
+ SUBAGENT_STATUS = {
38
+ "done": "完成",
39
+ "failed": "失败",
40
+ "cancelled": "已取消",
41
+ "budget_exceeded": "预算超限",
42
+ "max_steps": "步数上限",
43
+ }
44
+
35
45
  _ROLE_STYLES = {
36
46
  "user": BLUE,
37
47
  "assistant": GREEN,
@@ -119,6 +129,22 @@ def tool_call_label(name: str, args: dict) -> str:
119
129
  ]
120
130
  files = "、".join(dict.fromkeys(paths))
121
131
  return f"{name} · {files}" if files else f"{name} · 文件补丁"
132
+ if name == "delegate":
133
+ agent = str(args.get("agent") or "").strip()
134
+ task = str(args.get("task") or "").strip().replace("\n", " ")
135
+ if agent and task:
136
+ return f"{name} · {agent}:{truncate(task, 60)}"
137
+ if agent:
138
+ return f"{name} · {agent}"
139
+ return name
140
+ if name == "delegate_parallel":
141
+ tasks = args.get("tasks")
142
+ if isinstance(tasks, list) and tasks:
143
+ agents = [str(t.get("agent") or "?") if isinstance(t, dict) else "?"
144
+ for t in tasks]
145
+ roster = "、".join(dict.fromkeys(agents))
146
+ return f"{name} · {roster}({len(tasks)} 项)"
147
+ return name
122
148
  for key in ("query", "pattern", "agent", "command", "url"):
123
149
  value = args.get(key)
124
150
  if isinstance(value, str) and value.strip():
@@ -295,6 +321,14 @@ class UI:
295
321
  cost = ev.get("cost")
296
322
  if cost:
297
323
  parts.append(f"cost {cost:.4f}")
324
+ if ev.get("subagent_delegations"):
325
+ parts.append(f"delegations {int(ev['subagent_delegations'])}")
326
+ if ev.get("subagent_cost"):
327
+ parts.append(f"sub-cost {float(ev['subagent_cost']):.4f}")
328
+ if ev.get("context_percent") is not None:
329
+ parts.append(f"ctx {ev['context_percent']}%")
330
+ elif ev.get("context_tokens"):
331
+ parts.append(f"ctx {ev['context_tokens']}tk")
298
332
  duration = fmt_duration(ev.get("duration_s"))
299
333
  if duration:
300
334
  parts.append(duration)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
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
 
@@ -133,3 +133,115 @@ def test_set_subagents_toggles_and_warns(tmp_path):
133
133
 
134
134
  def test_system_prompt_mentions_delegation():
135
135
  assert "delegate" in build_system_prompt(Config(subagents=True))
136
+
137
+
138
+ def test_delegation_renders_live_progress_and_records(tmp_path, capsys):
139
+ """行模式下委派全程可见:调用标签带 roster、实时心跳带显示名、
140
+ start/end 记录与 footer 委派计数。"""
141
+ cfg = make_config(tmp_path, DELEGATE_SCRIPT)
142
+ cfg.subagents = True
143
+ cfg.workspace_dir.mkdir(parents=True, exist_ok=True)
144
+ (cfg.workspace_dir / "a.md").write_text("- 待办", encoding="utf-8")
145
+
146
+ from lithe_cli.agent import execute
147
+
148
+ rid, done, host = asyncio.run(execute(cfg, "看看 a.md 是什么"))
149
+ assert done["status"] == "done"
150
+ out = capsys.readouterr().out
151
+ # the parallel call line names the roster and the task count
152
+ assert "researcher(1 项)" in out
153
+ # live heartbeat: the worker's answer, labeled with its display name
154
+ assert "[检索员]" in out
155
+ assert "a.md 的内容是待办清单" in out
156
+ # per-agent start/end records follow the delegation's tool_result
157
+ assert "▸ 检索员:找一下 a.md 里写了什么" in out
158
+ assert "▪ 检索员 · 完成" in out
159
+ # the footer carries the delegation footprint
160
+ assert "delegations 1" in out
161
+
162
+
163
+ def test_tool_call_labels_delegation():
164
+ from lithe_cli.ui import tool_call_label
165
+
166
+ label = tool_call_label("delegate", {"agent": "researcher",
167
+ "task": "找一下 a.md 里写了什么"})
168
+ assert label == "delegate · researcher:找一下 a.md 里写了什么"
169
+ assert tool_call_label("delegate", {"agent": "researcher"}) == \
170
+ "delegate · researcher"
171
+ par = tool_call_label("delegate_parallel", {"tasks": [
172
+ {"agent": "researcher", "task": "查 a"},
173
+ {"agent": "coder", "task": "改 b"},
174
+ {"agent": "researcher", "task": "查 c"},
175
+ ]})
176
+ assert par == "delegate_parallel · researcher、coder(3 项)"
177
+
178
+
179
+ def test_render_event_subagent_records(capsys):
180
+ from lithe_cli.agent import render_event
181
+
182
+ render_event({"type": "subagent_start", "agent": "researcher",
183
+ "display": "检索员", "task": "审查配置"})
184
+ render_event({"type": "subagent_end", "agent": "researcher",
185
+ "display": "检索员", "status": "done", "steps": 4,
186
+ "changes": 2, "ok": True})
187
+ out = capsys.readouterr().out
188
+ assert "▸ 检索员:审查配置" in out
189
+ assert "▪ 检索员 · 完成 · 4 步 · 2 处改动" in out
190
+
191
+
192
+ def test_render_event_subagent_progress(capsys):
193
+ from lithe_cli.agent import render_event
194
+
195
+ render_event({"type": "subagent_progress", "agent": "coder",
196
+ "display": "编码员", "event": {
197
+ "type": "tool_call", "name": "read_file",
198
+ "args": '{"path": "cfg.py"}'}})
199
+ render_event({"type": "subagent_progress", "agent": "coder",
200
+ "display": "编码员", "event": {
201
+ "type": "tool_result", "ok": False,
202
+ "summary": "参数错误", "error": "文件不存在"}})
203
+ out = capsys.readouterr().out
204
+ assert "[编码员]" in out
205
+ assert "read_file" in out and "cfg.py" in out
206
+ assert "✗" in out and "文件不存在" in out
207
+
208
+
209
+ def test_footer_shows_delegation_and_context(capsys):
210
+ from lithe_cli.ui import UI
211
+
212
+ UI(color=False).footer({"status": "done", "steps": 3, "tokens": 900,
213
+ "subagent_delegations": 2,
214
+ "subagent_cost": 0.0123,
215
+ "context_percent": 42,
216
+ "duration_s": 10.0})
217
+ out = capsys.readouterr().out
218
+ assert "delegations 2" in out
219
+ assert "sub-cost 0.0123" in out
220
+ assert "ctx 42%" in out
221
+
222
+
223
+ def test_tui_folds_subagent_events():
224
+ from lithe_cli.tui import TuiState
225
+
226
+ state = TuiState("m", "/ws", 5)
227
+ state.on_event({"type": "subagent_start", "agent": "researcher",
228
+ "display": "检索员", "task": "查 a.md"})
229
+ state.on_event({"type": "subagent_progress", "agent": "researcher",
230
+ "display": "检索员", "event": {
231
+ "type": "tool_call", "name": "read_file",
232
+ "args": '{"path": "a.md"}'}})
233
+ state.on_event({"type": "subagent_progress", "agent": "researcher",
234
+ "display": "检索员", "event": {
235
+ "type": "tool_result", "ok": True,
236
+ "summary": "读取 a.md"}})
237
+ state.on_event({"type": "subagent_end", "agent": "researcher",
238
+ "display": "检索员", "status": "done", "steps": 2,
239
+ "changes": 0, "ok": True})
240
+ state.on_event({"type": "done", "status": "done", "steps": 2,
241
+ "subagent_delegations": 1, "subagent_cost": 0.01})
242
+ feed = "\n".join(text for _, text in state.feed)
243
+ assert "▸ 检索员:查 a.md" in feed
244
+ assert "[检索员] ◆ read_file · 读取 a.md" in feed
245
+ assert "[检索员] ✓ 读取 a.md" in feed
246
+ assert "▪ 检索员 · 完成 · 2 步" in feed
247
+ assert "委派 1 次" in feed and "子代理花费 $0.0100" in feed
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