diffle README

项目的 README,来自 github.com/moritzwilksch/diffle。合并为一个 markdown 文件:README.md。

diffle

CI conda-forge npm crates.io homebrew website

Review a Git diff in the browser and comment on lines, blocks, or whole files. Then hand the comments to an agent, which replies right in the thread, or to GitHub as a pending review. Or let the agent walk you through the change first, with a tour.

A review in diffle: a language-server hover, its references, a jump to one and a comment there, the agent's reply, then yy copies the comments as one prompt

Install

brew install diffle                      # Homebrew
pixi global install diffle               # conda-forge
npm install -g @moritzwilksch/diffle     # npm
cargo binstall diffle                    # crates.io, the release binary
cargo install diffle                     # crates.io, compiled from source

Or grab the standalone binary. On Linux (x64, arm64, glibc) and Apple silicon macOS:

curl -fsSL https://diffle.app/install.sh | sh

It installs to ~/.local/bin. Set DIFFLE_INSTALL_DIR to change that, or DIFFLE_VERSION=v0.4.0 to pin a release. On Windows (x64, arm64), from PowerShell:

irm https://diffle.app/install.ps1 | iex

It installs to %LOCALAPPDATA%\Programs\diffle and adds that to your user PATH; set DIFFLE_NO_MODIFY_PATH to keep the PATH as it is.

To try it without installing:

npx @moritzwilksch/diffle working
pixi exec diffle working
nix run github:moritzwilksch/diffle -- working

The Nix package bundles gh; #minimal drops it, and #web, #rust, #python, #csharp, #docker, and #helm bundle language servers. Every package takes more with withLsps, and #unwrapped is the bare binary:

diffle.packages.${system}.default.withLsps [ pkgs.gopls pkgs.clang-tools ]

To build from source, pixi builds the checkout with recipe/recipe.yaml (a Rust toolchain and Node.js come from conda-forge):

pixi global install --git https://github.com/moritzwilksch/diffle diffle

Pick what to review

diffle                  # HEAD vs worktree, like a bare `git diff`
diffle working          # HEAD vs worktree: staged, unstaged, untracked
diffle develop          # what this branch adds since it left develop, uncommitted included
diffle pr 27            # GitHub PR 27, or its URL; without a number, this branch's PR
diffle show a1b2c3d     # one commit, like `git show`
diffle main..feat       # any git-diff revspec: <rev> | a..b | a...b | a b
diffle main..worktree   # "worktree" names the uncommitted tree on either side
diffle range-diff main..v1 main..v2   # how a series of commits was reworked, like `git range-diff`
diffle --help           # all commands and flags

diffle pr needs a GitHub token. A PR from another repository opens in a temporary clone.

Closing the last diffle tab stops the server and prints your open comments. Pass --keep-alive to keep it running. One diffle runs per worktree: a second start in the same worktree exits with the running one's URL.

Review

Press ? for the full list.

A comparison lists its commits above the threads. Pick one, or step with < and >, to see that commit alone; All changes returns to the whole range. Comments on a focused commit belong to that commit, as in diffle show.

Comments live in <git-dir>/diffle/ and never touch your worktree. They follow their text as the code changes and go stale once it leaves the diff.

Generated files start collapsed, as on GitHub: linguist-generated in .gitattributes marks them, and linguist-generated=false opts a file out. To collapse other files, add auto-viewed globs in settings or with diffle config.

Take a tour of the change

Before you review your agent's change, let it walk you through it. It writes a tour: one page beside the diff that explains the change in a sensible order, shows the lines it talks about, and ends with the questions you need to decide. You know what you're looking at before you open the diff.

A tour in diffle: a diagram and a walk stepped with l, a symbol's references, a comment on the tour's words, a trace and tabs, then a checklist ticked and answered

Install the skill once, and your agent knows how to write a tour:

mkdir -p ~/.claude/skills/diffle
diffle skill > ~/.claude/skills/diffle/SKILL.md

Then ask it for one. diffle opens the tour as soon as it's pushed, and T toggles it:

Your comments on the tour reach the agent like any other comment, so you can ask "why?" right where the question comes up. Each review keeps its own tour. Export saves it as one HTML file that opens offline, to share with your team.

Send comments to GitHub

The pull request icon adds one thread, or all open threads, to a pending review on the PR. diffle never submits it: you edit, drop, and submit the comments on GitHub yourself. Adding a thread again updates its comment instead of duplicating it.

Export works when the comparison matches the PR's committed diff, so unpushed commits and worktree changes rule it out. Stale threads are skipped.

diffle takes the token from GITHUB_TOKEN, then GH_TOKEN, then a signed-in gh. Without one, everything except GitHub still works. GITHUB_API_URL points diffle at another GitHub API, as in Actions.

