|
| 1 | +/** |
| 2 | + * Copyright (c) 2025 Bytedance, Inc. and its affiliates. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | +import { join } from 'path'; |
| 6 | +import { MCPAgent } from '../src'; |
| 7 | +import { getModel } from './model'; |
| 8 | + |
| 9 | +const model = getModel('gpt-4o-2024-11-20'); |
| 10 | + |
| 11 | +async function main() { |
| 12 | + const agent = new MCPAgent({ |
| 13 | + model, |
| 14 | + instructions: |
| 15 | + 'You are GitHub Reviewer, a specialized assistant designed to help with code review tasks. ' + |
| 16 | + 'You excel at analyzing pull requests, identifying potential bugs, security issues, and suggesting code improvements. ' + |
| 17 | + 'You should focus on code quality, maintainability, performance, and adherence to best practices. ' + |
| 18 | + 'When reviewing code, consider readability, potential edge cases, error handling, and test coverage. ' + |
| 19 | + 'Provide constructive feedback and suggest specific improvements when possible.\n\n' + |
| 20 | + 'IMPORTANT WORKFLOW REQUIREMENTS:\n' + |
| 21 | + '1. You MUST browse through ALL code changes in the pull request before providing feedback. Do not skip any files or changes.\n' + |
| 22 | + '2. After reviewing all changes, create a comprehensive review report with the following sections:\n' + |
| 23 | + ' - Summary of changes\n' + |
| 24 | + ' - Potential issues and bugs\n' + |
| 25 | + ' - Code quality considerations\n' + |
| 26 | + ' - Suggested improvements\n' + |
| 27 | + ' - Overall assessment\n' + |
| 28 | + '3. ALWAYS include relevant code snippets in your report to illustrate your points. For each important issue or suggestion, ' + |
| 29 | + 'include the corresponding code before and after the change (if applicable) in markdown code blocks with proper syntax highlighting.\n' + |
| 30 | + '4. When highlighting significant changes, use the format:\n' + |
| 31 | + ' ```diff\n' + |
| 32 | + ' - removed code\n' + |
| 33 | + ' + added code\n' + |
| 34 | + ' ```\n' + |
| 35 | + '5. Use the filesystem tool to save your final review report to a file named "REVIEW_RESULT.md" in the current directory.\n\n' + |
| 36 | + 'Make extensive use of the playwright browsing tool to navigate GitHub repositories, ' + |
| 37 | + 'examine code changes in PRs, understand context by exploring related files, and analyze commit histories. ' + |
| 38 | + 'Take screenshots of specific code sections when they help illustrate complex issues or changes. ' + |
| 39 | + 'Your reviews should be thorough yet easy to understand, with code examples making your feedback concrete and actionable. ' + |
| 40 | + "Remember that including actual code snippets makes your reports more vivid and helps the developer understand exactly what you're referring to.", |
| 41 | + mcpServers: { |
| 42 | + playwright: { |
| 43 | + command: 'npx', |
| 44 | + args: ['@playwright/mcp@latest'], |
| 45 | + }, |
| 46 | + filesystem: { |
| 47 | + command: 'npx', |
| 48 | + args: [ |
| 49 | + '-y', |
| 50 | + '@modelcontextprotocol/server-filesystem', |
| 51 | + join(__dirname, 'result'), |
| 52 | + ], |
| 53 | + }, |
| 54 | + }, |
| 55 | + }); |
| 56 | + |
| 57 | + try { |
| 58 | + await agent.initialize(); |
| 59 | + const tools = agent.getTools(); |
| 60 | + console.log(`\nAvailable tools (${tools.length}):`); |
| 61 | + for (const tool of tools) { |
| 62 | + console.log(`- ${tool.name}: ${tool.description}`); |
| 63 | + } |
| 64 | + |
| 65 | + // GitHub PR review related queries |
| 66 | + const queries = [ |
| 67 | + 'Review https://github.com/bytedance/UI-TARS-desktop/pull/534', |
| 68 | + ]; |
| 69 | + |
| 70 | + for (const query of queries) { |
| 71 | + console.log('\n=================================================='); |
| 72 | + console.log(`👤 Review request: ${query}`); |
| 73 | + console.log('=================================================='); |
| 74 | + |
| 75 | + const reviewFeedback = await agent.run(query); |
| 76 | + |
| 77 | + console.log('--------------------------------------------------'); |
| 78 | + console.log(`🔍 Review feedback: ${reviewFeedback}`); |
| 79 | + console.log('==================================================\n'); |
| 80 | + } |
| 81 | + } catch (error) { |
| 82 | + console.error('Error during code review:', error); |
| 83 | + } finally { |
| 84 | + await agent.cleanup(); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +if (require.main === module) { |
| 89 | + main().catch(console.error); |
| 90 | +} |
0 commit comments