-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinstall.ps1
More file actions
360 lines (312 loc) · 12.8 KB
/
install.ps1
File metadata and controls
360 lines (312 loc) · 12.8 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# Codex SEO Installer for Windows
# PowerShell installation script
$ErrorActionPreference = "Stop"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Codex SEO - Installer" -ForegroundColor Cyan
Write-Host " Codex Skill Suite" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
function Resolve-Python {
$pythonCmd = Get-Command -Name python -ErrorAction SilentlyContinue
if ($null -ne $pythonCmd) {
return @{ Exe = "python"; Args = @() }
}
$pyCmd = Get-Command -Name py -ErrorAction SilentlyContinue
if ($null -ne $pyCmd) {
return @{ Exe = "py"; Args = @("-3") }
}
return $null
}
function Invoke-External {
param(
[Parameter(Mandatory = $true)][string]$Exe,
[Parameter(Mandatory = $true)][string[]]$Args,
[switch]$Quiet
)
$stdoutPath = [System.IO.Path]::GetTempFileName()
$stderrPath = [System.IO.Path]::GetTempFileName()
try {
$process = Start-Process `
-FilePath $Exe `
-ArgumentList $Args `
-NoNewWindow `
-Wait `
-PassThru `
-RedirectStandardOutput $stdoutPath `
-RedirectStandardError $stderrPath
$stdout = if (Test-Path $stdoutPath) { Get-Content -Path $stdoutPath -Raw } else { "" }
$stderr = if (Test-Path $stderrPath) { Get-Content -Path $stderrPath -Raw } else { "" }
$combined = @($stdout, $stderr) -join ""
$output = if ([string]::IsNullOrWhiteSpace($combined)) { @() } else { $combined -split "`r?`n" }
$exitCode = $process.ExitCode
} finally {
Remove-Item -Force $stdoutPath, $stderrPath -ErrorAction SilentlyContinue
}
if (-not $Quiet -and $null -ne $output -and $output.Count -gt 0) {
$output | ForEach-Object { Write-Host $_ }
}
return @{ ExitCode = $exitCode; Output = $output }
}
function Test-Truthy {
param([string]$Value)
if ([string]::IsNullOrWhiteSpace($Value)) {
return $false
}
return @("1", "true", "yes", "on") -contains $Value.Trim().ToLowerInvariant()
}
function Get-JsonObjectText {
param([string[]]$Output)
$text = ($Output -join "`n").Trim()
if ([string]::IsNullOrWhiteSpace($text)) {
return ""
}
$start = $text.IndexOf("{")
$end = $text.LastIndexOf("}")
if ($start -ge 0 -and $end -gt $start) {
return $text.Substring($start, $end - $start + 1).Trim()
}
return $text
}
function ConvertFrom-JsonCompat {
param(
[Parameter(Mandatory = $true)][string]$Json,
[Parameter(Mandatory = $true)][string]$ErrorMessage
)
try {
return $Json | ConvertFrom-Json
} catch {
$nativeParserError = $_.Exception.Message
if ($null -ne $script:python) {
$summaryScript = @'
import json
import sys
payload = json.loads(sys.stdin.read())
verification = payload.get("verification") or {}
summary = {
"ok": bool(payload.get("ok")),
"full_ready": bool(payload.get("full_ready")),
"python": payload.get("python") or "",
"optional_failed_groups": payload.get("optional_failed_groups") or [],
"verification": {"notes": verification.get("notes") or []},
"error": payload.get("error") or "",
}
print(json.dumps(summary))
'@
try {
$summaryJson = $Json | & $script:python.Exe @($script:python.Args + @("-c", $summaryScript)) 2>$null
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($summaryJson)) {
return $summaryJson | ConvertFrom-Json
}
} catch {
# Fall through to the detailed native parser error below.
}
}
$preview = $Json
if ($preview.Length -gt 1200) {
$preview = $preview.Substring(0, 1200) + "`n...[truncated]"
}
Write-Host "[ERROR] $ErrorMessage" -ForegroundColor Red
Write-Host "[ERROR] PowerShell JSON parser error: $nativeParserError" -ForegroundColor Red
if (-not [string]::IsNullOrWhiteSpace($preview)) {
Write-Host "[ERROR] Bootstrap output preview:" -ForegroundColor Red
Write-Host $preview
}
throw $ErrorMessage
}
}
function Remove-PathIfExists {
param([string]$Path)
if (Test-Path $Path) {
Remove-Item -Path $Path -Recurse -Force
}
}
$python = Resolve-Python
if ($null -eq $python) {
Write-Host "[ERROR] Python 3 is required but was not found in PATH." -ForegroundColor Red
exit 1
}
try {
$pythonVersionOutput = (& $python.Exe @($python.Args + @("--version")) 2>&1 | Select-Object -Last 1).ToString().Trim()
} catch {
Write-Host "[ERROR] Failed to determine Python version." -ForegroundColor Red
exit 1
}
if ($pythonVersionOutput -notmatch "Python\s+(\d+)\.(\d+)") {
Write-Host "[ERROR] Failed to parse Python version from: $pythonVersionOutput" -ForegroundColor Red
exit 1
}
$pythonMajor = [int]$Matches[1]
$pythonMinor = [int]$Matches[2]
$pythonVersion = "$pythonMajor.$pythonMinor"
if ($pythonMajor -lt 3 -or ($pythonMajor -eq 3 -and $pythonMinor -lt 10)) {
Write-Host "[ERROR] Python 3.10+ is required but $pythonVersion was found." -ForegroundColor Red
exit 1
}
Write-Host "[OK] Python $pythonVersion detected" -ForegroundColor Green
$gitCmd = Get-Command -Name git -ErrorAction SilentlyContinue
if ($null -eq $gitCmd) {
Write-Host "[ERROR] Git is required but not installed." -ForegroundColor Red
exit 1
}
$codexRoot = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $HOME ".codex" }
$skillsRoot = Join-Path $codexRoot "skills"
$agentDir = Join-Path $codexRoot "agents"
$skillDir = Join-Path $skillsRoot "seo"
$repoUrl = if ($env:CODEX_SEO_REPO) { $env:CODEX_SEO_REPO } else { "https://github.com/AgriciDaniel/codex-seo" }
$repoRef = if ($env:CODEX_SEO_REF) { $env:CODEX_SEO_REF } else { "v1.9.6-codex.5" }
$skipPlaywrightBrowser = Test-Truthy $env:CODEX_SEO_SKIP_PLAYWRIGHT_BROWSER
$playwrightWithDeps = Test-Truthy $env:CODEX_SEO_PLAYWRIGHT_WITH_DEPS
$suiteSkillDirs = @(
"seo",
"seo-audit",
"seo-backlinks",
"seo-cluster",
"seo-competitor-pages",
"seo-content",
"seo-dataforseo",
"seo-drift",
"seo-ecommerce",
"seo-flow",
"seo-firecrawl",
"seo-geo",
"seo-google",
"seo-hreflang",
"seo-image-gen",
"seo-images",
"seo-local",
"seo-maps",
"seo-page",
"seo-performance",
"seo-plan",
"seo-programmatic",
"seo-schema",
"seo-sitemap",
"seo-sxo",
"seo-technical",
"seo-visual"
)
New-Item -ItemType Directory -Force -Path $skillsRoot | Out-Null
New-Item -ItemType Directory -Force -Path $agentDir | Out-Null
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Force -Path $tempDir | Out-Null
try {
$checkoutDir = Join-Path $tempDir "codex-seo"
Write-Host "[INFO] Downloading Codex SEO ($repoRef)..." -ForegroundColor Yellow
$cloneResult = Invoke-External -Exe "git" -Args @("clone", "--depth", "1", "--branch", $repoRef, $repoUrl, $checkoutDir)
if ($cloneResult.ExitCode -ne 0) {
throw "Unable to download ref $repoRef. Confirm the branch/tag exists and your Git credentials can access $repoUrl."
}
$commitResult = Invoke-External -Exe "git" -Args @("-C", $checkoutDir, "rev-parse", "HEAD") -Quiet
if ($commitResult.ExitCode -ne 0 -or $commitResult.Output.Count -eq 0) {
throw "Unable to resolve the installed Codex SEO commit."
}
$installedCommit = $commitResult.Output[0].Trim()
Write-Host "[INFO] Resetting existing Codex SEO install..." -ForegroundColor Yellow
foreach ($suiteName in $suiteSkillDirs) {
Remove-PathIfExists -Path (Join-Path $skillsRoot $suiteName)
}
Get-ChildItem -Path $agentDir -Filter "seo-*.md" -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path $agentDir -Filter "seo-*.toml" -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "[INFO] Installing skill files..." -ForegroundColor Yellow
$skillsSource = Join-Path $checkoutDir "skills"
if (Test-Path $skillsSource) {
Get-ChildItem -Path $skillsSource -Directory | ForEach-Object {
$target = Join-Path $skillsRoot $_.Name
New-Item -ItemType Directory -Force -Path $target | Out-Null
Copy-Item -Path (Join-Path $_.FullName "*") -Destination $target -Recurse -Force
}
}
foreach ($pathName in @("scripts", "schema", "pdf", "hooks", "extensions")) {
$sourcePath = Join-Path $checkoutDir $pathName
if (Test-Path $sourcePath) {
$targetPath = Join-Path $skillDir $pathName
New-Item -ItemType Directory -Force -Path $targetPath | Out-Null
Copy-Item -Path (Join-Path $sourcePath "*") -Destination $targetPath -Recurse -Force
}
}
Get-ChildItem -Path $checkoutDir -Filter "requirements*.txt" -File -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item -Path $_.FullName -Destination (Join-Path $skillDir $_.Name) -Force
}
foreach ($doc in @("CHANGELOG.md", "README.md")) {
$sourceDoc = Join-Path $checkoutDir $doc
if (Test-Path $sourceDoc) {
Copy-Item -Path $sourceDoc -Destination (Join-Path $skillDir $doc) -Force
}
}
Write-Host "[INFO] Installing agent profiles..." -ForegroundColor Yellow
$agentsSource = Join-Path $checkoutDir "agents"
if (Test-Path $agentsSource) {
Copy-Item -Path (Join-Path $agentsSource "*.toml") -Destination $agentDir -Force
}
$bootstrapScript = Join-Path $skillDir "scripts\bootstrap_environment.py"
if (-not (Test-Path $bootstrapScript)) {
throw "Bootstrap script was not installed to $bootstrapScript."
}
Write-Host "[INFO] Bootstrapping Python runtime..." -ForegroundColor Yellow
$bootstrapJsonPath = Join-Path $tempDir "bootstrap-result.json"
$bootstrapArgs = @()
$bootstrapArgs += $python.Args
$bootstrapArgs += @(
$bootstrapScript,
"--venv",
(Join-Path $skillDir ".venv"),
"--json",
"--json-output",
$bootstrapJsonPath
)
if ($skipPlaywrightBrowser) {
$bootstrapArgs += "--skip-playwright-browser"
}
if ($playwrightWithDeps) {
$bootstrapArgs += "--with-deps"
}
$bootstrapResult = Invoke-External -Exe $python.Exe -Args $bootstrapArgs -Quiet
$bootstrapJson = ""
if (Test-Path $bootstrapJsonPath) {
$bootstrapJson = Get-Content -Path $bootstrapJsonPath -Raw
}
if ([string]::IsNullOrWhiteSpace($bootstrapJson)) {
$bootstrapJson = Get-JsonObjectText -Output $bootstrapResult.Output
}
if ([string]::IsNullOrWhiteSpace($bootstrapJson)) {
throw "Bootstrap script did not produce JSON output."
}
$bootstrapPayload = ConvertFrom-JsonCompat -Json $bootstrapJson -ErrorMessage "Bootstrap script produced invalid JSON output."
if ($bootstrapResult.ExitCode -ne 0 -or -not $bootstrapPayload.ok) {
$verificationNotes = @()
if ($null -ne $bootstrapPayload.verification -and $null -ne $bootstrapPayload.verification.notes) {
$verificationNotes = @($bootstrapPayload.verification.notes)
}
if ($verificationNotes.Count -gt 0) {
$verificationNotes | ForEach-Object { Write-Host "[ERROR] $_" -ForegroundColor Red }
}
throw "Codex SEO runtime bootstrap failed."
}
$optionalFailedGroups = @()
if ($null -ne $bootstrapPayload.optional_failed_groups) {
$optionalFailedGroups = @($bootstrapPayload.optional_failed_groups)
}
if (-not $bootstrapPayload.full_ready -or $optionalFailedGroups.Count -gt 0) {
Write-Host "[WARN] Core SEO workflows are ready, but one or more extended capabilities are limited. Run the verifier below for details." -ForegroundColor Yellow
}
if ($optionalFailedGroups.Count -gt 0) {
Write-Host "[WARN] Optional bootstrap groups failed: $($optionalFailedGroups -join ', ')" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "[OK] Codex SEO installed successfully!" -ForegroundColor Green
Write-Host ""
Write-Host "Commit: $installedCommit"
Write-Host "Installed to: $skillDir"
Write-Host "Agents installed to: $agentDir"
Write-Host "Python runtime: $($bootstrapPayload.python)"
Write-Host ""
Write-Host "Next steps:"
Write-Host " 1. Restart Codex CLI if it is already running"
Write-Host " 2. Verify the runtime: $($bootstrapPayload.python) $skillDir\scripts\verify_environment.py"
Write-Host " 3. Ask Codex to use the SEO skill for an audit or content task"
Write-Host ""
} finally {
if (Test-Path $tempDir) {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}