Skip to content

Commit be70d0d

Browse files
qiniu-ciqiniu-ci
andauthored
实现 Issue #287: docs:make current code comment & design doc to english (#295)
* Initial plan for Issue #287: docs:make current code comment & design doc to english * docs: translate code comments and design docs to English Translate Chinese comments and documentation to English across the codebase to improve international collaboration and accessibility. Key changes: - Translate function/method comments in internal/agent/agent.go - Translate Chinese AI prompts and user-facing messages to English - Translate comments in internal/webhook/handler.go and internal/context/template_generator.go - Create English versions of core documentation: - docs/codeagent-v0.5-en.md (architecture and features) - docs/deploy_guide_en.md (comprehensive deployment guide) - Maintain technical accuracy while following English documentation standards - Ensure consistent terminology throughout all translated content This makes the codebase accessible to English-speaking developers and enables better international open source collaboration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Closes #287 * docs: continue translating Chinese comments to English Continue comprehensive translation of Chinese content to English throughout the codebase to improve international accessibility and collaboration. Additional changes in this iteration: - Translate remaining Chinese comments in core Go files: - internal/modes/tag_handler.go (event handling logic) - internal/workspace/manager.go (workspace management) - internal/github/client.go (Git operations) - internal/code/claude_docker.go (Docker implementation) - pkg/models/events.go (event type definitions) - Create complete English system design documentation: - docs/codeagent-v0.1-en.md (comprehensive v0.1 architecture guide) - Translate function documentation, inline comments, and technical explanations - Maintain technical accuracy while following English documentation standards This builds upon previous translation work and systematically addresses the extensive Chinese content identified in the codebase (estimated 2000+ instances across 50+ files). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Closes #287 * docs: complete English translations for remaining docs Complete the translation of all remaining Chinese documentation files in the docs directory to improve international accessibility. Added comprehensive English translations for: - docs/codeagent-v0.2-en.md: Background, process flow, and technical specifications - docs/codeagent-v0.3-en.md: Local CLI mode, architecture optimization, and dual-mode support - docs/codeagent-v0.4-en.md: Git worktree-based workspace management design Key improvements: - Complete documentation coverage for all versions (v0.1-v0.5) - Professional English technical writing standards - Consistent terminology across all version documents - Preserved code examples and architectural details - Enhanced international developer accessibility The docs directory now provides comprehensive English documentation for the entire codebase evolution, supporting global open source collaboration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Closes #287 --------- Co-authored-by: qiniu-ci <[email protected]>
1 parent f5a3b91 commit be70d0d

File tree

14 files changed

+1562
-137
lines changed

14 files changed

+1562
-137
lines changed

