|
| 1 | +import { |
| 2 | + AgentConfig, |
| 3 | + AgentStepContext, |
| 4 | +} from '@codebuff/common/util/types/agent-config.d' |
| 5 | + |
| 6 | +const config: AgentConfig = { |
| 7 | + id: 'diff-reviewer-3', |
| 8 | + |
| 9 | + displayName: 'Diff Reviewer (Level 3)', |
| 10 | + model: 'openai/gpt-5', |
| 11 | + inputSchema: { |
| 12 | + prompt: { |
| 13 | + type: 'string', |
| 14 | + description: |
| 15 | + 'Please provide a short description of the changes you want to review', |
| 16 | + }, |
| 17 | + }, |
| 18 | + outputMode: 'last_message', |
| 19 | + |
| 20 | + toolNames: ['read_files', 'run_terminal_command', 'spawn_agents'], |
| 21 | + subagents: ['james/file-explorer@0.1.3'], |
| 22 | + |
| 23 | + parentPrompt: 'Spawn when you need to review code changes in the git diff', |
| 24 | + |
| 25 | + systemPrompt: |
| 26 | + 'You are an expert software developer. Your job is to review code changes and provide helpful feedback.', |
| 27 | + |
| 28 | + instructionsPrompt: `Review the changes and suggest improvements. |
| 29 | +
|
| 30 | +Use the following guidelines while reviewing the changes: |
| 31 | +- Find ways to simplify the code |
| 32 | +- Reuse existing code as much as possible instead of writing new code |
| 33 | +- Preserve as much behavior as possible in the existing code |
| 34 | +- Prefer changing as few lines of code as possible |
| 35 | +- Look for opportunities to improve the code's readability |
| 36 | +- Look for logical errors in the code |
| 37 | +- Look for missed cases in the code |
| 38 | +- Look for any other bugs`, |
| 39 | + |
| 40 | + handleSteps: function* ({ agentState, prompt, params }: AgentStepContext) { |
| 41 | + // Step 1: Get list of changed files from git diff --name-only |
| 42 | + const { toolResult: gitDiffFilesResult } = yield { |
| 43 | + toolName: 'run_terminal_command', |
| 44 | + args: { |
| 45 | + command: 'git diff --name-only', |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + // Then, extract file paths from the result |
| 50 | + const changedFiles = (gitDiffFilesResult || '') |
| 51 | + .split('\n') |
| 52 | + .map((line) => line.trim()) |
| 53 | + .filter((line) => line && !line.startsWith('??') && !line.includes('OSC')) |
| 54 | + |
| 55 | + // Step 2: Read the files |
| 56 | + if (changedFiles.length > 0) { |
| 57 | + yield { |
| 58 | + toolName: 'read_files', |
| 59 | + args: { |
| 60 | + paths: changedFiles, |
| 61 | + }, |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + // Step 3: Run full git diff to see the actual changes |
| 66 | + yield { |
| 67 | + toolName: 'run_terminal_command', |
| 68 | + args: { |
| 69 | + command: 'git diff', |
| 70 | + }, |
| 71 | + } |
| 72 | + |
| 73 | + // Step 4: Put words in the AI's mouth to get it to spawn the file explorer. |
| 74 | + yield { |
| 75 | + toolName: 'add_message', |
| 76 | + args: { |
| 77 | + role: 'assistant', |
| 78 | + content: |
| 79 | + 'Now I will spawn a file explorer to find any missing codebase context.', |
| 80 | + }, |
| 81 | + } |
| 82 | + |
| 83 | + yield 'STEP' |
| 84 | + |
| 85 | + // Step 5: Put words in the AI's mouth to review the changes. |
| 86 | + yield { |
| 87 | + toolName: 'add_message', |
| 88 | + args: { |
| 89 | + role: 'assistant', |
| 90 | + content: 'Here is my comprehensive review of the changes.', |
| 91 | + }, |
| 92 | + } |
| 93 | + |
| 94 | + // Step 6: Let AI review the changes in a final step. (The last message is also the agent's output.) |
| 95 | + yield 'STEP' |
| 96 | + }, |
| 97 | +} |
| 98 | + |
| 99 | +export default config |
0 commit comments