✨ feat(pr-autocreate): the PR watcher opens a branch carrying another slice's work as a draft

Merged
AT
2d ago
+148-17

Slice: #589

The PR watcher (niyam pr-autocreate) now opens a draft, not a ready pull
request, when the branch's own commits name no slice or more than one in
their Slice: trailers. That covers a branch stacked on a peer's, or one
carrying a peer's work. Its own commits are every one ahead of the base, the
range the placeholder lists (its list stops at 50). A branch whose commits name exactly one slice
opens as the settings say, as before.

Why. athya-rules docs/lessons/push-and-prepush.md#the-pr-the-push-opens
(read 2026-11-24 at 1d3ffa1, lesson pr-watcher-hold-peer-work): a branch
carrying a peer's work had to be put back to draft by hand at once, or
Mergify could merge the peer's unreviewed work. Before this change,
ensurePr opened a ready pull request for any branch without one unless
prAutocreate.draft was set. Work rules fails the placeholder, but once the
session writes the body with its own Slice: line, the peer's commits merge
with it. Per decision D2 on #394, the watcher's draft holds the peer's work;
there is no new Work rules refusal.

What changed (src/pr-autocreate.ts):

  • ownSlices reads the Slice: trailers of the commits ahead of the base
    (git log --no-merges over the placeholder's own range), with
    slicesNamed from work.ts. heldBy says why a branch is held, or
    nothing for exactly one slice.
  • ensurePr opens a draft when it is held (settings.draft || held). If
    git cannot read the log, the result names no slice, so it fails toward a
    draft.
  • The placeholder body gains a line, only when the branch is held: which
    slices the commits name, and that the session marks it ready with
    gh pr ready once its description is written. It still has no Slice:
    line, so Work rules still fails it.
  • The session's note says PR #N was opened as a draft: … mark it ready with gh pr ready N. It goes with the Autofix instruction, at a push or at
    Stop, and is said once. The watch log line says it too. Before this, a
    note was said only when there was no instruction, and the watcher logged
    notes only when it opened no PR.
  • spawn-watchers' line now reads "a ready PR opens, or a draft where its
    own commits name no slice or more than one, once the push lands". It
    cannot know at pre-push which one will open.
  • README: the watcher's paragraph says all this.

Cost:

  • A branch whose commits carry no trailer opens as a draft, and its session
    marks it ready.
  • gh pr ready needs GraphQL, which a Claude cloud session's proxy refuses.
    There, the note says to ask the user to mark it ready.

Evidence:

  • pnpm check (the full gate): exit 0. 2196 pass, 0 fail, coverage
    99.57% lines and 97.28% branches; test:scripts 138 pass, 0 fail. The
    first run had one failure in cubic-dismiss.test.ts, a file this PR
    does not touch: ENOTEMPTY cleaning a temp dir. The rerun passed.
  • src/pr-autocreate.test.ts, new tests:
    • one slice opens ready: test (4), whose fixture commit now carries
      Slice: #7;
    • two slices (#7, #8) open a draft, named in the body, the note and the
      watch log;
    • no slice opens a draft;
    • a slice the base already has (#3) does not count, so the branch's one
      slice (#9) opens ready;
    • Stop says the note with the instruction;
    • a cloud session is told to ask the user;
    • draft: true with one slice opens a draft and says nothing of holding;
    • when git cannot read the log, it opens a draft.

Not a release; the coordinator releases once #394's slices merge.

🤖 Generated with Claude Code