feat(gui): add Tool Usage Analytics panel with stats tracking

This commit is contained in:
2026-03-07 10:58:23 -05:00
parent 5075a82fe4
commit 1d87ad3566
2 changed files with 75 additions and 1 deletions

View File

@@ -333,6 +333,8 @@ class App:
self._render_token_budget_panel()
if imgui.collapsing_header("Cache Analytics"):
self._render_cache_panel()
if imgui.collapsing_header("Tool Usage Analytics"):
self._render_tool_analytics_panel()
if imgui.collapsing_header("System Prompts"):
self._render_system_prompts_panel()
@@ -1484,6 +1486,44 @@ class App:
if hasattr(self, '_cache_cleared_timestamp') and time.time() - self._cache_cleared_timestamp < 5:
imgui.text_colored(imgui.ImVec4(0.2, 1.0, 0.2, 1.0), "Cache cleared - will rebuild on next request")
def _render_tool_analytics_panel(self) -> None:
if not imgui.collapsing_header("Tool Usage Analytics"):
return
tool_stats = getattr(self, '_worker_status', {})
if not tool_stats:
tool_stats = {}
if hasattr(self.controller, '_tool_stats'):
tool_stats = self.controller._tool_stats
if not tool_stats:
imgui.text_disabled("No tool usage data")
return
if imgui.begin_table("tool_stats", 4, imgui.TableFlags_.borders | imgui.TableFlags_.sortable):
imgui.table_setup_column("Tool")
imgui.table_setup_column("Count")
imgui.table_setup_column("Avg (ms)")
imgui.table_setup_column("Fail %")
imgui.table_headers_row()
sorted_tools = sorted(tool_stats.items(), key=lambda x: -x[1].get("count", 0))
for tool_name, stats in sorted_tools:
count = stats.get("count", 0)
total_time = stats.get("total_time_ms", 0)
failures = stats.get("failures", 0)
avg_time = total_time / count if count > 0 else 0
fail_pct = (failures / count * 100) if count > 0 else 0
imgui.table_next_row()
imgui.table_set_column_index(0)
imgui.text(tool_name)
imgui.table_set_column_index(1)
imgui.text(str(count))
imgui.table_set_column_index(2)
imgui.text(f"{avg_time:.0f}")
imgui.table_set_column_index(3)
if fail_pct > 0:
imgui.text_colored(imgui.ImVec4(1.0, 0.2, 0.2, 1.0), f"{fail_pct:.0f}%")
else:
imgui.text("0%")
imgui.end_table()
def _render_message_panel(self) -> None:
# LIVE indicator
is_live = self.ai_status in ["running powershell...", "fetching url...", "searching web...", "powershell done, awaiting AI..."]