From cb088c4e9a3229a1c4589db7c24f05c084fe3852 Mon Sep 17 00:00:00 2001 From: delta-cloud-208e Date: Tue, 21 Apr 2026 10:49:45 +0000 Subject: [PATCH] fix(gemini): update.ps1 must set $env:GEMINI_API_KEY in current session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- gemini/ugemini_update.ps1 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gemini/ugemini_update.ps1 b/gemini/ugemini_update.ps1 index 56ea1f4..7b45cd7 100644 --- a/gemini/ugemini_update.ps1 +++ b/gemini/ugemini_update.ps1 @@ -103,12 +103,6 @@ if (-not $pyCmd) { # PowerShell fallback — generate settings directly 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 $geminiDir = "$env:USERPROFILE\.gemini" New-Item -ItemType Directory -Force -Path $geminiDir | Out-Null @@ -137,11 +131,25 @@ if (-not $pyCmd) { # Trusted folders $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) 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 " Update complete!" -ForegroundColor Green 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 ""