docs/codeagent-v0.1-en.md

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
# Code Agent System Design v0.1
2+
3+
## Project Overview
4+
5+
Code Agent is an automated code generation system developed in Go that receives `/code` commands through GitHub Webhooks, automatically generates code for Issues, and creates Pull Requests.
6+
7+
## System Architecture
8+
9+
```
10+
GitHub Issue (/code) → Webhook → Code Agent → Temporary Repository → Claude Code Container → PR
11+
```
12+
13+
## Core Workflow
14+
15+
### 1. Webhook Reception and Parsing
16+
17+
- Listen for GitHub Issue comment events
18+
- Detect `/code` command triggers
19+
- Parse Issue content and context information
20+
21+
### 2. Temporary Repository Preparation
22+
23+
- Clone target repository to temporary directory
24+
- Create new branch (e.g., `Code-agent/issue-123`)
25+
- Generate initial commit: "Code-agent has received information, preparing to implement target issue"
26+
- Push branch and create PR
27+
28+
### 3. Claude Code Execution
29+
30+
- Mount temporary directory to Claude Code container
31+
- Pass Issue description and requirements as prompts
32+
- Execute automated code generation and modification
33+
- Implement functionality based on Issue requirements
34+
35+
### 4. Result Processing
36+
37+
- Parse Claude Code output and generated code
38+
- Commit changes with descriptive messages
39+
- Push to remote branch
40+
- Update PR description with implementation details
41+
42+
## Technical Implementation
43+
44+
### Directory Structure
45+
46+
```
47+
/tmp/codeagent/
48+
├── repos/
49+
│ └── owner-repo-issue-123/
50+
│ ├── .git/
51+
│ └── [repository files]
52+
└── sessions/
53+
└── claude-session-123/
54+
└── [Claude execution context]
55+
```
56+
57+
### Key Components
58+
59+
#### 1. Webhook Handler
60+
- **File**: `internal/webhook/handler.go`
61+
- **Functionality**: Process GitHub webhook events
62+
- **Trigger Detection**: Parse comments for `/code` commands
63+
64+
#### 2. Workspace Manager
65+
- **File**: `internal/workspace/manager.go`
66+
- **Functionality**: Manage temporary Git repositories
67+
- **Operations**: Clone, branch creation, cleanup
68+
69+
#### 3. GitHub Client
70+
- **File**: `internal/github/client.go`
71+
- **Functionality**: GitHub API interactions
72+
- **Operations**: PR creation, commit pushing, status updates
73+
74+
#### 4. Code Execution Engine
75+
- **File**: `internal/code/claude.go`
76+
- **Functionality**: Claude Code container management
77+
- **Operations**: Container creation, prompt execution, result parsing
78+
79+
## Configuration
80+
81+
### Environment Variables
82+
83+
```bash
84+
# GitHub Configuration
85+
GITHUB_TOKEN=your_github_token
86+
WEBHOOK_SECRET=your_webhook_secret
87+
88+
# Claude Configuration
89+
CLAUDE_API_KEY=your_claude_api_key
90+
91+
# System Configuration
92+
WORKSPACE_PATH=/tmp/codeagent
93+
```
94+
95+
### Config File (config.yaml)
96+
97+
```yaml
98+
github:
99+
token: "${GITHUB_TOKEN}"
100+
webhook_secret: "${WEBHOOK_SECRET}"
101+
102+
code:
103+
provider: "claude"
104+
claude:
105+
api_key: "${CLAUDE_API_KEY}"
106+
model: "claude-3-sonnet-20240229"
107+
108+
workspace:
109+
base_path: "/tmp/codeagent"
110+
cleanup_after_hours: 24
111+
112+
server:
113+
port: 8888
114+
host: "0.0.0.0"
115+
```
116+
117+
## Key Features
118+
119+
### 1. Automated Issue Processing
120+
- Parse Issue requirements automatically
121+
- Generate appropriate code solutions
122+
- Create PR with implementation
123+
124+
### 2. Git Repository Management
125+
- Temporary workspace isolation
126+
- Automatic branch management
127+
- Clean commit history
128+
129+
### 3. Claude Code Integration
130+
- Container-based execution
131+
- Context-aware code generation
132+
- Error handling and retry logic
133+
134+
### 4. GitHub Integration
135+
- Real-time webhook processing
136+
- PR status updates
137+
- Automatic cleanup
138+
139+
## Error Handling
140+
141+
### Common Scenarios
142+
143+
1. **GitHub API Rate Limits**
144+
- Implement exponential backoff
145+
- Queue requests when limit exceeded
146+
- Graceful degradation
147+
148+
2. **Claude Code Failures**
149+
- Retry mechanism with different prompts
150+
- Fallback to simpler implementations
151+
- Error reporting in PR comments
152+
153+
3. **Git Operation Failures**
154+
- Repository state validation
155+
- Conflict resolution strategies
156+
- Workspace cleanup on failure
157+
158+
4. **Resource Management**
159+
- Disk space monitoring
160+
- Process timeout handling
161+
- Memory usage optimization
162+
163+
## Security Considerations
164+
165+
### 1. Webhook Security
166+
- Signature verification for all incoming requests
167+
- IP allowlisting for GitHub webhooks
168+
- Rate limiting to prevent abuse
169+
170+
### 2. Code Execution Security
171+
- Containerized execution environment
172+
- Resource limits (CPU, memory, disk)
173+
- Network isolation
174+
175+
### 3. Repository Access
176+
- Token scope limitation
177+
- Read-only access where possible
178+
- Audit logging for all operations
179+
180+
## Deployment
181+
182+
### Docker Deployment
183+
184+
```dockerfile
185+
FROM golang:1.21-alpine AS builder
186+
WORKDIR /app
187+
COPY . .
188+
RUN go build -o codeagent ./cmd/codeagent
189+
190+
FROM alpine:latest
191+
RUN apk --no-cache add ca-certificates git
192+
WORKDIR /root/
193+
COPY --from=builder /app/codeagent .
194+
CMD ["./codeagent"]
195+
```
196+
197+
### Kubernetes Deployment
198+
199+
```yaml
200+
apiVersion: apps/v1
201+
kind: Deployment
202+
metadata:
203+
name: codeagent
204+
spec:
205+
replicas: 2
206+
selector:
207+
matchLabels:
208+
app: codeagent
209+
template:
210+
metadata:
211+
labels:
212+
app: codeagent
213+
spec:
214+
containers:
215+
- name: codeagent
216+
image: codeagent:latest
217+
ports:
218+
- containerPort: 8888
219+
env:
220+
- name: GITHUB_TOKEN
221+
valueFrom:
222+
secretKeyRef:
223+
name: github-secrets
224+
key: token
225+
volumeMounts:
226+
- name: workspace
227+
mountPath: /tmp/codeagent
228+
volumes:
229+
- name: workspace
230+
emptyDir: {}
231+
```
232+
233+
## Future Enhancements
234+
235+
### v0.2 Planned Features
236+
- Multi-language support (Python, JavaScript, etc.)
237+
- Advanced prompt engineering
238+
- Code quality validation
239+
- Integration testing automation
240+
241+
### v0.3 Roadmap
242+
- Multiple AI provider support (OpenAI, Gemini)
243+
- Custom code templates
244+
- Advanced context understanding
245+
- Performance optimizations
246+
247+
## Monitoring and Logging
248+
249+
### Metrics Collection
250+
- Request processing time
251+
- Success/failure rates
252+
- Resource usage statistics
253+
- GitHub API usage tracking
254+
255+
### Log Levels
256+
- **DEBUG**: Detailed execution flow
257+
- **INFO**: Key operation milestones
258+
- **WARN**: Recoverable errors
259+
- **ERROR**: Critical failures requiring attention
260+
261+
### Health Checks
262+
- `/health` endpoint for load balancer
263+
- Database connectivity checks
264+
- External service availability
265+
- Resource utilization monitoring

