Skip to content

🤖 AI-powered coding assistant with Google Gemini integration. Features interactive chat, code analysis, project detection, and intelligent code generation. Built for developers who want a ChatGPT-like experience for their projects.

License

Notifications You must be signed in to change notification settings

erenkara1907/ai-code-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 AI Code Agent

A powerful command-line interface for an AI-powered coding assistant that can analyze, generate, and manage code projects. Built with Google's Gemini AI for intelligent code understanding and generation.

✨ Features

🔍 Code Analysis

  • Python Code Analysis: Parse and analyze Python files with AST
  • Code Quality Review: Detect issues, suggest improvements
  • Dependency Analysis: Analyze project dependencies and security

📁 File Operations

  • Smart File Management: List, read, write, and organize files
  • Advanced Search: Search for patterns across multiple files
  • Directory Management: Create and manage project directories

🏗️ Project Intelligence

  • Project Type Detection: Automatically detect Python, Node.js, Java projects
  • Dependency Management: Analyze and suggest dependency improvements
  • Structure Analysis: Understand and optimize project organization

🎨 Code Generation

  • README Generation: Create comprehensive documentation
  • Template Creation: Generate Python modules, classes, and functions
  • Test File Generation: Create unit tests with pytest or unittest
  • Configuration Files: Generate .gitignore and other config files

🛠️ Developer Tools

  • Interactive Chat Mode: Continuous conversation with memory
  • Shell Integration: Safe command execution
  • Multi-format Support: Work with various file types and languages
  • Conversation History: Remembers previous interactions
  • Token Optimization: Efficient API usage with smart history management

🚀 Quick Start

Prerequisites

  • Python 3.13+
  • Google Gemini API key
  • UV package manager (recommended)

Installation

# Clone the repository
git clone https://github.com/erenkara1907/ai-code-agent.git
cd ai-code-agent

# Install dependencies
uv install

# Set up environment variables
echo "GEMINI_API_KEY=your_api_key_here" > .env

Basic Usage

Interactive Mode (Recommended)

# Start interactive chat session
uv run main.py

# This starts an interactive session where you can:
💬 You: Analyze this project
💬 You: Create a README file  
💬 You: q  # to quit

Single Command Mode

# Simple file listing
python main.py "List all Python files in this project"

# Code analysis
python main.py "Analyze the main.py file and suggest improvements"

# Generate documentation
python main.py "Create a comprehensive README for this project"

# Verbose mode for detailed output
python main.py "Analyze project structure" --verbose

# Clear conversation history
python main.py --clear

🎯 Interactive Mode Features

The interactive mode provides a ChatGPT-like experience:

  • Continuous Conversation: Ask follow-up questions naturally
  • Memory Retention: Agent remembers previous context
  • Smart Commands: Built-in commands for session management
  • Token Efficient: Automatically manages conversation history

Interactive Commands

help     # Show available commands
clear    # Clear conversation history  
q, quit  # Exit the session

📖 Detailed Usage Examples

Code Analysis Examples

# Analyze Python file structure
python main.py "Analyze src/agent.py - show classes, functions, and metrics"

# Detect code issues
python main.py "Review main.py and suggest code improvements"

# Check project dependencies
python main.py "Analyze project dependencies and security recommendations"

Project Management

# Detect project type and structure
python main.py "What type of project is this? Analyze the technology stack"

# Get improvement suggestions
python main.py "Suggest improvements for this project structure"

# Create missing project files
python main.py "Create .gitignore and basic test structure for this project"

Code Generation

# Generate README
python main.py "Create a README.md file with installation and usage instructions"

# Create Python module
python main.py "Generate a user_manager.py module with UserManager class and CRUD functions"

# Generate test files
python main.py "Create pytest tests for the agent module"

# Create configuration files
python main.py "Generate appropriate .gitignore for Python project"

File Operations

# Search in files
python main.py "Search for 'import' in all Python files"

# File information
python main.py "Get detailed information about src/agent.py"

# Create directories
python main.py "Create a docs directory and add a basic structure"

Advanced Examples

# Comprehensive project analysis
python main.py "Analyze this entire project: structure, code quality, missing files, and improvement suggestions"

# Code refactoring assistance
python main.py "Review all Python files and suggest refactoring opportunities"

# Project setup automation
python main.py "Set up this project for production: create missing files, improve structure, add documentation"

🏗️ Architecture

Project Structure

ai_code_agent/
├── src/
│   ├── agent.py              # Main AI Agent class
│   └── tools/
│       ├── file_operations.py    # File management tools
│       ├── shell_executor.py     # Safe shell execution
│       ├── code_analyzer.py      # Python code analysis
│       ├── project_detector.py   # Project type detection
│       └── code_generator.py     # Code template generation
├── main.py                   # CLI entry point
├── pyproject.toml           # Dependencies and metadata
└── README.md               # Documentation

Core Components

  • CodeAgent: Main orchestrator that manages AI interactions
  • FileOperations: Handle file system operations safely
  • ShellExecutor: Execute shell commands with security measures
  • CodeAnalyzer: Parse and analyze Python code using AST
  • ProjectDetector: Detect project types and analyze structure
  • CodeGenerator: Generate code templates and documentation

🔧 Configuration

Environment Variables

GEMINI_API_KEY=your_google_gemini_api_key

Supported Project Types

  • Python: pyproject.toml, requirements.txt, setup.py
  • Node.js: package.json, yarn.lock, package-lock.json
  • Java: pom.xml, build.gradle
  • Generic: Any project structure

🧪 Development

Running Tests

# Run all tests
python -m pytest tests/

# Run with coverage
python -m pytest tests/ --cov=src/

# Run specific test
python -m pytest tests/test_agent.py

Code Quality

# Format code
black src/

# Lint code
flake8 src/

# Type checking
mypy src/

Contributing Guidelines

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Write tests for new functionality
  4. Ensure code quality: Run linting and tests
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Create Pull Request

📊 Capabilities Overview

Feature Category Capabilities Status
File Operations List, Read, Write, Search, Info ✅ Complete
Code Analysis Python AST, Issues Detection, Metrics ✅ Complete
Project Detection Type Detection, Dependencies, Structure ✅ Complete
Code Generation README, .gitignore, Modules, Tests ✅ Complete
Shell Integration Safe Command Execution ✅ Complete
AI Integration Google Gemini API, Function Calling ✅ Complete

🚨 Limitations

  • Currently optimized for Python projects
  • Shell execution limited to safe commands
  • Requires internet connection for AI features
  • API rate limits apply based on Gemini usage

🔒 Security

  • Sandboxed Execution: Shell commands are restricted to safe operations
  • Path Validation: All file operations are contained within working directory
  • Input Sanitization: User inputs are validated before processing
  • No Credential Storage: API keys should be stored in environment variables

🗺️ Roadmap

  • Support for more programming languages
  • Integration with popular IDEs
  • Real-time collaboration features
  • Advanced code refactoring suggestions
  • Custom plugin system
  • Web interface option

📄 License

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

🤝 Support & Contact

🙏 Acknowledgments

  • Google Gemini AI for powerful language understanding
  • Python AST for code analysis capabilities
  • UV Package Manager for fast dependency management
  • Open Source Community for inspiration and tools

Made with ❤️ by Eren Kara for the developer community

About

🤖 AI-powered coding assistant with Google Gemini integration. Features interactive chat, code analysis, project detection, and intelligent code generation. Built for developers who want a ChatGPT-like experience for their projects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages