agent-ssh 0.4.1

Arrange agent terminal layouts and reconnect through provider attachment plans
Documentation
param([string]$Repository = (Join-Path $PSScriptRoot '..'))
$ErrorActionPreference = 'Stop'
$repo = [IO.Path]::GetFullPath($Repository)
foreach ($name in @('capture-windows.ps1', 'passive-windows.ps1', 'verify_windows_helpers.ps1')) {
    $tokens = $null
    $parseErrors = $null
    $null = [System.Management.Automation.Language.Parser]::ParseFile((Join-Path $repo ('scripts\' + $name)), [ref]$tokens, [ref]$parseErrors)
    if ($parseErrors.Count) { throw "PowerShell parse failed for $name" }
}
$output = Join-Path $repo 'target\journal-stress'
$null = New-Item -ItemType Directory -Path $output -Force
$compiler = Join-Path ([Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) 'csc.exe'
$probe = Join-Path $output 'console-probe.exe'
& $compiler /nologo /target:exe /reference:System.Web.Extensions.dll ("/out:"+$probe) (Join-Path $repo 'scripts\console-probe.cs')
if ($LASTEXITCODE) { throw 'Console helper compilation failed' }
Add-Type -AssemblyName UIAutomationClient
Add-Type -AssemblyName UIAutomationTypes
Add-Type -AssemblyName WindowsBase
$client = [System.Windows.Automation.AutomationElement].Assembly.Location
$types = [System.Windows.Automation.ControlType].Assembly.Location
$base = [System.Windows.Rect].Assembly.Location
$fixture = Join-Path $output 'stress.exe'
& $compiler /nologo /target:exe /main:JournalStress /reference:System.Web.Extensions.dll ("/reference:"+$probe) ("/reference:"+$client) ("/reference:"+$types) ("/reference:"+$base) ("/out:"+$fixture) (Join-Path $repo 'scripts\selection-watchdog.cs') (Join-Path $repo 'tests\windows_journal_stress.cs')
if ($LASTEXITCODE) { throw 'Journal stress fixture compilation failed' }
& $fixture (Join-Path $output 'owned-files')
if ($LASTEXITCODE) { throw 'Journal stress fixture failed' }

$actualCodex = @(Get-CimInstance Win32_Process | Where-Object {$_.Name -eq 'codex.exe'})
foreach ($missing in @('CommandLine', 'CreationDate')) {
    $fakeCodex = [pscustomobject]@{Name='codex.exe';ProcessId=[uint32]4294967294;ParentProcessId=0;CommandLine='codex.exe';CreationDate=[DateTime]::UtcNow;ExecutablePath='C:\fixture\codex.exe'}
    $fakeCodex.$missing = $null
    function Get-CimInstance { return @($actualCodex) + @($fakeCodex) }
    $failedClosed = $false
    try {
        $null = & (Join-Path $repo 'scripts\capture-windows.ps1') -ProcessesOnly
    } catch {
        if ($_.ToString() -notlike '*Live Codex process command line or creation metadata is unavailable*') { throw }
        $failedClosed = $true
    } finally { Remove-Item -LiteralPath Function:\Get-CimInstance }
    if (!$failedClosed) { throw "Missing Codex $missing was silently ignored" }
}