# Установка подключения «Избранного» для Windows PowerShell. # irm https://agentpolka.site/install.ps1 -OutFile "$env:TEMP\install-agentpolka.ps1" # Set-ExecutionPolicy -Scope Process Bypass # & "$env:TEMP\install-agentpolka.ps1" -Client all # ... -Token ap_xxx (готовый токен, без выдачи нового) $ErrorActionPreference = "Stop" $Base = if ($env:AGENTPOLKA_BASE) { $env:AGENTPOLKA_BASE } else { "https://agentpolka.site" } $Client = "auto" $Provided = "" for ($i = 0; $i -lt $args.Count; $i++) { if ($args[$i] -eq "-Client" -and $i + 1 -lt $args.Count) { $Client = $args[$i + 1] $i++ } elseif (($args[$i] -eq "-Token" -or $args[$i] -eq "--token") -and $i + 1 -lt $args.Count) { $Provided = $args[$i + 1] $i++ } } $HomeDir = $HOME if (-not $HomeDir) { $HomeDir = $env:USERPROFILE } if (-not $HomeDir) { throw "Не найден домашний каталог" } $Dir = Join-Path $HomeDir ".agentpolka" $TokenFile = Join-Path $Dir "token" $SkillFile = Join-Path $Dir "SKILL.md" New-Item -ItemType Directory -Force -Path $Dir | Out-Null function Get-TokenState([string]$value) { if (-not $value) { return "none" } try { Invoke-RestMethod -Uri "$Base/api/tokens/me" -Method Get ` -Headers @{ Authorization = "Bearer $value" } -TimeoutSec 20 | Out-Null return "ok" } catch { $code = 0 try { $code = [int]$_.Exception.Response.StatusCode } catch { $code = 0 } if ($code -eQ 401) { return "invalid" } return "error" } } $token = "" if ($Provided) { $state = Get-TokenState $Provided if ($state -ne "ok") { Write-Error "Токен не принят ($state). Проверь $Base/connect/." exit 1 } $token = $Provided Set-Content -NoNewline -Path $TokenFile -Value $token Write-Host "Токен принят: $($token.Substring(0, 9))…" } if (-not $token -and (Test-Path $TokenFile)) { $token = (Get-Content -Raw -Path $TokenFile).Trim() $state = Get-TokenState $token if ($state -eq "ok") { Write-Host "Токен уже есть: $($token.Substring(0, 9))…" } elseif ($state -eq "error") { Write-Error "Сеть недоступна: не удалось проверить $TokenFile. Новый токен не выпускаю." exit 1 } else { $token = "" } } if (-not $token) { try { $response = Invoke-RestMethod -Uri "$Base/api/tokens" -Method Post ` -ContentType "application/json" -Body '{"label":"installer"}' -TimeoutSec 20 } catch { Write-Error "Не удалось получить токен. Открой $Base/connect/ или повтори позже." exit 1 } $token = $response.token if (-not $token) { Write-Error "Ответ без токена. Открой $Base/connect/." exit 1 } Set-Content -NoNewline -Path $TokenFile -Value $token Write-Host "Токен создан: $($token.Substring(0, 9))…" } try { Invoke-WebRequest -Uri "$Base/SKILL.md" -OutFile $SkillFile -TimeoutSec 20 } catch { Write-Error "Не удалось скачать навык. Токен уже сохранён в $TokenFile." exit 1 } $targets = @( @{ Dir = (Join-Path $HomeDir ".codex"); Target = (Join-Path $HomeDir ".codex/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".claude"); Target = (Join-Path $HomeDir ".claude/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".cursor"); Target = (Join-Path $HomeDir ".cursor/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".config/opencode"); Target = (Join-Path $HomeDir ".config/opencode/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".kiro"); Target = (Join-Path $HomeDir ".kiro/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".factory"); Target = (Join-Path $HomeDir ".factory/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".slate"); Target = (Join-Path $HomeDir ".slate/skills/agentpolka") }, @{ Dir = (Join-Path $HomeDir ".hermes"); Target = (Join-Path $HomeDir ".hermes/skills/agentpolka") } ) $installed = 0 foreach ($item in $targets) { if ($Client -eq "all" -or (Test-Path $item.Dir)) { New-Item -ItemType Directory -Force -Path $item.Target | Out-Null Copy-Item -Force -Path $SkillFile -Destination (Join-Path $item.Target "SKILL.md") Write-Host "навык: $(Join-Path $item.Target 'SKILL.md')" $installed++ } } $canonical = Join-Path $Dir "skills/agentpolka" New-Item -ItemType Directory -Force -Path $canonical | Out-Null Copy-Item -Force -Path $SkillFile -Destination (Join-Path $canonical "SKILL.md") if ($installed -eq 0) { Write-Host "Клиенты не найдены. Навык лежит в $(Join-Path $canonical 'SKILL.md')." } else { Write-Host "Навык установлен в клиентов: $installed." } Write-Host "" Write-Host "Токен: $TokenFile (не коммить)" Write-Host "MCP: $Base/mcp" Write-Host "" Write-Host "Claude Code:" Write-Host " `$token = Get-Content -Raw `"$TokenFile`"" Write-Host " claude mcp add --transport http agentpolka $Base/mcp --header `"Authorization: Bearer `$token`"" Write-Host "" Write-Host "Codex:" Write-Host " `$env:AGENTPOLKA_TOKEN = Get-Content -Raw `"$TokenFile`"" Write-Host " [mcp_servers.agentpolka]" Write-Host " url = `"$Base/mcp`"" Write-Host " bearer_token_env_var = `"AGENTPOLKA_TOKEN`"" Write-Host "" Write-Host "OpenCode:" Write-Host " `$env:AGENTPOLKA_TOKEN = Get-Content -Raw `"$TokenFile`"" Write-Host " mcp.servers.agentpolka: type=remote, url=$Base/mcp, oauth=false," Write-Host " headers.Authorization=`"Bearer {env:AGENTPOLKA_TOKEN}`"" Write-Host "" Write-Host "Конфиги и отзыв токена: $Base/connect/"