# AeThex AI Module - README

## Overview
The AeThex AI module provides AI-powered development assistance directly in the engine,
including code completion, error detection, and documentation generation.

## Features
- **Code Completion**: AI-powered GDScript code suggestions
- **Error Fixing**: Intelligent error detection and fix suggestions
- **Documentation**: Auto-generate function and class documentation
- **Natural Language**: Convert descriptions to working code

## Usage

### GDScript Example
```gdscript
extends Node

func _ready():
    # Initialize AI assistant
    var ai = AIAssistant
    ai.initialize("your-api-key-here")
    
    # Get code completion
    var code = "func _process(delta):"
    var completion = ai.get_code_completion(code, [])
    print(completion)
    
    # Explain code
    var explanation = ai.explain_code("func _ready(): pass")
    print(explanation)
    
    # Fix an error
    var fixed = ai.fix_error("Invalid syntax", "func test()\n\tpas")
    print(fixed)
```

### Configuration
Set your Claude API key in project settings:
```
Project → Project Settings → AeThex → AI → API Key
```

Or via code:
```gdscript
AIAssistant.set_api_key("your-api-key")
```

## API Reference

### AIAssistant (Singleton)
Main AI assistant class accessible globally.

**Methods:**
- `initialize(api_key: String) -> Error` - Initialize with API key
- `is_initialized() -> bool` - Check if initialized
- `get_code_completion(context: String, recent_code: PackedStringArray) -> String`
- `explain_code(code_block: String) -> String`
- `fix_error(error_message: String, code_context: String) -> String`
- `generate_function_docs(function_signature: String) -> String`
- `natural_language_to_code(description: String, context: String) -> String`
- `clear_cache()` - Clear response cache

### AIAPIClient
Low-level API client for Claude API.

**Methods:**
- `initialize() -> Error`
- `send_completion_sync(prompt: String, timeout: float) -> String`
- `set_api_key(key: String)`
- `set_model(model: String)`

### AICodeCompletion
Code completion helper (editor integration coming soon).

**Methods:**
- `get_suggestions(code: String, cursor_position: int) -> PackedStringArray`
- `set_enabled(enabled: bool)`
- `set_suggestion_delay(delay: float)`

## Building
The module is automatically included when building AeThex Engine:
```bash
cd engine
scons platform=linuxbsd target=editor
```

To disable the module:
```bash
scons platform=linuxbsd target=editor module_aethex_ai_enabled=no
```

## Requirements
- Claude API key (get one at https://console.anthropic.com)
- Internet connection for API calls
- HTTPS support (built-in)

## Privacy
- Only sends relevant code context to API (not entire project)
- Responses are cached locally
- API key is stored securely
- Opt-in only - disabled by default

## Troubleshooting

**"Not initialized" error:**
- Make sure to call `AIAssistant.initialize()` with a valid API key

**No response:**
- Check internet connection
- Verify API key is valid
- Check API rate limits

**Slow responses:**
- Responses are cached after first request
- Typical response time is 1-5 seconds
- Consider adjusting timeout values

## Future Enhancements
- [ ] Async API calls with callbacks
- [ ] Editor UI panel
- [ ] Real-time code completion
- [ ] Multi-file context awareness
- [ ] Local AI model support
- [ ] Voice commands

## License
Copyright (c) 2026-present AeThex Labs
Based on Godot Engine (MIT License)
