# VCN #44 The Loop - get a Windows machine ready to build a coding-agent loop by hand. # Doctor first, then wire. Idempotent and safe: it never deletes anything, never # touches global config, and never installs a system package for you (it prints # the one line to run instead). # # Run: # irm https://vcn-44-the-loop.vercel.app/wire.ps1 | iex # # Doctor only, changes nothing: # & ([scriptblock]::Create((irm https://vcn-44-the-loop.vercel.app/wire.ps1))) -Check # # There are NO credentials in this file. It never prints your key. ASCII only. # Uninstall: delete the directory it created. Nothing else was touched. param( [switch]$Check, [switch]$NoLab, [switch]$Yes, [string]$Dir = "vcn44" ) $ErrorActionPreference = "Continue" $Base = "https://vcn-44-the-loop.vercel.app" function Ok ($m) { Write-Host " OK $m" } function Warn ($m) { Write-Host " WARN $m" } function Bad ($m) { Write-Host " FAIL $m" } Write-Host "" Write-Host "VCN #44 The Loop - setup doctor" Write-Host "-------------------------------" # ---------------------------------------------------------------- 1. python $py = $null foreach ($c in @("python", "python3", "py")) { $cmd = Get-Command $c -ErrorAction SilentlyContinue if (-not $cmd) { continue } # The Microsoft Store stub is a 0-byte shim that opens the Store. Skip it. if ($cmd.Source -and $cmd.Source -like "*WindowsApps*") { Warn "$c is the Microsoft Store stub, skipping" continue } $v = & $c -c "import sys;print('%d.%d'%sys.version_info[:2])" 2>$null if ($LASTEXITCODE -eq 0 -and $v) { $parts = $v.Split('.') if ([int]$parts[0] -eq 3 -and [int]$parts[1] -ge 10) { $py = $c; Ok "python $v ($c)"; break } else { Warn "$c is $v, need 3.10 or newer" } } } if (-not $py) { Bad "no python 3.10+ on PATH" Write-Host "" Write-Host " Install it, then re-run:" Write-Host " winget install Python.Python.3.12" Write-Host " or the installer from https://python.org (tick 'Add python.exe to PATH')" return } # ---------------------------------------------------------------- 2. key $keySet = $false if ($env:ZAI_API_KEY) { $keySet = $true; Ok "ZAI_API_KEY is set in this shell" } else { Warn "ZAI_API_KEY is not set (you get the key at the event, see $Base/setup.txt section 4)" } # ---------------------------------------------------------------- 3. network try { Invoke-WebRequest -Uri "$Base/setup.txt" -TimeoutSec 10 -UseBasicParsing | Out-Null Ok "can reach $Base" } catch { Warn "cannot reach $Base (offline? the lab still runs without network)" } if ($Check) { Write-Host "" Write-Host "Doctor only. Nothing was changed." Write-Host "To actually set up: irm $Base/wire.ps1 | iex" return } # ---------------------------------------------------------------- 4. confirm if (-not $Yes) { Write-Host "" Write-Host "About to create .\$Dir, make a virtualenv inside it, and pip install" Write-Host "anthropic + openai + pyyaml into that virtualenv only." Write-Host "Nothing global is modified. Ctrl-C to stop." $ans = Read-Host "Continue? [y/N]" if ($ans -notmatch '^(y|Y|yes|YES)$') { Write-Host "Stopped. Nothing changed."; return } } # ---------------------------------------------------------------- 5. venv New-Item -ItemType Directory -Force -Path $Dir | Out-Null Set-Location $Dir if (Test-Path ".venv") { Ok "reusing existing .venv" } else { & $py -m venv .venv if ($LASTEXITCODE -ne 0) { Bad "venv failed"; return } Ok "created .venv" } $vpy = Join-Path ".venv" "Scripts\python.exe" if (-not (Test-Path $vpy)) { Bad "cannot find the venv python"; return } & $vpy -m pip install --quiet --upgrade pip 2>$null | Out-Null & $vpy -m pip install --quiet anthropic openai pyyaml if ($LASTEXITCODE -eq 0) { Ok "installed anthropic, openai, pyyaml" } else { Bad "pip install failed; re-run without --quiet to see why"; return } # ---------------------------------------------------------------- 6. lab if (-not $NoLab) { New-Item -ItemType Directory -Force -Path "lab\fixtures", "lab\loops" | Out-Null $top = @("README.md","requirements.txt","agent.py","nebius.py","safety.py","verify.py", "verify_loop.py","stage0_skeleton.py","stage1_tools.py","stage2_toolcall.py", "stage3_stop.py","stage4_context.py") foreach ($f in $top) { try { Invoke-WebRequest -Uri "$Base/lab/$f" -OutFile "lab\$f" -TimeoutSec 20 -UseBasicParsing } catch {} } foreach ($f in @("mathlib.py","test_math.py")) { try { Invoke-WebRequest -Uri "$Base/lab/fixtures/$f" -OutFile "lab\fixtures\$f" -TimeoutSec 20 -UseBasicParsing } catch {} } try { Invoke-WebRequest -Uri "$Base/lab/loops/README.md" -OutFile "lab\loops\README.md" -TimeoutSec 20 -UseBasicParsing } catch {} $n = (Get-ChildItem -Recurse -File lab | Measure-Object).Count Ok "downloaded $n lab files into .\$Dir\lab" } # ---------------------------------------------------------------- 7. smoke Write-Host "" if ($keySet) { $smoke = @' import os, sys try: from anthropic import Anthropic except ImportError: sys.exit("FAIL: anthropic did not install") key = os.environ.get("ZAI_API_KEY") try: c = Anthropic(base_url="https://api.z.ai/api/anthropic", api_key=key) r = c.messages.create( model="glm-4.6", max_tokens=32, messages=[{"role": "user", "content": "Reply with exactly: LOOP OK"}], ) print(" model replied:", "".join(b.text for b in r.content if b.type == "text").strip()) print("") print("VCN44 SETUP READY") except Exception as e: print(" FAIL: the call did not go through:", str(e)[:180]) print(" If this says malformed token, see setup.txt section 4: the gateway reads") print(" Authorization Bearer, so the SDK arg is auth_token=, not api_key=.") sys.exit(1) '@ $tmp = Join-Path $env:TEMP "vcn44_smoke.py" Set-Content -Path $tmp -Value $smoke -Encoding utf8 & $vpy $tmp Remove-Item $tmp -ErrorAction SilentlyContinue } else { Write-Host " Skipping the smoke test: ZAI_API_KEY is not set." Write-Host " Set it with: `$env:ZAI_API_KEY = ''" Write-Host " Then run: .\.venv\Scripts\python.exe lab\verify_loop.py" Write-Host " (verify_loop.py needs no key and no network, so you can test the loop now.)" } Write-Host "" Write-Host "Done. Everything lives in .\$Dir - delete that folder to undo all of this." Write-Host "Deck: $Base Lab: .\$Dir\lab Guide: $Base/setup.txt"