Skip to content

feat(session): batch apply live comments for agent reviews#179

Merged
benvinegar merged 2 commits into
mainfrom
feat/session-comment-apply
Apr 7, 2026
Merged

feat(session): batch apply live comments for agent reviews#179
benvinegar merged 2 commits into
mainfrom
feat/session-comment-apply

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Summary

  • add hunk session comment apply so agents can send many live inline comments in one stdin JSON batch with optional --focus
  • validate the full batch before mutating live review state, while resolving either hunk-wide or line-based targets through shared comment-target helpers
  • document the standalone batch workflow and cover it across CLI, controller, daemon, server, command, and session integration tests

Testing

  • bun run typecheck
  • bun test
  • bun run lint

@greptile-apps

greptile-apps Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds hunk session comment apply, a batch comment endpoint that lets agents pipe a single stdin JSON object (with a comments array) into a live Hunk review session instead of issuing one comment add call per note. The change is threaded correctly through the entire stack — CLI stdin parsing, HTTP daemon server, WebSocket command broker, and React review-controller — and ships with comprehensive tests at each layer.

Key changes:

  • parseSessionCommentApplyPayload in cli.ts validates each item and normalises the hunk/hunkNumber alias pair into a single hunkNumber before forwarding to the daemon
  • addLiveCommentBatch in useReviewController.ts resolves every target synchronously first, then applies them all in a single setLiveCommentsByFileId call, preserving the validate-before-mutate guarantee
  • server.ts correctly converts incoming hunkNumber (1-based) to hunkIndex (0-based) before sending the WebSocket command to the live TUI session
  • The hunk/hunkNumber alias validation only rejects when both fields disagree — if both are supplied with the same value the payload is silently accepted, contrary to the documented "exactly one target" contract
  • An empty comments array produces a silent no-op ("Applied 0 live comments …") rather than a validation error

Confidence Score: 5/5

Safe to merge; all remaining findings are P2 style suggestions with no correctness impact

The validate-before-mutate guarantee holds correctly. The hunkNumber to hunkIndex conversion is consistent across the full stack. Batch comment IDs are unique per request via mcp:requestId:index. Test coverage spans CLI parsing, daemon server forwarding, state management, and session integration. Both open findings are P2: the alias-validation leniency is a cosmetic contract issue and the empty-batch no-op is a UX edge case.

src/core/cli.ts — hunk/hunkNumber alias validation accepts both fields when they are equal

Important Files Changed

Filename Overview
src/core/cli.ts Adds stdin JSON payload parser for comment apply; hunk/hunkNumber alias validation permits both fields when they agree, contrary to the exactly-one-target contract
src/core/liveComments.ts Extracts shared comment-target helpers reused correctly by both single and batch comment paths
src/mcp/types.ts Adds CommentBatchItemInput, CommentBatchToolInput, and AppliedCommentBatchResult types for the batch path
src/mcp/daemonState.ts Adds sendCommentBatch with a 30s timeout, mirroring the sendComment pattern
src/mcp/server.ts Adds comment-apply case; correctly maps hunkNumber (1-based) to hunkIndex (0-based) before forwarding over WebSocket
src/session/commands.ts Wires applyComments into the CLI HTTP client and runSessionCommand dispatch with correct normalisation
src/session/protocol.ts Extends SessionDaemonAction and SessionDaemonRequest union with comment-apply
src/ui/hooks/useReviewController.ts Adds addLiveCommentBatch: validates all targets synchronously then applies in a single setLiveCommentsByFileId call
src/ui/hooks/useHunkSessionBridge.ts Adds applyIncomingCommentBatch bridge handler; correctly calls openAgentNotes when revealMode is first
src/core/types.ts Adds SessionCommentApplyItemInput and SessionCommentApplyCommandInput to the SessionCommandInput union

Sequence Diagram

sequenceDiagram
  participant Agent
  participant CLI as hunk session comment apply
  participant Daemon as HTTP Daemon server.ts
  participant WS as WebSocket daemonState.ts
  participant UI as Hunk TUI useReviewController

  Agent->>CLI: stdin JSON with comments array
  CLI->>CLI: parseSessionCommentApplyPayload validate each item
  CLI->>Daemon: POST /session-api action comment-apply
  Daemon->>Daemon: map hunkNumber minus 1 to hunkIndex
  Daemon->>WS: sendCommentBatch comment_batch WebSocket command
  WS->>UI: command comment_batch
  UI->>UI: addLiveCommentBatch resolve all targets then one setState
  UI-->>WS: AppliedCommentBatchResult
  WS-->>Daemon: command-result
  Daemon-->>CLI: result with applied array
  CLI-->>Agent: Applied N live comments to session
Loading

Reviews (1): Last reviewed commit: "feat(session): batch apply live comments..." | Re-trigger Greptile

Comment thread src/core/cli.ts
Comment thread src/core/cli.ts
@benvinegar
benvinegar merged commit ab819b8 into main Apr 7, 2026
3 checks passed
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