chore: cleanup sprint — dead CSS, dedup helpers, handler refactor
CI / Lint + build + test (push) Successful in 1m34s
Release / detect (push) Successful in 4s
Release / build-live-image (push) Has been skipped
Release / bundle (push) Successful in 1m5s

Remove ~126 lines of orphaned CSS from tile slim-down and old detail
layout. Consolidate 4 duplicate duration formatters into shared
elapsed()/fmtElapsed() helpers. Break 160-line Result handler into
focused sub-functions. Implement real Hub.Shutdown() (was a no-op).
Standardize agent error responses to JSON. Replace panic() in router
init with error return. Extract magic numbers as named constants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 20:39:38 -04:00
parent c11573eeeb
commit 17ec55cb85
17 changed files with 242 additions and 438 deletions
+33 -9
View File
@@ -22,6 +22,11 @@ type subscriber struct {
ch chan Event
}
const (
defaultSubscriberBuffer = 32
heartbeatInterval = 15 * time.Second
)
// Hub is an in-process fan-out for SSE subscribers.
type Hub struct {
mu sync.RWMutex
@@ -29,13 +34,16 @@ type Hub struct {
subs map[int64]*subscriber
buffer int
heartbeat time.Duration
done chan struct{}
closeOnce sync.Once
}
func NewHub() *Hub {
h := &Hub{
subs: map[int64]*subscriber{},
buffer: 32,
heartbeat: 15 * time.Second,
buffer: defaultSubscriberBuffer,
heartbeat: heartbeatInterval,
done: make(chan struct{}),
}
go h.heartbeatLoop()
return h
@@ -70,11 +78,16 @@ func (h *Hub) Subscribe() (id int64, ch <-chan Event, cancel func()) {
func (h *Hub) heartbeatLoop() {
t := time.NewTicker(h.heartbeat)
defer t.Stop()
for range t.C {
h.Publish(Event{
Name: "heartbeat",
Payload: fmt.Sprintf(`<span data-heartbeat="%d"></span>`, time.Now().Unix()),
})
for {
select {
case <-h.done:
return
case <-t.C:
h.Publish(Event{
Name: "heartbeat",
Payload: fmt.Sprintf(`<span data-heartbeat="%d"></span>`, time.Now().Unix()),
})
}
}
}
@@ -140,5 +153,16 @@ func splitLines(s string) []string {
return out
}
// Shutdown is a no-op placeholder wired into graceful shutdown.
func (h *Hub) Shutdown(_ context.Context) error { return nil }
// Shutdown stops the heartbeat goroutine and closes all subscriber channels.
func (h *Hub) Shutdown(_ context.Context) error {
h.closeOnce.Do(func() {
close(h.done)
h.mu.Lock()
for id, s := range h.subs {
close(s.ch)
delete(h.subs, id)
}
h.mu.Unlock()
})
return nil
}