cmdy-cli
v1.0.0
Published
AI-powered CLI tool that generates and executes commands using OpenAI
Readme
CMDy 🤖
An AI-powered CLI tool that generates and executes commands using OpenAI. Simply describe what you want to do, and CMDy will generate the appropriate command for you.
Features
- 🤖 AI-powered command generation using OpenAI GPT-3.5-turbo
- ⚡ Interactive and one-shot modes for flexible usage
- 🔄 Command regeneration if the first attempt isn't quite right
- 🛡️ Built-in safety checks for potentially dangerous operations
- 💾 Secure API key storage in
~/.cmdy/config.json - 🎨 Beautiful CLI interface with colors and spinners
- ⏱️ 30-second command timeout protection
Installation
Prerequisites
- Node.js (v16 or higher)
- npm or yarn
- OpenAI API key (get one from OpenAI Platform)
Install globally
npm install -g cmdyOr clone and install locally:
git clone <repository-url>
cd cmdy
npm install
npm linkDevelopment
git clone <repository-url>
cd cmdy
npm install
npm startQuick Start
Initialize CMDy with your OpenAI API key:
cmdy initUse CMDy in two ways:
Interactive mode:
cmdyThen describe what you want to do:
prompt a command > ffmpeg command to crop video input.mp4 1080px x 1080pxOne-shot mode:
cmdy "compress all jpg files in current directory"Review and execute the generated command:
Executing command: find . -name "*.jpg" -exec jpegoptim --strip-all {} \; Press Enter to run, 'c' to cancel, 'r' to regenerate
Usage
Commands
cmdy init- Set up your OpenAI API keycmdy --help- Show help informationcmdy --version- Show version information
Modes
Interactive Mode:
When you run cmdy without arguments, you'll enter an interactive session where you can:
- Describe your command in natural language
- Review the generated command before execution
- Execute the command by pressing Enter
- Cancel the command by typing 'c'
- Regenerate a new command by typing 'r'
- Exit the session by typing 'exit'
One-shot Mode:
When you run cmdy "your prompt here", it will:
- Generate the command based on your prompt
- Show the generated command
- Ask for confirmation before execution
- Execute the command after you confirm
Examples
Interactive Mode:
prompt a command > compress all jpg files in current directory
> find . -name "*.jpg" -exec jpegoptim --strip-all {} \;
prompt a command > create a backup of my documents folder
> tar -czf documents_backup_$(date +%Y%m%d).tar.gz ~/Documents
prompt a command > find all files larger than 100MB
> find . -type f -size +100M -exec ls -lh {} \;
prompt a command > convert all png files to jpg
> for file in *.png; do convert "$file" "${file%.png}.jpg"; doneOne-shot Mode:
cmdy "compress all jpg files in current directory"
# Output: find . -name "*.jpg" -exec jpegoptim --strip-all {} \;
cmdy "create a backup of my documents folder"
# Output: tar -czf documents_backup_$(date +%Y%m%d).tar.gz ~/Documents
cmdy "find all files larger than 100MB"
# Output: find . -type f -size +100M -exec ls -lh {} \;Configuration
CMDy stores its configuration in ~/.cmdy/config.json. This includes:
- Your OpenAI API key (stored securely)
- Configuration is automatically created on first run
Safety Features
- Command validation: CMDy validates API keys and command syntax
- Execution confirmation: You must confirm before any command runs (Enter to run, 'c' to cancel, 'r' to regenerate)
- Timeout protection: Commands timeout after 30 seconds
- Error handling: Comprehensive error messages and graceful failure handling
- Dangerous operation detection: AI model is trained to detect potentially harmful commands
- Safe defaults: File operations use safe defaults and confirm destructive operations
Requirements
- OpenAI API Key: Get one from OpenAI Platform
- Node.js: Version 16 or higher
- Internet Connection: Required for AI command generation
- System Tools: Commands generated may require specific tools (ffmpeg, imagemagick, etc.)
Troubleshooting
Common Issues
"OpenAI API key not found"
- Run
cmdy initto set up your API key - Ensure the API key starts with 'sk-'
- Run
"Failed to generate command"
- Check your internet connection
- Verify your OpenAI API key is valid
- Ensure you have sufficient API credits
- Check if the request is clear and not potentially dangerous
"Command execution failed"
- Check if the required tools are installed on your system
- Verify file paths and permissions
- Review the error output for specific issues
- Commands timeout after 30 seconds
"Request unclear or potentially dangerous"
- Rephrase your request to be more specific
- Avoid requests that could harm your system
Getting Help
- Run
cmdy --helpfor command-line help - Check the error messages for specific guidance
- Ensure all prerequisites are installed
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the ISC License.
Disclaimer
This tool executes commands on your system. Always review generated commands before execution, especially for operations that could affect your files or system. The authors are not responsible for any damage caused by the use of this tool.
Technical Details
- Model: OpenAI GPT-3.5-turbo
- Max Tokens: 200 for command generation
- Temperature: 0.1 for consistent results
- Timeout: 30 seconds for command execution
- Configuration: Stored in
~/.cmdy/config.json
