Skip to content

feat(site): add diff line reference and annotation system for agents chat#22697

Merged
kylecarbs merged 1 commit intomainfrom
diff-comments
Mar 8, 2026
Merged

feat(site): add diff line reference and annotation system for agents chat#22697
kylecarbs merged 1 commit intomainfrom
diff-comments

Conversation

@kylecarbs
Copy link
Copy Markdown
Member

Summary

Adds a line-reference and annotation system for diffs in the Agents UI. Users can click line numbers in the Git diff panel to open an inline prompt input, type a comment, and have a reference chip + text added to the chat message input.

Changes

Backend

  • Added diff-comment type to ChatInputPart and ChatMessagePart in codersdk/chats.go with FileName, StartLine, EndLine, Side fields

Frontend

  • DiffCommentContext: React context/provider managing pending diff comments with addReference, removeComment, restoreComment, clearComments
  • DiffCommentNode: Lexical DecoratorNode rendering inline chips in the chat input showing file:line references. Chips are clickable (scroll to line in diff), removable, and support undo/redo via mutation tracking
  • InlinePromptInput: Textarea annotation rendered inline under clicked lines in the diff. Supports multiline (Shift+Enter), submit (Enter), cancel (Escape)
  • FilesChangedPanel: Line click/drag-select handlers open the inline input. On submit, a badge chip + plain text are inserted into the Lexical editor
  • AgentDetail: Bidirectional sync between DiffCommentContext and Lexical editor. Comments are sent as diff-comment parts on message submit
  • ConversationTimeline: Renders diff-comment message parts with file:line labels

How it works

  1. Click a line number in the diff → inline textarea appears below that line
  2. Type a comment and press Enter → reference chip appears in chat input with your text after it
  3. Send the message → diff-comment parts are included alongside the message text

@coder-tasks
Copy link
Copy Markdown
Contributor

coder-tasks bot commented Mar 6, 2026

Documentation Check

New Documentation Needed

  • docs/ai-coder/agents/index.md - Add a subsection describing the diff line annotation feature, similar to the existing "Image attachments" section. Users clicking line numbers in the Git diff panel, typing inline comments, and having reference chips added to chat messages is a new interaction pattern worth documenting.

Automated review via Coder Tasks

Copy link
Copy Markdown
Contributor

@DanielleMaywood DanielleMaywood left a comment

Choose a reason for hiding this comment

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

We have a syncing useEffect which might be able to be replaced but that can be a future fix

@kylecarbs kylecarbs force-pushed the diff-comments branch 9 times, most recently from d3ef533 to 8f1538a Compare March 8, 2026 18:46
Users can click line numbers in the Git diff panel to open an inline
prompt input, type a comment, and have a reference chip + text added
to the Lexical chat input. Comments are sent as diff-comment parts
alongside the message.

The diff-comment part includes the actual code content from the diff
lines that were commented on, giving the LLM full context of what
the user is referencing.

- Add DiffCommentContext for managing comment state
- Add DiffCommentNode (Lexical DecoratorNode) for inline chips
- Add InlinePromptInput for annotation-based comment entry
- Add diff-comment handling in backend (coderd/chats.go)
- Add diff-comment rendering in ConversationTimeline
- Add diff-comment parsing in messageParsing.ts
- Extract actual diff code content via extractDiffContent helper
- Sync diff comments bidirectionally between context and Lexical
@kylecarbs kylecarbs merged commit 2ad0e74 into main Mar 8, 2026
27 checks passed
@kylecarbs kylecarbs deleted the diff-comments branch March 8, 2026 19:38
@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants