Typing, pasting, an AI rewrite and a collaborator all change the document through the same door. Here is why I think that's the only honest design, and what it costs.
Anyone building an editor where a person and a model write in the same document. The person expects undo to take back their last move, not the model's. The model's edits should wait for a yes before they count. And a collaborator's cursor keeps moving the whole time.
Most editors grow one path per writer: an input handler for keys, a separate function that splices in AI output, a third channel for sync. Each works alone. Together they break the principle of least surprise, because undo, review and history each tell a slightly different story about what just happened.
Pen keeps a single source of truth for change. Every edit, whoever makes it, is a list of operations handed to editor.apply. The door is three lines long.
Behind it, every call walks the same eight steps, from validation to the moment the change is announced. An extension can reshape an edit on the way in. It can't take a side entrance.
Every edit also says who made it: you, the AI, an import or a collaborator. Undo, review and presence all read that one label, which is what makes undo a promise rather than a guess. Try it: type a few words, press Write as AI, then Undo. The AI's sentence leaves on its own, and yours stays.
The label has to survive being synced, too. The collaboration layer compares authors by identity, so a freshly made label would never match the one it came from. Pen compares by kind instead, and the provenance holds.
Everything has to be expressible as an edit. A feature that wants to reach into the page or the sync layer directly has to become an operation first. That makes the first version of anything slower to build, and it's exactly why every feature after it stays cheap.
Draft. The reasoning above is scaffolding; rewrite it in your own words before publishing.