Skip to content

Chat: comment on selected text in an agent's reply, and send the comments with the next message #511

Closed

Description

@aNNdii

Updated 2026-10-29: rewritten for the design as it works now on my fork. The first version of this description (inline cards with a Pending badge) is in the edit history; what changed is summarized in the comment below.

Problem

I work spec first: before an agent writes code, it writes a plan or a spec, and I review it. Most of my answers are remarks on single points ("batch this", "ask instead"). Today each one means:

  1. copy the passage
  2. paste it into the message box and quote it by hand
  3. write the remark under it
  4. repeat for every point

On a phone, that is a long-press selection, copy, scrolling down to the message box and paste, for every point. If I skip the quotes, the agent has to guess which remark belongs to which step. The same holds for a spec the agent wrote into a file, and for code.

Proposal

Comment on an agent's reply, a Markdown file or code the way a code review comments on a diff: select text, write a comment, and send all comments together with the next message.

Comment mode

  • One toggle switches commenting on for the whole app: in the chat it sits at the top right (beside Find), in the file viewer in the header. Its badge counts the comments of this pane or this file.
  • Off, text selects as it does today, with the system's selection and menu, for copying. Saved comments still show, read-only.
  • On, a selection is a comment's text. Nothing in the chat moves while text is selected: no row joins the composer, the button floats over the text.

Writing a comment

  • With a mouse, a pen or the keyboard (Shift+arrows), letting go of a selection shows a floating Comment button under it. Its click opens a small field at the selection, above or below it, so it does not cover the words it is about. Settings can open the field at once instead.
  • Enter saves, Shift+Enter breaks the line. Leaving the field (Escape, a click outside) saves what was typed; an emptied comment is deleted. There is no Cancel.
  • Several selections in one paragraph are several comments. One selection across several paragraphs or list items is one comment. User messages, a reply that is still streaming and the narration between tool calls take none.
  • Every comment's text keeps a soft highlight (CSS Custom Highlight API, so the reply's DOM is not changed); where comments overlap, the text reads darker.

Where comments show

  • Beside the text, in the free space right of it: cards in the margin where there is room, else counts beside the lines (a small speech bubble with the number). The text never moves or narrows for them.
  • A click on a card or a count opens the comment to edit, in place. Pointing at one brings its text forward.

Phones and tablets

  • In comment mode, a long press selects a word and shows two handles and a Comment pill where the system menu would be. This is the app's own selection: the system's Copy/Share menu cannot be turned off while keeping its selection. With the mode off, the system's selection is back.
  • The comment is written in a bottom sheet that quotes the selected text.

Files

  • Markdown preview: works as the chat does, with a selection.
  • Code: a ⊕ beside the line number opens a field under the line (or a click on the line, as Settings say); arrows move the ⊕ for the keyboard. On a phone, a long press or a tap opens it, in a bottom sheet or under the line. The quote names the file and lines.
  • Comments on files join the comments of the pane the file was opened from.

The message box and the comments panel

  • A bar above the text says "2 comments on the reply". Its X removes them all.
  • A tap on the bar opens the comments panel: every comment of the pane that goes with the next message, grouped by where it is (the reply, then each file), each with its quote, editable in place, deletable with Undo, and a link to its place. Docked beside the panes on a desktop, a sheet on a phone.

