Skip to main content

A command-line AI chat application that helps perform tasks by writing and executing terminal commands with user supervision and by answering questions.

Project description

AI Shell Agent

AI Shell Agent is a command-line LLM-powered tool that can help you perform tasks by writing and executing terminal commands (with human confirmation or edit) and responding to questions, directly from the console.
It features a very simple CLI and adjusts the LLM prompts based on your detected system.
Works on Windows, Linux with Bash, and Mac. (Tested on Windows, please contribute!)

Installation

pip install ai-shell-agent

This will automatically install the CLI tool in your current Python environment.
Requires python=3.11.x.
You can also clone and install from the repository.

Quickly send messages

ai "your message here"

This will send a message to the AI in the active chat (and create a new chat if there isn't one active).

You will see the AI response or editable commands that the AI wants to run, which you can confirm by pressing Enter.

Output of the command is displayed in the console and added to the chat messages.
Once all the commands are run, the AI will provide its interpretation of the results or try to run more commands.

If you haven't set your API key yet, you will be prompted.

Execute command yourself and ask about the outputs

ai -x "dir"

This will execute the command and add the output to the AI logs, as it can't see the whole console.

ai "tell me about these files"

Will present both the command output and the question to the AI.

You can run multiple commands in a row and then ask your question too.
Or even run a few commands yourself and then ask the AI to finish up.

Titled chats

ai -c "title of new or existing chat"
ai "your message here"

Will create a new chat and set it active if it doesn't exist, then send a message to the active chat.

Temporary chats

ai -tc "your first message in a temporary chat"

Will create a new temporary chat without a title and set it active.

Edit last message

ai -e "updated last message"

Will update the last message and send the updated chat to the llm to reply. You can also specify the user message id you want to update. It's displayed after each message you send, and when you list messages with ai -lsm.


Table of Contents


Warning

Please use at your own risk. AI can still generate wrong and possibly destructive commands. You always can view the command before sending—please be mindful. If you see any dangerous commands, please post a screenshot.


Features

  • Chat Session Management:
    Create new chats or load existing ones using a title, have one active chat session set to receive messages by default.

  • API Key Management:
    Set and update your OpenAI API key via a dedicated command. You will be prompted to input the key if you have not provided it yet.

  • Message Handling:
    Send new messages or edit previous ones within an active session with the simple ai "your message" command.

  • Temporary Sessions:
    Start temporary sessions for quick, ephemeral chats (currently saved as temp chats under UUID names for easier debugging and tracing).

  • Shell Command Execution:
    The LLM can write your commands, and you can edit them or execute them with one press of a button.

  • Python Code Execution:
    The agent also has the ability to run Python REPL, though this feature hasn't undergone extensive development or testing.


Quickstart Guide

Setting Up the API Key

Upon launching AI Shell Agent for the first time, if no API key is detected, the application will prompt you to enter it:

$ ai
No OpenAI API key found. Please enter your OpenAI API key:

After entering the key, it will be saved in a .env file located in the project's installation directory. This ensures that your API key is securely stored and automatically loaded in future sessions.

Managing the API Key

If you need to update or set a new API key at any time, use the following command:

ai -k

Shorthand:

ai --set-api-key

Starting a Chat Session

Create a new chat session with a title:

ai -c "My Chat Session"

Shorthand:

ai --chat "My Chat Session"

Sending a Message

To send a message to the active chat session:

ai "what is the time right now?"

Executing Shell Commands

Run a shell command directly:

ai -x "dir"

Shorthand:

ai --execute "dir"

By automatically detecting your operating system (via Python’s platform library), AI Shell Agent customizes its console suggestions for Windows CMD, Linux bash, or macOS Terminal.

Temporary Chat Sessions

Start a temporary session (untitled, currently saved to file but untitled):

ai -tc "Initial temporary message"

Shorthand:

ai --temp-chat "Initial temporary message"

Listing and Managing Sessions

  • List Sessions:

    ai -lsc
    

    Shorthand:

    ai --list-chats
    
  • Load an Existing Session:

    ai -lc "My Chat Session"
    

    Shorthand:

    ai --load-chat "My Chat Session"
    
  • Rename a Session:

    ai -rnc "Old Title" "New Title"
    

    Shorthand:

    ai --rename-chat "Old Title" "New Title"
    
  • Delete a Session:

    ai -delc "Chat Title"
    

    Shorthand:

    ai --delete-chat "Chat Title"
    
  • List messages:

    ai -lsm
    

    Shorthand:

    ai --list-messages
    
  • Show the current chat title:

    ai -ct
    

    Shorthand:

    ai --current-chat-title
    

Installation

Installing from PyPI

pip install ai-shell-agent

Installing from Source

  1. Clone the repository:
    git clone https://github.com/laelhalawani/ai-shell-agent.git
    
  2. Navigate to the project directory:
    cd ai-shell-agent
    
  3. Install the package:
    pip install .
    

Usage

API Key Management

  • Set or Update API Key:
    ai -k
    
    Shorthand:
    ai --set-api-key
    

Chat Session Management

  • Create or Load a Chat Session:
    ai -c "Session Title"
    
    Shorthand:
    ai --chat "Session Title"
    

Messaging

  • Send a Message:

    ai -m "Your message"
    

    Shorthand:

    ai --send-message "Your message"
    
  • Edit a Message at a Given Index:

    ai -e 1 "Updated message"
    

    Shorthand:

    ai --edit 1 "Updated message"
    

System Prompt Management

  • Set Default System Prompt:
    ai --default-system-prompt "Your default system prompt"
    

Shell Command Execution

  • Direct Execution (without confirmation):
    ai -x "your shell command"
    
    Shorthand:
    ai --execute "your shell command"
    

Development & Contributing

Follow the same steps as described earlier.


License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_shell_agent-0.1.5.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_shell_agent-0.1.5-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file ai_shell_agent-0.1.5.tar.gz.

File metadata

  • Download URL: ai_shell_agent-0.1.5.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for ai_shell_agent-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0d26c66cc4b6a8bd08a88a5e7a7b970acf58fa6e9ec1ba75de91b5d866822ac9
MD5 89b207bf1d41218c664ab5d0431d0d72
BLAKE2b-256 47d2634b01ea3994fe13ef26ae38910c5a9df1a985c8e18450d3cea0bb3e4c34

See more details on using hashes here.

File details

Details for the file ai_shell_agent-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: ai_shell_agent-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for ai_shell_agent-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ae83423824475a97b0e29b3475b78beacbe3be61bb4212c0a3620c632b97b280
MD5 1645fe46720e0ac6b4df8a255864df6b
BLAKE2b-256 1859b1ebce26750ffc55aba41d883c4b215e3b603f24530319f44909d9633458

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page