Skip to main content

AI-powered CLI coding assistant with API

Project description

๐Ÿ”ฅ Flame - AI-Powered CLI Coding Assistant

An intelligent command-line interface (CLI) application that functions as an AI coding assistant directly in your terminal, powered by API.

โœจ Features

  • Interactive REPL: Continuous chat loop with full conversation context
  • System Awareness: Automatically gathers context about your environment (OS, project structure, git status)
  • Real-time Streaming: Responses stream into the terminal as they're generated
  • Safe File Operations: Create and edit files with intelligent diff preview and approval prompts
  • Command Execution: Suggest and safely execute terminal commands with user approval
  • Dangerous Command Detection: Blocks potentially harmful commands while allowing safe ones
  • Multi-turn Conversations: Maintains full chat history across sessions

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10+
  • A API key
  • pip or poetry for dependency management

Installation

  1. Install via pip (recommended to use a virtual environment):

    pip install flamecli
    
  2. Setup configuration:

    # Interactively securely configure your API key and preferences
    flame --setup
    

Test Connection

Before running the REPL, verify your setup:

flame --check

Expected output:

๐Ÿ” Testing connection to API...
โœ… Connection successful!

Start the CLI

flame

You'll see:

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ ๐Ÿ”ฅ Flame - AI Coding Assistant      โ”ƒ
โ”ƒ Powered by API              โ”ƒ
โ”—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”›

Type 'help' for commands, 'exit' to quit

You: _

๐Ÿ’ฌ Usage Examples

Basic Chat

You: What does this code do?
[paste code]

๐Ÿค– Flame: This code does...

Get Project Context

You: help

Available Commands:

  help          - Show this help message
  context       - Show current system context
  clear         - Clear conversation history
  exit          - Exit the program
  /run <cmd>    - Suggest running a command (AI-aware)
  /edit <file>  - Suggest editing a file
  /create <file> - Suggest creating a file

View System Context

You: context

๐Ÿ“ System Context:

๐Ÿ“ Working Directory: /path/to/project
๐Ÿ–ฅ๏ธ  System: Linux 6.1.0 | Python 3.11.0
๐ŸŒฟ Git Status: On branch main
๐Ÿ“‚ Project Structure:
  project-name/
  โ”œโ”€โ”€ main.py
  โ”œโ”€โ”€ utils/
  โ””โ”€โ”€ ...
๐Ÿ“Š File Summary:
  Total files: 24
  .py: 12
  .md: 3
  ...

AI-Suggested File Creation

You: Create a requirements.txt with common Python packages

๐Ÿค– Flame: I'll create a requirements.txt with popular packages...

๐Ÿ“ Create File: requirements.txt
   Suggested by AI assistant

Preview:
requests>=2.28.0
python-dotenv>=0.20.0
rich>=13.0.0
...

โœ… Create this file? [y/n]: y
โœ… File created: requirements.txt

AI-Suggested Command Execution

You: How do I install the dependencies?

๐Ÿค– Flame: You can run pip install...

๐Ÿ”ง Run Command:
   Suggested by AI assistant

Command:
   pip install -r requirements.txt

โœ… Execute this command? [y/n]: y
โœ… Command executed successfully

Output:
Collecting requests...
...

Clear History

You: clear
โœ… Conversation history cleared

๐Ÿ—๏ธ Architecture

Directory Structure

flame/
โ”œโ”€โ”€ api/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ client.py          # API wrapper
โ”œโ”€โ”€ cli/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ repl.py            # Interactive REPL loop
โ”‚   โ””โ”€โ”€ executor.py        # File and command execution
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ context.py         # System context collector
โ”œโ”€โ”€ main.py                # Entry point
โ”œโ”€โ”€ pyproject.toml         # Project configuration
โ”œโ”€โ”€ .env.example           # Environment template
โ””โ”€โ”€ .env                   # Your configuration (gitignored)

Component Interaction

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         main.py (Entry Point)           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    REPL (cli/repl.py)                  โ”‚
โ”‚  โ”œโ”€ Interactive loop                   โ”‚
โ”‚  โ”œโ”€ Message history                    โ”‚
โ”‚  โ””โ”€ Command handling                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ             โ–ผ            โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚HackClubAI API    โ”‚   โ”‚FileExecutor โ”‚ โ”‚CommandExecutor
   โ”‚(api/client.py)   โ”‚   โ”‚(executor.py)โ”‚ โ”‚(executor.py)
   โ”‚                  โ”‚   โ”‚             โ”‚ โ”‚
   โ”‚โ€ข Streaming       โ”‚   โ”‚โ€ข Safe file  โ”‚ โ”‚โ€ข Command checks
   โ”‚โ€ข Non-streaming   โ”‚   โ”‚  ops        โ”‚ โ”‚โ€ข Approval prompts
   โ”‚โ€ข Error handling  โ”‚   โ”‚โ€ข Diffs      โ”‚ โ”‚โ€ข History
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
      SystemContext
      (utils/context.py)
      โ”œโ”€ OS info
      โ”œโ”€ Git status
      โ”œโ”€ Project structure
      โ””โ”€ File summary

