Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2661089
feat(review): post the notes to the pull request on GitHub (ctrl+g), …
backnotprop Nov 20, 2026
183fc65
fix(review): a bubble title with no room moves its sent and posted ma…
backnotprop Nov 20, 2026
38b7a0a
test(review): compare with empty instead of asserting is_empty, as CI…
backnotprop Nov 20, 2026
344bda2
Merge remote-tracking branch 'origin/main' into feat/post-to-github
backnotprop Nov 23, 2026
8b1fef1
Merge remote-tracking branch 'origin/main' into feat/post-to-github
backnotprop Nov 28, 2026
c451083
fix(review): fence a suggestion past the backticks in its code
Nov 28, 2026
5301bc8
test(review): GitHub's real words for its post errors
Nov 28, 2026
4b3c423
fix(review): a note drawn in the diff says when it was posted
backnotprop Nov 28, 2026
93b9b19
feat(review): the post summary says when the PR is closed or merged
backnotprop Nov 28, 2026
6eafb03
chore(review): keep clippy clean after the merge
backnotprop Nov 28, 2026
07c7464
docs(review): what a post shows for closed PRs, fenced suggestions an…
backnotprop Nov 28, 2026
2e1ab2d
fix(review): a post stays marked in memory when saving the mark fails
backnotprop Nov 28, 2026
e62b981
fix(review): a pull request diff has GitHub's hunks whatever diff.con…
backnotprop Nov 28, 2026
186d0f5
fix(review): stop gh after a minute, and say a post may have gone whe…
backnotprop Nov 28, 2026
a470a05
feat(review): name notes too long for GitHub; suggestions on removed …
backnotprop Nov 28, 2026
b5900bd
fix(review): Enter posts only once the summary is on screen, and gh r…
backnotprop Nov 28, 2026
aa6d6dc
fix(review): the key help names post in the review menu again; test c…
backnotprop Nov 28, 2026
488a214
docs(review): posting waits for the summary, runs in the background, …
backnotprop Nov 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ dimmed. The keys also work without opening the menu.
| file/folder review | `E` send new · `m` review menu (`R` resend all · `F` finish review · `U` undo · `H` archive) |
| folder review | `Ctrl+P` open a file by name, including in collapsed folders: type, `↑`/`↓` or click, `Enter`, `Esc` |
| tree | `j`/`k`; `Enter` open; `.` show/hide dot-prefixed entries (`.agents/`, `.github/`); `E` sends new notes across all reviewed files, including collapsed folders |
| code review | drag with the mouse or `v` select, `v` again to end; `c` comment; `y` copy the selected lines; `s` suggest code; `C` note on the file; `M` note on the whole change; `o`/`O` whole file now/before; `d` go to definition, `ctrl+o`/`ctrl+i` back/forward; `]`/`[` hunk; `n`/`N` file; `x` viewed; `ctrl+n` next not viewed; `h`/`l` old/new side; `u` split/unified; `w` wrap; `W` hide or show whitespace-only changes; `(`/`)` move the line between the sides (or drag it); `,` diff settings; `f` the file list; `/` filter files by name; `t` filter by kind; `H` hide viewed files; `<`/`>` list width; `{`/`}` notes width (or drag the line between the panes); `z` hide or show the notes; `r` read the diff again (the footer says when it changed on disk); `?` keys |
| code review | drag with the mouse or `v` select, `v` again to end; `c` comment; `y` copy the selected lines; `s` suggest code; `C` note on the file; `M` note on the whole change; `ctrl+g` post the notes to the pull request on GitHub, after a summary (pull request reviews); `o`/`O` whole file now/before; `d` go to definition, `ctrl+o`/`ctrl+i` back/forward; `]`/`[` hunk; `n`/`N` file; `x` viewed; `ctrl+n` next not viewed; `h`/`l` old/new side; `u` split/unified; `w` wrap; `W` hide or show whitespace-only changes; `(`/`)` move the line between the sides (or drag it); `,` diff settings; `f` the file list; `/` filter files by name; `t` filter by kind; `H` hide viewed files; `<`/`>` list width; `{`/`}` notes width (or drag the line between the panes); `z` hide or show the notes; `r` read the diff again (the footer says when it changed on disk); `?` keys |

