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
add auto update notice
Justin D'Souza4ce1056ae804
diff --git a/cli/beacon/cmd/root.go b/cli/beacon/cmd/root.goindex 5875a6ed..255a37df 100644--- a/cli/beacon/cmd/root.go+++ b/cli/beacon/cmd/root.go@@ -1,14 +1,18 @@package cmdimport (+ "context""fmt""io""os"+ "time""github.com/spf13/cobra""github.com/spf13/cobra/doc""golang.org/x/term"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/selfupdate"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/updatecheck""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/version")@@ -20,13 +24,25 @@ local telemetry, and writes Wazuh-compatible JSON logs without requiring anBeacon-hosted backend.`,Version: version.GetVersion(),Run: func(cmd *cobra.Command, args []string) {+ maybePrintRootUpdateNotice(cmd)printRootSplash(cmd)},}const (beaconPurple = "\x1b[38;5;141m"+ beaconOrange = "\x1b[38;5;208m"resetColor = "\x1b[0m"++ beaconCLIChangelogURL = "https://docs.beacon.sh/changelog/cli"+)++var (+ newRootVersionChecker = func(currentVersion string) versionChecker {+ return updatecheck.DefaultChecker(currentVersion)+ }+ rootUpdateCheckTimeout = 2 * time.Second+ rootDetectInstall = selfupdate.DetectInstall)var beaconBanner = []string{@@ -38,6 +54,47 @@ var beaconBanner = []string{"╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝",}+func maybePrintRootUpdateNotice(cmd *cobra.Command) {+ in, inOK := cmd.InOrStdin().(*os.File)+ out, outOK := cmd.OutOrStdout().(*os.File)+ if !inOK || !outOK || !isTerminal(in) || !isTerminal(out) {+ return+ }++ parent := cmd.Context()+ if parent == nil {+ parent = context.Background()+ }+ ctx, cancel := context.WithTimeout(parent, rootUpdateCheckTimeout)+ defer cancel()++ result, err := newRootVersionChecker(version.GetVersion()).Check(ctx)+ if err != nil || !result.UpdateAvailable {+ return+ }+ printRootUpdateNotice(out, result, shouldUseColor(out), rootDetectInstall())+}++func printRootUpdateNotice(out io.Writer, result updatecheck.Result, color bool, install selfupdate.Install) {+ if color {+ fmt.Fprint(out, beaconOrange)+ }+ fmt.Fprintf(out, "Update available · %s → %s\n", result.CurrentVersion, result.LatestVersion)+ if color {+ fmt.Fprint(out, resetColor)+ }+ fmt.Fprintf(out, "Release notes: %s\n", beaconCLIChangelogURL)+ switch install.Kind {+ case selfupdate.InstallHomebrew:+ fmt.Fprintln(out, "Update with: brew upgrade beacon")+ case selfupdate.InstallSystemPkg:+ fmt.Fprintln(out, "Update with: sudo beacon endpoint update --apply")+ default:+ fmt.Fprintln(out, "Update with: beacon endpoint update")+ }+ fmt.Fprintln(out)+}+func printRootSplash(cmd *cobra.Command) {out := cmd.OutOrStdout()cmd.SetOut(out)diff --git a/cli/beacon/cmd/root_test.go b/cli/beacon/cmd/root_test.goindex 9e880aad..0704443c 100644--- a/cli/beacon/cmd/root_test.go+++ b/cli/beacon/cmd/root_test.go@@ -8,6 +8,9 @@ import ("testing""github.com/spf13/cobra"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/selfupdate"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/updatecheck")func TestPrintRootSplash(t *testing.T) {@@ -41,6 +44,77 @@ func TestPrintRootSplash(t *testing.T) {}}+func TestPrintRootUpdateNotice(t *testing.T) {+ result := updatecheck.Result{+ CurrentVersion: "v1.3.33",+ LatestVersion: "v1.3.34",+ UpdateAvailable: true,+ }++ tests := []struct {+ name string+ install selfupdate.Install+ command string+ }{+ {name: "homebrew", install: selfupdate.Install{Kind: selfupdate.InstallHomebrew}, command: "brew upgrade beacon"},+ {name: "system package", install: selfupdate.Install{Kind: selfupdate.InstallSystemPkg}, command: "sudo beacon endpoint update --apply"},+ {name: "other", install: selfupdate.Install{Kind: selfupdate.InstallOther}, command: "beacon endpoint update"},+ }+ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ var out bytes.Buffer+ printRootUpdateNotice(&out, result, false, tt.install)+ got := out.String()+ for _, want := range []string{+ "Update available · v1.3.33 → v1.3.34",+ "Release notes: https://docs.beacon.sh/changelog/cli",+ "Update with: " + tt.command,+ } {+ if !strings.Contains(got, want) {+ t.Fatalf("update notice missing %q:\n%s", want, got)+ }+ }+ if strings.Contains(got, "\x1b[") {+ t.Fatalf("uncolored update notice includes ANSI escapes: %q", got)+ }+ })+ }+}++func TestPrintRootUpdateNoticeUsesOrange(t *testing.T) {+ var out bytes.Buffer+ printRootUpdateNotice(&out, updatecheck.Result{+ CurrentVersion: "v1.3.33",+ LatestVersion: "v1.3.34",+ UpdateAvailable: true,+ }, true, selfupdate.Install{Kind: selfupdate.InstallHomebrew})++ if !strings.HasPrefix(out.String(), beaconOrange) {+ t.Fatalf("colored update notice does not start orange: %q", out.String())+ }+ if !strings.Contains(out.String(), resetColor) {+ t.Fatalf("colored update notice does not reset color: %q", out.String())+ }+}++func TestRootUpdateNoticeSkipsNonInteractiveCommands(t *testing.T) {+ oldChecker := newRootVersionChecker+ t.Cleanup(func() { newRootVersionChecker = oldChecker })+ called := false+ newRootVersionChecker = func(string) versionChecker {+ called = true+ return stubVersionChecker{}+ }++ cmd := &cobra.Command{}+ cmd.SetIn(bytes.NewBuffer(nil))+ cmd.SetOut(&bytes.Buffer{})+ maybePrintRootUpdateNotice(cmd)+ if called {+ t.Fatal("non-interactive root command performed an update check")+ }+}+// isTerminal gates the full-screen onboarding wizard and the trace browser, so// anything that is not a real terminal has to read as false.//diff --git a/docs/cli/version.mdx b/docs/cli/version.mdxindex 1722ca8b..131c0e78 100644--- a/docs/cli/version.mdx+++ b/docs/cli/version.mdx@@ -11,6 +11,12 @@ Display the version number, git commit, and build date of the Agent Beacon CLI,beacon version```+Running `beacon` by itself in an interactive terminal also checks for a newer+release. When one is available, an orange notice shows the installed and latest+versions, links to the [CLI changelog](/changelog/cli), and prints the update+command for the detected installation method. The notice is best-effort and is+never shown in pipes, redirects, scripts, or other non-interactive commands.+<Accordion title="Example output">```bash title="Example output"$ beacon version