Skip to main content

gcop_rs/
lib.rs

1//! # gcop-rs
2//!
3//! AI-powered Git tool for generating commit messages and code reviews.
4//!
5//! This is a Rust rewrite of the original Python project [gcop](https://github.com/Undertone0809/gcop).
6//!
7//! ## Features
8//! - **Commit message generation**: Generates messages from staged changes (Conventional Commits by default, configurable).
9//! - **Code review**: Analyzes diffs to surface potential issues and improvement suggestions.
10//! - **Multiple providers**: Claude, OpenAI, Gemini, and Ollama (local models).
11//! - **High availability**: Built-in fallback chain when the primary provider fails.
12//! - **Streaming output**: Real-time typewriter-style output (Claude/OpenAI/Gemini).
13//! - **Internationalization**: Supports English and Chinese.
14//!
15//! ## Quick Start
16//!
17//! ### Use as a CLI
18//! ```bash
19//! # Install
20//! cargo install gcop-rs
21//!
22//! # Initialize configuration
23//! gcop-rs init
24//!
25//! # Generate commit message
26//! git add .
27//! gcop-rs commit
28//!
29//! # Code review
30//! gcop-rs review changes
31//! ```
32//!
33//! ### Use as a library
34//! ```ignore
35//! use gcop_rs::git::repository::GitRepository;
36//! use gcop_rs::git::GitOperations;
37//! use gcop_rs::llm::provider::openai::OpenAIProvider;
38//! use gcop_rs::llm::LLMProvider;
39//! use gcop_rs::config::{ProviderConfig, NetworkConfig};
40//!
41//! # async fn example() -> anyhow::Result<()> {
42//! // 1. Initialize Git repository
43//! let repo = GitRepository::open(None)?;
44//! let diff = repo.get_staged_diff()?;
45//!
46//! // 2. Initialize LLM provider
47//! let config = ProviderConfig {
48//!     api_key: Some("sk-...".to_string()),
49//!     model: "gpt-4o-mini".to_string(),
50//!     ..Default::default()
51//! };
52//! let network_config = NetworkConfig::default();
53//! let provider = OpenAIProvider::new(&config, "openai", &network_config, false)?;
54//!
55//! // 3. Generate commit message
56//! let message = provider.generate_commit_message(&diff, None, None).await?;
57//! println!("Generated: {}", message);
58//! # Ok(())
59//! # }
60//! ```
61//!
62//! ## Core Modules
63//! - [`git`] - Git operation abstractions.
64//! - [`llm`] - LLM provider traits and implementations.
65//! - [`commands`] - CLI command implementations.
66//! - [`config`] - Configuration loading and management.
67//! - [`error`] - Unified error types.
68//! - [`ui`] - Terminal UI utilities.
69//!
70//! ## Configuration
71//! Configuration file locations:
72//! - Linux: `~/.config/gcop/config.toml`
73//! - macOS: `~/Library/Application Support/gcop/config.toml`
74//! - Windows: `%APPDATA%\gcop\config\config.toml`
75//! - Project-level (optional): `<repo>/.gcop/config.toml`
76//!
77//! Example configuration:
78//! ```toml
79//! [llm]
80//! default_provider = "claude"
81//! fallback_providers = ["openai"]
82//!
83//! [llm.providers.claude]
84//! api_key = "sk-ant-..."
85//! model = "claude-sonnet-4-5-20250929"
86//!
87//! [commit]
88//! max_retries = 10
89//! show_diff_preview = true
90//! ```
91
92#[macro_use]
93extern crate rust_i18n;
94
95/// Command-line argument definitions and parsing.
96pub mod cli;
97/// CLI command implementations and shared helpers.
98pub mod commands;
99/// Configuration loading, defaults, and validation.
100pub mod config;
101/// Unified error types and localization helpers.
102pub mod error;
103/// Git repository abstractions and operations.
104pub mod git;
105/// LLM traits, message types, prompts, and providers.
106pub mod llm;
107/// Terminal UI helpers (colors, prompts, spinner, streaming output).
108pub mod ui;
109/// Workspace detection and commit scope inference for monorepos.
110pub mod workspace;
111
112// Initialize i18n for library modules.
113i18n!("locales", fallback = "en");