Skip to content

Add an interactive submit TUI for customizing each PR's title, description, and draft state#147

Draft
skarim wants to merge 6 commits into
skarim/shared-headerfrom
skarim/submit-tui
Draft

Add an interactive submit TUI for customizing each PR's title, description, and draft state#147
skarim wants to merge 6 commits into
skarim/shared-headerfrom
skarim/submit-tui

Conversation

@skarim

@skarim skarim commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Previously, gh stack submit only let you customize each PR's title. The description was either left blank or filled from a default template, and there was no way to choose, per PR, whether to open it as a draft. That made it awkward to submit a well-described stack — you'd typically create the PRs and then edit each one on GitHub afterward.

This PR adds a fully interactive TUI to gh stack submit so you can customize each PR's details — title, description (with a live markdown preview), and ready/draft state — and choose which branches become PRs, all before anything is created. Overall it's a much smoother experience for submitting and creating a stack of PRs.

image

What's new

Running gh stack submit now opens a single-screen, keyboard- and mouse-driven TUI:

  • Left panel — stack timeline. A vertical, git-graph-style view of the stack. Each branch is a node on a spine down to the trunk:
    • ● cyan — will be created as a PR
    • ◌ gray (dotted) — skipped
    • ○ state-colored ring — already has a PR (open/draft/queued/merged), with its state · #num shown below the name
    • Per-branch include checkbox, full branch names (wrapped, never truncated), focus shading, and vertical scrolling when the stack is tall.
  • Right panel — PR editor. For the focused branch you can edit the title and description, toggle the description between edit and markdown preview, and pick CREATE AS [ Ready | Draft ]. Branches that already have a PR render as a read-only card (title + scrollable rendered-markdown description + an "↗ Open on GitHub" link).
  • Submit flow. Toggle which branches become PRs (with dependency cascade), and a bottom-right action that shows NEXT BRANCH while moving through the stack and a prominent SUBMIT N PRs button on the last PR. A non-empty title is required before submitting.
  • Input. Full keyboard support — arrows / tab (cycle fields & PRs), ^x skip/include, ^p preview, ^e $EDITOR, ^o open existing PR, ^s submit, ^h / ? help, esc / q quit — plus mouse support (click rows, checkboxes, toggles, fields, links, and the footer buttons; wheel scrolling in both panels).
  • Help overlay (^h works even while editing a field) listing the full keyboard + mouse reference.

