-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
83 lines (77 loc) · 3.92 KB
/
Copy pathinstall.ps1
File metadata and controls
83 lines (77 loc) · 3.92 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
# install.ps1 — instala a skill loopify globalmente + registra o Stop hook.
# Idempotente. Faz backup do settings.json antes de tocar nele.
$ErrorActionPreference = "Stop"
$repo = $PSScriptRoot
$dest = Join-Path $HOME ".claude\skills\loopify"
$settings = Join-Path $HOME ".claude\settings.json"
$stamp = Get-Date -Format yyyyMMdd-HHmmss
Write-Host "[1/3] Copiando skill para $dest"
New-Item -ItemType Directory -Force (Split-Path $dest) | Out-Null
# G5: nunca apaga a skill existente sem backup — move a antiga pra .bak-loopify-<stamp>
if (Test-Path $dest) { Move-Item $dest "$dest.bak-loopify-$stamp" }
Copy-Item -Recurse (Join-Path $repo "skills\loopify") $dest
# G2: o Stop hook chama `python ... loopify_stop_hook.py`; sem python no PATH o hook quebra.
# Aborta ANTES de registrar o hook (skill ja copiada e idempotente, entao re-rodar apos instalar o Python resolve).
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
throw "python nao encontrado no PATH. O Stop hook (loopify_stop_hook.py) exige python. Instale o Python e rode o instalador de novo."
}
Write-Host "[2/3] Registrando Stop hook em $settings"
$hookPy = Join-Path $dest "scripts\loopify_stop_hook.py"
if (Test-Path $settings) {
# G4: backup com timestamp — nao sobrescreve backups anteriores a cada run
Copy-Item $settings "$settings.bak-loopify-$stamp"
$cfg = Get-Content $settings -Raw | ConvertFrom-Json
} else {
$cfg = [pscustomobject]@{}
}
$entry = [pscustomobject]@{
hooks = @([pscustomobject]@{
type = "command"
command = "python `"$hookPy`""
timeout = 20
statusMessage = "loopify: validando pacotes de loop..."
})
}
if (-not ($cfg.PSObject.Properties.Name -contains "hooks")) {
$cfg | Add-Member -NotePropertyName hooks -NotePropertyValue ([pscustomobject]@{})
}
# substitui/insere só a entrada Stop do loopify, preservando outros hooks Stop
$existing = @()
if ($cfg.hooks.PSObject.Properties.Name -contains "Stop") {
$existing = @($cfg.hooks.Stop | Where-Object {
-not ($_.hooks | Where-Object { $_.command -like "*loopify_stop_hook*" })
})
}
# G1: embrulha em @(...) pra Stop permanecer um array mesmo com 1 elemento.
# Residual conhecido: no Windows PowerShell 5.1 o ConvertTo-Json abaixo ainda pode
# serializar um array de 1 elemento como objeto solto (round-trip imperfeito). Em
# PS 7+ o -Depth preserva o array. O guard de dedupe acima tolera ambos os formatos.
$stopValue = @($existing + @($entry))
if ($cfg.hooks.PSObject.Properties.Name -contains "Stop") {
$cfg.hooks.Stop = $stopValue
} else {
$cfg.hooks | Add-Member -NotePropertyName Stop -NotePropertyValue $stopValue
}
# G3: grava UTF-8 SEM BOM (Set-Content -Encoding UTF8 emite BOM no PS 5.1).
# Pareia com o leitor utf-8-sig do gerador, mas o correto e nao emitir BOM.
$json = $cfg | ConvertTo-Json -Depth 16
[System.IO.File]::WriteAllText($settings, $json, (New-Object System.Text.UTF8Encoding($false)))
Write-Host "[3/3] Smoke: validador contra pacote sintetico invalido"
$tmp = Join-Path $env:TEMP "loopify_smoke_$PID"
New-Item -ItemType Directory -Force $tmp | Out-Null
# MEDIUM-1: no PS 7.4+ ($PSNativeCommandUseErrorActionPreference=$true por default) +
# $ErrorActionPreference="Stop", o exit!=0 do python LANCARIA excecao antes do if abaixo,
# abortando o instalador justo no caso que consideramos sucesso (validador reprova = exit 1).
# Neutraliza o auto-throw nativo APENAS aqui; a checagem $LASTEXITCODE -eq 1 continua valendo.
$PSNativeCommandUseErrorActionPreference = $false
python (Join-Path $dest "scripts\loopify_validate.py") $tmp | Out-Host
if ($LASTEXITCODE -eq 1) {
Write-Host "OK: validador reprova pacote vazio (esperado)."
} else {
Write-Warning "validador nao reprovou pacote vazio - verifique o Python do PATH"
}
Remove-Item -Recurse -Force $tmp
Write-Host ""
Write-Host "loopify instalado. Sessoes NOVAS do Claude Code ja enxergam a skill e o hook."
Write-Host "Teste: abra uma sessao e digite /loopify help"
exit 0