# Fieldkit web web-23cb8ed2f53ceee7. Evaluate: irm https://kit.rockystech.help | iex # This bootstrap deliberately uses PS2 syntax; portable tools are selected by the native launcher. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'Continue' $started = Get-Date $baseUrl = 'https://kit.rockystech.help' $objectsUrl = 'https://fieldkit-obj.rockystech.help' if ($env:FIELDKIT_BASE_URL) { $baseUrl = $env:FIELDKIT_BASE_URL.TrimEnd('/'); $objectsUrl = $baseUrl } if ($env:FIELDKIT_OBJECT_BASE_URL) { $objectsUrl = $env:FIELDKIT_OBJECT_BASE_URL.TrimEnd('/') } $uri = New-Object Uri($baseUrl) if ($uri.Scheme -ne 'https' -and -not ($uri.Scheme -eq 'http' -and $uri.IsLoopback)) { throw 'Fieldkit requires HTTPS; HTTP is allowed only for localhost testing.' } $objectUri = New-Object Uri($objectsUrl) if ($objectUri.Scheme -ne 'https' -and -not ($objectUri.Scheme -eq 'http' -and $objectUri.IsLoopback)) { throw 'Fieldkit objects require HTTPS; HTTP is allowed only for localhost testing.' } $oldTls = [Net.ServicePointManager]::SecurityProtocol $oldConnections = [Net.ServicePointManager]::DefaultConnectionLimit $owned = $false; $mutex = $null; $readyPath = ''; $progressPath = ''; $logPath = '' $jobs = New-Object Collections.ArrayList $jobMap = @{}; $components = @{}; $selectionIssues = @{}; $display = @{lastReport=[DateTime]::MinValue;lastBytes=0L;lastSample=(Get-Date);speed=0.0;stage="Preparing bootstrap"} function Say($Level, $Message) { $line = '[{0}] [{1}] {2}' -f (Get-Date -Format 'HH:mm:ss'), $Level, $Message Write-Host $line if ($logPath) { try { [IO.File]::AppendAllText($logPath, $line + "`r`n") } catch {} } } function Sha($Path) { $stream = [IO.File]::OpenRead($Path); $hash = [Security.Cryptography.SHA256]::Create() try { ([BitConverter]::ToString($hash.ComputeHash($stream))).Replace('-', '').ToLowerInvariant() } finally { $stream.Close(); $hash.Clear() } } function Write-Ready($Path, $Text) { # Publish only a closed, complete file: the child must never see a partial result. $temporary = $Path + '.' + [Guid]::NewGuid().ToString('N') + '.tmp' $backup = $temporary + '.previous' try { [IO.File]::WriteAllText($temporary, $Text) if ([IO.File]::Exists($Path)) { [IO.File]::Replace($temporary, $Path, $backup, $true) } else { [IO.File]::Move($temporary, $Path) } } finally { if ([IO.File]::Exists($temporary)) { [IO.File]::Delete($temporary) } if ([IO.File]::Exists($backup)) { [IO.File]::Delete($backup) } } } function Pulse { $active = @($jobs | Where-Object { $_.Started -and -not $_.Done }) foreach ($job in $jobs) { if ($active.Count -ge 4) { break } if (-not $job.Started) { Say 'DOWNLOAD' ($job.Label + ' <- ' + $job.Url); $job.Start(); $active += $job } } $now = Get-Date; $bytes = 0L; $networkBytes = 0L; $total = 0L; $done = 0 foreach ($job in $jobs) { $bytes += $job.Received; if (-not $job.Cached) { $networkBytes += $job.Received }; $total += $job.Size; if ($job.Done) { $done++ } } $elapsed = ($now - $display.lastSample).TotalSeconds if ($elapsed -ge 1) { $display.speed = [Math]::Max(0, ($networkBytes - $display.lastBytes) / $elapsed / 1MB); $display.lastBytes = $networkBytes; $display.lastSample = $now } $percent = 0; if ($total -gt 0) { $percent = [Math]::Min(100, [int](100 * $bytes / $total)) } $status = '{0}: {1:N1}/{2:N1} MiB ({3}%), {4:N1} MiB/s; {5}/{6} downloads complete' -f $display.stage, ($bytes/1MB), ($total/1MB), $percent, $display.speed, $done, $jobs.Count Write-Progress -Id 42 -Activity 'Fieldkit portable startup' -Status $status -PercentComplete $percent if (($now - $display.lastReport).TotalSeconds -ge 1) { Say 'PROGRESS' $status $details = @($status) foreach ($job in $active) { $details += (' {0}: {1:N1}/{2:N1} MiB; attempt {3}/3' -f $job.Label, ($job.Received/1MB), ($job.Size/1MB), $job.Attempts) } if ($progressPath) { try { [IO.File]::WriteAllText($progressPath, ($details -join "`r`n")) } catch {} } $display.lastReport = $now } } function Queue($Label, $Remote, $Hash, $Size) { if ($jobMap.ContainsKey($Hash)) { return $jobMap[$Hash] } if ($Remote -notmatch '^[A-Za-z0-9/._-]+$' -or $Remote.Contains('..') -or $Hash -notmatch '^[a-f0-9]{64}$') { throw 'Invalid download manifest record.' } $path = Join-Path $downloads ($Hash + '.blob') $job = New-Object FieldkitWebV2_AF173A262BA7.Transfer $job.Label = $Label; $job.Url = $objectsUrl + '/' + $Remote; $job.Path = $path; $job.Expected = $Hash; $job.Size = [long]$Size if ((Test-Path -LiteralPath $path) -and (Sha $path) -eq $Hash) { $job.UseCache(); Say 'CACHE' ('Verified downloaded bytes for ' + $Label) } [void]$jobs.Add($job); $jobMap[$Hash] = $job; return $job } function Wait-Download($Job) { while (-not $Job.Done) { Pulse; Start-Sleep -Milliseconds 200 } if ($Job.Error) { throw ($Job.Label + ': ' + $Job.Error) } return $Job.Path } function Run($Exe, $Arguments, $MaximumSeconds) { $parts = @(); foreach ($value in $Arguments) { $parts += [FieldkitWebV2_AF173A262BA7.Runner]::Quote([string]$value) } $runner = New-Object FieldkitWebV2_AF173A262BA7.Runner; $runner.Start($Exe, ($parts -join ' '), $clientCwd) $deadline = (Get-Date).AddSeconds($MaximumSeconds) try { while (-not $runner.Done) { foreach ($line in $runner.Drain()) { Say 'TOOL' $line } Pulse if ((Get-Date) -gt $deadline) { $runner.Kill(); throw ('Process timed out: ' + $Exe) } Start-Sleep -Milliseconds 200 } foreach ($line in $runner.Drain()) { Say 'TOOL' $line } return $runner.ExitCode } finally { $runner.Dispose() } } function Extract($Archive, $Destination) { $display.stage = 'Extracting ' + [IO.Path]::GetFileName($Destination) Say 'EXTRACT' ($Archive + ' -> ' + $Destination) [IO.Directory]::CreateDirectory($Destination) | Out-Null if ((Run $extractor @('x', $Archive, ('-o'+$Destination), '-y', '-bd', '-bso0', '-bsp0') 600) -ne 0) { throw ('Extraction failed: ' + $Destination) } } function Prepare($Id) { if (-not $components.ContainsKey($Id)) { throw ('Unknown component: ' + $Id) } $component = $components[$Id] if ($component.ready -or $component.job) { return } $marker = Join-Path $component.directory '.fieldkit-complete' $exe = Join-Path $component.directory $component.executable if ((Test-Path -LiteralPath $marker) -and ([IO.File]::ReadAllText($marker) -eq $component.sha256) -and (Test-Path -LiteralPath $exe) -and (Sha $exe) -eq $component.exeSha256) { $component.ready = $true; Say 'CACHE' ('Reusing extracted ' + $Id + '; main executable SHA256 verified.'); return } if (Test-Path -LiteralPath $component.directory) { $saved = $component.directory + '.incomplete-' + [Guid]::NewGuid().ToString('N') [IO.Directory]::Move($component.directory, $saved); Say 'REPAIR' ('Preserved incomplete/corrupt cache at ' + $saved) } $component.job = Queue $Id $component.url $component.sha256 $component.bytes } function Finish($Id) { Prepare $Id; $component = $components[$Id] if (-not $component.ready) { $display.stage = 'Waiting for ' + $Id $archive = Wait-Download $component.job Say 'VERIFY' ($Id + ': complete archive SHA256 passed.') $temporary = $component.directory + '.extract-' + [Guid]::NewGuid().ToString('N') Extract $archive $temporary if ((Sha (Join-Path $temporary $component.executable)) -ne $component.exeSha256) { throw ('Extracted executable SHA256 mismatch: ' + $Id) } [IO.File]::WriteAllText((Join-Path $temporary '.fieldkit-complete'), $component.sha256) [IO.Directory]::Move($temporary, $component.directory); $component.ready = $true Say 'READY' ($Id + ' extracted and cached.') } return $component } function Pick($Kind) { foreach ($entry in @($eligible | Where-Object { $_.kind -eq $Kind })) { try { $component = Finish $entry.component $display.stage = 'Probing ' + $entry.id; Say 'PROBE' ($entry.id + ' from our portable cache') if ((Run $helper ($common + @('--probe-candidate', $entry.id)) 60) -eq 0) { Say 'SELECT' $entry.id; return $entry } Say 'FALLBACK' ($entry.id + ' did not pass its process probe; fetching the next compatible candidate.') $selectionIssues[$Kind] = $entry.id + ' failed its executable probe. See bootstrap log: ' + $logPath } catch { $selectionIssues[$Kind] = $entry.id + ': ' + $_.Exception.Message; Say 'FALLBACK' $selectionIssues[$Kind] } } return $null } try { Say 'START' ('Fieldkit web-23cb8ed2f53ceee7; inspecting this PC and preparing only compatible portable components.') if (-not ('FieldkitWebV2_AF173A262BA7.Transfer' -as [type])) { Say 'PREPARE' 'Loading the portable parallel downloader (no installation).' Add-Type -TypeDefinition @' // C# 2-compatible helpers for Windows PowerShell 2/.NET 2 and newer. // Network and pipe work stays off PowerShell runspaces. No client installation. // Keep these legacy networking APIs: they also work on .NET 2/PowerShell 2. #pragma warning disable using System; using System.IO; using System.Net; using System.Text; using System.Diagnostics; using System.Threading; using System.Collections.Generic; using System.Security.Cryptography; namespace FieldkitWebV2_AF173A262BA7 { public sealed class Transfer { public string Label, Url, Path, Expected, Error; public long Size; public volatile bool Started, Done, Cancelled; public bool Cached; public int Attempts; private long received; private HttpWebRequest request; public long Received { get { return Interlocked.Read(ref received); } } public void UseCache() { Cached = true; Interlocked.Exchange(ref received, Size); Started = true; Done = true; } public void Start() { Started = true; ThreadPool.QueueUserWorkItem(delegate(object unused) { Download(); }); } public void Cancel() { Cancelled = true; try { if (request != null) request.Abort(); } catch {} } private void Download() { string temporary = Path + "." + Guid.NewGuid().ToString("N") + ".partial"; try { for (Attempts = 1; Attempts <= 3 && !Cancelled; Attempts++) { try { Interlocked.Exchange(ref received, 0); request = (HttpWebRequest)WebRequest.Create(Url); request.Timeout = 30000; request.ReadWriteTimeout = 30000; request.UserAgent = "Fieldkit/2"; if (request.Proxy != null) request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream input = response.GetResponseStream()) using (FileStream output = File.Create(temporary)) using (SHA256 hash = SHA256.Create()) { byte[] buffer = new byte[65536]; int count; while ((count = input.Read(buffer, 0, buffer.Length)) != 0) { if (Cancelled) throw new OperationCanceledException(); output.Write(buffer, 0, count); hash.TransformBlock(buffer, 0, count, buffer, 0); Interlocked.Add(ref received, count); } hash.TransformFinalBlock(buffer, 0, 0); string actual = BitConverter.ToString(hash.Hash).Replace("-", "").ToLowerInvariant(); if (actual != Expected || (Size >= 0 && Received != Size)) throw new IOException("Download SHA256 or length mismatch: " + Url); } // Promotion occurs only after the complete stream passed SHA256. if (File.Exists(Path)) File.Delete(Path); File.Move(temporary, Path); return; } catch (Exception error) { if (Cancelled || Attempts == 3) { Error = error.Message; return; } Thread.Sleep(500 * Attempts); } } Error = "Download cancelled"; } finally { try { if (File.Exists(temporary)) File.Delete(temporary); } catch {} Done = true; } } } public sealed class Runner { private Process process; private readonly List lines = new List(); private int readers; public bool Done { get { return process.HasExited && Interlocked.CompareExchange(ref readers, 0, 0) == 0; } } public int ExitCode { get { return process.ExitCode; } } public void Start(string executable, string arguments, string directory) { ProcessStartInfo info = new ProcessStartInfo(executable, arguments); info.WorkingDirectory = directory; info.UseShellExecute = false; info.CreateNoWindow = true; info.RedirectStandardOutput = true; info.RedirectStandardError = true; process = new Process(); process.StartInfo = info; process.Start(); readers = 2; ThreadPool.QueueUserWorkItem(delegate(object unused) { Read(process.StandardOutput); }); ThreadPool.QueueUserWorkItem(delegate(object unused) { Read(process.StandardError); }); } private void Read(StreamReader input) { try { string line; while ((line = input.ReadLine()) != null) lock (lines) { lines.Add(line); } } catch (IOException) { } catch (ObjectDisposedException) { } finally { Interlocked.Decrement(ref readers); } } public string[] Drain() { lock (lines) { string[] result = lines.ToArray(); lines.Clear(); return result; } } public void Kill() { try { if (!process.HasExited) process.Kill(); } catch {} } public void Dispose() { process.Dispose(); } public static string Quote(string value) { StringBuilder result = new StringBuilder("\""); int slashes = 0; foreach (char c in value) { if (c == '\\') { slashes++; continue; } result.Append('\\', c == '"' ? slashes * 2 + 1 : slashes); slashes = 0; result.Append(c); } result.Append('\\', slashes * 2); result.Append('"'); return result.ToString(); } } } '@ } try { [Net.ServicePointManager]::SecurityProtocol = $oldTls -bor 3072 } catch { Say 'INFO' 'TLS1.2 unavailable; trying the existing HTTPS support on this runtime.' } [Net.ServicePointManager]::DefaultConnectionLimit = 8 $clientCwd = (Get-Location).Path $cache = $env:FIELDKIT_CACHE_DIR if (-not $cache) { $cache = $env:LOCALAPPDATA; if (-not $cache) { $cache = [IO.Path]::GetTempPath() }; $cache = Join-Path $cache 'Fieldkit\web' } $cache = [IO.Path]::GetFullPath($cache); $downloads = Join-Path $cache 'downloads' [IO.Directory]::CreateDirectory($downloads) | Out-Null $launch = Join-Path $cache ('launches\' + [Guid]::NewGuid().ToString('N')); [IO.Directory]::CreateDirectory($launch) | Out-Null $logPath = Join-Path $launch 'bootstrap.log'; $progressPath = Join-Path $launch 'progress.txt'; $readyPath = Join-Path $launch 'ready.ini' Say 'INFO' ('Cache: ' + $cache); Say 'INFO' ('Log: ' + $logPath) $keyHash = [Security.Cryptography.SHA256]::Create() try { $key = ([BitConverter]::ToString($keyHash.ComputeHash([Text.Encoding]::UTF8.GetBytes($cache.ToLowerInvariant())))).Replace('-', '') } finally { $keyHash.Clear() } $mutex = New-Object Threading.Mutex($false, ('Local\Fieldkit-Web-' + $key)) $deadline = (Get-Date).AddMinutes(20); $display.stage = 'Waiting for another Fieldkit cache writer' while (-not $owned) { try { $owned = $mutex.WaitOne(0) } catch [Threading.AbandonedMutexException] { $owned = $true } if (-not $owned) { Pulse; if ((Get-Date) -gt $deadline) { throw 'Cache writer wait timed out.' }; Start-Sleep -Milliseconds 200 } } $display.stage = 'Fetching release catalog' $catalogJob = Queue 'release catalog' 'objects/23cb8ed2f53ceee7d845eb48eb5dba1880440d31ff495601c3e5b5528851b9fd.xml' '23cb8ed2f53ceee7d845eb48eb5dba1880440d31ff495601c3e5b5528851b9fd' 15868 $catalogFile = Wait-Download $catalogJob [xml]$catalog = [IO.File]::ReadAllText($catalogFile) if ($catalog.fieldkit.schema -ne '2') { throw 'Unsupported web release catalog.' } $architecture = $env:PROCESSOR_ARCHITEW6432; if (-not $architecture) { $architecture = $env:PROCESSOR_ARCHITECTURE } $arch = 'x86'; if ($architecture -eq 'AMD64') { $arch = 'x64' }; if ($architecture -eq 'ARM64') { $arch = 'arm64' } Say 'DETECT' ('Native architecture: ' + $arch) $native = @($catalog.fieldkit.helpers.helper | Where-Object { $_.arch -eq $arch })[0] $core = $catalog.fieldkit.core; $unzip = $catalog.fieldkit.extractor $coreJob = Queue 'configuration and session scripts' $core.url $core.sha256 $core.bytes $helperJob = Queue ('native '+$arch+' launcher') $native.url $native.sha256 $native.bytes $extractorJob = Queue 'portable extractor' $unzip.url $unzip.sha256 $unzip.bytes $extractor = Wait-Download $extractorJob # Windows executes a PE regardless of extension, but .exe aids diagnostics and compatibility. $extractorExe = Join-Path $downloads ($unzip.sha256 + '.exe'); if (-not (Test-Path -LiteralPath $extractorExe) -or (Sha $extractorExe) -ne $unzip.sha256) { [IO.File]::Copy($extractor, $extractorExe, $true) }; $extractor = $extractorExe if ((Sha $extractor) -ne $unzip.sha256) { throw 'Cached extractor SHA256 mismatch.' } $kit = Join-Path $cache ('kits\' + $core.sha256) $coreGood = Test-Path -LiteralPath (Join-Path $kit '.core-complete') if ($coreGood) { foreach ($file in $core.files.file) { $path = Join-Path $kit $file.path; if (-not (Test-Path -LiteralPath $path) -or (Sha $path) -ne $file.sha256) { $coreGood = $false; break } } } if (-not $coreGood) { if (Test-Path -LiteralPath $kit) { [IO.Directory]::Move($kit, ($kit+'.bad-'+[Guid]::NewGuid().ToString('N'))) } Extract (Wait-Download $coreJob) $kit foreach ($file in $core.files.file) { if ((Sha (Join-Path $kit $file.path)) -ne $file.sha256) { throw ('Core file SHA256 mismatch: ' + $file.path) } } [IO.File]::WriteAllText((Join-Path $kit '.core-complete'), $core.sha256) } else { Say 'CACHE' 'Session scripts and personal configuration passed their SHA256 checks.' } $helper = Join-Path $kit ('launcher\fieldkit-'+$arch+'.exe') $nativeFile = Wait-Download $helperJob if (-not (Test-Path -LiteralPath $helper) -or (Sha $helper) -ne $native.sha256) { [IO.File]::Copy($nativeFile, $helper, $true) } $tools = Join-Path $cache 'tools'; [IO.Directory]::CreateDirectory($tools) | Out-Null foreach ($item in $catalog.fieldkit.components.component) { if ($item.id -notmatch '^[A-Za-z0-9._-]+$' -or $item.sha256 -notmatch '^[a-f0-9]{64}$' -or $item.executable.Contains('..')) { throw 'Invalid component record.' } $components[$item.id] = @{id=[string]$item.id;url=[string]$item.url;sha256=[string]$item.sha256;bytes=[long]$item.bytes;executable=[string]$item.executable;exeSha256=[string]$item.exeSha256;directory=(Join-Path $tools ($item.id+'-'+$item.sha256.Substring(0,16)));ready=$false;job=$null} } $records = @(); $candidateMap = @{} foreach ($item in $catalog.fieldkit.candidates.candidate) { $component = $components[$item.component] $relative = 'tools/' + $component.id + '-' + $component.sha256.Substring(0,16) + '/' + $item.executable $records += (@($item.kind,$item.id,$item.version,$item.arch,$item.major,$item.minor,$item.build,$item.priority,$relative,$item.cpu,$item.status) -join '|') $candidateMap[$item.id] = @{kind=[string]$item.kind;id=[string]$item.id;component=[string]$item.component;executable=[string]$item.executable} } [IO.File]::WriteAllText((Join-Path $kit 'candidates.tsv'), ($records -join "`r`n"), [Text.Encoding]::UTF8) $common = @('--root',$kit,'--tools-root',$tools,'--state-dir',(Join-Path $cache 'state'),'--cwd',$clientCwd) $plan = Join-Path $launch 'plan.tsv'; $display.stage = 'Detecting Windows and CPU capabilities' if ((Run $helper ($common + @('--plan-file',$plan)) 60) -ne 0) { throw 'Native compatibility detection failed.' } $eligible = @(); $desktop = $true foreach ($line in [IO.File]::ReadAllLines($plan)) { $fields = $line.Split('|') if ($fields[0] -eq 'host') { Say 'DETECT' $line; $desktop = $fields[3] -eq 'desktop=1' } elseif ($candidateMap.ContainsKey($fields[1])) { $eligible += $candidateMap[$fields[1]] } } if ($env:FIELDKIT_BOOTSTRAP_HEADLESS -eq '1') { $desktop = $false } # Start exactly the best candidates together; no other architectures or fallback downloads yet. foreach ($kind in @('terminal','shell','opencode','git','psmux')) { if ($kind -eq 'terminal' -and -not $desktop) { continue } $first = @($eligible | Where-Object { $_.kind -eq $kind }) if ($first.Count) { Say 'PLAN' ($kind + ': ' + $first[0].id); Prepare $first[0].component } } $shell = Pick 'shell'; $chosenShellId = 'auto'; if ($shell) { $chosenShellId = $shell.id } else { Say 'FALLBACK' 'No bundled PowerShell passed; using the explicitly located system shell or CMD rescue.' } $shellReason = '' if (-not $shell) { $shellReason = $selectionIssues['shell'] if (-not $shellReason) { $shellReason = 'No bundled PowerShell supports this OS/build. Legacy portable PowerShell requires Windows 7 SP1 (build 7601) or newer; the system shell is retained.' } Say 'FALLBACK' $shellReason } $launchFlags = @('--shell',$chosenShellId,'--web-progress',$progressPath,'--web-ready',$readyPath) if ($shell) { $launchFlags += '--preverified-shell' } if ($env:FIELDKIT_BOOTSTRAP_TEST -eq '1') { $launchFlags += @('--test-session','--no-opencode') } if ($env:FIELDKIT_BOOTSTRAP_DIAGNOSE -eq '1') { $desktop = $false; $launchFlags += '--diagnose' } $terminalStarted = $false if ($desktop) { foreach ($entry in @($eligible | Where-Object { $_.kind -eq 'terminal' })) { try { $null = Finish $entry.component; $display.stage = 'Starting ' + $entry.id Say 'LAUNCH' ($entry.id + ' with ' + $chosenShellId + '; remaining downloads continue in parallel.') if ((Run $helper ($common + $launchFlags + @('--terminal',$entry.id)) 120) -eq 0) { $terminalStarted = $true; break } Say 'FALLBACK' ($entry.id + ' startup handshake failed; fetching the next terminal.') } catch { Say 'FALLBACK' ($entry.id + ': ' + $_.Exception.Message) } } } $opencode = Pick 'opencode'; $git = Pick 'git'; $psmux = Pick 'psmux' $opencodeReason = '' if (-not $opencode) { $openCandidates = @($eligible | Where-Object { $_.kind -eq 'opencode' }) $opencodeReason = 'Bundled OpenCode candidates failed; see bootstrap log: ' + $logPath if (-not $openCandidates.Count) { $opencodeReason = 'No bundled OpenCode supports this OS/CPU. Current Windows OpenCode requires Windows 10 1809+ and a compatible 64-bit CPU. Windows 7 receives the rescue shell.' } Say 'FALLBACK' $opencodeReason } $openPath = ''; $gitPath = ''; $muxPath = '' if ($opencode) { $openPath = Join-Path $components[$opencode.component].directory $opencode.executable } if ($git) { $gitPath = Join-Path $components[$git.component].directory $git.executable } if ($psmux) { $muxPath = Join-Path $components[$psmux.component].directory $psmux.executable } $display.stage = 'All selected components are ready' Write-Ready $readyPath ('status=ready' + "`r`n" + 'opencode=' + $openPath + "`r`n" + 'psmux=' + $muxPath + "`r`n" + 'git=' + $gitPath + "`r`n" + 'opencodeReason=' + $opencodeReason + "`r`n" + 'shellReason=' + $shellReason) if (-not $terminalStarted) { Say 'LAUNCH' 'Starting the selected shell in the Windows console.' $consoleFlags = @('--terminal','console') if ($env:FIELDKIT_BOOTSTRAP_TEST -eq '1') { $consoleFlags = @('--headless') } if (-not $desktop -and $env:FIELDKIT_BOOTSTRAP_TEST -ne '1' -and $env:FIELDKIT_BOOTSTRAP_DIAGNOSE -ne '1') { # Preserve interactive stdin/stdout; the background runner redirects them. Say 'READY' 'Selected components are ready; entering the current console. Exit the child shell to return.' & $helper ($common + $launchFlags + @('--headless')) if ($LASTEXITCODE -ne 0) { throw 'Fieldkit console startup failed.' } } elseif ((Run $helper ($common + $launchFlags + $consoleFlags) 120) -ne 0) { throw 'Fieldkit shell startup failed.' } } Say 'READY' ('Fieldkit started in {0:N1}s. Payload: {1}' -f ((Get-Date)-$started).TotalSeconds, $kit) Say 'INFO' 'Verified portable components remain cached for subsequent launches.' } catch { Say 'FAIL' $_.Exception.Message if ($readyPath) { try { Write-Ready $readyPath ('status=error' + "`r`n" + 'error=' + $_.Exception.Message) } catch {} } throw } finally { foreach ($job in $jobs) { if ($job.Started -and -not $job.Done) { $job.Cancel() } } Write-Progress -Id 42 -Activity 'Fieldkit portable startup' -Status 'Finished' -Completed [Net.ServicePointManager]::SecurityProtocol = $oldTls [Net.ServicePointManager]::DefaultConnectionLimit = $oldConnections if ($owned) { $mutex.ReleaseMutex() }; if ($mutex) { $mutex.Close() } } }