fix: discover mise-managed Node and Pi binaries #2

Merged
BlackHatMagic merged 2 commits from fix/mise-node into master 2026-10-23 09:41:09 +00:00

PR Type Selection

  • 🐛 Bug Fix - Fixing incorrect behavior

Problem

On a laptop where Node is installed with mise and Obsidian is launched from the desktop, Pi Chat reported that Pi could not run because node was not found. The plugin found a Pi install or shim, but the GUI session had no mise-activated shell PATH, so Pi's exec node failed.

Root Cause Analysis

  • Symptom: Pi fails to start from Obsidian with a Node/"not found" error; the same Pi works in a terminal.
  • Root cause: piSearchPath() only appended mise shims to the inherited PATH. A shim is not an actual Node binary, and a GUI-launched Obsidian may not have a mise config active for the vault working directory. Pi's npm bin script runs exec node, which therefore had no executable to find.
  • Why now / trigger: Obsidian launched from the desktop instead of a shell where mise has already activated Node; most likely on a second machine/vault.

Fix Description

  • Scan mise data directories (MISE_DATA_DIR, XDG_DATA_HOME, ~/.local/share/mise, macOS Application Support, Windows LocalAppData/AppData) for:
    • actual installs/node/<version>/bin/node binaries;
    • global npm pi bins under those Node versions;
    • versioned installs/npm-*-pi-coding-agent/<version>/node_modules/.bin/pi bins, not only a latest symlink;
    • Pi's cli.js entry point as a fallback.
  • Put discovered Node and Pi bin directories ahead of mise shims in the child PATH.
  • If only a Pi CLI entry point is found, launch it with the discovered Node directly.
  • Keep explicit settings and PI_OBSIDIAN_PI as hard overrides.
  • Show the detected Node executable in Settings → Pi Chat diagnostics.

Testing Evidence

  • Added tests: tests/launcher.test.ts now creates a synthetic mise data dir with Node and a versioned Pi npm install, then verifies discovery, PATH ordering, resolvePiLaunch(), and the child environment.
  • bun run check passes: typecheck + 15 tests.
  • bun run build passes.
  • Manual verification: ran the real PiClient smoke test under env -i HOME=... PATH=/usr/local/bin:/usr/bin:/bin; it discovered mise Node, started Pi, hydrated 29 models, and exited cleanly.

Checklist

  • Root cause clearly identified
  • Fix tested and verified
  • No new warnings introduced
  • Docs updated
## PR Type Selection - [x] 🐛 **Bug Fix** - Fixing incorrect behavior ## Problem On a laptop where Node is installed with mise and Obsidian is launched from the desktop, Pi Chat reported that Pi could not run because `node` was not found. The plugin found a Pi install or shim, but the GUI session had no mise-activated shell PATH, so Pi's `exec node` failed. ## Root Cause Analysis - **Symptom:** Pi fails to start from Obsidian with a Node/"not found" error; the same Pi works in a terminal. - **Root cause:** `piSearchPath()` only appended mise *shims* to the inherited PATH. A shim is not an actual Node binary, and a GUI-launched Obsidian may not have a mise config active for the vault working directory. Pi's npm bin script runs `exec node`, which therefore had no executable to find. - **Why now / trigger:** Obsidian launched from the desktop instead of a shell where mise has already activated Node; most likely on a second machine/vault. ## Fix Description - Scan mise data directories (`MISE_DATA_DIR`, `XDG_DATA_HOME`, `~/.local/share/mise`, macOS Application Support, Windows LocalAppData/AppData) for: - actual `installs/node/<version>/bin/node` binaries; - global npm `pi` bins under those Node versions; - versioned `installs/npm-*-pi-coding-agent/<version>/node_modules/.bin/pi` bins, not only a `latest` symlink; - Pi's `cli.js` entry point as a fallback. - Put discovered Node and Pi bin directories ahead of mise shims in the child PATH. - If only a Pi CLI entry point is found, launch it with the discovered Node directly. - Keep explicit settings and `PI_OBSIDIAN_PI` as hard overrides. - Show the detected Node executable in Settings → Pi Chat diagnostics. ## Testing Evidence - Added tests: `tests/launcher.test.ts` now creates a synthetic mise data dir with Node and a versioned Pi npm install, then verifies discovery, PATH ordering, `resolvePiLaunch()`, and the child environment. - `bun run check` passes: typecheck + 15 tests. - `bun run build` passes. - Manual verification: ran the real `PiClient` smoke test under `env -i HOME=... PATH=/usr/local/bin:/usr/bin:/bin`; it discovered mise Node, started Pi, hydrated 29 models, and exited cleanly. ## Checklist - [x] Root cause clearly identified - [x] Fix tested and verified - [x] No new warnings introduced - [x] Docs updated
GUI-launched Obsidian may not inherit a mise-activated shell, so the plugin
found a Pi shim but its script failed to resolve node. Scan mise data
directories for real Node and Pi installs, put those bins ahead of shims in
the child PATH, and fall back to running Pi's CLI with the discovered Node.
Show the detected Node path in settings diagnostics.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] Discovered mise Node shadows working inherited Node — src/launcher.ts:178

Merged three candidate reviews of mise Node/Pi discovery and PATH wiring; verified ordering change and launch/env callers by read-only inspection without running builds or tests.

