Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(install): seed bun's global manifest so a stray home package.json cannot hijack bun add -g
trohitgb88341ae8968
diff --git a/cli/terraform/gcp/startup.sh.tftpl b/cli/terraform/gcp/startup.sh.tftplindex dc289dbe..74afd672 100644--- a/cli/terraform/gcp/startup.sh.tftpl+++ b/cli/terraform/gcp/startup.sh.tftpl@@ -21,6 +21,11 @@ export BUN_INSTALL=/usr/localcurl -fsSL https://bun.sh/install | bash# uv on a stable system path (company build uses it to sync the Python venv).curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin sh+# bun resolves its global "project" by walking up from $BUN_INSTALL/install/global+# to the first package.json; give that dir its own manifest so a stray one+# higher up can never hijack the install (docs-internal/errors.md #23).+mkdir -p "$BUN_INSTALL/install/global"+test -f "$BUN_INSTALL/install/global/package.json" || echo '{ "private": true }' > "$BUN_INSTALL/install/global/package.json"echo "[${resource_name}] installing OpenCompany package..."%{ if source_mode == "local" ~}diff --git a/cli/tests/test_release_pipeline_config.py b/cli/tests/test_release_pipeline_config.pyindex 6ac4e18c..e63dfa47 100644--- a/cli/tests/test_release_pipeline_config.py+++ b/cli/tests/test_release_pipeline_config.py@@ -595,6 +595,10 @@ def test_installers_provision_through_the_shim_not_a_guessed_package_root(root:assert "provision" in src, relassert "install/global/node_modules" not in src, relassert "scripts/install.js" not in src, rel+ # bun walks up from its (initially empty) global dir to the first+ # package.json; a stray one in $HOME hijacks the install (errors.md+ # 23). Every installer seeds the global dir's own manifest first.+ assert "install/global" in src.replace("\\", "/") and "private" in src, rellauncher = (root / "bin" / "cli.js").read_text(encoding="utf-8")assert "function provision(" in launcherassert "function ensureProvisioned(" in launcherdiff --git a/docs-internal/errors.md b/docs-internal/errors.mdindex ddef7788..d9fc243d 100644--- a/docs-internal/errors.md+++ b/docs-internal/errors.md@@ -506,10 +506,18 @@ uv then downloads its 3.12 into `~/.local/share/uv`, the venvs are usable by the**Fix**: `desktop/scripts/_lib.ts::tarBinary()` prefers the System32 tar on Windows and always passes the archive as a path relative to the extraction directory so no argument carries a drive colon.-## 23. `company: command not found` after `bun add -g`, or `bun pm ls -g` aborts with `InvalidNPMLockfile`+## 23. `bun add -g` fails with `InvalidNPMLockfile: failed to migrate lockfile: 'package-lock.json'`, or `company` lands in `~/node_modules`-**Symptom**: `bun add -g @zeenie-ai/opencompany` succeeds, but `company` is not found in the same shell; or `bun pm ls -g` prints `error: failed to migrate lockfile: InvalidNPMLockfile`.+**Symptom**: `bun add -g @zeenie-ai/opencompany` aborts with `InvalidNPMLockfile: failed to migrate lockfile: 'package-lock.json'`; or it succeeds but `bun pm ls -g` reports the root as your home directory and the package sits in `~/node_modules/@zeenie-ai/opencompany`; or `company` is not found in the same shell after the install.-**Root cause**: bun puts global bin shims in `$(bun pm bin -g)` (`~/.bun/bin`, or `$BUN_INSTALL/bin`), which a shell opened before the bun installer ran does not have on PATH. Separately, bun keeps its global packages in a directory it chooses per platform and configuration (on Windows 1.4 it was the user profile, not `$BUN_INSTALL/install/global`), and a stray npm `package-lock.json` in that directory makes `bun pm ls -g` try to migrate it and fail.+**Root cause**: bun resolves the "project" for a global install by walking up from its global directory (`$BUN_INSTALL/install/global`, default `~/.bun/install/global`) until it meets a `package.json`. On a fresh bun that directory is empty, so the walk continues into `$HOME`. A stray `package.json` or `package-lock.json` there (typically an old `npm init` / `npm install` run in the home directory; the lockfile is an empty `{"name": "<user>", "lockfileVersion": 3, "packages": {}}`) becomes the global project: the package is installed into `~/node_modules`, and when only the npm lockfile is present bun tries to migrate it and fails. Seen on Windows with bun 1.4.0, where the leftover pair had sat in the profile since 2025. The not-found variant is separate: bun's global bin dir (`bun pm bin -g`, `~/.bun/bin`) is not on the PATH of a shell opened before the bun installer ran.-**Fix**: open a new shell, or `export PATH="$HOME/.bun/bin:$PATH"` (`$env:USERPROFILE\.bun\bin` on Windows). Nothing in OpenCompany depends on where the global package lives: `company provision` runs from the shim's own package root, `uninstall.sh` uses `bun remove -g` rather than listing, and the installers address the shim through `bun pm bin -g`. Delete the stray `package-lock.json` only if you know it is not yours.+**Fix**: delete the stray `package.json`, `package-lock.json`, `bun.lock` and `node_modules` from your home directory (after checking they are not a real project), then give bun's global directory its own manifest and re-run the install:++```bash+mkdir -p ~/.bun/install/global+[ -f ~/.bun/install/global/package.json ] || echo '{ "private": true }' > ~/.bun/install/global/package.json+bun add -g @zeenie-ai/opencompany+```++`install.sh`, `install.ps1` and the cloud-init templates seed that manifest before `bun add -g`, so the installer path never hits this. For the PATH variant open a new shell, or `export PATH="$HOME/.bun/bin:$PATH"` (`$env:USERPROFILE\.bun\bin` on Windows). Nothing in OpenCompany depends on where the global package lives: `company provision` runs from the shim's own package root, `uninstall.sh` uses `bun remove -g` rather than listing, and the installers address the shim through `bun pm bin -g`.diff --git a/install.ps1 b/install.ps1index 358b31c0..cd50d8e4 100644--- a/install.ps1+++ b/install.ps1@@ -187,6 +187,18 @@ function Main {Info "Installing OpenCompany..."Write-Host ""+ # bun finds its global "project" by walking up from $BUN_INSTALL\install\global+ # until it meets a package.json. A stray package.json or package-lock.json in+ # the user profile (an old npm mishap) therefore hijacks global installs and+ # `bun add -g` fails with "InvalidNPMLockfile" (docs-internal/errors.md #23).+ # Giving the global dir its own manifest stops the walk-up.+ $globalDir = Join-Path $BUN_HOME "install\global"+ New-Item -ItemType Directory -Force -Path $globalDir | Out-Null+ $globalManifest = Join-Path $globalDir "package.json"+ if (-not (Test-Path $globalManifest)) {+ Set-Content -Path $globalManifest -Value '{ "private": true }' -Encoding utf8+ }+# Global install as the current user (bun's global root is user-owned).bun add -g $PKG_NAMEif ($LASTEXITCODE -ne 0) {diff --git a/install.sh b/install.shindex 25245fcf..9210487c 100755--- a/install.sh+++ b/install.sh@@ -174,6 +174,22 @@ install_uv() {fi}+# bun finds its global "project" by walking up from $BUN_INSTALL/install/global+# until it meets a package.json. A stray package.json or package-lock.json in+# $HOME (an old `npm init` / `npm install` run in the home dir) therefore+# hijacks every global install: packages land in $HOME/node_modules and+# `bun add -g` dies with "InvalidNPMLockfile: failed to migrate lockfile"+# (docs-internal/errors.md #23). Giving the global dir its own manifest stops+# the walk-up before it reaches $HOME. Harmless on a clean machine: it is the+# same file bun would create there itself.+seed_bun_global_dir() {+ local global_dir="$BUN_HOME/install/global"+ mkdir -p "$global_dir"+ if [ ! -f "$global_dir/package.json" ]; then+ printf '{\n "private": true\n}\n' > "$global_dir/package.json"+ fi+}+ensure_bun_on_path() {# The bun installer adds ~/.bun/bin to the shell profile; make sure the# `company` shim is reachable from new shells even when bun was already@@ -205,6 +221,7 @@ main() {check_python || install_pythoncheck_uv || install_uvensure_bun_on_path+ seed_bun_global_dirremove_legacy_npm_installs