fix(resolve): resolve project-local node_modules/.bin tools (fixes exit 127 for hook-rewritten npx on Windows)#2321
Open
danscMax wants to merge 1 commit into
Conversation
The agent Bash hook rewrites 'npx <tool>' to 'rtk <tool>', dropping the npx launcher. RTK then resolves the tool via which::which, which only searches the system PATH. Project-local JS tools (eslint, vite, vitest, tsc, prettier, playwright) are installed in ./node_modules/.bin and are NOT on PATH, so 'rtk eslint' fails with 'program not found' (exit 127) on Windows even though 'npx eslint' would run fine. npx/npm add node_modules/.bin to PATH at runtime; RTK strips the launcher but never replicated that lookup. Fix resolve_binary to mirror npx resolution: search the nearest node_modules/.bin (cwd walking up to the filesystem root) first, then the inherited PATH, via which::which_in (PATHEXT-aware). tool_exists uses the same resolution so handlers that branch on it detect local tools. Native tools (git, cargo) are unaffected and fall through to PATH; project-local tools now take precedence over a globally-installed shadow. Adds unit tests for local-bin resolution and the not-found path. Verified on Windows against v0.42.3: rtk eslint/vite/vitest and the hook-rewritten 'npx eslint' now exit 0; native git/cargo/npm unaffected; resolution unit tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The agent Bash hook (
rtk hook claude/cursor/gemini/ copilot) rewritesnpx <tool>tortk <tool>, dropping thenpxlauncher. RTK then resolves the tool throughresolve_binary→which::which, which only searches the system PATH.Project-local JS tools —
eslint,vite,vitest,tsc,prettier,playwright, … — are installed in./node_modules/.bin, which is not on the system PATH. So on Windows:…even though
npx eslint --versionruns fine.npx/npmaddnode_modules/.bintoPATHat runtime; RTK strips the launcher during the rewrite but never replicated that lookup. The result: every hook-rewrittennpx <local-tool>invocation fails with exit 127 for locally-installed tooling — the common case, since running not-globally-installed tools is exactly whatnpxis for.Fix
resolve_binarynow mirrors npx's resolution order:node_modules/.bin(cwd walking up to the filesystem root — handles monorepos / nested packages)PATH…via
which::which_in(PATHEXT-aware on Windows; already used in this module's tests).tool_existsuses the same resolution so handlers that branch on it (tsc_cmd,next_cmd,prisma_cmd, …) also detect local tools.git,cargo,npm, etc. aren't innode_modules/.bin, so they fall through to PATH exactly as before — this is an additive change to the search path.playwrighton PATH from another ecosystem), matching npx semantics.The logic is split into a testable
resolve_binary_in(name, cwd, path_var)so resolution can be unit-tested without mutating global process state. Adds tests for local-node_modules/.binresolution and the not-found path.Verification (Windows 11)
rtk eslint --versionv9.39.4, exit 0rtk vite --versionvite/6.4.3, exit 0npx eslint --version(hook-rewritten →rtk eslint)rtk git status/rtk npm run/rtk cargo --versioncargo checkis clean ondevelop; the resolution unit tests pass (cargo test resolve_binary).🤖 Generated with Claude Code