Skip to content

Update npm-installed providers in the prefix that owns the CLI - #5550

Closed
ryanolson wants to merge 1 commit into
get-bb:mainfrom
ryanolson:fix/npm-provider-update-prefix
Closed

ryanolson wants to merge 1 commit into
get-bb:mainfrom
ryanolson:fix/npm-provider-update-prefix

Conversation

@ryanolson

Copy link
Copy Markdown

Human comments

What was wrong

bb updates npm-installed providers with npm install -g <package>@latest and no --prefix (provider-maintenance-kit.ts#L131-L137). The host daemon runs that command with its own environment plus only PATH from the login shell (command-dispatch.ts#L165-L168). So NPM_CONFIG_PREFIX from the shell is lost, and npm installs into its default prefix. If the user installed the CLI into their own prefix (for example NPM_CONFIG_PREFIX=~/.npm-global npm install -g ...), that copy is first on PATH and stays old. The update then fails its version check with "pi update exited successfully, but the provider could not verify the installed result." Every retry does the same. Status also shows the install source as external, because the npm probe looks at the default prefix too.

Seen with pi on macOS: ~/.npm-global/bin/pi stayed at 1.1.0 while each update wrote 1.2.0 to /opt/homebrew/bin/pi. With only PATH set, npm prefix -g prints /opt/homebrew, and the daemon's npm logs load /opt/homebrew/etc/npmrc. On Linux the same update went to ~/.pixi/envs/nodejs. #4009 reports the same thing for codex.

What changed

  • packages/provider-bridge-protocol/src/bridge-kit/provider-maintenance-kit.ts: new npmPrefixOwningExecutable(executablePath, npmPackage). It follows the CLI on PATH to its real path. If that path is under <prefix>/lib/node_modules/<package> (Windows: the shim folder holds node_modules/<package>), it returns <prefix>. It returns null when that prefix is npm's default prefix or when no npm prefix owns the CLI. npmGlobalInstallCommand and probeNpmGlobalPackage take an optional prefix and add --prefix <prefix> when it is set.
  • plugins/provider-pi/src/bridge/provider-maintenance.ts: pi passes the owning prefix to the install command and to the probe. The Bun path is unchanged.
  • packages/plugin-sdk/src/provider-bridge.ts: exports experimental_npmPrefixOwningExecutable. It is added to the provider maintenance toolkit entry in docs/api_to_audit.md and to the bb-guide API index.
  • When no owning prefix is found, behavior is unchanged: plain npm install -g <package>@latest. Users whose default prefix already holds the CLI (for example Homebrew npm) see the same command as before.
  • Codex is not fixed here. Codex installs through the kit, but it updates with codex update, which does not use the kit's npm command. Claude Code also updates with claude update. Both only get the probe default, which is unchanged.
  • No wire change. The command is still a ProviderInstallationCommand with command, args and displayCommand; only the args differ. HOST_DAEMON_PROTOCOL_VERSION is not changed.

How you verified

  • New test plugins/provider-pi/src/bridge/provider-maintenance.npm-prefix.test.ts: builds a fake npm prefix in a temp folder (package folder with package.json, bin/pi symlink into it), puts that bin first on PATH, and checks that the update command is npm install -g --prefix <prefix> @earendil-works/pi-coding-agent@latest and that status reports npmGlobal with the version from that prefix.
    • Before the fix it fails on the machine that showed the bug:
      -   "installSource": "npmGlobal",
      -   "npmGlobalPackageVersion": "0.84.0",
      +   "installSource": "external",
      +   "npmGlobalPackageVersion": "1.2.0",
      
      (1.2.0 is the pi that earlier updates wrote to /opt/homebrew.)
    • After the fix it passes.
  • New kit tests in provider-maintenance-kit.test.ts: the CLI in a custom prefix gets --prefix, and the npm list probe reads that prefix; a control where NPM_CONFIG_PREFIX makes the same prefix npm's default keeps the plain command; a CLI outside any npm package gets no prefix.
  • The existing Bun test still passes.
  • pnpm exec turbo run test --filter=@bb/provider-bridge-protocol --filter=bb-plugin-provider-pi: 314 and 318 tests pass.
  • pnpm exec turbo run test --filter=bb-plugin-provider-codex --filter=bb-plugin-provider-claude-code --filter=@get-bb/plugin-sdk: all pass.
  • pnpm exec turbo run typecheck for those five packages: pass.

Refs #4009

AGENT GENERATED

The host daemon runs provider updates with only PATH from the login
shell, so NPM_CONFIG_PREFIX is lost. npm then installs into its default
prefix, while bb keeps running the older CLI from the user's prefix, and
the version check after the update fails.

The provider maintenance kit now finds the npm prefix whose
lib/node_modules/<package> holds the CLI on PATH. When that prefix is
not npm's default, the install command and the npm list probe add
--prefix <prefix>. Pi uses this for npm installs.

Refs get-bb#4009
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @ryanolson for the PR. This repo approves new contributors before it reviews their PRs, so this PR now closes on its own. That is expected. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to this PR, and explain what it changes and why. A maintainer then adds you to the allow list and can reopen the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant