Skip to content

feat(code-review): batch review comments into a single agent prompt#1965

Draft
adboio wants to merge 2 commits intomainfrom
batch-review-comments-1827
Draft

feat(code-review): batch review comments into a single agent prompt#1965
adboio wants to merge 2 commits intomainfrom
batch-review-comments-1827

Conversation

@adboio
Copy link
Copy Markdown
Contributor

@adboio adboio commented Apr 30, 2026

Summary

Closes #1827. Lets reviewers queue multiple inline review comments and send them to the agent as one combined prompt instead of one prompt per comment.

  • Inline comment form now has an "Add to review" checkbox. When on, submit appends to a per-task draft list instead of firing the agent. Default is on once any draft exists.
  • New PendingReviewBar pinned to the bottom of the review panel lists every queued draft (file, line range, snippet) with edit / delete buttons, click-to-scroll on the file path, and a single Send to agent action that combines all drafts via buildBatchedInlineCommentsPrompt.
  • Drafts also render inline on the diff at their line range as DraftCommentAnnotation, sharing the comment textarea for edit.
  • Drafts clear only on successful send, manual discard, or task unmount. One-off comments (checkbox off) leave queued drafts intact.
  • PR comment "Fix with agent" / "Ask agent" actions are unchanged — out of scope for this PR.

Test plan

  • Add 2 drafts on different files, verify both render inline + show in PendingReviewBar
  • Click "Send to agent" → single prompt fires with both comments enumerated, drafts clear, review collapses, logs tab activates
  • Edit a draft → textarea pre-fills, resubmit updates without duplicating
  • Delete a draft → annotation disappears, count decrements
  • Mixed mode: with 2 drafts queued, submit a one-off comment (checkbox off) → one-off goes immediately, drafts persist
  • Submit a batch while agent is mid-prompt → batched prompt enters messageQueue and fires when current prompt completes
  • Diff content change (agent edits a drafted file) → drafts persist
  • Source switch (local ↔ branch ↔ PR) → drafts persist in the bar
  • Close/unmount task tab, reopen → drafts are empty
  • Pre-existing single-comment immediate-send still works when no drafts exist
  • pnpm --filter code typecheck passes
  • pnpm --filter code test --run reviewDraftsStore passes (8 tests)

Closes #1827. Inline review comments now have an "Add to review"
checkbox: when checked, submitting the form queues the comment into a
per-task draft instead of dispatching to the agent. A pinned
PendingReviewBar at the bottom of the review panel lists every queued
draft (file, line range, snippet) with edit / delete affordances and a
single "Send to agent" action that combines all drafts into one prompt
via buildBatchedInlineCommentsPrompt. Drafts also render inline on the
diff at their line range as DraftCommentAnnotation, sharing the same
edit flow as the comment textarea.

Drafts are in-memory per task and clear on successful send, manual
discard, or task unmount. Submitting a one-off comment (checkbox off)
leaves any queued drafts intact. PR comment "Fix with agent" / "Ask
agent" actions are unchanged.

