open-code-review-delegate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Open 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
ocr
is not installed:
bash
npm install -g @alibaba-group/open-code-review
No LLM configuration is needed for delegation mode.
bash
which ocr || echo "NOT INSTALLED"
如果未安装
ocr
bash
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:
ScenarioCommand
Workspace changes
ocr delegate preview
Branch comparison
ocr delegate preview --from main --to feature
Single commit
ocr delegate preview -c abc123
bash
ocr delegate preview [--from <ref> --to <ref>] [--commit <hash>] [--exclude <patterns>]
该命令输出:
  • 模式(工作区 / 范围 / 提交)
  • from / to / commit / merge_base — 用于构建git命令的引用元数据
  • 可审查文件列表 — 文件路径、状态、新增/删除行数
  • 排除文件 — 附带排除原因
常见调用方式:
场景命令
工作区变更
ocr delegate preview
分支对比
ocr delegate preview --from main --to feature
单个提交
ocr delegate preview -c abc123

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
undefined

Tracked files

已追踪文件

git diff HEAD -- <path>
git diff HEAD -- <path>

New untracked files — read directly (entire file is new code)

新的未追踪文件 — 直接读取(整个文件都是新增代码)

cat <path>
undefined
cat <path>
undefined

Step 4: Review Each File

步骤4:逐一审查文件

For each reviewable file:
  1. Get its diff (Step 3)
  2. Consult its Rule Group (from Step 2) for the review checklist
  3. Conduct a thorough review, using appropriate context tools as needed
对于每个可审查文件:
  1. 获取其差异内容(步骤3)
  2. 查阅其对应的规则组(步骤2)获取审查检查清单
  3. 进行全面审查,必要时使用合适的上下文工具

Step 5: Format Output

步骤5:格式化输出

Each comment must follow this structure:
FieldTypeRequiredDescription
pathstringyesRelative file path
contentstringyesReview comment describing the issue
start_lineintegernoStart line in the new file
end_lineintegernoEnd line in the new file
categoryenumnobug, security, performance, maintainability, test, style, documentation, other
severityenumnocritical, high, medium, low
每条评论必须遵循以下结构:
字段类型是否必填描述
pathstring相对文件路径
contentstring描述问题的审查评论
start_lineinteger新文件中的起始行
end_lineinteger新文件中的结束行
categoryenumbug、security、performance、maintainability、test、style、documentation、other
severityenumcritical、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

子命令参考

CommandPurpose
ocr delegate preview
Which files to review + mode/ref metadata
ocr delegate rule <path...>
Review rules grouped by content
命令用途
ocr delegate preview
确定待审查文件 + 模式/引用元数据
ocr delegate rule <path...>
按内容分组的审查规则

Shared Flags

共享标志

FlagDescription
--from <ref>
Source ref for range mode
--to <ref>
Target ref for range mode
-c, --commit <hash>
Single commit mode
--repo <path>
Repository root (default: cwd)
--rule <path>
Custom rule.json path
--exclude <patterns>
Comma-separated exclude patterns
-b, --background <text>
Business context
-B, --background-file <path>
Business context from Markdown file
标志描述
--from <ref>
范围模式的源引用
--to <ref>
范围模式的目标引用
-c, --commit <hash>
单个提交模式
--repo <path>
仓库根目录(默认:当前工作目录)
--rule <path>
自定义rule.json路径
--exclude <patterns>
逗号分隔的排除模式
-b, --background <text>
业务上下文
-B, --background-file <path>
来自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
    ocr delegate
    operates on the Git repo at the current directory. Use
    --repo /path
    to override.
  • Untracked files in workspace mode
    preview
    includes untracked files. For these, read the file directly instead of using
    git diff
    .
  • Background context — pass
    --background
    to
    preview
    when you have requirement context; it appears in the output for your reference during review.
  • OCR端无需LLM — 委托模式从不调用LLM。所有智能均来自宿主Agent。
  • 规则已分组 — 拥有相同规则的文件会在输出中归为一组。每次调用可传入任意数量的路径;对于大规模变更,可在审查时分批获取规则。
  • 工作目录很重要
    ocr delegate
    在当前目录的Git仓库上运行。使用
    --repo /path
    可覆盖默认路径。
  • 工作区模式中的未追踪文件
    preview
    会包含未追踪文件。对于这些文件,直接读取文件内容而非使用
    git diff
  • 背景上下文 — 当你有需求上下文时,可在
    preview
    中传入
    --background
    参数;它会显示在输出中,供你审查时参考。