mcp-gee-sweet 0.9.2.dev349__tar.gz → 0.9.2.dev351__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/PKG-INFO +1 -1
  2. mcp_gee_sweet-0.9.2.dev351/docs/design/doc-replace-backup.md +86 -0
  3. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/index.md +1 -0
  4. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/docs_content.md +80 -0
  5. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/roadmap.md +1 -1
  6. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/content.py +245 -36
  7. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/markdown_export.py +6 -6
  8. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_content.py +391 -2
  9. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/cleanup-worktrees.md +0 -0
  10. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/merge-pr.md +0 -0
  11. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/notify-kai.md +0 -0
  12. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/notify-partner.md +0 -0
  13. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/orchestrator.md +0 -0
  14. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/prep-for-pr.md +0 -0
  15. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/qa-kickoff.md +0 -0
  16. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/release.md +0 -0
  17. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/retro.md +0 -0
  18. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/roadmap-status.md +0 -0
  19. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/security-advisory.md +0 -0
  20. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/start-worktree.md +0 -0
  21. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/team-member.md +0 -0
  22. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/commands/verify-pr.md +0 -0
  23. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/settings.json +0 -0
  24. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/amy.md +0 -0
  25. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/aziz.md +0 -0
  26. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/bob.md +0 -0
  27. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/dev.md +0 -0
  28. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/joy.md +0 -0
  29. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/kai.md +0 -0
  30. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.claude/team-roles/qa.md +0 -0
  31. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.dockerignore +0 -0
  32. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  33. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  34. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  35. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/dependabot.yml +0 -0
  36. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/workflows/ci.yml +0 -0
  37. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/workflows/docs.yml +0 -0
  38. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/workflows/publish-dev.yml +0 -0
  39. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.github/workflows/release.yml +0 -0
  40. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.gitignore +0 -0
  41. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.pre-commit-config.yaml +0 -0
  42. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/.python-version +0 -0
  43. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/CHANGELOG.md +0 -0
  44. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/CLAUDE.md +0 -0
  45. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/CODE_OF_CONDUCT.md +0 -0
  46. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/CONTRIBUTING.md +0 -0
  47. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/Dockerfile +0 -0
  48. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/LICENSE +0 -0
  49. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/Makefile +0 -0
  50. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/README.md +0 -0
  51. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/SECURITY.md +0 -0
  52. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docker-compose.yml +0 -0
  53. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/assets/logo.png +0 -0
  54. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/auth.md +0 -0
  55. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/client-setup.md +0 -0
  56. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/configuration.md +0 -0
  57. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-async-tool-execution.md +0 -0
  58. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-auth-status-limitation-categories.md +0 -0
  59. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-cache-invalidation.md +0 -0
  60. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-chart-theming.md +0 -0
  61. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-comments-first-class.md +0 -0
  62. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-composite-tools.md +0 -0
  63. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-condition-type-docstring-generation.md +0 -0
  64. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-converted-doc-change-detection.md +0 -0
  65. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-dev-team.md +0 -0
  66. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-docs-formatting.md +0 -0
  67. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-fork.md +0 -0
  68. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-gmail-domain.md +0 -0
  69. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-grid-data-size-cap.md +0 -0
  70. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-local-fs-test-harness.md +0 -0
  71. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-mcp-v2-resource-context-access.md +0 -0
  72. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-pillow-image-dependency.md +0 -0
  73. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-prompt-qa-role.md +0 -0
  74. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-publishing.md +0 -0
  75. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-release-docs-roles.md +0 -0
  76. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-repositioning.md +0 -0
  77. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-response-size-cap-generalization.md +0 -0
  78. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-response-size-cap-reevaluation-519.md +0 -0
  79. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-review-finding-ticket-bar.md +0 -0
  80. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-supports-all-drives-lint-check.md +0 -0
  81. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-sync-folder-recursion.md +0 -0
  82. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-testing.md +0 -0
  83. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/decision-tool-error-visibility.md +0 -0
  84. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/index.md +0 -0
  85. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/decisions/role-file-history.md +0 -0
  86. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/blockquote-representation.md +0 -0
  87. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/borderless-table-columns.md +0 -0
  88. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/doc-revision-export.md +0 -0
  89. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/doc-to-markdown.md +0 -0
  90. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/docs-ast-pipeline.md +0 -0
  91. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/effectiveformat-spike.md +0 -0
  92. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/heading-anchor-resolution.md +0 -0
  93. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/image-conversion.md +0 -0
  94. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/local-file-access-policy.md +0 -0
  95. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/markdown-support.md +0 -0
  96. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/module-history.md +0 -0
  97. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/oauth-reauthorize-from-tool-call.md +0 -0
  98. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/phase3-theme-system.md +0 -0
  99. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design/sse-consent-off-event-loop.md +0 -0
  100. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/design.md +0 -0
  101. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/index.md +0 -0
  102. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/known-limitations.md +0 -0
  103. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/notes-read.md +0 -0
  104. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/README.md +0 -0
  105. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/qa-fixture-pixel.png +0 -0
  106. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-d195-create-doc.md +0 -0
  107. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-d196-create-doc.html +0 -0
  108. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-d213-dollar-escape.md +0 -0
  109. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-d226-heading-table.md +0 -0
  110. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc102-image-conversion.html +0 -0
  111. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc103-image-conversion.md +0 -0
  112. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc104-nested-lists.html +0 -0
  113. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc105-nested-lists-gfm.md +0 -0
  114. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc106-nested-lists-4space.md +0 -0
  115. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc135-paragraph-boundary.md +0 -0
  116. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc136-interrupted-block-boundary.md +0 -0
  117. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc137-inline-hr-no-block-ancestor.html +0 -0
  118. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc138-nbsp-spacer-paragraph.md +0 -0
  119. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc141-mismatched-list-tags.html +0 -0
  120. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc142-heading-anchors.md +0 -0
  121. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc144-anchor-in-table-cell.md +0 -0
  122. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures/tc-doc145-anchor-on-first-element.md +0 -0
  123. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/fixtures.template.md +0 -0
  124. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/gmail-test-plan.md +0 -0
  125. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/operations.yaml +0 -0
  126. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/playwright_oauth.md +0 -0
  127. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/.gitkeep +0 -0
  128. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-02.md +0 -0
  129. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-14.md +0 -0
  130. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-17.md +0 -0
  131. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-18.md +0 -0
  132. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-21-drive-discovery.md +0 -0
  133. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-21-sheets-delete-clear.md +0 -0
  134. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-06-28.md +0 -0
  135. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-07-04-docs.md +0 -0
  136. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-07-04-drive-smoke.md +0 -0
  137. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-07-04-infra.md +0 -0
  138. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-07-04-sheets_read.md +0 -0
  139. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-07-04.md +0 -0
  140. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/results/2026-09-04.md +0 -0
  141. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/retro-v0.8.0.md +0 -0
  142. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/retro-v0.9.0.md +0 -0
  143. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/run.md +0 -0
  144. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/runs/README.md +0 -0
  145. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/runs/v0.8.0.md +0 -0
  146. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/runs/v0.8.1.md +0 -0
  147. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/runs/v0.9.0.md +0 -0
  148. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/runs/v0.9.1.md +0 -0
  149. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/setup.md +0 -0
  150. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/calendar.md +0 -0
  151. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/docs_layout.md +0 -0
  152. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/docs_style.md +0 -0
  153. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/docs_tables.md +0 -0
  154. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/drive_activity.md +0 -0
  155. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/drive_files.md +0 -0
  156. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/drive_sharing.md +0 -0
  157. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/drive_transfer.md +0 -0
  158. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/gmail.md +0 -0
  159. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/infra.md +0 -0
  160. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/sheets_charts.md +0 -0
  161. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/sheets_mgmt.md +0 -0
  162. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/sheets_read.md +0 -0
  163. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/qa/tests/sheets_write.md +0 -0
  164. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/style-guide.md +0 -0
  165. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/docs/tools.md +0 -0
  166. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/mkdocs.yml +0 -0
  167. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/pyproject.toml +0 -0
  168. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/pyrightconfig.json +0 -0
  169. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/check_supports_all_drives.py +0 -0
  170. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/gen_tool_docs.py +0 -0
  171. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/lane_context_hook.py +0 -0
  172. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/oauth_setup.py +0 -0
  173. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/qa_cancel_insert_local_images.py +0 -0
  174. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/qa_gmail_fixtures.py +0 -0
  175. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/qa_revision_temp_doc_parent.py +0 -0
  176. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/setup_team.sh +0 -0
  177. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/scripts/write_team_mcp_configs.sh +0 -0
  178. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/server.json +0 -0
  179. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/.env.template +0 -0
  180. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/__init__.py +0 -0
  181. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/auth.py +0 -0
  182. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/cache.py +0 -0
  183. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/http_transport.py +0 -0
  184. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/reauth.py +0 -0
  185. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/server.py +0 -0
  186. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/sse_shutdown.py +0 -0
  187. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/__init__.py +0 -0
  188. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/atomic_write.py +0 -0
  189. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/cache.py +0 -0
  190. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/calendar.py +0 -0
  191. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/concurrency.py +0 -0
  192. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/__init__.py +0 -0
  193. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/anchors.py +0 -0
  194. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/ast.py +0 -0
  195. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/ast_to_markdown.py +0 -0
  196. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/comments.py +0 -0
  197. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/doc_to_ast.py +0 -0
  198. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/editing.py +0 -0
  199. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/emitter.py +0 -0
  200. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/html_parser.py +0 -0
  201. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/images.py +0 -0
  202. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/indices.py +0 -0
  203. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/layout.py +0 -0
  204. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/named_ranges.py +0 -0
  205. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/style.py +0 -0
  206. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/docs/tables.py +0 -0
  207. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/drive/__init__.py +0 -0
  208. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/drive/activity.py +0 -0
  209. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/drive/files.py +0 -0
  210. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/drive/sharing.py +0 -0
  211. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/drive/transfer.py +0 -0
  212. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/gmail.py +0 -0
  213. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/http_errors.py +0 -0
  214. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/mime_types.py +0 -0
  215. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/pagination.py +0 -0
  216. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/response_limits.py +0 -0
  217. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/sheets/__init__.py +0 -0
  218. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/sheets/data.py +0 -0
  219. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/sheets/helpers.py +0 -0
  220. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/src/mcp_gee_sweet/tools/sheets/structure.py +0 -0
  221. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/__init__.py +0 -0
  222. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/conftest.py +0 -0
  223. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/drive/__init__.py +0 -0
  224. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/drive/test_activity.py +0 -0
  225. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/drive/test_files.py +0 -0
  226. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/drive/test_sharing.py +0 -0
  227. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/drive/test_transfer.py +0 -0
  228. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/fakes.py +0 -0
  229. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/integration/__init__.py +0 -0
  230. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/integration/conftest.py +0 -0
  231. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/integration/test_local_fs_harness.py +0 -0
  232. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/sheets/__init__.py +0 -0
  233. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/sheets/test_data.py +0 -0
  234. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/sheets/test_helpers.py +0 -0
  235. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/sheets/test_structure.py +0 -0
  236. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_atomic_write.py +0 -0
  237. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_auth.py +0 -0
  238. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_cache.py +0 -0
  239. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_calendar.py +0 -0
  240. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_check_supports_all_drives.py +0 -0
  241. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_concurrency.py +0 -0
  242. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_anchors.py +0 -0
  243. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_comments.py +0 -0
  244. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_core.py +0 -0
  245. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_editing.py +0 -0
  246. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_images.py +0 -0
  247. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_indices.py +0 -0
  248. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_layout.py +0 -0
  249. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_markdown_export.py +0 -0
  250. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_named_ranges.py +0 -0
  251. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_revision_export.py +0 -0
  252. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_style.py +0 -0
  253. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_docs_tables.py +0 -0
  254. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_gen_tool_docs.py +0 -0
  255. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_gmail.py +0 -0
  256. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_http_errors.py +0 -0
  257. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_lane_context_hook.py +0 -0
  258. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_mime_types.py +0 -0
  259. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_qa_gmail_fixtures.py +0 -0
  260. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_reauth.py +0 -0
  261. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_response_limits.py +0 -0
  262. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_server.py +0 -0
  263. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_server_json.py +0 -0
  264. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_sse_shutdown.py +0 -0
  265. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/tests/test_team_mcp_configs.py +0 -0
  266. {mcp_gee_sweet-0.9.2.dev349 → mcp_gee_sweet-0.9.2.dev351}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mcp-gee-sweet
