Skip to content

feat(update): update Bun global installations - #1735

Merged
morluto merged 2 commits into
morluto:mainfrom
xeropresence:feat/update-bun-installs
Oct 11, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
xeropresence:feat/update-bun-installs

Conversation

@xeropresence

Copy link
Copy Markdown
Contributor

Summary

rea update only knew npm global installs. If you installed REA with bun add --global rea-agents on a machine that has Bun but no npm, it stopped right away:

{"status":"failed","currentVersion":"6.4.0","latestVersion":null,"reason":"version-check","remediation":"REA could not resolve the latest release: spawn npm ENOENT..."}

With this PR, rea update recognizes a Bun global installation of the running package. It looks up the latest release with Bun, installs it with Bun into the same global directory, checks the installed entry point's version, and plans integration maintenance the same way it does for npm. npm installations use the same commands and messages as before.

No linked issue. The problem was seen on a Bun-only Windows machine.

Problem and expected behavior

  • Trigger: run rea update from a bun add --global install ($BUN_INSTALL/install/global/node_modules/rea-agents, with ~/.bun as the default BUN_INSTALL).
  • Before: detectNpmInstallation recognizes only npm's global root or a <prefix>/lib/node_modules/rea-agents layout. A Bun install becomes "unknown", so the release lookup falls back to npm view. Without npm, that fails with spawn npm ENOENT. With npm present, the update can only fail with unknown-install-method.
  • Expected: a Bun global install updates itself with Bun, under the same guarantees as npm: exact resolved version, installed into the directory that owns the running package, verified by running that package's entry point, and a maintenance plan that is not applied.

Change and scope

  • Update.ts (workflow): an installation is now NpmInstallation | BunInstallation, with a manager discriminant. installMethod reports "npm", "bun", or "unknown". For Bun, updateInstallCommand returns bun add --global --ignore-scripts rea-agents@<version>. Install and verification remediation messages name the manager and its location; for npm the text is unchanged.
  • UpdateRuntime.ts (system host):
    • bunGlobalDirectory follows Bun's precedence for the global project directory: BUN_INSTALL_GLOBAL_DIR, then $BUN_INSTALL/install/global, then $XDG_CACHE_HOME/.bun/install/global, then ~/.bun/install/global. The home directory comes from the existing homeDirectoryFromEnvironment, so it is USERPROFILE on Windows. I checked each step with throwaway roots under Bun 1.4.2 on Windows.
    • detectBunInstallation matches only when the canonical package root equals <globalDir>/node_modules/rea-agents and <globalDir>/package.json exists. It is location-based, so a Bun global install running under Node is still detected. It runs before npm detection, so Bun installs don't spawn npm. npm detection is unchanged.
    • Release lookup for Bun uses bun info rea-agents dist-tags.latest --json, which honors Bun's registry configuration. Its output (a JSON string) goes through the existing npmReleaseLookup parser.
    • Bun subprocesses (bun info and bun add) run with cwd set to the owning global directory and BUN_INSTALL_GLOBAL_DIR set to that same directory. This plays the role of npm's --prefix. runUpdateCommand got an optional working-directory parameter for this. npm subprocesses keep the caller's working directory and environment as before.
  • Hazard and guard. Under Bun 1.4.2 on Windows, if Bun's global directory has no package.json, bun add --global walks up to the nearest ancestor package.json and installs into that project. I hit this while probing: with BUN_INSTALL pointed at a temp directory under C:\Users\<user>\AppData\Local\Temp, bun add -g [email protected] rewrote C:\Users\<user>\package.json, bun.lock and node_modules (restored right away). Also, bun info refuses to run unless its working directory is inside a project. Guards:
    1. Detection requires <globalDir>/package.json. Without it, the installation is not treated as Bun-owned, so rea update never runs bun add there.
    2. Bun commands run inside the owning global directory with that directory pinned, so the shell's current directory and any project it belongs to are never selected.
  • Not included: Bun global directories set only through bunfig.toml install.globalDir, which REA cannot see without parsing bunfig; layouts where Bun already installed into an ancestor project because of the walk-up above; bunx invocations (still "unknown", as npx is); and the release lookup for unknown installations, which still uses npm as before.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/application/Update.ts (installation model, install command) and src/application/UpdateRuntime.ts (detection and package-manager effects).
  • CLI and MCP/tool-catalog contract: the rea update JSON result can now report installMethod: "bun", with a Bun command. No other fields changed and no MCP tools changed.
  • Provider, bridge, target-format, or platform compatibility: not applicable to providers. Bun global layout detection follows Bun's documented environment variables on every platform. Only Windows x64 was exercised with real Bun.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact: rea update can now spawn bun info and bun add --global --ignore-scripts, always with the owning Bun global directory as cwd and BUN_INSTALL_GLOBAL_DIR. Arguments go through cross-spawn as literals, like the npm path.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: no generated metadata or package changes. Updated README.md (Update section and bug FAQ) and docs/installation.md (update behavior and the "Diagnose, update, and remove" section).

