difit-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Difit Review

Difit 审查

Overview

概述

This skill launches a requested git diff in a viewer that is easy for humans to read. At the same time, the agent can attach arbitrary comments via the
--comment
option. This comment mechanism is well suited for code review findings and code explanations. Before running commands, choose
<difit-command>
using the following rule:
  • If
    command -v difit
    succeeds, use
    difit
    .
  • Otherwise, use
    npx difit
    .
  • If falling back to
    npx difit
    would require network access in a sandboxed environment without network permission, request escalated permissions and user approval before running it.
该Skill会在一款易于人类阅读的查看器中启动指定的git diff,同时Agent可通过
--comment
参数添加任意评论。 这种评论机制非常适合用于代码审查结果和代码解释的展示。 在运行命令前,请根据以下规则选择
<difit-command>
  • command -v difit
    执行成功,则使用
    difit
  • 否则,使用
    npx difit
  • 若在无网络权限的沙箱环境中回退到
    npx difit
    需要网络访问,请先申请提升权限并获得用户批准后再运行。

Steps

步骤

The final command typically looks like this:
bash
<difit-command> <target> [compare-with] \
  --comment '{"type":"thread","filePath":"src/foobar.ts","position":{"side":"old","line":102},"body":"line 1\nline 2"}' \
  --comment '{"type":"thread","filePath":"src/example.ts","position":{"side":"new","line":{"start":36,"end":39}},"body":"Range comment for L36-L39"}'
The detailed procedure is as follows.
  1. Identify the target diff and review its contents.
  • Inspect the diff specified by the user. This may be a local git revision, a GitHub URL, a patch file, or something similar.
  • Understand the diff normally, inspect surrounding code when needed, and think through the response required by the user's request, whether that is review findings, explanations, or something else.
  • For PR reviews, inspect the PR locally and keep the review result limited to difit output. Do not post comments back to remote GitHub.
  1. Attach the prepared comments and launch difit.
  • difit launch options
    • Use
      <difit-command> <target> [compare-with]
      to specify the target diff.
    • For uncommitted changes use
      <difit-command> .
      , for working tree changes use
      <difit-command> working
      , and for staged changes use
      <difit-command> staging
      .
    • For PRs use
      <difit-command> --pr <URL>
      . For stdin input, use a form such as
      diff -u file1.txt file2.txt | <difit-command>
      .
  • Comment arguments
    • Use
      type: "thread"
      for each comment.
    • Write comment bodies in the language the user is using.
    • Use
      position.side: "new"
      for lines that exist on the target side of the diff.
    • Use
      position.side: "old"
      for lines that exist only on the deleted side.
    • Use range comments for issues that span multiple lines.
  • Additional argument for files not yet added to git
    • For uncommitted changes, if you decide files not yet added to git should also appear in the diff, add
      --include-untracked
      .
  1. Share the difit URL and finish the response.
    • If there were no comments to attach, explicitly say so.
    • No manual verification of the launched difit page is required.
最终命令通常如下所示:
bash
<difit-command> <target> [compare-with] \
  --comment '{"type":"thread","filePath":"src/foobar.ts","position":{"side":"old","line":102},"body":"line 1\nline 2"}' \
  --comment '{"type":"thread","filePath":"src/example.ts","position":{"side":"new","line":{"start":36,"end":39}},"body":"Range comment for L36-L39"}'
详细流程如下:
  1. 确定目标diff并审查其内容。
  • 检查用户指定的diff,这可能是本地git版本、GitHub URL、补丁文件或类似内容。
  • 常规理解diff内容,必要时查看周边代码,思考用户请求所需的回应,无论是审查结果、代码解释还是其他内容。
  • 对于PR审查,请在本地检查PR,并将审查结果限定在difit输出中,不要将评论发布到远程GitHub。
  1. 添加准备好的评论并启动difit。
  • difit启动选项
    • 使用
      <difit-command> <target> [compare-with]
      指定目标diff。
    • 对于未提交的变更,使用
      <difit-command> .
      ;对于工作区变更,使用
      <difit-command> working
      ;对于暂存区变更,使用
      <difit-command> staging
    • 对于PR,使用
      <difit-command> --pr <URL>
      。对于标准输入,可使用类似
      diff -u file1.txt file2.txt | <difit-command>
      的形式。
  • 评论参数
    • 每条评论使用
      type: "thread"
    • 评论正文使用用户所使用的语言编写。
    • 对于diff目标侧存在的行,使用
      position.side: "new"
    • 对于仅在删除侧存在的行,使用
      position.side: "old"
    • 对于跨多行的问题,使用范围评论。
  • 针对未添加到git的文件的额外参数
    • 对于未提交的变更,若你认为未被git追踪的文件也应出现在diff中,请添加
      --include-untracked
      参数。
  1. 分享difit URL并完成回应。
    • 若没有需要添加的评论,请明确说明。
    • 无需手动验证已启动的difit页面。