Files
buryan-infra/ops/combine/research-pack/night-sprint.ps1
T
2026-11-18 20:31:39 +03:00

62 lines
2.4 KiB
PowerShell

param(
[switch]$Shutdown
)
$ErrorActionPreference = "Continue"
$base = "D:\Buryans Hub\sources\plan\research-pack"
$py = Join-Path $env:USERPROFILE ".dsh\dsh-runtimes\dsh-primary-runtime\dependencies\python\python.exe"
$srcFile = Join-Path $base "night-sources.jsonl"
$dlDir = Join-Path $base "pc-pdfs\night"
$manifest = Join-Path $base "night-manifest.jsonl"
$out = Join-Path $base "pc-results-night"
$log = Join-Path $base "night-sprint.log"
New-Item -ItemType Directory -Force $dlDir, $out | Out-Null
function Log($m) { $line = "$(Get-Date -Format s) $m"; Add-Content -Path $log -Value $line; Write-Host $line }
Log "=== night sprint start ==="
$rows = Get-Content $srcFile -Encoding UTF8 | ForEach-Object { $_ | ConvertFrom-Json }
$ready = @()
foreach ($r in $rows) {
$local = $r.source
if (-not $local) {
$url = $r.url
$ext = if ($url -match '\.pdf($|\?)') { ".pdf" } else { ".html" }
$local = Join-Path $dlDir ($r.id + $ext)
if ((Test-Path $local) -and ((Get-Item $local).Length -gt 1000)) {
Log "reuse $($r.id)"
} else {
$ok = $false
for ($i = 1; $i -le 2 -and -not $ok; $i++) {
try {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $local -TimeoutSec 35
$ok = (Test-Path $local) -and ((Get-Item $local).Length -gt 1000)
if ($ok) { Log "downloaded $($r.id) $((Get-Item $local).Length)B" }
} catch { Log "download fail $($r.id) try$i : $($_.Exception.Message)" ; Start-Sleep -Seconds 3 }
}
if (-not $ok) { continue }
}
}
if (Test-Path $local) {
$ready += [pscustomobject]@{ id=$r.id; vendor=$r.vendor; level=$r.level; source=$local; url=$r.url }
}
}
$ready | ForEach-Object { $_ | ConvertTo-Json -Compress } | Set-Content -Path $manifest -Encoding UTF8
Log "ready $($ready.Count) of $($rows.Count)"
if ($ready.Count -gt 0) {
$env:LLM_PROVIDER = "ollama"
$env:LLM_URL = "http://127.0.0.1:11434"
$env:LLM_MODEL = "qwen2.5:3b"
& $py (Join-Path $base "extract_docs.py") --manifest $manifest --out $out
Log "extractor exit $LASTEXITCODE"
}
Log "=== night sprint done ==="
if ($Shutdown) {
Log "export before shutdown"
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $base "sync-to-host.ps1")
if ($LASTEXITCODE -eq 0) {
Log "export ok; shutdown in 60s"
shutdown.exe /s /t 60 /c "Prism night sprint complete"
} else {
Log "export failed; PC stays on for manual transfer"
}
}