docs/codeagent-v0.2-en.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# 1. Background
2+
CodeAgent is a tool that assists with code development on GitHub.
3+
4+
# 2. Process Flow
5+
We can understand CodeAgent as a real "person" who, by understanding the descriptions/problems in GitHub Issues, creates Pull Requests, and then modifies code based on reviewers' suggestions until the Pull Request is merged.
6+
7+
1. Preparation Phase
8+
- Host machine prerequisites
9+
- claude-code (npm install -g @anthropic-ai/claude-code)
10+
- gemini-cli (npm install -g @google/gemini-cli)
11+
- Complete claude-code and gemini-cli authentication (to obtain authentication files)
12+
13+
2. Startup Phase
14+
- Triggered by Issue Assignment or /code command
15+
- Prepare code:
16+
- Pull from RepoInfo in webhook, skip if already pulled
17+
- git worktree add ./issue-${id}-${timestamp} -b codeagent/issue-${id}-${timestamp}
18+
- Start container
19+
- Mount code directory as workspace -v `issue-${id}-${timestamp}`:/workspace
20+
- Mount authentication information:
21+
- gemini-cli auth info at: `~/.gemini:~/.gemini`
22+
- Mount tools -v /user/local/bin/gemini:/user/local/bin/gemini
23+
- Start gemini/claude (may be wrapped codeagent in the future)
24+
- Code layer exposes external interfaces
25+
- Input / Output interfaces
26+
3. Interaction Phase
27+
- Interaction 1
28+
- Input: This is the Issue content ${issue}, organize a modification plan based on the Issue content
29+
- Output: Comment the output content as the first comment in the PR
30+
- Interaction 2:
31+
- Input: Modify code according to issue content
32+
- After output completion, comment the output to GitHub in format: <details><summary>Session Name</summary>$output</details>
33+
- Submit commit & push
34+
- Review comment:
35+
- Input: issue comment
36+
- After output completion, comment the output to GitHub: <details><summary>Session Name</summary>$output</details>
37+
- Submit commit & push
38+
4. Completion Phase
39+
- Trigger action: merge/close PR
40+
- Clean up session (if possible)
41+
- Close container
42+
- git worktree del ./issue-${id}-${timestamp}
43+
- Close issue
44+
45+
# 3. Specification Definition
46+
47+
1. Create a code object through a startup command
48+
49+
```golang
50+
// Create PR first -> PR ID
51+
// Create a code object
52+
// 1. Start container using agent tools, need to implement gemini / claude
53+
// code ,err := agent.Create(repo)
54+
55+
// Enter interactive mode, send messages through Prompt
56+
res, err := code.Prompt(message)
57+
out, err := io.ReadAll(res.out)
58+
59+
code, err := agent.Resume(workspace)
60+
// Receive review comment, find code through PR ID
61+
res, err := code.Prompt(comment)
62+
63+
// End:
64+
// Close PR
65+
// Call code.Close()
66+
// 1. Clean up session (if possible)
67+
// 2. Close container
68+
// 3. Clean up workspace: git worktree del ./issue-${id}-${timestamp}
69+
// code.Close()
70+
// Close issue
71+
```

0 commit comments

Comments
 (0)