Skip to content

Commit 142c9a9

Browse files
qiniu-ciqiniu-ciCarlJi
authored
实现 Issue #184: 支持通过交互式来使用Claude docker姿势 (#185)
* Initial plan for Issue #184: 支持通过交互式来使用Claude docker姿势 * feat: add interactive Docker mode support for Claude Implement interactive Docker mode to enable full context management capabilities when using Claude Docker, similar to native CLI usage. Key changes: - Add ClaudeInteractive implementation with persistent container connections - Support streaming communication and session management - Add Interactive config option with environment variable support - Enhance factory pattern with interactive mode selection logic - Extract shared Docker utilities to avoid code duplication - Update start script with -i/--interactive flag support Technical features: - Persistent container connections to avoid restart overhead - Session management with context preservation - Stream response processing with automatic container reuse - Complete error handling and timeout controls Usage: ./scripts/start.sh -p claude -d -i 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Closes #184 * feat: implement interactive PTY mode for Claude Docker Replace pipe-based Docker communication with PTY (pseudo-terminal) to enable full Claude Code interactive features. This allows proper context management and terminal-based tool usage within Docker containers. Key changes: - Added PTY master/slave device creation with proper system calls - Updated Docker command to use -it flag for TTY allocation - Enhanced response handling with timeout and completion detection - Improved session lifecycle management with context cancellation - Added terminal environment setup (TERM=xterm-256color) This enables the same interactive experience as native Claude Code CLI while running in Docker containers, supporting all terminal-based features and context management capabilities. Closes #184 * fix(codeagent): support relative dir as work dir (#190) * fix(codeagent): support relative dir as work dir * fix(codeagent): support interactive mode * fix(codeagent): claude support bash url and api key env * fix(codeagent): adjust interactive way * fix(codeagent): adjust interactive way --------- Co-authored-by: qiniu-ci <qiniu-ci@qiniu.com> Co-authored-by: Changjun Ji <jinsdu@outlook.com>
1 parent 028e16c commit 142c9a9

File tree

12 files changed

+845
-80
lines changed

12 files changed

+845
-80
lines changed

README.md

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,29 @@
11
# CodeAgent
22

3-
CodeAgent 是一个基于 Go 语言开发的自动化代码生成系统,通过 GitHub Webhook 接收 `/code` 命令,自动为 Issue 生成代码并创建 Pull Request。
3+
CodeAgent 是一个基于 AI 的代码代理,能够自动处理 GitHub Issue Pull Request,生成代码修改建议
44

55
## 功能特性
66

7-
- 🤖 **智能代码生成**: 基于 Issue 描述自动生成代码
8-
- 🔄 **GitHub 集成**: 通过 Webhook 接收命令,自动创建 PR
9-
-**即时响应**: 立即创建分支和 PR,提供进度跟踪
10-
- 🐳 **容器化执行**: 使用 Docker 容器隔离执行环境
11-
- 💻 **本地 CLI 模式**: 支持本地 Claude CLI 和 Gemini CLI,无需 Docker
12-
- 🧹 **自动清理**: 智能管理临时工作空间,避免资源泄露
13-
- 📊 **状态监控**: 实时监控系统状态和执行进度
14-
- 🔒 **安全可靠**: 完善的错误处理和重试机制,支持 GitHub Webhook 签名验证
15-
- 🧠 **上下文感知**: Gemini CLI 模式自动构建完整上下文,提升代码质量
16-
17-
## 系统架构
18-
19-
```
20-
GitHub Issue (/code) → Webhook → CodeAgent → 创建分支和空PR → Claude Code 容器 → 更新PR
21-
```
22-
23-
### 工作流程
24-
25-
1. **接收命令**: 通过 GitHub Webhook 接收 `/code` 命令
26-
2. **创建分支**: 立即创建分支并推送空的 "Initial plan" commit
27-
3. **创建 PR**: 基于空 commit 创建 Pull Request,提供进度跟踪
28-
4. **代码生成**: 在后台执行 Claude Code 生成代码
29-
5. **Mock 测试**: 创建模拟文件用于测试二次提交流程
30-
6. **更新 PR**: 将生成的代码作为新的 commit 推送到 PR
7+
- 🤖 支持多种 AI 模型(Claude、Gemini)
8+
- 🔄 自动处理 GitHub Issue 和 Pull Request
9+
- 🐳 Docker 容器化执行环境
10+
- 🔒 GitHub Webhook 签名验证
11+
- 📁 基于 Git Worktree 的工作空间管理
12+
- 🛠️ 灵活的配置选项,支持相对路径
3113

