Skip to content

Inline review: comment on a diff before opening a PR, and assign comments to agents #1920

Description

@nicolastakashi

What I'd like to build

Review a change inside bb before a PR exists: read the diff in the thread's diff panel, leave comments anchored to lines, and hand them to an agent as work.

Today that loop leaves bb. An agent changes something, I read the diff, then either describe the problem in prose ("in session.ts, the TTL thing") or push a branch and review on GitHub. "Add to chat" comes closest: it quotes lines into the composer, but nothing persists, nothing is anchored, and there is no open review item.

Prior art: Orca.

Why it fits the diff panel

Most of the substrate exists:

  • DiffFilesPanel → DiffFileCard → GitDiffCardBody renders @pierre/diffs's FileDiff, with virtualization, merge-base handling, and patch paging.
  • usePierreLineSelectionActions does line-range selection, the gutter utility button, and an anchored TimelineSelectionMenu, with one action today: "Add to chat".
  • @pierre/diffs supports inline annotations and we don't use them. FileDiff takes lineAnnotations plus renderAnnotation(annotation) and projects the returned React subtree into a shadow slot named annotation-<side>-<lineNumber>. Pierre is a code review product, so we already depend on the primitive.

Missing is the comment model: storage, an anchor that survives edits, and a way to turn a comment into agent work.

Prototype

Two things I couldn't get from reading code: can that slot host a real interactive thread, and does a line selection convert to a stable anchor?

poc/inline-review, ~250 lines across 4 new files and 4 edited. UI only: comments live in localStorage and "assign" inserts a composer draft. A prototype, not a merge candidate.

The slot works: a focusable textarea with buttons renders inline between diff rows, split and unified, with the library reserving row height. Verified in a browser against the running app.

The loop closes: comment on a line, agent edits the code. Verified against a live claude-code thread and real checkout.

Anchoring naively misleads agents. The panel renders unified at real widths, where a modified line is one row carrying the OLD line number and the library reports side: "deletions". Anchoring that verbatim cited and quoted the removed line. An agent flagged it unprompted: "The comment was anchored to the deletion side of the diff … but the intended target was the replacement line."

Fixed on the branch. A deletion-side anchor resolves to the new-file line: a context line carries both numbers, and a replaced line pairs positionally, Nth deletion to Nth addition of its change block. A deletions anchor survives only for a genuinely removed line, where the prompt says so instead of citing a number that means something else. Unified and split now agree.

That last one is why I want alignment first: it is the anchor format, and it gets expensive to change once comments persist.

The decision I need

Is the reviewable unit the environment or the pull request?

The prototype uses the environment: a thread's checkout or worktree diffed against its merge base, where agent work lands and which predates any PR. Comments key on environmentId, not a thread, since several threads can share one.

Scoping to a PR instead overlaps the GitHub plugin. If you want both, do they share one comment store with different diff targets, or stay separate? This decides the schema.

Rough shape

  1. Line-selection enablement becomes a capability set instead of deriving from onSelectionAddToChat, and GitDiffCardBody passes annotations through. Core only, no feature, and it isolates churn in a component that also backs timeline diff cards.
  2. Server-owned comments with SDK and bb review CLI surfaces, no UI. localStorage comments can't be read by an agent, which is half the value; server-side, an agent reads its own environment's open comments before any UI exists.
  3. The UI, ported off localStorage.
  4. Re-anchoring: re-resolve stored anchors against a fresh patch, mark outdated ones. Least understood part.
  5. Assignment: threads.send into the owning thread, or threads.spawn a child per review. Today's "assign" is only a composer draft.

Other questions

  • Should diffSelectionAction and diff annotations become plugin slots? The GitHub plugin would want the same hook. I'd defer until the core shape is proven.
  • A comment on a removed line has no code to edit. Keep it and say so in the prompt, or refuse to assign it?
  • Anchoring to the post-change file means clicking a context line in split view's left column renders its thread in the right column. Correct for handoff, but not where the user clicked.

