# Served by getjack.dev; resolve the release when the installer runs. & { $ErrorActionPreference = 'Stop' $architecture = $env:PROCESSOR_ARCHITECTURE if ($env:PROCESSOR_ARCHITEW6432) { $architecture = $env:PROCESSOR_ARCHITEW6432 } if ($env:OS -ne 'Windows_NT' -or $architecture -ne 'AMD64') { throw 'Unsupported platform. Jack supports Windows x64.' } # Windows PowerShell 5.1 may otherwise default to older TLS versions. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $origin = 'https://dl.getjack.dev/runtime' try { $release = (Invoke-WebRequest -UseBasicParsing -Uri "$origin/latest.json").Content | ConvertFrom-Json $version = $release.version $sums = $release.sha256sums } catch { # Only a not-yet-published pointer permits the legacy endpoint fallback. if (-not $_.Exception.Response -or [int]$_.Exception.Response.StatusCode -ne 404) { throw } $versions = (Invoke-WebRequest -UseBasicParsing -Uri 'https://getjack.dev/version.json').Content | ConvertFrom-Json $version = $versions.runtime.latest.latest $sums = "v$version/SHA256SUMS" } if ($version -isnot [string] -or $version -cnotmatch '\A(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\z') { throw 'Invalid Runtime release version.' } if ($version -eq '0.0.0') { throw 'Jack Runtime has no release yet. Please try again after release.' } if ($sums -isnot [string] -or $sums -cne "v$version/SHA256SUMS") { throw 'Invalid release checksum path.' } function New-PrivateDirectory([string]$Path) { $sid = [Security.Principal.WindowsIdentity]::GetCurrent().User $acl = New-Object Security.AccessControl.DirectorySecurity $acl.SetAccessRuleProtection($true, $false) $rule = New-Object Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow') $acl.AddAccessRule($rule) # An existing folder gets only its access rules: Set-Acl in Windows PowerShell 5.1 also writes # the audit rules (SeSecurityPrivilege) and a new owner needs SeRestorePrivilege. if ((Test-Path -LiteralPath $Path) -and $PSVersionTable.PSEdition -eq 'Core') { [IO.FileSystemAclExtensions]::SetAccessControl([IO.DirectoryInfo]::new($Path), $acl) return } if (Test-Path -LiteralPath $Path) { (Get-Item -LiteralPath $Path -Force).SetAccessControl($acl) return } $acl.SetOwner($sid) if ($PSVersionTable.PSEdition -eq 'Core') { $null = [IO.FileSystemAclExtensions]::CreateDirectory($acl, $Path) } else { $null = [IO.Directory]::CreateDirectory($Path, $acl) } } # Match the Runtime's HOME, USERPROFILE, system-home resolution. $jackHome = $env:HOME if (-not $jackHome -or $jackHome -eq 'undefined') { $jackHome = $env:USERPROFILE } if (-not $jackHome -or $jackHome -eq 'undefined') { $jackHome = [Environment]::GetFolderPath('UserProfile') } $runtime = Join-Path $jackHome '.jack' $bin = Join-Path $runtime 'bin' New-PrivateDirectory $runtime New-PrivateDirectory $bin $staging = Join-Path $bin ('.install.' + [Guid]::NewGuid().ToString('N')) $null = New-Item -ItemType Directory -Path $staging try { $asset = 'jack-windows-x64.zip' $sdk = 'sdk-win32-x64' $archive = Join-Path $staging $asset $base = "$origin/v$version" Invoke-WebRequest -UseBasicParsing -Uri "$base/$asset" -OutFile $archive Invoke-WebRequest -UseBasicParsing -Uri "$origin/$sums" -OutFile (Join-Path $staging 'SHA256SUMS') $checksums = @(Get-Content (Join-Path $staging 'SHA256SUMS') | Where-Object { $_ -match '^([0-9a-fA-F]{64}) jack-windows-x64\.zip$' }) if ($checksums.Count -ne 1) { throw 'Missing or invalid release checksum.' } $expected = $checksums[0].Substring(0, 64) $actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $archive).Hash if ($actual -ne $expected) { throw 'Release checksum mismatch; Jack was not installed.' } # Accept only the Runtime's layout (apps runtime/src/platform/release-archive.ts): # jack.exe and its Cursor SDK helpers, as regular files and directories. Add-Type -AssemblyName System.IO.Compression.FileSystem $prefix = "node_modules/@cursor/$sdk" $zip = [IO.Compression.ZipFile]::OpenRead($archive) try { foreach ($entry in $zip.Entries) { $name = $entry.FullName.TrimEnd('/') $allowed = $name -ceq 'jack.exe' -or $name -ceq 'node_modules' -or $name -ceq 'node_modules/@cursor' -or $name -ceq $prefix -or $name.StartsWith("$prefix/", [StringComparison]::Ordinal) if ($entry.FullName.Contains('\') -or ($name -split '/') -contains '..' -or -not $allowed) { throw 'Unexpected file in the release archive; Jack was not installed.' } # ExternalAttributes needs .NET Framework 4.7.2+; without it this reads 0, and older # .NET never creates links from a zip anyway. $kind = ($entry.ExternalAttributes -shr 16) -band 0xF000 if ($kind -ne 0 -and $kind -ne 0x8000 -and $kind -ne 0x4000) { throw 'The release archive contains links or special files; Jack was not installed.' } } } finally { $zip.Dispose() } $unpacked = Join-Path $staging 'unpacked' [IO.Compression.ZipFile]::ExtractToDirectory($archive, $unpacked) $incoming = Join-Path (Join-Path (Join-Path $unpacked 'node_modules') '@cursor') $sdk foreach ($file in @('jack.exe', "$prefix/package.json", "$prefix/bin/rg.exe", "$prefix/bin/cursorsandbox.exe", "$prefix/vendor/tree-sitter/binding.node", "$prefix/vendor/tree-sitter-bash/binding.node")) { $path = $unpacked foreach ($part in $file.Split('/')) { $path = Join-Path $path $part } if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "The release archive is missing $file; Jack was not installed." } } [IO.File]::WriteAllText((Join-Path $staging 'install.json'), "{`"method`":`"script`"}`n") # Swap the helpers and jack.exe together, as jack upgrade does # (apps runtime/src/platform/release-layout.ts); restore the previous helpers on failure. $cursor = Join-Path (Join-Path $bin 'node_modules') '@cursor' $helpers = Join-Path $cursor $sdk $old = "$helpers.old" $busy = 'Could not replace Jack; the previous install was kept. Stop Jack with jack daemon stop, then run the installer again.' $null = New-Item -ItemType Directory -Force -Path $cursor if (Test-Path -LiteralPath $old) { Remove-Item -LiteralPath $old -Recurse -Force } $previous = Test-Path -LiteralPath $helpers # A running daemon holds its helpers open, so Windows refuses to move the folder. if ($previous) { try { Move-Item -LiteralPath $helpers -Destination $old } catch { throw $busy } } try { Move-Item -LiteralPath $incoming -Destination $helpers Move-Item -LiteralPath (Join-Path $unpacked 'jack.exe') -Destination (Join-Path $bin 'jack.exe') -Force } catch { if (Test-Path -LiteralPath $helpers) { Remove-Item -LiteralPath $helpers -Recurse -Force } if ($previous) { Move-Item -LiteralPath $old -Destination $helpers } throw $busy } if ($previous) { Remove-Item -LiteralPath $old -Recurse -Force } Move-Item -LiteralPath (Join-Path $staging 'install.json') -Destination (Join-Path $runtime 'install.json') -Force Write-Host "Installed Jack Runtime $version to $bin\jack.exe." Write-Host "Add $bin to your user Path in Environment Variables, then open a new terminal." Write-Host 'If the Jack daemon was running, stop it with jack daemon stop and start it again so it uses this version.' } finally { Remove-Item -LiteralPath $staging -Recurse -Force } }