param( [Parameter(Mandatory = $true)] [string]$RunPath, [Parameter(Mandatory = $true)] [string]$RoleId, [Parameter(Mandatory = $true)] [ValidateSet("pending", "in_progress", "done", "blocked", "rejected")] [string]$Status, [string]$Note ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" if (-not (Test-Path -LiteralPath $RunPath)) { throw "Run path not found: $RunPath" } $manifestPath = Join-Path $RunPath "manifest.json" if (-not (Test-Path -LiteralPath $manifestPath)) { throw "manifest.json not found: $manifestPath" } $manifestRaw = Get-Content -LiteralPath $manifestPath -Raw $manifest = $manifestRaw | ConvertFrom-Json $role = $manifest.roles | Where-Object { $_.id -eq $RoleId } | Select-Object -First 1 if (-not $role) { throw "Role not found: $RoleId" } $reportPath = Join-Path $RunPath (($role.reportPath -replace "/", "\")) if (-not (Test-Path -LiteralPath $reportPath)) { throw "Role report not found: $reportPath" } $reportLines = Get-Content -LiteralPath $reportPath $now = (Get-Date).ToString("s") $statusLineIndex = -1 $updatedLineIndex = -1 for ($index = 0; $index -lt $reportLines.Count; $index++) { if ($reportLines[$index] -like "- Status:*") { $statusLineIndex = $index } if ($reportLines[$index] -like "- Updated At:*") { $updatedLineIndex = $index } } if ($statusLineIndex -ge 0) { $reportLines[$statusLineIndex] = "- Status: $Status" } else { $reportLines = @("- Status: $Status") + $reportLines } if ($updatedLineIndex -ge 0) { $reportLines[$updatedLineIndex] = "- Updated At: $now" } else { $reportLines = @("- Updated At: $now") + $reportLines } if (-not [string]::IsNullOrWhiteSpace($Note)) { $reportLines += "" $reportLines += "## Progress Log ($now)" $reportLines += "" $reportLines += "- $Note" } Set-Content -LiteralPath $reportPath -Value $reportLines -Encoding UTF8 foreach ($manifestRole in $manifest.roles) { if ($manifestRole.id -eq $RoleId) { $manifestRole.status = $Status } } $manifest.updatedAt = $now $manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $manifestPath -Encoding UTF8 Write-Host "Role status updated: $RoleId -> $Status" Write-Host "Report file: $reportPath"