lithe-cli 0.6.6__tar.gz → 0.6.7__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.6.6
3
+ Version: 0.6.7
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.6.6"
3
+ __version__ = "0.6.7"
@@ -122,11 +122,13 @@ class TuiState:
122
122
  self.input_tokens = 0
123
123
  self.output_tokens = 0
124
124
  self.cached_tokens = 0
125
+ self.last_turn_cost = 0.0
125
126
  self._turn_tokens = 0
126
127
  self._turn_cost = 0.0
127
128
  self._turn_input_tokens = 0
128
129
  self._turn_output_tokens = 0
129
130
  self._turn_cached_tokens = 0
131
+ self._done_seen = True
130
132
  self.context_tokens = None
131
133
  self.context_window = None
132
134
  self.context_percent = None
@@ -176,26 +178,43 @@ class TuiState:
176
178
  self.input_tokens = 0
177
179
  self.output_tokens = 0
178
180
  self.cached_tokens = 0
181
+ self.last_turn_cost = 0.0
179
182
  self._turn_tokens = 0
180
183
  self._turn_cost = 0.0
181
184
  self._turn_input_tokens = 0
182
185
  self._turn_output_tokens = 0
183
186
  self._turn_cached_tokens = 0
187
+ self._done_seen = True
184
188
  self.context_tokens = None
185
189
  self.context_window = None
186
190
  self.context_percent = None
187
191
 
192
+ def _fold_turn(self) -> None:
193
+ """Fold the current turn's usage into session totals and clear it."""
194
+ self.input_tokens += self._turn_input_tokens
195
+ self.output_tokens += self._turn_output_tokens
196
+ self.cached_tokens += self._turn_cached_tokens
197
+ self.tokens += self._turn_tokens
198
+ self.cost += self._turn_cost
199
+ self.last_turn_cost = self._turn_cost
200
+ self._turn_tokens = 0
201
+ self._turn_cost = 0.0
202
+ self._turn_input_tokens = 0
203
+ self._turn_output_tokens = 0
204
+ self._turn_cached_tokens = 0
205
+
188
206
  def on_event(self, ev: dict) -> None:
189
207
  kind = ev.get("type")
190
208
  if kind == "run_start":
191
209
  self.status = "思考中"
192
210
  self.step = 0
193
211
  self.scroll = 0
194
- self._turn_tokens = 0
195
- self._turn_cost = 0.0
196
- self._turn_input_tokens = 0
197
- self._turn_output_tokens = 0
198
- self._turn_cached_tokens = 0
212
+ # A previous round that died without a done event (host-level
213
+ # failure) still burned tokens: keep its measured usage instead
214
+ # of silently dropping it when the accumulators reset.
215
+ if not self._done_seen:
216
+ self._fold_turn()
217
+ self._done_seen = False
199
218
  self.context_tokens = None
200
219
  self.context_window = None
201
220
  self.context_percent = None
@@ -284,16 +303,8 @@ class TuiState:
284
303
  self._turn_tokens = int(ev["tokens"])
285
304
  if ev.get("cost") is not None:
286
305
  self._turn_cost = float(ev["cost"])
287
- self.input_tokens += self._turn_input_tokens
288
- self.output_tokens += self._turn_output_tokens
289
- self.cached_tokens += self._turn_cached_tokens
290
- self.tokens += self._turn_tokens
291
- self.cost += self._turn_cost
292
- self._turn_tokens = 0
293
- self._turn_cost = 0.0
294
- self._turn_input_tokens = 0
295
- self._turn_output_tokens = 0
296
- self._turn_cached_tokens = 0
306
+ self._done_seen = True
307
+ self._fold_turn()
297
308
  if ev.get("context_tokens") is not None:
298
309
  self.context_tokens = int(ev["context_tokens"])
299
310
  if ev.get("context_window") is not None:
@@ -494,6 +505,10 @@ def _sidebar_lines(state: TuiState) -> list[tuple[str, str]]:
494
505
  cached_tokens = state.cached_tokens + state._turn_cached_tokens
495
506
  tokens = state.tokens + state._turn_tokens
496
507
  cost = state.cost + state._turn_cost
508
+ if state.running or not state._done_seen:
509
+ turn_cost = state._turn_cost
510
+ else:
511
+ turn_cost = state.last_turn_cost
497
512
  context = "—"
498
513
  if state.context_tokens is not None:
499
514
  context = f"{state.context_tokens:,}"
