fix(desktop): find user-installed CLIs when shell probing fails - #9232
CyberStefNef wants to merge 1 commit into
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This focused bug fix adds known POSIX CLI directories only when existing shell and launchctl PATH discovery fails, leaving successful probe paths unchanged. The implementation is small, isolated, and tested, with no schema, deployment, security-sensitive, or static-analysis configuration changes. You can add or adjust custom eligibility rules. Learn more. |
POSIX PATH hydration had no fallback when both the login-shell and launchctl probes returned nothing, so a slow shell profile left the desktop app and the server on the bare Finder PATH and every bare-name CLI spawn failed.
7bd0ba4 to
10ead92
Compare
|
Hit the same bug (Claude Code and OpenCode installed via their native installers, at ~/.local/bin/claude and ~/.opencode/bin/opencode; neither found on PATH) and had built basically this same fix before finding this PR. One directory missing from Separately (more of a discussion than a one-line fix): this only fires via Happy to open a PR adding |
What Changed
resolveKnownPosixCliDirsinpackages/shared/src/shell.tsreturns the standard CLI directories for macOS and Linux, beside the existingresolveKnownWindowsCliDirs. Both POSIX PATH hydration paths now fall back to it when neither the login shell norlaunchctl getenv PATHanswers:installPosixEnvironmentinapps/desktop/src/shell/DesktopShellEnvironment.tsandhydratePosixPathinapps/server/src/os-jank.ts.The fallback is last in the chain, so a shell that did answer still decides the order. Directories are not checked for existence, matching
resolveKnownWindowsCliDirs.Why
A Finder launch starts the app with
/usr/bin:/bin:/usr/sbin:/sbin. Both hydration paths repair that from the login shell, but the probe collapses failures and timeouts into an empty result, so a profile slower than the 5s timeout leaves PATH untouched.launchctl getenv PATHis unset on recent macOS, so the second probe returns nothing either. Every bare-name spawn then fails with ENOENT: #7618 counted 1246 failedghspawns and zero successes over 14 hours, withgh auth statusnever running.#1799 built this chain and added the
launchctlprobe as its last step. This adds the next step, for machines where that probe is also empty. Raising the timeout does not help, since the probe fails for reasons unrelated to how long it is given.Both Windows paths already end in
resolveKnownWindowsCliDirs. POSIX ended in nothing.Closes #7618
Verification
vp test run apps/desktop/src/shell/DesktopShellEnvironment.test.ts packages/shared/src/shell.test.ts apps/server/src/os-jank.test.ts: 54 passed.@t3tools/desktop,@t3tools/shared, and the server.vp linton the five changed files with--report-unused-disable-directives.git diff --check: clean.Checklist
Note
Medium Risk
Changes process
PATHfor all POSIX desktop and server startups when probes fail; behavior shifts from minimal system PATH to hard-coded install locations, which could affect spawn resolution in edge environments but addresses widespread CLI spawn failures.Overview
When login-shell and (on macOS)
launchctlPATH probes return nothing—common for GUI/Finder launches with a minimal PATH—POSIX hydration no longer leaves only/usr/bin:/bin:….Shared: Adds
resolveKnownPosixCliDirs(macOS Homebrew//usr/local/~/.local/bin, Linux Linuxbrew//usr/local/~/.local/bin; skips~/.localifHOMEis blank), mirroring the existing Windows known-CLI helper and without checking that directories exist.Desktop & server:
installPosixEnvironmentandhydratePosixPathuse that list as the last preferred PATH segment before merging with the inherited PATH. Any PATH from the login shell orlaunchctlstill wins and does not inject these defaults.New unit tests cover macOS/Linux fallback merges and assert the known dirs are not added when either probe succeeds.
Reviewed by Cursor Bugbot for commit 10ead92. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add known CLI directory fallback to
hydratePosixPathandinstallPosixEnvironmentresolveKnownPosixCliDirsresolver that returns platform-specific CLI install directories (Homebrew on macOS, Linuxbrew on Linux, plus system-local and HOME-localbin).launchctlproduces a PATH.launchctlremains preferred and is used directly without adding the fallback directories.HOMEis blank or unset.Macroscope summarized 10ead92.