3214
## 快速开始
3315

34-
### 环境要求
35-
36-
- Go 1.21+
37-
- Git
38-
- GitHub Personal Access Token
39-
- **Docker 模式**: Docker(默认)
40-
- **本地 CLI 模式**: Claude CLI 或 Gemini CLI
41-
4216
### 安装
4317

44-
1. **克隆项目**
45-
4618
```bash
47-
git clone <your-repo-url>
19+
git clone https://github.com/qbox/codeagent.git
4820
cd codeagent
49-
```
50-
51-
2. **安装依赖**
52-
53-
```bash
54-
go mod tidy
21+
go mod download
5522
```
5623

5724
### 配置
5825

59-
#### 方式一:命令行参数(推荐)
26+
#### 方式一:命令行参数
6027

6128
```bash
6229
go run ./cmd/server \
@@ -77,7 +44,7 @@ export PORT=8888
7744
go run ./cmd/server
7845
```
7946

80-
#### 方式三:配置文件(不包含敏感信息
47+
#### 方式三:配置文件(推荐
8148

8249
创建配置文件 `config.yaml`
8350

@@ -91,7 +58,7 @@ github:
9158
webhook_url: "http://localhost:8888/hook"
9259

9360
workspace:
94-
base_dir: "/tmp/codeagent"
61+
base_dir: "./codeagent" # 支持相对路径!
9562
cleanup_after: "24h"
9663

9764
claude:
@@ -124,22 +91,39 @@ use_docker: true # 是否使用 Docker,false 表示使用本地 CLI
12491

12592
**注意**: 敏感信息(如 token、api_key、webhook_secret)应该通过命令行参数或环境变量设置,而不是写在配置文件中。
12693

94+
### 相对路径支持
95+
96+
CodeAgent 现在支持在配置文件中使用相对路径,提供更灵活的配置选项:
97+
98+
```yaml
99+
workspace:
100+
base_dir: "./codeagent" # 相对于配置文件目录
101+
# 或者
102+
base_dir: "../workspace" # 相对于配置文件目录的上级目录
103+
# 或者
104+
base_dir: "/tmp/codeagent" # 绝对路径(保持不变)
105+
```
106+
107+
相对路径会在配置加载时自动转换为绝对路径,详情请参考 [相对路径支持文档](docs/relative-path-support.md)。
108+
127109
### 安全配置
128110

129111
#### Webhook 签名验证
130112

131113
为了防止 webhook 接口被恶意利用,CodeAgent 支持 GitHub Webhook 签名验证功能:
132114

133115
1. **配置 webhook secret**:
116+
134117
```bash
135118
# 方式1: 环境变量(推荐)
136119
export WEBHOOK_SECRET="your-strong-secret-here"
137-
120+
138121
# 方式2: 命令行参数
139122
go run ./cmd/server --webhook-secret "your-strong-secret-here"
140123
```
141124

142125
2. **GitHub Webhook 设置**:
126+
143127
- 在 GitHub 仓库设置中添加 Webhook
144128
- URL: `https://your-domain.com/hook`
145129
- Content type: `application/json`

cmd/server/config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
server:
22
port: 8888
3-
# webhook_secret: 通过 --webhook-secret 参数或 WEBHOOK_SECRET 环境变量设置
3+
webhook_secret: "1234567890"
44

55
github:
6-
# token: 通过 --github-token 参数或 GITHUB_TOKEN 环境变量设置
6+
#token: "1234567890"
77
webhook_url: "http://localhost:8888/hook"
88

99
workspace:
10-
base_dir: "/codeagent"
10+
base_dir: "./codeagent"
1111
cleanup_after: "24h"
1212

1313
claude:
1414
# api_key: 通过 --claude-api-key 参数或 CLAUDE_API_KEY 环境变量设置
1515
container_image: "goplusorg/codeagent:v0.4"
1616
timeout: "30m"
17+
interactive: true
1718

1819
docker:
1920
socket: "unix:///var/run/docker.sock"

config.example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ workspace:
1717

1818
claude:
1919
api_key: your-claude-api-key-here
20+
base_url: https://api.anthropic.com # 可选,默认为官方 API 地址
2021
container_image: anthropic/claude-code:latest
2122
timeout: 30m
23+
interactive: true # 是否启用交互式模式
2224

2325
gemini:
2426
api_key: your-gemini-api-key-here

0 commit comments

Comments
 (0)