For GitHub Enterprise Server, add its host to githubHosts in the config file (diffle config prints its path). Each entry maps the host in remote URLs to the host serving the web UI and API, the same one unless remotes use another, as an SSH-only host might:

{
  "githubHosts": {
    "github.work.com": "github.work.com",
    "ssh.work.com": "github.work.com"
  }
}

A run talks to one GitHub: the pull request URL's, else origin's, else the one all GitHub remotes share. The token then comes from GITHUB_ENTERPRISE_TOKEN, GH_ENTERPRISE_TOKEN, or gh auth login --hostname <host>.

Jump to definitions

diffle starts a language server for each language in the diff, if it finds one on PATH:

Results outside the diff, such as the standard library, open read-only. Large repositories can take a while to index.

A Helm chart's templates (the YAML and .tpl files under the templates/ beside its Chart.yaml) get helm-ls instead of the YAML server; values.yaml and Chart.yaml stay YAML. helm-ls passes the templates' YAML on to yaml-language-server when that is on PATH too.

diffle lsp shows which server each language gets and what to install for the rest:

python    pyrefly lsp
rust      not on PATH (tried rust-analyzer)

Override a server or turn one off for a run:

diffle working --lsp python="pyrefly lsp"        # this run only
diffle working --no-lsp                          # none at all

Or persistently, in the config file (diffle config prints its path and contents):

{ "lspCommands": { "rust": "rust-analyzer", "java": "" } }

Language servers run inside the repository and can read anything your user can. --no-lsp starts none.

See the change as a graph

Press M to swap the diff for a graph of what changed: one box per file, or per symbol with s, and an arrow wherever one uses another. d adds the unchanged code that uses the change, T the tests.

The change graph in diffle: files, then symbols, a function's links in the side panel, a peek at the lines behind them, then a pan to two linked symbols

Click a box to list what it uses and what uses it in the side panel; Peek steps through the lines behind those links without leaving the graph. A card in the panel, or a double-click on a box, frames that box with its neighbours. Enter opens the selection in the diff, and M returns to the graph as you left it.

The graph needs the language servers, the same ones Jump to definitions uses.

Work with a coding agent

A coding agent in the same repository talks to the diffle running there:

diffle comments list            # the threads you are shown, as JSON
diffle comments reply <id> -    # answer a thread in Markdown; - reads stdin
diffle tour push tour.html      # show a guided tour of the change; stdin without a file
diffle tour clear               # remove it
diffle tour export tour.html    # save it as one HTML file that opens offline; - for stdout

Ask your agent to look at your comments: it reads the threads, makes the changes, and replies in each one. The replies show up in your open review, marked as the agent's.

See Take a tour of the change for what a tour shows.

diffle skill prints all of this for the agent, the tour's elements included, as a skill to install as is: save it as SKILL.md in a diffle folder among your agent's skills, such as ~/.claude/skills/diffle/. --no-frontmatter leaves out its name and description.

Open from lazygit

lazygit custom commands open diffle on what is selected. Add them to its config.yml (lazygit --print-config-dir prints the folder):

customCommands:
  - key: '<c-d>'
    context: 'files'
    command: 'diffle working'
    output: terminal
    description: 'Review uncommitted changes in diffle'
  - key: '<c-d>'
    context: 'commits'
    command: 'diffle {{.SelectedCommitRange.From}}^..{{.SelectedCommitRange.To}}'
    output: terminal
    description: 'Review the selected commits in diffle'
  - key: '<c-d>'
    context: 'localBranches'
    command: 'diffle main...{{.SelectedLocalBranch.Name}}'
    output: terminal
    description: 'Review the branch against main in diffle'

lazygit waits while you review; closing the tab returns to it with the open comments printed as a prompt. Append | pbcopy (or your clipboard tool) to a command to copy them instead.

Shell completions

diffle completion --shell bash > ~/.local/share/bash-completion/completions/diffle
diffle completion --shell zsh > ~/.local/share/zsh/site-functions/_diffle   # on fpath, before compinit
diffle completion --shell fish > ~/.config/fish/completions/diffle.fish

Rerun after upgrading to pick up new commands. Revisions don't complete.

Behind a reverse proxy

diffle works under a path prefix such as https://proxy.example/diffle/ with no extra setting. Have the proxy strip the prefix, including for WebSocket upgrades at /diffle/ws, and trust its public origin:

diffle working -H 0.0.0.0 --no-open --allowed-origin https://proxy.example

If the proxy rewrites Host and Origin to its upstream address, such as a Kubernetes service name, trust that address instead. A rejected request gets a 403 naming the header that failed.

