From 9c1012f5b81c9a59b96381843be86bc71e80c00b Mon Sep 17 00:00:00 2001 From: Myfro9 <36755290+Myfro9@users.noreply.github.com> Date: Mon, 10 Aug 2026 09:43:39 -0500 Subject: [PATCH] =?UTF-8?q?sync:=20WIN11-BOWEI=202026-08-10=20MCP=E5=AE=A1?= =?UTF-8?q?=E8=AE=A1=E8=84=9A=E6=9C=ACpython=E5=9B=9E=E9=80=80=E5=88=B0con?= =?UTF-8?q?da(MS=20Store=E5=AD=98=E6=A0=B9=E4=BF=AE=E5=A4=8D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sync_mcp_registrations.ps1 默认用 PATH 上的 python 解析 Codex TOML, 但 Windows 上常见的是 Microsoft Store python 存根(exit 49, 无 stdlib)。 新增 Resolve-PythonCommand: python 不带 tomllib 时自动回退到 skills_env.md 的 CONDA_LANGGRAPH_PYTHON, 再退到 python3/py。显式 -PythonCommand 仍优先。 Co-Authored-By: Claude Opus 4.8 --- tools-sync/scripts/sync_mcp_registrations.ps1 | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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 }