From ed9a16373129cfb24faf2d60a2a57cd32117e73e Mon Sep 17 00:00:00 2001 From: Koraji95-coder Date: Sun, 24 May 2026 04:32:43 +0000 Subject: [PATCH] feat(start.ps1): expand hermes-agent candidate paths for Windows installers (#2805) Squashed from 3 author commits onto current master (the 3 base commits from already-shipped #2783 were filtered out by the squash): - 6822cbbb feat: expand hermes-agent candidate paths - 6f423538 Copilot review: PathType+null-guard+changelog - dbebbedd handle WOW64 ProgramFiles redirection Authorship preserved. CHANGELOG entry merged into batch stamp commit. --- start.ps1 | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/start.ps1 b/start.ps1 index 191db6c1..af61f14b 100644 --- a/start.ps1 +++ b/start.ps1 @@ -91,23 +91,35 @@ if (-not $Python) { # that's about to crash on missing imports. Smoke-test feedback on # PR #2783: nesquena/hermes-webui requested this guard. $AgentDir = $env:HERMES_WEBUI_AGENT_DIR -if ($AgentDir -and -not (Test-Path (Join-Path $AgentDir 'hermes_cli'))) { +if ($AgentDir -and -not (Test-Path (Join-Path $AgentDir 'hermes_cli') -PathType Container)) { Write-Error "HERMES_WEBUI_AGENT_DIR is set to '$AgentDir' but no hermes_cli/ folder exists there. Unset the variable to fall back to auto-discovery, or fix the path." exit 1 } if (-not $AgentDir) { - $candidates = @( - (Join-Path $env:USERPROFILE '.hermes\hermes-agent'), - (Join-Path (Split-Path -Parent $RepoRoot) 'hermes-agent') - ) + # Build candidate list incrementally — ${env:ProgramFiles(x86)} is null on + # 32-bit Windows and in some constrained environments, and Join-Path throws + # on a null Path. Skip any system-wide root that isn't set so the launcher + # stays robust across Windows variants. USERPROFILE is always set so it + # stays unguarded; the dev-checkout sibling is path-derived, not env-based. + $candidates = @() + $candidates += (Join-Path $env:USERPROFILE '.hermes\hermes-agent') + foreach ($root in @($env:LOCALAPPDATA, ${env:ProgramW6432}, ${env:ProgramFiles}, ${env:ProgramFiles(x86)})) { + if ($root) { $candidates += (Join-Path $root 'hermes\hermes-agent') } + } + $candidates += (Join-Path (Split-Path -Parent $RepoRoot) 'hermes-agent') + # De-dup: when running in a WOW64 (32-bit-on-64-bit) PowerShell process, + # $env:ProgramFiles is redirected to C:\Program Files (x86), so without + # $env:ProgramW6432 (the canonical 64-bit override) we'd miss the real + # C:\Program Files\hermes\hermes-agent AND duplicate the x86 entry. + # Select-Object -Unique collapses any collisions regardless of cause. + $candidates = $candidates | Select-Object -Unique foreach ($c in $candidates) { - if (Test-Path (Join-Path $c 'hermes_cli')) { $AgentDir = $c; break } + if (Test-Path (Join-Path $c 'hermes_cli') -PathType Container) { $AgentDir = $c; break } } } if (-not $AgentDir) { - $expectedPrimary = Join-Path $env:USERPROFILE '.hermes\hermes-agent' - $expectedSibling = Join-Path (Split-Path -Parent $RepoRoot) 'hermes-agent' - Write-Error "hermes-agent not found at $expectedPrimary or $expectedSibling. Set HERMES_WEBUI_AGENT_DIR explicitly." + $searched = $candidates -join ', ' + Write-Error "hermes-agent not found. Searched: $searched. Set HERMES_WEBUI_AGENT_DIR explicitly to override." exit 1 }