Chuyển đến nội dung
tinAI
Quay lại

Open Code Review: Alibaba mở mã code review agent đã chạy nội bộ 2 năm ở scale tens-of-thousands dev

Bản dịch tiếng Việt của tinAI · Từ Open Code Review – Battle-tested at Alibaba's scale (github.com) · Ngày gốc: · Dịch ngày:

Bài gốc: Open Code Review – Battle-tested at Alibaba's scale (github.com)

Tác giả: Alibaba

Ngày đăng: Dịch ngày:

TL;DR

Alibaba open source tool code review nội bộ từng phục vụ tens of thousands dev và bắt millions of defect. Kiến trúc hybrid: deterministic pipeline lo việc cần đúng chính xác (chọn file, bundle file liên quan, position comment), agent LLM chỉ phụ trách dynamic decision. Built-in ruleset cho NPE, thread-safety, XSS, SQL injection. Tương thích OpenAI và Anthropic API, plug được vào Claude Code skill/plugin và CI/CD (GitHub Actions, GitLab CI).

Ước tính đọc: 3 phút

Giới thiệu

Open Code Review (OCR) là CLI tool review code dựa trên AI, xuất phát từ tool nội bộ chính thức của Alibaba. Trong hơn 2 năm vận hành nội bộ, nó phục vụ tens of thousands dev và bắt millions of defect — sau khi đủ battle-test, Alibaba spin out thành open source project.

Cơ chế cốt lõi: đọc git diff, gửi file thay đổi qua LLM (cấu hình endpoint tùy ý), và sinh ra structured review comment với line-level precision. Agent có thể đọc toàn file, search codebase, inspect các file thay đổi khác để có context — sinh review deep chứ không chỉ surface-level diff feedback.

Vấn đề của general-purpose agent

Nếu từng dùng Claude Code với Skill cho review, bạn sẽ quen ba pain point:

Root cause: kiến trúc thuần language-driven không có hard constraint nào.

Kiến trúc hybrid: deterministic engineering × LLM agent

OCR design theo nguyên tắc: phần nào không được sai → deterministic engineering, phần nào cần dynamic → LLM.

Deterministic engineering (hard constraint):

Agent (dynamic decision):

Cách sử dụng

Cài đặt

# Khuyến nghị: NPM
npm install -g @alibaba-group/open-code-review

# Hoặc tải binary trực tiếp từ GitHub Release
curl -Lo ocr https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-darwin-arm64
chmod +x ocr && sudo mv ocr /usr/local/bin/ocr

Sau cài, lệnh ocr available global.

Cấu hình LLM

# Anthropic (Claude)
ocr config set llm.url https://api.anthropic.com/v1/messages
ocr config set llm.auth_token your-api-key-here
ocr config set llm.model claude-opus-4-6
ocr config set llm.use_anthropic true

# Hoặc env var (priority cao hơn)
export OCR_LLM_URL=https://api.anthropic.com/v1/messages
export OCR_LLM_TOKEN=your-api-key-here
export OCR_LLM_MODEL=claude-opus-4-6

Config lưu ở ~/.opencodereview/config.json. Tool cũng tương thích Claude Code env var (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL) và đọc luôn từ ~/.zshrc / ~/.bashrc.

Chạy review

# Workspace mode — review staged + unstaged + untracked
ocr review

# Branch range — so 2 ref
ocr review --from main --to feature-branch

# Single commit
ocr review --commit abc123

Tích hợp với coding agent

Ba cách plug OCR vào Claude Code:

Cách 1 — Skill:

npx skills add alibaba/open-code-review --skill open-code-review

Dạy agent của bạn cách invoke ocr, classify issue theo priority, optionally apply fix.

Cách 2 — Claude Code plugin:

/plugin marketplace add alibaba/open-code-review
/plugin install open-code-review@open-code-review

Đăng ký slash command /open-code-review:review chạy OCR rồi tự filter và fix issue.

Cách 3 — Copy command file: download file .md vào .claude/commands/ (project-level, share qua git) hoặc ~/.claude/commands/ (user-level).

CI/CD

ocr review --from "origin/main" --to "origin/feature-branch" --format json

Flag --format json cho output machine-readable cho CI script. Repo có sẵn example cho GitHub ActionsGitLab CI.

Built-in ruleset

Khác với tool review chỉ dựa vào prompt template, OCR ship ruleset đã được fine-tune cho:

Khi review file, OCR match rule theo file type/path và inject vào context của LLM — sharper attention, less noise.


Đường dẫn nguồn

tinAI dịch bài này sang tiếng Việt từ Open Code Review – Battle-tested at Alibaba's scale (github.com) · Loại nguồn: GitHub và giữ bối cảnh từ bản tin tinAI đã giới thiệu bài này .

Bản tin này có 3 bài dịch liên quan từ cùng bản tin.