Skip to content

Land shared editor API primitives (getDocText, getParagraphs, applyEdit) - #554

Draft
kcarnold wants to merge 1 commit into
mainfrom
claude/editor-api-changes-strategy-dyuwux
Draft

Land shared editor API primitives (getDocText, getParagraphs, applyEdit)#554
kcarnold wants to merge 1 commit into
mainfrom
claude/editor-api-changes-strategy-dyuwux

Conversation

@kcarnold

Copy link
Copy Markdown
Contributor

Why

Three separate front-end branches from the "My Words" line of work each independently re-added the same additive editor API surface, with identical method signatures and JSDoc:

Branch PR Editor-API surface
claude/confident-ride-7s1c3m #499 core trio
claude/mywords-interaction-design-cuvkl3 core trio + scratchpad
claude/voice-native-conversation-research-k7uirl #506 (draft) core trio + scratchpad + applySplice?

When N branches copy the same abstraction, it's infrastructure, not feature code. The copies have already begun to drift (the Word implementation gained tracked-changes/reviewed-text handling in the later branches). Landing the shared core on main now stops that drift and lets each feature branch rebase down to just its feature logic.

What this PR adds

Three new members on the host-agnostic EditorAPI interface, plus a DocEdit type:

  • getDocText() — full document text (the corpus + view tool).
  • getParagraphs() — document split into ordered paragraphs; the coordinate system the view tool numbers and paragraph-targeted inserts index into.
  • applyEdit(edit: DocEdit) — apply a structured str_replace / insert edit. Each host lowers DocEdit to its own primitives.

Per host:

  • Word (wordEditorAPI.ts) — full implementation. Uses the reviewed-text-aware version: reads tracked-changes "current" text via getReviewedText (WordApi 1.4), falling back to raw .text on older hosts, so the AI never sees struck-through text. Track-Changes-aware applyEdit with optional paragraph scoping.
  • Google Docs (googleDocsEditorAPI.ts) — read accessors implemented via the existing Apps Script context bridge; applyEdit stubbed (rejects) until the bridge is wired. The existing pull-based polling on main is left untouched.
  • Standalone editor (editor/index.tsx) and context defaults (editorContext.tsx) — read accessors implemented; applyEdit stubbed.

Scope

Deliberately limited to the primitives shared by all three branches. Left with their feature branches:

  • loadScratchpad / saveScratchpad (My Words persistence)
  • applySplice? and the internal delete_paragraph / ParagraphSplice types (voice-only splice optimization)

Tests

Added unit tests for the Google Docs read accessors and the applyEdit stub. Full suite: 40/40 passing; tsc --noEmit clean.

Follow-up

Once this lands, #499 and #506 rebase onto it and shrink to their feature logic (My Words UI; voice spike).

🤖 Generated with Claude Code

https://claude.ai/code/session_01XcidL4aeC5xV59XVXsipCF


Generated by Claude Code

Land the host-agnostic document primitives that three separate feature
branches (My Words v1, the My Words interaction design, and the voice
spike) each independently re-added with identical shape. Landing the
shared surface first stops those copies from drifting further and lets
each feature branch shrink to just its feature logic on a common base.

The new EditorAPI members:
- getDocText(): full document text
- getParagraphs(): document split into ordered paragraphs — the coordinate
  system the `view` tool numbers and paragraph-targeted inserts index into
- applyEdit(edit: DocEdit): apply a structured str_replace/insert edit

DocEdit is a host-agnostic edit type; each host lowers it to its own
primitives. The Word implementation is the reviewed-text-aware version
(reads tracked-changes "current" text via getReviewedText on WordApi 1.4,
falling back to raw .text), so the AI never sees struck-through text. The
Google Docs and standalone-editor hosts implement the read accessors and
stub applyEdit until their bridges are wired up.

Scoped deliberately to the primitives shared by all three branches:
the My Words scratchpad persistence and the voice-only applySplice
optimization stay with their feature branches.

Added unit tests for the Google Docs read accessors and applyEdit stub.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XcidL4aeC5xV59XVXsipCF
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.

2 participants