The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(scan): name skipped rules when every rule needs a newer spec
Clauded7b6046f8b3d
diff --git a/cli/beacon/cmd/scan.go b/cli/beacon/cmd/scan.goindex 3e2fc739..a1a9c878 100644--- a/cli/beacon/cmd/scan.go+++ b/cli/beacon/cmd/scan.go@@ -80,10 +80,11 @@ func runScan(cmd *cobra.Command, args []string) error {if err != nil {return fmt.Errorf("load rules: %w", err)}- detect.WarnSkipped(cmd.ErrOrStderr(), skipped)if len(loaded) == 0 {- return fmt.Errorf("no rules to run (store is empty and baseline missing)")+ // The error names any skipped rules itself, so they are not also warned about.+ return &detect.NoRulesError{Skipped: skipped}}+ detect.WarnSkipped(cmd.ErrOrStderr(), skipped)compiled := make([]*threatrules.CompiledRule, 0, len(loaded))for _, lr := range loaded {c, err := threatrules.Compile(lr.Rule)diff --git a/cli/beacon/cmd/scan_test.go b/cli/beacon/cmd/scan_test.goindex 983f8fe1..3558d92b 100644--- a/cli/beacon/cmd/scan_test.go+++ b/cli/beacon/cmd/scan_test.go@@ -202,3 +202,44 @@ func TestScanSkipsNewerSpecRuleWithWarning(t *testing.T) {t.Fatalf("want the skip warning on stderr, got %q", stderr.String())}}++func TestScanAllRulesSkippedNamesThem(t *testing.T) {+ scanFixture(t, []string{evSecretRead})+ // Replace the fixture's only rule with one that needs a newer spec.+ future := strings.Replace(scanTestRule, "id: scan-test-secret-read\n", "id: scan-future-rule\nspec: threat-rules/v1.2\n", 1)+ if err := os.WriteFile(filepath.Join(scanOpts.rulesDir, "secret.rule.yaml"), []byte(future), 0o644); err != nil {+ t.Fatal(err)+ }+ stdout, stderr := &strings.Builder{}, &strings.Builder{}+ cmd, _ := newCmd()+ cmd.SetOut(stdout)+ cmd.SetErr(stderr)+ err := runScan(cmd, nil)+ if err == nil {+ t.Fatal("want an error when every rule is skipped")+ }+ msg := err.Error()+ if strings.Contains(msg, "store is empty") {+ t.Fatalf("error must not claim the store is empty: %s", msg)+ }+ for _, want := range []string{`rule "scan-future-rule" requires threat-rules/v1.2`, "secret.rule.yaml", "supports up to " + threatrules.SupportedSpec, "upgrade Beacon"} {+ if !strings.Contains(msg, want) {+ t.Errorf("error %q missing %q", msg, want)+ }+ }+ if stderr.Len() != 0 {+ t.Errorf("the error names the skipped rules; no separate warning expected, got %q", stderr.String())+ }+}++func TestScanEmptyRulesDirKeepsMessage(t *testing.T) {+ scanFixture(t, []string{evSecretRead})+ if err := os.Remove(filepath.Join(scanOpts.rulesDir, "secret.rule.yaml")); err != nil {+ t.Fatal(err)+ }+ cmd, _ := newCmd()+ err := runScan(cmd, nil)+ if err == nil || err.Error() != "no rules to run (store is empty and baseline missing)" {+ t.Fatalf("want the unchanged empty-store message, got %v", err)+ }+}diff --git a/cli/beacon/internal/endpoint/dashboard/detections.go b/cli/beacon/internal/endpoint/dashboard/detections.goindex 55e153dd..668aedff 100644--- a/cli/beacon/internal/endpoint/dashboard/detections.go+++ b/cli/beacon/internal/endpoint/dashboard/detections.go@@ -63,11 +63,7 @@ func BuildDetections(userMode bool, rulesDir string) (DetectionsResponse, error)Taxonomy: r.Taxonomy,})}- resp := DetectionsResponse{Rules: rules, Count: len(rules)}- for _, sk := range skipped {- resp.Skipped = append(resp.Skipped, sk.String())- }- return resp, nil+ return DetectionsResponse{Rules: rules, Count: len(rules), Skipped: detect.SkippedStrings(skipped)}, nil}// FindingsResponse is the /api/findings payload: the hits from running the@@ -76,6 +72,8 @@ type FindingsResponse struct {Findings []threatrules.Finding `json:"findings"`Scanned int `json:"scanned"`Count int `json:"count"`+ // Skipped lists rule files left out because they need a newer Beacon.+ Skipped []string `json:"skipped,omitempty"`}// RunScan loads and compiles the active rules, streams the runtime log (optionally@@ -95,13 +93,12 @@ func RunScan(userMode bool, logPath, rulesDir, session, minSeverity string) (Fin}}- // Rules needing a newer Beacon are left out here and listed by BuildDetections.- loaded, _, err := detect.LoadActiveSkipping(userMode, strings.TrimSpace(rulesDir))+ loaded, skipped, err := detect.LoadActiveSkipping(userMode, strings.TrimSpace(rulesDir))if err != nil {return FindingsResponse{}, fmt.Errorf("load rules: %w", err)}if len(loaded) == 0 {- return FindingsResponse{}, fmt.Errorf("no rules to run (store is empty and baseline missing)")+ return FindingsResponse{}, &detect.NoRulesError{Skipped: skipped}}compiled := make([]*threatrules.CompiledRule, 0, len(loaded))for _, lr := range loaded {@@ -142,5 +139,5 @@ func RunScan(userMode bool, logPath, rulesDir, session, minSeverity string) (Finif findings == nil {findings = []threatrules.Finding{}}- return FindingsResponse{Findings: findings, Scanned: len(events), Count: len(findings)}, nil+ return FindingsResponse{Findings: findings, Scanned: len(events), Count: len(findings), Skipped: detect.SkippedStrings(skipped)}, nil}diff --git a/cli/beacon/internal/endpoint/dashboard/findings_skipped_test.go b/cli/beacon/internal/endpoint/dashboard/findings_skipped_test.gonew file mode 100644index 00000000..9fc91bcb--- /dev/null+++ b/cli/beacon/internal/endpoint/dashboard/findings_skipped_test.go@@ -0,0 +1,128 @@+package dashboard++import (+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/detect"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/threatrules"+)++// storeRule is a minimal valid rule; spec, when set, is written as its spec line.+func storeRule(id, spec string) string {+ specLine := ""+ if spec != "" {+ specLine = "spec: " + spec + "\n"+ }+ return "id: " + id + "\n" + specLine + `version: 1+title: T+severity: high+status: experimental+posture: detect+match: 'e.event.action == "file.read"'+emit:+ reason: read+tests:+ - name: p+ verdict: match+ events:+ - event: { action: file.read }+`+}++// findingsFixture writes the given rules into a fresh user-mode store and a one-event+// runtime log, and returns the /api/findings response.+func findingsFixture(t *testing.T, rules map[string]string) *httptest.ResponseRecorder {+ t.Helper()+ testenv.SetHome(t, t.TempDir())+ store := detect.StoreDir(true)+ if err := os.MkdirAll(store, 0o755); err != nil {+ t.Fatal(err)+ }+ for id, body := range rules {+ if err := os.WriteFile(filepath.Join(store, id+".rule.yaml"), []byte(body), 0o644); err != nil {+ t.Fatal(err)+ }+ }+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")+ line := `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"file.read","category":"file"},"severity":"info","endpoint":{"os":"darwin"},"session":{"id":"s1"},"file":{"path":".env"},"message":"file.read"}`+ if err := os.WriteFile(logPath, []byte(line+"\n"), 0o644); err != nil {+ t.Fatal(err)+ }+ handler, err := Handler(Options{UserMode: true, LogPath: logPath})+ if err != nil {+ t.Fatalf("Handler: %v", err)+ }+ rec := httptest.NewRecorder()+ handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/findings", nil))+ return rec+}++func TestFindingsAllRulesSkippedNamesThem(t *testing.T) {+ rec := findingsFixture(t, map[string]string{+ "future-a": storeRule("future-a", "threat-rules/v1.2"),+ "future-b": storeRule("future-b", "threat-rules/v2"),+ })+ if rec.Code != http.StatusBadRequest {+ t.Fatalf("status = %d, want 400; body %s", rec.Code, rec.Body.String())+ }+ var body struct {+ Error string `json:"error"`+ Skipped []string `json:"skipped"`+ }+ if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {+ t.Fatalf("unmarshal: %v\n%s", err, rec.Body.String())+ }+ if strings.Contains(body.Error, "store is empty") {+ t.Fatalf("error must not claim the store is empty: %s", body.Error)+ }+ for _, want := range []string{+ `rule "future-a" requires threat-rules/v1.2`,+ `rule "future-b" requires threat-rules/v2`,+ "supports up to " + threatrules.SupportedSpec,+ "upgrade Beacon",+ } {+ if !strings.Contains(body.Error, want) {+ t.Errorf("error %q missing %q", body.Error, want)+ }+ }+ if len(body.Skipped) != 2 || !strings.Contains(strings.Join(body.Skipped, "\n"), "future-a.rule.yaml") {+ t.Fatalf("want both rules in skipped, got %v", body.Skipped)+ }+}++func TestFindingsSomeRulesSkippedRunsTheRest(t *testing.T) {+ rec := findingsFixture(t, map[string]string{+ "current-rule": storeRule("current-rule", ""),+ "future-rule": storeRule("future-rule", "threat-rules/v1.2"),+ })+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body %s", rec.Code, rec.Body.String())+ }+ var resp FindingsResponse+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {+ t.Fatal(err)+ }+ if resp.Count != 1 || resp.Findings[0].RuleID != "current-rule" {+ t.Fatalf("want the current rule's finding, got %+v", resp.Findings)+ }+ if len(resp.Skipped) != 1 || !strings.Contains(resp.Skipped[0], `rule "future-rule" requires threat-rules/v1.2`) {+ t.Fatalf("want future-rule in skipped, got %v", resp.Skipped)+ }+}++func TestFindingsNothingSkippedOmitsSkipList(t *testing.T) {+ rec := findingsFixture(t, map[string]string{"current-rule": storeRule("current-rule", "")})+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body %s", rec.Code, rec.Body.String())+ }+ if strings.Contains(rec.Body.String(), `"skipped"`) {+ t.Fatalf("skipped must be omitted when nothing is skipped: %s", rec.Body.String())+ }+}diff --git a/cli/beacon/internal/endpoint/dashboard/server.go b/cli/beacon/internal/endpoint/dashboard/server.goindex 4f764207..a2e8711a 100644--- a/cli/beacon/internal/endpoint/dashboard/server.go+++ b/cli/beacon/internal/endpoint/dashboard/server.go@@ -3,6 +3,7 @@ package dashboardimport ("embed""encoding/json"+ "errors""fmt""io/fs""net"@@ -12,6 +13,7 @@ import ("time""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/auth"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/detect"endpointhooks "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/inventory""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle"@@ -302,6 +304,15 @@ func Handler(opts Options) (http.Handler, error) {}q := r.URL.Query()resp, err := RunScan(rulesUserMode, opts.LogPath, "", q.Get("session"), q.Get("min_severity"))+ var noRules *detect.NoRulesError+ if errors.As(err, &noRules) && len(noRules.Skipped) > 0 {+ // Every rule needs a newer Beacon: keep the error status, and carry the+ // skip list so the UI can say which rules and versions.+ w.Header().Set("Content-Type", "application/json")+ w.WriteHeader(http.StatusBadRequest)+ _ = json.NewEncoder(w).Encode(map[string]any{"error": err.Error(), "skipped": detect.SkippedStrings(noRules.Skipped)})+ return+ }if err != nil {writeError(w, http.StatusBadRequest, err)returndiff --git a/cli/beacon/internal/endpoint/dashboard/server_test.go b/cli/beacon/internal/endpoint/dashboard/server_test.goindex 932e1bd9..29ae808f 100644--- a/cli/beacon/internal/endpoint/dashboard/server_test.go+++ b/cli/beacon/internal/endpoint/dashboard/server_test.go@@ -525,8 +525,8 @@ func TestRunScanRejectsEmptyRuleSet(t *testing.T) {if err == nil {t.Fatal("expected empty rule set to be rejected")}- if !strings.Contains(err.Error(), "no rules to run") {- t.Fatalf("error = %q, want no rules to run", err)+ if err.Error() != "no rules to run (store is empty and baseline missing)" {+ t.Fatalf("error = %q, want the unchanged empty-store message", err)}}diff --git a/cli/beacon/internal/endpoint/detect/detect.go b/cli/beacon/internal/endpoint/detect/detect.goindex e2788f7c..d9ab3428 100644--- a/cli/beacon/internal/endpoint/detect/detect.go+++ b/cli/beacon/internal/endpoint/detect/detect.go@@ -12,6 +12,7 @@ import ("fmt""io""path/filepath"+ "strings"endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config""github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/rulestore"@@ -69,6 +70,37 @@ func InstallFilesSkipping(userMode bool, src string, force bool) ([]Installed, [return rulestore.InstallFilesSkipping(StoreDir(userMode), src, force)}+// NoRulesError reports that no rules are left to run. Skipped holds the rules set aside+// for needing a newer spec; when it is empty, the store is empty and the baseline is+// missing.+type NoRulesError struct {+ Skipped []threatrules.SkippedRule+}++func (e *NoRulesError) Error() string {+ if len(e.Skipped) == 0 {+ return "no rules to run (store is empty and baseline missing)"+ }+ parts := make([]string, len(e.Skipped))+ for i, s := range e.Skipped {+ parts[i] = fmt.Sprintf("rule %q requires %s (%s)", s.Err.RuleID, s.Err.Required, s.Path)+ }+ return fmt.Sprintf("no rules to run: every rule needs a newer Beacon (this one supports up to %s): %s; upgrade Beacon to load them",+ threatrules.SupportedSpec, strings.Join(parts, ", "))+}++// SkippedStrings renders skipped rules as one line each, for JSON payloads.+func SkippedStrings(skipped []threatrules.SkippedRule) []string {+ if len(skipped) == 0 {+ return nil+ }+ out := make([]string, len(skipped))+ for i, s := range skipped {+ out[i] = s.String()+ }+ return out+}+// WarnSkipped writes one warning line per skipped rule. Commands send it to stderr so// JSON on stdout stays parseable.func WarnSkipped(w io.Writer, skipped []threatrules.SkippedRule) {