If you don't want inline review in core, fine: the prototype was cheap and the annotation-slot finding is useful regardless.

Activity

  1. added
    ui
    threads
    on Aug 19, 2026
  2. lanjak commented on Nov 21, 2026

    @lanjak
    Contributor

    Hi, I'd like to build this. Your prototype answered the hard parts, so here is the anchor format I plan to use before anything persists. Objections welcome before I start.

    Checked against main at 4e45c9bc12, where the Diff tab, Viewed marks and bb git now live in the bundled Git plugin (#6157, #6165).

    Reviewable unit: the environment. Comments key on environmentId, as in your prototype. They show on every Git plugin target (uncommitted, branch, all, commit), so a commit does not hide them. Comments on the GitHub plugin's PR view (no environment) come later, on the same Diff props.

    Storage: the Git plugin database, next to Viewed marks. No core schema change.

    Anchor, stored once and never rewritten:

    • path, side (new or old), start_line, end_line
    • anchor_lines: the exact code, max 50 lines
    • context_before / context_after: up to 3 lines each
    • anchor_blob: the blob id of that side when the comment was made

    Selection to anchor: your rule. A context row uses the new number. A modified row in unified view pairs with the Nth addition of its change block. side: "old" only for a genuinely removed line, and the prompt says so.

    Re-anchoring on read, computed and not stored:

    • same blob: unchanged
    • otherwise search the current file for anchor_lines, score matches by context, then by distance
    • no match: Outdated, shown with the stored code as a quote

    Delivery: one "N review comments" chip in the composer, resolved at send through the existing plugin mention path (the one agent-annotations uses). The CLI sends the same mention. The agent closes each comment with bb git comments resolve <id> --note "...".

    API: selection actions and line annotations become experimental_ props on the plugin Diff, and core's Add to chat moves onto the same selection-action list.

    On your other questions: comments on removed lines are kept and labelled as removed in the prompt. A context line clicked in split view's left column renders on the right, as you describe.

  3. lanjak commented on Nov 21, 2026

    @lanjak
    Contributor

    Prototype: main...lanjak:bb:diff-comments-3-ui (three stacked commits on 35a03bbbb3). It uses the anchor format from my comment above, unchanged. No PR until we agree on the feature.

    The three commits match the split I'd propose for PRs:

    1. diff-comments-1-core: a selection-action list that core's Add to chat and plugins share, selection-to-anchor mapping, and experimental_ selection-action and line-annotation props on the plugin Diff, with audit and Plugin Guide entries.
    2. diff-comments-2-server: comments in the Git plugin database, re-anchoring on read (cached by blob id), batches, a mention chip resolved at send, and bb git comments list|add|send|resolve|reopen. Agents can use it without any UI.
    3. diff-comments-3-ui: inline comment cards, a Comments list with filters, and Send.

    Details that go beyond the format I posted:

    • The plugin keeps Viewed marks and comments in one flat migration list. Index 0 is main's Viewed table unchanged, and a test pins every index.
    • Sending the same comments twice to one thread reuses one batch, and the agent gets each comment once.
    • Context sent to the agent is capped at about 96 KB. Over the cap, comments are listed as omitted.
    • A comment counts as the user's only when the caller says so. Otherwise it is marked unspecified.

    Checked live in a dev bb with a real Claude Code thread:

    • a comment on a modified line anchors to the new line, not the removed one
    • an edit above it shows it as Moved
    • deleting the code shows Outdated
    • the agent resolves each comment with a note

    Not checked yet: the iOS Simulator drawer (only a touch-emulated Chromium so far), and the desktop and mobile apps.

  4. lanjak commented on Dec 2, 2026

    @lanjak
    Contributor

    Update: I rebased the prototype onto 4d7a9af609. Same link: main...lanjak:bb:diff-comments-3-ui (head 7a511f792d; the stack is diff-comments-1-core 0f70040708, diff-comments-2-server 4828f00a50).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    threadsui

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions