# C64/C128 Dev Foundry - validation, resolution, rendering and generation. # Deterministic: no network access and no AI API needed. Requires PowerShell 7+ and git. Set-StrictMode -Version 1.0 $ErrorActionPreference = 'Stop' $script:FoundryRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..')).Path $script:Stages = @('idea', 'target', 'first-release', 'details', 'toolchain', 'plan', 'destination', 'review') $script:StageQuestions = @{ 'idea' = @('In a sentence or two, what should the program do and who is it for?', 'What is the smallest version that would already be useful or playable?') 'target' = @('Which machine and display: C64, C128 native 40-column, C128 native 80-column, or both C64 and C128?', 'PAL, NTSC or both?', 'Should it be tested on real hardware as well as VICE?') 'first-release' = @('What must the first release do, and what is explicitly out of scope?', 'How will we see that it works (observable success criteria)?') 'details' = @('Controls (keyboard, joystick port)?', 'Visuals and sound?', 'Saving/loading, file formats, disk drive or other peripherals?', 'Speed and memory limits that matter?') 'toolchain' = @('Any language or tool preference? (Otherwise the Foundry picks the simplest that fits and explains why.)', 'Build on Windows (default) or author/compile on the Commodore itself?') 'plan' = @('Does the proposed first milestone and its checks look right?') 'destination' = @('Where should the new project folder be created?') 'review' = @('Do you approve this spec for generation, or what should change?') } $script:DesignTopics = @('controls', 'visuals', 'sound', 'persistence', 'fileFormats', 'peripherals', 'budgets') # --------------------------------------------------------------------------- # Basics # --------------------------------------------------------------------------- function Get-FoundryRoot { $script:FoundryRoot } function Read-FoundryJson([string]$Path) { if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { throw "File not found: $Path" } try { Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json -AsHashtable -Depth 64 } catch { throw "Invalid JSON in ${Path}: $($_.Exception.Message)" } } function Get-FoundryCatalog { Read-FoundryJson (Join-Path $script:FoundryRoot 'catalog/recipes.json') } function Test-Blank($Value) { ($null -eq $Value) -or ($Value -is [string] -and [string]::IsNullOrWhiteSpace($Value)) } function Get-List($Value) { if ($null -eq $Value) { return }; foreach ($x in @($Value)) { $x } } function Get-Field($Object, [string]$Path) { $cur = $Object foreach ($part in $Path -split '\.') { if ($cur -is [System.Collections.IDictionary] -and $cur.Contains($part)) { $cur = $cur[$part] } else { return $null } } $cur } # --------------------------------------------------------------------------- # Validation # --------------------------------------------------------------------------- class FoundryIssues { [System.Collections.Generic.List[object]]$Items = [System.Collections.Generic.List[object]]::new() [void] Add([string]$stage, [string]$kind, [string]$path, [string]$message) { $this.Items.Add([pscustomobject]@{ Stage = $stage; Kind = $kind; Path = $path; Message = $message }) } } function Test-FoundryBrief { <# .SYNOPSIS Validate a brief. Mode Draft reports what is still missing and where to resume; mode Approved requires a complete, approved, conflict-free brief. #> [CmdletBinding()] param( [Parameter(Mandatory)][hashtable]$Brief, [ValidateSet('Draft', 'Approved')][string]$Mode = 'Approved', [string]$BriefPath, [hashtable]$Catalog = (Get-FoundryCatalog) ) $issues = [FoundryIssues]::new() $need = { param($stage, $path, $message) $issues.Add($stage, 'missing', $path, $message) } $err = { param($stage, $path, $message) $issues.Add($stage, 'error', $path, $message) } $conflict = { param($stage, $path, $message) $issues.Add($stage, 'conflict', $path, $message) } $warn = { param($stage, $path, $message) $issues.Add($stage, 'warning', $path, $message) } if ($Brief.schemaVersion -ne '1.0') { & $err 'idea' 'schemaVersion' "schemaVersion must be '1.0'." } # --- idea --------------------------------------------------------------- $p = $Brief.project if ($p -isnot [System.Collections.IDictionary]) { & $need 'idea' 'project' 'project section (name, slug, idea, summary, kind, smallestUsefulVersion) is missing.'; $p = @{} } foreach ($f in 'name', 'idea', 'summary', 'smallestUsefulVersion') { if (Test-Blank $p[$f]) { & $need 'idea' "project.$f" "project.$f is required." } } if (Test-Blank $p.slug) { & $need 'idea' 'project.slug' 'project.slug is required.' } elseif ($p.slug -cnotmatch '^[a-z0-9][a-z0-9-]{1,48}[a-z0-9]$') { & $err 'idea' 'project.slug' "project.slug '$($p.slug)' must be 3-50 lower-case letters, digits and dashes." } if ((-not (Test-Blank $p.name)) -and $p.name.Length -gt 60) { & $err 'idea' 'project.name' 'project.name must be 60 characters or fewer.' } if (Test-Blank $p.kind) { & $need 'idea' 'project.kind' 'project.kind is required.' } elseif ($p.kind -notin 'game', 'utility', 'demo', 'tool', 'education', 'other') { & $err 'idea' 'project.kind' "project.kind '$($p.kind)' must be game, utility, demo, tool, education or other." } # --- target ------------------------------------------------------------- $targets = @(Get-List $Brief.targets) $targetIds = @() if ($targets.Count -eq 0) { & $need 'target' 'targets' 'At least one target (machine + display) is required.' } $i = 0 foreach ($t in $targets) { $tp = "targets[$i]"; $i++ if ($t -isnot [System.Collections.IDictionary]) { & $err 'target' $tp 'Each target must be an object.'; continue } if (Test-Blank $t.id) { & $need 'target' "$tp.id" 'Target id is required.' } elseif ($t.id -cnotmatch '^[a-z0-9][a-z0-9-]{0,23}$') { & $err 'target' "$tp.id" "Target id '$($t.id)' must be lower-case letters, digits and dashes (max 24)." } elseif ($t.id -in $targetIds) { & $err 'target' "$tp.id" "Duplicate target id '$($t.id)'." } else { $targetIds += $t.id } if (Test-Blank $t.platform) { & $need 'target' "$tp.platform" 'Target platform is required (c64, c128-native or c128-c64mode).' } elseif (-not $Catalog.platforms.Contains($t.platform)) { & $err 'target' "$tp.platform" "Unknown platform '$($t.platform)'. Use c64, c128-native or c128-c64mode." } if (Test-Blank $t.display) { & $need 'target' "$tp.display" 'Target display is required (vicii-40 or vdc-80).' } elseif (-not $Catalog.displays.Contains($t.display)) { & $err 'target' "$tp.display" "Unknown display '$($t.display)'. Use vicii-40 or vdc-80." } elseif ($Catalog.platforms.Contains("$($t.platform)") -and $t.display -notin $Catalog.platforms[$t.platform].displays) { & $conflict 'target' "$tp.display" ("Target '$($t.id)': display '$($t.display)' is not available on platform '$($t.platform)'. 80-column VDC output needs a C128 in native mode (platform c128-native). Ask the user which constraint to change: the machine/mode, or the 80-column requirement.") } if (Test-Blank $t.video) { & $need 'target' "$tp.video" 'Target video standard is required (pal, ntsc or pal-ntsc).' } elseif ($t.video -notin 'pal', 'ntsc', 'pal-ntsc') { & $err 'target' "$tp.video" "video must be pal, ntsc or pal-ntsc." } if (Test-Blank $t.expectedBehavior) { & $need 'target' "$tp.expectedBehavior" "Target '$($t.id)': describe the expected behavior on this target." } if ($t.disk) { if ((Test-Blank $t.disk.name) -or $t.disk.name -notmatch '^[^,]{1,16},[^,]{1,2}$') { & $err 'target' "$tp.disk.name" "disk.name must look like 'diskname,id' (name up to 16 chars, id 1-2 chars)." } if ($t.disk.format -and $t.disk.format -notin 'd64', 'd71', 'd81') { & $err 'target' "$tp.disk.format" 'disk.format must be d64, d71 or d81.' } foreach ($df in Get-List $t.disk.files) { if ((Test-Blank $df.source) -or (Test-Blank $df.name)) { & $err 'target' "$tp.disk.files" 'Each disk file needs source and name.' } elseif ($df.name.Length -gt 16) { & $err 'target' "$tp.disk.files" "Disk file name '$($df.name)' is longer than 16 characters." } } } if ($t.autostart -and $t.autostart -notin 'prg', 'disk') { & $err 'target' "$tp.autostart" 'autostart must be prg or disk.' } if ($t.autostart -eq 'disk' -and -not $t.disk) { & $err 'target' "$tp.autostart" "Target '$($t.id)' autostarts from disk but has no disk section." } } $platforms = @($targets | Where-Object { $_ -is [System.Collections.IDictionary] } | ForEach-Object { $_.platform }) if ($targets.Count -gt 1) { $strategy = Get-Field $Brief 'dualTarget.strategy' if (Test-Blank $strategy) { & $need 'target' 'dualTarget.strategy' 'More than one target: record dualTarget.strategy (c64-mode-on-both, native-per-target or multi-display) and how each target behaves.' } elseif ($strategy -eq 'c64-mode-on-both') { if ('c128-native' -in $platforms) { & $conflict 'target' 'dualTarget.strategy' "Strategy 'c64-mode-on-both' runs the same C64 program on both machines, but a target uses platform 'c128-native'. Ask the user: keep one C64-mode program (use platform c128-c64mode), or build a native C128 version (strategy native-per-target)." } if (-not ('c64' -in $platforms -and 'c128-c64mode' -in $platforms)) { & $err 'target' 'targets' "Strategy 'c64-mode-on-both' needs one c64 target and one c128-c64mode target." } } elseif ($strategy -eq 'native-per-target') { if (-not ('c64' -in $platforms -and 'c128-native' -in $platforms)) { & $err 'target' 'targets' "Strategy 'native-per-target' needs a c64 target and a c128-native target." } } elseif ($strategy -eq 'multi-display') { if (@($platforms | Where-Object { $_ -ne 'c128-native' }).Count -gt 0) { & $err 'target' 'targets' "Strategy 'multi-display' is for one C128 native program with separate 40- and 80-column targets." } } else { & $err 'target' 'dualTarget.strategy' "Unknown dualTarget.strategy '$strategy'." } if (Test-Blank (Get-Field $Brief 'dualTarget.notes')) { & $need 'target' 'dualTarget.notes' 'Explain in dualTarget.notes what is shared and what differs between targets.' } } if ($Brief.testing -isnot [System.Collections.IDictionary]) { & $need 'target' 'testing' 'testing section (emulator, realHardware) is required.' } else { if ($Brief.testing.emulator -ne 'vice') { & $err 'target' 'testing.emulator' "testing.emulator must be 'vice' in version 1." } $rh = $Brief.testing.realHardware if ($rh -isnot [System.Collections.IDictionary] -or $rh.requested -isnot [bool]) { & $need 'target' 'testing.realHardware.requested' 'Say whether real-hardware testing is requested (true/false).' } elseif ($rh.requested -and (Test-Blank $rh.reason)) { & $need 'target' 'testing.realHardware.reason' 'Real hardware requested: record why (which requirement depends on it).' } } # --- first release -------------------------------------------------------- $s = $Brief.scope if ($s -isnot [System.Collections.IDictionary]) { & $need 'first-release' 'scope' 'scope section (firstRelease, inScope, outOfScope) is required.' } else { if (Test-Blank $s.firstRelease) { & $need 'first-release' 'scope.firstRelease' 'Describe the first release.' } if (@(Get-List $s.inScope).Count -eq 0) { & $need 'first-release' 'scope.inScope' 'List what is in scope.' } if (@(Get-List $s.outOfScope).Count -eq 0) { & $need 'first-release' 'scope.outOfScope' 'List what is out of scope.' } } $reqIds = @() $reqs = @(Get-List $Brief.requirements) if ($reqs.Count -eq 0) { & $need 'first-release' 'requirements' 'At least one requirement with observable acceptance criteria is required.' } foreach ($r in $reqs) { if ((Test-Blank $r.id) -or $r.id -cnotmatch '^R\d+$') { & $err 'first-release' 'requirements' "Requirement id '$($r.id)' must look like R1, R2, ..."; continue } if ($r.id -in $reqIds) { & $err 'first-release' "requirements.$($r.id)" "Duplicate requirement id $($r.id)." } $reqIds += $r.id if ((Test-Blank $r.title) -or (Test-Blank $r.text)) { & $need 'first-release' "requirements.$($r.id)" "$($r.id) needs a title and text." } if ($r.priority -notin 'must', 'should', 'could') { & $err 'first-release' "requirements.$($r.id).priority" "$($r.id) priority must be must, should or could." } if (@(Get-List $r.acceptance).Count -eq 0) { & $need 'first-release' "requirements.$($r.id).acceptance" "$($r.id) needs at least one observable acceptance criterion." } } # --- details -------------------------------------------------------------- $d = $Brief.design if ($d -isnot [System.Collections.IDictionary]) { & $need 'details' 'design' 'design section is required (controls, visuals, sound, persistence, fileFormats, peripherals, budgets).'; $d = @{} } foreach ($topic in $script:DesignTopics) { $entry = $d[$topic] if ($entry -isnot [System.Collections.IDictionary] -or (Test-Blank $entry.value)) { & $need 'details' "design.$topic" "design.$topic needs a value (use source 'n/a' with a short reason when it does not apply)." ; continue } if ($entry.source -notin 'user', 'default', 'n/a', 'open') { & $err 'details' "design.$topic.source" "design.$topic.source must be user, default, n/a or open." } if ($entry.source -eq 'open') { $listed = @(Get-List $Brief.openDecisions | Where-Object { $_.topic -eq $topic }).Count -gt 0 if (-not $listed) { & $err 'details' "design.$topic" "design.$topic is marked open but no openDecisions entry has topic '$topic'." } } } $caps = @(Get-List $Brief.capabilities) foreach ($c in $caps) { if (-not $Catalog.capabilities.Contains("$c")) { & $err 'details' 'capabilities' "Unknown capability '$c'. Known: $($Catalog.capabilities.Keys -join ', ')." } } foreach ($a in Get-List $Brief.assumptions) { if ((Test-Blank $a.id) -or (Test-Blank $a.text)) { & $err 'details' 'assumptions' 'Each assumption needs id and text.' } elseif ($a.status -notin 'default', 'unverified', 'confirmed') { & $err 'details' "assumptions.$($a.id)" "Assumption $($a.id) status must be default, unverified or confirmed." } } foreach ($o in Get-List $Brief.openDecisions) { if ((Test-Blank $o.id) -or (Test-Blank $o.question) -or (Test-Blank $o.default)) { & $err 'details' 'openDecisions' 'Each open decision needs id, question and the default used until it is decided.' } elseif ($o.status -notin 'open', 'resolved') { & $err 'details' "openDecisions.$($o.id)" "Open decision $($o.id) status must be open or resolved." } } # --- toolchain ---------------------------------------------------------------- $tc = $Brief.toolchain $buildLocation = $Brief.buildLocation if (Test-Blank $buildLocation) { & $need 'toolchain' 'buildLocation' "buildLocation is required (windows-cross or on-commodore)." } elseif ($buildLocation -notin 'windows-cross', 'on-commodore') { & $err 'toolchain' 'buildLocation' "buildLocation must be windows-cross or on-commodore." } if ($tc -isnot [System.Collections.IDictionary]) { & $need 'toolchain' 'toolchain' 'toolchain section (recipe, language, recommended, reasons, alternatives) is required.' } else { $recipe = $null; $lang = $null if (Test-Blank $tc.recipe) { & $need 'toolchain' 'toolchain.recipe' 'toolchain.recipe is required.' } elseif (-not $Catalog.recipes.Contains($tc.recipe)) { & $err 'toolchain' 'toolchain.recipe' "Unknown recipe '$($tc.recipe)'. Known: $($Catalog.recipes.Keys -join ', ')." } else { $recipe = $Catalog.recipes[$tc.recipe] } if (Test-Blank $tc.language) { & $need 'toolchain' 'toolchain.language' 'toolchain.language is required.' } elseif (-not $Catalog.languages.Contains($tc.language)) { & $err 'toolchain' 'toolchain.language' "Unknown language '$($tc.language)'. Known: $($Catalog.languages.Keys -join ', ')." } else { $lang = $Catalog.languages[$tc.language] } $override = $tc.override $byOverride = ($override -is [System.Collections.IDictionary]) -and (-not (Test-Blank $override.requestedLanguage)) -and $override.requestedLanguage -eq $tc.language $ask = if ($byOverride) { $rec = Get-Field $tc 'recommended.language' " This language is a user override. Ask the user which constraint to change: keep '$($tc.language)' and change the conflicting target/requirement, or drop the override and use the recommended '$rec'." } else { ' Ask the user which constraint to change.' } if ($lang) { foreach ($t in $targets) { if ($t -isnot [System.Collections.IDictionary] -or (Test-Blank $t.platform)) { continue } if ($t.platform -notin $lang.platforms) { & $conflict 'toolchain' 'toolchain.language' ("Language '$($tc.language)' ($($lang.title)) does not run on platform '$($t.platform)' (target '$($t.id)')." + $ask) } } foreach ($c in $caps) { if ($c -notin $lang.capabilities) { $by = @(Get-List $Brief.requirements | Where-Object { @(Get-List $_.capabilities) -contains $c } | ForEach-Object { $_.id }) -join ', ' $reqNote = if ($by) { " (needed by $by)" } else { '' } & $conflict 'toolchain' 'capabilities' ("Required capability '$c'$reqNote is not provided by '$($tc.language)': $($lang.limits)" + $ask) } } } if ('vdc-80col' -in $caps -and -not ($targets | Where-Object { $_ -is [System.Collections.IDictionary] -and $_.display -eq 'vdc-80' })) { & $conflict 'target' 'capabilities' "Capability 'vdc-80col' is required but no target uses display 'vdc-80'. Ask the user which constraint to change: add a C128 native 80-column target, or drop the 80-column requirement." } if ($recipe -and $lang) { if ($tc.language -notin $recipe.languages) { & $conflict 'toolchain' 'toolchain.recipe' ("Recipe '$($tc.recipe)' does not support language '$($tc.language)' (supports: $($recipe.languages -join ', '))." + $ask) } if ($buildLocation -and $buildLocation -notin $recipe.buildLocations) { $alt = @($Catalog.recipes.Keys | Where-Object { $buildLocation -in $Catalog.recipes[$_].buildLocations -and $tc.language -in $Catalog.recipes[$_].languages }) $altNote = if ($alt) { " Recipe(s) that fit: $($alt -join ', ')." } else { " No catalog recipe supports '$($tc.language)' with build location '$buildLocation'." } & $conflict 'toolchain' 'buildLocation' ("Recipe '$($tc.recipe)' does not support build location '$buildLocation'.$altNote Ask the user which constraint to change: the build location or the language.") } foreach ($t in $targets) { if ($t -isnot [System.Collections.IDictionary]) { continue } $combo = @($recipe.combos | Where-Object { $_.platform -eq $t.platform -and $_.display -eq $t.display -and $tc.language -in $_.languages }) if ($combo.Count -eq 0 -and $t.platform -and $t.display -and $t.platform -in $lang.platforms) { & $conflict 'toolchain' 'toolchain.recipe' ("Recipe '$($tc.recipe)' has no configuration for '$($tc.language)' on $($t.platform)/$($t.display) (target '$($t.id)')." + $ask) } elseif ($combo.Count -gt 0 -and $combo[0].status -ne 'verified') { & $warn 'toolchain' 'toolchain.recipe' "Target '$($t.id)': $($tc.recipe) on $($t.platform)/$($t.display) with $($tc.language) has no verified starter yet; the generated docs include a validation plan." } } } if ($tc.recommended -isnot [System.Collections.IDictionary] -or (Test-Blank $tc.recommended.recipe) -or (Test-Blank $tc.recommended.language)) { & $need 'toolchain' 'toolchain.recommended' "Record the Foundry's default recommendation (recommended.recipe and recommended.language)." } if (@(Get-List $tc.reasons).Count -eq 0) { & $need 'toolchain' 'toolchain.reasons' 'Explain the language choice in plain English (toolchain.reasons).' } if (@(Get-List $tc.alternatives).Count -eq 0) { & $need 'toolchain' 'toolchain.alternatives' 'List meaningful alternatives and why they were not chosen.' } if ($override -is [System.Collections.IDictionary]) { if ((Test-Blank $override.requestedLanguage) -or (Test-Blank $override.reason)) { & $err 'toolchain' 'toolchain.override' 'An override needs requestedLanguage and reason.' } elseif (-not $byOverride) { & $err 'toolchain' 'toolchain.override' "The user requested '$($override.requestedLanguage)' but toolchain.language is '$($tc.language)'. An approved override takes precedence: set toolchain.language to the requested language, or record that the user withdrew the override." } } elseif ($tc.recommended -is [System.Collections.IDictionary] -and $tc.recommended.language -and $tc.language -and $tc.recommended.language -ne $tc.language) { & $err 'toolchain' 'toolchain.language' "toolchain.language differs from the recommendation but no override is recorded." } } if ($buildLocation -eq 'on-commodore') { $oc = $Brief.onCommodore if ($oc -isnot [System.Collections.IDictionary]) { & $need 'toolchain' 'onCommodore' 'On-Commodore build: describe targetTool, transfer method and diskFormat.' } else { foreach ($f in 'targetTool', 'transfer') { if (Test-Blank $oc[$f]) { & $need 'toolchain' "onCommodore.$f" "onCommodore.$f is required." } } if ($oc.diskFormat -notin 'd64', 'd71', 'd81') { & $err 'toolchain' 'onCommodore.diskFormat' 'onCommodore.diskFormat must be d64, d71 or d81.' } } } # --- plan ----------------------------------------------------------------- $st = $Brief.starter if ($st -isnot [System.Collections.IDictionary]) { & $need 'plan' 'starter' 'starter section (screenTitle, expectedScreen) is required.' } else { if (Test-Blank $st.screenTitle) { & $need 'plan' 'starter.screenTitle' 'starter.screenTitle (text shown on the first screen row) is required.' } elseif ($st.screenTitle -cnotmatch "^[A-Z0-9 .,:!?()+\-*/=#%&<>]{1,38}$") { & $err 'plan' 'starter.screenTitle' "starter.screenTitle must be 1-38 characters of A-Z, 0-9, space and simple punctuation (no quotes); got '$($st.screenTitle)'." } if (Test-Blank $st.expectedScreen) { & $need 'plan' 'starter.expectedScreen' 'Describe what the starter screen shows (starter.expectedScreen).' } foreach ($sc in Get-List $st.smokeChecks) { if ($null -eq $sc.row -or $null -eq $sc.col -or (Test-Blank $sc.text)) { & $err 'plan' 'starter.smokeChecks' 'Each smoke check needs row, col and text.' } elseif ($sc.text -cnotmatch "^[A-Za-z0-9 .,:!?()+\-*/=#%&<>]{1,80}$") { & $err 'plan' 'starter.smokeChecks' "Smoke check text '$($sc.text)' has unsupported characters." } foreach ($tid in Get-List $sc.targets) { if ($tid -notin $targetIds) { & $err 'plan' 'starter.smokeChecks' "Smoke check refers to unknown target '$tid'." } } } if ($st.filesDir) { if (-not $BriefPath) { & $warn 'plan' 'starter.filesDir' 'starter.filesDir is set but the brief path is unknown; cannot check it.' } else { $fd = Join-Path (Split-Path -Parent $BriefPath) $st.filesDir if (-not (Test-Path -LiteralPath $fd -PathType Container)) { & $err 'plan' 'starter.filesDir' "starter.filesDir '$($st.filesDir)' does not exist next to the brief." } } } } $ms = @(Get-List $Brief.milestones) if ($ms.Count -eq 0) { & $need 'plan' 'milestones' 'At least one milestone (M1, M2, ...) is required. M0 (starter) is added automatically.' } $covered = @() $msIds = @() foreach ($m in $ms) { if ((Test-Blank $m.id) -or $m.id -cnotmatch '^M[1-9]\d*$') { & $err 'plan' 'milestones' "Milestone id '$($m.id)' must be M1, M2, ... (M0 is generated)."; continue } if ($m.id -in $msIds) { & $err 'plan' "milestones.$($m.id)" "Duplicate milestone $($m.id)." } $msIds += $m.id if ((Test-Blank $m.title) -or (Test-Blank $m.goal)) { & $need 'plan' "milestones.$($m.id)" "$($m.id) needs title and goal." } $tasks = @(Get-List $m.tasks) if ($tasks.Count -eq 0) { & $need 'plan' "milestones.$($m.id).tasks" "$($m.id) needs at least one task." } foreach ($t in $tasks) { if ((Test-Blank $t.id) -or (Test-Blank $t.text) -or (Test-Blank $t.outcome) -or (Test-Blank $t.check)) { & $need 'plan' "milestones.$($m.id).tasks" "Every task in $($m.id) needs id, text, outcome (buildable result) and check (how completion is verified)." } $refs = @(Get-List $t.requirements) if ($refs.Count -eq 0) { & $err 'plan' "milestones.$($m.id).tasks" "Task $($t.id) must link to at least one requirement." } foreach ($rid in $refs) { if ($rid -notin $reqIds) { & $err 'plan' "milestones.$($m.id).tasks" "Task $($t.id) refers to unknown requirement '$rid'." } else { $covered += $rid } } } $tests = @(Get-List $m.manualTests) if ($tests.Count -eq 0) { & $need 'plan' "milestones.$($m.id).manualTests" "$($m.id) needs at least one manual test." } foreach ($mt in $tests) { if ((Test-Blank $mt.id) -or (Test-Blank $mt.setup) -or @(Get-List $mt.steps).Count -eq 0 -or @(Get-List $mt.expected).Count -eq 0) { & $need 'plan' "milestones.$($m.id).manualTests" "Manual test $($mt.id) in $($m.id) needs id, setup, steps and expected observations." } $tt = if ($mt.target) { $mt.target } else { 'all' } if ($tt -ne 'all' -and $tt -ne 'real-hardware' -and $tt -notin $targetIds) { & $err 'plan' "milestones.$($m.id).manualTests" "Manual test $($mt.id) targets unknown target '$tt'." } } } foreach ($rid in @(Get-List (Get-Field $Brief 'starter.requirements'))) { if ($rid -notin $reqIds) { & $err 'plan' 'starter.requirements' "starter.requirements refers to unknown requirement '$rid'." } else { $covered += $rid } } foreach ($rid in $reqIds) { if ($rid -notin $covered -and $ms.Count -gt 0) { & $err 'plan' 'milestones' "Requirement $rid is not linked to any milestone task." } } # --- destination ------------------------------------------------------------ if (Test-Blank $Brief.destination) { & $need 'destination' 'destination' 'destination (folder for the new project) is required.' } else { try { $null = Resolve-FoundryDestination $Brief.destination } catch { & $err 'destination' 'destination' $_.Exception.Message } } # --- review ----------------------------------------------------------------- if ($Mode -eq 'Approved') { if ($Brief.status -ne 'approved') { & $need 'review' 'status' "status must be 'approved' (the user approved the spec) before generation." } if ((Test-Blank (Get-Field $Brief 'approval.approvedBy')) -or (Test-Blank (Get-Field $Brief 'approval.approvedOn'))) { & $need 'review' 'approval' 'Record approval.approvedBy and approval.approvedOn.' } } elseif ($Brief.status -notin 'draft', 'approved') { & $err 'review' 'status' "status must be 'draft' or 'approved'." } # --- summary ---------------------------------------------------------------- $items = $issues.Items $blocking = @($items | Where-Object { $_.Kind -in 'error', 'conflict' -or ($Mode -eq 'Approved' -and $_.Kind -eq 'missing') }) $missingStages = @($items | Where-Object { $_.Kind -eq 'missing' } | ForEach-Object { $_.Stage } | Select-Object -Unique) $resume = $script:Stages | Where-Object { $_ -in $missingStages } | Select-Object -First 1 if (-not $resume) { $problemStages = @($items | Where-Object { $_.Kind -in 'error', 'conflict' } | ForEach-Object { $_.Stage } | Select-Object -Unique) $resume = $script:Stages | Where-Object { $_ -in $problemStages } | Select-Object -First 1 } if (-not $resume) { $resume = if ($Brief.status -eq 'approved') { 'generate' } else { 'review' } } $questions = @(Get-List (Get-Field $Brief 'interview.openQuestions')) if ($script:StageQuestions.Contains($resume)) { $questions += $script:StageQuestions[$resume] } [pscustomobject]@{ Valid = ($blocking.Count -eq 0) Mode = $Mode Errors = @($items | Where-Object Kind -eq 'error') Conflicts = @($items | Where-Object Kind -eq 'conflict') Missing = @($items | Where-Object Kind -eq 'missing') Warnings = @($items | Where-Object Kind -eq 'warning') ResumeStage = $resume NextQuestions = $questions } } function Format-FoundryValidation($Result) { $lines = @() $lines += "Validation ($($Result.Mode)): " + $(if ($Result.Valid) { 'OK' } else { 'NOT READY' }) foreach ($c in $Result.Conflicts) { $lines += " CONFLICT [$($c.Path)] $($c.Message)" } foreach ($e in $Result.Errors) { $lines += " ERROR [$($e.Path)] $($e.Message)" } foreach ($m in $Result.Missing) { $lines += " MISSING [$($m.Stage)] $($m.Message)" } foreach ($w in $Result.Warnings) { $lines += " WARNING [$($w.Path)] $($w.Message)" } $lines += "Resume interview at stage: $($Result.ResumeStage)" if ($Result.ResumeStage -notin 'generate') { $lines += 'Next questions:' foreach ($q in $Result.NextQuestions) { $lines += " - $q" } } $lines -join [Environment]::NewLine } # --------------------------------------------------------------------------- # Destination handling # --------------------------------------------------------------------------- function Resolve-FoundryDestination([string]$Destination) { if (Test-Blank $Destination) { throw 'Destination is empty.' } $raw = [Environment]::ExpandEnvironmentVariables($Destination) if ($raw.IndexOfAny([char[]]'<>"|?*') -ge 0) { throw "Destination '$Destination' contains a character Windows does not allow in paths (< > "" | ? *)." } # Check the name as written: Windows path normalization silently drops trailing dots and spaces. $rawLeaf = ($raw.TrimEnd('\', '/') -split '[\\/]')[-1] if ($rawLeaf -match '[. ]$') { throw "Destination folder name '$rawLeaf' ends with a dot or space, which Windows does not keep." } $full = if ([IO.Path]::IsPathRooted($raw)) { [IO.Path]::GetFullPath($raw) } else { [IO.Path]::GetFullPath((Join-Path $script:FoundryRoot $raw)) } $full = $full.TrimEnd('\', '/') $leaf = Split-Path $full -Leaf if ((Test-Blank $leaf) -or $leaf -match '[. ]$') { throw "Destination folder name '$leaf' is empty or ends with a dot or space." } if ($leaf -match '^(CON|PRN|AUX|NUL|COM\d|LPT\d)(\..*)?$') { throw "Destination folder name '$leaf' is reserved on Windows." } $root = $script:FoundryRoot.TrimEnd('\', '/') if ($full -eq $root -or $full.StartsWith($root + [IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)) { throw "Destination '$full' is inside the Foundry repository. Generate projects into their own folder outside the Foundry." } $full } function Get-DestinationState([string]$Path) { if (-not (Test-Path -LiteralPath $Path)) { return 'absent' } if (Test-Path -LiteralPath $Path -PathType Leaf) { return 'file' } if (@(Get-ChildItem -LiteralPath $Path -Force).Count -eq 0) { return 'empty' } if (Test-Path -LiteralPath (Join-Path $Path '.git')) { return 'git-repo' } 'non-empty' } # --------------------------------------------------------------------------- # Resolution: brief + catalog -> concrete build/run/smoke configuration # --------------------------------------------------------------------------- function Get-ProgramName([hashtable]$Brief) { $n = ($Brief.project.slug -replace '-', '') if ($n.Length -gt 16) { $n = $n.Substring(0, 16) } $n } function Resolve-FoundryProject([hashtable]$Brief, [hashtable]$Catalog = (Get-FoundryCatalog)) { $recipe = $Catalog.recipes[$Brief.toolchain.recipe] $langId = $Brief.toolchain.language $lang = $Catalog.languages[$langId] $slug = $Brief.project.slug $isAsm = $langId -eq 'asm-ca65' $sameProgram = (Get-Field $Brief 'dualTarget.strategy') -eq 'c64-mode-on-both' $onboard = $Brief.buildLocation -eq 'on-commodore' $programName = if ($Brief.onCommodore -and $Brief.onCommodore.programName) { $Brief.onCommodore.programName } else { Get-ProgramName $Brief } $transferImage = "build/transfer/$slug.$(if ($Brief.onCommodore -and $Brief.onCommodore.diskFormat) { $Brief.onCommodore.diskFormat } else { 'd64' })" $smokeChecks = @(Get-List $Brief.starter.smokeChecks) if ($smokeChecks.Count -eq 0) { $smokeChecks = @( @{ row = 0; col = 0; text = $Brief.starter.screenTitle; description = 'Title on row 0' }, @{ row = 2; col = 0; text = 'STARTER OK'; description = "'STARTER OK' on row 2" } ) } # Emulator options a capability needs on every target (for example a 1351 mouse in control port 1). $capEmuArgs = @(); $capEmuNotes = @() foreach ($c in Get-List $Brief.capabilities) { $ce = if ($Catalog.Contains('capabilityEmulator')) { $Catalog.capabilityEmulator["$c"] } else { $null } if ($ce) { $capEmuArgs += @($ce.args); if ($ce.note) { $capEmuNotes += "${c}: $($ce.note)" } } } $toolUse = [ordered]@{} $addUse = { param($tool, $what) if (-not $toolUse.Contains($tool)) { $toolUse[$tool] = [System.Collections.Generic.List[string]]::new() }; if ($what -notin $toolUse[$tool]) { $toolUse[$tool].Add($what) } } $targets = foreach ($t in Get-List $Brief.targets) { $combo = @($recipe.combos | Where-Object { $_.platform -eq $t.platform -and $_.display -eq $t.display -and $langId -in $_.languages })[0] $artifact = if ($t.artifact) { $t.artifact } elseif ($sameProgram) { "build/$slug.prg" } elseif (@($Brief.targets).Count -eq 1) { "build/$slug.prg" } else { "build/$slug-$($t.id).prg" } $base = [IO.Path]::ChangeExtension($artifact, $null).TrimEnd('.') $build = switch ($recipe.buildKind) { 'cc65' { $defines = @("FOUNDRY_TARGET_$(($t.id -replace '-', '_').ToUpperInvariant())") if ($t.display -eq 'vdc-80') { $defines += 'FOUNDRY_VDC80' } [ordered]@{ kind = 'cc65'; cc65Target = $combo.cc65Target; config = $(if ($isAsm) { "$($combo.cc65Target)-asm.cfg" } else { $null }); defines = $defines; sourceDirs = @('src'); labels = "$base.lbl"; map = "$base.map" } } 'petcat' { [ordered]@{ kind = 'petcat'; dialect = $combo.dialect; source = 'src/main.bas' } } default { [ordered]@{ kind = 'none' } } } $disk = $null $autostart = 'prg' if ($t.disk) { $files = foreach ($f in Get-List $t.disk.files) { $src = if ($f.source -eq '$artifact') { $artifact } else { $f.source } [ordered]@{ source = $src; name = $f.name; type = $(if ($f.type) { $f.type } else { 'prg' }); convert = $f.convert; lineEndings = $(if ($f.lineEndings) { $f.lineEndings } else { 'cr' }) } } $disk = [ordered]@{ image = $(if ($t.disk.image) { $t.disk.image } else { "build/$slug-$($t.id).$(if ($t.disk.format) { $t.disk.format } else { 'd64' })" }); format = $(if ($t.disk.format) { $t.disk.format } else { 'd64' }); name = $t.disk.name; files = @($files) } $autostart = if ($t.autostart) { $t.autostart } else { 'prg' } } elseif ($onboard -and $recipe.buildKind -eq 'petcat') { # On-Commodore BASIC: the smoke test uses the same load-and-run procedure as a person, # autostarting the transfer disk that tools/to-commodore.ps1 produces. $disk = [ordered]@{ image = $transferImage; format = $(if ($Brief.onCommodore.diskFormat) { $Brief.onCommodore.diskFormat } else { 'd64' }); name = "$programName,fd"; files = @([ordered]@{ source = $artifact; name = $programName; type = 'prg'; convert = $null; lineEndings = 'keep' }) } $autostart = 'disk' } $smoke = $null if ($recipe.buildKind -ne 'none' -and $combo.status -eq 'verified') { $ready = if ($recipe.buildKind -eq 'cc65') { [ordered]@{ kind = 'exec'; symbol = $(if ($isAsm) { 'smoke_ready' } else { '_smoke_ready' }); address = $null } } else { [ordered]@{ kind = 'store'; symbol = $null; address = $(if ($combo.dialect -eq '70') { '0BFF' } else { '02A7' }) } } $dumps = @(); $checks = @() $enc = $lang.screenEncoding if ($t.display -eq 'vicii-40') { $dumps += [ordered]@{ name = 'screen'; symbol = $null; address = '0400'; length = 1000 } foreach ($sc in $smokeChecks) { if (@(Get-List $sc.targets).Count -gt 0 -and $t.id -notin $sc.targets) { continue } $checks += [ordered]@{ dump = 'screen'; offset = ([int]$sc.row * 40 + [int]$sc.col); text = $sc.text; encoding = $enc; bytes = $null; description = $(if ($sc.description) { $sc.description } else { "Row $($sc.row): '$($sc.text)'" }) } } } elseif ($recipe.buildKind -eq 'cc65' -and -not $isAsm) { $dumps += [ordered]@{ name = 'probe'; symbol = '_smoke_probe'; address = $null; length = 320 } foreach ($sc in $smokeChecks) { if (@(Get-List $sc.targets).Count -gt 0 -and $t.id -notin $sc.targets) { continue } if ([int]$sc.row -ge 4) { continue } $checks += [ordered]@{ dump = 'probe'; offset = ([int]$sc.row * 80 + [int]$sc.col); text = $sc.text; encoding = $enc; bytes = $null; description = $(if ($sc.description) { $sc.description } else { "VDC row $($sc.row): '$($sc.text)'" }) } } } if ($t.platform -eq 'c128-native') { $dumps += [ordered]@{ name = 'mode'; symbol = $null; address = '00D7'; length = 1 } $checks += [ordered]@{ dump = 'mode'; offset = 0; text = $null; encoding = $null; bytes = $(if ($t.display -eq 'vdc-80') { '80' } else { '00' }); description = $(if ($t.display -eq 'vdc-80') { 'C128 MODE flag $D7 = $80 (80-column screen active)' } else { 'C128 MODE flag $D7 = $00 (40-column screen active)' }) } } else { $dumps += [ordered]@{ name = 'vector'; symbol = $null; address = 'FFFC'; length = 2 } $checks += [ordered]@{ dump = 'vector'; offset = 0; text = $null; encoding = $null; bytes = 'E2 FC'; description = 'C64 KERNAL reset vector at $FFFC (machine is in C64 mode)' } } $limit = if ($t.smokeLimitCycles) { [int]$t.smokeLimitCycles } elseif ($autostart -eq 'disk') { 80000000 } else { 30000000 } $smoke = [ordered]@{ ready = $ready; limitCycles = $limit; dumps = $dumps; checks = $checks; expectedScreen = $Brief.starter.expectedScreen } } # tool usage notes for check-prereqs foreach ($tool in $recipe.tools) { if ($tool -eq 'c1541' -and $onboard) { & $addUse $tool "transfer disk (tools/to-commodore.ps1, tools/from-commodore.ps1)" ; continue } & $addUse $tool "build of target $($t.id) (tools/build.ps1)" } if ($disk) { & $addUse 'c1541' "disk image for target $($t.id)" } & $addUse $combo.emulator "run and smoke test of target $($t.id) (tools/run.ps1, tools/smoke.ps1)" [ordered]@{ id = $t.id; name = $(if ($t.name) { $t.name } else { "$($Catalog.platforms[$t.platform].title), $($Catalog.displays[$t.display])" }) platform = $t.platform; display = $t.display; video = $(if ($t.video -eq 'ntsc') { 'ntsc' } else { 'pal' }); videoSupport = $t.video artifact = $artifact; expectedBehavior = $t.expectedBehavior build = $build; disk = $disk emulator = [ordered]@{ binary = $combo.emulator; args = @($combo.emulatorArgs) + @($capEmuArgs); autostart = $autostart; notes = @($capEmuNotes) } smoke = $smoke recipeStatus = $combo.status validationPlan = @(Get-List $combo.validationPlan) } } $tools = foreach ($id in $toolUse.Keys) { $c = $Catalog.tools[$id] [ordered]@{ id = $id; executable = $c.executable; package = $c.package; purpose = $c.purpose; verifiedVersion = $c.verifiedVersion; versionArgs = @($c.versionArgs); envVar = $c.envVar; searchPaths = @($c.searchPaths); install = $c.install; docs = @($c.docs); requiredFor = @($toolUse[$id]) } } $onCommodore = $null if ($onboard) { $oc = $recipe.onCommodore $onCommodore = [ordered]@{ kind = $(if ($recipe.buildKind -eq 'petcat') { 'basic' } else { 'files' }) programName = $programName dialect = $(if ($recipe.buildKind -eq 'petcat') { @($targets)[0].build.dialect } else { $null }) source = $(if ($recipe.buildKind -eq 'petcat') { 'src/main.bas' } else { $null }) image = $transferImage diskName = "$programName,fd" diskFormat = $(if ($Brief.onCommodore.diskFormat) { $Brief.onCommodore.diskFormat } else { 'd64' }) files = $(if ($recipe.buildKind -eq 'petcat') { @() } else { @([ordered]@{ source = 'src/STARTER.TXT'; name = 'starter'; type = 'seq'; convert = 'ascii-to-petscii'; lineEndings = 'cr' }) }) returnFiles = $(if ($recipe.buildKind -eq 'petcat') { @() } else { @([ordered]@{ name = $programName; type = 'prg'; dest = "build/$programName.prg" }) }) loadCommand = $(if ($recipe.buildKind -eq 'petcat') { "LOAD`"$($programName.ToUpperInvariant())`",8 then RUN" } else { 'Load your assembler, then load the source file STARTER from drive 8' }) targetTool = $Brief.onCommodore.targetTool transfer = $Brief.onCommodore.transfer hostToTarget = $oc.hostToTarget targetToHost = $oc.targetToHost } # The transfer disk needs c1541 even when no target has its own disk. if (-not ($tools | Where-Object { $_.id -eq 'c1541' })) { $c = $Catalog.tools['c1541'] $tools = @($tools) + [ordered]@{ id = 'c1541'; executable = $c.executable; package = $c.package; purpose = $c.purpose; verifiedVersion = $c.verifiedVersion; versionArgs = @($c.versionArgs); envVar = $c.envVar; searchPaths = @($c.searchPaths); install = $c.install; docs = @($c.docs); requiredFor = @('transfer disk (tools/to-commodore.ps1, tools/from-commodore.ps1)') } } } [ordered]@{ _note = 'Generated by the C64/C128 Dev Foundry from the approved brief and catalog. tools/*.ps1 read this section; edit it (and docs/toolchain.md) together if the build changes.' recipe = $Brief.toolchain.recipe recipeTitle = $recipe.title language = $langId languageTitle = $lang.title starter = $recipe.starters[$langId] tools = @($tools) targets = @($targets) onCommodore = $onCommodore catalogVerifiedOn = $Catalog.verifiedOn catalogVerifiedWith = $Catalog.verifiedWith sources = @($recipe.sources) } } # --------------------------------------------------------------------------- # Templates # --------------------------------------------------------------------------- function Expand-FoundryTemplate([string]$Text, [hashtable]$Vars, [string]$Name = 'template') { $missing = [System.Collections.Generic.List[string]]::new() $out = [regex]::Replace($Text, '\{\{([A-Z0-9_]+)\}\}', { param($m) $key = $m.Groups[1].Value if ($Vars.ContainsKey($key)) { return [string]$Vars[$key] } $missing.Add($key); return $m.Value }) if ($missing.Count) { throw "Template '$Name' uses unknown placeholder(s): $(($missing | Select-Object -Unique) -join ', ')" } $out } function Find-UnresolvedPlaceholders([string]$Directory) { $textExt = '.md', '.json', '.c', '.h', '.s', '.bas', '.txt', '.ps1', '.gitignore', '.gitattributes', '.cfg', '.inc' Get-ChildItem -LiteralPath $Directory -Recurse -File -Force | Where-Object { $_.FullName -notmatch '[\\/]\.git[\\/]' -and ($_.Extension -in $textExt -or $_.Name -in '.gitignore', '.gitattributes') } | ForEach-Object { $hits = Select-String -LiteralPath $_.FullName -Pattern '\{\{[A-Z0-9_]+\}\}' -AllMatches foreach ($h in $hits) { [pscustomobject]@{ File = $_.FullName.Substring($Directory.Length + 1); Line = $h.LineNumber; Text = $h.Line.Trim() } } } } function ConvertTo-MdCell([string]$Text) { if ($null -eq $Text) { '' } else { ($Text -replace '\|', '\|' -replace '\r?\n', ' ') } } function Get-TargetLabel([hashtable]$Catalog, $t) { "$($t.id) ($($Catalog.platforms[$t.platform].title), $($t.display))" } function New-DocVariables([hashtable]$Brief, $Resolved, [hashtable]$Catalog, [string]$Destination) { $nl = "`n" $p = $Brief.project $targets = @($Resolved.targets) $firstTarget = $targets[0] $v = @{} $v.PROJECT_NAME = $p.name $v.PROJECT_SLUG = $p.slug $v.PROJECT_SUMMARY = $p.summary $v.PROJECT_IDEA = $p.idea $v.SMALLEST_VERSION = $p.smallestUsefulVersion $v.PROJECT_KIND = $p.kind $v.SCREEN_TITLE = $Brief.starter.screenTitle $v.SCREEN_TITLE_LOWER = $Brief.starter.screenTitle.ToLowerInvariant() $v.PROJECT_NAME_LOWER = ($p.name.ToLowerInvariant() -replace '[^a-z0-9 .,:!?()+\-*/=#%&<>]', '') $v.GENERATED_ON = (Get-Date -Format 'yyyy-MM-dd') $v.APPROVED_BY = $Brief.approval.approvedBy $v.APPROVED_ON = $Brief.approval.approvedOn $v.LANGUAGE_TITLE = $Resolved.languageTitle $v.RECIPE_TITLE = $Resolved.recipeTitle $v.RECIPE_ID = $Resolved.recipe $v.BUILD_LOCATION = $(if ($Brief.buildLocation -eq 'on-commodore') { 'On the Commodore (repository kept on the Windows host)' } else { 'Windows cross-development' }) $v.FIRST_TARGET = $firstTarget.id $v.EXPECTED_SCREEN = $Brief.starter.expectedScreen $v.FIRST_RELEASE = $Brief.scope.firstRelease $v.HANDOFF_MESSAGE = 'Read AGENTS.md and follow it. Build and verify the starter (milestone M0) first, then implement the next milestone one task at a time, reporting after each task what changed, which checks ran, and exactly how I should verify it.' # Targets table $rows = @('| Target | Machine / mode | Display | Video | Artifact | Expected behavior |', '|---|---|---|---|---|---|') foreach ($t in $targets) { $rows += "| ``$($t.id)`` | $($Catalog.platforms[$t.platform].title) | $(ConvertTo-MdCell $Catalog.displays[$t.display]) | $($t.videoSupport) | ``$($t.artifact)`` | $(ConvertTo-MdCell $t.expectedBehavior) |" } $v.TARGETS_TABLE = $rows -join $nl $dual = $Brief.dualTarget $v.DUAL_TARGET = if ($dual -and $dual.strategy) { $desc = switch ($dual.strategy) { 'c64-mode-on-both' { 'One C64 program. The C128 runs it in C64 mode (GO 64, or hold the Commodore key at power-on); no native C128 build.' } 'native-per-target' { 'Separate builds from shared source: a C64 program and a native C128 program.' } 'multi-display' { 'One native C128 program with separate 40-column and 80-column targets that are verified independently.' } } "**Strategy:** ``$($dual.strategy)`` - $desc$nl$nl$($dual.notes)" } else { 'Single target.' } $displayNotes = foreach ($t in $targets) { switch ($t.display) { 'vicii-40' { "- ``$($t.id)``: VIC-II 40x25 screen. Screen RAM at `$0400 by default. $(if ($t.platform -eq 'c128-native') { 'On a C128 this is the 40-column (composite/RF) output; the 40/80 DISPLAY key must be up, or the program switches with videomode().' } else { '' })" } 'vdc-80' { "- ``$($t.id)``: VDC 80x25 text screen on the C128 RGBI output. Not memory-mapped: all screen access goes through `$D600/`$D601. 40/80 DISPLAY key down (VICE: -80col). In VICE the 80-column output appears in its own window." } } } $v.DISPLAY_NOTES = $displayNotes -join $nl # Scope $v.IN_SCOPE = @(Get-List $Brief.scope.inScope | ForEach-Object { "- $_" }) -join $nl $v.OUT_OF_SCOPE = @(Get-List $Brief.scope.outOfScope | ForEach-Object { "- $_" }) -join $nl # Requirements $req = foreach ($r in Get-List $Brief.requirements) { $caps = @(Get-List $r.capabilities) $lines = @("### $($r.id) - $($r.title) ($($r.priority))", '', $r.text, '', 'Acceptance criteria:') $n = 0 foreach ($a in Get-List $r.acceptance) { $n++; $lines += "- [$($r.id).$n] $a" } if ($caps.Count) { $lines += ''; $lines += "Capabilities: $($caps -join ', ')" } $lines -join $nl } $v.REQUIREMENTS = $req -join ($nl + $nl) # Design decisions $labels = @{ controls = 'Controls'; visuals = 'Visuals'; sound = 'Sound'; persistence = 'Persistence (save/load)'; fileFormats = 'File formats'; peripherals = 'Peripherals'; budgets = 'Timing and memory budgets' } $srcLabel = @{ user = 'decided by user'; default = 'practical default'; 'n/a' = 'not applicable'; open = 'UNRESOLVED' } $design = @('| Topic | Decision | Source |', '|---|---|---|') foreach ($topic in $script:DesignTopics) { $e = $Brief.design[$topic] $design += "| $($labels[$topic]) | $(ConvertTo-MdCell $e.value) | $($srcLabel[$e.source]) |" } foreach ($o in Get-List $Brief.design.other) { $design += "| $(ConvertTo-MdCell $o.topic) | $(ConvertTo-MdCell $o.value) | $($srcLabel[$o.source]) |" } $v.DESIGN_TABLE = $design -join $nl $v.CAPABILITIES = if (@(Get-List $Brief.capabilities).Count) { @(Get-List $Brief.capabilities | ForEach-Object { "- ``$_``: $($Catalog.capabilities[$_])" }) -join $nl } else { '- (none beyond plain text output)' } $v.ASSUMPTIONS = if (@(Get-List $Brief.assumptions).Count) { (@('| ID | Assumption | Status |', '|---|---|---|') + @(Get-List $Brief.assumptions | ForEach-Object { "| $($_.id) | $(ConvertTo-MdCell $_.text) | $($_.status) |" })) -join $nl } else { '- None recorded.' } $v.OPEN_DECISIONS = if (@(Get-List $Brief.openDecisions).Count) { (@('| ID | Question | Default until decided | Status |', '|---|---|---|---|') + @(Get-List $Brief.openDecisions | ForEach-Object { "| $($_.id) | $(ConvertTo-MdCell $_.question) | $(ConvertTo-MdCell $_.default) | $($_.status) |" })) -join $nl } else { '- None. Every decision in this spec is settled.' } $rh = $Brief.testing.realHardware $v.REAL_HARDWARE = if ($rh.requested) { "Requested. Reason: $($rh.reason)" } else { 'Not requested for this release. VICE is the reference environment; real-hardware steps in docs/manual-tests.md are optional.' } # Toolchain $tc = $Brief.toolchain $v.TOOLCHAIN_REASONS = @(Get-List $tc.reasons | ForEach-Object { "- $_" }) -join $nl $v.TOOLCHAIN_ALTERNATIVES = (@('| Alternative | Why not chosen |', '|---|---|') + @(Get-List $tc.alternatives | ForEach-Object { "| $(ConvertTo-MdCell $_.option) | $(ConvertTo-MdCell $_.whyNot) |" })) -join $nl $v.TOOLCHAIN_RECOMMENDED = "``$($tc.recommended.recipe)`` / ``$($tc.recommended.language)`` ($($Catalog.languages[$tc.recommended.language].title))" $v.TOOLCHAIN_OVERRIDE = if ($tc.override -and $tc.override.requestedLanguage) { "**User override (approved):** the user asked for ``$($tc.override.requestedLanguage)`` instead of the recommendation. Reason given: $($tc.override.reason) The override is compatible with every target and required capability, so it takes precedence." } else { 'No user override. The recommended language is used.' } $v.TOOLCHAIN_VERIFY = if (@(Get-List $tc.assumptionsToVerify).Count) { @(Get-List $tc.assumptionsToVerify | ForEach-Object { "- [ ] $_" }) -join $nl } else { '- [ ] None beyond the starter verification below.' } $toolRows = @('| Tool | Purpose | Verified version | Install source | First command if missing | Override variable |', '|---|---|---|---|---|---|') foreach ($t in $Resolved.tools) { $toolRows += "| ``$($t.executable)`` | $(ConvertTo-MdCell $t.purpose) | $($t.verifiedVersion) | $($t.install.source) | $(ConvertTo-MdCell $t.install.firstCommand) | ``$($t.envVar)`` |" } $v.TOOLS_TABLE = $toolRows -join $nl $cmdRows = foreach ($t in $targets) { $b = $t.build $buildCmd = switch ($b.kind) { 'cc65' { "cl65 -t $($b.cc65Target) -g $(if ($b.config) { "-C $($b.config) -u __EXEHDR__" } else { '-O' }) $(($b.defines | ForEach-Object { "-D $_" }) -join ' ') -I src -o $($t.artifact) -Ln $($b.labels) -m $($b.map) src/*.c src/*.s" } 'petcat' { "petcat -w$($b.dialect) -f -o $($t.artifact) -- $($b.source)" } default { '(built on the Commodore - see On-Commodore workflow)' } } $emuArgs = (@(if ($t.video -eq 'ntsc') { '-ntsc' } else { '-pal' }) + @($t.emulator.args)) -join ' ' $runFile = if ($t.emulator.autostart -eq 'disk') { $t.disk.image } else { $t.artifact } $lines = @("### Target ``$($t.id)``", '', "- Status: **$($t.recipeStatus)** starter configuration ($($Resolved.recipe), $($t.platform)/$($t.display), $($Resolved.language))", "- Build (what tools/build.ps1 runs): ``$buildCmd``") if ($t.disk) { $lines += "- Disk image: ``$($t.disk.image)`` ($($t.disk.format), header ``$($t.disk.name)``), files: $((@($t.disk.files) | ForEach-Object { "$($_.name) ($($_.type))" }) -join ', ')" } $lines += "- Emulator: ``$($t.emulator.binary) $emuArgs -autostart $runFile``" foreach ($note in @(Get-List $t.emulator.notes)) { $lines += "- Emulator note - $note" } if ($t.smoke) { $readyText = if ($t.smoke.ready.symbol) { '`' + $t.smoke.ready.symbol + '`' } else { 'its marker store to $' + $t.smoke.ready.address } $lines += "- Smoke test: ``pwsh -File tools/smoke.ps1 -Target $($t.id)``. It runs VICE headless for $($t.smoke.limitCycles) cycles, saves memory when the program reaches $readyText, and checks:" foreach ($c in $t.smoke.checks) { $lines += " - $($c.description)" } if ($t.display -eq 'vdc-80' -and -not ($t.smoke.checks | Where-Object { $_.text })) { $lines += ' - (80-column text is not readable from CPU memory in this recipe: inspect build/smoke/' + $t.id + '/screen.png)' } } else { $lines += '- Smoke test: none automated. Verification is manual (docs/manual-tests.md, M0).' } if (@($t.validationPlan).Count) { $lines += ''; $lines += 'Validation plan (no verified starter yet for this configuration):' $n = 0; foreach ($s in $t.validationPlan) { $n++; $lines += "$n. $s" } } $lines -join $nl } $v.TARGET_COMMANDS = $cmdRows -join ($nl + $nl) $vw = $Resolved.catalogVerifiedWith $v.CATALOG_VERIFIED = "Starter configurations marked verified were exercised by the Foundry's automated checks on $($Resolved.catalogVerifiedOn) with $($vw.cc65), $($vw.vice), $($vw.powershell) on $($vw.os)." $v.SOURCES = ($Resolved.sources + @($Resolved.tools | ForEach-Object { $_.install.source }) | Select-Object -Unique | ForEach-Object { "- $_" }) -join $nl if ($Resolved.onCommodore) { $oc = $Resolved.onCommodore $v.ON_COMMODORE = @( '## On-Commodore workflow', '', 'The Git repository stays on the Windows host. Authoring (and, for compiled languages, building) happens on the Commodore or in VICE; disk images carry the work back and forth.', '', "- Target-side tool: $($oc.targetTool)", "- Transfer method: $($oc.transfer)", "- Disk format: ``$($oc.diskFormat)``, transfer image ``$($oc.image)`` (header ``$($oc.diskName)``)", "- Program file on disk: ``$($oc.programName)``", '', '### Host to Commodore', '', $oc.hostToTarget, '', '```powershell', 'pwsh -File tools/to-commodore.ps1', '```', '', "Then on the Commodore (VICE: attach the image to drive 8): ``$($oc.loadCommand)``.", '', '### Commodore to host', '', $oc.targetToHost, '', '```powershell', 'pwsh -File tools/from-commodore.ps1', 'git diff', '```', '', 'Never edit the same program on both sides at once: pull the Commodore copy back (and commit) before editing on the host, and run to-commodore.ps1 before editing on the Commodore.' ) -join $nl } else { $v.ON_COMMODORE = '' } # Milestones $m0 = @{ id = 'M0'; title = 'Starter builds and runs'; goal = 'Prove the toolchain, emulator configuration and smoke test work before any feature work.' tasks = @(@{ id = 'M0.1'; text = 'Run tools/check-prereqs.ps1, then tools/smoke.ps1 for every target.'; requirements = @(Get-List $Brief.starter.requirements); outcome = "Starter artifact(s) built: $((@($targets | ForEach-Object { $_.artifact }) | Select-Object -Unique) -join ', ')"; check = 'tools/smoke.ps1 exits 0 (or every target without automation is verified by hand), and the user confirms the M0 manual test.' }) } $milestones = @($m0) + @(Get-List $Brief.milestones) $ml = foreach ($m in $milestones) { $reqs = @($m.tasks | ForEach-Object { Get-List $_.requirements } | Select-Object -Unique) $lines = @("## $($m.id) - $($m.title)", '', "Goal: $($m.goal)", '', "Requirements: $(if ($reqs.Count) { $reqs -join ', ' } else { '(foundation)' })", '', '| Task | Description | Requirements | Buildable outcome | Completion check |', '|---|---|---|---|---|') foreach ($t in $m.tasks) { $lines += "| $($t.id) | $(ConvertTo-MdCell $t.text) | $(@(Get-List $t.requirements) -join ', ') | $(ConvertTo-MdCell $t.outcome) | $(ConvertTo-MdCell $t.check) |" } $lines += ''; $lines += "Manual verification: see docs/manual-tests.md section $($m.id)." $lines -join $nl } $v.MILESTONES = $ml -join ($nl + $nl) $v.NEXT_MILESTONE = if (@(Get-List $Brief.milestones).Count) { "$($Brief.milestones[0].id) - $($Brief.milestones[0].title)" } else { 'none' } # Manual tests $mt = @() $mt += '## M0 - Starter builds and runs' foreach ($t in $targets) { $runFile = if ($t.emulator.autostart -eq 'disk') { $t.disk.image } else { $t.artifact } $mt += '' $mt += "### MT0-$($t.id): starter on $(Get-TargetLabel $Catalog $t)" $mt += '' $mt += "Setup: prerequisites installed (``pwsh -File tools/check-prereqs.ps1`` reports no missing tools)." $mt += '' $mt += 'Steps:' if ($t.build.kind -eq 'none') { $mt += '1. Run `pwsh -File tools/to-commodore.ps1` and attach the transfer image to drive 8.' $mt += "2. Follow the validation plan in docs/toolchain.md for target ``$($t.id)``: load the assembler, assemble src/STARTER.TXT, save and run it." } else { $mt += "1. Run ``pwsh -File tools/smoke.ps1 -Target $($t.id)``$(if ($t.smoke) { ' and note the result.' } else { '.' })" $mt += "2. Run ``pwsh -File tools/run.ps1 -Target $($t.id)`` (VICE starts and autostarts ``$runFile``)." if ($t.display -eq 'vdc-80') { $mt += '3. Look at the VDC (80-column) window. If VICE shows only one window, use View > Show VDC window / switch to the VDC display.' } } $mt += '' $mt += 'Expected:' if ($t.smoke) { $mt += "- tools/smoke.ps1 prints ``[PASS] $($t.id)``; screenshot in build/smoke/$($t.id)/." } $mt += "- $($Brief.starter.expectedScreen)" $mt += "- $($t.expectedBehavior)" } foreach ($m in Get-List $Brief.milestones) { $mt += ''; $mt += "## $($m.id) - $($m.title)" foreach ($test in Get-List $m.manualTests) { $tt = if ($test.target) { $test.target } else { 'all' } $applies = if ($tt -eq 'all') { @($targets | ForEach-Object { $_.id }) } else { @($tt) } foreach ($tid in $applies) { $title = if ($tid -eq 'real-hardware') { 'real hardware' } else { $tid } $mt += ''; $mt += "### $($test.id)$(if ($applies.Count -gt 1) { "-$tid" }): $($test.title) ($title)" $mt += ''; $mt += "Setup: $($test.setup)" if ($tid -ne 'real-hardware') { $t = $targets | Where-Object { $_.id -eq $tid } $mt += "Start: ``pwsh -File tools/run.ps1 -Target $tid``" } $mt += ''; $mt += 'Steps:' $n = 0; foreach ($s in Get-List $test.steps) { $n++; $mt += "$n. $s" } $mt += ''; $mt += 'Expected:' foreach ($e in Get-List $test.expected) { $mt += "- $e" } if ($test.requirements) { $mt += ''; $mt += "Verifies: $(@(Get-List $test.requirements) -join ', ')" } } } } $mt += ''; $mt += '## Real hardware' $mt += '' if ($rh.requested) { $mt += "Real-hardware verification is **required** for this project: $($rh.reason)" } else { $mt += 'Optional for this release. Use these steps when hardware is available.' } $mt += '' $mt += '1. Build: `pwsh -File tools/build.ps1`.' $mt += '2. Get the program onto a disk the machine can read, for example: copy the .prg (or .d64) to an SD2IEC/Pi1541/1541 Ultimate SD card; or write the .d64 to a real floppy with a ZoomFloppy/XUM1541 and OpenCBM (`d64copy build\.d64 8`).' $mt += "3. On the machine: ``LOAD`"*`",8`` then ``RUN`` (a C128 in native mode can also use ``RUN`"name`"``). For C64-mode targets on a C128, enter C64 mode first (``GO 64``, then ``Y``)." $mt += '4. Repeat the manual tests for the current milestone and note any difference from VICE (timing, colours, display artefacts, disk speed) in docs/verification-status.md.' $v.MANUAL_TESTS = $mt -join $nl # Verification status $vs = @('| Item | Automated check | Manual verification by user |', '|---|---|---|') foreach ($m in $milestones) { foreach ($t in $m.tasks) { $vs += "| $($t.id) $(ConvertTo-MdCell $t.text) | not run | pending |" } } $v.VERIFICATION_TABLE = $vs -join $nl $v.TARGET_LIST = (@($targets | ForEach-Object { "``$($_.id)``" })) -join ', ' $v.TOOL_LIST = (@($Resolved.tools | ForEach-Object { $_.executable }) + 'PowerShell 7', 'git') -join ', ' $v.DESTINATION = $Destination $v.ON_COMMODORE_README = if ($Resolved.onCommodore) { @('', '## Working on the Commodore', '', "This project is authored on the Commodore. Move work with ``pwsh -File tools/to-commodore.ps1`` (host to disk image) and ``pwsh -File tools/from-commodore.ps1`` (disk image to host). Details: docs/toolchain.md, On-Commodore workflow.") -join $nl } else { '' } $v.ON_COMMODORE_AGENTS = if ($Resolved.onCommodore) { @('', '## On-Commodore projects', '', '- The source of truth is the repository, but the user may edit the program on the Commodore. Before you edit `' + $Resolved.onCommodore.source + '`, ask whether there is newer work on the transfer disk, and if so have them run `pwsh -File tools/from-commodore.ps1` first.', '- After you change source, run `pwsh -File tools/to-commodore.ps1` so the user can load the new version on the machine, and say so in your report.') -join $nl } else { '' } $v } # --------------------------------------------------------------------------- # Generation # --------------------------------------------------------------------------- function Copy-TemplateTree([string]$From, [string]$To, [hashtable]$Vars) { if (-not (Test-Path -LiteralPath $From)) { return } foreach ($f in Get-ChildItem -LiteralPath $From -Recurse -File -Force) { if ($f.Name -eq 'starter.json') { continue } $rel = $f.FullName.Substring($From.Length + 1) if ($rel.EndsWith('.tmpl')) { $rel = $rel.Substring(0, $rel.Length - 5) $dest = Join-Path $To $rel New-Item -ItemType Directory -Force -Path (Split-Path $dest -Parent) | Out-Null $text = Expand-FoundryTemplate (Get-Content -LiteralPath $f.FullName -Raw) $Vars $rel [IO.File]::WriteAllText($dest, $text, [Text.UTF8Encoding]::new($false)) } else { $dest = Join-Path $To $rel New-Item -ItemType Directory -Force -Path (Split-Path $dest -Parent) | Out-Null Copy-Item -LiteralPath $f.FullName -Destination $dest -Force } } } function Remove-StaleStaging([string]$Parent, [string]$Leaf) { if (-not (Test-Path -LiteralPath $Parent)) { return @() } $removed = @() foreach ($d in Get-ChildItem -LiteralPath $Parent -Directory -Force -Filter ".$Leaf.foundry-staging-*") { Remove-Item -LiteralPath $d.FullName -Recurse -Force $removed += $d.FullName } $removed } function Invoke-Git([string]$Dir, [string[]]$GitArgs, [switch]$AllowFail) { $out = & git -C $Dir @GitArgs 2>&1 | ForEach-Object { "$_" } if ($LASTEXITCODE -ne 0 -and -not $AllowFail) { throw "git $($GitArgs -join ' ') failed: $($out -join ' ')" } , @($out) } function New-FoundryProject { <# .SYNOPSIS Generate a handoff repository from an approved brief. #> [CmdletBinding()] param( [Parameter(Mandatory)][string]$BriefPath, [string]$Destination, [switch]$SkipVerify, [string]$FailAfterStep # test hook: simulate an interruption after the named step ) $catalog = Get-FoundryCatalog $BriefPath = (Resolve-Path -LiteralPath $BriefPath).ProviderPath $brief = Read-FoundryJson $BriefPath if ($Destination) { $brief.destination = $Destination } # 1. Validate inputs $validation = Test-FoundryBrief -Brief $brief -Mode Approved -BriefPath $BriefPath -Catalog $catalog if (-not $validation.Valid) { throw ("The brief is not ready for generation.`n" + (Format-FoundryValidation $validation)) } if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw 'git was not found on PATH. Install it first: winget install --id Git.Git -e' } # 2. Validate destination $dest = Resolve-FoundryDestination $brief.destination $state = Get-DestinationState $dest switch ($state) { 'file' { throw "Destination '$dest' is an existing file. Nothing was written." } 'git-repo' { throw "Destination '$dest' already contains a Git repository. The Foundry never overwrites an existing project; choose another folder. Nothing was written." } 'non-empty' { throw "Destination '$dest' already exists and is not empty. The Foundry never overwrites existing work; choose another folder or move the existing one yourself. Nothing was written." } } $parent = Split-Path $dest -Parent $leaf = Split-Path $dest -Leaf New-Item -ItemType Directory -Force -Path $parent | Out-Null $stale = Remove-StaleStaging $parent $leaf $staging = Join-Path $parent (".$leaf.foundry-staging-" + (Get-Date -Format 'yyyyMMddHHmmss') + '-' + [Guid]::NewGuid().ToString('N').Substring(0, 6)) $published = $false $resolved = Resolve-FoundryProject $brief $catalog $step = { param($name) if ($FailAfterStep -eq $name) { throw "Simulated interruption after step '$name' (test hook)." } } try { New-Item -ItemType Directory -Path $staging | Out-Null $vars = New-DocVariables $brief $resolved $catalog $dest $tpl = Join-Path $script:FoundryRoot 'templates' # 3. Common files and docs Copy-TemplateTree (Join-Path $tpl 'repo') $staging $vars if (-not $resolved.onCommodore) { Remove-Item -LiteralPath (Join-Path $staging 'tools/to-commodore.ps1'), (Join-Path $staging 'tools/from-commodore.ps1') -Force } & $step 'templates' # 4. Starter source: recipe default, then project-specific files on top $starterDir = Join-Path $tpl "starters/$($resolved.starter)" $manifest = Join-Path $starterDir 'starter.json' if (Test-Path -LiteralPath $manifest) { foreach ($inc in (Read-FoundryJson $manifest).include) { Copy-TemplateTree (Join-Path $tpl "starters/$inc") $staging $vars } } Copy-TemplateTree $starterDir $staging $vars if ($brief.starter.filesDir) { $filesDir = (Resolve-Path -LiteralPath (Join-Path (Split-Path $BriefPath -Parent) $brief.starter.filesDir)).ProviderPath Copy-TemplateTree $filesDir $staging $vars } foreach ($dir in 'src', 'fixtures') { New-Item -ItemType Directory -Force -Path (Join-Path $staging $dir) | Out-Null } if (-not (Get-ChildItem -LiteralPath (Join-Path $staging 'fixtures') -Force)) { Set-Content -LiteralPath (Join-Path $staging 'fixtures/README.md') -Value "# Fixtures`n`nSample inputs for tests go here. Files in this folder are stored byte-for-byte (see .gitattributes)." } # 5. project.json = approved brief + resolved configuration $project = [ordered]@{} foreach ($k in $brief.Keys) { $project[$k] = $brief[$k] } $project.destination = $dest $project.generated = [ordered]@{ by = 'C64/C128 Dev Foundry'; foundryVersion = '1.0'; on = (Get-Date -Format 'yyyy-MM-dd'); fromBrief = (Split-Path $BriefPath -Leaf) } $project.resolved = $resolved [IO.File]::WriteAllText((Join-Path $staging 'project.json'), ($project | ConvertTo-Json -Depth 64), [Text.UTF8Encoding]::new($false)) & $step 'files' # 6. Template completeness $unresolved = @(Find-UnresolvedPlaceholders $staging) if ($unresolved.Count) { throw ("Unresolved template placeholders:`n" + (($unresolved | ForEach-Object { " $($_.File):$($_.Line) $($_.Text)" }) -join "`n")) } # 7. Git Invoke-Git $staging @('init', '-q', '-b', 'main') | Out-Null Invoke-Git $staging @('add', '-A') | Out-Null $name = (Invoke-Git $staging @('config', 'user.name') -AllowFail) -join '' $email = (Invoke-Git $staging @('config', 'user.email') -AllowFail) -join '' $committed = $false if ($name -and $email) { Invoke-Git $staging @('commit', '-q', '--no-verify', '-m', "Initial handoff from the C64/C128 Dev Foundry`n`nApproved spec: $($brief.project.name). Starter (milestone M0) plus implementation docs.") | Out-Null $committed = $true } & $step 'git' # 8. Publish if ($state -eq 'empty') { Remove-Item -LiteralPath $dest -Force } Move-Item -LiteralPath $staging -Destination $dest $published = $true } finally { if (-not $published -and (Test-Path -LiteralPath $staging)) { Remove-Item -LiteralPath $staging -Recurse -Force -ErrorAction SilentlyContinue } if (-not $published -and $state -eq 'empty' -and -not (Test-Path -LiteralPath $dest)) { New-Item -ItemType Directory -Path $dest | Out-Null } } # 9. Starter verification in the published repo $verification = [ordered]@{ status = 'skipped'; exitCode = $null; output = @() } if (-not $SkipVerify) { $out = & pwsh -NoProfile -File (Join-Path $dest 'tools/smoke.ps1') 2>&1 | ForEach-Object { "$_" } $code = $LASTEXITCODE $verification.exitCode = $code $verification.output = @($out) $verification.status = switch ($code) { 0 { 'passed' } 1 { 'failed' } 2 { 'not run: missing tool' } 3 { 'manual verification only' } default { "unknown (exit $code)" } } } [pscustomobject]@{ Destination = $dest Committed = $committed StaleRemoved = @($stale) Warnings = @($validation.Warnings | ForEach-Object { $_.Message }) Verification = $verification HandoffMessage = $vars.HANDOFF_MESSAGE Targets = @($resolved.targets | ForEach-Object { [pscustomobject]@{ Id = $_.id; Artifact = $_.artifact; Status = $_.recipeStatus } }) } } function Format-FoundrySpecPreview { <# .SYNOPSIS Markdown summary of a brief for the user to approve before generation (interview step 4). #> param([Parameter(Mandatory)][hashtable]$Brief, [string]$BriefPath, [hashtable]$Catalog = (Get-FoundryCatalog)) $check = Test-FoundryBrief -Brief $Brief -Mode Draft -BriefPath $BriefPath -Catalog $Catalog $blocking = @($check.Missing | Where-Object { $_.Stage -ne 'review' }) + @($check.Errors) + @($check.Conflicts) if ($blocking.Count) { throw ("The brief is not complete enough to preview.`n" + (Format-FoundryValidation $check)) } $resolved = Resolve-FoundryProject $Brief $Catalog $dest = Resolve-FoundryDestination $Brief.destination $v = New-DocVariables $Brief $resolved $Catalog $dest $m1 = @(Get-List $Brief.milestones)[0] $lines = @( "# Proposed spec: $($Brief.project.name)", '', $Brief.project.summary, '', "**Smallest useful version:** $($Brief.project.smallestUsefulVersion)", '', '## Scope', '', "**First release:** $($Brief.scope.firstRelease)", '', '**In scope**', $v.IN_SCOPE, '', '**Out of scope**', $v.OUT_OF_SCOPE, '', '## Target and toolchain', '', $v.TARGETS_TABLE, '', $v.DUAL_TARGET, '', "- Language: **$($resolved.languageTitle)** via $($resolved.recipeTitle)", "- Build location: $($v.BUILD_LOCATION)", "- Testing: VICE; real hardware: $($v.REAL_HARDWARE)", "- $($v.TOOLCHAIN_OVERRIDE)", '', 'Why:', $v.TOOLCHAIN_REASONS, '', (($resolved.targets | ForEach-Object { "- Starter for ``$($_.id)``: **$($_.recipeStatus)** configuration$(if (@($_.validationPlan).Count) { ' (validation plan included)' })" }) -join "`n"), '', '## Design decisions', '', $v.DESIGN_TABLE, '', '## Assumptions', '', $v.ASSUMPTIONS, '', '## Unresolved decisions', '', $v.OPEN_DECISIONS, '', '## Acceptance checks', '' ) foreach ($r in @(Get-List $Brief.requirements)) { $lines += "- **$($r.id) $($r.title)** ($($r.priority)): " + ((@(Get-List $r.acceptance)) -join '; ') } $lines += @('', '## First milestone', '', "M0 (automatic): the starter builds and passes the smoke test. Expected screen: $($Brief.starter.expectedScreen)", '') if ($m1) { $lines += "$($m1.id) - $($m1.title): $($m1.goal)" foreach ($t in @(Get-List $m1.tasks)) { $lines += "- $($t.id): $($t.text) (done when: $($t.check))" } } $lines += @('', '## Destination', '', "``$dest`` ($(Get-DestinationState $dest))", '', 'Reply "approve" to generate the project, or tell me what to change.') $lines -join "`n" } Export-ModuleMember -Function Format-FoundrySpecPreview, Get-FoundryRoot, Read-FoundryJson, Get-FoundryCatalog, Test-FoundryBrief, Format-FoundryValidation, Resolve-FoundryDestination, Get-DestinationState, Resolve-FoundryProject, Expand-FoundryTemplate, Find-UnresolvedPlaceholders, New-FoundryProject