feat(monitor): Monitor tab as primary landing + errors KPI + recent executions + date filter

Rebrand "Claude Usage" tab to "Monitor" and promote it to first/default tab in
the main TabBar. Monitor is the landing for the reactive loop (construir →
ejecutar → recopilar → analizar → mejorar).

UI additions:
- Local toolbar inside Monitor with date preset combo (1h / 24h / 7d / 30d /
  All), manual Refresh button, and live LED + last-event-ts indicator.
- 5 KPI cards (was 4): added "Errors" derived from COUNT(*) FROM calls WHERE
  success = 0 filtered by the active window.
- New sub-tab "Recent Executions" (first sub-tab) with columns: When,
  Function, Tool, ms, OK (check/X colored), Error class. Backed by calls
  table, sorted by ts DESC, limit 100, filtered by window.
- Violations sub-tab gains "When" column with formatted ts.

Data layer:
- data.h: RecentExecutionRow + window_secs + ws_connected/last_event_ts /
  last_seen_call_id watermark on ClaudeUsageData.
- data_http.{h,cpp}: load_claude_usage_http now takes window_secs and embeds
  ts_filter() in calls/errors/violations queries. total_errors populated.
  recent_executions populated up to 100 rows. New standalone
  load_recent_executions_http() for future WS-driven partial refetch.
- main.cpp: reload_data preserves window_secs across reloads; new
  reload_monitor() does a Monitor-only refetch when the user changes the
  window or clicks Refresh, without re-querying the full registry.

Wiring:
- views.h: draw_monitor + monitor_consume_reload_request() +
  monitor_set_ws_state() exported. draw_claude_usage removed.
- views.cpp: render() consumes monitor_consume_reload_request each frame
  and dispatches reload_monitor().

This is the UI half of issue 0086. The server-side WebSocket endpoint in
sqlite_api and the C++ WS client are next; the LED is wired to
monitor_set_ws_state but stays gray until those land.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 00:26:29 +02:00
parent 33d50aacdd
commit 87b7ef45ff
6 changed files with 592 additions and 3 deletions
+15
View File
@@ -22,3 +22,18 @@ void draw_projects_list(RegistryData& data);
// Explorer: lista navegable de funciones + visor de codigo y documentacion.
// Carga la lista completa al primer render via /api/databases/registry/query.
void draw_functions_explorer();
// Issue 0086: tab "Monitor" (antes "Claude Usage"). Pestana principal y por
// defecto. Muestra KPIs del bucle reactivo + Recent Executions con timestamps,
// top functions, violations, copied code. Filtro de fecha por presets y
// estado WS live (LED + ts ultimo evento). Si data.claude.available == false
// muestra placeholder con instrucciones para inicializar call_monitor.
void draw_monitor(RegistryData& data);
// Flag global: cuando draw_monitor cambia la ventana o WS reconecta y necesita
// refetch parcial. Lo lee main.cpp y llama load_claude_usage_http sin tocar
// el resto del registry (rapido).
bool monitor_consume_reload_request();
// Setter expuesto a main.cpp: refleja estado WS en el LED. true = live.
void monitor_set_ws_state(bool connected, long long last_event_ts);