mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2025-09-15 04:17:22 +00:00
Merge pull request #8 from gejjech/hv
Update system status to reflect global autopilot variable
This commit is contained in:
commit
f3211fbe99
@ -19,6 +19,11 @@ if ($PSVersionTable.PSVersion.Major -lt 7) {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Global variables
|
||||||
|
$script:SpeechRecognizer = $null
|
||||||
|
$script:SpeechSynthesizer = $null
|
||||||
|
$script:AutopilotEnabled = $false
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
function Load-Configuration {
|
function Load-Configuration {
|
||||||
param([string]$ConfigPath)
|
param([string]$ConfigPath)
|
||||||
@ -201,13 +206,13 @@ function Start-VoiceRecognition {
|
|||||||
if ($script:SpeechRecognizer) {
|
if ($script:SpeechRecognizer) {
|
||||||
$script:SpeechRecognizer.SpeechRecognized += {
|
$script:SpeechRecognizer.SpeechRecognized += {
|
||||||
param($sender, $e)
|
param($sender, $e)
|
||||||
$command = $e.Result.Text
|
$recognizedText = $e.Result.Text
|
||||||
Write-Host "🎤 Recognized: $command" -ForegroundColor Cyan
|
Write-Host "🎤 Recognized: $recognizedText" -ForegroundColor Cyan
|
||||||
& $OnRecognized $command
|
& $OnRecognized -RecognizedCommand $recognizedText
|
||||||
}
|
}
|
||||||
|
|
||||||
$script:SpeechRecognizer.RecognizeAsync()
|
$script:SpeechRecognizer.RecognizeAsync()
|
||||||
Write-Host "🎤 Voice recognition started. Speak your command..." -ForegroundColor Green
|
Write-Host "🎤 Voice recognition started. Speak your commands..." -ForegroundColor Green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
@ -227,105 +232,19 @@ function Stop-VoiceRecognition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Speak-Response {
|
# Autopilot functions
|
||||||
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
|
|
||||||
function Enable-AutopilotMode {
|
function Enable-AutopilotMode {
|
||||||
param([object]$Config)
|
param([object]$Config)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Config.Autopilot.Enabled = $true
|
$script:AutopilotEnabled = $true
|
||||||
Write-Host "🤖 Autopilot mode enabled" -ForegroundColor Green
|
Write-Host "🤖 Autopilot mode enabled" -ForegroundColor Green
|
||||||
|
Write-Host " Autonomy Level: $($Config.Autopilot.AutonomyLevel)" -ForegroundColor Cyan
|
||||||
# Start monitoring for autonomous actions
|
Write-Host " Risk Tolerance: $($Config.Autopilot.RiskTolerance)" -ForegroundColor Cyan
|
||||||
Start-Job -ScriptBlock {
|
Write-Host " Max Concurrent Tasks: $($Config.Autopilot.MaxConcurrentTasks)" -ForegroundColor Cyan
|
||||||
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
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "Failed to enable autopilot mode: $_"
|
Write-Error "Failed to enable autopilot mode: $_"
|
||||||
return $false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,17 +252,15 @@ function Disable-AutopilotMode {
|
|||||||
param([object]$Config)
|
param([object]$Config)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Config.Autopilot.Enabled = $false
|
$script:AutopilotEnabled = $false
|
||||||
Write-Host "🤖 Autopilot mode disabled" -ForegroundColor Yellow
|
Write-Host "🤖 Autopilot mode disabled" -ForegroundColor Yellow
|
||||||
return $true
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "Failed to disable autopilot mode: $_"
|
Write-Error "Failed to disable autopilot mode: $_"
|
||||||
return $false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main command processing
|
# Command processing function
|
||||||
function Process-Command {
|
function Process-Command {
|
||||||
param(
|
param(
|
||||||
[string]$Command,
|
[string]$Command,
|
||||||
@ -352,57 +269,67 @@ function Process-Command {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Host "🔄 Processing command: $Command" -ForegroundColor Cyan
|
Write-Host "`n🔍 Processing command: $Command" -ForegroundColor Yellow
|
||||||
|
|
||||||
# Add command to memory
|
# 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
|
# Analyze command intent
|
||||||
$analysis = Invoke-AIAnalysis -Command $Command -Config $Config
|
$commandLower = $Command.ToLower()
|
||||||
|
|
||||||
# Generate response
|
# Simple intent detection
|
||||||
$response = @"
|
if ($commandLower -match "get-childitem|ls|dir|show|list") {
|
||||||
🤖 PowerShell AI Agent Response
|
Write-Host "📁 Navigation command detected" -ForegroundColor Green
|
||||||
===============================
|
$result = Invoke-Expression $Command
|
||||||
|
Write-Host "Navigation completed successfully" -ForegroundColor Green
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
elseif ($commandLower -match "start|run|execute|invoke") {
|
||||||
# Execute suggested actions if autopilot is enabled
|
Write-Host "⚡ Execution command detected" -ForegroundColor Green
|
||||||
if ($Config.Autopilot.Enabled) {
|
$result = Invoke-Expression $Command
|
||||||
Write-Host "🤖 Autopilot: Executing suggested actions..." -ForegroundColor Green
|
Write-Host "Command executed successfully" -ForegroundColor Green
|
||||||
foreach ($action in $analysis.suggestedActions) {
|
|
||||||
try {
|
|
||||||
Write-Host "Executing: $action" -ForegroundColor Yellow
|
|
||||||
Invoke-Expression $action | Out-Null
|
|
||||||
}
|
}
|
||||||
catch {
|
elseif ($commandLower -match "analyze|check|review|test") {
|
||||||
Write-Warning "Failed to execute $action : $_"
|
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 {
|
catch {
|
||||||
Write-Error "Failed to process command: $_"
|
Write-Error "Failed to process command: $_"
|
||||||
return $null
|
Add-MemoryEntry -Type "error" -Content "Error: $_" -Context $Command -MemoryPath $MemoryPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,31 +345,29 @@ function Main {
|
|||||||
|
|
||||||
# Show help if requested
|
# Show help if requested
|
||||||
if ($Help) {
|
if ($Help) {
|
||||||
Write-Host @"
|
Write-Host "PowerShell AI Agent - Help" -ForegroundColor Cyan
|
||||||
PowerShell AI Agent - Help
|
Write-Host "==========================" -ForegroundColor Cyan
|
||||||
==========================
|
Write-Host ""
|
||||||
|
Write-Host "Usage: .\main.ps1 [options]" -ForegroundColor White
|
||||||
Usage: .\main.ps1 [options]
|
Write-Host ""
|
||||||
|
Write-Host "Options:" -ForegroundColor White
|
||||||
Options:
|
Write-Host " -Command string Command to process" -ForegroundColor White
|
||||||
-Command <string> Command to process
|
Write-Host " -Voice Enable voice recognition" -ForegroundColor White
|
||||||
-Voice Enable voice recognition
|
Write-Host " -Autopilot Enable autopilot mode" -ForegroundColor White
|
||||||
-Autopilot Enable autopilot mode
|
Write-Host " -Help Show this help message" -ForegroundColor White
|
||||||
-Help Show this help message
|
Write-Host " -ConfigPath string Path to configuration file" -ForegroundColor White
|
||||||
-ConfigPath <string> Path to configuration file
|
Write-Host ""
|
||||||
|
Write-Host "Examples:" -ForegroundColor White
|
||||||
Examples:
|
Write-Host " .\main.ps1 -Command 'Get-ChildItem'" -ForegroundColor White
|
||||||
.\main.ps1 -Command "Get-ChildItem"
|
Write-Host " .\main.ps1 -Voice -Command 'Show me the processes'" -ForegroundColor White
|
||||||
.\main.ps1 -Voice -Command "Show me the processes"
|
Write-Host " .\main.ps1 -Autopilot -Command 'Monitor system performance'" -ForegroundColor White
|
||||||
.\main.ps1 -Autopilot -Command "Monitor system performance"
|
Write-Host ""
|
||||||
|
Write-Host "Features:" -ForegroundColor White
|
||||||
Features:
|
Write-Host " - Voice recognition and synthesis" -ForegroundColor White
|
||||||
- Voice recognition and synthesis
|
Write-Host " - Autopilot mode for autonomous execution" -ForegroundColor White
|
||||||
- Autopilot mode for autonomous execution
|
Write-Host " - Memory system for persistent learning" -ForegroundColor White
|
||||||
- Memory system for persistent learning
|
Write-Host " - AI-powered command analysis" -ForegroundColor White
|
||||||
- AI-powered command analysis
|
Write-Host " - Cross-platform PowerShell 7 support" -ForegroundColor White
|
||||||
- Cross-platform PowerShell 7 support
|
|
||||||
"@ -ForegroundColor Cyan
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,7 +462,7 @@ Features:
|
|||||||
Write-Host "System Status:" -ForegroundColor Green
|
Write-Host "System Status:" -ForegroundColor Green
|
||||||
Write-Host " PowerShell Version: $($PSVersionTable.PSVersion)" -ForegroundColor White
|
Write-Host " PowerShell Version: $($PSVersionTable.PSVersion)" -ForegroundColor White
|
||||||
Write-Host " Voice Recognition: $($config.Voice.Enabled)" -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
|
Write-Host " Memory Entries: $(($entries = Get-MemoryEntries -MemoryPath $memoryPath).Count)" -ForegroundColor White
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -558,6 +483,5 @@ Features:
|
|||||||
Write-Host "PowerShell AI Agent shutting down..." -ForegroundColor Green
|
Write-Host "PowerShell AI Agent shutting down..." -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Execute main function with parameters
|
# Execute main function with parameters
|
||||||
Main -Command $Command -Voice $Voice -Autopilot $Autopilot -Help $Help -ConfigPath $ConfigPath
|
Main -Command $Command -Voice $Voice -Autopilot $Autopilot -Help $Help -ConfigPath $ConfigPath
|
||||||
|
@ -11,6 +11,7 @@ if (Test-Path $configPath) {
|
|||||||
Write-Host "✅ Configuration file exists" -ForegroundColor Green
|
Write-Host "✅ Configuration file exists" -ForegroundColor Green
|
||||||
$config = Get-Content $configPath | ConvertFrom-Json
|
$config = Get-Content $configPath | ConvertFrom-Json
|
||||||
Write-Host "✅ Configuration loaded successfully" -ForegroundColor Green
|
Write-Host "✅ Configuration loaded successfully" -ForegroundColor Green
|
||||||
|
Write-Host " Configuration properties: $($config.PSObject.Properties.Name -join ', ')" -ForegroundColor Cyan
|
||||||
} else {
|
} else {
|
||||||
Write-Host "❌ Configuration file not found" -ForegroundColor Red
|
Write-Host "❌ Configuration file not found" -ForegroundColor Red
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user