diff --git a/tools-sync/scripts/sync_mcp_registrations.ps1 b/tools-sync/scripts/sync_mcp_registrations.ps1 index 7e9b4b5..e33ddde 100644 --- a/tools-sync/scripts/sync_mcp_registrations.ps1 +++ b/tools-sync/scripts/sync_mcp_registrations.ps1 @@ -18,6 +18,41 @@ $script:CodexBackupMade = $false $script:Failures = @() $CodexOnlyEnv = @("PYTHONIOENCODING", "PYTHONUTF8") +function Test-TomllibPython([string]$Candidate) { + # tomllib needs CPython 3.11+; the Microsoft Store 'python' stub exits 49 and has no stdlib. + if (-not $Candidate) { return $false } + try { & $Candidate -c "import tomllib" 2>&1 | Out-Null } catch { return $false } + return ($LASTEXITCODE -eq 0) +} + +function Resolve-PythonCommand([string]$Requested, [bool]$Explicit) { + # An explicit -PythonCommand is authoritative; only auto-probe the default. + if ($Explicit) { return $Requested } + if (Test-TomllibPython $Requested) { return $Requested } + $envFile = "$env:USERPROFILE\skills_env.md" + if (Test-Path -LiteralPath $envFile) { + $line = Select-String -LiteralPath $envFile -Pattern '^\s*CONDA_LANGGRAPH_PYTHON\s*=\s*(.+?)\s*$' | + Select-Object -First 1 + if ($line) { + $cand = $line.Matches[0].Groups[1].Value.Trim() + if ((Test-Path -LiteralPath $cand) -and (Test-TomllibPython $cand)) { + Write-Host "python: falling back to CONDA_LANGGRAPH_PYTHON ($cand)" + return $cand + } + } + } + # Single-token candidates only: '& $cmd' treats the whole string as one exe name. + foreach ($cand in @("python3", "py")) { + if ((Get-Command $cand -ErrorAction SilentlyContinue) -and (Test-TomllibPython $cand)) { + Write-Host "python: falling back to '$cand'" + return $cand + } + } + throw "No tomllib-capable Python found ('$Requested' unusable). Pass -PythonCommand ." +} + +$PythonCommand = Resolve-PythonCommand $PythonCommand $PSBoundParameters.ContainsKey('PythonCommand') + function ConvertTo-StringMap($Object) { $result = [ordered]@{} if ($null -eq $Object) { return $result }