feat(api): status ring buffer (last 100) + GET /status/recent endpoint

Bus.Publish now also appends each event to a per-topic ring buffer of
size 100. Bus.Recent(topic, n) returns the tail. New endpoint:

  GET /status/recent?n=N    → JSON array of last N status-diff events

This lets a fresh client (agents_dashboard launching cold) populate its
Status Feed panel with historical activity before subscribing to
/sse/status for live updates. Until now, new SSE subscribers only saw
events emitted AFTER they connected — making the panel useless for
recent history review.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-22 23:38:55 +02:00
parent e3b034e784
commit 71b3b2bca9
3 changed files with 57 additions and 9 deletions
+16
View File
@@ -103,6 +103,22 @@ func queryMessages24h(agentID, dataDir string) int {
return count
}
// --- Recent status events ---
// handleStatusRecent returns the last N status-diff events from the bus ring
// buffer (default 100, cap 100). Lets a new client populate its Status Feed
// panel with history before subscribing to /sse/status for live updates.
func (s *Server) handleStatusRecent(w http.ResponseWriter, r *http.Request) {
n := 100
if qn := r.URL.Query().Get("n"); qn != "" {
if parsed, err := strconv.Atoi(qn); err == nil && parsed > 0 {
n = parsed
}
}
events := s.bus.Recent("status", n)
writeJSON(w, http.StatusOK, events)
}
// --- Health ---
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {