jjack:一个 CLI 和 TypeScript 库,帮助 jj 用户在 GitHub 上管理 PR 堆栈
jjack: A CLI and TypeScript library to help jj users manage PR stacks on GitHub

原始链接: https://github.com/david-crespo/jjack

jjack 是一个 CLI 和 TypeScript 库,帮助 jj 用户管理 GitHub PR 堆栈,灵感来自 jj-spr。它通过将变更投影为合并提交来解决强推/审查问题,使现有提交保持不变。需要 Node 24+、jj、git,以及 gh 或 token。通过 jj config 配置(回退到 jj-spr 键)。PR 来自堆栈文件或 `-r rev`。命令包括 init、status、adopt、submit、land、sync、close,并支持 `--json` 输出。它导出类型化函数、上下文辅助函数和 JjackError 供库使用。测试针对进程内假 GitHub 运行。该项目是 vibe-coded,公开的主要目的是支持另一个仓库。

Hacker News 讨论了 jjack,一个用于在 GitHub 上管理 jj PR 栈的 CLI 和 TypeScript 库。评论者分享了替代方案:jjpr 支持多个 Git 托管平台和钻石形栈,而 jj-gh 将 PR 摘要同步到提交并重新挂载被打乱的 PR。对工作流的看法不同:一位维护者更喜欢将栈保持在本地并合并到 main,以避免让审阅者困惑;另一位指出 jj 的 megamerge 模型可能无法干净映射到线性堆叠 PR;还有人说采用 jj 后堆叠 PR 变得更自然。
相关文章

原文

jjack is a CLI and TypeScript library to help jj users manage PR stacks on GitHub.

It started as a very stripped-down TS port of @papertigers's native-stacks branch of jj-spr (which in turn comes from spr), but at this point it's fairly different in implementation. See THIRD_PARTY_NOTICES.md for attribution and licenses.

Because jjack is built narrowly around how I want to work, I don't expect anyone else to want to use it, but you might take it as inspiration when building your own stack tool. This repo is public mostly because my other public repo ah depends on it for its stack management GUI, and I want anyone interested in that to be able to see all the pieces.

This was entirely vibe-coded with a variety of frontier models. I have not read any of the code and do not plan to. Despite that (or because of it), the tool and the GitHub test fake are pretty well-validated against actual GitHub behavior.

If you're looking for a stack tool to actually use yourself, you'll probably want one of these instead:

See docs/comparison.md for details on how jjack differs from them.

The problem with stacks on GitHub

A big problem for jj users trying to use stacks on GitHub is that if you do things naively, every time you change a PR lower in the stack, whether by editing a commit or adding a new one, later PRs get rebased and force pushed. This results in a very poor reviewing experience in GitHub because the reviewer cannot easily tell what changed between pushes. The jj-spr approach is to treat what gets pushed to GitHub as a sort of generated projection of the "real" change you have in jj locally, taking what is intuitive for you and turning it into something entirely different that displays well on GitHub. In practice what that means is merge commits.

How jjack does it (which is also how jj-spr does it)

Say you have a stack of three PRs, A, B, and C, and the bottom one has three changes:

%%{init: {"gitGraph": {"mainBranchName": "A", "rotateCommitLabel": false}}}%%
gitGraph
  commit id: "A1"
  commit id: "A2"
  commit id: "A3"
  branch B
  commit id: "B1"
  branch C
  commit id: "C1"
Loading

You make a change to A2 locally:

%%{init: {"gitGraph": {"mainBranchName": "A", "rotateCommitLabel": false}}}%%
gitGraph
  commit id: "A1"
  commit id: "A2'" type: HIGHLIGHT
  commit id: "A3"
  branch B
  commit id: "B1"
  branch C
  commit id: "C1"
Loading

From git's point of view, everything from A2' on is brand new, so if you were to push the branches for A, B, and C directly, those are force pushes. What jj spr diff and jjack submit do here instead is maintain a second representation of the change that preserves all the existing commits, turning your change to A2 above into this:

%%{init: {"gitGraph": {"mainBranchName": "A", "rotateCommitLabel": false}}}%%
gitGraph
  commit id: "A1"
  commit id: "A2"
  commit id: "A3"
  branch B
  commit id: "B1"
  branch C
  commit id: "C1"
  checkout A
  commit id: "U"
  checkout B
  merge A id: "MB"
  checkout C
  merge B id: "MC"
Loading

U is an ordinary commit on top of A's branch that contains your edit. MB is a merge commit on B's branch with parents B1 and U. MC is a merge commit on C's branch with parents C1 and MB. Every commit that was already on GitHub is untouched, so each PR shows the update as new commits on top of what reviewers have already seen.

This is Git and GitHub's fault

The only reason all this is necessary is that Git doesn't have a good canonical spot to put the information necessary to make this work well, and GitHub does not know how to display stacks and the changes between them properly. They're stuck in a very tough spot because the vast majority of their users are not using jj, but their most savvy users want functionality like this.

We want interdiff!

Requires Node 24 or later, jj, and git. It also needs gh unless you pass --token or set jjack.token. From a checkout of this repository:

npm install && npm run build && npm install --global .

jjack reads jj config and falls back to the jj-spr keys, so a repository already set up for jj-spr works without changes.

Key Falls back to Default
jjack.branchPrefix spr.branchPrefix none (required; e.g., yourname/)
jjack.repository spr.githubRepository from the remote's URL (owner/repo)
jjack.remote spr.githubRemoteName origin
jjack.mainBranch spr.githubMasterBranch the remote's bookmark at jj's trunk(), or main
jjack.requireApproval spr.requireApproval false
jjack.token spr.githubAuthToken the output of gh auth token
jjack.apiUrl spr.githubApiUrl https://api.github.com
jj config set --repo jjack.branchPrefix yourname/

--branch-prefix, --repository, and --token override these for a single run.

submit, land, sync, and close take their PRs from one of two sources:

  • A stack file (JSON) listing one entry per PR, from the bottom of the stack up. Each entry has a tip (a bookmark or change ID) and covers every change from the previous tip (or main) up to it. Set title directly, or set body to a markdown path relative to the stack file: a leading # heading becomes the title (falling back to title if absent), and the rest becomes the PR body. Keep stack files outside the repo or in an ignored directory, since jjack updates them with PR metadata and jj snapshots unignored files.

    {
      "prs": [
        { "tip": "routes", "body": "routes.md" },
        { "tip": "kxqzwmvtnlop", "title": "Document the handlers" }
      ]
    }
  • -r <rev>, where each change from main up to <rev> becomes its own PR, titled with the first line of its description. jjack appends a Pull Request: <url> line to each change's description.

  • jjack init <file> --tips <revset> — write a stack file with one entry per tip, in stack order.
  • jjack status <file> — check a stack file, showing what submit would do and any problems that would block it.
  • jjack adopt <file> — take over open PRs pushed without jjack whose branch names match the entries' bookmarks.
  • jjack submit <file | -r rev> — open or update PRs and register them through GitHub's native stacks API (--upto <tip>, -m <message>, --dry-run).
  • jjack land <file | -r rev> — squash-merge PRs starting from the bottom of the stack, then run sync (--upto <tip>, --no-sync).
  • jjack sync <file | -r rev> — abandon changes whose PRs merged, rebase the rest onto main, and mark merged entries (--dry-run).
  • jjack close <file | -r rev> — close PRs (--pr <tip> or --all) and delete their branches.

Pass --json to any command to get a single JSON document on stdout (with logs on stderr). Run jjack <command> --help for all flags.

If you use a coding agent, point it at skills/jjack/SKILL.md.

src/index.ts exports one function per command (submit, land, sync, etc.), context helpers (openContext, openLocalContext, resolveStack), captureOut, JjackError, and their types. Each function returns the same typed result as --json and throws JjackError on error.

Because the entry point is TypeScript source (run directly by Node 24, which disables type stripping inside node_modules), depend on jjack by local path:

{ "dependencies": { "jjack": "file:../jjack" } }
import { captureOut, JjackError, land, openContext, submit } from "jjack"

const out = captureOut()
const ctx = await openContext("/path/to/workspace", { out })
const stack = { file: "/path/to/stack.json" }

const plan = await submit(ctx, stack, { dryRun: true })
for (const pr of plan.pullRequests) console.log(pr.label, pr.action, pr.number ?? "new")

try {
  const landed = await land(ctx, stack)
  console.log(landed.landed, landed.sync?.abandoned)
} catch (e) {
  if (!(e instanceof JjackError)) throw e
  console.log(e.code, e.fix, e.partial)
}

For local-only reads without GitHub or a token (such as redrawing a UI on every jj operation), use openLocalContext(cwd) with resolveStack(ctx, path).

npm run ci   # typecheck, lint, format check, and tests

The tests run against test/fake_github.ts, an in-process fake of GitHub's REST and native stacks APIs backed by a bare git repo. The fake is ported from jj-spr's Rust fake GitHub (mostly Mike Zeller's, on the native-stacks branch of papertigers/jj-spr), whose stack rules follow bos/jj-stack's fake. test/env.ts and the scenario tests are ports of jj-spr's tests.

联系我们 contact @ memedata.com