Skip to content

fix(docs): make structured edits revision-safe - #447

Closed
hentt30 wants to merge 1 commit into
gemini-cli-extensions:mainfrom
hentt30:cursor/safe-docs-mcp
Closed

hentt30 wants to merge 1 commit into
gemini-cli-extensions:mainfrom
hentt30:cursor/safe-docs-mcp

Conversation

@hentt30

@hentt30 hentt30 commented Sep 23, 2026

Copy link
Copy Markdown

Problem

docs.replaceText renders a tab to plain text, then uses offsets in that rendered string as Google Docs API indexes. Those coordinate systems diverge around rich links/person chips, tables, and other structural elements, so a replacement can delete adjacent content. It also writes without requiredRevisionId, allowing a concurrent edit to shift ranges between read and write.

Change

  • resolve literal matches from real paragraph-element startIndex / endIndex
  • apply multiple replacements from highest index to lowest
  • lock writes with writeControl.requiredRevisionId
  • return explicit match counts, including no-op
  • add structure/preview/section-replacement tools with unique heading anchors, expected text, and revision checks
  • document safe section-edit flow

Verification

  • npm test: 630 passed, 1 skipped
  • npm run lint
  • npm run format:check
  • npm run build
  • live disposable Google Doc integration: rich link, table, two tabs, styled headings; section replacement preserved content outside the selected range

@google-cla

google-cla Bot commented Sep 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@hentt30 hentt30 closed this Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant