open-code-review-delegate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpen Code Review — Delegation Mode
Open Code Review — 委托模式
A skill for performing AI code review where OCR provides deterministic engineering (file filtering, rule resolution) and the host agent performs the actual review using its own intelligence and tools.
这是一项用于AI代码审查的技能,其中OCR负责提供确定性工程支持(文件过滤、规则解析),而宿主Agent则利用自身智能和工具执行实际审查工作。
Prerequisites
前提条件
bash
which ocr || echo "NOT INSTALLED"If is not installed:
ocrbash
npm install -g @alibaba-group/open-code-reviewNo LLM configuration is needed for delegation mode.
bash
which ocr || echo "NOT INSTALLED"如果未安装:
ocrbash
npm install -g @alibaba-group/open-code-review委托模式无需配置LLM。
Workflow
工作流程
Step 1: Preview — Determine What to Review
步骤1:预览 — 确定审查范围
bash
ocr delegate preview [--from <ref> --to <ref>] [--commit <hash>] [--exclude <patterns>]This outputs:
- mode (workspace / range / commit)
- from / to / commit / merge_base — ref metadata for constructing git commands
- Reviewable file list — paths, status, insertions/deletions
- Excluded files — with exclusion reason
Common invocations:
| Scenario | Command |
|---|---|
| Workspace changes | |
| Branch comparison | |
| Single commit | |
bash
ocr delegate preview [--from <ref> --to <ref>] [--commit <hash>] [--exclude <patterns>]该命令输出:
- 模式(工作区 / 范围 / 提交)
- from / to / commit / merge_base — 用于构建git命令的引用元数据
- 可审查文件列表 — 文件路径、状态、新增/删除行数
- 排除文件 — 附带排除原因
常见调用方式:
| 场景 | 命令 |
|---|---|
| 工作区变更 | |
| 分支对比 | |
| 单个提交 | |
Step 2: Get Rules for Files
步骤2:获取文件对应的规则
bash
ocr delegate rule <path1> <path2> ...Pass the reviewable file paths from Step 1. Output is grouped by rule content — files sharing the same rule appear under one group, avoiding repetition.
bash
ocr delegate rule <path1> <path2> ...传入步骤1中得到的可审查文件路径。输出结果按规则内容分组 — 拥有相同规则的文件会归为一组,避免重复。
Step 3: Get Diffs
步骤3:获取差异内容
Use git directly based on the mode/ref info from Step 1:
Range mode (merge_base provided in preview output):
bash
git diff <merge_base>..<to> -- <path>Commit mode:
bash
git show <commit> -- <path>Workspace mode:
bash
undefined根据步骤1中的模式/引用信息,直接使用git命令:
范围模式(预览输出中提供了merge_base):
bash
git diff <merge_base>..<to> -- <path>提交模式:
bash
git show <commit> -- <path>工作区模式:
bash
undefinedTracked files
已追踪文件
git diff HEAD -- <path>
git diff HEAD -- <path>
New untracked files — read directly (entire file is new code)
新的未追踪文件 — 直接读取(整个文件都是新增代码)
cat <path>
undefinedcat <path>
undefinedStep 4: Review Each File
步骤4:逐一审查文件
For each reviewable file:
- Get its diff (Step 3)
- Consult its Rule Group (from Step 2) for the review checklist
- Conduct a thorough review, using appropriate context tools as needed
对于每个可审查文件:
- 获取其差异内容(步骤3)
- 查阅其对应的规则组(步骤2)获取审查检查清单
- 进行全面审查,必要时使用合适的上下文工具
Step 5: Format Output
步骤5:格式化输出
Each comment must follow this structure:
| Field | Type | Required | Description |
|---|---|---|---|
| path | string | yes | Relative file path |
| content | string | yes | Review comment describing the issue |
| start_line | integer | no | Start line in the new file |
| end_line | integer | no | End line in the new file |
| category | enum | no | bug, security, performance, maintainability, test, style, documentation, other |
| severity | enum | no | critical, high, medium, low |
每条评论必须遵循以下结构:
| 字段 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| path | string | 是 | 相对文件路径 |
| content | string | 是 | 描述问题的审查评论 |
| start_line | integer | 否 | 新文件中的起始行 |
| end_line | integer | 否 | 新文件中的结束行 |
| category | enum | 否 | bug、security、performance、maintainability、test、style、documentation、other |
| severity | enum | 否 | critical、high、medium、low |
Step 6: Classify and Report
步骤6:分类并报告
Group findings by severity:
- Critical/High: Bugs, security issues, data loss risks — always report
- Medium: Performance concerns, error handling gaps, maintainability issues — report with context
- Low: Style nits, minor suggestions — report only if clearly valuable
Discard likely false positives silently.
按严重程度分组整理审查结果:
- Critical/High(严重/高):Bug、安全问题、数据丢失风险 — 必须报告
- Medium(中):性能问题、错误处理漏洞、可维护性问题 — 附带上下文报告
- Low(低):风格问题、小建议 — 仅当明确有价值时才报告
静默丢弃可能的误报。
Step 7: Fix (Optional)
步骤7:修复(可选)
If the user requested "review and fix":
- Apply High/Critical fixes directly
- Describe Medium fixes that require manual intervention
- Skip Low-priority items unless trivial
如果用户要求“审查并修复”:
- 直接修复严重/高优先级问题
- 描述需要手动干预的中等优先级修复方案
- 除非问题 trivial,否则跳过低优先级项
Sub-commands Reference
子命令参考
| Command | Purpose |
|---|---|
| Which files to review + mode/ref metadata |
| Review rules grouped by content |
| 命令 | 用途 |
|---|---|
| 确定待审查文件 + 模式/引用元数据 |
| 按内容分组的审查规则 |
Shared Flags
共享标志
| Flag | Description |
|---|---|
| Source ref for range mode |
| Target ref for range mode |
| Single commit mode |
| Repository root (default: cwd) |
| Custom rule.json path |
| Comma-separated exclude patterns |
| Business context |
| Business context from Markdown file |
| 标志 | 描述 |
|---|---|
| 范围模式的源引用 |
| 范围模式的目标引用 |
| 单个提交模式 |
| 仓库根目录(默认:当前工作目录) |
| 自定义rule.json路径 |
| 逗号分隔的排除模式 |
| 业务上下文 |
| 来自Markdown文件的业务上下文 |
Gotchas
注意事项
- No LLM needed on OCR side — delegation mode never calls an LLM. All intelligence comes from the host agent.
- Rules are grouped — Files sharing the same rule are grouped together in the output. You can pass any number of paths per call; for large changes, fetch rules per-batch as you review.
- Working directory matters — operates on the Git repo at the current directory. Use
ocr delegateto override.--repo /path - Untracked files in workspace mode — includes untracked files. For these, read the file directly instead of using
preview.git diff - Background context — pass to
--backgroundwhen you have requirement context; it appears in the output for your reference during review.preview
- OCR端无需LLM — 委托模式从不调用LLM。所有智能均来自宿主Agent。
- 规则已分组 — 拥有相同规则的文件会在输出中归为一组。每次调用可传入任意数量的路径;对于大规模变更,可在审查时分批获取规则。
- 工作目录很重要 — 在当前目录的Git仓库上运行。使用
ocr delegate可覆盖默认路径。--repo /path - 工作区模式中的未追踪文件 — 会包含未追踪文件。对于这些文件,直接读取文件内容而非使用
preview。git diff - 背景上下文 — 当你有需求上下文时,可在中传入
preview参数;它会显示在输出中,供你审查时参考。--background