|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Build locale del contesto per Codex su Windows. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | +Wrapper operativo per `agent-context build` in local mode. |
| 7 | +Richiede un workspace root esplicito e prova a usare prima `.venv314`, |
| 8 | +poi `.venv`, se presenti nella repo. |
| 9 | +#> |
| 10 | + |
| 11 | +param( |
| 12 | + [Parameter(Mandatory = $true)] |
| 13 | + [string]$WorkspaceRoot, |
| 14 | + [string]$OutDir = "generated-local", |
| 15 | + [string]$ConfigPath = "dataciviclab.config.yml", |
| 16 | + [string]$VenvName = "" |
| 17 | +) |
| 18 | + |
| 19 | +$ErrorActionPreference = "Stop" |
| 20 | + |
| 21 | +$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 22 | +$resolvedOutDir = Join-Path $repoRoot $OutDir |
| 23 | +$resolvedConfig = Join-Path $repoRoot $ConfigPath |
| 24 | + |
| 25 | +$candidateVenvs = @() |
| 26 | +if ($VenvName) { |
| 27 | + $candidateVenvs += $VenvName |
| 28 | +} |
| 29 | +$candidateVenvs += @(".venv314", ".venv") |
| 30 | + |
| 31 | +$python = $null |
| 32 | +$agentContext = $null |
| 33 | +$resolvedVenv = $null |
| 34 | +foreach ($candidate in $candidateVenvs | Select-Object -Unique) { |
| 35 | + $candidatePython = Join-Path $repoRoot "$candidate\Scripts\python.exe" |
| 36 | + $candidateCli = Join-Path $repoRoot "$candidate\Scripts\agent-context.exe" |
| 37 | + if ((Test-Path $candidatePython) -and (Test-Path $candidateCli)) { |
| 38 | + $python = $candidatePython |
| 39 | + $agentContext = $candidateCli |
| 40 | + $resolvedVenv = $candidate |
| 41 | + break |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +if (-not (Test-Path $WorkspaceRoot)) { |
| 46 | + throw "Workspace root non trovato: $WorkspaceRoot" |
| 47 | +} |
| 48 | + |
| 49 | +if (-not (Test-Path $python)) { |
| 50 | + throw "Nessun venv compatibile trovato. Attesi: .venv314 o .venv, oppure passa -VenvName." |
| 51 | +} |
| 52 | + |
| 53 | +if (-not (Test-Path $resolvedConfig)) { |
| 54 | + throw "Config non trovata: $resolvedConfig" |
| 55 | +} |
| 56 | + |
| 57 | +$env:PYTHONIOENCODING = "utf-8" |
| 58 | +$env:PYTHONUTF8 = "1" |
| 59 | +$env:CURL_CA_BUNDLE = "" |
| 60 | + |
| 61 | +Write-Host "Building agent context for Codex..." -ForegroundColor Cyan |
| 62 | +Write-Host " repo: $repoRoot" |
| 63 | +Write-Host " venv: $resolvedVenv" |
| 64 | +Write-Host " workspace: $WorkspaceRoot" |
| 65 | +Write-Host " out: $resolvedOutDir" |
| 66 | + |
| 67 | +& $agentContext build ` |
| 68 | + --config $resolvedConfig ` |
| 69 | + --out $resolvedOutDir ` |
| 70 | + --workspace-root $WorkspaceRoot |
| 71 | + |
| 72 | +if ($LASTEXITCODE -ne 0) { |
| 73 | + throw "agent-context build fallito con exit code $LASTEXITCODE" |
| 74 | +} |
| 75 | + |
| 76 | +Write-Host "" |
| 77 | +Write-Host "Artifacts pronti:" -ForegroundColor Green |
| 78 | +Write-Host " $resolvedOutDir\session_bootstrap.md" |
| 79 | +Write-Host " $resolvedOutDir\workspace_triage.json" |
| 80 | +Write-Host " $resolvedOutDir\topic_index.json" |
0 commit comments