如何为 OpenClaw 开源社区做贡献 2026
完整的 OpenClaw 贡献指南 - 从搭建开发环境到提交第一个 PR。学习代码规范、PR 流程和社区准则。
完整的 OpenClaw 贡献指南 - 从搭建开发环境到提交第一个 PR。学习代码规范、PR 流程和社区准则。
OpenClaw 因为像你这样的贡献者而蓬勃发展。无论你是修复 bug、添加功能、改进文档,还是在社区中帮助他人,每一份贡献都很重要。本指南将带你了解所需的一切。
在贡献之前,确保你有:
```bash
```
```bash
git clone https://github.com/YOUR_USERNAME/openclaw.git
cd openclaw
```
```bash
git remote add upstream https://github.com/openclaw/openclaw.git
```
```bash
npm install
cd python-sdk
pip install -e ".[dev]"
```
```bash
npm test
pytest
```
我们遵循严格的编码标准以保持代码质量:
```typescript
// ✅ 好:清晰的命名、正确的类型、错误处理
async function executeAgentTask(
task: Task,
options: ExecutionOptions
): Promise
if (!task.description) {
throw new ValidationError('任务描述是必需的')
}
try {
const result = await this.agent.execute(task, options)
return {
status: 'completed',
output: result,
timestamp: new Date()
}
} catch (error) {
logger.error('任务执行失败', { task, error })
throw new ExecutionError(`执行任务失败: ${error.message}`)
}
}
// ❌ 差:不清晰的命名、没有类型、糟糕的错误处理
async function doStuff(t, opts) {
const r = await this.agent.execute(t, opts)
return r
}
```
关键原则:
```python
from typing import Optional
from openclaw.types import Task, TaskResult
from openclaw.exceptions import ValidationError, ExecutionError
async def execute_agent_task(
task: Task,
options: Optional[ExecutionOptions] = None
) -> TaskResult:
"""
使用给定选项执行 agent 任务。
Args:
task: 要执行的任务
options: 可选的执行配置
Returns:
包含执行输出和元数据的 TaskResult
Raises:
ValidationError: 如果任务无效
ExecutionError: 如果执行失败
"""
if not task.description:
raise ValidationError("任务描述是必需的")
try:
result = await self.agent.execute(task, options)
return TaskResult(
status="completed",
output=result,
timestamp=datetime.now()
)
except Exception as error:
logger.error(f"任务执行失败: {error}", extra={"task": task})
raise ExecutionError(f"执行任务失败: {error}")
async def do_stuff(t, opts=None):
r = await self.agent.execute(t, opts)
return r
```
关键原则:
所有贡献必须包含测试。我们维持 80%+ 的代码覆盖率。
```typescript
// TypeScript (Vitest)
import { describe, it, expect, vi } from 'vimport { Agent } from '../src/agent'
describe('Agent', () => {
it('应该成功执行简单任务', async () => {
const mockLLM = vi.fn().mockResolvedValue({
content: '任务完成'
})
const agent = new Agent({ llm: mockLLM })
const result = await agent.execute({ description: '简单任务' })
expect(result.status).toBe('completed')
expect(mockLLM).toHaveBeenCalledTimes(1)
})
it('应该优雅地处理执行失败', async () => {
const mockLLM = vi.fn().mockRejectedValue(new Error('API 错误'))
const agent = new Agent({ llm: mockLLM })
await expect(
agent.execute({ description: '失败的任务' })
).rejeoThrow('API 错误')
})
})
```
```python
import pytest
from openclaw import Agent
from openclaw.exceptions import ExecutionError
@pytest.mark.asyncio
async def test_agent_executes_simple_tasks():
"""Agent 应该成功执行简单任务。"""
mock_llm = AsyncMock(return_value={"content": "任务完成"})
agent = Agent(llm=mock_llm)
result = await agent.execute({"description": "简单任务"})
assert result.status == "completed"
assert mock_llm.call_count == 1
@pytest.mark.asyncio
async def test_agent_handles_failures():
"""Agent 应该优雅地处理执行失败。"""
mock_llm = AsyncMock(side_effect=Exception("API 错误"))
agent = Agent(llm=mock_llm)
with pytest.raises(ExecutionError, match="API 错误"):
await agent.execute({"description": "失败的任务"})
```
```typescript
describe('Agent 集成测试', () => {
it('应该完成端到端的真实任务', async () => {
const agent = new Agent({
apiKey: process.env.OPENCLAW_API_KEY
})
const result = await agent.execute({
description: '计算 50 美元的 15% 小费',
maxSteps: 5
})
expect(result.status).toBe('completed')
expect(result.output).toContain('7.50')
}, 30000) // 真实 API 调用需要更长的超时时间
})
```
```bash
git checkout -b feature/your-feature-name
git checkout -b fix/bug-description
```
```bash
npm run lint
npm run format
black .
flake8 .
mypy .
```
我们使用 约定式提交:
```bash
git commit -m "feat(agent): 添加并行工具执行"
git commit -m "fix(api): 正确处理速率限制错误"
git commit -m "docs(readme): 更新安装说明"
git commit -m "test(agent): 添加错误处理测试"
```
类型:
```bash
git push origin feature/your-feature-name
```
然后访问 GitHub 并点击 "Create Pull Request"。
```markdown
简要描述此 PR 的作用。
Closes #123
```
更快审查的技巧:
寻找标记为 `good-first-issue` 的问题:
在开始主要功能之前:
文档贡献总是受欢迎的:
发现了 bug?帮助我们修复它:
```markdown
Bug 描述
清晰描述 bug。
重现步骤
预期行为
应该发生什么。
实际行为
实际发生了什么。
环境
附加上下文
任何其他相关信息。
```
我们致力于提供一个热情和包容的环境:
遇到困难?以下是获取帮助的方法:
我们重视所有贡献:
维护者拥有提交权限并帮助指导项目:
要求:
职责:
维护者遵循此流程进行发布:
为 OpenClaw 做贡献是有意义的,并帮助全球数千名开发者。无论你是修复拼写错误还是添加主要功能,你的贡献都很重要。
准备好贡献了吗?查看我们的 适合新手的 issue 并加入我们的 Discord 社区。