From d20d9d91a75dd90a355d2ef7085057f090f92cb1 Mon Sep 17 00:00:00 2001 From: bookworm Date: Fri, 10 Apr 2026 11:07:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(installer):=20=E4=B8=89=E7=BA=A7=E5=87=AD?= =?UTF-8?q?=E8=AF=81=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B,=20=E9=87=8D?= =?UTF-8?q?=E8=A3=85=E5=85=8D=E8=BE=93=E6=8E=88=E6=9D=83=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 4 凭证加载优先级: 1. User 环境变量 (上次安装已永久写入) → 直接加载, 完全跳过授权码 2. Registry DPAPI 缓存 → 加载 + 写 User 环境变量 3. 授权码输入 → 解密 + 写 User 环境变量 解决: 用户重装/升级时不再被要求重新输入授权码, 旧凭证自动检测并沿用. "全自动检测+修复"闭环. Co-Authored-By: Claude Opus 4.6 (1M context) --- auto-setup.ps1 | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/auto-setup.ps1 b/auto-setup.ps1 index 9adfa4b..232d118 100644 --- a/auto-setup.ps1 +++ b/auto-setup.ps1 @@ -952,9 +952,25 @@ Log-Phase 4 "凭证解密" $secretsDecrypted = $false -# 先查缓存 -if (Get-CachedSecrets) { - Log-OK "从本日缓存加载凭证 (免密)" +# 优先级 1: User 级环境变量已有 (上次安装已永久写入) +$existingKey = [System.Environment]::GetEnvironmentVariable("ANTHROPIC_API_KEY", "User") +$existingUrl = [System.Environment]::GetEnvironmentVariable("ANTHROPIC_BASE_URL", "User") +if ($existingKey) { + # 注入到当前 Process (User 环境变量新终端才生效, 当前进程需手动加载) + $env:ANTHROPIC_API_KEY = $existingKey + if ($existingUrl) { $env:ANTHROPIC_BASE_URL = $existingUrl } + # 加载其他 Key (如果有) + foreach ($k in $CacheAllowedKeys) { + $v = [System.Environment]::GetEnvironmentVariable($k, "User") + if ($v) { [System.Environment]::SetEnvironmentVariable($k, $v, "Process") } + } + Log-OK "从系统环境变量加载凭证 (已有安装记录, 免输授权码)" + $secretsDecrypted = $true +} + +# 优先级 2: Registry DPAPI 缓存 +if (-not $secretsDecrypted -and (Get-CachedSecrets)) { + Log-OK "从 Registry 缓存加载凭证" $secretsDecrypted = $true } # 再解密 (缓存命中则跳过)