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
+32
View File
@@ -56,4 +56,36 @@ if (($userPath -split ';') -notcontains $binDir) {
}
Write-Host "Installed to $dest"
# 5. Warn if a different codegraph earlier on PATH will shadow this install.
# 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). Check both the persisted PATH a
# fresh shell sees (Machine + User) and this session's PATH (catches dirs a
# shell profile injects, e.g. conda / npm).
$expected = Join-Path $binDir 'codegraph.cmd'
function Find-FirstCodegraph([string]$pathStr) {
foreach ($dir in ($pathStr -split ';')) {
if (-not $dir) { continue }
foreach ($leaf in @('codegraph.cmd', 'codegraph.exe', 'codegraph.bat', 'codegraph.ps1')) {
$cand = Join-Path $dir $leaf
if (Test-Path -LiteralPath $cand) { return $cand }
}
}
return $null
}
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'Machine')
$freshPath = ((@($machinePath, [Environment]::GetEnvironmentVariable('Path', 'User')) | Where-Object { $_ }) -join ';')
$shadow = $null
foreach ($winner in @((Find-FirstCodegraph $env:Path), (Find-FirstCodegraph $freshPath))) {
if ($winner -and ($winner -ne $expected)) { $shadow = $winner; break }
}
if ($shadow) {
Write-Warning "Another codegraph is earlier on your PATH and will run instead of this install:"
Write-Warning " $shadow"
Write-Warning " (this install: $expected)"
Write-Warning "If 'codegraph --version' shows an unexpected version, remove the other copy"
Write-Warning "(e.g. 'npm rm -g @colbymchenry/codegraph') or put '$binDir' first on your PATH."
}
Write-Host "Run: codegraph --help"