Skip to content

fix: resolve pi binary from node_modules instead of bare PATH lookup#9

Open
minzique wants to merge 1 commit into
rawwerks:masterfrom
minzique:fix/resolve-pi-binary
Open

fix: resolve pi binary from node_modules instead of bare PATH lookup#9
minzique wants to merge 1 commit into
rawwerks:masterfrom
minzique:fix/resolve-pi-binary

Conversation

@minzique

Copy link
Copy Markdown

Problem

Fixes #8

When ypi is installed globally via bun (or pnpm), the pi binary from @mariozechner/pi-coding-agent is not symlinked to the global bin directory. Both ypi and rlm_query call bare pi via exec/command, which either:

  • Fails with pi: not found, or
  • Picks up the wrong pi npm package (a math calculator that name-squats pi on npm)

Changes

ypi

  • Added pi binary resolution block that searches node_modules relative to SCRIPT_DIR (handles both hoisted and nested layouts)
  • Exports YPI_PI_BIN so child processes (rlm_query) inherit the resolved path
  • Clear error message pointing to @mariozechner/pi-coding-agent if pi can't be found
  • Changed exec piexec "$PI_BIN"

rlm_query

  • Added same resolution logic, preferring YPI_PI_BIN env var from parent
  • Changed all 3 bare pi invocations to use "$PI_BIN"

Search order

1. $SCRIPT_DIR/node_modules/.bin/pi          (nested .bin)
2. $SCRIPT_DIR/../.bin/pi                     (hoisted .bin)
3. $SCRIPT_DIR/node_modules/@mariozechner/pi-coding-agent/dist/cli.js  (nested direct)
4. $SCRIPT_DIR/../@mariozechner/pi-coding-agent/dist/cli.js            (hoisted direct)
5. command -v pi                              (PATH fallback)

Testing

Verified resolution against actual bun global install layout:

$ SCRIPT_DIR="/Users/minzi/.bun/install/global/node_modules/ypi"
# Finds: ../@mariozechner/pi-coding-agent/dist/cli.js ✓

No breaking changes — if pi is already on PATH (npm global install, standalone install, or manual PATH setup), the fallback still works.

When ypi is installed globally via bun (or pnpm), transitive dependency
binaries from @mariozechner/pi-coding-agent are NOT symlinked to the
global bin directory. Both `ypi` and `rlm_query` call bare `pi` via
exec/command, which either fails with 'pi: not found' or — worse —
picks up the wrong `pi` npm package (a math pi-number calculator that
squats the name).

This was the exact failure path in practice:
  1. User installs ypi → `pi` binary not on PATH
  2. User runs `bun install -g pi` to fix it → installs wrong package
  3. Wrong `pi` crashes: 'Cannot find module ./pi' (blocked postinstall)

Fix: resolve the pi binary by searching node_modules relative to the
script location (handles both hoisted and nested layouts), then fall
back to PATH. ypi exports YPI_PI_BIN so rlm_query inherits the resolved
path. Both scripts now give a clear error message pointing to the
correct package (@mariozechner/pi-coding-agent) if pi can't be found.
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.

Bug: pi: not found when installed via bun — transitive dep binary not linked

1 participant