hermes-agent/tui_gateway
kshitijk4poor d0964c5150 feat(dashboard): log HTTP access + WebSocket lifecycle to the gui surface
The messaging gateway logs every inbound message to gateway.log, but its
dashboard/TUI twin (gui.log) was nearly silent: the dashboard FastAPI app had
host-header/auth-gate/auth middlewares but no access log, and 3 of 4 WebSocket
endpoints logged nothing at all. Worst of these, /api/pty logged 'pty accepted'
on connect but was completely silent on close — a PTY EOF (backend crash), a
send failure, or a client drop left no trace, so user-reported 'chat
disconnected / TUI froze' was unreproducible.

Extend the convention tui_gateway/ws.py::handle_ws already establishes (a
structured 'ws closed peer=... reason=... <counters>' line) across the whole
surface, at the same INFO granularity as gateway.log, into the gui.log that is
already sized for it (10MB x5):

- HTTP access-log middleware (registered LIFO-outermost so it captures the
  final status, including 400/401 from the middlewares above): one INFO line
  per request with method, path, status, latency, request id, peer. Path only,
  never the query string (tokens ride in query on some routes). UA/referer at
  DEBUG (-v). Reads/echoes X-Request-ID for client/proxy correlation.
- /api/pty: structured close line covering all exit paths
  (client_disconnect | pty_eof | send_failed | error) with duration and
  bytes_in/out counters.
- /api/pub + /api/events: accept + structured close (reason/duration/frames)
  + all reject paths.
- /api/ws: reject paths logged; request id threaded into handle_ws and stamped
  on its accept/close lines so a WS session correlates with the HTTP upgrade.

Metadata only — no request/response bodies, no WS frame payloads, no
headers/cookies on the INFO lines. Opt-in body capture is a separate change so
this stays clear of the debug-share privacy surface.

handle_ws gains an optional rid=None arg, backward-compatible with the stdio
entry-point (tui_gateway.entry) which calls handle_ws(ws).

Tests (behavior-contract style, not frozen strings): HTTP access line shape +
query-string redaction + 401-still-logged + X-Request-ID round-trip; WS
accept/close lines for /api/pub and /api/events; WS reject logging; rid
propagation through handle_ws.
2026-06-19 17:45:17 +05:30
..
__init__.py feat: new tui based on ink 2026-04-02 19:07:53 -05:00
entry.py fix(tui): refresh tool snapshot when MCP discovery lands after agent build (#48403) 2026-06-18 05:41:23 -07:00
event_publisher.py chore: address copilot comments 2026-04-24 12:51:04 -04:00
render.py tui: inherit Python-side rendering via gateway bridge 2026-04-05 18:50:41 -05:00
server.py fix(tui): route pending-input commands via command.dispatch (#48848) 2026-06-19 14:53:33 +05:30
slash_worker.py fix(tui-gateway): reap leaked slash_worker sessions on disconnect + active_list liveness (re-scoped onto current main) 2026-06-08 10:02:05 -07:00
transport.py fix(tui-gateway): harden stdio transport against half-closed pipes + SIGTERM races (#17118) 2026-04-28 17:54:06 -05:00
ws.py feat(dashboard): log HTTP access + WebSocket lifecycle to the gui surface 2026-06-19 17:45:17 +05:30