Files
ai-contract-platform/scripts/run-phase14-incremental-batch-plan.ps1
T

53 lines
2.1 KiB
PowerShell

param(
[string]$Phase14Root = "",
[string]$DiffArtifactDir = "",
[string]$OutputDir = "",
[string]$ArtifactRoot = ""
)
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not (Test-Path "$HOME\.Codex\skills\gstack\bin")) {
throw "GSTACK_MISSING: gstack is required for AI-assisted work in this repo."
}
if ([string]::IsNullOrWhiteSpace($Phase14Root)) {
$Phase14Root = Join-Path $repoRoot "project-docs\phase14-legal-fulltext-library"
}
if ([string]::IsNullOrWhiteSpace($DiffArtifactDir)) {
$diffRoot = Join-Path $repoRoot "project-docs\qa-artifacts\legal-source-diff-report"
$latest = Get-ChildItem $diffRoot -Directory | Where-Object { Test-Path (Join-Path $_.FullName "legal-source-diff-report.json") } | Sort-Object Name -Descending | Select-Object -First 1
if ($null -eq $latest) {
throw "No legal-source-diff-report artifact found under $diffRoot"
}
$DiffArtifactDir = $latest.FullName
}
if ([string]::IsNullOrWhiteSpace($OutputDir)) {
$OutputDir = Join-Path $Phase14Root "incremental-batches"
}
if ([string]::IsNullOrWhiteSpace($ArtifactRoot)) {
$ArtifactRoot = Join-Path $repoRoot "project-docs\qa-artifacts\phase14-incremental-batch-plan"
}
$timestamp = Get-Date -Format "yyyy-MM-ddTHH-mm-ss-fff"
$artifactDir = Join-Path $ArtifactRoot $timestamp
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
$toolPath = Join-Path $repoRoot "backend\tools\plan_phase14_incremental_batches.py"
$toolOutput = & python $toolPath `
--phase14-root $Phase14Root `
--diff-artifact-dir $DiffArtifactDir `
--output-dir $OutputDir `
--artifact-dir $artifactDir
$toolExitCode = if ($LASTEXITCODE -is [int]) { $LASTEXITCODE } else { 0 }
($toolOutput -join [Environment]::NewLine) | Set-Content -Encoding UTF8 -Path (Join-Path $artifactDir "phase14-incremental-batch-plan-tool.log")
if ($toolExitCode -ne 0) {
throw "plan_phase14_incremental_batches.py failed with exit code $toolExitCode."
}
Write-Host "PHASE14_INCREMENTAL_BATCH_PLAN_PASS $artifactDir"
Write-Output ($toolOutput -join [Environment]::NewLine)