Skip to content

feat(docs comments): add locate subcommand to resolve a comment to a body range #687

@sebsnyk

Description

@sebsnyk

Motivation

A comment carries quotedFileContent.value (the literal text the comment was anchored to at creation time). To act surgically on a comment ("delete the text the reviewer flagged", "wrap it in a hyperlink"), the script needs (startIndex, endIndex) in the current doc body. Today every consumer has to roll this resolution themselves, including HTML-entity unescaping (Drive sometimes returns ", &, ', ·, >, <) and whitespace normalisation.

This is the load-bearing primitive for any "comments to automated edits" workflow.

Depends on

Consumed by

  • feat(docs write): pre-flight orphan-comment check on --replace --markdown #691 docs write --check-orphans — the orphan pre-flight runs comments locate per open comment and treats orphaned: true as a "would orphan" hit. Sharing the locate path between the two commands keeps the normalisation rules consistent (a comment that survives --check-orphans is also resolvable by locate after the write).

Repro

# Today:
quote=$(gog drive comments list <DOC_ID> --include-quoted -j --all | jq -r '.comments[0].quotedFileContent.value')
# Then manually walk gog docs raw to find the index range. About 30 lines of jq/awk.

Proposed surface

gog docs comments locate <docId> <commentId> [--tab=...]

JSON output:

{
  "commentId": "AAAA...",
  "matches": [
    {"startIndex": 1234, "endIndex": 1267, "tabId": "kix.abc"}
  ],
  "orphaned": false,
  "quote": "the literal text the comment was anchored to"
}

Returns orphaned: true and an empty matches array when the quoted text no longer appears in the body.

Acceptance criteria

  • Returns the correct range for the most recent edit-state of the doc.
  • Reports orphaned comments cleanly (no error; flag in payload + exit code 4 in plain mode).
  • Handles the entity-encoded quote cases (&quot;, &amp;, &#39;, &#183; etc.) without manual decoding.
  • Works in tabs via --tab resolution.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions