categories/AiFeatures.ps1

# AI Features category: recent Windows 11 AI surfaces distinct from Copilot/Recall - Click to
# Do, Edge's AI sidebar (Hubs), and the WindowsAI scheduled task that otherwise auto-configures
# on first login. Paint AI/Notepad AI are intentionally NOT included: no reliably-documented
# Group Policy/registry mechanism was confirmed for either during research (see
# specs/006-win11debloat-parity/research.md) - shipping a guessed key would risk silently doing
# nothing (or worse) while claiming success, so they're dropped rather than faked.

function Get-OctaAiFeaturesCategory {
    [CmdletBinding()]
    param()
    return [pscustomobject]@{
        Id                          = 'ai-features'
        DisplayName                 = 'AI Features'
        Description                 = 'Click to Do, Edge AI sidebar, AI service autostart'
        RequiresElevation           = $true
        ContainsIrreversibleActions = $false
        GetActionsFunction          = 'Get-OctaAiFeaturesActions'
        ApplyActionFunction         = 'Set-OctaAiFeaturesAction'
    }
}

function Get-OctaAiFeaturesActions {
    [CmdletBinding()]
    param()
    $actions = @()

    $regPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsAI'
    $current = $null
    if (Test-Path $regPath) {
        $current = (Get-ItemProperty -Path $regPath -Name 'DisableClickToDo' -ErrorAction SilentlyContinue).DisableClickToDo
    }
    if ($null -eq $current -or $current -ne 1) {
        $displayCurrent = if ($null -eq $current) { '(not set)' } else { $current }
        $actions += New-OctaAction -TargetType Registry -TargetIdentifier "$regPath|DisableClickToDo" `
            -CurrentValue $displayCurrent -PlannedValue 1 -Reversible $true
    }

    $edgeRegPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge'
    $edgeCurrent = $null
    if (Test-Path $edgeRegPath) {
        $edgeCurrent = (Get-ItemProperty -Path $edgeRegPath -Name 'HubsSidebarEnabled' -ErrorAction SilentlyContinue).HubsSidebarEnabled
    }
    if ($null -eq $edgeCurrent -or $edgeCurrent -ne 0) {
        $displayCurrent = if ($null -eq $edgeCurrent) { '(not set)' } else { $edgeCurrent }
        $actions += New-OctaAction -TargetType Registry -TargetIdentifier "$edgeRegPath|HubsSidebarEnabled" `
            -CurrentValue $displayCurrent -PlannedValue 0 -Reversible $true
    }

    $taskPath = '\Microsoft\Windows\WindowsAI\Settings\'
    $taskName = 'InitialConfiguration'
    $task = Get-ScheduledTask -TaskPath $taskPath -TaskName $taskName -ErrorAction SilentlyContinue
    if ($task -and $task.State -ne 'Disabled') {
        $actions += New-OctaAction -TargetType ScheduledTask -TargetIdentifier ('{0}|{1}' -f $taskPath, $taskName) `
            -CurrentValue $task.State.ToString() -PlannedValue 'Disabled' -Reversible $true
    }

    return $actions
}

function Set-OctaAiFeaturesAction {
    [CmdletBinding()]
    param([Parameter(Mandatory)]$Action)

    switch ($Action.TargetType) {
        'Registry' {
            $keyPath, $valueName = $Action.TargetIdentifier -split '\|', 2
            if (-not (Test-Path $keyPath)) {
                New-Item -Path $keyPath -Force | Out-Null
            }
            Set-ItemProperty -Path $keyPath -Name $valueName -Value $Action.PlannedValue -Type DWord
        }
        'ScheduledTask' {
            $parts = $Action.TargetIdentifier -split '\|', 2
            Disable-ScheduledTask -TaskPath $parts[0] -TaskName $parts[1] | Out-Null
        }
    }
}