Generated-By: PostHog Code
Task-Id: 53f42d57-7308-48a1-996f-836f1c7536eb
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Comments Outside Diff (2)

  1. apps/code/src/renderer/features/code-review/utils/reviewPrompts.ts, line 1184 (link)

    P2 Numbered list in prompt violates "no numbers in list" rule

    The batch prompt uses ${idx + 1}. to enumerate comments. The team rule is to avoid numbered lists in prompts to prevent confusion when user responses contain numbers themselves — use bullets or letters instead.

    Rule Used: In prompts, avoid using numbers in lists to preven... (source)

    Learned From
    PostHog/posthog#31624

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/renderer/features/code-review/utils/reviewPrompts.ts
    Line: 1184
    
    Comment:
    **Numbered list in prompt violates "no numbers in list" rule**
    
    The batch prompt uses `${idx + 1}.` to enumerate comments. The team rule is to avoid numbered lists in prompts to prevent confusion when user responses contain numbers themselves — use bullets or letters instead.
    
    
    
    **Rule Used:** In prompts, avoid using numbers in lists to preven... ([source](https://app.greptile.com/review/custom-context?memory=1dd45b94-c307-4dd0-a025-5aa16059229b))
    
    **Learned From**
    [PostHog/posthog#31624](https://github.com/PostHog/posthog/pull/31624)
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  2. apps/code/src/renderer/features/code-review/components/PendingReviewBar.tsx, line 563-565 (link)

    P2 Drafts cleared before send succeeds

    clearDrafts is called before sendPromptToAgent, so if the send throws the queued comments are silently lost. The PR description says drafts should clear only on a successful send. Swapping the order aligns implementation with stated intent.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/renderer/features/code-review/components/PendingReviewBar.tsx
    Line: 563-565
    
    Comment:
    **Drafts cleared before send succeeds**
    
    `clearDrafts` is called before `sendPromptToAgent`, so if the send throws the queued comments are silently lost. The PR description says drafts should clear only on a successful send. Swapping the order aligns implementation with stated intent.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
apps/code/src/renderer/features/code-review/utils/reviewPrompts.ts:1184
**Numbered list in prompt violates "no numbers in list" rule**

The batch prompt uses `${idx + 1}.` to enumerate comments. The team rule is to avoid numbered lists in prompts to prevent confusion when user responses contain numbers themselves — use bullets or letters instead.

```suggestion
      return `- In file <file path="${escapedPath}" />, ${lineRef} (${sideLabel}):\n${indented}`;
```

### Issue 2 of 3
apps/code/src/renderer/features/code-review/components/InteractiveFileDiff.tsx:375-389
**`handleEditDraft` duplicated across `PatchDiffView` and `FilesDiffView`**

The same callback — look up the draft by id, call `openCommentForEdit` — is copy-pasted verbatim into both components. Extracting it into the shared `useCommentState` hook (or a small dedicated hook that takes `fileDrafts` and `openCommentForEdit`) would keep this logic OnceAndOnlyOnce and make future changes to the edit flow easier to track.

### Issue 3 of 3
apps/code/src/renderer/features/code-review/components/PendingReviewBar.tsx:563-565
**Drafts cleared before send succeeds**

`clearDrafts` is called before `sendPromptToAgent`, so if the send throws the queued comments are silently lost. The PR description says drafts should clear only on a successful send. Swapping the order aligns implementation with stated intent.

```suggestion
    sendPromptToAgent(taskId, prompt);
    clearDrafts(taskId);
```

Reviews (1): Last reviewed commit: "feat(code-review): batch review comments..." | Re-trigger Greptile

Comment on lines +375 to +389
const draftAnnotations = useMemo(() => {
const drafts = editSeed
? fileDrafts.filter((d) => d.id !== editSeed.draftId)
: fileDrafts;
return buildDraftAnnotations(drafts);
}, [fileDrafts, editSeed]);
const annotations = useMemo(() => {
const all = [...prAnnotations];
const all = [...prAnnotations, ...draftAnnotations];
if (commentAnnotation) all.push(commentAnnotation);
return all;
}, [prAnnotations, commentAnnotation]);
}, [prAnnotations, draftAnnotations, commentAnnotation]);

const renderAnnotation = useCallback(
(annotation: DiffLineAnnotation<AnnotationMetadata>) =>
renderSharedAnnotation(
annotation,
renderSharedAnnotation(annotation, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 handleEditDraft duplicated across PatchDiffView and FilesDiffView

The same callback — look up the draft by id, call openCommentForEdit — is copy-pasted verbatim into both components. Extracting it into the shared useCommentState hook (or a small dedicated hook that takes fileDrafts and openCommentForEdit) would keep this logic OnceAndOnlyOnce and make future changes to the edit flow easier to track.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/code-review/components/InteractiveFileDiff.tsx
Line: 375-389

Comment:
**`handleEditDraft` duplicated across `PatchDiffView` and `FilesDiffView`**

The same callback — look up the draft by id, call `openCommentForEdit` — is copy-pasted verbatim into both components. Extracting it into the shared `useCommentState` hook (or a small dedicated hook that takes `fileDrafts` and `openCommentForEdit`) would keep this logic OnceAndOnlyOnce and make future changes to the edit flow easier to track.

How can I resolve this? If you propose a fix, please make it concise.

- Mock @renderer/trpc/client and @features/sessions/service/service in
  ReviewShell.test.tsx so importing ReviewShell (which now transitively
  pulls in sendPromptToAgent → trpcClient) doesn't initialize the IPC
  link at module load time. Fixes the unit-test CI job.
- Use bullets instead of "1.", "2." enumeration in
  buildBatchedInlineCommentsPrompt to match the team rule about avoiding
  numbered lists in agent prompts.
- Send the batched prompt before clearing drafts in PendingReviewBar so
  drafts aren't lost if sendPromptToAgent throws.
- Extract the duplicated handleEditDraft callback in
  InteractiveFileDiff.tsx into a shared useEditDraftHandler hook so the
  edit flow lives in one place.

Generated-By: PostHog Code
Task-Id: 53f42d57-7308-48a1-996f-836f1c7536eb
@adboio adboio marked this pull request as draft May 1, 2026 15:19
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.

Batch multiple review comments to the agent into a single prompt

1 participant