3
- Version: 0.9.2.dev349
3
+ Version: 0.9.2.dev351
4
4
  Summary: MCP server for Google Workspace — Sheets, Drive, Docs (HTML or Markdown), and Calendar.
5
5
  Project-URL: Homepage, https://github.com/khuisman/mcp-gee-sweet
6
6
  Project-URL: Bug Tracker, https://github.com/khuisman/mcp-gee-sweet/issues
@@ -0,0 +1,86 @@
1
+ # Design: Backup Copy Before Replacing a Doc's Content
2
+
3
+ **Status:** Implemented. Issue #878. Live-verified against real Drive/Docs API calls via scratch
4
+ scripts per `CLAUDE.md`'s "Verify a ticket's API premise live" convention (2026-10-12).
5
+
6
+ ## Problem
7
+
8
+ `write_doc_content` and `update_doc_from_file` share `_replace_doc_content`
9
+ (`tools/docs/content.py`). It clears the doc in its own `batchUpdate` and then writes the new
10
+ content in later calls. The clear has to be separate because of the same-batch `insertText`
11
+ style-inheritance quirk. If anything after the clear fails (the content `batchUpdate`, a non-image
12
+ retry failure, `fill_tables`, anchor resolution), the original content is already gone, and the
13
+ error didn't say so.
14
+
15
+ ## The decision that didn't survive measurement
16
+
17
+ The issue was triaged on 2026-10-04 to record the doc's current Drive revision ID before the clear,
18
+ and to name it in the error for recovery with `export_revision`. Restoring the old content by
19
+ re-inserting a snapshot was ruled out, because formatting, images, and tables don't round-trip.
20
+
21
+ Measured live before implementing:
22
+
23
+ | Case | Revisions before the clear | Right after the clear | `revisions.get` on the recorded ID |
24
+ |---|---|---|---|
25
+ | Doc written 5 s before the clear | `1, 3` (3 exported the original text) | `1, 4` | 404 at +0 s, +30 s, +2, +5, +8 min |
26
+ | Doc idle for 7 min before the clear | `1, 3` (same) | `1, 4` | 404 at +0 s, +30 s, +2, +5, +8 min |
27
+
28
+ Docs merges the revision that was current before the clear into the clear's own new revision
29
+ straight away, however old it is. The pre-clear content is no longer reachable through the
30
+ revisions API, so an error naming that revision would point at a 404. This matches the merge
31
+ behavior `doc-revision-export.md` recorded, except that here it happened immediately rather than
32
+ after a later edit.
33
+
34
+ ## Decision (maintainer, 2026-10-12)
35
+
36
+ Copy the doc with Drive (`files.copy`) before the clear. A copy is the real document, so formatting,
37
+ images, and tables survive, which a re-inserted snapshot wouldn't.
38
+
39
+ - **Only a doc with content is copied.** An empty doc (`endIndex <= 2`) has nothing to lose and
40
+ isn't cleared.
41
+ - **Name and location.** `"<title> (backup before replace)"`. With no `parents` in the request, the
42
+ copy inherits the source's parents, so it sits next to the doc.
43
+ - **Success:** the copy is removed with `markdown_export._discard_temp_doc`, the same helper
44
+ `export_revision`'s temporary Doc uses. It deletes the copy, or trashes it when `canDelete` is
45
+ false (a Content manager on a Shared Drive, #876), and retries on a 5xx or 429. A failed removal
46
+ doesn't fail the call. The result gets a `warning` naming the copy.
47
+ - **Failure after the clear:** the copy is kept. The result is `{"error", "docId", "backupId"}`
48
+ (plus `images` when there are any), and the error names the copy.
49
+ - **The clear answered with a 4xx (429 included):** the API ran nothing, so the doc is unchanged.
50
+ The copy is removed and the error says so. Anything else from the clear (a 5xx, a timeout, a
51
+ transport error) doesn't say whether it landed, so the copy is kept and the error says the
52
+ content *may have been* cleared. QA reproduced a 503 returned after a clear that had run (PR
53
+ #1017 round 1), which an earlier version treated as rejected, deleting the only copy.
54
+ - **The doc is re-read after the copy.** The copy takes seconds, and a concurrent edit meanwhile
55
+ would otherwise survive the clear (the doc grew) or make it fail (it shrank). A failed re-read
56
+ stops before the clear: the doc is unchanged and the copy is removed. A doc emptied meanwhile
57
+ isn't cleared, and a later failure still names the copy.
58
+ - **The copy fails:** nothing is changed, and an error is returned. A 429 is retried (up to 3 times,
59
+ with backoff), since Drive ran nothing. A 5xx isn't, since the copy may already exist and a
60
+ retry would make a second one. For a failure other than a 4xx, the error names the copy that
61
+ may have been created, so the caller can find and remove it. The exception is
62
+ `storageQuotaExceeded`. A service account can't own a copy of a user-owned doc, and
63
+ `write_doc_content` is the documented way for a service account to write into such a doc
64
+ (`known-limitations.md`'s quota section). That case replaces without a backup and logs a
65
+ warning. If the replace then fails, the error says no backup could be made. Whether other
66
+ permission or limit failures should also fall back to no backup is #1018.
67
+ - **Cancellation:** the copy is created inside a shielded scope, so its ID is always recorded (the
68
+ PR #877 rule). The scope is bounded by `_BACKUP_COPY_TIMEOUT` (60 s, all attempts together), per
69
+ `CLAUDE.md`'s rule that a cancel waits for shielded work; a timeout is reported like a 5xx.
70
+ Once the copy exists, a cancellation keeps it and logs a warning with its ID, since the doc may
71
+ already be cleared and the call has no result left to report it in.
72
+ - **On success,** the copy's removal and the `webViewLink` lookup run together.
73
+
74
+ ## Cost
75
+
76
+ Measured on a 20 KB doc: `files.copy` 2.5–4.0 s, delete 0.8–1.3 s, so about 3.5–5 s added to every
77
+ replace of a non-empty doc. The maintainer accepted this over options with no recovery path.
78
+
79
+ ## Options rejected
80
+
81
+ - **Name the pre-clear revision in the error.** The revision is gone at once (table above).
82
+ - **Snapshot and re-insert on failure.** Formatting, images, and tables don't round-trip (2026-10-04
83
+ triage).
84
+ - **Error message only, no recovery.** A silently emptied doc is real data loss (2026-10-04 triage).
85
+ - **Backup behind an opt-out parameter.** Considered on 2026-10-12. Not chosen: the default would
86
+ have been on anyway, and the latency cost is accepted.
@@ -16,3 +16,4 @@ These are more granular than the [decision records](../decisions/index.md), whic
16
16
  | [Re-authorizing OAuth from the Failing Tool Call](oauth-reauthorize-from-tool-call.md) | 2026-10-06 | #873/#906: a revoked or missing token offers the consent link from the failing call (URL elicitation, or the link in the `ToolError`), detected at `thread_http`'s transport so tools that catch errors are covered, adopted in place on every connection |
17
17
  | [Local-File Access Policy](local-file-access-policy.md) | 2026-10-10 | #796: `LOCAL_FILE_ACCESS=full\|roots\|off` resolved at import from argv (plus an HTTP-request tripwire for launches argv can't see), one `check_read`/`check_write` at each choke point and per entry in folder walks, an identity-based (`samefile`) deny-list of the server's own credential/config/cache/log files, `@tool(local_only=True)` unregistering nine tools in `off` mode, mode and roots reported in `server://auth-status` and the refusal |
18
18
  | [Google Doc Revisions as Markdown](doc-revision-export.md) | 2026-10-11 | #959: `export_revision` on a Doc via DOCX export → temporary Doc → `get_doc_as_markdown`'s own converter (Drive's Markdown and HTML exports measured lossy), heading links and image URLs rewritten so two exports diff cleanly, shielded temp-Doc cleanup |
19
+ | [Backup Copy Before Replacing a Doc's Content](doc-replace-backup.md) | 2026-10-12 | #878: `write_doc_content`/`update_doc_from_file` copy a non-empty doc with `files.copy` before the clear, delete it on success and name it as `backupId` on failure; the planned pre-clear revision ID was measured to 404 right after the clear |
@@ -4305,3 +4305,83 @@ Every capped tool's `local_path` goes through the shared `write_capped_result_to
4305
4305
  **Result (2026-10-11) ✅ PASS — Kit, PR #1000 round 2 (`695d0f9`).** Ran under this job's scratch dir instead of `/tmp`. Step 1 returned `<dir>/new/sub/{DOC_ID}.md`, `bytes_written` 96, and `new/sub` is a directory. Step 2 raised "…has a non-directory path component at '<dir>/blocker'; local_path ends in a path separator or '.', which makes it a directory target…", and `blocker` still holds `keep me`. Step 3 raised the `ValueError` naming `<dir>/blocker`. Step 4 raised "…has a symlink to a missing target at '<dir>/dangling'", and `missing` was not created.
4306
4306
 
4307
4307
  **Result (2026-10-11) ✅ PASS — Kit, PR #1000 round 3 (`290f5bc`).** Ran under this job's scratch dir instead of `/tmp`. Steps 1–4 matched round 2 (step 1 wrote `<dir>/new/sub/{DOC_ID}.md`, 96 bytes; steps 2–4 raised the expected `ValueError`s; `blocker` still holds `keep me`; `missing` not created). Step 5 raised "…has a symlink to a missing target at '<dir>/linkdir/{DOC_ID}.md'", and `elsewhere` was not created.
4308
+
4309
+ ## Backup copy before replacing a doc's content — `write_doc_content` / `update_doc_from_file` (#878)
4310
+
4311
+ ### TC-DOC219: A replace backs the doc up first, removes the backup on success, and names it on failure ⚠️ destructive
4312
+ Before #878, a replace that failed after the clear left the doc empty, and the error didn't say so. Now a doc with content is copied with Drive before the clear (`"<title> (backup before replace)"`, next to the doc). The copy is removed on success and kept and named as `backupId` on failure. No tool call can make the content write fail after a successful clear, so part B injects the failure from a scratch script against the checkout under test. Design: `docs/design/doc-replace-backup.md`.
4313
+
4314
+ Run it on a server whose account can own a copy of `{DOC_ID}`: OAuth, or a service account when `{DOC_ID}` is on a Shared Drive. A service account writing into a My Drive doc gets `storageQuotaExceeded` on the copy, so it replaces without a backup by design, and step 4 then reports "couldn't be backed up" instead of a `backupId`.
4315
+
4316
+ **Setup:** `write_doc_content(doc_id={DOC_ID}, content="<p>TC-DOC219 before</p>")`. Note the doc's `name` from `get_file_metadata(file_id={DOC_ID})`.
4317
+
4318
+ **Steps (part A, tool calls)**
4319
+ 1. `write_doc_content(doc_id={DOC_ID}, content="<h1>TC-DOC219 after</h1><p>Replaced.</p>")`
4320
+ 2. `search_files(query="<name> (backup before replace)")` (the name noted in Setup)
4321
+ 3. `get_doc_content(file_id={DOC_ID})`
4322
+
4323
+ **Steps (part B, scratch script from the checkout under test, same OAuth token as the server under test)**
4324
+
4325
+ 4. Run, with `{DOC_ID}` filled in:
4326
+ ```
4327
+ uv run python3 -c "
4328
+ import asyncio, mcp_gee_sweet
4329
+ from types import SimpleNamespace
4330
+ from unittest.mock import MagicMock, patch
4331
+ from googleapiclient.discovery import build
4332
+ from mcp_gee_sweet import auth
4333
+ from mcp_gee_sweet.tools.docs import content as c
4334
+ creds = auth._oauth_creds()
4335
+ lc = SimpleNamespace(docs_service=build('docs', 'v1', credentials=creds),
4336
+ drive_service=build('drive', 'v3', credentials=creds), doc_cache=MagicMock(), folder_id=None)
4337
+ with patch.object(c, 'fill_tables', side_effect=RuntimeError('injected failure')):
4338
+ print(asyncio.run(c._replace_doc_content(lc, '{DOC_ID}', '<p>TC-DOC219 failed write</p>', 'html',
4339
+ autolink_urls=True, revoke_sharing=True, auto_downscale=False)))
4340
+ "
4341
+ ```
4342
+ 5. `get_doc_content(file_id={BACKUP_ID})`, where `{BACKUP_ID}` is step 4's `backupId`. Part B's mock `doc_cache` leaves the server's cache stale, so call `refresh_cache(doc_id={DOC_ID})` before reading `{DOC_ID}` again.
4343
+
4344
+ **Steps (part C, a 503 returned after the request already ran, PR #1017 QA round 1)**
4345
+
4346
+ 6. Restore some content first: `write_doc_content(doc_id={DOC_ID}, content="<p>TC-DOC219 before C</p>")`. Then run the script below with `MATCH=':batchUpdate'` (the clear), then `refresh_cache(doc_id={DOC_ID})` and `get_doc_content(file_id={DOC_ID})`, then `get_doc_content(file_id=<its backupId>)`.
4347
+ 7. `write_doc_content(doc_id={DOC_ID}, content="<p>TC-DOC219 before C2</p>")`, then run the script with `MATCH='/copy'` (the backup copy), then `refresh_cache(doc_id={DOC_ID})`, `get_doc_content(file_id={DOC_ID})`, and `search_files(query="<name> (backup before replace)")`.
4348
+ ```
4349
+ MATCH=':batchUpdate' uv run python3 -c "
4350
+ import asyncio, os, mcp_gee_sweet
4351
+ from types import SimpleNamespace
4352
+ from unittest.mock import MagicMock, patch
4353
+ from googleapiclient.discovery import build
4354
+ from googleapiclient.errors import HttpError
4355
+ from mcp_gee_sweet import auth
4356
+ from mcp_gee_sweet.tools.docs import content as c
4357
+ creds = auth._oauth_creds()
4358
+ lc = SimpleNamespace(docs_service=build('docs', 'v1', credentials=creds),
4359
+ drive_service=build('drive', 'v3', credentials=creds), doc_cache=MagicMock(), folder_id=None)
4360
+ real = c.execute_in_thread
4361
+ async def after_commit(fn, service):
4362
+ result = await real(fn, service)
4363
+ if os.environ['MATCH'] in getattr(getattr(fn, '__self__', None), 'uri', ''):
4364
+ raise HttpError(resp=MagicMock(status=503), content=b'{}')
4365
+ return result
4366
+ with patch.object(c, 'execute_in_thread', after_commit):
4367
+ print(asyncio.run(c._replace_doc_content(lc, '{DOC_ID}', '<p>TC-DOC219 part C</p>', 'html',
4368
+ autolink_urls=True, revoke_sharing=True, auto_downscale=False)))
4369
+ "
4370
+ ```
4371
+
4372
+ **Checks**
4373
+ - Step 1 returns `docId` and `web_link`, with no `error`, `backupId`, or `warning`
4374
+ - Step 2 finds no file: the backup was removed (deleted, or trashed on a Shared Drive where the account can't delete, #876)
4375
+ - Step 3 shows "TC-DOC219 after" and "Replaced.", and no "TC-DOC219 before"
4376
+ - Step 4 prints `{"error": "doc edit failed: injected failure. The document's previous content was cleared first; a full copy of it is kept as '<name> (backup before replace)' (backupId).", "docId": "{DOC_ID}", "backupId": "..."}`
4377
+ - Step 5 shows "TC-DOC219 after" and "Replaced.", the content from before step 4's failed write
4378
+ - Step 6's script prints an error containing "may have been cleared" and a `backupId`. `{DOC_ID}` reads empty, and the `backupId` doc shows "TC-DOC219 before C": the backup was kept, not deleted
4379
+ - Step 7's script prints "Couldn't back up the document before replacing its content, so it was left unchanged" ending in "A copy named '<name> (backup before replace)' may still have been created next to the document; check for it and delete it". `{DOC_ID}` still shows "TC-DOC219 before C2", and `search_files` finds that copy
4380
+
4381
+ **Cleanup:** `delete_file` on `{BACKUP_ID}`, step 6's `backupId`, and the copy step 7's `search_files` found, then write fixture content back over `{DOC_ID}`
4382
+
4383
+ **Result (2026-10-12) ❌ FAIL — Sky, PR #1017 round 1 (`94b1ddd`).** Ran on a scratch doc on the QA Shared Drive (OAuth), not the shared fixture doc, and part B used the script with the server's env loaded from this slot's MCP config. Part A passed: step 1 returned `docId`/`web_link` only; step 2 found no backup; step 3 showed the new content. Part B passed: step 4 printed the expected error with a `backupId`, step 5 showed the pre-failure content, and the same `search_files` query from step 2 found that kept backup (a positive control for step 2). The case fails on two extra probes run with the same script, `execute_in_thread` patched to raise `HttpError` 503 after the real call had already gone through. (a) On the clear: it returned "Couldn't clear the document, so it was left unchanged" and removed the backup, but a fresh `get_doc_content` (after `refresh_cache`) showed the doc empty: data loss (review finding 1). (b) On the `files.copy`: it returned "Couldn't back up… left unchanged" with no file ID, while a `(backup before replace)` copy now existed next to the doc (finding 5). `update_doc_from_file` replace on the same doc: new content written, no backup left behind. Note: part B's mock `doc_cache` leaves the server's cache stale, so call `refresh_cache(doc_id=…)` before step 5-style reads of `{DOC_ID}`. Cleanup done: the scratch doc and both kept copies were trashed.
4384
+
4385
+ **Result (2026-10-13) ✅ PASS — Sky, PR #1017 round 2 (`e6f0902`).** Ran on a fresh scratch doc on the QA Shared Drive (OAuth). The scripts loaded the server's env from this slot's MCP config. Part A: step 1 returned `docId`/`web_link` only, step 2 found no backup, step 3 showed the new content. Part B: step 4 printed the expected "cleared first" error with a `backupId`, and step 5 showed "TC-DOC219 after / Replaced.". Part C step 6 (503 after the clear landed): "…may have been cleared; a full copy of it is kept…" with a `backupId`. After `refresh_cache`, `{DOC_ID}` read empty and the backup showed "TC-DOC219 before C". Step 7 (503 after the copy landed): "…left unchanged… A copy named '<name> (backup before replace)' may still have been created next to the document; check for it and delete it". `{DOC_ID}` still showed "TC-DOC219 before C2", and `search_files` found the copy. The 503 text in steps 6–7 shows the script's `MagicMock` reason, a script artifact. Extra probe: `_BACKUP_COPY_TIMEOUT` patched to 3 s, with the copy's worker thread blocking 15 s after the real copy. The coroutine returned after 3.7 s with "…left unchanged: TimeoutError. A copy named … may still have been created…", so the bound cancels the wait on the thread. `asyncio.run` still waited for the thread at exit, which is expected in a script. Each timeout run left the copy it warned about. Cleanup done: the scratch doc and all five copies were trashed.
4386
+
4387
+ **Result (2026-10-13) ✅ PASS — Sky, PR #1017 round 3 (`b78faab`).** Re-verification of the round-2 cache fix. Part A ran on a fresh scratch doc on the QA Shared Drive (OAuth), with the cache warmed by a `get_doc_content` before step 1 and no `refresh_cache` before step 3. Step 1 returned `docId`/`web_link` only, step 2 found no backup, and step 3 showed "TC-DOC219 after / Replaced.", so the write invalidated the cached pre-write content. Parts B and C weren't re-run: the fix only moves `mark_dirty` on the success path, and both parts passed in round 2. The lookup-failure path is covered by the new unit assertion. Cleanup done: the scratch doc was trashed.
@@ -209,7 +209,7 @@ Same shape as v0.8.1 — stabilize on defects that surfaced since v0.9.0 shipped
209
209
  - [ ] `create_spreadsheet`/`import_csv_to_sheet` response has no web link, unlike sibling create/copy tools — enhancement or fix TC-D01's expectation instead, still open. Found in the v0.9.0 QA pass ([#693](https://github.com/khuisman/mcp-gee-sweet/issues/693))
210
210
  - [x] PyPI project page drops the logo — README `<img src>` is a relative path, which PyPI's `readme_renderer` strips. Found on the published v0.9.0 page (PR #707) ([#706](https://github.com/khuisman/mcp-gee-sweet/issues/706))
211
211
  - [x] `sync_folder`/`upload_local_file` convert: Drive's `modifiedTime` for a Google Doc lags real edits by minutes, and the async import can overwrite the post-create restamp. Change detection for `convert_markdown` Docs needs a new signal. Joy scopes; decision doc in PR #819 ([#814](https://github.com/khuisman/mcp-gee-sweet/issues/814)) (PR #854)
212
- - [ ] `sync_folder` convert_markdown: a Drive-edited converted Doc stays a `conflict` on every run, and the only way out today is replacing the Doc (new file ID, loses sharing/comments/links). Decide: accept the Drive version as the baseline, force-upload, or both. #814 follow-up; Joy scopes ([#860](https://github.com/khuisman/mcp-gee-sweet/issues/860))
212
+ - [x] `sync_folder` convert_markdown: a Drive-edited converted Doc stays a `conflict` on every run, and the only way out today is replacing the Doc (new file ID, loses sharing/comments/links). Decide: accept the Drive version as the baseline, force-upload, or both. #814 follow-up; Joy scopes ([#860](https://github.com/khuisman/mcp-gee-sweet/issues/860)) (PR #1016)
213
213
  - [x] auth: with no `token.json`, a stdio server blocks on OAuth consent with no timeout, and the consent prompt goes to the protocol channel ([#811](https://github.com/khuisman/mcp-gee-sweet/issues/811)) (PR #828)
214
214
  - [x] auth: under `--transport sse`, the OAuth consent wait runs synchronously on the event loop, stalling every other session and ignoring SIGTERM until consent or timeout. #811 follow-up, found in PR #828 ([#833](https://github.com/khuisman/mcp-gee-sweet/issues/833)) (PR #867)
215
215
  - [x] Tool errors are opaque on PyPI installs: `mcp` 2.3 (what `uvx` resolves; the lock pins 2.0.0) hides any non-`ToolError` exception text, so #811's "run `mcp-gee-sweet auth`" message and uncaught Google API errors reach the client as a bare `Error executing tool <name>`. Observed live. Urgent: lane-a, next after #844 ([#872](https://github.com/khuisman/mcp-gee-sweet/issues/872)) (PR #905)
@@ -34,6 +34,7 @@ from .images import (
34
34
  upload_and_share_local_image,
35
35
  )
36
36
  from .indices import _collect_doc_paragraphs, decode_code_run_text, utf16_len
37
+ from .markdown_export import _discard_temp_doc
37
38
  from .style import _add_or_clear_field
38
39
 
39
40
  logger = logging.getLogger(__name__)
@@ -308,6 +309,59 @@ def _read_doc_source_file(
308
309
  return content, content_format
309
310
 
310
311
 
312
+ # A bound on the backup copy (all attempts), since it runs shielded from
313
+ # cancellation and a cancel waits for shielded work. Measured at 2.5-4 s for a
314
+ # 20 KB doc; a doc with many images takes longer.
315
+ _BACKUP_COPY_TIMEOUT = 60
316
+
317
+ # A 429 on the copy is retried this many times, with exponential backoff. A 429
318
+ # means Drive ran nothing; a 5xx isn't retried, since the copy may already exist
319
+ # and a retry would make another one.
320
+ _BACKUP_COPY_RATE_LIMIT_RETRIES = 3
321
+
322
+
323
+ def _was_rejected(e: BaseException) -> bool:
324
+ """True if `e` is an HttpError the API answered with a 4xx, meaning the
325
+ request ran nothing. A 5xx, a timeout, or a transport error doesn't say
326
+ whether the request landed."""
327
+ return isinstance(e, HttpError) and 400 <= int(e.resp.status) < 500
328
+
329
+
330
+ def _describe(e: BaseException) -> str:
331
+ """str(e), or the exception's type name when that's empty (a TimeoutError)."""
332
+ return str(e) or type(e).__name__
333
+
334
+
335
+ async def _copy_for_backup(drive_service, doc_id: str, name: str) -> dict[str, Any]:
336
+ """files.copy of `doc_id` named `name`, next to the source. Retries a 429
337
+ only, within _BACKUP_COPY_TIMEOUT for every attempt together."""
338
+ request = drive_service.files().copy(
339
+ fileId=doc_id,
340
+ body={"name": name},
341
+ fields="id,name,capabilities(canDelete)",
342
+ supportsAllDrives=True,
343
+ )
344
+ with anyio.fail_after(_BACKUP_COPY_TIMEOUT):
345
+ for attempt in range(_BACKUP_COPY_RATE_LIMIT_RETRIES + 1):
346
+ try:
347
+ return await execute_in_thread(request.execute, drive_service)
348
+ except HttpError as e:
349
+ if int(e.resp.status) != 429 or attempt == _BACKUP_COPY_RATE_LIMIT_RETRIES:
350
+ raise
351
+ await anyio.sleep(2**attempt)
352
+ raise AssertionError("unreachable")
353
+
354
+
355
+ async def _doc_end_index(docs_service, doc_id: str) -> tuple[dict[str, Any], int]:
356
+ """The doc and its body's endIndex (2 for an empty doc)."""
357
+ doc = await execute_in_thread(
358
+ docs_service.documents().get(documentId=doc_id).execute,
359
+ docs_service,
360
+ )
361
+ body_content = doc.get("body", {}).get("content", [])
362
+ return doc, body_content[-1].get("endIndex", 2) if body_content else 2
363
+
364
+
311
365
  async def _replace_doc_content(
312
366
  lc: SpreadsheetContext,
313
367
  doc_id: str,
@@ -327,18 +381,100 @@ async def _replace_doc_content(
327
381
  The three flags are keyword-only (#567), here and in _apply_doc_content: as
328
382
  positional bools, swapping two at a call site would type-check and silently do
329
383
  the wrong thing.
384
+
385
+ A doc with content is copied with Drive before the clear (#878), and the copy
386
+ is deleted once the new content is in. If anything after the copy fails or is
387
+ cancelled, the copy is kept and a failure result names it as "backupId". Drive's
388
+ revision history can't serve this: Docs merges the revision current before the
389
+ clear into the clear's own revision at once, so its ID is a 404 straight away
390
+ (measured live; see docs/design/doc-replace-backup.md). A failed copy leaves the
391
+ doc untouched and returns an error, except a storageQuotaExceeded one: a service
392
+ account writing into a user-owned doc can't own a copy, and this tool is the
393
+ documented way to write such a doc, so it replaces without a backup, and a
394
+ failure says so.
395
+
396
+ The doc is unchanged, and the copy removed, only when a step before the clear
397
+ fails or the clear gets a 4xx. A clear that fails any other way (a 5xx, a
398
+ timeout, a transport error) may have landed, so the copy is kept and the error
399
+ says the content may have been cleared (PR #1017 QA round 1).
330
400
  """
331
401
  docs_service = lc.docs_service
332
402
  drive_service = lc.drive_service
333
403
  doc_cache = lc.doc_cache
334
- doc = await execute_in_thread(
335
- docs_service.documents().get(documentId=doc_id).execute,
336
- docs_service,
337
- )
338
- body_content = doc.get("body", {}).get("content", [])
339
- end_index = body_content[-1].get("endIndex", 2) if body_content else 2
404
+ doc, end_index = await _doc_end_index(docs_service, doc_id)
405
+
406
+ backup: dict[str, Any] = {}
407
+ no_backup_reason: str | None = None
408
+ if end_index > 2:
409
+ backup_name = f"{doc.get('title') or doc_id} (backup before replace)"
410
+ # Shielded, so a cancellation can't land after Drive made the copy but
411
+ # before its ID is recorded (the PR #877 rule); bounded inside by
412
+ # _BACKUP_COPY_TIMEOUT.
413
+ with anyio.CancelScope(shield=True):
414
+ try:
415
+ backup = await _copy_for_backup(drive_service, doc_id, backup_name)
416
+ except Exception as e:
417
+ if not is_storage_quota_error(e):
418
+ error = (
419
+ f"Couldn't back up the document before replacing its content, "
420
+ f"so it was left unchanged: {_describe(e)}"
421
+ )
422
+ if not _was_rejected(e):
423
+ # Drive may have made the copy and lost the response.
424
+ error += (
425
+ f". A copy named {backup_name!r} may still have been created "
426
+ f"next to the document; check for it and delete it"
427
+ )
428
+ return {"error": error, "docId": doc_id}
429
+ no_backup_reason = "this account has no Drive storage quota for the copy"
430
+ logger.warning(
431
+ "Replacing doc %s without a backup: storage quota exceeded on copy", doc_id
432
+ )
433
+
434
+ # Re-read after the copy, which takes seconds: a concurrent edit meanwhile
435
+ # would otherwise survive the clear (the doc grew) or make it fail (it
436
+ # shrank).
437
+ try:
438
+ _, end_index = await _doc_end_index(docs_service, doc_id)
439
+ except BaseException as e:
440
+ return await _unchanged_result(drive_service, backup, doc_id, e)
441
+
442
+ def _failed(e: BaseException, cleared: str) -> dict[str, Any]:
443
+ """The result for a failure once the clear was sent; `cleared` is "yes",
444
+ "maybe", or "no" (the doc was empty by the time the clear would run)."""
445
+ doc_cache.mark_dirty(doc_id)
446
+ if not isinstance(e, Exception):
447
+ if backup.get("id"):
448
+ logger.warning(
449
+ "Replacing doc %s was cancelled; kept its backup copy %s", doc_id, backup["id"]
450
+ )
451
+ raise e
452
+ if isinstance(e, DocEditError):
453
+ result = _doc_edit_failure_result(e, doc_id)
454
+ else:
455
+ result = {"error": f"doc edit failed: {_describe(e)}", "docId": doc_id}
456
+ state = {
457
+ "yes": "The document's previous content was cleared first",
458
+ "maybe": "The document's previous content may have been cleared",
459
+ }.get(cleared)
460
+ if backup.get("id"):
461
+ if state:
462
+ result["error"] += (
463
+ f". {state}; a full copy of it is kept as {backup['name']!r} (backupId)."
464
+ )
465
+ else:
466
+ result["error"] += (
467
+ f". A full copy of the document from before this call is kept as "
468
+ f"{backup['name']!r} (backupId)."
469
+ )
470
+ result["backupId"] = backup["id"]
471
+ elif no_backup_reason and state:
472
+ result["error"] += (
473
+ f". {state} and couldn't be backed up ({no_backup_reason}), so the "
474
+ f"document may be empty or partly written."
475
+ )
476
+ return result
340
477
 
341
- clear_requests = []
342
478
  if end_index > 2:
343
479
  # The document's final paragraph mark can't be deleted by the Docs API (only
344
480
  # everything before it), so an explicit textStyle override left there by prior
@@ -346,29 +482,35 @@ async def _replace_doc_content(
346
482
  # table, see _build_blank_para_before_table_collapses in emitter.py — would
347
483
  # otherwise survive this "clear" and can leak into newly-inserted content below.
348
484
  # Reset it before deleting, while its original index range is still valid.
349
- clear_requests.append(
485
+ clear_requests = [
350
486
  {
351
487
  "updateTextStyle": {
352
488
  "range": {"startIndex": end_index - 1, "endIndex": end_index},
353
489
  "textStyle": {},
354
490
  "fields": "*",
355
491
  }
356
- }
357
- )
358
- clear_requests.append(
359
- {"deleteContentRange": {"range": {"startIndex": 1, "endIndex": end_index - 1}}}
360
- )
492
+ },
493
+ {"deleteContentRange": {"range": {"startIndex": 1, "endIndex": end_index - 1}}},
494
+ ]
361
495
  # Sent as its own batchUpdate, not combined with the insert below: live testing
362
496
  # showed the Docs API resolves a same-batch insertText's inherited formatting
363
497
  # from a pre-batch snapshot, so contamination survived even after the clear
364
498
  # request above ran earlier in that same batch. A separate call forces the
365
499
  # insert to see the already-cleared document state.
366
- await execute_in_thread(
367
- docs_service.documents()
368
- .batchUpdate(documentId=doc_id, body={"requests": clear_requests})
369
- .execute,
370
- docs_service,
371
- )
500
+ try:
501
+ await execute_in_thread(
502
+ docs_service.documents()
503
+ .batchUpdate(documentId=doc_id, body={"requests": clear_requests})
504
+ .execute,
505
+ docs_service,
506
+ )
507
+ except BaseException as e:
508
+ if _was_rejected(e):
509
+ return await _unchanged_result(drive_service, backup, doc_id, e)
510
+ return _failed(e, "maybe")
511
+ cleared = "yes"
512
+ else:
513
+ cleared = "no"
372
514
 
373
515
  try:
374
516
  image_outcomes = await _apply_doc_content(
@@ -382,26 +524,81 @@ async def _replace_doc_content(
382
524
  revoke_sharing=revoke_sharing,
383
525
  auto_downscale=auto_downscale,
384
526
  )
385
- except DocEditError as e:
386
- # The clear above already committed, so the doc changed either way.
387
- doc_cache.mark_dirty(doc_id)
388
- return _doc_edit_failure_result(e, doc_id)
527
+ except BaseException as e:
528
+ return _failed(e, cleared)
529
+ # Before the link lookup, which can still raise with the doc already
530
+ # replaced (PR #1017 QA round 2).
531
+ doc_cache.mark_dirty(doc_id)
389
532
 
390
- metadata = await execute_in_thread(
391
- drive_service.files()
392
- .get(fileId=doc_id, fields="webViewLink", supportsAllDrives=True)
393
- .execute,
394
- drive_service,
395
- )
533
+ # The backup's removal and the link lookup are independent, so they run
534
+ # together. The removal catches its own errors; a lookup error is re-raised
535
+ # after the removal finishes.
536
+ warning: str | None = None
537
+ metadata: dict[str, Any] = {}
538
+ lookup_error: Exception | None = None
539
+
540
+ async def _remove_backup() -> None:
541
+ nonlocal warning
542
+ warning = await _discard_backup(drive_service, backup)
543
+
544
+ async with anyio.create_task_group() as tg:
545
+ tg.start_soon(_remove_backup)
546
+ try:
547
+ metadata = await execute_in_thread(
548
+ drive_service.files()
549
+ .get(fileId=doc_id, fields="webViewLink", supportsAllDrives=True)
550
+ .execute,
551
+ drive_service,
552
+ )
553
+ except Exception as e:
554
+ lookup_error = e
555
+ if lookup_error is not None:
556
+ raise lookup_error
396
557
 
397
- doc_cache.mark_dirty(doc_id)
398
558
  logger.debug("Replaced content in doc %s", doc_id)
399
559
  result: dict[str, Any] = {"docId": doc_id, "web_link": metadata.get("webViewLink")}
400
560
  if image_outcomes is not None:
401
561
  result["images"] = image_outcomes
562
+ if warning:
563
+ result["warning"] = warning
402
564
  return result
403
565
 
404
566
 
567
+ async def _unchanged_result(
568
+ drive_service, backup: dict[str, Any], doc_id: str, e: BaseException
569
+ ) -> dict[str, Any]:
570
+ """_replace_doc_content's result when it stopped before changing the doc: the
571
+ backup isn't needed, so it's removed. A cancellation is re-raised after."""
572
+ warning = await _discard_backup(drive_service, backup)
573
+ if not isinstance(e, Exception):
574
+ raise e
575
+ result: dict[str, Any] = {
576
+ "error": f"Couldn't clear the document, so it was left unchanged: {_describe(e)}",
577
+ "docId": doc_id,
578
+ }
579
+ if warning:
580
+ result["warning"] = warning
581
+ return result
582
+
583
+
584
+ async def _discard_backup(drive_service, backup: dict[str, Any]) -> str | None:
585
+ """Remove _replace_doc_content's backup copy, if one was made. Shielded, so a
586
+ cancellation doesn't leave the copy behind. Returns a warning for the caller's
587
+ result if the removal failed, else None."""
588
+ if not backup.get("id"):
589
+ return None
590
+ with anyio.CancelScope(shield=True):
591
+ cleanup_error = await _discard_temp_doc(
592
+ drive_service, backup["id"], backup.get("capabilities", {}).get("canDelete", True)
593
+ )
594
+ if not cleanup_error:
595
+ return None
596
+ return (
597
+ f"Couldn't remove the backup copy {backup['id']} made before replacing "
598
+ f"the content; delete it manually ({cleanup_error})."
599
+ )
600
+
601
+
405
602
  class DocEditError(Exception):
406
603
  """_apply_doc_content's doc edit raised after its images were resolved (#789).
407
604
  Carries the per-image outcome list, which would otherwise be lost with the
@@ -1277,9 +1474,15 @@ def register(tool):
1277
1474
  Returns:
1278
1475
  Confirmation with the document ID and web link. Includes "images" (per-image
1279
1476
  outcomes) when content contained any images.
1280
- If writing the new content fails, returns {"error", "docId", "images"}
1281
- instead, with any temporary image share already revoked. The old content
1282
- was cleared first, so the doc may be empty or partly written.
1477
+ Includes "warning" if the backup copy (below) couldn't be removed.
1478
+ Before clearing a doc that has content, a full copy of it is made in Drive,
1479
+ and deleted again once the new content is in. If the copy fails, nothing
1480
+ is changed and an error is returned (except when the account has no
1481
+ storage quota for it, e.g. a service account: the replace then goes ahead
1482
+ without a backup). If writing the new content fails, returns {"error",
1483
+ "docId", "backupId", "images"} instead, with any temporary image share
1484
+ already revoked: the doc may be empty or partly written, and backupId is
1485
+ the kept copy of its previous content.
1283
1486
  """
1284
1487
  lc = ctx.request_context.lifespan_context
1285
1488
  return await _replace_doc_content(
@@ -1338,9 +1541,15 @@ def register(tool):
1338
1541
  Returns:
1339
1542
  Confirmation with the document ID and web link. Includes "images" (per-image
1340
1543
  outcomes) when the file contained any images.
1341
- If writing the new content fails, returns {"error", "docId", "images"}
1342
- instead, with any temporary image share already revoked. The old content
1343
- was cleared first, so the doc may be empty or partly written.
1544
+ Includes "warning" if the backup copy (below) couldn't be removed.
1545
+ Before clearing a doc that has content, a full copy of it is made in Drive,
1546
+ and deleted again once the new content is in. If the copy fails, nothing
1547
+ is changed and an error is returned (except when the account has no
1548
+ storage quota for it, e.g. a service account: the replace then goes ahead
1549
+ without a backup). If writing the new content fails, returns {"error",
1550
+ "docId", "backupId", "images"} instead, with any temporary image share
1551
+ already revoked: the doc may be empty or partly written, and backupId is
1552
+ the kept copy of its previous content.
1344
1553
  """
1345
1554
  source = _read_doc_source_file(local_path, content_format, format_overridable=True)
1346
1555
  if isinstance(source, dict):
@@ -179,9 +179,10 @@ async def _stabilize_images(drive_service, document: dict) -> None:
179
179
 
180
180
 
181
181
  async def _discard_temp_doc(drive_service, file_id: str, can_delete: bool) -> str | None:
182
- """Delete (or, without permanent-delete permission, trash) the temporary
183
- Doc. Returns an error string instead of raising, so a failed cleanup never
184
- hides the export's own outcome."""
182
+ """Delete (or, without permanent-delete permission, trash) a temporary Doc:
183
+ a revision export's import here, or _replace_doc_content's pre-clear backup
184
+ (#878). Returns an error string instead of raising, so a failed cleanup
185
+ never hides the calling tool's own outcome."""
185
186
  try:
186
187
  if can_delete:
187
188
  request = drive_service.files().delete(fileId=file_id, supportsAllDrives=True)
@@ -190,13 +191,12 @@ async def _discard_temp_doc(drive_service, file_id: str, can_delete: bool) -> st
190
191
  request = drive_service.files().update(
191
192
  fileId=file_id, body={"trashed": True}, fields="id", supportsAllDrives=True
192
193
  )
193
- # Retried on a 5xx or 429: a failed removal leaves a copy of the
194
- # revision in Drive.
194
+ # Retried on a 5xx or 429: a failed removal leaves a stray copy in Drive.
195
195
  await execute_in_thread(
196
196
  functools.partial(request.execute, num_retries=_CLEANUP_RETRIES), drive_service
197
197
  )
198
198
  except Exception as e:
199
- logger.warning("Couldn't remove temporary revision Doc %s: %s", file_id, e)
199
+ logger.warning("Couldn't remove temporary Doc %s: %s", file_id, e)
200
200
  return str(e)
201
201
  return None
202
202