research-agent 0.2.3

Long-term research assistant: index papers, articles, and PDFs
Documentation
# install.ps1 — one-line installer for research (Windows)
# Usage: irm https://github.com/epicsagas/research-agent/releases/latest/download/install.ps1 | iex
param(
    [string]$InstallDir = "$env:USERPROFILE\.local\bin"
)

$Repo   = "epicsagas/research-agent"
$Binary = "research"

# TLS 1.2 for older Windows PowerShell 5.1 builds (no-op on PS 7+).
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

# ── Detect architecture ───────────────────────────────────────────────────────
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
if ($arch -eq "X64") {
    $target = "x86_64-pc-windows-msvc"
} else {
    Write-Error "Error: unsupported architecture $arch (only x86_64-pc-windows-msvc is built)"; exit 1
}

# ── Resolve latest version ────────────────────────────────────────────────────
$tag = (Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest").tag_name
if (-not $tag) { Write-Error "Error: could not determine latest version"; exit 1 }
$version = $tag.TrimStart("v")

$baseUrl = "https://github.com/$Repo/releases/download/$tag"
# cargo-dist names archives after the package, not the binary.
$archive = "research-agent-$target.zip"
$url     = "$baseUrl/$archive"
$shaUrl  = "$baseUrl/$archive.sha256"

# ── Download, verify, and install ────────────────────────────────────────────
Write-Host "Installing $Binary v$version for $target..."

$tmpdir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "research-install-$pid") -Force
try {
$zip    = Join-Path $tmpdir $archive
$shaFile = Join-Path $tmpdir "$archive.sha256"

Invoke-WebRequest -Uri $url    -OutFile $zip     -UseBasicParsing -TimeoutSec 300
Invoke-WebRequest -Uri $shaUrl -OutFile $shaFile -UseBasicParsing -TimeoutSec 60

# SHA-256 verification
$expected = (Get-Content $shaFile -Raw).Split(" ")[0].Trim()
$actual   = (Get-FileHash -Path $zip -Algorithm SHA256).Hash.ToLower()
if ($actual -ne $expected) {
    Write-Error "Error: SHA-256 verification failed (expected $expected, got $actual)"; exit 1
}

Expand-Archive -Path $zip -DestinationPath $tmpdir -Force

if (-not (Test-Path $InstallDir)) {
    New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}

# Robust to archive layout: locate the binary wherever it landed.
$exe = Get-ChildItem -Path $tmpdir -Recurse -Filter "$Binary.exe" | Select-Object -First 1
if (-not $exe) { Write-Error "Error: $Binary.exe not found in archive"; exit 1 }
Copy-Item -Path $exe.FullName -Destination (Join-Path $InstallDir "$Binary.exe") -Force
} finally {
    Remove-Item -Path $tmpdir -Recurse -Force -ErrorAction SilentlyContinue
}

# ── Verify ───────────────────────────────────────────────────────────────────
if (Get-Command $Binary -ErrorAction SilentlyContinue) {
    Write-Host "Installed: $Binary v$version"
} else {
    Write-Host ""
    Write-Host "Add $InstallDir to your PATH:"
    Write-Host "  `$env:PATH = `"$InstallDir;`$env:PATH`""
}