Skip to content

A PowerShell module that helps is generating commands using LLM calls.

License

Notifications You must be signed in to change notification settings

kunalk16/cmdassist

Repository files navigation

CmdAssist - AI-Powered Command Line Assistant

CmdAssist is a PowerShell module that provides AI-powered command line assistance. It helps users by suggesting appropriate commands based on natural language prompts using various Large Language Models (LLMs).

Features

  • πŸ€– Multiple AI Providers: Support for OpenAI, Azure OpenAI, Claude, Llama, Google Gemini, and DeepSeek
  • ⚑ PowerShell Integration: Native PowerShell cmdlet with proper parameter support
  • πŸ›‘οΈ Safety First: Confirmation prompts before executing potentially dangerous commands
  • πŸ“‹ Clipboard Support: Copy commands to clipboard without execution
  • πŸ”§ Context Aware: Uses current working directory and system information
  • πŸ“Š Confidence Scoring: AI responses include confidence levels

Installation

Prerequisites

  • .NET 8.0 SDK or later
  • PowerShell 7.4 or later

Build from Source

  1. Clone the repository:
git clone https://github.com/kunalk16/cmdassist.git
cd cmdassist
  1. Build the project:
dotnet build
  1. Import the module:
Import-Module ./src/CmdAssist.PowerShell/bin/Debug/net8.0/CmdAssist.psd1

Configuration

CmdAssist uses environment variables for API configuration. Set the appropriate variables for your chosen AI provider:

OpenAI

$env:OPENAI_API_KEY = "your-openai-api-key"
$env:OPENAI_MODEL = "gpt-4"  # Optional, defaults to gpt-4
$env:OPENAI_ORGANIZATION = "your-org-id"  # Optional

Azure OpenAI

$env:AZURE_OPENAI_API_KEY = "your-azure-openai-key"
$env:AZURE_OPENAI_ENDPOINT = "https://your-resource.openai.azure.com/"
$env:AZURE_OPENAI_DEPLOYMENT_NAME = "your-deployment-name"
$env:AZURE_OPENAI_API_VERSION = "2024-02-01"  # Optional

Claude

$env:CLAUDE_API_KEY = "your-claude-api-key"
$env:CLAUDE_MODEL = "claude-3-sonnet-20240229"  # Optional

Llama

$env:LLAMA_API_URL = "https://your-llama-endpoint.com"
$env:LLAMA_API_KEY = "your-api-key"  # Optional, depending on your setup
$env:LLAMA_MODEL = "llama2-70b-chat"  # Optional

Google Gemini

$env:GEMINI_API_KEY = "your-gemini-api-key"
$env:GEMINI_MODEL = "gemini-pro"  # Optional, defaults to gemini-pro

DeepSeek

$env:DEEPSEEK_API_KEY = "your-deepseek-api-key"
$env:DEEPSEEK_API_URL = "https://api.deepseek.com/v1"  # Optional
$env:DEEPSEEK_MODEL = "deepseek-chat"  # Optional, defaults to deepseek-chat

API Key Resources

Usage

Basic Usage

# Get a command suggestion with confirmation prompt
cmd-assist "list all .txt files in the current directory"

# Execute directly without confirmation
cmd-assist "create a new folder called 'documents'" -Confirm

# Use a specific AI provider
cmd-assist "show disk usage" -Provider Claude

# Enable verbose output
cmd-assist "find large files" -Verbose

Examples

# File operations
cmd-assist "copy all .pdf files to a backup folder"
cmd-assist "find files modified in the last 7 days"
cmd-assist "compress the logs folder"

# System administration
cmd-assist "check system memory usage"
cmd-assist "restart the print spooler service"
cmd-assist "show network connections"

# Development tasks
cmd-assist "initialize a git repository"
cmd-assist "build a .NET project in release mode"
cmd-assist "run unit tests and show coverage"

Interactive Mode

When you run a command without the -Confirm switch, CmdAssist will:

  1. Display the suggested command
  2. Show an explanation of what it does
  3. Ask for confirmation with options:
    • Yes: Execute the command
    • No: Cancel execution
    • Copy: Copy the command to clipboard without executing

Command Line Parameters

  • Prompt (Position 0, Mandatory): The natural language description of what you want to accomplish
  • Confirm (Switch): Execute the command without confirmation prompt
  • Provider (Optional): Specify AI provider (OpenAI, AzureOpenAI, Claude, Llama, Gemini, DeepSeek)
  • Verbose (Switch): Enable verbose output for debugging

Safety Features

  • Confirmation Prompts: By default, all commands require user confirmation
  • Confidence Scoring: Low-confidence responses trigger additional warnings
  • Context Awareness: Commands are generated with awareness of your current environment
  • Error Handling: Comprehensive error handling with helpful messages

Troubleshooting

Common Issues

  1. API Key Not Set

    Error: OpenAI API key not configured. Set the OPENAI_API_KEY environment variable.
    

    Solution: Set the appropriate environment variable for your chosen provider.

  2. Network Connection Issues

    Error: API request failed: Unauthorized
    

    Solution: Verify your API key and network connection.

  3. Module Import Errors

    Import-Module: Could not load file or assembly
    

    Solution: Ensure .NET 8.0 runtime is installed and try rebuilding the project.

Enable Debug Logging

cmd-assist "your prompt" -Verbose

Development

Project Structure

cmdassist/
β”œβ”€β”€ src/
β”‚   └── CmdAssist.PowerShell/
β”‚       β”œβ”€β”€ Cmdlets/                 # PowerShell cmdlet implementations
β”‚       β”œβ”€β”€ Services/                # AI service implementations
β”‚       β”œβ”€β”€ Models/                  # Data models and DTOs
β”‚       β”œβ”€β”€ CmdAssist.psd1          # PowerShell module manifest
β”‚       └── CmdAssist.PowerShell.csproj
β”œβ”€β”€ Directory.Build.props            # Common build properties
β”œβ”€β”€ Directory.Packages.props         # Package version management
β”œβ”€β”€ global.json                      # .NET SDK version
└── cmdassist.sln                   # Solution file

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Running Tests

dotnet test

Building Release Version

dotnet build -c Release

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support


⚠️ Important: Always review generated commands before execution, especially when using the -Confirm switch. CmdAssist is a tool to assist with command generation, but you remain responsible for the commands you choose to execute.

About

A PowerShell module that helps is generating commands using LLM calls.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published