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

+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
}