The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge origin/main: reconcile with PR #92092 (in-checkout launcher restore)
emozillafe95ed3930e3
diff --cc hermes_cli/_install_repair.pyindex 05da09b42f9,848d400b0bc..e8f520ef129--- a/hermes_cli/_install_repair.py+++ b/hermes_cli/_install_repair.py@@@ -235,221 -134,37 +236,219 @@@ def ensure_windows_bin_launchersreturn []root = Path(root)- scripts_dir = _venv_scripts_dir(root)- if scripts_dir is None:- raise FileNotFoundError(- f"project venv executable directory not found under: {root}"- )- required_source = scripts_dir / "hermes.exe"- if not required_source.is_file():- raise FileNotFoundError(- f"required Hermes launcher not found: {required_source}"- )- bin_dir = root / "bin"- bin_dir.mkdir(parents=True, exist_ok=True)+ # Per-machine anchor: the DEFAULT Hermes root, not get_hermes_home() —+ # under ``hermes -p <name>`` that returns ``profiles\\<name>``, which+ # would fail the managed-clone gate below and silently skip the heal+ # for profile users. The launcher dir serves the whole machine.+ from hermes_constants import get_default_hermes_root- copied: list[Path] = []- for name in ("hermes.exe", "hermes-acp.exe"):- source = scripts_dir / name- if not source.is_file():- continue- destination = bin_dir / name- if destination.exists():+ try:+ home = Path(get_default_hermes_root())+ except Exception:+ return []++ def _launcher_present(target: Path, name: str) -> bool:+ return (target / f"{name}.exe").exists() or (target / f"{name}.cmd").exists()++ targets: list[Path] = []++ # Canonical target — gate on the managed-clone shape. This runs at+ # every hermes_cli.main process start (right after the profile+ # override), so the healthy path must stay at a couple of stat calls.+ if _normalize_windows_path(root.parent) == _normalize_windows_path(home):+ canonical = home / "bin"+ if any(not _launcher_present(canonical, name) for name in _WINDOWS_BIN_LAUNCHERS):+ targets.append(canonical)++ # Legacy transition target — the pre-migration in-checkout dir. Only+ # re-staged while the user PATH still points at it (consent), compared+ # as normalized literal strings: the installer wrote the long literal+ # path, and realpath'ing arbitrary PATH entries could hang on dead+ # network shares. An entry stored some other way (8.3 short path,+ # subst drive) misses the re-stage, which fails safe: no-op.+ legacy = root / "bin"+ if any(not _launcher_present(legacy, name) for name in _WINDOWS_BIN_LAUNCHERS):+ if user_path_entries is None:+ user_path_entries = _windows_user_path_entries()+ configured = {_normalize_windows_path(entry) for entry in user_path_entries}+ if _normalize_windows_path(legacy) in configured:+ targets.append(legacy)++ if not targets:+ return []++ from hermes_constants import project_venv_dir, venv_bin_dir++ venv_dir = project_venv_dir(root)+ if venv_dir is None:+ return []+ scripts_dir = venv_bin_dir(venv_dir, windows=windows)+ sources = [+ (name, scripts_dir / f"{name}.exe")+ for name in _WINDOWS_BIN_LAUNCHERS+ if (scripts_dir / f"{name}.exe").is_file()+ ]+ if not sources:+ return []+ relocatable = _venv_is_relocatable(venv_dir)+- import shutil-+ restored: list[str] = []+ for target in targets:+ try:+ target.mkdir(parents=True, exist_ok=True)+ except OSError:continue- shutil.copy2(source, destination)- copied.append(destination)+ for name, source in sources:+ if _launcher_present(target, name):+ continue+ final = target / (f"{name}.cmd" if relocatable else f"{name}.exe")+ staging = target / f"{final.name}.heal.{os.getpid()}"+ try:+ if relocatable:+ staging.write_text(+ "@echo off\r\n" f'"{source}" %*\r\n', encoding="ascii"+ )+ else:+ shutil.copy2(source, staging)+ os.replace(staging, final)+ restored.append(str(final))+ except OSError:+ with contextlib.suppress(OSError):+ staging.unlink()+ if restored:+ # Guarded like everything else in this never-raises helper: a+ # closed/broken stderr must not turn a successful heal into a crash.+ with contextlib.suppress(OSError, ValueError):+ print(+ " ✓ Restored hermes launcher(s): " + ", ".join(restored),+ file=sys.stderr,+ )+ return restored- required_destination = bin_dir / "hermes.exe"- if not required_destination.is_file():- raise FileNotFoundError(- f"Hermes launcher was not installed: {required_destination}"- )- return copied++def _read_user_path_raw() -> tuple[list[str], int]:+ """Raw (unexpanded) user PATH entries + registry value type.++ Raw so a rewrite preserves ``%VARS%`` exactly as the user stored them+ (same discipline as ``hermes_cli.uninstall``). Only called on Windows.+ """+ import winreg++ with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment") as key:+ try:+ raw, kind = winreg.QueryValueEx(key, "Path")+ except FileNotFoundError:+ return [], winreg.REG_EXPAND_SZ+ return [entry for entry in str(raw).split(";") if entry], int(kind)+++def _write_user_path_raw(entries: list[str], kind: int) -> None:+ """Write the user PATH back, preserving the registry value type."""+ import winreg++ with winreg.OpenKey(+ winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_READ | winreg.KEY_WRITE+ ) as key:+ winreg.SetValueEx(key, "Path", 0, kind, ";".join(entries))+++def migrate_windows_bin_path(+ root,+ *,+ windows: bool | None = None,+ read_user_path=None,+ write_user_path=None,+) -> bool:+ """One-time PATH migration to the ``HERMES_HOME\\bin`` launcher layout.++ Runs from the ``hermes update`` tail (and mirrors what install.ps1's+ Set-PathVariable does on fresh installs/repairs, which never reach+ existing installs — updates don't run install.ps1):++ 1. stage the launcher copies into the managed binary dir (via+ :func:`ensure_windows_bin_launchers`);+ 2. verify both launchers are present there — otherwise STOP, leaving+ the user PATH untouched (never strip a working entry before its+ replacement is proven);+ 3. ensure the managed binary dir is on the user PATH (prepend);+ 4. strip the legacy entries: ``<root>\\bin`` (in-checkout launcher dir+ the update autostash could sweep) and ``<root>\\venv\\Scripts``+ (shadowed the user's ``python``, #83797).++ The legacy ``<root>\\bin`` FILES are deliberately left in place: editor+ and ACP configs that captured absolute launcher paths keep working+ (the launchers run fine from there — only PATH resolution through a+ dir git could sweep was the bug), and the dir is git-ignored so it+ cannot dirty the tree.++ Registry writes preserve the stored value type and raw ``%VARS%``.+ Never raises; returns True when the canonical layout is in place.++ *read_user_path*/*write_user_path* are injectable for tests.+ """+ if windows is None:+ windows = _is_windows()+ if not windows:+ return False++ root = Path(root)++ # Same per-machine anchor as ensure_windows_bin_launchers (see there).+ from hermes_constants import get_default_hermes_root++ try:+ home = Path(get_default_hermes_root())+ except Exception:+ return False+ if _normalize_windows_path(root.parent) != _normalize_windows_path(home):+ return False # not the managed clone — nothing to migrate++ ensure_windows_bin_launchers(root, windows=windows, user_path_entries=[])++ home_bin = home / "bin"+ if any(+ not ((home_bin / f"{name}.exe").is_file() or (home_bin / f"{name}.cmd").is_file())+ for name in _WINDOWS_BIN_LAUNCHERS+ ):+ return False # staging incomplete — leave the PATH alone++ if read_user_path is None:+ read_user_path = _read_user_path_raw+ if write_user_path is None:+ write_user_path = _write_user_path_raw++ try:+ entries, kind = read_user_path()+ except (OSError, ImportError):+ return False++ legacy_keys = {+ _normalize_windows_path(root / "bin"),+ _normalize_windows_path(root / "venv" / "Scripts"),+ }+ home_bin_key = _normalize_windows_path(home_bin)++ def _entry_key(entry: str) -> str:+ return _normalize_windows_path(os.path.expandvars(entry))++ kept = [e for e in entries if _entry_key(e) not in legacy_keys]+ have_home_bin = any(_entry_key(e) == home_bin_key for e in kept)+ if not have_home_bin:+ kept = [str(home_bin)] + kept++ if kept != entries:+ try:+ write_user_path(kept, kind)+ except (OSError, ImportError):+ return False+ with contextlib.suppress(OSError, ValueError):+ print(+ f" ✓ hermes launchers now resolve from {home_bin} "+ "(legacy PATH entries removed)",+ file=sys.stderr,+ )+ return Truedef _load_console_script_names(root: Path) -> list[str]:diff --cc hermes_cli/update_cmd.pyindex 4fd762c70d5,8bdecc94469..57e65fceed5--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@@ -3195,16 -3429,21 +3424,19 @@@ def _ensure_acp_launcher() -> None(venv wrapper, FHS symlink, pipx/pip console script) without having toreconstruct interpreter/entrypoint paths.- No-op on Windows (install.ps1 copies ``hermes.exe`` + ``hermes-acp.exe``- into ``$InstallDir\bin`` and puts THAT on the user PATH — never the whole- ``venv\Scripts`` dir, which would shadow the user's ``python`` (#83797);- when those copies go missing, ``hermes_cli._install_repair.- ensure_windows_bin_launchers`` re-stages them) and wherever a- ``hermes-acp`` is already present next to the ``hermes`` command.- Unwritable directories (e.g. ``/usr/local/bin`` as non-root) are skipped- silently. Idempotent.- On POSIX, the ACP shim is skipped wherever a ``hermes-acp`` is already- present next to the ``hermes`` command. Unwritable POSIX directories- (e.g. ``/usr/local/bin`` as non-root) are skipped silently. Idempotent.++ No-op on Windows (install.ps1 stages the ``hermes`` / ``hermes-acp``++ launchers into the managed binary dir ``$HermesHome\bin`` and puts THAT++ on the user PATH — never the whole ``venv\Scripts`` dir, which would++ shadow the user's ``python`` (#83797); when those launchers go missing,++ ``hermes_cli._install_repair.ensure_windows_bin_launchers`` re-stages++ them) and wherever a ``hermes-acp`` is already present next to the++ ``hermes`` command. Unwritable directories (e.g. ``/usr/local/bin`` as++ non-root) are skipped silently. Idempotent."""if _m().sys.platform == "win32":- from hermes_cli._install_repair import _sync_windows_cli_launchers-- try:- copied = _sync_windows_cli_launchers(Path(_m().PROJECT_ROOT))- except OSError as exc:- print(f" ⚠ Could not restore Windows command launchers: {exc}")- return- if copied:- names = ", ".join(path.name for path in copied)- print(f" ✓ Restored Windows command launcher(s): {names}")++ # Windows launcher staging/repair lives in _install_repair++ # (ensure_windows_bin_launchers at process start,++ # migrate_windows_bin_path in this command's tail) — not here.returnfor bin_dir in (Path.home() / ".local" / "bin", Path("/usr/local/bin")):hermes_cmd = bin_dir / "hermes"@@@ -6480,9 -7042,8 +7035,10 @@@ def _cmd_update_impl(args, gateway_modeexcept Exception as e:logger.debug("FHS PATH guard check failed: %s", e)- # Self-heal the launchers exposed on PATH: the POSIX hermes-acp shim- # and missing copies in Windows' dedicated bin directory.+ # Self-heal the hermes-acp launcher for installs that predate it, so+ # ACP hosts (Zed, JetBrains, Buzz) can resolve Hermes on PATH without- # a reinstall. No-op on Windows and when already present.++ # a reinstall. No-op on Windows (the launcher migration below owns++ # that) and when already present.try:_ensure_acp_launcher()except Exception as e:diff --cc scripts/ci/test_install_ps1_cli_launchers.ps1index 00000000000,8a449385346..830e68eb1efmode 000000,100644..100644--- a/scripts/ci/test_install_ps1_cli_launchers.ps1+++ b/scripts/ci/test_install_ps1_cli_launchers.ps1@@@ -1,0 -1,115 +1,141 @@@-# Behavioral test for install.ps1's dedicated Hermes launcher directory.++# Behavioral test for install.ps1's hermes launcher staging (PR #92092,++# reworked for the managed-binary-dir layout).+ #+ # Run: powershell.exe -NoProfile -File scripts/ci/test_install_ps1_cli_launchers.ps1+ #+ # The test lifts the real Install-HermesCommandLaunchers function from the+ # PowerShell AST and executes it against a temporary install tree. It never-# reads or changes the user's PATH.++# reads or changes the user's PATH. The staging destination is passed in by++# the caller (Set-PathVariable passes $HermesHome\bin -- the managed binary++# dir OUTSIDE the git checkout); here it is a sibling temp dir, which also++# proves the function stages wherever it is pointed rather than assuming++# the legacy in-checkout location.++ Set-StrictMode -Version Latest+ $ErrorActionPreference = 'Stop'++ $installPs1 = Join-Path (Join-Path $PSScriptRoot '..') 'install.ps1' | Resolve-Path+ $ast = [System.Management.Automation.Language.Parser]::ParseFile(+ $installPs1, [ref]$null, [ref]$null)++ $fn = $ast.Find({+ param($n)+ $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and+ $n.Name -eq 'Install-HermesCommandLaunchers'+ }, $true)++ if (-not $fn) {+ throw "Install-HermesCommandLaunchers not found in $installPs1"+ }++ Invoke-Expression $fn.Extent.Text++ $tempBase = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath())+ $caseRoot = [System.IO.Path]::GetFullPath((Join-Path $tempBase (+ 'hermes-cli-launcher-test-' + [guid]::NewGuid().ToString('N')+ )))+ if (-not $caseRoot.StartsWith($tempBase, [System.StringComparison]::OrdinalIgnoreCase)) {+ throw "Refusing to create test directory outside the system temp directory: $caseRoot"+ }++ $script:Failures = 0++ function Assert-True {+ param([bool]$Condition, [string]$Name)+ if ($Condition) {+ Write-Host " PASS $Name"+ } else {+ Write-Host " FAIL $Name"+ $script:Failures+++ }+ }++ function Assert-BytesEqual {+ param([byte[]]$Expected, [byte[]]$Actual, [string]$Name)+ $same = $Expected.Length -eq $Actual.Length+ if ($same) {+ for ($i = 0; $i -lt $Expected.Length; $i++) {+ if ($Expected[$i] -ne $Actual[$i]) {+ $same = $false+ break+ }+ }+ }+ Assert-True $same $Name+ }++ try {- New-Item -ItemType Directory -Force -Path $caseRoot | Out-Null++ $installRoot = Join-Path $caseRoot 'hermes-agent'++ $binDir = Join-Path $caseRoot 'bin'++ New-Item -ItemType Directory -Force -Path $installRoot | Out-Null+++ # Fail-before-PATH-mutation: a missing required source must throw and++ # must not leave an empty destination for the caller to put on PATH.+ $missingThrew = $false+ try {- Install-HermesCommandLaunchers -Root $caseRoot | Out-Null++ Install-HermesCommandLaunchers -Root $installRoot -Destination $binDir | Out-Null+ } catch {+ $missingThrew = $_.Exception.Message -like '*required launcher not found*'+ }+ Assert-True $missingThrew 'missing hermes.exe fails the launcher stage'- Assert-True (-not (Test-Path -LiteralPath (Join-Path $caseRoot 'bin'))) `++ Assert-True (-not (Test-Path -LiteralPath $binDir)) `+ 'failure does not create an empty PATH directory'+- $scriptsDir = Join-Path $caseRoot 'venv\Scripts'++ $scriptsDir = Join-Path $installRoot 'venv\Scripts'+ New-Item -ItemType Directory -Force -Path $scriptsDir | Out-Null+ $hermesV1 = [byte[]](77, 90, 1)+ $hermesV2 = [byte[]](77, 90, 2)+ $acp = [byte[]](77, 90, 3)+ [System.IO.File]::WriteAllBytes((Join-Path $scriptsDir 'hermes.exe'), $hermesV1)++ Set-Content -Path (Join-Path $installRoot 'venv\pyvenv.cfg') `++ -Value "home = X" -Encoding Ascii+- $binDir = Install-HermesCommandLaunchers -Root $caseRoot++ $staged = Install-HermesCommandLaunchers -Root $installRoot -Destination $binDir++ Assert-True ($staged -eq $binDir) 'returns the destination it staged into'+ Assert-BytesEqual $hermesV1 `+ ([System.IO.File]::ReadAllBytes((Join-Path $binDir 'hermes.exe'))) `- 'required launcher is copied into the dedicated bin directory'++ 'normal venv: exe copy lands in the destination'+ Assert-True (-not (Test-Path -LiteralPath (Join-Path $binDir 'hermes-acp.exe'))) `+ 'optional ACP launcher may be absent'++ [System.IO.File]::WriteAllBytes((Join-Path $scriptsDir 'hermes.exe'), $hermesV2)+ [System.IO.File]::WriteAllBytes((Join-Path $scriptsDir 'hermes-acp.exe'), $acp)- Install-HermesCommandLaunchers -Root $caseRoot | Out-Null++ Install-HermesCommandLaunchers -Root $installRoot -Destination $binDir | Out-Null+ Assert-BytesEqual $hermesV2 `+ ([System.IO.File]::ReadAllBytes((Join-Path $binDir 'hermes.exe'))) `+ 'installer refreshes an existing Hermes launcher'+ Assert-BytesEqual $acp `+ ([System.IO.File]::ReadAllBytes((Join-Path $binDir 'hermes-acp.exe'))) `+ 'installer copies the optional ACP launcher when present'++++ # Relocatable venv: exe trampolines die when copied out of venv\Scripts++ # ('uv trampoline failed to canonicalize script path'), so the stage++ # must emit .cmd delegators and clear the stale exe copies.++ Set-Content -Path (Join-Path $installRoot 'venv\pyvenv.cfg') `++ -Value "home = X`r`nrelocatable = true" -Encoding Ascii++ Install-HermesCommandLaunchers -Root $installRoot -Destination $binDir | Out-Null++ Assert-True (Test-Path -LiteralPath (Join-Path $binDir 'hermes.cmd')) `++ 'relocatable venv: .cmd delegator staged'++ Assert-True (-not (Test-Path -LiteralPath (Join-Path $binDir 'hermes.exe'))) `++ 'relocatable venv: stale exe copy removed'++ $cmdBody = [System.IO.File]::ReadAllText((Join-Path $binDir 'hermes.cmd'))++ Assert-True ($cmdBody.Contains((Join-Path $scriptsDir 'hermes.exe')) -and $cmdBody.Contains('%*')) `++ 'delegator invokes the in-venv exe and forwards args'+ } finally {+ if (Test-Path -LiteralPath $caseRoot) {+ $resolvedCase = [System.IO.Path]::GetFullPath($caseRoot)+ if (-not $resolvedCase.StartsWith($tempBase, [System.StringComparison]::OrdinalIgnoreCase)) {+ throw "Refusing to remove test directory outside the system temp directory: $resolvedCase"+ }+ Remove-Item -LiteralPath $resolvedCase -Recurse -Force+ }+ }++ if ($script:Failures -gt 0) {+ Write-Host ""+ Write-Host "$script:Failures assertion(s) failed"+ exit 1+ }++ Write-Host ""+ Write-Host "all assertions passed"diff --cc scripts/install.ps1index 48dd10e8adc,67f08bcb666..0258b904478--- a/scripts/install.ps1+++ b/scripts/install.ps1@@@ -2977,50 -2977,44 +2977,75 @@@ print(','.join(scripts)Write-Success "All dependencies installed"}+ function Install-HermesCommandLaunchers {+ param(- [Parameter(Mandatory=$true)] [string]$Root++ [Parameter(Mandatory=$true)] [string]$Root,++ [Parameter(Mandatory=$true)] [string]$Destination+ )+- # Expose ONLY the Hermes launchers on PATH -- never the whole- # venv\Scripts directory. Requiring hermes.exe before creating bin keeps- # the PATH stage from reporting success with an unusable command.++ # Expose ONLY the hermes launchers on PATH -- never the whole++ # venv\Scripts directory, which contains python.exe / pip.exe and++ # silently hijacks the `python` command in every terminal (#83797).++ # Requiring hermes.exe before creating the destination keeps the PATH++ # stage from reporting success with an unusable command (PR #92092).+ $scriptsDir = Join-Path $Root "venv\Scripts"+ $requiredSource = Join-Path $scriptsDir "hermes.exe"+ if (-not (Test-Path -LiteralPath $requiredSource -PathType Leaf)) {+ throw "Cannot set up the hermes command: required launcher not found: $requiredSource"+ }+- $hermesBin = Join-Path $Root "bin"- New-Item -ItemType Directory -Force -Path $hermesBin | Out-Null- foreach ($launcher in @("hermes.exe", "hermes-acp.exe")) {- $src = Join-Path $scriptsDir $launcher- if (Test-Path -LiteralPath $src -PathType Leaf) {- Copy-Item -Force -LiteralPath $src -Destination (Join-Path $hermesBin $launcher)++ New-Item -ItemType Directory -Force -Path $Destination | Out-Null++++ # Launcher form depends on the venv (keep in lockstep with++ # hermes_cli/_install_repair.py): a normal venv's exe trampoline++ # embeds an absolute interpreter path and survives copying; a++ # relocatable venv's trampoline (managed_uv rebuilds use++ # --relocatable) resolves relative to its own location, and a copy++ # dies with 'uv trampoline failed to canonicalize script path' --++ # those get a .cmd delegator invoking the in-venv exe instead.++ $pyvenvCfg = Join-Path $Root "venv\pyvenv.cfg"++ $venvRelocatable = $false++ if (Test-Path -LiteralPath $pyvenvCfg) {++ $venvRelocatable = [bool](Select-String -Path $pyvenvCfg -Pattern '^\s*relocatable\s*=\s*true\s*$' -Quiet)++ }++ foreach ($launcher in @("hermes", "hermes-acp")) {++ $src = Join-Path $scriptsDir "$launcher.exe"++ if (-not (Test-Path -LiteralPath $src -PathType Leaf)) { continue }++ if ($venvRelocatable) {++ Remove-Item (Join-Path $Destination "$launcher.exe") -Force -ErrorAction SilentlyContinue++ Set-Content -Path (Join-Path $Destination "$launcher.cmd") -Value "@echo off`r`n`"$src`" %*" -Encoding Ascii++ } else {++ Remove-Item (Join-Path $Destination "$launcher.cmd") -Force -ErrorAction SilentlyContinue++ Copy-Item -Force -LiteralPath $src -Destination (Join-Path $Destination "$launcher.exe")+ }+ }+- $requiredDestination = Join-Path $hermesBin "hermes.exe"- if (-not (Test-Path -LiteralPath $requiredDestination -PathType Leaf)) {- throw "Cannot set up the hermes command: launcher was not installed: $requiredDestination"++ # Verify either staged form before the caller mutates PATH.++ $requiredExe = Join-Path $Destination "hermes.exe"++ $requiredCmd = Join-Path $Destination "hermes.cmd"++ if (-not ((Test-Path -LiteralPath $requiredExe -PathType Leaf) -or++ (Test-Path -LiteralPath $requiredCmd -PathType Leaf))) {++ throw "Cannot set up the hermes command: launcher was not installed: $requiredExe"+ }- return $hermesBin++ return $Destination+ }+function Set-PathVariable {Write-Info "Setting up hermes command..."if ($NoVenv) {$hermesBin = "$InstallDir"} else {- # 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). And never a directory inside the git checkout:- # `hermes update`'s autostash (git stash push --include-untracked)- # deletes untracked files from the working tree, which silently- # removed the launchers an earlier installer staged under- # hermes-agent\bin. $HermesHome\bin is the managed binary dir- # (shared with the managed uv), outside the checkout, where no git- # operation can ever touch it. (Launcher exes embed the venv- # interpreter path, so they work from any location and survive- # updates.)- $hermesBin = "$InstallDir\bin"- Install-HermesCommandLaunchers -Root $InstallDir | Out-Null++ # $HermesHome\bin is the managed binary dir (shared with the managed++ # uv), OUTSIDE the git checkout: `hermes update`'s autostash++ # (git stash push --include-untracked) deletes untracked files from++ # the working tree, which silently removed the launchers an earlier++ # installer staged under hermes-agent\bin. No git operation can ever++ # touch this dir. Staging and verification live in++ # Install-HermesCommandLaunchers, which throws BEFORE any PATH++ # mutation when the launchers cannot be staged.+ $hermesBin = "$HermesHome\bin"- New-Item -ItemType Directory -Force -Path $hermesBin | Out-Null- # Launcher form depends on the venv (keep in lockstep with- # hermes_cli/_install_repair.py): a normal venv's exe trampoline- # embeds an absolute interpreter path and survives copying; a- # relocatable venv's trampoline (managed_uv rebuilds use- # --relocatable) resolves relative to its own location, and a copy- # dies with 'uv trampoline failed to canonicalize script path' --- # those get a .cmd delegator invoking the in-venv exe instead.- $pyvenvCfg = "$InstallDir\venv\pyvenv.cfg"- $venvRelocatable = $false- if (Test-Path $pyvenvCfg) {- $venvRelocatable = [bool](Select-String -Path $pyvenvCfg -Pattern '^\s*relocatable\s*=\s*true\s*$' -Quiet)- }- foreach ($launcher in @("hermes", "hermes-acp")) {- $src = "$InstallDir\venv\Scripts\$launcher.exe"- if (-not (Test-Path $src)) { continue }- if ($venvRelocatable) {- Remove-Item "$hermesBin\$launcher.exe" -Force -ErrorAction SilentlyContinue- Set-Content -Path "$hermesBin\$launcher.cmd" -Value "@echo off`r`n`"$src`" %*" -Encoding Ascii- } else {- Remove-Item "$hermesBin\$launcher.cmd" -Force -ErrorAction SilentlyContinue- Copy-Item -Force $src "$hermesBin\$launcher.exe"- }- }++ Install-HermesCommandLaunchers -Root $InstallDir -Destination $hermesBin | Out-Null}$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")