fix(windows): SSH ControlMaster gating + stop hijacking the user's python (#84452)

* fix(windows): SSH ControlMaster gating + stop hijacking the user's python

Two Windows environment-integrity fixes:

1. tools/environments/ssh.py (#73927): Windows OpenSSH has no
   Unix-domain-socket ControlMaster support, so unconditionally passing
   ControlPath/ControlMaster/ControlPersist failed EVERY tool call on a
   Windows-hosted ssh terminal backend with 'getsockname failed: Not a
   socket'. Gate the three multiplexing options behind a module-level
   _SSH_MULTIPLEX = (os.name != 'nt'); the scp upload path is gated the
   same way. On Windows the backend now works without connection pooling
   (each command a fresh connection); POSIX behavior is unchanged. The
   teardown 'ssh -O exit' is naturally inert because the socket never
   exists on Windows.

2. scripts/install.ps1 (#83797): the installer put the whole
   venv\Scripts directory on the user PATH, which contains python.exe /
   pythonw.exe / pip.exe and so silently hijacked the 'python' command in
   every terminal on the machine — unrelated projects started resolving
   python to Hermes' runtime interpreter. Now copy only the launchers
   (hermes.exe, hermes-acp.exe) into a dedicated $InstallDir\bin and put
   THAT on PATH. Existing installs are migrated: the legacy venv\Scripts
   entry is stripped from the user PATH on the next install/update. The
   new bin dir is under $InstallDir (…\hermes-agent), which the uninstall
   PATH sweep already matches via its \hermes-agent marker.

Updated the stale hermes_cli/update_cmd.py docstring that described the
old venv\Scripts-on-PATH layout.

Tests: SSH ControlMaster gating pinned both directions (multiplex on →
flags present; off → absent but BatchMode/StrictHostKeyChecking retained).
install.ps1 parses clean via the PowerShell AST parser.

* docs: update windows-native install docs for the bin\ launcher layout

CI (test_windows_native_docs) pins the docs and installer to the same
PATH layout. The #83797 fix moved the PATH entry from venv\Scripts to a
dedicated $InstallDir\bin holding only the hermes launchers, so update
the Windows-native guide to match: PATH-after-install section, the
install-steps list, the directory-layout table, the Get-Command
verification line, and the 'command not found' pitfall. Test now asserts
the bin\ layout and guards against a regression back to venv\Scripts on
PATH.

* fix: keep install.ps1 pure ASCII (PowerShell 5.1 codepage safety)

The two comments I added in the #83797 PATH-hijack fix used em-dashes,
tripping tests/test_install_ps1_ascii_only.py — Windows PowerShell 5.1
reads a BOM-less .ps1 in the system ANSI codepage (not UTF-8), so a
non-ASCII byte can misdecode into a stray quote and desync the parser
(issues #66994/#67000). Replace the em-dashes with ASCII '--'.
This commit is contained in:
Teknium
2026-08-12 02:56:33 -07:00
committed by GitHub
parent 8d0d908bef
commit f20d16fbf1
6 changed files with 81 additions and 18 deletions
+27 -3
View File
@@ -2715,12 +2715,36 @@ function Set-PathVariable {
if ($NoVenv) {
$hermesBin = "$InstallDir"
} else {
$hermesBin = "$InstallDir\venv\Scripts"
# Expose ONLY the hermes launchers on PATH -- never the whole
# venv\Scripts directory. venv\Scripts contains python.exe /
# pythonw.exe / pip.exe, and putting it on the user PATH silently
# hijacks the `python` command in every terminal on the machine
# (#83797): unrelated projects start resolving python to Hermes'
# runtime interpreter. A dedicated bin dir with copies of the
# launcher exes keeps `hermes` globally available without
# shadowing anything. (Launcher exes embed the venv interpreter
# path, so they work from any location and survive updates.)
$hermesBin = "$InstallDir\bin"
New-Item -ItemType Directory -Force -Path $hermesBin | Out-Null
foreach ($launcher in @("hermes.exe", "hermes-acp.exe")) {
$src = "$InstallDir\venv\Scripts\$launcher"
if (Test-Path $src) {
Copy-Item -Force $src "$hermesBin\$launcher"
}
}
}
# Add the venv Scripts dir to user PATH so hermes is globally available
# On Windows, the hermes.exe in venv\Scripts\ has the venv Python baked in
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
# Migrate installs that got venv\Scripts onto PATH from earlier
# installer versions -- remove it so the python shadowing stops.
$legacyBin = "$InstallDir\venv\Scripts"
if ((-not $NoVenv) -and $currentPath -like "*$legacyBin*") {
$cleaned = ($currentPath -split ';' | Where-Object { $_ -and $_ -ne $legacyBin }) -join ';'
[Environment]::SetEnvironmentVariable("Path", $cleaned, "User")
$currentPath = $cleaned
Write-Info "Removed legacy venv\Scripts from user PATH (kept hermes via $hermesBin)"
}
if ($currentPath -notlike "*$hermesBin*") {
[Environment]::SetEnvironmentVariable(