From e2fe67991de182e42c544eef7dc07f27b2de430c Mon Sep 17 00:00:00 2001 From: MaxNad Date: Sun, 17 May 2026 08:44:44 -0400 Subject: [PATCH] Add support for flag filtering in admin commands Signed-off-by: MaxNad --- cmd/askgod/cmd_admin_history.go | 8 +++++++- cmd/askgod/cmd_admin_monitor.go | 6 ++++++ cmd/askgod/main.go | 12 +++++++++++- cmd/askgod/utils.go | 22 ++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/cmd/askgod/cmd_admin_history.go b/cmd/askgod/cmd_admin_history.go index 97658be..98107ce 100644 --- a/cmd/askgod/cmd_admin_history.go +++ b/cmd/askgod/cmd_admin_history.go @@ -14,7 +14,9 @@ import ( "github.com/nsec/askgod/internal/utils" ) -func (c *client) cmdAdminHistory(ctx context.Context, _ *cli.Command) error { +func (c *client) cmdAdminHistory(ctx context.Context, cmd *cli.Command) error { + flagIDs := cmd.Int64Slice("flags") + // Get the scores scores := []api.AdminScore{} @@ -51,6 +53,10 @@ func (c *client) cmdAdminHistory(ctx context.Context, _ *cli.Command) error { table.SetAutoWrapText(false) for _, entry := range scores { + if !matchesFlagIDs(entry.FlagID, flagIDs) { + continue + } + // Get the team team := api.AdminTeam{} diff --git a/cmd/askgod/cmd_admin_monitor.go b/cmd/askgod/cmd_admin_monitor.go index 9c99553..0c81fe3 100644 --- a/cmd/askgod/cmd_admin_monitor.go +++ b/cmd/askgod/cmd_admin_monitor.go @@ -81,6 +81,8 @@ func (c *client) cmdAdminMonitorLog(_ context.Context, cmd *cli.Command) error { } func (c *client) cmdAdminMonitorFlags(_ context.Context, cmd *cli.Command) error { + flagIDs := cmd.Int64Slice("flags") + humanOnly := cmd.Bool("human") // Connection handler @@ -115,6 +117,10 @@ func (c *client) cmdAdminMonitorFlags(_ context.Context, cmd *cli.Command) error continue } + if !flagMatchesIDs(score.Flag, flagIDs) { + continue + } + if humanOnly && (strings.Contains(score.Source, "agent") || strings.Contains(score.Source, "mcp")) { continue } diff --git a/cmd/askgod/main.go b/cmd/askgod/main.go index 8e94cee..0661d6d 100644 --- a/cmd/askgod/main.go +++ b/cmd/askgod/main.go @@ -58,6 +58,10 @@ func main() { Usage: "Show a live stream of submitted flags", Category: "server", Flags: []cli.Flag{ + &cli.Int64SliceFlag{ + Name: "flags", + Usage: "Only show entries for flags with the given IDs", + }, &cli.BoolFlag{ Name: "human", Usage: "Only show submissions from human sources (excludes agent/mcp)", @@ -195,7 +199,13 @@ func main() { Name: "history", Usage: "List the global flag history", Category: "scores", - Action: c.cmdAdminHistory, + Flags: []cli.Flag{ + &cli.Int64SliceFlag{ + Name: "flags", + Usage: "Only show entries for flags with the given IDs", + }, + }, + Action: c.cmdAdminHistory, }, { Name: "stats", diff --git a/cmd/askgod/utils.go b/cmd/askgod/utils.go index 78c4238..5586963 100644 --- a/cmd/askgod/utils.go +++ b/cmd/askgod/utils.go @@ -3,12 +3,34 @@ package main import ( "fmt" "reflect" + "slices" "strconv" "strings" + "github.com/nsec/askgod/api" "github.com/nsec/askgod/internal/utils" ) +func matchesFlagIDs(flagID int64, flagIDs []int64) bool { + if len(flagIDs) == 0 { + return true + } + + return slices.Contains(flagIDs, flagID) +} + +func flagMatchesIDs(flag *api.AdminFlag, flagIDs []int64) bool { + if len(flagIDs) == 0 { + return true + } + + if flag == nil { + return false + } + + return matchesFlagIDs(flag.ID, flagIDs) +} + func getStructField(base reflect.Value, key string) (reflect.Value, error) { field := base