From 7956969c8b69375fddb3b5773fd3c8720874755f Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:03:57 +0400 Subject: [PATCH 1/8] Improves config loading feedback Adds a detailed output of configuration properties upon successful loading. This enhancement provides immediate feedback to the user, confirming that the configuration file has been loaded correctly and displaying the available properties. --- PowerShell_AI_Agent/test.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerShell_AI_Agent/test.ps1 b/PowerShell_AI_Agent/test.ps1 index 1e8bb17..ae8d4cc 100644 --- a/PowerShell_AI_Agent/test.ps1 +++ b/PowerShell_AI_Agent/test.ps1 @@ -11,6 +11,7 @@ if (Test-Path $configPath) { Write-Host "āœ… Configuration file exists" -ForegroundColor Green $config = Get-Content $configPath | ConvertFrom-Json Write-Host "āœ… Configuration loaded successfully" -ForegroundColor Green + Write-Host " Configuration properties: $($config.PSObject.Properties.Name -join ', ')" -ForegroundColor Cyan } else { Write-Host "āŒ Configuration file not found" -ForegroundColor Red } From 4de69b584c28bb4234ed530e8bb27ac393852475 Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:20 +0400 Subject: [PATCH 2/8] Initialize global variables for speech and autopilot --- PowerShell_AI_Agent/scripts/main.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index f148feb..f55ebc1 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -19,6 +19,11 @@ if ($PSVersionTable.PSVersion.Major -lt 7) { exit 1 } +# Global variables +$script:SpeechRecognizer = $null +$script:SpeechSynthesizer = $null +$script:AutopilotEnabled = $false + # Load configuration function Load-Configuration { param([string]$ConfigPath) From 070d5c7e20bbb9b5589e669333323f4af8fb818f Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:20 +0400 Subject: [PATCH 3/8] Refactor voice recognition to pass recognized text as a parameter --- PowerShell_AI_Agent/scripts/main.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index f55ebc1..6e7dd04 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -206,13 +206,13 @@ function Start-VoiceRecognition { if ($script:SpeechRecognizer) { $script:SpeechRecognizer.SpeechRecognized += { param($sender, $e) - $command = $e.Result.Text - Write-Host "šŸŽ¤ Recognized: $command" -ForegroundColor Cyan - & $OnRecognized $command + $recognizedText = $e.Result.Text + Write-Host "šŸŽ¤ Recognized: $recognizedText" -ForegroundColor Cyan + & $OnRecognized -RecognizedCommand $recognizedText } $script:SpeechRecognizer.RecognizeAsync() - Write-Host "šŸŽ¤ Voice recognition started. Speak your command..." -ForegroundColor Green + Write-Host "šŸŽ¤ Voice recognition started. Speak your commands..." -ForegroundColor Green } } catch { From efc6bad6384ec8c54583408419bd117f131db58d Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:20 +0400 Subject: [PATCH 4/8] Remove Speak-Response function --- PowerShell_AI_Agent/scripts/main.ps1 | 96 ++-------------------------- 1 file changed, 5 insertions(+), 91 deletions(-) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index 6e7dd04..561e3c1 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -232,105 +232,19 @@ function Stop-VoiceRecognition { } } -function Speak-Response { - param([string]$Text) - - try { - if ($script:SpeechSynthesizer) { - $script:SpeechSynthesizer.SpeakAsync($Text) | Out-Null - } - } - catch { - Write-Warning "Failed to speak response: $_" - } -} - -# AI integration functions -function Invoke-AIAnalysis { - param( - [string]$Command, - [object]$Context = @{}, - [object]$Config - ) - - try { - # Simulate AI analysis (in a real implementation, this would call an AI API) - $analysis = @{ - intent = "unknown" - confidence = 0.8 - suggestedActions = @() - response = "" - } - - # Basic intent recognition - $commandLower = $Command.ToLower() - - if ($commandLower -match "get-childitem|show|list|find") { - $analysis.intent = "navigation" - $analysis.suggestedActions = @("Get-ChildItem", "Get-Process", "Get-Service") - $analysis.response = "I'll help you navigate the system. Here are some useful commands:" - } - elseif ($commandLower -match "start|run|execute|invoke") { - $analysis.intent = "execution" - $analysis.suggestedActions = @("Start-Process", "Invoke-Expression", "Start-Service") - $analysis.response = "I'll help you execute commands. Here are some execution options:" - } - elseif ($commandLower -match "analyze|check|review|test") { - $analysis.intent = "analysis" - $analysis.suggestedActions = @("Get-Process", "Get-Service", "Test-Path") - $analysis.response = "I'll help you analyze the system. Here are some analysis commands:" - } - elseif ($commandLower -match "create|new|add|build") { - $analysis.intent = "creation" - $analysis.suggestedActions = @("New-Item", "New-Object", "Add-Content") - $analysis.response = "I'll help you create new items. Here are some creation commands:" - } - else { - $analysis.intent = "general" - $analysis.suggestedActions = @("Get-Help", "Get-Command", "Get-Module") - $analysis.response = "I understand your request. Here are some general PowerShell commands:" - } - - return $analysis - } - catch { - Write-Error "Failed to analyze command: $_" - return @{ - intent = "error" - confidence = 0.0 - suggestedActions = @() - response = "Sorry, I encountered an error while analyzing your command." - } - } -} - -# Autopilot mode functions +# Autopilot functions function Enable-AutopilotMode { param([object]$Config) try { - $Config.Autopilot.Enabled = $true + $script:AutopilotEnabled = $true Write-Host "šŸ¤– Autopilot mode enabled" -ForegroundColor Green - - # Start monitoring for autonomous actions - Start-Job -ScriptBlock { - while ($true) { - # Monitor system for opportunities to help - Start-Sleep -Seconds 30 - - # Check for common issues and suggest solutions - $processes = Get-Process | Where-Object { $_.CPU -gt 10 } - if ($processes) { - Write-Host "šŸ¤– Autopilot: High CPU usage detected. Consider optimizing processes." -ForegroundColor Yellow - } - } - } | Out-Null - - return $true + Write-Host " Autonomy Level: $($Config.Autopilot.AutonomyLevel)" -ForegroundColor Cyan + Write-Host " Risk Tolerance: $($Config.Autopilot.RiskTolerance)" -ForegroundColor Cyan + Write-Host " Max Concurrent Tasks: $($Config.Autopilot.MaxConcurrentTasks)" -ForegroundColor Cyan } catch { Write-Error "Failed to enable autopilot mode: $_" - return $false } } From 051b501fa732c2b61444fe8c8653aac4aa525dd5 Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:21 +0400 Subject: [PATCH 5/8] Refactor Autopilot Mode to Use Global Variable --- PowerShell_AI_Agent/scripts/main.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index 561e3c1..c8371f5 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -252,17 +252,15 @@ function Disable-AutopilotMode { param([object]$Config) try { - $Config.Autopilot.Enabled = $false + $script:AutopilotEnabled = $false Write-Host "šŸ¤– Autopilot mode disabled" -ForegroundColor Yellow - return $true } catch { Write-Error "Failed to disable autopilot mode: $_" - return $false } } -# Main command processing +# Command processing function function Process-Command { param( [string]$Command, From bfa1c4330f1ef568f816a8ed71d13c0e9922cfde Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:21 +0400 Subject: [PATCH 6/8] Refactor command processing for simpler intent detection and execution --- PowerShell_AI_Agent/scripts/main.ps1 | 88 ++++++++++++++++------------ 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index c8371f5..ac00a7c 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -269,57 +269,67 @@ function Process-Command { ) try { - Write-Host "šŸ”„ Processing command: $Command" -ForegroundColor Cyan + Write-Host "`nšŸ” Processing command: $Command" -ForegroundColor Yellow # Add command to memory - $memoryId = Add-MemoryEntry -Type "command" -Content $Command -MemoryPath $MemoryPath + Add-MemoryEntry -Type "command" -Content $Command -MemoryPath $MemoryPath - # Analyze command with AI - $analysis = Invoke-AIAnalysis -Command $Command -Config $Config + # Analyze command intent + $commandLower = $Command.ToLower() - # Generate response - $response = @" -šŸ¤– PowerShell AI Agent Response -=============================== - -Command: $Command -Intent: $($analysis.intent) -Confidence: $($analysis.confidence) - -$($analysis.response) - -Suggested Actions: -$(($analysis.suggestedActions | ForEach-Object { "- $_" }) -join "`n") - -Memory ID: $memoryId -"@ - - Write-Host $response -ForegroundColor White - - # Speak response if voice is enabled - if ($Config.Voice.Enabled) { - Speak-Response -Text $analysis.response + # Simple intent detection + if ($commandLower -match "get-childitem|ls|dir|show|list") { + Write-Host "šŸ“ Navigation command detected" -ForegroundColor Green + $result = Invoke-Expression $Command + Write-Host "Navigation completed successfully" -ForegroundColor Green } - - # Execute suggested actions if autopilot is enabled - if ($Config.Autopilot.Enabled) { - Write-Host "šŸ¤– Autopilot: Executing suggested actions..." -ForegroundColor Green - foreach ($action in $analysis.suggestedActions) { - try { - Write-Host "Executing: $action" -ForegroundColor Yellow - Invoke-Expression $action | Out-Null - } - catch { - Write-Warning "Failed to execute $action : $_" + elseif ($commandLower -match "start|run|execute|invoke") { + Write-Host "⚔ Execution command detected" -ForegroundColor Green + $result = Invoke-Expression $Command + Write-Host "Command executed successfully" -ForegroundColor Green + } + elseif ($commandLower -match "analyze|check|review|test") { + Write-Host "šŸ” Analysis command detected" -ForegroundColor Green + $result = Invoke-Expression $Command + Write-Host "Analysis completed" -ForegroundColor Green + } + elseif ($commandLower -match "create|new|add|build") { + Write-Host "šŸ› ļø Creation command detected" -ForegroundColor Green + $result = Invoke-Expression $Command + Write-Host "Creation completed" -ForegroundColor Green + } + elseif ($commandLower -match "modify|change|update|edit") { + Write-Host "āœļø Modification command detected" -ForegroundColor Green + $result = Invoke-Expression $Command + Write-Host "Modification completed" -ForegroundColor Green + } + elseif ($commandLower -match "delete|remove|clear") { + Write-Host "šŸ—‘ļø Deletion command detected" -ForegroundColor Green + Write-Warning "āš ļø Deletion command detected" + if ($Config.Security.RequireConfirmation) { + $confirmation = Read-Host "Are you sure you want to delete? (y/N)" + if ($confirmation -ne "y") { + Write-Host "Deletion cancelled" -ForegroundColor Yellow + return } } + $result = Invoke-Expression $Command + Write-Host "Deletion completed" -ForegroundColor Green + } + else { + Write-Host "ā“ General command execution" -ForegroundColor Yellow + $result = Invoke-Expression $Command + Write-Host "Command completed" -ForegroundColor Green } - return $analysis + # Add response to memory + Add-MemoryEntry -Type "response" -Content "Command processed successfully" -Context $Command -MemoryPath $MemoryPath + + return $result } catch { Write-Error "Failed to process command: $_" - return $null + Add-MemoryEntry -Type "error" -Content "Error: $_" -Context $Command -MemoryPath $MemoryPath } } From 0bf5f9cc20272dc1d324a3dc2b2595710f8a88cc Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:22 +0400 Subject: [PATCH 7/8] Improve help message formatting --- PowerShell_AI_Agent/scripts/main.ps1 | 48 +++++++++++++--------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index ac00a7c..12a251e 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -345,31 +345,29 @@ function Main { # Show help if requested if ($Help) { - Write-Host @" -PowerShell AI Agent - Help -========================== - -Usage: .\main.ps1 [options] - -Options: - -Command Command to process - -Voice Enable voice recognition - -Autopilot Enable autopilot mode - -Help Show this help message - -ConfigPath Path to configuration file - -Examples: - .\main.ps1 -Command "Get-ChildItem" - .\main.ps1 -Voice -Command "Show me the processes" - .\main.ps1 -Autopilot -Command "Monitor system performance" - -Features: - - Voice recognition and synthesis - - Autopilot mode for autonomous execution - - Memory system for persistent learning - - AI-powered command analysis - - Cross-platform PowerShell 7 support -"@ -ForegroundColor Cyan + Write-Host "PowerShell AI Agent - Help" -ForegroundColor Cyan + Write-Host "==========================" -ForegroundColor Cyan + Write-Host "" + Write-Host "Usage: .\main.ps1 [options]" -ForegroundColor White + Write-Host "" + Write-Host "Options:" -ForegroundColor White + Write-Host " -Command string Command to process" -ForegroundColor White + Write-Host " -Voice Enable voice recognition" -ForegroundColor White + Write-Host " -Autopilot Enable autopilot mode" -ForegroundColor White + Write-Host " -Help Show this help message" -ForegroundColor White + Write-Host " -ConfigPath string Path to configuration file" -ForegroundColor White + Write-Host "" + Write-Host "Examples:" -ForegroundColor White + Write-Host " .\main.ps1 -Command 'Get-ChildItem'" -ForegroundColor White + Write-Host " .\main.ps1 -Voice -Command 'Show me the processes'" -ForegroundColor White + Write-Host " .\main.ps1 -Autopilot -Command 'Monitor system performance'" -ForegroundColor White + Write-Host "" + Write-Host "Features:" -ForegroundColor White + Write-Host " - Voice recognition and synthesis" -ForegroundColor White + Write-Host " - Autopilot mode for autonomous execution" -ForegroundColor White + Write-Host " - Memory system for persistent learning" -ForegroundColor White + Write-Host " - AI-powered command analysis" -ForegroundColor White + Write-Host " - Cross-platform PowerShell 7 support" -ForegroundColor White return } From f203baf9d83eb402ae525a75cf1ee9fd3fc7c4e8 Mon Sep 17 00:00:00 2001 From: dopeuni444 Date: Thu, 31 Jul 2025 13:19:22 +0400 Subject: [PATCH 8/8] Update system status to reflect global autopilot variable --- PowerShell_AI_Agent/scripts/main.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PowerShell_AI_Agent/scripts/main.ps1 b/PowerShell_AI_Agent/scripts/main.ps1 index 12a251e..4a80e18 100644 --- a/PowerShell_AI_Agent/scripts/main.ps1 +++ b/PowerShell_AI_Agent/scripts/main.ps1 @@ -462,7 +462,7 @@ function Main { Write-Host "System Status:" -ForegroundColor Green Write-Host " PowerShell Version: $($PSVersionTable.PSVersion)" -ForegroundColor White Write-Host " Voice Recognition: $($config.Voice.Enabled)" -ForegroundColor White - Write-Host " Autopilot Mode: $($config.Autopilot.Enabled)" -ForegroundColor White + Write-Host " Autopilot Mode: $($script:AutopilotEnabled)" -ForegroundColor White Write-Host " Memory Entries: $(($entries = Get-MemoryEntries -MemoryPath $memoryPath).Count)" -ForegroundColor White } else { @@ -483,6 +483,5 @@ function Main { Write-Host "PowerShell AI Agent shutting down..." -ForegroundColor Green } - # Execute main function with parameters Main -Command $Command -Voice $Voice -Autopilot $Autopilot -Help $Help -ConfigPath $ConfigPath