Skip to content

c0dd3vi11/ai-shell

 
 

Repository files navigation

AI Shell logo

A CLI that converts natural language to shell commands.

Current version

Gif Demo

Inspired by the GitHub Copilot X CLI, but open source for everyone.


AI Shell

Setup

The minimum supported version of Node.js is v14

  1. Install ai shell:

    npm install -g @builder.io/ai-shell
  2. Choose and configure your AI engine:

Option A: OpenAI (default)

  1. Retrieve your API key from OpenAI

    Note: If you haven't already, you'll have to create an account and set up billing.

  2. Set the key so ai-shell can use it:

    ai config set OPENAI_KEY=<your openai token>

    The default model is gpt-4.1-nano (most cost-effective). You can change it using ai config set OPENAI_MODEL=<model_name>

Option B: GigaChat

  1. Get your GigaChat API credentials from AI Platform

  2. Configure GigaChat as your AI engine:

    ai config set AI_ENGINE=GigaChat ai config set GIGACHAT_KEY=<your gigachat api key>

This will create a .ai-shell file in your home directory. You can change the path to the config file by setting the AI_SHELL_CONFIG_PATH environment variable.

Usage

ai <prompt>

For example:

ai list all log files

Then you will get an output like this, where you can choose to run the suggested command, revise the command via a prompt, or cancel:

◇ Your script: │ │ find . -name "*.log" │ ◇ Explanation: │ │ 1. Search current directory and subdirectories │ 2. Find files ending with ".log" │ ◆ Run this script? │ ● ✅ Yes (Lets go!) │ ○ 📝 Edit │ ○ 🔁 Revise │ ○ 📋 Copy │ ○ ❌ Cancel └

Special characters

Note that some shells handle certain characters like the ? or * or things that look like file paths specially. If you are getting strange behaviors, you can wrap the prompt in quotes to avoid issues, like below:

ai 'what is my ip address'

Chat mode

Chat demo

ai chat

With this mode, you can engage in a conversation with the AI and receive helpful responses in a natural, conversational manner directly through the CLI:

┌ Starting new conversation │ ◇ You: │ how do I serve a redirect in express │ ◇ AI Shell: In Express, you can use the `redirect()` method to serve a redirect. The `redirect()` method takes one argument, which is the URL that you want to redirect to.  Here's an example:  \`\`\`js app.get('/oldurl', (req, res) => {  res.redirect('/newurl'); }); \`\`\`

Silent mode (skip explanations)

You can disable and skip the explanation section by using the flag -s or --silent

ai -s list all log files

or save the option as a preference using this command:

ai config set SILENT_MODE=true

Custom API endpoints

You can customize API endpoints for both engines:

For OpenAI (default: https://api.openai.com/v1):

ai config set OPENAI_API_ENDPOINT=<your proxy endpoint>

For GigaChat:

ai config set GIGACHAT_API_ENDPOINT=<your gigachat endpoint>

Proxy Configuration

The application supports advanced proxy settings for both engines:

ALL_PROXY settings (separate for each engine):

# For OpenAI ai config set OPENAI_ALLPROXY=<your_proxy_url> # For GigaChat  ai config set GIGACHAT_ALLPROXY=<your_proxy_url>

Proxy PAC URL (common setting):

ai config set PROXY_PAC_URL=<your_pac_url>

Set Language

Language UI

The AI Shell's default language is English, but you can easily switch to your preferred language by using the corresponding language keys, as shown below:

Language Key
English en
Simplified Chinese zh-Hans
Traditional Chinese zh-Hant
Spanish es
Japanese jp
Korean ko
French fr
German de
Russian ru
Ukrainian uk
Vietnamese vi
Arabic ar
Portuguese pt
Turkish tr

For instance, if you want to switch to Simplified Chinese, you can do so by setting the LANGUAGE value to zh-Hans:

ai config set LANGUAGE=zh-Hans

This will set your language to Simplified Chinese.

Config UI

To use a more visual interface to view and set config options you can type:

ai config

To get an interactive UI like below:

◆ Set config: │ ● AI Engine (OpenAI) │ ○ [OpenAI] Key │ ○ [OpenAI] Model │ ○ [OpenAI] API Endpoint │ ○ [OpenAI] ALL_PROXY │ ○ [GigaChat] Key │ ○ [GigaChat] Model │ ○ [GigaChat] API Endpoint │ ○ [GigaChat] ALL_PROXY │ ○ [Common] Proxy PAC URL │ ○ Silent Mode │ ○ Language │ ○ Cancel └

Upgrading

Check the installed version with:

ai --version

If it's not the latest version, run:

npm update -g @builder.io/ai-shell

Or just use AI shell:

ai update

Common Issues

OpenAI Issues

429 error

Some users are reporting a 429 from OpenAI. This is due to incorrect billing setup or excessive quota usage. Please follow this guide to fix it.

You can activate billing at this link. Make sure to add a payment method if not under an active grant from OpenAI.

GigaChat Issues

Authentication errors

If you encounter authentication issues with GigaChat:

  1. Verify your API key is correct
  2. Ensure your GigaChat account has proper access rights
  3. Check that your credentials haven't expired

Rate limiting

GigaChat has its own rate limiting. If you encounter 429 errors:

  1. Wait a few moments before retrying
  2. Check your usage quotas in the Developer Console

Motivation

I am not a bash wizard, and am dying for access to the copilot CLI, and got impatient.

Contributing

If you want to help fix a bug or implement a feature in Issues (tip: look out for the help wanted label), checkout the Contribution Guide to learn how to setup the project.

Credit

  • Thanks to GitHub Copilot for their amazing tools and the idea for this.
  • Thanks to Hassan and his work on aicommits, which inspired the workflow and some parts of the code and flows



Made with love by Builder.io

About

A CLI that converts natural language to shell commands.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.7%
  • JavaScript 1.3%