Sending

  • The next message sends the comments first, in reading order, each as a quote of its text and then the comment. The typed text comes after them, and a message may be comments alone:

    > backfill it from updated_at
    Backfill in batches of 1,000, the table has 40 million rows.
    
    > docs/spec.md:14
    > Older revision | 409 Conflict with the stored note
    Also return the stored revision, so the client can show what changed.
    
    > src/sync.ts:7-9
    > if (incoming.revision < stored.revision) {
    Compare with <=, a replayed write reuses the revision.
    
    Go ahead with step 1.
    
  • A slash command, or an answer to the agent's open question, goes without the comments. They wait for the next message, and the bar says "2 comments waiting".

  • Comments only ever go to an agent. In a pane without an agent, the typed text goes alone, because a shell would run > quote as a redirect. The submit carries an agent_only flag, and the server refuses it when no agent runs in the pane. A queued message keeps that rule, so it stays in the queue instead of being typed into a shell.

Storage

  • Comments are kept per pane on this device, in localStorage. Reply comments and file comments share one store and one anchor model: the text (or lines) a comment is on, its offsets in the block, and the block's content.
  • A comment shows only while its text still reads the same, so a changed reply or file never marks the wrong place. A comment whose text is gone stays in the panel with its quote.

Settings → Comments (a page of its own, all per device)

Setting Options Default
Comments the whole feature; turning it off with comments saved asks first and deletes them On
When you select text Show a Comment button · Open the comment field Button
Comments beside the text Cards in the margin · Counts beside the lines Cards
Click a line to comment (code) a click anywhere on a line, or only the ⊕ Off
On mobile, comment with (code) Long press · Tap Long press
On mobile, write comments in (code) Bottom sheet · Below the line Bottom sheet

Screenshots

From my fork's demo, dark theme. The demo has no file contents, so the files were filled in for the shots.

Comment mode on: select text, a Comment button floats under it The field opens at the selection
Image Image
Saved: highlights, cards in the margin, the bar in the message box A command: the comments wait
Image Image
What the agent gets No room for cards: counts beside the lines
Image Image
Markdown preview in the file viewer (a count: the dialog has no room for cards) Code: the ⊕ beside the line number, a saved comment under its line
Image Image
The comments panel: the reply, then each file
Image
Phone: long press, handles and the Comment pill Phone: the sheet Phone: saved
Image Image Image

What changes outside the client

  • the optional agent_only flag on submit, and a submit-agent-only server feature, in shared/protocol.ts and server/core/composer.ts, with a contract test
  • typed: false on a submit or pending result when nothing reached the pane
  • the same answers from the demo transport

The comments themselves add no dependency.

Not in this issue

  • A Git view (a repository's tree beside a file or its diff): my fork has one, and the comments work there the same way (a comment below shows it). The view itself is separate and would need its own implementation.
  • Tags on comments (@vibewriter-hand's good / bad / adopt list): not built. The store has room for it.

Where

Chat, file viewer

Workarounds and alternatives

Implementation

It is built on aNNdii/herdr-web-ui next, kept in sync with main (last merge: up to #2291). Most of it lives in files of its own (MarkdownComments.tsx, ChatComments.tsx, CommentMargin.tsx, CommentPopover.tsx, CommentsPanel.tsx, TouchSelection.tsx, lib/blockComments.ts, lib/fileComments.ts, …), with browser regressions (scripts/block-comments-regression.ts, scripts/file-viewer-comments-regression.ts), DESIGN.md sections and ko/ja/zh translations.

It is too big for one PR. If the shape is wanted, I would bring it in as a stack, each usable on its own:

  1. the store, the anchors and sending (agent_only, the bar, the quotes)
  2. comments on a reply in the chat (comment mode, selection, highlights, margin)
  3. touch: the app's selection and the sheet
  4. comments on files: the Markdown preview and code lines
  5. the comments panel and Settings → Comments

Questions:

  1. Is this shape (comment mode, a selection, comments beside the text, sent with the next message) what you want in the chat?
  2. Is the agent_only flag on submit fine as the guard against sending quotes into a shell?
  3. Would you take it as the stack above, or rather a different cut?

Activity

  1. aNNdii commented on Oct 14, 2026

    @aNNdii
    ContributorAuthor

    Update: comments on code in the file viewer

    The follow-up from "Later, not built yet" is built for code. It is on aNNdii/herdr-web-ui feat/code-view-comments, merged into my fork's next in aNNdii/herdr-web-ui#19. It doesn't use a text selection. It works like Claude's code preview: a ⊕ beside the line number opens a field under the line, and a saved comment stays in the code as a card. The Markdown preview keeps the selection, as described above.

    Comments on code join the pane's comment bar, the same bar as the chat's, and are sent with the next message:

    > src/sync.ts:23
    > if (incoming.revision < stored.revision) {
    Compare with <=, a replayed write reuses the revision.
    

    How it works

    • Comment mode:
      • The viewer's comment counter becomes a toggle in its header, with the file's comment count as a badge.
      • The mode is off by default and remembered per device.
      • While it is off, the code selects and copies as before, and the cards are read-only.
    • Mouse:
      • The ⊕ sits on the hovered line, on a thin divider between the line numbers and the code.
      • It opens a field under the line. Cmd/Ctrl+Enter saves, and Escape closes the field while it is empty.
      • A click on a card edits it.
      • Optional: a click anywhere on the line opens the field (see Settings below).
    • Keyboard:
      • The ⊕ is one Tab stop.
      • The arrow keys, PageUp/PageDown and Home/End move it.
      • Enter or Space opens the field, and the focus goes back to the ⊕ when the field closes.
    • Phones and tablets:
      • A long press on a line opens the field, or a tap (see Settings below).
      • You write in a bottom sheet, or in a field under the line.
      • There is no ⊕ for a finger.
    • Unchanged: anchoring and storage. A comment still shows only while its lines read the same. The change is client-only: nothing in shared/ or server/ changes.

    Settings

    Settings → File viewer gets a new Comments group. Like every comment feature, it follows the existing master switch in Settings → Chat → Comments: while that is off, the group is greyed out and links to it.

    Setting Options Default
    Click a line to comment With a mouse: a click anywhere on a line opens a comment. Off: only the ⊕ beside the line number. Off
    On mobile, comment with Long press or Tap: how a phone or tablet comments on a line while comment mode is on. Long press
    On mobile, write comments in Bottom sheet (the field and the quoted line over the keyboard, like the app's other sheets) or Below the line (the field in the code, as on a desktop). Bottom sheet

    The comment mode itself is switched from the viewer's header, not from Settings, and is remembered per device like the other settings. All settings are per device, in localStorage, and translated into ko/ja/zh.

    Settings → File viewer → Comments
    Image
    Hover: the ⊕ beside the line number Writing under the line
    Image Image
    Saved: cards under their lines The comments wait in the message box
    Image Image
    Phone: a long press opens the sheet Phone: saved
    Image Image

    Long files (20,000 lines)

    The viewer loads the first 256 KB of a file, so a 20,000-line file with short lines opens in full. Commenting has to stay fast there, and in the first version it didn't. The main changes:

    • Chunks: the code is drawn in chunks of 200 lines, so a comment's room lays out one chunk instead of the whole <pre>.
      • The line numbers come from each line's data-source-line, not from a CSS counter. With a counter, WebKit renumbered every later line, and Firefox recounted the whole file on every room.
      • Text, copy and innerText stay exactly the file's.
    • The field lives in a same-origin iframe: on iOS Safari the work before the keyboard rises grows with the size of the whole document.
    • The desktop viewer has a fixed height for files longer than one chunk. A viewer that grew with its content made Firefox lay out the whole file again on every room.
    • No content-visibility and no virtualization: both broke Ctrl+F, copy or innerText.
    20,000 lines Before After
    Open the file, desktop (WebKit) 4.3–4.5 s 0.9–2.0 s
    Field opens at ⊕ (WebKit) 364–411 ms 105–135 ms
    Card saved (Chromium / WebKit) 878 / 384 ms 195 / 139 ms
    A room added or removed (WebKit) 163–190 ms 1–5 ms
    Firefox 157 on macOS: open a field / close it / a room 800–1030 / ~300 / 140–280 ms 46–60 / 41–49 / ~30 ms
    Comment mode toggled (Chromium) 476 ms 180 ms
    Keyboard up after tapping a line, iPad ~1.6 s ~0.33 s

    The numbers are in-page timings on the demo. The iPad row was measured on a real iPad, on a lab page that uses the same technique.

    A generated 19,999-line, 240 KB file, around line 18,200
    Image

    Checked so far:

    • A real iPad (Safari) and a Mac (Firefox 157).
    • The browser regression (scripts/file-viewer-comments-regression.ts).

    Not checked yet: iPhone and VoiceOver.

    Known limits:

    • Opening a 20,000-line file still takes 0.9–2 s in WebKit.
    • At the very top of a file, a field closing above the clicked line still moves that line up by the field's height.
  2. added
    enhancement
    on Oct 17, 2026
  3. devtm1123 commented on Oct 20, 2026

    @devtm1123

    Any updates?

  4. devswha commented on Oct 22, 2026

    @devswha
    Owner

    Status from the AoE borrowings plan run (2026-10-22)

    Implemented a narrow first step on the local branch feat/reply-selection-quote (2 commits, not pushed yet). It doesn't close this issue.

    What it does:

    • Selecting text inside one assistant reply offers a "Quote in message" action. The selected visible text is appended to that pane's existing draft as a labelled, fenced quote, then the composer gets focus.
    • It reuses the terminal quote path: same per-pane draft key and the same length limit. A quote that would go over the limit is refused as a whole and the draft stays untouched.
    • Selections that cross into user messages, tool output, prompts or another pane are refused. Native copy and mobile selection handles keep working.
    • Nothing is sent. The user edits the draft and presses Send as usual. Watch mode offers no quote action, and a disconnect keeps the draft without replaying it.
    • No highlight store, comment bar, server endpoint or new wire field.

    Verification: the work was independently reviewed and needs fixes. Still wrong:

    • On phones, pressing the quote button can unpin the selected reply row before the quote is taken, and at the top edge the button can cover the selected text.
    • The browser regression races the demo's timed reply completion, so it isn't deterministic yet.
    • The two independent visual reviews haven't been done.

    Left to do: fix the above, get the visual reviews, then push and open a PR with Refs #511 (not Closes). The full comment workflow this issue describes is still a separate design decision.

  5. vibewriter-hand commented on Oct 26, 2026

    @vibewriter-hand
    Contributor

    I would like to add my use case to this issue.

    I review plans, specifications, research notes and drafts before code is written, on a desktop and on a phone. Three sources matter to me: local Markdown and text files, documents an agent wrote, and selected passages in an agent's reply. For each passage I want a comment and a tag from a short list I maintain — good, bad, improve, reject, adopt — with editable names and order. The record has to stay useful before anything is sent: I want to revisit the passage, the comment and the tag, and then choose what goes into the next message.

    I have read the 2026-10-22 status and the #1845/#1922 history. The selection must stay where it is: a composer row that moves the selected text fails the use case, and on the phone the native selection handles have to keep working.

    Questions I would like to settle before code:

    • Is the whole workflow in scope — comments and custom tags kept as records, with an explicit send — or only the send step?
    • Should reply comments and file comments share one source, anchor and storage model?
    • Device-local records through the host, or the host as the only store so desktop and phone see the same review?
    • How would you stage it: anchoring first, then saved comments, then tags, then delivery?

    Tags are personal labels. They do not edit files, run commands or send anything by themselves.

    Human Review is the closest reference I have found for quote anchoring and batched feedback, and its pure anchor functions may be reusable. Claude Docs shows the value of commenting on a passage of a document. Neither is a drop-in component, and I am not claiming either covers the storage model or the phone.

    A Markdown notes panel is #1196 and the separate write API is #771; I am not mixing those into this issue.

    I need this workflow for my own writing and review, so I intend to build it either way. If the scope fits upstream, I would rather contribute the reply-and-file comment path as a focused PR after the anchor and storage model are agreed, rather than land the whole feature at once. I am not asking for a promise to merge it whole.

  6. phirschybar commented on Oct 28, 2026

    @phirschybar
    Contributor

    A data point from using the quick quote while it was on main (#1845), before #1922 removed it.

    Selecting a passage in a reply and pressing Quote in message was the fastest way I've had to answer a plan point by point, and I'd like that step back. The removal was right for the version that shipped, though. The row joined the composer stack, so the chat moved while I was still dragging, and the selection grew or shrank under the pointer. I often ended up with more or less text than I meant to select.

    That makes me agree with the point above: whatever comes back must not change the layout while a selection is in progress. A floating button drawn over the chat near the selection end (with a mouse, where the button was released, as the original proposal says) takes up no room, so nothing under the selection moves. On a phone it would sit clear of the selection handles and the system menu.

    If the fuller comment workflow needs time to settle, a floating Quote in message that only appends to the draft could be a first step that later becomes the Comment entry point. Happy to help test either on desktop and phone.

  7. aNNdii commented on Oct 29, 2026

    @aNNdii
    ContributorAuthor

    Update: the description now shows the current design

    I rewrote the description above for how the comments work now on my fork, with new screenshots. What changed since the first version:

    • Comment mode. One toggle (in the chat beside Find, and in the file viewer's header) turns commenting on. With it off, text selects and copies as before.
    • Nothing moves while you select. The Comment button floats under the selection, and the field opens above it. This is the point @phirschybar made about feat(chat): quote selected reply text into the editable draft #1845: nothing joins the composer, so the selection stays where it was dragged.
    • Comments sit beside the text, not inside it. Cards in the margin, or counts beside the lines where there is no room. The reply's text never moves or narrows. The inline cards with a Pending badge are gone.
    • Phones use the app's own selection in comment mode (a long press, two handles, a Comment pill) and a bottom sheet to write in. With the mode off, the system's selection and menu are back.
    • Files. The Markdown preview takes selections as the chat does, and code takes comments on lines (the ⊕ from the earlier update).
    • A comments panel opens from the message box's bar, with every comment of the pane, grouped by place, to edit or delete before sending.
    • Settings → Comments is a page of its own.

    @devswha, the narrow first step from your 2026-10-22 status fits this: a floating Quote in message would sit where the Comment button is now, and could become it later.

    @vibewriter-hand, on your questions, from what I have built:

    • Reply comments and file comments share one store and one anchor model: the selected text, its offsets in the block, and the block's content. A comment shows only while its text still reads the same.
    • Storage is device-local (localStorage per pane). A host-side store, so desktop and phone see the same review, would be a good next step, but it is not built.
    • Tags are not built. They would fit as a field on the stored comment.
    • Staging: I proposed a stack in the description: the store and sending first, then the chat, touch, files, and the panel.

    The next comment shows the same comment flow in my fork's Git view, which is separate from this issue.

  8. aNNdii commented on Oct 29, 2026

    @aNNdii
    ContributorAuthor

    The same comments in a Git view

    On my fork, the comments also work in a review of a repository's changes: a Git view with the repository's tree beside a file or its diff. That view is separate and would have to be implemented on its own; it is not part of this issue. It is only here to show that the comment flow is the same there:

    • Select text on a line and press Comment: the same field opens, and a saved comment shows under its line.

    • The quote names the file and the line:

      > src/money.ts:5
      > Math.abs(amount)
      Math.abs drops the sign before rounding; add a test for a negative refund amount.
      
    • The comments join the same bar in the message box and the same comments panel, and go with the next message.

    Writing a comment on a line Saved under its line
    Image Image
    In the comments panel
    Image
  9. 9 remaining items

  10. added a commit that references this issue on Oct 30, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions