Repository navigation
Built-in editors: save through the host's save request, under any renderer - #1915
Merged
Merged
Conversation
The file viewer announces a save path for the editable kinds and answers the host's POST by asking every page that holds its save poll open to run its document save; the next poll carries each page's outcome. saveEditor asks the host first when the run announced save, and falls back to a connected iframe editor only without one. Co-Authored-By: Claude Fable 5.2 <[email protected]>
dor-tools-builtin.md states the announcement and the reply rules for one, several, and no pages; S150 names the save poll and the host's Origin-less save route; dor-tool.md asks the host request before the iframe channel; dor-tools-lib.md keeps only retiring the channel. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A long-poll in flight across a sleep, a proxy restart, or a dropped tunnel fails; the page now retries while it lives, 1 s doubling to 10 s and reset by the next successful poll, keeping any outcome it owes. Each ask carries a never-reused number, so a repeated or late outcome counts once, only for the request that asked. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…route tests beside the viewer's Co-Authored-By: Claude Fable 5.2 <[email protected]>
# Conflicts: # docs/specs/dor-tools-builtin.rationale.md # dor-tools-builtin/src/file-viewer.ts # scripts/spec-word-budgets.json
dormouse-bot
approved these changes
Nov 29, 2026
# Conflicts: # scripts/spec-word-budgets.json
This was referenced Nov 30, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The built-in editors (
builtin:filetext, Markdown and image editors, andbuiltin:code) now save through the same host save request every other Tool uses (#1910), so they save from the close prompt under any renderer, minimized, or showing their terminal. This is stage 2 of removing the iframe's privilege; a forked copy of a built-in can do exactly what the original does.How it works
An editor's unsaved edits live only in its page, but the host's request reaches the viewer process, and every other route is page-initiated. So:
saveas<capability prefix>host-savein its OSC 367serve, and marks the page it serves with<meta name="dor-host-save">.POST <prefix>save-poll. The viewer answers it with{"save":n}when the host asks, or{}after 20 s.{"saved":n,"dirty":false}, ordirty: truewith anerror.saveEditornow asks the host first when the run announcedsaveand the platform can send it, and falls back to the iframe channel otherwise (Pocket, the playground).What the host is told
{"v":1,"dirty":false}Each ask carries a never-reused number, so an outcome a page resends after a failed poll counts once, and only for the request that made it.
A page retries a failed poll for as long as it lives, 1 s doubling to a 10 s cap, keeping the outcome it owes. The channel it replaces is
postMessage, which survives a laptop sleep, a proxy restart, and a dropped phone tunnel; without the retry such a page would answer "not connected" until a reload discarded its edits.Security
S150changes: the viewer's guard admits exactly one POST without anOrigin, the host's request to an editable viewer's announcedsavepath, and requires theOriginabsent there (every browser sends one on a POST, so a page cannot forge it). The save poll is an ordinary page POST and needs the viewer's ownOrigin. Both still need the capability prefix and the loopbackHost. A view-only file viewer and the folder viewer accept neither.Accepted gap
With several pages open on one editor, a page that is between polls at the instant every other page has answered is not asked. Closing it needs a page registry with liveness. It is not a regression: before this PR, closing on the laptop never saved a second page's copy at all. The rationale records it; stage 3 is the place to settle it.
Not in this PR
The iframe save channel stays for reading position, immediate dirty state, the prompt's labels, and Pocket's own save. Retiring it is the one item left in
docs/specs/dor-tools-lib.md→ Future, thenrender: webviewfor Tools.Verified
builtin:file, pressed Kill, then Save in the prompt, underiframeand again underagent-browser-screencast. Both wrote the file and closed the pane.main: the Markdown editor saved and closed the same way.pnpm test(repo checks, every package's type check and suites). The new tests were mutation-checked; removing the page's marker gate hangsdocument-session.test.mjsrather than failing it.Not verified
builtin:code, live. They sharedocumentSessionwith the text editor.🤖 Generated with Claude Code