Commit Graph
1 Commits
Author SHA1 Message Date
yetoneandEdward4226 5b4da5bee3 proc: magpie on Windows finds fnm's node and npx (#2685)
What changed
- fnm puts its Node on a terminal's PATH from the shell profile
  (`fnm env | Invoke-Expression`), never in the registry, so magpie
  started from the Start menu had no node: a Library MCP server run by
  bare npx was "notfound", and one run by npx.cmd's full path (the
  reporter's C:\Users\...\fnm\aliases\default\npx.cmd, alone or under
  `cmd /c`) exited 1 with cmd's "'node' is not recognized", since the
  package npx fetched runs node by name.
- Windows UserPath (no-op before) adds the folder fnm's default alias
  names, after what PATH has. UserBinDirs (FindTool) gets each fnm
  Node: the default alias first, then installations newest by number.
- fnm's Windows layout, checked against Schniz/fnm master (config.rs,
  directories.rs, version.rs, fs.rs, commands/env.rs): root FNM_DIR,
  else etcetera's Windows data_dir\fnm (home\AppData\Roaming, APPDATA),
  else legacy ~\.fnm; versions in node-versions\<v>\installation with
  node.exe/npx.cmd directly in it (no bin on Windows); aliases\default
  a junction to an installation folder; the "system" alias points at
  Z:\_fnm_\..., read as none. XDG vars on Windows only move fnm's
  multishell links, not its versions. LOCALAPPDATA isn't used for them.
- The shared node-version helpers (nodeVersions, parseNodeVersion,
  nodeVersionLess, isDir) and addPath moved from the !windows files to
  nodever.go unchanged; fnmWin* there take home/APPDATA/FNM_DIR as
  arguments so the tests run them on every OS.
- The Library check (checkStdioAt, this machine only) starts a bare
  command PATH lacks from where proc.FindTool finds it and puts that
  folder on the child's PATH (stdioProgram, withPath), as the owner's
  plan on the issue said. Docs: agent-wiring.md, library.md.

Run
- macOS: go test -count=1 ./internal/proc/ ./internal/library/ ok
  (TestNoCommandBypassesProc and the other proc guards included);
  gofmt -l clean; go vet GOOS=windows/darwin for proc, library, cli,
  daemon; GOOS=linux vet proc, library and (-tags nogui) cli, daemon;
  GOOS=windows test binaries for proc and library build.
- Windows box (Win 11 x64), cross-compiled amd64 test binaries:
  TestUserPathFnmNode (real junction via mklink /J, npx.cmd that runs
  node by name) red on origin/main 4a1cd7765's code ("PATH after
  UserPath = [C:\windows\System32], want fnm's default alias"), green
  here; TestFnmWin* green.
- Real fnm 1.39.0 + Node v24.22.1 installed into a sandbox
  (USERPROFILE/APPDATA under C:\Users\yeton\fnm-2685, no FNM_DIR,
  registry PATH without node). A throwaway probe calling UserPath then
  library.CheckServer on chrome-devtools-mcp@latest:
  4a1cd7765: npx -> notfound; ...\aliases\default\npx.cmd -> exited 1;
  cmd /c ...npx.cmd -> exited 1 (the reporter's case).
  This commit: all three ok, 32 tools.
- Broken by hand: stdioProgram without FindTool ->
  TestStdioProgramFindsWhatPathLacks red; fnmWinBins without the
  default alias -> TestFnmWinBins red; Windows UserPath as before ->
  TestUserPathFnmNode red (above).
- Windows full proc/library binaries: TestNoCommandBypassesProc,
  TestGoneAgentListedToTakeOut, TestCheckMixedServerEachSide,
  TestCheckKeepsToolNames and TestRTKNoHookIssuesAreEachAgents fail
  the same with 4a1cd7765's binaries run the same way; the guard and
  two of them read the source tree, which a binary run outside a
  checkout doesn't have; the other two are in #1827.

Not tried
- The desktop GUI on Windows with the reporter's fnm (the probe runs
  the same UserPath and CheckServer calls the app does).
- magpie serve/web/tui on Windows don't call UserPath (as on macOS), so
  there an absolute npx.cmd still lacks node on PATH; a bare npx is
  covered by the check's FindTool.
- Agents magpie starts get the new PATH only from the GUI/daemon.

Refs #2685

Co-authored-by: Edward4226 <234070868+Edward4226@users.noreply.github.com>
2026-10-27 06:45:37 +08:00