public/Show-OctaHistory.ps1
|
function Show-OctaHistory { <# .SYNOPSIS Read-only view over the existing Run Record folders already used by Undo-OctaRun - no new storage, just a projection of data that already exists (research.md). #> [CmdletBinding()] param() $runsRoot = Get-OctaRunsRoot $runFolders = Get-ChildItem -Path $runsRoot -Directory -ErrorAction SilentlyContinue | Sort-Object Name -Descending $history = @( foreach ($runFolder in $runFolders) { $runFile = Join-Path $runFolder.FullName 'run.json' if (-not (Test-Path $runFile)) { continue } # ponytail: one unreadable run.json (interrupted write, disk issue, hand-edited file) # used to throw out of ConvertFrom-Json and take the whole history listing with it - # verified by dropping a single malformed file into the runs folder. Skip that one # record and still show every other run, which is the whole point of the view. try { $record = Get-Content -Path $runFile -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop } catch { Write-Host (" (skipping unreadable run record: {0})" -f $runFolder.Name) continue } [pscustomobject]@{ RunId = $record.RunId Timestamp = $record.Timestamp CategoriesApplied = ($record.CategoriesApplied -join ', ') ActionCount = @($record.ActionSnapshots).Count Status = $record.Status } } ) foreach ($h in $history) { Write-Host ("{0,-16} {1,-24} {2,-40} {3,-6} {4}" -f $h.RunId, $h.Timestamp, $h.CategoriesApplied, $h.ActionCount, $h.Status) } return $history } |