Skip to content

The agent that grows with you

fix(install): resolve 8.3 profile aliases so a built desktop app stops reporting failure

xxxigm9621f903254d
diff --git a/scripts/install.ps1 b/scripts/install.ps1
index fdfdd7aa07c..960e014fc22 100644
--- a/scripts/install.ps1
+++ b/scripts/install.ps1
@@ -43,6 +43,15 @@ param(
[switch]$NonInteractive,
[switch]$Json,
+ # Print the paths this install would use, as JSON, and exit without
+ # touching anything. The first question on any "installer says a path
+ # doesn't exist" report is which paths it actually resolved -- especially
+ # on profiles Windows exposes through an 8.3 alias, where what the user
+ # sees in Explorer and what the installer receives differ.
+ #
+ # powershell -File install.ps1 -ShowResolvedPaths
+ [switch]$ShowResolvedPaths,
+
# --- Ensure mode (dep_ensure.py entry point) ---
[string]$Ensure = "",
[switch]$PostInstall,
@@ -97,45 +106,267 @@ try {
# ============================================================================
# 8.3 short-path normalization
# ============================================================================
-# When the Windows user-profile folder name contains a space (e.g.
-# "First Last"), Windows generates an 8.3 short alias for it (e.g. FIRST~1.LAS)
-# and may expose %TEMP%/%TMP% in that short form:
+# Windows generates an 8.3 short alias for a user-profile folder whose name
+# contains a space ("First Last" -> FIRST~1.LAS), a dot ("Stone.ZEN8" ->
+# STONE~1.ZEN), or an accented character ("Ruben" spelled with an acute e ->
+# RUBN~1). It can then expose %TEMP%, %TMP%, %LOCALAPPDATA%, %APPDATA% and
+# %USERPROFILE% -- plus everything derived from them, including the default
+# HERMES_HOME and InstallDir -- in that short form:
# C:\Users\FIRST~1.LAS\AppData\Local\Temp
-# PowerShell's FileSystem provider mishandles the "~1.ext" component when such a
-# path is handed to a provider cmdlet like `Tee-Object -FilePath` /
-# `Out-File -FilePath`, throwing:
-# "An object at the specified path C:\Users\FIRST~1.LAS does not exist."
-# Every Node/Electron build+install stage streams its log to %TEMP% via
-# Tee-Object, so they all abort with that error, while the Python/uv stages --
-# which never write a side log to %TEMP% through a provider cmdlet -- complete
-# fine. Expanding %TEMP%/%TMP% back to their long form once, up front, lets
-# every downstream cmdlet (and child process) see a path the provider can
-# resolve. (GH: Windows desktop installer fails at Node/Electron stages.)
+#
+# PowerShell's FileSystem provider mishandles the aliased component when such a
+# path reaches a provider cmdlet (`Tee-Object -FilePath`, `Out-File`,
+# `New-Item`, `Test-Path`), throwing "An object at the specified path
+# C:\Users\FIRST~1.LAS does not exist" -- localized on non-English hosts.
+# Every Node/Electron stage streams its build log to %TEMP% via Tee-Object and
+# the desktop stage probes the binary it produced under the profile-derived
+# InstallDir, so the bootstrap aborts even though the artifact built fine.
+# The Python/uv stages, which never hand a %TEMP% path to a provider cmdlet,
+# sail through -- which is why the failure looks Node-specific.
+#
+# Expanding every profile-rooted path back to long form once, up front, lets
+# every downstream cmdlet and child process see something the provider can
+# resolve. Three resolvers, tried in order, because no single one covers every
+# host:
+#
+# 1. kernel32!GetLongPathNameW -- expands any 8.3 component regardless of
+# locale, including the accented-username aliases the COM resolver misses.
+# 2. Scripting.FileSystemObject -- fallback for hosts where P/Invoke is
+# blocked.
+# 3. Profile-root substitution -- when the volume has 8.3 generation disabled
+# or the alias is stale, neither resolver can expand the name because it
+# no longer maps to anything on disk. The aliased component is always the
+# profile folder itself (everything below it was created long), so swap in
+# a profile root we can prove is long and reattach the tail.
+#
+# All three degrade to returning the input untouched, so a host where none of
+# them apply -- including non-Windows -- behaves exactly as it did before.
+
+$script:LongProfileRoot = $null
+
+function Write-PathDiag {
+ # Diagnostics for this block go to stderr, never stdout: the stage protocol
+ # hands drivers a single line of JSON on stdout and a stray note would break
+ # anything parsing it.
+ #
+ # Suppressed entirely under -ShowResolvedPaths, which is a machine-readable
+ # query: Windows PowerShell 5.1 wraps any native-command stderr in a
+ # NativeCommandError and folds it back into the caller's own stream, so a
+ # child writing here at all is enough to corrupt a 5.1 caller's capture.
+ # The JSON already carries everything these lines say.
+ #
+ # [Console]::Error.WriteLine specifically -- verified reaching a caller on a
+ # windows-latest runner. $host.UI.WriteErrorLine was tried and silently
+ # produced nothing there under a non-interactive host.
+ param([string]$Message)
+ if ($ShowResolvedPaths) { return }
+ [Console]::Error.WriteLine("[hermes] $Message")
+}
+
+function Get-LongProfileRoot {
+ # The user's profile directory in long form, or '' when every source we
+ # can reach is itself aliased. Cached: this runs per env var.
+ if ($null -ne $script:LongProfileRoot) { return $script:LongProfileRoot }
+ $script:LongProfileRoot = ''
+
+ # %USERPROFILE% first: it is what the rest of the install derives from, and
+ # on a host handing us aliased paths the .NET known-folder lookup tends to
+ # be aliased in exactly the same way. Then the HOMEDRIVE/HOMEPATH pair, then
+ # the profile's parent (C:\Users never carries an alias) plus %USERNAME%,
+ # which stays the long account name even when every path is short.
+ $envProfile = [Environment]::GetEnvironmentVariable('USERPROFILE')
+ $shellProfile = [Environment]::GetFolderPath('UserProfile')
+ $candidates = @($envProfile, $shellProfile, "$env:HOMEDRIVE$env:HOMEPATH")
+ foreach ($anchor in @($envProfile, $shellProfile)) {
+ if ($anchor -and $env:USERNAME) {
+ $parent = Split-Path -Parent $anchor.TrimEnd('\', '/')
+ if ($parent) { $candidates += (Join-Path $parent $env:USERNAME) }
+ }
+ }
+
+ foreach ($candidate in $candidates) {
+ if ([string]::IsNullOrWhiteSpace($candidate)) { continue }
+ # Trailing separators make Split-Path -Parent return the directory
+ # itself, which would silently break the ancestry check downstream.
+ $candidate = $candidate.TrimEnd('\', '/')
+ if (-not $candidate) { continue }
+ if ($candidate -match '~\d') { continue }
+ try {
+ if (Test-Path -LiteralPath $candidate -PathType Container) {
+ $script:LongProfileRoot = $candidate
+ break
+ }
+ } catch {
+ # Unreadable candidate (denied, malformed): try the next one.
+ }
+ }
+
+ # Say which root we landed on. When someone reports "still broken" this is
+ # the first thing worth knowing, and it costs one line on the rare path
+ # where an alias actually showed up.
+ if ($script:LongProfileRoot) {
+ Write-PathDiag "long profile root: $script:LongProfileRoot"
+ } else {
+ Write-PathDiag "no long profile root found; 8.3 paths left as-is (tried: $($candidates -join ', '))"
+ }
+ return $script:LongProfileRoot
+}
+
+function Expand-ShortProfileRoot {
+ # Rebuild $Path onto a known-long profile root when its aliased component
+ # is the profile folder. Returns $Path unchanged when it isn't, so a custom
+ # TEMP on another volume (D:\SHORT~1\Temp) is never rewritten.
+ param([string]$Path)
+
+ $longRoot = Get-LongProfileRoot
+ if (-not $longRoot) { return $Path }
+ $longRootParent = Split-Path -Parent $longRoot
+ if (-not $longRootParent) { return $Path }
+
+ $node = $Path
+ $tail = ''
+ while ($node -and ($node -match '~\d')) {
+ $leaf = Split-Path -Leaf $node
+ $parent = Split-Path -Parent $node
+ if (-not $parent) { return $Path }
+ if ($leaf -match '~\d') {
+ # Candidate profile folder. Only substitute when it sits in the
+ # same directory as the real profile (both C:\Users).
+ if ($parent -ne $longRootParent) { return $Path }
+ if ($tail) { return (Join-Path $longRoot $tail) }
+ return $longRoot
+ }
+ $tail = if ($tail) { Join-Path $leaf $tail } else { $leaf }
+ $node = $parent
+ }
+ return $Path
+}
function ConvertTo-LongPath {
param([string]$Path)
if ([string]::IsNullOrWhiteSpace($Path)) { return $Path }
- # Only 8.3 short names carry a tilde+digit ("~1"); skip the COM round-trip
- # for ordinary long paths.
+ # Only 8.3 short names carry a tilde+digit ("~1"); skip every resolver for
+ # ordinary long paths, which is the overwhelmingly common case.
if ($Path -notmatch '~\d') { return $Path }
+
+ # 1. kernel32. Compiled on first use only, so a normal profile never pays
+ # the Add-Type cost (this file is re-entered once per install stage).
+ try {
+ if (-not ([System.Management.Automation.PSTypeName]'HermesInstall.LongPath').Type) {
+ Add-Type -Namespace 'HermesInstall' -Name 'LongPath' -MemberDefinition @'
+[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+public static extern int GetLongPathNameW(string lpszShortPath, System.Text.StringBuilder lpszLongPath, int cchBuffer);
+'@
+ }
+ $buffer = New-Object System.Text.StringBuilder 4096
+ $length = [HermesInstall.LongPath]::GetLongPathNameW($Path, $buffer, $buffer.Capacity)
+ if ($length -gt $buffer.Capacity) {
+ $buffer = New-Object System.Text.StringBuilder $length
+ $length = [HermesInstall.LongPath]::GetLongPathNameW($Path, $buffer, $buffer.Capacity)
+ }
+ if ($length -gt 0) {
+ $expanded = $buffer.ToString()
+ if ($expanded -and $expanded -notmatch '~\d') {
+ $script:LastResolver = 'kernel32'
+ return $expanded
+ }
+ }
+ } catch {
+ # Not Windows, or P/Invoke denied by policy: try the next resolver.
+ }
+
+ # 2. COM. Validate the result the same way the kernel32 branch does: this
+ # resolver can report success and still hand back a path that carries the
+ # alias (observed on a windows-latest runner, where it "resolved"
+ # C:\Users\FIRST~1.LAS\... to itself). Accepting that silently is what let a
+ # short path reach the provider cmdlets in the first place, so an
+ # unexpanded result counts as failure and falls through.
try {
$fso = New-Object -ComObject Scripting.FileSystemObject
- if ($fso.FolderExists($Path)) { return $fso.GetFolder($Path).Path }
- if ($fso.FileExists($Path)) { return $fso.GetFile($Path).Path }
+ $resolved = $null
+ if ($fso.FolderExists($Path)) { $resolved = $fso.GetFolder($Path).Path }
+ elseif ($fso.FileExists($Path)) { $resolved = $fso.GetFile($Path).Path }
+ if ($resolved -and $resolved -notmatch '~\d') {
+ $script:LastResolver = 'com'
+ return $resolved
+ }
} catch {
- # COM unavailable / locked-down host: fall back to the original path.
+ # COM unavailable / locked-down host: try the next resolver.
}
- return $Path
+
+ # 3. The alias resolves to nothing. Rebuild from a long profile root.
+ $rebuilt = Expand-ShortProfileRoot $Path
+ $script:LastResolver = if ($rebuilt -ne $Path) { 'profile-root' } else { 'none' }
+ return $rebuilt
}
-foreach ($tmpVar in @('TEMP', 'TMP')) {
- $current = [Environment]::GetEnvironmentVariable($tmpVar)
- if ($current) {
+function Set-LongProfileEnvVars {
+ # Normalize every profile-rooted variable the install reads, not just
+ # %TEMP%: the desktop stage derives InstallDir from %LOCALAPPDATA%, and a
+ # short root there fails the post-build probe after a successful build.
+ # Returns $true when anything was rewritten.
+ $rewrote = $false
+ $script:NormalizedPathRewrites = @{}
+ foreach ($name in @('TEMP', 'TMP', 'LOCALAPPDATA', 'APPDATA', 'USERPROFILE')) {
+ $current = [Environment]::GetEnvironmentVariable($name)
+ if (-not $current) { continue }
$expanded = ConvertTo-LongPath $current
if ($expanded -and $expanded -ne $current) {
- Set-Item -Path "Env:$tmpVar" -Value $expanded
+ Set-Item -Path "Env:$name" -Value $expanded
+ $rewrote = $true
+ $script:NormalizedPathRewrites[$name] = $expanded
+ # Rewriting a profile path is rare and corrective; say so. Every
+ # report of this bug class arrived as a bare "does not exist" with
+ # no hint that a short alias was involved. stderr, so the stage
+ # protocol's stdout JSON stays parseable.
+ Write-PathDiag "expanded 8.3 short path in %$name%: $current -> $expanded"
}
}
+ return $rewrote
+}
+
+$script:NormalizedProfilePaths = Set-LongProfileEnvVars
+
+# Re-derive the install paths now that the env vars behind their defaults are
+# long. An explicitly passed -HermesHome / -InstallDir is normalized in place
+# rather than replaced, so a caller's choice is never overwritten by a default.
+# $PSBoundParameters is only meaningful at script scope, so this stays inline.
+if ($PSBoundParameters.ContainsKey('HermesHome')) {
+ $HermesHome = ConvertTo-LongPath $HermesHome
+} else {
+ $HermesHome = ConvertTo-LongPath $(
+ if ($env:HERMES_HOME) { $env:HERMES_HOME } else { "$env:LOCALAPPDATA\hermes" }
+ )
+}
+if ($PSBoundParameters.ContainsKey('InstallDir')) {
+ $InstallDir = ConvertTo-LongPath $InstallDir
+} else {
+ $InstallDir = ConvertTo-LongPath $(
+ if ($env:HERMES_HOME) { "$env:HERMES_HOME\hermes-agent" } else { "$env:LOCALAPPDATA\hermes\hermes-agent" }
+ )
+}
+if ($script:NormalizedProfilePaths) {
+ # Which paths the install actually settled on. Absent from every report of
+ # this bug class, and the whole question once a short alias is in play.
+ Write-PathDiag "resolved install paths: HermesHome=$HermesHome InstallDir=$InstallDir"
+}
+
+# Captured here, where the values are final, and emitted from the entry-point
+# dispatch at the bottom (alongside -ProtocolVersion / -Manifest) so
+# -ShowResolvedPaths exits before any stage runs.
+#
+# The report goes to STDOUT as JSON: on Windows a child's stderr does not
+# reliably reach a parent process -- three separate capture mechanisms each came
+# back empty on a windows-latest runner while stdout arrived intact -- and the
+# first question on any "installer says a path doesn't exist" report is which
+# paths it actually resolved.
+$script:ResolvedPathReport = @{
+ long_profile_root = (Get-LongProfileRoot)
+ normalized = $script:NormalizedPathRewrites
+ resolver = $script:LastResolver
+ temp = $env:TEMP
+ hermes_home = $HermesHome
+ install_dir = $InstallDir
}
# ============================================================================
@@ -3233,7 +3464,7 @@ function Install-Desktop {
throw "apps/desktop build failed (exit $code)"
}
Write-Success "Desktop app built"
- Remove-Item -Force $buildLog -ErrorAction SilentlyContinue
+ Remove-Item -LiteralPath $buildLog -Force -ErrorAction SilentlyContinue
} catch {
if ($prevEAP) { $ErrorActionPreference = $prevEAP }
Pop-Location
@@ -3955,6 +4186,11 @@ try {
exit 0
}
+ if ($ShowResolvedPaths) {
+ $script:ResolvedPathReport | ConvertTo-Json -Depth 5 -Compress | Write-Output
+ exit 0
+ }
+
if ($Manifest) {
$payload = @{
protocol_version = $InstallStageProtocolVersion