forked from AgriciDaniel/claude-seo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
376 lines (337 loc) · 14.6 KB
/
Copy pathinstall.ps1
File metadata and controls
376 lines (337 loc) · 14.6 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# Kimi SEO Installer for Windows
# PowerShell installation script
#
# Kimi Code is the primary install target. Pass -Claude to install into the
# Claude Code layout instead (upstream parity).
param(
[switch]$Claude
)
$ErrorActionPreference = "Stop"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "| Kimi SEO - Installer |" -ForegroundColor Cyan
Write-Host "| Kimi Code SEO Skill |" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
function Resolve-Python {
$candidates = @(
@{ Exe = 'py'; Args = @('-3') },
@{ Exe = 'python3'; Args = @() },
@{ Exe = 'python'; Args = @() }
)
foreach ($candidate in $candidates) {
$resolved = Test-PythonCandidate -Exe $candidate.Exe -Args $candidate.Args
if ($null -ne $resolved) {
return $resolved
}
}
return $null
}
function Invoke-External {
param(
[Parameter(Mandatory = $true)][string]$Exe,
[Parameter(Mandatory = $true)][string[]]$Args,
[switch]$Quiet
)
$previousErrorActionPreference = $ErrorActionPreference
$hasNativePreference = $null -ne (Get-Variable -Name PSNativeCommandUseErrorActionPreference -ErrorAction SilentlyContinue)
if ($hasNativePreference) {
$previousNativePreference = $PSNativeCommandUseErrorActionPreference
}
try {
$ErrorActionPreference = 'Continue'
if ($hasNativePreference) {
$PSNativeCommandUseErrorActionPreference = $false
}
$output = & $Exe @Args 2>&1 | ForEach-Object { $_.ToString() }
$exitCode = $LASTEXITCODE
} finally {
$ErrorActionPreference = $previousErrorActionPreference
if ($hasNativePreference) {
$PSNativeCommandUseErrorActionPreference = $previousNativePreference
}
}
if (-not $Quiet -and $null -ne $output -and $output.Count -gt 0) {
$output | ForEach-Object { Write-Host $_ }
}
return @{ ExitCode = $exitCode; Output = $output }
}
function Test-PythonCandidate {
param(
[Parameter(Mandatory = $true)][string]$Exe,
[Parameter(Mandatory = $true)][string[]]$Args
)
$pythonCmd = Get-Command -Name $Exe -ErrorAction SilentlyContinue
if ($null -eq $pythonCmd) {
return $null
}
$probeCode = 'import sys; print(sys.executable); print(sys.version.split()[0]); raise SystemExit(0 if sys.version_info >= (3, 10) else 1)'
$probe = Invoke-External -Exe $Exe -Args @($Args + @('-c', $probeCode)) -Quiet
$probeText = ($probe.Output -join "`n")
if ($probe.ExitCode -ne 0) {
return $null
}
if ($probeText -match 'Microsoft Store|WindowsApps|App execution alias|was not found') {
return $null
}
return @{ Exe = $Exe; Args = $Args }
}
# Check prerequisites
$python = Resolve-Python
if ($null -eq $python) {
Write-Host "[x] Python is required but was not found (tried 'py -3', 'python3', and 'python')." -ForegroundColor Red
exit 1
}
try {
$pythonVersion = & $python.Exe @($python.Args + @('--version')) 2>&1
Write-Host "[+] $pythonVersion detected" -ForegroundColor Green
} catch {
Write-Host "[x] Python is installed but could not be executed." -ForegroundColor Red
exit 1
}
try {
git --version | Out-Null
Write-Host "[+] Git detected" -ForegroundColor Green
} catch {
Write-Host "[x] Git is required but not installed." -ForegroundColor Red
exit 1
}
# Set paths
if ($Claude) {
$SkillsHome = "$env:USERPROFILE\.claude\skills"
$AgentDir = "$env:USERPROFILE\.claude\agents"
} else {
$SkillsHome = "$env:USERPROFILE\.kimi-code\skills"
$AgentDir = "$env:USERPROFILE\.agents\agents"
}
$SkillDir = "$SkillsHome\seo"
$RepoUrl = "https://github.com/bentocodeing/kimi-seo"
# Pin to a specific release tag to prevent silent updates from main.
# This default MUST be bumped on every release. CI guard
# (tests/test_manifest_consistency.py) enforces this matches kimi.plugin.json.
# Override: $env:KIMI_SEO_TAG = 'main'; .\install.ps1
$RepoTag = if ($env:KIMI_SEO_TAG) { $env:KIMI_SEO_TAG } else { 'v1.0.0' }
# Create directories
New-Item -ItemType Directory -Force -Path $SkillDir | Out-Null
New-Item -ItemType Directory -Force -Path $AgentDir | Out-Null
# Clone to temp directory
$TempDir = Join-Path $env:TEMP "kimi-seo-install"
if (Test-Path $TempDir) {
Remove-Item -Recurse -Force $TempDir
}
$keepTemp = ($env:KIMI_SEO_KEEP_TEMP -eq '1') -or ($env:CLAUDE_SEO_KEEP_TEMP -eq '1')
try {
Write-Host ">> Downloading Kimi SEO ($RepoTag)..." -ForegroundColor Yellow
$clone = Invoke-External -Exe 'git' -Args @('clone','--depth','1','--branch',$RepoTag,$RepoUrl,$TempDir) -Quiet
if ($clone.ExitCode -ne 0) {
throw "git clone failed. Output:`n$($clone.Output -join "`n")"
}
# Copy skill files
Write-Host "=> Installing skill files..." -ForegroundColor Yellow
$skillSource = Join-Path $TempDir 'skills\seo'
if (-not (Test-Path $skillSource)) {
throw "Could not find skill source folder in repo clone."
}
Copy-Item -Recurse -Force (Join-Path $skillSource '*') $SkillDir
# Copy sub-skills
$SkillsPath = "$TempDir\skills"
if (Test-Path $SkillsPath) {
Get-ChildItem -Directory $SkillsPath | ForEach-Object {
$target = "$SkillsHome\$($_.Name)"
New-Item -ItemType Directory -Force -Path $target | Out-Null
Copy-Item -Recurse -Force "$($_.FullName)\*" $target
}
}
# Copy schema templates
$SchemaPath = "$TempDir\schema"
if (Test-Path $SchemaPath) {
$SkillSchema = "$SkillDir\schema"
New-Item -ItemType Directory -Force -Path $SkillSchema | Out-Null
Copy-Item -Recurse -Force "$SchemaPath\*" $SkillSchema
}
# Copy reference docs
$PdfPath = "$TempDir\pdf"
if (Test-Path $PdfPath) {
$SkillPdf = "$SkillDir\pdf"
New-Item -ItemType Directory -Force -Path $SkillPdf | Out-Null
Copy-Item -Recurse -Force "$PdfPath\*" $SkillPdf
}
# Copy agents
Write-Host "=> Installing subagents..." -ForegroundColor Yellow
$AgentsPath = Join-Path $TempDir 'agents'
if (Test-Path $AgentsPath) {
Copy-Item -Force (Join-Path $AgentsPath '*.md') $AgentDir -ErrorAction SilentlyContinue
}
# Copy shared scripts
$ScriptsPath = "$TempDir\scripts"
if (Test-Path $ScriptsPath) {
$SkillScripts = "$SkillDir\scripts"
New-Item -ItemType Directory -Force -Path $SkillScripts | Out-Null
Copy-Item -Recurse -Force "$ScriptsPath\*" $SkillScripts
}
# Copy the stable launcher used by skill and agent instructions.
$BinPath = Join-Path $TempDir 'bin'
$SkillBin = Join-Path $SkillDir 'bin'
if (Test-Path (Join-Path $BinPath 'kimi-seo')) {
New-Item -ItemType Directory -Force -Path $SkillBin | Out-Null
Copy-Item -Force (Join-Path $BinPath 'kimi-seo') (Join-Path $SkillBin 'kimi-seo')
}
# Copy hooks
Write-Host " Note: hook enforcement requires plugin install; manual hook copy is best-effort." -ForegroundColor Yellow
$HooksPath = "$TempDir\hooks"
if (Test-Path $HooksPath) {
$SkillHooks = "$SkillDir\hooks"
New-Item -ItemType Directory -Force -Path $SkillHooks | Out-Null
Copy-Item -Recurse -Force "$HooksPath\*" $SkillHooks
}
# Copy extensions (optional add-ons: dataforseo, banana)
$ExtensionsPath = Join-Path $TempDir 'extensions'
if (Test-Path $ExtensionsPath) {
Write-Host "=> Installing extensions..." -ForegroundColor Yellow
Get-ChildItem -Directory $ExtensionsPath | ForEach-Object {
$extName = $_.Name
$extDir = $_.FullName
# Extension skills
$extSkills = Join-Path $extDir 'skills'
if (Test-Path $extSkills) {
Get-ChildItem -Directory $extSkills | ForEach-Object {
$target = "$SkillsHome\$($_.Name)"
New-Item -ItemType Directory -Force -Path $target | Out-Null
Copy-Item -Recurse -Force "$($_.FullName)\*" $target
}
}
# Extension agents
$extAgents = Join-Path $extDir 'agents'
if (Test-Path $extAgents) {
Copy-Item -Force (Join-Path $extAgents '*.md') $AgentDir -ErrorAction SilentlyContinue
}
# Extension references
$extRefs = Join-Path $extDir 'references'
if (Test-Path $extRefs) {
$refTarget = "$SkillDir\extensions\$extName\references"
New-Item -ItemType Directory -Force -Path $refTarget | Out-Null
Copy-Item -Recurse -Force "$extRefs\*" $refTarget
}
# Extension scripts
$extScripts = Join-Path $extDir 'scripts'
if (Test-Path $extScripts) {
$scriptTarget = "$SkillDir\extensions\$extName\scripts"
New-Item -ItemType Directory -Force -Path $scriptTarget | Out-Null
Copy-Item -Recurse -Force "$extScripts\*" $scriptTarget
}
}
}
# Copy requirements.txt to skill dir for retry
$reqFile = Join-Path $TempDir 'requirements.txt'
$installedReqFile = Join-Path $SkillDir 'requirements.txt'
if (Test-Path $reqFile) {
Copy-Item -Force $reqFile $installedReqFile
}
$pluginManifest = Join-Path $TempDir '.claude-plugin\plugin.json'
if (Test-Path $pluginManifest) {
Copy-Item -Force $pluginManifest (Join-Path $SkillDir 'runtime-plugin.json')
}
$kimiManifest = Join-Path $TempDir 'kimi.plugin.json'
if (Test-Path $kimiManifest) {
Copy-Item -Force $kimiManifest (Join-Path $SkillDir 'kimi.plugin.json')
}
# Manual installs do not receive plugin bin/ PATH injection. Rewrite only
# the canonical runtime token in installed Markdown. Kimi Code's Bash tool
# expands $HOME on Windows as well as Unix.
if ($Claude) {
$manualBin = '$HOME/.claude/skills/seo/bin/kimi-seo'
} else {
$manualBin = '$HOME/.kimi-code/skills/seo/bin/kimi-seo'
}
$manualRunner = "`"$manualBin`" run"
$installedDocs = @()
Get-ChildItem -Path $SkillsPath -Directory | ForEach-Object {
$sourceRoot = $_.FullName
$targetRoot = "$SkillsHome\$($_.Name)"
$installedDocs += Get-ChildItem -Path $sourceRoot -Recurse -File -Filter '*.md' | ForEach-Object {
$relative = $_.FullName.Substring($sourceRoot.Length).TrimStart('\','/')
Get-Item (Join-Path $targetRoot $relative) -ErrorAction SilentlyContinue
}
}
Get-ChildItem -Path $ExtensionsPath -Directory -ErrorAction SilentlyContinue | ForEach-Object {
$extName = $_.Name
$extSkills = Join-Path $_.FullName 'skills'
Get-ChildItem -Path $extSkills -Directory -ErrorAction SilentlyContinue | ForEach-Object {
$sourceRoot = $_.FullName
$targetRoot = "$SkillsHome\$($_.Name)"
$installedDocs += Get-ChildItem -Path $sourceRoot -Recurse -File -Filter '*.md' | ForEach-Object {
$relative = $_.FullName.Substring($sourceRoot.Length).TrimStart('\','/')
Get-Item (Join-Path $targetRoot $relative) -ErrorAction SilentlyContinue
}
}
$extRefs = Join-Path $_.FullName 'references'
if (Test-Path $extRefs) {
$targetRefs = Join-Path $SkillDir "extensions\$extName\references"
$installedDocs += Get-ChildItem -Path $extRefs -Recurse -File -Filter '*.md' | ForEach-Object {
$relative = $_.FullName.Substring($extRefs.Length).TrimStart('\','/')
Get-Item (Join-Path $targetRefs $relative) -ErrorAction SilentlyContinue
}
}
}
$agentSources = @()
$agentSources += Get-ChildItem -Path $AgentsPath -File -Filter '*.md' -ErrorAction SilentlyContinue
$agentSources += Get-ChildItem -Path $ExtensionsPath -Recurse -File -Filter '*.md' -ErrorAction SilentlyContinue |
Where-Object { $_.Directory.Name -eq 'agents' }
$installedDocs += $agentSources | ForEach-Object {
Get-Item (Join-Path $AgentDir $_.Name) -ErrorAction SilentlyContinue
}
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$installedDocs | ForEach-Object {
$text = [System.IO.File]::ReadAllText($_.FullName)
$manualSetup = "`"$manualBin`" setup"
$manualDoctor = "`"$manualBin`" doctor"
$updated = $text.Replace('kimi-seo run', $manualRunner)
$updated = $updated.Replace('kimi-seo setup', $manualSetup)
$updated = $updated.Replace('kimi-seo doctor', $manualDoctor)
if ($updated -ne $text) {
[System.IO.File]::WriteAllText($_.FullName, $updated, $utf8NoBom)
}
}
# Use the same standard-library runtime on Windows. It creates an isolated
# .venv with Scripts\python.exe and installs Chromium through that interpreter.
Write-Host "=> Creating isolated Python runtime..." -ForegroundColor Yellow
$runtimeScript = Join-Path $SkillDir 'scripts\runtime.py'
$runtime = Invoke-External -Exe $python.Exe -Args @($python.Args + @($runtimeScript,'setup'))
if ($runtime.ExitCode -ne 0 -and $runtime.ExitCode -ne 10) {
throw "Core Python runtime setup failed. Installation is incomplete."
}
if ($runtime.ExitCode -eq 10) {
Write-Host " [!] Core runtime installed, but Chromium setup is incomplete." -ForegroundColor Yellow
}
} catch {
Write-Host ""
Write-Host "[x] Installation failed: $($_.Exception.Message)" -ForegroundColor Red
if ($keepTemp -and (Test-Path $TempDir)) {
Write-Host "Temp dir kept at: $TempDir" -ForegroundColor Yellow
}
throw
} finally {
if (-not $keepTemp -and (Test-Path $TempDir)) {
Remove-Item -Recurse -Force $TempDir
}
}
Write-Host ""
if ($Claude) {
Write-Host "[+] Kimi SEO installed successfully (claude target)!" -ForegroundColor Green
Write-Host ""
Write-Host "Usage:" -ForegroundColor Cyan
Write-Host " 1. Start Claude Code: claude"
Write-Host " 2. Run commands: /kimi-seo:seo audit https://example.com"
} else {
Write-Host "[+] Kimi SEO installed successfully (kimi target)!" -ForegroundColor Green
Write-Host ""
Write-Host "Usage:" -ForegroundColor Cyan
Write-Host " 1. Start Kimi Code: kimi"
Write-Host " 2. Reload skills: /reload"
Write-Host " 3. Run commands: /kimi-seo:seo audit https://example.com"
Write-Host ""
Write-Host "Managed alternative (recommended): install as a Kimi Code plugin instead:" -ForegroundColor Cyan
Write-Host " /plugins install $RepoUrl"
Write-Host " /reload"
}
Write-Host ""
Write-Host "Python deps location: $installedReqFile" -ForegroundColor Gray