param( [Parameter(Mandatory = $true)] [ValidateSet('review', 'closure')] [string]$Boundary, [Parameter(Mandatory = $true)] [string]$PacketPath, [Parameter(Mandatory = $true)] [string]$PassPath, [string]$RepositoryRoot ) $ErrorActionPreference = 'Stop' if (-not $RepositoryRoot) { $RepositoryRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) } $repoFull = [System.IO.Path]::GetFullPath($RepositoryRoot).TrimEnd('\', '/') if (-not (Test-Path -LiteralPath $repoFull -PathType Container)) { throw "Repository root not found: $repoFull" } function Resolve-RepositoryFile { param( [Parameter(Mandatory = $true)] [string]$Path, [Parameter(Mandatory = $true)] [string]$Label ) $candidate = $Path if (-not [System.IO.Path]::IsPathRooted($candidate)) { $candidate = Join-Path $repoFull $candidate } $full = [System.IO.Path]::GetFullPath($candidate) if (-not $full.StartsWith($repoFull + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase)) { throw "$Label must remain inside the repository root: $full" } if (-not (Test-Path -LiteralPath $full -PathType Leaf)) { throw "$Label not found: $full" } return $full } function Invoke-RepositoryGit { param([Parameter(Mandatory = $true)][string[]]$Arguments) $output = & git -C $repoFull -c core.quotepath=false @Arguments 2>&1 if ($LASTEXITCODE -ne 0) { throw "git $($Arguments -join ' ') failed:`n$($output -join "`n")" } return @($output) } function Normalize-RepositoryPath { param([Parameter(Mandatory = $true)][string]$Path) $normalized = $Path.Trim().Trim('`').Replace('\', '/') while ($normalized.StartsWith('./', [System.StringComparison]::Ordinal)) { $normalized = $normalized.Substring(2) } return $normalized } function Get-FrontMatter { param([Parameter(Mandatory = $true)][string]$Text) $match = [regex]::Match($Text, '\A---\r?\n(?
.*?)\r?\n---(?:\r?\n|\z)', [System.Text.RegularExpressions.RegexOptions]::Singleline) if (-not $match.Success) { return '' } return $match.Groups['body'].Value } function Test-IsIntakeNote { param([Parameter(Mandatory = $true)][string]$RepositoryPath) $full = Join-Path $repoFull ($RepositoryPath.Replace('/', [System.IO.Path]::DirectorySeparatorChar)) if (-not (Test-Path -LiteralPath $full -PathType Leaf)) { return $false } $stem = [System.IO.Path]::GetFileNameWithoutExtension($full) if ($stem -match '(?i)(?:^|[-_ ])(?:proposal|handoff)(?:$|[-_ ])') { return $true } $frontMatter = Get-FrontMatter -Text (Get-Content -LiteralPath $full -Raw -Encoding utf8) if (-not $frontMatter) { return $false } return ( $frontMatter -match '(?im)^\s*status:\s*(?:proposal|handoff|adopted-candidate)\s*(?:#.*)?$' -or $frontMatter -match '(?im)^\s*(?:type|owns):[^\r\n]*(?:proposal|handoff)' -or $frontMatter -match '(?im)^\s*-\s*(?:proposal|handoff)\s*$' ) } $packetFull = Resolve-RepositoryFile -Path $PacketPath -Label 'Packet' $passFull = Resolve-RepositoryFile -Path $PassPath -Label 'Pass record' $packetText = Get-Content -LiteralPath $packetFull -Raw -Encoding utf8 $passText = Get-Content -LiteralPath $passFull -Raw -Encoding utf8 $baseMatch = [regex]::Match($passText, '(?im)^intake_base_commit:\s*([0-9a-f]{40})\s*$') if (-not $baseMatch.Success) { throw 'Pass record must name a full 40-character intake_base_commit in its frontmatter' } $baseCommit = $baseMatch.Groups[1].Value.ToLowerInvariant() Invoke-RepositoryGit -Arguments @('rev-parse', '--verify', "$baseCommit^{commit}") | Out-Null $manifest = [System.Collections.Generic.Dictionary[string, string]]::new([System.StringComparer]::OrdinalIgnoreCase) $manifestMatches = [regex]::Matches($packetText, '(?m)^(?