Skip to content

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

fix(pi): honor PI_CODING_AGENT_DIR for the extension install, discovery and inventory (#898)

Rudy Mizrahi Celekli7159906b2794
diff --git a/cli/beacon/internal/endpoint/harness/pi.go b/cli/beacon/internal/endpoint/harness/pi.go
index 3c5bff22..2c2d2a9e 100644
--- a/cli/beacon/internal/endpoint/harness/pi.go
+++ b/cli/beacon/internal/endpoint/harness/pi.go
@@ -2,10 +2,10 @@ package harness
import (
"os"
- "path/filepath"
"strings"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/pisession"
)
// DiscoverPi reports whether Pi (pi.dev) is present and whether Beacon is observing it.
@@ -18,9 +18,6 @@ func DiscoverPi() Harness {
h := Harness{Name: "pi_cli", DisplayName: "Pi", Capability: "plugin"}
detectExecutable(&h, "pi")
- home, _ := os.UserHomeDir()
- agentDir := filepath.Join(home, ".pi", "agent")
-
// A missing home directory leaves the config path empty rather than resolving to a relative
// path like ".pi/agent/extensions/beacon.ts", which would make discovery report on whatever
// happens to sit under the current working directory.
@@ -37,8 +34,12 @@ func DiscoverPi() Harness {
// is still there. Treating that directory as evidence keeps `endpoint discover` from reporting
// "not detected" for a runtime the user is actively using, which is the same fallback the
// opencode, Cursor and Hermes probes make for the same reason.
- if !h.Detected && dirExists(agentDir) {
- h.Detected = true
+ if !h.Detected {
+ if home, err := os.UserHomeDir(); err == nil {
+ if agentDir, err := pisession.AgentDir(home); err == nil && dirExists(agentDir) {
+ h.Detected = true
+ }
+ }
}
h.TelemetryStatus, h.Message = piStatus(extensionPath)
diff --git a/cli/beacon/internal/endpoint/harness/pi_test.go b/cli/beacon/internal/endpoint/harness/pi_test.go
index 7866c40f..ba90968f 100644
--- a/cli/beacon/internal/endpoint/harness/pi_test.go
+++ b/cli/beacon/internal/endpoint/harness/pi_test.go
@@ -168,3 +168,23 @@ func TestDiscoverPiUsesCanonicalHarnessName(t *testing.T) {
"hook and OTLP paths agree", name, got)
}
}
+
+// PI_CODING_AGENT_DIR moves Pi's agent directory, so discovery has to report the extension, and
+// look for the state directory, where the override puts them rather than under ~/.pi/agent.
+func TestDiscoverPiFollowsTheAgentDirOverride(t *testing.T) {
+ home := setupPiDiscovery(t)
+ agentDir := filepath.Join(home, "elsewhere", "agent")
+ t.Setenv("PI_CODING_AGENT_DIR", agentDir)
+ if err := os.MkdirAll(agentDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+
+ h := DiscoverPi()
+ 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("DiscoverPi reported not detected with an overridden agent directory present")
+ }
+}
diff --git a/cli/beacon/internal/endpoint/hooks/pi.go b/cli/beacon/internal/endpoint/hooks/pi.go
index 683c5392..d1b8998d 100644
--- a/cli/beacon/internal/endpoint/hooks/pi.go
+++ b/cli/beacon/internal/endpoint/hooks/pi.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
piextension "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks/assets/pi"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/pisession"
)
// Pi (pi.dev) has no hooks configuration file and no OpenTelemetry support, so neither of Beacon's
@@ -118,7 +119,7 @@ func piExtensionDir(level Level) (string, error) {
if err != nil {
return "", err
}
- return filepath.Join(home, ".pi", "agent", "extensions"), nil
+ return piUserExtensionDir(home)
case LevelProject:
cwd, err := os.Getwd()
if err != nil {
@@ -129,3 +130,23 @@ func piExtensionDir(level Level) (string, error) {
return "", fmt.Errorf("unknown hook level %q", level)
}
}
+
+// PiExtensionPathForHome is the user-level extension file for home. Inventory uses it so a scan
+// reports the file the installer writes, including where PI_CODING_AGENT_DIR moves it.
+func PiExtensionPathForHome(home string) (string, error) {
+ dir, err := piUserExtensionDir(home)
+ if err != nil {
+ return "", err
+ }
+ return filepath.Join(dir, piExtensionFileName), nil
+}
+
+// piUserExtensionDir is the extensions directory in Pi's agent directory (pisession.AgentDir), which
+// PI_CODING_AGENT_DIR moves.
+func piUserExtensionDir(home string) (string, error) {
+ agentDir, err := pisession.AgentDir(home)
+ if err != nil {
+ return "", fmt.Errorf("resolve the Pi extension path: %w", err)
+ }
+ return filepath.Join(agentDir, "extensions"), nil
+}
diff --git a/cli/beacon/internal/endpoint/hooks/pi_test.go b/cli/beacon/internal/endpoint/hooks/pi_test.go
index dd998bdc..0016ec07 100644
--- a/cli/beacon/internal/endpoint/hooks/pi_test.go
+++ b/cli/beacon/internal/endpoint/hooks/pi_test.go
@@ -293,3 +293,45 @@ func TestPiExtensionReferencesBinaryHandlesWindowsPaths(t *testing.T) {
t.Fatal("piExtensionReferencesBinary matched an empty binary path")
}
}
+
+// PI_CODING_AGENT_DIR replaces Pi's user agent directory outright, and Beacon's Pi session store
+// already reads it. An install that ignored it would write the extension where Pi does not look.
+func TestPiExtensionPathHonorsTheAgentDirOverride(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ agentDir := filepath.Join(home, "elsewhere", "agent")
+ t.Setenv("PI_CODING_AGENT_DIR", agentDir)
+
+ got, err := PiExtensionPath(LevelUser)
+ if err != nil {
+ t.Fatalf("PiExtensionPath returned error: %v", err)
+ }
+ if want := filepath.Join(agentDir, "extensions", "beacon.ts"); got != want {
+ t.Fatalf("PiExtensionPath = %q, want %q", got, want)
+ }
+
+ t.Setenv("PI_CODING_AGENT_DIR", "~/custom/agent")
+ got, err = PiExtensionPath(LevelUser)
+ if err != nil {
+ t.Fatalf("PiExtensionPath returned error: %v", err)
+ }
+ if want := filepath.Join(home, "custom", "agent", "extensions", "beacon.ts"); got != want {
+ t.Fatalf("PiExtensionPath with ~ = %q, want %q", got, want)
+ }
+}
+
+func TestPiAgentDirOverrideDoesNotMoveTheProjectPath(t *testing.T) {
+ home := t.TempDir()
+ cwd := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Chdir(cwd)
+ t.Setenv("PI_CODING_AGENT_DIR", filepath.Join(home, "elsewhere", "agent"))
+
+ got, err := PiExtensionPath(LevelProject)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if want := filepath.Join(cwd, ".pi", "extensions", "beacon.ts"); got != want {
+ t.Fatalf("PiExtensionPath(project) = %q, want %q", got, want)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.go
index 2db9cd73..fe666862 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory.go
@@ -369,11 +369,13 @@ func clineCandidates(home, wd string) []candidate {
func piCandidates(home, wd string) []candidate {
items := []candidate{}
if home != "" {
- items = append(items, candidate{
- runtime: "pi_cli",
- path: filepath.Join(home, ".pi", "agent", "extensions", "beacon.ts"),
- scope: ScopeUser, format: formatMetadataOnly, kind: KindPlugin,
- })
+ if path, err := hooks.PiExtensionPathForHome(home); err == nil {
+ items = append(items, candidate{
+ runtime: "pi_cli",
+ path: path,
+ scope: ScopeUser, format: formatMetadataOnly, kind: KindPlugin,
+ })
+ }
}
if wd != "" {
items = append(items, candidate{
diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.go
index 84cbbf92..fa0cffb2 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go
@@ -1399,3 +1399,18 @@ func TestSnapshotDigestIgnoresVolatileStateFileChurn(t *testing.T) {
t.Fatal("an edit to settings.json must still change the digest")
}
}
+
+func TestScanFollowsPiAgentDirForTheUserExtension(t *testing.T) {
+ home := t.TempDir()
+ agentDir := filepath.Join(t.TempDir(), "pi-agent")
+ t.Setenv("PI_CODING_AGENT_DIR", agentDir)
+
+ var got []string
+ for _, c := range piCandidates(home, "") {
+ got = append(got, c.path)
+ }
+ want := filepath.Join(agentDir, "extensions", "beacon.ts")
+ if len(got) != 1 || got[0] != want {
+ t.Fatalf("pi user candidates = %v, want [%s]", got, want)
+ }
+}
diff --git a/cli/beacon/internal/pisession/store.go b/cli/beacon/internal/pisession/store.go
index 2a7cb41e..6b96133d 100644
--- a/cli/beacon/internal/pisession/store.go
+++ b/cli/beacon/internal/pisession/store.go
@@ -73,7 +73,18 @@ func defaultAgentDir() (string, error) {
if err != nil {
return "", fmt.Errorf("resolve home directory: %w", err)
}
+ return AgentDir(home)
+}
+
+// AgentDir resolves Pi's user agent directory for home, the way Pi does: PI_CODING_AGENT_DIR,
+// trimmed and with a leading `~` expanded against home, or ~/.pi/agent. Pi keeps its sessions and
+// its user extensions under it, so the session reader, the extension installer, discovery and
+// inventory all resolve it here.
+func AgentDir(home string) (string, error) {
if override := strings.TrimSpace(os.Getenv(piAgentDirEnv)); override != "" {
+ if strings.TrimSpace(home) == "" && (override == "~" || strings.HasPrefix(override, "~/") || strings.HasPrefix(override, `~\`)) {
+ return "", fmt.Errorf("home directory is required to resolve %s=%q", piAgentDirEnv, override)
+ }
return expandTilde(override, home), nil
}
if strings.TrimSpace(home) == "" {
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index c13fed89..6246bfba 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -12,6 +12,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
## October 2026
- **The scheduled inventory job follows every moved runtime directory** · The job starts without your shell's environment, so a per-user install or repair records the variables that move a runtime's user directory into it. It recorded `CODEX_HOME`, `HERMES_HOME`, `CLINE_DIR`, `GEMINI_CLI_HOME` and `CLAUDE_CONFIG_DIR`, and now also `KIRO_HOME`, `KIMI_CODE_HOME`, `DSH_HOME`, `OH_PERSISTENCE_DIR`, `OPENCLAW_STATE_DIR`, `XDG_CONFIG_HOME` (Muse, and VS Code on Linux), `PI_CODING_AGENT_DIR`, `OMO_CODING_AGENT_DIR`, `SENPI_CODING_AGENT_DIR`, `PRIME_AGENT_CODING_AGENT_DIR`, and Oh My Pi's `PI_CONFIG_DIR`, `OMP_PROFILE` and `PI_PROFILE`. With one of these set only in your shell, the job used to inventory the default directory while the runtime read the moved one. See [Inventory heartbeats](/cli/endpoint-inventory#inventory-heartbeats).
+- **Pi extension follows `PI_CODING_AGENT_DIR`** · `beacon endpoint hooks install --harness pi`, `beacon endpoint discover` and inventory now use `$PI_CODING_AGENT_DIR/extensions/beacon.ts` when `PI_CODING_AGENT_DIR` is set, as Pi does, including a leading `~`. They previously always used `~/.pi/agent`, so with the variable set the extension went where Pi never loads it while discovery reported Pi as enabled, and live capture silently recorded nothing. Session status and sync already followed the variable; all of them now resolve the directory the same way.
### v1.3.42 · October 15, 2026
diff --git a/docs/cli/endpoint-paths.mdx b/docs/cli/endpoint-paths.mdx
index 2e380f78..f4c5d0e4 100644
--- a/docs/cli/endpoint-paths.mdx
+++ b/docs/cli/endpoint-paths.mdx
@@ -63,7 +63,7 @@ Hook and plugin configuration is written to:
| Grok Build | `~/.grok/hooks/beacon-endpoint.json` | `./.grok/hooks/beacon-endpoint.json` |
| Hermes Agent | `$HERMES_HOME/config.yaml` or the active profile's (default `~/.hermes/config.yaml`) | Not supported |
| OpenCode | `~/.config/opencode/plugins/beacon.ts` | `./.opencode/plugins/beacon.ts` |
-| Pi | `~/.pi/agent/extensions/beacon.ts` | `./.pi/extensions/beacon.ts` |
+| Pi | `$PI_CODING_AGENT_DIR/extensions/beacon.ts` (default `~/.pi/agent/extensions/beacon.ts`) | `./.pi/extensions/beacon.ts` |
| Qwen Code | `~/.qwen/settings.json` | `./.qwen/settings.json` |
## Related
diff --git a/docs/runtimes/pi.mdx b/docs/runtimes/pi.mdx
index ebfa43ea..e41160da 100644
--- a/docs/runtimes/pi.mdx
+++ b/docs/runtimes/pi.mdx
@@ -39,18 +39,20 @@ Beacon's managed Pi extension is a single TypeScript file at one of two document
| Level | Extension path |
|-------|----------------|
-| User | `~/.pi/agent/extensions/beacon.ts` |
+| User | `~/.pi/agent/extensions/beacon.ts`, or `$PI_CODING_AGENT_DIR/extensions/beacon.ts` |
| Project | `./.pi/extensions/beacon.ts` |
User level is the default. A project-level extension is subject to Pi's project-trust prompt, and `beacon endpoint discover` reports on the user path only, so a project-level extension does not appear in discovery output.
+`PI_CODING_AGENT_DIR` replaces Pi's user agent directory, and Beacon follows it as Pi does, including a leading `~`: extension install, discovery, inventory, and session status and sync all use the same directory. It does not move the project path. The scheduled inventory job starts without your shell's environment, so a per-user `beacon endpoint install` or `repair` records `PI_CODING_AGENT_DIR` in the job; see [Inventory heartbeats](/cli/endpoint-inventory#inventory-heartbeats).
+
Beacon identifies its own extension file by the marker `beacon-managed-pi-extension:v1`. The version suffix is part of the contract with the extension source: it is what lets a repair recognize a stale file instead of leaving it in place. A `beacon.ts` without the marker belongs to somebody else, so install will not overwrite it and discovery does not report it as Beacon telemetry.
Pi has no OpenTelemetry export for Beacon to configure, so there is no OTLP path for this runtime. The poll path reads JSONL transcripts from `~/.pi/agent/sessions`; if `PI_CODING_AGENT_DIR` is set, Beacon reads `sessions` below that directory, matching Pi's user-level agent directory override. The cursor lives in Beacon state, not in Pi's directory.
## Discovery and status
-Beacon detects Pi through the `pi` executable, and treats the `~/.pi/agent` state directory as an additional signal. Pi installed through npm, pnpm, or bun is often missing from the `PATH` the endpoint process inherited, because a shell alias, a version manager, or a per-project install can all hide it while the state directory is still present. The OpenCode, Cursor, and Hermes probes use the same fallback.
+Beacon detects Pi through the `pi` executable, and treats the agent state directory (`~/.pi/agent`, or `PI_CODING_AGENT_DIR`) as an additional signal. Pi installed through npm, pnpm, or bun is often missing from the `PATH` the endpoint process inherited, because a shell alias, a version manager, or a per-project install can all hide it while the state directory is still present. The OpenCode, Cursor, and Hermes probes use the same fallback.
```bash title="Show Pi discovery state"
beacon endpoint discover --all --json