feat(ui,judgement,system): unify nav, surface built-in guards, readiness and decision reasoning

This commit is contained in:
sam committed 2026-11-27 02:13:28 +11:00
1 parent 5dc2d79fdb
commit 2ea0062bef
34 files changed
+548 -103

No files matched your search

+18 -1
View File
@@ -84,8 +84,25 @@ func (m *Module) list(contract string) func(context.Context, *struct{}) (*httpap
}
}
// GuardInstallations lists every guard installation the caller can see,
// running, disabled, or failed.
func (m *Module) GuardInstallations(ctx context.Context) ([]ExtensionView, error) {
if m.store == nil {
return nil, nil
}
return m.viewsFor(ctx, func(a store.Installed) bool { return a.Contract == store.ContractGuard })
}
// listViews returns the installations the caller can see that keep accepts.
func (m *Module) listViews(ctx context.Context, keep func(store.Installed) bool) (*httpapi.Reply[[]ExtensionView], error) {
views, err := m.viewsFor(ctx, keep)
if err != nil {
return nil, err
}
return httpapi.OK(views), nil
}
func (m *Module) viewsFor(ctx context.Context, keep func(store.Installed) bool) ([]ExtensionView, error) {
auth, err := authorityOf(ctx)
if err != nil {
return nil, err
@@ -116,7 +133,7 @@ func (m *Module) listViews(ctx context.Context, keep func(store.Installed) bool)
}
views = append(views, view)
}
return httpapi.OK(views), nil
return views, nil
}
// viewOf shows an installation. A caller who may not change it sees what it is
+9
View File
@@ -436,6 +436,15 @@ func (m *Module) Work(ctx context.Context) {
}
}
// SourceCount reports how many event sources exist for the organisation.
func (m *Module) SourceCount(ctx context.Context) (int, error) {
sources, err := m.store.Sources(ctx, m.orgID)
if err != nil {
return 0, err
}
return len(sources), nil
}
// startListeners starts one listener for each source whose connector listens
// and has none yet. A listener lives until ctx ends.
func (m *Module) startListeners(ctx context.Context, wg *sync.WaitGroup, listening map[uuid.UUID]bool) {
+96 -17
View File
@@ -17,19 +17,30 @@ import (
// guard's last recorded standing.
const judgeScanLimit = 200
// JudgeControl is one running guard as the Controls page shows the judge it
// asks: what it was configured with, and the last standing a model judge
// recorded.
// JudgeControl is one guard as the Controls page shows it: built-in guards and
// every guard extension installation (running, disabled, or failed), with its
// configuration and the last model judgement recorded for it.
type JudgeControl struct {
Name string `json:"name"`
InstallationID string `json:"installation_id,omitempty"`
Package string `json:"package,omitempty"`
Scope string `json:"scope,omitempty"`
BuiltIn bool `json:"built_in,omitempty"`
Version string `json:"version,omitempty"`
Digest string `json:"digest,omitempty"`
Advisory bool `json:"advisory"`
Enabled bool `json:"enabled"`
State string `json:"state,omitempty"`
Error string `json:"error,omitempty"`
Settings map[string]string `json:"settings"`
SettingsSchema []connectors.Setting `json:"settings_schema"`
Latest *JudgeStanding `json:"latest,omitempty"`
}
type guardInstallationLister interface {
GuardInstallations(ctx context.Context) ([]connectors.ExtensionView, error)
}
// JudgeStanding is the last model judgement a guard recorded: what the judge
// answered, whether its eval counts it, and the date that eval is from.
type JudgeStanding struct {
@@ -41,25 +52,93 @@ type JudgeStanding struct {
At time.Time `json:"at"`
}
// Judges returns each running guard with its judge configuration and the last
// model judgement recorded for it.
// Judges returns each built-in guard and every guard extension installation with
// its configuration and the last model judgement recorded for it.
func (m *Module) Judges(ctx context.Context) ([]JudgeControl, error) {
if m.extensions == nil {
return []JudgeControl{}, nil
}
guards := m.extensions.Guards(ctx)
out := make([]JudgeControl, 0, len(guards))
for _, g := range guards {
control := JudgeControl{
Name: g.Name(), Version: g.Version(), Digest: g.Digest(), Advisory: g.Advisory(),
Settings: g.Settings(), SettingsSchema: g.SettingsSchema(),
}
out := make([]JudgeControl, 0, len(m.guards))
for _, g := range m.guards {
latest, err := m.latestJudge(ctx, g.Name())
if err != nil {
return nil, err
}
control.Latest = latest
out = append(out, control)
out = append(out, JudgeControl{
Name: g.Name(),
BuiltIn: true,
Advisory: g.Advisory(),
Enabled: true,
State: "running",
Settings: map[string]string{},
Latest: latest,
})
}
if m.extensions == nil {
return out, nil
}
ext, err := m.extensionJudges(ctx)
if err != nil {
return nil, err
}
return append(out, ext...), nil
}
func (m *Module) extensionJudges(ctx context.Context) ([]JudgeControl, error) {
running := map[string]*connectors.Guard{}
for _, g := range m.extensions.Guards(ctx) {
running[g.Name()] = g
}
if lister, ok := m.extensions.(guardInstallationLister); ok {
views, err := lister.GuardInstallations(ctx)
if err == nil && views != nil {
return m.viewsToJudges(ctx, views, running)
}
}
out := make([]JudgeControl, 0, len(running))
for _, g := range running {
latest, err := m.latestJudge(ctx, g.Name())
if err != nil {
return nil, err
}
out = append(out, JudgeControl{
Name: g.Name(),
Version: g.Version(),
Digest: g.Digest(),
Advisory: g.Advisory(),
Enabled: true,
State: "running",
Settings: g.Settings(),
SettingsSchema: g.SettingsSchema(),
Latest: latest,
})
}
return out, nil
}
func (m *Module) viewsToJudges(ctx context.Context, views []connectors.ExtensionView, running map[string]*connectors.Guard) ([]JudgeControl, error) {
out := make([]JudgeControl, 0, len(views))
for _, v := range views {
advisory := false
if g := running[v.Name]; g != nil {
advisory = g.Advisory()
}
latest, err := m.latestJudge(ctx, v.Name)
if err != nil {
return nil, err
}
out = append(out, JudgeControl{
Name: v.Name,
InstallationID: v.ID.String(),
Package: v.Package,
Scope: v.Scope,
Version: v.Version,
Digest: v.Digest,
Advisory: advisory,
Enabled: v.Enabled,
State: v.State,
Error: v.Error,
Settings: v.Settings,
SettingsSchema: v.SettingsSchema,
Latest: latest,
})
}
return out, nil
}
+16 -2
View File
@@ -33,6 +33,16 @@ type Sources struct {
Waiting func(context.Context) (Waiting, error)
// LastFailedRun is the most recent run that failed; nil when none has.
LastFailedRun func(context.Context) (*runs.RunView, error)
// Setup reports what the instance still needs before workflows and chat can run.
Setup func(context.Context) []SetupStep
}
// SetupStep is one readiness item on the Home dashboard.
type SetupStep struct {
Title string `json:"title"`
Detail string `json:"detail,omitzero"`
Done bool `json:"done"`
Path string `json:"path,omitzero"`
}
// UseHealth sets where the health report reads from.
@@ -80,8 +90,9 @@ type Health struct {
Connectors []connectors.Health `json:"connectors"`
Runner Runner `json:"runner"`
// Waiting is absent when it could not be read; that is a failed check.
Waiting *Waiting `json:"waiting,omitzero"`
LastFailure *Failure `json:"last_failure,omitzero"`
Waiting *Waiting `json:"waiting,omitzero"`
LastFailure *Failure `json:"last_failure,omitzero"`
Setup []SetupStep `json:"setup,omitzero"`
}
func (m *Module) registerHealth(api huma.API) {
@@ -133,6 +144,9 @@ func (m *Module) getHealth(ctx context.Context, _ *struct{}) (*httpapi.Reply[Hea
}
h.Healthy = healthy(h)
h.LastFailure = lastFailure(h, lastRun)
if src.Setup != nil {
h.Setup = src.Setup(ctx)
}
return httpapi.OK(h), nil
}