Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Legion Code Generator

A powerful terminal-based AI agent specialized in coding and full-stack project development. This tool helps developers create, modify, and maintain projects through natural language instructions in the terminal.

Features

  • Project Initialization: Generate complete project structures for various frameworks and languages
  • Code Generation: Create files with well-structured code based on natural language descriptions
  • Context-Aware Updates: Modify existing projects by understanding the current codebase
  • Command Execution: Run system commands like npm install or pip install directly
  • Interactive Mode: Engage in a conversation-like experience for iterative development
  • Multiple LLM Support: Use either OpenAI or Google's Gemini API

Installation

Prerequisites

  • Python 3.8+
  • OpenAI API key or Google Gemini API key

Install from PyPI

pip install legion-code-generator

Install from source

  1. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  2. Install the package in development mode:

    pip install -e .
    

Usage

Using your API Key

You have several options for providing your API key:

  1. Command-line argument:

    # For OpenAI API
    legion-code-generator --api-key "your-api-key-here" --api-type openai
    
    # For Gemini API
    legion-code-generator --api-key "your-api-key-here" --api-type gemini
    
  2. Environment variable:

    # For OpenAI (Linux/macOS)
    export OPENAI_API_KEY="your-api-key-here"
    legion-code-generator
    
    # For Gemini (Linux/macOS)
    export OPENAI_API_KEY="your-gemini-api-key-here"
    export BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
    legion-code-generator
    
  3. .env file: Create a .env file in your working directory with:

    # For OpenAI
    OPENAI_API_KEY=your-api-key-here
    
    # For Gemini
    OPENAI_API_KEY=your-gemini-api-key-here
    BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
    

Interactive API Selection

If you don't provide an API key or type via command line or environment, Legion Code Generator will prompt you to select between OpenAI and Gemini APIs, and then ask for your API key.

Command-line Options

# Initialize a new project
legion-code-generator --init project_name project_type

# Work with an existing project
legion-code-generator --project /path/to/your/project

# Make a specific feature request
legion-code-generator --project /path/to/your/project --request "Add a navigation bar with responsive design"

# Run a shell command in the project context
legion-code-generator --project /path/to/your/project --command "npm install bootstrap"

# Get an explanation of the current project
legion-code-generator --project /path/to/your/project --explain

# Specify the API type
legion-code-generator --api-type gemini --api-key "your-gemini-api-key"

# Start interactive mode (default)
legion-code-generator --project /path/to/your/project

Interactive Mode Commands

Once in interactive mode, you can use the following commands:

  • Initialize a Project:

    init my_project react
    

    Creates a new React project with appropriate structure and files.

  • Run a Command:

    run npm install react-router-dom
    

    Executes the command in the project directory.

  • Explain Project:

    explain
    

    Provides an explanation of the current project structure and components.

  • API Information:

    api
    

    Displays information about the currently configured API and model.

  • Update Project: Simply type your request in natural language:

    Add a login page with React Router integration
    

    or

    Create a database schema for user profiles with SQLite
    
  • Exit Interactive Mode:

    exit
    

    or press Ctrl+C

Examples

Creating a new React project

> legion-code-generator --init myapp react
🤖 Initializing new react project: myapp
✅ Created directory: src
✅ Created file: src/index.js
✅ Created file: src/App.js
✅ Created file: src/App.css
✅ Created file: public/index.html
✅ Created file: package.json
✅ Created file: .gitignore
$ npm install
React project myapp initialized successfully!

Adding a feature to an existing project

> legion-code-generator --project ./myapp --request "Add a navigation bar with Home, About and Contact links"
Processing request...
✅ Updated file: src/App.js
✅ Created new file: src/components/Navbar.js
✅ Updated file: src/App.css

Running build commands

> legion-code-generator --project ./myapp --command "npm run build"
$ npm run build
Creating an optimized production build...
Build completed successfully!

Development

Project Structure

legion_code_generator/
├── __init__.py      # Package initialization
├── agent.py         # Main entry point and CLI handler
├── context.py       # Project context management
├── llm.py           # LLM integration
├── executor.py      # Command execution
├── utils.py         # Helper functions
└── prompts.py       # LLM prompting templates

Limitations

  • The agent requires an internet connection to use OpenAI's or Gemini's API.
  • Very large projects might exceed context limits of the LLM.
  • The agent cannot debug runtime errors or test the functionality of the code it generates.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Acknowledgements

  • This project uses AI APIs (OpenAI/Gemini) for code generation and understanding.
  • Special thanks to the open-source community for inspiration and tools.

Metadata

Release files for legion-code-generator 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for legion-code-generator 0.1.6
File Size Uploaded Provenance Actions
legion_code_generator-0.1.6.tar.gz 27.1 kB Without provenance Details for legion_code_generator-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for legion-code-generator 0.1.6
File Interpreter ABI Platform Actions
legion_code_generator-0.1.6-py3-none-any.whl Python 3 none any Details for legion_code_generator-0.1.6-py3-none-any.whl

Total release size: 54.4 kB

Release files / legion_code_generator-0.1.6.tar.gz

Download URL legion_code_generator-0.1.6.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ed8b3005427debbcad40d27c7f9d642e2b230aeb97a13d88665406b12439568
BLAKE2b-256 checksum
How to use checksums
b10eb958bac95ccdc5de9bfb65b6d0a4f423c524cdc2b281b69bf77bcd5889eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / legion_code_generator-0.1.6-py3-none-any.whl

Download URL legion_code_generator-0.1.6-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d56d46ea892ef99be20df7ba61fb0e2b138f84ec1f2acaa3067a5a0f361b7065
BLAKE2b-256 checksum
How to use checksums
aeebf3e53fbee25d761894dde9daf31b3833df2fb4ad1931a10e27f8dc4ec048
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Security for legion-code-generator 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page