On a remote machine

Serve on a Unix socket that only you can connect to, and forward it over SSH:

diffle working --socket /home/me/diffle.sock          # on the remote machine
ssh -N -L 4966:/home/me/diffle.sock remote            # here, then open http://localhost:4966

No browser opens on the remote machine. Closing the last tab connected through the socket stops diffle there and prints your open comments, as on your own machine. --socket needs macOS or Linux, and the forward needs OpenSSH 6.7 or later.

Development

The server is Rust (crates/diffle), the client TypeScript; you need a Rust toolchain (rust-toolchain.toml pins it) and Node.js.

pixi installs the toolchain, git, gh and lefthook from pixi.lock, and its tasks are the entry points, locally and in CI. npm builds and tests the client; cargo builds and tests the server, whose release build embeds the client.

pixi run diffle working                   # build the client, then serve the working tree
pixi run test-node && pixi run test-rust  # the client's and the server's suites
pixi run lefthook-run                     # the pre-commit hook over every file, as CI runs it
pixi run build-release                    # the release binary
pixi run diffle lsp                       # the language servers the environment resolves

The environment puts real language servers on PATH, so pixi run diffle working reviews with them. pixi run lefthook-install wires up the pre-commit hook (.lefthook.yml): it formats and lints the staged files, typechecks, and checks file-size and folder limits across the whole tree. pixi run lefthook-run runs the same hook over every file, as CI does. A debug build reads crates/diffle/client from disk: after a client change, run npm run build and reload the page. A release build (cargo build --release) embeds the client. npm run fixture -- <dir> builds the repository the tests review, covering renames, binaries, CRLF, and more. The browser suite drives Playwright's Linux Chromium in a Docker container (compose.yml, started and stopped by the suite) while the tests and the release binary run natively, so screenshots match CI on every host:

pixi run e2e                              # the browser suite, after the release build
pixi run e2e -g search                    # matching scenarios
pixi run e2e-report                       # open the last report
pixi run e2e --update-snapshots           # accept new screenshots

See AGENTS.md for more.

Acknowledgements

diffle is inspired by difit. Diffs are rendered with @pierre/diffs.

diffle (moritzwilksch/diffle)

正在搜索数据库…

这是什么?Diffle 是一个以键盘操作为主的 diff 查看器,它会在浏览器中打开 Git diff,让你对某一行、某个代码块或整个文件发表评论,然后把这些评论作为提示词交给 AI 代理,或者作为待提交的评审推送到 GitHub。
这是一个浏览器应用,还是一个会打开浏览器的命令行工具?它是一个命令行工具:你运行 diffle 命令后,它会启动一个本地服务器,并在浏览器的标签页中打开 diff。关闭最后一个标签页时,服务器也会随之关闭。
我怎么安装 diffle?下载独立的二进制文件即可,不需要 Node.js:Linux(x64/arm64,glibc)和 Apple 芯片的 macOS 有安装脚本,Windows(x64/arm64)有 PowerShell 命令。另外还提供 Nix 软件包,你也可以先试用再安装。
我的评论总是能直接推送到 GitHub 吗?不能,只有当你本地的对比结果与 PR 中已提交的 diff 完全一致时才能导出,所以未推送的提交或工作区的改动都会阻止导出,过期的评论话题则会被跳过。
我的评审评论会被写进项目的文件里吗?不会,评论是单独存储的,绝不会改动你的工作区;它们只是跟随匹配的文本随代码变动,一旦该文本离开 diff,评论就会过期。
它用什么键盘快捷键来导航?Vim 风格的按键:j/k 在行之间移动(10j 表示移动十行),J/K 切换文件,c/C 对某一行或整个文件发表评论,V 选中一个代码块,R 解决一个话题,v 把文件标记为已查看,/ 或 g/ 分别在文件内或跨文件搜索。
评审时能跳转到某个符号的定义吗?可以,diffle 会为它在 PATH 中找到的每种语言启动语言服务器,支持 gd 跳转到定义,gA 查看引用,gs/gS 查找符号,gh 查看悬停信息,其中包括 JSON/YAML/TOML 的 schema 文档。
diffle 的灵感来自哪里,diff 是用什么渲染的?Diffle 的灵感来自工具 'difit',diff 本身则是用 @pierre/diffs 库渲染的。
可以把 diffle 放在反向代理后面运行吗?可以,在路径前缀下无需任何额外配置即可使用,只要代理会剥离该前缀(包括针对 /diffle/ws 的 WebSocket 升级请求),并且信任自己的公网来源即可;来源不匹配的请求会收到 403 而被拒绝。
大小
222 MB
星标
203
时长
2个月
提交 · 90 天