Change walkthrough
Area Files Changes
Other code (2) src/launcher.ts, src/settings.ts Discover mise-managed Node/Pi binaries and prefer them in child PATH with cli.js fallback Show discovered Node executable in diagnostics
Documentation (1) README.md Document direct mise binary discovery
Tests (1) tests/launcher.test.ts Cover mise data-dir discovery and PATH ordering

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 4 files, +203/-58.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed ed56bff7ab976d6df7a952f8f8a87c4eec1d85e9 with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:76ca20acc388b783f8dd6e9fede675de4c2934c6b391db7762060186c1fc406a --> ## Pi code review **1 new actionable finding** - **[P2] Discovered mise Node shadows working inherited Node** — `src/launcher.ts:178` Merged three candidate reviews of mise Node/Pi discovery and PATH wiring; verified ordering change and launch/env callers by read-only inspection without running builds or tests. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (2) | `src/launcher.ts`, `src/settings.ts` | Discover mise-managed Node/Pi binaries and prefer them in child PATH with cli.js fallback Show discovered Node executable in diagnostics | | Documentation (1) | `README.md` | Document direct mise binary discovery | | Tests (1) | `tests/launcher.test.ts` | Cover mise data-dir discovery and PATH ordering | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 4 files, +203/-58. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `ed56bff7ab976d6df7a952f8f8a87c4eec1d85e9` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
@ -53,1 +176,3 @@
dirs.push(
const layout = miseLayout(home, env, platform);
const dirs = [
...layout.nodeBins,
Collaborator

[P2] Discovered mise Node shadows working inherited Node

piSearchPath prepends all discovered mise Node/Pi bins ahead of inherited PATH, so a previously working Node/Pi pair can run under an unrelated mise Node version ordered only by latest alias/mtime.

Trigger: Obsidian inherits a working Node/Pi via PATH while mise data dir retains another Node version; no activation needed for it to shadow.

Impact: Pi script resolves exec node to the shadowing version and can fail at startup, leaving chat unavailable with no Pi-path setting to restore prior Node.

Evidence: src/launcher.ts:172-174 prepends layout.nodeBins/piBins before env.PATH; miseLayout collects every installs/node version ordered by newestFirst mtime/latest alias; piEnvironment exports reordered PATH used at src/session.ts:108 into PiClient spawn; configured-path guard selects only Pi command. Base piSearchPath kept inherited PATH first.

**[P2] Discovered mise Node shadows working inherited Node** piSearchPath prepends all discovered mise Node/Pi bins ahead of inherited PATH, so a previously working Node/Pi pair can run under an unrelated mise Node version ordered only by latest alias/mtime. **Trigger:** Obsidian inherits a working Node/Pi via PATH while mise data dir retains another Node version; no activation needed for it to shadow. **Impact:** Pi script resolves exec node to the shadowing version and can fail at startup, leaving chat unavailable with no Pi-path setting to restore prior Node. **Evidence:** src/launcher.ts:172-174 prepends layout.nodeBins/piBins before env.PATH; miseLayout collects every installs/node version ordered by newestFirst mtime/latest alias; piEnvironment exports reordered PATH used at src/session.ts:108 into PiClient spawn; configured-path guard selects only Pi command. Base piSearchPath kept inherited PATH first.
Preserve a working inherited Node/Pi pair, and move mise shim directories
behind discovered real binaries so an unactivated shim cannot shadow them.
Add precedence and shim-shadowing tests.
Code-Reviewer left a comment

Pi code review

0 new actionable findings

No new actionable findings. Previously reported issues, if any, are tracked below.

Earlier findings: 1 rechecked
  • Resolved: Discovered mise Node shadows working inherited Node (src/launcher.ts:178, first reported in review #238) — src/launcher.ts piSearchPath now builds [...inherited, ...layout.nodeBins, ...layout.piBins, ...shimDirs] after filtering shimDirs from inherited, so inherited Node/Pi wins over discovered mise bins.

Merged 3 candidate reviews of mise Node/Pi discovery; verified prior PATH-shadowing defect is fixed in current code. No new evidence-backed defects; checks were read-only without running tests.

Change walkthrough
Area Files Changes
Other code (2) src/launcher.ts, src/settings.ts Discover mise-managed Node and Pi binaries and reorder PATH with Node/CLI fallback Show discovered Node executable in diagnostics
Tests (1) tests/launcher.test.ts Cover mise discovery, precedence, and shim ordering
Documentation (1) README.md Document mise binary discovery and Node diagnostics

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 4 files, +270/-59.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 0cc1d69ef0838c9ef2a0539a7878d5884d0187ec with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:1e71880ed03e1a7c2dd01008641689fe3c15a1eaf682a8e2306058f3e4287fd1 --> ## Pi code review **0 new actionable findings** No new actionable findings. Previously reported issues, if any, are tracked below. <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** Discovered mise Node shadows working inherited Node (`src/launcher.ts:178`, first reported in review #238) — src/launcher.ts piSearchPath now builds [...inherited, ...layout.nodeBins, ...layout.piBins, ...shimDirs] after filtering shimDirs from inherited, so inherited Node/Pi wins over discovered mise bins. </details> Merged 3 candidate reviews of mise Node/Pi discovery; verified prior PATH-shadowing defect is fixed in current code. No new evidence-backed defects; checks were read-only without running tests. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (2) | `src/launcher.ts`, `src/settings.ts` | Discover mise-managed Node and Pi binaries and reorder PATH with Node/CLI fallback Show discovered Node executable in diagnostics | | Tests (1) | `tests/launcher.test.ts` | Cover mise discovery, precedence, and shim ordering | | Documentation (1) | `README.md` | Document mise binary discovery and Node diagnostics | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 4 files, +270/-59. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `0cc1d69ef0838c9ef2a0539a7878d5884d0187ec` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
BlackHatMagic deleted branch fix/mise-node 2026-10-23 09:41:09 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackHatMagic/Pi-Obsidian!2
No description provided.