Files
Claude-Code-Workflow/install-remote.ps1
catlog22 a03415bfeb feat: Add version tracking and upgrade check system
- Add /version command to check installed and latest versions
- Create version.json metadata file during installation
- Pass version and branch info from install-remote.ps1 to Install-Claude.ps1
- Support version comparison and upgrade recommendations
- Track installation mode (Global/Path) and source branch

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 12:46:44 +08:00

605 lines
19 KiB
PowerShell

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Claude Code Workflow (CCW) - Remote Installation Script
.DESCRIPTION
One-liner remote installation for Claude Code Workflow system.
Downloads and installs CCW from GitHub with flexible version selection.
.PARAMETER Version
Installation version type:
- "stable" (default): Latest stable release tag
- "latest": Latest main branch (development version)
- "branch": Install from specific branch
.PARAMETER Tag
Specific release tag to install (e.g., "v3.2.0")
Only used when Version is "stable"
.PARAMETER Branch
Branch name to install from (default: "main")
Only used when Version is "branch"
.PARAMETER Global
Install to global user directory (~/.claude)
.PARAMETER Directory
Install to custom directory
.PARAMETER Force
Skip confirmation prompts
.PARAMETER NoBackup
Skip backup of existing installation
.PARAMETER NonInteractive
Run in non-interactive mode
.PARAMETER BackupAll
Backup all files including git-ignored files
.EXAMPLE
# Install latest stable release (recommended)
.\install-remote.ps1
.EXAMPLE
# Install specific stable version
.\install-remote.ps1 -Version stable -Tag "v3.2.0"
.EXAMPLE
# Install latest development version
.\install-remote.ps1 -Version latest
.EXAMPLE
# Install from specific branch
.\install-remote.ps1 -Version branch -Branch "feature/new-feature"
.EXAMPLE
# Install to global directory without prompts
.\install-remote.ps1 -Global -Force
.LINK
https://github.com/catlog22/Claude-Code-Workflow
#>
[CmdletBinding()]
param(
[ValidateSet("stable", "latest", "branch")]
[string]$Version = "stable",
[string]$Tag = "",
[string]$Branch = "main",
[switch]$Global,
[string]$Directory = "",
[switch]$Force,
[switch]$NoBackup,
[switch]$NonInteractive,
[switch]$BackupAll
)
# Set encoding for proper Unicode support
if ($PSVersionTable.PSVersion.Major -ge 6) {
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
} else {
# Windows PowerShell 5.1
$OutputEncoding = [System.Text.Encoding]::UTF8
chcp 65001 | Out-Null
}
# Script metadata
$ScriptName = "Claude Code Workflow (CCW) Remote Installer"
$InstallerVersion = "2.2.0"
# Colors for output
$ColorSuccess = "Green"
$ColorInfo = "Cyan"
$ColorWarning = "Yellow"
$ColorError = "Red"
function Write-ColorOutput {
param(
[string]$Message,
[string]$Color = "White"
)
Write-Host $Message -ForegroundColor $Color
}
function Show-Header {
Write-ColorOutput "==== $ScriptName v$InstallerVersion ====" $ColorInfo
Write-ColorOutput "========================================================" $ColorInfo
Write-Host ""
}
function Test-Prerequisites {
# Test PowerShell version
if ($PSVersionTable.PSVersion.Major -lt 5) {
Write-ColorOutput "ERROR: PowerShell 5.1 or higher is required" $ColorError
Write-ColorOutput "Current version: $($PSVersionTable.PSVersion)" $ColorError
return $false
}
# Test internet connectivity
try {
$null = Invoke-WebRequest -Uri "https://github.com" -Method Head -TimeoutSec 10 -UseBasicParsing
Write-ColorOutput "Network connection OK" $ColorSuccess
} catch {
Write-ColorOutput "ERROR: Cannot connect to GitHub" $ColorError
Write-ColorOutput "Please check your network connection: $($_.Exception.Message)" $ColorError
return $false
}
return $true
}
function Get-TempDirectory {
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) "claude-code-workflow-install"
if (Test-Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force
}
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
return $tempDir
}
function Get-LatestRelease {
try {
$apiUrl = "https://api.github.com/repos/catlog22/Claude-Code-Workflow/releases/latest"
$response = Invoke-RestMethod -Uri $apiUrl -UseBasicParsing
return $response.tag_name
} catch {
Write-ColorOutput "WARNING: Failed to fetch latest release, using 'main' branch" $ColorWarning
return $null
}
}
function Download-Repository {
param(
[string]$TempDir,
[string]$Version = "stable",
[string]$Branch = "main",
[string]$Tag = ""
)
$repoUrl = "https://github.com/catlog22/Claude-Code-Workflow"
# Determine download URL based on version type
if ($Version -eq "stable") {
# Download latest stable release
if ([string]::IsNullOrEmpty($Tag)) {
$latestTag = Get-LatestRelease
if ($latestTag) {
$Tag = $latestTag
} else {
# Fallback to main branch if API fails
$zipUrl = "$repoUrl/archive/refs/heads/main.zip"
$downloadType = "main branch (fallback)"
}
}
if (-not [string]::IsNullOrEmpty($Tag)) {
$zipUrl = "$repoUrl/archive/refs/tags/$Tag.zip"
$downloadType = "stable release $Tag"
}
} elseif ($Version -eq "latest") {
# Download latest main branch
$zipUrl = "$repoUrl/archive/refs/heads/main.zip"
$downloadType = "latest main branch"
} else {
# Download specific branch
$zipUrl = "$repoUrl/archive/refs/heads/$Branch.zip"
$downloadType = "branch $Branch"
}
$zipPath = Join-Path $TempDir "repo.zip"
Write-ColorOutput "Downloading from GitHub..." $ColorInfo
Write-ColorOutput "Source: $repoUrl" $ColorInfo
Write-ColorOutput "Type: $downloadType" $ColorInfo
try {
# Download with progress
$progressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing
$ProgressPreference = $progressPreference
if (Test-Path $zipPath) {
$fileSize = (Get-Item $zipPath).Length
Write-ColorOutput "Download complete ($([math]::Round($fileSize/1024/1024, 2)) MB)" $ColorSuccess
return $zipPath
} else {
throw "Downloaded file does not exist"
}
} catch {
Write-ColorOutput "Download failed: $($_.Exception.Message)" $ColorError
return $null
}
}
function Extract-Repository {
param(
[string]$ZipPath,
[string]$TempDir
)
Write-ColorOutput "Extracting files..." $ColorInfo
try {
# Use .NET to extract zip
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipPath, $TempDir)
# Find the extracted directory (usually repo-name-branch)
$extractedDirs = Get-ChildItem -Path $TempDir -Directory
$repoDir = $extractedDirs | Where-Object { $_.Name -like "Claude-Code-Workflow-*" } | Select-Object -First 1
if ($repoDir) {
Write-ColorOutput "Extraction complete: $($repoDir.FullName)" $ColorSuccess
return $repoDir.FullName
} else {
throw "Could not find extracted repository directory"
}
} catch {
Write-ColorOutput "Extraction failed: $($_.Exception.Message)" $ColorError
return $null
}
}
function Invoke-LocalInstaller {
param(
[string]$RepoDir,
[string]$VersionInfo = "",
[string]$BranchInfo = ""
)
$installerPath = Join-Path $RepoDir "Install-Claude.ps1"
if (-not (Test-Path $installerPath)) {
Write-ColorOutput "ERROR: Install-Claude.ps1 not found" $ColorError
return $false
}
Write-ColorOutput "Running local installer..." $ColorInfo
Write-Host ""
# Build parameters for local installer
$params = @{}
if ($Global) { $params["InstallMode"] = "Global" }
if ($Directory) {
$params["InstallMode"] = "Custom"
$params["TargetPath"] = $Directory
}
if ($Force) { $params["Force"] = $Force }
if ($NoBackup) { $params["NoBackup"] = $NoBackup }
if ($NonInteractive) { $params["NonInteractive"] = $NonInteractive }
if ($BackupAll) { $params["BackupAll"] = $BackupAll }
# Pass version and branch information
if ($VersionInfo) { $params["SourceVersion"] = $VersionInfo }
if ($BranchInfo) { $params["SourceBranch"] = $BranchInfo }
try {
# Change to repo directory and run installer
Push-Location $RepoDir
if ($params.Count -gt 0) {
$paramList = ($params.GetEnumerator() | ForEach-Object { "-$($_.Key) $($_.Value)" }) -join " "
Write-ColorOutput "Executing: & `"$installerPath`" $paramList" $ColorInfo
& $installerPath @params
} else {
Write-ColorOutput "Executing: & `"$installerPath`"" $ColorInfo
& $installerPath
}
Pop-Location
return $true
} catch {
Pop-Location
Write-ColorOutput "Installation script failed: $($_.Exception.Message)" $ColorError
return $false
}
}
function Cleanup-TempFiles {
param(
[string]$TempDir
)
if (Test-Path $TempDir) {
try {
Remove-Item -Path $TempDir -Recurse -Force
Write-ColorOutput "Temporary files cleaned up" $ColorInfo
} catch {
Write-ColorOutput "WARNING: Failed to clean temporary files: $($_.Exception.Message)" $ColorWarning
}
}
}
function Wait-ForUserConfirmation {
param(
[string]$Message = "Press any key to continue...",
[switch]$ExitAfter
)
if (-not $NonInteractive) {
Write-Host ""
Write-ColorOutput $Message $ColorInfo
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}
if ($ExitAfter) {
exit 0
}
}
function Show-VersionMenu {
param(
[string]$LatestStableVersion = "Detecting...",
[string]$LatestStableDate = "",
[string]$LatestCommitId = "",
[string]$LatestCommitDate = ""
)
Write-Host ""
Write-ColorOutput "====================================================" $ColorInfo
Write-ColorOutput " Version Selection Menu" $ColorInfo
Write-ColorOutput "====================================================" $ColorInfo
Write-Host ""
# Option 1: Latest Stable
Write-ColorOutput "1) Latest Stable Release (Recommended)" $ColorSuccess
if ($LatestStableVersion -ne "Detecting..." -and $LatestStableVersion -ne "Unknown") {
Write-Host " |-- Version: $LatestStableVersion"
if ($LatestStableDate) {
Write-Host " |-- Released: $LatestStableDate"
}
Write-Host " \-- Production-ready"
} else {
Write-Host " |-- Version: Auto-detected from GitHub"
Write-Host " \-- Production-ready"
}
Write-Host ""
# Option 2: Latest Development
Write-ColorOutput "2) Latest Development Version" $ColorWarning
Write-Host " |-- Branch: main"
if ($LatestCommitId -and $LatestCommitDate) {
Write-Host " |-- Commit: $LatestCommitId"
Write-Host " |-- Updated: $LatestCommitDate"
}
Write-Host " |-- Cutting-edge features"
Write-Host " \-- May contain experimental changes"
Write-Host ""
# Option 3: Specific Version
Write-ColorOutput "3) Specific Release Version" $ColorInfo
Write-Host " |-- Install a specific tagged release"
Write-Host " \-- Recent: v3.2.0, v3.1.0, v3.0.1"
Write-Host ""
Write-ColorOutput "====================================================" $ColorInfo
Write-Host ""
}
function Get-UserVersionChoice {
if ($NonInteractive -or $Force) {
# Non-interactive mode: use default stable version
return @{
Type = "stable"
Tag = $Tag
Branch = $Branch
}
}
# Detect latest stable version and commit info
Write-ColorOutput "Detecting latest release and commits..." $ColorInfo
$latestVersion = "Unknown"
$latestStableDate = ""
$latestCommitId = ""
$latestCommitDate = ""
try {
# Get latest release info
$apiUrl = "https://api.github.com/repos/catlog22/Claude-Code-Workflow/releases/latest"
$response = Invoke-RestMethod -Uri $apiUrl -UseBasicParsing -TimeoutSec 5
$latestVersion = $response.tag_name
# Parse and format release date
if ($response.published_at) {
$publishDate = [DateTime]::Parse($response.published_at)
$latestStableDate = $publishDate.ToString("yyyy-MM-dd HH:mm UTC")
}
Write-ColorOutput "Latest stable: $latestVersion ($latestStableDate)" $ColorSuccess
} catch {
Write-ColorOutput "Could not detect latest release" $ColorWarning
}
try {
# Get latest commit info from main branch
$commitUrl = "https://api.github.com/repos/catlog22/Claude-Code-Workflow/commits/main"
$commitResponse = Invoke-RestMethod -Uri $commitUrl -UseBasicParsing -TimeoutSec 5
$latestCommitId = $commitResponse.sha.Substring(0, 7)
# Parse and format commit date
if ($commitResponse.commit.committer.date) {
$commitDate = [DateTime]::Parse($commitResponse.commit.committer.date)
$latestCommitDate = $commitDate.ToString("yyyy-MM-dd HH:mm UTC")
}
Write-ColorOutput "Latest commit: $latestCommitId ($latestCommitDate)" $ColorSuccess
} catch {
Write-ColorOutput "Could not detect latest commit" $ColorWarning
}
Show-VersionMenu -LatestStableVersion $latestVersion -LatestStableDate $latestStableDate -LatestCommitId $latestCommitId -LatestCommitDate $latestCommitDate
$choice = Read-Host "Select version to install (1-3, default: 1)"
switch ($choice) {
"2" {
Write-Host ""
Write-ColorOutput "✓ Selected: Latest Development Version (main branch)" $ColorSuccess
return @{
Type = "latest"
Tag = ""
Branch = "main"
}
}
"3" {
Write-Host ""
Write-ColorOutput "Available recent releases:" $ColorInfo
Write-Host " v3.2.0, v3.1.0, v3.0.1, v3.0.0"
Write-Host ""
$tagInput = Read-Host "Enter version tag (e.g., v3.2.0)"
if ([string]::IsNullOrWhiteSpace($tagInput)) {
Write-ColorOutput "No tag specified, using latest stable" $ColorWarning
return @{
Type = "stable"
Tag = ""
Branch = "main"
}
}
Write-ColorOutput "✓ Selected: Specific Version $tagInput" $ColorSuccess
return @{
Type = "stable"
Tag = $tagInput
Branch = "main"
}
}
default {
Write-Host ""
if ($latestVersion -ne "Unknown") {
Write-ColorOutput "✓ Selected: Latest Stable Release ($latestVersion)" $ColorSuccess
} else {
Write-ColorOutput "✓ Selected: Latest Stable Release (auto-detect)" $ColorSuccess
}
return @{
Type = "stable"
Tag = ""
Branch = "main"
}
}
}
}
function Main {
Show-Header
Write-ColorOutput "This will download and install Claude Code Workflow System from GitHub." $ColorInfo
Write-Host ""
# Test prerequisites
Write-ColorOutput "Checking system requirements..." $ColorInfo
if (-not (Test-Prerequisites)) {
Wait-ForUserConfirmation "System check failed! Press any key to exit..." -ExitAfter
}
# Get version choice from user (interactive menu)
$versionChoice = Get-UserVersionChoice
$script:Version = $versionChoice.Type
$script:Tag = $versionChoice.Tag
$script:Branch = $versionChoice.Branch
# Determine version information for display
$versionInfo = switch ($Version) {
"stable" {
if ($Tag) { "Stable release: $Tag" }
else { "Latest stable release (auto-detected)" }
}
"latest" { "Latest main branch (development)" }
"branch" { "Custom branch: $Branch" }
}
# Confirm installation
if (-not $NonInteractive -and -not $Force) {
Write-Host ""
Write-ColorOutput "INSTALLATION DETAILS:" $ColorInfo
Write-Host "- Repository: https://github.com/catlog22/Claude-Code-Workflow"
Write-Host "- Version: $versionInfo"
Write-Host "- Features: Intelligent workflow orchestration with multi-agent coordination"
Write-Host ""
Write-ColorOutput "SECURITY NOTE:" $ColorWarning
Write-Host "- This script will download and execute code from GitHub"
Write-Host "- Please ensure you trust this source"
Write-Host ""
$choice = Read-Host "Continue with installation? (y/N)"
if ($choice -notmatch '^[Yy]') {
Write-ColorOutput "Installation cancelled" $ColorWarning
Wait-ForUserConfirmation -ExitAfter
}
}
# Create temp directory
$tempDir = Get-TempDirectory
Write-ColorOutput "Temporary directory: $tempDir" $ColorInfo
try {
# Download repository
$zipPath = Download-Repository -TempDir $tempDir -Version $Version -Branch $Branch -Tag $Tag
if (-not $zipPath) {
throw "Download failed"
}
# Extract repository
$repoDir = Extract-Repository $zipPath $tempDir
if (-not $repoDir) {
throw "Extraction failed"
}
# Determine version and branch information to pass
$versionToPass = if ($Tag) { $Tag } else { "latest" }
$branchToPass = if ($Version -eq "branch") { $Branch } elseif ($Version -eq "latest") { "main" } elseif ($Tag) { $Tag } else { "main" }
Write-ColorOutput "Version info: $versionToPass (branch: $branchToPass)" $ColorInfo
# Run local installer with version information
$success = Invoke-LocalInstaller -RepoDir $repoDir -VersionInfo $versionToPass -BranchInfo $branchToPass
if (-not $success) {
throw "Installation script failed"
}
Write-Host ""
Write-ColorOutput "Remote installation completed successfully!" $ColorSuccess
} catch {
Write-Host ""
Write-ColorOutput "Remote installation failed: $($_.Exception.Message)" $ColorError
Wait-ForUserConfirmation "Installation failed! Press any key to exit..." -ExitAfter
} finally {
# Cleanup
Cleanup-TempFiles $tempDir
}
Write-Host ""
Write-ColorOutput "Next steps:" $ColorInfo
Write-Host "1. Review CLAUDE.md for project-specific guidelines"
Write-Host "2. Try /workflow commands for Agent coordination"
Write-Host "3. Use /update-memory to manage distributed documentation"
Wait-ForUserConfirmation "Remote installation done! Press any key to exit..." -ExitAfter
}
# Run main function
try {
Main
} catch {
Write-ColorOutput "CRITICAL ERROR: $($_.Exception.Message)" $ColorError
Write-Host ""
Wait-ForUserConfirmation "A critical error occurred! Press any key to exit..." -ExitAfter
}