fix: TOML dotted key bug + PowerShell fallback for all Windows scripts
- codex: add [notice.model_migrations] with quoted keys to prevent Codex from writing unquoted dotted keys (gpt-5.4 → gpt-5 → 4) which causes "invalid type: map, expected a string" TOML error - codex_patcher.py: add toml_key() to quote keys with dots, handle broken TOML gracefully in read_toml() - claude install: remove unnecessary Python requirement - claude update: rewrite as standalone (no git clone dependency) - gemini update: add Python check with fallback, auth headers - qwen install: add PowerShell fallback, auth headers, no exit on no Python - qwen update: add Python check with fallback, auth headers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,19 +32,6 @@ function Get-NodeMajor {
|
||||
|
||||
# ---- Check prerequisites ----
|
||||
|
||||
# Python
|
||||
if (-not (Test-Command "python3") -and -not (Test-Command "python")) {
|
||||
Write-Host " Python not found. Installing..." -ForegroundColor Yellow
|
||||
if (Test-Command "winget") {
|
||||
winget install --id Python.Python.3.12 --accept-package-agreements --accept-source-agreements -e 2>$null
|
||||
Refresh-Path
|
||||
} else {
|
||||
Write-Host " Install Python manually: https://www.python.org/downloads/" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
Write-Host " Python OK" -ForegroundColor Green
|
||||
|
||||
# Node.js >= 20
|
||||
$MIN_NODE_MAJOR = 20
|
||||
$nodeMajor = Get-NodeMajor
|
||||
|
||||
@@ -1,164 +1,97 @@
|
||||
# UClaude Updater — automatic Claude Code patch updater
|
||||
# Usage: powershell -ExecutionPolicy Bypass -File claude\uclaude_update.ps1 [--check] [--force] [--settings-only]
|
||||
# Claude Code — Windows Updater
|
||||
# Usage: powershell -ExecutionPolicy Bypass -File claude\uclaude_update.ps1
|
||||
#
|
||||
# Updates Claude Code via npm registry + re-applies config patches.
|
||||
|
||||
$ErrorActionPreference = "Continue"
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$RepoRoot = Split-Path -Parent $ScriptDir
|
||||
Set-Location $RepoRoot
|
||||
|
||||
# ---- Pull latest FIRST so we always run newest scripts ----
|
||||
|
||||
Write-Host " Updating from remote..." -ForegroundColor Cyan
|
||||
git fetch --depth 1 origin master 2>$null
|
||||
git reset --hard origin/master 2>$null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
git pull --quiet 2>$null
|
||||
}
|
||||
|
||||
# ---- Helpers ----
|
||||
|
||||
function Test-Command($cmd) {
|
||||
return [bool](Get-Command $cmd -ErrorAction SilentlyContinue)
|
||||
}
|
||||
Write-Host ""
|
||||
Write-Host " +--------------------------------------+" -ForegroundColor Cyan
|
||||
Write-Host " | Claude Code -- Windows Updater |" -ForegroundColor Cyan
|
||||
Write-Host " +--------------------------------------+" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
function Refresh-Path {
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
|
||||
[System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||
}
|
||||
|
||||
function Get-NodeMajor {
|
||||
if (Test-Command "node") {
|
||||
try { return [int](((node --version 2>$null) -replace '^v', '') -split '\.')[0] }
|
||||
catch { return 0 }
|
||||
}
|
||||
return 0
|
||||
}
|
||||
# ---- Check current version ----
|
||||
|
||||
# ---- Check prerequisites ----
|
||||
|
||||
# Git
|
||||
if (-not (Test-Command "git")) {
|
||||
Write-Host " git not found." -ForegroundColor Red
|
||||
if (Test-Command "winget") {
|
||||
winget install --id Git.Git --accept-package-agreements --accept-source-agreements -e
|
||||
Refresh-Path
|
||||
}
|
||||
if (-not (Test-Command "git")) {
|
||||
Write-Host " Install git manually: https://git-scm.com/download/win" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Python
|
||||
$hasPython = (Test-Command "python3") -or (Test-Command "python")
|
||||
if (-not $hasPython) {
|
||||
Write-Host " Python not found." -ForegroundColor Red
|
||||
if (Test-Command "winget") {
|
||||
winget install --id Python.Python.3.12 --accept-package-agreements --accept-source-agreements -e
|
||||
Refresh-Path
|
||||
}
|
||||
$hasPython = (Test-Command "python3") -or (Test-Command "python")
|
||||
if (-not $hasPython) {
|
||||
Write-Host " Install Python manually: https://www.python.org/downloads/" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Dynamic Node.js version detection from npm registry
|
||||
$MIN_NODE_MAJOR = 18 # fallback
|
||||
|
||||
function Get-RequiredNodeMajor {
|
||||
# Try to detect required Node.js major version from npm registry
|
||||
$oldVer = "not installed"
|
||||
if (Get-Command claude -ErrorAction SilentlyContinue) {
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri "https://registry.npmjs.org/@anthropic-ai/claude-code/latest" -UseBasicParsing -TimeoutSec 10
|
||||
$engines = $response.engines
|
||||
$nodeReq = $engines.node
|
||||
|
||||
# Parse ">=18.0.0" or "^24.0.0" etc → extract first number
|
||||
if ($nodeReq -match '(\d+)') {
|
||||
return [int]$matches[1]
|
||||
}
|
||||
} catch {
|
||||
Write-Host " Warning: Could not fetch Node.js requirement from npm, using fallback v$MIN_NODE_MAJOR" -ForegroundColor Yellow
|
||||
}
|
||||
return $MIN_NODE_MAJOR
|
||||
$oldVer = (claude --version 2>$null) -replace '[\r\n]', ''
|
||||
} catch {}
|
||||
}
|
||||
$nodeMajor = Get-NodeMajor
|
||||
$requiredMajor = Get-RequiredNodeMajor
|
||||
Write-Host " Current: $oldVer" -ForegroundColor Cyan
|
||||
|
||||
if ($nodeMajor -ge $requiredMajor) {
|
||||
Write-Host " Node.js v$nodeMajor.x OK" -ForegroundColor Green
|
||||
} else {
|
||||
if ($nodeMajor -gt 0) {
|
||||
Write-Host " Node.js v$nodeMajor found, need v$requiredMajor+. Upgrading..." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host " Node.js not found. Installing v$requiredMajor+..." -ForegroundColor Yellow
|
||||
}
|
||||
# ---- Configure registry ----
|
||||
|
||||
$installed = $false
|
||||
Write-Host " Configuring npm registry..." -ForegroundColor Cyan
|
||||
npm config set "@anthropic-ai:registry" "https://npm.sensey24.ru/" 2>$null
|
||||
|
||||
# 1. Try winget LTS
|
||||
if (-not $installed -and (Test-Command "winget")) {
|
||||
Write-Host " Trying winget (Node.js LTS)..." -ForegroundColor Yellow
|
||||
winget install --id OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements -e 2>$null
|
||||
Refresh-Path
|
||||
if ((Get-NodeMajor) -ge $requiredMajor) { $installed = $true }
|
||||
}
|
||||
# ---- Update package ----
|
||||
|
||||
# 2. Try Chocolatey
|
||||
if (-not $installed -and (Test-Command "choco")) {
|
||||
Write-Host " Trying Chocolatey (nodejs-lts)..." -ForegroundColor Yellow
|
||||
choco install nodejs-lts -y 2>$null
|
||||
Refresh-Path
|
||||
if ((Get-NodeMajor) -ge $requiredMajor) { $installed = $true }
|
||||
}
|
||||
|
||||
# 3. Direct MSI download — dynamically pick the right major version
|
||||
if (-not $installed) {
|
||||
Write-Host " Downloading Node.js v$requiredMajor MSI..." -ForegroundColor Yellow
|
||||
try {
|
||||
# Fetch latest release of the required major version from nodejs.org
|
||||
$latestForMajor = "v$requiredMajor.0.0"
|
||||
try {
|
||||
$releases = Invoke-RestMethod -Uri "https://nodejs.org/dist/index.json" -UseBasicParsing -TimeoutSec 10
|
||||
$match = $releases | Where-Object { $_.version -match "^v$requiredMajor\." } | Select-Object -First 1
|
||||
if ($match) { $latestForMajor = $match.version }
|
||||
} catch {}
|
||||
$msiUrl = "https://nodejs.org/dist/$latestForMajor/node-$latestForMajor-x64.msi"
|
||||
$msiFile = Join-Path $env:TEMP "node-v$requiredMajor.msi"
|
||||
Invoke-WebRequest -Uri $msiUrl -OutFile $msiFile -UseBasicParsing
|
||||
Start-Process msiexec.exe -ArgumentList "/i `"$msiFile`" /quiet /norestart" -Wait
|
||||
Refresh-Path
|
||||
Remove-Item $msiFile -Force -ErrorAction SilentlyContinue
|
||||
if ((Get-NodeMajor) -ge $requiredMajor) { $installed = $true }
|
||||
} catch {
|
||||
Write-Host " Download failed: $_" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $installed) {
|
||||
Write-Host "" -ForegroundColor Red
|
||||
Write-Host " Could not install Node.js automatically." -ForegroundColor Red
|
||||
Write-Host " Install manually: https://nodejs.org/en/download/ (v$requiredMajor+)" -ForegroundColor Yellow
|
||||
Write-Host " Then re-run this script." -ForegroundColor Yellow
|
||||
Write-Host " Installing latest @anthropic-ai/claude-code..." -ForegroundColor Cyan
|
||||
npm install -g @anthropic-ai/claude-code 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " npm install failed. Retrying..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 3
|
||||
npm install -g @anthropic-ai/claude-code 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " npm install failed." -ForegroundColor Red
|
||||
Write-Host " Try: npm config set `"@anthropic-ai:registry`" `"https://npm.sensey24.ru/`"" -ForegroundColor Yellow
|
||||
Write-Host " Then: npm install -g @anthropic-ai/claude-code" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host " Node.js v$(Get-NodeMajor).x installed OK" -ForegroundColor Green
|
||||
}
|
||||
Refresh-Path
|
||||
|
||||
# ---- Check admin, re-launch elevated if needed ----
|
||||
|
||||
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
|
||||
if (-not $isAdmin) {
|
||||
Write-Host " Re-running as Administrator..." -ForegroundColor Yellow
|
||||
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`" $args" -Verb RunAs
|
||||
exit
|
||||
$newVer = "unknown"
|
||||
if (Get-Command claude -ErrorAction SilentlyContinue) {
|
||||
try {
|
||||
$newVer = (claude --version 2>$null) -replace '[\r\n]', ''
|
||||
} catch {}
|
||||
}
|
||||
Write-Host " Updated: $oldVer -> $newVer" -ForegroundColor Green
|
||||
|
||||
# ---- Run updater ----
|
||||
# ---- Re-apply config patches ----
|
||||
|
||||
$pythonCmd = if (Test-Command "python3") { "python3" } else { "python" }
|
||||
& $pythonCmd claude\uclaude_updater.py @args
|
||||
Write-Host " Setting environment variables..." -ForegroundColor Cyan
|
||||
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "ClauderAPI", "User")
|
||||
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://ai.37-187-136-86.sslip.io", "User")
|
||||
$env:ANTHROPIC_API_KEY = "ClauderAPI"
|
||||
$env:ANTHROPIC_BASE_URL = "https://ai.37-187-136-86.sslip.io"
|
||||
Write-Host " Env vars set (ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL)" -ForegroundColor Green
|
||||
|
||||
# ---- Re-apply settings ----
|
||||
|
||||
Write-Host " Configuring settings..." -ForegroundColor Cyan
|
||||
$claudeDir = "$env:USERPROFILE\.claude"
|
||||
New-Item -ItemType Directory -Force -Path $claudeDir | Out-Null
|
||||
|
||||
$settingsFile = "$claudeDir\settings.json"
|
||||
$json = @'
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(*)",
|
||||
"Read(*)",
|
||||
"Write(*)",
|
||||
"Edit(*)",
|
||||
"Glob(*)",
|
||||
"Grep(*)",
|
||||
"WebFetch(*)",
|
||||
"WebSearch(*)"
|
||||
],
|
||||
"deny": []
|
||||
}
|
||||
}
|
||||
'@
|
||||
[System.IO.File]::WriteAllText($settingsFile, $json)
|
||||
Write-Host " Settings: $settingsFile" -ForegroundColor Green
|
||||
|
||||
Write-Host ""
|
||||
Write-Host " Update complete!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
Reference in New Issue
Block a user