-
-
Save HoriLiu/e95d48009cf0d76e8f52a9009c0a79c4 to your computer and use it in GitHub Desktop.
Hermes Agent Windows 安裝腳本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #=============================================================================== | |
| # Hermes Agent 一鍵安裝腳本 (Windows PowerShell) | |
| # 用途:在 Windows 上自動安裝 Hermes Agent 企業助理系統 | |
| # 使用方式:右鍵 → 使用 PowerShell 執行 | |
| #=============================================================================== | |
| # 設定輸出顏色 | |
| function Write-Success { Write-Host "✅ $args" -ForegroundColor Green } | |
| function Write-Error-Custom { Write-Host "❌ $args" -ForegroundColor Red } | |
| function Write-Warning-Custom { Write-Host "⚠️ $args" -ForegroundColor Yellow } | |
| function Write-Info { Write-Host "📋 $args" -ForegroundColor Cyan } | |
| #=============================================================================== | |
| # 步驟 1: 檢查系統狀態 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "開始安裝 Hermes Agent..." | |
| Write-Host "================================" | |
| # 檢查是否為 Windows | |
| if ($env:OS -ne "Windows_NT") { | |
| Write-Error-Custom "此腳本僅支援 Windows" | |
| exit 1 | |
| } | |
| Write-Success "系統檢查通過:Windows" | |
| # 檢查 Windows 版本 | |
| $windowsVersion = Get-WmiObject Win32_OperatingSystem | |
| Write-Info "Windows 版本:$($windowsVersion.Caption)" | |
| Write-Info "系統架構:$($env:PROCESSOR_ARCHITECTURE)" | |
| # 檢查 PowerShell 版本 | |
| Write-Info "PowerShell 版本:$($PSVersionTable.PSVersion)" | |
| #=============================================================================== | |
| # 步驟 2: 檢查並設定執行原則 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 2: 檢查 PowerShell 執行原則..." | |
| $executionPolicy = Get-ExecutionPolicy -Scope CurrentUser | |
| if ($executionPolicy -eq "Restricted") { | |
| Write-Warning-Custom "執行原則為 Restricted,嘗試設定為 RemoteSigned..." | |
| Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force | |
| Write-Success "執行原則已更新" | |
| } else { | |
| Write-Success "執行原則:$executionPolicy" | |
| } | |
| #=============================================================================== | |
| # 步驟 3: 檢查並安裝 Chocolatey (Windows 套件管理器) | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 3: 檢查 Chocolatey..." | |
| if (Get-Command choco -ErrorAction SilentlyContinue) { | |
| Write-Success "Chocolatey 已安裝:$(choco --version)" | |
| } else { | |
| Write-Warning-Custom "Chocolatey 未安裝,開始安裝..." | |
| # 下載並安裝 Chocolatey | |
| Set-ExecutionPolicy Bypass -Scope Process -Force | |
| [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
| iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) | |
| Write-Success "Chocolatey 安裝完成" | |
| } | |
| #=============================================================================== | |
| # 步驟 4: 檢查並安裝 Python 3 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 4: 檢查 Python 3..." | |
| $pythonInstalled = Get-Command python -ErrorAction SilentlyContinue | |
| if ($pythonInstalled) { | |
| $pythonVersion = python --version | |
| Write-Success "Python 已安裝:$pythonVersion" | |
| } else { | |
| Write-Warning-Custom "Python 未安裝,使用 Chocolatey 安裝..." | |
| choco install python -y | |
| $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
| Write-Success "Python 安裝完成:$(python --version)" | |
| } | |
| # 檢查 pip | |
| if (Get-Command pip -ErrorAction SilentlyContinue) { | |
| Write-Success "pip 已安裝:$(pip --version)" | |
| } else { | |
| Write-Warning-Custom "pip 未安裝,嘗試安裝..." | |
| python -m ensurepip --upgrade | |
| Write-Success "pip 安裝完成" | |
| } | |
| #=============================================================================== | |
| # 步驟 5: 檢查並安裝 Git | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 5: 檢查 Git..." | |
| if (Get-Command git -ErrorAction SilentlyContinue) { | |
| Write-Success "Git 已安裝:$(git --version)" | |
| } else { | |
| Write-Warning-Custom "Git 未安裝,使用 Chocolatey 安裝..." | |
| choco install git -y | |
| $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
| Write-Success "Git 安裝完成:$(git --version)" | |
| } | |
| #=============================================================================== | |
| # 步驟 6: 檢查並安裝 Node.js (可選) | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 6: 檢查 Node.js..." | |
| if (Get-Command node -ErrorAction SilentlyContinue) { | |
| Write-Success "Node.js 已安裝:$(node --version)" | |
| } else { | |
| Write-Warning-Custom "Node.js 未安裝,使用 Chocolatey 安裝..." | |
| choco install nodejs-lts -y | |
| $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
| Write-Success "Node.js 安裝完成:$(node --version)" | |
| } | |
| #=============================================================================== | |
| # 步驟 7: 建立 Hermes Agent 工作目錄 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 7: 建立工作目錄..." | |
| $hermesHome = "$env:USERPROFILE\hermes-agent" | |
| $directories = @( | |
| "$hermesHome\scripts", | |
| "$hermesHome\cache", | |
| "$hermesHome\logs" | |
| ) | |
| foreach ($dir in $directories) { | |
| if (-not (Test-Path $dir)) { | |
| New-Item -ItemType Directory -Path $dir -Force | Out-Null | |
| } | |
| } | |
| Write-Success "目錄建立完成:$hermesHome" | |
| #=============================================================================== | |
| # 步驟 8: 安裝 Hermes Agent 核心套件 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 8: 安裝 Hermes Agent..." | |
| # 檢查是否已安裝 | |
| $hermesCheck = pip show hermes-agent -ErrorAction SilentlyContinue | |
| if ($hermesCheck) { | |
| Write-Info "Hermes Agent 已安裝,更新中..." | |
| pip install --upgrade hermes-agent | |
| } else { | |
| Write-Info "安裝 Hermes Agent..." | |
| pip install hermes-agent | |
| } | |
| Write-Success "Hermes Agent 安裝完成" | |
| #=============================================================================== | |
| # 步驟 9: 安裝額外依賴套件 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 9: 安裝額外依賴..." | |
| pip install --user ` | |
| requests ` | |
| python-dotenv ` | |
| rich ` | |
| prompt_toolkit | |
| Write-Success "額外依賴安裝完成" | |
| #=============================================================================== | |
| # 步驟 10: 設定環境變數 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 10: 設定環境變數..." | |
| # 設定用戶層級環境變數 | |
| [Environment]::SetEnvironmentVariable("HERMES_HOME", $hermesHome, "User") | |
| [Environment]::SetEnvironmentVariable("OPENROUTER_API_KEY", "sk-or-你的 KEY", "User") | |
| [Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-你的 KEY", "User") | |
| # 更新 PATH | |
| $currentPath = [Environment]::GetEnvironmentVariable("Path", "User") | |
| if ($currentPath -notlike "*$hermesHome\scripts*") { | |
| $newPath = "$currentPath;$hermesHome\scripts" | |
| [Environment]::SetEnvironmentVariable("Path", $newPath, "User") | |
| } | |
| Write-Info "已設定環境變數 (需要重新開啟終端生效)" | |
| Write-Warning-Custom "請替換 OPENROUTER_API_KEY 和 ANTHROPIC_API_KEY 為你的實際金鑰" | |
| #=============================================================================== | |
| # 步驟 11: 建立快速啟動腳本 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 11: 建立快速啟動腳本..." | |
| $hermesScript = @" | |
| @echo off | |
| REM Hermes Agent 快速啟動 (Windows) | |
| cd /d "%USERPROFILE%\hermes-agent" | |
| python -m hermes_agent %* | |
| "@ | |
| $hermesScript | Out-File -FilePath "$hermesHome\scripts\hermes.bat" -Encoding ASCII | |
| $hermesPwsh = @" | |
| # Hermes Agent PowerShell 啟動腳本 | |
| Set-Location "$hermesHome" | |
| python -m hermes_agent @args | |
| "@ | |
| $hermesPwsh | Out-File -FilePath "$hermesHome\scripts\hermes.ps1" -Encoding UTF8 | |
| Write-Success "快速啟動腳本建立完成" | |
| #=============================================================================== | |
| # 步驟 12: 使設定生效 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 12: 更新環境變數..." | |
| $env:HERMES_HOME = $hermesHome | |
| Write-Success "當前工作階段環境變數已更新" | |
| Write-Warning-Custom "永久設定需要重新開啟終端機" | |
| #=============================================================================== | |
| # 步驟 13: 驗證安裝 | |
| #=============================================================================== | |
| Write-Host "" | |
| Write-Info "步驟 13: 驗證安裝..." | |
| Write-Host "" | |
| Write-Host "================================" | |
| Write-Info "安裝驗證:" | |
| Write-Host "--------------------------------" | |
| # 檢查 Python | |
| if (Get-Command python -ErrorAction SilentlyContinue) { | |
| Write-Success "Python: $(python --version)" | |
| } else { | |
| Write-Error-Custom "Python: 未安裝" | |
| } | |
| # 檢查 Hermes | |
| if (Get-Command hermes -ErrorAction SilentlyContinue) { | |
| Write-Success "Hermes: 已安裝" | |
| } else { | |
| Write-Warning-Custom "Hermes: 請重新開啟終端後再試" | |
| } | |
| # 檢查環境變數 | |
| if ($env:HERMES_HOME) { | |
| Write-Success "HERMES_HOME: $env:HERMES_HOME" | |
| } else { | |
| Write-Warning-Custom "HERMES_HOME: 未設定" | |
| } | |
| Write-Host "================================" | |
| Write-Host "" | |
| #=============================================================================== | |
| # 安裝完成 | |
| #=============================================================================== | |
| Write-Success "🎉 Hermes Agent 安裝完成!" | |
| Write-Host "" | |
| Write-Host "================================" | |
| Write-Info "下一步:" | |
| Write-Host "" | |
| Write-Host "1. 設定 API Key (選擇一個方式):" | |
| Write-Host "" | |
| Write-Host " 【方式 A】使用環境變數 GUI:" | |
| Write-Host " 執行:sysdm.cpl → 進階 → 環境變數" | |
| Write-Host " 新增用戶變數:" | |
| Write-Host " OPENROUTER_API_KEY = sk-or-你的 KEY" | |
| Write-Host " ANTHROPIC_API_KEY = sk-ant-你的 KEY" | |
| Write-Host "" | |
| Write-Host " 【方式 B】使用 PowerShell:" | |
| Write-Host ' [Environment]::SetEnvironmentVariable("OPENROUTER_API_KEY", "sk-or-xxx", "User")' | |
| Write-Host ' [Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-xxx", "User")' | |
| Write-Host "" | |
| Write-Host "2. 重新開啟 PowerShell 或 CMD" | |
| Write-Host "" | |
| Write-Host "3. 啟動 Hermes Agent:" | |
| Write-Host " hermes" | |
| Write-Host "" | |
| Write-Host "4. 查看說明:" | |
| Write-Host " hermes --help" | |
| Write-Host "================================" | |
| Write-Host "" | |
| # 詢問是否現在設定 API Key | |
| $setKey = Read-Host "現在要設定 API Key 嗎?(y/n)" | |
| if ($setKey -eq "y" -or $setKey -eq "Y") { | |
| Write-Host "" | |
| $orKey = Read-Host "輸入 OpenRouter API Key" | |
| $anKey = Read-Host "輸入 Anthropic API Key" | |
| # 設定環境變數 | |
| [Environment]::SetEnvironmentVariable("OPENROUTER_API_KEY", $orKey, "User") | |
| [Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $anKey, "User") | |
| # 更新當前工作階段 | |
| $env:OPENROUTER_API_KEY = $orKey | |
| $env:ANTHROPIC_API_KEY = $anKey | |
| Write-Success "API Key 設定完成!" | |
| Write-Host "" | |
| Write-Info "啟動 Hermes Agent:" | |
| Write-Host " hermes" | |
| } | |
| Write-Host "" | |
| Write-Info "安裝腳本位置:$PSCommandPath" | |
| Write-Host "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment