soothe-cli 1.2.7__tar.gz → 1.2.9__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.
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/PKG-INFO +1 -1
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/renderer_base.py +0 -4
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/state/session_stats.py +28 -42
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/token_events_debug.py +19 -2
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/token_usage.py +56 -21
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/turn/prepare.py +5 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_app.py +5 -5
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_model.py +5 -2
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_startup.py +0 -1
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_ui.py +29 -41
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/textual_adapter.py +69 -73
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/context_data.py +13 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/status.py +1 -17
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/.gitignore +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/README.md +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/pyproject.toml +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/_cli_context.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/_env_vars.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/_version.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/card_wire.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/commands/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/commands/config_cmd.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/commands/cron_cmd.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/commands/loop_cmd.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/commands/run_cmd.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/commands/status_cmd.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/execution/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/execution/daemon.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/execution/daemon_errors.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/execution/headless.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/execution/headless_renderer.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/execution/launcher.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/main.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/cli/soothecli.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/commands/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/commands/binding.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/commands/command_registry.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/commands/command_router.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/commands/slash_commands.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/commands/subagent_routing.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/config/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/config/cli_config.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/config/loader.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/config/logging_setup.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/card.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/card_binder.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/markdown_theme.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/media_utils.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/mermaid_render.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/path_utils.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/preview_limits.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/shell_color.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/spinner_labels.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/text_extract.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/theme.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/tips.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/tool_display.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/display/unicode_security.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/loops/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/loops/sessions.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/model_config.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/project_utils.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/headless/processor.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/headless/processor_state.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/parse/tool_call_resolution.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/policy/tui_trace_log.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/duration_format.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/engine.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/id_format.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/renderer_protocol.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/step_id_format.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/presentation/subagent_task_display.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/state/file_tracker.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/state/step_router.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/state/stream_accumulator.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/transport/session.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/wire/chunk_filter.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/wire/message_text.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/runtime/wire/messages.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/_console_impl.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/bootstrap.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/core.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/glyphs.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/provider.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/shell_allow.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/skills_dirs.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/settings/stream_config.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_clarification.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_entrypoints.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_execution.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_history.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_messages_mixin.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_model_params.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_terminal.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_theme_prefs.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/_types.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/app/app.tcss +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/composer_mode.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/file_change_notify.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/file_change_renderers.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/input.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/skills/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/skills/invocation.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/skills/load.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/_links.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/autocomplete.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/chat_input.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/clipboard.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/context_viewer.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/diff.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/editor.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/file_change_preview.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/help_screen.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/history.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/loading.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/loop_selector.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/mcp_viewer.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/message_store.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/_helpers.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/app.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/assistant.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/cognition_goal_tree.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/cognition_reason.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/cognition_step.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/cognition_step_activity.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/diff_message.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/error.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/skill.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/structured_ask_user.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/messages/user.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/model_selector.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/notification_settings.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/pinned_goal_bar.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/plan_quick_view_overlay.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/queued_goals_bar.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/router_profile_selector.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/theme_selector.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/tui/widgets/welcome.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/update_check.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/ux/__init__.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/ux/subagent_progress.py +0 -0
- {soothe_cli-1.2.7 → soothe_cli-1.2.9}/src/soothe_cli/ux/subagent_wire_display.py +0 -0
|
@@ -20,10 +20,6 @@ class RendererBase:
|
|
|
20
20
|
def repair_concatenated_output(text: str) -> str:
|
|
21
21
|
"""Repair common markdown/text concatenation artifacts.
|
|
22
22
|
|
|
23
|
-
Consolidates the repair logic previously duplicated in:
|
|
24
|
-
- CLI: _repair_concatenated_final_output()
|
|
25
|
-
- TUI: _repair_concatenated_output_text()
|
|
26
|
-
|
|
27
23
|
Fixes issues that arise when streaming text chunks are concatenated:
|
|
28
24
|
- Missing newlines before headings
|
|
29
25
|
- Missing spaces after heading markers
|
|
@@ -7,6 +7,8 @@ import time
|
|
|
7
7
|
from dataclasses import dataclass, field
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
|
+
from soothe_cli.runtime.token_usage import TokenUsage
|
|
11
|
+
|
|
10
12
|
SpinnerStatus = str | None
|
|
11
13
|
"""Spinner line label, or `None` to hide.
|
|
12
14
|
|
|
@@ -17,68 +19,46 @@ Common single-word values include ``Thinking``, ``Planning``, ``Executing``,
|
|
|
17
19
|
|
|
18
20
|
@dataclass
|
|
19
21
|
class ModelStats:
|
|
20
|
-
"""Token stats for a single model within a session.
|
|
21
|
-
|
|
22
|
-
Attributes:
|
|
23
|
-
request_count: Number of LLM API requests made to this model.
|
|
24
|
-
input_tokens: Cumulative input tokens sent to this model.
|
|
25
|
-
output_tokens: Cumulative output tokens received from this model.
|
|
26
|
-
"""
|
|
22
|
+
"""Token stats for a single model within a session."""
|
|
27
23
|
|
|
28
24
|
request_count: int = 0
|
|
29
25
|
input_tokens: int = 0
|
|
30
26
|
output_tokens: int = 0
|
|
27
|
+
total_tokens: int = 0
|
|
28
|
+
cache_read_tokens: int = 0
|
|
29
|
+
cache_creation_tokens: int = 0
|
|
31
30
|
|
|
32
31
|
|
|
33
32
|
@dataclass
|
|
34
33
|
class SessionStats:
|
|
35
|
-
"""Stats accumulated over a single agent turn (or full session).
|
|
36
|
-
|
|
37
|
-
Attributes:
|
|
38
|
-
request_count: Total LLM API requests made (each chunk with
|
|
39
|
-
usage_metadata counts as one completed request).
|
|
40
|
-
input_tokens: Cumulative input tokens across all LLM requests.
|
|
41
|
-
output_tokens: Cumulative output tokens across all LLM requests.
|
|
42
|
-
wall_time_seconds: Wall-clock duration from stream start to end.
|
|
43
|
-
per_model: Per-model breakdown keyed by model name.
|
|
44
|
-
Populated only when `record_request` receives a non-empty
|
|
45
|
-
`model_name`. Empty dict means no named-model requests were
|
|
46
|
-
recorded; `print_usage_table` omits the model table in that case and
|
|
47
|
-
shows only the wall-time line (if applicable).
|
|
48
|
-
"""
|
|
34
|
+
"""Stats accumulated over a single agent turn (or full session)."""
|
|
49
35
|
|
|
50
36
|
request_count: int = 0
|
|
51
37
|
input_tokens: int = 0
|
|
52
38
|
output_tokens: int = 0
|
|
39
|
+
total_tokens: int = 0
|
|
40
|
+
cache_read_tokens: int = 0
|
|
41
|
+
cache_creation_tokens: int = 0
|
|
53
42
|
wall_time_seconds: float = 0.0
|
|
54
43
|
per_model: dict[str, ModelStats] = field(default_factory=dict)
|
|
55
44
|
event_stats: TurnEventStats | None = None
|
|
56
45
|
|
|
57
|
-
def record_request(
|
|
58
|
-
|
|
59
|
-
model_name: str,
|
|
60
|
-
input_toks: int,
|
|
61
|
-
output_toks: int,
|
|
62
|
-
) -> None:
|
|
63
|
-
"""Accumulate token counts for one completed LLM request.
|
|
64
|
-
|
|
65
|
-
Updates both the session totals and the per-model breakdown.
|
|
66
|
-
|
|
67
|
-
Args:
|
|
68
|
-
model_name: The model that served this request (used as the
|
|
69
|
-
per-model key). Pass an empty string to skip the per-model
|
|
70
|
-
breakdown for this request.
|
|
71
|
-
input_toks: Input tokens for this request.
|
|
72
|
-
output_toks: Output tokens for this request.
|
|
73
|
-
"""
|
|
46
|
+
def record_request(self, model_name: str, usage: TokenUsage) -> None:
|
|
47
|
+
"""Accumulate one LLM request's full token breakdown."""
|
|
74
48
|
self.request_count += 1
|
|
75
|
-
self.input_tokens +=
|
|
76
|
-
self.output_tokens +=
|
|
49
|
+
self.input_tokens += usage.input_tokens
|
|
50
|
+
self.output_tokens += usage.output_tokens
|
|
51
|
+
self.total_tokens += usage.total_tokens
|
|
52
|
+
self.cache_read_tokens += usage.cache_read_tokens
|
|
53
|
+
self.cache_creation_tokens += usage.cache_creation_tokens
|
|
77
54
|
if model_name:
|
|
78
55
|
entry = self.per_model.setdefault(model_name, ModelStats())
|
|
79
56
|
entry.request_count += 1
|
|
80
|
-
entry.input_tokens +=
|
|
81
|
-
entry.output_tokens +=
|
|
57
|
+
entry.input_tokens += usage.input_tokens
|
|
58
|
+
entry.output_tokens += usage.output_tokens
|
|
59
|
+
entry.total_tokens += usage.total_tokens
|
|
60
|
+
entry.cache_read_tokens += usage.cache_read_tokens
|
|
61
|
+
entry.cache_creation_tokens += usage.cache_creation_tokens
|
|
82
62
|
|
|
83
63
|
def merge(self, other: SessionStats) -> None:
|
|
84
64
|
"""Merge another `SessionStats` into this one (mutates *self*).
|
|
@@ -91,12 +71,18 @@ class SessionStats:
|
|
|
91
71
|
self.request_count += other.request_count
|
|
92
72
|
self.input_tokens += other.input_tokens
|
|
93
73
|
self.output_tokens += other.output_tokens
|
|
74
|
+
self.total_tokens += other.total_tokens
|
|
75
|
+
self.cache_read_tokens += other.cache_read_tokens
|
|
76
|
+
self.cache_creation_tokens += other.cache_creation_tokens
|
|
94
77
|
self.wall_time_seconds += other.wall_time_seconds
|
|
95
78
|
for model, ms in other.per_model.items():
|
|
96
79
|
entry = self.per_model.setdefault(model, ModelStats())
|
|
97
80
|
entry.request_count += ms.request_count
|
|
98
81
|
entry.input_tokens += ms.input_tokens
|
|
99
82
|
entry.output_tokens += ms.output_tokens
|
|
83
|
+
entry.total_tokens += ms.total_tokens
|
|
84
|
+
entry.cache_read_tokens += ms.cache_read_tokens
|
|
85
|
+
entry.cache_creation_tokens += ms.cache_creation_tokens
|
|
100
86
|
if other.event_stats is not None:
|
|
101
87
|
if self.event_stats is None:
|
|
102
88
|
self.event_stats = TurnEventStats()
|
|
@@ -18,6 +18,8 @@ class TokenEventTrace:
|
|
|
18
18
|
plan_phase_missing_total_field: int = 0
|
|
19
19
|
step_completed_events: int = 0
|
|
20
20
|
step_completed_with_total_field: int = 0
|
|
21
|
+
completed_events: int = 0
|
|
22
|
+
completed_with_total_field: int = 0
|
|
21
23
|
authoritative_applied: int = 0
|
|
22
24
|
display_refreshes: int = 0
|
|
23
25
|
anomalies: list[str] = field(default_factory=list)
|
|
@@ -30,6 +32,8 @@ class TokenEventTrace:
|
|
|
30
32
|
self.plan_phase_missing_total_field = 0
|
|
31
33
|
self.step_completed_events = 0
|
|
32
34
|
self.step_completed_with_total_field = 0
|
|
35
|
+
self.completed_events = 0
|
|
36
|
+
self.completed_with_total_field = 0
|
|
33
37
|
self.authoritative_applied = 0
|
|
34
38
|
self.display_refreshes = 0
|
|
35
39
|
self.anomalies.clear()
|
|
@@ -78,6 +82,17 @@ class TokenEventTrace:
|
|
|
78
82
|
has_total_field,
|
|
79
83
|
)
|
|
80
84
|
|
|
85
|
+
def note_completed(self, *, total_tokens_used: int | None, has_total_field: bool) -> None:
|
|
86
|
+
"""Record the turn-end authoritative total from `strange_loop.completed`."""
|
|
87
|
+
self.completed_events += 1
|
|
88
|
+
if has_total_field:
|
|
89
|
+
self.completed_with_total_field += 1
|
|
90
|
+
logger.debug(
|
|
91
|
+
"[token-events] completed total=%s has_total_field=%s",
|
|
92
|
+
total_tokens_used if has_total_field else "—",
|
|
93
|
+
has_total_field,
|
|
94
|
+
)
|
|
95
|
+
|
|
81
96
|
def note_authoritative_merge(
|
|
82
97
|
self,
|
|
83
98
|
*,
|
|
@@ -123,7 +138,9 @@ class TokenEventTrace:
|
|
|
123
138
|
"""Emit one summary line per turn; flags missing events."""
|
|
124
139
|
has_stream = self.stream_chunks > 0
|
|
125
140
|
has_backend_total = (
|
|
126
|
-
self.plan_phase_with_total_field > 0
|
|
141
|
+
self.plan_phase_with_total_field > 0
|
|
142
|
+
or self.step_completed_with_total_field > 0
|
|
143
|
+
or self.completed_with_total_field > 0
|
|
127
144
|
)
|
|
128
145
|
has_any_usage = display_total > 0 or turn_input > 0 or turn_output > 0
|
|
129
146
|
|
|
@@ -163,4 +180,4 @@ class TokenEventTrace:
|
|
|
163
180
|
)
|
|
164
181
|
|
|
165
182
|
|
|
166
|
-
__all__ = ["TokenEventTrace"
|
|
183
|
+
__all__ = ["TokenEventTrace"]
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
|
+
from dataclasses import dataclass
|
|
6
7
|
from typing import Any
|
|
7
8
|
|
|
8
9
|
logger = logging.getLogger(__name__)
|
|
9
10
|
|
|
10
11
|
__all__ = [
|
|
12
|
+
"TokenUsage",
|
|
11
13
|
"coerce_total_tokens_used",
|
|
12
14
|
"extract_stream_message_token_usage",
|
|
13
15
|
"fetch_conversation_token_count",
|
|
@@ -23,41 +25,75 @@ def coerce_total_tokens_used(value: Any) -> int:
|
|
|
23
25
|
return 0
|
|
24
26
|
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class TokenUsage:
|
|
30
|
+
"""Full per-call token breakdown (cache stays a subset of input)."""
|
|
28
31
|
|
|
32
|
+
input_tokens: int = 0
|
|
33
|
+
output_tokens: int = 0
|
|
34
|
+
cache_read_tokens: int = 0
|
|
35
|
+
cache_creation_tokens: int = 0
|
|
36
|
+
total_tokens: int = 0
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
@classmethod
|
|
39
|
+
def from_mapping(cls, usage: dict[str, Any]) -> TokenUsage:
|
|
40
|
+
"""Build a breakdown from a LangChain/OpenAI usage mapping."""
|
|
41
|
+
input_toks = coerce_total_tokens_used(
|
|
42
|
+
usage.get("input_tokens") or usage.get("prompt_tokens")
|
|
43
|
+
)
|
|
44
|
+
output_toks = coerce_total_tokens_used(
|
|
45
|
+
usage.get("output_tokens") or usage.get("completion_tokens")
|
|
46
|
+
)
|
|
47
|
+
total_toks = coerce_total_tokens_used(usage.get("total_tokens")) or input_toks + output_toks
|
|
48
|
+
|
|
49
|
+
cache_read = 0
|
|
50
|
+
cache_creation = 0
|
|
51
|
+
details = usage.get("input_token_details")
|
|
52
|
+
if isinstance(details, dict):
|
|
53
|
+
cache_read = coerce_total_tokens_used(details.get("cache_read"))
|
|
54
|
+
cache_creation = coerce_total_tokens_used(details.get("cache_creation"))
|
|
55
|
+
prompt_details = usage.get("prompt_tokens_details")
|
|
56
|
+
if isinstance(prompt_details, dict):
|
|
57
|
+
cache_read = cache_read or coerce_total_tokens_used(prompt_details.get("cached_tokens"))
|
|
58
|
+
cache_read = cache_read or coerce_total_tokens_used(usage.get("cache_read_input_tokens"))
|
|
59
|
+
cache_creation = cache_creation or coerce_total_tokens_used(
|
|
60
|
+
usage.get("cache_creation_input_tokens")
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
return cls(input_toks, output_toks, cache_read, cache_creation, total_toks)
|
|
64
|
+
|
|
65
|
+
def has_any(self) -> bool:
|
|
66
|
+
"""True when any token count is present."""
|
|
67
|
+
return bool(
|
|
68
|
+
self.input_tokens
|
|
69
|
+
or self.output_tokens
|
|
70
|
+
or self.total_tokens
|
|
71
|
+
or self.cache_read_tokens
|
|
72
|
+
or self.cache_creation_tokens
|
|
73
|
+
)
|
|
38
74
|
|
|
39
75
|
|
|
40
|
-
def extract_stream_message_token_usage(message: Any) ->
|
|
41
|
-
"""Extract token
|
|
76
|
+
def extract_stream_message_token_usage(message: Any) -> TokenUsage:
|
|
77
|
+
"""Extract a full token breakdown from a streamed LangChain or wire message.
|
|
42
78
|
|
|
43
79
|
Providers vary:
|
|
44
|
-
- LangChain `usage_metadata` (`input_tokens` / `output_tokens`)
|
|
80
|
+
- LangChain `usage_metadata` (`input_tokens` / `output_tokens` + cache details)
|
|
45
81
|
- OpenAI-style `response_metadata.token_usage` (`prompt_tokens` / `completion_tokens`)
|
|
46
82
|
- Flat wire dicts with either shape
|
|
47
83
|
"""
|
|
48
84
|
if message is None:
|
|
49
|
-
return
|
|
85
|
+
return TokenUsage()
|
|
50
86
|
|
|
51
87
|
usage = getattr(message, "usage_metadata", None)
|
|
52
88
|
if isinstance(usage, dict) and usage:
|
|
53
|
-
return
|
|
89
|
+
return TokenUsage.from_mapping(usage)
|
|
54
90
|
|
|
55
91
|
response_metadata = getattr(message, "response_metadata", None)
|
|
56
92
|
if isinstance(response_metadata, dict):
|
|
57
93
|
for key in ("token_usage", "usage"):
|
|
58
94
|
nested = response_metadata.get(key)
|
|
59
95
|
if isinstance(nested, dict) and nested:
|
|
60
|
-
return
|
|
96
|
+
return TokenUsage.from_mapping(nested)
|
|
61
97
|
|
|
62
98
|
if isinstance(message, dict):
|
|
63
99
|
from soothe_cli.runtime.wire.message_text import wire_message_body
|
|
@@ -71,21 +107,20 @@ def extract_stream_message_token_usage(message: Any) -> tuple[int, int, int]:
|
|
|
71
107
|
continue
|
|
72
108
|
direct_usage = body.get("usage_metadata")
|
|
73
109
|
if isinstance(direct_usage, dict) and direct_usage:
|
|
74
|
-
return
|
|
110
|
+
return TokenUsage.from_mapping(direct_usage)
|
|
75
111
|
response = body.get("response_metadata")
|
|
76
112
|
if isinstance(response, dict):
|
|
77
113
|
for key in ("token_usage", "usage"):
|
|
78
114
|
nested_usage = response.get(key)
|
|
79
115
|
if isinstance(nested_usage, dict) and nested_usage:
|
|
80
|
-
return
|
|
116
|
+
return TokenUsage.from_mapping(nested_usage)
|
|
81
117
|
|
|
82
|
-
return
|
|
118
|
+
return TokenUsage()
|
|
83
119
|
|
|
84
120
|
|
|
85
121
|
def message_has_token_usage_metadata(message: Any) -> bool:
|
|
86
122
|
"""Return True when a stream message carries provider token usage."""
|
|
87
|
-
|
|
88
|
-
return bool(input_toks or output_toks or total_toks)
|
|
123
|
+
return extract_stream_message_token_usage(message).has_any()
|
|
89
124
|
|
|
90
125
|
|
|
91
126
|
async def fetch_conversation_token_count(daemon_session: Any, loop_id: str | None) -> int | None:
|
|
@@ -15,6 +15,7 @@ from soothe_client.appkit.turn import (
|
|
|
15
15
|
from soothe_client.core.events import (
|
|
16
16
|
STRANGE_LOOP_COMPLETED,
|
|
17
17
|
STRANGE_LOOP_PLAN_DECISION,
|
|
18
|
+
STRANGE_LOOP_PLAN_PHASE,
|
|
18
19
|
STRANGE_LOOP_STARTED,
|
|
19
20
|
STRANGE_LOOP_STEP_COMPLETED,
|
|
20
21
|
STRANGE_LOOP_STEP_QUEUED,
|
|
@@ -27,6 +28,7 @@ from soothe_client.ux.stream_tool_wire import STREAM_TOOL_CALL_UPDATE, TOOL_CALL
|
|
|
27
28
|
|
|
28
29
|
from soothe_cli.runtime.presentation.engine import PresentationEngine
|
|
29
30
|
from soothe_cli.runtime.state.session_stats import TurnEventStats
|
|
31
|
+
from soothe_cli.runtime.token_usage import message_has_token_usage_metadata
|
|
30
32
|
from soothe_cli.runtime.wire.chunk_filter import (
|
|
31
33
|
message_has_tool_invocation_metadata,
|
|
32
34
|
updates_chunk_is_noop,
|
|
@@ -43,6 +45,7 @@ _MAIN_LOOP_CUSTOM_TYPES = frozenset(
|
|
|
43
45
|
STRANGE_LOOP_STARTED,
|
|
44
46
|
STRANGE_LOOP_COMPLETED,
|
|
45
47
|
STRANGE_LOOP_PLAN_DECISION,
|
|
48
|
+
STRANGE_LOOP_PLAN_PHASE,
|
|
46
49
|
STRANGE_LOOP_STEP_STARTED,
|
|
47
50
|
STRANGE_LOOP_STEP_QUEUED,
|
|
48
51
|
STRANGE_LOOP_STEP_COMPLETED,
|
|
@@ -83,6 +86,8 @@ class TurnPrepareState:
|
|
|
83
86
|
def _message_priority(message: Any, *, is_summarization: bool) -> int:
|
|
84
87
|
if isinstance(message, ToolMessage):
|
|
85
88
|
return PRIORITY_NORMAL
|
|
89
|
+
if message_has_token_usage_metadata(message):
|
|
90
|
+
return PRIORITY_HIGH
|
|
86
91
|
if message_has_tool_invocation_metadata(message):
|
|
87
92
|
return PRIORITY_NORMAL
|
|
88
93
|
if is_summarization:
|
|
@@ -281,13 +281,13 @@ class SootheApp(
|
|
|
281
281
|
"""Loop id that ``_loop_*_tokens`` counters belong to."""
|
|
282
282
|
|
|
283
283
|
self._loop_baseline_tokens: int = 0
|
|
284
|
-
"""
|
|
284
|
+
"""Cumulative usage from completed goals (resume baseline)."""
|
|
285
285
|
|
|
286
|
-
self.
|
|
287
|
-
"""
|
|
286
|
+
self._loop_goal_run_tokens: int = 0
|
|
287
|
+
"""Authoritative per-goal cumulative total from backend lifecycle events."""
|
|
288
288
|
|
|
289
|
-
self.
|
|
290
|
-
"""
|
|
289
|
+
self._loop_turn_committed: bool = False
|
|
290
|
+
"""True once the active goal's usage has been folded into the baseline."""
|
|
291
291
|
|
|
292
292
|
self._tokens_approximate: bool = False
|
|
293
293
|
"""Whether the cached token count is stale (interrupted generation)."""
|
|
@@ -263,6 +263,7 @@ class _ModelMixin:
|
|
|
263
263
|
from soothe_cli.settings import settings
|
|
264
264
|
from soothe_cli.tui.widgets.context_data import load_token_usage_snapshot
|
|
265
265
|
|
|
266
|
+
inflight = self._inflight_turn_stats
|
|
266
267
|
return await load_token_usage_snapshot(
|
|
267
268
|
context_tokens=self._loop_token_total(),
|
|
268
269
|
approximate=self._tokens_approximate,
|
|
@@ -270,8 +271,10 @@ class _ModelMixin:
|
|
|
270
271
|
daemon_session=self._daemon_session,
|
|
271
272
|
model_name=settings.model_name,
|
|
272
273
|
context_limit=settings.model_context_limit,
|
|
273
|
-
input_tokens=
|
|
274
|
-
output_tokens=
|
|
274
|
+
input_tokens=inflight.input_tokens if inflight else 0,
|
|
275
|
+
output_tokens=inflight.output_tokens if inflight else 0,
|
|
276
|
+
cache_read_tokens=inflight.cache_read_tokens if inflight else 0,
|
|
277
|
+
cache_creation_tokens=inflight.cache_creation_tokens if inflight else 0,
|
|
275
278
|
)
|
|
276
279
|
|
|
277
280
|
async def _show_context_viewer(self) -> None:
|
|
@@ -221,7 +221,6 @@ class _StartupMixin:
|
|
|
221
221
|
self._ui_adapter._get_loop_token_breakdown = self._loop_token_breakdown
|
|
222
222
|
self._ui_adapter._on_begin_loop_turn_tokens = self._begin_loop_turn_tokens
|
|
223
223
|
self._ui_adapter._apply_authoritative_loop_tokens = self._apply_authoritative_loop_tokens
|
|
224
|
-
self._ui_adapter._on_tokens_hide = self._hide_tokens
|
|
225
224
|
self._dump_tui_debug_snapshot()
|
|
226
225
|
|
|
227
226
|
# Seed static slash commands now that the first frame has rendered.
|
|
@@ -59,24 +59,24 @@ class _UIMixin:
|
|
|
59
59
|
self._status_bar.set_tokens(count, approximate=approximate)
|
|
60
60
|
|
|
61
61
|
def _loop_token_total(self) -> int:
|
|
62
|
-
"""Return
|
|
63
|
-
return self.
|
|
62
|
+
"""Return the current cumulative loop usage (display total)."""
|
|
63
|
+
return self._display_token_total()
|
|
64
64
|
|
|
65
65
|
def _current_turn_token_total(self) -> int:
|
|
66
|
-
"""Best-effort tokens for the in-flight goal
|
|
67
|
-
goal_total = self.
|
|
66
|
+
"""Best-effort tokens for the in-flight goal (backend vs stream)."""
|
|
67
|
+
goal_total = self._loop_goal_run_tokens
|
|
68
68
|
inflight = getattr(self, "_inflight_turn_stats", None)
|
|
69
|
-
if inflight is None
|
|
70
|
-
return goal_total
|
|
71
|
-
stream_total = inflight.input_tokens + inflight.output_tokens
|
|
69
|
+
stream_total = inflight.input_tokens + inflight.output_tokens if inflight is not None else 0
|
|
72
70
|
return max(goal_total, stream_total)
|
|
73
71
|
|
|
74
72
|
def _display_token_total(self) -> int:
|
|
75
|
-
"""Return
|
|
73
|
+
"""Return completed-goal baseline plus the active goal's usage."""
|
|
74
|
+
if self._loop_turn_committed:
|
|
75
|
+
return self._loop_baseline_tokens
|
|
76
76
|
return self._loop_baseline_tokens + self._current_turn_token_total()
|
|
77
77
|
|
|
78
78
|
def _refresh_token_displays(self, *, approximate: bool | None = None) -> None:
|
|
79
|
-
"""Push the
|
|
79
|
+
"""Push the live token total to the thinking row and status bar."""
|
|
80
80
|
if approximate is not None:
|
|
81
81
|
self._tokens_approximate = self._tokens_approximate or approximate
|
|
82
82
|
total = self._display_token_total()
|
|
@@ -85,14 +85,11 @@ class _UIMixin:
|
|
|
85
85
|
status_bar = getattr(self, "_status_bar", None)
|
|
86
86
|
if loading_widget is not None:
|
|
87
87
|
loading_widget.set_token_usage(total, approximate=approximate_flag)
|
|
88
|
-
if status_bar:
|
|
89
|
-
status_bar.hide_tokens()
|
|
90
88
|
target = "thinking_row"
|
|
91
|
-
elif status_bar:
|
|
92
|
-
self._update_tokens(total, approximate=approximate_flag)
|
|
93
|
-
target = "status_bar"
|
|
94
89
|
else:
|
|
95
|
-
target = "
|
|
90
|
+
target = "status_bar"
|
|
91
|
+
if status_bar:
|
|
92
|
+
self._update_tokens(total, approximate=approximate_flag)
|
|
96
93
|
trace = self._token_event_trace()
|
|
97
94
|
if trace is not None:
|
|
98
95
|
trace.note_display_refresh(display_total=total, target=target)
|
|
@@ -100,7 +97,7 @@ class _UIMixin:
|
|
|
100
97
|
def _loop_token_breakdown(self) -> tuple[int, int, int]:
|
|
101
98
|
"""Return `(baseline, goal_run, display_total)` for debug tracing."""
|
|
102
99
|
baseline = self._loop_baseline_tokens
|
|
103
|
-
goal_run = self.
|
|
100
|
+
goal_run = self._loop_goal_run_tokens
|
|
104
101
|
return baseline, goal_run, self._display_token_total()
|
|
105
102
|
|
|
106
103
|
def _reset_loop_token_usage(
|
|
@@ -113,8 +110,8 @@ class _UIMixin:
|
|
|
113
110
|
"""Clear per-loop token counters (loop switch, /clear, or scope change)."""
|
|
114
111
|
self._loop_token_scope_id = str(loop_id or "").strip() or None
|
|
115
112
|
self._loop_baseline_tokens = max(0, baseline)
|
|
116
|
-
self.
|
|
117
|
-
self.
|
|
113
|
+
self._loop_goal_run_tokens = 0
|
|
114
|
+
self._loop_turn_committed = False
|
|
118
115
|
self._refresh_token_displays(approximate=approximate)
|
|
119
116
|
|
|
120
117
|
def _ensure_loop_token_scope(self, loop_id: str | None) -> None:
|
|
@@ -134,10 +131,10 @@ class _UIMixin:
|
|
|
134
131
|
self._reset_loop_token_usage(loop_id, baseline=baseline, approximate=approximate)
|
|
135
132
|
|
|
136
133
|
def _begin_loop_turn_tokens(self) -> None:
|
|
137
|
-
"""Reset per-
|
|
134
|
+
"""Reset per-goal counters; baseline from prior goals is retained."""
|
|
138
135
|
self._ensure_loop_token_scope(self._lc_loop_id)
|
|
139
|
-
self.
|
|
140
|
-
self.
|
|
136
|
+
self._loop_goal_run_tokens = 0
|
|
137
|
+
self._loop_turn_committed = False
|
|
141
138
|
|
|
142
139
|
def _record_loop_turn_tokens(
|
|
143
140
|
self,
|
|
@@ -146,16 +143,15 @@ class _UIMixin:
|
|
|
146
143
|
*,
|
|
147
144
|
approximate: bool = False,
|
|
148
145
|
) -> None:
|
|
149
|
-
"""Fold one
|
|
146
|
+
"""Fold one goal's usage into the loop baseline and refresh the bar."""
|
|
150
147
|
self._ensure_loop_token_scope(self._lc_loop_id)
|
|
151
148
|
stream_total = max(0, input_tokens) + max(0, output_tokens)
|
|
152
|
-
|
|
153
|
-
turn_total = max(stream_total, goal_total)
|
|
149
|
+
turn_total = max(stream_total, self._loop_goal_run_tokens)
|
|
154
150
|
if turn_total <= 0:
|
|
155
151
|
return
|
|
156
152
|
self._loop_baseline_tokens += turn_total
|
|
157
|
-
self.
|
|
158
|
-
self.
|
|
153
|
+
self._loop_goal_run_tokens = 0
|
|
154
|
+
self._loop_turn_committed = True
|
|
159
155
|
if approximate:
|
|
160
156
|
self._tokens_approximate = True
|
|
161
157
|
self._refresh_token_displays()
|
|
@@ -170,34 +166,26 @@ class _UIMixin:
|
|
|
170
166
|
*,
|
|
171
167
|
source: str = "backend",
|
|
172
168
|
) -> None:
|
|
173
|
-
"""Merge backend goal
|
|
169
|
+
"""Merge a backend per-goal cumulative total into the live counter."""
|
|
174
170
|
from soothe_cli.runtime.token_usage import coerce_total_tokens_used
|
|
175
171
|
|
|
176
172
|
goal_total = coerce_total_tokens_used(goal_run_tokens)
|
|
177
173
|
self._ensure_loop_token_scope(self._lc_loop_id)
|
|
178
|
-
previous_goal = self.
|
|
179
|
-
applied = goal_total
|
|
180
|
-
if applied
|
|
181
|
-
self.
|
|
182
|
-
|
|
183
|
-
self._refresh_token_displays()
|
|
184
|
-
else:
|
|
185
|
-
self._refresh_token_displays()
|
|
174
|
+
previous_goal = self._loop_goal_run_tokens
|
|
175
|
+
applied = goal_total > previous_goal
|
|
176
|
+
if applied:
|
|
177
|
+
self._loop_goal_run_tokens = goal_total
|
|
178
|
+
self._refresh_token_displays()
|
|
186
179
|
trace = self._token_event_trace()
|
|
187
180
|
if trace is not None:
|
|
188
181
|
trace.note_authoritative_merge(
|
|
189
182
|
source=source,
|
|
190
183
|
goal_run_total=goal_total,
|
|
191
184
|
previous_goal_run=previous_goal,
|
|
192
|
-
applied=applied
|
|
185
|
+
applied=applied,
|
|
193
186
|
display_total=self._display_token_total(),
|
|
194
187
|
)
|
|
195
188
|
|
|
196
|
-
def _hide_tokens(self) -> None:
|
|
197
|
-
"""Hide the status-bar token display while the thinking row is active."""
|
|
198
|
-
if self._status_bar:
|
|
199
|
-
self._status_bar.hide_tokens()
|
|
200
|
-
|
|
201
189
|
def _check_hydration_needed(self) -> None:
|
|
202
190
|
"""Check if we need to hydrate messages from the store.
|
|
203
191
|
|