-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.ps1
More file actions
228 lines (180 loc) · 5.65 KB
/
Copy pathupgrade.ps1
File metadata and controls
228 lines (180 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<#
.SYNOPSIS
Enterprise Code Upgrader v3 — PowerShell wrapper
.DESCRIPTION
Recursively upgrades code files to enterprise quality using Claude Code CLI.
Maintains a SINGLE conversation. Runs headlessly in terminal.
Default: creates an upgrade branch, you review + merge.
.EXAMPLE
.\upgrade.ps1 -ProjectPath "C:\Users\subha\projects\penora\backend"
.\upgrade.ps1 -ProjectPath "." -Include "backend/**/*.py" -CommitEvery 5
.\upgrade.ps1 -ProjectPath "." -Include "backend/**/*.py" -Push
.\upgrade.ps1 -ProjectPath "." -Include "backend/**/*.py" -Direct
.\upgrade.ps1 -ProjectPath "." -Include "backend/**/*.py" -NoPersist
.\upgrade.ps1 -ProjectPath "." -Include "src/**/*.ts","src/**/*.tsx"
.\upgrade.ps1 -ProjectPath "." -Include "**/*.py" -DryRun
.\upgrade.ps1 -ProjectPath "." -Include "**/*.py" -ResetState
.\upgrade.ps1 -ProjectPath "." -Backend api -ApiKey "sk-ant-..."
.\upgrade.ps1 -ProjectPath "." -Branch "upgrade/my-feature"
#>
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$ProjectPath,
[string[]]$Include = @("**/*.*"),
[string[]]$Exclude = @(),
[ValidateSet("api", "cli", "opencode")]
[string]$Backend = "cli",
[string]$Model,
[string]$PlanningModel,
[string]$SystemPrompt,
[switch]$DryRun,
[int]$CommitEvery = 1,
[switch]$NoCommit,
[switch]$NoBatch,
[int]$BatchSize = 3,
[string]$OutputDir,
[double]$Delay = 2.0,
[switch]$SkipDone,
[switch]$ResetState,
[string]$FallbackModel,
[double]$MaxBudget,
[ValidateSet("low", "medium", "high", "max")]
[string]$Effort = "max",
[switch]$NoJsonSchema,
[switch]$NoPersist,
[string]$Branch,
[string]$FromBranch,
[switch]$Direct,
[switch]$Push,
[switch]$Hybrid,
[switch]$Explore,
[switch]$NoExploreCutoff,
[int]$MaxReads = 5,
[string]$ApiKey
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Set API key if provided
if ($ApiKey) {
$env:ANTHROPIC_API_KEY = $ApiKey
}
# Verify Python
try {
$pythonVersion = python --version 2>&1
Write-Host "Using $pythonVersion" -ForegroundColor Cyan
}
catch {
Write-Host "ERROR: Python not found. Install Python 3.10+ and add to PATH." -ForegroundColor Red
exit 1
}
# Verify backend dependencies
if ($Backend -eq "cli") {
try {
claude --version 2>&1 | Out-Null
}
catch {
Write-Host "ERROR: Claude Code CLI not found." -ForegroundColor Red
Write-Host " npm install -g @anthropic-ai/claude-code" -ForegroundColor Gray
exit 1
}
}
elseif ($Backend -eq "api") {
# API backend — requires Anthropic SDK + API key
$check = python -c "import anthropic" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Installing anthropic SDK..." -ForegroundColor Yellow
pip install anthropic
}
if (-not $env:ANTHROPIC_API_KEY) {
Write-Host "ERROR: Set ANTHROPIC_API_KEY or pass -ApiKey parameter." -ForegroundColor Red
Write-Host ' $env:ANTHROPIC_API_KEY = "sk-ant-..."' -ForegroundColor Gray
exit 1
}
}
# opencode backend — no SDK or API key needed (uses `opencode` CLI)
# Build command
$pyScript = Join-Path $ScriptDir "upgrade_codebase.py"
$cmd = @("python", $pyScript, $ProjectPath)
$cmd += "--include"
$cmd += $Include
$cmd += "--backend"
$cmd += $Backend
if ($Exclude.Count -gt 0) {
$cmd += "--exclude"
$cmd += $Exclude
}
if ($Model) {
$cmd += "--model"
$cmd += $Model
}
if ($SystemPrompt) {
$cmd += "--system-prompt"
$cmd += $SystemPrompt
}
if ($DryRun) { $cmd += "--dry-run" }
if ($NoCommit) { $cmd += "--no-commit" }
if ($NoBatch) { $cmd += "--no-batch" }
if ($SkipDone) { $cmd += "--skip-done" }
if ($ResetState) { $cmd += "--reset-state" }
if ($NoJsonSchema) { $cmd += "--no-json-schema" }
if ($NoPersist) { $cmd += "--no-persist" }
if ($Direct) { $cmd += "--direct" }
if ($Push) { $cmd += "--push" }
if ($Hybrid) { $cmd += "--hybrid" }
if ($Explore) { $cmd += "--explore" }
if ($NoExploreCutoff) { $cmd += "--no-explore-cutoff" }
$cmd += "--max-reads"
$cmd += $MaxReads.ToString()
if ($PlanningModel) {
$cmd += "--planning-model"
$cmd += $PlanningModel
}
if ($Branch) {
$cmd += "--branch"
$cmd += $Branch
}
if ($FromBranch) {
$cmd += "--from-branch"
$cmd += $FromBranch
}
if ($FallbackModel) {
$cmd += "--fallback-model"
$cmd += $FallbackModel
}
if ($MaxBudget -gt 0) {
$cmd += "--max-budget"
$cmd += $MaxBudget.ToString()
}
$cmd += "--effort"
$cmd += $Effort
$cmd += "--commit-every"
$cmd += $CommitEvery.ToString()
$cmd += "--batch-size"
$cmd += $BatchSize.ToString()
$cmd += "--delay"
$cmd += $Delay.ToString()
if ($OutputDir) {
$cmd += "--output-dir"
$cmd += $OutputDir
}
# Run
Write-Host ""
Write-Host "================================================================" -ForegroundColor Green
Write-Host " Enterprise Code Upgrader v3" -ForegroundColor Green
Write-Host " Claude Code CLI (default) | Syntax validation | Headless" -ForegroundColor Green
Write-Host "================================================================" -ForegroundColor Green
Write-Host ""
Write-Host " Project: $ProjectPath" -ForegroundColor White
Write-Host " Backend: $Backend" -ForegroundColor White
Write-Host " Include: $($Include -join ', ')" -ForegroundColor White
Write-Host " Commit every: $CommitEvery file(s)" -ForegroundColor White
Write-Host ""
& $cmd[0] $cmd[1..($cmd.Count - 1)]
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
Write-Host "`nAll done." -ForegroundColor Green
}
else {
Write-Host "`nFinished with errors (exit code: $exitCode)" -ForegroundColor Yellow
}
exit $exitCode