Skip to main content

Crate gcop_rs

Crate gcop_rs 

Source
Expand description

§gcop-rs

AI-powered Git tool for generating commit messages and code reviews.

This is a Rust rewrite of the original Python project gcop.

§Features

  • Commit message generation: Generates messages from staged changes (Conventional Commits by default, configurable).
  • Code review: Analyzes diffs to surface potential issues and improvement suggestions.
  • Multiple providers: Claude, OpenAI, Gemini, and Ollama (local models).
  • High availability: Built-in fallback chain when the primary provider fails.
  • Streaming output: Real-time typewriter-style output (Claude/OpenAI/Gemini).
  • Internationalization: Supports English and Chinese.

§Quick Start

§Use as a CLI

# Install
cargo install gcop-rs

# Initialize configuration
gcop-rs init

# Generate commit message
git add .
gcop-rs commit

# Code review
gcop-rs review changes

§Use as a library

use gcop_rs::git::repository::GitRepository;
use gcop_rs::git::GitOperations;
use gcop_rs::llm::provider::openai::OpenAIProvider;
use gcop_rs::llm::LLMProvider;
use gcop_rs::config::{ProviderConfig, NetworkConfig};

// 1. Initialize Git repository
let repo = GitRepository::open(None)?;
let diff = repo.get_staged_diff()?;

// 2. Initialize LLM provider
let config = ProviderConfig {
    api_key: Some("sk-...".to_string()),
    model: "gpt-4o-mini".to_string(),
    ..Default::default()
};
let network_config = NetworkConfig::default();
let provider = OpenAIProvider::new(&config, "openai", &network_config, false)?;

// 3. Generate commit message
let message = provider.generate_commit_message(&diff, None, None).await?;
println!("Generated: {}", message);

§Core Modules

  • git - Git operation abstractions.
  • llm - LLM provider traits and implementations.
  • commands - CLI command implementations.
  • config - Configuration loading and management.
  • error - Unified error types.
  • ui - Terminal UI utilities.

§Configuration

Configuration file locations:

  • Linux: ~/.config/gcop/config.toml
  • macOS: ~/Library/Application Support/gcop/config.toml
  • Windows: %APPDATA%\gcop\config\config.toml
  • Project-level (optional): <repo>/.gcop/config.toml

Example configuration:

[llm]
default_provider = "claude"
fallback_providers = ["openai"]

[llm.providers.claude]
api_key = "sk-ant-..."
model = "claude-sonnet-4-5-20250929"

[commit]
max_retries = 10
show_diff_preview = true

Modules§

cli
Command-line argument definitions and parsing.
commands
CLI command implementations and shared helpers. Command implementations.
config
Configuration loading, defaults, and validation. Configuration loading, merging, and validation.
error
Unified error types and localization helpers.
git
Git repository abstractions and operations. Git abstractions and repository operations.
llm
LLM traits, message types, prompts, and providers. LLM abstractions, shared types, and provider traits.
ui
Terminal UI helpers (colors, prompts, spinner, streaming output). Terminal UI utilities.
workspace
Workspace detection and commit scope inference for monorepos. Monorepo workspace detection and scope inference