AI-powered Git CLI tool
Project description
GitSpectre
A production-ready, cross-platform CLI tool that uses AI to interpret natural language Git commands, answer questions, execute operations, and handle complex code modifications with intelligent conflict resolution.
Prerequisites
- Python 3.6 or higher
- pip (Python package installer, comes with Python)
- Git repository (for most operations)
Installation
Option 1: Local Installation (Recommended for Development)
-
Clone the repository:
git clone https://github.com/predat-r/GitSpectre.git cd GitSpectre
-
Install locally:
pip install -e .
This installs the package in development mode, allowing you to modify the code.
Option 2: Global Installation
-
Install directly from GitHub:
pip install git+https://github.com/yourusername/GitSpectre.git
Or if you have the code locally:
pip install .
This makes
spectreavailable system-wide.
Cross-Platform Notes
The installation works identically on:
- Windows: Use Command Prompt, PowerShell, or Git Bash
- macOS: Use Terminal or iTerm
- Linux: Use your preferred terminal
Setup
You can use either OpenRouter (free options available) or Anthropic (Claude) as the AI provider.
Option 1: OpenRouter (Default - Free Options Available)
-
Get an API Key:
- Visit OpenRouter.ai
- Sign up and get your API key
- This powers the AI functionality with various free models
-
Configure GitSpectre:
spectre config set api_key your_openrouter_api_key_here
Option 2: Anthropic (Claude)
-
Get an API Key:
- Visit Anthropic Console
- Sign up and get your API key
- Provides full access to Claude models
-
Configure GitSpectre:
spectre --configSelect option 4 to set provider to "anthropic", then option 1 to set your Anthropic API key.
Continue Setup
-
Navigate to a Git Repository:
cd /path/to/your/git/repo
-
Run Commands:
spectre your natural language command
For help:
spectre --help
Features
Core AI Capabilities
- Natural Language Git Commands: Execute complex Git workflows using plain English (e.g., "push my code but resolve any conflicts first")
- Intelligent Code Analysis: Reads, modifies, and validates code files with syntax checking
- Conversational Interface: Ask questions about Git, get explanations, and receive guidance
Advanced Git Operations
- Repository Management: Init, clone, status, branches, commits, merges, diffs
- Conflict Resolution: Automatic detection, analysis, and resolution with user options (keep ours/theirs/merge)
- Stashing & Tagging: Full support for Git stashing, tagging, and advanced operations
- Remote Operations: Push, pull, fetch with conflict handling
- History & Logs: Commit history, blame, log analysis
Code Modification Tools
- File Operations: Read, write, search-replace files with path validation
- Syntax Validation: Python AST parsing for code safety
- Diff Analysis: Intelligent conflict diffing and resolution suggestions
Configuration & Security
- Git Config Management: Set user.name, user.email, and other Git configs
- API Key Management: Secure storage of OpenRouter API keys
- Path Validation: Ensures all operations stay within repository boundaries
- Command Sanitization: Prevents dangerous shell commands
User Experience
- Verbose Mode:
--verboseflag shows tool calls, commands, and internal processing - Colored Output: Syntax highlighting for code, status colors for operations
- Progress Indicators: Spinners and status updates during long operations
- Error Handling: Comprehensive error messages and recovery suggestions
- Async Processing: Non-blocking operations for better responsiveness
Technical Features
- Modular Architecture: Clean separation of CLI, agent, and tools
- Async/Await: Full async support for API calls and long-running tasks
- Logging: Configurable logging levels with file output
- Cross-Platform: Works identically on Windows, macOS, Linux
- Extensible: Plugin-like tool system for adding new capabilities
Installation
Prerequisites
- Python 3.6+
- Git repository (for Git operations)
- OpenRouter or Anthropic API key (for AI functionality)
Install from Source
git clone https://github.com/yourusername/GitSpectre.git
cd GitSpectre
pip install -e .
Get API Key
OpenRouter (default, free options):
- Visit OpenRouter.ai
- Sign up and get your API key
- Set it:
spectre config set api_key your_key_here
Anthropic (Claude):
- Visit Anthropic Console
- Sign up and get your API key
- Set it:
spectre --configand follow the prompts
Usage
Command Line Options
spectre --help # Show help
spectre --verbose <command> # Show detailed tool calls and processing
spectre config set <key> <value> # Set configuration
spectre config get <key> # Get configuration
spectre <natural language> # Execute AI-powered Git commands
Examples
Basic Git Operations
spectre commit my changes with message 'update readme'
spectre create a new branch called feature-x
spectre merge main into current branch
spectre push my changes to origin
spectre what is my current branch?
spectre show me the status
Conflict Resolution
spectre push my code # Detects conflicts and explains them
spectre resolve conflicts in my files # Interactive resolution
spectre merge feature-branch # Handles conflicts automatically
Code Operations
spectre read the main.py file
spectre search for 'TODO' in all files
spectre validate syntax of utils.py
spectre show diff between branches
Configuration
# OpenRouter (default)
spectre config set api_key your_openrouter_key
# Anthropic - use interactive config
spectre --config
# Set Git config
spectre config set user.name "Your Name"
spectre config set user.email "your.email@example.com"
Advanced Operations
spectre stash my changes with message 'work in progress'
spectre create a tag v1.0 with message 'Release version 1.0'
spectre show diff between HEAD and HEAD~3
spectre reset files to last commit
spectre what changed in the last commit?
Architecture
Core Components
- CLI Layer (
cli.py): Click-based command interface - Agent Layer (
agent.py): OpenRouter AI integration with tool calling - Tool Layer (
tools/): Modular Git and file operation functions - Config Layer (
config.py): Settings and API key management - Utils Layer (
utils.py): Logging, validation, formatting
Tool System
GitSpectre uses a comprehensive tool-calling system with 31+ tools:
Git Tools (22 tools)
- Repository:
get_repo_status,init_repo,clone_repo - Branches:
get_branches,switch_branch,create_branch - Commits:
create_commit,get_commit_history,amend_commit - Merging:
merge_branch,detect_conflicts,resolve_conflicts,abort_merge - Remotes:
push_changes,pull_changes - Advanced:
stash_changes,apply_stash,create_tag,reset_files,get_diff
File Tools (6 tools)
- Operations:
read_file,write_file,search_replace - Analysis:
validate_code,analyze_conflicts,apply_conflict_resolution,get_file_info
Utility Tools (3 tools)
- Config:
get_git_config_tool,set_git_config_tool,list_git_configs
AI Integration
GitSpectre supports two AI providers:
OpenRouter (Default)
- Models: GPT-4o-mini, Claude 3.5 Sonnet, and many others
- Many free models available
- Use:
spectre config set api_key your_openrouter_key
Anthropic (Claude)
-
Models: Claude Sonnet 4, Claude Opus 4, Claude 3.5
-
Full access to Claude models
-
Use:
spectre --configto set provider and API key -
Tool Calling: Function calling for programmatic Git/file operations
-
Context Awareness: Repository state passed to AI for informed decisions
-
Safety: Command validation and path restrictions
Development
Project Structure
gitspectre/
├── __init__.py
├── main.py # Entry point
├── cli.py # Command-line interface
├── agent.py # AI agent and tool calling
├── config.py # Configuration management
├── utils.py # Utilities and logging
├── prompts.json # AI system prompts
└── tools/
├── git_tools.py # Git operations
├── file_tools.py # File operations
└── utility_tools.py # Configuration tools
Adding New Tools
- Create function in appropriate
tools/*.pyfile - Add tool schema to
*_TOOLSlist - Update
ALL_TOOLSinagent.py - Test with verbose mode
Testing
# Run with verbose output
spectre --verbose "test command"
# Check logs
tail ~/.gitspectre/gitspectre.log
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure verbose mode works for debugging
- Submit a pull request
Publishing & Distribution
GitSpectre can be installed via multiple package managers:
PyPI (pip)
Automatic Publishing: Releases are automatically published to PyPI via GitHub Actions.
Manual Installation:
pip install gitspectre
Homebrew (macOS/Linux)
Automatic Updates: Homebrew formulas are automatically updated via GitHub Actions when new releases are published.
Installation:
brew install gitspectre
Manual Formula: The Homebrew formula is maintained in the gitspectre.rb file in this repository.
Development Installation
For contributors and developers:
# Clone and install in development mode
git clone https://github.com/predat-r/GitSpectre.git
cd GitSpectre
pip install -e .
CI/CD Workflows
This project uses GitHub Actions for automated publishing:
.github/workflows/publish-pypi.yml: Builds and publishes to PyPI on release.github/workflows/update-homebrew.yml: Updates Homebrew formula on release
Release Process
- Create a new release on GitHub with a version tag (e.g.,
v0.1.1) - GitHub Actions automatically:
- Builds the Python package
- Publishes to PyPI
- Updates the Homebrew formula
- Users can install the new version via
pip install --upgrade gitspectreorbrew upgrade gitspectre
License
MIT License - see LICENSE file for details.
Changelog
v0.1.0 (Current)
- Complete rewrite with modular architecture
- 31+ AI-powered tools for Git and file operations
- Intelligent conflict resolution
- Async processing and robust error handling
- Verbose mode for debugging
- Production-ready code with comprehensive documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitspectre-0.2.0.tar.gz.
File metadata
- Download URL: gitspectre-0.2.0.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ec3d2af94bf21330975d91a51b761587da35657eccb7b34d2ed6cc8f04f7db2
|
|
| MD5 |
56a01b507df7215561393e12e45a763f
|
|
| BLAKE2b-256 |
5a11eea1293abee1e958238c0a8e436cdfebc78c3df6221292ba21ec60263515
|
File details
Details for the file gitspectre-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gitspectre-0.2.0-py3-none-any.whl
- Upload date:
- Size: 33.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67df2e1eb57f4438718ee0d46c01c233d20d547810df63435825e265d3c507b2
|
|
| MD5 |
af55ae9de5c7f3245a0e67272163cdc1
|
|
| BLAKE2b-256 |
eda133ff1f26456535a8d45c73942175185f66a4a87e2c9330a7d572810e23e1
|