$ErrorActionPreference = "Stop" $bundleRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $homeRoot = [Environment]::GetFolderPath("UserProfile") $timestamp = Get-Date -Format "yyyyMMdd-HHmmss" $backupRoot = Join-Path $homeRoot "airplan-backups\$timestamp" $sourceRoot = Join-Path $bundleRoot "AirContextServer" $targetRoot = Join-Path $homeRoot "AirContextServer" $snippetPath = Join-Path $bundleRoot "aircontext-settings-snippet.json" function Backup-ItemIfExists { param( [Parameter(Mandatory = $true)][string]$SourcePath, [Parameter(Mandatory = $true)][string]$BackupRelativePath ) if (-not (Test-Path -LiteralPath $SourcePath)) { return } $backupPath = Join-Path $backupRoot $BackupRelativePath $backupParent = Split-Path -Parent $backupPath if ($backupParent) { New-Item -ItemType Directory -Path $backupParent -Force | Out-Null } Copy-Item -LiteralPath $SourcePath -Destination $backupPath -Recurse -Force } function Replace-Directory { param( [Parameter(Mandatory = $true)][string]$SourcePath, [Parameter(Mandatory = $true)][string]$TargetPath ) $targetParent = Split-Path -Parent $TargetPath if ($targetParent) { New-Item -ItemType Directory -Path $targetParent -Force | Out-Null } if (Test-Path -LiteralPath $TargetPath) { Remove-Item -LiteralPath $TargetPath -Recurse -Force } Copy-Item -LiteralPath $SourcePath -Destination $TargetPath -Recurse -Force } New-Item -ItemType Directory -Path $backupRoot -Force | Out-Null Backup-ItemIfExists -SourcePath $targetRoot -BackupRelativePath "AirContextServer" Replace-Directory -SourcePath $sourceRoot -TargetPath $targetRoot Write-Output "aircontext_stage=completed" Write-Output ("aircontext_root=" + $targetRoot) Write-Output ("settings_snippet=" + $snippetPath) Write-Output "next_step=merge the snippet into %USERPROFILE%\.claude\settings.json or settings.local.json and enable aircontext@aircontext-mkt"