Metadata-Version: 2.4
Name: codemate-cli
Version: 1.0.0
Summary: AI-powered CLI assistant with rich streaming interface
Home-page: https://codemate.ai/
Author: Codemate.ai
Author-email: "Codemate.ai" <developers.codemate@gmail.com>
Project-URL: Homepage, https://codemate.ai/
Project-URL: Documentation, https://docs.codemate.ai/
Keywords: cli,ai,assistant,llm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich>=13.7.0
Requires-Dist: click>=8.1.0
Requires-Dist: httpx>=0.25.0
Requires-Dist: pydantic>=2.5.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: prompt-toolkit>=3.0.43
Requires-Dist: pygments>=2.17.0
Requires-Dist: python-socketio>=5.8.0
Requires-Dist: aiohttp>=3.8.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# 🚀 CodeMate CLI

AI-powered command-line assistant with beautiful streaming responses and rich markdown formatting.

![Version](https://img.shields.io/badge/version-1.0.0-blue)
![Python](https://img.shields.io/badge/python-3.8+-green)
![License](https://img.shields.io/badge/license-MIT-blue)

## ✨ Features

- 🎨 **Rich Terminal UI** - Beautiful, colorful interface with syntax highlighting
- 📝 **Markdown Rendering** - Real-time markdown formatting in your terminal
- 🌊 **Streaming Responses** - See responses as they're generated
- 💬 **Interactive Mode** - Maintain conversation context across multiple messages
- 🔧 **Cross-Platform** - Works on macOS, Linux, and Windows
- ⚡ **Fast & Efficient** - Minimal latency with async streaming
- 🔐 **Secure** - API keys stored safely in your local config

## 📦 Installation

### Using pip (Recommended)

```bash
pip install codemate-cli
```

### From Source

```bash
git clone https://github.com/yourusername/codemate-cli.git
cd codemate-cli
pip install -e .
```

### For Development

```bash
pip install -e ".[dev]"
```

## 🚀 Quick Start

### 1. Configure Your API Key

```bash
codemate config set-key YOUR_API_KEY
```

### 2. Set Your Endpoint (if different from default)

```bash
codemate config set-endpoint http://localhost:45223
```

### 3. Start Chatting!

```bash
# One-off question
codemate chat "Explain async/await in Python"

# Interactive mode
codemate interactive

# With specific model
codemate chat --model openai/gpt-4 "Write a binary search algorithm"
```

## 📖 Usage Guide

### Basic Commands

#### Chat Command

Send a single message to the AI:

```bash
# Basic usage
codemate chat "Your question here"

# Specify model
codemate chat --model openai/gpt-4 "Your question"

# Disable streaming
codemate chat --no-stream "Your question"
```

#### Interactive Mode

Start a persistent conversation:

```bash
codemate interactive

# In interactive mode:
# - Type your message and press Enter
# - Use /clear to clear conversation history
# - Use /help for commands
# - Use /exit or Ctrl+C to quit
```

#### Configuration Management

```bash
# View all settings
codemate config show

# Set API key
codemate config set-key YOUR_API_KEY

# View masked API key
codemate config get-key

# Set custom endpoint
codemate config set-endpoint http://your-server:port
```

#### List Available Models

```bash
codemate models
```

#### Clear History

```bash
codemate clear
```

### Advanced Usage

#### Environment Variables

You can also configure via environment variables:

```bash
export CODEMATE_API_KEY="your-api-key"
export CODEMATE_ENDPOINT="http://localhost:45223"
```

#### Configuration File

Config is stored in:
- **macOS/Linux**: `~/.config/codemate/config.json`
- **Windows**: `%APPDATA%\CodeMate\config.json`

Example config:
```json
{
  "api_key": "your-key",
  "endpoint": "http://localhost:45223",
  "default_model": "chat_c0_cli",
  "stream": true,
  "theme": "monokai",
  "save_history": true
}
```

## 🎨 Rich UI Features

### Markdown Rendering

The CLI automatically renders:
- **Headers** with proper hierarchy
- **Code blocks** with syntax highlighting
- **Lists** (ordered and unordered)
- **Tables** formatted beautifully
- **Bold**, *italic*, and `inline code`
- **Links**

### Code Highlighting

Supports 100+ languages including:
- Python, JavaScript, TypeScript
- Go, Rust, C++, Java
- HTML, CSS, SQL
- And many more!

### Streaming Display

Watch responses appear in real-time with:
- Live markdown rendering
- Smooth scrolling
- Progress indicators
- Error handling

## 🔧 Architecture

### Component Overview

```
┌─────────────────────────────────┐
│      CLI Interface (cli.py)      │
│  - Command parsing & routing     │
│  - User interaction              │
└────────────┬────────────────────┘
             │
┌────────────▼────────────────────┐
│   HTTP Client (client.py)        │
│  - API communication             │
│  - Request/response handling     │
└────────────┬────────────────────┘
             │
┌────────────▼────────────────────┐
│  Streaming Handler (streaming.py)│
│  - Real-time rendering           │
│  - Markdown processing           │
└──────────────────────────────────┘
```

### Key Components

1. **CLI Layer** (`cli.py`)
   - Built with Click for robust command parsing
   - Rich console integration
   - Interactive prompts

2. **HTTP Client** (`client.py`)
    - Async/sync dual support
    - Streaming and non-streaming modes
    - Error handling

3. **UI Layer** (`ui/`)
   - `streaming.py`: Live response rendering
   - `markdown.py`: Enhanced markdown formatting
   - `renderer.py`: Rich component rendering

4. **Configuration** (`config.py`)
   - Cross-platform config storage
   - Environment variable support
   - Persistent settings

## 🛠️ API Integration

### Your Backend Requirements

Your FastAPI server should expose:

```python
@app.post("/v1/chat/completions")
async def handle_chat(request: Request):
    # Handle both streaming and non-streaming
    # Return SSE format for streaming:
    # data: {"choices": [{"delta": {"content": "text"}}]}
    # data: [DONE]
```

### Request Format

```json
{
  "model": "chat_c0_cli",
  "messages": [
    {"role": "user", "content": "Hello"}
  ],
  "stream": true,
  "call_for": "chat_c0_cli"
}
```

### Response Format (Streaming)

```
data: {"choices": [{"delta": {"content": "Hello"}}]}
data: {"choices": [{"delta": {"content": " there!"}}]}
data: [DONE]
```

## 🧪 Testing

```bash
# Run tests
pytest

# With coverage
pytest --cov=codemate

# Run specific test
pytest tests/test_client.py
```

## 📝 Development

### Project Structure

```
codemate-cli/
├── codemate/
│   ├── __init__.py
│   ├── cli.py           # Main CLI entry
│   ├── client.py        # API client
│   ├── config.py        # Configuration
│   ├── ui/              # UI components
│   │   ├── streaming.py
│   │   ├── markdown.py
│   │   └── renderer.py
│   ├── commands/        # Command handlers
│   └── utils/           # Utilities
├── tests/               # Test suite
├── pyproject.toml       # Project config
└── README.md
```

### Adding New Commands

1. Create command handler in `codemate/commands/`
2. Register in `cli.py`:

```python
@main.command()
@click.option('--option', help='Description')
def your_command(option):
    """Command description"""
    # Implementation
```

### Customizing UI

Modify `ui/streaming.py` for rendering behavior:

```python
class StreamingHandler:
    def _render_content(self, text: str):
        # Custom rendering logic
        pass
```

## 🤝 Contributing

Contributions welcome! Please:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

## 📄 License

MIT License - see LICENSE file

## 🆘 Troubleshooting

### Connection Issues

```bash
# Check endpoint
codemate config show

# Test with curl
curl http://localhost:45223/v1/chat/completions
```

### API Key Issues

```bash
# Verify key is set
codemate config get-key

# Reset configuration
rm ~/.config/codemate/config.json  # Linux/macOS
```

### Installation Issues

```bash
# Use virtual environment
python -m venv venv
source venv/bin/activate  # Linux/macOS
venv\Scripts\activate     # Windows
pip install codemate-cli
```

## 🔗 Links

- [Documentation](https://docs.codemate-cli.dev)
- [GitHub](https://github.com/yourusername/codemate-cli)
- [Issues](https://github.com/yourusername/codemate-cli/issues)

## 💡 Examples

### Code Generation

```bash
codemate chat "Write a Python function to calculate fibonacci numbers"
```

### Code Explanation

```bash
codemate chat "Explain this code: $(cat script.py)"
```

### Debugging Help

```bash
codemate chat "I'm getting this error: ImportError: No module named 'requests'"
```

### Interactive Coding Session

```bash
codemate interactive

# Then ask follow-up questions:
# "Now add error handling"
# "How do I test this?"
# "Refactor this to be more efficient"
```

---

Made with ❤️ by the CodeMate team
