Files
archie/internal/webui/api_curators.go
T
sam 8120dc0760 feat(curator): track and expose recent activity per curator
Add a small bounded activity tracker (activityTracker, in
internal/domain/curator/activity.go) fed directly from the runtime's
existing emitRun point: last-run time, last-run action count, and up to
20 recent actions per curator, newest first. No persistence layer -- it
resets on restart, same as the rest of the runtime's in-memory state.
Registry.RecordActivity/Activity expose it.

Closes archie-core-1786637489932-6-1f803e02.
2026-08-28 22:28:48 +10:00

82 lines
2.6 KiB
Go

package webui
import (
"net/http"
"time"
)
// CuratorActionView is one recorded curator action, as shown on the
// dashboard's curator activity view: what changed and why.
type CuratorActionView struct {
At time.Time `json:"at"`
Type string `json:"type"`
Detail string `json:"detail"`
Reason string `json:"reason"`
}
// CuratorView is one registered curator's observable state: identity,
// health, and recent activity. Backed by curator.Registry -- see
// handleCurators.
type CuratorView struct {
Name string `json:"name"`
Health CuratorHealthView `json:"health"`
// LastRunAt is a pointer so a curator that has never run omits the
// field entirely instead of serializing time.Time's zero value
// ("0001-01-01T00:00:00Z") -- json's "omitempty" does not treat a
// zero-valued struct as empty, and a non-empty string is truthy to
// the dashboard's "has this run yet" check.
LastRunAt *time.Time `json:"last_run_at,omitempty"`
LastRunActions int `json:"last_run_actions"`
RecentActions []CuratorActionView `json:"recent_actions"`
}
// CuratorHealthView mirrors curator.Health for the wire.
type CuratorHealthView struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
}
// handleCurators reports which curators are registered, their point-in-time
// health, and their recent activity -- which curators exist, when each last
// ran, what it changed, and why (archie-core-1786637489932-6). The registry
// is the sole source of truth; this handler is transport only.
func (s *Server) handleCurators(w http.ResponseWriter, r *http.Request) {
if s.Curators == nil {
writeJSON(w, map[string]any{"curators": []CuratorView{}})
return
}
names := s.Curators.Names()
health := s.Curators.Health(r.Context())
views := make([]CuratorView, 0, len(names))
for _, name := range names {
h := health[name]
view := CuratorView{
Name: name,
Health: CuratorHealthView{
Status: string(h.Status),
Message: h.Message,
},
RecentActions: []CuratorActionView{},
}
if activity, ok := s.Curators.Activity(name); ok && !activity.LastRunAt.IsZero() {
at := activity.LastRunAt
view.LastRunAt = &at
view.LastRunActions = activity.LastRunActions
view.RecentActions = make([]CuratorActionView, 0, len(activity.Recent))
for _, a := range activity.Recent {
view.RecentActions = append(view.RecentActions, CuratorActionView{
At: a.At,
Type: a.Type,
Detail: a.Detail,
Reason: a.Reason,
})
}
}
views = append(views, view)
}
writeJSON(w, map[string]any{"curators": views})
}