npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cmdgen

v0.0.6

Published

AI-powered CLI tool that generates and executes commands using OpenAI

Readme

CMDGen 🤖

An AI-powered CLI tool that generates and executes commands using OpenAI. Simply describe what you want to do, and CMDGen 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 ~/.cmdgen/config.json
  • 🎨 Beautiful CLI interface with colors and spinners
  • ⏱️ 30-second command timeout protection
  • 🔍 Command validation and verification
  • 💻 OS-aware command generation

Installation

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • OpenAI API key (get one from OpenAI Platform)

Install globally

Option 1: Using npm (recommended)

npm install -g cmdgen

Option 2: Clone and install locally

git clone <repository-url>
cd cmdgen
npm install
npm link

Development

git clone <repository-url>
cd cmdgen
npm install
npm start

Updating

To update to the latest version:

npm install -g cmdgen-cli@latest

Quick Start

  1. Initialize CMDGen with your OpenAI API key:

    cmdgen init
  2. Use CMDGen in multiple ways:

    Interactive mode:

    cmdgen

    Then describe what you want to do:

    prompt a command > ffmpeg command to crop video input.mp4 1080px x 1080px

    One-shot mode:

    cmdgen "compress all jpg files in current directory"

    Enhanced interactive mode:

    cmdgen start

    This mode includes better validation and command verification.

  3. 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

  • cmdgen init - Set up your OpenAI API key
  • cmdgen start - Start enhanced interactive mode
  • cmdgen --help - Show help information
  • cmdgen --version - Show version information

Modes

Interactive Mode: When you run cmdgen without arguments, you'll enter an interactive session where you can:

  1. Describe your command in natural language
  2. Review the generated command before execution
  3. Execute the command by pressing Enter
  4. Cancel the command by typing 'c'
  5. Regenerate a new command by typing 'r'
  6. Exit the session by typing 'exit'

Enhanced Interactive Mode (cmdgen start): This mode includes additional features:

  • Command validation: Automatic verification of generated commands
  • Better error handling: More detailed feedback on command generation
  • Improved user experience: Streamlined command generation flow

One-shot Mode: When you run cmdgen "your prompt here", it will:

  1. Generate the command based on your prompt
  2. Show the generated command
  3. Ask for confirmation before execution
  4. 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"; done

One-shot Mode:

cmdgen "compress all jpg files in current directory"
# Output: find . -name "*.jpg" -exec jpegoptim --strip-all {} \;

cmdgen "create a backup of my documents folder"
# Output: tar -czf documents_backup_$(date +%Y%m%d).tar.gz ~/Documents

cmdgen "find all files larger than 100MB"
# Output: find . -type f -size +100M -exec ls -lh {} \;

Configuration

CMDGen stores its configuration in ~/.cmdgen/config.json. This includes:

  • Your OpenAI API key (stored securely)
  • Configuration is automatically created on first run
  • OS detection for platform-specific commands

Safety Features

  • Command validation: CMDGen validates API keys and command syntax
  • Command verification: Automatic verification that generated text is actually a command
  • 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
  • OS-aware generation: Commands are generated specifically for your operating system

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

  1. "OpenAI API key not found"

    • Run cmdgen init to set up your API key
    • Ensure the API key starts with 'sk-'
  2. "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
  3. "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
  4. "Request unclear or potentially dangerous"

    • Rephrase your request to be more specific
    • Avoid requests that could harm your system
  5. "Generated text doesn't appear to be a valid command"

    • Try rephrasing your request more clearly
    • Be more specific about what you want to accomplish
    • Use technical terms instead of casual language

Getting Help

  • Run cmdgen --help for 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 ~/.cmdgen/config.json
  • OS Detection: Automatically detects your operating system for platform-specific commands
  • Command Verification: Built-in validation to ensure generated text is actually a command