Skip to content

Instantly share code, notes, and snippets.

@boxabirds
Created June 13, 2025 09:41
Show Gist options
  • Save boxabirds/445b8c45b7ad8859ff5503a143b37fe1 to your computer and use it in GitHub Desktop.
Save boxabirds/445b8c45b7ad8859ff5503a143b37fe1 to your computer and use it in GitHub Desktop.
Install the "ai" command line helper by builder.io
@echo off
setlocal enabledelayedexpansion
:: AI Shell Installation Script for Windows
:: This script installs Node.js/npm if needed, then installs @builder.io/ai-shell
echo ======================================
echo AI Shell Installation Script
echo ======================================
echo.
:: Check if npm is installed
where npm >nul 2>nul
if %errorlevel% equ 0 (
echo [✓] npm is already installed
for /f "tokens=*" %%i in ('npm --version') do echo Version: %%i
echo.
goto :install_ai_shell
) else (
echo [✗] npm is not installed
echo.
goto :install_nodejs
)
:install_nodejs
echo Installing Node.js and npm...
echo.
:: Check if winget is available (Windows Package Manager)
where winget >nul 2>nul
if %errorlevel% equ 0 (
echo Using Windows Package Manager (winget) to install Node.js...
winget install OpenJS.NodeJS --accept-package-agreements --accept-source-agreements
if !errorlevel! equ 0 (
echo.
echo [✓] Node.js has been installed successfully!
echo.
echo Refreshing environment variables...
call refreshenv >nul 2>nul
:: Try to find npm in common locations
set "PATH=%PATH%;%ProgramFiles%\nodejs;%ProgramFiles(x86)%\nodejs;%LOCALAPPDATA%\Programs\nodejs"
goto :verify_npm
) else (
goto :try_choco
)
) else (
goto :try_choco
)
:try_choco
:: Check if chocolatey is available
where choco >nul 2>nul
if %errorlevel% equ 0 (
echo Using Chocolatey to install Node.js...
choco install nodejs -y
if !errorlevel! equ 0 (
echo.
echo [✓] Node.js has been installed successfully!
echo.
call refreshenv >nul 2>nul
goto :verify_npm
) else (
goto :download_nodejs
)
) else (
goto :download_nodejs
)
:download_nodejs
echo.
echo Downloading Node.js installer...
echo.
:: Create temp directory
set "TEMP_DIR=%TEMP%\nodejs_install"
if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%"
:: Download Node.js installer using PowerShell
powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://nodejs.org/dist/v20.11.0/node-v20.11.0-x64.msi' -OutFile '%TEMP_DIR%\nodejs.msi'}"
if exist "%TEMP_DIR%\nodejs.msi" (
echo Installing Node.js...
msiexec /i "%TEMP_DIR%\nodejs.msi" /qn /norestart
:: Wait for installation
timeout /t 5 /nobreak >nul
:: Clean up
del "%TEMP_DIR%\nodejs.msi"
rmdir "%TEMP_DIR%"
:: Update PATH
set "PATH=%PATH%;%ProgramFiles%\nodejs"
goto :verify_npm
) else (
echo.
echo Failed to download Node.js installer.
echo Please download and install manually from: https://nodejs.org/
echo.
pause
exit /b 1
)
:verify_npm
:: Verify npm is now available
where npm >nul 2>nul
if %errorlevel% neq 0 (
echo.
echo [✗] npm is still not found in PATH.
echo.
echo Please close this window and open a new Command Prompt,
echo then run this script again.
echo.
pause
exit /b 1
)
:install_ai_shell
echo Installing @builder.io/ai-shell globally...
echo.
npm install -g @builder.io/ai-shell
if %errorlevel% equ 0 (
echo.
echo [✓] @builder.io/ai-shell has been successfully installed!
echo.
) else (
echo.
echo [✗] Failed to install @builder.io/ai-shell
echo.
echo If you see permission errors, try running this script as Administrator.
echo.
pause
exit /b 1
)
:: Check and set up API keys
echo ======================================
echo API Key Configuration
echo ======================================
echo.
set api_key_found=false
:: Check existing keys
if defined OPENAI_API_KEY (
echo [✓] OPENAI_API_KEY is already set
set api_key_found=true
)
if defined GEMINI_API_KEY (
echo [✓] GEMINI_API_KEY is already set
set api_key_found=true
)
if defined ANTHROPIC_API_KEY (
echo [✓] ANTHROPIC_API_KEY is already set
set api_key_found=true
)
:: If no keys found, help user set them up
if "%api_key_found%"=="false" (
echo.
echo No API keys found. Let's set one up!
echo.
echo AI Shell needs at least one API key to work.
echo Choose which service you'd like to use:
echo.
echo 1^) OpenAI ^(GPT-4, GPT-3.5^)
echo 2^) Google Gemini
echo 3^) Anthropic ^(Claude^)
echo 4^) Skip for now
echo.
set /p choice="Enter your choice (1-4): "
if "!choice!"=="1" (
echo.
echo To get an OpenAI API key:
echo 1. Go to https://platform.openai.com/api-keys
echo 2. Sign in or create an account
echo 3. Click 'Create new secret key'
echo 4. Copy the key ^(it starts with 'sk-'^)
echo.
set /p openai_key="Paste your OpenAI API key here (or press Enter to skip): "
if not "!openai_key!"=="" (
echo Setting OPENAI_API_KEY...
setx OPENAI_API_KEY "!openai_key!" >nul
set OPENAI_API_KEY=!openai_key!
set api_key_found=true
echo [✓] OPENAI_API_KEY has been set
)
) else if "!choice!"=="2" (
echo.
echo To get a Google Gemini API key:
echo 1. Go to https://makersuite.google.com/app/apikey
echo 2. Sign in with your Google account
echo 3. Click 'Create API key'
echo 4. Copy the key
echo.
set /p gemini_key="Paste your Gemini API key here (or press Enter to skip): "
if not "!gemini_key!"=="" (
echo Setting GEMINI_API_KEY...
setx GEMINI_API_KEY "!gemini_key!" >nul
set GEMINI_API_KEY=!gemini_key!
set api_key_found=true
echo [✓] GEMINI_API_KEY has been set
)
) else if "!choice!"=="3" (
echo.
echo To get an Anthropic API key:
echo 1. Go to https://console.anthropic.com/api-keys
echo 2. Sign in or create an account
echo 3. Click 'Create Key'
echo 4. Copy the key
echo.
set /p anthropic_key="Paste your Anthropic API key here (or press Enter to skip): "
if not "!anthropic_key!"=="" (
echo Setting ANTHROPIC_API_KEY...
setx ANTHROPIC_API_KEY "!anthropic_key!" >nul
set ANTHROPIC_API_KEY=!anthropic_key!
set api_key_found=true
echo [✓] ANTHROPIC_API_KEY has been set
)
) else if "!choice!"=="4" (
echo.
echo Skipping API key setup...
) else (
echo Invalid choice. Skipping API key setup...
)
)
echo.
echo ======================================
echo Installation Summary
echo ======================================
echo.
if "%api_key_found%"=="true" (
echo [✓] AI Shell is installed and configured!
echo.
echo You can now use AI Shell by running:
echo ai "your question or command"
echo.
echo Example:
echo ai "list all PDF files in the current directory"
echo.
if not "!openai_key!"=="" (
echo Note: API key has been set for future sessions.
echo Close and reopen Command Prompt to use AI Shell with the new key.
)
if not "!gemini_key!"=="" (
echo Note: API key has been set for future sessions.
echo Close and reopen Command Prompt to use AI Shell with the new key.
)
if not "!anthropic_key!"=="" (
echo Note: API key has been set for future sessions.
echo Close and reopen Command Prompt to use AI Shell with the new key.
)
) else (
echo [✓] AI Shell is installed but needs an API key to work.
echo.
echo To add an API key later, run this script again or manually set one of:
echo setx OPENAI_API_KEY "your-key"
echo setx GEMINI_API_KEY "your-key"
echo setx ANTHROPIC_API_KEY "your-key"
echo.
echo Then close and reopen Command Prompt.
)
echo.
echo ======================================
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment