Payload/scripts/kaden/harness-advisory.ps1

#Requires -Version 5.1
<#
.SYNOPSIS
    Public advisory continuity actions for one feature.

.DESCRIPTION
    Driving port for issue, decision, amendment, route, and rebuild-index.
    Resume context, projection exclusion, and integrated verification are the
    consumer and evidence actions on the same port. Invoke only through
    pwsh -File scripts/kaden/harness-invoke.ps1 harness-advisory.ps1.

    Action classes:
    - Workflow: issue, decision, amendment, route
    - Maintenance: rebuild-index
    - Evidence: resume-context, projection-exclusion, verify-integration

    Evidence and maintenance actions do not change turns, phases, ownership,
    mandatory routing, or review_ready.

.PARAMETER SlateReply
    Numbered operator decision slate for Action decision. One line per finding
    position (`1 Fix`, `3 Fix owner spike-runner`, `2 Defer - trigger`, or
    `all Fix`). A Fix on a route with no default owner is not recorded until the
    line names an owner, and those finding ids are returned in needs_owner.
    `3 Fix owner` with the name omitted is not recorded either. A named owner
    on specification must be spec-writer, and on domain-design must be ddd-architect.
    Incomplete Defer / Promote To Backlog / More Info asks only for the missing direction.

.EXAMPLE
    pwsh -File scripts/kaden/harness-invoke.ps1 harness-advisory.ps1 -Feature my-feature -Action issue -ActionId advact-11111111-1111-1111-1111-111111111111 -Actor operator -Target feature -TargetReference slice-plan.md -ReviewQuestion "Is the contract complete?" -EvidenceBoundary "The approved spec" -IntentionalLatitude "Local recovery only" -ReviewerProvenance "operator" -AdvisoryReadiness Proceed -ReadinessReason "The public action is ready to record."

.EXAMPLE
    pwsh -File scripts/kaden/harness-invoke.ps1 harness-advisory.ps1 -Feature my-feature -Action rebuild-index -ActionId advact-22222222-2222-2222-2222-222222222222 -Actor operator
#>

[CmdletBinding()]
param(
    [Alias('h', 'help')]
    [switch]$ShowHelp,

    [string]$Feature = '',
    [string]$Action = '',
    [string]$ActionId = '',
    [string]$Actor = '',
    [string]$FeatureRoot = '',
    [string]$RepoRoot = '',
    [switch]$AllowArbitraryFeatureRoot,
    [string]$Target = '',
    [string]$TargetReference = '',
    [string]$ReviewQuestion = '',
    [string]$EvidenceBoundary = '',
    [string]$IntentionalLatitude = '',
    [string]$ReviewerProvenance = '',
    [string]$AdvisoryReadiness = '',
    [string]$ReadinessReason = '',
    [string]$FindingsJson = '',
    [string]$DecisionsJson = '',
    [string]$ReportId = '',
    [string]$FindingId = '',
    [string]$DecisionJson = '',
    [string]$SlateReply = '',
    [string]$PriorEventId = '',
    [string]$AmendmentReason = '',
    [string]$AmendedAt = '',
    [string]$IssuedAt = '',
    [string]$OccurredAt = '',
    [string]$SelectedWorkDestination = '',
    [string]$NextOwner = '',
    [string]$TurnContextJson = '',
    [string]$ReportScope = '',
    [string]$MandatoryNextAction = '',
    [string]$ProfileName = 'standard'
)

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

$workflowPath = Join-Path $PSScriptRoot 'advisory\AdvisoryWorkflow.psm1'
$contractPath = Join-Path $PSScriptRoot 'harness\lib\HarnessContract.psm1'
Import-Module $contractPath -Force

if ($ShowHelp) {
    Import-Module $workflowPath -Force
    Get-Help -Name $PSCommandPath -Full
    Write-Output ''
    Write-Output 'Action classes:'
    Write-Output ' Workflow: issue, decision, amendment, route'
    Write-Output ' Maintenance: rebuild-index'
    Write-Output ' Evidence: resume-context, projection-exclusion, verify-integration'
    Write-Output ''
    Write-Output ('Cross-entry: ' + (Get-AdvisoryCrossEntrySentence))
    exit 0
}

if ([string]::IsNullOrWhiteSpace($RepoRoot)) {
    $RepoRoot = Get-HarnessRepoRoot -StartPath $PSScriptRoot
}
if ([string]::IsNullOrWhiteSpace($FeatureRoot)) {
    $FeatureRoot = Get-HarnessFeatureRoot -RepoRoot $RepoRoot -Feature $Feature
} else {
    $FeatureRoot = Get-HarnessFeatureRoot -RepoRoot $RepoRoot -Feature $Feature -FeatureRootOverride $FeatureRoot -AllowArbitraryFeatureRoot:$AllowArbitraryFeatureRoot
}

Import-Module $workflowPath -Force

$request = [pscustomobject]@{
    Feature                   = $Feature
    Action                    = $Action
    ActionId                  = $ActionId
    Actor                     = $Actor
    FeatureRoot               = $FeatureRoot
    RepoRoot                  = $RepoRoot
    Target                    = $Target
    TargetReference           = $TargetReference
    ReviewQuestion            = $ReviewQuestion
    EvidenceBoundary          = $EvidenceBoundary
    IntentionalLatitude       = $IntentionalLatitude
    ReviewerProvenance        = $ReviewerProvenance
    AdvisoryReadiness         = $AdvisoryReadiness
    ReadinessReason           = $ReadinessReason
    FindingsJson              = $FindingsJson
    DecisionsJson             = $DecisionsJson
    ReportId                  = $ReportId
    FindingId                 = $FindingId
    DecisionJson              = $DecisionJson
    SlateReply                = $SlateReply
    PriorEventId              = $PriorEventId
    AmendmentReason           = $AmendmentReason
    AmendedAt                 = $AmendedAt
    IssuedAt                  = $IssuedAt
    OccurredAt                = $OccurredAt
    SelectedWorkDestination   = $SelectedWorkDestination
    NextOwner                 = $NextOwner
    TurnContextJson           = $TurnContextJson
    ReportScope               = $ReportScope
    MandatoryNextAction       = $MandatoryNextAction
    ProfileName               = $ProfileName
}

$result = Invoke-AdvisoryWorkflowAction -Request $request
$result | ConvertTo-Json -Depth 30 -Compress
exit 0