코드 검토 봇 구축
이 가이드에서는 작업 영역 기술을 사용하여 끌어오기 요청을 자동으로 검토하는 코드 검토 봇을 구축합니다. 봇은 기술 파일에서 코딩 표준을 로드하고 구조화된 피드백을 제공합니다. 기술 디렉터리가 있는 작업 공간을 만들고Agent Skill검토 지침 및 참조 파일이 포함되어 있습니다. 그런 다음 자동화된 검토를 수행하는 Agent에 기술을 연결합니다.
전제조건전제조건에 대한 직접 링크
- Node.js
v22.13.0이상 설치 - 지원되는 Model Provider의 API 키
- 기존 Mastra 프로젝트(새 프로젝트를 설정하려면 설치 가이드를 따르세요)
작업공간 만들기작업공간 만들기에 대한 직접 링크
src/mastra/index.ts 파일에서 Workspace 및 LocalFilesystem 클래스를 가져옵니다. Workspace 인스턴스에서 skills 옵션이 Skill 디렉터리를 가리키도록 구성합니다. skills 디렉터리는 파일 시스템의 basePath 내부에 위치합니다.
import { Mastra } from '@mastra/core'
import { resolve } from 'node:path'
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
const workspace = new Workspace({
filesystem: new LocalFilesystem({
basePath: resolve(import.meta.dirname, '../../workspace'),
}),
skills: ['skills'],
})
export const mastra = new Mastra({
workspace,
})
프로젝트 루트에 workspace라는 새 폴더를 만듭니다. 그 안에 skills 폴더를 만듭니다. 다음 단계에서 이 폴더에 코드 표준 Skill을 정의합니다.
코드 표준 기술 만들기코드 표준 기술 만들기에 대한 직접 링크
Skill은 Agent를 위한 지침이 담긴 SKILL.md 파일을 포함하는 구조화된 디렉터리입니다. 코드 표준 Skill은 검토 프로세스를 정의하고 스타일 가이드를 참조합니다.
workspace/skills 안에 code-standards라는 새 폴더를 만듭니다. SKILL.md 파일을 만들고 검토 지침을 추가합니다.
---
name: code-standards
description: Automated code review standards and checks
---
# Code Review Standards
Review code systematically using these steps:
1. **Critical Issues**: Security vulnerabilities, memory leaks, logic bugs, missing error handling
2. **Code Quality**: Functions over 50 lines, code duplication, confusing names, missing types
3. **Style Guide**: Check references/style-guide.md for naming and organization
4. **Linting**: Flag common issues like use of `var`, leftover `console.log` statements, and `debugger` statements
Provide feedback in this format:
**Summary**: One sentence overview
**Critical Issues**: List with line numbers
**Suggestions**: Improvements that would help
**Positive Notes**: What the code does well
workspace/skills/code-standards 안에 Skill의 참고 자료를 보관할 references 폴더를 만듭니다. 프로젝트의 코딩 규칙을 설명하는 스타일 가이드를 작성하고 파일 이름을 style-guide.md로 지정합니다.
# Style Guide
## Naming
- Variables/Functions: `camelCase`
- Constants: `UPPER_SNAKE_CASE`
- Files: `kebab-case.ts`
- Booleans: Start with `is`, `has`, `should`
## Code organization
```typescript
// 1. Imports
import { foo } from 'bar'
// 2. Constants
const MAX_SIZE = 100
// 3. Types
interface User {
id: string
}// 4. Functions
function doSomething() {}
// 5. Exports
export { doSomething }
```
## Error handling
Always handle errors explicitly - never silently catch.
## Comments
Write "why" not "what".
리뷰 Agent 만들기리뷰 Agent 만들기에 대한 직접 링크
이제 코드 표준 Skill을 사용하는 코드 검토 봇 Agent를 만들 차례입니다. src/mastra/agents/code-reviewer.ts 파일을 새로 만들고 Agent를 정의합니다.
import { Agent } from '@mastra/core/agent'
export const codeReviewer = new Agent({
id: 'code-reviewer',
name: 'Code Review Bot',
instructions: `You are an automated code reviewer.
When asked to review code:
1. Activate the 'code-standards' skill
2. Follow the review process from the skill
3. Check against the style guide in skill references
4. Be constructive and specific with line numbers`,
model: 'openai/gpt-5.6-sol',
})
src/mastra/index.ts에서 Agent를 가져와 정의하고 Mastra 인스턴스에 등록합니다.
import { Mastra } from '@mastra/core'
import { resolve } from 'node:path'
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
import { codeReviewer } from './agents/code-reviewer'
const workspace = new Workspace({
filesystem: new LocalFilesystem({
basePath: resolve(import.meta.dirname, '../../workspace'),
}),
skills: ['skills'],
})
export const mastra = new Mastra({
workspace,
agents: { codeReviewer },
})
봇 테스트봇 테스트에 대한 직접 링크
Studio를 시작하고 코드 검토 봇과 상호 작용하여 작동 방식을 확인합니다.
- npm
- pnpm
- Yarn
- Bun
npm run dev
pnpm run dev
yarn dev
bun run dev
localhost:4111을 열고 코드 검토 Agent로 이동합니다. 채팅 입력 내에서 다음과 같은 검토용 코드 조각을 제공합니다.
Review this code:
function getData(id) {
var result = fetch('/api/data/' + id);
console.log(result);
return result;
}
봇은 code-standards Skill을 활성화하고 구조화된 피드백을 제공해야 합니다. Agent 응답은 비결정적이므로 출력이 다를 수 있지만 다음과 비슷한 결과가 표시되어야 합니다.
**Summary**: Function has several issues with variable declaration,
debugging statements, and missing error handling.
**Critical Issues**:
- Missing error handling for fetch (line 2)
- No async/await for asynchronous operation (line 2)
**Suggestions**:
- Use const instead of var (line 2)
- Remove console.log before committing (line 3)
- Add TypeScript type for id parameter
- Use template literals instead of concatenation
**Positive Notes**:
- Function name is clear and descriptive
다음 단계다음 단계에 대한 직접 링크
이 봇을 다음으로 확장할 수 있습니다.
- 다양한 언어 또는 프레임워크에 대한 기술 추가
- 보안 점검 및 성과 검토를 위한 기술 생성
- 자동 PR 검토를 위해 GitHub Actions와 통합
- 인라인 피드백을 남기는 PR 댓글 봇 구축
자세히 알아보기: