bookworm-boot/启动Bookworm.bat

59 lines
2.4 KiB
Batchfile

@echo off
chcp 65001 > nul
cd /d "%~dp0"
:: 默认模型 (中转站兼容白名单, Claude Code 2.0.x 默认 4-5 会 503)
if not defined ANTHROPIC_MODEL set ANTHROPIC_MODEL=claude-opus-4-7
:: 中转站在国内,不走代理
set NO_PROXY=bww.letcareme.com,code.letcareme.com,letcareme.com,localhost,127.0.0.1
set no_proxy=%NO_PROXY%
:: 静默自动更新 (bookworm-boot + .claude 配置, 失败不阻断启动)
echo [..] 检查更新...
git pull --rebase >nul 2>nul
git -C "%USERPROFILE%\.claude" pull --rebase >nul 2>nul
:: === 终端选择: Windows Terminal > conhost ===
:: wt.exe 支持完整 Unicode 渲染 + 自由缩放不闪退
set USE_WT=0
where wt >nul 2>nul && set USE_WT=1
:: === Shell 选择: pwsh7 > powershell 5.1 ===
:: pwsh7 启动更快, 支持更多语法, Claude Code TUI 渲染更好
set USE_PWSH7=0
where pwsh >nul 2>nul && set USE_PWSH7=1
:: 构建凭证加载命令 (DPAPI 解密)
set CRED_CMD=Add-Type -AssemblyName System.Security;$r='HKCU:\Software\Bookworm\CachedEnv';try{(Get-ItemProperty $r -EA Stop).PSObject.Properties^|Where-Object{$_.Name-match'^[A-Z_]+$'}^|ForEach-Object{$v=$_.Value;try{$b=[Security.Cryptography.ProtectedData]::Unprotect([Convert]::FromBase64String($v),$null,[Security.Cryptography.DataProtectionScope]::CurrentUser);$v=[Text.Encoding]::UTF8.GetString($b)}catch{};[Environment]::SetEnvironmentVariable($_.Name,$v,'Process')}}catch{};
:: 优先路径: wt + pwsh7
if %USE_WT% equ 1 if %USE_PWSH7% equ 1 (
start "" wt new-tab --title "Bookworm Smart Assistant" -d "%~dp0" -- pwsh -NoLogo -NoExit -Command "%CRED_CMD% & claude --dangerously-skip-permissions"
exit
)
:: 路径 2: wt + powershell 5.1
if %USE_WT% equ 1 if %USE_PWSH7% equ 0 (
start "" wt new-tab --title "Bookworm Smart Assistant" -d "%~dp0" -- powershell -NoLogo -ExecutionPolicy Bypass -NoExit -Command "%CRED_CMD% & claude --dangerously-skip-permissions"
exit
)
:: 路径 3: conhost + pwsh7
if %USE_PWSH7% equ 1 (
start "Bookworm Smart Assistant" pwsh -NoLogo -NoExit -Command "%CRED_CMD% & claude --dangerously-skip-permissions"
exit
)
:: 路径 4: 回退 PowerShell 5.1 (最低保障)
title Bookworm Portable
echo.
echo [!] PowerShell 7 未安装, 使用 PowerShell 5.1
echo.
powershell -ExecutionPolicy Bypass -File install.ps1 -StartOnly -AutoAccept
if %errorlevel% neq 0 (
echo.
echo 启动失败,按任意键退出...
pause > nul
)