fix(gemini): update.ps1 must set $env:GEMINI_API_KEY in current session
Previously env vars were only set inside the PowerShell-fallback branch (when Python was missing). If Python was present, gemini_patcher.py wrote env vars via setx — which only updates the registry, not the current PowerShell process. Result: user runs update, then `gemini`, and gets prompted for API key because process.env.GEMINI_API_KEY is empty. Fix: always set env vars in BOTH User scope (persistent across sessions) AND $env: (current session) at the end of the script, regardless of which branch was taken. Also fix malformed JSON in trustedFolders.json fallback (escaped quotes were inconsistent). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -103,12 +103,6 @@ if (-not $pyCmd) {
|
|||||||
# PowerShell fallback — generate settings directly
|
# PowerShell fallback — generate settings directly
|
||||||
Write-Host " Applying patches (PowerShell)..." -ForegroundColor Cyan
|
Write-Host " Applying patches (PowerShell)..." -ForegroundColor Cyan
|
||||||
|
|
||||||
# Environment variables
|
|
||||||
[System.Environment]::SetEnvironmentVariable("GEMINI_API_KEY", "ClauderAPI2", "User")
|
|
||||||
[System.Environment]::SetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL", "https://ai.37-187-136-86.sslip.io", "User")
|
|
||||||
$env:GEMINI_API_KEY = "ClauderAPI2"
|
|
||||||
$env:GOOGLE_GEMINI_BASE_URL = "https://ai.37-187-136-86.sslip.io"
|
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
$geminiDir = "$env:USERPROFILE\.gemini"
|
$geminiDir = "$env:USERPROFILE\.gemini"
|
||||||
New-Item -ItemType Directory -Force -Path $geminiDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $geminiDir | Out-Null
|
||||||
@@ -137,11 +131,25 @@ if (-not $pyCmd) {
|
|||||||
|
|
||||||
# Trusted folders
|
# Trusted folders
|
||||||
$trustedFile = "$geminiDir\trustedFolders.json"
|
$trustedFile = "$geminiDir\trustedFolders.json"
|
||||||
$trustedJson = '{"C:\\":\"TRUST_PARENT\",\"C:\\Users\":\"TRUST_PARENT\"}'
|
$trustedJson = '{"C:\\":"TRUST_PARENT","C:\\Users":"TRUST_PARENT"}'
|
||||||
[System.IO.File]::WriteAllText($trustedFile, $trustedJson)
|
[System.IO.File]::WriteAllText($trustedFile, $trustedJson)
|
||||||
Write-Host " Patches applied (PowerShell fallback)" -ForegroundColor Green
|
Write-Host " Patches applied (PowerShell fallback)" -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ---- ALWAYS set env vars in BOTH User scope (persistent) and current session ----
|
||||||
|
# Critical: gemini reads process.env.GEMINI_API_KEY — without setting $env:* here,
|
||||||
|
# `gemini` launched in the same PowerShell will not see the key (setx only updates
|
||||||
|
# registry; existing processes are not notified).
|
||||||
|
Write-Host " Ensuring env vars are set in current session..." -ForegroundColor Cyan
|
||||||
|
[System.Environment]::SetEnvironmentVariable("GEMINI_API_KEY", "ClauderAPI2", "User")
|
||||||
|
[System.Environment]::SetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL", "https://ai.37-187-136-86.sslip.io", "User")
|
||||||
|
$env:GEMINI_API_KEY = "ClauderAPI2"
|
||||||
|
$env:GOOGLE_GEMINI_BASE_URL = "https://ai.37-187-136-86.sslip.io"
|
||||||
|
Write-Host " GEMINI_API_KEY and GOOGLE_GEMINI_BASE_URL set" -ForegroundColor Green
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host " Update complete!" -ForegroundColor Green
|
Write-Host " Update complete!" -ForegroundColor Green
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
Write-Host " Now you can run: gemini -p `"Hello`"" -ForegroundColor Cyan
|
||||||
|
Write-Host " (env vars active in this PowerShell session — no restart needed)" -ForegroundColor DarkGray
|
||||||
|
Write-Host ""
|
||||||
|
|||||||
Reference in New Issue
Block a user