Report each macOS app's build commit in /api/admin/status

This commit is contained in:
Ian Gulliver
2026-10-17 15:32:35 -07:00
parent 702ce49ff1
commit 24b04966dc
9 changed files with 306 additions and 241 deletions
+28 -5
View File
@@ -1,6 +1,7 @@
package server
import (
"sort"
"sync"
"g.fc.run/misc/byre/internal/api"
@@ -8,25 +9,26 @@ import (
type hub struct {
mu sync.Mutex
subs map[chan api.Event]bool
subs map[chan api.Event]api.ConnectedClient
}
func newHub() *hub {
return &hub{subs: map[chan api.Event]bool{}}
return &hub{subs: map[chan api.Event]api.ConnectedClient{}}
}
func (h *hub) subscribe() chan api.Event {
func (h *hub) subscribe(client api.ConnectedClient) chan api.Event {
h.mu.Lock()
defer h.mu.Unlock()
ch := make(chan api.Event, 256)
h.subs[ch] = true
h.subs[ch] = client
return ch
}
func (h *hub) unsubscribe(ch chan api.Event) {
h.mu.Lock()
defer h.mu.Unlock()
if !h.subs[ch] {
_, ok := h.subs[ch]
if !ok {
return
}
delete(h.subs, ch)
@@ -51,3 +53,24 @@ func (h *hub) count() int {
defer h.mu.Unlock()
return len(h.subs)
}
func (h *hub) clients() []api.ConnectedClient {
h.mu.Lock()
defer h.mu.Unlock()
type key struct{ login, host, commit string }
oldest := map[key]api.ConnectedClient{}
for _, c := range h.subs {
k := key{c.Login, c.Host, c.Commit}
prev, ok := oldest[k]
if ok && !c.ConnectedAt.Before(prev.ConnectedAt) {
continue
}
oldest[k] = c
}
out := []api.ConnectedClient{}
for _, c := range oldest {
out = append(out, c)
}
sort.Slice(out, func(i, j int) bool { return out[i].ConnectedAt.Before(out[j].ConnectedAt) })
return out
}
+1
View File
@@ -599,6 +599,7 @@ func (s *Server) status(ctx context.Context) (api.Status, error) {
Projects: c.Projects,
ActiveTasks: c.ActiveTasks,
SseClients: s.hub.count(),
Clients: s.hub.clients(),
LiveAgents: s.agents.LiveCount(),
RunningTurns: usage.Running,
RateLimits: usage.RateLimits,
+6 -1
View File
@@ -55,7 +55,12 @@ func (s *Server) StreamEvents(w http.ResponseWriter, r *http.Request, params api
w.Header().Set("Cache-Control", "no-cache")
w.WriteHeader(http.StatusOK)
live := s.hub.subscribe()
live := s.hub.subscribe(api.ConnectedClient{
Login: viewer,
Host: r.Header.Get("Byre-Host"),
Commit: r.Header.Get("Byre-Commit"),
ConnectedAt: time.Now(),
})
defer s.hub.unsubscribe(live)
for {