|
| 1 | +# Feature Request Tool Integration |
| 2 | + |
| 3 | +这个集成将 `testFeatureRequestImplementation` 功能封装为一个标准的 remote-agent 工具,让用户可以通过简单的工具调用来触发自动化功能开发。 |
| 4 | + |
| 5 | +## 🎯 功能特性 |
| 6 | + |
| 7 | +- **工具化集成**: 将功能请求实现封装为标准的 remote-agent 工具 |
| 8 | +- **自动代码生成**: 基于功能描述自动分析和生成代码 |
| 9 | +- **智能工具链**: 集成 FeatureRequestPlaybook 的完整工具链 |
| 10 | +- **MCP 兼容**: 支持 Model Context Protocol 标准 |
| 11 | + |
| 12 | +## 🏗️ 架构组件 |
| 13 | + |
| 14 | +### 1. 核心工具 |
| 15 | +- **FeatureRequestTool**: `packages/remote-agent/src/capabilities/tools/feature/feature-request-tool.ts` |
| 16 | + - 封装了 testFeatureRequestImplementation 的核心逻辑 |
| 17 | + - 提供标准的工具接口 |
| 18 | + - 支持详细的参数配置 |
| 19 | + |
| 20 | +### 2. 服务层 |
| 21 | +- **FeatureRequestService**: `packages/remote-agent/src/services/feature-request-service.ts` |
| 22 | + - 处理功能请求的业务逻辑 |
| 23 | + - 管理 AI Agent 和 FeatureRequestPlaybook |
| 24 | + - 提供结构化的结果分析 |
| 25 | + |
| 26 | +### 3. 工具注册 |
| 27 | +- **工具集成**: 在 `packages/remote-agent/src/capabilities/tools.ts` 中注册 |
| 28 | +- **MCP 支持**: 在 `packages/remote-agent/src/capabilities.ts` 中启用 |
| 29 | + |
| 30 | +## 🚀 使用方法 |
| 31 | + |
| 32 | +### 1. 通过 AI Agent 使用 |
| 33 | + |
| 34 | +```javascript |
| 35 | +const { AIAgent } = require('./packages/remote-agent/dist/agent.js') |
| 36 | + |
| 37 | +const agent = new AIAgent({ |
| 38 | + workspacePath: './', |
| 39 | + githubToken: process.env.GITHUB_TOKEN, |
| 40 | + verbose: true, |
| 41 | + enableToolChaining: true |
| 42 | +}) |
| 43 | + |
| 44 | +// 使用 feature-request 工具 |
| 45 | +const response = await agent.start(` |
| 46 | +请使用 feature-request 工具实现以下功能: |
| 47 | +
|
| 48 | +添加一个简单的日志工具,支持不同级别的日志输出(info, warn, error) |
| 49 | +
|
| 50 | +参数: |
| 51 | +- description: "添加一个简单的日志工具,支持不同级别的日志输出" |
| 52 | +- verbose: true |
| 53 | +- max_rounds: 6 |
| 54 | +`) |
| 55 | +``` |
| 56 | + |
| 57 | +### 2. 直接调用工具 |
| 58 | + |
| 59 | +```javascript |
| 60 | +const { FeatureRequestService } = require('./packages/remote-agent/dist/services/feature-request-service.js') |
| 61 | + |
| 62 | +const service = new FeatureRequestService({ |
| 63 | + description: "实现用户认证中间件", |
| 64 | + workspacePath: "./", |
| 65 | + verbose: true, |
| 66 | + maxToolRounds: 8 |
| 67 | +}) |
| 68 | + |
| 69 | +const result = await service.implementFeature() |
| 70 | +console.log(result) |
| 71 | +``` |
| 72 | + |
| 73 | +### 3. MCP 客户端使用 |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "method": "tools/call", |
| 78 | + "params": { |
| 79 | + "name": "feature-request", |
| 80 | + "arguments": { |
| 81 | + "description": "创建一个配置管理器,支持从环境变量和配置文件加载设置", |
| 82 | + "verbose": true, |
| 83 | + "max_rounds": 6 |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## 🧪 测试 |
| 90 | + |
| 91 | +### 运行工具测试 |
| 92 | +```bash |
| 93 | +# 测试 feature-request 工具 |
| 94 | +node packages/remote-agent/test-feature-request-tool.js |
| 95 | + |
| 96 | +# 测试特定 GitHub issue |
| 97 | +node packages/remote-agent/test-feature-request-tool.js 105 |
| 98 | + |
| 99 | +# 运行原始功能测试 |
| 100 | +node packages/remote-agent/test-feature-request.js |
| 101 | +``` |
| 102 | + |
| 103 | +### 构建和准备 |
| 104 | +```bash |
| 105 | +# 构建 remote-agent |
| 106 | +cd packages/remote-agent |
| 107 | +pnpm build |
| 108 | + |
| 109 | +# 确保环境变量配置 |
| 110 | +cp .env.example .env |
| 111 | +# 编辑 .env 文件,添加必要的 token |
| 112 | +``` |
| 113 | + |
| 114 | +## ⚙️ 工具参数 |
| 115 | + |
| 116 | +### feature-request 工具参数 |
| 117 | + |
| 118 | +| 参数 | 类型 | 必需 | 默认值 | 描述 | |
| 119 | +|------|------|------|--------|------| |
| 120 | +| `description` | string | ✅ | - | 功能的详细描述 | |
| 121 | +| `issue_number` | number | ❌ | - | GitHub issue 编号 | |
| 122 | +| `owner` | string | ❌ | "unit-mesh" | GitHub 仓库所有者 | |
| 123 | +| `repo` | string | ❌ | "autodev-workbench" | GitHub 仓库名称 | |
| 124 | +| `workspace_path` | string | ❌ | 当前目录 | 工作空间路径 | |
| 125 | +| `max_rounds` | number | ❌ | 8 | 最大工具执行轮数 | |
| 126 | +| `validate_changes` | boolean | ❌ | true | 是否验证代码修改 | |
| 127 | +| `verbose` | boolean | ❌ | false | 启用详细日志 | |
| 128 | + |
| 129 | +## 📊 工具输出 |
| 130 | + |
| 131 | +工具会返回详细的执行报告,包括: |
| 132 | + |
| 133 | +- **执行状态**: 成功/失败状态 |
| 134 | +- **进度步骤**: 各个执行阶段的状态 |
| 135 | +- **代码修改**: 修改的文件数量和详情 |
| 136 | +- **工具使用**: 使用的工具列表和执行情况 |
| 137 | +- **实现总结**: AI 生成的实现摘要 |
| 138 | +- **执行时间**: 总执行时间统计 |
| 139 | + |
| 140 | +### 示例输出 |
| 141 | + |
| 142 | +``` |
| 143 | +🚀 Starting Feature Request Implementation |
| 144 | +📝 Description: 添加一个简单的日志工具,支持不同级别的日志输出 |
| 145 | +
|
| 146 | +🤖 AI Agent: deepseek (deepseek-chat) |
| 147 | +🔧 Available Tools: 25 |
| 148 | +
|
| 149 | +⚙️ Configuration: |
| 150 | + • Max Rounds: 6 |
| 151 | + • Validate Changes: true |
| 152 | + • Verbose: false |
| 153 | +
|
| 154 | +🧪 Executing feature request analysis and implementation... |
| 155 | +
|
| 156 | +📊 Implementation Results: |
| 157 | +✅ Success: true |
| 158 | +🔄 Rounds: 4 |
| 159 | +🛠️ Tools Used: github-analyze-issue, search-keywords, read-file, str-replace-editor |
| 160 | +💻 Code Modifications: 1 |
| 161 | +⏱️ Execution Time: 45230ms |
| 162 | +
|
| 163 | +🔧 Progress Steps: |
| 164 | + 1. 分析功能需求 - ✅ |
| 165 | + 2. 搜索相关代码 - ✅ |
| 166 | + 3. 生成实现方案 - ✅ |
| 167 | + 4. 修改代码文件 - ✅ |
| 168 | +
|
| 169 | +📄 Implementation Summary: |
| 170 | +成功实现了日志工具功能,创建了支持多级别日志输出的 Logger 类... |
| 171 | +
|
| 172 | +📝 Modified Files: |
| 173 | + 1. src/utils/logger.ts |
| 174 | +
|
| 175 | +🎉 Feature request implementation completed successfully! |
| 176 | +
|
| 177 | +💡 Next Steps: |
| 178 | +• Review the generated code changes |
| 179 | +• Test the implemented functionality |
| 180 | +• Consider adding unit tests |
| 181 | +• Update documentation if needed |
| 182 | +``` |
| 183 | + |
| 184 | +## 🔧 自定义配置 |
| 185 | + |
| 186 | +### 修改工具行为 |
| 187 | +在 `feature-request-tool.ts` 中可以自定义: |
| 188 | +- 参数验证逻辑 |
| 189 | +- 输出格式 |
| 190 | +- 错误处理 |
| 191 | +- 日志级别 |
| 192 | + |
| 193 | +### 调整服务配置 |
| 194 | +在 `FeatureRequestService` 中可以修改: |
| 195 | +- 默认工具轮数 |
| 196 | +- 工作空间路径 |
| 197 | +- 验证规则 |
| 198 | +- 进度回调 |
| 199 | + |
| 200 | +## 🔗 与现有功能的关系 |
| 201 | + |
| 202 | +- **testFeatureRequestImplementation**: 原始测试脚本,现在作为服务层的基础 |
| 203 | +- **FeatureRequestPlaybook**: 核心的 AI 提示词策略,负责指导功能实现 |
| 204 | +- **AutoDevRemoteAgentTools**: 工具集合,feature-request 工具已集成其中 |
| 205 | +- **MCP 服务器**: 支持通过 MCP 协议调用 feature-request 工具 |
| 206 | + |
| 207 | +## 🐛 故障排除 |
| 208 | + |
| 209 | +### 常见问题 |
| 210 | + |
| 211 | +1. **工具未找到** |
| 212 | + - 确认 remote-agent 已构建:`pnpm build` |
| 213 | + - 检查工具是否正确注册在 `AutoDevRemoteAgentTools` 中 |
| 214 | + |
| 215 | +2. **环境配置错误** |
| 216 | + - 检查 `.env` 文件中的 token 配置 |
| 217 | + - 确认 GITHUB_TOKEN 和 LLM provider token 已设置 |
| 218 | + |
| 219 | +3. **执行失败** |
| 220 | + - 启用 verbose 模式查看详细日志 |
| 221 | + - 检查工作空间路径是否正确 |
| 222 | + - 确认网络连接和 API 访问权限 |
| 223 | + |
| 224 | +### 调试模式 |
| 225 | +```javascript |
| 226 | +// 启用详细日志 |
| 227 | +const result = await agent.start(` |
| 228 | +使用 feature-request 工具,参数: |
| 229 | +- description: "..." |
| 230 | +- verbose: true |
| 231 | +- max_rounds: 10 |
| 232 | +`) |
| 233 | +``` |
| 234 | + |
| 235 | +## 🔮 未来扩展 |
| 236 | + |
| 237 | +- 支持更多编程语言和框架 |
| 238 | +- 添加代码质量检查和测试生成 |
| 239 | +- 集成 CI/CD 流水线触发 |
| 240 | +- 支持团队协作和代码审查 |
| 241 | +- 添加性能监控和分析 |
| 242 | +- 实现增量功能更新 |
0 commit comments