感谢你对 Claude Code Rust 项目的兴趣!本文档指导如何为项目贡献代码。
# 克隆仓库
git clone https://github.com/yourusername/claude-code-rust.git
cd claude-code-rust
# 安装 Rust (如果未安装)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 构建项目
cargo build
# 运行测试
cargo test
# 检查代码质量
cargo clippy# 创建特性分支
git checkout -b feature/your-feature-name
# 进行更改并提交
git add .
git commit -m "feat: 描述你的改进"
# 推送分支
git push origin feature/your-feature-name
# 创建 Pull Request
# 在 GitHub 上提交 PR我们遵循 Conventional Commits 规范:
<type>(<scope>): <subject>
<body>
<footer>
feat: 新功能fix: 错误修复docs: 文档更新style: 代码风格 (不改变功能)refactor: 代码重构perf: 性能优化test: 添加/修改测试chore: 项目管理
feat(cli): 添加 config reset 命令
- 支持重置配置到默认值
- 添加确认提示
- 添加 --force 标志
Closes #123
在提交 PR 前,请确保:
- 运行
cargo clippy无错误 - 运行
cargo fmt格式化代码 - 添加/更新相关测试
- 运行
cargo test所有测试通过
- 更新相关文档
- 添加代码注释 (复杂逻辑)
- 更新 CHANGELOG.md
- 未显著增加启动时间
- 未显著增加内存占用
- 已优化关键路径
// ✅ 好的例子
pub async fn query(client: &Client, q: &str) -> Result<Response> {
// 完整的错误处理
client
.post("/query")
.json(&QueryRequest { query: q })
.send()
.await
.context("Failed to send query")?
.json()
.await
.context("Failed to parse response")
}
// ❌ 避免
pub async fn query(client: &Client, q: &str) -> Result<Response> {
let resp = client.post("/query").json(&QueryRequest { query: q }).send().await?;
Ok(resp.json().await?) // 信息不足的错误处理
}// ✅ 使用 anyhow + thiserror
use thiserror::Error;
use anyhow::{Context, Result};
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("Invalid configuration: {0}")]
Invalid(String),
#[error("Configuration file not found: {0}")]
NotFound(String),
}
// ❌ 有时候对
pub fn load_config(path: &str) -> Result<Config> {
std::fs::read_to_string(path)
.context("Failed to read config file")?
.parse()
.context("Failed to parse config file")
}// ✅ 使用 Tokio
#[tokio::main]
async fn main() -> Result<()> {
let client = Client::new();
client.query("test").await?;
Ok(())
}
// ✅ 批量操作使用 join_all
let futures: Vec<_> = urls
.iter()
.map(|url| fetch(url))
.collect();
let results = futures::future::join_all(futures).await;新增代码应该:
- 启动速度: 不增将启动时间超过 5%
- 内存占用: 不增加基础内存超过 2%
- 二进制大小: 不增加体积超过 500KB
# 构建 release 版本
cargo build --release
# 测试启动速度
time ./target/release/claude_code_rs --version
# 测试内存占用
/usr/bin/time -v ./target/release/claude_code_rs --help
# 检查二进制大小
ls -lh ./target/release/claude_code_rs在提交 Issue 时:
- 检查已有 Issue - 避免重复
- 提供复现步骤 - 清晰的步骤说明
- 提供环境信息 - OS, Rust 版本等
- 提供日志输出 - RUST_LOG=debug 的输出
## 描述
简明描述 bug
## 复现步骤
1. ...
2. ...
3. ...
## 预期行为
应该发生什么
## 实际行为
实际发生了什么
## 环境
- OS: [e.g. Windows 10, Ubuntu 22.04]
- Rust: 1.75+ (cargo --version)
- 其他相关信息
## 日志
\`\`\`
RUST_LOG=debug cargo run ...
<输出>
\`\`\`良好的功能建议应该包括:
- 明确的用例说明
- 与现有功能的关系
- 可能的实现方向 (可选)
- 性能/安全性考虑 (如适用)
- Rust Book
- Rust API Guidelines
- Tokio 文档
- 项目代码注释和文档
- 提交 Discussion - 提问和讨论
- 加入 Discord/Slack - (待添加)
- 阅读现有 PR - 学习如何做好贡献
感谢你的贡献!🙌