@@ -60,14 +60,29 @@ if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
6060Write-Host " ${GREEN} ✓${NC} uv detected"
6161Write-Host " "
6262
63+ try {
64+ $uvOutput = uv tool list 2> $null
65+ } catch {
66+ $uvOutput = @ ()
67+ }
68+
6369# Install or upgrade codeplain using uv tool
64- $codeplainLine = @ (uv tool list 2> $null ) | Where-Object { $_ -match ' ^codeplain' } | Select-Object - First 1
70+ $codeplainLine = $uvOutput | Where-Object { $_ -match ' ^codeplain' } | Select-Object - First 1
6571if ($codeplainLine ) {
6672 $currentVersion = ($codeplainLine -replace ' codeplain v' , ' ' ).Trim()
6773 Write-Host " ${GRAY} codeplain ${currentVersion} is already installed.${NC} "
6874 Write-Host " upgrading to latest version..."
6975 Write-Host " "
70- uv tool upgrade codeplain 2>&1 | Out-Null
76+
77+ try {
78+ $upgradeOutput = & uv tool upgrade codeplain 2>&1
79+ if ($LASTEXITCODE -ne 0 ) {
80+ throw " uv exited with code $LASTEXITCODE "
81+ }
82+ } catch {
83+ Write-Host " ${RED} Failed to upgrade codeplain.${NC} "
84+ Write-Host $_
85+ }
7186 $newLine = @ (uv tool list 2> $null ) | Where-Object { $_ -match ' ^codeplain' } | Select-Object - First 1
7287 $newVersion = ($newLine -replace ' codeplain v' , ' ' ).Trim()
7388 if ($currentVersion -eq $newVersion ) {
@@ -83,6 +98,24 @@ if ($codeplainLine) {
8398 Write-Host " ${GREEN} ✓ codeplain installed successfully!${NC} "
8499}
85100
101+ # Ensure uv tool bin directory is on user PATH permanently (so codeplain is available)
102+ $uvBinDir = Join-Path $env: USERPROFILE ' .local\bin'
103+ $userPath = [Environment ]::GetEnvironmentVariable(' Path' , ' User' )
104+ if ($userPath ) {
105+ $pathEntries = $userPath -split ' ;' | ForEach-Object { $_.Trim () } | Where-Object { $_ }
106+ if ($uvBinDir -notin $pathEntries ) {
107+ $newPath = ($userPath.TrimEnd (' ;' ) + ' ;' + $uvBinDir )
108+ [Environment ]::SetEnvironmentVariable(' Path' , $newPath , ' User' )
109+ $env: Path = $uvBinDir + ' ;' + $env: Path
110+ Write-Host " ${GREEN} ✓${NC} added $uvBinDir to your user PATH"
111+ }
112+ } else {
113+ [Environment ]::SetEnvironmentVariable(' Path' , $uvBinDir , ' User' )
114+ $env: Path = $uvBinDir + ' ;' + $env: Path
115+ Write-Host " ${GREEN} ✓${NC} added $uvBinDir to your user PATH"
116+ }
117+ Write-Host " "
118+
86119# Check if API key already exists
87120$skipApiKeySetup = $false
88121if ($env: CODEPLAIN_API_KEY ) {
0 commit comments