Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

intel: fail --fail-on closed, add --fail-on partial, never hide counts

Claude002077ce7cba
diff --git a/cli/beacon/cmd/intel.go b/cli/beacon/cmd/intel.go
index 88dbeaca..c0ff1c86 100644
--- a/cli/beacon/cmd/intel.go
+++ b/cli/beacon/cmd/intel.go
@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"os"
+ "slices"
"sort"
"strings"
"text/tabwriter"
@@ -70,7 +71,9 @@ Nothing you send is stored.
Each is matched (with its risk), ambiguous (no artifact has exactly that name: check one of
the candidates by its key), or not_found. --fail-on exits non-zero when any matched artifact
-is at or above a risk, for use in CI.`,
+is at or above a risk, for use in CI; --fail-on partial also fails one whose coverage is
+partial, at any risk. A matched artifact whose risk this beacon does not recognize fails every
+--fail-on.`,
SilenceUsage: true,
RunE: runIntelCheck,
}
@@ -93,7 +96,7 @@ func init() {
intelLookupCmd.Flags().IntVar(&intelOpts.limit, "limit", 10, fmt.Sprintf("Results to show (at most %d)", intelapi.MaxLimit))
intelCheckCmd.Flags().StringVar(&intelOpts.kind, "kind", "", "Read every artifact as mcp or skill")
intelCheckCmd.Flags().StringVar(&intelOpts.file, "file", "", "Read artifacts from a file, one per line (- for standard input)")
- intelCheckCmd.Flags().StringVar(&intelOpts.failOn, "fail-on", "", "Exit non-zero when a matched artifact is at or above this risk: high, medium or low")
+ intelCheckCmd.Flags().StringVar(&intelOpts.failOn, "fail-on", "", "Exit non-zero when a matched artifact is at or above this risk (high, medium or low), or with partial also has partial coverage")
}
// newIntelClient is the test seam for the client.
@@ -252,12 +255,83 @@ func printIntelList(out io.Writer, title string, items []string) {
}
}
-// intelRiskRank orders risks for --fail-on; unchecked and anything unknown rank lowest.
-var intelRiskRank = map[string]int{"benign": 1, "low": 2, "medium": 3, "high": 4}
+// intelRiskRank orders risks for --fail-on. unchecked (listed, never analyzed) ranks lowest.
+var intelRiskRank = map[string]int{"unchecked": 0, "benign": 1, "low": 2, "medium": 3, "high": 4}
// intelRetiredRisks are the verdict values the index used before risk and coverage replaced
-// them, named in --fail-on's error so a CI script that still passes one is told what changed.
-var intelRetiredRisks = map[string]bool{"malicious": true, "suspicious": true, "inconclusive": true}
+// them, with the risk each one became. --fail-on refuses them as thresholds, naming what
+// replaced them, and ranks them as their replacement when an index that has not moved to risk
+// and coverage still answers with one, so a malicious match still trips --fail-on high.
+var intelRetiredRisks = map[string]int{"malicious": 4, "suspicious": 3, "inconclusive": 2}
+
+// intelGate is what --fail-on fails a check on: a matched artifact at or above rank, and with
+// partial, also one whose analysis did not cover everything (what --fail-on inconclusive
+// caught before coverage was its own field).
+type intelGate struct {
+ name string
+ rank int
+ partial bool
+}
+
+func parseIntelFailOn(value string) (*intelGate, error) {
+ switch value {
+ case "":
+ return nil, nil
+ case "high", "medium", "low":
+ return &intelGate{name: value, rank: intelRiskRank[value]}, nil
+ case "partial":
+ return &intelGate{name: value, rank: intelRiskRank["low"], partial: true}, nil
+ }
+ if _, ok := intelRetiredRisks[value]; ok {
+ hint := "use high, medium or low"
+ if value == "inconclusive" {
+ hint = "use partial, which fails on low or above and on partial coverage at any risk, as inconclusive did"
+ }
+ return nil, fmt.Errorf("--fail-on %s is no longer a risk: Beacon Intel now rates risk as high, medium, low or benign, with coverage apart; %s", value, hint)
+ }
+ return nil, fmt.Errorf("--fail-on must be high, medium, low or partial, not %q", termLine(value, 40))
+}
+
+// fails says why a check result fails the gate, or "" when it passes. Only matched results
+// can fail: ambiguous and not_found claim no risk. It fails closed: a matched result whose
+// risk this build does not know fails at every threshold rather than ranking lowest, and with
+// partial, so does one whose coverage is neither complete nor partial.
+func (g *intelGate) fails(r intelapi.CheckOutcome) string {
+ if r.Status != "matched" {
+ return ""
+ }
+ risk := termLine(orDash(r.Risk), 16)
+ rank, known := intelRiskRank[r.Risk]
+ retired := false
+ if !known {
+ rank, retired = intelRetiredRisks[r.Risk]
+ known = retired
+ }
+ switch {
+ case !known:
+ return fmt.Sprintf("%s (risk %s not recognized)", termLine(r.Q, 80), risk)
+ case rank >= g.rank:
+ if r.Coverage == "partial" {
+ return fmt.Sprintf("%s (%s, partial)", termLine(r.Q, 80), risk)
+ }
+ return fmt.Sprintf("%s (%s)", termLine(r.Q, 80), risk)
+ case !g.partial || r.Risk == "unchecked" || retired || r.Coverage == "complete":
+ // unchecked was never analyzed, so it has no coverage, and a retired verdict carried
+ // its coverage in the verdict itself (inconclusive ranks as low above).
+ return ""
+ case r.Coverage == "partial":
+ return fmt.Sprintf("%s (%s, partial)", termLine(r.Q, 80), risk)
+ default:
+ return fmt.Sprintf("%s (%s, coverage %s not recognized)", termLine(r.Q, 80), risk, termLine(orDash(r.Coverage), 16))
+ }
+}
+
+func (g *intelGate) describe() string {
+ if g.partial {
+ return "at or above low or with partial coverage"
+ }
+ return "at or above " + g.name
+}
// intelRisk is a risk as the tables print it, marked when the analysis covered only part of
// the artifact, which is never a clearance.
@@ -273,16 +347,9 @@ func intelRisk(risk, coverage string) string {
var errIntelCheckFailed = errors.New("intel check failed")
func runIntelCheck(cmd *cobra.Command, args []string) error {
- threshold := 0
- if intelOpts.failOn != "" {
- rank, ok := intelRiskRank[intelOpts.failOn]
- if !ok || rank < 2 {
- if intelRetiredRisks[intelOpts.failOn] {
- return fmt.Errorf("--fail-on %s is no longer a risk: Beacon Intel now rates risk as high, medium, low or benign, with coverage apart; use high, medium or low", intelOpts.failOn)
- }
- return fmt.Errorf("--fail-on must be high, medium or low, not %q", termLine(intelOpts.failOn, 40))
- }
- threshold = rank
+ gate, err := parseIntelFailOn(intelOpts.failOn)
+ if err != nil {
+ return err
}
if err := intelapi.ValidateKind(intelOpts.kind); err != nil {
return err
@@ -342,27 +409,42 @@ func runIntelCheck(cmd *cobra.Command, args []string) error {
fmt.Fprintln(out, intelCountsLine(res.Counts))
fmt.Fprintln(out, "not_found means never checked, not safe; partial coverage is never a clearance. Details: beacon intel show <key>")
}
- if threshold > 0 {
+ if gate != nil {
var failed []string
for _, r := range res.Results {
- if r.Status == "matched" && intelRiskRank[r.Risk] >= threshold {
- failed = append(failed, fmt.Sprintf("%s (%s)", termLine(r.Q, 80), r.Risk))
+ if why := gate.fails(r); why != "" {
+ failed = append(failed, why)
}
}
if len(failed) > 0 {
- return fmt.Errorf("%w: %d at or above %s: %s", errIntelCheckFailed, len(failed), intelOpts.failOn, strings.Join(failed, ", "))
+ return fmt.Errorf("%w: %d %s: %s", errIntelCheckFailed, len(failed), gate.describe(), strings.Join(failed, ", "))
}
}
return nil
}
+// intelCountKeys are the check counts in the order the summary line prints them.
+var intelCountKeys = []string{"high", "medium", "low", "benign", "unchecked", "ambiguous", "not_found"}
+
func intelCountsLine(counts map[string]int) string {
parts := []string{}
- for _, key := range []string{"high", "medium", "low", "benign", "unchecked", "ambiguous", "not_found"} {
+ for _, key := range intelCountKeys {
if counts[key] > 0 {
parts = append(parts, fmt.Sprintf("%d %s", counts[key], key))
}
}
+ // Never hide a count the server sent: one this build does not know (a retired verdict
+ // such as malicious, or a value added later) is printed after the known ones.
+ var others []string
+ for key, n := range counts {
+ if n > 0 && key != "partial" && !slices.Contains(intelCountKeys, key) {
+ others = append(others, key)
+ }
+ }
+ sort.Strings(others)
+ for _, key := range others {
+ parts = append(parts, fmt.Sprintf("%d %s", counts[key], termLine(key, 32)))
+ }
if len(parts) == 0 {
return "Nothing checked."
@@ -434,11 +516,43 @@ func runIntelStatus(cmd *cobra.Command, args []string) error {
if err := tw.Flush(); err != nil {
return err
}
+ for _, kind := range []string{"mcp", "skill"} {
+ if line := intelStatusOthers(kind, s.Index[kind]); line != "" {
+ fmt.Fprintln(out, line)
+ }
+ }
fmt.Fprintf(out, "\nNewest verdict: %s\n", termLine(orDash(s.LatestAnalyzedAt), 40))
fmt.Fprintf(out, "Newest registry update: %s\n", termLine(orDash(s.LatestListedAt), 40))
return nil
}
+// intelStatusOthers names analyzed artifacts the table's risk columns do not show: counts
+// under a risk this build does not know (an index still on the retired verdicts answers with
+// malicious, suspicious and inconclusive), and analyzed artifacts no count accounts for.
+// PARTIAL overlaps the risk columns, so it is not part of the sum.
+func intelStatusOthers(kind string, k intelapi.IndexCounts) string {
+ var parts []string
+ keys := make([]string, 0, len(k.Other))
+ for key := range k.Other {
+ keys = append(keys, key)
+ }
+ sort.Strings(keys)
+ shown := k.High + k.Medium + k.Low + k.Benign
+ for _, key := range keys {
+ if n := k.Other[key]; n > 0 {
+ parts = append(parts, fmt.Sprintf("%d %s", n, termLine(key, 32)))
+ shown += n
+ }
+ }
+ if rest := k.Analyzed - shown; rest > 0 {
+ parts = append(parts, fmt.Sprintf("%d with no risk count", rest))
+ }
+ if len(parts) == 0 {
+ return ""
+ }
+ return fmt.Sprintf("%s also: %s (not in the columns above; --json shows the full answer)", kind, strings.Join(parts, ", "))
+}
+
// writeIntelJSON re-indents the API's answer. It was decoded already, so it is valid JSON.
// encoding/json escapes C0 controls but writes C1 controls and bidirectional formatting
// characters as they are, so those are escaped here: the JSON decodes the same, and the
diff --git a/cli/beacon/cmd/intel_test.go b/cli/beacon/cmd/intel_test.go
index cccbda7d..e3b1fa7f 100644
--- a/cli/beacon/cmd/intel_test.go
+++ b/cli/beacon/cmd/intel_test.go
@@ -301,6 +301,19 @@ func TestIntelCheckFailOn(t *testing.T) {
t.Fatalf("ambiguous failed the check: %v", err)
}
before := f.requests()
+ // partial also fails a match with partial coverage, at any risk.
+ f.answer("/api/v1/check", 200, `{"api":"intel.v1","results":[
+{"q":"pdf","status":"matched","risk":"benign","coverage":"partial"},
+{"q":"ok","status":"matched","risk":"benign","coverage":"complete"},
+{"q":"new","status":"matched","risk":"unchecked"}],"counts":{"benign":2,"unchecked":1,"partial":1}}`)
+ if _, err := runIntel(t, "", "check", "a", "--fail-on", "low"); err != nil {
+ t.Fatalf("--fail-on low failed on benign: %v", err)
+ }
+ _, err = runIntel(t, "", "check", "a", "--fail-on", "partial")
+ if !errors.Is(err, errIntelCheckFailed) || !strings.Contains(err.Error(), "1 at or above low or with partial coverage: pdf (benign, partial)") {
+ t.Fatalf("--fail-on partial: %v", err)
+ }
+ before = f.requests()
for _, bad := range []string{"benign", "unchecked", "critical", "malicious", "suspicious", "inconclusive"} {
if _, err := runIntel(t, "", "check", "a", "--fail-on", bad); err == nil {
t.Errorf("--fail-on %s accepted", bad)
@@ -314,6 +327,47 @@ func TestIntelCheckFailOn(t *testing.T) {
!strings.Contains(err.Error(), "use high, medium or low") {
t.Fatalf("retired value: %v", err)
}
+ if _, err := runIntel(t, "", "check", "a", "--fail-on", "inconclusive"); err == nil || !strings.Contains(err.Error(), "use partial") {
+ t.Fatalf("retired inconclusive: %v", err)
+ }
+}
+
+// An index still answering with the retired verdicts, or with a risk this build does not
+// know, must not pass a gate silently.
+func TestIntelCheckFailOnFailsClosed(t *testing.T) {
+ f := startFakeIntel(t)
+ f.answer("/api/v1/check", 200, `{"api":"intel.v1","results":[
+{"q":"old-evil","status":"matched","risk":"malicious"},
+{"q":"old-maybe","status":"matched","risk":"inconclusive"},
+{"q":"old-ok","status":"matched","risk":"benign"}],"counts":{"malicious":1,"inconclusive":1,"benign":1}}`)
+ out, err := runIntel(t, "", "check", "a", "--fail-on", "high")
+ if !errors.Is(err, errIntelCheckFailed) || !strings.Contains(err.Error(), "1 at or above high: old-evil (malicious)") {
+ t.Fatalf("retired malicious under --fail-on high: %v", err)
+ }
+ if !strings.Contains(out, "1 benign, 1 inconclusive, 1 malicious.") {
+ t.Errorf("counts line hid a retired count:\n%s", out)
+ }
+ _, err = runIntel(t, "", "check", "a", "--fail-on", "partial")
+ if !errors.Is(err, errIntelCheckFailed) || !strings.Contains(err.Error(), "3 at or above low or with partial coverage") ||
+ !strings.Contains(err.Error(), "old-ok (benign, coverage - not recognized)") {
+ // benign with no coverage cannot be told from a new answer missing its coverage, so
+ // --fail-on partial fails it rather than read it as complete.
+ t.Fatalf("retired values under --fail-on partial: %v", err)
+ }
+
+ f.answer("/api/v1/check", 200, `{"api":"intel.v1","results":[
+{"q":"odd","status":"matched","risk":"critical","coverage":"complete"},
+{"q":"blank","status":"matched","risk":null},
+{"q":"odd-coverage","status":"matched","risk":"benign","coverage":"sampled"}],"counts":{"critical":1}}`)
+ _, err = runIntel(t, "", "check", "a", "--fail-on", "high")
+ if !errors.Is(err, errIntelCheckFailed) || !strings.Contains(err.Error(), "odd (risk critical not recognized)") ||
+ !strings.Contains(err.Error(), "blank (risk - not recognized)") || strings.Contains(err.Error(), "odd-coverage") {
+ t.Fatalf("unknown risk under --fail-on high: %v", err)
+ }
+ _, err = runIntel(t, "", "check", "a", "--fail-on", "partial")
+ if !errors.Is(err, errIntelCheckFailed) || !strings.Contains(err.Error(), "odd-coverage (benign, coverage sampled not recognized)") {
+ t.Fatalf("unknown coverage under --fail-on partial: %v", err)
+ }
}
func TestIntelCheckRefusesBadInputWithoutARequest(t *testing.T) {
diff --git a/docs/cli/intel.mdx b/docs/cli/intel.mdx
index c81ddd65..dc92703f 100644
--- a/docs/cli/intel.mdx
+++ b/docs/cli/intel.mdx
@@ -106,15 +106,28 @@ The summary line counts matched artifacts by risk, then ambiguous and not-found
how many of the matched ones had partial coverage.
`--fail-on high|medium|low` exits with status 1 when any matched artifact is at or above that
-risk, which makes `check` a CI gate. Ambiguous and not-found artifacts never fail it, because
-they claim no risk. The retired values `malicious`, `suspicious` and `inconclusive` are
-refused with a message naming the new ones, so update CI scripts that pass them: `--fail-on
-medium` is the usual replacement for `--fail-on suspicious`.
+risk, which makes `check` a CI gate. `--fail-on partial` is the strictest gate: it fails on
+`low` or above and on any artifact whose coverage is partial, at any risk, because partial
+coverage is never a clearance. Ambiguous and not-found artifacts never fail it, because
+they claim no risk. The gate fails closed: a matched artifact whose risk this `beacon` does not
+recognize fails every `--fail-on`, and under `--fail-on partial` so does one whose coverage is
+neither `complete` nor `partial`. An index that still answers with a retired verdict is ranked
+as its replacement (`malicious` as `high`, `suspicious` as `medium`, `inconclusive` as `low`).
+
+The retired values `malicious`, `suspicious` and `inconclusive` are refused as `--fail-on`
+thresholds with a message naming the new ones, so update CI scripts that pass them: `--fail-on
+medium` replaces `--fail-on suspicious`, `--fail-on high` replaces `--fail-on malicious`, and
+`--fail-on partial` replaces `--fail-on inconclusive`.
+
+The summary line never hides a count the index sent: one this `beacon` does not know is
+printed after the known ones.
## Status
`beacon intel status` shows how many MCP servers and skills the index lists and has analyzed,
-how many it rates at each risk, and how many have partial coverage.
+how many it rates at each risk, and how many have partial coverage. When an index sends counts
+the columns do not show (an index still on the retired verdicts, for example), or analyzed
+artifacts no count accounts for, a line below the table names them.
It also shows when the newest verdict and registry update arrived. The index is refreshed
hourly.
diff --git a/pkg/asymptoteobserve/intelapi/client.go b/pkg/asymptoteobserve/intelapi/client.go
index be0a765c..cfa81337 100644
--- a/pkg/asymptoteobserve/intelapi/client.go
+++ b/pkg/asymptoteobserve/intelapi/client.go
@@ -231,18 +231,52 @@ type CheckResult struct {
// Status is GET /api/v1/status.
type Status struct {
- Index map[string]struct {
- Artifacts int `json:"artifacts"`
- Analyzed int `json:"analyzed"`
- High int `json:"high"`
- Medium int `json:"medium"`
- Low int `json:"low"`
- Benign int `json:"benign"`
- // Analyzed with partial coverage, at any risk.
- Partial int `json:"partial"`
- } `json:"index"`
- LatestAnalyzedAt string `json:"latest_analyzed_at"`
- LatestListedAt string `json:"latest_listed_at"`
+ Index map[string]IndexCounts `json:"index"`
+ LatestAnalyzedAt string `json:"latest_analyzed_at"`
+ LatestListedAt string `json:"latest_listed_at"`
+}
+
+// IndexCounts is one kind's counts in Status. Other keeps every other numeric count the index
+// sent, such as the retired malicious, suspicious and inconclusive of an index not yet on risk
+// and coverage, so a reader can show what the fixed fields would otherwise drop.
+type IndexCounts struct {
+ Artifacts int `json:"artifacts"`
+ Analyzed int `json:"analyzed"`
+ High int `json:"high"`
+ Medium int `json:"medium"`
+ Low int `json:"low"`
+ Benign int `json:"benign"`
+ // Analyzed with partial coverage, at any risk.
+ Partial int `json:"partial"`
+ Other map[string]int `json:"other,omitempty"`
+}
+
+var indexCountsKnown = map[string]bool{"artifacts": true, "analyzed": true, "high": true, "medium": true, "low": true, "benign": true, "partial": true}
+
+// UnmarshalJSON decodes the known counts and collects the rest into Other.
+func (k *IndexCounts) UnmarshalJSON(data []byte) error {
+ type plain IndexCounts
+ var p plain
+ if err := json.Unmarshal(data, &p); err != nil {
+ return err
+ }
+ p.Other = nil
+ var all map[string]json.RawMessage
+ if err := json.Unmarshal(data, &all); err != nil {
+ return err
+ }
+ for key, raw := range all {
+ var n int
+ if indexCountsKnown[key] || json.Unmarshal(raw, &n) != nil {
+ continue
+ }
+ if p.Other == nil {
+ p.Other = map[string]int{}
+ }
+ p.Other[key] = n
+ }
+ *k = IndexCounts(p)
+ return nil
}
// APIError is an answer other than 200. NotFound reports a 404.
diff --git a/pkg/asymptoteobserve/intelapi/client_test.go b/pkg/asymptoteobserve/intelapi/client_test.go
index 8dffac07..a987f25b 100644
--- a/pkg/asymptoteobserve/intelapi/client_test.go
+++ b/pkg/asymptoteobserve/intelapi/client_test.go
@@ -218,6 +218,17 @@ func TestCheckPostsTheItems(t *testing.T) {
}
}
+func TestIndexCountsKeepsCountsItDoesNotName(t *testing.T) {
+ var s Status
+ if err := json.Unmarshal([]byte(`{"index":{"mcp":{"artifacts":3,"analyzed":2,"high":1,"malicious":4,"note":"x"}}}`), &s); err != nil {
+ t.Fatal(err)
+ }
+ k := s.Index["mcp"]
+ if k.Artifacts != 3 || k.High != 1 || len(k.Other) != 1 || k.Other["malicious"] != 4 {
+ t.Fatalf("counts = %+v", k)
+ }
+}
+
func TestStatus(t *testing.T) {
_, c := newFake(t, func(w http.ResponseWriter, r *http.Request, _ string) {
writeJSON(w, 200, map[string]any{"api": "intel.v1", "index": map[string]any{"mcp": map[string]int{"artifacts": 4, "high": 1, "partial": 2}}, "latest_analyzed_at": "2026-10-02T00:00:00.000Z"})