Skip to content

fix(agents): detect all user-installed CLIs by hydrating PATH from login shell - #843

Merged
nwparker merged 3 commits into
mainfrom
nwparker/open-code-PI
Apr 19, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/open-code-PI

Conversation

@nwparker

@nwparker nwparker commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

GUI-launched Electron on macOS/Linux inherits a minimal launchd PATH that doesn't include whatever the user's shell rc files append — ~/.opencode/bin, ~/.cargo/bin, ~/.vite-plus/bin, nvm shims, pyenv, custom tool dirs. Result: the Agents settings page reports CLIs as "Not installed" even when which resolves them fine from Terminal (see #829 repro with opencode and pi).

This PR replaces a whack-a-mole fix (hardcoding two known install paths) with a generic solution:

  1. Shell PATH hydration (src/main/startup/hydrate-shell-path.ts): on packaged startup (non-Windows), spawn ${SHELL} -ilc 'echo \$PATH' with a 5s timeout, parse the delimited PATH, and prepend new segments to process.env.PATH. Cached once per session.
  2. Hardcoded fallback retained: patchPackagedProcessPath still seeds homebrew/nix/user bin dirs synchronously, so early IPC calls (before the shell spawn completes) aren't empty-handed, and we still resolve something reasonable if the spawn fails.
  3. Refresh button in Settings > Agents: forces a re-probe + re-detect, so users who just installed a new CLI don't need to restart Orca.

Fixes #829

How it handles edge cases

  • Slow rc files (corporate env setup, eager nvm init) — 5s timeout, then fall back to the hardcoded list.
  • Shell spawn error / missing $SHELL — ok: false, nothing merged, detection still runs against existing PATH.
  • Windows — skipped; launchd-style PATH stripping is a POSIX problem and cmd/PowerShell don't accept -ilc.
  • Dev runs — skipped (pnpm dev inherits a full PATH from the launching terminal, no spawn cost needed).
  • Re-running Refresh — forces a fresh shell spawn, merges only new segments (idempotent on PATH).

Test plan

  • `pnpm test src/main/startup/hydrate-shell-path.test.ts src/main/ipc/preflight.test.ts` — new unit tests (10 + 7) cover hydration caching, force-refresh, merge idempotence, and the refresh IPC handler's happy / shell-failed paths.
  • `pnpm test` — 203 files / 2161 tests green.
  • `pnpm typecheck` — clean.
  • Live-verified: running `zsh -ilc 'echo $PATH'` with a minimal launchd-style env returns the user's full rc-augmented PATH (32+ segments including `~/.opencode/bin` and the active nvm node bin where `pi` lives).
  • Manual: packaged macOS build — confirm Agents pane shows OpenCode/Pi as Detected on first open, and Refresh re-detects after a fresh CLI install without restart.

…and ~/.vite-plus/bin

Packaged Electron inherits a minimal PATH without shell rc files, so
agent install-script fallback dirs stay invisible to `which` probes —
the Agents settings page then shows OpenCode/Pi as "Not installed"
even when the user can run them from Terminal.

Add ~/bin, ~/.opencode/bin, and ~/.vite-plus/bin to the packaged PATH
augmentation so preflight detection matches shell behavior.

Fixes #829
…utton

Packaged Electron inherits a minimal launchd PATH that misses whatever
the user's shell rc files append — ~/.opencode/bin, ~/.cargo/bin, nvm
shims, pyenv, custom tool dirs. The preceding commit hardcoded two known
install locations; this replaces that whack-a-mole pattern with a
generic approach.

On packaged startup (non-Windows), spawn `${SHELL} -ilc 'echo $PATH'`
with a 5s timeout, parse the delimited PATH, and prepend any new
segments to process.env.PATH. The result is cached for the app session
so we pay the shell-init cost at most once.

Surface a Refresh button in Settings > Agents that forces a re-probe
and re-detects installed agents — handy right after installing a new
CLI, no restart needed.

Live-verified that a `zsh -ilc` spawn with a minimal launchd-style env
still resolves the user's full PATH (32+ segments including the
rc-appended dirs).
@nwparker nwparker changed the title fix(agents): detect opencode/pi CLIs installed under ~/.opencode/bin and ~/.vite-plus/bin fix(agents): detect all user-installed CLIs by hydrating PATH from login shell Apr 19, 2026
Set preserves insertion order, so PATH first-match-wins semantics are
preserved without manual tracking. Set.prototype.difference (Node 22+)
expresses the new-segments calculation in mergePathSegments as the
set-difference operation it always was.
@nwparker
nwparker merged commit 9d56108 into main Apr 19, 2026
2 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 13, 2026
5 tasks
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…gin shell (stablyai#843)

* fix(agents): detect opencode/pi CLIs installed under ~/.opencode/bin and ~/.vite-plus/bin

Packaged Electron inherits a minimal PATH without shell rc files, so
agent install-script fallback dirs stay invisible to `which` probes —
the Agents settings page then shows OpenCode/Pi as "Not installed"
even when the user can run them from Terminal.

Add ~/bin, ~/.opencode/bin, and ~/.vite-plus/bin to the packaged PATH
augmentation so preflight detection matches shell behavior.

Fixes stablyai#829

* feat(agents): hydrate PATH from user's login shell + Agents Refresh button

Packaged Electron inherits a minimal launchd PATH that misses whatever
the user's shell rc files append — ~/.opencode/bin, ~/.cargo/bin, nvm
shims, pyenv, custom tool dirs. The preceding commit hardcoded two known
install locations; this replaces that whack-a-mole pattern with a
generic approach.

On packaged startup (non-Windows), spawn `${SHELL} -ilc 'echo $PATH'`
with a 5s timeout, parse the delimited PATH, and prepend any new
segments to process.env.PATH. The result is cached for the app session
so we pay the shell-init cost at most once.

Surface a Refresh button in Settings > Agents that forces a re-probe
and re-detects installed agents — handy right after installing a new
CLI, no restart needed.

Live-verified that a `zsh -ilc` spawn with a minimal launchd-style env
still resolves the user's full PATH (32+ segments including the
rc-appended dirs).

* refactor(hydrate-shell-path): simplify dedup with Set + Set.difference

Set preserves insertion order, so PATH first-match-wins semantics are
preserved without manual tracking. Set.prototype.difference (Node 22+)
expresses the new-segments calculation in mergePathSegments as the
set-difference operation it always was.
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]: OpenCode and PI CLI not detected

1 participant