Diffle 发布:支持 LSP 的键盘驱动代码差异审查工具,可一键将评论转为 AI Agent 提示词或 GitHub 待审请求

原标题:Show HN: Diffle, a keyboard-centric diff viewer with LSP support
48AI 研判分

开发者 Moritz Wilksch 推出开源工具 Diffle,这是一款基于浏览器的 Git 差异查看器,主打全键盘操作与语言服务器协议(LSP)集成。其核心创新在于工作流闭环:用户可在浏览器中直接对代码行、块或文件添加评论,并一键将这些结构化反馈转化为 AI Agent 的上下文提示词,或同步为 GitHub 的待处理审查请求。该工具提供 npm、conda-forge 及独立二进制等多种安装方式,旨在提升代码审查效率并桥接人工审查与自动化智能体协作。

报道正文

本文目录7 个章节

Review a Git diff in the browser and comment on lines, blocks, or whole files. Then hand the comments to an agent as a prompt, or to GitHub as a pending review.

<picture> <source media="(prefers-color-scheme: dark)" srcset=".github/assets/diffle-dark.png"> <source media="(prefers-color-scheme: light)" srcset=".github/assets/diffle-light.png"> <img alt="diffle reviewing a git diff" src=".github/assets/diffle-light.png"> </picture>

Install

BASH
pixi global install diffle               # conda-forge
npm install -g @moritzwilksch/diffle     # npm

Or grab the standalone binary, which needs no Node.js. On Linux (x64, arm64, glibc) and Apple silicon macOS:

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

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

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

To try it without installing:

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

The Nix package bundles gh; #minimal drops it, and #web, #rust, and #python bundle language servers.

Pick what to review

BASH
diffle                  # HEAD vs worktree, like a bare `git diff`
diffle working          # HEAD vs worktree: staged, unstaged, untracked
diffle develop          # what this branch added since it left develop
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.

Review

  • j / k: next or previous line (10j: ten lines down)
  • J / K: next or previous file
  • ] / [: next or previous hunk
  • c: comment
  • C: comment on the whole file
  • V: select a block
  • R: resolve
  • v: mark viewed
  • /: search the current file
  • g/: search all changed files
  • gf: filter files
  • F: open the full file
  • Ctrl+o: go back
  • yy: copy all comments

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.

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.

Jump to definitions

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

  • gd or Ctrl/Cmd+click: definition
  • gy: type definition
  • gA: references
  • gs / gS: file or repository symbols
  • gh: hover, including schema docs for JSON, YAML, and TOML
  • w / b / 0 / $: step through a line's symbols; the one under the cursor or the pointer is tinted wherever it recurs in the file, writes apart from reads

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

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:

BASH
diffle config set-lsp rust "rust-analyzer"       # persistent
diffle config set-lsp java ""                    # never start one for java
diffle config unset-lsp rust                     # back to PATH
diffle working --lsp python="pyrefly lsp"        # this run only
diffle working --no-lsp                          # none at all

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

Shell completions

BASH
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:

BASH
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.

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)