fix(install): warn when another codegraph on PATH shadows the new install (#1071) (#1072)

The standalone installers report installing the latest version while
`codegraph --version` can keep printing an old one. This is not a packaging
bug: the released bundle's version is correct, but a *different* codegraph
earlier on PATH runs instead — most often a stale
`npm i -g @colbymchenry/codegraph`, whose shim execs its own version-pinned
per-platform bundle, so it reports that old version forever and shadows the
freshly-installed standalone bundle.

install.sh and install.ps1 now detect this at install time and point at the
shadowing copy with how to fix it (remove the other install, or reorder PATH).
install.ps1 checks both the persisted PATH a fresh shell sees (Machine + User)
and the live session PATH, to catch dirs a shell profile injects (conda/npm).

Validated end-to-end on real substrate: install.sh in Docker (linux-arm64,
dash + `set -eu`) and install.ps1 on a Windows 11 PowerShell 5.1 VM
(win32-arm64) — each really downloads the bundle, wires PATH, and fires the
warning, with PATH-resolved `--version` showing the old shadow while the fresh
bundle reports the new version.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-06-29 21:42:58 -05:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 236fb10d62
commit 7e3da77f21
3 changed files with 66 additions and 8 deletions
+33 -8
View File
@@ -83,13 +83,38 @@ ln -sfn "$dest" "$INSTALL_DIR/current"
echo "Installed to $dest"
echo "Linked $BIN_DIR/codegraph"
case ":$PATH:" in
*":$BIN_DIR:"*) ;;
*)
echo ""
echo "$BIN_DIR is not on your PATH. Add it:"
echo " export PATH=\"$BIN_DIR:\$PATH\""
;;
esac
# 5. PATH sanity. Two ways this install can fail to be the codegraph that runs:
# 1. $BIN_DIR isn't on PATH at all.
# 2. A *different* codegraph sits earlier on PATH and shadows ours — most
# often a stale `npm i -g @colbymchenry/codegraph`, whose launcher keeps
# running its own version-pinned bundle, so `codegraph --version` disagrees
# with what we just installed (issue #1071).
# Walk PATH once: note whether $BIN_DIR is present and which codegraph wins.
on_path=0
winner=""
oldifs="$IFS"; IFS=:
for dir in $PATH; do
[ -n "$dir" ] || continue
if [ "$dir" = "$BIN_DIR" ]; then on_path=1; fi
if [ -z "$winner" ] && [ -x "$dir/codegraph" ] && [ ! -d "$dir/codegraph" ]; then
winner="$dir/codegraph"
fi
done
IFS="$oldifs"
if [ "$on_path" -eq 0 ]; then
echo ""
echo "$BIN_DIR is not on your PATH. Add it:"
echo " export PATH=\"$BIN_DIR:\$PATH\""
elif [ -n "$winner" ] && [ "$winner" != "$BIN_DIR/codegraph" ]; then
echo ""
echo "Warning: another codegraph is earlier on your PATH and will run instead:"
echo " $winner"
echo " (this install: $BIN_DIR/codegraph)"
echo "If 'codegraph --version' shows an unexpected version, remove the other copy"
echo "(e.g. 'npm rm -g @colbymchenry/codegraph') or put $BIN_DIR first on PATH."
fi
echo ""
echo "Done. Run: codegraph --help"