Skip to content

feat(docs write): pre-flight orphan-comment check on --replace --markdown #691

@sebsnyk

Description

@sebsnyk

Motivation

A full-body markdown rewrite (gog docs write --replace --markdown --file=...) silently leaves any comment anchored to a phrase that disappears from the body as "orphaned". The comment is still attached to the file but is no longer anchored to live content, which is invisible until a reader notices. For docs collaborating with reviewers, this is a credibility leak: their notes effectively vanish.

The Docs API already returns quotedFileContent on comments.list, so a pre-flight check is straightforward: for every open comment, look up its quote, normalise whitespace + HTML entities, and check whether it survives in the incoming body.

Pairs with

Repro

# Reviewer leaves a comment on the phrase "rule extensions".
# Author rewrites the body and accidentally drops the phrase:
gog docs write <DOC_ID> --replace --markdown --file new.md
# Comment is now orphaned. Author has no idea.

Proposed surface

gog docs write <docId> --replace --markdown --file <md> --check-orphans
gog docs write <docId> --replace --markdown --file <md> --allow-orphans

Default behaviour change candidate: warn-on-orphan (with --allow-orphans to silence), or strict block-on-orphan (with --allow-orphans to override). Pick whichever fits the project's policy on backward-compat.

The pre-flight logic:

  1. Read comments.list for the doc, including quotedFileContent.
  2. For each open (unresolved) comment, take quotedFileContent.value, HTML-entity-decode it, normalise whitespace.
  3. Apply the same normalisation to the incoming markdown body.
  4. If the quote does not appear, mark the comment as "would orphan" and either warn or refuse.

Exit code 5 (or another well-defined non-zero) when orphans would happen and --allow-orphans was not given.

Acceptance criteria

  • Detects orphans on a 3-reviewer test doc with mixed entity-encoded quotes (&#39;, &quot;, &amp;).
  • Reports the orphaned comments grouped by author with the first 80 chars of the comment content + the first 60 chars of the quote.
  • --allow-orphans proceeds silently.
  • Resolved comments are skipped.
  • Works under --tab= resolution.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-risk cleanup, docs, polish, ergonomics, or speculative feature.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm 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.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    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