From c241c6d6d0232fdb594b436e95b82f72accfd58f Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Tue, 28 Apr 2026 01:28:37 -0500 Subject: [PATCH] fix(coding-agent): use alternate logic to find Bun's node_modules (#3861) When `"npmCommand": ["bun"]` is configured in settings.json, pi fails to start because it invokes `bun root -g`, which doesn't exist: error: Failed to run bun root -g: error: Script not found "root" Add a check for the Bun runtime using the logic already used elsewhere, and build the relative path starting from Bun's bin directory. --- packages/coding-agent/src/core/package-manager.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/coding-agent/src/core/package-manager.ts b/packages/coding-agent/src/core/package-manager.ts index a90e041d..5a25a904 100644 --- a/packages/coding-agent/src/core/package-manager.ts +++ b/packages/coding-agent/src/core/package-manager.ts @@ -27,7 +27,7 @@ import type { Readable } from "node:stream"; import { globSync } from "glob"; import ignore from "ignore"; import { minimatch } from "minimatch"; -import { CONFIG_DIR_NAME } from "../config.js"; +import { CONFIG_DIR_NAME, isBunRuntime } from "../config.js"; import { type GitSource, parseGitUrl } from "../utils/git.js"; import { canonicalizePath, isLocalPath } from "../utils/paths.js"; import { isStdoutTakenOver } from "./output-guard.js"; @@ -1843,8 +1843,12 @@ export class DefaultPackageManager implements PackageManager { if (this.globalNpmRoot && this.globalNpmRootCommandKey === commandKey) { return this.globalNpmRoot; } - const result = this.runNpmCommandSync(["root", "-g"]); - this.globalNpmRoot = result.trim(); + if (isBunRuntime) { + const binDir = this.runCommandSync("bun", ["pm", "bin", "-g"]).trim(); + this.globalNpmRoot = join(dirname(binDir), "install", "global", "node_modules"); + } else { + this.globalNpmRoot = this.runNpmCommandSync(["root", "-g"]).trim(); + } this.globalNpmRootCommandKey = commandKey; return this.globalNpmRoot; }