public/Get-AITool.ps1

function Get-AITool {
    <#
    .SYNOPSIS
        Retrieves information about installed AI CLI tools.

    .DESCRIPTION
        Displays information about AI CLI tools including their installation status,
        version, and command path. By default, shows all available tools.

    .PARAMETER Tool
        The specific AI tool to check. If not specified, shows information for all tools.
        Valid values: All, ClaudeCode, Aider, Gemini, GitHubCopilot, Codex, Cursor, Ollama

    .EXAMPLE
        Get-AITool
        Shows information for all AI tools

    .EXAMPLE
        Get-AITool -Tool ClaudeCode
        Shows information only for Claude Code

    .EXAMPLE
        Get-AITool -Tool Aider
        Shows information only for Aider

    .OUTPUTS
        AITools.ToolInfo
        An object containing Tool name, Installed status, Version, and Path.
    #>

    [CmdletBinding()]
    param(
        [Parameter()]
        [string]$Tool = 'All'
    )

    begin {
        Write-PSFMessage -Level Verbose -Message "Starting Get-AITool for: $Tool"

        # Determine which tools to check
        $toolsToCheck = @()
        if ($Tool -eq 'All' -or [string]::IsNullOrWhiteSpace($Tool)) {
            Write-PSFMessage -Level Verbose -Message "Checking all available tools"
            $toolsToCheck = $script:ToolDefinitions.Keys | Sort-Object { $script:ToolDefinitions[$_].Priority }
        } else {
            Write-PSFMessage -Level Verbose -Message "Checking specific tool: $Tool"
            $toolsToCheck = @($Tool)
        }
    }

    process {
        foreach ($currentToolName in $toolsToCheck) {
            Write-PSFMessage -Level Verbose -Message "Retrieving information for $currentToolName"

            # Get the tool definition
            $toolDef = $script:ToolDefinitions[$currentToolName]

            if (-not $toolDef) {
                Write-PSFMessage -Level Warning -Message "Unknown tool: $currentToolName"
                continue
            }

            # Check if the tool is installed
            $isInstalled = Test-Command -Command $toolDef.Command

            if ($isInstalled) {
                Write-PSFMessage -Level Verbose -Message "$currentToolName is installed"

                # Get version information
                try {
                    $versionOutput = & $toolDef.Command --version 2>&1 | Select-Object -First 1
                    $version = ($versionOutput -replace '^.*?(\d+\.\d+\.\d+).*$', '$1').Trim()

                    # If regex didn't match properly, use the original output
                    if ([string]::IsNullOrWhiteSpace($version) -or $version -eq $versionOutput) {
                        $version = $versionOutput.ToString().Trim()
                    }

                    Write-PSFMessage -Level Verbose -Message "Version: $version"
                } catch {
                    $version = 'Unknown'
                    Write-PSFMessage -Level Verbose -Message "Failed to retrieve version: $_"
                }

                # Get the command path
                try {
                    $commandPath = (Get-Command $toolDef.Command -ErrorAction SilentlyContinue).Source
                    if (-not $commandPath) {
                        $commandPath = (Get-Command $toolDef.Command -ErrorAction SilentlyContinue).Path
                    }
                    Write-PSFMessage -Level Verbose -Message "Path: $commandPath"
                } catch {
                    $commandPath = 'Unknown'
                    Write-PSFMessage -Level Verbose -Message "Failed to retrieve path: $_"
                }
            } else {
                Write-PSFMessage -Level Verbose -Message "$currentToolName is not installed"
                $version = 'N/A'
                $commandPath = 'N/A'
            }

            # Output the tool information
            [PSCustomObject]@{
                PSTypeName = 'AITools.ToolInfo'
                Tool       = $currentToolName
                Installed  = $isInstalled
                Version    = $version
                Path       = $commandPath
            }
        }
    }
}