๐Ÿ”’ Security Features

File Operations Security

  1. Path Validation: All file paths are validated to stay within the project directory
  2. Diff Preview: Before writing, users see exactly what changes will be made
  3. User Approval: Every file creation/edit requires explicit user confirmation
  4. Safe by Default: Operations are blocked if path escapes project root

Command Execution Security

  1. Dangerous Pattern Detection: Blocks commands matching risky patterns:

    • rm -rf / (recursive root deletion)
    • sudo (privilege escalation)
    • dd (disk operations)
    • mkfs (filesystem formatting)
    • Fork bombs
  2. User Approval: Every command execution requires explicit confirmation

  3. Timeout Protection: Commands are forcibly terminated after 30 seconds

  4. Error Reporting: Command failures are clearly reported

API Key Security

  • Store in .env file (add to .gitignore automatically)
  • Never commit .env to version control
  • Use environment variables in production
  • Supports .env.example for template sharing

๐Ÿ“‹ Configuration

Environment Variables

Create a .env file from .env.example:

# Required: Your API key
FLAME_API_KEY=hf_xxxxxxxxxxxxx

# Optional: API endpoint (usually pre-configured)
FLAME_API_BASE_URL=https://api.example.com/proxy/v1

# Optional: AI model to use
FLAME_MODEL=qwen/qwen3-32b

# Optional: CLI settings
CLI_THEME=dark
DEBUG=false

๐ŸŽฎ CLI Options

python main.py --help

usage: main.py [-h] [--version] [--check] [--dir DIR] [--model MODEL] [--debug]

Flame - AI Coding Assistant powered by API

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --check               Test connection to API
  --setup               Interactive setup to configure your API key and settings
  --dir DIR             Working directory (defaults to current directory)
  --model MODEL         AI model to use (overrides FLAME_MODEL env var)
  --debug               Enable debug mode

๐Ÿ› Troubleshooting

Connection Failed

Error: Connection failed. Check your API key and network.

Solutions:

  1. Verify API key is correct in .env
  2. Check internet connection
  3. Verify API base URL is correct
  4. Test with: python main.py --check --debug

Import Errors

Error: ModuleNotFoundError: No module named 'api'

Solutions:

  1. Ensure you're in the project root directory
  2. Virtual environment is activated
  3. Dependencies are installed: pip install -e .

Command Won't Execute

Error: Dangerous Command Detected

Solutions:

  1. Command matches safety patterns (by design)
  2. Use --debug to see pattern matching
  3. Use safer alternative commands
  4. File path must be within project directory

๐Ÿ“š Advanced Usage

Using with Different Models

# Override model at runtime
python main.py --model llama2

# Or set in .env:
FLAME_MODEL=llama2

Using Different Working Directory

# Analyze a different project
python main.py --dir /path/to/other/project

Debug Mode

# See detailed error messages
python main.py --debug

๐Ÿ”ง Development

Running Tests

pytest tests/

Code Style

# Format code
black api/ cli/ utils/ main.py

# Lint
flake8 api/ cli/ utils/ main.py

๐Ÿ“ License

MIT License - feel free to use and modify!

๐Ÿค Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

๐Ÿ™‹ Support

Need help? Try:

  1. Check .env configuration
  2. Run python main.py --check to verify setup
  3. Use --debug flag for detailed error messages
  4. Review this README for common issues

Made with ๐Ÿ”ฅ by API Community

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

flamecli-0.1.6.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

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

flamecli-0.1.6-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file flamecli-0.1.6.tar.gz.

File metadata

  • Download URL: flamecli-0.1.6.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for flamecli-0.1.6.tar.gz
Algorithm Hash digest
SHA256 18919e4d09d1419e7b381f9d35f97618911c2d9d278b4b72bc5aafddfffd6de9
MD5 3157091efe14f219e4271c67195cdcac
BLAKE2b-256 7dcd8168a3767975ad0fa03ec358153db5461aebadf2eaa35fe6e84ffd4f448d

See more details on using hashes here.

File details

Details for the file flamecli-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: flamecli-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for flamecli-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 64ef9f3957d07c77e07f96a3f78b197196dcdf679a9421ae455e356885a05b77
MD5 da41ed00f0fe7f03e2cb9f1b12b93372
BLAKE2b-256 b69ffe0f0705a8e6a4cc23a6403b8c1b612605d289cd57b44ed4fdbb03d0a452

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