Evidence and regression coverage

  • Tests added or updated:
    • tests/process-global/updateMaintenance.test.ts › "updates a Bun global installation from inside its global project": runs runUpdate with the real systemUpdateHost and real subprocesses. A recording bun executable (bun.cmd on Windows, a shell script elsewhere) on PATH plays the registry and installer. The test checks installMethod: "bun", the exact bun add command, the verified version read back from the package's own scripts/rea.mjs, and that both bun info and bun add ran with cwd and BUN_INSTALL_GLOBAL_DIR equal to the owning global directory. Mutation check: when I removed the working-directory pin, this test failed because the recorded cwd was the repository root.
    • src/application/Update.test.ts: Bun update and current paths through runUpdate; Bun ownership (match, missing global package.json, package roots outside the global project, unresolvable path); bunGlobalDirectory precedence, including Windows USERPROFILE. Existing npm ownership assertions now include manager: "npm".
    • src/application/UpdateRuntime.release.test.ts, src/cliLogging.test.ts: fixtures updated for the manager discriminant.
  • Base reproduction or other evidence: the base failure above was observed on Windows with Bun and no npm. Bun behavior I observed under Bun 1.4.2 on Windows x64, using throwaway roots outside the home tree:
    • bun add -g from a cwd inside an unrelated project with its own package.json left that project untouched.
    • bun add -g with an empty global directory below an ancestor package.json installed into the ancestor (the hazard above).
    • bun info rea-agents dist-tags.latest --json printed "6.4.0" inside the global directory. Outside any project it printed error: Bun could not find a package.json file to install from.
    • BUN_INSTALL_GLOBAL_DIR and XDG_CACHE_HOME were both honored for the global directory.
  • User-visible CLI/MCP output: real end-to-end smoke on Windows x64, Bun 1.4.2, no Node.js or npm.
    1. Created a temp root C:\rea-bun-smoke-<random> (outside the user's home tree), with BUN_INSTALL=<root>\bun and HOME/USERPROFILE=<root>\home. Ran bun add -g [email protected] from <root>.

    2. Overlaid this branch's compiled dist/, scripts/ and package.json onto <root>\bun\install\global\node_modules\rea-agents, then set its package.json version and dist/generatedPackageMetadata.js version to 6.3.0. bun <pkg>\scripts\rea.mjs --version printed 6.3.0.

    3. Created an unrelated project <root>\project\package.json and recorded its hash, plus hashes and mtimes of the real ~/package.json, ~/bun.lock, ~/node_modules/rea-agents, ~/.bun/bin/*, ~/.bun/install/global, and the worktree's git status.

    4. From cwd=<root>\project, ran bun <root>\bun\install\global\node_modules\rea-agents\scripts\rea.mjs update --format json. It exited 0, wrote nothing to stderr, and printed:

      {"status":"updated","previousVersion":"6.3.0","latestVersion":"6.4.0","installedVersion":"6.4.0","installMethod":"bun","command":["bun","add","--global","--ignore-scripts","[email protected]"],"maintenance":{"status":"current","plannedActions":[]},"remediation":"REA is updated. Restart agents running this installation to load the new version."}
    5. Afterwards: <root>\bun\install\global\package.json lists "rea-agents": "6.4.0". The installed package is the registry 6.4.0 (the overlay is gone and generatedPackageMetadata.js says 6.4.0). The regenerated shim <root>\bun\bin\rea.exe --version printed 6.4.0. <root>\project still held only its original package.json with the same hash. The before/after snapshot of everything outside the temp root was identical. I deleted the temp root.

  • Remaining proof gaps: real Bun was exercised only on Windows x64. Linux and macOS Bun global layouts are covered only by the recorder test and bunGlobalDirectory unit cases. The Node-runtime-with-Bun-install combination was not run (Node is not installed here); detection does not depend on the runtime. Bun's walk-up was observed only on Windows. bunfig.toml install.globalDir is not detected.

For evidence-bearing changes: not applicable (no Evidence records change).

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Local validation ran under Bun 1.4.2 on Windows x64 without Node.js or npm, on this commit rebased onto main at e36c82b. CI covers Node.

  • bun --bun run compile and every artifacts:* generator (skills, mcp-catalog, product-catalog, managed-evidence, error-schema): succeeded.
  • bun --bun run test:local -- src/application/Update.test.ts src/application/UpdateRuntime.release.test.ts src/cliLogging.test.ts: 3 files, 50 tests passed.
  • bun --bun node_modules/vitest/vitest.mjs run tests/process-global/updateMaintenance.test.ts: 18 tests passed. Before the rebase, removing the working-directory pin made the new Bun test fail on the recorded cwd; it passed again after restoring the pin.
  • bun --bun node_modules/vitest/vitest.mjs run tests/boundary/cli/cliStartupImports.test.ts (covers the deferred update command loading on main): 2 passed, 3 failed. The same 3 fail on main under Bun: the test records imports through --import hooks from node:module, and under Bun the recorded lists come back empty.
  • bun --bun run typecheck: passed.
  • bun --bun run lint (oxlint plus module-boundary check): exit 0, no warnings in changed files.
  • bun --bun node_modules/.bin/oxfmt --check on LF-normalized copies of all 8 changed files: passed. (The Windows checkout uses CRLF, which oxfmt flags in every file.)
  • bun --bun run docs:check:built: exit 0. The docs:check wrapper could not run because it requires npm's node_modules/.package-lock.json.
  • Real Bun end-to-end smoke as described above, rerun on the rebased commit with the same result: rea update exited 0 with the JSON shown, the global package.json lists rea-agents 6.4.0, the shim prints 6.4.0, the unrelated project was untouched, and the snapshot outside the temp root was identical.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The rea update result type gains installMethod: "bun". npm installs keep the same detection, commands, and message text. NpmInstallation gains a manager: "npm" field; it is internal and not part of the CLI/MCP contract.
  • Real Hopper/Ghidra, browser, or OS coverage: no providers involved. Real Bun on Windows x64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: bun add --global runs with --ignore-scripts. It is confined to the detected Bun global directory by cwd and BUN_INSTALL_GLOBAL_DIR, and it never runs when that directory lacks package.json, which would otherwise let Bun modify an ancestor project such as the user's home directory. The environment override applies only to that child process and is not persisted.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

`rea update` only recognized npm global installations and looked up
releases with `npm view`, so a `bun add --global rea-agents` install on a
machine without npm failed with `spawn npm ENOENT`.

Detect the running package inside Bun's global directory
(BUN_INSTALL_GLOBAL_DIR, $BUN_INSTALL/install/global,
$XDG_CACHE_HOME/.bun/install/global, ~/.bun/install/global), resolve the
latest release with `bun info`, install with
`bun add --global --ignore-scripts`, then verify the installed entry point
and plan integration maintenance exactly as for npm.

Bun commands run inside the owning global directory with
BUN_INSTALL_GLOBAL_DIR pinned, so the caller's current project is never
selected. A global directory without package.json is not treated as an
owned installation: Bun then installs into the nearest ancestor project.
npm installations keep their existing commands and messages.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T10:03:43.859473Z 5963280 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1111b5f2e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/application/UpdateRuntime.ts Resolved
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Great PR! Thanks!

@morluto
morluto merged commit e4027e4 into morluto:main Oct 11, 2026
20 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5963280de9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/application/UpdateRuntime.ts Resolved
@morluto morluto added enhancement New feature or request area: setup Setup, packaging, upgrade, install, Doctor, and client registration labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants