Skip to content

Commit 660ebf1

Browse files
committed
docs: add AI coding guidelines
1. Created a comprehensive `copilot-instructions.md` file to guide AI coding assistance. 2. Documented project overview, architecture patterns, development workflow, code patterns, commit message conventions, testing patterns, packaging details, key files, common tasks, and quality assurance measures. 3. This document will allow AI assistants (like GitHub Copilot) to provide more accurate and relevant suggestions within the project's context. feat: 添加 AI 编码指南 1. 创建了一个全面的 `copilot-instructions.md` 文件,以指导 AI 编码辅助。 2. 记录了项目概述、架构模式、开发工作流程、代码模式、提交消息约定、测试 模式、打包详细信息、关键文件、常见任务和质量保证措施。 3. 该文档将允许 AI 助手(如 GitHub Copilot)在项目上下文中提供更准确和相 关的建议。
1 parent d0d479e commit 660ebf1

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

.github/copilot-instructions.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Git Commit Helper - AI Coding Guidelines
2+
3+
## Project Overview
4+
This is a Rust CLI tool that generates intelligent git commit messages using multiple AI services. It supports bilingual output (Chinese/English), integrates with GitHub/Gerrit for code reviews, and provides automatic commit message translation and enhancement.
5+
6+
## Architecture Patterns
7+
8+
### Core Components
9+
- **CLI Layer** (`main.rs`): Command parsing and orchestration using clap
10+
- **AI Service Layer** (`ai_service.rs`): Abstracted AI provider implementations with async traits
11+
- **Configuration** (`config.rs`): Service management and user preferences
12+
- **Git Integration** (`git.rs`): Hook processing and commit message handling
13+
- **Platform Integrations**: GitHub (`github.rs`), Gerrit (`gerrit.rs`) for remote reviews
14+
15+
### Key Design Patterns
16+
- **Async Service Abstraction**: All AI services implement `AiService` trait with `chat()` and `translate()` methods
17+
- **Fallback Mechanism**: `ai_service::translate_with_fallback()` tries multiple services on failure
18+
- **Progress Reporting**: Long operations use `terminal_format::print_progress()` for user feedback
19+
- **Configuration-Driven**: Service selection and behavior controlled via `Config` struct
20+
21+
## Development Workflow
22+
23+
### Building
24+
```bash
25+
cargo build --release # Production build
26+
cargo build # Debug build
27+
```
28+
29+
### Testing
30+
```bash
31+
cargo test # Run all tests
32+
cargo test --lib # Library tests only
33+
```
34+
35+
### Installation
36+
```bash
37+
./install.sh # Quick install from source
38+
git-commit-helper install # Install git hooks in current repo
39+
```
40+
41+
## Code Patterns
42+
43+
### AI Service Implementation
44+
```rust
45+
#[async_trait]
46+
impl AiService for MyTranslator {
47+
async fn chat(&self, system_prompt: &str, user_content: &str) -> Result<String> {
48+
// Implementation with proper error handling
49+
}
50+
}
51+
```
52+
53+
### Configuration Management
54+
```rust
55+
#[derive(Serialize, Deserialize)]
56+
pub struct Config {
57+
pub default_service: AIService,
58+
pub services: Vec<AIServiceConfig>,
59+
// ... other fields
60+
}
61+
```
62+
63+
### Error Handling
64+
- Use `anyhow::Result<()>` for fallible operations
65+
- Prefer `?` operator for error propagation
66+
- Log errors with `log::{debug, info, warn, error}`
67+
68+
### Async Operations
69+
- All AI calls are async with `tokio::main`
70+
- Use `reqwest` for HTTP requests with timeout configuration
71+
- Handle network failures gracefully with retries
72+
73+
## Commit Message Conventions
74+
75+
### Structure
76+
```
77+
<type>(<scope>): <english title>
78+
79+
<detailed english description>
80+
81+
<chinese title>
82+
83+
<chinese description>
84+
85+
Fixes: #123
86+
PMS: BUG-456
87+
```
88+
89+
### Types
90+
- `feat`: New features
91+
- `fix`: Bug fixes
92+
- `docs`: Documentation
93+
- `style`: Code style changes
94+
- `refactor`: Code refactoring
95+
- `test`: Testing
96+
- `chore`: Maintenance
97+
98+
### Issue Linking
99+
- GitHub: `https://github.com/owner/repo/issues/123``Fixes: owner/repo#123`
100+
- PMS: `https://pms.uniontech.com/bug-view-123.html``PMS: BUG-123`
101+
- Local: `123``Fixes: #123`
102+
103+
## Testing Patterns
104+
105+
### Unit Tests
106+
```rust
107+
#[cfg(test)]
108+
mod tests {
109+
#[test]
110+
fn test_my_function() {
111+
// Test implementation
112+
}
113+
}
114+
```
115+
116+
### CLI Testing
117+
Uses `assert_cmd` for command-line interface testing in `dev-dependencies`.
118+
119+
## Packaging
120+
121+
### Distribution Formats
122+
- **Arch Linux**: `PKGBUILD` with makepkg
123+
- **Debian/Ubuntu**: `debian/` directory with debuild
124+
- **Fedora**: RPM packaging
125+
- **Shell Completions**: bash, zsh, fish in `completions/`
126+
127+
### Build Dependencies
128+
- Rust 1.70+ (stable toolchain)
129+
- Cargo for dependency management
130+
- Git for version control
131+
132+
## Key Files to Reference
133+
134+
### Core Logic
135+
- `src/main.rs`: CLI command structure and main flow
136+
- `src/ai_service.rs`: AI service abstractions and implementations
137+
- `src/commit.rs`: Commit message parsing and generation logic
138+
- `src/config.rs`: Configuration structures and file handling
139+
140+
### Integration Points
141+
- `src/git.rs`: Git hook integration and commit processing
142+
- `src/github.rs`: GitHub API interactions
143+
- `src/gerrit.rs`: Gerrit API interactions
144+
145+
### Utilities
146+
- `src/terminal_format.rs`: Terminal output styling and progress
147+
- `install.sh`: Installation script with dependency checking
148+
- `completions/`: Shell completion files
149+
150+
## Common Tasks
151+
152+
### Adding New AI Service
153+
1. Add variant to `AIService` enum in `config.rs`
154+
2. Implement `AiService` trait in `ai_service.rs`
155+
3. Add service creation logic in `ai_service::create_translator()`
156+
4. Update CLI selection menu in `main.rs`
157+
158+
### Adding New Commit Type
159+
1. Update commit type validation in `commit.rs`
160+
2. Add to documentation in `README.md`
161+
3. Update shell completions if needed
162+
163+
### Platform Integration
164+
1. Create new module (e.g., `myplatform.rs`)
165+
2. Implement review functions following `github.rs`/`gerrit.rs` patterns
166+
3. Add URL pattern matching in `review.rs`
167+
4. Update CLI help text
168+
169+
## Quality Assurance
170+
171+
### Code Review Checklist
172+
- [ ] Async error handling with proper `Result` types
173+
- [ ] Configuration validation and fallbacks
174+
- [ ] Progress reporting for user-facing operations
175+
- [ ] Bilingual output support where applicable
176+
- [ ] Unit tests for new functionality
177+
- [ ] Documentation updates for user-facing changes
178+
179+
### Performance Considerations
180+
- AI requests use configurable timeouts (default 20s)
181+
- Progress reporting prevents perceived hangs
182+
- Fallback mechanism ensures reliability
183+
- Minimal dependencies for fast compilation</content>
184+
<parameter name="filePath">/home/zccrs/projects/git-commit-helper/.github/copilot-instructions.md

0 commit comments

Comments
 (0)