#1159·gogcli

feat(docs comments): anchored comments via Docs API `insertComment` (track until GA)

Author: ignacioreynaCreated Sep 24, 2026Updated Sep 24, 2026
Labelsissue-rating: 🌊 off-meta tidepoolclawsweeper:no-new-fix-prclawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionP2impact:ux-friction

Recommendation

Don't implement this while insertComment is in Developer Preview. Revisit it when InsertCommentRequest shows up in the public Docs discovery document and in google.golang.org/api/docs/v1, which is an objective GA signal. Until then this issue tracks the capability, and the proposed surface below is the design for that moment.

The small, non-preview fix (warning + help text for --quoted) is tracked separately in #1160.

Motivation

gog docs comments add creates comments through the Drive API (comments.create). Google documents that Workspace editors never render those as anchored:

"Google Workspace editor apps (such as Docs, Sheets, and Slides) don't render comments created with the Drive API anchored to content; they treat these comments as unanchored comments." — https://developers.google.com/workspace/drive/api/guides/manage-comments

In practice it is worse than unanchored when --quoted is used: the comment shows up in the Docs comments panel as "Original content deleted" (observed on gog v0.41.0, 2026-09-24). gog docs comments get shows anchor: null for the API-created comment, while a comment created from the UI on the same doc has anchor: kix.….

This blocks the review workflow agents are good at: "leave a comment on the paragraph that needs X's input". Today the only way to get a real anchored comment is to have someone (human or agent) create it in the UI.

What changed since #585

#585 was closed as out of scope on 2026-05-31 because the only workaround then was browser automation. On 2026-07-08 Google closed the underlying bug (https://issuetracker.google.com/issues/491884714) with:

"Full support for anchored comments in now in public preview for the Docs API."

The Docs API now exposes an insertComment request in documents.batchUpdate, anchored to a body range (https://developers.google.com/workspace/docs/api/how-tos/suggestions):

json
{
  "requests": [
    {
      "insertComment": {
        "content": "This is a comment added via the API.",
        "range": { "startIndex": 10, "endIndex": 25 }
      }
    }
  ]
}

The same page mentions assigneeEmailAddress to assign the comment, plus replies, edits, and deletions.

So this is no longer UI automation. It is a regular Docs API request, which fits the existing docs command surface.

Proposed surface (once GA)

Reuse the anchor flags gog already has for insert / delete / update (#683):

gog docs comments add <docId> <content> --at "literal text" [--occurrence N] [--match-case] [--tab ...]
gog docs comments add <docId> <content> --range START:END [--tab ...]
gog docs comments add <docId> <content> --at "..." --assignee [email protected]
  • With --at / --range: use Docs API insertComment (anchored).
  • Without them: keep the current Drive API path (unanchored), unchanged for existing scripts.
  • --quoted on Google Docs could resolve to a range and go through insertComment too, replacing the #1160 warning.

Why wait: constraints today

  • Developer Preview gating: insertComment is available through the Google Workspace Developer Preview Program. The Cloud project that owns the OAuth client must be enrolled (https://developers.google.com/workspace/preview). Most users can't use it, and when it lands gog should surface a clear error for non-enrolled projects, not a raw 400.

  • Go client: as of today InsertCommentRequest is not in the public Docs discovery document or in google.golang.org/api/docs/v1 (checked against v0.298.0 and main). Implementing now would mean hand-rolled raw JSON for a request shape that may still change.

  • Index resolution: --at can reuse the existing find-range logic, so comments add --at stays consistent with insert --at / delete --at.

  • Live testing: per VISION.md ("Discuss First"), this can't be live-tested from a non-enrolled Cloud project, and I'm not in the preview program. Once GA, the acceptance check is simple: the comment is visible anchored in the Docs UI, and gog docs comments get shows a non-null anchor.

Actionable now

Split out to #1160 (warning + help text fix for --quoted), as suggested in the triage review.

Open questions (for GA)

  • Does insertComment support tabs (range.tabId) and headers/footers/footnotes (segmentId)? The how-to example only shows startIndex / endIndex.
  • Does a mention (@email) in content, or assigneeEmailAddress, trigger the same notification as a UI-created comment?

Related: #1160, #585, #683, #687, #691