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
Resolve config paths named in the environment; keep a private basis on merge
Clauded524e081da88
diff --git a/cli/beacon/internal/intel/installed.go b/cli/beacon/internal/intel/installed.goindex b3cee535..64685ff5 100644--- a/cli/beacon/internal/intel/installed.go+++ b/cli/beacon/internal/intel/installed.go@@ -100,6 +100,10 @@ func FromInventory(res inventory.Result, opts FromInventoryOptions) ([]Installeditem = &Installed{Kind: kind, Q: q, Basis: basis}byKey[key] = itemorder = append(order, key)+ } else if basis == BasisPrivateNPM || basis == BasisPrivatePyPI {+ // One source fetching the package from a private registry or index makes every+ // match a match by name for that source, so the private basis wins.+ item.Basis = basis}for _, s := range item.Sources {if s == src {diff --git a/cli/beacon/internal/intel/installed_test.go b/cli/beacon/internal/intel/installed_test.goindex 0e092811..2b894f2b 100644--- a/cli/beacon/internal/intel/installed_test.go+++ b/cli/beacon/internal/intel/installed_test.go@@ -266,6 +266,17 @@ func TestFromInventoryKnowsBeaconByDefinitionNotName(t *testing.T) {}}+func TestFromInventoryKeepsThePrivateBasisWhicheverSourceComesFirst(t *testing.T) {+ public := server("cursor", "a", "user", map[string]interface{}{"command": "npx", "args": []interface{}{"-y", "foo"}})+ private := server("claude_code", "b", "user", map[string]interface{}{"command": "npx", "args": []interface{}{"--registry=https://npm.corp.example", "-y", "foo"}})+ for _, order := range [][]inventory.MCPServer{{public, private}, {private, public}} {+ items, _ := FromInventory(inventory.Result{MCPServers: order}, FromInventoryOptions{IncludePrivateNames: true})+ if len(items) != 1 || items[0].Q != "npm:foo" || items[0].Basis != BasisPrivateNPM || len(items[0].Sources) != 2 {+ t.Errorf("order %s, %s: items = %+v", order[0].ServerName, order[1].ServerName, items)+ }+ }+}+func TestPackageFromCommandRefusesSpecsOffTheRegistry(t *testing.T) {for _, tc := range []struct {command stringdiff --git a/cli/beacon/internal/intel/registries.go b/cli/beacon/internal/intel/registries.goindex 51196565..54aacd1a 100644--- a/cli/beacon/internal/intel/registries.go+++ b/cli/beacon/internal/intel/registries.go@@ -106,16 +106,31 @@ func LocalRegistries(env RegistryEnv) Registries {return path}+ // A config file or prefix the environment names is resolved as npm, pip and uv resolve it+ // (${VAR}, ~, an absolute path). One Beacon cannot resolve is still read by the launcher, so+ // it leaves Beacon unable to tell where packages come from.+ envPath := func(k string, private *bool) string {+ v := getenv(k)+ if v == "" {+ return ""+ }+ path, ok := reg.expandPath(v)+ if !ok {+ *private = true+ }+ return path+ }+// npm and pnpm: user, project and global npmrc.- userNpmrc := getenv("npm_config_userconfig")- if userNpmrc == "" {+ userNpmrc := envPath("npm_config_userconfig", ®.NPM)+ if getenv("npm_config_userconfig") == "" {userNpmrc = join(home, ".npmrc")}- npmrcs := []string{userNpmrc, getenv("npm_config_globalconfig")}+ npmrcs := []string{userNpmrc, envPath("npm_config_globalconfig", ®.NPM)}// The global npmrc lives under npm's prefix, and npm's builtin npmrc beside the npm the node// ships; npm derives both from the node it runs on (nvm, fnm, Volta and system installs each// have their own).- npmrcs = append(npmrcs, join(getenv("npm_config_prefix"), "etc", "npmrc"))+ npmrcs = append(npmrcs, join(envPath("npm_config_prefix", ®.NPM), "etc", "npmrc"))npmrcs = append(npmrcs, nodeNpmrcs(filepath.SplitList(getenv("PATH")))...)for _, path := range append(npmrcs, system("/etc/npmrc"),// pnpm's global config (pnpm config set --location=global), npmrc format.@@ -135,7 +150,7 @@ func LocalRegistries(env RegistryEnv) Registries {}}// pip (and pipx, which runs pip): every config file pip reads.- for _, path := range []string{getenv("PIP_CONFIG_FILE"), join(home, ".pip", "pip.conf"), join(xdg, "pip", "pip.conf"),+ for _, path := range []string{envPath("PIP_CONFIG_FILE", ®.PyPI), join(home, ".pip", "pip.conf"), join(xdg, "pip", "pip.conf"),join(home, "Library", "Application Support", "pip", "pip.conf"), join(appData, "pip", "pip.ini"), join(home, "pip", "pip.ini"),system("/etc/pip.conf"), system("/etc/xdg/pip/pip.conf"), system("/Library/Application Support/pip/pip.conf"),join(getenv("ProgramData"), "pip", "pip.ini"), join(getenv("VIRTUAL_ENV"), "pip.conf")} {@@ -144,7 +159,7 @@ func LocalRegistries(env RegistryEnv) Registries {}}// uv: user, system and project configuration.- for _, path := range []string{getenv("UV_CONFIG_FILE"), join(xdg, "uv", "uv.toml"), join(appData, "uv", "uv.toml"),+ for _, path := range []string{envPath("UV_CONFIG_FILE", ®.PyPI), join(xdg, "uv", "uv.toml"), join(appData, "uv", "uv.toml"),system("/etc/uv/uv.toml"), system("/etc/xdg/uv/uv.toml"), join(getenv("ProgramData"), "uv", "uv.toml")} {if registryLine(path, isPyPIIndexLine) {reg.PyPI = truediff --git a/cli/beacon/internal/intel/registries_test.go b/cli/beacon/internal/intel/registries_test.goindex 53dee041..c7da3393 100644--- a/cli/beacon/internal/intel/registries_test.go+++ b/cli/beacon/internal/intel/registries_test.go@@ -247,6 +247,40 @@ func TestLocalRegistriesFollowsAConfigFileNamedInTheEnvironment(t *testing.T) {}}+func TestLocalRegistriesResolvesConfigPathsNamedInTheEnvironment(t *testing.T) {+ home := t.TempDir()+ writeConfig(t, filepath.Join(home, ".npmrc-work"), "registry=https://npm.corp.example\n")+ writeConfig(t, filepath.Join(home, "pip-work.conf"), "[global]\nindex-url = https://pypi.corp.example/simple\n")+ // ~ is resolved as npm and pip resolve it, so the file they read is read here too.+ if reg := LocalRegistries(RegistryEnv{Home: home, Environ: []string{"npm_config_userconfig=~/.npmrc-work"}}); !reg.private("npm:plain") {+ t.Errorf("npm_config_userconfig=~/... was not followed: %+v", reg)+ }+ if reg := LocalRegistries(RegistryEnv{Home: home, Environ: []string{"PIP_CONFIG_FILE=~/pip-work.conf"}}); !reg.private("pypi:x") {+ t.Errorf("PIP_CONFIG_FILE=~/... was not followed: %+v", reg)+ }+ // A path Beacon cannot resolve is still one the launcher reads, so nothing reads as public.+ for _, kv := range []string{+ "npm_config_userconfig=relative/.npmrc",+ "npm_config_globalconfig=${UNSET_VAR}/npmrc",+ "npm_config_prefix=relative-prefix",+ } {+ if reg := LocalRegistries(RegistryEnv{Home: home, Environ: []string{kv}}); !reg.private("npm:plain") {+ t.Errorf("%s left npm packages public: %+v", kv, reg)+ }+ }+ for _, kv := range []string{"PIP_CONFIG_FILE=relative/pip.conf", "UV_CONFIG_FILE=${UNSET_VAR}/uv.toml"} {+ if reg := LocalRegistries(RegistryEnv{Home: home, Environ: []string{kv}}); !reg.private("pypi:x") {+ t.Errorf("%s left PyPI packages public: %+v", kv, reg)+ }+ }+ // An absolute path to a file with nothing private in it changes nothing.+ empty := filepath.Join(home, "empty-npmrc")+ writeConfig(t, empty, "color=false\n")+ if reg := LocalRegistries(RegistryEnv{Home: home, Environ: []string{"npm_config_userconfig=" + empty}}); reg.private("npm:plain") {+ t.Errorf("an empty npmrc named in the environment made npm private: %+v", reg)+ }+}+func TestCurrentRegistryEnvReadsSystemAndProjectFiles(t *testing.T) {if env := CurrentRegistryEnv(); !env.System || env.WorkingDir == "" {t.Fatalf("CurrentRegistryEnv() = %+v", env)