fix(coding-agent): handled <bunfs-root>/<binary> in __computeBunfsPackageRoot#3330
Conversation
…ackageRoot Bun 1.3.14 reports `import.meta.dir` as `<bunfs-mount>/<binary-basename>` for the compiled entry on some hosts — e.g. the Homebrew darwin-arm64 build sees `//root/omp-darwin-arm64` instead of the bunfs root alone. The pre-fix path joined `metaDir` with `"packages"` and baked the binary basename into every bunfs path, so the typebox / legacy-pi shim overrides failed `existsSync` validation, `resolveCanonicalPiSpecifier` fell through to a bunfs `Bun.resolveSync` that also could not find the module, and every third-party `@oh-my-pi/pi-*` extension was silently dropped. `__computeBunfsPackageRoot` now detects the trailing binary-basename segment (`path.basename(path.dirname(metaDir)) === "root"`) and strips it off the original `metaDir` via string slicing rather than `path.join`, so Bun's bunfs-native `//root` and `B:\~BUN\root` prefixes survive verbatim (`path.posix.join` would collapse `//root` to `/root`). The single-segment `<bunfs-root>` and deep `<bunfs>/packages/coding-agent/src/extensibility/plugins` paths keep their existing branches. Regression test added in `legacy-pi-bunfs-root.test.ts` for the POSIX `//root/<bin>`, POSIX `/$bunfs/root/<bin>`, and Win32 `<drive>:\~BUN\root\<bin>.exe` shapes. Fixes #3329
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5766952c20
ℹ️ 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".
| } | ||
| const parent = pathImpl.dirname(metaDir); | ||
| if (pathImpl.basename(pathImpl.normalize(parent)) === "root") { | ||
| return `${parent + pathImpl.sep}packages`; |
There was a problem hiding this comment.
Preserve double-slash bunfs paths beyond the root helper
For the //root/<binary> case this line returns //root/packages, but production immediately feeds BUNFS_PACKAGE_ROOT into bunfsPath(), which calls path.join(BUNFS_PACKAGE_ROOT, ...); on POSIX path.join("//root/packages", "coding-agent") normalizes back to /root/packages/coding-agent. That means the Homebrew/Bun 1.3.14 scenario this branch targets still builds shim and package-root override paths outside Bun's //root bunfs mount, so override validation drops them and extension loading continues to fail; the added test only checks the helper return value and misses the joined production paths.
Useful? React with 👍 / 👎.
…brew The reporter clarified that the failing binary is the pre-built `omp-darwin-arm64` release asset from GitHub Releases; Homebrew is only a local-tap wrapper that downloads that asset. The fix already covers every cross-compiled `<bunfs-root>/<binary>` shape, but the source/test docstrings and changelog blurb framed it as a Homebrew-build-specific bug. Updated those three call sites to name the release asset and note the Homebrew tap as a downstream consumer of the same binary; no code change.
`__computeBunfsPackageRoot` now returns `//root/packages` for the Bun 1.3.14 `//root/<binary>` import.meta.dir shape, but production immediately joined that root with shim and package segments through `path.join`, which collapses the POSIX double-slash bunfs mount back to `/root`. That still made override validation miss the embedded shim files. Added a bunfs join helper that preserves the `//root` mount prefix after joining production descendants, wired `bunfsPath` through it, and extended the #3329 regression test to assert the full typebox shim path stays under `//root/packages/...`. Fixes #3329
|
Addressed in
|
Repro
On the Homebrew-installed darwin-arm64 compiled binary (
omp/16.1.15, Bun 1.3.14), Bun reportsimport.meta.diras//root/omp-darwin-arm64for the compiled entry — the bunfs mount root followed by the binary's basename, not the bare bunfs root previous Bun versions emitted. Driving the pre-fix__computeBunfsPackageRootagainst that input produces/root/omp-darwin-arm64/packagesinstead of//root/packages, so the typebox / legacy-pi-ai / legacy-pi-coding-agent shim paths land on/root/omp-darwin-arm64/packages/coding-agent/src/extensibility/*.js(which does not exist in the bunfs). Every override is dropped by__validateLegacyPiPackageRootOverrides,resolveCanonicalPiSpecifierfalls through to a bunfsBun.resolveSyncthat also fails, and every@oh-my-pi/pi-*extension (pi-dynamic-workflows, pi-lens, pi-subagents, …) is silently rejected withCannot find module '@oh-my-pi/pi-coding-agent' from '<plugin>'.Cause
packages/coding-agent/src/extensibility/plugins/legacy-pi-compat.ts__computeBunfsPackageRootonly knew twoimport.meta.dirshapes: the bunfs root (/$bunfs/root/<drive>:\~BUN\root) and the deep plugins source path. The new Bun 1.3.x shape<bunfs-root>/<binary-basename>fell through the suffix branch and intopathImpl.join(metaDir, "packages"), which appended"packages"after the binary segment.A naive fix using
path.joinonpath.dirname(metaDir)also fails on POSIX: Bun's bunfs identifier//rootcollapses to/rootunderpath.posix.join, and Bun's bunfs lookup is keyed on the exact//rootform.Fix
__computeBunfsPackageRootinlegacy-pi-compat.tsthat recognises<bunfs-root>/<binary>by checking whether the normalized parent ends in therootsegment (path.basename(path.normalize(path.dirname(metaDir))) === "root").metaDirviapath.dirname(metaDir) + path.sep + "packages"rather thanpath.join, so the bunfs-native//root/B:\~BUN\rootprefix survives verbatim.import.meta.dirshapes and the reason the strip path avoidspath.join.test/extensibility/legacy-pi-bunfs-root.test.tsfor the POSIX//root/<bin>, POSIX/$bunfs/root/<bin>, and Win32<drive>:\~BUN\root\<bin>.exeinputs, plus the original repro path//root/omp-darwin-arm64 → //root/packagesfrom this issue.[Unreleased] → Fixedinpackages/coding-agent/CHANGELOG.md.Verification
bun test packages/coding-agent/test/extensibility/legacy-pi-bunfs-root.test.ts— 7 pass, 0 fail (the four pre-existing shapes plus the new<bunfs-root>/<binary>case). The pre-publish gate (bun run fix+bun check) ran clean as part ofgh_push_branch. The neighbouringlegacy-pi-ai-type-remap.test.ts/custom-commands/ci-green.test.tsfailures observed locally are pre-existing onmain(missing./tool-views.generated.jsbuild artifact in dev mode) and unrelated to this diff. Fixes #3329.