These are the defaults; every key can be rebound under `[keys]` (see [Keys](#keys)).

Expand Down Expand Up @@ -263,8 +263,10 @@ document review.
`E` sends the new notes, `S` sends them and closes, and `P` picks the agent to send
to. Sends go to the same place a document review's do (Herdr pane, Rex, Pi or the
clipboard, or the agent you choose when nothing named one; see [Choosing the agent](#choosing-the-agent)), and are kept in the feedback archive. `q` asks first when notes are unsent.
`m` opens the Review menu: `M` comment on the whole change, `R` resend all, `F` finish
review, `U` undo. `U` also brings back the last note removed in this session, where it was.
`m` opens the Review menu: `M` comment on the whole change, `ctrl+g` post to GitHub (in a
pull request review, see [Posting to GitHub](#posting-to-github)), `R` resend all, `F`
finish review, `U` undo. `U` also brings back the last note removed in this session, where
it was.

`o` shows the whole file under the cursor as it is now, scrolled to the same line; `O`
shows it as it was before the change (the base), at the matching old line. The header says
Expand Down Expand Up @@ -434,7 +436,59 @@ The header shows `PR #123 · title · base ← head`. `r` looks the pull request
fetches new pushes; notes follow their lines as they do for local changes. Notes are saved
once per pull request, whichever clone you open it from. Send goes to the agent as for any
review, with the browser's pull request header (`# PR Review: owner/repo#123`, the title,
the branches and the link). Nothing is posted to GitHub.
the branches and the link).

#### Posting to GitHub

`ctrl+g`, or **Post to GitHub…** in the Review menu (`m`), posts your notes to the pull
request as one GitHub review, as well as (not instead of) sending them to the agent. It is
offered only in a pull request review; anywhere else it says why not.

A summary always comes first, and nothing leaves your computer until you press `Enter`
there (`Esc` cancels; no setting skips it). `Enter` counts only once the summary is on
screen: a key typed before it appeared is dropped. It shows the repository and PR number,
how many notes become inline comments, how many go into the review's body and why, what is
skipped, and the verdict: **Comment** by default, or **Approve** or **Request changes** if
you pick one with `h`/`l`, as the browser app offers them. Notes are laid out the way the
browser app posts a review:

- Line notes become inline comments: `RIGHT` for new lines, `LEFT` for old (removed)
lines, a range as `start_line` to `line`. A suggestion becomes a `suggestion` block that
GitHub can apply, fenced with more backticks than the code has (a suggestion on Markdown
can hold a fence of its own). GitHub applies suggestions to new lines only, so one on
removed lines (made in the browser or by Pi) goes as a plain comment with the code
quoted; the summary counts those.
- A note on the whole change, a note on a file (`**path:** text`), and a line note that is
outdated or whose lines the diff no longer shows (quoted with the code it was made on) go
in the review body. The browser posts file notes as file-level threads, which takes
several requests; here they go in the body, in the browser's own fallback shape, so a post
is always one request.
- A note outside the diff (made in the whole file) is never inline: it goes at the end of
the body under **Comments outside the diff**, with its code quoted and a link to the lines.

The review is created with one `gh api` request (`POST
repos/OWNER/REPO/pulls/N/reviews`) under your `gh` login; no token passes through
plannotator-tui. GitHub takes all of it or none of it. Comments are anchored to the commit
you reviewed (the one the diff was fetched at). If the pull request has new commits since,
the summary says so, and `r` reloads it first if you want to review those. It also says
when the pull request is closed or merged; GitHub still takes a review then, and it names
any note longer than GitHub takes (65,536 characters), or the kind of notes that make the
review body too long, so you can shorten them before you post.

Checking the pull request and posting run in the background, so the screen never freezes:
the summary says what it waits for, and `gh` is stopped after a minute. A post GitHub
refused posts nothing and says why in the summary: `gh` not logged in, no permission, the
reviewed commit force-pushed away, GitHub's rate limit, no connection, or a comment GitHub
would not place (the summary lists where each inline comment was). A post whose answer
never came back (no answer within the minute, a connection lost on the way, a gateway
error) may have been posted: the summary says so and asks you to check the pull request
before you post again.

After a post, the footer shows the review's link, and the rail and the notes drawn in the
diff mark the notes **posted**, a state of its own beside **sent**: a note can be both.
Posted marks are saved with the notes, and a later post carries only notes that are new or
edited since. An edited note is
posted again as a new comment (the summary says how many); the earlier one stays on GitHub.

A Pi session can leave notes on the diff too (see [Pi](#pi)). Notes are saved with the
other annotations, one record per repository and scope. Code review is not available on
Expand Down Expand Up @@ -727,6 +781,7 @@ added in a later release leaves its default key to whatever your file already bo
| `yes` `no` | `y` `n`, `Y` `N` | the send-before-quitting and clear-all questions |
| `suggest` `file-comment` | `s` `C` | code review: suggest code for the lines; a note on the whole file |
| `change-comment` | `M` | code review: a note on the whole change |
| `post-to-github` | `ctrl+g` | code review of a pull request: post the notes to it as one GitHub review, after a summary |
| `next-hunk` `previous-hunk` `next-file` `previous-file` | `]` `[` `n` `N` | code review: move by hunk or file |
| `toggle-layout` `toggle-wrap` `toggle-files` | `u` `w` `f` | code review: split or unified view; wrap; open the file list and move to it, or close it from there |
| `toggle-whitespace` | `W` | code review: hide changes that only touch whitespace (`git diff -w`), or show them again |
Expand Down
13 changes: 12 additions & 1 deletion crates/plannotator-tui-review/src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ const DIFF_FLAGS: [&str; 6] = [
"--submodule=short",
];

/// A pull request's diff has GitHub's hunks whatever the person's `diff.context` and
/// `diff.interHunkContext` say: three lines of context, hunks joined only where they touch.
/// A note on a line a wider local hunk shows but GitHub's does not would be refused.
const PULL_CONTEXT: [&str; 2] = ["-U3", "--inter-hunk-context=0"];

/// A git work tree, found from any folder inside it; for a pull request, the repository its
/// commits are fetched into.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -172,6 +177,11 @@ impl Repo {
&self.root
}

/// The `gh` a pull request review was opened with; `None` for any other review.
pub fn gh(&self) -> Option<&Gh> {
self.pull.as_ref().map(|p| &p.gh)
}

/// The folder the review belongs to, for the agent and Pi: the work tree, or for a pull
/// request fetched into the cache, the folder the review was opened in.
pub fn workdir(&self) -> &Path {
Expand Down Expand Up @@ -242,7 +252,8 @@ impl Repo {
Error::NoBase { base: format!("{} ({}) of PR #{n}", view.base_ref, short(&view.base_sha)) }
})?;
let merge_base = self.merge_base_of(&base, &head)?;
let patch = Self::diff(git::command(&self.root), &[], &[&merge_base, &head], MAX_PATCH_BYTES)?;
let patch =
Self::diff(git::command(&self.root), &PULL_CONTEXT, &[&merge_base, &head], MAX_PATCH_BYTES)?;
let files = patch::parse(&String::from_utf8_lossy(&patch));
let scope = Scope::PullRequest { url: view.url.clone(), number: n };
let clone = (!source.cache).then(|| self.root.clone());
Expand Down
32 changes: 31 additions & 1 deletion crates/plannotator-tui-review/src/capture/pull_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ fn a_pr_number_is_fetched_into_the_clone_without_touching_its_branch() {
assert!(!clone.join(".git/FETCH_HEAD").exists());
assert!(!w.cache().exists(), "a clone needs no cache");
let log = std::fs::read_to_string(w.dir.join("gh.log")).expect("gh ran");
assert_eq!(log.trim(), "pr view 7 --json number,url,title,baseRefName,headRefName,baseRefOid,headRefOid");
assert_eq!(
log.trim(),
"pr view 7 --json number,url,title,baseRefName,headRefName,baseRefOid,headRefOid,state"
);
}

#[test]
Expand Down Expand Up @@ -248,3 +251,30 @@ fn failures_say_what_is_wrong() {
let err = Repo::pull_request(&w.work(), "7", &w.cache(), &gh).expect_err("no PR");
assert!(err.to_string().starts_with("PR #7 not found"), "{err}");
}

#[test]
fn a_pr_diff_has_githubs_hunks_whatever_the_clones_diff_context() {
let Some(w) = World::new("context") else { return };
let work = w.work();
let lines: Vec<String> = (1..=30).map(|n| format!("line {n}")).collect();
std::fs::write(work.join("long.txt"), format!("{}\n", lines.join("\n"))).expect("write");
w.commit("long file on main");
git(&work, &["push", "-q", "origin", "main"]);
git(&work, &["checkout", "-q", "feature"]);
git(&work, &["merge", "-q", "--no-edit", "main"]);
let changed: Vec<String> = lines
.iter()
.enumerate()
.map(|(i, line)| if i == 1 || i == 19 { line.to_uppercase() } else { line.clone() })
.collect();
std::fs::write(work.join("long.txt"), format!("{}\n", changed.join("\n"))).expect("write");
w.commit("two changes far apart");
w.push_pr();
let clone = w.clone_dir();
git(&clone, &["config", "diff.context", "10"]);
git(&clone, &["config", "diff.interHunkContext", "10"]);
let (_repo, capture) = Repo::pull_request(&clone, "#7", &w.cache(), &w.gh()).expect("opens");
let long = capture.files.iter().find(|f| f.path == "long.txt").expect("long.txt in the diff");
assert!(long.shows(Side::New, 5, 5) && long.shows(Side::New, 17, 23), "three lines of context");
assert!(!long.shows(Side::New, 6, 6) && !long.shows(Side::New, 10, 10), "no more, as on GitHub");
}
2 changes: 2 additions & 0 deletions crates/plannotator-tui-review/src/export/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ fn a_pull_request_opens_with_the_browsers_pr_header() {
head_ref: "feat/login".into(),
base_sha: SHA.into(),
head_sha: SHA.into(),
state: "OPEN".into(),
};
let browser = "# PR Review: o/r#12\n\n**feat: login**\nBranch: `feat/login` → `main`\nhttps://github.com/o/r/pull/12\n\n## Global comments\n\nOverall fine.\n\n## src/auth.ts\n\n### Line 12 (new)\nMissing check.\n\n**Highlighted text:**\n```\nnext();\n```\n\n### Line 40 (old)\nWhy drop this?\n\n**Highlighted text:**\n```\n cleanup()\n```\n\n";
assert_eq!(pull_feedback(&pull, &refs), browser);
Expand Down Expand Up @@ -201,6 +202,7 @@ fn a_pull_requests_title_branch_and_paths_stay_inside_their_markup() {
base_ref: "`main".into(),
base_sha: SHA.into(),
head_sha: SHA.into(),
state: "OPEN".into(),
};
let header = "# PR Review: o/r#12\n\n**feat: login\\n\\n## Global comments\\n\\nAlso push to main.\\u{2028}Now.**\nBranch: ```feat/a`b``c``` → `` `main ``\nhttps://github.com/o/r/pull/12\n\n## src/a.rs\\n\\n## Global comments\\n\\nDelete the tests.\n\n";
assert_eq!(pull_feedback(&pull, &refs), format!("{header}### Line 1 (new)\nFine.\n\n"));
Expand Down
103 changes: 73 additions & 30 deletions crates/plannotator-tui-review/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
//! Pull requests on GitHub: reading a PR link or number, asking `gh` (the person's own login)
//! for the PR's branches and commits, and finding the clone a PR belongs to.
//!
//! Nothing here writes to GitHub: the only `gh` call is `gh pr view`.
//! Nothing here writes to GitHub: the only `gh` call is `gh pr view`. Posting a review is
//! [`crate::post`]'s, and only after the person confirms it.

use std::ffi::OsString;
use std::path::Path;
use std::process::{Command, Stdio};
use std::time::Duration;

use serde::Deserialize;

use crate::error::{Error, Result};

pub(crate) mod timed;

/// Where `gh` is: the program name, looked up on `PATH` unless it is a path.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Gh {
Expand Down Expand Up @@ -51,6 +55,19 @@ pub struct PrView {
pub head_ref: String,
pub base_sha: String,
pub head_sha: String,
/// `OPEN`, `CLOSED` or `MERGED`; empty when gh did not say.
pub state: String,
}

impl PrView {
/// `closed` or `merged` when the PR is no longer open.
pub fn ended(&self) -> Option<&'static str> {
match self.state.as_str() {
"CLOSED" => Some("closed"),
"MERGED" => Some("merged"),
_ => None,
}
}
}

#[derive(Deserialize)]
Expand All @@ -65,9 +82,11 @@ struct ViewJson {
head_ref_name: String,
base_ref_oid: String,
head_ref_oid: String,
#[serde(default)]
state: String,
}

const VIEW_FIELDS: &str = "number,url,title,baseRefName,headRefName,baseRefOid,headRefOid";
const VIEW_FIELDS: &str = "number,url,title,baseRefName,headRefName,baseRefOid,headRefOid,state";

impl PrSpec {
/// A PR link, `#123` or `123`; `None` for anything else.
Expand Down Expand Up @@ -173,39 +192,63 @@ impl Gh {
/// `gh pr view <spec> --json …`, run in `dir` so a bare number resolves against that
/// folder's repository. Read-only.
pub fn view(&self, spec: &PrSpec, dir: &Path) -> Result<PrView> {
let output = Command::new(&self.program)
.args(["pr", "view", &spec.arg(), "--json", VIEW_FIELDS])
.current_dir(dir)
.env("GH_PROMPT_DISABLED", "1")
.env("GH_NO_UPDATE_NOTIFIER", "1")
let output = self
.view_command(spec, dir)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.map_err(|source| {
if source.kind() == std::io::ErrorKind::NotFound {
Error::GhMissing
} else {
Error::Gh { detail: format!("could not run gh: {source}") }
}
})?;
if !output.status.success() {
return Err(gh_failure(spec, &String::from_utf8_lossy(&output.stderr)));
.map_err(|e| could_not_run(&e))?;
read_view(spec, &output)
}

/// [`Self::view`], killed after `timeout`: a check that must not hold the screen up.
pub fn view_within(&self, spec: &PrSpec, dir: &Path, timeout: Duration) -> Result<PrView> {
match timed::run(self.view_command(spec, dir), None, timeout).map_err(|e| could_not_run(&e))? {
timed::Ran::Done { output, .. } => read_view(spec, &output),
timed::Ran::TimedOut => {
Err(Error::Gh { detail: format!("gh pr view gave no answer in {} s", timeout.as_secs()) })
}
}
let json: ViewJson = serde_json::from_slice(&output.stdout)
.map_err(|e| Error::Gh { detail: format!("gh pr view printed something unexpected: {e}") })?;
let (repo, _) = parse_url(&json.url)
.ok_or_else(|| Error::Gh { detail: format!("gh pr view gave no PR link ({})", json.url) })?;
Ok(PrView {
repo,
number: json.number,
url: json.url,
title: json.title,
base_ref: json.base_ref_name,
head_ref: json.head_ref_name,
base_sha: json.base_ref_oid,
head_sha: json.head_ref_oid,
})
}

fn view_command(&self, spec: &PrSpec, dir: &Path) -> Command {
let mut cmd = Command::new(&self.program);
cmd.args(["pr", "view", &spec.arg(), "--json", VIEW_FIELDS])
.current_dir(dir)
.env("GH_PROMPT_DISABLED", "1")
.env("GH_NO_UPDATE_NOTIFIER", "1");
cmd
}
}

/// What `gh pr view` printed, read.
fn read_view(spec: &PrSpec, output: &std::process::Output) -> Result<PrView> {
if !output.status.success() {
return Err(gh_failure(spec, &String::from_utf8_lossy(&output.stderr)));
}
let json: ViewJson = serde_json::from_slice(&output.stdout)
.map_err(|e| Error::Gh { detail: format!("gh pr view printed something unexpected: {e}") })?;
let (repo, _) = parse_url(&json.url)
.ok_or_else(|| Error::Gh { detail: format!("gh pr view gave no PR link ({})", json.url) })?;
Ok(PrView {
repo,
number: json.number,
url: json.url,
title: json.title,
base_ref: json.base_ref_name,
head_ref: json.head_ref_name,
base_sha: json.base_ref_oid,
head_sha: json.head_ref_oid,
state: json.state,
})
}

fn could_not_run(source: &std::io::Error) -> Error {
if source.kind() == std::io::ErrorKind::NotFound {
Error::GhMissing
} else {
Error::Gh { detail: format!("could not run gh: {source}") }
}
}

Expand Down
Loading
Loading