<# .SYNOPSIS Generate a self-contained C64/C128 project repository from an approved brief. .DESCRIPTION 1. Validates the brief (status must be "approved", no missing fields, no conflicts). 2. Validates the destination. An existing non-empty folder or Git repository is never touched; an empty folder is allowed. 3. Builds the repository in a temporary sibling folder ("..foundry-staging-*"): templates, starter source, project-specific files (starter.filesDir), project.json. 4. Fails if any {{PLACEHOLDER}} is left unresolved. 5. Runs git init on branch main and commits if a Git identity is configured; otherwise the files are staged and ready to commit. 6. Moves the folder to the destination in one rename. If anything fails before this, the staging folder is removed and the destination is left as it was. Leftovers from an interrupted earlier attempt are removed on the next run. 7. Runs the generated repo's tools/smoke.ps1 (unless -SkipVerify) and reports the result. Exit codes: 0 = generated (see verification status), 1 = nothing generated. .EXAMPLE pwsh -File tools/New-FoundryProject.ps1 examples/traffic-control-64/brief.json pwsh -File tools/New-FoundryProject.ps1 drafts/my-game.json -Destination "D:\Retro Projects\my-game" #> [CmdletBinding()] param( [Parameter(Mandatory, Position = 0)][string]$BriefPath, [string]$Destination, [switch]$SkipVerify, [switch]$Json, [string]$FailAfterStep ) Import-Module (Join-Path $PSScriptRoot 'Foundry.psm1') -Force try { $r = New-FoundryProject -BriefPath $BriefPath -Destination $Destination -SkipVerify:$SkipVerify -FailAfterStep $FailAfterStep } catch { Write-Host "NOT GENERATED: $($_.Exception.Message)" -ForegroundColor Red exit 1 } if ($Json) { $r | ConvertTo-Json -Depth 6; exit 0 } Write-Host "" Write-Host "Project generated" -ForegroundColor Green Write-Host " Path : $($r.Destination)" Write-Host " Git : branch main, $(if ($r.Committed) { 'initial commit created' } else { 'files staged; no Git identity configured. Set one (git config --global user.name / user.email), then run: git commit -m "Initial handoff"' })" foreach ($t in $r.Targets) { Write-Host " Target : $($t.Id) -> $($t.Artifact) (starter configuration: $($t.Status))" } foreach ($w in $r.Warnings) { Write-Host " Warning : $w" -ForegroundColor Yellow } if ($r.StaleRemoved.Count) { Write-Host " Cleaned : removed $($r.StaleRemoved.Count) leftover staging folder(s) from an interrupted run" } Write-Host " Starter verification: $($r.Verification.status)" if ($r.Verification.output) { $r.Verification.output | Where-Object { $_ -match '^\s*(\[|MISSING| First| Unverified|ok |FAIL)|^\s+(ok|FAIL)\s' } | ForEach-Object { Write-Host " $_" } } Write-Host "" Write-Host "Next: open a fresh coding-agent session in the folder above and send:" Write-Host "" Write-Host " $($r.HandoffMessage)" exit 0