Skip to content

Markdown reading position: Back, Forward and headings through dehydrate - #1972

Merged
nedtwigg merged 4 commits into
mainfrom
tool-reading-position
Dec 1, 2026
Merged

nedtwigg merged 4 commits into
mainfrom
tool-reading-position

Conversation

@nedtwigg

@nedtwigg nedtwigg commented Dec 1, 2026

Copy link
Copy Markdown
Member

Back, Forward and heading links in the Markdown editor now run on dehydrate/rehydrate, the protocol any Tool already has, in place of a private page channel. A copy of the built-in run as a user Tool gets the same behavior, which closes the last name check separating a copy from the bundled one. The change removes more than it adds: 59 files, +560/−726 overall, and +251/−344 of source.

What a user sees

Nothing changes for the bundled editor, with one gain and a few small losses:

  • Kept: Back and Forward return each document to its scroll position and rich-text or source mode. A link to other.md#heading lands on the heading, and "Heading not found" still shows.
  • Gained: a reaped Markdown viewer comes back where it was (since Tools: close without asking by what a Tool declares, not its name #1941 it came back at the top). A copy run as a user Tool behaves the same.
  • Lost:
    • A link opened into another pane that reveals an already-open document applies no heading.
    • A scroll made less than 300 ms before pressing Back or Forward may not be kept.
    • A link that reaches the same file through a symlinked name does not scroll.

How it works

The old way: the host asked the page for its position before navigating and told the next page where to go, over a postMessage channel in an iframe and an evaluated script under a screencast, both switched on by the built-in's name.

The new way:

  1. The page tells its own process where it is, as the folder viewer already does for its expanded folders.
  2. Leaving a document dehydrates it. The navigation opens the same stop window a reap uses, and keeps the payload on the history entry being left, in renderer memory.
  3. The next run asks for its state. dor tool --rehydrate prints one JSON line, {"v":1,"state":…,"fragment":"…"}, or nothing, and answers once, for the caller's own Surface. The fragment is the heading a link named.
  4. A reap is unchanged: its state still arrives in DORMOUSE_DEHYDRATE.

A navigation cannot use the environment variable because it types the next command into the shell already there (a take-over Tool runs in the user's own shell; a preview slot retargets in place), and a typed command cannot be given one.

The new request rides the existing surface.tool control method, so no host changed: not the sidecar, the Rust bridge, or the VS Code host.

Deleted

  • dor-tools-lib's protocol and frame modules, their exports and tests. The package is now OSC 367 only.
  • The host's position plumbing: reading before a navigation, applying after, the lock on navigation and Workspace transfer while a position was pending, and the 10 s "Reading position unavailable." deadline.
  • The screencast tool-view operation and the window.__dorToolView global.

Security

Two wording edits in docs/specs/security-local.md, both to keep audited text accurate:

  • S150 lists the file viewer's POST requests. The page's position report is added to the list. It goes through the same guard as the page's other requests: its own Origin, the capability prefix, a JSON body capped at 1 KiB.
  • The sentence that a stopping Tool's dehydrate reaches only its own next run now adds the run a Back or Forward starts for that document on the same Surface.

No rule is added or removed. As with every dor request, the caller asserts its Surface id; the control socket does not bound processes running as the same user, which security-local.md already states.

Notes for review

  • Views with no position write false as their payload when stopped, so a navigation away from a text, code or image view does not wait 100 ms for a payload that never comes. The host keeps it like any payload and every reader restores nothing from it.
  • The folder viewer still writes nothing until its page has reported a view, so leaving it before then waits the 100 ms.
  • The playground asks and dehydrates as the Node viewer does, in about 20 lines, so Back, Forward and headings work there too.
  • One self-test retarget: scripts/outbound-lint-selftest.mjs mutated the deleted protocol.ts; it now mutates sanitize.ts, the smallest file left in that package.

Verified

  • Live, in the dev harness on macOS (Chromium, iframe renderer):
    • Bundled editor: a link to second.md#deep landed on the heading. Back returned the first document to the lines it had been scrolled to, and Forward returned the second to its heading.
    • A copy launched from dor-tools-builtin/dormouse.yml (node …/dist/main.js file …): the same link and the same Back and Forward. The screenshot of the first document before leaving and after returning is byte-identical, so the copy read its state by running dor tool --rehydrate itself.
    • The harness log shows no error.
  • Tests, on this head (main merged in): pnpm test:checks, pnpm test:audit, pnpm test:packages, and pnpm test:lib (7,493 passed, 24 skipped), run one after another. The first test:lib run failed one test, IframePanel.test.tsx "hides the frame until its first load, then reports ready a frame later"; it passes alone three times in three and the full rerun was clean. It has failed the same way on unrelated branches.
  • Mutation checks: 28 across lib, dor-tools-builtin, dor and the playground; each turned its test red. One (the page's scroll listener) first passed, and the test was fixed until it failed.

Not verified

  • A real reap of a Markdown viewer returning at its position: it takes 30 minutes out of sight. Tests cover the payload and the environment path.
  • A screencast renderer, live. The live run used the iframe. The new path does not depend on the renderer; the old screencast path is deleted.
  • Windows, including the copy's spawn of dor there; VS Code and Tauri, live; the playground in a browser (tests only).

🤖 Generated with Claude Code

nedtwigg and others added 4 commits November 30, 2026 17:31
Back/Forward and heading links in the Markdown editor now ride the
dehydrate protocol. A navigation keeps the payload its outgoing run
writes as Ctrl+C stops it on the history entry it leaves, and holds the
destination's payload and the link's fragment for the next run, which
asks once with the new `dor tool --rehydrate`. The Markdown page reports
its mode and scroll offset to its process, which writes it as its
payload and hands what it was given back to the page.

The reading-position channel goes: dor-tools-lib's protocol and frame
entries, the host's toolView/connectToolView and its ToolPanel and
IframePanel wiring, and the screencast host's tool-view operation.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A Markdown link naming its own file with a fragment now gets `here` from
the viewer process, which sends no OSC 367 `open`, and the page scrolls
to the heading itself, as for a bare `#x`. The playground's Markdown
viewer asks for its state and writes its position as it stops, so
Back/Forward and cross-document headings work there too. Every file
view now writes a `false` payload as it stops, so leaving one never
waits the settle. S150 and the terminal-output prose name the new
reading-position POST and the Back/Forward path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
# Conflicts:
#	scripts/spec-word-budgets.json
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2de36f8
Status: ✅  Deploy successful!
Preview URL: https://e6597d7a.mouseterm.pages.dev
Branch Preview URL: https://tool-reading-position.mouseterm.pages.dev

View logs

@nedtwigg
nedtwigg merged commit 11d0d06 into main Dec 1, 2026
19 checks passed
@nedtwigg
nedtwigg deleted the tool-reading-position branch December 1, 2026 02:24
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