Skip to content

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

Discover Prime Agent and expect its token usage

Claude3ebefb319a76
diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.go
index f7c59bcb..c63d4473 100644
--- a/cli/beacon/internal/endpoint/harness/harness.go
+++ b/cli/beacon/internal/endpoint/harness/harness.go
@@ -59,6 +59,7 @@ func DiscoverAll() []Harness {
DiscoverCline(),
DiscoverPi(),
DiscoverOmp(),
+ DiscoverPrime(),
DiscoverFx(),
DiscoverQwen(),
DiscoverHermes(),
diff --git a/cli/beacon/internal/endpoint/harness/prime.go b/cli/beacon/internal/endpoint/harness/prime.go
new file mode 100644
index 00000000..c058422b
--- /dev/null
+++ b/cli/beacon/internal/endpoint/harness/prime.go
@@ -0,0 +1,78 @@
+package harness
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
+)
+
+// DiscoverPrime reports whether Prime Agent (Prime Intellect) is present and whether Beacon is
+// observing it.
+//
+// Its capability is "plugin" rather than "hooks" or "otel_env" for the same reason Pi's and Oh My
+// Pi's are: it has neither surface -- no hooks configuration file to merge into and no
+// OpenTelemetry export to point at the local collector. Its documented observation surface is the
+// TypeScript extension API, so what Beacon installs is one extension file, and what this function
+// reports is the state of that file.
+func DiscoverPrime() Harness {
+ h := Harness{Name: "prime_agent", DisplayName: "Prime Agent", Capability: "plugin"}
+ // The distributed command is `prime-agent`. `prime` is deliberately not probed for: it is an
+ // ordinary word that a coreutils-adjacent binary or a company-internal script could plausibly
+ // claim, and a false positive here reports a runtime the machine does not have.
+ detectExecutable(&h, "prime-agent")
+
+ // A missing home directory leaves the config path empty rather than resolving to a relative
+ // path like ".prime/agent/extensions/beacon.ts", which would make discovery report on whatever
+ // happens to sit under the current working directory. DiscoverPi and DiscoverOmp guard the
+ // same way.
+ extensionPath, err := hooks.PrimeExtensionPath(hooks.LevelUser)
+ if err != nil {
+ h.TelemetryStatus = TelemetryMissing
+ h.Message = "Prime Agent extension directory could not be resolved: " + err.Error()
+ return h
+ }
+ h.ConfigPath = extensionPath
+
+ // Prime Agent installed through npm, through its own install.sh into
+ // ~/.local/share/prime-agent, or into any directory this process did not inherit on PATH is
+ // still detectable by its state directory -- a shell alias, a version manager, or a per-project
+ // install all hide the binary while the directory remains. Treating that directory as evidence
+ // keeps `endpoint discover` from reporting "not detected" for a runtime the operator is
+ // actively using, the same fallback the Pi, Oh My Pi, opencode, Cursor and Hermes probes make.
+ //
+ // The directory checked is the one the resolved extension path lives under rather than a
+ // rebuilt `~/.prime/agent`, so a PRIME_AGENT_CODING_AGENT_DIR override is detected where it
+ // actually is instead of being missed at the default location.
+ if !h.Detected && dirExists(filepath.Dir(filepath.Dir(extensionPath))) {
+ h.Detected = true
+ }
+
+ h.TelemetryStatus, h.Message = primeStatus(extensionPath)
+ return h
+}
+
+// primeStatus classifies the extension file at path.
+//
+// The middle case is the one worth spelling out: a beacon.ts that exists without Beacon's marker is
+// somebody else's extension sharing the filename, so it is reported as disabled rather than
+// enabled. Reporting it as enabled would claim telemetry Beacon is not collecting, and install
+// refuses to overwrite the same file for the same reason.
+//
+// A file carrying Pi's or Oh My Pi's marker at this path is also not a Prime Agent install. The
+// three runtimes read different directories today, so it should not happen -- but the markers are
+// distinct precisely so that the answer does not depend on that staying true.
+func primeStatus(path string) (TelemetryStatus, string) {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return TelemetryMissing, "Beacon Prime Agent extension was not found"
+ }
+ return TelemetryMissing, err.Error()
+ }
+ if !strings.Contains(string(data), hooks.PrimeManagedExtensionMarker) {
+ return TelemetryDisabled, "Prime Agent extension file exists but Beacon endpoint extension was not found"
+ }
+ return TelemetryEnabled, "Beacon Prime Agent extension is configured"
+}
diff --git a/cli/beacon/internal/endpoint/harness/prime_test.go b/cli/beacon/internal/endpoint/harness/prime_test.go
new file mode 100644
index 00000000..c96cfd2a
--- /dev/null
+++ b/cli/beacon/internal/endpoint/harness/prime_test.go
@@ -0,0 +1,174 @@
+package harness
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
+)
+
+// writePrimeExtension creates a user-level Prime Agent extension file with the given contents.
+func writePrimeExtension(t *testing.T, home, contents string) string {
+ t.Helper()
+ path := filepath.Join(home, ".prime", "agent", "extensions", "beacon.ts")
+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+ t.Fatalf("mkdir prime extensions dir: %v", err)
+ }
+ if err := os.WriteFile(path, []byte(contents), 0644); err != nil {
+ t.Fatalf("write prime extension: %v", err)
+ }
+ return path
+}
+
+// Every Prime Agent discovery test empties PATH and the variable that moves its extension
+// directory. Without that, the result depends on whether the machine running the suite happens to
+// have `prime-agent` installed -- exactly the kind of environment-dependent assertion the repo's
+// deterministic-test rule exists to prevent.
+func setupPrimeDiscovery(t *testing.T) string {
+ t.Helper()
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Setenv("PATH", t.TempDir())
+ t.Setenv("PRIME_AGENT_CODING_AGENT_DIR", "")
+ return home
+}
+
+func TestDiscoverPrimeReportsMissingExtension(t *testing.T) {
+ home := setupPrimeDiscovery(t)
+
+ h := DiscoverPrime()
+ if h.Detected {
+ t.Fatalf("DiscoverPrime detected Prime Agent with no executable and no state directory: %#v", h)
+ }
+ want := filepath.Join(home, ".prime", "agent", "extensions", "beacon.ts")
+ if h.ConfigPath != want {
+ t.Fatalf("ConfigPath = %q, want %q", h.ConfigPath, want)
+ }
+ if h.TelemetryStatus != TelemetryMissing {
+ t.Fatalf("TelemetryStatus = %q, want %q", h.TelemetryStatus, TelemetryMissing)
+ }
+ if h.Capability != "plugin" {
+ t.Fatalf("Capability = %q, want %q -- Prime Agent has no hooks file and no OTel export, so "+
+ "the integration is extension-shaped", h.Capability, "plugin")
+ }
+}
+
+// Prime Agent installed through npm, through its own install.sh into ~/.local/share/prime-agent, or
+// into a directory this process did not inherit on PATH is not visible as an executable, so the
+// state directory has to count as evidence. The alternative is reporting "not detected" for a
+// runtime the operator is actively running, which reads as "Beacon cannot see this" when the truth
+// is "Beacon has not been installed into it yet".
+func TestDiscoverPrimeTreatsTheStateDirectoryAsEvidence(t *testing.T) {
+ home := setupPrimeDiscovery(t)
+ if err := os.MkdirAll(filepath.Join(home, ".prime", "agent"), 0755); err != nil {
+ t.Fatal(err)
+ }
+
+ h := DiscoverPrime()
+ if !h.Detected {
+ t.Fatal("DiscoverPrime reported not detected with a Prime Agent agent directory present")
+ }
+ if h.TelemetryStatus != TelemetryMissing {
+ t.Fatalf("TelemetryStatus = %q, want %q -- the runtime is present but Beacon is not "+
+ "installed into it", h.TelemetryStatus, TelemetryMissing)
+ }
+}
+
+// The directory checked is the one the resolved extension path lives under, not a rebuilt
+// `~/.prime/agent`, so an overridden install is detected where it actually is rather than being
+// missed at the default location.
+func TestDiscoverPrimeFollowsTheAgentDirOverride(t *testing.T) {
+ home := setupPrimeDiscovery(t)
+ agentDir := filepath.Join(home, "elsewhere", "agent")
+ t.Setenv("PRIME_AGENT_CODING_AGENT_DIR", agentDir)
+ if err := os.MkdirAll(agentDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+
+ h := DiscoverPrime()
+ want := filepath.Join(agentDir, "extensions", "beacon.ts")
+ if h.ConfigPath != want {
+ t.Fatalf("ConfigPath = %q, want %q", h.ConfigPath, want)
+ }
+ if !h.Detected {
+ t.Fatal("DiscoverPrime reported not detected with an overridden agent directory present")
+ }
+}
+
+func TestDiscoverPrimeReportsAManagedExtensionAsEnabled(t *testing.T) {
+ home := setupPrimeDiscovery(t)
+ writePrimeExtension(t, home, "// "+hooks.PrimeManagedExtensionMarker+"\nexport default function () {}\n")
+
+ h := DiscoverPrime()
+ if h.TelemetryStatus != TelemetryEnabled {
+ t.Fatalf("TelemetryStatus = %q, want %q", h.TelemetryStatus, TelemetryEnabled)
+ }
+ if !h.Detected {
+ t.Fatal("an installed Beacon extension implies the runtime is present")
+ }
+}
+
+// Somebody else's extension can legitimately be called beacon.ts. Reporting it as enabled would
+// claim telemetry Beacon is not collecting -- and install refuses to overwrite it for the same
+// reason, so "disabled" is the honest reading rather than a pessimistic one.
+func TestDiscoverPrimeReportsAnUnmanagedExtensionAsDisabled(t *testing.T) {
+ home := setupPrimeDiscovery(t)
+ writePrimeExtension(t, home, "// somebody else's extension\nexport default function () {}\n")
+
+ h := DiscoverPrime()
+ if h.TelemetryStatus != TelemetryDisabled {
+ t.Fatalf("TelemetryStatus = %q, want %q", h.TelemetryStatus, TelemetryDisabled)
+ }
+}
+
+// A sibling runtime's extension is not a Prime Agent install. The three read different directories
+// today, so this should not arise -- but the markers are distinct precisely so the answer does not
+// depend on that staying true.
+func TestDiscoverPrimeDoesNotAcceptASiblingsMarker(t *testing.T) {
+ for name, marker := range map[string]string{
+ "pi": hooks.PiManagedExtensionMarker,
+ "omp": hooks.OmpManagedExtensionMarker,
+ } {
+ t.Run(name, func(t *testing.T) {
+ home := setupPrimeDiscovery(t)
+ writePrimeExtension(t, home, "// "+marker+"\nexport default function () {}\n")
+
+ if h := DiscoverPrime(); h.TelemetryStatus == TelemetryEnabled {
+ t.Fatalf("DiscoverPrime reported %s's extension as a Prime Agent install", name)
+ }
+ })
+ }
+}
+
+// The harness name discovery reports must be the canonical one events are written under, or the
+// dashboard groups a runtime's discovery row and its telemetry rows separately.
+func TestDiscoverPrimeUsesTheCanonicalHarnessName(t *testing.T) {
+ setupPrimeDiscovery(t)
+
+ h := DiscoverPrime()
+ if got := asymptoteobserve.NormalizeHarnessName(h.Name); got != h.Name {
+ t.Fatalf("DiscoverPrime reports %q, which normalizes to %q; discovery and telemetry would "+
+ "not join", h.Name, got)
+ }
+ for _, sibling := range []Harness{DiscoverPi(), DiscoverOmp()} {
+ if h.Name == sibling.Name {
+ t.Fatalf("Prime Agent and %s discovery report the same harness name", sibling.DisplayName)
+ }
+ }
+}
+
+// A runtime absent from DiscoverAll is a runtime `beacon endpoint discover` never mentions, which
+// is how support ships without anyone being able to find it.
+func TestDiscoverAllIncludesPrime(t *testing.T) {
+ setupPrimeDiscovery(t)
+
+ for _, h := range DiscoverAll() {
+ if h.Name == "prime_agent" {
+ return
+ }
+ }
+ t.Fatal("DiscoverAll does not include Prime Agent")
+}
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.go
index 1f6464ec..99fa222e 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory.go
@@ -237,6 +237,7 @@ func candidates(home, wd string) []candidate {
items = append(items, clineCandidates(home, wd)...)
items = append(items, piCandidates(home, wd)...)
items = append(items, ompCandidates(home, wd)...)
+ items = append(items, primeCandidates(home, wd)...)
items = append(items, hermesCandidates(home)...)
items = append(items, devinCandidates(home, wd)...)
items = append(items, grokCandidates(home, wd)...)
@@ -384,6 +385,34 @@ func ompCandidates(home, wd string) []candidate {
return items
}
+// primeCandidates covers both Prime Agent extension locations.
+//
+// Like ompCandidates, the user path comes from the installer rather than being rebuilt here,
+// because it is not a fixed string: PRIME_AGENT_CODING_AGENT_DIR moves it, and only the installer
+// knows that rule. The project path keeps the `agent` segment the user path has -- Prime Agent
+// joins the same two-segment literal at both scopes, unlike Pi and Oh My Pi, whose project
+// directories drop it.
+func primeCandidates(home, wd string) []candidate {
+ items := []candidate{}
+ if home != "" {
+ if path, err := hooks.PrimeExtensionPathForHome(home, hooks.LevelUser); err == nil {
+ items = append(items, candidate{
+ runtime: "prime_agent",
+ path: path,
+ scope: ScopeUser, format: formatMetadataOnly, kind: KindPlugin,
+ })
+ }
+ }
+ if wd != "" {
+ items = append(items, candidate{
+ runtime: "prime_agent",
+ path: filepath.Join(wd, ".prime", "agent", "extensions", "beacon.ts"),
+ scope: ScopeProject, format: formatMetadataOnly, kind: KindPlugin,
+ })
+ }
+ return items
+}
+
func hermesCandidates(home string) []candidate {
return []candidate{{runtime: "hermes", path: filepath.Join(home, ".hermes", "config.yaml"), scope: ScopeUser, format: formatYAML, kind: KindNativeConfig}}
}
@@ -856,6 +885,11 @@ func beaconManaged(item candidate, data []byte) bool {
// is attributed to the runtime that actually loads it rather than to whichever case ran first.
case "omp":
return strings.Contains(text, hooks.OmpManagedExtensionMarker)
+ // Third distinct marker in this family, matched separately for the same reason: a file found at
+ // any of the three paths is attributed to the runtime that actually loads it rather than to
+ // whichever case ran first.
+ case "prime_agent":
+ return strings.Contains(text, hooks.PrimeManagedExtensionMarker)
case "grok":
return strings.Contains(text, "beacon-managed-grok-hooks:v1")
// Matched on the hook command rather than on a marker, because Beacon merges into Qwen's own
diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.go
index 416c2139..207551dd 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go
@@ -353,6 +353,11 @@ func TestScanIncludesAllSupportedCurrentUserAndProjectConfigs(t *testing.T) {
// project -- but under its own `.omp` root, because the two runtimes install separately.
{runtime: "omp", path: filepath.Join(home, ".omp", "agent", "extensions", "beacon.ts"), scope: ScopeUser, format: formatMetadataOnly, kind: KindPlugin},
{runtime: "omp", path: filepath.Join(work, ".omp", "extensions", "beacon.ts"), scope: ScopeProject, format: formatMetadataOnly, kind: KindPlugin},
+ // Prime Agent, the third pi-family runtime, under its own `.prime` root. Both scopes carry
+ // the `agent` segment: it joins the same two-segment literal at project scope where Pi and
+ // Oh My Pi drop it, so a path derived from either sibling would be wrong here.
+ {runtime: "prime_agent", path: filepath.Join(home, ".prime", "agent", "extensions", "beacon.ts"), scope: ScopeUser, format: formatMetadataOnly, kind: KindPlugin},
+ {runtime: "prime_agent", path: filepath.Join(work, ".prime", "agent", "extensions", "beacon.ts"), scope: ScopeProject, format: formatMetadataOnly, kind: KindPlugin},
{runtime: "hermes", path: filepath.Join(home, ".hermes", "config.yaml"), scope: ScopeUser, format: formatYAML, kind: KindNativeConfig},
{runtime: "devin-cli", path: filepath.Join(home, ".config", "devin", "config.json"), scope: ScopeUser, format: formatJSON, kind: KindNativeConfig},
{runtime: "devin-cli", path: filepath.Join(work, ".devin", "hooks.v1.json"), scope: ScopeProject, format: formatJSON, kind: KindHookConfig},
diff --git a/cli/beacon/internal/tokens/coverage.go b/cli/beacon/internal/tokens/coverage.go
index 5ba07e37..a8a5ab82 100644
--- a/cli/beacon/internal/tokens/coverage.go
+++ b/cli/beacon/internal/tokens/coverage.go
@@ -75,6 +75,7 @@ var usageExpectation = map[string]struct {
"opencode": {ExpectReported, "plugin reports usage per assistant message"},
"pi_cli": {ExpectReported, "extension reports usage and cost"},
"omp": {ExpectReported, "extension reports usage and cost"},
+ "prime_agent": {ExpectReported, "extension reports usage and cost"},
"vercel_fx": {ExpectReported, "session store carries cumulative usage and cost"},
"asymptote_observe": {ExpectReported, "SDK spans carry semconv usage"},
@@ -103,7 +104,6 @@ var usageExpectation = map[string]struct {
"devin-desktop": {ExpectNone, "Cascade/Windsurf hook payloads carry no token counts"},
"muse_code": {ExpectNone, "usage arrives on PostLLMCall, which Beacon does not subscribe to"},
"qwen_code": {ExpectNone, "Stop reports context occupancy, not per-call usage"},
- "prime_agent": {ExpectNone, "no managed extension ships yet"},
"claude_web": {ExpectNone, "no recorded claude.ai stream has carried a usage object"},
"chatgpt_web": {ExpectNone, "the chat stream reports no token counts"},
"openhands": {ExpectNone, "hook payloads carry no token counts"},