The header (art, title, stack info lines, shortcut list) is shared with gh stack view / gh stack modify (introduced in the base PR, #143) for a consistent look.

How to review

The change is split into three commits to make review easier:

  1. Add submitview data model and PR draft override plumbing — the data model (SubmitNode, branch state, title/description prefill, prefix helpers in internal/tui/submitview/{types,data}.go) and the plumbing in cmd/submit.go to carry a per-PR ready/draft override through to PR creation. No UI yet.
  2. Add single-screen submit TUI — the Bubble Tea screen in internal/tui/submitview/ (layout/rendering, the left timeline + right editor, mouse handling, markdown preview, help overlay, styles), with thorough unit tests.
  3. Wire the single-screen submit TUI into gh stack submit — replaces the old prompt flow in cmd/submit.go with the TUI and updates the docs/README.

git diff is large (~5k lines) but is mostly the self-contained internal/tui/submitview package plus its tests; cmd/submit.go is the main integration point.

Testing

  • New unit tests across internal/tui/submitview/*_test.go covering rendering, navigation/field cycling, the include cascade, mouse click/scroll hit-targets, markdown preview, the help overlay, and the footer actions, plus cmd/submit_tui_test.go for the command integration.
  • go test ./... passes; go vet and gofmt are clean; each of the three commits builds independently.

skarim added 3 commits June 24, 2026 13:03
Introduce the internal/tui/submitview package that will back the new
interactive `gh stack submit` TUI, and wire its per-PR override contract
into the submit command without changing current behavior.

- submitview: BranchState model (NEW/OPEN/DRAFT/QUEUED/MERGED/CLOSED) with
  selectability/editability rules, SubmitNode UI state with edit detection,
  PRDraft override type, state derivation, title/description prefill, and
  state-badge/panel/tab styles.
- submit: refactor ensurePR/createPR to accept an optional per-branch
  override map (title/body/draft/include); deselected NEW branches are
  pushed but get no PR.

The override map is nil on the --auto / non-interactive path, so the
agent-compat contract is unchanged. Fully unit tested.
Introduce an interactive, single-screen editor for `gh stack submit`,
built on Bubble Tea and Lip Gloss.

The left panel renders the stack as a connected tree down to the trunk.
Every branch without a PR is included by default; deselect one with its
checkbox or `^x`. Because each PR builds on the branch below it,
deselecting a branch also deselects the ones stacked above it, and
re-including a branch re-includes the ones below it that it depends on.
The cursor uses its own cyan accent so it reads distinctly from the green
new/included color; existing PRs are shown dimmed with a no-entry glyph.

The right panel edits the focused branch's PR in web-create-PR order: a
header with the branch name and an include chip ("Creating PR" /
"Skipped"), the title, a scrollable description (Glamour markdown preview
and $EDITOR escape, with a scrollbar and mouse click-to-position), and a
ready to draft segmented toggle (defaulting to ready). A footer strip
shows the PR progress, the next branch, and the editor hints. Skipping a
branch dims its body; branches that already have a PR show a read-only
card linking to the PR.

It shares the gh-stack header (art, title, stack info, and keyboard
shortcuts) with `gh stack view` and `gh stack modify` for a unified look.
Submit every included PR at once with Ctrl+S. Full keyboard and mouse
support throughout.
Launch the submit editor from `gh stack submit` in interactive terminals,
collecting per-branch PR drafts and applying them in a single batch. In
non-interactive terminals or with --auto, fall back to auto-generated
titles and skip the editor. Update the README and CLI reference to
describe the single-screen flow.
GitHub Advanced Security started work on behalf of skarim June 26, 2026 12:36 View session
GitHub Advanced Security finished work on behalf of skarim June 26, 2026 12:37
For existing PRs, the submit TUI showed a commit/template-derived draft
instead of the pull request's real title and body. Fetch the actual title
and body and render them in the read-only card:

- open/draft/queued (tracked) and adopted-open PRs now carry title/body
  through the existing batch sync (added the fields to the GraphQL queries
  and PRDetails — no extra round trips), and
- merged branches (which skip the live refresh) are filled in by a targeted
  enrichment step run only when the submit TUI opens.

Also align the new-PR defaults with the non-TUI submit's defaultPRTitleBody:

- Title: the commit subject only when the branch has exactly one commit,
  otherwise the humanized branch name (was: the oldest commit's subject even
  for multi-commit branches).
- Description: the PR template, else the single commit's body, else empty
  (removed the bulleted commit-subject list for multi-commit branches).
GitHub Advanced Security started work on behalf of skarim June 26, 2026 13:05 View session
GitHub Advanced Security finished work on behalf of skarim June 26, 2026 13:06
GitHub Advanced Security started work on behalf of skarim June 26, 2026 14:10 View session
GitHub Advanced Security finished work on behalf of skarim June 26, 2026 14:11
Scrolling the mouse wheel while a title or description field was focused
could insert stray characters such as "[<65;54;51M" into the field. The
submit TUI ran the Bubble Tea program with WithMouseAllMotion (mode 1003),
which reports an event on every pointer move. During a wheel scroll that
floods the input stream, and under that volume Bubble Tea splits an SGR
mouse escape sequence ("\x1b[<Cb;Cx;Cy(M|m)") across input reads; the
leftover bytes of a partially-parsed sequence are then emitted as key
runes and inserted into the focused text input.

Two changes fix this:

  - Switch to WithMouseCellMotion (mode 1002), which reports clicks, drag,
    and wheel but not idle pointer motion. That removes the per-move input
    flood, so under a real terminal's reads (up to 256 bytes) the only
    fragment that still surfaces is a single, clean burst at each wheel
    notch boundary. The TUI never used idle-hover for rendering, so
    cell-motion loses nothing.

  - Drop any leaked fragments before they reach a field. A split SGR mouse
    sequence surfaces as an Alt+"[" (the consumed "\x1b[") followed by
    body fragments ("<65;54;5", "1M"), or occasionally the whole body in
    one run ("[<65;54;51M"). consumeLeakedMouseKey recognises the start,
    swallows the body up to its "M"/"m" terminator, and bails out the
    moment a rune does not fit an SGR body, so ordinary typing (including
    "<", ";", digits, "M") and bracketed pastes are never eaten.

Tests cover every split point of an SGR sequence, single-run tails,
preserved real typing, a stray Alt+"[", bracketed paste, and that wheel
events never modify the focused field. Verified end-to-end by feeding
1,500 wheel sequences through the real parser under terminal-sized reads
and confirming the field stays empty.
@skarim skarim force-pushed the skarim/submit-tui branch from fd8c52b to e7d9173 Compare June 26, 2026 14:37
GitHub Advanced Security started work on behalf of skarim June 26, 2026 14:38 View session
GitHub Advanced Security finished work on behalf of skarim June 26, 2026 14:39
Opening the description in $EDITOR with ^e and then quitting left the
mouse unresponsive: clicks and wheel scrolling stopped working while
keyboard navigation still did.

The editor is launched with tea.ExecProcess, which releases the terminal
before running the command and calls Bubble Tea's RestoreTerminal when it
returns. RestoreTerminal re-enables the alt-screen, bracketed paste, and
focus reporting, but it does not re-enable mouse tracking. The editor
(e.g. vim) disables mouse reporting on exit, so once control returns to
the TUI the terminal no longer emits mouse events.

Re-arm mouse mode when the editor-finished message arrives by batching
tea.EnableMouseCellMotion with the handler's command. That re-enables
cell-motion and SGR mouse reporting, matching the WithMouseCellMotion
option the program starts with, on every editor-return path (success or
error).
GitHub Advanced Security started work on behalf of skarim June 26, 2026 16:57 View session
GitHub Advanced Security finished work on behalf of skarim June 26, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant