public/Invoke-OctaStartupManager.ps1

function Invoke-OctaStartupManager {
    <#
        .SYNOPSIS
        Lists startup apps (Win32_StartupCommand) and can disable a Registry-Run-key-based one
        by name. FR-043. Reuses the exact same snapshot + Run Record mechanism every category
        already uses - Undo-OctaRun needs no changes to reverse this.

        Startup-folder-shortcut-based entries are listed but not manageable this phase (no
        existing TargetType represents "a file was moved" - see research.md).
    #>

    [CmdletBinding()]
    param(
        [string]$Disable
    )

    $items = @(Get-CimInstance -ClassName Win32_StartupCommand -ErrorAction SilentlyContinue)

    if (-not $Disable) {
        foreach ($item in $items) {
            $locationType = if ($item.Location -match 'Run') { 'RegistryRun' } else { 'StartupFolder' }
            # 007 US6: no reliable, publicly-documented PS 5.1-accessible API reports real
            # per-app boot-time contribution (Task Manager's own "Startup impact" column comes
            # from internal, non-exposed diagnostics data - see research.md). Reporting this
            # honestly rather than fabricating a number, same rule already applied to
            # benchmark.ps1 (FR-020) and the gpu category.
            Add-Member -InputObject $item -MemberType NoteProperty -Name 'BootImpact' -Value 'not measurable' -Force
            Write-Host ("{0,-30} {1,-14} {2,-16} {3}" -f $item.Name, $locationType, $item.BootImpact, $item.Command)
        }
        return $items
    }

    $target = $items | Where-Object { $_.Name -eq $Disable } | Select-Object -First 1
    if (-not $target) {
        return [pscustomobject]@{ Status = 'NotFound'; Message = "Startup item not found: $Disable" }
    }
    if ($target.Location -notmatch 'Run') {
        return [pscustomobject]@{ Status = 'Unsupported'; Message = "'$Disable' is a Startup-folder shortcut, not yet manageable by Octa (see research.md)." }
    }

    $regPath = if ($target.Location -match 'HKLM') {
        "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
    }
    else {
        "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
    }

    $run = New-OctaRunFolder
    $snapshot = $null
    try {
        # Save-OctaRegistrySnapshot no longer checks existence itself (private/StateSnapshot.ps1,
        # 006) - the caller must, same as Save-OctaActionSnapshot's own Registry branch does.
        if (Test-Path $regPath) {
            $fileName = "reg-{0:N}.reg" -f [guid]::NewGuid()
            $destination = Join-Path $run.Path $fileName
            Save-OctaRegistrySnapshot -RegistryPath $regPath -DestinationFile $destination
            $snapshot = [pscustomobject]@{ ActionRef = "$regPath|$($target.Name)"; Type = 'Registry'; SnapshotFile = $fileName }
        }
        Remove-ItemProperty -Path $regPath -Name $target.Name -ErrorAction Stop
    }
    catch {
        return [pscustomobject]@{ Status = 'Error'; Message = $_.Exception.Message }
    }

    Save-OctaRunRecord -RunFolder $run.Path -RunRecord ([pscustomobject]@{
            RunId                      = $run.RunId
            Timestamp                  = (Get-Date).ToString('o')
            CategoriesApplied          = @('startup-manager')
            # 'NotAttempted', not 'SkippedByUser': no restore point is taken for a single
            # startup-entry toggle, and claiming the user skipped it describes a choice they
            # were never offered. Matches Invoke-OctaTaskBrowser, which does the same thing.
            RestorePointStatus         = 'NotAttempted'
            RestorePointSequenceNumber = $null
            ActionSnapshots            = @($snapshot)
            IrreversibleActionRefs     = @()
            Status                     = 'Completed'
        })

    return [pscustomobject]@{ Status = 'Success'; RunId = $run.RunId }
}