@@ -504,9 +519,12 @@ def _sidebar_lines(state: TuiState) -> list[tuple[str, str]]:
504
519
  lines.extend(
505
520
  [
506
521
  ("dim", "◆ 会话用量"),
507
- ("", f"输入 {input_tokens:,} · 输出 {output_tokens:,}"),
522
+ ("", f"输入 {input_tokens:,}"),
523
+ ("", f"输出 {output_tokens:,}"),
508
524
  ("", f"缓存输入 {cached_tokens:,}"),
509
- ("", f"合计 {tokens:,} · ${cost:.4f}"),
525
+ ("", f"合计 {tokens:,}"),
526
+ ("", f"本轮费用 ${turn_cost:.4f}"),
527
+ ("", f"累计费用 ${cost:.4f}"),
510
528
  ("", f"上下文 {context}"),
511
529
  ]
512
530
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lithe-cli
3
- Version: 0.6.6
3
+ Version: 0.6.7
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
 
@@ -330,14 +330,66 @@ def test_run_dashboard_shows_tools_todos_and_usage():
330
330
  assert state.tokens == 180 and state.cost == pytest.approx(0.003)
331
331
  assert state.input_tokens == 150 and state.output_tokens == 30
332
332
  assert state.cached_tokens == 85 and state.context_tokens == 50
333
+ assert state.last_turn_cost == pytest.approx(0.002)
333
334
  from lithe_cli.tui import _sidebar_lines
334
335
 
335
336
  usage_text = "\n".join(text for _, text in _sidebar_lines(state))
336
- assert "输入 150 · 输出 30" in usage_text
337
- assert "缓存输入 85" in usage_text
337
+ assert "输入 150" in usage_text and "输出 30" in usage_text
338
+ assert "缓存输入 85" in usage_text and "合计 180" in usage_text
339
+ assert "本轮费用 $0.0020" in usage_text
340
+ assert "累计费用 $0.0030" in usage_text
338
341
  assert "50 / 500 (10.0%)" in usage_text
339
342
 
340
343
 
344
+ def test_sidebar_usage_is_one_metric_per_line():
345
+ from lithe_cli.tui import TuiState, _sidebar_lines
346
+
347
+ state = TuiState("模型", "/ws", 5)
348
+ state.on_event({"type": "run_start"})
349
+ state.on_event({
350
+ "type": "usage",
351
+ "prompt_tokens": 1200,
352
+ "completion_tokens": 340,
353
+ "cached_tokens": 900,
354
+ "total_tokens": 1540,
355
+ "cost": 0.0123,
356
+ })
357
+ lines = [text for _, text in _sidebar_lines(state)]
358
+ labels = ("输入 ", "输出 ", "缓存输入 ", "合计 ", "本轮费用 ", "累计费用 ")
359
+ usage = [line for line in lines if line.startswith(labels)]
360
+ for line in usage:
361
+ assert sum(line.startswith(label) for label in labels) == 1
362
+ assert len(usage) == 6
363
+ assert "输入 1,200" in lines and "输出 340" in lines
364
+ assert "缓存输入 900" in lines and "合计 1,540" in lines
365
+ assert "本轮费用 $0.0123" in lines and "累计费用 $0.0123" in lines
366
+
367
+
368
+ def test_usage_from_a_round_that_died_without_done_is_kept():
369
+ from lithe_cli.tui import TuiState
370
+
371
+ state = TuiState("模型", "/ws", 5)
372
+ state.on_event({"type": "run_start"})
373
+ state.on_event({
374
+ "type": "usage",
375
+ "prompt_tokens": 100,
376
+ "completion_tokens": 20,
377
+ "total_tokens": 120,
378
+ "cost": 0.001,
379
+ })
380
+ state.on_event({"type": "error", "message": "host blew up before done"})
381
+ state.on_event({"type": "run_start"})
382
+ assert state.cost == pytest.approx(0.001)
383
+ assert state.input_tokens == 100 and state.tokens == 120
384
+ state.on_event({
385
+ "type": "done", "status": "done", "steps": 1,
386
+ "tokens": 60, "prompt_tokens": 50, "completion_tokens": 10,
387
+ "cost": 0.002,
388
+ })
389
+ assert state.cost == pytest.approx(0.003)
390
+ assert state.last_turn_cost == pytest.approx(0.002)
391
+
392
+
341
393
  def test_system_prompt_prefers_localized_file_edits_and_limits_todo_planning():
342
394
  from lithe_cli.agent import SYSTEM_PROMPT_BASE
343
395
 
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